source: git/kernel/GBEngine/kstd2.cc @ 9a871d

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