source: git/kernel/GBEngine/kstd1.cc @ 2a4bc6e

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