source: git/kernel/gr_kstd2.cc @ a13cae

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