source: git/kernel/kstd1.cc @ a6889e

fieker-DuValspielwiese
Last change on this file since a6889e was 585bbcb, checked in by Oliver Wienand <wienand@…>, 18 years ago
Makefile.in: --> rmodulo2m.[h/cc] in HEADERS / CXXSOURCES eingetragen kspoly.cc: --> ksReducePoly beachtet Nullteiler --> ksRingReducePoly (neu) --> ksCreateSpoly beachtet Nullteiler kstd1.cc: --> use strat->red = redRing2toM if currRing->cring == 1 kstd2.cc: --> kRingFindDivisibleByInT (neu) --> kRingFindDivisibleByInS (neu) --> redRing2toM (neu) kutil.cc: --> kRingFindDivisibleByInS (neu) --> redTailBba beachtet Nullteiler und andere Strategien (zum Teil) kutil.h: --> int redRing2toM (LObject* h,kStrategy strat); (neu) --> Dekl. von kRingFind* und ksRingReducePoly numbers.cc: --> Unterstützung für Z/2^m pDebug.cc: --> p_DebugLmDivisibleByNoComp beachtet coeff für Ringe pInline1.h: --> *LmRing* Teilbarkeit mit Beachtung des Koeff p_Minus_mm_Mult_qq__T.cc: --> Term*Term = 0 möglich polys.cc: --> nGetUnit (neu) --> pNorm beachtet Nullteiler polys.h: --> nGetUnit (neu) polys1.cc: --> pCleardenom: in case of ring, just do a pNorm --> pContent: in case of ring do nothing pp_Mult_mm__T.cc: --> Term*Term = 0 möglich bei KoeffRing ring.cc: --> rSetOption: setze intStrategy ring.h: --> rField_is_Ring_2toM (neu) --> alle anderen Fkt. angepasst ringgb.cc, ringgb.h: test container in Zshg. mit extra.cc structs.h: --> ring->cring property (neu) cring = 0 bei Körpern, cring = 1 bei Z/2^m git-svn-id: file:///usr/local/Singular/svn/trunk@8813 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 49.1 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kstd1.cc,v 1.9 2005-11-27 15:28:44 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
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    /*- try to reduce the s-polynomial -*/
280    pass++;
281    d = h->GetpFDeg()+h->ecart;
282    /*
283     *test whether the polynomial should go to the lazyset L
284     *-if the degree jumps
285     *-if the number of pre-defined reductions jumps
286     */
287    if (!K_TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
288        && ((d >= reddeg) || (pass > strat->LazyPass)))
289    {
290      h->SetLmCurrRing();
291      if (strat->honey && strat->posInLDependsOnLength)
292        h->SetLength(strat->length_pLength);
293      assume(h->FDeg == h->pFDeg());
294      at = strat->posInL(strat->L,strat->Ll,h,strat);
295      if (at <= strat->Ll)
296      {
297        if (kFindDivisibleByInS(strat->S, strat->sevS, strat->sl, h) < 0)
298        {
299          if (strat->honey && !strat->posInLDependsOnLength)
300            h->SetLength(strat->length_pLength);
301          return 1;
302        }
303        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
304#ifdef KDEBUG
305        if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
306#endif
307        h->Clear();
308        return -1;
309      }
310    }
311    else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
312    {
313      Print(".%d",d);mflush();
314      reddeg = d+1;
315    }
316  }
317}
318
319/*2
320*reduces h with elements from T choosing  the first possible
321* element in t with respect to the given pDivisibleBy
322*/
323int redFirst (LObject* h,kStrategy strat)
324{
325  if (h->IsNull()) return 0;
326
327  int at, reddeg,d;
328  int pass = 0;
329  int j = 0;
330
331  if (! strat->homog)
332  {
333    d = h->GetpFDeg() + h->ecart;
334    reddeg = strat->LazyDegree+d;
335  }
336  h->SetShortExpVector();
337  while (1)
338  {
339    j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h);
340    if (j < 0)
341    {
342      h->SetDegStuffReturnLDeg(strat->LDegLast);
343      return 1;
344    }
345
346    if (!TEST_OPT_INTSTRATEGY)
347      strat->T[j].pNorm();
348#ifdef KDEBUG
349    if (TEST_OPT_DEBUG)
350    {
351      PrintS("reduce ");
352      h->wrp();
353      PrintS(" with ");
354      strat->T[j].wrp();
355    }
356#endif
357    ksReducePoly(h, &(strat->T[j]), strat->kNoetherTail(), NULL, strat);
358#ifdef KDEBUG
359    if (TEST_OPT_DEBUG)
360    {
361      PrintS(" to ");
362      wrp(h->p);
363      PrintLn();
364    }
365#endif
366    if (h->IsNull())
367    {
368      if (h->lcm!=NULL) pLmFree(h->lcm);
369      h->Clear();
370      return 0;
371    }
372    h->SetShortExpVector();
373
374    if ((strat->syzComp!=0) && !strat->honey)
375    {
376      if ((strat->syzComp>0) &&
377          (h->Comp() > strat->syzComp))
378      {
379        assume(h->MinComp() > strat->syzComp);
380#ifdef KDEBUG
381        if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
382#endif
383        if (strat->homog)
384          h->SetDegStuffReturnLDeg(strat->LDegLast);
385        return -2;
386      }
387    }
388    if (!strat->homog)
389    {
390      if (!K_TEST_OPT_OLDSTD && strat->honey)
391      {
392        h->SetpFDeg();
393        if (strat->T[j].ecart <= h->ecart)
394          h->ecart = d - h->GetpFDeg();
395        else
396          h->ecart = d - h->GetpFDeg() + strat->T[j].ecart - h->ecart;
397
398        d = h->GetpFDeg() + h->ecart;
399      }
400      else
401        d = h->SetDegStuffReturnLDeg(strat->LDegLast);
402      /*- try to reduce the s-polynomial -*/
403      pass++;
404      /*
405       *test whether the polynomial should go to the lazyset L
406       *-if the degree jumps
407       *-if the number of pre-defined reductions jumps
408       */
409      if (!K_TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
410          && ((d >= reddeg) || (pass > strat->LazyPass)))
411      {
412        h->SetLmCurrRing();
413        if (strat->posInLDependsOnLength)
414          h->SetLength(strat->length_pLength);
415        at = strat->posInL(strat->L,strat->Ll,h,strat);
416        if (at <= strat->Ll)
417        {
418          if (kFindDivisibleByInS(strat->S, strat->sevS, strat->sl, h) < 0)
419            return 1;
420          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
421#ifdef KDEBUG
422          if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
423#endif
424          h->Clear();
425          return -1;
426        }
427      }
428      if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
429      {
430        reddeg = d+1;
431        Print(".%d",d);mflush();
432      }
433    }
434  }
435}
436
437/*2
438* reduces h with elements from T choosing first possible
439* element in T with respect to the given ecart
440* used for computing normal forms outside kStd
441*/
442static poly redMoraNF (poly h,kStrategy strat, int flag)
443{
444  LObject H;
445  H.p = h;
446  int j = 0;
447  int z = 10;
448  int o = H.SetpFDeg();
449  H.ecart = pLDeg(H.p,&H.length,currRing)-o;
450  if ((flag & 2) == 0) cancelunit(&H);
451  H.sev = pGetShortExpVector(H.p);
452  unsigned long not_sev = ~ H.sev;
453  loop
454  {
455    if (j > strat->tl)
456    {
457      return H.p;
458    }
459    if (TEST_V_DEG_STOP)
460    {
461      if (kModDeg(H.p)>Kstd1_deg) pDeleteLm(&H.p);
462      if (H.p==NULL) return NULL;
463    }
464    if (p_LmShortDivisibleBy(strat->T[j].GetLmTailRing(), strat->sevT[j], H.GetLmTailRing(), not_sev, strat->tailRing))
465    {
466      //if (strat->interpt) test_int_std(strat->kIdeal);
467      /*- remember the found T-poly -*/
468      poly pi = strat->T[j].p;
469      int ei = strat->T[j].ecart;
470      int li = strat->T[j].length;
471      int ii = j;
472      /*
473      * the polynomial to reduce with (up to the moment) is;
474      * pi with ecart ei and length li
475      */
476      loop
477      {
478        /*- look for a better one with respect to ecart -*/
479        /*- stop, if the ecart is small enough (<=ecart(H)) -*/
480        j++;
481        if (j > strat->tl) break;
482        if (ei <= H.ecart) break;
483        if (((strat->T[j].ecart < ei)
484          || ((strat->T[j].ecart == ei)
485        && (strat->T[j].length < li)))
486        && pLmShortDivisibleBy(strat->T[j].p,strat->sevT[j], H.p, not_sev))
487        {
488          /*
489          * the polynomial to reduce with is now;
490          */
491          pi = strat->T[j].p;
492          ei = strat->T[j].ecart;
493          li = strat->T[j].length;
494          ii = j;
495        }
496      }
497      /*
498      * end of search: have to reduce with pi
499      */
500      z++;
501      if (z>10)
502      {
503        pNormalize(H.p);
504        z=0;
505      }
506      if ((ei > H.ecart) && (!strat->kHEdgeFound))
507      {
508        /*
509        * It is not possible to reduce h with smaller ecart;
510        * we have to reduce with bad ecart: H has to enter in T
511        */
512        doRed(&H,&(strat->T[ii]),TRUE,strat);
513        if (H.p == NULL)
514          return NULL;
515      }
516      else
517      {
518        /*
519        * we reduce with good ecart, h need not to be put to T
520        */
521        doRed(&H,&(strat->T[ii]),FALSE,strat);
522        if (H.p == NULL)
523          return NULL;
524      }
525      /*- try to reduce the s-polynomial -*/
526      o = H.SetpFDeg();
527      if ((flag &2 ) == 0) cancelunit(&H);
528      H.ecart = pLDeg(H.p,&(H.length),currRing)-o;
529      j = 0;
530      H.sev = pGetShortExpVector(H.p);
531      not_sev = ~ H.sev;
532    }
533    else
534    {
535      j++;
536    }
537  }
538}
539
540/*2
541*reorders  L with respect to posInL
542*/
543void reorderL(kStrategy strat)
544{
545  int i,j,at;
546  LObject p;
547
548  for (i=1; i<=strat->Ll; i++)
549  {
550    at = strat->posInL(strat->L,i-1,&(strat->L[i]),strat);
551    if (at != i)
552    {
553      p = strat->L[i];
554      for (j=i-1; j>=at; j--) strat->L[j+1] = strat->L[j];
555      strat->L[at] = p;
556    }
557  }
558}
559
560/*2
561*reorders  T with respect to length
562*/
563void reorderT(kStrategy strat)
564{
565  int i,j,at;
566  TObject p;
567  unsigned long sev;
568
569
570  for (i=1; i<=strat->tl; i++)
571  {
572    if (strat->T[i-1].length > strat->T[i].length)
573    {
574      p = strat->T[i];
575      sev = strat->sevT[i];
576      at = i-1;
577      loop
578      {
579        at--;
580        if (at < 0) break;
581        if (strat->T[i].length > strat->T[at].length) break;
582      }
583      for (j = i-1; j>at; j--)
584      {
585        strat->T[j+1]=strat->T[j];
586        strat->sevT[j+1]=strat->sevT[j];
587        strat->R[strat->T[j+1].i_r] = &(strat->T[j+1]);
588      }
589      strat->T[at+1]=p;
590      strat->sevT[at+1] = sev;
591      strat->R[p.i_r] = &(strat->T[at+1]);
592    }
593  }
594}
595
596/*2
597*looks whether exactly pVariables-1 axis are used
598*returns last != 0 in this case
599*last is the (first) unused axis
600*/
601void missingAxis (int* last,kStrategy strat)
602{
603  int   i = 0;
604  int   k = 0;
605
606  *last = 0;
607  if (!currRing->MixedOrder)
608  {
609    loop
610    {
611      i++;
612      if (i > pVariables) break;
613      if (strat->NotUsedAxis[i])
614      {
615        *last = i;
616        k++;
617      }
618      if (k>1)
619      {
620        *last = 0;
621        break;
622      }
623    }
624  }
625}
626
627/*2
628*last is the only non used axis, it looks
629*for a monomial in p being a pure power of this
630*variable and returns TRUE in this case
631*(*length) gives the length between the pure power and the leading term
632*(should be minimal)
633*/
634BOOLEAN hasPurePower (const poly p,int last, int *length,kStrategy strat)
635{
636  poly h;
637  int i;
638
639  if (pNext(p) == strat->tail)
640    return FALSE;
641  pp_Test(p, currRing, strat->tailRing);
642  if (strat->ak <= 0 || p_MinComp(p, currRing, strat->tailRing) == strat->ak)
643  {
644    i = p_IsPurePower(p, currRing);
645    if (i == last)
646    {
647      *length = 0;
648      return TRUE;
649    }
650    *length = 1;
651    h = pNext(p);
652    while (h != NULL)
653    {
654      i = p_IsPurePower(h, strat->tailRing);
655      if (i==last) return TRUE;
656      (*length)++;
657      pIter(h);
658    }
659  }
660  return FALSE;
661}
662
663BOOLEAN hasPurePower (LObject *L,int last, int *length,kStrategy strat)
664{
665  if (L->bucket != NULL)
666  {
667    poly p = L->CanonicalizeP();
668    BOOLEAN ret = hasPurePower(p, last, length, strat);
669    pNext(p) = NULL;
670    return ret;
671  }
672  else
673  {
674    return hasPurePower(L->p, last, length, strat);
675  }
676}
677
678/*2
679* looks up the position of polynomial p in L
680* in the case of looking for the pure powers
681*/
682int posInL10 (const LSet set,const int length, LObject* p,const kStrategy strat)
683{
684  int j,dp,dL;
685
686  if (length<0) return 0;
687  if (hasPurePower(p,strat->lastAxis,&dp,strat))
688  {
689    int op= p->GetpFDeg() +p->ecart;
690    for (j=length; j>=0; j--)
691    {
692      if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat))
693        return j+1;
694      if (dp < dL)
695        return j+1;
696      if ((dp == dL)
697          && (set[j].GetpFDeg()+set[j].ecart >= op))
698        return j+1;
699    }
700  }
701  j=length;
702  loop
703  {
704    if (j<0) break;
705    if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat)) break;
706    j--;
707  }
708  return strat->posInLOld(set,j,p,strat);
709}
710
711
712/*2
713* computes the s-polynomials L[ ].p in L
714*/
715void updateL(kStrategy strat)
716{
717  LObject p;
718  int dL;
719  int j=strat->Ll;
720  loop
721  {
722    if (j<0) break;
723    if (hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat))
724    {
725      p=strat->L[strat->Ll];
726      strat->L[strat->Ll]=strat->L[j];
727      strat->L[j]=p;
728      break;
729    }
730    j--;
731  }
732  if (j<0)
733  {
734    j=strat->Ll;
735    loop
736    {
737      if (j<0) break;
738      if (pNext(strat->L[j].p) == strat->tail)
739      {
740        pLmFree(strat->L[j].p);    /*deletes the short spoly and computes*/
741        strat->L[j].p = NULL;
742        poly m1 = NULL, m2 = NULL;
743        // check that spoly creation is ok
744        while (strat->tailRing != currRing &&
745               !kCheckSpolyCreation(&(strat->L[j]), strat, m1, m2))
746        {
747          assume(m1 == NULL && m2 == NULL);
748          // if not, change to a ring where exponents are at least
749          // large enough
750          kStratChangeTailRing(strat);
751        }
752        /* create the real one */
753        ksCreateSpoly(&(strat->L[j]), strat->kNoetherTail(), FALSE,
754                      strat->tailRing, m1, m2, strat->R);
755
756        strat->L[j].SetLmCurrRing();
757        if (!strat->honey)
758          strat->initEcart(&strat->L[j]);
759        else
760          strat->L[j].SetLength(strat->length_pLength);
761
762        BOOLEAN pp = hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat);
763
764        if (strat->use_buckets) strat->L[j].PrepareRed(TRUE);
765
766        if (pp)
767        {
768          p=strat->L[strat->Ll];
769          strat->L[strat->Ll]=strat->L[j];
770          strat->L[j]=p;
771          break;
772        }
773      }
774      j--;
775    }
776  }
777}
778
779/*2
780* computes the s-polynomials L[ ].p in L and
781* cuts elements in L above noether
782*/
783void updateLHC(kStrategy strat)
784{
785  int i = 0;
786  kTest_TS(strat);
787  while (i <= strat->Ll)
788  {
789    if (pNext(strat->L[i].p) == strat->tail)
790    {
791       /*- deletes the int spoly and computes -*/
792      if (pLmCmp(strat->L[i].p,strat->kNoether) == -1)
793      {
794        pLmFree(strat->L[i].p);
795        strat->L[i].p = NULL;
796      }
797      else
798      {
799        pLmFree(strat->L[i].p);
800        strat->L[i].p = NULL;
801        poly m1 = NULL, m2 = NULL;
802        // check that spoly creation is ok
803        while (strat->tailRing != currRing &&
804               !kCheckSpolyCreation(&(strat->L[i]), strat, m1, m2))
805        {
806          assume(m1 == NULL && m2 == NULL);
807          // if not, change to a ring where exponents are at least
808          // large enough
809          kStratChangeTailRing(strat);
810        }
811        /* create the real one */
812        ksCreateSpoly(&(strat->L[i]), strat->kNoetherTail(), FALSE,
813                      strat->tailRing, m1, m2, strat->R);
814        if (! strat->L[i].IsNull())
815        {
816          strat->L[i].SetLmCurrRing();
817          strat->L[i].SetpFDeg();
818          strat->L[i].ecart
819            = strat->L[i].pLDeg(strat->LDegLast) - strat->L[i].GetpFDeg();
820          if (strat->use_buckets) strat->L[i].PrepareRed(TRUE);
821        }
822      }
823    }
824    else
825      deleteHC(&(strat->L[i]), strat);
826   if (strat->L[i].IsNull())
827      deleteInL(strat->L,&strat->Ll,i,strat);
828    else
829    {
830#ifdef KDEBUG
831      kTest_L(&(strat->L[i]), strat->tailRing, TRUE, i, strat->T, strat->tl);
832#endif
833      i++;
834    }
835  }
836  kTest_TS(strat);
837}
838
839/*2
840* cuts in T above strat->kNoether and tries to cancel a unit
841*/
842void updateT(kStrategy strat)
843{
844  int i = 0;
845  LObject p;
846
847  while (i <= strat->tl)
848  {
849    p = strat->T[i];
850    deleteHC(&p,strat, TRUE);
851    /*- tries to cancel a unit: -*/
852    cancelunit(&p);
853    if (p.p != strat->T[i].p)
854    {
855      strat->sevT[i] = pGetShortExpVector(p.p);
856      p.SetpFDeg();
857    }
858    strat->T[i] = p;
859    i++;
860  }
861}
862
863/*2
864* arranges red, pos and T if strat->kHEdgeFound (first time)
865*/
866void firstUpdate(kStrategy strat)
867{
868  if (strat->update)
869  {
870    kTest_TS(strat);
871    strat->update = (strat->tl == -1);
872    if (TEST_OPT_WEIGHTM)
873    {
874      pRestoreDegProcs(pFDegOld, pLDegOld);
875      if (strat->tailRing != currRing)
876      {
877        strat->tailRing->pFDeg = strat->pOrigFDeg_TailRing;
878        strat->tailRing->pLDeg = strat->pOrigLDeg_TailRing;
879      }
880      int i;
881      for (i=strat->Ll; i>=0; i--)
882      {
883        strat->L[i].SetpFDeg();
884      }
885      for (i=strat->tl; i>=0; i--)
886      {
887        strat->T[i].SetpFDeg();
888      }
889      if (ecartWeights)
890      {
891        omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
892        ecartWeights=NULL;
893      }
894    }
895    if (TEST_OPT_FASTHC)
896    {
897      strat->posInL = strat->posInLOld;
898      strat->lastAxis = 0;
899    }
900    if (BTEST1(27))
901      return;
902    strat->red = redFirst;
903    strat->use_buckets = kMoraUseBucket(strat);
904    updateT(strat);
905    strat->posInT = posInT2;
906    reorderT(strat);
907  }
908  kTest_TS(strat);
909}
910
911/*2
912*-puts p to the standardbasis s at position at
913*-reduces the tail of p if TEST_OPT_REDTAIL
914*-tries to cancel a unit
915*-HEckeTest
916*  if TRUE
917*  - decides about reduction-strategies
918*  - computes noether
919*  - stops computation if BTEST1(27)
920*  - cuts the tails of the polynomials
921*    in s,t and the elements in L above noether
922*    and cancels units if possible
923*  - reorders s,L
924*/
925void enterSMora (LObject p,int atS,kStrategy strat, int atR = -1)
926{
927  int i;
928  enterSBba(p, atS, strat, atR);
929  if (TEST_OPT_DEBUG)
930  {
931    Print("new s%d:",atS);
932    wrp(p.p);
933    PrintLn();
934  }
935  if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat);
936  if (strat->kHEdgeFound)
937  {
938    if (newHEdge(strat->S,strat))
939    {
940      firstUpdate(strat);
941      if (BTEST1(27))
942        return;
943      /*- cuts elements in L above noether and reorders L -*/
944      updateLHC(strat);
945      /*- reorders L with respect to posInL -*/
946      reorderL(strat);
947    }
948  }
949  else if (strat->kNoether!=NULL)
950    strat->kHEdgeFound = TRUE;
951  else if (TEST_OPT_FASTHC)
952  {
953    if (strat->posInLOldFlag)
954    {
955      missingAxis(&strat->lastAxis,strat);
956      if (strat->lastAxis)
957      {
958        strat->posInLOld = strat->posInL;
959        strat->posInLOldFlag = FALSE;
960        strat->posInL = posInL10;
961        strat->posInLDependsOnLength = TRUE;
962        updateL(strat);
963        reorderL(strat);
964      }
965    }
966    else if (strat->lastAxis)
967      updateL(strat);
968  }
969}
970
971/*2
972*-puts p to the standardbasis s at position at
973*-HEckeTest
974*  if TRUE
975*  - computes noether
976*/
977void enterSMoraNF (LObject p, int atS,kStrategy strat, int atR = -1)
978{
979  int i;
980
981  enterSBba(p, atS, strat, atR);
982  if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat);
983  if (strat->kHEdgeFound)
984    newHEdge(strat->S,strat);
985  else if (strat->kNoether!=NULL)
986    strat->kHEdgeFound = TRUE;
987}
988
989void initBba(ideal F,kStrategy strat)
990{
991  int i;
992  idhdl h;
993 /* setting global variables ------------------- */
994  strat->enterS = enterSBba;
995  if (strat->honey)
996    strat->red = redHoney;
997  else if (pLexOrder && !strat->homog)
998    strat->red = redLazy;
999  else
1000    strat->red = redHomog;
1001#ifdef HAVE_RING2TOM
1002  if (currRing->cring == 1) {
1003    strat->red = redRing2toM;
1004  }
1005#endif
1006  if (pLexOrder && strat->honey)
1007    strat->initEcart = initEcartNormal;
1008  else
1009    strat->initEcart = initEcartBBA;
1010  if (strat->honey)
1011    strat->initEcartPair = initEcartPairMora;
1012  else
1013    strat->initEcartPair = initEcartPairBba;
1014  strat->kIdeal = NULL;
1015  //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD;
1016  //else              strat->kIdeal->rtyp=MODUL_CMD;
1017  //strat->kIdeal->data=(void *)strat->Shdl;
1018  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1019  {
1020    //interred  machen   Aenderung
1021    pFDegOld=pFDeg;
1022    pLDegOld=pLDeg;
1023    //h=ggetid("ecart");
1024    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
1025    //{
1026    //  ecartWeights=iv2array(IDINTVEC(h));
1027    //}
1028    //else
1029    {
1030      ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short));
1031      /*uses automatic computation of the ecartWeights to set them*/
1032      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1033    }
1034    pRestoreDegProcs(totaldegreeWecart, maxdegreeWecart);
1035    if (TEST_OPT_PROT)
1036    {
1037      for(i=1; i<=pVariables; i++)
1038        Print(" %d",ecartWeights[i]);
1039      PrintLn();
1040      mflush();
1041    }
1042  }
1043}
1044
1045void initMora(ideal F,kStrategy strat)
1046{
1047  int i,j;
1048  idhdl h;
1049
1050  strat->NotUsedAxis = (BOOLEAN *)omAlloc((pVariables+1)*sizeof(BOOLEAN));
1051  for (j=pVariables; j>0; j--) strat->NotUsedAxis[j] = TRUE;
1052  strat->enterS = enterSMora;
1053  strat->initEcartPair = initEcartPairMora; /*- ecart approximation -*/
1054  strat->posInLOld = strat->posInL;
1055  strat->posInLOldFlag = TRUE;
1056  strat->initEcart = initEcartNormal;
1057  strat->kHEdgeFound = ppNoether != NULL;
1058  if ( strat->kHEdgeFound )
1059     strat->kNoether = pCopy(ppNoether);
1060  else if (strat->kHEdgeFound || strat->homog)
1061    strat->red = redFirst;  /*take the first possible in T*/
1062  else
1063    strat->red = redEcart;/*take the first possible in under ecart-restriction*/
1064  if (strat->kHEdgeFound)
1065  {
1066    strat->HCord = pFDeg(ppNoether,currRing)+1;
1067    strat->posInT = posInT2;
1068  }
1069  else
1070  {
1071    strat->HCord = 32000;/*- very large -*/
1072  }
1073  /*reads the ecartWeights used for Graebes method from the
1074   *intvec ecart and set ecartWeights
1075   */
1076  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1077  {
1078    //interred  machen   Aenderung
1079    pFDegOld=pFDeg;
1080    pLDegOld=pLDeg;
1081    //h=ggetid("ecart");
1082    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
1083    //{
1084    //  ecartWeights=iv2array(IDINTVEC(h));
1085    //}
1086    //else
1087    {
1088      ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short));
1089      /*uses automatic computation of the ecartWeights to set them*/
1090      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1091    }
1092
1093    pSetDegProcs(totaldegreeWecart, maxdegreeWecart);
1094    if (TEST_OPT_PROT)
1095    {
1096      for(i=1; i<=pVariables; i++)
1097        Print(" %d",ecartWeights[i]);
1098      PrintLn();
1099      mflush();
1100    }
1101  }
1102  kOptimizeLDeg(pLDeg, strat);
1103}
1104
1105#ifdef HAVE_ASSUME
1106static int mora_count = 0;
1107static int mora_loop_count;
1108#endif
1109
1110ideal mora (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
1111{
1112#ifdef HAVE_ASSUME
1113  mora_count++;
1114  mora_loop_count = 0;
1115#endif
1116#ifdef KDEBUG
1117  om_Opts.MinTrack = 5;
1118#endif
1119  int srmax;
1120  int lrmax = 0;
1121  int olddeg = 0;
1122  int reduc = 0;
1123  int red_result = 1;
1124  int hilbeledeg=1,hilbcount=0;
1125
1126  strat->update = TRUE;
1127  /*- setting global variables ------------------- -*/
1128  initBuchMoraCrit(strat);
1129  initHilbCrit(F,Q,&hilb,strat);
1130  initMora(F,strat);
1131  initBuchMoraPos(strat);
1132  /*Shdl=*/initBuchMora(F,Q,strat);
1133  if (TEST_OPT_FASTHC) missingAxis(&strat->lastAxis,strat);
1134  /*updateS in initBuchMora has Hecketest
1135  * and could have put strat->kHEdgdeFound FALSE*/
1136  if (ppNoether!=NULL)
1137  {
1138    strat->kHEdgeFound = TRUE;
1139  }
1140  if (strat->kHEdgeFound && strat->update)
1141  {
1142    firstUpdate(strat);
1143    updateLHC(strat);
1144    reorderL(strat);
1145  }
1146  if (TEST_OPT_FASTHC && (strat->lastAxis) && strat->posInLOldFlag)
1147  {
1148    strat->posInLOld = strat->posInL;
1149    strat->posInLOldFlag = FALSE;
1150    strat->posInL = posInL10;
1151    updateL(strat);
1152    reorderL(strat);
1153  }
1154  srmax = strat->sl;
1155  kTest_TS(strat);
1156  strat->use_buckets = kMoraUseBucket(strat);
1157  /*- compute-------------------------------------------*/
1158
1159#ifdef HAVE_TAIL_RING
1160//  if (strat->homog && strat->red == redFirst)
1161    kStratInitChangeTailRing(strat);
1162#endif
1163
1164  while (strat->Ll >= 0)
1165  {
1166#ifdef HAVE_ASSUME
1167    mora_loop_count++;
1168#endif
1169    if (lrmax< strat->Ll) lrmax=strat->Ll; /*stat*/
1170    //test_int_std(strat->kIdeal);
1171    if (TEST_OPT_DEBUG) messageSets(strat);
1172    if (TEST_OPT_DEGBOUND
1173    && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg))
1174    {
1175      /*
1176      * stops computation if
1177      * - 24 (degBound)
1178      *   && upper degree is bigger than Kstd1_deg
1179      */
1180      while ((strat->Ll >= 0)
1181        && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg)
1182        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL))
1183      {
1184        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1185        //if (TEST_OPT_PROT)
1186        //{
1187        //   PrintS("D"); mflush();
1188        //}
1189      }
1190      if (strat->Ll<0) break;
1191    }
1192    strat->P = strat->L[strat->Ll];/*- picks the last element from the lazyset L -*/
1193    if (strat->Ll==0) strat->interpt=TRUE;
1194    strat->Ll--;
1195
1196    // create the real Spoly
1197    if (pNext(strat->P.p) == strat->tail)
1198    {
1199      /*- deletes the short spoly and computes -*/
1200      pLmFree(strat->P.p);
1201      strat->P.p = NULL;
1202      poly m1 = NULL, m2 = NULL;
1203      // check that spoly creation is ok
1204      while (strat->tailRing != currRing &&
1205             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
1206      {
1207        assume(m1 == NULL && m2 == NULL);
1208        // if not, change to a ring where exponents are large enough
1209        kStratChangeTailRing(strat);
1210      }
1211      /* create the real one */
1212      ksCreateSpoly(&(strat->P), strat->kNoetherTail(), strat->use_buckets,
1213                    strat->tailRing, m1, m2, strat->R);
1214      if (!strat->use_buckets)
1215        strat->P.SetLength(strat->length_pLength);
1216    }
1217    else if (strat->P.p1 == NULL)
1218    {
1219      // for input polys, prepare reduction (buckets !)
1220      strat->P.SetLength(strat->length_pLength);
1221      strat->P.PrepareRed(strat->use_buckets);
1222    }
1223
1224    if (!strat->P.IsNull())
1225    {
1226      // might be NULL from noether !!!
1227      if (TEST_OPT_PROT)
1228        message(strat->P.ecart+strat->P.GetpFDeg(),&olddeg,&reduc,strat, red_result);
1229      // reduce
1230      red_result = strat->red(&strat->P,strat);
1231    }
1232
1233    if (! strat->P.IsNull())
1234    {
1235      strat->P.GetP();
1236      // statistics
1237      if (TEST_OPT_PROT) PrintS("s");
1238      // normalization
1239      if (!TEST_OPT_INTSTRATEGY)
1240        strat->P.pNorm();
1241      // tailreduction
1242      strat->P.p = redtail(&(strat->P),strat->sl,strat);
1243      // set ecart -- might have changed because of tail reductions
1244      if ((!strat->noTailReduction) && (!strat->honey))
1245        strat->initEcart(&strat->P);
1246      // cancel unit
1247      cancelunit(&strat->P);
1248      // for char 0, clear denominators
1249      if (TEST_OPT_INTSTRATEGY)
1250        strat->P.pCleardenom();
1251
1252      // put in T
1253      enterT(strat->P,strat);
1254      // build new pairs
1255      enterpairs(strat->P.p,strat->sl,strat->P.ecart,0,strat, strat->tl);
1256      // put in S
1257      strat->enterS(strat->P,
1258                    posInS(strat,strat->sl,strat->P.p, strat->P.ecart),
1259                    strat, strat->tl);
1260
1261      // apply hilbert criterion
1262      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1263
1264      // clear strat->P
1265      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
1266      strat->P.lcm=NULL;
1267#ifdef KDEBUG
1268      // make sure kTest_TS does not complain about strat->P
1269      memset(&strat->P,0,sizeof(strat->P));
1270#endif
1271      if (strat->sl>srmax) srmax = strat->sl; /*stat.*/
1272      if (strat->Ll>lrmax) lrmax = strat->Ll;
1273    }
1274    if (strat->kHEdgeFound)
1275    {
1276      if ((BTEST1(27))
1277      || ((TEST_OPT_MULTBOUND) && (scMult0Int((strat->Shdl)) < mu)))
1278      {
1279        // obachman: is this still used ???
1280        /*
1281        * stops computation if strat->kHEdgeFound and
1282        * - 27 (finiteDeterminacyTest)
1283        * or
1284        * - 23
1285        *   (multBound)
1286        *   && multiplicity of the ideal is smaller then a predefined number mu
1287        */
1288        while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1289      }
1290    }
1291    kTest_TS(strat);
1292  }
1293  /*- complete reduction of the standard basis------------------------ -*/
1294  if (TEST_OPT_REDSB) completeReduce(strat);
1295  /*- release temp data------------------------------- -*/
1296  exitBuchMora(strat);
1297  /*- polynomials used for HECKE: HC, noether -*/
1298  if (BTEST1(27))
1299  {
1300    if (strat->kHEdge!=NULL)
1301      Kstd1_mu=pFDeg(strat->kHEdge,currRing);
1302    else
1303      Kstd1_mu=-1;
1304  }
1305  pDelete(&strat->kHEdge);
1306  strat->update = TRUE; //???
1307  strat->lastAxis = 0; //???
1308  pDelete(&strat->kNoether);
1309  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1310  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
1311  if (TEST_OPT_WEIGHTM)
1312  {
1313    pRestoreDegProcs(pFDegOld, pLDegOld);
1314    if (ecartWeights)
1315    {
1316      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
1317      ecartWeights=NULL;
1318    }
1319  }
1320  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1321  idTest(strat->Shdl);
1322  return (strat->Shdl);
1323}
1324
1325poly kNF1 (ideal F,ideal Q,poly q, kStrategy strat, int lazyReduce)
1326{
1327  poly   p;
1328  int   i;
1329  int   j;
1330  int   o;
1331  LObject   h;
1332  BITSET save_test=test;
1333
1334  if ((idIs0(F))&&(Q==NULL))
1335    return pCopy(q); /*F=0*/
1336  strat->ak = si_max(idRankFreeModule(F),pMaxComp(q));
1337  /*- creating temp data structures------------------- -*/
1338  strat->kHEdgeFound = ppNoether != NULL;
1339  strat->kNoether    = pCopy(ppNoether);
1340  test|=Sy_bit(OPT_REDTAIL);
1341  test&=~Sy_bit(OPT_INTSTRATEGY);
1342  if (TEST_OPT_STAIRCASEBOUND
1343  && (! TEST_V_DEG_STOP)
1344  && (0<Kstd1_deg)
1345  && ((!strat->kHEdgeFound)
1346    ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg))))
1347  {
1348    pDelete(&strat->kNoether);
1349    strat->kNoether=pOne();
1350    pSetExp(strat->kNoether,1, Kstd1_deg+1);
1351    pSetm(strat->kNoether);
1352    strat->kHEdgeFound=TRUE;
1353  }
1354  initBuchMoraCrit(strat);
1355  initBuchMoraPos(strat);
1356  initMora(F,strat);
1357  strat->enterS = enterSMoraNF;
1358  /*- set T -*/
1359  strat->tl = -1;
1360  strat->tmax = setmaxT;
1361  strat->T = initT();
1362  strat->R = initR();
1363  strat->sevT = initsevT();
1364  /*- set S -*/
1365  strat->sl = -1;
1366  /*- init local data struct.-------------------------- -*/
1367  /*Shdl=*/initS(F,Q,strat);
1368  if ((strat->ak!=0)
1369  && (strat->kHEdgeFound))
1370  {
1371    if (strat->ak!=1)
1372    {
1373      pSetComp(strat->kNoether,1);
1374      pSetmComp(strat->kNoether);
1375      poly p=pHead(strat->kNoether);
1376      pSetComp(p,strat->ak);
1377      pSetmComp(p);
1378      p=pAdd(strat->kNoether,p);
1379      strat->kNoether=pNext(p);
1380      p_LmFree(p,currRing);
1381    }
1382  }
1383  if ((lazyReduce & 1)==0)
1384  {
1385    for (i=strat->sl; i>=0; i--)
1386      pNorm(strat->S[i]);
1387  }
1388  /*- puts the elements of S also to T -*/
1389  for (i=0; i<=strat->sl; i++)
1390  {
1391    h.p = strat->S[i];
1392    h.ecart = strat->ecartS[i];
1393    if (strat->sevS[i] == 0) strat->sevS[i] = pGetShortExpVector(h.p);
1394    else assume(strat->sevS[i] == pGetShortExpVector(h.p));
1395    h.length = pLength(h.p);
1396    h.sev = strat->sevS[i];
1397    h.SetpFDeg();
1398    enterT(h,strat);
1399  }
1400  /*- compute------------------------------------------- -*/
1401  p = pCopy(q);
1402  deleteHC(&p,&o,&j,strat);
1403  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
1404  if (p!=NULL) p = redMoraNF(p,strat, lazyReduce & 2);
1405  if ((p!=NULL)&&((lazyReduce & 1)==0))
1406  {
1407    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1408    p = redtail(p,strat->sl,strat);
1409  }
1410  /*- release temp data------------------------------- -*/
1411  cleanT(strat);
1412  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
1413  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1414  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
1415  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1416  omfree(strat->sevT);
1417  omfree(strat->S_2_R);
1418  omfree(strat->R);
1419
1420  if ((Q!=NULL)&&(strat->fromQ!=NULL))
1421  {
1422    i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
1423    omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
1424    strat->fromQ=NULL;
1425  }
1426  pDelete(&strat->kHEdge);
1427  pDelete(&strat->kNoether);
1428  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1429  {
1430    pRestoreDegProcs(pFDegOld, pLDegOld);
1431    if (ecartWeights)
1432    {
1433      omFreeSize((ADDRESS *)&ecartWeights,(pVariables+1)*sizeof(short));
1434      ecartWeights=NULL;
1435    }
1436  }
1437  idDelete(&strat->Shdl);
1438  test=save_test;
1439  if (TEST_OPT_PROT) PrintLn();
1440  return p;
1441}
1442
1443ideal kNF1 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce)
1444{
1445  poly   p;
1446  int   i;
1447  int   j;
1448  int   o;
1449  LObject   h;
1450  ideal res;
1451  BITSET save_test=test;
1452
1453  if (idIs0(q)) return idInit(IDELEMS(q),q->rank);
1454  if ((idIs0(F))&&(Q==NULL))
1455    return idCopy(q); /*F=0*/
1456  strat->ak = si_max(idRankFreeModule(F),idRankFreeModule(q));
1457  /*- creating temp data structures------------------- -*/
1458  strat->kHEdgeFound = ppNoether != NULL;
1459  strat->kNoether=pCopy(ppNoether);
1460  test|=Sy_bit(OPT_REDTAIL);
1461  if (TEST_OPT_STAIRCASEBOUND
1462  && (0<Kstd1_deg)
1463  && ((!strat->kHEdgeFound)
1464    ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg))))
1465  {
1466    pDelete(&strat->kNoether);
1467    strat->kNoether=pOne();
1468    pSetExp(strat->kNoether,1, Kstd1_deg+1);
1469    pSetm(strat->kNoether);
1470    strat->kHEdgeFound=TRUE;
1471  }
1472  initBuchMoraCrit(strat);
1473  initBuchMoraPos(strat);
1474  initMora(F,strat);
1475  strat->enterS = enterSMoraNF;
1476  /*- set T -*/
1477  strat->tl = -1;
1478  strat->tmax = setmaxT;
1479  strat->T = initT();
1480  strat->R = initR();
1481  strat->sevT = initsevT();
1482  /*- set S -*/
1483  strat->sl = -1;
1484  /*- init local data struct.-------------------------- -*/
1485  /*Shdl=*/initS(F,Q,strat);
1486  if ((strat->ak!=0)
1487  && (strat->kHEdgeFound))
1488  {
1489    if (strat->ak!=1)
1490    {
1491      pSetComp(strat->kNoether,1);
1492      pSetmComp(strat->kNoether);
1493      poly p=pHead(strat->kNoether);
1494      pSetComp(p,strat->ak);
1495      pSetmComp(p);
1496      p=pAdd(strat->kNoether,p);
1497      strat->kNoether=pNext(p);
1498      p_LmFree(p,currRing);
1499    }
1500  }
1501  if (TEST_OPT_INTSTRATEGY && ((lazyReduce & 1)==0))
1502  {
1503    for (i=strat->sl; i>=0; i--)
1504      pNorm(strat->S[i]);
1505  }
1506  /*- compute------------------------------------------- -*/
1507  res=idInit(IDELEMS(q),q->rank);
1508  for (i=0; i<IDELEMS(q); i++)
1509  {
1510    if (q->m[i]!=NULL)
1511    {
1512      p = pCopy(q->m[i]);
1513      deleteHC(&p,&o,&j,strat);
1514      if (p!=NULL)
1515      {
1516        /*- puts the elements of S also to T -*/
1517        for (j=0; j<=strat->sl; j++)
1518        {
1519          h.p = strat->S[j];
1520          h.ecart = strat->ecartS[j];
1521          h.pLength = h.length = pLength(h.p);
1522          if (strat->sevS[j] == 0) strat->sevS[j] = pGetShortExpVector(h.p);
1523          else assume(strat->sevS[j] == pGetShortExpVector(h.p));
1524          h.sev = strat->sevS[j];
1525          h.SetpFDeg();
1526          enterT(h,strat);
1527        }
1528        if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
1529        p = redMoraNF(p,strat, lazyReduce & 2);
1530        if ((p!=NULL)&&((lazyReduce & 1)==0))
1531        {
1532          if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1533          p = redtail(p,strat->sl,strat);
1534        }
1535        cleanT(strat);
1536      }
1537      res->m[i]=p;
1538    }
1539    //else
1540    //  res->m[i]=NULL;
1541  }
1542  /*- release temp data------------------------------- -*/
1543  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
1544  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1545  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
1546  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1547  omfree(strat->sevT);
1548  omfree(strat->S_2_R);
1549  omfree(strat->R);
1550  if ((Q!=NULL)&&(strat->fromQ!=NULL))
1551  {
1552    i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
1553    omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
1554    strat->fromQ=NULL;
1555  }
1556  pDelete(&strat->kHEdge);
1557  pDelete(&strat->kNoether);
1558  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1559  {
1560    pFDeg=pFDegOld;
1561    pLDeg=pLDegOld;
1562    if (ecartWeights)
1563    {
1564      omFreeSize((ADDRESS *)&ecartWeights,(pVariables+1)*sizeof(short));
1565      ecartWeights=NULL;
1566    }
1567  }
1568  idDelete(&strat->Shdl);
1569  test=save_test;
1570  if (TEST_OPT_PROT) PrintLn();
1571  return res;
1572}
1573
1574pFDegProc pFDegOld;
1575pLDegProc pLDegOld;
1576intvec * kModW, * kHomW;
1577
1578long kModDeg(poly p, ring r)
1579{
1580  long o=pWDegree(p, r);
1581  long i=p_GetComp(p, r);
1582  if (i==0) return o;
1583  assume((i>0) && (i<=kModW->length()));
1584  return o+(*kModW)[i-1];
1585}
1586long kHomModDeg(poly p, ring r)
1587{
1588  int i;
1589  long j=0;
1590
1591  for (i=r->N;i>0;i--)
1592    j+=p_GetExp(p,i,r)*(*kHomW)[i-1];
1593  if (kModW == NULL) return j;
1594  i = p_GetComp(p,r);
1595  if (i==0) return j;
1596  return j+(*kModW)[i-1];
1597}
1598
1599ideal kStd(ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp,
1600          int newIdeal, intvec *vw)
1601{
1602  ideal r;
1603  BOOLEAN b=pLexOrder,toReset=FALSE;
1604  BOOLEAN delete_w=(w==NULL);
1605  kStrategy strat=new skStrategy;
1606
1607  if(!TEST_OPT_RETURN_SB)
1608    strat->syzComp = syzComp;
1609  if (TEST_OPT_SB_1)
1610    strat->newIdeal = newIdeal;
1611  if (rField_has_simple_inverse())
1612    strat->LazyPass=20;
1613  else
1614    strat->LazyPass=2;
1615  strat->LazyDegree = 1;
1616  strat->ak = idRankFreeModule(F);
1617  strat->kModW=kModW=NULL;
1618  strat->kHomW=kHomW=NULL;
1619  if (vw != NULL)
1620  {
1621    pLexOrder=FALSE;
1622    strat->kHomW=kHomW=vw;
1623    pFDegOld = pFDeg;
1624    pLDegOld = pLDeg;
1625    pSetDegProcs(kHomModDeg);
1626    toReset = TRUE;
1627  }
1628  if (h==testHomog)
1629  {
1630    if (strat->ak == 0)
1631    {
1632      h = (tHomog)idHomIdeal(F,Q);
1633      w=NULL;
1634    }
1635    else if (!TEST_OPT_DEGBOUND)
1636    {
1637      h = (tHomog)idHomModule(F,Q,w);
1638    }
1639  }
1640  pLexOrder=b;
1641  if (h==isHomog)
1642  {
1643    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
1644    {
1645      strat->kModW = kModW = *w;
1646      if (vw == NULL)
1647      {
1648        pFDegOld = pFDeg;
1649        pLDegOld = pLDeg;
1650        pSetDegProcs(kModDeg);
1651        toReset = TRUE;
1652      }
1653    }
1654    pLexOrder = TRUE;
1655    if (hilb==NULL) strat->LazyPass*=2;
1656  }
1657  strat->homog=h;
1658#ifdef KDEBUG
1659  idTest(F);
1660#endif
1661#ifdef HAVE_PLURAL
1662  if (rIsPluralRing(currRing))
1663  {
1664    r=gr_bba(F,Q,strat);
1665  }
1666  else
1667#endif
1668  if (pOrdSgn==-1)
1669  {
1670    if (w!=NULL)
1671      r=mora(F,Q,*w,hilb,strat);
1672    else
1673      r=mora(F,Q,NULL,hilb,strat);
1674  }
1675  else
1676  {
1677    if (w!=NULL)
1678      r=bba(F,Q,*w,hilb,strat);
1679    else
1680      r=bba(F,Q,NULL,hilb,strat);
1681  }
1682#ifdef KDEBUG
1683  idTest(r);
1684#endif
1685  if (toReset)
1686  {
1687    kModW = NULL;
1688    pRestoreDegProcs(pFDegOld, pLDegOld);
1689  }
1690  pLexOrder = b;
1691//Print("%d reductions canceled \n",strat->cel);
1692  HCord=strat->HCord;
1693  delete(strat);
1694  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
1695  return r;
1696}
1697
1698//##############################################################
1699//##############################################################
1700//##############################################################
1701//##############################################################
1702//##############################################################
1703
1704ideal kMin_std(ideal F, ideal Q, tHomog h,intvec ** w, ideal &M, intvec *hilb,
1705              int syzComp, int reduced)
1706{
1707  ideal r=NULL;
1708  int Kstd1_OldDeg = Kstd1_deg,i;
1709  intvec* temp_w=NULL;
1710  BOOLEAN b=pLexOrder,toReset=FALSE;
1711  BOOLEAN delete_w=(w==NULL);
1712  BOOLEAN oldDegBound=TEST_OPT_DEGBOUND;
1713  kStrategy strat=new skStrategy;
1714
1715  if(!TEST_OPT_RETURN_SB)
1716     strat->syzComp = syzComp;
1717  if (rField_has_simple_inverse())
1718    strat->LazyPass=20;
1719  else
1720    strat->LazyPass=2;
1721  strat->LazyDegree = 1;
1722  strat->minim=(reduced % 2)+1;
1723  strat->ak = idRankFreeModule(F);
1724  if (delete_w)
1725  {
1726    temp_w=new intvec((strat->ak)+1);
1727    w = &temp_w;
1728  }
1729  if ((h==testHomog)
1730  )
1731  {
1732    if (strat->ak == 0)
1733    {
1734      h = (tHomog)idHomIdeal(F,Q);
1735      w=NULL;
1736    }
1737    else
1738    {
1739      h = (tHomog)idHomModule(F,Q,w);
1740    }
1741  }
1742  if (h==isHomog)
1743  {
1744    if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
1745    {
1746      kModW = *w;
1747      strat->kModW = *w;
1748      assume(pFDeg != NULL && pLDeg != NULL);
1749      pFDegOld = pFDeg;
1750      pLDegOld = pLDeg;
1751      pSetDegProcs(kModDeg);
1752
1753      toReset = TRUE;
1754      if (reduced>1)
1755      {
1756        Kstd1_OldDeg=Kstd1_deg;
1757        Kstd1_deg = -1;
1758        for (i=IDELEMS(F)-1;i>=0;i--)
1759        {
1760          if ((F->m[i]!=NULL) && (pFDeg(F->m[i],currRing)>=Kstd1_deg))
1761            Kstd1_deg = pFDeg(F->m[i],currRing)+1;
1762        }
1763      }
1764    }
1765    pLexOrder = TRUE;
1766    strat->LazyPass*=2;
1767  }
1768  strat->homog=h;
1769  if (pOrdSgn==-1)
1770  {
1771    if (w!=NULL)
1772      r=mora(F,Q,*w,hilb,strat);
1773    else
1774      r=mora(F,Q,NULL,hilb,strat);
1775  }
1776  else
1777  {
1778    if (w!=NULL)
1779      r=bba(F,Q,*w,hilb,strat);
1780    else
1781      r=bba(F,Q,NULL,hilb,strat);
1782  }
1783#ifdef KDEBUG
1784  {
1785    int i;
1786    for (i=IDELEMS(r)-1; i>=0; i--) pTest(r->m[i]);
1787  }
1788#endif
1789  idSkipZeroes(r);
1790  if (toReset)
1791  {
1792    pRestoreDegProcs(pFDegOld, pLDegOld);
1793    kModW = NULL;
1794  }
1795  pLexOrder = b;
1796  HCord=strat->HCord;
1797  if ((delete_w)&&(temp_w!=NULL)) delete temp_w;
1798  if ((IDELEMS(r)==1) && (r->m[0]!=NULL) && pIsConstant(r->m[0]) && (strat->ak==0))
1799  {
1800    M=idInit(1,F->rank);
1801    M->m[0]=pOne();
1802    //if (strat->ak!=0) { pSetComp(M->m[0],strat->ak); pSetmComp(M->m[0]); }
1803    if (strat->M!=NULL) idDelete(&strat->M);
1804  }
1805  else
1806  if (strat->M==NULL)
1807  {
1808    M=idInit(1,F->rank);
1809    Warn("no minimal generating set computed");
1810  }
1811  else
1812  {
1813    idSkipZeroes(strat->M);
1814    M=strat->M;
1815  }
1816  delete(strat);
1817  if (reduced>2)
1818  {
1819    Kstd1_deg=Kstd1_OldDeg;
1820    if (!oldDegBound)
1821      test &= ~Sy_bit(OPT_DEGBOUND);
1822  }
1823  return r;
1824}
1825
1826poly kNF(ideal F, ideal Q, poly p,int syzComp, int lazyReduce)
1827{
1828  if (p==NULL)
1829     return NULL;
1830  kStrategy strat=new skStrategy;
1831  strat->syzComp = syzComp;
1832  if (pOrdSgn==-1)
1833    p=kNF1(F,Q,p,strat,lazyReduce);
1834  else
1835    p=kNF2(F,Q,p,strat,lazyReduce);
1836  delete(strat);
1837  return p;
1838}
1839
1840ideal kNF(ideal F, ideal Q, ideal p,int syzComp,int lazyReduce)
1841{
1842  ideal res;
1843  if (TEST_OPT_PROT)
1844  {
1845    Print("(S:%d)",IDELEMS(p));mflush();
1846  }
1847  kStrategy strat=new skStrategy;
1848  strat->syzComp = syzComp;
1849  if (pOrdSgn==-1)
1850    res=kNF1(F,Q,p,strat,lazyReduce);
1851  else
1852    res=kNF2(F,Q,p,strat,lazyReduce);
1853  delete(strat);
1854  return res;
1855}
1856
1857/*2
1858*interreduces F
1859*/
1860#if 0
1861// new version
1862ideal kInterRed(ideal F, ideal Q)
1863{
1864  ideal r;
1865  BOOLEAN b=pLexOrder,toReset=FALSE;
1866  kStrategy strat=new skStrategy;
1867  strat->interred_flag=TRUE;
1868  tHomog h;
1869  intvec *w=NULL;
1870
1871  if (rField_has_simple_inverse())
1872    strat->LazyPass=20;
1873  else
1874    strat->LazyPass=2;
1875  strat->LazyDegree = 1;
1876  strat->ak = idRankFreeModule(F);
1877  if (strat->ak == 0)
1878  {
1879    h = (tHomog)idHomIdeal(F,Q);
1880  }
1881  else
1882  {
1883    h = (tHomog)idHomModule(F,Q,&w);
1884  }
1885  pLexOrder=b;
1886  if (h==isHomog)
1887  {
1888    if (strat->ak > 0 && (w!=NULL))
1889    {
1890      strat->kModW = kModW = w;
1891      pFDegOld = pFDeg;
1892      pLDegOld = pLDeg;
1893      pSetDegProcs(kModDeg);
1894      toReset = TRUE;
1895    }
1896    pLexOrder = TRUE;
1897    strat->LazyPass*=2;
1898  }
1899  strat->homog=h;
1900#ifdef KDEBUG
1901  idTest(F);
1902#endif
1903  if (pOrdSgn==-1)
1904  {
1905    if (w!=NULL)
1906      r=mora(F,Q,w,NULL,strat);
1907    else
1908      r=mora(F,Q,NULL,NULL,strat);
1909  }
1910  else
1911  {
1912    if (w!=NULL)
1913      r=bba(F,Q,w,NULL,strat);
1914    else
1915      r=bba(F,Q,NULL,NULL,strat);
1916  }
1917#ifdef KDEBUG
1918  idTest(r);
1919#endif
1920  if (toReset)
1921  {
1922    kModW = NULL;
1923    pRestoreDegProcs(pFDegOld, pLDegOld);
1924  }
1925  pLexOrder = b;
1926//Print("%d reductions canceled \n",strat->cel);
1927  HCord=strat->HCord;
1928  delete(strat);
1929  if (w!=NULL) delete w;
1930  return r;
1931}
1932#else
1933// old version
1934ideal kInterRed (ideal F, ideal Q)
1935{
1936  int j;
1937  kStrategy strat = new skStrategy;
1938
1939//  if (TEST_OPT_PROT)
1940//  {
1941//    writeTime("start InterRed:");
1942//    mflush();
1943//  }
1944  //strat->syzComp     = 0;
1945  strat->kHEdgeFound = ppNoether != NULL;
1946  strat->kNoether=pCopy(ppNoether);
1947  strat->ak = idRankFreeModule(F);
1948  initBuchMoraCrit(strat);
1949  strat->NotUsedAxis = (BOOLEAN *)omAlloc((pVariables+1)*sizeof(BOOLEAN));
1950  for (j=pVariables; j>0; j--) strat->NotUsedAxis[j] = TRUE;
1951  strat->enterS      = enterSBba;
1952  strat->posInT      = posInT17;
1953  strat->initEcart   = initEcartNormal;
1954  strat->sl   = -1;
1955  strat->tl          = -1;
1956  strat->tmax        = setmaxT;
1957  strat->T           = initT();
1958  strat->R           = initR();
1959  strat->sevT        = initsevT();
1960  if (pOrdSgn == -1)   strat->honey = TRUE;
1961  initS(F,Q,strat);
1962  if (TEST_OPT_REDSB)
1963    strat->noTailReduction=FALSE;
1964  updateS(TRUE,strat);
1965  if (TEST_OPT_REDSB && TEST_OPT_INTSTRATEGY)
1966    completeReduce(strat);
1967  pDelete(&strat->kHEdge);
1968  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
1969  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1970  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
1971  omFreeSize((ADDRESS)strat->NotUsedAxis,(pVariables+1)*sizeof(BOOLEAN));
1972  omfree(strat->sevT);
1973  omfree(strat->S_2_R);
1974  omfree(strat->R);
1975
1976  if (strat->fromQ)
1977  {
1978    for (j=IDELEMS(strat->Shdl)-1;j>=0;j--)
1979    {
1980      if(strat->fromQ[j]) pDelete(&strat->Shdl->m[j]);
1981    }
1982    omFreeSize((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
1983    strat->fromQ=NULL;
1984  }
1985//  if (TEST_OPT_PROT)
1986//  {
1987//    writeTime("end Interred:");
1988//    mflush();
1989//  }
1990  ideal shdl=strat->Shdl;
1991  idSkipZeroes(shdl);
1992  delete(strat);
1993  return shdl;
1994}
1995#endif
1996
1997// returns TRUE if mora should use buckets, false otherwise
1998static BOOLEAN kMoraUseBucket(kStrategy strat)
1999{
2000#ifdef MORA_USE_BUCKETS
2001  if (TEST_OPT_NOT_BUCKETS)
2002    return FALSE;
2003  if (strat->red == redFirst)
2004  {
2005#ifdef NO_LDEG
2006    if (!strat->syzComp)
2007      return TRUE;
2008#else
2009    if ((strat->homog || strat->honey) && !strat->syzComp)
2010      return TRUE;
2011#endif
2012  }
2013  else
2014  {
2015    assume(strat->red == redEcart);
2016    if (strat->honey && !strat->syzComp)
2017      return TRUE;
2018  }
2019#endif
2020  return FALSE;
2021}
Note: See TracBrowser for help on using the repository browser.