source: git/kernel/kstd2.cc @ 1eba39

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