source: git/kernel/kstd1.cc @ 3a67ea7

spielwiese
Last change on this file since 3a67ea7 was 04d04e0, checked in by Oliver Wienand <wienand@…>, 17 years ago
kleine verbesserungen und konstantencheck für ringe entfernt. git-svn-id: file:///usr/local/Singular/svn/trunk@10067 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 54.7 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kstd1.cc,v 1.21 2007-05-22 16:14:09 wienand 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_RINGS  //TODO Oliver
1011  if (rField_is_Ring(currRing)) {
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#ifdef HAVE_RINGS  //TODO Oliver
1072  else if (rField_is_Ring(currRing))
1073    strat->red = redRing2toM;
1074#endif
1075  else
1076    strat->red = redEcart;/*take the first possible in under ecart-restriction*/
1077  if (strat->kHEdgeFound)
1078  {
1079    strat->HCord = pFDeg(ppNoether,currRing)+1;
1080    strat->posInT = posInT2;
1081  }
1082  else
1083  {
1084    strat->HCord = 32000;/*- very large -*/
1085  }
1086  /*reads the ecartWeights used for Graebes method from the
1087   *intvec ecart and set ecartWeights
1088   */
1089  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1090  {
1091    //interred  machen   Aenderung
1092    pFDegOld=pFDeg;
1093    pLDegOld=pLDeg;
1094    //h=ggetid("ecart");
1095    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
1096    //{
1097    //  ecartWeights=iv2array(IDINTVEC(h));
1098    //}
1099    //else
1100    {
1101      ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short));
1102      /*uses automatic computation of the ecartWeights to set them*/
1103      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1104    }
1105
1106    pSetDegProcs(totaldegreeWecart, maxdegreeWecart);
1107    if (TEST_OPT_PROT)
1108    {
1109      for(i=1; i<=pVariables; i++)
1110        Print(" %d",ecartWeights[i]);
1111      PrintLn();
1112      mflush();
1113    }
1114  }
1115  kOptimizeLDeg(pLDeg, strat);
1116}
1117
1118#ifdef HAVE_ASSUME
1119static int mora_count = 0;
1120static int mora_loop_count;
1121#endif
1122
1123ideal mora (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
1124{
1125#ifdef HAVE_ASSUME
1126  mora_count++;
1127  mora_loop_count = 0;
1128#endif
1129#ifdef KDEBUG
1130  om_Opts.MinTrack = 5;
1131#endif
1132  int srmax;
1133  int lrmax = 0;
1134  int olddeg = 0;
1135  int reduc = 0;
1136  int red_result = 1;
1137  int hilbeledeg=1,hilbcount=0;
1138
1139  strat->update = TRUE;
1140  /*- setting global variables ------------------- -*/
1141  initBuchMoraCrit(strat);
1142  initHilbCrit(F,Q,&hilb,strat);
1143  initMora(F,strat);
1144  initBuchMoraPos(strat);
1145  /*Shdl=*/initBuchMora(F,Q,strat);
1146  if (TEST_OPT_FASTHC) missingAxis(&strat->lastAxis,strat);
1147  /*updateS in initBuchMora has Hecketest
1148  * and could have put strat->kHEdgdeFound FALSE*/
1149  if (ppNoether!=NULL)
1150  {
1151    strat->kHEdgeFound = TRUE;
1152  }
1153  if (strat->kHEdgeFound && strat->update)
1154  {
1155    firstUpdate(strat);
1156    updateLHC(strat);
1157    reorderL(strat);
1158  }
1159  if (TEST_OPT_FASTHC && (strat->lastAxis) && strat->posInLOldFlag)
1160  {
1161    strat->posInLOld = strat->posInL;
1162    strat->posInLOldFlag = FALSE;
1163    strat->posInL = posInL10;
1164    updateL(strat);
1165    reorderL(strat);
1166  }
1167  srmax = strat->sl;
1168  kTest_TS(strat);
1169  strat->use_buckets = kMoraUseBucket(strat);
1170  /*- compute-------------------------------------------*/
1171
1172#ifdef HAVE_TAIL_RING
1173//  if (strat->homog && strat->red == redFirst)
1174    kStratInitChangeTailRing(strat);
1175#endif
1176
1177  while (strat->Ll >= 0)
1178  {
1179#ifdef HAVE_ASSUME
1180    mora_loop_count++;
1181#endif
1182    if (lrmax< strat->Ll) lrmax=strat->Ll; /*stat*/
1183    //test_int_std(strat->kIdeal);
1184    if (TEST_OPT_DEBUG) messageSets(strat);
1185    if (TEST_OPT_DEGBOUND
1186    && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg))
1187    {
1188      /*
1189      * stops computation if
1190      * - 24 (degBound)
1191      *   && upper degree is bigger than Kstd1_deg
1192      */
1193      while ((strat->Ll >= 0)
1194        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
1195        && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg)
1196      )
1197      {
1198        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1199        //if (TEST_OPT_PROT)
1200        //{
1201        //   PrintS("D"); mflush();
1202        //}
1203      }
1204      if (strat->Ll<0) break;
1205      else strat->noClearS=TRUE;
1206    }
1207    strat->P = strat->L[strat->Ll];/*- picks the last element from the lazyset L -*/
1208    if (strat->Ll==0) strat->interpt=TRUE;
1209    strat->Ll--;
1210
1211    // create the real Spoly
1212    if (pNext(strat->P.p) == strat->tail)
1213    {
1214      /*- deletes the short spoly and computes -*/
1215      pLmFree(strat->P.p);
1216      strat->P.p = NULL;
1217      poly m1 = NULL, m2 = NULL;
1218      // check that spoly creation is ok
1219      while (strat->tailRing != currRing &&
1220             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
1221      {
1222        assume(m1 == NULL && m2 == NULL);
1223        // if not, change to a ring where exponents are large enough
1224        kStratChangeTailRing(strat);
1225      }
1226      /* create the real one */
1227      ksCreateSpoly(&(strat->P), strat->kNoetherTail(), strat->use_buckets,
1228                    strat->tailRing, m1, m2, strat->R);
1229      if (!strat->use_buckets)
1230        strat->P.SetLength(strat->length_pLength);
1231    }
1232    else if (strat->P.p1 == NULL)
1233    {
1234      // for input polys, prepare reduction (buckets !)
1235      strat->P.SetLength(strat->length_pLength);
1236      strat->P.PrepareRed(strat->use_buckets);
1237    }
1238
1239    if (!strat->P.IsNull())
1240    {
1241      // might be NULL from noether !!!
1242      if (TEST_OPT_PROT)
1243        message(strat->P.ecart+strat->P.GetpFDeg(),&olddeg,&reduc,strat, red_result);
1244      // reduce
1245      red_result = strat->red(&strat->P,strat);
1246    }
1247
1248    if (! strat->P.IsNull())
1249    {
1250      strat->P.GetP();
1251      // statistics
1252      if (TEST_OPT_PROT) PrintS("s");
1253      // normalization
1254      if (!TEST_OPT_INTSTRATEGY)
1255        strat->P.pNorm();
1256      // tailreduction
1257      strat->P.p = redtail(&(strat->P),strat->sl,strat);
1258      // set ecart -- might have changed because of tail reductions
1259      if ((!strat->noTailReduction) && (!strat->honey))
1260        strat->initEcart(&strat->P);
1261      // cancel unit
1262      cancelunit(&strat->P);
1263      // for char 0, clear denominators
1264      if (TEST_OPT_INTSTRATEGY)
1265        strat->P.pCleardenom();
1266
1267      // put in T
1268      enterT(strat->P,strat);
1269      // build new pairs
1270      enterpairs(strat->P.p,strat->sl,strat->P.ecart,0,strat, strat->tl);
1271      // put in S
1272      strat->enterS(strat->P,
1273                    posInS(strat,strat->sl,strat->P.p, strat->P.ecart),
1274                    strat, strat->tl);
1275
1276      // apply hilbert criterion
1277      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1278
1279      // clear strat->P
1280      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
1281      strat->P.lcm=NULL;
1282#ifdef KDEBUG
1283      // make sure kTest_TS does not complain about strat->P
1284      memset(&strat->P,0,sizeof(strat->P));
1285#endif
1286      if (strat->sl>srmax) srmax = strat->sl; /*stat.*/
1287      if (strat->Ll>lrmax) lrmax = strat->Ll;
1288    }
1289    if (strat->kHEdgeFound)
1290    {
1291      if ((BTEST1(27))
1292      || ((TEST_OPT_MULTBOUND) && (scMult0Int((strat->Shdl)) < mu)))
1293      {
1294        // obachman: is this still used ???
1295        /*
1296        * stops computation if strat->kHEdgeFound and
1297        * - 27 (finiteDeterminacyTest)
1298        * or
1299        * - 23
1300        *   (multBound)
1301        *   && multiplicity of the ideal is smaller then a predefined number mu
1302        */
1303        while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1304      }
1305    }
1306    kTest_TS(strat);
1307  }
1308  /*- complete reduction of the standard basis------------------------ -*/
1309  if (TEST_OPT_REDSB) completeReduce(strat);
1310  /*- release temp data------------------------------- -*/
1311  exitBuchMora(strat);
1312  /*- polynomials used for HECKE: HC, noether -*/
1313  if (BTEST1(27))
1314  {
1315    if (strat->kHEdge!=NULL)
1316      Kstd1_mu=pFDeg(strat->kHEdge,currRing);
1317    else
1318      Kstd1_mu=-1;
1319  }
1320  pDelete(&strat->kHEdge);
1321  strat->update = TRUE; //???
1322  strat->lastAxis = 0; //???
1323  pDelete(&strat->kNoether);
1324  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1325  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
1326  if (TEST_OPT_WEIGHTM)
1327  {
1328    pRestoreDegProcs(pFDegOld, pLDegOld);
1329    if (ecartWeights)
1330    {
1331      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
1332      ecartWeights=NULL;
1333    }
1334  }
1335  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1336  idTest(strat->Shdl);
1337  return (strat->Shdl);
1338}
1339
1340poly kNF1 (ideal F,ideal Q,poly q, kStrategy strat, int lazyReduce)
1341{
1342  poly   p;
1343  int   i;
1344  int   j;
1345  int   o;
1346  LObject   h;
1347  BITSET save_test=test;
1348
1349  if ((idIs0(F))&&(Q==NULL))
1350    return pCopy(q); /*F=0*/
1351  strat->ak = si_max(idRankFreeModule(F),pMaxComp(q));
1352  /*- creating temp data structures------------------- -*/
1353  strat->kHEdgeFound = ppNoether != NULL;
1354  strat->kNoether    = pCopy(ppNoether);
1355  test|=Sy_bit(OPT_REDTAIL);
1356  test&=~Sy_bit(OPT_INTSTRATEGY);
1357  if (TEST_OPT_STAIRCASEBOUND
1358  && (! TEST_V_DEG_STOP)
1359  && (0<Kstd1_deg)
1360  && ((!strat->kHEdgeFound)
1361    ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg))))
1362  {
1363    pDelete(&strat->kNoether);
1364    strat->kNoether=pOne();
1365    pSetExp(strat->kNoether,1, Kstd1_deg+1);
1366    pSetm(strat->kNoether);
1367    strat->kHEdgeFound=TRUE;
1368  }
1369  initBuchMoraCrit(strat);
1370  initBuchMoraPos(strat);
1371  initMora(F,strat);
1372  strat->enterS = enterSMoraNF;
1373  /*- set T -*/
1374  strat->tl = -1;
1375  strat->tmax = setmaxT;
1376  strat->T = initT();
1377  strat->R = initR();
1378  strat->sevT = initsevT();
1379  /*- set S -*/
1380  strat->sl = -1;
1381  /*- init local data struct.-------------------------- -*/
1382  /*Shdl=*/initS(F,Q,strat);
1383  if ((strat->ak!=0)
1384  && (strat->kHEdgeFound))
1385  {
1386    if (strat->ak!=1)
1387    {
1388      pSetComp(strat->kNoether,1);
1389      pSetmComp(strat->kNoether);
1390      poly p=pHead(strat->kNoether);
1391      pSetComp(p,strat->ak);
1392      pSetmComp(p);
1393      p=pAdd(strat->kNoether,p);
1394      strat->kNoether=pNext(p);
1395      p_LmFree(p,currRing);
1396    }
1397  }
1398  if ((lazyReduce & 1)==0)
1399  {
1400    for (i=strat->sl; i>=0; i--)
1401      pNorm(strat->S[i]);
1402  }
1403  /*- puts the elements of S also to T -*/
1404  for (i=0; i<=strat->sl; i++)
1405  {
1406    h.p = strat->S[i];
1407    h.ecart = strat->ecartS[i];
1408    if (strat->sevS[i] == 0) strat->sevS[i] = pGetShortExpVector(h.p);
1409    else assume(strat->sevS[i] == pGetShortExpVector(h.p));
1410    h.length = pLength(h.p);
1411    h.sev = strat->sevS[i];
1412    h.SetpFDeg();
1413    enterT(h,strat);
1414  }
1415  /*- compute------------------------------------------- -*/
1416  p = pCopy(q);
1417  deleteHC(&p,&o,&j,strat);
1418  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
1419  if (p!=NULL) p = redMoraNF(p,strat, lazyReduce & 2);
1420  if ((p!=NULL)&&((lazyReduce & 1)==0))
1421  {
1422    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1423    p = redtail(p,strat->sl,strat);
1424  }
1425  /*- release temp data------------------------------- -*/
1426  cleanT(strat);
1427  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
1428  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1429  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
1430  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1431  omfree(strat->sevT);
1432  omfree(strat->S_2_R);
1433  omfree(strat->R);
1434
1435  if ((Q!=NULL)&&(strat->fromQ!=NULL))
1436  {
1437    i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
1438    omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
1439    strat->fromQ=NULL;
1440  }
1441  pDelete(&strat->kHEdge);
1442  pDelete(&strat->kNoether);
1443  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1444  {
1445    pRestoreDegProcs(pFDegOld, pLDegOld);
1446    if (ecartWeights)
1447    {
1448      omFreeSize((ADDRESS *)&ecartWeights,(pVariables+1)*sizeof(short));
1449      ecartWeights=NULL;
1450    }
1451  }
1452  idDelete(&strat->Shdl);
1453  test=save_test;
1454  if (TEST_OPT_PROT) PrintLn();
1455  return p;
1456}
1457
1458ideal kNF1 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce)
1459{
1460  poly   p;
1461  int   i;
1462  int   j;
1463  int   o;
1464  LObject   h;
1465  ideal res;
1466  BITSET save_test=test;
1467
1468  if (idIs0(q)) return idInit(IDELEMS(q),q->rank);
1469  if ((idIs0(F))&&(Q==NULL))
1470    return idCopy(q); /*F=0*/
1471  strat->ak = si_max(idRankFreeModule(F),idRankFreeModule(q));
1472  /*- creating temp data structures------------------- -*/
1473  strat->kHEdgeFound = ppNoether != NULL;
1474  strat->kNoether=pCopy(ppNoether);
1475  test|=Sy_bit(OPT_REDTAIL);
1476  if (TEST_OPT_STAIRCASEBOUND
1477  && (0<Kstd1_deg)
1478  && ((!strat->kHEdgeFound)
1479    ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg))))
1480  {
1481    pDelete(&strat->kNoether);
1482    strat->kNoether=pOne();
1483    pSetExp(strat->kNoether,1, Kstd1_deg+1);
1484    pSetm(strat->kNoether);
1485    strat->kHEdgeFound=TRUE;
1486  }
1487  initBuchMoraCrit(strat);
1488  initBuchMoraPos(strat);
1489  initMora(F,strat);
1490  strat->enterS = enterSMoraNF;
1491  /*- set T -*/
1492  strat->tl = -1;
1493  strat->tmax = setmaxT;
1494  strat->T = initT();
1495  strat->R = initR();
1496  strat->sevT = initsevT();
1497  /*- set S -*/
1498  strat->sl = -1;
1499  /*- init local data struct.-------------------------- -*/
1500  /*Shdl=*/initS(F,Q,strat);
1501  if ((strat->ak!=0)
1502  && (strat->kHEdgeFound))
1503  {
1504    if (strat->ak!=1)
1505    {
1506      pSetComp(strat->kNoether,1);
1507      pSetmComp(strat->kNoether);
1508      poly p=pHead(strat->kNoether);
1509      pSetComp(p,strat->ak);
1510      pSetmComp(p);
1511      p=pAdd(strat->kNoether,p);
1512      strat->kNoether=pNext(p);
1513      p_LmFree(p,currRing);
1514    }
1515  }
1516  if (TEST_OPT_INTSTRATEGY && ((lazyReduce & 1)==0))
1517  {
1518    for (i=strat->sl; i>=0; i--)
1519      pNorm(strat->S[i]);
1520  }
1521  /*- compute------------------------------------------- -*/
1522  res=idInit(IDELEMS(q),q->rank);
1523  for (i=0; i<IDELEMS(q); i++)
1524  {
1525    if (q->m[i]!=NULL)
1526    {
1527      p = pCopy(q->m[i]);
1528      deleteHC(&p,&o,&j,strat);
1529      if (p!=NULL)
1530      {
1531        /*- puts the elements of S also to T -*/
1532        for (j=0; j<=strat->sl; j++)
1533        {
1534          h.p = strat->S[j];
1535          h.ecart = strat->ecartS[j];
1536          h.pLength = h.length = pLength(h.p);
1537          if (strat->sevS[j] == 0) strat->sevS[j] = pGetShortExpVector(h.p);
1538          else assume(strat->sevS[j] == pGetShortExpVector(h.p));
1539          h.sev = strat->sevS[j];
1540          h.SetpFDeg();
1541          enterT(h,strat);
1542        }
1543        if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
1544        p = redMoraNF(p,strat, lazyReduce & 2);
1545        if ((p!=NULL)&&((lazyReduce & 1)==0))
1546        {
1547          if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1548          p = redtail(p,strat->sl,strat);
1549        }
1550        cleanT(strat);
1551      }
1552      res->m[i]=p;
1553    }
1554    //else
1555    //  res->m[i]=NULL;
1556  }
1557  /*- release temp data------------------------------- -*/
1558  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
1559  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1560  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
1561  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1562  omfree(strat->sevT);
1563  omfree(strat->S_2_R);
1564  omfree(strat->R);
1565  if ((Q!=NULL)&&(strat->fromQ!=NULL))
1566  {
1567    i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
1568    omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
1569    strat->fromQ=NULL;
1570  }
1571  pDelete(&strat->kHEdge);
1572  pDelete(&strat->kNoether);
1573  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1574  {
1575    pFDeg=pFDegOld;
1576    pLDeg=pLDegOld;
1577    if (ecartWeights)
1578    {
1579      omFreeSize((ADDRESS *)&ecartWeights,(pVariables+1)*sizeof(short));
1580      ecartWeights=NULL;
1581    }
1582  }
1583  idDelete(&strat->Shdl);
1584  test=save_test;
1585  if (TEST_OPT_PROT) PrintLn();
1586  return res;
1587}
1588
1589pFDegProc pFDegOld;
1590pLDegProc pLDegOld;
1591intvec * kModW, * kHomW;
1592
1593long kModDeg(poly p, ring r)
1594{
1595  long o=pWDegree(p, r);
1596  long i=p_GetComp(p, r);
1597  if (i==0) return o;
1598  assume((i>0) && (i<=kModW->length()));
1599  return o+(*kModW)[i-1];
1600}
1601long kHomModDeg(poly p, ring r)
1602{
1603  int i;
1604  long j=0;
1605
1606  for (i=r->N;i>0;i--)
1607    j+=p_GetExp(p,i,r)*(*kHomW)[i-1];
1608  if (kModW == NULL) return j;
1609  i = p_GetComp(p,r);
1610  if (i==0) return j;
1611  return j+(*kModW)[i-1];
1612}
1613
1614ideal kStd(ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp,
1615          int newIdeal, intvec *vw)
1616{
1617  ideal r;
1618  BOOLEAN b=pLexOrder,toReset=FALSE;
1619  BOOLEAN delete_w=(w==NULL);
1620  kStrategy strat=new skStrategy;
1621
1622  if(!TEST_OPT_RETURN_SB)
1623    strat->syzComp = syzComp;
1624  if (TEST_OPT_SB_1)
1625    strat->newIdeal = newIdeal;
1626  if (rField_has_simple_inverse())
1627    strat->LazyPass=20;
1628  else
1629    strat->LazyPass=2;
1630  strat->LazyDegree = 1;
1631  strat->ak = idRankFreeModule(F);
1632  strat->kModW=kModW=NULL;
1633  strat->kHomW=kHomW=NULL;
1634  if (vw != NULL)
1635  {
1636    pLexOrder=FALSE;
1637    strat->kHomW=kHomW=vw;
1638    pFDegOld = pFDeg;
1639    pLDegOld = pLDeg;
1640    pSetDegProcs(kHomModDeg);
1641    toReset = TRUE;
1642  }
1643  if (h==testHomog)
1644  {
1645    if (strat->ak == 0)
1646    {
1647      h = (tHomog)idHomIdeal(F,Q);
1648      w=NULL;
1649    }
1650    else if (!TEST_OPT_DEGBOUND)
1651    {
1652      h = (tHomog)idHomModule(F,Q,w);
1653    }
1654  }
1655  pLexOrder=b;
1656  if (h==isHomog)
1657  {
1658    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
1659    {
1660      strat->kModW = kModW = *w;
1661      if (vw == NULL)
1662      {
1663        pFDegOld = pFDeg;
1664        pLDegOld = pLDeg;
1665        pSetDegProcs(kModDeg);
1666        toReset = TRUE;
1667      }
1668    }
1669    pLexOrder = TRUE;
1670    if (hilb==NULL) strat->LazyPass*=2;
1671  }
1672  strat->homog=h;
1673#ifdef KDEBUG
1674  idTest(F);
1675#endif
1676#ifdef HAVE_PLURAL
1677  if (rIsPluralRing(currRing))
1678  {
1679    if (w!=NULL)
1680      r = nc_GB(F, Q, *w, hilb, strat);
1681    else
1682      r = nc_GB(F, Q, NULL, hilb, strat);
1683  }
1684  else
1685#endif
1686  {
1687    if (pOrdSgn==-1)
1688    {
1689      if (w!=NULL)
1690        r=mora(F,Q,*w,hilb,strat);
1691      else
1692        r=mora(F,Q,NULL,hilb,strat);
1693    }
1694    else
1695    {
1696      if (w!=NULL)
1697        r=bba(F,Q,*w,hilb,strat);
1698      else
1699        r=bba(F,Q,NULL,hilb,strat);
1700    }
1701  }
1702#ifdef KDEBUG
1703  idTest(r);
1704#endif
1705  if (toReset)
1706  {
1707    kModW = NULL;
1708    pRestoreDegProcs(pFDegOld, pLDegOld);
1709  }
1710  pLexOrder = b;
1711//Print("%d reductions canceled \n",strat->cel);
1712  HCord=strat->HCord;
1713  delete(strat);
1714  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
1715  return r;
1716}
1717
1718//##############################################################
1719//##############################################################
1720//##############################################################
1721//##############################################################
1722//##############################################################
1723
1724ideal kMin_std(ideal F, ideal Q, tHomog h,intvec ** w, ideal &M, intvec *hilb,
1725              int syzComp, int reduced)
1726{
1727  ideal r=NULL;
1728  int Kstd1_OldDeg = Kstd1_deg,i;
1729  intvec* temp_w=NULL;
1730  BOOLEAN b=pLexOrder,toReset=FALSE;
1731  BOOLEAN delete_w=(w==NULL);
1732  BOOLEAN oldDegBound=TEST_OPT_DEGBOUND;
1733  kStrategy strat=new skStrategy;
1734
1735  if(!TEST_OPT_RETURN_SB)
1736     strat->syzComp = syzComp;
1737  if (rField_has_simple_inverse())
1738    strat->LazyPass=20;
1739  else
1740    strat->LazyPass=2;
1741  strat->LazyDegree = 1;
1742  strat->minim=(reduced % 2)+1;
1743  strat->ak = idRankFreeModule(F);
1744  if (delete_w)
1745  {
1746    temp_w=new intvec((strat->ak)+1);
1747    w = &temp_w;
1748  }
1749  if ((h==testHomog)
1750  )
1751  {
1752    if (strat->ak == 0)
1753    {
1754      h = (tHomog)idHomIdeal(F,Q);
1755      w=NULL;
1756    }
1757    else
1758    {
1759      h = (tHomog)idHomModule(F,Q,w);
1760    }
1761  }
1762  if (h==isHomog)
1763  {
1764    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
1765    {
1766      kModW = *w;
1767      strat->kModW = *w;
1768      assume(pFDeg != NULL && pLDeg != NULL);
1769      pFDegOld = pFDeg;
1770      pLDegOld = pLDeg;
1771      pSetDegProcs(kModDeg);
1772
1773      toReset = TRUE;
1774      if (reduced>1)
1775      {
1776        Kstd1_OldDeg=Kstd1_deg;
1777        Kstd1_deg = -1;
1778        for (i=IDELEMS(F)-1;i>=0;i--)
1779        {
1780          if ((F->m[i]!=NULL) && (pFDeg(F->m[i],currRing)>=Kstd1_deg))
1781            Kstd1_deg = pFDeg(F->m[i],currRing)+1;
1782        }
1783      }
1784    }
1785    pLexOrder = TRUE;
1786    strat->LazyPass*=2;
1787  }
1788  strat->homog=h;
1789  if (pOrdSgn==-1)
1790  {
1791    if (w!=NULL)
1792      r=mora(F,Q,*w,hilb,strat);
1793    else
1794      r=mora(F,Q,NULL,hilb,strat);
1795  }
1796  else
1797  {
1798    if (w!=NULL)
1799      r=bba(F,Q,*w,hilb,strat);
1800    else
1801      r=bba(F,Q,NULL,hilb,strat);
1802  }
1803#ifdef KDEBUG
1804  {
1805    int i;
1806    for (i=IDELEMS(r)-1; i>=0; i--) pTest(r->m[i]);
1807  }
1808#endif
1809  idSkipZeroes(r);
1810  if (toReset)
1811  {
1812    pRestoreDegProcs(pFDegOld, pLDegOld);
1813    kModW = NULL;
1814  }
1815  pLexOrder = b;
1816  HCord=strat->HCord;
1817  if ((delete_w)&&(temp_w!=NULL)) delete temp_w;
1818  if ((IDELEMS(r)==1) && (r->m[0]!=NULL) && pIsConstant(r->m[0]) && (strat->ak==0))
1819  {
1820    M=idInit(1,F->rank);
1821    M->m[0]=pOne();
1822    //if (strat->ak!=0) { pSetComp(M->m[0],strat->ak); pSetmComp(M->m[0]); }
1823    if (strat->M!=NULL) idDelete(&strat->M);
1824  }
1825  else
1826  if (strat->M==NULL)
1827  {
1828    M=idInit(1,F->rank);
1829    Warn("no minimal generating set computed");
1830  }
1831  else
1832  {
1833    idSkipZeroes(strat->M);
1834    M=strat->M;
1835  }
1836  delete(strat);
1837  if (reduced>2)
1838  {
1839    Kstd1_deg=Kstd1_OldDeg;
1840    if (!oldDegBound)
1841      test &= ~Sy_bit(OPT_DEGBOUND);
1842  }
1843  return r;
1844}
1845
1846poly kNF(ideal F, ideal Q, poly p,int syzComp, int lazyReduce)
1847{
1848  if (p==NULL)
1849     return NULL;
1850  kStrategy strat=new skStrategy;
1851  strat->syzComp = syzComp;
1852  if (pOrdSgn==-1)
1853    p=kNF1(F,Q,p,strat,lazyReduce);
1854  else
1855    p=kNF2(F,Q,p,strat,lazyReduce);
1856  delete(strat);
1857  return p;
1858}
1859
1860ideal kNF(ideal F, ideal Q, ideal p,int syzComp,int lazyReduce)
1861{
1862  ideal res;
1863  if (TEST_OPT_PROT)
1864  {
1865    Print("(S:%d)",IDELEMS(p));mflush();
1866  }
1867  kStrategy strat=new skStrategy;
1868  strat->syzComp = syzComp;
1869  if (pOrdSgn==-1)
1870    res=kNF1(F,Q,p,strat,lazyReduce);
1871  else
1872    res=kNF2(F,Q,p,strat,lazyReduce);
1873  delete(strat);
1874  return res;
1875}
1876
1877/*2
1878*interreduces F
1879*/
1880#if 0
1881// new version
1882ideal kInterRed (ideal F, ideal Q)
1883{
1884  int   srmax,lrmax, red_result = 1;
1885  int   olddeg,reduc,j;
1886  BOOLEAN need_update=FALSE;
1887
1888  kStrategy strat = new skStrategy;
1889  strat->kHEdgeFound = ppNoether != NULL;
1890  strat->kNoether=pCopy(ppNoether);
1891  strat->ak = idRankFreeModule(F);
1892  initBuchMoraCrit(strat);
1893  initBuchMoraPos(strat);
1894  strat->NotUsedAxis = (BOOLEAN *)omAlloc((pVariables+1)*sizeof(BOOLEAN));
1895  for (j=pVariables; j>0; j--) strat->NotUsedAxis[j] = TRUE;
1896  strat->enterS      = enterSBba;
1897  strat->posInT      = posInT17;
1898  strat->initEcart   = initEcartNormal;
1899  strat->sl          = -1;
1900  strat->tl          = -1;
1901  strat->Ll          = -1;
1902  strat->tmax        = setmaxT;
1903  strat->Lmax        = setmaxL;
1904  strat->T           = initT();
1905  strat->R           = initR();
1906  strat->L           = initL();
1907  strat->sevT        = initsevT();
1908  strat->red         = redLazy;
1909#ifdef HAVE_RINGS  //TODO Oliver
1910  if (rField_is_Ring(currRing)) {
1911    strat->red = redRing2toM;
1912  }
1913#endif
1914  strat->tailRing    = currRing;
1915  if (pOrdSgn == -1)
1916    strat->honey = TRUE;
1917  initSL(F,Q,strat);
1918  for(j=strat->Ll; j>=0; j--)
1919    strat->L[j].tailRing=currRing;
1920  if (TEST_OPT_REDSB)
1921    strat->noTailReduction=FALSE;
1922
1923  srmax = strat->sl;
1924  reduc = olddeg = lrmax = 0;
1925
1926#ifndef NO_BUCKETS
1927  if (!TEST_OPT_NOT_BUCKETS)
1928    strat->use_buckets = 1;
1929#endif
1930
1931  // strat->posInT = posInT_pLength;
1932  kTest_TS(strat);
1933
1934  /* compute------------------------------------------------------- */
1935  while (strat->Ll >= 0)
1936  {
1937    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
1938#ifdef KDEBUG
1939    if (TEST_OPT_DEBUG) messageSets(strat);
1940#endif
1941    if (strat->Ll== 0) strat->interpt=TRUE;
1942    /* picks the last element from the lazyset L */
1943    strat->P = strat->L[strat->Ll];
1944    strat->Ll--;
1945
1946    // for input polys, prepare reduction
1947    strat->P.PrepareRed(strat->use_buckets);
1948
1949    if (strat->P.p == NULL && strat->P.t_p == NULL)
1950    {
1951      red_result = 0;
1952    }
1953    else
1954    {
1955      if (TEST_OPT_PROT)
1956        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
1957                &olddeg,&reduc,strat, red_result);
1958
1959      /* reduction of the element choosen from L */
1960      red_result = strat->red(&strat->P,strat);
1961    }
1962
1963    // reduction to non-zero new poly
1964    if (red_result == 1)
1965    {
1966      /* statistic */
1967      if (TEST_OPT_PROT) PrintS("s");
1968
1969      // get the polynomial (canonicalize bucket, make sure P.p is set)
1970      strat->P.GetP(strat->lmBin);
1971
1972      int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
1973
1974      // reduce the tail and normalize poly
1975      if (TEST_OPT_INTSTRATEGY)
1976      {
1977        strat->P.pCleardenom();
1978        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
1979        {
1980          strat->P.p = redtailBba(&(strat->P),pos-1,strat, FALSE);
1981          strat->P.pCleardenom();
1982        }
1983      }
1984      else
1985      {
1986        strat->P.pNorm();
1987        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
1988          strat->P.p = redtailBba(&(strat->P),pos-1,strat, FALSE);
1989      }
1990
1991#ifdef KDEBUG
1992      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
1993#endif
1994
1995      // enter into S, L, and T
1996      enterT(strat->P, strat);
1997      // posInS only depends on the leading term
1998      strat->enterS(strat->P, pos, strat, strat->tl);
1999      if (pos<strat->sl)
2000      {
2001        need_update=TRUE;
2002#if 0
2003        LObject h;
2004        for(j=strat->sl;j>pos;j--)
2005        {
2006          if (TEST_OPT_PROT) { PrintS("+"); mflush(); }
2007          memset(&h, 0, sizeof(h));
2008          h.p=strat->S[j];
2009          int i;
2010          for(i=strat->tl;i>=0;i--)
2011          {
2012            if (pLmCmp(h.p,strat->T[i].p)==0)
2013            {
2014              if (i < strat->tl)
2015              {
2016#ifdef ENTER_USE_MEMMOVE
2017                memmove(&(strat->T[i]), &(strat->T[i+1]),
2018                   (strat->tl-i)*sizeof(TObject));
2019                memmove(&(strat->sevT[i]), &(strat->sevT[i+1]),
2020                   (strat->tl-i)*sizeof(unsigned long));
2021#endif
2022                for (int l=i; l<strat->tl; l++)
2023                {
2024#ifndef ENTER_USE_MEMMOVE
2025                  strat->T[l] = strat->T[l+1];
2026                  strat->sevT[l] = strat->sevT[l+1];
2027#endif
2028                  strat->R[strat->T[l].i_r] = &(strat->T[l]);
2029                }
2030              }
2031              strat->tl--;
2032              break;
2033            }
2034          }
2035          strat->S[j]=NULL;
2036          strat->sl--;
2037          if (TEST_OPT_INTSTRATEGY)
2038          {
2039            //pContent(h.p);
2040            h.pCleardenom(); // also does a pContent
2041          }
2042          else
2043          {
2044            h.pNorm();
2045          }
2046          strat->initEcart(&h);
2047                    if (strat->Ll==-1)
2048            pos =0;
2049          else
2050            pos = strat->posInL(strat->L,strat->Ll,&h,strat);
2051          h.sev = pGetShortExpVector(h.p);
2052          enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
2053        }
2054#endif
2055      }
2056      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
2057      if (strat->sl>srmax) srmax = strat->sl;
2058    }
2059#ifdef KDEBUG
2060    memset(&(strat->P), 0, sizeof(strat->P));
2061#endif
2062    kTest_TS(strat);
2063  }
2064#ifdef KDEBUG
2065  if (TEST_OPT_DEBUG) messageSets(strat);
2066#endif
2067  /* complete reduction of the standard basis--------- */
2068  if (TEST_OPT_REDSB)
2069  {
2070    completeReduce(strat);
2071    if (strat->completeReduce_retry)
2072    {
2073      // completeReduce needed larger exponents, retry
2074      // to reduce with S (instead of T)
2075      // and in currRing (instead of strat->tailRing)
2076      cleanT(strat);strat->tailRing=currRing;
2077      int i;
2078      for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
2079      completeReduce(strat);
2080    }
2081  }
2082
2083  /* release temp data-------------------------------- */
2084  if (TEST_OPT_PROT) messageStat(srmax,lrmax,0,strat);
2085  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
2086  ideal shdl=strat->Shdl;
2087  idSkipZeroes(shdl);
2088  pDelete(&strat->kHEdge);
2089  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
2090  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
2091  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
2092  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
2093  omFreeSize((ADDRESS)strat->L,(strat->Lmax)*sizeof(LObject));
2094  omfree(strat->sevT);
2095  omfree(strat->S_2_R);
2096  omfree(strat->R);
2097
2098  if (strat->fromQ)
2099  {
2100    for (j=IDELEMS(strat->Shdl)-1;j>=0;j--)
2101    {
2102      if(strat->fromQ[j]) pDelete(&strat->Shdl->m[j]);
2103    }
2104    omFreeSize((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
2105    strat->fromQ=NULL;
2106  }
2107  delete(strat);
2108#if 0
2109  if (need_update)
2110  {
2111    ideal res=kInterRed(shdl,Q);
2112    idDelete(&shdl);
2113    shdl=res;
2114  }
2115#endif
2116  return shdl;
2117}
2118#else
2119// old version
2120ideal kInterRed (ideal F, ideal Q)
2121{
2122  int j;
2123  kStrategy strat = new skStrategy;
2124
2125//  if (TEST_OPT_PROT)
2126//  {
2127//    writeTime("start InterRed:");
2128//    mflush();
2129//  }
2130  //strat->syzComp     = 0;
2131  strat->kHEdgeFound = ppNoether != NULL;
2132  strat->kNoether=pCopy(ppNoether);
2133  strat->ak = idRankFreeModule(F);
2134  initBuchMoraCrit(strat);
2135  strat->NotUsedAxis = (BOOLEAN *)omAlloc((pVariables+1)*sizeof(BOOLEAN));
2136  for (j=pVariables; j>0; j--) strat->NotUsedAxis[j] = TRUE;
2137  strat->enterS      = enterSBba;
2138  strat->posInT      = posInT17;
2139  strat->initEcart   = initEcartNormal;
2140  strat->sl   = -1;
2141  strat->tl          = -1;
2142  strat->tmax        = setmaxT;
2143  strat->T           = initT();
2144  strat->R           = initR();
2145  strat->sevT        = initsevT();
2146  if (pOrdSgn == -1)   strat->honey = TRUE;
2147  initS(F,Q,strat);
2148  if (TEST_OPT_REDSB)
2149    strat->noTailReduction=FALSE;
2150  updateS(TRUE,strat);
2151  if (TEST_OPT_REDSB && TEST_OPT_INTSTRATEGY)
2152    completeReduce(strat);
2153  pDelete(&strat->kHEdge);
2154  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
2155  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
2156  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
2157  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
2158  omfree(strat->sevT);
2159  omfree(strat->S_2_R);
2160  omfree(strat->R);
2161
2162  if (strat->fromQ)
2163  {
2164    for (j=IDELEMS(strat->Shdl)-1;j>=0;j--)
2165    {
2166      if(strat->fromQ[j]) pDelete(&strat->Shdl->m[j]);
2167    }
2168    omFreeSize((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
2169    strat->fromQ=NULL;
2170  }
2171//  if (TEST_OPT_PROT)
2172//  {
2173//    writeTime("end Interred:");
2174//    mflush();
2175//  }
2176  ideal shdl=strat->Shdl;
2177  idSkipZeroes(shdl);
2178  delete(strat);
2179  return shdl;
2180}
2181#endif
2182
2183// returns TRUE if mora should use buckets, false otherwise
2184static BOOLEAN kMoraUseBucket(kStrategy strat)
2185{
2186#ifdef MORA_USE_BUCKETS
2187  if (TEST_OPT_NOT_BUCKETS)
2188    return FALSE;
2189  if (strat->red == redFirst)
2190  {
2191#ifdef NO_LDEG
2192    if (strat->syzComp==0)
2193      return TRUE;
2194#else
2195    if ((strat->homog || strat->honey) && (strat->syzComp==0))
2196      return TRUE;
2197#endif
2198  }
2199  else
2200  {
2201    assume(strat->red == redEcart);
2202    if (strat->honey && (strat->syzComp==0))
2203      return TRUE;
2204  }
2205#endif
2206  return FALSE;
2207}
Note: See TracBrowser for help on using the repository browser.