source: git/kernel/GBEngine/kstd2.cc @ 0091f5

fieker-DuValspielwiese
Last change on this file since 0091f5 was 0091f5, checked in by Hans Schoenemann <hannes@…>, 7 years ago
fix: finalReduceByMon: in n_IntMod(A,B,C) B should be positive
  • Property mode set to 100644
File size: 124.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5*  ABSTRACT -  Kernel: alg. of Buchberger
6*/
7
8// #define PDEBUG 2
9
10#include <kernel/mod2.h>
11
12//#define ADIDEBUG 1
13#define GCD_SBA 1
14
15// define if no buckets should be used
16// #define NO_BUCKETS
17
18#ifdef HAVE_PLURAL
19#define PLURAL_INTERNAL_DECLARATIONS 1
20#endif
21
22/***********************************************
23 * SBA stuff -- start
24***********************************************/
25#define DEBUGF50  0
26#define DEBUGF51  0
27
28#ifdef DEBUGF5
29#undef DEBUGF5
30//#define DEBUGF5 1
31#endif
32
33#define F5C       1
34#if F5C
35  #define F5CTAILRED 1
36#endif
37
38#define SBA_INTERRED_START                  0
39#define SBA_TAIL_RED                        1
40#define SBA_PRODUCT_CRITERION               0
41#define SBA_PRINT_ZERO_REDUCTIONS           0
42#define SBA_PRINT_REDUCTION_STEPS           0
43#define SBA_PRINT_OPERATIONS                0
44#define SBA_PRINT_SIZE_G                    0
45#define SBA_PRINT_SIZE_SYZ                  0
46#define SBA_PRINT_PRODUCT_CRITERION         0
47
48// counts sba's reduction steps
49#if SBA_PRINT_REDUCTION_STEPS
50long sba_reduction_steps;
51long sba_interreduction_steps;
52#endif
53#if SBA_PRINT_OPERATIONS
54long sba_operations;
55long sba_interreduction_operations;
56#endif
57
58/***********************************************
59 * SBA stuff -- done
60***********************************************/
61
62#include <kernel/GBEngine/kutil.h>
63#include <misc/options.h>
64#include <omalloc/omalloc.h>
65#include <kernel/polys.h>
66#include <kernel/ideals.h>
67#include <kernel/GBEngine/kstd1.h>
68#include <kernel/GBEngine/khstd.h>
69#include <polys/kbuckets.h>
70#include <polys/prCopy.h>
71//#include "cntrlc.h"
72#include <polys/weight.h>
73#include <misc/intvec.h>
74#ifdef HAVE_PLURAL
75#include <polys/nc/nc.h>
76#endif
77// #include "timer.h"
78
79/* shiftgb stuff */
80#include <kernel/GBEngine/shiftgb.h>
81
82  int (*test_PosInT)(const TSet T,const int tl,LObject &h);
83  int (*test_PosInL)(const LSet set, const int length,
84                LObject* L,const kStrategy strat);
85
86// return -1 if no divisor is found
87//        number of first divisor, otherwise
88int kFindDivisibleByInT(const kStrategy strat, const LObject* L, const int start)
89{
90  unsigned long not_sev = ~L->sev;
91  int j = start;
92
93  const TSet T=strat->T;
94  const unsigned long* sevT=strat->sevT;
95  if (L->p!=NULL)
96  {
97    const ring r=currRing;
98    const poly p=L->p;
99
100    pAssume(~not_sev == p_GetShortExpVector(p, r));
101
102    if(rField_is_Ring(r))
103    {
104      loop
105      {
106        if (j > strat->tl) return -1;
107#if defined(PDEBUG) || defined(PDIV_DEBUG)
108        if (p_LmShortDivisibleBy(T[j].p, sevT[j],p, not_sev, r))
109        {
110          if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].p), r->cf))
111            return j;
112        }
113#else
114        if (!(sevT[j] & not_sev) &&
115          p_LmDivisibleBy(T[j].p, p, r))
116        {
117          if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].p), r->cf))
118            return j;
119        }
120#endif
121        j++;
122      }
123    }
124    else
125    {
126      loop
127      {
128        if (j > strat->tl) return -1;
129#if defined(PDEBUG) || defined(PDIV_DEBUG)
130        if (p_LmShortDivisibleBy(T[j].p, sevT[j],p, not_sev, r))
131        {
132          return j;
133        }
134#else
135        if (!(sevT[j] & not_sev) &&
136          p_LmDivisibleBy(T[j].p, p, r))
137        {
138          return j;
139        }
140#endif
141        j++;
142      }
143    }
144  }
145  else
146  {
147    const poly p=L->t_p;
148    const ring r=strat->tailRing;
149    if(rField_is_Ring(r))
150    {
151      loop
152      {
153        if (j > strat->tl) return -1;
154#if defined(PDEBUG) || defined(PDIV_DEBUG)
155        if (p_LmShortDivisibleBy(T[j].t_p, sevT[j],
156                               p, not_sev, r))
157        {
158          if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].t_p), r->cf))
159            return j;
160        }
161#else
162        if (!(sevT[j] & not_sev) &&
163          p_LmDivisibleBy(T[j].t_p, p, r))
164        {
165          if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].t_p), r->cf))
166            return j;
167        }
168#endif
169        j++;
170      }
171    }
172    else
173    {
174      loop
175      {
176        if (j > strat->tl) return -1;
177#if defined(PDEBUG) || defined(PDIV_DEBUG)
178        if (p_LmShortDivisibleBy(T[j].t_p, sevT[j],
179                               p, not_sev, r))
180        {
181          return j;
182        }
183#else
184        if (!(sevT[j] & not_sev) &&
185          p_LmDivisibleBy(T[j].t_p, p, r))
186        {
187          return j;
188        }
189#endif
190        j++;
191      }
192    }
193  }
194}
195
196// same as above, only with set S
197int kFindDivisibleByInS(const kStrategy strat, int* max_ind, LObject* L)
198{
199  unsigned long not_sev = ~L->sev;
200  poly p = L->GetLmCurrRing();
201  int j = 0;
202
203  pAssume(~not_sev == p_GetShortExpVector(p, currRing));
204#if 1
205  int ende;
206  if ((strat->ak>0) || currRing->pLexOrder || rField_is_Ring(currRing)) ende=strat->sl;
207  else ende=posInS(strat,*max_ind,p,0)+1;
208  if (ende>(*max_ind)) ende=(*max_ind);
209#else
210  int ende=strat->sl;
211#endif
212  (*max_ind)=ende;
213  if(rField_is_Ring(currRing))
214  {
215    loop
216    {
217      if (j > ende) return -1;
218#if defined(PDEBUG) || defined(PDIV_DEBUG)
219      if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j],
220                             p, not_sev, currRing))
221      {
222        if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing->cf))
223          return j;
224      }
225#else
226      if ( !(strat->sevS[j] & not_sev) &&
227         p_LmDivisibleBy(strat->S[j], p, currRing))
228      {
229        if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing->cf))
230          return j;
231      }
232#endif
233      j++;
234    }
235  }
236  else
237  {
238    loop
239    {
240      if (j > ende) return -1;
241#if defined(PDEBUG) || defined(PDIV_DEBUG)
242      if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j],
243                             p, not_sev, currRing))
244      {
245        return j;
246      }
247#else
248      if ( !(strat->sevS[j] & not_sev) &&
249         p_LmDivisibleBy(strat->S[j], p, currRing))
250      {
251        return j;
252      }
253#endif
254      j++;
255    }
256  }
257}
258
259int kFindNextDivisibleByInS(const kStrategy strat, int start,int max_ind, LObject* L)
260{
261  unsigned long not_sev = ~L->sev;
262  poly p = L->GetLmCurrRing();
263  int j = start;
264
265  pAssume(~not_sev == p_GetShortExpVector(p, currRing));
266#if 1
267  int ende=max_ind;
268#else
269  int ende=strat->sl;
270#endif
271  if(rField_is_Ring(currRing))
272  {
273    loop
274    {
275      if (j > ende) return -1;
276#if defined(PDEBUG) || defined(PDIV_DEBUG)
277      if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j],
278                             p, not_sev, currRing))
279      {
280        if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing->cf))
281          return j;
282      }
283#else
284      if ( !(strat->sevS[j] & not_sev) &&
285         p_LmDivisibleBy(strat->S[j], p, currRing))
286      {
287        if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing->cf))
288          return j;
289      }
290#endif
291      j++;
292    }
293  }
294  else
295  {
296    loop
297    {
298      if (j > ende) return -1;
299#if defined(PDEBUG) || defined(PDIV_DEBUG)
300      if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j],
301                             p, not_sev, currRing))
302      {
303        return j;
304      }
305#else
306      if ( !(strat->sevS[j] & not_sev) &&
307         p_LmDivisibleBy(strat->S[j], p, currRing))
308      {
309        return j;
310      }
311#endif
312      j++;
313    }
314  }
315}
316
317#ifdef HAVE_RINGS
318poly kFindZeroPoly(poly input_p, ring leadRing, ring tailRing)
319{
320  // m = currRing->ch
321
322  if (input_p == NULL) return NULL;
323
324  poly p = input_p;
325  poly zeroPoly = NULL;
326  unsigned long a = (unsigned long) pGetCoeff(p);
327
328  int k_ind2 = 0;
329  int a_ind2 = ind2(a);
330
331  // unsigned long k = 1;
332  // of interest is only k_ind2, special routine for improvement ... TODO OLIVER
333  for (int i = 1; i <= leadRing->N; i++)
334  {
335    k_ind2 = k_ind2 + ind_fact_2(p_GetExp(p, i, leadRing));
336  }
337
338  a = (unsigned long) pGetCoeff(p);
339
340  number tmp1;
341  poly tmp2, tmp3;
342  poly lead_mult = p_ISet(1, tailRing);
343  if (n_GetChar(leadRing->cf) <= k_ind2 + a_ind2)
344  {
345    int too_much = k_ind2 + a_ind2 - n_GetChar(leadRing->cf);
346    int s_exp;
347    zeroPoly = p_ISet(a, tailRing);
348    for (int i = 1; i <= leadRing->N; i++)
349    {
350      s_exp = p_GetExp(p, i,leadRing);
351      if (s_exp % 2 != 0)
352      {
353        s_exp = s_exp - 1;
354      }
355      while ( (0 < ind2(s_exp)) && (ind2(s_exp) <= too_much) )
356      {
357        too_much = too_much - ind2(s_exp);
358        s_exp = s_exp - 2;
359      }
360      p_SetExp(lead_mult, i, p_GetExp(p, i,leadRing) - s_exp, tailRing);
361      for (int j = 1; j <= s_exp; j++)
362      {
363        tmp1 = nInit(j);
364        tmp2 = p_ISet(1, tailRing);
365        p_SetExp(tmp2, i, 1, tailRing);
366        p_Setm(tmp2, tailRing);
367        if (nIsZero(tmp1))
368        { // should nowbe obsolet, test ! TODO OLIVER
369          zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
370        }
371        else
372        {
373          tmp3 = p_NSet(nCopy(tmp1), tailRing);
374          zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing);
375        }
376      }
377    }
378    p_Setm(lead_mult, tailRing);
379    zeroPoly = p_Mult_mm(zeroPoly, lead_mult, tailRing);
380    tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing);
381    for (int i = 1; i <= leadRing->N; i++)
382    {
383      pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
384    }
385    p_Setm(tmp2, leadRing);
386    zeroPoly = p_LmDeleteAndNext(zeroPoly, tailRing);
387    pNext(tmp2) = zeroPoly;
388    return tmp2;
389  }
390/*  unsigned long alpha_k = twoPow(leadRing->ch - k_ind2);
391  if (1 == 0 && alpha_k <= a)
392  {  // Temporarly disabled, reducing coefficients not compatible with std TODO Oliver
393    zeroPoly = p_ISet((a / alpha_k)*alpha_k, tailRing);
394    for (int i = 1; i <= leadRing->N; i++)
395    {
396      for (unsigned long j = 1; j <= p_GetExp(p, i, leadRing); j++)
397      {
398        tmp1 = nInit(j);
399        tmp2 = p_ISet(1, tailRing);
400        p_SetExp(tmp2, i, 1, tailRing);
401        p_Setm(tmp2, tailRing);
402        if (nIsZero(tmp1))
403        {
404          zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
405        }
406        else
407        {
408          tmp3 = p_ISet((unsigned long) tmp1, tailRing);
409          zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp2, tmp3, tailRing), tailRing);
410        }
411      }
412    }
413    tmp2 = p_ISet((unsigned long) pGetCoeff(zeroPoly), leadRing);
414    for (int i = 1; i <= leadRing->N; i++)
415    {
416      pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
417    }
418    p_Setm(tmp2, leadRing);
419    zeroPoly = p_LmDeleteAndNext(zeroPoly, tailRing);
420    pNext(tmp2) = zeroPoly;
421    return tmp2;
422  } */
423  return NULL;
424}
425#endif
426
427
428#ifdef HAVE_RINGS
429/*2
430*  reduction procedure for the ring Z/2^m
431*/
432int redRing (LObject* h,kStrategy strat)
433{
434  if (h->IsNull()) return 0; // spoly is zero (can only occure with zero divisors)
435  if (strat->tl<0) return 1;
436
437  int at/*,i*/;
438  long d;
439  int j = 0;
440  int pass = 0;
441  // poly zeroPoly = NULL;
442
443// TODO warum SetpFDeg notwendig?
444  h->SetpFDeg();
445  assume(h->pFDeg() == h->FDeg);
446  long reddeg = h->GetpFDeg();
447
448  h->SetShortExpVector();
449  loop
450  {
451    j = kFindDivisibleByInT(strat, h);
452    if (j < 0)
453    {
454      // over ZZ: cleanup coefficients by complete reduction with monomials
455      postReduceByMon(h, strat);
456      if(h->p == NULL)
457      {
458        if (h->lcm!=NULL) pLmDelete(h->lcm);
459        h->Clear();
460        return 0;
461      }
462      if(nIsZero(pGetCoeff(h->p))) return 2;
463      j = kFindDivisibleByInT(strat, h);
464      if(j < 0)
465      {
466        if(strat->tl >= 0)
467            h->i_r1 = strat->tl;
468        else
469            h->i_r1 = -1;
470        if (h->GetLmTailRing() == NULL)
471        {
472          if (h->lcm!=NULL) pLmDelete(h->lcm);
473          h->Clear();
474          return 0;
475        }
476        return 1;
477      }
478    }
479    //printf("\nFound one: ");pWrite(strat->T[j].p);
480    //enterT(*h, strat);
481    ksReducePoly(h, &(strat->T[j]), NULL, NULL, strat); // with debug output
482    //printf("\nAfter small red: ");pWrite(h->p);
483    if (h->GetLmTailRing() == NULL)
484    {
485      if (h->lcm!=NULL) pLmDelete(h->lcm);
486#ifdef KDEBUG
487      h->lcm=NULL;
488#endif
489      h->Clear();
490      return 0;
491    }
492    h->SetShortExpVector();
493    d = h->SetpFDeg();
494    /*- try to reduce the s-polynomial -*/
495    pass++;
496    if (!TEST_OPT_REDTHROUGH &&
497        (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
498    {
499      h->SetLmCurrRing();
500      if (strat->posInLDependsOnLength)
501        h->SetLength(strat->length_pLength);
502      at = strat->posInL(strat->L,strat->Ll,h,strat);
503      if (at <= strat->Ll)
504      {
505#ifdef KDEBUG
506        if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at);
507#endif
508        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);     // NOT RING CHECKED OLIVER
509        h->Clear();
510        return -1;
511      }
512    }
513    if (d != reddeg)
514    {
515      if (d >= (long)strat->tailRing->bitmask)
516      {
517        if (h->pTotalDeg() >= (long)strat->tailRing->bitmask)
518        {
519          strat->overflow=TRUE;
520          //Print("OVERFLOW in redRing d=%ld, max=%ld\n",d,strat->tailRing->bitmask);
521          h->GetP();
522          at = strat->posInL(strat->L,strat->Ll,h,strat);
523          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
524          h->Clear();
525          return -1;
526        }
527      }
528      else if ((TEST_OPT_PROT) && (strat->Ll < 0))
529      {
530        Print(".%ld",d);mflush();
531        reddeg = d;
532      }
533    }
534  }
535}
536#endif
537
538/*2
539*  reduction procedure for the homogeneous case
540*  and the case of a degree-ordering
541*/
542int redHomog (LObject* h,kStrategy strat)
543{
544  if (strat->tl<0) return 1;
545  //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED!
546  assume(h->FDeg == h->pFDeg());
547
548  poly h_p;
549  int i,j,at,pass, ii;
550  unsigned long not_sev;
551  // long reddeg,d;
552
553  pass = j = 0;
554  // d = reddeg = h->GetpFDeg();
555  h->SetShortExpVector();
556  int li;
557  h_p = h->GetLmTailRing();
558  not_sev = ~ h->sev;
559  loop
560  {
561    j = kFindDivisibleByInT(strat, h);
562    if (j < 0) return 1;
563
564    li = strat->T[j].pLength;
565    ii = j;
566    /*
567     * the polynomial to reduce with (up to the moment) is;
568     * pi with length li
569     */
570    i = j;
571#if 1
572    if (TEST_OPT_LENGTH)
573    loop
574    {
575      /*- search the shortest possible with respect to length -*/
576      i++;
577      if (i > strat->tl)
578        break;
579      if (li<=1)
580        break;
581      if ((strat->T[i].pLength < li)
582         &&
583          p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
584                               h_p, not_sev, strat->tailRing))
585      {
586        /*
587         * the polynomial to reduce with is now;
588         */
589        li = strat->T[i].pLength;
590        ii = i;
591      }
592    }
593#endif
594
595    /*
596     * end of search: have to reduce with pi
597     */
598#ifdef KDEBUG
599    if (TEST_OPT_DEBUG)
600    {
601      PrintS("red:");
602      h->wrp();
603      PrintS(" with ");
604      strat->T[ii].wrp();
605    }
606#endif
607    assume(strat->fromT == FALSE);
608
609    ksReducePoly(h, &(strat->T[ii]), NULL, NULL, strat);
610#if SBA_PRINT_REDUCTION_STEPS
611    sba_interreduction_steps++;
612#endif
613#if SBA_PRINT_OPERATIONS
614    sba_interreduction_operations  +=  pLength(strat->T[ii].p);
615#endif
616
617#ifdef KDEBUG
618    if (TEST_OPT_DEBUG)
619    {
620      PrintS("\nto ");
621      h->wrp();
622      PrintLn();
623    }
624#endif
625
626    h_p = h->GetLmTailRing();
627    if (h_p == NULL)
628    {
629      if (h->lcm!=NULL) pLmFree(h->lcm);
630#ifdef KDEBUG
631      h->lcm=NULL;
632#endif
633      return 0;
634    }
635    h->SetShortExpVector();
636    not_sev = ~ h->sev;
637    /*
638     * try to reduce the s-polynomial h
639     *test first whether h should go to the lazyset L
640     *-if the degree jumps
641     *-if the number of pre-defined reductions jumps
642     */
643    pass++;
644    if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass))
645    {
646      h->SetLmCurrRing();
647      at = strat->posInL(strat->L,strat->Ll,h,strat);
648      if (at <= strat->Ll)
649      {
650        int dummy=strat->sl;
651        if (kFindDivisibleByInS(strat, &dummy, h) < 0)
652          return 1;
653        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
654#ifdef KDEBUG
655        if (TEST_OPT_DEBUG)
656          Print(" lazy: -> L%d\n",at);
657#endif
658        h->Clear();
659        return -1;
660      }
661    }
662  }
663}
664
665KINLINE int ksReducePolyTailSig(LObject* PR, TObject* PW, LObject* Red, kStrategy strat)
666{
667  BOOLEAN ret;
668  number coef;
669  assume(PR->GetLmCurrRing() != PW->GetLmCurrRing());
670  if(!rField_is_Ring(currRing))
671    Red->HeadNormalize();
672  /*
673  printf("------------------------\n");
674  pWrite(Red->GetLmCurrRing());
675  */
676  if(rField_is_Ring(currRing))
677    ret = ksReducePolySigRing(Red, PW, 1, NULL, &coef, strat);
678  else
679    ret = ksReducePolySig(Red, PW, 1, NULL, &coef, strat);
680  if (!ret)
681  {
682    if (! n_IsOne(coef, currRing->cf) && !rField_is_Ring(currRing))
683    {
684      PR->Mult_nn(coef);
685      // HANNES: mark for Normalize
686    }
687    n_Delete(&coef, currRing->cf);
688  }
689  return ret;
690}
691
692/*2
693*  reduction procedure for signature-based standard
694*  basis algorithms:
695*  all reductions have to be sig-safe!
696*
697*  2 is returned if and only if the pair is rejected by the rewritten criterion
698*  at exactly this point of the computations. This is the last possible point
699*  such a check can be done => checks with the biggest set of available
700*  signatures
701*/
702
703int redSig (LObject* h,kStrategy strat)
704{
705  if (strat->tl<0) return 1;
706  //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED!
707  //printf("FDEGS: %ld -- %ld\n",h->FDeg, h->pFDeg());
708  assume(h->FDeg == h->pFDeg());
709//#if 1
710#ifdef DEBUGF5
711  PrintS("------- IN REDSIG -------\n");
712  Print("p: ");
713  pWrite(pHead(h->p));
714  PrintS("p1: ");
715  pWrite(pHead(h->p1));
716  PrintS("p2: ");
717  pWrite(pHead(h->p2));
718  PrintS("---------------------------\n");
719#endif
720  poly h_p;
721  int i,j,at,pass, ii;
722  int start=0;
723  int sigSafe;
724  unsigned long not_sev;
725  // long reddeg,d;
726
727  pass = j = 0;
728  // d = reddeg = h->GetpFDeg();
729  h->SetShortExpVector();
730  int li;
731  h_p = h->GetLmTailRing();
732  not_sev = ~ h->sev;
733  loop
734  {
735    j = kFindDivisibleByInT(strat, h, start);
736    if (j < 0)
737    {
738      return 1;
739    }
740
741    li = strat->T[j].pLength;
742    ii = j;
743    /*
744     * the polynomial to reduce with (up to the moment) is;
745     * pi with length li
746     */
747    i = j;
748#if 1
749    if (TEST_OPT_LENGTH)
750    loop
751    {
752      /*- search the shortest possible with respect to length -*/
753      i++;
754      if (i > strat->tl)
755        break;
756      if (li<=1)
757        break;
758      if ((strat->T[i].pLength < li)
759         &&
760          p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
761                               h_p, not_sev, strat->tailRing))
762      {
763        /*
764         * the polynomial to reduce with is now;
765         */
766        li = strat->T[i].pLength;
767        ii = i;
768      }
769    }
770    start = ii+1;
771#endif
772
773    /*
774     * end of search: have to reduce with pi
775     */
776#ifdef KDEBUG
777    if (TEST_OPT_DEBUG)
778    {
779      PrintS("red:");
780      h->wrp();
781      PrintS(" with ");
782      strat->T[ii].wrp();
783    }
784#endif
785    assume(strat->fromT == FALSE);
786//#if 1
787#ifdef DEBUGF5
788    Print("BEFORE REDUCTION WITH %d:\n",ii);
789    PrintS("--------------------------------\n");
790    pWrite(h->sig);
791    pWrite(strat->T[ii].sig);
792    pWrite(h->GetLmCurrRing());
793    pWrite(pHead(h->p1));
794    pWrite(pHead(h->p2));
795    pWrite(pHead(strat->T[ii].p));
796    PrintS("--------------------------------\n");
797    printf("INDEX OF REDUCER T: %d\n",ii);
798#endif
799    sigSafe = ksReducePolySig(h, &(strat->T[ii]), strat->S_2_R[ii], NULL, NULL, strat);
800#if SBA_PRINT_REDUCTION_STEPS
801    if (sigSafe != 3)
802      sba_reduction_steps++;
803#endif
804#if SBA_PRINT_OPERATIONS
805    if (sigSafe != 3)
806      sba_operations  +=  pLength(strat->T[ii].p);
807#endif
808    // if reduction has taken place, i.e. the reduction was sig-safe
809    // otherwise start is already at the next position and the loop
810    // searching reducers in T goes on from index start
811//#if 1
812#ifdef DEBUGF5
813    Print("SigSAFE: %d\n",sigSafe);
814#endif
815    if (sigSafe != 3)
816    {
817      // start the next search for reducers in T from the beginning
818      start = 0;
819#ifdef KDEBUG
820      if (TEST_OPT_DEBUG)
821      {
822        PrintS("\nto ");
823        h->wrp();
824        PrintLn();
825      }
826#endif
827
828      h_p = h->GetLmTailRing();
829      if (h_p == NULL)
830      {
831        if (h->lcm!=NULL) pLmFree(h->lcm);
832#ifdef KDEBUG
833        h->lcm=NULL;
834#endif
835        return 0;
836      }
837      h->SetShortExpVector();
838      not_sev = ~ h->sev;
839      /*
840      * try to reduce the s-polynomial h
841      *test first whether h should go to the lazyset L
842      *-if the degree jumps
843      *-if the number of pre-defined reductions jumps
844      */
845      pass++;
846      if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass))
847      {
848        h->SetLmCurrRing();
849        at = strat->posInL(strat->L,strat->Ll,h,strat);
850        if (at <= strat->Ll)
851        {
852          int dummy=strat->sl;
853          if (kFindDivisibleByInS(strat, &dummy, h) < 0)
854          {
855            return 1;
856          }
857          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
858#ifdef KDEBUG
859          if (TEST_OPT_DEBUG)
860            Print(" lazy: -> L%d\n",at);
861#endif
862          h->Clear();
863          return -1;
864        }
865      }
866    }
867  }
868}
869
870
871int redSigRing (LObject* h,kStrategy strat)
872{
873  //Since reduce is really bad for SBA we use the following idea:
874  // We first check if we can build a gcd pair between h and S
875  //where the sig remains the same and replace h by this gcd poly
876  assume(rField_is_Ring(currRing));
877  #if GCD_SBA
878  #ifdef ADIDEBUG
879  printf("\nBefore sbaCheckGcdPair ");pWrite(h->p);
880  #endif
881  while(sbaCheckGcdPair(h,strat))
882  {
883    #ifdef ADIDEBUG
884    printf("\nIntermidiate sbaCheckGcdPair ");pWrite(h->p);
885    #endif
886    h->sev = pGetShortExpVector(h->p);
887  }
888  #ifdef ADIDEBUG
889  printf("\nAfter sbaCheckGcdPair ");pWrite(h->p);
890  #endif
891  #endif
892  poly beforeredsig;
893  beforeredsig = pCopy(h->sig);
894
895  if (strat->tl<0) return 1;
896  //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED!
897  //printf("FDEGS: %ld -- %ld\n",h->FDeg, h->pFDeg());
898  assume(h->FDeg == h->pFDeg());
899  #ifdef ADIDEBUG
900  printf("\n--------------------------redSig-------------------------------------\n");
901  printf("\nBefore redSig:\n");
902  p_Write(h->p,strat->tailRing);pWrite(h->sig);
903  #endif
904//#if 1
905#ifdef DEBUGF5
906  Print("------- IN REDSIG -------\n");
907  Print("p: ");
908  pWrite(pHead(h->p));
909  Print("p1: ");
910  pWrite(pHead(h->p1));
911  Print("p2: ");
912  pWrite(pHead(h->p2));
913  Print("---------------------------\n");
914#endif
915  poly h_p;
916  int i,j,at,pass, ii;
917  int start=0;
918  int sigSafe;
919  unsigned long not_sev;
920  // long reddeg,d;
921
922  pass = j = 0;
923  // d = reddeg = h->GetpFDeg();
924  h->SetShortExpVector();
925  int li;
926  h_p = h->GetLmTailRing();
927  not_sev = ~ h->sev;
928  loop
929  {
930    j = kFindDivisibleByInT(strat, h, start);
931    if (j < 0)
932    {
933      #if GCD_SBA
934      #ifdef ADIDEBUG
935      printf("\nBefore sbaCheckGcdPair ");pWrite(h->p);
936      #endif
937      while(sbaCheckGcdPair(h,strat))
938      {
939        #ifdef ADIDEBUG
940        printf("\nIntermidiate sbaCheckGcdPair ");pWrite(h->p);
941        #endif
942        h->sev = pGetShortExpVector(h->p);
943        h->is_redundant = FALSE;
944        start = 0;
945      }
946      #ifdef ADIDEBUG
947      printf("\nAfter sbaCheckGcdPair ");pWrite(h->p);
948      #endif
949      #endif
950      // over ZZ: cleanup coefficients by complete reduction with monomials
951      postReduceByMonSig(h, strat);
952      if(h->p == NULL || nIsZero(pGetCoeff(h->p))) return 2;
953      j = kFindDivisibleByInT(strat, h,start);
954      if(j < 0)
955      {
956        if(strat->tl >= 0)
957            h->i_r1 = strat->tl;
958        else
959            h->i_r1 = -1;
960        if (h->GetLmTailRing() == NULL)
961        {
962          if (h->lcm!=NULL) pLmDelete(h->lcm);
963          h->Clear();
964          return 0;
965        }
966        //Check for sigdrop after reduction
967        if(pLtCmp(beforeredsig,h->sig) == 1)
968        {
969          #ifdef ADIDEBUG
970          printf("\nSigDrop after reduce\n");pWrite(beforeredsig);pWrite(h->sig);
971          #endif
972          strat->sigdrop = TRUE;
973          //Reduce it as much as you can
974          int red_result = redRing(h,strat);
975          if(red_result == 0)
976          {
977            //It reduced to 0, cancel the sigdrop
978            #ifdef ADIDEBUG
979            printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
980            #endif
981            strat->sigdrop = FALSE;
982            p_Delete(&h->sig,currRing);h->sig = NULL;
983            return 0;
984          }
985          else
986          {
987            #ifdef ADIDEBUG
988            printf("\nReduced to this via redRing.SIGDROP\n");pWrite(h->p);
989            #endif
990            //strat->enterS(*h, strat->sl+1, strat, strat->tl);
991            return 0;
992          }
993        }
994        p_Delete(&beforeredsig,currRing);
995        return 1;
996      }
997    }
998
999    li = strat->T[j].pLength;
1000    ii = j;
1001    /*
1002     * the polynomial to reduce with (up to the moment) is;
1003     * pi with length li
1004     */
1005    i = j;
1006    if (TEST_OPT_LENGTH)
1007    loop
1008    {
1009      /*- search the shortest possible with respect to length -*/
1010      i++;
1011      if (i > strat->tl)
1012        break;
1013      if (li<=1)
1014        break;
1015      if ((strat->T[i].pLength < li)
1016         && n_DivBy(pGetCoeff(h_p),pGetCoeff(strat->T[i].p),currRing->cf)
1017         && p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
1018                               h_p, not_sev, strat->tailRing))
1019      {
1020        /*
1021         * the polynomial to reduce with is now;
1022         */
1023        li = strat->T[i].pLength;
1024        ii = i;
1025      }
1026    }
1027
1028    start = ii+1;
1029
1030    /*
1031     * end of search: have to reduce with pi
1032     */
1033#ifdef KDEBUG
1034    if (TEST_OPT_DEBUG)
1035    {
1036      PrintS("red:");
1037      h->wrp();
1038      PrintS(" with ");
1039      strat->T[ii].wrp();
1040    }
1041#endif
1042    assume(strat->fromT == FALSE);
1043//#if 1
1044#ifdef DEBUGF5
1045    Print("BEFORE REDUCTION WITH %d:\n",ii);
1046    Print("--------------------------------\n");
1047    pWrite(h->sig);
1048    pWrite(strat->T[ii].sig);
1049    pWrite(h->GetLmCurrRing());
1050    pWrite(pHead(h->p1));
1051    pWrite(pHead(h->p2));
1052    pWrite(pHead(strat->T[ii].p));
1053    Print("--------------------------------\n");
1054    printf("INDEX OF REDUCER T: %d\n",ii);
1055#endif
1056    #ifdef ADIDEBUG
1057    printf("\nWe reduce it with:\n");p_Write(strat->T[ii].p,strat->tailRing);pWrite(strat->T[ii].sig);
1058    #endif
1059    sigSafe = ksReducePolySigRing(h, &(strat->T[ii]), strat->S_2_R[ii], NULL, NULL, strat);
1060    #ifdef ADIDEBUG
1061    printf("\nAfter small reduction:\n");pWrite(h->p);pWrite(h->sig);
1062    #endif
1063    if(h->p == NULL && h->sig == NULL)
1064    {
1065      //Trivial case catch
1066      strat->sigdrop = FALSE;
1067    }
1068    #if 0
1069    //If the reducer has the same lt (+ or -) as the other one, reduce it via redRing
1070    //In some cases this proves to be very bad
1071    if(rField_is_Ring(currRing) && h->p != NULL && pLmCmp(h->p,strat->T[ii].p)==0)
1072    {
1073      #ifdef ADIDEBUG
1074      printf("\nReducer and Original have same LT. Force it with redRing!\n");
1075      #endif
1076      int red_result = redRing(h,strat);
1077      if(red_result == 0)
1078      {
1079        #ifdef ADIDEBUG
1080        printf("\nRedRing reduced it to 0. Perfect\n");
1081        #endif
1082        pDelete(&h->sig);h->sig = NULL;
1083        return 0;
1084      }
1085      else
1086      {
1087        #ifdef ADIDEBUG
1088        printf("\nRedRing reduced it to *.\nHave to sigdrop now\n");pWrite(h->p);
1089        #endif
1090        strat->sigdrop = TRUE;
1091        return 1;
1092      }
1093    }
1094    #endif
1095    if(strat->sigdrop)
1096      return 1;
1097#if SBA_PRINT_REDUCTION_STEPS
1098    if (sigSafe != 3)
1099      sba_reduction_steps++;
1100#endif
1101#if SBA_PRINT_OPERATIONS
1102    if (sigSafe != 3)
1103      sba_operations  +=  pLength(strat->T[ii].p);
1104#endif
1105    // if reduction has taken place, i.e. the reduction was sig-safe
1106    // otherwise start is already at the next position and the loop
1107    // searching reducers in T goes on from index start
1108//#if 1
1109#ifdef DEBUGF5
1110    Print("SigSAFE: %d\n",sigSafe);
1111#endif
1112    if (sigSafe != 3)
1113    {
1114      // start the next search for reducers in T from the beginning
1115      start = 0;
1116#ifdef KDEBUG
1117      if (TEST_OPT_DEBUG)
1118      {
1119        PrintS("\nto ");
1120        h->wrp();
1121        PrintLn();
1122      }
1123#endif
1124
1125      h_p = h->GetLmTailRing();
1126      if (h_p == NULL)
1127      {
1128        if (h->lcm!=NULL) pLmFree(h->lcm);
1129#ifdef KDEBUG
1130        h->lcm=NULL;
1131#endif
1132        return 0;
1133      }
1134      h->SetShortExpVector();
1135      not_sev = ~ h->sev;
1136      /*
1137      * try to reduce the s-polynomial h
1138      *test first whether h should go to the lazyset L
1139      *-if the degree jumps
1140      *-if the number of pre-defined reductions jumps
1141      */
1142      pass++;
1143      if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass))
1144      {
1145        h->SetLmCurrRing();
1146        at = strat->posInL(strat->L,strat->Ll,h,strat);
1147        if (at <= strat->Ll)
1148        {
1149          int dummy=strat->sl;
1150          if (kFindDivisibleByInS(strat, &dummy, h) < 0)
1151          {
1152            return 1;
1153          }
1154          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1155#ifdef KDEBUG
1156          if (TEST_OPT_DEBUG)
1157            Print(" lazy: -> L%d\n",at);
1158#endif
1159          h->Clear();
1160          return -1;
1161        }
1162      }
1163    }
1164  }
1165}
1166
1167// tail reduction for SBA
1168poly redtailSba (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
1169{
1170#define REDTAIL_CANONICALIZE 100
1171  strat->redTailChange=FALSE;
1172  if (strat->noTailReduction) return L->GetLmCurrRing();
1173  poly h, p;
1174  p = h = L->GetLmTailRing();
1175  if ((h==NULL) || (pNext(h)==NULL))
1176    return L->GetLmCurrRing();
1177
1178  TObject* With;
1179  // placeholder in case strat->tl < 0
1180  TObject  With_s(strat->tailRing);
1181
1182  LObject Ln(pNext(h), strat->tailRing);
1183  Ln.sig      = L->sig;
1184  Ln.sevSig   = L->sevSig;
1185  Ln.pLength  = L->GetpLength() - 1;
1186
1187  pNext(h) = NULL;
1188  if (L->p != NULL) pNext(L->p) = NULL;
1189  L->pLength = 1;
1190
1191  Ln.PrepareRed(strat->use_buckets);
1192
1193  int cnt=REDTAIL_CANONICALIZE;
1194  while(!Ln.IsNull())
1195  {
1196    loop
1197    {
1198      if(rField_is_Ring(currRing) && strat->sigdrop)
1199        break;
1200      Ln.SetShortExpVector();
1201      if (withT)
1202      {
1203        int j;
1204        j = kFindDivisibleByInT(strat, &Ln);
1205        if (j < 0) break;
1206        With = &(strat->T[j]);
1207      }
1208      else
1209      {
1210        With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
1211        if (With == NULL) break;
1212      }
1213      cnt--;
1214      if (cnt==0)
1215      {
1216        cnt=REDTAIL_CANONICALIZE;
1217        /*poly tmp=*/Ln.CanonicalizeP();
1218        if (normalize && !rField_is_Ring(currRing))
1219        {
1220          Ln.Normalize();
1221          //pNormalize(tmp);
1222          //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
1223        }
1224      }
1225      if (normalize && (!TEST_OPT_INTSTRATEGY) && !rField_is_Ring(currRing) && (!nIsOne(pGetCoeff(With->p))))
1226      {
1227        With->pNorm();
1228      }
1229      strat->redTailChange=TRUE;
1230      #ifdef ADIDEBUG
1231      printf("\nWill TAILreduce * with *:\n");p_Write(Ln.p,strat->tailRing);pWrite(Ln.sig);
1232      p_Write(With->p,strat->tailRing);pWrite(With->sig);pWrite(L->sig);
1233      #endif
1234      int ret = ksReducePolyTailSig(L, With, &Ln, strat);
1235      if(rField_is_Ring(currRing))
1236        L->sig = Ln.sig;
1237      //Because Ln.sig is set to L->sig, but in ksReducePolyTailSig -> ksReducePolySig
1238      // I delete it an then set Ln.sig. Hence L->sig is lost
1239      #ifdef ADIDEBUG
1240      printf("\nAfter small TAILreduce:\n");pWrite(Ln.p);pWrite(Ln.sig);pWrite(L->sig);
1241      #endif
1242#if SBA_PRINT_REDUCTION_STEPS
1243      if (ret != 3)
1244        sba_reduction_steps++;
1245#endif
1246#if SBA_PRINT_OPERATIONS
1247      if (ret != 3)
1248        sba_operations  +=  pLength(With->p);
1249#endif
1250      if (ret)
1251      {
1252        // reducing the tail would violate the exp bound
1253        //  set a flag and hope for a retry (in bba)
1254        strat->completeReduce_retry=TRUE;
1255        if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
1256        do
1257        {
1258          pNext(h) = Ln.LmExtractAndIter();
1259          pIter(h);
1260          L->pLength++;
1261        } while (!Ln.IsNull());
1262        goto all_done;
1263      }
1264      if (Ln.IsNull()) goto all_done;
1265      if (! withT) With_s.Init(currRing);
1266      if(rField_is_Ring(currRing) && strat->sigdrop)
1267      {
1268        //Cannot break the loop here so easily
1269        break;
1270      }
1271    }
1272    pNext(h) = Ln.LmExtractAndIter();
1273    pIter(h);
1274    if(!rField_is_Ring(currRing))
1275      pNormalize(h);
1276    L->pLength++;
1277  }
1278  all_done:
1279  Ln.Delete();
1280  if (L->p != NULL) pNext(L->p) = pNext(p);
1281
1282  if (strat->redTailChange)
1283  {
1284    L->length = 0;
1285  }
1286  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
1287  //L->Normalize(); // HANNES: should have a test
1288  kTest_L(L);
1289  return L->GetLmCurrRing();
1290}
1291
1292/*2
1293*  reduction procedure for the inhomogeneous case
1294*  and not a degree-ordering
1295*/
1296int redLazy (LObject* h,kStrategy strat)
1297{
1298  if (strat->tl<0) return 1;
1299  int at,i,ii,li;
1300  int j = 0;
1301  int pass = 0;
1302  assume(h->pFDeg() == h->FDeg);
1303  long reddeg = h->GetpFDeg();
1304  long d;
1305  unsigned long not_sev;
1306
1307  h->SetShortExpVector();
1308  poly h_p = h->GetLmTailRing();
1309  not_sev = ~ h->sev;
1310  loop
1311  {
1312    j = kFindDivisibleByInT(strat, h);
1313    if (j < 0) return 1;
1314
1315    li = strat->T[j].pLength;
1316    #if 0
1317    if (li==0)
1318    {
1319      li=strat->T[j].pLength=pLength(strat->T[j].p);
1320    }
1321    #endif
1322    ii = j;
1323    /*
1324     * the polynomial to reduce with (up to the moment) is;
1325     * pi with length li
1326     */
1327
1328    i = j;
1329#if 1
1330    if (TEST_OPT_LENGTH)
1331    loop
1332    {
1333      /*- search the shortest possible with respect to length -*/
1334      i++;
1335      if (i > strat->tl)
1336        break;
1337      if (li<=1)
1338        break;
1339    #if 0
1340      if (strat->T[i].pLength==0)
1341      {
1342        PrintS("!");
1343        strat->T[i].pLength=pLength(strat->T[i].p);
1344      }
1345   #endif
1346      if ((strat->T[i].pLength < li)
1347         &&
1348          p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
1349                               h_p, not_sev, strat->tailRing))
1350      {
1351        /*
1352         * the polynomial to reduce with is now;
1353         */
1354        PrintS("+");
1355        li = strat->T[i].pLength;
1356        ii = i;
1357      }
1358    }
1359#endif
1360
1361    /*
1362     * end of search: have to reduce with pi
1363     */
1364
1365
1366#ifdef KDEBUG
1367    if (TEST_OPT_DEBUG)
1368    {
1369      PrintS("red:");
1370      h->wrp();
1371      PrintS(" with ");
1372      strat->T[ii].wrp();
1373    }
1374#endif
1375
1376    ksReducePoly(h, &(strat->T[ii]), NULL, NULL, strat);
1377#if SBA_PRINT_REDUCTION_STEPS
1378    sba_interreduction_steps++;
1379#endif
1380#if SBA_PRINT_OPERATIONS
1381    sba_interreduction_operations  +=  pLength(strat->T[ii].p);
1382#endif
1383
1384#ifdef KDEBUG
1385    if (TEST_OPT_DEBUG)
1386    {
1387      PrintS("\nto ");
1388      h->wrp();
1389      PrintLn();
1390    }
1391#endif
1392
1393    h_p=h->GetLmTailRing();
1394
1395    if (h_p == NULL)
1396    {
1397      if (h->lcm!=NULL) pLmFree(h->lcm);
1398#ifdef KDEBUG
1399      h->lcm=NULL;
1400#endif
1401      return 0;
1402    }
1403    h->SetShortExpVector();
1404    not_sev = ~ h->sev;
1405    d = h->SetpFDeg();
1406    /*- try to reduce the s-polynomial -*/
1407    pass++;
1408    if (//!TEST_OPT_REDTHROUGH &&
1409        (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
1410    {
1411      h->SetLmCurrRing();
1412      at = strat->posInL(strat->L,strat->Ll,h,strat);
1413      if (at <= strat->Ll)
1414      {
1415#if 1
1416        int dummy=strat->sl;
1417        if (kFindDivisibleByInS(strat, &dummy, h) < 0)
1418          return 1;
1419#endif
1420#ifdef KDEBUG
1421        if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at);
1422#endif
1423        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1424        h->Clear();
1425        return -1;
1426      }
1427    }
1428    else if (d != reddeg)
1429    {
1430      if (d>=(long)strat->tailRing->bitmask)
1431      {
1432        if (h->pTotalDeg() >= (long)strat->tailRing->bitmask)
1433        {
1434          strat->overflow=TRUE;
1435          //Print("OVERFLOW in redLazy d=%ld, max=%ld\n",d,strat->tailRing->bitmask);
1436          h->GetP();
1437          at = strat->posInL(strat->L,strat->Ll,h,strat);
1438          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1439          h->Clear();
1440          return -1;
1441        }
1442      }
1443      else if ((TEST_OPT_PROT) && (strat->Ll < 0))
1444      {
1445        Print(".%ld",d);mflush();
1446        reddeg = d;
1447      }
1448    }
1449  }
1450}
1451/*2
1452*  reduction procedure for the sugar-strategy (honey)
1453* reduces h with elements from T choosing first possible
1454* element in T with respect to the given ecart
1455*/
1456int redHoney (LObject* h, kStrategy strat)
1457{
1458  if (strat->tl<0) return 1;
1459  //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED!
1460  assume(h->FDeg == h->pFDeg());
1461  poly h_p;
1462  int i,j,at,pass,ei, ii, h_d;
1463  unsigned long not_sev;
1464  long reddeg,d;
1465
1466  pass = j = 0;
1467  d = reddeg = h->GetpFDeg() + h->ecart;
1468  h->SetShortExpVector();
1469  int li;
1470  h_p = h->GetLmTailRing();
1471  not_sev = ~ h->sev;
1472
1473  h->PrepareRed(strat->use_buckets);
1474  loop
1475  {
1476    j=kFindDivisibleByInT(strat, h);
1477    if (j < 0) return 1;
1478
1479    ei = strat->T[j].ecart;
1480    li = strat->T[j].pLength;
1481    ii = j;
1482    /*
1483     * the polynomial to reduce with (up to the moment) is;
1484     * pi with ecart ei (T[ii])
1485     */
1486    i = j;
1487    if (TEST_OPT_LENGTH)
1488    loop
1489    {
1490      /*- takes the first possible with respect to ecart -*/
1491      i++;
1492      if (i > strat->tl)
1493        break;
1494      //if (ei < h->ecart)
1495      //  break;
1496      if (li<=1)
1497        break;
1498      if ((((strat->T[i].ecart < ei) && (ei> h->ecart))
1499         || ((strat->T[i].ecart <= h->ecart) && (strat->T[i].pLength < li)))
1500         &&
1501          p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
1502                               h_p, not_sev, strat->tailRing))
1503      {
1504        /*
1505         * the polynomial to reduce with is now;
1506         */
1507        ei = strat->T[i].ecart;
1508        li = strat->T[i].pLength;
1509        ii = i;
1510      }
1511    }
1512
1513    /*
1514     * end of search: have to reduce with pi
1515     */
1516    if (!TEST_OPT_REDTHROUGH && (pass!=0) && (ei > h->ecart))
1517    {
1518      h->GetTP(); // clears bucket
1519      h->SetLmCurrRing();
1520      /*
1521       * It is not possible to reduce h with smaller ecart;
1522       * if possible h goes to the lazy-set L,i.e
1523       * if its position in L would be not the last one
1524       */
1525      if (strat->Ll >= 0) /* L is not empty */
1526      {
1527        at = strat->posInL(strat->L,strat->Ll,h,strat);
1528        if(at <= strat->Ll)
1529          /*- h will not become the next element to reduce -*/
1530        {
1531          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1532#ifdef KDEBUG
1533          if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at);
1534#endif
1535          h->Clear();
1536          return -1;
1537        }
1538      }
1539    }
1540#ifdef KDEBUG
1541    if (TEST_OPT_DEBUG)
1542    {
1543      PrintS("red:");
1544      h->wrp();
1545      Print("\nwith T[%d]:",ii);
1546      strat->T[ii].wrp();
1547    }
1548#endif
1549    assume(strat->fromT == FALSE);
1550
1551    number coef;
1552    ksReducePoly(h,&(strat->T[ii]),strat->kNoetherTail(),&coef,strat);
1553#if SBA_PRINT_REDUCTION_STEPS
1554    sba_interreduction_steps++;
1555#endif
1556#if SBA_PRINT_OPERATIONS
1557    sba_interreduction_operations  +=  pLength(strat->T[ii].p);
1558#endif
1559#ifdef KDEBUG
1560    if (TEST_OPT_DEBUG)
1561    {
1562      PrintS("\nto:");
1563      h->wrp();
1564      PrintLn();
1565    }
1566#endif
1567    if(h->IsNull())
1568    {
1569      h->Clear();
1570      if (h->lcm!=NULL) pLmFree(h->lcm);
1571      #ifdef KDEBUG
1572      h->lcm=NULL;
1573      #endif
1574      return 0;
1575    }
1576    if (TEST_OPT_IDLIFT)
1577    {
1578      if (h->p!=NULL)
1579      {
1580        if(p_GetComp(h->p,currRing)>strat->syzComp)
1581        {
1582          h->Delete();
1583          return 0;
1584        }
1585      }
1586      else if (h->t_p!=NULL)
1587      {
1588        if(p_GetComp(h->t_p,strat->tailRing)>strat->syzComp)
1589        {
1590          h->Delete();
1591          return 0;
1592        }
1593      }
1594    }
1595    h->SetShortExpVector();
1596    not_sev = ~ h->sev;
1597    h_d = h->SetpFDeg();
1598    /* compute the ecart */
1599    if (ei <= h->ecart)
1600      h->ecart = d-h_d;
1601    else
1602      h->ecart = d-h_d+ei-h->ecart;
1603
1604    /*
1605     * try to reduce the s-polynomial h
1606     *test first whether h should go to the lazyset L
1607     *-if the degree jumps
1608     *-if the number of pre-defined reductions jumps
1609     */
1610    pass++;
1611    d = h_d + h->ecart;
1612    if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
1613    {
1614      h->GetTP(); // clear bucket
1615      h->SetLmCurrRing();
1616      at = strat->posInL(strat->L,strat->Ll,h,strat);
1617      if (at <= strat->Ll)
1618      {
1619        int dummy=strat->sl;
1620        if (kFindDivisibleByInS(strat, &dummy, h) < 0)
1621          return 1;
1622        enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1623#ifdef KDEBUG
1624        if (TEST_OPT_DEBUG)
1625          Print(" degree jumped: -> L%d\n",at);
1626#endif
1627        h->Clear();
1628        return -1;
1629      }
1630    }
1631    else if (d > reddeg)
1632    {
1633      if (d>=(long)strat->tailRing->bitmask)
1634      {
1635        if (h->pTotalDeg()+h->ecart >= (long)strat->tailRing->bitmask)
1636        {
1637          strat->overflow=TRUE;
1638          //Print("OVERFLOW in redHoney d=%ld, max=%ld\n",d,strat->tailRing->bitmask);
1639          h->GetP();
1640          at = strat->posInL(strat->L,strat->Ll,h,strat);
1641          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
1642          h->Clear();
1643          return -1;
1644        }
1645      }
1646      else if (TEST_OPT_PROT && (strat->Ll < 0) )
1647      {
1648        //h->wrp(); Print("<%d>\n",h->GetpLength());
1649        reddeg = d;
1650        Print(".%ld",d); mflush();
1651      }
1652    }
1653  }
1654}
1655
1656/*2
1657*  reduction procedure for the normal form
1658*/
1659
1660poly redNF (poly h,int &max_ind,int nonorm,kStrategy strat)
1661{
1662  if (h==NULL) return NULL;
1663  int j;
1664  max_ind=strat->sl;
1665
1666  if (0 > strat->sl)
1667  {
1668    return h;
1669  }
1670  LObject P(h);
1671  P.SetShortExpVector();
1672  P.bucket = kBucketCreate(currRing);
1673  kBucketInit(P.bucket,P.p,pLength(P.p));
1674  kbTest(P.bucket);
1675#ifdef HAVE_RINGS
1676  BOOLEAN is_ring = rField_is_Ring(currRing);
1677#endif
1678#ifdef KDEBUG
1679//  if (TEST_OPT_DEBUG)
1680//  {
1681//    PrintS("redNF: starting S:\n");
1682//    for( j = 0; j <= max_ind; j++ )
1683//    {
1684//      Print("S[%d] (of size: %d): ", j, pSize(strat->S[j]));
1685//      pWrite(strat->S[j]);
1686//    }
1687//  };
1688#endif
1689
1690  loop
1691  {
1692    j=kFindDivisibleByInS(strat,&max_ind,&P);
1693    if (j>=0)
1694    {
1695#ifdef HAVE_RINGS
1696      if (!is_ring)
1697      {
1698#endif
1699        int sl=pSize(strat->S[j]);
1700        int jj=j;
1701        loop
1702        {
1703          int sll;
1704          jj=kFindNextDivisibleByInS(strat,jj+1,max_ind,&P);
1705          if (jj<0) break;
1706          sll=pSize(strat->S[jj]);
1707          if (sll<sl)
1708          {
1709            #ifdef KDEBUG
1710            if (TEST_OPT_DEBUG) Print("better(S%d:%d -> S%d:%d)\n",j,sl,jj,sll);
1711            #endif
1712            //else if (TEST_OPT_PROT) { PrintS("b"); mflush(); }
1713            j=jj;
1714            sl=sll;
1715          }
1716        }
1717        if ((nonorm==0) && (!nIsOne(pGetCoeff(strat->S[j]))))
1718        {
1719          pNorm(strat->S[j]);
1720          //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
1721        }
1722#ifdef HAVE_RINGS
1723      }
1724#endif
1725      nNormalize(pGetCoeff(P.p));
1726#ifdef KDEBUG
1727      if (TEST_OPT_DEBUG)
1728      {
1729        PrintS("red:");
1730        wrp(h);
1731        PrintS(" with ");
1732        wrp(strat->S[j]);
1733      }
1734#endif
1735#ifdef HAVE_PLURAL
1736      if (rIsPluralRing(currRing))
1737      {
1738        number coef;
1739        nc_kBucketPolyRed(P.bucket,strat->S[j],&coef);
1740        nDelete(&coef);
1741      }
1742      else
1743#endif
1744      {
1745        number coef;
1746        coef=kBucketPolyRed(P.bucket,strat->S[j],pLength(strat->S[j]),strat->kNoether);
1747        nDelete(&coef);
1748      }
1749      h = kBucketGetLm(P.bucket);   // FRAGE OLIVER
1750      if (h==NULL)
1751      {
1752        kBucketDestroy(&P.bucket);
1753
1754#ifdef KDEBUG
1755//        if (TEST_OPT_DEBUG)
1756//        {
1757//          PrintS("redNF: starting S:\n");
1758//          for( j = 0; j <= max_ind; j++ )
1759//          {
1760//            Print("S[%d] (of size: %d): ", j, pSize(strat->S[j]));
1761//            pWrite(strat->S[j]);
1762//          }
1763//        };
1764#endif
1765
1766        return NULL;
1767      }
1768      kbTest(P.bucket);
1769      P.p=h;
1770      P.t_p=NULL;
1771      P.SetShortExpVector();
1772#ifdef KDEBUG
1773      if (TEST_OPT_DEBUG)
1774      {
1775        PrintS("\nto:");
1776        wrp(h);
1777        PrintLn();
1778      }
1779#endif
1780    }
1781    else
1782    {
1783      P.p=kBucketClear(P.bucket);
1784      kBucketDestroy(&P.bucket);
1785      pNormalize(P.p);
1786
1787#ifdef KDEBUG
1788//      if (TEST_OPT_DEBUG)
1789//      {
1790//        PrintS("redNF: starting S:\n");
1791//        for( j = 0; j <= max_ind; j++ )
1792//        {
1793//          Print("S[%d] (of size: %d): ", j, pSize(strat->S[j]));
1794//          pWrite(strat->S[j]);
1795//        }
1796//      };
1797#endif
1798
1799      return P.p;
1800    }
1801  }
1802}
1803
1804/*2
1805*  reduction procedure from global case but with jet bound
1806*/
1807
1808poly redNFBound (poly h,int &max_ind,int nonorm,kStrategy strat,int bound)
1809{
1810  h = pJet(h,bound);
1811  if (h==NULL) return NULL;
1812  int j;
1813  max_ind=strat->sl;
1814
1815  if (0 > strat->sl)
1816  {
1817    return h;
1818  }
1819  LObject P(h);
1820  P.SetShortExpVector();
1821  P.bucket = kBucketCreate(currRing);
1822  kBucketInit(P.bucket,P.p,pLength(P.p));
1823  kbTest(P.bucket);
1824#ifdef HAVE_RINGS
1825  BOOLEAN is_ring = rField_is_Ring(currRing);
1826#endif
1827#ifdef KDEBUG
1828//  if (TEST_OPT_DEBUG)
1829//  {
1830//    PrintS("redNF: starting S:\n");
1831//    for( j = 0; j <= max_ind; j++ )
1832//    {
1833//      Print("S[%d] (of size: %d): ", j, pSize(strat->S[j]));
1834//      pWrite(strat->S[j]);
1835//    }
1836//  };
1837#endif
1838
1839  loop
1840  {
1841    j=kFindDivisibleByInS(strat,&max_ind,&P);
1842    if (j>=0)
1843    {
1844#ifdef HAVE_RINGS
1845      if (!is_ring)
1846      {
1847#endif
1848        int sl=pSize(strat->S[j]);
1849        int jj=j;
1850        loop
1851        {
1852          int sll;
1853          jj=kFindNextDivisibleByInS(strat,jj+1,max_ind,&P);
1854          if (jj<0) break;
1855          sll=pSize(strat->S[jj]);
1856          if (sll<sl)
1857          {
1858            #ifdef KDEBUG
1859            if (TEST_OPT_DEBUG) Print("better(S%d:%d -> S%d:%d)\n",j,sl,jj,sll);
1860            #endif
1861            //else if (TEST_OPT_PROT) { PrintS("b"); mflush(); }
1862            j=jj;
1863            sl=sll;
1864          }
1865        }
1866        if ((nonorm==0) && (!nIsOne(pGetCoeff(strat->S[j]))))
1867        {
1868          pNorm(strat->S[j]);
1869          //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
1870        }
1871#ifdef HAVE_RINGS
1872      }
1873#endif
1874      nNormalize(pGetCoeff(P.p));
1875#ifdef KDEBUG
1876      if (TEST_OPT_DEBUG)
1877      {
1878        PrintS("red:");
1879        wrp(h);
1880        PrintS(" with ");
1881        wrp(strat->S[j]);
1882      }
1883#endif
1884#ifdef HAVE_PLURAL
1885      if (rIsPluralRing(currRing))
1886      {
1887        number coef;
1888        nc_kBucketPolyRed(P.bucket,strat->S[j],&coef);
1889        nDelete(&coef);
1890      }
1891      else
1892#endif
1893      {
1894        number coef;
1895        coef=kBucketPolyRed(P.bucket,strat->S[j],pLength(strat->S[j]),strat->kNoether);
1896        P.p = kBucketClear(P.bucket);
1897        P.p = pJet(P.p,bound);
1898        if(!P.IsNull())
1899        {
1900          kBucketDestroy(&P.bucket);
1901          P.SetShortExpVector();
1902          P.bucket = kBucketCreate(currRing);
1903          kBucketInit(P.bucket,P.p,pLength(P.p));
1904        }
1905        nDelete(&coef);
1906      }
1907      h = kBucketGetLm(P.bucket);   // FRAGE OLIVER
1908      if (h==NULL)
1909      {
1910        kBucketDestroy(&P.bucket);
1911
1912#ifdef KDEBUG
1913//        if (TEST_OPT_DEBUG)
1914//        {
1915//          PrintS("redNF: starting S:\n");
1916//          for( j = 0; j <= max_ind; j++ )
1917//          {
1918//            Print("S[%d] (of size: %d): ", j, pSize(strat->S[j]));
1919//            pWrite(strat->S[j]);
1920//          }
1921//        };
1922#endif
1923
1924        return NULL;
1925      }
1926      kbTest(P.bucket);
1927      P.p=h;
1928      P.t_p=NULL;
1929      P.SetShortExpVector();
1930#ifdef KDEBUG
1931      if (TEST_OPT_DEBUG)
1932      {
1933        PrintS("\nto:");
1934        wrp(h);
1935        PrintLn();
1936      }
1937#endif
1938    }
1939    else
1940    {
1941      P.p=kBucketClear(P.bucket);
1942      kBucketDestroy(&P.bucket);
1943      pNormalize(P.p);
1944
1945#ifdef KDEBUG
1946//      if (TEST_OPT_DEBUG)
1947//      {
1948//        PrintS("redNF: starting S:\n");
1949//        for( j = 0; j <= max_ind; j++ )
1950//        {
1951//          Print("S[%d] (of size: %d): ", j, pSize(strat->S[j]));
1952//          pWrite(strat->S[j]);
1953//        }
1954//      };
1955#endif
1956
1957      return P.p;
1958    }
1959  }
1960}
1961
1962void kDebugPrint(kStrategy strat);
1963
1964ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
1965{
1966  int   red_result = 1;
1967  int   olddeg,reduc;
1968  int hilbeledeg=1,hilbcount=0,minimcnt=0;
1969  BOOLEAN withT = FALSE;
1970  BITSET save;
1971  SI_SAVE_OPT1(save);
1972
1973  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
1974  if(rField_is_Ring(currRing))
1975    initBuchMoraPosRing(strat);
1976  else
1977    initBuchMoraPos(strat);
1978  initHilbCrit(F,Q,&hilb,strat);
1979  initBba(strat);
1980  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
1981  /*Shdl=*/initBuchMora(F, Q,strat);
1982  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
1983  reduc = olddeg = 0;
1984
1985#ifndef NO_BUCKETS
1986  if (!TEST_OPT_NOT_BUCKETS)
1987    strat->use_buckets = 1;
1988#endif
1989  // redtailBBa against T for inhomogenous input
1990  if (!TEST_OPT_OLDSTD)
1991    withT = ! strat->homog;
1992
1993  // strat->posInT = posInT_pLength;
1994  kTest_TS(strat);
1995
1996#ifdef HAVE_TAIL_RING
1997  if(!idIs0(F) &&(!rField_is_Ring(currRing)))  // create strong gcd poly computes with tailring and S[i] ->to be fixed
1998    kStratInitChangeTailRing(strat);
1999#endif
2000  if (BVERBOSE(23))
2001  {
2002    if (test_PosInT!=NULL) strat->posInT=test_PosInT;
2003    if (test_PosInL!=NULL) strat->posInL=test_PosInL;
2004    kDebugPrint(strat);
2005  }
2006
2007
2008#ifdef KDEBUG
2009  //kDebugPrint(strat);
2010#endif
2011  /* compute------------------------------------------------------- */
2012  while (strat->Ll >= 0)
2013  {
2014    #ifdef ADIDEBUG
2015    printf("\n      ------------------------NEW LOOP\n");
2016    printf("\nShdl = \n");
2017    #if 0
2018    idPrint(strat->Shdl);
2019    #else
2020    for(int ii = 0; ii<=strat->sl;ii++)
2021        p_Write(strat->S[ii],strat->tailRing);
2022    #endif
2023    printf("\n   list   L\n");
2024    int iii;
2025    #if 1
2026    for(iii = 0; iii<= strat->Ll; iii++)
2027    {
2028        printf("L[%i]:",iii);
2029        p_Write(strat->L[iii].p, currRing);
2030        p_Write(strat->L[iii].p1, currRing);
2031        p_Write(strat->L[iii].p2, currRing);
2032    }
2033    #else
2034    {
2035        printf("L[%i]:",strat->Ll);
2036        p_Write(strat->L[strat->Ll].p, strat->tailRing);
2037        p_Write(strat->L[strat->Ll].p1, strat->tailRing);
2038        p_Write(strat->L[strat->Ll].p2, strat->tailRing);
2039    }
2040    #endif
2041    #if 0
2042    for(iii = 0; iii<= strat->Bl; iii++)
2043    {
2044        printf("B[%i]:",iii);
2045        p_Write(strat->B[iii].p, /*strat->tailRing*/currRing);
2046        p_Write(strat->B[iii].p1, /*strat->tailRing*/currRing);
2047        p_Write(strat->B[iii].p2, strat->tailRing);
2048    }
2049    #endif
2050    //getchar();
2051    #endif
2052    #ifdef KDEBUG
2053      if (TEST_OPT_DEBUG) messageSets(strat);
2054    #endif
2055    if (strat->Ll== 0) strat->interpt=TRUE;
2056    if (TEST_OPT_DEGBOUND
2057        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
2058            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
2059    {
2060      /*
2061       *stops computation if
2062       * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
2063       *a predefined number Kstd1_deg
2064       */
2065      while ((strat->Ll >= 0)
2066        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
2067        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
2068            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))
2069        )
2070        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
2071      if (strat->Ll<0) break;
2072      else strat->noClearS=TRUE;
2073    }
2074    /* picks the last element from the lazyset L */
2075    strat->P = strat->L[strat->Ll];
2076    strat->Ll--;
2077
2078    if (pNext(strat->P.p) == strat->tail)
2079    {
2080      // deletes the short spoly
2081      if (rField_is_Ring(currRing))
2082        pLmDelete(strat->P.p);
2083      else
2084        pLmFree(strat->P.p);
2085      strat->P.p = NULL;
2086      poly m1 = NULL, m2 = NULL;
2087
2088      // check that spoly creation is ok
2089      while (strat->tailRing != currRing &&
2090             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
2091      {
2092        assume(m1 == NULL && m2 == NULL);
2093        // if not, change to a ring where exponents are at least
2094        // large enough
2095        if (!kStratChangeTailRing(strat))
2096        {
2097          WerrorS("OVERFLOW...");
2098          break;
2099        }
2100      }
2101      // create the real one
2102      ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
2103                    strat->tailRing, m1, m2, strat->R);
2104    }
2105    else if (strat->P.p1 == NULL)
2106    {
2107      if (strat->minim > 0)
2108        strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
2109      // for input polys, prepare reduction
2110      strat->P.PrepareRed(strat->use_buckets);
2111    }
2112
2113    if (strat->P.p == NULL && strat->P.t_p == NULL)
2114    {
2115      red_result = 0;
2116    }
2117    else
2118    {
2119      if (TEST_OPT_PROT)
2120        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
2121                &olddeg,&reduc,strat, red_result);
2122
2123      /* reduction of the element chosen from L */
2124      red_result = strat->red(&strat->P,strat);
2125      if (errorreported)  break;
2126    }
2127
2128    if (strat->overflow)
2129    {
2130      if (!kStratChangeTailRing(strat)) { WerrorS("OVERFLOW.."); break;}
2131    }
2132
2133    // reduction to non-zero new poly
2134    if (red_result == 1)
2135    {
2136      // get the polynomial (canonicalize bucket, make sure P.p is set)
2137      strat->P.GetP(strat->lmBin);
2138      // in the homogeneous case FDeg >= pFDeg (sugar/honey)
2139      // but now, for entering S, T, we reset it
2140      // in the inhomogeneous case: FDeg == pFDeg
2141      if (strat->homog) strat->initEcart(&(strat->P));
2142
2143      /* statistic */
2144      if (TEST_OPT_PROT) PrintS("s");
2145
2146      int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
2147
2148      // reduce the tail and normalize poly
2149      // in the ring case we cannot expect LC(f) = 1,
2150      // therefore we call pContent instead of pNorm
2151      if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing)))
2152      {
2153        strat->P.pCleardenom();
2154        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2155        {
2156          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT,!TEST_OPT_CONTENTSB);
2157          strat->P.pCleardenom();
2158        }
2159      }
2160      else
2161      {
2162        strat->P.pNorm();
2163        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2164          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
2165      }
2166
2167#ifdef KDEBUG
2168      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
2169#endif /* KDEBUG */
2170
2171      // min_std stuff
2172      if ((strat->P.p1==NULL) && (strat->minim>0))
2173      {
2174        if (strat->minim==1)
2175        {
2176          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
2177          p_Delete(&strat->P.p2, currRing, strat->tailRing);
2178        }
2179        else
2180        {
2181          strat->M->m[minimcnt]=strat->P.p2;
2182          strat->P.p2=NULL;
2183        }
2184        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
2185          pNext(strat->M->m[minimcnt])
2186            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
2187                                           strat->tailRing, currRing,
2188                                           currRing->PolyBin);
2189        minimcnt++;
2190      }
2191
2192      // enter into S, L, and T
2193      if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
2194      {
2195        enterT(strat->P, strat);
2196        if (rField_is_Ring(currRing))
2197          superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
2198        else
2199          enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
2200        // posInS only depends on the leading term
2201        strat->enterS(strat->P, pos, strat, strat->tl);
2202        #ifdef ADIDEBUG
2203        printf("\nThis element has been added to S:\n");pWrite(strat->P.p);pWrite(strat->P.p1);pWrite(strat->P.p2);
2204        #endif
2205#if 0
2206        int pl=pLength(strat->P.p);
2207        if (pl==1)
2208        {
2209          //if (TEST_OPT_PROT)
2210          //PrintS("<1>");
2211        }
2212        else if (pl==2)
2213        {
2214          //if (TEST_OPT_PROT)
2215          //PrintS("<2>");
2216        }
2217#endif
2218      }
2219      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
2220//      Print("[%d]",hilbeledeg);
2221      if (strat->P.lcm!=NULL)
2222      {
2223        if (rField_is_Ring(currRing)) pLmDelete(strat->P.lcm);
2224        else                          pLmFree(strat->P.lcm);
2225        strat->P.lcm=NULL;
2226      }
2227      if (strat->s_poly!=NULL)
2228      {
2229        // the only valid entries are: strat->P.p,
2230        // strat->tailRing (read-only, keep it)
2231        // (and P->p1, P->p2 (read-only, must set to NULL if P.p is changed)
2232        if (strat->s_poly(strat))
2233        {
2234          // we are called AFTER enterS, i.e. if we change P
2235          // we have to add it also to S/T
2236          // and add pairs
2237          int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
2238          enterT(strat->P, strat);
2239          if (rField_is_Ring(currRing))
2240            superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
2241          else
2242            enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
2243          strat->enterS(strat->P, pos, strat, strat->tl);
2244        }
2245      }
2246    }
2247    else if (strat->P.p1 == NULL && strat->minim > 0)
2248    {
2249      p_Delete(&strat->P.p2, currRing, strat->tailRing);
2250    }
2251
2252#ifdef KDEBUG
2253    memset(&(strat->P), 0, sizeof(strat->P));
2254#endif /* KDEBUG */
2255    kTest_TS(strat);
2256  }
2257#ifdef KDEBUG
2258  if (TEST_OPT_DEBUG) messageSets(strat);
2259#endif /* KDEBUG */
2260
2261  if (TEST_OPT_SB_1)
2262  {
2263    if(!rField_is_Ring(currRing))
2264    {
2265      int k=1;
2266      int j;
2267      while(k<=strat->sl)
2268      {
2269        j=0;
2270        loop
2271        {
2272          if (j>=k) break;
2273          clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
2274          j++;
2275        }
2276        k++;
2277      }
2278    }
2279  }
2280  /* complete reduction of the standard basis--------- */
2281  if (TEST_OPT_REDSB)
2282  {
2283    completeReduce(strat);
2284    if (strat->completeReduce_retry)
2285    {
2286      // completeReduce needed larger exponents, retry
2287      // to reduce with S (instead of T)
2288      // and in currRing (instead of strat->tailRing)
2289#ifdef HAVE_TAIL_RING
2290      if(currRing->bitmask>strat->tailRing->bitmask)
2291      {
2292        strat->completeReduce_retry=FALSE;
2293        cleanT(strat);strat->tailRing=currRing;
2294        int i;
2295        for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
2296        completeReduce(strat);
2297      }
2298      if (strat->completeReduce_retry)
2299#endif
2300        Werror("exponent bound is %ld",currRing->bitmask);
2301    }
2302  }
2303  else if (TEST_OPT_PROT) PrintLn();
2304  if (!errorreported)
2305  {
2306    if(rField_is_Ring_Z(currRing))
2307    {
2308      for(int i = 0;i<=strat->sl;i++)
2309      {
2310        if(!nGreaterZero(pGetCoeff(strat->S[i])))
2311        {
2312          strat->S[i] = pNeg(strat->S[i]);
2313        }
2314      }
2315      finalReduceByMon(strat);
2316      for(int i = 0;i<=strat->sl;i++)
2317      {
2318        if(!nGreaterZero(pGetCoeff(strat->S[i])))
2319        {
2320          strat->S[i] = pNeg(strat->S[i]);
2321        }
2322      }
2323    }
2324    else if (rField_is_Ring(currRing))
2325      finalReduceByMon(strat);
2326  }
2327  /* release temp data-------------------------------- */
2328  exitBuchMora(strat);
2329//  if (TEST_OPT_WEIGHTM)
2330//  {
2331//    pRestoreDegProcs(currRing,pFDegOld, pLDegOld);
2332//    if (ecartWeights)
2333//    {
2334//      omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
2335//      ecartWeights=NULL;
2336//    }
2337//  }
2338  if ((TEST_OPT_PROT) || (TEST_OPT_DEBUG)) messageStat(hilbcount,strat);
2339  SI_RESTORE_OPT1(save);
2340  if ((Q!=NULL)&&(!errorreported)) updateResult(strat->Shdl,Q,strat);
2341
2342  idTest(strat->Shdl);
2343
2344  return (strat->Shdl);
2345}
2346
2347ideal sba (ideal F0, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
2348{
2349  // ring order stuff:
2350  // in sba we have (until now) two possibilities:
2351  // 1. an incremental computation w.r.t. (C,monomial order)
2352  // 2. a (possibly non-incremental) computation w.r.t. the
2353  //    induced Schreyer order.
2354  // The corresponding orders are computed in sbaRing(), depending
2355  // on the flag strat->sbaOrder
2356#if SBA_PRINT_ZERO_REDUCTIONS
2357  long zeroreductions           = 0;
2358#endif
2359#if SBA_PRINT_PRODUCT_CRITERION
2360  long product_criterion        = 0;
2361#endif
2362#if SBA_PRINT_SIZE_G
2363  int size_g                    = 0;
2364  int size_g_non_red            = 0;
2365#endif
2366#if SBA_PRINT_SIZE_SYZ
2367  long size_syz                 = 0;
2368#endif
2369  // global variable
2370#if SBA_PRINT_REDUCTION_STEPS
2371  sba_reduction_steps           = 0;
2372  sba_interreduction_steps      = 0;
2373#endif
2374#if SBA_PRINT_OPERATIONS
2375  sba_operations                = 0;
2376  sba_interreduction_operations = 0;
2377#endif
2378
2379  ideal F1 = F0;
2380  ring sRing, currRingOld;
2381  currRingOld  = currRing;
2382  if (strat->sbaOrder == 1 || strat->sbaOrder == 3)
2383  {
2384    sRing = sbaRing(strat);
2385    if (sRing!=currRingOld)
2386    {
2387      rChangeCurrRing (sRing);
2388      F1 = idrMoveR (F0, currRingOld, currRing);
2389    }
2390  }
2391  ideal F;
2392  // sort ideal F
2393  //Put the SigDrop element on the correct position (think of sbaEnterS)
2394  //We also sort them
2395  if(rField_is_Ring(currRing) && strat->sigdrop)
2396  {
2397    #if 1
2398    F = idInit(IDELEMS(F1),F1->rank);
2399    for (int i=0; i<IDELEMS(F1);++i)
2400      F->m[i] = F1->m[i];
2401    if(strat->sbaEnterS >= 0)
2402    {
2403      poly dummy;
2404      dummy = pCopy(F->m[0]); //the sigdrop element
2405      for(int i = 0;i<strat->sbaEnterS;i++)
2406        F->m[i] = F->m[i+1];
2407      F->m[strat->sbaEnterS] = dummy;
2408    }
2409    #else
2410    F = idInit(1,F1->rank);
2411    //printf("\nBefore the initial block sorting:\n");idPrint(F1);
2412    F->m[0] = F1->m[0];
2413    int pos;
2414    if(strat->sbaEnterS >= 0)
2415    {
2416      for(int i=1;i<=strat->sbaEnterS;i++)
2417      {
2418        pos = posInIdealMonFirst(F,F1->m[i],1,strat->sbaEnterS);
2419        idInsertPolyOnPos(F,F1->m[i],pos);
2420      }
2421      for(int i=strat->sbaEnterS+1;i<IDELEMS(F1);i++)
2422      {
2423        pos = posInIdealMonFirst(F,F1->m[i],strat->sbaEnterS+1,IDELEMS(F));
2424        idInsertPolyOnPos(F,F1->m[i],pos);
2425      }
2426      poly dummy;
2427      dummy = pCopy(F->m[0]); //the sigdrop element
2428      for(int i = 0;i<strat->sbaEnterS;i++)
2429        F->m[i] = F->m[i+1];
2430      F->m[strat->sbaEnterS] = dummy;
2431    }
2432    else
2433    {
2434      for(int i=1;i<IDELEMS(F1);i++)
2435      {
2436        pos = posInIdealMonFirst(F,F1->m[i],1,IDELEMS(F));
2437        idInsertPolyOnPos(F,F1->m[i],pos);
2438      }
2439    }
2440    #endif
2441    //printf("\nAfter the initial block sorting:\n");idPrint(F);getchar();
2442  }
2443  else
2444  {
2445    F       = idInit(IDELEMS(F1),F1->rank);
2446    intvec *sort  = idSort(F1);
2447    for (int i=0; i<sort->length();++i)
2448      F->m[i] = F1->m[(*sort)[i]-1];
2449    if(rField_is_Ring(currRing))
2450    {
2451      // put the monomials after the sbaEnterS polynomials
2452      //printf("\nThis is the ideal before sorting (sbaEnterS = %i)\n",strat->sbaEnterS);idPrint(F);
2453      int nrmon = 0;
2454      for(int i = IDELEMS(F)-1,j;i>strat->sbaEnterS+nrmon+1 ;i--)
2455      {
2456        //pWrite(F->m[i]);
2457        if(F->m[i] != NULL && pNext(F->m[i]) == NULL)
2458        {
2459          poly mon = F->m[i];
2460          for(j = i;j>strat->sbaEnterS+nrmon+1;j--)
2461          {
2462            F->m[j] = F->m[j-1];
2463          }
2464          F->m[j] = mon;
2465          nrmon++;
2466        }
2467        //idPrint(F);
2468      }
2469    }
2470  }
2471    //printf("\nThis is the ideal after sorting\n");idPrint(F);getchar();
2472  if(rField_is_Ring(currRing))
2473    strat->sigdrop = FALSE;
2474  strat->nrsyzcrit = 0;
2475  strat->nrrewcrit = 0;
2476#if SBA_INTERRED_START
2477  F = kInterRed(F,NULL);
2478#endif
2479#if F5DEBUG
2480  printf("SBA COMPUTATIONS DONE IN THE FOLLOWING RING:\n");
2481  rWrite (currRing);
2482  printf("ordSgn = %d\n",currRing->OrdSgn);
2483  printf("\n");
2484#endif
2485  int   srmax,lrmax, red_result = 1;
2486  int   olddeg,reduc;
2487  int hilbeledeg=1,hilbcount=0,minimcnt=0;
2488  LObject L;
2489  BOOLEAN withT     = TRUE;
2490  strat->max_lower_index = 0;
2491  //initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
2492  initSbaCrit(strat); /*set Gebauer, honey, sugarCrit*/
2493  initSbaPos(strat);
2494  initHilbCrit(F,Q,&hilb,strat);
2495  initSba(F,strat);
2496  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
2497  /*Shdl=*/initSbaBuchMora(F, Q,strat);
2498  idTest(strat->Shdl);
2499  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
2500  srmax = strat->sl;
2501  reduc = olddeg = lrmax = 0;
2502#ifndef NO_BUCKETS
2503  if (!TEST_OPT_NOT_BUCKETS)
2504    strat->use_buckets = 1;
2505#endif
2506
2507  // redtailBBa against T for inhomogenous input
2508  // if (!TEST_OPT_OLDSTD)
2509  //   withT = ! strat->homog;
2510
2511  // strat->posInT = posInT_pLength;
2512  kTest_TS(strat);
2513
2514#ifdef HAVE_TAIL_RING
2515  if(!idIs0(F) &&(!rField_is_Ring(currRing)))  // create strong gcd poly computes with tailring and S[i] ->to be fixed
2516    kStratInitChangeTailRing(strat);
2517#endif
2518  if (BVERBOSE(23))
2519  {
2520    if (test_PosInT!=NULL) strat->posInT=test_PosInT;
2521    if (test_PosInL!=NULL) strat->posInL=test_PosInL;
2522    kDebugPrint(strat);
2523  }
2524  // We add the elements directly in S from the previous loop
2525  if(rField_is_Ring(currRing) && strat->sbaEnterS >= 0)
2526  {
2527    for(int i = 0;i<strat->sbaEnterS;i++)
2528    {
2529      //Update: now the element is at the corect place
2530      //i+1 because on the 0 position is the sigdrop element
2531      enterT(strat->L[strat->Ll-(i)],strat);
2532      strat->enterS(strat->L[strat->Ll-(i)], strat->sl+1, strat, strat->tl);
2533    }
2534    strat->Ll = strat->Ll - strat->sbaEnterS;
2535    strat->sbaEnterS = -1;
2536  }
2537  kTest_TS(strat);
2538#ifdef KDEBUG
2539  //kDebugPrint(strat);
2540#endif
2541  /* compute------------------------------------------------------- */
2542  while (strat->Ll >= 0)
2543  {
2544    #ifdef ADIDEBUG
2545    printf("\n      ------------------------NEW LOOP\n");
2546    printf("\nShdl = \n");
2547    #if 0
2548    idPrint(strat->Shdl);
2549    #else
2550    for(int ii = 0; ii<=strat->sl;ii++)
2551    {
2552      printf("\nS[%i]:  ",ii);p_Write(strat->S[ii],strat->tailRing);
2553      printf("sig:   ");pWrite(strat->sig[ii]);
2554    }
2555    #endif
2556    #if 0
2557    for(int iii = 0; iii< strat->syzl; iii++)
2558    {
2559        printf("\nsyz[%i]:\n",iii);
2560        p_Write(strat->syz[iii], currRing);
2561    }
2562    #endif
2563    #if 0
2564    for(int iii = 0; iii<= strat->tl; iii++)
2565    {
2566        printf("\nT[%i]:\n",iii);
2567        p_Write(strat->T[iii].p, currRing);
2568    }
2569    #endif
2570    printf("\n   list   L\n");
2571    int iii;
2572    #if 0
2573    for(iii = 0; iii<= strat->Ll; iii++)
2574    {
2575        printf("\nL[%i]:\n",iii);
2576        p_Write(strat->L[iii].p, currRing);
2577        p_Write(strat->L[iii].p1, currRing);
2578        p_Write(strat->L[iii].p2, currRing);
2579        p_Write(strat->L[iii].sig, currRing);
2580    }
2581    #else
2582    {
2583        printf("L[%i]:",strat->Ll);
2584        p_Write(strat->L[strat->Ll].p, strat->tailRing);
2585        p_Write(strat->L[strat->Ll].p1, strat->tailRing);
2586        p_Write(strat->L[strat->Ll].p2, strat->tailRing);
2587        p_Write(strat->L[strat->Ll].sig, currRing);
2588    }
2589    #endif
2590    //getchar();
2591    #endif
2592    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
2593    #ifdef KDEBUG
2594      if (TEST_OPT_DEBUG) messageSets(strat);
2595    #endif
2596    if (strat->Ll== 0) strat->interpt=TRUE;
2597    /*
2598    if (TEST_OPT_DEGBOUND
2599        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
2600            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
2601    {
2602
2603       //stops computation if
2604       // 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
2605       //a predefined number Kstd1_deg
2606      while ((strat->Ll >= 0)
2607        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
2608        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
2609            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))
2610        )
2611        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
2612      if (strat->Ll<0) break;
2613      else strat->noClearS=TRUE;
2614    }
2615    */
2616    if (strat->sbaOrder == 1 && pGetComp(strat->L[strat->Ll].sig) != strat->currIdx)
2617    {
2618      strat->currIdx  = pGetComp(strat->L[strat->Ll].sig);
2619#if F5C
2620      // 1. interreduction of the current standard basis
2621      // 2. generation of new principal syzygy rules for syzCriterion
2622      f5c ( strat, olddeg, minimcnt, hilbeledeg, hilbcount, srmax,
2623          lrmax, reduc, Q, w, hilb );
2624#endif
2625      // initialize new syzygy rules for the next iteration step
2626      initSyzRules(strat);
2627    }
2628    /*********************************************************************
2629      * interrreduction step is done, we can go on with the next iteration
2630      * step of the signature-based algorithm
2631      ********************************************************************/
2632    /* picks the last element from the lazyset L */
2633    strat->P = strat->L[strat->Ll];
2634    strat->Ll--;
2635
2636    if(rField_is_Ring(currRing))
2637      strat->sbaEnterS = pGetComp(strat->P.sig) - 1;
2638
2639    #ifdef ADIDEBUG
2640    printf("\n-------------------------\nThis is the current element P\n");
2641    p_Write(strat->P.p,strat->tailRing);
2642    p_Write(strat->P.p1,strat->tailRing);
2643    p_Write(strat->P.p2,strat->tailRing);
2644    p_Write(strat->P.sig,currRing);
2645    #endif
2646    /* reduction of the element chosen from L */
2647    if (!strat->rewCrit2(strat->P.sig, ~strat->P.sevSig, strat->P.GetLmCurrRing(), strat, strat->P.checked+1)) {
2648      //#if 1
2649#ifdef DEBUGF5
2650      PrintS("SIG OF NEXT PAIR TO HANDLE IN SIG-BASED ALGORITHM\n");
2651      PrintS("-------------------------------------------------\n");
2652      pWrite(strat->P.sig);
2653      pWrite(pHead(strat->P.p));
2654      pWrite(pHead(strat->P.p1));
2655      pWrite(pHead(strat->P.p2));
2656      PrintS("-------------------------------------------------\n");
2657#endif
2658      if (pNext(strat->P.p) == strat->tail)
2659      {
2660        // deletes the short spoly
2661        /*
2662        if (rField_is_Ring(currRing))
2663          pLmDelete(strat->P.p);
2664        else
2665          pLmFree(strat->P.p);
2666*/
2667          // TODO: needs some masking
2668          // TODO: masking needs to vanish once the signature
2669          //       sutff is completely implemented
2670          strat->P.p = NULL;
2671        poly m1 = NULL, m2 = NULL;
2672
2673        // check that spoly creation is ok
2674        while (strat->tailRing != currRing &&
2675            !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
2676        {
2677          assume(m1 == NULL && m2 == NULL);
2678          // if not, change to a ring where exponents are at least
2679          // large enough
2680          if (!kStratChangeTailRing(strat))
2681          {
2682            WerrorS("OVERFLOW...");
2683            break;
2684          }
2685        }
2686        // create the real one
2687        ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
2688            strat->tailRing, m1, m2, strat->R);
2689
2690      }
2691      else if (strat->P.p1 == NULL)
2692      {
2693        if (strat->minim > 0)
2694          strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
2695        // for input polys, prepare reduction
2696        if(!rField_is_Ring(currRing))
2697          strat->P.PrepareRed(strat->use_buckets);
2698      }
2699      if (strat->P.p == NULL && strat->P.t_p == NULL)
2700      {
2701        red_result = 0;
2702      }
2703      else
2704      {
2705        //#if 1
2706#ifdef DEBUGF5
2707        PrintS("Poly before red: ");
2708        pWrite(pHead(strat->P.p));
2709        pWrite(strat->P.sig);
2710#endif
2711#if SBA_PRODUCT_CRITERION
2712        if (strat->P.prod_crit) {
2713#if SBA_PRINT_PRODUCT_CRITERION
2714          product_criterion++;
2715#endif
2716          int pos = posInSyz(strat, strat->P.sig);
2717          enterSyz(strat->P, strat, pos);
2718          if (strat->P.lcm!=NULL)
2719            pLmFree(strat->P.lcm);
2720          red_result = 2;
2721        } else {
2722          red_result = strat->red(&strat->P,strat);
2723        }
2724#else
2725        red_result = strat->red(&strat->P,strat);
2726#endif
2727      }
2728    } else {
2729      /*
2730      if (strat->P.lcm != NULL)
2731        pLmFree(strat->P.lcm);
2732        */
2733      red_result = 2;
2734    }
2735    if(rField_is_Ring(currRing))
2736    {
2737      if(strat->P.sig!= NULL && !nGreaterZero(pGetCoeff(strat->P.sig)))
2738      {
2739        strat->P.p = pNeg(strat->P.p);
2740        strat->P.sig = pNeg(strat->P.sig);
2741      }
2742      strat->P.pLength = pLength(strat->P.p);
2743      if(strat->P.sig != NULL)
2744        strat->P.sevSig = pGetShortExpVector(strat->P.sig);
2745      if(strat->P.p != NULL)
2746        strat->P.sev = pGetShortExpVector(strat->P.p);
2747    }
2748    #ifdef ADIDEBUG
2749    printf("\nAfter reduce (redresult=%i): \n",red_result);pWrite(strat->P.p);pWrite(strat->P.sig);
2750    #endif
2751    //sigdrop case
2752    if(rField_is_Ring(currRing) && strat->sigdrop)
2753    {
2754      //First reduce it as much as one can
2755      #ifdef ADIDEBUG
2756      printf("\nSigdrop in the reduce. Trying redring\n");
2757      #endif
2758      red_result = redRing(&strat->P,strat);
2759      if(red_result == 0)
2760      {
2761        #ifdef ADIDEBUG
2762        printf("\nSigdrop cancelled since redRing reduced to 0\n");
2763        #endif
2764        strat->sigdrop = FALSE;
2765        pDelete(&strat->P.sig);
2766        strat->P.sig = NULL;
2767      }
2768      else
2769      {
2770        #ifdef ADIDEBUG
2771        printf("\nStill Sigdrop - redRing reduced to:\n");pWrite(strat->P.p);
2772        #endif
2773        strat->enterS(strat->P, 0, strat, strat->tl);
2774        if (TEST_OPT_PROT)
2775          PrintS("-");
2776        break;
2777      }
2778    }
2779    if(rField_is_Ring(currRing) && strat->blockred > strat->blockredmax)
2780    {
2781      #ifdef ADIDEBUG
2782      printf("\nToo many blocked reductions\n");
2783      #endif
2784      strat->sigdrop = TRUE;
2785      break;
2786    }
2787
2788    if (errorreported)  break;
2789
2790//#if 1
2791#ifdef DEBUGF5
2792    if (red_result != 0) {
2793        PrintS("Poly after red: ");
2794        pWrite(pHead(strat->P.p));
2795        pWrite(strat->P.GetLmCurrRing());
2796        pWrite(strat->P.sig);
2797        printf("%d\n",red_result);
2798    }
2799#endif
2800    if (TEST_OPT_PROT)
2801    {
2802      if(strat->P.p != NULL)
2803        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
2804                &olddeg,&reduc,strat, red_result);
2805      else
2806        message((strat->honey ? strat->P.ecart : 0),
2807                &olddeg,&reduc,strat, red_result);
2808    }
2809
2810    if (strat->overflow)
2811    {
2812        if (!kStratChangeTailRing(strat)) { WerrorS("OVERFLOW.."); break;}
2813    }
2814    // reduction to non-zero new poly
2815    if (red_result == 1)
2816    {
2817      // get the polynomial (canonicalize bucket, make sure P.p is set)
2818      strat->P.GetP(strat->lmBin);
2819
2820      // sig-safe computations may lead to wrong FDeg computation, thus we need
2821      // to recompute it to make sure everything is alright
2822      (strat->P).FDeg = (strat->P).pFDeg();
2823      // in the homogeneous case FDeg >= pFDeg (sugar/honey)
2824      // but now, for entering S, T, we reset it
2825      // in the inhomogeneous case: FDeg == pFDeg
2826      if (strat->homog) strat->initEcart(&(strat->P));
2827
2828      /* statistic */
2829      if (TEST_OPT_PROT) PrintS("s");
2830
2831      //int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
2832      // in F5E we know that the last reduced element is already the
2833      // the one with highest signature
2834      int pos = strat->sl+1;
2835
2836      // reduce the tail and normalize poly
2837      // in the ring case we cannot expect LC(f) = 1,
2838      // therefore we call pContent instead of pNorm
2839      #ifdef HAVE_RINGS
2840      poly beforetailred;
2841      if(rField_is_Ring(currRing))
2842        beforetailred = pCopy(strat->P.sig);
2843      #endif
2844#if SBA_TAIL_RED
2845      if(rField_is_Ring(currRing))
2846      {
2847        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2848          strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
2849      }
2850      else
2851      {
2852        if (strat->sbaOrder != 2) {
2853          if (TEST_OPT_INTSTRATEGY)
2854          {
2855            strat->P.pCleardenom();
2856            if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2857            {
2858              strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
2859              strat->P.pCleardenom();
2860            }
2861          }
2862          else
2863          {
2864            strat->P.pNorm();
2865            if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
2866              strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
2867          }
2868        }
2869      }
2870      // It may happen that we have lost the sig in redtailsba
2871      // It cannot reduce to 0 since here we are doing just tail reduction.
2872      // Best case scenerio: remains the leading term
2873      if(rField_is_Ring(currRing) && strat->sigdrop)
2874      {
2875        #ifdef ADIDEBUG
2876        printf("\n Still sigdrop after redtailSba - it reduced to \n");pWrite(strat->P.p);
2877        #endif
2878        strat->enterS(strat->P, 0, strat, strat->tl);
2879        break;
2880      }
2881#endif
2882    if(rField_is_Ring(currRing))
2883    {
2884      if(strat->P.sig == NULL || pLtCmp(beforetailred,strat->P.sig) == 1)
2885      {
2886        #ifdef ADIDEBUG
2887        printf("\nSigDrop after TAILred\n");pWrite(beforetailred);pWrite(strat->P.sig);
2888        #endif
2889        strat->sigdrop = TRUE;
2890        //Reduce it as much as you can
2891        red_result = redRing(&strat->P,strat);
2892        if(red_result == 0)
2893        {
2894          //It reduced to 0, cancel the sigdrop
2895          #ifdef ADIDEBUG
2896          printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
2897          #endif
2898          strat->sigdrop = FALSE;
2899          p_Delete(&strat->P.sig,currRing);strat->P.sig = NULL;
2900        }
2901        else
2902        {
2903          #ifdef ADIDEBUG
2904          printf("\nReduced to this via redRing.SIGDROP\n");pWrite(strat->P.p);
2905          #endif
2906          strat->enterS(strat->P, 0, strat, strat->tl);
2907          break;
2908        }
2909      }
2910      p_Delete(&beforetailred,currRing);
2911      // strat->P.p = NULL may appear if we had  a sigdrop above and reduced to 0 via redRing
2912      if(strat->P.p == NULL)
2913        goto case_when_red_result_changed;
2914    }
2915    #ifdef ADIDEBUG
2916    printf("\nNach redTailSba: \n");
2917    p_Write(strat->P.p,strat->tailRing);p_Write(strat->P.sig,currRing);
2918    #endif
2919    // remove sigsafe label since it is no longer valid for the next element to
2920    // be reduced
2921    if (strat->sbaOrder == 1)
2922    {
2923      for (int jj = 0; jj<strat->tl+1; jj++)
2924      {
2925        if (pGetComp(strat->T[jj].sig) == strat->currIdx)
2926        {
2927          strat->T[jj].is_sigsafe = FALSE;
2928        }
2929      }
2930    }
2931    else
2932    {
2933      for (int jj = 0; jj<strat->tl+1; jj++)
2934      {
2935        strat->T[jj].is_sigsafe = FALSE;
2936      }
2937    }
2938#ifdef KDEBUG
2939      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
2940#endif /* KDEBUG */
2941
2942      // min_std stuff
2943      if ((strat->P.p1==NULL) && (strat->minim>0))
2944      {
2945        if (strat->minim==1)
2946        {
2947          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
2948          p_Delete(&strat->P.p2, currRing, strat->tailRing);
2949        }
2950        else
2951        {
2952          strat->M->m[minimcnt]=strat->P.p2;
2953          strat->P.p2=NULL;
2954        }
2955        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
2956          pNext(strat->M->m[minimcnt])
2957            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
2958                                           strat->tailRing, currRing,
2959                                           currRing->PolyBin);
2960        minimcnt++;
2961      }
2962
2963      // enter into S, L, and T
2964      //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
2965      enterT(strat->P, strat);
2966      strat->T[strat->tl].is_sigsafe = FALSE;
2967      /*
2968      printf("hier\n");
2969      pWrite(strat->P.GetLmCurrRing());
2970      pWrite(strat->P.sig);
2971      */
2972      if (rField_is_Ring(currRing))
2973        superenterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
2974      else
2975        enterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
2976      #ifdef ADIDEBUG
2977        printf("\nThis element is added to S\n");
2978        p_Write(strat->P.p, strat->tailRing);p_Write(strat->P.p1, strat->tailRing);p_Write(strat->P.p2, strat->tailRing);pWrite(strat->P.sig);
2979        //getchar();
2980        #endif
2981      if(rField_is_Ring(currRing) && strat->sigdrop)
2982        break;
2983      if(rField_is_Ring(currRing))
2984        strat->P.sevSig = p_GetShortExpVector(strat->P.sig,currRing);
2985      strat->enterS(strat->P, pos, strat, strat->tl);
2986      if(strat->sbaOrder != 1)
2987      {
2988        BOOLEAN overwrite = FALSE;
2989        for (int tk=0; tk<strat->sl+1; tk++)
2990        {
2991          if (pGetComp(strat->sig[tk]) == pGetComp(strat->P.sig))
2992          {
2993            //printf("TK %d / %d\n",tk,strat->sl);
2994            overwrite = FALSE;
2995            break;
2996          }
2997        }
2998        //printf("OVERWRITE %d\n",overwrite);
2999        if (overwrite)
3000        {
3001          int cmp = pGetComp(strat->P.sig);
3002          int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int));
3003          pGetExpV (strat->P.p,vv);
3004          pSetExpV (strat->P.sig, vv);
3005          pSetComp (strat->P.sig,cmp);
3006
3007          strat->P.sevSig = pGetShortExpVector (strat->P.sig);
3008          int i;
3009          LObject Q;
3010          for(int ps=0;ps<strat->sl+1;ps++)
3011          {
3012
3013            strat->newt = TRUE;
3014            if (strat->syzl == strat->syzmax)
3015            {
3016              pEnlargeSet(&strat->syz,strat->syzmax,setmaxTinc);
3017              strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
3018                  (strat->syzmax)*sizeof(unsigned long),
3019                  ((strat->syzmax)+setmaxTinc)
3020                  *sizeof(unsigned long));
3021              strat->syzmax += setmaxTinc;
3022            }
3023            Q.sig = pCopy(strat->P.sig);
3024            // add LM(F->m[i]) to the signature to get a Schreyer order
3025            // without changing the underlying polynomial ring at all
3026            if (strat->sbaOrder == 0)
3027              p_ExpVectorAdd (Q.sig,strat->S[ps],currRing);
3028            // since p_Add_q() destroys all input
3029            // data we need to recreate help
3030            // each time
3031            // ----------------------------------------------------------
3032            // in the Schreyer order we always know that the multiplied
3033            // module monomial strat->P.sig gives the leading monomial of
3034            // the corresponding principal syzygy
3035            // => we do not need to compute the "real" syzygy completely
3036            poly help = p_Copy(strat->sig[ps],currRing);
3037            p_ExpVectorAdd (help,strat->P.p,currRing);
3038            Q.sig = p_Add_q(Q.sig,help,currRing);
3039            //printf("%d. SYZ  ",i+1);
3040            //pWrite(strat->syz[i]);
3041            Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
3042            i = posInSyz(strat, Q.sig);
3043            enterSyz(Q, strat, i);
3044          }
3045        }
3046      }
3047      // deg - idx - lp/rp
3048      // => we need to add syzygies with indices > pGetComp(strat->P.sig)
3049      if(strat->sbaOrder == 0 || strat->sbaOrder == 3)
3050      {
3051        int cmp     = pGetComp(strat->P.sig);
3052        int max_cmp = IDELEMS(F);
3053        int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int));
3054        pGetExpV (strat->P.p,vv);
3055        LObject Q;
3056        int pos;
3057        int idx = p_GetComp(strat->P.sig,currRing);
3058        //printf("++ -- adding syzygies -- ++\n");
3059        // if new element is the first one in this index
3060        if (strat->currIdx < idx) {
3061          for (int i=0; i<strat->sl; ++i) {
3062            Q.sig = p_Copy(strat->P.sig,currRing);
3063            p_ExpVectorAdd(Q.sig,strat->S[i],currRing);
3064            poly help = p_Copy(strat->sig[i],currRing);
3065            p_ExpVectorAdd(help,strat->P.p,currRing);
3066            Q.sig = p_Add_q(Q.sig,help,currRing);
3067            //pWrite(Q.sig);
3068            pos = posInSyz(strat, Q.sig);
3069            enterSyz(Q, strat, pos);
3070          }
3071          strat->currIdx = idx;
3072        } else {
3073          // if the element is not the first one in the given index we build all
3074          // possible syzygies with elements of higher index
3075          for (int i=cmp+1; i<=max_cmp; ++i) {
3076            pos = -1;
3077            for (int j=0; j<strat->sl; ++j) {
3078              if (p_GetComp(strat->sig[j],currRing) == i) {
3079                pos = j;
3080                break;
3081              }
3082            }
3083            if (pos != -1) {
3084              Q.sig = p_One(currRing);
3085              p_SetExpV(Q.sig, vv, currRing);
3086              // F->m[i-1] corresponds to index i
3087              p_ExpVectorAdd(Q.sig,F->m[i-1],currRing);
3088              p_SetComp(Q.sig, i, currRing);
3089              poly help = p_Copy(strat->P.sig,currRing);
3090              p_ExpVectorAdd(help,strat->S[pos],currRing);
3091              Q.sig = p_Add_q(Q.sig,help,currRing);
3092              if (strat->sbaOrder == 0) {
3093                if (p_LmCmp(Q.sig,strat->syz[strat->syzl-1],currRing) == -currRing->OrdSgn) {
3094                  pos = posInSyz(strat, Q.sig);
3095                  enterSyz(Q, strat, pos);
3096                }
3097              } else {
3098                pos = posInSyz(strat, Q.sig);
3099                enterSyz(Q, strat, pos);
3100              }
3101            }
3102          }
3103          //printf("++ -- done adding syzygies -- ++\n");
3104        }
3105      }
3106//#if 1
3107#if DEBUGF50
3108    printf("---------------------------\n");
3109    Print(" %d. ELEMENT ADDED TO GCURR:\n",strat->sl+1);
3110    PrintS("LEAD POLY:  "); pWrite(pHead(strat->S[strat->sl]));
3111    PrintS("SIGNATURE:  "); pWrite(strat->sig[strat->sl]);
3112#endif
3113      /*
3114      if (newrules)
3115      {
3116        newrules  = FALSE;
3117      }
3118      */
3119#if 0
3120      int pl=pLength(strat->P.p);
3121      if (pl==1)
3122      {
3123        //if (TEST_OPT_PROT)
3124        //PrintS("<1>");
3125      }
3126      else if (pl==2)
3127      {
3128        //if (TEST_OPT_PROT)
3129        //PrintS("<2>");
3130      }
3131#endif
3132      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
3133//      Print("[%d]",hilbeledeg);
3134      if (strat->P.lcm!=NULL)
3135#ifdef HAVE_RINGS
3136        pLmDelete(strat->P.lcm);
3137#else
3138        pLmFree(strat->P.lcm);
3139#endif
3140      if (strat->sl>srmax) srmax = strat->sl;
3141    }
3142    else
3143    {
3144      case_when_red_result_changed:
3145      // adds signature of the zero reduction to
3146      // strat->syz. This is the leading term of
3147      // syzygy and can be used in syzCriterion()
3148      // the signature is added if and only if the
3149      // pair was not detected by the rewritten criterion in strat->red = redSig
3150      if (red_result!=2) {
3151#if SBA_PRINT_ZERO_REDUCTIONS
3152        zeroreductions++;
3153#endif
3154        if(rField_is_Ring(currRing) && strat->P.p == NULL && strat->P.sig == NULL)
3155        {
3156          //Catch the case when p = 0, sig = 0
3157        }
3158        else
3159        {
3160          int pos = posInSyz(strat, strat->P.sig);
3161          enterSyz(strat->P, strat, pos);
3162  //#if 1
3163  #ifdef DEBUGF5
3164          Print("ADDING STUFF TO SYZ :  ");
3165          //pWrite(strat->P.p);
3166          pWrite(strat->P.sig);
3167  #endif
3168        }
3169      }
3170      if (strat->P.p1 == NULL && strat->minim > 0)
3171      {
3172        p_Delete(&strat->P.p2, currRing, strat->tailRing);
3173      }
3174    }
3175
3176#ifdef KDEBUG
3177    memset(&(strat->P), 0, sizeof(strat->P));
3178#endif /* KDEBUG */
3179    kTest_TS(strat);
3180  }
3181  #if 0
3182  if(strat->sigdrop)
3183    printf("\nSigDrop!\n");
3184  else
3185    printf("\nEnded with no SigDrop\n");
3186  #endif
3187// Clean strat->P for the next sba call
3188  if(rField_is_Ring(currRing) && strat->sigdrop)
3189  {
3190    //This is used to know how many elements can we directly add to S in the next run
3191    if(strat->P.sig != NULL)
3192      strat->sbaEnterS = pGetComp(strat->P.sig)-1;
3193    //else we already set it at the beggining of the loop
3194    #ifdef KDEBUG
3195    memset(&(strat->P), 0, sizeof(strat->P));
3196    #endif /* KDEBUG */
3197  }
3198#ifdef KDEBUG
3199  if (TEST_OPT_DEBUG) messageSets(strat);
3200#endif /* KDEBUG */
3201
3202  if (TEST_OPT_SB_1)
3203  {
3204    if(!rField_is_Ring(currRing))
3205    {
3206      int k=1;
3207      int j;
3208      while(k<=strat->sl)
3209      {
3210        j=0;
3211        loop
3212        {
3213          if (j>=k) break;
3214          clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
3215          j++;
3216        }
3217        k++;
3218      }
3219    }
3220  }
3221  /* complete reduction of the standard basis--------- */
3222  if (TEST_OPT_REDSB)
3223  {
3224    completeReduce(strat);
3225    if (strat->completeReduce_retry)
3226    {
3227      // completeReduce needed larger exponents, retry
3228      // to reduce with S (instead of T)
3229      // and in currRing (instead of strat->tailRing)
3230#ifdef HAVE_TAIL_RING
3231      if(currRing->bitmask>strat->tailRing->bitmask)
3232      {
3233        strat->completeReduce_retry=FALSE;
3234        cleanT(strat);strat->tailRing=currRing;
3235        int i;
3236        for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
3237        completeReduce(strat);
3238      }
3239      if (strat->completeReduce_retry)
3240#endif
3241        Werror("exponent bound is %ld",currRing->bitmask);
3242    }
3243  }
3244  else if (TEST_OPT_PROT) PrintLn();
3245
3246#if SBA_PRINT_SIZE_SYZ
3247  // that is correct, syzl is counting one too far
3248  size_syz = strat->syzl;
3249#endif
3250//  if (TEST_OPT_WEIGHTM)
3251//  {
3252//    pRestoreDegProcs(pFDegOld, pLDegOld);
3253//    if (ecartWeights)
3254//    {
3255//      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
3256//      ecartWeights=NULL;
3257//    }
3258//  }
3259  if (TEST_OPT_PROT) messageStatSBA(hilbcount,strat);
3260  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
3261#if SBA_PRINT_SIZE_G
3262  size_g_non_red  = IDELEMS(strat->Shdl);
3263#endif
3264  if(!rField_is_Ring(currRing))
3265      exitSba(strat);
3266  // I have to add the initial input polynomials which where not used (p1 and p2 = NULL)
3267  #ifdef HAVE_RINGS
3268  int k;
3269  if(rField_is_Ring(currRing))
3270  {
3271    //for(k = strat->sl;k>=0;k--)
3272    //  {printf("\nS[%i] = %p\n",k,strat->Shdl->m[k]);pWrite(strat->Shdl->m[k]);}
3273    k = strat->Ll;
3274    #if 1
3275    // 1 - adds just the unused ones, 0 - adds everthing
3276    for(;k>=0 && (strat->L[k].p1 != NULL || strat->L[k].p2 != NULL);k--)
3277    {
3278      //printf("\nDeleted k = %i, %p\n",k,strat->L[k].p);pWrite(strat->L[k].p);pWrite(strat->L[k].p1);pWrite(strat->L[k].p2);
3279      deleteInL(strat->L,&strat->Ll,k,strat);
3280    }
3281    #endif
3282    //for(int kk = strat->sl;kk>=0;kk--)
3283    //  {printf("\nS[%i] = %p\n",kk,strat->Shdl->m[kk]);pWrite(strat->Shdl->m[kk]);}
3284    //idPrint(strat->Shdl);
3285    //printf("\nk = %i\n",k);
3286    for(;k>=0 && strat->L[k].p1 == NULL && strat->L[k].p2 == NULL;k--)
3287    {
3288      //printf("\nAdded k = %i\n",k);
3289      strat->enterS(strat->L[k], strat->sl+1, strat, strat->tl);
3290      //printf("\nThis elements was added from L on pos %i\n",strat->sl);pWrite(strat->S[strat->sl]);pWrite(strat->sig[strat->sl]);
3291    }
3292  }
3293  // Find the "sigdrop element" and put the same signature as the previous one - do we really need this?? - now i put it on the 0 position - no more comparing needed
3294  #if 0
3295  if(strat->sigdrop && rField_is_Ring(currRing))
3296  {
3297    for(k=strat->sl;k>=0;k--)
3298    {
3299      printf("\nsig[%i] = ",i);pWrite(strat->sig[k]);
3300      if(strat->sig[k] == NULL)
3301        strat->sig[k] = pCopy(strat->sig[k-1]);
3302    }
3303  }
3304  #endif
3305  #endif
3306  //Never do this - you will damage S
3307  //idSkipZeroes(strat->Shdl);
3308  //idPrint(strat->Shdl);
3309
3310  if ((strat->sbaOrder == 1 || strat->sbaOrder == 3) && sRing!=currRingOld)
3311  {
3312    rChangeCurrRing (currRingOld);
3313    F0          = idrMoveR (F1, sRing, currRing);
3314    strat->Shdl = idrMoveR_NoSort (strat->Shdl, sRing, currRing);
3315    rChangeCurrRing (sRing);
3316    if(rField_is_Ring(currRing))
3317      exitSba(strat);
3318    rChangeCurrRing (currRingOld);
3319    if(strat->tailRing == sRing)
3320      strat->tailRing = currRing;
3321    rDelete (sRing);
3322  }
3323  if(rField_is_Ring(currRing) && !strat->sigdrop)
3324    id_DelDiv(strat->Shdl, currRing);
3325  if(!rField_is_Ring(currRing))
3326    id_DelDiv(strat->Shdl, currRing);
3327  idSkipZeroes(strat->Shdl);
3328  idTest(strat->Shdl);
3329
3330#if SBA_PRINT_SIZE_G
3331  size_g   = IDELEMS(strat->Shdl);
3332#endif
3333#ifdef DEBUGF5
3334  printf("SIZE OF SHDL: %d\n",IDELEMS(strat->Shdl));
3335  int oo = 0;
3336  while (oo<IDELEMS(strat->Shdl))
3337  {
3338    printf(" %d.   ",oo+1);
3339    pWrite(pHead(strat->Shdl->m[oo]));
3340    oo++;
3341  }
3342#endif
3343#if SBA_PRINT_ZERO_REDUCTIONS
3344  printf("----------------------------------------------------------\n");
3345  printf("ZERO REDUCTIONS:            %ld\n",zeroreductions);
3346  zeroreductions  = 0;
3347#endif
3348#if SBA_PRINT_REDUCTION_STEPS
3349  printf("----------------------------------------------------------\n");
3350  printf("S-REDUCTIONS:               %ld\n",sba_reduction_steps);
3351#endif
3352#if SBA_PRINT_OPERATIONS
3353  printf("OPERATIONS:                 %ld\n",sba_operations);
3354#endif
3355#if SBA_PRINT_REDUCTION_STEPS
3356  printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
3357  printf("INTERREDUCTIONS:            %ld\n",sba_interreduction_steps);
3358#endif
3359#if SBA_PRINT_OPERATIONS
3360  printf("INTERREDUCTION OPERATIONS:  %ld\n",sba_interreduction_operations);
3361#endif
3362#if SBA_PRINT_REDUCTION_STEPS
3363  printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
3364  printf("ALL REDUCTIONS:             %ld\n",sba_reduction_steps+sba_interreduction_steps);
3365  sba_interreduction_steps  = 0;
3366  sba_reduction_steps       = 0;
3367#endif
3368#if SBA_PRINT_OPERATIONS
3369  printf("ALL OPERATIONS:             %ld\n",sba_operations+sba_interreduction_operations);
3370  sba_interreduction_operations = 0;
3371  sba_operations                = 0;
3372#endif
3373#if SBA_PRINT_SIZE_G
3374  printf("----------------------------------------------------------\n");
3375  printf("SIZE OF G:                  %d / %d\n",size_g,size_g_non_red);
3376  size_g          = 0;
3377  size_g_non_red  = 0;
3378#endif
3379#if SBA_PRINT_SIZE_SYZ
3380  printf("SIZE OF SYZ:                %ld\n",size_syz);
3381  printf("----------------------------------------------------------\n");
3382  size_syz  = 0;
3383#endif
3384#if SBA_PRINT_PRODUCT_CRITERION
3385  printf("PRODUCT CRITERIA:           %ld\n",product_criterion);
3386  product_criterion = 0;
3387#endif
3388  return (strat->Shdl);
3389}
3390
3391poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce)
3392{
3393  assume(q!=NULL);
3394  assume(!(idIs0(F)&&(Q==NULL))); // NF(q, std(0) in polynomial ring?
3395
3396// lazy_reduce flags: can be combined by |
3397//#define KSTD_NF_LAZY   1
3398  // do only a reduction of the leading term
3399//#define KSTD_NF_NONORM 4
3400  // only global: avoid normalization, return a multiply of NF
3401  poly   p;
3402
3403  //if ((idIs0(F))&&(Q==NULL))
3404  //  return pCopy(q); /*F=0*/
3405  //strat->ak = idRankFreeModule(F);
3406  /*- creating temp data structures------------------- -*/
3407  BITSET save1;
3408  SI_SAVE_OPT1(save1);
3409  si_opt_1|=Sy_bit(OPT_REDTAIL);
3410  initBuchMoraCrit(strat);
3411  strat->initEcart = initEcartBBA;
3412  strat->enterS = enterSBba;
3413#ifndef NO_BUCKETS
3414  strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing));
3415#endif
3416  /*- set S -*/
3417  strat->sl = -1;
3418  /*- init local data struct.---------------------------------------- -*/
3419  /*Shdl=*/initS(F,Q,strat);
3420  /*- compute------------------------------------------------------- -*/
3421  //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
3422  //{
3423  //  for (i=strat->sl;i>=0;i--)
3424  //    pNorm(strat->S[i]);
3425  //}
3426  kTest(strat);
3427  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
3428  if (BVERBOSE(23)) kDebugPrint(strat);
3429  int max_ind;
3430  p = redNF(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat);
3431  if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
3432  {
3433    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
3434    if (rField_is_Ring(currRing))
3435    {
3436      p = redtailBba_Z(p,max_ind,strat);
3437    }
3438    else
3439    {
3440      si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY);
3441      p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0);
3442    }
3443  }
3444  /*- release temp data------------------------------- -*/
3445  assume(strat->L==NULL); /* strat->L unused */
3446  assume(strat->B==NULL); /* strat->B unused */
3447  omFree(strat->sevS);
3448  omFree(strat->ecartS);
3449  assume(strat->T==NULL);//omfree(strat->T);
3450  assume(strat->sevT==NULL);//omfree(strat->sevT);
3451  assume(strat->R==NULL);//omfree(strat->R);
3452  omfree(strat->S_2_R);
3453  omfree(strat->fromQ);
3454  idDelete(&strat->Shdl);
3455  SI_RESTORE_OPT1(save1);
3456  if (TEST_OPT_PROT) PrintLn();
3457  return p;
3458}
3459
3460poly kNF2Bound (ideal F,ideal Q,poly q,int bound,kStrategy strat, int lazyReduce)
3461{
3462  assume(q!=NULL);
3463  assume(!(idIs0(F)&&(Q==NULL))); // NF(q, std(0) in polynomial ring?
3464
3465// lazy_reduce flags: can be combined by |
3466//#define KSTD_NF_LAZY   1
3467  // do only a reduction of the leading term
3468//#define KSTD_NF_NONORM 4
3469  // only global: avoid normalization, return a multiply of NF
3470  poly   p;
3471
3472  //if ((idIs0(F))&&(Q==NULL))
3473  //  return pCopy(q); /*F=0*/
3474  //strat->ak = idRankFreeModule(F);
3475  /*- creating temp data structures------------------- -*/
3476  BITSET save1;
3477  SI_SAVE_OPT1(save1);
3478  si_opt_1|=Sy_bit(OPT_REDTAIL);
3479  initBuchMoraCrit(strat);
3480  strat->initEcart = initEcartBBA;
3481  strat->enterS = enterSBba;
3482#ifndef NO_BUCKETS
3483  strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing));
3484#endif
3485  /*- set S -*/
3486  strat->sl = -1;
3487  /*- init local data struct.---------------------------------------- -*/
3488  /*Shdl=*/initS(F,Q,strat);
3489  /*- compute------------------------------------------------------- -*/
3490  //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
3491  //{
3492  //  for (i=strat->sl;i>=0;i--)
3493  //    pNorm(strat->S[i]);
3494  //}
3495  kTest(strat);
3496  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
3497  if (BVERBOSE(23)) kDebugPrint(strat);
3498  int max_ind;
3499  p = redNFBound(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat,bound);
3500  if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
3501  {
3502    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
3503    if (rField_is_Ring(currRing))
3504    {
3505      p = redtailBba_Z(p,max_ind,strat);
3506    }
3507    else
3508    {
3509      si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY);
3510      p = redtailBbaBound(p,max_ind,strat,bound,(lazyReduce & KSTD_NF_NONORM)==0);
3511      //p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0);
3512    }
3513  }
3514  /*- release temp data------------------------------- -*/
3515  assume(strat->L==NULL); /* strat->L unused */
3516  assume(strat->B==NULL); /* strat->B unused */
3517  omFree(strat->sevS);
3518  omFree(strat->ecartS);
3519  assume(strat->T==NULL);//omfree(strat->T);
3520  assume(strat->sevT==NULL);//omfree(strat->sevT);
3521  assume(strat->R==NULL);//omfree(strat->R);
3522  omfree(strat->S_2_R);
3523  omfree(strat->fromQ);
3524  idDelete(&strat->Shdl);
3525  SI_RESTORE_OPT1(save1);
3526  if (TEST_OPT_PROT) PrintLn();
3527  return p;
3528}
3529
3530ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce)
3531{
3532  assume(!idIs0(q));
3533  assume(!(idIs0(F)&&(Q==NULL)));
3534// lazy_reduce flags: can be combined by |
3535//#define KSTD_NF_LAZY   1
3536  // do only a reduction of the leading term
3537//#define KSTD_NF_NONORM 4
3538  // only global: avoid normalization, return a multiply of NF
3539  poly   p;
3540  int   i;
3541  ideal res;
3542  int max_ind;
3543
3544  //if (idIs0(q))
3545  //  return idInit(IDELEMS(q),si_max(q->rank,F->rank));
3546  //if ((idIs0(F))&&(Q==NULL))
3547  //  return idCopy(q); /*F=0*/
3548  //strat->ak = idRankFreeModule(F);
3549  /*- creating temp data structures------------------- -*/
3550  BITSET save1;
3551  SI_SAVE_OPT1(save1);
3552  si_opt_1|=Sy_bit(OPT_REDTAIL);
3553  initBuchMoraCrit(strat);
3554  strat->initEcart = initEcartBBA;
3555  strat->enterS = enterSBba;
3556  /*- set S -*/
3557  strat->sl = -1;
3558#ifndef NO_BUCKETS
3559  strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing));
3560#endif
3561  /*- init local data struct.---------------------------------------- -*/
3562  /*Shdl=*/initS(F,Q,strat);
3563  /*- compute------------------------------------------------------- -*/
3564  res=idInit(IDELEMS(q),si_max(q->rank,F->rank));
3565  si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY);
3566  for (i=IDELEMS(q)-1; i>=0; i--)
3567  {
3568    if (q->m[i]!=NULL)
3569    {
3570      if (TEST_OPT_PROT) { PrintS("r");mflush(); }
3571      p = redNF(pCopy(q->m[i]),max_ind,lazyReduce & KSTD_NF_NONORM,strat);
3572      if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
3573      {
3574        if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
3575        if (rField_is_Ring(currRing))
3576        {
3577          p = redtailBba_Z(p,max_ind,strat);
3578        }
3579        else
3580        {
3581          p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0);
3582        }
3583      }
3584      res->m[i]=p;
3585    }
3586    //else
3587    //  res->m[i]=NULL;
3588  }
3589  /*- release temp data------------------------------- -*/
3590  assume(strat->L==NULL); /* strat->L unused */
3591  assume(strat->B==NULL); /* strat->B unused */
3592  omFree(strat->sevS);
3593  omFree(strat->ecartS);
3594  assume(strat->T==NULL);//omfree(strat->T);
3595  assume(strat->sevT==NULL);//omfree(strat->sevT);
3596  assume(strat->R==NULL);//omfree(strat->R);
3597  omfree(strat->S_2_R);
3598  omfree(strat->fromQ);
3599  idDelete(&strat->Shdl);
3600  SI_RESTORE_OPT1(save1);
3601  if (TEST_OPT_PROT) PrintLn();
3602  return res;
3603}
3604
3605ideal kNF2Bound (ideal F,ideal Q,ideal q,int bound,kStrategy strat, int lazyReduce)
3606{
3607  assume(!idIs0(q));
3608  assume(!(idIs0(F)&&(Q==NULL)));
3609// lazy_reduce flags: can be combined by |
3610//#define KSTD_NF_LAZY   1
3611  // do only a reduction of the leading term
3612//#define KSTD_NF_NONORM 4
3613  // only global: avoid normalization, return a multiply of NF
3614  poly   p;
3615  int   i;
3616  ideal res;
3617  int max_ind;
3618
3619  //if (idIs0(q))
3620  //  return idInit(IDELEMS(q),si_max(q->rank,F->rank));
3621  //if ((idIs0(F))&&(Q==NULL))
3622  //  return idCopy(q); /*F=0*/
3623  //strat->ak = idRankFreeModule(F);
3624  /*- creating temp data structures------------------- -*/
3625  BITSET save1;
3626  SI_SAVE_OPT1(save1);
3627  si_opt_1|=Sy_bit(OPT_REDTAIL);
3628  initBuchMoraCrit(strat);
3629  strat->initEcart = initEcartBBA;
3630  strat->enterS = enterSBba;
3631  /*- set S -*/
3632  strat->sl = -1;
3633#ifndef NO_BUCKETS
3634  strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing));
3635#endif
3636  /*- init local data struct.---------------------------------------- -*/
3637  /*Shdl=*/initS(F,Q,strat);
3638  /*- compute------------------------------------------------------- -*/
3639  res=idInit(IDELEMS(q),si_max(q->rank,F->rank));
3640  si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY);
3641  for (i=IDELEMS(q)-1; i>=0; i--)
3642  {
3643    if (q->m[i]!=NULL)
3644    {
3645      if (TEST_OPT_PROT) { PrintS("r");mflush(); }
3646      p = redNFBound(pCopy(q->m[i]),max_ind,lazyReduce & KSTD_NF_NONORM,strat,bound);
3647      if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
3648      {
3649        if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
3650        if (rField_is_Ring(currRing))
3651        {
3652          p = redtailBba_Z(p,max_ind,strat);
3653        }
3654        else
3655        {
3656          p = redtailBbaBound(p,max_ind,strat,bound,(lazyReduce & KSTD_NF_NONORM)==0);
3657        }
3658      }
3659      res->m[i]=p;
3660    }
3661    //else
3662    //  res->m[i]=NULL;
3663  }
3664  /*- release temp data------------------------------- -*/
3665  assume(strat->L==NULL); /* strat->L unused */
3666  assume(strat->B==NULL); /* strat->B unused */
3667  omFree(strat->sevS);
3668  omFree(strat->ecartS);
3669  assume(strat->T==NULL);//omfree(strat->T);
3670  assume(strat->sevT==NULL);//omfree(strat->sevT);
3671  assume(strat->R==NULL);//omfree(strat->R);
3672  omfree(strat->S_2_R);
3673  omfree(strat->fromQ);
3674  idDelete(&strat->Shdl);
3675  SI_RESTORE_OPT1(save1);
3676  if (TEST_OPT_PROT) PrintLn();
3677  return res;
3678}
3679
3680#if F5C
3681/*********************************************************************
3682* interrreduction step of the signature-based algorithm:
3683* 1. all strat->S are interpreted as new critical pairs
3684* 2. those pairs need to be completely reduced by the usual (non sig-
3685*    safe) reduction process (including tail reductions)
3686* 3. strat->S and strat->T are completely new computed in these steps
3687********************************************************************/
3688void f5c (kStrategy strat, int& olddeg, int& minimcnt, int& hilbeledeg,
3689          int& hilbcount, int& srmax, int& lrmax, int& reduc, ideal Q,
3690          intvec *w,intvec *hilb )
3691{
3692  int Ll_old, red_result = 1;
3693  int pos  = 0;
3694  hilbeledeg=1;
3695  hilbcount=0;
3696  minimcnt=0;
3697  srmax = 0; // strat->sl is 0 at this point
3698  reduc = olddeg = lrmax = 0;
3699  // we cannot use strat->T anymore
3700  //cleanT(strat);
3701  //strat->tl = -1;
3702  Ll_old    = strat->Ll;
3703  while (strat->tl >= 0)
3704  {
3705    if(!strat->T[strat->tl].is_redundant)
3706    {
3707      LObject h;
3708      h.p = strat->T[strat->tl].p;
3709      h.tailRing = strat->T[strat->tl].tailRing;
3710      h.t_p = strat->T[strat->tl].t_p;
3711      if (h.p!=NULL)
3712      {
3713        if (currRing->OrdSgn==-1)
3714        {
3715          cancelunit(&h);
3716          deleteHC(&h, strat);
3717        }
3718        if (h.p!=NULL)
3719        {
3720          if (TEST_OPT_INTSTRATEGY)
3721          {
3722            //pContent(h.p);
3723            h.pCleardenom(); // also does a pContent
3724          }
3725          else
3726          {
3727            h.pNorm();
3728          }
3729          strat->initEcart(&h);
3730          if(rField_is_Ring(currRing))
3731            pos = posInLF5CRing(strat->L, Ll_old+1,strat->Ll,&h,strat);
3732          else
3733            pos = strat->Ll+1;
3734          h.sev = pGetShortExpVector(h.p);
3735          enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
3736        }
3737      }
3738    }
3739    strat->tl--;
3740  }
3741  strat->sl = -1;
3742#if 0
3743//#ifdef HAVE_TAIL_RING
3744  if(!rField_is_Ring())  // create strong gcd poly computes with tailring and S[i] ->to be fixed
3745    kStratInitChangeTailRing(strat);
3746#endif
3747  //enterpairs(pOne(),0,0,-1,strat,strat->tl);
3748  //strat->sl = -1;
3749  /* picks the last element from the lazyset L */
3750  while (strat->Ll>Ll_old)
3751  {
3752    strat->P = strat->L[strat->Ll];
3753    strat->Ll--;
3754//#if 1
3755#ifdef DEBUGF5
3756    PrintS("NEXT PAIR TO HANDLE IN INTERRED ALGORITHM\n");
3757    PrintS("-------------------------------------------------\n");
3758    pWrite(pHead(strat->P.p));
3759    pWrite(pHead(strat->P.p1));
3760    pWrite(pHead(strat->P.p2));
3761    printf("%d\n",strat->tl);
3762    PrintS("-------------------------------------------------\n");
3763#endif
3764    if (pNext(strat->P.p) == strat->tail)
3765    {
3766      // deletes the short spoly
3767      if (rField_is_Ring(currRing))
3768        pLmDelete(strat->P.p);
3769      else
3770        pLmFree(strat->P.p);
3771
3772      // TODO: needs some masking
3773      // TODO: masking needs to vanish once the signature
3774      //       sutff is completely implemented
3775      strat->P.p = NULL;
3776      poly m1 = NULL, m2 = NULL;
3777
3778      // check that spoly creation is ok
3779      while (strat->tailRing != currRing &&
3780          !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
3781      {
3782        assume(m1 == NULL && m2 == NULL);
3783        // if not, change to a ring where exponents are at least
3784        // large enough
3785        if (!kStratChangeTailRing(strat))
3786        {
3787          WerrorS("OVERFLOW...");
3788          break;
3789        }
3790      }
3791      // create the real one
3792      ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
3793          strat->tailRing, m1, m2, strat->R);
3794    }
3795    else if (strat->P.p1 == NULL)
3796    {
3797      if (strat->minim > 0)
3798        strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
3799      // for input polys, prepare reduction
3800      if(!rField_is_Ring(currRing))
3801        strat->P.PrepareRed(strat->use_buckets);
3802    }
3803
3804    if (strat->P.p == NULL && strat->P.t_p == NULL)
3805    {
3806      red_result = 0;
3807    }
3808    else
3809    {
3810      if (TEST_OPT_PROT)
3811        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
3812            &olddeg,&reduc,strat, red_result);
3813
3814#ifdef DEBUGF5
3815      PrintS("Poly before red: ");
3816      pWrite(strat->P.p);
3817#endif
3818      /* complete reduction of the element chosen from L */
3819      red_result = strat->red2(&strat->P,strat);
3820      if (errorreported)  break;
3821    }
3822
3823    if (strat->overflow)
3824    {
3825      if (!kStratChangeTailRing(strat)) { WerrorS("OVERFLOW.."); break;}
3826    }
3827
3828    // reduction to non-zero new poly
3829    if (red_result == 1)
3830    {
3831      // get the polynomial (canonicalize bucket, make sure P.p is set)
3832      strat->P.GetP(strat->lmBin);
3833      // in the homogeneous case FDeg >= pFDeg (sugar/honey)
3834      // but now, for entering S, T, we reset it
3835      // in the inhomogeneous case: FDeg == pFDeg
3836      if (strat->homog) strat->initEcart(&(strat->P));
3837
3838      /* statistic */
3839      if (TEST_OPT_PROT) PrintS("s");
3840      int pos;
3841      #if 1
3842      if(!rField_is_Ring(currRing))
3843        pos = posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
3844      else
3845        pos = posInSMonFirst(strat,strat->sl,strat->P.p);
3846      #else
3847      pos = posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
3848      #endif
3849      // reduce the tail and normalize poly
3850      // in the ring case we cannot expect LC(f) = 1,
3851      // therefore we call pContent instead of pNorm
3852#if F5CTAILRED
3853      BOOLEAN withT = TRUE;
3854      if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing)))
3855      {
3856        strat->P.pCleardenom();
3857        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
3858        {
3859          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
3860          strat->P.pCleardenom();
3861        }
3862      }
3863      else
3864      {
3865        strat->P.pNorm();
3866        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
3867          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
3868      }
3869#endif
3870#ifdef KDEBUG
3871      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
3872#endif /* KDEBUG */
3873
3874      // min_std stuff
3875      if ((strat->P.p1==NULL) && (strat->minim>0))
3876      {
3877        if (strat->minim==1)
3878        {
3879          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
3880          p_Delete(&strat->P.p2, currRing, strat->tailRing);
3881        }
3882        else
3883        {
3884          strat->M->m[minimcnt]=strat->P.p2;
3885          strat->P.p2=NULL;
3886        }
3887        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
3888          pNext(strat->M->m[minimcnt])
3889            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
3890                strat->tailRing, currRing,
3891                currRing->PolyBin);
3892        minimcnt++;
3893      }
3894
3895      // enter into S, L, and T
3896      // here we need to recompute new signatures, but those are trivial ones
3897      if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
3898      {
3899        enterT(strat->P, strat);
3900        // posInS only depends on the leading term
3901        strat->enterS(strat->P, pos, strat, strat->tl);
3902//#if 1
3903#ifdef DEBUGF5
3904        PrintS("ELEMENT ADDED TO GCURR DURING INTERRED: ");
3905        pWrite(pHead(strat->S[strat->sl]));
3906        pWrite(strat->sig[strat->sl]);
3907#endif
3908        if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
3909      }
3910      //      Print("[%d]",hilbeledeg);
3911      if (strat->P.lcm!=NULL)
3912#ifdef HAVE_RINGS
3913        pLmDelete(strat->P.lcm);
3914#else
3915      pLmFree(strat->P.lcm);
3916#endif
3917      if (strat->sl>srmax) srmax = strat->sl;
3918    }
3919    else
3920    {
3921      // adds signature of the zero reduction to
3922      // strat->syz. This is the leading term of
3923      // syzygy and can be used in syzCriterion()
3924      // the signature is added if and only if the
3925      // pair was not detected by the rewritten criterion in strat->red = redSig
3926      if (strat->P.p1 == NULL && strat->minim > 0)
3927      {
3928        p_Delete(&strat->P.p2, currRing, strat->tailRing);
3929      }
3930    }
3931
3932#ifdef KDEBUG
3933    memset(&(strat->P), 0, sizeof(strat->P));
3934#endif /* KDEBUG */
3935  }
3936  int cc = 0;
3937  while (cc<strat->tl+1)
3938  {
3939    strat->T[cc].sig        = pOne();
3940    p_SetComp(strat->T[cc].sig,cc+1,currRing);
3941    strat->T[cc].sevSig     = pGetShortExpVector(strat->T[cc].sig);
3942    strat->sig[cc]          = strat->T[cc].sig;
3943    strat->sevSig[cc]       = strat->T[cc].sevSig;
3944    strat->T[cc].is_sigsafe = TRUE;
3945    cc++;
3946  }
3947  strat->max_lower_index = strat->tl;
3948  // set current signature index of upcoming iteration step
3949  // NOTE:  this needs to be set here, as otherwise initSyzRules cannot compute
3950  //        the corresponding syzygy rules correctly
3951  strat->currIdx = cc+1;
3952  for (int cd=strat->Ll; cd>=0; cd--)
3953  {
3954    p_SetComp(strat->L[cd].sig,cc+1,currRing);
3955    cc++;
3956  }
3957  for (cc=strat->sl+1; cc<IDELEMS(strat->Shdl); ++cc)
3958    strat->Shdl->m[cc]  = NULL;
3959  #if 0
3960  printf("\nAfter f5c sorting\n");
3961  for(int i=0;i<=strat->sl;i++)
3962  pWrite(pHead(strat->S[i]));
3963  getchar();
3964  #endif
3965//#if 1
3966#if DEBUGF5
3967  PrintS("------------------- STRAT S ---------------------\n");
3968  cc = 0;
3969  while (cc<strat->tl+1)
3970  {
3971    pWrite(pHead(strat->S[cc]));
3972    pWrite(strat->sig[cc]);
3973    printf("- - - - - -\n");
3974    cc++;
3975  }
3976  PrintS("-------------------------------------------------\n");
3977  PrintS("------------------- STRAT T ---------------------\n");
3978  cc = 0;
3979  while (cc<strat->tl+1)
3980  {
3981    pWrite(pHead(strat->T[cc].p));
3982    pWrite(strat->T[cc].sig);
3983    printf("- - - - - -\n");
3984    cc++;
3985  }
3986  PrintS("-------------------------------------------------\n");
3987  PrintS("------------------- STRAT L ---------------------\n");
3988  cc = 0;
3989  while (cc<strat->Ll+1)
3990  {
3991    pWrite(pHead(strat->L[cc].p));
3992    pWrite(pHead(strat->L[cc].p1));
3993    pWrite(pHead(strat->L[cc].p2));
3994    pWrite(strat->L[cc].sig);
3995    printf("- - - - - -\n");
3996    cc++;
3997  }
3998  PrintS("-------------------------------------------------\n");
3999  printf("F5C DONE\nSTRAT SL: %d -- %d\n",strat->sl, strat->currIdx);
4000#endif
4001
4002}
4003#endif
4004
4005/* shiftgb stuff */
4006#ifdef HAVE_SHIFTBBA
4007
4008
4009ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, int uptodeg, int lV)
4010{
4011  int   red_result = 1;
4012  int   olddeg,reduc;
4013  int hilbeledeg=1,hilbcount=0,minimcnt=0;
4014  BOOLEAN withT = TRUE; // very important for shifts
4015
4016  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit, NO CHANGES */
4017  if(rField_is_Ring(currRing))
4018    initBuchMoraPosRing(strat);
4019  else
4020    initBuchMoraPos(strat); /*NO CHANGES YET: perhaps later*/
4021  initHilbCrit(F,Q,&hilb,strat); /*NO CHANGES*/
4022  initBbaShift(strat); /* DONE */
4023  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
4024  /*Shdl=*/initBuchMoraShift(F, Q,strat); /* updateS with no toT, i.e. no init for T */
4025  updateSShift(strat,uptodeg,lV); /* initializes T */
4026
4027  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
4028  reduc = olddeg = 0;
4029  strat->lV=lV;
4030
4031#ifndef NO_BUCKETS
4032  if (!TEST_OPT_NOT_BUCKETS)
4033    strat->use_buckets = 1;
4034#endif
4035
4036  // redtailBBa against T for inhomogenous input
4037  //  if (!TEST_OPT_OLDSTD)
4038  //    withT = ! strat->homog;
4039
4040  // strat->posInT = posInT_pLength;
4041  kTest_TS(strat);
4042
4043#ifdef HAVE_TAIL_RING
4044  kStratInitChangeTailRing(strat);
4045#endif
4046
4047  /* compute------------------------------------------------------- */
4048  while (strat->Ll >= 0)
4049  {
4050#ifdef KDEBUG
4051    if (TEST_OPT_DEBUG) messageSets(strat);
4052#endif
4053    if (strat->Ll== 0) strat->interpt=TRUE;
4054    if (TEST_OPT_DEGBOUND
4055        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
4056            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
4057    {
4058      /*
4059       *stops computation if
4060       * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
4061       *a predefined number Kstd1_deg
4062       */
4063      while ((strat->Ll >= 0)
4064        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
4065        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
4066            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))
4067        )
4068        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
4069      if (strat->Ll<0) break;
4070      else strat->noClearS=TRUE;
4071    }
4072    /* picks the last element from the lazyset L */
4073    strat->P = strat->L[strat->Ll];
4074    strat->Ll--;
4075
4076    if (pNext(strat->P.p) == strat->tail)
4077    {
4078      // deletes the short spoly
4079      pLmFree(strat->P.p);
4080      strat->P.p = NULL;
4081      poly m1 = NULL, m2 = NULL;
4082
4083      // check that spoly creation is ok
4084      while (strat->tailRing != currRing &&
4085             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
4086      {
4087        assume(m1 == NULL && m2 == NULL);
4088        // if not, change to a ring where exponents are at least
4089        // large enough
4090        kStratChangeTailRing(strat);
4091      }
4092      // create the real one
4093      ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
4094                    strat->tailRing, m1, m2, strat->R);
4095    }
4096    else if (strat->P.p1 == NULL)
4097    {
4098      if (strat->minim > 0)
4099        strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
4100      // for input polys, prepare reduction
4101      strat->P.PrepareRed(strat->use_buckets);
4102    }
4103
4104    poly qq;
4105
4106    /* here in the nonhomog case we shrink the new spoly */
4107
4108    if ( ! strat->homog)
4109    {
4110      strat->P.GetP(strat->lmBin); // because shifts are counted with .p structure
4111      /* in the nonhomog case we have to shrink the polynomial */
4112      assume(strat->P.t_p!=NULL);
4113      qq = p_Shrink(strat->P.t_p, lV, strat->tailRing); // direct shrink
4114      if (qq != NULL)
4115      {
4116         /* we're here if Shrink is nonzero */
4117        //         strat->P.p =  NULL;
4118        //        strat->P.Delete(); /* deletes P.p and P.t_p */ //error
4119        strat->P.p   =  NULL; // is not set by Delete
4120        strat->P.t_p =  qq;
4121        strat->P.GetP(strat->lmBin);
4122        // update sev and length
4123        strat->initEcart(&(strat->P));
4124        strat->P.sev = pGetShortExpVector(strat->P.p);
4125//         strat->P.FDeg = strat->P.pFDeg();
4126//         strat->P.length = strat->P.pLDeg();
4127//         strat->P.pLength =strat->P.GetpLength(); //pLength(strat->P.p);
4128      }
4129      else
4130      {
4131         /* Shrink is zero, like y(1)*y(2) - y(1)*y(3)*/
4132#ifdef KDEBUG
4133         if (TEST_OPT_DEBUG){PrintS("nonzero s shrinks to 0");PrintLn();}
4134#endif
4135         //         strat->P.Delete();  // cause error
4136         strat->P.p = NULL;
4137         strat->P.t_p = NULL;
4138           //         strat->P.p = NULL; // or delete strat->P.p ?
4139       }
4140    }
4141      /* end shrinking poly in the nonhomog case */
4142
4143    if (strat->P.p == NULL && strat->P.t_p == NULL)
4144    {
4145      red_result = 0;
4146    }
4147    else
4148    {
4149      if (TEST_OPT_PROT)
4150        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
4151                &olddeg,&reduc,strat, red_result);
4152
4153      /* reduction of the element chosen from L */
4154      red_result = strat->red(&strat->P,strat);
4155    }
4156
4157    // reduction to non-zero new poly
4158    if (red_result == 1)
4159    {
4160      /* statistic */
4161      if (TEST_OPT_PROT) PrintS("s");
4162
4163      // get the polynomial (canonicalize bucket, make sure P.p is set)
4164      strat->P.GetP(strat->lmBin);
4165
4166      int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
4167
4168      // reduce the tail and normalize poly
4169      if (TEST_OPT_INTSTRATEGY)
4170      {
4171        strat->P.pCleardenom();
4172        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
4173        {
4174          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
4175          strat->P.pCleardenom();
4176        }
4177      }
4178      else
4179      {
4180        strat->P.pNorm();
4181        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
4182          strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
4183      }
4184
4185      // here we must shrink again! and optionally reduce again
4186      // or build shrink into redtailBba!
4187
4188#ifdef KDEBUG
4189      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
4190#endif
4191
4192      // min_std stuff
4193      if ((strat->P.p1==NULL) && (strat->minim>0))
4194      {
4195        if (strat->minim==1)
4196        {
4197          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
4198          p_Delete(&strat->P.p2, currRing, strat->tailRing);
4199        }
4200        else
4201        {
4202          strat->M->m[minimcnt]=strat->P.p2;
4203          strat->P.p2=NULL;
4204        }
4205        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
4206          pNext(strat->M->m[minimcnt])
4207            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
4208                                           strat->tailRing, currRing,
4209                                           currRing->PolyBin);
4210        minimcnt++;
4211      }
4212
4213    /* here in the nonhomog case we shrink the reduced poly AGAIN */
4214
4215    if ( ! strat->homog)
4216    {
4217      strat->P.GetP(strat->lmBin); // because shifts are counted with .p structure
4218      /* assume strat->P.t_p != NULL */
4219      /* in the nonhomog case we have to shrink the polynomial */
4220      assume(strat->P.t_p!=NULL); // poly qq defined above
4221      qq = p_Shrink(strat->P.t_p, lV, strat->tailRing); // direct shrink
4222      if (qq != NULL)
4223      {
4224         /* we're here if Shrink is nonzero */
4225        //         strat->P.p =  NULL;
4226        //        strat->P.Delete(); /* deletes P.p and P.t_p */ //error
4227        strat->P.p   =  NULL; // is not set by Delete
4228        strat->P.t_p =  qq;
4229        strat->P.GetP(strat->lmBin);
4230        // update sev and length
4231        strat->initEcart(&(strat->P));
4232        strat->P.sev = pGetShortExpVector(strat->P.p);
4233      }
4234      else
4235      {
4236         /* Shrink is zero, like y(1)*y(2) - y(1)*y(3)*/
4237#ifdef PDEBUG
4238         if (TEST_OPT_DEBUG){PrintS("nonzero s shrinks to 0");PrintLn();}
4239#endif
4240         //         strat->P.Delete();  // cause error
4241         strat->P.p = NULL;
4242         strat->P.t_p = NULL;
4243           //         strat->P.p = NULL; // or delete strat->P.p ?
4244         goto     red_shrink2zero;
4245       }
4246    }
4247      /* end shrinking poly AGAIN in the nonhomog case */
4248
4249
4250      // enter into S, L, and T
4251      //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
4252      //        enterT(strat->P, strat); // this was here before Shift stuff
4253      //enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV); // syntax
4254      // the default value for atT = -1 as in bba
4255      /*   strat->P.GetP(); */
4256      // because shifts are counted with .p structure // done before, but ?
4257      enterTShift(strat->P,strat,-1,uptodeg, lV);
4258      enterpairsShift(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl,uptodeg,lV);
4259      //      enterpairsShift(vw,strat->sl,strat->P.ecart,pos,strat, strat->tl,uptodeg,lV);
4260      // posInS only depends on the leading term
4261      strat->enterS(strat->P, pos, strat, strat->tl);
4262
4263      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
4264//      Print("[%d]",hilbeledeg);
4265      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
4266    }
4267    else
4268    {
4269    red_shrink2zero:
4270      if (strat->P.p1 == NULL && strat->minim > 0)
4271      {
4272        p_Delete(&strat->P.p2, currRing, strat->tailRing);
4273      }
4274    }
4275#ifdef KDEBUG
4276    memset(&(strat->P), 0, sizeof(strat->P));
4277#endif
4278    kTest_TS(strat);
4279  }
4280#ifdef KDEBUG
4281  if (TEST_OPT_DEBUG) messageSets(strat);
4282#endif
4283  /* complete reduction of the standard basis--------- */
4284  /*  shift case: look for elt's in S such that they are divisible by elt in T */
4285  //  if (TEST_OPT_SB_1)
4286  if (TEST_OPT_REDSB)
4287  {
4288    int k=0;
4289    int j=-1;
4290    while(k<=strat->sl)
4291    {
4292//       loop
4293//       {
4294//         if (j>=k) break;
4295//         clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
4296//         j++;
4297//       }
4298      LObject Ln (strat->S[k],currRing, strat->tailRing);
4299      Ln.SetShortExpVector();
4300      j = kFindDivisibleByInT(strat, &Ln, j+1);
4301      if (j<0) {  k++; j=-1;}
4302      else
4303      {
4304        if ( pLmCmp(strat->S[k],strat->T[j].p) == 0)
4305        {
4306          j = kFindDivisibleByInT(strat, &Ln, j+1);
4307          if (j<0) {  k++; j=-1;}
4308          else
4309          {
4310            deleteInS(k,strat);
4311          }
4312        }
4313        else
4314        {
4315          deleteInS(k,strat);
4316        }
4317      }
4318    }
4319  }
4320
4321  if (TEST_OPT_REDSB)
4322  {    completeReduce(strat, TRUE); //shift: withT = TRUE
4323    if (strat->completeReduce_retry)
4324    {
4325      // completeReduce needed larger exponents, retry
4326      // to reduce with S (instead of T)
4327      // and in currRing (instead of strat->tailRing)
4328#ifdef HAVE_TAIL_RING
4329      if(currRing->bitmask>strat->tailRing->bitmask)
4330      {
4331        strat->completeReduce_retry=FALSE;
4332        cleanT(strat);strat->tailRing=currRing;
4333        int i;
4334        for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
4335        completeReduce(strat);
4336      }
4337      if (strat->completeReduce_retry)
4338#endif
4339        Werror("exponent bound is %ld",currRing->bitmask);
4340    }
4341  }
4342  else if (TEST_OPT_PROT) PrintLn();
4343
4344  /* release temp data-------------------------------- */
4345  exitBuchMora(strat);
4346//  if (TEST_OPT_WEIGHTM)
4347//  {
4348//    pRestoreDegProcs(currRing,pFDegOld, pLDegOld);
4349//    if (ecartWeights)
4350//    {
4351//      omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
4352//      ecartWeights=NULL;
4353//    }
4354//  }
4355  if (TEST_OPT_PROT) messageStat(hilbcount,strat);
4356  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
4357  return (strat->Shdl);
4358}
4359
4360
4361ideal freegb(ideal I, int uptodeg, int lVblock)
4362{
4363  /* todo main call */
4364
4365  /* assume: ring is prepared, ideal is copied into shifted ring */
4366  /* uptodeg and lVblock are correct - test them! */
4367
4368  /* check whether the ideal is in V */
4369
4370//  if (0)
4371  if (! ideal_isInV(I,lVblock) )
4372  {
4373    WerrorS("The input ideal contains incorrectly encoded elements! ");
4374    return(NULL);
4375  }
4376
4377  //  kStrategy strat = new skStrategy;
4378  /* ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, int uptodeg, int lV) */
4379  /* at the moment:
4380- no quotient (check)
4381- no *w, no *hilb
4382  */
4383  /* ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp,
4384     int newIdeal, intvec *vw) */
4385  ideal RS = kStdShift(I,NULL, testHomog, NULL,NULL,0,0,NULL, uptodeg, lVblock);
4386    //bbaShift(I,NULL, NULL, NULL, strat, uptodeg, lVblock);
4387  idSkipZeroes(RS);
4388  return(RS);
4389}
4390
4391/*2
4392*reduces h with elements from T choosing  the first possible
4393* element in t with respect to the given pDivisibleBy
4394*/
4395int redFirstShift (LObject* h,kStrategy strat)
4396{
4397  if (h->IsNull()) return 0;
4398
4399  int at, reddeg,d;
4400  int pass = 0;
4401  int j = 0;
4402
4403  if (! strat->homog)
4404  {
4405    d = h->GetpFDeg() + h->ecart;
4406    reddeg = strat->LazyDegree+d;
4407  }
4408  h->SetShortExpVector();
4409  loop
4410  {
4411    j = kFindDivisibleByInT(strat, h);
4412    if (j < 0)
4413    {
4414      h->SetDegStuffReturnLDeg(strat->LDegLast);
4415      return 1;
4416    }
4417
4418    if (!TEST_OPT_INTSTRATEGY)
4419      strat->T[j].pNorm();
4420#ifdef KDEBUG
4421    if (TEST_OPT_DEBUG)
4422    {
4423      PrintS("reduce ");
4424      h->wrp();
4425      PrintS(" with ");
4426      strat->T[j].wrp();
4427    }
4428#endif
4429    ksReducePoly(h, &(strat->T[j]), strat->kNoetherTail(), NULL, strat);
4430    if (!h->IsNull())
4431    {
4432      poly qq=p_Shrink(h->GetTP(),strat->lV,strat->tailRing);
4433      h->p=NULL;
4434      h->t_p=qq;
4435      if (qq!=NULL) h->GetP(strat->lmBin);
4436    }
4437
4438#ifdef KDEBUG
4439    if (TEST_OPT_DEBUG)
4440    {
4441      PrintS("\nto ");
4442      wrp(h->p);
4443      PrintLn();
4444    }
4445#endif
4446    if (h->IsNull())
4447    {
4448      if (h->lcm!=NULL) pLmFree(h->lcm);
4449      h->Clear();
4450      return 0;
4451    }
4452    h->SetShortExpVector();
4453
4454#if 0
4455    if ((strat->syzComp!=0) && !strat->honey)
4456    {
4457      if ((strat->syzComp>0) &&
4458          (h->Comp() > strat->syzComp))
4459      {
4460        assume(h->MinComp() > strat->syzComp);
4461#ifdef KDEBUG
4462        if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
4463#endif
4464        if (strat->homog)
4465          h->SetDegStuffReturnLDeg(strat->LDegLast);
4466        return -2;
4467      }
4468    }
4469#endif
4470    if (!strat->homog)
4471    {
4472      if (!TEST_OPT_OLDSTD && strat->honey)
4473      {
4474        h->SetpFDeg();
4475        if (strat->T[j].ecart <= h->ecart)
4476          h->ecart = d - h->GetpFDeg();
4477        else
4478          h->ecart = d - h->GetpFDeg() + strat->T[j].ecart - h->ecart;
4479
4480        d = h->GetpFDeg() + h->ecart;
4481      }
4482      else
4483        d = h->SetDegStuffReturnLDeg(strat->LDegLast);
4484      /*- try to reduce the s-polynomial -*/
4485      pass++;
4486      /*
4487       *test whether the polynomial should go to the lazyset L
4488       *-if the degree jumps
4489       *-if the number of pre-defined reductions jumps
4490       */
4491      if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
4492          && ((d >= reddeg) || (pass > strat->LazyPass)))
4493      {
4494        h->SetLmCurrRing();
4495        if (strat->posInLDependsOnLength)
4496          h->SetLength(strat->length_pLength);
4497        at = strat->posInL(strat->L,strat->Ll,h,strat);
4498        if (at <= strat->Ll)
4499        {
4500          //int dummy=strat->sl;
4501          /*          if (kFindDivisibleByInS(strat,&dummy, h) < 0) */
4502          //if (kFindDivisibleByInT(strat->T,strat->sevT, dummy, h) < 0)
4503          if (kFindDivisibleByInT(strat, h) < 0)
4504            return 1;
4505          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
4506#ifdef KDEBUG
4507          if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
4508#endif
4509          h->Clear();
4510          return -1;
4511        }
4512      }
4513      if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
4514      {
4515        reddeg = d+1;
4516        Print(".%d",d);mflush();
4517      }
4518    }
4519  }
4520}
4521
4522void initBbaShift(kStrategy strat)
4523{
4524 /* setting global variables ------------------- */
4525  strat->enterS = enterSBba; /* remains as is, we change enterT! */
4526
4527  strat->red = redFirstShift; /* no redHomog ! */
4528
4529  if (currRing->pLexOrder && strat->honey)
4530    strat->initEcart = initEcartNormal;
4531  else
4532    strat->initEcart = initEcartBBA;
4533  if (strat->honey)
4534    strat->initEcartPair = initEcartPairMora;
4535  else
4536    strat->initEcartPair = initEcartPairBba;
4537//  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
4538//  {
4539//    //interred  machen   Aenderung
4540//    pFDegOld=currRing->pFDeg;
4541//    pLDegOld=pLDeg;
4542//    //h=ggetid("ecart");
4543//    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
4544//    //{
4545//    //  ecartWeights=iv2array(IDINTVEC(h));
4546//    //}
4547//    //else
4548//    {
4549//      ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
4550//      /*uses automatic computation of the ecartWeights to set them*/
4551//      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights,currRing);
4552//    }
4553//    pRestoreDegProcs(currRing,totaldegreeWecart, maxdegreeWecart);
4554//    if (TEST_OPT_PROT)
4555//    {
4556//      for(int i=1; i<=rVar(currRing); i++)
4557//        Print(" %d",ecartWeights[i]);
4558//      PrintLn();
4559//      mflush();
4560//    }
4561//  }
4562}
4563#endif
Note: See TracBrowser for help on using the repository browser.