My Project  UNKNOWN_GIT_VERSION
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 
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 
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 
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 
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->p!=NULL)
771  {
772  nTest(pGetCoeff(T->p));
773  if ((T->t_p==NULL)&&(pNext(T->p)!=NULL)) p_Test(pNext(T->p),currRing);
774  }
775  if (T->t_p!=NULL)
776  {
777  nTest(pGetCoeff(T->t_p));
778  if (pNext(T->t_p)!=NULL) p_Test(pNext(T->t_p),strat_tailRing);
779  }
780  if ((T->p!=NULL)&&(T->t_p!=NULL)) assume(pGetCoeff(T->p)==pGetCoeff(T->t_p));
781 
782  if (T->tailRing != currRing)
783  {
784  if (T->t_p == NULL && i > 0)
785  return dReportError("%c[%d].t_p is NULL", TN, i);
786  pFalseReturn(p_Test(T->t_p, T->tailRing));
787  if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
788  if (T->p != NULL && T->t_p != NULL)
789  {
790  const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
791  if (msg != NULL)
792  return dReportError("%c[%d] %s", TN, i, msg);
793  // r = T->tailRing;
794  p = T->t_p;
795  }
796  if (T->p == NULL)
797  {
798  p = T->t_p;
799  // r = T->tailRing;
800  }
801  if (T->t_p != NULL && i >= 0 && TN == 'T')
802  {
803  if (pNext(T->t_p) == NULL)
804  {
805  if (T->max_exp != NULL)
806  return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
807  }
808  else
809  {
810  if (T->max_exp == NULL)
811  return dReportError("%c[%d].max_exp is NULL", TN, i);
812  if (pNext(T->max_exp) != NULL)
813  return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
814 
815  pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
816  omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
817 #if KDEBUG > 0
818  if (! sloppy_max)
819  {
820  poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
821  p_Setm(T->max_exp, tailRing);
822  p_Setm(test_max, tailRing);
823  BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
824  if (! equal)
825  return dReportError("%c[%d].max out of sync", TN, i);
826  p_LmFree(test_max, tailRing);
827  }
828 #endif
829  }
830  }
831  }
832  else
833  {
834  if (T->p == NULL && i > 0)
835  return dReportError("%c[%d].p is NULL", TN, i);
837  }
838 
839  if ((i >= 0) && (T->pLength != 0)
840  && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
841  {
842  int l=T->pLength;
843  T->pLength=pLength(p);
844  return dReportError("%c[%d] pLength error: has %d, specified to have %d",
845  TN, i , pLength(p), l);
846  }
847 
848  // check FDeg, for elements in L and T
849  if (i >= 0 && (TN == 'T' || TN == 'L'))
850  {
851  // FDeg has ir element from T of L set
852  if (T->FDeg != T->pFDeg())
853  {
854  int d=T->FDeg;
855  T->FDeg=T->pFDeg();
856  return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
857  TN, i , T->pFDeg(), d);
858  }
859  }
860 
861  // check is_normalized for elements in T
862  if (i >= 0 && TN == 'T')
863  {
864  if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
865  return dReportError("T[%d] is_normalized error", i);
866 
867  }
868  return TRUE;
869 }
870 
871 BOOLEAN kTest_L(LObject *L, ring strat_tailRing,
872  BOOLEAN testp, int lpos, TSet T, int tlength)
873 {
874  if (L->p!=NULL)
875  {
876  nTest(pGetCoeff(L->p));
877  if ((L->t_p==NULL)&&(pNext(L->p)!=NULL)) p_Test(pNext(L->p),currRing);
878  }
879  if (L->t_p!=NULL)
880  {
881  nTest(pGetCoeff(L->t_p));
882  if (pNext(L->t_p)!=NULL) p_Test(pNext(L->t_p),strat_tailRing);
883  }
884  if ((L->p!=NULL)&&(L->t_p!=NULL)) assume(pGetCoeff(L->p)==pGetCoeff(L->t_p));
885 
886  if (testp)
887  {
888  poly pn = NULL;
889  if (L->bucket != NULL)
890  {
891  kFalseReturn(kbTest(L->bucket));
892  r_assume(L->bucket->bucket_ring == L->tailRing);
893  if (L->p != NULL && pNext(L->p) != NULL)
894  {
895  pn = pNext(L->p);
896  pNext(L->p) = NULL;
897  }
898  }
899  if (testp!=2) kFalseReturn(kTest_T(L, strat_tailRing, lpos, 'L'));
900  if (pn != NULL)
901  pNext(L->p) = pn;
902 
903  ring r;
904  poly p;
905  L->GetLm(p, r);
906  if (L->sev != 0 && p_GetShortExpVector(p, r) != L->sev)
907  {
908  return dReportError("L[%d] wrong sev: has %o, specified to have %o",
909  lpos, p_GetShortExpVector(p, r), L->sev);
910  }
911  }
912  if (L->p1 == NULL)
913  {
914  // L->p2 either NULL or "normal" poly
915  pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
916  }
917  else if (tlength > 0 && T != NULL && (lpos >=0) && (testp!=2))
918  {
919  // now p1 and p2 must be != NULL and must be contained in T
920  // unless for SHIFTGB: here each p_i must be in T or
921  // be shifted from an element in T -> to difficult to test
922  int i;
923  i = kFindInT(L->p1, T, tlength);
924  if (i < 0)
925  return dReportError("L[%d].p1 not in T",lpos);
926  i = kFindInT(L->p2, T, tlength);
927  if (i < 0)
928  return dReportError("L[%d].p2 not in T",lpos);
929  }
930  return TRUE;
931 }
932 
934 {
935  int i;
936  // test P
937  kFalseReturn(kTest_L(&(strat->P), strat->tailRing,
938  (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
939  -1, strat->T, strat->tl));
940 
941  // test T
942  if (strat->T != NULL)
943  {
944  for (i=0; i<=strat->tl; i++)
945  {
946  kFalseReturn(kTest_T(&(strat->T[i]), strat->tailRing, i, 'T'));
947  if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
948  return dReportError("strat->sevT[%d] out of sync", i);
949  }
950  }
951 
952  // test L
953  if (strat->L != NULL)
954  {
955  #ifdef HAVE_SHIFTBBA
956  if (strat->red==redFirstShift) // is this in bbaShift ?
957  {
958  for (i=0; i<=strat->Ll; i++)
959  {
960  kFalseReturn(kTest_L(&(strat->L[i]), strat->tailRing,
961  2, i,
962  strat->T, strat->tl));
963  }
964  }
965  else
966  #endif
967  for (i=0; i<=strat->Ll; i++)
968  {
969  kFalseReturn(kTest_L(&(strat->L[i]), strat->tailRing,
970  strat->L[i].Next() != strat->tail, i,
971  strat->T, strat->tl));
972  // may be unused
973  //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
974  // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
975  //{
976  // assume(strat->L[i].bucket != NULL);
977  //}
978  }
979  }
980 
981  // test S
982  if (strat->S != NULL)
983  kFalseReturn(kTest_S(strat));
984 
985  return TRUE;
986 }
987 
989 {
990  int i;
991  BOOLEAN ret = TRUE;
992  for (i=0; i<=strat->sl; i++)
993  {
994  if (strat->S[i] != NULL &&
995  strat->sevS[i] != pGetShortExpVector(strat->S[i]))
996  {
997  return dReportError("S[%d] wrong sev: has %o, specified to have %o",
998  i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
999  }
1000  }
1001  return ret;
1002 }
1003 
1004 
1005 
1007 {
1008  int i, j;
1009  // BOOLEAN ret = TRUE;
1010  kFalseReturn(kTest(strat));
1011 
1012  // test strat->R, strat->T[i].i_r
1013  for (i=0; i<=strat->tl; i++)
1014  {
1015  if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1016  return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1017  strat->T[i].i_r);
1018  if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1019  return dReportError("T[%d].i_r with R out of sync", i);
1020  }
1021  // test containment of S inT
1022  if (strat->S != NULL)
1023  {
1024  for (i=0; i<=strat->sl; i++)
1025  {
1026  j = kFindInT(strat->S[i], strat->T, strat->tl);
1027  if (j < 0)
1028  return dReportError("S[%d] not in T", i);
1029  if (strat->S_2_R[i] != strat->T[j].i_r)
1030  return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1031  i, strat->S_2_R[i], j, strat->T[j].i_r);
1032  }
1033  }
1034  // test strat->L[i].i_r1
1035  #ifdef HAVE_SHIFTBBA
1036  if (strat->red!=redFirstShift) // not from bbaShift
1037  #endif
1038  for (i=0; i<=strat->Ll; i++)
1039  {
1040  if (strat->L[i].p1 != NULL && strat->L[i].p2)
1041  {
1042  if (strat->L[i].i_r1 < 0 ||
1043  strat->L[i].i_r1 > strat->tl ||
1044  strat->L[i].T_1(strat)->p != strat->L[i].p1)
1045  return dReportError("L[%d].i_r1 out of sync", i);
1046  if (strat->L[i].i_r2 < 0 ||
1047  strat->L[i].i_r2 > strat->tl ||
1048  strat->L[i].T_2(strat)->p != strat->L[i].p2)
1049  return dReportError("L[%d].i_r2 out of sync", i);
1050  }
1051  else
1052  {
1053  if (strat->L[i].i_r1 != -1)
1054  return dReportError("L[%d].i_r1 out of sync", i);
1055  if (strat->L[i].i_r2 != -1)
1056  return dReportError("L[%d].i_r2 out of sync", i);
1057  }
1058  if (strat->L[i].i_r != -1)
1059  return dReportError("L[%d].i_r out of sync", i);
1060  }
1061  return TRUE;
1062 }
1063 
1064 #endif // KDEBUG
1065 
1066 /*2
1067 *cancels the i-th polynomial in the standardbase s
1068 */
1069 void deleteInS (int i,kStrategy strat)
1070 {
1071 #ifdef ENTER_USE_MEMMOVE
1072  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1073  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1074  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1075  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1076 #else
1077  int j;
1078  for (j=i; j<strat->sl; j++)
1079  {
1080  strat->S[j] = strat->S[j+1];
1081  strat->ecartS[j] = strat->ecartS[j+1];
1082  strat->sevS[j] = strat->sevS[j+1];
1083  strat->S_2_R[j] = strat->S_2_R[j+1];
1084  }
1085 #endif
1086  if (strat->lenS!=NULL)
1087  {
1088 #ifdef ENTER_USE_MEMMOVE
1089  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1090 #else
1091  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1092 #endif
1093  }
1094  if (strat->lenSw!=NULL)
1095  {
1096 #ifdef ENTER_USE_MEMMOVE
1097  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1098 #else
1099  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1100 #endif
1101  }
1102  if (strat->fromQ!=NULL)
1103  {
1104 #ifdef ENTER_USE_MEMMOVE
1105  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1106 #else
1107  for (j=i; j<strat->sl; j++)
1108  {
1109  strat->fromQ[j] = strat->fromQ[j+1];
1110  }
1111 #endif
1112  }
1113  strat->S[strat->sl] = NULL;
1114  strat->sl--;
1115 }
1116 
1117 
1118 /*2
1119 *cancels the i-th polynomial in the standardbase s
1120 */
1121 void deleteInSSba (int i,kStrategy strat)
1122 {
1123 #ifdef ENTER_USE_MEMMOVE
1124  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1125  memmove(&(strat->sig[i]), &(strat->sig[i+1]), (strat->sl - i)*sizeof(poly));
1126  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1127  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1128  memmove(&(strat->sevSig[i]),&(strat->sevSig[i+1]),(strat->sl - i)*sizeof(unsigned long));
1129  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1130 #else
1131  int j;
1132  for (j=i; j<strat->sl; j++)
1133  {
1134  strat->S[j] = strat->S[j+1];
1135  strat->sig[j] = strat->sig[j+1];
1136  strat->ecartS[j] = strat->ecartS[j+1];
1137  strat->sevS[j] = strat->sevS[j+1];
1138  strat->sevSig[j] = strat->sevSig[j+1];
1139  strat->S_2_R[j] = strat->S_2_R[j+1];
1140  }
1141 #endif
1142  if (strat->lenS!=NULL)
1143  {
1144 #ifdef ENTER_USE_MEMMOVE
1145  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1146 #else
1147  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1148 #endif
1149  }
1150  if (strat->lenSw!=NULL)
1151  {
1152 #ifdef ENTER_USE_MEMMOVE
1153  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1154 #else
1155  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1156 #endif
1157  }
1158  if (strat->fromQ!=NULL)
1159  {
1160 #ifdef ENTER_USE_MEMMOVE
1161  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1162 #else
1163  for (j=i; j<strat->sl; j++)
1164  {
1165  strat->fromQ[j] = strat->fromQ[j+1];
1166  }
1167 #endif
1168  }
1169  strat->S[strat->sl] = NULL;
1170  strat->sl--;
1171 }
1172 
1173 /*2
1174 *cancels the j-th polynomial in the set
1175 */
1176 void deleteInL (LSet set, int *length, int j,kStrategy strat)
1177 {
1178  if (set[j].lcm!=NULL)
1179  {
1180  kDeleteLcm(&set[j]);
1181  }
1182  if (set[j].sig!=NULL)
1183  {
1184 #ifdef HAVE_RINGS
1185  if (pGetCoeff(set[j].sig) != NULL)
1186  pLmDelete(set[j].sig);
1187  else
1188 #endif
1189  pLmFree(set[j].sig);
1190  }
1191  if (set[j].p!=NULL)
1192  {
1193  if (pNext(set[j].p) == strat->tail)
1194  {
1195 #ifdef HAVE_RINGS
1196  if (pGetCoeff(set[j].p) != NULL)
1197  pLmDelete(set[j].p);
1198  else
1199 #endif
1200  pLmFree(set[j].p);
1201  /*- tail belongs to several int spolys -*/
1202  }
1203  else
1204  {
1205  // search p in T, if it is there, do not delete it
1206  if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1207  {
1208  // assure that for global orderings kFindInT fails
1209  //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1210  set[j].Delete();
1211  }
1212  }
1213  }
1214  if (*length > 0 && j < *length)
1215  {
1216 #ifdef ENTER_USE_MEMMOVE
1217  memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1218 #else
1219  int i;
1220  for (i=j; i < (*length); i++)
1221  set[i] = set[i+1];
1222 #endif
1223  }
1224 #ifdef KDEBUG
1225  memset(&(set[*length]),0,sizeof(LObject));
1226 #endif
1227  (*length)--;
1228 }
1229 
1230 /*2
1231 *enters p at position at in L
1232 */
1233 void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1234 {
1235  // this should be corrected
1236  assume(p.FDeg == p.pFDeg());
1237 
1238  if ((*length)>=0)
1239  {
1240  if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1241  if (at <= (*length))
1242 #ifdef ENTER_USE_MEMMOVE
1243  memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1244 #else
1245  for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1246 #endif
1247  }
1248  else at = 0;
1249  (*set)[at] = p;
1250  (*length)++;
1251 }
1252 
1253 /*2
1254 * computes the normal ecart;
1255 * used in mora case and if pLexOrder & sugar in bba case
1256 */
1258 {
1259  h->FDeg = h->pFDeg();
1260  h->ecart = h->pLDeg() - h->FDeg;
1261  // h->length is set by h->pLDeg
1262  h->length=h->pLength=pLength(h->p);
1263 }
1264 
1266 {
1267  h->FDeg = h->pFDeg();
1268  (*h).ecart = 0;
1269  h->length=h->pLength=pLength(h->p);
1270 }
1271 
1272 void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1273 {
1274  Lp->FDeg = Lp->pFDeg();
1275  (*Lp).ecart = 0;
1276  (*Lp).length = 0;
1277 }
1278 
1279 void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1280 {
1281  Lp->FDeg = Lp->pFDeg();
1282  (*Lp).ecart = si_max(ecartF,ecartG);
1283  (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1284  (*Lp).length = 0;
1285 }
1286 
1287 /*2
1288 *if ecart1<=ecart2 it returns TRUE
1289 */
1290 static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1291 {
1292  return (ecart1 <= ecart2);
1293 }
1294 
1295 #ifdef HAVE_RINGS
1296 /*2
1297 * put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1298 */
1299 static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1300 {
1301  assume(atR >= 0);
1302  assume(i<=strat->sl);
1303  assume(p!=NULL);
1304  #if ALL_VS_JUST
1305  //Over rings, if we construct the strong pair, do not add the spair
1307  {
1308  number s,t,d;
1309  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1310 
1311  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1312  {
1313  nDelete(&d);
1314  nDelete(&s);
1315  nDelete(&t);
1316  return;
1317  }
1318  nDelete(&d);
1319  nDelete(&s);
1320  nDelete(&t);
1321  }
1322  #endif
1323  int j,compare,compareCoeff;
1324  LObject h;
1325 
1326 #ifdef KDEBUG
1327  h.ecart=0; h.length=0;
1328 #endif
1329  /*- computes the lcm(s[i],p) -*/
1330  h.lcm = p_Lcm(p,strat->S[i],currRing);
1331  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1332  if (nIsZero(pGetCoeff(h.lcm)))
1333  {
1334  strat->cp++;
1335  pLmDelete(h.lcm);
1336  return;
1337  }
1338  // basic chain criterion
1339  /*
1340  *the set B collects the pairs of type (S[j],p)
1341  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1342  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
1343  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
1344  */
1345 
1346  for(j = strat->Bl;j>=0;j--)
1347  {
1348  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1349  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1350  if(compare == pDivComp_EQUAL)
1351  {
1352  //They have the same LM
1353  if(compareCoeff == pDivComp_LESS)
1354  {
1355  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1356  {
1357  strat->c3++;
1358  pLmDelete(h.lcm);
1359  return;
1360  }
1361  break;
1362  }
1363  if(compareCoeff == pDivComp_GREATER)
1364  {
1365  deleteInL(strat->B,&strat->Bl,j,strat);
1366  strat->c3++;
1367  }
1368  if(compareCoeff == pDivComp_EQUAL)
1369  {
1370  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1371  {
1372  strat->c3++;
1373  pLmDelete(h.lcm);
1374  return;
1375  }
1376  break;
1377  }
1378  }
1379  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1380  {
1381  if(compare == pDivComp_LESS)
1382  {
1383  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1384  {
1385  strat->c3++;
1386  pLmDelete(h.lcm);
1387  return;
1388  }
1389  break;
1390  }
1391  if(compare == pDivComp_GREATER)
1392  {
1393  deleteInL(strat->B,&strat->Bl,j,strat);
1394  strat->c3++;
1395  }
1396  }
1397  }
1398  number s, t;
1399  poly m1, m2, gcd = NULL;
1400  s = pGetCoeff(strat->S[i]);
1401  t = pGetCoeff(p);
1402  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1403  ksCheckCoeff(&s, &t, currRing->cf);
1404  pSetCoeff0(m1, s);
1405  pSetCoeff0(m2, t);
1406  m2 = pNeg(m2);
1407  p_Test(m1,strat->tailRing);
1408  p_Test(m2,strat->tailRing);
1409  poly si = pCopy(strat->S[i]);
1410  poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1411  poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1412  pDelete(&si);
1413  p_LmDelete(m1, currRing);
1414  p_LmDelete(m2, currRing);
1415  if(sim2 == NULL)
1416  {
1417  if(pm1 == NULL)
1418  {
1419  if(h.lcm != NULL)
1420  {
1421  pLmDelete(h.lcm);
1422  h.lcm=NULL;
1423  }
1424  h.Clear();
1425  if (strat->pairtest==NULL) initPairtest(strat);
1426  strat->pairtest[i] = TRUE;
1427  strat->pairtest[strat->sl+1] = TRUE;
1428  return;
1429  }
1430  else
1431  {
1432  gcd = pm1;
1433  pm1 = NULL;
1434  }
1435  }
1436  else
1437  {
1438  if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1439  {
1440  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1441  pSetmComp(sim2);
1442  }
1443  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1444  gcd = p_Add_q(pm1, sim2, strat->tailRing);
1445  }
1446  p_Test(gcd, strat->tailRing);
1447 #ifdef KDEBUG
1448  if (TEST_OPT_DEBUG)
1449  {
1450  wrp(gcd);
1451  PrintLn();
1452  }
1453 #endif
1454  h.p = gcd;
1455  h.i_r = -1;
1456  if(h.p == NULL)
1457  {
1458  if (strat->pairtest==NULL) initPairtest(strat);
1459  strat->pairtest[i] = TRUE;
1460  strat->pairtest[strat->sl+1] = TRUE;
1461  return;
1462  }
1463  h.tailRing = strat->tailRing;
1464  int posx;
1465  //h.pCleardenom();
1466  //pSetm(h.p);
1467  h.i_r1 = -1;h.i_r2 = -1;
1468  strat->initEcart(&h);
1469  #if 1
1470  h.p2 = strat->S[i];
1471  h.p1 = p;
1472  #endif
1473  #if 1
1474  if (atR >= 0)
1475  {
1476  h.i_r1 = atR;
1477  h.i_r2 = strat->S_2_R[i];
1478  }
1479  #endif
1480  if (strat->Bl==-1)
1481  posx =0;
1482  else
1483  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1484  h.sev = pGetShortExpVector(h.p);
1485  if (currRing!=strat->tailRing)
1486  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1487  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1488  kTest_TS(strat);
1489 }
1490 
1491 
1492 /*2
1493 * put the lcm(s[i],p) into the set B
1494 */
1495 
1496 static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1497 {
1498  number d, s, t;
1499  assume(atR >= 0);
1500  poly m1, m2, gcd,si;
1501  if(!enterTstrong)
1502  {
1503  assume(i<=strat->sl);
1504  si = strat->S[i];
1505  }
1506  else
1507  {
1508  assume(i<=strat->tl);
1509  si = strat->T[i].p;
1510  }
1511  //printf("\n--------------------------------\n");
1512  //pWrite(p);pWrite(si);
1513  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1514 
1515  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1516  {
1517  nDelete(&d);
1518  nDelete(&s);
1519  nDelete(&t);
1520  return FALSE;
1521  }
1522 
1523  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1524  //p_Test(m1,strat->tailRing);
1525  //p_Test(m2,strat->tailRing);
1526  /*if(!enterTstrong)
1527  {
1528  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1529  {
1530  memset(&(strat->P), 0, sizeof(strat->P));
1531  kStratChangeTailRing(strat);
1532  strat->P = *(strat->R[atR]);
1533  p_LmFree(m1, strat->tailRing);
1534  p_LmFree(m2, strat->tailRing);
1535  p_LmFree(gcd, currRing);
1536  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1537  }
1538  }*/
1539  pSetCoeff0(m1, s);
1540  pSetCoeff0(m2, t);
1541  pSetCoeff0(gcd, d);
1542  p_Test(m1,strat->tailRing);
1543  p_Test(m2,strat->tailRing);
1544  //printf("\n===================================\n");
1545  //pWrite(m1);pWrite(m2);pWrite(gcd);
1546 #ifdef KDEBUG
1547  if (TEST_OPT_DEBUG)
1548  {
1549  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1550  PrintS("m1 = ");
1551  p_wrp(m1, strat->tailRing);
1552  PrintS(" ; m2 = ");
1553  p_wrp(m2, strat->tailRing);
1554  PrintS(" ; gcd = ");
1555  wrp(gcd);
1556  PrintS("\n--- create strong gcd poly: ");
1557  Print("\n p: %d", i);
1558  wrp(p);
1559  Print("\n strat->S[%d]: ", i);
1560  wrp(si);
1561  PrintS(" ---> ");
1562  }
1563 #endif
1564 
1565  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1566  p_LmDelete(m1, strat->tailRing);
1567  p_LmDelete(m2, strat->tailRing);
1568 #ifdef KDEBUG
1569  if (TEST_OPT_DEBUG)
1570  {
1571  wrp(gcd);
1572  PrintLn();
1573  }
1574 #endif
1575 
1576  LObject h;
1577  h.p = gcd;
1578  h.tailRing = strat->tailRing;
1579  int posx;
1580  h.pCleardenom();
1581  strat->initEcart(&h);
1582  h.sev = pGetShortExpVector(h.p);
1583  h.i_r1 = -1;h.i_r2 = -1;
1584  if (currRing!=strat->tailRing)
1585  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1586  if(!enterTstrong)
1587  {
1588  #if 1
1589  h.p1 = p;h.p2 = strat->S[i];
1590  #endif
1591  if (atR >= 0)
1592  {
1593  h.i_r2 = strat->S_2_R[i];
1594  h.i_r1 = atR;
1595  }
1596  else
1597  {
1598  h.i_r1 = -1;
1599  h.i_r2 = -1;
1600  }
1601  if (strat->Ll==-1)
1602  posx =0;
1603  else
1604  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1605  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1606  }
1607  else
1608  {
1609  if(h.IsNull()) return FALSE;
1610  //int red_result;
1611  //reduzieren ist teur!!!
1612  //if(strat->L != NULL)
1613  //red_result = strat->red(&h,strat);
1614  if(!h.IsNull())
1615  {
1616  enterT(h, strat,-1);
1617  //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1618  //strat->enterS(h,pos,strat,-1);
1619  }
1620  }
1621  return TRUE;
1622 }
1623 
1625 {
1626  if(strat->sl < 0) return FALSE;
1627  int i;
1628  for(i=0;i<strat->sl;i++)
1629  {
1630  //Construct the gcd pair between h and S[i]
1631  number d, s, t;
1632  poly m1, m2, gcd;
1633  d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1634  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1635  {
1636  nDelete(&d);
1637  nDelete(&s);
1638  nDelete(&t);
1639  }
1640  else
1641  {
1642  k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1643  pSetCoeff0(m1, s);
1644  pSetCoeff0(m2, t);
1645  pSetCoeff0(gcd, d);
1646  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);
1647  poly pSigMult = p_Copy(h->sig,currRing);
1648  poly sSigMult = p_Copy(strat->sig[i],currRing);
1649  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1650  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1651  p_LmDelete(m1, strat->tailRing);
1652  p_LmDelete(m2, strat->tailRing);
1653  poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1654  if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1655  {
1656  pDelete(&h->p);
1657  h->p = gcd;
1658  pDelete(&h->sig);
1659  h->sig = pairsig;
1660  pNext(h->sig) = NULL;
1661  strat->initEcart(h);
1662  h->sev = pGetShortExpVector(h->p);
1663  h->sevSig = pGetShortExpVector(h->sig);
1664  h->i_r1 = -1;h->i_r2 = -1;
1665  if(h->lcm != NULL)
1666  {
1667  pLmDelete(h->lcm);
1668  h->lcm = NULL;
1669  }
1670  if (currRing!=strat->tailRing)
1671  h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1672  return TRUE;
1673  }
1674  //Delete what you didn't use
1675  pDelete(&gcd);
1676  pDelete(&pairsig);
1677  }
1678  }
1679  return FALSE;
1680 }
1681 
1682 static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1683 {
1684  number d, s, t;
1685  assume(atR >= 0);
1686  poly m1, m2, gcd,si;
1687  assume(i<=strat->sl);
1688  si = strat->S[i];
1689  //printf("\n--------------------------------\n");
1690  //pWrite(p);pWrite(si);
1691  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1692 
1693  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1694  {
1695  nDelete(&d);
1696  nDelete(&s);
1697  nDelete(&t);
1698  return FALSE;
1699  }
1700 
1701  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1702  //p_Test(m1,strat->tailRing);
1703  //p_Test(m2,strat->tailRing);
1704  /*if(!enterTstrong)
1705  {
1706  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1707  {
1708  memset(&(strat->P), 0, sizeof(strat->P));
1709  kStratChangeTailRing(strat);
1710  strat->P = *(strat->R[atR]);
1711  p_LmFree(m1, strat->tailRing);
1712  p_LmFree(m2, strat->tailRing);
1713  p_LmFree(gcd, currRing);
1714  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1715  }
1716  }*/
1717  pSetCoeff0(m1, s);
1718  pSetCoeff0(m2, t);
1719  pSetCoeff0(gcd, d);
1720  p_Test(m1,strat->tailRing);
1721  p_Test(m2,strat->tailRing);
1722  //printf("\n===================================\n");
1723  //pWrite(m1);pWrite(m2);pWrite(gcd);
1724 #ifdef KDEBUG
1725  if (TEST_OPT_DEBUG)
1726  {
1727  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1728  PrintS("m1 = ");
1729  p_wrp(m1, strat->tailRing);
1730  PrintS(" ; m2 = ");
1731  p_wrp(m2, strat->tailRing);
1732  PrintS(" ; gcd = ");
1733  wrp(gcd);
1734  PrintS("\n--- create strong gcd poly: ");
1735  Print("\n p: %d", i);
1736  wrp(p);
1737  Print("\n strat->S[%d]: ", i);
1738  wrp(si);
1739  PrintS(" ---> ");
1740  }
1741 #endif
1742 
1743  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1744 
1745 #ifdef KDEBUG
1746  if (TEST_OPT_DEBUG)
1747  {
1748  wrp(gcd);
1749  PrintLn();
1750  }
1751 #endif
1752 
1753  //Check and set the signatures
1754  poly pSigMult = p_Copy(sig,currRing);
1755  poly sSigMult = p_Copy(strat->sig[i],currRing);
1756  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1757  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1758  p_LmDelete(m1, strat->tailRing);
1759  p_LmDelete(m2, strat->tailRing);
1760  poly pairsig;
1761  if(pLmCmp(pSigMult,sSigMult) == 0)
1762  {
1763  //Same lm, have to add them
1764  pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1765  //This might be zero
1766  }
1767  else
1768  {
1769  //Set the sig to either pSigMult or sSigMult
1770  if(pLtCmp(pSigMult,sSigMult)==1)
1771  {
1772  pairsig = pSigMult;
1773  pDelete(&sSigMult);
1774  }
1775  else
1776  {
1777  pairsig = sSigMult;
1778  pDelete(&pSigMult);
1779  }
1780  }
1781 
1782  LObject h;
1783  h.p = gcd;
1784  h.tailRing = strat->tailRing;
1785  h.sig = pairsig;
1786  int posx;
1787  h.pCleardenom();
1788  strat->initEcart(&h);
1789  h.sev = pGetShortExpVector(h.p);
1790  h.i_r1 = -1;h.i_r2 = -1;
1791  if (currRing!=strat->tailRing)
1792  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1793  if(h.sig == NULL)
1794  {
1795  //sigdrop since we loose the signature
1796  strat->sigdrop = TRUE;
1797  //Try to reduce it as far as we can via redRing
1798  int red_result = redRing(&h,strat);
1799  if(red_result == 0)
1800  {
1801  // Cancel the sigdrop
1802  p_Delete(&h.sig,currRing);h.sig = NULL;
1803  strat->sigdrop = FALSE;
1804  return FALSE;
1805  }
1806  else
1807  {
1808  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1809  #if 1
1810  strat->enterS(h,0,strat,strat->tl);
1811  #endif
1812  return FALSE;
1813  }
1814  }
1815  if(!nGreaterZero(pGetCoeff(h.sig)))
1816  {
1817  h.sig = pNeg(h.sig);
1818  h.p = pNeg(h.p);
1819  }
1820 
1821  if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1822  {
1823  strat->sigdrop = TRUE;
1824  // Completely reduce it
1825  int red_result = redRing(&h,strat);
1826  if(red_result == 0)
1827  {
1828  // Reduced to 0
1829  strat->sigdrop = FALSE;
1830  p_Delete(&h.sig,currRing);h.sig = NULL;
1831  return FALSE;
1832  }
1833  else
1834  {
1835  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1836  // 0 - add just the original poly causing the sigdrop, 1 - add also this
1837  #if 1
1838  strat->enterS(h,0,strat, strat->tl+1);
1839  #endif
1840  return FALSE;
1841  }
1842  }
1843  //Check for sigdrop
1844  if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1845  {
1846  strat->sigdrop = TRUE;
1847  //Enter this element to S
1848  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1849  strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1850  }
1851  #if 1
1852  h.p1 = p;h.p2 = strat->S[i];
1853  #endif
1854  if (atR >= 0)
1855  {
1856  h.i_r2 = strat->S_2_R[i];
1857  h.i_r1 = atR;
1858  }
1859  else
1860  {
1861  h.i_r1 = -1;
1862  h.i_r2 = -1;
1863  }
1864  if (strat->Ll==-1)
1865  posx =0;
1866  else
1867  posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1868  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1869  return TRUE;
1870 }
1871 #endif
1872 
1873 /*2
1874 * put the pair (s[i],p) into the set B, ecart=ecart(p)
1875 */
1876 
1877 void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1878 {
1879  assume(i<=strat->sl);
1880 
1881  int l,j,compare;
1882  LObject Lp;
1883  Lp.i_r = -1;
1884 
1885 #ifdef KDEBUG
1886  Lp.ecart=0; Lp.length=0;
1887 #endif
1888  /*- computes the lcm(s[i],p) -*/
1889  Lp.lcm = pInit();
1890 
1891 #ifndef HAVE_RATGRING
1892  pLcm(p,strat->S[i],Lp.lcm);
1893 #elif defined(HAVE_RATGRING)
1894  if (rIsRatGRing(currRing))
1895  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1896  else
1897  pLcm(p,strat->S[i],Lp.lcm);
1898 #endif
1899  pSetm(Lp.lcm);
1900 
1901 
1902  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
1903  {
1904  if((!((strat->ecartS[i]>0)&&(ecart>0)))
1905  && pHasNotCF(p,strat->S[i]))
1906  {
1907  /*
1908  *the product criterion has applied for (s,p),
1909  *i.e. lcm(s,p)=product of the leading terms of s and p.
1910  *Suppose (s,r) is in L and the leading term
1911  *of p divides lcm(s,r)
1912  *(==> the leading term of p divides the leading term of r)
1913  *but the leading term of s does not divide the leading term of r
1914  *(notice that tis condition is automatically satisfied if r is still
1915  *in S), then (s,r) can be cancelled.
1916  *This should be done here because the
1917  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1918  *
1919  *Moreover, skipping (s,r) holds also for the noncommutative case.
1920  */
1921  strat->cp++;
1922  pLmFree(Lp.lcm);
1923  return;
1924  }
1925  else
1926  Lp.ecart = si_max(ecart,strat->ecartS[i]);
1927  if (strat->fromT && (strat->ecartS[i]>ecart))
1928  {
1929  pLmFree(Lp.lcm);
1930  return;
1931  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
1932  }
1933  /*
1934  *the set B collects the pairs of type (S[j],p)
1935  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
1936  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
1937  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
1938  */
1939  {
1940  j = strat->Bl;
1941  loop
1942  {
1943  if (j < 0) break;
1944  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
1945  if ((compare==1)
1946  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
1947  {
1948  strat->c3++;
1949  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1950  {
1951  pLmFree(Lp.lcm);
1952  return;
1953  }
1954  break;
1955  }
1956  else
1957  if ((compare ==-1)
1958  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
1959  {
1960  deleteInL(strat->B,&strat->Bl,j,strat);
1961  strat->c3++;
1962  }
1963  j--;
1964  }
1965  }
1966  }
1967  else /*sugarcrit*/
1968  {
1969  if (ALLOW_PROD_CRIT(strat))
1970  {
1971  // if currRing->nc_type!=quasi (or skew)
1972  // TODO: enable productCrit for super commutative algebras...
1973  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
1974  pHasNotCF(p,strat->S[i]))
1975  {
1976  /*
1977  *the product criterion has applied for (s,p),
1978  *i.e. lcm(s,p)=product of the leading terms of s and p.
1979  *Suppose (s,r) is in L and the leading term
1980  *of p devides lcm(s,r)
1981  *(==> the leading term of p devides the leading term of r)
1982  *but the leading term of s does not devide the leading term of r
1983  *(notice that tis condition is automatically satisfied if r is still
1984  *in S), then (s,r) can be canceled.
1985  *This should be done here because the
1986  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1987  */
1988  strat->cp++;
1989  pLmFree(Lp.lcm);
1990  return;
1991  }
1992  if (strat->fromT && (strat->ecartS[i]>ecart))
1993  {
1994  pLmFree(Lp.lcm);
1995  return;
1996  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
1997  }
1998  /*
1999  *the set B collects the pairs of type (S[j],p)
2000  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2001  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2002  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2003  */
2004  for(j = strat->Bl;j>=0;j--)
2005  {
2006  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2007  if (compare==1)
2008  {
2009  strat->c3++;
2010  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2011  {
2012  pLmFree(Lp.lcm);
2013  return;
2014  }
2015  break;
2016  }
2017  else
2018  if (compare ==-1)
2019  {
2020  deleteInL(strat->B,&strat->Bl,j,strat);
2021  strat->c3++;
2022  }
2023  }
2024  }
2025  }
2026  /*
2027  *the pair (S[i],p) enters B if the spoly != 0
2028  */
2029  /*- compute the short s-polynomial -*/
2030  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2031  pNorm(p);
2032 
2033  if ((strat->S[i]==NULL) || (p==NULL))
2034  return;
2035 
2036  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2037  Lp.p=NULL;
2038  else
2039  {
2040  #ifdef HAVE_PLURAL
2041  if ( rIsPluralRing(currRing) )
2042  {
2043  if(pHasNotCF(p, strat->S[i]))
2044  {
2045  if(ncRingType(currRing) == nc_lie)
2046  {
2047  // generalized prod-crit for lie-type
2048  strat->cp++;
2049  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2050  }
2051  else
2052  if( ALLOW_PROD_CRIT(strat) )
2053  {
2054  // product criterion for homogeneous case in SCA
2055  strat->cp++;
2056  Lp.p = NULL;
2057  }
2058  else
2059  {
2060  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2061  nc_CreateShortSpoly(strat->S[i], p, currRing);
2062  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2063  pNext(Lp.p) = strat->tail; // !!!
2064  }
2065  }
2066  else
2067  {
2068  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2069  nc_CreateShortSpoly(strat->S[i], p, currRing);
2070 
2071  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2072  pNext(Lp.p) = strat->tail; // !!!
2073  }
2074  }
2075  else
2076  #endif
2077  {
2079  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2080  }
2081  }
2082  if (Lp.p == NULL)
2083  {
2084  /*- the case that the s-poly is 0 -*/
2085  if (strat->pairtest==NULL) initPairtest(strat);
2086  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2087  strat->pairtest[strat->sl+1] = TRUE;
2088  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2089  /*
2090  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2091  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2092  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2093  *term of p devides the lcm(s,r)
2094  *(this canceling should be done here because
2095  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2096  *the first case is handeled in chainCrit
2097  */
2098  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2099  }
2100  else
2101  {
2102  /*- the pair (S[i],p) enters B -*/
2103  Lp.p1 = strat->S[i];
2104  Lp.p2 = p;
2105 
2106  if (
2108 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2109  )
2110  {
2111  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2112  pNext(Lp.p) = strat->tail; // !!!
2113  }
2114 
2115  if (atR >= 0)
2116  {
2117  Lp.i_r1 = strat->S_2_R[i];
2118  Lp.i_r2 = atR;
2119  }
2120  else
2121  {
2122  Lp.i_r1 = -1;
2123  Lp.i_r2 = -1;
2124  }
2125  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2126 
2128  {
2129  if (!rIsPluralRing(currRing)
2131  && (Lp.p->coef!=NULL))
2132  nDelete(&(Lp.p->coef));
2133  }
2134 
2135  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2136  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2137  }
2138 }
2139 
2140 /// p_HasNotCF for the IDLIFT case: ignore component
2141 static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2142 {
2143  int i = rVar(r);
2144  loop
2145  {
2146  if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2147  return FALSE;
2148  i--;
2149  if (i == 0)
2150  return TRUE;
2151  }
2152 }
2153 
2154 /*2
2155 * put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2156 */
2157 
2158 static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2159 {
2160  assume(ALLOW_PROD_CRIT(strat));
2162  assume(strat->syzComp==1);
2163  assume(i<=strat->sl);
2164 
2165  if ((strat->S[i]==NULL) || (p==NULL))
2166  return;
2167 
2168  int l,j,compare;
2169  LObject Lp;
2170  Lp.i_r = -1;
2171 
2172 #ifdef KDEBUG
2173  Lp.ecart=0; Lp.length=0;
2174 #endif
2175  /*- computes the lcm(s[i],p) -*/
2176  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2177 
2178  if (strat->sugarCrit)
2179  {
2180  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2181  && p_HasNotCF_Lift(p,strat->S[i],currRing))
2182  {
2183  /*
2184  *the product criterion has applied for (s,p),
2185  *i.e. lcm(s,p)=product of the leading terms of s and p.
2186  *Suppose (s,r) is in L and the leading term
2187  *of p divides lcm(s,r)
2188  *(==> the leading term of p divides the leading term of r)
2189  *but the leading term of s does not divide the leading term of r
2190  *(notice that tis condition is automatically satisfied if r is still
2191  *in S), then (s,r) can be cancelled.
2192  *This should be done here because the
2193  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2194  *
2195  *Moreover, skipping (s,r) holds also for the noncommutative case.
2196  */
2197  strat->cp++;
2198  pLmFree(Lp.lcm);
2199  return;
2200  }
2201  else
2202  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2203  if (strat->fromT && (strat->ecartS[i]>ecart))
2204  {
2205  pLmFree(Lp.lcm);
2206  return;
2207  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2208  }
2209  /*
2210  *the set B collects the pairs of type (S[j],p)
2211  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2212  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2213  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2214  */
2215  {
2216  j = strat->Bl;
2217  loop
2218  {
2219  if (j < 0) break;
2220  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2221  if ((compare==1)
2222  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2223  {
2224  strat->c3++;
2225  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2226  {
2227  pLmFree(Lp.lcm);
2228  return;
2229  }
2230  break;
2231  }
2232  else
2233  if ((compare ==-1)
2234  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2235  {
2236  deleteInL(strat->B,&strat->Bl,j,strat);
2237  strat->c3++;
2238  }
2239  j--;
2240  }
2241  }
2242  }
2243  else /*sugarcrit*/
2244  {
2245  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2246  p_HasNotCF_Lift(p,strat->S[i],currRing))
2247  {
2248  /*
2249  *the product criterion has applied for (s,p),
2250  *i.e. lcm(s,p)=product of the leading terms of s and p.
2251  *Suppose (s,r) is in L and the leading term
2252  *of p devides lcm(s,r)
2253  *(==> the leading term of p devides the leading term of r)
2254  *but the leading term of s does not devide the leading term of r
2255  *(notice that tis condition is automatically satisfied if r is still
2256  *in S), then (s,r) can be canceled.
2257  *This should be done here because the
2258  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2259  */
2260  strat->cp++;
2261  pLmFree(Lp.lcm);
2262  return;
2263  }
2264  if (strat->fromT && (strat->ecartS[i]>ecart))
2265  {
2266  pLmFree(Lp.lcm);
2267  return;
2268  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2269  }
2270  /*
2271  *the set B collects the pairs of type (S[j],p)
2272  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2273  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2274  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2275  */
2276  for(j = strat->Bl;j>=0;j--)
2277  {
2278  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2279  if (compare==1)
2280  {
2281  strat->c3++;
2282  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2283  {
2284  pLmFree(Lp.lcm);
2285  return;
2286  }
2287  break;
2288  }
2289  else
2290  if (compare ==-1)
2291  {
2292  deleteInL(strat->B,&strat->Bl,j,strat);
2293  strat->c3++;
2294  }
2295  }
2296  }
2297  /*
2298  *the pair (S[i],p) enters B if the spoly != 0
2299  */
2300  /*- compute the short s-polynomial -*/
2301  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2302  pNorm(p);
2303 
2304  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2305  Lp.p=NULL;
2306  else
2307  {
2309  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2310  }
2311  if (Lp.p == NULL)
2312  {
2313  /*- the case that the s-poly is 0 -*/
2314  if (strat->pairtest==NULL) initPairtest(strat);
2315  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2316  strat->pairtest[strat->sl+1] = TRUE;
2317  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2318  /*
2319  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2320  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2321  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2322  *term of p devides the lcm(s,r)
2323  *(this canceling should be done here because
2324  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2325  *the first case is handeled in chainCrit
2326  */
2327  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2328  }
2329  else
2330  {
2331  /*- the pair (S[i],p) enters B -*/
2332  Lp.p1 = strat->S[i];
2333  Lp.p2 = p;
2334 
2335  pNext(Lp.p) = strat->tail; // !!!
2336 
2337  if (atR >= 0)
2338  {
2339  Lp.i_r1 = strat->S_2_R[i];
2340  Lp.i_r2 = atR;
2341  }
2342  else
2343  {
2344  Lp.i_r1 = -1;
2345  Lp.i_r2 = -1;
2346  }
2347  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2348 
2350  {
2351  if (!rIsPluralRing(currRing)
2353  && (Lp.p->coef!=NULL))
2354  nDelete(&(Lp.p->coef));
2355  }
2356 
2357  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2358  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2359  }
2360 }
2361 
2362 /*2
2363 * put the pair (s[i],p) into the set B, ecart=ecart(p)
2364 * NOTE: here we need to add the signature-based criteria
2365 */
2366 
2367 #ifdef DEBUGF5
2368 static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2369 #else
2370 static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2371 #endif
2372 {
2373  assume(i<=strat->sl);
2374 
2375  int l;
2376  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2377  // the corresponding signatures for criteria checks
2378  LObject Lp;
2379  poly pSigMult = p_Copy(pSig,currRing);
2380  poly sSigMult = p_Copy(strat->sig[i],currRing);
2381  unsigned long pSigMultNegSev,sSigMultNegSev;
2382  Lp.i_r = -1;
2383 
2384 #ifdef KDEBUG
2385  Lp.ecart=0; Lp.length=0;
2386 #endif
2387  /*- computes the lcm(s[i],p) -*/
2388  Lp.lcm = pInit();
2389  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2390 #ifndef HAVE_RATGRING
2391  pLcm(p,strat->S[i],Lp.lcm);
2392 #elif defined(HAVE_RATGRING)
2393  if (rIsRatGRing(currRing))
2394  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2395  else
2396  pLcm(p,strat->S[i],Lp.lcm);
2397 #endif
2398  pSetm(Lp.lcm);
2399 
2400  // set coeffs of multipliers m1 and m2
2401  pSetCoeff0(m1, nInit(1));
2402  pSetCoeff0(m2, nInit(1));
2403 //#if 1
2404 #ifdef DEBUGF5
2405  PrintS("P1 ");
2406  pWrite(pHead(p));
2407  PrintS("P2 ");
2408  pWrite(pHead(strat->S[i]));
2409  PrintS("M1 ");
2410  pWrite(m1);
2411  PrintS("M2 ");
2412  pWrite(m2);
2413 #endif
2414  // get multiplied signatures for testing
2415  pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2416  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2417  sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2418  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2419 
2420 //#if 1
2421 #ifdef DEBUGF5
2422  PrintS("----------------\n");
2423  pWrite(pSigMult);
2424  pWrite(sSigMult);
2425  PrintS("----------------\n");
2426  Lp.checked = 0;
2427 #endif
2428  int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2429 //#if 1
2430 #if DEBUGF5
2431  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2432  pWrite(pSigMult);
2433  pWrite(sSigMult);
2434 #endif
2435  if(sigCmp==0)
2436  {
2437  // printf("!!!! EQUAL SIGS !!!!\n");
2438  // pSig = sSig, delete element due to Rewritten Criterion
2439  pDelete(&pSigMult);
2440  pDelete(&sSigMult);
2441  if (rField_is_Ring(currRing))
2442  pLmDelete(Lp.lcm);
2443  else
2444  pLmFree(Lp.lcm);
2445  pDelete (&m1);
2446  pDelete (&m2);
2447  return;
2448  }
2449  // testing by syzCrit = F5 Criterion
2450  // testing by rewCrit1 = Rewritten Criterion
2451  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2452  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2453  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2454  || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2455  )
2456  {
2457  pDelete(&pSigMult);
2458  pDelete(&sSigMult);
2459  if (rField_is_Ring(currRing))
2460  pLmDelete(Lp.lcm);
2461  else
2462  pLmFree(Lp.lcm);
2463  pDelete (&m1);
2464  pDelete (&m2);
2465  return;
2466  }
2467  /*
2468  *the pair (S[i],p) enters B if the spoly != 0
2469  */
2470  /*- compute the short s-polynomial -*/
2471  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2472  pNorm(p);
2473 
2474  if ((strat->S[i]==NULL) || (p==NULL))
2475  return;
2476 
2477  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2478  Lp.p=NULL;
2479  else
2480  {
2481  #ifdef HAVE_PLURAL
2482  if ( rIsPluralRing(currRing) )
2483  {
2484  if(pHasNotCF(p, strat->S[i]))
2485  {
2486  if(ncRingType(currRing) == nc_lie)
2487  {
2488  // generalized prod-crit for lie-type
2489  strat->cp++;
2490  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2491  }
2492  else
2493  if( ALLOW_PROD_CRIT(strat) )
2494  {
2495  // product criterion for homogeneous case in SCA
2496  strat->cp++;
2497  Lp.p = NULL;
2498  }
2499  else
2500  {
2501  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2502  nc_CreateShortSpoly(strat->S[i], p, currRing);
2503 
2504  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2505  pNext(Lp.p) = strat->tail; // !!!
2506  }
2507  }
2508  else
2509  {
2510  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2511  nc_CreateShortSpoly(strat->S[i], p, currRing);
2512 
2513  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2514  pNext(Lp.p) = strat->tail; // !!!
2515  }
2516  }
2517  else
2518  #endif
2519  {
2521  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2522  }
2523  }
2524  // store from which element this pair comes from for further tests
2525  //Lp.from = strat->sl+1;
2526  if(sigCmp==currRing->OrdSgn)
2527  {
2528  // pSig > sSig
2529  pDelete (&sSigMult);
2530  Lp.sig = pSigMult;
2531  Lp.sevSig = ~pSigMultNegSev;
2532  }
2533  else
2534  {
2535  // pSig < sSig
2536  pDelete (&pSigMult);
2537  Lp.sig = sSigMult;
2538  Lp.sevSig = ~sSigMultNegSev;
2539  }
2540  if (Lp.p == NULL)
2541  {
2542  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2543  int pos = posInSyz(strat, Lp.sig);
2544  enterSyz(Lp, strat, pos);
2545  }
2546  else
2547  {
2548  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2549  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2550  {
2551  pLmFree(Lp.lcm);
2552  pDelete(&Lp.sig);
2553  pDelete (&m1);
2554  pDelete (&m2);
2555  return;
2556  }
2557  // in any case Lp is checked up to the next strat->P which is added
2558  // to S right after this critical pair creation.
2559  // NOTE: this even holds if the 2nd generator gives the bigger signature
2560  // moreover, this improves rewCriterion,
2561  // i.e. strat->checked > strat->from if and only if the 2nd generator
2562  // gives the bigger signature.
2563  Lp.checked = strat->sl+1;
2564  // at this point it is clear that the pair will be added to L, since it has
2565  // passed all tests up to now
2566 
2567  // adds buchberger's first criterion
2568  if (pLmCmp(m2,pHead(p)) == 0)
2569  {
2570  Lp.prod_crit = TRUE; // Product Criterion
2571 #if 0
2572  int pos = posInSyz(strat, Lp.sig);
2573  enterSyz(Lp, strat, pos);
2574  pDelete (&m1);
2575  pDelete (&m2);
2576  return;
2577 #endif
2578  }
2579  pDelete (&m1);
2580  pDelete (&m2);
2581 #if DEBUGF5
2582  PrintS("SIGNATURE OF PAIR: ");
2583  pWrite(Lp.sig);
2584 #endif
2585  /*- the pair (S[i],p) enters B -*/
2586  Lp.p1 = strat->S[i];
2587  Lp.p2 = p;
2588 
2589  if (
2591 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2592  )
2593  {
2594  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2595  pNext(Lp.p) = strat->tail; // !!!
2596  }
2597 
2598  if (atR >= 0)
2599  {
2600  Lp.i_r1 = strat->S_2_R[i];
2601  Lp.i_r2 = atR;
2602  }
2603  else
2604  {
2605  Lp.i_r1 = -1;
2606  Lp.i_r2 = -1;
2607  }
2608  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2609 
2611  {
2612  if (!rIsPluralRing(currRing)
2614  && (Lp.p->coef!=NULL))
2615  nDelete(&(Lp.p->coef));
2616  }
2617 
2618  l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2619  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2620  }
2621 }
2622 
2623 
2624 #ifdef DEBUGF5
2625 static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2626 #else
2627 static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2628 #endif
2629 {
2630  #if ALL_VS_JUST
2631  //Over rings, if we construct the strong pair, do not add the spair
2633  {
2634  number s,t,d;
2635  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2636 
2637  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2638  {
2639  nDelete(&d);
2640  nDelete(&s);
2641  nDelete(&t);
2642  return;
2643  }
2644  nDelete(&d);
2645  nDelete(&s);
2646  nDelete(&t);
2647  }
2648  #endif
2649  assume(i<=strat->sl);
2650  int l;
2651  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2652  // the corresponding signatures for criteria checks
2653  LObject Lp;
2654  poly pSigMult = p_Copy(pSig,currRing);
2655  poly sSigMult = p_Copy(strat->sig[i],currRing);
2656  unsigned long pSigMultNegSev,sSigMultNegSev;
2657  Lp.i_r = -1;
2658 
2659 #ifdef KDEBUG
2660  Lp.ecart=0; Lp.length=0;
2661 #endif
2662  /*- computes the lcm(s[i],p) -*/
2663  Lp.lcm = pInit();
2664  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2665 #ifndef HAVE_RATGRING
2666  pLcm(p,strat->S[i],Lp.lcm);
2667 #elif defined(HAVE_RATGRING)
2668  if (rIsRatGRing(currRing))
2669  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2670  else
2671  pLcm(p,strat->S[i],Lp.lcm);
2672 #endif
2673  pSetm(Lp.lcm);
2674 
2675  // set coeffs of multipliers m1 and m2
2677  {
2678  number s = nCopy(pGetCoeff(strat->S[i]));
2679  number t = nCopy(pGetCoeff(p));
2680  pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2681  ksCheckCoeff(&s, &t, currRing->cf);
2682  pSetCoeff0(m1,s);
2683  pSetCoeff0(m2,t);
2684  }
2685  else
2686  {
2687  pSetCoeff0(m1, nInit(1));
2688  pSetCoeff0(m2, nInit(1));
2689  }
2690 #ifdef DEBUGF5
2691  Print("P1 ");
2692  pWrite(pHead(p));
2693  Print("P2 ");
2694  pWrite(pHead(strat->S[i]));
2695  Print("M1 ");
2696  pWrite(m1);
2697  Print("M2 ");
2698  pWrite(m2);
2699 #endif
2700 
2701  // get multiplied signatures for testing
2702  pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2703  if(pSigMult != NULL)
2704  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2705  sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2706  if(sSigMult != NULL)
2707  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2708 //#if 1
2709 #ifdef DEBUGF5
2710  Print("----------------\n");
2711  pWrite(pSigMult);
2712  pWrite(sSigMult);
2713  Print("----------------\n");
2714  Lp.checked = 0;
2715 #endif
2716  int sigCmp;
2717  if(pSigMult != NULL && sSigMult != NULL)
2718  {
2720  sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2721  else
2722  sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2723  }
2724  else
2725  {
2726  if(pSigMult == NULL)
2727  {
2728  if(sSigMult == NULL)
2729  sigCmp = 0;
2730  else
2731  sigCmp = -1;
2732  }
2733  else
2734  sigCmp = 1;
2735  }
2736 //#if 1
2737 #if DEBUGF5
2738  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2739  pWrite(pSigMult);
2740  pWrite(sSigMult);
2741 #endif
2742  //In the ring case we already build the sig
2744  {
2745  if(sigCmp == 0)
2746  {
2747  //sigdrop since we loose the signature
2748  strat->sigdrop = TRUE;
2749  //Try to reduce it as far as we can via redRing
2751  {
2752  poly p1 = p_Copy(p,currRing);
2753  poly p2 = p_Copy(strat->S[i],currRing);
2754  p1 = p_Mult_mm(p1,m1,currRing);
2755  p2 = p_Mult_mm(p2,m2,currRing);
2756  Lp.p = p_Sub(p1,p2,currRing);
2757  if(Lp.p != NULL)
2758  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2759  }
2760  int red_result = redRing(&Lp,strat);
2761  if(red_result == 0)
2762  {
2763  // Cancel the sigdrop
2764  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2765  strat->sigdrop = FALSE;
2766  return;
2767  }
2768  else
2769  {
2770  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2771  #if 1
2772  strat->enterS(Lp,0,strat,strat->tl);
2773  #endif
2774  return;
2775  }
2776  }
2777  if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2778  {
2779  //Same lm, have to substract
2780  Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2781  }
2782  else
2783  {
2784  if(sigCmp == 1)
2785  {
2786  Lp.sig = pCopy(pSigMult);
2787  }
2788  if(sigCmp == -1)
2789  {
2790  Lp.sig = pNeg(pCopy(sSigMult));
2791  }
2792  }
2793  Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2794  }
2795 
2796  #if 0
2797  if(sigCmp==0)
2798  {
2799  // printf("!!!! EQUAL SIGS !!!!\n");
2800  // pSig = sSig, delete element due to Rewritten Criterion
2801  pDelete(&pSigMult);
2802  pDelete(&sSigMult);
2803  if (rField_is_Ring(currRing))
2804  pLmDelete(Lp.lcm);
2805  else
2806  pLmFree(Lp.lcm);
2807  pDelete (&m1);
2808  pDelete (&m2);
2809  return;
2810  }
2811  #endif
2812  // testing by syzCrit = F5 Criterion
2813  // testing by rewCrit1 = Rewritten Criterion
2814  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2815  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2816  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2817  // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2818  //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2819  )
2820  {
2821  pDelete(&pSigMult);
2822  pDelete(&sSigMult);
2823  if (rField_is_Ring(currRing))
2824  pLmDelete(Lp.lcm);
2825  else
2826  pLmFree(Lp.lcm);
2827  pDelete (&m1);
2828  pDelete (&m2);
2829  return;
2830  }
2831  /*
2832  *the pair (S[i],p) enters B if the spoly != 0
2833  */
2834  /*- compute the short s-polynomial -*/
2835  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2836  pNorm(p);
2837 
2838  if ((strat->S[i]==NULL) || (p==NULL))
2839  return;
2840 
2841  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2842  Lp.p=NULL;
2843  else
2844  {
2845  //Build p
2847  {
2848  poly p1 = p_Copy(p,currRing);
2849  poly p2 = p_Copy(strat->S[i],currRing);
2850  p1 = p_Mult_mm(p1,m1,currRing);
2851  p2 = p_Mult_mm(p2,m2,currRing);
2852  Lp.p = p_Sub(p1,p2,currRing);
2853  if(Lp.p != NULL)
2854  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2855  }
2856  else
2857  {
2858  #ifdef HAVE_PLURAL
2859  if ( rIsPluralRing(currRing) )
2860  {
2861  if(ncRingType(currRing) == nc_lie)
2862  {
2863  // generalized prod-crit for lie-type
2864  strat->cp++;
2865  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2866  }
2867  else
2868  if( ALLOW_PROD_CRIT(strat) )
2869  {
2870  // product criterion for homogeneous case in SCA
2871  strat->cp++;
2872  Lp.p = NULL;
2873  }
2874  else
2875  {
2876  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2877  nc_CreateShortSpoly(strat->S[i], p, currRing);
2878 
2879  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2880  pNext(Lp.p) = strat->tail; // !!!
2881  }
2882  }
2883  else
2884  #endif
2885  {
2887  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2888  }
2889  }
2890  }
2891  // store from which element this pair comes from for further tests
2892  //Lp.from = strat->sl+1;
2894  {
2895  //Put the sig to be > 0
2896  if(!nGreaterZero(pGetCoeff(Lp.sig)))
2897  {
2898  Lp.sig = pNeg(Lp.sig);
2899  Lp.p = pNeg(Lp.p);
2900  }
2901  }
2902  else
2903  {
2904  if(sigCmp==currRing->OrdSgn)
2905  {
2906  // pSig > sSig
2907  pDelete (&sSigMult);
2908  Lp.sig = pSigMult;
2909  Lp.sevSig = ~pSigMultNegSev;
2910  }
2911  else
2912  {
2913  // pSig < sSig
2914  pDelete (&pSigMult);
2915  Lp.sig = sSigMult;
2916  Lp.sevSig = ~sSigMultNegSev;
2917  }
2918  }
2919  if (Lp.p == NULL)
2920  {
2921  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2922  int pos = posInSyz(strat, Lp.sig);
2923  enterSyz(Lp, strat, pos);
2924  }
2925  else
2926  {
2927  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2928  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2929  {
2930  pLmFree(Lp.lcm);
2931  pDelete(&Lp.sig);
2932  pDelete (&m1);
2933  pDelete (&m2);
2934  return;
2935  }
2936  // in any case Lp is checked up to the next strat->P which is added
2937  // to S right after this critical pair creation.
2938  // NOTE: this even holds if the 2nd generator gives the bigger signature
2939  // moreover, this improves rewCriterion,
2940  // i.e. strat->checked > strat->from if and only if the 2nd generator
2941  // gives the bigger signature.
2942  Lp.checked = strat->sl+1;
2943  // at this point it is clear that the pair will be added to L, since it has
2944  // passed all tests up to now
2945 
2946  // adds buchberger's first criterion
2947  if (pLmCmp(m2,pHead(p)) == 0)
2948  {
2949  Lp.prod_crit = TRUE; // Product Criterion
2950 #if 0
2951  int pos = posInSyz(strat, Lp.sig);
2952  enterSyz(Lp, strat, pos);
2953  pDelete (&m1);
2954  pDelete (&m2);
2955  return;
2956 #endif
2957  }
2958  pDelete (&m1);
2959  pDelete (&m2);
2960 #if DEBUGF5
2961  PrintS("SIGNATURE OF PAIR: ");
2962  pWrite(Lp.sig);
2963 #endif
2964  /*- the pair (S[i],p) enters B -*/
2965  Lp.p1 = strat->S[i];
2966  Lp.p2 = p;
2967 
2968  if (
2970 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2972  )
2973  {
2974  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2975  pNext(Lp.p) = strat->tail; // !!!
2976  }
2977 
2978  if (atR >= 0)
2979  {
2980  Lp.i_r1 = strat->S_2_R[i];
2981  Lp.i_r2 = atR;
2982  }
2983  else
2984  {
2985  Lp.i_r1 = -1;
2986  Lp.i_r2 = -1;
2987  }
2988  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2989 
2991  {
2992  if (!rIsPluralRing(currRing)
2994  && (Lp.p->coef!=NULL))
2995  nDelete(&(Lp.p->coef));
2996  }
2997  // Check for sigdrop
2998  if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
2999  {
3000  strat->sigdrop = TRUE;
3001  // Completely reduce it
3002  int red_result = redRing(&Lp,strat);
3003  if(red_result == 0)
3004  {
3005  // Reduced to 0
3006  strat->sigdrop = FALSE;
3007  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3008  return;
3009  }
3010  else
3011  {
3012  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3013  // 0 - add just the original poly causing the sigdrop, 1 - add also this
3014  #if 1
3015  strat->enterS(Lp,0,strat, strat->tl+1);
3016  #endif
3017  return;
3018  }
3019  }
3020  l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3021  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3022  }
3023 }
3024 
3025 /*2
3026 * put the pair (s[i],p) into the set L, ecart=ecart(p)
3027 * in the case that s forms a SB of (s)
3028 */
3029 void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3030 {
3031  //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3032  if(pHasNotCF(p,strat->S[i]))
3033  {
3034  //PrintS("prod-crit\n");
3035  if(ALLOW_PROD_CRIT(strat))
3036  {
3037  //PrintS("prod-crit\n");
3038  strat->cp++;
3039  return;
3040  }
3041  }
3042 
3043  int l;
3044  LObject Lp;
3045  Lp.i_r = -1;
3046 
3047  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3048  /*- compute the short s-polynomial -*/
3049 
3050  #ifdef HAVE_PLURAL
3051  if (rIsPluralRing(currRing))
3052  {
3053  Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3054  }
3055  else
3056  #endif
3057  Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3058 
3059  if (Lp.p == NULL)
3060  {
3061  //PrintS("short spoly==NULL\n");
3062  pLmFree(Lp.lcm);
3063  }
3064  else
3065  {
3066  /*- the pair (S[i],p) enters L -*/
3067  Lp.p1 = strat->S[i];
3068  Lp.p2 = p;
3069  if (atR >= 0)
3070  {
3071  Lp.i_r1 = strat->S_2_R[i];
3072  Lp.i_r2 = atR;
3073  }
3074  else
3075  {
3076  Lp.i_r1 = -1;
3077  Lp.i_r2 = -1;
3078  }
3079  assume(pNext(Lp.p) == NULL);
3080  pNext(Lp.p) = strat->tail;
3081  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3083  {
3084  if (!rIsPluralRing(currRing)
3086  && (Lp.p->coef!=NULL))
3087  nDelete(&(Lp.p->coef));
3088  }
3089  l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3090  //Print("-> L[%d]\n",l);
3091  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3092  }
3093 }
3094 
3095 /*2
3096 * merge set B into L
3097 */
3099 {
3100  int j=strat->Ll+strat->Bl+1;
3101  if (j>strat->Lmax)
3102  {
3103  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3104  enlargeL(&(strat->L),&(strat->Lmax),j);
3105  }
3106  j = strat->Ll;
3107  int i;
3108  for (i=strat->Bl; i>=0; i--)
3109  {
3110  j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3111  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3112  }
3113  strat->Bl = -1;
3114 }
3115 
3116 /*2
3117 * merge set B into L
3118 */
3120 {
3121  int j=strat->Ll+strat->Bl+1;
3122  if (j>strat->Lmax)
3123  {
3124  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3125  enlargeL(&(strat->L),&(strat->Lmax),j);
3126  }
3127  j = strat->Ll;
3128  int i;
3129  for (i=strat->Bl; i>=0; i--)
3130  {
3131  j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3132  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3133  }
3134  strat->Bl = -1;
3135 }
3136 /*2
3137 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3138 *using the chain-criterion in B and L and enters B to L
3139 */
3140 void chainCritNormal (poly p,int ecart,kStrategy strat)
3141 {
3142  int i,j,l;
3143 
3144  /*
3145  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3146  *In this case all elements in B such
3147  *that their lcm is divisible by the leading term of S[i] can be canceled
3148  */
3149  if (strat->pairtest!=NULL)
3150  {
3151  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3152  for (j=0; j<=strat->sl; j++)
3153  {
3154  if (strat->pairtest[j])
3155  {
3156  for (i=strat->Bl; i>=0; i--)
3157  {
3158  if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3159  {
3160  deleteInL(strat->B,&strat->Bl,i,strat);
3161  strat->c3++;
3162  }
3163  }
3164  }
3165  }
3166  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3167  strat->pairtest=NULL;
3168  }
3169  if (strat->Gebauer || strat->fromT)
3170  {
3171  if (strat->sugarCrit)
3172  {
3173  /*
3174  *suppose L[j] == (s,r) and p/lcm(s,r)
3175  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3176  *and in case the sugar is o.k. then L[j] can be canceled
3177  */
3178  for (j=strat->Ll; j>=0; j--)
3179  {
3180  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3181  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3182  && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3183  {
3184  if (strat->L[j].p == strat->tail)
3185  {
3186  deleteInL(strat->L,&strat->Ll,j,strat);
3187  strat->c3++;
3188  }
3189  }
3190  }
3191  /*
3192  *this is GEBAUER-MOELLER:
3193  *in B all elements with the same lcm except the "best"
3194  *(i.e. the last one in B with this property) will be canceled
3195  */
3196  j = strat->Bl;
3197  loop /*cannot be changed into a for !!! */
3198  {
3199  if (j <= 0) break;
3200  i = j-1;
3201  loop
3202  {
3203  if (i < 0) break;
3204  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3205  {
3206  strat->c3++;
3207  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3208  {
3209  deleteInL(strat->B,&strat->Bl,i,strat);
3210  j--;
3211  }
3212  else
3213  {
3214  deleteInL(strat->B,&strat->Bl,j,strat);
3215  break;
3216  }
3217  }
3218  i--;
3219  }
3220  j--;
3221  }
3222  }
3223  else /*sugarCrit*/
3224  {
3225  /*
3226  *suppose L[j] == (s,r) and p/lcm(s,r)
3227  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3228  *and in case the sugar is o.k. then L[j] can be canceled
3229  */
3230  for (j=strat->Ll; j>=0; j--)
3231  {
3232  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3233  {
3234  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3235  {
3236  deleteInL(strat->L,&strat->Ll,j,strat);
3237  strat->c3++;
3238  }
3239  }
3240  }
3241  /*
3242  *this is GEBAUER-MOELLER:
3243  *in B all elements with the same lcm except the "best"
3244  *(i.e. the last one in B with this property) will be canceled
3245  */
3246  j = strat->Bl;
3247  loop /*cannot be changed into a for !!! */
3248  {
3249  if (j <= 0) break;
3250  for(i=j-1; i>=0; i--)
3251  {
3252  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3253  {
3254  strat->c3++;
3255  deleteInL(strat->B,&strat->Bl,i,strat);
3256  j--;
3257  }
3258  }
3259  j--;
3260  }
3261  }
3262  /*
3263  *the elements of B enter L
3264  */
3265  kMergeBintoL(strat);
3266  }
3267  else
3268  {
3269  for (j=strat->Ll; j>=0; j--)
3270  {
3271  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3272  {
3273  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3274  {
3275  deleteInL(strat->L,&strat->Ll,j,strat);
3276  strat->c3++;
3277  }
3278  }
3279  }
3280  /*
3281  *this is our MODIFICATION of GEBAUER-MOELLER:
3282  *First the elements of B enter L,
3283  *then we fix a lcm and the "best" element in L
3284  *(i.e the last in L with this lcm and of type (s,p))
3285  *and cancel all the other elements of type (r,p) with this lcm
3286  *except the case the element (s,r) has also the same lcm
3287  *and is on the worst position with respect to (s,p) and (r,p)
3288  */
3289  /*
3290  *B enters to L/their order with respect to B is permutated for elements
3291  *B[i].p with the same leading term
3292  */
3293  kMergeBintoL(strat);
3294  j = strat->Ll;
3295  loop /*cannot be changed into a for !!! */
3296  {
3297  if (j <= 0)
3298  {
3299  /*now L[0] cannot be canceled any more and the tail can be removed*/
3300  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3301  break;
3302  }
3303  if (strat->L[j].p2 == p)
3304  {
3305  i = j-1;
3306  loop
3307  {
3308  if (i < 0) break;
3309  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3310  {
3311  /*L[i] could be canceled but we search for a better one to cancel*/
3312  strat->c3++;
3313  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3314  && (pNext(strat->L[l].p) == strat->tail)
3315  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3316  && pDivisibleBy(p,strat->L[l].lcm))
3317  {
3318  /*
3319  *"NOT equal(...)" because in case of "equal" the element L[l]
3320  *is "older" and has to be from theoretical point of view behind
3321  *L[i], but we do not want to reorder L
3322  */
3323  strat->L[i].p2 = strat->tail;
3324  /*
3325  *L[l] will be canceled, we cannot cancel L[i] later on,
3326  *so we mark it with "tail"
3327  */
3328  deleteInL(strat->L,&strat->Ll,l,strat);
3329  i--;
3330  }
3331  else
3332  {
3333  deleteInL(strat->L,&strat->Ll,i,strat);
3334  }
3335  j--;
3336  }
3337  i--;
3338  }
3339  }
3340  else if (strat->L[j].p2 == strat->tail)
3341  {
3342  /*now L[j] cannot be canceled any more and the tail can be removed*/
3343  strat->L[j].p2 = p;
3344  }
3345  j--;
3346  }
3347  }
3348 }
3349 /*2
3350 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3351 *without the chain-criterion in B and L and enters B to L
3352 */
3353 void chainCritOpt_1 (poly,int,kStrategy strat)
3354 {
3355  if (strat->pairtest!=NULL)
3356  {
3357  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3358  strat->pairtest=NULL;
3359  }
3360  /*
3361  *the elements of B enter L
3362  */
3363  kMergeBintoL(strat);
3364 }
3365 /*2
3366 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3367 *using the chain-criterion in B and L and enters B to L
3368 */
3369 void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3370 {
3371  int i,j,l;
3372  kMergeBintoLSba(strat);
3373  j = strat->Ll;
3374  loop /*cannot be changed into a for !!! */
3375  {
3376  if (j <= 0)
3377  {
3378  /*now L[0] cannot be canceled any more and the tail can be removed*/
3379  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3380  break;
3381  }
3382  if (strat->L[j].p2 == p)
3383  {
3384  i = j-1;
3385  loop
3386  {
3387  if (i < 0) break;
3388  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3389  {
3390  /*L[i] could be canceled but we search for a better one to cancel*/
3391  strat->c3++;
3392  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3393  && (pNext(strat->L[l].p) == strat->tail)
3394  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3395  && pDivisibleBy(p,strat->L[l].lcm))
3396  {
3397  /*
3398  *"NOT equal(...)" because in case of "equal" the element L[l]
3399  *is "older" and has to be from theoretical point of view behind
3400  *L[i], but we do not want to reorder L
3401  */
3402  strat->L[i].p2 = strat->tail;
3403  /*
3404  *L[l] will be canceled, we cannot cancel L[i] later on,
3405  *so we mark it with "tail"
3406  */
3407  deleteInL(strat->L,&strat->Ll,l,strat);
3408  i--;
3409  }
3410  else
3411  {
3412  deleteInL(strat->L,&strat->Ll,i,strat);
3413  }
3414  j--;
3415  }
3416  i--;
3417  }
3418  }
3419  else if (strat->L[j].p2 == strat->tail)
3420  {
3421  /*now L[j] cannot be canceled any more and the tail can be removed*/
3422  strat->L[j].p2 = p;
3423  }
3424  j--;
3425  }
3426 }
3427 #ifdef HAVE_RATGRING
3428 void chainCritPart (poly p,int ecart,kStrategy strat)
3429 {
3430  int i,j,l;
3431 
3432  /*
3433  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3434  *In this case all elements in B such
3435  *that their lcm is divisible by the leading term of S[i] can be canceled
3436  */
3437  if (strat->pairtest!=NULL)
3438  {
3439  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3440  for (j=0; j<=strat->sl; j++)
3441  {
3442  if (strat->pairtest[j])
3443  {
3444  for (i=strat->Bl; i>=0; i--)
3445  {
3446  if (_p_LmDivisibleByPart(strat->S[j],currRing,
3447  strat->B[i].lcm,currRing,
3448  currRing->real_var_start,currRing->real_var_end))
3449  {
3450  if(TEST_OPT_DEBUG)
3451  {
3452  Print("chain-crit-part: S[%d]=",j);
3453  p_wrp(strat->S[j],currRing);
3454  Print(" divide B[%d].lcm=",i);
3455  p_wrp(strat->B[i].lcm,currRing);
3456  PrintLn();
3457  }
3458  deleteInL(strat->B,&strat->Bl,i,strat);
3459  strat->c3++;
3460  }
3461  }
3462  }
3463  }
3464  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3465  strat->pairtest=NULL;
3466  }
3467  if (strat->Gebauer || strat->fromT)
3468  {
3469  if (strat->sugarCrit)
3470  {
3471  /*
3472  *suppose L[j] == (s,r) and p/lcm(s,r)
3473  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3474  *and in case the sugar is o.k. then L[j] can be canceled
3475  */
3476  for (j=strat->Ll; j>=0; j--)
3477  {
3478  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3479  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3480  && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3481  {
3482  if (strat->L[j].p == strat->tail)
3483  {
3484  if(TEST_OPT_DEBUG)
3485  {
3486  PrintS("chain-crit-part: pCompareChainPart p=");
3487  p_wrp(p,currRing);
3488  Print(" delete L[%d]",j);
3489  p_wrp(strat->L[j].lcm,currRing);
3490  PrintLn();
3491  }
3492  deleteInL(strat->L,&strat->Ll,j,strat);
3493  strat->c3++;
3494  }
3495  }
3496  }
3497  /*
3498  *this is GEBAUER-MOELLER:
3499  *in B all elements with the same lcm except the "best"
3500  *(i.e. the last one in B with this property) will be canceled
3501  */
3502  j = strat->Bl;
3503  loop /*cannot be changed into a for !!! */
3504  {
3505  if (j <= 0) break;
3506  i = j-1;
3507  loop
3508  {
3509  if (i < 0) break;
3510  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3511  {
3512  strat->c3++;
3513  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3514  {
3515  if(TEST_OPT_DEBUG)
3516  {
3517  Print("chain-crit-part: sugar B[%d].lcm=",j);
3518  p_wrp(strat->B[j].lcm,currRing);
3519  Print(" delete B[%d]",i);
3520  p_wrp(strat->B[i].lcm,currRing);
3521  PrintLn();
3522  }
3523  deleteInL(strat->B,&strat->Bl,i,strat);
3524  j--;
3525  }
3526  else
3527  {
3528  if(TEST_OPT_DEBUG)
3529  {
3530  Print("chain-crit-part: sugar B[%d].lcm=",i);
3531  p_wrp(strat->B[i].lcm,currRing);
3532  Print(" delete B[%d]",j);
3533  p_wrp(strat->B[j].lcm,currRing);
3534  PrintLn();
3535  }
3536  deleteInL(strat->B,&strat->Bl,j,strat);
3537  break;
3538  }
3539  }
3540  i--;
3541  }
3542  j--;
3543  }
3544  }
3545  else /*sugarCrit*/
3546  {
3547  /*
3548  *suppose L[j] == (s,r) and p/lcm(s,r)
3549  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3550  *and in case the sugar is o.k. then L[j] can be canceled
3551  */
3552  for (j=strat->Ll; j>=0; j--)
3553  {
3554  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3555  {
3556  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3557  {
3558  if(TEST_OPT_DEBUG)
3559  {
3560  PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3561  p_wrp(p,currRing);
3562  Print(" delete L[%d]",j);
3563  p_wrp(strat->L[j].lcm,currRing);
3564  PrintLn();
3565  }
3566  deleteInL(strat->L,&strat->Ll,j,strat);
3567  strat->c3++;
3568  }
3569  }
3570  }
3571  /*
3572  *this is GEBAUER-MOELLER:
3573  *in B all elements with the same lcm except the "best"
3574  *(i.e. the last one in B with this property) will be canceled
3575  */
3576  j = strat->Bl;
3577  loop /*cannot be changed into a for !!! */
3578  {
3579  if (j <= 0) break;
3580  for(i=j-1; i>=0; i--)
3581  {
3582  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3583  {
3584  if(TEST_OPT_DEBUG)
3585  {
3586  Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3587  p_wrp(strat->B[j].lcm,currRing);
3588  Print(" delete B[%d]\n",i);
3589  }
3590  strat->c3++;
3591  deleteInL(strat->B,&strat->Bl,i,strat);
3592  j--;
3593  }
3594  }
3595  j--;
3596  }
3597  }
3598  /*
3599  *the elements of B enter L
3600  */
3601  kMergeBintoL(strat);
3602  }
3603  else
3604  {
3605  for (j=strat->Ll; j>=0; j--)
3606  {
3607  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3608  {
3609  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3610  {
3611  if(TEST_OPT_DEBUG)
3612  {
3613  PrintS("chain-crit-part: pCompareChainPart p=");
3614  p_wrp(p,currRing);
3615  Print(" delete L[%d]",j);
3616  p_wrp(strat->L[j].lcm,currRing);
3617  PrintLn();
3618  }
3619  deleteInL(strat->L,&strat->Ll,j,strat);
3620  strat->c3++;
3621  }
3622  }
3623  }
3624  /*
3625  *this is our MODIFICATION of GEBAUER-MOELLER:
3626  *First the elements of B enter L,
3627  *then we fix a lcm and the "best" element in L
3628  *(i.e the last in L with this lcm and of type (s,p))
3629  *and cancel all the other elements of type (r,p) with this lcm
3630  *except the case the element (s,r) has also the same lcm
3631  *and is on the worst position with respect to (s,p) and (r,p)
3632  */
3633  /*
3634  *B enters to L/their order with respect to B is permutated for elements
3635  *B[i].p with the same leading term
3636  */
3637  kMergeBintoL(strat);
3638  j = strat->Ll;
3639  loop /*cannot be changed into a for !!! */
3640  {
3641  if (j <= 0)
3642  {
3643  /*now L[0] cannot be canceled any more and the tail can be removed*/
3644  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3645  break;
3646  }
3647  if (strat->L[j].p2 == p)
3648  {
3649  i = j-1;
3650  loop
3651  {
3652  if (i < 0) break;
3653  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3654  {
3655  /*L[i] could be canceled but we search for a better one to cancel*/
3656  strat->c3++;
3657  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3658  && (pNext(strat->L[l].p) == strat->tail)
3659  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3661  strat->L[l].lcm,currRing,
3662  currRing->real_var_start, currRing->real_var_end))
3663 
3664  {
3665  /*
3666  *"NOT equal(...)" because in case of "equal" the element L[l]
3667  *is "older" and has to be from theoretical point of view behind
3668  *L[i], but we do not want to reorder L
3669  */
3670  strat->L[i].p2 = strat->tail;
3671  /*
3672  *L[l] will be canceled, we cannot cancel L[i] later on,
3673  *so we mark it with "tail"
3674  */
3675  if(TEST_OPT_DEBUG)
3676  {
3677  PrintS("chain-crit-part: divisible_by p=");
3678  p_wrp(p,currRing);
3679  Print(" delete L[%d]",l);
3680  p_wrp(strat->L[l].lcm,currRing);
3681  PrintLn();
3682  }
3683  deleteInL(strat->L,&strat->Ll,l,strat);
3684  i--;
3685  }
3686  else
3687  {
3688  if(TEST_OPT_DEBUG)
3689  {
3690  PrintS("chain-crit-part: divisible_by(2) p=");
3691  p_wrp(p,currRing);
3692  Print(" delete L[%d]",i);
3693  p_wrp(strat->L[i].lcm,currRing);
3694  PrintLn();
3695  }
3696  deleteInL(strat->L,&strat->Ll,i,strat);
3697  }
3698  j--;
3699  }
3700  i--;
3701  }
3702  }
3703  else if (strat->L[j].p2 == strat->tail)
3704  {
3705  /*now L[j] cannot be canceled any more and the tail can be removed*/
3706  strat->L[j].p2 = p;
3707  }
3708  j--;
3709  }
3710  }
3711 }
3712 #endif
3713 
3714 /*2
3715 *(s[0],h),...,(s[k],h) will be put to the pairset L
3716 */
3717 void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3718 {
3719 
3720  if ((strat->syzComp==0)
3721  || (pGetComp(h)<=strat->syzComp))
3722  {
3723  int j;
3724  BOOLEAN new_pair=FALSE;
3725 
3726  if (pGetComp(h)==0)
3727  {
3728  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3729  if ((isFromQ)&&(strat->fromQ!=NULL))
3730  {
3731  for (j=0; j<=k; j++)
3732  {
3733  if (!strat->fromQ[j])
3734  {
3735  new_pair=TRUE;
3736  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3737  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3738  }
3739  }
3740  }
3741  else
3742  {
3743  new_pair=TRUE;
3744  for (j=0; j<=k; j++)
3745  {
3746  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3747  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3748  }
3749  }
3750  }
3751  else
3752  {
3753  for (j=0; j<=k; j++)
3754  {
3755  if ((pGetComp(h)==pGetComp(strat->S[j]))
3756  || (pGetComp(strat->S[j])==0))
3757  {
3758  new_pair=TRUE;
3759  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3760  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3761  }
3762  }
3763  }
3764  if (new_pair)
3765  {
3766  #ifdef HAVE_RATGRING
3767  if (currRing->real_var_start>0)
3768  chainCritPart(h,ecart,strat);
3769  else
3770  #endif
3771  strat->chainCrit(h,ecart,strat);
3772  }
3773  kMergeBintoL(strat);
3774  }
3775 }
3776 
3777 /*2
3778 *(s[0],h),...,(s[k],h) will be put to the pairset L
3779 *using signatures <= only for signature-based standard basis algorithms
3780 */
3781 
3782 void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3783 {
3784 
3785  if ((strat->syzComp==0)
3786  || (pGetComp(h)<=strat->syzComp))
3787  {
3788  int j;
3789  BOOLEAN new_pair=FALSE;
3790 
3791  if (pGetComp(h)==0)
3792  {
3793  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3794  if ((isFromQ)&&(strat->fromQ!=NULL))
3795  {
3796  for (j=0; j<=k; j++)
3797  {
3798  if (!strat->fromQ[j])
3799  {
3800  new_pair=TRUE;
3801  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3802  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3803  }
3804  }
3805  }
3806  else
3807  {
3808  new_pair=TRUE;
3809  for (j=0; j<=k; j++)
3810  {
3811  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3812  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3813  }
3814  }
3815  }
3816  else
3817  {
3818  for (j=0; j<=k; j++)
3819  {
3820  if ((pGetComp(h)==pGetComp(strat->S[j]))
3821  || (pGetComp(strat->S[j])==0))
3822  {
3823  new_pair=TRUE;
3824  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3825  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3826  }
3827  }
3828  }
3829 
3830  if (new_pair)
3831  {
3832 #ifdef HAVE_RATGRING
3833  if (currRing->real_var_start>0)
3834  chainCritPart(h,ecart,strat);
3835  else
3836 #endif
3837  strat->chainCrit(h,ecart,strat);
3838  }
3839  }
3840 }
3841 
3842 void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3843 {
3844 
3845  if ((strat->syzComp==0)
3846  || (pGetComp(h)<=strat->syzComp))
3847  {
3848  int j;
3849 
3850  if (pGetComp(h)==0)
3851  {
3852  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3853  if ((isFromQ)&&(strat->fromQ!=NULL))
3854  {
3855  for (j=0; j<=k && !strat->sigdrop; j++)
3856  {
3857  if (!strat->fromQ[j])
3858  {
3859  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3860  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3861  }
3862  }
3863  }
3864  else
3865  {
3866  for (j=0; j<=k && !strat->sigdrop; j++)
3867  {
3868  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3869  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3870  }
3871  }
3872  }
3873  else
3874  {
3875  for (j=0; j<=k && !strat->sigdrop; j++)
3876  {
3877  if ((pGetComp(h)==pGetComp(strat->S[j]))
3878  || (pGetComp(strat->S[j])==0))
3879  {
3880  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3881  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3882  }
3883  }
3884  }
3885 
3886 #if 0
3887  if (new_pair)
3888  {
3889 #ifdef HAVE_RATGRING
3890  if (currRing->real_var_start>0)
3891  chainCritPart(h,ecart,strat);
3892  else
3893 #endif
3894  strat->chainCrit(h,ecart,strat);
3895  }
3896 #endif
3897  }
3898 }
3899 
3900 #ifdef HAVE_RINGS
3901 /*2
3902 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3903 *using the chain-criterion in B and L and enters B to L
3904 */
3905 void chainCritRing (poly p,int, kStrategy strat)
3906 {
3907  int i,j,l;
3908  /*
3909  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3910  *In this case all elements in B such
3911  *that their lcm is divisible by the leading term of S[i] can be canceled
3912  */
3913  if (strat->pairtest!=NULL)
3914  {
3915  {
3916  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3917  for (j=0; j<=strat->sl; j++)
3918  {
3919  if (strat->pairtest[j])
3920  {
3921  for (i=strat->Bl; i>=0; i--)
3922  {
3923  if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
3924  {
3925 #ifdef KDEBUG
3926  if (TEST_OPT_DEBUG)
3927  {
3928  PrintS("--- chain criterion func chainCritRing type 1\n");
3929  PrintS("strat->S[j]:");
3930  wrp(strat->S[j]);
3931  PrintS(" strat->B[i].lcm:");
3932  wrp(strat->B[i].lcm);PrintLn();
3933  pWrite(strat->B[i].p);
3934  pWrite(strat->B[i].p1);
3935  pWrite(strat->B[i].p2);
3936  wrp(strat->B[i].lcm);
3937  PrintLn();
3938  }
3939 #endif
3940  deleteInL(strat->B,&strat->Bl,i,strat);
3941  strat->c3++;
3942  }
3943  }
3944  }
3945  }
3946  }
3947  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3948  strat->pairtest=NULL;
3949  }
3950  assume(!(strat->Gebauer || strat->fromT));
3951  for (j=strat->Ll; j>=0; j--)
3952  {
3953  if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
3954  {
3955  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3956  {
3957  if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3958  {
3959  deleteInL(strat->L,&strat->Ll,j,strat);
3960  strat->c3++;
3961 #ifdef KDEBUG
3962  if (TEST_OPT_DEBUG)
3963  {
3964  PrintS("--- chain criterion func chainCritRing type 2\n");
3965  PrintS("strat->L[j].p:");
3966  wrp(strat->L[j].p);
3967  PrintS(" p:");
3968  wrp(p);
3969  PrintLn();
3970  }
3971 #endif
3972  }
3973  }
3974  }
3975  }
3976  /*
3977  *this is our MODIFICATION of GEBAUER-MOELLER:
3978  *First the elements of B enter L,
3979  *then we fix a lcm and the "best" element in L
3980  *(i.e the last in L with this lcm and of type (s,p))
3981  *and cancel all the other elements of type (r,p) with this lcm
3982  *except the case the element (s,r) has also the same lcm
3983  *and is on the worst position with respect to (s,p) and (r,p)
3984  */
3985  /*
3986  *B enters to L/their order with respect to B is permutated for elements
3987  *B[i].p with the same leading term
3988  */
3989  kMergeBintoL(strat);
3990  j = strat->Ll;
3991  loop /*cannot be changed into a for !!! */
3992  {
3993  if (j <= 0)
3994  {
3995  /*now L[0] cannot be canceled any more and the tail can be removed*/
3996  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3997  break;
3998  }
3999  if (strat->L[j].p2 == p) // Was the element added from B?
4000  {
4001  i = j-1;
4002  loop
4003  {
4004  if (i < 0) break;
4005  // Element is from B and has the same lcm as L[j]
4006  if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4007  && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4008  {
4009  /*L[i] could be canceled but we search for a better one to cancel*/
4010  strat->c3++;
4011 #ifdef KDEBUG
4012  if (TEST_OPT_DEBUG)
4013  {
4014  PrintS("--- chain criterion func chainCritRing type 3\n");
4015  PrintS("strat->L[j].lcm:");
4016  wrp(strat->L[j].lcm);
4017  PrintS(" strat->L[i].lcm:");
4018  wrp(strat->L[i].lcm);
4019  PrintLn();
4020  }
4021 #endif
4022  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4023  && (pNext(strat->L[l].p) == strat->tail)
4024  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4025  && pDivisibleBy(p,strat->L[l].lcm))
4026  {
4027  /*
4028  *"NOT equal(...)" because in case of "equal" the element L[l]
4029  *is "older" and has to be from theoretical point of view behind
4030  *L[i], but we do not want to reorder L
4031  */
4032  strat->L[i].p2 = strat->tail;
4033  /*
4034  *L[l] will be canceled, we cannot cancel L[i] later on,
4035  *so we mark it with "tail"
4036  */
4037  deleteInL(strat->L,&strat->Ll,l,strat);
4038  i--;
4039  }
4040  else
4041  {
4042  deleteInL(strat->L,&strat->Ll,i,strat);
4043  }
4044  j--;
4045  }
4046  i--;
4047  }
4048  }
4049  else if (strat->L[j].p2 == strat->tail)
4050  {
4051  /*now L[j] cannot be canceled any more and the tail can be removed*/
4052  strat->L[j].p2 = p;
4053  }
4054  j--;
4055  }
4056 }
4057 #endif
4058 
4059 #ifdef HAVE_RINGS
4060 long ind2(long arg)
4061 {
4062  long ind = 0;
4063  if (arg <= 0) return 0;
4064  while (arg%2 == 0)
4065  {
4066  arg = arg / 2;
4067  ind++;
4068  }
4069  return ind;
4070 }
4071 
4072 long ind_fact_2(long arg)
4073 {
4074  long ind = 0;
4075  if (arg <= 0) return 0;
4076  if (arg%2 == 1) { arg--; }
4077  while (arg > 0)
4078  {
4079  ind += ind2(arg);
4080  arg = arg - 2;
4081  }
4082  return ind;
4083 }
4084 #endif
4085 
4086 #ifdef HAVE_VANIDEAL
4087 long twoPow(long arg)
4088 {
4089  return 1L << arg;
4090 }
4091 
4092 /*2
4093 * put the pair (p, f) in B and f in T
4094 */
4095 void enterOneZeroPairRing (poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR = -1)
4096 {
4097  int l,j,compare,compareCoeff;
4098  LObject Lp;
4099 
4100 #ifdef KDEBUG
4101  Lp.ecart=0; Lp.length=0;
4102 #endif
4103  /*- computes the lcm(s[i],p) -*/
4104  Lp.lcm = p_Lcm(p,f,Lp.lcm,currRing);
4105  pSetCoeff(Lp.lcm, nLcm(pGetCoeff(p), pGetCoeff(f), currRing));
4106  assume(!strat->sugarCrit);
4107  assume(!strat->fromT);
4108  /*
4109  *the set B collects the pairs of type (S[j],p)
4110  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
4111  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
4112  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
4113  */
4114  for(j = strat->Bl;j>=0;j--)
4115  {
4116  compare=pDivCompRing(strat->B[j].lcm,Lp.lcm);
4117  compareCoeff = nDivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(Lp.lcm));
4118  if (compareCoeff == 0 || compare == compareCoeff)
4119  {
4120  if (compare == 1)
4121  {
4122  strat->c3++;
4123  pLmDelete(Lp.lcm);
4124  return;
4125  }
4126  else
4127  if (compare == -1)
4128  {
4129  deleteInL(strat->B,&strat->Bl,j,strat);
4130  strat->c3++;
4131  }
4132  }
4133  if (compare == pDivComp_EQUAL)
4134  {
4135  // Add hint for same LM and direction of LC (later) (TODO Oliver)
4136  if (compareCoeff == 1)
4137  {
4138  strat->c3++;
4139  pLmDelete(Lp.lcm);
4140  return;
4141  }
4142  else
4143  if (compareCoeff == -1)
4144  {
4145  deleteInL(strat->B,&strat->Bl,j,strat);
4146  strat->c3++;
4147  }
4148  }
4149  }
4150  /*
4151  *the pair (S[i],p) enters B if the spoly != 0
4152  */
4153  /*- compute the short s-polynomial -*/
4154  if ((f==NULL) || (p==NULL)) return;
4155  pNorm(p);
4156  {
4157  Lp.p = ksCreateShortSpoly(f, p, strat->tailRing);
4158  }
4159  if (Lp.p == NULL) //deactivated, as we are adding pairs with zeropoly and not from S
4160  {
4161  /*- the case that the s-poly is 0 -*/
4162 // if (strat->pairtest==NULL) initPairtest(strat);
4163 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
4164 // strat->pairtest[strat->sl+1] = TRUE;
4165  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
4166  /*
4167  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
4168  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
4169  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
4170  *term of p devides the lcm(s,r)
4171  *(this canceling should be done here because
4172  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
4173  *the first case is handeled in chainCrit
4174  */
4175  if (Lp.lcm!=NULL) pLmDelete(Lp.lcm);
4176  }
4177  else
4178  {
4179  /*- the pair (S[i],p) enters B -*/
4180  Lp.p1 = f;
4181  Lp.p2 = p;
4182 
4183  pNext(Lp.p) = strat->tail;
4184 
4185  LObject tmp_h(f, currRing, strat->tailRing);
4186  tmp_h.SetShortExpVector();
4187  strat->initEcart(&tmp_h);
4188  tmp_h.sev = pGetShortExpVector(tmp_h.p);
4189  tmp_h.t_p = t_p;
4190 
4191  enterT(tmp_h, strat, strat->tl + 1);
4192 
4193  if (atR >= 0)
4194  {
4195  Lp.i_r2 = atR;
4196  Lp.i_r1 = strat->tl;
4197  }
4198 
4199  strat->initEcartPair(&Lp,f,p,0/*strat->ecartS[i]*/,ecart); // Attention: TODO: break ecart
4200  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
4201  enterL(&strat->B, &strat->Bl, &strat->Bmax, Lp, l);
4202  }
4203 }
4204 
4205 /* Helper for kCreateZeroPoly
4206  * enumerating the exponents
4207 ring r = 2^2, (a, b, c), lp; ideal G0 = system("createG0"); ideal G = interred(G0); ncols(G0); ncols(G);
4208  */
4209 
4210 int nextZeroSimplexExponent (long exp[], long ind[], long cexp[], long cind[], long* cabsind, long step[], long bound, long N)
4211 /* gives the next exponent from the set H_1 */
4212 {
4213  long add = ind2(cexp[1] + 2);
4214  if ((*cabsind < bound) && (*cabsind - step[1] + add < bound))
4215  {
4216  cexp[1] += 2;
4217  cind[1] += add;
4218  *cabsind += add;
4219  }
4220  else
4221  {
4222  // cabsind >= habsind
4223  if (N == 1) return 0;
4224  int i = 1;
4225  while (exp[i] == cexp[i] && i <= N) i++;
4226  cexp[i] = exp[i];
4227  *cabsind -= cind[i];
4228  cind[i] = ind[i];
4229  step[i] = 500000;
4230  *cabsind += cind[i];
4231  // Print("in: %d\n", *cabsind);
4232  i += 1;
4233  if (i > N) return 0;
4234  do
4235  {
4236  step[1] = 500000;
4237  for (int j = i + 1; j <= N; j++)
4238  {
4239  if (step[1] > step[j]) step[1] = step[j];
4240  }
4241  add = ind2(cexp[i] + 2);
4242  if (*cabsind - step[1] + add >= bound)
4243  {
4244  cexp[i] = exp[i];
4245  *cabsind -= cind[i];
4246  cind[i] = ind[i];
4247  *cabsind += cind[i];
4248  step[i] = 500000;
4249  i += 1;
4250  if (i > N) return 0;
4251  }
4252  else step[1] = -1;
4253  } while (step[1] != -1);
4254  step[1] = 500000;
4255  cexp[i] += 2;
4256  cind[i] += add;
4257  *cabsind += add;
4258  if (add < step[i]) step[i] = add;
4259  for (i = 2; i <= N; i++)
4260  {
4261  if (step[1] > step[i]) step[1] = step[i];
4262  }
4263  }
4264  return 1;
4265 }
4266 
4267 /*
4268  * Creates the zero Polynomial on position exp
4269  * long exp[] : exponent of leading term
4270  * cabsind : total 2-ind of exp (if -1 will be computed)
4271  * poly* t_p : will hold the LT in tailRing
4272  * leadRing : ring for the LT
4273  * tailRing : ring for the tail
4274  */
4275 
4276 poly kCreateZeroPoly(long exp[], long cabsind, poly* t_p, ring leadRing, ring tailRing)
4277 {
4278 
4279  poly zeroPoly = NULL;
4280 
4281  number tmp1;
4282  poly tmp2, tmp3;
4283 
4284  if (cabsind == -1)
4285  {
4286  cabsind = 0;
4287  for (int i = 1; i <= leadRing->N; i++)
4288  {
4289  cabsind += ind_fact_2(exp[i]);
4290  }
4291 // Print("cabsind: %d\n", cabsind);
4292  }
4293  if (cabsind < leadRing->ch)
4294  {
4295  zeroPoly = p_ISet(twoPow(leadRing->ch - cabsind), tailRing);
4296  }
4297  else
4298  {
4299  zeroPoly = p_ISet(1, tailRing);
4300  }
4301  for (int i = 1; i <= leadRing->N; i++)
4302  {
4303  for (long j = 1; j <= exp[i]; j++)
4304  {
4305  tmp1 = nInit(j);
4306  tmp2 = p_ISet(1, tailRing);
4307  p_SetExp(tmp2, i, 1, tailRing);
4308  p_Setm(tmp2, tailRing);
4309  if (nIsZero(tmp1))
4310  { // should nowbe obsolet, test ! TODO OLIVER
4311  zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
4312  }
4313  else
4314  {
4315  tmp3 = p_NSet(nCopy(tmp1), tailRing);
4316  zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing);
4317  }
4318  }
4319  }
4320  tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing);
4321  for (int i = 1; i <= leadRing->N; i++)
4322  {
4323  pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
4324  }
4325  p_Setm(tmp2, leadRing);
4326  *t_p = zeroPoly;
4327  zeroPoly = pNext(zeroPoly);
4328  pNext(*t_p) = NULL;
4329  pNext(tmp2) = zeroPoly;
4330  return tmp2;
4331 }
4332 
4333 // #define OLI_DEBUG
4334 
4335 /*
4336  * Generate the s-polynomial for the virtual set of zero-polynomials
4337  */
4338 
4339 void initenterzeropairsRing (poly p, int ecart, kStrategy strat, int atR)
4340 {
4341  // Initialize
4342  long exp[50]; // The exponent of \hat{X} (basepoint)
4343  long cexp[50]; // The current exponent for iterating over all
4344  long ind[50]; // The power of 2 in the i-th component of exp
4345  long cind[50]; // analog for cexp
4346  long mult[50]; // How to multiply the elements of G
4347  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4348  long habsind = 0; // The abs. index of the coefficient of h
4349  long step[50]; // The last increases
4350  for (int i = 1; i <= currRing->N; i++)
4351  {
4352  exp[i] = p_GetExp(p, i, currRing);
4353  if (exp[i] & 1 != 0)
4354  {
4355  exp[i] = exp[i] - 1;
4356  mult[i] = 1;
4357  }
4358  cexp[i] = exp[i];
4359  ind[i] = ind_fact_2(exp[i]);
4360  cabsind += ind[i];
4361  cind[i] = ind[i];
4362  step[i] = 500000;
4363  }
4364  step[1] = 500000;
4365  habsind = ind2(n_Int(pGetCoeff(p), currRing->cf);
4366  long bound = currRing->ch - habsind;
4367 #ifdef OLI_DEBUG
4368  PrintS("-------------\npoly :");
4369  wrp(p);
4370  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4371  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4372  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4373  Print("bound : %d\n", bound);
4374  Print("cind : %d\n", cabsind);
4375 #endif
4376  if (cabsind == 0)
4377  {
4378  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4379  {
4380  return;
4381  }
4382  }
4383  // Now the whole simplex
4384  do
4385  {
4386  // Build s-polynomial
4387  // 2**ind-def * mult * g - exp-def * h
4388  poly t_p;
4389  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, strat->tailRing);
4390 #ifdef OLI_DEBUG
4391  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4392  PrintS("zPoly : ");
4393  wrp(zeroPoly);
4394  PrintLn();
4395 #endif
4396  enterOneZeroPairRing(zeroPoly, t_p, p, ecart, strat, atR);
4397  }
4398  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4399 }
4400 
4401 /*
4402  * Create the Groebner basis of the vanishing polynomials.
4403  */
4404 
4405 ideal createG0()
4406 {
4407  // Initialize
4408  long exp[50]; // The exponent of \hat{X} (basepoint)
4409  long cexp[50]; // The current exponent for iterating over all
4410  long ind[50]; // The power of 2 in the i-th component of exp
4411  long cind[50]; // analog for cexp
4412  long mult[50]; // How to multiply the elements of G
4413  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4414  long habsind = 0; // The abs. index of the coefficient of h
4415  long step[50]; // The last increases
4416  for (int i = 1; i <= currRing->N; i++)
4417  {
4418  exp[i] = 0;
4419  cexp[i] = exp[i];
4420  ind[i] = 0;
4421  step[i] = 500000;
4422  cind[i] = ind[i];
4423  }
4424  long bound = currRing->ch;
4425  step[1] = 500000;
4426 #ifdef OLI_DEBUG
4427  PrintS("-------------\npoly :");
4428 // wrp(p);
4429  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4430  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4431  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4432  Print("bound : %d\n", bound);
4433  Print("cind : %d\n", cabsind);
4434 #endif
4435  if (cabsind == 0)
4436  {
4437  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4438  {
4439  return idInit(1, 1);
4440  }
4441  }
4442  ideal G0 = idInit(1, 1);
4443  // Now the whole simplex
4444  do
4445  {
4446  // Build s-polynomial
4447  // 2**ind-def * mult * g - exp-def * h
4448  poly t_p;
4449  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, currRing);
4450 #ifdef OLI_DEBUG
4451  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4452  PrintS("zPoly : ");
4453  wrp(zeroPoly);
4454  PrintLn();
4455 #endif
4456  // Add to ideal
4457  pEnlargeSet(&(G0->m), IDELEMS(G0), 1);
4458  IDELEMS(G0) += 1;
4459  G0->m[IDELEMS(G0) - 1] = zeroPoly;
4460  }
4461  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4462  idSkipZeroes(G0);
4463  return G0;
4464 }
4465 #endif
4466 
4467 #ifdef HAVE_RINGS
4468 /*2
4469 *(s[0],h),...,(s[k],h) will be put to the pairset L
4470 */
4471 void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4472 {
4473  const int iCompH = pGetComp(h);
4474  if (!nIsOne(pGetCoeff(h)))
4475  {
4476  int j;
4477 
4478  for (j=0; j<=k; j++)
4479  {
4480  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4481 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4482 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4483  if (((iCompH == pGetComp(strat->S[j]))
4484  || (0 == pGetComp(strat->S[j])))
4485  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4486  {
4487  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4488  }
4489  }
4490  }
4491 }
4492 
4493 static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4494 {
4495  const int iCompH = pGetComp(h);
4496  if (!nIsOne(pGetCoeff(h)))
4497  {
4498  int j;
4499 
4500  for (j=0; j<=k && !strat->sigdrop; j++)
4501  {
4502  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4503 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4504 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4505  if (((iCompH == pGetComp(strat->S[j]))
4506  || (0 == pGetComp(strat->S[j])))
4507  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4508  {
4509  enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4510  }
4511  }
4512  }
4513 }
4514 #endif
4515 
4516 #ifdef HAVE_RINGS
4517 /*2
4518 * Generates spoly(0, h) if applicable. Assumes ring in Z/2^n.
4519 */
4521 {
4522  if (nIsOne(pGetCoeff(h))) return;
4523  number gcd;
4524  bool go = false;
4525  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4526  {
4527  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4528  go = true;
4529  }
4530  else
4531  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4532  if (go || !nIsOne(gcd))
4533  {
4534  poly p = h->next;
4535  if (!go)
4536  {
4537  number tmp = gcd;
4538  gcd = n_Ann(gcd,currRing->cf);
4539  nDelete(&tmp);
4540  }
4541  p_Test(p,strat->tailRing);
4542  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4543  nDelete(&gcd);
4544 
4545  if (p != NULL)
4546  {
4547  if (TEST_OPT_PROT)
4548  {
4549  PrintS("Z");
4550  }
4551 #ifdef KDEBUG
4552  if (TEST_OPT_DEBUG)
4553  {
4554  PrintS("--- create zero spoly: ");
4555  p_wrp(h,currRing,strat->tailRing);
4556  PrintS(" ---> ");
4557  }
4558 #endif
4559  poly tmp = pInit();
4560  pSetCoeff0(tmp, pGetCoeff(p));
4561  for (int i = 1; i <= rVar(currRing); i++)
4562  {
4563  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4564  }
4566  {
4567  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4568  }
4569  p_Setm(tmp, currRing);
4570  p = p_LmFreeAndNext(p, strat->tailRing);
4571  pNext(tmp) = p;
4572  LObject Lp;
4573  Lp.Init();
4574  Lp.p = tmp;
4575  Lp.tailRing = strat->tailRing;
4576  int posx;
4577  if (Lp.p!=NULL)
4578  {
4579  strat->initEcart(&Lp);
4580  if (strat->Ll==-1)
4581  posx =0;
4582  else
4583  posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4584  Lp.sev = pGetShortExpVector(Lp.p);
4585  if (strat->tailRing != currRing)
4586  {
4587  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4588  }
4589 #ifdef KDEBUG
4590  if (TEST_OPT_DEBUG)
4591  {
4592  p_wrp(tmp,currRing,strat->tailRing);
4593  PrintLn();
4594  }
4595 #endif
4596  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4597  }
4598  }
4599  }
4600  nDelete(&gcd);
4601 }
4602 
4603 void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
4604 {
4605  if (nIsOne(pGetCoeff(h))) return;
4606  number gcd;
4607  bool go = false;
4608  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4609  {
4610  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4611  go = true;
4612  }
4613  else
4614  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4615  if (go || !nIsOne(gcd))
4616  {
4617  poly p = h->next;
4618  if (!go)
4619  {
4620  number tmp = gcd;
4621  gcd = n_Ann(gcd,currRing->cf);
4622  nDelete(&tmp);
4623  }
4624  p_Test(p,strat->tailRing);
4625  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4626 
4627  if (p != NULL)
4628  {
4629  if (TEST_OPT_PROT)
4630  {
4631  PrintS("Z");
4632  }
4633 #ifdef KDEBUG
4634  if (TEST_OPT_DEBUG)
4635  {
4636  PrintS("--- create zero spoly: ");
4637  p_wrp(h,currRing,strat->tailRing);
4638  PrintS(" ---> ");
4639  }
4640 #endif
4641  poly tmp = pInit();
4642  pSetCoeff0(tmp, pGetCoeff(p));
4643  for (int i = 1; i <= rVar(currRing); i++)
4644  {
4645  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4646  }
4648  {
4649  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4650  }
4651  p_Setm(tmp, currRing);
4652  p = p_LmFreeAndNext(p, strat->tailRing);
4653  pNext(tmp) = p;
4654  LObject Lp;
4655  Lp.Init();
4656  Lp.p = tmp;
4657  //printf("\nOld\n");pWrite(h);pWrite(hSig);
4658  #if EXT_POLY_NEW
4659  Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4660  if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4661  {
4662  strat->sigdrop = TRUE;
4663  //Try to reduce it as far as we can via redRing
4664  int red_result = redRing(&Lp,strat);
4665  if(red_result == 0)
4666  {
4667  // Cancel the sigdrop
4668  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4669  strat->sigdrop = FALSE;
4670  return;
4671  }
4672  else
4673  {
4674  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4675  #if 1
4676  strat->enterS(Lp,0,strat,strat->tl);
4677  #endif
4678  return;
4679  }
4680 
4681  }
4682  #else
4683  Lp.sig = pOne();
4684  if(strat->Ll >= 0)
4685  p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4686  else
4687  p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4688  #endif
4689  Lp.tailRing = strat->tailRing;
4690  int posx;
4691  if (Lp.p!=NULL)
4692  {
4693  strat->initEcart(&Lp);
4694  if (strat->Ll==-1)
4695  posx =0;
4696  else
4697  posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4698  Lp.sev = pGetShortExpVector(Lp.p);
4699  if (strat->tailRing != currRing)
4700  {
4701  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4702  }
4703 #ifdef KDEBUG
4704  if (TEST_OPT_DEBUG)
4705  {
4706  p_wrp(tmp,currRing,strat->tailRing);
4707  PrintLn();
4708  }
4709 #endif
4710  //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4711  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4712  }
4713  }
4714  nDelete(&gcd);
4715  }
4716  nDelete(&gcd);
4717 }
4718 #endif
4719 
4720 #ifdef HAVE_RINGS
4721 void clearSbatch (poly h,int k,int pos,kStrategy strat)
4722 {
4723  int j = pos;
4724  if ( (!strat->fromT)
4725  && ((strat->syzComp==0)
4726  ||(pGetComp(h)<=strat->syzComp)
4727  ))
4728  {
4729  // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4730  unsigned long h_sev = pGetShortExpVector(h);
4731  loop
4732  {
4733  if (j > k) break;
4734  clearS(h,h_sev, &j,&k,strat);
4735  j++;
4736  }
4737  // Print("end clearS sl=%d\n",strat->sl);
4738  }
4739 }
4740 #endif
4741 
4742 #ifdef HAVE_RINGS
4743 /*2
4744 * Generates a sufficient set of spolys (maybe just a finite generating
4745 * set of the syzygys)
4746 */
4747 void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4748 {
4750  // enter also zero divisor * poly, if this is non zero and of smaller degree
4751  if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat);
4752  initenterpairs(h, k, ecart, 0, strat, atR);
4753  initenterstrongPairs(h, k, ecart, 0, strat, atR);
4754  clearSbatch(h, k, pos, strat);
4755 }
4756 
4757 void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4758 {
4760  // enter also zero divisor * poly, if this is non zero and of smaller degree
4761  if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4762  if(strat->sigdrop) return;
4763  initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4764  if(strat->sigdrop) return;
4765  initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4766  if(strat->sigdrop) return;
4767  clearSbatch(h, k, pos, strat);
4768 }
4769 #endif
4770 
4771 /*2
4772 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4773 *superfluous elements in S will be deleted
4774 */
4775 void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4776 {
4777  int j=pos;
4778 
4780  initenterpairs(h,k,ecart,0,strat, atR);
4781  if ( (!strat->fromT)
4782  && ((strat->syzComp==0)
4783  ||(pGetComp(h)<=strat->syzComp)))
4784  {
4785  unsigned long h_sev = pGetShortExpVector(h);
4786  loop
4787  {
4788  if (j > k) break;
4789  clearS(h,h_sev, &j,&k,strat);
4790  j++;
4791  }
4792  }
4793 }
4794 
4795 /*2
4796 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4797 *superfluous elements in S will be deleted
4798 *this is a special variant of signature-based algorithms including the
4799 *signatures for criteria checks
4800 */
4801 void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4802 {
4803  int j=pos;
4805  initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4806  if ( (!strat->fromT)
4807  && ((strat->syzComp==0)
4808  ||(pGetComp(h)<=strat->syzComp)))
4809  {
4810  unsigned long h_sev = pGetShortExpVector(h);
4811  loop
4812  {
4813  if (j > k) break;
4814  clearS(h,h_sev, &j,&k,strat);
4815  j++;
4816  }
4817  }
4818 }
4819 
4820 /*2
4821 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4822 *superfluous elements in S will be deleted
4823 */
4824 void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4825 {
4826  int j;
4827  const int iCompH = pGetComp(h);
4828 
4829  if (rField_is_Ring(currRing))
4830  {
4831  for (j=0; j<=k; j++)
4832  {
4833  const int iCompSj = pGetComp(strat->S[j]);
4834  if ((iCompH==iCompSj)
4835  //|| (0==iCompH) // can only happen,if iCompSj==0
4836  || (0==iCompSj))
4837  {
4838  enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4839  }
4840  }
4841  kMergeBintoL(strat);
4842  }
4843  else
4844  {
4845  for (j=0; j<=k; j++)
4846  {
4847  const int iCompSj = pGetComp(strat->S[j]);
4848  if ((iCompH==iCompSj)
4849  //|| (0==iCompH) // can only happen,if iCompSj==0
4850  || (0==iCompSj))
4851  {
4852  enterOnePairSpecial(j,h,ecart,strat, atR);
4853  }
4854  }
4855  }
4856 
4857  if (strat->noClearS) return;
4858 
4859 // #ifdef HAVE_PLURAL
4860 /*
4861  if (rIsPluralRing(currRing))
4862  {
4863  j=pos;
4864  loop
4865  {
4866  if (j > k) break;
4867 
4868  if (pLmDivisibleBy(h, strat->S[j]))
4869  {
4870  deleteInS(j, strat);
4871  j--;
4872  k--;
4873  }
4874 
4875  j++;
4876  }
4877  }
4878  else
4879 */
4880 // #endif // ??? Why was the following cancelation disabled for non-commutative rings?
4881  {
4882  j=pos;
4883  loop
4884  {
4885  unsigned long h_sev = pGetShortExpVector(h);
4886  if (j > k) break;
4887  clearS(h,h_sev,&j,&k,strat);
4888  j++;
4889  }
4890  }
4891 }
4892 
4893 /*2
4894 *reorders s with respect to posInS,
4895 *suc is the first changed index or zero
4896 */
4897 
4898 void reorderS (int* suc,kStrategy strat)
4899 {
4900  int i,j,at,ecart, s2r;
4901  int fq=0;
4902  unsigned long sev;
4903  poly p;
4904  int new_suc=strat->sl+1;
4905  i= *suc;
4906  if (i<0) i=0;
4907 
4908  for (; i<=strat->sl; i++)
4909  {
4910  at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4911  if (at != i)
4912  {
4913  if (new_suc > at) new_suc = at;
4914  p = strat->S[i];
4915  ecart = strat->ecartS[i];
4916  sev = strat->sevS[i];
4917  s2r = strat->S_2_R[i];
4918  if (strat->fromQ!=NULL) fq=strat->fromQ[i];
4919  for (j=i; j>=at+1; j--)
4920  {
4921  strat->S[j] = strat->S[j-1];
4922  strat->ecartS[j] = strat->ecartS[j-1];
4923  strat->sevS[j] = strat->sevS[j-1];
4924  strat->S_2_R[j] = strat->S_2_R[j-1];
4925  }
4926  strat->S[at] = p;
4927  strat->ecartS[at] = ecart;
4928  strat->sevS[at] = sev;
4929  strat->S_2_R[at] = s2r;
4930  if (strat->fromQ!=NULL)
4931  {
4932  for (j=i; j>=at+1; j--)
4933  {
4934  strat->fromQ[j] = strat->fromQ[j-1];
4935  }
4936  strat->fromQ[at]=fq;
4937  }
4938  }
4939  }
4940  if (new_suc <= strat->sl) *suc=new_suc;
4941  else *suc=-1;
4942 }
4943 
4944 
4945 /*2
4946 *looks up the position of p in set
4947 *set[0] is the smallest with respect to the ordering-procedure deg/pComp
4948 * Assumption: posInS only depends on the leading term
4949 * otherwise, bba has to be changed
4950 */
4951 int posInS (const kStrategy strat, const int length,const poly p,
4952  const int ecart_p)
4953 {
4954  if(length==-1) return 0;
4955  polyset set=strat->S;
4956  int i;
4957  int an = 0;
4958  int en = length;
4959  int cmp_int = currRing->OrdSgn;
4961 #ifdef HAVE_PLURAL
4962  && (currRing->real_var_start==0)
4963 #endif
4964 #if 0
4965  || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
4966 #endif
4967  )
4968  {
4969  int o=p_Deg(p,currRing);
4970  int oo=p_Deg(set[length],currRing);
4971 
4972  if ((oo<o)
4973  || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
4974  return length+1;
4975 
4976  loop
4977  {
4978  if (an >= en-1)
4979  {
4980  if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
4981  {
4982  return an;
4983  }
4984  return en;
4985  }
4986  i=(an+en) / 2;
4987  if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
4988  else an=i;
4989  }
4990  }
4991  else
4992  {
4993  if (rField_is_Ring(currRing))
4994  {
4995  if (pLmCmp(set[length],p)== -cmp_int)
4996  return length+1;
4997  int cmp;
4998  loop
4999  {
5000  if (an >= en-1)
5001  {
5002  cmp = pLmCmp(set[an],p);
5003  if (cmp == cmp_int) return an;
5004  if (cmp == -cmp_int) return en;
5005  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
5006  return an;
5007  }
5008  i = (an+en) / 2;
5009  cmp = pLmCmp(set[i],p);
5010  if (cmp == cmp_int) en = i;
5011  else if (cmp == -cmp_int) an = i;
5012  else
5013  {
5014  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
5015  else en = i;
5016  }
5017  }
5018  }
5019  else
5020  if (pLmCmp(set[length],p)== -cmp_int)
5021  return length+1;
5022 
5023  loop
5024  {
5025  if (an >= en-1)
5026  {
5027  if (pLmCmp(set[an],p) == cmp_int) return an;
5028  if (pLmCmp(set[an],p) == -cmp_int) return en;
5029  if ((cmp_int!=1)
5030  && ((strat->ecartS[an])>ecart_p))
5031  return an;
5032  return en;
5033  }
5034  i=(an+en) / 2;
5035  if (pLmCmp(set[i],p) == cmp_int) en=i;
5036  else if (pLmCmp(set[i],p) == -cmp_int) an=i;
5037  else
5038  {
5039  if ((cmp_int!=1)
5040  &&((strat->ecartS[i])<ecart_p))
5041  en=i;
5042  else
5043  an=i;
5044  }
5045  }
5046  }
5047 }
5048 
5049 
5050 // sorts by degree and pLtCmp
5051 // but puts pure monomials at the beginning
5052 int posInSMonFirst (const kStrategy strat, const int length,const poly p)
5053 {
5054  if (length<0) return 0;
5055  polyset set=strat->S;
5056  if(pNext(p) == NULL)
5057  {
5058  int mon = 0;
5059  for(int i = 0;i<=length;i++)
5060  {
5061  if(set[i] != NULL && pNext(set[i]) == NULL)
5062  mon++;
5063  }
5064  int o = p_Deg(p,currRing);
5065  int op = p_Deg(set[mon],currRing);
5066 
5067  if ((op < o)
5068  || ((op == o) && (pLtCmp(set[mon],p) == -1)))
5069  return length+1;
5070  int i;
5071  int an = 0;
5072  int en= mon;
5073  loop
5074  {
5075  if (an >= en-1)
5076  {
5077  op = p_Deg(set[an],currRing);
5078  if ((op < o)
5079  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5080  return en;
5081  return an;
5082  }
5083  i=(an+en) / 2;
5084  op = p_Deg(set[i],currRing);
5085  if ((op < o)
5086  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5087  an=i;
5088  else
5089  en=i;
5090  }
5091  }
5092  else /*if(pNext(p) != NULL)*/
5093  {
5094  int o = p_Deg(p,currRing);
5095  int op = p_Deg(set[length],currRing);
5096 
5097  if ((op < o)
5098  || ((op == o) && (pLtCmp(set[length],p) == -1)))
5099  return length+1;
5100  int i;
5101  int an = 0;
5102  for(i=0;i<=length;i++)
5103  if(set[i] != NULL && pNext(set[i]) == NULL)
5104  an++;
5105  int en= length;
5106  loop
5107  {
5108  if (an >= en-1)
5109  {
5110  op = p_Deg(set[an],currRing);
5111  if ((op < o)
5112  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5113  return en;
5114  return an;
5115  }
5116  i=(an+en) / 2;
5117  op = p_Deg(set[i],currRing);
5118  if ((op < o)
5119  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5120  an=i;
5121  else
5122  en=i;
5123  }
5124  }
5125 }
5126 
5127 // sorts by degree and pLtCmp in the block between start,end;
5128 // but puts pure monomials at the beginning
5129 int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
5130 {
5131  if(end < 0 || end >= IDELEMS(F))
5132  end = IDELEMS(F);
5133  if (end<0) return 0;
5134  if(pNext(p) == NULL) return start;
5135  polyset set=F->m;
5136  int o = p_Deg(p,currRing);
5137  int op;
5138  int i;
5139  int an = start;
5140  for(i=start;i<end;i++)
5141  if(set[i] != NULL && pNext(set[i]) == NULL)
5142  an++;
5143  if(an == end-1)
5144  return end;
5145  int en= end;
5146  loop
5147  {
5148  if(an>=en)
5149  return en;
5150  if (an == en-1)
5151  {
5152  op = p_Deg(set[an],currRing);
5153  if ((op < o)
5154  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5155  return en;
5156  return an;
5157  }
5158  i=(an+en) / 2;
5159  op = p_Deg(set[i],currRing);
5160  if ((op < o)
5161  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5162  an=i;
5163  else
5164  en=i;
5165  }
5166 }
5167 
5168 
5169 /*2
5170 * looks up the position of p in set
5171 * the position is the last one
5172 */
5173 int posInT0 (const TSet,const int length,LObject &)
5174 {
5175  return (length+1);
5176 }
5177 
5178 
5179 /*2
5180 * looks up the position of p in T
5181 * set[0] is the smallest with respect to the ordering-procedure
5182 * pComp
5183 */
5184 int posInT1 (const TSet set,const int length,LObject &p)
5185 {
5186  if (length==-1) return 0;
5187 
5188  if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
5189 
5190  int i;
5191  int an = 0;
5192  int en= length;
5193 
5194  loop
5195  {
5196  if (an >= en-1)
5197  {
5198  if (pLmCmp(set[an].p,p.p) == currRing->OrdSgn) return an;
5199  return en;
5200  }
5201  i=(an+en) / 2;
5202  if (pLmCmp(set[i].p,p.p) == currRing->OrdSgn) en=i;
5203  else an=i;
5204  }
5205 }
5206 
5207 /*2
5208 * looks up the position of p in T
5209 * set[0] is the smallest with respect to the ordering-procedure
5210 * length
5211 */
5212 int posInT2 (const TSet set,const int length,LObject &p)
5213 {
5214  p.GetpLength();
5215  if (length==-1)
5216  return 0;
5217  if (set[length].length<p.length)
5218  return length+1;
5219 
5220  int i;
5221  int an = 0;
5222  int en= length;
5223 
5224  loop
5225  {
5226  if (an >= en-1)
5227  {
5228  if (set[an].length>p.length) return an;
5229  return en;
5230  }
5231  i=(an+en) / 2;
5232  if (set[i].length>p.length) en=i;
5233  else an=i;
5234  }
5235 }
5236 
5237 /*2
5238 * looks up the position of p in T
5239 * set[0] is the smallest with respect to the ordering-procedure
5240 * totaldegree,pComp
5241 */
5242 int posInT11 (const TSet set,const int length,LObject &p)
5243 {
5244  if (length==-1) return 0;
5245 
5246  int o = p.GetpFDeg();
5247  int op = set[length].GetpFDeg();
5248 
5249  if ((op < o)
5250  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5251  return length+1;
5252 
5253  int i;
5254  int an = 0;
5255  int en= length;
5256 
5257  loop
5258  {
5259  if (an >= en-1)
5260  {
5261  op= set[an].GetpFDeg();
5262  if ((op > o)
5263  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5264  return an;
5265  return en;
5266  }
5267  i=(an+en) / 2;
5268  op = set[i].GetpFDeg();
5269  if (( op > o)
5270  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5271  en=i;
5272  else
5273  an=i;
5274  }
5275 }
5276 
5277 #ifdef HAVE_RINGS
5278 int posInT11Ring (const TSet set,const int length,LObject &p)
5279 {
5280  if (length==-1) return 0;
5281 
5282  int o = p.GetpFDeg();
5283  int op = set[length].GetpFDeg();
5284 
5285  if ((op < o)
5286  || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5287  return length+1;
5288 
5289  int i;
5290  int an = 0;
5291  int en= length;
5292 
5293  loop
5294  {
5295  if (an >= en-1)
5296  {
5297  op= set[an].GetpFDeg();
5298  if ((op > o)
5299  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5300  return an;
5301  return en;
5302  }
5303  i=(an+en) / 2;
5304  op = set[i].GetpFDeg();
5305  if (( op > o)
5306  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5307  en=i;
5308  else
5309  an=i;
5310  }
5311 }
5312 #endif
5313 
5314 /*2 Pos for rings T: Here I am
5315 * looks up the position of p in T
5316 * set[0] is the smallest with respect to the ordering-procedure
5317 * totaldegree,pComp
5318 */
5319 int posInTrg0 (const TSet set,const int length,LObject &p)
5320 {
5321  if (length==-1) return 0;
5322  int o = p.GetpFDeg();
5323  int op = set[length].GetpFDeg();
5324  int i;
5325  int an = 0;
5326  int en = length;
5327  int cmp_int = currRing->OrdSgn;
5328  if ((op < o) || (pLmCmp(set[length].p,p.p)== -cmp_int))
5329  return length+1;
5330  int cmp;
5331  loop
5332  {
5333  if (an >= en-1)
5334  {
5335  op = set[an].GetpFDeg();
5336  if (op > o) return an;
5337  if (op < 0) return en;
5338  cmp = pLmCmp(set[an].p,p.p);
5339  if (cmp == cmp_int) return an;
5340  if (cmp == -cmp_int) return en;
5341  if (nGreater(pGetCoeff(p.p), pGetCoeff(set[an].p))) return en;
5342  return an;
5343  }
5344  i = (an + en) / 2;
5345  op = set[i].GetpFDeg();
5346  if (op > o) en = i;
5347  else if (op < o) an = i;
5348  else
5349  {
5350  cmp = pLmCmp(set[i].p,p.p);
5351  if (cmp == cmp_int) en = i;
5352  else if (cmp == -cmp_int) an = i;
5353  else if (nGreater(pGetCoeff(p.p), pGetCoeff(set[i].p))) an = i;
5354  else en = i;
5355  }
5356  }
5357 }
5358 /*
5359  int o = p.GetpFDeg();
5360  int op = set[length].GetpFDeg();
5361 
5362  if ((op < o)
5363  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5364  return length+1;
5365 
5366  int i;
5367  int an = 0;
5368  int en= length;
5369 
5370  loop
5371  {
5372  if (an >= en-1)
5373  {
5374  op= set[an].GetpFDeg();
5375  if ((op > o)
5376  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5377  return an;
5378  return en;
5379  }
5380  i=(an+en) / 2;
5381  op = set[i].GetpFDeg();
5382  if (( op > o)
5383  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5384  en=i;
5385  else
5386  an=i;
5387  }
5388 }
5389  */
5390 /*2
5391 * looks up the position of p in T
5392 * set[0] is the smallest with respect to the ordering-procedure
5393 * totaldegree,pComp
5394 */
5395 int posInT110 (const TSet set,const int length,LObject &p)
5396 {
5397  p.GetpLength();
5398  if (length==-1) return 0;
5399 
5400  int o = p.GetpFDeg();
5401  int op = set[length].GetpFDeg();
5402 
5403  if (( op < o)
5404  || (( op == o) && (set[length].length<p.length))
5405  || (( op == o) && (set[length].length == p.length)
5406  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5407  return length+1;
5408 
5409  int i;
5410  int an = 0;
5411  int en= length;
5412  loop
5413  {
5414  if (an >= en-1)
5415  {
5416  op = set[an].GetpFDeg();
5417  if (( op > o)
5418  || (( op == o) && (set[an].length > p.length))
5419  || (( op == o) && (set[an].length == p.length)
5420  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5421  return an;
5422  return en;
5423  }
5424  i=(an+en) / 2;
5425  op = set[i].GetpFDeg();
5426  if (( op > o)
5427  || (( op == o) && (set[i].length > p.length))
5428  || (( op == o) && (set[i].length == p.length)
5429  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5430  en=i;
5431  else
5432  an=i;
5433  }
5434 }
5435 
5436 #ifdef HAVE_RINGS
5437 int posInT110Ring (const TSet set,const int length,LObject &p)
5438 {
5439  p.GetpLength();
5440  if (length==-1) return 0;
5441 
5442  int o = p.GetpFDeg();
5443  int op = set[length].GetpFDeg();
5444 
5445  if (( op < o)
5446  || (( op == o) && (set[length].length<p.length))
5447  || (( op == o) && (set[length].length == p.length)
5448  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5449  return length+1;
5450 
5451  int i;
5452  int an = 0;
5453  int en= length;
5454  loop
5455  {
5456  if (an >= en-1)
5457  {
5458  op = set[an].GetpFDeg();
5459  if (( op > o)
5460  || (( op == o) && (set[an].length > p.length))
5461  || (( op == o) && (set[an].length == p.length)
5462  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5463  return an;
5464  return en;
5465  }
5466  i=(an+en) / 2;
5467  op = set[i].GetpFDeg();
5468  if (( op > o)
5469  || (( op == o) && (set[i].length > p.length))
5470  || (( op == o) && (set[i].length == p.length)
5471  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5472  en=i;
5473  else
5474  an=i;
5475  }
5476 }
5477 #endif
5478 
5479 /*2
5480 * looks up the position of p in set
5481 * set[0] is the smallest with respect to the ordering-procedure
5482 * pFDeg
5483 */
5484 int posInT13 (const TSet set,const int length,LObject &p)
5485 {
5486  if (length==-1) return 0;
5487 
5488  int o = p.GetpFDeg();
5489 
5490  if (set[length].GetpFDeg() <= o)
5491  return length+1;
5492 
5493  int i;
5494  int an = 0;
5495  int en= length;
5496  loop
5497  {
5498  if (an >= en-1)
5499  {
5500  if (set[an].GetpFDeg() > o)
5501  return an;
5502  return en;
5503  }
5504  i=(an+en) / 2;
5505  if (set[i].GetpFDeg() > o)
5506  en=i;
5507  else
5508  an=i;
5509  }
5510 }
5511 
5512 // determines the position based on: 1.) Ecart 2.) pLength
5513 int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5514 {
5515  int ol = p.GetpLength();
5516  if (length==-1) return 0;
5517 
5518  int op=p.ecart;
5519 
5520  int oo=set[length].ecart;
5521  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
5522  return length+1;
5523 
5524  int i;
5525  int an = 0;
5526  int en= length;
5527  loop
5528  {
5529  if (an >= en-1)
5530  {
5531  int oo=set[an].ecart;
5532  if((oo > op)
5533  || ((oo==op) && (set[an].pLength > ol)))
5534  return an;
5535  return en;
5536  }
5537  i=(an+en) / 2;
5538  int oo=set[i].ecart;
5539  if ((oo > op)
5540  || ((oo == op) && (set[i].pLength > ol)))
5541  en=i;
5542  else
5543  an=i;
5544  }
5545 }
5546 
5547 /*2
5548 * looks up the position of p in set
5549 * set[0] is the smallest with respect to the ordering-procedure
5550 * maximaldegree, pComp
5551 */
5552 int posInT15 (const TSet set,const int length,LObject &p)
5553 /*{
5554  *int j=0;
5555  * int o;
5556  *
5557  * o = p.GetpFDeg()+p.ecart;
5558  * loop
5559  * {
5560  * if ((set[j].GetpFDeg()+set[j].ecart > o)
5561  * || ((set[j].GetpFDeg()+set[j].ecart == o)
5562  * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5563  * {
5564  * return j;
5565  * }
5566  * j++;
5567  * if (j > length) return j;
5568  * }
5569  *}
5570  */
5571 {
5572  if (length==-1) return 0;
5573 
5574  int o = p.GetpFDeg() + p.ecart;
5575  int op = set[length].GetpFDeg()+set[length].ecart;
5576 
5577  if ((op < o)
5578  || ((op == o)
5579  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5580  return length+1;
5581 
5582  int i;
5583  int an = 0;
5584  int en= length;
5585  loop
5586  {
5587  if (an >= en-1)
5588  {
5589  op = set[an].GetpFDeg()+set[an].ecart;
5590  if (( op > o)
5591  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5592  return an;
5593  return en;
5594  }
5595  i=(an+en) / 2;
5596  op = set[i].GetpFDeg()+set[i].ecart;
5597  if (( op > o)
5598  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5599  en=i;
5600  else
5601  an=i;
5602  }
5603 }
5604 
5605 #ifdef HAVE_RINGS
5606 int posInT15Ring (const TSet set,const int length,LObject &p)
5607 {
5608  if (length==-1) return 0;
5609 
5610  int o = p.GetpFDeg() + p.ecart;
5611  int op = set[length].GetpFDeg()+set[length].ecart;
5612 
5613  if ((op < o)
5614  || ((op == o)
5615  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5616  return length+1;
5617 
5618  int i;
5619  int an = 0;
5620  int en= length;
5621  loop
5622  {
5623  if (an >= en-1)
5624  {
5625  op = set[an].GetpFDeg()+set[an].ecart;
5626  if (( op > o)
5627  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5628  return an;
5629  return en;
5630  }
5631  i=(an+en) / 2;
5632  op = set[i].GetpFDeg()+set[i].ecart;
5633  if (( op > o)
5634  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5635  en=i;
5636  else
5637  an=i;
5638  }
5639 }
5640 #endif
5641 
5642 /*2
5643 * looks up the position of p in set
5644 * set[0] is the smallest with respect to the ordering-procedure
5645 * pFDeg+ecart, ecart, pComp
5646 */
5647 int posInT17 (const TSet set,const int length,LObject &p)
5648 /*
5649 *{
5650 * int j=0;
5651 * int o;
5652 *
5653 * o = p.GetpFDeg()+p.ecart;
5654 * loop
5655 * {
5656 * if ((pFDeg(set[j].p)+set[j].ecart > o)
5657 * || (((pFDeg(set[j].p)+set[j].ecart == o)
5658 * && (set[j].ecart < p.ecart)))
5659 * || ((pFDeg(set[j].p)+set[j].ecart == o)
5660 * && (set[j].ecart==p.ecart)
5661 * && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5662 * return j;
5663 * j++;
5664 * if (j > length) return j;
5665 * }
5666 * }
5667 */
5668 {
5669  if (length==-1) return 0;
5670 
5671  int o = p.GetpFDeg() + p.ecart;
5672  int op = set[length].GetpFDeg()+set[length].ecart;
5673 
5674  if ((op < o)
5675  || (( op == o) && (set[length].ecart > p.ecart))
5676  || (( op == o) && (set[length].ecart==p.ecart)
5677  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5678  return length+1;
5679 
5680  int i;
5681  int an = 0;
5682  int en= length;
5683  loop
5684  {
5685  if (an >= en-1)
5686  {
5687  op = set[an].GetpFDeg()+set[an].ecart;
5688  if (( op > o)
5689  || (( op == o) && (set[an].ecart < p.ecart))
5690  || (( op == o) && (set[an].ecart==p.ecart)
5691  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5692  return an;
5693  return en;
5694  }
5695  i=(an+en) / 2;
5696  op = set[i].GetpFDeg()+set[i].ecart;
5697  if ((op > o)
5698  || (( op == o) && (set[i].ecart < p.ecart))
5699  || (( op == o) && (set[i].ecart == p.ecart)
5700  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5701  en=i;
5702  else
5703  an=i;
5704  }
5705 }
5706 
5707 #ifdef HAVE_RINGS
5708 int posInT17Ring (const TSet set,const int length,LObject &p)
5709 {
5710  if (length==-1) return 0;
5711 
5712  int o = p.GetpFDeg() + p.ecart;
5713  int op = set[length].GetpFDeg()+set[length].ecart;
5714 
5715  if ((op < o)
5716  || (( op == o) && (set[length].ecart > p.ecart))
5717  || (( op == o) && (set[length].ecart==p.ecart)
5718  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5719  return length+1;
5720 
5721  int i;
5722  int an = 0;
5723  int en= length;
5724  loop
5725  {
5726  if (an >= en-1)
5727  {
5728  op = set[an].GetpFDeg()+set[an].ecart;
5729  if (( op > o)
5730  || (( op == o) && (set[an].ecart < p.ecart))
5731  || (( op == o) && (set[an].ecart==p.ecart)
5732  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5733  return an;
5734  return en;
5735  }
5736  i=(an+en) / 2;
5737  op = set[i].GetpFDeg()+set[i].ecart;
5738  if ((op > o)
5739  || (( op == o) && (set[i].ecart < p.ecart))
5740  || (( op == o) && (set[i].ecart == p.ecart)
5741  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5742  en=i;
5743  else
5744  an=i;
5745  }
5746 }
5747 #endif
5748 
5749 /*2
5750 * looks up the position of p in set
5751 * set[0] is the smallest with respect to the ordering-procedure
5752 * pGetComp, pFDeg+ecart, ecart, pComp
5753 */
5754 int posInT17_c (const TSet set,const int length,LObject &p)
5755 {
5756  if (length==-1) return 0;
5757 
5758  int cc = (-1+2*currRing->order[0]==ringorder_c);
5759  /* cc==1 for (c,..), cc==-1 for (C,..) */
5760  int o = p.GetpFDeg() + p.ecart;
5761  int c = pGetComp(p.p)*cc;
5762 
5763  if (pGetComp(set[length].p)*cc < c)
5764  return length+1;
5765  if (pGetComp(set[length].p)*cc == c)
5766  {
5767  int op = set[length].GetpFDeg()+set[length].ecart;
5768  if ((op < o)
5769  || ((op == o) && (set[length].ecart > p.ecart))
5770  || ((op == o) && (set[length].ecart==p.ecart)
5771  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5772  return length+1;
5773  }
5774 
5775  int i;
5776  int an = 0;
5777  int en= length;
5778  loop
5779  {
5780  if (an >= en-1)
5781  {
5782  if (pGetComp(set[an].p)*cc < c)
5783  return en;
5784  if (pGetComp(set[an].p)*cc == c)
5785  {
5786  int op = set[an].GetpFDeg()+set[an].ecart;
5787  if ((op > o)
5788  || ((op == o) && (set[an].ecart < p.ecart))
5789  || ((op == o) && (set[an].ecart==p.ecart)
5790  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5791  return an;
5792  }
5793  return en;
5794  }
5795  i=(an+en) / 2;
5796  if (pGetComp(set[i].p)*cc > c)
5797  en=i;
5798  else if (pGetComp(set[i].p)*cc == c)
5799  {
5800  int op = set[i].GetpFDeg()+set[i].ecart;
5801  if ((op > o)
5802  || ((op == o) && (set[i].ecart < p.ecart))
5803  || ((op == o) && (set[i].ecart == p.ecart)
5804  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5805  en=i;
5806  else
5807  an=i;
5808  }
5809  else
5810  an=i;
5811  }
5812 }
5813 
5814 #ifdef HAVE_RINGS
5815 int posInT17_cRing (const TSet set,const int length,LObject &p)
5816 {
5817  if (length==-1) return 0;
5818 
5819  int cc = (-1+2*currRing->order[0]==ringorder_c);
5820  /* cc==1 for (c,..), cc==-1 for (C,..) */
5821  int o = p.GetpFDeg() + p.ecart;
5822  int c = pGetComp(p.p)*cc;
5823 
5824  if (pGetComp(set[length].p)*cc < c)
5825  return length+1;
5826  if (pGetComp(set[length].p)*cc == c)
5827  {
5828  int op = set[length].GetpFDeg()+set[length].ecart;
5829  if ((op < o)
5830  || ((op == o) && (set[length].ecart > p.ecart))
5831  || ((op == o) && (set[length].ecart==p.ecart)
5832  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5833  return length+1;
5834  }
5835 
5836  int i;
5837  int an = 0;
5838  int en= length;
5839  loop
5840  {
5841  if (an >= en-1)
5842  {
5843  if (pGetComp(set[an].p)*cc < c)
5844  return en;
5845  if (pGetComp(set[an].p)*cc == c)
5846  {
5847  int op = set[an].GetpFDeg()+set[an].ecart;
5848  if ((op > o)
5849  || ((op == o) && (set[an].ecart < p.ecart))
5850  || ((op == o) && (set[an].ecart==p.ecart)
5851  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5852  return an;
5853  }
5854  return en;
5855  }
5856  i=(an+en) / 2;
5857  if (pGetComp(set[i].p)*cc > c)
5858  en=i;
5859  else if (pGetComp(set[i].p)*cc == c)
5860  {
5861  int op = set[i].GetpFDeg()+set[i].ecart;
5862  if ((op > o)
5863  || ((op == o) && (set[i].ecart < p.ecart))
5864  || ((op == o) && (set[i].ecart == p.ecart)
5865  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5866  en=i;
5867  else
5868  an=i;
5869  }
5870  else
5871  an=i;
5872  }
5873 }
5874 #endif
5875 
5876 /*2
5877 * looks up the position of p in set
5878 * set[0] is the smallest with respect to
5879 * ecart, pFDeg, length
5880 */
5881 int posInT19 (const TSet set,const int length,LObject &p)
5882 {
5883  p.GetpLength();
5884  if (length==-1) return 0;
5885 
5886  int o = p.ecart;
5887  int op=p.GetpFDeg();
5888 
5889  if (set[length].ecart < o)
5890  return length+1;
5891  if (set[length].ecart == o)
5892  {
5893  int oo=set[length].GetpFDeg();
5894  if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5895  return length+1;
5896  }
5897 
5898  int i;
5899  int an = 0;
5900  int en= length;
5901  loop
5902  {
5903  if (an >= en-1)
5904  {
5905  if (set[an].ecart > o)
5906  return an;
5907  if (set[an].ecart == o)
5908  {
5909  int oo=set[an].GetpFDeg();
5910  if((oo > op)
5911  || ((oo==op) && (set[an].length > p.length)))
5912  return an;
5913  }
5914  return en;
5915  }
5916  i=(an+en) / 2;
5917  if (set[i].ecart > o)
5918  en=i;
5919  else if (set[i].ecart == o)
5920  {
5921  int oo=set[i].GetpFDeg();
5922  if ((oo > op)
5923  || ((oo == op) && (set[i].length > p.length)))
5924  en=i;
5925  else
5926  an=i;
5927  }
5928  else
5929  an=i;
5930  }
5931 }
5932 
5933 /*2
5934 *looks up the position of polynomial p in set
5935 *set[length] is the smallest element in set with respect
5936 *to the ordering-procedure pComp
5937 */
5938 int posInLSpecial (const LSet set, const int length,
5939  LObject *p,const kStrategy)
5940 {
5941  if (length<0) return 0;
5942 
5943  int d=p->GetpFDeg();
5944  int op=set[length].GetpFDeg();
5945 
5946  if ((op > d)
5947  || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
5948  || (pLmCmp(set[length].p,p->p)== currRing->OrdSgn))
5949  return length+1;
5950 
5951  int i;
5952  int an = 0;
5953  int en= length;
5954  loop
5955  {
5956  if (an >= en-1)
5957  {
5958  op=set[an].GetpFDeg();
5959  if ((op > d)
5960  || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
5961  || (pLmCmp(set[an].p,p->p)== currRing->OrdSgn))
5962  return en;
5963  return an;
5964  }
5965  i=(an+en) / 2;
5966  op=set[i].GetpFDeg();
5967  if ((op>d)
5968  || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
5969  || (pLmCmp(set[i].p,p->p) == currRing->OrdSgn))
5970  an=i;
5971  else
5972  en=i;
5973  }
5974 }
5975 
5976 /*2
5977 *looks up the position of polynomial p in set
5978 *set[length] is the smallest element in set with respect
5979 *to the ordering-procedure pComp
5980 */
5981 int posInL0 (const LSet set, const int length,
5982  LObject* p,const kStrategy)
5983 {
5984  if (length<0) return 0;
5985 
5986  if (pLmCmp(set[length].p,p->p)== currRing->OrdSgn)
5987  return length+1;
5988 
5989  int i;
5990  int an = 0;
5991  int en= length;
5992  loop
5993  {
5994  if (an >= en-1)
5995  {
5996  if (pLmCmp(set[an].p,p->p) == currRing->OrdSgn) return en;
5997  return an;
5998  }
5999  i=(an+en) / 2;
6000  if (pLmCmp(set[i].p,p->p) == currRing->OrdSgn) an=i;
6001  else en=i;
6002  /*aend. fuer lazy == in !=- machen */
6003  }
6004 }
6005 
6006 #ifdef HAVE_RINGS
6007 int posInL0Ring (const LSet set, const int length,
6008  LObject* p,const kStrategy)
6009 {
6010  if (length<0) return 0;
6011 
6012  if (pLtCmpOrdSgnEqP(set[length].p,p->p))
6013  return length+1;
6014 
6015  int i;
6016  int an = 0;
6017  int en= length;
6018  loop
6019  {
6020  if (an >= en-1)
6021  {
6022  if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
6023  return an;
6024  }
6025  i=(an+en) / 2;
6026  if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
6027  else en=i;
6028  /*aend. fuer lazy == in !=- machen */
6029  }
6030 }
6031 #endif
6032 
6033 /*2
6034 * looks up the position of polynomial p in set
6035 * e is the ecart of p
6036 * set[length] is the smallest element in set with respect
6037 * to the signature order
6038 */
6039 int posInLSig (const LSet set, const int length,
6040  LObject* p,const kStrategy /*strat*/)
6041 {
6042  if (length<0) return 0;
6043  if (pLtCmp(set[length].sig,p->sig)== currRing->OrdSgn)
6044  return length+1;
6045 
6046  int i;
6047  int an = 0;
6048  int en= length;
6049  loop
6050  {
6051  if (an >= en-1)
6052  {
6053  if (pLtCmp(set[an].sig,p->sig) == currRing->OrdSgn) return en;
6054  return an;
6055  }
6056  i=(an+en) / 2;
6057  if (pLtCmp(set[i].sig,p->sig) == currRing->OrdSgn) an=i;
6058  else en=i;
6059  /*aend. fuer lazy == in !=- machen */
6060  }
6061 }
6062 //sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
6063 int posInLSigRing (const LSet set, const int length,
6064  LObject* p,const kStrategy /*strat*/)
6065 {
6066  assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
6067  if (length<0) return 0;
6068  if (pLtCmp(set[length].sig,p->sig)== 1)
6069  return length+1;
6070 
6071  int an,en,i;
6072  an = 0;
6073  en = length+1;
6074  int cmp;
6075  loop
6076  {
6077  if (an >= en-1)
6078  {
6079  if(an == en)
6080  return en;
6081  cmp = pLtCmp(set[an].sig,p->sig);
6082  if (cmp == 1)
6083  return en;
6084  if (cmp == -1)
6085  return an;
6086  if (cmp == 0)
6087  {
6088  if (set[an].FDeg > p->FDeg)
6089  return en;
6090  if (set[an].FDeg < p->FDeg)
6091  return an;
6092  if (set[an].FDeg == p->FDeg)
6093  {
6094  cmp = pLtCmp(set[an].p,p->p);
6095  if(cmp == 1)
6096  return en;
6097  else
6098  return an;
6099  }
6100  }
6101  }
6102  i=(an+en) / 2;
6103  cmp = pLtCmp(set[i].sig,p->sig);
6104  if (cmp == 1)
6105  an = i;
6106  if (cmp == -1)
6107  en = i;
6108  if (cmp == 0)
6109  {
6110  if (set[i].FDeg > p->FDeg)
6111  an = i;
6112  if (set[i].FDeg < p->FDeg)
6113  en = i;
6114  if (set[i].FDeg == p->FDeg)
6115  {
6116  cmp = pLtCmp(set[i].p,p->p);
6117  if(cmp == 1)
6118  an = i;
6119  else
6120  en = i;
6121  }
6122  }
6123  }
6124 }
6125 
6126 int posInLRing (const LSet set, const int length,
6127  LObject* p,const kStrategy /*strat*/)
6128 {
6129  if (length < 0) return 0;
6130  if (set[length].FDeg > p->FDeg)
6131  return length+1;
6132  if (set[length].FDeg == p->FDeg)
6133  if(set[length].GetpLength() > p->GetpLength())
6134  return length+1;
6135  int i;
6136  int an = 0;
6137  int en= length+1;
6138  loop
6139  {
6140  if (an >= en-1)
6141  {
6142  if(an == en)
6143  return en;
6144  if (set[an].FDeg > p->FDeg)
6145  return en;
6146  if(set[an].FDeg == p->FDeg)
6147  {
6148  if(set[an].GetpLength() > p->GetpLength())
6149  return en;
6150  else
6151  {
6152  if(set[an].GetpLength() == p->GetpLength())
6153  {
6154  if(nGreater(set[an].p->coef, p->p->coef))
6155  return en;
6156  else
6157  return an;
6158  }
6159  else
6160  {
6161  return an;
6162  }
6163  }
6164  }
6165  else
6166  return an;
6167  }
6168  i=(an+en) / 2;
6169  if (set[i].FDeg > p->FDeg)
6170  an=i;
6171  else
6172  {
6173  if(set[i].FDeg == p->FDeg)
6174  {
6175  if(set[i].GetpLength() > p->GetpLength())
6176  an=i;
6177  else
6178  {
6179  if(set[i].GetpLength() == p->GetpLength())
6180  {
6181  if(nGreater(set[i].p->coef, p->p->coef))
6182  an = i;
6183  else
6184  en = i;
6185  }
6186  else
6187  {
6188  en=i;
6189  }
6190  }
6191  }
6192  else
6193  en=i;
6194  }
6195  }
6196 }
6197 
6198 // for sba, sorting syzygies
6199 int posInSyz (const kStrategy strat, poly sig)
6200 {
6201  if (strat->syzl==0) return 0;
6202  if (pLtCmp(strat->syz[strat->syzl-1],sig) != currRing->OrdSgn)
6203  return strat->syzl;
6204  int i;
6205  int an = 0;
6206  int en= strat->syzl-1;
6207  loop
6208  {
6209  if (an >= en-1)
6210  {
6211  if (pLtCmp(strat->syz[an],sig) != currRing->OrdSgn) return en;
6212  return an;
6213  }
6214  i=(an+en) / 2;
6215  if (pLtCmp(strat->syz[i],sig) != currRing->OrdSgn) an=i;
6216  else en=i;
6217  /*aend. fuer lazy == in !=- machen */
6218  }
6219 }
6220 
6221 /*2
6222 *
6223 * is only used in F5C, must ensure that the interreduction process does add new
6224 * critical pairs to strat->L only behind all other critical pairs which are
6225 * still in strat->L!
6226 */
6227 int posInLF5C (const LSet /*set*/, const int /*length*/,
6228  LObject* /*p*/,const kStrategy strat)
6229 {
6230  return strat->Ll+1;
6231 }
6232 
6233 /*2
6234 * looks up the position of polynomial p in set
6235 * e is the ecart of p
6236 * set[length] is the smallest element in set with respect
6237 * to the ordering-procedure totaldegree,pComp
6238 */
6239 int posInL11 (const LSet set, const int length,
6240  LObject* p,const kStrategy)
6241 {
6242  if (length<0) return 0;
6243 
6244  int o = p->GetpFDeg();
6245  int op = set[length].GetpFDeg();
6246 
6247  if ((op > o)
6248  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6249  return length+1;
6250  int i;
6251  int an = 0;
6252  int en= length;
6253  loop
6254  {
6255  if (an >= en-1)
6256  {
6257  op = set[an].GetpFDeg();
6258  if ((op > o)
6259  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6260  return en;
6261  return an;
6262  }
6263  i=(an+en) / 2;
6264  op = set[i].GetpFDeg();
6265  if ((op > o)
6266  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6267  an=i;
6268  else
6269  en=i;
6270  }
6271 }
6272 
6273 #ifdef HAVE_RINGS
6274 /*2
6275 * looks up the position of polynomial p in set
6276 * set[length] is the smallest element in set with respect
6277 * to the ordering-procedure pLmCmp,totaldegree,coefficient
6278 * For the same totaldegree, original pairs (from F) will
6279 * be put at the end and smalles coefficents
6280 */
6281 int posInL11Ring (const LSet set, const int length,
6282  LObject* p,const kStrategy)
6283 {
6284  if (length<0) return 0;
6285 
6286  int o = p->GetpFDeg();
6287  int op = set[length].GetpFDeg();
6288 
6289  if ((op > o)
6290  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6291  return length+1;
6292  int i;
6293  int an = 0;
6294  int en= length;
6295  loop
6296  {
6297  if (an >= en-1)
6298  {
6299  op = set[an].GetpFDeg();
6300  if ((op > o)
6301  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6302  return en;
6303  return an;
6304  }
6305  i=(an+en) / 2;
6306  op = set[i].GetpFDeg();
6307  if ((op > o)
6308  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6309  an=i;
6310  else
6311  en=i;
6312  }
6313 }
6314 
6315 int posInLF5CRing (const LSet set, int start,const int length,
6316  LObject* p,const kStrategy)
6317 {
6318  if (length<0) return 0;
6319  if(start == (length +1)) return (length+1);
6320  int o = p->GetpFDeg();
6321  int op = set[length].GetpFDeg();
6322 
6323  if ((op > o)
6324  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6325  return length+1;
6326  int i;
6327  int an = start;
6328  int en= length;
6329  loop
6330  {
6331  if (an >= en-1)
6332  {
6333  op = set[an].GetpFDeg();
6334  if ((op > o)
6335  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6336  return en;
6337  return an;
6338  }
6339  i=(an+en) / 2;
6340  op = set[i].GetpFDeg();
6341  if ((op > o)
6342  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6343  an=i;
6344  else
6345  en=i;
6346  }
6347 }
6348 #endif
6349 
6350 #ifdef HAVE_RINGS
6351 int posInL11Ringls (const LSet set, const int length,
6352  LObject* p,const kStrategy)
6353 {
6354  if (length < 0) return 0;
6355  int an,en,i;
6356  an = 0;
6357  en = length+1;
6358  loop
6359  {
6360  if (an >= en-1)
6361  {
6362  if(an == en)
6363  return en;
6364  if (set[an].FDeg > p->FDeg)
6365  return en;
6366  if (set[an].FDeg < p->FDeg)
6367  return an;
6368  if (set[an].FDeg == p->FDeg)
6369  {
6370  number lcset,lcp;
6371  lcset = pGetCoeff(set[an].p);
6372  lcp = pGetCoeff(p->p);
6373  if(!nGreaterZero(lcset))
6374  {
6375  set[an].p=p_Neg(set[an].p,currRing);
6376  if (set[an].t_p!=NULL)
6377  pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
6378  lcset=pGetCoeff(set[an].p);
6379  }
6380  if(!nGreaterZero(lcp))
6381  {
6382  p->p=p_Neg(p->p,currRing);
6383  if (p->t_p!=NULL)
6384  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6385  lcp=pGetCoeff(p->p);
6386  }
6387  if(nGreater(lcset, lcp))
6388  {
6389  return en;
6390  }
6391  else
6392  {
6393  return an;
6394  }
6395  }
6396  }
6397  i=(an+en) / 2;
6398  if (set[i].FDeg > p->FDeg)
6399  an=i;
6400  if (set[i].FDeg < p->FDeg)
6401  en=i;
6402  if (set[i].FDeg == p->FDeg)
6403  {
6404  number lcset,lcp;
6405  lcset = pGetCoeff(set[i].p);
6406  lcp = pGetCoeff(p->p);
6407  if(!nGreaterZero(lcset))
6408  {
6409  set[i].p=p_Neg(set[i].p,currRing);
6410  if (set[i].t_p!=NULL)
6411  pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6412  lcset=pGetCoeff(set[i].p);
6413  }
6414  if(!nGreaterZero(lcp))
6415  {
6416  p->p=p_Neg(p->p,currRing);
6417  if (p->t_p!=NULL)
6418  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6419  lcp=pGetCoeff(p->p);
6420  }
6421  if(nGreater(lcset, lcp))
6422  {
6423  an = i;
6424  }
6425  else
6426  {
6427  en = i;
6428  }
6429  }
6430  }
6431 }
6432 #endif
6433 
6434 /*2 Position for rings L: Here I am
6435 * looks up the position of polynomial p in set
6436 * e is the ecart of p
6437 * set[length] is the smallest element in set with respect
6438 * to the ordering-procedure totaldegree,pComp
6439 */
6440 inline int getIndexRng(long coeff)
6441 {
6442  if (coeff == 0) return -1;
6443  long tmp = coeff;
6444  int ind = 0;
6445  while (tmp % 2 == 0)
6446  {
6447  tmp = tmp / 2;
6448  ind++;
6449  }
6450  return ind;
6451 }
6452 
6453 int posInLrg0 (const LSet set, const int length,
6454  LObject* p,const kStrategy)
6455 /* if (nGreater(pGetCoeff(p), pGetCoeff(set[an]))) return en;
6456  if (pLmCmp(set[i],p) == cmp_int) en = i;
6457  else if (pLmCmp(set[i],p) == -cmp_int) an = i;
6458  else
6459  {
6460  if (nGreater(pGetCoeff(p), pGetCoeff(set[i]))) an = i;
6461  else en = i;
6462  }*/
6463 {
6464  if (length < 0) return 0;
6465 
6466  int o = p->GetpFDeg();
6467  int op = set[length].GetpFDeg();
6468 
6469  if ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6470  return length + 1;
6471  int i;
6472  int an = 0;
6473  int en = length;
6474  loop
6475  {
6476  if (an >= en - 1)
6477  {
6478  op = set[an].GetpFDeg();
6479  if ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6480  return en;
6481  return an;
6482  }
6483  i = (an+en) / 2;
6484  op = set[i].GetpFDeg();
6485  if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6486  an = i;
6487  else
6488  en = i;
6489  }
6490 }
6491 
6492 /*{
6493  if (length < 0) return 0;
6494 
6495  int o = p->GetpFDeg();
6496  int op = set[length].GetpFDeg();
6497 
6498  int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6499  int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6500  int inda;
6501  int indi;
6502 
6503  if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6504  return length + 1;
6505  int i;
6506  int an = 0;
6507  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6508  int en = length;
6509  loop
6510  {
6511  if (an >= en-1)
6512  {
6513  op = set[an].GetpFDeg();
6514  if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6515  return en;
6516  return an;
6517  }
6518  i = (an + en) / 2;
6519  indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6520  op = set[i].GetpFDeg();
6521  if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6522  // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6523  {
6524  an = i;
6525  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6526  }
6527  else
6528  en = i;
6529  }
6530 } */
6531 
6532 /*2
6533 * looks up the position of polynomial p in set
6534 * set[length] is the smallest element in set with respect
6535 * to the ordering-procedure totaldegree,pLength0
6536 */
6537 int posInL110 (const LSet set, const int length,
6538  LObject* p,const kStrategy)
6539 {
6540  if (length<0) return 0;
6541 
6542  int o = p->GetpFDeg();
6543  int op = set[length].GetpFDeg();
6544 
6545  if ((op > o)
6546  || ((op == o) && (set[length].length >p->length))
6547  || ((op == o) && (set[length].length <= p->length)
6548  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6549  return length+1;
6550  int i;
6551  int an = 0;
6552  int en= length;
6553  loop
6554  {
6555  if (an >= en-1)
6556  {
6557  op = set[an].GetpFDeg();
6558  if ((op > o)
6559  || ((op == o) && (set[an].length >p->length))
6560  || ((op == o) && (set[an].length <=p->length)
6561  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6562  return en;
6563  return an;
6564  }
6565  i=(an+en) / 2;
6566  op = set[i].GetpFDeg();
6567  if ((op > o)
6568  || ((op == o) && (set[i].length > p->length))
6569  || ((op == o) && (set[i].length <= p->length)
6570  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6571  an=i;
6572  else
6573  en=i;
6574  }
6575 }
6576 
6577 #ifdef HAVE_RINGS
6578 int posInL110Ring (const LSet set, const int length,
6579  LObject* p,const kStrategy)
6580 {
6581  if (length<0) return 0;
6582 
6583  int o = p->GetpFDeg();
6584  int op = set[length].GetpFDeg();
6585 
6586  if ((op > o)
6587  || ((op == o) && (set[length].length >p->length))
6588  || ((op == o) && (set[length].length <= p->length)
6589  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6590  return length+1;
6591  int i;
6592  int an = 0;
6593  int en= length;
6594  loop
6595  {
6596  if (an >= en-1)
6597  {
6598  op = set[an].GetpFDeg();
6599  if ((op > o)
6600  || ((op == o) && (set[an].length >p->length))
6601  || ((op == o) && (set[an].length <=p->length)
6602  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6603  return en;
6604  return an;
6605  }
6606  i=(an+en) / 2;
6607  op = set[i].GetpFDeg();
6608  if ((op > o)
6609  || ((op == o) && (set[i].length > p->length))
6610  || ((op == o) && (set[i].length <= p->length)
6611  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6612  an=i;
6613  else
6614  en=i;
6615  }
6616 }
6617 #endif
6618 
6619 /*2
6620 * looks up the position of polynomial p in set
6621 * e is the ecart of p
6622 * set[length] is the smallest element in set with respect
6623 * to the ordering-procedure totaldegree
6624 */
6625 int posInL13 (const LSet set, const int length,
6626  LObject* p,const kStrategy)
6627 {
6628  if (length<0) return 0;
6629 
6630  int o = p->GetpFDeg();
6631 
6632  if (set[length].GetpFDeg() > o)
6633  return length+1;
6634 
6635  int i;
6636  int an = 0;
6637  int en= length;
6638  loop
6639  {
6640  if (an >= en-1)
6641  {
6642  if (set[an].GetpFDeg() >= o)
6643  return en;
6644  return an;
6645  }
6646  i=(an+en) / 2;
6647  if (set[i].GetpFDeg() >= o)
6648  an=i;
6649  else
6650  en=i;
6651  }
6652 }
6653 
6654 /*2
6655 * looks up the position of polynomial p in set
6656 * e is the ecart of p
6657 * set[length] is the smallest element in set with respect
6658 * to the ordering-procedure maximaldegree,pComp
6659 */
6660 int posInL15 (const LSet set, const int length,
6661  LObject* p,const kStrategy)
6662 {
6663  if (length<0) return 0;
6664 
6665  int o = p->GetpFDeg() + p->ecart;
6666  int op = set[length].GetpFDeg() + set[length].ecart;
6667 
6668  if ((op > o)
6669  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6670  return length+1;
6671  int i;
6672  int an = 0;
6673  int en= length;
6674  loop
6675  {
6676  if (an >= en-1)
6677  {
6678  op = set[an].GetpFDeg() + set[an].ecart;
6679  if ((op > o)
6680  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6681  return en;
6682  return an;
6683  }
6684  i=(an+en) / 2;
6685  op = set[i].GetpFDeg() + set[i].ecart;
6686  if ((op > o)
6687  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6688  an=i;
6689  else
6690  en=i;
6691  }
6692 }
6693 
6694 #ifdef HAVE_RINGS
6695 int posInL15Ring (const LSet set, const int length,
6696  LObject* p,const kStrategy)
6697 {
6698  if (length<0) return 0;
6699 
6700  int o = p->GetpFDeg() + p->ecart;
6701  int op = set[length].GetpFDeg() + set[length].ecart;
6702 
6703  if ((op > o)
6704  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6705  return length+1;
6706  int i;
6707  int an = 0;
6708  int en= length;
6709  loop
6710  {
6711  if (an >= en-1)
6712  {
6713  op = set[an].GetpFDeg() + set[an].ecart;
6714  if ((op > o)
6715  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6716  return en;
6717  return an;
6718  }
6719  i=(an+en) / 2;
6720  op = set[i].GetpFDeg() + set[i].ecart;
6721  if ((op > o)
6722  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6723  an=i;
6724  else
6725  en=i;
6726  }
6727 }
6728 #endif
6729 
6730 /*2
6731 * looks up the position of polynomial p in set
6732 * e is the ecart of p
6733 * set[length] is the smallest element in set with respect
6734 * to the ordering-procedure totaldegree
6735 */
6736 int posInL17 (const LSet set, const int length,
6737  LObject* p,const kStrategy)
6738 {
6739  if (length<0) return 0;
6740 
6741  int o = p->GetpFDeg() + p->ecart;
6742 
6743  if ((set[length].GetpFDeg() + set[length].ecart > o)
6744  || ((set[length].GetpFDeg() + set[length].ecart == o)
6745  && (set[length].ecart > p->ecart))
6746  || ((set[length].GetpFDeg() + set[length].ecart == o)
6747  && (set[length].ecart == p->ecart)
6748  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6749  return length+1;
6750  int i;
6751  int an = 0;
6752  int en= length;
6753  loop
6754  {
6755  if (an >= en-1)
6756  {
6757  if ((set[an].GetpFDeg() + set[an].ecart > o)
6758  || ((set[an].GetpFDeg() + set[an].ecart == o)
6759  && (set[an].ecart > p->ecart))
6760  || ((set[an].GetpFDeg() + set[an].ecart == o)
6761  && (set[an].ecart == p->ecart)
6762  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6763  return en;
6764  return an;
6765  }
6766  i=(an+en) / 2;
6767  if ((set[i].GetpFDeg() + set[i].ecart > o)
6768  || ((set[i].GetpFDeg() + set[i].ecart == o)
6769  && (set[i].ecart > p->ecart))
6770  || ((set[i].GetpFDeg() +set[i].ecart == o)
6771  && (set[i].ecart == p->ecart)
6772  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6773  an=i;
6774  else
6775  en=i;
6776  }
6777 }
6778 
6779 #ifdef HAVE_RINGS
6780 int posInL17Ring (const LSet set, const int length,
6781  LObject* p,const kStrategy)
6782 {
6783  if (length<0) return 0;
6784 
6785  int o = p->GetpFDeg() + p->ecart;
6786 
6787  if ((set[length].GetpFDeg() + set[length].ecart > o)
6788  || ((set[length].GetpFDeg() + set[length].ecart == o)
6789  && (set[length].ecart > p->ecart))
6790  || ((set[length].GetpFDeg() + set[length].ecart == o)
6791  && (set[length].ecart == p->ecart)
6792  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6793  return length+1;
6794  int i;
6795  int an = 0;
6796  int en= length;
6797  loop
6798  {
6799  if (an >= en-1)
6800  {
6801  if ((set[an].GetpFDeg() + set[an].ecart > o)
6802  || ((set[an].GetpFDeg() + set[an].ecart == o)
6803  && (set[an].ecart > p->ecart))
6804  || ((set[an].GetpFDeg() + set[an].ecart == o)
6805  && (set[an].ecart == p->ecart)
6806  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6807  return en;
6808  return an;
6809  }
6810  i=(an+en) / 2;
6811  if ((set[i].GetpFDeg() + set[i].ecart > o)
6812  || ((set[i].GetpFDeg() + set[i].ecart == o)
6813  && (set[i].ecart > p->ecart))
6814  || ((set[i].GetpFDeg() +set[i].ecart == o)
6815  && (set[i].ecart == p->ecart)
6816  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6817  an=i;
6818  else
6819  en=i;
6820  }
6821 }
6822 #endif
6823 
6824 /*2
6825 * looks up the position of polynomial p in set
6826 * e is the ecart of p
6827 * set[length] is the smallest element in set with respect
6828 * to the ordering-procedure pComp
6829 */
6830 int posInL17_c (const LSet set, const int length,
6831  LObject* p,const kStrategy)
6832 {
6833  if (length<0) return 0;
6834 
6835  int cc = (-1+2*currRing->order[0]==ringorder_c);
6836  /* cc==1 for (c,..), cc==-1 for (C,..) */
6837  unsigned long c = pGetComp(p->p)*cc;
6838  int o = p->GetpFDeg() + p->ecart;
6839 
6840  if (pGetComp(set[length].p)*cc > c)
6841  return length+1;
6842  if (pGetComp(set[length].p)*cc == c)
6843  {
6844  if ((set[length].GetpFDeg() + set[length].ecart > o)
6845  || ((set[length].GetpFDeg() + set[length].ecart == o)
6846  && (set[length].ecart > p->ecart))
6847  || ((set[length].GetpFDeg() + set[length].ecart == o)
6848  && (set[length].ecart == p->ecart)
6849  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6850  return length+1;
6851  }
6852  int i;
6853  int an = 0;
6854  int en= length;
6855  loop
6856  {
6857  if (an >= en-1)
6858  {
6859  if (pGetComp(set[an].p)*cc > c)
6860  return en;
6861  if (pGetComp(set[an].p)*cc == c)
6862  {
6863  if ((set[an].GetpFDeg() + set[an].ecart > o)
6864  || ((set[an].GetpFDeg() + set[an].ecart == o)
6865  && (set[an].ecart > p->ecart))
6866  || ((set[an].GetpFDeg() + set[an].ecart == o)
6867  && (set[an].ecart == p->ecart)
6868  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6869  return en;
6870  }
6871  return an;
6872  }
6873  i=(an+en) / 2;
6874  if (pGetComp(set[i].p)*cc > c)
6875  an=i;
6876  else if (pGetComp(set[i].p)*cc == c)
6877  {
6878  if ((set[i].GetpFDeg() + set[i].ecart > o)
6879  || ((set[i].GetpFDeg() + set[i].ecart == o)
6880  && (set[i].ecart > p->ecart))
6881  || ((set[i].GetpFDeg() +set[i].ecart == o)
6882  && (set[i].ecart == p->ecart)
6883  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6884  an=i;
6885  else
6886  en=i;
6887  }
6888  else
6889  en=i;
6890  }
6891 }
6892 
6893 #ifdef HAVE_RINGS
6894 int posInL17_cRing (const LSet set, const int length,
6895  LObject* p,const kStrategy)
6896 {
6897  if (length<0) return 0;
6898 
6899  int cc = (-1+2*currRing->order[0]==ringorder_c);
6900  /* cc==1 for (c,..), cc==-1 for (C,..) */
6901  unsigned long c = pGetComp(p->p)*cc;
6902  int o = p->GetpFDeg() + p->ecart;
6903 
6904  if (pGetComp(set[length].p)*cc > c)
6905  return length+1;
6906  if (pGetComp(set[length].p)*cc == c)
6907  {
6908  if ((set[length].GetpFDeg() + set[length].ecart > o)
6909  || ((set[length].GetpFDeg() + set[length].ecart == o)
6910  && (set[length].ecart > p->ecart))
6911  || ((set[length].GetpFDeg() + set[length].ecart == o)
6912  && (set[length].ecart == p->ecart)
6913  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6914  return length+1;
6915  }
6916  int i;
6917  int an = 0;
6918  int en= length;
6919  loop
6920  {
6921  if (an >= en-1)
6922  {
6923  if (pGetComp(set[an].p)*cc > c)
6924  return en;
6925  if (pGetComp(set[an].p)*cc == c)
6926  {
6927  if ((set[an].GetpFDeg() + set[an].ecart > o)
6928  || ((set[an].GetpFDeg() + set[an].ecart == o)
6929  && (set[an].ecart > p->ecart))
6930  || ((set[an].GetpFDeg() + set[an].ecart == o)
6931  && (set[an].ecart == p->ecart)
6932  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6933  return en;
6934  }
6935  return an;
6936  }
6937  i=(an+en) / 2;
6938  if (pGetComp(set[i].p)*cc > c)
6939  an=i;
6940  else if (pGetComp(set[i].p)*cc == c)
6941  {
6942  if ((set[i].GetpFDeg() + set[i].ecart > o)
6943  || ((set[i].GetpFDeg() + set[i].ecart == o)
6944  && (set[i].ecart > p->ecart))
6945  || ((set[i].GetpFDeg() +set[i].ecart == o)
6946  && (set[i].ecart == p->ecart)
6947  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6948  an=i;
6949  else
6950  en=i;
6951  }
6952  else
6953  en=i;
6954  }
6955 }
6956 #endif
6957 
6958 /*
6959  * SYZYGY CRITERION for signature-based standard basis algorithms
6960  */
6961 BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6962 {
6963 //#if 1
6964 #ifdef DEBUGF5
6965  PrintS("syzygy criterion checks: ");
6966  pWrite(sig);
6967 #endif
6968  for (int k=0; k<strat->syzl; k++)
6969  {
6970  //printf("-%d",k);
6971 //#if 1
6972 #ifdef DEBUGF5
6973  Print("checking with: %d / %d -- \n",k,strat->syzl);
6974  pWrite(pHead(strat->syz[k]));
6975 #endif
6976  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6977  && (!rField_is_Ring(currRing) ||
6978  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6979  {
6980 //#if 1
6981 #ifdef DEBUGF5
6982  PrintS("DELETE!\n");
6983 #endif
6984  strat->nrsyzcrit++;
6985  //printf("- T -\n\n");
6986  return TRUE;
6987  }
6988  }
6989  //printf("- F -\n\n");
6990  return FALSE;
6991 }
6992 
6993 /*
6994  * SYZYGY CRITERION for signature-based standard basis algorithms
6995  */
6996 BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6997 {
6998 //#if 1
6999  if(sig == NULL)
7000  return FALSE;
7001 #ifdef DEBUGF5
7002  PrintS("--- syzygy criterion checks: ");
7003  pWrite(sig);
7004 #endif
7005  int comp = __p_GetComp(sig, currRing);
7006  int min, max;
7007  if (comp<=1)
7008  return FALSE;
7009  else
7010  {
7011  min = strat->syzIdx[comp-2];
7012  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
7013  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
7014  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
7015  if (comp == strat->currIdx)
7016  {
7017  max = strat->syzl;
7018  }
7019  else
7020  {
7021  max = strat->syzIdx[comp-1];
7022  }
7023  for (int k=min; k<max; k++)
7024  {
7025 #ifdef F5DEBUG
7026  Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
7027  Print("checking with: %d -- ",k);
7028  pWrite(pHead(strat->syz[k]));
7029 #endif
7030  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7031  && (!rField_is_Ring(currRing) ||
7032  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7033  {
7034  strat->nrsyzcrit++;
7035  return TRUE;
7036  }
7037  }
7038  return FALSE;
7039  }
7040 }
7041 
7042 /*
7043  * REWRITTEN CRITERION for signature-based standard basis algorithms
7044  */
7045 BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
7046 {
7047  //printf("Faugere Rewritten Criterion\n");
7049  return FALSE;
7050 //#if 1
7051 #ifdef DEBUGF5
7052  PrintS("rewritten criterion checks: ");
7053  pWrite(sig);
7054 #endif
7055  for(int k = strat->sl; k>=start; k--)
7056  {
7057 //#if 1
7058 #ifdef DEBUGF5
7059  PrintS("checking with: ");
7060  pWrite(strat->sig[k]);
7061  pWrite(pHead(strat->S[k]));
7062 #endif
7063  if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
7064  {
7065 //#if 1
7066 #ifdef DEBUGF5
7067  PrintS("DELETE!\n");
7068 #endif
7069  strat->nrrewcrit++;
7070  return TRUE;
7071  }
7072  //k--;
7073  }
7074 #ifdef DEBUGF5
7075  PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
7076  for(int kk = 0; kk<strat->sl+1; kk++)
7077  {
7078  pWrite(pHead(strat->S[kk]));
7079  }
7080  PrintS("------------------------------\n");
7081 #endif
7082  return FALSE;
7083 }
7084 
7085 /*
7086  * REWRITTEN CRITERION for signature-based standard basis algorithms
7087  ***************************************************************************
7088  * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
7089  ***************************************************************************
7090  */
7091 
7092 // real implementation of arri's rewritten criterion, only called once in
7093 // kstd2.cc, right before starting reduction
7094 // IDEA: Arri says that it is enough to consider 1 polynomial for each unique
7095 // signature appearing during the computations. Thus we first of all go
7096 // through strat->L and delete all other pairs of the same signature,
7097 // keeping only the one with least possible leading monomial. After this
7098 // we check if we really need to compute this critical pair at all: There
7099 // can be elements already in strat->S whose signatures divide the
7100 // signature of the critical pair in question and whose multiplied
7101 // leading monomials are smaller than the leading monomial of the
7102 // critical pair. In this situation we can discard the critical pair
7103 // completely.
7104 BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
7105 {
7107  return FALSE;
7108  poly p1 = pOne();
7109  poly p2 = pOne();
7110  for (int ii=strat->sl; ii>start; ii--)
7111  {
7112  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
7113  {
7114  p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
7115  p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
7116  if (!(pLmCmp(p1,p2) == 1))
7117  {
7118  pDelete(&p1);
7119  pDelete(&p2);
7120  return TRUE;
7121  }
7122  }
7123  }
7124  pDelete(&p1);
7125  pDelete(&p2);
7126  return FALSE;
7127 }
7128 
7129 BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
7130 {
7131  //Over Rings, there are still some changes to do: considering coeffs
7133  return FALSE;
7134  int found = -1;
7135  for (int i=strat->Bl; i>-1; i--) {
7136  if (pLmEqual(strat->B[i].sig,sig))
7137  {
7138  found = i;
7139  break;
7140  }
7141  }
7142  if (found != -1)
7143  {
7144  if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
7145  {
7146  deleteInL(strat->B,&strat->Bl,found,strat);
7147  }
7148  else
7149  {
7150  return TRUE;
7151  }
7152  }
7153  poly p1 = pOne();
7154  poly p2 = pOne();
7155  for (int ii=strat->sl; ii>-1; ii--)
7156  {
7157  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
7158  {
7159  p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
7160  p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
7161  if (!(pLmCmp(p1,p2) == 1))
7162  {
7163  pDelete(&p1);
7164  pDelete(&p2);
7165  return TRUE;
7166  }
7167  }
7168  }
7169  pDelete(&p1);
7170  pDelete(&p2);
7171  return FALSE;
7172 }
7173 
7174 /***************************************************************
7175  *
7176  * Tail reductions
7177  *
7178  ***************************************************************/
7179 TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
7180 {
7181  int j = 0;
7182  const unsigned long not_sev = ~L->sev;
7183  const unsigned long* sev = strat->sevS;
7184  poly p;
7185  ring r;
7186  L->GetLm(p, r);
7187 
7188  assume(~not_sev == p_GetShortExpVector(p, r));
7189 
7190  if (r == currRing)
7191  {
7192  if(!rField_is_Ring(r))
7193  {
7194  loop
7195  {
7196  if (j > end_pos) return NULL;
7197  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7198  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7199  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7200  {
7201  break;
7202  }
7203  #else
7204  if (!(sev[j] & not_sev) &&
7205  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7206  p_LmDivisibleBy(strat->S[j], p, r))
7207  {
7208  break;
7209  }
7210  #endif
7211  j++;
7212  }
7213  }
7214  #ifdef HAVE_RINGS
7215  else
7216  {
7217  loop
7218  {
7219  if (j > end_pos) return NULL;
7220  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7221  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7222  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7223  {
7224  break;
7225  }
7226  #else
7227  if (!(sev[j] & not_sev) &&
7228  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7229  p_LmDivisibleBy(strat->S[j], p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7230  {
7231  break;
7232  }
7233  #endif
7234  j++;
7235  }
7236  }
7237  #endif
7238  // if called from NF, T objects do not exist:
7239  if (strat->tl < 0 || strat->S_2_R[j] == -1)
7240  {
7241  T->Set(strat->S[j], r, strat->tailRing);
7242  assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
7243  return T;
7244  }
7245  else
7246  {
7247 ///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
7248 ///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
7249 // assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
7250  return strat->S_2_T(j);
7251  }
7252  }
7253  else
7254  {
7255  TObject* t;
7256  if(!rField_is_Ring(r))
7257  {
7258  loop
7259  {
7260  if (j > end_pos) return NULL;
7261  assume(strat->S_2_R[j] != -1);
7262  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7263  t = strat->S_2_T(j);
7264  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7265  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7266  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7267  {
7268  t->pLength=pLength(t->t_p);
7269  return t;
7270  }
7271  #else
7272  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7273  {
7274  t = strat->S_2_T(j);
7275  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7276  if (p_LmDivisibleBy(t->t_p, p, r))
7277  {
7278  t->pLength=pLength(t->t_p);
7279  return t;
7280  }
7281  }
7282  #endif
7283  j++;
7284  }
7285  }
7286  #ifdef HAVE_RINGS
7287  else
7288  {
7289  loop
7290  {
7291  if (j > end_pos) return NULL;
7292  assume(strat->S_2_R[j] != -1);
7293  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7294  t = strat->S_2_T(j);
7295  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7296  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7297  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7298  {
7299  t->pLength=pLength(t->t_p);
7300  return t;
7301  }
7302  #else
7303  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7304  {
7305  t = strat->S_2_T(j);
7306  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7307  if (p_LmDivisibleBy(t->t_p, p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7308  {
7309  t->pLength=pLength(t->t_p);
7310  return t;
7311  }
7312  }
7313  #endif
7314  j++;
7315  }
7316  }
7317  #endif
7318  }
7319 }
7320 
7321 poly redtail (LObject* L, int end_pos, kStrategy strat)
7322 {
7323  poly h, hn;
7324  strat->redTailChange=FALSE;
7325 
7326  L->GetP();
7327  poly p = L->p;
7328  if (strat->noTailReduction || pNext(p) == NULL)
7329  return p;
7330 
7331  LObject Ln(strat->tailRing);
7332  TObject* With;
7333  // placeholder in case strat->tl < 0
7334  TObject With_s(strat->tailRing);
7335  h = p;
7336  hn = pNext(h);
7337  long op = strat->tailRing->pFDeg(hn, strat->tailRing);
7338  long e;
7339  int l;
7340  BOOLEAN save_HE=strat->kHEdgeFound;
7341  strat->kHEdgeFound |=
7342  ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
7343 
7344  while(hn != NULL)
7345  {
7346  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7347  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7348  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7349  loop
7350  {
7351  Ln.Set(hn, strat->tailRing);
7352  Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
7353  if (strat->kHEdgeFound)
7354  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7355  else
7356  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
7357  if (With == NULL) break;
7358  With->length=0;
7359  With->pLength=0;
7360  strat->redTailChange=TRUE;
7361  if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
7362  {
7363  // reducing the tail would violate the exp bound
7364  if (kStratChangeTailRing(strat, L))
7365  {
7366  strat->kHEdgeFound = save_HE;
7367  return redtail(L, end_pos, strat);
7368  }
7369  else
7370  return NULL;
7371  }
7372  hn = pNext(h);
7373  if (hn == NULL) goto all_done;
7374  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7375  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7376  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7377  }
7378  h = hn;
7379  hn = pNext(h);
7380  }
7381 
7382  all_done:
7383  if (strat->redTailChange)
7384  {
7385  L->pLength = 0;
7386  }
7387  strat->kHEdgeFound = save_HE;
7388  return p;
7389 }
7390 
7391 poly redtail (poly p, int end_pos, kStrategy strat)
7392 {
7393  LObject L(p, currRing);
7394  return redtail(&L, end_pos, strat);
7395 }
7396 
7397 poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
7398 {
7399 #define REDTAIL_CANONICALIZE 100
7400  strat->redTailChange=FALSE;
7401  if (strat->noTailReduction) return L->GetLmCurrRing();
7402  poly h, p;
7403  p = h = L->GetLmTailRing();
7404  if ((h==NULL) || (pNext(h)==NULL))
7405  return L->GetLmCurrRing();
7406 
7407  TObject* With;
7408  // placeholder in case strat->tl < 0
7409  TObject With_s(strat->tailRing);
7410 
7411  LObject Ln(pNext(h), strat->tailRing);
7412  Ln.GetpLength();
7413 
7414  pNext(h) = NULL;
7415  if (L->p != NULL)
7416  {
7417  pNext(L->p) = NULL;
7418  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7419  }
7420  L->pLength = 1;
7421 
7422  Ln.PrepareRed(strat->use_buckets);
7423 
7424  int cnt=REDTAIL_CANONICALIZE;
7425  while(!Ln.IsNull())
7426  {
7427  loop
7428  {
7429  if (TEST_OPT_IDLIFT)
7430  {
7431  if (Ln.p!=NULL)
7432  {
7433  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7434  }
7435  else
7436  {
7437  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7438  }
7439  }
7440  Ln.SetShortExpVector();
7441  if (withT)
7442  {
7443  int j;
7444  j = kFindDivisibleByInT(strat, &Ln);
7445  if (j < 0) break;
7446  With = &(strat->T[j]);
7447  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7448  }
7449  else
7450  {
7451  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7452  if (With == NULL) break;
7453  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7454  }
7455  cnt--;
7456  if (cnt==0)
7457  {
7459  /*poly tmp=*/Ln.CanonicalizeP();
7460  if (normalize)
7461  {
7462  Ln.Normalize();
7463  //pNormalize(tmp);
7464  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7465  }
7466  }
7467  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7468  {
7469  With->pNorm();
7470  }
7471  strat->redTailChange=TRUE;
7472  if (ksReducePolyTail(L, With, &Ln))
7473  {
7474  // reducing the tail would violate the exp bound
7475  // set a flag and hope for a retry (in bba)
7476  strat->completeReduce_retry=TRUE;
7477  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7478  do
7479  {
7480  pNext(h) = Ln.LmExtractAndIter();
7481  pIter(h);
7482  L->pLength++;
7483  } while (!Ln.IsNull());
7484  goto all_done;
7485  }
7486  if (Ln.IsNull()) goto all_done;
7487  if (! withT) With_s.Init(currRing);
7488  }
7489  pNext(h) = Ln.LmExtractAndIter();
7490  pIter(h);
7491  pNormalize(h);
7492  L->pLength++;
7493  }
7494 
7495  all_done:
7496  Ln.Delete();
7497  if (L->p != NULL) pNext(L->p) = pNext(p);
7498 
7499  if (strat->redTailChange)
7500  {
7501  L->length = 0;
7502  L->pLength = 0;
7503  }
7504 
7505  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7506  //L->Normalize(); // HANNES: should have a test
7507  kTest_L(L);
7508  return L->GetLmCurrRing();
7509 }
7510 
7511 poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7512 {
7513  strat->redTailChange=FALSE;
7514  if (strat->noTailReduction) return L->GetLmCurrRing();
7515  poly h, p;
7516  p = h = L->GetLmTailRing();
7517  if ((h==NULL) || (pNext(h)==NULL))
7518  return L->GetLmCurrRing();
7519 
7520  TObject* With;
7521  // placeholder in case strat->tl < 0
7522  TObject With_s(strat->tailRing);
7523 
7524  LObject Ln(pNext(h), strat->tailRing);
7525  Ln.pLength = L->GetpLength() - 1;
7526 
7527  pNext(h) = NULL;
7528  if (L->p != NULL) pNext(L->p) = NULL;
7529  L->pLength = 1;
7530 
7531  Ln.PrepareRed(strat->use_buckets);
7532 
7533  int cnt=REDTAIL_CANONICALIZE;
7534  while(!Ln.IsNull())
7535  {
7536  loop
7537  {
7538  if (TEST_OPT_IDLIFT)
7539  {
7540  if (Ln.p!=NULL)
7541  {
7542  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7543  }
7544  else
7545  {
7546  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7547  }
7548  }
7549  Ln.SetShortExpVector();
7550  if (withT)
7551  {
7552  int j;
7553  j = kFindDivisibleByInT(strat, &Ln);
7554  if (j < 0) break;
7555  With = &(strat->T[j]);
7556  }
7557  else
7558  {
7559  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7560  if (With == NULL) break;
7561  }
7562  cnt--;
7563  if (cnt==0)
7564  {
7566  /*poly tmp=*/Ln.CanonicalizeP();
7567  if (normalize)
7568  {
7569  Ln.Normalize();
7570  //pNormalize(tmp);
7571  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7572  }
7573  }
7574  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7575  {
7576  With->pNorm();
7577  }
7578  strat->redTailChange=TRUE;
7579  if (ksReducePolyTail(L, With, &Ln))
7580  {
7581  // reducing the tail would violate the exp bound
7582  // set a flag and hope for a retry (in bba)
7583  strat->completeReduce_retry=TRUE;
7584  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7585  do
7586  {
7587  pNext(h) = Ln.LmExtractAndIter();
7588  pIter(h);
7589  L->pLength++;
7590  } while (!Ln.IsNull());
7591  goto all_done;
7592  }
7593  if(!Ln.IsNull())
7594  {
7595  Ln.GetP();
7596  Ln.p = pJet(Ln.p,bound);
7597  }
7598  if (Ln.IsNull())
7599  {
7600  goto all_done;
7601  }
7602  if (! withT) With_s.Init(currRing);
7603  }
7604  pNext(h) = Ln.LmExtractAndIter();
7605  pIter(h);
7606  pNormalize(h);
7607  L->pLength++;
7608  }
7609 
7610  all_done:
7611  Ln.Delete();
7612  if (L->p != NULL) pNext(L->p) = pNext(p);
7613 
7614  if (strat->redTailChange)
7615  {
7616  L->length = 0;
7617  L->pLength = 0;
7618  }
7619 
7620  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7621  //L->Normalize(); // HANNES: should have a test
7622  kTest_L(L);
7623  return L->GetLmCurrRing();
7624 }
7625 
7626 #ifdef HAVE_RINGS
7627 poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7628 // normalize=FALSE, withT=FALSE, coeff=Z
7629 {
7630  strat->redTailChange=FALSE;
7631  if (strat->noTailReduction) return L->GetLmCurrRing();
7632  poly h, p;
7633  p = h = L->GetLmTailRing();
7634  if ((h==NULL) || (pNext(h)==NULL))
7635  return L->GetLmCurrRing();
7636 
7637  TObject* With;
7638  // placeholder in case strat->tl < 0
7639  TObject With_s(strat->tailRing);
7640 
7641  LObject Ln(pNext(h), strat->tailRing);
7642  Ln.pLength = L->GetpLength() - 1;
7643 
7644  pNext(h) = NULL;
7645  if (L->p != NULL) pNext(L->p) = NULL;
7646  L->pLength = 1;
7647 
7648  Ln.PrepareRed(strat->use_buckets);
7649 
7650  int cnt=REDTAIL_CANONICALIZE;
7651  while(!Ln.IsNull())
7652  {
7653  loop
7654  {
7655  Ln.SetShortExpVector();
7656  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7657  if (With == NULL) break;
7658  cnt--;
7659  if (cnt==0)
7660  {
7662  /*poly tmp=*/Ln.CanonicalizeP();
7663  }
7664  // we are in Z, do not call pNorm
7665  strat->redTailChange=TRUE;
7666  // test divisibility of coefs:
7667  poly p_Ln=Ln.GetLmCurrRing();
7668  poly p_With=With->GetLmCurrRing();
7669  number z=n_IntMod(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf);
7670  if (!nIsZero(z))
7671  {
7672  // subtract z*Ln, add z.Ln to L
7673  poly m=pHead(p_Ln);
7674  pSetCoeff(m,z);
7675  poly mm=pHead(m);
7676  pNext(h) = m;
7677  pIter(h);
7678  L->pLength++;
7679  mm=pNeg(mm);
7680  if (Ln.bucket!=NULL)
7681  {
7682  int dummy=1;
7683  kBucket_Add_q(Ln.bucket,mm,&dummy);
7684  }
7685  else
7686  {
7687  if ((Ln.t_p!=NULL)&&(Ln.p==NULL))
7688  Ln.GetP();
7689  if (Ln.p!=NULL)
7690  {
7691  Ln.p=pAdd(Ln.p,mm);
7692  if (Ln.t_p!=NULL)
7693  {
7694  pNext(Ln.t_p)=NULL;
7695  p_LmDelete(Ln.t_p,strat->tailRing);
7696  }
7697  }
7698  }
7699  }
7700  else
7701  nDelete(&z);
7702 
7703  if (ksReducePolyTail(L, With, &Ln))
7704  {
7705  // reducing the tail would violate the exp bound
7706  // set a flag and hope for a retry (in bba)
7707  strat->completeReduce_retry=TRUE;
7708  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7709  do
7710  {
7711  pNext(h) = Ln.LmExtractAndIter();
7712  pIter(h);
7713  L->pLength++;
7714  } while (!Ln.IsNull());
7715  goto all_done;
7716  }
7717  if (Ln.IsNull()) goto all_done;
7718  With_s.Init(currRing);
7719  }
7720  pNext(h) = Ln.LmExtractAndIter();
7721  pIter(h);
7722  pNormalize(h);
7723  L->pLength++;
7724  }
7725 
7726  all_done:
7727  Ln.Delete();
7728  if (L->p != NULL) pNext(L->p) = pNext(p);
7729 
7730  if (strat->redTailChange)
7731  {
7732  L->length = 0;
7733  }
7734 
7735  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7736  //L->Normalize(); // HANNES: should have a test
7737  kTest_L(L);
7738  return L->GetLmCurrRing();
7739 }
7740 #endif
7741 
7742 /*2
7743 *checks the change degree and write progress report
7744 */
7745 void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7746 {
7747  if (i != *olddeg)
7748  {
7749  Print("%d",i);
7750  *olddeg = i;
7751  }
7752  if (TEST_OPT_OLDSTD)
7753  {
7754  if (strat->Ll != *reduc)
7755  {
7756  if (strat->Ll != *reduc-1)
7757  Print("(%d)",strat->Ll+1);
7758  else
7759  PrintS("-");
7760  *reduc = strat->Ll;
7761  }
7762  else
7763  PrintS(".");
7764  mflush();
7765  }
7766  else
7767  {
7768  if (red_result == 0)
7769  PrintS("-");
7770  else if (red_result < 0)
7771  PrintS(".");
7772  if ((red_result > 0) || ((strat->Ll % 100)==99))
7773  {
7774  if (strat->Ll != *reduc && strat->Ll > 0)
7775  {
7776  Print("(%d)",strat->Ll+1);
7777  *reduc = strat->Ll;
7778  }
7779  }
7780  }
7781 }
7782 
7783 /*2
7784 *statistics
7785 */
7786 void messageStat (int hilbcount,kStrategy strat)
7787 {
7788  //PrintS("\nUsage/Allocation of temporary storage:\n");
7789  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7790  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7791  Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7792  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7793  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7794  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7795  /*mflush();*/
7796 }
7797 
7798 void messageStatSBA (int hilbcount,kStrategy strat)
7799 {
7800  //PrintS("\nUsage/Allocation of temporary storage:\n");
7801  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7802  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7803  Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7804  //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7805  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7806  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7807  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7808  /*mflush();*/
7809 }
7810 
7811 #ifdef KDEBUG
7812 /*2
7813 *debugging output: all internal sets, if changed
7814 *for testing purpuse only/has to be changed for later use
7815 */
7817 {
7818  int i;
7819  if (strat->news)
7820  {
7821  PrintS("set S");
7822  for (i=0; i<=strat->sl; i++)
7823  {
7824  Print("\n %d:",i);
7825  p_wrp(strat->S[i], currRing, strat->tailRing);
7826  }
7827  strat->news = FALSE;
7828  }
7829  if (strat->newt)
7830  {
7831  PrintS("\nset T");
7832  for (i=0; i<=strat->tl; i++)
7833  {
7834  Print("\n %d:",i);
7835  strat->T[i].wrp();
7836  if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7837  Print(" o:%ld e:%d l:%d",
7838  strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7839  }
7840  strat->newt = FALSE;
7841  }
7842  PrintS("\nset L");
7843  for (i=strat->Ll; i>=0; i--)
7844  {
7845  Print("\n%d:",i);
7846  p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7847  PrintS(" ");
7848  p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7849  PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7850  PrintS("\n p : ");
7851  strat->L[i].wrp();
7852  Print(" o:%ld e:%d l:%d",
7853  strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7854  }
7855  PrintLn();
7856 }
7857 
7858 #endif
7859 
7860 
7861 /*2
7862 *construct the set s from F
7863 */
7864 void initS (ideal F, ideal Q, kStrategy strat)
7865 {
7866  int i,pos;
7867 
7868  if (Q!=NULL) i=((IDELEMS(F)+IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7869  else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7870  strat->ecartS=initec(i);
7871  strat->sevS=initsevS(i);
7872  strat->S_2_R=initS_2_R(i);
7873  strat->fromQ=NULL;
7874  strat->Shdl=idInit(i,F->rank);
7875  strat->S=strat->Shdl->m;
7876  /*- put polys into S -*/
7877  if (Q!=NULL)
7878  {
7879  strat->fromQ=initec(i);
7880  memset(strat->fromQ,0,i*sizeof(int));
7881  for (i=0; i<IDELEMS(Q); i++)
7882  {
7883  if (Q->m[i]!=NULL)
7884  {
7885  LObject h;
7886  h.p = pCopy(Q->m[i]);
7888  {
7889  h.pCleardenom(); // also does remove Content
7890  }
7891  else
7892  {
7893  h.pNorm();
7894  }
7896  {
7897  deleteHC(&h, strat);
7898  }
7899  if (h.p!=NULL)
7900  {
7901  strat->initEcart(&h);
7902  if (strat->sl==-1)
7903  pos =0;
7904  else
7905  {
7906  pos = posInS(strat,strat->sl,h.p,h.ecart);
7907  }
7908  h.sev = pGetShortExpVector(h.p);
7909  strat->enterS(h,pos,strat,-1);
7910  strat->fromQ[pos]=1;
7911  }
7912  }
7913  }
7914  }
7915  for (i=0; i<IDELEMS(F); i++)
7916  {
7917  if (F->m[i]!=NULL)
7918  {
7919  LObject h;
7920  h.p = pCopy(F->m[i]);
7922  {
7923  cancelunit(&h); /*- tries to cancel a unit -*/
7924  deleteHC(&h, strat);
7925  }
7926  if (h.p!=NULL)
7927  // do not rely on the input being a SB!
7928  {
7930  {
7931  h.pCleardenom(); // also does remove Content
7932  }
7933  else
7934  {
7935  h.pNorm();
7936  }
7937  strat->initEcart(&h);
7938  if (strat->sl==-1)
7939  pos =0;
7940  else
7941  pos = posInS(strat,strat->sl,h.p,h.ecart);
7942  h.sev = pGetShortExpVector(h.p);
7943  strat->enterS(h,pos,strat,-1);
7944  }
7945  }
7946  }
7947  /*- test, if a unit is in F -*/
7948  if ((strat->sl>=0)
7949 #ifdef HAVE_RINGS
7950  && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7951 #endif
7952  && pIsConstant(strat->S[0]))
7953  {
7954  while (strat->sl>0) deleteInS(strat->sl,strat);
7955  }
7956 }
7957 
7958 void initSL (ideal F, ideal Q,kStrategy strat)
7959 {
7960  int i,pos;
7961 
7962  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7963  else i=setmaxT;
7964  strat->ecartS=initec(i);
7965  strat->sevS=initsevS(i);
7966  strat->S_2_R=initS_2_R(i);
7967  strat->fromQ=NULL;
7968  strat->Shdl=idInit(i,F->rank);
7969  strat->S=strat->Shdl->m;
7970  /*- put polys into S -*/
7971  if (Q!=NULL)
7972  {
7973  strat->fromQ=initec(i);
7974  memset(strat->fromQ,0,i*sizeof(int));
7975  for (i=0; i<IDELEMS(Q); i++)
7976  {
7977  if (Q->m[i]!=NULL)
7978  {
7979  LObject h;
7980  h.p = pCopy(Q->m[i]);
7982  {
7983  deleteHC(&h,strat);
7984  }
7986  {
7987  h.pCleardenom(); // also does remove Content
7988  }
7989  else
7990  {
7991  h.pNorm();
7992  }
7993  if (h.p!=NULL)
7994  {
7995  strat->initEcart(&h);
7996  if (strat->sl==-1)
7997  pos =0;
7998  else
7999  {
8000  pos = posInS(strat,strat->sl,h.p,h.ecart);
8001  }
8002  h.sev = pGetShortExpVector(h.p);
8003  strat->enterS(h,pos,strat,-1);
8004  strat->fromQ[pos]=1;
8005  }
8006  }
8007  }
8008  }
8009  for (i=0; i<IDELEMS(F); i++)
8010  {
8011  if (F->m[i]!=NULL)
8012  {
8013  LObject h;
8014  h.p = pCopy(F->m[i]);
8015  if (h.p!=NULL)
8016  {
8018  {
8019  cancelunit(&h); /*- tries to cancel a unit -*/
8020  deleteHC(&h, strat);
8021  }
8022  if (h.p!=NULL)
8023  {
8025  {
8026  h.pCleardenom(); // also does remove Content
8027  }
8028  else
8029  {
8030  h.pNorm();
8031  }
8032  strat->initEcart(&h);
8033  if (strat->Ll==-1)
8034  pos =0;
8035  else
8036  pos = strat->posInL(strat->L,strat->Ll,&h,strat);
8037  h.sev = pGetShortExpVector(h.p);
8038  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8039  }
8040  }
8041  }
8042  }
8043  /*- test, if a unit is in F -*/
8044 
8045  if ((strat->Ll>=0)
8046 #ifdef HAVE_RINGS
8047  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8048 #endif
8049  && pIsConstant(strat->L[strat->Ll].p))
8050  {
8051  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8052  }
8053 }
8054 
8055 void initSLSba (ideal F, ideal Q,kStrategy strat)
8056 {
8057  int i,pos;
8058  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8059  else i=setmaxT;
8060  strat->ecartS = initec(i);
8061  strat->sevS = initsevS(i);
8062  strat->sevSig = initsevS(i);
8063  strat->S_2_R = initS_2_R(i);
8064  strat->fromQ = NULL;
8065  strat->Shdl = idInit(i,F->rank);
8066  strat->S = strat->Shdl->m;
8067  strat->sig = (poly *)omAlloc0(i*sizeof(poly));
8068  if (strat->sbaOrder != 1)
8069  {
8070  strat->syz = (poly *)omAlloc0(i*sizeof(poly));
8071  strat->sevSyz = initsevS(i);
8072  strat->syzmax = i;
8073  strat->syzl = 0;
8074  }
8075  /*- put polys into S -*/
8076  if (Q!=NULL)
8077  {
8078  strat->fromQ=initec(i);
8079  memset(strat->fromQ,0,i*sizeof(int));
8080  for (i=0; i<IDELEMS(Q); i++)
8081  {
8082  if (Q->m[i]!=NULL)
8083  {
8084  LObject h;
8085  h.p = pCopy(Q->m[i]);
8087  {
8088  deleteHC(&h,strat);
8089  }
8091  {
8092  h.pCleardenom(); // also does remove Content
8093  }
8094  else
8095  {
8096  h.pNorm();
8097  }
8098  if (h.p!=NULL)
8099  {
8100  strat->initEcart(&h);
8101  if (strat->sl==-1)
8102  pos =0;
8103  else
8104  {
8105  pos = posInS(strat,strat->sl,h.p,h.ecart);
8106  }
8107  h.sev = pGetShortExpVector(h.p);
8108  strat->enterS(h,pos,strat,-1);
8109  strat->fromQ[pos]=1;
8110  }
8111  }
8112  }
8113  }
8114  for (i=0; i<IDELEMS(F); i++)
8115  {
8116  if (F->m[i]!=NULL)
8117  {
8118  LObject h;
8119  h.p = pCopy(F->m[i]);
8120  h.sig = pOne();
8121  //h.sig = pInit();
8122  //p_SetCoeff(h.sig,nInit(1),currRing);
8123  p_SetComp(h.sig,i+1,currRing);
8124  // if we are working with the Schreyer order we generate it
8125  // by multiplying the initial signatures with the leading monomial
8126  // of the corresponding initial polynomials generating the ideal
8127  // => we can keep the underlying monomial order and get a Schreyer
8128  // order without any bigger overhead
8129  if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
8130  {
8131  p_ExpVectorAdd (h.sig,F->m[i],currRing);
8132  }
8133  h.sevSig = pGetShortExpVector(h.sig);
8134 #ifdef DEBUGF5
8135  pWrite(h.p);
8136  pWrite(h.sig);
8137 #endif
8138  if (h.p!=NULL)
8139  {
8141  {
8142  cancelunit(&h); /*- tries to cancel a unit -*/
8143  deleteHC(&h, strat);
8144  }
8145  if (h.p!=NULL)
8146  {
8148  {
8149  h.pCleardenom(); // also does remove Content
8150  }
8151  else
8152  {
8153  h.pNorm();
8154  }
8155  strat->initEcart(&h);
8156  if (strat->Ll==-1)
8157  pos =0;
8158  else
8159  pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
8160  h.sev = pGetShortExpVector(h.p);
8161  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8162  }
8163  }
8164  /*
8165  if (strat->sbaOrder != 1)
8166  {
8167  for(j=0;j<i;j++)
8168  {
8169  strat->syz[ctr] = pCopy(F->m[j]);
8170  p_SetCompP(strat->syz[ctr],i+1,currRing);
8171  // add LM(F->m[i]) to the signature to get a Schreyer order
8172  // without changing the underlying polynomial ring at all
8173  p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
8174  // since p_Add_q() destroys all input
8175  // data we need to recreate help
8176  // each time
8177  poly help = pCopy(F->m[i]);
8178  p_SetCompP(help,j+1,currRing);
8179  pWrite(strat->syz[ctr]);
8180  pWrite(help);
8181  printf("%d\n",pLmCmp(strat->syz[ctr],help));
8182  strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
8183  printf("%d. SYZ ",ctr);
8184  pWrite(strat->syz[ctr]);
8185  strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
8186  ctr++;
8187  }
8188  strat->syzl = ps;
8189  }
8190  */
8191  }
8192  }
8193  /*- test, if a unit is in F -*/
8194 
8195  if ((strat->Ll>=0)
8196 #ifdef HAVE_RINGS
8197  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8198 #endif
8199  && pIsConstant(strat->L[strat->Ll].p))
8200  {
8201  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8202  }
8203 }
8204 
8206 {
8207  if( strat->S[0] )
8208  {
8209  if( strat->S[1] && !rField_is_Ring(currRing))
8210  {
8211  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
8212  omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
8213  omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
8214  }
8215  int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
8216  /************************************************************
8217  * computing the length of the syzygy array needed
8218  ***********************************************************/
8219  for(i=1; i<=strat->sl; i++)
8220  {
8221  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8222  {
8223  ps += i;
8224  }
8225  }
8226  ps += strat->sl+1;
8227  //comp = pGetComp (strat->P.sig);
8228  comp = strat->currIdx;
8229  strat->syzIdx = initec(comp);
8230  strat->sevSyz = initsevS(ps);
8231  strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8232  strat->syzmax = ps;
8233  strat->syzl = 0;
8234  strat->syzidxmax = comp;
8235 #if defined(DEBUGF5) || defined(DEBUGF51)
8236  PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8237 #endif
8238  i = 1;
8239  j = 0;
8240  /************************************************************
8241  * generating the leading terms of the principal syzygies
8242  ***********************************************************/
8243  while (i <= strat->sl)
8244  {
8245  /**********************************************************
8246  * principal syzygies start with component index 2
8247  * the array syzIdx starts with index 0
8248  * => the rules for a signature with component comp start
8249  * at strat->syz[strat->syzIdx[comp-2]] !
8250  *********************************************************/
8251  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8252  {
8253  comp = pGetComp(strat->sig[i]);
8254  comp_old = pGetComp(strat->sig[i-1]);
8255  diff = comp - comp_old - 1;
8256  // diff should be zero, but sometimes also the initial generating
8257  // elements of the input ideal reduce to zero. then there is an
8258  // index-gap between the signatures. for these inbetween signatures we
8259  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8260  // in the following.
8261  // doing this, we keep the relation "j = comp - 2" alive, which makes
8262  // jumps way easier when checking criteria
8263  while (diff>0)
8264  {
8265  strat->syzIdx[j] = 0;
8266  diff--;
8267  j++;
8268  }
8269  strat->syzIdx[j] = ctr;
8270  j++;
8271  LObject Q;
8272  int pos;
8273  for (k = 0; k<i; k++)
8274  {
8275  Q.sig = pOne();
8277  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8278  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8279  p_SetCompP (Q.sig, comp, currRing);
8280  poly q = p_One(currRing);
8283  p_ExpVectorCopy(q,strat->S[i],currRing);
8284  q = p_Neg (q, currRing);
8285  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8286  Q.sig = p_Add_q (Q.sig, q, currRing);
8287  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8288  pos = posInSyz(strat, Q.sig);
8289  enterSyz(Q, strat, pos);
8290  ctr++;
8291  }
8292  }
8293  i++;
8294  }
8295  /**************************************************************
8296  * add syzygies for upcoming first element of new iteration step
8297  **************************************************************/
8298  comp = strat->currIdx;
8299  comp_old = pGetComp(strat->sig[i-1]);
8300  diff = comp - comp_old - 1;
8301  // diff should be zero, but sometimes also the initial generating
8302  // elements of the input ideal reduce to zero. then there is an
8303  // index-gap between the signatures. for these inbetween signatures we
8304  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8305  // in the following.
8306  // doing this, we keep the relation "j = comp - 2" alive, which makes
8307  // jumps way easier when checking criteria
8308  while (diff>0)
8309  {
8310  strat->syzIdx[j] = 0;
8311  diff--;
8312  j++;
8313  }
8314  strat->syzIdx[j] = ctr;
8315  LObject Q;
8316  int pos;
8317  for (k = 0; k<strat->sl+1; k++)
8318  {
8319  Q.sig = pOne();
8321  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8322  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8323  p_SetCompP (Q.sig, comp, currRing);
8324  poly q = p_One(currRing);
8326  p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8327  p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8328  q = p_Neg (q, currRing);
8329  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8330  Q.sig = p_Add_q (Q.sig, q, currRing);
8331  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8332  pos = posInSyz(strat, Q.sig);
8333  enterSyz(Q, strat, pos);
8334  ctr++;
8335  }
8336 //#if 1
8337 #ifdef DEBUGF5
8338  PrintS("Principal syzygies:\n");
8339  Print("syzl %d\n",strat->syzl);
8340  Print("syzmax %d\n",strat->syzmax);
8341  Print("ps %d\n",ps);
8342  PrintS("--------------------------------\n");
8343  for(i=0;i<=strat->syzl-1;i++)
8344  {
8345  Print("%d - ",i);
8346  pWrite(strat->syz[i]);
8347  }
8348  for(i=0;i<strat->currIdx;i++)
8349  {
8350  Print("%d - %d\n",i,strat->syzIdx[i]);
8351  }
8352  PrintS("--------------------------------\n");
8353 #endif
8354  }
8355 }
8356 
8357 /*2
8358 *construct the set s from F and {P}
8359 */
8360 void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8361 {
8362  int i,pos;
8363 
8364  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8365  else i=setmaxT;
8366  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8367  strat->ecartS=initec(i);
8368  strat->sevS=initsevS(i);
8369  strat->S_2_R=initS_2_R(i);
8370  strat->fromQ=NULL;
8371  strat->Shdl=idInit(i,F->rank);
8372  strat->S=strat->Shdl->m;
8373 
8374  /*- put polys into S -*/
8375  if (Q!=NULL)
8376  {
8377  strat->fromQ=initec(i);
8378  memset(strat->fromQ,0,i*sizeof(int));
8379  for (i=0; i<IDELEMS(Q); i++)
8380  {
8381  if (Q->m[i]!=NULL)
8382  {
8383  LObject h;
8384  h.p = pCopy(Q->m[i]);
8385  //if (TEST_OPT_INTSTRATEGY)
8386  //{
8387  // h.pCleardenom(); // also does remove Content
8388  //}
8389  //else
8390  //{
8391  // h.pNorm();
8392  //}
8394  {
8395  deleteHC(&h,strat);
8396  }
8397  if (h.p!=NULL)
8398  {
8399  strat->initEcart(&h);
8400  if (strat->sl==-1)
8401  pos =0;
8402  else
8403  {
8404  pos = posInS(strat,strat->sl,h.p,h.ecart);
8405  }
8406  h.sev = pGetShortExpVector(h.p);
8407  strat->enterS(h,pos,strat, strat->tl+1);
8408  enterT(h, strat);
8409  strat->fromQ[pos]=1;
8410  }
8411  }
8412  }
8413  }
8414  /*- put polys into S -*/
8415  for (i=0; i<IDELEMS(F); i++)
8416  {
8417  if (F->m[i]!=NULL)
8418  {
8419  LObject h;
8420  h.p = pCopy(F->m[i]);
8422  {
8423  deleteHC(&h,strat);
8424  }
8425  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8426  {
8427  h.p=redtailBba(h.p,strat->sl,strat);
8428  }
8429  if (h.p!=NULL)
8430  {
8431  strat->initEcart(&h);
8432  if (strat->sl==-1)
8433  pos =0;
8434  else
8435  pos = posInS(strat,strat->sl,h.p,h.ecart);
8436  h.sev = pGetShortExpVector(h.p);
8437  strat->enterS(h,pos,strat, strat->tl+1);
8438  enterT(h,strat);
8439  }
8440  }
8441  }
8442  for (i=0; i<IDELEMS(P); i++)
8443  {
8444  if (P->m[i]!=NULL)
8445  {
8446  LObject h;
8447  h.p=pCopy(P->m[i]);
8449  {
8450  h.pCleardenom();
8451  }
8452  else
8453  {
8454  h.pNorm();
8455  }
8456  if(strat->sl>=0)
8457  {
8459  {
8460  h.p=redBba(h.p,strat->sl,strat);
8461  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8462  {
8463  h.p=redtailBba(h.p,strat->sl,strat);
8464  }
8465  }
8466  else
8467  {
8468  h.p=redMora(h.p,strat->sl,strat);
8469  }
8470  if(h.p!=NULL)
8471  {
8472  strat->initEcart(&h);
8474  {
8475  h.pCleardenom();
8476  }
8477  else
8478  {
8479  h.is_normalized = 0;
8480  h.pNorm();
8481  }
8482  h.sev = pGetShortExpVector(h.p);
8483  h.SetpFDeg();
8484  pos = posInS(strat,strat->sl,h.p,h.ecart);
8485  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8486  strat->enterS(h,pos,strat, strat->tl+1);
8487  enterT(h,strat);
8488  }
8489  }
8490  else
8491  {
8492  h.sev = pGetShortExpVector(h.p);
8493  strat->initEcart(&h);
8494  strat->enterS(h,0,strat, strat->tl+1);
8495  enterT(h,strat);
8496  }
8497  }
8498  }
8499 }
8500 /*2
8501 *construct the set s from F and {P}
8502 */
8503 
8504 void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8505 {
8506  int i,pos;
8507 
8508  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8509  else i=setmaxT;
8510  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8511  strat->sevS=initsevS(i);
8512  strat->sevSig=initsevS(i);
8513  strat->S_2_R=initS_2_R(i);
8514  strat->fromQ=NULL;
8515  strat->Shdl=idInit(i,F->rank);
8516  strat->S=strat->Shdl->m;
8517  strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8518  /*- put polys into S -*/
8519  if (Q!=NULL)
8520  {
8521  strat->fromQ=initec(i);
8522  memset(strat->fromQ,0,i*sizeof(int));
8523  for (i=0; i<IDELEMS(Q); i++)
8524  {
8525  if (Q->m[i]!=NULL)
8526  {
8527  LObject h;
8528  h.p = pCopy(Q->m[i]);
8529  //if (TEST_OPT_INTSTRATEGY)
8530  //{
8531  // h.pCleardenom(); // also does remove Content
8532  //}
8533  //else
8534  //{
8535  // h.pNorm();
8536  //}
8538  {
8539  deleteHC(&h,strat);
8540  }
8541  if (h.p!=NULL)
8542  {
8543  strat->initEcart(&h);
8544  if (strat->sl==-1)
8545  pos =0;
8546  else
8547  {
8548  pos = posInS(strat,strat->sl,h.p,h.ecart);
8549  }
8550  h.sev = pGetShortExpVector(h.p);
8551  strat->enterS(h,pos,strat, strat->tl+1);
8552  enterT(h, strat);
8553  strat->fromQ[pos]=1;
8554  }
8555  }
8556  }
8557  }
8558  /*- put polys into S -*/
8559  for (i=0; i<IDELEMS(F); i++)
8560  {
8561  if (F->m[i]!=NULL)
8562  {
8563  LObject h;
8564  h.p = pCopy(F->m[i]);
8566  {
8567  deleteHC(&h,strat);
8568  }
8569  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8570  {
8571  h.p=redtailBba(h.p,strat->sl,strat);
8572  }
8573  if (h.p!=NULL)
8574  {
8575  strat->initEcart(&h);
8576  if (strat->sl==-1)
8577  pos =0;
8578  else
8579  pos = posInS(strat,strat->sl,h.p,h.ecart);
8580  h.sev = pGetShortExpVector(h.p);
8581  strat->enterS(h,pos,strat, strat->tl+1);
8582  enterT(h,strat);
8583  }
8584  }
8585  }
8586  for (i=0; i<IDELEMS(P); i++)
8587  {
8588  if (P->m[i]!=NULL)
8589  {
8590  LObject h;
8591  h.p=pCopy(P->m[i]);
8593  {
8594  h.pCleardenom();
8595  }
8596  else
8597  {
8598  h.pNorm();
8599  }
8600  if(strat->sl>=0)
8601  {
8603  {
8604  h.p=redBba(h.p,strat->sl,strat);
8605  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8606  {
8607  h.p=redtailBba(h.p,strat->sl,strat);
8608  }
8609  }
8610  else
8611  {
8612  h.p=redMora(h.p,strat->sl,strat);
8613  }
8614  if(h.p!=NULL)
8615  {
8616  strat->initEcart(&h);
8618  {
8619  h.pCleardenom();
8620  }
8621  else
8622  {
8623  h.is_normalized = 0;
8624  h.pNorm();
8625  }
8626  h.sev = pGetShortExpVector(h.p);
8627  h.SetpFDeg();
8628  pos = posInS(strat,strat->sl,h.p,h.ecart);
8629  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8630  strat->enterS(h,pos,strat, strat->tl+1);
8631  enterT(h,strat);
8632  }
8633  }
8634  else
8635  {
8636  h.sev = pGetShortExpVector(h.p);
8637  strat->initEcart(&h);
8638  strat->enterS(h,0,strat, strat->tl+1);
8639  enterT(h,strat);
8640  }
8641  }
8642  }
8643 }
8644 
8645 /*2
8646 * reduces h using the set S
8647 * procedure used in cancelunit1
8648 */
8649 static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8650 {
8651  int j = 0;
8652  unsigned long not_sev = ~ pGetShortExpVector(h);
8653 
8654  while (j <= maxIndex)
8655  {
8656  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8657  return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8658  else j++;
8659  }
8660  return h;
8661 }
8662 
8663 /*2
8664 *tests if p.p=monomial*unit and cancels the unit
8665 */
8666 void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8667 {
8668  int k;
8669  poly r,h,h1,q;
8670 
8671  if (!pIsVector((*p).p) && ((*p).ecart != 0))
8672  {
8673 #ifdef HAVE_RINGS
8674  // Leading coef have to be a unit: no
8675  // example 2x+4x2 should be simplified to 2x*(1+2x)
8676  // and 2 is not a unit in Z
8677  //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8678 #endif
8679  k = 0;
8680  h1 = r = pCopy((*p).p);
8681  h =pNext(r);
8682  loop
8683  {
8684  if (h==NULL)
8685  {
8686  pDelete(&r);
8687  pDelete(&(pNext((*p).p)));
8688  (*p).ecart = 0;
8689  (*p).length = 1;
8690  (*p).pLength = 1;
8691  (*suc)=0;
8692  return;
8693  }
8694  if (!pDivisibleBy(r,h))
8695  {
8696  q=redBba1(h,index ,strat);
8697  if (q != h)
8698  {
8699  k++;
8700  pDelete(&h);
8701  pNext(h1) = h = q;
8702  }
8703  else
8704  {
8705  pDelete(&r);
8706  return;
8707  }
8708  }
8709  else
8710  {
8711  h1 = h;
8712  pIter(h);
8713  }
8714  if (k > 10)
8715  {
8716  pDelete(&r);
8717  return;
8718  }
8719  }
8720  }
8721 }
8722 
8723 #if 0
8724 /*2
8725 * reduces h using the elements from Q in the set S
8726 * procedure used in updateS
8727 * must not be used for elements of Q or elements of an ideal !
8728 */
8729 static poly redQ (poly h, int j, kStrategy strat)
8730 {
8731  int start;
8732  unsigned long not_sev = ~ pGetShortExpVector(h);
8733  while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8734  start=j;
8735  while (j<=strat->sl)
8736  {
8737  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8738  {
8739  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8740  if (h==NULL) return NULL;
8741  j = start;
8742  not_sev = ~ pGetShortExpVector(h);
8743  }
8744  else j++;
8745  }
8746  return h;
8747 }
8748 #endif
8749 
8750 /*2
8751 * reduces h using the set S
8752 * procedure used in updateS
8753 */
8754 static poly redBba (poly h,int maxIndex,kStrategy strat)
8755 {
8756  int j = 0;
8757  unsigned long not_sev = ~ pGetShortExpVector(h);
8758 
8759  while (j <= maxIndex)
8760  {
8761  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8762  {
8763  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8764  if (h==NULL) return NULL;
8765  j = 0;
8766  not_sev = ~ pGetShortExpVector(h);
8767  }
8768  else j++;
8769  }
8770  return h;
8771 }
8772 
8773 /*2
8774 * reduces h using the set S
8775 *e is the ecart of h
8776 *procedure used in updateS
8777 */
8778 static poly redMora (poly h,int maxIndex,kStrategy strat)
8779 {
8780  int j=0;
8781  int e,l;
8782  unsigned long not_sev = ~ pGetShortExpVector(h);
8783 
8784  if (maxIndex >= 0)
8785  {
8786  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8787  do
8788  {
8789  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8790  && ((e >= strat->ecartS[j]) || strat->kHEdgeFound))
8791  {
8792 #ifdef KDEBUG
8793  if (TEST_OPT_DEBUG)
8794  {
8795  PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8796  }
8797 #endif
8798  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8799 #ifdef KDEBUG
8800  if(TEST_OPT_DEBUG)
8801  {
8802  PrintS(")\nto "); wrp(h); PrintLn();
8803  }
8804 #endif
8805  // pDelete(&h);
8806  if (h == NULL) return NULL;
8807  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8808  j = 0;
8809  not_sev = ~ pGetShortExpVector(h);
8810  }
8811  else j++;
8812  }
8813  while (j <= maxIndex);
8814  }
8815  return h;
8816 }
8817 
8818 /*2
8819 *updates S:
8820 *the result is a set of polynomials which are in
8821 *normalform with respect to S
8822 */
8823 void updateS(BOOLEAN toT,kStrategy strat)
8824 {
8825  LObject h;
8826  int i, suc=0;
8827  poly redSi=NULL;
8828  BOOLEAN change,any_change;
8829 // Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8830 // for (i=0; i<=(strat->sl); i++)
8831 // {
8832 // Print("s%d:",i);
8833 // if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8834 // pWrite(strat->S[i]);
8835 // }
8836 // Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8837  any_change=FALSE;
8839  {
8840  while (suc != -1)
8841  {
8842  i=suc+1;
8843  while (i<=strat->sl)
8844  {
8845  change=FALSE;
8847  any_change = FALSE;
8848  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8849  {
8850  redSi = pHead(strat->S[i]);
8851  strat->S[i] = redBba(strat->S[i],i-1,strat);
8852  //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8853  // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8854  if (pCmp(redSi,strat->S[i])!=0)
8855  {
8856  change=TRUE;
8857  any_change=TRUE;
8858  #ifdef KDEBUG
8859  if (TEST_OPT_DEBUG)
8860  {
8861  PrintS("reduce:");
8862  wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8863  }
8864  #endif
8865  if (TEST_OPT_PROT)
8866  {
8867  if (strat->S[i]==NULL)
8868  PrintS("V");
8869  else
8870  PrintS("v");
8871  mflush();
8872  }
8873  }
8874  pLmDelete(&redSi);
8875  if (strat->S[i]==NULL)
8876  {
8877  deleteInS(i,strat);
8878  i--;
8879  }
8880  else if (change)
8881  {
8883  {
8884  if (TEST_OPT_CONTENTSB)
8885  {
8886  number n;
8887  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8888  if (!nIsOne(n))
8889  {
8891  denom->n=nInvers(n);
8892  denom->next=DENOMINATOR_LIST;
8893  DENOMINATOR_LIST=denom;
8894  }
8895  nDelete(&n);
8896  }
8897  else
8898  {
8899  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8900  }
8901  }
8902  else
8903  {
8904  pNorm(strat->S[i]);
8905  }
8906  strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8907  }
8908  }
8909  i++;
8910  }
8911  if (any_change) reorderS(&suc,strat);
8912  else break;
8913  }
8914  if (toT)
8915  {
8916  for (i=0; i<=strat->sl; i++)
8917  {
8918  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8919  {
8920  h.p = redtailBba(strat->S[i],i-1,strat);
8922  {
8923  h.pCleardenom();// also does remove Content
8924  }
8925  }
8926  else
8927  {
8928  h.p = strat->S[i];
8929  }
8930  strat->initEcart(&h);
8931  if (strat->honey)
8932  {
8933  strat->ecartS[i] = h.ecart;
8934  }
8935  if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8936  else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8937  h.sev = strat->sevS[i];
8938  /*puts the elements of S also to T*/
8939  strat->initEcart(&h);
8940  enterT(h,strat);
8941  strat->S_2_R[i] = strat->tl;
8942  }
8943  }
8944  }
8945  else
8946  {
8947  while (suc != -1)
8948  {
8949  i=suc;
8950  while (i<=strat->sl)
8951  {
8952  change=FALSE;
8953  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8954  {
8955  redSi=pHead((strat->S)[i]);
8956  (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
8957  if ((strat->S)[i]==NULL)
8958  {
8959  deleteInS(i,strat);
8960  i--;
8961  }
8962  else if (pCmp((strat->S)[i],redSi)!=0)
8963  {
8964  any_change=TRUE;
8965  h.p = strat->S[i];
8966  strat->initEcart(&h);
8967  strat->ecartS[i] = h.ecart;
8969  {
8970  if (TEST_OPT_CONTENTSB)
8971  {
8972  number n;
8973  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8974  if (!nIsOne(n))
8975  {
8977  denom->n=nInvers(n);
8978  denom->next=DENOMINATOR_LIST;
8979  DENOMINATOR_LIST=denom;
8980  }
8981  nDelete(&n);
8982  }
8983  else
8984  {
8985  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8986  }
8987  }
8988  else
8989  {
8990  pNorm(strat->S[i]); // == h.p
8991  }
8992  h.sev = pGetShortExpVector(h.p);
8993  strat->sevS[i] = h.sev;
8994  }
8995  pLmDelete(&redSi);
8996  kTest(strat);
8997  }
8998  i++;
8999  }
9000 #ifdef KDEBUG
9001  kTest(strat);
9002 #endif
9003  if (any_change) reorderS(&suc,strat);
9004  else { suc=-1; break; }
9005  if (h.p!=NULL)
9006  {
9007  if (!strat->kHEdgeFound)
9008  {
9009  /*strat->kHEdgeFound =*/ HEckeTest(h.p,strat);
9010  }
9011  if (strat->kHEdgeFound)
9012  newHEdge(strat);
9013  }
9014  }
9015  for (i=0; i<=strat->sl; i++)
9016  {
9017  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9018  {
9019  strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
9020  strat->initEcart(&h);
9021  strat->ecartS[i] = h.ecart;
9022  h.sev = pGetShortExpVector(h.p);
9023  strat->sevS[i] = h.sev;
9024  }
9025  else
9026  {
9027  h.p = strat->S[i];
9028  h.ecart=strat->ecartS[i];
9029  h.sev = strat->sevS[i];
9030  h.length = h.pLength = pLength(h.p);
9031  }
9032  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9033  cancelunit1(&h,&suc,strat->sl,strat);
9034  h.SetpFDeg();
9035  /*puts the elements of S also to T*/
9036  enterT(h,strat);
9037  strat->S_2_R[i] = strat->tl;
9038  }
9039  if (suc!= -1) updateS(toT,strat);
9040  }
9041 #ifdef KDEBUG
9042  kTest(strat);
9043 #endif
9044 }
9045 
9046 /*2
9047 * -puts p to the standardbasis s at position at
9048 * -saves the result in S
9049 */
9050 void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
9051 {
9052  strat->news = TRUE;
9053  /*- puts p to the standardbasis s at position at -*/
9054  if (strat->sl == IDELEMS(strat->Shdl)-1)
9055  {
9056  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9057  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9058  (IDELEMS(strat->Shdl)+setmaxTinc)
9059  *sizeof(unsigned long));
9060  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9061  IDELEMS(strat->Shdl)*sizeof(int),
9062  (IDELEMS(strat->Shdl)+setmaxTinc)
9063  *sizeof(int));
9064  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9065  IDELEMS(strat->Shdl)*sizeof(int),
9066  (IDELEMS(strat->Shdl)+setmaxTinc)
9067  *sizeof(int));
9068  if (strat->lenS!=NULL)
9069  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9070  IDELEMS(strat->Shdl)*sizeof(int),
9071  (IDELEMS(strat->Shdl)+setmaxTinc)
9072  *sizeof(int));
9073  if (strat->lenSw!=NULL)
9074  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9075  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9076  (IDELEMS(strat->Shdl)+setmaxTinc)
9077  *sizeof(wlen_type));
9078  if (strat->fromQ!=NULL)
9079  {
9080  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9081  IDELEMS(strat->Shdl)*sizeof(int),
9082  (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9083  }
9084  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
9085  IDELEMS(strat->Shdl)+=setmaxTinc;
9086  strat->Shdl->m=strat->S;
9087  }
9088  if (atS <= strat->sl)
9089  {
9090 #ifdef ENTER_USE_MEMMOVE
9091  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9092  (strat->sl - atS + 1)*sizeof(poly));
9093  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9094  (strat->sl - atS + 1)*sizeof(int));
9095  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9096  (strat->sl - atS + 1)*sizeof(unsigned long));
9097  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9098  (strat->sl - atS + 1)*sizeof(int));
9099  if (strat->lenS!=NULL)
9100  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9101  (strat->sl - atS + 1)*sizeof(int));
9102  if (strat->lenSw!=NULL)
9103  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9104  (strat->sl - atS + 1)*sizeof(wlen_type));
9105 #else
9106  for (i=strat->sl+1; i>=atS+1; i--)
9107  {
9108  strat->S[i] = strat->S[i-1];
9109  strat->ecartS[i] = strat->ecartS[i-1];
9110  strat->sevS[i] = strat->sevS[i-1];
9111  strat->S_2_R[i] = strat->S_2_R[i-1];
9112  }
9113  if (strat->lenS!=NULL)
9114  for (i=strat->sl+1; i>=atS+1; i--)
9115  strat->lenS[i] = strat->lenS[i-1];
9116  if (strat->lenSw!=NULL)
9117  for (i=strat->sl+1; i>=atS+1; i--)
9118  strat->lenSw[i] = strat->lenSw[i-1];
9119 #endif
9120  }
9121  if (strat->fromQ!=NULL)
9122  {
9123 #ifdef ENTER_USE_MEMMOVE
9124  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9125  (strat->sl - atS + 1)*sizeof(int));
9126 #else
9127  for (i=strat->sl+1; i>=atS+1; i--)
9128  {
9129  strat->fromQ[i] = strat->fromQ[i-1];
9130  }
9131 #endif
9132  strat->fromQ[atS]=0;
9133  }
9134 
9135  /*- save result -*/
9136  poly pp=p.p;
9137  strat->S[atS] = pp;
9138  if (strat->honey) strat->ecartS[atS] = p.ecart;
9139  if (p.sev == 0)
9140  p.sev = pGetShortExpVector(pp);
9141  else
9142  assume(p.sev == pGetShortExpVector(pp));
9143  strat->sevS[atS] = p.sev;
9144  strat->ecartS[atS] = p.ecart;
9145  strat->S_2_R[atS] = atR;
9146  strat->sl++;
9147 }
9148 
9149 /*2
9150 * -puts p to the standardbasis s at position at
9151 * -saves the result in S
9152 */
9153 void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
9154 {
9155  strat->news = TRUE;
9156  /*- puts p to the standardbasis s at position at -*/
9157  if (strat->sl == IDELEMS(strat->Shdl)-1)
9158  {
9159  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9160  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9161  (IDELEMS(strat->Shdl)+setmax)
9162  *sizeof(unsigned long));
9163  strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
9164  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9165  (IDELEMS(strat->Shdl)+setmax)
9166  *sizeof(unsigned long));
9167  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9168  IDELEMS(strat->Shdl)*sizeof(int),
9169  (IDELEMS(strat->Shdl)+setmax)
9170  *sizeof(int));
9171  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9172  IDELEMS(strat->Shdl)*sizeof(int),
9173  (IDELEMS(strat->Shdl)+setmax)
9174  *sizeof(int));
9175  if (strat->lenS!=NULL)
9176  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9177  IDELEMS(strat->Shdl)*sizeof(int),
9178  (IDELEMS(strat->Shdl)+setmax)
9179  *sizeof(int));
9180  if (strat->lenSw!=NULL)
9181  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9182  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9183  (IDELEMS(strat->Shdl)+setmax)
9184  *sizeof(wlen_type));
9185  if (strat->fromQ!=NULL)
9186  {
9187  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9188  IDELEMS(strat->Shdl)*sizeof(int),
9189  (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
9190  }
9191  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
9192  pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
9193  IDELEMS(strat->Shdl)+=setmax;
9194  strat->Shdl->m=strat->S;
9195  }
9196  // in a signature-based algorithm the following situation will never
9197  // appear due to the fact that the critical pairs are already sorted
9198  // by increasing signature.
9199  // True. However, in the case of integers we need to put the element
9200  // that caused the signature drop on the first position
9201  if (atS <= strat->sl)
9202  {
9203 #ifdef ENTER_USE_MEMMOVE
9204  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9205  (strat->sl - atS + 1)*sizeof(poly));
9206  memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9207  (strat->sl - atS + 1)*sizeof(poly));
9208  memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9209  (strat->sl - atS + 1)*sizeof(unsigned long));
9210  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9211  (strat->sl - atS + 1)*sizeof(int));
9212  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9213  (strat->sl - atS + 1)*sizeof(unsigned long));
9214  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9215  (strat->sl - atS + 1)*sizeof(int));
9216  if (strat->lenS!=NULL)
9217  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9218  (strat->sl - atS + 1)*sizeof(int));
9219  if (strat->lenSw!=NULL)
9220  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9221  (strat->sl - atS + 1)*sizeof(wlen_type));
9222 #else
9223  for (i=strat->sl+1; i>=atS+1; i--)
9224  {
9225  strat->S[i] = strat->S[i-1];
9226  strat->ecartS[i] = strat->ecartS[i-1];
9227  strat->sevS[i] = strat->sevS[i-1];
9228  strat->S_2_R[i] = strat->S_2_R[i-1];
9229  strat->sig[i] = strat->sig[i-1];
9230  strat->sevSig[i] = strat->sevSig[i-1];
9231  }
9232  if (strat->lenS!=NULL)
9233  for (i=strat->sl+1; i>=atS+1; i--)
9234  strat->lenS[i] = strat->lenS[i-1];
9235  if (strat->lenSw!=NULL)
9236  for (i=strat->sl+1; i>=atS+1; i--)
9237  strat->lenSw[i] = strat->lenSw[i-1];
9238 #endif
9239  }
9240  if (strat->fromQ!=NULL)
9241  {
9242 #ifdef ENTER_USE_MEMMOVE
9243  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9244  (strat->sl - atS + 1)*sizeof(int));
9245 #else
9246  for (i=strat->sl+1; i>=atS+1; i--)
9247  {
9248  strat->fromQ[i] = strat->fromQ[i-1];
9249  }
9250 #endif
9251  strat->fromQ[atS]=0;
9252  }
9253 
9254  /*- save result -*/
9255  strat->S[atS] = p.p;
9256  strat->sig[atS] = p.sig; // TODO: get ths correct signature in here!
9257  if (strat->honey) strat->ecartS[atS] = p.ecart;
9258  if (p.sev == 0)
9259  p.sev = pGetShortExpVector(p.p);
9260  else
9261  assume(p.sev == pGetShortExpVector(p.p));
9262  strat->sevS[atS] = p.sev;
9263  // during the interreduction process of a signature-based algorithm we do not
9264  // compute the signature at this point, but when the whole interreduction
9265  // process finishes, i.e. f5c terminates!
9266  if (p.sig != NULL)
9267  {
9268  if (p.sevSig == 0)
9269  p.sevSig = pGetShortExpVector(p.sig);
9270  else
9271  assume(p.sevSig == pGetShortExpVector(p.sig));
9272  strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9273  }
9274  strat->ecartS[atS] = p.ecart;
9275  strat->S_2_R[atS] = atR;
9276  strat->sl++;
9277 #ifdef DEBUGF5
9278  int k;
9279  Print("--- LIST S: %d ---\n",strat->sl);
9280  for(k=0;k<=strat->sl;k++)
9281  {
9282  pWrite(strat->sig[k]);
9283  }
9284  PrintS("--- LIST S END ---\n");
9285 #endif
9286 }
9287 
9288 /*2
9289 * puts p to the set T at position atT
9290 */
9291 void enterT(LObject &p, kStrategy strat, int atT)
9292 {
9293  int i;
9294 
9295  pp_Test(p.p, currRing, p.tailRing);
9296  assume(strat->tailRing == p.tailRing);
9297  // redMoraNF complains about this -- but, we don't really
9298  // neeed this so far
9299  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9300  assume(p.FDeg == p.pFDeg());
9301  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9302 
9303 #ifdef KDEBUG
9304  // do not put an LObject twice into T:
9305  for(i=strat->tl;i>=0;i--)
9306  {
9307  if (p.p==strat->T[i].p)
9308  {
9309  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9310  return;
9311  }
9312  }
9313 #endif
9314 
9315 #ifdef HAVE_TAIL_RING
9316  if (currRing!=strat->tailRing)
9317  {
9318  p.t_p=p.GetLmTailRing();
9319  }
9320 #endif
9321  strat->newt = TRUE;
9322  if (atT < 0)
9323  atT = strat->posInT(strat->T, strat->tl, p);
9324  if (strat->tl == strat->tmax-1)
9325  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9326  if (atT <= strat->tl)
9327  {
9328 #ifdef ENTER_USE_MEMMOVE
9329  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9330  (strat->tl-atT+1)*sizeof(TObject));
9331  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9332  (strat->tl-atT+1)*sizeof(unsigned long));
9333 #endif
9334  for (i=strat->tl+1; i>=atT+1; i--)
9335  {
9336 #ifndef ENTER_USE_MEMMOVE
9337  strat->T[i] = strat->T[i-1];
9338  strat->sevT[i] = strat->sevT[i-1];
9339 #endif
9340  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9341  }
9342  }
9343 
9344  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9345  {
9347  (strat->tailRing != NULL ?
9348  strat->tailRing : currRing),
9349  strat->tailBin);
9350  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9351  }
9352  strat->T[atT] = (TObject) p;
9353  //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9354 
9355  if (pNext(p.p) != NULL)
9356  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9357  else
9358  strat->T[atT].max_exp = NULL;
9359 
9360  strat->tl++;
9361  strat->R[strat->tl] = &(strat->T[atT]);
9362  strat->T[atT].i_r = strat->tl;
9363  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9364  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9365  kTest_T(&(strat->T[atT]));
9366 }
9367 
9368 /*2
9369 * puts p to the set T at position atT
9370 */
9371 #ifdef HAVE_RINGS
9372 void enterT_strong(LObject &p, kStrategy strat, int atT)
9373 {
9375  int i;
9376 
9377  pp_Test(p.p, currRing, p.tailRing);
9378  assume(strat->tailRing == p.tailRing);
9379  // redMoraNF complains about this -- but, we don't really
9380  // neeed this so far
9381  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9382  assume(p.FDeg == p.pFDeg());
9383  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9384 
9385 #ifdef KDEBUG
9386  // do not put an LObject twice into T:
9387  for(i=strat->tl;i>=0;i--)
9388  {
9389  if (p.p==strat->T[i].p)
9390  {
9391  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9392  return;
9393  }
9394  }
9395 #endif
9396 
9397 #ifdef HAVE_TAIL_RING
9398  if (currRing!=strat->tailRing)
9399  {
9400  p.t_p=p.GetLmTailRing();
9401  }
9402 #endif
9403  strat->newt = TRUE;
9404  if (atT < 0)
9405  atT = strat->posInT(strat->T, strat->tl, p);
9406  if (strat->tl == strat->tmax-1)
9407  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9408  if (atT <= strat->tl)
9409  {
9410 #ifdef ENTER_USE_MEMMOVE
9411  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9412  (strat->tl-atT+1)*sizeof(TObject));
9413  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9414  (strat->tl-atT+1)*sizeof(unsigned long));
9415 #endif
9416  for (i=strat->tl+1; i>=atT+1; i--)
9417  {
9418 #ifndef ENTER_USE_MEMMOVE
9419  strat->T[i] = strat->T[i-1];
9420  strat->sevT[i] = strat->sevT[i-1];
9421 #endif
9422  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9423  }
9424  }
9425 
9426  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9427  {
9429  (strat->tailRing != NULL ?
9430  strat->tailRing : currRing),
9431  strat->tailBin);
9432  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9433  }
9434  strat->T[atT] = (TObject) p;
9435  //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9436 
9437  if (pNext(p.p) != NULL)
9438  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9439  else
9440  strat->T[atT].max_exp = NULL;
9441 
9442  strat->tl++;
9443  strat->R[strat->tl] = &(strat->T[atT]);
9444  strat->T[atT].i_r = strat->tl;
9445  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9446  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9447  #if 1
9449  && !n_IsUnit(p.p->coef, currRing->cf))
9450  {
9451  for(i=strat->tl;i>=0;i--)
9452  {
9453  if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9454  {
9455  enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9456  }
9457  }
9458  }
9459  /*
9460  printf("\nThis is T:\n");
9461  for(i=strat->tl;i>=0;i--)
9462  {
9463  pWrite(strat->T[i].p);
9464  }
9465  //getchar();*/
9466  #endif
9467  kTest_T(&(strat->T[atT]));
9468 }
9469 #endif
9470 
9471 /*2
9472 * puts signature p.sig to the set syz
9473 */
9474 void enterSyz(LObject &p, kStrategy strat, int atT)
9475 {
9476  int i;
9477  strat->newt = TRUE;
9478  if (strat->syzl == strat->syzmax-1)
9479  {
9480  pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9481  strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9482  (strat->syzmax)*sizeof(unsigned long),
9483  ((strat->syzmax)+setmax)
9484  *sizeof(unsigned long));
9485  strat->syzmax += setmax;
9486  }
9487  if (atT < strat->syzl)
9488  {
9489 #ifdef ENTER_USE_MEMMOVE
9490  memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9491  (strat->syzl-atT+1)*sizeof(poly));
9492  memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9493  (strat->syzl-atT+1)*sizeof(unsigned long));
9494 #endif
9495  for (i=strat->syzl; i>=atT+1; i--)
9496  {
9497 #ifndef ENTER_USE_MEMMOVE
9498  strat->syz[i] = strat->syz[i-1];
9499  strat->sevSyz[i] = strat->sevSyz[i-1];
9500 #endif
9501  }
9502  }
9503  //i = strat->syzl;
9504  i = atT;
9505  //Makes sure the syz saves just the signature
9506  #ifdef HAVE_RINGS
9508  pNext(p.sig) = NULL;
9509  #endif
9510  strat->syz[atT] = p.sig;
9511  strat->sevSyz[atT] = p.sevSig;
9512  strat->syzl++;
9513 #if F5DEBUG
9514  Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9515  pWrite(strat->syz[atT]);
9516 #endif
9517  // recheck pairs in strat->L with new rule and delete correspondingly
9518  int cc = strat->Ll;
9519  while (cc>-1)
9520  {
9521  //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9522  //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);
9523  if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9524  strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9525  #ifdef HAVE_RINGS
9526  &&((!rField_is_Ring(currRing))
9527  || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9528  #endif
9529  )
9530  {
9531  //printf("\nYES!\n");
9532  deleteInL(strat->L,&strat->Ll,cc,strat);
9533  }
9534  cc--;
9535  }
9536 //#if 1
9537 #ifdef DEBUGF5
9538  PrintS("--- Syzygies ---\n");
9539  Print("syzl %d\n",strat->syzl);
9540  Print("syzmax %d\n",strat->syzmax);
9541  PrintS("--------------------------------\n");
9542  for(i=0;i<=strat->syzl-1;i++)
9543  {
9544  Print("%d - ",i);
9545  pWrite(strat->syz[i]);
9546  }
9547  PrintS("--------------------------------\n");
9548 #endif
9549 }
9550 
9551 
9552 void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9553 {
9554 
9555  //if the ordering is local, then hilb criterion
9556  //can be used also if the ideal is not homogenous
9558  {
9560  *hilb=NULL;
9561  else
9562  return;
9563  }
9564  if (strat->homog!=isHomog)
9565  {
9566  *hilb=NULL;
9567  }
9568 }
9569 
9571 {
9573  strat->chainCrit=chainCritNormal;
9574  if (TEST_OPT_SB_1)
9575  strat->chainCrit=chainCritOpt_1;
9576 #ifdef HAVE_RINGS
9577  if (rField_is_Ring(currRing))
9578  {
9580  strat->chainCrit=chainCritRing;
9581  }
9582 #endif
9583 #ifdef HAVE_RATGRING
9584  if (rIsRatGRing(currRing))
9585  {
9586  strat->chainCrit=chainCritPart;
9587  /* enterOnePairNormal get rational part in it */
9588  }
9589 #endif
9590  if (TEST_OPT_IDLIFT /* i.e. also strat->syzComp==1 */
9591  && (!rIsPluralRing(currRing)))
9593 
9594  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9595  strat->Gebauer = strat->homog || strat->sugarCrit;
9596  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9597  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9598  strat->pairtest = NULL;
9599  /* alway use tailreduction, except:
9600  * - in local rings, - in lex order case, -in ring over extensions */
9602  //if(rHasMixedOrdering(currRing)==2)
9603  //{
9604  // strat->noTailReduction =TRUE;
9605  //}
9606 
9607 #ifdef HAVE_PLURAL
9608  // and r is plural_ring
9609  // hence this holds for r a rational_plural_ring
9610  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9611  { //or it has non-quasi-comm type... later
9612  strat->sugarCrit = FALSE;
9613  strat->Gebauer = FALSE;
9614  strat->honey = FALSE;
9615  }
9616 #endif
9617 
9618  // Coefficient ring?
9619  if (rField_is_Ring(currRing))
9620  {
9621  strat->sugarCrit = FALSE;
9622  strat->Gebauer = FALSE ;
9623  strat->honey = FALSE;
9624  }
9625  #ifdef KDEBUG
9626  if (TEST_OPT_DEBUG)
9627  {
9628  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9629  else PrintS("ideal/module is not homogeneous\n");
9630  }
9631  #endif
9632 }
9633 
9635 {
9636  //strat->enterOnePair=enterOnePairNormal;
9638  //strat->chainCrit=chainCritNormal;
9639  strat->chainCrit = chainCritSig;
9640  /******************************************
9641  * rewCrit1 and rewCrit2 are already set in
9642  * kSba() in kstd1.cc
9643  *****************************************/
9644  //strat->rewCrit1 = faugereRewCriterion;
9645  if (strat->sbaOrder == 1)
9646  {
9647  strat->syzCrit = syzCriterionInc;
9648  }
9649  else
9650  {
9651  strat->syzCrit = syzCriterion;
9652  }
9653 #ifdef HAVE_RINGS
9654  if (rField_is_Ring(currRing))
9655  {
9657  strat->chainCrit=chainCritRing;
9658  }
9659 #endif
9660 #ifdef HAVE_RATGRING
9661  if (rIsRatGRing(currRing))
9662  {
9663  strat->chainCrit=chainCritPart;
9664  /* enterOnePairNormal get rational part in it */
9665  }
9666 #endif
9667 
9668  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9669  strat->Gebauer = strat->homog || strat->sugarCrit;
9670  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9671  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9672  strat->pairtest = NULL;
9673  /* alway use tailreduction, except:
9674  * - in local rings, - in lex order case, -in ring over extensions */
9677 
9678 #ifdef HAVE_PLURAL
9679  // and r is plural_ring
9680  // hence this holds for r a rational_plural_ring
9681  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9682  { //or it has non-quasi-comm type... later
9683  strat->sugarCrit = FALSE;
9684  strat->Gebauer = FALSE;
9685  strat->honey = FALSE;
9686  }
9687 #endif
9688 
9689  // Coefficient ring?
9690  if (rField_is_Ring(currRing))
9691  {
9692  strat->sugarCrit = FALSE;
9693  strat->Gebauer = FALSE ;
9694  strat->honey = FALSE;
9695  }
9696  #ifdef KDEBUG
9697  if (TEST_OPT_DEBUG)
9698  {
9699  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9700  else PrintS("ideal/module is not homogeneous\n");
9701  }
9702  #endif
9703 }
9704 
9706  (const LSet set, const int length,
9707  LObject* L,const kStrategy strat))
9708 {
9709  if (pos_in_l == posInL110
9710  || pos_in_l == posInL10
9711  #ifdef HAVE_RINGS
9712  || pos_in_l == posInL110Ring
9713  || pos_in_l == posInLRing
9714  #endif
9715  )
9716  return TRUE;
9717 
9718  return FALSE;
9719 }
9720 
9722 {
9724  {
9725  if (strat->honey)
9726  {
9727  strat->posInL = posInL15;
9728  // ok -- here is the deal: from my experiments for Singular-2-0
9729  // I conclude that that posInT_EcartpLength is the best of
9730  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9731  // see the table at the end of this file
9732  if (TEST_OPT_OLDSTD)
9733  strat->posInT = posInT15;
9734  else
9735  strat->posInT = posInT_EcartpLength;
9736  }
9737  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9738  {
9739  strat->posInL = posInL11;
9740  strat->posInT = posInT11;
9741  }
9742  else if (TEST_OPT_INTSTRATEGY)
9743  {
9744  strat->posInL = posInL11;
9745  strat->posInT = posInT11;
9746  }
9747  else
9748  {
9749  strat->posInL = posInL0;
9750  strat->posInT = posInT0;
9751  }
9752  //if (strat->minim>0) strat->posInL =posInLSpecial;
9753  if (strat->homog)
9754  {
9755  strat->posInL = posInL110;
9756  strat->posInT = posInT110;
9757  }
9758  }
9759  else
9760  {
9761  if (strat->homog)
9762  {
9763  strat->posInL = posInL11;
9764  strat->posInT = posInT11;
9765  }
9766  else
9767  {
9768  if ((currRing->order[0]==ringorder_c)
9769  ||(currRing->order[0]==ringorder_C))
9770  {
9771  strat->posInL = posInL17_c;
9772  strat->posInT = posInT17_c;
9773  }
9774  else
9775  {
9776  strat->posInL = posInL17;
9777  strat->posInT = posInT17;
9778  }
9779  }
9780  }
9781  if (strat->minim>0) strat->posInL =posInLSpecial;
9782  // for further tests only
9783  if ((BTEST1(11)) || (BTEST1(12)))
9784  strat->posInL = posInL11;
9785  else if ((BTEST1(13)) || (BTEST1(14)))
9786  strat->posInL = posInL13;
9787  else if ((BTEST1(15)) || (BTEST1(16)))
9788  strat->posInL = posInL15;
9789  else if ((BTEST1(17)) || (BTEST1(18)))
9790  strat->posInL = posInL17;
9791  if (BTEST1(11))
9792  strat->posInT = posInT11;
9793  else if (BTEST1(13))
9794  strat->posInT = posInT13;
9795  else if (BTEST1(15))
9796  strat->posInT = posInT15;
9797  else if ((BTEST1(17)))
9798  strat->posInT = posInT17;
9799  else if ((BTEST1(19)))
9800  strat->posInT = posInT19;
9801  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9802  strat->posInT = posInT1;
9804 }
9805 
9806 #ifdef HAVE_RINGS
9808 {
9810  {
9811  if (strat->honey)
9812  {
9813  strat->posInL = posInL15Ring;
9814  // ok -- here is the deal: from my experiments for Singular-2-0
9815  // I conclude that that posInT_EcartpLength is the best of
9816  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9817  // see the table at the end of this file
9818  if (TEST_OPT_OLDSTD)
9819  strat->posInT = posInT15Ring;
9820  else
9821  strat->posInT = posInT_EcartpLength;
9822  }
9823  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9824  {
9825  strat->posInL = posInL11Ring;
9826  strat->posInT = posInT11;
9827  }
9828  else if (TEST_OPT_INTSTRATEGY)
9829  {
9830  strat->posInL = posInL11Ring;
9831  strat->posInT = posInT11;
9832  }
9833  else
9834  {
9835  strat->posInL = posInL0Ring;
9836  strat->posInT = posInT0;
9837  }
9838  //if (strat->minim>0) strat->posInL =posInLSpecial;
9839  if (strat->homog)
9840  {
9841  strat->posInL = posInL110Ring;
9842  strat->posInT = posInT110Ring;
9843  }
9844  }
9845  else
9846  {
9847  if (strat->homog)
9848  {
9849  //printf("\nHere 3\n");
9850  strat->posInL = posInL11Ring;
9851  strat->posInT = posInT11Ring;
9852  }
9853  else
9854  {
9855  if ((currRing->order[0]==ringorder_c)
9856  ||(currRing->order[0]==ringorder_C))
9857  {
9858  strat->posInL = posInL17_cRing;
9859  strat->posInT = posInT17_cRing;
9860  }
9861  else
9862  {
9863  strat->posInL = posInL11Ringls;
9864  strat->posInT = posInT17Ring;
9865  }
9866  }
9867  }
9868  if (strat->minim>0) strat->posInL =posInLSpecial;
9869  // for further tests only
9870  if ((BTEST1(11)) || (BTEST1(12)))
9871  strat->posInL = posInL11Ring;
9872  else if ((BTEST1(13)) || (BTEST1(14)))
9873  strat->posInL = posInL13;
9874  else if ((BTEST1(15)) || (BTEST1(16)))
9875  strat->posInL = posInL15Ring;
9876  else if ((BTEST1(17)) || (BTEST1(18)))
9877  strat->posInL = posInL17Ring;
9878  if (BTEST1(11))
9879  strat->posInT = posInT11Ring;
9880  else if (BTEST1(13))
9881  strat->posInT = posInT13;
9882  else if (BTEST1(15))
9883  strat->posInT = posInT15Ring;
9884  else if ((BTEST1(17)))
9885  strat->posInT = posInT17Ring;
9886  else if ((BTEST1(19)))
9887  strat->posInT = posInT19;
9888  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9889  strat->posInT = posInT1;
9891 }
9892 #endif
9893 
9894 void initBuchMora (ideal F,ideal Q,kStrategy strat)
9895 {
9896  strat->interpt = BTEST1(OPT_INTERRUPT);
9897  strat->kHEdge=NULL;
9899  /*- creating temp data structures------------------- -*/
9900  strat->cp = 0;
9901  strat->c3 = 0;
9902  strat->tail = pInit();
9903  /*- set s -*/
9904  strat->sl = -1;
9905  /*- set L -*/
9906  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9907  strat->Ll = -1;
9908  strat->L = initL(strat->Lmax);
9909  /*- set B -*/
9910  strat->Bmax = setmaxL;
9911  strat->Bl = -1;
9912  strat->B = initL();
9913  /*- set T -*/
9914  strat->tl = -1;
9915  strat->tmax = setmaxT;
9916  strat->T = initT();
9917  strat->R = initR();
9918  strat->sevT = initsevT();
9919  /*- init local data struct.---------------------------------------- -*/
9920  strat->P.ecart=0;
9921  strat->P.length=0;
9922  strat->P.pLength=0;
9924  {
9925  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
9926  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
9927  }
9929  {
9930  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9931  }
9932  else
9933  {
9934  if(TEST_OPT_SB_1)
9935  {
9936  int i;
9937  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
9938  for (i=strat->newIdeal;i<IDELEMS(F);i++)
9939  {
9940  P->m[i-strat->newIdeal] = F->m[i];
9941  F->m[i] = NULL;
9942  }
9943  initSSpecial(F,Q,P,strat);
9944  for (i=strat->newIdeal;i<IDELEMS(F);i++)
9945  {
9946  F->m[i] = P->m[i-strat->newIdeal];
9947  P->m[i-strat->newIdeal] = NULL;
9948  }
9949  idDelete(&P);
9950  }
9951  else
9952  {
9953  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9954  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
9955  }
9956  }
9957  strat->fromT = FALSE;
9959  if ((!TEST_OPT_SB_1)
9960  || (rField_is_Ring(currRing))
9961  )
9962  {
9963  updateS(TRUE,strat);
9964  }
9965  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9966  strat->fromQ=NULL;
9967  assume(kTest_TS(strat));
9968 }
9969 
9971 {
9972  /*- release temp data -*/
9973  cleanT(strat);
9974  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
9975  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
9976  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
9977  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
9978  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
9979  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
9980  /*- set L: should be empty -*/
9981  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
9982  /*- set B: should be empty -*/
9983  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
9984  pLmFree(&strat->tail);
9985  strat->syzComp=0;
9986 }
9987 
9988 void initSbaPos (kStrategy strat)
9989 {
9991  {
9992  if (strat->honey)
9993  {
9994  strat->posInL = posInL15;
9995  // ok -- here is the deal: from my experiments for Singular-2-0
9996  // I conclude that that posInT_EcartpLength is the best of
9997  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9998  // see the table at the end of this file
9999  if (TEST_OPT_OLDSTD)
10000  strat->posInT = posInT15;
10001  else
10002  strat->posInT = posInT_EcartpLength;
10003  }
10004  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10005  {
10006  strat->posInL = posInL11;
10007  strat->posInT = posInT11;
10008  }
10009  else if (TEST_OPT_INTSTRATEGY)
10010  {
10011  strat->posInL = posInL11;
10012  strat->posInT = posInT11;
10013  }
10014  else
10015  {
10016  strat->posInL = posInL0;
10017  strat->posInT = posInT0;
10018  }
10019  //if (strat->minim>0) strat->posInL =posInLSpecial;
10020  if (strat->homog)
10021  {
10022  strat->posInL = posInL110;
10023  strat->posInT = posInT110;
10024  }
10025  }
10026  else
10027  {
10028  if (strat->homog)
10029  {
10030  strat->posInL = posInL11;
10031  strat->posInT = posInT11;
10032  }
10033  else
10034  {
10035  if ((currRing->order[0]==ringorder_c)
10036  ||(currRing->order[0]==ringorder_C))
10037  {
10038  strat->posInL = posInL17_c;
10039  strat->posInT = posInT17_c;
10040  }
10041  else
10042  {
10043  strat->posInL = posInL17;
10044  strat->posInT = posInT17;
10045  }
10046  }
10047  }
10048  if (strat->minim>0) strat->posInL =posInLSpecial;
10049  // for further tests only
10050  if ((BTEST1(11)) || (BTEST1(12)))
10051  strat->posInL = posInL11;
10052  else if ((BTEST1(13)) || (BTEST1(14)))
10053  strat->posInL = posInL13;
10054  else if ((BTEST1(15)) || (BTEST1(16)))
10055  strat->posInL = posInL15;
10056  else if ((BTEST1(17)) || (BTEST1(18)))
10057  strat->posInL = posInL17;
10058  if (BTEST1(11))
10059  strat->posInT = posInT11;
10060  else if (BTEST1(13))
10061  strat->posInT = posInT13;
10062  else if (BTEST1(15))
10063  strat->posInT = posInT15;
10064  else if ((BTEST1(17)))
10065  strat->posInT = posInT17;
10066  else if ((BTEST1(19)))
10067  strat->posInT = posInT19;
10068  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10069  strat->posInT = posInT1;
10070  if (rField_is_Ring(currRing))
10071  {
10072  strat->posInL = posInL11Ring;
10073  if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
10074  strat->posInL = posInL11Ringls;
10075  strat->posInT = posInT11;
10076  }
10077  strat->posInLDependsOnLength = FALSE;
10078  strat->posInLSba = posInLSig;
10079  //strat->posInL = posInLSig;
10080  strat->posInL = posInLF5C;
10081  /*
10082  if (rField_is_Ring(currRing))
10083  {
10084  strat->posInLSba = posInLSigRing;
10085  strat->posInL = posInL11Ring;
10086  }*/
10087  //strat->posInT = posInTSig;
10088 }
10089 
10090 void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10091 {
10092  strat->interpt = BTEST1(OPT_INTERRUPT);
10093  strat->kHEdge=NULL;
10095  /*- creating temp data structures------------------- -*/
10096  strat->cp = 0;
10097  strat->c3 = 0;
10098  strat->tail = pInit();
10099  /*- set s -*/
10100  strat->sl = -1;
10101  /*- set ps -*/
10102  strat->syzl = -1;
10103  /*- set L -*/
10104  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10105  strat->Ll = -1;
10106  strat->L = initL(strat->Lmax);
10107  /*- set B -*/
10108  strat->Bmax = setmaxL;
10109  strat->Bl = -1;
10110  strat->B = initL();
10111  /*- set T -*/
10112  strat->tl = -1;
10113  strat->tmax = setmaxT;
10114  strat->T = initT();
10115  strat->R = initR();
10116  strat->sevT = initsevT();
10117  /*- init local data struct.---------------------------------------- -*/
10118  strat->P.ecart=0;
10119  strat->P.length=0;
10121  {
10122  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
10123  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
10124  }
10126  {
10127  /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10128  }
10129  else
10130  {
10131  if(TEST_OPT_SB_1)
10132  {
10133  int i;
10134  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10135  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10136  {
10137  P->m[i-strat->newIdeal] = F->m[i];
10138  F->m[i] = NULL;
10139  }
10140  initSSpecialSba(F,Q,P,strat);
10141  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10142  {
10143  F->m[i] = P->m[i-strat->newIdeal];
10144  P->m[i-strat->newIdeal] = NULL;
10145  }
10146  idDelete(&P);
10147  }
10148  else
10149  {
10150  initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10151  }
10152  }
10153  strat->fromT = FALSE;
10154  if (!TEST_OPT_SB_1)
10155  {
10156  if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10157  }
10158  //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10159  //strat->fromQ=NULL;
10160  assume(kTest_TS(strat));
10161 }
10162 
10163 void exitSba (kStrategy strat)
10164 {
10165  /*- release temp data -*/
10167  cleanTSbaRing(strat);
10168  else
10169  cleanT(strat);
10170  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10171  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10172  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10173  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10174  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10175  omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10176  if(strat->syzmax>0)
10177  {
10178  omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10179  omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10180  if (strat->sbaOrder == 1)
10181  {
10182  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10183  }
10184  }
10185  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10186  /*- set L: should be empty -*/
10187  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10188  /*- set B: should be empty -*/
10189  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10190  /*- set sig: no need for the signatures anymore -*/
10191  omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10192  pLmDelete(&strat->tail);
10193  strat->syzComp=0;
10194 }
10195 
10196 /*2
10197 * in the case of a standardbase of a module over a qring:
10198 * replace polynomials in i by ak vectors,
10199 * (the polynomial * unit vectors gen(1)..gen(ak)
10200 * in every case (also for ideals:)
10201 * deletes divisible vectors/polynomials
10202 */
10203 void updateResult(ideal r,ideal Q, kStrategy strat)
10204 {
10205  int l;
10206  if (strat->ak>0)
10207  {
10208  for (l=IDELEMS(r)-1;l>=0;l--)
10209  {
10210  if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10211  {
10212  pDelete(&r->m[l]); // and set it to NULL
10213  }
10214  }
10215  int q;
10216  poly p;
10217  if(!rField_is_Ring(currRing))
10218  {
10219  for (l=IDELEMS(r)-1;l>=0;l--)
10220  {
10221  if ((r->m[l]!=NULL)
10222  //&& (strat->syzComp>0)
10223  //&& (pGetComp(r->m[l])<=strat->syzComp)
10224  )
10225  {
10226  for(q=IDELEMS(Q)-1; q>=0;q--)
10227  {
10228  if ((Q->m[q]!=NULL)
10229  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10230  {
10231  if (TEST_OPT_REDSB)
10232  {
10233  p=r->m[l];
10234  r->m[l]=kNF(Q,NULL,p);
10235  pDelete(&p);
10236  }
10237  else
10238  {
10239  pDelete(&r->m[l]); // and set it to NULL
10240  }
10241  break;
10242  }
10243  }
10244  }
10245  }
10246  }
10247  #ifdef HAVE_RINGS
10248  else
10249  {
10250  for (l=IDELEMS(r)-1;l>=0;l--)
10251  {
10252  if ((r->m[l]!=NULL)
10253  //&& (strat->syzComp>0)
10254  //&& (pGetComp(r->m[l])<=strat->syzComp)
10255  )
10256  {
10257  for(q=IDELEMS(Q)-1; q>=0;q--)
10258  {
10259  if ((Q->m[q]!=NULL)
10260  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10261  {
10262  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10263  {
10264  if (TEST_OPT_REDSB)
10265  {
10266  p=r->m[l];
10267  r->m[l]=kNF(Q,NULL,p);
10268  pDelete(&p);
10269  }
10270  else
10271  {
10272  pDelete(&r->m[l]); // and set it to NULL
10273  }
10274  break;
10275  }
10276  }
10277  }
10278  }
10279  }
10280  }
10281  #endif
10282  }
10283  else
10284  {
10285  int q;
10286  poly p;
10287  BOOLEAN reduction_found=FALSE;
10288  if (!rField_is_Ring(currRing))
10289  {
10290  for (l=IDELEMS(r)-1;l>=0;l--)
10291  {
10292  if (r->m[l]!=NULL)
10293  {
10294  for(q=IDELEMS(Q)-1; q>=0;q--)
10295  {
10296  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10297  {
10298  if (TEST_OPT_REDSB)
10299  {
10300  p=r->m[l];
10301  r->m[l]=kNF(Q,NULL,p);
10302  pDelete(&p);
10303  reduction_found=TRUE;
10304  }
10305  else
10306  {
10307  pDelete(&r->m[l]); // and set it to NULL
10308  }
10309  break;
10310  }
10311  }
10312  }
10313  }
10314  }
10315  #ifdef HAVE_RINGS
10316  //Also need divisibility of the leading coefficients
10317  else
10318  {
10319  for (l=IDELEMS(r)-1;l>=0;l--)
10320  {
10321  if (r->m[l]!=NULL)
10322  {
10323  for(q=IDELEMS(Q)-1; q>=0;q--)
10324  {
10325  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10326  {
10327  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10328  {
10329  if (TEST_OPT_REDSB)
10330  {
10331  p=r->m[l];
10332  r->m[l]=kNF(Q,NULL,p);
10333  pDelete(&p);
10334  reduction_found=TRUE;
10335  }
10336  else
10337  {
10338  pDelete(&r->m[l]); // and set it to NULL
10339  }
10340  break;
10341  }
10342  }
10343  }
10344  }
10345  }
10346  }
10347  #endif
10348  if (/*TEST_OPT_REDSB &&*/ reduction_found)
10349  {
10350  #ifdef HAVE_RINGS
10352  {
10353  for (l=IDELEMS(r)-1;l>=0;l--)
10354  {
10355  if (r->m[l]!=NULL)
10356  {
10357  for(q=IDELEMS(r)-1;q>=0;q--)
10358  {
10359  if ((l!=q)
10360  && (r->m[q]!=NULL)
10361  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10362  &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10363  )
10364  {
10365  //If they are equal then take the one with the smallest length
10366  if(pLmDivisibleBy(r->m[q],r->m[l])
10367  && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10368  && (pLength(r->m[q]) < pLength(r->m[l]) ||
10369  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10370  {
10371  pDelete(&r->m[l]);
10372  break;
10373  }
10374  else
10375  pDelete(&r->m[q]);
10376  }
10377  }
10378  }
10379  }
10380  }
10381  else
10382  #endif
10383  {
10384  for (l=IDELEMS(r)-1;l>=0;l--)
10385  {
10386  if (r->m[l]!=NULL)
10387  {
10388  for(q=IDELEMS(r)-1;q>=0;q--)
10389  {
10390  if ((l!=q)
10391  && (r->m[q]!=NULL)
10392  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10393  )
10394  {
10395  //If they are equal then take the one with the smallest length
10396  if(pLmDivisibleBy(r->m[q],r->m[l])
10397  &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10398  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10399  {
10400  pDelete(&r->m[l]);
10401  break;
10402  }
10403  else
10404  pDelete(&r->m[q]);
10405  }
10406  }
10407  }
10408  }
10409  }
10410  }
10411  }
10412  idSkipZeroes(r);
10413 }
10414 
10415 void completeReduce (kStrategy strat, BOOLEAN withT)
10416 {
10417  int i;
10418  int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10419  LObject L;
10420 
10421 #ifdef KDEBUG
10422  // need to set this: during tailreductions of T[i], T[i].max is out of
10423  // sync
10424  sloppy_max = TRUE;
10425 #endif
10426 
10427  strat->noTailReduction = FALSE;
10428  //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10429  if (TEST_OPT_PROT)
10430  {
10431  PrintLn();
10432 // if (timerv) writeTime("standard base computed:");
10433  }
10434  if (TEST_OPT_PROT)
10435  {
10436  Print("(S:%d)",strat->sl);mflush();
10437  }
10438  for (i=strat->sl; i>=low; i--)
10439  {
10440  int end_pos=strat->sl;
10441  if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10442  if (strat->ak==0) end_pos=i-1;
10443  TObject* T_j = strat->s_2_t(i);
10444  if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10445  {
10446  L = *T_j;
10447  #ifdef KDEBUG
10448  if (TEST_OPT_DEBUG)
10449  {
10450  Print("test S[%d]:",i);
10451  p_wrp(L.p,currRing,strat->tailRing);
10452  PrintLn();
10453  }
10454  #endif
10456  strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10457  else
10458  strat->S[i] = redtail(&L, strat->sl, strat);
10459  #ifdef KDEBUG
10460  if (TEST_OPT_DEBUG)
10461  {
10462  Print("to (tailR) S[%d]:",i);
10463  p_wrp(strat->S[i],currRing,strat->tailRing);
10464  PrintLn();
10465  }
10466  #endif
10467 
10468  if (strat->redTailChange)
10469  {
10470  if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10471  if (pNext(T_j->p) != NULL)
10472  T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10473  else
10474  T_j->max_exp = NULL;
10475  }
10477  T_j->pCleardenom();
10478  }
10479  else
10480  {
10481  assume(currRing == strat->tailRing);
10482  #ifdef KDEBUG
10483  if (TEST_OPT_DEBUG)
10484  {
10485  Print("test S[%d]:",i);
10486  p_wrp(strat->S[i],currRing,strat->tailRing);
10487  PrintLn();
10488  }
10489  #endif
10491  strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10492  else
10493  strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10495  {
10496  if (TEST_OPT_CONTENTSB)
10497  {
10498  number n;
10499  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10500  if (!nIsOne(n))
10501  {
10503  denom->n=nInvers(n);
10504  denom->next=DENOMINATOR_LIST;
10505  DENOMINATOR_LIST=denom;
10506  }
10507  nDelete(&n);
10508  }
10509  else
10510  {
10511  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10512  }
10513  }
10514  #ifdef KDEBUG
10515  if (TEST_OPT_DEBUG)
10516  {
10517  Print("to (-tailR) S[%d]:",i);
10518  p_wrp(strat->S[i],currRing,strat->tailRing);
10519  PrintLn();
10520  }
10521  #endif
10522  }
10523  if (TEST_OPT_PROT)
10524  PrintS("-");
10525  }
10526  if (TEST_OPT_PROT) PrintLn();
10527 #ifdef KDEBUG
10528  sloppy_max = FALSE;
10529 #endif
10530 }
10531 
10532 
10533 /*2
10534 * computes the new strat->kHEdge and the new pNoether,
10535 * returns TRUE, if pNoether has changed
10536 */
10538 {
10539  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10540  return FALSE;
10541  int i,j;
10542  poly newNoether;
10543 
10544 #if 0
10545  if (currRing->weight_all_1)
10546  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10547  else
10548  scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10549 #else
10550  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10551 #endif
10552  if (strat->kHEdge==NULL) return FALSE;
10553  if (strat->t_kHEdge != NULL) p_LmFree(strat->t_kHEdge, strat->tailRing);
10554  if (strat->tailRing != currRing)
10555  strat->t_kHEdge = k_LmInit_currRing_2_tailRing(strat->kHEdge, strat->tailRing);
10556  /* compare old and new noether*/
10557  newNoether = pLmInit(strat->kHEdge);
10558  pSetCoeff0(newNoether,nInit(1));
10559  j = p_FDeg(newNoether,currRing);
10560  for (i=1; i<=(currRing->N); i++)
10561  {
10562  if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
10563  }
10564  pSetm(newNoether);
10565  if (j < strat->HCord) /*- statistics -*/
10566  {
10567  if (TEST_OPT_PROT)
10568  {
10569  Print("H(%d)",j);
10570  mflush();
10571  }
10572  strat->HCord=j;
10573  #ifdef KDEBUG
10574  if (TEST_OPT_DEBUG)
10575  {
10576  Print("H(%d):",j);
10577  wrp(strat->kHEdge);
10578  PrintLn();
10579  }
10580  #endif
10581  }
10582  if (pCmp(strat->kNoether,newNoether)!=1)
10583  {
10584  if (strat->kNoether!=NULL) pLmDelete(&strat->kNoether);
10585  strat->kNoether=newNoether;
10586  if (strat->t_kNoether != NULL) p_LmFree(strat->t_kNoether, strat->tailRing);
10587  if (strat->tailRing != currRing)
10588  strat->t_kNoether = k_LmInit_currRing_2_tailRing(strat->kNoether, strat->tailRing);
10589 
10590  return TRUE;
10591  }
10592  pLmDelete(newNoether);
10593  return FALSE;
10594 }
10595 
10596 /***************************************************************
10597  *
10598  * Routines related for ring changes during std computations
10599  *
10600  ***************************************************************/
10601 BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10602 {
10603  if (strat->overflow) return FALSE;
10604  assume(L->p1 != NULL && L->p2 != NULL);
10605  // shift changes: from 0 to -1
10606  assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10607  assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10608  assume(strat->tailRing != currRing);
10609 
10610  if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10611  return FALSE;
10612  // shift changes: extra case inserted
10613  if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10614  {
10615  return TRUE;
10616  }
10617  poly p1_max=NULL;
10618  if (L->i_r1>=0) p1_max = (strat->R[L->i_r1])->max_exp;
10619  poly p2_max=NULL;
10620  if (L->i_r2>=0) p2_max = (strat->R[L->i_r2])->max_exp;
10621 
10622  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10623  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10624  {
10625  p_LmFree(m1, strat->tailRing);
10626  p_LmFree(m2, strat->tailRing);
10627  m1 = NULL;
10628  m2 = NULL;
10629  return FALSE;
10630  }
10631  return TRUE;
10632 }
10633 
10634 #ifdef HAVE_RINGS
10635 /***************************************************************
10636  *
10637  * Checks, if we can compute the gcd poly / strong pair
10638  * gcd-poly = m1 * R[atR] + m2 * S[atS]
10639  *
10640  ***************************************************************/
10641 BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10642 {
10643  assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10644  //assume(strat->tailRing != currRing);
10645 
10646  poly p1_max = (strat->R[atR])->max_exp;
10647  poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10648 
10649  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10650  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10651  {
10652  return FALSE;
10653  }
10654  return TRUE;
10655 }
10656 #endif
10657 
10658 #ifdef HAVE_RINGS
10659 /*!
10660  used for GB over ZZ: look for constant and monomial elements in the ideal
10661  background: any known constant element of ideal suppresses
10662  intermediate coefficient swell
10663 */
10664 poly preIntegerCheck(const ideal Forig, const ideal Q)
10665 {
10666  if(!nCoeff_is_Z(currRing->cf))
10667  return NULL;
10668  ideal F = idCopy(Forig);
10669  idSkipZeroes(F);
10670  poly pmon;
10671  ring origR = currRing;
10672  ideal monred = idInit(1,1);
10673  for(int i=0; i<idElem(F); i++)
10674  {
10675  if(pNext(F->m[i]) == NULL)
10676  idInsertPoly(monred, pCopy(F->m[i]));
10677  }
10678  int posconst = idPosConstant(F);
10679  if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10680  {
10681  idDelete(&F);
10682  idDelete(&monred);
10683  return NULL;
10684  }
10685  int idelemQ = 0;
10686  if(Q!=NULL)
10687  {
10688  idelemQ = IDELEMS(Q);
10689  for(int i=0; i<idelemQ; i++)
10690  {
10691  if(pNext(Q->m[i]) == NULL)
10692  idInsertPoly(monred, pCopy(Q->m[i]));
10693  }
10694  idSkipZeroes(monred);
10695  posconst = idPosConstant(monred);
10696  //the constant, if found, will be from Q
10697  if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10698  {
10699  pmon = pCopy(monred->m[posconst]);
10700  idDelete(&F);
10701  idDelete(&monred);
10702  return pmon;
10703  }
10704  }
10705  ring QQ_ring = rCopy0(currRing,FALSE);
10706  nKillChar(QQ_ring->cf);
10707  QQ_ring->cf = nInitChar(n_Q, NULL);
10708  rComplete(QQ_ring,1);
10709  QQ_ring = rAssure_c_dp(QQ_ring);
10710  rChangeCurrRing(QQ_ring);
10711  nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10712  ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10713  for(int i = 0, j = 0; i<IDELEMS(F); i++)
10714  II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10715  for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10716  II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10717  ideal one = kStd(II, NULL, isNotHomog, NULL);
10718  idSkipZeroes(one);
10719  if(idIsConstant(one))
10720  {
10721  //one should be <1>
10722  for(int i = IDELEMS(II)-1; i>=0; i--)
10723  if(II->m[i] != NULL)
10724  II->m[i+1] = II->m[i];
10725  II->m[0] = pOne();
10726  ideal syz = idSyzygies(II, isNotHomog, NULL);
10727  poly integer = NULL;
10728  for(int i = IDELEMS(syz)-1;i>=0; i--)
10729  {
10730  if(pGetComp(syz->m[i]) == 1)
10731  {
10732  pSetComp(syz->m[i],0);
10733  if(pIsConstant(pHead(syz->m[i])))
10734  {
10735  integer = pHead(syz->m[i]);
10736  break;
10737  }
10738  }
10739  }
10740  rChangeCurrRing(origR);
10741  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10742  pmon = prMapR(integer, nMap2, QQ_ring, origR);
10743  idDelete(&monred);
10744  idDelete(&F);
10745  id_Delete(&II,QQ_ring);
10746  id_Delete(&one,QQ_ring);
10747  id_Delete(&syz,QQ_ring);
10748  p_Delete(&integer,QQ_ring);
10749  rDelete(QQ_ring);
10750  return pmon;
10751  }
10752  else
10753  {
10754  if(idIs0(monred))
10755  {
10756  poly mindegmon = NULL;
10757  for(int i = 0; i<IDELEMS(one); i++)
10758  {
10759  if(pNext(one->m[i]) == NULL)
10760  {
10761  if(mindegmon == NULL)
10762  mindegmon = pCopy(one->m[i]);
10763  else
10764  {
10765  if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10766  mindegmon = pCopy(one->m[i]);
10767  }
10768  }
10769  }
10770  if(mindegmon != NULL)
10771  {
10772  for(int i = IDELEMS(II)-1; i>=0; i--)
10773  if(II->m[i] != NULL)
10774  II->m[i+1] = II->m[i];
10775  II->m[0] = pCopy(mindegmon);
10776  ideal syz = idSyzygies(II, isNotHomog, NULL);
10777  bool found = FALSE;
10778  for(int i = IDELEMS(syz)-1;i>=0; i--)
10779  {
10780  if(pGetComp(syz->m[i]) == 1)
10781  {
10782  pSetComp(syz->m[i],0);
10783  if(pIsConstant(pHead(syz->m[i])))
10784  {
10785  pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10786  found = TRUE;
10787  break;
10788  }
10789  }
10790  }
10791  id_Delete(&syz,QQ_ring);
10792  if (found == FALSE)
10793  {
10794  rChangeCurrRing(origR);
10795  idDelete(&monred);
10796  idDelete(&F);
10797  id_Delete(&II,QQ_ring);
10798  id_Delete(&one,QQ_ring);
10799  rDelete(QQ_ring);
10800  return NULL;
10801  }
10802  rChangeCurrRing(origR);
10803  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10804  pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
10805  idDelete(&monred);
10806  idDelete(&F);
10807  id_Delete(&II,QQ_ring);
10808  id_Delete(&one,QQ_ring);
10809  id_Delete(&syz,QQ_ring);
10810  rDelete(QQ_ring);
10811  return pmon;
10812  }
10813  }
10814  }
10815  rChangeCurrRing(origR);
10816  idDelete(&monred);
10817  idDelete(&F);
10818  id_Delete(&II,QQ_ring);
10819  id_Delete(&one,QQ_ring);
10820  rDelete(QQ_ring);
10821  return NULL;
10822 }
10823 #endif
10824 
10825 #ifdef HAVE_RINGS
10826 /*!
10827  used for GB over ZZ: intermediate reduction by monomial elements
10828  background: any known constant element of ideal suppresses
10829  intermediate coefficient swell
10830 */
10832 {
10833  if(!nCoeff_is_Z(currRing->cf))
10834  return;
10835  poly pH = h->GetP();
10836  poly p,pp;
10837  p = pH;
10838  bool deleted = FALSE, ok = FALSE;
10839  for(int i = 0; i<=strat->sl; i++)
10840  {
10841  p = pH;
10842  if(pNext(strat->S[i]) == NULL)
10843  {
10844  //pWrite(p);
10845  //pWrite(strat->S[i]);
10846  while(ok == FALSE && p != NULL)
10847  {
10848  if(pLmDivisibleBy(strat->S[i], p))
10849  {
10850  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10851  p_SetCoeff(p,dummy,currRing);
10852  }
10853  if(nIsZero(p->coef))
10854  {
10855  pLmDelete(&p);
10856  h->p = p;
10857  deleted = TRUE;
10858  }
10859  else
10860  {
10861  ok = TRUE;
10862  }
10863  }
10864  if (p!=NULL)
10865  {
10866  pp = pNext(p);
10867  while(pp != NULL)
10868  {
10869  if(pLmDivisibleBy(strat->S[i], pp))
10870  {
10871  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10872  p_SetCoeff(pp,dummy,currRing);
10873  if(nIsZero(pp->coef))
10874  {
10875  pLmDelete(&pNext(p));
10876  pp = pNext(p);
10877  deleted = TRUE;
10878  }
10879  else
10880  {
10881  p = pp;
10882  pp = pNext(p);
10883  }
10884  }
10885  else
10886  {
10887  p = pp;
10888  pp = pNext(p);
10889  }
10890  }
10891  }
10892  }
10893  }
10894  h->SetLmCurrRing();
10895  if((deleted)&&(h->p!=NULL))
10896  strat->initEcart(h);
10897 }
10898 
10900 {
10901  if(!nCoeff_is_Z(currRing->cf))
10902  return;
10903  poly hSig = h->sig;
10904  poly pH = h->GetP();
10905  poly p,pp;
10906  p = pH;
10907  bool deleted = FALSE, ok = FALSE;
10908  for(int i = 0; i<=strat->sl; i++)
10909  {
10910  p = pH;
10911  if(pNext(strat->S[i]) == NULL)
10912  {
10913  while(ok == FALSE && p!=NULL)
10914  {
10915  if(pLmDivisibleBy(strat->S[i], p))
10916  {
10917  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10918  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10919  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10920  {
10921  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10922  p_SetCoeff(p,dummy,currRing);
10923  }
10924  pDelete(&sigMult);
10925  }
10926  if(nIsZero(p->coef))
10927  {
10928  pLmDelete(&p);
10929  h->p = p;
10930  deleted = TRUE;
10931  }
10932  else
10933  {
10934  ok = TRUE;
10935  }
10936  }
10937  if(p == NULL)
10938  return;
10939  pp = pNext(p);
10940  while(pp != NULL)
10941  {
10942  if(pLmDivisibleBy(strat->S[i], pp))
10943  {
10944  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10945  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10946  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10947  {
10948  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10949  p_SetCoeff(pp,dummy,currRing);
10950  if(nIsZero(pp->coef))
10951  {
10952  pLmDelete(&pNext(p));
10953  pp = pNext(p);
10954  deleted = TRUE;
10955  }
10956  else
10957  {
10958  p = pp;
10959  pp = pNext(p);
10960  }
10961  }
10962  else
10963  {
10964  p = pp;
10965  pp = pNext(p);
10966  }
10967  pDelete(&sigMult);
10968  }
10969  else
10970  {
10971  p = pp;
10972  pp = pNext(p);
10973  }
10974  }
10975  }
10976  }
10977  h->SetLmCurrRing();
10978  if(deleted)
10979  strat->initEcart(h);
10980 
10981 }
10982 
10983 /*!
10984  used for GB over ZZ: final reduction by constant elements
10985  background: any known constant element of ideal suppresses
10986  intermediate coefficient swell and beautifies output
10987 */
10989 {
10990  assume(strat->tl<0); /* can only be called with no elements in T:
10991  i.e. after exitBuchMora */
10992  /* do not use strat->S, strat->sl as they may be out of sync*/
10993  if(!nCoeff_is_Z(currRing->cf))
10994  return;
10995  poly p,pp;
10996  for(int j = 0; j<IDELEMS(strat->Shdl); j++)
10997  {
10998  if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
10999  {
11000  for(int i = 0; i<IDELEMS(strat->Shdl); i++)
11001  {
11002  if((i != j) && (strat->Shdl->m[i] != NULL))
11003  {
11004  p = strat->Shdl->m[i];
11005  while((p!=NULL) && pLmDivisibleBy(strat->Shdl->m[j], p))
11006  {
11007  number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
11008  if (!nEqual(dummy,p->coef))
11009  {
11010  if (nIsZero(dummy))
11011  {
11012  nDelete(&dummy);
11013  pLmDelete(&strat->Shdl->m[i]);
11014  p=strat->Shdl->m[i];
11015  }
11016  else
11017  {
11018  p_SetCoeff(p,dummy,currRing);
11019  break;
11020  }
11021  }
11022  else
11023  {
11024  nDelete(&dummy);
11025  break;
11026  }
11027  }
11028  if (p!=NULL)
11029  {
11030  pp = pNext(p);
11031  while(pp != NULL)
11032  {
11033  if(pLmDivisibleBy(strat->Shdl->m[j], pp))
11034  {
11035  number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
11036  if (!nEqual(dummy,pp->coef))
11037  {
11038  p_SetCoeff(pp,dummy,currRing);
11039  if(nIsZero(pp->coef))
11040  {
11041  pLmDelete(&pNext(p));
11042  pp = pNext(p);
11043  }
11044  else
11045  {
11046  p = pp;
11047  pp = pNext(p);
11048  }
11049  }
11050  else
11051  {
11052  nDelete(&dummy);
11053  p = pp;
11054  pp = pNext(p);
11055  }
11056  }
11057  else
11058  {
11059  p = pp;
11060  pp = pNext(p);
11061  }
11062  }
11063  }
11064  }
11065  }
11066  //idPrint(strat->Shdl);
11067  }
11068  }
11069  idSkipZeroes(strat->Shdl);
11070 }
11071 #endif
11072 
11073 BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
11074 {
11075  assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11076  /* initial setup or extending */
11077 
11078  if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11079  if (expbound >= currRing->bitmask) return FALSE;
11080  strat->overflow=FALSE;
11081  ring new_tailRing = rModifyRing(currRing,
11082  // Hmmm .. the condition pFDeg == p_Deg
11083  // might be too strong
11084  (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11085  (strat->ak==0), // omit_comp if the input is an ideal
11086  expbound); // exp_limit
11087 
11088  if (new_tailRing == currRing) return TRUE;
11089 
11090  strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11091  strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11092 
11093  if (currRing->pFDeg != currRing->pFDegOrig)
11094  {
11095  new_tailRing->pFDeg = currRing->pFDeg;
11096  new_tailRing->pLDeg = currRing->pLDeg;
11097  }
11098 
11099  if (TEST_OPT_PROT)
11100  Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11101  kTest_TS(strat);
11102  assume(new_tailRing != strat->tailRing);
11103  pShallowCopyDeleteProc p_shallow_copy_delete
11104  = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11105 
11106  omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11107 
11108  int i;
11109  for (i=0; i<=strat->tl; i++)
11110  {
11111  strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11112  p_shallow_copy_delete);
11113  }
11114  for (i=0; i<=strat->Ll; i++)
11115  {
11116  assume(strat->L[i].p != NULL);
11117  if (pNext(strat->L[i].p) != strat->tail)
11118  strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11119  }
11120  if ((strat->P.t_p != NULL) ||
11121  ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11122  strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11123 
11124  if ((L != NULL) && (L->tailRing != new_tailRing))
11125  {
11126  if (L->i_r < 0)
11127  L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11128  else
11129  {
11130  assume(L->i_r <= strat->tl);
11131  TObject* t_l = strat->R[L->i_r];
11132  assume(t_l != NULL);
11133  L->tailRing = new_tailRing;
11134  L->p = t_l->p;
11135  L->t_p = t_l->t_p;
11136  L->max_exp = t_l->max_exp;
11137  }
11138  }
11139 
11140  if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11141  T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11142 
11143  omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11144  if (strat->tailRing != currRing)
11145  rKillModifiedRing(strat->tailRing);
11146 
11147  strat->tailRing = new_tailRing;
11148  strat->tailBin = new_tailBin;
11149  strat->p_shallow_copy_delete
11150  = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11151 
11152  if (strat->kHEdge != NULL)
11153  {
11154  if (strat->t_kHEdge != NULL)
11155  p_LmFree(strat->t_kHEdge, strat->tailRing);
11156  strat->t_kHEdge=k_LmInit_currRing_2_tailRing(strat->kHEdge, new_tailRing);
11157  }
11158 
11159  if (strat->kNoether != NULL)
11160  {
11161  if (strat->t_kNoether != NULL)
11162  p_LmFree(strat->t_kNoether, strat->tailRing);
11164  new_tailRing);
11165  }
11166  kTest_TS(strat);
11167  if (TEST_OPT_PROT)
11168  PrintS("]");
11169  return TRUE;
11170 }
11171 
11173 {
11174  unsigned long l = 0;
11175  int i;
11176  long e;
11177 
11178  assume(strat->tailRing == currRing);
11179 
11180  for (i=0; i<= strat->Ll; i++)
11181  {
11182  l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11183  }
11184  for (i=0; i<=strat->tl; i++)
11185  {
11186  // Hmm ... this we could do in one Step
11187  l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11188  }
11189  if (rField_is_Ring(currRing))
11190  {
11191  l *= 2;
11192  }
11193  e = p_GetMaxExp(l, currRing);
11194  if (e <= 1) e = 2;
11195 
11196  kStratChangeTailRing(strat, NULL, NULL, e);
11197 }
11198 
11199 ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11200 {
11201  int n = rBlocks(r); // Including trailing zero!
11202  // if sbaOrder == 1 => use (C,monomial order from r)
11203  if (strat->sbaOrder == 1)
11204  {
11205  if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11206  {
11207  return r;
11208  }
11209  ring res = rCopy0(r, TRUE, FALSE);
11210  res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11211  res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11212  res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11213  int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11214  res->wvhdl = wvhdl;
11215  for (int i=1; i<n; i++)
11216  {
11217  res->order[i] = r->order[i-1];
11218  res->block0[i] = r->block0[i-1];
11219  res->block1[i] = r->block1[i-1];
11220  res->wvhdl[i] = r->wvhdl[i-1];
11221  }
11222 
11223  // new 1st block
11224  res->order[0] = ringorder_C; // Prefix
11225  // removes useless secondary component order if defined in old ring
11226  for (int i=rBlocks(res); i>0; --i)
11227  {
11228  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11229  {
11230  res->order[i] = (rRingOrder_t)0;
11231  }
11232  }
11233  rComplete(res, 1);
11234 #ifdef HAVE_PLURAL
11235  if (rIsPluralRing(r))
11236  {
11237  if ( nc_rComplete(r, res, false) ) // no qideal!
11238  {
11239 #ifndef SING_NDEBUG
11240  WarnS("error in nc_rComplete");
11241 #endif
11242  // cleanup?
11243 
11244  // rDelete(res);
11245  // return r;
11246 
11247  // just go on..
11248  }
11249  }
11250 #endif
11251  strat->tailRing = res;
11252  return (res);
11253  }
11254  // if sbaOrder == 3 => degree - position - ring order
11255  if (strat->sbaOrder == 3)
11256  {
11257  ring res = rCopy0(r, TRUE, FALSE);
11258  res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11259  res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11260  res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11261  int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11262  res->wvhdl = wvhdl;
11263  for (int i=2; i<n+2; i++)
11264  {
11265  res->order[i] = r->order[i-2];
11266  res->block0[i] = r->block0[i-2];
11267  res->block1[i] = r->block1[i-2];
11268  res->wvhdl[i] = r->wvhdl[i-2];
11269  }
11270 
11271  // new 1st block
11272  res->order[0] = ringorder_a; // Prefix
11273  res->block0[0] = 1;
11274  res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11275  for (int i=0; i<res->N; ++i)
11276  res->wvhdl[0][i] = 1;
11277  res->block1[0] = si_min(res->N, rVar(res));
11278  // new 2nd block
11279  res->order[1] = ringorder_C; // Prefix
11280  res->wvhdl[1] = NULL;
11281  // removes useless secondary component order if defined in old ring
11282  for (int i=rBlocks(res); i>1; --i)
11283  {
11284  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11285  {
11286  res->order[i] = (rRingOrder_t)0;
11287  }
11288  }
11289  rComplete(res, 1);
11290 #ifdef HAVE_PLURAL
11291  if (rIsPluralRing(r))
11292  {
11293  if ( nc_rComplete(r, res, false) ) // no qideal!
11294  {
11295 #ifndef SING_NDEBUG
11296  WarnS("error in nc_rComplete");
11297 #endif
11298  // cleanup?
11299 
11300  // rDelete(res);
11301  // return r;
11302 
11303  // just go on..
11304  }
11305  }
11306 #endif
11307  strat->tailRing = res;
11308  return (res);
11309  }
11310 
11311  // not sbaOrder == 1 => use Schreyer order
11312  // this is done by a trick when initializing the signatures
11313  // in initSLSba():
11314  // Instead of using the signature 1e_i for F->m[i], we start
11315  // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11316  // Schreyer order w.r.t. the underlying monomial order.
11317  // => we do not need to change the underlying polynomial ring at all!
11318 
11319  // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11320 
11321  /*
11322  else
11323  {
11324  ring res = rCopy0(r, FALSE, FALSE);
11325  // Create 2 more blocks for prefix/suffix:
11326  res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11327  res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11328  res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11329  int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11330 
11331  // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11332  // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11333 
11334  // new 1st block
11335  int j = 0;
11336  res->order[j] = ringorder_IS; // Prefix
11337  res->block0[j] = res->block1[j] = 0;
11338  // wvhdl[j] = NULL;
11339  j++;
11340 
11341  for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11342  {
11343  res->order [j] = r->order [i];
11344  res->block0[j] = r->block0[i];
11345  res->block1[j] = r->block1[i];
11346 
11347  if (r->wvhdl[i] != NULL)
11348  {
11349  wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11350  } // else wvhdl[j] = NULL;
11351  }
11352 
11353  // new last block
11354  res->order [j] = ringorder_IS; // Suffix
11355  res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11356  // wvhdl[j] = NULL;
11357  j++;
11358 
11359  // res->order [j] = 0; // The End!
11360  res->wvhdl = wvhdl;
11361 
11362  // j == the last zero block now!
11363  assume(j == (n+1));
11364  assume(res->order[0]==ringorder_IS);
11365  assume(res->order[j-1]==ringorder_IS);
11366  assume(res->order[j]==0);
11367 
11368  if (complete)
11369  {
11370  rComplete(res, 1);
11371 
11372 #ifdef HAVE_PLURAL
11373  if (rIsPluralRing(r))
11374  {
11375  if ( nc_rComplete(r, res, false) ) // no qideal!
11376  {
11377  }
11378  }
11379  assume(rIsPluralRing(r) == rIsPluralRing(res));
11380 #endif
11381 
11382 
11383 #ifdef HAVE_PLURAL
11384  ring old_ring = r;
11385 
11386 #endif
11387 
11388  if (r->qideal!=NULL)
11389  {
11390  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11391 
11392  assume(idRankFreeModule(res->qideal, res) == 0);
11393 
11394 #ifdef HAVE_PLURAL
11395  if( rIsPluralRing(res) )
11396  if( nc_SetupQuotient(res, r, true) )
11397  {
11398  // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11399  }
11400 
11401 #endif
11402  assume(idRankFreeModule(res->qideal, res) == 0);
11403  }
11404 
11405 #ifdef HAVE_PLURAL
11406  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11407  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11408  assume(rIsSCA(res) == rIsSCA(old_ring));
11409  assume(ncRingType(res) == ncRingType(old_ring));
11410 #endif
11411  }
11412  strat->tailRing = res;
11413  return res;
11414  }
11415  */
11416 
11417  assume(FALSE);
11418  return(NULL);
11419 }
11420 
11422 {
11423  memset(this, 0, sizeof(skStrategy));
11424  strat_nr++;
11425  nr=strat_nr;
11426  tailRing = currRing;
11427  P.tailRing = currRing;
11428  tl = -1;
11429  sl = -1;
11430 #ifdef HAVE_LM_BIN
11431  lmBin = omGetStickyBinOfBin(currRing->PolyBin);
11432 #endif
11433 #ifdef HAVE_TAIL_BIN
11434  tailBin = omGetStickyBinOfBin(currRing->PolyBin);
11435 #endif
11436  pOrigFDeg = currRing->pFDeg;
11437  pOrigLDeg = currRing->pLDeg;
11438 }
11439 
11440 
11442 {
11443  if (lmBin != NULL)
11445  if (tailBin != NULL)// && !rField_is_Ring(currRing))
11447  (tailRing != NULL ? tailRing->PolyBin:
11448  currRing->PolyBin));
11449  if (t_kHEdge != NULL)
11451  if (t_kNoether != NULL)
11453 
11454  if (currRing != tailRing)
11457 }
11458 
11459 #if 0
11460 Timings for the different possibilities of posInT:
11461  T15 EDL DL EL L 1-2-3
11462 Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11463 Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11464 Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11465 ahml 4.48 4.03 4.03 4.38 4.96 26.50
11466 c7 15.02 13.98 15.16 13.24 17.31 47.89
11467 c8 505.09 407.46 852.76 413.21 499.19 n/a
11468 f855 12.65 9.27 14.97 8.78 14.23 33.12
11469 gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11470 gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11471 ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11472 noon8 40.68 37.02 37.99 36.82 35.59 877.16
11473 rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11474 rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11475 schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11476 test016 16.39 14.17 14.40 13.50 14.26 34.07
11477 test017 34.70 36.01 33.16 35.48 32.75 71.45
11478 test042 10.76 10.99 10.27 11.57 10.45 23.04
11479 test058 6.78 6.75 6.51 6.95 6.22 9.47
11480 test066 10.71 10.94 10.76 10.61 10.56 19.06
11481 test073 10.75 11.11 10.17 10.79 8.63 58.10
11482 test086 12.23 11.81 12.88 12.24 13.37 66.68
11483 test103 5.05 4.80 5.47 4.64 4.89 11.90
11484 test154 12.96 11.64 13.51 12.46 14.61 36.35
11485 test162 65.27 64.01 67.35 59.79 67.54 196.46
11486 test164 7.50 6.50 7.68 6.70 7.96 17.13
11487 virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11488 #endif
11489 
11490 
11491 //#ifdef HAVE_MORE_POS_IN_T
11492 #if 1
11493 // determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11494 int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p)
11495 {
11496 
11497  if (length==-1) return 0;
11498 
11499  int o = p.ecart;
11500  int op=p.GetpFDeg();
11501  int ol = p.GetpLength();
11502 
11503  if (set[length].ecart < o)
11504  return length+1;
11505  if (set[length].ecart == o)
11506  {
11507  int oo=set[length].GetpFDeg();
11508  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11509  return length+1;
11510  }
11511 
11512  int i;
11513  int an = 0;
11514  int en= length;
11515  loop
11516  {
11517  if (an >= en-1)
11518  {
11519  if (set[an].ecart > o)
11520  return an;
11521  if (set[an].ecart == o)
11522  {
11523  int oo=set[an].GetpFDeg();
11524  if((oo > op)
11525  || ((oo==op) && (set[an].pLength > ol)))
11526  return an;
11527  }
11528  return en;
11529  }
11530  i=(an+en) / 2;
11531  if (set[i].ecart > o)
11532  en=i;
11533  else if (set[i].ecart == o)
11534  {
11535  int oo=set[i].GetpFDeg();
11536  if ((oo > op)
11537  || ((oo == op) && (set[i].pLength > ol)))
11538  en=i;
11539  else
11540  an=i;
11541  }
11542  else
11543  an=i;
11544  }
11545 }
11546 
11547 // determines the position based on: 1.) FDeg 2.) pLength
11548 int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11549 {
11550 
11551  if (length==-1) return 0;
11552 
11553  int op=p.GetpFDeg();
11554  int ol = p.GetpLength();
11555 
11556  int oo=set[length].GetpFDeg();
11557  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11558  return length+1;
11559 
11560  int i;
11561  int an = 0;
11562  int en= length;
11563  loop
11564  {
11565  if (an >= en-1)
11566  {
11567  int oo=set[an].GetpFDeg();
11568  if((oo > op)
11569  || ((oo==op) && (set[an].pLength > ol)))
11570  return an;
11571  return en;
11572  }
11573  i=(an+en) / 2;
11574  int oo=set[i].GetpFDeg();
11575  if ((oo > op)
11576  || ((oo == op) && (set[i].pLength > ol)))
11577  en=i;
11578  else
11579  an=i;
11580  }
11581 }
11582 
11583 
11584 // determines the position based on: 1.) pLength
11585 int posInT_pLength(const TSet set,const int length,LObject &p)
11586 {
11587  int ol = p.GetpLength();
11588  if (length==-1)
11589  return 0;
11590  if (set[length].length<p.length)
11591  return length+1;
11592 
11593  int i;
11594  int an = 0;
11595  int en= length;
11596 
11597  loop
11598  {
11599  if (an >= en-1)
11600  {
11601  if (set[an].pLength>ol) return an;
11602  return en;
11603  }
11604  i=(an+en) / 2;
11605  if (set[i].pLength>ol) en=i;
11606  else an=i;
11607  }
11608 }
11609 #endif
11610 
11611 // kstd1.cc:
11612 int redFirst (LObject* h,kStrategy strat);
11613 int redEcart (LObject* h,kStrategy strat);
11614 void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11615 void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11616 // ../Singular/misc.cc:
11617 extern char * showOption();
11618 
11620 {
11621  PrintS("red: ");
11622  if (strat->red==redFirst) PrintS("redFirst\n");
11623  else if (strat->red==redHoney) PrintS("redHoney\n");
11624  else if (strat->red==redEcart) PrintS("redEcart\n");
11625  else if (strat->red==redHomog) PrintS("redHomog\n");
11626  else Print("%p\n",(void*)strat->red);
11627  PrintS("posInT: ");
11628  if (strat->posInT==posInT0) PrintS("posInT0\n");
11629  else if (strat->posInT==posInT1) PrintS("posInT1\n");
11630  else if (strat->posInT==posInT11) PrintS("posInT11\n");
11631  else if (strat->posInT==posInT110) PrintS("posInT110\n");
11632  else if (strat->posInT==posInT13) PrintS("posInT13\n");
11633  else if (strat->posInT==posInT15) PrintS("posInT15\n");
11634  else if (strat->posInT==posInT17) PrintS("posInT17\n");
11635  else if (strat->posInT==posInT17_c) PrintS("posInT17_c\n");
11636  else if (strat->posInT==posInT19) PrintS("posInT19\n");
11637  else if (strat->posInT==posInT2) PrintS("posInT2\n");
11638  #ifdef HAVE_RINGS
11639  else if (strat->posInT==posInT11Ring) PrintS("posInT11Ring\n");
11640  else if (strat->posInT==posInT110Ring) PrintS("posInT110Ring\n");
11641  else if (strat->posInT==posInT15Ring) PrintS("posInT15Ring\n");
11642  else if (strat->posInT==posInT17Ring) PrintS("posInT17Ring\n");
11643  else if (strat->posInT==posInT17_cRing) PrintS("posInT17_cRing\n");
11644  #endif
11645 #ifdef HAVE_MORE_POS_IN_T
11646  else if (strat->posInT==posInT_EcartFDegpLength) PrintS("posInT_EcartFDegpLength\n");
11647  else if (strat->posInT==posInT_FDegpLength) PrintS("posInT_FDegpLength\n");
11648  else if (strat->posInT==posInT_pLength) PrintS("posInT_pLength\n");
11649 #endif
11650  else if (strat->posInT==posInT_EcartpLength) PrintS("posInT_EcartpLength\n");
11651  else if (strat->posInT==posInTrg0) PrintS("posInTrg0\n");
11652  else Print("%p\n",(void*)strat->posInT);
11653  PrintS("posInL: ");
11654  if (strat->posInL==posInL0) PrintS("posInL0\n");
11655  else if (strat->posInL==posInL10) PrintS("posInL10\n");
11656  else if (strat->posInL==posInL11) PrintS("posInL11\n");
11657  else if (strat->posInL==posInL110) PrintS("posInL110\n");
11658  else if (strat->posInL==posInL13) PrintS("posInL13\n");
11659  else if (strat->posInL==posInL15) PrintS("posInL15\n");
11660  else if (strat->posInL==posInL17) PrintS("posInL17\n");
11661  else if (strat->posInL==posInL17_c) PrintS("posInL17_c\n");
11662  #ifdef HAVE_RINGS
11663  else if (strat->posInL==posInL0) PrintS("posInL0Ring\n");
11664  else if (strat->posInL==posInL11Ring) PrintS("posInL11Ring\n");
11665  else if (strat->posInL==posInL11Ringls) PrintS("posInL11Ringls\n");
11666  else if (strat->posInL==posInL110Ring) PrintS("posInL110Ring\n");
11667  else if (strat->posInL==posInL15Ring) PrintS("posInL15Ring\n");
11668  else if (strat->posInL==posInL17Ring) PrintS("posInL17Ring\n");
11669  else if (strat->posInL==posInL17_cRing) PrintS("posInL17_cRing\n");
11670  #endif
11671  else if (strat->posInL==posInLSpecial) PrintS("posInLSpecial\n");
11672  else if (strat->posInL==posInLrg0) PrintS("posInLrg0\n");
11673  else Print("%p\n",(void*)strat->posInL);
11674  PrintS("enterS: ");
11675  if (strat->enterS==enterSBba) PrintS("enterSBba\n");
11676  else if (strat->enterS==enterSMora) PrintS("enterSMora\n");
11677  else if (strat->enterS==enterSMoraNF) PrintS("enterSMoraNF\n");
11678  else Print("%p\n",(void*)strat->enterS);
11679  PrintS("initEcart: ");
11680  if (strat->initEcart==initEcartBBA) PrintS("initEcartBBA\n");
11681  else if (strat->initEcart==initEcartNormal) PrintS("initEcartNormal\n");
11682  else Print("%p\n",(void*)strat->initEcart);
11683  PrintS("initEcartPair: ");
11684  if (strat->initEcartPair==initEcartPairBba) PrintS("initEcartPairBba\n");
11685  else if (strat->initEcartPair==initEcartPairMora) PrintS("initEcartPairMora\n");
11686  else Print("%p\n",(void*)strat->initEcartPair);
11687  Print("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11688  strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11689  Print("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11690  strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11691  PrintS("chainCrit: ");
11692  if (strat->chainCrit==chainCritNormal) PrintS("chainCritNormal\n");
11693  else if (strat->chainCrit==chainCritOpt_1) PrintS("chainCritOpt_1\n");
11694  else Print("%p\n",(void*)strat->chainCrit);
11695  Print("posInLDependsOnLength=%d\n",
11696  strat->posInLDependsOnLength);
11697  PrintS(showOption());PrintLn();
11698  PrintS("LDeg: ");
11699  if (currRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11700  else if (currRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11701  else if (currRing->pLDeg==pLDegb) PrintS("pLDegb");
11702  else if (currRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11703  else if (currRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11704  else if (currRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11705  else if (currRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11706  else if (currRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11707  else if (currRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11708  else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11709  else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11710  else if (currRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11711  else Print("? (%lx)", (long)currRing->pLDeg);
11712  PrintS(" / ");
11713  if (strat->tailRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11714  else if (strat->tailRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11715  else if (strat->tailRing->pLDeg==pLDegb) PrintS("pLDegb");
11716  else if (strat->tailRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11717  else if (strat->tailRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11718  else if (strat->tailRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11719  else if (strat->tailRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11720  else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11721  else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11722  else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11723  else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11724  else if (strat->tailRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11725  else Print("? (%lx)", (long)strat->tailRing->pLDeg);
11726  PrintLn();
11727  PrintS("currRing->pFDeg: ");
11728  if (currRing->pFDeg==p_Totaldegree) PrintS("p_Totaldegree");
11729  else if (currRing->pFDeg==p_WFirstTotalDegree) PrintS("pWFirstTotalDegree");
11730  else if (currRing->pFDeg==p_Deg) PrintS("p_Deg");
11731  else if (currRing->pFDeg==kHomModDeg) PrintS("kHomModDeg");
11732  else if (currRing->pFDeg==totaldegreeWecart) PrintS("totaldegreeWecart");
11733  else if (currRing->pFDeg==p_WTotaldegree) PrintS("p_WTotaldegree");
11734  else Print("? (%lx)", (long)currRing->pFDeg);
11735  PrintLn();
11736  Print(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11737  if(TEST_OPT_DEGBOUND)
11738  Print(" degBound: %d\n", Kstd1_deg);
11739 
11740  if( ecartWeights != NULL )
11741  {
11742  PrintS("ecartWeights: ");
11743  for (int i = rVar(currRing); i > 0; i--)
11744  Print("%hd ", ecartWeights[i]);
11745  PrintLn();
11747  }
11748 
11749 #ifndef SING_NDEBUG
11751 #endif
11752 }
11753 
11754 #ifdef HAVE_SHIFTBBA
11755 poly pMove2CurrTail(poly p, kStrategy strat)
11756 {
11757  /* assume: p is completely in currRing */
11758  /* produces an object with LM in curring
11759  and TAIL in tailring */
11760  if (pNext(p)!=NULL)
11761  {
11762  pNext(p) = prMoveR(pNext(p), /* src */ currRing, /* dest */ strat->tailRing);
11763  }
11764  return(p);
11765 }
11766 #endif
11767 
11768 #ifdef HAVE_SHIFTBBA
11769 poly pMoveCurrTail2poly(poly p, kStrategy strat)
11770 {
11771  /* assume: p has LM in curring and TAIL in tailring */
11772  /* convert it to complete currRing */
11773 
11774  /* check that LM is in currRing */
11776 
11777  if (pNext(p)!=NULL)
11778  {
11779  pNext(p) = prMoveR(pNext(p), /* src */ strat->tailRing, /* dest */currRing);
11780  }
11781  return(p);
11782 }
11783 #endif
11784 
11785 #ifdef HAVE_SHIFTBBA
11787 {
11788  /* restores a poly in currRing from LObject */
11789  LObject h = H;
11790  h.Copy();
11791  poly p;
11792  if (h.p == NULL)
11793  {
11794  if (h.t_p != NULL)
11795  {
11796  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing, /* dest. ring: */ currRing);
11797  return(p);
11798  }
11799  else
11800  {
11801  /* h.tp == NULL -> the object is NULL */
11802  return(NULL);
11803  }
11804  }
11805  /* we're here if h.p != NULL */
11806  if (h.t_p == NULL)
11807  {
11808  /* then h.p is the whole poly in currRing */
11809  p = h.p;
11810  return(p);
11811  }
11812  /* we're here if h.p != NULL and h.t_p != NULL */
11813  // clean h.p, get poly from t_p
11814  pNext(h.p)=NULL;
11815  pLmDelete(&h.p);
11816  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing,
11817  /* dest. ring: */ currRing);
11818  // no need to clean h: we re-used the polys
11819  return(p);
11820 }
11821 #endif
11822 
11823 //LObject pCopyp2L(poly p, kStrategy strat)
11824 //{
11825  /* creates LObject from the poly in currRing */
11826  /* actually put p into L.p and make L.t_p=NULL : does not work */
11827 
11828 //}
11829 
11830 // poly pCopyL2p(LObject H, kStrategy strat)
11831 // {
11832 // /* restores a poly in currRing from LObject */
11833 // LObject h = H;
11834 // h.Copy();
11835 // poly p;
11836 // if (h.p == NULL)
11837 // {
11838 // if (h.t_p != NULL)
11839 // {
11840 // p = p_ShallowCopyDelete(h.t_p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
11841 // return(p);
11842 // }
11843 // else
11844 // {
11845 // /* h.tp == NULL -> the object is NULL */
11846 // return(NULL);
11847 // }
11848 // }
11849 // /* we're here if h.p != NULL */
11850 
11851 // if (h.t_p == NULL)
11852 // {
11853 // /* then h.p is the whole poly in tailRing */
11854 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
11855 // {
11856 // p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
11857 // }
11858 // return(p);
11859 // }
11860 // /* we're here if h.p != NULL and h.t_p != NULL */
11861 // p = pCopy(pHead(h.p)); // in currRing
11862 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
11863 // {
11864 // // pNext(p) = p_ShallowCopyDelete(pNext(h.t_p), (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
11865 // poly pp = p_Copy(pNext(h.p), strat->tailRing);
11866 // // poly p3 = p_Copy(pNext(h.p), currRing); // error
11867 // // p_ShallowCopyDelete(pNext(h.p), currRing, strat->tailBin); // the same as pp
11868 // poly p5 = p_ShallowCopyDelete(pNext(h.p), strat->tailRing, strat->tailBin);
11869 // pNext(p) = p_ShallowCopyDelete(h.t_p, strat->tailRing, strat->tailBin);
11870 // poly p4 = p_Copy(h.t_p, strat->tailRing);
11871 // // if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
11872 // }
11873 // // pTest(p);
11874 // return(p);
11875 // }
11876 
11877 #ifdef HAVE_SHIFTBBA
11878 /* including the self pairs */
11879 void updateSShift(kStrategy strat,int uptodeg,int lV)
11880 {
11881  /* to use after updateS(toT=FALSE,strat) */
11882  /* fills T with shifted elt's of S */
11883  int i;
11884  LObject h;
11885  int atT = -1; // or figure out smth better
11886  strat->tl = -1; // init
11887  for (i=0; i<=strat->sl; i++)
11888  {
11889  memset(&h,0,sizeof(h));
11890  h.p = strat->S[i];
11891  strat->initEcart(&h);
11892  h.sev = strat->sevS[i];
11893  h.t_p = NULL;
11894  h.GetTP(); // creates correct t_p
11895  /*puts the elements of S with their shifts to T*/
11896  // int atT, int uptodeg, int lV)
11897  strat->S_2_R[i] = strat->tl + 1; // the el't with shift 0 will be inserted first
11898  // need a small check for above; we insert >=1 elements
11899  // insert this check into kTest_TS ?
11900  enterTShift(h,strat,atT,uptodeg,lV);
11901  }
11902  /* what about setting strat->tl? */
11903 }
11904 #endif
11905 
11906 #ifdef HAVE_SHIFTBBA
11907 void initBuchMoraShift (ideal F,ideal Q,kStrategy strat)
11908 {
11909  strat->interpt = BTEST1(OPT_INTERRUPT);
11910  strat->kHEdge=NULL;
11912  /*- creating temp data structures------------------- -*/
11913  strat->cp = 0;
11914  strat->c3 = 0;
11915  strat->cv = 0;
11916  strat->tail = pInit();
11917  /*- set s -*/
11918  strat->sl = -1;
11919  /*- set L -*/
11920  strat->Lmax = setmaxL;
11921  strat->Ll = -1;
11922  strat->L = initL();
11923  /*- set B -*/
11924  strat->Bmax = setmaxL;
11925  strat->Bl = -1;
11926  strat->B = initL();
11927  /*- set T -*/
11928  strat->tl = -1;
11929  strat->tmax = setmaxT;
11930  strat->T = initT();
11931  strat->R = initR();
11932  strat->sevT = initsevT();
11933  /*- init local data struct.---------------------------------------- -*/
11934  strat->P.ecart=0;
11935  strat->P.length=0;
11937  {
11938  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
11939  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
11940  }
11942  {
11943  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
11944  }
11945  {
11946  if(TEST_OPT_SB_1)
11947  {
11948  int i;
11949  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
11950  for (i=strat->newIdeal;i<IDELEMS(F);i++)
11951  {
11952  P->m[i-strat->newIdeal] = F->m[i];
11953  F->m[i] = NULL;
11954  }
11955  initSSpecial(F,Q,P,strat);
11956  for (i=strat->newIdeal;i<IDELEMS(F);i++)
11957  {
11958  F->m[i] = P->m[i-strat->newIdeal];
11959  P->m[i-strat->newIdeal] = NULL;
11960  }
11961  idDelete(&P);
11962  }
11963  else
11964  {
11965  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
11966  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
11967  }
11968  }
11969  strat->fromT = FALSE;
11970  if (!TEST_OPT_SB_1)
11971  {
11972  /* the only change: we do not fill the set T*/
11973  if(!rField_is_Ring(currRing)) updateS(FALSE,strat);
11974  }
11975  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
11976  strat->fromQ=NULL;
11977  /* more changes: fill the set T with all the shifts of elts of S*/
11978  /* is done by other procedure */
11979 }
11980 #endif
11981 
11982 #ifdef HAVE_SHIFTBBA
11983 /*1
11984 * put the pairs (sh \dot s[i],p) into the set B, ecart=ecart(p)
11985 */
11986 static void enterOnePairManyShifts (int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
11987 {
11988  /* p comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
11989 
11992 
11993  /* cycles through all shifts of s[i] until uptodeg - lastVblock(s[i]) */
11994  /* that is create the pairs (f, s \dot g) */
11995 
11996  poly qq = strat->S[i]; // lm in currRing, tail in tailRing
11997 
11998  // poly q = pCopy(pHead(strat->S[i])); // lm in currRing
11999  // pNext(q) = prCopyR(pNext(strat->S[i]),strat->tailRing,currRing); // zero shift
12000 
12001  /* determine how many elements we have to insert for a given s[i] */
12002  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12003  /* hence, a total number of elt's to add is: */
12004  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12005  int toInsert = itoInsert(qq, uptodeg, lV, strat->tailRing);
12006 
12007 #ifdef KDEBUG
12008  if (TEST_OPT_DEBUG)
12009  {
12010  // Print("entered ManyShifts: with toInsert=%d",toInsert); PrintLn();
12011  }
12012 #endif
12013 
12014  assume(i<=strat->sl); // from OnePair
12015 
12016  /* these vars hold for all shifts of s[i] */
12017  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12018 
12019  int qfromQ;
12020  if (strat->fromQ != NULL)
12021  {
12022  qfromQ = strat->fromQ[i];
12023  }
12024  else
12025  {
12026  qfromQ = -1;
12027  }
12028 
12029  int j;
12030 
12031  poly q/*, s*/;
12032 
12033  // for the 0th shift: insert the orig. pair
12034  enterOnePairShift(qq, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, 0, i, uptodeg, lV);
12035 
12036  for (j=1; j<= toInsert; j++)
12037  {
12038  // q = pLPshift(strat->S[i],j,uptodeg,lV);
12039  q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing);
12040  // q = p_mLPshift(qq,j,uptodeg,lV,currRing); // lm in currRing, shift this monomial
12041  // s = p_LPshift(pNext(qq), j, uptodeg, lV, strat->tailRing); // from tailRing
12042  // pNext(q) = s; // in tailRing
12043  /* here we need to call enterOnePair with two polys ... */
12044 
12045 #ifdef KDEBUG
12046  //if (TEST_OPT_DEBUG)
12047  //{
12048  // PrintS("ManyShifts: calling enterOnePairShift(q,p)"); PrintLn();
12049  //}
12050 #endif
12051  //kFindInTShift(q,atR,strat);
12052  enterOnePairShift(q, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, j, i, uptodeg, lV);
12053  }
12054 }
12055 #endif
12056 
12057 #ifdef HAVE_SHIFTBBA
12058 /*1
12059 * put the pairs (sh \dot qq,p) into the set B, ecart=ecart(p)
12060 * despite the name, not only self shifts
12061 */
12062 void enterOnePairSelfShifts (poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int /*atR*/, int uptodeg, int lV)
12063 {
12064 
12065  /* format: p,qq are in LObject form: lm in CR, tail in TR */
12066  /* for true self pairs qq ==p */
12067  /* we test both qq and p */
12069  assume(p_CheckIsFromRing(pNext(qq),strat->tailRing));
12072 
12073  /* since this proc is applied twice for (h, s*g) and (g,s*h), init j with 1 only */
12074 
12075  // int j = 0;
12076  int j = 1;
12077 
12078  /* for such self pairs start with 1, not with 0 */
12079  if (qq == p) j=1;
12080 
12081  /* should cycle through all shifts of q until uptodeg - lastVblock(q) */
12082  /* that is create the pairs (f, s \dot g) */
12083 
12084  int toInsert = itoInsert(qq, uptodeg, lV, strat->tailRing);
12085 
12086 #ifdef KDEBUG
12087  //if (TEST_OPT_DEBUG)
12088  //{
12089  // Print("entered SelfShifts: with toInsert=%d",toInsert); PrintLn();
12090  //}
12091 #endif
12092 
12093  poly q;
12094 
12095  /* these vars hold for all shifts of s[i] */
12096  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12097  int qfromQ = 0; // strat->fromQ[i];
12098 
12099  for (; j<= toInsert; j++)
12100  {
12101  // q = pLPshift(strat->S[i],j,uptodeg,lV);
12102  /* we increase shifts by one; must delete q there*/
12103  // q = qq; q = pMoveCurrTail2poly(q,strat);
12104  // q = pLPshift(q,j,uptodeg,lV); //,currRing);
12105  q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing);
12106  // q = p_mLPshift(qq,j,uptodeg,lV,currRing); // lm in currRing, shift this monomial
12107  // s = p_LPshift(pNext(qq), j, uptodeg, lV, strat->tailRing); // from tailRing
12108  // pNext(q) = s; // in tailRing
12109  /* here we need to call enterOnePair with two polys ... */
12110 #ifdef KDEBUG
12111  //if (TEST_OPT_DEBUG)
12112  //{
12113  // PrintS("SelfShifts: calling enterOnePairShift(q,p)"); PrintLn();
12114  //}
12115 #endif
12116  enterOnePairShift(q, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, j, -1, uptodeg, lV);
12117  }
12118 }
12119 #endif
12120 
12121 #ifdef HAVE_SHIFTBBA
12122 /*2
12123 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12124 */
12125 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)
12126 {
12127 
12128  /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12129 
12130  /* check this Formats: */
12132  assume(p_CheckIsFromRing(pNext(q),strat->tailRing));
12135 
12136 #ifdef KDEBUG
12137 // if (TEST_OPT_DEBUG)
12138 // {
12139 // PrintS("enterOnePairShift(q,p) invoked with q = ");
12140 // wrp(q); // wrp(pHead(q));
12141 // PrintS(", p = ");
12142 // wrp(p); //wrp(pHead(p));
12143 // PrintLn();
12144 // }
12145 #endif
12146 
12147  /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12148 
12149  int qfromQ = qisFromQ;
12150 
12151  /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12152 
12153  int l,j,compare;
12154  LObject Lp;
12155  Lp.i_r = -1;
12156 
12157 #ifdef KDEBUG
12158  Lp.ecart=0; Lp.length=0;
12159 #endif
12160  /*- computes the lcm(s[i],p) -*/
12161  Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12162 
12163  /* apply the V criterion */
12164  if (!isInV(Lp.lcm, lV))
12165  {
12166 #ifdef KDEBUG
12167  if (TEST_OPT_DEBUG)
12168  {
12169  PrintS("V crit applied to q = ");
12170  wrp(q); // wrp(pHead(q));
12171  PrintS(", p = ");
12172  wrp(p); //wrp(pHead(p));
12173  PrintLn();
12174  }
12175 #endif
12176  pLmFree(Lp.lcm);
12177  /* + counter for applying the V criterion */
12178  strat->cv++;
12179  return;
12180  }
12181 
12182  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12183  {
12184  if((!((ecartq>0)&&(ecart>0)))
12185  && pHasNotCF(p,q))
12186  {
12187  /*
12188  *the product criterion has applied for (s,p),
12189  *i.e. lcm(s,p)=product of the leading terms of s and p.
12190  *Suppose (s,r) is in L and the leading term
12191  *of p divides lcm(s,r)
12192  *(==> the leading term of p divides the leading term of r)
12193  *but the leading term of s does not divide the leading term of r
12194  *(notice that this condition is automatically satisfied if r is still
12195  *in S), then (s,r) can be cancelled.
12196  *This should be done here because the
12197  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12198  *
12199  *Moreover, skipping (s,r) holds also for the noncommutative case.
12200  */
12201  strat->cp++;
12202  pLmFree(Lp.lcm);
12203  return;
12204  }
12205  else
12206  Lp.ecart = si_max(ecart,ecartq);
12207  if (strat->fromT && (ecartq>ecart))
12208  {
12209  pLmFree(Lp.lcm);
12210  return;
12211  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12212  }
12213  /*
12214  *the set B collects the pairs of type (S[j],p)
12215  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12216  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12217  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12218  */
12219  {
12220  j = strat->Bl;
12221  loop
12222  {
12223  if (j < 0) break;
12224  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12225  if ((compare==1)
12226  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12227  {
12228  strat->c3++;
12229  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12230  {
12231  pLmFree(Lp.lcm);
12232  return;
12233  }
12234  break;
12235  }
12236  else
12237  if ((compare ==-1)
12238  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12239  {
12240  deleteInL(strat->B,&strat->Bl,j,strat);
12241  strat->c3++;
12242  }
12243  j--;
12244  }
12245  }
12246  }
12247  else /*sugarcrit*/
12248  {
12249  if (ALLOW_PROD_CRIT(strat))
12250  {
12251  // if currRing->nc_type!=quasi (or skew)
12252  // TODO: enable productCrit for super commutative algebras...
12253  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12254  pHasNotCF(p,q))
12255  {
12256  /*
12257  *the product criterion has applied for (s,p),
12258  *i.e. lcm(s,p)=product of the leading terms of s and p.
12259  *Suppose (s,r) is in L and the leading term
12260  *of p devides lcm(s,r)
12261  *(==> the leading term of p devides the leading term of r)
12262  *but the leading term of s does not devide the leading term of r
12263  *(notice that tis condition is automatically satisfied if r is still
12264  *in S), then (s,r) can be canceled.
12265  *This should be done here because the
12266  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12267  */
12268  strat->cp++;
12269  pLmFree(Lp.lcm);
12270  return;
12271  }
12272  if (strat->fromT && (ecartq>ecart))
12273  {
12274  pLmFree(Lp.lcm);
12275  return;
12276  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12277  }
12278  /*
12279  *the set B collects the pairs of type (S[j],p)
12280  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12281  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12282  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12283  */
12284  for(j = strat->Bl;j>=0;j--)
12285  {
12286  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12287  if (compare==1)
12288  {
12289  strat->c3++;
12290  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12291  {
12292  pLmFree(Lp.lcm);
12293  return;
12294  }
12295  break;
12296  }
12297  else
12298  if (compare ==-1)
12299  {
12300  deleteInL(strat->B,&strat->Bl,j,strat);
12301  strat->c3++;
12302  }
12303  }
12304  }
12305  }
12306  /*
12307  *the pair (S[i],p) enters B if the spoly != 0
12308  */
12309  /*- compute the short s-polynomial -*/
12310  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12311  pNorm(p);
12312  if ((q==NULL) || (p==NULL))
12313  return;
12314  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12315  Lp.p=NULL;
12316  else
12317  {
12318 // if ( rIsPluralRing(currRing) )
12319 // {
12320 // if(pHasNotCF(p, q))
12321 // {
12322 // if(ncRingType(currRing) == nc_lie)
12323 // {
12324 // // generalized prod-crit for lie-type
12325 // strat->cp++;
12326 // Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12327 // }
12328 // else
12329 // if( ALLOW_PROD_CRIT(strat) )
12330 // {
12331 // // product criterion for homogeneous case in SCA
12332 // strat->cp++;
12333 // Lp.p = NULL;
12334 // }
12335 // else
12336 // Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12337 // }
12338 // else Lp.p = nc_CreateSpoly(q,p,currRing);
12339 // }
12340 // else
12341 // {
12342 
12343  /* ksCreateShortSpoly needs two Lobject-kind presentations */
12344  /* p is already in this form, so convert q */
12345  // q = pMove2CurrTail(q, strat);
12346  Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12347  // }
12348  }
12349  if (Lp.p == NULL)
12350  {
12351  /*- the case that the s-poly is 0 -*/
12352  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12353 // if (strat->pairtest==NULL) initPairtest(strat);
12354 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12355 // strat->pairtest[strat->sl+1] = TRUE;
12356 // new: visual check how often this happens: ! for the debug situation
12357 #ifdef KDEBUG
12358  Print("!");
12359  //if (TEST_OPT_DEBUG){Print("!");} // option teach
12360 #endif /* KDEBUG */
12361  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12362  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12363  /*
12364  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12365  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12366  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12367  *term of p devides the lcm(s,r)
12368  *(this canceling should be done here because
12369  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12370  *the first case is handeled in chainCrit
12371  */
12372  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12373  }
12374  else
12375  {
12376  /*- the pair (S[i],p) enters B -*/
12377  /* both of them should have their LM in currRing and TAIL in tailring */
12378  Lp.p1 = q; // already in the needed form
12379  Lp.p2 = p; // already in the needed form
12380 
12381  if ( !rIsPluralRing(currRing) )
12382  pNext(Lp.p) = strat->tail;
12383 
12384  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12385  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12386  if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12387  {
12388  Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12389  Lp.i_r2 = atR;
12390  }
12391  else
12392  {
12393  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12394  Lp.i_r1 = -1;
12395  Lp.i_r2 = -1;
12396  }
12397  strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12398 
12400  {
12401  if (!rIsPluralRing(currRing)
12403  && (Lp.p->coef!=NULL))
12404  nDelete(&(Lp.p->coef));
12405  }
12406 
12407  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12408  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12409  }
12410 }
12411 #endif
12412 
12413 #ifdef HAVE_SHIFTBBA
12414 /*3
12415 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12416 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12417 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
12418 */
12419 void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
12420 {
12421  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12422  // atR = -1;
12423  if ((strat->syzComp==0)
12424  || (pGetComp(h)<=strat->syzComp))
12425  {
12426  int j;
12427  BOOLEAN new_pair=FALSE;
12428 
12429  if (pGetComp(h)==0)
12430  {
12431  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12432  if ((isFromQ)&&(strat->fromQ!=NULL))
12433  {
12434  for (j=0; j<=k; j++)
12435  {
12436  if (!strat->fromQ[j])
12437  {
12438  new_pair=TRUE;
12439  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR,uptodeg,lV);
12440  // other side pairs:
12441  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12442  //Print("j:%d, Ll:%d\n",j,strat->Ll);
12443  }
12444  }
12445  }
12446  else
12447  {
12448  new_pair=TRUE;
12449  for (j=0; j<=k; j++)
12450  {
12451  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR,uptodeg,lV);
12452  // other side pairs
12453  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12454  }
12455  /* HERE we put (h, s*h) pairs */
12456  /* enterOnePairSelfShifts (poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV); */
12457  enterOnePairSelfShifts (h, h, ecart, isFromQ, strat, atR, uptodeg, lV);
12458  }
12459  }
12460  else
12461  {
12462  for (j=0; j<=k; j++)
12463  {
12464  if ((pGetComp(h)==pGetComp(strat->S[j]))
12465  || (pGetComp(strat->S[j])==0))
12466  {
12467  new_pair=TRUE;
12468  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR, uptodeg, lV);
12469  // other side pairs
12470  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12471  //Print("j:%d, Ll:%d\n",j,strat->Ll);
12472  }
12473  }
12474  /* HERE we put (h, s*h) pairs */
12475  enterOnePairSelfShifts (h, h, ecart, isFromQ, strat, atR, uptodeg, lV);
12476  }
12477 
12478  if (new_pair)
12479  {
12480  strat->chainCrit(h,ecart,strat);
12481  }
12482 
12483  }
12484 }
12485 #endif
12486 
12487 #ifdef HAVE_SHIFTBBA
12488 /*2
12489 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
12490 *superfluous elements in S will be deleted
12491 */
12492 void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR,int uptodeg, int lV)
12493 {
12494  /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12495  /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
12496  int j=pos;
12497 
12499  initenterpairsShift(h,k,ecart,0,strat, atR,uptodeg,lV);
12500  if ( (!strat->fromT)
12501  && ((strat->syzComp==0)
12502  ||(pGetComp(h)<=strat->syzComp)))
12503  {
12504  //Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
12505  unsigned long h_sev = pGetShortExpVector(h);
12506  loop
12507  {
12508  if (j > k) break;
12509  clearS(h,h_sev, &j,&k,strat);
12510  j++;
12511  }
12512  //Print("end clearS sl=%d\n",strat->sl);
12513  }
12514  // PrintS("end enterpairs\n");
12515 }
12516 #endif
12517 
12518 #ifdef HAVE_SHIFTBBA
12519 /*2
12520 * puts p to the set T, starting with the at position atT
12521 * and inserts all admissible shifts of p
12522 */
12523 void enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV)
12524 {
12525  /* determine how many elements we have to insert */
12526  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12527  /* hence, a total number of elt's to add is: */
12528  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12529 
12530  int toInsert = itoInsert(p.p, uptodeg, lV, strat->tailRing);
12531 
12532 #ifdef PDEBUG
12533  // Print("enterTShift uses toInsert: %d", toInsert); PrintLn();
12534 #endif
12535  int i;
12536 
12537  if (atT < 0)
12538  atT = strat->posInT(strat->T, strat->tl, p);
12539 
12540  /* can call enterT in a sequence, e.g. */
12541 
12542  /* shift0 = it's our model for further shifts */
12543  enterT(p,strat,atT);
12544  LObject qq;
12545  for (i=1; i<=toInsert; i++) // toIns - 1?
12546  {
12547  qq = p; //qq.Copy();
12548  qq.t_p=NULL;
12549  qq.max_exp = NULL;
12550  if (p.p!=NULL)
12551  qq.p = p_LPshift(p_Copy(p.p,currRing), i, uptodeg, lV, currRing); // direct shift
12552  qq.GetTP();
12553  // update q.sev
12554  qq.sev = pGetShortExpVector(qq.p);
12555  #ifdef KTEST
12556  kTest_T(&qq, strat->tailRing, -1, 'L');
12557  #endif
12558  /* enter it into T, first el't is with the shift 0 */
12559  // compute the position for qq
12560  atT = strat->posInT(strat->T, strat->tl, qq);
12561  enterT(qq,strat,atT);
12562  }
12563 /* Q: what to do with this one in the orig enterT ? */
12564 /* strat->R[strat->tl] = &(strat->T[atT]); */
12565 /* Solution: it is done by enterT each time separately */
12566 }
12567 #endif
12568 
12569 #ifdef HAVE_SHIFTBBA
12570 poly redtailBbaShift (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
12571 {
12572  /* for the shift case need to run it with withT = TRUE */
12573  strat->redTailChange=FALSE;
12574  if (strat->noTailReduction) return L->GetLmCurrRing();
12575  poly h, p;
12576  p = h = L->GetLmTailRing();
12577  if ((h==NULL) || (pNext(h)==NULL))
12578  return L->GetLmCurrRing();
12579 
12580  TObject* With;
12581  // placeholder in case strat->tl < 0
12582  TObject With_s(strat->tailRing);
12583 
12584  LObject Ln(pNext(h), strat->tailRing);
12585  Ln.pLength = L->GetpLength() - 1;
12586 
12587  pNext(h) = NULL;
12588  if (L->p != NULL) pNext(L->p) = NULL;
12589  L->pLength = 1;
12590 
12591  Ln.PrepareRed(strat->use_buckets);
12592 
12593  while(!Ln.IsNull())
12594  {
12595  loop
12596  {
12597  Ln.SetShortExpVector();
12598  if (withT)
12599  {
12600  int j;
12601  j = kFindDivisibleByInT(strat, &Ln);
12602  if (j < 0) break;
12603  With = &(strat->T[j]);
12604  }
12605  else
12606  {
12607  With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
12608  if (With == NULL) break;
12609  }
12610  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
12611  {
12612  With->pNorm();
12613  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
12614  }
12615  strat->redTailChange=TRUE;
12616  if (ksReducePolyTail(L, With, &Ln))
12617  {
12618  // reducing the tail would violate the exp bound
12619  // set a flag and hope for a retry (in bba)
12620  strat->completeReduce_retry=TRUE;
12621  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
12622  do
12623  {
12624  pNext(h) = Ln.LmExtractAndIter();
12625  pIter(h);
12626  L->pLength++;
12627  } while (!Ln.IsNull());
12628  goto all_done;
12629  }
12630  if (Ln.IsNull()) goto all_done;
12631  if (! withT) With_s.Init(currRing);
12632  }
12633  pNext(h) = Ln.LmExtractAndIter();
12634  pIter(h);
12635  L->pLength++;
12636  }
12637 
12638  all_done:
12639  Ln.Delete();
12640  if (L->p != NULL) pNext(L->p) = pNext(p);
12641 
12642  if (strat->redTailChange)
12643  {
12644  L->length = 0;
12645  }
12646  L->Normalize(); // HANNES: should have a test
12647  kTest_L(L);
12648  return L->GetLmCurrRing();
12649 }
12650 #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:3369
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:35
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:11172
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:138
enterpairsSig
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4801
FALSE
#define FALSE
Definition: auxiliary.h:94
chainCritRing
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:3905
posInLSig
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6039
dReportError
int dReportError(const char *fmt,...)
Definition: dError.cc:45
idCopy
ideal idCopy(ideal A)
Definition: ideals.h:60
_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:1780
skStrategy
Definition: kutil.h:266
idElem
int idElem(const ideal F)
count non-zero elements
Definition: simpleideals.cc:210
p_LmFreeAndNext
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:704
pLDeg1
long pLDeg1(poly p, int *l, const ring r)
Definition: p_polys.cc:833
omalloc.h
pLtCmpOrdSgnEqP
#define pLtCmpOrdSgnEqP(p, q)
Definition: polys.h:128
deleteHC
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:243
p_GetCoeff
#define p_GetCoeff(p, r)
Definition: monomials.h:51
pIsConstant
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:233
REGISTER
#define REGISTER
Definition: omalloc.h:22
skStrategy::fromQ
intset fromQ
Definition: kutil.h:312
initBuchMoraCrit
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9570
p_GetComp
#define p_GetComp(p, r)
Definition: monomials.h:65
enterExtendedSpolySig
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition: kutil.cc:4603
skStrategy::tail
poly tail
Definition: kutil.h:327
pLmEqual
#define pLmEqual(p1, p2)
Definition: polys.h:111
initPairtest
void initPairtest(kStrategy strat)
Definition: kutil.cc:659
enterOneZeroPairRing
void enterOneZeroPairRing(poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:4095
kutil.h
pGetComp
#define pGetComp(p)
Component.
Definition: polys.h:37
redtailBbaBound
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7511
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:470
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:5754
pNorm
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:357
TEST_OPT_INFREDTAIL
#define TEST_OPT_INFREDTAIL
Definition: options.h:116
cleanT
void cleanT(kStrategy strat)
Definition: kutil.cc:537
pRestoreDegProcs
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3600
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:236
skStrategy::enterS
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:277
TEST_OPT_PROT
#define TEST_OPT_PROT
Definition: options.h:102
kTest_LmEqual
static const char * kTest_LmEqual(poly p, poly t_p, ring tailRing)
Definition: kutil.cc:740
pLDeg0c
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:762
redEcart
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:168
pHasNotCF
#define pHasNotCF(p1, p2)
Definition: polys.h:257
k
int k
Definition: cfEzgcd.cc:92
idDelete
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
scComputeHC
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge, ring tailRing)
Definition: hdegree.cc:1005
equal
bool equal
Definition: cfModGcd.cc:4067
nCoeff_is_Z
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:838
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:70
enterT_strong
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9372
skStrategy::tmax
int tmax
Definition: kutil.h:343
TEST_OPT_REDTAIL
#define TEST_OPT_REDTAIL
Definition: options.h:115
enterOneStrongPoly
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition: kutil.cc:1496
skStrategy::cp
int cp
Definition: kutil.h:340
TObject
class sTObject TObject
Definition: kutil.h:53
ecartWeights
short * ecartWeights
Definition: weight0.c:28
ppMult_mm
#define ppMult_mm(p, m)
Definition: polys.h:196
rDebugPrint
void rDebugPrint(const ring r)
Definition: ring.cc:4016
LSet
LObject * LSet
Definition: kutil.h:56
posInL0
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5981
rField_is_Domain
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:478
pLDeg0
long pLDeg0(poly p, int *l, const ring r)
Definition: p_polys.cc:731
rChangeCurrRing
void rChangeCurrRing(ring r)
Definition: polys.cc:15
TEST_OPT_DEGBOUND
#define TEST_OPT_DEGBOUND
Definition: options.h:112
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:2243
diff
static gmp_float * diff
Definition: mpr_complex.cc:46
posInL17_c
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6830
skStrategy::P
LObject P
Definition: kutil.h:293
skStrategy::sbaOrder
unsigned sbaOrder
Definition: kutil.h:307
arriRewCriterion
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7104
isInV
int isInV(poly p, int lV)
Definition: shiftgb.cc:238
initT
KINLINE TSet initT()
Definition: kInline.h:81
polyset
poly * polyset
Definition: polys.h:254
nGreater
#define nGreater(a, b)
Definition: numbers.h:29
skStrategy::ecartS
intset ecartS
Definition: kutil.h:300
pLDeg1_Totaldegree
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:967
kTest_TS
BOOLEAN kTest_TS(kStrategy strat)
Definition: kutil.cc:1006
pGetExp
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
posInT_EcartFDegpLength
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11494
pEnlargeSet
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3647
ADDRESS
void * ADDRESS
Definition: auxiliary.h:133
redtail
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7321
posInT17
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5647
isInPairsetL
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition: kutil.cc:668
skStrategy::t_kHEdge
poly t_kHEdge
Definition: kutil.h:322
posInT110Ring
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5437
p_Mult_mm
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:998
kCheckStrongCreation
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition: kutil.cc:10641
skStrategy::chainCrit
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:282
skStrategy::R
TObject ** R
Definition: kutil.h:333
ncRingType
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:159
skStrategy::L
LSet L
Definition: kutil.h:318
skStrategy::S
polyset S
Definition: kutil.h:297
initsevT
KINLINE unsigned long * initsevT()
Definition: kInline.h:97
skStrategy::z2homog
char z2homog
Definition: kutil.h:368
isNotHomog
@ isNotHomog
Definition: structs.h:39
initBuchMoraShift
void initBuchMoraShift(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:11907
p_Neg
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1044
nEqual
#define nEqual(n1, n2)
Definition: numbers.h:21
skStrategy::lenS
intset lenS
Definition: kutil.h:310
p_SetCompP
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:255
rKillModifiedRing
void rKillModifiedRing(ring r)
Definition: ring.cc:2973
weight.h
BTEST1
#define BTEST1(a)
Definition: options.h:34
updateResult
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10203
polys.h
Compatiblity layer for legacy polynomial operations (over currRing)
kCheckSpolyCreation
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10601
superenterpairs
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4747
totaldegreeWecart
long totaldegreeWecart(poly p, ring r)
Definition: weight.cc:223
posInT110
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5395
skStrategy::tailRing
ring tailRing
Definition: kutil.h:336
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:640
redtailBba
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7397
length
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:263
ind_fact_2
long ind_fact_2(long arg)
Definition: kutil.cc:4072
p_ShallowCopyDelete
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:885
p_ExpVectorCopy
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition: p_polys.h:1250
itoInsert
int itoInsert(poly p, int uptodeg, int lV, const ring r)
Definition: shiftgb.cc:321
TEST_OPT_CONTENTSB
#define TEST_OPT_CONTENTSB
Definition: options.h:125
__p_GetComp
#define __p_GetComp(p, r)
Definition: monomials.h:64
updateS
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:8823
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:933
skStrategy::tailBin
omBin tailBin
Definition: kutil.h:338
TEST_OPT_DEBUG
#define TEST_OPT_DEBUG
Definition: options.h:107
pNeg
#define pNeg(p)
Definition: polys.h:193
p_Test
#define p_Test(p, r)
Definition: p_polys.h:164
nc_rComplete
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5538
p_wrp
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:235
skStrategy::overflow
char overflow
Definition: kutil.h:398
nInitChar
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:350
pGetShortExpVector
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl....
Definition: polys.h:152
n_Q
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:31
options.h
kFalseReturn
#define kFalseReturn(x)
Definition: kutil.cc:737
REDTAIL_CANONICALIZE
#define REDTAIL_CANONICALIZE
pp_Mult_mm
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:988
posInS
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:4951
skStrategy::~skStrategy
~skStrategy()
Definition: kutil.cc:11441
initSbaCrit
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:9634
skStrategy::sevS
unsigned long * sevS
Definition: kutil.h:313
kDebugPrint
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition: kutil.cc:11619
skStrategy::homog
char homog
Definition: kutil.h:366
pLDeg1c_WFirstTotalDegree
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1060
pDelete
#define pDelete(p_ptr)
Definition: polys.h:181
initenterzeropairsRing
void initenterzeropairsRing(poly p, int ecart, kStrategy strat, int atR)
Definition: kutil.cc:4339
N
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
pLtCmp
#define pLtCmp(p, q)
Definition: polys.h:123
posInT_EcartpLength
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5513
skStrategy::honey
char honey
Definition: kutil.h:371
posInL0Ring
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6007
deleteInSSba
void deleteInSSba(int i, kStrategy strat)
Definition: kutil.cc:1121
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:10831
idIs0
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
Definition: simpleideals.cc:768
enlargeL
static void enlargeL(LSet *L, int *length, const int incr)
Definition: kutil.cc:649
posInT_FDegpLength
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11548
loop
#define loop
Definition: structs.h:78
skStrategy::B
LSet B
Definition: kutil.h:319
skStrategy::Lmax
int Lmax
Definition: kutil.h:344
pSetComp
#define pSetComp(p, v)
Definition: polys.h:38
kTest_T
BOOLEAN kTest_T(TObject *T, ring strat_tailRing, int i, char TN)
Definition: kutil.cc:758
syzCriterion
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6961
pJet
#define pJet(p, m)
Definition: polys.h:362
TEST_OPT_REDSB
#define TEST_OPT_REDSB
Definition: options.h:103
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:1602
isInPairsetB
BOOLEAN isInPairsetB(poly q, int *k, kStrategy strat)
Definition: kutil.cc:689
initec
static intset initec(const int maxnr)
Definition: kutil.cc:502
ind2
long ind2(long arg)
Definition: kutil.cc:4060
p_LmDivisibleBy
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1821
posInSyz
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:6199
posInT17_cRing
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5815
pLDegb
long pLDegb(poly p, int *l, const ring r)
Definition: p_polys.cc:803
skStrategy::lmBin
omBin lmBin
Definition: kutil.h:337
p_LmCheckIsFromRing
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:71
enterSMoraNF
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1326
posInT19
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5881
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:42
arriRewCriterionPre
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition: kutil.cc:7129
nTest
#define nTest(a)
Definition: numbers.h:36
setmax
#define setmax
Definition: kutil.h:29
nGreaterZero
#define nGreaterZero(n)
Definition: numbers.h:28
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:489
skStrategy::t_kNoether
poly t_kNoether
Definition: kutil.h:324
ringorder_C
@ ringorder_C
Definition: ring.h:74
k_LmInit_currRing_2_tailRing
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:872
rCopy0
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1340
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:398
rGetCurrSyzLimit
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:713
skStrategy::syzidxmax
int syzidxmax
Definition: kutil.h:342
pLength
static unsigned pLength(poly a)
Definition: p_polys.h:193
rAssure_c_dp
ring rAssure_c_dp(const ring r)
Definition: ring.cc:4895
newHEdge
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10537
kMergeBintoLSba
void kMergeBintoLSba(kStrategy strat)
Definition: kutil.cc:3119
chainCritOpt_1
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3353
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:6996
p_WFirstTotalDegree
long p_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:588
p_Copy
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:813
kTest
BOOLEAN kTest(kStrategy strat)
Definition: kutil.cc:933
posInLSigRing
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6063
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:314
initEcartPairBba
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1272
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:70
denominator_list
denominator_list_s * denominator_list
Definition: kutil.h:59
posInLSpecial
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5938
ALLOW_PROD_CRIT
#define ALLOW_PROD_CRIT(A)
Definition: kutil.h:389
p_ExpVectorAdd
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1348
TRUE
#define TRUE
Definition: auxiliary.h:98
skStrategy::s_2_t
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:44
TEST_OPT_INTSTRATEGY
#define TEST_OPT_INTSTRATEGY
Definition: options.h:109
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:1200
id_Delete
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
Definition: simpleideals.cc:114
rHasLocalOrMixedOrdering
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:751
skStrategy::syz
polyset syz
Definition: kutil.h:298
pShallowCopyDelete.h
p_Sub
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1937
res
CanonicalForm res
Definition: facAbsFact.cc:64
nIsOne
#define nIsOne(n)
Definition: numbers.h:26
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:651
skStrategy::sl
int sl
Definition: kutil.h:341
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
@ nc_lie
Definition: nc.h:18
skStrategy::redTailChange
char redTailChange
Definition: kutil.h:393
kBucketDestroy
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:213
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:782
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:5052
add
static unsigned add[]
Definition: misc_ip.cc:122
skStrategy::T
TSet T
Definition: kutil.h:317
redRing
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:438
skStrategy::posInLDependsOnLength
char posInLDependsOnLength
Definition: kutil.h:383
skStrategy::syzl
int syzl
Definition: kutil.h:342
skStrategy::LazyDegree
int LazyDegree
Definition: kutil.h:346
pDivCompRing
static int pDivCompRing(poly p, poly q)
Definition: kutil.cc:147
enterSBba
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9050
posInT2
int posInT2(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5212
skStrategy::Gebauer
char Gebauer
Definition: kutil.h:372
initEcartNormal
void initEcartNormal(TObject *h)
Definition: kutil.cc:1257
PrintS
void PrintS(const char *s)
Definition: reporter.cc:284
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
TEST_OPT_NOT_SUGAR
#define TEST_OPT_NOT_SUGAR
Definition: options.h:105
skStrategy::syzIdx
intset syzIdx
Definition: kutil.h:304
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:1030
p_Cmp
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1653
strat_nr
int strat_nr
Definition: kstdfac.cc:25
pIsVector
#define pIsVector(p)
Definition: polys.h:245
kBucketInit
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:490
pLcm
#define pLcm(a, b, m)
Definition: polys.h:289
message
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7745
kbTest
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
Definition: kbuckets.cc:194
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:10988
skStrategy::LazyPass
int LazyPass
Definition: kutil.h:346
setmaxTinc
#define setmaxTinc
Definition: kutil.h:34
TEST_OPT_OLDSTD
#define TEST_OPT_OLDSTD
Definition: options.h:121
createG0
ideal createG0()
Definition: kutil.cc:4405
pDivComp_EQUAL
#define pDivComp_EQUAL
Definition: kutil.cc:138
posInT_pLength
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11585
ksReducePolyTail
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1022
skStrategy::newIdeal
int newIdeal
Definition: kutil.h:350
T
static jList * T
Definition: janet.cc:31
skStrategy::Shdl
ideal Shdl
Definition: kutil.h:294
idSkipZeroes
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
Definition: simpleideals.cc:172
rField_is_Ring
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:475
posInTrg0
int posInTrg0(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5319
completeReduce
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:10415
skStrategy::sig
polyset sig
Definition: kutil.h:299
pFalseReturn
#define pFalseReturn(cond)
Definition: monomials.h:140
denominator_list_s
Definition: kutil.h:61
posInL11Ringls
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6351
skStrategy::posInL
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:275
skStrategy::next
kStrategy next
Definition: kutil.h:268
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:12125
skStrategy::kNoetherTail
KINLINE poly kNoetherTail()
Definition: kInline.h:63
TSet
TObject * TSet
Definition: kutil.h:55
initS_2_R
static int * initS_2_R(const int maxnr)
Definition: kutil.cc:511
exitBuchMora
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:9970
enterSSba
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9153
h
static Poly * h
Definition: janet.cc:972
rIsRatGRing
static BOOLEAN rIsRatGRing(const ring r)
Definition: ring.h:419
mod2.h
sca.h
redFirst
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:530
initenterpairs
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3717
skStrategy::fromT
char fromT
Definition: kutil.h:373
max
static int max(int a, int b)
Definition: fast_mult.cc:264
skStrategy::pOrigFDeg_TailRing
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:289
posInL17Ring
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6780
initenterstrongPairsSig
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4493
initL
static LSet initL(int nr=setmaxL)
Definition: kutil.h:415
p_LmDelete
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:712
initBuchMora
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:9894
intset
int * intset
Definition: kutil.h:49
pInit
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:61
redMora
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8778
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:931
pCopyL2p
poly pCopyL2p(LObject H, kStrategy strat)
Definition: kutil.cc:11786
pOne
#define pOne()
Definition: polys.h:309
kMergeBintoL
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3098
enterSyz
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9474
posInL10
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition: kstd1.cc:1008
redtailBbaShift
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:12570
cancelunit1
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition: kutil.cc:8666
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:2158
intvec
Definition: intvec.h:21
pDivComp_GREATER
#define pDivComp_GREATER
Definition: kutil.cc:140
pLDeg1c_Totaldegree
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:997
isHomog
@ isHomog
Definition: structs.h:40
pIter
#define pIter(p)
Definition: monomials.h:38
setmaxT
#define setmaxT
Definition: kutil.h:33
pLtCmpOrdSgnDiffP
#define pLtCmpOrdSgnDiffP(p, q)
Definition: polys.h:126
p_Cleardenom
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2782
pDivComp_INCOMP
#define pDivComp_INCOMP
Definition: kutil.cc:141
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
posInL11Ring
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6281
shiftgb.h
skStrategy::rewCrit1
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:284
initenterpairsSigRing
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3842
skStrategy::sevSig
unsigned long * sevSig
Definition: kutil.h:315
skStrategy::syzmax
int syzmax
Definition: kutil.h:342
pGetShallowCopyDeleteProc
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
Definition: pShallowCopyDelete.cc:50
pLDeg1c
long pLDeg1c(poly p, int *l, const ring r)
Definition: p_polys.cc:869
p_LmExpVectorAddIsOk
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition: p_polys.h:1964
posInLF5CRing
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6315
initBuchMoraPos
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:9721
clearSbatch
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4721
sugarDivisibleBy
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition: kutil.cc:1290
p_LmCmp
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1498
enterOnePairSig
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2370
chainCritPart
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3428
p_ExpVectorSum
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1362
pp
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:248
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:1130
enterOnePairSelfShifts
void enterOnePairSelfShifts(poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int, int uptodeg, int lV)
Definition: kutil.cc:12062
kBucketClear
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:518
kFindDivisibleByInS_T
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition: kutil.cc:7179
skStrategy::lenSw
wlen_set lenSw
Definition: kutil.h:311
skStrategy::nr
int nr
Definition: kutil.h:339
posInLRing
int posInLRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6126
rBlocks
static int rBlocks(ring r)
Definition: ring.h:558
__pp_Mult_nn
#define __pp_Mult_nn(p, n, r)
Definition: p_polys.h:959
tmp1
CFList tmp1
Definition: facFqBivar.cc:70
messageStat
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7786
pLtCmpOrdSgnDiffM
#define pLtCmpOrdSgnDiffM(p, q)
Definition: polys.h:125
initSyzRules
void initSyzRules(kStrategy strat)
Definition: kutil.cc:8205
skStrategy::S_2_R
int * S_2_R
Definition: kutil.h:335
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:6695
skStrategy::kHEdgeFound
char kHEdgeFound
Definition: kutil.h:370
skStrategy::noTailReduction
char noTailReduction
Definition: kutil.h:372
pCompareChain
BOOLEAN pCompareChain(poly p, poly p1, poly p2, poly lcm, const ring R)
Returns TRUE if.
Definition: kpolys.cc:20
p_LtCmpNoAbs
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition: p_polys.h:1565
kNF
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2822
ksOldSpolyRed
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1049
pAdd
#define pAdd(p, q)
Definition: polys.h:198
pLmInit
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
pDivideM
#define pDivideM(a, b)
Definition: polys.h:288
skStrategy::news
char news
Definition: kutil.h:394
ringorder_c
@ ringorder_c
Definition: ring.h:73
skStrategy::syzComp
int syzComp
Definition: kutil.h:347
DENOMINATOR_LIST
denominator_list DENOMINATOR_LIST
Definition: kutil.cc:87
posInT13
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5484
redtailBba_Z
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7627
pMove2CurrTail
poly pMove2CurrTail(poly p, kStrategy strat)
Definition: kutil.cc:11755
enterOnePairManyShifts
static void enterOnePairManyShifts(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
Definition: kutil.cc:11986
posInL13
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6625
wlen_type
int64 wlen_type
Definition: kutil.h:50
p_LmTest
#define p_LmTest(p, r)
Definition: p_polys.h:165
kTest_L
BOOLEAN kTest_L(LObject *L, ring strat_tailRing, BOOLEAN testp, int lpos, TSet T, int tlength)
Definition: kutil.cc:871
pSetCoeff
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
kFindInT
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:704
getIndexRng
int getIndexRng(long coeff)
Definition: kutil.cc:6440
pDecrExp
#define pDecrExp(p, i)
Definition: polys.h:44
posInL110Ring
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6578
exp
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:358
skStrategy::NotUsedAxis
BOOLEAN * NotUsedAxis
Definition: kutil.h:325
enterOnePairSigRing
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2627
skStrategy::interpt
char interpt
Definition: kutil.h:365
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:320
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:10664
skStrategy::posInLSba
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:273
rDelete
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:437
skStrategy::pOrigLDeg_TailRing
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:290
kbuckets.h
p_LmFree
static void p_LmFree(poly p, ring)
Definition: p_polys.h:684
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:1879
nIsZero
#define nIsZero(n)
Definition: numbers.h:20
initSbaPos
void initSbaPos(kStrategy strat)
Definition: kutil.cc:9988
ring.h
skStrategy::cv
int cv
Definition: kutil.h:363
posInL11
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6239
p_Deg
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:579
skStrategy::sigdrop
bool sigdrop
Definition: kutil.h:353
omBin
omBin_t * omBin
Definition: omStructs.h:12
posInIdealMonFirst
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:5129
posInL17_cRing
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6894
p_Delete
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:858
initSL
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7958
p_Add_q
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:893
kstd1.h
skStrategy::Ll
int Ll
Definition: kutil.h:344
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:6736
redBba1
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8649
postReduceByMonSig
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:10899
p_One
poly p_One(const ring r)
Definition: p_polys.cc:1305
sbaCheckGcdPair
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition: kutil.cc:1624
messageSets
void messageSets(kStrategy strat)
Definition: kutil.cc:7816
enterpairsShift
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR, int uptodeg, int lV)
Definition: kutil.cc:12492
sTObject::wrp
void wrp()
Definition: kutil.cc:730
maxdegreeWecart
long maxdegreeWecart(poly p, int *l, ring r)
Definition: weight.cc:253
posInT15Ring
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5606
faugereRewCriterion
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7045
pDivComp_LESS
#define pDivComp_LESS
Definition: kutil.cc:139
setmaxL
#define setmaxL
Definition: kutil.h:30
HCord
int HCord
Definition: kutil.cc:235
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:1027
initBuchMoraPosRing
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:9807
chainCritNormal
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3140
skStrategy::c3
int c3
Definition: kutil.h:340
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:267
skStrategy::LDegLast
char LDegLast
Definition: kutil.h:379
enterSMora
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1272
skStrategy::p_shallow_copy_delete
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:331
kTest_S
BOOLEAN kTest_S(kStrategy strat)
Definition: kutil.cc:988
pLDeg1_Deg
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:902
skStrategy::sevT
unsigned long * sevT
Definition: kutil.h:316
p_CheckPolyRing
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:112
rRing_has_Comp
#define rRing_has_Comp(r)
Definition: monomials.h:267
posInL110
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6537
redBba
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8754
ringorder_a
@ ringorder_a
Definition: ring.h:71
initSLSba
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8055
Print
#define Print
Definition: emacs.cc:80
skStrategy::initEcartPair
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:278
nInvers
#define nInvers(a)
Definition: numbers.h:34
skStrategy::newt
char newt
Definition: kutil.h:395
sloppy_max
static BOOLEAN sloppy_max
Definition: kutil.cc:757
mylimits.h
initSbaBuchMora
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10090
TEST_OPT_WEIGHTM
#define TEST_OPT_WEIGHTM
Definition: options.h:119
TEST_OPT_SUGARCRIT
#define TEST_OPT_SUGARCRIT
Definition: options.h:106
cleanTSbaRing
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:590
omMergeStickyBinIntoBin
void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin)
Definition: omBin.c:396
reorderS
void reorderS(int *suc, kStrategy strat)
Definition: kutil.cc:4898
p_NSet
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1435
omSizeWOfBin
#define omSizeWOfBin(bin_ptr)
Definition: omAllocPrivate.h:100
pIsPurePower
#define pIsPurePower(p)
Definition: polys.h:243
idInit
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:37
p_SetCoeff
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:413
pp_Test
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:166
posInLF5C
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:6227
initsevS
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:507
TEST_OPT_IDLIFT
#define TEST_OPT_IDLIFT
Definition: options.h:127
pSetCoeff0
#define pSetCoeff0(p, n)
Definition: monomials.h:60
rModifyRing
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2613
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:326
showOption
char * showOption()
Definition: misc_ip.cc:728
m
int m
Definition: cfEzgcd.cc:121
skStrategy::kNoether
poly kNoether
Definition: kutil.h:321
enterOnePairRing
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:1299
skStrategy::tl
int tl
Definition: kutil.h:343
HEckeTest
void HEckeTest(poly pp, kStrategy strat)
Definition: kutil.cc:467
skStrategy::Bl
int Bl
Definition: kutil.h:345
WarnS
#define WarnS
Definition: emacs.cc:78
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:775
assume
#define assume(x)
Definition: mod2.h:390
Kstd1_mu
int Kstd1_mu
Definition: kutil.cc:237
enterpairsSpecial
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:4824
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:1167
NULL
#define NULL
Definition: omList.c:10
pLmDelete
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
posInT1
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5184
pSetm
#define pSetm(p)
Definition: polys.h:265
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:396
mflush
#define mflush()
Definition: reporter.h:57
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:146
p_SetComp
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:248
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:516
nDelete
#define nDelete(n)
Definition: numbers.h:17
posInLrg0
int posInLrg0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6453
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:69
p_WTotaldegree
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:605
omRealloc0Size
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221
skStrategy::rewCrit3
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:286
kBucket
Definition: kbuckets.h:179
R
#define R
Definition: sirandom.c:26
initSSpecialSba
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8504
posInT11Ring
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5278
kPosInLDependsOnLength
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition: kutil.cc:9705
skStrategy::completeReduce_retry
char completeReduce_retry
Definition: kutil.h:397
TEST_OPT_SB_1
#define TEST_OPT_SB_1
Definition: options.h:117
p_Setm
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:234
LObject
class sLObject LObject
Definition: kutil.h:54
skStrategy::ak
int ak
Definition: kutil.h:346
posInL15
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6660
TEST_OPT_CANCELUNIT
#define TEST_OPT_CANCELUNIT
Definition: options.h:126
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:12419
pLmDivisibleBy
#define pLmDivisibleBy(a, b)
like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
Definition: polys.h:140
pSetExp
#define pSetExp(p, i, v)
Definition: polys.h:42
updateSShift
void updateSShift(kStrategy strat, int uptodeg, int lV)
Definition: kutil.cc:11879
initenterstrongPairs
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4471
denominator_list_s::next
denominator_list next
Definition: kutil.h:61
cancelunit
void cancelunit(LObject *L, BOOLEAN inNF)
Definition: kutil.cc:332
pDivComp
static int pDivComp(poly p, poly q)
Definition: kutil.cc:186
p_Totaldegree
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1444
skStrategy::pOrigFDeg
pFDegProc pOrigFDeg
Definition: kutil.h:287
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:4424
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:45
enterOneStrongPolySig
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1682
posInT17Ring
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5708
messageStatSBA
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:7798
enterL
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1233
r_assume
#define r_assume(x)
Definition: mod2.h:391
deleteInL
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1176
skStrategy::initEcart
void(* initEcart)(TObject *L)
Definition: kutil.h:271
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:748
nInit
#define nInit(i)
Definition: numbers.h:25
pLmCmp
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:105
initSSpecial
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8360
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:269
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:2141
kHomModDeg
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2074
initEcartBBA
void initEcartBBA(TObject *h)
Definition: kutil.cc:1265
enterpairs
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4775
pCopy
#define pCopy(p)
return a copy of the poly
Definition: polys.h:180
skStrategy::nrsyzcrit
int nrsyzcrit
Definition: kutil.h:354
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:272
pNormalize
#define pNormalize(p)
Definition: polys.h:311
posInT15
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5552
skStrategy::currIdx
int currIdx
Definition: kutil.h:308
initenterpairsSig
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3782
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:2087
p_ISet
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1289
sTObject::tailRing
ring tailRing
Definition: kutil.h:72
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:5173
p_Mult_q
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1051
deleteInS
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1069
kDeleteLcm
static void kDeleteLcm(LObject *P)
Definition: kutil.h:844
pHead
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL
Definition: polys.h:67
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:974
initEcartPairMora
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1279
skStrategy::sugarCrit
char sugarCrit
Definition: kutil.h:371
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:45
tmp2
CFList tmp2
Definition: facFqBivar.cc:70
redFirstShift
int redFirstShift(LObject *h, kStrategy strat)
Definition: kstd2.cc:4234
denominator_list_s::n
number n
Definition: kutil.h:61
skStrategy::minim
int minim
Definition: kutil.h:351
enterOnePairNormal
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:1877
PrintLn
void PrintLn()
Definition: reporter.cc:310
skStrategy::use_buckets
char use_buckets
Definition: kutil.h:377
skStrategy::Bmax
int Bmax
Definition: kutil.h:345
sbaRing
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11199
rIsSCA
static bool rIsSCA(const ring r)
Definition: nc.h:190
kStratChangeTailRing
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11073
p_GetShortExpVector
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4679
initR
KINLINE TObject ** initR()
Definition: kInline.h:92
p_LPshift
poly p_LPshift(poly p, int sh, int uptodeg, int lV, const ring r)
Definition: shiftgb.cc:74
omGetStickyBinOfBin
omBin omGetStickyBinOfBin(omBin bin)
Definition: omBin.c:373
skStrategy::syzCrit
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.h:283
omCheckBinAddrSize
#define omCheckBinAddrSize(addr, size)
Definition: omAllocDecl.h:326
p_FDeg
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:381
skStrategy::skStrategy
skStrategy()
Definition: kutil.cc:11421
kCreateZeroPoly
poly kCreateZeroPoly(long exp[], long cabsind, poly *t_p, ring leadRing, ring tailRing)
Definition: kutil.cc:4276
ratgring.h
enterExtendedSpoly
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4520
initHilbCrit
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9552
exitSba
void exitSba(kStrategy strat)
Definition: kutil.cc:10163
index
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
redHoney
int redHoney(LObject *h, kStrategy strat)
Definition: kstd2.cc:1387
nCopy
#define nCopy(n)
Definition: numbers.h:16
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:69
skStrategy::HCord
int HCord
Definition: kutil.h:348
numbers.h
pNext
#define pNext(p)
Definition: monomials.h:37
superenterpairsSig
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4757
enterT
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9291
setmaxLinc
#define setmaxLinc
Definition: kutil.h:31
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:211
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:1855
OPT_INTERRUPT
#define OPT_INTERRUPT
Definition: options.h:78
pCmp
#define pCmp(p1, p2)
pCmp: args may be NULL returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
Definition: polys.h:115
enterTShift
void enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV)
Definition: kutil.cc:12523
posInT11
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5242
twoPow
long twoPow(long arg)
Definition: kutil.cc:4087
enterOnePairSpecial
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3029
nKillChar
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:511
idIsConstant
#define idIsConstant(I)
Definition: ideals.h:40
skStrategy::enterOnePair
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.h:281
idPosConstant
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition: ideals.h:37
redHomog
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:545
pMoveCurrTail2poly
poly pMoveCurrTail2poly(poly p, kStrategy strat)
Definition: kutil.cc:11769
skStrategy::nrrewcrit
int nrrewcrit
Definition: kutil.h:355
initS
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7864
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:4210
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:3369
pWrite
void pWrite(poly p)
Definition: polys.h:302
omReallocSize
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
wrp
void wrp(poly p)
Definition: polys.h:304
p_Cleardenom_n
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2891
skStrategy::pOrigLDeg
pLDegProc pOrigLDeg
Definition: kutil.h:288
p_CheckIsFromRing
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:102