source: git/kernel/gr_kstd2.cc @ 4e654a2

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