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

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