source: git/kernel/kstd2.cc @ d11734

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