source: git/kernel/GBEngine/gr_kstd2.cc @ 7203f7

spielwiese
Last change on this file since 7203f7 was 7203f7, checked in by Hans Schoenemann <hannes@…>, 9 years ago
fix (windows port): move reference to NF/BBA stuff to function pointers
  • Property mode set to 100644
File size: 30.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5*  ABSTRACT -  Kernel: noncomm. alg. of Buchberger
6*/
7#define PLURAL_INTERNAL_DECLARATIONS
8
9
10
11
12#include <kernel/mod2.h>
13
14#ifdef HAVE_PLURAL
15
16
17#include <omalloc/omalloc.h>
18#include <misc/options.h>
19#include <misc/intvec.h>
20
21#include <polys/weight.h>
22#include <kernel/polys.h>
23#include <polys/monomials/ring.h>
24
25#include <polys/nc/gb_hack.h>
26#include <polys/nc/nc.h>
27#include <polys/nc/sca.h>
28
29
30#include <kernel/ideals.h>
31#include <kernel/GBEngine/kstd1.h>
32#include <kernel/GBEngine/khstd.h>
33//#include "spolys.h"
34//#include "cntrlc.h"
35#include <kernel/GBEngine/ratgring.h>
36#include <kernel/GBEngine/kutil.h>
37
38#include <kernel/GBEngine/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
971#ifdef HAVE_RATGRING
972void nc_gr_initBba(ideal F, kStrategy strat)
973#else
974void nc_gr_initBba(ideal, kStrategy strat)
975#endif
976{
977  assume(rIsPluralRing(currRing));
978
979  // int i;
980//  idhdl h;
981 /* setting global variables ------------------- */
982  strat->enterS = enterSBba;
983
984/*
985  if ((BTEST1(20)) && (!strat->honey))
986    strat->red = nc_redBest;
987  else if (strat->honey)
988    strat->red = nc_redHoney;
989  else if (currRing->pLexOrder && !strat->homog)
990    strat->red = nc_redLazy;
991  else if (TEST_OPT_INTSTRATEGY && strat->homog)
992    strat->red = nc_redHomog0;
993  else
994    strat->red = nc_redHomog;
995*/
996
997//   if (rIsPluralRing(currRing))
998    strat->red = redGrFirst;
999#ifdef HAVE_RATGRING
1000  if (rIsRatGRing(currRing))
1001  {
1002    int ii=IDELEMS(F)-1;
1003    int jj;
1004    BOOLEAN is_rat_id=FALSE;
1005    for(;ii>=0;ii--)
1006    {
1007      for(jj=currRing->real_var_start;jj<=currRing->real_var_end;jj++)
1008      {
1009        if(pGetExp(F->m[ii],jj)>0) { is_rat_id=TRUE; break; }
1010      }
1011      if (is_rat_id) break;
1012    }
1013    if (is_rat_id) strat->red=redGrRatGB;
1014  }
1015#endif
1016
1017  if (currRing->pLexOrder && strat->honey)
1018    strat->initEcart = initEcartNormal;
1019  else
1020    strat->initEcart = initEcartBBA;
1021  if (strat->honey)
1022    strat->initEcartPair = initEcartPairMora;
1023  else
1024    strat->initEcartPair = initEcartPairBba;
1025//  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1026//  {
1027//     //interred  machen   Aenderung
1028//     pFDegOld=currRing->pFDeg;
1029//     pLDegOld=currRing->pLDeg;
1030//  //   h=ggetid("ecart");
1031//  //   if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD))
1032//  //   {
1033//  //     ecartWeights=iv2array(IDINTVEC(h));
1034//  //   }
1035//  //   else
1036//    {
1037//      ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
1038//      /*uses automatic computation of the ecartWeights to set them*/
1039//      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1040//    }
1041//    currRing->pFDeg=totaldegreeWecart;
1042//    currRing->pLDeg=maxdegreeWecart;
1043//    for(i=1; i<=(currRing->N); i++)
1044//      Print(" %d",ecartWeights[i]);
1045//    PrintLn();
1046//    mflush();
1047//  }
1048}
1049
1050#define MYTEST 0
1051
1052ideal k_gnc_gr_bba(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
1053{
1054  const ring save = currRing; if( currRing != _currRing ) rChangeCurrRing(_currRing);
1055
1056#if MYTEST
1057   PrintS("<gnc_gr_bba>\n");
1058#endif
1059
1060#ifdef HAVE_PLURAL
1061#if MYTEST
1062   PrintS("currRing: \n");
1063   rWrite(currRing);
1064#ifdef RDEBUG
1065   rDebugPrint(currRing);
1066#endif
1067
1068   PrintS("F: \n");
1069   idPrint(F);
1070   PrintS("Q: \n");
1071   idPrint(Q);
1072#endif
1073#endif
1074
1075  assume(currRing->OrdSgn != -1); // no mora!!! it terminates only for global ordering!!! (?)
1076
1077  // intvec *w=NULL;
1078  // intvec *hilb=NULL;
1079  int   olddeg,reduc;
1080  int red_result=1;
1081  int /*hilbeledeg=1,*/hilbcount=0/*,minimcnt=0*/;
1082
1083  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
1084  // initHilbCrit(F,Q,&hilb,strat);
1085  /* in plural we don't need Hilb yet */
1086  nc_gr_initBba(F,strat);
1087  initBuchMoraPos(strat);
1088  if (rIsRatGRing(currRing))
1089  {
1090    strat->posInL=posInL0; // by pCmp of lcm
1091  }
1092  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
1093  /*Shdl=*/initBuchMora(F, Q,strat);
1094  strat->posInT=posInT110;
1095  reduc = olddeg = 0;
1096
1097  /* compute------------------------------------------------------- */
1098  while (strat->Ll >= 0)
1099  {
1100    if (TEST_OPT_DEBUG) messageSets(strat);
1101
1102    if (strat->Ll== 0) strat->interpt=TRUE;
1103    if (TEST_OPT_DEGBOUND
1104    && ((strat->honey
1105    && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
1106       || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
1107    {
1108      /*
1109      *stops computation if
1110      * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
1111      *a predefined number Kstd1_deg
1112      */
1113      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1114      break;
1115    }
1116    /* picks the last element from the lazyset L */
1117    strat->P = strat->L[strat->Ll];
1118    strat->Ll--;
1119    //kTest(strat);
1120
1121    if (strat->P.p != NULL)
1122    if (pNext(strat->P.p) == strat->tail)
1123    {
1124      /* deletes the short spoly and computes */
1125      pLmFree(strat->P.p);
1126      /* the real one */
1127//      if (ncRingType(currRing)==nc_lie) /* prod crit */
1128//        if(pHasNotCF(strat->P.p1,strat->P.p2))
1129//        {
1130//          strat->cp++;
1131//          /* prod.crit itself in nc_CreateSpoly */
1132//        }
1133
1134
1135      if( ! rIsRatGRing(currRing) )
1136      {
1137        strat->P.p = nc_CreateSpoly(strat->P.p1,strat->P.p2,currRing);
1138      }
1139#ifdef HAVE_RATGRING
1140      else
1141      {
1142        /* rational case */
1143        strat->P.p = nc_rat_CreateSpoly(strat->P.p1,strat->P.p2,currRing->real_var_start-1,currRing);
1144      }
1145#endif
1146
1147
1148#ifdef PDEBUG
1149      p_Test(strat->P.p, currRing);
1150#endif
1151
1152#if MYTEST
1153      if (TEST_OPT_DEBUG)
1154      {
1155        PrintS("p1: "); pWrite(strat->P.p1);
1156        PrintS("p2: "); pWrite(strat->P.p2);
1157        PrintS("SPoly: "); pWrite(strat->P.p);
1158      }
1159#endif
1160    }
1161
1162
1163    if (strat->P.p != NULL)
1164    {
1165      if (TEST_OPT_PROT)
1166        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
1167              &olddeg,&reduc,strat, red_result);
1168
1169#if MYTEST
1170      if (TEST_OPT_DEBUG)
1171      {
1172        PrintS("p1: "); pWrite(strat->P.p1);
1173        PrintS("p2: "); pWrite(strat->P.p2);
1174        PrintS("SPoly before: "); pWrite(strat->P.p);
1175      }
1176#endif
1177
1178      /* reduction of the element chosen from L */
1179      strat->red(&strat->P,strat);
1180
1181#if MYTEST
1182      if (TEST_OPT_DEBUG)
1183      {
1184        PrintS("red SPoly: "); pWrite(strat->P.p);
1185      }
1186#endif
1187    }
1188    if (strat->P.p != NULL)
1189    {
1190      if (TEST_OPT_PROT)
1191      {
1192        PrintS("s\n");
1193      }
1194      /* enter P.p into s and L */
1195      {
1196/* quick unit detection in the rational case */
1197#ifdef HAVE_RATGRING
1198        if( rIsRatGRing(currRing) )
1199        {
1200          if ( p_LmIsConstantRat(strat->P.p, currRing) )
1201          {
1202#ifdef PDEBUG
1203             Print("unit element detected:");
1204             p_wrp(strat->P.p,currRing);
1205#endif
1206            p_Delete(&strat->P.p,currRing, strat->tailRing);
1207            strat->P.p = pOne();
1208          }
1209      }
1210#endif
1211        strat->P.sev=0;
1212        int pos=posInS(strat,strat->sl,strat->P.p, strat->P.ecart);
1213        {
1214          if (TEST_OPT_INTSTRATEGY)
1215          {
1216            if ((strat->syzComp==0)||(!strat->homog))
1217            {
1218              #ifdef HAVE_RATGRING
1219              if(!rIsRatGRing(currRing))
1220              #endif
1221                strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1222            }
1223
1224            strat->P.p=p_Cleardenom(strat->P.p, currRing);
1225          }
1226          else
1227          {
1228            pNorm(strat->P.p);
1229            if ((strat->syzComp==0)||(!strat->homog))
1230            {
1231              strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1232            }
1233          }
1234          if (TEST_OPT_DEBUG)
1235          {
1236            PrintS("new s:"); wrp(strat->P.p);
1237            PrintLn();
1238#if MYTEST
1239            Print("s: "); pWrite(strat->P.p);
1240#endif
1241
1242          }
1243          // kTest(strat);
1244          //
1245          enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat);
1246
1247          if (strat->sl==-1) pos=0;
1248          else pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
1249
1250          strat->enterS(strat->P,pos,strat,-1);
1251        }
1252//      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1253      }
1254      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
1255    }
1256#ifdef KDEBUG
1257    strat->P.lcm=NULL;
1258#endif
1259    //kTest(strat);
1260  }
1261  if (TEST_OPT_DEBUG) messageSets(strat);
1262
1263  /* complete reduction of the standard basis--------- */
1264  if (TEST_OPT_SB_1)
1265  {
1266    int k=1;
1267    int j;
1268    while(k<=strat->sl)
1269    {
1270      j=0;
1271      loop
1272      {
1273        if (j>=k) break;
1274        clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
1275        j++;
1276      }
1277      k++;
1278    }
1279  }
1280
1281  if (TEST_OPT_REDSB)
1282     completeReduce(strat);
1283  /* release temp data-------------------------------- */
1284  exitBuchMora(strat);
1285//  if (TEST_OPT_WEIGHTM)
1286//  {
1287//    currRing->pFDeg=pFDegOld;
1288//    currRing->pLDeg=pLDegOld;
1289//    if (ecartWeights)
1290//    {
1291//      omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
1292//      ecartWeights=NULL;
1293//    }
1294//  }
1295  if (TEST_OPT_PROT) messageStat(hilbcount,strat);
1296  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1297
1298
1299#ifdef PDEBUG
1300/* for counting number of pairs [enterL] in Plural */
1301/*   extern int zaehler; */
1302/*   Print("Total pairs considered:%d\n",zaehler); zaehler=0; */
1303#endif /*PDEBUG*/
1304
1305#if MYTEST
1306  PrintS("</gnc_gr_bba>\n");
1307#endif
1308
1309  if( currRing != save )     rChangeCurrRing(save);
1310
1311  return (strat->Shdl);
1312}
1313
1314ideal k_gnc_gr_mora(const ideal F, const ideal Q, const intvec *, const intvec *, kStrategy strat, const ring _currRing)
1315{
1316#ifndef SING_NDEBUG
1317  // Not yet!
1318  WarnS("Sorry, non-commutative mora is not yet implemented!");
1319#endif
1320
1321  return gnc_gr_bba(F, Q, NULL, NULL, strat, _currRing);
1322}
1323
1324#endif
1325
Note: See TracBrowser for help on using the repository browser.