source: git/kernel/kstd1.cc @ 1c473f

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