kstd1.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT:
6 */
7 
8 // TODO: why the following is here instead of mod2.h???
9 
10 
11 // define if buckets should be used
12 #define MORA_USE_BUCKETS
13 
14 //#define ADIDEBUG 0
15 //#define ADIDEBUG_NF 0
16 #define PRE_INTEGER_CHECK 0
17 
18 #include <kernel/mod2.h>
19 
20 #include <omalloc/omalloc.h>
21 
22 #include <misc/options.h>
23 #include <misc/intvec.h>
24 
25 #include <polys/weight.h>
26 #include <kernel/polys.h>
27 
28 #include <kernel/GBEngine/kutil.h>
29 #include <kernel/GBEngine/kstd1.h>
30 #include <kernel/GBEngine/khstd.h>
32 //#include "cntrlc.h"
33 #include <kernel/ideals.h>
34 //#include "../Singular/ipid.h"
35 
36 //#include "ipprint.h"
37 
38 #ifdef HAVE_PLURAL
39 #include <polys/nc/nc.h>
40 #include <polys/nc/sca.h>
41 #include <kernel/GBEngine/nc.h>
42 #endif
43 
45 
46 
47 /* the list of all options which give a warning by test */
49  |Sy_bit(OPT_REDSB) /* 1 */
50  |Sy_bit(OPT_NOT_SUGAR) /* 3 */
51  |Sy_bit(OPT_INTERRUPT) /* 4 */
52  |Sy_bit(OPT_SUGARCRIT) /* 5 */
55  |Sy_bit(OPT_FASTHC) /* 10 */
56  |Sy_bit(OPT_INTSTRATEGY) /* 26 */
57  |Sy_bit(OPT_INFREDTAIL) /* 28 */
58  |Sy_bit(OPT_NOTREGULARITY) /* 30 */
59  |Sy_bit(OPT_WEIGHTM); /* 31 */
60 
61 /* the list of all options which may be used by option and test */
62 /* defintion of ALL options: libpolys/misc/options.h */
64  |Sy_bit(1)
65  |Sy_bit(2) // obachman 10/00: replaced by notBucket
66  |Sy_bit(3)
67  |Sy_bit(4)
68  |Sy_bit(5)
69  |Sy_bit(6)
70 // |Sy_bit(7) obachman 11/00 tossed: 12/00 used for redThrough
71  |Sy_bit(7) // OPT_REDTHROUGH
72  |Sy_bit(8) // obachman 11/00 tossed -> motsak 2011 experimental: OPT_NO_SYZ_MINIM
73  |Sy_bit(9)
74  |Sy_bit(10)
75  |Sy_bit(11)
76  |Sy_bit(12)
77  |Sy_bit(13)
78  |Sy_bit(14)
79  |Sy_bit(15)
80  |Sy_bit(16)
81  |Sy_bit(17)
82  |Sy_bit(18)
83  |Sy_bit(19)
84 // |Sy_bit(20) obachman 11/00 tossed: 12/00 used for redOldStd
86  |Sy_bit(21)
87  |Sy_bit(22)
88  /*|Sy_bit(23)*/
89  /*|Sy_bit(24)*/
92  |Sy_bit(27)
93  |Sy_bit(28)
94  |Sy_bit(29)
95  |Sy_bit(30)
96  |Sy_bit(31);
97 
98 //static BOOLEAN posInLOldFlag;
99  /*FALSE, if posInL == posInL10*/
100 // returns TRUE if mora should use buckets, false otherwise
102 
104 {
105 // if (strat->ak == 0 && !rIsSyzIndexRing(currRing))
106  strat->length_pLength = TRUE;
107 // else
108 // strat->length_pLength = FALSE;
109 
110  if ((ldeg == pLDeg0c /*&& !rIsSyzIndexRing(currRing)*/) ||
111  (ldeg == pLDeg0 && strat->ak == 0))
112  {
113  strat->LDegLast = TRUE;
114  }
115  else
116  {
117  strat->LDegLast = FALSE;
118  }
119 }
120 
121 
122 static int doRed (LObject* h, TObject* with,BOOLEAN intoT,kStrategy strat, bool redMoraNF)
123 {
124  int ret;
125 #if KDEBUG > 0
126  kTest_L(h);
127  kTest_T(with);
128 #endif
129  // Hmmm ... why do we do this -- polys from T should already be normalized
131  with->pNorm();
132 #ifdef KDEBUG
133  if (TEST_OPT_DEBUG)
134  {
135  PrintS("reduce ");h->wrp();PrintS(" with ");with->wrp();PrintLn();
136  }
137 #endif
138  if (intoT)
139  {
140  // need to do it exacly like this: otherwise
141  // we might get errors
142  LObject L= *h;
143  L.Copy();
144  h->GetP();
145  h->length=h->pLength=pLength(h->p);
146  ret = ksReducePoly(&L, with, strat->kNoetherTail(), NULL, strat);
147  if (ret)
148  {
149  if (ret < 0) return ret;
150  if (h->tailRing != strat->tailRing)
151  h->ShallowCopyDelete(strat->tailRing,
152  pGetShallowCopyDeleteProc(h->tailRing,
153  strat->tailRing));
154  }
155  if(redMoraNF && (rField_is_Ring(currRing)))
156  enterT_strong(*h,strat);
157  else
158  enterT(*h,strat);
159  *h = L;
160  }
161  else
162  ret = ksReducePoly(h, with, strat->kNoetherTail(), NULL, strat);
163 #ifdef KDEBUG
164  if (TEST_OPT_DEBUG)
165  {
166  PrintS("to ");h->wrp();PrintLn();
167  }
168 #endif
169  return ret;
170 }
171 
173 {
174  int i,at,ei,li,ii;
175  int j = 0;
176  int pass = 0;
177  long d,reddeg;
178 
179  d = h->GetpFDeg()+ h->ecart;
180  reddeg = strat->LazyDegree+d;
181  h->SetShortExpVector();
182  loop
183  {
184  j = kFindDivisibleByInT(strat, h);
185  if (j < 0)
186  {
187  if (strat->honey) h->SetLength(strat->length_pLength);
188  return 1;
189  }
190 
191  ei = strat->T[j].ecart;
192  ii = j;
193 
194  if (ei > h->ecart && ii < strat->tl)
195  {
196  li = strat->T[j].length;
197  // the polynomial to reduce with (up to the moment) is;
198  // pi with ecart ei and length li
199  // look for one with smaller ecart
200  i = j;
201  loop
202  {
203  /*- takes the first possible with respect to ecart -*/
204  i++;
205 #if 1
206  if (i > strat->tl) break;
207  if ((strat->T[i].ecart < ei || (strat->T[i].ecart == ei &&
208  strat->T[i].length < li))
209  &&
210  p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], h->GetLmTailRing(), ~h->sev, strat->tailRing))
211 #else
212  j = kFindDivisibleByInT(strat, h, i);
213  if (j < 0) break;
214  i = j;
215  if (strat->T[i].ecart < ei || (strat->T[i].ecart == ei &&
216  strat->T[i].length < li))
217 #endif
218  {
219  // the polynomial to reduce with is now
220  ii = i;
221  ei = strat->T[i].ecart;
222  if (ei <= h->ecart) break;
223  li = strat->T[i].length;
224  }
225  }
226  }
227 
228  // end of search: have to reduce with pi
229  if (ei > h->ecart)
230  {
231  // It is not possible to reduce h with smaller ecart;
232  // if possible h goes to the lazy-set L,i.e
233  // if its position in L would be not the last one
234  strat->fromT = TRUE;
235  if (!TEST_OPT_REDTHROUGH && strat->Ll >= 0) /*- L is not empty -*/
236  {
237  h->SetLmCurrRing();
238  if (strat->honey && strat->posInLDependsOnLength)
239  h->SetLength(strat->length_pLength);
240  assume(h->FDeg == h->pFDeg());
241  at = strat->posInL(strat->L,strat->Ll,h,strat);
242  if (at <= strat->Ll)
243  {
244  /*- h will not become the next element to reduce -*/
245  enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
246 #ifdef KDEBUG
247  if (TEST_OPT_DEBUG) Print(" ecart too big; -> L%d\n",at);
248 #endif
249  h->Clear();
250  strat->fromT = FALSE;
251  return -1;
252  }
253  }
254  }
255 
256  // now we finally can reduce
257  doRed(h,&(strat->T[ii]),strat->fromT,strat,FALSE);
258  strat->fromT=FALSE;
259 
260  // are we done ???
261  if (h->IsNull())
262  {
264  if (h->lcm!=NULL) pLmFree(h->lcm);
265  h->Clear();
266  return 0;
267  }
268 
269  // NO!
270  h->SetShortExpVector();
271  h->SetpFDeg();
272  if (strat->honey)
273  {
274  if (ei <= h->ecart)
275  h->ecart = d-h->GetpFDeg();
276  else
277  h->ecart = d-h->GetpFDeg()+ei-h->ecart;
278  }
279  else
280  // this has the side effect of setting h->length
281  h->ecart = h->pLDeg(strat->LDegLast) - h->GetpFDeg();
282 #if 0
283  if (strat->syzComp!=0)
284  {
285  if ((strat->syzComp>0) && (h->Comp() > strat->syzComp))
286  {
287  assume(h->MinComp() > strat->syzComp);
288  if (strat->honey) h->SetLength();
289 #ifdef KDEBUG
290  if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
291 #endif
292  return -2;
293  }
294  }
295 #endif
296  /*- try to reduce the s-polynomial -*/
297  pass++;
298  d = h->GetpFDeg()+h->ecart;
299  /*
300  *test whether the polynomial should go to the lazyset L
301  *-if the degree jumps
302  *-if the number of pre-defined reductions jumps
303  */
304  if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
305  && ((d >= reddeg) || (pass > strat->LazyPass)))
306  {
307  h->SetLmCurrRing();
308  if (strat->honey && strat->posInLDependsOnLength)
309  h->SetLength(strat->length_pLength);
310  assume(h->FDeg == h->pFDeg());
311  at = strat->posInL(strat->L,strat->Ll,h,strat);
312  if (at <= strat->Ll)
313  {
314  int dummy=strat->sl;
315  if (kFindDivisibleByInS(strat, &dummy, h) < 0)
316  {
317  if (strat->honey && !strat->posInLDependsOnLength)
318  h->SetLength(strat->length_pLength);
319  return 1;
320  }
321  enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
322 #ifdef KDEBUG
323  if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
324 #endif
325  h->Clear();
326  return -1;
327  }
328  }
329  else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
330  {
331  Print(".%ld",d);mflush();
332  reddeg = d+1;
333  if (h->pTotalDeg()+h->ecart >= (int)strat->tailRing->bitmask)
334  {
335  strat->overflow=TRUE;
336  //Print("OVERFLOW in redEcart d=%ld, max=%ld",d,strat->tailRing->bitmask);
337  h->GetP();
338  at = strat->posInL(strat->L,strat->Ll,h,strat);
339  enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
340  h->Clear();
341  return -1;
342  }
343  }
344  }
345 }
346 
347 #ifdef HAVE_RINGS
349 {
350  int i,at,ei,li,ii;
351  int j = 0;
352  int pass = 0;
353  long d,reddeg;
354 
355 
356 #ifdef ADIDEBUG_NF
357  int iii;
358  PrintS("\n---------------------------- NEW REDRILOC COMPUTATION ----------------------------\n");
359  PrintS(" The pair h :\n");
360  PrintS("\n p1 = "); p_Write(h->p1,strat->tailRing);
361  PrintS("\n p2 = "); p_Write(h->p2,strat->tailRing);
362  PrintS("\n p = "); p_Write(h->p,strat->tailRing);
363  PrintS("\n The actual reducer T is: ");
364  if(strat->tl<0)
365  {PrintS(" Empty.\n");}
366  else
367  {
368  for (iii=0;iii<=strat->tl;iii++)
369  {
370  Print("\n T[%i] = ",iii);p_Write(strat->T[iii].p,strat->tailRing);
371  }
372  }
373 #endif /* ADIDEBUG_NF */
374 
375  d = h->GetpFDeg()+ h->ecart;
376  reddeg = strat->LazyDegree+d;
377  h->SetShortExpVector();
378 #ifdef ADIDEBUG_NF
379  Print("\n Searching for a poly in T that divides h (of ecart %i) ...\n",h->ecart);
380 #endif
381  loop
382  {
383  j = kFindDivisibleByInT(strat, h);
384 #ifdef ADIDEBUG_NF
385  if(j != -1)
386  {
387  ei = strat->T[j].ecart;
388  Print("\n Found one: T[%i] of ecart %i: ",j,ei);
389  p_Write(strat->T[j].p,strat->tailRing);
390  PrintS("\n Try to find another with smaller ecart:\n");
391  }
392  else
393  {
394  PrintS("\n No poly in T divides h.\n");
395  }
396  //getchar();
397 #endif
398  if (j < 0)
399  {
400  // over ZZ: cleanup coefficients by complete reduction with monomials
401  postReduceByMon(h, strat);
402  if(h->p == NULL)
403  {
404  if (h->lcm!=NULL) pLmDelete(h->lcm);
405  h->Clear();
406  return 0;
407  }
408  if (strat->honey) h->SetLength(strat->length_pLength);
409  if(strat->tl >= 0)
410  h->i_r1 = strat->tl;
411  else
412  h->i_r1 = -1;
413  if (h->GetLmTailRing() == NULL)
414  {
415  if (h->lcm!=NULL) pLmDelete(h->lcm);
416  h->Clear();
417  return 0;
418  }
419  return 1;
420  }
421 
422  ei = strat->T[j].ecart;
423  ii = j;
424 #ifdef ADIDEBUG_NF
425  iii=ii;
426 #endif
427  if (ei > h->ecart && ii < strat->tl)
428  {
429  li = strat->T[j].length;
430  // the polynomial to reduce with (up to the moment) is;
431  // pi with ecart ei and length li
432  // look for one with smaller ecart
433  i = j;
434  loop
435  {
436  /*- takes the first possible with respect to ecart -*/
437  i++;
438 #if 1
439  if (i > strat->tl) break;
440  if ((strat->T[i].ecart < ei || (strat->T[i].ecart == ei &&
441  strat->T[i].length < li))
442  &&
443  p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], h->GetLmTailRing(), ~h->sev, strat->tailRing)
444  &&
445  n_DivBy(h->p->coef,strat->T[i].p->coef,strat->tailRing->cf))
446 #else
447  j = kFindDivisibleByInT(strat, h, i);
448  if (j < 0) break;
449  i = j;
450  if (strat->T[i].ecart < ei || (strat->T[i].ecart == ei &&
451  strat->T[i].length < li))
452 #endif
453  {
454  // the polynomial to reduce with is now
455  #ifdef ADIDEBUG_NF
456  printf("\n Intermidiate one, h.ecart = %i < ecart = %i < ei = %i: ",h->ecart,strat->T[i].ecart, ei);
457  pWrite(strat->T[i].p);
458  #endif
459  ii = i;
460  ei = strat->T[i].ecart;
461  if (ei <= h->ecart) break;
462  li = strat->T[i].length;
463  }
464  }
465 
466 #ifdef ADIDEBUG_NF
467  if(iii == ii)
468  {
469  PrintS("\n None was found.\n");
470  }
471  else
472  {
473  Print("\n A better one (ecart = %i): T[%i] = ",ei,ii);
474  p_Write(strat->T[ii].p,strat->tailRing);
475  PrintLn();
476  }
477 #endif
478  }
479 
480  // end of search: have to reduce with pi
481  if (ei > h->ecart)
482  {
483  #ifdef ADIDEBUG_NF
484  printf("\nHAD TO REDUCE WITH BIGGER ECART!!!\n");
485  #endif
486  // It is not possible to reduce h with smaller ecart;
487  // if possible h goes to the lazy-set L,i.e
488  // if its position in L would be not the last one
489  strat->fromT = TRUE;
490  if (!TEST_OPT_REDTHROUGH && strat->Ll >= 0) /*- L is not empty -*/
491  {
492  h->SetLmCurrRing();
493  if (strat->honey && strat->posInLDependsOnLength)
494  h->SetLength(strat->length_pLength);
495  assume(h->FDeg == h->pFDeg());
496  at = strat->posInL(strat->L,strat->Ll,h,strat);
497  if (at <= strat->Ll && pLmCmp(h->p, strat->L[strat->Ll].p) != 0 && !nEqual(h->p->coef, strat->L[strat->Ll].p->coef))
498  {
499  /*- h will not become the next element to reduce -*/
500  enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
501  #ifdef KDEBUG
502  if (TEST_OPT_DEBUG) Print(" ecart too big; -> L%d\n",at);
503  #endif
504  h->Clear();
505  strat->fromT = FALSE;
506  return -1;
507  }
508  }
509  doRed(h,&(strat->T[ii]),strat->fromT,strat,TRUE);
510  }
511  else
512  {
513  // now we finally can reduce
514  doRed(h,&(strat->T[ii]),strat->fromT,strat,FALSE);
515  }
516  strat->fromT=FALSE;
517  // are we done ???
518  if (h->IsNull())
519  {
520  #ifdef ADIDEBUG_NF
521  printf("\nReduced to 0. Exit\n");
522  #endif
523  if (h->lcm!=NULL) pLmDelete(h->lcm);
524  h->Clear();
525  return 0;
526  }
527 
528  // NO!
529  h->SetShortExpVector();
530  h->SetpFDeg();
531  if (strat->honey)
532  {
533  if (ei <= h->ecart)
534  h->ecart = d-h->GetpFDeg();
535  else
536  h->ecart = d-h->GetpFDeg()+ei-h->ecart;
537  }
538  else
539  // this has the side effect of setting h->length
540  h->ecart = h->pLDeg(strat->LDegLast) - h->GetpFDeg();
541  #ifdef ADIDEBUG_NF
542  printf("\n Partial Reduced (ecart %i) h = ",h->ecart);p_Write(h->p,strat->tailRing);
543  PrintLn();
544  #endif
545  /*- try to reduce the s-polynomial -*/
546  pass++;
547  d = h->GetpFDeg()+h->ecart;
548  /*
549  *test whether the polynomial should go to the lazyset L
550  *-if the degree jumps
551  *-if the number of pre-defined reductions jumps
552  */
553  if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
554  && ((d >= reddeg) || (pass > strat->LazyPass)))
555  {
556  h->SetLmCurrRing();
557  if (strat->honey && strat->posInLDependsOnLength)
558  h->SetLength(strat->length_pLength);
559  assume(h->FDeg == h->pFDeg());
560  at = strat->posInL(strat->L,strat->Ll,h,strat);
561  if (at <= strat->Ll)
562  {
563  int dummy=strat->sl;
564  if (kFindDivisibleByInS(strat, &dummy, h) < 0)
565  {
566  if (strat->honey && !strat->posInLDependsOnLength)
567  h->SetLength(strat->length_pLength);
568  return 1;
569  }
570  enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
571 #ifdef KDEBUG
572  if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
573 #endif
574  h->Clear();
575  return -1;
576  }
577  }
578  else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
579  {
580  Print(".%ld",d);mflush();
581  reddeg = d+1;
582  if (h->pTotalDeg()+h->ecart >= (int)strat->tailRing->bitmask)
583  {
584  strat->overflow=TRUE;
585  //Print("OVERFLOW in redEcart d=%ld, max=%ld",d,strat->tailRing->bitmask);
586  h->GetP();
587  at = strat->posInL(strat->L,strat->Ll,h,strat);
588  enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
589  h->Clear();
590  return -1;
591  }
592  }
593  }
594 }
595 #endif
596 
597 /*2
598 *reduces h with elements from T choosing the first possible
599 * element in t with respect to the given pDivisibleBy
600 */
602 {
603  if (h->IsNull()) return 0;
604 
605  int at;
606  long reddeg,d;
607  int pass = 0;
608  int j = 0;
609 
610  if (! strat->homog)
611  {
612  d = h->GetpFDeg() + h->ecart;
613  reddeg = strat->LazyDegree+d;
614  }
615  h->SetShortExpVector();
616  loop
617  {
618  j = kFindDivisibleByInT(strat, h);
619  if (j < 0)
620  {
621  h->SetDegStuffReturnLDeg(strat->LDegLast);
622  return 1;
623  }
624 
626  strat->T[j].pNorm();
627 #ifdef KDEBUG
628  if (TEST_OPT_DEBUG)
629  {
630  PrintS("reduce ");
631  h->wrp();
632  PrintS(" with ");
633  strat->T[j].wrp();
634  }
635 #endif
636  ksReducePoly(h, &(strat->T[j]), strat->kNoetherTail(), NULL, strat);
637 #ifdef KDEBUG
638  if (TEST_OPT_DEBUG)
639  {
640  PrintS(" to ");
641  wrp(h->p);
642  PrintLn();
643  }
644 #endif
645  if (h->IsNull())
646  {
648  if (h->lcm!=NULL) pLmFree(h->lcm);
649  h->Clear();
650  return 0;
651  }
652  h->SetShortExpVector();
653 
654 #if 0
655  if ((strat->syzComp!=0) && !strat->honey)
656  {
657  if ((strat->syzComp>0) &&
658  (h->Comp() > strat->syzComp))
659  {
660  assume(h->MinComp() > strat->syzComp);
661 #ifdef KDEBUG
662  if (TEST_OPT_DEBUG) PrintS(" > syzComp\n");
663 #endif
664  if (strat->homog)
665  h->SetDegStuffReturnLDeg(strat->LDegLast);
666  return -2;
667  }
668  }
669 #endif
670  if (!strat->homog)
671  {
672  if (!TEST_OPT_OLDSTD && strat->honey)
673  {
674  h->SetpFDeg();
675  if (strat->T[j].ecart <= h->ecart)
676  h->ecart = d - h->GetpFDeg();
677  else
678  h->ecart = d - h->GetpFDeg() + strat->T[j].ecart - h->ecart;
679 
680  d = h->GetpFDeg() + h->ecart;
681  }
682  else
683  d = h->SetDegStuffReturnLDeg(strat->LDegLast);
684  /*- try to reduce the s-polynomial -*/
685  pass++;
686  /*
687  *test whether the polynomial should go to the lazyset L
688  *-if the degree jumps
689  *-if the number of pre-defined reductions jumps
690  */
691  if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0)
692  && ((d >= reddeg) || (pass > strat->LazyPass)))
693  {
694  h->SetLmCurrRing();
695  if (strat->posInLDependsOnLength)
696  h->SetLength(strat->length_pLength);
697  at = strat->posInL(strat->L,strat->Ll,h,strat);
698  if (at <= strat->Ll)
699  {
700  int dummy=strat->sl;
701  if (kFindDivisibleByInS(strat,&dummy, h) < 0)
702  return 1;
703  enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
704 #ifdef KDEBUG
705  if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at);
706 #endif
707  h->Clear();
708  return -1;
709  }
710  }
711  if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg))
712  {
713  reddeg = d+1;
714  Print(".%ld",d);mflush();
715  if (h->pTotalDeg()+h->ecart >= (int)strat->tailRing->bitmask)
716  {
717  strat->overflow=TRUE;
718  //Print("OVERFLOW in redFirst d=%ld, max=%ld",d,strat->tailRing->bitmask);
719  h->GetP();
720  at = strat->posInL(strat->L,strat->Ll,h,strat);
721  enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
722  h->Clear();
723  return -1;
724  }
725  }
726  }
727  }
728 }
729 
730 /*2
731 * reduces h with elements from T choosing first possible
732 * element in T with respect to the given ecart
733 * used for computing normal forms outside kStd
734 */
735 static poly redMoraNF (poly h,kStrategy strat, int flag)
736 {
737  LObject H;
738  H.p = h;
739  int j = 0;
740  int z = 10;
741  int o = H.SetpFDeg();
742  H.ecart = currRing->pLDeg(H.p,&H.length,currRing)-o;
743  if ((flag & 2) == 0) cancelunit(&H,TRUE);
744  H.sev = pGetShortExpVector(H.p);
745  unsigned long not_sev = ~ H.sev;
746  loop
747  {
748  if (j > strat->tl)
749  {
750  return H.p;
751  }
752  if (TEST_V_DEG_STOP)
753  {
754  if (kModDeg(H.p)>Kstd1_deg) pLmDelete(&H.p);
755  if (H.p==NULL) return NULL;
756  }
757  if (p_LmShortDivisibleBy(strat->T[j].GetLmTailRing(), strat->sevT[j], H.GetLmTailRing(), not_sev, strat->tailRing)
758  )
759  {
760  /*- remember the found T-poly -*/
761  // poly pi = strat->T[j].p;
762  int ei = strat->T[j].ecart;
763  int li = strat->T[j].length;
764  int ii = j;
765  /*
766  * the polynomial to reduce with (up to the moment) is;
767  * pi with ecart ei and length li
768  */
769  loop
770  {
771  /*- look for a better one with respect to ecart -*/
772  /*- stop, if the ecart is small enough (<=ecart(H)) -*/
773  j++;
774  if (j > strat->tl) break;
775  if (ei <= H.ecart) break;
776  if (((strat->T[j].ecart < ei)
777  || ((strat->T[j].ecart == ei)
778  && (strat->T[j].length < li)))
779  && pLmShortDivisibleBy(strat->T[j].p,strat->sevT[j], H.p, not_sev)
780  )
781  {
782  /*
783  * the polynomial to reduce with is now;
784  */
785  // pi = strat->T[j].p;
786  ei = strat->T[j].ecart;
787  li = strat->T[j].length;
788  ii = j;
789  }
790  }
791  /*
792  * end of search: have to reduce with pi
793  */
794  z++;
795  if (z>10)
796  {
797  pNormalize(H.p);
798  z=0;
799  }
800  if ((ei > H.ecart) && (!strat->kHEdgeFound))
801  {
802  /*
803  * It is not possible to reduce h with smaller ecart;
804  * we have to reduce with bad ecart: H has to enter in T
805  */
806  doRed(&H,&(strat->T[ii]),TRUE,strat,TRUE);
807  if (H.p == NULL)
808  return NULL;
809  }
810  else
811  {
812  /*
813  * we reduce with good ecart, h need not to be put to T
814  */
815  doRed(&H,&(strat->T[ii]),FALSE,strat,TRUE);
816  if (H.p == NULL)
817  return NULL;
818  }
819  /*- try to reduce the s-polynomial -*/
820  o = H.SetpFDeg();
821  if ((flag &2 ) == 0) cancelunit(&H,TRUE);
822  H.ecart = currRing->pLDeg(H.p,&(H.length),currRing)-o;
823  j = 0;
824  H.sev = pGetShortExpVector(H.p);
825  not_sev = ~ H.sev;
826  }
827  else
828  {
829  j++;
830  }
831  }
832 }
833 
834 #ifdef HAVE_RINGS
836 {
837  LObject H;
838  H.p = h;
839  int j = 0;
840  int z = 10;
841  int o = H.SetpFDeg();
842  H.ecart = currRing->pLDeg(H.p,&H.length,currRing)-o;
843  if ((flag & 2) == 0) cancelunit(&H,TRUE);
844  H.sev = pGetShortExpVector(H.p);
845  unsigned long not_sev = ~ H.sev;
846  loop
847  {
848  if (j > strat->tl)
849  {
850  return H.p;
851  }
852  if (TEST_V_DEG_STOP)
853  {
854  if (kModDeg(H.p)>Kstd1_deg) pLmDelete(&H.p);
855  if (H.p==NULL) return NULL;
856  }
857  #ifdef ADIDEBUG_NF
858  printf("\nSearching for a reducer...\n");
859  #endif
860  if (p_LmShortDivisibleBy(strat->T[j].GetLmTailRing(), strat->sevT[j], H.GetLmTailRing(), not_sev, strat->tailRing)
861  && (n_DivBy(H.p->coef, strat->T[j].p->coef,strat->tailRing->cf))
862  )
863  {
864  /*- remember the found T-poly -*/
865  // poly pi = strat->T[j].p;
866  int ei = strat->T[j].ecart;
867  int li = strat->T[j].length;
868  int ii = j;
869  #ifdef ADIDEBUG_NF
870  printf("\nFound: j = %i, ecart = %i\nTrying to find a better one...\n",j,ei);pWrite(strat->T[j].p);
871  #endif
872  /*
873  * the polynomial to reduce with (up to the moment) is;
874  * pi with ecart ei and length li
875  */
876  loop
877  {
878  /*- look for a better one with respect to ecart -*/
879  /*- stop, if the ecart is small enough (<=ecart(H)) -*/
880  j++;
881  if (j > strat->tl) break;
882  if (ei <= H.ecart) break;
883  if (((strat->T[j].ecart < ei)
884  || ((strat->T[j].ecart == ei)
885  && (strat->T[j].length < li)))
886  && pLmShortDivisibleBy(strat->T[j].p,strat->sevT[j], H.p, not_sev)
887  && (n_DivBy(H.p->coef, strat->T[j].p->coef,strat->tailRing->cf))
888  )
889  {
890  /*
891  * the polynomial to reduce with is now;
892  */
893  // pi = strat->T[j].p;
894  ei = strat->T[j].ecart;
895  li = strat->T[j].length;
896  ii = j;
897  #ifdef ADIDEBUG_NF
898  printf("\nFound a better one: j = %i, ecart = %i\nTrying to find a better one...\n",j,ei);
899  pWrite(strat->T[j].p);
900  #endif
901  }
902  }
903  /*
904  * end of search: have to reduce with pi
905  */
906  z++;
907  if (z>10)
908  {
909  pNormalize(H.p);
910  z=0;
911  }
912  if ((ei > H.ecart) && (!strat->kHEdgeFound))
913  {
914  /*
915  * It is not possible to reduce h with smaller ecart;
916  * we have to reduce with bad ecart: H has to enter in T
917  */
918  #ifdef ADIDEBUG_NF
919  printf("\nHAVE TO REDUCE IT WITH BIGGER ECART\n");
920  #endif
921  doRed(&H,&(strat->T[ii]),TRUE,strat,TRUE);
922  if (H.p == NULL)
923  return NULL;
924  }
925  else
926  {
927  /*
928  * we reduce with good ecart, h need not to be put to T
929  */
930  doRed(&H,&(strat->T[ii]),FALSE,strat,TRUE);
931  if (H.p == NULL)
932  return NULL;
933  }
934  #ifdef ADIDEBUG_NF
935  printf("\nAfter the small reduction it looks like this:\n");pWrite(H.p);
936  getchar();
937  #endif
938  /*- try to reduce the s-polynomial -*/
939  o = H.SetpFDeg();
940  if ((flag &2 ) == 0) cancelunit(&H,TRUE);
941  H.ecart = currRing->pLDeg(H.p,&(H.length),currRing)-o;
942  j = 0;
943  H.sev = pGetShortExpVector(H.p);
944  not_sev = ~ H.sev;
945  }
946  else
947  {
948  j++;
949  }
950  }
951 }
952 #endif
953 
954 /*2
955 *reorders L with respect to posInL
956 */
958 {
959  int i,j,at;
960  LObject p;
961 
962  for (i=1; i<=strat->Ll; i++)
963  {
964  at = strat->posInL(strat->L,i-1,&(strat->L[i]),strat);
965  if (at != i)
966  {
967  p = strat->L[i];
968  for (j=i-1; j>=at; j--) strat->L[j+1] = strat->L[j];
969  strat->L[at] = p;
970  }
971  }
972 }
973 
974 /*2
975 *reorders T with respect to length
976 */
978 {
979  int i,j,at;
980  TObject p;
981  unsigned long sev;
982 
983 
984  for (i=1; i<=strat->tl; i++)
985  {
986  if (strat->T[i-1].length > strat->T[i].length)
987  {
988  p = strat->T[i];
989  sev = strat->sevT[i];
990  at = i-1;
991  loop
992  {
993  at--;
994  if (at < 0) break;
995  if (strat->T[i].length > strat->T[at].length) break;
996  }
997  for (j = i-1; j>at; j--)
998  {
999  strat->T[j+1]=strat->T[j];
1000  strat->sevT[j+1]=strat->sevT[j];
1001  strat->R[strat->T[j+1].i_r] = &(strat->T[j+1]);
1002  }
1003  strat->T[at+1]=p;
1004  strat->sevT[at+1] = sev;
1005  strat->R[p.i_r] = &(strat->T[at+1]);
1006  }
1007  }
1008 }
1009 
1010 /*2
1011 *looks whether exactly (currRing->N)-1 axis are used
1012 *returns last != 0 in this case
1013 *last is the (first) unused axis
1014 */
1016 {
1017  int i = 0;
1018  int k = 0;
1019 
1020  *last = 0;
1022  {
1023  loop
1024  {
1025  i++;
1026  if (i > (currRing->N)) break;
1027  if (strat->NotUsedAxis[i])
1028  {
1029  *last = i;
1030  k++;
1031  }
1032  if (k>1)
1033  {
1034  *last = 0;
1035  break;
1036  }
1037  }
1038  }
1039 }
1040 
1041 /*2
1042 *last is the only non used axis, it looks
1043 *for a monomial in p being a pure power of this
1044 *variable and returns TRUE in this case
1045 *(*length) gives the length between the pure power and the leading term
1046 *(should be minimal)
1047 */
1048 BOOLEAN hasPurePower (const poly p,int last, int *length,kStrategy strat)
1049 {
1050  poly h;
1051  int i;
1052 
1053  if (pNext(p) == strat->tail)
1054  return FALSE;
1055  pp_Test(p, currRing, strat->tailRing);
1056  if (strat->ak <= 0 || p_MinComp(p, currRing, strat->tailRing) == strat->ak)
1057  {
1058  i = p_IsPurePower(p, currRing);
1059  if (rField_is_Ring(currRing) && (!n_IsUnit(pGetCoeff(p), currRing->cf))) i=0;
1060  if (i == last)
1061  {
1062  *length = 0;
1063  return TRUE;
1064  }
1065  *length = 1;
1066  h = pNext(p);
1067  while (h != NULL)
1068  {
1069  i = p_IsPurePower(h, strat->tailRing);
1070  if (rField_is_Ring(currRing) && (!n_IsUnit(pGetCoeff(h), currRing->cf))) i=0;
1071  if (i==last) return TRUE;
1072  (*length)++;
1073  pIter(h);
1074  }
1075  }
1076  return FALSE;
1077 }
1078 
1080 {
1081  if (L->bucket != NULL)
1082  {
1083  poly p = L->CanonicalizeP();
1084  BOOLEAN ret = hasPurePower(p, last, length, strat);
1085  pNext(p) = NULL;
1086  return ret;
1087  }
1088  else
1089  {
1090  return hasPurePower(L->p, last, length, strat);
1091  }
1092 }
1093 
1094 /*2
1095 * looks up the position of polynomial p in L
1096 * in the case of looking for the pure powers
1097 */
1098 int posInL10 (const LSet set,const int length, LObject* p,const kStrategy strat)
1099 {
1100  int j,dp,dL;
1101 
1102  if (length<0) return 0;
1103  if (hasPurePower(p,strat->lastAxis,&dp,strat))
1104  {
1105  int op= p->GetpFDeg() +p->ecart;
1106  for (j=length; j>=0; j--)
1107  {
1108  if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat))
1109  return j+1;
1110  if (dp < dL)
1111  return j+1;
1112  if ((dp == dL)
1113  && (set[j].GetpFDeg()+set[j].ecart >= op))
1114  return j+1;
1115  }
1116  }
1117  j=length;
1118  loop
1119  {
1120  if (j<0) break;
1121  if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat)) break;
1122  j--;
1123  }
1124  return strat->posInLOld(set,j,p,strat);
1125 }
1126 
1127 
1128 /*2
1129 * computes the s-polynomials L[ ].p in L
1130 */
1132 {
1133  LObject p;
1134  int dL;
1135  int j=strat->Ll;
1136  loop
1137  {
1138  if (j<0) break;
1139  if (hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat))
1140  {
1141  p=strat->L[strat->Ll];
1142  strat->L[strat->Ll]=strat->L[j];
1143  strat->L[j]=p;
1144  break;
1145  }
1146  j--;
1147  }
1148  if (j<0)
1149  {
1150  j=strat->Ll;
1151  loop
1152  {
1153  if (j<0) break;
1154  if (pNext(strat->L[j].p) == strat->tail)
1155  {
1156  if (rField_is_Ring(currRing))
1157  pLmDelete(strat->L[j].p); /*deletes the short spoly and computes*/
1158  else
1159  pLmFree(strat->L[j].p); /*deletes the short spoly and computes*/
1160  strat->L[j].p = NULL;
1161  poly m1 = NULL, m2 = NULL;
1162  // check that spoly creation is ok
1163  while (strat->tailRing != currRing &&
1164  !kCheckSpolyCreation(&(strat->L[j]), strat, m1, m2))
1165  {
1166  assume(m1 == NULL && m2 == NULL);
1167  // if not, change to a ring where exponents are at least
1168  // large enough
1169  kStratChangeTailRing(strat);
1170  }
1171  /* create the real one */
1172  ksCreateSpoly(&(strat->L[j]), strat->kNoetherTail(), FALSE,
1173  strat->tailRing, m1, m2, strat->R);
1174 
1175  strat->L[j].SetLmCurrRing();
1176  if (!strat->honey)
1177  strat->initEcart(&strat->L[j]);
1178  else
1179  strat->L[j].SetLength(strat->length_pLength);
1180 
1181  BOOLEAN pp = hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat);
1182 
1183  if (strat->use_buckets) strat->L[j].PrepareRed(TRUE);
1184 
1185  if (pp)
1186  {
1187  p=strat->L[strat->Ll];
1188  strat->L[strat->Ll]=strat->L[j];
1189  strat->L[j]=p;
1190  break;
1191  }
1192  }
1193  j--;
1194  }
1195  }
1196 }
1197 
1198 /*2
1199 * computes the s-polynomials L[ ].p in L and
1200 * cuts elements in L above noether
1201 */
1203 {
1204 
1205  int i = 0;
1206  kTest_TS(strat);
1207  while (i <= strat->Ll)
1208  {
1209  if (pNext(strat->L[i].p) == strat->tail)
1210  {
1211  /*- deletes the int spoly and computes -*/
1212  if (pLmCmp(strat->L[i].p,strat->kNoether) == -1)
1213  {
1214  if (rField_is_Ring(currRing))
1215  pLmDelete(strat->L[i].p);
1216  else
1217  pLmFree(strat->L[i].p);
1218  strat->L[i].p = NULL;
1219  }
1220  else
1221  {
1222  if (rField_is_Ring(currRing))
1223  pLmDelete(strat->L[i].p);
1224  else
1225  pLmFree(strat->L[i].p);
1226  strat->L[i].p = NULL;
1227  poly m1 = NULL, m2 = NULL;
1228  // check that spoly creation is ok
1229  while (strat->tailRing != currRing &&
1230  !kCheckSpolyCreation(&(strat->L[i]), strat, m1, m2))
1231  {
1232  assume(m1 == NULL && m2 == NULL);
1233  // if not, change to a ring where exponents are at least
1234  // large enough
1235  kStratChangeTailRing(strat);
1236  }
1237  /* create the real one */
1238  ksCreateSpoly(&(strat->L[i]), strat->kNoetherTail(), FALSE,
1239  strat->tailRing, m1, m2, strat->R);
1240  if (! strat->L[i].IsNull())
1241  {
1242  strat->L[i].SetLmCurrRing();
1243  strat->L[i].SetpFDeg();
1244  strat->L[i].ecart
1245  = strat->L[i].pLDeg(strat->LDegLast) - strat->L[i].GetpFDeg();
1246  if (strat->use_buckets) strat->L[i].PrepareRed(TRUE);
1247  }
1248  }
1249  }
1250  else
1251  deleteHC(&(strat->L[i]), strat);
1252  if (strat->L[i].IsNull())
1253  deleteInL(strat->L,&strat->Ll,i,strat);
1254  else
1255  {
1256 #ifdef KDEBUG
1257  kTest_L(&(strat->L[i]), strat->tailRing, TRUE, i, strat->T, strat->tl);
1258 #endif
1259  i++;
1260  }
1261  }
1262  kTest_TS(strat);
1263 }
1264 
1265 /*2
1266 * cuts in T above strat->kNoether and tries to cancel a unit
1267 * changes also S as S is a subset of T
1268 */
1270 {
1271  int i = 0;
1272  LObject p;
1273 
1274  while (i <= strat->tl)
1275  {
1276  p = strat->T[i];
1277  deleteHC(&p,strat, TRUE);
1278  /*- tries to cancel a unit: -*/
1279  cancelunit(&p);
1280  if (TEST_OPT_INTSTRATEGY) /* deleteHC and/or cancelunit may have changed p*/
1281  p.pCleardenom();
1282  if (p.p != strat->T[i].p)
1283  {
1284  strat->sevT[i] = pGetShortExpVector(p.p);
1285  p.SetpFDeg();
1286  }
1287  strat->T[i] = p;
1288  i++;
1289  }
1290 }
1291 
1292 /*2
1293 * arranges red, pos and T if strat->kHEdgeFound (first time)
1294 */
1296 {
1297  if (strat->update)
1298  {
1299  kTest_TS(strat);
1300  strat->update = (strat->tl == -1);
1301  if (TEST_OPT_WEIGHTM)
1302  {
1303  pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
1304  if (strat->tailRing != currRing)
1305  {
1306  strat->tailRing->pFDeg = strat->pOrigFDeg_TailRing;
1307  strat->tailRing->pLDeg = strat->pOrigLDeg_TailRing;
1308  }
1309  int i;
1310  for (i=strat->Ll; i>=0; i--)
1311  {
1312  strat->L[i].SetpFDeg();
1313  }
1314  for (i=strat->tl; i>=0; i--)
1315  {
1316  strat->T[i].SetpFDeg();
1317  }
1318  if (ecartWeights)
1319  {
1320  omFreeSize((ADDRESS)ecartWeights,(rVar(currRing)+1)*sizeof(short));
1321  ecartWeights=NULL;
1322  }
1323  }
1324  if (TEST_OPT_FASTHC)
1325  {
1326  strat->posInL = strat->posInLOld;
1327  strat->lastAxis = 0;
1328  }
1329  if (TEST_OPT_FINDET)
1330  return;
1331 
1333  {
1334  strat->red = redFirst;
1335  strat->use_buckets = kMoraUseBucket(strat);
1336  }
1337  updateT(strat);
1338 
1340  {
1341  strat->posInT = posInT2;
1342  reorderT(strat);
1343  }
1344  }
1345  kTest_TS(strat);
1346 }
1347 
1348 /*2
1349 *-puts p to the standardbasis s at position at
1350 *-reduces the tail of p if TEST_OPT_REDTAIL
1351 *-tries to cancel a unit
1352 *-HEckeTest
1353 * if TRUE
1354 * - decides about reduction-strategies
1355 * - computes noether
1356 * - stops computation if TEST_OPT_FINDET
1357 * - cuts the tails of the polynomials
1358 * in s,t and the elements in L above noether
1359 * and cancels units if possible
1360 * - reorders s,L
1361 */
1362 void enterSMora (LObject &p,int atS,kStrategy strat, int atR = -1)
1363 {
1364  enterSBba(p, atS, strat, atR);
1365  #ifdef KDEBUG
1366  if (TEST_OPT_DEBUG)
1367  {
1368  Print("new s%d:",atS);
1369  p_wrp(p.p,currRing,strat->tailRing);
1370  PrintLn();
1371  }
1372  #endif
1373  if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat);
1374  if (strat->kHEdgeFound)
1375  {
1376  if (newHEdge(strat))
1377  {
1378  firstUpdate(strat);
1379  if (TEST_OPT_FINDET)
1380  return;
1381 
1382  /*- cuts elements in L above noether and reorders L -*/
1383  updateLHC(strat);
1384  /*- reorders L with respect to posInL -*/
1385  reorderL(strat);
1386  }
1387  }
1388  else if (strat->kNoether!=NULL)
1389  strat->kHEdgeFound = TRUE;
1390  else if (TEST_OPT_FASTHC)
1391  {
1392  if (strat->posInLOldFlag)
1393  {
1394  missingAxis(&strat->lastAxis,strat);
1395  if (strat->lastAxis)
1396  {
1397  strat->posInLOld = strat->posInL;
1398  strat->posInLOldFlag = FALSE;
1399  strat->posInL = posInL10;
1400  strat->posInLDependsOnLength = TRUE;
1401  updateL(strat);
1402  reorderL(strat);
1403  }
1404  }
1405  else if (strat->lastAxis)
1406  updateL(strat);
1407  }
1408 }
1409 
1410 /*2
1411 *-puts p to the standardbasis s at position at
1412 *-HEckeTest
1413 * if TRUE
1414 * - computes noether
1415 */
1416 void enterSMoraNF (LObject &p, int atS,kStrategy strat, int atR = -1)
1417 {
1418  enterSBba(p, atS, strat, atR);
1419  if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat);
1420  if (strat->kHEdgeFound)
1421  newHEdge(strat);
1422  else if (strat->kNoether!=NULL)
1423  strat->kHEdgeFound = TRUE;
1424 }
1425 
1427 {
1428  /* setting global variables ------------------- */
1429  strat->enterS = enterSBba;
1430  strat->red = redHoney;
1431  if (strat->honey)
1432  strat->red = redHoney;
1433  else if (currRing->pLexOrder && !strat->homog)
1434  strat->red = redLazy;
1435  else
1436  {
1437  strat->LazyPass *=4;
1438  strat->red = redHomog;
1439  }
1440  if (rField_is_Ring(currRing))
1441  {
1442  strat->red = redRing;
1443  }
1444  if (currRing->pLexOrder && strat->honey)
1445  strat->initEcart = initEcartNormal;
1446  else
1447  strat->initEcart = initEcartBBA;
1448  if (strat->honey)
1450  else
1452 // if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1453 // {
1454 // //interred machen Aenderung
1455 // strat->pOrigFDeg=pFDeg;
1456 // strat->pOrigLDeg=pLDeg;
1457 // //h=ggetid("ecart");
1458 // //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
1459 // //{
1460 // // ecartWeights=iv2array(IDINTVEC(h));
1461 // //}
1462 // //else
1463 // {
1464 // ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
1465 // /*uses automatic computation of the ecartWeights to set them*/
1466 // kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1467 // }
1468 // pRestoreDegProcs(currRing,totaldegreeWecart, maxdegreeWecart);
1469 // if (TEST_OPT_PROT)
1470 // {
1471 // for(i=1; i<=(currRing->N); i++)
1472 // Print(" %d",ecartWeights[i]);
1473 // PrintLn();
1474 // mflush();
1475 // }
1476 // }
1477 }
1478 
1479 void initSba(ideal F,kStrategy strat)
1480 {
1481  int i;
1482  //idhdl h;
1483  /* setting global variables ------------------- */
1484  strat->enterS = enterSSba;
1485  strat->red2 = redHoney;
1486  if (strat->honey)
1487  strat->red2 = redHoney;
1488  else if (currRing->pLexOrder && !strat->homog)
1489  strat->red2 = redLazy;
1490  else
1491  {
1492  strat->LazyPass *=4;
1493  strat->red2 = redHomog;
1494  }
1495  if (rField_is_Ring(currRing))
1496  {
1498  {strat->red2 = redRiloc;}
1499  else
1500  {strat->red2 = redRing;}
1501  }
1502  if (currRing->pLexOrder && strat->honey)
1503  strat->initEcart = initEcartNormal;
1504  else
1505  strat->initEcart = initEcartBBA;
1506  if (strat->honey)
1508  else
1510  //strat->kIdeal = NULL;
1511  //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD;
1512  //else strat->kIdeal->rtyp=MODUL_CMD;
1513  //strat->kIdeal->data=(void *)strat->Shdl;
1514  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1515  {
1516  //interred machen Aenderung
1517  strat->pOrigFDeg = currRing->pFDeg;
1518  strat->pOrigLDeg = currRing->pLDeg;
1519  //h=ggetid("ecart");
1520  //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
1521  //{
1522  // ecartWeights=iv2array(IDINTVEC(h));
1523  //}
1524  //else
1525  {
1526  ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
1527  /*uses automatic computation of the ecartWeights to set them*/
1529  }
1531  if (TEST_OPT_PROT)
1532  {
1533  for(i=1; i<=(currRing->N); i++)
1534  Print(" %d",ecartWeights[i]);
1535  PrintLn();
1536  mflush();
1537  }
1538  }
1539  // for sig-safe reductions in signature-based
1540  // standard basis computations
1542  strat->red = redSigRing;
1543  else
1544  strat->red = redSig;
1545  //strat->sbaOrder = 1;
1546  strat->currIdx = 1;
1547 }
1548 
1549 void initMora(ideal F,kStrategy strat)
1550 {
1551  int i,j;
1552 
1553  strat->NotUsedAxis = (BOOLEAN *)omAlloc(((currRing->N)+1)*sizeof(BOOLEAN));
1554  for (j=(currRing->N); j>0; j--) strat->NotUsedAxis[j] = TRUE;
1555  strat->enterS = enterSMora;
1556  strat->initEcartPair = initEcartPairMora; /*- ecart approximation -*/
1557  strat->posInLOld = strat->posInL;
1558  strat->posInLOldFlag = TRUE;
1559  strat->initEcart = initEcartNormal;
1560  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
1561  if ( strat->kHEdgeFound )
1562  strat->kNoether = pCopy((currRing->ppNoether));
1563  else if (strat->kHEdgeFound || strat->homog)
1564  strat->red = redFirst; /*take the first possible in T*/
1565  else
1566  strat->red = redEcart;/*take the first possible in under ecart-restriction*/
1567  if (strat->kHEdgeFound)
1568  {
1569  strat->HCord = currRing->pFDeg((currRing->ppNoether),currRing)+1;
1570  strat->posInT = posInT2;
1571  }
1572  else
1573  {
1574  strat->HCord = 32000;/*- very large -*/
1575  }
1576 
1577  if (rField_is_Ring(currRing))
1578  strat->red = redRiloc;
1579 
1580  /*reads the ecartWeights used for Graebes method from the
1581  *intvec ecart and set ecartWeights
1582  */
1583  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1584  {
1585  //interred machen Aenderung
1586  strat->pOrigFDeg=currRing->pFDeg;
1587  strat->pOrigLDeg=currRing->pLDeg;
1588  ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short));
1589  /*uses automatic computation of the ecartWeights to set them*/
1591 
1593  if (TEST_OPT_PROT)
1594  {
1595  for(i=1; i<=(currRing->N); i++)
1596  Print(" %d",ecartWeights[i]);
1597  PrintLn();
1598  mflush();
1599  }
1600  }
1601  kOptimizeLDeg(currRing->pLDeg, strat);
1602 }
1603 
1605 
1606 ideal mora (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
1607 {
1608 #ifdef HAVE_RINGS
1609 #ifdef ADIDEBUG
1610 int loop_count;
1611 loop_count = 1;
1612 #endif
1613 #endif
1614  int olddeg = 0;
1615  int reduc = 0;
1616  int red_result = 1;
1617  int hilbeledeg=1,hilbcount=0;
1618  BITSET save1;
1619  SI_SAVE_OPT1(save1);
1621  {
1622  si_opt_1 &= ~Sy_bit(OPT_REDSB);
1624  }
1625 
1626  strat->update = TRUE;
1627  /*- setting global variables ------------------- -*/
1628  initBuchMoraCrit(strat);
1629  initHilbCrit(F,Q,&hilb,strat);
1630  initMora(F,strat);
1632  initBuchMoraPosRing(strat);
1633  else
1634  initBuchMoraPos(strat);
1635  /*Shdl=*/initBuchMora(F,Q,strat);
1636  if (TEST_OPT_FASTHC) missingAxis(&strat->lastAxis,strat);
1637  /*updateS in initBuchMora has Hecketest
1638  * and could have put strat->kHEdgdeFound FALSE*/
1639  if ((currRing->ppNoether)!=NULL)
1640  {
1641  strat->kHEdgeFound = TRUE;
1642  }
1643  if (strat->kHEdgeFound && strat->update)
1644  {
1645  firstUpdate(strat);
1646  updateLHC(strat);
1647  reorderL(strat);
1648  }
1649  if (TEST_OPT_FASTHC && (strat->lastAxis) && strat->posInLOldFlag)
1650  {
1651  strat->posInLOld = strat->posInL;
1652  strat->posInLOldFlag = FALSE;
1653  strat->posInL = posInL10;
1654  updateL(strat);
1655  reorderL(strat);
1656  }
1657  kTest_TS(strat);
1658  strat->use_buckets = kMoraUseBucket(strat);
1659 
1660 #ifdef HAVE_TAIL_RING
1661  if (strat->homog && strat->red == redFirst)
1662  if(!idIs0(F) &&(!rField_is_Ring(currRing)))
1663  kStratInitChangeTailRing(strat);
1664 #endif
1665 
1666  if (BVERBOSE(23))
1667  {
1668  kDebugPrint(strat);
1669  }
1670 //deleteInL(strat->L,&strat->Ll,1,strat);
1671 //deleteInL(strat->L,&strat->Ll,0,strat);
1672 
1673  /*- compute-------------------------------------------*/
1674  while (strat->Ll >= 0)
1675  {
1676  #ifdef ADIDEBUG
1677  printf("\n ------------------------NEW LOOP\n");
1678  printf("\nShdl = \n");
1679  for(int iii = 0; iii<= strat->sl; iii++)
1680  {
1681  printf("S[%i]:",iii);
1682  p_Write(strat->S[iii], strat->tailRing);
1683  }
1684  printf("\n list L has %i\n", strat->Ll);
1685  int iii;
1686  #ifdef ADIDEBUG
1687  for(iii = 0; iii<= strat->Ll; iii++)
1688  {
1689  printf("L[%i]:",iii);
1690  pWrite(strat->L[iii].p);
1691  pWrite(strat->L[iii].p1);
1692  pWrite(strat->L[iii].p2);
1693  }
1694  #endif
1695  getchar();
1696  #endif
1697  #ifdef KDEBUG
1698  if (TEST_OPT_DEBUG) messageSets(strat);
1699  #endif
1700  if (TEST_OPT_DEGBOUND
1701  && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg))
1702  {
1703  /*
1704  * stops computation if
1705  * - 24 (degBound)
1706  * && upper degree is bigger than Kstd1_deg
1707  */
1708  while ((strat->Ll >= 0)
1709  && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
1710  && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg)
1711  )
1712  {
1713  deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1714  //if (TEST_OPT_PROT)
1715  //{
1716  // PrintS("D"); mflush();
1717  //}
1718  }
1719  if (strat->Ll<0) break;
1720  else strat->noClearS=TRUE;
1721  }
1722  strat->P = strat->L[strat->Ll];/*- picks the last element from the lazyset L -*/
1723  if (strat->Ll==0) strat->interpt=TRUE;
1724  strat->Ll--;
1725  // create the real Spoly
1726  if (pNext(strat->P.p) == strat->tail)
1727  {
1728  /*- deletes the short spoly and computes -*/
1729  if (rField_is_Ring(currRing))
1730  pLmDelete(strat->P.p);
1731  else
1732  pLmFree(strat->P.p);
1733  strat->P.p = NULL;
1734  poly m1 = NULL, m2 = NULL;
1735  // check that spoly creation is ok
1736  while (strat->tailRing != currRing &&
1737  !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
1738  {
1739  assume(m1 == NULL && m2 == NULL);
1740  // if not, change to a ring where exponents are large enough
1741  kStratChangeTailRing(strat);
1742  }
1743  /* create the real one */
1744  ksCreateSpoly(&(strat->P), strat->kNoetherTail(), strat->use_buckets,
1745  strat->tailRing, m1, m2, strat->R);
1746  if (!strat->use_buckets)
1747  strat->P.SetLength(strat->length_pLength);
1748  }
1749  else if (strat->P.p1 == NULL)
1750  {
1751  // for input polys, prepare reduction (buckets !)
1752  strat->P.SetLength(strat->length_pLength);
1753  strat->P.PrepareRed(strat->use_buckets);
1754  }
1755 
1756  // the s-poly
1757  if (!strat->P.IsNull())
1758  {
1759  // might be NULL from noether !!!
1760  if (TEST_OPT_PROT)
1761  message(strat->P.ecart+strat->P.GetpFDeg(),&olddeg,&reduc,strat, red_result);
1762  // reduce
1763  #ifdef ADIDEBUG
1764  printf("\nThis is P vor red:\n");p_Write(strat->P.p,strat->tailRing);p_Write(strat->P.p1,strat->tailRing);p_Write(strat->P.p2,strat->tailRing);
1765  printf("\nBefore Ll = %i\n", strat->Ll);
1766  #endif
1767  red_result = strat->red(&strat->P,strat);
1768  #ifdef ADIDEBUG
1769  printf("\nThis is P nach red:\n");p_Write(strat->P.p,strat->tailRing);p_Write(strat->P.p1,strat->tailRing);p_Write(strat->P.p2,strat->tailRing);
1770  printf("\nAfter Ll = %i\n", strat->Ll);
1771  #endif
1772  }
1773 
1774  // the reduced s-poly
1775  if (! strat->P.IsNull())
1776  {
1777  strat->P.GetP();
1778  // statistics
1779  if (TEST_OPT_PROT) PrintS("s");
1780  // normalization
1782  strat->P.pCleardenom();
1783  else
1784  strat->P.pNorm();
1785  // tailreduction
1786  strat->P.p = redtail(&(strat->P),strat->sl,strat);
1787  if (strat->P.p==NULL)
1788  {
1789  WerrorS("expoent overflow - wrong ordering");
1790  return(idInit(1,1));
1791  }
1792  // set ecart -- might have changed because of tail reductions
1793  if ((!strat->noTailReduction) && (!strat->honey))
1794  strat->initEcart(&strat->P);
1795  // cancel unit
1796  cancelunit(&strat->P);
1797  // for char 0, clear denominators
1798  if ((strat->P.p->next==NULL) /* i.e. cancelunit did something*/
1800  strat->P.pCleardenom();
1801 
1802  enterT(strat->P,strat);
1803  // build new pairs
1804  if (rField_is_Ring(currRing))
1805  superenterpairs(strat->P.p,strat->sl,strat->P.ecart,0,strat, strat->tl);
1806  else
1807  enterpairs(strat->P.p,strat->sl,strat->P.ecart,0,strat, strat->tl);
1808  // put in S
1809 
1810  #ifdef ADIDEBUG
1811  Print("\n The new pair list L -- after superenterpairs in loop %d -- is:\n",loop_count);
1812  for(int iii=0;iii<=strat->Ll;iii++)
1813  {
1814  printf("\n L[%d]:\n",iii);
1815  PrintS(" ");p_Write(strat->L[iii].p,strat->tailRing);
1816  PrintS(" ");p_Write(strat->L[iii].p1,strat->tailRing);
1817  PrintS(" ");p_Write(strat->L[iii].p2,strat->tailRing);
1818  }
1819  #endif
1820  strat->enterS(strat->P,
1821  posInS(strat,strat->sl,strat->P.p, strat->P.ecart),
1822  strat, strat->tl);
1823  #ifdef ADIDEBUG
1824  printf("\nThis pair has been added to S:\n");
1825  pWrite(strat->P.p);
1826  pWrite(strat->P.p1);
1827  pWrite(strat->P.p2);
1828  #endif
1829 
1830  // apply hilbert criterion
1831  if (hilb!=NULL)
1832  {
1833  if (strat->homog==isHomog)
1834  khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1835  else
1836  khCheckLocInhom(Q,w,hilb,hilbcount,strat);
1837  }
1838 
1839  // clear strat->P
1840  if (strat->P.lcm!=NULL)
1841  {
1842  if (rField_is_Ring(currRing))
1843  pLmDelete(strat->P.lcm);
1844  else
1845  pLmFree(strat->P.lcm);
1846  strat->P.lcm=NULL;
1847  }
1848 
1849 #ifdef KDEBUG
1850  // make sure kTest_TS does not complain about strat->P
1851  memset(&strat->P,0,sizeof(strat->P));
1852 #endif
1853  }
1854  if (strat->kHEdgeFound)
1855  {
1856  if ((TEST_OPT_FINDET)
1857  || ((TEST_OPT_MULTBOUND) && (scMult0Int(strat->Shdl,NULL,strat->tailRing) < Kstd1_mu)))
1858  {
1859  // obachman: is this still used ???
1860  /*
1861  * stops computation if strat->kHEdgeFound and
1862  * - 27 (finiteDeterminacyTest)
1863  * or
1864  * - 23
1865  * (multBound)
1866  * && multiplicity of the ideal is smaller then a predefined number mu
1867  */
1868  while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1869  }
1870  }
1871  kTest_TS(strat);
1872  }
1873  /*- complete reduction of the standard basis------------------------ -*/
1874  if (TEST_OPT_REDSB) completeReduce(strat);
1875  else if (TEST_OPT_PROT) PrintLn();
1876  /*- release temp data------------------------------- -*/
1877  exitBuchMora(strat);
1878  /*- polynomials used for HECKE: HC, noether -*/
1879  if (TEST_OPT_FINDET)
1880  {
1881  if (strat->kHEdge!=NULL)
1882  Kstd1_mu=currRing->pFDeg(strat->kHEdge,currRing);
1883  else
1884  Kstd1_mu=-1;
1885  }
1886  pDelete(&strat->kHEdge);
1887  strat->update = TRUE; //???
1888  strat->lastAxis = 0; //???
1889  pDelete(&strat->kNoether);
1890  omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN));
1891  if ((TEST_OPT_PROT)||(TEST_OPT_DEBUG)) messageStat(hilbcount,strat);
1892 // if (TEST_OPT_WEIGHTM)
1893 // {
1894 // pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
1895 // if (ecartWeights)
1896 // {
1897 // omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
1898 // ecartWeights=NULL;
1899 // }
1900 // }
1901  if(nCoeff_is_Ring_Z(currRing->cf))
1902  finalReduceByMon(strat);
1903  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1904  SI_RESTORE_OPT1(save1);
1905  idTest(strat->Shdl);
1906  return (strat->Shdl);
1907 }
1908 
1909 poly kNF1 (ideal F,ideal Q,poly q, kStrategy strat, int lazyReduce)
1910 {
1911  assume(q!=NULL);
1912  assume(!(idIs0(F)&&(Q==NULL)));
1913 
1914 // lazy_reduce flags: can be combined by |
1915 //#define KSTD_NF_LAZY 1
1916  // do only a reduction of the leading term
1917 //#define KSTD_NF_ECART 2
1918  // only local: recude even with bad ecart
1919  poly p;
1920  int i;
1921  int j;
1922  int o;
1923  LObject h;
1924  BITSET save1;
1925  SI_SAVE_OPT1(save1);
1926 
1927  //if ((idIs0(F))&&(Q==NULL))
1928  // return pCopy(q); /*F=0*/
1929  //strat->ak = si_max(idRankFreeModule(F),pMaxComp(q));
1930  /*- creating temp data structures------------------- -*/
1931  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
1932  strat->kNoether = pCopy((currRing->ppNoether));
1936  && (! TEST_V_DEG_STOP)
1937  && (0<Kstd1_deg)
1938  && ((!strat->kHEdgeFound)
1940  {
1941  pDelete(&strat->kNoether);
1942  strat->kNoether=pOne();
1943  pSetExp(strat->kNoether,1, Kstd1_deg+1);
1944  pSetm(strat->kNoether);
1945  strat->kHEdgeFound=TRUE;
1946  }
1947  initBuchMoraCrit(strat);
1949  initBuchMoraPosRing(strat);
1950  else
1951  initBuchMoraPos(strat);
1952  initMora(F,strat);
1953  strat->enterS = enterSMoraNF;
1954  /*- set T -*/
1955  strat->tl = -1;
1956  strat->tmax = setmaxT;
1957  strat->T = initT();
1958  strat->R = initR();
1959  strat->sevT = initsevT();
1960  /*- set S -*/
1961  strat->sl = -1;
1962  /*- init local data struct.-------------------------- -*/
1963  /*Shdl=*/initS(F,Q,strat);
1964  if ((strat->ak!=0)
1965  && (strat->kHEdgeFound))
1966  {
1967  if (strat->ak!=1)
1968  {
1969  pSetComp(strat->kNoether,1);
1970  pSetmComp(strat->kNoether);
1971  poly p=pHead(strat->kNoether);
1972  pSetComp(p,strat->ak);
1973  pSetmComp(p);
1974  p=pAdd(strat->kNoether,p);
1975  strat->kNoether=pNext(p);
1976  p_LmFree(p,currRing);
1977  }
1978  }
1979  if ((lazyReduce & KSTD_NF_LAZY)==0)
1980  {
1981  for (i=strat->sl; i>=0; i--)
1982  pNorm(strat->S[i]);
1983  }
1984  /*- puts the elements of S also to T -*/
1985  for (i=0; i<=strat->sl; i++)
1986  {
1987  h.p = strat->S[i];
1988  h.ecart = strat->ecartS[i];
1989  if (strat->sevS[i] == 0) strat->sevS[i] = pGetShortExpVector(h.p);
1990  else assume(strat->sevS[i] == pGetShortExpVector(h.p));
1991  h.length = pLength(h.p);
1992  h.sev = strat->sevS[i];
1993  h.SetpFDeg();
1994  enterT(h,strat);
1995  }
1996 #ifdef KDEBUG
1997 // kDebugPrint(strat);
1998 #endif
1999  /*- compute------------------------------------------- -*/
2000  p = pCopy(q);
2001  deleteHC(&p,&o,&j,strat);
2002  kTest(strat);
2003  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
2004  if (BVERBOSE(23)) kDebugPrint(strat);
2006  {
2007  if (p!=NULL) p = redMoraNFRing(p,strat, lazyReduce & KSTD_NF_ECART);
2008  }
2009  else
2010  {
2011  if (p!=NULL) p = redMoraNF(p,strat, lazyReduce & KSTD_NF_ECART);
2012  }
2013  if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
2014  {
2015  if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
2016  p = redtail(p,strat->sl,strat);
2017  }
2018  /*- release temp data------------------------------- -*/
2019  cleanT(strat);
2020  assume(strat->L==NULL); /*strat->L unsed */
2021  assume(strat->B==NULL); /*strat->B unused */
2022  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
2023  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
2024  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
2025  omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN));
2026  omFree(strat->sevT);
2027  omFree(strat->S_2_R);
2028  omFree(strat->R);
2029 
2030  if ((Q!=NULL)&&(strat->fromQ!=NULL))
2031  {
2032  i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
2033  omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
2034  strat->fromQ=NULL;
2035  }
2036  pDelete(&strat->kHEdge);
2037  pDelete(&strat->kNoether);
2038 // if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
2039 // {
2040 // pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2041 // if (ecartWeights)
2042 // {
2043 // omFreeSize((ADDRESS *)&ecartWeights,((currRing->N)+1)*sizeof(short));
2044 // ecartWeights=NULL;
2045 // }
2046 // }
2047  idDelete(&strat->Shdl);
2048  SI_RESTORE_OPT1(save1);
2049  if (TEST_OPT_PROT) PrintLn();
2050  return p;
2051 }
2052 
2053 ideal kNF1 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce)
2054 {
2055  assume(!idIs0(q));
2056  assume(!(idIs0(F)&&(Q==NULL)));
2057 
2058 // lazy_reduce flags: can be combined by |
2059 //#define KSTD_NF_LAZY 1
2060  // do only a reduction of the leading term
2061 //#define KSTD_NF_ECART 2
2062  // only local: recude even with bad ecart
2063  poly p;
2064  int i;
2065  int j;
2066  int o;
2067  LObject h;
2068  ideal res;
2069  BITSET save1;
2070  SI_SAVE_OPT1(save1);
2071 
2072  //if (idIs0(q)) return idInit(IDELEMS(q),si_max(q->rank,F->rank));
2073  //if ((idIs0(F))&&(Q==NULL))
2074  // return idCopy(q); /*F=0*/
2075  //strat->ak = si_max(idRankFreeModule(F),idRankFreeModule(q));
2076  /*- creating temp data structures------------------- -*/
2077  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
2078  strat->kNoether=pCopy((currRing->ppNoether));
2081  && (0<Kstd1_deg)
2082  && ((!strat->kHEdgeFound)
2084  {
2085  pDelete(&strat->kNoether);
2086  strat->kNoether=pOne();
2087  pSetExp(strat->kNoether,1, Kstd1_deg+1);
2088  pSetm(strat->kNoether);
2089  strat->kHEdgeFound=TRUE;
2090  }
2091  initBuchMoraCrit(strat);
2093  initBuchMoraPosRing(strat);
2094  else
2095  initBuchMoraPos(strat);
2096  initMora(F,strat);
2097  strat->enterS = enterSMoraNF;
2098  /*- set T -*/
2099  strat->tl = -1;
2100  strat->tmax = setmaxT;
2101  strat->T = initT();
2102  strat->R = initR();
2103  strat->sevT = initsevT();
2104  /*- set S -*/
2105  strat->sl = -1;
2106  /*- init local data struct.-------------------------- -*/
2107  /*Shdl=*/initS(F,Q,strat);
2108  if ((strat->ak!=0)
2109  && (strat->kHEdgeFound))
2110  {
2111  if (strat->ak!=1)
2112  {
2113  pSetComp(strat->kNoether,1);
2114  pSetmComp(strat->kNoether);
2115  poly p=pHead(strat->kNoether);
2116  pSetComp(p,strat->ak);
2117  pSetmComp(p);
2118  p=pAdd(strat->kNoether,p);
2119  strat->kNoether=pNext(p);
2120  p_LmFree(p,currRing);
2121  }
2122  }
2123  if (TEST_OPT_INTSTRATEGY && ((lazyReduce & KSTD_NF_LAZY)==0))
2124  {
2125  for (i=strat->sl; i>=0; i--)
2126  pNorm(strat->S[i]);
2127  }
2128  /*- compute------------------------------------------- -*/
2129  res=idInit(IDELEMS(q),strat->ak);
2130  for (i=0; i<IDELEMS(q); i++)
2131  {
2132  if (q->m[i]!=NULL)
2133  {
2134  p = pCopy(q->m[i]);
2135  deleteHC(&p,&o,&j,strat);
2136  if (p!=NULL)
2137  {
2138  /*- puts the elements of S also to T -*/
2139  for (j=0; j<=strat->sl; j++)
2140  {
2141  h.p = strat->S[j];
2142  h.ecart = strat->ecartS[j];
2143  h.pLength = h.length = pLength(h.p);
2144  if (strat->sevS[j] == 0) strat->sevS[j] = pGetShortExpVector(h.p);
2145  else assume(strat->sevS[j] == pGetShortExpVector(h.p));
2146  h.sev = strat->sevS[j];
2147  h.SetpFDeg();
2149  enterT_strong(h,strat);
2150  else
2151  enterT(h,strat);
2152  }
2153  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
2155  {
2156  p = redMoraNFRing(p,strat, lazyReduce & KSTD_NF_ECART);
2157  }
2158  else
2159  p = redMoraNF(p,strat, lazyReduce & KSTD_NF_ECART);
2160  if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
2161  {
2162  if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
2163  p = redtail(p,strat->sl,strat);
2164  }
2165  cleanT(strat);
2166  }
2167  res->m[i]=p;
2168  }
2169  //else
2170  // res->m[i]=NULL;
2171  }
2172  /*- release temp data------------------------------- -*/
2173  assume(strat->L==NULL); /*strat->L unsed */
2174  assume(strat->B==NULL); /*strat->B unused */
2175  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
2176  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
2177  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
2178  omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN));
2179  omFree(strat->sevT);
2180  omFree(strat->S_2_R);
2181  omFree(strat->R);
2182  if ((Q!=NULL)&&(strat->fromQ!=NULL))
2183  {
2184  i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16;
2185  omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int));
2186  strat->fromQ=NULL;
2187  }
2188  pDelete(&strat->kHEdge);
2189  pDelete(&strat->kNoether);
2190 // if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
2191 // {
2192 // pFDeg=strat->pOrigFDeg;
2193 // pLDeg=strat->pOrigLDeg;
2194 // if (ecartWeights)
2195 // {
2196 // omFreeSize((ADDRESS *)&ecartWeights,((currRing->N)+1)*sizeof(short));
2197 // ecartWeights=NULL;
2198 // }
2199 // }
2200  idDelete(&strat->Shdl);
2201  SI_RESTORE_OPT1(save1);
2202  if (TEST_OPT_PROT) PrintLn();
2203  return res;
2204 }
2205 
2207 
2208 long kModDeg(poly p, ring r)
2209 {
2210  long o=p_WDegree(p, r);
2211  long i=p_GetComp(p, r);
2212  if (i==0) return o;
2213  //assume((i>0) && (i<=kModW->length()));
2214  if (i<=kModW->length())
2215  return o+(*kModW)[i-1];
2216  return o;
2217 }
2218 long kHomModDeg(poly p, ring r)
2219 {
2220  int i;
2221  long j=0;
2222 
2223  for (i=r->N;i>0;i--)
2224  j+=p_GetExp(p,i,r)*(*kHomW)[i-1];
2225  if (kModW == NULL) return j;
2226  i = p_GetComp(p,r);
2227  if (i==0) return j;
2228  return j+(*kModW)[i-1];
2229 }
2230 
2231 ideal kStd(ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp,
2232  int newIdeal, intvec *vw, s_poly_proc_t sp)
2233 {
2234  if(idIs0(F))
2235  return idInit(1,F->rank);
2236 
2237  ideal r;
2238  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
2239  BOOLEAN delete_w=(w==NULL);
2240  kStrategy strat=new skStrategy;
2241 
2242  strat->s_poly=sp;
2243  if(!TEST_OPT_RETURN_SB)
2244  strat->syzComp = syzComp;
2245  if (TEST_OPT_SB_1
2246  &&(!rField_is_Ring(currRing))
2247  )
2248  strat->newIdeal = newIdeal;
2250  strat->LazyPass=20;
2251  else
2252  strat->LazyPass=2;
2253  strat->LazyDegree = 1;
2254  strat->ak = id_RankFreeModule(F,currRing);
2255  strat->kModW=kModW=NULL;
2256  strat->kHomW=kHomW=NULL;
2257  if (vw != NULL)
2258  {
2259  currRing->pLexOrder=FALSE;
2260  strat->kHomW=kHomW=vw;
2261  strat->pOrigFDeg = currRing->pFDeg;
2262  strat->pOrigLDeg = currRing->pLDeg;
2264  toReset = TRUE;
2265  }
2266  if (h==testHomog)
2267  {
2268  if (strat->ak == 0)
2269  {
2270  h = (tHomog)idHomIdeal(F,Q);
2271  w=NULL;
2272  }
2273  else if (!TEST_OPT_DEGBOUND)
2274  {
2275  h = (tHomog)idHomModule(F,Q,w);
2276  }
2277  }
2278  currRing->pLexOrder=b;
2279  if (h==isHomog)
2280  {
2281  if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
2282  {
2283  strat->kModW = kModW = *w;
2284  if (vw == NULL)
2285  {
2286  strat->pOrigFDeg = currRing->pFDeg;
2287  strat->pOrigLDeg = currRing->pLDeg;
2289  toReset = TRUE;
2290  }
2291  }
2292  currRing->pLexOrder = TRUE;
2293  if (hilb==NULL) strat->LazyPass*=2;
2294  }
2295  strat->homog=h;
2296 #ifdef KDEBUG
2297  idTest(F);
2298  if (Q!=NULL) idTest(Q);
2299 #endif
2300 #ifdef HAVE_PLURAL
2301  if (rIsPluralRing(currRing))
2302  {
2303  const BOOLEAN bIsSCA = rIsSCA(currRing) && strat->z2homog; // for Z_2 prod-crit
2304  strat->no_prod_crit = ! bIsSCA;
2305  if (w!=NULL)
2306  r = nc_GB(F, Q, *w, hilb, strat, currRing);
2307  else
2308  r = nc_GB(F, Q, NULL, hilb, strat, currRing);
2309  }
2310  else
2311 #endif
2312  {
2313  #if PRE_INTEGER_CHECK
2314  //the preinteger check strategy is not for modules
2315  if(rField_is_Ring(currRing) && nCoeff_is_Ring_Z(currRing->cf) && strat->ak <= 0)
2316  {
2317  ideal FCopy = idCopy(F);
2318  poly pFmon = preIntegerCheck(FCopy, Q);
2319  if(pFmon != NULL)
2320  {
2321  idInsertPoly(FCopy, pFmon);
2322  #ifdef ADIDEBUG
2323  printf("\nPreintegerCheck found this constant:\n");pWrite(pFmon);
2324  #endif
2325 
2326  strat->kModW=kModW=NULL;
2327  if (h==testHomog)
2328  {
2329  if (strat->ak == 0)
2330  {
2331  h = (tHomog)idHomIdeal(FCopy,Q);
2332  w=NULL;
2333  }
2334  else if (!TEST_OPT_DEGBOUND)
2335  {
2336  h = (tHomog)idHomModule(FCopy,Q,w);
2337  }
2338  }
2339  currRing->pLexOrder=b;
2340  if (h==isHomog)
2341  {
2342  if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
2343  {
2344  strat->kModW = kModW = *w;
2345  if (vw == NULL)
2346  {
2347  strat->pOrigFDeg = currRing->pFDeg;
2348  strat->pOrigLDeg = currRing->pLDeg;
2350  toReset = TRUE;
2351  }
2352  }
2353  currRing->pLexOrder = TRUE;
2354  if (hilb==NULL) strat->LazyPass*=2;
2355  }
2356  strat->homog=h;
2357  }
2358  else
2359  {
2360  #ifdef ADIDEBUG
2361  printf("\npreIntegerCheck didn't found any new information\n");
2362  #endif
2363  }
2364  omTestMemory(1);
2365  if(w == NULL)
2366  {
2368  r=mora(FCopy,Q,NULL,hilb,strat);
2369  else
2370  r=bba(FCopy,Q,NULL,hilb,strat);
2371  }
2372  else
2373  {
2375  r=mora(FCopy,Q,*w,hilb,strat);
2376  else
2377  r=bba(FCopy,Q,*w,hilb,strat);
2378  }
2379  idDelete(&FCopy);
2380  }
2381  else
2382  #endif
2383  {
2384  if(w==NULL)
2385  {
2387  r=mora(F,Q,NULL,hilb,strat);
2388  else
2389  r=bba(F,Q,NULL,hilb,strat);
2390  }
2391  else
2392  {
2394  r=mora(F,Q,*w,hilb,strat);
2395  else
2396  r=bba(F,Q,*w,hilb,strat);
2397  }
2398  }
2399  }
2400 #ifdef KDEBUG
2401  idTest(r);
2402 #endif
2403  if (toReset)
2404  {
2405  kModW = NULL;
2406  pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2407  }
2408  currRing->pLexOrder = b;
2409 //Print("%d reductions canceled \n",strat->cel);
2410  HCord=strat->HCord;
2411  delete(strat);
2412  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
2413  return r;
2414 }
2415 
2416 ideal kSba(ideal F, ideal Q, tHomog h,intvec ** w, int sbaOrder, int arri, intvec *hilb,int syzComp,
2417  int newIdeal, intvec *vw)
2418 {
2419  if(idIs0(F))
2420  return idInit(1,F->rank);
2421  if(!rField_is_Ring(currRing))
2422  {
2423  ideal r;
2424  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
2425  BOOLEAN delete_w=(w==NULL);
2426  kStrategy strat=new skStrategy;
2427  strat->sbaOrder = sbaOrder;
2428  if (arri!=0)
2429  {
2430  strat->rewCrit1 = arriRewDummy;
2431  strat->rewCrit2 = arriRewCriterion;
2432  strat->rewCrit3 = arriRewCriterionPre;
2433  }
2434  else
2435  {
2436  strat->rewCrit1 = faugereRewCriterion;
2437  strat->rewCrit2 = faugereRewCriterion;
2438  strat->rewCrit3 = faugereRewCriterion;
2439  }
2440 
2441  if(!TEST_OPT_RETURN_SB)
2442  strat->syzComp = syzComp;
2443  if (TEST_OPT_SB_1)
2444  //if(!rField_is_Ring(currRing)) // always true here
2445  strat->newIdeal = newIdeal;
2447  strat->LazyPass=20;
2448  else
2449  strat->LazyPass=2;
2450  strat->LazyDegree = 1;
2452  strat->chainCrit=chainCritNormal;
2454  strat->ak = id_RankFreeModule(F,currRing);
2455  strat->kModW=kModW=NULL;
2456  strat->kHomW=kHomW=NULL;
2457  if (vw != NULL)
2458  {
2459  currRing->pLexOrder=FALSE;
2460  strat->kHomW=kHomW=vw;
2461  strat->pOrigFDeg = currRing->pFDeg;
2462  strat->pOrigLDeg = currRing->pLDeg;
2464  toReset = TRUE;
2465  }
2466  if (h==testHomog)
2467  {
2468  if (strat->ak == 0)
2469  {
2470  h = (tHomog)idHomIdeal(F,Q);
2471  w=NULL;
2472  }
2473  else if (!TEST_OPT_DEGBOUND)
2474  {
2475  h = (tHomog)idHomModule(F,Q,w);
2476  }
2477  }
2478  currRing->pLexOrder=b;
2479  if (h==isHomog)
2480  {
2481  if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
2482  {
2483  strat->kModW = kModW = *w;
2484  if (vw == NULL)
2485  {
2486  strat->pOrigFDeg = currRing->pFDeg;
2487  strat->pOrigLDeg = currRing->pLDeg;
2489  toReset = TRUE;
2490  }
2491  }
2492  currRing->pLexOrder = TRUE;
2493  if (hilb==NULL) strat->LazyPass*=2;
2494  }
2495  strat->homog=h;
2496  #ifdef KDEBUG
2497  idTest(F);
2498  if(Q != NULL)
2499  idTest(Q);
2500  #endif
2501  #ifdef HAVE_PLURAL
2502  if (rIsPluralRing(currRing))
2503  {
2504  const BOOLEAN bIsSCA = rIsSCA(currRing) && strat->z2homog; // for Z_2 prod-crit
2505  strat->no_prod_crit = ! bIsSCA;
2506  if (w!=NULL)
2507  r = nc_GB(F, Q, *w, hilb, strat, currRing);
2508  else
2509  r = nc_GB(F, Q, NULL, hilb, strat, currRing);
2510  }
2511  else
2512  #endif
2513  {
2515  {
2516  if (w!=NULL)
2517  r=mora(F,Q,*w,hilb,strat);
2518  else
2519  r=mora(F,Q,NULL,hilb,strat);
2520  }
2521  else
2522  {
2523  strat->sigdrop = FALSE;
2524  if (w!=NULL)
2525  r=sba(F,Q,*w,hilb,strat);
2526  else
2527  r=sba(F,Q,NULL,hilb,strat);
2528  }
2529  }
2530  #ifdef KDEBUG
2531  idTest(r);
2532  #endif
2533  if (toReset)
2534  {
2535  kModW = NULL;
2536  pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2537  }
2538  currRing->pLexOrder = b;
2539  //Print("%d reductions canceled \n",strat->cel);
2540  HCord=strat->HCord;
2541  //delete(strat);
2542  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
2543  return r;
2544  }
2545  else
2546  {
2547  //--------------------------RING CASE-------------------------
2548  assume(sbaOrder == 1);
2549  assume(arri == 0);
2550  ideal r;
2551  r = idCopy(F);
2552  int sbaEnterS = -1;
2553  bool sigdrop = TRUE;
2554  #ifdef ADIDEBUG
2555  printf("\nEnter the nice kSba loop\n");
2556  #endif
2557  //This is how we set the SBA algorithm;
2558  int totalsbaruns = 1,blockedreductions = 20,blockred = 0,loops = 0;
2559  while(sigdrop && (loops < totalsbaruns || totalsbaruns == -1)
2560  && (blockred <= blockedreductions))
2561  {
2562  loops++;
2563  if(loops == 1)
2564  sigdrop = FALSE;
2565  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
2566  BOOLEAN delete_w=(w==NULL);
2567  kStrategy strat=new skStrategy;
2568  strat->sbaEnterS = sbaEnterS;
2569  strat->sigdrop = sigdrop;
2570  #if 0
2571  strat->blockred = blockred;
2572  #else
2573  strat->blockred = 0;
2574  #endif
2575  strat->blockredmax = blockedreductions;
2576  //printf("\nsbaEnterS beginning = %i\n",strat->sbaEnterS);
2577  //printf("\nsigdrop beginning = %i\n",strat->sigdrop);
2578  strat->sbaOrder = sbaOrder;
2579  if (arri!=0)
2580  {
2581  strat->rewCrit1 = arriRewDummy;
2582  strat->rewCrit2 = arriRewCriterion;
2583  strat->rewCrit3 = arriRewCriterionPre;
2584  }
2585  else
2586  {
2587  strat->rewCrit1 = faugereRewCriterion;
2588  strat->rewCrit2 = faugereRewCriterion;
2589  strat->rewCrit3 = faugereRewCriterion;
2590  }
2591 
2592  if(!TEST_OPT_RETURN_SB)
2593  strat->syzComp = syzComp;
2594  if (TEST_OPT_SB_1)
2595  if(!rField_is_Ring(currRing))
2596  strat->newIdeal = newIdeal;
2598  strat->LazyPass=20;
2599  else
2600  strat->LazyPass=2;
2601  strat->LazyDegree = 1;
2603  strat->chainCrit=chainCritNormal;
2605  strat->ak = id_RankFreeModule(F,currRing);
2606  strat->kModW=kModW=NULL;
2607  strat->kHomW=kHomW=NULL;
2608  if (vw != NULL)
2609  {
2610  currRing->pLexOrder=FALSE;
2611  strat->kHomW=kHomW=vw;
2612  strat->pOrigFDeg = currRing->pFDeg;
2613  strat->pOrigLDeg = currRing->pLDeg;
2615  toReset = TRUE;
2616  }
2617  if (h==testHomog)
2618  {
2619  if (strat->ak == 0)
2620  {
2621  h = (tHomog)idHomIdeal(F,Q);
2622  w=NULL;
2623  }
2624  else if (!TEST_OPT_DEGBOUND)
2625  {
2626  h = (tHomog)idHomModule(F,Q,w);
2627  }
2628  }
2629  currRing->pLexOrder=b;
2630  if (h==isHomog)
2631  {
2632  if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
2633  {
2634  strat->kModW = kModW = *w;
2635  if (vw == NULL)
2636  {
2637  strat->pOrigFDeg = currRing->pFDeg;
2638  strat->pOrigLDeg = currRing->pLDeg;
2640  toReset = TRUE;
2641  }
2642  }
2643  currRing->pLexOrder = TRUE;
2644  if (hilb==NULL) strat->LazyPass*=2;
2645  }
2646  strat->homog=h;
2647  #ifdef KDEBUG
2648  idTest(F);
2649  if(Q != NULL)
2650  idTest(Q);
2651  #endif
2652  #ifdef HAVE_PLURAL
2653  if (rIsPluralRing(currRing))
2654  {
2655  const BOOLEAN bIsSCA = rIsSCA(currRing) && strat->z2homog; // for Z_2 prod-crit
2656  strat->no_prod_crit = ! bIsSCA;
2657  if (w!=NULL)
2658  r = nc_GB(F, Q, *w, hilb, strat, currRing);
2659  else
2660  r = nc_GB(F, Q, NULL, hilb, strat, currRing);
2661  }
2662  else
2663  #endif
2664  {
2666  {
2667  if (w!=NULL)
2668  r=mora(F,Q,*w,hilb,strat);
2669  else
2670  r=mora(F,Q,NULL,hilb,strat);
2671  }
2672  else
2673  {
2674  if (w!=NULL)
2675  r=sba(r,Q,*w,hilb,strat);
2676  else
2677  {
2678  r=sba(r,Q,NULL,hilb,strat);
2679  }
2680  #ifdef ADIDEBUG
2681  printf("\nSBA Run %i: %i elements (syzCrit = %i,rewCrit = %i)\n",loops,IDELEMS(r),strat->nrsyzcrit,strat->nrrewcrit);
2682  idPrint(r);
2683  //getchar();
2684  #endif
2685  }
2686  }
2687  #ifdef KDEBUG
2688  idTest(r);
2689  #endif
2690  if (toReset)
2691  {
2692  kModW = NULL;
2693  pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2694  }
2695  currRing->pLexOrder = b;
2696  //Print("%d reductions canceled \n",strat->cel);
2697  HCord=strat->HCord;
2698  sigdrop = strat->sigdrop;
2699  sbaEnterS = strat->sbaEnterS;
2700  blockred = strat->blockred;
2701  #ifdef ADIDEBUG
2702  printf("\nsbaEnterS = %i\n",sbaEnterS);
2703  #endif
2704  delete(strat);
2705  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
2706  }
2707  // Go to std
2708  if(sigdrop || blockred > blockedreductions)
2709  {
2710  #ifdef ADIDEBUG
2711  printf("\nWent to std\n");
2712  idPrint(r);
2713  getchar();
2714  #endif
2715  r = kStd(r, Q, h, w, hilb, syzComp, newIdeal, vw);
2716  }
2717  return r;
2718  }
2719 }
2720 
2721 #ifdef HAVE_SHIFTBBA
2722 ideal kStdShift(ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp,
2723  int newIdeal, intvec *vw, int uptodeg, int lV)
2724 {
2725  ideal r;
2726  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
2727  BOOLEAN delete_w=(w==NULL);
2728  kStrategy strat=new skStrategy;
2729 
2730  if(!TEST_OPT_RETURN_SB)
2731  strat->syzComp = syzComp;
2732  if (TEST_OPT_SB_1)
2733  if(!rField_is_Ring(currRing))
2734  strat->newIdeal = newIdeal;
2736  strat->LazyPass=20;
2737  else
2738  strat->LazyPass=2;
2739  strat->LazyDegree = 1;
2740  strat->ak = id_RankFreeModule(F,currRing);
2741  strat->kModW=kModW=NULL;
2742  strat->kHomW=kHomW=NULL;
2743  if (vw != NULL)
2744  {
2745  currRing->pLexOrder=FALSE;
2746  strat->kHomW=kHomW=vw;
2747  strat->pOrigFDeg = currRing->pFDeg;
2748  strat->pOrigLDeg = currRing->pLDeg;
2750  toReset = TRUE;
2751  }
2752  if (h==testHomog)
2753  {
2754  if (strat->ak == 0)
2755  {
2756  h = (tHomog)idHomIdeal(F,Q);
2757  w=NULL;
2758  }
2759  else if (!TEST_OPT_DEGBOUND)
2760  {
2761  h = (tHomog)idHomModule(F,Q,w);
2762  }
2763  }
2764  currRing->pLexOrder=b;
2765  if (h==isHomog)
2766  {
2767  if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
2768  {
2769  strat->kModW = kModW = *w;
2770  if (vw == NULL)
2771  {
2772  strat->pOrigFDeg = currRing->pFDeg;
2773  strat->pOrigLDeg = currRing->pLDeg;
2775  toReset = TRUE;
2776  }
2777  }
2778  currRing->pLexOrder = TRUE;
2779  if (hilb==NULL) strat->LazyPass*=2;
2780  }
2781  strat->homog=h;
2782 #ifdef KDEBUG
2783  idTest(F);
2784 #endif
2786  {
2787  /* error: no local ord yet with shifts */
2788  PrintS("No local ordering possible for shifts");
2789  return(NULL);
2790  }
2791  else
2792  {
2793  /* global ordering */
2794  if (w!=NULL)
2795  r=bbaShift(F,Q,*w,hilb,strat,uptodeg,lV);
2796  else
2797  r=bbaShift(F,Q,NULL,hilb,strat,uptodeg,lV);
2798  }
2799 #ifdef KDEBUG
2800  idTest(r);
2801 #endif
2802  if (toReset)
2803  {
2804  kModW = NULL;
2805  pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2806  }
2807  currRing->pLexOrder = b;
2808 //Print("%d reductions canceled \n",strat->cel);
2809  HCord=strat->HCord;
2810  delete(strat);
2811  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
2812  return r;
2813 }
2814 #endif
2815 
2816 //##############################################################
2817 //##############################################################
2818 //##############################################################
2819 //##############################################################
2820 //##############################################################
2821 
2822 ideal kMin_std(ideal F, ideal Q, tHomog h,intvec ** w, ideal &M, intvec *hilb,
2823  int syzComp, int reduced)
2824 {
2825  if(idIs0(F))
2826  {
2827  M=idInit(1,F->rank);
2828  return idInit(1,F->rank);
2829  }
2831  {
2832  ideal sb;
2833  sb = kStd(F, Q, h, w, hilb);
2834  idSkipZeroes(sb);
2835  if(IDELEMS(sb) <= IDELEMS(F))
2836  {
2837  M = idCopy(sb);
2838  idSkipZeroes(M);
2839  return(sb);
2840  }
2841  else
2842  {
2843  M = idCopy(F);
2844  idSkipZeroes(M);
2845  return(sb);
2846  }
2847  }
2848  ideal r=NULL;
2849  int Kstd1_OldDeg = Kstd1_deg,i;
2850  intvec* temp_w=NULL;
2851  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
2852  BOOLEAN delete_w=(w==NULL);
2853  BOOLEAN oldDegBound=TEST_OPT_DEGBOUND;
2854  kStrategy strat=new skStrategy;
2855 
2856  if(!TEST_OPT_RETURN_SB)
2857  strat->syzComp = syzComp;
2859  strat->LazyPass=20;
2860  else
2861  strat->LazyPass=2;
2862  strat->LazyDegree = 1;
2863  strat->minim=(reduced % 2)+1;
2864  strat->ak = id_RankFreeModule(F,currRing);
2865  if (delete_w)
2866  {
2867  temp_w=new intvec((strat->ak)+1);
2868  w = &temp_w;
2869  }
2870  if (h==testHomog)
2871  {
2872  if (strat->ak == 0)
2873  {
2874  h = (tHomog)idHomIdeal(F,Q);
2875  w=NULL;
2876  }
2877  else
2878  {
2879  h = (tHomog)idHomModule(F,Q,w);
2880  }
2881  }
2882  if (h==isHomog)
2883  {
2884  if (strat->ak > 0 && (w!=NULL) && (*w!=NULL))
2885  {
2886  kModW = *w;
2887  strat->kModW = *w;
2888  assume(currRing->pFDeg != NULL && currRing->pLDeg != NULL);
2889  strat->pOrigFDeg = currRing->pFDeg;
2890  strat->pOrigLDeg = currRing->pLDeg;
2892 
2893  toReset = TRUE;
2894  if (reduced>1)
2895  {
2896  Kstd1_OldDeg=Kstd1_deg;
2897  Kstd1_deg = -1;
2898  for (i=IDELEMS(F)-1;i>=0;i--)
2899  {
2900  if ((F->m[i]!=NULL) && (currRing->pFDeg(F->m[i],currRing)>=Kstd1_deg))
2901  Kstd1_deg = currRing->pFDeg(F->m[i],currRing)+1;
2902  }
2903  }
2904  }
2905  currRing->pLexOrder = TRUE;
2906  strat->LazyPass*=2;
2907  }
2908  strat->homog=h;
2910  {
2911  if (w!=NULL)
2912  r=mora(F,Q,*w,hilb,strat);
2913  else
2914  r=mora(F,Q,NULL,hilb,strat);
2915  }
2916  else
2917  {
2918  if (w!=NULL)
2919  r=bba(F,Q,*w,hilb,strat);
2920  else
2921  r=bba(F,Q,NULL,hilb,strat);
2922  }
2923 #ifdef KDEBUG
2924  {
2925  int i;
2926  for (i=IDELEMS(r)-1; i>=0; i--) pTest(r->m[i]);
2927  }
2928 #endif
2929  idSkipZeroes(r);
2930  if (toReset)
2931  {
2932  pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
2933  kModW = NULL;
2934  }
2935  currRing->pLexOrder = b;
2936  HCord=strat->HCord;
2937  if ((delete_w)&&(temp_w!=NULL)) delete temp_w;
2938  if ((IDELEMS(r)==1) && (r->m[0]!=NULL) && pIsConstant(r->m[0]) && (strat->ak==0))
2939  {
2940  M=idInit(1,F->rank);
2941  M->m[0]=pOne();
2942  //if (strat->ak!=0) { pSetComp(M->m[0],strat->ak); pSetmComp(M->m[0]); }
2943  if (strat->M!=NULL) idDelete(&strat->M);
2944  }
2945  else if (strat->M==NULL)
2946  {
2947  M=idInit(1,F->rank);
2948  Warn("no minimal generating set computed");
2949  }
2950  else
2951  {
2952  idSkipZeroes(strat->M);
2953  M=strat->M;
2954  }
2955  delete(strat);
2956  if (reduced>2)
2957  {
2958  Kstd1_deg=Kstd1_OldDeg;
2959  if (!oldDegBound)
2961  }
2962  else
2963  {
2964  if (IDELEMS(M)>IDELEMS(r)) {
2965  idDelete(&M);
2966  M=idCopy(r); }
2967  }
2968  return r;
2969 }
2970 
2971 poly kNF(ideal F, ideal Q, poly p,int syzComp, int lazyReduce)
2972 {
2973  if (p==NULL)
2974  return NULL;
2975 
2976  poly pp = p;
2977 
2978 #ifdef HAVE_PLURAL
2979  if(rIsSCA(currRing))
2980  {
2981  const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
2982  const unsigned int m_iLastAltVar = scaLastAltVar(currRing);
2983  pp = p_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing);
2984 
2985  if(Q == currRing->qideal)
2986  Q = SCAQuotient(currRing);
2987  }
2988 #endif
2989 
2990  if ((idIs0(F))&&(Q==NULL))
2991  {
2992 #ifdef HAVE_PLURAL
2993  if(p != pp)
2994  return pp;
2995 #endif
2996  return pCopy(p); /*F+Q=0*/
2997  }
2998 
2999  kStrategy strat=new skStrategy;
3000  strat->syzComp = syzComp;
3001  strat->ak = si_max(id_RankFreeModule(F,currRing),pMaxComp(p));
3002  poly res;
3003 
3005  res=kNF1(F,Q,pp,strat,lazyReduce);
3006  else
3007  res=kNF2(F,Q,pp,strat,lazyReduce);
3008  delete(strat);
3009 
3010 #ifdef HAVE_PLURAL
3011  if(pp != p)
3012  p_Delete(&pp, currRing);
3013 #endif
3014  return res;
3015 }
3016 
3017 poly kNFBound(ideal F, ideal Q, poly p,int bound,int syzComp, int lazyReduce)
3018 {
3019  if (p==NULL)
3020  return NULL;
3021 
3022  poly pp = p;
3023 
3024 #ifdef HAVE_PLURAL
3025  if(rIsSCA(currRing))
3026  {
3027  const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
3028  const unsigned int m_iLastAltVar = scaLastAltVar(currRing);
3029  pp = p_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing);
3030 
3031  if(Q == currRing->qideal)
3032  Q = SCAQuotient(currRing);
3033  }
3034 #endif
3035 
3036  if ((idIs0(F))&&(Q==NULL))
3037  {
3038 #ifdef HAVE_PLURAL
3039  if(p != pp)
3040  return pp;
3041 #endif
3042  return pCopy(p); /*F+Q=0*/
3043  }
3044 
3045  kStrategy strat=new skStrategy;
3046  strat->syzComp = syzComp;
3047  strat->ak = si_max(id_RankFreeModule(F,currRing),pMaxComp(p));
3048  poly res;
3049  res=kNF2Bound(F,Q,pp,bound,strat,lazyReduce);
3050  delete(strat);
3051 
3052 #ifdef HAVE_PLURAL
3053  if(pp != p)
3054  p_Delete(&pp, currRing);
3055 #endif
3056  return res;
3057 }
3058 
3059 ideal kNF(ideal F, ideal Q, ideal p,int syzComp,int lazyReduce)
3060 {
3061  ideal res;
3062  if (TEST_OPT_PROT)
3063  {
3064  Print("(S:%d)",IDELEMS(p));mflush();
3065  }
3066  if (idIs0(p))
3067  return idInit(IDELEMS(p),si_max(p->rank,F->rank));
3068 
3069  ideal pp = p;
3070 #ifdef HAVE_PLURAL
3071  if(rIsSCA(currRing))
3072  {
3073  const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
3074  const unsigned int m_iLastAltVar = scaLastAltVar(currRing);
3075  pp = id_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing, false);
3076 
3077  if(Q == currRing->qideal)
3078  Q = SCAQuotient(currRing);
3079  }
3080 #endif
3081 
3082  if ((idIs0(F))&&(Q==NULL))
3083  {
3084 #ifdef HAVE_PLURAL
3085  if(p != pp)
3086  return pp;
3087 #endif
3088  return idCopy(p); /*F+Q=0*/
3089  }
3090 
3091  kStrategy strat=new skStrategy;
3092  strat->syzComp = syzComp;
3094  if (strat->ak>0) // only for module case, see Tst/Short/bug_reduce.tst
3095  {
3096  strat->ak = si_max(strat->ak,(int)F->rank);
3097  }
3098 
3100  res=kNF1(F,Q,pp,strat,lazyReduce);
3101  else
3102  res=kNF2(F,Q,pp,strat,lazyReduce);
3103  delete(strat);
3104 
3105 #ifdef HAVE_PLURAL
3106  if(pp != p)
3107  id_Delete(&pp, currRing);
3108 #endif
3109 
3110  return res;
3111 }
3112 
3113 ideal kNFBound(ideal F, ideal Q, ideal p,int bound,int syzComp,int lazyReduce)
3114 {
3115  ideal res;
3116  if (TEST_OPT_PROT)
3117  {
3118  Print("(S:%d)",IDELEMS(p));mflush();
3119  }
3120  if (idIs0(p))
3121  return idInit(IDELEMS(p),si_max(p->rank,F->rank));
3122 
3123  ideal pp = p;
3124 #ifdef HAVE_PLURAL
3125  if(rIsSCA(currRing))
3126  {
3127  const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
3128  const unsigned int m_iLastAltVar = scaLastAltVar(currRing);
3129  pp = id_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing, false);
3130 
3131  if(Q == currRing->qideal)
3132  Q = SCAQuotient(currRing);
3133  }
3134 #endif
3135 
3136  if ((idIs0(F))&&(Q==NULL))
3137  {
3138 #ifdef HAVE_PLURAL
3139  if(p != pp)
3140  return pp;
3141 #endif
3142  return idCopy(p); /*F+Q=0*/
3143  }
3144 
3145  kStrategy strat=new skStrategy;
3146  strat->syzComp = syzComp;
3148  if (strat->ak>0) // only for module case, see Tst/Short/bug_reduce.tst
3149  {
3150  strat->ak = si_max(strat->ak,(int)F->rank);
3151  }
3152 
3153  res=kNF2Bound(F,Q,pp,bound,strat,lazyReduce);
3154  delete(strat);
3155 
3156 #ifdef HAVE_PLURAL
3157  if(pp != p)
3158  id_Delete(&pp, currRing);
3159 #endif
3160 
3161  return res;
3162 }
3163 
3164 poly k_NF (ideal F, ideal Q, poly p,int syzComp, int lazyReduce, const ring _currRing)
3165 {
3166  const ring save = currRing;
3167  if( currRing != _currRing ) rChangeCurrRing(_currRing);
3168  poly ret = kNF(F, Q, p, syzComp, lazyReduce);
3169  if( currRing != save ) rChangeCurrRing(save);
3170  return ret;
3171 }
3172 
3173 /*2
3174 *interreduces F
3175 */
3176 // old version
3177 ideal kInterRedOld (ideal F, ideal Q)
3178 {
3179  int j;
3180  kStrategy strat = new skStrategy;
3181 
3182  ideal tempF = F;
3183  ideal tempQ = Q;
3184 
3185 #ifdef HAVE_PLURAL
3186  if(rIsSCA(currRing))
3187  {
3188  const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
3189  const unsigned int m_iLastAltVar = scaLastAltVar(currRing);
3190  tempF = id_KillSquares(F, m_iFirstAltVar, m_iLastAltVar, currRing);
3191 
3192  // this should be done on the upper level!!! :
3193  // tempQ = SCAQuotient(currRing);
3194 
3195  if(Q == currRing->qideal)
3196  tempQ = SCAQuotient(currRing);
3197  }
3198 #endif
3199 
3200 // if (TEST_OPT_PROT)
3201 // {
3202 // writeTime("start InterRed:");
3203 // mflush();
3204 // }
3205  //strat->syzComp = 0;
3206  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
3207  strat->kNoether=pCopy((currRing->ppNoether));
3208  strat->ak = id_RankFreeModule(tempF,currRing);
3209  initBuchMoraCrit(strat);
3210  strat->NotUsedAxis = (BOOLEAN *)omAlloc(((currRing->N)+1)*sizeof(BOOLEAN));
3211  for (j=(currRing->N); j>0; j--) strat->NotUsedAxis[j] = TRUE;
3212  strat->enterS = enterSBba;
3213  strat->posInT = posInT17;
3214  strat->initEcart = initEcartNormal;
3215  strat->sl = -1;
3216  strat->tl = -1;
3217  strat->tmax = setmaxT;
3218  strat->T = initT();
3219  strat->R = initR();
3220  strat->sevT = initsevT();
3222  initS(tempF, tempQ, strat);
3223  if (TEST_OPT_REDSB)
3224  strat->noTailReduction=FALSE;
3225  updateS(TRUE,strat);
3227  completeReduce(strat);
3228  //else if (TEST_OPT_PROT) PrintLn();
3229  pDelete(&strat->kHEdge);
3230  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
3231  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
3232  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
3233  omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN));
3234  omfree(strat->sevT);
3235  omfree(strat->S_2_R);
3236  omfree(strat->R);
3237 
3238  if (strat->fromQ)
3239  {
3240  for (j=IDELEMS(strat->Shdl)-1;j>=0;j--)
3241  {
3242  if(strat->fromQ[j]) pDelete(&strat->Shdl->m[j]);
3243  }
3244  omFreeSize((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
3245  }
3246 // if (TEST_OPT_PROT)
3247 // {
3248 // writeTime("end Interred:");
3249 // mflush();
3250 // }
3251  ideal shdl=strat->Shdl;
3252  idSkipZeroes(shdl);
3253  if (strat->fromQ)
3254  {
3255  strat->fromQ=NULL;
3256  ideal res=kInterRed(shdl,NULL);
3257  idDelete(&shdl);
3258  shdl=res;
3259  }
3260  delete(strat);
3261 #ifdef HAVE_PLURAL
3262  if( tempF != F )
3263  id_Delete( &tempF, currRing);
3264 #endif
3265  return shdl;
3266 }
3267 // new version
3268 ideal kInterRedBba (ideal F, ideal Q, int &need_retry)
3269 {
3270  need_retry=0;
3271  int red_result = 1;
3272  int olddeg,reduc;
3273  BOOLEAN withT = FALSE;
3274  // BOOLEAN toReset=FALSE;
3275  kStrategy strat=new skStrategy;
3276  tHomog h;
3277  intvec * w=NULL;
3278 
3280  strat->LazyPass=20;
3281  else
3282  strat->LazyPass=2;
3283  strat->LazyDegree = 1;
3284  strat->ak = id_RankFreeModule(F,currRing);
3285  strat->syzComp = strat->ak;
3286  strat->kModW=kModW=NULL;
3287  strat->kHomW=kHomW=NULL;
3288  if (strat->ak == 0)
3289  {
3290  h = (tHomog)idHomIdeal(F,Q);
3291  w=NULL;
3292  }
3293  else if (!TEST_OPT_DEGBOUND)
3294  {
3295  h = (tHomog)idHomModule(F,Q,&w);
3296  }
3297  if (h==isHomog)
3298  {
3299  if (strat->ak > 0 && (w!=NULL) && (w!=NULL))
3300  {
3301  strat->kModW = kModW = w;
3302  strat->pOrigFDeg = currRing->pFDeg;
3303  strat->pOrigLDeg = currRing->pLDeg;
3305  // toReset = TRUE;
3306  }
3307  strat->LazyPass*=2;
3308  }
3309  strat->homog=h;
3310 #ifdef KDEBUG
3311  idTest(F);
3312 #endif
3313 
3314  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
3316  initBuchMoraPosRing(strat);
3317  else
3318  initBuchMoraPos(strat);
3319  initBba(strat);
3320  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
3321  strat->posInL=posInL0; /* ord according pComp */
3322 
3323  /*Shdl=*/initBuchMora(F, Q, strat);
3324  reduc = olddeg = 0;
3325 
3326 #ifndef NO_BUCKETS
3327  if (!TEST_OPT_NOT_BUCKETS)
3328  strat->use_buckets = 1;
3329 #endif
3330 
3331  // redtailBBa against T for inhomogenous input
3332  if (!TEST_OPT_OLDSTD)
3333  withT = ! strat->homog;
3334 
3335  // strat->posInT = posInT_pLength;
3336  kTest_TS(strat);
3337 
3338 #ifdef HAVE_TAIL_RING
3339  kStratInitChangeTailRing(strat);
3340 #endif
3341 
3342  /* compute------------------------------------------------------- */
3343  while (strat->Ll >= 0)
3344  {
3345  #ifdef KDEBUG
3346  if (TEST_OPT_DEBUG) messageSets(strat);
3347  #endif
3348  if (strat->Ll== 0) strat->interpt=TRUE;
3349  /* picks the last element from the lazyset L */
3350  strat->P = strat->L[strat->Ll];
3351  strat->Ll--;
3352 
3353  if (strat->P.p1 == NULL)
3354  {
3355  // for input polys, prepare reduction
3356  strat->P.PrepareRed(strat->use_buckets);
3357  }
3358 
3359  if (strat->P.p == NULL && strat->P.t_p == NULL)
3360  {
3361  red_result = 0;
3362  }
3363  else
3364  {
3365  if (TEST_OPT_PROT)
3366  message(strat->P.pFDeg(),
3367  &olddeg,&reduc,strat, red_result);
3368 
3369  /* reduction of the element chosen from L */
3370  red_result = strat->red(&strat->P,strat);
3371  }
3372 
3373  // reduction to non-zero new poly
3374  if (red_result == 1)
3375  {
3376  /* statistic */
3377  if (TEST_OPT_PROT) PrintS("s");
3378 
3379  // get the polynomial (canonicalize bucket, make sure P.p is set)
3380  strat->P.GetP(strat->lmBin);
3381 
3382  int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
3383 
3384  // reduce the tail and normalize poly
3385  // in the ring case we cannot expect LC(f) = 1,
3386  // therefore we call pContent instead of pNorm
3388  {
3389  strat->P.pCleardenom();
3390  if (0)
3391  //if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
3392  {
3393  strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
3394  strat->P.pCleardenom();
3395  }
3396  }
3397  else
3398  {
3399  strat->P.pNorm();
3400  if (0)
3401  //if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
3402  strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT);
3403  }
3404 
3405 #ifdef KDEBUG
3406  if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
3407 #endif
3408 
3409  // enter into S, L, and T
3410  if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
3411  {
3412  enterT(strat->P, strat);
3413  // posInS only depends on the leading term
3414  strat->enterS(strat->P, pos, strat, strat->tl);
3415 
3416  if (pos<strat->sl)
3417  {
3418  need_retry++;
3419  // move all "larger" elements fromS to L
3420  // remove them from T
3421  int ii=pos+1;
3422  for(;ii<=strat->sl;ii++)
3423  {
3424  LObject h;
3425  memset(&h,0,sizeof(h));
3426  h.tailRing=strat->tailRing;
3427  h.p=strat->S[ii]; strat->S[ii]=NULL;
3428  strat->initEcart(&h);
3429  h.sev=strat->sevS[ii];
3430  int jj=strat->tl;
3431  while (jj>=0)
3432  {
3433  if (strat->T[jj].p==h.p)
3434  {
3435  strat->T[jj].p=NULL;
3436  if (jj<strat->tl)
3437  {
3438  memmove(&(strat->T[jj]),&(strat->T[jj+1]),
3439  (strat->tl-jj)*sizeof(strat->T[jj]));
3440  memmove(&(strat->sevT[jj]),&(strat->sevT[jj+1]),
3441  (strat->tl-jj)*sizeof(strat->sevT[jj]));
3442  }
3443  strat->tl--;
3444  break;
3445  }
3446  jj--;
3447  }
3448  int lpos=strat->posInL(strat->L,strat->Ll,&h,strat);
3449  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,lpos);
3450  #ifdef KDEBUG
3451  if (TEST_OPT_DEBUG)
3452  {
3453  Print("move S[%d] -> L[%d]: ",ii,pos);
3454  p_wrp(h.p,currRing, strat->tailRing);
3455  PrintLn();
3456  }
3457  #endif
3458  }
3459  if (strat->fromQ!=NULL)
3460  {
3461  for(ii=pos+1;ii<=strat->sl;ii++) strat->fromQ[ii]=0;
3462  }
3463  strat->sl=pos;
3464  }
3465  }
3466  else
3467  {
3468  // clean P
3469  }
3470  if (strat->P.lcm!=NULL)
3471 #ifdef HAVE_RINGS
3472  pLmDelete(strat->P.lcm);
3473 #else
3474  pLmFree(strat->P.lcm);
3475 #endif
3476  }
3477 
3478 #ifdef KDEBUG
3479  if (TEST_OPT_DEBUG)
3480  {
3481  messageSets(strat);
3482  }
3483  memset(&(strat->P), 0, sizeof(strat->P));
3484 #endif
3485  //kTest_TS(strat);: i_r out of sync in kInterRedBba, but not used!
3486  }
3487 #ifdef KDEBUG
3488  //if (TEST_OPT_DEBUG) messageSets(strat);
3489 #endif
3490  /* complete reduction of the standard basis--------- */
3491 
3492  if((need_retry<=0) && (TEST_OPT_REDSB))
3493  {
3494  completeReduce(strat);
3495  if (strat->completeReduce_retry)
3496  {
3497  // completeReduce needed larger exponents, retry
3498  // hopefully: kStratChangeTailRing already provided a larger tailRing
3499  // (otherwise: it will fail again)
3500  strat->completeReduce_retry=FALSE;
3501  completeReduce(strat);
3502  if (strat->completeReduce_retry)
3503  {
3504 #ifdef HAVE_TAIL_RING
3505  if(currRing->bitmask>strat->tailRing->bitmask)
3506  {
3507  // retry without T
3508  strat->completeReduce_retry=FALSE;
3509  cleanT(strat);strat->tailRing=currRing;
3510  int i;
3511  for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
3512  completeReduce(strat);
3513  }
3514  if (strat->completeReduce_retry)
3515 #endif
3516  Werror("exponent bound is %ld",currRing->bitmask);
3517  }
3518  }
3519  }
3520  else if (TEST_OPT_PROT) PrintLn();
3521 
3522 
3523  /* release temp data-------------------------------- */
3524  exitBuchMora(strat);
3525 // if (TEST_OPT_WEIGHTM)
3526 // {
3527 // pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
3528 // if (ecartWeights)
3529 // {
3530 // omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
3531 // ecartWeights=NULL;
3532 // }
3533 // }
3534  //if (TEST_OPT_PROT) messageStat(0/*hilbcount*/,strat);
3535  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
3536  ideal res=strat->Shdl;
3537  strat->Shdl=NULL;
3538  delete strat;
3539  if (w!=NULL) delete w;
3540  return res;
3541 }
3542 ideal kInterRed (ideal F, ideal Q)
3543 {
3544 #ifdef HAVE_PLURAL
3545  if(rIsPluralRing(currRing)) return kInterRedOld(F,Q);
3546 #endif
3549  )
3550  return kInterRedOld(F,Q);
3551 
3552  //return kInterRedOld(F,Q);
3553 
3554  BITSET save1;
3555  SI_SAVE_OPT1(save1);
3556  //si_opt_1|=Sy_bit(OPT_NOT_SUGAR);
3558  //si_opt_1&= ~Sy_bit(OPT_REDTAIL);
3559  //si_opt_1&= ~Sy_bit(OPT_REDSB);
3560  //extern char * showOption() ;
3561  //Print("%s\n",showOption());
3562 
3563  int need_retry;
3564  int counter=3;
3565  ideal res, res1;
3566  int elems;
3567  ideal null=NULL;
3568  if ((Q==NULL) || (!TEST_OPT_REDSB))
3569  {
3570  elems=idElem(F);
3571  res=kInterRedBba(F,Q,need_retry);
3572  }
3573  else
3574  {
3575  ideal FF=idSimpleAdd(F,Q);
3576  res=kInterRedBba(FF,NULL,need_retry);
3577  idDelete(&FF);
3578  null=idInit(1,1);
3579  if (need_retry)
3580  res1=kNF(null,Q,res,0,KSTD_NF_LAZY);
3581  else
3582  res1=kNF(null,Q,res);
3583  idDelete(&res);
3584  res=res1;
3585  need_retry=1;
3586  }
3587  if (idElem(res)<=1) need_retry=0;
3588  while (need_retry && (counter>0))
3589  {
3590  #ifdef KDEBUG
3591  if (TEST_OPT_DEBUG) { Print("retry counter %d\n",counter); }
3592  #endif
3593  res1=kInterRedBba(res,Q,need_retry);
3594  int new_elems=idElem(res1);
3595  counter -= (new_elems >= elems);
3596  elems = new_elems;
3597  idDelete(&res);
3598  if (idElem(res1)<=1) need_retry=0;
3599  if ((Q!=NULL) && (TEST_OPT_REDSB))
3600  {
3601  if (need_retry)
3602  res=kNF(null,Q,res1,0,KSTD_NF_LAZY);
3603  else
3604  res=kNF(null,Q,res1);
3605  idDelete(&res1);
3606  }
3607  else
3608  res = res1;
3609  if (idElem(res)<=1) need_retry=0;
3610  }
3611  if (null!=NULL) idDelete(&null);
3612  SI_RESTORE_OPT1(save1);
3613  idSkipZeroes(res);
3614  return res;
3615 }
3616 
3617 // returns TRUE if mora should use buckets, false otherwise
3619 {
3620 #ifdef MORA_USE_BUCKETS
3622  return FALSE;
3623  if (strat->red == redFirst)
3624  {
3625 #ifdef NO_LDEG
3626  if (strat->syzComp==0)
3627  return TRUE;
3628 #else
3629  if ((strat->homog || strat->honey) && (strat->syzComp==0))
3630  return TRUE;
3631 #endif
3632  }
3633  else
3634  {
3635  #ifdef HAVE_RINGS
3636  assume(strat->red == redEcart || strat->red == redRiloc);
3637  #else
3638  assume(strat->red == redEcart);
3639  #endif
3640  if (strat->honey && (strat->syzComp==0))
3641  return TRUE;
3642  }
3643 #endif
3644  return FALSE;
3645 }
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:752
#define OPT_REDSB
Definition: options.h:71
#define pSetmComp(p)
TODO:
Definition: polys.h:255
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1266
void updateT(kStrategy strat)
Definition: kstd1.cc:1269
poly k_NF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce, const ring _currRing)
NOTE: this is just a wrapper which sets currRing for the actual kNF call.
Definition: kstd1.cc:3164
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:270
ideal SCAQuotient(const ring r)
Definition: sca.h:10
KINLINE TObject ** initR()
Definition: kInline.h:92
unsigned si_opt_1
Definition: options.c:5
poly redtail(LObject *L, int pos, kStrategy strat)
Definition: kutil.cc:7496
BOOLEAN honey
Definition: kutil.h:366
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9331
#define OPT_PROT
Definition: options.h:70
poly kNF2Bound(ideal F, ideal Q, poly q, int bound, kStrategy strat, int lazyReduce)
Definition: kstd2.cc:3468
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2971
#define pSetm(p)
Definition: polys.h:253
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:432
static FORCE_INLINE BOOLEAN n_IsUnit(number n, const coeffs r)
TRUE iff n has a multiplicative inverse in the given coeff field/ring r.
Definition: coeffs.h:519
int HCord
Definition: kutil.cc:235
void PrintLn()
Definition: reporter.cc:310
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
int posInT2(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5363
#define Print
Definition: emacs.cc:83
int syzComp
Definition: kutil.h:342
static poly redMoraNFRing(poly h, kStrategy strat, int flag)
Definition: kstd1.cc:835
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:172
KINLINE unsigned long * initsevT()
Definition: kInline.h:97
#define TEST_OPT_DEGBOUND
Definition: options.h:108
#define pAdd(p, q)
Definition: polys.h:186
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:9919
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:279
#define OPT_INFREDTAIL
Definition: options.h:89
static BOOLEAN idHomIdeal(ideal id, ideal Q=NULL)
Definition: ideals.h:91
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7915
poly kHEdge
Definition: kutil.h:315
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:285
void initMora(ideal F, kStrategy strat)
Definition: kstd1.cc:1549
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
class sLObject LObject
Definition: kutil.h:52
BOOLEAN length_pLength
Definition: kutil.h:376
KINLINE TSet initT()
Definition: kInline.h:81
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7956
bool sigdrop
Definition: kutil.h:348
#define TEST_OPT_PROT
Definition: options.h:98
#define pMaxComp(p)
Definition: polys.h:281
loop
Definition: myNF.cc:98
if(0 > strat->sl)
Definition: myNF.cc:73
int Ll
Definition: kutil.h:339
#define pSetExp(p, i, v)
Definition: polys.h:42
void kEcartWeights(poly *s, int sl, short *eweight, const ring R)
Definition: weight.cc:190
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7202
#define FALSE
Definition: auxiliary.h:94
BOOLEAN noTailReduction
Definition: kutil.h:367
Compatiblity layer for legacy polynomial operations (over currRing)
int * S_2_R
Definition: kutil.h:330
ideal kSba(ideal F, ideal Q, tHomog h, intvec **w, int sbaOrder, int arri, intvec *hilb, int syzComp, int newIdeal, intvec *vw)
Definition: kstd1.cc:2416
long totaldegreeWecart(poly p, ring r)
Definition: weight.cc:225
return P p
Definition: myNF.cc:203
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3247
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10092
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:105
short * ecartWeights
Definition: weight0.c:28
#define p_GetComp(p, r)
Definition: monomials.h:72
int sbaEnterS
Definition: kutil.h:351
#define pTest(p)
Definition: polys.h:397
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:601
static poly last
Definition: hdegree.cc:1077
BOOLEAN * NotUsedAxis
Definition: kutil.h:320
BOOLEAN posInLDependsOnLength
Definition: kutil.h:378
long p_WDegree(poly p, const ring r)
Definition: p_polys.cc:715
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_Z(const coeffs r)
Definition: coeffs.h:759
static int doRed(LObject *h, TObject *with, BOOLEAN intoT, kStrategy strat, bool redMoraNF)
Definition: kstd1.cc:122
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define idSimpleAdd(A, B)
Definition: ideals.h:42
BOOLEAN(* rewCrit2)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:280
void initSba(ideal F, kStrategy strat)
Definition: kstd1.cc:1479
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:771
BOOLEAN z2homog
Definition: kutil.h:363
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4926
poly kNoether
Definition: kutil.h:316
#define OPT_OLDSTD
Definition: options.h:81
int tl
Definition: kutil.h:338
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
#define TEST_OPT_MULTBOUND
Definition: options.h:109
char noClearS
Definition: kutil.h:391
#define TRUE
Definition: auxiliary.h:98
#define TEST_OPT_REDSB
Definition: options.h:99
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
Definition: kstd1.cc:2231
int ksReducePoly(LObject *PR, TObject *PW, poly spNoether, number *coef, kStrategy strat)
Definition: kspoly.cc:45
#define kTest(A)
Definition: kutil.h:640
unsigned long * sevT
Definition: kutil.h:311
void * ADDRESS
Definition: auxiliary.h:115
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:281
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:273
#define SI_SAVE_OPT1(A)
Definition: options.h:20
void pWrite(poly p)
Definition: polys.h:290
int ak
Definition: kutil.h:341
poly preIntegerCheck(const ideal Forig, const ideal Q)
used for GB over ZZ: look for constant and monomial elements in the ideal background: any known const...
Definition: kutil.cc:10863
void cancelunit(LObject *L, BOOLEAN inNF)
Definition: kutil.cc:332
void WerrorS(const char *s)
Definition: feFopen.cc:24
int k
Definition: cfEzgcd.cc:93
void initBba(kStrategy strat)
Definition: kstd1.cc:1426
#define TEST_OPT_DEBUG
Definition: options.h:103
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1227
#define Q
Definition: sirandom.c:25
#define nEqual(n1, n2)
Definition: numbers.h:20
int redSig(LObject *h, kStrategy strat)
Definition: kstd2.cc:703
ideal bba(ideal F, ideal Q, intvec *w, intvec *hilb, kStrategy strat)
Definition: kstd2.cc:1972
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
ideal sba(ideal F0, ideal Q, intvec *w, intvec *hilb, kStrategy strat)
Definition: kstd2.cc:2355
#define BITSET
Definition: structs.h:18
int(* red)(LObject *L, kStrategy strat)
Definition: kutil.h:264
#define omAlloc(size)
Definition: omAllocDecl.h:210
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:10005
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:542
KINLINE poly redtailBba(poly p, int pos, kStrategy strat, BOOLEAN normalize)
Definition: kInline.h:1091
poly p_KillSquares(const poly p, const short iFirstAltVar, const short iLastAltVar, const ring r)
Definition: sca.cc:1478
#define Sy_bit(x)
Definition: options.h:30
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:267
void HEckeTest(poly pp, kStrategy strat)
Definition: kutil.cc:482
int currIdx
Definition: kutil.h:303
long(* pLDegProc)(poly p, int *length, ring r)
Definition: ring.h:45
static void p_LmFree(poly p, ring)
Definition: p_polys.h:678
#define pGetComp(p)
Component.
Definition: polys.h:37
void updateL(kStrategy strat)
Definition: kstd1.cc:1131
int minim
Definition: kutil.h:346
poly pp
Definition: myNF.cc:296
int lastAxis
Definition: kutil.h:344
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:1952
BITSET validOpts
Definition: kstd1.cc:63
char completeReduce_retry
Definition: kutil.h:392
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11353
int Kstd1_mu
Definition: kutil.cc:237
#define TEST_OPT_NOT_BUCKETS
Definition: options.h:100
static BOOLEAN rField_has_simple_inverse(const ring r)
Definition: ring.h:540
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
#define TEST_OPT_FINDET
Definition: options.h:106
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9469
int HCord
Definition: kutil.h:343
#define mflush()
Definition: reporter.h:57
void missingAxis(int *last, kStrategy strat)
Definition: kstd1.cc:1015
int redHoney(LObject *h, kStrategy strat)
Definition: kstd2.cc:1456
#define pIter(p)
Definition: monomials.h:44
pFDegProc pOrigFDeg
Definition: kutil.h:282
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1165
poly res
Definition: myNF.cc:322
BOOLEAN interpt
Definition: kutil.h:360
ideal kStdShift(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, int uptodeg, int lV)
Definition: kstd1.cc:2722
static BOOLEAN idHomModule(ideal m, ideal Q, intvec **w)
Definition: ideals.h:96
intvec * kHomW
Definition: kstd1.cc:2206
int redRiloc(LObject *h, kStrategy strat)
Definition: kstd1.cc:348
#define M
Definition: sirandom.c:24
void(* initEcart)(TObject *L)
Definition: kutil.h:266
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
int redLazy(LObject *h, kStrategy strat)
Definition: kstd2.cc:1296
int blockredmax
Definition: kutil.h:354
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.h:276
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8033
poly kNF2(ideal F, ideal Q, poly q, kStrategy strat, int lazyReduce)
Definition: kstd2.cc:3399
#define idPrint(id)
Definition: ideals.h:46
int nrsyzcrit
Definition: kutil.h:349
BOOLEAN fromT
Definition: kutil.h:368
ideal kInterRedBba(ideal F, ideal Q, int &need_retry)
Definition: kstd1.cc:3268
int nrrewcrit
Definition: kutil.h:350
omError_t omTestMemory(int check_level)
Definition: omDebug.c:94
const ring r
Definition: syzextra.cc:208
pLDegProc pOrigLDeg
Definition: kutil.h:283
#define KSTD_NF_LAZY
Definition: kstd1.h:17
intvec * kModW
Definition: kstd1.cc:2206
BOOLEAN homog
Definition: kutil.h:361
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1273
#define TEST_OPT_INTSTRATEGY
Definition: options.h:105
Definition: intvec.h:14
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
#define setmaxT
Definition: kutil.h:31
#define kTest_TS(A)
Definition: kutil.h:641
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:464
#define OPT_REDTAIL
Definition: options.h:86
#define TEST_V_DEG_STOP
Definition: options.h:130
tHomog
Definition: structs.h:37
int j
Definition: myNF.cc:70
#define TEST_OPT_STAIRCASEBOUND
Definition: options.h:110
END_NAMESPACE BEGIN_NAMESPACE_SINGULARXX ideal poly int syzComp
Definition: myNF.cc:291
void pSetDegProcs(ring r, pFDegProc new_FDeg, pLDegProc new_lDeg)
Definition: p_polys.cc:3543
#define omFree(addr)
Definition: omAllocDecl.h:261
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9750
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1362
#define TEST_OPT_OLDSTD
Definition: options.h:117
int scMult0Int(ideal S, ideal Q, const ring tailRing)
Definition: hdegree.cc:919
#define assume(x)
Definition: mod2.h:394
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
intset fromQ
Definition: kutil.h:307
#define messageSets(s)
Definition: kutil.h:528
poly kNF1(ideal F, ideal Q, poly q, kStrategy strat, int lazyReduce)
Definition: kstd1.cc:1909
LObject * LSet
Definition: kutil.h:54
void initEcartBBA(TObject *h)
Definition: kutil.cc:1259
void updateLHC(kStrategy strat)
Definition: kstd1.cc:1202
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl.cc )
Definition: polys.h:152
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether &#39;a&#39; is divisible &#39;b&#39;; for r encoding a field: TRUE iff &#39;b&#39; does not represent zero in Z:...
Definition: coeffs.h:787
long pLDeg0(poly p, int *l, const ring r)
Definition: p_polys.cc:740
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition: polys.h:146
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:162
pNormalize(P.p)
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:272
#define omfree(addr)
Definition: omAllocDecl.h:237
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2218
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1802
ideal kInterRed(ideal F, ideal Q)
Definition: kstd1.cc:3542
void ksCreateSpoly(LObject *Pair, poly spNoether, int use_buckets, ring tailRing, poly m1, poly m2, TObject **R)
Definition: kspoly.cc:774
int kFindDivisibleByInS(const kStrategy strat, int *max_ind, LObject *L)
return -1 if no divisor is found number of first divisor in S, otherwise
Definition: kstd2.cc:197
#define kTest_L(T)
Definition: kutil.h:644
#define KSTD_NF_ECART
Definition: kstd1.h:19
#define OPT_NOT_SUGAR
Definition: options.h:73
BOOLEAN idInsertPoly(ideal h1, poly h2)
insert h2 into h1 (if h2 is not the zero polynomial) return TRUE iff h2 was indeed inserted ...
#define pSetComp(p, v)
Definition: polys.h:38
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11254
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6132
LObject P
Definition: kutil.h:288
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:221
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9768
ideal M
Definition: kutil.h:291
unsigned sbaOrder
Definition: kutil.h:302
static int si_max(const int a, const int b)
Definition: auxiliary.h:120
void reorderL(kStrategy strat)
Definition: kstd1.cc:957
BOOLEAN update
Definition: kutil.h:370
int i
Definition: cfEzgcd.cc:123
ideal kInterRedOld(ideal F, ideal Q)
Definition: kstd1.cc:3177
void PrintS(const char *s)
Definition: reporter.cc:284
poly tail
Definition: kutil.h:322
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:243
int redSigRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:871
static long p_MinComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:308
static void kOptimizeLDeg(pLDegProc ldeg, kStrategy strat)
Definition: kstd1.cc:103
#define pOne()
Definition: polys.h:297
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5798
int(* posInLOld)(const LSet Ls, const int Ll, LObject *Lo, const kStrategy strat)
Definition: kutil.h:274
CanonicalForm H
Definition: facAbsFact.cc:64
TObject ** R
Definition: kutil.h:328
static unsigned pLength(poly a)
Definition: p_polys.h:189
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL ...
Definition: polys.h:67
polyset S
Definition: kutil.h:292
#define IDELEMS(i)
Definition: simpleideals.h:24
poly kNFBound(ideal F, ideal Q, poly p, int bound, int syzComp, int lazyReduce)
Definition: kstd1.cc:3017
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
static short scaFirstAltVar(ring r)
Definition: sca.h:18
int tmax
Definition: kutil.h:338
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:753
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9554
ideal idCopy(ideal A)
Definition: ideals.h:60
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3555
void rChangeCurrRing(ring r)
Definition: polys.cc:12
#define OPT_SUGARCRIT
Definition: options.h:75
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10802
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7264
#define OPT_INTSTRATEGY
Definition: options.h:87
#define BVERBOSE(a)
Definition: options.h:33
int int kStrategy strat
Definition: myNF.cc:68
#define TEST_OPT_RETURN_SB
Definition: options.h:107
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
void khCheck(ideal Q, intvec *w, intvec *hilb, int &eledeg, int &count, kStrategy strat)
Definition: khstd.cc:35
BOOLEAN kHEdgeFound
Definition: kutil.h:365
intset ecartS
Definition: kutil.h:295
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition: kutil.cc:7295
s_poly_proc_t s_poly
Definition: kutil.h:286
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition: p_polys.cc:1227
#define TEST_OPT_WEIGHTM
Definition: options.h:115
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:277
LSet L
Definition: kutil.h:313
BOOLEAN LDegLast
Definition: kutil.h:374
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:11031
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:477
#define NULL
Definition: omList.c:10
#define TEST_OPT_IDLIFT
Definition: options.h:123
intvec * kHomW
Definition: kutil.h:324
void cleanT(kStrategy strat)
Definition: kutil.cc:552
ideal id_KillSquares(const ideal id, const short iFirstAltVar, const short iLastAltVar, const ring r, const bool bSkipZeroes)
Definition: sca.cc:1533
#define OPT_WEIGHTM
Definition: options.h:92
LSet B
Definition: kutil.h:314
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4889
int Lmax
Definition: kutil.h:339
void firstUpdate(kStrategy strat)
Definition: kstd1.cc:1295
BOOLEAN rHasGlobalOrdering(const ring r)
Definition: ring.h:751
ring tailRing
Definition: kutil.h:331
void khCheckLocInhom(ideal Q, intvec *w, intvec *hilb, int &count, kStrategy strat)
Definition: khstd.cc:140
ideal kMin_std(ideal F, ideal Q, tHomog h, intvec **w, ideal &M, intvec *hilb, int syzComp, int reduced)
Definition: kstd1.cc:2822
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:345
#define TEST_OPT_SB_1
Definition: options.h:113
BOOLEAN hasPurePower(const poly p, int last, int *length, kStrategy strat)
Definition: kstd1.cc:1048
int blockred
Definition: kutil.h:353
void reorderT(kStrategy strat)
Definition: kstd1.cc:977
BOOLEAN(* s_poly_proc_t)(kStrategy strat)
Definition: kstd1.h:14
const CanonicalForm & w
Definition: facAbsFact.cc:55
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:5102
#define pWTotaldegree(p)
Definition: polys.h:265
#define pDelete(p_ptr)
Definition: polys.h:169
char overflow
Definition: kutil.h:393
static short scaLastAltVar(ring r)
Definition: sca.h:25
intvec * kModW
Definition: kutil.h:323
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:9000
BOOLEAN no_prod_crit
Definition: kutil.h:383
unsigned long * sevS
Definition: kutil.h:308
ideal bbaShift(ideal F, ideal Q, intvec *w, intvec *hilb, kStrategy strat, int uptodeg, int lV)
Definition: kstd2.cc:4017
static bool rIsSCA(const ring r)
Definition: nc.h:206
BOOLEAN posInLOldFlag
Definition: kutil.h:371
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:10613
#define pNext(p)
Definition: monomials.h:43
static poly redMoraNF(poly h, kStrategy strat, int flag)
Definition: kstd1.cc:735
long kModDeg(poly p, ring r)
Definition: kstd1.cc:2208
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3460
#define OPT_REDTHROUGH
Definition: options.h:77
long maxdegreeWecart(poly p, int *l, ring r)
Definition: weight.cc:255
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10401
static void pLmFree(poly p)
frees the space of the monomial m, assumes m != NULL coef is not freed, m is not advanced ...
Definition: polys.h:70
int sl
Definition: kutil.h:336
int idElem(const ideal F)
count non-zero elements
TSet T
Definition: kutil.h:312
omBin lmBin
Definition: kutil.h:332
static BOOLEAN kMoraUseBucket(kStrategy strat)
Definition: kstd1.cc:3618
BOOLEAN use_buckets
Definition: kutil.h:372
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:237
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:206
int kFindDivisibleByInT(const kStrategy strat, const LObject *L, const int start)
return -1 if no divisor is found number of first divisor in T, otherwise
Definition: kstd2.cc:88
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10736
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1416
void initEcartNormal(TObject *h)
Definition: kutil.cc:1251
#define OPT_DEGBOUND
Definition: options.h:85
void wrp(poly p)
Definition: polys.h:292
#define kTest_T(T)
Definition: kutil.h:642
#define TEST_OPT_FASTHC
Definition: options.h:104
int LazyPass
Definition: kutil.h:341
polyrec * poly
Definition: hilb.h:10
int Kstd1_deg
Definition: kutil.cc:236
BITSET kOptions
Definition: kstd1.cc:48
#define OPT_NOTREGULARITY
Definition: options.h:91
int newIdeal
Definition: kutil.h:345
#define TEST_OPT_REDTHROUGH
Definition: options.h:116
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:11188
static ideal nc_GB(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat, const ring r)
Definition: nc.h:27
ideal Shdl
Definition: kutil.h:289
#define OPT_INTERRUPT
Definition: options.h:74
int(* red2)(LObject *L, kStrategy strat)
Definition: kutil.h:265
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:85
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
const poly b
Definition: syzextra.cc:213
KINLINE poly kNoetherTail()
Definition: kInline.h:63
#define SI_RESTORE_OPT1(A)
Definition: options.h:23
KINLINE BOOLEAN arriRewDummy(poly, unsigned long, poly, kStrategy, int)
Definition: kInline.h:1147
static BOOLEAN rField_is_numeric(const ring r)
Definition: ring.h:507
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:10168
void Werror(const char *fmt,...)
Definition: reporter.cc:189
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:284
#define OPT_FASTHC
Definition: options.h:80
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition: kstd1.cc:1098
int LazyDegree
Definition: kutil.h:341
void kDebugPrint(kStrategy strat)
Definition: kutil.cc:11800
END_NAMESPACE BEGIN_NAMESPACE_SINGULARXX ideal poly int int lazyReduce
Definition: myNF.cc:292
class sTObject TObject
Definition: kutil.h:51
ideal mora(ideal F, ideal Q, intvec *w, intvec *hilb, kStrategy strat)
Definition: kstd1.cc:1606
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9229
#define pCopy(p)
return a copy of the poly
Definition: polys.h:168
#define idTest(id)
Definition: ideals.h:47
#define Warn
Definition: emacs.cc:80