source: git/kernel/gr_kstd2.cc @ d42b51

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