source: git/Singular/kstd2.cc @ 6f1610

spielwiese
Last change on this file since 6f1610 was 6f1610, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* ideals: fix in idModulo * k* fix initSSpecial * mmbt: don't track on new git-svn-id: file:///usr/local/Singular/svn/trunk@3835 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 20.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kstd2.cc,v 1.40 1999-11-17 12:09:25 obachman Exp $ */
5/*
6*  ABSTRACT -  Kernel: alg. of Buchberger
7*/
8
9#include "mod2.h"
10#include "tok.h"
11#include "mmemory.h"
12#include "polys.h"
13#include "ideals.h"
14#include "febase.h"
15#include "kutil.h"
16#include "kstd1.h"
17#include "khstd.h"
18#include "cntrlc.h"
19#include "weight.h"
20#include "ipid.h"
21#include "ipshell.h"
22#include "intvec.h"
23
24// #include "timer.h"
25
26/*2
27* consider the part above syzComp:
28* (assume the polynomial comes from a syz computation)
29* - it is a constant term: return a copy of it
30* - else: return NULL
31*/
32static poly kFromInput(poly p,kStrategy strat)
33{
34  poly q=p;
35
36  if (pGetComp(q)>strat->syzComp) return NULL;
37  while ((q!=NULL) && (pGetComp(q)<=strat->syzComp)) pIter(q);
38  if (pIsConstantComp(q))
39    return pHead(q);
40  return NULL;
41}
42
43/*2
44*  reduction procedure for the homogeneous case
45*  and the case of a degree-ordering
46*/
47static int redHomog (LObject* h,kStrategy strat)
48{
49  if (strat->tl<0) return 1;
50#ifdef KDEBUG
51  if (TEST_OPT_DEBUG)
52  {
53    PrintS("red:");
54    wrp(h->p);
55    PrintS(" ");
56  }
57#endif
58  int j;
59  unsigned long not_sev;
60  while (1)
61  {
62    j = 0;
63    h->sev = pGetShortExpVector(h->p);
64    not_sev = ~ h->sev;
65    while ( j <= strat->tl)
66    {
67      if (pShortDivisibleBy(strat->T[j].p, strat->T[j].sev, 
68                            h->p, not_sev)) break;
69      j++;
70    }
71
72    if (j > strat->tl) return 1;
73
74    // now we found one which is divisible
75    ksReducePoly(h, &(strat->T[j]), strat->kNoether);
76#ifdef KDEBUG
77    if (TEST_OPT_DEBUG)
78    {
79      PrintS("\nto ");
80      wrp(h->p);
81      PrintLn();
82    }
83#endif
84    if (h->p == NULL)
85    {
86      if (h->lcm!=NULL) pFree1((*h).lcm);
87#ifdef KDEBUG
88      (*h).lcm=NULL;
89#endif
90      return 0;
91    }
92  }
93}
94
95
96/*2
97*  reduction procedure for the inhomogeneous case
98*  and not a degree-ordering
99*/
100static int redLazy (LObject* h,kStrategy strat)
101{
102  if (strat->tl<0) return 1;
103  int at,d,i;
104  int j = 0;
105  int pass = 0;
106  int reddeg = pFDeg((*h).p);
107  int not_sev;
108
109  h->sev = pGetShortExpVector(h->p);
110  not_sev = ~ h->sev;
111  while (1)
112  {
113    j = 0;
114    while (j <= strat->tl)
115    {
116      if (pShortDivisibleBy(strat->T[j].p,strat->T[j].sev,
117                            h->p, not_sev))
118          break;
119      j++;
120    }
121
122    if (j>strat->tl) return 1;
123
124    if (TEST_OPT_DEBUG)
125    {
126      PrintS("red:");
127      wrp(h->p);
128      PrintS(" with ");
129      wrp(strat->T[j].p);
130    }
131
132    ksReducePoly(h, &(strat->T[j]), strat->kNoether);
133
134    if (TEST_OPT_DEBUG)
135    {
136      PrintS("\nto ");
137      wrp(h->p);
138      PrintLn();
139    }
140
141    if ((*h).p == NULL)
142    {
143      if (h->lcm!=NULL) pFree1((*h).lcm);
144#ifdef KDEBUG
145      (*h).lcm=NULL;
146#endif
147      return 0;
148    }
149    h->sev = pGetShortExpVector(h->p);
150    not_sev = ~ h->sev;
151    /*- try to reduce the s-polynomial -*/
152    pass++;
153    d = pFDeg((*h).p);
154    if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
155    {
156      at = posInL11(strat->L,strat->Ll,*h,strat);
157      if (at <= strat->Ll)
158      {
159        i=strat->sl+1;
160        do
161        {
162          i--;
163          if (i<0) return 1;
164        }
165        while (!pShortDivisibleBy(strat->S[i], strat->sevS[i], 
166                                  h->p, not_sev));
167        if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at);
168        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
169        (*h).p = NULL;
170        return -1;
171      }
172    }
173    else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d != reddeg))
174    {
175      Print(".%d",d);mflush();
176      reddeg = d;
177    }
178  }
179}
180
181/*2
182*  reduction procedure for the sugar-strategy (honey)
183* reduces h with elements from T choosing first possible
184* element in T with respect to the given ecart
185*/
186static int redHoney (LObject*  h,kStrategy strat)
187{
188  if (strat->tl<0) return 1;
189
190  poly pi;
191  int i,j,at,reddeg,d,pass,ei, ii;
192  unsigned long not_sev;
193
194  pass = j = 0;
195  d = reddeg = pFDeg((*h).p)+(*h).ecart;
196  h->sev = pGetShortExpVector(h->p);
197  not_sev = ~ h->sev;
198  loop
199  {
200    j = 0;
201    while (j<= strat->tl)
202    {
203      if (pShortDivisibleBy(strat->T[j].p, strat->T[j].sev, 
204                            h->p, not_sev)) break;
205      j++;
206    }
207
208    if (j > strat->tl)
209    {
210      h->sev = ~ not_sev;
211      return 1;
212    }
213
214    pi = strat->T[j].p;
215    ei = strat->T[j].ecart;
216    ii = j;
217    /*
218     * the polynomial to reduce with (up to the moment) is;
219     * pi with ecart ei
220     */
221    i = j;
222    loop
223    {
224      /*- takes the first possible with respect to ecart -*/
225      i++;
226      if (i > strat->tl)
227        break;
228      if ((!BTEST1(20)) && (ei <= (*h).ecart))
229        break;
230      if ((strat->T[i].ecart < ei) && 
231          pShortDivisibleBy(strat->T[i].p, strat->T[i].sev,
232                            h->p, not_sev))
233      {
234        /*
235         * the polynomial to reduce with is now;
236         */
237        pi = strat->T[i].p;
238        ei = strat->T[i].ecart;
239        ii = i;
240      }
241    }
242
243    /*
244     * end of search: have to reduce with pi
245     */
246    if ((pass!=0) && (ei > (*h).ecart))
247    {
248      /*
249       * It is not possible to reduce h with smaller ecart;
250       * if possible h goes to the lazy-set L,i.e
251       * if its position in L would be not the last one
252       */
253      if (strat->Ll >= 0) /* L is not empty */
254      {
255        at = strat->posInL(strat->L,strat->Ll,*h,strat);
256        if(at <= strat->Ll)
257          /*- h will not become the next element to reduce -*/
258        {
259          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
260          if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at);
261          (*h).p = NULL;
262          return -1;
263        }
264      }
265      if (TEST_OPT_MOREPAIRS)
266      {
267        /*put the polynomial also in the pair set*/
268        strat->fromT = TRUE;
269        if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p);
270        enterpairs((*h).p,strat->sl,(*h).ecart,0,strat);
271      }
272    }
273    if (TEST_OPT_DEBUG)
274    {
275      PrintS("red:");
276      wrp(h->p);
277      PrintS(" with ");
278      wrp(pi);
279    }
280    if (strat->fromT)
281    {
282      strat->fromT=FALSE;
283      h->p = pCopy(h->p);
284    }
285    ksReducePoly(h, &(strat->T[ii]), strat->kNoether);
286    if (TEST_OPT_DEBUG)
287    {
288      PrintS("\nto ");
289      wrp(h->p);
290      PrintLn();
291    }
292    if ((*h).p == NULL)
293    {
294      if (h->lcm!=NULL) pFree1((*h).lcm);
295#ifdef KDEBUG
296      (*h).lcm=NULL;
297#endif
298      return 0;
299    }
300    h->sev = pGetShortExpVector(h->p);
301    not_sev = ~ h->sev;
302    /* compute the ecart */
303    if (ei <= (*h).ecart)
304      (*h).ecart = d-pFDeg((*h).p);
305    else
306      (*h).ecart = d-pFDeg((*h).p)+ei-(*h).ecart;
307    /*
308     * try to reduce the s-polynomial h
309     *test first whether h should go to the lazyset L
310     *-if the degree jumps
311     *-if the number of pre-defined reductions jumps
312     */
313    pass++;
314    d = pFDeg((*h).p)+(*h).ecart;
315    if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
316    {
317      at = strat->posInL(strat->L,strat->Ll,*h,strat);
318      if (at <= strat->Ll)
319      {
320        /*test if h is already standardbasis element*/
321        i=strat->sl+1;
322        do
323        {
324          i--;
325          if (i<0) return 1;
326        } while (!pShortDivisibleBy(strat->S[i], strat->sevS[i], 
327                                    h->p, not_sev));
328        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
329        if (TEST_OPT_DEBUG)
330          Print(" degree jumped: -> L%d\n",at);
331        (*h).p = NULL;
332        return -1;
333      }
334    }
335    else if (TEST_OPT_PROT && (strat->Ll < 0) && (d > reddeg))
336    {
337      reddeg = d;
338      Print(".%d",d); mflush();
339    }
340  }
341}
342
343/*2
344*  reduction procedure for tests only
345*  reduces with elements from T and chooses the best possible
346*/
347static int redBest (LObject*  h,kStrategy strat)
348{
349  if (strat->tl<0) return 1;
350  int j,jbest,at,reddeg,d,pass;
351  poly     p,ph;
352  pass = j = 0;
353
354  if (strat->honey)
355    reddeg = pFDeg((*h).p)+(*h).ecart;
356  else
357    reddeg = pFDeg((*h).p);
358  loop
359  {
360    if (pDivisibleBy(strat->T[j].p,(*h).p))
361    {
362      //if (strat->interpt) test_int_std(strat->kIdeal);
363      /* compute the s-polynomial */
364      if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p);
365      p = ksCreateShortSpoly(strat->T[j].p,(*h).p);
366      /* computes only the first monomial of the spoly  */
367      if (p)
368      {
369        jbest = j;
370        /* looking for the best possible reduction */
371        if ((strat->syzComp==0) || (pMinComp(p) <= strat->syzComp))
372        {
373          loop
374          {
375            j++;
376            if (j > strat->tl)
377              break;
378            if (pDivisibleBy(strat->T[j].p,(*h).p))
379            {
380              ph = ksCreateShortSpoly(strat->T[j].p,(*h).p);
381              if (ph==NULL)
382              {
383                pFree1(p);
384                pDelete(&((*h).p));
385                if (h->lcm!=NULL) pFree1((*h).lcm);
386#ifdef KDEBUG
387                (*h).lcm=NULL;
388#endif
389                return 0;
390              }
391              else if (pComp0(ph,p) == -1)
392              {
393                pFree1(p);
394                p = ph;
395                jbest = j;
396              }
397              else
398              {
399                pFree1(ph);
400              }
401            }
402          }
403        }
404        pFree1(p);
405        (*h).p = ksOldSpolyRed(strat->T[jbest].p,(*h).p,strat->kNoether);
406      }
407      else
408      {
409        if (h->lcm!=NULL) pFree1((*h).lcm);
410#ifdef KDEBUG
411        (*h).lcm=NULL;
412#endif
413        (*h).p = NULL;
414        return 0;
415      }
416      if (strat->honey && pLexOrder)
417        strat->initEcart(h);
418      if (strat->honey || pLexOrder)
419      {
420        pass++;
421        d = pFDeg((*h).p);
422        if (strat->honey)
423          d += (*h).ecart;
424        if ((strat->Ll >= 0) && ((pass > strat->LazyPass) || (d > reddeg)))
425        {
426          at = strat->posInL(strat->L,strat->Ll,*h,strat);
427          if (at <= strat->Ll)
428          {
429            enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
430            (*h).p = NULL;
431            return -1;
432          }
433        }
434        else if (TEST_OPT_PROT && (strat->Ll < 0) && (d != reddeg))
435        {
436          reddeg = d;
437          Print("%d.");
438          mflush();
439        }
440      }
441      j = 0;
442    }
443    else
444    {
445      if (j >= strat->tl) return 1;
446      j++;
447    }
448  }
449}
450
451/*2
452*  reduction procedure for the normal form
453*/
454
455static poly redNF (poly h,kStrategy strat)
456{
457  int j = 0;
458  int z = 3;
459  unsigned long not_sev;
460
461  if (0 > strat->sl)
462  {
463    return h;
464  }
465  not_sev = ~ pGetShortExpVector(h);
466  loop
467  {
468    if (pShortDivisibleBy(strat->S[j], strat->sevS[j], h, not_sev))
469    {
470      //if (strat->interpt) test_int_std(strat->kIdeal);
471      /*- compute the s-polynomial -*/
472      if (TEST_OPT_DEBUG)
473      {
474        PrintS("red:");
475        wrp(h);
476        PrintS(" with ");
477        wrp(strat->S[j]);
478      }
479      h = ksOldSpolyRed(strat->S[j],h,strat->kNoether);
480      if (TEST_OPT_DEBUG)
481      {
482        PrintS("\nto:");
483        wrp(h);
484        PrintLn();
485      }
486      if (h == NULL) return NULL;
487      z++;
488      if (z>=10)
489      {
490        z=0;
491        pNormalize(h);
492      }
493      /*- try to reduce the s-polynomial -*/
494      j = 0;
495      not_sev = ~ pGetShortExpVector(h);
496    }
497    else
498    {
499      if (j >= strat->sl) return h;
500      j++;
501    }
502  }
503}
504
505void initBba(ideal F,kStrategy strat)
506{
507  int i;
508  idhdl h;
509 /* setting global variables ------------------- */
510  strat->enterS = enterSBba;
511  if ((BTEST1(20)) && (!strat->honey))
512    strat->red = redBest;
513  else if (strat->honey)
514    strat->red = redHoney;
515  else if (pLexOrder && !strat->homog)
516    strat->red = redLazy;
517  else
518    strat->red = redHomog;
519  if (pLexOrder && strat->honey)
520    strat->initEcart = initEcartNormal;
521  else
522    strat->initEcart = initEcartBBA;
523  if (strat->honey)
524    strat->initEcartPair = initEcartPairMora;
525  else
526    strat->initEcartPair = initEcartPairBba;
527  strat->kIdeal = NULL;
528  //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD;
529  //else              strat->kIdeal->rtyp=MODUL_CMD;
530  //strat->kIdeal->data=(void *)strat->Shdl;
531  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
532  {
533    //interred  machen   Aenderung
534    pFDegOld=pFDeg;
535    pLDegOld=pLDeg;
536    h=ggetid("ecart");
537    if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD))
538    {
539      ecartWeights=iv2array(IDINTVEC(h));
540    }
541    else
542    {
543      ecartWeights=(short *)Alloc((pVariables+1)*sizeof(short));
544      /*uses automatic computation of the ecartWeights to set them*/
545      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
546    }
547    pFDeg=totaldegreeWecart;
548    pLDeg=maxdegreeWecart;
549    for(i=1; i<=pVariables; i++)
550      Print(" %d",ecartWeights[i]);
551    PrintLn();
552    mflush();
553  }
554}
555
556void kinitBbaHeaps(kStrategy heap)
557{
558#if 0
559  // use extra heap for monoms of T, if not syzcomp
560  if (!strat->red == redSyz)
561  {
562    strat->THeap = mmCreateTempHeap();
563  }
564#endif
565}
566
567ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
568{
569  int   srmax,lrmax, red_result;
570  int   olddeg,reduc;
571  int hilbeledeg=1,hilbcount=0,minimcnt=0;
572
573  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
574  initBuchMoraPos(strat);
575  initHilbCrit(F,Q,&hilb,strat);
576  initBba(F,strat);
577  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
578  /*Shdl=*/initBuchMora(F, Q,strat);
579  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
580  kinitBbaHeaps(strat);
581  srmax = strat->sl;
582  reduc = olddeg = lrmax = 0;
583  /* compute------------------------------------------------------- */
584  kTest_TS(strat);
585  while (strat->Ll >= 0)
586  {
587    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
588    if (TEST_OPT_DEBUG) messageSets(strat);
589    if (strat->Ll== 0) strat->interpt=TRUE;
590    if (TEST_OPT_DEGBOUND
591        && ((strat->honey && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))
592            || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))))
593    {
594      /*
595       *stops computation if
596       * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
597       *a predefined number Kstd1_deg
598       */
599      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
600      break;
601    }
602    /* picks the last element from the lazyset L */
603    strat->P = strat->L[strat->Ll];
604    strat->Ll--;
605
606    if (pNext(strat->P.p) == strat->tail)
607    {
608      /* deletes the short spoly and computes */
609      pFree1(strat->P.p);
610      /* the real one */
611      ksCreateSpoly(&(strat->P),
612                    strat->kNoether);
613    }
614    if((strat->P.p1==NULL) && (strat->minim>0)) strat->P.p2=pCopy(strat->P.p);
615
616    if (TEST_OPT_PROT)
617      message((strat->honey ? strat->P.ecart : 0) + pFDeg(strat->P.p),
618              &olddeg,&reduc,strat);
619
620    kTest_TS(strat);
621    /* reduction of the element choosen from L */
622    red_result = strat->red(&strat->P,strat);
623
624    // reduktion to non-zero new poly
625    if (red_result == 1)
626    {
627      kTest_TS(strat);
628      /* statistic */
629      if (TEST_OPT_PROT) PrintS("s");
630      /* enter P.p into s and L */
631      {
632        int pos=posInS(strat->S,strat->sl,strat->P.p);
633        if (TEST_OPT_INTSTRATEGY)
634        {
635          pCleardenom(strat->P.p);
636          strat->P.p = redtailBba(strat->P.p,pos-1,strat);
637          pCleardenom(strat->P.p);
638        }
639        else
640        {
641          pNorm(strat->P.p);
642          strat->P.p = redtailBba(strat->P.p,pos-1,strat);
643        }
644
645        if (TEST_OPT_DEBUG){PrintS("new s:");wrp(strat->P.p);PrintLn();}
646
647        if ((strat->P.p1==NULL) && (strat->minim>0))
648        {
649          if (strat->minim==1)
650          {
651            strat->M->m[minimcnt]=pCopy(strat->P.p);
652            pDelete(&strat->P.p2);
653          }
654          else
655          {
656            strat->M->m[minimcnt]=strat->P.p2;
657            strat->P.p2=NULL;
658          }
659          minimcnt++;
660        }
661
662        // put stuff into T-Set
663        enterTBba(strat->P, strat->posInT(strat->T,strat->tl,strat->P), 
664                  strat);
665        enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat);
666        // posInS only depends only onthe leading term
667        strat->enterS(strat->P, pos, strat);
668        if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
669      }
670      if (strat->P.lcm!=NULL) pFree1(strat->P.lcm);
671      if (strat->sl>srmax) srmax = strat->sl;
672    }
673#ifdef KDEBUG
674    strat->P.lcm=NULL;
675#endif
676    kTest_TS(strat);
677  }
678  if (TEST_OPT_DEBUG) messageSets(strat);
679  /* complete reduction of the standard basis--------- */
680  if (TEST_OPT_REDSB) completeReduce(strat);
681  /* release temp data-------------------------------- */
682  exitBuchMora(strat);
683  if (TEST_OPT_WEIGHTM)
684  {
685    pFDeg=pFDegOld;
686    pLDeg=pLDegOld;
687    if (ecartWeights)
688    {
689      Free((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
690      ecartWeights=NULL;
691    }
692  }
693  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
694  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
695  return (strat->Shdl);
696}
697
698poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce)
699{
700  poly   p;
701  int   i;
702
703  if ((idIs0(F))&&(Q==NULL))
704    return pCopy(q); /*F=0*/
705  strat->ak = idRankFreeModule(F);
706  /*- creating temp data structures------------------- -*/
707  BITSET save_test=test;
708  test|=Sy_bit(OPT_REDTAIL);
709  initBuchMoraCrit(strat);
710  strat->initEcart = initEcartBBA;
711  strat->enterS = enterSBba;
712  /*- set S -*/
713  strat->sl = -1;
714  /*- init local data struct.---------------------------------------- -*/
715  /*Shdl=*/initS(F,Q,strat);
716  /*- compute------------------------------------------------------- -*/
717  if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
718  {
719    for (i=strat->sl;i>=0;i--)
720      pNorm(strat->S[i]);
721  }
722  kTest(strat);
723  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
724  p = redNF(pCopy(q),strat);
725  if ((p!=NULL)&&(lazyReduce==0))
726  {
727    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
728    p = redtailBba(p,strat->sl,strat);
729  }
730  /*- release temp data------------------------------- -*/
731  if (strat->ecartS != NULL)
732    Free((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
733  if (strat->sevS != NULL)
734    Free((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
735  idDelete(&strat->Shdl);
736  test=save_test;
737  if (TEST_OPT_PROT) PrintLn();
738  return p;
739}
740
741ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce)
742{
743  poly   p;
744  int   i;
745  ideal res;
746
747  if (idIs0(q))
748    return idInit(1,q->rank);
749  if ((idIs0(F))&&(Q==NULL))
750    return idCopy(q); /*F=0*/
751  strat->ak = idRankFreeModule(F);
752  /*- creating temp data structures------------------- -*/
753  BITSET save_test=test;
754  test|=Sy_bit(OPT_REDTAIL);
755  initBuchMoraCrit(strat);
756  strat->initEcart = initEcartBBA;
757  strat->enterS = enterSBba;
758  /*- set S -*/
759  strat->sl = -1;
760  /*- init local data struct.---------------------------------------- -*/
761  /*Shdl=*/initS(F,Q,strat);
762  /*- compute------------------------------------------------------- -*/
763  res=idInit(IDELEMS(q),q->rank);
764  if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
765  {
766    for (i=strat->sl;i>=0;i--)
767      pNorm(strat->S[i]);
768  }
769  for (i=IDELEMS(q)-1; i>=0; i--)
770  {
771    if (q->m[i]!=NULL)
772    {
773      if (TEST_OPT_PROT) { PrintS("r");mflush(); }
774      p = redNF(pCopy(q->m[i]),strat);
775      if ((p!=NULL)&&(lazyReduce==0))
776      {
777        if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
778        p = redtailBba(p,strat->sl,strat);
779      }
780      res->m[i]=p;
781    }
782    //else
783    //  res->m[i]=NULL;
784  }
785  /*- release temp data------------------------------- -*/
786  if (strat->ecartS != NULL)
787    Free((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
788  if (strat->sevS != NULL)
789    Free((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
790  idDelete(&strat->Shdl);
791  test=save_test;
792  if (TEST_OPT_PROT) PrintLn();
793  return res;
794}
795
796static ideal bbared (ideal F, ideal Q,kStrategy strat)
797{
798
799  /* complete reduction of the standard basis--------- */
800  completeReduce(strat);
801  /* release temp data-------------------------------- */
802  exitBuchMora(strat);
803  if (TEST_OPT_WEIGHTM)
804  {
805    pFDeg=pFDegOld;
806    pLDeg=pLDegOld;
807    if (ecartWeights)
808    {
809      Free((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
810      ecartWeights=NULL;
811    }
812  }
813  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
814  return (strat->Shdl);
815}
816
817ideal stdred(ideal F, ideal Q, tHomog h,intvec ** w)
818{
819  ideal r;
820  BOOLEAN b=pLexOrder,toReset=FALSE;
821  BOOLEAN delete_w=(w==NULL);
822  kStrategy strat=(kStrategy)Alloc0SizeOf(skStrategy);
823
824  if (rField_has_simple_inverse())
825    strat->LazyPass=20;
826  else
827   strat->LazyPass=2;
828  strat->LazyDegree = 1;
829  strat->ak = idRankFreeModule(F);
830  if ((h==testHomog))
831  {
832    if (strat->ak==0)
833    {
834      h = (tHomog)idHomIdeal(F,Q);
835      w=NULL;
836    }
837    else
838      h = (tHomog)idHomModule(F,Q,w);
839  }
840  if (h==isHomog)
841  {
842    if ((w!=NULL) && (*w!=NULL))
843    {
844      kModW = *w;
845      strat->kModW = *w;
846      pOldFDeg = pFDeg;
847      pFDeg = kModDeg;
848      toReset = TRUE;
849    }
850    pLexOrder = TRUE;
851    strat->LazyPass*=2;
852  }
853  strat->homog=h;
854  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
855  initBuchMoraPos(strat);
856  if (pOrdSgn==1)
857    initBba(F,strat);
858  else
859    initMora(F,strat);
860  initBuchMora(F, Q,strat);
861  //initS(F,Q,strat);
862// Ende der Initalisierung
863  r=bbared(F,Q,strat);
864#ifdef KDEBUG
865  int i;
866  for (i=0; i<IDELEMS(r); i++) pTest(r->m[i]);
867#endif
868// Ende: aufraeumen
869  if (toReset)
870  {
871    kModW = NULL;
872    pFDeg = pOldFDeg;
873  }
874  pLexOrder = b;
875  kFreeStrat(strat);
876  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
877  idSkipZeroes(r);
878  return r;
879}
Note: See TracBrowser for help on using the repository browser.