source: git/Singular/kstd1.cc @ a1c44e

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