source: git/Singular/kstd2.cc @ 7e5a38

spielwiese
Last change on this file since 7e5a38 was 7e5a38, checked in by Olaf Bachmann <obachman@…>, 23 years ago
* dynamic loading of p_Procs git-svn-id: file:///usr/local/Singular/svn/trunk@4833 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.65 2000-12-07 15:03:55 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        h->CanonicalizeP();
217        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
218        h->Clear();
219        return -1;
220      }
221    }
222    else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d != reddeg))
223    {
224      Print(".%d",d);mflush();
225      reddeg = d;
226    }
227  }
228}
229
230/*2
231*  reduction procedure for the sugar-strategy (honey)
232* reduces h with elements from T choosing first possible
233* element in T with respect to the given ecart
234*/
235static int redHoney (LObject* h, kStrategy strat)
236{
237  if (strat->tl<0) return 1;
238  assume(h->FDeg == h->pFDeg());
239
240  poly h_p;
241  int i,j,at,pass,ei, ii, h_d;
242  unsigned long not_sev;
243  long reddeg,d;
244 
245  pass = j = 0;
246  d = reddeg = h->GetpFDeg() + h->ecart;
247  h->SetShortExpVector();
248  h_p = h->GetLmTailRing();
249  not_sev = ~ h->sev;
250  loop
251  {
252    j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h);
253    if (j < 0) return 1;
254
255    ei = strat->T[j].ecart;
256    ii = j;
257    /*
258     * the polynomial to reduce with (up to the moment) is;
259     * pi with ecart ei
260     */
261    i = j;
262    loop
263    {
264      /*- takes the first possible with respect to ecart -*/
265      i++;
266      if (i > strat->tl)
267        break;
268      if (ei <= h->ecart)
269        break;
270      if ((strat->T[i].ecart < ei) && 
271          p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], 
272                               h_p, not_sev, strat->tailRing))
273      {
274        /*
275         * the polynomial to reduce with is now;
276         */
277        ei = strat->T[i].ecart;
278        ii = i;
279      }
280    }
281
282    /*
283     * end of search: have to reduce with pi
284     */
285    if ((pass!=0) && (ei > h->ecart))
286    {
287      h->SetLmCurrRing();
288      /*
289       * It is not possible to reduce h with smaller ecart;
290       * if possible h goes to the lazy-set L,i.e
291       * if its position in L would be not the last one
292       */
293      if (strat->Ll >= 0) /* L is not empty */
294      {
295        at = strat->posInL(strat->L,strat->Ll,h,strat);
296        if(at <= strat->Ll)
297          /*- h will not become the next element to reduce -*/
298        {
299          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
300#ifdef KDEBUG
301          if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at);
302#endif
303          h->Clear();
304          return -1;
305        }
306      }
307    }
308#ifdef KDEBUG
309    if (TEST_OPT_DEBUG)
310    {
311      PrintS("red:");
312      h->wrp();
313      PrintS(" with ");
314      strat->T[ii].wrp();
315    }
316#endif
317    assume(strat->fromT == FALSE);
318
319    ksReducePoly(h, &(strat->T[ii]), strat->kNoether, NULL, strat);
320
321#ifdef KDEBUG
322    if (TEST_OPT_DEBUG)
323    {
324      PrintS("\nto ");
325      h->wrp();
326      PrintLn();
327    }
328#endif
329
330    h_p = h->GetLmTailRing();
331    if (h_p == NULL)
332    {
333      if (h->lcm!=NULL) pLmFree(h->lcm);
334#ifdef KDEBUG
335      h->lcm=NULL;
336#endif
337      return 0;
338    }
339    h->SetShortExpVector();
340    not_sev = ~ h->sev;
341    h_d = h->SetpFDeg();
342    /* compute the ecart */
343    if (ei <= h->ecart)
344      h->ecart = d-h_d;
345    else
346      h->ecart = d-h_d+ei-h->ecart;
347    /*
348     * try to reduce the s-polynomial h
349     *test first whether h should go to the lazyset L
350     *-if the degree jumps
351     *-if the number of pre-defined reductions jumps
352     */
353    pass++;
354    d = h_d + h->ecart;
355    if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
356    {
357      h->SetLmCurrRing();
358      at = strat->posInL(strat->L,strat->Ll,h,strat);
359      if (at <= strat->Ll)
360      {
361        if (kFindDivisibleByInS(strat->S, strat->sevS, strat->sl, h) < 0)
362          return 1;
363        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
364#ifdef KDEBUG
365        if (TEST_OPT_DEBUG)
366          Print(" degree jumped: -> L%d\n",at);
367#endif
368        h->Clear();
369        return -1;
370      }
371    }
372    else if (TEST_OPT_PROT && (strat->Ll < 0) && (d > reddeg))
373    {
374      reddeg = d;
375      Print(".%d",d); mflush();
376    }
377  }
378}
379/*2
380*  reduction procedure for the normal form
381*/
382
383static poly redNF (poly h,kStrategy strat)
384{
385  int j = 0;
386  int z = 3;
387  unsigned long not_sev;
388
389  if (0 > strat->sl)
390  {
391    return h;
392  }
393  not_sev = ~ pGetShortExpVector(h);
394  loop
395  {
396    if (pLmShortDivisibleBy(strat->S[j], strat->sevS[j], h, not_sev))
397    {
398      //if (strat->interpt) test_int_std(strat->kIdeal);
399      /*- compute the s-polynomial -*/
400#ifdef KDEBUG
401      if (TEST_OPT_DEBUG)
402      {
403        PrintS("red:");
404        wrp(h);
405        PrintS(" with ");
406        wrp(strat->S[j]);
407      }
408#endif
409      h = ksOldSpolyRed(strat->S[j],h,strat->kNoether);
410#ifdef KDEBUG
411      if (TEST_OPT_DEBUG)
412      {
413        PrintS("\nto:");
414        wrp(h);
415        PrintLn();
416      }
417#endif
418      if (h == NULL) return NULL;
419      z++;
420      if (z>=10)
421      {
422        z=0;
423        pNormalize(h);
424      }
425      /*- try to reduce the s-polynomial -*/
426      j = 0;
427      not_sev = ~ pGetShortExpVector(h);
428    }
429    else
430    {
431      if (j >= strat->sl) return h;
432      j++;
433    }
434  }
435}
436
437void initBba(ideal F,kStrategy strat)
438{
439  int i;
440  idhdl h;
441 /* setting global variables ------------------- */
442  strat->enterS = enterSBba;
443  if (strat->honey)
444    strat->red = redHoney;
445  else if (pLexOrder && !strat->homog)
446    strat->red = redLazy;
447  else
448    strat->red = redHomog;
449  if (pLexOrder && strat->honey)
450    strat->initEcart = initEcartNormal;
451  else
452    strat->initEcart = initEcartBBA;
453  if (strat->honey)
454    strat->initEcartPair = initEcartPairMora;
455  else
456    strat->initEcartPair = initEcartPairBba;
457  strat->kIdeal = NULL;
458  //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD;
459  //else              strat->kIdeal->rtyp=MODUL_CMD;
460  //strat->kIdeal->data=(void *)strat->Shdl;
461  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
462  {
463    //interred  machen   Aenderung
464    pFDegOld=pFDeg;
465    pLDegOld=pLDeg;
466    h=ggetid("ecart");
467    if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD))
468    {
469      ecartWeights=iv2array(IDINTVEC(h));
470    }
471    else
472    {
473      ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short));
474      /*uses automatic computation of the ecartWeights to set them*/
475      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
476    }
477    pFDeg=totaldegreeWecart;
478    pLDeg=maxdegreeWecart;
479    for(i=1; i<=pVariables; i++)
480      Print(" %d",ecartWeights[i]);
481    PrintLn();
482    mflush();
483  }
484}
485
486#ifdef KDEBUG
487static int bba_count = 0;
488#endif
489
490ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
491{
492#ifdef KDEBUG
493  bba_count++;
494  int loop_count = 0;
495#endif
496  om_Opts.MinTrack = 5;
497  int   srmax,lrmax, red_result;
498  int   olddeg,reduc;
499  int hilbeledeg=1,hilbcount=0,minimcnt=0;
500#ifdef PROT_LENGTH
501  int length;
502#endif
503
504  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
505  initBuchMoraPos(strat);
506  initHilbCrit(F,Q,&hilb,strat);
507  initBba(F,strat);
508  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
509  /*Shdl=*/initBuchMora(F, Q,strat);
510  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
511  srmax = strat->sl;
512  reduc = olddeg = lrmax = 0;
513
514  if (!TEST_OPT_NOT_BUCKETS)
515    strat->use_buckets = 1;
516
517  kTest_TS(strat);
518 
519#ifdef HAVE_TAIL_RING
520  kStratInitChangeTailRing(strat);
521#endif 
522 
523  /* compute------------------------------------------------------- */
524  while (strat->Ll >= 0)
525  {
526    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
527#ifdef KDEBUG
528    loop_count++;
529    if (TEST_OPT_DEBUG) messageSets(strat);
530#endif
531    if (strat->Ll== 0) strat->interpt=TRUE;
532    if (TEST_OPT_DEGBOUND
533        && ((strat->honey && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))
534            || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))))
535    {
536      /*
537       *stops computation if
538       * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
539       *a predefined number Kstd1_deg
540       */
541      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
542      break;
543    }
544    /* picks the last element from the lazyset L */
545    strat->P = strat->L[strat->Ll];
546    strat->Ll--;
547
548    if (pNext(strat->P.p) == strat->tail)
549    {
550      // deletes the short spoly
551      pLmFree(strat->P.p);
552      strat->P.p = NULL;
553      poly m1 = NULL, m2 = NULL;
554
555      // check that spoly creation is ok
556      while (strat->tailRing != currRing && 
557             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
558      {
559        assume(m1 == NULL && m2 == NULL);
560        // if not, change to a ring where exponents are at least
561        // large enough
562        kStratChangeTailRing(strat);
563      }
564      // create the real one
565      ksCreateSpoly(&(strat->P), strat->kNoether, strat->use_buckets, 
566                    strat->tailRing, m1, m2, strat->R);
567    }
568    else if (strat->P.p1 == NULL)
569    {
570      if (strat->minim > 0)
571        strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
572      // for input polys, prepare reduction
573      strat->P.PrepareRed(strat->use_buckets);
574    }
575   
576    if (TEST_OPT_PROT)
577      message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
578              &olddeg,&reduc,strat);
579
580    /* reduction of the element choosen from L */
581    red_result = strat->red(&strat->P,strat);
582
583    // reduction to non-zero new poly
584    if (red_result == 1)
585    {
586      /* statistic */
587      if (TEST_OPT_PROT) PrintS("s");
588
589      // get the polynomial (canonicalize bucket, make sure P.p is set)
590      strat->P.GetP(strat->lmBin);
591
592      int pos=posInS(strat->S,strat->sl,strat->P.p);
593
594      // reduce the tail and normailze poly
595      if (TEST_OPT_INTSTRATEGY)
596      {
597        strat->P.pCleardenom();
598        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
599        {
600          strat->P.p = redtailBba(&(strat->P),pos-1,strat);
601          strat->P.pCleardenom();
602        }
603      }
604      else
605      {
606        strat->P.pNorm();
607        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
608          strat->P.p = redtailBba(&(strat->P),pos-1,strat);
609      }
610
611#ifdef KDEBUG
612      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
613#endif
614
615      // min_std stuff
616      if ((strat->P.p1==NULL) && (strat->minim>0))
617      {
618        if (strat->minim==1)
619        {
620          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
621          p_Delete(&strat->P.p2, currRing, strat->tailRing);
622        }
623        else
624        {
625          strat->M->m[minimcnt]=strat->P.p2;
626          strat->P.p2=NULL;
627        }
628        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
629          pNext(strat->M->m[minimcnt]) 
630            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
631                                           strat->tailRing, currRing,
632                                           currRing->PolyBin);
633        minimcnt++;
634      }
635
636      // enter into S, L, and T
637#ifdef PROT_LENGTH
638      if (TEST_OPT_PROT)
639      {
640        length += strat->P.GetpLength();
641        Print("[%d:%d]", strat->P.GetpLength(), length);
642      }
643#endif
644      enterT(strat->P, strat);
645      enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
646      // posInS only depends on the leading term
647      strat->enterS(strat->P, pos, strat, strat->tl);
648      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
649      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
650      if (strat->sl>srmax) srmax = strat->sl;
651    }
652    else if (strat->P.p1 == NULL && strat->minim > 0)
653    {
654      p_Delete(&strat->P.p2, currRing, strat->tailRing);
655    }
656#ifdef KDEBUG
657    memset(&(strat->P), 0, sizeof(strat->P));
658#endif
659    kTest_TS(strat);
660  }
661#ifdef KDEBUG
662  if (TEST_OPT_DEBUG) messageSets(strat);
663#endif
664  /* complete reduction of the standard basis--------- */
665  if (TEST_OPT_REDSB) completeReduce(strat);
666  /* release temp data-------------------------------- */
667  exitBuchMora(strat);
668  if (TEST_OPT_WEIGHTM)
669  {
670    pFDeg=pFDegOld;
671    pLDeg=pLDegOld;
672    if (ecartWeights)
673    {
674      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
675      ecartWeights=NULL;
676    }
677  }
678  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
679  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
680  return (strat->Shdl);
681}
682
683poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce)
684{
685  poly   p;
686  int   i;
687
688  if ((idIs0(F))&&(Q==NULL))
689    return pCopy(q); /*F=0*/
690  strat->ak = idRankFreeModule(F);
691  /*- creating temp data structures------------------- -*/
692  BITSET save_test=test;
693  test|=Sy_bit(OPT_REDTAIL);
694  initBuchMoraCrit(strat);
695  strat->initEcart = initEcartBBA;
696  strat->enterS = enterSBba;
697  /*- set S -*/
698  strat->sl = -1;
699  /*- init local data struct.---------------------------------------- -*/
700  /*Shdl=*/initS(F,Q,strat);
701  /*- compute------------------------------------------------------- -*/
702  if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
703  {
704    for (i=strat->sl;i>=0;i--)
705      pNorm(strat->S[i]);
706  }
707  kTest(strat);
708  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
709  p = redNF(pCopy(q),strat);
710  if ((p!=NULL)&&(lazyReduce==0))
711  {
712    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
713    p = redtailBba(p,strat->sl,strat);
714  }
715  /*- release temp data------------------------------- -*/
716  omfree(strat->sevS);
717  omfree(strat->ecartS);
718  omfree(strat->T);
719  omfree(strat->sevT);
720  omfree(strat->R);
721  omfree(strat->S_2_R);
722  omfree(strat->L);
723  omfree(strat->B);
724  omfree(strat->fromQ);
725  idDelete(&strat->Shdl);
726  test=save_test;
727  if (TEST_OPT_PROT) PrintLn();
728  return p;
729}
730
731ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce)
732{
733  poly   p;
734  int   i;
735  ideal res;
736
737  if (idIs0(q))
738    return idInit(1,q->rank);
739  if ((idIs0(F))&&(Q==NULL))
740    return idCopy(q); /*F=0*/
741  strat->ak = idRankFreeModule(F);
742  /*- creating temp data structures------------------- -*/
743  BITSET save_test=test;
744  test|=Sy_bit(OPT_REDTAIL);
745  initBuchMoraCrit(strat);
746  strat->initEcart = initEcartBBA;
747  strat->enterS = enterSBba;
748  /*- set S -*/
749  strat->sl = -1;
750  /*- init local data struct.---------------------------------------- -*/
751  /*Shdl=*/initS(F,Q,strat);
752  /*- compute------------------------------------------------------- -*/
753  res=idInit(IDELEMS(q),q->rank);
754  if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
755  {
756    for (i=strat->sl;i>=0;i--)
757      pNorm(strat->S[i]);
758  }
759  for (i=IDELEMS(q)-1; i>=0; i--)
760  {
761    if (q->m[i]!=NULL)
762    {
763      if (TEST_OPT_PROT) { PrintS("r");mflush(); }
764      p = redNF(pCopy(q->m[i]),strat);
765      if ((p!=NULL)&&(lazyReduce==0))
766      {
767        if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
768        p = redtailBba(p,strat->sl,strat);
769      }
770      res->m[i]=p;
771    }
772    //else
773    //  res->m[i]=NULL;
774  }
775  /*- release temp data------------------------------- -*/
776  omfree(strat->sevS);
777  omfree(strat->ecartS);
778  omfree(strat->T);
779  omfree(strat->sevT);
780  omfree(strat->R);
781  omfree(strat->S_2_R);
782  omfree(strat->L);
783  omfree(strat->B);
784  omfree(strat->fromQ);
785  idDelete(&strat->Shdl);
786  test=save_test;
787  if (TEST_OPT_PROT) PrintLn();
788  return res;
789}
790
791static ideal bbared (ideal F, ideal Q,kStrategy strat)
792{
793
794  /* complete reduction of the standard basis--------- */
795  completeReduce(strat);
796  /* release temp data-------------------------------- */
797  exitBuchMora(strat);
798  if (TEST_OPT_WEIGHTM)
799  {
800    pFDeg=pFDegOld;
801    pLDeg=pLDegOld;
802    if (ecartWeights)
803    {
804      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
805      ecartWeights=NULL;
806    }
807  }
808  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
809  return (strat->Shdl);
810}
811
812ideal stdred(ideal F, ideal Q, tHomog h,intvec ** w)
813{
814  ideal r;
815  BOOLEAN b=pLexOrder,toReset=FALSE;
816  BOOLEAN delete_w=(w==NULL);
817  kStrategy strat=new skStrategy;
818
819  if (rField_has_simple_inverse())
820    strat->LazyPass=20;
821  else
822   strat->LazyPass=2;
823  strat->LazyDegree = 1;
824  strat->ak = idRankFreeModule(F);
825  if ((h==testHomog))
826  {
827    if (strat->ak==0)
828    {
829      h = (tHomog)idHomIdeal(F,Q);
830      w=NULL;
831    }
832    else
833      h = (tHomog)idHomModule(F,Q,w);
834  }
835  if (h==isHomog)
836  {
837    if ((w!=NULL) && (*w!=NULL))
838    {
839      kModW = *w;
840      strat->kModW = *w;
841      pOldFDeg = pFDeg;
842      pFDeg = kModDeg;
843      toReset = TRUE;
844    }
845    pLexOrder = TRUE;
846    strat->LazyPass*=2;
847  }
848  strat->homog=h;
849  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
850  initBuchMoraPos(strat);
851  if (pOrdSgn==1)
852    initBba(F,strat);
853  else
854    initMora(F,strat);
855  initBuchMora(F, Q,strat);
856  //initS(F,Q,strat);
857// Ende der Initalisierung
858  r=bbared(F,Q,strat);
859#ifdef KDEBUG
860  int i;
861  for (i=0; i<IDELEMS(r); i++) pTest(r->m[i]);
862#endif
863// Ende: aufraeumen
864  if (toReset)
865  {
866    kModW = NULL;
867    pFDeg = pOldFDeg;
868  }
869  pLexOrder = b;
870  delete(strat);
871  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
872  idSkipZeroes(r);
873  return r;
874}
Note: See TracBrowser for help on using the repository browser.