source: git/Singular/kutil.cc @ 996e19

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