source: git/kernel/kstd2.cc @ 2ce53d

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