source: git/Singular/kstd1.cc @ 48aa42

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