source: git/kernel/GBEngine/kstd2.cc @ b61d858

fieker-DuValspielwiese
Last change on this file since b61d858 was b61d858, checked in by Adi Popescu <adi_popescum@…>, 8 years ago
Merge remote-tracking branch 'origin/spielwiese' into SigDrop Conflicts: kernel/GBEngine/kstd1.cc kernel/GBEngine/kstd2.cc
  • Property mode set to 100644
File size: 108.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5*  ABSTRACT -  Kernel: alg. of Buchberger
6*/
7
8// #define PDEBUG 2
9
10
11
12
13
14#include <kernel/mod2.h>
15
16#define ADIDEBUG 0
17#define ADIDEBUG_COUNT 0
18#define REV_BLOCK_SBA 0
19#define SIG_DROP_FIRST 1
20
21// define if no buckets should be used
22// #define NO_BUCKETS
23
24#ifdef HAVE_PLURAL
25#define PLURAL_INTERNAL_DECLARATIONS 1
26#endif
27
28/***********************************************
29 * SBA stuff -- start
30***********************************************/
31#define DEBUGF50  0
32#define DEBUGF51  0
33
34#ifdef DEBUGF5
35#undef DEBUGF5
36//#define DEBUGF5 1
37#endif
38
39#define F5C       1
40#if F5C
41  #define F5CTAILRED 1
42#endif
43
44#define SBA_INTERRED_START                  0
45#define SBA_TAIL_RED                        1
46#define SBA_PRODUCT_CRITERION               0
47#define SBA_PRINT_ZERO_REDUCTIONS           0
48#define SBA_PRINT_REDUCTION_STEPS           0
49#define SBA_PRINT_OPERATIONS                0
50#define SBA_PRINT_SIZE_G                    0
51#define SBA_PRINT_SIZE_SYZ                  0
52#define SBA_PRINT_PRODUCT_CRITERION         0
53
54// counts sba's reduction steps
55#if SBA_PRINT_REDUCTION_STEPS
56long sba_reduction_steps;
57long sba_interreduction_steps;
58#endif
59#if SBA_PRINT_OPERATIONS
60long sba_operations;
61long sba_interreduction_operations;
62#endif
63
64/***********************************************
65 * SBA stuff -- done
66***********************************************/
67
68#include <kernel/GBEngine/kutil.h>
69#include <misc/options.h>
70#include <omalloc/omalloc.h>
71#include <kernel/polys.h>
72#include <kernel/ideals.h>
73#include <kernel/GBEngine/kstd1.h>
74#include <kernel/GBEngine/khstd.h>
75#include <polys/kbuckets.h>
76#include <polys/prCopy.h>
77//#include "cntrlc.h"
78#include <polys/weight.h>
79#include <misc/intvec.h>
80#ifdef HAVE_PLURAL
81#include <polys/nc/nc.h>
82#endif
83// #include "timer.h"
84
85/* shiftgb stuff */
86#include <kernel/GBEngine/shiftgb.h>
87
88  int (*test_PosInT)(const TSet T,const int tl,LObject &h);
89  int (*test_PosInL)(const LSet set, const int length,
90                LObject* L,const kStrategy strat);
91
92// return -1 if no divisor is found
93//        number of first divisor, otherwise
94int kFindDivisibleByInT(const kStrategy strat, const LObject* L, const int start)
95{
96  unsigned long not_sev = ~L->sev;
97  int j = start;
98
99  const TSet T=strat->T;
100  const unsigned long* sevT=strat->sevT;
101  if (L->p!=NULL)
102  {
103    const ring r=currRing;
104    const poly p=L->p;
105
106    pAssume(~not_sev == p_GetShortExpVector(p, r));
107
108    loop
109    {
110      if (j > strat->tl) return -1;
111#if defined(PDEBUG) || defined(PDIV_DEBUG)
112      if (p_LmShortDivisibleBy(T[j].p, sevT[j],p, not_sev, r))
113      {
114        if(rField_is_Ring(r))
115        {
116          if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].p), r))
117            return j;}
118          else
119          {
120            return j;
121          }
122        }
123#else
124      if (!(sevT[j] & not_sev) &&
125          p_LmDivisibleBy(T[j].p, p, r))
126        {
127          if(rField_is_Ring(r))
128          {
129            if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].p), r))
130              return j;
131          }
132          else
133          {
134            return j;
135          }
136        }
137#endif
138      j++;
139    }
140  }
141  else
142  {
143    const poly p=L->t_p;
144    const ring r=strat->tailRing;
145    loop
146    {
147      if (j > strat->tl) return -1;
148#if defined(PDEBUG) || defined(PDIV_DEBUG)
149      if (p_LmShortDivisibleBy(T[j].t_p, sevT[j],
150                               p, not_sev, r))
151        {
152          if(rField_is_Ring(r))
153          {
154            if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].t_p), r))
155              return j;
156          }
157          else
158          {
159            return j;
160          }
161        }
162#else
163      if (!(sevT[j] & not_sev) &&
164          p_LmDivisibleBy(T[j].t_p, p, r))
165        {
166          if(rField_is_Ring(r))
167          {
168            if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].t_p), r))
169              return j;
170          }
171          else
172          {
173            return j;
174          }
175        }
176#endif
177      j++;
178    }
179  }
180}
181
182// same as above, only with set S
183int kFindDivisibleByInS(const kStrategy strat, int* max_ind, LObject* L)
184{
185  unsigned long not_sev = ~L->sev;
186  poly p = L->GetLmCurrRing();
187  int j = 0;
188
189  pAssume(~not_sev == p_GetShortExpVector(p, currRing));
190#if 1
191  int ende;
192  if ((strat->ak>0) || currRing->pLexOrder) ende=strat->sl;
193  else ende=posInS(strat,*max_ind,p,0)+1;
194  if (ende>(*max_ind)) ende=(*max_ind);
195#else
196  int ende=strat->sl;
197#endif
198  (*max_ind)=ende;
199  loop
200  {
201    if (j > ende) return -1;
202#if defined(PDEBUG) || defined(PDIV_DEBUG)
203    if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j],
204                             p, not_sev, currRing))
205        {
206            if(rField_is_Ring(currRing))
207                {if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing))
208                    return j;}
209            else
210            return j;
211        }
212#else
213    if ( !(strat->sevS[j] & not_sev) &&
214         p_LmDivisibleBy(strat->S[j], p, currRing))
215        {
216            if(rField_is_Ring(currRing))
217                {if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing))
218                    return j;}
219            else
220            return j;
221        }
222#endif
223    j++;
224  }
225}
226
227int kFindNextDivisibleByInS(const kStrategy strat, int start,int max_ind, LObject* L)
228{
229  unsigned long not_sev = ~L->sev;
230  poly p = L->GetLmCurrRing();
231  int j = start;
232
233  pAssume(~not_sev == p_GetShortExpVector(p, currRing));
234#if 1
235  int ende=max_ind;
236#else
237  int ende=strat->sl;
238#endif
239  loop
240  {
241    if (j > ende) return -1;
242#if defined(PDEBUG) || defined(PDIV_DEBUG)
243    if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j],
244                             p, not_sev, currRing))
245        {
246            if(rField_is_Ring(currRing))
247                {if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing))
248                    return j;}
249            else
250            return j;
251        }
252#else
253    if ( !(strat->sevS[j] & not_sev) &&
254         p_LmDivisibleBy(strat->S[j], p, currRing))
255        {
256            if(rField_is_Ring(currRing))
257                {if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing))
258                    return j;}
259            else
260            return j;
261        }
262#endif
263    j++;
264  }
265}
266
267#ifdef HAVE_RINGS
268poly kFindZeroPoly(poly input_p, ring leadRing, ring tailRing)
269{
270  // m = currRing->ch
271
272  if (input_p == NULL) return NULL;
273
274  poly p = input_p;
275  poly zeroPoly = NULL;
276  unsigned long a = (unsigned long) pGetCoeff(p);
277
278  int k_ind2 = 0;
279  int a_ind2 = ind2(a);
280
281  // unsigned long k = 1;
282  // of interest is only k_ind2, special routine for improvement ... TODO OLIVER
283  for (int i = 1; i <= leadRing->N; i++)
284  {
285    k_ind2 = k_ind2 + ind_fact_2(p_GetExp(p, i, leadRing));
286  }
287
288  a = (unsigned long) pGetCoeff(p);
289
290  number tmp1;
291  poly tmp2, tmp3;
292  poly lead_mult = p_ISet(1, tailRing);
293  if (n_GetChar(leadRing->cf) <= k_ind2 + a_ind2)
294  {
295    int too_much = k_ind2 + a_ind2 - n_GetChar(leadRing->cf);
296    int s_exp;
297    zeroPoly = p_ISet(a, tailRing);
298    for (int i = 1; i <= leadRing->N; i++)
299    {
300      s_exp = p_GetExp(p, i,leadRing);
301      if (s_exp % 2 != 0)
302      {
303        s_exp = s_exp - 1;
304      }
305      while ( (0 < ind2(s_exp)) && (ind2(s_exp) <= too_much) )
306      {
307        too_much = too_much - ind2(s_exp);
308        s_exp = s_exp - 2;
309      }
310      p_SetExp(lead_mult, i, p_GetExp(p, i,leadRing) - s_exp, tailRing);
311      for (int j = 1; j <= s_exp; j++)
312      {
313        tmp1 = nInit(j);
314        tmp2 = p_ISet(1, tailRing);
315        p_SetExp(tmp2, i, 1, tailRing);
316        p_Setm(tmp2, tailRing);
317        if (nIsZero(tmp1))
318        { // should nowbe obsolet, test ! TODO OLIVER
319          zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
320        }
321        else
322        {
323          tmp3 = p_NSet(nCopy(tmp1), tailRing);
324          zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing);
325        }
326      }
327    }
328    p_Setm(lead_mult, tailRing);
329    zeroPoly = p_Mult_mm(zeroPoly, lead_mult, tailRing);
330    tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing);
331    for (int i = 1; i <= leadRing->N; i++)
332    {
333      pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
334    }
335    p_Setm(tmp2, leadRing);
336    zeroPoly = p_LmDeleteAndNext(zeroPoly, tailRing);
337    pNext(tmp2) = zeroPoly;
338    return tmp2;
339  }
340/*  unsigned long alpha_k = twoPow(leadRing->ch - k_ind2);
341  if (1 == 0 && alpha_k <= a)
342  {  // Temporarly disabled, reducing coefficients not compatible with std TODO Oliver
343    zeroPoly = p_ISet((a / alpha_k)*alpha_k, tailRing);
344    for (int i = 1; i <= leadRing->N; i++)
345    {
346      for (unsigned long j = 1; j <= p_GetExp(p, i, leadRing); j++)
347      {
348        tmp1 = nInit(j);
349        tmp2 = p_ISet(1, tailRing);
350        p_SetExp(tmp2, i, 1, tailRing);
351        p_Setm(tmp2, tailRing);
352        if (nIsZero(tmp1))
353        {
354          zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
355        }
356        else
357        {
358          tmp3 = p_ISet((unsigned long) tmp1, tailRing);
359          zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp2, tmp3, tailRing), tailRing);
360        }
361      }
362    }
363    tmp2 = p_ISet((unsigned long) pGetCoeff(zeroPoly), leadRing);
364    for (int i = 1; i <= leadRing->N; i++)
365    {
366      pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
367    }
368    p_Setm(tmp2, leadRing);
369    zeroPoly = p_LmDeleteAndNext(zeroPoly, tailRing);
370    pNext(tmp2) = zeroPoly;
371    return tmp2;
372  } */
373  return NULL;
374}
375#endif
376
377
378#ifdef HAVE_RINGS
379/*2
380*  reduction procedure for the ring Z/2^m
381*/
382int redRing (LObject* h,kStrategy strat)
383{
384  if (h->IsNull()) return 0; // spoly is zero (can only occure with zero divisors)
385  if (strat->tl<0) return 1;
386
387  int at/*,i*/;
388  long d;
389  int j = 0;
390  int pass = 0;
391  // poly zeroPoly = NULL;
392
393// TODO warum SetpFDeg notwendig?
394  h->SetpFDeg();
395  assume(h->pFDeg() == h->FDeg);
396  long reddeg = h->GetpFDeg();
397
398  h->SetShortExpVector();
399  loop
400  {
401    j = kFindDivisibleByInT(strat, h);
402    if (j < 0)
403    {
404      // over ZZ: cleanup coefficients by complete reduction with monomials
405      postReduceByMon(h, strat);
406      if(nIsZero(pGetCoeff(h->p))) return 2;
407      j = kFindDivisibleByInT(strat, h);
408      if(j < 0)
409      {
410        if(strat->tl >= 0)
411            h->i_r1 = strat->tl;
412        else
413            h->i_r1 = -1;
414        if (h->GetLmTailRing() == NULL)
415        {
416          if (h->lcm!=NULL) pLmDelete(h->lcm);
417          h->Clear();
418          return 0;
419        }
420        return 1;
421      }
422    }
423    //enterT(*h, strat);
424    ksReducePoly(h, &(strat->T[j]), NULL, NULL, strat); // with debug output
425
426    if (h->GetLmTailRing() == NULL)
427    {
428      if (h->lcm!=NULL) pLmDelete(h->lcm);
429#ifdef KDEBUG
430      h->lcm=NULL;
431#endif
432      h->Clear();
433      return 0;
434    }
435    h->SetShortExpVector();
436    d = h->SetpFDeg();
437    /*- try to reduce the s-polynomial -*/
438    pass++;
439    if (!TEST_OPT_REDTHROUGH &&
440        (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
441    {
442      h->SetLmCurrRing();
443      if (strat->posInLDependsOnLength)
444        h->SetLength(strat->length_pLength);
445      at = strat->posInL(strat->L,strat->Ll,h,strat);
446      if (at <= strat->Ll)
447      {
448#ifdef KDEBUG
449        if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at);
450#endif
451        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);     // NOT RING CHECKED OLIVER
452        h->Clear();
453        return -1;
454      }
455    }
456    if (d != reddeg)
457    {
458      if (d >= (long)strat->tailRing->bitmask)
459      {
460        if (h->pTotalDeg() >= (long)strat->tailRing->bitmask)
461        {
462          strat->overflow=TRUE;
463          //Print("OVERFLOW in redRing d=%ld, max=%ld\n",d,strat->tailRing->bitmask);
464          h->GetP();
465          at = strat->posInL(strat->L,strat->Ll,h,strat);
466          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
467          h->Clear();
468          return -1;
469        }
470      }
471      else if ((TEST_OPT_PROT) && (strat->Ll < 0))
472      {
473        Print(".%ld",d);mflush();
474        reddeg = d;
475      }
476    }
477  }
478}
479#endif
480
481/*2
482*  reduction procedure for the homogeneous case
483*  and the case of a degree-ordering
484*/
485int redHomog (LObject* h,kStrategy strat)
486{
487  if (strat->tl<0) return 1;
488  //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED!
489  assume(h->FDeg == h->pFDeg());
490
491  poly h_p;
492  int i,j,at,pass, ii;
493  unsigned long not_sev;
494  // long reddeg,d;
495
496  pass = j = 0;
497  // d = reddeg = h->GetpFDeg();
498  h->SetShortExpVector();
499  int li;
500  h_p = h->GetLmTailRing();
501  not_sev = ~ h->sev;
502  loop
503  {
504    j = kFindDivisibleByInT(strat, h);
505    if (j < 0) return 1;
506
507    li = strat->T[j].pLength;
508    ii = j;
509    /*
510     * the polynomial to reduce with (up to the moment) is;
511     * pi with length li
512     */
513    i = j;
514#if 1
515    if (TEST_OPT_LENGTH)
516    loop
517    {
518      /*- search the shortest possible with respect to length -*/
519      i++;
520      if (i > strat->tl)
521        break;
522      if (li<=1)
523        break;
524      if ((strat->T[i].pLength < li)
525         &&
526          p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
527                               h_p, not_sev, strat->tailRing))
528      {
529        /*
530         * the polynomial to reduce with is now;
531         */
532        li = strat->T[i].pLength;
533        ii = i;
534      }
535    }
536#endif
537
538    /*
539     * end of search: have to reduce with pi
540     */
541#ifdef KDEBUG
542    if (TEST_OPT_DEBUG)
543    {
544      PrintS("red:");
545      h->wrp();
546      PrintS(" with ");
547      strat->T[ii].wrp();
548    }
549#endif
550    assume(strat->fromT == FALSE);
551
552    ksReducePoly(h, &(strat->T[ii]), NULL, NULL, strat);
553#if SBA_PRINT_REDUCTION_STEPS
554    sba_interreduction_steps++;
555#endif
556#if SBA_PRINT_OPERATIONS
557    sba_interreduction_operations  +=  pLength(strat->T[ii].p);
558#endif
559
560#ifdef KDEBUG
561    if (TEST_OPT_DEBUG)
562    {
563      PrintS("\nto ");
564      h->wrp();
565      PrintLn();
566    }
567#endif
568
569    h_p = h->GetLmTailRing();
570    if (h_p == NULL)
571    {
572      if (h->lcm!=NULL) pLmFree(h->lcm);
573#ifdef KDEBUG
574      h->lcm=NULL;
575#endif
576      return 0;
577    }
578    h->SetShortExpVector();
579    not_sev = ~ h->sev;
580    /*
581     * try to reduce the s-polynomial h
582     *test first whether h should go to the lazyset L
583     *-if the degree jumps
584     *-if the number of pre-defined reductions jumps
585     */
586    pass++;
587    if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass))
588    {
589      h->SetLmCurrRing();
590      at = strat->posInL(strat->L,strat->Ll,h,strat);
591      if (at <= strat->Ll)
592      {
593        int dummy=strat->sl;
594        if (kFindDivisibleByInS(strat, &dummy, h) < 0)
595          return 1;
596        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
597#ifdef KDEBUG
598        if (TEST_OPT_DEBUG)
599          Print(" lazy: -> L%d\n",at);
600#endif
601        h->Clear();
602        return -1;
603      }
604    }
605  }
606}
607
608KINLINE int ksReducePolyTailSig(LObject* PR, TObject* PW, LObject* Red, kStrategy strat)
609{
610  BOOLEAN ret;
611  number coef;
612
613  assume(PR->GetLmCurrRing() != PW->GetLmCurrRing());
614  Red->HeadNormalize();
615  /*
616  printf("------------------------\n");
617  pWrite(Red->GetLmCurrRing());
618  */
619  ret = ksReducePolySig(Red, PW, 1, NULL, &coef, strat);
620
621  if (!ret)
622  {
623    if (! n_IsOne(coef, currRing->cf))
624    {
625      PR->Mult_nn(coef);
626      // HANNES: mark for Normalize
627    }
628    n_Delete(&coef, currRing->cf);
629  }
630  return ret;
631}
632
633/*2
634*  reduction procedure for signature-based standard
635*  basis algorithms:
636*  all reductions have to be sig-safe!
637*
638*  2 is returned if and only if the pair is rejected by the rewritten criterion
639*  at exactly this point of the computations. This is the last possible point
640*  such a check can be done => checks with the biggest set of available
641*  signatures
642*/
643int redSig (LObject* h,kStrategy strat)
644{
645  #ifdef HAVE_RINGS
646  poly beforeredsig;
647  if(rField_is_Ring(currRing)) 
648    beforeredsig = pCopy(h->sig);
649  #endif
650  if (strat->tl<0) return 1;
651  //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED!
652  //printf("FDEGS: %ld -- %ld\n",h->FDeg, h->pFDeg());
653  assume(h->FDeg == h->pFDeg());
654  #if ADIDEBUG
655  printf("\n--------------------------redSig-------------------------------------\n");
656  printf("\nBefore redSig:\n");
657  p_Write(h->p,strat->tailRing);pWrite(h->sig);
658  #endif
659//#if 1
660#ifdef DEBUGF5
661  Print("------- IN REDSIG -------\n");
662  Print("p: ");
663  pWrite(pHead(h->p));
664  Print("p1: ");
665  pWrite(pHead(h->p1));
666  Print("p2: ");
667  pWrite(pHead(h->p2));
668  Print("---------------------------\n");
669#endif
670  poly h_p;
671  int i,j,at,pass, ii;
672  int start=0;
673  int sigSafe;
674  unsigned long not_sev;
675  // long reddeg,d;
676
677  pass = j = 0;
678  // d = reddeg = h->GetpFDeg();
679  h->SetShortExpVector();
680  int li;
681  h_p = h->GetLmTailRing();
682  not_sev = ~ h->sev;
683  loop
684  {
685    j = kFindDivisibleByInT(strat, h, start);
686    if (j < 0)
687    {
688      // over ZZ: cleanup coefficients by complete reduction with monomials
689      postReduceByMonSig(h, strat);
690      if(nIsZero(pGetCoeff(h->p))) return 2;
691      j = kFindDivisibleByInT(strat, h,start);
692      if(j < 0)
693      {
694        if(strat->tl >= 0)
695            h->i_r1 = strat->tl;
696        else
697            h->i_r1 = -1;
698        if (h->GetLmTailRing() == NULL)
699        {
700          if (h->lcm!=NULL) pLmDelete(h->lcm);
701          h->Clear();
702          return 0;
703        }
704        #ifdef HAVE_RINGS
705        if(rField_is_Ring(currRing))
706        {
707          //Check for sigdrop after reduction
708          if(pLtCmp(beforeredsig,h->sig) == 1)
709          {
710            #if ADIDEBUG
711            printf("\nSigDrop after reduce\n");pWrite(beforeredsig);pWrite(h->sig);
712            #endif
713            strat->sigdrop = TRUE;
714            //Reduce it as much as you can
715            int red_result = redRing(h,strat);
716            if(red_result == 0)
717            {
718              //It reduced to 0, cancel the sigdrop
719              #if ADIDEBUG
720              printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
721              #endif
722              strat->sigdrop = FALSE;
723              p_Delete(&h->sig,currRing);h->sig = NULL;
724              return 0;
725            }
726            else
727            {
728              #if ADIDEBUG
729              printf("\nReduced to this via redRing.SIGDROP\n");pWrite(h->p);
730              #endif
731              //strat->enterS(*h, strat->sl+1, strat, strat->tl);
732              return 0;
733            }
734          }
735          p_Delete(&beforeredsig,currRing);
736        }
737        #endif
738        return 1;
739      }
740    }
741
742    li = strat->T[j].pLength;
743    ii = j;
744    /*
745     * the polynomial to reduce with (up to the moment) is;
746     * pi with length li
747     */
748    i = j;
749#if 1
750    if (TEST_OPT_LENGTH)
751    loop
752    {
753      /*- search the shortest possible with respect to length -*/
754      i++;
755      if (i > strat->tl)
756        break;
757      if (li<=1)
758        break;
759      if ((strat->T[i].pLength < li)
760         #ifdef HAVE_RINGS
761         && (!rField_is_Ring(currRing) || n_DivBy(pGetCoeff(h_p),pGetCoeff(strat->T[i].p),currRing->cf))
762         #endif
763         && p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
764                               h_p, not_sev, strat->tailRing))
765      {
766        /*
767         * the polynomial to reduce with is now;
768         */
769        li = strat->T[i].pLength;
770        ii = i;
771      }
772    }
773    start = ii+1;
774#endif
775
776    /*
777     * end of search: have to reduce with pi
778     */
779#ifdef KDEBUG
780    if (TEST_OPT_DEBUG)
781    {
782      PrintS("red:");
783      h->wrp();
784      PrintS(" with ");
785      strat->T[ii].wrp();
786    }
787#endif
788    assume(strat->fromT == FALSE);
789//#if 1
790#ifdef DEBUGF5
791    Print("BEFORE REDUCTION WITH %d:\n",ii);
792    Print("--------------------------------\n");
793    pWrite(h->sig);
794    pWrite(strat->T[ii].sig);
795    pWrite(h->GetLmCurrRing());
796    pWrite(pHead(h->p1));
797    pWrite(pHead(h->p2));
798    pWrite(pHead(strat->T[ii].p));
799    Print("--------------------------------\n");
800    printf("INDEX OF REDUCER T: %d\n",ii);
801#endif
802    #if ADIDEBUG
803    printf("\nWe reduce it with:\n");p_Write(strat->T[ii].p,strat->tailRing);pWrite(strat->T[ii].sig);
804    #endif
805    sigSafe = ksReducePolySig(h, &(strat->T[ii]), strat->S_2_R[ii], NULL, NULL, strat);
806    #if ADIDEBUG
807    printf("\nAfter small reduction:\n");pWrite(h->p);pWrite(h->sig);
808    #endif
809    #ifdef HAVE_RINGS
810    if(rField_is_Ring(currRing) && h->p == NULL && h->sig == NULL)
811    {
812      //Trivial case catch
813      strat->sigdrop = FALSE;
814    }
815    if(rField_is_Ring(currRing) && strat->sigdrop)
816    {
817      return 1;
818    }
819    #endif
820#if SBA_PRINT_REDUCTION_STEPS
821    if (sigSafe != 3)
822      sba_reduction_steps++;
823#endif
824#if SBA_PRINT_OPERATIONS
825    if (sigSafe != 3)
826      sba_operations  +=  pLength(strat->T[ii].p);
827#endif
828    // if reduction has taken place, i.e. the reduction was sig-safe
829    // otherwise start is already at the next position and the loop
830    // searching reducers in T goes on from index start
831//#if 1
832#ifdef DEBUGF5
833    Print("SigSAFE: %d\n",sigSafe);
834#endif
835    if (sigSafe != 3)
836    {
837      // start the next search for reducers in T from the beginning
838      start = 0;
839#ifdef KDEBUG
840      if (TEST_OPT_DEBUG)
841      {
842        PrintS("\nto ");
843        h->wrp();
844        PrintLn();
845      }
846#endif
847
848      h_p = h->GetLmTailRing();
849      if (h_p == NULL)
850      {
851        if (h->lcm!=NULL) pLmFree(h->lcm);
852#ifdef KDEBUG
853        h->lcm=NULL;
854#endif
855        return 0;
856      }
857      h->SetShortExpVector();
858      not_sev = ~ h->sev;
859      /*
860      * try to reduce the s-polynomial h
861      *test first whether h should go to the lazyset L
862      *-if the degree jumps
863      *-if the number of pre-defined reductions jumps
864      */
865      pass++;
866      if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass))
867      {
868        h->SetLmCurrRing();
869        at = strat->posInL(strat->L,strat->Ll,h,strat);
870        if (at <= strat->Ll)
871        {
872          int dummy=strat->sl;
873          if (kFindDivisibleByInS(strat, &dummy, h) < 0)
874          {
875            return 1;
876          }
877          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
878#ifdef KDEBUG
879          if (TEST_OPT_DEBUG)
880            Print(" lazy: -> L%d\n",at);
881#endif
882          h->Clear();
883          return -1;
884        }
885      }
886    }
887  }
888}
889
890// tail reduction for SBA
891poly redtailSba (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
892{
893#define REDTAIL_CANONICALIZE 100
894  strat->redTailChange=FALSE;
895  if (strat->noTailReduction) return L->GetLmCurrRing();
896  poly h, p;
897  p = h = L->GetLmTailRing();
898  if ((h==NULL) || (pNext(h)==NULL))
899    return L->GetLmCurrRing();
900
901  TObject* With;
902  // placeholder in case strat->tl < 0
903  TObject  With_s(strat->tailRing);
904
905  LObject Ln(pNext(h), strat->tailRing);
906  Ln.sig      = L->sig;
907  Ln.sevSig   = L->sevSig;
908  Ln.pLength  = L->GetpLength() - 1;
909
910  pNext(h) = NULL;
911  if (L->p != NULL) pNext(L->p) = NULL;
912  L->pLength = 1;
913
914  Ln.PrepareRed(strat->use_buckets);
915
916  int cnt=REDTAIL_CANONICALIZE;
917  while(!Ln.IsNull())
918  {
919    loop
920    {
921      #ifdef HAVE_RINGS
922      if(rField_is_Ring(currRing) && strat->sigdrop)
923        break;
924      #endif
925      Ln.SetShortExpVector();
926      if (withT)
927      {
928        int j;
929        j = kFindDivisibleByInT(strat, &Ln);
930        if (j < 0) break;
931        With = &(strat->T[j]);
932      }
933      else
934      {
935        With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
936        if (With == NULL) break;
937      }
938      cnt--;
939      if (cnt==0)
940      {
941        cnt=REDTAIL_CANONICALIZE;
942        /*poly tmp=*/Ln.CanonicalizeP();
943        if (normalize)
944        {
945          Ln.Normalize();
946          //pNormalize(tmp);
947          //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
948        }
949      }
950      if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
951      {
952        With->pNorm();
953      }
954      strat->redTailChange=TRUE;
955      #if ADIDEBUG
956      printf("\nWill TAILreduce * with *:\n");pWrite(Ln.p);pWrite(Ln.sig);
957      pWrite(With->p);pWrite(With->sig);pWrite(L->sig);
958      #endif
959      int ret = ksReducePolyTailSig(L, With, &Ln, strat);
960      #ifdef HAVE_RINGS
961      if(rField_is_Ring(currRing) && strat->sigdrop)
962      {
963        //Cannot break the loop here so easily
964        break;
965      }
966      if(rField_is_Ring(currRing))
967        L->sig = Ln.sig;
968      //Because Ln.sig is set to L->sig, but in ksReducePolyTailSig -> ksReducePolySig
969      // I delete it an then set Ln.sig. Hence L->sig is lost
970      #endif
971      #if ADIDEBUG
972      printf("\nAfter small TAILreduce:\n");pWrite(Ln.p);pWrite(Ln.sig);pWrite(L->sig);
973      #endif
974#if SBA_PRINT_REDUCTION_STEPS
975      if (ret != 3)
976        sba_reduction_steps++;
977#endif
978#if SBA_PRINT_OPERATIONS
979      if (ret != 3)
980        sba_operations  +=  pLength(With->p);
981#endif
982      if (ret)
983      {
984        // reducing the tail would violate the exp bound
985        //  set a flag and hope for a retry (in bba)
986        strat->completeReduce_retry=TRUE;
987        if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
988        do
989        {
990          pNext(h) = Ln.LmExtractAndIter();
991          pIter(h);
992          L->pLength++;
993        } while (!Ln.IsNull());
994        goto all_done;
995      }
996      if (Ln.IsNull()) goto all_done;
997      if (! withT) With_s.Init(currRing);
998    }
999    pNext(h) = Ln.LmExtractAndIter();
1000    pIter(h);
1001    pNormalize(h);
1002    L->pLength++;
1003  }
1004  all_done:
1005  Ln.Delete();
1006  if (L->p != NULL) pNext(L->p) = pNext(p);
1007
1008  if (strat->redTailChange)
1009  {
1010    L->length = 0;
1011  }
1012
1013  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
1014  //L->Normalize(); // HANNES: should have a test
1015  kTest_L(L);
1016  return L->GetLmCurrRing();
1017}
1018
1019/*2
1020*  reduction procedure for the inhomogeneous case
1021*  and not a degree-ordering
1022*/
1023int redLazy (LObject* h,kStrategy strat)
1024{
1025  if (strat->tl<0) return 1;
1026  int at,i,ii,li;
1027  int j = 0;
1028  int pass = 0;
1029  assume(h->pFDeg() == h->FDeg);
1030  long reddeg = h->GetpFDeg();
1031  long d;
1032  unsigned long not_sev;
1033
1034  h->SetShortExpVector();
1035  poly h_p = h->GetLmTailRing();
1036  not_sev = ~ h->sev;
1037  loop
1038  {
1039    j = kFindDivisibleByInT(strat, h);
1040    if (j < 0) return 1;
1041
1042    li = strat->T[j].pLength;
1043    #if 0
1044    if (li==0)
1045    {
1046      li=strat->T[j].pLength=pLength(strat->T[j].p);
1047    }
1048    #endif
1049    ii = j;
1050    /*
1051     * the polynomial to reduce with (up to the moment) is;
1052     * pi with length li
1053     */
1054
1055    i = j;
1056#if 1
1057    if (TEST_OPT_LENGTH)
1058    loop
1059    {
1060      /*- search the shortest possible with respect to length -*/
1061      i++;
1062      if (i > strat->tl)
1063        break;
1064      if (li<=1)
1065        break;
1066    #if 0
1067      if (strat->T[i].pLength==0)
1068      {
1069        PrintS("!");
1070        strat->T[i].pLength=pLength(strat->T[i].p);
1071      }
1072   #endif
1073      if ((strat->T[i].pLength < li)
1074         &&
1075          p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
1076                               h_p, not_sev, strat->tailRing))
1077      {
1078        /*
1079         * the polynomial to reduce with is now;
1080         */
1081        PrintS("+");
1082        li = strat->T[i].pLength;
1083        ii = i;
1084      }
1085    }
1086#endif
1087
1088    /*
1089     * end of search: have to reduce with pi
1090     */
1091
1092
1093#ifdef KDEBUG
1094    if (TEST_OPT_DEBUG)
1095    {
1096      PrintS("red:");
1097      h->wrp();
1098      PrintS(" with ");
1099      strat->T[ii].wrp();
1100    }
1101#endif
1102
1103    ksReducePoly(h, &(strat->T[ii]), NULL, NULL, strat);
1104#if SBA_PRINT_REDUCTION_STEPS
1105    sba_interreduction_steps++;
1106#endif
1107#if SBA_PRINT_OPERATIONS
1108    sba_interreduction_operations  +=  pLength(strat->T[ii].p);
1109#endif
1110
1111#ifdef KDEBUG
1112    if (TEST_OPT_DEBUG)
1113    {
1114      PrintS("\nto ");
1115      h->wrp();
1116      PrintLn();
1117    }
1118#endif
1119
1120    h_p=h->GetLmTailRing();
1121
1122    if (h_p == NULL)
1123    {
1124      if (h->lcm!=NULL) pLmFree(h->lcm);
1125#ifdef KDEBUG
1126      h->lcm=NULL;
1127#endif
1128      return 0;
1129    }
1130    h->SetShortExpVector();
1131    not_sev = ~ h->sev;
1132    d = h->SetpFDeg();
1133    /*- try to reduce the s-polynomial -*/
1134    pass++;
1135    if (//!TEST_OPT_REDTHROUGH &&
1136        (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
1137    {
1138      h->SetLmCurrRing();
1139      at = strat->posInL(strat->L,strat->Ll,h,strat);
1140      if (at <= strat->Ll)
1141      {
1142#if 1
1143        int dummy=strat->sl;
1144        if (kFindDivisibleByInS(strat, &dummy, h) < 0)
1145          return 1;
1146#endif
1147#ifdef KDEBUG
1148        if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at);
1149#endif
1150        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1151        h->Clear();
1152        return -1;
1153      }
1154    }
1155    else if (d != reddeg)
1156    {
1157      if (d>=(long)strat->tailRing->bitmask)
1158      {
1159        if (h->pTotalDeg() >= (long)strat->tailRing->bitmask)
1160        {
1161          strat->overflow=TRUE;
1162          //Print("OVERFLOW in redLazy d=%ld, max=%ld\n",d,strat->tailRing->bitmask);
1163          h->GetP();
1164          at = strat->posInL(strat->L,strat->Ll,h,strat);
1165          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1166          h->Clear();
1167          return -1;
1168        }
1169      }
1170      else if ((TEST_OPT_PROT) && (strat->Ll < 0))
1171      {
1172        Print(".%ld",d);mflush();
1173        reddeg = d;
1174      }
1175    }
1176  }
1177}
1178/*2
1179*  reduction procedure for the sugar-strategy (honey)
1180* reduces h with elements from T choosing first possible
1181* element in T with respect to the given ecart
1182*/
1183int redHoney (LObject* h, kStrategy strat)
1184{
1185  if (strat->tl<0) return 1;
1186  //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED!
1187  assume(h->FDeg == h->pFDeg());
1188  poly h_p;
1189  int i,j,at,pass,ei, ii, h_d;
1190  unsigned long not_sev;
1191  long reddeg,d;
1192
1193  pass = j = 0;
1194  d = reddeg = h->GetpFDeg() + h->ecart;
1195  h->SetShortExpVector();
1196  int li;
1197  h_p = h->GetLmTailRing();
1198  not_sev = ~ h->sev;
1199
1200  h->PrepareRed(strat->use_buckets);
1201  loop
1202  {
1203    j=kFindDivisibleByInT(strat, h);
1204    if (j < 0) return 1;
1205
1206    ei = strat->T[j].ecart;
1207    li = strat->T[j].pLength;
1208    ii = j;
1209    /*
1210     * the polynomial to reduce with (up to the moment) is;
1211     * pi with ecart ei
1212     */
1213    i = j;
1214    if (TEST_OPT_LENGTH)
1215    loop
1216    {
1217      /*- takes the first possible with respect to ecart -*/
1218      i++;
1219      if (i > strat->tl)
1220        break;
1221      //if (ei < h->ecart)
1222      //  break;
1223      if (li<=1)
1224        break;
1225      if ((((strat->T[i].ecart < ei) && (ei> h->ecart))
1226         || ((strat->T[i].ecart <= h->ecart) && (strat->T[i].pLength < li)))
1227         &&
1228          p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
1229                               h_p, not_sev, strat->tailRing))
1230      {
1231        /*
1232         * the polynomial to reduce with is now;
1233         */
1234        ei = strat->T[i].ecart;
1235        li = strat->T[i].pLength;
1236        ii = i;
1237      }
1238    }
1239
1240    /*
1241     * end of search: have to reduce with pi
1242     */
1243    if (!TEST_OPT_REDTHROUGH && (pass!=0) && (ei > h->ecart))
1244    {
1245      h->GetTP(); // clears bucket
1246      h->SetLmCurrRing();
1247      /*
1248       * It is not possible to reduce h with smaller ecart;
1249       * if possible h goes to the lazy-set L,i.e
1250       * if its position in L would be not the last one
1251       */
1252      if (strat->Ll >= 0) /* L is not empty */
1253      {
1254        at = strat->posInL(strat->L,strat->Ll,h,strat);
1255        if(at <= strat->Ll)
1256          /*- h will not become the next element to reduce -*/
1257        {
1258          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1259#ifdef KDEBUG
1260          if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at);
1261#endif
1262          h->Clear();
1263          return -1;
1264        }
1265      }
1266    }
1267#ifdef KDEBUG
1268    if (TEST_OPT_DEBUG)
1269    {
1270      PrintS("red:");
1271      h->wrp();
1272      PrintS(" with ");
1273      strat->T[ii].wrp();
1274    }
1275#endif
1276    assume(strat->fromT == FALSE);
1277
1278    number coef;
1279    ksReducePoly(h,&(strat->T[ii]),strat->kNoetherTail(),&coef,strat);
1280#if SBA_PRINT_REDUCTION_STEPS
1281    sba_interreduction_steps++;
1282#endif
1283#if SBA_PRINT_OPERATIONS
1284    sba_interreduction_operations  +=  pLength(strat->T[ii].p);
1285#endif
1286#ifdef KDEBUG
1287    if (TEST_OPT_DEBUG)
1288    {
1289      PrintS("\nto:");
1290      h->wrp();
1291      PrintLn();
1292    }
1293#endif
1294    if(h->IsNull())
1295    {
1296      h->Clear();
1297      if (h->lcm!=NULL) pLmFree(h->lcm);
1298      #ifdef KDEBUG
1299      h->lcm=NULL;
1300      #endif
1301      return 0;
1302    }
1303    if (TEST_OPT_IDLIFT)
1304    {
1305      if (h->p!=NULL)
1306      {
1307        if(p_GetComp(h->p,currRing)>strat->syzComp)
1308        {
1309          h->Delete();
1310          return 0;
1311        }
1312      }
1313      else if (h->t_p!=NULL)
1314      {
1315        if(p_GetComp(h->t_p,strat->tailRing)>strat->syzComp)
1316        {
1317          h->Delete();
1318          return 0;
1319        }
1320      }
1321    }
1322    h->SetShortExpVector();
1323    not_sev = ~ h->sev;
1324    h_d = h->SetpFDeg();
1325    /* compute the ecart */
1326    if (ei <= h->ecart)
1327      h->ecart = d-h_d;
1328    else
1329      h->ecart = d-h_d+ei-h->ecart;
1330
1331    /*
1332     * try to reduce the s-polynomial h
1333     *test first whether h should go to the lazyset L
1334     *-if the degree jumps
1335     *-if the number of pre-defined reductions jumps
1336     */
1337    pass++;
1338    d = h_d + h->ecart;
1339    if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
1340    {
1341      h->GetTP(); // clear bucket
1342      h->SetLmCurrRing();
1343      at = strat->posInL(strat->L,strat->Ll,h,strat);
1344      if (at <= strat->Ll)
1345      {
1346        int dummy=strat->sl;
1347        if (kFindDivisibleByInS(strat, &dummy, h) < 0)
1348          return 1;
1349        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1350#ifdef KDEBUG
1351        if (TEST_OPT_DEBUG)
1352          Print(" degree jumped: -> L%d\n",at);
1353#endif
1354        h->Clear();
1355        return -1;
1356      }
1357    }
1358    else if (d > reddeg)
1359    {
1360      if (d>=(long)strat->tailRing->bitmask)
1361      {
1362        if (h->pTotalDeg()+h->ecart >= (long)strat->tailRing->bitmask)
1363        {
1364          strat->overflow=TRUE;
1365          //Print("OVERFLOW in redHoney d=%ld, max=%ld\n",d,strat->tailRing->bitmask);
1366          h->GetP();
1367          at = strat->posInL(strat->L,strat->Ll,h,strat);
1368          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1369          h->Clear();
1370          return -1;
1371        }
1372      }
1373      else if (TEST_OPT_PROT && (strat->Ll < 0) )
1374      {
1375        //h->wrp(); Print("<%d>\n",h->GetpLength());
1376        reddeg = d;
1377        Print(".%ld",d); mflush();
1378      }
1379    }
1380  }
1381}
1382
1383/*2
1384*  reduction procedure for the normal form
1385*/
1386
1387poly redNF (poly h,int &max_ind,int nonorm,kStrategy strat)
1388{
1389  if (h==NULL) return NULL;
1390  int j;
1391  max_ind=strat->sl;
1392
1393  if (0 > strat->sl)
1394  {
1395    return h;
1396  }
1397  LObject P(h);
1398  P.SetShortExpVector();
1399  P.bucket = kBucketCreate(currRing);
1400  kBucketInit(P.bucket,P.p,pLength(P.p));
1401  kbTest(P.bucket);
1402#ifdef HAVE_RINGS
1403  BOOLEAN is_ring = rField_is_Ring(currRing);
1404#endif
1405#ifdef KDEBUG
1406//  if (TEST_OPT_DEBUG)
1407//  {
1408//    PrintS("redNF: starting S:\n");
1409//    for( j = 0; j <= max_ind; j++ )
1410//    {
1411//      Print("S[%d] (of size: %d): ", j, pSize(strat->S[j]));
1412//      pWrite(strat->S[j]);
1413//    }
1414//  };
1415#endif
1416
1417  loop
1418  {
1419    j=kFindDivisibleByInS(strat,&max_ind,&P);
1420    if (j>=0)
1421    {
1422#ifdef HAVE_RINGS
1423      if (!is_ring)
1424      {
1425#endif
1426        int sl=pSize(strat->S[j]);
1427        int jj=j;
1428        loop
1429        {
1430          int sll;
1431          jj=kFindNextDivisibleByInS(strat,jj+1,max_ind,&P);
1432          if (jj<0) break;
1433          sll=pSize(strat->S[jj]);
1434          if (sll<sl)
1435          {
1436            #ifdef KDEBUG
1437            if (TEST_OPT_DEBUG) Print("better(S%d:%d -> S%d:%d)\n",j,sl,jj,sll);
1438            #endif
1439            //else if (TEST_OPT_PROT) { PrintS("b"); mflush(); }
1440            j=jj;
1441            sl=sll;
1442          }
1443        }
1444        if ((nonorm==0) && (!nIsOne(pGetCoeff(strat->S[j]))))
1445        {
1446          pNorm(strat->S[j]);
1447          //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
1448        }
1449#ifdef HAVE_RINGS
1450      }
1451#endif
1452      nNormalize(pGetCoeff(P.p));
1453#ifdef KDEBUG
1454      if (TEST_OPT_DEBUG)
1455      {
1456        PrintS("red:");
1457        wrp(h);
1458        PrintS(" with ");
1459        wrp(strat->S[j]);
1460      }
1461#endif
1462#ifdef HAVE_PLURAL
1463      if (rIsPluralRing(currRing))
1464      {
1465        number coef;
1466        nc_kBucketPolyRed(P.bucket,strat->S[j],&coef);
1467        nDelete(&coef);
1468      }
1469      else
1470#endif
1471      {
1472        number coef;
1473        coef=kBucketPolyRed(P.bucket,strat->S[j],pLength(strat->S[j]),strat->kNoether);
1474        nDelete(&coef);
1475      }
1476      h = kBucketGetLm(P.bucket);   // FRAGE OLIVER
1477      if (h==NULL)
1478      {
1479        kBucketDestroy(&P.bucket);
1480
1481#ifdef KDEBUG
1482//        if (TEST_OPT_DEBUG)
1483//        {
1484//          PrintS("redNF: starting S:\n");
1485//          for( j = 0; j <= max_ind; j++ )
1486//          {
1487//            Print("S[%d] (of size: %d): ", j, pSize(strat->S[j]));
1488//            pWrite(strat->S[j]);
1489//          }
1490//        };
1491#endif
1492
1493        return NULL;
1494      }
1495      kbTest(P.bucket);
1496      P.p=h;
1497      P.t_p=NULL;
1498      P.SetShortExpVector();
1499#ifdef KDEBUG
1500      if (TEST_OPT_DEBUG)
1501      {
1502        PrintS("\nto:");
1503        wrp(h);
1504        PrintLn();
1505      }
1506#endif
1507    }
1508    else
1509    {
1510      P.p=kBucketClear(P.bucket);
1511      kBucketDestroy(&P.bucket);
1512      pNormalize(P.p);
1513
1514#ifdef KDEBUG
1515//      if (TEST_OPT_DEBUG)
1516//      {
1517//        PrintS("redNF: starting S:\n");
1518//        for( j = 0; j <= max_ind; j++ )
1519//        {
1520//          Print("S[%d] (of size: %d): ", j, pSize(strat->S[j]));
1521//          pWrite(strat->S[j]);
1522//        }
1523//      };
1524#endif
1525
1526      return P.p;
1527    }
1528  }
1529}
1530
1531void kDebugPrint(kStrategy strat);
1532
1533ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
1534{
1535  int   red_result = 1;
1536  int   olddeg,reduc;
1537  int hilbeledeg=1,hilbcount=0,minimcnt=0;
1538  BOOLEAN withT = FALSE;
1539  BITSET save;
1540  SI_SAVE_OPT1(save);
1541
1542  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
1543  initBuchMoraPos(strat);
1544  initHilbCrit(F,Q,&hilb,strat);
1545  initBba(strat);
1546  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
1547  /*Shdl=*/initBuchMora(F, Q,strat);
1548  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
1549  reduc = olddeg = 0;
1550
1551#ifndef NO_BUCKETS
1552  if (!TEST_OPT_NOT_BUCKETS)
1553    strat->use_buckets = 1;
1554#endif
1555  // redtailBBa against T for inhomogenous input
1556  if (!TEST_OPT_OLDSTD)
1557    withT = ! strat->homog;
1558
1559  // strat->posInT = posInT_pLength;
1560  kTest_TS(strat);
1561
1562#ifdef HAVE_TAIL_RING
1563  if(!idIs0(F) &&(!rField_is_Ring(currRing)))  // create strong gcd poly computes with tailring and S[i] ->to be fixed
1564    kStratInitChangeTailRing(strat);
1565#endif
1566  if (BVERBOSE(23))
1567  {
1568    if (test_PosInT!=NULL) strat->posInT=test_PosInT;
1569    if (test_PosInL!=NULL) strat->posInL=test_PosInL;
1570    kDebugPrint(strat);
1571  }
1572
1573
1574#ifdef KDEBUG
1575  //kDebugPrint(strat);
1576#endif
1577  /* compute------------------------------------------------------- */
1578  while (strat->Ll >= 0)
1579  {
1580    #if ADIDEBUG
1581    printf("\n      ------------------------NEW LOOP\n");
1582    printf("\nShdl = \n");
1583    #if 0
1584    idPrint(strat->Shdl);
1585    #else
1586    for(int ii = 0; ii<=strat->sl;ii++)
1587        p_Write(strat->S[ii],strat->tailRing);
1588    #endif
1589    printf("\n   list   L\n");
1590    int iii;
1591    #if 1
1592    for(iii = 0; iii<= strat->Ll; iii++)
1593    {
1594        printf("L[%i]:",iii);
1595        p_Write(strat->L[iii].p, currRing);
1596        p_Write(strat->L[iii].p1, currRing);
1597        p_Write(strat->L[iii].p2, currRing);
1598    }
1599    #else
1600    {
1601        printf("L[%i]:",strat->Ll);
1602        p_Write(strat->L[strat->Ll].p, strat->tailRing);
1603        p_Write(strat->L[strat->Ll].p1, strat->tailRing);
1604        p_Write(strat->L[strat->Ll].p2, strat->tailRing);
1605    }
1606    #endif
1607    #if 1
1608    for(iii = 0; iii<= strat->Bl; iii++)
1609    {
1610        printf("B[%i]:",iii);
1611        p_Write(strat->B[iii].p, /*strat->tailRing*/currRing);
1612        p_Write(strat->B[iii].p1, /*strat->tailRing*/currRing);
1613        p_Write(strat->B[iii].p2, strat->tailRing);
1614    }
1615    #endif
1616    //getchar();
1617    #endif
1618    #ifdef KDEBUG
1619      if (TEST_OPT_DEBUG) messageSets(strat);
1620    #endif
1621    if (strat->Ll== 0) strat->interpt=TRUE;
1622    if (TEST_OPT_DEGBOUND
1623        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
1624            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
1625    {
1626      /*
1627       *stops computation if
1628       * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
1629       *a predefined number Kstd1_deg
1630       */
1631      while ((strat->Ll >= 0)
1632        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
1633        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
1634            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))
1635        )
1636        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1637      if (strat->Ll<0) break;
1638      else strat->noClearS=TRUE;
1639    }
1640    /* picks the last element from the lazyset L */
1641    strat->P = strat->L[strat->Ll];
1642    strat->Ll--;
1643
1644    if (pNext(strat->P.p) == strat->tail)
1645    {
1646      // deletes the short spoly
1647      if (rField_is_Ring(currRing))
1648        pLmDelete(strat->P.p);
1649      else
1650        pLmFree(strat->P.p);
1651      strat->P.p = NULL;
1652      poly m1 = NULL, m2 = NULL;
1653
1654      // check that spoly creation is ok
1655      while (strat->tailRing != currRing &&
1656             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
1657      {
1658        assume(m1 == NULL && m2 == NULL);
1659        // if not, change to a ring where exponents are at least
1660        // large enough
1661        if (!kStratChangeTailRing(strat))
1662        {
1663          WerrorS("OVERFLOW...");
1664          break;
1665        }
1666      }
1667      // create the real one
1668      ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
1669                    strat->tailRing, m1, m2, strat->R);
1670    }
1671    else if (strat->P.p1 == NULL)
1672    {
1673      if (strat->minim > 0)
1674        strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
1675      // for input polys, prepare reduction
1676      strat->P.PrepareRed(strat->use_buckets);
1677    }
1678
1679    if (strat->P.p == NULL && strat->P.t_p == NULL)
1680    {
1681      red_result = 0;
1682    }
1683    else
1684    {
1685      if (TEST_OPT_PROT)
1686        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
1687                &olddeg,&reduc,strat, red_result);
1688
1689      /* reduction of the element chosen from L */
1690      red_result = strat->red(&strat->P,strat);
1691      if (errorreported)  break;
1692    }
1693
1694    if (strat->overflow)
1695    {
1696      if (!kStratChangeTailRing(strat)) { Werror("OVERFLOW.."); break;}
1697    }
1698
1699    // reduction to non-zero new poly
1700    if (red_result == 1)
1701    {
1702      // get the polynomial (canonicalize bucket, make sure P.p is set)
1703      strat->P.GetP(strat->lmBin);
1704      // in the homogeneous case FDeg >= pFDeg (sugar/honey)
1705      // but now, for entering S, T, we reset it
1706      // in the inhomogeneous case: FDeg == pFDeg
1707      if (strat->homog) strat->initEcart(&(strat->P));
1708
1709      /* statistic */
1710      if (TEST_OPT_PROT) PrintS("s");
1711
1712      int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
1713
1714      // reduce the tail and normalize poly
1715      // in the ring case we cannot expect LC(f) = 1,
1716      // therefore we call pContent instead of pNorm
1717      if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing)))
1718      {
1719        strat->P.pCleardenom();
1720        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
1721        {
1722          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
1723          strat->P.pCleardenom();
1724        }
1725      }
1726      else
1727      {
1728        strat->P.pNorm();
1729        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
1730          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
1731      }
1732
1733#ifdef KDEBUG
1734      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
1735#endif /* KDEBUG */
1736
1737      // min_std stuff
1738      if ((strat->P.p1==NULL) && (strat->minim>0))
1739      {
1740        if (strat->minim==1)
1741        {
1742          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
1743          p_Delete(&strat->P.p2, currRing, strat->tailRing);
1744        }
1745        else
1746        {
1747          strat->M->m[minimcnt]=strat->P.p2;
1748          strat->P.p2=NULL;
1749        }
1750        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
1751          pNext(strat->M->m[minimcnt])
1752            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
1753                                           strat->tailRing, currRing,
1754                                           currRing->PolyBin);
1755        minimcnt++;
1756      }
1757
1758      // enter into S, L, and T
1759      if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
1760      {
1761        enterT(strat->P, strat);
1762        if (rField_is_Ring(currRing))
1763          superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
1764        else
1765          enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
1766        // posInS only depends on the leading term
1767        strat->enterS(strat->P, pos, strat, strat->tl);
1768#if 0
1769        int pl=pLength(strat->P.p);
1770        if (pl==1)
1771        {
1772          //if (TEST_OPT_PROT)
1773          //PrintS("<1>");
1774        }
1775        else if (pl==2)
1776        {
1777          //if (TEST_OPT_PROT)
1778          //PrintS("<2>");
1779        }
1780#endif
1781      }
1782      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1783//      Print("[%d]",hilbeledeg);
1784      if (strat->P.lcm!=NULL)
1785      {
1786        if (rField_is_Ring(currRing)) pLmDelete(strat->P.lcm);
1787        else                          pLmFree(strat->P.lcm);
1788        strat->P.lcm=NULL;
1789      }
1790      if (strat->s_poly!=NULL)
1791      {
1792        // the only valid entries are: strat->P.p,
1793        // strat->tailRing (read-only, keep it)
1794        // (and P->p1, P->p2 (read-only, must set to NULL if P.p is changed)
1795        if (strat->s_poly(strat))
1796        {
1797          // we are called AFTER enterS, i.e. if we change P
1798          // we have to add it also to S/T
1799          // and add pairs
1800          int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
1801          enterT(strat->P, strat);
1802          if (rField_is_Ring(currRing))
1803            superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
1804          else
1805            enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
1806          strat->enterS(strat->P, pos, strat, strat->tl);
1807        }
1808      }
1809    }
1810    else if (strat->P.p1 == NULL && strat->minim > 0)
1811    {
1812      p_Delete(&strat->P.p2, currRing, strat->tailRing);
1813    }
1814
1815#ifdef KDEBUG
1816    memset(&(strat->P), 0, sizeof(strat->P));
1817#endif /* KDEBUG */
1818    kTest_TS(strat);
1819  }
1820#ifdef KDEBUG
1821  if (TEST_OPT_DEBUG) messageSets(strat);
1822#endif /* KDEBUG */
1823
1824  if (TEST_OPT_SB_1)
1825  {
1826    if(!rField_is_Ring(currRing))
1827    {
1828      int k=1;
1829      int j;
1830      while(k<=strat->sl)
1831      {
1832        j=0;
1833        loop
1834        {
1835          if (j>=k) break;
1836          clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
1837          j++;
1838        }
1839        k++;
1840      }
1841    }
1842  }
1843  /* complete reduction of the standard basis--------- */
1844  if (TEST_OPT_REDSB)
1845  {
1846    completeReduce(strat);
1847#ifdef HAVE_TAIL_RING
1848    if (strat->completeReduce_retry)
1849    {
1850      // completeReduce needed larger exponents, retry
1851      // to reduce with S (instead of T)
1852      // and in currRing (instead of strat->tailRing)
1853      cleanT(strat);strat->tailRing=currRing;
1854      int i;
1855      for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
1856      completeReduce(strat);
1857    }
1858#endif
1859  }
1860  else if (TEST_OPT_PROT) PrintLn();
1861  if(nCoeff_is_Ring_Z(currRing->cf))
1862    finalReduceByMon(strat);
1863  if(rField_is_Ring(currRing))
1864  {
1865    for(int i = 0;i<=strat->sl;i++)
1866    {
1867      if(!nGreaterZero(pGetCoeff(strat->S[i])))
1868      {
1869        strat->S[i] = pNeg(strat->S[i]);
1870      }
1871    }
1872  }
1873  /* release temp data-------------------------------- */
1874  exitBuchMora(strat);
1875//  if (TEST_OPT_WEIGHTM)
1876//  {
1877//    pRestoreDegProcs(currRing,pFDegOld, pLDegOld);
1878//    if (ecartWeights)
1879//    {
1880//      omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
1881//      ecartWeights=NULL;
1882//    }
1883//  }
1884  if ((TEST_OPT_PROT) || (TEST_OPT_DEBUG)) messageStat(hilbcount,strat);
1885  SI_RESTORE_OPT1(save);
1886  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1887
1888  idTest(strat->Shdl);
1889
1890  return (strat->Shdl);
1891}
1892ideal sba (ideal F0, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
1893{
1894  // ring order stuff:
1895  // in sba we have (until now) two possibilities:
1896  // 1. an incremental computation w.r.t. (C,monomial order)
1897  // 2. a (possibly non-incremental) computation w.r.t. the
1898  //    induced Schreyer order.
1899  // The corresponding orders are computed in sbaRing(), depending
1900  // on the flag strat->sbaOrder
1901#if SBA_PRINT_ZERO_REDUCTIONS
1902  long zeroreductions           = 0;
1903#endif
1904#if SBA_PRINT_PRODUCT_CRITERION
1905  long product_criterion        = 0;
1906#endif
1907#if SBA_PRINT_SIZE_G
1908  int size_g                    = 0;
1909  int size_g_non_red            = 0;
1910#endif
1911#if SBA_PRINT_SIZE_SYZ
1912  long size_syz                 = 0;
1913#endif
1914  // global variable
1915#if SBA_PRINT_REDUCTION_STEPS
1916  sba_reduction_steps           = 0;
1917  sba_interreduction_steps      = 0;
1918#endif
1919#if SBA_PRINT_OPERATIONS
1920  sba_operations                = 0;
1921  sba_interreduction_operations = 0;
1922#endif
1923 
1924  ideal F1 = F0;
1925  ring sRing, currRingOld;
1926  currRingOld  = currRing;
1927  if (strat->sbaOrder == 1 || strat->sbaOrder == 3)
1928  {
1929    sRing = sbaRing(strat);
1930    if (sRing!=currRingOld)
1931    {
1932      rChangeCurrRing (sRing);
1933      F1 = idrMoveR (F0, currRingOld, currRing);
1934    }
1935  }
1936  // sort ideal F
1937  ideal F       = idInit(IDELEMS(F1),F1->rank);
1938  #if REV_BLOCK_SBA || SIG_DROP_FIRST
1939  //#ifdef HAVE_RINGS
1940  if(rField_is_Ring(currRing) && strat->sigdrop)
1941  {
1942    #if REV_BLOCK_SBA
1943    for (int i=0; i<IDELEMS(F1);++i)
1944      F->m[i] = F1->m[i];
1945    #else
1946    //Now I put the element on pos 0 already with enterS
1947    #if 0
1948    for (int i=IDELEMS(F1)-1; i>0;i--)
1949      F->m[i] = F1->m[i-1];
1950    F->m[0] = F1->m[IDELEMS(F1)-1];
1951    #else
1952    for (int i=0; i<IDELEMS(F1);++i)
1953      F->m[i] = F1->m[i];
1954    //Put the SigDrop element on the correct position (think of sbaEnterS)
1955    if(strat->sbaEnterS >= 0)
1956    {
1957      poly dummy;
1958      dummy = pCopy(F->m[0]); //the sigdrop element
1959      for(int i = 0;i<strat->sbaEnterS;i++)
1960        F->m[i] = F->m[i+1];
1961      F->m[strat->sbaEnterS] = dummy;
1962    }
1963    #endif
1964    #endif
1965  }
1966  else
1967  #endif
1968  {
1969    intvec *sort  = idSort(F1);
1970    for (int i=0; i<sort->length();++i)
1971      F->m[i] = F1->m[(*sort)[i]-1];
1972  }
1973  #ifdef HAVE_RINGS
1974  if(rField_is_Ring(currRing))
1975    strat->sigdrop = FALSE;
1976  strat->nrsyzcrit = 0;
1977  #endif
1978#if SBA_INTERRED_START
1979  F = kInterRed(F,NULL);
1980#endif
1981#if F5DEBUG
1982  printf("SBA COMPUTATIONS DONE IN THE FOLLOWING RING:\n");
1983  rWrite (currRing);
1984  printf("ordSgn = %d\n",currRing->OrdSgn);
1985  printf("\n");
1986#endif
1987  int   srmax,lrmax, red_result = 1;
1988  int   olddeg,reduc;
1989  int hilbeledeg=1,hilbcount=0,minimcnt=0;
1990  LObject L;
1991  BOOLEAN withT     = TRUE;
1992  strat->max_lower_index = 0;
1993  //initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
1994  initSbaCrit(strat); /*set Gebauer, honey, sugarCrit*/
1995  initSbaPos(strat);
1996  //initBuchMoraPos(strat);
1997  initHilbCrit(F,Q,&hilb,strat);
1998  initSba(F,strat);
1999  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
2000  /*Shdl=*/initSbaBuchMora(F, Q,strat);
2001  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
2002  srmax = strat->sl;
2003  reduc = olddeg = lrmax = 0;
2004#ifndef NO_BUCKETS
2005  if (!TEST_OPT_NOT_BUCKETS)
2006    strat->use_buckets = 1;
2007#endif
2008
2009  // redtailBBa against T for inhomogenous input
2010  // if (!TEST_OPT_OLDSTD)
2011  //   withT = ! strat->homog;
2012
2013  // strat->posInT = posInT_pLength;
2014  kTest_TS(strat);
2015
2016#ifdef HAVE_TAIL_RING
2017  if(!idIs0(F) &&(!rField_is_Ring(currRing)))  // create strong gcd poly computes with tailring and S[i] ->to be fixed
2018    kStratInitChangeTailRing(strat);
2019#endif
2020  if (BVERBOSE(23))
2021  {
2022    if (test_PosInT!=NULL) strat->posInT=test_PosInT;
2023    if (test_PosInL!=NULL) strat->posInL=test_PosInL;
2024    kDebugPrint(strat);
2025  }
2026
2027  #if 1
2028  if(rField_is_Ring(currRing) && strat->sbaEnterS >= 0)
2029  {
2030    for(int i = 0;i<strat->sbaEnterS;i++)
2031    {
2032      //Update: now the element is at the corect place
2033      //i+1 because on the 0 position is the sigdrop element
2034      enterT(strat->L[strat->Ll-(i)],strat);
2035      strat->enterS(strat->L[strat->Ll-(i)], strat->sl+1, strat, strat->tl);
2036    }
2037    strat->Ll = strat->Ll - strat->sbaEnterS; 
2038    strat->sbaEnterS = -1;
2039  }
2040  #endif
2041  kTest_TS(strat);
2042#ifdef KDEBUG
2043  //kDebugPrint(strat);
2044#endif
2045  /* compute------------------------------------------------------- */
2046  while (strat->Ll >= 0)
2047  {
2048    #if ADIDEBUG
2049    printf("\n      ------------------------NEW LOOP\n");
2050    printf("\nShdl = \n");
2051    #if 0
2052    idPrint(strat->Shdl);
2053    #else
2054    for(int ii = 0; ii<=strat->sl;ii++)
2055    {
2056      printf("\nS[%i]:  ",ii);p_Write(strat->S[ii],strat->tailRing);
2057      printf("sig:   ");pWrite(strat->sig[ii]);
2058    }
2059    #endif
2060    #if 0
2061    for(int iii = 0; iii< strat->syzl; iii++)
2062    {
2063        printf("\nsyz[%i]:\n",iii);
2064        p_Write(strat->syz[iii], currRing);
2065    }
2066    #endif
2067    #if 0
2068    for(int iii = 0; iii<= strat->tl; iii++)
2069    {
2070        printf("\nT[%i]:\n",iii);
2071        p_Write(strat->T[iii].p, currRing);
2072    }
2073    #endif
2074    printf("\n   list   L\n");
2075    int iii;
2076    #if 1
2077    for(iii = 0; iii<= strat->Ll; iii++)
2078    {
2079        printf("\nL[%i]:\n",iii);
2080        p_Write(strat->L[iii].p, currRing);
2081        p_Write(strat->L[iii].p1, currRing);
2082        p_Write(strat->L[iii].p2, currRing);
2083        p_Write(strat->L[iii].sig, currRing);
2084    }
2085    #else
2086    {
2087        printf("L[%i]:",strat->Ll);
2088        p_Write(strat->L[strat->Ll].p, strat->tailRing);
2089        p_Write(strat->L[strat->Ll].p1, strat->tailRing);
2090        p_Write(strat->L[strat->Ll].p2, strat->tailRing);
2091        p_Write(strat->L[strat->Ll].sig, strat->tailRing);
2092    }
2093    #endif
2094    //getchar();
2095    #endif
2096    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
2097    #ifdef KDEBUG
2098      if (TEST_OPT_DEBUG) messageSets(strat);
2099    #endif
2100    if (strat->Ll== 0) strat->interpt=TRUE;
2101    /*
2102    if (TEST_OPT_DEGBOUND
2103        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
2104            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
2105    {
2106
2107       //stops computation if
2108       // 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
2109       //a predefined number Kstd1_deg
2110      while ((strat->Ll >= 0)
2111        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
2112        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
2113            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))
2114        )
2115        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
2116      if (strat->Ll<0) break;
2117      else strat->noClearS=TRUE;
2118    }
2119    */
2120    if (strat->sbaOrder == 1 && pGetComp(strat->L[strat->Ll].sig) != strat->currIdx)
2121    {
2122      strat->currIdx  = pGetComp(strat->L[strat->Ll].sig);
2123#if F5C
2124      // 1. interreduction of the current standard basis
2125      // 2. generation of new principal syzygy rules for syzCriterion
2126      f5c ( strat, olddeg, minimcnt, hilbeledeg, hilbcount, srmax,
2127          lrmax, reduc, Q, w, hilb );
2128#endif
2129      // initialize new syzygy rules for the next iteration step
2130      initSyzRules(strat);
2131    }
2132    /*********************************************************************
2133      * interrreduction step is done, we can go on with the next iteration
2134      * step of the signature-based algorithm
2135      ********************************************************************/
2136    /* picks the last element from the lazyset L */
2137    strat->P = strat->L[strat->Ll];
2138    strat->Ll--;
2139   
2140    #ifdef HAVE_RINGS
2141    if(rField_is_Ring(currRing))
2142      strat->sbaEnterS = pGetComp(strat->P.sig) - 1;
2143    #endif
2144   
2145    #if ADIDEBUG
2146    printf("\n-------------------------\nThis is the current element P\n");
2147    pWrite(strat->P.p);
2148    pWrite(strat->P.p1);
2149    pWrite(strat->P.p2);
2150    pWrite(strat->P.sig);
2151    #endif
2152    /* reduction of the element chosen from L */
2153    // We do not delete via RewCrit strong pairs or extended spolys over rings
2154    // these should have .lcm = NULL
2155    if (strat->P.lcm == NULL || !strat->rewCrit2(strat->P.sig, ~strat->P.sevSig, strat->P.GetLmCurrRing(), strat, strat->P.checked+1)) {
2156      //#if 1
2157#ifdef DEBUGF5
2158      Print("SIG OF NEXT PAIR TO HANDLE IN SIG-BASED ALGORITHM\n");
2159      Print("-------------------------------------------------\n");
2160      pWrite(strat->P.sig);
2161      pWrite(pHead(strat->P.p));
2162      pWrite(pHead(strat->P.p1));
2163      pWrite(pHead(strat->P.p2));
2164      Print("-------------------------------------------------\n");
2165#endif
2166      if (pNext(strat->P.p) == strat->tail)
2167      {
2168        // deletes the short spoly
2169        /*
2170        if (rField_is_Ring(currRing))
2171          pLmDelete(strat->P.p);
2172        else
2173          pLmFree(strat->P.p);
2174*/
2175          // TODO: needs some masking
2176          // TODO: masking needs to vanish once the signature
2177          //       sutff is completely implemented
2178          strat->P.p = NULL;
2179        poly m1 = NULL, m2 = NULL;
2180
2181        // check that spoly creation is ok
2182        while (strat->tailRing != currRing &&
2183            !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
2184        {
2185          assume(m1 == NULL && m2 == NULL);
2186          // if not, change to a ring where exponents are at least
2187          // large enough
2188          if (!kStratChangeTailRing(strat))
2189          {
2190            WerrorS("OVERFLOW...");
2191            break;
2192          }
2193        }
2194        // create the real one
2195        ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
2196            strat->tailRing, m1, m2, strat->R);
2197
2198      }
2199      else if (strat->P.p1 == NULL)
2200      {
2201        if (strat->minim > 0)
2202          strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
2203        // for input polys, prepare reduction
2204        strat->P.PrepareRed(strat->use_buckets);
2205      }
2206      if (strat->P.p == NULL && strat->P.t_p == NULL)
2207      {
2208        red_result = 0;
2209      }
2210      else
2211      {
2212        //#if 1
2213#ifdef DEBUGF5
2214        Print("Poly before red: ");
2215        pWrite(pHead(strat->P.p));
2216        pWrite(strat->P.sig);
2217#endif
2218#if SBA_PRODUCT_CRITERION
2219        if (strat->P.prod_crit) {
2220#if SBA_PRINT_PRODUCT_CRITERION
2221          product_criterion++;
2222#endif
2223          int pos = posInSyz(strat, strat->P.sig);
2224          enterSyz(strat->P, strat, pos);
2225          if (strat->P.lcm!=NULL)
2226            pLmFree(strat->P.lcm);
2227          red_result = 2;
2228        } else {
2229          red_result = strat->red(&strat->P,strat);
2230        }
2231#else
2232        red_result = strat->red(&strat->P,strat);
2233#endif
2234      }
2235    } else {
2236      /*
2237      if (strat->P.lcm != NULL)
2238        pLmFree(strat->P.lcm);
2239        */
2240      red_result = 2;
2241    }
2242    #ifdef HAVE_RINGS
2243    if(rField_is_Ring(currRing))
2244    {
2245      strat->P.pLength = pLength(strat->P.p);
2246      if(strat->P.sig != NULL)
2247        strat->P.sevSig = pGetShortExpVector(strat->P.sig);
2248      if(strat->P.p != NULL)
2249        strat->P.sev = pGetShortExpVector(strat->P.p);
2250    }
2251    #endif
2252    #if ADIDEBUG
2253    printf("\nAfter reduce (redresult=%i): \n",red_result);pWrite(strat->P.p);pWrite(strat->P.sig);
2254    #endif
2255    #ifdef HAVE_RINGS
2256    //sigdrop case
2257    if(rField_is_Ring(currRing) && strat->sigdrop)
2258    {
2259      //First reduce it as much as one can
2260      #if ADIDEBUG
2261      printf("\nSigdrop in the reduce. Trying redring\n");
2262      #endif
2263      red_result = redRing(&strat->P,strat);
2264      if(red_result == 0)
2265      {
2266        #if ADIDEBUG
2267        printf("\nSigdrop cancelled since redRing reduced to 0\n");
2268        #endif
2269        strat->sigdrop = FALSE;
2270      }
2271      else
2272      {
2273        #if ADIDEBUG
2274        printf("\nStill Sigdrop - redRing reduced to:\n");pWrite(strat->P.p);
2275        #endif
2276        strat->enterS(strat->P, 0, strat, strat->tl);
2277        break;
2278      }
2279    }
2280    #endif
2281   
2282    if (errorreported)  break;
2283
2284//#if 1
2285#ifdef DEBUGF5
2286    if (red_result != 0) {
2287        Print("Poly after red: ");
2288        pWrite(pHead(strat->P.p));
2289        pWrite(strat->P.GetLmCurrRing());
2290        pWrite(strat->P.sig);
2291        printf("%d\n",red_result);
2292    }
2293#endif
2294
2295    if (strat->overflow)
2296    {
2297        if (!kStratChangeTailRing(strat)) { Werror("OVERFLOW.."); break;}
2298    }
2299    // reduction to non-zero new poly
2300    if (red_result == 1)
2301    {
2302      // get the polynomial (canonicalize bucket, make sure P.p is set)
2303      strat->P.GetP(strat->lmBin);
2304
2305      // sig-safe computations may lead to wrong FDeg computation, thus we need
2306      // to recompute it to make sure everything is alright
2307      (strat->P).FDeg = (strat->P).pFDeg();
2308      // in the homogeneous case FDeg >= pFDeg (sugar/honey)
2309      // but now, for entering S, T, we reset it
2310      // in the inhomogeneous case: FDeg == pFDeg
2311      if (strat->homog) strat->initEcart(&(strat->P));
2312
2313      /* statistic */
2314      if (TEST_OPT_PROT) PrintS("s");
2315
2316      //int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
2317      // in F5E we know that the last reduced element is already the
2318      // the one with highest signature
2319      int pos = strat->sl+1;
2320
2321      // reduce the tail and normalize poly
2322      // in the ring case we cannot expect LC(f) = 1,
2323      // therefore we call pContent instead of pNorm
2324      #ifdef HAVE_RINGS
2325      poly beforetailred;
2326      if(rField_is_Ring(currRing))
2327        beforetailred = pCopy(strat->P.sig);
2328      #endif
2329#if SBA_TAIL_RED
2330#ifdef HAVE_RINGS
2331      if(rField_is_Ring(currRing))
2332      { 
2333        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2334          strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
2335      }
2336      else
2337#endif
2338      {
2339        if (strat->sbaOrder != 2) {
2340          if (TEST_OPT_INTSTRATEGY)
2341          {
2342            strat->P.pCleardenom();
2343            if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2344            {
2345              strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
2346              strat->P.pCleardenom();
2347            }
2348          }
2349          else
2350          {
2351            strat->P.pNorm();
2352            if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2353              strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
2354          }
2355        }
2356      }
2357      // It may happen that we have lost the sig in redtailsba
2358      // It cannot reduce to 0 since here we are doing just tail reduction.
2359      // Best case scenerio: remains the leading term
2360      #ifdef HAVE_RINGS
2361      if(rField_is_Ring(currRing) && strat->sigdrop)     
2362      {
2363        #if ADIDEBUG
2364        printf("\n Still sigdrop after redtailSba - it reduced to \n");pWrite(strat->P.p);
2365        #endif
2366        strat->enterS(strat->P, 0, strat, strat->tl);
2367        break;
2368      }
2369      #endif
2370#endif
2371    #ifdef HAVE_RINGS
2372    if(rField_is_Ring(currRing))
2373    {
2374      if(strat->P.sig == NULL || pLtCmp(beforetailred,strat->P.sig) == 1)
2375      {
2376        #if ADIDEBUG
2377        printf("\nSigDrop after TAILred\n");pWrite(beforetailred);pWrite(strat->P.sig);
2378        #endif
2379        strat->sigdrop = TRUE;
2380        //Reduce it as much as you can
2381        red_result = redRing(&strat->P,strat);
2382        if(red_result == 0)
2383        {
2384          //It reduced to 0, cancel the sigdrop
2385          #if ADIDEBUG
2386          printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
2387          #endif
2388          strat->sigdrop = FALSE;
2389          p_Delete(&strat->P.sig,currRing);strat->P.sig = NULL;
2390        }
2391        else
2392        {
2393          #if ADIDEBUG
2394          printf("\nReduced to this via redRing.SIGDROP\n");pWrite(strat->P.p);
2395          #endif
2396          strat->enterS(strat->P, 0, strat, strat->tl);
2397          break;
2398        }
2399      }
2400      p_Delete(&beforetailred,currRing);
2401      // strat->P.p = NULL may appear if we had  a sigdrop above and reduced to 0 via redRing
2402      if(strat->P.p == NULL)
2403        goto case_when_red_result_changed;
2404      if(!nGreaterZero(pGetCoeff(strat->P.p)))
2405      {
2406        strat->P.p = pNeg(strat->P.p);
2407        strat->P.sig = pNeg(strat->P.sig);
2408      }
2409    }
2410    #endif
2411    // remove sigsafe label since it is no longer valid for the next element to
2412    // be reduced
2413    if (strat->sbaOrder == 1)
2414    {
2415      for (int jj = 0; jj<strat->tl+1; jj++)
2416      {
2417        if (pGetComp(strat->T[jj].sig) == strat->currIdx)
2418        {
2419          strat->T[jj].is_sigsafe = FALSE;
2420        }
2421      }
2422    }
2423    else
2424    {
2425      for (int jj = 0; jj<strat->tl+1; jj++)
2426      {
2427        strat->T[jj].is_sigsafe = FALSE;
2428      }
2429    }
2430#ifdef KDEBUG
2431      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
2432#endif /* KDEBUG */
2433
2434      // min_std stuff
2435      if ((strat->P.p1==NULL) && (strat->minim>0))
2436      {
2437        if (strat->minim==1)
2438        {
2439          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
2440          p_Delete(&strat->P.p2, currRing, strat->tailRing);
2441        }
2442        else
2443        {
2444          strat->M->m[minimcnt]=strat->P.p2;
2445          strat->P.p2=NULL;
2446        }
2447        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
2448          pNext(strat->M->m[minimcnt])
2449            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
2450                                           strat->tailRing, currRing,
2451                                           currRing->PolyBin);
2452        minimcnt++;
2453      }
2454
2455      // enter into S, L, and T
2456      //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
2457      enterT(strat->P, strat);
2458      strat->T[strat->tl].is_sigsafe = FALSE;
2459      /*
2460      printf("hier\n");
2461      pWrite(strat->P.GetLmCurrRing());
2462      pWrite(strat->P.sig);
2463      */
2464      if (rField_is_Ring(currRing))
2465        superenterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
2466      else
2467        enterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
2468      #if ADIDEBUG
2469        printf("\nThis element is added to S\n");
2470        p_Write(strat->P.p, strat->tailRing);p_Write(strat->P.p1, strat->tailRing);p_Write(strat->P.p2, strat->tailRing);pWrite(strat->P.sig);
2471        #endif
2472      // posInS only depends on the leading term
2473     
2474      #ifdef HAVE_RINGS
2475      if(rField_is_Ring(currRing) && strat->sigdrop)
2476        break;
2477      #endif
2478      strat->P.sevSig = p_GetShortExpVector(strat->P.sig,currRing);
2479      strat->enterS(strat->P, pos, strat, strat->tl);
2480     
2481      if(strat->sbaOrder != 1)
2482      {
2483        BOOLEAN overwrite = FALSE;
2484        for (int tk=0; tk<strat->sl+1; tk++)
2485        {
2486          if (pGetComp(strat->sig[tk]) == pGetComp(strat->P.sig))
2487          {
2488            //printf("TK %d / %d\n",tk,strat->sl);
2489            overwrite = FALSE;
2490            break;
2491          }
2492        }
2493        //printf("OVERWRITE %d\n",overwrite);
2494        if (overwrite)
2495        {
2496          int cmp = pGetComp(strat->P.sig);
2497          int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int));
2498          pGetExpV (strat->P.p,vv);
2499          pSetExpV (strat->P.sig, vv);
2500          pSetComp (strat->P.sig,cmp);
2501
2502          strat->P.sevSig = pGetShortExpVector (strat->P.sig);
2503          int i;
2504          LObject Q;
2505          for(int ps=0;ps<strat->sl+1;ps++)
2506          {
2507
2508            strat->newt = TRUE;
2509            if (strat->syzl == strat->syzmax)
2510            {
2511              pEnlargeSet(&strat->syz,strat->syzmax,setmaxTinc);
2512              strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
2513                  (strat->syzmax)*sizeof(unsigned long),
2514                  ((strat->syzmax)+setmaxTinc)
2515                  *sizeof(unsigned long));
2516              strat->syzmax += setmaxTinc;
2517            }
2518            Q.sig = pCopy(strat->P.sig);
2519            // add LM(F->m[i]) to the signature to get a Schreyer order
2520            // without changing the underlying polynomial ring at all
2521            if (strat->sbaOrder == 0)
2522              p_ExpVectorAdd (Q.sig,strat->S[ps],currRing);
2523            // since p_Add_q() destroys all input
2524            // data we need to recreate help
2525            // each time
2526            // ----------------------------------------------------------
2527            // in the Schreyer order we always know that the multiplied
2528            // module monomial strat->P.sig gives the leading monomial of
2529            // the corresponding principal syzygy
2530            // => we do not need to compute the "real" syzygy completely
2531            poly help = p_Copy(strat->sig[ps],currRing);
2532            p_ExpVectorAdd (help,strat->P.p,currRing);
2533            Q.sig = p_Add_q(Q.sig,help,currRing);
2534            //printf("%d. SYZ  ",i+1);
2535            //pWrite(strat->syz[i]);
2536            Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
2537            i = posInSyz(strat, Q.sig);
2538            enterSyz(Q, strat, i);
2539          }
2540        }
2541      }
2542      // deg - idx - lp/rp
2543      // => we need to add syzygies with indices > pGetComp(strat->P.sig)
2544      if(strat->sbaOrder == 0 || strat->sbaOrder == 3)
2545      {
2546        int cmp     = pGetComp(strat->P.sig);
2547        int max_cmp = IDELEMS(F);
2548        int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int));
2549        pGetExpV (strat->P.p,vv);
2550        LObject Q;
2551        int pos;
2552        int idx = p_GetComp(strat->P.sig,currRing);
2553        //printf("++ -- adding syzygies -- ++\n");
2554        // if new element is the first one in this index
2555        if (strat->currIdx < idx) {
2556          for (int i=0; i<strat->sl; ++i) {
2557            Q.sig = p_Copy(strat->P.sig,currRing);
2558            p_ExpVectorAdd(Q.sig,strat->S[i],currRing);
2559            poly help = p_Copy(strat->sig[i],currRing);
2560            p_ExpVectorAdd(help,strat->P.p,currRing);
2561            Q.sig = p_Add_q(Q.sig,help,currRing);
2562            //pWrite(Q.sig);
2563            pos = posInSyz(strat, Q.sig);
2564            enterSyz(Q, strat, pos);
2565          }
2566          strat->currIdx = idx;
2567        } else {
2568          // if the element is not the first one in the given index we build all
2569          // possible syzygies with elements of higher index
2570          for (int i=cmp+1; i<=max_cmp; ++i) {
2571            pos = -1;
2572            for (int j=0; j<strat->sl; ++j) {
2573              if (p_GetComp(strat->sig[j],currRing) == i) {
2574                pos = j;
2575                break;
2576              }
2577            }
2578            if (pos != -1) {
2579              Q.sig = p_One(currRing);
2580              p_SetExpV(Q.sig, vv, currRing);
2581              // F->m[i-1] corresponds to index i
2582              p_ExpVectorAdd(Q.sig,F->m[i-1],currRing);
2583              p_SetComp(Q.sig, i, currRing);
2584              poly help = p_Copy(strat->P.sig,currRing);
2585              p_ExpVectorAdd(help,strat->S[pos],currRing);
2586              Q.sig = p_Add_q(Q.sig,help,currRing);
2587              if (strat->sbaOrder == 0) {
2588                if (p_LmCmp(Q.sig,strat->syz[strat->syzl-1],currRing) == -currRing->OrdSgn) {
2589                  pos = posInSyz(strat, Q.sig);
2590                  enterSyz(Q, strat, pos);
2591                }
2592              } else {
2593                pos = posInSyz(strat, Q.sig);
2594                enterSyz(Q, strat, pos);
2595              }
2596            }
2597          }
2598          //printf("++ -- done adding syzygies -- ++\n");
2599        }
2600      }
2601//#if 1
2602#if DEBUGF50
2603    printf("---------------------------\n");
2604    Print(" %d. ELEMENT ADDED TO GCURR:\n",strat->sl+1);
2605    Print("LEAD POLY:  "); pWrite(pHead(strat->S[strat->sl]));
2606    Print("SIGNATURE:  "); pWrite(strat->sig[strat->sl]);
2607#endif
2608      /*
2609      if (newrules)
2610      {
2611        newrules  = FALSE;
2612      }
2613      */
2614#if 0
2615      int pl=pLength(strat->P.p);
2616      if (pl==1)
2617      {
2618        //if (TEST_OPT_PROT)
2619        //PrintS("<1>");
2620      }
2621      else if (pl==2)
2622      {
2623        //if (TEST_OPT_PROT)
2624        //PrintS("<2>");
2625      }
2626#endif
2627      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
2628//      Print("[%d]",hilbeledeg);
2629      if (strat->P.lcm!=NULL)
2630#ifdef HAVE_RINGS
2631        pLmDelete(strat->P.lcm);
2632#else
2633        pLmFree(strat->P.lcm);
2634#endif
2635      if (strat->sl>srmax) srmax = strat->sl;
2636    }
2637    else
2638    {
2639      case_when_red_result_changed:
2640      // adds signature of the zero reduction to
2641      // strat->syz. This is the leading term of
2642      // syzygy and can be used in syzCriterion()
2643      // the signature is added if and only if the
2644      // pair was not detected by the rewritten criterion in strat->red = redSig
2645      if (red_result!=2) {
2646#if SBA_PRINT_ZERO_REDUCTIONS
2647        zeroreductions++;
2648#endif
2649        #ifdef HAVE_RINGS
2650        if(rField_is_Ring(currRing) && strat->P.p == NULL && strat->P.sig == NULL)
2651        {
2652          //Catch the case when p = 0, sig = 0
2653        }
2654        else
2655        #endif
2656        {
2657          int pos = posInSyz(strat, strat->P.sig);
2658          enterSyz(strat->P, strat, pos);
2659  //#if 1
2660  #ifdef DEBUGF5
2661          Print("ADDING STUFF TO SYZ :  ");
2662          //pWrite(strat->P.p);
2663          pWrite(strat->P.sig);
2664  #endif
2665        }
2666      }
2667      if (strat->P.p1 == NULL && strat->minim > 0)
2668      {
2669        p_Delete(&strat->P.p2, currRing, strat->tailRing);
2670      }
2671    }
2672
2673#ifdef KDEBUG
2674    memset(&(strat->P), 0, sizeof(strat->P));
2675#endif /* KDEBUG */
2676    kTest_TS(strat);
2677  }
2678  #if 0
2679  if(strat->sigdrop)
2680    printf("\nSigDrop!\n");
2681  else
2682    printf("\nEnded with no SigDrop\n");
2683  #endif
2684// Clean strat->P for the next sba call
2685#ifdef HAVE_RINGS
2686  if(rField_is_Ring(currRing) && strat->sigdrop)
2687  {
2688    //This is used to know how many elements can we directly add to S in the next run
2689    if(strat->P.sig != NULL)
2690      strat->sbaEnterS = pGetComp(strat->P.sig)-1;
2691    //else we already set it at the beggining of the loop
2692    #ifdef KDEBUG
2693    memset(&(strat->P), 0, sizeof(strat->P));
2694    #endif /* KDEBUG */
2695  }
2696#endif
2697#ifdef KDEBUG
2698  if (TEST_OPT_DEBUG) messageSets(strat);
2699#endif /* KDEBUG */
2700
2701  if (TEST_OPT_SB_1)
2702  {
2703    if(!rField_is_Ring(currRing))
2704    {
2705      int k=1;
2706      int j;
2707      while(k<=strat->sl)
2708      {
2709        j=0;
2710        loop
2711        {
2712          if (j>=k) break;
2713          clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
2714          j++;
2715        }
2716        k++;
2717      }
2718    }
2719  }
2720  /* complete reduction of the standard basis--------- */
2721  if (TEST_OPT_REDSB)
2722  {
2723    completeReduce(strat);
2724#ifdef HAVE_TAIL_RING
2725    if (strat->completeReduce_retry)
2726    {
2727      // completeReduce needed larger exponents, retry
2728      // to reduce with S (instead of T)
2729      // and in currRing (instead of strat->tailRing)
2730      cleanT(strat);strat->tailRing=currRing;
2731      int i;
2732      for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
2733      completeReduce(strat);
2734    }
2735#endif
2736  }
2737  else if (TEST_OPT_PROT) PrintLn();
2738
2739#if SBA_PRINT_SIZE_SYZ
2740  // that is correct, syzl is counting one too far
2741  size_syz = strat->syzl;
2742#endif
2743//  if (TEST_OPT_WEIGHTM)
2744//  {
2745//    pRestoreDegProcs(pFDegOld, pLDegOld);
2746//    if (ecartWeights)
2747//    {
2748//      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
2749//      ecartWeights=NULL;
2750//    }
2751//  }
2752  if (TEST_OPT_PROT) messageStat(hilbcount,strat);
2753  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
2754#if SBA_PRINT_SIZE_G
2755  size_g_non_red  = IDELEMS(strat->Shdl);
2756#endif
2757  //This is again done better at the beginning of the next loop because else damage S
2758  //Put the element that caused the sigdrop ast the beginning
2759  #if 0
2760  //#if SIG_DROP_FIRST
2761  poly dummy;
2762  dummy = pCopy(strat->Shdl->m[strat->sl]);
2763  for(int k=strat->sl;k>=1;k--)
2764  {
2765    strat->Shdl->m[k] = strat->Shdl->m[k-1];
2766    strat->sig[k] = strat->sig[k-1];
2767  }
2768  strat->Shdl->m[0] = dummy;
2769  #endif
2770  idTest(strat->Shdl);
2771  // I have to add the initial input polynomials which where not used (p1 and p2 = NULL)
2772  #ifdef HAVE_RINGS
2773  int k;
2774  if(rField_is_Ring(currRing))
2775  {
2776    //for(k = strat->sl;k>=0;k--)
2777    //  {printf("\nS[%i] = %p\n",k,strat->Shdl->m[k]);pWrite(strat->Shdl->m[k]);}
2778    k = strat->Ll;
2779    #if 1
2780    // 1 - adds just the unused ones, 0 - adds everthing
2781    for(;k>=0 && (strat->L[k].p1 != NULL || strat->L[k].p2 != NULL);k--)
2782    {
2783      //printf("\nDeleted k = %i, %p\n",k,strat->L[k].p);pWrite(strat->L[k].p);pWrite(strat->L[k].p1);pWrite(strat->L[k].p2);
2784      deleteInL(strat->L,&strat->Ll,k,strat);
2785    }
2786    #endif
2787    //for(int kk = strat->sl;kk>=0;kk--)
2788    //  {printf("\nS[%i] = %p\n",kk,strat->Shdl->m[kk]);pWrite(strat->Shdl->m[kk]);}
2789    //idPrint(strat->Shdl);
2790  idTest(strat->Shdl);
2791    //printf("\nk = %i\n",k);
2792    for(;k>=0 && strat->L[k].p1 == NULL && strat->L[k].p2 == NULL;k--)
2793    {
2794      //printf("\nAdded k = %i\n",k);
2795      strat->enterS(strat->L[k], strat->sl+1, strat, strat->tl);
2796      //printf("\nThis elements was added from L on pos %i\n",strat->sl);pWrite(strat->S[strat->sl]);pWrite(strat->sig[strat->sl]);
2797    }
2798  }
2799  // Find the "sigdrop element" and put the same signature as the previous one - do we really need this?? - now i put it on the 0 position - no more comparing needed
2800  #if 0
2801  if(strat->sigdrop && rField_is_Ring(currRing))
2802  {
2803    for(k=strat->sl;k>=0;k--)
2804    {
2805      printf("\nsig[%i] = ",i);pWrite(strat->sig[k]);
2806      if(strat->sig[k] == NULL)
2807        strat->sig[k] = pCopy(strat->sig[k-1]);
2808    }
2809  }
2810  #endif
2811  #endif
2812  //Never do this - you will damage S
2813  //idSkipZeroes(strat->Shdl);
2814  //idPrint(strat->Shdl);
2815  idTest(strat->Shdl);
2816  #if REV_BLOCK_SBA
2817  #if ADIDEBUG
2818  printf("\nSBA Endrun before block reverse sigdrop sorting: \n");
2819  for(k = 0; k<=strat->sl; k++)
2820  {
2821    printf("[%i]:",k);pWrite(strat->Shdl->m[k]);
2822    if(strat->sig[k]!= NULL)
2823      {printf("       ");pWrite(strat->sig[k]);}
2824    else
2825      printf("        0\n");
2826  }
2827  #endif
2828  //Reverse Blockwise Sorting of output needed for the Sig Drop Problem
2829  #ifdef HAVE_RINGS
2830  if(rField_is_Ring(currRing) && strat->sigdrop)
2831  {
2832    poly dummy;
2833    int i,j;
2834    for(i=0;i<=strat->sl;)
2835    {
2836      k = pGetComp(strat->sig[i]);
2837      for(j = i; j<=strat->sl && strat->sig[j]!= NULL && pGetComp(strat->sig[j]) == k;++j)
2838      {
2839        //printf("\n%i is ok",j);
2840      }
2841      if(j == strat->sl && strat->sig[j] == NULL)
2842        j++;
2843      j--;
2844      //printf("\ni = %i, j = %i\n",i,j);
2845      //getchar();
2846      for(k=0;k<(j-i)/2;k++)
2847      {
2848        //printf("\n%i <> %i\n",i+k,j-k);
2849        dummy = pCopy(strat->Shdl->m[i+k]);
2850        strat->Shdl->m[i+k] = strat->Shdl->m[j-k];
2851        strat->Shdl->m[j-k] = pCopy(dummy);
2852        p_Delete(&dummy, currRing);
2853        if(strat->sig[i+k]!= NULL)
2854          dummy = pCopy(strat->sig[i+k]);
2855        else
2856          dummy = NULL;
2857        strat->sig[i+k] = strat->sig[j-k];
2858        if(dummy!= NULL)
2859        {
2860          strat->sig[j-k] = pCopy(dummy);
2861          p_Delete(&dummy, currRing);
2862        }
2863      }
2864      i = j+1;
2865    }
2866  }
2867  #endif
2868  #if ADIDEBUG
2869  printf("\nSBA Endrun after block reverse sigdrop sorting: \n");
2870  for(k = 0; k<=strat->sl; k++)
2871  {
2872    printf("[%i]:",k);pWrite(strat->Shdl->m[k]);
2873    if(strat->sig[k]!= NULL)
2874      {printf("       ");pWrite(strat->sig[k]);}
2875    else
2876      printf("        0\n");
2877  }
2878  #endif
2879  #endif
2880  if ((strat->sbaOrder == 1 || strat->sbaOrder == 3) && sRing!=currRingOld)
2881  {
2882    rChangeCurrRing (currRingOld);
2883    F0          = idrMoveR (F1, sRing, currRing);
2884    strat->Shdl = idrMoveR_NoSort (strat->Shdl, sRing, currRing);
2885    rChangeCurrRing (sRing);
2886    exitSba(strat);
2887    rChangeCurrRing (currRingOld);
2888    rDelete (sRing);
2889  }
2890  #ifdef HAVE_RINGS
2891  //if(nCoeff_is_Ring_Z(currRing->cf))
2892  //  finalReduceByMon(strat);
2893  if(rField_is_Ring(currRing) && !strat->sigdrop)
2894  #endif
2895    id_DelDiv(strat->Shdl, currRing);
2896  idSkipZeroes(strat->Shdl);
2897  idTest(strat->Shdl);
2898
2899#if SBA_PRINT_SIZE_G
2900  size_g   = IDELEMS(strat->Shdl);
2901#endif
2902#ifdef DEBUGF5
2903  printf("SIZE OF SHDL: %d\n",IDELEMS(strat->Shdl));
2904  int oo = 0;
2905  while (oo<IDELEMS(strat->Shdl))
2906  {
2907    printf(" %d.   ",oo+1);
2908    pWrite(pHead(strat->Shdl->m[oo]));
2909    oo++;
2910  }
2911#endif
2912#if SBA_PRINT_ZERO_REDUCTIONS
2913  printf("----------------------------------------------------------\n");
2914  printf("ZERO REDUCTIONS:            %ld\n",zeroreductions);
2915  zeroreductions  = 0;
2916#endif
2917#if SBA_PRINT_REDUCTION_STEPS
2918  printf("----------------------------------------------------------\n");
2919  printf("S-REDUCTIONS:               %ld\n",sba_reduction_steps);
2920#endif
2921#if SBA_PRINT_OPERATIONS
2922  printf("OPERATIONS:                 %ld\n",sba_operations);
2923#endif
2924#if SBA_PRINT_REDUCTION_STEPS
2925  printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
2926  printf("INTERREDUCTIONS:            %ld\n",sba_interreduction_steps);
2927#endif
2928#if SBA_PRINT_OPERATIONS
2929  printf("INTERREDUCTION OPERATIONS:  %ld\n",sba_interreduction_operations);
2930#endif
2931#if SBA_PRINT_REDUCTION_STEPS
2932  printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
2933  printf("ALL REDUCTIONS:             %ld\n",sba_reduction_steps+sba_interreduction_steps);
2934  sba_interreduction_steps  = 0;
2935  sba_reduction_steps       = 0;
2936#endif
2937#if SBA_PRINT_OPERATIONS
2938  printf("ALL OPERATIONS:             %ld\n",sba_operations+sba_interreduction_operations);
2939  sba_interreduction_operations = 0;
2940  sba_operations                = 0;
2941#endif
2942#if SBA_PRINT_SIZE_G
2943  printf("----------------------------------------------------------\n");
2944  printf("SIZE OF G:                  %d / %d\n",size_g,size_g_non_red);
2945  size_g          = 0;
2946  size_g_non_red  = 0;
2947#endif
2948#if SBA_PRINT_SIZE_SYZ
2949  printf("SIZE OF SYZ:                %ld\n",size_syz);
2950  printf("----------------------------------------------------------\n");
2951  size_syz  = 0;
2952#endif
2953#if SBA_PRINT_PRODUCT_CRITERION
2954  printf("PRODUCT CRITERIA:           %ld\n",product_criterion);
2955  product_criterion = 0;
2956#endif
2957  return (strat->Shdl);
2958}
2959
2960poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce)
2961{
2962  assume(q!=NULL);
2963  assume(!(idIs0(F)&&(Q==NULL))); // NF(q, std(0) in polynomial ring?
2964
2965// lazy_reduce flags: can be combined by |
2966//#define KSTD_NF_LAZY   1
2967  // do only a reduction of the leading term
2968//#define KSTD_NF_NONORM 4
2969  // only global: avoid normalization, return a multiply of NF
2970  poly   p;
2971
2972  //if ((idIs0(F))&&(Q==NULL))
2973  //  return pCopy(q); /*F=0*/
2974  //strat->ak = idRankFreeModule(F);
2975  /*- creating temp data structures------------------- -*/
2976  BITSET save1;
2977  SI_SAVE_OPT1(save1);
2978  si_opt_1|=Sy_bit(OPT_REDTAIL);
2979  initBuchMoraCrit(strat);
2980  strat->initEcart = initEcartBBA;
2981  strat->enterS = enterSBba;
2982#ifndef NO_BUCKETS
2983  strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing));
2984#endif
2985  /*- set S -*/
2986  strat->sl = -1;
2987  /*- init local data struct.---------------------------------------- -*/
2988  /*Shdl=*/initS(F,Q,strat);
2989  /*- compute------------------------------------------------------- -*/
2990  //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
2991  //{
2992  //  for (i=strat->sl;i>=0;i--)
2993  //    pNorm(strat->S[i]);
2994  //}
2995  kTest(strat);
2996  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
2997  if (BVERBOSE(23)) kDebugPrint(strat);
2998  int max_ind;
2999  p = redNF(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat);
3000  if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
3001  {
3002    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
3003    if (rField_is_Ring(currRing))
3004    {
3005      p = redtailBba_Z(p,max_ind,strat);
3006    }
3007    else
3008    {
3009      si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY);
3010      p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0);
3011    }
3012  }
3013  /*- release temp data------------------------------- -*/
3014  assume(strat->L==NULL); /* strat->L unused */
3015  assume(strat->B==NULL); /* strat->B unused */
3016  omFree(strat->sevS);
3017  omFree(strat->ecartS);
3018  assume(strat->T==NULL);//omfree(strat->T);
3019  assume(strat->sevT==NULL);//omfree(strat->sevT);
3020  assume(strat->R==NULL);//omfree(strat->R);
3021  omfree(strat->S_2_R);
3022  omfree(strat->fromQ);
3023  idDelete(&strat->Shdl);
3024  SI_RESTORE_OPT1(save1);
3025  if (TEST_OPT_PROT) PrintLn();
3026  return p;
3027}
3028
3029ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce)
3030{
3031  assume(!idIs0(q));
3032  assume(!(idIs0(F)&&(Q==NULL)));
3033// lazy_reduce flags: can be combined by |
3034//#define KSTD_NF_LAZY   1
3035  // do only a reduction of the leading term
3036//#define KSTD_NF_NONORM 4
3037  // only global: avoid normalization, return a multiply of NF
3038  poly   p;
3039  int   i;
3040  ideal res;
3041  int max_ind;
3042
3043  //if (idIs0(q))
3044  //  return idInit(IDELEMS(q),si_max(q->rank,F->rank));
3045  //if ((idIs0(F))&&(Q==NULL))
3046  //  return idCopy(q); /*F=0*/
3047  //strat->ak = idRankFreeModule(F);
3048  /*- creating temp data structures------------------- -*/
3049  BITSET save1;
3050  SI_SAVE_OPT1(save1);
3051  si_opt_1|=Sy_bit(OPT_REDTAIL);
3052  initBuchMoraCrit(strat);
3053  strat->initEcart = initEcartBBA;
3054  strat->enterS = enterSBba;
3055  /*- set S -*/
3056  strat->sl = -1;
3057#ifndef NO_BUCKETS
3058  strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing));
3059#endif
3060  /*- init local data struct.---------------------------------------- -*/
3061  /*Shdl=*/initS(F,Q,strat);
3062  /*- compute------------------------------------------------------- -*/
3063  res=idInit(IDELEMS(q),si_max(q->rank,F->rank));
3064  si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY);
3065  for (i=IDELEMS(q)-1; i>=0; i--)
3066  {
3067    if (q->m[i]!=NULL)
3068    {
3069      if (TEST_OPT_PROT) { PrintS("r");mflush(); }
3070      p = redNF(pCopy(q->m[i]),max_ind,lazyReduce & KSTD_NF_NONORM,strat);
3071      if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
3072      {
3073        if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
3074        if (rField_is_Ring(currRing))
3075        {
3076          p = redtailBba_Z(p,max_ind,strat);
3077        }
3078        else
3079        {
3080          p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0);
3081        }
3082      }
3083      res->m[i]=p;
3084    }
3085    //else
3086    //  res->m[i]=NULL;
3087  }
3088  /*- release temp data------------------------------- -*/
3089  assume(strat->L==NULL); /* strat->L unused */
3090  assume(strat->B==NULL); /* strat->B unused */
3091  omFree(strat->sevS);
3092  omFree(strat->ecartS);
3093  assume(strat->T==NULL);//omfree(strat->T);
3094  assume(strat->sevT==NULL);//omfree(strat->sevT);
3095  assume(strat->R==NULL);//omfree(strat->R);
3096  omfree(strat->S_2_R);
3097  omfree(strat->fromQ);
3098  idDelete(&strat->Shdl);
3099  SI_RESTORE_OPT1(save1);
3100  if (TEST_OPT_PROT) PrintLn();
3101  return res;
3102}
3103
3104#if F5C
3105/*********************************************************************
3106* interrreduction step of the signature-based algorithm:
3107* 1. all strat->S are interpreted as new critical pairs
3108* 2. those pairs need to be completely reduced by the usual (non sig-
3109*    safe) reduction process (including tail reductions)
3110* 3. strat->S and strat->T are completely new computed in these steps
3111********************************************************************/
3112void f5c (kStrategy strat, int& olddeg, int& minimcnt, int& hilbeledeg,
3113          int& hilbcount, int& srmax, int& lrmax, int& reduc, ideal Q,
3114          intvec *w,intvec *hilb )
3115{
3116  int Ll_old, red_result = 1;
3117  int pos  = 0;
3118  hilbeledeg=1;
3119  hilbcount=0;
3120  minimcnt=0;
3121  srmax = 0; // strat->sl is 0 at this point
3122  reduc = olddeg = lrmax = 0;
3123  // we cannot use strat->T anymore
3124  //cleanT(strat);
3125  //strat->tl = -1;
3126  Ll_old    = strat->Ll;
3127  while (strat->tl >= 0)
3128  {
3129    if(!strat->T[strat->tl].is_redundant)
3130    {
3131      LObject h;
3132      h.p = strat->T[strat->tl].p;
3133      h.tailRing = strat->T[strat->tl].tailRing;
3134      h.t_p = strat->T[strat->tl].t_p;
3135      if (h.p!=NULL)
3136      {
3137        if (currRing->OrdSgn==-1)
3138        {
3139          cancelunit(&h);
3140          deleteHC(&h, strat);
3141        }
3142        if (h.p!=NULL)
3143        {
3144          if (TEST_OPT_INTSTRATEGY)
3145          {
3146            //pContent(h.p);
3147            h.pCleardenom(); // also does a pContent
3148          }
3149          else
3150          {
3151            h.pNorm();
3152          }
3153          strat->initEcart(&h);
3154          pos = strat->Ll+1;
3155          h.sev = pGetShortExpVector(h.p);
3156          enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
3157        }
3158      }
3159    }
3160    strat->tl--;
3161  }
3162  strat->sl = -1;
3163#if 0
3164//#ifdef HAVE_TAIL_RING
3165  if(!rField_is_Ring())  // create strong gcd poly computes with tailring and S[i] ->to be fixed
3166    kStratInitChangeTailRing(strat);
3167#endif
3168  //enterpairs(pOne(),0,0,-1,strat,strat->tl);
3169  //strat->sl = -1;
3170  /* picks the last element from the lazyset L */
3171  while (strat->Ll>Ll_old)
3172  {
3173    strat->P = strat->L[strat->Ll];
3174    strat->Ll--;
3175//#if 1
3176#ifdef DEBUGF5
3177    Print("NEXT PAIR TO HANDLE IN INTERRED ALGORITHM\n");
3178    Print("-------------------------------------------------\n");
3179    pWrite(pHead(strat->P.p));
3180    pWrite(pHead(strat->P.p1));
3181    pWrite(pHead(strat->P.p2));
3182    printf("%d\n",strat->tl);
3183    Print("-------------------------------------------------\n");
3184#endif
3185    if (pNext(strat->P.p) == strat->tail)
3186    {
3187      // deletes the short spoly
3188      if (rField_is_Ring(currRing))
3189        pLmDelete(strat->P.p);
3190      else
3191        pLmFree(strat->P.p);
3192
3193      // TODO: needs some masking
3194      // TODO: masking needs to vanish once the signature
3195      //       sutff is completely implemented
3196      strat->P.p = NULL;
3197      poly m1 = NULL, m2 = NULL;
3198
3199      // check that spoly creation is ok
3200      while (strat->tailRing != currRing &&
3201          !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
3202      {
3203        assume(m1 == NULL && m2 == NULL);
3204        // if not, change to a ring where exponents are at least
3205        // large enough
3206        if (!kStratChangeTailRing(strat))
3207        {
3208          WerrorS("OVERFLOW...");
3209          break;
3210        }
3211      }
3212      // create the real one
3213      ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
3214          strat->tailRing, m1, m2, strat->R);
3215    }
3216    else if (strat->P.p1 == NULL)
3217    {
3218      if (strat->minim > 0)
3219        strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
3220      // for input polys, prepare reduction
3221      strat->P.PrepareRed(strat->use_buckets);
3222    }
3223
3224    if (strat->P.p == NULL && strat->P.t_p == NULL)
3225    {
3226      red_result = 0;
3227    }
3228    else
3229    {
3230      if (TEST_OPT_PROT)
3231        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
3232            &olddeg,&reduc,strat, red_result);
3233
3234#ifdef DEBUGF5
3235      Print("Poly before red: ");
3236      pWrite(strat->P.p);
3237#endif
3238      /* complete reduction of the element chosen from L */
3239      red_result = strat->red2(&strat->P,strat);
3240      if (errorreported)  break;
3241    }
3242
3243    if (strat->overflow)
3244    {
3245      if (!kStratChangeTailRing(strat)) { Werror("OVERFLOW.."); break;}
3246    }
3247
3248    // reduction to non-zero new poly
3249    if (red_result == 1)
3250    {
3251      // get the polynomial (canonicalize bucket, make sure P.p is set)
3252      strat->P.GetP(strat->lmBin);
3253      // in the homogeneous case FDeg >= pFDeg (sugar/honey)
3254      // but now, for entering S, T, we reset it
3255      // in the inhomogeneous case: FDeg == pFDeg
3256      if (strat->homog) strat->initEcart(&(strat->P));
3257
3258      /* statistic */
3259      if (TEST_OPT_PROT) PrintS("s");
3260
3261      int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
3262
3263      // reduce the tail and normalize poly
3264      // in the ring case we cannot expect LC(f) = 1,
3265      // therefore we call pContent instead of pNorm
3266#if F5CTAILRED
3267      BOOLEAN withT = TRUE;
3268      if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing)))
3269      {
3270        strat->P.pCleardenom();
3271        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
3272        {
3273          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
3274          strat->P.pCleardenom();
3275        }
3276      }
3277      else
3278      {
3279        strat->P.pNorm();
3280        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
3281          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
3282      }
3283#endif
3284#ifdef KDEBUG
3285      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
3286#endif /* KDEBUG */
3287
3288      // min_std stuff
3289      if ((strat->P.p1==NULL) && (strat->minim>0))
3290      {
3291        if (strat->minim==1)
3292        {
3293          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
3294          p_Delete(&strat->P.p2, currRing, strat->tailRing);
3295        }
3296        else
3297        {
3298          strat->M->m[minimcnt]=strat->P.p2;
3299          strat->P.p2=NULL;
3300        }
3301        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
3302          pNext(strat->M->m[minimcnt])
3303            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
3304                strat->tailRing, currRing,
3305                currRing->PolyBin);
3306        minimcnt++;
3307      }
3308
3309      // enter into S, L, and T
3310      // here we need to recompute new signatures, but those are trivial ones
3311      if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
3312      {
3313        enterT(strat->P, strat);
3314        // posInS only depends on the leading term
3315        strat->enterS(strat->P, pos, strat, strat->tl);
3316//#if 1
3317#ifdef DEBUGF5
3318        Print("ELEMENT ADDED TO GCURR DURING INTERRED: ");
3319        pWrite(pHead(strat->S[strat->sl]));
3320        pWrite(strat->sig[strat->sl]);
3321#endif
3322        if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
3323      }
3324      //      Print("[%d]",hilbeledeg);
3325      if (strat->P.lcm!=NULL)
3326#ifdef HAVE_RINGS
3327        pLmDelete(strat->P.lcm);
3328#else
3329      pLmFree(strat->P.lcm);
3330#endif
3331      if (strat->sl>srmax) srmax = strat->sl;
3332    }
3333    else
3334    {
3335      // adds signature of the zero reduction to
3336      // strat->syz. This is the leading term of
3337      // syzygy and can be used in syzCriterion()
3338      // the signature is added if and only if the
3339      // pair was not detected by the rewritten criterion in strat->red = redSig
3340      if (strat->P.p1 == NULL && strat->minim > 0)
3341      {
3342        p_Delete(&strat->P.p2, currRing, strat->tailRing);
3343      }
3344    }
3345
3346#ifdef KDEBUG
3347    memset(&(strat->P), 0, sizeof(strat->P));
3348#endif /* KDEBUG */
3349  }
3350  int cc = 0;
3351  while (cc<strat->tl+1)
3352  {
3353    strat->T[cc].sig        = pOne();
3354    p_SetComp(strat->T[cc].sig,cc+1,currRing);
3355    strat->T[cc].sevSig     = pGetShortExpVector(strat->T[cc].sig);
3356    strat->sig[cc]          = strat->T[cc].sig;
3357    strat->sevSig[cc]       = strat->T[cc].sevSig;
3358    strat->T[cc].is_sigsafe = TRUE;
3359    cc++;
3360  }
3361  strat->max_lower_index = strat->tl;
3362  // set current signature index of upcoming iteration step
3363  // NOTE:  this needs to be set here, as otherwise initSyzRules cannot compute
3364  //        the corresponding syzygy rules correctly
3365  strat->currIdx = cc+1;
3366  for (int cd=strat->Ll; cd>=0; cd--)
3367  {
3368    p_SetComp(strat->L[cd].sig,cc+1,currRing);
3369    cc++;
3370  }
3371  for (cc=strat->sl+1; cc<IDELEMS(strat->Shdl); ++cc)
3372    strat->Shdl->m[cc]  = NULL;
3373//#if 1
3374#if DEBUGF5
3375  Print("------------------- STRAT S ---------------------\n");
3376  cc = 0;
3377  while (cc<strat->tl+1)
3378  {
3379    pWrite(pHead(strat->S[cc]));
3380    pWrite(strat->sig[cc]);
3381    printf("- - - - - -\n");
3382    cc++;
3383  }
3384  Print("-------------------------------------------------\n");
3385  Print("------------------- STRAT T ---------------------\n");
3386  cc = 0;
3387  while (cc<strat->tl+1)
3388  {
3389    pWrite(pHead(strat->T[cc].p));
3390    pWrite(strat->T[cc].sig);
3391    printf("- - - - - -\n");
3392    cc++;
3393  }
3394  Print("-------------------------------------------------\n");
3395  Print("------------------- STRAT L ---------------------\n");
3396  cc = 0;
3397  while (cc<strat->Ll+1)
3398  {
3399    pWrite(pHead(strat->L[cc].p));
3400    pWrite(pHead(strat->L[cc].p1));
3401    pWrite(pHead(strat->L[cc].p2));
3402    pWrite(strat->L[cc].sig);
3403    printf("- - - - - -\n");
3404    cc++;
3405  }
3406  Print("-------------------------------------------------\n");
3407  printf("F5C DONE\nSTRAT SL: %d -- %d\n",strat->sl, strat->currIdx);
3408#endif
3409
3410}
3411#endif
3412
3413/* shiftgb stuff */
3414#ifdef HAVE_SHIFTBBA
3415
3416
3417ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, int uptodeg, int lV)
3418{
3419  int   red_result = 1;
3420  int   olddeg,reduc;
3421  int hilbeledeg=1,hilbcount=0,minimcnt=0;
3422  BOOLEAN withT = TRUE; // very important for shifts
3423
3424  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit, NO CHANGES */
3425  initBuchMoraPos(strat); /*NO CHANGES YET: perhaps later*/
3426  initHilbCrit(F,Q,&hilb,strat); /*NO CHANGES*/
3427  initBbaShift(strat); /* DONE */
3428  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
3429  /*Shdl=*/initBuchMoraShift(F, Q,strat); /* updateS with no toT, i.e. no init for T */
3430  updateSShift(strat,uptodeg,lV); /* initializes T */
3431
3432  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
3433  reduc = olddeg = 0;
3434  strat->lV=lV;
3435
3436#ifndef NO_BUCKETS
3437  if (!TEST_OPT_NOT_BUCKETS)
3438    strat->use_buckets = 1;
3439#endif
3440
3441  // redtailBBa against T for inhomogenous input
3442  //  if (!TEST_OPT_OLDSTD)
3443  //    withT = ! strat->homog;
3444
3445  // strat->posInT = posInT_pLength;
3446  kTest_TS(strat);
3447
3448#ifdef HAVE_TAIL_RING
3449  kStratInitChangeTailRing(strat);
3450#endif
3451
3452  /* compute------------------------------------------------------- */
3453  while (strat->Ll >= 0)
3454  {
3455#ifdef KDEBUG
3456    if (TEST_OPT_DEBUG) messageSets(strat);
3457#endif
3458    if (strat->Ll== 0) strat->interpt=TRUE;
3459    if (TEST_OPT_DEGBOUND
3460        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
3461            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
3462    {
3463      /*
3464       *stops computation if
3465       * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
3466       *a predefined number Kstd1_deg
3467       */
3468      while ((strat->Ll >= 0)
3469        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
3470        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
3471            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))
3472        )
3473        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
3474      if (strat->Ll<0) break;
3475      else strat->noClearS=TRUE;
3476    }
3477    /* picks the last element from the lazyset L */
3478    strat->P = strat->L[strat->Ll];
3479    strat->Ll--;
3480
3481    if (pNext(strat->P.p) == strat->tail)
3482    {
3483      // deletes the short spoly
3484      pLmFree(strat->P.p);
3485      strat->P.p = NULL;
3486      poly m1 = NULL, m2 = NULL;
3487
3488      // check that spoly creation is ok
3489      while (strat->tailRing != currRing &&
3490             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
3491      {
3492        assume(m1 == NULL && m2 == NULL);
3493        // if not, change to a ring where exponents are at least
3494        // large enough
3495        kStratChangeTailRing(strat);
3496      }
3497      // create the real one
3498      ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
3499                    strat->tailRing, m1, m2, strat->R);
3500    }
3501    else if (strat->P.p1 == NULL)
3502    {
3503      if (strat->minim > 0)
3504        strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
3505      // for input polys, prepare reduction
3506      strat->P.PrepareRed(strat->use_buckets);
3507    }
3508
3509    poly qq;
3510
3511    /* here in the nonhomog case we shrink the new spoly */
3512
3513    if ( ! strat->homog)
3514    {
3515      strat->P.GetP(strat->lmBin); // because shifts are counted with .p structure
3516      /* in the nonhomog case we have to shrink the polynomial */
3517      assume(strat->P.t_p!=NULL);
3518      qq = p_Shrink(strat->P.t_p, lV, strat->tailRing); // direct shrink
3519      if (qq != NULL)
3520      {
3521         /* we're here if Shrink is nonzero */
3522        //         strat->P.p =  NULL;
3523        //        strat->P.Delete(); /* deletes P.p and P.t_p */ //error
3524        strat->P.p   =  NULL; // is not set by Delete
3525        strat->P.t_p =  qq;
3526        strat->P.GetP(strat->lmBin);
3527        // update sev and length
3528        strat->initEcart(&(strat->P));
3529        strat->P.sev = pGetShortExpVector(strat->P.p);
3530//         strat->P.FDeg = strat->P.pFDeg();
3531//         strat->P.length = strat->P.pLDeg();
3532//         strat->P.pLength =strat->P.GetpLength(); //pLength(strat->P.p);
3533      }
3534      else
3535      {
3536         /* Shrink is zero, like y(1)*y(2) - y(1)*y(3)*/
3537#ifdef KDEBUG
3538         if (TEST_OPT_DEBUG){PrintS("nonzero s shrinks to 0");PrintLn();}
3539#endif
3540         //         strat->P.Delete();  // cause error
3541         strat->P.p = NULL;
3542         strat->P.t_p = NULL;
3543           //         strat->P.p = NULL; // or delete strat->P.p ?
3544       }
3545    }
3546      /* end shrinking poly in the nonhomog case */
3547
3548    if (strat->P.p == NULL && strat->P.t_p == NULL)
3549    {
3550      red_result = 0;
3551    }
3552    else
3553    {
3554      if (TEST_OPT_PROT)
3555        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
3556                &olddeg,&reduc,strat, red_result);
3557
3558      /* reduction of the element chosen from L */
3559      red_result = strat->red(&strat->P,strat);
3560    }
3561
3562    // reduction to non-zero new poly
3563    if (red_result == 1)
3564    {
3565      /* statistic */
3566      if (TEST_OPT_PROT) PrintS("s");
3567
3568      // get the polynomial (canonicalize bucket, make sure P.p is set)
3569      strat->P.GetP(strat->lmBin);
3570
3571      int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
3572
3573      // reduce the tail and normalize poly
3574      if (TEST_OPT_INTSTRATEGY)
3575      {
3576        strat->P.pCleardenom();
3577        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
3578        {
3579          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
3580          strat->P.pCleardenom();
3581        }
3582      }
3583      else
3584      {
3585        strat->P.pNorm();
3586        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
3587          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
3588      }
3589
3590      // here we must shrink again! and optionally reduce again
3591      // or build shrink into redtailBba!
3592
3593#ifdef KDEBUG
3594      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
3595#endif
3596
3597      // min_std stuff
3598      if ((strat->P.p1==NULL) && (strat->minim>0))
3599      {
3600        if (strat->minim==1)
3601        {
3602          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
3603          p_Delete(&strat->P.p2, currRing, strat->tailRing);
3604        }
3605        else
3606        {
3607          strat->M->m[minimcnt]=strat->P.p2;
3608          strat->P.p2=NULL;
3609        }
3610        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
3611          pNext(strat->M->m[minimcnt])
3612            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
3613                                           strat->tailRing, currRing,
3614                                           currRing->PolyBin);
3615        minimcnt++;
3616      }
3617
3618    /* here in the nonhomog case we shrink the reduced poly AGAIN */
3619
3620    if ( ! strat->homog)
3621    {
3622      strat->P.GetP(strat->lmBin); // because shifts are counted with .p structure
3623      /* assume strat->P.t_p != NULL */
3624      /* in the nonhomog case we have to shrink the polynomial */
3625      assume(strat->P.t_p!=NULL); // poly qq defined above
3626      qq = p_Shrink(strat->P.t_p, lV, strat->tailRing); // direct shrink
3627      if (qq != NULL)
3628      {
3629         /* we're here if Shrink is nonzero */
3630        //         strat->P.p =  NULL;
3631        //        strat->P.Delete(); /* deletes P.p and P.t_p */ //error
3632        strat->P.p   =  NULL; // is not set by Delete
3633        strat->P.t_p =  qq;
3634        strat->P.GetP(strat->lmBin);
3635        // update sev and length
3636        strat->initEcart(&(strat->P));
3637        strat->P.sev = pGetShortExpVector(strat->P.p);
3638      }
3639      else
3640      {
3641         /* Shrink is zero, like y(1)*y(2) - y(1)*y(3)*/
3642#ifdef PDEBUG
3643         if (TEST_OPT_DEBUG){PrintS("nonzero s shrinks to 0");PrintLn();}
3644#endif
3645         //         strat->P.Delete();  // cause error
3646         strat->P.p = NULL;
3647         strat->P.t_p = NULL;
3648           //         strat->P.p = NULL; // or delete strat->P.p ?
3649         goto     red_shrink2zero;
3650       }
3651    }
3652      /* end shrinking poly AGAIN in the nonhomog case */
3653
3654
3655      // enter into S, L, and T
3656      //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
3657      //        enterT(strat->P, strat); // this was here before Shift stuff
3658      //enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV); // syntax
3659      // the default value for atT = -1 as in bba
3660      /*   strat->P.GetP(); */
3661      // because shifts are counted with .p structure // done before, but ?
3662      enterTShift(strat->P,strat,-1,uptodeg, lV);
3663      enterpairsShift(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl,uptodeg,lV);
3664      //      enterpairsShift(vw,strat->sl,strat->P.ecart,pos,strat, strat->tl,uptodeg,lV);
3665      // posInS only depends on the leading term
3666      strat->enterS(strat->P, pos, strat, strat->tl);
3667
3668      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
3669//      Print("[%d]",hilbeledeg);
3670      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
3671    }
3672    else
3673    {
3674    red_shrink2zero:
3675      if (strat->P.p1 == NULL && strat->minim > 0)
3676      {
3677        p_Delete(&strat->P.p2, currRing, strat->tailRing);
3678      }
3679    }
3680#ifdef KDEBUG
3681    memset(&(strat->P), 0, sizeof(strat->P));
3682#endif
3683    kTest_TS(strat);
3684  }
3685#ifdef KDEBUG
3686  if (TEST_OPT_DEBUG) messageSets(strat);
3687#endif
3688  /* complete reduction of the standard basis--------- */
3689  /*  shift case: look for elt's in S such that they are divisible by elt in T */
3690  //  if (TEST_OPT_SB_1)
3691  if (TEST_OPT_REDSB)
3692  {
3693    int k=0;
3694    int j=-1;
3695    while(k<=strat->sl)
3696    {
3697//       loop
3698//       {
3699//         if (j>=k) break;
3700//         clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
3701//         j++;
3702//       }
3703      LObject Ln (strat->S[k],currRing, strat->tailRing);
3704      Ln.SetShortExpVector();
3705      j = kFindDivisibleByInT(strat, &Ln, j+1);
3706      if (j<0) {  k++; j=-1;}
3707      else
3708      {
3709        if ( pLmCmp(strat->S[k],strat->T[j].p) == 0)
3710        {
3711          j = kFindDivisibleByInT(strat, &Ln, j+1);
3712          if (j<0) {  k++; j=-1;}
3713          else
3714          {
3715            deleteInS(k,strat);
3716          }
3717        }
3718        else
3719        {
3720          deleteInS(k,strat);
3721        }
3722      }
3723    }
3724  }
3725
3726  if (TEST_OPT_REDSB)
3727  {    completeReduce(strat, TRUE); //shift: withT = TRUE
3728    if (strat->completeReduce_retry)
3729    {
3730      // completeReduce needed larger exponents, retry
3731      // to reduce with S (instead of T)
3732      // and in currRing (instead of strat->tailRing)
3733      cleanT(strat);strat->tailRing=currRing;
3734      int i;
3735      for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
3736      completeReduce(strat, TRUE);
3737    }
3738  }
3739  else if (TEST_OPT_PROT) PrintLn();
3740
3741  /* release temp data-------------------------------- */
3742  exitBuchMora(strat);
3743//  if (TEST_OPT_WEIGHTM)
3744//  {
3745//    pRestoreDegProcs(currRing,pFDegOld, pLDegOld);
3746//    if (ecartWeights)
3747//    {
3748//      omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
3749//      ecartWeights=NULL;
3750//    }
3751//  }
3752  if (TEST_OPT_PROT) messageStat(hilbcount,strat);
3753  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
3754  return (strat->Shdl);
3755}
3756
3757
3758ideal freegb(ideal I, int uptodeg, int lVblock)
3759{
3760  /* todo main call */
3761
3762  /* assume: ring is prepared, ideal is copied into shifted ring */
3763  /* uptodeg and lVblock are correct - test them! */
3764
3765  /* check whether the ideal is in V */
3766
3767//  if (0)
3768  if (! ideal_isInV(I,lVblock) )
3769  {
3770    WerrorS("The input ideal contains incorrectly encoded elements! ");
3771    return(NULL);
3772  }
3773
3774  //  kStrategy strat = new skStrategy;
3775  /* ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, int uptodeg, int lV) */
3776  /* at the moment:
3777- no quotient (check)
3778- no *w, no *hilb
3779  */
3780  /* ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp,
3781     int newIdeal, intvec *vw) */
3782  ideal RS = kStdShift(I,NULL, testHomog, NULL,NULL,0,0,NULL, uptodeg, lVblock);
3783    //bbaShift(I,NULL, NULL, NULL, strat, uptodeg, lVblock);
3784  idSkipZeroes(RS);
3785  return(RS);
3786}
3787
3788/*2
3789*reduces h with elements from T choosing  the first possible
3790* element in t with respect to the given pDivisibleBy
3791*/
3792int redFirstShift (LObject* h,kStrategy strat)
3793{
3794  if (h->IsNull()) return 0;
3795
3796  int at, reddeg,d;
3797  int pass = 0;
3798  int j = 0;
3799
3800  if (! strat->homog)
3801  {
3802    d = h->GetpFDeg() + h->ecart;
3803    reddeg = strat->LazyDegree+d;
3804  }
3805  h->SetShortExpVector();
3806  loop
3807  {
3808    j = kFindDivisibleByInT(strat, h);
3809    if (j < 0)
3810    {
3811      h->SetDegStuffReturnLDeg(strat->LDegLast);
3812      return 1;
3813    }
3814
3815    if (!TEST_OPT_INTSTRATEGY)
3816      strat->T[j].pNorm();
3817#ifdef KDEBUG
3818    if (TEST_OPT_DEBUG)
3819    {
3820      PrintS("reduce ");
3821      h->wrp();
3822      PrintS(" with ");
3823      strat->T[j].wrp();
3824    }
3825#endif
3826    ksReducePoly(h, &(strat->T[j]), strat->kNoetherTail(), NULL, strat);
3827    if (!h->IsNull())
3828    {
3829      poly qq=p_Shrink(h->GetTP(),strat->lV,strat->tailRing);
3830      h->p=NULL;
3831      h->t_p=qq;
3832      if (qq!=NULL) h->GetP(strat->lmBin);
3833    }
3834
3835#ifdef KDEBUG
3836    if (TEST_OPT_DEBUG)
3837    {
3838      PrintS(" to ");
3839      wrp(h->p);
3840      PrintLn();
3841    }
3842#endif
3843    if (h->IsNull())
3844    {
3845      if (h->lcm!=NULL) pLmFree(h->lcm);
3846      h->Clear();
3847      return 0;
3848    }
3849    h->SetShortExpVector();
3850
3851#if 0
3852    if ((strat->syzComp!=0) && !strat->honey)
3853    {
3854      if ((strat->syzComp>0) &&
3855          (h->Comp() > strat->syzComp))
3856      {
3857        assume(h->MinComp() > strat->syzComp);
3858#ifdef KDEBUG
3859        if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
3860#endif
3861        if (strat->homog)
3862          h->SetDegStuffReturnLDeg(strat->LDegLast);
3863        return -2;
3864      }
3865    }
3866#endif
3867    if (!strat->homog)
3868    {
3869      if (!TEST_OPT_OLDSTD && strat->honey)
3870      {
3871        h->SetpFDeg();
3872        if (strat->T[j].ecart <= h->ecart)
3873          h->ecart = d - h->GetpFDeg();
3874        else
3875          h->ecart = d - h->GetpFDeg() + strat->T[j].ecart - h->ecart;
3876
3877        d = h->GetpFDeg() + h->ecart;
3878      }
3879      else
3880        d = h->SetDegStuffReturnLDeg(strat->LDegLast);
3881      /*- try to reduce the s-polynomial -*/
3882      pass++;
3883      /*
3884       *test whether the polynomial should go to the lazyset L
3885       *-if the degree jumps
3886       *-if the number of pre-defined reductions jumps
3887       */
3888      if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
3889          && ((d >= reddeg) || (pass > strat->LazyPass)))
3890      {
3891        h->SetLmCurrRing();
3892        if (strat->posInLDependsOnLength)
3893          h->SetLength(strat->length_pLength);
3894        at = strat->posInL(strat->L,strat->Ll,h,strat);
3895        if (at <= strat->Ll)
3896        {
3897          //int dummy=strat->sl;
3898          /*          if (kFindDivisibleByInS(strat,&dummy, h) < 0) */
3899          //if (kFindDivisibleByInT(strat->T,strat->sevT, dummy, h) < 0)
3900          if (kFindDivisibleByInT(strat, h) < 0)
3901            return 1;
3902          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
3903#ifdef KDEBUG
3904          if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
3905#endif
3906          h->Clear();
3907          return -1;
3908        }
3909      }
3910      if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
3911      {
3912        reddeg = d+1;
3913        Print(".%d",d);mflush();
3914      }
3915    }
3916  }
3917}
3918
3919void initBbaShift(kStrategy strat)
3920{
3921 /* setting global variables ------------------- */
3922  strat->enterS = enterSBba; /* remains as is, we change enterT! */
3923
3924  strat->red = redFirstShift; /* no redHomog ! */
3925
3926  if (currRing->pLexOrder && strat->honey)
3927    strat->initEcart = initEcartNormal;
3928  else
3929    strat->initEcart = initEcartBBA;
3930  if (strat->honey)
3931    strat->initEcartPair = initEcartPairMora;
3932  else
3933    strat->initEcartPair = initEcartPairBba;
3934//  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
3935//  {
3936//    //interred  machen   Aenderung
3937//    pFDegOld=currRing->pFDeg;
3938//    pLDegOld=pLDeg;
3939//    //h=ggetid("ecart");
3940//    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
3941//    //{
3942//    //  ecartWeights=iv2array(IDINTVEC(h));
3943//    //}
3944//    //else
3945//    {
3946//      ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
3947//      /*uses automatic computation of the ecartWeights to set them*/
3948//      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights,currRing);
3949//    }
3950//    pRestoreDegProcs(currRing,totaldegreeWecart, maxdegreeWecart);
3951//    if (TEST_OPT_PROT)
3952//    {
3953//      for(int i=1; i<=rVar(currRing); i++)
3954//        Print(" %d",ecartWeights[i]);
3955//      PrintLn();
3956//      mflush();
3957//    }
3958//  }
3959}
3960#endif
Note: See TracBrowser for help on using the repository browser.