source: git/Singular/kstd2.cc @ 48aa42

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