source: git/kernel/gr_kstd2.cc @ 327d41

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