source: git/Singular/kstd1.cc @ ca7a56

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