source: git/kernel/GBEngine/kstd2.cc @ 5efbf9

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