source: git/kernel/kstd1.cc @ b51d2c

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