source: git/kernel/gr_kstd2.cc @ 342c80

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