source: git/kernel/gr_kstd2.cc @ 4d80cd5

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