source: git/kernel/kstd2.cc @ 32f7e5

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