source: git/kernel/GBEngine/gr_kstd2.cc @ dd940b

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