source: git/kernel/kstd1.cc @ 1bc7d4a

spielwiese
Last change on this file since 1bc7d4a was 1bc7d4a, checked in by Christian Eder, 12 years ago
removes Galkins ssg implementations since there are too many dependencies
  • Property mode set to 100644
File size: 68.6 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5/*
6* ABSTRACT:
7*/
8
9// TODO: why the following is here instead of mod2.h???
10
11// define if tailrings should be used
12#define HAVE_TAIL_RING
13
14// define if buckets should be used
15#define MORA_USE_BUCKETS
16
17#ifndef NDEBUG
18# define MYTEST 0
19#else /* ifndef NDEBUG */
20# define MYTEST 0
21#endif /* ifndef NDEBUG */
22
23
24#include "config.h"
25#include "mod2.h"
26
27#include <omalloc/omalloc.h>
28#include <misc/options.h>
29#include <misc/intvec.h>
30
31#if MYTEST
32#ifdef HAVE_TAIL_RING
33#undef HAVE_TAIL_RING
34#endif /* ifdef HAVE_TAIL_RING */
35#endif /* if MYTEST */
36
37#include <polys/weight.h>
38#include <kernel/polys.h>
39
40#include <kernel/kutil.h>
41#include <kernel/febase.h>
42#include <kernel/kstd1.h>
43#include <kernel/khstd.h>
44#include <kernel/stairc.h>
45//#include "cntrlc.h"
46#include <kernel/ideals.h>
47//#include "../Singular/ipid.h"
48#include <kernel/timer.h>
49
50//#include "ipprint.h"
51
52#ifdef HAVE_PLURAL
53#include <polys/nc/nc.h>
54#include <polys/nc/sca.h>
55#include <kernel/nc.h>
56#endif
57
58#include <kernel/kInline.h>
59
60
61/* the list of all options which give a warning by test */
62BITSET kOptions=Sy_bit(OPT_PROT)           /*  0 */
63                |Sy_bit(OPT_REDSB)         /*  1 */
64                |Sy_bit(OPT_NOT_SUGAR)     /*  3 */
65                |Sy_bit(OPT_INTERRUPT)     /*  4 */
66                |Sy_bit(OPT_SUGARCRIT)     /*  5 */
67                |Sy_bit(OPT_REDTHROUGH)
68                |Sy_bit(OPT_OLDSTD)
69                |Sy_bit(OPT_FASTHC)        /* 10 */
70                |Sy_bit(OPT_INTSTRATEGY)   /* 26 */
71                |Sy_bit(OPT_INFREDTAIL)    /* 28 */
72                |Sy_bit(OPT_NOTREGULARITY) /* 30 */
73                |Sy_bit(OPT_WEIGHTM);      /* 31 */
74
75/* the list of all options which may be used by option and test */
76BITSET validOpts=Sy_bit(0)
77                |Sy_bit(1)
78                |Sy_bit(2) // obachman 10/00: replaced by notBucket
79                |Sy_bit(3)
80                |Sy_bit(4)
81                |Sy_bit(5)
82                |Sy_bit(6)
83//                |Sy_bit(7) obachman 11/00 tossed: 12/00 used for redThrough
84                |Sy_bit(7) // OPT_REDTHROUGH
85                |Sy_bit(8) // obachman 11/00 tossed -> motsak 2011 experimental: OPT_NO_SYZ_MINIM
86                |Sy_bit(9)
87                |Sy_bit(10)
88                |Sy_bit(11)
89                |Sy_bit(12)
90                |Sy_bit(13)
91                |Sy_bit(14)
92                |Sy_bit(15)
93                |Sy_bit(16)
94                |Sy_bit(17)
95                |Sy_bit(18)
96                |Sy_bit(19)
97//                |Sy_bit(20) obachman 11/00 tossed: 12/00 used for redOldStd
98                |Sy_bit(OPT_OLDSTD)
99                |Sy_bit(21)
100                |Sy_bit(22)
101                /*|Sy_bit(23)*/
102                /*|Sy_bit(24)*/
103                |Sy_bit(OPT_REDTAIL)
104                |Sy_bit(OPT_INTSTRATEGY)
105                |Sy_bit(27)
106                |Sy_bit(28)
107                |Sy_bit(29)
108                |Sy_bit(30)
109                |Sy_bit(31);
110
111//static BOOLEAN posInLOldFlag;
112           /*FALSE, if posInL == posInL10*/
113// returns TRUE if mora should use buckets, false otherwise
114static BOOLEAN kMoraUseBucket(kStrategy strat);
115
116static void kOptimizeLDeg(pLDegProc ldeg, kStrategy strat)
117{
118//  if (strat->ak == 0 && !rIsSyzIndexRing(currRing))
119    strat->length_pLength = TRUE;
120//  else
121//    strat->length_pLength = FALSE;
122
123  if ((ldeg == pLDeg0c /*&& !rIsSyzIndexRing(currRing)*/) ||
124      (ldeg == pLDeg0 && strat->ak == 0))
125  {
126    strat->LDegLast = TRUE;
127  }
128  else
129  {
130    strat->LDegLast = FALSE;
131  }
132}
133
134
135static int doRed (LObject* h, TObject* with,BOOLEAN intoT,kStrategy strat)
136{
137  int ret;
138#if KDEBUG > 0
139  kTest_L(h);
140  kTest_T(with);
141#endif
142  // Hmmm ... why do we do this -- polys from T should already be normalized
143  if (!TEST_OPT_INTSTRATEGY)
144    with->pNorm();
145#ifdef KDEBUG
146  if (TEST_OPT_DEBUG)
147  {
148    PrintS("reduce ");h->wrp();PrintS(" with ");with->wrp();PrintLn();
149  }
150#endif
151  if (intoT)
152  {
153    // need to do it exacly like this: otherwise
154    // we might get errors
155    LObject L= *h;
156    L.Copy();
157    h->GetP();
158    h->SetLength(strat->length_pLength);
159    ret = ksReducePoly(&L, with, strat->kNoetherTail(), NULL, strat);
160    if (ret)
161    {
162      if (ret < 0) return ret;
163      if (h->tailRing != strat->tailRing)
164        h->ShallowCopyDelete(strat->tailRing,
165                             pGetShallowCopyDeleteProc(h->tailRing,
166                                                       strat->tailRing));
167    }
168    enterT(*h,strat);
169    *h = L;
170  }
171  else
172    ret = ksReducePoly(h, with, strat->kNoetherTail(), NULL, strat);
173#ifdef KDEBUG
174  if (TEST_OPT_DEBUG)
175  {
176    PrintS("to ");h->wrp();PrintLn();
177  }
178#endif
179  return ret;
180}
181
182int redEcart (LObject* h,kStrategy strat)
183{
184  int i,at,ei,li,ii;
185  int j = 0;
186  int pass = 0;
187  long d,reddeg;
188
189  d = h->GetpFDeg()+ h->ecart;
190  reddeg = strat->LazyDegree+d;
191  h->SetShortExpVector();
192  loop
193  {
194    j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h);
195    if (j < 0)
196    {
197      if (strat->honey) h->SetLength(strat->length_pLength);
198      return 1;
199    }
200
201    ei = strat->T[j].ecart;
202    ii = j;
203
204    if (ei > h->ecart && ii < strat->tl)
205    {
206      li = strat->T[j].length;
207      // the polynomial to reduce with (up to the moment) is;
208      // pi with ecart ei and length li
209      // look for one with smaller ecart
210      i = j;
211      loop
212      {
213        /*- takes the first possible with respect to ecart -*/
214        i++;
215#if 1
216        if (i > strat->tl) break;
217        if ((strat->T[i].ecart < ei || (strat->T[i].ecart == ei &&
218                                        strat->T[i].length < li))
219            &&
220            p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], h->GetLmTailRing(), ~h->sev, strat->tailRing))
221#else
222          j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h, i);
223        if (j < 0) break;
224        i = j;
225        if (strat->T[i].ecart < ei || (strat->T[i].ecart == ei &&
226                                        strat->T[i].length < li))
227#endif
228        {
229          // the polynomial to reduce with is now
230          ii = i;
231          ei = strat->T[i].ecart;
232          if (ei <= h->ecart) break;
233          li = strat->T[i].length;
234        }
235      }
236    }
237
238    // end of search: have to reduce with pi
239    if (ei > h->ecart)
240    {
241      // It is not possible to reduce h with smaller ecart;
242      // if possible h goes to the lazy-set L,i.e
243      // if its position in L would be not the last one
244      strat->fromT = TRUE;
245      if (!TEST_OPT_REDTHROUGH && strat->Ll >= 0) /*- L is not empty -*/
246      {
247        h->SetLmCurrRing();
248        if (strat->honey && strat->posInLDependsOnLength)
249          h->SetLength(strat->length_pLength);
250        assume(h->FDeg == h->pFDeg());
251        at = strat->posInL(strat->L,strat->Ll,h,strat);
252        if (at <= strat->Ll)
253        {
254          /*- h will not become the next element to reduce -*/
255          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
256#ifdef KDEBUG
257          if (TEST_OPT_DEBUG) Print(" ecart too big; -> L%d\n",at);
258#endif
259          h->Clear();
260          strat->fromT = FALSE;
261          return -1;
262        }
263      }
264    }
265
266    // now we finally can reduce
267    doRed(h,&(strat->T[ii]),strat->fromT,strat);
268    h->last=NULL;
269    strat->fromT=FALSE;
270
271    // are we done ???
272    if (h->IsNull())
273    {
274      if (h->lcm!=NULL) pLmFree(h->lcm);
275      h->Clear();
276      return 0;
277    }
278
279    // NO!
280    h->SetShortExpVector();
281    h->SetpFDeg();
282    if (strat->honey)
283    {
284      if (ei <= h->ecart)
285        h->ecart = d-h->GetpFDeg();
286      else
287        h->ecart = d-h->GetpFDeg()+ei-h->ecart;
288    }
289    else
290      // this has the side effect of setting h->length
291      h->ecart = h->pLDeg(strat->LDegLast) - h->GetpFDeg();
292#if 0
293    if (strat->syzComp!=0)
294    {
295      if ((strat->syzComp>0) && (h->Comp() > strat->syzComp))
296      {
297        assume(h->MinComp() > strat->syzComp);
298        if (strat->honey) h->SetLength();
299#ifdef KDEBUG
300        if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
301#endif
302        return -2;
303      }
304    }
305#endif
306    /*- try to reduce the s-polynomial -*/
307    pass++;
308    d = h->GetpFDeg()+h->ecart;
309    /*
310     *test whether the polynomial should go to the lazyset L
311     *-if the degree jumps
312     *-if the number of pre-defined reductions jumps
313     */
314    if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
315        && ((d >= reddeg) || (pass > strat->LazyPass)))
316    {
317      h->SetLmCurrRing();
318      if (strat->honey && strat->posInLDependsOnLength)
319        h->SetLength(strat->length_pLength);
320      assume(h->FDeg == h->pFDeg());
321      at = strat->posInL(strat->L,strat->Ll,h,strat);
322      if (at <= strat->Ll)
323      {
324        int dummy=strat->sl;
325        if (kFindDivisibleByInS(strat, &dummy, h) < 0)
326        {
327          if (strat->honey && !strat->posInLDependsOnLength)
328            h->SetLength(strat->length_pLength);
329          return 1;
330        }
331        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
332#ifdef KDEBUG
333        if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
334#endif
335        h->Clear();
336        return -1;
337      }
338    }
339    else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
340    {
341      Print(".%ld",d);mflush();
342      reddeg = d+1;
343      if (h->pTotalDeg()+h->ecart >= strat->tailRing->bitmask)
344      {
345        strat->overflow=TRUE;
346        //Print("OVERFLOW in redEcart d=%ld, max=%ld",d,strat->tailRing->bitmask);
347        h->GetP();
348        at = strat->posInL(strat->L,strat->Ll,h,strat);
349        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
350        h->Clear();
351        return -1;
352      }
353    }
354  }
355}
356
357/*2
358*reduces h with elements from T choosing  the first possible
359* element in t with respect to the given pDivisibleBy
360*/
361int redFirst (LObject* h,kStrategy strat)
362{
363  if (h->IsNull()) return 0;
364
365  int at;
366  long reddeg,d;
367  int pass = 0;
368  int j = 0;
369
370  if (! strat->homog)
371  {
372    d = h->GetpFDeg() + h->ecart;
373    reddeg = strat->LazyDegree+d;
374  }
375  h->SetShortExpVector();
376  loop
377  {
378    j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h);
379    if (j < 0)
380    {
381      h->SetDegStuffReturnLDeg(strat->LDegLast);
382      return 1;
383    }
384
385    if (!TEST_OPT_INTSTRATEGY)
386      strat->T[j].pNorm();
387#ifdef KDEBUG
388    if (TEST_OPT_DEBUG)
389    {
390      PrintS("reduce ");
391      h->wrp();
392      PrintS(" with ");
393      strat->T[j].wrp();
394    }
395#endif
396    ksReducePoly(h, &(strat->T[j]), strat->kNoetherTail(), NULL, strat);
397#ifdef KDEBUG
398    if (TEST_OPT_DEBUG)
399    {
400      PrintS(" to ");
401      wrp(h->p);
402      PrintLn();
403    }
404#endif
405    if (h->IsNull())
406    {
407      if (h->lcm!=NULL) pLmFree(h->lcm);
408      h->Clear();
409      return 0;
410    }
411    h->SetShortExpVector();
412
413#if 0
414    if ((strat->syzComp!=0) && !strat->honey)
415    {
416      if ((strat->syzComp>0) &&
417          (h->Comp() > strat->syzComp))
418      {
419        assume(h->MinComp() > strat->syzComp);
420#ifdef KDEBUG
421        if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
422#endif
423        if (strat->homog)
424          h->SetDegStuffReturnLDeg(strat->LDegLast);
425        return -2;
426      }
427    }
428#endif
429    if (!strat->homog)
430    {
431      if (!TEST_OPT_OLDSTD && strat->honey)
432      {
433        h->SetpFDeg();
434        if (strat->T[j].ecart <= h->ecart)
435          h->ecart = d - h->GetpFDeg();
436        else
437          h->ecart = d - h->GetpFDeg() + strat->T[j].ecart - h->ecart;
438
439        d = h->GetpFDeg() + h->ecart;
440      }
441      else
442        d = h->SetDegStuffReturnLDeg(strat->LDegLast);
443      /*- try to reduce the s-polynomial -*/
444      pass++;
445      /*
446       *test whether the polynomial should go to the lazyset L
447       *-if the degree jumps
448       *-if the number of pre-defined reductions jumps
449       */
450      if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
451          && ((d >= reddeg) || (pass > strat->LazyPass)))
452      {
453        h->SetLmCurrRing();
454        if (strat->posInLDependsOnLength)
455          h->SetLength(strat->length_pLength);
456        at = strat->posInL(strat->L,strat->Ll,h,strat);
457        if (at <= strat->Ll)
458        {
459          int dummy=strat->sl;
460          if (kFindDivisibleByInS(strat,&dummy, h) < 0)
461            return 1;
462          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
463#ifdef KDEBUG
464          if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
465#endif
466          h->Clear();
467          return -1;
468        }
469      }
470      if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
471      {
472        reddeg = d+1;
473        Print(".%ld",d);mflush();
474        if (h->pTotalDeg()+h->ecart >= strat->tailRing->bitmask)
475        {
476          strat->overflow=TRUE;
477          //Print("OVERFLOW in redFirst d=%ld, max=%ld",d,strat->tailRing->bitmask);
478          h->GetP();
479          at = strat->posInL(strat->L,strat->Ll,h,strat);
480          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
481          h->Clear();
482          return -1;
483        }
484      }
485    }
486  }
487}
488
489/*2
490* reduces h with elements from T choosing first possible
491* element in T with respect to the given ecart
492* used for computing normal forms outside kStd
493*/
494static poly redMoraNF (poly h,kStrategy strat, int flag)
495{
496  LObject H;
497  H.p = h;
498  int j = 0;
499  int z = 10;
500  int o = H.SetpFDeg();
501  H.ecart = currRing->pLDeg(H.p,&H.length,currRing)-o;
502  if ((flag & 2) == 0) cancelunit(&H,TRUE);
503  H.sev = pGetShortExpVector(H.p);
504  unsigned long not_sev = ~ H.sev;
505  loop
506  {
507    if (j > strat->tl)
508    {
509      return H.p;
510    }
511    if (TEST_V_DEG_STOP)
512    {
513      if (kModDeg(H.p)>Kstd1_deg) pLmDelete(&H.p);
514      if (H.p==NULL) return NULL;
515    }
516    if (p_LmShortDivisibleBy(strat->T[j].GetLmTailRing(), strat->sevT[j], H.GetLmTailRing(), not_sev, strat->tailRing))
517    {
518      /*- remember the found T-poly -*/
519      poly pi = strat->T[j].p;
520      int ei = strat->T[j].ecart;
521      int li = strat->T[j].length;
522      int ii = j;
523      /*
524      * the polynomial to reduce with (up to the moment) is;
525      * pi with ecart ei and length li
526      */
527      loop
528      {
529        /*- look for a better one with respect to ecart -*/
530        /*- stop, if the ecart is small enough (<=ecart(H)) -*/
531        j++;
532        if (j > strat->tl) break;
533        if (ei <= H.ecart) break;
534        if (((strat->T[j].ecart < ei)
535          || ((strat->T[j].ecart == ei)
536        && (strat->T[j].length < li)))
537        && pLmShortDivisibleBy(strat->T[j].p,strat->sevT[j], H.p, not_sev))
538        {
539          /*
540          * the polynomial to reduce with is now;
541          */
542          pi = strat->T[j].p;
543          ei = strat->T[j].ecart;
544          li = strat->T[j].length;
545          ii = j;
546        }
547      }
548      /*
549      * end of search: have to reduce with pi
550      */
551      z++;
552      if (z>10)
553      {
554        pNormalize(H.p);
555        z=0;
556      }
557      if ((ei > H.ecart) && (!strat->kHEdgeFound))
558      {
559        /*
560        * It is not possible to reduce h with smaller ecart;
561        * we have to reduce with bad ecart: H has to enter in T
562        */
563        doRed(&H,&(strat->T[ii]),TRUE,strat);
564        if (H.p == NULL)
565          return NULL;
566      }
567      else
568      {
569        /*
570        * we reduce with good ecart, h need not to be put to T
571        */
572        doRed(&H,&(strat->T[ii]),FALSE,strat);
573        if (H.p == NULL)
574          return NULL;
575      }
576      /*- try to reduce the s-polynomial -*/
577      o = H.SetpFDeg();
578      if ((flag &2 ) == 0) cancelunit(&H,TRUE);
579      H.ecart = currRing->pLDeg(H.p,&(H.length),currRing)-o;
580      j = 0;
581      H.sev = pGetShortExpVector(H.p);
582      not_sev = ~ H.sev;
583    }
584    else
585    {
586      j++;
587    }
588  }
589}
590
591/*2
592*reorders  L with respect to posInL
593*/
594void reorderL(kStrategy strat)
595{
596  int i,j,at;
597  LObject p;
598
599  for (i=1; i<=strat->Ll; i++)
600  {
601    at = strat->posInL(strat->L,i-1,&(strat->L[i]),strat);
602    if (at != i)
603    {
604      p = strat->L[i];
605      for (j=i-1; j>=at; j--) strat->L[j+1] = strat->L[j];
606      strat->L[at] = p;
607    }
608  }
609}
610
611/*2
612*reorders  T with respect to length
613*/
614void reorderT(kStrategy strat)
615{
616  int i,j,at;
617  TObject p;
618  unsigned long sev;
619
620
621  for (i=1; i<=strat->tl; i++)
622  {
623    if (strat->T[i-1].length > strat->T[i].length)
624    {
625      p = strat->T[i];
626      sev = strat->sevT[i];
627      at = i-1;
628      loop
629      {
630        at--;
631        if (at < 0) break;
632        if (strat->T[i].length > strat->T[at].length) break;
633      }
634      for (j = i-1; j>at; j--)
635      {
636        strat->T[j+1]=strat->T[j];
637        strat->sevT[j+1]=strat->sevT[j];
638        strat->R[strat->T[j+1].i_r] = &(strat->T[j+1]);
639      }
640      strat->T[at+1]=p;
641      strat->sevT[at+1] = sev;
642      strat->R[p.i_r] = &(strat->T[at+1]);
643    }
644  }
645}
646
647/*2
648*looks whether exactly (currRing->N)-1 axis are used
649*returns last != 0 in this case
650*last is the (first) unused axis
651*/
652void missingAxis (int* last,kStrategy strat)
653{
654  int   i = 0;
655  int   k = 0;
656
657  *last = 0;
658  if (!currRing->MixedOrder)
659  {
660    loop
661    {
662      i++;
663      if (i > (currRing->N)) break;
664      if (strat->NotUsedAxis[i])
665      {
666        *last = i;
667        k++;
668      }
669      if (k>1)
670      {
671        *last = 0;
672        break;
673      }
674    }
675  }
676}
677
678/*2
679*last is the only non used axis, it looks
680*for a monomial in p being a pure power of this
681*variable and returns TRUE in this case
682*(*length) gives the length between the pure power and the leading term
683*(should be minimal)
684*/
685BOOLEAN hasPurePower (const poly p,int last, int *length,kStrategy strat)
686{
687  poly h;
688  int i;
689
690  if (pNext(p) == strat->tail)
691    return FALSE;
692  pp_Test(p, currRing, strat->tailRing);
693  if (strat->ak <= 0 || p_MinComp(p, currRing, strat->tailRing) == strat->ak)
694  {
695    i = p_IsPurePower(p, currRing);
696    if (i == last)
697    {
698      *length = 0;
699      return TRUE;
700    }
701    *length = 1;
702    h = pNext(p);
703    while (h != NULL)
704    {
705      i = p_IsPurePower(h, strat->tailRing);
706      if (i==last) return TRUE;
707      (*length)++;
708      pIter(h);
709    }
710  }
711  return FALSE;
712}
713
714BOOLEAN hasPurePower (LObject *L,int last, int *length,kStrategy strat)
715{
716  if (L->bucket != NULL)
717  {
718    poly p = L->CanonicalizeP();
719    BOOLEAN ret = hasPurePower(p, last, length, strat);
720    pNext(p) = NULL;
721    return ret;
722  }
723  else
724  {
725    return hasPurePower(L->p, last, length, strat);
726  }
727}
728
729/*2
730* looks up the position of polynomial p in L
731* in the case of looking for the pure powers
732*/
733int posInL10 (const LSet set,const int length, LObject* p,const kStrategy strat)
734{
735  int j,dp,dL;
736
737  if (length<0) return 0;
738  if (hasPurePower(p,strat->lastAxis,&dp,strat))
739  {
740    int op= p->GetpFDeg() +p->ecart;
741    for (j=length; j>=0; j--)
742    {
743      if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat))
744        return j+1;
745      if (dp < dL)
746        return j+1;
747      if ((dp == dL)
748          && (set[j].GetpFDeg()+set[j].ecart >= op))
749        return j+1;
750    }
751  }
752  j=length;
753  loop
754  {
755    if (j<0) break;
756    if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat)) break;
757    j--;
758  }
759  return strat->posInLOld(set,j,p,strat);
760}
761
762
763/*2
764* computes the s-polynomials L[ ].p in L
765*/
766void updateL(kStrategy strat)
767{
768  LObject p;
769  int dL;
770  int j=strat->Ll;
771  loop
772  {
773    if (j<0) break;
774    if (hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat))
775    {
776      p=strat->L[strat->Ll];
777      strat->L[strat->Ll]=strat->L[j];
778      strat->L[j]=p;
779      break;
780    }
781    j--;
782  }
783  if (j<0)
784  {
785    j=strat->Ll;
786    loop
787    {
788      if (j<0) break;
789      if (pNext(strat->L[j].p) == strat->tail)
790      {
791#ifdef HAVE_RINGS
792        if (rField_is_Ring(currRing))
793          pLmDelete(strat->L[j].p);    /*deletes the short spoly and computes*/
794        else
795#else
796          pLmFree(strat->L[j].p);    /*deletes the short spoly and computes*/
797#endif
798        strat->L[j].p = NULL;
799        poly m1 = NULL, m2 = NULL;
800        // check that spoly creation is ok
801        while (strat->tailRing != currRing &&
802               !kCheckSpolyCreation(&(strat->L[j]), strat, m1, m2))
803        {
804          assume(m1 == NULL && m2 == NULL);
805          // if not, change to a ring where exponents are at least
806          // large enough
807          kStratChangeTailRing(strat);
808        }
809        /* create the real one */
810        ksCreateSpoly(&(strat->L[j]), strat->kNoetherTail(), FALSE,
811                      strat->tailRing, m1, m2, strat->R);
812
813        strat->L[j].SetLmCurrRing();
814        if (!strat->honey)
815          strat->initEcart(&strat->L[j]);
816        else
817          strat->L[j].SetLength(strat->length_pLength);
818
819        BOOLEAN pp = hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat);
820
821        if (strat->use_buckets) strat->L[j].PrepareRed(TRUE);
822
823        if (pp)
824        {
825          p=strat->L[strat->Ll];
826          strat->L[strat->Ll]=strat->L[j];
827          strat->L[j]=p;
828          break;
829        }
830      }
831      j--;
832    }
833  }
834}
835
836/*2
837* computes the s-polynomials L[ ].p in L and
838* cuts elements in L above noether
839*/
840void updateLHC(kStrategy strat)
841{
842  int i = 0;
843  kTest_TS(strat);
844  while (i <= strat->Ll)
845  {
846    if (pNext(strat->L[i].p) == strat->tail)
847    {
848       /*- deletes the int spoly and computes -*/
849      if (pLmCmp(strat->L[i].p,strat->kNoether) == -1)
850      {
851        pLmFree(strat->L[i].p);
852        strat->L[i].p = NULL;
853      }
854      else
855      {
856        pLmFree(strat->L[i].p);
857        strat->L[i].p = NULL;
858        poly m1 = NULL, m2 = NULL;
859        // check that spoly creation is ok
860        while (strat->tailRing != currRing &&
861               !kCheckSpolyCreation(&(strat->L[i]), strat, m1, m2))
862        {
863          assume(m1 == NULL && m2 == NULL);
864          // if not, change to a ring where exponents are at least
865          // large enough
866          kStratChangeTailRing(strat);
867        }
868        /* create the real one */
869        ksCreateSpoly(&(strat->L[i]), strat->kNoetherTail(), FALSE,
870                      strat->tailRing, m1, m2, strat->R);
871        if (! strat->L[i].IsNull())
872        {
873          strat->L[i].SetLmCurrRing();
874          strat->L[i].SetpFDeg();
875          strat->L[i].ecart
876            = strat->L[i].pLDeg(strat->LDegLast) - strat->L[i].GetpFDeg();
877          if (strat->use_buckets) strat->L[i].PrepareRed(TRUE);
878        }
879      }
880    }
881    else
882      deleteHC(&(strat->L[i]), strat);
883   if (strat->L[i].IsNull())
884      deleteInL(strat->L,&strat->Ll,i,strat);
885    else
886    {
887#ifdef KDEBUG
888      kTest_L(&(strat->L[i]), strat->tailRing, TRUE, i, strat->T, strat->tl);
889#endif
890      i++;
891    }
892  }
893  kTest_TS(strat);
894}
895
896/*2
897* cuts in T above strat->kNoether and tries to cancel a unit
898*/
899void updateT(kStrategy strat)
900{
901  int i = 0;
902  LObject p;
903
904  while (i <= strat->tl)
905  {
906    p = strat->T[i];
907    deleteHC(&p,strat, TRUE);
908    /*- tries to cancel a unit: -*/
909    cancelunit(&p);
910    if (p.p != strat->T[i].p)
911    {
912      strat->sevT[i] = pGetShortExpVector(p.p);
913      p.SetpFDeg();
914    }
915    strat->T[i] = p;
916    i++;
917  }
918}
919
920/*2
921* arranges red, pos and T if strat->kHEdgeFound (first time)
922*/
923void firstUpdate(kStrategy strat)
924{
925  if (strat->update)
926  {
927    kTest_TS(strat);
928    strat->update = (strat->tl == -1);
929    //if (TEST_OPT_WEIGHTM)
930    //{
931    //  pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
932    //  if (strat->tailRing != currRing)
933    //  {
934    //    strat->tailRing->pFDeg = strat->pOrigFDeg_TailRing;
935    //    strat->tailRing->pLDeg = strat->pOrigLDeg_TailRing;
936    //  }
937    //  int i;
938    //  for (i=strat->Ll; i>=0; i--)
939    //  {
940    //    strat->L[i].SetpFDeg();
941    //  }
942    //  for (i=strat->tl; i>=0; i--)
943    //  {
944    //    strat->T[i].SetpFDeg();
945    //  }
946    //  if (ecartWeights)
947    //  {
948    //    omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
949    //    ecartWeights=NULL;
950    //  }
951    //}
952    if (TEST_OPT_FASTHC)
953    {
954      strat->posInL = strat->posInLOld;
955      strat->lastAxis = 0;
956    }
957    if (TEST_OPT_FINDET)
958      return;
959    strat->red = redFirst;
960    strat->use_buckets = kMoraUseBucket(strat);
961    updateT(strat);
962    strat->posInT = posInT2;
963    reorderT(strat);
964  }
965  kTest_TS(strat);
966}
967
968/*2
969*-puts p to the standardbasis s at position at
970*-reduces the tail of p if TEST_OPT_REDTAIL
971*-tries to cancel a unit
972*-HEckeTest
973*  if TRUE
974*  - decides about reduction-strategies
975*  - computes noether
976*  - stops computation if TEST_OPT_FINDET
977*  - cuts the tails of the polynomials
978*    in s,t and the elements in L above noether
979*    and cancels units if possible
980*  - reorders s,L
981*/
982void enterSMora (LObject p,int atS,kStrategy strat, int atR = -1)
983{
984  enterSBba(p, atS, strat, atR);
985  #ifdef KDEBUG
986  if (TEST_OPT_DEBUG)
987  {
988    Print("new s%d:",atS);
989    p_wrp(p.p,currRing,strat->tailRing);
990    PrintLn();
991  }
992  #endif
993  if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat);
994  if (strat->kHEdgeFound)
995  {
996    if (newHEdge(strat))
997    {
998      firstUpdate(strat);
999      if (TEST_OPT_FINDET)
1000        return;
1001      /*- cuts elements in L above noether and reorders L -*/
1002      updateLHC(strat);
1003      /*- reorders L with respect to posInL -*/
1004      reorderL(strat);
1005    }
1006  }
1007  else if (strat->kNoether!=NULL)
1008    strat->kHEdgeFound = TRUE;
1009  else if (TEST_OPT_FASTHC)
1010  {
1011    if (strat->posInLOldFlag)
1012    {
1013      missingAxis(&strat->lastAxis,strat);
1014      if (strat->lastAxis)
1015      {
1016        strat->posInLOld = strat->posInL;
1017        strat->posInLOldFlag = FALSE;
1018        strat->posInL = posInL10;
1019        strat->posInLDependsOnLength = TRUE;
1020        updateL(strat);
1021        reorderL(strat);
1022      }
1023    }
1024    else if (strat->lastAxis)
1025      updateL(strat);
1026  }
1027}
1028
1029/*2
1030*-puts p to the standardbasis s at position at
1031*-HEckeTest
1032*  if TRUE
1033*  - computes noether
1034*/
1035void enterSMoraNF (LObject p, int atS,kStrategy strat, int atR = -1)
1036{
1037  enterSBba(p, atS, strat, atR);
1038  if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat);
1039  if (strat->kHEdgeFound)
1040    newHEdge(strat);
1041  else if (strat->kNoether!=NULL)
1042    strat->kHEdgeFound = TRUE;
1043}
1044
1045void initBba(ideal F,kStrategy strat)
1046{
1047 /* setting global variables ------------------- */
1048  strat->enterS = enterSBba;
1049    strat->red = redHoney;
1050  if (strat->honey)
1051    strat->red = redHoney;
1052  else if (currRing->pLexOrder && !strat->homog)
1053    strat->red = redLazy;
1054  else
1055  {
1056    strat->LazyPass *=4;
1057    strat->red = redHomog;
1058  }
1059#ifdef HAVE_RINGS  //TODO Oliver
1060  if (rField_is_Ring(currRing))
1061  {
1062    strat->red = redRing;
1063  }
1064#endif
1065  if (currRing->pLexOrder && strat->honey)
1066    strat->initEcart = initEcartNormal;
1067  else
1068    strat->initEcart = initEcartBBA;
1069  if (strat->honey)
1070    strat->initEcartPair = initEcartPairMora;
1071  else
1072    strat->initEcartPair = initEcartPairBba;
1073//  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1074//  {
1075//    //interred  machen   Aenderung
1076//    strat->pOrigFDeg=pFDeg;
1077//    strat->pOrigLDeg=pLDeg;
1078//    //h=ggetid("ecart");
1079//    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
1080//    //{
1081//    //  ecartWeights=iv2array(IDINTVEC(h));
1082//    //}
1083//    //else
1084//    {
1085//      ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
1086//      /*uses automatic computation of the ecartWeights to set them*/
1087//      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1088//    }
1089//    pRestoreDegProcs(currRing,totaldegreeWecart, maxdegreeWecart);
1090//    if (TEST_OPT_PROT)
1091//    {
1092//      for(i=1; i<=(currRing->N); i++)
1093//        Print(" %d",ecartWeights[i]);
1094//      PrintLn();
1095//      mflush();
1096//    }
1097//  }
1098}
1099
1100
1101void initSba(ideal F,kStrategy strat)
1102{
1103  int i;
1104  //idhdl h;
1105 /* setting global variables ------------------- */
1106  strat->enterS = enterSSba;
1107    strat->red2 = redHoney;
1108  if (strat->honey)
1109    strat->red2 = redHoney;
1110  else if (currRing->pLexOrder && !strat->homog)
1111    strat->red2 = redLazy;
1112  else
1113  {
1114    strat->LazyPass *=4;
1115    strat->red2 = redHomog;
1116  }
1117#ifdef HAVE_RINGS  //TODO Oliver
1118  if (rField_is_Ring(currRing))
1119  {
1120    strat->red2 = redRing;
1121  }
1122#endif
1123  if (currRing->pLexOrder && strat->honey)
1124    strat->initEcart = initEcartNormal;
1125  else
1126    strat->initEcart = initEcartBBA;
1127  if (strat->honey)
1128    strat->initEcartPair = initEcartPairMora;
1129  else
1130    strat->initEcartPair = initEcartPairBba;
1131  //strat->kIdeal = NULL;
1132  //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD;
1133  //else              strat->kIdeal->rtyp=MODUL_CMD;
1134  //strat->kIdeal->data=(void *)strat->Shdl;
1135  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1136  {
1137    //interred  machen   Aenderung
1138    strat->pOrigFDeg  = currRing->pFDeg;
1139    strat->pOrigLDeg  = currRing->pLDeg;
1140    //h=ggetid("ecart");
1141    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
1142    //{
1143    //  ecartWeights=iv2array(IDINTVEC(h));
1144    //}
1145    //else
1146    {
1147      ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
1148      /*uses automatic computation of the ecartWeights to set them*/
1149      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights, currRing);
1150    }
1151    pRestoreDegProcs(currRing, totaldegreeWecart, maxdegreeWecart);
1152    if (TEST_OPT_PROT)
1153    {
1154      for(i=1; i<=(currRing->N); i++)
1155        Print(" %d",ecartWeights[i]);
1156      PrintLn();
1157      mflush();
1158    }
1159  }
1160  // for sig-safe reductions in signature-based
1161  // standard basis computations
1162  strat->red          = redSig;
1163  //strat->incremental  = TRUE;
1164  strat->currIdx      = 1;
1165}
1166
1167void initMora(ideal F,kStrategy strat)
1168{
1169  int i,j;
1170
1171  strat->NotUsedAxis = (BOOLEAN *)omAlloc(((currRing->N)+1)*sizeof(BOOLEAN));
1172  for (j=(currRing->N); j>0; j--) strat->NotUsedAxis[j] = TRUE;
1173  strat->enterS = enterSMora;
1174  strat->initEcartPair = initEcartPairMora; /*- ecart approximation -*/
1175  strat->posInLOld = strat->posInL;
1176  strat->posInLOldFlag = TRUE;
1177  strat->initEcart = initEcartNormal;
1178  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
1179  if ( strat->kHEdgeFound )
1180     strat->kNoether = pCopy((currRing->ppNoether));
1181  else if (strat->kHEdgeFound || strat->homog)
1182    strat->red = redFirst;  /*take the first possible in T*/
1183  else
1184    strat->red = redEcart;/*take the first possible in under ecart-restriction*/
1185  if (strat->kHEdgeFound)
1186  {
1187    strat->HCord = currRing->pFDeg((currRing->ppNoether),currRing)+1;
1188    strat->posInT = posInT2;
1189  }
1190  else
1191  {
1192    strat->HCord = 32000;/*- very large -*/
1193  }
1194  /*reads the ecartWeights used for Graebes method from the
1195   *intvec ecart and set ecartWeights
1196   */
1197  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1198  {
1199    //interred  machen   Aenderung
1200    strat->pOrigFDeg=currRing->pFDeg;
1201    strat->pOrigLDeg=currRing->pLDeg;
1202    ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
1203    /*uses automatic computation of the ecartWeights to set them*/
1204    kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights,currRing);
1205
1206    pSetDegProcs(currRing,totaldegreeWecart, maxdegreeWecart);
1207    if (TEST_OPT_PROT)
1208    {
1209      for(i=1; i<=(currRing->N); i++)
1210        Print(" %d",ecartWeights[i]);
1211      PrintLn();
1212      mflush();
1213    }
1214  }
1215  kOptimizeLDeg(currRing->pLDeg, strat);
1216}
1217
1218#ifdef HAVE_ASSUME
1219static int mora_count = 0;
1220static int mora_loop_count;
1221#endif
1222
1223void kDebugPrint(kStrategy strat);
1224
1225ideal mora (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
1226{
1227#ifdef HAVE_ASSUME
1228  mora_count++;
1229  mora_loop_count = 0;
1230#endif
1231#ifdef KDEBUG
1232  om_Opts.MinTrack = 5;
1233#endif
1234  int olddeg = 0;
1235  int reduc = 0;
1236  int red_result = 1;
1237  int hilbeledeg=1,hilbcount=0;
1238  int save_test=test;
1239  if (currRing->MixedOrder)
1240  {
1241    test &= ~Sy_bit(OPT_REDSB);
1242    test &= ~Sy_bit(OPT_REDTAIL);
1243  }
1244
1245  strat->update = TRUE;
1246  /*- setting global variables ------------------- -*/
1247  initBuchMoraCrit(strat);
1248  initHilbCrit(F,Q,&hilb,strat);
1249  initMora(F,strat);
1250  initBuchMoraPos(strat);
1251  /*Shdl=*/initBuchMora(F,Q,strat);
1252  if (TEST_OPT_FASTHC) missingAxis(&strat->lastAxis,strat);
1253  /*updateS in initBuchMora has Hecketest
1254  * and could have put strat->kHEdgdeFound FALSE*/
1255  if ((currRing->ppNoether)!=NULL)
1256  {
1257    strat->kHEdgeFound = TRUE;
1258  }
1259  if (strat->kHEdgeFound && strat->update)
1260  {
1261    firstUpdate(strat);
1262    updateLHC(strat);
1263    reorderL(strat);
1264  }
1265  if (TEST_OPT_FASTHC && (strat->lastAxis) && strat->posInLOldFlag)
1266  {
1267    strat->posInLOld = strat->posInL;
1268    strat->posInLOldFlag = FALSE;
1269    strat->posInL = posInL10;
1270    updateL(strat);
1271    reorderL(strat);
1272  }
1273  kTest_TS(strat);
1274  strat->use_buckets = kMoraUseBucket(strat);
1275  /*- compute-------------------------------------------*/
1276
1277#ifdef HAVE_TAIL_RING
1278//  if (strat->homog && strat->red == redFirst)
1279  kStratInitChangeTailRing(strat);
1280#endif
1281  if (BVERBOSE(23))
1282  {
1283    kDebugPrint(strat);
1284  }
1285
1286  while (strat->Ll >= 0)
1287  {
1288#ifdef HAVE_ASSUME
1289    mora_loop_count++;
1290#endif
1291    #ifdef KDEBUG
1292    if (TEST_OPT_DEBUG) messageSets(strat);
1293    #endif
1294    if (TEST_OPT_DEGBOUND
1295    && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg))
1296    {
1297      /*
1298      * stops computation if
1299      * - 24 (degBound)
1300      *   && upper degree is bigger than Kstd1_deg
1301      */
1302      while ((strat->Ll >= 0)
1303        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
1304        && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg)
1305      )
1306      {
1307        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1308        //if (TEST_OPT_PROT)
1309        //{
1310        //   PrintS("D"); mflush();
1311        //}
1312      }
1313      if (strat->Ll<0) break;
1314      else strat->noClearS=TRUE;
1315    }
1316    strat->P = strat->L[strat->Ll];/*- picks the last element from the lazyset L -*/
1317    if (strat->Ll==0) strat->interpt=TRUE;
1318    strat->Ll--;
1319
1320    // create the real Spoly
1321    if (pNext(strat->P.p) == strat->tail)
1322    {
1323      /*- deletes the short spoly and computes -*/
1324#ifdef HAVE_RINGS_LOC
1325      if (rField_is_Ring(currRing))
1326        pLmDelete(strat->P.p);
1327      else
1328#endif
1329      pLmFree(strat->P.p);
1330      strat->P.p = NULL;
1331      poly m1 = NULL, m2 = NULL;
1332      // check that spoly creation is ok
1333      while (strat->tailRing != currRing &&
1334             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
1335      {
1336        assume(m1 == NULL && m2 == NULL);
1337        // if not, change to a ring where exponents are large enough
1338        kStratChangeTailRing(strat);
1339      }
1340      /* create the real one */
1341      ksCreateSpoly(&(strat->P), strat->kNoetherTail(), strat->use_buckets,
1342                    strat->tailRing, m1, m2, strat->R);
1343      if (!strat->use_buckets)
1344        strat->P.SetLength(strat->length_pLength);
1345    }
1346    else if (strat->P.p1 == NULL)
1347    {
1348      // for input polys, prepare reduction (buckets !)
1349      strat->P.SetLength(strat->length_pLength);
1350      strat->P.PrepareRed(strat->use_buckets);
1351    }
1352
1353    if (!strat->P.IsNull())
1354    {
1355      // might be NULL from noether !!!
1356      if (TEST_OPT_PROT)
1357        message(strat->P.ecart+strat->P.GetpFDeg(),&olddeg,&reduc,strat, red_result);
1358      // reduce
1359      red_result = strat->red(&strat->P,strat);
1360    }
1361
1362    if (! strat->P.IsNull())
1363    {
1364      strat->P.GetP();
1365      // statistics
1366      if (TEST_OPT_PROT) PrintS("s");
1367      // normalization
1368      if (!TEST_OPT_INTSTRATEGY)
1369        strat->P.pNorm();
1370      // tailreduction
1371      strat->P.p = redtail(&(strat->P),strat->sl,strat);
1372      // set ecart -- might have changed because of tail reductions
1373      if ((!strat->noTailReduction) && (!strat->honey))
1374        strat->initEcart(&strat->P);
1375      // cancel unit
1376      cancelunit(&strat->P);
1377      // for char 0, clear denominators
1378      if (TEST_OPT_INTSTRATEGY)
1379        strat->P.pCleardenom();
1380
1381      // put in T
1382      enterT(strat->P,strat);
1383      // build new pairs
1384#ifdef HAVE_RINGS_LOC
1385      if (rField_is_Ring(currRing))
1386        superenterpairs(strat->P.p,strat->sl,strat->P.ecart,0,strat, strat->tl);
1387      else
1388#endif
1389      enterpairs(strat->P.p,strat->sl,strat->P.ecart,0,strat, strat->tl);
1390      // put in S
1391      strat->enterS(strat->P,
1392                    posInS(strat,strat->sl,strat->P.p, strat->P.ecart),
1393                    strat, strat->tl);
1394
1395      // apply hilbert criterion
1396      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1397
1398      // clear strat->P
1399      if (strat->P.lcm!=NULL)
1400#ifdef HAVE_RINGS_LOC
1401        pLmDelete(strat->P.lcm);
1402#else
1403        pLmFree(strat->P.lcm);
1404#endif
1405      strat->P.lcm=NULL;
1406#ifdef KDEBUG
1407      // make sure kTest_TS does not complain about strat->P
1408      memset(&strat->P,0,sizeof(strat->P));
1409#endif
1410    }
1411    if (strat->kHEdgeFound)
1412    {
1413      if ((TEST_OPT_FINDET)
1414      || ((TEST_OPT_MULTBOUND) && (scMult0Int((strat->Shdl)) < Kstd1_mu)))
1415      {
1416        // obachman: is this still used ???
1417        /*
1418        * stops computation if strat->kHEdgeFound and
1419        * - 27 (finiteDeterminacyTest)
1420        * or
1421        * - 23
1422        *   (multBound)
1423        *   && multiplicity of the ideal is smaller then a predefined number mu
1424        */
1425        while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1426      }
1427    }
1428    kTest_TS(strat);
1429  }
1430  /*- complete reduction of the standard basis------------------------ -*/
1431  if (TEST_OPT_REDSB) completeReduce(strat);
1432  else if (TEST_OPT_PROT) PrintLn();
1433  /*- release temp data------------------------------- -*/
1434  exitBuchMora(strat);
1435  /*- polynomials used for HECKE: HC, noether -*/
1436  if (TEST_OPT_FINDET)
1437  {
1438    if (strat->kHEdge!=NULL)
1439      Kstd1_mu=currRing->pFDeg(strat->kHEdge,currRing);
1440    else
1441      Kstd1_mu=-1;
1442  }
1443  pDelete(&strat->kHEdge);
1444  strat->update = TRUE; //???
1445  strat->lastAxis = 0; //???
1446  pDelete(&strat->kNoether);
1447  omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN));
1448  if (TEST_OPT_PROT) messageStat(hilbcount,strat);
1449//  if (TEST_OPT_WEIGHTM)
1450//  {
1451//    pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
1452//    if (ecartWeights)
1453//    {
1454//      omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
1455//      ecartWeights=NULL;
1456//    }
1457//  }
1458  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1459  test=save_test;
1460  idTest(strat->Shdl);
1461  return (strat->Shdl);
1462}
1463
1464poly kNF1 (ideal F,ideal Q,poly q, kStrategy strat, int lazyReduce)
1465{
1466  assume(q!=NULL);
1467  assume(!(idIs0(F)&&(Q==NULL)));
1468
1469// lazy_reduce flags: can be combined by |
1470//#define KSTD_NF_LAZY   1
1471  // do only a reduction of the leading term
1472//#define KSTD_NF_ECART  2
1473  // only local: recude even with bad ecart
1474  poly   p;
1475  int   i;
1476  int   j;
1477  int   o;
1478  LObject   h;
1479  BITSET save_test=test;
1480
1481  //if ((idIs0(F))&&(Q==NULL))
1482  //  return pCopy(q); /*F=0*/
1483  //strat->ak = si_max(idRankFreeModule(F),pMaxComp(q));
1484  /*- creating temp data structures------------------- -*/
1485  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
1486  strat->kNoether    = pCopy((currRing->ppNoether));
1487  test|=Sy_bit(OPT_REDTAIL);
1488  test&=~Sy_bit(OPT_INTSTRATEGY);
1489  if (TEST_OPT_STAIRCASEBOUND
1490  && (! TEST_V_DEG_STOP)
1491  && (0<Kstd1_deg)
1492  && ((!strat->kHEdgeFound)
1493    ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg))))
1494  {
1495    pDelete(&strat->kNoether);
1496    strat->kNoether=pOne();
1497    pSetExp(strat->kNoether,1, Kstd1_deg+1);
1498    pSetm(strat->kNoether);
1499    strat->kHEdgeFound=TRUE;
1500  }
1501  initBuchMoraCrit(strat);
1502  initBuchMoraPos(strat);
1503  initMora(F,strat);
1504  strat->enterS = enterSMoraNF;
1505  /*- set T -*/
1506  strat->tl = -1;
1507  strat->tmax = setmaxT;
1508  strat->T = initT();
1509  strat->R = initR();
1510  strat->sevT = initsevT();
1511  /*- set S -*/
1512  strat->sl = -1;
1513  /*- init local data struct.-------------------------- -*/
1514  /*Shdl=*/initS(F,Q,strat);
1515  if ((strat->ak!=0)
1516  && (strat->kHEdgeFound))
1517  {
1518    if (strat->ak!=1)
1519    {
1520      pSetComp(strat->kNoether,1);
1521      pSetmComp(strat->kNoether);
1522      poly p=pHead(strat->kNoether);
1523      pSetComp(p,strat->ak);
1524      pSetmComp(p);
1525      p=pAdd(strat->kNoether,p);
1526      strat->kNoether=pNext(p);
1527      p_LmFree(p,currRing);
1528    }
1529  }
1530  if ((lazyReduce & KSTD_NF_LAZY)==0)
1531  {
1532    for (i=strat->sl; i>=0; i--)
1533      pNorm(strat->S[i]);
1534  }
1535  /*- puts the elements of S also to T -*/
1536  for (i=0; i<=strat->sl; i++)
1537  {
1538    h.p = strat->S[i];
1539    h.ecart = strat->ecartS[i];
1540    if (strat->sevS[i] == 0) strat->sevS[i] = pGetShortExpVector(h.p);
1541    else assume(strat->sevS[i] == pGetShortExpVector(h.p));
1542    h.length = pLength(h.p);
1543    h.sev = strat->sevS[i];
1544    h.SetpFDeg();
1545    enterT(h,strat);
1546  }
1547  /*- compute------------------------------------------- -*/
1548  p = pCopy(q);
1549  deleteHC(&p,&o,&j,strat);
1550  kTest(strat);
1551  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
1552  if (BVERBOSE(23)) kDebugPrint(strat);
1553  if (p!=NULL) p = redMoraNF(p,strat, lazyReduce & KSTD_NF_ECART);
1554  if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
1555  {
1556    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1557    p = redtail(p,strat->sl,strat);
1558  }
1559  /*- release temp data------------------------------- -*/
1560  cleanT(strat);
1561  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
1562  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1563  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
1564  omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN));
1565  omfree(strat->sevT);
1566  omfree(strat->S_2_R);
1567  omfree(strat->R);
1568
1569  if ((Q!=NULL)&&(strat->fromQ!=NULL))
1570  {
1571    i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
1572    omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
1573    strat->fromQ=NULL;
1574  }
1575  pDelete(&strat->kHEdge);
1576  pDelete(&strat->kNoether);
1577//  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1578//  {
1579//    pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
1580//    if (ecartWeights)
1581//    {
1582//      omFreeSize((ADDRESS *)&ecartWeights,((currRing->N)+1)*sizeof(short));
1583//      ecartWeights=NULL;
1584//    }
1585//  }
1586  idDelete(&strat->Shdl);
1587  test=save_test;
1588  if (TEST_OPT_PROT) PrintLn();
1589  return p;
1590}
1591
1592ideal kNF1 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce)
1593{
1594  assume(!idIs0(q));
1595  assume(!(idIs0(F)&&(Q==NULL)));
1596
1597// lazy_reduce flags: can be combined by |
1598//#define KSTD_NF_LAZY   1
1599  // do only a reduction of the leading term
1600//#define KSTD_NF_ECART  2
1601  // only local: recude even with bad ecart
1602  poly   p;
1603  int   i;
1604  int   j;
1605  int   o;
1606  LObject   h;
1607  ideal res;
1608  BITSET save_test=test;
1609
1610  //if (idIs0(q)) return idInit(IDELEMS(q),si_max(q->rank,F->rank));
1611  //if ((idIs0(F))&&(Q==NULL))
1612  //  return idCopy(q); /*F=0*/
1613  //strat->ak = si_max(idRankFreeModule(F),idRankFreeModule(q));
1614  /*- creating temp data structures------------------- -*/
1615  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
1616  strat->kNoether=pCopy((currRing->ppNoether));
1617  test|=Sy_bit(OPT_REDTAIL);
1618  if (TEST_OPT_STAIRCASEBOUND
1619  && (0<Kstd1_deg)
1620  && ((!strat->kHEdgeFound)
1621    ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg))))
1622  {
1623    pDelete(&strat->kNoether);
1624    strat->kNoether=pOne();
1625    pSetExp(strat->kNoether,1, Kstd1_deg+1);
1626    pSetm(strat->kNoether);
1627    strat->kHEdgeFound=TRUE;
1628  }
1629  initBuchMoraCrit(strat);
1630  initBuchMoraPos(strat);
1631  initMora(F,strat);
1632  strat->enterS = enterSMoraNF;
1633  /*- set T -*/
1634  strat->tl = -1;
1635  strat->tmax = setmaxT;
1636  strat->T = initT();
1637  strat->R = initR();
1638  strat->sevT = initsevT();
1639  /*- set S -*/
1640  strat->sl = -1;
1641  /*- init local data struct.-------------------------- -*/
1642  /*Shdl=*/initS(F,Q,strat);
1643  if ((strat->ak!=0)
1644  && (strat->kHEdgeFound))
1645  {
1646    if (strat->ak!=1)
1647    {
1648      pSetComp(strat->kNoether,1);
1649      pSetmComp(strat->kNoether);
1650      poly p=pHead(strat->kNoether);
1651      pSetComp(p,strat->ak);
1652      pSetmComp(p);
1653      p=pAdd(strat->kNoether,p);
1654      strat->kNoether=pNext(p);
1655      p_LmFree(p,currRing);
1656    }
1657  }
1658  if (TEST_OPT_INTSTRATEGY && ((lazyReduce & KSTD_NF_LAZY)==0))
1659  {
1660    for (i=strat->sl; i>=0; i--)
1661      pNorm(strat->S[i]);
1662  }
1663  /*- compute------------------------------------------- -*/
1664  res=idInit(IDELEMS(q),strat->ak);
1665  for (i=0; i<IDELEMS(q); i++)
1666  {
1667    if (q->m[i]!=NULL)
1668    {
1669      p = pCopy(q->m[i]);
1670      deleteHC(&p,&o,&j,strat);
1671      if (p!=NULL)
1672      {
1673        /*- puts the elements of S also to T -*/
1674        for (j=0; j<=strat->sl; j++)
1675        {
1676          h.p = strat->S[j];
1677          h.ecart = strat->ecartS[j];
1678          h.pLength = h.length = pLength(h.p);
1679          if (strat->sevS[j] == 0) strat->sevS[j] = pGetShortExpVector(h.p);
1680          else assume(strat->sevS[j] == pGetShortExpVector(h.p));
1681          h.sev = strat->sevS[j];
1682          h.SetpFDeg();
1683          enterT(h,strat);
1684        }
1685        if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
1686        p = redMoraNF(p,strat, lazyReduce & KSTD_NF_ECART);
1687        if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
1688        {
1689          if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1690          p = redtail(p,strat->sl,strat);
1691        }
1692        cleanT(strat);
1693      }
1694      res->m[i]=p;
1695    }
1696    //else
1697    //  res->m[i]=NULL;
1698  }
1699  /*- release temp data------------------------------- -*/
1700  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
1701  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1702  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
1703  omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN));
1704  omfree(strat->sevT);
1705  omfree(strat->S_2_R);
1706  omfree(strat->R);
1707  if ((Q!=NULL)&&(strat->fromQ!=NULL))
1708  {
1709    i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
1710    omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
1711    strat->fromQ=NULL;
1712  }
1713  pDelete(&strat->kHEdge);
1714  pDelete(&strat->kNoether);
1715//  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1716//  {
1717//    pFDeg=strat->pOrigFDeg;
1718//    pLDeg=strat->pOrigLDeg;
1719//    if (ecartWeights)
1720//    {
1721//      omFreeSize((ADDRESS *)&ecartWeights,((currRing->N)+1)*sizeof(short));
1722//      ecartWeights=NULL;
1723//    }
1724//  }
1725  idDelete(&strat->Shdl);
1726  test=save_test;
1727  if (TEST_OPT_PROT) PrintLn();
1728  return res;
1729}
1730
1731intvec * kModW, * kHomW;
1732
1733long kModDeg(poly p, ring r)
1734{
1735  long o=p_WDegree(p, r);
1736  long i=p_GetComp(p, r);
1737  if (i==0) return o;
1738  //assume((i>0) && (i<=kModW->length()));
1739  if (i<=kModW->length())
1740    return o+(*kModW)[i-1];
1741  return o;
1742}
1743long kHomModDeg(poly p, ring r)
1744{
1745  int i;
1746  long j=0;
1747
1748  for (i=r->N;i>0;i--)
1749    j+=p_GetExp(p,i,r)*(*kHomW)[i-1];
1750  if (kModW == NULL) return j;
1751  i = p_GetComp(p,r);
1752  if (i==0) return j;
1753  return j+(*kModW)[i-1];
1754}
1755
1756ideal kStd(ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp,
1757          int newIdeal, intvec *vw)
1758{
1759  if(idIs0(F))
1760    return idInit(1,F->rank);
1761
1762  ideal r;
1763  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
1764  BOOLEAN delete_w=(w==NULL);
1765  kStrategy strat=new skStrategy;
1766
1767  if(!TEST_OPT_RETURN_SB)
1768    strat->syzComp = syzComp;
1769  if (TEST_OPT_SB_1)
1770    strat->newIdeal = newIdeal;
1771  if (rField_has_simple_inverse(currRing))
1772    strat->LazyPass=20;
1773  else
1774    strat->LazyPass=2;
1775  strat->LazyDegree = 1;
1776  strat->enterOnePair=enterOnePairNormal;
1777  strat->chainCrit=chainCritNormal;
1778  strat->ak = id_RankFreeModule(F,currRing);
1779  strat->kModW=kModW=NULL;
1780  strat->kHomW=kHomW=NULL;
1781  if (vw != NULL)
1782  {
1783    currRing->pLexOrder=FALSE;
1784    strat->kHomW=kHomW=vw;
1785    strat->pOrigFDeg = currRing->pFDeg;
1786    strat->pOrigLDeg = currRing->pLDeg;
1787    pSetDegProcs(currRing,kHomModDeg);
1788    toReset = TRUE;
1789  }
1790  if (h==testHomog)
1791  {
1792    if (strat->ak == 0)
1793    {
1794      h = (tHomog)idHomIdeal(F,Q);
1795      w=NULL;
1796    }
1797    else if (!TEST_OPT_DEGBOUND)
1798    {
1799      h = (tHomog)idHomModule(F,Q,w);
1800    }
1801  }
1802  currRing->pLexOrder=b;
1803  if (h==isHomog)
1804  {
1805    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
1806    {
1807      strat->kModW = kModW = *w;
1808      if (vw == NULL)
1809      {
1810        strat->pOrigFDeg = currRing->pFDeg;
1811        strat->pOrigLDeg = currRing->pLDeg;
1812        pSetDegProcs(currRing,kModDeg);
1813        toReset = TRUE;
1814      }
1815    }
1816    currRing->pLexOrder = TRUE;
1817    if (hilb==NULL) strat->LazyPass*=2;
1818  }
1819  strat->homog=h;
1820#ifdef KDEBUG
1821  idTest(F);
1822  idTest(Q);
1823
1824#if MYTEST
1825  if (TEST_OPT_DEBUG)
1826  {
1827    PrintS("// kSTD: currRing: ");
1828    rWrite(currRing);
1829  }
1830#endif
1831
1832#endif
1833#ifdef HAVE_PLURAL
1834  if (rIsPluralRing(currRing))
1835  {
1836    const BOOLEAN bIsSCA  = rIsSCA(currRing) && strat->z2homog; // for Z_2 prod-crit
1837    strat->no_prod_crit   = ! bIsSCA;
1838    if (w!=NULL)
1839      r = nc_GB(F, Q, *w, hilb, strat, currRing);
1840    else
1841      r = nc_GB(F, Q, NULL, hilb, strat, currRing);
1842  }
1843  else
1844#endif
1845#ifdef HAVE_RINGS
1846  if (rField_is_Ring(currRing))
1847    r=bba(F,Q,NULL,hilb,strat);
1848  else
1849#endif
1850  {
1851    if (currRing->OrdSgn==-1)
1852    {
1853      if (w!=NULL)
1854        r=mora(F,Q,*w,hilb,strat);
1855      else
1856        r=mora(F,Q,NULL,hilb,strat);
1857    }
1858    else
1859    {
1860      if (w!=NULL)
1861        r=bba(F,Q,*w,hilb,strat);
1862      else
1863        r=bba(F,Q,NULL,hilb,strat);
1864    }
1865  }
1866#ifdef KDEBUG
1867  idTest(r);
1868#endif
1869  if (toReset)
1870  {
1871    kModW = NULL;
1872    pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
1873  }
1874  currRing->pLexOrder = b;
1875//Print("%d reductions canceled \n",strat->cel);
1876  HCord=strat->HCord;
1877  delete(strat);
1878  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
1879  return r;
1880}
1881
1882ideal kSba(ideal F, ideal Q, tHomog h,intvec ** w, int incremental, int arri, intvec *hilb,int syzComp,
1883          int newIdeal, intvec *vw)
1884{
1885  if(idIs0(F))
1886    return idInit(1,F->rank);
1887
1888  ideal r;
1889  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
1890  BOOLEAN delete_w=(w==NULL);
1891  kStrategy strat=new skStrategy;
1892  if (incremental!=0)
1893  {
1894    strat->incremental = TRUE;
1895  }
1896  else
1897  {
1898    strat->incremental = FALSE;
1899  }
1900  if (arri!=0)
1901  {
1902    strat->rewCrit1 = arriRewDummy;
1903    strat->rewCrit2 = arriRewCriterion;
1904  }
1905  else
1906  {
1907    strat->rewCrit1 = faugereRewCriterion;
1908    strat->rewCrit2 = faugereRewCriterion;
1909  }
1910
1911  if(!TEST_OPT_RETURN_SB)
1912    strat->syzComp = syzComp;
1913  if (TEST_OPT_SB_1)
1914    strat->newIdeal = newIdeal;
1915  if (rField_has_simple_inverse(currRing))
1916    strat->LazyPass=20;
1917  else
1918    strat->LazyPass=2;
1919  strat->LazyDegree = 1;
1920  strat->enterOnePair=enterOnePairNormal;
1921  strat->chainCrit=chainCritNormal;
1922  strat->ak = id_RankFreeModule(F,currRing);
1923  strat->kModW=kModW=NULL;
1924  strat->kHomW=kHomW=NULL;
1925  if (vw != NULL)
1926  {
1927    currRing->pLexOrder=FALSE;
1928    strat->kHomW=kHomW=vw;
1929    strat->pOrigFDeg = currRing->pFDeg;
1930    strat->pOrigLDeg = currRing->pLDeg;
1931    pSetDegProcs(currRing,kHomModDeg);
1932    toReset = TRUE;
1933  }
1934  if (h==testHomog)
1935  {
1936    if (strat->ak == 0)
1937    {
1938      h = (tHomog)idHomIdeal(F,Q);
1939      w=NULL;
1940    }
1941    else if (!TEST_OPT_DEGBOUND)
1942    {
1943      h = (tHomog)idHomModule(F,Q,w);
1944    }
1945  }
1946  currRing->pLexOrder=b;
1947  if (h==isHomog)
1948  {
1949    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
1950    {
1951      strat->kModW = kModW = *w;
1952      if (vw == NULL)
1953      {
1954        strat->pOrigFDeg = currRing->pFDeg;
1955        strat->pOrigLDeg = currRing->pLDeg;
1956        pSetDegProcs(currRing,kModDeg);
1957        toReset = TRUE;
1958      }
1959    }
1960    currRing->pLexOrder = TRUE;
1961    if (hilb==NULL) strat->LazyPass*=2;
1962  }
1963  strat->homog=h;
1964#ifdef KDEBUG
1965  idTest(F);
1966  idTest(Q);
1967
1968#if MYTEST
1969  if (TEST_OPT_DEBUG)
1970  {
1971    PrintS("// kSTD: currRing: ");
1972    rWrite(currRing);
1973  }
1974#endif
1975
1976#endif
1977#ifdef HAVE_PLURAL
1978  if (rIsPluralRing(currRing))
1979  {
1980    const BOOLEAN bIsSCA  = rIsSCA(currRing) && strat->z2homog; // for Z_2 prod-crit
1981    strat->no_prod_crit   = ! bIsSCA;
1982    if (w!=NULL)
1983      r = nc_GB(F, Q, *w, hilb, strat, currRing);
1984    else
1985      r = nc_GB(F, Q, NULL, hilb, strat, currRing);
1986  }
1987  else
1988#endif
1989#ifdef HAVE_RINGS
1990  if (rField_is_Ring(currRing))
1991    r=bba(F,Q,NULL,hilb,strat);
1992  else
1993#endif
1994  {
1995    if (currRing->OrdSgn==-1)
1996    {
1997      if (w!=NULL)
1998        r=mora(F,Q,*w,hilb,strat);
1999      else
2000        r=mora(F,Q,NULL,hilb,strat);
2001    }
2002    else
2003    {
2004      if (w!=NULL)
2005        r=sba(F,Q,*w,hilb,strat);
2006      else
2007                          r=sba(F,Q,NULL,hilb,strat);
2008    }
2009  }
2010#ifdef KDEBUG
2011  idTest(r);
2012#endif
2013  if (toReset)
2014  {
2015    kModW = NULL;
2016    pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2017  }
2018  currRing->pLexOrder = b;
2019//Print("%d reductions canceled \n",strat->cel);
2020  HCord=strat->HCord;
2021  delete(strat);
2022  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
2023  return r;
2024}
2025
2026#ifdef HAVE_SHIFTBBA
2027ideal kStdShift(ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp,
2028                int newIdeal, intvec *vw, int uptodeg, int lV)
2029{
2030  ideal r;
2031  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
2032  BOOLEAN delete_w=(w==NULL);
2033  kStrategy strat=new skStrategy;
2034
2035  if(!TEST_OPT_RETURN_SB)
2036    strat->syzComp = syzComp;
2037  if (TEST_OPT_SB_1)
2038    strat->newIdeal = newIdeal;
2039  if (rField_has_simple_inverse(currRing))
2040    strat->LazyPass=20;
2041  else
2042    strat->LazyPass=2;
2043  strat->LazyDegree = 1;
2044  strat->ak = id_RankFreeModule(F,currRing);
2045  strat->kModW=kModW=NULL;
2046  strat->kHomW=kHomW=NULL;
2047  if (vw != NULL)
2048  {
2049    currRing->pLexOrder=FALSE;
2050    strat->kHomW=kHomW=vw;
2051    strat->pOrigFDeg = currRing->pFDeg;
2052    strat->pOrigLDeg = currRing->pLDeg;
2053    pSetDegProcs(currRing,kHomModDeg);
2054    toReset = TRUE;
2055  }
2056  if (h==testHomog)
2057  {
2058    if (strat->ak == 0)
2059    {
2060      h = (tHomog)idHomIdeal(F,Q);
2061      w=NULL;
2062    }
2063    else if (!TEST_OPT_DEGBOUND)
2064    {
2065      h = (tHomog)idHomModule(F,Q,w);
2066    }
2067  }
2068  currRing->pLexOrder=b;
2069  if (h==isHomog)
2070  {
2071    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
2072    {
2073      strat->kModW = kModW = *w;
2074      if (vw == NULL)
2075      {
2076        strat->pOrigFDeg = currRing->pFDeg;
2077        strat->pOrigLDeg = currRing->pLDeg;
2078        pSetDegProcs(currRing,kModDeg);
2079        toReset = TRUE;
2080      }
2081    }
2082    currRing->pLexOrder = TRUE;
2083    if (hilb==NULL) strat->LazyPass*=2;
2084  }
2085  strat->homog=h;
2086#ifdef KDEBUG
2087  idTest(F);
2088#endif
2089  if (currRing->OrdSgn==-1)
2090  {
2091    /* error: no local ord yet with shifts */
2092    Print("No local ordering possible for shifts");
2093    return(NULL);
2094  }
2095  else
2096  {
2097    /* global ordering */
2098    if (w!=NULL)
2099      r=bbaShift(F,Q,*w,hilb,strat,uptodeg,lV);
2100    else
2101      r=bbaShift(F,Q,NULL,hilb,strat,uptodeg,lV);
2102  }
2103#ifdef KDEBUG
2104  idTest(r);
2105#endif
2106  if (toReset)
2107  {
2108    kModW = NULL;
2109    pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2110  }
2111  currRing->pLexOrder = b;
2112//Print("%d reductions canceled \n",strat->cel);
2113  HCord=strat->HCord;
2114  delete(strat);
2115  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
2116  return r;
2117}
2118#endif
2119
2120//##############################################################
2121//##############################################################
2122//##############################################################
2123//##############################################################
2124//##############################################################
2125
2126ideal kMin_std(ideal F, ideal Q, tHomog h,intvec ** w, ideal &M, intvec *hilb,
2127              int syzComp, int reduced)
2128{
2129  if(idIs0(F))
2130  {
2131    M=idInit(1,F->rank);
2132    return idInit(1,F->rank);
2133  }
2134
2135  ideal r=NULL;
2136  int Kstd1_OldDeg = Kstd1_deg,i;
2137  intvec* temp_w=NULL;
2138  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
2139  BOOLEAN delete_w=(w==NULL);
2140  BOOLEAN oldDegBound=TEST_OPT_DEGBOUND;
2141  kStrategy strat=new skStrategy;
2142
2143  if(!TEST_OPT_RETURN_SB)
2144     strat->syzComp = syzComp;
2145  if (rField_has_simple_inverse(currRing))
2146    strat->LazyPass=20;
2147  else
2148    strat->LazyPass=2;
2149  strat->LazyDegree = 1;
2150  strat->minim=(reduced % 2)+1;
2151  strat->ak = id_RankFreeModule(F,currRing);
2152  if (delete_w)
2153  {
2154    temp_w=new intvec((strat->ak)+1);
2155    w = &temp_w;
2156  }
2157  if ((h==testHomog)
2158  )
2159  {
2160    if (strat->ak == 0)
2161    {
2162      h = (tHomog)idHomIdeal(F,Q);
2163      w=NULL;
2164    }
2165    else
2166    {
2167      h = (tHomog)idHomModule(F,Q,w);
2168    }
2169  }
2170  if (h==isHomog)
2171  {
2172    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
2173    {
2174      kModW = *w;
2175      strat->kModW = *w;
2176      assume(currRing->pFDeg != NULL && currRing->pLDeg != NULL);
2177      strat->pOrigFDeg = currRing->pFDeg;
2178      strat->pOrigLDeg = currRing->pLDeg;
2179      pSetDegProcs(currRing,kModDeg);
2180
2181      toReset = TRUE;
2182      if (reduced>1)
2183      {
2184        Kstd1_OldDeg=Kstd1_deg;
2185        Kstd1_deg = -1;
2186        for (i=IDELEMS(F)-1;i>=0;i--)
2187        {
2188          if ((F->m[i]!=NULL) && (currRing->pFDeg(F->m[i],currRing)>=Kstd1_deg))
2189            Kstd1_deg = currRing->pFDeg(F->m[i],currRing)+1;
2190        }
2191      }
2192    }
2193    currRing->pLexOrder = TRUE;
2194    strat->LazyPass*=2;
2195  }
2196  strat->homog=h;
2197  if (currRing->OrdSgn==-1)
2198  {
2199    if (w!=NULL)
2200      r=mora(F,Q,*w,hilb,strat);
2201    else
2202      r=mora(F,Q,NULL,hilb,strat);
2203  }
2204  else
2205  {
2206    if (w!=NULL)
2207      r=bba(F,Q,*w,hilb,strat);
2208    else
2209      r=bba(F,Q,NULL,hilb,strat);
2210  }
2211#ifdef KDEBUG
2212  {
2213    int i;
2214    for (i=IDELEMS(r)-1; i>=0; i--) pTest(r->m[i]);
2215  }
2216#endif
2217  idSkipZeroes(r);
2218  if (toReset)
2219  {
2220    pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2221    kModW = NULL;
2222  }
2223  currRing->pLexOrder = b;
2224  HCord=strat->HCord;
2225  if ((delete_w)&&(temp_w!=NULL)) delete temp_w;
2226  if ((IDELEMS(r)==1) && (r->m[0]!=NULL) && pIsConstant(r->m[0]) && (strat->ak==0))
2227  {
2228    M=idInit(1,F->rank);
2229    M->m[0]=pOne();
2230    //if (strat->ak!=0) { pSetComp(M->m[0],strat->ak); pSetmComp(M->m[0]); }
2231    if (strat->M!=NULL) idDelete(&strat->M);
2232  }
2233  else if (strat->M==NULL)
2234  {
2235    M=idInit(1,F->rank);
2236    Warn("no minimal generating set computed");
2237  }
2238  else
2239  {
2240    idSkipZeroes(strat->M);
2241    M=strat->M;
2242  }
2243  delete(strat);
2244  if (reduced>2)
2245  {
2246    Kstd1_deg=Kstd1_OldDeg;
2247    if (!oldDegBound)
2248      test &= ~Sy_bit(OPT_DEGBOUND);
2249  }
2250  else
2251  {
2252    if (IDELEMS(M)>IDELEMS(r)) { idDelete(&M); M=idCopy(r); }
2253  }
2254  return r;
2255}
2256
2257poly kNF(ideal F, ideal Q, poly p,int syzComp, int lazyReduce)
2258{
2259  if (p==NULL)
2260     return NULL;
2261
2262  poly pp = p;
2263
2264#ifdef HAVE_PLURAL
2265  if(rIsSCA(currRing))
2266  {
2267    const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
2268    const unsigned int m_iLastAltVar  = scaLastAltVar(currRing);
2269    pp = p_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing);
2270
2271    if(Q == currQuotient)
2272      Q = SCAQuotient(currRing);
2273  }
2274#endif
2275
2276  if ((idIs0(F))&&(Q==NULL))
2277  {
2278#ifdef HAVE_PLURAL
2279    if(p != pp)
2280      return pp;
2281#endif
2282    return pCopy(p); /*F+Q=0*/
2283  }
2284
2285  kStrategy strat=new skStrategy;
2286  strat->syzComp = syzComp;
2287  strat->ak = si_max(id_RankFreeModule(F,currRing),pMaxComp(p));
2288  poly res;
2289
2290  if (currRing->OrdSgn==-1)
2291    res=kNF1(F,Q,pp,strat,lazyReduce);
2292  else
2293    res=kNF2(F,Q,pp,strat,lazyReduce);
2294  delete(strat);
2295
2296#ifdef HAVE_PLURAL
2297  if(pp != p)
2298    p_Delete(&pp, currRing);
2299#endif
2300  return res;
2301}
2302
2303ideal kNF(ideal F, ideal Q, ideal p,int syzComp,int lazyReduce)
2304{
2305  ideal res;
2306  if (TEST_OPT_PROT)
2307  {
2308    Print("(S:%d)",IDELEMS(p));mflush();
2309  }
2310  if (idIs0(p))
2311    return idInit(IDELEMS(p),si_max(p->rank,F->rank));
2312
2313  ideal pp = p;
2314#ifdef HAVE_PLURAL
2315  if(rIsSCA(currRing))
2316  {
2317    const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
2318    const unsigned int m_iLastAltVar  = scaLastAltVar(currRing);
2319    pp = id_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing, false);
2320
2321    if(Q == currQuotient)
2322      Q = SCAQuotient(currRing);
2323  }
2324#endif
2325
2326  if ((idIs0(F))&&(Q==NULL))
2327  {
2328#ifdef HAVE_PLURAL
2329    if(p != pp)
2330      return pp;
2331#endif
2332    return idCopy(p); /*F+Q=0*/
2333  }
2334
2335  kStrategy strat=new skStrategy;
2336  strat->syzComp = syzComp;
2337  strat->ak = si_max(id_RankFreeModule(F,currRing),id_RankFreeModule(p,currRing));
2338  if (strat->ak>0) // only for module case, see Tst/Short/bug_reduce.tst
2339  {
2340    strat->ak = si_max(strat->ak,(int)F->rank);
2341  }
2342
2343  if (currRing->OrdSgn==-1)
2344    res=kNF1(F,Q,pp,strat,lazyReduce);
2345  else
2346    res=kNF2(F,Q,pp,strat,lazyReduce);
2347  delete(strat);
2348
2349#ifdef HAVE_PLURAL
2350  if(pp != p)
2351    id_Delete(&pp, currRing);
2352#endif
2353
2354  return res;
2355}
2356
2357poly kNF (ideal F, ideal Q, poly p,int syzComp, int lazyReduce, const ring _currRing)
2358{
2359  const ring save = currRing; if( currRing != _currRing ) rChangeCurrRing(_currRing);
2360  poly ret = kNF(F, Q, p, syzComp, lazyReduce);
2361  if( currRing != save )     rChangeCurrRing(save);
2362  return ret;
2363}
2364
2365/*2
2366*interreduces F
2367*/
2368// old version
2369ideal kInterRedOld (ideal F, ideal Q)
2370{
2371  int j;
2372  kStrategy strat = new skStrategy;
2373
2374  ideal tempF = F;
2375  ideal tempQ = Q;
2376
2377#ifdef HAVE_PLURAL
2378  if(rIsSCA(currRing))
2379  {
2380    const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
2381    const unsigned int m_iLastAltVar  = scaLastAltVar(currRing);
2382    tempF = id_KillSquares(F, m_iFirstAltVar, m_iLastAltVar, currRing);
2383
2384    // this should be done on the upper level!!! :
2385    //    tempQ = SCAQuotient(currRing);
2386
2387    if(Q == currQuotient)
2388      tempQ = SCAQuotient(currRing);
2389  }
2390#endif
2391
2392//  if (TEST_OPT_PROT)
2393//  {
2394//    writeTime("start InterRed:");
2395//    mflush();
2396//  }
2397  //strat->syzComp     = 0;
2398  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
2399  strat->kNoether=pCopy((currRing->ppNoether));
2400  strat->ak = id_RankFreeModule(tempF,currRing);
2401  initBuchMoraCrit(strat);
2402  strat->NotUsedAxis = (BOOLEAN *)omAlloc(((currRing->N)+1)*sizeof(BOOLEAN));
2403  for (j=(currRing->N); j>0; j--) strat->NotUsedAxis[j] = TRUE;
2404  strat->enterS      = enterSBba;
2405  strat->posInT      = posInT17;
2406  strat->initEcart   = initEcartNormal;
2407  strat->sl   = -1;
2408  strat->tl          = -1;
2409  strat->tmax        = setmaxT;
2410  strat->T           = initT();
2411  strat->R           = initR();
2412  strat->sevT        = initsevT();
2413  if (currRing->OrdSgn == -1)   strat->honey = TRUE;
2414  initS(tempF, tempQ, strat);
2415  if (TEST_OPT_REDSB)
2416    strat->noTailReduction=FALSE;
2417  updateS(TRUE,strat);
2418  if (TEST_OPT_REDSB && TEST_OPT_INTSTRATEGY)
2419    completeReduce(strat);
2420  //else if (TEST_OPT_PROT) PrintLn();
2421  pDelete(&strat->kHEdge);
2422  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
2423  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
2424  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
2425  omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN));
2426  omfree(strat->sevT);
2427  omfree(strat->S_2_R);
2428  omfree(strat->R);
2429
2430  if (strat->fromQ)
2431  {
2432    for (j=IDELEMS(strat->Shdl)-1;j>=0;j--)
2433    {
2434      if(strat->fromQ[j]) pDelete(&strat->Shdl->m[j]);
2435    }
2436    omFreeSize((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
2437  }
2438//  if (TEST_OPT_PROT)
2439//  {
2440//    writeTime("end Interred:");
2441//    mflush();
2442//  }
2443  ideal shdl=strat->Shdl;
2444  idSkipZeroes(shdl);
2445  if (strat->fromQ)
2446  {
2447    strat->fromQ=NULL;
2448    ideal res=kInterRed(shdl,NULL);
2449    idDelete(&shdl);
2450    shdl=res;
2451  }
2452  delete(strat);
2453#ifdef HAVE_PLURAL
2454  if( tempF != F )
2455    id_Delete( &tempF, currRing);
2456#endif
2457  return shdl;
2458}
2459// new version
2460ideal kInterRedBba (ideal F, ideal Q, int &need_retry)
2461{
2462  need_retry=0;
2463  int   red_result = 1;
2464  int   olddeg,reduc;
2465  BOOLEAN withT = FALSE;
2466  BOOLEAN toReset=FALSE;
2467  kStrategy strat=new skStrategy;
2468  tHomog h;
2469  intvec * w=NULL;
2470
2471  if (rField_has_simple_inverse(currRing))
2472    strat->LazyPass=20;
2473  else
2474    strat->LazyPass=2;
2475  strat->LazyDegree = 1;
2476  strat->ak = id_RankFreeModule(F,currRing);
2477  strat->syzComp = strat->ak;
2478  strat->kModW=kModW=NULL;
2479  strat->kHomW=kHomW=NULL;
2480  if (strat->ak == 0)
2481  {
2482    h = (tHomog)idHomIdeal(F,Q);
2483    w=NULL;
2484  }
2485  else if (!TEST_OPT_DEGBOUND)
2486  {
2487    h = (tHomog)idHomModule(F,Q,&w);
2488  }
2489  if (h==isHomog)
2490  {
2491    if (strat->ak > 0 && (w!=NULL) && (w!=NULL))
2492    {
2493      strat->kModW = kModW = w;
2494      strat->pOrigFDeg = currRing->pFDeg;
2495      strat->pOrigLDeg = currRing->pLDeg;
2496      pSetDegProcs(currRing,kModDeg);
2497      toReset = TRUE;
2498    }
2499    strat->LazyPass*=2;
2500  }
2501  strat->homog=h;
2502#ifdef KDEBUG
2503  idTest(F);
2504#endif
2505
2506  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
2507  initBuchMoraPos(strat);
2508  initBba(F,strat);
2509  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
2510  strat->posInL=posInL0; /* ord according pComp */
2511
2512  /*Shdl=*/initBuchMora(F, Q, strat);
2513  reduc = olddeg = 0;
2514
2515#ifndef NO_BUCKETS
2516  if (!TEST_OPT_NOT_BUCKETS)
2517    strat->use_buckets = 1;
2518#endif
2519
2520  // redtailBBa against T for inhomogenous input
2521  if (!TEST_OPT_OLDSTD)
2522    withT = ! strat->homog;
2523
2524  // strat->posInT = posInT_pLength;
2525  kTest_TS(strat);
2526
2527#ifdef HAVE_TAIL_RING
2528  kStratInitChangeTailRing(strat);
2529#endif
2530
2531  /* compute------------------------------------------------------- */
2532  while (strat->Ll >= 0)
2533  {
2534    #ifdef KDEBUG
2535      if (TEST_OPT_DEBUG) messageSets(strat);
2536    #endif
2537    if (strat->Ll== 0) strat->interpt=TRUE;
2538    /* picks the last element from the lazyset L */
2539    strat->P = strat->L[strat->Ll];
2540    strat->Ll--;
2541
2542    if (strat->P.p1 == NULL)
2543    {
2544      // for input polys, prepare reduction
2545      strat->P.PrepareRed(strat->use_buckets);
2546    }
2547
2548    if (strat->P.p == NULL && strat->P.t_p == NULL)
2549    {
2550      red_result = 0;
2551    }
2552    else
2553    {
2554      if (TEST_OPT_PROT)
2555        message(strat->P.pFDeg(),
2556                &olddeg,&reduc,strat, red_result);
2557
2558      /* reduction of the element choosen from L */
2559      red_result = strat->red(&strat->P,strat);
2560    }
2561
2562    // reduction to non-zero new poly
2563    if (red_result == 1)
2564    {
2565      /* statistic */
2566      if (TEST_OPT_PROT) PrintS("s");
2567
2568      // get the polynomial (canonicalize bucket, make sure P.p is set)
2569      strat->P.GetP(strat->lmBin);
2570
2571      int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
2572
2573      // reduce the tail and normalize poly
2574      // in the ring case we cannot expect LC(f) = 1,
2575      // therefore we call pContent instead of pNorm
2576      if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing)))
2577      {
2578        strat->P.pCleardenom();
2579        if (0)
2580        //if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2581        {
2582          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
2583          strat->P.pCleardenom();
2584        }
2585      }
2586      else
2587      {
2588        strat->P.pNorm();
2589        if (0)
2590        //if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2591          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
2592      }
2593
2594#ifdef KDEBUG
2595      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
2596#endif
2597
2598      // enter into S, L, and T
2599      //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
2600        enterT(strat->P, strat);
2601      // posInS only depends on the leading term
2602      strat->enterS(strat->P, pos, strat, strat->tl);
2603
2604      if (strat->P.lcm!=NULL)
2605#ifdef HAVE_RINGS
2606        pLmDelete(strat->P.lcm);
2607#else
2608        pLmFree(strat->P.lcm);
2609#endif
2610      if (pos<strat->sl)
2611      {
2612        need_retry++;
2613        // move all "larger" elements fromS to L
2614        // remove them from T
2615        int ii=pos+1;
2616        for(;ii<=strat->sl;ii++)
2617        {
2618          LObject h;
2619          memset(&h,0,sizeof(h));
2620          h.tailRing=strat->tailRing;
2621          h.p=strat->S[ii]; strat->S[ii]=NULL;
2622          strat->initEcart(&h);
2623          h.sev=strat->sevS[ii];
2624          int jj=strat->tl;
2625          while (jj>=0)
2626          {
2627            if (strat->T[jj].p==h.p)
2628            {
2629              strat->T[jj].p=NULL;
2630              if (jj<strat->tl)
2631              {
2632                memmove(&(strat->T[jj]),&(strat->T[jj+1]),
2633                        (strat->tl-jj)*sizeof(strat->T[jj]));
2634                memmove(&(strat->sevT[jj]),&(strat->sevT[jj+1]),
2635                        (strat->tl-jj)*sizeof(strat->sevT[jj]));
2636              }
2637              strat->tl--;
2638              break;
2639            }
2640            jj--;
2641          }
2642          int lpos=strat->posInL(strat->L,strat->Ll,&h,strat);
2643          enterL(&strat->L,&strat->Ll,&strat->Lmax,h,lpos);
2644          #ifdef KDEBUG
2645          if (TEST_OPT_DEBUG)
2646          {
2647            Print("move S[%d] -> L[%d]: ",ii,pos);
2648            p_wrp(h.p,currRing, strat->tailRing);
2649            PrintLn();
2650          }
2651          #endif
2652        }
2653        if (strat->fromQ!=NULL)
2654        {
2655          for(ii=pos+1;ii<=strat->sl;ii++) strat->fromQ[ii]=0;
2656        }
2657        strat->sl=pos;
2658      }
2659    }
2660
2661#ifdef KDEBUG
2662    if (TEST_OPT_DEBUG)
2663    {
2664      messageSets(strat);
2665    }
2666    memset(&(strat->P), 0, sizeof(strat->P));
2667#endif
2668    //kTest_TS(strat);: i_r out of sync in kInterRedBba, but not used!
2669  }
2670#ifdef KDEBUG
2671  //if (TEST_OPT_DEBUG) messageSets(strat);
2672#endif
2673  /* complete reduction of the standard basis--------- */
2674
2675  if((need_retry<=0) && (TEST_OPT_REDSB))
2676  {
2677    completeReduce(strat);
2678#ifdef HAVE_TAIL_RING
2679    if (strat->completeReduce_retry)
2680    {
2681      // completeReduce needed larger exponents, retry
2682      // to reduce with S (instead of T)
2683      // and in currRing (instead of strat->tailRing)
2684      cleanT(strat);strat->tailRing=currRing;
2685      int i;
2686      for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
2687      completeReduce(strat);
2688    }
2689#endif
2690  }
2691  else if (TEST_OPT_PROT) PrintLn();
2692
2693  /* release temp data-------------------------------- */
2694  exitBuchMora(strat);
2695//  if (TEST_OPT_WEIGHTM)
2696//  {
2697//    pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2698//    if (ecartWeights)
2699//    {
2700//      omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
2701//      ecartWeights=NULL;
2702//    }
2703//  }
2704  //if (TEST_OPT_PROT) messageStat(0/*hilbcount*/,strat);
2705  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
2706  ideal res=strat->Shdl;
2707  strat->Shdl=NULL;
2708  delete strat;
2709  if (w!=NULL) delete w;
2710  return res;
2711}
2712ideal kInterRed (ideal F, ideal Q)
2713{
2714#ifdef HAVE_PLURAL
2715  if(rIsPluralRing(currRing)) return kInterRedOld(F,Q);
2716#endif
2717  if ((currRing->OrdSgn==-1)
2718  || (rField_is_numeric(currRing)))
2719    return kInterRedOld(F,Q);
2720
2721    //return kInterRedOld(F,Q);
2722
2723  BITSET save=test;
2724  //test|=Sy_bit(OPT_NOT_SUGAR);
2725  test|=Sy_bit(OPT_REDTHROUGH);
2726  //test&= ~Sy_bit(OPT_REDTAIL);
2727  //test&= ~Sy_bit(OPT_REDSB);
2728  //extern char * showOption() ;
2729  //Print("%s\n",showOption());
2730
2731  int need_retry;
2732  int counter=3;
2733  ideal res, res1;
2734  int elems;
2735  ideal null=NULL;
2736  if ((Q==NULL) || (!TEST_OPT_REDSB))
2737  {
2738    elems=idElem(F);
2739    res=kInterRedBba(F,Q,need_retry);
2740  }
2741  else
2742  {
2743    ideal FF=idSimpleAdd(F,Q);
2744    res=kInterRedBba(FF,NULL,need_retry);
2745    idDelete(&FF);
2746    null=idInit(1,1);
2747    res1=kNF(null,Q,res);
2748    idDelete(&res);
2749    res=res1;
2750  }
2751  while (need_retry && (counter>0))
2752  {
2753    #ifdef KDEBUG
2754    if (TEST_OPT_DEBUG) { Print("retry counter %d\n",counter); }
2755    #endif
2756    res1=kInterRedBba(res,Q,need_retry);
2757    int new_elems=idElem(res1);
2758    counter -= (new_elems >= elems);
2759    elems = new_elems;
2760    idDelete(&res);
2761    if ((Q!=NULL) && (TEST_OPT_REDSB))
2762    {
2763      res=kNF(null,Q,res1);
2764      idDelete(&res1);
2765    }
2766    else
2767      res = res1;
2768  }
2769  if (null!=NULL) idDelete(&null);
2770  test=save;
2771  idSkipZeroes(res);
2772  return res;
2773}
2774
2775// returns TRUE if mora should use buckets, false otherwise
2776static BOOLEAN kMoraUseBucket(kStrategy strat)
2777{
2778#ifdef MORA_USE_BUCKETS
2779  if (TEST_OPT_NOT_BUCKETS)
2780    return FALSE;
2781  if (strat->red == redFirst)
2782  {
2783#ifdef NO_LDEG
2784    if (strat->syzComp==0)
2785      return TRUE;
2786#else
2787    if ((strat->homog || strat->honey) && (strat->syzComp==0))
2788      return TRUE;
2789#endif
2790  }
2791  else
2792  {
2793    assume(strat->red == redEcart);
2794    if (strat->honey && (strat->syzComp==0))
2795      return TRUE;
2796  }
2797#endif
2798  return FALSE;
2799}
Note: See TracBrowser for help on using the repository browser.