source: git/kernel/gr_kstd2.cc @ c7aad0

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