My Project  debian-1:4.1.1-p2+ds-4
kutil.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT: kernel: utils for kStd
6 */
7 
8 // #define PDEBUG 2
9 // #define PDIV_DEBUG
10 #define KUTIL_CC
11 
12 #define MYTEST 0
13 
14 //All vs Just strategy over rings:
15 // 1 - Just
16 // 0 - All
17 #define ALL_VS_JUST 0
18 //Extended Spoly Strategy:
19 // 0 - new gen sig
20 // 1 - ann*old sig
21 #define EXT_POLY_NEW 0
22 
23 #include "kernel/mod2.h"
24 
25 #include "misc/mylimits.h"
26 #include "misc/options.h"
27 #include "polys/nc/nc.h"
28 #include "polys/nc/sca.h"
29 #include "polys/weight.h" /* for kDebugPrint: maxdegreeWecart*/
30 
31 #include <stdlib.h>
32 #include <string.h>
33 
34 #ifdef KDEBUG
35 #undef KDEBUG
36 #define KDEBUG 2
37 #endif
38 
39 #ifdef DEBUGF5
40 #undef DEBUGF5
41 //#define DEBUGF5 1
42 #endif
43 
44 #ifdef HAVE_RINGS
45 #include "kernel/ideals.h"
46 #endif
47 
48 // define if enterL, enterT should use memmove instead of doing it manually
49 // on topgun, this is slightly faster (see monodromy_l.tst, homog_gonnet.sing)
50 #ifndef SunOS_4
51 #define ENTER_USE_MEMMOVE
52 #endif
53 
54 // define, if the my_memmove inlines should be used instead of
55 // system memmove -- it does not seem to pay off, though
56 // #define ENTER_USE_MYMEMMOVE
57 
58 #include "kernel/GBEngine/kutil.h"
59 #include "polys/kbuckets.h"
60 #include "omalloc/omalloc.h"
61 #include "coeffs/numbers.h"
62 #include "kernel/polys.h"
63 #include "polys/monomials/ring.h"
64 #include "kernel/ideals.h"
66 #include "kernel/GBEngine/kstd1.h"
68 
69 /* shiftgb stuff */
71 #include "polys/prCopy.h"
72 
73 #ifdef HAVE_RATGRING
75 #endif
76 
77 #ifdef KDEBUG
78 #undef KDEBUG
79 #define KDEBUG 2
80 #endif
81 
82 #ifdef DEBUGF5
83 #undef DEBUGF5
84 #define DEBUGF5 2
85 #endif
86 
88 
89 
90 #ifdef ENTER_USE_MYMEMMOVE
91 inline void _my_memmove_d_gt_s(unsigned long* d, unsigned long* s, long l)
92 {
93  REGISTER unsigned long* _dl = (unsigned long*) d;
94  REGISTER unsigned long* _sl = (unsigned long*) s;
95  REGISTER long _i = l - 1;
96 
97  do
98  {
99  _dl[_i] = _sl[_i];
100  _i--;
101  }
102  while (_i >= 0);
103 }
104 
105 inline void _my_memmove_d_lt_s(unsigned long* d, unsigned long* s, long l)
106 {
107  REGISTER long _ll = l;
108  REGISTER unsigned long* _dl = (unsigned long*) d;
109  REGISTER unsigned long* _sl = (unsigned long*) s;
110  REGISTER long _i = 0;
111 
112  do
113  {
114  _dl[_i] = _sl[_i];
115  _i++;
116  }
117  while (_i < _ll);
118 }
119 
120 inline void _my_memmove(void* d, void* s, long l)
121 {
122  unsigned long _d = (unsigned long) d;
123  unsigned long _s = (unsigned long) s;
124  unsigned long _l = ((l) + SIZEOF_LONG - 1) >> LOG_SIZEOF_LONG;
125 
126  if (_d > _s) _my_memmove_d_gt_s(_d, _s, _l);
127  else _my_memmove_d_lt_s(_d, _s, _l);
128 }
129 
130 #undef memmove
131 #define memmove(d,s,l) _my_memmove(d, s, l)
132 #endif
133 
134 static poly redMora (poly h,int maxIndex,kStrategy strat);
135 static poly redBba (poly h,int maxIndex,kStrategy strat);
136 
137 #ifdef HAVE_RINGS
138 #define pDivComp_EQUAL 2
139 #define pDivComp_LESS 1
140 #define pDivComp_GREATER -1
141 #define pDivComp_INCOMP 0
142 /* Checks the relation of LM(p) and LM(q)
143  LM(p) = LM(q) => return pDivComp_EQUAL
144  LM(p) | LM(q) => return pDivComp_LESS
145  LM(q) | LM(p) => return pDivComp_GREATER
146  else return pDivComp_INCOMP */
147 static inline int pDivCompRing(poly p, poly q)
148 {
149  if ((currRing->pCompIndex < 0)
151  {
152  BOOLEAN a=FALSE, b=FALSE;
153  int i;
154  unsigned long la, lb;
155  unsigned long divmask = currRing->divmask;
156  for (i=0; i<currRing->VarL_Size; i++)
157  {
158  la = p->exp[currRing->VarL_Offset[i]];
159  lb = q->exp[currRing->VarL_Offset[i]];
160  if (la != lb)
161  {
162  if (la < lb)
163  {
164  if (b) return pDivComp_INCOMP;
165  if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
166  return pDivComp_INCOMP;
167  a = TRUE;
168  }
169  else
170  {
171  if (a) return pDivComp_INCOMP;
172  if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
173  return pDivComp_INCOMP;
174  b = TRUE;
175  }
176  }
177  }
178  if (a) return pDivComp_LESS;
179  if (b) return pDivComp_GREATER;
180  if (!a & !b) return pDivComp_EQUAL;
181  }
182  return pDivComp_INCOMP;
183 }
184 #endif
185 
186 static inline int pDivComp(poly p, poly q)
187 {
188  if ((currRing->pCompIndex < 0)
190  {
191 #ifdef HAVE_RATGRING
192  if (rIsRatGRing(currRing))
193  {
195  q,currRing,
196  currRing->real_var_start, currRing->real_var_end))
197  return 0;
198  return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
199  }
200 #endif
201  BOOLEAN a=FALSE, b=FALSE;
202  int i;
203  unsigned long la, lb;
204  unsigned long divmask = currRing->divmask;
205  for (i=0; i<currRing->VarL_Size; i++)
206  {
207  la = p->exp[currRing->VarL_Offset[i]];
208  lb = q->exp[currRing->VarL_Offset[i]];
209  if (la != lb)
210  {
211  if (la < lb)
212  {
213  if (b) return 0;
214  if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
215  return 0;
216  a = TRUE;
217  }
218  else
219  {
220  if (a) return 0;
221  if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
222  return 0;
223  b = TRUE;
224  }
225  }
226  }
227  if (a) { /*assume(pLmCmp(q,p)==1);*/ return 1; }
228  if (b) { /*assume(pLmCmp(q,p)==-1);*/return -1; }
229  /*assume(pLmCmp(q,p)==0);*/
230  }
231  return 0;
232 }
233 
234 
235 int HCord;
237 int Kstd1_mu=32000;
238 
239 /*2
240 *deletes higher monomial of p, re-compute ecart and length
241 *works only for orderings with ecart =pFDeg(end)-pFDeg(start)
242 */
243 void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
244 {
245  if (strat->kHEdgeFound)
246  {
247  kTest_L(L);
248  poly p1;
249  poly p = L->GetLmTailRing();
250  int l = 1;
251  kBucket_pt bucket = NULL;
252  if (L->bucket != NULL)
253  {
254  kBucketClear(L->bucket, &pNext(p), &L->pLength);
255  L->pLength++;
256  bucket = L->bucket;
257  L->bucket = NULL;
258  }
259 
260  if (!fromNext && p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
261  {
262  L->Delete();
263  L->Clear();
264  L->ecart = -1;
265  if (bucket != NULL) kBucketDestroy(&bucket);
266  return;
267  }
268  p1 = p;
269  while (pNext(p1)!=NULL)
270  {
271  if (p_LmCmp(pNext(p1), strat->kNoetherTail(), L->tailRing) == -1)
272  {
273  p_Delete(&pNext(p1), L->tailRing);
274  if (p1 == p)
275  {
276  if (L->t_p != NULL)
277  {
278  assume(L->p != NULL && p == L->t_p);
279  pNext(L->p) = NULL;
280  }
281  L->max_exp = NULL;
282  }
283  else if (fromNext)
284  L->max_exp = p_GetMaxExpP(pNext(L->p), L->tailRing ); // p1;
285  //if (L->pLength != 0)
286  L->pLength = l;
287  // Hmmm when called from updateT, then only
288  // reset ecart when cut
289  if (fromNext)
290  L->ecart = L->pLDeg() - L->GetpFDeg();
291  break;
292  }
293  l++;
294  pIter(p1);
295  }
296  if (! fromNext)
297  {
298  L->SetpFDeg();
299  L->ecart = L->pLDeg(strat->LDegLast) - L->GetpFDeg();
300  }
301  if (bucket != NULL)
302  {
303  if (L->pLength > 1)
304  {
305  kBucketInit(bucket, pNext(p), L->pLength - 1);
306  pNext(p) = NULL;
307  if (L->t_p != NULL) pNext(L->t_p) = NULL;
308  L->pLength = 0;
309  L->bucket = bucket;
310  }
311  else
312  kBucketDestroy(&bucket);
313  }
314  kTest_L(L);
315  }
316 }
317 
318 void deleteHC(poly* p, int* e, int* l,kStrategy strat)
319 {
320  LObject L(*p, currRing, strat->tailRing);
321 
322  deleteHC(&L, strat);
323  *p = L.p;
324  *e = L.ecart;
325  *l = L.length;
326  if (L.t_p != NULL) p_LmFree(L.t_p, strat->tailRing);
327 }
328 
329 /*2
330 *tests if p.p=monomial*unit and cancels the unit
331 */
332 void cancelunit (LObject* L,BOOLEAN inNF)
333 {
334  number lc;
335 
336  if(rHasGlobalOrdering (currRing)) return;
337  if(TEST_OPT_CANCELUNIT) return;
338 
339  ring r = L->tailRing;
340  poly p = L->GetLmTailRing();
341  if(p_GetComp(p, r) != 0 && !p_OneComp(p, r)) return;
342 
343  if (rField_is_Ring(r) /*&& (rHasLocalOrMixedOrdering(r))*/)
344  lc = pGetCoeff(p);
345 #ifdef HAVE_RINGS
346  // Leading coef have to be a unit
347  // example 2x+4x2 should be simplified to 2x*(1+2x)
348  // and 2 is not a unit in Z
349  //if ( !(n_IsUnit(pGetCoeff(p), r->cf)) ) return;
350 #endif
351 
352 
353 // for(i=r->N;i>0;i--)
354 // {
355 // if ((p_GetExp(p,i,r)>0) && (rIsPolyVar(i, r)==TRUE)) return;
356 // }
357  poly h = pNext(p);
358  int i;
359 
361  {
362  loop
363  {
364  if (h==NULL)
365  {
366  p_Delete(&pNext(p), r);
367  if (!inNF)
368  {
369  number eins= nCopy(lc);
370  if (L->p != NULL)
371  {
372  pSetCoeff(L->p,eins);
373  if (L->t_p != NULL)
374  pSetCoeff0(L->t_p,eins);
375  }
376  else
377  pSetCoeff(L->t_p,eins);
378  /* p and t_p share the same coeff, if both are !=NULL */
379  /* p==NULL==t_p cannot happen here */
380  }
381  L->ecart = 0;
382  L->length = 1;
383  //if (L->pLength > 0)
384  L->pLength = 1;
385  L->max_exp = NULL;
386 
387  if (L->t_p != NULL && pNext(L->t_p) != NULL)
388  p_Delete(&pNext(L->t_p),r);
389  if (L->p != NULL && pNext(L->p) != NULL)
390  pNext(L->p) = NULL;
391  return;
392  }
393  i = rVar(r);
394  loop
395  {
396  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
397  i--;
398  if (i == 0) break; // does divide, try next monom
399  }
400  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
401  // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
402  // domains), no zerodivisor test needed CAUTION
403  if (!n_DivBy(pGetCoeff(h),lc,r->cf))
404  {
405  return;
406  }
407  pIter(h);
408  }
409  }
410  else
411  {
412  loop
413  {
414  if (h==NULL)
415  {
416  p_Delete(&pNext(p), r);
417  if (!inNF)
418  {
419  number eins=nInit(1);
420  if (L->p != NULL)
421  {
422  pSetCoeff(L->p,eins);
423  if (L->t_p != NULL)
424  pSetCoeff0(L->t_p,eins);
425  }
426  else
427  pSetCoeff(L->t_p,eins);
428  /* p and t_p share the same coeff, if both are !=NULL */
429  /* p==NULL==t_p cannot happen here */
430  }
431  L->ecart = 0;
432  L->length = 1;
433  //if (L->pLength > 0)
434  L->pLength = 1;
435  L->max_exp = NULL;
436 
437  if (L->t_p != NULL && pNext(L->t_p) != NULL)
438  p_Delete(&pNext(L->t_p),r);
439  if (L->p != NULL && pNext(L->p) != NULL)
440  pNext(L->p) = NULL;
441 
442  return;
443  }
444  i = rVar(r);
445  loop
446  {
447  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
448  i--;
449  if (i == 0) break; // does divide, try next monom
450  }
451  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
452  pIter(h);
453  }
454  }
455 }
456 
457 /*2
458 *pp is the new element in s
459 *returns TRUE (in strat->kHEdgeFound) if
460 *-HEcke is allowed
461 *-we are in the last componente of the vector
462 *-on all axis are monomials (all elements in NotUsedAxis are FALSE)
463 *returns FALSE for pLexOrderings,
464 *assumes in module case an ordering of type c* !!
465 * HEckeTest is only called with strat->kHEdgeFound==FALSE !
466 */
467 void HEckeTest (poly pp,kStrategy strat)
468 {
469  int j,/*k,*/p;
470 
471  strat->kHEdgeFound=FALSE;
472  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
473  {
474  return;
475  }
476  if (strat->ak > 1) /*we are in the module case*/
477  {
478  return; // until ....
479  //if (!pVectorOut) /*pVectorOut <=> order = c,* */
480  // return FALSE;
481  //if (pGetComp(pp) < strat->ak) /* ak is the number of the last component */
482  // return FALSE;
483  }
484  // k = 0;
485  p=pIsPurePower(pp);
486  if (rField_is_Ring(currRing) && (!n_IsUnit(pGetCoeff(pp),currRing->cf))) return;
487  if (p!=0) strat->NotUsedAxis[p] = FALSE;
488  /*- the leading term of pp is a power of the p-th variable -*/
489  for (j=(currRing->N);j>0; j--)
490  {
491  if (strat->NotUsedAxis[j])
492  {
493  return;
494  }
495  }
496  strat->kHEdgeFound=TRUE;
497 }
498 
499 /*2
500 *utilities for TSet, LSet
501 */
502 inline static intset initec (const int maxnr)
503 {
504  return (intset)omAlloc(maxnr*sizeof(int));
505 }
506 
507 inline static unsigned long* initsevS (const int maxnr)
508 {
509  return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
510 }
511 inline static int* initS_2_R (const int maxnr)
512 {
513  return (int*)omAlloc0(maxnr*sizeof(int));
514 }
515 
516 static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
517  int &length, const int incr)
518 {
519  assume(T!=NULL);
520  assume(sevT!=NULL);
521  assume(R!=NULL);
522  assume((length+incr) > 0);
523 
524  int i;
525  T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
526  (length+incr)*sizeof(TObject));
527 
528  sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
529  (length+incr)*sizeof(long*));
530 
531  R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
532  (length+incr)*sizeof(TObject*));
533  for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
534  length += incr;
535 }
536 
537 void cleanT (kStrategy strat)
538 {
539  int i,j;
540  poly p;
541  assume(currRing == strat->tailRing || strat->tailRing != NULL);
542 
543  pShallowCopyDeleteProc p_shallow_copy_delete =
544  (strat->tailRing != currRing ?
546  NULL);
547  for (j=0; j<=strat->tl; j++)
548  {
549  p = strat->T[j].p;
550  strat->T[j].p=NULL;
551  if (strat->T[j].max_exp != NULL)
552  {
553  p_LmFree(strat->T[j].max_exp, strat->tailRing);
554  }
555  i = -1;
556  loop
557  {
558  i++;
559  if (i>strat->sl)
560  {
561  if (strat->T[j].t_p != NULL)
562  {
563  p_Delete(&(strat->T[j].t_p), strat->tailRing);
564  p_LmFree(p, currRing);
565  }
566  else
567  {
568  pDelete(&p);
569  }
570  break;
571  }
572  if (p == strat->S[i])
573  {
574  if (strat->T[j].t_p != NULL)
575  {
576  if (p_shallow_copy_delete!=NULL)
577  {
578  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
579  currRing->PolyBin);
580  }
581  p_LmFree(strat->T[j].t_p, strat->tailRing);
582  }
583  break;
584  }
585  }
586  }
587  strat->tl=-1;
588 }
589 
590 void cleanTSbaRing (kStrategy strat)
591 {
592  int i,j;
593  poly p;
594  assume(currRing == strat->tailRing || strat->tailRing != NULL);
595 
596  pShallowCopyDeleteProc p_shallow_copy_delete =
597  (strat->tailRing != currRing ?
599  NULL);
600  for (j=0; j<=strat->tl; j++)
601  {
602  p = strat->T[j].p;
603  strat->T[j].p=NULL;
604  if (strat->T[j].max_exp != NULL)
605  {
606  p_LmFree(strat->T[j].max_exp, strat->tailRing);
607  }
608  i = -1;
609  loop
610  {
611  i++;
612  if (i>strat->sl)
613  {
614  if (strat->T[j].t_p != NULL)
615  {
616  p_Delete(&(strat->T[j].t_p), strat->tailRing);
617  p_LmFree(p, currRing);
618  }
619  else
620  {
621  //pDelete(&p);
622  p = NULL;
623  }
624  break;
625  }
626  if (p == strat->S[i])
627  {
628  if (strat->T[j].t_p != NULL)
629  {
630  assume(p_shallow_copy_delete != NULL);
631  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
632  currRing->PolyBin);
633  p_LmFree(strat->T[j].t_p, strat->tailRing);
634  }
635  break;
636  }
637  }
638  }
639  strat->tl=-1;
640 }
641 
642 //LSet initL ()
643 //{
644 // int i;
645 // LSet l = (LSet)omAlloc(setmaxL*sizeof(LObject));
646 // return l;
647 //}
648 
649 static inline void enlargeL (LSet* L,int* length,const int incr)
650 {
651  assume((*L)!=NULL);
652  assume(((*length)+incr)>0);
653 
654  *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
655  ((*length)+incr)*sizeof(LObject));
656  (*length) += incr;
657 }
658 
659 void initPairtest(kStrategy strat)
660 {
661  strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
662 }
663 
664 /*2
665 *test whether (p1,p2) or (p2,p1) is in L up position length
666 *it returns TRUE if yes and the position k
667 */
668 BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
669 {
670  LObject *p=&(strat->L[length]);
671 
672  *k = length;
673  loop
674  {
675  if ((*k) < 0) return FALSE;
676  if (((p1 == (*p).p1) && (p2 == (*p).p2))
677  || ((p1 == (*p).p2) && (p2 == (*p).p1)))
678  return TRUE;
679  (*k)--;
680  p--;
681  }
682 }
683 
684 /*2
685 *in B all pairs have the same element p on the right
686 *it tests whether (q,p) is in B and returns TRUE if yes
687 *and the position k
688 */
689 BOOLEAN isInPairsetB(poly q,int* k,kStrategy strat)
690 {
691  LObject *p=&(strat->B[strat->Bl]);
692 
693  *k = strat->Bl;
694  loop
695  {
696  if ((*k) < 0) return FALSE;
697  if (q == (*p).p1)
698  return TRUE;
699  (*k)--;
700  p--;
701  }
702 }
703 
704 int kFindInT(poly p, TSet T, int tlength)
705 {
706  int i;
707 
708  for (i=0; i<=tlength; i++)
709  {
710  if (T[i].p == p) return i;
711  }
712  return -1;
713 }
714 
715 int kFindInT(poly p, kStrategy strat)
716 {
717  int i;
718  do
719  {
720  i = kFindInT(p, strat->T, strat->tl);
721  if (i >= 0) return i;
722  strat = strat->next;
723  }
724  while (strat != NULL);
725  return -1;
726 }
727 
728 #ifdef KDEBUG
729 
730 void sTObject::wrp()
731 {
732  if (t_p != NULL) p_wrp(t_p, tailRing);
733  else if (p != NULL) p_wrp(p, currRing, tailRing);
734  else ::wrp(NULL);
735 }
736 
737 #define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
738 
739 // check that Lm's of a poly from T are "equal"
740 static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
741 {
742  int i;
743  for (i=1; i<=tailRing->N; i++)
744  {
745  if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
746  return "Lm[i] different";
747  }
748  if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
749  return "Lm[0] different";
750  if (pNext(p) != pNext(t_p))
751  return "Lm.next different";
752  if (pGetCoeff(p) != pGetCoeff(t_p))
753  return "Lm.coeff different";
754  return NULL;
755 }
756 
757 static BOOLEAN sloppy_max = FALSE;
758 BOOLEAN kTest_T(TObject * T, ring strat_tailRing, int i, char TN)
759 {
760  ring tailRing = T->tailRing;
761  if (strat_tailRing == NULL) strat_tailRing = tailRing;
762  r_assume(strat_tailRing == tailRing);
763 
764  poly p = T->p;
765  // ring r = currRing;
766 
767  if (T->p == NULL && T->t_p == NULL && i >= 0)
768  return dReportError("%c[%d].poly is NULL", TN, i);
769 
770  if (T->tailRing != currRing)
771  {
772  if (T->t_p == NULL && i > 0)
773  return dReportError("%c[%d].t_p is NULL", TN, i);
774  pFalseReturn(p_Test(T->t_p, T->tailRing));
775  if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
776  if (T->p != NULL && T->t_p != NULL)
777  {
778  const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
779  if (msg != NULL)
780  return dReportError("%c[%d] %s", TN, i, msg);
781  // r = T->tailRing;
782  p = T->t_p;
783  }
784  if (T->p == NULL)
785  {
786  p = T->t_p;
787  // r = T->tailRing;
788  }
789  if (T->t_p != NULL && i >= 0 && TN == 'T')
790  {
791  if (pNext(T->t_p) == NULL)
792  {
793  if (T->max_exp != NULL)
794  return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
795  }
796  else
797  {
798  if (T->max_exp == NULL)
799  return dReportError("%c[%d].max_exp is NULL", TN, i);
800  if (pNext(T->max_exp) != NULL)
801  return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
802 
803  pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
804  omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
805 #if KDEBUG > 0
806  if (! sloppy_max)
807  {
808  poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
809  p_Setm(T->max_exp, tailRing);
810  p_Setm(test_max, tailRing);
811  BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
812  if (! equal)
813  return dReportError("%c[%d].max out of sync", TN, i);
814  p_LmFree(test_max, tailRing);
815  }
816 #endif
817  }
818  }
819  }
820  else
821  {
822  if (T->p == NULL && i > 0)
823  return dReportError("%c[%d].p is NULL", TN, i);
825  }
826 
827  if ((i >= 0) && (T->pLength != 0)
828  && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
829  {
830  int l=T->pLength;
831  T->pLength=pLength(p);
832  return dReportError("%c[%d] pLength error: has %d, specified to have %d",
833  TN, i , pLength(p), l);
834  }
835 
836  // check FDeg, for elements in L and T
837  if (i >= 0 && (TN == 'T' || TN == 'L'))
838  {
839  // FDeg has ir element from T of L set
840  if (T->FDeg != T->pFDeg())
841  {
842  int d=T->FDeg;
843  T->FDeg=T->pFDeg();
844  return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
845  TN, i , T->pFDeg(), d);
846  }
847  }
848 
849  // check is_normalized for elements in T
850  if (i >= 0 && TN == 'T')
851  {
852  if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
853  return dReportError("T[%d] is_normalized error", i);
854 
855  }
856  return TRUE;
857 }
858 
859 BOOLEAN kTest_L(LObject *L, ring strat_tailRing,
860  BOOLEAN testp, int lpos, TSet T, int tlength)
861 {
862  if (testp)
863  {
864  poly pn = NULL;
865  if (L->bucket != NULL)
866  {
867  kFalseReturn(kbTest(L->bucket));
868  r_assume(L->bucket->bucket_ring == L->tailRing);
869  if (L->p != NULL && pNext(L->p) != NULL)
870  {
871  pn = pNext(L->p);
872  pNext(L->p) = NULL;
873  }
874  }
875  if (testp!=2) kFalseReturn(kTest_T(L, strat_tailRing, lpos, 'L'));
876  if (pn != NULL)
877  pNext(L->p) = pn;
878 
879  ring r;
880  poly p;
881  L->GetLm(p, r);
882  if (L->sev != 0 && p_GetShortExpVector(p, r) != L->sev)
883  {
884  return dReportError("L[%d] wrong sev: has %o, specified to have %o",
885  lpos, p_GetShortExpVector(p, r), L->sev);
886  }
887  }
888  if (L->p1 == NULL)
889  {
890  // L->p2 either NULL or "normal" poly
891  pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
892  }
893  else if (tlength > 0 && T != NULL && (lpos >=0) && (testp!=2))
894  {
895  // now p1 and p2 must be != NULL and must be contained in T
896  // unless for SHIFTGB: here each p_i must be in T or
897  // be shifted from an element in T -> to difficult to test
898  int i;
899  i = kFindInT(L->p1, T, tlength);
900  if (i < 0)
901  return dReportError("L[%d].p1 not in T",lpos);
902  i = kFindInT(L->p2, T, tlength);
903  if (i < 0)
904  return dReportError("L[%d].p2 not in T",lpos);
905  }
906  return TRUE;
907 }
908 
909 BOOLEAN kTest (kStrategy strat)
910 {
911  int i;
912  // test P
913  kFalseReturn(kTest_L(&(strat->P), strat->tailRing,
914  (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
915  -1, strat->T, strat->tl));
916 
917  // test T
918  if (strat->T != NULL)
919  {
920  for (i=0; i<=strat->tl; i++)
921  {
922  kFalseReturn(kTest_T(&(strat->T[i]), strat->tailRing, i, 'T'));
923  if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
924  return dReportError("strat->sevT[%d] out of sync", i);
925  }
926  }
927 
928  // test L
929  if (strat->L != NULL)
930  {
931  #ifdef HAVE_SHIFTBBA
932  if (strat->red==redFirstShift) // is this in bbaShift ?
933  {
934  for (i=0; i<=strat->Ll; i++)
935  {
936  kFalseReturn(kTest_L(&(strat->L[i]), strat->tailRing,
937  2, i,
938  strat->T, strat->tl));
939  }
940  }
941  else
942  #endif
943  for (i=0; i<=strat->Ll; i++)
944  {
945  kFalseReturn(kTest_L(&(strat->L[i]), strat->tailRing,
946  strat->L[i].Next() != strat->tail, i,
947  strat->T, strat->tl));
948  // may be unused
949  //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
950  // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
951  //{
952  // assume(strat->L[i].bucket != NULL);
953  //}
954  }
955  }
956 
957  // test S
958  if (strat->S != NULL)
959  kFalseReturn(kTest_S(strat));
960 
961  return TRUE;
962 }
963 
965 {
966  int i;
967  BOOLEAN ret = TRUE;
968  for (i=0; i<=strat->sl; i++)
969  {
970  if (strat->S[i] != NULL &&
971  strat->sevS[i] != pGetShortExpVector(strat->S[i]))
972  {
973  return dReportError("S[%d] wrong sev: has %o, specified to have %o",
974  i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
975  }
976  }
977  return ret;
978 }
979 
980 
981 
983 {
984  int i, j;
985  // BOOLEAN ret = TRUE;
986  kFalseReturn(kTest(strat));
987 
988  // test strat->R, strat->T[i].i_r
989  for (i=0; i<=strat->tl; i++)
990  {
991  if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
992  return dReportError("strat->T[%d].i_r == %d out of bounds", i,
993  strat->T[i].i_r);
994  if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
995  return dReportError("T[%d].i_r with R out of sync", i);
996  }
997  // test containment of S inT
998  if (strat->S != NULL)
999  {
1000  for (i=0; i<=strat->sl; i++)
1001  {
1002  j = kFindInT(strat->S[i], strat->T, strat->tl);
1003  if (j < 0)
1004  return dReportError("S[%d] not in T", i);
1005  if (strat->S_2_R[i] != strat->T[j].i_r)
1006  return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1007  i, strat->S_2_R[i], j, strat->T[j].i_r);
1008  }
1009  }
1010  // test strat->L[i].i_r1
1011  #ifdef HAVE_SHIFTBBA
1012  if (strat->red!=redFirstShift) // not from bbaShift
1013  #endif
1014  for (i=0; i<=strat->Ll; i++)
1015  {
1016  if (strat->L[i].p1 != NULL && strat->L[i].p2)
1017  {
1018  if (strat->L[i].i_r1 < 0 ||
1019  strat->L[i].i_r1 > strat->tl ||
1020  strat->L[i].T_1(strat)->p != strat->L[i].p1)
1021  return dReportError("L[%d].i_r1 out of sync", i);
1022  if (strat->L[i].i_r2 < 0 ||
1023  strat->L[i].i_r2 > strat->tl ||
1024  strat->L[i].T_2(strat)->p != strat->L[i].p2)
1025  return dReportError("L[%d].i_r2 out of sync", i);
1026  }
1027  else
1028  {
1029  if (strat->L[i].i_r1 != -1)
1030  return dReportError("L[%d].i_r1 out of sync", i);
1031  if (strat->L[i].i_r2 != -1)
1032  return dReportError("L[%d].i_r2 out of sync", i);
1033  }
1034  if (strat->L[i].i_r != -1)
1035  return dReportError("L[%d].i_r out of sync", i);
1036  }
1037  return TRUE;
1038 }
1039 
1040 #endif // KDEBUG
1041 
1042 /*2
1043 *cancels the i-th polynomial in the standardbase s
1044 */
1045 void deleteInS (int i,kStrategy strat)
1046 {
1047 #ifdef ENTER_USE_MEMMOVE
1048  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1049  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1050  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1051  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1052 #else
1053  int j;
1054  for (j=i; j<strat->sl; j++)
1055  {
1056  strat->S[j] = strat->S[j+1];
1057  strat->ecartS[j] = strat->ecartS[j+1];
1058  strat->sevS[j] = strat->sevS[j+1];
1059  strat->S_2_R[j] = strat->S_2_R[j+1];
1060  }
1061 #endif
1062  if (strat->lenS!=NULL)
1063  {
1064 #ifdef ENTER_USE_MEMMOVE
1065  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1066 #else
1067  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1068 #endif
1069  }
1070  if (strat->lenSw!=NULL)
1071  {
1072 #ifdef ENTER_USE_MEMMOVE
1073  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1074 #else
1075  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1076 #endif
1077  }
1078  if (strat->fromQ!=NULL)
1079  {
1080 #ifdef ENTER_USE_MEMMOVE
1081  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1082 #else
1083  for (j=i; j<strat->sl; j++)
1084  {
1085  strat->fromQ[j] = strat->fromQ[j+1];
1086  }
1087 #endif
1088  }
1089  strat->S[strat->sl] = NULL;
1090  strat->sl--;
1091 }
1092 
1093 
1094 /*2
1095 *cancels the i-th polynomial in the standardbase s
1096 */
1097 void deleteInSSba (int i,kStrategy strat)
1098 {
1099 #ifdef ENTER_USE_MEMMOVE
1100  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1101  memmove(&(strat->sig[i]), &(strat->sig[i+1]), (strat->sl - i)*sizeof(poly));
1102  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1103  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1104  memmove(&(strat->sevSig[i]),&(strat->sevSig[i+1]),(strat->sl - i)*sizeof(unsigned long));
1105  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1106 #else
1107  int j;
1108  for (j=i; j<strat->sl; j++)
1109  {
1110  strat->S[j] = strat->S[j+1];
1111  strat->sig[j] = strat->sig[j+1];
1112  strat->ecartS[j] = strat->ecartS[j+1];
1113  strat->sevS[j] = strat->sevS[j+1];
1114  strat->sevSig[j] = strat->sevSig[j+1];
1115  strat->S_2_R[j] = strat->S_2_R[j+1];
1116  }
1117 #endif
1118  if (strat->lenS!=NULL)
1119  {
1120 #ifdef ENTER_USE_MEMMOVE
1121  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1122 #else
1123  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1124 #endif
1125  }
1126  if (strat->lenSw!=NULL)
1127  {
1128 #ifdef ENTER_USE_MEMMOVE
1129  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1130 #else
1131  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1132 #endif
1133  }
1134  if (strat->fromQ!=NULL)
1135  {
1136 #ifdef ENTER_USE_MEMMOVE
1137  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1138 #else
1139  for (j=i; j<strat->sl; j++)
1140  {
1141  strat->fromQ[j] = strat->fromQ[j+1];
1142  }
1143 #endif
1144  }
1145  strat->S[strat->sl] = NULL;
1146  strat->sl--;
1147 }
1148 
1149 /*2
1150 *cancels the j-th polynomial in the set
1151 */
1152 void deleteInL (LSet set, int *length, int j,kStrategy strat)
1153 {
1154  if (set[j].lcm!=NULL)
1155  {
1156 #ifdef HAVE_RINGS
1158  && (pGetCoeff(set[j].lcm) != NULL))
1159  pLmDelete(set[j].lcm);
1160  else
1161 #endif
1162  pLmFree(set[j].lcm);
1163  }
1164  if (set[j].sig!=NULL)
1165  {
1166 #ifdef HAVE_RINGS
1167  if (pGetCoeff(set[j].sig) != NULL)
1168  pLmDelete(set[j].sig);
1169  else
1170 #endif
1171  pLmFree(set[j].sig);
1172  }
1173  if (set[j].p!=NULL)
1174  {
1175  if (pNext(set[j].p) == strat->tail)
1176  {
1177 #ifdef HAVE_RINGS
1178  if (pGetCoeff(set[j].p) != NULL)
1179  pLmDelete(set[j].p);
1180  else
1181 #endif
1182  pLmFree(set[j].p);
1183  /*- tail belongs to several int spolys -*/
1184  }
1185  else
1186  {
1187  // search p in T, if it is there, do not delete it
1188  if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1189  {
1190  // assure that for global orderings kFindInT fails
1191  //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1192  set[j].Delete();
1193  }
1194  }
1195  }
1196  if (*length > 0 && j < *length)
1197  {
1198 #ifdef ENTER_USE_MEMMOVE
1199  memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1200 #else
1201  int i;
1202  for (i=j; i < (*length); i++)
1203  set[i] = set[i+1];
1204 #endif
1205  }
1206 #ifdef KDEBUG
1207  memset(&(set[*length]),0,sizeof(LObject));
1208 #endif
1209  (*length)--;
1210 }
1211 
1212 /*2
1213 *enters p at position at in L
1214 */
1215 void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1216 {
1217  // this should be corrected
1218  assume(p.FDeg == p.pFDeg());
1219 
1220  if ((*length)>=0)
1221  {
1222  if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1223  if (at <= (*length))
1224 #ifdef ENTER_USE_MEMMOVE
1225  memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1226 #else
1227  for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1228 #endif
1229  }
1230  else at = 0;
1231  (*set)[at] = p;
1232  (*length)++;
1233 }
1234 
1235 /*2
1236 * computes the normal ecart;
1237 * used in mora case and if pLexOrder & sugar in bba case
1238 */
1239 void initEcartNormal (TObject* h)
1240 {
1241  h->FDeg = h->pFDeg();
1242  h->ecart = h->pLDeg() - h->FDeg;
1243  // h->length is set by h->pLDeg
1244  h->length=h->pLength=pLength(h->p);
1245 }
1247 void initEcartBBA (TObject* h)
1248 {
1249  h->FDeg = h->pFDeg();
1250  (*h).ecart = 0;
1251  h->length=h->pLength=pLength(h->p);
1252 }
1254 void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1255 {
1256  Lp->FDeg = Lp->pFDeg();
1257  (*Lp).ecart = 0;
1258  (*Lp).length = 0;
1259 }
1261 void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1262 {
1263  Lp->FDeg = Lp->pFDeg();
1264  (*Lp).ecart = si_max(ecartF,ecartG);
1265  (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1266  (*Lp).length = 0;
1267 }
1268 
1269 /*2
1270 *if ecart1<=ecart2 it returns TRUE
1271 */
1272 static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1273 {
1274  return (ecart1 <= ecart2);
1275 }
1276 
1277 #ifdef HAVE_RINGS
1278 /*2
1279 * put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1280 */
1281 static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1282 {
1283  assume(atR >= 0);
1284  assume(i<=strat->sl);
1285  assume(p!=NULL);
1286  #if ALL_VS_JUST
1287  //Over rings, if we construct the strong pair, do not add the spair
1289  {
1290  number s,t,d;
1291  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1292 
1293  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1294  {
1295  nDelete(&d);
1296  nDelete(&s);
1297  nDelete(&t);
1298  return;
1299  }
1300  nDelete(&d);
1301  nDelete(&s);
1302  nDelete(&t);
1303  }
1304  #endif
1305  int j,compare,compareCoeff;
1306  LObject h;
1307 
1308 #ifdef KDEBUG
1309  h.ecart=0; h.length=0;
1310 #endif
1311  /*- computes the lcm(s[i],p) -*/
1312  h.lcm = p_Lcm(p,strat->S[i],currRing);
1313  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1314  if (nIsZero(pGetCoeff(h.lcm)))
1315  {
1316  strat->cp++;
1317  pLmDelete(h.lcm);
1318  return;
1319  }
1320  // basic chain criterion
1321  /*
1322  *the set B collects the pairs of type (S[j],p)
1323  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1324  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
1325  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
1326  */
1327 
1328  for(j = strat->Bl;j>=0;j--)
1329  {
1330  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1331  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1332  if(compare == pDivComp_EQUAL)
1333  {
1334  //They have the same LM
1335  if(compareCoeff == pDivComp_LESS)
1336  {
1337  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1338  {
1339  strat->c3++;
1340  pLmDelete(h.lcm);
1341  return;
1342  }
1343  break;
1344  }
1345  if(compareCoeff == pDivComp_GREATER)
1346  {
1347  deleteInL(strat->B,&strat->Bl,j,strat);
1348  strat->c3++;
1349  }
1350  if(compareCoeff == pDivComp_EQUAL)
1351  {
1352  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1353  {
1354  strat->c3++;
1355  pLmDelete(h.lcm);
1356  return;
1357  }
1358  break;
1359  }
1360  }
1361  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1362  {
1363  if(compare == pDivComp_LESS)
1364  {
1365  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1366  {
1367  strat->c3++;
1368  pLmDelete(h.lcm);
1369  return;
1370  }
1371  break;
1372  }
1373  if(compare == pDivComp_GREATER)
1374  {
1375  deleteInL(strat->B,&strat->Bl,j,strat);
1376  strat->c3++;
1377  }
1378  }
1379  }
1380  number s, t;
1381  poly m1, m2, gcd = NULL;
1382  s = pGetCoeff(strat->S[i]);
1383  t = pGetCoeff(p);
1384  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1385  ksCheckCoeff(&s, &t, currRing->cf);
1386  pSetCoeff0(m1, s);
1387  pSetCoeff0(m2, t);
1388  m2 = pNeg(m2);
1389  p_Test(m1,strat->tailRing);
1390  p_Test(m2,strat->tailRing);
1391  poly si = pCopy(strat->S[i]);
1392  poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1393  poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1394  pDelete(&si);
1395  if(sim2 == NULL)
1396  {
1397  pDelete(&m1);
1398  pDelete(&m2);
1399  if(pm1 == NULL)
1400  {
1401  if(h.lcm != NULL)
1402  {
1403  pLmDelete(h.lcm);
1404  h.lcm=NULL;
1405  }
1406  h.Clear();
1407  if (strat->pairtest==NULL) initPairtest(strat);
1408  strat->pairtest[i] = TRUE;
1409  strat->pairtest[strat->sl+1] = TRUE;
1410  return;
1411  }
1412  else
1413  {
1414  gcd = pm1;
1415  pm1 = NULL;
1416  }
1417  }
1418  else
1419  {
1420  if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1421  {
1422  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1423  pSetmComp(sim2);
1424  }
1425  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1426  gcd = p_Add_q(pm1, sim2, strat->tailRing);
1427  }
1428  p_Test(gcd, strat->tailRing);
1429  //p_LmDelete(m1, strat->tailRing);
1430  //p_LmDelete(m2, strat->tailRing);
1431 #ifdef KDEBUG
1432  if (TEST_OPT_DEBUG)
1433  {
1434  wrp(gcd);
1435  PrintLn();
1436  }
1437 #endif
1438  h.p = gcd;
1439  h.i_r = -1;
1440  if(h.p == NULL)
1441  {
1442  if (strat->pairtest==NULL) initPairtest(strat);
1443  strat->pairtest[i] = TRUE;
1444  strat->pairtest[strat->sl+1] = TRUE;
1445  return;
1446  }
1447  h.tailRing = strat->tailRing;
1448  int posx;
1449  //h.pCleardenom();
1450  //pSetm(h.p);
1451  h.i_r1 = -1;h.i_r2 = -1;
1452  strat->initEcart(&h);
1453  #if 1
1454  h.p2 = strat->S[i];
1455  h.p1 = p;
1456  #endif
1457  #if 1
1458  if (atR >= 0)
1459  {
1460  h.i_r1 = atR;
1461  h.i_r2 = strat->S_2_R[i];
1462  }
1463  #endif
1464  if (strat->Bl==-1)
1465  posx =0;
1466  else
1467  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1468  h.sev = pGetShortExpVector(h.p);
1469  if (currRing!=strat->tailRing)
1470  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1471  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1472  kTest_TS(strat);
1473 }
1474 
1475 
1476 /*2
1477 * put the lcm(s[i],p) into the set B
1478 */
1480 static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1481 {
1482  number d, s, t;
1483  assume(atR >= 0);
1484  poly m1, m2, gcd,si;
1485  if(!enterTstrong)
1486  {
1487  assume(i<=strat->sl);
1488  si = strat->S[i];
1489  }
1490  else
1491  {
1492  assume(i<=strat->tl);
1493  si = strat->T[i].p;
1494  }
1495  //printf("\n--------------------------------\n");
1496  //pWrite(p);pWrite(si);
1497  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1498 
1499  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1500  {
1501  nDelete(&d);
1502  nDelete(&s);
1503  nDelete(&t);
1504  return FALSE;
1505  }
1506 
1507  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1508  //p_Test(m1,strat->tailRing);
1509  //p_Test(m2,strat->tailRing);
1510  /*if(!enterTstrong)
1511  {
1512  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1513  {
1514  memset(&(strat->P), 0, sizeof(strat->P));
1515  kStratChangeTailRing(strat);
1516  strat->P = *(strat->R[atR]);
1517  p_LmFree(m1, strat->tailRing);
1518  p_LmFree(m2, strat->tailRing);
1519  p_LmFree(gcd, currRing);
1520  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1521  }
1522  }*/
1523  pSetCoeff0(m1, s);
1524  pSetCoeff0(m2, t);
1525  pSetCoeff0(gcd, d);
1526  p_Test(m1,strat->tailRing);
1527  p_Test(m2,strat->tailRing);
1528  //printf("\n===================================\n");
1529  //pWrite(m1);pWrite(m2);pWrite(gcd);
1530 #ifdef KDEBUG
1531  if (TEST_OPT_DEBUG)
1532  {
1533  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1534  PrintS("m1 = ");
1535  p_wrp(m1, strat->tailRing);
1536  PrintS(" ; m2 = ");
1537  p_wrp(m2, strat->tailRing);
1538  PrintS(" ; gcd = ");
1539  wrp(gcd);
1540  PrintS("\n--- create strong gcd poly: ");
1541  Print("\n p: %d", i);
1542  wrp(p);
1543  Print("\n strat->S[%d]: ", i);
1544  wrp(si);
1545  PrintS(" ---> ");
1546  }
1547 #endif
1548 
1549  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1550  p_LmDelete(m1, strat->tailRing);
1551  p_LmDelete(m2, strat->tailRing);
1552 #ifdef KDEBUG
1553  if (TEST_OPT_DEBUG)
1554  {
1555  wrp(gcd);
1556  PrintLn();
1557  }
1558 #endif
1559 
1560  LObject h;
1561  h.p = gcd;
1562  h.tailRing = strat->tailRing;
1563  int posx;
1564  h.pCleardenom();
1565  strat->initEcart(&h);
1566  h.sev = pGetShortExpVector(h.p);
1567  h.i_r1 = -1;h.i_r2 = -1;
1568  if (currRing!=strat->tailRing)
1569  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1570  if(!enterTstrong)
1571  {
1572  #if 1
1573  h.p1 = p;h.p2 = strat->S[i];
1574  #endif
1575  if (atR >= 0)
1576  {
1577  h.i_r2 = strat->S_2_R[i];
1578  h.i_r1 = atR;
1579  }
1580  else
1581  {
1582  h.i_r1 = -1;
1583  h.i_r2 = -1;
1584  }
1585  if (strat->Ll==-1)
1586  posx =0;
1587  else
1588  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1589  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1590  }
1591  else
1592  {
1593  if(h.IsNull()) return FALSE;
1594  //int red_result;
1595  //reduzieren ist teur!!!
1596  //if(strat->L != NULL)
1597  //red_result = strat->red(&h,strat);
1598  if(!h.IsNull())
1599  {
1600  enterT(h, strat,-1);
1601  //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1602  //strat->enterS(h,pos,strat,-1);
1603  }
1604  }
1605  return TRUE;
1606 }
1609 {
1610  if(strat->sl < 0) return FALSE;
1611  int i;
1612  for(i=0;i<strat->sl;i++)
1613  {
1614  //Construct the gcd pair between h and S[i]
1615  number d, s, t;
1616  poly m1, m2, gcd;
1617  d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1618  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1619  {
1620  nDelete(&d);
1621  nDelete(&s);
1622  nDelete(&t);
1623  }
1624  else
1625  {
1626  k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1627  pSetCoeff0(m1, s);
1628  pSetCoeff0(m2, t);
1629  pSetCoeff0(gcd, d);
1630  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(h->p), m1, strat->tailRing), pp_Mult_mm(pNext(strat->S[i]), m2, strat->tailRing), strat->tailRing);
1631  poly pSigMult = p_Copy(h->sig,currRing);
1632  poly sSigMult = p_Copy(strat->sig[i],currRing);
1633  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1634  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1635  p_LmDelete(m1, strat->tailRing);
1636  p_LmDelete(m2, strat->tailRing);
1637  poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1638  if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1639  {
1640  pDelete(&h->p);
1641  h->p = gcd;
1642  pDelete(&h->sig);
1643  h->sig = pairsig;
1644  pNext(h->sig) = NULL;
1645  strat->initEcart(h);
1646  h->sev = pGetShortExpVector(h->p);
1647  h->sevSig = pGetShortExpVector(h->sig);
1648  h->i_r1 = -1;h->i_r2 = -1;
1649  if(h->lcm != NULL)
1650  {
1651  pLmDelete(h->lcm);
1652  h->lcm = NULL;
1653  }
1654  if (currRing!=strat->tailRing)
1655  h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1656  return TRUE;
1657  }
1658  //Delete what you didn't use
1659  pDelete(&gcd);
1660  pDelete(&pairsig);
1661  }
1662  }
1663  return FALSE;
1664 }
1666 static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1667 {
1668  number d, s, t;
1669  assume(atR >= 0);
1670  poly m1, m2, gcd,si;
1671  assume(i<=strat->sl);
1672  si = strat->S[i];
1673  //printf("\n--------------------------------\n");
1674  //pWrite(p);pWrite(si);
1675  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1676 
1677  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1678  {
1679  nDelete(&d);
1680  nDelete(&s);
1681  nDelete(&t);
1682  return FALSE;
1683  }
1684 
1685  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1686  //p_Test(m1,strat->tailRing);
1687  //p_Test(m2,strat->tailRing);
1688  /*if(!enterTstrong)
1689  {
1690  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1691  {
1692  memset(&(strat->P), 0, sizeof(strat->P));
1693  kStratChangeTailRing(strat);
1694  strat->P = *(strat->R[atR]);
1695  p_LmFree(m1, strat->tailRing);
1696  p_LmFree(m2, strat->tailRing);
1697  p_LmFree(gcd, currRing);
1698  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1699  }
1700  }*/
1701  pSetCoeff0(m1, s);
1702  pSetCoeff0(m2, t);
1703  pSetCoeff0(gcd, d);
1704  p_Test(m1,strat->tailRing);
1705  p_Test(m2,strat->tailRing);
1706  //printf("\n===================================\n");
1707  //pWrite(m1);pWrite(m2);pWrite(gcd);
1708 #ifdef KDEBUG
1709  if (TEST_OPT_DEBUG)
1710  {
1711  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1712  PrintS("m1 = ");
1713  p_wrp(m1, strat->tailRing);
1714  PrintS(" ; m2 = ");
1715  p_wrp(m2, strat->tailRing);
1716  PrintS(" ; gcd = ");
1717  wrp(gcd);
1718  PrintS("\n--- create strong gcd poly: ");
1719  Print("\n p: %d", i);
1720  wrp(p);
1721  Print("\n strat->S[%d]: ", i);
1722  wrp(si);
1723  PrintS(" ---> ");
1724  }
1725 #endif
1726 
1727  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1728 
1729 #ifdef KDEBUG
1730  if (TEST_OPT_DEBUG)
1731  {
1732  wrp(gcd);
1733  PrintLn();
1734  }
1735 #endif
1736 
1737  //Check and set the signatures
1738  poly pSigMult = p_Copy(sig,currRing);
1739  poly sSigMult = p_Copy(strat->sig[i],currRing);
1740  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1741  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1742  p_LmDelete(m1, strat->tailRing);
1743  p_LmDelete(m2, strat->tailRing);
1744  poly pairsig;
1745  if(pLmCmp(pSigMult,sSigMult) == 0)
1746  {
1747  //Same lm, have to add them
1748  pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1749  //This might be zero
1750  }
1751  else
1752  {
1753  //Set the sig to either pSigMult or sSigMult
1754  if(pLtCmp(pSigMult,sSigMult)==1)
1755  {
1756  pairsig = pSigMult;
1757  pDelete(&sSigMult);
1758  }
1759  else
1760  {
1761  pairsig = sSigMult;
1762  pDelete(&pSigMult);
1763  }
1764  }
1765 
1766  LObject h;
1767  h.p = gcd;
1768  h.tailRing = strat->tailRing;
1769  h.sig = pairsig;
1770  int posx;
1771  h.pCleardenom();
1772  strat->initEcart(&h);
1773  h.sev = pGetShortExpVector(h.p);
1774  h.i_r1 = -1;h.i_r2 = -1;
1775  if (currRing!=strat->tailRing)
1776  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1777  if(h.sig == NULL)
1778  {
1779  //sigdrop since we loose the signature
1780  strat->sigdrop = TRUE;
1781  //Try to reduce it as far as we can via redRing
1782  int red_result = redRing(&h,strat);
1783  if(red_result == 0)
1784  {
1785  // Cancel the sigdrop
1786  p_Delete(&h.sig,currRing);h.sig = NULL;
1787  strat->sigdrop = FALSE;
1788  return FALSE;
1789  }
1790  else
1791  {
1792  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1793  #if 1
1794  strat->enterS(h,0,strat,strat->tl);
1795  #endif
1796  return FALSE;
1797  }
1798  }
1799  if(!nGreaterZero(pGetCoeff(h.sig)))
1800  {
1801  h.sig = pNeg(h.sig);
1802  h.p = pNeg(h.p);
1803  }
1804 
1805  if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1806  {
1807  strat->sigdrop = TRUE;
1808  // Completely reduce it
1809  int red_result = redRing(&h,strat);
1810  if(red_result == 0)
1811  {
1812  // Reduced to 0
1813  strat->sigdrop = FALSE;
1814  p_Delete(&h.sig,currRing);h.sig = NULL;
1815  return FALSE;
1816  }
1817  else
1818  {
1819  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1820  // 0 - add just the original poly causing the sigdrop, 1 - add also this
1821  #if 1
1822  strat->enterS(h,0,strat, strat->tl+1);
1823  #endif
1824  return FALSE;
1825  }
1826  }
1827  //Check for sigdrop
1828  if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1829  {
1830  strat->sigdrop = TRUE;
1831  //Enter this element to S
1832  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1833  strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1834  }
1835  #if 1
1836  h.p1 = p;h.p2 = strat->S[i];
1837  #endif
1838  if (atR >= 0)
1839  {
1840  h.i_r2 = strat->S_2_R[i];
1841  h.i_r1 = atR;
1842  }
1843  else
1844  {
1845  h.i_r1 = -1;
1846  h.i_r2 = -1;
1847  }
1848  if (strat->Ll==-1)
1849  posx =0;
1850  else
1851  posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1852  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1853  return TRUE;
1854 }
1855 #endif
1856 
1857 /*2
1858 * put the pair (s[i],p) into the set B, ecart=ecart(p)
1859 */
1861 void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1862 {
1863  assume(i<=strat->sl);
1864 
1865  int l,j,compare;
1866  LObject Lp;
1867  Lp.i_r = -1;
1868 
1869 #ifdef KDEBUG
1870  Lp.ecart=0; Lp.length=0;
1871 #endif
1872  /*- computes the lcm(s[i],p) -*/
1873  Lp.lcm = pInit();
1874 
1875 #ifndef HAVE_RATGRING
1876  pLcm(p,strat->S[i],Lp.lcm);
1877 #elif defined(HAVE_RATGRING)
1878  if (rIsRatGRing(currRing))
1879  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1880  else
1881  pLcm(p,strat->S[i],Lp.lcm);
1882 #endif
1883  pSetm(Lp.lcm);
1884 
1885 
1886  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
1887  {
1888  if((!((strat->ecartS[i]>0)&&(ecart>0)))
1889  && pHasNotCF(p,strat->S[i]))
1890  {
1891  /*
1892  *the product criterion has applied for (s,p),
1893  *i.e. lcm(s,p)=product of the leading terms of s and p.
1894  *Suppose (s,r) is in L and the leading term
1895  *of p divides lcm(s,r)
1896  *(==> the leading term of p divides the leading term of r)
1897  *but the leading term of s does not divide the leading term of r
1898  *(notice that tis condition is automatically satisfied if r is still
1899  *in S), then (s,r) can be cancelled.
1900  *This should be done here because the
1901  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1902  *
1903  *Moreover, skipping (s,r) holds also for the noncommutative case.
1904  */
1905  strat->cp++;
1906  pLmFree(Lp.lcm);
1907  return;
1908  }
1909  else
1910  Lp.ecart = si_max(ecart,strat->ecartS[i]);
1911  if (strat->fromT && (strat->ecartS[i]>ecart))
1912  {
1913  pLmFree(Lp.lcm);
1914  return;
1915  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
1916  }
1917  /*
1918  *the set B collects the pairs of type (S[j],p)
1919  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
1920  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
1921  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
1922  */
1923  {
1924  j = strat->Bl;
1925  loop
1926  {
1927  if (j < 0) break;
1928  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
1929  if ((compare==1)
1930  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
1931  {
1932  strat->c3++;
1933  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1934  {
1935  pLmFree(Lp.lcm);
1936  return;
1937  }
1938  break;
1939  }
1940  else
1941  if ((compare ==-1)
1942  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
1943  {
1944  deleteInL(strat->B,&strat->Bl,j,strat);
1945  strat->c3++;
1946  }
1947  j--;
1948  }
1949  }
1950  }
1951  else /*sugarcrit*/
1952  {
1953  if (ALLOW_PROD_CRIT(strat))
1954  {
1955  // if currRing->nc_type!=quasi (or skew)
1956  // TODO: enable productCrit for super commutative algebras...
1957  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
1958  pHasNotCF(p,strat->S[i]))
1959  {
1960  /*
1961  *the product criterion has applied for (s,p),
1962  *i.e. lcm(s,p)=product of the leading terms of s and p.
1963  *Suppose (s,r) is in L and the leading term
1964  *of p devides lcm(s,r)
1965  *(==> the leading term of p devides the leading term of r)
1966  *but the leading term of s does not devide the leading term of r
1967  *(notice that tis condition is automatically satisfied if r is still
1968  *in S), then (s,r) can be canceled.
1969  *This should be done here because the
1970  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1971  */
1972  strat->cp++;
1973  pLmFree(Lp.lcm);
1974  return;
1975  }
1976  if (strat->fromT && (strat->ecartS[i]>ecart))
1977  {
1978  pLmFree(Lp.lcm);
1979  return;
1980  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
1981  }
1982  /*
1983  *the set B collects the pairs of type (S[j],p)
1984  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
1985  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
1986  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
1987  */
1988  for(j = strat->Bl;j>=0;j--)
1989  {
1990  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
1991  if (compare==1)
1992  {
1993  strat->c3++;
1994  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1995  {
1996  pLmFree(Lp.lcm);
1997  return;
1998  }
1999  break;
2000  }
2001  else
2002  if (compare ==-1)
2003  {
2004  deleteInL(strat->B,&strat->Bl,j,strat);
2005  strat->c3++;
2006  }
2007  }
2008  }
2009  }
2010  /*
2011  *the pair (S[i],p) enters B if the spoly != 0
2012  */
2013  /*- compute the short s-polynomial -*/
2014  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2015  pNorm(p);
2016 
2017  if ((strat->S[i]==NULL) || (p==NULL))
2018  return;
2019 
2020  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2021  Lp.p=NULL;
2022  else
2023  {
2024  #ifdef HAVE_PLURAL
2025  if ( rIsPluralRing(currRing) )
2026  {
2027  if(pHasNotCF(p, strat->S[i]))
2028  {
2029  if(ncRingType(currRing) == nc_lie)
2030  {
2031  // generalized prod-crit for lie-type
2032  strat->cp++;
2033  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2034  }
2035  else
2036  if( ALLOW_PROD_CRIT(strat) )
2037  {
2038  // product criterion for homogeneous case in SCA
2039  strat->cp++;
2040  Lp.p = NULL;
2041  }
2042  else
2043  {
2044  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2045  nc_CreateShortSpoly(strat->S[i], p, currRing);
2046  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2047  pNext(Lp.p) = strat->tail; // !!!
2048  }
2049  }
2050  else
2051  {
2052  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2053  nc_CreateShortSpoly(strat->S[i], p, currRing);
2054 
2055  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2056  pNext(Lp.p) = strat->tail; // !!!
2057  }
2058  }
2059  else
2060  #endif
2061  {
2063  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2064  }
2065  }
2066  if (Lp.p == NULL)
2067  {
2068  /*- the case that the s-poly is 0 -*/
2069  if (strat->pairtest==NULL) initPairtest(strat);
2070  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2071  strat->pairtest[strat->sl+1] = TRUE;
2072  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2073  /*
2074  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2075  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2076  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2077  *term of p devides the lcm(s,r)
2078  *(this canceling should be done here because
2079  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2080  *the first case is handeled in chainCrit
2081  */
2082  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2083  }
2084  else
2085  {
2086  /*- the pair (S[i],p) enters B -*/
2087  Lp.p1 = strat->S[i];
2088  Lp.p2 = p;
2089 
2090  if (
2092 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2093  )
2094  {
2095  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2096  pNext(Lp.p) = strat->tail; // !!!
2097  }
2098 
2099  if (atR >= 0)
2100  {
2101  Lp.i_r1 = strat->S_2_R[i];
2102  Lp.i_r2 = atR;
2103  }
2104  else
2105  {
2106  Lp.i_r1 = -1;
2107  Lp.i_r2 = -1;
2108  }
2109  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2110 
2112  {
2113  if (!rIsPluralRing(currRing)
2115  && (Lp.p->coef!=NULL))
2116  nDelete(&(Lp.p->coef));
2117  }
2118 
2119  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2120  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2121  }
2122 }
2123 
2124 /// p_HasNotCF for the IDLIFT case: ignore component
2125 static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2126 {
2127  int i = rVar(r);
2128  loop
2129  {
2130  if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2131  return FALSE;
2132  i--;
2133  if (i == 0)
2134  return TRUE;
2135  }
2136 }
2137 
2138 /*2
2139 * put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2140 */
2142 static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2143 {
2144  assume(ALLOW_PROD_CRIT(strat));
2146  assume(strat->syzComp==1);
2147  assume(i<=strat->sl);
2148 
2149  if ((strat->S[i]==NULL) || (p==NULL))
2150  return;
2151 
2152  int l,j,compare;
2153  LObject Lp;
2154  Lp.i_r = -1;
2155 
2156 #ifdef KDEBUG
2157  Lp.ecart=0; Lp.length=0;
2158 #endif
2159  /*- computes the lcm(s[i],p) -*/
2160  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2161 
2162  if (strat->sugarCrit)
2163  {
2164  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2165  && p_HasNotCF_Lift(p,strat->S[i],currRing))
2166  {
2167  /*
2168  *the product criterion has applied for (s,p),
2169  *i.e. lcm(s,p)=product of the leading terms of s and p.
2170  *Suppose (s,r) is in L and the leading term
2171  *of p divides lcm(s,r)
2172  *(==> the leading term of p divides the leading term of r)
2173  *but the leading term of s does not divide the leading term of r
2174  *(notice that tis condition is automatically satisfied if r is still
2175  *in S), then (s,r) can be cancelled.
2176  *This should be done here because the
2177  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2178  *
2179  *Moreover, skipping (s,r) holds also for the noncommutative case.
2180  */
2181  strat->cp++;
2182  pLmFree(Lp.lcm);
2183  return;
2184  }
2185  else
2186  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2187  if (strat->fromT && (strat->ecartS[i]>ecart))
2188  {
2189  pLmFree(Lp.lcm);
2190  return;
2191  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2192  }
2193  /*
2194  *the set B collects the pairs of type (S[j],p)
2195  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2196  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2197  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2198  */
2199  {
2200  j = strat->Bl;
2201  loop
2202  {
2203  if (j < 0) break;
2204  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2205  if ((compare==1)
2206  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2207  {
2208  strat->c3++;
2209  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2210  {
2211  pLmFree(Lp.lcm);
2212  return;
2213  }
2214  break;
2215  }
2216  else
2217  if ((compare ==-1)
2218  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2219  {
2220  deleteInL(strat->B,&strat->Bl,j,strat);
2221  strat->c3++;
2222  }
2223  j--;
2224  }
2225  }
2226  }
2227  else /*sugarcrit*/
2228  {
2229  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2230  p_HasNotCF_Lift(p,strat->S[i],currRing))
2231  {
2232  /*
2233  *the product criterion has applied for (s,p),
2234  *i.e. lcm(s,p)=product of the leading terms of s and p.
2235  *Suppose (s,r) is in L and the leading term
2236  *of p devides lcm(s,r)
2237  *(==> the leading term of p devides the leading term of r)
2238  *but the leading term of s does not devide the leading term of r
2239  *(notice that tis condition is automatically satisfied if r is still
2240  *in S), then (s,r) can be canceled.
2241  *This should be done here because the
2242  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2243  */
2244  strat->cp++;
2245  pLmFree(Lp.lcm);
2246  return;
2247  }
2248  if (strat->fromT && (strat->ecartS[i]>ecart))
2249  {
2250  pLmFree(Lp.lcm);
2251  return;
2252  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2253  }
2254  /*
2255  *the set B collects the pairs of type (S[j],p)
2256  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2257  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2258  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2259  */
2260  for(j = strat->Bl;j>=0;j--)
2261  {
2262  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2263  if (compare==1)
2264  {
2265  strat->c3++;
2266  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2267  {
2268  pLmFree(Lp.lcm);
2269  return;
2270  }
2271  break;
2272  }
2273  else
2274  if (compare ==-1)
2275  {
2276  deleteInL(strat->B,&strat->Bl,j,strat);
2277  strat->c3++;
2278  }
2279  }
2280  }
2281  /*
2282  *the pair (S[i],p) enters B if the spoly != 0
2283  */
2284  /*- compute the short s-polynomial -*/
2285  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2286  pNorm(p);
2287 
2288  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2289  Lp.p=NULL;
2290  else
2291  {
2293  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2294  }
2295  if (Lp.p == NULL)
2296  {
2297  /*- the case that the s-poly is 0 -*/
2298  if (strat->pairtest==NULL) initPairtest(strat);
2299  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2300  strat->pairtest[strat->sl+1] = TRUE;
2301  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2302  /*
2303  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2304  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2305  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2306  *term of p devides the lcm(s,r)
2307  *(this canceling should be done here because
2308  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2309  *the first case is handeled in chainCrit
2310  */
2311  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2312  }
2313  else
2314  {
2315  /*- the pair (S[i],p) enters B -*/
2316  Lp.p1 = strat->S[i];
2317  Lp.p2 = p;
2318 
2319  pNext(Lp.p) = strat->tail; // !!!
2320 
2321  if (atR >= 0)
2322  {
2323  Lp.i_r1 = strat->S_2_R[i];
2324  Lp.i_r2 = atR;
2325  }
2326  else
2327  {
2328  Lp.i_r1 = -1;
2329  Lp.i_r2 = -1;
2330  }
2331  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2332 
2334  {
2335  if (!rIsPluralRing(currRing)
2337  && (Lp.p->coef!=NULL))
2338  nDelete(&(Lp.p->coef));
2339  }
2340 
2341  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2342  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2343  }
2344 }
2345 
2346 /*2
2347 * put the pair (s[i],p) into the set B, ecart=ecart(p)
2348 * NOTE: here we need to add the signature-based criteria
2349 */
2350 
2351 #ifdef DEBUGF5
2352 static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2353 #else
2354 static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2355 #endif
2356 {
2357  assume(i<=strat->sl);
2358 
2359  int l;
2360  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2361  // the corresponding signatures for criteria checks
2362  LObject Lp;
2363  poly pSigMult = p_Copy(pSig,currRing);
2364  poly sSigMult = p_Copy(strat->sig[i],currRing);
2365  unsigned long pSigMultNegSev,sSigMultNegSev;
2366  Lp.i_r = -1;
2367 
2368 #ifdef KDEBUG
2369  Lp.ecart=0; Lp.length=0;
2370 #endif
2371  /*- computes the lcm(s[i],p) -*/
2372  Lp.lcm = pInit();
2373  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2374 #ifndef HAVE_RATGRING
2375  pLcm(p,strat->S[i],Lp.lcm);
2376 #elif defined(HAVE_RATGRING)
2377  if (rIsRatGRing(currRing))
2378  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2379  else
2380  pLcm(p,strat->S[i],Lp.lcm);
2381 #endif
2382  pSetm(Lp.lcm);
2383 
2384  // set coeffs of multipliers m1 and m2
2385  pSetCoeff0(m1, nInit(1));
2386  pSetCoeff0(m2, nInit(1));
2387 //#if 1
2388 #ifdef DEBUGF5
2389  PrintS("P1 ");
2390  pWrite(pHead(p));
2391  PrintS("P2 ");
2392  pWrite(pHead(strat->S[i]));
2393  PrintS("M1 ");
2394  pWrite(m1);
2395  PrintS("M2 ");
2396  pWrite(m2);
2397 #endif
2398  // get multiplied signatures for testing
2399  pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2400  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2401  sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2402  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2403 
2404 //#if 1
2405 #ifdef DEBUGF5
2406  PrintS("----------------\n");
2407  pWrite(pSigMult);
2408  pWrite(sSigMult);
2409  PrintS("----------------\n");
2410  Lp.checked = 0;
2411 #endif
2412  int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2413 //#if 1
2414 #if DEBUGF5
2415  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2416  pWrite(pSigMult);
2417  pWrite(sSigMult);
2418 #endif
2419  if(sigCmp==0)
2420  {
2421  // printf("!!!! EQUAL SIGS !!!!\n");
2422  // pSig = sSig, delete element due to Rewritten Criterion
2423  pDelete(&pSigMult);
2424  pDelete(&sSigMult);
2425  if (rField_is_Ring(currRing))
2426  pLmDelete(Lp.lcm);
2427  else
2428  pLmFree(Lp.lcm);
2429  pDelete (&m1);
2430  pDelete (&m2);
2431  return;
2432  }
2433  // testing by syzCrit = F5 Criterion
2434  // testing by rewCrit1 = Rewritten Criterion
2435  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2436  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2437  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2438  || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2439  )
2440  {
2441  pDelete(&pSigMult);
2442  pDelete(&sSigMult);
2443  if (rField_is_Ring(currRing))
2444  pLmDelete(Lp.lcm);
2445  else
2446  pLmFree(Lp.lcm);
2447  pDelete (&m1);
2448  pDelete (&m2);
2449  return;
2450  }
2451  /*
2452  *the pair (S[i],p) enters B if the spoly != 0
2453  */
2454  /*- compute the short s-polynomial -*/
2455  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2456  pNorm(p);
2457 
2458  if ((strat->S[i]==NULL) || (p==NULL))
2459  return;
2460 
2461  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2462  Lp.p=NULL;
2463  else
2464  {
2465  #ifdef HAVE_PLURAL
2466  if ( rIsPluralRing(currRing) )
2467  {
2468  if(pHasNotCF(p, strat->S[i]))
2469  {
2470  if(ncRingType(currRing) == nc_lie)
2471  {
2472  // generalized prod-crit for lie-type
2473  strat->cp++;
2474  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2475  }
2476  else
2477  if( ALLOW_PROD_CRIT(strat) )
2478  {
2479  // product criterion for homogeneous case in SCA
2480  strat->cp++;
2481  Lp.p = NULL;
2482  }
2483  else
2484  {
2485  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2486  nc_CreateShortSpoly(strat->S[i], p, currRing);
2487 
2488  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2489  pNext(Lp.p) = strat->tail; // !!!
2490  }
2491  }
2492  else
2493  {
2494  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2495  nc_CreateShortSpoly(strat->S[i], p, currRing);
2496 
2497  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2498  pNext(Lp.p) = strat->tail; // !!!
2499  }
2500  }
2501  else
2502  #endif
2503  {
2505  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2506  }
2507  }
2508  // store from which element this pair comes from for further tests
2509  //Lp.from = strat->sl+1;
2510  if(sigCmp==currRing->OrdSgn)
2511  {
2512  // pSig > sSig
2513  pDelete (&sSigMult);
2514  Lp.sig = pSigMult;
2515  Lp.sevSig = ~pSigMultNegSev;
2516  }
2517  else
2518  {
2519  // pSig < sSig
2520  pDelete (&pSigMult);
2521  Lp.sig = sSigMult;
2522  Lp.sevSig = ~sSigMultNegSev;
2523  }
2524  if (Lp.p == NULL)
2525  {
2526  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2527  int pos = posInSyz(strat, Lp.sig);
2528  enterSyz(Lp, strat, pos);
2529  }
2530  else
2531  {
2532  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2533  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2534  {
2535  pLmFree(Lp.lcm);
2536  pDelete(&Lp.sig);
2537  pDelete (&m1);
2538  pDelete (&m2);
2539  return;
2540  }
2541  // in any case Lp is checked up to the next strat->P which is added
2542  // to S right after this critical pair creation.
2543  // NOTE: this even holds if the 2nd generator gives the bigger signature
2544  // moreover, this improves rewCriterion,
2545  // i.e. strat->checked > strat->from if and only if the 2nd generator
2546  // gives the bigger signature.
2547  Lp.checked = strat->sl+1;
2548  // at this point it is clear that the pair will be added to L, since it has
2549  // passed all tests up to now
2550 
2551  // adds buchberger's first criterion
2552  if (pLmCmp(m2,pHead(p)) == 0)
2553  {
2554  Lp.prod_crit = TRUE; // Product Criterion
2555 #if 0
2556  int pos = posInSyz(strat, Lp.sig);
2557  enterSyz(Lp, strat, pos);
2558  pDelete (&m1);
2559  pDelete (&m2);
2560  return;
2561 #endif
2562  }
2563  pDelete (&m1);
2564  pDelete (&m2);
2565 #if DEBUGF5
2566  PrintS("SIGNATURE OF PAIR: ");
2567  pWrite(Lp.sig);
2568 #endif
2569  /*- the pair (S[i],p) enters B -*/
2570  Lp.p1 = strat->S[i];
2571  Lp.p2 = p;
2572 
2573  if (
2575 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2576  )
2577  {
2578  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2579  pNext(Lp.p) = strat->tail; // !!!
2580  }
2581 
2582  if (atR >= 0)
2583  {
2584  Lp.i_r1 = strat->S_2_R[i];
2585  Lp.i_r2 = atR;
2586  }
2587  else
2588  {
2589  Lp.i_r1 = -1;
2590  Lp.i_r2 = -1;
2591  }
2592  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2593 
2595  {
2596  if (!rIsPluralRing(currRing)
2598  && (Lp.p->coef!=NULL))
2599  nDelete(&(Lp.p->coef));
2600  }
2601 
2602  l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2603  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2604  }
2605 }
2606 
2607 
2608 #ifdef DEBUGF5
2609 static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2610 #else
2611 static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2612 #endif
2613 {
2614  #if ALL_VS_JUST
2615  //Over rings, if we construct the strong pair, do not add the spair
2617  {
2618  number s,t,d;
2619  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2620 
2621  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2622  {
2623  nDelete(&d);
2624  nDelete(&s);
2625  nDelete(&t);
2626  return;
2627  }
2628  nDelete(&d);
2629  nDelete(&s);
2630  nDelete(&t);
2631  }
2632  #endif
2633  assume(i<=strat->sl);
2634  int l;
2635  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2636  // the corresponding signatures for criteria checks
2637  LObject Lp;
2638  poly pSigMult = p_Copy(pSig,currRing);
2639  poly sSigMult = p_Copy(strat->sig[i],currRing);
2640  unsigned long pSigMultNegSev,sSigMultNegSev;
2641  Lp.i_r = -1;
2642 
2643 #ifdef KDEBUG
2644  Lp.ecart=0; Lp.length=0;
2645 #endif
2646  /*- computes the lcm(s[i],p) -*/
2647  Lp.lcm = pInit();
2648  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2649 #ifndef HAVE_RATGRING
2650  pLcm(p,strat->S[i],Lp.lcm);
2651 #elif defined(HAVE_RATGRING)
2652  if (rIsRatGRing(currRing))
2653  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2654  else
2655  pLcm(p,strat->S[i],Lp.lcm);
2656 #endif
2657  pSetm(Lp.lcm);
2658 
2659  // set coeffs of multipliers m1 and m2
2661  {
2662  number s = nCopy(pGetCoeff(strat->S[i]));
2663  number t = nCopy(pGetCoeff(p));
2664  pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2665  ksCheckCoeff(&s, &t, currRing->cf);
2666  pSetCoeff0(m1,s);
2667  pSetCoeff0(m2,t);
2668  }
2669  else
2670  {
2671  pSetCoeff0(m1, nInit(1));
2672  pSetCoeff0(m2, nInit(1));
2673  }
2674 #ifdef DEBUGF5
2675  Print("P1 ");
2676  pWrite(pHead(p));
2677  Print("P2 ");
2678  pWrite(pHead(strat->S[i]));
2679  Print("M1 ");
2680  pWrite(m1);
2681  Print("M2 ");
2682  pWrite(m2);
2683 #endif
2684 
2685  // get multiplied signatures for testing
2686  pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2687  if(pSigMult != NULL)
2688  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2689  sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2690  if(sSigMult != NULL)
2691  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2692 //#if 1
2693 #ifdef DEBUGF5
2694  Print("----------------\n");
2695  pWrite(pSigMult);
2696  pWrite(sSigMult);
2697  Print("----------------\n");
2698  Lp.checked = 0;
2699 #endif
2700  int sigCmp;
2701  if(pSigMult != NULL && sSigMult != NULL)
2702  {
2704  sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2705  else
2706  sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2707  }
2708  else
2709  {
2710  if(pSigMult == NULL)
2711  {
2712  if(sSigMult == NULL)
2713  sigCmp = 0;
2714  else
2715  sigCmp = -1;
2716  }
2717  else
2718  sigCmp = 1;
2719  }
2720 //#if 1
2721 #if DEBUGF5
2722  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2723  pWrite(pSigMult);
2724  pWrite(sSigMult);
2725 #endif
2726  //In the ring case we already build the sig
2728  {
2729  if(sigCmp == 0)
2730  {
2731  //sigdrop since we loose the signature
2732  strat->sigdrop = TRUE;
2733  //Try to reduce it as far as we can via redRing
2735  {
2736  poly p1 = p_Copy(p,currRing);
2737  poly p2 = p_Copy(strat->S[i],currRing);
2738  p1 = p_Mult_mm(p1,m1,currRing);
2739  p2 = p_Mult_mm(p2,m2,currRing);
2740  Lp.p = p_Sub(p1,p2,currRing);
2741  if(Lp.p != NULL)
2742  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2743  }
2744  int red_result = redRing(&Lp,strat);
2745  if(red_result == 0)
2746  {
2747  // Cancel the sigdrop
2748  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2749  strat->sigdrop = FALSE;
2750  return;
2751  }
2752  else
2753  {
2754  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2755  #if 1
2756  strat->enterS(Lp,0,strat,strat->tl);
2757  #endif
2758  return;
2759  }
2760  }
2761  if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2762  {
2763  //Same lm, have to substract
2764  Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2765  }
2766  else
2767  {
2768  if(sigCmp == 1)
2769  {
2770  Lp.sig = pCopy(pSigMult);
2771  }
2772  if(sigCmp == -1)
2773  {
2774  Lp.sig = pNeg(pCopy(sSigMult));
2775  }
2776  }
2777  Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2778  }
2779 
2780  #if 0
2781  if(sigCmp==0)
2782  {
2783  // printf("!!!! EQUAL SIGS !!!!\n");
2784  // pSig = sSig, delete element due to Rewritten Criterion
2785  pDelete(&pSigMult);
2786  pDelete(&sSigMult);
2787  if (rField_is_Ring(currRing))
2788  pLmDelete(Lp.lcm);
2789  else
2790  pLmFree(Lp.lcm);
2791  pDelete (&m1);
2792  pDelete (&m2);
2793  return;
2794  }
2795  #endif
2796  // testing by syzCrit = F5 Criterion
2797  // testing by rewCrit1 = Rewritten Criterion
2798  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2799  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2800  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2801  // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2802  //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2803  )
2804  {
2805  pDelete(&pSigMult);
2806  pDelete(&sSigMult);
2807  if (rField_is_Ring(currRing))
2808  pLmDelete(Lp.lcm);
2809  else
2810  pLmFree(Lp.lcm);
2811  pDelete (&m1);
2812  pDelete (&m2);
2813  return;
2814  }
2815  /*
2816  *the pair (S[i],p) enters B if the spoly != 0
2817  */
2818  /*- compute the short s-polynomial -*/
2819  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2820  pNorm(p);
2821 
2822  if ((strat->S[i]==NULL) || (p==NULL))
2823  return;
2824 
2825  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2826  Lp.p=NULL;
2827  else
2828  {
2829  //Build p
2831  {
2832  poly p1 = p_Copy(p,currRing);
2833  poly p2 = p_Copy(strat->S[i],currRing);
2834  p1 = p_Mult_mm(p1,m1,currRing);
2835  p2 = p_Mult_mm(p2,m2,currRing);
2836  Lp.p = p_Sub(p1,p2,currRing);
2837  if(Lp.p != NULL)
2838  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2839  }
2840  else
2841  {
2842  #ifdef HAVE_PLURAL
2843  if ( rIsPluralRing(currRing) )
2844  {
2845  if(ncRingType(currRing) == nc_lie)
2846  {
2847  // generalized prod-crit for lie-type
2848  strat->cp++;
2849  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2850  }
2851  else
2852  if( ALLOW_PROD_CRIT(strat) )
2853  {
2854  // product criterion for homogeneous case in SCA
2855  strat->cp++;
2856  Lp.p = NULL;
2857  }
2858  else
2859  {
2860  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2861  nc_CreateShortSpoly(strat->S[i], p, currRing);
2862 
2863  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2864  pNext(Lp.p) = strat->tail; // !!!
2865  }
2866  }
2867  else
2868  #endif
2869  {
2871  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2872  }
2873  }
2874  }
2875  // store from which element this pair comes from for further tests
2876  //Lp.from = strat->sl+1;
2878  {
2879  //Put the sig to be > 0
2880  if(!nGreaterZero(pGetCoeff(Lp.sig)))
2881  {
2882  Lp.sig = pNeg(Lp.sig);
2883  Lp.p = pNeg(Lp.p);
2884  }
2885  }
2886  else
2887  {
2888  if(sigCmp==currRing->OrdSgn)
2889  {
2890  // pSig > sSig
2891  pDelete (&sSigMult);
2892  Lp.sig = pSigMult;
2893  Lp.sevSig = ~pSigMultNegSev;
2894  }
2895  else
2896  {
2897  // pSig < sSig
2898  pDelete (&pSigMult);
2899  Lp.sig = sSigMult;
2900  Lp.sevSig = ~sSigMultNegSev;
2901  }
2902  }
2903  if (Lp.p == NULL)
2904  {
2905  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2906  int pos = posInSyz(strat, Lp.sig);
2907  enterSyz(Lp, strat, pos);
2908  }
2909  else
2910  {
2911  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2912  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2913  {
2914  pLmFree(Lp.lcm);
2915  pDelete(&Lp.sig);
2916  pDelete (&m1);
2917  pDelete (&m2);
2918  return;
2919  }
2920  // in any case Lp is checked up to the next strat->P which is added
2921  // to S right after this critical pair creation.
2922  // NOTE: this even holds if the 2nd generator gives the bigger signature
2923  // moreover, this improves rewCriterion,
2924  // i.e. strat->checked > strat->from if and only if the 2nd generator
2925  // gives the bigger signature.
2926  Lp.checked = strat->sl+1;
2927  // at this point it is clear that the pair will be added to L, since it has
2928  // passed all tests up to now
2929 
2930  // adds buchberger's first criterion
2931  if (pLmCmp(m2,pHead(p)) == 0)
2932  {
2933  Lp.prod_crit = TRUE; // Product Criterion
2934 #if 0
2935  int pos = posInSyz(strat, Lp.sig);
2936  enterSyz(Lp, strat, pos);
2937  pDelete (&m1);
2938  pDelete (&m2);
2939  return;
2940 #endif
2941  }
2942  pDelete (&m1);
2943  pDelete (&m2);
2944 #if DEBUGF5
2945  PrintS("SIGNATURE OF PAIR: ");
2946  pWrite(Lp.sig);
2947 #endif
2948  /*- the pair (S[i],p) enters B -*/
2949  Lp.p1 = strat->S[i];
2950  Lp.p2 = p;
2951 
2952  if (
2954 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2956  )
2957  {
2958  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2959  pNext(Lp.p) = strat->tail; // !!!
2960  }
2961 
2962  if (atR >= 0)
2963  {
2964  Lp.i_r1 = strat->S_2_R[i];
2965  Lp.i_r2 = atR;
2966  }
2967  else
2968  {
2969  Lp.i_r1 = -1;
2970  Lp.i_r2 = -1;
2971  }
2972  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2973 
2975  {
2976  if (!rIsPluralRing(currRing)
2978  && (Lp.p->coef!=NULL))
2979  nDelete(&(Lp.p->coef));
2980  }
2981  // Check for sigdrop
2982  if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
2983  {
2984  strat->sigdrop = TRUE;
2985  // Completely reduce it
2986  int red_result = redRing(&Lp,strat);
2987  if(red_result == 0)
2988  {
2989  // Reduced to 0
2990  strat->sigdrop = FALSE;
2991  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2992  return;
2993  }
2994  else
2995  {
2996  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2997  // 0 - add just the original poly causing the sigdrop, 1 - add also this
2998  #if 1
2999  strat->enterS(Lp,0,strat, strat->tl+1);
3000  #endif
3001  return;
3002  }
3003  }
3004  l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3005  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3006  }
3007 }
3008 
3009 /*2
3010 * put the pair (s[i],p) into the set L, ecart=ecart(p)
3011 * in the case that s forms a SB of (s)
3012 */
3013 void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3014 {
3015  //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3016  if(pHasNotCF(p,strat->S[i]))
3017  {
3018  //PrintS("prod-crit\n");
3019  if(ALLOW_PROD_CRIT(strat))
3020  {
3021  //PrintS("prod-crit\n");
3022  strat->cp++;
3023  return;
3024  }
3025  }
3026 
3027  int l;
3028  LObject Lp;
3029  Lp.i_r = -1;
3030 
3031  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3032  /*- compute the short s-polynomial -*/
3033 
3034  #ifdef HAVE_PLURAL
3035  if (rIsPluralRing(currRing))
3036  {
3037  Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3038  }
3039  else
3040  #endif
3041  Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3042 
3043  if (Lp.p == NULL)
3044  {
3045  //PrintS("short spoly==NULL\n");
3046  pLmFree(Lp.lcm);
3047  }
3048  else
3049  {
3050  /*- the pair (S[i],p) enters L -*/
3051  Lp.p1 = strat->S[i];
3052  Lp.p2 = p;
3053  if (atR >= 0)
3054  {
3055  Lp.i_r1 = strat->S_2_R[i];
3056  Lp.i_r2 = atR;
3057  }
3058  else
3059  {
3060  Lp.i_r1 = -1;
3061  Lp.i_r2 = -1;
3062  }
3063  assume(pNext(Lp.p) == NULL);
3064  pNext(Lp.p) = strat->tail;
3065  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3067  {
3068  if (!rIsPluralRing(currRing)
3070  && (Lp.p->coef!=NULL))
3071  nDelete(&(Lp.p->coef));
3072  }
3073  l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3074  //Print("-> L[%d]\n",l);
3075  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3076  }
3077 }
3078 
3079 /*2
3080 * merge set B into L
3081 */
3082 void kMergeBintoL(kStrategy strat)
3083 {
3084  int j=strat->Ll+strat->Bl+1;
3085  if (j>strat->Lmax)
3086  {
3087  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3088  enlargeL(&(strat->L),&(strat->Lmax),j);
3089  }
3090  j = strat->Ll;
3091  int i;
3092  for (i=strat->Bl; i>=0; i--)
3093  {
3094  j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3095  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3096  }
3097  strat->Bl = -1;
3098 }
3099 
3100 /*2
3101 * merge set B into L
3102 */
3103 void kMergeBintoLSba(kStrategy strat)
3104 {
3105  int j=strat->Ll+strat->Bl+1;
3106  if (j>strat->Lmax)
3107  {
3108  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3109  enlargeL(&(strat->L),&(strat->Lmax),j);
3110  }
3111  j = strat->Ll;
3112  int i;
3113  for (i=strat->Bl; i>=0; i--)
3114  {
3115  j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3116  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3117  }
3118  strat->Bl = -1;
3119 }
3120 /*2
3121 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3122 *using the chain-criterion in B and L and enters B to L
3123 */
3124 void chainCritNormal (poly p,int ecart,kStrategy strat)
3125 {
3126  int i,j,l;
3127 
3128  /*
3129  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3130  *In this case all elements in B such
3131  *that their lcm is divisible by the leading term of S[i] can be canceled
3132  */
3133  if (strat->pairtest!=NULL)
3134  {
3135  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3136  for (j=0; j<=strat->sl; j++)
3137  {
3138  if (strat->pairtest[j])
3139  {
3140  for (i=strat->Bl; i>=0; i--)
3141  {
3142  if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3143  {
3144  deleteInL(strat->B,&strat->Bl,i,strat);
3145  strat->c3++;
3146  }
3147  }
3148  }
3149  }
3150  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3151  strat->pairtest=NULL;
3152  }
3153  if (strat->Gebauer || strat->fromT)
3154  {
3155  if (strat->sugarCrit)
3156  {
3157  /*
3158  *suppose L[j] == (s,r) and p/lcm(s,r)
3159  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3160  *and in case the sugar is o.k. then L[j] can be canceled
3161  */
3162  for (j=strat->Ll; j>=0; j--)
3163  {
3164  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3165  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3166  && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3167  {
3168  if (strat->L[j].p == strat->tail)
3169  {
3170  deleteInL(strat->L,&strat->Ll,j,strat);
3171  strat->c3++;
3172  }
3173  }
3174  }
3175  /*
3176  *this is GEBAUER-MOELLER:
3177  *in B all elements with the same lcm except the "best"
3178  *(i.e. the last one in B with this property) will be canceled
3179  */
3180  j = strat->Bl;
3181  loop /*cannot be changed into a for !!! */
3182  {
3183  if (j <= 0) break;
3184  i = j-1;
3185  loop
3186  {
3187  if (i < 0) break;
3188  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3189  {
3190  strat->c3++;
3191  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3192  {
3193  deleteInL(strat->B,&strat->Bl,i,strat);
3194  j--;
3195  }
3196  else
3197  {
3198  deleteInL(strat->B,&strat->Bl,j,strat);
3199  break;
3200  }
3201  }
3202  i--;
3203  }
3204  j--;
3205  }
3206  }
3207  else /*sugarCrit*/
3208  {
3209  /*
3210  *suppose L[j] == (s,r) and p/lcm(s,r)
3211  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3212  *and in case the sugar is o.k. then L[j] can be canceled
3213  */
3214  for (j=strat->Ll; j>=0; j--)
3215  {
3216  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3217  {
3218  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3219  {
3220  deleteInL(strat->L,&strat->Ll,j,strat);
3221  strat->c3++;
3222  }
3223  }
3224  }
3225  /*
3226  *this is GEBAUER-MOELLER:
3227  *in B all elements with the same lcm except the "best"
3228  *(i.e. the last one in B with this property) will be canceled
3229  */
3230  j = strat->Bl;
3231  loop /*cannot be changed into a for !!! */
3232  {
3233  if (j <= 0) break;
3234  for(i=j-1; i>=0; i--)
3235  {
3236  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3237  {
3238  strat->c3++;
3239  deleteInL(strat->B,&strat->Bl,i,strat);
3240  j--;
3241  }
3242  }
3243  j--;
3244  }
3245  }
3246  /*
3247  *the elements of B enter L
3248  */
3249  kMergeBintoL(strat);
3250  }
3251  else
3252  {
3253  for (j=strat->Ll; j>=0; j--)
3254  {
3255  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3256  {
3257  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3258  {
3259  deleteInL(strat->L,&strat->Ll,j,strat);
3260  strat->c3++;
3261  }
3262  }
3263  }
3264  /*
3265  *this is our MODIFICATION of GEBAUER-MOELLER:
3266  *First the elements of B enter L,
3267  *then we fix a lcm and the "best" element in L
3268  *(i.e the last in L with this lcm and of type (s,p))
3269  *and cancel all the other elements of type (r,p) with this lcm
3270  *except the case the element (s,r) has also the same lcm
3271  *and is on the worst position with respect to (s,p) and (r,p)
3272  */
3273  /*
3274  *B enters to L/their order with respect to B is permutated for elements
3275  *B[i].p with the same leading term
3276  */
3277  kMergeBintoL(strat);
3278  j = strat->Ll;
3279  loop /*cannot be changed into a for !!! */
3280  {
3281  if (j <= 0)
3282  {
3283  /*now L[0] cannot be canceled any more and the tail can be removed*/
3284  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3285  break;
3286  }
3287  if (strat->L[j].p2 == p)
3288  {
3289  i = j-1;
3290  loop
3291  {
3292  if (i < 0) break;
3293  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3294  {
3295  /*L[i] could be canceled but we search for a better one to cancel*/
3296  strat->c3++;
3297  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3298  && (pNext(strat->L[l].p) == strat->tail)
3299  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3300  && pDivisibleBy(p,strat->L[l].lcm))
3301  {
3302  /*
3303  *"NOT equal(...)" because in case of "equal" the element L[l]
3304  *is "older" and has to be from theoretical point of view behind
3305  *L[i], but we do not want to reorder L
3306  */
3307  strat->L[i].p2 = strat->tail;
3308  /*
3309  *L[l] will be canceled, we cannot cancel L[i] later on,
3310  *so we mark it with "tail"
3311  */
3312  deleteInL(strat->L,&strat->Ll,l,strat);
3313  i--;
3314  }
3315  else
3316  {
3317  deleteInL(strat->L,&strat->Ll,i,strat);
3318  }
3319  j--;
3320  }
3321  i--;
3322  }
3323  }
3324  else if (strat->L[j].p2 == strat->tail)
3325  {
3326  /*now L[j] cannot be canceled any more and the tail can be removed*/
3327  strat->L[j].p2 = p;
3328  }
3329  j--;
3330  }
3331  }
3332 }
3333 /*2
3334 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3335 *without the chain-criterion in B and L and enters B to L
3336 */
3337 void chainCritOpt_1 (poly,int,kStrategy strat)
3338 {
3339  if (strat->pairtest!=NULL)
3340  {
3341  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3342  strat->pairtest=NULL;
3343  }
3344  /*
3345  *the elements of B enter L
3346  */
3347  kMergeBintoL(strat);
3348 }
3349 /*2
3350 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3351 *using the chain-criterion in B and L and enters B to L
3352 */
3353 void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3354 {
3355  int i,j,l;
3356  kMergeBintoLSba(strat);
3357  j = strat->Ll;
3358  loop /*cannot be changed into a for !!! */
3359  {
3360  if (j <= 0)
3361  {
3362  /*now L[0] cannot be canceled any more and the tail can be removed*/
3363  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3364  break;
3365  }
3366  if (strat->L[j].p2 == p)
3367  {
3368  i = j-1;
3369  loop
3370  {
3371  if (i < 0) break;
3372  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3373  {
3374  /*L[i] could be canceled but we search for a better one to cancel*/
3375  strat->c3++;
3376  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3377  && (pNext(strat->L[l].p) == strat->tail)
3378  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3379  && pDivisibleBy(p,strat->L[l].lcm))
3380  {
3381  /*
3382  *"NOT equal(...)" because in case of "equal" the element L[l]
3383  *is "older" and has to be from theoretical point of view behind
3384  *L[i], but we do not want to reorder L
3385  */
3386  strat->L[i].p2 = strat->tail;
3387  /*
3388  *L[l] will be canceled, we cannot cancel L[i] later on,
3389  *so we mark it with "tail"
3390  */
3391  deleteInL(strat->L,&strat->Ll,l,strat);
3392  i--;
3393  }
3394  else
3395  {
3396  deleteInL(strat->L,&strat->Ll,i,strat);
3397  }
3398  j--;
3399  }
3400  i--;
3401  }
3402  }
3403  else if (strat->L[j].p2 == strat->tail)
3404  {
3405  /*now L[j] cannot be canceled any more and the tail can be removed*/
3406  strat->L[j].p2 = p;
3407  }
3408  j--;
3409  }
3410 }
3411 #ifdef HAVE_RATGRING
3412 void chainCritPart (poly p,int ecart,kStrategy strat)
3413 {
3414  int i,j,l;
3415 
3416  /*
3417  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3418  *In this case all elements in B such
3419  *that their lcm is divisible by the leading term of S[i] can be canceled
3420  */
3421  if (strat->pairtest!=NULL)
3422  {
3423  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3424  for (j=0; j<=strat->sl; j++)
3425  {
3426  if (strat->pairtest[j])
3427  {
3428  for (i=strat->Bl; i>=0; i--)
3429  {
3430  if (_p_LmDivisibleByPart(strat->S[j],currRing,
3431  strat->B[i].lcm,currRing,
3432  currRing->real_var_start,currRing->real_var_end))
3433  {
3434  if(TEST_OPT_DEBUG)
3435  {
3436  Print("chain-crit-part: S[%d]=",j);
3437  p_wrp(strat->S[j],currRing);
3438  Print(" divide B[%d].lcm=",i);
3439  p_wrp(strat->B[i].lcm,currRing);
3440  PrintLn();
3441  }
3442  deleteInL(strat->B,&strat->Bl,i,strat);
3443  strat->c3++;
3444  }
3445  }
3446  }
3447  }
3448  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3449  strat->pairtest=NULL;
3450  }
3451  if (strat->Gebauer || strat->fromT)
3452  {
3453  if (strat->sugarCrit)
3454  {
3455  /*
3456  *suppose L[j] == (s,r) and p/lcm(s,r)
3457  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3458  *and in case the sugar is o.k. then L[j] can be canceled
3459  */
3460  for (j=strat->Ll; j>=0; j--)
3461  {
3462  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3463  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3464  && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3465  {
3466  if (strat->L[j].p == strat->tail)
3467  {
3468  if(TEST_OPT_DEBUG)
3469  {
3470  PrintS("chain-crit-part: pCompareChainPart p=");
3471  p_wrp(p,currRing);
3472  Print(" delete L[%d]",j);
3473  p_wrp(strat->L[j].lcm,currRing);
3474  PrintLn();
3475  }
3476  deleteInL(strat->L,&strat->Ll,j,strat);
3477  strat->c3++;
3478  }
3479  }
3480  }
3481  /*
3482  *this is GEBAUER-MOELLER:
3483  *in B all elements with the same lcm except the "best"
3484  *(i.e. the last one in B with this property) will be canceled
3485  */
3486  j = strat->Bl;
3487  loop /*cannot be changed into a for !!! */
3488  {
3489  if (j <= 0) break;
3490  i = j-1;
3491  loop
3492  {
3493  if (i < 0) break;
3494  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3495  {
3496  strat->c3++;
3497  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3498  {
3499  if(TEST_OPT_DEBUG)
3500  {
3501  Print("chain-crit-part: sugar B[%d].lcm=",j);
3502  p_wrp(strat->B[j].lcm,currRing);
3503  Print(" delete B[%d]",i);
3504  p_wrp(strat->B[i].lcm,currRing);
3505  PrintLn();
3506  }
3507  deleteInL(strat->B,&strat->Bl,i,strat);
3508  j--;
3509  }
3510  else
3511  {
3512  if(TEST_OPT_DEBUG)
3513  {
3514  Print("chain-crit-part: sugar B[%d].lcm=",i);
3515  p_wrp(strat->B[i].lcm,currRing);
3516  Print(" delete B[%d]",j);
3517  p_wrp(strat->B[j].lcm,currRing);
3518  PrintLn();
3519  }
3520  deleteInL(strat->B,&strat->Bl,j,strat);
3521  break;
3522  }
3523  }
3524  i--;
3525  }
3526  j--;
3527  }
3528  }
3529  else /*sugarCrit*/
3530  {
3531  /*
3532  *suppose L[j] == (s,r) and p/lcm(s,r)
3533  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3534  *and in case the sugar is o.k. then L[j] can be canceled
3535  */
3536  for (j=strat->Ll; j>=0; j--)
3537  {
3538  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3539  {
3540  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3541  {
3542  if(TEST_OPT_DEBUG)
3543  {
3544  PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3545  p_wrp(p,currRing);
3546  Print(" delete L[%d]",j);
3547  p_wrp(strat->L[j].lcm,currRing);
3548  PrintLn();
3549  }
3550  deleteInL(strat->L,&strat->Ll,j,strat);
3551  strat->c3++;
3552  }
3553  }
3554  }
3555  /*
3556  *this is GEBAUER-MOELLER:
3557  *in B all elements with the same lcm except the "best"
3558  *(i.e. the last one in B with this property) will be canceled
3559  */
3560  j = strat->Bl;
3561  loop /*cannot be changed into a for !!! */
3562  {
3563  if (j <= 0) break;
3564  for(i=j-1; i>=0; i--)
3565  {
3566  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3567  {
3568  if(TEST_OPT_DEBUG)
3569  {
3570  Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3571  p_wrp(strat->B[j].lcm,currRing);
3572  Print(" delete B[%d]\n",i);
3573  }
3574  strat->c3++;
3575  deleteInL(strat->B,&strat->Bl,i,strat);
3576  j--;
3577  }
3578  }
3579  j--;
3580  }
3581  }
3582  /*
3583  *the elements of B enter L
3584  */
3585  kMergeBintoL(strat);
3586  }
3587  else
3588  {
3589  for (j=strat->Ll; j>=0; j--)
3590  {
3591  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3592  {
3593  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3594  {
3595  if(TEST_OPT_DEBUG)
3596  {
3597  PrintS("chain-crit-part: pCompareChainPart p=");
3598  p_wrp(p,currRing);
3599  Print(" delete L[%d]",j);
3600  p_wrp(strat->L[j].lcm,currRing);
3601  PrintLn();
3602  }
3603  deleteInL(strat->L,&strat->Ll,j,strat);
3604  strat->c3++;
3605  }
3606  }
3607  }
3608  /*
3609  *this is our MODIFICATION of GEBAUER-MOELLER:
3610  *First the elements of B enter L,
3611  *then we fix a lcm and the "best" element in L
3612  *(i.e the last in L with this lcm and of type (s,p))
3613  *and cancel all the other elements of type (r,p) with this lcm
3614  *except the case the element (s,r) has also the same lcm
3615  *and is on the worst position with respect to (s,p) and (r,p)
3616  */
3617  /*
3618  *B enters to L/their order with respect to B is permutated for elements
3619  *B[i].p with the same leading term
3620  */
3621  kMergeBintoL(strat);
3622  j = strat->Ll;
3623  loop /*cannot be changed into a for !!! */
3624  {
3625  if (j <= 0)
3626  {
3627  /*now L[0] cannot be canceled any more and the tail can be removed*/
3628  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3629  break;
3630  }
3631  if (strat->L[j].p2 == p)
3632  {
3633  i = j-1;
3634  loop
3635  {
3636  if (i < 0) break;
3637  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3638  {
3639  /*L[i] could be canceled but we search for a better one to cancel*/
3640  strat->c3++;
3641  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3642  && (pNext(strat->L[l].p) == strat->tail)
3643  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3645  strat->L[l].lcm,currRing,
3646  currRing->real_var_start, currRing->real_var_end))
3647 
3648  {
3649  /*
3650  *"NOT equal(...)" because in case of "equal" the element L[l]
3651  *is "older" and has to be from theoretical point of view behind
3652  *L[i], but we do not want to reorder L
3653  */
3654  strat->L[i].p2 = strat->tail;
3655  /*
3656  *L[l] will be canceled, we cannot cancel L[i] later on,
3657  *so we mark it with "tail"
3658  */
3659  if(TEST_OPT_DEBUG)
3660  {
3661  PrintS("chain-crit-part: divisible_by p=");
3662  p_wrp(p,currRing);
3663  Print(" delete L[%d]",l);
3664  p_wrp(strat->L[l].lcm,currRing);
3665  PrintLn();
3666  }
3667  deleteInL(strat->L,&strat->Ll,l,strat);
3668  i--;
3669  }
3670  else
3671  {
3672  if(TEST_OPT_DEBUG)
3673  {
3674  PrintS("chain-crit-part: divisible_by(2) p=");
3675  p_wrp(p,currRing);
3676  Print(" delete L[%d]",i);
3677  p_wrp(strat->L[i].lcm,currRing);
3678  PrintLn();
3679  }
3680  deleteInL(strat->L,&strat->Ll,i,strat);
3681  }
3682  j--;
3683  }
3684  i--;
3685  }
3686  }
3687  else if (strat->L[j].p2 == strat->tail)
3688  {
3689  /*now L[j] cannot be canceled any more and the tail can be removed*/
3690  strat->L[j].p2 = p;
3691  }
3692  j--;
3693  }
3694  }
3695 }
3696 #endif
3697 
3698 /*2
3699 *(s[0],h),...,(s[k],h) will be put to the pairset L
3700 */
3701 void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3702 {
3703 
3704  if ((strat->syzComp==0)
3705  || (pGetComp(h)<=strat->syzComp))
3706  {
3707  int j;
3708  BOOLEAN new_pair=FALSE;
3709 
3710  if (pGetComp(h)==0)
3711  {
3712  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3713  if ((isFromQ)&&(strat->fromQ!=NULL))
3714  {
3715  for (j=0; j<=k; j++)
3716  {
3717  if (!strat->fromQ[j])
3718  {
3719  new_pair=TRUE;
3720  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3721  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3722  }
3723  }
3724  }
3725  else
3726  {
3727  new_pair=TRUE;
3728  for (j=0; j<=k; j++)
3729  {
3730  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3731  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3732  }
3733  }
3734  }
3735  else
3736  {
3737  for (j=0; j<=k; j++)
3738  {
3739  if ((pGetComp(h)==pGetComp(strat->S[j]))
3740  || (pGetComp(strat->S[j])==0))
3741  {
3742  new_pair=TRUE;
3743  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3744  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3745  }
3746  }
3747  }
3748  if (new_pair)
3749  {
3750  #ifdef HAVE_RATGRING
3751  if (currRing->real_var_start>0)
3752  chainCritPart(h,ecart,strat);
3753  else
3754  #endif
3755  strat->chainCrit(h,ecart,strat);
3756  }
3757  kMergeBintoL(strat);
3758  }
3759 }
3760 
3761 /*2
3762 *(s[0],h),...,(s[k],h) will be put to the pairset L
3763 *using signatures <= only for signature-based standard basis algorithms
3764 */
3766 void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3767 {
3768 
3769  if ((strat->syzComp==0)
3770  || (pGetComp(h)<=strat->syzComp))
3771  {
3772  int j;
3773  BOOLEAN new_pair=FALSE;
3774 
3775  if (pGetComp(h)==0)
3776  {
3777  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3778  if ((isFromQ)&&(strat->fromQ!=NULL))
3779  {
3780  for (j=0; j<=k; j++)
3781  {
3782  if (!strat->fromQ[j])
3783  {
3784  new_pair=TRUE;
3785  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3786  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3787  }
3788  }
3789  }
3790  else
3791  {
3792  new_pair=TRUE;
3793  for (j=0; j<=k; j++)
3794  {
3795  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3796  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3797  }
3798  }
3799  }
3800  else
3801  {
3802  for (j=0; j<=k; j++)
3803  {
3804  if ((pGetComp(h)==pGetComp(strat->S[j]))
3805  || (pGetComp(strat->S[j])==0))
3806  {
3807  new_pair=TRUE;
3808  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3809  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3810  }
3811  }
3812  }
3813 
3814  if (new_pair)
3815  {
3816 #ifdef HAVE_RATGRING
3817  if (currRing->real_var_start>0)
3818  chainCritPart(h,ecart,strat);
3819  else
3820 #endif
3821  strat->chainCrit(h,ecart,strat);
3822  }
3823  }
3824 }
3826 void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3827 {
3828 
3829  if ((strat->syzComp==0)
3830  || (pGetComp(h)<=strat->syzComp))
3831  {
3832  int j;
3833 
3834  if (pGetComp(h)==0)
3835  {
3836  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3837  if ((isFromQ)&&(strat->fromQ!=NULL))
3838  {
3839  for (j=0; j<=k && !strat->sigdrop; j++)
3840  {
3841  if (!strat->fromQ[j])
3842  {
3843  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3844  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3845  }
3846  }
3847  }
3848  else
3849  {
3850  for (j=0; j<=k && !strat->sigdrop; j++)
3851  {
3852  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3853  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3854  }
3855  }
3856  }
3857  else
3858  {
3859  for (j=0; j<=k && !strat->sigdrop; j++)
3860  {
3861  if ((pGetComp(h)==pGetComp(strat->S[j]))
3862  || (pGetComp(strat->S[j])==0))
3863  {
3864  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3865  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3866  }
3867  }
3868  }
3869 
3870 #if 0
3871  if (new_pair)
3872  {
3873 #ifdef HAVE_RATGRING
3874  if (currRing->real_var_start>0)
3875  chainCritPart(h,ecart,strat);
3876  else
3877 #endif
3878  strat->chainCrit(h,ecart,strat);
3879  }
3880 #endif
3881  }
3882 }
3883 
3884 #ifdef HAVE_RINGS
3885 /*2
3886 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3887 *using the chain-criterion in B and L and enters B to L
3888 */
3889 void chainCritRing (poly p,int, kStrategy strat)
3890 {
3891  int i,j,l;
3892  /*
3893  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3894  *In this case all elements in B such
3895  *that their lcm is divisible by the leading term of S[i] can be canceled
3896  */
3897  if (strat->pairtest!=NULL)
3898  {
3899  {
3900  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3901  for (j=0; j<=strat->sl; j++)
3902  {
3903  if (strat->pairtest[j])
3904  {
3905  for (i=strat->Bl; i>=0; i--)
3906  {
3907  if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
3908  {
3909 #ifdef KDEBUG
3910  if (TEST_OPT_DEBUG)
3911  {
3912  PrintS("--- chain criterion func chainCritRing type 1\n");
3913  PrintS("strat->S[j]:");
3914  wrp(strat->S[j]);
3915  PrintS(" strat->B[i].lcm:");
3916  wrp(strat->B[i].lcm);PrintLn();
3917  pWrite(strat->B[i].p);
3918  pWrite(strat->B[i].p1);
3919  pWrite(strat->B[i].p2);
3920  wrp(strat->B[i].lcm);
3921  PrintLn();
3922  }
3923 #endif
3924  deleteInL(strat->B,&strat->Bl,i,strat);
3925  strat->c3++;
3926  }
3927  }
3928  }
3929  }
3930  }
3931  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3932  strat->pairtest=NULL;
3933  }
3934  assume(!(strat->Gebauer || strat->fromT));
3935  for (j=strat->Ll; j>=0; j--)
3936  {
3937  if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
3938  {
3939  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3940  {
3941  if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3942  {
3943  deleteInL(strat->L,&strat->Ll,j,strat);
3944  strat->c3++;
3945 #ifdef KDEBUG
3946  if (TEST_OPT_DEBUG)
3947  {
3948  PrintS("--- chain criterion func chainCritRing type 2\n");
3949  PrintS("strat->L[j].p:");
3950  wrp(strat->L[j].p);
3951  PrintS(" p:");
3952  wrp(p);
3953  PrintLn();
3954  }
3955 #endif
3956  }
3957  }
3958  }
3959  }
3960  /*
3961  *this is our MODIFICATION of GEBAUER-MOELLER:
3962  *First the elements of B enter L,
3963  *then we fix a lcm and the "best" element in L
3964  *(i.e the last in L with this lcm and of type (s,p))
3965  *and cancel all the other elements of type (r,p) with this lcm
3966  *except the case the element (s,r) has also the same lcm
3967  *and is on the worst position with respect to (s,p) and (r,p)
3968  */
3969  /*
3970  *B enters to L/their order with respect to B is permutated for elements
3971  *B[i].p with the same leading term
3972  */
3973  kMergeBintoL(strat);
3974  j = strat->Ll;
3975  loop /*cannot be changed into a for !!! */
3976  {
3977  if (j <= 0)
3978  {
3979  /*now L[0] cannot be canceled any more and the tail can be removed*/
3980  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3981  break;
3982  }
3983  if (strat->L[j].p2 == p) // Was the element added from B?
3984  {
3985  i = j-1;
3986  loop
3987  {
3988  if (i < 0) break;
3989  // Element is from B and has the same lcm as L[j]
3990  if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
3991  && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3992  {
3993  /*L[i] could be canceled but we search for a better one to cancel*/
3994  strat->c3++;
3995 #ifdef KDEBUG
3996  if (TEST_OPT_DEBUG)
3997  {
3998  PrintS("--- chain criterion func chainCritRing type 3\n");
3999  PrintS("strat->L[j].lcm:");
4000  wrp(strat->L[j].lcm);
4001  PrintS(" strat->L[i].lcm:");
4002  wrp(strat->L[i].lcm);
4003  PrintLn();
4004  }
4005 #endif
4006  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4007  && (pNext(strat->L[l].p) == strat->tail)
4008  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4009  && pDivisibleBy(p,strat->L[l].lcm))
4010  {
4011  /*
4012  *"NOT equal(...)" because in case of "equal" the element L[l]
4013  *is "older" and has to be from theoretical point of view behind
4014  *L[i], but we do not want to reorder L
4015  */
4016  strat->L[i].p2 = strat->tail;
4017  /*
4018  *L[l] will be canceled, we cannot cancel L[i] later on,
4019  *so we mark it with "tail"
4020  */
4021  deleteInL(strat->L,&strat->Ll,l,strat);
4022  i--;
4023  }
4024  else
4025  {
4026  deleteInL(strat->L,&strat->Ll,i,strat);
4027  }
4028  j--;
4029  }
4030  i--;
4031  }
4032  }
4033  else if (strat->L[j].p2 == strat->tail)
4034  {
4035  /*now L[j] cannot be canceled any more and the tail can be removed*/
4036  strat->L[j].p2 = p;
4037  }
4038  j--;
4039  }
4040 }
4041 #endif
4042 
4043 #ifdef HAVE_RINGS
4044 long ind2(long arg)
4045 {
4046  long ind = 0;
4047  if (arg <= 0) return 0;
4048  while (arg%2 == 0)
4049  {
4050  arg = arg / 2;
4051  ind++;
4052  }
4053  return ind;
4054 }
4056 long ind_fact_2(long arg)
4057 {
4058  long ind = 0;
4059  if (arg <= 0) return 0;
4060  if (arg%2 == 1) { arg--; }
4061  while (arg > 0)
4062  {
4063  ind += ind2(arg);
4064  arg = arg - 2;
4065  }
4066  return ind;
4067 }
4068 #endif
4069 
4070 #ifdef HAVE_VANIDEAL
4071 long twoPow(long arg)
4072 {
4073  return 1L << arg;
4074 }
4075 
4076 /*2
4077 * put the pair (p, f) in B and f in T
4078 */
4079 void enterOneZeroPairRing (poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR = -1)
4080 {
4081  int l,j,compare,compareCoeff;
4082  LObject Lp;
4083 
4084 #ifdef KDEBUG
4085  Lp.ecart=0; Lp.length=0;
4086 #endif
4087  /*- computes the lcm(s[i],p) -*/
4088  Lp.lcm = p_Lcm(p,f,Lp.lcm,currRing);
4089  pSetCoeff(Lp.lcm, nLcm(pGetCoeff(p), pGetCoeff(f), currRing));
4090  assume(!strat->sugarCrit);
4091  assume(!strat->fromT);
4092  /*
4093  *the set B collects the pairs of type (S[j],p)
4094  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
4095  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
4096  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
4097  */
4098  for(j = strat->Bl;j>=0;j--)
4099  {
4100  compare=pDivCompRing(strat->B[j].lcm,Lp.lcm);
4101  compareCoeff = nDivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(Lp.lcm));
4102  if (compareCoeff == 0 || compare == compareCoeff)
4103  {
4104  if (compare == 1)
4105  {
4106  strat->c3++;
4107  pLmDelete(Lp.lcm);
4108  return;
4109  }
4110  else
4111  if (compare == -1)
4112  {
4113  deleteInL(strat->B,&strat->Bl,j,strat);
4114  strat->c3++;
4115  }
4116  }
4117  if (compare == pDivComp_EQUAL)
4118  {
4119  // Add hint for same LM and direction of LC (later) (TODO Oliver)
4120  if (compareCoeff == 1)
4121  {
4122  strat->c3++;
4123  pLmDelete(Lp.lcm);
4124  return;
4125  }
4126  else
4127  if (compareCoeff == -1)
4128  {
4129  deleteInL(strat->B,&strat->Bl,j,strat);
4130  strat->c3++;
4131  }
4132  }
4133  }
4134  /*
4135  *the pair (S[i],p) enters B if the spoly != 0
4136  */
4137  /*- compute the short s-polynomial -*/
4138  if ((f==NULL) || (p==NULL)) return;
4139  pNorm(p);
4140  {
4141  Lp.p = ksCreateShortSpoly(f, p, strat->tailRing);
4142  }
4143  if (Lp.p == NULL) //deactivated, as we are adding pairs with zeropoly and not from S
4144  {
4145  /*- the case that the s-poly is 0 -*/
4146 // if (strat->pairtest==NULL) initPairtest(strat);
4147 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
4148 // strat->pairtest[strat->sl+1] = TRUE;
4149  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
4150  /*
4151  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
4152  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
4153  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
4154  *term of p devides the lcm(s,r)
4155  *(this canceling should be done here because
4156  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
4157  *the first case is handeled in chainCrit
4158  */
4159  if (Lp.lcm!=NULL) pLmDelete(Lp.lcm);
4160  }
4161  else
4162  {
4163  /*- the pair (S[i],p) enters B -*/
4164  Lp.p1 = f;
4165  Lp.p2 = p;
4166 
4167  pNext(Lp.p) = strat->tail;
4168 
4169  LObject tmp_h(f, currRing, strat->tailRing);
4170  tmp_h.SetShortExpVector();
4171  strat->initEcart(&tmp_h);
4172  tmp_h.sev = pGetShortExpVector(tmp_h.p);
4173  tmp_h.t_p = t_p;
4174 
4175  enterT(tmp_h, strat, strat->tl + 1);
4176 
4177  if (atR >= 0)
4178  {
4179  Lp.i_r2 = atR;
4180  Lp.i_r1 = strat->tl;
4181  }
4182 
4183  strat->initEcartPair(&Lp,f,p,0/*strat->ecartS[i]*/,ecart); // Attention: TODO: break ecart
4184  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
4185  enterL(&strat->B, &strat->Bl, &strat->Bmax, Lp, l);
4186  }
4187 }
4188 
4189 /* Helper for kCreateZeroPoly
4190  * enumerating the exponents
4191 ring r = 2^2, (a, b, c), lp; ideal G0 = system("createG0"); ideal G = interred(G0); ncols(G0); ncols(G);
4192  */
4194 int nextZeroSimplexExponent (long exp[], long ind[], long cexp[], long cind[], long* cabsind, long step[], long bound, long N)
4195 /* gives the next exponent from the set H_1 */
4196 {
4197  long add = ind2(cexp[1] + 2);
4198  if ((*cabsind < bound) && (*cabsind - step[1] + add < bound))
4199  {
4200  cexp[1] += 2;
4201  cind[1] += add;
4202  *cabsind += add;
4203  }
4204  else
4205  {
4206  // cabsind >= habsind
4207  if (N == 1) return 0;
4208  int i = 1;
4209  while (exp[i] == cexp[i] && i <= N) i++;
4210  cexp[i] = exp[i];
4211  *cabsind -= cind[i];
4212  cind[i] = ind[i];
4213  step[i] = 500000;
4214  *cabsind += cind[i];
4215  // Print("in: %d\n", *cabsind);
4216  i += 1;
4217  if (i > N) return 0;
4218  do
4219  {
4220  step[1] = 500000;
4221  for (int j = i + 1; j <= N; j++)
4222  {
4223  if (step[1] > step[j]) step[1] = step[j];
4224  }
4225  add = ind2(cexp[i] + 2);
4226  if (*cabsind - step[1] + add >= bound)
4227  {
4228  cexp[i] = exp[i];
4229  *cabsind -= cind[i];
4230  cind[i] = ind[i];
4231  *cabsind += cind[i];
4232  step[i] = 500000;
4233  i += 1;
4234  if (i > N) return 0;
4235  }
4236  else step[1] = -1;
4237  } while (step[1] != -1);
4238  step[1] = 500000;
4239  cexp[i] += 2;
4240  cind[i] += add;
4241  *cabsind += add;
4242  if (add < step[i]) step[i] = add;
4243  for (i = 2; i <= N; i++)
4244  {
4245  if (step[1] > step[i]) step[1] = step[i];
4246  }
4247  }
4248  return 1;
4249 }
4250 
4251 /*
4252  * Creates the zero Polynomial on position exp
4253  * long exp[] : exponent of leading term
4254  * cabsind : total 2-ind of exp (if -1 will be computed)
4255  * poly* t_p : will hold the LT in tailRing
4256  * leadRing : ring for the LT
4257  * tailRing : ring for the tail
4258  */
4260 poly kCreateZeroPoly(long exp[], long cabsind, poly* t_p, ring leadRing, ring tailRing)
4261 {
4262 
4263  poly zeroPoly = NULL;
4264 
4265  number tmp1;
4266  poly tmp2, tmp3;
4267 
4268  if (cabsind == -1)
4269  {
4270  cabsind = 0;
4271  for (int i = 1; i <= leadRing->N; i++)
4272  {
4273  cabsind += ind_fact_2(exp[i]);
4274  }
4275 // Print("cabsind: %d\n", cabsind);
4276  }
4277  if (cabsind < leadRing->ch)
4278  {
4279  zeroPoly = p_ISet(twoPow(leadRing->ch - cabsind), tailRing);
4280  }
4281  else
4282  {
4283  zeroPoly = p_ISet(1, tailRing);
4284  }
4285  for (int i = 1; i <= leadRing->N; i++)
4286  {
4287  for (long j = 1; j <= exp[i]; j++)
4288  {
4289  tmp1 = nInit(j);
4290  tmp2 = p_ISet(1, tailRing);
4291  p_SetExp(tmp2, i, 1, tailRing);
4292  p_Setm(tmp2, tailRing);
4293  if (nIsZero(tmp1))
4294  { // should nowbe obsolet, test ! TODO OLIVER
4295  zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
4296  }
4297  else
4298  {
4299  tmp3 = p_NSet(nCopy(tmp1), tailRing);
4300  zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing);
4301  }
4302  }
4303  }
4304  tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing);
4305  for (int i = 1; i <= leadRing->N; i++)
4306  {
4307  pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
4308  }
4309  p_Setm(tmp2, leadRing);
4310  *t_p = zeroPoly;
4311  zeroPoly = pNext(zeroPoly);
4312  pNext(*t_p) = NULL;
4313  pNext(tmp2) = zeroPoly;
4314  return tmp2;
4315 }
4316 
4317 // #define OLI_DEBUG
4318 
4319 /*
4320  * Generate the s-polynomial for the virtual set of zero-polynomials
4321  */
4323 void initenterzeropairsRing (poly p, int ecart, kStrategy strat, int atR)
4324 {
4325  // Initialize
4326  long exp[50]; // The exponent of \hat{X} (basepoint)
4327  long cexp[50]; // The current exponent for iterating over all
4328  long ind[50]; // The power of 2 in the i-th component of exp
4329  long cind[50]; // analog for cexp
4330  long mult[50]; // How to multiply the elements of G
4331  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4332  long habsind = 0; // The abs. index of the coefficient of h
4333  long step[50]; // The last increases
4334  for (int i = 1; i <= currRing->N; i++)
4335  {
4336  exp[i] = p_GetExp(p, i, currRing);
4337  if (exp[i] & 1 != 0)
4338  {
4339  exp[i] = exp[i] - 1;
4340  mult[i] = 1;
4341  }
4342  cexp[i] = exp[i];
4343  ind[i] = ind_fact_2(exp[i]);
4344  cabsind += ind[i];
4345  cind[i] = ind[i];
4346  step[i] = 500000;
4347  }
4348  step[1] = 500000;
4349  habsind = ind2(n_Int(pGetCoeff(p), currRing->cf);
4350  long bound = currRing->ch - habsind;
4351 #ifdef OLI_DEBUG
4352  PrintS("-------------\npoly :");
4353  wrp(p);
4354  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4355  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4356  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4357  Print("bound : %d\n", bound);
4358  Print("cind : %d\n", cabsind);
4359 #endif
4360  if (cabsind == 0)
4361  {
4362  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4363  {
4364  return;
4365  }
4366  }
4367  // Now the whole simplex
4368  do
4369  {
4370  // Build s-polynomial
4371  // 2**ind-def * mult * g - exp-def * h
4372  poly t_p;
4373  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, strat->tailRing);
4374 #ifdef OLI_DEBUG
4375  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4376  PrintS("zPoly : ");
4377  wrp(zeroPoly);
4378  PrintLn();
4379 #endif
4380  enterOneZeroPairRing(zeroPoly, t_p, p, ecart, strat, atR);
4381  }
4382  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4383 }
4384 
4385 /*
4386  * Create the Groebner basis of the vanishing polynomials.
4387  */
4389 ideal createG0()
4390 {
4391  // Initialize
4392  long exp[50]; // The exponent of \hat{X} (basepoint)
4393  long cexp[50]; // The current exponent for iterating over all
4394  long ind[50]; // The power of 2 in the i-th component of exp
4395  long cind[50]; // analog for cexp
4396  long mult[50]; // How to multiply the elements of G
4397  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4398  long habsind = 0; // The abs. index of the coefficient of h
4399  long step[50]; // The last increases
4400  for (int i = 1; i <= currRing->N; i++)
4401  {
4402  exp[i] = 0;
4403  cexp[i] = exp[i];
4404  ind[i] = 0;
4405  step[i] = 500000;
4406  cind[i] = ind[i];
4407  }
4408  long bound = currRing->ch;
4409  step[1] = 500000;
4410 #ifdef OLI_DEBUG
4411  PrintS("-------------\npoly :");
4412 // wrp(p);
4413  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4414  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4415  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4416  Print("bound : %d\n", bound);
4417  Print("cind : %d\n", cabsind);
4418 #endif
4419  if (cabsind == 0)
4420  {
4421  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4422  {
4423  return idInit(1, 1);
4424  }
4425  }
4426  ideal G0 = idInit(1, 1);
4427  // Now the whole simplex
4428  do
4429  {
4430  // Build s-polynomial
4431  // 2**ind-def * mult * g - exp-def * h
4432  poly t_p;
4433  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, currRing);
4434 #ifdef OLI_DEBUG
4435  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4436  PrintS("zPoly : ");
4437  wrp(zeroPoly);
4438  PrintLn();
4439 #endif
4440  // Add to ideal
4441  pEnlargeSet(&(G0->m), IDELEMS(G0), 1);
4442  IDELEMS(G0) += 1;
4443  G0->m[IDELEMS(G0) - 1] = zeroPoly;
4444  }
4445  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4446  idSkipZeroes(G0);
4447  return G0;
4448 }
4449 #endif
4450 
4451 #ifdef HAVE_RINGS
4452 /*2
4453 *(s[0],h),...,(s[k],h) will be put to the pairset L
4454 */
4455 void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4456 {
4457  const int iCompH = pGetComp(h);
4458  if (!nIsOne(pGetCoeff(h)))
4459  {
4460  int j;
4461 
4462  for (j=0; j<=k; j++)
4463  {
4464  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4465 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4466 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4467  if (((iCompH == pGetComp(strat->S[j]))
4468  || (0 == pGetComp(strat->S[j])))
4469  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4470  {
4471  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4472  }
4473  }
4474  }
4475 }
4477 static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4478 {
4479  const int iCompH = pGetComp(h);
4480  if (!nIsOne(pGetCoeff(h)))
4481  {
4482  int j;
4483 
4484  for (j=0; j<=k && !strat->sigdrop; j++)
4485  {
4486  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4487 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4488 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4489  if (((iCompH == pGetComp(strat->S[j]))
4490  || (0 == pGetComp(strat->S[j])))
4491  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4492  {
4493  enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4494  }
4495  }
4496  }
4497 }
4498 #endif
4499 
4500 #ifdef HAVE_RINGS
4501 /*2
4502 * Generates spoly(0, h) if applicable. Assumes ring in Z/2^n.
4503 */
4504 void enterExtendedSpoly(poly h,kStrategy strat)
4505 {
4506  if (nIsOne(pGetCoeff(h))) return;
4507  number gcd;
4508  bool go = false;
4509  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4510  {
4511  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4512  go = true;
4513  }
4514  else
4515  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4516  if (go || !nIsOne(gcd))
4517  {
4518  poly p = h->next;
4519  if (!go)
4520  {
4521  number tmp = gcd;
4522  gcd = n_Ann(gcd,currRing->cf);
4523  nDelete(&tmp);
4524  }
4525  p_Test(p,strat->tailRing);
4526  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4527  nDelete(&gcd);
4528 
4529  if (p != NULL)
4530  {
4531  if (TEST_OPT_PROT)
4532  {
4533  PrintS("Z");
4534  }
4535 #ifdef KDEBUG
4536  if (TEST_OPT_DEBUG)
4537  {
4538  PrintS("--- create zero spoly: ");
4539  p_wrp(h,currRing,strat->tailRing);
4540  PrintS(" ---> ");
4541  }
4542 #endif
4543  poly tmp = pInit();
4544  pSetCoeff0(tmp, pGetCoeff(p));
4545  for (int i = 1; i <= rVar(currRing); i++)
4546  {
4547  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4548  }
4550  {
4551  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4552  }
4553  p_Setm(tmp, currRing);
4554  p = p_LmFreeAndNext(p, strat->tailRing);
4555  pNext(tmp) = p;
4556  LObject Lp;
4557  Lp.Init();
4558  Lp.p = tmp;
4559  Lp.tailRing = strat->tailRing;
4560  int posx;
4561  if (Lp.p!=NULL)
4562  {
4563  strat->initEcart(&Lp);
4564  if (strat->Ll==-1)
4565  posx =0;
4566  else
4567  posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4568  Lp.sev = pGetShortExpVector(Lp.p);
4569  if (strat->tailRing != currRing)
4570  {
4571  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4572  }
4573 #ifdef KDEBUG
4574  if (TEST_OPT_DEBUG)
4575  {
4576  p_wrp(tmp,currRing,strat->tailRing);
4577  PrintLn();
4578  }
4579 #endif
4580  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4581  }
4582  }
4583  }
4584  nDelete(&gcd);
4585 }
4587 void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
4588 {
4589  if (nIsOne(pGetCoeff(h))) return;
4590  number gcd;
4591  bool go = false;
4592  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4593  {
4594  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4595  go = true;
4596  }
4597  else
4598  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4599  if (go || !nIsOne(gcd))
4600  {
4601  poly p = h->next;
4602  if (!go)
4603  {
4604  number tmp = gcd;
4605  gcd = n_Ann(gcd,currRing->cf);
4606  nDelete(&tmp);
4607  }
4608  p_Test(p,strat->tailRing);
4609  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4610 
4611  if (p != NULL)
4612  {
4613  if (TEST_OPT_PROT)
4614  {
4615  PrintS("Z");
4616  }
4617 #ifdef KDEBUG
4618  if (TEST_OPT_DEBUG)
4619  {
4620  PrintS("--- create zero spoly: ");
4621  p_wrp(h,currRing,strat->tailRing);
4622  PrintS(" ---> ");
4623  }
4624 #endif
4625  poly tmp = pInit();
4626  pSetCoeff0(tmp, pGetCoeff(p));
4627  for (int i = 1; i <= rVar(currRing); i++)
4628  {
4629  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4630  }
4632  {
4633  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4634  }
4635  p_Setm(tmp, currRing);
4636  p = p_LmFreeAndNext(p, strat->tailRing);
4637  pNext(tmp) = p;
4638  LObject Lp;
4639  Lp.Init();
4640  Lp.p = tmp;
4641  //printf("\nOld\n");pWrite(h);pWrite(hSig);
4642  #if EXT_POLY_NEW
4643  Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4644  if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4645  {
4646  strat->sigdrop = TRUE;
4647  //Try to reduce it as far as we can via redRing
4648  int red_result = redRing(&Lp,strat);
4649  if(red_result == 0)
4650  {
4651  // Cancel the sigdrop
4652  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4653  strat->sigdrop = FALSE;
4654  return;
4655  }
4656  else
4657  {
4658  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4659  #if 1
4660  strat->enterS(Lp,0,strat,strat->tl);
4661  #endif
4662  return;
4663  }
4664 
4665  }
4666  #else
4667  Lp.sig = pOne();
4668  if(strat->Ll >= 0)
4669  p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4670  else
4671  p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4672  #endif
4673  Lp.tailRing = strat->tailRing;
4674  int posx;
4675  if (Lp.p!=NULL)
4676  {
4677  strat->initEcart(&Lp);
4678  if (strat->Ll==-1)
4679  posx =0;
4680  else
4681  posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4682  Lp.sev = pGetShortExpVector(Lp.p);
4683  if (strat->tailRing != currRing)
4684  {
4685  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4686  }
4687 #ifdef KDEBUG
4688  if (TEST_OPT_DEBUG)
4689  {
4690  p_wrp(tmp,currRing,strat->tailRing);
4691  PrintLn();
4692  }
4693 #endif
4694  //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4695  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4696  }
4697  }
4698  nDelete(&gcd);
4699  }
4700  nDelete(&gcd);
4701 }
4702 #endif
4703 
4704 #ifdef HAVE_RINGS
4705 void clearSbatch (poly h,int k,int pos,kStrategy strat)
4706 {
4707  int j = pos;
4708  if ( (!strat->fromT)
4709  && ((strat->syzComp==0)
4710  ||(pGetComp(h)<=strat->syzComp)
4711  ))
4712  {
4713  // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4714  unsigned long h_sev = pGetShortExpVector(h);
4715  loop
4716  {
4717  if (j > k) break;
4718  clearS(h,h_sev, &j,&k,strat);
4719  j++;
4720  }
4721  // Print("end clearS sl=%d\n",strat->sl);
4722  }
4723 }
4724 #endif
4725 
4726 #ifdef HAVE_RINGS
4727 /*2
4728 * Generates a sufficient set of spolys (maybe just a finite generating
4729 * set of the syzygys)
4730 */
4731 void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4732 {
4734  // enter also zero divisor * poly, if this is non zero and of smaller degree
4735  if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat);
4736  initenterpairs(h, k, ecart, 0, strat, atR);
4737  initenterstrongPairs(h, k, ecart, 0, strat, atR);
4738  clearSbatch(h, k, pos, strat);
4739 }
4741 void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4742 {
4744  // enter also zero divisor * poly, if this is non zero and of smaller degree
4745  if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4746  if(strat->sigdrop) return;
4747  initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4748  if(strat->sigdrop) return;
4749  initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4750  if(strat->sigdrop) return;
4751  clearSbatch(h, k, pos, strat);
4752 }
4753 #endif
4754 
4755 /*2
4756 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4757 *superfluous elements in S will be deleted
4758 */
4759 void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4760 {
4761  int j=pos;
4762 
4764  initenterpairs(h,k,ecart,0,strat, atR);
4765  if ( (!strat->fromT)
4766  && ((strat->syzComp==0)
4767  ||(pGetComp(h)<=strat->syzComp)))
4768  {
4769  unsigned long h_sev = pGetShortExpVector(h);
4770  loop
4771  {
4772  if (j > k) break;
4773  clearS(h,h_sev, &j,&k,strat);
4774  j++;
4775  }
4776  }
4777 }
4778 
4779 /*2
4780 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4781 *superfluous elements in S will be deleted
4782 *this is a special variant of signature-based algorithms including the
4783 *signatures for criteria checks
4784 */
4785 void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4786 {
4787  int j=pos;
4789  initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4790  if ( (!strat->fromT)
4791  && ((strat->syzComp==0)
4792  ||(pGetComp(h)<=strat->syzComp)))
4793  {
4794  unsigned long h_sev = pGetShortExpVector(h);
4795  loop
4796  {
4797  if (j > k) break;
4798  clearS(h,h_sev, &j,&k,strat);
4799  j++;
4800  }
4801  }
4802 }
4803 
4804 /*2
4805 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4806 *superfluous elements in S will be deleted
4807 */
4808 void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4809 {
4810  int j;
4811  const int iCompH = pGetComp(h);
4812 
4813  if (rField_is_Ring(currRing))
4814  {
4815  for (j=0; j<=k; j++)
4816  {
4817  const int iCompSj = pGetComp(strat->S[j]);
4818  if ((iCompH==iCompSj)
4819  //|| (0==iCompH) // can only happen,if iCompSj==0
4820  || (0==iCompSj))
4821  {
4822  enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4823  }
4824  }
4825  kMergeBintoL(strat);
4826  }
4827  else
4828  {
4829  for (j=0; j<=k; j++)
4830  {
4831  const int iCompSj = pGetComp(strat->S[j]);
4832  if ((iCompH==iCompSj)
4833  //|| (0==iCompH) // can only happen,if iCompSj==0
4834  || (0==iCompSj))
4835  {
4836  enterOnePairSpecial(j,h,ecart,strat, atR);
4837  }
4838  }
4839  }
4840 
4841  if (strat->noClearS) return;
4842 
4843 // #ifdef HAVE_PLURAL
4844 /*
4845  if (rIsPluralRing(currRing))
4846  {
4847  j=pos;
4848  loop
4849  {
4850  if (j > k) break;
4851 
4852  if (pLmDivisibleBy(h, strat->S[j]))
4853  {
4854  deleteInS(j, strat);
4855  j--;
4856  k--;
4857  }
4858 
4859  j++;
4860  }
4861  }
4862  else
4863 */
4864 // #endif // ??? Why was the following cancelation disabled for non-commutative rings?
4865  {
4866  j=pos;
4867  loop
4868  {
4869  unsigned long h_sev = pGetShortExpVector(h);
4870  if (j > k) break;
4871  clearS(h,h_sev,&j,&k,strat);
4872  j++;
4873  }
4874  }
4875 }
4876 
4877 /*2
4878 *reorders s with respect to posInS,
4879 *suc is the first changed index or zero
4880 */
4882 void reorderS (int* suc,kStrategy strat)
4883 {
4884  int i,j,at,ecart, s2r;
4885  int fq=0;
4886  unsigned long sev;
4887  poly p;
4888  int new_suc=strat->sl+1;
4889  i= *suc;
4890  if (i<0) i=0;
4891 
4892  for (; i<=strat->sl; i++)
4893  {
4894  at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4895  if (at != i)
4896  {
4897  if (new_suc > at) new_suc = at;
4898  p = strat->S[i];
4899  ecart = strat->ecartS[i];
4900  sev = strat->sevS[i];
4901  s2r = strat->S_2_R[i];
4902  if (strat->fromQ!=NULL) fq=strat->fromQ[i];
4903  for (j=i; j>=at+1; j--)
4904  {
4905  strat->S[j] = strat->S[j-1];
4906  strat->ecartS[j] = strat->ecartS[j-1];
4907  strat->sevS[j] = strat->sevS[j-1];
4908  strat->S_2_R[j] = strat->S_2_R[j-1];
4909  }
4910  strat->S[at] = p;
4911  strat->ecartS[at] = ecart;
4912  strat->sevS[at] = sev;
4913  strat->S_2_R[at] = s2r;
4914  if (strat->fromQ!=NULL)
4915  {
4916  for (j=i; j>=at+1; j--)
4917  {
4918  strat->fromQ[j] = strat->fromQ[j-1];
4919  }
4920  strat->fromQ[at]=fq;
4921  }
4922  }
4923  }
4924  if (new_suc <= strat->sl) *suc=new_suc;
4925  else *suc=-1;
4926 }
4927 
4928 
4929 /*2
4930 *looks up the position of p in set
4931 *set[0] is the smallest with respect to the ordering-procedure deg/pComp
4932 * Assumption: posInS only depends on the leading term
4933 * otherwise, bba has to be changed
4934 */
4935 int posInS (const kStrategy strat, const int length,const poly p,
4936  const int ecart_p)
4937 {
4938  if(length==-1) return 0;
4939  polyset set=strat->S;
4940  int i;
4941  int an = 0;
4942  int en = length;
4943  int cmp_int = currRing->OrdSgn;
4945 #ifdef HAVE_PLURAL
4946  && (currRing->real_var_start==0)
4947 #endif
4948 #if 0
4949  || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
4950 #endif
4951  )
4952  {
4953  int o=p_Deg(p,currRing);
4954  int oo=p_Deg(set[length],currRing);
4955 
4956  if ((oo<o)
4957  || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
4958  return length+1;
4959 
4960  loop
4961  {
4962  if (an >= en-1)
4963  {
4964  if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
4965  {
4966  return an;
4967  }
4968  return en;
4969  }
4970  i=(an+en) / 2;
4971  if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
4972  else an=i;
4973  }
4974  }
4975  else
4976  {
4977  if (rField_is_Ring(currRing))
4978  {
4979  if (pLmCmp(set[length],p)== -cmp_int)
4980  return length+1;
4981  int cmp;
4982  loop
4983  {
4984  if (an >= en-1)
4985  {
4986  cmp = pLmCmp(set[an],p);
4987  if (cmp == cmp_int) return an;
4988  if (cmp == -cmp_int) return en;
4989  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
4990  return an;
4991  }
4992  i = (an+en) / 2;
4993  cmp = pLmCmp(set[i],p);
4994  if (cmp == cmp_int) en = i;
4995  else if (cmp == -cmp_int) an = i;
4996  else
4997  {
4998  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
4999  else en = i;
5000  }
5001  }
5002  }
5003  else
5004  if (pLmCmp(set[length],p)== -cmp_int)
5005  return length+1;
5006 
5007  loop
5008  {
5009  if (an >= en-1)
5010  {
5011  if (pLmCmp(set[an],p) == cmp_int) return an;
5012  if (pLmCmp(set[an],p) == -cmp_int) return en;
5013  if ((cmp_int!=1)
5014  && ((strat->ecartS[an])>ecart_p))
5015  return an;
5016  return en;
5017  }
5018  i=(an+en) / 2;
5019  if (pLmCmp(set[i],p) == cmp_int) en=i;
5020  else if (pLmCmp(set[i],p) == -cmp_int) an=i;
5021  else
5022  {
5023  if ((cmp_int!=1)
5024  &&((strat->ecartS[i])<ecart_p))
5025  en=i;
5026  else
5027  an=i;
5028  }
5029  }
5030  }
5031 }
5032 
5033 
5034 // sorts by degree and pLtCmp
5035 // but puts pure monomials at the beginning
5036 int posInSMonFirst (const kStrategy strat, const int length,const poly p)
5037 {
5038  if (length<0) return 0;
5039  polyset set=strat->S;
5040  if(pNext(p) == NULL)
5041  {
5042  int mon = 0;
5043  for(int i = 0;i<=length;i++)
5044  {
5045  if(set[i] != NULL && pNext(set[i]) == NULL)
5046  mon++;
5047  }
5048  int o = p_Deg(p,currRing);
5049  int op = p_Deg(set[mon],currRing);
5050 
5051  if ((op < o)
5052  || ((op == o) && (pLtCmp(set[mon],p) == -1)))
5053  return length+1;
5054  int i;
5055  int an = 0;
5056  int en= mon;
5057  loop
5058  {
5059  if (an >= en-1)
5060  {
5061  op = p_Deg(set[an],currRing);
5062  if ((op < o)
5063  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5064  return en;
5065  return an;
5066  }
5067  i=(an+en) / 2;
5068  op = p_Deg(set[i],currRing);
5069  if ((op < o)
5070  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5071  an=i;
5072  else
5073  en=i;
5074  }
5075  }
5076  else /*if(pNext(p) != NULL)*/
5077  {
5078  int o = p_Deg(p,currRing);
5079  int op = p_Deg(set[length],currRing);
5080 
5081  if ((op < o)
5082  || ((op == o) && (pLtCmp(set[length],p) == -1)))
5083  return length+1;
5084  int i;
5085  int an = 0;
5086  for(i=0;i<=length;i++)
5087  if(set[i] != NULL && pNext(set[i]) == NULL)
5088  an++;
5089  int en= length;
5090  loop
5091  {
5092  if (an >= en-1)
5093  {
5094  op = p_Deg(set[an],currRing);
5095  if ((op < o)
5096  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5097  return en;
5098  return an;
5099  }
5100  i=(an+en) / 2;
5101  op = p_Deg(set[i],currRing);
5102  if ((op < o)
5103  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5104  an=i;
5105  else
5106  en=i;
5107  }
5108  }
5109 }
5110 
5111 // sorts by degree and pLtCmp in the block between start,end;
5112 // but puts pure monomials at the beginning
5113 int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
5114 {
5115  if(end < 0 || end >= IDELEMS(F))
5116  end = IDELEMS(F);
5117  if (end<0) return 0;
5118  if(pNext(p) == NULL) return start;
5119  polyset set=F->m;
5120  int o = p_Deg(p,currRing);
5121  int op;
5122  int i;
5123  int an = start;
5124  for(i=start;i<end;i++)
5125  if(set[i] != NULL && pNext(set[i]) == NULL)
5126  an++;
5127  if(an == end-1)
5128  return end;
5129  int en= end;
5130  loop
5131  {
5132  if(an>=en)
5133  return en;
5134  if (an == en-1)
5135  {
5136  op = p_Deg(set[an],currRing);
5137  if ((op < o)
5138  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5139  return en;
5140  return an;
5141  }
5142  i=(an+en) / 2;
5143  op = p_Deg(set[i],currRing);
5144  if ((op < o)
5145  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5146  an=i;
5147  else
5148  en=i;
5149  }
5150 }
5151 
5152 
5153 /*2
5154 * looks up the position of p in set
5155 * the position is the last one
5156 */
5157 int posInT0 (const TSet,const int length,LObject &)
5158 {
5159  return (length+1);
5160 }
5161 
5162 
5163 /*2
5164 * looks up the position of p in T
5165 * set[0] is the smallest with respect to the ordering-procedure
5166 * pComp
5167 */
5168 int posInT1 (const TSet set,const int length,LObject &p)
5169 {
5170  if (length==-1) return 0;
5171 
5172  if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
5173 
5174  int i;
5175  int an = 0;
5176  int en= length;
5177 
5178  loop
5179  {
5180  if (an >= en-1)
5181  {
5182  if (pLmCmp(set[an].p,p.p) == currRing->OrdSgn) return an;
5183  return en;
5184  }
5185  i=(an+en) / 2;
5186  if (pLmCmp(set[i].p,p.p) == currRing->OrdSgn) en=i;
5187  else an=i;
5188  }
5189 }
5190 
5191 /*2
5192 * looks up the position of p in T
5193 * set[0] is the smallest with respect to the ordering-procedure
5194 * length
5195 */
5196 int posInT2 (const TSet set,const int length,LObject &p)
5197 {
5198  p.GetpLength();
5199  if (length==-1)
5200  return 0;
5201  if (set[length].length<p.length)
5202  return length+1;
5203 
5204  int i;
5205  int an = 0;
5206  int en= length;
5207 
5208  loop
5209  {
5210  if (an >= en-1)
5211  {
5212  if (set[an].length>p.length) return an;
5213  return en;
5214  }
5215  i=(an+en) / 2;
5216  if (set[i].length>p.length) en=i;
5217  else an=i;
5218  }
5219 }
5220 
5221 /*2
5222 * looks up the position of p in T
5223 * set[0] is the smallest with respect to the ordering-procedure
5224 * totaldegree,pComp
5225 */
5226 int posInT11 (const TSet set,const int length,LObject &p)
5227 {
5228  if (length==-1) return 0;
5229 
5230  int o = p.GetpFDeg();
5231  int op = set[length].GetpFDeg();
5232 
5233  if ((op < o)
5234  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5235  return length+1;
5236 
5237  int i;
5238  int an = 0;
5239  int en= length;
5240 
5241  loop
5242  {
5243  if (an >= en-1)
5244  {
5245  op= set[an].GetpFDeg();
5246  if ((op > o)
5247  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5248  return an;
5249  return en;
5250  }
5251  i=(an+en) / 2;
5252  op = set[i].GetpFDeg();
5253  if (( op > o)
5254  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5255  en=i;
5256  else
5257  an=i;
5258  }
5259 }
5260 
5261 #ifdef HAVE_RINGS
5262 int posInT11Ring (const TSet set,const int length,LObject &p)
5263 {
5264  if (length==-1) return 0;
5265 
5266  int o = p.GetpFDeg();
5267  int op = set[length].GetpFDeg();
5268 
5269  if ((op < o)
5270  || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5271  return length+1;
5272 
5273  int i;
5274  int an = 0;
5275  int en= length;
5276 
5277  loop
5278  {
5279  if (an >= en-1)
5280  {
5281  op= set[an].GetpFDeg();
5282  if ((op > o)
5283  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5284  return an;
5285  return en;
5286  }
5287  i=(an+en) / 2;
5288  op = set[i].GetpFDeg();
5289  if (( op > o)
5290  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5291  en=i;
5292  else
5293  an=i;
5294  }
5295 }
5296 #endif
5297 
5298 /*2 Pos for rings T: Here I am
5299 * looks up the position of p in T
5300 * set[0] is the smallest with respect to the ordering-procedure
5301 * totaldegree,pComp
5302 */
5303 int posInTrg0 (const TSet set,const int length,LObject &p)
5304 {
5305  if (length==-1) return 0;
5306  int o = p.GetpFDeg();
5307  int op = set[length].GetpFDeg();
5308  int i;
5309  int an = 0;
5310  int en = length;
5311  int cmp_int = currRing->OrdSgn;
5312  if ((op < o) || (pLmCmp(set[length].p,p.p)== -cmp_int))
5313  return length+1;
5314  int cmp;
5315  loop
5316  {
5317  if (an >= en-1)
5318  {
5319  op = set[an].GetpFDeg();
5320  if (op > o) return an;
5321  if (op < 0) return en;
5322  cmp = pLmCmp(set[an].p,p.p);
5323  if (cmp == cmp_int) return an;
5324  if (cmp == -cmp_int) return en;
5325  if (nGreater(pGetCoeff(p.p), pGetCoeff(set[an].p))) return en;
5326  return an;
5327  }
5328  i = (an + en) / 2;
5329  op = set[i].GetpFDeg();
5330  if (op > o) en = i;
5331  else if (op < o) an = i;
5332  else
5333  {
5334  cmp = pLmCmp(set[i].p,p.p);
5335  if (cmp == cmp_int) en = i;
5336  else if (cmp == -cmp_int) an = i;
5337  else if (nGreater(pGetCoeff(p.p), pGetCoeff(set[i].p))) an = i;
5338  else en = i;
5339  }
5340  }
5341 }
5342 /*
5343  int o = p.GetpFDeg();
5344  int op = set[length].GetpFDeg();
5345 
5346  if ((op < o)
5347  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5348  return length+1;
5349 
5350  int i;
5351  int an = 0;
5352  int en= length;
5353 
5354  loop
5355  {
5356  if (an >= en-1)
5357  {
5358  op= set[an].GetpFDeg();
5359  if ((op > o)
5360  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5361  return an;
5362  return en;
5363  }
5364  i=(an+en) / 2;
5365  op = set[i].GetpFDeg();
5366  if (( op > o)
5367  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5368  en=i;
5369  else
5370  an=i;
5371  }
5372 }
5373  */
5374 /*2
5375 * looks up the position of p in T
5376 * set[0] is the smallest with respect to the ordering-procedure
5377 * totaldegree,pComp
5378 */
5379 int posInT110 (const TSet set,const int length,LObject &p)
5380 {
5381  p.GetpLength();
5382  if (length==-1) return 0;
5383 
5384  int o = p.GetpFDeg();
5385  int op = set[length].GetpFDeg();
5386 
5387  if (( op < o)
5388  || (( op == o) && (set[length].length<p.length))
5389  || (( op == o) && (set[length].length == p.length)
5390  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5391  return length+1;
5392 
5393  int i;
5394  int an = 0;
5395  int en= length;
5396  loop
5397  {
5398  if (an >= en-1)
5399  {
5400  op = set[an].GetpFDeg();
5401  if (( op > o)
5402  || (( op == o) && (set[an].length > p.length))
5403  || (( op == o) && (set[an].length == p.length)
5404  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5405  return an;
5406  return en;
5407  }
5408  i=(an+en) / 2;
5409  op = set[i].GetpFDeg();
5410  if (( op > o)
5411  || (( op == o) && (set[i].length > p.length))
5412  || (( op == o) && (set[i].length == p.length)
5413  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5414  en=i;
5415  else
5416  an=i;
5417  }
5418 }
5419 
5420 #ifdef HAVE_RINGS
5421 int posInT110Ring (const TSet set,const int length,LObject &p)
5422 {
5423  p.GetpLength();
5424  if (length==-1) return 0;
5425 
5426  int o = p.GetpFDeg();
5427  int op = set[length].GetpFDeg();
5428 
5429  if (( op < o)
5430  || (( op == o) && (set[length].length<p.length))
5431  || (( op == o) && (set[length].length == p.length)
5432  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5433  return length+1;
5434 
5435  int i;
5436  int an = 0;
5437  int en= length;
5438  loop
5439  {
5440  if (an >= en-1)
5441  {
5442  op = set[an].GetpFDeg();
5443  if (( op > o)
5444  || (( op == o) && (set[an].length > p.length))
5445  || (( op == o) && (set[an].length == p.length)
5446  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5447  return an;
5448  return en;
5449  }
5450  i=(an+en) / 2;
5451  op = set[i].GetpFDeg();
5452  if (( op > o)
5453  || (( op == o) && (set[i].length > p.length))
5454  || (( op == o) && (set[i].length == p.length)
5455  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5456  en=i;
5457  else
5458  an=i;
5459  }
5460 }
5461 #endif
5462 
5463 /*2
5464 * looks up the position of p in set
5465 * set[0] is the smallest with respect to the ordering-procedure
5466 * pFDeg
5467 */
5468 int posInT13 (const TSet set,const int length,LObject &p)
5469 {
5470  if (length==-1) return 0;
5471 
5472  int o = p.GetpFDeg();
5473 
5474  if (set[length].GetpFDeg() <= o)
5475  return length+1;
5476 
5477  int i;
5478  int an = 0;
5479  int en= length;
5480  loop
5481  {
5482  if (an >= en-1)
5483  {
5484  if (set[an].GetpFDeg() > o)
5485  return an;
5486  return en;
5487  }
5488  i=(an+en) / 2;
5489  if (set[i].GetpFDeg() > o)
5490  en=i;
5491  else
5492  an=i;
5493  }
5494 }
5495 
5496 // determines the position based on: 1.) Ecart 2.) pLength
5497 int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5498 {
5499  int ol = p.GetpLength();
5500  if (length==-1) return 0;
5501 
5502  int op=p.ecart;
5503 
5504  int oo=set[length].ecart;
5505  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
5506  return length+1;
5507 
5508  int i;
5509  int an = 0;
5510  int en= length;
5511  loop
5512  {
5513  if (an >= en-1)
5514  {
5515  int oo=set[an].ecart;
5516  if((oo > op)
5517  || ((oo==op) && (set[an].pLength > ol)))
5518  return an;
5519  return en;
5520  }
5521  i=(an+en) / 2;
5522  int oo=set[i].ecart;
5523  if ((oo > op)
5524  || ((oo == op) && (set[i].pLength > ol)))
5525  en=i;
5526  else
5527  an=i;
5528  }
5529 }
5530 
5531 /*2
5532 * looks up the position of p in set
5533 * set[0] is the smallest with respect to the ordering-procedure
5534 * maximaldegree, pComp
5535 */
5536 int posInT15 (const TSet set,const int length,LObject &p)
5537 /*{
5538  *int j=0;
5539  * int o;
5540  *
5541  * o = p.GetpFDeg()+p.ecart;
5542  * loop
5543  * {
5544  * if ((set[j].GetpFDeg()+set[j].ecart > o)
5545  * || ((set[j].GetpFDeg()+set[j].ecart == o)
5546  * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5547  * {
5548  * return j;
5549  * }
5550  * j++;
5551  * if (j > length) return j;
5552  * }
5553  *}
5554  */
5555 {
5556  if (length==-1) return 0;
5557 
5558  int o = p.GetpFDeg() + p.ecart;
5559  int op = set[length].GetpFDeg()+set[length].ecart;
5560 
5561  if ((op < o)
5562  || ((op == o)
5563  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5564  return length+1;
5565 
5566  int i;
5567  int an = 0;
5568  int en= length;
5569  loop
5570  {
5571  if (an >= en-1)
5572  {
5573  op = set[an].GetpFDeg()+set[an].ecart;
5574  if (( op > o)
5575  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5576  return an;
5577  return en;
5578  }
5579  i=(an+en) / 2;
5580  op = set[i].GetpFDeg()+set[i].ecart;
5581  if (( op > o)
5582  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5583  en=i;
5584  else
5585  an=i;
5586  }
5587 }
5588 
5589 #ifdef HAVE_RINGS
5590 int posInT15Ring (const TSet set,const int length,LObject &p)
5591 {
5592  if (length==-1) return 0;
5593 
5594  int o = p.GetpFDeg() + p.ecart;
5595  int op = set[length].GetpFDeg()+set[length].ecart;
5596 
5597  if ((op < o)
5598  || ((op == o)
5599  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5600  return length+1;
5601 
5602  int i;
5603  int an = 0;
5604  int en= length;
5605  loop
5606  {
5607  if (an >= en-1)
5608  {
5609  op = set[an].GetpFDeg()+set[an].ecart;
5610  if (( op > o)
5611  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5612  return an;
5613  return en;
5614  }
5615  i=(an+en) / 2;
5616  op = set[i].GetpFDeg()+set[i].ecart;
5617  if (( op > o)
5618  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5619  en=i;
5620  else
5621  an=i;
5622  }
5623 }
5624 #endif
5625 
5626 /*2
5627 * looks up the position of p in set
5628 * set[0] is the smallest with respect to the ordering-procedure
5629 * pFDeg+ecart, ecart, pComp
5630 */
5631 int posInT17 (const TSet set,const int length,LObject &p)
5632 /*
5633 *{
5634 * int j=0;
5635 * int o;
5636 *
5637 * o = p.GetpFDeg()+p.ecart;
5638 * loop
5639 * {
5640 * if ((pFDeg(set[j].p)+set[j].ecart > o)
5641 * || (((pFDeg(set[j].p)+set[j].ecart == o)
5642 * && (set[j].ecart < p.ecart)))
5643 * || ((pFDeg(set[j].p)+set[j].ecart == o)
5644 * && (set[j].ecart==p.ecart)
5645 * && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5646 * return j;
5647 * j++;
5648 * if (j > length) return j;
5649 * }
5650 * }
5651 */
5652 {
5653  if (length==-1) return 0;
5654 
5655  int o = p.GetpFDeg() + p.ecart;
5656  int op = set[length].GetpFDeg()+set[length].ecart;
5657 
5658  if ((op < o)
5659  || (( op == o) && (set[length].ecart > p.ecart))
5660  || (( op == o) && (set[length].ecart==p.ecart)
5661  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5662  return length+1;
5663 
5664  int i;
5665  int an = 0;
5666  int en= length;
5667  loop
5668  {
5669  if (an >= en-1)
5670  {
5671  op = set[an].GetpFDeg()+set[an].ecart;
5672  if (( op > o)
5673  || (( op == o) && (set[an].ecart < p.ecart))
5674  || (( op == o) && (set[an].ecart==p.ecart)
5675  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5676  return an;
5677  return en;
5678  }
5679  i=(an+en) / 2;
5680  op = set[i].GetpFDeg()+set[i].ecart;
5681  if ((op > o)
5682  || (( op == o) && (set[i].ecart < p.ecart))
5683  || (( op == o) && (set[i].ecart == p.ecart)
5684  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5685  en=i;
5686  else
5687  an=i;
5688  }
5689 }
5690 
5691 #ifdef HAVE_RINGS
5692 int posInT17Ring (const TSet set,const int length,LObject &p)
5693 {
5694  if (length==-1) return 0;
5695 
5696  int o = p.GetpFDeg() + p.ecart;
5697  int op = set[length].GetpFDeg()+set[length].ecart;
5698 
5699  if ((op < o)
5700  || (( op == o) && (set[length].ecart > p.ecart))
5701  || (( op == o) && (set[length].ecart==p.ecart)
5702  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5703  return length+1;
5704 
5705  int i;
5706  int an = 0;
5707  int en= length;
5708  loop
5709  {
5710  if (an >= en-1)
5711  {
5712  op = set[an].GetpFDeg()+set[an].ecart;
5713  if (( op > o)
5714  || (( op == o) && (set[an].ecart < p.ecart))
5715  || (( op == o) && (set[an].ecart==p.ecart)
5716  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5717  return an;
5718  return en;
5719  }
5720  i=(an+en) / 2;
5721  op = set[i].GetpFDeg()+set[i].ecart;
5722  if ((op > o)
5723  || (( op == o) && (set[i].ecart < p.ecart))
5724  || (( op == o) && (set[i].ecart == p.ecart)
5725  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5726  en=i;
5727  else
5728  an=i;
5729  }
5730 }
5731 #endif
5732 
5733 /*2
5734 * looks up the position of p in set
5735 * set[0] is the smallest with respect to the ordering-procedure
5736 * pGetComp, pFDeg+ecart, ecart, pComp
5737 */
5738 int posInT17_c (const TSet set,const int length,LObject &p)
5739 {
5740  if (length==-1) return 0;
5741 
5742  int cc = (-1+2*currRing->order[0]==ringorder_c);
5743  /* cc==1 for (c,..), cc==-1 for (C,..) */
5744  int o = p.GetpFDeg() + p.ecart;
5745  int c = pGetComp(p.p)*cc;
5746 
5747  if (pGetComp(set[length].p)*cc < c)
5748  return length+1;
5749  if (pGetComp(set[length].p)*cc == c)
5750  {
5751  int op = set[length].GetpFDeg()+set[length].ecart;
5752  if ((op < o)
5753  || ((op == o) && (set[length].ecart > p.ecart))
5754  || ((op == o) && (set[length].ecart==p.ecart)
5755  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5756  return length+1;
5757  }
5758 
5759  int i;
5760  int an = 0;
5761  int en= length;
5762  loop
5763  {
5764  if (an >= en-1)
5765  {
5766  if (pGetComp(set[an].p)*cc < c)
5767  return en;
5768  if (pGetComp(set[an].p)*cc == c)
5769  {
5770  int op = set[an].GetpFDeg()+set[an].ecart;
5771  if ((op > o)
5772  || ((op == o) && (set[an].ecart < p.ecart))
5773  || ((op == o) && (set[an].ecart==p.ecart)
5774  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5775  return an;
5776  }
5777  return en;
5778  }
5779  i=(an+en) / 2;
5780  if (pGetComp(set[i].p)*cc > c)
5781  en=i;
5782  else if (pGetComp(set[i].p)*cc == c)
5783  {
5784  int op = set[i].GetpFDeg()+set[i].ecart;
5785  if ((op > o)
5786  || ((op == o) && (set[i].ecart < p.ecart))
5787  || ((op == o) && (set[i].ecart == p.ecart)
5788  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5789  en=i;
5790  else
5791  an=i;
5792  }
5793  else
5794  an=i;
5795  }
5796 }
5797 
5798 #ifdef HAVE_RINGS
5799 int posInT17_cRing (const TSet set,const int length,LObject &p)
5800 {
5801  if (length==-1) return 0;
5802 
5803  int cc = (-1+2*currRing->order[0]==ringorder_c);
5804  /* cc==1 for (c,..), cc==-1 for (C,..) */
5805  int o = p.GetpFDeg() + p.ecart;
5806  int c = pGetComp(p.p)*cc;
5807 
5808  if (pGetComp(set[length].p)*cc < c)
5809  return length+1;
5810  if (pGetComp(set[length].p)*cc == c)
5811  {
5812  int op = set[length].GetpFDeg()+set[length].ecart;
5813  if ((op < o)
5814  || ((op == o) && (set[length].ecart > p.ecart))
5815  || ((op == o) && (set[length].ecart==p.ecart)
5816  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5817  return length+1;
5818  }
5819 
5820  int i;
5821  int an = 0;
5822  int en= length;
5823  loop
5824  {
5825  if (an >= en-1)
5826  {
5827  if (pGetComp(set[an].p)*cc < c)
5828  return en;
5829  if (pGetComp(set[an].p)*cc == c)
5830  {
5831  int op = set[an].GetpFDeg()+set[an].ecart;
5832  if ((op > o)
5833  || ((op == o) && (set[an].ecart < p.ecart))
5834  || ((op == o) && (set[an].ecart==p.ecart)
5835  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5836  return an;
5837  }
5838  return en;
5839  }
5840  i=(an+en) / 2;
5841  if (pGetComp(set[i].p)*cc > c)
5842  en=i;
5843  else if (pGetComp(set[i].p)*cc == c)
5844  {
5845  int op = set[i].GetpFDeg()+set[i].ecart;
5846  if ((op > o)
5847  || ((op == o) && (set[i].ecart < p.ecart))
5848  || ((op == o) && (set[i].ecart == p.ecart)
5849  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5850  en=i;
5851  else
5852  an=i;
5853  }
5854  else
5855  an=i;
5856  }
5857 }
5858 #endif
5859 
5860 /*2
5861 * looks up the position of p in set
5862 * set[0] is the smallest with respect to
5863 * ecart, pFDeg, length
5864 */
5865 int posInT19 (const TSet set,const int length,LObject &p)
5866 {
5867  p.GetpLength();
5868  if (length==-1) return 0;
5869 
5870  int o = p.ecart;
5871  int op=p.GetpFDeg();
5872 
5873  if (set[length].ecart < o)
5874  return length+1;
5875  if (set[length].ecart == o)
5876  {
5877  int oo=set[length].GetpFDeg();
5878  if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5879  return length+1;
5880  }
5881 
5882  int i;
5883  int an = 0;
5884  int en= length;
5885  loop
5886  {
5887  if (an >= en-1)
5888  {
5889  if (set[an].ecart > o)
5890  return an;
5891  if (set[an].ecart == o)
5892  {
5893  int oo=set[an].GetpFDeg();
5894  if((oo > op)
5895  || ((oo==op) && (set[an].length > p.length)))
5896  return an;
5897  }
5898  return en;
5899  }
5900  i=(an+en) / 2;
5901  if (set[i].ecart > o)
5902  en=i;
5903  else if (set[i].ecart == o)
5904  {
5905  int oo=set[i].GetpFDeg();
5906  if ((oo > op)
5907  || ((oo == op) && (set[i].length > p.length)))
5908  en=i;
5909  else
5910  an=i;
5911  }
5912  else
5913  an=i;
5914  }
5915 }
5916 
5917 /*2
5918 *looks up the position of polynomial p in set
5919 *set[length] is the smallest element in set with respect
5920 *to the ordering-procedure pComp
5921 */
5922 int posInLSpecial (const LSet set, const int length,
5923  LObject *p,const kStrategy)
5924 {
5925  if (length<0) return 0;
5926 
5927  int d=p->GetpFDeg();
5928  int op=set[length].GetpFDeg();
5929 
5930  if ((op > d)
5931  || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
5932  || (pLmCmp(set[length].p,p->p)== currRing->OrdSgn))
5933  return length+1;
5934 
5935  int i;
5936  int an = 0;
5937  int en= length;
5938  loop
5939  {
5940  if (an >= en-1)
5941  {
5942  op=set[an].GetpFDeg();
5943  if ((op > d)
5944  || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
5945  || (pLmCmp(set[an].p,p->p)== currRing->OrdSgn))
5946  return en;
5947  return an;
5948  }
5949  i=(an+en) / 2;
5950  op=set[i].GetpFDeg();
5951  if ((op>d)
5952  || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
5953  || (pLmCmp(set[i].p,p->p) == currRing->OrdSgn))
5954  an=i;
5955  else
5956  en=i;
5957  }
5958 }
5959 
5960 /*2
5961 *looks up the position of polynomial p in set
5962 *set[length] is the smallest element in set with respect
5963 *to the ordering-procedure pComp
5964 */
5965 int posInL0 (const LSet set, const int length,
5966  LObject* p,const kStrategy)
5967 {
5968  if (length<0) return 0;
5969 
5970  if (pLmCmp(set[length].p,p->p)== currRing->OrdSgn)
5971  return length+1;
5972 
5973  int i;
5974  int an = 0;
5975  int en= length;
5976  loop
5977  {
5978  if (an >= en-1)
5979  {
5980  if (pLmCmp(set[an].p,p->p) == currRing->OrdSgn) return en;
5981  return an;
5982  }
5983  i=(an+en) / 2;
5984  if (pLmCmp(set[i].p,p->p) == currRing->OrdSgn) an=i;
5985  else en=i;
5986  /*aend. fuer lazy == in !=- machen */
5987  }
5988 }
5989 
5990 #ifdef HAVE_RINGS
5991 int posInL0Ring (const LSet set, const int length,
5992  LObject* p,const kStrategy)
5993 {
5994  if (length<0) return 0;
5995 
5996  if (pLtCmpOrdSgnEqP(set[length].p,p->p))
5997  return length+1;
5998 
5999  int i;
6000  int an = 0;
6001  int en= length;
6002  loop
6003  {
6004  if (an >= en-1)
6005  {
6006  if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
6007  return an;
6008  }
6009  i=(an+en) / 2;
6010  if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
6011  else en=i;
6012  /*aend. fuer lazy == in !=- machen */
6013  }
6014 }
6015 #endif
6016 
6017 /*2
6018 * looks up the position of polynomial p in set
6019 * e is the ecart of p
6020 * set[length] is the smallest element in set with respect
6021 * to the signature order
6022 */
6023 int posInLSig (const LSet set, const int length,
6024  LObject* p,const kStrategy /*strat*/)
6025 {
6026  if (length<0) return 0;
6027  if (pLtCmp(set[length].sig,p->sig)== currRing->OrdSgn)
6028  return length+1;
6029 
6030  int i;
6031  int an = 0;
6032  int en= length;
6033  loop
6034  {
6035  if (an >= en-1)
6036  {
6037  if (pLtCmp(set[an].sig,p->sig) == currRing->OrdSgn) return en;
6038  return an;
6039  }
6040  i=(an+en) / 2;
6041  if (pLtCmp(set[i].sig,p->sig) == currRing->OrdSgn) an=i;
6042  else en=i;
6043  /*aend. fuer lazy == in !=- machen */
6044  }
6045 }
6046 //sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
6047 int posInLSigRing (const LSet set, const int length,
6048  LObject* p,const kStrategy /*strat*/)
6049 {
6050  assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
6051  if (length<0) return 0;
6052  if (pLtCmp(set[length].sig,p->sig)== 1)
6053  return length+1;
6054 
6055  int an,en,i;
6056  an = 0;
6057  en = length+1;
6058  int cmp;
6059  loop
6060  {
6061  if (an >= en-1)
6062  {
6063  if(an == en)
6064  return en;
6065  cmp = pLtCmp(set[an].sig,p->sig);
6066  if (cmp == 1)
6067  return en;
6068  if (cmp == -1)
6069  return an;
6070  if (cmp == 0)
6071  {
6072  if (set[an].FDeg > p->FDeg)
6073  return en;
6074  if (set[an].FDeg < p->FDeg)
6075  return an;
6076  if (set[an].FDeg == p->FDeg)
6077  {
6078  cmp = pLtCmp(set[an].p,p->p);
6079  if(cmp == 1)
6080  return en;
6081  else
6082  return an;
6083  }
6084  }
6085  }
6086  i=(an+en) / 2;
6087  cmp = pLtCmp(set[i].sig,p->sig);
6088  if (cmp == 1)
6089  an = i;
6090  if (cmp == -1)
6091  en = i;
6092  if (cmp == 0)
6093  {
6094  if (set[i].FDeg > p->FDeg)
6095  an = i;
6096  if (set[i].FDeg < p->FDeg)
6097  en = i;
6098  if (set[i].FDeg == p->FDeg)
6099  {
6100  cmp = pLtCmp(set[i].p,p->p);
6101  if(cmp == 1)
6102  an = i;
6103  else
6104  en = i;
6105  }
6106  }
6107  }
6108 }
6110 int posInLRing (const LSet set, const int length,
6111  LObject* p,const kStrategy /*strat*/)
6112 {
6113  if (length < 0) return 0;
6114  if (set[length].FDeg > p->FDeg)
6115  return length+1;
6116  if (set[length].FDeg == p->FDeg)
6117  if(set[length].GetpLength() > p->GetpLength())
6118  return length+1;
6119  int i;
6120  int an = 0;
6121  int en= length+1;
6122  loop
6123  {
6124  if (an >= en-1)
6125  {
6126  if(an == en)
6127  return en;
6128  if (set[an].FDeg > p->FDeg)
6129  return en;
6130  if(set[an].FDeg == p->FDeg)
6131  {
6132  if(set[an].GetpLength() > p->GetpLength())
6133  return en;
6134  else
6135  {
6136  if(set[an].GetpLength() == p->GetpLength())
6137  {
6138  if(nGreater(set[an].p->coef, p->p->coef))
6139  return en;
6140  else
6141  return an;
6142  }
6143  else
6144  {
6145  return an;
6146  }
6147  }
6148  }
6149  else
6150  return an;
6151  }
6152  i=(an+en) / 2;
6153  if (set[i].FDeg > p->FDeg)
6154  an=i;
6155  else
6156  {
6157  if(set[i].FDeg == p->FDeg)
6158  {
6159  if(set[i].GetpLength() > p->GetpLength())
6160  an=i;
6161  else
6162  {
6163  if(set[i].GetpLength() == p->GetpLength())
6164  {
6165  if(nGreater(set[i].p->coef, p->p->coef))
6166  an = i;
6167  else
6168  en = i;
6169  }
6170  else
6171  {
6172  en=i;
6173  }
6174  }
6175  }
6176  else
6177  en=i;
6178  }
6179  }
6180 }
6181 
6182 // for sba, sorting syzygies
6183 int posInSyz (const kStrategy strat, poly sig)
6184 {
6185  if (strat->syzl==0) return 0;
6186  if (pLtCmp(strat->syz[strat->syzl-1],sig) != currRing->OrdSgn)
6187  return strat->syzl;
6188  int i;
6189  int an = 0;
6190  int en= strat->syzl-1;
6191  loop
6192  {
6193  if (an >= en-1)
6194  {
6195  if (pLtCmp(strat->syz[an],sig) != currRing->OrdSgn) return en;
6196  return an;
6197  }
6198  i=(an+en) / 2;
6199  if (pLtCmp(strat->syz[i],sig) != currRing->OrdSgn) an=i;
6200  else en=i;
6201  /*aend. fuer lazy == in !=- machen */
6202  }
6203 }
6204 
6205 /*2
6206 *
6207 * is only used in F5C, must ensure that the interreduction process does add new
6208 * critical pairs to strat->L only behind all other critical pairs which are
6209 * still in strat->L!
6210 */
6211 int posInLF5C (const LSet /*set*/, const int /*length*/,
6212  LObject* /*p*/,const kStrategy strat)
6213 {
6214  return strat->Ll+1;
6215 }
6216 
6217 /*2
6218 * looks up the position of polynomial p in set
6219 * e is the ecart of p
6220 * set[length] is the smallest element in set with respect
6221 * to the ordering-procedure totaldegree,pComp
6222 */
6223 int posInL11 (const LSet set, const int length,
6224  LObject* p,const kStrategy)
6225 {
6226  if (length<0) return 0;
6227 
6228  int o = p->GetpFDeg();
6229  int op = set[length].GetpFDeg();
6230 
6231  if ((op > o)
6232  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6233  return length+1;
6234  int i;
6235  int an = 0;
6236  int en= length;
6237  loop
6238  {
6239  if (an >= en-1)
6240  {
6241  op = set[an].GetpFDeg();
6242  if ((op > o)
6243  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6244  return en;
6245  return an;
6246  }
6247  i=(an+en) / 2;
6248  op = set[i].GetpFDeg();
6249  if ((op > o)
6250  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6251  an=i;
6252  else
6253  en=i;
6254  }
6255 }
6256 
6257 #ifdef HAVE_RINGS
6258 /*2
6259 * looks up the position of polynomial p in set
6260 * set[length] is the smallest element in set with respect
6261 * to the ordering-procedure pLmCmp,totaldegree,coefficient
6262 * For the same totaldegree, original pairs (from F) will
6263 * be put at the end and smalles coefficents
6264 */
6265 int posInL11Ring (const LSet set, const int length,
6266  LObject* p,const kStrategy)
6267 {
6268  if (length<0) return 0;
6269 
6270  int o = p->GetpFDeg();
6271  int op = set[length].GetpFDeg();
6272 
6273  if ((op > o)
6274  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6275  return length+1;
6276  int i;
6277  int an = 0;
6278  int en= length;
6279  loop
6280  {
6281  if (an >= en-1)
6282  {
6283  op = set[an].GetpFDeg();
6284  if ((op > o)
6285  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6286  return en;
6287  return an;
6288  }
6289  i=(an+en) / 2;
6290  op = set[i].GetpFDeg();
6291  if ((op > o)
6292  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6293  an=i;
6294  else
6295  en=i;
6296  }
6297 }
6299 int posInLF5CRing (const LSet set, int start,const int length,
6300  LObject* p,const kStrategy)
6301 {
6302  if (length<0) return 0;
6303  if(start == (length +1)) return (length+1);
6304  int o = p->GetpFDeg();
6305  int op = set[length].GetpFDeg();
6306 
6307  if ((op > o)
6308  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6309  return length+1;
6310  int i;
6311  int an = start;
6312  int en= length;
6313  loop
6314  {
6315  if (an >= en-1)
6316  {
6317  op = set[an].GetpFDeg();
6318  if ((op > o)
6319  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6320  return en;
6321  return an;
6322  }
6323  i=(an+en) / 2;
6324  op = set[i].GetpFDeg();
6325  if ((op > o)
6326  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6327  an=i;
6328  else
6329  en=i;
6330  }
6331 }
6332 #endif
6333 
6334 #ifdef HAVE_RINGS
6335 int posInL11Ringls (const LSet set, const int length,
6336  LObject* p,const kStrategy)
6337 {
6338  if (length < 0) return 0;
6339  int an,en,i;
6340  an = 0;
6341  en = length+1;
6342  loop
6343  {
6344  if (an >= en-1)
6345  {
6346  if(an == en)
6347  return en;
6348  if (set[an].FDeg > p->FDeg)
6349  return en;
6350  if (set[an].FDeg < p->FDeg)
6351  return an;
6352  if (set[an].FDeg == p->FDeg)
6353  {
6354  number lcset,lcp;
6355  lcset = pGetCoeff(set[an].p);
6356  lcp = pGetCoeff(p->p);
6357  if(!nGreaterZero(lcset))
6358  {
6359  set[an].p=p_Neg(set[an].p,currRing);
6360  if (set[an].t_p!=NULL)
6361  pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
6362  lcset=pGetCoeff(set[an].p);
6363  }
6364  if(!nGreaterZero(lcp))
6365  {
6366  p->p=p_Neg(p->p,currRing);
6367  if (p->t_p!=NULL)
6368  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6369  lcp=pGetCoeff(p->p);
6370  }
6371  if(nGreater(lcset, lcp))
6372  {
6373  return en;
6374  }
6375  else
6376  {
6377  return an;
6378  }
6379  }
6380  }
6381  i=(an+en) / 2;
6382  if (set[i].FDeg > p->FDeg)
6383  an=i;
6384  if (set[i].FDeg < p->FDeg)
6385  en=i;
6386  if (set[i].FDeg == p->FDeg)
6387  {
6388  number lcset,lcp;
6389  lcset = pGetCoeff(set[i].p);
6390  lcp = pGetCoeff(p->p);
6391  if(!nGreaterZero(lcset))
6392  {
6393  set[i].p=p_Neg(set[i].p,currRing);
6394  if (set[i].t_p!=NULL)
6395  pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6396  lcset=pGetCoeff(set[i].p);
6397  }
6398  if(!nGreaterZero(lcp))
6399  {
6400  p->p=p_Neg(p->p,currRing);
6401  if (p->t_p!=NULL)
6402  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6403  lcp=pGetCoeff(p->p);
6404  }
6405  if(nGreater(lcset, lcp))
6406  {
6407  an = i;
6408  }
6409  else
6410  {
6411  en = i;
6412  }
6413  }
6414  }
6415 }
6416 #endif
6417 
6418 /*2 Position for rings L: Here I am
6419 * looks up the position of polynomial p in set
6420 * e is the ecart of p
6421 * set[length] is the smallest element in set with respect
6422 * to the ordering-procedure totaldegree,pComp
6423 */
6424 inline int getIndexRng(long coeff)
6425 {
6426  if (coeff == 0) return -1;
6427  long tmp = coeff;
6428  int ind = 0;
6429  while (tmp % 2 == 0)
6430  {
6431  tmp = tmp / 2;
6432  ind++;
6433  }
6434  return ind;
6435 }
6437 int posInLrg0 (const LSet set, const int length,
6438  LObject* p,const kStrategy)
6439 /* if (nGreater(pGetCoeff(p), pGetCoeff(set[an]))) return en;
6440  if (pLmCmp(set[i],p) == cmp_int) en = i;
6441  else if (pLmCmp(set[i],p) == -cmp_int) an = i;
6442  else
6443  {
6444  if (nGreater(pGetCoeff(p), pGetCoeff(set[i]))) an = i;
6445  else en = i;
6446  }*/
6447 {
6448  if (length < 0) return 0;
6449 
6450  int o = p->GetpFDeg();
6451  int op = set[length].GetpFDeg();
6452 
6453  if ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6454  return length + 1;
6455  int i;
6456  int an = 0;
6457  int en = length;
6458  loop
6459  {
6460  if (an >= en - 1)
6461  {
6462  op = set[an].GetpFDeg();
6463  if ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6464  return en;
6465  return an;
6466  }
6467  i = (an+en) / 2;
6468  op = set[i].GetpFDeg();
6469  if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6470  an = i;
6471  else
6472  en = i;
6473  }
6474 }
6475 
6476 /*{
6477  if (length < 0) return 0;
6478 
6479  int o = p->GetpFDeg();
6480  int op = set[length].GetpFDeg();
6481 
6482  int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6483  int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6484  int inda;
6485  int indi;
6486 
6487  if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6488  return length + 1;
6489  int i;
6490  int an = 0;
6491  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6492  int en = length;
6493  loop
6494  {
6495  if (an >= en-1)
6496  {
6497  op = set[an].GetpFDeg();
6498  if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6499  return en;
6500  return an;
6501  }
6502  i = (an + en) / 2;
6503  indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6504  op = set[i].GetpFDeg();
6505  if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6506  // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6507  {
6508  an = i;
6509  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6510  }
6511  else
6512  en = i;
6513  }
6514 } */
6515 
6516 /*2
6517 * looks up the position of polynomial p in set
6518 * set[length] is the smallest element in set with respect
6519 * to the ordering-procedure totaldegree,pLength0
6520 */
6521 int posInL110 (const LSet set, const int length,
6522  LObject* p,const kStrategy)
6523 {
6524  if (length<0) return 0;
6525 
6526  int o = p->GetpFDeg();
6527  int op = set[length].GetpFDeg();
6528 
6529  if ((op > o)
6530  || ((op == o) && (set[length].length >p->length))
6531  || ((op == o) && (set[length].length <= p->length)
6532  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6533  return length+1;
6534  int i;
6535  int an = 0;
6536  int en= length;
6537  loop
6538  {
6539  if (an >= en-1)
6540  {
6541  op = set[an].GetpFDeg();
6542  if ((op > o)
6543  || ((op == o) && (set[an].length >p->length))
6544  || ((op == o) && (set[an].length <=p->length)
6545  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6546  return en;
6547  return an;
6548  }
6549  i=(an+en) / 2;
6550  op = set[i].GetpFDeg();
6551  if ((op > o)
6552  || ((op == o) && (set[i].length > p->length))
6553  || ((op == o) && (set[i].length <= p->length)
6554  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6555  an=i;
6556  else
6557  en=i;
6558  }
6559 }
6560 
6561 #ifdef HAVE_RINGS
6562 int posInL110Ring (const LSet set, const int length,
6563  LObject* p,const kStrategy)
6564 {
6565  if (length<0) return 0;
6566 
6567  int o = p->GetpFDeg();
6568  int op = set[length].GetpFDeg();
6569 
6570  if ((op > o)
6571  || ((op == o) && (set[length].length >p->length))
6572  || ((op == o) && (set[length].length <= p->length)
6573  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6574  return length+1;
6575  int i;
6576  int an = 0;
6577  int en= length;
6578  loop
6579  {
6580  if (an >= en-1)
6581  {
6582  op = set[an].GetpFDeg();
6583  if ((op > o)
6584  || ((op == o) && (set[an].length >p->length))
6585  || ((op == o) && (set[an].length <=p->length)
6586  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6587  return en;
6588  return an;
6589  }
6590  i=(an+en) / 2;
6591  op = set[i].GetpFDeg();
6592  if ((op > o)
6593  || ((op == o) && (set[i].length > p->length))
6594  || ((op == o) && (set[i].length <= p->length)
6595  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6596  an=i;
6597  else
6598  en=i;
6599  }
6600 }
6601 #endif
6602 
6603 /*2
6604 * looks up the position of polynomial p in set
6605 * e is the ecart of p
6606 * set[length] is the smallest element in set with respect
6607 * to the ordering-procedure totaldegree
6608 */
6609 int posInL13 (const LSet set, const int length,
6610  LObject* p,const kStrategy)
6611 {
6612  if (length<0) return 0;
6613 
6614  int o = p->GetpFDeg();
6615 
6616  if (set[length].GetpFDeg() > o)
6617  return length+1;
6618 
6619  int i;
6620  int an = 0;
6621  int en= length;
6622  loop
6623  {
6624  if (an >= en-1)
6625  {
6626  if (set[an].GetpFDeg() >= o)
6627  return en;
6628  return an;
6629  }
6630  i=(an+en) / 2;
6631  if (set[i].GetpFDeg() >= o)
6632  an=i;
6633  else
6634  en=i;
6635  }
6636 }
6637 
6638 /*2
6639 * looks up the position of polynomial p in set
6640 * e is the ecart of p
6641 * set[length] is the smallest element in set with respect
6642 * to the ordering-procedure maximaldegree,pComp
6643 */
6644 int posInL15 (const LSet set, const int length,
6645  LObject* p,const kStrategy)
6646 {
6647  if (length<0) return 0;
6648 
6649  int o = p->GetpFDeg() + p->ecart;
6650  int op = set[length].GetpFDeg() + set[length].ecart;
6651 
6652  if ((op > o)
6653  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6654  return length+1;
6655  int i;
6656  int an = 0;
6657  int en= length;
6658  loop
6659  {
6660  if (an >= en-1)
6661  {
6662  op = set[an].GetpFDeg() + set[an].ecart;
6663  if ((op > o)
6664  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6665  return en;
6666  return an;
6667  }
6668  i=(an+en) / 2;
6669  op = set[i].GetpFDeg() + set[i].ecart;
6670  if ((op > o)
6671  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6672  an=i;
6673  else
6674  en=i;
6675  }
6676 }
6677 
6678 #ifdef HAVE_RINGS
6679 int posInL15Ring (const LSet set, const int length,
6680  LObject* p,const kStrategy)
6681 {
6682  if (length<0) return 0;
6683 
6684  int o = p->GetpFDeg() + p->ecart;
6685  int op = set[length].GetpFDeg() + set[length].ecart;
6686 
6687  if ((op > o)
6688  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6689  return length+1;
6690  int i;
6691  int an = 0;
6692  int en= length;
6693  loop
6694  {
6695  if (an >= en-1)
6696  {
6697  op = set[an].GetpFDeg() + set[an].ecart;
6698  if ((op > o)
6699  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6700  return en;
6701  return an;
6702  }
6703  i=(an+en) / 2;
6704  op = set[i].GetpFDeg() + set[i].ecart;
6705  if ((op > o)
6706  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6707  an=i;
6708  else
6709  en=i;
6710  }
6711 }
6712 #endif
6713 
6714 /*2
6715 * looks up the position of polynomial p in set
6716 * e is the ecart of p
6717 * set[length] is the smallest element in set with respect
6718 * to the ordering-procedure totaldegree
6719 */
6720 int posInL17 (const LSet set, const int length,
6721  LObject* p,const kStrategy)
6722 {
6723  if (length<0) return 0;
6724 
6725  int o = p->GetpFDeg() + p->ecart;
6726 
6727  if ((set[length].GetpFDeg() + set[length].ecart > o)
6728  || ((set[length].GetpFDeg() + set[length].ecart == o)
6729  && (set[length].ecart > p->ecart))
6730  || ((set[length].GetpFDeg() + set[length].ecart == o)
6731  && (set[length].ecart == p->ecart)
6732  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6733  return length+1;
6734  int i;
6735  int an = 0;
6736  int en= length;
6737  loop
6738  {
6739  if (an >= en-1)
6740  {
6741  if ((set[an].GetpFDeg() + set[an].ecart > o)
6742  || ((set[an].GetpFDeg() + set[an].ecart == o)
6743  && (set[an].ecart > p->ecart))
6744  || ((set[an].GetpFDeg() + set[an].ecart == o)
6745  && (set[an].ecart == p->ecart)
6746  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6747  return en;
6748  return an;
6749  }
6750  i=(an+en) / 2;
6751  if ((set[i].GetpFDeg() + set[i].ecart > o)
6752  || ((set[i].GetpFDeg() + set[i].ecart == o)
6753  && (set[i].ecart > p->ecart))
6754  || ((set[i].GetpFDeg() +set[i].ecart == o)
6755  && (set[i].ecart == p->ecart)
6756  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6757  an=i;
6758  else
6759  en=i;
6760  }
6761 }
6762 
6763 #ifdef HAVE_RINGS
6764 int posInL17Ring (const LSet set, const int length,
6765  LObject* p,const kStrategy)
6766 {
6767  if (length<0) return 0;
6768 
6769  int o = p->GetpFDeg() + p->ecart;
6770 
6771  if ((set[length].GetpFDeg() + set[length].ecart > o)
6772  || ((set[length].GetpFDeg() + set[length].ecart == o)
6773  && (set[length].ecart > p->ecart))
6774  || ((set[length].GetpFDeg() + set[length].ecart == o)
6775  && (set[length].ecart == p->ecart)
6776  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6777  return length+1;
6778  int i;
6779  int an = 0;
6780  int en= length;
6781  loop
6782  {
6783  if (an >= en-1)
6784  {
6785  if ((set[an].GetpFDeg() + set[an].ecart > o)
6786  || ((set[an].GetpFDeg() + set[an].ecart == o)
6787  && (set[an].ecart > p->ecart))
6788  || ((set[an].GetpFDeg() + set[an].ecart == o)
6789  && (set[an].ecart == p->ecart)
6790  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6791  return en;
6792  return an;
6793  }
6794  i=(an+en) / 2;
6795  if ((set[i].GetpFDeg() + set[i].ecart > o)
6796  || ((set[i].GetpFDeg() + set[i].ecart == o)
6797  && (set[i].ecart > p->ecart))
6798  || ((set[i].GetpFDeg() +set[i].ecart == o)
6799  && (set[i].ecart == p->ecart)
6800  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6801  an=i;
6802  else
6803  en=i;
6804  }
6805 }
6806 #endif
6807 
6808 /*2
6809 * looks up the position of polynomial p in set
6810 * e is the ecart of p
6811 * set[length] is the smallest element in set with respect
6812 * to the ordering-procedure pComp
6813 */
6814 int posInL17_c (const LSet set, const int length,
6815  LObject* p,const kStrategy)
6816 {
6817  if (length<0) return 0;
6818 
6819  int cc = (-1+2*currRing->order[0]==ringorder_c);
6820  /* cc==1 for (c,..), cc==-1 for (C,..) */
6821  unsigned long c = pGetComp(p->p)*cc;
6822  int o = p->GetpFDeg() + p->ecart;
6823 
6824  if (pGetComp(set[length].p)*cc > c)
6825  return length+1;
6826  if (pGetComp(set[length].p)*cc == c)
6827  {
6828  if ((set[length].GetpFDeg() + set[length].ecart > o)
6829  || ((set[length].GetpFDeg() + set[length].ecart == o)
6830  && (set[length].ecart > p->ecart))
6831  || ((set[length].GetpFDeg() + set[length].ecart == o)
6832  && (set[length].ecart == p->ecart)
6833  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6834  return length+1;
6835  }
6836  int i;
6837  int an = 0;
6838  int en= length;
6839  loop
6840  {
6841  if (an >= en-1)
6842  {
6843  if (pGetComp(set[an].p)*cc > c)
6844  return en;
6845  if (pGetComp(set[an].p)*cc == c)
6846  {
6847  if ((set[an].GetpFDeg() + set[an].ecart > o)
6848  || ((set[an].GetpFDeg() + set[an].ecart == o)
6849  && (set[an].ecart > p->ecart))
6850  || ((set[an].GetpFDeg() + set[an].ecart == o)
6851  && (set[an].ecart == p->ecart)
6852  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6853  return en;
6854  }
6855  return an;
6856  }
6857  i=(an+en) / 2;
6858  if (pGetComp(set[i].p)*cc > c)
6859  an=i;
6860  else if (pGetComp(set[i].p)*cc == c)
6861  {
6862  if ((set[i].GetpFDeg() + set[i].ecart > o)
6863  || ((set[i].GetpFDeg() + set[i].ecart == o)
6864  && (set[i].ecart > p->ecart))
6865  || ((set[i].GetpFDeg() +set[i].ecart == o)
6866  && (set[i].ecart == p->ecart)
6867  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6868  an=i;
6869  else
6870  en=i;
6871  }
6872  else
6873  en=i;
6874  }
6875 }
6876 
6877 #ifdef HAVE_RINGS
6878 int posInL17_cRing (const LSet set, const int length,
6879  LObject* p,const kStrategy)
6880 {
6881  if (length<0) return 0;
6882 
6883  int cc = (-1+2*currRing->order[0]==ringorder_c);
6884  /* cc==1 for (c,..), cc==-1 for (C,..) */
6885  unsigned long c = pGetComp(p->p)*cc;
6886  int o = p->GetpFDeg() + p->ecart;
6887 
6888  if (pGetComp(set[length].p)*cc > c)
6889  return length+1;
6890  if (pGetComp(set[length].p)*cc == c)
6891  {
6892  if ((set[length].GetpFDeg() + set[length].ecart > o)
6893  || ((set[length].GetpFDeg() + set[length].ecart == o)
6894  && (set[length].ecart > p->ecart))
6895  || ((set[length].GetpFDeg() + set[length].ecart == o)
6896  && (set[length].ecart == p->ecart)
6897  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6898  return length+1;
6899  }
6900  int i;
6901  int an = 0;
6902  int en= length;
6903  loop
6904  {
6905  if (an >= en-1)
6906  {
6907  if (pGetComp(set[an].p)*cc > c)
6908  return en;
6909  if (pGetComp(set[an].p)*cc == c)
6910  {
6911  if ((set[an].GetpFDeg() + set[an].ecart > o)
6912  || ((set[an].GetpFDeg() + set[an].ecart == o)
6913  && (set[an].ecart > p->ecart))
6914  || ((set[an].GetpFDeg() + set[an].ecart == o)
6915  && (set[an].ecart == p->ecart)
6916  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6917  return en;
6918  }
6919  return an;
6920  }
6921  i=(an+en) / 2;
6922  if (pGetComp(set[i].p)*cc > c)
6923  an=i;
6924  else if (pGetComp(set[i].p)*cc == c)
6925  {
6926  if ((set[i].GetpFDeg() + set[i].ecart > o)
6927  || ((set[i].GetpFDeg() + set[i].ecart == o)
6928  && (set[i].ecart > p->ecart))
6929  || ((set[i].GetpFDeg() +set[i].ecart == o)
6930  && (set[i].ecart == p->ecart)
6931  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6932  an=i;
6933  else
6934  en=i;
6935  }
6936  else
6937  en=i;
6938  }
6939 }
6940 #endif
6941 
6942 /*
6943  * SYZYGY CRITERION for signature-based standard basis algorithms
6944  */
6945 BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6946 {
6947 //#if 1
6948 #ifdef DEBUGF5
6949  PrintS("syzygy criterion checks: ");
6950  pWrite(sig);
6951 #endif
6952  for (int k=0; k<strat->syzl; k++)
6953  {
6954  //printf("-%d",k);
6955 //#if 1
6956 #ifdef DEBUGF5
6957  Print("checking with: %d / %d -- \n",k,strat->syzl);
6958  pWrite(pHead(strat->syz[k]));
6959 #endif
6960  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6961  && (!rField_is_Ring(currRing) ||
6962  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6963  {
6964 //#if 1
6965 #ifdef DEBUGF5
6966  PrintS("DELETE!\n");
6967 #endif
6968  strat->nrsyzcrit++;
6969  //printf("- T -\n\n");
6970  return TRUE;
6971  }
6972  }
6973  //printf("- F -\n\n");
6974  return FALSE;
6975 }
6976 
6977 /*
6978  * SYZYGY CRITERION for signature-based standard basis algorithms
6979  */
6980 BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6981 {
6982 //#if 1
6983  if(sig == NULL)
6984  return FALSE;
6985 #ifdef DEBUGF5
6986  PrintS("--- syzygy criterion checks: ");
6987  pWrite(sig);
6988 #endif
6989  int comp = __p_GetComp(sig, currRing);
6990  int min, max;
6991  if (comp<=1)
6992  return FALSE;
6993  else
6994  {
6995  min = strat->syzIdx[comp-2];
6996  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
6997  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
6998  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
6999  if (comp == strat->currIdx)
7000  {
7001  max = strat->syzl;
7002  }
7003  else
7004  {
7005  max = strat->syzIdx[comp-1];
7006  }
7007  for (int k=min; k<max; k++)
7008  {
7009 #ifdef F5DEBUG
7010  Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
7011  Print("checking with: %d -- ",k);
7012  pWrite(pHead(strat->syz[k]));
7013 #endif
7014  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7015  && (!rField_is_Ring(currRing) ||
7016  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7017  {
7018  strat->nrsyzcrit++;
7019  return TRUE;
7020  }
7021  }
7022  return FALSE;
7023  }
7024 }
7025 
7026 /*
7027  * REWRITTEN CRITERION for signature-based standard basis algorithms
7028  */
7029 BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
7030 {
7031  //printf("Faugere Rewritten Criterion\n");
7033  return FALSE;
7034 //#if 1
7035 #ifdef DEBUGF5
7036  PrintS("rewritten criterion checks: ");
7037  pWrite(sig);
7038 #endif
7039  for(int k = strat->sl; k>=start; k--)
7040  {
7041 //#if 1
7042 #ifdef DEBUGF5
7043  PrintS("checking with: ");
7044  pWrite(strat->sig[k]);
7045  pWrite(pHead(strat->S[k]));
7046 #endif
7047  if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
7048  {
7049 //#if 1
7050 #ifdef DEBUGF5
7051  PrintS("DELETE!\n");
7052 #endif
7053  strat->nrrewcrit++;
7054  return TRUE;
7055  }
7056  //k--;
7057  }
7058 #ifdef DEBUGF5
7059  PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
7060  for(int kk = 0; kk<strat->sl+1; kk++)
7061  {
7062  pWrite(pHead(strat->S[kk]));
7063  }
7064  PrintS("------------------------------\n");
7065 #endif
7066  return FALSE;
7067 }
7068 
7069 /*
7070  * REWRITTEN CRITERION for signature-based standard basis algorithms
7071  ***************************************************************************
7072  * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
7073  ***************************************************************************
7074  */
7075 
7076 // real implementation of arri's rewritten criterion, only called once in
7077 // kstd2.cc, right before starting reduction
7078 // IDEA: Arri says that it is enough to consider 1 polynomial for each unique
7079 // signature appearing during the computations. Thus we first of all go
7080 // through strat->L and delete all other pairs of the same signature,
7081 // keeping only the one with least possible leading monomial. After this
7082 // we check if we really need to compute this critical pair at all: There
7083 // can be elements already in strat->S whose signatures divide the
7084 // signature of the critical pair in question and whose multiplied
7085 // leading monomials are smaller than the leading monomial of the
7086 // critical pair. In this situation we can discard the critical pair
7087 // completely.
7088 BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
7089 {
7091  return FALSE;
7092  poly p1 = pOne();
7093  poly p2 = pOne();
7094  for (int ii=strat->sl; ii>start; ii--)
7095  {
7096  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
7097  {
7098  p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
7099  p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
7100  if (!(pLmCmp(p1,p2) == 1))
7101  {
7102  pDelete(&p1);
7103  pDelete(&p2);
7104  return TRUE;
7105  }
7106  }
7107  }
7108  pDelete(&p1);
7109  pDelete(&p2);
7110  return FALSE;
7111 }
7113 BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
7114 {
7115  //Over Rings, there are still some changes to do: considering coeffs
7117  return FALSE;
7118  int found = -1;
7119  for (int i=strat->Bl; i>-1; i--) {
7120  if (pLmEqual(strat->B[i].sig,sig))
7121  {
7122  found = i;
7123  break;
7124  }
7125  }
7126  if (found != -1)
7127  {
7128  if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
7129  {
7130  deleteInL(strat->B,&strat->Bl,found,strat);
7131  }
7132  else
7133  {
7134  return TRUE;
7135  }
7136  }
7137  poly p1 = pOne();
7138  poly p2 = pOne();
7139  for (int ii=strat->sl; ii>-1; ii--)
7140  {
7141  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
7142  {
7143  p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
7144  p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
7145  if (!(pLmCmp(p1,p2) == 1))
7146  {
7147  pDelete(&p1);
7148  pDelete(&p2);
7149  return TRUE;
7150  }
7151  }
7152  }
7153  pDelete(&p1);
7154  pDelete(&p2);
7155  return FALSE;
7156 }
7157 
7158 /***************************************************************
7159  *
7160  * Tail reductions
7161  *
7162  ***************************************************************/
7163 TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
7164 {
7165  int j = 0;
7166  const unsigned long not_sev = ~L->sev;
7167  const unsigned long* sev = strat->sevS;
7168  poly p;
7169  ring r;
7170  L->GetLm(p, r);
7171 
7172  assume(~not_sev == p_GetShortExpVector(p, r));
7173 
7174  if (r == currRing)
7175  {
7176  if(!rField_is_Ring(r))
7177  {
7178  loop
7179  {
7180  if (j > end_pos) return NULL;
7181  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7182  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7183  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7184  {
7185  break;
7186  }
7187  #else
7188  if (!(sev[j] & not_sev) &&
7189  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7190  p_LmDivisibleBy(strat->S[j], p, r))
7191  {
7192  break;
7193  }
7194  #endif
7195  j++;
7196  }
7197  }
7198  #ifdef HAVE_RINGS
7199  else
7200  {
7201  loop
7202  {
7203  if (j > end_pos) return NULL;
7204  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7205  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7206  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7207  {
7208  break;
7209  }
7210  #else
7211  if (!(sev[j] & not_sev) &&
7212  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7213  p_LmDivisibleBy(strat->S[j], p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7214  {
7215  break;
7216  }
7217  #endif
7218  j++;
7219  }
7220  }
7221  #endif
7222  // if called from NF, T objects do not exist:
7223  if (strat->tl < 0 || strat->S_2_R[j] == -1)
7224  {
7225  T->Set(strat->S[j], r, strat->tailRing);
7226  assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
7227  return T;
7228  }
7229  else
7230  {
7231 ///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
7232 ///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
7233 // assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
7234  return strat->S_2_T(j);
7235  }
7236  }
7237  else
7238  {
7239  TObject* t;
7240  if(!rField_is_Ring(r))
7241  {
7242  loop
7243  {
7244  if (j > end_pos) return NULL;
7245  assume(strat->S_2_R[j] != -1);
7246  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7247  t = strat->S_2_T(j);
7248  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7249  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7250  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7251  {
7252  t->pLength=pLength(t->t_p);
7253  return t;
7254  }
7255  #else
7256  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7257  {
7258  t = strat->S_2_T(j);
7259  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7260  if (p_LmDivisibleBy(t->t_p, p, r))
7261  {
7262  t->pLength=pLength(t->t_p);
7263  return t;
7264  }
7265  }
7266  #endif
7267  j++;
7268  }
7269  }
7270  #ifdef HAVE_RINGS
7271  else
7272  {
7273  loop
7274  {
7275  if (j > end_pos) return NULL;
7276  assume(strat->S_2_R[j] != -1);
7277  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7278  t = strat->S_2_T(j);
7279  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7280  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7281  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7282  {
7283  t->pLength=pLength(t->t_p);
7284  return t;
7285  }
7286  #else
7287  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7288  {
7289  t = strat->S_2_T(j);
7290  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7291  if (p_LmDivisibleBy(t->t_p, p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7292  {
7293  t->pLength=pLength(t->t_p);
7294  return t;
7295  }
7296  }
7297  #endif
7298  j++;
7299  }
7300  }
7301  #endif
7302  }
7304 
7305 poly redtail (LObject* L, int end_pos, kStrategy strat)
7306 {
7307  poly h, hn;
7308  strat->redTailChange=FALSE;
7309 
7310  L->GetP();
7311  poly p = L->p;
7312  if (strat->noTailReduction || pNext(p) == NULL)
7313  return p;
7314 
7315  LObject Ln(strat->tailRing);
7316  TObject* With;
7317  // placeholder in case strat->tl < 0
7318  TObject With_s(strat->tailRing);
7319  h = p;
7320  hn = pNext(h);
7321  long op = strat->tailRing->pFDeg(hn, strat->tailRing);
7322  long e;
7323  int l;
7324  BOOLEAN save_HE=strat->kHEdgeFound;
7325  strat->kHEdgeFound |=
7326  ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
7327 
7328  while(hn != NULL)
7329  {
7330  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7331  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7332  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7333  loop
7334  {
7335  Ln.Set(hn, strat->tailRing);
7336  Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
7337  if (strat->kHEdgeFound)
7338  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7339  else
7340  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
7341  if (With == NULL) break;
7342  With->length=0;
7343  With->pLength=0;
7344  strat->redTailChange=TRUE;
7345  if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
7346  {
7347  // reducing the tail would violate the exp bound
7348  if (kStratChangeTailRing(strat, L))
7349  {
7350  strat->kHEdgeFound = save_HE;
7351  return redtail(L, end_pos, strat);
7352  }
7353  else
7354  return NULL;
7355  }
7356  hn = pNext(h);
7357  if (hn == NULL) goto all_done;
7358  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7359  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7360  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7361  }
7362  h = hn;
7363  hn = pNext(h);
7364  }
7365 
7366  all_done:
7367  if (strat->redTailChange)
7368  {
7369  L->pLength = 0;
7370  }
7371  strat->kHEdgeFound = save_HE;
7372  return p;
7374 
7375 poly redtail (poly p, int end_pos, kStrategy strat)
7376 {
7377  LObject L(p, currRing);
7378  return redtail(&L, end_pos, strat);
7380 
7381 poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
7382 {
7383 #define REDTAIL_CANONICALIZE 100
7384  strat->redTailChange=FALSE;
7385  if (strat->noTailReduction) return L->GetLmCurrRing();
7386  poly h, p;
7387  p = h = L->GetLmTailRing();
7388  if ((h==NULL) || (pNext(h)==NULL))
7389  return L->GetLmCurrRing();
7390 
7391  TObject* With;
7392  // placeholder in case strat->tl < 0
7393  TObject With_s(strat->tailRing);
7394 
7395  LObject Ln(pNext(h), strat->tailRing);
7396  Ln.GetpLength();
7397 
7398  pNext(h) = NULL;
7399  if (L->p != NULL)
7400  {
7401  pNext(L->p) = NULL;
7402  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7403  }
7404  L->pLength = 1;
7405 
7406  Ln.PrepareRed(strat->use_buckets);
7407 
7408  int cnt=REDTAIL_CANONICALIZE;
7409  while(!Ln.IsNull())
7410  {
7411  loop
7412  {
7413  if (TEST_OPT_IDLIFT)
7414  {
7415  if (Ln.p!=NULL)
7416  {
7417  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7418  }
7419  else
7420  {
7421  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7422  }
7423  }
7424  Ln.SetShortExpVector();
7425  if (withT)
7426  {
7427  int j;
7428  j = kFindDivisibleByInT(strat, &Ln);
7429  if (j < 0) break;
7430  With = &(strat->T[j]);
7431  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7432  }
7433  else
7434  {
7435  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7436  if (With == NULL) break;
7437  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7438  }
7439  cnt--;
7440  if (cnt==0)
7441  {
7443  /*poly tmp=*/Ln.CanonicalizeP();
7444  if (normalize)
7445  {
7446  Ln.Normalize();
7447  //pNormalize(tmp);
7448  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7449  }
7450  }
7451  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7452  {
7453  With->pNorm();
7454  }
7455  strat->redTailChange=TRUE;
7456  if (ksReducePolyTail(L, With, &Ln))
7457  {
7458  // reducing the tail would violate the exp bound
7459  // set a flag and hope for a retry (in bba)
7460  strat->completeReduce_retry=TRUE;
7461  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7462  do
7463  {
7464  pNext(h) = Ln.LmExtractAndIter();
7465  pIter(h);
7466  L->pLength++;
7467  } while (!Ln.IsNull());
7468  goto all_done;
7469  }
7470  if (Ln.IsNull()) goto all_done;
7471  if (! withT) With_s.Init(currRing);
7472  }
7473  pNext(h) = Ln.LmExtractAndIter();
7474  pIter(h);
7475  pNormalize(h);
7476  L->pLength++;
7477  }
7478 
7479  all_done:
7480  Ln.Delete();
7481  if (L->p != NULL) pNext(L->p) = pNext(p);
7482 
7483  if (strat->redTailChange)
7484  {
7485  L->length = 0;
7486  L->pLength = 0;
7487  }
7488 
7489  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7490  //L->Normalize(); // HANNES: should have a test
7491  kTest_L(L);
7492  return L->GetLmCurrRing();
7494 
7495 poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7496 {
7497  strat->redTailChange=FALSE;
7498  if (strat->noTailReduction) return L->GetLmCurrRing();
7499  poly h, p;
7500  p = h = L->GetLmTailRing();
7501  if ((h==NULL) || (pNext(h)==NULL))
7502  return L->GetLmCurrRing();
7503 
7504  TObject* With;
7505  // placeholder in case strat->tl < 0
7506  TObject With_s(strat->tailRing);
7507 
7508  LObject Ln(pNext(h), strat->tailRing);
7509  Ln.pLength = L->GetpLength() - 1;
7510 
7511  pNext(h) = NULL;
7512  if (L->p != NULL) pNext(L->p) = NULL;
7513  L->pLength = 1;
7514 
7515  Ln.PrepareRed(strat->use_buckets);
7516 
7517  int cnt=REDTAIL_CANONICALIZE;
7518  while(!Ln.IsNull())
7519  {
7520  loop
7521  {
7522  if (TEST_OPT_IDLIFT)
7523  {
7524  if (Ln.p!=NULL)
7525  {
7526  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7527  }
7528  else
7529  {
7530  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7531  }
7532  }
7533  Ln.SetShortExpVector();
7534  if (withT)
7535  {
7536  int j;
7537  j = kFindDivisibleByInT(strat, &Ln);
7538  if (j < 0) break;
7539  With = &(strat->T[j]);
7540  }
7541  else
7542  {
7543  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7544  if (With == NULL) break;
7545  }
7546  cnt--;
7547  if (cnt==0)
7548  {
7550  /*poly tmp=*/Ln.CanonicalizeP();
7551  if (normalize)
7552  {
7553  Ln.Normalize();
7554  //pNormalize(tmp);
7555  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7556  }
7557  }
7558  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7559  {
7560  With->pNorm();
7561  }
7562  strat->redTailChange=TRUE;
7563  if (ksReducePolyTail(L, With, &Ln))
7564  {
7565  // reducing the tail would violate the exp bound
7566  // set a flag and hope for a retry (in bba)
7567  strat->completeReduce_retry=TRUE;
7568  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7569  do
7570  {
7571  pNext(h) = Ln.LmExtractAndIter();
7572  pIter(h);
7573  L->pLength++;
7574  } while (!Ln.IsNull());
7575  goto all_done;
7576  }
7577  if(!Ln.IsNull())
7578  {
7579  Ln.GetP();
7580  Ln.p = pJet(Ln.p,bound);
7581  }
7582  if (Ln.IsNull())
7583  {
7584  goto all_done;
7585  }
7586  if (! withT) With_s.Init(currRing);
7587  }
7588  pNext(h) = Ln.LmExtractAndIter();
7589  pIter(h);
7590  pNormalize(h);
7591  L->pLength++;
7592  }
7593 
7594  all_done:
7595  Ln.Delete();
7596  if (L->p != NULL) pNext(L->p) = pNext(p);
7597 
7598  if (strat->redTailChange)
7599  {
7600  L->length = 0;
7601  L->pLength = 0;
7602  }
7603 
7604  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7605  //L->Normalize(); // HANNES: should have a test
7606  kTest_L(L);
7607  return L->GetLmCurrRing();
7608 }
7610 #ifdef HAVE_RINGS
7611 poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7612 // normalize=FALSE, withT=FALSE, coeff=Z
7613 {
7614  strat->redTailChange=FALSE;
7615  if (strat->noTailReduction) return L->GetLmCurrRing();
7616  poly h, p;
7617  p = h = L->GetLmTailRing();
7618  if ((h==NULL) || (pNext(h)==NULL))
7619  return L->GetLmCurrRing();
7620 
7621  TObject* With;
7622  // placeholder in case strat->tl < 0
7623  TObject With_s(strat->tailRing);
7624 
7625  LObject Ln(pNext(h), strat->tailRing);
7626  Ln.pLength = L->GetpLength() - 1;
7627 
7628  pNext(h) = NULL;
7629  if (L->p != NULL) pNext(L->p) = NULL;
7630  L->pLength = 1;
7631 
7632  Ln.PrepareRed(strat->use_buckets);
7633 
7634  int cnt=REDTAIL_CANONICALIZE;
7635  while(!Ln.IsNull())
7636  {
7637  loop
7638  {
7639  Ln.SetShortExpVector();
7640  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7641  if (With == NULL) break;
7642  cnt--;
7643  if (cnt==0)
7644  {
7646  /*poly tmp=*/Ln.CanonicalizeP();
7647  }
7648  // we are in Z, do not call pNorm
7649  strat->redTailChange=TRUE;
7650  // test divisibility of coefs:
7651  poly p_Ln=Ln.GetLmCurrRing();
7652  poly p_With=With->GetLmCurrRing();
7653  number z=n_IntMod(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf);
7654  if (!nIsZero(z))
7655  {
7656  // subtract z*Ln, add z.Ln to L
7657  poly m=pHead(p_Ln);
7658  pSetCoeff(m,z);
7659  poly mm=pHead(m);
7660  pNext(h) = m;
7661  pIter(h);
7662  L->pLength++;
7663  mm=pNeg(mm);
7664  if (Ln.bucket!=NULL)
7665  {
7666  int dummy=1;
7667  kBucket_Add_q(Ln.bucket,mm,&dummy);
7668  }
7669  else
7670  {
7671  if ((Ln.t_p!=NULL)&&(Ln.p==NULL))
7672  Ln.GetP();
7673  if (Ln.p!=NULL)
7674  {
7675  Ln.p=pAdd(Ln.p,mm);
7676  if (Ln.t_p!=NULL)
7677  {
7678  pNext(Ln.t_p)=NULL;
7679  p_LmDelete(Ln.t_p,strat->tailRing);
7680  }
7681  }
7682  }
7683  }
7684  else
7685  nDelete(&z);
7686 
7687  if (ksReducePolyTail(L, With, &Ln))
7688  {
7689  // reducing the tail would violate the exp bound
7690  // set a flag and hope for a retry (in bba)
7691  strat->completeReduce_retry=TRUE;
7692  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7693  do
7694  {
7695  pNext(h) = Ln.LmExtractAndIter();
7696  pIter(h);
7697  L->pLength++;
7698  } while (!Ln.IsNull());
7699  goto all_done;
7700  }
7701  if (Ln.IsNull()) goto all_done;
7702  With_s.Init(currRing);
7703  }
7704  pNext(h) = Ln.LmExtractAndIter();
7705  pIter(h);
7706  pNormalize(h);
7707  L->pLength++;
7708  }
7709 
7710  all_done:
7711  Ln.Delete();
7712  if (L->p != NULL) pNext(L->p) = pNext(p);
7713 
7714  if (strat->redTailChange)
7715  {
7716  L->length = 0;
7717  }
7718 
7719  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7720  //L->Normalize(); // HANNES: should have a test
7721  kTest_L(L);
7722  return L->GetLmCurrRing();
7723 }
7724 #endif
7725 
7726 /*2
7727 *checks the change degree and write progress report
7728 */
7729 void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7730 {
7731  if (i != *olddeg)
7732  {
7733  Print("%d",i);
7734  *olddeg = i;
7735  }
7736  if (TEST_OPT_OLDSTD)
7737  {
7738  if (strat->Ll != *reduc)
7739  {
7740  if (strat->Ll != *reduc-1)
7741  Print("(%d)",strat->Ll+1);
7742  else
7743  PrintS("-");
7744  *reduc = strat->Ll;
7745  }
7746  else
7747  PrintS(".");
7748  mflush();
7749  }
7750  else
7751  {
7752  if (red_result == 0)
7753  PrintS("-");
7754  else if (red_result < 0)
7755  PrintS(".");
7756  if ((red_result > 0) || ((strat->Ll % 100)==99))
7757  {
7758  if (strat->Ll != *reduc && strat->Ll > 0)
7759  {
7760  Print("(%d)",strat->Ll+1);
7761  *reduc = strat->Ll;
7762  }
7763  }
7764  }
7765 }
7766 
7767 /*2
7768 *statistics
7769 */
7770 void messageStat (int hilbcount,kStrategy strat)
7771 {
7772  //PrintS("\nUsage/Allocation of temporary storage:\n");
7773  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7774  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7775  Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7776  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7777  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7778  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7779  /*mflush();*/
7781 
7782 void messageStatSBA (int hilbcount,kStrategy strat)
7783 {
7784  //PrintS("\nUsage/Allocation of temporary storage:\n");
7785  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7786  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7787  Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7788  //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7789  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7790  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7791  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7792  /*mflush();*/
7793 }
7794 
7795 #ifdef KDEBUG
7796 /*2
7797 *debugging output: all internal sets, if changed
7798 *for testing purpuse only/has to be changed for later use
7799 */
7800 void messageSets (kStrategy strat)
7801 {
7802  int i;
7803  if (strat->news)
7804  {
7805  PrintS("set S");
7806  for (i=0; i<=strat->sl; i++)
7807  {
7808  Print("\n %d:",i);
7809  p_wrp(strat->S[i], currRing, strat->tailRing);
7810  }
7811  strat->news = FALSE;
7812  }
7813  if (strat->newt)
7814  {
7815  PrintS("\nset T");
7816  for (i=0; i<=strat->tl; i++)
7817  {
7818  Print("\n %d:",i);
7819  strat->T[i].wrp();
7820  if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7821  Print(" o:%ld e:%d l:%d",
7822  strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7823  }
7824  strat->newt = FALSE;
7825  }
7826  PrintS("\nset L");
7827  for (i=strat->Ll; i>=0; i--)
7828  {
7829  Print("\n%d:",i);
7830  p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7831  PrintS(" ");
7832  p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7833  PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7834  PrintS("\n p : ");
7835  strat->L[i].wrp();
7836  Print(" o:%ld e:%d l:%d",
7837  strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7838  }
7839  PrintLn();
7840 }
7841 
7842 #endif
7843 
7844 
7845 /*2
7846 *construct the set s from F
7847 */
7848 void initS (ideal F, ideal Q, kStrategy strat)
7849 {
7850  int i,pos;
7851 
7852  if (Q!=NULL) i=((IDELEMS(F)+IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7853  else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7854  strat->ecartS=initec(i);
7855  strat->sevS=initsevS(i);
7856  strat->S_2_R=initS_2_R(i);
7857  strat->fromQ=NULL;
7858  strat->Shdl=idInit(i,F->rank);
7859  strat->S=strat->Shdl->m;
7860  /*- put polys into S -*/
7861  if (Q!=NULL)
7862  {
7863  strat->fromQ=initec(i);
7864  memset(strat->fromQ,0,i*sizeof(int));
7865  for (i=0; i<IDELEMS(Q); i++)
7866  {
7867  if (Q->m[i]!=NULL)
7868  {
7869  LObject h;
7870  h.p = pCopy(Q->m[i]);
7872  {
7873  h.pCleardenom(); // also does remove Content
7874  }
7875  else
7876  {
7877  h.pNorm();
7878  }
7880  {
7881  deleteHC(&h, strat);
7882  }
7883  if (h.p!=NULL)
7884  {
7885  strat->initEcart(&h);
7886  if (strat->sl==-1)
7887  pos =0;
7888  else
7889  {
7890  pos = posInS(strat,strat->sl,h.p,h.ecart);
7891  }
7892  h.sev = pGetShortExpVector(h.p);
7893  strat->enterS(h,pos,strat,-1);
7894  strat->fromQ[pos]=1;
7895  }
7896  }
7897  }
7898  }
7899  for (i=0; i<IDELEMS(F); i++)
7900  {
7901  if (F->m[i]!=NULL)
7902  {
7903  LObject h;
7904  h.p = pCopy(F->m[i]);
7906  {
7907  cancelunit(&h); /*- tries to cancel a unit -*/
7908  deleteHC(&h, strat);
7909  }
7910  if (h.p!=NULL)
7911  // do not rely on the input being a SB!
7912  {
7914  {
7915  h.pCleardenom(); // also does remove Content
7916  }
7917  else
7918  {
7919  h.pNorm();
7920  }
7921  strat->initEcart(&h);
7922  if (strat->sl==-1)
7923  pos =0;
7924  else
7925  pos = posInS(strat,strat->sl,h.p,h.ecart);
7926  h.sev = pGetShortExpVector(h.p);
7927  strat->enterS(h,pos,strat,-1);
7928  }
7929  }
7930  }
7931  /*- test, if a unit is in F -*/
7932  if ((strat->sl>=0)
7933 #ifdef HAVE_RINGS
7934  && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7935 #endif
7936  && pIsConstant(strat->S[0]))
7937  {
7938  while (strat->sl>0) deleteInS(strat->sl,strat);
7939  }
7941 
7942 void initSL (ideal F, ideal Q,kStrategy strat)
7943 {
7944  int i,pos;
7945 
7946  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7947  else i=setmaxT;
7948  strat->ecartS=initec(i);
7949  strat->sevS=initsevS(i);
7950  strat->S_2_R=initS_2_R(i);
7951  strat->fromQ=NULL;
7952  strat->Shdl=idInit(i,F->rank);
7953  strat->S=strat->Shdl->m;
7954  /*- put polys into S -*/
7955  if (Q!=NULL)
7956  {
7957  strat->fromQ=initec(i);
7958  memset(strat->fromQ,0,i*sizeof(int));
7959  for (i=0; i<IDELEMS(Q); i++)
7960  {
7961  if (Q->m[i]!=NULL)
7962  {
7963  LObject h;
7964  h.p = pCopy(Q->m[i]);
7966  {
7967  deleteHC(&h,strat);
7968  }
7970  {
7971  h.pCleardenom(); // also does remove Content
7972  }
7973  else
7974  {
7975  h.pNorm();
7976  }
7977  if (h.p!=NULL)
7978  {
7979  strat->initEcart(&h);
7980  if (strat->sl==-1)
7981  pos =0;
7982  else
7983  {
7984  pos = posInS(strat,strat->sl,h.p,h.ecart);
7985  }
7986  h.sev = pGetShortExpVector(h.p);
7987  strat->enterS(h,pos,strat,-1);
7988  strat->fromQ[pos]=1;
7989  }
7990  }
7991  }
7992  }
7993  for (i=0; i<IDELEMS(F); i++)
7994  {
7995  if (F->m[i]!=NULL)
7996  {
7997  LObject h;
7998  h.p = pCopy(F->m[i]);
7999  if (h.p!=NULL)
8000  {
8002  {
8003  cancelunit(&h); /*- tries to cancel a unit -*/
8004  deleteHC(&h, strat);
8005  }
8006  if (h.p!=NULL)
8007  {
8009  {
8010  h.pCleardenom(); // also does remove Content
8011  }
8012  else
8013  {
8014  h.pNorm();
8015  }
8016  strat->initEcart(&h);
8017  if (strat->Ll==-1)
8018  pos =0;
8019  else
8020  pos = strat->posInL(strat->L,strat->Ll,&h,strat);
8021  h.sev = pGetShortExpVector(h.p);
8022  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8023  }
8024  }
8025  }
8026  }
8027  /*- test, if a unit is in F -*/
8028 
8029  if ((strat->Ll>=0)
8030 #ifdef HAVE_RINGS
8031  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8032 #endif
8033  && pIsConstant(strat->L[strat->Ll].p))
8034  {
8035  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8036  }
8038 
8039 void initSLSba (ideal F, ideal Q,kStrategy strat)
8040 {
8041  int i,pos;
8042  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8043  else i=setmaxT;
8044  strat->ecartS = initec(i);
8045  strat->sevS = initsevS(i);
8046  strat->sevSig = initsevS(i);
8047  strat->S_2_R = initS_2_R(i);
8048  strat->fromQ = NULL;
8049  strat->Shdl = idInit(i,F->rank);
8050  strat->S = strat->Shdl->m;
8051  strat->sig = (poly *)omAlloc0(i*sizeof(poly));
8052  if (strat->sbaOrder != 1)
8053  {
8054  strat->syz = (poly *)omAlloc0(i*sizeof(poly));
8055  strat->sevSyz = initsevS(i);
8056  strat->syzmax = i;
8057  strat->syzl = 0;
8058  }
8059  /*- put polys into S -*/
8060  if (Q!=NULL)
8061  {
8062  strat->fromQ=initec(i);
8063  memset(strat->fromQ,0,i*sizeof(int));
8064  for (i=0; i<IDELEMS(Q); i++)
8065  {
8066  if (Q->m[i]!=NULL)
8067  {
8068  LObject h;
8069  h.p = pCopy(Q->m[i]);
8071  {
8072  deleteHC(&h,strat);
8073  }
8075  {
8076  h.pCleardenom(); // also does remove Content
8077  }
8078  else
8079  {
8080  h.pNorm();
8081  }
8082  if (h.p!=NULL)
8083  {
8084  strat->initEcart(&h);
8085  if (strat->sl==-1)
8086  pos =0;
8087  else
8088  {
8089  pos = posInS(strat,strat->sl,h.p,h.ecart);
8090  }
8091  h.sev = pGetShortExpVector(h.p);
8092  strat->enterS(h,pos,strat,-1);
8093  strat->fromQ[pos]=1;
8094  }
8095  }
8096  }
8097  }
8098  for (i=0; i<IDELEMS(F); i++)
8099  {
8100  if (F->m[i]!=NULL)
8101  {
8102  LObject h;
8103  h.p = pCopy(F->m[i]);
8104  h.sig = pOne();
8105  //h.sig = pInit();
8106  //p_SetCoeff(h.sig,nInit(1),currRing);
8107  p_SetComp(h.sig,i+1,currRing);
8108  // if we are working with the Schreyer order we generate it
8109  // by multiplying the initial signatures with the leading monomial
8110  // of the corresponding initial polynomials generating the ideal
8111  // => we can keep the underlying monomial order and get a Schreyer
8112  // order without any bigger overhead
8113  if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
8114  {
8115  p_ExpVectorAdd (h.sig,F->m[i],currRing);
8116  }
8117  h.sevSig = pGetShortExpVector(h.sig);
8118 #ifdef DEBUGF5
8119  pWrite(h.p);
8120  pWrite(h.sig);
8121 #endif
8122  if (h.p!=NULL)
8123  {
8125  {
8126  cancelunit(&h); /*- tries to cancel a unit -*/
8127  deleteHC(&h, strat);
8128  }
8129  if (h.p!=NULL)
8130  {
8132  {
8133  h.pCleardenom(); // also does remove Content
8134  }
8135  else
8136  {
8137  h.pNorm();
8138  }
8139  strat->initEcart(&h);
8140  if (strat->Ll==-1)
8141  pos =0;
8142  else
8143  pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
8144  h.sev = pGetShortExpVector(h.p);
8145  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8146  }
8147  }
8148  /*
8149  if (strat->sbaOrder != 1)
8150  {
8151  for(j=0;j<i;j++)
8152  {
8153  strat->syz[ctr] = pCopy(F->m[j]);
8154  p_SetCompP(strat->syz[ctr],i+1,currRing);
8155  // add LM(F->m[i]) to the signature to get a Schreyer order
8156  // without changing the underlying polynomial ring at all
8157  p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
8158  // since p_Add_q() destroys all input
8159  // data we need to recreate help
8160  // each time
8161  poly help = pCopy(F->m[i]);
8162  p_SetCompP(help,j+1,currRing);
8163  pWrite(strat->syz[ctr]);
8164  pWrite(help);
8165  printf("%d\n",pLmCmp(strat->syz[ctr],help));
8166  strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
8167  printf("%d. SYZ ",ctr);
8168  pWrite(strat->syz[ctr]);
8169  strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
8170  ctr++;
8171  }
8172  strat->syzl = ps;
8173  }
8174  */
8175  }
8176  }
8177  /*- test, if a unit is in F -*/
8178 
8179  if ((strat->Ll>=0)
8180 #ifdef HAVE_RINGS
8181  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8182 #endif
8183  && pIsConstant(strat->L[strat->Ll].p))
8184  {
8185  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8186  }
8188 
8189 void initSyzRules (kStrategy strat)
8190 {
8191  if( strat->S[0] )
8192  {
8193  if( strat->S[1] && !rField_is_Ring(currRing))
8194  {
8195  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
8196  omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
8197  omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
8198  }
8199  int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
8200  /************************************************************
8201  * computing the length of the syzygy array needed
8202  ***********************************************************/
8203  for(i=1; i<=strat->sl; i++)
8204  {
8205  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8206  {
8207  ps += i;
8208  }
8209  }
8210  ps += strat->sl+1;
8211  //comp = pGetComp (strat->P.sig);
8212  comp = strat->currIdx;
8213  strat->syzIdx = initec(comp);
8214  strat->sevSyz = initsevS(ps);
8215  strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8216  strat->syzmax = ps;
8217  strat->syzl = 0;
8218  strat->syzidxmax = comp;
8219 #if defined(DEBUGF5) || defined(DEBUGF51)
8220  PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8221 #endif
8222  i = 1;
8223  j = 0;
8224  /************************************************************
8225  * generating the leading terms of the principal syzygies
8226  ***********************************************************/
8227  while (i <= strat->sl)
8228  {
8229  /**********************************************************
8230  * principal syzygies start with component index 2
8231  * the array syzIdx starts with index 0
8232  * => the rules for a signature with component comp start
8233  * at strat->syz[strat->syzIdx[comp-2]] !
8234  *********************************************************/
8235  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8236  {
8237  comp = pGetComp(strat->sig[i]);
8238  comp_old = pGetComp(strat->sig[i-1]);
8239  diff = comp - comp_old - 1;
8240  // diff should be zero, but sometimes also the initial generating
8241  // elements of the input ideal reduce to zero. then there is an
8242  // index-gap between the signatures. for these inbetween signatures we
8243  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8244  // in the following.
8245  // doing this, we keep the relation "j = comp - 2" alive, which makes
8246  // jumps way easier when checking criteria
8247  while (diff>0)
8248  {
8249  strat->syzIdx[j] = 0;
8250  diff--;
8251  j++;
8252  }
8253  strat->syzIdx[j] = ctr;
8254  j++;
8255  LObject Q;
8256  int pos;
8257  for (k = 0; k<i; k++)
8258  {
8259  Q.sig = pOne();
8261  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8262  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8263  p_SetCompP (Q.sig, comp, currRing);
8264  poly q = p_One(currRing);
8267  p_ExpVectorCopy(q,strat->S[i],currRing);
8268  q = p_Neg (q, currRing);
8269  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8270  Q.sig = p_Add_q (Q.sig, q, currRing);
8271  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8272  pos = posInSyz(strat, Q.sig);
8273  enterSyz(Q, strat, pos);
8274  ctr++;
8275  }
8276  }
8277  i++;
8278  }
8279  /**************************************************************
8280  * add syzygies for upcoming first element of new iteration step
8281  **************************************************************/
8282  comp = strat->currIdx;
8283  comp_old = pGetComp(strat->sig[i-1]);
8284  diff = comp - comp_old - 1;
8285  // diff should be zero, but sometimes also the initial generating
8286  // elements of the input ideal reduce to zero. then there is an
8287  // index-gap between the signatures. for these inbetween signatures we
8288  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8289  // in the following.
8290  // doing this, we keep the relation "j = comp - 2" alive, which makes
8291  // jumps way easier when checking criteria
8292  while (diff>0)
8293  {
8294  strat->syzIdx[j] = 0;
8295  diff--;
8296  j++;
8297  }
8298  strat->syzIdx[j] = ctr;
8299  LObject Q;
8300  int pos;
8301  for (k = 0; k<strat->sl+1; k++)
8302  {
8303  Q.sig = pOne();
8305  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8306  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8307  p_SetCompP (Q.sig, comp, currRing);
8308  poly q = p_One(currRing);
8310  p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8311  p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8312  q = p_Neg (q, currRing);
8313  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8314  Q.sig = p_Add_q (Q.sig, q, currRing);
8315  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8316  pos = posInSyz(strat, Q.sig);
8317  enterSyz(Q, strat, pos);
8318  ctr++;
8319  }
8320 //#if 1
8321 #ifdef DEBUGF5
8322  PrintS("Principal syzygies:\n");
8323  Print("syzl %d\n",strat->syzl);
8324  Print("syzmax %d\n",strat->syzmax);
8325  Print("ps %d\n",ps);
8326  PrintS("--------------------------------\n");
8327  for(i=0;i<=strat->syzl-1;i++)
8328  {
8329  Print("%d - ",i);
8330  pWrite(strat->syz[i]);
8331  }
8332  for(i=0;i<strat->currIdx;i++)
8333  {
8334  Print("%d - %d\n",i,strat->syzIdx[i]);
8335  }
8336  PrintS("--------------------------------\n");
8337 #endif
8338  }
8339 }
8340 
8341 /*2
8342 *construct the set s from F and {P}
8343 */
8344 void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8345 {
8346  int i,pos;
8347 
8348  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8349  else i=setmaxT;
8350  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8351  strat->ecartS=initec(i);
8352  strat->sevS=initsevS(i);
8353  strat->S_2_R=initS_2_R(i);
8354  strat->fromQ=NULL;
8355  strat->Shdl=idInit(i,F->rank);
8356  strat->S=strat->Shdl->m;
8357 
8358  /*- put polys into S -*/
8359  if (Q!=NULL)
8360  {
8361  strat->fromQ=initec(i);
8362  memset(strat->fromQ,0,i*sizeof(int));
8363  for (i=0; i<IDELEMS(Q); i++)
8364  {
8365  if (Q->m[i]!=NULL)
8366  {
8367  LObject h;
8368  h.p = pCopy(Q->m[i]);
8369  //if (TEST_OPT_INTSTRATEGY)
8370  //{
8371  // h.pCleardenom(); // also does remove Content
8372  //}
8373  //else
8374  //{
8375  // h.pNorm();
8376  //}
8378  {
8379  deleteHC(&h,strat);
8380  }
8381  if (h.p!=NULL)
8382  {
8383  strat->initEcart(&h);
8384  if (strat->sl==-1)
8385  pos =0;
8386  else
8387  {
8388  pos = posInS(strat,strat->sl,h.p,h.ecart);
8389  }
8390  h.sev = pGetShortExpVector(h.p);
8391  strat->enterS(h,pos,strat, strat->tl+1);
8392  enterT(h, strat);
8393  strat->fromQ[pos]=1;
8394  }
8395  }
8396  }
8397  }
8398  /*- put polys into S -*/
8399  for (i=0; i<IDELEMS(F); i++)
8400  {
8401  if (F->m[i]!=NULL)
8402  {
8403  LObject h;
8404  h.p = pCopy(F->m[i]);
8406  {
8407  deleteHC(&h,strat);
8408  }
8409  else
8410  {
8411  h.p=redtailBba(h.p,strat->sl,strat);
8412  }
8413  if (h.p!=NULL)
8414  {
8415  strat->initEcart(&h);
8416  if (strat->sl==-1)
8417  pos =0;
8418  else
8419  pos = posInS(strat,strat->sl,h.p,h.ecart);
8420  h.sev = pGetShortExpVector(h.p);
8421  strat->enterS(h,pos,strat, strat->tl+1);
8422  enterT(h,strat);
8423  }
8424  }
8425  }
8426  for (i=0; i<IDELEMS(P); i++)
8427  {
8428  if (P->m[i]!=NULL)
8429  {
8430  LObject h;
8431  h.p=pCopy(P->m[i]);
8433  {
8434  h.pCleardenom();
8435  }
8436  else
8437  {
8438  h.pNorm();
8439  }
8440  if(strat->sl>=0)
8441  {
8443  {
8444  h.p=redBba(h.p,strat->sl,strat);
8445  if (h.p!=NULL)
8446  {
8447  h.p=redtailBba(h.p,strat->sl,strat);
8448  }
8449  }
8450  else
8451  {
8452  h.p=redMora(h.p,strat->sl,strat);
8453  }
8454  if(h.p!=NULL)
8455  {
8456  strat->initEcart(&h);
8458  {
8459  h.pCleardenom();
8460  }
8461  else
8462  {
8463  h.is_normalized = 0;
8464  h.pNorm();
8465  }
8466  h.sev = pGetShortExpVector(h.p);
8467  h.SetpFDeg();
8468  pos = posInS(strat,strat->sl,h.p,h.ecart);
8469  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8470  strat->enterS(h,pos,strat, strat->tl+1);
8471  enterT(h,strat);
8472  }
8473  }
8474  else
8475  {
8476  h.sev = pGetShortExpVector(h.p);
8477  strat->initEcart(&h);
8478  strat->enterS(h,0,strat, strat->tl+1);
8479  enterT(h,strat);
8480  }
8481  }
8482  }
8483 }
8484 /*2
8485 *construct the set s from F and {P}
8486 */
8487 
8488 void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8489 {
8490  int i,pos;
8491 
8492  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8493  else i=setmaxT;
8494  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8495  strat->sevS=initsevS(i);
8496  strat->sevSig=initsevS(i);
8497  strat->S_2_R=initS_2_R(i);
8498  strat->fromQ=NULL;
8499  strat->Shdl=idInit(i,F->rank);
8500  strat->S=strat->Shdl->m;
8501  strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8502  /*- put polys into S -*/
8503  if (Q!=NULL)
8504  {
8505  strat->fromQ=initec(i);
8506  memset(strat->fromQ,0,i*sizeof(int));
8507  for (i=0; i<IDELEMS(Q); i++)
8508  {
8509  if (Q->m[i]!=NULL)
8510  {
8511  LObject h;
8512  h.p = pCopy(Q->m[i]);
8513  //if (TEST_OPT_INTSTRATEGY)
8514  //{
8515  // h.pCleardenom(); // also does remove Content
8516  //}
8517  //else
8518  //{
8519  // h.pNorm();
8520  //}
8522  {
8523  deleteHC(&h,strat);
8524  }
8525  if (h.p!=NULL)
8526  {
8527  strat->initEcart(&h);
8528  if (strat->sl==-1)
8529  pos =0;
8530  else
8531  {
8532  pos = posInS(strat,strat->sl,h.p,h.ecart);
8533  }
8534  h.sev = pGetShortExpVector(h.p);
8535  strat->enterS(h,pos,strat, strat->tl+1);
8536  enterT(h, strat);
8537  strat->fromQ[pos]=1;
8538  }
8539  }
8540  }
8541  }
8542  /*- put polys into S -*/
8543  for (i=0; i<IDELEMS(F); i++)
8544  {
8545  if (F->m[i]!=NULL)
8546  {
8547  LObject h;
8548  h.p = pCopy(F->m[i]);
8550  {
8551  deleteHC(&h,strat);
8552  }
8553  else
8554  {
8555  h.p=redtailBba(h.p,strat->sl,strat);
8556  }
8557  if (h.p!=NULL)
8558  {
8559  strat->initEcart(&h);
8560  if (strat->sl==-1)
8561  pos =0;
8562  else
8563  pos = posInS(strat,strat->sl,h.p,h.ecart);
8564  h.sev = pGetShortExpVector(h.p);
8565  strat->enterS(h,pos,strat, strat->tl+1);
8566  enterT(h,strat);
8567  }
8568  }
8569  }
8570  for (i=0; i<IDELEMS(P); i++)
8571  {
8572  if (P->m[i]!=NULL)
8573  {
8574  LObject h;
8575  h.p=pCopy(P->m[i]);
8577  {
8578  h.pCleardenom();
8579  }
8580  else
8581  {
8582  h.pNorm();
8583  }
8584  if(strat->sl>=0)
8585  {
8587  {
8588  h.p=redBba(h.p,strat->sl,strat);
8589  if (h.p!=NULL)
8590  {
8591  h.p=redtailBba(h.p,strat->sl,strat);
8592  }
8593  }
8594  else
8595  {
8596  h.p=redMora(h.p,strat->sl,strat);
8597  }
8598  if(h.p!=NULL)
8599  {
8600  strat->initEcart(&h);
8602  {
8603  h.pCleardenom();
8604  }
8605  else
8606  {
8607  h.is_normalized = 0;
8608  h.pNorm();
8609  }
8610  h.sev = pGetShortExpVector(h.p);
8611  h.SetpFDeg();
8612  pos = posInS(strat,strat->sl,h.p,h.ecart);
8613  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8614  strat->enterS(h,pos,strat, strat->tl+1);
8615  enterT(h,strat);
8616  }
8617  }
8618  else
8619  {
8620  h.sev = pGetShortExpVector(h.p);
8621  strat->initEcart(&h);
8622  strat->enterS(h,0,strat, strat->tl+1);
8623  enterT(h,strat);
8624  }
8625  }
8626  }
8628 
8629 /*2
8630 * reduces h using the set S
8631 * procedure used in cancelunit1
8632 */
8633 static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8634 {
8635  int j = 0;
8636  unsigned long not_sev = ~ pGetShortExpVector(h);
8637 
8638  while (j <= maxIndex)
8639  {
8640  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8641  return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8642  else j++;
8643  }
8644  return h;
8645 }
8646 
8647 /*2
8648 *tests if p.p=monomial*unit and cancels the unit
8649 */
8650 void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8651 {
8652  int k;
8653  poly r,h,h1,q;
8654 
8655  if (!pIsVector((*p).p) && ((*p).ecart != 0))
8656  {
8657 #ifdef HAVE_RINGS
8658  // Leading coef have to be a unit: no
8659  // example 2x+4x2 should be simplified to 2x*(1+2x)
8660  // and 2 is not a unit in Z
8661  //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8662 #endif
8663  k = 0;
8664  h1 = r = pCopy((*p).p);
8665  h =pNext(r);
8666  loop
8667  {
8668  if (h==NULL)
8669  {
8670  pDelete(&r);
8671  pDelete(&(pNext((*p).p)));
8672  (*p).ecart = 0;
8673  (*p).length = 1;
8674  (*p).pLength = 1;
8675  (*suc)=0;
8676  return;
8677  }
8678  if (!pDivisibleBy(r,h))
8679  {
8680  q=redBba1(h,index ,strat);
8681  if (q != h)
8682  {
8683  k++;
8684  pDelete(&h);
8685  pNext(h1) = h = q;
8686  }
8687  else
8688  {
8689  pDelete(&r);
8690  return;
8691  }
8692  }
8693  else
8694  {
8695  h1 = h;
8696  pIter(h);
8697  }
8698  if (k > 10)
8699  {
8700  pDelete(&r);
8701  return;
8702  }
8703  }
8704  }
8705 }
8706 
8707 #if 0
8708 /*2
8709 * reduces h using the elements from Q in the set S
8710 * procedure used in updateS
8711 * must not be used for elements of Q or elements of an ideal !
8712 */
8713 static poly redQ (poly h, int j, kStrategy strat)
8714 {
8715  int start;
8716  unsigned long not_sev = ~ pGetShortExpVector(h);
8717  while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8718  start=j;
8719  while (j<=strat->sl)
8720  {
8721  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8722  {
8723  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8724  if (h==NULL) return NULL;
8725  j = start;
8726  not_sev = ~ pGetShortExpVector(h);
8727  }
8728  else j++;
8729  }
8730  return h;
8731 }
8732 #endif
8733 
8734 /*2
8735 * reduces h using the set S
8736 * procedure used in updateS
8737 */
8738 static poly redBba (poly h,int maxIndex,kStrategy strat)
8739 {
8740  int j = 0;
8741  unsigned long not_sev = ~ pGetShortExpVector(h);
8742 
8743  while (j <= maxIndex)
8744  {
8745  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8746  {
8747  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8748  if (h==NULL) return NULL;
8749  j = 0;
8750  not_sev = ~ pGetShortExpVector(h);
8751  }
8752  else j++;
8753  }
8754  return h;
8755 }
8757 /*2
8758 * reduces h using the set S
8759 *e is the ecart of h
8760 *procedure used in updateS
8761 */
8762 static poly redMora (poly h,int maxIndex,kStrategy strat)
8763 {
8764  int j=0;
8765  int e,l;
8766  unsigned long not_sev = ~ pGetShortExpVector(h);
8767 
8768  if (maxIndex >= 0)
8769  {
8770  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8771  do
8772  {
8773  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8774  && ((e >= strat->ecartS[j]) || strat->kHEdgeFound))
8775  {
8776 #ifdef KDEBUG
8777  if (TEST_OPT_DEBUG)
8778  {
8779  PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8780  }
8781 #endif
8782  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8783 #ifdef KDEBUG
8784  if(TEST_OPT_DEBUG)
8785  {
8786  PrintS(")\nto "); wrp(h); PrintLn();
8787  }
8788 #endif
8789  // pDelete(&h);
8790  if (h == NULL) return NULL;
8791  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8792  j = 0;
8793  not_sev = ~ pGetShortExpVector(h);
8794  }
8795  else j++;
8796  }
8797  while (j <= maxIndex);
8798  }
8799  return h;
8800 }
8802 /*2
8803 *updates S:
8804 *the result is a set of polynomials which are in
8805 *normalform with respect to S
8806 */
8807 void updateS(BOOLEAN toT,kStrategy strat)
8808 {
8809  LObject h;
8810  int i, suc=0;
8811  poly redSi=NULL;
8812  BOOLEAN change,any_change;
8813 // Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8814 // for (i=0; i<=(strat->sl); i++)
8815 // {
8816 // Print("s%d:",i);
8817 // if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8818 // pWrite(strat->S[i]);
8819 // }
8820 // Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8821  any_change=FALSE;
8823  {
8824  while (suc != -1)
8825  {
8826  i=suc+1;
8827  while (i<=strat->sl)
8828  {
8829  change=FALSE;
8831  any_change = FALSE;
8832  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8833  {
8834  redSi = pHead(strat->S[i]);
8835  strat->S[i] = redBba(strat->S[i],i-1,strat);
8836  //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8837  // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8838  if (pCmp(redSi,strat->S[i])!=0)
8839  {
8840  change=TRUE;
8841  any_change=TRUE;
8842  #ifdef KDEBUG
8843  if (TEST_OPT_DEBUG)
8844  {
8845  PrintS("reduce:");
8846  wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8847  }
8848  #endif
8849  if (TEST_OPT_PROT)
8850  {
8851  if (strat->S[i]==NULL)
8852  PrintS("V");
8853  else
8854  PrintS("v");
8855  mflush();
8856  }
8857  }
8858  pLmDelete(&redSi);
8859  if (strat->S[i]==NULL)
8860  {
8861  deleteInS(i,strat);
8862  i--;
8863  }
8864  else if (change)
8865  {
8867  {
8868  if (TEST_OPT_CONTENTSB)
8869  {
8870  number n;
8871  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8872  if (!nIsOne(n))
8873  {
8875  denom->n=nInvers(n);
8876  denom->next=DENOMINATOR_LIST;
8877  DENOMINATOR_LIST=denom;
8878  }
8879  nDelete(&n);
8880  }
8881  else
8882  {
8883  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8884  }
8885  }
8886  else
8887  {
8888  pNorm(strat->S[i]);
8889  }
8890  strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8891  }
8892  }
8893  i++;
8894  }
8895  if (any_change) reorderS(&suc,strat);
8896  else break;
8897  }
8898  if (toT)
8899  {
8900  for (i=0; i<=strat->sl; i++)
8901  {
8902  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8903  {
8904  h.p = redtailBba(strat->S[i],i-1,strat);
8906  {
8907  h.pCleardenom();// also does remove Content
8908  }
8909  }
8910  else
8911  {
8912  h.p = strat->S[i];
8913  }
8914  strat->initEcart(&h);
8915  if (strat->honey)
8916  {
8917  strat->ecartS[i] = h.ecart;
8918  }
8919  if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8920  else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8921  h.sev = strat->sevS[i];
8922  /*puts the elements of S also to T*/
8923  strat->initEcart(&h);
8924  enterT(h,strat);
8925  strat->S_2_R[i] = strat->tl;
8926  }
8927  }
8928  }
8929  else
8930  {
8931  while (suc != -1)
8932  {
8933  i=suc;
8934  while (i<=strat->sl)
8935  {
8936  change=FALSE;
8937  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8938  {
8939  redSi=pHead((strat->S)[i]);
8940  (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
8941  if ((strat->S)[i]==NULL)
8942  {
8943  deleteInS(i,strat);
8944  i--;
8945  }
8946  else if (pCmp((strat->S)[i],redSi)!=0)
8947  {
8948  any_change=TRUE;
8949  h.p = strat->S[i];
8950  strat->initEcart(&h);
8951  strat->ecartS[i] = h.ecart;
8953  {
8954  if (TEST_OPT_CONTENTSB)
8955  {
8956  number n;
8957  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8958  if (!nIsOne(n))
8959  {
8961  denom->n=nInvers(n);
8962  denom->next=DENOMINATOR_LIST;
8963  DENOMINATOR_LIST=denom;
8964  }
8965  nDelete(&n);
8966  }
8967  else
8968  {
8969  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8970  }
8971  }
8972  else
8973  {
8974  pNorm(strat->S[i]); // == h.p
8975  }
8976  h.sev = pGetShortExpVector(h.p);
8977  strat->sevS[i] = h.sev;
8978  }
8979  pLmDelete(&redSi);
8980  kTest(strat);
8981  }
8982  i++;
8983  }
8984 #ifdef KDEBUG
8985  kTest(strat);
8986 #endif
8987  if (any_change) reorderS(&suc,strat);
8988  else { suc=-1; break; }
8989  if (h.p!=NULL)
8990  {
8991  if (!strat->kHEdgeFound)
8992  {
8993  /*strat->kHEdgeFound =*/ HEckeTest(h.p,strat);
8994  }
8995  if (strat->kHEdgeFound)
8996  newHEdge(strat);
8997  }
8998  }
8999  for (i=0; i<=strat->sl; i++)
9000  {
9001  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9002  {
9003  strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
9004  strat->initEcart(&h);
9005  strat->ecartS[i] = h.ecart;
9006  h.sev = pGetShortExpVector(h.p);
9007  strat->sevS[i] = h.sev;
9008  }
9009  else
9010  {
9011  h.p = strat->S[i];
9012  h.ecart=strat->ecartS[i];
9013  h.sev = strat->sevS[i];
9014  h.length = h.pLength = pLength(h.p);
9015  }
9016  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9017  cancelunit1(&h,&suc,strat->sl,strat);
9018  h.SetpFDeg();
9019  /*puts the elements of S also to T*/
9020  enterT(h,strat);
9021  strat->S_2_R[i] = strat->tl;
9022  }
9023  if (suc!= -1) updateS(toT,strat);
9024  }
9025 #ifdef KDEBUG
9026  kTest(strat);
9027 #endif
9029 
9030 /*2
9031 * -puts p to the standardbasis s at position at
9032 * -saves the result in S
9033 */
9034 void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
9035 {
9036  strat->news = TRUE;
9037  /*- puts p to the standardbasis s at position at -*/
9038  if (strat->sl == IDELEMS(strat->Shdl)-1)
9039  {
9040  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9041  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9042  (IDELEMS(strat->Shdl)+setmaxTinc)
9043  *sizeof(unsigned long));
9044  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9045  IDELEMS(strat->Shdl)*sizeof(int),
9046  (IDELEMS(strat->Shdl)+setmaxTinc)
9047  *sizeof(int));
9048  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9049  IDELEMS(strat->Shdl)*sizeof(int),
9050  (IDELEMS(strat->Shdl)+setmaxTinc)
9051  *sizeof(int));
9052  if (strat->lenS!=NULL)
9053  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9054  IDELEMS(strat->Shdl)*sizeof(int),
9055  (IDELEMS(strat->Shdl)+setmaxTinc)
9056  *sizeof(int));
9057  if (strat->lenSw!=NULL)
9058  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9059  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9060  (IDELEMS(strat->Shdl)+setmaxTinc)
9061  *sizeof(wlen_type));
9062  if (strat->fromQ!=NULL)
9063  {
9064  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9065  IDELEMS(strat->Shdl)*sizeof(int),
9066  (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9067  }
9068  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
9069  IDELEMS(strat->Shdl)+=setmaxTinc;
9070  strat->Shdl->m=strat->S;
9071  }
9072  if (atS <= strat->sl)
9073  {
9074 #ifdef ENTER_USE_MEMMOVE
9075  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9076  (strat->sl - atS + 1)*sizeof(poly));
9077  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9078  (strat->sl - atS + 1)*sizeof(int));
9079  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9080  (strat->sl - atS + 1)*sizeof(unsigned long));
9081  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9082  (strat->sl - atS + 1)*sizeof(int));
9083  if (strat->lenS!=NULL)
9084  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9085  (strat->sl - atS + 1)*sizeof(int));
9086  if (strat->lenSw!=NULL)
9087  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9088  (strat->sl - atS + 1)*sizeof(wlen_type));
9089 #else
9090  for (i=strat->sl+1; i>=atS+1; i--)
9091  {
9092  strat->S[i] = strat->S[i-1];
9093  strat->ecartS[i] = strat->ecartS[i-1];
9094  strat->sevS[i] = strat->sevS[i-1];
9095  strat->S_2_R[i] = strat->S_2_R[i-1];
9096  }
9097  if (strat->lenS!=NULL)
9098  for (i=strat->sl+1; i>=atS+1; i--)
9099  strat->lenS[i] = strat->lenS[i-1];
9100  if (strat->lenSw!=NULL)
9101  for (i=strat->sl+1; i>=atS+1; i--)
9102  strat->lenSw[i] = strat->lenSw[i-1];
9103 #endif
9104  }
9105  if (strat->fromQ!=NULL)
9106  {
9107 #ifdef ENTER_USE_MEMMOVE
9108  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9109  (strat->sl - atS + 1)*sizeof(int));
9110 #else
9111  for (i=strat->sl+1; i>=atS+1; i--)
9112  {
9113  strat->fromQ[i] = strat->fromQ[i-1];
9114  }
9115 #endif
9116  strat->fromQ[atS]=0;
9117  }
9118 
9119  /*- save result -*/
9120  poly pp=p.p;
9121  strat->S[atS] = pp;
9122  if (strat->honey) strat->ecartS[atS] = p.ecart;
9123  if (p.sev == 0)
9124  p.sev = pGetShortExpVector(pp);
9125  else
9126  assume(p.sev == pGetShortExpVector(pp));
9127  strat->sevS[atS] = p.sev;
9128  strat->ecartS[atS] = p.ecart;
9129  strat->S_2_R[atS] = atR;
9130  strat->sl++;
9132 
9133 /*2
9134 * -puts p to the standardbasis s at position at
9135 * -saves the result in S
9136 */
9137 void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
9138 {
9139  strat->news = TRUE;
9140  /*- puts p to the standardbasis s at position at -*/
9141  if (strat->sl == IDELEMS(strat->Shdl)-1)
9142  {
9143  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9144  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9145  (IDELEMS(strat->Shdl)+setmax)
9146  *sizeof(unsigned long));
9147  strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
9148  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9149  (IDELEMS(strat->Shdl)+setmax)
9150  *sizeof(unsigned long));
9151  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9152  IDELEMS(strat->Shdl)*sizeof(int),
9153  (IDELEMS(strat->Shdl)+setmax)
9154  *sizeof(int));
9155  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9156  IDELEMS(strat->Shdl)*sizeof(int),
9157  (IDELEMS(strat->Shdl)+setmax)
9158  *sizeof(int));
9159  if (strat->lenS!=NULL)
9160  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9161  IDELEMS(strat->Shdl)*sizeof(int),
9162  (IDELEMS(strat->Shdl)+setmax)
9163  *sizeof(int));
9164  if (strat->lenSw!=NULL)
9165  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9166  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9167  (IDELEMS(strat->Shdl)+setmax)
9168  *sizeof(wlen_type));
9169  if (strat->fromQ!=NULL)
9170  {
9171  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9172  IDELEMS(strat->Shdl)*sizeof(int),
9173  (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
9174  }
9175  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
9176  pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
9177  IDELEMS(strat->Shdl)+=setmax;
9178  strat->Shdl->m=strat->S;
9179  }
9180  // in a signature-based algorithm the following situation will never
9181  // appear due to the fact that the critical pairs are already sorted
9182  // by increasing signature.
9183  // True. However, in the case of integers we need to put the element
9184  // that caused the signature drop on the first position
9185  if (atS <= strat->sl)
9186  {
9187 #ifdef ENTER_USE_MEMMOVE
9188  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9189  (strat->sl - atS + 1)*sizeof(poly));
9190  memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9191  (strat->sl - atS + 1)*sizeof(poly));
9192  memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9193  (strat->sl - atS + 1)*sizeof(unsigned long));
9194  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9195  (strat->sl - atS + 1)*sizeof(int));
9196  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9197  (strat->sl - atS + 1)*sizeof(unsigned long));
9198  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9199  (strat->sl - atS + 1)*sizeof(int));
9200  if (strat->lenS!=NULL)
9201  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9202  (strat->sl - atS + 1)*sizeof(int));
9203  if (strat->lenSw!=NULL)
9204  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9205  (strat->sl - atS + 1)*sizeof(wlen_type));
9206 #else
9207  for (i=strat->sl+1; i>=atS+1; i--)
9208  {
9209  strat->S[i] = strat->S[i-1];
9210  strat->ecartS[i] = strat->ecartS[i-1];
9211  strat->sevS[i] = strat->sevS[i-1];
9212  strat->S_2_R[i] = strat->S_2_R[i-1];
9213  strat->sig[i] = strat->sig[i-1];
9214  strat->sevSig[i] = strat->sevSig[i-1];
9215  }
9216  if (strat->lenS!=NULL)
9217  for (i=strat->sl+1; i>=atS+1; i--)
9218  strat->lenS[i] = strat->lenS[i-1];
9219  if (strat->lenSw!=NULL)
9220  for (i=strat->sl+1; i>=atS+1; i--)
9221  strat->lenSw[i] = strat->lenSw[i-1];
9222 #endif
9223  }
9224  if (strat->fromQ!=NULL)
9225  {
9226 #ifdef ENTER_USE_MEMMOVE
9227  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9228  (strat->sl - atS + 1)*sizeof(int));
9229 #else
9230  for (i=strat->sl+1; i>=atS+1; i--)
9231  {
9232  strat->fromQ[i] = strat->fromQ[i-1];
9233  }
9234 #endif
9235  strat->fromQ[atS]=0;
9236  }
9237 
9238  /*- save result -*/
9239  strat->S[atS] = p.p;
9240  strat->sig[atS] = p.sig; // TODO: get ths correct signature in here!
9241  if (strat->honey) strat->ecartS[atS] = p.ecart;
9242  if (p.sev == 0)
9243  p.sev = pGetShortExpVector(p.p);
9244  else
9245  assume(p.sev == pGetShortExpVector(p.p));
9246  strat->sevS[atS] = p.sev;
9247  // during the interreduction process of a signature-based algorithm we do not
9248  // compute the signature at this point, but when the whole interreduction
9249  // process finishes, i.e. f5c terminates!
9250  if (p.sig != NULL)
9251  {
9252  if (p.sevSig == 0)
9253  p.sevSig = pGetShortExpVector(p.sig);
9254  else
9255  assume(p.sevSig == pGetShortExpVector(p.sig));
9256  strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9257  }
9258  strat->ecartS[atS] = p.ecart;
9259  strat->S_2_R[atS] = atR;
9260  strat->sl++;
9261 #ifdef DEBUGF5
9262  int k;
9263  Print("--- LIST S: %d ---\n",strat->sl);
9264  for(k=0;k<=strat->sl;k++)
9265  {
9266  pWrite(strat->sig[k]);
9267  }
9268  PrintS("--- LIST S END ---\n");
9269 #endif
9270 }
9271 
9272 /*2
9273 * puts p to the set T at position atT
9274 */
9275 void enterT(LObject &p, kStrategy strat, int atT)
9276 {
9277  int i;
9278 
9279  pp_Test(p.p, currRing, p.tailRing);
9280  assume(strat->tailRing == p.tailRing);
9281  // redMoraNF complains about this -- but, we don't really
9282  // neeed this so far
9283  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9284  assume(p.FDeg == p.pFDeg());
9285  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9286 
9287 #ifdef KDEBUG
9288  // do not put an LObject twice into T:
9289  for(i=strat->tl;i>=0;i--)
9290  {
9291  if (p.p==strat->T[i].p)
9292  {
9293  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9294  return;
9295  }
9296  }
9297 #endif
9298 
9299 #ifdef HAVE_TAIL_RING
9300  if (currRing!=strat->tailRing)
9301  {
9302  p.t_p=p.GetLmTailRing();
9303  }
9304 #endif
9305  strat->newt = TRUE;
9306  if (atT < 0)
9307  atT = strat->posInT(strat->T, strat->tl, p);
9308  if (strat->tl == strat->tmax-1)
9309  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9310  if (atT <= strat->tl)
9311  {
9312 #ifdef ENTER_USE_MEMMOVE
9313  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9314  (strat->tl-atT+1)*sizeof(TObject));
9315  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9316  (strat->tl-atT+1)*sizeof(unsigned long));
9317 #endif
9318  for (i=strat->tl+1; i>=atT+1; i--)
9319  {
9320 #ifndef ENTER_USE_MEMMOVE
9321  strat->T[i] = strat->T[i-1];
9322  strat->sevT[i] = strat->sevT[i-1];
9323 #endif
9324  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9325  }
9326  }
9327 
9328  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9329  {
9331  (strat->tailRing != NULL ?
9332  strat->tailRing : currRing),
9333  strat->tailBin);
9334  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9335  }
9336  strat->T[atT] = (TObject) p;
9337  //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9338 
9339  if (pNext(p.p) != NULL)
9340  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9341  else
9342  strat->T[atT].max_exp = NULL;
9343 
9344  strat->tl++;
9345  strat->R[strat->tl] = &(strat->T[atT]);
9346  strat->T[atT].i_r = strat->tl;
9347  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9348  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9349  kTest_T(&(strat->T[atT]));
9351 
9352 /*2
9353 * puts p to the set T at position atT
9354 */
9355 #ifdef HAVE_RINGS
9356 void enterT_strong(LObject &p, kStrategy strat, int atT)
9357 {
9359  int i;
9360 
9361  pp_Test(p.p, currRing, p.tailRing);
9362  assume(strat->tailRing == p.tailRing);
9363  // redMoraNF complains about this -- but, we don't really
9364  // neeed this so far
9365  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9366  assume(p.FDeg == p.pFDeg());
9367  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9368 
9369 #ifdef KDEBUG
9370  // do not put an LObject twice into T:
9371  for(i=strat->tl;i>=0;i--)
9372  {
9373  if (p.p==strat->T[i].p)
9374  {
9375  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9376  return;
9377  }
9378  }
9379 #endif
9380 
9381 #ifdef HAVE_TAIL_RING
9382  if (currRing!=strat->tailRing)
9383  {
9384  p.t_p=p.GetLmTailRing();
9385  }
9386 #endif
9387  strat->newt = TRUE;
9388  if (atT < 0)
9389  atT = strat->posInT(strat->T, strat->tl, p);
9390  if (strat->tl == strat->tmax-1)
9391  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9392  if (atT <= strat->tl)
9393  {
9394 #ifdef ENTER_USE_MEMMOVE
9395  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9396  (strat->tl-atT+1)*sizeof(TObject));
9397  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9398  (strat->tl-atT+1)*sizeof(unsigned long));
9399 #endif
9400  for (i=strat->tl+1; i>=atT+1; i--)
9401  {
9402 #ifndef ENTER_USE_MEMMOVE
9403  strat->T[i] = strat->T[i-1];
9404  strat->sevT[i] = strat->sevT[i-1];
9405 #endif
9406  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9407  }
9408  }
9409 
9410  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9411  {
9413  (strat->tailRing != NULL ?
9414  strat->tailRing : currRing),
9415  strat->tailBin);
9416  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9417  }
9418  strat->T[atT] = (TObject) p;
9419  //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9420 
9421  if (pNext(p.p) != NULL)
9422  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9423  else
9424  strat->T[atT].max_exp = NULL;
9425 
9426  strat->tl++;
9427  strat->R[strat->tl] = &(strat->T[atT]);
9428  strat->T[atT].i_r = strat->tl;
9429  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9430  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9431  #if 1
9433  && !n_IsUnit(p.p->coef, currRing->cf))
9434  {
9435  for(i=strat->tl;i>=0;i--)
9436  {
9437  if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9438  {
9439  enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9440  }
9441  }
9442  }
9443  /*
9444  printf("\nThis is T:\n");
9445  for(i=strat->tl;i>=0;i--)
9446  {
9447  pWrite(strat->T[i].p);
9448  }
9449  //getchar();*/
9450  #endif
9451  kTest_T(&(strat->T[atT]));
9453 #endif
9454 
9455 /*2
9456 * puts signature p.sig to the set syz
9457 */
9458 void enterSyz(LObject &p, kStrategy strat, int atT)
9459 {
9460  int i;
9461  strat->newt = TRUE;
9462  if (strat->syzl == strat->syzmax-1)
9463  {
9464  pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9465  strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9466  (strat->syzmax)*sizeof(unsigned long),
9467  ((strat->syzmax)+setmax)
9468  *sizeof(unsigned long));
9469  strat->syzmax += setmax;
9470  }
9471  if (atT < strat->syzl)
9472  {
9473 #ifdef ENTER_USE_MEMMOVE
9474  memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9475  (strat->syzl-atT+1)*sizeof(poly));
9476  memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9477  (strat->syzl-atT+1)*sizeof(unsigned long));
9478 #endif
9479  for (i=strat->syzl; i>=atT+1; i--)
9480  {
9481 #ifndef ENTER_USE_MEMMOVE
9482  strat->syz[i] = strat->syz[i-1];
9483  strat->sevSyz[i] = strat->sevSyz[i-1];
9484 #endif
9485  }
9486  }
9487  //i = strat->syzl;
9488  i = atT;
9489  //Makes sure the syz saves just the signature
9490  #ifdef HAVE_RINGS
9492  pNext(p.sig) = NULL;
9493  #endif
9494  strat->syz[atT] = p.sig;
9495  strat->sevSyz[atT] = p.sevSig;
9496  strat->syzl++;
9497 #if F5DEBUG
9498  Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9499  pWrite(strat->syz[atT]);
9500 #endif
9501  // recheck pairs in strat->L with new rule and delete correspondingly
9502  int cc = strat->Ll;
9503  while (cc>-1)
9504  {
9505  //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9506  //printf("\npLmShDivBy(syz,L) = %i\nn_DivBy(L,syz) = %i\n pLtCmp(L,syz) = %i",p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],strat->L[cc].sig, ~strat->L[cc].sevSig, currRing), n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing), pLtCmp(strat->L[cc].sig,strat->syz[atT])==1);
9507  if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9508  strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9509  #ifdef HAVE_RINGS
9510  &&((!rField_is_Ring(currRing))
9511  || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9512  #endif
9513  )
9514  {
9515  //printf("\nYES!\n");
9516  deleteInL(strat->L,&strat->Ll,cc,strat);
9517  }
9518  cc--;
9519  }
9520 //#if 1
9521 #ifdef DEBUGF5
9522  PrintS("--- Syzygies ---\n");
9523  Print("syzl %d\n",strat->syzl);
9524  Print("syzmax %d\n",strat->syzmax);
9525  PrintS("--------------------------------\n");
9526  for(i=0;i<=strat->syzl-1;i++)
9527  {
9528  Print("%d - ",i);
9529  pWrite(strat->syz[i]);
9530  }
9531  PrintS("--------------------------------\n");
9532 #endif
9533 }
9534 
9535 
9536 void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9537 {
9538 
9539  //if the ordering is local, then hilb criterion
9540  //can be used also if the ideal is not homogenous
9542  {
9544  *hilb=NULL;
9545  else
9546  return;
9547  }
9548  if (strat->homog!=isHomog)
9549  {
9550  *hilb=NULL;
9551  }
9552 }
9553 
9554 void initBuchMoraCrit(kStrategy strat)
9555 {
9557  strat->chainCrit=chainCritNormal;
9558  if (TEST_OPT_SB_1)
9559  strat->chainCrit=chainCritOpt_1;
9560 #ifdef HAVE_RINGS
9561  if (rField_is_Ring(currRing))
9562  {
9564  strat->chainCrit=chainCritRing;
9565  }
9566 #endif
9567 #ifdef HAVE_RATGRING
9568  if (rIsRatGRing(currRing))
9569  {
9570  strat->chainCrit=chainCritPart;
9571  /* enterOnePairNormal get rational part in it */
9572  }
9573 #endif
9574  if (TEST_OPT_IDLIFT /* i.e. also strat->syzComp==1 */
9575  && (!rIsPluralRing(currRing)))
9577 
9578  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9579  strat->Gebauer = strat->homog || strat->sugarCrit;
9580  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9581  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9582  strat->pairtest = NULL;
9583  /* alway use tailreduction, except:
9584  * - in local rings, - in lex order case, -in ring over extensions */
9586  //if(rHasMixedOrdering(currRing)==2)
9587  //{
9588  // strat->noTailReduction =TRUE;
9589  //}
9590 
9591 #ifdef HAVE_PLURAL
9592  // and r is plural_ring
9593  // hence this holds for r a rational_plural_ring
9594  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9595  { //or it has non-quasi-comm type... later
9596  strat->sugarCrit = FALSE;
9597  strat->Gebauer = FALSE;
9598  strat->honey = FALSE;
9599  }
9600 #endif
9601 
9602  // Coefficient ring?
9603  if (rField_is_Ring(currRing))
9604  {
9605  strat->sugarCrit = FALSE;
9606  strat->Gebauer = FALSE ;
9607  strat->honey = FALSE;
9608  }
9609  #ifdef KDEBUG
9610  if (TEST_OPT_DEBUG)
9611  {
9612  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9613  else PrintS("ideal/module is not homogeneous\n");
9614  }
9615  #endif
9616 }
9617 
9618 void initSbaCrit(kStrategy strat)
9619 {
9620  //strat->enterOnePair=enterOnePairNormal;
9622  //strat->chainCrit=chainCritNormal;
9623  strat->chainCrit = chainCritSig;
9624  /******************************************
9625  * rewCrit1 and rewCrit2 are already set in
9626  * kSba() in kstd1.cc
9627  *****************************************/
9628  //strat->rewCrit1 = faugereRewCriterion;
9629  if (strat->sbaOrder == 1)
9630  {
9631  strat->syzCrit = syzCriterionInc;
9632  }
9633  else
9634  {
9635  strat->syzCrit = syzCriterion;
9636  }
9637 #ifdef HAVE_RINGS
9638  if (rField_is_Ring(currRing))
9639  {
9641  strat->chainCrit=chainCritRing;
9642  }
9643 #endif
9644 #ifdef HAVE_RATGRING
9645  if (rIsRatGRing(currRing))
9646  {
9647  strat->chainCrit=chainCritPart;
9648  /* enterOnePairNormal get rational part in it */
9649  }
9650 #endif
9651 
9652  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9653  strat->Gebauer = strat->homog || strat->sugarCrit;
9654  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9655  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9656  strat->pairtest = NULL;
9657  /* alway use tailreduction, except:
9658  * - in local rings, - in lex order case, -in ring over extensions */
9661 
9662 #ifdef HAVE_PLURAL
9663  // and r is plural_ring
9664  // hence this holds for r a rational_plural_ring
9665  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9666  { //or it has non-quasi-comm type... later
9667  strat->sugarCrit = FALSE;
9668  strat->Gebauer = FALSE;
9669  strat->honey = FALSE;
9670  }
9671 #endif
9672 
9673  // Coefficient ring?
9674  if (rField_is_Ring(currRing))
9675  {
9676  strat->sugarCrit = FALSE;
9677  strat->Gebauer = FALSE ;
9678  strat->honey = FALSE;
9679  }
9680  #ifdef KDEBUG
9681  if (TEST_OPT_DEBUG)
9682  {
9683  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9684  else PrintS("ideal/module is not homogeneous\n");
9685  }
9686  #endif
9687 }
9688 
9689 BOOLEAN kPosInLDependsOnLength(int (*pos_in_l)
9690  (const LSet set, const int length,
9691  LObject* L,const kStrategy strat))
9692 {
9693  if (pos_in_l == posInL110
9694  || pos_in_l == posInL10
9695  #ifdef HAVE_RINGS
9696  || pos_in_l == posInL110Ring
9697  || pos_in_l == posInLRing
9698  #endif
9699  )
9700  return TRUE;
9701 
9702  return FALSE;
9703 }
9704 
9705 void initBuchMoraPos (kStrategy strat)
9706 {
9708  {
9709  if (strat->honey)
9710  {
9711  strat->posInL = posInL15;
9712  // ok -- here is the deal: from my experiments for Singular-2-0
9713  // I conclude that that posInT_EcartpLength is the best of
9714  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9715  // see the table at the end of this file
9716  if (TEST_OPT_OLDSTD)
9717  strat->posInT = posInT15;
9718  else
9719  strat->posInT = posInT_EcartpLength;
9720  }
9721  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9722  {
9723  strat->posInL = posInL11;
9724  strat->posInT = posInT11;
9725  }
9726  else if (TEST_OPT_INTSTRATEGY)
9727  {
9728  strat->posInL = posInL11;
9729  strat->posInT = posInT11;
9730  }
9731  else
9732  {
9733  strat->posInL = posInL0;
9734  strat->posInT = posInT0;
9735  }
9736  //if (strat->minim>0) strat->posInL =posInLSpecial;
9737  if (strat->homog)
9738  {
9739  strat->posInL = posInL110;
9740  strat->posInT = posInT110;
9741  }
9742  }
9743  else
9744  {
9745  if (strat->homog)
9746  {
9747  strat->posInL = posInL11;
9748  strat->posInT = posInT11;
9749  }
9750  else
9751  {
9752  if ((currRing->order[0]==ringorder_c)
9753  ||(currRing->order[0]==ringorder_C))
9754  {
9755  strat->posInL = posInL17_c;
9756  strat->posInT = posInT17_c;
9757  }
9758  else
9759  {
9760  strat->posInL = posInL17;
9761  strat->posInT = posInT17;
9762  }
9763  }
9764  }
9765  if (strat->minim>0) strat->posInL =posInLSpecial;
9766  // for further tests only
9767  if ((BTEST1(11)) || (BTEST1(12)))
9768  strat->posInL = posInL11;
9769  else if ((BTEST1(13)) || (BTEST1(14)))
9770  strat->posInL = posInL13;
9771  else if ((BTEST1(15)) || (BTEST1(16)))
9772  strat->posInL = posInL15;
9773  else if ((BTEST1(17)) || (BTEST1(18)))
9774  strat->posInL = posInL17;
9775  if (BTEST1(11))
9776  strat->posInT = posInT11;
9777  else if (BTEST1(13))
9778  strat->posInT = posInT13;
9779  else if (BTEST1(15))
9780  strat->posInT = posInT15;
9781  else if ((BTEST1(17)))
9782  strat->posInT = posInT17;
9783  else if ((BTEST1(19)))
9784  strat->posInT = posInT19;
9785  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9786  strat->posInT = posInT1;
9788 }
9789 
9790 #ifdef HAVE_RINGS
9791 void initBuchMoraPosRing (kStrategy strat)
9792 {
9794  {
9795  if (strat->honey)
9796  {
9797  strat->posInL = posInL15Ring;
9798  // ok -- here is the deal: from my experiments for Singular-2-0
9799  // I conclude that that posInT_EcartpLength is the best of
9800  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9801  // see the table at the end of this file
9802  if (TEST_OPT_OLDSTD)
9803  strat->posInT = posInT15Ring;
9804  else
9805  strat->posInT = posInT_EcartpLength;
9806  }
9807  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9808  {
9809  strat->posInL = posInL11Ring;
9810  strat->posInT = posInT11;
9811  }
9812  else if (TEST_OPT_INTSTRATEGY)
9813  {
9814  strat->posInL = posInL11Ring;
9815  strat->posInT = posInT11;
9816  }
9817  else
9818  {
9819  strat->posInL = posInL0Ring;
9820  strat->posInT = posInT0;
9821  }
9822  //if (strat->minim>0) strat->posInL =posInLSpecial;
9823  if (strat->homog)
9824  {
9825  strat->posInL = posInL110Ring;
9826  strat->posInT = posInT110Ring;
9827  }
9828  }
9829  else
9830  {
9831  if (strat->homog)
9832  {
9833  //printf("\nHere 3\n");
9834  strat->posInL = posInL11Ring;
9835  strat->posInT = posInT11Ring;
9836  }
9837  else
9838  {
9839  if ((currRing->order[0]==ringorder_c)
9840  ||(currRing->order[0]==ringorder_C))
9841  {
9842  strat->posInL = posInL17_cRing;
9843  strat->posInT = posInT17_cRing;
9844  }
9845  else
9846  {
9847  strat->posInL = posInL11Ringls;
9848  strat->posInT = posInT17Ring;
9849  }
9850  }
9851  }
9852  if (strat->minim>0) strat->posInL =posInLSpecial;
9853  // for further tests only
9854  if ((BTEST1(11)) || (BTEST1(12)))
9855  strat->posInL = posInL11Ring;
9856  else if ((BTEST1(13)) || (BTEST1(14)))
9857  strat->posInL = posInL13;
9858  else if ((BTEST1(15)) || (BTEST1(16)))
9859  strat->posInL = posInL15Ring;
9860  else if ((BTEST1(17)) || (BTEST1(18)))
9861  strat->posInL = posInL17Ring;
9862  if (BTEST1(11))
9863  strat->posInT = posInT11Ring;
9864  else if (BTEST1(13))
9865  strat->posInT = posInT13;
9866  else if (BTEST1(15))
9867  strat->posInT = posInT15Ring;
9868  else if ((BTEST1(17)))
9869  strat->posInT = posInT17Ring;
9870  else if ((BTEST1(19)))
9871  strat->posInT = posInT19;
9872  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9873  strat->posInT = posInT1;
9875 }
9876 #endif
9877 
9878 void initBuchMora (ideal F,ideal Q,kStrategy strat)
9879 {
9880  strat->interpt = BTEST1(OPT_INTERRUPT);
9881  strat->kHEdge=NULL;
9883  /*- creating temp data structures------------------- -*/
9884  strat->cp = 0;
9885  strat->c3 = 0;
9886  strat->tail = pInit();
9887  /*- set s -*/
9888  strat->sl = -1;
9889  /*- set L -*/
9890  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9891  strat->Ll = -1;
9892  strat->L = initL(strat->Lmax);
9893  /*- set B -*/
9894  strat->Bmax = setmaxL;
9895  strat->Bl = -1;
9896  strat->B = initL();
9897  /*- set T -*/
9898  strat->tl = -1;
9899  strat->tmax = setmaxT;
9900  strat->T = initT();
9901  strat->R = initR();
9902  strat->sevT = initsevT();
9903  /*- init local data struct.---------------------------------------- -*/
9904  strat->P.ecart=0;
9905  strat->P.length=0;
9906  strat->P.pLength=0;
9908  {
9909  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
9910  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
9911  }
9913  {
9914  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9915  }
9916  else
9917  {
9918  if(TEST_OPT_SB_1)
9919  {
9920  int i;
9921  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
9922  for (i=strat->newIdeal;i<IDELEMS(F);i++)
9923  {
9924  P->m[i-strat->newIdeal] = F->m[i];
9925  F->m[i] = NULL;
9926  }
9927  initSSpecial(F,Q,P,strat);
9928  for (i=strat->newIdeal;i<IDELEMS(F);i++)
9929  {
9930  F->m[i] = P->m[i-strat->newIdeal];
9931  P->m[i-strat->newIdeal] = NULL;
9932  }
9933  idDelete(&P);
9934  }
9935  else
9936  {
9937  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9938  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
9939  }
9940  }
9941  strat->fromT = FALSE;
9943  if ((!TEST_OPT_SB_1)
9944  || (rField_is_Ring(currRing))
9945  )
9946  {
9947  updateS(TRUE,strat);
9948  }
9949  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9950  strat->fromQ=NULL;
9951  assume(kTest_TS(strat));
9952 }
9953 
9954 void exitBuchMora (kStrategy strat)
9955 {
9956  /*- release temp data -*/
9957  cleanT(strat);
9958  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
9959  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
9960  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
9961  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
9962  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
9963  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
9964  /*- set L: should be empty -*/
9965  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
9966  /*- set B: should be empty -*/
9967  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
9968  pLmFree(&strat->tail);
9969  strat->syzComp=0;
9970 }
9971 
9972 void initSbaPos (kStrategy strat)
9973 {
9975  {
9976  if (strat->honey)
9977  {
9978  strat->posInL = posInL15;
9979  // ok -- here is the deal: from my experiments for Singular-2-0
9980  // I conclude that that posInT_EcartpLength is the best of
9981  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9982  // see the table at the end of this file
9983  if (TEST_OPT_OLDSTD)
9984  strat->posInT = posInT15;
9985  else
9986  strat->posInT = posInT_EcartpLength;
9987  }
9988  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9989  {
9990  strat->posInL = posInL11;
9991  strat->posInT = posInT11;
9992  }
9993  else if (TEST_OPT_INTSTRATEGY)
9994  {
9995  strat->posInL = posInL11;
9996  strat->posInT = posInT11;
9997  }
9998  else
9999  {
10000  strat->posInL = posInL0;
10001  strat->posInT = posInT0;
10002  }
10003  //if (strat->minim>0) strat->posInL =posInLSpecial;
10004  if (strat->homog)
10005  {
10006  strat->posInL = posInL110;
10007  strat->posInT = posInT110;
10008  }
10009  }
10010  else
10011  {
10012  if (strat->homog)
10013  {
10014  strat->posInL = posInL11;
10015  strat->posInT = posInT11;
10016  }
10017  else
10018  {
10019  if ((currRing->order[0]==ringorder_c)
10020  ||(currRing->order[0]==ringorder_C))
10021  {
10022  strat->posInL = posInL17_c;
10023  strat->posInT = posInT17_c;
10024  }
10025  else
10026  {
10027  strat->posInL = posInL17;
10028  strat->posInT = posInT17;
10029  }
10030  }
10031  }
10032  if (strat->minim>0) strat->posInL =posInLSpecial;
10033  // for further tests only
10034  if ((BTEST1(11)) || (BTEST1(12)))
10035  strat->posInL = posInL11;
10036  else if ((BTEST1(13)) || (BTEST1(14)))
10037  strat->posInL = posInL13;
10038  else if ((BTEST1(15)) || (BTEST1(16)))
10039  strat->posInL = posInL15;
10040  else if ((BTEST1(17)) || (BTEST1(18)))
10041  strat->posInL = posInL17;
10042  if (BTEST1(11))
10043  strat->posInT = posInT11;
10044  else if (BTEST1(13))
10045  strat->posInT = posInT13;
10046  else if (BTEST1(15))
10047  strat->posInT = posInT15;
10048  else if ((BTEST1(17)))
10049  strat->posInT = posInT17;
10050  else if ((BTEST1(19)))
10051  strat->posInT = posInT19;
10052  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10053  strat->posInT = posInT1;
10054  if (rField_is_Ring(currRing))
10055  {
10056  strat->posInL = posInL11Ring;
10057  if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
10058  strat->posInL = posInL11Ringls;
10059  strat->posInT = posInT11;
10060  }
10061  strat->posInLDependsOnLength = FALSE;
10062  strat->posInLSba = posInLSig;
10063  //strat->posInL = posInLSig;
10064  strat->posInL = posInLF5C;
10065  /*
10066  if (rField_is_Ring(currRing))
10067  {
10068  strat->posInLSba = posInLSigRing;
10069  strat->posInL = posInL11Ring;
10070  }*/
10071  //strat->posInT = posInTSig;
10072 }
10073 
10074 void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10075 {
10076  strat->interpt = BTEST1(OPT_INTERRUPT);
10077  strat->kHEdge=NULL;
10079  /*- creating temp data structures------------------- -*/
10080  strat->cp = 0;
10081  strat->c3 = 0;
10082  strat->tail = pInit();
10083  /*- set s -*/
10084  strat->sl = -1;
10085  /*- set ps -*/
10086  strat->syzl = -1;
10087  /*- set L -*/
10088  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10089  strat->Ll = -1;
10090  strat->L = initL(strat->Lmax);
10091  /*- set B -*/
10092  strat->Bmax = setmaxL;
10093  strat->Bl = -1;
10094  strat->B = initL();
10095  /*- set T -*/
10096  strat->tl = -1;
10097  strat->tmax = setmaxT;
10098  strat->T = initT();
10099  strat->R = initR();
10100  strat->sevT = initsevT();
10101  /*- init local data struct.---------------------------------------- -*/
10102  strat->P.ecart=0;
10103  strat->P.length=0;
10105  {
10106  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
10107  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
10108  }
10110  {
10111  /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10112  }
10113  else
10114  {
10115  if(TEST_OPT_SB_1)
10116  {
10117  int i;
10118  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10119  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10120  {
10121  P->m[i-strat->newIdeal] = F->m[i];
10122  F->m[i] = NULL;
10123  }
10124  initSSpecialSba(F,Q,P,strat);
10125  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10126  {
10127  F->m[i] = P->m[i-strat->newIdeal];
10128  P->m[i-strat->newIdeal] = NULL;
10129  }
10130  idDelete(&P);
10131  }
10132  else
10133  {
10134  initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10135  }
10136  }
10137  strat->fromT = FALSE;
10138  if (!TEST_OPT_SB_1)
10139  {
10141  }
10142  //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10143  //strat->fromQ=NULL;
10144  assume(kTest_TS(strat));
10145 }
10146 
10147 void exitSba (kStrategy strat)
10148 {
10149  /*- release temp data -*/
10151  cleanTSbaRing(strat);
10152  else
10153  cleanT(strat);
10154  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10155  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10156  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10157  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10158  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10159  omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10160  if(strat->syzmax>0)
10161  {
10162  omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10163  omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10164  if (strat->sbaOrder == 1)
10165  {
10166  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10167  }
10168  }
10169  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10170  /*- set L: should be empty -*/
10171  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10172  /*- set B: should be empty -*/
10173  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10174  /*- set sig: no need for the signatures anymore -*/
10175  omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10176  pLmDelete(&strat->tail);
10177  strat->syzComp=0;
10178 }
10179 
10180 /*2
10181 * in the case of a standardbase of a module over a qring:
10182 * replace polynomials in i by ak vectors,
10183 * (the polynomial * unit vectors gen(1)..gen(ak)
10184 * in every case (also for ideals:)
10185 * deletes divisible vectors/polynomials
10186 */
10187 void updateResult(ideal r,ideal Q, kStrategy strat)
10188 {
10189  int l;
10190  if (strat->ak>0)
10191  {
10192  for (l=IDELEMS(r)-1;l>=0;l--)
10193  {
10194  if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10195  {
10196  pDelete(&r->m[l]); // and set it to NULL
10197  }
10198  }
10199  int q;
10200  poly p;
10201  if(!rField_is_Ring(currRing))
10202  {
10203  for (l=IDELEMS(r)-1;l>=0;l--)
10204  {
10205  if ((r->m[l]!=NULL)
10206  //&& (strat->syzComp>0)
10207  //&& (pGetComp(r->m[l])<=strat->syzComp)
10208  )
10209  {
10210  for(q=IDELEMS(Q)-1; q>=0;q--)
10211  {
10212  if ((Q->m[q]!=NULL)
10213  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10214  {
10215  if (TEST_OPT_REDSB)
10216  {
10217  p=r->m[l];
10218  r->m[l]=kNF(Q,NULL,p);
10219  pDelete(&p);
10220  }
10221  else
10222  {
10223  pDelete(&r->m[l]); // and set it to NULL
10224  }
10225  break;
10226  }
10227  }
10228  }
10229  }
10230  }
10231  #ifdef HAVE_RINGS
10232  else
10233  {
10234  for (l=IDELEMS(r)-1;l>=0;l--)
10235  {
10236  if ((r->m[l]!=NULL)
10237  //&& (strat->syzComp>0)
10238  //&& (pGetComp(r->m[l])<=strat->syzComp)
10239  )
10240  {
10241  for(q=IDELEMS(Q)-1; q>=0;q--)
10242  {
10243  if ((Q->m[q]!=NULL)
10244  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10245  {
10246  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10247  {
10248  if (TEST_OPT_REDSB)
10249  {
10250  p=r->m[l];
10251  r->m[l]=kNF(Q,NULL,p);
10252  pDelete(&p);
10253  }
10254  else
10255  {
10256  pDelete(&r->m[l]); // and set it to NULL
10257  }
10258  break;
10259  }
10260  }
10261  }
10262  }
10263  }
10264  }
10265  #endif
10266  }
10267  else
10268  {
10269  int q;
10270  poly p;
10271  BOOLEAN reduction_found=FALSE;
10272  if (!rField_is_Ring(currRing))
10273  {
10274  for (l=IDELEMS(r)-1;l>=0;l--)
10275  {
10276  if (r->m[l]!=NULL)
10277  {
10278  for(q=IDELEMS(Q)-1; q>=0;q--)
10279  {
10280  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10281  {
10282  if (TEST_OPT_REDSB)
10283  {
10284  p=r->m[l];
10285  r->m[l]=kNF(Q,NULL,p);
10286  pDelete(&p);
10287  reduction_found=TRUE;
10288  }
10289  else
10290  {
10291  pDelete(&r->m[l]); // and set it to NULL
10292  }
10293  break;
10294  }
10295  }
10296  }
10297  }
10298  }
10299  #ifdef HAVE_RINGS
10300  //Also need divisibility of the leading coefficients
10301  else
10302  {
10303  for (l=IDELEMS(r)-1;l>=0;l--)
10304  {
10305  if (r->m[l]!=NULL)
10306  {
10307  for(q=IDELEMS(Q)-1; q>=0;q--)
10308  {
10309  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10310  {
10311  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10312  {
10313  if (TEST_OPT_REDSB)
10314  {
10315  p=r->m[l];
10316  r->m[l]=kNF(Q,NULL,p);
10317  pDelete(&p);
10318  reduction_found=TRUE;
10319  }
10320  else
10321  {
10322  pDelete(&r->m[l]); // and set it to NULL
10323  }
10324  break;
10325  }
10326  }
10327  }
10328  }
10329  }
10330  }
10331  #endif
10332  if (/*TEST_OPT_REDSB &&*/ reduction_found)
10333  {
10334  #ifdef HAVE_RINGS
10336  {
10337  for (l=IDELEMS(r)-1;l>=0;l--)
10338  {
10339  if (r->m[l]!=NULL)
10340  {
10341  for(q=IDELEMS(r)-1;q>=0;q--)
10342  {
10343  if ((l!=q)
10344  && (r->m[q]!=NULL)
10345  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10346  &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10347  )
10348  {
10349  //If they are equal then take the one with the smallest length
10350  if(pLmDivisibleBy(r->m[q],r->m[l])
10351  && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10352  && (pLength(r->m[q]) < pLength(r->m[l]) ||
10353  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10354  {
10355  pDelete(&r->m[l]);
10356  break;
10357  }
10358  else
10359  pDelete(&r->m[q]);
10360  }
10361  }
10362  }
10363  }
10364  }
10365  else
10366  #endif
10367  {
10368  for (l=IDELEMS(r)-1;l>=0;l--)
10369  {
10370  if (r->m[l]!=NULL)
10371  {
10372  for(q=IDELEMS(r)-1;q>=0;q--)
10373  {
10374  if ((l!=q)
10375  && (r->m[q]!=NULL)
10376  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10377  )
10378  {
10379  //If they are equal then take the one with the smallest length
10380  if(pLmDivisibleBy(r->m[q],r->m[l])
10381  &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10382  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10383  {
10384  pDelete(&r->m[l]);
10385  break;
10386  }
10387  else
10388  pDelete(&r->m[q]);
10389  }
10390  }
10391  }
10392  }
10393  }
10394  }
10395  }
10396  idSkipZeroes(r);
10397 }
10398 
10399 void completeReduce (kStrategy strat, BOOLEAN withT)
10400 {
10401  int i;
10402  int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10403  LObject L;
10404 
10405 #ifdef KDEBUG
10406  // need to set this: during tailreductions of T[i], T[i].max is out of
10407  // sync
10408  sloppy_max = TRUE;
10409 #endif
10410 
10411  strat->noTailReduction = FALSE;
10412  //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10413  if (TEST_OPT_PROT)
10414  {
10415  PrintLn();
10416 // if (timerv) writeTime("standard base computed:");
10417  }
10418  if (TEST_OPT_PROT)
10419  {
10420  Print("(S:%d)",strat->sl);mflush();
10421  }
10422  for (i=strat->sl; i>=low; i--)
10423  {
10424  int end_pos=strat->sl;
10425  if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10426  if (strat->ak==0) end_pos=i-1;
10427  TObject* T_j = strat->s_2_t(i);
10428  if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10429  {
10430  L = *T_j;
10431  #ifdef KDEBUG
10432  if (TEST_OPT_DEBUG)
10433  {
10434  Print("test S[%d]:",i);
10435  p_wrp(L.p,currRing,strat->tailRing);
10436  PrintLn();
10437  }
10438  #endif
10440  strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10441  else
10442  strat->S[i] = redtail(&L, strat->sl, strat);
10443  #ifdef KDEBUG
10444  if (TEST_OPT_DEBUG)
10445  {
10446  Print("to (tailR) S[%d]:",i);
10447  p_wrp(strat->S[i],currRing,strat->tailRing);
10448  PrintLn();
10449  }
10450  #endif
10451 
10452  if (strat->redTailChange)
10453  {
10454  if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10455  if (pNext(T_j->p) != NULL)
10456  T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10457  else
10458  T_j->max_exp = NULL;
10459  }
10461  T_j->pCleardenom();
10462  }
10463  else
10464  {
10465  assume(currRing == strat->tailRing);
10466  #ifdef KDEBUG
10467  if (TEST_OPT_DEBUG)
10468  {
10469  Print("test S[%d]:",i);
10470  p_wrp(strat->S[i],currRing,strat->tailRing);
10471  PrintLn();
10472  }
10473  #endif
10475  strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10476  else
10477  strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10479  {
10480  if (TEST_OPT_CONTENTSB)
10481  {
10482  number n;
10483  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10484  if (!nIsOne(n))
10485  {
10487  denom->n=nInvers(n);
10488  denom->next=DENOMINATOR_LIST;
10489  DENOMINATOR_LIST=denom;
10490  }
10491  nDelete(&n);
10492  }
10493  else
10494  {
10495  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10496  }
10497  }
10498  #ifdef KDEBUG
10499  if (TEST_OPT_DEBUG)
10500  {
10501  Print("to (-tailR) S[%d]:",i);
10502  p_wrp(strat->S[i],currRing,strat->tailRing);
10503  PrintLn();
10504  }
10505  #endif
10506  }
10507  if (TEST_OPT_PROT)
10508  PrintS("-");
10509  }
10510  if (TEST_OPT_PROT) PrintLn();
10511 #ifdef KDEBUG
10512  sloppy_max = FALSE;
10513 #endif
10515 
10516 
10517 /*2
10518 * computes the new strat->kHEdge and the new pNoether,
10519 * returns TRUE, if pNoether has changed
10520 */
10521 BOOLEAN newHEdge(kStrategy strat)
10522 {
10523  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10524  return FALSE;
10525  int i,j;
10526  poly newNoether;
10527 
10528 #if 0
10529  if (currRing->weight_all_1)
10530  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10531  else
10532  scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10533 #else
10534  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10535 #endif
10536  if (strat->kHEdge==NULL) return FALSE;
10537  if (strat->t_kHEdge != NULL) p_LmFree(strat->t_kHEdge, strat->tailRing);
10538  if (strat->tailRing != currRing)
10539  strat->t_kHEdge = k_LmInit_currRing_2_tailRing(strat->kHEdge, strat->tailRing);
10540  /* compare old and new noether*/
10541  newNoether = pLmInit(strat->kHEdge);
10542  pSetCoeff0(newNoether,nInit(1));
10543  j = p_FDeg(newNoether,currRing);
10544  for (i=1; i<=(currRing->N); i++)
10545  {
10546  if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
10547  }
10548  pSetm(newNoether);
10549  if (j < strat->HCord) /*- statistics -*/
10550  {
10551  if (TEST_OPT_PROT)
10552  {
10553  Print("H(%d)",j);
10554  mflush();
10555  }
10556  strat->HCord=j;
10557  #ifdef KDEBUG
10558  if (TEST_OPT_DEBUG)
10559  {
10560  Print("H(%d):",j);
10561  wrp(strat->kHEdge);
10562  PrintLn();
10563  }
10564  #endif
10565  }
10566  if (pCmp(strat->kNoether,newNoether)!=1)
10567  {
10568  if (strat->kNoether!=NULL) pLmDelete(&strat->kNoether);
10569  strat->kNoether=newNoether;
10570  if (strat->t_kNoether != NULL) p_LmFree(strat->t_kNoether, strat->tailRing);
10571  if (strat->tailRing != currRing)
10572  strat->t_kNoether = k_LmInit_currRing_2_tailRing(strat->kNoether, strat->tailRing);
10573 
10574  return TRUE;
10575  }
10576  pLmDelete(newNoether);
10577  return FALSE;
10578 }
10579 
10580 /***************************************************************
10581  *
10582  * Routines related for ring changes during std computations
10583  *
10584  ***************************************************************/
10585 BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10586 {
10587  if (strat->overflow) return FALSE;
10588  assume(L->p1 != NULL && L->p2 != NULL);
10589  // shift changes: from 0 to -1
10590  assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10591  assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10592  assume(strat->tailRing != currRing);
10593 
10594  if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10595  return FALSE;
10596  // shift changes: extra case inserted
10597  if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10598  {
10599  return TRUE;
10600  }
10601  poly p1_max = (strat->R[L->i_r1])->max_exp;
10602  poly p2_max = (strat->R[L->i_r2])->max_exp;
10603 
10604  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10605  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10606  {
10607  p_LmFree(m1, strat->tailRing);
10608  p_LmFree(m2, strat->tailRing);
10609  m1 = NULL;
10610  m2 = NULL;
10611  return FALSE;
10612  }
10613  return TRUE;
10615 
10616 #ifdef HAVE_RINGS
10617 /***************************************************************
10618  *
10619  * Checks, if we can compute the gcd poly / strong pair
10620  * gcd-poly = m1 * R[atR] + m2 * S[atS]
10621  *
10622  ***************************************************************/
10623 BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10624 {
10625  assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10626  //assume(strat->tailRing != currRing);
10627 
10628  poly p1_max = (strat->R[atR])->max_exp;
10629  poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10630 
10631  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10632  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10633  {
10634  return FALSE;
10635  }
10636  return TRUE;
10638 #endif
10639 
10640 #ifdef HAVE_RINGS
10641 /*!
10642  used for GB over ZZ: look for constant and monomial elements in the ideal
10643  background: any known constant element of ideal suppresses
10644  intermediate coefficient swell
10645 */
10646 poly preIntegerCheck(const ideal Forig, const ideal Q)
10647 {
10649  if(!nCoeff_is_Ring_Z(currRing->cf))
10650  return NULL;
10651  ideal F = idCopy(Forig);
10652  idSkipZeroes(F);
10653  poly pmon;
10654  ring origR = currRing;
10655  ideal monred = idInit(1,1);
10656  for(int i=0; i<idElem(F); i++)
10657  {
10658  if(pNext(F->m[i]) == NULL)
10659  idInsertPoly(monred, pCopy(F->m[i]));
10660  }
10661  int posconst = idPosConstant(F);
10662  if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10663  {
10664  idDelete(&F);
10665  idDelete(&monred);
10666  return NULL;
10667  }
10668  int idelemQ = 0;
10669  if(Q!=NULL)
10670  {
10671  idelemQ = IDELEMS(Q);
10672  for(int i=0; i<idelemQ; i++)
10673  {
10674  if(pNext(Q->m[i]) == NULL)
10675  idInsertPoly(monred, pCopy(Q->m[i]));
10676  }
10677  idSkipZeroes(monred);
10678  posconst = idPosConstant(monred);
10679  //the constant, if found, will be from Q
10680  if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10681  {
10682  pmon = pCopy(monred->m[posconst]);
10683  idDelete(&F);
10684  idDelete(&monred);
10685  return pmon;
10686  }
10687  }
10688  ring QQ_ring = rCopy0(currRing,FALSE);
10689  nKillChar(QQ_ring->cf);
10690  QQ_ring->cf = nInitChar(n_Q, NULL);
10691  rComplete(QQ_ring,1);
10692  QQ_ring = rAssure_c_dp(QQ_ring);
10693  rChangeCurrRing(QQ_ring);
10694  nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10695  ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10696  for(int i = 0, j = 0; i<IDELEMS(F); i++)
10697  II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10698  for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10699  II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10700  ideal one = kStd(II, NULL, isNotHomog, NULL);
10701  idSkipZeroes(one);
10702  if(idIsConstant(one))
10703  {
10704  //one should be <1>
10705  for(int i = IDELEMS(II)-1; i>=0; i--)
10706  if(II->m[i] != NULL)
10707  II->m[i+1] = II->m[i];
10708  II->m[0] = pOne();
10709  ideal syz = idSyzygies(II, isNotHomog, NULL);
10710  poly integer = NULL;
10711  for(int i = IDELEMS(syz)-1;i>=0; i--)
10712  {
10713  if(pGetComp(syz->m[i]) == 1)
10714  {
10715  pSetComp(syz->m[i],0);
10716  if(pIsConstant(pHead(syz->m[i])))
10717  {
10718  integer = pHead(syz->m[i]);
10719  break;
10720  }
10721  }
10722  }
10723  rChangeCurrRing(origR);
10724  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10725  pmon = prMapR(integer, nMap2, QQ_ring, origR);
10726  idDelete(&monred);
10727  idDelete(&F);
10728  id_Delete(&II,QQ_ring);
10729  id_Delete(&one,QQ_ring);
10730  id_Delete(&syz,QQ_ring);
10731  p_Delete(&integer,QQ_ring);
10732  rDelete(QQ_ring);
10733  return pmon;
10734  }
10735  else
10736  {
10737  if(idIs0(monred))
10738  {
10739  poly mindegmon = NULL;
10740  for(int i = 0; i<IDELEMS(one); i++)
10741  {
10742  if(pNext(one->m[i]) == NULL)
10743  {
10744  if(mindegmon == NULL)
10745  mindegmon = pCopy(one->m[i]);
10746  else
10747  {
10748  if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10749  mindegmon = pCopy(one->m[i]);
10750  }
10751  }
10752  }
10753  if(mindegmon != NULL)
10754  {
10755  for(int i = IDELEMS(II)-1; i>=0; i--)
10756  if(II->m[i] != NULL)
10757  II->m[i+1] = II->m[i];
10758  II->m[0] = pCopy(mindegmon);
10759  ideal syz = idSyzygies(II, isNotHomog, NULL);
10760  bool found = FALSE;
10761  for(int i = IDELEMS(syz)-1;i>=0; i--)
10762  {
10763  if(pGetComp(syz->m[i]) == 1)
10764  {
10765  pSetComp(syz->m[i],0);
10766  if(pIsConstant(pHead(syz->m[i])))
10767  {
10768  pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10769  found = TRUE;
10770  break;
10771  }
10772  }
10773  }
10774  id_Delete(&syz,QQ_ring);
10775  if (found == FALSE)
10776  {
10777  rChangeCurrRing(origR);
10778  idDelete(&monred);
10779  idDelete(&F);
10780  id_Delete(&II,QQ_ring);
10781  id_Delete(&one,QQ_ring);
10782  rDelete(QQ_ring);
10783  return NULL;
10784  }
10785  rChangeCurrRing(origR);
10786  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10787  pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
10788  idDelete(&monred);
10789  idDelete(&F);
10790  id_Delete(&II,QQ_ring);
10791  id_Delete(&one,QQ_ring);
10792  id_Delete(&syz,QQ_ring);
10793  rDelete(QQ_ring);
10794  return pmon;
10795  }
10796  }
10797  }
10798  rChangeCurrRing(origR);
10799  idDelete(&monred);
10800  idDelete(&F);
10801  id_Delete(&II,QQ_ring);
10802  id_Delete(&one,QQ_ring);
10803  rDelete(QQ_ring);
10804  return NULL;
10806 #endif
10807 
10808 #ifdef HAVE_RINGS
10809 /*!
10810  used for GB over ZZ: intermediate reduction by monomial elements
10811  background: any known constant element of ideal suppresses
10812  intermediate coefficient swell
10813 */
10814 void postReduceByMon(LObject* h, kStrategy strat)
10815 {
10816  if(!nCoeff_is_Ring_Z(currRing->cf))
10817  return;
10818  poly pH = h->GetP();
10819  poly p,pp;
10820  p = pH;
10821  bool deleted = FALSE, ok = FALSE;
10822  for(int i = 0; i<=strat->sl; i++)
10823  {
10824  p = pH;
10825  if(pNext(strat->S[i]) == NULL)
10826  {
10827  //pWrite(p);
10828  //pWrite(strat->S[i]);
10829  while(ok == FALSE && p != NULL)
10830  {
10831  if(pLmDivisibleBy(strat->S[i], p))
10832  {
10833  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10834  p_SetCoeff(p,dummy,currRing);
10835  }
10836  if(nIsZero(p->coef))
10837  {
10838  pLmDelete(&p);
10839  h->p = p;
10840  deleted = TRUE;
10841  }
10842  else
10843  {
10844  ok = TRUE;
10845  }
10846  }
10847  if (p!=NULL)
10848  {
10849  pp = pNext(p);
10850  while(pp != NULL)
10851  {
10852  if(pLmDivisibleBy(strat->S[i], pp))
10853  {
10854  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10855  p_SetCoeff(pp,dummy,currRing);
10856  if(nIsZero(pp->coef))
10857  {
10858  pLmDelete(&pNext(p));
10859  pp = pNext(p);
10860  deleted = TRUE;
10861  }
10862  else
10863  {
10864  p = pp;
10865  pp = pNext(p);
10866  }
10867  }
10868  else
10869  {
10870  p = pp;
10871  pp = pNext(p);
10872  }
10873  }
10874  }
10875  }
10876  }
10877  h->SetLmCurrRing();
10878  if((deleted)&&(h->p!=NULL))
10879  strat->initEcart(h);
10880 }
10881 
10882 void postReduceByMonSig(LObject* h, kStrategy strat)
10883 {
10884  if(!nCoeff_is_Ring_Z(currRing->cf))
10885  return;
10886  poly hSig = h->sig;
10887  poly pH = h->GetP();
10888  poly p,pp;
10889  p = pH;
10890  bool deleted = FALSE, ok = FALSE;
10891  for(int i = 0; i<=strat->sl; i++)
10892  {
10893  p = pH;
10894  if(pNext(strat->S[i]) == NULL)
10895  {
10896  while(ok == FALSE && p!=NULL)
10897  {
10898  if(pLmDivisibleBy(strat->S[i], p))
10899  {
10900  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10901  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10902  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10903  {
10904  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10905  p_SetCoeff(p,dummy,currRing);
10906  }
10907  pDelete(&sigMult);
10908  }
10909  if(nIsZero(p->coef))
10910  {
10911  pLmDelete(&p);
10912  h->p = p;
10913  deleted = TRUE;
10914  }
10915  else
10916  {
10917  ok = TRUE;
10918  }
10919  }
10920  if(p == NULL)
10921  return;
10922  pp = pNext(p);
10923  while(pp != NULL)
10924  {
10925  if(pLmDivisibleBy(strat->S[i], pp))
10926  {
10927  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10928  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10929  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10930  {
10931  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10932  p_SetCoeff(pp,dummy,currRing);
10933  if(nIsZero(pp->coef))
10934  {
10935  pLmDelete(&pNext(p));
10936  pp = pNext(p);
10937  deleted = TRUE;
10938  }
10939  else
10940  {
10941  p = pp;
10942  pp = pNext(p);
10943  }
10944  }
10945  else
10946  {
10947  p = pp;
10948  pp = pNext(p);
10949  }
10950  pDelete(&sigMult);
10951  }
10952  else
10953  {
10954  p = pp;
10955  pp = pNext(p);
10956  }
10957  }
10958  }
10959  }
10960  h->SetLmCurrRing();
10961  if(deleted)
10962  strat->initEcart(h);
10963 
10964 }
10965 
10966 /*!
10967  used for GB over ZZ: final reduction by constant elements
10968  background: any known constant element of ideal suppresses
10969  intermediate coefficient swell and beautifies output
10970 */
10971 void finalReduceByMon(kStrategy strat)
10972 {
10973  if(!nCoeff_is_Ring_Z(currRing->cf))
10974  return;
10975  poly p,pp;
10976  for(int j = 0; j<=strat->sl; j++)
10977  {
10978  if((strat->S[j]!=NULL)&&(pNext(strat->S[j]) == NULL))
10979  {
10980  for(int i = 0; i<=strat->sl; i++)
10981  {
10982  if((i != j) && (strat->S[i] != NULL))
10983  {
10984  p = strat->S[i];
10985  if(pLmDivisibleBy(strat->S[j], p))
10986  {
10987  number dummy = n_IntMod(p->coef, strat->S[j]->coef, currRing->cf);
10988  p_SetCoeff(p,dummy,currRing);
10989  }
10990  pp = pNext(p);
10991  if((pp == NULL) && (nIsZero(p->coef)))
10992  {
10993  deleteInS(i, strat);
10994  }
10995  else
10996  {
10997  while(pp != NULL)
10998  {
10999  if(pLmDivisibleBy(strat->S[j], pp))
11000  {
11001  number dummy = n_IntMod(pp->coef, strat->S[j]->coef, currRing->cf);
11002  p_SetCoeff(pp,dummy,currRing);
11003  if(nIsZero(pp->coef))
11004  {
11005  pLmDelete(&pNext(p));
11006  pp = pNext(p);
11007  }
11008  else
11009  {
11010  p = pp;
11011  pp = pNext(p);
11012  }
11013  }
11014  else
11015  {
11016  p = pp;
11017  pp = pNext(p);
11018  }
11019  }
11020  }
11021  if(strat->S[i]!= NULL && nIsZero(pGetCoeff(strat->S[i])))
11022  {
11023  if(pNext(strat->S[i]) == NULL)
11024  strat->S[i]=NULL;
11025  else
11026  strat->S[i]=pNext(strat->S[i]);
11027  }
11028  }
11029  }
11030  //idPrint(strat->Shdl);
11031  }
11032  }
11033  //idSkipZeroes(strat->Shdl);
11034 }
11035 #endif
11036 
11037 BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
11038 {
11039  assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11040  /* initial setup or extending */
11041 
11042  if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11043  if (expbound >= currRing->bitmask) return FALSE;
11044  strat->overflow=FALSE;
11045  ring new_tailRing = rModifyRing(currRing,
11046  // Hmmm .. the condition pFDeg == p_Deg
11047  // might be too strong
11048  (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11049  (strat->ak==0), // omit_comp if the input is an ideal
11050  expbound); // exp_limit
11051 
11052  if (new_tailRing == currRing) return TRUE;
11053 
11054  strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11055  strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11056 
11057  if (currRing->pFDeg != currRing->pFDegOrig)
11058  {
11059  new_tailRing->pFDeg = currRing->pFDeg;
11060  new_tailRing->pLDeg = currRing->pLDeg;
11061  }
11062 
11063  if (TEST_OPT_PROT)
11064  Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11065  kTest_TS(strat);
11066  assume(new_tailRing != strat->tailRing);
11067  pShallowCopyDeleteProc p_shallow_copy_delete
11068  = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11069 
11070  omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11071 
11072  int i;
11073  for (i=0; i<=strat->tl; i++)
11074  {
11075  strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11076  p_shallow_copy_delete);
11077  }
11078  for (i=0; i<=strat->Ll; i++)
11079  {
11080  assume(strat->L[i].p != NULL);
11081  if (pNext(strat->L[i].p) != strat->tail)
11082  strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11083  }
11084  if ((strat->P.t_p != NULL) ||
11085  ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11086  strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11087 
11088  if ((L != NULL) && (L->tailRing != new_tailRing))
11089  {
11090  if (L->i_r < 0)
11091  L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11092  else
11093  {
11094  assume(L->i_r <= strat->tl);
11095  TObject* t_l = strat->R[L->i_r];
11096  assume(t_l != NULL);
11097  L->tailRing = new_tailRing;
11098  L->p = t_l->p;
11099  L->t_p = t_l->t_p;
11100  L->max_exp = t_l->max_exp;
11101  }
11102  }
11103 
11104  if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11105  T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11106 
11107  omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11108  if (strat->tailRing != currRing)
11109  rKillModifiedRing(strat->tailRing);
11110 
11111  strat->tailRing = new_tailRing;
11112  strat->tailBin = new_tailBin;
11113  strat->p_shallow_copy_delete
11114  = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11115 
11116  if (strat->kHEdge != NULL)
11117  {
11118  if (strat->t_kHEdge != NULL)
11119  p_LmFree(strat->t_kHEdge, strat->tailRing);
11120  strat->t_kHEdge=k_LmInit_currRing_2_tailRing(strat->kHEdge, new_tailRing);
11121  }
11122 
11123  if (strat->kNoether != NULL)
11124  {
11125  if (strat->t_kNoether != NULL)
11126  p_LmFree(strat->t_kNoether, strat->tailRing);
11128  new_tailRing);
11129  }
11130  kTest_TS(strat);
11131  if (TEST_OPT_PROT)
11132  PrintS("]");
11133  return TRUE;
11134 }
11135 
11137 {
11138  unsigned long l = 0;
11139  int i;
11140  long e;
11141 
11142  assume(strat->tailRing == currRing);
11143 
11144  for (i=0; i<= strat->Ll; i++)
11145  {
11146  l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11147  }
11148  for (i=0; i<=strat->tl; i++)
11149  {
11150  // Hmm ... this we could do in one Step
11151  l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11152  }
11153  if (rField_is_Ring(currRing))
11154  {
11155  l *= 2;
11156  }
11157  e = p_GetMaxExp(l, currRing);
11158  if (e <= 1) e = 2;
11159 
11160  kStratChangeTailRing(strat, NULL, NULL, e);
11161 }
11162 
11163 ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11164 {
11165  int n = rBlocks(r); // Including trailing zero!
11166  // if sbaOrder == 1 => use (C,monomial order from r)
11167  if (strat->sbaOrder == 1)
11168  {
11169  if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11170  {
11171  return r;
11172  }
11173  ring res = rCopy0(r, TRUE, FALSE);
11174  res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11175  res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11176  res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11177  int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11178  res->wvhdl = wvhdl;
11179  for (int i=1; i<n; i++)
11180  {
11181  res->order[i] = r->order[i-1];
11182  res->block0[i] = r->block0[i-1];
11183  res->block1[i] = r->block1[i-1];
11184  res->wvhdl[i] = r->wvhdl[i-1];
11185  }
11186 
11187  // new 1st block
11188  res->order[0] = ringorder_C; // Prefix
11189  // removes useless secondary component order if defined in old ring
11190  for (int i=rBlocks(res); i>0; --i)
11191  {
11192  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11193  {
11194  res->order[i] = (rRingOrder_t)0;
11195  }
11196  }
11197  rComplete(res, 1);
11198 #ifdef HAVE_PLURAL
11199  if (rIsPluralRing(r))
11200  {
11201  if ( nc_rComplete(r, res, false) ) // no qideal!
11202  {
11203 #ifndef SING_NDEBUG
11204  WarnS("error in nc_rComplete");
11205 #endif
11206  // cleanup?
11207 
11208  // rDelete(res);
11209  // return r;
11210 
11211  // just go on..
11212  }
11213  }
11214 #endif
11215  strat->tailRing = res;
11216  return (res);
11217  }
11218  // if sbaOrder == 3 => degree - position - ring order
11219  if (strat->sbaOrder == 3)
11220  {
11221  ring res = rCopy0(r, TRUE, FALSE);
11222  res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11223  res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11224  res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11225  int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11226  res->wvhdl = wvhdl;
11227  for (int i=2; i<n+2; i++)
11228  {
11229  res->order[i] = r->order[i-2];
11230  res->block0[i] = r->block0[i-2];
11231  res->block1[i] = r->block1[i-2];
11232  res->wvhdl[i] = r->wvhdl[i-2];
11233  }
11234 
11235  // new 1st block
11236  res->order[0] = ringorder_a; // Prefix
11237  res->block0[0] = 1;
11238  res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11239  for (int i=0; i<res->N; ++i)
11240  res->wvhdl[0][i] = 1;
11241  res->block1[0] = si_min(res->N, rVar(res));
11242  // new 2nd block
11243  res->order[1] = ringorder_C; // Prefix
11244  res->wvhdl[1] = NULL;
11245  // removes useless secondary component order if defined in old ring
11246  for (int i=rBlocks(res); i>1; --i)
11247  {
11248  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11249  {
11250  res->order[i] = (rRingOrder_t)0;
11251  }
11252  }
11253  rComplete(res, 1);
11254 #ifdef HAVE_PLURAL
11255  if (rIsPluralRing(r))
11256  {
11257  if ( nc_rComplete(r, res, false) ) // no qideal!
11258  {
11259 #ifndef SING_NDEBUG
11260  WarnS("error in nc_rComplete");
11261 #endif
11262  // cleanup?
11263 
11264  // rDelete(res);
11265  // return r;
11266 
11267  // just go on..
11268  }
11269  }
11270 #endif
11271  strat->tailRing = res;
11272  return (res);
11273  }
11274 
11275  // not sbaOrder == 1 => use Schreyer order
11276  // this is done by a trick when initializing the signatures
11277  // in initSLSba():
11278  // Instead of using the signature 1e_i for F->m[i], we start
11279  // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11280  // Schreyer order w.r.t. the underlying monomial order.
11281  // => we do not need to change the underlying polynomial ring at all!
11282 
11283  // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11284 
11285  /*
11286  else
11287  {
11288  ring res = rCopy0(r, FALSE, FALSE);
11289  // Create 2 more blocks for prefix/suffix:
11290  res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11291  res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11292  res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11293  int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11294 
11295  // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11296  // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11297 
11298  // new 1st block
11299  int j = 0;
11300  res->order[j] = ringorder_IS; // Prefix
11301  res->block0[j] = res->block1[j] = 0;
11302  // wvhdl[j] = NULL;
11303  j++;
11304 
11305  for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11306  {
11307  res->order [j] = r->order [i];
11308  res->block0[j] = r->block0[i];
11309  res->block1[j] = r->block1[i];
11310 
11311  if (r->wvhdl[i] != NULL)
11312  {
11313  wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11314  } // else wvhdl[j] = NULL;
11315  }
11316 
11317  // new last block
11318  res->order [j] = ringorder_IS; // Suffix
11319  res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11320  // wvhdl[j] = NULL;
11321  j++;
11322 
11323  // res->order [j] = 0; // The End!
11324  res->wvhdl = wvhdl;
11325 
11326  // j == the last zero block now!
11327  assume(j == (n+1));
11328  assume(res->order[0]==ringorder_IS);
11329  assume(res->order[j-1]==ringorder_IS);
11330  assume(res->order[j]==0);
11331 
11332  if (complete)
11333  {
11334  rComplete(res, 1);
11335 
11336 #ifdef HAVE_PLURAL
11337  if (rIsPluralRing(r))
11338  {
11339  if ( nc_rComplete(r, res, false) ) // no qideal!
11340  {
11341  }
11342  }
11343  assume(rIsPluralRing(r) == rIsPluralRing(res));
11344 #endif
11345 
11346 
11347 #ifdef HAVE_PLURAL
11348  ring old_ring = r;
11349 
11350 #endif
11351 
11352  if (r->qideal!=NULL)
11353  {
11354  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11355 
11356  assume(idRankFreeModule(res->qideal, res) == 0);
11357 
11358 #ifdef HAVE_PLURAL
11359  if( rIsPluralRing(res) )
11360  if( nc_SetupQuotient(res, r, true) )
11361  {
11362  // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11363  }
11364 
11365 #endif
11366  assume(idRankFreeModule(res->qideal, res) == 0);
11367  }
11368 
11369 #ifdef HAVE_PLURAL
11370  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11371  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11372  assume(rIsSCA(res) == rIsSCA(old_ring));
11373  assume(ncRingType(res) == ncRingType(old_ring));
11374 #endif
11375  }
11376  strat->tailRing = res;
11377  return res;
11378  }
11379  */
11380 
11381  assume(FALSE);
11382  return(NULL);
11383 }
11384 
11386 {
11387  memset(this, 0, sizeof(skStrategy));
11388  strat_nr++;
11389  nr=strat_nr;
11390  tailRing = currRing;
11391  P.tailRing = currRing;
11392  tl = -1;
11393  sl = -1;
11394 #ifdef HAVE_LM_BIN
11395  lmBin = omGetStickyBinOfBin(currRing->PolyBin);
11396 #endif
11397 #ifdef HAVE_TAIL_BIN
11398  tailBin = omGetStickyBinOfBin(currRing->PolyBin);
11399 #endif
11400  pOrigFDeg = currRing->pFDeg;
11401  pOrigLDeg = currRing->pLDeg;
11402 }
11403 
11404 
11406 {
11407  if (lmBin != NULL)
11409  if (tailBin != NULL)// && !rField_is_Ring(currRing))
11411  (tailRing != NULL ? tailRing->PolyBin:
11412  currRing->PolyBin));
11413  if (t_kHEdge != NULL)
11415  if (t_kNoether != NULL)
11417 
11418  if (currRing != tailRing)
11421 }
11422 
11423 #if 0
11424 Timings for the different possibilities of posInT:
11425  T15 EDL DL EL L 1-2-3
11426 Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11427 Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11428 Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11429 ahml 4.48 4.03 4.03 4.38 4.96 26.50
11430 c7 15.02 13.98 15.16 13.24 17.31 47.89
11431 c8 505.09 407.46 852.76 413.21 499.19 n/a
11432 f855 12.65 9.27 14.97 8.78 14.23 33.12
11433 gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11434 gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11435 ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11436 noon8 40.68 37.02 37.99 36.82 35.59 877.16
11437 rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11438 rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11439 schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11440 test016 16.39 14.17 14.40 13.50 14.26 34.07
11441 test017 34.70 36.01 33.16 35.48 32.75 71.45
11442 test042 10.76 10.99 10.27 11.57 10.45 23.04
11443 test058 6.78 6.75 6.51 6.95 6.22 9.47
11444 test066 10.71 10.94 10.76 10.61 10.56 19.06
11445 test073 10.75 11.11 10.17 10.79 8.63 58.10
11446 test086 12.23 11.81 12.88 12.24 13.37 66.68
11447 test103 5.05 4.80 5.47 4.64 4.89 11.90
11448 test154 12.96 11.64 13.51 12.46 14.61 36.35
11449 test162 65.27 64.01 67.35 59.79 67.54 196.46
11450 test164 7.50 6.50 7.68 6.70 7.96 17.13
11451 virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11452 #endif
11453 
11454 
11455 //#ifdef HAVE_MORE_POS_IN_T
11456 #if 1
11457 // determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11458 int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p)
11459 {
11460 
11461  if (length==-1) return 0;
11462 
11463  int o = p.ecart;
11464  int op=p.GetpFDeg();
11465  int ol = p.GetpLength();
11466 
11467  if (set[length].ecart < o)
11468  return length+1;
11469  if (set[length].ecart == o)
11470  {
11471  int oo=set[length].GetpFDeg();
11472  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11473  return length+1;
11474  }
11475 
11476  int i;
11477  int an = 0;
11478  int en= length;
11479  loop
11480  {
11481  if (an >= en-1)
11482  {
11483  if (set[an].ecart > o)
11484  return an;
11485  if (set[an].ecart == o)
11486  {
11487  int oo=set[an].GetpFDeg();
11488  if((oo > op)
11489  || ((oo==op) && (set[an].pLength > ol)))
11490  return an;
11491  }
11492  return en;
11493  }
11494  i=(an+en) / 2;
11495  if (set[i].ecart > o)
11496  en=i;
11497  else if (set[i].ecart == o)
11498  {
11499  int oo=set[i].GetpFDeg();
11500  if ((oo > op)
11501  || ((oo == op) && (set[i].pLength > ol)))
11502  en=i;
11503  else
11504  an=i;
11505  }
11506  else
11507  an=i;
11508  }
11509 }
11510 
11511 // determines the position based on: 1.) FDeg 2.) pLength
11512 int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11513 {
11514 
11515  if (length==-1) return 0;
11516 
11517  int op=p.GetpFDeg();
11518  int ol = p.GetpLength();
11519 
11520  int oo=set[length].GetpFDeg();
11521  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11522  return length+1;
11523 
11524  int i;
11525  int an = 0;
11526  int en= length;
11527  loop
11528  {
11529  if (an >= en-1)
11530  {
11531  int oo=set[an].GetpFDeg();
11532  if((oo > op)
11533  || ((oo==op) && (set[an].pLength > ol)))
11534  return an;
11535  return en;
11536  }
11537  i=(an+en) / 2;
11538  int oo=set[i].GetpFDeg();
11539  if ((oo > op)
11540  || ((oo == op) && (set[i].pLength > ol)))
11541  en=i;
11542  else
11543  an=i;
11544  }
11545 }
11546 
11547 
11548 // determines the position based on: 1.) pLength
11549 int posInT_pLength(const TSet set,const int length,LObject &p)
11550 {
11551  int ol = p.GetpLength();
11552  if (length==-1)
11553  return 0;
11554  if (set[length].length<p.length)
11555  return length+1;
11556 
11557  int i;
11558  int an = 0;
11559  int en= length;
11560 
11561  loop
11562  {
11563  if (an >= en-1)
11564  {
11565  if (set[an].pLength>ol) return an;
11566  return en;
11567  }
11568  i=(an+en) / 2;
11569  if (set[i].pLength>ol) en=i;
11570  else an=i;
11571  }
11572 }
11573 #endif
11575 // kstd1.cc:
11576 int redFirst (LObject* h,kStrategy strat);
11577 int redEcart (LObject* h,kStrategy strat);
11578 void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11579 void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11580 // ../Singular/misc.cc:
11581 extern char * showOption();
11582 
11583 void kDebugPrint(kStrategy strat)
11584 {
11585  PrintS("red: ");
11586  if (strat->red==redFirst) PrintS("redFirst\n");
11587  else if (strat->red==redHoney) PrintS("redHoney\n");
11588  else if (strat->red==redEcart) PrintS("redEcart\n");
11589  else if (strat->red==redHomog) PrintS("redHomog\n");
11590  else Print("%p\n",(void*)strat->red);
11591  PrintS("posInT: ");
11592  if (strat->posInT==posInT0) PrintS("posInT0\n");
11593  else if (strat->posInT==posInT1) PrintS("posInT1\n");
11594  else if (strat->posInT==posInT11) PrintS("posInT11\n");
11595  else if (strat->posInT==posInT110) PrintS("posInT110\n");
11596  else if (strat->posInT==posInT13) PrintS("posInT13\n");
11597  else if (strat->posInT==posInT15) PrintS("posInT15\n");
11598  else if (strat->posInT==posInT17) PrintS("posInT17\n");
11599  else if (strat->posInT==posInT17_c) PrintS("posInT17_c\n");
11600  else if (strat->posInT==posInT19) PrintS("posInT19\n");
11601  else if (strat->posInT==posInT2) PrintS("posInT2\n");
11602  #ifdef HAVE_RINGS
11603  else if (strat->posInT==posInT11Ring) PrintS("posInT11Ring\n");
11604  else if (strat->posInT==posInT110Ring) PrintS("posInT110Ring\n");
11605  else if (strat->posInT==posInT15Ring) PrintS("posInT15Ring\n");
11606  else if (strat->posInT==posInT17Ring) PrintS("posInT17Ring\n");
11607  else if (strat->posInT==posInT17_cRing) PrintS("posInT17_cRing\n");
11608  #endif
11609 #ifdef HAVE_MORE_POS_IN_T
11610  else if (strat->posInT==posInT_EcartFDegpLength) PrintS("posInT_EcartFDegpLength\n");
11611  else if (strat->posInT==posInT_FDegpLength) PrintS("posInT_FDegpLength\n");
11612  else if (strat->posInT==posInT_pLength) PrintS("posInT_pLength\n");
11613 #endif
11614  else if (strat->posInT==posInT_EcartpLength) PrintS("posInT_EcartpLength\n");
11615  else if (strat->posInT==posInTrg0) PrintS("posInTrg0\n");
11616  else Print("%p\n",(void*)strat->posInT);
11617  PrintS("posInL: ");
11618  if (strat->posInL==posInL0) PrintS("posInL0\n");
11619  else if (strat->posInL==posInL10) PrintS("posInL10\n");
11620  else if (strat->posInL==posInL11) PrintS("posInL11\n");
11621  else if (strat->posInL==posInL110) PrintS("posInL110\n");
11622  else if (strat->posInL==posInL13) PrintS("posInL13\n");
11623  else if (strat->posInL==posInL15) PrintS("posInL15\n");
11624  else if (strat->posInL==posInL17) PrintS("posInL17\n");
11625  else if (strat->posInL==posInL17_c) PrintS("posInL17_c\n");
11626  #ifdef HAVE_RINGS
11627  else if (strat->posInL==posInL0) PrintS("posInL0Ring\n");
11628  else if (strat->posInL==posInL11Ring) PrintS("posInL11Ring\n");
11629  else if (strat->posInL==posInL11Ringls) PrintS("posInL11Ringls\n");
11630  else if (strat->posInL==posInL110Ring) PrintS("posInL110Ring\n");
11631  else if (strat->posInL==posInL15Ring) PrintS("posInL15Ring\n");
11632  else if (strat->posInL==posInL17Ring) PrintS("posInL17Ring\n");
11633  else if (strat->posInL==posInL17_cRing) PrintS("posInL17_cRing\n");
11634  #endif
11635  else if (strat->posInL==posInLSpecial) PrintS("posInLSpecial\n");
11636  else if (strat->posInL==posInLrg0) PrintS("posInLrg0\n");
11637  else Print("%p\n",(void*)strat->posInL);
11638  PrintS("enterS: ");
11639  if (strat->enterS==enterSBba) PrintS("enterSBba\n");
11640  else if (strat->enterS==enterSMora) PrintS("enterSMora\n");
11641  else if (strat->enterS==enterSMoraNF) PrintS("enterSMoraNF\n");
11642  else Print("%p\n",(void*)strat->enterS);
11643  PrintS("initEcart: ");
11644  if (strat->initEcart==initEcartBBA) PrintS("initEcartBBA\n");
11645  else if (strat->initEcart==initEcartNormal) PrintS("initEcartNormal\n");
11646  else Print("%p\n",(void*)strat->initEcart);
11647  PrintS("initEcartPair: ");
11648  if (strat->initEcartPair==initEcartPairBba) PrintS("initEcartPairBba\n");
11649  else if (strat->initEcartPair==initEcartPairMora) PrintS("initEcartPairMora\n");
11650  else Print("%p\n",(void*)strat->initEcartPair);
11651  Print("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11652  strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11653  Print("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11654  strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11655  PrintS("chainCrit: ");
11656  if (strat->chainCrit==chainCritNormal) PrintS("chainCritNormal\n");
11657  else if (strat->chainCrit==chainCritOpt_1) PrintS("chainCritOpt_1\n");
11658  else Print("%p\n",(void*)strat->chainCrit);
11659  Print("posInLDependsOnLength=%d\n",
11660  strat->posInLDependsOnLength);
11661  PrintS(showOption());PrintLn();
11662  PrintS("LDeg: ");
11663  if (currRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11664  else if (currRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11665  else if (currRing->pLDeg==pLDegb) PrintS("pLDegb");
11666  else if (currRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11667  else if (currRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11668  else if (currRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11669  else if (currRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11670  else if (currRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11671  else if (currRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11672  else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11673  else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11674  else if (currRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11675  else Print("? (%lx)", (long)currRing->pLDeg);
11676  PrintS(" / ");
11677  if (strat->tailRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11678  else if (strat->tailRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11679  else if (strat->tailRing->pLDeg==pLDegb) PrintS("pLDegb");
11680  else if (strat->tailRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11681  else if (strat->tailRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11682  else if (strat->tailRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11683  else if (strat->tailRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11684  else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11685  else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11686  else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11687  else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11688  else if (strat->tailRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11689  else Print("? (%lx)", (long)strat->tailRing->pLDeg);
11690  PrintLn();
11691  PrintS("currRing->pFDeg: ");
11692  if (currRing->pFDeg==p_Totaldegree) PrintS("p_Totaldegree");
11693  else if (currRing->pFDeg==p_WFirstTotalDegree) PrintS("pWFirstTotalDegree");
11694  else if (currRing->pFDeg==p_Deg) PrintS("p_Deg");
11695  else if (currRing->pFDeg==kHomModDeg) PrintS("kHomModDeg");
11696  else if (currRing->pFDeg==totaldegreeWecart) PrintS("totaldegreeWecart");
11697  else if (currRing->pFDeg==p_WTotaldegree) PrintS("p_WTotaldegree");
11698  else Print("? (%lx)", (long)currRing->pFDeg);
11699  PrintLn();
11700  Print(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11701  if(TEST_OPT_DEGBOUND)
11702  Print(" degBound: %d\n", Kstd1_deg);
11703 
11704  if( ecartWeights != NULL )
11705  {
11706  PrintS("ecartWeights: ");
11707  for (int i = rVar(currRing); i > 0; i--)
11708  Print("%hd ", ecartWeights[i]);
11709  PrintLn();
11711  }
11712 
11713 #ifndef SING_NDEBUG
11715 #endif
11716 }
11717 
11718 #ifdef HAVE_SHIFTBBA
11719 poly pMove2CurrTail(poly p, kStrategy strat)
11720 {
11721  /* assume: p is completely in currRing */
11722  /* produces an object with LM in curring
11723  and TAIL in tailring */
11724  if (pNext(p)!=NULL)
11725  {
11726  pNext(p) = prMoveR(pNext(p), /* src */ currRing, /* dest */ strat->tailRing);
11727  }
11728  return(p);
11729 }
11730 #endif
11731 
11732 #ifdef HAVE_SHIFTBBA
11733 poly pMoveCurrTail2poly(poly p, kStrategy strat)
11734 {
11735  /* assume: p has LM in curring and TAIL in tailring */
11736  /* convert it to complete currRing */
11737 
11738  /* check that LM is in currRing */
11740 
11741  if (pNext(p)!=NULL)
11742  {
11743  pNext(p) = prMoveR(pNext(p), /* src */ strat->tailRing, /* dest */currRing);
11744  }
11745  return(p);
11746 }
11747 #endif
11748 
11749 #ifdef HAVE_SHIFTBBA
11750 poly pCopyL2p(LObject H, kStrategy strat)
11751 {
11752  /* restores a poly in currRing from LObject */
11753  LObject h = H;
11754  h.Copy();
11755  poly p;
11756  if (h.p == NULL)
11757  {
11758  if (h.t_p != NULL)
11759  {
11760  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing, /* dest. ring: */ currRing);
11761  return(p);
11762  }
11763  else
11764  {
11765  /* h.tp == NULL -> the object is NULL */
11766  return(NULL);
11767  }
11768  }
11769  /* we're here if h.p != NULL */
11770  if (h.t_p == NULL)
11771  {
11772  /* then h.p is the whole poly in currRing */
11773  p = h.p;
11774  return(p);
11775  }
11776  /* we're here if h.p != NULL and h.t_p != NULL */
11777  // clean h.p, get poly from t_p
11778  pNext(h.p)=NULL;
11779  pLmDelete(&h.p);
11780  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing,
11781  /* dest. ring: */ currRing);
11782  // no need to clean h: we re-used the polys
11783  return(p);
11784 }
11785 #endif
11786 
11787 //LObject pCopyp2L(poly p, kStrategy strat)
11788 //{
11789  /* creates LObject from the poly in currRing */
11790  /* actually put p into L.p and make L.t_p=NULL : does not work */
11791 
11792 //}
11793 
11794 // poly pCopyL2p(LObject H, kStrategy strat)
11795 // {
11796 // /* restores a poly in currRing from LObject */
11797 // LObject h = H;
11798 // h.Copy();
11799 // poly p;
11800 // if (h.p == NULL)
11801 // {
11802 // if (h.t_p != NULL)
11803 // {
11804 // p = p_ShallowCopyDelete(h.t_p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
11805 // return(p);
11806 // }
11807 // else
11808 // {
11809 // /* h.tp == NULL -> the object is NULL */
11810 // return(NULL);
11811 // }
11812 // }
11813 // /* we're here if h.p != NULL */
11814 
11815 // if (h.t_p == NULL)
11816 // {
11817 // /* then h.p is the whole poly in tailRing */
11818 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
11819 // {
11820 // p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
11821 // }
11822 // return(p);
11823 // }
11824 // /* we're here if h.p != NULL and h.t_p != NULL */
11825 // p = pCopy(pHead(h.p)); // in currRing
11826 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
11827 // {
11828 // // pNext(p) = p_ShallowCopyDelete(pNext(h.t_p), (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
11829 // poly pp = p_Copy(pNext(h.p), strat->tailRing);
11830 // // poly p3 = p_Copy(pNext(h.p), currRing); // error
11831 // // p_ShallowCopyDelete(pNext(h.p), currRing, strat->tailBin); // the same as pp
11832 // poly p5 = p_ShallowCopyDelete(pNext(h.p), strat->tailRing, strat->tailBin);
11833 // pNext(p) = p_ShallowCopyDelete(h.t_p, strat->tailRing, strat->tailBin);
11834 // poly p4 = p_Copy(h.t_p, strat->tailRing);
11835 // // if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
11836 // }
11837 // // pTest(p);
11838 // return(p);
11839 // }
11840 
11841 #ifdef HAVE_SHIFTBBA
11842 /* including the self pairs */
11843 void updateSShift(kStrategy strat,int uptodeg,int lV)
11844 {
11845  /* to use after updateS(toT=FALSE,strat) */
11846  /* fills T with shifted elt's of S */
11847  int i;
11848  LObject h;
11849  int atT = -1; // or figure out smth better
11850  strat->tl = -1; // init
11851  for (i=0; i<=strat->sl; i++)
11852  {
11853  memset(&h,0,sizeof(h));
11854  h.p = strat->S[i];
11855  strat->initEcart(&h);
11856  h.sev = strat->sevS[i];
11857  h.t_p = NULL;
11858  h.GetTP(); // creates correct t_p
11859  /*puts the elements of S with their shifts to T*/
11860  // int atT, int uptodeg, int lV)
11861  strat->S_2_R[i] = strat->tl + 1; // the el't with shift 0 will be inserted first
11862  // need a small check for above; we insert >=1 elements
11863  // insert this check into kTest_TS ?
11864  enterTShift(h,strat,atT,uptodeg,lV);
11865  }
11866  /* what about setting strat->tl? */
11867 }
11868 #endif
11869 
11870 #ifdef HAVE_SHIFTBBA
11871 void initBuchMoraShift (ideal F,ideal Q,kStrategy strat)
11872 {
11873  strat->interpt = BTEST1(OPT_INTERRUPT);
11874  strat->kHEdge=NULL;
11876  /*- creating temp data structures------------------- -*/
11877  strat->cp = 0;
11878  strat->c3 = 0;
11879  strat->cv = 0;
11880  strat->tail = pInit();
11881  /*- set s -*/
11882  strat->sl = -1;
11883  /*- set L -*/
11884  strat->Lmax = setmaxL;
11885  strat->Ll = -1;
11886  strat->L = initL();
11887  /*- set B -*/
11888  strat->Bmax = setmaxL;
11889  strat->Bl = -1;
11890  strat->B = initL();
11891  /*- set T -*/
11892  strat->tl = -1;
11893  strat->tmax = setmaxT;
11894  strat->T = initT();
11895  strat->R = initR();
11896  strat->sevT = initsevT();
11897  /*- init local data struct.---------------------------------------- -*/
11898  strat->P.ecart=0;
11899  strat->P.length=0;
11901  {
11902  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
11903  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
11904  }
11906  {
11907  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
11908  }
11909  {
11910  if(TEST_OPT_SB_1)
11911  {
11912  int i;
11913  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
11914  for (i=strat->newIdeal;i<IDELEMS(F);i++)
11915  {
11916  P->m[i-strat->newIdeal] = F->m[i];
11917  F->m[i] = NULL;
11918  }
11919  initSSpecial(F,Q,P,strat);
11920  for (i=strat->newIdeal;i<IDELEMS(F);i++)
11921  {
11922  F->m[i] = P->m[i-strat->newIdeal];
11923  P->m[i-strat->newIdeal] = NULL;
11924  }
11925  idDelete(&P);
11926  }
11927  else
11928  {
11929  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
11930  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
11931  }
11932  }
11933  strat->fromT = FALSE;
11934  if (!TEST_OPT_SB_1)
11935  {
11936  /* the only change: we do not fill the set T*/
11937  if(!rField_is_Ring(currRing)) updateS(FALSE,strat);
11938  }
11939  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
11940  strat->fromQ=NULL;
11941  /* more changes: fill the set T with all the shifts of elts of S*/
11942  /* is done by other procedure */
11943 }
11944 #endif
11945 
11946 #ifdef HAVE_SHIFTBBA
11947 /*1
11948 * put the pairs (sh \dot s[i],p) into the set B, ecart=ecart(p)
11949 */
11950 static void enterOnePairManyShifts (int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
11951 {
11952  /* p comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
11953 
11956 
11957  /* cycles through all shifts of s[i] until uptodeg - lastVblock(s[i]) */
11958  /* that is create the pairs (f, s \dot g) */
11959 
11960  poly qq = strat->S[i]; // lm in currRing, tail in tailRing
11961 
11962  // poly q = pCopy(pHead(strat->S[i])); // lm in currRing
11963  // pNext(q) = prCopyR(pNext(strat->S[i]),strat->tailRing,currRing); // zero shift
11964 
11965  /* determine how many elements we have to insert for a given s[i] */
11966  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
11967  /* hence, a total number of elt's to add is: */
11968  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
11969  int toInsert = itoInsert(qq, uptodeg, lV, strat->tailRing);
11970 
11971 #ifdef KDEBUG
11972  if (TEST_OPT_DEBUG)
11973  {
11974  // Print("entered ManyShifts: with toInsert=%d",toInsert); PrintLn();
11975  }
11976 #endif
11977 
11978  assume(i<=strat->sl); // from OnePair
11979 
11980  /* these vars hold for all shifts of s[i] */
11981  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
11982 
11983  int qfromQ;
11984  if (strat->fromQ != NULL)
11985  {
11986  qfromQ = strat->fromQ[i];
11987  }
11988  else
11989  {
11990  qfromQ = -1;
11991  }
11992 
11993  int j;
11994 
11995  poly q/*, s*/;
11996 
11997  // for the 0th shift: insert the orig. pair
11998  enterOnePairShift(qq, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, 0, i, uptodeg, lV);
11999 
12000  for (j=1; j<= toInsert; j++)
12001  {
12002  // q = pLPshift(strat->S[i],j,uptodeg,lV);
12003  q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing);
12004  // q = p_mLPshift(qq,j,uptodeg,lV,currRing); // lm in currRing, shift this monomial
12005  // s = p_LPshift(pNext(qq), j, uptodeg, lV, strat->tailRing); // from tailRing
12006  // pNext(q) = s; // in tailRing
12007  /* here we need to call enterOnePair with two polys ... */
12008 
12009 #ifdef KDEBUG
12010  //if (TEST_OPT_DEBUG)
12011  //{
12012  // PrintS("ManyShifts: calling enterOnePairShift(q,p)"); PrintLn();
12013  //}
12014 #endif
12015  //kFindInTShift(q,atR,strat);
12016  enterOnePairShift(q, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, j, i, uptodeg, lV);
12017  }
12018 }
12019 #endif
12020 
12021 #ifdef HAVE_SHIFTBBA
12022 /*1
12023 * put the pairs (sh \dot qq,p) into the set B, ecart=ecart(p)
12024 * despite the name, not only self shifts
12025 */
12026 void enterOnePairSelfShifts (poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int /*atR*/, int uptodeg, int lV)
12027 {
12028 
12029  /* format: p,qq are in LObject form: lm in CR, tail in TR */
12030  /* for true self pairs qq ==p */
12031  /* we test both qq and p */
12033  assume(p_CheckIsFromRing(pNext(qq),strat->tailRing));
12036 
12037  /* since this proc is applied twice for (h, s*g) and (g,s*h), init j with 1 only */
12038 
12039  // int j = 0;
12040  int j = 1;
12041 
12042  /* for such self pairs start with 1, not with 0 */
12043  if (qq == p) j=1;
12044 
12045  /* should cycle through all shifts of q until uptodeg - lastVblock(q) */
12046  /* that is create the pairs (f, s \dot g) */
12047 
12048  int toInsert = itoInsert(qq, uptodeg, lV, strat->tailRing);
12049 
12050 #ifdef KDEBUG
12051  //if (TEST_OPT_DEBUG)
12052  //{
12053  // Print("entered SelfShifts: with toInsert=%d",toInsert); PrintLn();
12054  //}
12055 #endif
12056 
12057  poly q;
12058 
12059  /* these vars hold for all shifts of s[i] */
12060  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12061  int qfromQ = 0; // strat->fromQ[i];
12062 
12063  for (; j<= toInsert; j++)
12064  {
12065  // q = pLPshift(strat->S[i],j,uptodeg,lV);
12066  /* we increase shifts by one; must delete q there*/
12067  // q = qq; q = pMoveCurrTail2poly(q,strat);
12068  // q = pLPshift(q,j,uptodeg,lV); //,currRing);
12069  q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing);
12070  // q = p_mLPshift(qq,j,uptodeg,lV,currRing); // lm in currRing, shift this monomial
12071  // s = p_LPshift(pNext(qq), j, uptodeg, lV, strat->tailRing); // from tailRing
12072  // pNext(q) = s; // in tailRing
12073  /* here we need to call enterOnePair with two polys ... */
12074 #ifdef KDEBUG
12075  //if (TEST_OPT_DEBUG)
12076  //{
12077  // PrintS("SelfShifts: calling enterOnePairShift(q,p)"); PrintLn();
12078  //}
12079 #endif
12080  enterOnePairShift(q, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, j, -1, uptodeg, lV);
12081  }
12082 }
12083 #endif
12084 
12085 #ifdef HAVE_SHIFTBBA
12086 /*2
12087 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12088 */
12089 void enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS, int /*uptodeg*/, int lV)
12090 {
12091 
12092  /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12093 
12094  /* check this Formats: */
12096  assume(p_CheckIsFromRing(pNext(q),strat->tailRing));
12099 
12100 #ifdef KDEBUG
12101 // if (TEST_OPT_DEBUG)
12102 // {
12103 // PrintS("enterOnePairShift(q,p) invoked with q = ");
12104 // wrp(q); // wrp(pHead(q));
12105 // PrintS(", p = ");
12106 // wrp(p); //wrp(pHead(p));
12107 // PrintLn();
12108 // }
12109 #endif
12110 
12111  /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12112 
12113  int qfromQ = qisFromQ;
12114 
12115  /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12116 
12117  int l,j,compare;
12118  LObject Lp;
12119  Lp.i_r = -1;
12120 
12121 #ifdef KDEBUG
12122  Lp.ecart=0; Lp.length=0;
12123 #endif
12124  /*- computes the lcm(s[i],p) -*/
12125  Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12126 
12127  /* apply the V criterion */
12128  if (!isInV(Lp.lcm, lV))
12129  {
12130 #ifdef KDEBUG
12131  if (TEST_OPT_DEBUG)
12132  {
12133  PrintS("V crit applied to q = ");
12134  wrp(q); // wrp(pHead(q));
12135  PrintS(", p = ");
12136  wrp(p); //wrp(pHead(p));
12137  PrintLn();
12138  }
12139 #endif
12140  pLmFree(Lp.lcm);
12141  /* + counter for applying the V criterion */
12142  strat->cv++;
12143  return;
12144  }
12145 
12146  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12147  {
12148  if((!((ecartq>0)&&(ecart>0)))
12149  && pHasNotCF(p,q))
12150  {
12151  /*
12152  *the product criterion has applied for (s,p),
12153  *i.e. lcm(s,p)=product of the leading terms of s and p.
12154  *Suppose (s,r) is in L and the leading term
12155  *of p divides lcm(s,r)
12156  *(==> the leading term of p divides the leading term of r)
12157  *but the leading term of s does not divide the leading term of r
12158  *(notice that this condition is automatically satisfied if r is still
12159  *in S), then (s,r) can be cancelled.
12160  *This should be done here because the
12161  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12162  *
12163  *Moreover, skipping (s,r) holds also for the noncommutative case.
12164  */
12165  strat->cp++;
12166  pLmFree(Lp.lcm);
12167  return;
12168  }
12169  else
12170  Lp.ecart = si_max(ecart,ecartq);
12171  if (strat->fromT && (ecartq>ecart))
12172  {
12173  pLmFree(Lp.lcm);
12174  return;
12175  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12176  }
12177  /*
12178  *the set B collects the pairs of type (S[j],p)
12179  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12180  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12181  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12182  */
12183  {
12184  j = strat->Bl;
12185  loop
12186  {
12187  if (j < 0) break;
12188  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12189  if ((compare==1)
12190  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12191  {
12192  strat->c3++;
12193  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12194  {
12195  pLmFree(Lp.lcm);
12196  return;
12197  }
12198  break;
12199  }
12200  else
12201  if ((compare ==-1)
12202  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12203  {
12204  deleteInL(strat->B,&strat->Bl,j,strat);
12205  strat->c3++;
12206  }
12207  j--;
12208  }
12209  }
12210  }
12211  else /*sugarcrit*/
12212  {
12213  if (ALLOW_PROD_CRIT(strat))
12214  {
12215  // if currRing->nc_type!=quasi (or skew)
12216  // TODO: enable productCrit for super commutative algebras...
12217  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12218  pHasNotCF(p,q))
12219  {
12220  /*
12221  *the product criterion has applied for (s,p),
12222  *i.e. lcm(s,p)=product of the leading terms of s and p.
12223  *Suppose (s,r) is in L and the leading term
12224  *of p devides lcm(s,r)
12225  *(==> the leading term of p devides the leading term of r)
12226  *but the leading term of s does not devide the leading term of r
12227  *(notice that tis condition is automatically satisfied if r is still
12228  *in S), then (s,r) can be canceled.
12229  *This should be done here because the
12230  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12231  */
12232  strat->cp++;
12233  pLmFree(Lp.lcm);
12234  return;
12235  }
12236  if (strat->fromT && (ecartq>ecart))
12237  {
12238  pLmFree(Lp.lcm);
12239  return;
12240  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12241  }
12242  /*
12243  *the set B collects the pairs of type (S[j],p)
12244  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12245  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12246  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12247  */
12248  for(j = strat->Bl;j>=0;j--)
12249  {
12250  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12251  if (compare==1)
12252  {
12253  strat->c3++;
12254  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12255  {
12256  pLmFree(Lp.lcm);
12257  return;
12258  }
12259  break;
12260  }
12261  else
12262  if (compare ==-1)
12263  {
12264  deleteInL(strat->B,&strat->Bl,j,strat);
12265  strat->c3++;
12266  }
12267  }
12268  }
12269  }
12270  /*
12271  *the pair (S[i],p) enters B if the spoly != 0
12272  */
12273  /*- compute the short s-polynomial -*/
12274  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12275  pNorm(p);
12276  if ((q==NULL) || (p==NULL))
12277  return;
12278  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12279  Lp.p=NULL;
12280  else
12281  {
12282 // if ( rIsPluralRing(currRing) )
12283 // {
12284 // if(pHasNotCF(p, q))
12285 // {
12286 // if(ncRingType(currRing) == nc_lie)
12287 // {
12288 // // generalized prod-crit for lie-type
12289 // strat->cp++;
12290 // Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12291 // }
12292 // else
12293 // if( ALLOW_PROD_CRIT(strat) )
12294 // {
12295 // // product criterion for homogeneous case in SCA
12296 // strat->cp++;
12297 // Lp.p = NULL;
12298 // }
12299 // else
12300 // Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12301 // }
12302 // else Lp.p = nc_CreateSpoly(q,p,currRing);
12303 // }
12304 // else
12305 // {
12306 
12307  /* ksCreateShortSpoly needs two Lobject-kind presentations */
12308  /* p is already in this form, so convert q */
12309  // q = pMove2CurrTail(q, strat);
12310  Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12311  // }
12312  }
12313  if (Lp.p == NULL)
12314  {
12315  /*- the case that the s-poly is 0 -*/
12316  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12317 // if (strat->pairtest==NULL) initPairtest(strat);
12318 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12319 // strat->pairtest[strat->sl+1] = TRUE;
12320  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12321  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12322  /*
12323  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12324  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12325  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12326  *term of p devides the lcm(s,r)
12327  *(this canceling should be done here because
12328  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12329  *the first case is handeled in chainCrit
12330  */
12331  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12332  }
12333  else
12334  {
12335  /*- the pair (S[i],p) enters B -*/
12336  /* both of them should have their LM in currRing and TAIL in tailring */
12337  Lp.p1 = q; // already in the needed form
12338  Lp.p2 = p; // already in the needed form
12339 
12340  if ( !rIsPluralRing(currRing) )
12341  pNext(Lp.p) = strat->tail;
12342 
12343  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12344  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12345  if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12346  {
12347  Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12348  Lp.i_r2 = atR;
12349  }
12350  else
12351  {
12352  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12353  Lp.i_r1 = -1;
12354  Lp.i_r2 = -1;
12355  }
12356  strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12357 
12359  {
12360  if (!rIsPluralRing(currRing)
12362  && (Lp.p->coef!=NULL))
12363  nDelete(&(Lp.p->coef));
12364  }
12365 
12366  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12367  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12368  }
12370 #endif
12371 
12372 #ifdef HAVE_SHIFTBBA
12373 /*3
12374 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12375 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12376 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
12377 */
12378 void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
12379 {
12380  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12381  // atR = -1;
12382  if ((strat->syzComp==0)
12383  || (pGetComp(h)<=strat->syzComp))
12384  {
12385  int j;
12386  BOOLEAN new_pair=FALSE;
12387 
12388  if (pGetComp(h)==0)
12389  {
12390  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12391  if ((isFromQ)&&(strat->fromQ!=NULL))
12392  {
12393  for (j=0; j<=k; j++)
12394  {
12395  if (!strat->fromQ[j])
12396  {
12397  new_pair=TRUE;
12398  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR,uptodeg,lV);
12399  // other side pairs:
12400  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12401  //Print("j:%d, Ll:%d\n",j,strat->Ll);
12402  }
12403  }
12404  }
12405  else
12406  {
12407  new_pair=TRUE;
12408  for (j=0; j<=k; j++)
12409  {
12410  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR,uptodeg,lV);
12411  // other side pairs
12412  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12413  }
12414  /* HERE we put (h, s*h) pairs */
12415  /* enterOnePairSelfShifts (poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV); */
12416  enterOnePairSelfShifts (h, h, ecart, isFromQ, strat, atR, uptodeg, lV);
12417  }
12418  }
12419  else
12420  {
12421  for (j=0; j<=k; j++)
12422  {
12423  if ((pGetComp(h)==pGetComp(strat->S[j]))
12424  || (pGetComp(strat->S[j])==0))
12425  {
12426  new_pair=TRUE;
12427  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR, uptodeg, lV);
12428  // other side pairs
12429  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12430  //Print("j:%d, Ll:%d\n",j,strat->Ll);
12431  }
12432  }
12433  /* HERE we put (h, s*h) pairs */
12434  enterOnePairSelfShifts (h, h, ecart, isFromQ, strat, atR, uptodeg, lV);
12435  }
12436 
12437  if (new_pair)
12438  {
12439  strat->chainCrit(h,ecart,strat);
12440  }
12441 
12442  }
12443 }
12444 #endif
12445 
12446 #ifdef HAVE_SHIFTBBA
12447 /*2
12448 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
12449 *superfluous elements in S will be deleted
12450 */
12451 void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR,int uptodeg, int lV)
12452 {
12453  /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12454  /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
12455  int j=pos;
12456 
12458  initenterpairsShift(h,k,ecart,0,strat, atR,uptodeg,lV);
12459  if ( (!strat->fromT)
12460  && ((strat->syzComp==0)
12461  ||(pGetComp(h)<=strat->syzComp)))
12462  {
12463  //Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
12464  unsigned long h_sev = pGetShortExpVector(h);
12465  loop
12466  {
12467  if (j > k) break;
12468  clearS(h,h_sev, &j,&k,strat);
12469  j++;
12470  }
12471  //Print("end clearS sl=%d\n",strat->sl);
12472  }
12473  // PrintS("end enterpairs\n");
12474 }
12475 #endif
12476 
12477 #ifdef HAVE_SHIFTBBA
12478 /*2
12479 * puts p to the set T, starting with the at position atT
12480 * and inserts all admissible shifts of p
12481 */
12482 void enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV)
12483 {
12484  /* determine how many elements we have to insert */
12485  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12486  /* hence, a total number of elt's to add is: */
12487  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12488 
12489  int toInsert = itoInsert(p.p, uptodeg, lV, strat->tailRing);
12490 
12491 #ifdef PDEBUG
12492  // Print("enterTShift uses toInsert: %d", toInsert); PrintLn();
12493 #endif
12494  int i;
12495 
12496  if (atT < 0)
12497  atT = strat->posInT(strat->T, strat->tl, p);
12498 
12499  /* can call enterT in a sequence, e.g. */
12500 
12501  /* shift0 = it's our model for further shifts */
12502  enterT(p,strat,atT);
12503  LObject qq;
12504  for (i=1; i<=toInsert; i++) // toIns - 1?
12505  {
12506  qq = p; //qq.Copy();
12507  qq.t_p=NULL;
12508  qq.max_exp = NULL;
12509  if (p.p!=NULL)
12510  qq.p = p_LPshift(p_Copy(p.p,currRing), i, uptodeg, lV, currRing); // direct shift
12511  qq.GetTP();
12512  // update q.sev
12513  qq.sev = pGetShortExpVector(qq.p);
12514  #ifdef KTEST
12515  kTest_T(&qq, strat->tailRing, -1, 'L');
12516  #endif
12517  /* enter it into T, first el't is with the shift 0 */
12518  // compute the position for qq
12519  atT = strat->posInT(strat->T, strat->tl, qq);
12520  enterT(qq,strat,atT);
12521  }
12522 /* Q: what to do with this one in the orig enterT ? */
12523 /* strat->R[strat->tl] = &(strat->T[atT]); */
12524 /* Solution: it is done by enterT each time separately */
12525 }
12526 #endif
12527 
12528 #ifdef HAVE_SHIFTBBA
12529 poly redtailBbaShift (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
12530 {
12531  /* for the shift case need to run it with withT = TRUE */
12532  strat->redTailChange=FALSE;
12533  if (strat->noTailReduction) return L->GetLmCurrRing();
12534  poly h, p;
12535  p = h = L->GetLmTailRing();
12536  if ((h==NULL) || (pNext(h)==NULL))
12537  return L->GetLmCurrRing();
12538 
12539  TObject* With;
12540  // placeholder in case strat->tl < 0
12541  TObject With_s(strat->tailRing);
12542 
12543  LObject Ln(pNext(h), strat->tailRing);
12544  Ln.pLength = L->GetpLength() - 1;
12545 
12546  pNext(h) = NULL;
12547  if (L->p != NULL) pNext(L->p) = NULL;
12548  L->pLength = 1;
12549 
12550  Ln.PrepareRed(strat->use_buckets);
12551 
12552  while(!Ln.IsNull())
12553  {
12554  loop
12555  {
12556  Ln.SetShortExpVector();
12557  if (withT)
12558  {
12559  int j;
12560  j = kFindDivisibleByInT(strat, &Ln);
12561  if (j < 0) break;
12562  With = &(strat->T[j]);
12563  }
12564  else
12565  {
12566  With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
12567  if (With == NULL) break;
12568  }
12569  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
12570  {
12571  With->pNorm();
12572  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
12573  }
12574  strat->redTailChange=TRUE;
12575  if (ksReducePolyTail(L, With, &Ln))
12576  {
12577  // reducing the tail would violate the exp bound
12578  // set a flag and hope for a retry (in bba)
12579  strat->completeReduce_retry=TRUE;
12580  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
12581  do
12582  {
12583  pNext(h) = Ln.LmExtractAndIter();
12584  pIter(h);
12585  L->pLength++;
12586  } while (!Ln.IsNull());
12587  goto all_done;
12588  }
12589  if (Ln.IsNull()) goto all_done;
12590  if (! withT) With_s.Init(currRing);
12591  }
12592  pNext(h) = Ln.LmExtractAndIter();
12593  pIter(h);
12594  L->pLength++;
12595  }
12596 
12597  all_done:
12598  Ln.Delete();
12599  if (L->p != NULL) pNext(L->p) = pNext(p);
12600 
12601  if (strat->redTailChange)
12602  {
12603  L->length = 0;
12604  }
12605  L->Normalize(); // HANNES: should have a test
12606  kTest_L(L);
12607  return L->GetLmCurrRing();
12608 }
12609 #endif
n_IntMod
static FORCE_INLINE number n_IntMod(number a, number b, const coeffs r)
for r a field, return n_Init(0,r) always: n_Div(a,b,r)*b+n_IntMod(a,b,r)==a n_IntMod(a,...
Definition: coeffs.h:628
chainCritSig
void chainCritSig(poly p, int, kStrategy strat)
Definition: kutil.cc:3352
clearS
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1107
rHasGlobalOrdering
BOOLEAN rHasGlobalOrdering(const ring r)
Definition: ring.h:750
skStrategy::S_2_T
KINLINE TObject * S_2_T(int i)
Definition: kInline.h:33
si_min
static int si_min(const int a, const int b)
Definition: auxiliary.h:139
ksCheckCoeff
int ksCheckCoeff(number *a, number *b)
kStratInitChangeTailRing
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11127
pDivisibleBy
#define pDivisibleBy(a, b)
returns TRUE, if leading monom of a divides leading monom of b i.e., if there exists a expvector c > ...
Definition: polys.h:132
enterpairsSig
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4784
FALSE
#define FALSE
Definition: auxiliary.h:94
chainCritRing
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:3888
posInLSig
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6022
dReportError
int dReportError(const char *fmt,...)
Definition: dError.cc:43
idCopy
ideal idCopy(ideal A)
Definition: ideals.h:59
_p_LmDivisibleByPart
static BOOLEAN _p_LmDivisibleByPart(poly a, const ring r_a, poly b, const ring r_b, const int start, const int end)
Definition: p_polys.h:1753
skStrategy
Definition: kutil.h:261
idElem
int idElem(const ideal F)
count non-zero elements
Definition: simpleideals.cc:209
p_LmFreeAndNext
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:690
pLDeg1
long pLDeg1(poly p, int *l, const ring r)
Definition: p_polys.cc:832
omalloc.h
pLtCmpOrdSgnEqP
#define pLtCmpOrdSgnEqP(p, q)
Definition: polys.h:123
deleteHC
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:242
p_GetCoeff
#define p_GetCoeff(p, r)
Definition: monomials.h:54
pIsConstant
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:215
REGISTER
#define REGISTER
Definition: omalloc.h:19
skStrategy::fromQ
intset fromQ
Definition: kutil.h:311
initBuchMoraCrit
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9548
p_GetComp
#define p_GetComp(p, r)
Definition: monomials.h:68
enterExtendedSpolySig
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition: kutil.cc:4586
skStrategy::tail
poly tail
Definition: kutil.h:326
pLmEqual
#define pLmEqual(p1, p2)
Definition: polys.h:107
initPairtest
void initPairtest(kStrategy strat)
Definition: kutil.cc:658
enterOneZeroPairRing
void enterOneZeroPairRing(poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:4078
kutil.h
pGetComp
#define pGetComp(p)
Component.
Definition: polys.h:36
redtailBbaBound
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7493
p_GetExp
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:457
j
int j
Definition: facHensel.cc:105
f
FILE * f
Definition: checklibs.c:9
posInT17_c
int posInT17_c(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5737
pNorm
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:337
TEST_OPT_INFREDTAIL
#define TEST_OPT_INFREDTAIL
Definition: options.h:115
cleanT
void cleanT(kStrategy strat)
Definition: kutil.cc:536
pRestoreDegProcs
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3583
pCompareChainPart
BOOLEAN pCompareChainPart(poly p, poly p1, poly p2, poly lcm, const ring R)
Definition: kpolys.cc:74
Kstd1_deg
int Kstd1_deg
Definition: kutil.cc:235
skStrategy::enterS
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:276
TEST_OPT_PROT
#define TEST_OPT_PROT
Definition: options.h:101
pLDeg0c
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:761
redEcart
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:167
pHasNotCF
#define pHasNotCF(p1, p2)
Definition: polys.h:238
k
int k
Definition: cfEzgcd.cc:92
idDelete
#define idDelete(H)
delete an ideal
Definition: ideals.h:28
scComputeHC
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge, ring tailRing)
Definition: hdegree.cc:1005
equal
bool equal
Definition: cfModGcd.cc:4067
pLmFree
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:68
enterT_strong
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9350
skStrategy::tmax
int tmax
Definition: kutil.h:342
TEST_OPT_REDTAIL
#define TEST_OPT_REDTAIL
Definition: options.h:114
enterOneStrongPoly
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition: kutil.cc:1479
skStrategy::cp
int cp
Definition: kutil.h:339
TObject
class sTObject TObject
Definition: kutil.h:52
ecartWeights
short * ecartWeights
Definition: weight0.c:27
ppMult_mm
#define ppMult_mm(p, m)
Definition: polys.h:180
kTest_T
#define kTest_T(T)
Definition: kutil.h:642
rDebugPrint
void rDebugPrint(const ring r)
Definition: ring.cc:3997
LSet
LObject * LSet
Definition: kutil.h:55
posInL0
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5964
rField_is_Domain
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:479
pLDeg0
long pLDeg0(poly p, int *l, const ring r)
Definition: p_polys.cc:730
rChangeCurrRing
void rChangeCurrRing(ring r)
Definition: polys.cc:15
TEST_OPT_DEGBOUND
#define TEST_OPT_DEGBOUND
Definition: options.h:111
nc_p_Bracket_qq
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
Definition: old.gring.cc:2242
diff
static gmp_float * diff
Definition: mpr_complex.cc:45
posInL17_c
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6813
skStrategy::P
LObject P
Definition: kutil.h:292
skStrategy::sbaOrder
unsigned sbaOrder
Definition: kutil.h:306
arriRewCriterion
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7087
isInV
int isInV(poly p, int lV)
Definition: shiftgb.cc:237
initT
KINLINE TSet initT()
Definition: kInline.h:78
polyset
poly * polyset
Definition: polys.h:235
nGreater
#define nGreater(a, b)
Definition: numbers.h:28
skStrategy::ecartS
intset ecartS
Definition: kutil.h:299
pLDeg1_Totaldegree
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:966
pGetExp
#define pGetExp(p, i)
Exponent.
Definition: polys.h:40
posInT_EcartFDegpLength
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11449
pEnlargeSet
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3630
ADDRESS
void * ADDRESS
Definition: auxiliary.h:133
redtail
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7303
posInT17
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5630
isInPairsetL
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition: kutil.cc:667
skStrategy::t_kHEdge
poly t_kHEdge
Definition: kutil.h:321
posInT110Ring
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5420
p_Mult_mm
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:982
kCheckStrongCreation
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition: kutil.cc:10614
skStrategy::chainCrit
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:281
skStrategy::R
TObject ** R
Definition: kutil.h:332
ncRingType
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:167
skStrategy::L
LSet L
Definition: kutil.h:317
skStrategy::S
polyset S
Definition: kutil.h:296
initsevT
KINLINE unsigned long * initsevT()
Definition: kInline.h:94
skStrategy::z2homog
char z2homog
Definition: kutil.h:367
isNotHomog
Definition: structs.h:38
initBuchMoraShift
void initBuchMoraShift(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:11862
p_Neg
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1028
skStrategy::lenS
intset lenS
Definition: kutil.h:309
p_SetCompP
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:245
rKillModifiedRing
void rKillModifiedRing(ring r)
Definition: ring.cc:2957
weight.h
BTEST1
#define BTEST1(a)
Definition: options.h:33
updateResult
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10180
polys.h
kCheckSpolyCreation
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10577
superenterpairs
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4730
totaldegreeWecart
long totaldegreeWecart(poly p, ring r)
Definition: weight.cc:222
posInT110
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5378
skStrategy::tailRing
ring tailRing
Definition: kutil.h:335
idInsertPoly
BOOLEAN idInsertPoly(ideal h1, poly h2)
insert h2 into h1 (if h2 is not the zero polynomial) return TRUE iff h2 was indeed inserted
Definition: simpleideals.cc:639
redtailBba
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7379
length
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:267
ind_fact_2
long ind_fact_2(long arg)
Definition: kutil.cc:4055
kTest_S
#define kTest_S(T)
Definition: kutil.h:643
p_ShallowCopyDelete
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:869
p_ExpVectorCopy
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition: p_polys.h:1242
itoInsert
int itoInsert(poly p, int uptodeg, int lV, const ring r)
Definition: shiftgb.cc:320
TEST_OPT_CONTENTSB
#define TEST_OPT_CONTENTSB
Definition: options.h:124
__p_GetComp
#define __p_GetComp(p, r)
Definition: monomials.h:67
updateS
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:8801
prMapR
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
Definition: prCopy.cc:46
pLDeg1c_Deg
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:932
skStrategy::tailBin
omBin tailBin
Definition: kutil.h:337
TEST_OPT_DEBUG
#define TEST_OPT_DEBUG
Definition: options.h:106
pNeg
#define pNeg(p)
Definition: polys.h:177
p_Test
#define p_Test(p, r)
Definition: p_polys.h:155
nc_rComplete
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5519
p_wrp
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:234
skStrategy::overflow
char overflow
Definition: kutil.h:397
nInitChar
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:349
pGetShortExpVector
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl....
Definition: polys.h:146
n_Q
rational (GMP) numbers
Definition: coeffs.h:30
options.h
REDTAIL_CANONICALIZE
#define REDTAIL_CANONICALIZE
pp_Mult_mm
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:972
posInS
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:4934
skStrategy::~skStrategy
~skStrategy()
Definition: kutil.cc:11396
initSbaCrit
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:9612
skStrategy::sevS
unsigned long * sevS
Definition: kutil.h:312
kDebugPrint
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition: kutil.cc:11574
skStrategy::homog
char homog
Definition: kutil.h:365
pLDeg1c_WFirstTotalDegree
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1059
pDelete
#define pDelete(p_ptr)
Definition: polys.h:166
initenterzeropairsRing
void initenterzeropairsRing(poly p, int ecart, kStrategy strat, int atR)
Definition: kutil.cc:4322
N
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:48
pLtCmp
#define pLtCmp(p, q)
Definition: polys.h:118
posInT_EcartpLength
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5496
skStrategy::honey
char honey
Definition: kutil.h:370
posInL0Ring
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5990
deleteInSSba
void deleteInSSba(int i, kStrategy strat)
Definition: kutil.cc:1096
postReduceByMon
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:10805
idIs0
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
Definition: simpleideals.cc:767
enlargeL
static void enlargeL(LSet *L, int *length, const int incr)
Definition: kutil.cc:648
posInT_FDegpLength
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11503
loop
#define loop
Definition: structs.h:77
skStrategy::B
LSet B
Definition: kutil.h:318
skStrategy::Lmax
int Lmax
Definition: kutil.h:343
pSetComp
#define pSetComp(p, v)
Definition: polys.h:37
syzCriterion
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6944
pJet
#define pJet(p, m)
Definition: polys.h:342
TEST_OPT_REDSB
#define TEST_OPT_REDSB
Definition: options.h:102
b
CanonicalForm b
Definition: cfModGcd.cc:4044
p_Lcm
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition: p_polys.cc:1599
isInPairsetB
BOOLEAN isInPairsetB(poly q, int *k, kStrategy strat)
Definition: kutil.cc:688
initec
static intset initec(const int maxnr)
Definition: kutil.cc:501
ind2
long ind2(long arg)
Definition: kutil.cc:4043
p_LmDivisibleBy
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1794
posInSyz
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:6182
posInT17_cRing
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5798
pLDegb
long pLDegb(poly p, int *l, const ring r)
Definition: p_polys.cc:802
skStrategy::lmBin
omBin lmBin
Definition: kutil.h:336
p_LmCheckIsFromRing
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:67
enterSMoraNF
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1327
posInT19
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5864
found
bool found
Definition: facFactorize.cc:56
p_LPshiftT
poly p_LPshiftT(poly p, int sh, int uptodeg, int lV, kStrategy strat, const ring r)
Definition: shiftgb.cc:41
arriRewCriterionPre
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition: kutil.cc:7112
setmax
#define setmax
Definition: kutil.h:28
nGreaterZero
#define nGreaterZero(n)
Definition: numbers.h:27
p_SetExp
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition: p_polys.h:476
skStrategy::t_kNoether
poly t_kNoether
Definition: kutil.h:323
ringorder_C
Definition: ring.h:79
k_LmInit_currRing_2_tailRing
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:875
rCopy0
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1324
prMoveR
poly prMoveR(poly &p, ring src_r, ring dest_r)
Definition: prCopy.cc:90
rIsPluralRing
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:403
rGetCurrSyzLimit
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:713
skStrategy::syzidxmax
int syzidxmax
Definition: kutil.h:341
pLength
static unsigned pLength(poly a)
Definition: p_polys.h:183
rAssure_c_dp
ring rAssure_c_dp(const ring r)
Definition: ring.cc:4876
newHEdge
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10514
kTest
#define kTest(A)
Definition: kutil.h:640
kMergeBintoLSba
void kMergeBintoLSba(kStrategy strat)
Definition: kutil.cc:3102
chainCritOpt_1
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3336
ksCreateShortSpoly
poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing)
Definition: kspoly.cc:998
syzCriterionInc
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6979
p_WFirstTotalDegree
long p_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:587
p_Copy
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:797
posInLSigRing
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6046
currRing
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
skStrategy::sevSyz
unsigned long * sevSyz
Definition: kutil.h:313
initEcartPairBba
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1253
stairc.h
rVar
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:582
sTObject::t_p
poly t_p
Definition: kutil.h:69
denominator_list
denominator_list_s * denominator_list
Definition: kutil.h:58
posInLSpecial
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5921
ALLOW_PROD_CRIT
#define ALLOW_PROD_CRIT(A)
Definition: kutil.h:388
p_ExpVectorAdd
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1339
TRUE
#define TRUE
Definition: auxiliary.h:98
skStrategy::s_2_t
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:42
TEST_OPT_INTSTRATEGY
#define TEST_OPT_INTSTRATEGY
Definition: options.h:108
i
int i
Definition: cfEzgcd.cc:125
p_OneComp
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition: p_polys.cc:1197
id_Delete
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
Definition: simpleideals.cc:113
rHasLocalOrMixedOrdering
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:751
skStrategy::syz
polyset syz
Definition: kutil.h:297
pShallowCopyDelete.h
p_Sub
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1934
res
CanonicalForm res
Definition: facAbsFact.cc:64
nIsOne
#define nIsOne(n)
Definition: numbers.h:25
kBucket_Add_q
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
Definition: kbuckets.cc:635
skStrategy::sl
int sl
Definition: kutil.h:340
n_Ann
static FORCE_INLINE number n_Ann(number a, const coeffs r)
if r is a ring with zero divisors, return an annihilator!=0 of b otherwise return NULL
Definition: coeffs.h:701
nc_lie
Definition: nc.h:18
skStrategy::redTailChange
char redTailChange
Definition: kutil.h:392
kBucketDestroy
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:212
prCopy.h
id_RankFreeModule
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
Definition: simpleideals.cc:781
nMapFunc
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
posInSMonFirst
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition: kutil.cc:5035
add
static unsigned add[]
Definition: misc_ip.cc:121
skStrategy::T
TSet T
Definition: kutil.h:316
redRing
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:438
skStrategy::posInLDependsOnLength
char posInLDependsOnLength
Definition: kutil.h:382
skStrategy::syzl
int syzl
Definition: kutil.h:341
skStrategy::LazyDegree
int LazyDegree
Definition: kutil.h:345
pDivCompRing
static int pDivCompRing(poly p, poly q)
Definition: kutil.cc:146
enterSBba
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9028
posInT2
int posInT2(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5195
skStrategy::Gebauer
char Gebauer
Definition: kutil.h:371
initEcartNormal
void initEcartNormal(TObject *h)
Definition: kutil.cc:1238
PrintS
void PrintS(const char *s)
Definition: reporter.cc:283
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:258
TEST_OPT_NOT_SUGAR
#define TEST_OPT_NOT_SUGAR
Definition: options.h:104
skStrategy::syzIdx
intset syzIdx
Definition: kutil.h:303
lc
CanonicalForm lc(const CanonicalForm &f)
Definition: canonicalform.h:297
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
pLDeg1_WFirstTotalDegree
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1029
p_Cmp
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1642
strat_nr
int strat_nr
Definition: kstdfac.cc:25
pIsVector
#define pIsVector(p)
Definition: polys.h:227
kBucketInit
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:474
pLcm
#define pLcm(a, b, m)
Definition: polys.h:269
message
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7727
kbTest
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
Definition: kbuckets.cc:193
finalReduceByMon
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:10962
skStrategy::LazyPass
int LazyPass
Definition: kutil.h:345
setmaxTinc
#define setmaxTinc
Definition: kutil.h:33
TEST_OPT_OLDSTD
#define TEST_OPT_OLDSTD
Definition: options.h:120
createG0
ideal createG0()
Definition: kutil.cc:4388
pDivComp_EQUAL
#define pDivComp_EQUAL
Definition: kutil.cc:137
posInT_pLength
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11540
ksReducePolyTail
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1023
skStrategy::newIdeal
int newIdeal
Definition: kutil.h:349
T
static jList * T
Definition: janet.cc:31
skStrategy::Shdl
ideal Shdl
Definition: kutil.h:293
idSkipZeroes
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
Definition: simpleideals.cc:171
rField_is_Ring
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:476
posInTrg0
int posInTrg0(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5302
completeReduce
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:10392
skStrategy::sig
polyset sig
Definition: kutil.h:298
pFalseReturn
#define pFalseReturn(cond)
Definition: monomials.h:142
denominator_list_s
Definition: kutil.h:60
posInL11Ringls
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6334
skStrategy::posInL
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:274
skStrategy::next
kStrategy next
Definition: kutil.h:267
enterOnePairShift
void enterOnePairShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS, int, int lV)
Definition: kutil.cc:12080
skStrategy::kNoetherTail
KINLINE poly kNoetherTail()
Definition: kInline.h:61
TSet
TObject * TSet
Definition: kutil.h:54
initS_2_R
static int * initS_2_R(const int maxnr)
Definition: kutil.cc:510
exitBuchMora
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:9947
enterSSba
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9131
h
static Poly * h
Definition: janet.cc:972
rIsRatGRing
static BOOLEAN rIsRatGRing(const ring r)
Definition: ring.h:414
mod2.h
sca.h
ENTER_USE_MEMMOVE
#define ENTER_USE_MEMMOVE
Definition: kutil.cc:50
redFirst
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:529
initenterpairs
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3700
skStrategy::fromT
char fromT
Definition: kutil.h:372
max
static int max(int a, int b)
Definition: fast_mult.cc:264
skStrategy::pOrigFDeg_TailRing
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:288
posInL17Ring
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6763
initenterstrongPairsSig
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4476
initL
static LSet initL(int nr=setmaxL)
Definition: kutil.h:414
p_LmDelete
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:698
initBuchMora
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:9871
intset
int * intset
Definition: kutil.h:48
pInit
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:59
redMora
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8756
k_GetLeadTerms
KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r, poly &m1, poly &m2, const ring m_r)
Definition: kInline.h:933
pCopyL2p
poly pCopyL2p(LObject H, kStrategy strat)
Definition: kutil.cc:11741
pOne
#define pOne()
Definition: polys.h:289
kMergeBintoL
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3081
enterSyz
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9452
posInL10
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition: kstd1.cc:1009
redtailBbaShift
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:12520
cancelunit1
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition: kutil.cc:8644
kFindDivisibleByInT
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:86
enterOnePairLift
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2141
intvec
Definition: intvec.h:16
pDivComp_GREATER
#define pDivComp_GREATER
Definition: kutil.cc:139
pLDeg1c_Totaldegree
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:996
isHomog
Definition: structs.h:39
pIter
#define pIter(p)
Definition: monomials.h:41
setmaxT
#define setmaxT
Definition: kutil.h:32
pLtCmpOrdSgnDiffP
#define pLtCmpOrdSgnDiffP(p, q)
Definition: polys.h:121
p_Cleardenom
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2779
pDivComp_INCOMP
#define pDivComp_INCOMP
Definition: kutil.cc:140
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:208
posInL11Ring
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6264
shiftgb.h
skStrategy::rewCrit1
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:283
initenterpairsSigRing
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3825
skStrategy::sevSig
unsigned long * sevSig
Definition: kutil.h:314
skStrategy::syzmax
int syzmax
Definition: kutil.h:341
pGetShallowCopyDeleteProc
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
Definition: pShallowCopyDelete.cc:48
pLDeg1c
long pLDeg1c(poly p, int *l, const ring r)
Definition: p_polys.cc:868
p_LmExpVectorAddIsOk
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition: p_polys.h:1936
posInLF5CRing
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6298
kTest_TS
#define kTest_TS(A)
Definition: kutil.h:641
initBuchMoraPos
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:9698
clearSbatch
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4704
sugarDivisibleBy
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition: kutil.cc:1271
p_LmCmp
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1488
enterOnePairSig
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2353
chainCritPart
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3411
p_ExpVectorSum
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1353
pp
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:253
p_GetMaxExpP
poly p_GetMaxExpP(poly p, const ring r)
return monomial r such that GetExp(r,i) is maximum of all monomials in p; coeff == 0,...
Definition: p_polys.cc:1128
enterOnePairSelfShifts
void enterOnePairSelfShifts(poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int, int uptodeg, int lV)
Definition: kutil.cc:12017
kBucketClear
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:502
kFindDivisibleByInS_T
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition: kutil.cc:7161
skStrategy::lenSw
wlen_set lenSw
Definition: kutil.h:310
skStrategy::nr
int nr
Definition: kutil.h:338
posInLRing
int posInLRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6109
rBlocks
static int rBlocks(ring r)
Definition: ring.h:558
__pp_Mult_nn
#define __pp_Mult_nn(p, n, r)
Definition: p_polys.h:943
tmp1
CFList tmp1
Definition: facFqBivar.cc:70
messageStat
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7768
pLtCmpOrdSgnDiffM
#define pLtCmpOrdSgnDiffM(p, q)
Definition: polys.h:120
initSyzRules
void initSyzRules(kStrategy strat)
Definition: kutil.cc:8187
skStrategy::S_2_R
int * S_2_R
Definition: kutil.h:334
pLcmRat
void pLcmRat(poly a, poly b, poly m, int rat_shift)
Definition: ratgring.cc:30
posInL15Ring
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6678
skStrategy::kHEdgeFound
char kHEdgeFound
Definition: kutil.h:369
skStrategy::noTailReduction
char noTailReduction
Definition: kutil.h:371
pCompareChain
BOOLEAN pCompareChain(poly p, poly p1, poly p2, poly lcm, const ring R)
Returns TRUE if.
Definition: kpolys.cc:20
messageSets
#define messageSets(s)
Definition: kutil.h:532
p_LtCmpNoAbs
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition: p_polys.h:1555
kNF
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2812
kTest_L
#define kTest_L(T)
Definition: kutil.h:644
ksOldSpolyRed
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1049
pAdd
#define pAdd(p, q)
Definition: polys.h:182
pLmInit
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:62
pDivideM
#define pDivideM(a, b)
Definition: polys.h:268
skStrategy::news
char news
Definition: kutil.h:393
ringorder_c
Definition: ring.h:78
skStrategy::syzComp
int syzComp
Definition: kutil.h:346
DENOMINATOR_LIST
denominator_list DENOMINATOR_LIST
Definition: kutil.cc:86
posInT13
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5467
redtailBba_Z
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7609
pMove2CurrTail
poly pMove2CurrTail(poly p, kStrategy strat)
Definition: kutil.cc:11710
enterOnePairManyShifts
static void enterOnePairManyShifts(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
Definition: kutil.cc:11941
posInL13
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6608
wlen_type
int64 wlen_type
Definition: kutil.h:49
p_LmTest
#define p_LmTest(p, r)
Definition: p_polys.h:156
pSetCoeff
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:30
kFindInT
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:703
getIndexRng
int getIndexRng(long coeff)
Definition: kutil.cc:6423
pDecrExp
#define pDecrExp(p, i)
Definition: polys.h:43
posInL110Ring
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6561
exp
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357
skStrategy::NotUsedAxis
BOOLEAN * NotUsedAxis
Definition: kutil.h:324
enterOnePairSigRing
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2610
skStrategy::interpt
char interpt
Definition: kutil.h:364
n_DivComp
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition: coeffs.h:522
skStrategy::kHEdge
poly kHEdge
Definition: kutil.h:319
preIntegerCheck
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:10637
skStrategy::posInLSba
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:272
rDelete
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:438
skStrategy::pOrigLDeg_TailRing
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:289
kbuckets.h
p_LmFree
static void p_LmFree(poly p, ring)
Definition: p_polys.h:670
n_Lcm
static FORCE_INLINE number n_Lcm(number a, number b, const coeffs r)
in Z: return the lcm of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition: coeffs.h:712
nc_CreateShortSpoly
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
Definition: old.gring.cc:1878
nIsZero
#define nIsZero(n)
Definition: numbers.h:19
initSbaPos
void initSbaPos(kStrategy strat)
Definition: kutil.cc:9965
ring.h
skStrategy::cv
int cv
Definition: kutil.h:362
posInL11
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6222
p_Deg
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:578
skStrategy::sigdrop
bool sigdrop
Definition: kutil.h:352
omBin
omBin_t * omBin
Definition: omStructs.h:11
posInIdealMonFirst
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:5112
posInL17_cRing
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6877
p_Delete
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:842
initSL
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7940
p_Add_q
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:877
kstd1.h
skStrategy::Ll
int Ll
Definition: kutil.h:343
min
static int min(int a, int b)
Definition: fast_mult.cc:268
posInL17
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6719
redBba1
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8627
postReduceByMonSig
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:10873
p_One
poly p_One(const ring r)
Definition: p_polys.cc:1302
sbaCheckGcdPair
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition: kutil.cc:1607
enterpairsShift
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR, int uptodeg, int lV)
Definition: kutil.cc:12442
maxdegreeWecart
long maxdegreeWecart(poly p, int *l, ring r)
Definition: weight.cc:252
posInT15Ring
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5589
faugereRewCriterion
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7028
pDivComp_LESS
#define pDivComp_LESS
Definition: kutil.cc:138
setmaxL
#define setmaxL
Definition: kutil.h:29
HCord
int HCord
Definition: kutil.cc:234
nc.h
normalize
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition: syz3.cc:1026
initBuchMoraPosRing
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:9784
chainCritNormal
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3123
skStrategy::c3
int c3
Definition: kutil.h:339
si_max
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
bound
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
mult
void mult(unsigned long *result, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:647
pSetmComp
#define pSetmComp(p)
TODO:
Definition: polys.h:248
skStrategy::LDegLast
char LDegLast
Definition: kutil.h:378
enterSMora
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1273
skStrategy::p_shallow_copy_delete
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:330
pLDeg1_Deg
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:901
skStrategy::sevT
unsigned long * sevT
Definition: kutil.h:315
p_CheckPolyRing
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:108
rRing_has_Comp
#define rRing_has_Comp(r)
Definition: monomials.h:265
posInL110
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6520
redBba
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8732
ringorder_a
Definition: ring.h:76
initSLSba
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8037
Print
#define Print
Definition: emacs.cc:79
skStrategy::initEcartPair
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:277
nInvers
#define nInvers(a)
Definition: numbers.h:33
skStrategy::newt
char newt
Definition: kutil.h:394
mylimits.h
initSbaBuchMora
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10067
TEST_OPT_WEIGHTM
#define TEST_OPT_WEIGHTM
Definition: options.h:118
TEST_OPT_SUGARCRIT
#define TEST_OPT_SUGARCRIT
Definition: options.h:105
cleanTSbaRing
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:589
omMergeStickyBinIntoBin
void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin)
Definition: omBin.c:392
reorderS
void reorderS(int *suc, kStrategy strat)
Definition: kutil.cc:4881
p_NSet
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1432
omSizeWOfBin
#define omSizeWOfBin(bin_ptr)
Definition: omAllocPrivate.h:96
pIsPurePower
#define pIsPurePower(p)
Definition: polys.h:225
idInit
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:36
p_SetCoeff
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:400
pp_Test
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:157
posInLF5C
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:6210
initsevS
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:506
TEST_OPT_IDLIFT
#define TEST_OPT_IDLIFT
Definition: options.h:126
pSetCoeff0
#define pSetCoeff0(p, n)
Definition: monomials.h:63
rModifyRing
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2597
n_Gcd
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition: coeffs.h:686
skStrategy::pairtest
BOOLEAN * pairtest
Definition: kutil.h:325
showOption
char * showOption()
Definition: misc_ip.cc:727
m
int m
Definition: cfEzgcd.cc:121
skStrategy::kNoether
poly kNoether
Definition: kutil.h:320
enterOnePairRing
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:1280
skStrategy::tl
int tl
Definition: kutil.h:342
HEckeTest
void HEckeTest(poly pp, kStrategy strat)
Definition: kutil.cc:466
skStrategy::Bl
int Bl
Definition: kutil.h:344
WarnS
#define WarnS
Definition: emacs.cc:77
n_DivBy
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether 'a' is divisible 'b'; for r encoding a field: TRUE iff 'b' does not represent zero in Z:...
Definition: coeffs.h:783
assume
#define assume(x)
Definition: mod2.h:384
Kstd1_mu
int Kstd1_mu
Definition: kutil.cc:236
enterpairsSpecial
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:4807
p_GetMaxExpL
unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max)
return the maximal exponent of p in form of the maximal long var
Definition: p_polys.cc:1165
NULL
#define NULL
Definition: omList.c:9
pLmDelete
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:74
posInT1
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5167
pSetm
#define pSetm(p)
Definition: polys.h:246
idSyzygies
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition: ideals.cc:730
skStrategy::noClearS
char noClearS
Definition: kutil.h:395
mflush
#define mflush()
Definition: reporter.h:56
ideals.h
pLmShortDivisibleBy
#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:140
p_SetComp
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:238
l
int l
Definition: cfEzgcd.cc:93
lcm
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:709
enlargeT
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition: kutil.cc:515
nDelete
#define nDelete(n)
Definition: numbers.h:16
posInLrg0
int posInLrg0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6436
n_Int
static FORCE_INLINE long n_Int(number &n, const coeffs r)
conversion of n to an int; 0 if not possible in Z/pZ: the representing int lying in (-p/2 ....
Definition: coeffs.h:547
sTObject::p
poly p
Definition: kutil.h:68
p_WTotaldegree
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:604
omRealloc0Size
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:219
skStrategy::rewCrit3
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:285
kBucket
Definition: kbuckets.h:174
R
#define R
Definition: sirandom.c:26
initSSpecialSba
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8482
posInT11Ring
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5261
kPosInLDependsOnLength
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition: kutil.cc:9682
skStrategy::completeReduce_retry
char completeReduce_retry
Definition: kutil.h:396
TEST_OPT_SB_1
#define TEST_OPT_SB_1
Definition: options.h:116
p_Setm
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:224
LObject
class sLObject LObject
Definition: kutil.h:53
skStrategy::ak
int ak
Definition: kutil.h:345
posInL15
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6643
TEST_OPT_CANCELUNIT
#define TEST_OPT_CANCELUNIT
Definition: options.h:125
gcd
int gcd(int a, int b)
Definition: walkSupport.cc:836
initenterpairsShift
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
Definition: kutil.cc:12369
pLmDivisibleBy
#define pLmDivisibleBy(a, b)
like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
Definition: polys.h:134
pSetExp
#define pSetExp(p, i, v)
Definition: polys.h:41
updateSShift
void updateSShift(kStrategy strat, int uptodeg, int lV)
Definition: kutil.cc:11834
initenterstrongPairs
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4454
denominator_list_s::next
denominator_list next
Definition: kutil.h:60
cancelunit
void cancelunit(LObject *L, BOOLEAN inNF)
Definition: kutil.cc:331
pDivComp
static int pDivComp(poly p, poly q)
Definition: kutil.cc:185
p_Totaldegree
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1435
skStrategy::pOrigFDeg
pFDegProc pOrigFDeg
Definition: kutil.h:286
p
int p
Definition: cfModGcd.cc:4019
p_ExpVectorEqual
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition: p_polys.cc:4406
pShallowCopyDeleteProc
poly(* pShallowCopyDeleteProc)(poly s_p, ring source_r, ring dest_r, omBin dest_bin)
returns a poly from dest_r which is a ShallowCopy of s_p from source_r assumes that source_r->N == de...
Definition: ring.h:50
enterOneStrongPolySig
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1665
posInT17Ring
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5691
messageStatSBA
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:7780
enterL
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1214
r_assume
#define r_assume(x)
Definition: mod2.h:385
deleteInL
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1151
skStrategy::initEcart
void(* initEcart)(TObject *L)
Definition: kutil.h:270
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
p_GetMaxExp
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition: p_polys.h:733
nInit
#define nInit(i)
Definition: numbers.h:24
pLmCmp
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:101
initSSpecial
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8338
H
CanonicalForm H
Definition: facAbsFact.cc:64
rIsSyzIndexRing
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:710
skStrategy::red
int(* red)(LObject *L, kStrategy strat)
Definition: kutil.h:268
p_HasNotCF_Lift
static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
p_HasNotCF for the IDLIFT case: ignore component
Definition: kutil.cc:2124
kHomModDeg
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2082
initEcartBBA
void initEcartBBA(TObject *h)
Definition: kutil.cc:1246
enterpairs
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4758
pCopy
#define pCopy(p)
return a copy of the poly
Definition: polys.h:165
skStrategy::nrsyzcrit
int nrsyzcrit
Definition: kutil.h:353
n_SetMap
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:721
IDELEMS
#define IDELEMS(i)
Definition: simpleideals.h:24
skStrategy::posInT
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:271
pNormalize
#define pNormalize(p)
Definition: polys.h:291
posInT15
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5535
skStrategy::currIdx
int currIdx
Definition: kutil.h:307
initenterpairsSig
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3765
kStd
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:2095
p_ISet
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1286
sTObject::tailRing
ring tailRing
Definition: kutil.h:71
comp
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
Definition: facSparseHensel.h:25
Q
#define Q
Definition: sirandom.c:25
posInT0
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:5156
p_Mult_q
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1035
deleteInS
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1044
pHead
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL
Definition: polys.h:65
k_GetStrongLeadTerms
KINLINE void k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing, poly &m1, poly &m2, poly &lcm, const ring tailRing)
Definition: kInline.h:976
initEcartPairMora
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1260
skStrategy::sugarCrit
char sugarCrit
Definition: kutil.h:370
rHasMixedOrdering
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:752
pGetCoeff
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:48
tmp2
CFList tmp2
Definition: facFqBivar.cc:70
redFirstShift
int redFirstShift(LObject *h, kStrategy strat)
Definition: kstd2.cc:4264
denominator_list_s::n
number n
Definition: kutil.h:60
skStrategy::minim
int minim
Definition: kutil.h:350
enterOnePairNormal
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:1860
PrintLn
void PrintLn()
Definition: reporter.cc:309
skStrategy::use_buckets
char use_buckets
Definition: kutil.h:376
skStrategy::Bmax
int Bmax
Definition: kutil.h:344
sbaRing
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11154
rIsSCA
static bool rIsSCA(const ring r)
Definition: nc.h:198
kStratChangeTailRing
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11028
p_GetShortExpVector
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4660
initR
KINLINE TObject ** initR()
Definition: kInline.h:89
p_LPshift
poly p_LPshift(poly p, int sh, int uptodeg, int lV, const ring r)
Definition: shiftgb.cc:73
omGetStickyBinOfBin
omBin omGetStickyBinOfBin(omBin bin)
Definition: omBin.c:369
skStrategy::syzCrit
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.h:282
omCheckBinAddrSize
#define omCheckBinAddrSize(addr, size)
Definition: omAllocDecl.h:324
p_FDeg
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:369
skStrategy::skStrategy
skStrategy()
Definition: kutil.cc:11376
kCreateZeroPoly
poly kCreateZeroPoly(long exp[], long cabsind, poly *t_p, ring leadRing, ring tailRing)
Definition: kutil.cc:4259
ratgring.h
enterExtendedSpoly
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4503
initHilbCrit
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9530
exitSba
void exitSba(kStrategy strat)
Definition: kutil.cc:10140
index
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:585
redHoney
int redHoney(LObject *h, kStrategy strat)
Definition: kstd2.cc:1402
nCoeff_is_Ring_Z
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_Z(const coeffs r)
Definition: coeffs.h:755
nCopy
#define nCopy(n)
Definition: numbers.h:15
n_ExtGcd
static FORCE_INLINE number n_ExtGcd(number a, number b, number *s, number *t, const coeffs r)
beware that ExtGCD is only relevant for a few chosen coeff. domains and may perform something unexpec...
Definition: coeffs.h:693
n_IsUnit
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:515
rRingOrder_t
rRingOrder_t
order stuff
Definition: ring.h:73
skStrategy::HCord
int HCord
Definition: kutil.h:347
numbers.h
pNext
#define pNext(p)
Definition: monomials.h:40
superenterpairsSig
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4740
enterT
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9269
setmaxLinc
#define setmaxLinc
Definition: kutil.h:30
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:209
p_LmShortDivisibleBy
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1828
OPT_INTERRUPT
#define OPT_INTERRUPT
Definition: options.h:77
pCmp
#define pCmp(p1, p2)
pCmp: args may be NULL returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
Definition: polys.h:111
enterTShift
void enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV)
Definition: kutil.cc:12473
posInT11
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5225
twoPow
long twoPow(long arg)
Definition: kutil.cc:4070
enterOnePairSpecial
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3012
nKillChar
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:510
idIsConstant
#define idIsConstant(I)
Definition: ideals.h:39
skStrategy::enterOnePair
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.h:280
idPosConstant
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition: ideals.h:36
redHomog
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:548
pMoveCurrTail2poly
poly pMoveCurrTail2poly(poly p, kStrategy strat)
Definition: kutil.cc:11724
skStrategy::nrrewcrit
int nrrewcrit
Definition: kutil.h:354
initS
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7846
ksOldSpolyRedNew
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1059
nextZeroSimplexExponent
int nextZeroSimplexExponent(long exp[], long ind[], long cexp[], long cind[], long *cabsind, long step[], long bound, long N)
Definition: kutil.cc:4193
rComplete
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition: ring.cc:3350
pWrite
void pWrite(poly p)
Definition: polys.h:282
omReallocSize
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:218
wrp
void wrp(poly p)
Definition: polys.h:284
p_Cleardenom_n
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2888
skStrategy::pOrigLDeg
pLDegProc pOrigLDeg
Definition: kutil.h:287
p_CheckIsFromRing
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:98