source: git/kernel/GBEngine/kstd1.cc @ a77bbef

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