source: git/Singular/kstd2.cc @ bef194

spielwiese
Last change on this file since bef194 was bef194, checked in by Olaf Bachmann <obachman@…>, 23 years ago
* new options: redThrough and oldStd * increased version to 1.3.11 git-svn-id: file:///usr/local/Singular/svn/trunk@4926 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 20.6 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kstd2.cc,v 1.68 2000-12-18 13:30:36 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 (!K_TEST_OPT_REDTHROUGH &&
206        (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
207    {
208      h->SetLmCurrRing();
209      at = posInL11(strat->L,strat->Ll,h,strat);
210      if (at <= strat->Ll)
211      {
212        if (kFindDivisibleByInS(strat->S, strat->sevS, strat->sl, h) < 0)
213          return 1;
214#ifdef KDEBUG
215        if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at);
216#endif
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 (!K_TEST_OPT_REDTHROUGH && (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 (!K_TEST_OPT_REDTHROUGH && (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 = 1;
498  int   olddeg,reduc;
499  int hilbeledeg=1,hilbcount=0,minimcnt=0;
500  BOOLEAN withT = FALSE;
501 
502  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
503  initBuchMoraPos(strat);
504  initHilbCrit(F,Q,&hilb,strat);
505  initBba(F,strat);
506  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
507  /*Shdl=*/initBuchMora(F, Q,strat);
508  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
509  srmax = strat->sl;
510  reduc = olddeg = lrmax = 0;
511
512  if (!TEST_OPT_NOT_BUCKETS)
513    strat->use_buckets = 1;
514
515  // redtailBBa against T for inhomogenous input
516  if (!K_TEST_OPT_OLDSTD)
517    withT = ! strat->homog;
518 
519  // strat->posInT = posInT_pLength;
520  kTest_TS(strat);
521 
522#ifdef HAVE_TAIL_RING
523  kStratInitChangeTailRing(strat);
524#endif 
525 
526  /* compute------------------------------------------------------- */
527  while (strat->Ll >= 0)
528  {
529    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
530#ifdef KDEBUG
531    loop_count++;
532    if (TEST_OPT_DEBUG) messageSets(strat);
533#endif
534    if (strat->Ll== 0) strat->interpt=TRUE;
535    if (TEST_OPT_DEGBOUND
536        && ((strat->honey && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))
537            || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))))
538    {
539      /*
540       *stops computation if
541       * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
542       *a predefined number Kstd1_deg
543       */
544      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
545      break;
546    }
547    /* picks the last element from the lazyset L */
548    strat->P = strat->L[strat->Ll];
549    strat->Ll--;
550
551    if (pNext(strat->P.p) == strat->tail)
552    {
553      // deletes the short spoly
554      pLmFree(strat->P.p);
555      strat->P.p = NULL;
556      poly m1 = NULL, m2 = NULL;
557
558      // check that spoly creation is ok
559      while (strat->tailRing != currRing && 
560             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
561      {
562        assume(m1 == NULL && m2 == NULL);
563        // if not, change to a ring where exponents are at least
564        // large enough
565        kStratChangeTailRing(strat);
566      }
567      // create the real one
568      ksCreateSpoly(&(strat->P), strat->kNoether, strat->use_buckets, 
569                    strat->tailRing, m1, m2, strat->R);
570    }
571    else if (strat->P.p1 == NULL)
572    {
573      if (strat->minim > 0)
574        strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
575      // for input polys, prepare reduction
576      strat->P.PrepareRed(strat->use_buckets);
577    }
578   
579    if (TEST_OPT_PROT)
580      message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
581              &olddeg,&reduc,strat, red_result);
582
583    /* reduction of the element choosen from L */
584    red_result = strat->red(&strat->P,strat);
585
586    // reduction to non-zero new poly
587    if (red_result == 1)
588    {
589      /* statistic */
590      if (TEST_OPT_PROT) PrintS("s");
591
592      // get the polynomial (canonicalize bucket, make sure P.p is set)
593      strat->P.GetP(strat->lmBin);
594
595      int pos=posInS(strat->S,strat->sl,strat->P.p);
596
597      // reduce the tail and normailze poly
598      if (TEST_OPT_INTSTRATEGY)
599      {
600        strat->P.pCleardenom();
601        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
602        {
603          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
604          strat->P.pCleardenom();
605        }
606      }
607      else
608      {
609        strat->P.pNorm();
610        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
611          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
612      }
613
614#ifdef KDEBUG
615      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
616#endif
617
618      // min_std stuff
619      if ((strat->P.p1==NULL) && (strat->minim>0))
620      {
621        if (strat->minim==1)
622        {
623          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
624          p_Delete(&strat->P.p2, currRing, strat->tailRing);
625        }
626        else
627        {
628          strat->M->m[minimcnt]=strat->P.p2;
629          strat->P.p2=NULL;
630        }
631        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
632          pNext(strat->M->m[minimcnt]) 
633            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
634                                           strat->tailRing, currRing,
635                                           currRing->PolyBin);
636        minimcnt++;
637      }
638
639      // enter into S, L, and T
640      enterT(strat->P, strat);
641      enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
642      // posInS only depends on the leading term
643      strat->enterS(strat->P, pos, strat, strat->tl);
644      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
645//      Print("[%d]",hilbeledeg);
646      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
647      if (strat->sl>srmax) srmax = strat->sl;
648    }
649    else if (strat->P.p1 == NULL && strat->minim > 0)
650    {
651      p_Delete(&strat->P.p2, currRing, strat->tailRing);
652    }
653#ifdef KDEBUG
654    memset(&(strat->P), 0, sizeof(strat->P));
655#endif
656    kTest_TS(strat);
657  }
658#ifdef KDEBUG
659  if (TEST_OPT_DEBUG) messageSets(strat);
660#endif
661  /* complete reduction of the standard basis--------- */
662  if (TEST_OPT_REDSB) completeReduce(strat);
663  /* release temp data-------------------------------- */
664  exitBuchMora(strat);
665  if (TEST_OPT_WEIGHTM)
666  {
667    pFDeg=pFDegOld;
668    pLDeg=pLDegOld;
669    if (ecartWeights)
670    {
671      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
672      ecartWeights=NULL;
673    }
674  }
675  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
676  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
677  return (strat->Shdl);
678}
679
680poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce)
681{
682  poly   p;
683  int   i;
684
685  if ((idIs0(F))&&(Q==NULL))
686    return pCopy(q); /*F=0*/
687  strat->ak = idRankFreeModule(F);
688  /*- creating temp data structures------------------- -*/
689  BITSET save_test=test;
690  test|=Sy_bit(OPT_REDTAIL);
691  initBuchMoraCrit(strat);
692  strat->initEcart = initEcartBBA;
693  strat->enterS = enterSBba;
694  /*- set S -*/
695  strat->sl = -1;
696  /*- init local data struct.---------------------------------------- -*/
697  /*Shdl=*/initS(F,Q,strat);
698  /*- compute------------------------------------------------------- -*/
699  if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
700  {
701    for (i=strat->sl;i>=0;i--)
702      pNorm(strat->S[i]);
703  }
704  kTest(strat);
705  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
706  p = redNF(pCopy(q),strat);
707  if ((p!=NULL)&&(lazyReduce==0))
708  {
709    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
710    p = redtailBba(p,strat->sl,strat);
711  }
712  /*- release temp data------------------------------- -*/
713  omfree(strat->sevS);
714  omfree(strat->ecartS);
715  omfree(strat->T);
716  omfree(strat->sevT);
717  omfree(strat->R);
718  omfree(strat->S_2_R);
719  omfree(strat->L);
720  omfree(strat->B);
721  omfree(strat->fromQ);
722  idDelete(&strat->Shdl);
723  test=save_test;
724  if (TEST_OPT_PROT) PrintLn();
725  return p;
726}
727
728ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce)
729{
730  poly   p;
731  int   i;
732  ideal res;
733
734  if (idIs0(q))
735    return idInit(1,q->rank);
736  if ((idIs0(F))&&(Q==NULL))
737    return idCopy(q); /*F=0*/
738  strat->ak = idRankFreeModule(F);
739  /*- creating temp data structures------------------- -*/
740  BITSET save_test=test;
741  test|=Sy_bit(OPT_REDTAIL);
742  initBuchMoraCrit(strat);
743  strat->initEcart = initEcartBBA;
744  strat->enterS = enterSBba;
745  /*- set S -*/
746  strat->sl = -1;
747  /*- init local data struct.---------------------------------------- -*/
748  /*Shdl=*/initS(F,Q,strat);
749  /*- compute------------------------------------------------------- -*/
750  res=idInit(IDELEMS(q),q->rank);
751  if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
752  {
753    for (i=strat->sl;i>=0;i--)
754      pNorm(strat->S[i]);
755  }
756  for (i=IDELEMS(q)-1; i>=0; i--)
757  {
758    if (q->m[i]!=NULL)
759    {
760      if (TEST_OPT_PROT) { PrintS("r");mflush(); }
761      p = redNF(pCopy(q->m[i]),strat);
762      if ((p!=NULL)&&(lazyReduce==0))
763      {
764        if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
765        p = redtailBba(p,strat->sl,strat);
766      }
767      res->m[i]=p;
768    }
769    //else
770    //  res->m[i]=NULL;
771  }
772  /*- release temp data------------------------------- -*/
773  omfree(strat->sevS);
774  omfree(strat->ecartS);
775  omfree(strat->T);
776  omfree(strat->sevT);
777  omfree(strat->R);
778  omfree(strat->S_2_R);
779  omfree(strat->L);
780  omfree(strat->B);
781  omfree(strat->fromQ);
782  idDelete(&strat->Shdl);
783  test=save_test;
784  if (TEST_OPT_PROT) PrintLn();
785  return res;
786}
787
788static ideal bbared (ideal F, ideal Q,kStrategy strat)
789{
790
791  /* complete reduction of the standard basis--------- */
792  completeReduce(strat);
793  /* release temp data-------------------------------- */
794  exitBuchMora(strat);
795  if (TEST_OPT_WEIGHTM)
796  {
797    pFDeg=pFDegOld;
798    pLDeg=pLDegOld;
799    if (ecartWeights)
800    {
801      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
802      ecartWeights=NULL;
803    }
804  }
805  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
806  return (strat->Shdl);
807}
808
809ideal stdred(ideal F, ideal Q, tHomog h,intvec ** w)
810{
811  ideal r;
812  BOOLEAN b=pLexOrder,toReset=FALSE;
813  BOOLEAN delete_w=(w==NULL);
814  kStrategy strat=new skStrategy;
815
816  if (rField_has_simple_inverse())
817    strat->LazyPass=20;
818  else
819   strat->LazyPass=2;
820  strat->LazyDegree = 1;
821  strat->ak = idRankFreeModule(F);
822  if ((h==testHomog))
823  {
824    if (strat->ak==0)
825    {
826      h = (tHomog)idHomIdeal(F,Q);
827      w=NULL;
828    }
829    else
830      h = (tHomog)idHomModule(F,Q,w);
831  }
832  if (h==isHomog)
833  {
834    if ((w!=NULL) && (*w!=NULL))
835    {
836      kModW = *w;
837      strat->kModW = *w;
838      pOldFDeg = pFDeg;
839      pFDeg = kModDeg;
840      toReset = TRUE;
841    }
842    pLexOrder = TRUE;
843    strat->LazyPass*=2;
844  }
845  strat->homog=h;
846  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
847  initBuchMoraPos(strat);
848  if (pOrdSgn==1)
849    initBba(F,strat);
850  else
851    initMora(F,strat);
852  initBuchMora(F, Q,strat);
853  //initS(F,Q,strat);
854// Ende der Initalisierung
855  r=bbared(F,Q,strat);
856#ifdef KDEBUG
857  int i;
858  for (i=0; i<IDELEMS(r); i++) pTest(r->m[i]);
859#endif
860// Ende: aufraeumen
861  if (toReset)
862  {
863    kModW = NULL;
864    pFDeg = pOldFDeg;
865  }
866  pLexOrder = b;
867  delete(strat);
868  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
869  idSkipZeroes(r);
870  return r;
871}
Note: See TracBrowser for help on using the repository browser.