source: git/kernel/GBEngine/kstd2.cc @ 29fde9

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