source: git/Singular/kutil.cc @ 9a3ece

fieker-DuValspielwiese
Last change on this file since 9a3ece was 743c32, checked in by Hans Schönemann <hannes@…>, 25 years ago
* hannes: - OPT_DEBUG revisited - fixes to sdb git-svn-id: file:///usr/local/Singular/svn/trunk@3014 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 84.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kutil.cc,v 1.33 1999-04-29 16:57:16 Singular Exp $ */
5/*
6* ABSTRACT: kernel: utils for kStd
7*/
8
9#include <stdlib.h>
10#include <string.h>
11#include "mod2.h"
12#include "tok.h"
13#include "febase.h"
14#include "spolys.h"
15#include "mmemory.h"
16#include "numbers.h"
17#include "polys.h"
18#include "ipid.h"
19#include "ring.h"
20#include "ideals.h"
21#include "timer.h"
22#include "cntrlc.h"
23#include "stairc.h"
24#include "subexpr.h"
25#include "kstd1.h"
26#include "kutil.h"
27#include "spSpolyLoop.h"
28//#include "longrat.h"
29
30static poly redMora (poly h,int maxIndex,kStrategy strat);
31static poly redBba (poly h,int maxIndex,kStrategy strat);
32
33//int     cp, c3;
34//BOOLEAN interpt;
35//BOOLEAN news=FALSE;
36//static BOOLEAN newt=FALSE;/*used for messageSets*/
37BITSET  test=(BITSET)0;
38//int     ak;
39//int     syzComp=0;
40int     HCord;
41//LObject P;
42//poly    tail;
43//BOOLEAN *pairtest;/*used for enterOnePair*/
44//int    // LazyPass=100,
45//        LazyDegree=1;
46int        Kstd1_deg;
47int        mu=32000;
48
49//polyset S;
50//int     sl;
51//ideal   Shdl;
52//intset  ecartS;
53//intset  fromQ;
54
55//TSet    T;
56//int     tl;
57//int     tmax;
58
59//LSet    L;
60//int     Ll;
61//int     Lmax;
62
63//LSet    B;
64//int     Bl;
65//int     Bmax;
66
67//BOOLEAN kActive=FALSE;
68//BOOLEAN fromT = FALSE;
69//BOOLEAN honey, sugarCrit;/*option 5*/
70//BOOLEAN Gebauer;
71//BOOLEAN * NotUsedAxis;
72//BOOLEAN homog;
73//BOOLEAN noTailReduction = FALSE;
74
75/*0 implementation*/
76/*
77*static void deleteHCn(poly* p)
78*{
79*  poly p1;
80*  if (pHEdgeFound && (*p))
81*  {
82*    if (pComp0(*p,pNoether) == -1)
83*    {
84*      pDelete(p);
85*      return;
86*    }
87*    p1 = *p;
88*    while (pNext(p1))
89*    {
90*      if (pComp0(pNext(p1), pNoether) == -1) pDelete(&pNext(p1));
91*      else                                  pIter(p1);
92*    }
93*  }
94*}
95*/
96
97/*2
98*deletes higher monomial of p, re-compute ecart and length
99*works only for orderings with ecart =pFDeg(end)-pFDeg(start)
100*/
101void deleteHC(poly* p, int* e, int* l,kStrategy strat)
102{
103  poly p1;
104
105  if (strat->kHEdgeFound)
106  {
107    if (pComp(*p,strat->kNoether) == -1)
108    {
109      pDelete(p);
110      *l = 0;
111      *e = -1;
112      return;
113    }
114    p1 = *p;
115    while (pNext(p1)!=NULL)
116    {
117      if (pComp0(pNext(p1), strat->kNoether) == -1)
118        pDelete(&pNext(p1));
119      else
120        pIter(p1);
121    }
122    *e = pLDeg(*p,l)-pFDeg(*p);
123  }
124}
125
126/*2
127*tests if p.p=monomial*unit and cancels the unit
128*/
129void cancelunit (LObject* p)
130{
131  int  i;
132  poly h;
133
134  if(pIsVector((*p).p))
135  {
136    if(!pOneComp((*p).p)) return;
137  }
138  if ((*p).ecart != 0)
139  {
140    for(i=1;i<=pVariables;i++)
141    {
142      if ((pGetExp((*p).p,1)>0) && (rIsPolyVar(i)==TRUE)) return;
143    }
144    h = pNext(((*p).p));
145    loop
146    {
147      if (h==NULL)
148      {
149        pDelete(&(pNext((*p).p)));
150        (*p).ecart = 0;
151        (*p).length = 1;
152        return;
153      }
154      i = 0;
155      loop
156      {
157        i++;
158        if (pGetExp((*p).p,i) > pGetExp(h,i)) return ;
159        if (i == pVariables) break;
160      }
161      pIter(h);
162    }
163  }
164}
165
166/*2
167*pp is the new element in s
168*returns TRUE (in strat->kHEdgeFound) if
169*-HEcke is allowed
170*-we are in the last componente of the vector
171*-on all axis are monomials (all elements in NotUsedAxis are FALSE)
172*returns FALSE for pLexOrderings,
173*assumes in module case an ordering of type c* !!
174* HEckeTest is only called with strat->kHEdgeFound==FALSE !
175*/
176void HEckeTest (poly pp,kStrategy strat)
177{
178  int   j,k,p;
179
180  strat->kHEdgeFound=FALSE;
181  if (pLexOrder)
182  {
183    return;
184  }
185  if (strat->ak > 1)           /*we are in the module case*/
186  {
187    return; // until ....
188    //if (!pVectorOut)     /*pVectorOut <=> order = c,* */
189    //  return FALSE;
190    //if (pGetComp(pp) < strat->ak) /* ak is the number of the last component */
191    //  return FALSE;
192  }
193  k = 0;
194  p=pIsPurePower(pp);
195  if (p!=0) strat->NotUsedAxis[p] = FALSE;
196  /*- the leading term of pp is a power of the p-th variable -*/
197  for (j=pVariables;j>0; j--)
198  {
199    if (strat->NotUsedAxis[j])
200    {
201      return;
202    }
203  }
204  strat->kHEdgeFound=TRUE;
205}
206
207/*2
208*utilities for TSet, LSet
209*/
210inline static intset initec (int maxnr)
211{
212  return (intset)Alloc(maxnr*sizeof(int));
213}
214
215static inline void enlargeT (TSet* T,int* length,int incr)
216{
217  *T = (TSet)ReAlloc((ADDRESS)(*T),(*length)*sizeof(TObject),
218                                   ((*length)+incr)*sizeof(TObject));
219  (*length) += incr;
220}
221
222void cleanT (kStrategy strat)
223{
224  int i,j;
225  poly  p;
226
227  for (j=0; j<=strat->tl; j++)
228  {
229    p = strat->T[j].p;
230//    pTest(p);
231    strat->T[j].p=NULL;
232    i = -1;
233    loop
234    {
235      i++;
236      if (i>strat->sl)
237      {
238        pDelete(&p);
239        break;
240      }
241      if (p == strat->S[i])
242      {
243        break;
244      }
245    }
246  }
247  strat->tl=-1;
248}
249
250LSet initL ()
251{
252  return (LSet)Alloc(setmax*sizeof(LObject));
253}
254
255static inline void enlargeL (LSet* L,int* length,int incr)
256{
257  LSet h;
258
259  *L = (LSet)ReAlloc((ADDRESS)(*L),(*length)*sizeof(LObject),
260                                   ((*length)+incr)*sizeof(LObject));
261  (*length) += incr;
262}
263
264void initPairtest(kStrategy strat)
265{
266  strat->pairtest = (BOOLEAN *)Alloc0((strat->sl+2)*sizeof(BOOLEAN));
267}
268
269/*2
270*test whether (p1,p2) or (p2,p1) is in L up position length
271*it returns TRUE if yes and the position k
272*/
273BOOLEAN isInPairsetL(int length,poly p1,poly p2,int*  k,kStrategy strat)
274{
275  LObject *p=&(strat->L[length]);
276
277  *k = length;
278  loop
279  {
280    if ((*k) < 0) return FALSE;
281    if (((p1 == (*p).p1) && (p2 == (*p).p2))
282    ||  ((p1 == (*p).p2) && (p2 == (*p).p1)))
283      return TRUE;
284    (*k)--;
285    p--;
286  }
287}
288
289/*2
290*in B all pairs have the same element p on the right
291*it tests whether (q,p) is in B and returns TRUE if yes
292*and the position k
293*/
294BOOLEAN isInPairsetB(poly q,int*  k,kStrategy strat)
295{
296  LObject *p=&(strat->B[strat->Bl]);
297
298  *k = strat->Bl;
299  loop
300  {
301    if ((*k) < 0) return FALSE;
302    if (q == (*p).p1)
303      return TRUE;
304    (*k)--;
305    p--;
306  }
307}
308
309#ifdef KDEBUG
310void K_Test (char *f, int l,kStrategy strat)
311{
312/*2
313*tests, if there is some wrong (deleted) in the set s or in pairs from L
314*/
315  int i;
316  /*- test pair P -*/
317  pDBTest(strat->P.p1,f,l);
318  pDBTest(strat->P.p2,f,l);
319  // pDBTest(strat->P.lcm,f,l);
320  /*- test set s -*/
321  if ((strat->S!=NULL) && (strat->sl>=0))
322  {
323    for (i=0; i<=strat->sl; i++)
324    {
325      pDBTest(strat->S[i],f,l);
326//      if(currQuotient==NULL)
327//      {
328//        if ((strat->ak!=0)
329//        && (pGetComp(strat->S[i])==0))
330//        {
331//          Print("wrong comp. S (0) in %s:%d\n",f,l);
332//        }
333//        else
334//        {
335//          if (pGetComp(strat->S[i])!=0)
336//            Print("wrong comp. S (%d) in %s:%d\n",pGetComp(strat->S[i]),f,l);
337//        }
338//      }
339    }
340  }
341  /*- test set L -*/
342  if ((strat->L!=NULL) && (strat->Ll>=0))
343  {
344    for (i=0; i<=strat->Ll; i++)
345    {
346      pDBTest(strat->L[i].p1,f,l);
347      pDBTest(strat->L[i].p2,f,l);
348      int j,f=0;
349      for(j=0;j<=strat->tl;j++)
350      {
351
352        if((strat->L[i].p1==NULL)
353        ||(strat->L[i].p1==strat->T[j].p))
354        {
355          f=1;
356          break;
357        }
358      }
359      if((f==0)&&(strat->L[i].p1!=NULL))
360        Print("L[%d].p1(%x) not in T ?\n",i,strat->L[i].p1);
361      f=0;
362      for(j=0;j<=strat->tl;j++)
363      {
364        if((strat->L[i].p2==NULL)
365        ||(strat->L[i].p2==strat->T[j].p))
366        {
367          f=1;
368          break;
369        }
370      }
371      if((f==0)&&(strat->L[i].p2!=NULL))
372        Print("L[%d].p2(%x) not in T ?\n",i,strat->L[i].p2);
373      //pDBTest(strat->L[i].lcm,f,l);
374    }
375  }
376/*
377*  #*- test set B -*#
378*  for (i=0; i<=strat->Bl; i++)
379*  {
380*    if (strat->B[i].p1 == (*p)) return ;
381*    if (strat->B[i].p2 == (*p)) return ;
382*  }
383*/
384  /*- test set T -*/
385  if ((strat->T!=NULL) && (strat->tl>=0))
386  {
387    for (i=0; i<=strat->tl; i++)
388    {
389      pDBTest(strat->T[i].p,f,l);
390//      if(currQuotient==NULL)
391//      {
392//        if ((strat->ak!=0)
393//        && (pGetComp(strat->T[i].p)==0))
394//        {
395//          Print("wrong comp. T (0) in %s:%d\n",f,l);
396//        }
397//        else
398//        {
399//          if (pGetComp(strat->T[i].p)!=0)
400//            Print("wrong comp. T (%d) in %s:%d\n",pGetComp(strat->T[i].p),f,l);
401//        }
402//      }
403    }
404  }
405#ifdef PDEBUG
406  idDBTest(strat->Shdl,f,l);
407  if (strat->D!=NULL) idDBTest(strat->D,f,l);
408#endif
409}
410#endif
411
412/*2
413*cancels the i-th polynomial in the standardbase s
414*/
415void deleteInS (int i,kStrategy strat)
416{
417  int j;
418
419  for (j=i; j<strat->sl; j++)
420  {
421    strat->S[j] = strat->S[j+1];
422    strat->ecartS[j] = strat->ecartS[j+1];
423  }
424  if (strat->fromQ!=NULL)
425  {
426    for (j=i; j<strat->sl; j++)
427    {
428      strat->fromQ[j] = strat->fromQ[j+1];
429    }
430  }
431  strat->S[strat->sl] = NULL;
432  strat->sl--;
433}
434
435/*2
436*cancels the j-th polynomial in the set
437*/
438void deleteInL (LSet set, int *length, int j,kStrategy strat)
439{
440  int i;
441
442  if (set[j].lcm!=NULL)
443    pFree1(set[j].lcm);
444  if (set[j].p!=NULL)
445  {
446    if (pNext(set[j].p) == strat->tail)
447    {
448      pFree1(set[j].p);
449      /*- tail belongs to several int spolys -*/
450    }
451    else
452    {
453      // search p in T, if it is there, do not delete it
454      int i=strat->tl;
455      poly p=set[j].p;
456      if (p!=NULL)
457      loop
458      {
459        if (i < 0)
460        {
461          //if (strat->next!=NULL)
462          //{
463          //  strat=strat->next;
464          //  i=strat->tl;
465          //}
466          //else
467          {
468            /* not found : */
469            pDelete(&p);
470            break;
471          }
472        }
473        else
474        {
475          if (strat->T[i].p==p)
476          {
477            /* found : */
478            p=NULL;
479            break;
480          }
481          i--;
482        }
483      }
484    }
485    set[j].p=NULL;
486  }
487  if ((*length)>0)
488  {
489    for (i=j; i < (*length); i++)
490      set[i] = set[i+1];
491  }
492#ifdef KDEBUG
493  memset(&(set[*length]),0,sizeof(LObject));
494#endif
495  (*length)--;
496}
497
498/*2
499*is used after updating the pairset,if the leading term of p
500*devides the leading term of some S[i] it will be canceled
501*/
502void clearS (poly p, int* at, int* k,kStrategy strat)
503{
504  if (!pDivisibleBy(p,strat->S[*at])) return;
505  deleteInS((*at),strat);
506  (*at)--;
507  (*k)--;
508}
509
510/*2
511*enters p at position at in L
512*/
513void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
514{
515  int i;
516
517  if ((*length)>=0)
518  {
519    if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmax);
520    for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
521  }
522  else at = 0;
523  (*set)[at] = p;
524  (*length)++;
525}
526
527/*2
528* computes the normal ecart;
529* used in mora case and if pLexOrder & sugar in bba case
530*/
531void initEcartNormal (LObject* h)
532{
533  h->ecart = pLDeg(h->p,&(h->length))-pFDeg(h->p);
534}
535
536void initEcartBBA (LObject* h)
537{
538  (*h).ecart = 0;
539//#ifdef KDEBUG
540  (*h).length = 0;
541//#endif
542}
543
544void initEcartPairBba (LObject* Lp,poly f,poly g,int ecartF,int ecartG)
545{
546//#ifdef KDEBUG
547  (*Lp).ecart = 0;
548  (*Lp).length = 0;
549//#endif
550}
551
552void initEcartPairMora (LObject* Lp,poly f,poly g,int ecartF,int ecartG)
553{
554  (*Lp).ecart = max(ecartF,ecartG);
555  (*Lp).ecart = (*Lp).ecart-(pFDeg((*Lp).p)-pFDeg((*Lp).lcm));
556//#ifdef KDEBUG
557  (*Lp).length = 0;
558//#endif
559}
560
561/*2
562*if ecart1<=ecart2 it returns TRUE
563*/
564BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
565{
566  return (ecart1 <= ecart2);
567}
568
569/*2
570* put the pair (s[i],p)  into the set B, ecart=ecart(p)
571*/
572void enterOnePair (int i,poly p,int ecart, int isFromQ,kStrategy strat)
573{
574  int      l,j,compare;
575  LObject  Lp;
576
577#ifdef KDEBUG
578  Lp.ecart=0; Lp.length=0;
579  pTest(p);
580#endif
581  /*- computes the lcm(s[i],p) -*/
582  Lp.lcm = pInit();
583  pLcm(p,strat->S[i],Lp.lcm);
584  pSetm(Lp.lcm);
585#ifdef DRING
586//  if ((pDRING) && (pdDFlag(Lp.lcm)==0))
587//  {
588//    for(j=1;j<=pdN;j++)
589//    {
590//      if((Lp.pGetExp(lcm,pdX(j))>0)
591//      &&(Lp.pGetExp(lcm,pdIX(j))>0))
592//      {
593//        pFree1(Lp.lcm);
594//        Lp.lcm=NULL;
595//        return;
596//      }
597//    }
598//    /*delete pairs with lcm contains x_j^a*x_j^(-b)*/
599//  }
600#endif
601  if (strat->sugarCrit)
602  {
603    if(
604#ifdef SDRING
605    (!pSDRING) &&
606#endif
607    (!((strat->ecartS[i]>0)&&(ecart>0)))
608    && pHasNotCF(p,strat->S[i]))
609    {
610    /*
611    *the product criterion has applied for (s,p),
612    *i.e. lcm(s,p)=product of the leading terms of s and p.
613    *Suppose (s,r) is in L and the leading term
614    *of p devides lcm(s,r)
615    *(==> the leading term of p devides the leading term of r)
616    *but the leading term of s does not devide the leading term of r
617    *(notice that tis condition is automatically satisfied if r is still
618    *in S), then (s,r) can be canceled.
619    *This should be done here because the
620    *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
621    */
622      strat->cp++;
623      pFree1(Lp.lcm);
624      Lp.lcm=NULL;
625      return;
626    }
627    else
628      Lp.ecart = max(ecart,strat->ecartS[i]);
629    if (strat->fromT && (strat->ecartS[i]>ecart))
630    {
631      pFree1(Lp.lcm);
632      Lp.lcm=NULL;
633      return;
634      /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
635    }
636    /*
637    *the set B collects the pairs of type (S[j],p)
638    *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
639    *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
640    *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
641    */
642#ifdef SDRING
643    if (!pSDRING)
644#endif
645    {
646      j = strat->Bl;
647      loop
648      {
649        if (j < 0)  break;
650        compare=pDivComp(strat->B[j].lcm,Lp.lcm);
651        if ((compare==1)
652        &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
653        {
654          strat->c3++;
655          if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
656          {
657            pFree1(Lp.lcm);
658            return;
659          }
660          break;
661        }
662        else
663        if ((compare ==-1)
664        && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
665        {
666          deleteInL(strat->B,&strat->Bl,j,strat);
667          strat->c3++;
668        }
669        j--;
670      }
671    }
672  }
673  else /*sugarcrit*/
674  {
675    if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
676#ifdef SDRING
677    (!pSDRING) &&
678#endif
679    pHasNotCF(p,strat->S[i]))
680    {
681    /*
682    *the product criterion has applied for (s,p),
683    *i.e. lcm(s,p)=product of the leading terms of s and p.
684    *Suppose (s,r) is in L and the leading term
685    *of p devides lcm(s,r)
686    *(==> the leading term of p devides the leading term of r)
687    *but the leading term of s does not devide the leading term of r
688    *(notice that tis condition is automatically satisfied if r is still
689    *in S), then (s,r) can be canceled.
690    *This should be done here because the
691    *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
692    */
693      strat->cp++;
694      pFree1(Lp.lcm);
695      Lp.lcm=NULL;
696      return;
697    }
698    if (strat->fromT && (strat->ecartS[i]>ecart))
699    {
700      pFree1(Lp.lcm);
701      Lp.lcm=NULL;
702      return;
703      /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
704    }
705    /*
706    *the set B collects the pairs of type (S[j],p)
707    *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
708    *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
709    *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
710    */
711#ifdef SDRING
712    if (!pSDRING)
713#endif
714    for(j = strat->Bl;j>=0;j--)
715    {
716      compare=pDivComp(strat->B[j].lcm,Lp.lcm);
717      if (compare==1)
718      {
719        strat->c3++;
720        if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
721        {
722          pFree1(Lp.lcm);
723          return;
724        }
725        break;
726      }
727      else
728      if (compare ==-1)
729      {
730        deleteInL(strat->B,&strat->Bl,j,strat);
731        strat->c3++;
732      }
733    }
734  }
735  /*
736  *the pair (S[i],p) enters B if the spoly != 0
737  */
738  /*-  compute the short s-polynomial -*/
739  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
740    pNorm(p);
741  if ((strat->S[i]==NULL) || (p==NULL))
742    return;
743  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
744    Lp.p=NULL;
745  else
746#ifdef SDRING
747  // spSpolyShortBba will not work for SDRING
748  if (pSDRING)
749  {
750    Lp.p=spSpolyCreate(strat->S[i],p,strat->kNoether,strat->spSpolyLoop);
751    if (Lp.p!=NULL)
752      pDelete(&pNext(Lp.p));
753  }
754  else
755#endif
756  {
757#ifdef KDEBUG
758    pTest(strat->S[i]);
759    pTest(p);
760#endif
761    Lp.p = spSpolyShortBba(strat->S[i],p);
762  }
763  if (Lp.p == NULL)
764  {
765    /*- the case that the s-poly is 0 -*/
766    if (strat->pairtest==NULL) initPairtest(strat);
767    strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
768    strat->pairtest[strat->sl+1] = TRUE;
769    /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
770    /*
771    *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
772    *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
773    *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
774    *term of p devides the lcm(s,r)
775    *(this canceling should be done here because
776    *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
777    *the first case is handeled in chainCrit
778    */
779    if (Lp.lcm!=NULL) pFree1(Lp.lcm);
780  }
781  else
782  {
783    /*- the pair (S[i],p) enters B -*/
784    Lp.p1 = strat->S[i];
785    Lp.p2 = p;
786    pNext(Lp.p) = strat->tail;
787    strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
788    if (TEST_OPT_INTSTRATEGY)
789    {
790      nDelete(&(Lp.p->coef));
791    }
792    l = strat->posInL(strat->B,strat->Bl,Lp,strat);
793    enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
794  }
795#ifdef DRING
796  if ((pDRING) && (pdDFlag(strat->S[i])==0) && (pdDFlag(p)==0))
797  {
798    Lp.lcm=pOne();
799    pdLcm(strat->S[i],p,Lp.lcm);
800    Lp.p1 = strat->S[i];
801    Lp.p2 = p;
802#ifdef KDEBUG
803    pTest(p);
804    pTest(strat->S[i]);
805#endif
806    Lp.p = pdSpolyCreate(strat->S[i],p);
807    if (Lp.p!=NULL)
808    {
809#ifdef KDEBUG
810      pTest(p);
811      pTest(strat->S[i]);
812#endif
813      /*spoly of p and S[i] bzgl Lp.lcm*/
814      strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
815      l = strat->posInL(strat->B,strat->Bl,Lp,strat);
816      enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
817    }
818  }
819#endif
820}
821
822/*2
823* put the pair (s[i],p) into the set L, ecart=ecart(p)
824* in the case that s forms a SB of (s)
825*/
826void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat)
827{
828  int      l,j,compare;
829  LObject  Lp;
830
831  Lp.lcm = pInit();
832  pLcm(p,strat->S[i],Lp.lcm);
833  pSetm(Lp.lcm);
834  if(
835#ifdef SDRING
836  (!pSDRING) &&
837#endif
838  (pHasNotCF(p,strat->S[i])))
839  {
840    strat->cp++;
841    pFree1(Lp.lcm);
842    Lp.lcm=NULL;
843    return;
844  }
845  for(j = strat->Ll;j>=0;j--)
846  {
847    compare=pDivComp(strat->L[j].lcm,Lp.lcm);
848    if ((compare==1) || (pEqual(strat->L[j].lcm,Lp.lcm)))
849    {
850      strat->c3++;
851      pFree1(Lp.lcm);
852      return;
853    }
854    else if (compare ==-1)
855    {
856      deleteInL(strat->L,&strat->Ll,j,strat);
857      strat->c3++;
858    }
859  }
860  /*-  compute the short s-polynomial -*/
861
862#ifdef SDRING
863  // spSpolyShortBba will not work for SDRING
864  if (pSDRING)
865  {
866    Lp.p=spSpolyCreate(strat->S[i],p,strat->kNoether,strat->spSpolyLoop);
867    if (Lp.p!=NULL)
868      pDelete(&pNext(Lp.p));
869  }
870  else
871#endif
872  {
873    Lp.p = spSpolyShortBba(strat->S[i],p);
874  }
875  if (Lp.p == NULL)
876  {
877     pFree1(Lp.lcm);
878  }
879  else
880  {
881    /*- the pair (S[i],p) enters B -*/
882    Lp.p1 = strat->S[i];
883    Lp.p2 = p;
884    pNext(Lp.p) = strat->tail;
885    strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
886    if (TEST_OPT_INTSTRATEGY)
887    {
888      nDelete(&(Lp.p->coef));
889    }
890    l = strat->posInL(strat->L,strat->Ll,Lp,strat);
891    enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
892  }
893#ifdef DRING
894  if ((pDRING) && (pdDFlag(strat->S[i])==0) && (pdDFlag(p)==0))
895  {
896    Lp.lcm=pOne();
897    pdLcm(strat->S[i],p,Lp.lcm);
898    Lp.p1 = strat->S[i];
899    Lp.p2 = p;
900#ifdef KDEBUG
901    pTest(p);
902    pTest(strat->S[i]);
903#endif
904    Lp.p = pdSpolyCreate(strat->S[i],p);
905    if (Lp.p!=NULL)
906    {
907#ifdef KDEBUG
908      pTest(p);
909      pTest(strat->S[i]);
910#endif
911      /*spoly of p and S[i] bzgl Lp.lcm*/
912      strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
913      l = strat->posInL(strat->B,strat->Bl,Lp,strat);
914      enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
915    }
916  }
917#endif
918}
919
920/*2
921*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
922*using the chain-criterion in B and L and enters B to L
923*/
924void chainCrit (poly p,int ecart,kStrategy strat)
925{
926  int i,j,l;
927
928  /*
929  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
930  *In this case all elements in B such
931  *that their lcm is divisible by the leading term of S[i] can be canceled
932  */
933  if (strat->pairtest!=NULL)
934  {
935#ifdef SDRING
936    if (!pSDRING)
937#endif
938    {
939      /*- i.e. there is an i with pairtest[i]==TRUE -*/
940      for (j=0; j<=strat->sl; j++)
941      {
942        if (strat->pairtest[j])
943        {
944          for (i=strat->Bl; i>=0; i--)
945          {
946            if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
947            {
948              deleteInL(strat->B,&strat->Bl,i,strat);
949              strat->c3++;
950            }
951          }
952        }
953      }
954    }
955    Free((ADDRESS)strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
956    strat->pairtest=NULL;
957  }
958  if ((strat->Gebauer || strat->fromT)
959#ifdef SDRING
960  && (!pSDRING)
961#endif
962  )
963  {
964    if (strat->sugarCrit)
965    {
966    /*
967    *suppose L[j] == (s,r) and p/lcm(s,r)
968    *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
969    *and in case the sugar is o.k. then L[j] can be canceled
970    */
971      for (j=strat->Ll; j>=0; j--)
972      {
973        if (sugarDivisibleBy(ecart,strat->L[j].ecart)
974        && ((pNext(strat->L[j].p) == strat->tail) || (pOrdSgn==1))
975        && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
976        {
977          if (strat->L[j].p == strat->tail)
978          {
979            deleteInL(strat->L,&strat->Ll,j,strat);
980            strat->c3++;
981          }
982        }
983      }
984      /*
985      *this is GEBAUER-MOELLER:
986      *in B all elements with the same lcm except the "best"
987      *(i.e. the last one in B with this property) will be canceled
988      */
989      j = strat->Bl;
990      loop /*cannot be changed into a for !!! */
991      {
992        if (j <= 0) break;
993        i = j-1;
994        loop
995        {
996          if (i <  0) break;
997          if (pEqual(strat->B[j].lcm,strat->B[i].lcm))
998          {
999            strat->c3++;
1000            if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
1001            {
1002              deleteInL(strat->B,&strat->Bl,i,strat);
1003              j--;
1004            }
1005            else
1006            {
1007              deleteInL(strat->B,&strat->Bl,j,strat);
1008              break;
1009            }
1010          }
1011          i--;
1012        }
1013        j--;
1014      }
1015    }
1016    else /*sugarCrit*/
1017    {
1018      /*
1019      *suppose L[j] == (s,r) and p/lcm(s,r)
1020      *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
1021      *and in case the sugar is o.k. then L[j] can be canceled
1022      */
1023      for (j=strat->Ll; j>=0; j--)
1024      {
1025        if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
1026        {
1027          if ((pNext(strat->L[j].p) == strat->tail)||(pOrdSgn==1))
1028          {
1029            deleteInL(strat->L,&strat->Ll,j,strat);
1030            strat->c3++;
1031          }
1032        }
1033      }
1034      /*
1035      *this is GEBAUER-MOELLER:
1036      *in B all elements with the same lcm except the "best"
1037      *(i.e. the last one in B with this property) will be canceled
1038      */
1039      j = strat->Bl;
1040      loop   /*cannot be changed into a for !!! */
1041      {
1042        if (j <= 0) break;
1043        for(i=j-1; i>=0; i--)
1044        {
1045          if (pEqual(strat->B[j].lcm,strat->B[i].lcm))
1046          {
1047            strat->c3++;
1048            deleteInL(strat->B,&strat->Bl,i,strat);
1049            j--;
1050          }
1051        }
1052        j--;
1053      }
1054    }
1055    /*
1056    *the elements of B enter L/their order with respect to B is kept
1057    *j = posInL(L,j,B[i]) would permutate the order
1058    *if once B is ordered different from L
1059    *then one should use j = posInL(L,Ll,B[i])
1060    */
1061    j = strat->Ll+1;
1062    for (i=strat->Bl; i>=0; i--)
1063    {
1064      j = strat->posInL(strat->L,j-1,strat->B[i],strat);
1065      enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
1066    }
1067    strat->Bl = -1;
1068  }
1069  else
1070  {
1071#ifdef SDRING
1072    if (!pSDRING)
1073#endif
1074    for (j=strat->Ll; j>=0; j--)
1075    {
1076      if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
1077      {
1078        if ((pNext(strat->L[j].p) == strat->tail)||(pOrdSgn==1))
1079        {
1080          deleteInL(strat->L,&strat->Ll,j,strat);
1081          strat->c3++;
1082        }
1083      }
1084    }
1085    /*
1086    *this is our MODIFICATION of GEBAUER-MOELLER:
1087    *First the elements of B enter L,
1088    *then we fix a lcm and the "best" element in L
1089    *(i.e the last in L with this lcm and of type (s,p))
1090    *and cancel all the other elements of type (r,p) with this lcm
1091    *except the case the element (s,r) has also the same lcm
1092    *and is on the worst position with respect to (s,p) and (r,p)
1093    */
1094    /*
1095    *B enters to L/their order with respect to B is permutated for elements
1096    *B[i].p with the same leading term
1097    */
1098    j = strat->Ll;
1099    for (i=strat->Bl; i>=0; i--)
1100    {
1101      j = strat->posInL(strat->L,j,strat->B[i],strat);
1102      enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
1103    }
1104    strat->Bl = -1;
1105    j = strat->Ll;
1106#ifdef SDRING
1107    if (!pSDRING)
1108#endif
1109    loop  /*cannot be changed into a for !!! */
1110    {
1111      if (j <= 0)
1112      {
1113        /*now L[0] cannot be canceled any more and the tail can be removed*/
1114        if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
1115        break;
1116      }
1117      if (strat->L[j].p2 == p)
1118      {
1119        i = j-1;
1120        loop
1121        {
1122          if (i < 0)  break;
1123          if ((strat->L[i].p2 == p) && pEqual(strat->L[j].lcm,strat->L[i].lcm))
1124          {
1125            /*L[i] could be canceled but we search for a better one to cancel*/
1126            strat->c3++;
1127            if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
1128            && (pNext(strat->L[l].p) == strat->tail)
1129            && (!pEqual(strat->L[i].p,strat->L[l].p))
1130            && pDivisibleBy(p,strat->L[l].lcm))
1131            {
1132              /*
1133              *"NOT equal(...)" because in case of "equal" the element L[l]
1134              *is "older" and has to be from theoretical point of view behind
1135              *L[i], but we do not want to reorder L
1136              */
1137              strat->L[i].p2 = strat->tail;
1138              /*
1139              *L[l] will be canceled, we cannot cancel L[i] later on,
1140              *so we mark it with "tail"
1141              */
1142              deleteInL(strat->L,&strat->Ll,l,strat);
1143              i--;
1144            }
1145            else
1146            {
1147              deleteInL(strat->L,&strat->Ll,i,strat);
1148            }
1149            j--;
1150          }
1151          i--;
1152        }
1153      }
1154      else if (strat->L[j].p2 == strat->tail)
1155      {
1156        /*now L[j] cannot be canceled any more and the tail can be removed*/
1157        strat->L[j].p2 = p;
1158      }
1159      j--;
1160    }
1161  }
1162}
1163
1164/*2
1165*(s[0],h),...,(s[k],h) will be put to the pairset L
1166*/
1167void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat)
1168{
1169
1170  if ((strat->syzComp==0)
1171  || (pGetComp(h)<=strat->syzComp))
1172  {
1173    int j;
1174    BOOLEAN new_pair=FALSE;
1175
1176    if (pGetComp(h)==0)
1177    {
1178      /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
1179      if ((isFromQ)&&(strat->fromQ!=NULL))
1180      {
1181        for (j=0; j<=k; j++)
1182        {
1183          if (!strat->fromQ[j])
1184          {
1185            new_pair=TRUE;
1186            enterOnePair(j,h,ecart,isFromQ,strat);
1187          //Print("j:%d, Ll:%d\n",j,strat->Ll);
1188          }
1189        }
1190      }
1191      else
1192      {
1193        new_pair=TRUE;
1194        for (j=0; j<=k; j++)
1195        {
1196          enterOnePair(j,h,ecart,isFromQ,strat);
1197          //Print("j:%d, Ll:%d\n",j,strat->Ll);
1198        }
1199      }
1200    }
1201    else
1202    {
1203      for (j=0; j<=k; j++)
1204      {
1205        if ((pGetComp(h)==pGetComp(strat->S[j]))
1206        || (pGetComp(strat->S[j])==0))
1207        {
1208          new_pair=TRUE;
1209          enterOnePair(j,h,ecart,isFromQ,strat);
1210        //Print("j:%d, Ll:%d\n",j,strat->Ll);
1211        }
1212      }
1213    }
1214    if (new_pair) chainCrit(h,ecart,strat);
1215  }
1216}
1217
1218/*2
1219*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
1220*superfluous elements in S will be deleted
1221*/
1222void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat)
1223{
1224  int j=pos;
1225
1226  initenterpairs(h,k,ecart,0,strat);
1227  if ((!strat->fromT)
1228  && ((strat->syzComp==0)
1229    ||(pGetComp(h)<=strat->syzComp)))
1230  {
1231    //Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
1232    loop
1233    {
1234      if (j > k) break;
1235      clearS(h,&j,&k,strat);
1236      j++;
1237    }
1238    //Print("end clearS sl=%d\n",strat->sl);
1239  }
1240 // PrintS("end enterpairs\n");
1241}
1242
1243/*2
1244*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
1245*superfluous elements in S will be deleted
1246*/
1247void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat)
1248{
1249  int j;
1250
1251  for (j=0; j<=k; j++)
1252  {
1253    if ((pGetComp(h)==pGetComp(strat->S[j]))
1254    || (0==pGetComp(strat->S[j])))
1255    {
1256      enterOnePairSpecial(j,h,ecart,strat);
1257    }
1258  }
1259  j=pos;
1260  loop
1261  {
1262    if (j > k) break;
1263    clearS(h,&j,&k,strat);
1264    j++;
1265  }
1266}
1267
1268/*2
1269*constructs the pairset at the beginning
1270*of the buchberger/mora algorithm
1271*/
1272void pairs (kStrategy strat)
1273{
1274  int j,i;
1275//  Print("pairs:sl=%d\n",strat->sl);
1276//  for (i=0; i<=strat->sl; i++)
1277//  {
1278//    Print("s%d:",i);pWrite(strat->S[i]);
1279//  }
1280  if (strat->fromQ!=NULL)
1281  {
1282    for (i=1; i<=strat->sl; i++)
1283    {
1284      initenterpairs(strat->S[i],i-1,strat->ecartS[i],strat->fromQ[i],strat);
1285    }
1286  }
1287  else
1288  {
1289    for (i=1; i<=strat->sl; i++)
1290    {
1291      initenterpairs(strat->S[i],i-1,strat->ecartS[i],0,strat);
1292    }
1293  }
1294  /*deletes superfluous elements in S*/
1295  i = -1;
1296  loop
1297  {
1298    i++;
1299    if (i >= strat->sl) break;
1300    if ((strat->syzComp==0) || (pGetComp(strat->S[i])<=strat->syzComp))
1301    {
1302      j=i;
1303      loop
1304      {
1305        j++;
1306        if (j > strat->sl) break;
1307        if (pDivisibleBy(strat->S[i],strat->S[j]))
1308        {
1309        //  Print("delete %d=",j);
1310        //  wrp(strat->S[j]);
1311        //  Print(" wegen %d=",i);
1312        //  wrp(strat->S[i]);
1313        //  Print("( fromQ=%d)\n", (strat->fromQ) ? strat->fromQ[j]:0);
1314          if ((strat->fromQ==NULL) || (strat->fromQ[j]==0))
1315          {
1316            deleteInS(j,strat);
1317            j--;
1318          }
1319        }
1320      }
1321    }
1322  }
1323}
1324
1325/*2
1326*reorders  s with respect to posInS,
1327*suc is the first changed index or zero
1328*/
1329void reorderS (int* suc,kStrategy strat)
1330{
1331  int i,j,at,ecart;
1332  int fq=0;
1333  poly  p;
1334
1335  *suc = -1;
1336  for (i=1; i<=strat->sl; i++)
1337  {
1338    at = posInS(strat->S,i-1,strat->S[i]);
1339    if (at != i)
1340    {
1341      if ((*suc > at) || (*suc == -1)) *suc = at;
1342      p = strat->S[i];
1343      ecart = strat->ecartS[i];
1344      if (strat->fromQ!=NULL) fq=strat->fromQ[i];
1345      for (j=i; j>=at+1; j--)
1346      {
1347        strat->S[j] = strat->S[j-1];
1348        strat->ecartS[j] = strat->ecartS[j-1];
1349      }
1350      strat->S[at] = p;
1351      strat->ecartS[at] = ecart;
1352      if (strat->fromQ!=NULL)
1353      {
1354        for (j=i; j>=at+1; j--)
1355        {
1356          strat->fromQ[j] = strat->fromQ[j-1];
1357        }
1358        strat->fromQ[at]=fq;
1359      }
1360    }
1361  }
1362}
1363
1364
1365/*2
1366*looks up the position of p in set
1367*set[0] is the smallest with respect to the ordering-procedure
1368*pComp
1369*/
1370int posInS (polyset set,int length,poly p)
1371{
1372  if(length==-1) return 0;
1373//  pTest(set[length]);
1374//  pTest(p);
1375  int i;
1376  int an = 0;
1377  int en= length;
1378  if (pMixedOrder)
1379  {
1380    int o=pWTotaldegree(p);
1381    int oo=pWTotaldegree(set[length]);
1382
1383    if ((oo<o)
1384    || ((o==oo) && (pComp0(set[length],p)!= pOrdSgn)))
1385      return length+1;
1386
1387    loop
1388    {
1389      if (an >= en-1)
1390      {
1391        if ((pWTotaldegree(set[an])>=o) && (pComp0(set[an],p) == pOrdSgn))
1392        {
1393          return an;
1394        }
1395        return en;
1396      }
1397      i=(an+en) / 2;
1398      if ((pWTotaldegree(set[an])>=o)
1399      && (pComp0(set[i],p) == pOrdSgn)) en=i;
1400      else                              an=i;
1401    }
1402  }
1403  else
1404  {
1405    if (pComp0(set[length],p)!= pOrdSgn)
1406      return length+1;
1407
1408    loop
1409    {
1410      if (an >= en-1)
1411      {
1412        if (pComp0(set[an],p) == pOrdSgn) return an;
1413        return en;
1414      }
1415      i=(an+en) / 2;
1416      if (pComp0(set[i],p) == pOrdSgn) en=i;
1417      else                             an=i;
1418    }
1419  }
1420}
1421
1422
1423/*2
1424* looks up the position of p in set
1425* the position is the last one
1426*/
1427int posInT0 (const TSet set,const int length,const LObject &p)
1428{
1429  return (length+1);
1430}
1431
1432
1433/*2
1434* looks up the position of p in T
1435* set[0] is the smallest with respect to the ordering-procedure
1436* pComp
1437*/
1438int posInT1 (const TSet set,const int length,const LObject &p)
1439{
1440  if (length==-1) return 0;
1441
1442  if (pComp0(set[length].p,p.p)!= pOrdSgn) return length+1;
1443
1444  int i;
1445  int an = 0;
1446  int en= length;
1447
1448  loop
1449  {
1450    if (an >= en-1)
1451    {
1452      if (pComp0(set[an].p,p.p) == pOrdSgn) return an;
1453      return en;
1454    }
1455    i=(an+en) / 2;
1456    if (pComp0(set[i].p,p.p) == pOrdSgn) en=i;
1457    else                                 an=i;
1458  }
1459}
1460
1461/*2
1462* looks up the position of p in T
1463* set[0] is the smallest with respect to the ordering-procedure
1464* length
1465*/
1466int posInT2 (const TSet set,const int length,const LObject &p)
1467{
1468  if (length==-1)
1469    return 0;
1470  if (set[length].length<p.length)
1471    return length+1;
1472
1473  int i;
1474  int an = 0;
1475  int en= length;
1476
1477  loop
1478  {
1479    if (an >= en-1)
1480    {
1481      if (set[an].length>p.length) return an;
1482      return en;
1483    }
1484    i=(an+en) / 2;
1485    if (set[i].length>p.length) en=i;
1486    else                        an=i;
1487  }
1488}
1489
1490/*2
1491* looks up the position of p in T
1492* set[0] is the smallest with respect to the ordering-procedure
1493* totaldegree,pComp
1494*/
1495int posInT11 (const TSet set,const int length,const LObject &p)
1496/*{
1497 * int j=0;
1498 * int o;
1499 *
1500 * o = pFDeg(p.p);
1501 * loop
1502 * {
1503 *   if ((pFDeg(set[j].p) > o)
1504 *   || ((pFDeg(set[j].p) == o) && (pComp0(set[j].p,p.p) == pOrdSgn)))
1505 *   {
1506 *     return j;
1507 *   }
1508 *   j++;
1509 *   if (j > length) return j;
1510 * }
1511 *}
1512 */
1513{
1514  if (length==-1) return 0;
1515
1516  int o = pFDeg(p.p);
1517  int op = pFDeg(set[length].p);
1518
1519  if ((op < o)
1520  || ((op == o) && (pComp0(set[length].p,p.p) != pOrdSgn)))
1521    return length+1;
1522
1523  int i;
1524  int an = 0;
1525  int en= length;
1526
1527  loop
1528  {
1529    if (an >= en-1)
1530    {
1531      op= pFDeg(set[an].p);
1532      if ((op > o)
1533      || (( op == o) && (pComp0(set[an].p,p.p) == pOrdSgn)))
1534        return an;
1535      return en;
1536    }
1537    i=(an+en) / 2;
1538    op = pFDeg(set[i].p);
1539    if (( op > o)
1540    || (( op == o) && (pComp0(set[i].p,p.p) == pOrdSgn)))
1541      en=i;
1542    else
1543      an=i;
1544  }
1545}
1546
1547/*2
1548* looks up the position of p in T
1549* set[0] is the smallest with respect to the ordering-procedure
1550* totaldegree,pComp
1551*/
1552int posInT110 (const TSet set,const int length,const LObject &p)
1553{
1554  if (length==-1) return 0;
1555
1556  int o = pFDeg(p.p);
1557  int op = pFDeg(set[length].p);
1558
1559  if (( op < o)
1560  || (( op == o) && (set[length].length<p.length))
1561  || (( op == o) && (set[length].length == p.length)
1562     && (pComp0(set[length].p,p.p) != pOrdSgn)))
1563    return length+1;
1564
1565  int i;
1566  int an = 0;
1567  int en= length;
1568  loop
1569  {
1570    if (an >= en-1)
1571    {
1572      op = pFDeg(set[an].p);
1573      if (( op > o)
1574      || (( op == o) && (set[an].length > p.length))
1575      || (( op == o) && (set[an].length == p.length)
1576         && (pComp0(set[an].p,p.p) == pOrdSgn)))
1577        return an;
1578      return en;
1579    }
1580    i=(an+en) / 2;
1581    op = pFDeg(set[i].p);
1582    if (( op > o)
1583    || (( op == o) && (set[i].length > p.length))
1584    || (( op == o) && (set[i].length == p.length)
1585       && (pComp0(set[i].p,p.p) == pOrdSgn)))
1586      en=i;
1587    else
1588      an=i;
1589  }
1590}
1591
1592/*2
1593* looks up the position of p in set
1594* set[0] is the smallest with respect to the ordering-procedure
1595* pFDeg
1596*/
1597int posInT13 (const TSet set,const int length,const LObject &p)
1598{
1599  if (length==-1) return 0;
1600
1601  int o = pFDeg(p.p);
1602
1603  if (pFDeg(set[length].p) <= o)
1604    return length+1;
1605
1606  int i;
1607  int an = 0;
1608  int en= length;
1609  loop
1610  {
1611    if (an >= en-1)
1612    {
1613      if (pFDeg(set[an].p) > o)
1614        return an;
1615      return en;
1616    }
1617    i=(an+en) / 2;
1618    if (pFDeg(set[i].p) > o)
1619      en=i;
1620    else
1621      an=i;
1622  }
1623}
1624
1625/*2
1626* looks up the position of p in set
1627* set[0] is the smallest with respect to the ordering-procedure
1628* maximaldegree, pComp
1629*/
1630int posInT15 (const TSet set,const int length,const LObject &p)
1631/*{
1632 *int j=0;
1633 * int o;
1634 *
1635 * o = pFDeg(p.p)+p.ecart;
1636 * loop
1637 * {
1638 *   if ((pFDeg(set[j].p)+set[j].ecart > o)
1639 *   || ((pFDeg(set[j].p)+set[j].ecart == o)
1640 *     && (pComp0(set[j].p,p.p) == pOrdSgn)))
1641 *   {
1642 *     return j;
1643 *   }
1644 *   j++;
1645 *   if (j > length) return j;
1646 * }
1647 *}
1648 */
1649{
1650  if (length==-1) return 0;
1651
1652  int o = pFDeg(p.p) + p.ecart;
1653  int op = pFDeg(set[length].p)+set[length].ecart;
1654
1655  if ((op < o)
1656  || ((op == o)
1657     && (pComp0(set[length].p,p.p) != pOrdSgn)))
1658    return length+1;
1659
1660  int i;
1661  int an = 0;
1662  int en= length;
1663  loop
1664  {
1665    if (an >= en-1)
1666    {
1667      op = pFDeg(set[an].p)+set[an].ecart;
1668      if (( op > o)
1669      || (( op  == o) && (pComp0(set[an].p,p.p) == pOrdSgn)))
1670        return an;
1671      return en;
1672    }
1673    i=(an+en) / 2;
1674    op = pFDeg(set[i].p)+set[i].ecart;
1675    if (( op > o)
1676    || (( op == o) && (pComp0(set[i].p,p.p) == pOrdSgn)))
1677      en=i;
1678    else
1679      an=i;
1680  }
1681}
1682
1683/*2
1684* looks up the position of p in set
1685* set[0] is the smallest with respect to the ordering-procedure
1686* pFDeg+ecart, ecart, pComp
1687*/
1688int posInT17 (const TSet set,const int length,const LObject &p)
1689/*
1690*{
1691* int j=0;
1692* int  o;
1693*
1694*  o = pFDeg(p.p)+p.ecart;
1695*  loop
1696*  {
1697*    if ((pFDeg(set[j].p)+set[j].ecart > o)
1698*    || (((pFDeg(set[j].p)+set[j].ecart == o)
1699*      && (set[j].ecart < p.ecart)))
1700*    || ((pFDeg(set[j].p)+set[j].ecart == o)
1701*      && (set[j].ecart==p.ecart)
1702*      && (pComp0(set[j].p,p.p)==pOrdSgn)))
1703*      return j;
1704*    j++;
1705*    if (j > length) return j;
1706*  }
1707* }
1708*/
1709{
1710  if (length==-1) return 0;
1711
1712  int o = pFDeg(p.p) + p.ecart;
1713  int op = pFDeg(set[length].p)+set[length].ecart;
1714
1715  if ((op < o)
1716  || (( op == o) && (set[length].ecart > p.ecart))
1717  || (( op == o) && (set[length].ecart==p.ecart)
1718     && (pComp0(set[length].p,p.p) != pOrdSgn)))
1719    return length+1;
1720
1721  int i;
1722  int an = 0;
1723  int en= length;
1724  loop
1725  {
1726    if (an >= en-1)
1727    {
1728      op = pFDeg(set[an].p)+set[an].ecart;
1729      if (( op > o)
1730      || (( op == o) && (set[an].ecart < p.ecart))
1731      || (( op  == o) && (set[an].ecart==p.ecart)
1732         && (pComp0(set[an].p,p.p) == pOrdSgn)))
1733        return an;
1734      return en;
1735    }
1736    i=(an+en) / 2;
1737    op = pFDeg(set[i].p)+set[i].ecart;
1738    if ((op > o)
1739    || (( op == o) && (set[i].ecart < p.ecart))
1740    || (( op == o) && (set[i].ecart == p.ecart)
1741       && (pComp0(set[i].p,p.p) == pOrdSgn)))
1742      en=i;
1743    else
1744      an=i;
1745  }
1746}
1747/*2
1748* looks up the position of p in set
1749* set[0] is the smallest with respect to the ordering-procedure
1750* pGetComp, pFDeg+ecart, ecart, pComp
1751*/
1752int posInT17_c (const TSet set,const int length,const LObject &p)
1753{
1754  if (length==-1) return 0;
1755
1756  int cc = (-1+2*currRing->order[0]==ringorder_c);
1757  /* cc==1 for (c,..), cc==-1 for (C,..) */
1758  int o = pFDeg(p.p) + p.ecart;
1759  int c = pGetComp(p.p)*cc;
1760
1761  if (pGetComp(set[length].p)*cc < c)
1762    return length+1;
1763  if (pGetComp(set[length].p)*cc == c)
1764  {
1765    int op = pFDeg(set[length].p)+set[length].ecart;
1766    if ((op < o)
1767    || ((op == o) && (set[length].ecart > p.ecart))
1768    || ((op == o) && (set[length].ecart==p.ecart)
1769       && (pComp0(set[length].p,p.p) != pOrdSgn)))
1770      return length+1;
1771  }
1772
1773  int i;
1774  int an = 0;
1775  int en= length;
1776  loop
1777  {
1778    if (an >= en-1)
1779    {
1780      if (pGetComp(set[an].p)*cc < c)
1781        return en;
1782      if (pGetComp(set[an].p)*cc == c)
1783      {
1784        int op = pFDeg(set[an].p)+set[an].ecart;
1785        if ((op > o)
1786        || ((op == o) && (set[an].ecart < p.ecart))
1787        || ((op == o) && (set[an].ecart==p.ecart)
1788           && (pComp0(set[an].p,p.p) == pOrdSgn)))
1789          return an;
1790      }
1791      return en;
1792    }
1793    i=(an+en) / 2;
1794    if (pGetComp(set[i].p)*cc > c)
1795      en=i;
1796    else if (pGetComp(set[i].p)*cc == c)
1797    {
1798      int op = pFDeg(set[i].p)+set[i].ecart;
1799      if ((op > o)
1800      || ((op == o) && (set[i].ecart < p.ecart))
1801      || ((op == o) && (set[i].ecart == p.ecart)
1802         && (pComp0(set[i].p,p.p) == pOrdSgn)))
1803        en=i;
1804      else
1805        an=i;
1806    }
1807    else
1808      an=i;
1809  }
1810}
1811
1812/*2
1813* looks up the position of p in set
1814* set[0] is the smallest with respect to
1815* ecart, pFDeg, length
1816*/
1817int posInT19 (const TSet set,const int length,const LObject &p)
1818{
1819  if (length==-1) return 0;
1820
1821  int o = p.ecart;
1822
1823  if (set[length].ecart < o)
1824    return length+1;
1825  if (set[length].ecart == o)
1826  {
1827     int oo=pFDeg(set[length].p);
1828     int op=pFDeg(p.p);
1829     if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
1830       return length+1;
1831  }
1832
1833  int i;
1834  int an = 0;
1835  int en= length;
1836  loop
1837  {
1838    if (an >= en-1)
1839    {
1840      if (set[an].ecart > o)
1841        return an;
1842      if (set[an].ecart == o)
1843      {
1844         int oo=pFDeg(set[an].p);
1845         int op=pFDeg(p.p);
1846         if((oo > op)
1847         || ((oo==op) && (set[an].length > p.length)))
1848           return an;
1849      }
1850      return en;
1851    }
1852    i=(an+en) / 2;
1853    if (set[i].ecart > o)
1854      en=i;
1855    else if (set[i].ecart == o)
1856    {
1857       int oo=pFDeg(set[i].p);
1858       int op=pFDeg(p.p);
1859       if ((oo > op)
1860       || ((oo == op) && (set[i].length > p.length)))
1861         en=i;
1862       else
1863        an=i;
1864    }
1865    else
1866      an=i;
1867  }
1868}
1869
1870/*2
1871*looks up the position of polynomial p in set
1872*set[length] is the smallest element in set with respect
1873*to the ordering-procedure pComp
1874*/
1875int posInLSpecial (const LSet set, const int length,
1876                   const LObject &p,const kStrategy strat)
1877{
1878  if (length<0) return 0;
1879
1880  int d=pFDeg(p.p);
1881  int op=pFDeg(set[length].p);
1882
1883  if ((op > d)
1884  || ((op == d) && (p.p1!=NULL)&&(set[length].p1==NULL))
1885  || (pComp0(set[length].p,p.p)== pOrdSgn))
1886     return length+1;
1887
1888  int i;
1889  int an = 0;
1890  int en= length;
1891  loop
1892  {
1893    if (an >= en-1)
1894    {
1895      op=pFDeg(set[an].p);
1896      if ((op > d)
1897      || ((op == d) && (p.p1!=NULL) && (set[an].p1==NULL))
1898      || (pComp0(set[an].p,p.p)== pOrdSgn))
1899         return en;
1900      return an;
1901    }
1902    i=(an+en) / 2;
1903    op=pFDeg(set[i].p);
1904    if ((op>d)
1905    || ((op==d) && (p.p1!=NULL) && (set[i].p1==NULL))
1906    || (pComp0(set[i].p,p.p) == pOrdSgn))
1907      an=i;
1908    else
1909      en=i;
1910  }
1911}
1912
1913/*2
1914*looks up the position of polynomial p in set
1915*set[length] is the smallest element in set with respect
1916*to the ordering-procedure pComp
1917*/
1918int posInL0 (const LSet set, const int length,
1919             const LObject &p,const kStrategy strat)
1920{
1921  if (length<0) return 0;
1922
1923  if (pComp0(set[length].p,p.p)== pOrdSgn)
1924    return length+1;
1925
1926  int i;
1927  int an = 0;
1928  int en= length;
1929  loop
1930  {
1931    if (an >= en-1)
1932    {
1933      if (pComp0(set[an].p,p.p) == pOrdSgn) return en;
1934      return an;
1935    }
1936    i=(an+en) / 2;
1937    if (pComp0(set[i].p,p.p) == pOrdSgn) an=i;
1938    else                                 en=i;
1939    /*aend. fuer lazy == in !=- machen */
1940  }
1941}
1942
1943/*2
1944* looks up the position of polynomial p in set
1945* e is the ecart of p
1946* set[length] is the smallest element in set with respect
1947* to the ordering-procedure totaldegree,pComp
1948*/
1949int posInL11 (const LSet set, const int length,
1950              const LObject &p,const kStrategy strat)
1951/*{
1952 * int j=0;
1953 * int o;
1954 *
1955 * o = pFDeg(p.p);
1956 * loop
1957 * {
1958 *   if (j > length)            return j;
1959 *   if ((pFDeg(set[j].p) < o)) return j;
1960 *   if ((pFDeg(set[j].p) == o) && (pComp0(set[j].p,p.p) == -pOrdSgn))
1961 *   {
1962 *     return j;
1963 *   }
1964 *   j++;
1965 * }
1966 *}
1967 */
1968{
1969  if (length<0) return 0;
1970
1971  int o = pFDeg(p.p);
1972  int op = pFDeg(set[length].p);
1973
1974  if ((op > o)
1975  || ((op == o) && (pComp0(set[length].p,p.p) != -pOrdSgn)))
1976    return length+1;
1977  int i;
1978  int an = 0;
1979  int en= length;
1980  loop
1981  {
1982    if (an >= en-1)
1983    {
1984      op = pFDeg(set[an].p);
1985      if ((op > o)
1986      || ((op == o) && (pComp0(set[an].p,p.p) != -pOrdSgn)))
1987        return en;
1988      return an;
1989    }
1990    i=(an+en) / 2;
1991    op = pFDeg(set[i].p);
1992    if ((op > o)
1993    || ((op == o) && (pComp0(set[i].p,p.p) != -pOrdSgn)))
1994      an=i;
1995    else
1996      en=i;
1997  }
1998}
1999
2000/*2
2001* looks up the position of polynomial p in set
2002* set[length] is the smallest element in set with respect
2003* to the ordering-procedure totaldegree,pLength0
2004*/
2005int posInL110 (const LSet set, const int length,
2006               const LObject &p,const kStrategy strat)
2007{
2008  if (length<0) return 0;
2009
2010  int o = pFDeg(p.p);
2011  int op = pFDeg(set[length].p);
2012
2013  if ((op > o)
2014  || ((op == o) && (set[length].length >2*p.length))
2015  || ((op == o) && (set[length].length <= 2*p.length)
2016     && (pComp0(set[length].p,p.p) != -pOrdSgn)))
2017    return length+1;
2018  int i;
2019  int an = 0;
2020  int en= length;
2021  loop
2022  {
2023    if (an >= en-1)
2024    {
2025      op = pFDeg(set[an].p);
2026      if ((op > o)
2027      || ((op == o) && (set[an].length >2*p.length))
2028      || ((op == o) && (set[an].length <=2*p.length)
2029         && (pComp0(set[an].p,p.p) != -pOrdSgn)))
2030        return en;
2031      return an;
2032    }
2033    i=(an+en) / 2;
2034    op = pFDeg(set[i].p);
2035    if ((op > o)
2036    || ((op == o) && (set[i].length > 2*p.length))
2037    || ((op == o) && (set[i].length <= 2*p.length)
2038       && (pComp0(set[i].p,p.p) != -pOrdSgn)))
2039      an=i;
2040    else
2041      en=i;
2042  }
2043}
2044
2045/*2
2046* looks up the position of polynomial p in set
2047* e is the ecart of p
2048* set[length] is the smallest element in set with respect
2049* to the ordering-procedure totaldegree
2050*/
2051int posInL13 (const LSet set, const int length,
2052              const LObject &p,const kStrategy strat)
2053{
2054  if (length<0) return 0;
2055
2056  int o = pFDeg(p.p);
2057
2058  if (pFDeg(set[length].p) > o)
2059    return length+1;
2060
2061  int i;
2062  int an = 0;
2063  int en= length;
2064  loop
2065  {
2066    if (an >= en-1)
2067    {
2068      if (pFDeg(set[an].p) >= o)
2069        return en;
2070      return an;
2071    }
2072    i=(an+en) / 2;
2073    if (pFDeg(set[i].p) >= o)
2074      an=i;
2075    else
2076      en=i;
2077  }
2078}
2079
2080/*2
2081* looks up the position of polynomial p in set
2082* e is the ecart of p
2083* set[length] is the smallest element in set with respect
2084* to the ordering-procedure maximaldegree,pComp
2085*/
2086int posInL15 (const LSet set, const int length,
2087              const LObject &p,const kStrategy strat)
2088/*{
2089 * int j=0;
2090 * int o;
2091 *
2092 * o = p.ecart+pFDeg(p.p);
2093 * loop
2094 * {
2095 *   if (j > length)                       return j;
2096 *   if (pFDeg(set[j].p)+set[j].ecart < o) return j;
2097 *   if ((pFDeg(set[j].p)+set[j].ecart == o)
2098 *   && (pComp0(set[j].p,p.p) == -pOrdSgn))
2099 *   {
2100 *     return j;
2101 *   }
2102 *   j++;
2103 * }
2104 *}
2105 */
2106{
2107  if (length<0) return 0;
2108
2109  int o = pFDeg(p.p) + p.ecart;
2110  int op = pFDeg(set[length].p) + set[length].ecart;
2111
2112  if ((op > o)
2113  || ((op == o) && (pComp0(set[length].p,p.p) != -pOrdSgn)))
2114    return length+1;
2115  int i;
2116  int an = 0;
2117  int en= length;
2118  loop
2119  {
2120    if (an >= en-1)
2121    {
2122      op = pFDeg(set[an].p) + set[an].ecart;
2123      if ((op > o)
2124      || ((op == o) && (pComp0(set[an].p,p.p) != -pOrdSgn)))
2125        return en;
2126      return an;
2127    }
2128    i=(an+en) / 2;
2129    op = pFDeg(set[i].p) + set[i].ecart;
2130    if ((op > o)
2131    || ((op == o) && (pComp0(set[i].p,p.p) != -pOrdSgn)))
2132      an=i;
2133    else
2134      en=i;
2135  }
2136}
2137
2138/*2
2139* looks up the position of polynomial p in set
2140* e is the ecart of p
2141* set[length] is the smallest element in set with respect
2142* to the ordering-procedure totaldegree
2143*/
2144int posInL17 (const LSet set, const int length,
2145              const LObject &p,const kStrategy strat)
2146{
2147  if (length<0) return 0;
2148
2149  int o = pFDeg(p.p) + p.ecart;
2150
2151  if ((pFDeg(set[length].p) + set[length].ecart > o)
2152  || ((pFDeg(set[length].p) + set[length].ecart == o)
2153     && (set[length].ecart > p.ecart))
2154  || ((pFDeg(set[length].p) + set[length].ecart == o)
2155     && (set[length].ecart == p.ecart)
2156     && (pComp0(set[length].p,p.p) != -pOrdSgn)))
2157    return length+1;
2158  int i;
2159  int an = 0;
2160  int en= length;
2161  loop
2162  {
2163    if (an >= en-1)
2164    {
2165      if ((pFDeg(set[an].p) + set[an].ecart > o)
2166      || ((pFDeg(set[an].p) + set[an].ecart == o)
2167         && (set[an].ecart > p.ecart))
2168      || ((pFDeg(set[an].p) + set[an].ecart == o)
2169         && (set[an].ecart == p.ecart)
2170         && (pComp0(set[an].p,p.p) != -pOrdSgn)))
2171        return en;
2172      return an;
2173    }
2174    i=(an+en) / 2;
2175    if ((pFDeg(set[i].p) + set[i].ecart > o)
2176    || ((pFDeg(set[i].p) + set[i].ecart == o)
2177       && (set[i].ecart > p.ecart))
2178    || ((pFDeg(set[i].p) +set[i].ecart == o)
2179       && (set[i].ecart == p.ecart)
2180       && (pComp0(set[i].p,p.p) != -pOrdSgn)))
2181      an=i;
2182    else
2183      en=i;
2184  }
2185}
2186#if 0
2187{
2188  if (length<0) return 0;
2189
2190  int o = pFDeg(p.p) + p.ecart;
2191  int ol = pFDeg(set[length].p) + set[length].ecart;
2192
2193  if ((ol > o)
2194  || ((ol == o)
2195     && (set[length].ecart > p.ecart))
2196  || ((ol == o)
2197     && (set[length].ecart == p.ecart)
2198     //&& (set[length].lp+set[length].length > p.lp+p.length))
2199     && (set[length].length > p.length))
2200  || ((ol == o)
2201     && (set[length].ecart == p.ecart)
2202     //&& (set[length].lp+set[length].length == p.lp+p.length)
2203     && (set[length].length == p.length)
2204     && (pComp0(set[length].p,p.p) != -pOrdSgn)))
2205    return length+1;
2206  int i;
2207  int an = 0;
2208  int en= length;
2209  loop
2210  {
2211    if (an >= en-1)
2212    {
2213      ol = pFDeg(set[an].p) + set[an].ecart;
2214      if ((ol > o)
2215      || ((ol == o)
2216         && (set[an].ecart > p.ecart))
2217      || ((ol == o)
2218         && (set[an].ecart == p.ecart)
2219         //&& (set[length].lp+set[length].length > p.lp+p.length))
2220         && (set[length].length > p.length))
2221      || ((ol == o)
2222         && (set[an].ecart == p.ecart)
2223         //&& (set[length].lp+set[length].length == p.lp+p.length)
2224         && (set[length].length == p.length)
2225         && (pComp0(set[an].p,p.p) != -pOrdSgn)))
2226        return en;
2227      return an;
2228    }
2229    i=(an+en) / 2;
2230    ol = pFDeg(set[i].p) + set[i].ecart;
2231    if ((ol > o)
2232    || ((ol == o)
2233       && (set[i].ecart > p.ecart))
2234    || ((ol == o)
2235       && (set[i].ecart == p.ecart)
2236       //&& (set[i].lp+set[i].length > p.lp+p.length))
2237       && (set[i].length > p.length))
2238    || ((ol == o)
2239       && (set[i].ecart == p.ecart)
2240       //&& (set[i].lp+set[i].length == p.lp+p.length)
2241       && (set[i].length == p.length)
2242       && (pComp0(set[i].p,p.p) != -pOrdSgn)))
2243      an=i;
2244    else
2245      en=i;
2246  }
2247}
2248#endif
2249/*2
2250* looks up the position of polynomial p in set
2251* e is the ecart of p
2252* set[length] is the smallest element in set with respect
2253* to the ordering-procedure pComp
2254*/
2255int posInL17_c (const LSet set, const int length,
2256                const LObject &p,const kStrategy strat)
2257{
2258  if (length<0) return 0;
2259
2260  int cc = (-1+2*currRing->order[0]==ringorder_c);
2261  /* cc==1 for (c,..), cc==-1 for (C,..) */
2262  int c = pGetComp(p.p)*cc;
2263  int o = pFDeg(p.p) + p.ecart;
2264
2265  if (pGetComp(set[length].p)*cc > c)
2266    return length+1;
2267  if (pGetComp(set[length].p)*cc == c)
2268  {
2269    if ((pFDeg(set[length].p) + set[length].ecart > o)
2270    || ((pFDeg(set[length].p) + set[length].ecart == o)
2271       && (set[length].ecart > p.ecart))
2272    || ((pFDeg(set[length].p) + set[length].ecart == o)
2273       && (set[length].ecart == p.ecart)
2274       && (pComp0(set[length].p,p.p) != -pOrdSgn)))
2275      return length+1;
2276  }
2277  int i;
2278  int an = 0;
2279  int en= length;
2280  loop
2281  {
2282    if (an >= en-1)
2283    {
2284      if (pGetComp(set[an].p)*cc > c)
2285        return en;
2286      if (pGetComp(set[an].p)*cc == c)
2287      {
2288        if ((pFDeg(set[an].p) + set[an].ecart > o)
2289        || ((pFDeg(set[an].p) + set[an].ecart == o)
2290           && (set[an].ecart > p.ecart))
2291        || ((pFDeg(set[an].p) + set[an].ecart == o)
2292           && (set[an].ecart == p.ecart)
2293           && (pComp0(set[an].p,p.p) != -pOrdSgn)))
2294          return en;
2295      }
2296      return an;
2297    }
2298    i=(an+en) / 2;
2299    if (pGetComp(set[i].p)*cc > c)
2300      an=i;
2301    else if (pGetComp(set[i].p)*cc == c)
2302    {
2303      if ((pFDeg(set[i].p) + set[i].ecart > o)
2304      || ((pFDeg(set[i].p) + set[i].ecart == o)
2305         && (set[i].ecart > p.ecart))
2306      || ((pFDeg(set[i].p) +set[i].ecart == o)
2307         && (set[i].ecart == p.ecart)
2308         && (pComp0(set[i].p,p.p) != -pOrdSgn)))
2309        an=i;
2310      else
2311        en=i;
2312    }
2313    else
2314      en=i;
2315  }
2316}
2317/*2
2318* reduces h using the set S
2319* procedure used in redtail
2320*/
2321/*2
2322*compute the normalform of the tail p->next of p
2323*with respect to S
2324*/
2325poly redtail (poly p, int pos, kStrategy strat)
2326{
2327  poly h, hn;
2328  int j, e, l;
2329  int op;
2330
2331  if (strat->noTailReduction)
2332  {
2333    return p;
2334  }
2335  h = p;
2336  hn = pNext(h);
2337  while(hn != NULL)
2338  {
2339    op = pFDeg(hn);
2340    e = pLDeg(hn,&l)-op;
2341    j = 0;
2342    while (j <= pos)
2343    {
2344      if (pDivisibleBy(strat->S[j], hn)
2345      && ((e >= strat->ecartS[j])
2346        || strat->kHEdgeFound
2347        || ((Kstd1_deg>0)&&(op<=Kstd1_deg)))
2348      )
2349      {
2350        spSpolyTail(strat->S[j], p, h, strat->kNoether, strat->spSpolyLoop);
2351        hn = pNext(h);
2352        if (hn == NULL)
2353        {
2354          return p;
2355        }
2356        op = pFDeg(hn);
2357        e = pLDeg(hn,&l)-op;
2358        j = 0;
2359      }
2360      else
2361      {
2362        j++;
2363      }
2364    }
2365    h = hn;
2366    hn = pNext(h);
2367  }
2368  return p;
2369}
2370
2371/*2
2372*compute the normalform of the tail p->next of p
2373*with respect to S
2374*/
2375poly redtailBba (poly p, int pos, kStrategy strat)
2376{
2377  poly h, hn;
2378  int j;
2379  strat->redTailChange=FALSE;
2380
2381  if (strat->noTailReduction)
2382  {
2383    return p;
2384  }
2385  h = p;
2386  hn = pNext(h);
2387  while(hn != NULL)
2388  {
2389    j = 0;
2390    while (j <= pos)
2391    {
2392      if (pDivisibleBy(strat->S[j], hn))
2393      {
2394        strat->redTailChange=TRUE;
2395        spSpolyTail(strat->S[j], p, h, strat->kNoether, strat->spSpolyLoop);
2396        hn = pNext(h);
2397        if (hn == NULL)
2398        {
2399          return p;
2400        }
2401        j = 0;
2402      }
2403      else
2404      {
2405        j++;
2406      }
2407    }
2408    h = hn;
2409    hn = pNext(h);
2410  }
2411  return p;
2412}
2413
2414/*2
2415*compute the "normalform" of the tail p->next of p
2416*with respect to S for syzygies
2417*/
2418poly redtailSyz (poly p, int pos, kStrategy strat)
2419{
2420  poly h, hn;
2421  int j;
2422
2423  if (strat->noTailReduction)
2424  {
2425    return p;
2426  }
2427  h = p;
2428  hn = pNext(h);
2429  while(hn != NULL)
2430  {
2431    j = 0;
2432    while (j <= pos)
2433    {
2434      if (pDivisibleBy(strat->S[j], hn) && (!pEqual(strat->S[j],h)))
2435      {
2436        spSpolyTail(strat->S[j], p, h, strat->kNoether, strat->spSpolyLoop);
2437        hn = pNext(h);
2438        if (hn == NULL)
2439        {
2440          return p;
2441        }
2442        j = 0;
2443      }
2444      else
2445      {
2446        j++;
2447      }
2448    }
2449    h = hn;
2450    hn = pNext(h);
2451  }
2452  return p;
2453}
2454
2455/*2
2456*checks the change degree and write progress report
2457*/
2458void message (int i,int* reduc,int* olddeg,kStrategy strat)
2459{
2460  if (i != *olddeg)
2461  {
2462    Print("%d",i);
2463    *olddeg = i;
2464  }
2465  if (strat->Ll != *reduc)
2466  {
2467    if (strat->Ll != *reduc-1)
2468      Print("(%d)",strat->Ll+1);
2469    else
2470      PrintS("-");
2471    *reduc = strat->Ll;
2472  }
2473  else
2474    PrintS(".");
2475  mflush();
2476}
2477
2478/*2
2479*statistics
2480*/
2481void messageStat (int srmax,int lrmax,int hilbcount,kStrategy strat)
2482{
2483  //PrintS("\nUsage/Allocation of temporary storage:\n");
2484  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
2485  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
2486  Print("\nproduct criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
2487  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
2488  /*mflush();*/
2489}
2490
2491/*2
2492*debugging output: all internal sets, if changed
2493*for testing purpuse only/has to be changed for later use
2494*/
2495void messageSets (kStrategy strat)
2496{
2497  int i;
2498  if (strat->news)
2499  {
2500    PrintS("set S");
2501    for (i=0; i<=strat->sl; i++)
2502    {
2503      Print("\n  %d:",i);
2504      wrp(strat->S[i]);
2505    }
2506    strat->news = FALSE;
2507  }
2508  if (strat->newt)
2509  {
2510    PrintS("\nset T");
2511    for (i=0; i<=strat->tl; i++)
2512    {
2513      Print("\n  %d:",i);
2514      wrp(strat->T[i].p);
2515      Print(" o:%d e:%d l:%d",
2516        pFDeg(strat->T[i].p),strat->T[i].ecart,strat->T[i].length);
2517    }
2518    strat->newt = FALSE;
2519  }
2520  PrintS("\nset L");
2521  for (i=strat->Ll; i>=0; i--)
2522  {
2523    Print("\n%d:",i);
2524    wrp(strat->L[i].p1);
2525    PrintS("  ");
2526    wrp(strat->L[i].p2);
2527    PrintS(" lcm: ");wrp(strat->L[i].lcm);
2528    PrintS("\n  p : ");
2529    wrp(strat->L[i].p);
2530    Print("  o:%d e:%d l:%d",
2531     pGetOrder(strat->L[i].p),strat->L[i].ecart,strat->L[i].length);
2532  }
2533  PrintLn();
2534}
2535
2536/*2
2537*construct the set s from F
2538*/
2539void initS (ideal F, ideal Q,kStrategy strat)
2540{
2541  LObject h;
2542  int   i,pos;
2543#ifdef SDRING
2544  polyset aug=(polyset)Alloc(setmax*sizeof(poly));
2545  int augmax=setmax, augl=-1;
2546#endif
2547
2548  h.ecart=0; h.length=0;
2549  if (Q!=NULL) i=IDELEMS(Q);
2550  else i=0;
2551  i=((i+IDELEMS(F)+15)/16)*16;
2552  strat->ecartS=initec(i);
2553  strat->fromQ=NULL;
2554  strat->Shdl=idInit(i,F->rank);
2555  strat->S=strat->Shdl->m;
2556  /*- put polys into S -*/
2557  if (Q!=NULL)
2558  {
2559    strat->fromQ=initec(i);
2560    memset(strat->fromQ,0,i*sizeof(int));
2561    for (i=0; i<IDELEMS(Q); i++)
2562    {
2563      if (Q->m[i]!=NULL)
2564      {
2565        h.p = pCopy(Q->m[i]);
2566        if (TEST_OPT_INTSTRATEGY)
2567        {
2568          //pContent(h.p);
2569          pCleardenom(h.p); // also does a pContent
2570        }
2571        else
2572        {
2573          pNorm(h.p);
2574        }
2575        strat->initEcart(&h);
2576        if (pOrdSgn==-1)
2577        {
2578          deleteHC(&h.p, &h.ecart, &h.length,strat);
2579        }
2580        if (h.p!=NULL)
2581        {
2582          if (strat->sl==-1)
2583            pos =0;
2584          else
2585          {
2586            pos = posInS(strat->S,strat->sl,h.p);
2587          }
2588          strat->enterS(h,pos,strat);
2589          strat->fromQ[pos]=1;
2590        }
2591      }
2592    }
2593  }
2594  for (i=0; i<IDELEMS(F); i++)
2595  {
2596    if (F->m[i]!=NULL)
2597    {
2598      h.p = pCopy(F->m[i]);
2599#ifdef SDRING
2600      aug[0]=h.p;
2601      augl=0;
2602#ifdef SRING
2603      if (pSRING)
2604        psAug(pCopy(h.p),pOne(),&aug,&augl,&augmax);
2605#endif
2606#ifdef DRING
2607      if (pDRING)
2608        pdAug(pCopy(h.p),&aug,&augl,&augmax);
2609#endif
2610      for (augl++;augl != 0;)
2611      {
2612        h.p=aug[--augl];
2613#ifdef KDEBUG
2614        pTest(h.p);
2615#endif
2616#ifdef KDEBUG
2617        if (TEST_OPT_DEBUG && pSDRING)
2618        {
2619          PrintS("new (aug) s:");
2620          wrp(h.p);
2621          PrintLn();
2622        }
2623#endif
2624#endif
2625        if (TEST_OPT_INTSTRATEGY)
2626        {
2627          //pContent(h.p);
2628          pCleardenom(h.p); // also does a pContent
2629        }
2630        else
2631        {
2632          pNorm(h.p);
2633        }
2634        strat->initEcart(&h);
2635        if (pOrdSgn==-1)
2636        {
2637          cancelunit(&h);  /*- tries to cancel a unit -*/
2638          deleteHC(&h.p, &h.ecart, &h.length,strat);
2639        }
2640        if (TEST_OPT_DEGBOUND
2641        && (((strat->honey) && (h.ecart+pFDeg(h.p)>Kstd1_deg))
2642          || ((!(strat->honey)) && (pFDeg(h.p)>Kstd1_deg))))
2643          pDelete(&h.p);
2644        else
2645        if (h.p!=NULL)
2646        {
2647          if (strat->sl==-1)
2648            pos =0;
2649          else
2650          {
2651            pos = posInS(strat->S,strat->sl,h.p);
2652          }
2653          strat->enterS(h,pos,strat);
2654        }
2655#ifdef SDRING
2656      }
2657#endif
2658    }
2659  }
2660  /*- test, if a unit is in F -*/
2661  if ((strat->sl>=0) && pIsConstant(strat->S[0]))
2662  {
2663    while (strat->sl>0) deleteInS(strat->sl,strat);
2664  }
2665#ifdef SDRING
2666  Free((ADDRESS)aug,augmax*sizeof(poly));
2667#endif
2668//  for(augl=0;augl<=strat->sl;augl++)
2669//    pTest(strat->S[augl]);
2670}
2671
2672void initSL (ideal F, ideal Q,kStrategy strat)
2673{
2674  LObject h;
2675  int   i,pos;
2676#ifdef SDRING
2677  polyset aug=(polyset)Alloc(setmax*sizeof(poly));
2678  int augmax=setmax, augl=-1;
2679#endif
2680
2681  h.ecart=0; h.length=0;
2682  if (Q!=NULL) i=IDELEMS(Q);
2683  else i=0;
2684  i=((i+16)/16)*16;
2685  strat->ecartS=initec(i);
2686  strat->fromQ=NULL;
2687  strat->Shdl=idInit(i,F->rank);
2688  strat->S=strat->Shdl->m;
2689  /*- put polys into S -*/
2690  if (Q!=NULL)
2691  {
2692    strat->fromQ=initec(i);
2693    memset(strat->fromQ,0,i*sizeof(int));
2694    for (i=0; i<IDELEMS(Q); i++)
2695    {
2696      if (Q->m[i]!=NULL)
2697      {
2698        h.p = pCopy(Q->m[i]);
2699        if (TEST_OPT_INTSTRATEGY)
2700        {
2701          //pContent(h.p);
2702          pCleardenom(h.p); // also does a pContent
2703        }
2704        else
2705        {
2706          pNorm(h.p);
2707        }
2708        strat->initEcart(&h);
2709        if (pOrdSgn==-1)
2710        {
2711          deleteHC(&h.p, &h.ecart, &h.length,strat);
2712        }
2713        if (h.p!=NULL)
2714        {
2715          if (strat->sl==-1)
2716            pos =0;
2717          else
2718          {
2719            pos = posInS(strat->S,strat->sl,h.p);
2720          }
2721          strat->enterS(h,pos,strat);
2722          strat->fromQ[pos]=1;
2723        }
2724      }
2725    }
2726  }
2727  for (i=0; i<IDELEMS(F); i++)
2728  {
2729    if (F->m[i]!=NULL)
2730    {
2731      h.p = pCopy(F->m[i]);
2732      h.p1=NULL;
2733      h.p2=NULL;
2734      h.lcm=NULL;
2735#ifdef SDRING
2736      aug[0]=h.p;
2737      augl=0;
2738#ifdef SRING
2739      if (pSRING)
2740        psAug(pCopy(h.p),pOne(),&aug,&augl,&augmax);
2741#endif
2742#ifdef DRING
2743      if (pDRING)
2744        pdAug(pCopy(h.p),&aug,&augl,&augmax);
2745#endif
2746      for (augl++;augl != 0;)
2747      {
2748        h.p=aug[--augl];
2749#ifdef KDEBUG
2750        pTest(h.p);
2751#endif
2752#ifdef SDRING
2753        if (TEST_OPT_DEBUG && pSDRING)
2754        {
2755          PrintS("new (aug) s:");
2756          wrp(h.p);
2757          PrintLn();
2758        }
2759#endif
2760#endif
2761        if (TEST_OPT_INTSTRATEGY)
2762        {
2763          //pContent(h.p);
2764          pCleardenom(h.p); // also does a pContent
2765        }
2766        else
2767        {
2768          pNorm(h.p);
2769        }
2770        strat->initEcart(&h);
2771        if (pOrdSgn==-1)
2772        {
2773          cancelunit(&h);  /*- tries to cancel a unit -*/
2774          deleteHC(&h.p, &h.ecart, &h.length,strat);
2775        }
2776        if (TEST_OPT_DEGBOUND
2777        && (((strat->honey) && (h.ecart+pFDeg(h.p)>Kstd1_deg))
2778          || ((!(strat->honey)) && (pFDeg(h.p)>Kstd1_deg))))
2779          pDelete(&h.p);
2780        else
2781        if (h.p!=NULL)
2782        {
2783          if (strat->Ll==-1)
2784            pos =0;
2785          else
2786          {
2787            pos = strat->posInL(strat->L,strat->Ll,h,strat);
2788          }
2789          enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
2790        }
2791#ifdef SDRING
2792      }
2793#endif
2794    }
2795  }
2796  /*- test, if a unit is in F -*/
2797  if ((strat->Ll>=0) && pIsConstant(strat->L[strat->Ll].p))
2798  {
2799    while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
2800  }
2801#ifdef SDRING
2802  Free((ADDRESS)aug,augmax*sizeof(poly));
2803#endif
2804//  for(augl=0;augl<=strat->sl;augl++)
2805//    pTest(strat->S[augl]);
2806}
2807
2808
2809/*2
2810*construct the set s from F u {P}
2811*/
2812void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
2813{
2814  LObject h;
2815  int   i,pos;
2816#ifdef SDRING
2817  polyset aug=(polyset)Alloc(setmax*sizeof(poly));
2818  int augmax=setmax, augl=-1;
2819#endif
2820
2821  h.ecart=0; h.length=0;
2822  if (Q!=NULL) i=IDELEMS(Q);
2823  else i=0;
2824  i=((i+IDELEMS(F)+15)/16)*16;
2825  strat->ecartS=initec(i);
2826  strat->fromQ=NULL;
2827  strat->Shdl=idInit(i,F->rank);
2828  strat->S=strat->Shdl->m;
2829
2830  /*- put polys into S -*/
2831  if (Q!=NULL)
2832  {
2833    strat->fromQ=initec(i);
2834    memset(strat->fromQ,0,i*sizeof(int));
2835    for (i=0; i<IDELEMS(Q); i++)
2836    {
2837      if (Q->m[i]!=NULL)
2838      {
2839        h.p = pCopy(Q->m[i]);
2840        //if (TEST_OPT_INTSTRATEGY)
2841        //{
2842        //  //pContent(h.p);
2843        //  pCleardenom(h.p); // also does a pContent
2844        //}
2845        //else
2846        //{
2847        //  pNorm(h.p);
2848        //}
2849        strat->initEcart(&h);
2850        if (pOrdSgn==-1)
2851        {
2852          deleteHC(&h.p, &h.ecart, &h.length,strat);
2853        }
2854        if (h.p!=NULL)
2855        {
2856          if (strat->sl==-1)
2857            pos =0;
2858          else
2859          {
2860            pos = posInS(strat->S,strat->sl,h.p);
2861          }
2862          strat->enterS(h,pos,strat);
2863          strat->fromQ[pos]=1;
2864        }
2865      }
2866    }
2867  }
2868  /*- put polys into S -*/
2869  for (i=0; i<IDELEMS(F); i++)
2870  {
2871    if (F->m[i]!=NULL)
2872    {
2873      h.p = pCopy(F->m[i]);
2874      if (pOrdSgn==1)
2875      {
2876        h.p=redtailBba(h.p,strat->sl,strat);
2877      }
2878      strat->initEcart(&h);
2879      if (pOrdSgn==-1)
2880      {
2881          deleteHC(&h.p, &h.ecart, &h.length,strat);
2882      }
2883      if (TEST_OPT_DEGBOUND
2884      && (((strat->honey) && (h.ecart+pFDeg(h.p)>Kstd1_deg))
2885        || ((!(strat->honey)) && (pFDeg(h.p)>Kstd1_deg))))
2886        pDelete(&h.p);
2887      else
2888      if (h.p!=NULL)
2889      {
2890        if (strat->sl==-1)
2891          pos =0;
2892        else
2893        {
2894          pos = posInS(strat->S,strat->sl,h.p);
2895        }
2896        strat->enterS(h,pos,strat);
2897        h.length = pLength(h.p);
2898        enterT(h,strat);
2899      }
2900    }
2901  }
2902  for (i=0; i<IDELEMS(P); i++)
2903  {
2904    if (P->m[i]!=NULL)
2905    {
2906      h.p=pCopy(P->m[i]);
2907      strat->initEcart(&h);
2908      h.length = pLength(h.p);
2909      if (TEST_OPT_INTSTRATEGY)
2910      {
2911        pCleardenom(h.p);
2912      }
2913      else
2914      {
2915        pNorm(h.p);
2916      }
2917      if(strat->sl>=0)
2918      {
2919        if (pOrdSgn==1)
2920        {
2921          h.p=redBba(h.p,strat->sl,strat);
2922          if (h.p!=NULL)
2923            h.p=redtailBba(h.p,strat->sl,strat);
2924        }
2925        else
2926        {
2927          h.p=redMora(h.p,strat->sl,strat);
2928          strat->initEcart(&h);
2929        }
2930        if(h.p!=NULL)
2931        {
2932          if (TEST_OPT_INTSTRATEGY)
2933          {
2934            pCleardenom(h.p);
2935          }
2936          else
2937          {
2938            pNorm(h.p);
2939          }
2940          pos = posInS(strat->S,strat->sl,h.p);
2941          enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat);
2942          strat->enterS(h,pos,strat);
2943          enterT(h,strat);
2944        }
2945      }
2946      else
2947      {
2948        strat->enterS(h,0,strat);
2949        enterT(h,strat);
2950      }
2951    }
2952  }
2953#ifdef SDRING
2954  Free((ADDRESS)aug,augmax*sizeof(poly));
2955#endif
2956}
2957/*2
2958* reduces h using the set S
2959* procedure used in cancelunit1
2960*/
2961static poly redBba1 (poly h,int maxIndex,kStrategy strat)
2962{
2963  int j = 0;
2964
2965  while (j <= maxIndex)
2966  {
2967    if (pDivisibleBy(strat->S[j],h))
2968       return spSpolyRedNew(strat->S[j],h,strat->kNoether, strat->spSpolyLoop);
2969    else j++;
2970  }
2971  return h;
2972}
2973
2974/*2
2975*tests if p.p=monomial*unit and cancels the unit
2976*/
2977void cancelunit1 (LObject* p,int index,kStrategy strat )
2978{
2979  int k;
2980  poly r,h,h1,q;
2981
2982  if (!pIsVector((*p).p) && ((*p).ecart != 0))
2983  {
2984    k = 0;
2985    h1 = r = pCopy((*p).p);
2986    h =pNext(r);
2987    loop
2988    {
2989      if (h==NULL)
2990      {
2991        pDelete(&r);
2992        pDelete(&(pNext((*p).p)));
2993        (*p).ecart = 0;
2994        (*p).length = 1;
2995        return;
2996      }
2997      if (!pDivisibleBy(r,h))
2998      {
2999        q=redBba1(h,index ,strat);
3000        if (q != h)
3001        {
3002          k++;
3003          pDelete(&h);
3004          pNext(h1) = h = q;
3005        }
3006        else
3007        {
3008          pDelete(&r);
3009          return;
3010        }
3011      }
3012      else
3013      {
3014        h1 = h;
3015        pIter(h);
3016      }
3017      if (k > 10)
3018      {
3019        pDelete(&r);
3020        return;
3021      }
3022    }
3023  }
3024}
3025
3026/*2
3027* reduces h using the elements from Q in the set S
3028* procedure used in updateS
3029* must not be used for elements of Q or elements of an ideal !
3030*/
3031static poly redQ (poly h, int j, kStrategy strat)
3032{
3033  int start;
3034
3035  while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
3036  start=j;
3037  while (j<=strat->sl)
3038  {
3039    if (pDivisibleBy(strat->S[j],h))
3040    {
3041      h = spSpolyRed(strat->S[j],h,strat->kNoether, strat->spSpolyLoop);
3042      if (h==NULL) return NULL;
3043      j = start;
3044    }
3045    else j++;
3046  }
3047  return h;
3048}
3049
3050/*2
3051* reduces h using the set S
3052* procedure used in updateS
3053*/
3054static poly redBba (poly h,int maxIndex,kStrategy strat)
3055{
3056  int j = 0;
3057
3058  while (j <= maxIndex)
3059  {
3060    if (pDivisibleBy(strat->S[j],h))
3061    {
3062      pTest(strat->S[j]);
3063      pTest(h);
3064      h = spSpolyRed(strat->S[j],h,strat->kNoether, strat->spSpolyLoop);
3065      if (h==NULL) return NULL;
3066      j = 0;
3067    }
3068    else j++;
3069  }
3070#ifdef KDEBUG
3071  pTest(h);
3072#endif
3073  return h;
3074}
3075
3076/*2
3077* reduces h using the set S
3078*e is the ecart of h
3079*procedure used in updateS
3080*/
3081static poly redMora (poly h,int maxIndex,kStrategy strat)
3082{
3083  int  j=0;
3084  int  e,l;
3085  poly h1;
3086
3087  if (maxIndex >= 0)
3088  {
3089    e = pLDeg(h,&l)-pFDeg(h);
3090    do
3091    {
3092      if (pDivisibleBy(strat->S[j],h)
3093      && ((e >= strat->ecartS[j]) || strat->kHEdgeFound))
3094      {
3095        h1 = spSpolyRedNew(strat->S[j],h,strat->kNoether, strat->spSpolyLoop);
3096        if(TEST_OPT_DEBUG)
3097        {
3098          PrintS("reduce "); wrp(h); Print(" with S[%d] (",j);wrp(strat->S[j]);
3099          PrintS(")\nto "); wrp(h1); PrintLn();
3100        }
3101        pDelete(&h);
3102        if (h1 == NULL) return NULL;
3103        h = h1;
3104        e = pLDeg(h,&l)-pFDeg(h);
3105        j = 0;
3106      }
3107      else j++;
3108    }
3109    while (j <= maxIndex);
3110  }
3111#ifdef KDEBUG
3112  pTest(h);
3113#endif
3114  return h;
3115}
3116
3117/*2
3118*updates S:
3119*the result is a set of polynomials which are in
3120*normalform with respect to S
3121*/
3122void updateS(BOOLEAN toT,kStrategy strat)
3123{
3124  LObject h;
3125  int i, suc=0;
3126  poly redSi=NULL;
3127#ifdef SDRING
3128  polyset aug=(polyset)Alloc(setmax*sizeof(poly));
3129  int augmax=setmax;
3130  int augl;
3131  int pos;
3132  BOOLEAN recursiv=FALSE;
3133#endif
3134
3135//Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
3136//  for (i=0; i<=(strat->sl); i++)
3137//  {
3138//    Print("s%d:",i);
3139//    if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
3140//    pWrite(strat->S[i]);
3141//  }
3142  memset(&h,0,sizeof(h));
3143  if (pOrdSgn==1)
3144  {
3145    while (suc != -1)
3146    {
3147      i=suc+1;
3148      while (i<=strat->sl)
3149      {
3150        pTest(strat->S[i]);
3151        if (((strat->syzComp==0) || (pGetComp(strat->S[i])<=strat->syzComp))
3152        && ((strat->fromQ==NULL) || (strat->fromQ[i]==0)))
3153        {
3154          pDelete(&redSi);
3155          redSi = pHead(strat->S[i]);
3156          strat->S[i] = redBba(strat->S[i],i-1,strat);
3157          if ((strat->ak!=0)&&(strat->S[i]!=NULL))
3158            strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
3159          if (TEST_OPT_DEBUG && (pComp(redSi,strat->S[i])!=0))
3160          {
3161            PrintS("reduce:");
3162            wrp(redSi);PrintS(" to ");wrp(strat->S[i]);PrintLn();
3163          }
3164          if (TEST_OPT_PROT && (pComp(redSi,strat->S[i])!=0))
3165          {
3166            if (strat->S[i]==NULL)
3167              PrintS("V");
3168            else
3169              PrintS("v");
3170            mflush();
3171          }
3172          if (strat->S[i]==NULL)
3173          {
3174            pDelete(&redSi);
3175            deleteInS(i,strat);
3176            i--;
3177          }
3178#ifdef SDRING
3179          else if ((pSDRING) && (pComp(redSi,strat->S[i])!=0))
3180          {
3181            pDelete(&redSi);
3182            redSi=strat->S[i];
3183            strat->S[i]=NULL;
3184            pTest(redSi);
3185            deleteInS(i,strat);
3186            suc=0;
3187            i=0;
3188            aug[0]=redSi;
3189            augl=0;
3190#ifdef SRING
3191            if (pSRING) psAug(pCopy(redSi),pOne(),&aug,&augl,&augmax);
3192#endif
3193#ifdef DRING
3194            if (pDRING) pdAug(pCopy(redSi),&aug,&augl,&augmax);
3195#endif
3196            redSi=NULL;
3197            if (augl>0) recursiv=TRUE;
3198            while (augl >= 0)
3199            {
3200              h.p=aug[augl];
3201              pTest(h.p);
3202              if (h.p!=NULL)
3203              {
3204                if (TEST_OPT_DEBUG)
3205                {
3206                  Print("new (aug %d) s:",augl);
3207                  wrp(h.p);
3208                  PrintLn();
3209                }
3210                if (TEST_OPT_INTSTRATEGY)
3211                {
3212                  //pContent(h.p);
3213                  pCleardenom(h.p);// also does a pContent
3214                }
3215                else
3216                {
3217                  pNorm(h.p);
3218                }
3219                strat->initEcart(&h);
3220                pos = posInS(strat->S,strat->sl,h.p);
3221                strat->enterS(h,pos,strat);
3222              }
3223              augl--;
3224            }
3225          }
3226#endif
3227          else
3228          {
3229            pDelete(&redSi);
3230            if (TEST_OPT_INTSTRATEGY)
3231            {
3232              //pContent(strat->S[i]);
3233              pCleardenom(strat->S[i]);// also does a pContent
3234            }
3235            else
3236            {
3237              pNorm(strat->S[i]);
3238            }
3239          }
3240        }
3241        i++;
3242      }
3243      reorderS(&suc,strat);
3244    }
3245    if (toT)
3246    {
3247      for (i=0; i<=strat->sl; i++)
3248      {
3249        if (((strat->fromQ==NULL) || (strat->fromQ[i]==0))
3250#ifdef SDRING
3251        && (!pSDRING)
3252#endif
3253        )
3254          h.p = redtailBba(strat->S[i],i-1,strat);
3255        else
3256        {
3257          h.p = strat->S[i];
3258        }
3259        if (strat->honey)
3260        {
3261          strat->initEcart(&h);
3262          strat->ecartS[i] = h.ecart;
3263        }
3264        /*puts the elements of S also to T*/
3265        enterT(h,strat);
3266      }
3267    }
3268  }
3269  else
3270  {
3271    while (suc != -1)
3272    {
3273      i=suc+1;
3274      while (i<=strat->sl)
3275      {
3276        if (((strat->syzComp==0) || (pGetComp(strat->S[i])<=strat->syzComp))
3277        && ((strat->fromQ==NULL) || (strat->fromQ[i]==0)))
3278        {
3279          pDelete(&redSi);
3280          redSi=pHead((strat->S)[i]);
3281          (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
3282          kTest(strat);
3283          if ((strat->S)[i]==NULL)
3284          {
3285            deleteInS(i,strat);
3286            i--;
3287          }
3288#ifdef SDRING
3289          else if ((pSDRING) && (pComp(redSi,(strat->S)[i])!=0))
3290          {
3291            pDelete(&redSi);
3292            redSi=(strat->S)[i];
3293            (strat->S)[i]=NULL;
3294            deleteInS(i,strat);
3295            i--;
3296            aug[0]=redSi;
3297            augl=0;
3298#ifdef SRING
3299            if (pSRING) psAug(pCopy(redSi),pOne(),&aug,&augl,&augmax);
3300#endif
3301#ifdef DRING
3302            if (pDRING) pdAug(pCopy(redSi),&aug,&augl,&augmax);
3303#endif
3304            redSi=NULL;
3305            if (augl>0) recursiv=TRUE;
3306            for (augl++;augl != 0;)
3307            {
3308              h.p=aug[--augl];
3309#ifdef KDEBUG
3310              if (TEST_OPT_DEBUG)
3311              {
3312                PrintS("new (aug) s:");
3313                wrp(h.p);
3314                PrintLn();
3315              }
3316#endif
3317              if (!TEST_OPT_INTSTRATEGY)
3318                pNorm(h.p);
3319              else
3320              {
3321                //pContent(h.p);
3322                pCleardenom(h.p);// also does a pContent
3323              }
3324              strat->initEcart(&h);
3325              pos = posInS(strat->S,strat->sl,h.p);
3326              strat->enterS(h,pos,strat);
3327            }
3328          }
3329#endif
3330          else if (TEST_OPT_INTSTRATEGY)
3331          {
3332            pDelete(&redSi);
3333            //pContent(strat->S[i]);
3334            pCleardenom(strat->S[i]);// also does a pContent
3335            h.p = strat->S[i];
3336            strat->initEcart(&h);
3337            strat->ecartS[i] = h.ecart;
3338          }
3339          else
3340          {
3341            pDelete(&redSi);
3342            pNorm(strat->S[i]);
3343            h.p = strat->S[i];
3344            strat->initEcart(&h);
3345            strat->ecartS[i] = h.ecart;
3346          }
3347        }
3348        i++;
3349      }
3350#ifdef KDEBUG
3351      kTest(strat);
3352#endif
3353      reorderS(&suc,strat);
3354      if (h.p!=NULL)
3355      {
3356        if (!strat->kHEdgeFound)
3357        {
3358          /*strat->kHEdgeFound =*/ HEckeTest(h.p,strat);
3359        }
3360        if (strat->kHEdgeFound)
3361          newHEdge(strat->S,strat->ak,strat);
3362      }
3363    }
3364    for (i=0; i<=strat->sl; i++)
3365    {
3366      if (((strat->fromQ==NULL) || (strat->fromQ[i]==0))
3367#ifdef SDRING
3368      && (!pSDRING)
3369#endif
3370      )
3371      {
3372        strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
3373        strat->initEcart(&h);
3374        strat->ecartS[i] = h.ecart;
3375      }
3376      else
3377      {
3378        h.p = strat->S[i];
3379        h.ecart=strat->ecartS[i];
3380      }
3381      if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
3382        cancelunit1(&h,strat->sl,strat);
3383      h.length = pLength(h.p);
3384      /*puts the elements of S also to T*/
3385      enterT(h,strat);
3386    }
3387  }
3388  if (redSi!=NULL) pDelete1(&redSi);
3389#ifdef SDRING
3390  Free((ADDRESS)aug,augmax*sizeof(poly));
3391  if (recursiv) updateS(FALSE,strat);
3392#endif
3393//  for(augl=0;augl<=strat->sl;augl++)
3394//    pTest(strat->S[augl]);
3395//Print("nach  updateS start mit sl=%d\n",strat->sl);
3396//  for (i=0; i<=strat->sl; i++)
3397//  {
3398//    Print("s%d:",i);
3399//    if (strat->fromQ) Print("(Q:%d) ",strat->fromQ[i]);
3400//    pWrite(strat->S[i]);
3401//  }
3402#ifdef KDEBUG
3403  kTest(strat);
3404#endif
3405}
3406
3407/*2
3408* -puts p to the standardbasis s at position at
3409* -saves the result in S
3410*/
3411void enterSBba (LObject p,int atS,kStrategy strat)
3412{
3413  int i;
3414
3415#ifdef SDRING
3416  if (pSDRING
3417  && (atS<=strat->sl)
3418  && pComparePolys(p.p,strat->S[atS]))
3419  {
3420    if (TEST_OPT_PROT)
3421      PrintS("m");
3422    p.p=NULL;
3423    return;
3424  }
3425  if (pSDRING
3426  && (atS<strat->sl)
3427  && pComparePolys(p.p,strat->S[atS+1]))
3428  {
3429    if (TEST_OPT_PROT)
3430      PrintS("m");
3431    p.p=NULL;
3432    return;
3433  }
3434  if (pSDRING
3435  && (atS>0)
3436  && pComparePolys(p.p,strat->S[atS-1]))
3437  {
3438    if (TEST_OPT_PROT)
3439      PrintS("m");
3440    p.p=NULL;
3441    return;
3442  }
3443#endif
3444  strat->news = TRUE;
3445  /*- puts p to the standardbasis s at position at -*/
3446  if (strat->sl == IDELEMS(strat->Shdl)-1)
3447  {
3448    strat->ecartS = (intset)ReAlloc(strat->ecartS,
3449                                    IDELEMS(strat->Shdl)*sizeof(int),
3450                                    (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
3451    if (strat->fromQ!=NULL)
3452    {
3453      strat->fromQ = (intset)ReAlloc(strat->fromQ,
3454                                    IDELEMS(strat->Shdl)*sizeof(int),
3455                                    (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
3456    }
3457    pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
3458    IDELEMS(strat->Shdl)+=setmax;
3459    strat->Shdl->m=strat->S;
3460  }
3461  for (i=strat->sl+1; i>=atS+1; i--)
3462  {
3463    strat->S[i] = strat->S[i-1];
3464    if (strat->honey) strat->ecartS[i] = strat->ecartS[i-1];
3465  }
3466  if (strat->fromQ!=NULL)
3467  {
3468    for (i=strat->sl+1; i>=atS+1; i--)
3469    {
3470      strat->fromQ[i] = strat->fromQ[i-1];
3471    }
3472    strat->fromQ[atS]=0;
3473  }
3474  /*- save result -*/
3475  strat->S[atS] = p.p;
3476  if (strat->honey) strat->ecartS[atS] = p.ecart;
3477  strat->sl++;
3478}
3479
3480/*2
3481* puts p to the set T at position atT
3482*/
3483void enterT (LObject p,kStrategy strat)
3484{
3485  int i,atT;
3486
3487#ifdef KDEBUG
3488  pTest(p.p);
3489  for (i=0; i<=strat->tl ;i++)
3490  {
3491    pTest(strat->T[i].p);
3492  }
3493#endif
3494  strat->newt = TRUE;
3495  if (strat->tl >= 0)
3496  {
3497    /*- puts p to the standardbasis s at position atT -*/
3498    atT = strat->posInT(strat->T,strat->tl,p);
3499//    if ((atT<=strat->tl)
3500//    && (p.p==strat->T[atT].p))
3501//    {
3502//      PrintS("?");
3503//      return;
3504//    }
3505//    if ((atT<strat->tl)
3506//    && (p.p==strat->T[atT+1].p))
3507//    {
3508//      PrintS("?");
3509//      return;
3510//    }
3511//    if ((atT>0)
3512//    && (p.p==strat->T[atT-1].p))
3513//    {
3514//      PrintS("?");
3515//      return;
3516//    }
3517    if (strat->tl == strat->tmax-1) enlargeT(&strat->T,&strat->tmax,setmax);
3518    for (i=strat->tl+1; i>=atT+1; i--)
3519      strat->T[i] = strat->T[i-1];
3520  }
3521  else atT = 0;
3522  strat->T[atT].p = p.p;
3523  strat->T[atT].ecart = p.ecart;
3524  strat->T[atT].length = p.length;
3525  strat->tl++;
3526}
3527
3528/*2
3529* puts p to the set T at position atT
3530*/
3531void enterTBba (LObject p, int atT,kStrategy strat)
3532{
3533  int i;
3534
3535  strat->newt = TRUE;
3536  if (strat->tl == strat->tmax-1) enlargeT(&strat->T,&strat->tmax,setmax);
3537  for (i=strat->tl+1; i>=atT+1; i--)
3538    strat->T[i] = strat->T[i-1];
3539  strat->T[atT].p = p.p;
3540  if (strat->honey)
3541    strat->T[atT].ecart = p.ecart;
3542  if (TEST_OPT_INTSTRATEGY)
3543    strat->T[atT].length = p.length;
3544  strat->tl++;
3545//    for (i=0; i<=strat->tl ;i++)
3546//    {
3547//      pTest(strat->T[i].p);
3548//    }
3549}
3550
3551void initHilbCrit(ideal F, ideal Q, intvec **hilb,kStrategy strat)
3552{
3553  if (strat->homog!=isHomog)
3554  {
3555    *hilb=NULL;
3556  }
3557}
3558
3559void initBuchMoraCrit(kStrategy strat)
3560{
3561  strat->sugarCrit =        TEST_OPT_SUGARCRIT;
3562  strat->Gebauer =          BTEST1(2) || strat->homog || strat->sugarCrit;
3563  strat->honey =            !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
3564  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
3565  strat->pairtest = NULL;
3566  /* alway use tailreduction, except:
3567  * - in local rings, - in lex order case, -in ring over extensions */
3568  strat->noTailReduction = !TEST_OPT_REDTAIL;
3569  if (TEST_OPT_DEBUG)
3570  {
3571    if (strat->homog) PrintS("ideal/module is homogeneous\n");
3572    else              PrintS("ideal/module is not homogeneous\n");
3573  }
3574}
3575
3576void initBuchMoraPos (kStrategy strat)
3577{
3578  if (pOrdSgn==1)
3579  {
3580    if (strat->honey)
3581    {
3582      strat->posInL = posInL15;
3583      strat->posInT = posInT15;
3584    }
3585    else if (pLexOrder && !TEST_OPT_INTSTRATEGY)
3586    {
3587      strat->posInL = posInL11;
3588      strat->posInT = posInT11;
3589    }
3590    else if (TEST_OPT_INTSTRATEGY)
3591    {
3592      strat->posInL = posInL11;
3593      strat->posInT = posInT11;
3594    }
3595    else
3596    {
3597      strat->posInL = posInL0;
3598      strat->posInT = posInT0;
3599    }
3600    //if (strat->minim>0) strat->posInL =posInLSpecial;
3601  }
3602  else
3603  {
3604    if (strat->homog)
3605    {
3606      strat->posInL = posInL11;
3607      strat->posInT = posInT11;
3608    }
3609    else
3610    {
3611      if ((currRing->order[0]==ringorder_c)
3612      ||(currRing->order[0]==ringorder_C))
3613      {
3614        strat->posInL = posInL17_c;
3615        strat->posInT = posInT17_c;
3616      }
3617      else
3618      {
3619        strat->posInL = posInL17;
3620        strat->posInT = posInT17;
3621      }
3622    }
3623  }
3624  if (strat->minim>0) strat->posInL =posInLSpecial;
3625  // for further tests only
3626  if ((BTEST1(11)) || (BTEST1(12)))
3627    strat->posInL = posInL11;
3628  else if ((BTEST1(13)) || (BTEST1(14)))
3629    strat->posInL = posInL13;
3630  else if ((BTEST1(15)) || (BTEST1(16)))
3631    strat->posInL = posInL15;
3632  else if ((BTEST1(17)) || (BTEST1(18)))
3633    strat->posInL = posInL17;
3634  if (BTEST1(11))
3635    strat->posInT = posInT11;
3636  else if (BTEST1(13))
3637    strat->posInT = posInT13;
3638  else if (BTEST1(15))
3639    strat->posInT = posInT15;
3640  else if ((BTEST1(17)))
3641    strat->posInT = posInT17;
3642  else if ((BTEST1(19)))
3643    strat->posInT = posInT19;
3644  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
3645    strat->posInT = posInT1;
3646}
3647
3648void initBuchMora (ideal F,ideal Q,kStrategy strat)
3649{
3650  strat->interpt = BTEST1(OPT_INTERRUPT);
3651  strat->kHEdge=NULL;
3652  if (pOrdSgn==1) strat->kHEdgeFound=FALSE;
3653  /*- creating temp data structures------------------- -*/
3654  strat->cp = 0;
3655  strat->c3 = 0;
3656  strat->tail = pInit();
3657  /*- set s -*/
3658  strat->sl = -1;
3659  /*- set L -*/
3660  strat->Lmax = setmax;
3661  strat->Ll = -1;
3662  strat->L = initL();
3663  /*- set B -*/
3664  strat->Bmax = setmax;
3665  strat->Bl = -1;
3666  strat->B = initL();
3667  /*- set T -*/
3668  strat->tl = -1;
3669  strat->tmax = setmax;
3670  strat->T = initT();
3671  /*- init local data struct.---------------------------------------- -*/
3672  strat->P.ecart=0;
3673  strat->P.length=0;
3674  if (pOrdSgn==-1)
3675  {
3676    if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
3677    if (strat->kNoether!=NULL) pSetComp(strat->kNoether, strat->ak);
3678  }
3679  if(TEST_OPT_SB_1)
3680  {
3681    int i;
3682    ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
3683    for (i=strat->newIdeal;i<IDELEMS(F);i++)
3684    {
3685      P->m[i-strat->newIdeal] = F->m[i];
3686      F->m[i] = NULL;
3687    }
3688    initSSpecial(F,Q,P,strat);
3689    for (i=strat->newIdeal;i<IDELEMS(F);i++)
3690    {
3691      F->m[i] = P->m[i-strat->newIdeal];
3692      P->m[i-strat->newIdeal] = NULL;
3693    }
3694    idDelete(&P);
3695  }
3696  else
3697  {
3698    #ifdef SDRING
3699    if (
3700    #ifdef SRING
3701        pSRING ||
3702    #endif
3703    #ifdef DRING
3704        pDRING ||
3705    #endif
3706        0)
3707         /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
3708    else
3709    #endif
3710    /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
3711    // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
3712  }
3713  strat->kIdeal = NULL;
3714  strat->fromT = FALSE;
3715  strat->noTailReduction = !TEST_OPT_REDTAIL;
3716  if(!TEST_OPT_SB_1)
3717  {
3718    updateS(TRUE,strat);
3719    pairs(strat);
3720  }
3721  if (strat->fromQ!=NULL) Free((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
3722  strat->fromQ=NULL;
3723}
3724
3725void exitBuchMora (kStrategy strat)
3726{
3727  /*- release temp data -*/
3728  cleanT(strat);
3729  Free((ADDRESS)strat->T,(strat->tmax)*sizeof(TObject));
3730  Free((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
3731  /*- set L: should be empty -*/
3732  Free((ADDRESS)strat->L,(strat->Lmax)*sizeof(LObject));
3733  /*- set B: should be empty -*/
3734  Free((ADDRESS)strat->B,(strat->Bmax)*sizeof(LObject));
3735  pDelete1(&strat->tail);
3736  strat->syzComp=0;
3737  if (strat->kIdeal!=NULL)
3738  {
3739    Free((ADDRESS)strat->kIdeal,sizeof(sleftv));
3740    strat->kIdeal=NULL;
3741  }
3742}
3743
3744/*2
3745* in the case of a standardbase of a module over a qring:
3746* replace polynomials in i by ak vectors,
3747* (the polynomial * unit vectors gen(1)..gen(ak)
3748* in every case (also for ideals:)
3749* deletes divisible vectors/polynomials
3750*/
3751void updateResult(ideal r,ideal Q,kStrategy strat)
3752{
3753  int l;
3754  if (strat->ak>0)
3755  {
3756    for (l=IDELEMS(r)-1;l>=0;l--)
3757    {
3758      if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
3759      {
3760        pDelete(&r->m[l]); // and set it to NULL
3761      }
3762    }
3763  }
3764  else
3765  {
3766    int q;
3767    poly p;
3768    for (l=IDELEMS(r)-1;l>=0;l--)
3769    {
3770      if (r->m[l]!=NULL)
3771      {
3772        for(q=IDELEMS(Q)-1; q>=0;q--)
3773        {
3774          if ((Q->m[q]!=NULL)
3775          &&(pEqual(r->m[l],Q->m[q])))
3776          {
3777            if (TEST_OPT_REDSB)
3778            {
3779              p=r->m[l];
3780              r->m[l]=kNF(Q,NULL,p);
3781              pDelete(&p);
3782            }
3783            else
3784            {
3785              pDelete(&r->m[l]); // and set it to NULL
3786            }
3787            break;
3788          }
3789        }
3790      }
3791    }
3792  }
3793  idSkipZeroes(r);
3794}
3795
3796void completeReduce (kStrategy strat)
3797{
3798  int i;
3799
3800  strat->noTailReduction = FALSE;
3801  if (TEST_OPT_PROT)
3802  {
3803    PrintLn();
3804    if (timerv) writeTime("standard base computed:");
3805  }
3806  if (TEST_OPT_PROT)
3807  {
3808    Print("(S:%d)",strat->sl);mflush();
3809  }
3810  if(pOrdSgn==1)
3811  {
3812    for (i=strat->sl; i>0; i--)
3813    {
3814      //if (strat->interpt) test_int_std(strat->kIdeal);
3815      strat->S[i] = redtailBba(strat->S[i],i-1,strat);
3816      if (TEST_OPT_INTSTRATEGY)
3817      {
3818        //if (strat->redTailChange)
3819          pCleardenom(strat->S[i]);
3820      }
3821      if (TEST_OPT_PROT)
3822      {
3823        PrintS("-");mflush();
3824      }
3825    }
3826  }
3827  else
3828  {
3829    for (i=strat->sl; i>=0; i--)
3830    {
3831      //if (strat->interpt) test_int_std(strat->kIdeal);
3832      strat->S[i] = redtail(strat->S[i],strat->sl,strat);
3833      if (TEST_OPT_INTSTRATEGY)
3834      {
3835        pCleardenom(strat->S[i]);
3836      }
3837      if (TEST_OPT_PROT)
3838      {
3839        PrintS("-");mflush();
3840      }
3841    }
3842  }
3843}
3844
3845/*2
3846* computes the new strat->kHEdge and the new pNoether,
3847* returns TRUE, if pNoether has changed
3848*/
3849BOOLEAN newHEdge(polyset S, int ak,kStrategy strat)
3850{
3851  int i,j;
3852  poly newNoether;
3853
3854  scComputeHC(strat->Shdl,ak,strat->kHEdge);
3855  /* compare old and new noether*/
3856  newNoether = pHead0(strat->kHEdge);
3857  j = pFDeg(newNoether);
3858  for (i=1; i<=pVariables; i++)
3859  {
3860    if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
3861  }
3862  pSetm(newNoether);
3863  if (j < strat->HCord) /*- statistics -*/
3864  {
3865    if (TEST_OPT_PROT)
3866    {
3867      Print("H(%d)",j);
3868      mflush();
3869    }
3870    strat->HCord=j;
3871    if (TEST_OPT_DEBUG)
3872    {
3873      Print("H(%d):",j);
3874      wrp(strat->kHEdge);
3875      PrintLn();
3876    }
3877  }
3878  if (pComp(strat->kNoether,newNoether)!=1)
3879  {
3880    pDelete(&strat->kNoether);
3881    strat->kNoether=newNoether;
3882    return TRUE;
3883  }
3884  pFree1(newNoether);
3885  return FALSE;
3886}
3887
3888rOrderType_t spGetOrderType(ring r, int modrank, int syzcomp)
3889{
3890  if (syzcomp > 0)
3891    return rOrderType_Syz;
3892  else
3893  {
3894    rOrderType_t rot = rGetOrderType(r);
3895
3896    if ((rot == rOrderType_CompExp || rot == rOrderType_ExpComp) &&
3897        (modrank == 0))
3898      return rOrderType_Exp;
3899    else
3900      return rot;
3901  }
3902}
3903
3904
Note: See TracBrowser for help on using the repository browser.