source: git/kernel/gr_kstd2.cc @ b172c3

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