source: git/kernel/gr_kstd2.cc @ 737a68

spielwiese
Last change on this file since 737a68 was 737a68, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
CHG: moved libpolys/polys/polys.h to kernel/polys.h & updated includes ADD: moved (definition of) currRing/rChangeCurrRing to kernel/polys.cc!?
  • Property mode set to 100644
File size: 30.7 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}
[83f8aff]219#ifdef HAVE_RATGRING
[737e25]220/*2
221*reduces h with elements from T choosing  the first possible
222* element in t with respect to the given pDivisibleBy
223* for use in ratGB
224*/
225int redGrRatGB (LObject* h,kStrategy strat)
226{
227  int at,reddeg,d,i;
228  int pass = 0;
229  int j = 0;
[0047ec]230  int c_j=-1, c_e=-2;
[737e25]231  poly c_p=NULL;
232  assume(strat->tailRing==currRing);
233
234  ratGB_divide_out((*h).p);
[1558d5]235  d = currRing->pFDeg((*h).p,currRing)+(*h).ecart;
[737e25]236  reddeg = strat->LazyDegree+d;
237  if (!TEST_OPT_INTSTRATEGY)
238  {
[1558d5]239    if (rField_is_Zp_a(currRing)) p_Content(h->p,currRing);
[c0e2c36]240    else h->pCleardenom();// also does a pContentRat
[737e25]241  }
242  loop
243  {
244    if (j > strat->sl)
245    {
246      if (c_j>=0)
247      {
248        /*
249        * the polynomial to reduce with is;
250        * S[c_j]
251        */
252        if (!TEST_OPT_INTSTRATEGY)
253          pNorm(strat->S[c_j]);
[d42b51]254#ifdef KDEBUG
255    if (TEST_OPT_DEBUG)
[737e25]256        if (TEST_OPT_DEBUG)
257        {
258          wrp(h->p);
[c7a127]259          Print(" with S[%d]= ",c_j);
[737e25]260          wrp(strat->S[c_j]);
261        }
[d42b51]262#endif
[a93f7b0]263    //poly hh = nc_CreateSpoly(strat->S[c_j],(*h).p, currRing);
264    //        Print("vor nc_rat_ReduceSpolyNew (ce:%d) ",c_e);wrp(h->p);PrintLn();
265    //if(c_e==-1)
266    //  c_p = nc_CreateSpoly(pCopy(strat->S[c_j]),pCopy((*h).p), currRing);
267    //else
268    //          c_p=nc_rat_ReduceSpolyNew(strat->S[c_j],pCopy((*h).p), currRing->real_var_start-1,currRing);
269    //        Print("nach nc_rat_ReduceSpolyNew ");wrp(c_p);PrintLn();
270    //        pDelete(&((*h).p));
271   
272        c_p=nc_rat_ReduceSpolyNew(strat->S[c_j],(*h).p, currRing->real_var_start-1,currRing);
[36b9ef]273        (*h).p=c_p;
[737e25]274        if (!TEST_OPT_INTSTRATEGY)
275        {
[1558d5]276          if (rField_is_Zp_a(currRing)) p_Content(h->p,currRing);
[a0d9be]277          else h->pCleardenom();// also does a p_Content
[737e25]278        }
279
[d42b51]280#ifdef KDEBUG
[737e25]281        if (TEST_OPT_DEBUG)
282        {
283          PrintS(" to ");
[9a001d]284          wrp(h->p);
[c7a127]285          PrintLn();
[737e25]286        }
[d42b51]287#endif
[737e25]288        if ((*h).p == NULL)
289        {
290          if (h->lcm!=NULL) p_LmFree((*h).lcm, currRing);
291          return 0;
292        }
293        ratGB_divide_out((*h).p);
[1558d5]294        d = currRing->pLDeg((*h).p,&((*h).length),currRing);
295        (*h).FDeg=currRing->pFDeg((*h).p,currRing);
[737e25]296        (*h).ecart = d-(*h).FDeg; /*pFDeg((*h).p);*/
297        /*- try to reduce the s-polynomial again -*/
298        pass++;
[a13cae]299        j=0;
[36b9ef]300        c_j=-1; c_e=-2; c_p=NULL;
[737e25]301      }
302      else
303      { // nothing found
304        return 0;
305      }
306    }
[0047ec]307    // first try usal division
308    if (p_LmDivisibleBy(strat->S[j],(*h).p,currRing))
309    {
[d42b51]310#ifdef KDEBUG
[0047ec]311      if(TEST_OPT_DEBUG)
312      {
[094f80]313        p_wrp(h->p,currRing); Print(" divisible by S[%d]=",j);
[0047ec]314        p_wrp(strat->S[j],currRing); PrintS(" e=-1\n");
315      }
[d42b51]316#endif
[342c80]317      if ((c_j<0)||(c_e>=0))
[0047ec]318      {
319        c_e=-1; c_j=j;
320      }
321    }
322    else
[737e25]323    if (p_LmDivisibleByPart(strat->S[j],(*h).p,currRing,
324        currRing->real_var_start,currRing->real_var_end))
325    {
[1558d5]326      int a_e=(p_Totaldegree(strat->S[j],currRing)-currRing->pFDeg(strat->S[j],currRing));
[d42b51]327#ifdef KDEBUG
[a13cae]328      if(TEST_OPT_DEBUG)
329      {
330        p_wrp(h->p,currRing); Print(" divisibly by S[%d]=",j);
[c7a127]331        p_wrp(strat->S[j],currRing); Print(" e=%d\n",a_e);
[a13cae]332      }
[d42b51]333#endif
[342c80]334      if ((c_j<0)||(c_e>a_e))
[737e25]335      {
336        c_e=a_e; c_j=j;
[342c80]337        //c_p = nc_CreateSpoly(pCopy(strat->S[c_j]),pCopy((*h).p), currRing);
[737e25]338      }
339      /*computes the ecart*/
340      if ((strat->syzComp!=0) && !strat->honey)
341      {
342        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
343        {
[d42b51]344#ifdef KDEBUG
[737e25]345          if (TEST_OPT_DEBUG) PrintS(" > sysComp\n");
[d42b51]346#endif
[737e25]347          return 0;
348        }
349      }
350    }
351    else
352    {
[d42b51]353#ifdef KDEBUG
[a13cae]354      if(TEST_OPT_DEBUG)
355      {
356        p_wrp(h->p,currRing); Print(" not divisibly by S[%d]=",j);
357        p_wrp(strat->S[j],currRing); PrintLn();
358      }
[d42b51]359#endif
[737e25]360    }
361    j++;
362  }
363}
[83f8aff]364#endif
[35aab3]365
366/*2
367*  reduction procedure for the homogeneous case
368*  and the case of a degree-ordering
369*/
[4bbe3b]370static int nc_redHomog (LObject* h,kStrategy strat)
[35aab3]371{
372  if (strat->tl<0)
373  {
374    enterT((*h),strat);
375    return 1;
376  }
377
378  int j = 0;
379
380  if (TEST_OPT_DEBUG)
381  {
382    PrintS("red:");
383    wrp(h->p);
384    PrintS(" ");
385  }
386  loop
387  {
388    if (TEST_OPT_DEBUG) Print("%d",j);
389    if (pDivisibleBy(strat->S[j],(*h).p))
390    {
391      if (TEST_OPT_DEBUG)
392      {
393        PrintS("+\nwith ");
394        wrp(strat->S[j]);
395      }
396      /*- compute the s-polynomial -*/
[19370c]397      (*h).p = nc_ReduceSpoly(strat->S[j],(*h).p,currRing);
[35aab3]398      if ((*h).p == NULL)
399      {
400        if (TEST_OPT_DEBUG) PrintS(" to 0\n");
401        if (h->lcm!=NULL) pLmFree((*h).lcm);
402        (*h).lcm=NULL;
403        return 0;
404      }
405/*
406*      else if (strat->syzComp)
407*      {
408*        if (pMinComp((*h).p) > strat->syzComp)
409*        {
410*          enterT((*h),strat);
411*          return;
412*        }
413*      }
414*/
415      /*- try to reduce the s-polynomial -*/
416      j = 0;
417    }
418    else
419    {
420      if (j >= strat->sl)
421      {
422        enterT((*h),strat);
423        return 1;
424      }
425      j++;
426    }
427  }
428}
429
[5a9e7b]430#if 0
[35aab3]431/*2
432*  reduction procedure for the homogeneous case
433*  and the case of a degree-ordering
434*/
[4bbe3b]435static int nc_redHomog0 (LObject* h,kStrategy strat)
[35aab3]436{
437  if (strat->tl<0)
438  {
439    enterT((*h),strat);
440    return 0;
441  }
442
443  int j = 0;
444  int k = 0;
445
446  if (TEST_OPT_DEBUG)
447  {
448    PrintS("red:");
449    wrp(h->p);
450    PrintS(" ");
451  }
452  loop
453  {
454    if (TEST_OPT_DEBUG) Print("%d",j);
455    if (pDivisibleBy(strat->T[j].p,(*h).p))
456    {
457      if (TEST_OPT_DEBUG)
458      {
459        PrintS("+\nwith ");
460        wrp(strat->S[j]);
461      }
462      /*- compute the s-polynomial -*/
[4bbe3b]463      (*h).p = nc_ReduceSpoly(strat->T[j].p,(*h).p,strat->kNoether,currRing);
[35aab3]464      if ((*h).p == NULL)
465      {
466        if (TEST_OPT_DEBUG) PrintS(" to 0\n");
467        if (h->lcm!=NULL) pLmFree((*h).lcm);
468        (*h).lcm=NULL;
469        return 0;
470      }
[e36a2c0]471      else
[35aab3]472      {
[e36a2c0]473        if (TEST_OPT_INTSTRATEGY)
[35aab3]474        {
[1558d5]475          if (rField_is_Zp_a(currRing)) p_Content(h->p,currRing);
[c0e2c36]476          else h->pCleardenom();// also does a pContent
[e36a2c0]477        }
478        if (strat->syzComp!=0)
479        {
480          if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
481          {
[35aab3]482/*
[e36a2c0]483*           (*h).length=pLength0((*h).p);
[35aab3]484*/
[e36a2c0]485            enterT((*h),strat);
486            return 0;
487          }
[35aab3]488        }
489      }
490      /*- try to reduce the s-polynomial -*/
491      j = 0;
492    }
493    else
494    {
495      if (j >= strat->tl)
496      {
[e36a2c0]497        if (TEST_OPT_INTSTRATEGY)
498        {
[1558d5]499          if (rField_is_Zp_a(currRing)) p_Content(h->p,currRing);
[a0d9be]500          else h->pCleardenom();// also does a p_Content
[e36a2c0]501        }
[35aab3]502/*
503*       (*h).length=pLength0((*h).p);
504*/
505        enterT((*h),strat);
506        return 0;
507      }
508      j++;
509    }
510  }
511}
512
513/*2
514*  reduction procedure for the inhomogeneous case
515*  and not a degree-ordering
516*/
[4bbe3b]517static int nc_redLazy (LObject* h,kStrategy strat)
[35aab3]518{
519  if (strat->tl<0)
520  {
521    enterT((*h),strat);
522    return 0;
523  }
524
525  int at,d,i;
526  int j = 0;
527  int pass = 0;
[1558d5]528  int reddeg = currRing->pFDeg((*h).p,currRing);
[35aab3]529
530  if (TEST_OPT_DEBUG)
531  {
532    PrintS("red:");
533    wrp(h->p);
534    PrintS(" ");
535  }
536  loop
537  {
538    if (TEST_OPT_DEBUG) Print("%d",j);
539    if (pDivisibleBy(strat->S[j],(*h).p))
540    {
541      if (TEST_OPT_DEBUG)
542      {
543        PrintS("+\nwith ");
544        wrp(strat->S[j]);
545      }
546      /*- compute the s-polynomial -*/
[4bbe3b]547      (*h).p = nc_ReduceSpoly(strat->S[j],(*h).p,strat->kNoether,currRing);
[35aab3]548      if ((*h).p == NULL)
549      {
550        if (TEST_OPT_DEBUG) PrintS(" to 0\n");
551        if (h->lcm!=NULL) pLmFree((*h).lcm);
552        (*h).lcm=NULL;
553        return 0;
554      }
555//      else if (strat->syzComp)
556//      {
557//        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
558//        {
559//          if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
[a0d9be]560//          if (TEST_OPT_INTSTRATEGY) p_Content(h->p,currRing);
[35aab3]561//          enterTBba((*h),strat->tl+1,strat);
562//          return;
563//        }
564//      }
[e36a2c0]565      else
[35aab3]566      {
[e36a2c0]567        if (TEST_OPT_DEBUG)
568        {
569          PrintS("to:");
570          wrp((*h).p);
571          PrintLn();
572        }
573        if (TEST_OPT_INTSTRATEGY)
574        {
[a0d9be]575          p_Content(h->p,currRing);
576          //pCleardenom(h->p);// also does a p_Content
[e36a2c0]577        }
[35aab3]578      }
579      /*- try to reduce the s-polynomial -*/
580      pass++;
[1558d5]581      d = currRing->pFDeg((*h).p,currRing);
[35aab3]582      if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
583      {
584        at = posInL11(strat->L,strat->Ll,h,strat);
585        if (at <= strat->Ll)
586        {
587          i=strat->sl+1;
588          do
589          {
590            i--;
591            if (i<0)
592            {
593              enterT((*h),strat);
594              return 0;
595            }
596          }
[e36a2c0]597          while (!pDivisibleBy(strat->S[i],(*h).p));
[35aab3]598          if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at);
599          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
600          (*h).p = NULL;
601          return 0;
602        }
603      }
604      else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d != reddeg))
605      {
606        Print(".%d",d);mflush();
607        reddeg = d;
608      }
609      j = 0;
610    }
611    else
612    {
613      if (TEST_OPT_DEBUG) PrintS("-");
614      if (j >= strat->sl)
615      {
616        if (TEST_OPT_DEBUG) PrintLn();
617        if (TEST_OPT_INTSTRATEGY)
618        {
[1558d5]619          if (rField_is_Zp_a(currRing)) p_Content(h->p,currRing);
[a0d9be]620          else h->pCleardenom();// also does a p_Content
[35aab3]621        }
622        enterT((*h),strat);
623        return 0;
624      }
625      j++;
626    }
627  }
628}
629
630/*2
631*  reduction procedure for the sugar-strategy (honey)
632* reduces h with elements from T choosing first possible
633* element in T with respect to the given ecart
634*/
[4bbe3b]635static int nc_redHoney (LObject*  h,kStrategy strat)
[35aab3]636{
637  if (strat->tl<0)
638  {
639    enterT((*h),strat);
640    return 0;
641  }
642
643  poly pi;
644  int i,j,at,reddeg,d,pass,ei;
645
646  pass = j = 0;
[1558d5]647  d = reddeg = currRing->pFDeg((*h).p,currRing)+(*h).ecart;
[35aab3]648  if (TEST_OPT_DEBUG)
649  {
650    PrintS("red:");
651    wrp((*h).p);
652  }
653  loop
654  {
655    if (TEST_OPT_DEBUG) Print("%d",j);
656    if (pDivisibleBy(strat->T[j].p,(*h).p))
657    {
658      if (TEST_OPT_DEBUG) PrintS("+");
659      pi = strat->T[j].p;
660      ei = strat->T[j].ecart;
661      /*
662      * the polynomial to reduce with (up to the moment) is;
663      * pi with ecart ei
664      */
665      i = j;
666      loop
667      {
668        /*- takes the first possible with respect to ecart -*/
669        i++;
670        if (i > strat->tl)
671          break;
672        if ((!BTEST1(20)) && (ei <= (*h).ecart))
673          break;
674        if (TEST_OPT_DEBUG) Print("%d",i);
675        if ((strat->T[i].ecart < ei) && pDivisibleBy(strat->T[i].p,(*h).p))
676        {
677          if (TEST_OPT_DEBUG) PrintS("+");
678          /*
679          * the polynomial to reduce with is now;
680          */
681          pi = strat->T[i].p;
682          ei = strat->T[i].ecart;
683        }
684        else if (TEST_OPT_DEBUG) PrintS("-");
685      }
686
687      /*
688      * end of search: have to reduce with pi
689      */
690      if (ei > (*h).ecart)
691      {
692        /*
693        * It is not possible to reduce h with smaller ecart;
694        * if possible h goes to the lazy-set L,i.e
695        * if its position in L would be not the last one
696        */
697        if (strat->Ll >= 0) /* L is not empty */
698        {
699          at = strat->posInL(strat->L,strat->Ll,h,strat);
700          if(at <= strat->Ll)
701          /*- h will not become the next element to reduce -*/
702          {
703            enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
704            if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at);
705            (*h).p = NULL;
706            return 0;
707          }
708        }
709      }
710      if (TEST_OPT_DEBUG)
711      {
712        PrintS("\nwith ");
713        wrp(pi);
714      }
715      if (strat->fromT)
716      {
717        strat->fromT=FALSE;
[52e2f6]718        (*h).p = nc_ReduceSpoly(pi,(*h).p,strat->kNoether,currRing);
[35aab3]719      }
720      else
[4bbe3b]721        (*h).p = nc_ReduceSpoly(pi,(*h).p,strat->kNoether,currRing);
[35aab3]722      if (TEST_OPT_DEBUG)
723      {
724        PrintS(" to ");
725        wrp((*h).p);
726        PrintLn();
727      }
728      if ((*h).p == NULL)
729      {
730        if (h->lcm!=NULL) pLmFree((*h).lcm);
731        (*h).lcm=NULL;
732        return 0;
733      }
[e36a2c0]734      if (TEST_OPT_INTSTRATEGY)
735      {
[a0d9be]736        h->pCleardenom();// also does a p_Content
[e36a2c0]737      }
[35aab3]738      /* compute the ecart */
739      if (ei <= (*h).ecart)
[1558d5]740        (*h).ecart = d-currRing->pFDeg((*h).p,currRing);
[35aab3]741      else
[1558d5]742        (*h).ecart = d-currRing->pFDeg((*h).p,currRing)+ei-(*h).ecart;
[35aab3]743//      if (strat->syzComp)
744//      {
745//        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
746//        {
747//          if (TEST_OPT_DEBUG)
748//            PrintS("  >syzComp\n");
[a0d9be]749//          if (TEST_OPT_INTSTRATEGY) p_Content(h->p,currRing);
[35aab3]750//          at=strat->posInT(strat->T,strat->tl,(*h));
751//          enterTBba((*h),at,strat);
752//          return;
753//        }
754//      }
755      /*
756      * try to reduce the s-polynomial h
757      *test first whether h should go to the lazyset L
758      *-if the degree jumps
759      *-if the number of pre-defined reductions jumps
760      */
761      pass++;
[1558d5]762      d = currRing->pFDeg((*h).p,currRing)+(*h).ecart;
[35aab3]763      if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
764      {
765        at = strat->posInL(strat->L,strat->Ll,h,strat);
766        if (at <= strat->Ll)
767        {
768          /*test if h is already standardbasis element*/
769          i=strat->sl+1;
770          do
771          {
772            i--;
773            if (i<0)
774            {
775              enterT((*h),strat);
776              return 0;
777            }
778          } while (!pDivisibleBy(strat->S[i],(*h).p));
779          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
780          if (TEST_OPT_DEBUG)
781            Print(" degree jumped: -> L%d\n",at);
782          (*h).p = NULL;
783          return 0;
784        }
785      }
786      else if (TEST_OPT_PROT && (strat->Ll < 0) && (d > reddeg))
787      {
788        reddeg = d;
789        Print(".%d",d); mflush();
790      }
791      j = 0;
792    }
793    else
794    {
795      if (TEST_OPT_DEBUG) PrintS("-");
796      if (j >= strat->tl)
797      {
798        if (TEST_OPT_DEBUG) PrintLn();
799        if (TEST_OPT_INTSTRATEGY)
800        {
[a0d9be]801          h->pCleardenom();// also does a p_Content
[35aab3]802        }
803        enterT((*h),strat);
804        return 0;
805      }
806      j++;
807    }
808  }
809}
810
811/*2
812*  reduction procedure for tests only
813*  reduces with elements from T and chooses the best possible
814*/
[4bbe3b]815static int nc_redBest (LObject*  h,kStrategy strat)
[35aab3]816{
817  if (strat->tl<0)
818  {
819    enterT((*h),strat);
820    return 0;
821  }
822
823  int j,jbest,at,reddeg,d,pass;
824  poly     p,ph;
825  pass = j = 0;
826
827  if (strat->honey)
[1558d5]828    reddeg = currRing->pFDeg((*h).p,currRing)+(*h).ecart;
[35aab3]829  else
[1558d5]830    reddeg = currRing->pFDeg((*h).p,currRing);
[35aab3]831  loop
832  {
833    if (pDivisibleBy(strat->T[j].p,(*h).p))
834    {
835      /* compute the s-polynomial */
836      if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p);
837#ifdef SDRING
838      // spSpolyShortBba will not work in the SRING case
839      if (pSDRING)
840      {
841        p=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether);
842        if (p!=NULL) pDelete(&pNext(p));
843      }
844      else
845#endif
[4bbe3b]846      p = nc_CreateShortSpoly(strat->T[j].p,(*h).p);
[35aab3]847      /* computes only the first monomial of the spoly  */
848      if (p)
849      {
850        jbest = j;
851        /* looking for the best possible reduction */
852        if ((strat->syzComp==0) || (pMinComp(p) <= strat->syzComp))
853        {
854          loop
855          {
856            j++;
857            if (j > strat->tl)
858              break;
859            if (pDivisibleBy(strat->T[j].p,(*h).p))
860            {
861#ifdef SDRING
862              // spSpolyShortBba will not work in the SRING case
863              if (pSDRING)
864              {
865                ph=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether);
866                if (ph!=NULL) pDelete(&pNext(ph));
867              }
868              else
869#endif
[4bbe3b]870              ph = nc_CreateShortSpoly(strat->T[j].p,(*h).p);
[35aab3]871              if (ph==NULL)
872              {
873                pLmFree(p);
874                pDelete(&((*h).p));
875                if (h->lcm!=NULL)
876                {
877                  pLmFree((*h).lcm);
878                  (*h).lcm=NULL;
879                }
880                return 0;
881              }
882              else if (pLmCmp(ph,p) == -1)
883              {
884                pLmFree(p);
885                p = ph;
886                jbest = j;
887              }
888              else
889              {
890                pLmFree(ph);
891              }
892            }
893          }
894        }
895        pLmFree(p);
[4bbe3b]896        (*h).p = nc_ReduceSpoly(strat->T[jbest].p,(*h).p,strat->kNoether,currRing);
[35aab3]897      }
898      else
899      {
900        if (h->lcm!=NULL)
901        {
902          pLmFree((*h).lcm);
903          (*h).lcm=NULL;
904        }
905        (*h).p = NULL;
906        return 0;
907      }
[fe89b98]908      if (strat->honey && currRing->pLexOrder)
[35aab3]909        strat->initEcart(h);
910      /* h.length:=l; */
911      /* try to reduce the s-polynomial */
912//      if (strat->syzComp)
913//      {
914//        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
915//        {
916//          if (TEST_OPT_DEBUG)
917//            PrintS(" >syzComp\n");
[a0d9be]918//          if (TEST_OPT_INTSTRATEGY) p_Content(h->p,currRing);
[35aab3]919//          at=strat->posInT(strat->T,strat->tl,(*h));
920//          enterTBba((*h),at,strat);
921//          return;
922//        }
923//      }
[fe89b98]924      if (strat->honey || currRing->pLexOrder)
[35aab3]925      {
926        pass++;
[1558d5]927        d = currRing->pFDeg((*h).p,currRing);
[35aab3]928        if (strat->honey)
929          d += (*h).ecart;
930        if ((strat->Ll >= 0) && ((pass > strat->LazyPass) || (d > reddeg)))
931        {
932          at = strat->posInL(strat->L,strat->Ll,h,strat);
933          if (at <= strat->Ll)
934          {
935            enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
936            (*h).p = NULL;
937            return 0;
938          }
939        }
940        else if (TEST_OPT_PROT && (strat->Ll < 0) && (d != reddeg))
941        {
942          reddeg = d;
943          Print("%d.");
944          mflush();
945        }
946      }
947      j = 0;
948    }
949    else
950    {
951      if (j >= strat->tl)
952      {
953        if (TEST_OPT_INTSTRATEGY)
954        {
[a0d9be]955          h->pCleardenom();// also does a p_Content
[35aab3]956        }
957        enterT((*h),strat);
958        return 0;
959      }
960      j++;
961    }
962  }
963}
964
[5a9e7b]965#endif
966
[86016d]967void nc_gr_initBba(ideal F, kStrategy strat)
[35aab3]968{
[5a9e7b]969  assume(rIsPluralRing(currRing));
970
[35aab3]971  int i;
972  idhdl h;
973 /* setting global variables ------------------- */
974  strat->enterS = enterSBba;
[5a9e7b]975
976/*
[35aab3]977  if ((BTEST1(20)) && (!strat->honey))
[4bbe3b]978    strat->red = nc_redBest;
[35aab3]979  else if (strat->honey)
[4bbe3b]980    strat->red = nc_redHoney;
[fe89b98]981  else if (currRing->pLexOrder && !strat->homog)
[4bbe3b]982    strat->red = nc_redLazy;
[35aab3]983  else if (TEST_OPT_INTSTRATEGY && strat->homog)
[4bbe3b]984    strat->red = nc_redHomog0;
[35aab3]985  else
[4bbe3b]986    strat->red = nc_redHomog;
[5a9e7b]987*/
988
989//   if (rIsPluralRing(currRing))
[35aab3]990    strat->red = redGrFirst;
[83f8aff]991#ifdef HAVE_RATGRING
[0b4ec2]992  if (rIsRatGRing(currRing))
[4debf02]993  {
[36b9ef]994    int ii=IDELEMS(F)-1;
995    int jj;
996    BOOLEAN is_rat_id=FALSE;
997    for(;ii>=0;ii--)
998    {
999      for(jj=currRing->real_var_start;jj<=currRing->real_var_end;jj++)
1000      {
1001        if(pGetExp(F->m[ii],jj)>0) { is_rat_id=TRUE; break; }
1002      }
1003      if (is_rat_id) break;
1004    }
1005    if (is_rat_id) strat->red=redGrRatGB;
[4debf02]1006  }
[83f8aff]1007#endif
[5a9e7b]1008
[fe89b98]1009  if (currRing->pLexOrder && strat->honey)
[35aab3]1010    strat->initEcart = initEcartNormal;
1011  else
1012    strat->initEcart = initEcartBBA;
1013  if (strat->honey)
1014    strat->initEcartPair = initEcartPairMora;
1015  else
1016    strat->initEcartPair = initEcartPairBba;
[327d41]1017//  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1018//  {
1019//     //interred  machen   Aenderung
[1558d5]1020//     pFDegOld=currRing->pFDeg;
1021//     pLDegOld=currRing->pLDeg;
[327d41]1022//  //   h=ggetid("ecart");
1023//  //   if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD))
1024//  //   {
1025//  //     ecartWeights=iv2array(IDINTVEC(h));
1026//  //   }
1027//  //   else
1028//    {
1029//      ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
1030//      /*uses automatic computation of the ecartWeights to set them*/
1031//      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1032//    }
[1558d5]1033//    currRing->pFDeg=totaldegreeWecart;
1034//    currRing->pLDeg=maxdegreeWecart;
[327d41]1035//    for(i=1; i<=(currRing->N); i++)
1036//      Print(" %d",ecartWeights[i]);
1037//    PrintLn();
1038//    mflush();
1039//  }
[35aab3]1040}
1041
[52e2f6]1042#define MYTEST 0
1043
[5a9e7b]1044ideal gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat)
[35aab3]1045{
[52e2f6]1046#if MYTEST
1047   PrintS("<gnc_gr_bba>\n");
1048#endif
1049
1050#ifdef HAVE_PLURAL
1051#if MYTEST
1052   PrintS("currRing: \n");
1053   rWrite(currRing);
1054#ifdef RDEBUG
1055   rDebugPrint(currRing);
1056#endif
1057
1058   PrintS("F: \n");
[737e25]1059   idPrint(F);
1060   PrintS("Q: \n");
[52e2f6]1061   idPrint(Q);
1062#endif
1063#endif
1064
[d5e030]1065  assume(currRing->OrdSgn != -1); // no mora!!! it terminates only for global ordering!!! (?)
[5a9e7b]1066
[35aab3]1067  intvec *w=NULL;
1068  intvec *hilb=NULL;
1069  int   srmax,lrmax;
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;
[35aab3]1086  srmax = strat->sl;
1087  reduc = olddeg = lrmax = 0;
[52e2f6]1088
[35aab3]1089  /* compute------------------------------------------------------- */
1090  while (strat->Ll >= 0)
1091  {
1092    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
[52e2f6]1093
[35aab3]1094    if (TEST_OPT_DEBUG) messageSets(strat);
[52e2f6]1095
[35aab3]1096    if (strat->Ll== 0) strat->interpt=TRUE;
1097    if (TEST_OPT_DEGBOUND
[b130fb]1098    && ((strat->honey
[1558d5]1099    && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
1100       || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
[35aab3]1101    {
1102      /*
1103      *stops computation if
1104      * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
1105      *a predefined number Kstd1_deg
1106      */
1107      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1108      break;
1109    }
1110    /* picks the last element from the lazyset L */
1111    strat->P = strat->L[strat->Ll];
1112    strat->Ll--;
[626431]1113    //kTest(strat);
[52e2f6]1114
1115    if (strat->P.p != NULL)
[35aab3]1116    if (pNext(strat->P.p) == strat->tail)
1117    {
1118      /* deletes the short spoly and computes */
1119      pLmFree(strat->P.p);
1120      /* the real one */
[454cb0]1121//      if (ncRingType(currRing)==nc_lie) /* prod crit */
1122//        if(pHasNotCF(strat->P.p1,strat->P.p2))
1123//        {
[52e2f6]1124//          strat->cp++;
[454cb0]1125//          /* prod.crit itself in nc_CreateSpoly */
1126//        }
[737e25]1127
[26d633]1128
[43cbc0]1129      if( ! rIsRatGRing(currRing) )
[26d633]1130      {
[43cbc0]1131        strat->P.p = nc_CreateSpoly(strat->P.p1,strat->P.p2,currRing);
1132      }
[26d633]1133#ifdef HAVE_RATGRING
[43cbc0]1134      else
1135      {
1136        /* rational case */
1137        strat->P.p = nc_rat_CreateSpoly(strat->P.p1,strat->P.p2,currRing->real_var_start-1,currRing);
1138      }
[26d633]1139#endif
[43cbc0]1140
[52e2f6]1141
1142#ifdef PDEBUG
1143      p_Test(strat->P.p, currRing);
1144#endif
1145
1146#if MYTEST
1147      if (TEST_OPT_DEBUG)
[35aab3]1148      {
[52e2f6]1149        PrintS("p1: "); pWrite(strat->P.p1);
1150        PrintS("p2: "); pWrite(strat->P.p2);
1151        PrintS("SPoly: "); pWrite(strat->P.p);
[35aab3]1152      }
[737e25]1153#endif
[35aab3]1154    }
[52e2f6]1155
[737e25]1156
[35aab3]1157    if (strat->P.p != NULL)
1158    {
1159      if (TEST_OPT_PROT)
[52e2f6]1160        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
[35aab3]1161              &olddeg,&reduc,strat, red_result);
[52e2f6]1162
1163#if MYTEST
1164      if (TEST_OPT_DEBUG)
1165      {
1166        PrintS("p1: "); pWrite(strat->P.p1);
1167        PrintS("p2: "); pWrite(strat->P.p2);
1168        PrintS("SPoly before: "); pWrite(strat->P.p);
1169      }
1170#endif
1171
[35aab3]1172      /* reduction of the element chosen from L */
1173      strat->red(&strat->P,strat);
[52e2f6]1174
1175#if MYTEST
1176      if (TEST_OPT_DEBUG)
1177      {
1178        PrintS("red SPoly: "); pWrite(strat->P.p);
1179      }
1180#endif
[35aab3]1181    }
1182    if (strat->P.p != NULL)
1183    {
[c0e2c36]1184      if (TEST_OPT_PROT)
1185      {
1186        PrintS("s\n");
1187      }
1188      /* enter P.p into s and L */
1189      {
[0ffc823]1190/* quick unit detection in the rational case */
1191#ifdef HAVE_RATGRING
1192        if( rIsRatGRing(currRing) )
1193        {
1194          if ( p_LmIsConstantRat(strat->P.p, currRing) )
1195          {
1196#ifdef PDEBUG
1197             Print("unit element detected:"); 
1198             p_wrp(strat->P.p,currRing);
1199#endif
1200            p_Delete(&strat->P.p,currRing, strat->tailRing);
1201            strat->P.p = pOne();
1202          }
1203      }
1204#endif
[c0e2c36]1205        strat->P.sev=0;
1206        int pos=posInS(strat,strat->sl,strat->P.p, strat->P.ecart);
1207        {
1208          if (TEST_OPT_INTSTRATEGY)
[35aab3]1209          {
[c0e2c36]1210            if ((strat->syzComp==0)||(!strat->homog))
1211            {
1212              #ifdef HAVE_RATGRING
1213              if(!rIsRatGRing(currRing))
1214              #endif
1215                strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1216            }
1217
[a0d9be]1218            strat->P.p=p_Cleardenom(strat->P.p, currRing);
[35aab3]1219          }
[c0e2c36]1220          else
[35aab3]1221          {
[c0e2c36]1222            pNorm(strat->P.p);
1223            if ((strat->syzComp==0)||(!strat->homog))
[35aab3]1224            {
[c0e2c36]1225              strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1226            }
1227          }
1228          if (TEST_OPT_DEBUG)
1229          {
1230            PrintS("new s:"); wrp(strat->P.p);
1231            PrintLn();
[52e2f6]1232#if MYTEST
[c0e2c36]1233            Print("s: "); pWrite(strat->P.p);
[52e2f6]1234#endif
[737e25]1235
[c0e2c36]1236          }
1237          // kTest(strat);
1238          //
1239          enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat);
[737e25]1240
[c0e2c36]1241          if (strat->sl==-1) pos=0;
1242          else pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
[737e25]1243
[c0e2c36]1244          strat->enterS(strat->P,pos,strat,-1);
1245        }
1246//      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1247      }
1248      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
[35aab3]1249      if (strat->sl>srmax) srmax = strat->sl;
1250    }
1251#ifdef KDEBUG
1252    strat->P.lcm=NULL;
1253#endif
[626431]1254    //kTest(strat);
[35aab3]1255  }
1256  if (TEST_OPT_DEBUG) messageSets(strat);
[86016d]1257
[35aab3]1258  /* complete reduction of the standard basis--------- */
[07b1cf]1259  if (TEST_OPT_SB_1)
1260  {
1261    int k=1;
1262    int j;
1263    while(k<=strat->sl)
1264    {
1265      j=0;
1266      loop
1267      {
1268        if (j>=k) break;
1269        clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
1270        j++;
1271      }
1272      k++;
1273    }
[86016d]1274  }
1275
[07b1cf]1276  if (TEST_OPT_REDSB)
1277     completeReduce(strat);
[35aab3]1278  /* release temp data-------------------------------- */
1279  exitBuchMora(strat);
[1558d5]1280//  if (TEST_OPT_WEIGHTM)
1281//  {
1282//    currRing->pFDeg=pFDegOld;
1283//    currRing->pLDeg=pLDegOld;
1284//    if (ecartWeights)
1285//    {
1286//      omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
1287//      ecartWeights=NULL;
1288//    }
1289//  }
[35aab3]1290  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
1291  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
[86016d]1292
1293
[e38e91]1294#ifdef PDEBUG
1295/* for counting number of pairs [enterL] in Plural */
1296/*   extern int zaehler; */
1297/*   Print("Total pairs considered:%d\n",zaehler); zaehler=0; */
[7447d8]1298#endif /*PDEBUG*/
[52e2f6]1299
1300#if MYTEST
1301  PrintS("</gnc_gr_bba>\n");
1302#endif
1303
[35aab3]1304  return (strat->Shdl);
1305}
[5a9e7b]1306
1307ideal gnc_gr_mora(const ideal, const ideal, const intvec *, const intvec *, kStrategy)
1308{
1309  PrintS("Sorry, non-commutative mora is not yet implemented!");
1310  PrintLn();
1311
1312  // Not yet!
1313  return NULL;
1314}
1315
[f2f460]1316#endif
[5a9e7b]1317
Note: See TracBrowser for help on using the repository browser.