source: git/kernel/gr_kstd2.cc @ 454cb0

spielwiese
Last change on this file since 454cb0 was 454cb0, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: rIsRatGRing git-svn-id: file:///usr/local/Singular/svn/trunk@11434 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 29.5 KB
RevLine 
[35aab3]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[454cb0]4/* $Id: gr_kstd2.cc,v 1.27 2009-02-22 11:22:08 Singular Exp $ */
[35aab3]5/*
6*  ABSTRACT -  Kernel: noncomm. alg. of Buchberger
7*/
8
9#include "mod2.h"
[5a9e7b]10
[f2f460]11#ifdef HAVE_PLURAL
[5a9e7b]12
[86016d]13#define PLURAL_INTERNAL_DECLARATIONS
[5a9e7b]14
[35aab3]15#include "omalloc.h"
16#include "polys.h"
17#include "ideals.h"
18#include "febase.h"
19#include "kutil.h"
20#include "kstd1.h"
21#include "khstd.h"
[07b1cf]22#include "kutil.h"
[35aab3]23//#include "spolys.h"
[f599636]24//#include "cntrlc.h"
[35aab3]25#include "weight.h"
26#include "intvec.h"
[4bbe3b]27#include "structs.h"
[35aab3]28#include "gring.h"
[5a9e7b]29#include "sca.h"
[342c80]30#include "ratgring.h"
[35aab3]31
[5a9e7b]32#if 0
33/*3
34* reduction of p2 with p1
35* do not destroy p1 and p2
36* p1 divides p2 -> for use in NF algorithm
[35aab3]37*/
[5a9e7b]38poly gnc_ReduceSpolyNew(const poly p1, poly p2/*,poly spNoether*/, const ring r)
[35aab3]39{
[5a9e7b]40  return(nc_ReduceSPoly(p1,p_Copy(p2,r)/*,spNoether*/,r));
[35aab3]41}
[5a9e7b]42#endif
[35aab3]43
44/*2
45*reduces h with elements from T choosing  the first possible
46* element in t with respect to the given pDivisibleBy
47*/
48int redGrFirst (LObject* h,kStrategy strat)
49{
50  int at,reddeg,d,i;
51  int pass = 0;
52  int j = 0;
53
[b130fb]54  d = pFDeg((*h).p,currRing)+(*h).ecart;
[35aab3]55  reddeg = strat->LazyDegree+d;
56  loop
57  {
58    if (j > strat->sl)
59    {
[d42b51]60#ifdef KDEBUG
[35aab3]61      if (TEST_OPT_DEBUG) PrintLn();
[d42b51]62#endif
[35aab3]63      return 0;
64    }
[d42b51]65#ifdef KDEBUG
[35aab3]66    if (TEST_OPT_DEBUG) Print("%d",j);
[d42b51]67#endif
[35aab3]68    if (pDivisibleBy(strat->S[j],(*h).p))
69    {
[d42b51]70#ifdef KDEBUG
[35aab3]71      if (TEST_OPT_DEBUG) PrintS("+\n");
[d42b51]72#endif
[35aab3]73      /*
74      * the polynomial to reduce with is;
75      * T[j].p
76      */
77      if (!TEST_OPT_INTSTRATEGY)
78        pNorm(strat->S[j]);
[d42b51]79#ifdef KDEBUG
[35aab3]80      if (TEST_OPT_DEBUG)
81      {
82        wrp(h->p);
83        PrintS(" with ");
84        wrp(strat->S[j]);
85      }
[d42b51]86#endif
[19370c]87      (*h).p = nc_ReduceSpoly(strat->S[j],(*h).p, currRing);
[35aab3]88      //spSpolyRed(strat->T[j].p,(*h).p,strat->kNoether);
89
[d42b51]90#ifdef KDEBUG
[35aab3]91      if (TEST_OPT_DEBUG)
92      {
93        PrintS(" to ");
94        wrp(h->p);
95      }
[d42b51]96#endif
[35aab3]97      if ((*h).p == NULL)
98      {
99        if (h->lcm!=NULL) p_LmFree((*h).lcm, currRing);
100        return 0;
101      }
102      if (TEST_OPT_INTSTRATEGY)
103      {
[e36a2c0]104        if (rField_is_Zp_a()) pContent(h->p);
105        else pCleardenom(h->p);// also does a pContent
[35aab3]106      }
107      /*computes the ecart*/
[b130fb]108      d = pLDeg((*h).p,&((*h).length),currRing);
109      (*h).FDeg=pFDeg((*h).p,currRing);
[35aab3]110      (*h).ecart = d-(*h).FDeg; /*pFDeg((*h).p);*/
111      if ((strat->syzComp!=0) && !strat->honey)
112      {
113        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
114        {
[d42b51]115#ifdef KDEBUG
[35aab3]116          if (TEST_OPT_DEBUG) PrintS(" > sysComp\n");
[d42b51]117#endif
[35aab3]118          return 0;
119        }
120      }
121      /*- try to reduce the s-polynomial -*/
122      pass++;
123      /*
124      *test whether the polynomial should go to the lazyset L
125      *-if the degree jumps
126      *-if the number of pre-defined reductions jumps
127      */
128      if ((strat->Ll >= 0)
129      && ((d >= reddeg) || (pass > strat->LazyPass))
130      && !strat->homog)
131      {
132        at = strat->posInL(strat->L,strat->Ll,h,strat);
133        if (at <= strat->Ll)
134        {
135          i=strat->sl+1;
136          do
137          {
138            i--;
139            if (i<0) return 0;
140          } while (!pDivisibleBy(strat->S[i],(*h).p));
141          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
[d42b51]142#ifdef KDEBUG
[35aab3]143          if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
[d42b51]144#endif
[35aab3]145          (*h).p = NULL;
146          return 0;
147        }
148      }
149      if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
150      {
151        reddeg = d+1;
152        Print(".%d",d);mflush();
153      }
154      j = 0;
[d42b51]155#ifdef KDEBUG
[35aab3]156      if TEST_OPT_DEBUG PrintLn();
[d42b51]157#endif
[35aab3]158    }
159    else
160    {
[d42b51]161#ifdef KDEBUG
[35aab3]162      if (TEST_OPT_DEBUG) PrintS("-");
[d42b51]163#endif
[35aab3]164      j++;
165    }
166  }
167}
[737e25]168void ratGB_divide_out(poly p)
169{
170  if (p==NULL) return;
171  poly root=p;
172  assume(currRing->real_var_start>0);
173  poly f=pHead(p);
174  int i;
175  for (i=currRing->real_var_start;i<=currRing->real_var_end;i++)
176  {
177    pSetExp(f,i,0);
178  }
179  loop
180  {
181    pIter(p);
182    if (p==NULL) { pSetm(f); break;}
183    for (i=1;i<=rVar(currRing);i++)
184    {
185      pSetExp(f,i,si_min(pGetExp(f,i),pGetExp(p,i)));
186    }
187  }
188  if (!pIsConstant(f))
189  {
[d42b51]190#ifdef KDEBUG
[737e25]191    if (TEST_OPT_DEBUG)
192    {
193      PrintS("divide out:");p_wrp(f,currRing);
194      PrintS(" from ");pWrite(root);
195    }
[d42b51]196#endif
[737e25]197    p=root;
198    loop
199    {
200      if (p==NULL) break;
201      for (i=1;i<=rVar(currRing);i++)
202      {
203        pSetExp(p,i,pGetExp(p,i)-pGetExp(f,i));
204      }
205      pSetm(p);
206      pIter(p);
207    }
208  }
209  pDelete(&f);
210}
[83f8aff]211#ifdef HAVE_RATGRING
[737e25]212/*2
213*reduces h with elements from T choosing  the first possible
214* element in t with respect to the given pDivisibleBy
215* for use in ratGB
216*/
217int redGrRatGB (LObject* h,kStrategy strat)
218{
219  int at,reddeg,d,i;
220  int pass = 0;
221  int j = 0;
[0047ec]222  int c_j=-1, c_e=-2;
[737e25]223  poly c_p=NULL;
224  assume(strat->tailRing==currRing);
225
226  ratGB_divide_out((*h).p);
227  d = pFDeg((*h).p,currRing)+(*h).ecart;
228  reddeg = strat->LazyDegree+d;
229  if (!TEST_OPT_INTSTRATEGY)
230  {
231    if (rField_is_Zp_a()) pContent(h->p);
232    else pCleardenom(h->p);// also does a pContent
233  }
234  loop
235  {
236    if (j > strat->sl)
237    {
238      if (c_j>=0)
239      {
240        /*
241        * the polynomial to reduce with is;
242        * S[c_j]
243        */
244        if (!TEST_OPT_INTSTRATEGY)
245          pNorm(strat->S[c_j]);
[d42b51]246#ifdef KDEBUG
247    if (TEST_OPT_DEBUG)
[737e25]248        if (TEST_OPT_DEBUG)
249        {
250          wrp(h->p);
[c7a127]251          Print(" with S[%d]= ",c_j);
[737e25]252          wrp(strat->S[c_j]);
253        }
[d42b51]254#endif
[737e25]255        //poly hh = nc_CreateSpoly(strat->S[c_j],(*h).p, currRing);
[36b9ef]256        if(c_e==-1)
257          c_p = nc_CreateSpoly(pCopy(strat->S[c_j]),pCopy((*h).p), currRing);
258        else
[40b31de]259          c_p=nc_rat_ReduceSpolyNew(pCopy(strat->S[c_j]),pCopy((*h).p), currRing->real_var_start-1,currRing);
[a13cae]260        pDelete(&((*h).p));
[36b9ef]261        (*h).p=c_p;
[737e25]262        if (!TEST_OPT_INTSTRATEGY)
263        {
264          if (rField_is_Zp_a()) pContent(h->p);
265          else pCleardenom(h->p);// also does a pContent
266        }
267
[d42b51]268#ifdef KDEBUG
[737e25]269        if (TEST_OPT_DEBUG)
270        {
271          PrintS(" to ");
[9a001d]272          wrp(h->p);
[c7a127]273          PrintLn();
[737e25]274        }
[d42b51]275#endif
[737e25]276        if ((*h).p == NULL)
277        {
278          if (h->lcm!=NULL) p_LmFree((*h).lcm, currRing);
279          return 0;
280        }
281        ratGB_divide_out((*h).p);
282        d = pLDeg((*h).p,&((*h).length),currRing);
283        (*h).FDeg=pFDeg((*h).p,currRing);
284        (*h).ecart = d-(*h).FDeg; /*pFDeg((*h).p);*/
285        /*- try to reduce the s-polynomial again -*/
286        pass++;
[a13cae]287        j=0;
[36b9ef]288        c_j=-1; c_e=-2; c_p=NULL;
[737e25]289      }
290      else
291      { // nothing found
292        return 0;
293      }
294    }
[0047ec]295    // first try usal division
296    if (p_LmDivisibleBy(strat->S[j],(*h).p,currRing))
297    {
[d42b51]298#ifdef KDEBUG
[0047ec]299      if(TEST_OPT_DEBUG)
300      {
301        p_wrp(h->p,currRing); Print(" divisibly by S[%d]=",j);
302        p_wrp(strat->S[j],currRing); PrintS(" e=-1\n");
303      }
[d42b51]304#endif
[342c80]305      if ((c_j<0)||(c_e>=0))
[0047ec]306      {
307        c_e=-1; c_j=j;
308      }
309    }
310    else
[737e25]311    if (p_LmDivisibleByPart(strat->S[j],(*h).p,currRing,
312        currRing->real_var_start,currRing->real_var_end))
313    {
314      int a_e=(pTotaldegree(strat->S[j],currRing)-pFDeg(strat->S[j],currRing));
[d42b51]315#ifdef KDEBUG
[a13cae]316      if(TEST_OPT_DEBUG)
317      {
318        p_wrp(h->p,currRing); Print(" divisibly by S[%d]=",j);
[c7a127]319        p_wrp(strat->S[j],currRing); Print(" e=%d\n",a_e);
[a13cae]320      }
[d42b51]321#endif
[342c80]322      if ((c_j<0)||(c_e>a_e))
[737e25]323      {
324        c_e=a_e; c_j=j;
[342c80]325        //c_p = nc_CreateSpoly(pCopy(strat->S[c_j]),pCopy((*h).p), currRing);
[737e25]326      }
327      /*computes the ecart*/
328      if ((strat->syzComp!=0) && !strat->honey)
329      {
330        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
331        {
[d42b51]332#ifdef KDEBUG
[737e25]333          if (TEST_OPT_DEBUG) PrintS(" > sysComp\n");
[d42b51]334#endif
[737e25]335          return 0;
336        }
337      }
338    }
339    else
340    {
[d42b51]341#ifdef KDEBUG
[a13cae]342      if(TEST_OPT_DEBUG)
343      {
344        p_wrp(h->p,currRing); Print(" not divisibly by S[%d]=",j);
345        p_wrp(strat->S[j],currRing); PrintLn();
346      }
[d42b51]347#endif
[737e25]348    }
349    j++;
350  }
351}
[83f8aff]352#endif
[35aab3]353
354/*2
355*  reduction procedure for the homogeneous case
356*  and the case of a degree-ordering
357*/
[4bbe3b]358static int nc_redHomog (LObject* h,kStrategy strat)
[35aab3]359{
360  if (strat->tl<0)
361  {
362    enterT((*h),strat);
363    return 1;
364  }
365
366  int j = 0;
367
368  if (TEST_OPT_DEBUG)
369  {
370    PrintS("red:");
371    wrp(h->p);
372    PrintS(" ");
373  }
374  loop
375  {
376    if (TEST_OPT_DEBUG) Print("%d",j);
377    if (pDivisibleBy(strat->S[j],(*h).p))
378    {
379      if (TEST_OPT_DEBUG)
380      {
381        PrintS("+\nwith ");
382        wrp(strat->S[j]);
383      }
384      /*- compute the s-polynomial -*/
[19370c]385      (*h).p = nc_ReduceSpoly(strat->S[j],(*h).p,currRing);
[35aab3]386      if ((*h).p == NULL)
387      {
388        if (TEST_OPT_DEBUG) PrintS(" to 0\n");
389        if (h->lcm!=NULL) pLmFree((*h).lcm);
390        (*h).lcm=NULL;
391        return 0;
392      }
393/*
394*      else if (strat->syzComp)
395*      {
396*        if (pMinComp((*h).p) > strat->syzComp)
397*        {
398*          enterT((*h),strat);
399*          return;
400*        }
401*      }
402*/
403      /*- try to reduce the s-polynomial -*/
404      j = 0;
405    }
406    else
407    {
408      if (j >= strat->sl)
409      {
410        enterT((*h),strat);
411        return 1;
412      }
413      j++;
414    }
415  }
416}
417
[5a9e7b]418#if 0
[35aab3]419/*2
420*  reduction procedure for the homogeneous case
421*  and the case of a degree-ordering
422*/
[4bbe3b]423static int nc_redHomog0 (LObject* h,kStrategy strat)
[35aab3]424{
425  if (strat->tl<0)
426  {
427    enterT((*h),strat);
428    return 0;
429  }
430
431  int j = 0;
432  int k = 0;
433
434  if (TEST_OPT_DEBUG)
435  {
436    PrintS("red:");
437    wrp(h->p);
438    PrintS(" ");
439  }
440  loop
441  {
442    if (TEST_OPT_DEBUG) Print("%d",j);
443    if (pDivisibleBy(strat->T[j].p,(*h).p))
444    {
445      if (TEST_OPT_DEBUG)
446      {
447        PrintS("+\nwith ");
448        wrp(strat->S[j]);
449      }
450      /*- compute the s-polynomial -*/
[4bbe3b]451      (*h).p = nc_ReduceSpoly(strat->T[j].p,(*h).p,strat->kNoether,currRing);
[35aab3]452      if ((*h).p == NULL)
453      {
454        if (TEST_OPT_DEBUG) PrintS(" to 0\n");
455        if (h->lcm!=NULL) pLmFree((*h).lcm);
456        (*h).lcm=NULL;
457        return 0;
458      }
[e36a2c0]459      else
[35aab3]460      {
[e36a2c0]461        if (TEST_OPT_INTSTRATEGY)
[35aab3]462        {
[e36a2c0]463          if (rField_is_Zp_a()) pContent(h->p);
464          else pCleardenom(h->p);// also does a pContent
465        }
466        if (strat->syzComp!=0)
467        {
468          if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
469          {
[35aab3]470/*
[e36a2c0]471*           (*h).length=pLength0((*h).p);
[35aab3]472*/
[e36a2c0]473            enterT((*h),strat);
474            return 0;
475          }
[35aab3]476        }
477      }
478      /*- try to reduce the s-polynomial -*/
479      j = 0;
480    }
481    else
482    {
483      if (j >= strat->tl)
484      {
[e36a2c0]485        if (TEST_OPT_INTSTRATEGY)
486        {
487          if (rField_is_Zp_a()) pContent(h->p);
488          else pCleardenom(h->p);// also does a pContent
489        }
[35aab3]490/*
491*       (*h).length=pLength0((*h).p);
492*/
493        enterT((*h),strat);
494        return 0;
495      }
496      j++;
497    }
498  }
499}
500
501/*2
502*  reduction procedure for the inhomogeneous case
503*  and not a degree-ordering
504*/
[4bbe3b]505static int nc_redLazy (LObject* h,kStrategy strat)
[35aab3]506{
507  if (strat->tl<0)
508  {
509    enterT((*h),strat);
510    return 0;
511  }
512
513  int at,d,i;
514  int j = 0;
515  int pass = 0;
[b130fb]516  int reddeg = pFDeg((*h).p,currRing);
[35aab3]517
518  if (TEST_OPT_DEBUG)
519  {
520    PrintS("red:");
521    wrp(h->p);
522    PrintS(" ");
523  }
524  loop
525  {
526    if (TEST_OPT_DEBUG) Print("%d",j);
527    if (pDivisibleBy(strat->S[j],(*h).p))
528    {
529      if (TEST_OPT_DEBUG)
530      {
531        PrintS("+\nwith ");
532        wrp(strat->S[j]);
533      }
534      /*- compute the s-polynomial -*/
[4bbe3b]535      (*h).p = nc_ReduceSpoly(strat->S[j],(*h).p,strat->kNoether,currRing);
[35aab3]536      if ((*h).p == NULL)
537      {
538        if (TEST_OPT_DEBUG) PrintS(" to 0\n");
539        if (h->lcm!=NULL) pLmFree((*h).lcm);
540        (*h).lcm=NULL;
541        return 0;
542      }
543//      else if (strat->syzComp)
544//      {
545//        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
546//        {
547//          if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
548//          if (TEST_OPT_INTSTRATEGY) pContent(h->p);
549//          enterTBba((*h),strat->tl+1,strat);
550//          return;
551//        }
552//      }
[e36a2c0]553      else
[35aab3]554      {
[e36a2c0]555        if (TEST_OPT_DEBUG)
556        {
557          PrintS("to:");
558          wrp((*h).p);
559          PrintLn();
560        }
561        if (TEST_OPT_INTSTRATEGY)
562        {
563          pContent(h->p);
564          //pCleardenom(h->p);// also does a pContent
565        }
[35aab3]566      }
567      /*- try to reduce the s-polynomial -*/
568      pass++;
[b130fb]569      d = pFDeg((*h).p,currRing);
[35aab3]570      if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
571      {
572        at = posInL11(strat->L,strat->Ll,h,strat);
573        if (at <= strat->Ll)
574        {
575          i=strat->sl+1;
576          do
577          {
578            i--;
579            if (i<0)
580            {
581              enterT((*h),strat);
582              return 0;
583            }
584          }
[e36a2c0]585          while (!pDivisibleBy(strat->S[i],(*h).p));
[35aab3]586          if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at);
587          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
588          (*h).p = NULL;
589          return 0;
590        }
591      }
592      else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d != reddeg))
593      {
594        Print(".%d",d);mflush();
595        reddeg = d;
596      }
597      j = 0;
598    }
599    else
600    {
601      if (TEST_OPT_DEBUG) PrintS("-");
602      if (j >= strat->sl)
603      {
604        if (TEST_OPT_DEBUG) PrintLn();
605        if (TEST_OPT_INTSTRATEGY)
606        {
[e36a2c0]607          if (rField_is_Zp_a()) pContent(h->p);
608          else pCleardenom(h->p);// also does a pContent
[35aab3]609        }
610        enterT((*h),strat);
611        return 0;
612      }
613      j++;
614    }
615  }
616}
617
618/*2
619*  reduction procedure for the sugar-strategy (honey)
620* reduces h with elements from T choosing first possible
621* element in T with respect to the given ecart
622*/
[4bbe3b]623static int nc_redHoney (LObject*  h,kStrategy strat)
[35aab3]624{
625  if (strat->tl<0)
626  {
627    enterT((*h),strat);
628    return 0;
629  }
630
631  poly pi;
632  int i,j,at,reddeg,d,pass,ei;
633
634  pass = j = 0;
[b130fb]635  d = reddeg = pFDeg((*h).p,currRing)+(*h).ecart;
[35aab3]636  if (TEST_OPT_DEBUG)
637  {
638    PrintS("red:");
639    wrp((*h).p);
640  }
641  loop
642  {
643    if (TEST_OPT_DEBUG) Print("%d",j);
644    if (pDivisibleBy(strat->T[j].p,(*h).p))
645    {
646      if (TEST_OPT_DEBUG) PrintS("+");
647      pi = strat->T[j].p;
648      ei = strat->T[j].ecart;
649      /*
650      * the polynomial to reduce with (up to the moment) is;
651      * pi with ecart ei
652      */
653      i = j;
654      loop
655      {
656        /*- takes the first possible with respect to ecart -*/
657        i++;
658        if (i > strat->tl)
659          break;
660        if ((!BTEST1(20)) && (ei <= (*h).ecart))
661          break;
662        if (TEST_OPT_DEBUG) Print("%d",i);
663        if ((strat->T[i].ecart < ei) && pDivisibleBy(strat->T[i].p,(*h).p))
664        {
665          if (TEST_OPT_DEBUG) PrintS("+");
666          /*
667          * the polynomial to reduce with is now;
668          */
669          pi = strat->T[i].p;
670          ei = strat->T[i].ecart;
671        }
672        else if (TEST_OPT_DEBUG) PrintS("-");
673      }
674
675      /*
676      * end of search: have to reduce with pi
677      */
678      if (ei > (*h).ecart)
679      {
680        /*
681        * It is not possible to reduce h with smaller ecart;
682        * if possible h goes to the lazy-set L,i.e
683        * if its position in L would be not the last one
684        */
685        if (strat->Ll >= 0) /* L is not empty */
686        {
687          at = strat->posInL(strat->L,strat->Ll,h,strat);
688          if(at <= strat->Ll)
689          /*- h will not become the next element to reduce -*/
690          {
691            enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
692            if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at);
693            (*h).p = NULL;
694            return 0;
695          }
696        }
697      }
698      if (TEST_OPT_DEBUG)
699      {
700        PrintS("\nwith ");
701        wrp(pi);
702      }
703      if (strat->fromT)
704      {
705        strat->fromT=FALSE;
[52e2f6]706        (*h).p = nc_ReduceSpoly(pi,(*h).p,strat->kNoether,currRing);
[35aab3]707      }
708      else
[4bbe3b]709        (*h).p = nc_ReduceSpoly(pi,(*h).p,strat->kNoether,currRing);
[35aab3]710      if (TEST_OPT_DEBUG)
711      {
712        PrintS(" to ");
713        wrp((*h).p);
714        PrintLn();
715      }
716      if ((*h).p == NULL)
717      {
718        if (h->lcm!=NULL) pLmFree((*h).lcm);
719        (*h).lcm=NULL;
720        return 0;
721      }
[e36a2c0]722      if (TEST_OPT_INTSTRATEGY)
723      {
724        //pContent(h->p);
725        pCleardenom(h->p);// also does a pContent
726      }
[35aab3]727      /* compute the ecart */
728      if (ei <= (*h).ecart)
[b130fb]729        (*h).ecart = d-pFDeg((*h).p,currRing);
[35aab3]730      else
[b130fb]731        (*h).ecart = d-pFDeg((*h).p,currRing)+ei-(*h).ecart;
[35aab3]732//      if (strat->syzComp)
733//      {
734//        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
735//        {
736//          if (TEST_OPT_DEBUG)
737//            PrintS("  >syzComp\n");
738//          if (TEST_OPT_INTSTRATEGY) pContent(h->p);
739//          at=strat->posInT(strat->T,strat->tl,(*h));
740//          enterTBba((*h),at,strat);
741//          return;
742//        }
743//      }
744      /*
745      * try to reduce the s-polynomial h
746      *test first whether h should go to the lazyset L
747      *-if the degree jumps
748      *-if the number of pre-defined reductions jumps
749      */
750      pass++;
[b130fb]751      d = pFDeg((*h).p,currRing)+(*h).ecart;
[35aab3]752      if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
753      {
754        at = strat->posInL(strat->L,strat->Ll,h,strat);
755        if (at <= strat->Ll)
756        {
757          /*test if h is already standardbasis element*/
758          i=strat->sl+1;
759          do
760          {
761            i--;
762            if (i<0)
763            {
764              enterT((*h),strat);
765              return 0;
766            }
767          } while (!pDivisibleBy(strat->S[i],(*h).p));
768          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
769          if (TEST_OPT_DEBUG)
770            Print(" degree jumped: -> L%d\n",at);
771          (*h).p = NULL;
772          return 0;
773        }
774      }
775      else if (TEST_OPT_PROT && (strat->Ll < 0) && (d > reddeg))
776      {
777        reddeg = d;
778        Print(".%d",d); mflush();
779      }
780      j = 0;
781    }
782    else
783    {
784      if (TEST_OPT_DEBUG) PrintS("-");
785      if (j >= strat->tl)
786      {
787        if (TEST_OPT_DEBUG) PrintLn();
788        if (TEST_OPT_INTSTRATEGY)
789        {
790          //pContent(h->p);
791          pCleardenom(h->p);// also does a pContent
792        }
793        enterT((*h),strat);
794        return 0;
795      }
796      j++;
797    }
798  }
799}
800
801/*2
802*  reduction procedure for tests only
803*  reduces with elements from T and chooses the best possible
804*/
[4bbe3b]805static int nc_redBest (LObject*  h,kStrategy strat)
[35aab3]806{
807  if (strat->tl<0)
808  {
809    enterT((*h),strat);
810    return 0;
811  }
812
813  int j,jbest,at,reddeg,d,pass;
814  poly     p,ph;
815  pass = j = 0;
816
817  if (strat->honey)
[b130fb]818    reddeg = pFDeg((*h).p,currRing)+(*h).ecart;
[35aab3]819  else
[b130fb]820    reddeg = pFDeg((*h).p,currRing);
[35aab3]821  loop
822  {
823    if (pDivisibleBy(strat->T[j].p,(*h).p))
824    {
825      /* compute the s-polynomial */
826      if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p);
827#ifdef SDRING
828      // spSpolyShortBba will not work in the SRING case
829      if (pSDRING)
830      {
831        p=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether);
832        if (p!=NULL) pDelete(&pNext(p));
833      }
834      else
835#endif
[4bbe3b]836      p = nc_CreateShortSpoly(strat->T[j].p,(*h).p);
[35aab3]837      /* computes only the first monomial of the spoly  */
838      if (p)
839      {
840        jbest = j;
841        /* looking for the best possible reduction */
842        if ((strat->syzComp==0) || (pMinComp(p) <= strat->syzComp))
843        {
844          loop
845          {
846            j++;
847            if (j > strat->tl)
848              break;
849            if (pDivisibleBy(strat->T[j].p,(*h).p))
850            {
851#ifdef SDRING
852              // spSpolyShortBba will not work in the SRING case
853              if (pSDRING)
854              {
855                ph=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether);
856                if (ph!=NULL) pDelete(&pNext(ph));
857              }
858              else
859#endif
[4bbe3b]860              ph = nc_CreateShortSpoly(strat->T[j].p,(*h).p);
[35aab3]861              if (ph==NULL)
862              {
863                pLmFree(p);
864                pDelete(&((*h).p));
865                if (h->lcm!=NULL)
866                {
867                  pLmFree((*h).lcm);
868                  (*h).lcm=NULL;
869                }
870                return 0;
871              }
872              else if (pLmCmp(ph,p) == -1)
873              {
874                pLmFree(p);
875                p = ph;
876                jbest = j;
877              }
878              else
879              {
880                pLmFree(ph);
881              }
882            }
883          }
884        }
885        pLmFree(p);
[4bbe3b]886        (*h).p = nc_ReduceSpoly(strat->T[jbest].p,(*h).p,strat->kNoether,currRing);
[35aab3]887      }
888      else
889      {
890        if (h->lcm!=NULL)
891        {
892          pLmFree((*h).lcm);
893          (*h).lcm=NULL;
894        }
895        (*h).p = NULL;
896        return 0;
897      }
898      if (strat->honey && pLexOrder)
899        strat->initEcart(h);
900      /* h.length:=l; */
901      /* try to reduce the s-polynomial */
902//      if (strat->syzComp)
903//      {
904//        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
905//        {
906//          if (TEST_OPT_DEBUG)
907//            PrintS(" >syzComp\n");
908//          if (TEST_OPT_INTSTRATEGY) pContent(h->p);
909//          at=strat->posInT(strat->T,strat->tl,(*h));
910//          enterTBba((*h),at,strat);
911//          return;
912//        }
913//      }
914      if (strat->honey || pLexOrder)
915      {
916        pass++;
[b130fb]917        d = pFDeg((*h).p,currRing);
[35aab3]918        if (strat->honey)
919          d += (*h).ecart;
920        if ((strat->Ll >= 0) && ((pass > strat->LazyPass) || (d > reddeg)))
921        {
922          at = strat->posInL(strat->L,strat->Ll,h,strat);
923          if (at <= strat->Ll)
924          {
925            enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
926            (*h).p = NULL;
927            return 0;
928          }
929        }
930        else if (TEST_OPT_PROT && (strat->Ll < 0) && (d != reddeg))
931        {
932          reddeg = d;
933          Print("%d.");
934          mflush();
935        }
936      }
937      j = 0;
938    }
939    else
940    {
941      if (j >= strat->tl)
942      {
943        if (TEST_OPT_INTSTRATEGY)
944        {
945          //pContent(h->p);
946          pCleardenom(h->p);// also does a pContent
947        }
948        enterT((*h),strat);
949        return 0;
950      }
951      j++;
952    }
953  }
954}
955
[5a9e7b]956#endif
957
[86016d]958void nc_gr_initBba(ideal F, kStrategy strat)
[35aab3]959{
[5a9e7b]960  assume(rIsPluralRing(currRing));
961
[35aab3]962  int i;
963  idhdl h;
964 /* setting global variables ------------------- */
965  strat->enterS = enterSBba;
[5a9e7b]966
967/*
[35aab3]968  if ((BTEST1(20)) && (!strat->honey))
[4bbe3b]969    strat->red = nc_redBest;
[35aab3]970  else if (strat->honey)
[4bbe3b]971    strat->red = nc_redHoney;
[35aab3]972  else if (pLexOrder && !strat->homog)
[4bbe3b]973    strat->red = nc_redLazy;
[35aab3]974  else if (TEST_OPT_INTSTRATEGY && strat->homog)
[4bbe3b]975    strat->red = nc_redHomog0;
[35aab3]976  else
[4bbe3b]977    strat->red = nc_redHomog;
[5a9e7b]978*/
979
980//   if (rIsPluralRing(currRing))
[35aab3]981    strat->red = redGrFirst;
[83f8aff]982#ifdef HAVE_RATGRING
[737e25]983  if (currRing->real_var_start>0)
[4debf02]984  {
[36b9ef]985    int ii=IDELEMS(F)-1;
986    int jj;
987    BOOLEAN is_rat_id=FALSE;
988    for(;ii>=0;ii--)
989    {
990      for(jj=currRing->real_var_start;jj<=currRing->real_var_end;jj++)
991      {
992        if(pGetExp(F->m[ii],jj)>0) { is_rat_id=TRUE; break; }
993      }
994      if (is_rat_id) break;
995    }
996    if (is_rat_id) strat->red=redGrRatGB;
[4debf02]997  }
[83f8aff]998#endif
[5a9e7b]999
[35aab3]1000  if (pLexOrder && strat->honey)
1001    strat->initEcart = initEcartNormal;
1002  else
1003    strat->initEcart = initEcartBBA;
1004  if (strat->honey)
1005    strat->initEcartPair = initEcartPairMora;
1006  else
1007    strat->initEcartPair = initEcartPairBba;
1008  strat->kIdeal = NULL;
1009  //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD;
1010  //else              strat->kIdeal->rtyp=MODUL_CMD;
1011  //strat->kIdeal->data=(void *)strat->Shdl;
1012  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1013  {
[4bbe3b]1014     //interred  machen   Aenderung
1015     pFDegOld=pFDeg;
1016     pLDegOld=pLDeg;
1017  //   h=ggetid("ecart");
1018  //   if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD))
1019  //   {
1020  //     ecartWeights=iv2array(IDINTVEC(h));
1021  //   }
1022  //   else
[35aab3]1023    {
1024      ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short));
1025      /*uses automatic computation of the ecartWeights to set them*/
1026      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1027    }
1028    pFDeg=totaldegreeWecart;
1029    pLDeg=maxdegreeWecart;
1030    for(i=1; i<=pVariables; i++)
1031      Print(" %d",ecartWeights[i]);
1032    PrintLn();
1033    mflush();
1034  }
1035}
1036
[52e2f6]1037#define MYTEST 0
1038
[5a9e7b]1039ideal gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat)
[35aab3]1040{
[52e2f6]1041#if MYTEST
1042   PrintS("<gnc_gr_bba>\n");
1043#endif
1044
1045#ifdef HAVE_PLURAL
1046#if MYTEST
1047   PrintS("currRing: \n");
1048   rWrite(currRing);
1049#ifdef RDEBUG
1050   rDebugPrint(currRing);
1051#endif
1052
1053   PrintS("F: \n");
[737e25]1054   idPrint(F);
1055   PrintS("Q: \n");
[52e2f6]1056   idPrint(Q);
1057#endif
1058#endif
1059
1060
[737e25]1061
[5a9e7b]1062  assume(pOrdSgn != -1); // no mora!!! it terminates only for global ordering!!! (?)
1063
[35aab3]1064  intvec *w=NULL;
1065  intvec *hilb=NULL;
1066  int   srmax,lrmax;
1067  int   olddeg,reduc;
1068  int red_result=1;
1069  int hilbeledeg=1,hilbcount=0,minimcnt=0;
1070
1071  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
1072  // initHilbCrit(F,Q,&hilb,strat);
1073  /* in plural we don't need Hilb yet */
[86016d]1074  nc_gr_initBba(F,strat);
[35aab3]1075  initBuchMoraPos(strat);
[4debf02]1076  if (currRing->real_var_start>0)
1077  {
1078    strat->posInL=posInL0; // by pCmp of lcm
1079  }
[0047ec]1080  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
1081  /*Shdl=*/initBuchMora(F, Q,strat);
1082  strat->posInT=posInT110;
[35aab3]1083  srmax = strat->sl;
1084  reduc = olddeg = lrmax = 0;
[52e2f6]1085
[35aab3]1086  /* compute------------------------------------------------------- */
1087  while (strat->Ll >= 0)
1088  {
1089    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
[52e2f6]1090
[35aab3]1091    if (TEST_OPT_DEBUG) messageSets(strat);
[52e2f6]1092
[35aab3]1093    if (strat->Ll== 0) strat->interpt=TRUE;
1094    if (TEST_OPT_DEGBOUND
[b130fb]1095    && ((strat->honey
1096    && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
1097       || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
[35aab3]1098    {
1099      /*
1100      *stops computation if
1101      * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
1102      *a predefined number Kstd1_deg
1103      */
1104      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1105      break;
1106    }
1107    /* picks the last element from the lazyset L */
1108    strat->P = strat->L[strat->Ll];
1109    strat->Ll--;
[626431]1110    //kTest(strat);
[52e2f6]1111
1112    if (strat->P.p != NULL)
[35aab3]1113    if (pNext(strat->P.p) == strat->tail)
1114    {
1115      /* deletes the short spoly and computes */
1116      pLmFree(strat->P.p);
1117      /* the real one */
[454cb0]1118//      if (ncRingType(currRing)==nc_lie) /* prod crit */
1119//        if(pHasNotCF(strat->P.p1,strat->P.p2))
1120//        {
[52e2f6]1121//          strat->cp++;
[454cb0]1122//          /* prod.crit itself in nc_CreateSpoly */
1123//        }
[737e25]1124
[52e2f6]1125      strat->P.p = nc_CreateSpoly(strat->P.p1,strat->P.p2,currRing);
1126
1127#ifdef PDEBUG
1128      p_Test(strat->P.p, currRing);
1129#endif
1130
1131#if MYTEST
1132      if (TEST_OPT_DEBUG)
[35aab3]1133      {
[52e2f6]1134        PrintS("p1: "); pWrite(strat->P.p1);
1135        PrintS("p2: "); pWrite(strat->P.p2);
1136        PrintS("SPoly: "); pWrite(strat->P.p);
[35aab3]1137      }
[737e25]1138#endif
[35aab3]1139    }
[52e2f6]1140
[737e25]1141
[35aab3]1142    if (strat->P.p != NULL)
1143    {
1144      if (TEST_OPT_PROT)
[52e2f6]1145        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
[35aab3]1146              &olddeg,&reduc,strat, red_result);
[52e2f6]1147
1148#if MYTEST
1149      if (TEST_OPT_DEBUG)
1150      {
1151        PrintS("p1: "); pWrite(strat->P.p1);
1152        PrintS("p2: "); pWrite(strat->P.p2);
1153        PrintS("SPoly before: "); pWrite(strat->P.p);
1154      }
1155#endif
1156
[35aab3]1157      /* reduction of the element chosen from L */
1158      strat->red(&strat->P,strat);
[52e2f6]1159
1160#if MYTEST
1161      if (TEST_OPT_DEBUG)
1162      {
1163        PrintS("red SPoly: "); pWrite(strat->P.p);
1164      }
1165#endif
1166
[35aab3]1167    }
1168    if (strat->P.p != NULL)
1169    {
1170          /* statistic */
1171          if (TEST_OPT_PROT)
1172          {
1173            PrintS("s\n");
1174          }
1175          /* enter P.p into s and L */
1176          {
1177            strat->P.sev=0;
1178            int pos=posInS(strat,strat->sl,strat->P.p, strat->P.ecart);
1179            {
1180              if (TEST_OPT_INTSTRATEGY)
1181              {
1182                if ((strat->syzComp==0)||(!strat->homog))
1183                {
1184                  strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1185                }
1186                pCleardenom(strat->P.p);
1187              }
1188              else
1189              {
1190                pNorm(strat->P.p);
1191                if ((strat->syzComp==0)||(!strat->homog))
1192                {
1193                  strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1194                }
1195              }
1196              // PLURAL debug
1197              /* should be used only internally!!! */
1198
1199              //pWrite(strat->P.p);
1200
1201              if (TEST_OPT_DEBUG)
1202              {
[52e2f6]1203                PrintS("new s:"); wrp(strat->P.p);
[35aab3]1204                PrintLn();
[52e2f6]1205#if MYTEST
1206                Print("s: "); pWrite(strat->P.p);
1207#endif
[737e25]1208
[35aab3]1209              }
1210              // kTest(strat);
1211              //
1212              enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat);
[737e25]1213
[35aab3]1214              if (strat->sl==-1) pos=0;
1215              else pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
[737e25]1216
[b130fb]1217              strat->enterS(strat->P,pos,strat,-1);
[35aab3]1218            }
[86016d]1219//            if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
[35aab3]1220          }
1221          if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
1222      if (strat->sl>srmax) srmax = strat->sl;
1223    }
1224#ifdef KDEBUG
1225    strat->P.lcm=NULL;
1226#endif
[626431]1227    //kTest(strat);
[35aab3]1228  }
1229  if (TEST_OPT_DEBUG) messageSets(strat);
[86016d]1230
[35aab3]1231  /* complete reduction of the standard basis--------- */
[07b1cf]1232  if (TEST_OPT_SB_1)
1233  {
1234    int k=1;
1235    int j;
1236    while(k<=strat->sl)
1237    {
1238      j=0;
1239      loop
1240      {
1241        if (j>=k) break;
1242        clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
1243        j++;
1244      }
1245      k++;
1246    }
[86016d]1247  }
1248
[07b1cf]1249  if (TEST_OPT_REDSB)
1250     completeReduce(strat);
[35aab3]1251  /* release temp data-------------------------------- */
1252  exitBuchMora(strat);
1253  if (TEST_OPT_WEIGHTM)
1254  {
1255    pFDeg=pFDegOld;
1256    pLDeg=pLDegOld;
1257    if (ecartWeights)
1258    {
1259      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
1260      ecartWeights=NULL;
1261    }
1262  }
1263  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
1264  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
[86016d]1265
1266
[e38e91]1267#ifdef PDEBUG
1268/* for counting number of pairs [enterL] in Plural */
1269/*   extern int zaehler; */
1270/*   Print("Total pairs considered:%d\n",zaehler); zaehler=0; */
[7447d8]1271#endif /*PDEBUG*/
[52e2f6]1272
1273#if MYTEST
1274  PrintS("</gnc_gr_bba>\n");
1275#endif
1276
[35aab3]1277  return (strat->Shdl);
1278}
[5a9e7b]1279
1280ideal gnc_gr_mora(const ideal, const ideal, const intvec *, const intvec *, kStrategy)
1281{
1282  PrintS("Sorry, non-commutative mora is not yet implemented!");
1283  PrintLn();
1284
1285  // Not yet!
1286  return NULL;
1287}
1288
[f2f460]1289#endif
[5a9e7b]1290
Note: See TracBrowser for help on using the repository browser.