source: git/kernel/gr_kstd2.cc @ 7b8818

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