source: git/Singular/kstd1.cc @ 512a2b

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