source: git/kernel/kstd1.cc @ 16493d

spielwiese
Last change on this file since 16493d was 16493d, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: kInterRed git-svn-id: file:///usr/local/Singular/svn/trunk@10008 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 54.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kstd1.cc,v 1.18 2007-05-02 10:01:23 Singular Exp $ */
5/*
6* ABSTRACT:
7*/
8
9// define if buckets should be used
10#define MORA_USE_BUCKETS
11
12// define if tailrings should be used
13#define HAVE_TAIL_RING
14
15#include "mod2.h"
16#include "structs.h"
17#include "omalloc.h"
18#include "kutil.h"
19#include "kInline.cc"
20#include "polys.h"
21#include "febase.h"
22#include "kstd1.h"
23#include "khstd.h"
24#include "stairc.h"
25#include "weight.h"
26//#include "cntrlc.h"
27#include "intvec.h"
28#include "ideals.h"
29//#include "../Singular/ipid.h"
30#include "timer.h"
31
32//#include "ipprint.h"
33
34/* the list of all options which give a warning by test */
35BITSET kOptions=Sy_bit(OPT_PROT)           /*  0 */
36                |Sy_bit(OPT_REDSB)         /*  1 */
37                |Sy_bit(OPT_NOT_SUGAR)     /*  3 */
38                |Sy_bit(OPT_INTERRUPT)     /*  4 */
39                |Sy_bit(OPT_SUGARCRIT)     /*  5 */
40                |Sy_bit(OPT_REDTHROUGH)
41                |Sy_bit(OPT_OLDSTD)
42                |Sy_bit(OPT_FASTHC)        /* 10 */
43                |Sy_bit(OPT_KEEPVARS)      /* 21 */
44                |Sy_bit(OPT_INTSTRATEGY)   /* 26 */
45                |Sy_bit(OPT_INFREDTAIL)    /* 28 */
46                |Sy_bit(OPT_NOTREGULARITY) /* 30 */
47                |Sy_bit(OPT_WEIGHTM);      /* 31 */
48
49/* the list of all options which may be used by option and test */
50BITSET validOpts=Sy_bit(0)
51                |Sy_bit(1)
52                |Sy_bit(2) // obachman 10/00: replaced by notBucket
53                |Sy_bit(3)
54                |Sy_bit(4)
55                |Sy_bit(5)
56                |Sy_bit(6)
57//                |Sy_bit(7) obachman 11/00 tossed: 12/00 used for redThrough
58  |Sy_bit(OPT_REDTHROUGH)
59//                |Sy_bit(8) obachman 11/00 tossed
60                |Sy_bit(9)
61                |Sy_bit(10)
62                |Sy_bit(11)
63                |Sy_bit(12)
64                |Sy_bit(13)
65                |Sy_bit(14)
66                |Sy_bit(15)
67                |Sy_bit(16)
68                |Sy_bit(17)
69                |Sy_bit(18)
70                |Sy_bit(19)
71//                |Sy_bit(20) obachman 11/00 tossed: 12/00 used for redOldStd
72  |Sy_bit(OPT_OLDSTD)
73                |Sy_bit(21)
74                |Sy_bit(22)
75                /*|Sy_bit(23)*/
76                /*|Sy_bit(24)*/
77                |Sy_bit(OPT_REDTAIL)
78                |Sy_bit(OPT_INTSTRATEGY)
79                |Sy_bit(27)
80                |Sy_bit(28)
81                |Sy_bit(29)
82                |Sy_bit(30)
83                |Sy_bit(31);
84
85//static BOOLEAN posInLOldFlag;
86           /*FALSE, if posInL == posInL10*/
87// returns TRUE if mora should use buckets, false otherwise
88static BOOLEAN kMoraUseBucket(kStrategy strat);
89
90static void kOptimizeLDeg(pLDegProc ldeg, kStrategy strat)
91{
92//  if (strat->ak == 0 && !rIsSyzIndexRing(currRing))
93    strat->length_pLength = TRUE;
94//  else
95//    strat->length_pLength = FALSE;
96
97  if ((ldeg == pLDeg0c /*&& !rIsSyzIndexRing(currRing)*/) ||
98      (ldeg == pLDeg0 && strat->ak == 0))
99  {
100    strat->LDegLast = TRUE;
101  }
102  else
103  {
104    strat->LDegLast = FALSE;
105  }
106}
107
108
109static int doRed (LObject* h, TObject* with,BOOLEAN intoT,kStrategy strat)
110{
111  poly hp;
112  int ret;
113#if KDEBUG > 0
114  kTest_L(h);
115  kTest_T(with);
116#endif
117  // Hmmm ... why do we do this -- polys from T should already be normalized
118  if (!TEST_OPT_INTSTRATEGY)
119    with->pNorm();
120#ifdef KDEBUG
121  if (TEST_OPT_DEBUG)
122  {
123    PrintS("reduce ");h->wrp();PrintS(" with ");with->wrp();PrintLn();
124  }
125#endif
126  if (intoT)
127  {
128    // need to do it exacly like this: otherwise
129    // we might get errors
130    LObject L= *h;
131    L.Copy();
132    h->GetP();
133    h->SetLength(strat->length_pLength);
134    ret = ksReducePoly(&L, with, strat->kNoetherTail(), NULL, strat);
135    if (ret)
136    {
137      if (ret < 0) return ret;
138      if (h->tailRing != strat->tailRing)
139        h->ShallowCopyDelete(strat->tailRing,
140                             pGetShallowCopyDeleteProc(h->tailRing,
141                                                       strat->tailRing));
142    }
143    enterT(*h,strat);
144    *h = L;
145  }
146  else
147    ret = ksReducePoly(h, with, strat->kNoetherTail(), NULL, strat);
148#ifdef KDEBUG
149  if (TEST_OPT_DEBUG)
150  {
151    PrintS("to ");h->wrp();PrintLn();
152  }
153#endif
154  return ret;
155}
156
157int redEcart (LObject* h,kStrategy strat)
158{
159  poly pi;
160  int i,at,reddeg,d,ei,li,ii;
161  int j = 0;
162  int pass = 0;
163
164  d = h->GetpFDeg()+ h->ecart;
165  reddeg = strat->LazyDegree+d;
166  h->SetShortExpVector();
167  loop
168  {
169    j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h);
170    if (j < 0)
171    {
172      if (strat->honey) h->SetLength(strat->length_pLength);
173      return 1;
174    }
175
176    ei = strat->T[j].ecart;
177    ii = j;
178
179    if (ei > h->ecart && ii < strat->tl)
180    {
181      li = strat->T[j].length;
182      // the polynomial to reduce with (up to the moment) is;
183      // pi with ecart ei and length li
184      // look for one with smaller ecart
185      i = j;
186      loop
187      {
188        /*- takes the first possible with respect to ecart -*/
189        i++;
190#if 1
191        if (i > strat->tl) break;
192        if ((strat->T[i].ecart < ei || (strat->T[i].ecart == ei &&
193                                        strat->T[i].length < li))
194            &&
195            p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], h->GetLmTailRing(), ~h->sev, strat->tailRing))
196#else
197          j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h, i);
198        if (j < 0) break;
199        i = j;
200        if (strat->T[i].ecart < ei || (strat->T[i].ecart == ei &&
201                                        strat->T[i].length < li))
202#endif
203        {
204          // the polynomial to reduce with is now
205          ii = i;
206          ei = strat->T[i].ecart;
207          if (ei <= h->ecart) break;
208          li = strat->T[i].length;
209        }
210      }
211    }
212
213    // end of search: have to reduce with pi
214    if (ei > h->ecart)
215    {
216      // It is not possible to reduce h with smaller ecart;
217      // if possible h goes to the lazy-set L,i.e
218      // if its position in L would be not the last one
219      strat->fromT = TRUE;
220      if (!K_TEST_OPT_REDTHROUGH && strat->Ll >= 0) /*- L is not empty -*/
221      {
222        h->SetLmCurrRing();
223        if (strat->honey && strat->posInLDependsOnLength)
224          h->SetLength(strat->length_pLength);
225        assume(h->FDeg == h->pFDeg());
226        at = strat->posInL(strat->L,strat->Ll,h,strat);
227        if (at <= strat->Ll)
228        {
229          /*- h will not become the next element to reduce -*/
230          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
231#ifdef KDEBUG
232          if (TEST_OPT_DEBUG) Print(" ecart too big; -> L%d\n",at);
233#endif
234          h->Clear();
235          strat->fromT = FALSE;
236          return -1;
237        }
238      }
239    }
240
241    // now we finally can reduce
242    doRed(h,&(strat->T[ii]),strat->fromT,strat);
243    strat->fromT=FALSE;
244
245    // are we done ???
246    if (h->IsNull())
247    {
248      if (h->lcm!=NULL) pLmFree(h->lcm);
249      h->Clear();
250      return 0;
251    }
252
253    // NO!
254    h->SetShortExpVector();
255    h->SetpFDeg();
256    if (strat->honey)
257    {
258      if (ei <= h->ecart)
259        h->ecart = d-h->GetpFDeg();
260      else
261        h->ecart = d-h->GetpFDeg()+ei-h->ecart;
262    }
263    else
264      // this has the side effect of setting h->length
265      h->ecart = h->pLDeg(strat->LDegLast) - h->GetpFDeg();
266#if 0
267    if (strat->syzComp!=0)
268    {
269      if ((strat->syzComp>0) && (h->Comp() > strat->syzComp))
270      {
271        assume(h->MinComp() > strat->syzComp);
272        if (strat->honey) h->SetLength();
273#ifdef KDEBUG
274        if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
275#endif
276        return -2;
277      }
278    }
279#endif
280    /*- try to reduce the s-polynomial -*/
281    pass++;
282    d = h->GetpFDeg()+h->ecart;
283    /*
284     *test whether the polynomial should go to the lazyset L
285     *-if the degree jumps
286     *-if the number of pre-defined reductions jumps
287     */
288    if (!K_TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
289        && ((d >= reddeg) || (pass > strat->LazyPass)))
290    {
291      h->SetLmCurrRing();
292      if (strat->honey && strat->posInLDependsOnLength)
293        h->SetLength(strat->length_pLength);
294      assume(h->FDeg == h->pFDeg());
295      at = strat->posInL(strat->L,strat->Ll,h,strat);
296      if (at <= strat->Ll)
297      {
298        int dummy=strat->sl;
299        if (kFindDivisibleByInS(strat, &dummy, h) < 0)
300        {
301          if (strat->honey && !strat->posInLDependsOnLength)
302            h->SetLength(strat->length_pLength);
303          return 1;
304        }
305        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
306#ifdef KDEBUG
307        if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
308#endif
309        h->Clear();
310        return -1;
311      }
312    }
313    else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
314    {
315      Print(".%d",d);mflush();
316      reddeg = d+1;
317    }
318  }
319}
320
321/*2
322*reduces h with elements from T choosing  the first possible
323* element in t with respect to the given pDivisibleBy
324*/
325int redFirst (LObject* h,kStrategy strat)
326{
327  if (h->IsNull()) return 0;
328
329  int at, reddeg,d;
330  int pass = 0;
331  int j = 0;
332
333  if (! strat->homog)
334  {
335    d = h->GetpFDeg() + h->ecart;
336    reddeg = strat->LazyDegree+d;
337  }
338  h->SetShortExpVector();
339  loop
340  {
341    j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h);
342    if (j < 0)
343    {
344      h->SetDegStuffReturnLDeg(strat->LDegLast);
345      return 1;
346    }
347
348    if (!TEST_OPT_INTSTRATEGY)
349      strat->T[j].pNorm();
350#ifdef KDEBUG
351    if (TEST_OPT_DEBUG)
352    {
353      PrintS("reduce ");
354      h->wrp();
355      PrintS(" with ");
356      strat->T[j].wrp();
357    }
358#endif
359    ksReducePoly(h, &(strat->T[j]), strat->kNoetherTail(), NULL, strat);
360#ifdef KDEBUG
361    if (TEST_OPT_DEBUG)
362    {
363      PrintS(" to ");
364      wrp(h->p);
365      PrintLn();
366    }
367#endif
368    if (h->IsNull())
369    {
370      if (h->lcm!=NULL) pLmFree(h->lcm);
371      h->Clear();
372      return 0;
373    }
374    h->SetShortExpVector();
375
376#if 0
377    if ((strat->syzComp!=0) && !strat->honey)
378    {
379      if ((strat->syzComp>0) &&
380          (h->Comp() > strat->syzComp))
381      {
382        assume(h->MinComp() > strat->syzComp);
383#ifdef KDEBUG
384        if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
385#endif
386        if (strat->homog)
387          h->SetDegStuffReturnLDeg(strat->LDegLast);
388        return -2;
389      }
390    }
391#endif
392    if (!strat->homog)
393    {
394      if (!K_TEST_OPT_OLDSTD && strat->honey)
395      {
396        h->SetpFDeg();
397        if (strat->T[j].ecart <= h->ecart)
398          h->ecart = d - h->GetpFDeg();
399        else
400          h->ecart = d - h->GetpFDeg() + strat->T[j].ecart - h->ecart;
401
402        d = h->GetpFDeg() + h->ecart;
403      }
404      else
405        d = h->SetDegStuffReturnLDeg(strat->LDegLast);
406      /*- try to reduce the s-polynomial -*/
407      pass++;
408      /*
409       *test whether the polynomial should go to the lazyset L
410       *-if the degree jumps
411       *-if the number of pre-defined reductions jumps
412       */
413      if (!K_TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
414          && ((d >= reddeg) || (pass > strat->LazyPass)))
415      {
416        h->SetLmCurrRing();
417        if (strat->posInLDependsOnLength)
418          h->SetLength(strat->length_pLength);
419        at = strat->posInL(strat->L,strat->Ll,h,strat);
420        if (at <= strat->Ll)
421        {
422          int dummy=strat->sl;
423          if (kFindDivisibleByInS(strat,&dummy, h) < 0)
424            return 1;
425          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
426#ifdef KDEBUG
427          if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
428#endif
429          h->Clear();
430          return -1;
431        }
432      }
433      if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
434      {
435        reddeg = d+1;
436        Print(".%d",d);mflush();
437      }
438    }
439  }
440}
441
442/*2
443* reduces h with elements from T choosing first possible
444* element in T with respect to the given ecart
445* used for computing normal forms outside kStd
446*/
447static poly redMoraNF (poly h,kStrategy strat, int flag)
448{
449  LObject H;
450  H.p = h;
451  int j = 0;
452  int z = 10;
453  int o = H.SetpFDeg();
454  H.ecart = pLDeg(H.p,&H.length,currRing)-o;
455  if ((flag & 2) == 0) cancelunit(&H);
456  H.sev = pGetShortExpVector(H.p);
457  unsigned long not_sev = ~ H.sev;
458  loop
459  {
460    if (j > strat->tl)
461    {
462      return H.p;
463    }
464    if (TEST_V_DEG_STOP)
465    {
466      if (kModDeg(H.p)>Kstd1_deg) pDeleteLm(&H.p);
467      if (H.p==NULL) return NULL;
468    }
469    if (p_LmShortDivisibleBy(strat->T[j].GetLmTailRing(), strat->sevT[j], H.GetLmTailRing(), not_sev, strat->tailRing))
470    {
471      //if (strat->interpt) test_int_std(strat->kIdeal);
472      /*- remember the found T-poly -*/
473      poly pi = strat->T[j].p;
474      int ei = strat->T[j].ecart;
475      int li = strat->T[j].length;
476      int ii = j;
477      /*
478      * the polynomial to reduce with (up to the moment) is;
479      * pi with ecart ei and length li
480      */
481      loop
482      {
483        /*- look for a better one with respect to ecart -*/
484        /*- stop, if the ecart is small enough (<=ecart(H)) -*/
485        j++;
486        if (j > strat->tl) break;
487        if (ei <= H.ecart) break;
488        if (((strat->T[j].ecart < ei)
489          || ((strat->T[j].ecart == ei)
490        && (strat->T[j].length < li)))
491        && pLmShortDivisibleBy(strat->T[j].p,strat->sevT[j], H.p, not_sev))
492        {
493          /*
494          * the polynomial to reduce with is now;
495          */
496          pi = strat->T[j].p;
497          ei = strat->T[j].ecart;
498          li = strat->T[j].length;
499          ii = j;
500        }
501      }
502      /*
503      * end of search: have to reduce with pi
504      */
505      z++;
506      if (z>10)
507      {
508        pNormalize(H.p);
509        z=0;
510      }
511      if ((ei > H.ecart) && (!strat->kHEdgeFound))
512      {
513        /*
514        * It is not possible to reduce h with smaller ecart;
515        * we have to reduce with bad ecart: H has to enter in T
516        */
517        doRed(&H,&(strat->T[ii]),TRUE,strat);
518        if (H.p == NULL)
519          return NULL;
520      }
521      else
522      {
523        /*
524        * we reduce with good ecart, h need not to be put to T
525        */
526        doRed(&H,&(strat->T[ii]),FALSE,strat);
527        if (H.p == NULL)
528          return NULL;
529      }
530      /*- try to reduce the s-polynomial -*/
531      o = H.SetpFDeg();
532      if ((flag &2 ) == 0) cancelunit(&H);
533      H.ecart = pLDeg(H.p,&(H.length),currRing)-o;
534      j = 0;
535      H.sev = pGetShortExpVector(H.p);
536      not_sev = ~ H.sev;
537    }
538    else
539    {
540      j++;
541    }
542  }
543}
544
545/*2
546*reorders  L with respect to posInL
547*/
548void reorderL(kStrategy strat)
549{
550  int i,j,at;
551  LObject p;
552
553  for (i=1; i<=strat->Ll; i++)
554  {
555    at = strat->posInL(strat->L,i-1,&(strat->L[i]),strat);
556    if (at != i)
557    {
558      p = strat->L[i];
559      for (j=i-1; j>=at; j--) strat->L[j+1] = strat->L[j];
560      strat->L[at] = p;
561    }
562  }
563}
564
565/*2
566*reorders  T with respect to length
567*/
568void reorderT(kStrategy strat)
569{
570  int i,j,at;
571  TObject p;
572  unsigned long sev;
573
574
575  for (i=1; i<=strat->tl; i++)
576  {
577    if (strat->T[i-1].length > strat->T[i].length)
578    {
579      p = strat->T[i];
580      sev = strat->sevT[i];
581      at = i-1;
582      loop
583      {
584        at--;
585        if (at < 0) break;
586        if (strat->T[i].length > strat->T[at].length) break;
587      }
588      for (j = i-1; j>at; j--)
589      {
590        strat->T[j+1]=strat->T[j];
591        strat->sevT[j+1]=strat->sevT[j];
592        strat->R[strat->T[j+1].i_r] = &(strat->T[j+1]);
593      }
594      strat->T[at+1]=p;
595      strat->sevT[at+1] = sev;
596      strat->R[p.i_r] = &(strat->T[at+1]);
597    }
598  }
599}
600
601/*2
602*looks whether exactly pVariables-1 axis are used
603*returns last != 0 in this case
604*last is the (first) unused axis
605*/
606void missingAxis (int* last,kStrategy strat)
607{
608  int   i = 0;
609  int   k = 0;
610
611  *last = 0;
612  if (!currRing->MixedOrder)
613  {
614    loop
615    {
616      i++;
617      if (i > pVariables) break;
618      if (strat->NotUsedAxis[i])
619      {
620        *last = i;
621        k++;
622      }
623      if (k>1)
624      {
625        *last = 0;
626        break;
627      }
628    }
629  }
630}
631
632/*2
633*last is the only non used axis, it looks
634*for a monomial in p being a pure power of this
635*variable and returns TRUE in this case
636*(*length) gives the length between the pure power and the leading term
637*(should be minimal)
638*/
639BOOLEAN hasPurePower (const poly p,int last, int *length,kStrategy strat)
640{
641  poly h;
642  int i;
643
644  if (pNext(p) == strat->tail)
645    return FALSE;
646  pp_Test(p, currRing, strat->tailRing);
647  if (strat->ak <= 0 || p_MinComp(p, currRing, strat->tailRing) == strat->ak)
648  {
649    i = p_IsPurePower(p, currRing);
650    if (i == last)
651    {
652      *length = 0;
653      return TRUE;
654    }
655    *length = 1;
656    h = pNext(p);
657    while (h != NULL)
658    {
659      i = p_IsPurePower(h, strat->tailRing);
660      if (i==last) return TRUE;
661      (*length)++;
662      pIter(h);
663    }
664  }
665  return FALSE;
666}
667
668BOOLEAN hasPurePower (LObject *L,int last, int *length,kStrategy strat)
669{
670  if (L->bucket != NULL)
671  {
672    poly p = L->CanonicalizeP();
673    BOOLEAN ret = hasPurePower(p, last, length, strat);
674    pNext(p) = NULL;
675    return ret;
676  }
677  else
678  {
679    return hasPurePower(L->p, last, length, strat);
680  }
681}
682
683/*2
684* looks up the position of polynomial p in L
685* in the case of looking for the pure powers
686*/
687int posInL10 (const LSet set,const int length, LObject* p,const kStrategy strat)
688{
689  int j,dp,dL;
690
691  if (length<0) return 0;
692  if (hasPurePower(p,strat->lastAxis,&dp,strat))
693  {
694    int op= p->GetpFDeg() +p->ecart;
695    for (j=length; j>=0; j--)
696    {
697      if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat))
698        return j+1;
699      if (dp < dL)
700        return j+1;
701      if ((dp == dL)
702          && (set[j].GetpFDeg()+set[j].ecart >= op))
703        return j+1;
704    }
705  }
706  j=length;
707  loop
708  {
709    if (j<0) break;
710    if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat)) break;
711    j--;
712  }
713  return strat->posInLOld(set,j,p,strat);
714}
715
716
717/*2
718* computes the s-polynomials L[ ].p in L
719*/
720void updateL(kStrategy strat)
721{
722  LObject p;
723  int dL;
724  int j=strat->Ll;
725  loop
726  {
727    if (j<0) break;
728    if (hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat))
729    {
730      p=strat->L[strat->Ll];
731      strat->L[strat->Ll]=strat->L[j];
732      strat->L[j]=p;
733      break;
734    }
735    j--;
736  }
737  if (j<0)
738  {
739    j=strat->Ll;
740    loop
741    {
742      if (j<0) break;
743      if (pNext(strat->L[j].p) == strat->tail)
744      {
745        pLmFree(strat->L[j].p);    /*deletes the short spoly and computes*/
746        strat->L[j].p = NULL;
747        poly m1 = NULL, m2 = NULL;
748        // check that spoly creation is ok
749        while (strat->tailRing != currRing &&
750               !kCheckSpolyCreation(&(strat->L[j]), strat, m1, m2))
751        {
752          assume(m1 == NULL && m2 == NULL);
753          // if not, change to a ring where exponents are at least
754          // large enough
755          kStratChangeTailRing(strat);
756        }
757        /* create the real one */
758        ksCreateSpoly(&(strat->L[j]), strat->kNoetherTail(), FALSE,
759                      strat->tailRing, m1, m2, strat->R);
760
761        strat->L[j].SetLmCurrRing();
762        if (!strat->honey)
763          strat->initEcart(&strat->L[j]);
764        else
765          strat->L[j].SetLength(strat->length_pLength);
766
767        BOOLEAN pp = hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat);
768
769        if (strat->use_buckets) strat->L[j].PrepareRed(TRUE);
770
771        if (pp)
772        {
773          p=strat->L[strat->Ll];
774          strat->L[strat->Ll]=strat->L[j];
775          strat->L[j]=p;
776          break;
777        }
778      }
779      j--;
780    }
781  }
782}
783
784/*2
785* computes the s-polynomials L[ ].p in L and
786* cuts elements in L above noether
787*/
788void updateLHC(kStrategy strat)
789{
790  int i = 0;
791  kTest_TS(strat);
792  while (i <= strat->Ll)
793  {
794    if (pNext(strat->L[i].p) == strat->tail)
795    {
796       /*- deletes the int spoly and computes -*/
797      if (pLmCmp(strat->L[i].p,strat->kNoether) == -1)
798      {
799        pLmFree(strat->L[i].p);
800        strat->L[i].p = NULL;
801      }
802      else
803      {
804        pLmFree(strat->L[i].p);
805        strat->L[i].p = NULL;
806        poly m1 = NULL, m2 = NULL;
807        // check that spoly creation is ok
808        while (strat->tailRing != currRing &&
809               !kCheckSpolyCreation(&(strat->L[i]), strat, m1, m2))
810        {
811          assume(m1 == NULL && m2 == NULL);
812          // if not, change to a ring where exponents are at least
813          // large enough
814          kStratChangeTailRing(strat);
815        }
816        /* create the real one */
817        ksCreateSpoly(&(strat->L[i]), strat->kNoetherTail(), FALSE,
818                      strat->tailRing, m1, m2, strat->R);
819        if (! strat->L[i].IsNull())
820        {
821          strat->L[i].SetLmCurrRing();
822          strat->L[i].SetpFDeg();
823          strat->L[i].ecart
824            = strat->L[i].pLDeg(strat->LDegLast) - strat->L[i].GetpFDeg();
825          if (strat->use_buckets) strat->L[i].PrepareRed(TRUE);
826        }
827      }
828    }
829    else
830      deleteHC(&(strat->L[i]), strat);
831   if (strat->L[i].IsNull())
832      deleteInL(strat->L,&strat->Ll,i,strat);
833    else
834    {
835#ifdef KDEBUG
836      kTest_L(&(strat->L[i]), strat->tailRing, TRUE, i, strat->T, strat->tl);
837#endif
838      i++;
839    }
840  }
841  kTest_TS(strat);
842}
843
844/*2
845* cuts in T above strat->kNoether and tries to cancel a unit
846*/
847void updateT(kStrategy strat)
848{
849  int i = 0;
850  LObject p;
851
852  while (i <= strat->tl)
853  {
854    p = strat->T[i];
855    deleteHC(&p,strat, TRUE);
856    /*- tries to cancel a unit: -*/
857    cancelunit(&p);
858    if (p.p != strat->T[i].p)
859    {
860      strat->sevT[i] = pGetShortExpVector(p.p);
861      p.SetpFDeg();
862    }
863    strat->T[i] = p;
864    i++;
865  }
866}
867
868/*2
869* arranges red, pos and T if strat->kHEdgeFound (first time)
870*/
871void firstUpdate(kStrategy strat)
872{
873  if (strat->update)
874  {
875    kTest_TS(strat);
876    strat->update = (strat->tl == -1);
877    if (TEST_OPT_WEIGHTM)
878    {
879      pRestoreDegProcs(pFDegOld, pLDegOld);
880      if (strat->tailRing != currRing)
881      {
882        strat->tailRing->pFDeg = strat->pOrigFDeg_TailRing;
883        strat->tailRing->pLDeg = strat->pOrigLDeg_TailRing;
884      }
885      int i;
886      for (i=strat->Ll; i>=0; i--)
887      {
888        strat->L[i].SetpFDeg();
889      }
890      for (i=strat->tl; i>=0; i--)
891      {
892        strat->T[i].SetpFDeg();
893      }
894      if (ecartWeights)
895      {
896        omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
897        ecartWeights=NULL;
898      }
899    }
900    if (TEST_OPT_FASTHC)
901    {
902      strat->posInL = strat->posInLOld;
903      strat->lastAxis = 0;
904    }
905    if (BTEST1(27))
906      return;
907    strat->red = redFirst;
908    strat->use_buckets = kMoraUseBucket(strat);
909    updateT(strat);
910    strat->posInT = posInT2;
911    reorderT(strat);
912  }
913  kTest_TS(strat);
914}
915
916/*2
917*-puts p to the standardbasis s at position at
918*-reduces the tail of p if TEST_OPT_REDTAIL
919*-tries to cancel a unit
920*-HEckeTest
921*  if TRUE
922*  - decides about reduction-strategies
923*  - computes noether
924*  - stops computation if BTEST1(27)
925*  - cuts the tails of the polynomials
926*    in s,t and the elements in L above noether
927*    and cancels units if possible
928*  - reorders s,L
929*/
930void enterSMora (LObject p,int atS,kStrategy strat, int atR = -1)
931{
932  int i;
933  enterSBba(p, atS, strat, atR);
934  if (TEST_OPT_DEBUG)
935  {
936    Print("new s%d:",atS);
937    wrp(p.p);
938    PrintLn();
939  }
940  if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat);
941  if (strat->kHEdgeFound)
942  {
943    if (newHEdge(strat->S,strat))
944    {
945      firstUpdate(strat);
946      if (BTEST1(27))
947        return;
948      /*- cuts elements in L above noether and reorders L -*/
949      updateLHC(strat);
950      /*- reorders L with respect to posInL -*/
951      reorderL(strat);
952    }
953  }
954  else if (strat->kNoether!=NULL)
955    strat->kHEdgeFound = TRUE;
956  else if (TEST_OPT_FASTHC)
957  {
958    if (strat->posInLOldFlag)
959    {
960      missingAxis(&strat->lastAxis,strat);
961      if (strat->lastAxis)
962      {
963        strat->posInLOld = strat->posInL;
964        strat->posInLOldFlag = FALSE;
965        strat->posInL = posInL10;
966        strat->posInLDependsOnLength = TRUE;
967        updateL(strat);
968        reorderL(strat);
969      }
970    }
971    else if (strat->lastAxis)
972      updateL(strat);
973  }
974}
975
976/*2
977*-puts p to the standardbasis s at position at
978*-HEckeTest
979*  if TRUE
980*  - computes noether
981*/
982void enterSMoraNF (LObject p, int atS,kStrategy strat, int atR = -1)
983{
984  int i;
985
986  enterSBba(p, atS, strat, atR);
987  if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat);
988  if (strat->kHEdgeFound)
989    newHEdge(strat->S,strat);
990  else if (strat->kNoether!=NULL)
991    strat->kHEdgeFound = TRUE;
992}
993
994void initBba(ideal F,kStrategy strat)
995{
996  int i;
997  idhdl h;
998 /* setting global variables ------------------- */
999  strat->enterS = enterSBba;
1000    strat->red = redHoney;
1001  if (strat->honey)
1002    strat->red = redHoney;
1003  else if (pLexOrder && !strat->homog)
1004    strat->red = redLazy;
1005  else
1006  {
1007    strat->LazyPass *=4;
1008    strat->red = redHomog;
1009  }
1010#ifdef HAVE_RING2TOM
1011  if (currRing->cring == 1) {
1012    strat->red = redRing2toM;
1013  }
1014#endif
1015  if (pLexOrder && strat->honey)
1016    strat->initEcart = initEcartNormal;
1017  else
1018    strat->initEcart = initEcartBBA;
1019  if (strat->honey)
1020    strat->initEcartPair = initEcartPairMora;
1021  else
1022    strat->initEcartPair = initEcartPairBba;
1023  strat->kIdeal = NULL;
1024  //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD;
1025  //else              strat->kIdeal->rtyp=MODUL_CMD;
1026  //strat->kIdeal->data=(void *)strat->Shdl;
1027  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1028  {
1029    //interred  machen   Aenderung
1030    pFDegOld=pFDeg;
1031    pLDegOld=pLDeg;
1032    //h=ggetid("ecart");
1033    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
1034    //{
1035    //  ecartWeights=iv2array(IDINTVEC(h));
1036    //}
1037    //else
1038    {
1039      ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short));
1040      /*uses automatic computation of the ecartWeights to set them*/
1041      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1042    }
1043    pRestoreDegProcs(totaldegreeWecart, maxdegreeWecart);
1044    if (TEST_OPT_PROT)
1045    {
1046      for(i=1; i<=pVariables; i++)
1047        Print(" %d",ecartWeights[i]);
1048      PrintLn();
1049      mflush();
1050    }
1051  }
1052}
1053
1054void initMora(ideal F,kStrategy strat)
1055{
1056  int i,j;
1057  idhdl h;
1058
1059  strat->NotUsedAxis = (BOOLEAN *)omAlloc((pVariables+1)*sizeof(BOOLEAN));
1060  for (j=pVariables; j>0; j--) strat->NotUsedAxis[j] = TRUE;
1061  strat->enterS = enterSMora;
1062  strat->initEcartPair = initEcartPairMora; /*- ecart approximation -*/
1063  strat->posInLOld = strat->posInL;
1064  strat->posInLOldFlag = TRUE;
1065  strat->initEcart = initEcartNormal;
1066  strat->kHEdgeFound = ppNoether != NULL;
1067  if ( strat->kHEdgeFound )
1068     strat->kNoether = pCopy(ppNoether);
1069  else if (strat->kHEdgeFound || strat->homog)
1070    strat->red = redFirst;  /*take the first possible in T*/
1071  else
1072    strat->red = redEcart;/*take the first possible in under ecart-restriction*/
1073  if (strat->kHEdgeFound)
1074  {
1075    strat->HCord = pFDeg(ppNoether,currRing)+1;
1076    strat->posInT = posInT2;
1077  }
1078  else
1079  {
1080    strat->HCord = 32000;/*- very large -*/
1081  }
1082  /*reads the ecartWeights used for Graebes method from the
1083   *intvec ecart and set ecartWeights
1084   */
1085  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1086  {
1087    //interred  machen   Aenderung
1088    pFDegOld=pFDeg;
1089    pLDegOld=pLDeg;
1090    //h=ggetid("ecart");
1091    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
1092    //{
1093    //  ecartWeights=iv2array(IDINTVEC(h));
1094    //}
1095    //else
1096    {
1097      ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short));
1098      /*uses automatic computation of the ecartWeights to set them*/
1099      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1100    }
1101
1102    pSetDegProcs(totaldegreeWecart, maxdegreeWecart);
1103    if (TEST_OPT_PROT)
1104    {
1105      for(i=1; i<=pVariables; i++)
1106        Print(" %d",ecartWeights[i]);
1107      PrintLn();
1108      mflush();
1109    }
1110  }
1111  kOptimizeLDeg(pLDeg, strat);
1112}
1113
1114#ifdef HAVE_ASSUME
1115static int mora_count = 0;
1116static int mora_loop_count;
1117#endif
1118
1119ideal mora (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
1120{
1121#ifdef HAVE_ASSUME
1122  mora_count++;
1123  mora_loop_count = 0;
1124#endif
1125#ifdef KDEBUG
1126  om_Opts.MinTrack = 5;
1127#endif
1128  int srmax;
1129  int lrmax = 0;
1130  int olddeg = 0;
1131  int reduc = 0;
1132  int red_result = 1;
1133  int hilbeledeg=1,hilbcount=0;
1134
1135  strat->update = TRUE;
1136  /*- setting global variables ------------------- -*/
1137  initBuchMoraCrit(strat);
1138  initHilbCrit(F,Q,&hilb,strat);
1139  initMora(F,strat);
1140  initBuchMoraPos(strat);
1141  /*Shdl=*/initBuchMora(F,Q,strat);
1142  if (TEST_OPT_FASTHC) missingAxis(&strat->lastAxis,strat);
1143  /*updateS in initBuchMora has Hecketest
1144  * and could have put strat->kHEdgdeFound FALSE*/
1145  if (ppNoether!=NULL)
1146  {
1147    strat->kHEdgeFound = TRUE;
1148  }
1149  if (strat->kHEdgeFound && strat->update)
1150  {
1151    firstUpdate(strat);
1152    updateLHC(strat);
1153    reorderL(strat);
1154  }
1155  if (TEST_OPT_FASTHC && (strat->lastAxis) && strat->posInLOldFlag)
1156  {
1157    strat->posInLOld = strat->posInL;
1158    strat->posInLOldFlag = FALSE;
1159    strat->posInL = posInL10;
1160    updateL(strat);
1161    reorderL(strat);
1162  }
1163  srmax = strat->sl;
1164  kTest_TS(strat);
1165  strat->use_buckets = kMoraUseBucket(strat);
1166  /*- compute-------------------------------------------*/
1167
1168#ifdef HAVE_TAIL_RING
1169//  if (strat->homog && strat->red == redFirst)
1170    kStratInitChangeTailRing(strat);
1171#endif
1172
1173  while (strat->Ll >= 0)
1174  {
1175#ifdef HAVE_ASSUME
1176    mora_loop_count++;
1177#endif
1178    if (lrmax< strat->Ll) lrmax=strat->Ll; /*stat*/
1179    //test_int_std(strat->kIdeal);
1180    if (TEST_OPT_DEBUG) messageSets(strat);
1181    if (TEST_OPT_DEGBOUND
1182    && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg))
1183    {
1184      /*
1185      * stops computation if
1186      * - 24 (degBound)
1187      *   && upper degree is bigger than Kstd1_deg
1188      */
1189      while ((strat->Ll >= 0)
1190        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
1191        && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg)
1192      )
1193      {
1194        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1195        //if (TEST_OPT_PROT)
1196        //{
1197        //   PrintS("D"); mflush();
1198        //}
1199      }
1200      if (strat->Ll<0) break;
1201      else strat->noClearS=TRUE;
1202    }
1203    strat->P = strat->L[strat->Ll];/*- picks the last element from the lazyset L -*/
1204    if (strat->Ll==0) strat->interpt=TRUE;
1205    strat->Ll--;
1206
1207    // create the real Spoly
1208    if (pNext(strat->P.p) == strat->tail)
1209    {
1210      /*- deletes the short spoly and computes -*/
1211      pLmFree(strat->P.p);
1212      strat->P.p = NULL;
1213      poly m1 = NULL, m2 = NULL;
1214      // check that spoly creation is ok
1215      while (strat->tailRing != currRing &&
1216             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
1217      {
1218        assume(m1 == NULL && m2 == NULL);
1219        // if not, change to a ring where exponents are large enough
1220        kStratChangeTailRing(strat);
1221      }
1222      /* create the real one */
1223      ksCreateSpoly(&(strat->P), strat->kNoetherTail(), strat->use_buckets,
1224                    strat->tailRing, m1, m2, strat->R);
1225      if (!strat->use_buckets)
1226        strat->P.SetLength(strat->length_pLength);
1227    }
1228    else if (strat->P.p1 == NULL)
1229    {
1230      // for input polys, prepare reduction (buckets !)
1231      strat->P.SetLength(strat->length_pLength);
1232      strat->P.PrepareRed(strat->use_buckets);
1233    }
1234
1235    if (!strat->P.IsNull())
1236    {
1237      // might be NULL from noether !!!
1238      if (TEST_OPT_PROT)
1239        message(strat->P.ecart+strat->P.GetpFDeg(),&olddeg,&reduc,strat, red_result);
1240      // reduce
1241      red_result = strat->red(&strat->P,strat);
1242    }
1243
1244    if (! strat->P.IsNull())
1245    {
1246      strat->P.GetP();
1247      // statistics
1248      if (TEST_OPT_PROT) PrintS("s");
1249      // normalization
1250      if (!TEST_OPT_INTSTRATEGY)
1251        strat->P.pNorm();
1252      // tailreduction
1253      strat->P.p = redtail(&(strat->P),strat->sl,strat);
1254      // set ecart -- might have changed because of tail reductions
1255      if ((!strat->noTailReduction) && (!strat->honey))
1256        strat->initEcart(&strat->P);
1257      // cancel unit
1258      cancelunit(&strat->P);
1259      // for char 0, clear denominators
1260      if (TEST_OPT_INTSTRATEGY)
1261        strat->P.pCleardenom();
1262
1263      // put in T
1264      enterT(strat->P,strat);
1265      // build new pairs
1266      enterpairs(strat->P.p,strat->sl,strat->P.ecart,0,strat, strat->tl);
1267      // put in S
1268      strat->enterS(strat->P,
1269                    posInS(strat,strat->sl,strat->P.p, strat->P.ecart),
1270                    strat, strat->tl);
1271
1272      // apply hilbert criterion
1273      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1274
1275      // clear strat->P
1276      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
1277      strat->P.lcm=NULL;
1278#ifdef KDEBUG
1279      // make sure kTest_TS does not complain about strat->P
1280      memset(&strat->P,0,sizeof(strat->P));
1281#endif
1282      if (strat->sl>srmax) srmax = strat->sl; /*stat.*/
1283      if (strat->Ll>lrmax) lrmax = strat->Ll;
1284    }
1285    if (strat->kHEdgeFound)
1286    {
1287      if ((BTEST1(27))
1288      || ((TEST_OPT_MULTBOUND) && (scMult0Int((strat->Shdl)) < mu)))
1289      {
1290        // obachman: is this still used ???
1291        /*
1292        * stops computation if strat->kHEdgeFound and
1293        * - 27 (finiteDeterminacyTest)
1294        * or
1295        * - 23
1296        *   (multBound)
1297        *   && multiplicity of the ideal is smaller then a predefined number mu
1298        */
1299        while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1300      }
1301    }
1302    kTest_TS(strat);
1303  }
1304  /*- complete reduction of the standard basis------------------------ -*/
1305  if (TEST_OPT_REDSB) completeReduce(strat);
1306  /*- release temp data------------------------------- -*/
1307  exitBuchMora(strat);
1308  /*- polynomials used for HECKE: HC, noether -*/
1309  if (BTEST1(27))
1310  {
1311    if (strat->kHEdge!=NULL)
1312      Kstd1_mu=pFDeg(strat->kHEdge,currRing);
1313    else
1314      Kstd1_mu=-1;
1315  }
1316  pDelete(&strat->kHEdge);
1317  strat->update = TRUE; //???
1318  strat->lastAxis = 0; //???
1319  pDelete(&strat->kNoether);
1320  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1321  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
1322  if (TEST_OPT_WEIGHTM)
1323  {
1324    pRestoreDegProcs(pFDegOld, pLDegOld);
1325    if (ecartWeights)
1326    {
1327      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
1328      ecartWeights=NULL;
1329    }
1330  }
1331  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1332  idTest(strat->Shdl);
1333  return (strat->Shdl);
1334}
1335
1336poly kNF1 (ideal F,ideal Q,poly q, kStrategy strat, int lazyReduce)
1337{
1338  poly   p;
1339  int   i;
1340  int   j;
1341  int   o;
1342  LObject   h;
1343  BITSET save_test=test;
1344
1345  if ((idIs0(F))&&(Q==NULL))
1346    return pCopy(q); /*F=0*/
1347  strat->ak = si_max(idRankFreeModule(F),pMaxComp(q));
1348  /*- creating temp data structures------------------- -*/
1349  strat->kHEdgeFound = ppNoether != NULL;
1350  strat->kNoether    = pCopy(ppNoether);
1351  test|=Sy_bit(OPT_REDTAIL);
1352  test&=~Sy_bit(OPT_INTSTRATEGY);
1353  if (TEST_OPT_STAIRCASEBOUND
1354  && (! TEST_V_DEG_STOP)
1355  && (0<Kstd1_deg)
1356  && ((!strat->kHEdgeFound)
1357    ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg))))
1358  {
1359    pDelete(&strat->kNoether);
1360    strat->kNoether=pOne();
1361    pSetExp(strat->kNoether,1, Kstd1_deg+1);
1362    pSetm(strat->kNoether);
1363    strat->kHEdgeFound=TRUE;
1364  }
1365  initBuchMoraCrit(strat);
1366  initBuchMoraPos(strat);
1367  initMora(F,strat);
1368  strat->enterS = enterSMoraNF;
1369  /*- set T -*/
1370  strat->tl = -1;
1371  strat->tmax = setmaxT;
1372  strat->T = initT();
1373  strat->R = initR();
1374  strat->sevT = initsevT();
1375  /*- set S -*/
1376  strat->sl = -1;
1377  /*- init local data struct.-------------------------- -*/
1378  /*Shdl=*/initS(F,Q,strat);
1379  if ((strat->ak!=0)
1380  && (strat->kHEdgeFound))
1381  {
1382    if (strat->ak!=1)
1383    {
1384      pSetComp(strat->kNoether,1);
1385      pSetmComp(strat->kNoether);
1386      poly p=pHead(strat->kNoether);
1387      pSetComp(p,strat->ak);
1388      pSetmComp(p);
1389      p=pAdd(strat->kNoether,p);
1390      strat->kNoether=pNext(p);
1391      p_LmFree(p,currRing);
1392    }
1393  }
1394  if ((lazyReduce & 1)==0)
1395  {
1396    for (i=strat->sl; i>=0; i--)
1397      pNorm(strat->S[i]);
1398  }
1399  /*- puts the elements of S also to T -*/
1400  for (i=0; i<=strat->sl; i++)
1401  {
1402    h.p = strat->S[i];
1403    h.ecart = strat->ecartS[i];
1404    if (strat->sevS[i] == 0) strat->sevS[i] = pGetShortExpVector(h.p);
1405    else assume(strat->sevS[i] == pGetShortExpVector(h.p));
1406    h.length = pLength(h.p);
1407    h.sev = strat->sevS[i];
1408    h.SetpFDeg();
1409    enterT(h,strat);
1410  }
1411  /*- compute------------------------------------------- -*/
1412  p = pCopy(q);
1413  deleteHC(&p,&o,&j,strat);
1414  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
1415  if (p!=NULL) p = redMoraNF(p,strat, lazyReduce & 2);
1416  if ((p!=NULL)&&((lazyReduce & 1)==0))
1417  {
1418    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1419    p = redtail(p,strat->sl,strat);
1420  }
1421  /*- release temp data------------------------------- -*/
1422  cleanT(strat);
1423  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
1424  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1425  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
1426  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1427  omfree(strat->sevT);
1428  omfree(strat->S_2_R);
1429  omfree(strat->R);
1430
1431  if ((Q!=NULL)&&(strat->fromQ!=NULL))
1432  {
1433    i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
1434    omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
1435    strat->fromQ=NULL;
1436  }
1437  pDelete(&strat->kHEdge);
1438  pDelete(&strat->kNoether);
1439  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1440  {
1441    pRestoreDegProcs(pFDegOld, pLDegOld);
1442    if (ecartWeights)
1443    {
1444      omFreeSize((ADDRESS *)&ecartWeights,(pVariables+1)*sizeof(short));
1445      ecartWeights=NULL;
1446    }
1447  }
1448  idDelete(&strat->Shdl);
1449  test=save_test;
1450  if (TEST_OPT_PROT) PrintLn();
1451  return p;
1452}
1453
1454ideal kNF1 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce)
1455{
1456  poly   p;
1457  int   i;
1458  int   j;
1459  int   o;
1460  LObject   h;
1461  ideal res;
1462  BITSET save_test=test;
1463
1464  if (idIs0(q)) return idInit(IDELEMS(q),q->rank);
1465  if ((idIs0(F))&&(Q==NULL))
1466    return idCopy(q); /*F=0*/
1467  strat->ak = si_max(idRankFreeModule(F),idRankFreeModule(q));
1468  /*- creating temp data structures------------------- -*/
1469  strat->kHEdgeFound = ppNoether != NULL;
1470  strat->kNoether=pCopy(ppNoether);
1471  test|=Sy_bit(OPT_REDTAIL);
1472  if (TEST_OPT_STAIRCASEBOUND
1473  && (0<Kstd1_deg)
1474  && ((!strat->kHEdgeFound)
1475    ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg))))
1476  {
1477    pDelete(&strat->kNoether);
1478    strat->kNoether=pOne();
1479    pSetExp(strat->kNoether,1, Kstd1_deg+1);
1480    pSetm(strat->kNoether);
1481    strat->kHEdgeFound=TRUE;
1482  }
1483  initBuchMoraCrit(strat);
1484  initBuchMoraPos(strat);
1485  initMora(F,strat);
1486  strat->enterS = enterSMoraNF;
1487  /*- set T -*/
1488  strat->tl = -1;
1489  strat->tmax = setmaxT;
1490  strat->T = initT();
1491  strat->R = initR();
1492  strat->sevT = initsevT();
1493  /*- set S -*/
1494  strat->sl = -1;
1495  /*- init local data struct.-------------------------- -*/
1496  /*Shdl=*/initS(F,Q,strat);
1497  if ((strat->ak!=0)
1498  && (strat->kHEdgeFound))
1499  {
1500    if (strat->ak!=1)
1501    {
1502      pSetComp(strat->kNoether,1);
1503      pSetmComp(strat->kNoether);
1504      poly p=pHead(strat->kNoether);
1505      pSetComp(p,strat->ak);
1506      pSetmComp(p);
1507      p=pAdd(strat->kNoether,p);
1508      strat->kNoether=pNext(p);
1509      p_LmFree(p,currRing);
1510    }
1511  }
1512  if (TEST_OPT_INTSTRATEGY && ((lazyReduce & 1)==0))
1513  {
1514    for (i=strat->sl; i>=0; i--)
1515      pNorm(strat->S[i]);
1516  }
1517  /*- compute------------------------------------------- -*/
1518  res=idInit(IDELEMS(q),q->rank);
1519  for (i=0; i<IDELEMS(q); i++)
1520  {
1521    if (q->m[i]!=NULL)
1522    {
1523      p = pCopy(q->m[i]);
1524      deleteHC(&p,&o,&j,strat);
1525      if (p!=NULL)
1526      {
1527        /*- puts the elements of S also to T -*/
1528        for (j=0; j<=strat->sl; j++)
1529        {
1530          h.p = strat->S[j];
1531          h.ecart = strat->ecartS[j];
1532          h.pLength = h.length = pLength(h.p);
1533          if (strat->sevS[j] == 0) strat->sevS[j] = pGetShortExpVector(h.p);
1534          else assume(strat->sevS[j] == pGetShortExpVector(h.p));
1535          h.sev = strat->sevS[j];
1536          h.SetpFDeg();
1537          enterT(h,strat);
1538        }
1539        if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
1540        p = redMoraNF(p,strat, lazyReduce & 2);
1541        if ((p!=NULL)&&((lazyReduce & 1)==0))
1542        {
1543          if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1544          p = redtail(p,strat->sl,strat);
1545        }
1546        cleanT(strat);
1547      }
1548      res->m[i]=p;
1549    }
1550    //else
1551    //  res->m[i]=NULL;
1552  }
1553  /*- release temp data------------------------------- -*/
1554  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
1555  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1556  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
1557  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1558  omfree(strat->sevT);
1559  omfree(strat->S_2_R);
1560  omfree(strat->R);
1561  if ((Q!=NULL)&&(strat->fromQ!=NULL))
1562  {
1563    i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
1564    omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
1565    strat->fromQ=NULL;
1566  }
1567  pDelete(&strat->kHEdge);
1568  pDelete(&strat->kNoether);
1569  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1570  {
1571    pFDeg=pFDegOld;
1572    pLDeg=pLDegOld;
1573    if (ecartWeights)
1574    {
1575      omFreeSize((ADDRESS *)&ecartWeights,(pVariables+1)*sizeof(short));
1576      ecartWeights=NULL;
1577    }
1578  }
1579  idDelete(&strat->Shdl);
1580  test=save_test;
1581  if (TEST_OPT_PROT) PrintLn();
1582  return res;
1583}
1584
1585pFDegProc pFDegOld;
1586pLDegProc pLDegOld;
1587intvec * kModW, * kHomW;
1588
1589long kModDeg(poly p, ring r)
1590{
1591  long o=pWDegree(p, r);
1592  long i=p_GetComp(p, r);
1593  if (i==0) return o;
1594  assume((i>0) && (i<=kModW->length()));
1595  return o+(*kModW)[i-1];
1596}
1597long kHomModDeg(poly p, ring r)
1598{
1599  int i;
1600  long j=0;
1601
1602  for (i=r->N;i>0;i--)
1603    j+=p_GetExp(p,i,r)*(*kHomW)[i-1];
1604  if (kModW == NULL) return j;
1605  i = p_GetComp(p,r);
1606  if (i==0) return j;
1607  return j+(*kModW)[i-1];
1608}
1609
1610ideal kStd(ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp,
1611          int newIdeal, intvec *vw)
1612{
1613  ideal r;
1614  BOOLEAN b=pLexOrder,toReset=FALSE;
1615  BOOLEAN delete_w=(w==NULL);
1616  kStrategy strat=new skStrategy;
1617
1618  if(!TEST_OPT_RETURN_SB)
1619    strat->syzComp = syzComp;
1620  if (TEST_OPT_SB_1)
1621    strat->newIdeal = newIdeal;
1622  if (rField_has_simple_inverse())
1623    strat->LazyPass=20;
1624  else
1625    strat->LazyPass=2;
1626  strat->LazyDegree = 1;
1627  strat->ak = idRankFreeModule(F);
1628  strat->kModW=kModW=NULL;
1629  strat->kHomW=kHomW=NULL;
1630  if (vw != NULL)
1631  {
1632    pLexOrder=FALSE;
1633    strat->kHomW=kHomW=vw;
1634    pFDegOld = pFDeg;
1635    pLDegOld = pLDeg;
1636    pSetDegProcs(kHomModDeg);
1637    toReset = TRUE;
1638  }
1639  if (h==testHomog)
1640  {
1641    if (strat->ak == 0)
1642    {
1643      h = (tHomog)idHomIdeal(F,Q);
1644      w=NULL;
1645    }
1646    else if (!TEST_OPT_DEGBOUND)
1647    {
1648      h = (tHomog)idHomModule(F,Q,w);
1649    }
1650  }
1651  pLexOrder=b;
1652  if (h==isHomog)
1653  {
1654    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
1655    {
1656      strat->kModW = kModW = *w;
1657      if (vw == NULL)
1658      {
1659        pFDegOld = pFDeg;
1660        pLDegOld = pLDeg;
1661        pSetDegProcs(kModDeg);
1662        toReset = TRUE;
1663      }
1664    }
1665    pLexOrder = TRUE;
1666    if (hilb==NULL) strat->LazyPass*=2;
1667  }
1668  strat->homog=h;
1669#ifdef KDEBUG
1670  idTest(F);
1671#endif
1672#ifdef HAVE_PLURAL
1673  if (rIsPluralRing(currRing))
1674  {
1675    if (w!=NULL)
1676      r = nc_GB(F, Q, *w, hilb, strat);
1677    else
1678      r = nc_GB(F, Q, NULL, hilb, strat);
1679  }
1680  else
1681#endif
1682  {
1683    if (pOrdSgn==-1)
1684    {
1685      if (w!=NULL)
1686        r=mora(F,Q,*w,hilb,strat);
1687      else
1688        r=mora(F,Q,NULL,hilb,strat);
1689    }
1690    else
1691    {
1692      if (w!=NULL)
1693        r=bba(F,Q,*w,hilb,strat);
1694      else
1695        r=bba(F,Q,NULL,hilb,strat);
1696    }
1697  }
1698#ifdef KDEBUG
1699  idTest(r);
1700#endif
1701  if (toReset)
1702  {
1703    kModW = NULL;
1704    pRestoreDegProcs(pFDegOld, pLDegOld);
1705  }
1706  pLexOrder = b;
1707//Print("%d reductions canceled \n",strat->cel);
1708  HCord=strat->HCord;
1709  delete(strat);
1710  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
1711  return r;
1712}
1713
1714//##############################################################
1715//##############################################################
1716//##############################################################
1717//##############################################################
1718//##############################################################
1719
1720ideal kMin_std(ideal F, ideal Q, tHomog h,intvec ** w, ideal &M, intvec *hilb,
1721              int syzComp, int reduced)
1722{
1723  ideal r=NULL;
1724  int Kstd1_OldDeg = Kstd1_deg,i;
1725  intvec* temp_w=NULL;
1726  BOOLEAN b=pLexOrder,toReset=FALSE;
1727  BOOLEAN delete_w=(w==NULL);
1728  BOOLEAN oldDegBound=TEST_OPT_DEGBOUND;
1729  kStrategy strat=new skStrategy;
1730
1731  if(!TEST_OPT_RETURN_SB)
1732     strat->syzComp = syzComp;
1733  if (rField_has_simple_inverse())
1734    strat->LazyPass=20;
1735  else
1736    strat->LazyPass=2;
1737  strat->LazyDegree = 1;
1738  strat->minim=(reduced % 2)+1;
1739  strat->ak = idRankFreeModule(F);
1740  if (delete_w)
1741  {
1742    temp_w=new intvec((strat->ak)+1);
1743    w = &temp_w;
1744  }
1745  if ((h==testHomog)
1746  )
1747  {
1748    if (strat->ak == 0)
1749    {
1750      h = (tHomog)idHomIdeal(F,Q);
1751      w=NULL;
1752    }
1753    else
1754    {
1755      h = (tHomog)idHomModule(F,Q,w);
1756    }
1757  }
1758  if (h==isHomog)
1759  {
1760    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
1761    {
1762      kModW = *w;
1763      strat->kModW = *w;
1764      assume(pFDeg != NULL && pLDeg != NULL);
1765      pFDegOld = pFDeg;
1766      pLDegOld = pLDeg;
1767      pSetDegProcs(kModDeg);
1768
1769      toReset = TRUE;
1770      if (reduced>1)
1771      {
1772        Kstd1_OldDeg=Kstd1_deg;
1773        Kstd1_deg = -1;
1774        for (i=IDELEMS(F)-1;i>=0;i--)
1775        {
1776          if ((F->m[i]!=NULL) && (pFDeg(F->m[i],currRing)>=Kstd1_deg))
1777            Kstd1_deg = pFDeg(F->m[i],currRing)+1;
1778        }
1779      }
1780    }
1781    pLexOrder = TRUE;
1782    strat->LazyPass*=2;
1783  }
1784  strat->homog=h;
1785  if (pOrdSgn==-1)
1786  {
1787    if (w!=NULL)
1788      r=mora(F,Q,*w,hilb,strat);
1789    else
1790      r=mora(F,Q,NULL,hilb,strat);
1791  }
1792  else
1793  {
1794    if (w!=NULL)
1795      r=bba(F,Q,*w,hilb,strat);
1796    else
1797      r=bba(F,Q,NULL,hilb,strat);
1798  }
1799#ifdef KDEBUG
1800  {
1801    int i;
1802    for (i=IDELEMS(r)-1; i>=0; i--) pTest(r->m[i]);
1803  }
1804#endif
1805  idSkipZeroes(r);
1806  if (toReset)
1807  {
1808    pRestoreDegProcs(pFDegOld, pLDegOld);
1809    kModW = NULL;
1810  }
1811  pLexOrder = b;
1812  HCord=strat->HCord;
1813  if ((delete_w)&&(temp_w!=NULL)) delete temp_w;
1814  if ((IDELEMS(r)==1) && (r->m[0]!=NULL) && pIsConstant(r->m[0]) && (strat->ak==0))
1815  {
1816    M=idInit(1,F->rank);
1817    M->m[0]=pOne();
1818    //if (strat->ak!=0) { pSetComp(M->m[0],strat->ak); pSetmComp(M->m[0]); }
1819    if (strat->M!=NULL) idDelete(&strat->M);
1820  }
1821  else
1822  if (strat->M==NULL)
1823  {
1824    M=idInit(1,F->rank);
1825    Warn("no minimal generating set computed");
1826  }
1827  else
1828  {
1829    idSkipZeroes(strat->M);
1830    M=strat->M;
1831  }
1832  delete(strat);
1833  if (reduced>2)
1834  {
1835    Kstd1_deg=Kstd1_OldDeg;
1836    if (!oldDegBound)
1837      test &= ~Sy_bit(OPT_DEGBOUND);
1838  }
1839  return r;
1840}
1841
1842poly kNF(ideal F, ideal Q, poly p,int syzComp, int lazyReduce)
1843{
1844  if (p==NULL)
1845     return NULL;
1846  kStrategy strat=new skStrategy;
1847  strat->syzComp = syzComp;
1848  if (pOrdSgn==-1)
1849    p=kNF1(F,Q,p,strat,lazyReduce);
1850  else
1851    p=kNF2(F,Q,p,strat,lazyReduce);
1852  delete(strat);
1853  return p;
1854}
1855
1856ideal kNF(ideal F, ideal Q, ideal p,int syzComp,int lazyReduce)
1857{
1858  ideal res;
1859  if (TEST_OPT_PROT)
1860  {
1861    Print("(S:%d)",IDELEMS(p));mflush();
1862  }
1863  kStrategy strat=new skStrategy;
1864  strat->syzComp = syzComp;
1865  if (pOrdSgn==-1)
1866    res=kNF1(F,Q,p,strat,lazyReduce);
1867  else
1868    res=kNF2(F,Q,p,strat,lazyReduce);
1869  delete(strat);
1870  return res;
1871}
1872
1873/*2
1874*interreduces F
1875*/
1876#if 0
1877// new version
1878ideal kInterRed (ideal F, ideal Q)
1879{
1880  int   srmax,lrmax, red_result = 1;
1881  int   olddeg,reduc,j;
1882  BOOLEAN need_update=FALSE;
1883
1884  kStrategy strat = new skStrategy;
1885  strat->kHEdgeFound = ppNoether != NULL;
1886  strat->kNoether=pCopy(ppNoether);
1887  strat->ak = idRankFreeModule(F);
1888  initBuchMoraCrit(strat);
1889  initBuchMoraPos(strat);
1890  strat->NotUsedAxis = (BOOLEAN *)omAlloc((pVariables+1)*sizeof(BOOLEAN));
1891  for (j=pVariables; j>0; j--) strat->NotUsedAxis[j] = TRUE;
1892  strat->enterS      = enterSBba;
1893  strat->posInT      = posInT17;
1894  strat->initEcart   = initEcartNormal;
1895  strat->sl          = -1;
1896  strat->tl          = -1;
1897  strat->Ll          = -1;
1898  strat->tmax        = setmaxT;
1899  strat->Lmax        = setmaxL;
1900  strat->T           = initT();
1901  strat->R           = initR();
1902  strat->L           = initL();
1903  strat->sevT        = initsevT();
1904  strat->red         = redLazy;
1905  strat->tailRing    = currRing;
1906  if (pOrdSgn == -1)
1907    strat->honey = TRUE;
1908  initSL(F,Q,strat);
1909  for(j=strat->Ll; j>=0; j--)
1910    strat->L[j].tailRing=currRing;
1911  if (TEST_OPT_REDSB)
1912    strat->noTailReduction=FALSE;
1913
1914  srmax = strat->sl;
1915  reduc = olddeg = lrmax = 0;
1916
1917#ifndef NO_BUCKETS
1918  if (!TEST_OPT_NOT_BUCKETS)
1919    strat->use_buckets = 1;
1920#endif
1921
1922  // strat->posInT = posInT_pLength;
1923  kTest_TS(strat);
1924
1925  /* compute------------------------------------------------------- */
1926  while (strat->Ll >= 0)
1927  {
1928    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
1929#ifdef KDEBUG
1930    if (TEST_OPT_DEBUG) messageSets(strat);
1931#endif
1932    if (strat->Ll== 0) strat->interpt=TRUE;
1933    /* picks the last element from the lazyset L */
1934    strat->P = strat->L[strat->Ll];
1935    strat->Ll--;
1936
1937    // for input polys, prepare reduction
1938    strat->P.PrepareRed(strat->use_buckets);
1939
1940    if (strat->P.p == NULL && strat->P.t_p == NULL)
1941    {
1942      red_result = 0;
1943    }
1944    else
1945    {
1946      if (TEST_OPT_PROT)
1947        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
1948                &olddeg,&reduc,strat, red_result);
1949
1950      /* reduction of the element choosen from L */
1951      red_result = strat->red(&strat->P,strat);
1952    }
1953
1954    // reduction to non-zero new poly
1955    if (red_result == 1)
1956    {
1957      /* statistic */
1958      if (TEST_OPT_PROT) PrintS("s");
1959
1960      // get the polynomial (canonicalize bucket, make sure P.p is set)
1961      strat->P.GetP(strat->lmBin);
1962
1963      int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
1964
1965      // reduce the tail and normalize poly
1966      if (TEST_OPT_INTSTRATEGY)
1967      {
1968        strat->P.pCleardenom();
1969        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
1970        {
1971          strat->P.p = redtailBba(&(strat->P),pos-1,strat, FALSE);
1972          strat->P.pCleardenom();
1973        }
1974      }
1975      else
1976      {
1977        strat->P.pNorm();
1978        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
1979          strat->P.p = redtailBba(&(strat->P),pos-1,strat, FALSE);
1980      }
1981
1982#ifdef KDEBUG
1983      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
1984#endif
1985
1986      // enter into S, L, and T
1987      enterT(strat->P, strat);
1988      // posInS only depends on the leading term
1989      strat->enterS(strat->P, pos, strat, strat->tl);
1990      if (pos<strat->sl)
1991      {
1992        need_update=TRUE;
1993#if 0
1994        LObject h;
1995        for(j=strat->sl;j>pos;j--)
1996        {
1997          if (TEST_OPT_PROT) { PrintS("+"); mflush(); }
1998          memset(&h, 0, sizeof(h));
1999          h.p=strat->S[j];
2000          int i;
2001          for(i=strat->tl;i>=0;i--)
2002          {
2003            if (pLmCmp(h.p,strat->T[i].p)==0)
2004            {
2005              if (i < strat->tl)
2006              {
2007#ifdef ENTER_USE_MEMMOVE
2008                memmove(&(strat->T[i]), &(strat->T[i+1]),
2009                   (strat->tl-i)*sizeof(TObject));
2010                memmove(&(strat->sevT[i]), &(strat->sevT[i+1]),
2011                   (strat->tl-i)*sizeof(unsigned long));
2012#endif
2013                for (int l=i; l<strat->tl; l++)
2014                {
2015#ifndef ENTER_USE_MEMMOVE
2016                  strat->T[l] = strat->T[l+1];
2017                  strat->sevT[l] = strat->sevT[l+1];
2018#endif
2019                  strat->R[strat->T[l].i_r] = &(strat->T[l]);
2020                }
2021              }
2022              strat->tl--;
2023              break;
2024            }
2025          }
2026          strat->S[j]=NULL;
2027          strat->sl--;
2028          if (TEST_OPT_INTSTRATEGY)
2029          {
2030            //pContent(h.p);
2031            h.pCleardenom(); // also does a pContent
2032          }
2033          else
2034          {
2035            h.pNorm();
2036          }
2037          strat->initEcart(&h);
2038                    if (strat->Ll==-1)
2039            pos =0;
2040          else
2041            pos = strat->posInL(strat->L,strat->Ll,&h,strat);
2042          h.sev = pGetShortExpVector(h.p);
2043          enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
2044        }
2045#endif
2046      }
2047      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
2048      if (strat->sl>srmax) srmax = strat->sl;
2049    }
2050#ifdef KDEBUG
2051    memset(&(strat->P), 0, sizeof(strat->P));
2052#endif
2053    kTest_TS(strat);
2054  }
2055#ifdef KDEBUG
2056  if (TEST_OPT_DEBUG) messageSets(strat);
2057#endif
2058  /* complete reduction of the standard basis--------- */
2059  if (TEST_OPT_REDSB)
2060  {
2061    completeReduce(strat);
2062    if (strat->completeReduce_retry)
2063    {
2064      // completeReduce needed larger exponents, retry
2065      // to reduce with S (instead of T)
2066      // and in currRing (instead of strat->tailRing)
2067      cleanT(strat);strat->tailRing=currRing;
2068      int i;
2069      for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
2070      completeReduce(strat);
2071    }
2072  }
2073
2074  /* release temp data-------------------------------- */
2075  if (TEST_OPT_PROT) messageStat(srmax,lrmax,0,strat);
2076  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
2077  ideal shdl=strat->Shdl;
2078  idSkipZeroes(shdl);
2079  pDelete(&strat->kHEdge);
2080  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
2081  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
2082  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
2083  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
2084  omFreeSize((ADDRESS)strat->L,(strat->Lmax)*sizeof(LObject));
2085  omfree(strat->sevT);
2086  omfree(strat->S_2_R);
2087  omfree(strat->R);
2088
2089  if (strat->fromQ)
2090  {
2091    for (j=IDELEMS(strat->Shdl)-1;j>=0;j--)
2092    {
2093      if(strat->fromQ[j]) pDelete(&strat->Shdl->m[j]);
2094    }
2095    omFreeSize((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
2096    strat->fromQ=NULL;
2097  }
2098  delete(strat);
2099#if 0
2100  if (need_update)
2101  {
2102    ideal res=kInterRed(shdl,Q);
2103    idDelete(&shdl);
2104    shdl=res;
2105  }
2106#endif
2107  return shdl;
2108}
2109#else
2110// old version
2111ideal kInterRed (ideal F, ideal Q)
2112{
2113  int j;
2114  kStrategy strat = new skStrategy;
2115
2116//  if (TEST_OPT_PROT)
2117//  {
2118//    writeTime("start InterRed:");
2119//    mflush();
2120//  }
2121  //strat->syzComp     = 0;
2122  strat->kHEdgeFound = ppNoether != NULL;
2123  strat->kNoether=pCopy(ppNoether);
2124  strat->ak = idRankFreeModule(F);
2125  initBuchMoraCrit(strat);
2126  strat->NotUsedAxis = (BOOLEAN *)omAlloc((pVariables+1)*sizeof(BOOLEAN));
2127  for (j=pVariables; j>0; j--) strat->NotUsedAxis[j] = TRUE;
2128  strat->enterS      = enterSBba;
2129  strat->posInT      = posInT17;
2130  strat->initEcart   = initEcartNormal;
2131  strat->sl   = -1;
2132  strat->tl          = -1;
2133  strat->tmax        = setmaxT;
2134  strat->T           = initT();
2135  strat->R           = initR();
2136  strat->sevT        = initsevT();
2137  if (pOrdSgn == -1)   strat->honey = TRUE;
2138  initS(F,Q,strat);
2139  if (TEST_OPT_REDSB)
2140    strat->noTailReduction=FALSE;
2141  updateS(TRUE,strat);
2142  if (TEST_OPT_REDSB && TEST_OPT_INTSTRATEGY)
2143    completeReduce(strat);
2144  pDelete(&strat->kHEdge);
2145  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
2146  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
2147  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
2148  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
2149  omfree(strat->sevT);
2150  omfree(strat->S_2_R);
2151  omfree(strat->R);
2152
2153  if (strat->fromQ)
2154  {
2155    for (j=IDELEMS(strat->Shdl)-1;j>=0;j--)
2156    {
2157      if(strat->fromQ[j]) pDelete(&strat->Shdl->m[j]);
2158    }
2159    omFreeSize((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
2160    strat->fromQ=NULL;
2161  }
2162//  if (TEST_OPT_PROT)
2163//  {
2164//    writeTime("end Interred:");
2165//    mflush();
2166//  }
2167  ideal shdl=strat->Shdl;
2168  idSkipZeroes(shdl);
2169  delete(strat);
2170  return shdl;
2171}
2172#endif
2173
2174// returns TRUE if mora should use buckets, false otherwise
2175static BOOLEAN kMoraUseBucket(kStrategy strat)
2176{
2177#ifdef MORA_USE_BUCKETS
2178  if (TEST_OPT_NOT_BUCKETS)
2179    return FALSE;
2180  if (strat->red == redFirst)
2181  {
2182#ifdef NO_LDEG
2183    if (strat->syzComp==0)
2184      return TRUE;
2185#else
2186    if ((strat->homog || strat->honey) && (strat->syzComp==0))
2187      return TRUE;
2188#endif
2189  }
2190  else
2191  {
2192    assume(strat->red == redEcart);
2193    if (strat->honey && (strat->syzComp==0))
2194      return TRUE;
2195  }
2196#endif
2197  return FALSE;
2198}
Note: See TracBrowser for help on using the repository browser.