source: git/kernel/kstd1.cc @ d30a399

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