source: git/kernel/gr_kstd2.cc @ 930ea8

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