My Project
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 // define if enterL, enterT should use memmove instead of doing it manually
45 // on topgun, this is slightly faster (see monodromy_l.tst, homog_gonnet.sing)
46 #ifndef SunOS_4
47 #define ENTER_USE_MEMMOVE
48 #endif
49 
50 // define, if the my_memmove inlines should be used instead of
51 // system memmove -- it does not seem to pay off, though
52 // #define ENTER_USE_MYMEMMOVE
53 
54 #include "kernel/GBEngine/kutil.h"
55 #include "polys/kbuckets.h"
56 #include "coeffs/numbers.h"
57 #include "kernel/polys.h"
58 #include "polys/monomials/ring.h"
59 #include "kernel/ideals.h"
61 #include "kernel/GBEngine/kstd1.h"
63 
64 #ifdef HAVE_SHIFTBBA
65 #include "polys/shiftop.h"
66 #endif
67 
68 #include "polys/prCopy.h"
69 
70 #ifdef HAVE_RATGRING
72 #endif
73 
74 #ifdef KDEBUG
75 #undef KDEBUG
76 #define KDEBUG 2
77 #endif
78 
79 #ifdef DEBUGF5
80 #undef DEBUGF5
81 #define DEBUGF5 2
82 #endif
83 
85 
86 
87 #ifdef ENTER_USE_MYMEMMOVE
88 inline void _my_memmove_d_gt_s(unsigned long* d, unsigned long* s, long l)
89 {
90  REGISTER unsigned long* _dl = (unsigned long*) d;
91  REGISTER unsigned long* _sl = (unsigned long*) s;
92  REGISTER long _i = l - 1;
93 
94  do
95  {
96  _dl[_i] = _sl[_i];
97  _i--;
98  }
99  while (_i >= 0);
100 }
101 
102 inline void _my_memmove_d_lt_s(unsigned long* d, unsigned long* s, long l)
103 {
104  REGISTER long _ll = l;
105  REGISTER unsigned long* _dl = (unsigned long*) d;
106  REGISTER unsigned long* _sl = (unsigned long*) s;
107  REGISTER long _i = 0;
108 
109  do
110  {
111  _dl[_i] = _sl[_i];
112  _i++;
113  }
114  while (_i < _ll);
115 }
116 
117 inline void _my_memmove(void* d, void* s, long l)
118 {
119  unsigned long _d = (unsigned long) d;
120  unsigned long _s = (unsigned long) s;
121  unsigned long _l = ((l) + SIZEOF_LONG - 1) >> LOG_SIZEOF_LONG;
122 
123  if (_d > _s) _my_memmove_d_gt_s(_d, _s, _l);
124  else _my_memmove_d_lt_s(_d, _s, _l);
125 }
126 
127 #undef memmove
128 #define memmove(d,s,l) _my_memmove(d, s, l)
129 #endif
130 
131 static poly redMora (poly h,int maxIndex,kStrategy strat);
132 static poly redBba (poly h,int maxIndex,kStrategy strat);
133 
134 #ifdef HAVE_RINGS
135 #define pDivComp_EQUAL 2
136 #define pDivComp_LESS 1
137 #define pDivComp_GREATER -1
138 #define pDivComp_INCOMP 0
139 /* Checks the relation of LM(p) and LM(q)
140  LM(p) = LM(q) => return pDivComp_EQUAL
141  LM(p) | LM(q) => return pDivComp_LESS
142  LM(q) | LM(p) => return pDivComp_GREATER
143  else return pDivComp_INCOMP */
144 static inline int pDivCompRing(poly p, poly q)
145 {
146  if ((currRing->pCompIndex < 0)
148  {
149  BOOLEAN a=FALSE, b=FALSE;
150  int i;
151  unsigned long la, lb;
152  unsigned long divmask = currRing->divmask;
153  for (i=0; i<currRing->VarL_Size; i++)
154  {
155  la = p->exp[currRing->VarL_Offset[i]];
156  lb = q->exp[currRing->VarL_Offset[i]];
157  if (la != lb)
158  {
159  if (la < lb)
160  {
161  if (b) return pDivComp_INCOMP;
162  if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
163  return pDivComp_INCOMP;
164  a = TRUE;
165  }
166  else
167  {
168  if (a) return pDivComp_INCOMP;
169  if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
170  return pDivComp_INCOMP;
171  b = TRUE;
172  }
173  }
174  }
175  if (a) return pDivComp_LESS;
176  if (b) return pDivComp_GREATER;
177  if (!a & !b) return pDivComp_EQUAL;
178  }
179  return pDivComp_INCOMP;
180 }
181 #endif
182 
183 static inline int pDivComp(poly p, poly q)
184 {
185  if ((currRing->pCompIndex < 0)
187  {
188 #ifdef HAVE_RATGRING
189  if (rIsRatGRing(currRing))
190  {
192  q,currRing,
193  currRing->real_var_start, currRing->real_var_end))
194  return 0;
195  return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
196  }
197 #endif
198  BOOLEAN a=FALSE, b=FALSE;
199  int i;
200  unsigned long la, lb;
201  unsigned long divmask = currRing->divmask;
202  for (i=0; i<currRing->VarL_Size; i++)
203  {
204  la = p->exp[currRing->VarL_Offset[i]];
205  lb = q->exp[currRing->VarL_Offset[i]];
206  if (la != lb)
207  {
208  if (la < lb)
209  {
210  if (b) return 0;
211  if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
212  return 0;
213  a = TRUE;
214  }
215  else
216  {
217  if (a) return 0;
218  if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
219  return 0;
220  b = TRUE;
221  }
222  }
223  }
224  if (a) { /*assume(pLmCmp(q,p)==1);*/ return 1; }
225  if (b) { /*assume(pLmCmp(q,p)==-1);*/return -1; }
226  /*assume(pLmCmp(q,p)==0);*/
227  }
228  return 0;
229 }
230 
231 #ifdef HAVE_SHIFTBBA
232 static inline int pLPDivComp(poly p, poly q)
233 {
234  if ((currRing->pCompIndex < 0) || (__p_GetComp(p,currRing) == __p_GetComp(q,currRing)))
235  {
236  // maybe there is a more performant way to do this? This will get called quite often in bba.
237  if (_p_LPLmDivisibleByNoComp(p, q, currRing)) return 1;
238  if (_p_LPLmDivisibleByNoComp(q, p, currRing)) return -1;
239  }
240 
241  return 0;
242 }
243 #endif
244 
245 
246 VAR int HCord;
248 VAR int Kstd1_mu=32000;
249 
250 /*2
251 *deletes higher monomial of p, re-compute ecart and length
252 *works only for orderings with ecart =pFDeg(end)-pFDeg(start)
253 */
254 void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
255 {
256  if (strat->kHEdgeFound)
257  {
258  kTest_L(L,strat->tailRing);
259  poly p1;
260  poly p = L->GetLmTailRing();
261  int l = 1;
262  kBucket_pt bucket = NULL;
263  if (L->bucket != NULL)
264  {
265  kBucketClear(L->bucket, &pNext(p), &L->pLength);
266  L->pLength++;
267  bucket = L->bucket;
268  L->bucket = NULL;
269  }
270 
271  if (!fromNext && p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
272  {
273  L->Delete();
274  L->Clear();
275  L->ecart = -1;
276  if (bucket != NULL) kBucketDestroy(&bucket);
277  return;
278  }
279  p1 = p;
280  while (pNext(p1)!=NULL)
281  {
282  if (p_LmCmp(pNext(p1), strat->kNoetherTail(), L->tailRing) == -1)
283  {
284  p_Delete(&pNext(p1), L->tailRing);
285  if (p1 == p)
286  {
287  if (L->t_p != NULL)
288  {
289  assume(L->p != NULL && p == L->t_p);
290  pNext(L->p) = NULL;
291  }
292  L->max_exp = NULL;
293  }
294  else if (fromNext)
295  L->max_exp = p_GetMaxExpP(pNext(L->p), L->tailRing ); // p1;
296  //if (L->pLength != 0)
297  L->pLength = l;
298  // Hmmm when called from updateT, then only
299  // reset ecart when cut
300  if (fromNext)
301  L->ecart = L->pLDeg() - L->GetpFDeg();
302  break;
303  }
304  l++;
305  pIter(p1);
306  }
307  if (! fromNext)
308  {
309  L->SetpFDeg();
310  L->ecart = L->pLDeg(strat->LDegLast) - L->GetpFDeg();
311  }
312  if (bucket != NULL)
313  {
314  if (L->pLength > 1)
315  {
316  kBucketInit(bucket, pNext(p), L->pLength - 1);
317  pNext(p) = NULL;
318  if (L->t_p != NULL) pNext(L->t_p) = NULL;
319  L->pLength = 0;
320  L->bucket = bucket;
321  }
322  else
323  kBucketDestroy(&bucket);
324  }
325  kTest_L(L,strat->tailRing);
326  }
327 }
328 
329 void deleteHC(poly* p, int* e, int* l,kStrategy strat)
330 {
331  LObject L(*p, currRing, strat->tailRing);
332 
333  deleteHC(&L, strat);
334  *p = L.p;
335  *e = L.ecart;
336  *l = L.length;
337  if (L.t_p != NULL) p_LmFree(L.t_p, strat->tailRing);
338 }
339 
340 /*2
341 *tests if p.p=monomial*unit and cancels the unit
342 */
343 void cancelunit (LObject* L,BOOLEAN inNF)
344 {
345  if(rHasGlobalOrdering (currRing)) return;
346  if(TEST_OPT_CANCELUNIT) return;
347 
348  ring r = L->tailRing;
349  poly p = L->GetLmTailRing();
350  if(p_GetComp(p, r) != 0 && !p_OneComp(p, r)) return;
351 
352  number lc=NULL; /*dummy, is always set if rField_is_Ring(r) */
353  if (rField_is_Ring(r) /*&& (rHasLocalOrMixedOrdering(r))*/)
354  lc = pGetCoeff(p);
355 
356  // Leading coef have to be a unit
357  // example 2x+4x2 should be simplified to 2x*(1+2x)
358  // and 2 is not a unit in Z
359  //if ( !(n_IsUnit(pGetCoeff(p), r->cf)) ) return;
360 
361 // for(i=r->N;i>0;i--)
362 // {
363 // if ((p_GetExp(p,i,r)>0) && (rIsPolyVar(i, r)==TRUE)) return;
364 // }
365  poly h = pNext(p);
366  int i;
367 
369  {
370  loop
371  {
372  if (h==NULL)
373  {
374  p_Delete(&pNext(p), r);
375  if (!inNF)
376  {
377  number eins= nCopy(lc);
378  if (L->p != NULL)
379  {
380  pSetCoeff(L->p,eins);
381  if (L->t_p != NULL)
382  pSetCoeff0(L->t_p,eins);
383  }
384  else
385  pSetCoeff(L->t_p,eins);
386  /* p and t_p share the same coeff, if both are !=NULL */
387  /* p==NULL==t_p cannot happen here */
388  }
389  L->ecart = 0;
390  L->length = 1;
391  //if (L->pLength > 0)
392  L->pLength = 1;
393  L->max_exp = NULL;
394 
395  if (L->t_p != NULL && pNext(L->t_p) != NULL)
396  p_Delete(&pNext(L->t_p),r);
397  if (L->p != NULL && pNext(L->p) != NULL)
398  pNext(L->p) = NULL;
399  return;
400  }
401  i = rVar(r);
402  loop
403  {
404  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
405  i--;
406  if (i == 0) break; // does divide, try next monom
407  }
408  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
409  // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
410  // domains), no zerodivisor test needed CAUTION
411  if (!n_DivBy(pGetCoeff(h),lc,r->cf))
412  {
413  return;
414  }
415  pIter(h);
416  }
417  }
418  else
419  {
420  loop
421  {
422  if (h==NULL)
423  {
424  p_Delete(&pNext(p), r);
425  if (!inNF)
426  {
427  number eins=nInit(1);
428  if (L->p != NULL)
429  {
430  pSetCoeff(L->p,eins);
431  if (L->t_p != NULL)
432  pSetCoeff0(L->t_p,eins);
433  }
434  else
435  pSetCoeff(L->t_p,eins);
436  /* p and t_p share the same coeff, if both are !=NULL */
437  /* p==NULL==t_p cannot happen here */
438  }
439  L->ecart = 0;
440  L->length = 1;
441  //if (L->pLength > 0)
442  L->pLength = 1;
443  L->max_exp = NULL;
444 
445  if (L->t_p != NULL && pNext(L->t_p) != NULL)
446  p_Delete(&pNext(L->t_p),r);
447  if (L->p != NULL && pNext(L->p) != NULL)
448  pNext(L->p) = NULL;
449 
450  return;
451  }
452  i = rVar(r);
453  loop
454  {
455  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
456  i--;
457  if (i == 0) break; // does divide, try next monom
458  }
459  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
460  pIter(h);
461  }
462  }
463 }
464 
465 /*2
466 *pp is the new element in s
467 *returns TRUE (in strat->kHEdgeFound) if
468 *-HEcke is allowed
469 *-we are in the last componente of the vector
470 *-on all axis are monomials (all elements in NotUsedAxis are FALSE)
471 *returns FALSE for pLexOrderings,
472 *assumes in module case an ordering of type c* !!
473 * HEckeTest is only called with strat->kHEdgeFound==FALSE !
474 */
475 void HEckeTest (poly pp,kStrategy strat)
476 {
477  int j,/*k,*/p;
478 
479  strat->kHEdgeFound=FALSE;
480  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
481  {
482  return;
483  }
484  if (strat->ak > 1) /*we are in the module case*/
485  {
486  return; // until ....
487  //if (!pVectorOut) /*pVectorOut <=> order = c,* */
488  // return FALSE;
489  //if (pGetComp(pp) < strat->ak) /* ak is the number of the last component */
490  // return FALSE;
491  }
492  // k = 0;
493  p=pIsPurePower(pp);
494  if (rField_is_Ring(currRing) && (!n_IsUnit(pGetCoeff(pp),currRing->cf))) return;
495  if (p!=0) strat->NotUsedAxis[p] = FALSE;
496  /*- the leading term of pp is a power of the p-th variable -*/
497  for (j=(currRing->N);j>0; j--)
498  {
499  if (strat->NotUsedAxis[j])
500  {
501  return;
502  }
503  }
504  strat->kHEdgeFound=TRUE;
505 }
506 
507 /*2
508 *utilities for TSet, LSet
509 */
510 inline static intset initec (const int maxnr)
511 {
512  return (intset)omAlloc(maxnr*sizeof(int));
513 }
514 
515 inline static unsigned long* initsevS (const int maxnr)
516 {
517  return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
518 }
519 inline static int* initS_2_R (const int maxnr)
520 {
521  return (int*)omAlloc0(maxnr*sizeof(int));
522 }
523 
524 static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
525  int &length, const int incr)
526 {
527  assume(T!=NULL);
528  assume(sevT!=NULL);
529  assume(R!=NULL);
530  assume((length+incr) > 0);
531 
532  int i;
533  T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
534  (length+incr)*sizeof(TObject));
535 
536  sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
537  (length+incr)*sizeof(long*));
538 
539  R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
540  (length+incr)*sizeof(TObject*));
541  for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
542  length += incr;
543 }
544 
545 void cleanT (kStrategy strat)
546 {
547  int i,j;
548  poly p;
549  assume(currRing == strat->tailRing || strat->tailRing != NULL);
550 
551  pShallowCopyDeleteProc p_shallow_copy_delete =
552  (strat->tailRing != currRing ?
554  NULL);
555  for (j=0; j<=strat->tl; j++)
556  {
557  p = strat->T[j].p;
558  strat->T[j].p=NULL;
559  if (strat->T[j].max_exp != NULL)
560  {
561  p_LmFree(strat->T[j].max_exp, strat->tailRing);
562  }
563  i = -1;
564  loop
565  {
566  i++;
567  if (i>strat->sl)
568  {
569  if (strat->T[j].t_p != NULL)
570  {
571  p_Delete(&(strat->T[j].t_p), strat->tailRing);
572  p_LmFree(p, currRing);
573  }
574  else
575  {
576 #ifdef HAVE_SHIFTBBA
577  if (currRing->isLPring && strat->T[j].shift > 0)
578  {
579  pNext(p) = NULL; // pNext(p) points to the unshifted tail, don't try to delete it here
580  }
581 #endif
582  pDelete(&p);
583  }
584  break;
585  }
586  if (p == strat->S[i])
587  {
588  if (strat->T[j].t_p != NULL)
589  {
590  if (p_shallow_copy_delete!=NULL)
591  {
592  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
593  currRing->PolyBin);
594  }
595  p_LmFree(strat->T[j].t_p, strat->tailRing);
596  }
597  break;
598  }
599  }
600  }
601  strat->tl=-1;
602 }
603 
605 {
606  int i,j;
607  poly p;
608  assume(currRing == strat->tailRing || strat->tailRing != NULL);
609 
610  pShallowCopyDeleteProc p_shallow_copy_delete =
611  (strat->tailRing != currRing ?
613  NULL);
614  for (j=0; j<=strat->tl; j++)
615  {
616  p = strat->T[j].p;
617  strat->T[j].p=NULL;
618  if (strat->T[j].max_exp != NULL)
619  {
620  p_LmFree(strat->T[j].max_exp, strat->tailRing);
621  }
622  i = -1;
623  loop
624  {
625  i++;
626  if (i>strat->sl)
627  {
628  if (strat->T[j].t_p != NULL)
629  {
630  p_Delete(&(strat->T[j].t_p), strat->tailRing);
631  p_LmFree(p, currRing);
632  }
633  else
634  {
635  //pDelete(&p);
636  p = NULL;
637  }
638  break;
639  }
640  if (p == strat->S[i])
641  {
642  if (strat->T[j].t_p != NULL)
643  {
644  assume(p_shallow_copy_delete != NULL);
645  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
646  currRing->PolyBin);
647  p_LmFree(strat->T[j].t_p, strat->tailRing);
648  }
649  break;
650  }
651  }
652  }
653  strat->tl=-1;
654 }
655 
656 //LSet initL ()
657 //{
658 // int i;
659 // LSet l = (LSet)omAlloc(setmaxL*sizeof(LObject));
660 // return l;
661 //}
662 
663 static inline void enlargeL (LSet* L,int* length,const int incr)
664 {
665  assume((*L)!=NULL);
666  assume(((*length)+incr)>0);
667 
668  *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
669  ((*length)+incr)*sizeof(LObject));
670  (*length) += incr;
671 }
672 
674 {
675  strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
676 }
677 
678 /*2
679 *test whether (p1,p2) or (p2,p1) is in L up position length
680 *it returns TRUE if yes and the position k
681 */
682 BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
683 {
684  LObject *p=&(strat->L[length]);
685 
686  *k = length;
687  loop
688  {
689  if ((*k) < 0) return FALSE;
690  if (((p1 == (*p).p1) && (p2 == (*p).p2))
691  || ((p1 == (*p).p2) && (p2 == (*p).p1)))
692  return TRUE;
693  (*k)--;
694  p--;
695  }
696 }
697 
698 /*2
699 *in B all pairs have the same element p on the right
700 *it tests whether (q,p) is in B and returns TRUE if yes
701 *and the position k
702 */
703 BOOLEAN isInPairsetB(poly q,int* k,kStrategy strat)
704 {
705  LObject *p=&(strat->B[strat->Bl]);
706 
707  *k = strat->Bl;
708  loop
709  {
710  if ((*k) < 0) return FALSE;
711  if (q == (*p).p1)
712  return TRUE;
713  (*k)--;
714  p--;
715  }
716 }
717 
718 int kFindInT(poly p, TSet T, int tlength)
719 {
720  int i;
721 
722  for (i=0; i<=tlength; i++)
723  {
724  if (T[i].p == p) return i;
725  }
726  return -1;
727 }
728 
729 int kFindInT(poly p, kStrategy strat)
730 {
731  int i;
732  do
733  {
734  i = kFindInT(p, strat->T, strat->tl);
735  if (i >= 0) return i;
736  strat = strat->next;
737  }
738  while (strat != NULL);
739  return -1;
740 }
741 
742 #ifdef HAVE_SHIFTBBA
743 int kFindInTShift(poly p, TSet T, int tlength)
744 {
745  int i;
746 
747  for (i=0; i<=tlength; i++)
748  {
749  // in the Letterplace ring the LMs in T and L are copies thus we have to use pEqualPolys() instead of ==
750  if (pEqualPolys(T[i].p, p)) return i;
751  }
752  return -1;
753 }
754 #endif
755 
756 #ifdef HAVE_SHIFTBBA
757 int kFindInTShift(poly p, kStrategy strat)
758 {
759  int i;
760  do
761  {
762  i = kFindInTShift(p, strat->T, strat->tl);
763  if (i >= 0) return i;
764  strat = strat->next;
765  }
766  while (strat != NULL);
767  return -1;
768 }
769 #endif
770 
771 #ifdef KDEBUG
772 
774 {
775  if (t_p != NULL) p_wrp(t_p, tailRing);
776  else if (p != NULL) p_wrp(p, currRing, tailRing);
777  else ::wrp(NULL);
778 }
779 
780 #define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
781 
782 // check that Lm's of a poly from T are "equal"
783 static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
784 {
785  int i;
786  for (i=1; i<=tailRing->N; i++)
787  {
788  if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
789  return "Lm[i] different";
790  }
791  if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
792  return "Lm[0] different";
793  if (pNext(p) != pNext(t_p))
794  return "Lm.next different";
795  if (pGetCoeff(p) != pGetCoeff(t_p))
796  return "Lm.coeff different";
797  return NULL;
798 }
799 
801 BOOLEAN kTest_T(TObject * T, ring strat_tailRing, int i, char TN)
802 {
803  ring tailRing = T->tailRing;
804  if (strat_tailRing == NULL) strat_tailRing = tailRing;
805  r_assume(strat_tailRing == tailRing);
806 
807  poly p = T->p;
808  // ring r = currRing;
809 
810  if (T->p == NULL && T->t_p == NULL && i >= 0)
811  return dReportError("%c[%d].poly is NULL", TN, i);
812 
813  if (T->p!=NULL)
814  {
815  nTest(pGetCoeff(T->p));
816  if ((T->t_p==NULL)&&(pNext(T->p)!=NULL)) p_Test(pNext(T->p),currRing);
817  }
818  if (T->t_p!=NULL)
819  {
820  nTest(pGetCoeff(T->t_p));
821  if (pNext(T->t_p)!=NULL) p_Test(pNext(T->t_p),strat_tailRing);
822  }
823  if ((T->p!=NULL)&&(T->t_p!=NULL)) assume(pGetCoeff(T->p)==pGetCoeff(T->t_p));
824 
825  if (T->tailRing != currRing)
826  {
827  if (T->t_p == NULL && i > 0)
828  return dReportError("%c[%d].t_p is NULL", TN, i);
829  pFalseReturn(p_Test(T->t_p, T->tailRing));
830  if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
831  if (T->p != NULL && T->t_p != NULL)
832  {
833  const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
834  if (msg != NULL)
835  return dReportError("%c[%d] %s", TN, i, msg);
836  // r = T->tailRing;
837  p = T->t_p;
838  }
839  if (T->p == NULL)
840  {
841  p = T->t_p;
842  // r = T->tailRing;
843  }
844  if (T->t_p != NULL && i >= 0 && TN == 'T')
845  {
846  if (pNext(T->t_p) == NULL)
847  {
848  if (T->max_exp != NULL)
849  return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
850  }
851  else
852  {
853  if (T->max_exp == NULL)
854  return dReportError("%c[%d].max_exp is NULL", TN, i);
855  if (pNext(T->max_exp) != NULL)
856  return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
857 
858  pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
859  omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
860 #if KDEBUG > 0
861  if (! sloppy_max)
862  {
863  poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
864  p_Setm(T->max_exp, tailRing);
865  p_Setm(test_max, tailRing);
866  BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
867  if (! equal)
868  return dReportError("%c[%d].max out of sync", TN, i);
869  p_LmFree(test_max, tailRing);
870  }
871 #endif
872  }
873  }
874  }
875  else
876  {
877  if (T->p == NULL && i > 0)
878  return dReportError("%c[%d].p is NULL", TN, i);
879 #ifdef HAVE_SHIFTBBA
880  if (currRing->isLPring && T->shift > 0)
881  {
882  // in this case, the order is not correct. test LM and tail separately
885  }
886  else
887 #endif
888  {
890  }
891  }
892 
893  if ((i >= 0) && (T->pLength != 0)
894  && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
895  {
896  int l=T->pLength;
897  T->pLength=pLength(p);
898  return dReportError("%c[%d] pLength error: has %d, specified to have %d",
899  TN, i , pLength(p), l);
900  }
901 
902  // check FDeg, for elements in L and T
903  if (i >= 0 && (TN == 'T' || TN == 'L'))
904  {
905  // FDeg has ir element from T of L set
906  if (T->FDeg != T->pFDeg())
907  {
908  int d=T->FDeg;
909  T->FDeg=T->pFDeg();
910  return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
911  TN, i , T->pFDeg(), d);
912  }
913  }
914 
915  // check is_normalized for elements in T
916  if (i >= 0 && TN == 'T')
917  {
918  if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
919  return dReportError("T[%d] is_normalized error", i);
920 
921  }
922  return TRUE;
923 }
924 
925 BOOLEAN kTest_L(LObject *L, ring strat_tailRing,
926  BOOLEAN testp, int lpos, TSet T, int tlength)
927 {
928  if (L->p!=NULL)
929  {
930  if ((L->t_p==NULL)
931  &&(pNext(L->p)!=NULL)
932  &&(pGetCoeff(pNext(L->p))!=NULL)) /* !=strat->tail*/
933  {
934  p_Test(pNext(L->p),currRing);
935  nTest(pGetCoeff(L->p));
936  }
937  }
938  if (L->t_p!=NULL)
939  {
940  if ((pNext(L->t_p)!=NULL)
941  &&(pGetCoeff(pNext(L->t_p))!=NULL)) /* !=strat->tail*/
942  {
943  p_Test(pNext(L->t_p),strat_tailRing);
944  nTest(pGetCoeff(L->t_p));
945  }
946  }
947  if ((L->p!=NULL)&&(L->t_p!=NULL)) assume(pGetCoeff(L->p)==pGetCoeff(L->t_p));
948 
949  if (testp)
950  {
951  poly pn = NULL;
952  if (L->bucket != NULL)
953  {
954  kFalseReturn(kbTest(L->bucket));
955  r_assume(L->bucket->bucket_ring == L->tailRing);
956  if (L->p != NULL && pNext(L->p) != NULL)
957  {
958  pn = pNext(L->p);
959  pNext(L->p) = NULL;
960  }
961  }
962  kFalseReturn(kTest_T(L, strat_tailRing, lpos, 'L'));
963  if (pn != NULL)
964  pNext(L->p) = pn;
965 
966  ring r;
967  poly p;
968  L->GetLm(p, r);
969  if (L->sev != 0L)
970  {
971  if (p_GetShortExpVector(p, r) != L->sev)
972  {
973  return dReportError("L[%d] wrong sev: has %lo, specified to have %lo",
974  lpos, p_GetShortExpVector(p, r), L->sev);
975  }
976  }
977  }
978  if (L->p1 == NULL)
979  {
980  // L->p2 either NULL or "normal" poly
981  pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
982  }
983  else if (tlength > 0 && T != NULL && (lpos >=0))
984  {
985  // now p1 and p2 must be != NULL and must be contained in T
986  int i;
987 #ifdef HAVE_SHIFTBBA
988  if (rIsLPRing(currRing))
989  i = kFindInTShift(L->p1, T, tlength);
990  else
991 #endif
992  i = kFindInT(L->p1, T, tlength);
993  if (i < 0)
994  return dReportError("L[%d].p1 not in T",lpos);
995 #ifdef HAVE_SHIFTBBA
996  if (rIsLPRing(currRing))
997  {
998  if (rField_is_Ring(currRing)) return TRUE; // m*shift(q) is not in T
999  i = kFindInTShift(L->p2, T, tlength);
1000  }
1001  else
1002 #endif
1003  i = kFindInT(L->p2, T, tlength);
1004  if (i < 0)
1005  return dReportError("L[%d].p2 not in T",lpos);
1006  }
1007  return TRUE;
1008 }
1009 
1011 {
1012  int i;
1013  // test P
1014  kFalseReturn(kTest_L(&(strat->P), strat->tailRing,
1015  (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
1016  -1, strat->T, strat->tl));
1017 
1018  // test T
1019  if (strat->T != NULL)
1020  {
1021  for (i=0; i<=strat->tl; i++)
1022  {
1023  kFalseReturn(kTest_T(&(strat->T[i]), strat->tailRing, i, 'T'));
1024  if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
1025  return dReportError("strat->sevT[%d] out of sync", i);
1026  }
1027  }
1028 
1029  // test L
1030  if (strat->L != NULL)
1031  {
1032  for (i=0; i<=strat->Ll; i++)
1033  {
1034  kFalseReturn(kTest_L(&(strat->L[i]), strat->tailRing,
1035  strat->L[i].Next() != strat->tail, i,
1036  strat->T, strat->tl));
1037  // may be unused
1038  //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
1039  // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
1040  //{
1041  // assume(strat->L[i].bucket != NULL);
1042  //}
1043  }
1044  }
1045 
1046  // test S
1047  if (strat->S != NULL)
1048  kFalseReturn(kTest_S(strat));
1049 
1050  return TRUE;
1051 }
1052 
1054 {
1055  int i;
1056  BOOLEAN ret = TRUE;
1057  for (i=0; i<=strat->sl; i++)
1058  {
1059  if (strat->S[i] != NULL &&
1060  strat->sevS[i] != pGetShortExpVector(strat->S[i]))
1061  {
1062  return dReportError("S[%d] wrong sev: has %o, specified to have %o",
1063  i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
1064  }
1065  }
1066  return ret;
1067 }
1068 
1069 
1070 
1072 {
1073  int i, j;
1074  // BOOLEAN ret = TRUE;
1075  kFalseReturn(kTest(strat));
1076 
1077  // test strat->R, strat->T[i].i_r
1078  for (i=0; i<=strat->tl; i++)
1079  {
1080  if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1081  return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1082  strat->T[i].i_r);
1083  if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1084  return dReportError("T[%d].i_r with R out of sync", i);
1085  }
1086  // test containment of S inT
1087  if ((strat->S != NULL)&&(strat->tl>=0))
1088  {
1089  for (i=0; i<=strat->sl; i++)
1090  {
1091  j = kFindInT(strat->S[i], strat->T, strat->tl);
1092  if (j < 0)
1093  return dReportError("S[%d] not in T", i);
1094  if (strat->S_2_R[i] != strat->T[j].i_r)
1095  return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1096  i, strat->S_2_R[i], j, strat->T[j].i_r);
1097  }
1098  }
1099  // test strat->L[i].i_r1
1100  #ifdef HAVE_SHIFTBBA
1101  if (!rIsLPRing(currRing)) // in the Letterplace ring we currently don't set/use i_r1 and i_r2
1102  #endif
1103  if (strat->L!=NULL)
1104  {
1105  for (i=0; i<=strat->Ll; i++)
1106  {
1107  if (strat->L[i].p1 != NULL && strat->L[i].p2)
1108  {
1109  if (strat->L[i].i_r1 < 0 ||
1110  strat->L[i].i_r1 > strat->tl ||
1111  strat->L[i].T_1(strat)->p != strat->L[i].p1)
1112  return dReportError("L[%d].i_r1 out of sync", i);
1113  if (strat->L[i].i_r2 < 0 ||
1114  strat->L[i].i_r2 > strat->tl ||
1115  strat->L[i].T_2(strat)->p != strat->L[i].p2)
1116  return dReportError("L[%d].i_r2 out of sync", i);
1117  }
1118  else
1119  {
1120  if (strat->L[i].i_r1 != -1)
1121  return dReportError("L[%d].i_r1 out of sync", i);
1122  if (strat->L[i].i_r2 != -1)
1123  return dReportError("L[%d].i_r2 out of sync", i);
1124  }
1125  if (strat->L[i].i_r != -1)
1126  return dReportError("L[%d].i_r out of sync", i);
1127  }
1128  }
1129  return TRUE;
1130 }
1131 
1132 #endif // KDEBUG
1133 
1134 /*2
1135 *cancels the i-th polynomial in the standardbase s
1136 */
1137 void deleteInS (int i,kStrategy strat)
1138 {
1139 #ifdef ENTER_USE_MEMMOVE
1140  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1141  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1142  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1143  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1144 #else
1145  int j;
1146  for (j=i; j<strat->sl; j++)
1147  {
1148  strat->S[j] = strat->S[j+1];
1149  strat->ecartS[j] = strat->ecartS[j+1];
1150  strat->sevS[j] = strat->sevS[j+1];
1151  strat->S_2_R[j] = strat->S_2_R[j+1];
1152  }
1153 #endif
1154  if (strat->lenS!=NULL)
1155  {
1156 #ifdef ENTER_USE_MEMMOVE
1157  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1158 #else
1159  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1160 #endif
1161  }
1162  if (strat->lenSw!=NULL)
1163  {
1164 #ifdef ENTER_USE_MEMMOVE
1165  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1166 #else
1167  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1168 #endif
1169  }
1170  if (strat->fromQ!=NULL)
1171  {
1172 #ifdef ENTER_USE_MEMMOVE
1173  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1174 #else
1175  for (j=i; j<strat->sl; j++)
1176  {
1177  strat->fromQ[j] = strat->fromQ[j+1];
1178  }
1179 #endif
1180  }
1181  strat->S[strat->sl] = NULL;
1182  strat->sl--;
1183 }
1184 
1185 
1186 /*2
1187 *cancels the i-th polynomial in the standardbase s
1188 */
1189 void deleteInSSba (int i,kStrategy strat)
1190 {
1191 #ifdef ENTER_USE_MEMMOVE
1192  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1193  memmove(&(strat->sig[i]), &(strat->sig[i+1]), (strat->sl - i)*sizeof(poly));
1194  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1195  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1196  memmove(&(strat->sevSig[i]),&(strat->sevSig[i+1]),(strat->sl - i)*sizeof(unsigned long));
1197  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1198 #else
1199  int j;
1200  for (j=i; j<strat->sl; j++)
1201  {
1202  strat->S[j] = strat->S[j+1];
1203  strat->sig[j] = strat->sig[j+1];
1204  strat->ecartS[j] = strat->ecartS[j+1];
1205  strat->sevS[j] = strat->sevS[j+1];
1206  strat->sevSig[j] = strat->sevSig[j+1];
1207  strat->S_2_R[j] = strat->S_2_R[j+1];
1208  }
1209 #endif
1210  if (strat->lenS!=NULL)
1211  {
1212 #ifdef ENTER_USE_MEMMOVE
1213  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1214 #else
1215  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1216 #endif
1217  }
1218  if (strat->lenSw!=NULL)
1219  {
1220 #ifdef ENTER_USE_MEMMOVE
1221  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1222 #else
1223  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1224 #endif
1225  }
1226  if (strat->fromQ!=NULL)
1227  {
1228 #ifdef ENTER_USE_MEMMOVE
1229  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1230 #else
1231  for (j=i; j<strat->sl; j++)
1232  {
1233  strat->fromQ[j] = strat->fromQ[j+1];
1234  }
1235 #endif
1236  }
1237  strat->S[strat->sl] = NULL;
1238  strat->sl--;
1239 }
1240 
1241 /*2
1242 *cancels the j-th polynomial in the set
1243 */
1244 void deleteInL (LSet set, int *length, int j,kStrategy strat)
1245 {
1246  if (set[j].lcm!=NULL)
1247  {
1248  kDeleteLcm(&set[j]);
1249  }
1250  if (set[j].sig!=NULL)
1251  {
1252 #ifdef HAVE_RINGS
1253  if (pGetCoeff(set[j].sig) != NULL)
1254  pLmDelete(set[j].sig);
1255  else
1256 #endif
1257  pLmFree(set[j].sig);
1258  }
1259  if (set[j].p!=NULL)
1260  {
1261  if (pNext(set[j].p) == strat->tail)
1262  {
1263 #ifdef HAVE_RINGS
1264  if (pGetCoeff(set[j].p) != NULL)
1265  pLmDelete(set[j].p);
1266  else
1267 #endif
1268  pLmFree(set[j].p);
1269  /*- tail belongs to several int spolys -*/
1270  }
1271  else
1272  {
1273  // search p in T, if it is there, do not delete it
1274  if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1275  {
1276  // assure that for global orderings kFindInT fails
1277  //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1278  set[j].Delete();
1279  }
1280  }
1281  }
1282  if (*length > 0 && j < *length)
1283  {
1284 #ifdef ENTER_USE_MEMMOVE
1285  memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1286 #else
1287  int i;
1288  for (i=j; i < (*length); i++)
1289  set[i] = set[i+1];
1290 #endif
1291  }
1292 #ifdef KDEBUG
1293  memset(&(set[*length]),0,sizeof(LObject));
1294 #endif
1295  (*length)--;
1296 }
1297 
1298 /*2
1299 *enters p at position at in L
1300 */
1301 void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1302 {
1303  // this should be corrected
1304  assume(p.FDeg == p.pFDeg());
1305 
1306  if ((*length)>=0)
1307  {
1308  if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1309  if (at <= (*length))
1310 #ifdef ENTER_USE_MEMMOVE
1311  memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1312 #else
1313  for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1314 #endif
1315  }
1316  else at = 0;
1317  (*set)[at] = p;
1318  (*length)++;
1319 }
1320 
1321 /*2
1322 * computes the normal ecart;
1323 * used in mora case and if pLexOrder & sugar in bba case
1324 */
1326 {
1327  h->FDeg = h->pFDeg();
1328  h->ecart = h->pLDeg() - h->FDeg;
1329  // h->length is set by h->pLDeg
1330  h->length=h->pLength=pLength(h->p);
1331 }
1332 
1334 {
1335  h->FDeg = h->pFDeg();
1336  (*h).ecart = 0;
1337  h->length=h->pLength=pLength(h->p);
1338 }
1339 
1340 void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1341 {
1342  Lp->FDeg = Lp->pFDeg();
1343  (*Lp).ecart = 0;
1344  (*Lp).length = 0;
1345 }
1346 
1347 void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1348 {
1349  Lp->FDeg = Lp->pFDeg();
1350  (*Lp).ecart = si_max(ecartF,ecartG);
1351  (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1352  (*Lp).length = 0;
1353 }
1354 
1355 /*2
1356 *if ecart1<=ecart2 it returns TRUE
1357 */
1358 static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1359 {
1360  return (ecart1 <= ecart2);
1361 }
1362 
1363 #ifdef HAVE_RINGS
1364 /*2
1365 * put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1366 */
1367 static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1368 {
1369  assume(atR >= 0);
1370  assume(i<=strat->sl);
1371  assume(p!=NULL);
1373  #if ALL_VS_JUST
1374  //Over rings, if we construct the strong pair, do not add the spair
1376  {
1377  number s,t,d;
1378  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1379 
1380  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1381  {
1382  nDelete(&d);
1383  nDelete(&s);
1384  nDelete(&t);
1385  return;
1386  }
1387  nDelete(&d);
1388  nDelete(&s);
1389  nDelete(&t);
1390  }
1391  #endif
1392  int j,compare,compareCoeff;
1393  LObject h;
1394 
1395 #ifdef KDEBUG
1396  h.ecart=0; h.length=0;
1397 #endif
1398  /*- computes the lcm(s[i],p) -*/
1399  if(pHasNotCFRing(p,strat->S[i]))
1400  {
1401  strat->cp++;
1402  return;
1403  }
1404  h.lcm = p_Lcm(p,strat->S[i],currRing);
1405  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1406  if (nIsZero(pGetCoeff(h.lcm)))
1407  {
1408  strat->cp++;
1409  pLmDelete(h.lcm);
1410  return;
1411  }
1412  // basic chain criterion
1413  /*
1414  *the set B collects the pairs of type (S[j],p)
1415  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1416  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
1417  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
1418  */
1419 
1420  for(j = strat->Bl;j>=0;j--)
1421  {
1422  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1423  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1424  if(compare == pDivComp_EQUAL)
1425  {
1426  //They have the same LM
1427  if(compareCoeff == pDivComp_LESS)
1428  {
1429  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1430  {
1431  strat->c3++;
1432  pLmDelete(h.lcm);
1433  return;
1434  }
1435  break;
1436  }
1437  if(compareCoeff == pDivComp_GREATER)
1438  {
1439  deleteInL(strat->B,&strat->Bl,j,strat);
1440  strat->c3++;
1441  }
1442  if(compareCoeff == pDivComp_EQUAL)
1443  {
1444  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1445  {
1446  strat->c3++;
1447  pLmDelete(h.lcm);
1448  return;
1449  }
1450  break;
1451  }
1452  }
1453  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1454  {
1455  if(compare == pDivComp_LESS)
1456  {
1457  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1458  {
1459  strat->c3++;
1460  pLmDelete(h.lcm);
1461  return;
1462  }
1463  break;
1464  }
1465  if(compare == pDivComp_GREATER)
1466  {
1467  deleteInL(strat->B,&strat->Bl,j,strat);
1468  strat->c3++;
1469  }
1470  }
1471  }
1472  number s, t;
1473  poly m1, m2, gcd = NULL;
1474  s = pGetCoeff(strat->S[i]);
1475  t = pGetCoeff(p);
1476  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1477  ksCheckCoeff(&s, &t, currRing->cf);
1478  pSetCoeff0(m1, s);
1479  pSetCoeff0(m2, t);
1480  m2 = pNeg(m2);
1481  p_Test(m1,strat->tailRing);
1482  p_Test(m2,strat->tailRing);
1483  poly si = pCopy(strat->S[i]);
1484  poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1485  poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1486  pDelete(&si);
1487  p_LmDelete(m1, currRing);
1488  p_LmDelete(m2, currRing);
1489  if(sim2 == NULL)
1490  {
1491  if(pm1 == NULL)
1492  {
1493  if(h.lcm != NULL)
1494  {
1495  pLmDelete(h.lcm);
1496  h.lcm=NULL;
1497  }
1498  h.Clear();
1499  if (strat->pairtest==NULL) initPairtest(strat);
1500  strat->pairtest[i] = TRUE;
1501  strat->pairtest[strat->sl+1] = TRUE;
1502  return;
1503  }
1504  else
1505  {
1506  gcd = pm1;
1507  pm1 = NULL;
1508  }
1509  }
1510  else
1511  {
1512  if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1513  {
1514  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1515  pSetmComp(sim2);
1516  }
1517  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1518  gcd = p_Add_q(pm1, sim2, strat->tailRing);
1519  }
1520  p_Test(gcd, strat->tailRing);
1521 #ifdef KDEBUG
1522  if (TEST_OPT_DEBUG)
1523  {
1524  wrp(gcd);
1525  PrintLn();
1526  }
1527 #endif
1528  h.p = gcd;
1529  h.i_r = -1;
1530  if(h.p == NULL)
1531  {
1532  if (strat->pairtest==NULL) initPairtest(strat);
1533  strat->pairtest[i] = TRUE;
1534  strat->pairtest[strat->sl+1] = TRUE;
1535  return;
1536  }
1537  h.tailRing = strat->tailRing;
1538  int posx;
1539  //h.pCleardenom();
1540  //pSetm(h.p);
1541  h.i_r1 = -1;h.i_r2 = -1;
1542  strat->initEcart(&h);
1543  #if 1
1544  h.p2 = strat->S[i];
1545  h.p1 = p;
1546  #endif
1547  #if 1
1548  if (atR >= 0)
1549  {
1550  h.i_r1 = atR;
1551  h.i_r2 = strat->S_2_R[i];
1552  }
1553  #endif
1554  if (strat->Bl==-1)
1555  posx =0;
1556  else
1557  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1558  h.sev = pGetShortExpVector(h.p);
1559  if (currRing!=strat->tailRing)
1560  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1561  if (strat->P.p!=NULL) strat->P.sev = pGetShortExpVector(strat->P.p);
1562  else strat->P.sev=0L;
1563  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1564  kTest_TS(strat);
1565 }
1566 
1567 /*2
1568 * put the lcm(s[i],p) into the set B
1569 */
1570 
1571 static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1572 {
1573  number d, s, t;
1574  assume(atR >= 0);
1576  poly m1, m2, gcd,si;
1577  if(!enterTstrong)
1578  {
1579  assume(i<=strat->sl);
1580  si = strat->S[i];
1581  }
1582  else
1583  {
1584  assume(i<=strat->tl);
1585  si = strat->T[i].p;
1586  }
1587  //printf("\n--------------------------------\n");
1588  //pWrite(p);pWrite(si);
1589  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1590 
1591  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1592  {
1593  nDelete(&d);
1594  nDelete(&s);
1595  nDelete(&t);
1596  return FALSE;
1597  }
1598 
1599  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1600 
1602  {
1603  unsigned long sev = pGetShortExpVector(gcd);
1604 
1605  for (int j = 0; j < strat->sl; j++)
1606  {
1607  if (j == i)
1608  continue;
1609 
1610  if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf)
1611  && !(strat->sevS[j] & ~sev)
1612  && p_LmDivisibleBy(strat->S[j], gcd, currRing))
1613  {
1614  nDelete(&d);
1615  nDelete(&s);
1616  nDelete(&t);
1617  return FALSE;
1618  }
1619  }
1620  }
1621 
1622  //p_Test(m1,strat->tailRing);
1623  //p_Test(m2,strat->tailRing);
1624  /*if(!enterTstrong)
1625  {
1626  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1627  {
1628  memset(&(strat->P), 0, sizeof(strat->P));
1629  kStratChangeTailRing(strat);
1630  strat->P = *(strat->R[atR]);
1631  p_LmFree(m1, strat->tailRing);
1632  p_LmFree(m2, strat->tailRing);
1633  p_LmFree(gcd, currRing);
1634  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1635  }
1636  }*/
1637  pSetCoeff0(m1, s);
1638  pSetCoeff0(m2, t);
1639  pSetCoeff0(gcd, d);
1640  p_Test(m1,strat->tailRing);
1641  p_Test(m2,strat->tailRing);
1642  //printf("\n===================================\n");
1643  //pWrite(m1);pWrite(m2);pWrite(gcd);
1644 #ifdef KDEBUG
1645  if (TEST_OPT_DEBUG)
1646  {
1647  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1648  PrintS("m1 = ");
1649  p_wrp(m1, strat->tailRing);
1650  PrintS(" ; m2 = ");
1651  p_wrp(m2, strat->tailRing);
1652  PrintS(" ; gcd = ");
1653  wrp(gcd);
1654  PrintS("\n--- create strong gcd poly: ");
1655  Print("\n p: %d", i);
1656  wrp(p);
1657  Print("\n strat->S[%d]: ", i);
1658  wrp(si);
1659  PrintS(" ---> ");
1660  }
1661 #endif
1662 
1663  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1664  p_LmDelete(m1, strat->tailRing);
1665  p_LmDelete(m2, strat->tailRing);
1666 #ifdef KDEBUG
1667  if (TEST_OPT_DEBUG)
1668  {
1669  wrp(gcd);
1670  PrintLn();
1671  }
1672 #endif
1673 
1674  LObject h;
1675  h.p = gcd;
1676  h.tailRing = strat->tailRing;
1677  int posx;
1678  h.pCleardenom();
1679  strat->initEcart(&h);
1680  h.sev = pGetShortExpVector(h.p);
1681  h.i_r1 = -1;h.i_r2 = -1;
1682  if (currRing!=strat->tailRing)
1683  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1684  if(!enterTstrong)
1685  {
1686  #if 1
1687  h.p1 = p;h.p2 = strat->S[i];
1688  #endif
1689  if (atR >= 0)
1690  {
1691  h.i_r2 = strat->S_2_R[i];
1692  h.i_r1 = atR;
1693  }
1694  else
1695  {
1696  h.i_r1 = -1;
1697  h.i_r2 = -1;
1698  }
1699  if (strat->Ll==-1)
1700  posx =0;
1701  else
1702  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1703  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1704  }
1705  else
1706  {
1707  if(h.IsNull()) return FALSE;
1708  //int red_result;
1709  //reduzieren ist teur!!!
1710  //if(strat->L != NULL)
1711  //red_result = strat->red(&h,strat);
1712  if(!h.IsNull())
1713  {
1714  enterT(h, strat,-1);
1715  //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1716  //strat->enterS(h,pos,strat,-1);
1717  }
1718  }
1719  return TRUE;
1720 }
1721 
1723 {
1724  if(strat->sl < 0) return FALSE;
1725  int i;
1726  for(i=0;i<strat->sl;i++)
1727  {
1728  //Construct the gcd pair between h and S[i]
1729  number d, s, t;
1730  poly m1, m2, gcd;
1731  d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1732  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1733  {
1734  nDelete(&d);
1735  nDelete(&s);
1736  nDelete(&t);
1737  }
1738  else
1739  {
1740  k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1741  pSetCoeff0(m1, s);
1742  pSetCoeff0(m2, t);
1743  pSetCoeff0(gcd, d);
1744  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);
1745  poly pSigMult = p_Copy(h->sig,currRing);
1746  poly sSigMult = p_Copy(strat->sig[i],currRing);
1747  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1748  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1749  p_LmDelete(m1, strat->tailRing);
1750  p_LmDelete(m2, strat->tailRing);
1751  poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1752  if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1753  {
1754  pDelete(&h->p);
1755  h->p = gcd;
1756  pDelete(&h->sig);
1757  h->sig = pairsig;
1758  pNext(h->sig) = NULL;
1759  strat->initEcart(h);
1760  h->sev = pGetShortExpVector(h->p);
1761  h->sevSig = pGetShortExpVector(h->sig);
1762  h->i_r1 = -1;h->i_r2 = -1;
1763  if(h->lcm != NULL)
1764  {
1765  pLmDelete(h->lcm);
1766  h->lcm = NULL;
1767  }
1768  if (currRing!=strat->tailRing)
1769  h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1770  return TRUE;
1771  }
1772  //Delete what you didn't use
1773  pDelete(&gcd);
1774  pDelete(&pairsig);
1775  }
1776  }
1777  return FALSE;
1778 }
1779 
1780 static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1781 {
1782  number d, s, t;
1783  assume(atR >= 0);
1784  poly m1, m2, gcd,si;
1785  assume(i<=strat->sl);
1786  si = strat->S[i];
1787  //printf("\n--------------------------------\n");
1788  //pWrite(p);pWrite(si);
1789  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1790 
1791  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1792  {
1793  nDelete(&d);
1794  nDelete(&s);
1795  nDelete(&t);
1796  return FALSE;
1797  }
1798 
1799  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1800  //p_Test(m1,strat->tailRing);
1801  //p_Test(m2,strat->tailRing);
1802  /*if(!enterTstrong)
1803  {
1804  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1805  {
1806  memset(&(strat->P), 0, sizeof(strat->P));
1807  kStratChangeTailRing(strat);
1808  strat->P = *(strat->R[atR]);
1809  p_LmFree(m1, strat->tailRing);
1810  p_LmFree(m2, strat->tailRing);
1811  p_LmFree(gcd, currRing);
1812  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1813  }
1814  }*/
1815  pSetCoeff0(m1, s);
1816  pSetCoeff0(m2, t);
1817  pSetCoeff0(gcd, d);
1818  p_Test(m1,strat->tailRing);
1819  p_Test(m2,strat->tailRing);
1820  //printf("\n===================================\n");
1821  //pWrite(m1);pWrite(m2);pWrite(gcd);
1822 #ifdef KDEBUG
1823  if (TEST_OPT_DEBUG)
1824  {
1825  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1826  PrintS("m1 = ");
1827  p_wrp(m1, strat->tailRing);
1828  PrintS(" ; m2 = ");
1829  p_wrp(m2, strat->tailRing);
1830  PrintS(" ; gcd = ");
1831  wrp(gcd);
1832  PrintS("\n--- create strong gcd poly: ");
1833  Print("\n p: %d", i);
1834  wrp(p);
1835  Print("\n strat->S[%d]: ", i);
1836  wrp(si);
1837  PrintS(" ---> ");
1838  }
1839 #endif
1840 
1841  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1842 
1843 #ifdef KDEBUG
1844  if (TEST_OPT_DEBUG)
1845  {
1846  wrp(gcd);
1847  PrintLn();
1848  }
1849 #endif
1850 
1851  //Check and set the signatures
1852  poly pSigMult = p_Copy(sig,currRing);
1853  poly sSigMult = p_Copy(strat->sig[i],currRing);
1854  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1855  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1856  p_LmDelete(m1, strat->tailRing);
1857  p_LmDelete(m2, strat->tailRing);
1858  poly pairsig;
1859  if(pLmCmp(pSigMult,sSigMult) == 0)
1860  {
1861  //Same lm, have to add them
1862  pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1863  //This might be zero
1864  }
1865  else
1866  {
1867  //Set the sig to either pSigMult or sSigMult
1868  if(pLtCmp(pSigMult,sSigMult)==1)
1869  {
1870  pairsig = pSigMult;
1871  pDelete(&sSigMult);
1872  }
1873  else
1874  {
1875  pairsig = sSigMult;
1876  pDelete(&pSigMult);
1877  }
1878  }
1879 
1880  LObject h;
1881  h.p = gcd;
1882  h.tailRing = strat->tailRing;
1883  h.sig = pairsig;
1884  int posx;
1885  h.pCleardenom();
1886  strat->initEcart(&h);
1887  h.sev = pGetShortExpVector(h.p);
1888  h.i_r1 = -1;h.i_r2 = -1;
1889  if (currRing!=strat->tailRing)
1890  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1891  if(h.sig == NULL)
1892  {
1893  //sigdrop since we loose the signature
1894  strat->sigdrop = TRUE;
1895  //Try to reduce it as far as we can via redRing
1896  int red_result = redRing(&h,strat);
1897  if(red_result == 0)
1898  {
1899  // Cancel the sigdrop
1900  p_Delete(&h.sig,currRing);h.sig = NULL;
1901  strat->sigdrop = FALSE;
1902  return FALSE;
1903  }
1904  else
1905  {
1906  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1907  #if 1
1908  strat->enterS(h,0,strat,strat->tl);
1909  #endif
1910  return FALSE;
1911  }
1912  }
1913  if(!nGreaterZero(pGetCoeff(h.sig)))
1914  {
1915  h.sig = pNeg(h.sig);
1916  h.p = pNeg(h.p);
1917  }
1918 
1919  if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1920  {
1921  strat->sigdrop = TRUE;
1922  // Completely reduce it
1923  int red_result = redRing(&h,strat);
1924  if(red_result == 0)
1925  {
1926  // Reduced to 0
1927  strat->sigdrop = FALSE;
1928  p_Delete(&h.sig,currRing);h.sig = NULL;
1929  return FALSE;
1930  }
1931  else
1932  {
1933  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1934  // 0 - add just the original poly causing the sigdrop, 1 - add also this
1935  #if 1
1936  strat->enterS(h,0,strat, strat->tl+1);
1937  #endif
1938  return FALSE;
1939  }
1940  }
1941  //Check for sigdrop
1942  if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1943  {
1944  strat->sigdrop = TRUE;
1945  //Enter this element to S
1946  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1947  strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1948  }
1949  #if 1
1950  h.p1 = p;h.p2 = strat->S[i];
1951  #endif
1952  if (atR >= 0)
1953  {
1954  h.i_r2 = strat->S_2_R[i];
1955  h.i_r1 = atR;
1956  }
1957  else
1958  {
1959  h.i_r1 = -1;
1960  h.i_r2 = -1;
1961  }
1962  if (strat->Ll==-1)
1963  posx =0;
1964  else
1965  posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1966  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1967  return TRUE;
1968 }
1969 #endif
1970 
1971 /*2
1972 * put the pair (s[i],p) into the set B, ecart=ecart(p)
1973 */
1974 
1975 void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1976 {
1977  assume(i<=strat->sl);
1978 
1979  int l,j,compare;
1980  LObject Lp;
1981  Lp.i_r = -1;
1982 
1983 #ifdef KDEBUG
1984  Lp.ecart=0; Lp.length=0;
1985 #endif
1986  /*- computes the lcm(s[i],p) -*/
1987  Lp.lcm = pInit();
1988 
1989 #ifndef HAVE_RATGRING
1990  pLcm(p,strat->S[i],Lp.lcm);
1991 #elif defined(HAVE_RATGRING)
1992  if (rIsRatGRing(currRing))
1993  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1994  else
1995  pLcm(p,strat->S[i],Lp.lcm);
1996 #endif
1997  pSetm(Lp.lcm);
1998 
1999 
2000  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
2001  {
2002  if (strat->fromT && (strat->ecartS[i]>ecart))
2003  {
2004  pLmFree(Lp.lcm);
2005  return;
2006  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2007  }
2008  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2009  && pHasNotCF(p,strat->S[i]))
2010  {
2011  /*
2012  *the product criterion has applied for (s,p),
2013  *i.e. lcm(s,p)=product of the leading terms of s and p.
2014  *Suppose (s,r) is in L and the leading term
2015  *of p divides lcm(s,r)
2016  *(==> the leading term of p divides the leading term of r)
2017  *but the leading term of s does not divide the leading term of r
2018  *(notice that tis condition is automatically satisfied if r is still
2019  *in S), then (s,r) can be cancelled.
2020  *This should be done here because the
2021  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2022  *
2023  *Moreover, skipping (s,r) holds also for the noncommutative case.
2024  */
2025  strat->cp++;
2026  pLmFree(Lp.lcm);
2027  return;
2028  }
2029  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2030  /*
2031  *the set B collects the pairs of type (S[j],p)
2032  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2033  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2034  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2035  */
2036  {
2037  j = strat->Bl;
2038  loop
2039  {
2040  if (j < 0) break;
2041  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2042  if ((compare==1)
2043  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2044  {
2045  strat->c3++;
2046  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2047  {
2048  pLmFree(Lp.lcm);
2049  return;
2050  }
2051  break;
2052  }
2053  else
2054  if ((compare ==-1)
2055  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2056  {
2057  deleteInL(strat->B,&strat->Bl,j,strat);
2058  strat->c3++;
2059  }
2060  j--;
2061  }
2062  }
2063  }
2064  else /*sugarcrit*/
2065  {
2066  if (ALLOW_PROD_CRIT(strat))
2067  {
2068  if (strat->fromT && (strat->ecartS[i]>ecart))
2069  {
2070  pLmFree(Lp.lcm);
2071  return;
2072  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2073  }
2074  // if currRing->nc_type!=quasi (or skew)
2075  // TODO: enable productCrit for super commutative algebras...
2076  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2077  pHasNotCF(p,strat->S[i]))
2078  {
2079  /*
2080  *the product criterion has applied for (s,p),
2081  *i.e. lcm(s,p)=product of the leading terms of s and p.
2082  *Suppose (s,r) is in L and the leading term
2083  *of p divides lcm(s,r)
2084  *(==> the leading term of p divides the leading term of r)
2085  *but the leading term of s does not divide the leading term of r
2086  *(notice that tis condition is automatically satisfied if r is still
2087  *in S), then (s,r) can be canceled.
2088  *This should be done here because the
2089  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2090  */
2091  strat->cp++;
2092  pLmFree(Lp.lcm);
2093  return;
2094  }
2095  /*
2096  *the set B collects the pairs of type (S[j],p)
2097  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2098  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2099  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2100  */
2101  for(j = strat->Bl;j>=0;j--)
2102  {
2103  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2104  if (compare==1)
2105  {
2106  strat->c3++;
2107  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2108  {
2109  pLmFree(Lp.lcm);
2110  return;
2111  }
2112  break;
2113  }
2114  else
2115  if (compare ==-1)
2116  {
2117  deleteInL(strat->B,&strat->Bl,j,strat);
2118  strat->c3++;
2119  }
2120  }
2121  }
2122  }
2123  /*
2124  *the pair (S[i],p) enters B if the spoly != 0
2125  */
2126  /*- compute the short s-polynomial -*/
2127  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2128  pNorm(p);
2129 
2130  if ((strat->S[i]==NULL) || (p==NULL))
2131  return;
2132 
2133  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2134  Lp.p=NULL;
2135  else
2136  {
2137  #ifdef HAVE_PLURAL
2138  if ( rIsPluralRing(currRing) )
2139  {
2140  if(pHasNotCF(p, strat->S[i]))
2141  {
2142  if(ncRingType(currRing) == nc_lie)
2143  {
2144  // generalized prod-crit for lie-type
2145  strat->cp++;
2146  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2147  }
2148  else
2149  if( ALLOW_PROD_CRIT(strat) )
2150  {
2151  // product criterion for homogeneous case in SCA
2152  strat->cp++;
2153  Lp.p = NULL;
2154  }
2155  else
2156  {
2157  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2158  nc_CreateShortSpoly(strat->S[i], p, currRing);
2159  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2160  pNext(Lp.p) = strat->tail; // !!!
2161  }
2162  }
2163  else
2164  {
2165  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2166  nc_CreateShortSpoly(strat->S[i], p, currRing);
2167 
2168  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2169  pNext(Lp.p) = strat->tail; // !!!
2170  }
2171  }
2172  else
2173  #endif
2174  {
2176  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2177  }
2178  }
2179  if (Lp.p == NULL)
2180  {
2181  /*- the case that the s-poly is 0 -*/
2182  if (strat->pairtest==NULL) initPairtest(strat);
2183  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2184  strat->pairtest[strat->sl+1] = TRUE;
2185  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2186  /*
2187  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2188  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2189  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2190  *term of p divides the lcm(s,r)
2191  *(this canceling should be done here because
2192  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2193  *the first case is handeled in chainCrit
2194  */
2195  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2196  }
2197  else
2198  {
2199  /*- the pair (S[i],p) enters B -*/
2200  Lp.p1 = strat->S[i];
2201  Lp.p2 = p;
2202 
2203  if (
2205 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2206  )
2207  {
2208  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2209  pNext(Lp.p) = strat->tail; // !!!
2210  }
2211 
2212  if (atR >= 0)
2213  {
2214  Lp.i_r1 = strat->S_2_R[i];
2215  Lp.i_r2 = atR;
2216  }
2217  else
2218  {
2219  Lp.i_r1 = -1;
2220  Lp.i_r2 = -1;
2221  }
2222  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2223 
2225  {
2226  if (!rIsPluralRing(currRing)
2228  && (Lp.p->coef!=NULL))
2229  nDelete(&(Lp.p->coef));
2230  }
2231 
2232  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2233  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2234  }
2235 }
2236 
2237 /// p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
2238 static inline BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2239 {
2240  int i = rVar(r);
2241  loop
2242  {
2243  if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2244  return FALSE;
2245  i--;
2246  if (i == 0)
2247  return TRUE;
2248  }
2249 }
2250 
2251 /*2
2252 * put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2253 * (in the special case: idLift for ideals, i.e. strat->syzComp==1)
2254 * (prod.crit applies)
2255 */
2256 
2257 static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2258 {
2259  assume(ALLOW_PROD_CRIT(strat));
2261  assume(i<=strat->sl);
2262  assume(strat->syzComp==1);
2263 
2264  if ((strat->S[i]==NULL) || (p==NULL))
2265  return;
2266 
2267  int l,j,compare;
2268  LObject Lp;
2269  Lp.i_r = -1;
2270 
2271 #ifdef KDEBUG
2272  Lp.ecart=0; Lp.length=0;
2273 #endif
2274  /*- computes the lcm(s[i],p) -*/
2275  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2276 
2277  if (strat->sugarCrit)
2278  {
2279  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2280  && p_HasNotCF_Lift(p,strat->S[i],currRing))
2281  {
2282  /*
2283  *the product criterion has applied for (s,p),
2284  *i.e. lcm(s,p)=product of the leading terms of s and p.
2285  *Suppose (s,r) is in L and the leading term
2286  *of p divides lcm(s,r)
2287  *(==> the leading term of p divides the leading term of r)
2288  *but the leading term of s does not divide the leading term of r
2289  *(notice that tis condition is automatically satisfied if r is still
2290  *in S), then (s,r) can be cancelled.
2291  *This should be done here because the
2292  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2293  *
2294  *Moreover, skipping (s,r) holds also for the noncommutative case.
2295  */
2296  strat->cp++;
2297  pLmFree(Lp.lcm);
2298  return;
2299  }
2300  else
2301  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2302  if (strat->fromT && (strat->ecartS[i]>ecart))
2303  {
2304  pLmFree(Lp.lcm);
2305  return;
2306  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2307  }
2308  /*
2309  *the set B collects the pairs of type (S[j],p)
2310  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2311  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2312  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2313  */
2314  {
2315  j = strat->Bl;
2316  loop
2317  {
2318  if (j < 0) break;
2319  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2320  if ((compare==1)
2321  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2322  {
2323  strat->c3++;
2324  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2325  {
2326  pLmFree(Lp.lcm);
2327  return;
2328  }
2329  break;
2330  }
2331  else
2332  if ((compare ==-1)
2333  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2334  {
2335  deleteInL(strat->B,&strat->Bl,j,strat);
2336  strat->c3++;
2337  }
2338  j--;
2339  }
2340  }
2341  }
2342  else /*sugarcrit*/
2343  {
2344  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2345  p_HasNotCF_Lift(p,strat->S[i],currRing))
2346  {
2347  /*
2348  *the product criterion has applied for (s,p),
2349  *i.e. lcm(s,p)=product of the leading terms of s and p.
2350  *Suppose (s,r) is in L and the leading term
2351  *of p divides lcm(s,r)
2352  *(==> the leading term of p divides the leading term of r)
2353  *but the leading term of s does not divide the leading term of r
2354  *(notice that tis condition is automatically satisfied if r is still
2355  *in S), then (s,r) can be canceled.
2356  *This should be done here because the
2357  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2358  */
2359  strat->cp++;
2360  pLmFree(Lp.lcm);
2361  return;
2362  }
2363  if (strat->fromT && (strat->ecartS[i]>ecart))
2364  {
2365  pLmFree(Lp.lcm);
2366  return;
2367  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2368  }
2369  /*
2370  *the set B collects the pairs of type (S[j],p)
2371  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2372  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2373  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2374  */
2375  for(j = strat->Bl;j>=0;j--)
2376  {
2377  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2378  if (compare==1)
2379  {
2380  strat->c3++;
2381  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2382  {
2383  pLmFree(Lp.lcm);
2384  return;
2385  }
2386  break;
2387  }
2388  else
2389  if (compare ==-1)
2390  {
2391  deleteInL(strat->B,&strat->Bl,j,strat);
2392  strat->c3++;
2393  }
2394  }
2395  }
2396  /*
2397  *the pair (S[i],p) enters B if the spoly != 0
2398  */
2399  /*- compute the short s-polynomial -*/
2400  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2401  pNorm(p);
2402 
2403  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2404  Lp.p=NULL;
2405  else
2406  {
2408  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2409  }
2410  if (Lp.p == NULL)
2411  {
2412  /*- the case that the s-poly is 0 -*/
2413  if (strat->pairtest==NULL) initPairtest(strat);
2414  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2415  strat->pairtest[strat->sl+1] = TRUE;
2416  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2417  /*
2418  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2419  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2420  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2421  *term of p divides the lcm(s,r)
2422  *(this canceling should be done here because
2423  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2424  *the first case is handeled in chainCrit
2425  */
2426  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2427  }
2428  else
2429  {
2430  /*- the pair (S[i],p) enters B -*/
2431  Lp.p1 = strat->S[i];
2432  Lp.p2 = p;
2433 
2434  pNext(Lp.p) = strat->tail; // !!!
2435 
2436  if (atR >= 0)
2437  {
2438  Lp.i_r1 = strat->S_2_R[i];
2439  Lp.i_r2 = atR;
2440  }
2441  else
2442  {
2443  Lp.i_r1 = -1;
2444  Lp.i_r2 = -1;
2445  }
2446  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2447 
2449  {
2450  if (!rIsPluralRing(currRing)
2452  && (Lp.p->coef!=NULL))
2453  nDelete(&(Lp.p->coef));
2454  }
2455 
2456  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2457  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2458  }
2459 }
2460 
2461 /*2
2462 * put the pair (s[i],p) into the set B, ecart=ecart(p)
2463 * NOTE: here we need to add the signature-based criteria
2464 */
2465 
2466 #ifdef DEBUGF5
2467 static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2468 #else
2469 static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2470 #endif
2471 {
2472  assume(i<=strat->sl);
2473 
2474  int l;
2475  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2476  // the corresponding signatures for criteria checks
2477  LObject Lp;
2478  poly pSigMult = p_Copy(pSig,currRing);
2479  poly sSigMult = p_Copy(strat->sig[i],currRing);
2480  unsigned long pSigMultNegSev,sSigMultNegSev;
2481  Lp.i_r = -1;
2482 
2483 #ifdef KDEBUG
2484  Lp.ecart=0; Lp.length=0;
2485 #endif
2486  /*- computes the lcm(s[i],p) -*/
2487  Lp.lcm = pInit();
2488  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2489 #ifndef HAVE_RATGRING
2490  pLcm(p,strat->S[i],Lp.lcm);
2491 #elif defined(HAVE_RATGRING)
2492  if (rIsRatGRing(currRing))
2493  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2494  else
2495  pLcm(p,strat->S[i],Lp.lcm);
2496 #endif
2497  pSetm(Lp.lcm);
2498 
2499  // set coeffs of multipliers m1 and m2
2500  pSetCoeff0(m1, nInit(1));
2501  pSetCoeff0(m2, nInit(1));
2502 //#if 1
2503 #ifdef DEBUGF5
2504  PrintS("P1 ");
2505  pWrite(pHead(p));
2506  PrintS("P2 ");
2507  pWrite(pHead(strat->S[i]));
2508  PrintS("M1 ");
2509  pWrite(m1);
2510  PrintS("M2 ");
2511  pWrite(m2);
2512 #endif
2513  // get multiplied signatures for testing
2514  pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2515  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2516  sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2517  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2518 
2519 //#if 1
2520 #ifdef DEBUGF5
2521  PrintS("----------------\n");
2522  pWrite(pSigMult);
2523  pWrite(sSigMult);
2524  PrintS("----------------\n");
2525  Lp.checked = 0;
2526 #endif
2527  int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2528 //#if 1
2529 #if DEBUGF5
2530  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2531  pWrite(pSigMult);
2532  pWrite(sSigMult);
2533 #endif
2534  if(sigCmp==0)
2535  {
2536  // printf("!!!! EQUAL SIGS !!!!\n");
2537  // pSig = sSig, delete element due to Rewritten Criterion
2538  pDelete(&pSigMult);
2539  pDelete(&sSigMult);
2540  if (rField_is_Ring(currRing))
2541  pLmDelete(Lp.lcm);
2542  else
2543  pLmFree(Lp.lcm);
2544  pDelete (&m1);
2545  pDelete (&m2);
2546  return;
2547  }
2548  // testing by syzCrit = F5 Criterion
2549  // testing by rewCrit1 = Rewritten Criterion
2550  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2551  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2552  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2553  || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2554  )
2555  {
2556  pDelete(&pSigMult);
2557  pDelete(&sSigMult);
2558  if (rField_is_Ring(currRing))
2559  pLmDelete(Lp.lcm);
2560  else
2561  pLmFree(Lp.lcm);
2562  pDelete (&m1);
2563  pDelete (&m2);
2564  return;
2565  }
2566  /*
2567  *the pair (S[i],p) enters B if the spoly != 0
2568  */
2569  /*- compute the short s-polynomial -*/
2570  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2571  pNorm(p);
2572 
2573  if ((strat->S[i]==NULL) || (p==NULL))
2574  return;
2575 
2576  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2577  Lp.p=NULL;
2578  else
2579  {
2580  #ifdef HAVE_PLURAL
2581  if ( rIsPluralRing(currRing) )
2582  {
2583  if(pHasNotCF(p, strat->S[i]))
2584  {
2585  if(ncRingType(currRing) == nc_lie)
2586  {
2587  // generalized prod-crit for lie-type
2588  strat->cp++;
2589  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2590  }
2591  else
2592  if( ALLOW_PROD_CRIT(strat) )
2593  {
2594  // product criterion for homogeneous case in SCA
2595  strat->cp++;
2596  Lp.p = NULL;
2597  }
2598  else
2599  {
2600  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2601  nc_CreateShortSpoly(strat->S[i], p, currRing);
2602 
2603  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2604  pNext(Lp.p) = strat->tail; // !!!
2605  }
2606  }
2607  else
2608  {
2609  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2610  nc_CreateShortSpoly(strat->S[i], p, currRing);
2611 
2612  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2613  pNext(Lp.p) = strat->tail; // !!!
2614  }
2615  }
2616  else
2617  #endif
2618  {
2620  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2621  }
2622  }
2623  // store from which element this pair comes from for further tests
2624  //Lp.from = strat->sl+1;
2625  if(sigCmp==currRing->OrdSgn)
2626  {
2627  // pSig > sSig
2628  pDelete (&sSigMult);
2629  Lp.sig = pSigMult;
2630  Lp.sevSig = ~pSigMultNegSev;
2631  }
2632  else
2633  {
2634  // pSig < sSig
2635  pDelete (&pSigMult);
2636  Lp.sig = sSigMult;
2637  Lp.sevSig = ~sSigMultNegSev;
2638  }
2639  if (Lp.p == NULL)
2640  {
2641  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2642  int pos = posInSyz(strat, Lp.sig);
2643  enterSyz(Lp, strat, pos);
2644  }
2645  else
2646  {
2647  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2648  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2649  {
2650  pLmFree(Lp.lcm);
2651  pDelete(&Lp.sig);
2652  pDelete (&m1);
2653  pDelete (&m2);
2654  return;
2655  }
2656  // in any case Lp is checked up to the next strat->P which is added
2657  // to S right after this critical pair creation.
2658  // NOTE: this even holds if the 2nd generator gives the bigger signature
2659  // moreover, this improves rewCriterion,
2660  // i.e. strat->checked > strat->from if and only if the 2nd generator
2661  // gives the bigger signature.
2662  Lp.checked = strat->sl+1;
2663  // at this point it is clear that the pair will be added to L, since it has
2664  // passed all tests up to now
2665 
2666  // adds buchberger's first criterion
2667  if (pLmCmp(m2,pHead(p)) == 0)
2668  {
2669  Lp.prod_crit = TRUE; // Product Criterion
2670 #if 0
2671  int pos = posInSyz(strat, Lp.sig);
2672  enterSyz(Lp, strat, pos);
2673  pDelete (&m1);
2674  pDelete (&m2);
2675  return;
2676 #endif
2677  }
2678  pDelete (&m1);
2679  pDelete (&m2);
2680 #if DEBUGF5
2681  PrintS("SIGNATURE OF PAIR: ");
2682  pWrite(Lp.sig);
2683 #endif
2684  /*- the pair (S[i],p) enters B -*/
2685  Lp.p1 = strat->S[i];
2686  Lp.p2 = p;
2687 
2688  if (
2690 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2691  )
2692  {
2693  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2694  pNext(Lp.p) = strat->tail; // !!!
2695  }
2696 
2697  if (atR >= 0)
2698  {
2699  Lp.i_r1 = strat->S_2_R[i];
2700  Lp.i_r2 = atR;
2701  }
2702  else
2703  {
2704  Lp.i_r1 = -1;
2705  Lp.i_r2 = -1;
2706  }
2707  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2708 
2710  {
2711  if (!rIsPluralRing(currRing)
2713  && (Lp.p->coef!=NULL))
2714  nDelete(&(Lp.p->coef));
2715  }
2716 
2717  l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2718  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2719  }
2720 }
2721 
2722 
2723 #ifdef DEBUGF5
2724 static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2725 #else
2726 static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2727 #endif
2728 {
2729  #if ALL_VS_JUST
2730  //Over rings, if we construct the strong pair, do not add the spair
2732  {
2733  number s,t,d;
2734  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2735 
2736  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2737  {
2738  nDelete(&d);
2739  nDelete(&s);
2740  nDelete(&t);
2741  return;
2742  }
2743  nDelete(&d);
2744  nDelete(&s);
2745  nDelete(&t);
2746  }
2747  #endif
2748  assume(i<=strat->sl);
2749  int l;
2750  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2751  // the corresponding signatures for criteria checks
2752  LObject Lp;
2753  poly pSigMult = p_Copy(pSig,currRing);
2754  poly sSigMult = p_Copy(strat->sig[i],currRing);
2755  unsigned long pSigMultNegSev,sSigMultNegSev;
2756  Lp.i_r = -1;
2757 
2758 #ifdef KDEBUG
2759  Lp.ecart=0; Lp.length=0;
2760 #endif
2761  /*- computes the lcm(s[i],p) -*/
2762  Lp.lcm = pInit();
2763  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2764 #ifndef HAVE_RATGRING
2765  pLcm(p,strat->S[i],Lp.lcm);
2766 #elif defined(HAVE_RATGRING)
2767  if (rIsRatGRing(currRing))
2768  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2769  else
2770  pLcm(p,strat->S[i],Lp.lcm);
2771 #endif
2772  pSetm(Lp.lcm);
2773 
2774  // set coeffs of multipliers m1 and m2
2776  {
2777  number s = nCopy(pGetCoeff(strat->S[i]));
2778  number t = nCopy(pGetCoeff(p));
2779  pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2780  ksCheckCoeff(&s, &t, currRing->cf);
2781  pSetCoeff0(m1,s);
2782  pSetCoeff0(m2,t);
2783  }
2784  else
2785  {
2786  pSetCoeff0(m1, nInit(1));
2787  pSetCoeff0(m2, nInit(1));
2788  }
2789 #ifdef DEBUGF5
2790  Print("P1 ");
2791  pWrite(pHead(p));
2792  Print("P2 ");
2793  pWrite(pHead(strat->S[i]));
2794  Print("M1 ");
2795  pWrite(m1);
2796  Print("M2 ");
2797  pWrite(m2);
2798 #endif
2799 
2800  // get multiplied signatures for testing
2801  pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2802  if(pSigMult != NULL)
2803  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2804  sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2805  if(sSigMult != NULL)
2806  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2807 //#if 1
2808 #ifdef DEBUGF5
2809  Print("----------------\n");
2810  pWrite(pSigMult);
2811  pWrite(sSigMult);
2812  Print("----------------\n");
2813  Lp.checked = 0;
2814 #endif
2815  int sigCmp;
2816  if(pSigMult != NULL && sSigMult != NULL)
2817  {
2819  sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2820  else
2821  sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2822  }
2823  else
2824  {
2825  if(pSigMult == NULL)
2826  {
2827  if(sSigMult == NULL)
2828  sigCmp = 0;
2829  else
2830  sigCmp = -1;
2831  }
2832  else
2833  sigCmp = 1;
2834  }
2835 //#if 1
2836 #if DEBUGF5
2837  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2838  pWrite(pSigMult);
2839  pWrite(sSigMult);
2840 #endif
2841  //In the ring case we already build the sig
2843  {
2844  if(sigCmp == 0)
2845  {
2846  //sigdrop since we loose the signature
2847  strat->sigdrop = TRUE;
2848  //Try to reduce it as far as we can via redRing
2850  {
2851  poly p1 = p_Copy(p,currRing);
2852  poly p2 = p_Copy(strat->S[i],currRing);
2853  p1 = p_Mult_mm(p1,m1,currRing);
2854  p2 = p_Mult_mm(p2,m2,currRing);
2855  Lp.p = p_Sub(p1,p2,currRing);
2856  if(Lp.p != NULL)
2857  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2858  }
2859  int red_result = redRing(&Lp,strat);
2860  if(red_result == 0)
2861  {
2862  // Cancel the sigdrop
2863  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2864  strat->sigdrop = FALSE;
2865  return;
2866  }
2867  else
2868  {
2869  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2870  #if 1
2871  strat->enterS(Lp,0,strat,strat->tl);
2872  #endif
2873  return;
2874  }
2875  }
2876  if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2877  {
2878  //Same lm, have to substract
2879  Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2880  }
2881  else
2882  {
2883  if(sigCmp == 1)
2884  {
2885  Lp.sig = pCopy(pSigMult);
2886  }
2887  if(sigCmp == -1)
2888  {
2889  Lp.sig = pNeg(pCopy(sSigMult));
2890  }
2891  }
2892  Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2893  }
2894 
2895  #if 0
2896  if(sigCmp==0)
2897  {
2898  // printf("!!!! EQUAL SIGS !!!!\n");
2899  // pSig = sSig, delete element due to Rewritten Criterion
2900  pDelete(&pSigMult);
2901  pDelete(&sSigMult);
2902  if (rField_is_Ring(currRing))
2903  pLmDelete(Lp.lcm);
2904  else
2905  pLmFree(Lp.lcm);
2906  pDelete (&m1);
2907  pDelete (&m2);
2908  return;
2909  }
2910  #endif
2911  // testing by syzCrit = F5 Criterion
2912  // testing by rewCrit1 = Rewritten Criterion
2913  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2914  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2915  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2916  // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2917  //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2918  )
2919  {
2920  pDelete(&pSigMult);
2921  pDelete(&sSigMult);
2922  if (rField_is_Ring(currRing))
2923  pLmDelete(Lp.lcm);
2924  else
2925  pLmFree(Lp.lcm);
2926  pDelete (&m1);
2927  pDelete (&m2);
2928  return;
2929  }
2930  /*
2931  *the pair (S[i],p) enters B if the spoly != 0
2932  */
2933  /*- compute the short s-polynomial -*/
2934  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2935  pNorm(p);
2936 
2937  if ((strat->S[i]==NULL) || (p==NULL))
2938  return;
2939 
2940  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2941  Lp.p=NULL;
2942  else
2943  {
2944  //Build p
2946  {
2947  poly p1 = p_Copy(p,currRing);
2948  poly p2 = p_Copy(strat->S[i],currRing);
2949  p1 = p_Mult_mm(p1,m1,currRing);
2950  p2 = p_Mult_mm(p2,m2,currRing);
2951  Lp.p = p_Sub(p1,p2,currRing);
2952  if(Lp.p != NULL)
2953  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2954  }
2955  else
2956  {
2957  #ifdef HAVE_PLURAL
2958  if ( rIsPluralRing(currRing) )
2959  {
2960  if(ncRingType(currRing) == nc_lie)
2961  {
2962  // generalized prod-crit for lie-type
2963  strat->cp++;
2964  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2965  }
2966  else
2967  if( ALLOW_PROD_CRIT(strat) )
2968  {
2969  // product criterion for homogeneous case in SCA
2970  strat->cp++;
2971  Lp.p = NULL;
2972  }
2973  else
2974  {
2975  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2976  nc_CreateShortSpoly(strat->S[i], p, currRing);
2977 
2978  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2979  pNext(Lp.p) = strat->tail; // !!!
2980  }
2981  }
2982  else
2983  #endif
2984  {
2986  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2987  }
2988  }
2989  }
2990  // store from which element this pair comes from for further tests
2991  //Lp.from = strat->sl+1;
2993  {
2994  //Put the sig to be > 0
2995  if(!nGreaterZero(pGetCoeff(Lp.sig)))
2996  {
2997  Lp.sig = pNeg(Lp.sig);
2998  Lp.p = pNeg(Lp.p);
2999  }
3000  }
3001  else
3002  {
3003  if(sigCmp==currRing->OrdSgn)
3004  {
3005  // pSig > sSig
3006  pDelete (&sSigMult);
3007  Lp.sig = pSigMult;
3008  Lp.sevSig = ~pSigMultNegSev;
3009  }
3010  else
3011  {
3012  // pSig < sSig
3013  pDelete (&pSigMult);
3014  Lp.sig = sSigMult;
3015  Lp.sevSig = ~sSigMultNegSev;
3016  }
3017  }
3018  if (Lp.p == NULL)
3019  {
3020  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
3021  int pos = posInSyz(strat, Lp.sig);
3022  enterSyz(Lp, strat, pos);
3023  }
3024  else
3025  {
3026  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
3027  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
3028  {
3029  pLmFree(Lp.lcm);
3030  pDelete(&Lp.sig);
3031  pDelete (&m1);
3032  pDelete (&m2);
3033  return;
3034  }
3035  // in any case Lp is checked up to the next strat->P which is added
3036  // to S right after this critical pair creation.
3037  // NOTE: this even holds if the 2nd generator gives the bigger signature
3038  // moreover, this improves rewCriterion,
3039  // i.e. strat->checked > strat->from if and only if the 2nd generator
3040  // gives the bigger signature.
3041  Lp.checked = strat->sl+1;
3042  // at this point it is clear that the pair will be added to L, since it has
3043  // passed all tests up to now
3044 
3045  // adds buchberger's first criterion
3046  if (pLmCmp(m2,pHead(p)) == 0)
3047  {
3048  Lp.prod_crit = TRUE; // Product Criterion
3049 #if 0
3050  int pos = posInSyz(strat, Lp.sig);
3051  enterSyz(Lp, strat, pos);
3052  pDelete (&m1);
3053  pDelete (&m2);
3054  return;
3055 #endif
3056  }
3057  pDelete (&m1);
3058  pDelete (&m2);
3059 #if DEBUGF5
3060  PrintS("SIGNATURE OF PAIR: ");
3061  pWrite(Lp.sig);
3062 #endif
3063  /*- the pair (S[i],p) enters B -*/
3064  Lp.p1 = strat->S[i];
3065  Lp.p2 = p;
3066 
3067  if (
3069 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3071  )
3072  {
3073  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3074  pNext(Lp.p) = strat->tail; // !!!
3075  }
3076 
3077  if (atR >= 0)
3078  {
3079  Lp.i_r1 = strat->S_2_R[i];
3080  Lp.i_r2 = atR;
3081  }
3082  else
3083  {
3084  Lp.i_r1 = -1;
3085  Lp.i_r2 = -1;
3086  }
3087  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3088 
3090  {
3091  if (!rIsPluralRing(currRing)
3093  && (Lp.p->coef!=NULL))
3094  nDelete(&(Lp.p->coef));
3095  }
3096  // Check for sigdrop
3097  if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3098  {
3099  strat->sigdrop = TRUE;
3100  // Completely reduce it
3101  int red_result = redRing(&Lp,strat);
3102  if(red_result == 0)
3103  {
3104  // Reduced to 0
3105  strat->sigdrop = FALSE;
3106  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3107  return;
3108  }
3109  else
3110  {
3111  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3112  // 0 - add just the original poly causing the sigdrop, 1 - add also this
3113  #if 1
3114  strat->enterS(Lp,0,strat, strat->tl+1);
3115  #endif
3116  return;
3117  }
3118  }
3119  l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3120  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3121  }
3122 }
3123 
3124 /*2
3125 * put the pair (s[i],p) into the set L, ecart=ecart(p)
3126 * in the case that s forms a SB of (s)
3127 */
3128 void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3129 {
3130  //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3131  if(pHasNotCF(p,strat->S[i]))
3132  {
3133  //PrintS("prod-crit\n");
3134  if(ALLOW_PROD_CRIT(strat))
3135  {
3136  //PrintS("prod-crit\n");
3137  strat->cp++;
3138  return;
3139  }
3140  }
3141 
3142  int l;
3143  LObject Lp;
3144  Lp.i_r = -1;
3145 
3146  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3147  /*- compute the short s-polynomial -*/
3148 
3149  #ifdef HAVE_PLURAL
3150  if (rIsPluralRing(currRing))
3151  {
3152  Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3153  }
3154  else
3155  #endif
3156  Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3157 
3158  if (Lp.p == NULL)
3159  {
3160  //PrintS("short spoly==NULL\n");
3161  pLmFree(Lp.lcm);
3162  }
3163  else
3164  {
3165  /*- the pair (S[i],p) enters L -*/
3166  Lp.p1 = strat->S[i];
3167  Lp.p2 = p;
3168  if (atR >= 0)
3169  {
3170  Lp.i_r1 = strat->S_2_R[i];
3171  Lp.i_r2 = atR;
3172  }
3173  else
3174  {
3175  Lp.i_r1 = -1;
3176  Lp.i_r2 = -1;
3177  }
3178  assume(pNext(Lp.p) == NULL);
3179  pNext(Lp.p) = strat->tail;
3180  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3182  {
3183  if (!rIsPluralRing(currRing)
3185  && (Lp.p->coef!=NULL))
3186  nDelete(&(Lp.p->coef));
3187  }
3188  l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3189  //Print("-> L[%d]\n",l);
3190  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3191  }
3192 }
3193 
3194 /*2
3195 * merge set B into L
3196 */
3198 {
3199  int j=strat->Ll+strat->Bl+1;
3200  if (j>strat->Lmax)
3201  {
3202  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3203  enlargeL(&(strat->L),&(strat->Lmax),j);
3204  }
3205  j = strat->Ll;
3206  int i;
3207  for (i=strat->Bl; i>=0; i--)
3208  {
3209  j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3210  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3211  }
3212  strat->Bl = -1;
3213 }
3214 
3215 /*2
3216 * merge set B into L
3217 */
3219 {
3220  int j=strat->Ll+strat->Bl+1;
3221  if (j>strat->Lmax)
3222  {
3223  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3224  enlargeL(&(strat->L),&(strat->Lmax),j);
3225  }
3226  j = strat->Ll;
3227  int i;
3228  for (i=strat->Bl; i>=0; i--)
3229  {
3230  j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3231  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3232  }
3233  strat->Bl = -1;
3234 }
3235 
3236 /*2
3237 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3238 *using the chain-criterion in B and L and enters B to L
3239 */
3240 void chainCritNormal (poly p,int ecart,kStrategy strat)
3241 {
3242  int i,j,l;
3243 
3244  /*
3245  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3246  *In this case all elements in B such
3247  *that their lcm is divisible by the leading term of S[i] can be canceled
3248  */
3249  if (strat->pairtest!=NULL)
3250  {
3251 #ifdef HAVE_SHIFTBBA
3252  // only difference is pLPDivisibleBy instead of pDivisibleBy
3253  if (rIsLPRing(currRing))
3254  {
3255  for (j=0; j<=strat->sl; j++)
3256  {
3257  if (strat->pairtest[j])
3258  {
3259  for (i=strat->Bl; i>=0; i--)
3260  {
3261  if (pLPDivisibleBy(strat->S[j],strat->B[i].lcm))
3262  {
3263  deleteInL(strat->B,&strat->Bl,i,strat);
3264  strat->c3++;
3265  }
3266  }
3267  }
3268  }
3269  }
3270  else
3271 #endif
3272  {
3273  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3274  for (j=0; j<=strat->sl; j++)
3275  {
3276  if (strat->pairtest[j])
3277  {
3278  for (i=strat->Bl; i>=0; i--)
3279  {
3280  if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3281  {
3282  deleteInL(strat->B,&strat->Bl,i,strat);
3283  strat->c3++;
3284  }
3285  }
3286  }
3287  }
3288  }
3289  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3290  strat->pairtest=NULL;
3291  }
3292  if (strat->Gebauer || strat->fromT)
3293  {
3294  if (strat->sugarCrit)
3295  {
3296  /*
3297  *suppose L[j] == (s,r) and p/lcm(s,r)
3298  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3299  *and in case the sugar is o.k. then L[j] can be canceled
3300  */
3301  for (j=strat->Ll; j>=0; j--)
3302  {
3303  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3304  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3305  && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3306  {
3307  if (strat->L[j].p == strat->tail)
3308  {
3309  deleteInL(strat->L,&strat->Ll,j,strat);
3310  strat->c3++;
3311  }
3312  }
3313  }
3314  /*
3315  *this is GEBAUER-MOELLER:
3316  *in B all elements with the same lcm except the "best"
3317  *(i.e. the last one in B with this property) will be canceled
3318  */
3319  j = strat->Bl;
3320  loop /*cannot be changed into a for !!! */
3321  {
3322  if (j <= 0) break;
3323  i = j-1;
3324  loop
3325  {
3326  if (i < 0) break;
3327  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3328  {
3329  strat->c3++;
3330  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3331  {
3332  deleteInL(strat->B,&strat->Bl,i,strat);
3333  j--;
3334  }
3335  else
3336  {
3337  deleteInL(strat->B,&strat->Bl,j,strat);
3338  break;
3339  }
3340  }
3341  i--;
3342  }
3343  j--;
3344  }
3345  }
3346  else /*sugarCrit*/
3347  {
3348  /*
3349  *suppose L[j] == (s,r) and p/lcm(s,r)
3350  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3351  *and in case the sugar is o.k. then L[j] can be canceled
3352  */
3353  for (j=strat->Ll; j>=0; j--)
3354  {
3355  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3356  {
3357  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3358  {
3359  deleteInL(strat->L,&strat->Ll,j,strat);
3360  strat->c3++;
3361  }
3362  }
3363  }
3364  /*
3365  *this is GEBAUER-MOELLER:
3366  *in B all elements with the same lcm except the "best"
3367  *(i.e. the last one in B with this property) will be canceled
3368  */
3369  j = strat->Bl;
3370  loop /*cannot be changed into a for !!! */
3371  {
3372  if (j <= 0) break;
3373  for(i=j-1; i>=0; i--)
3374  {
3375  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3376  {
3377  strat->c3++;
3378  deleteInL(strat->B,&strat->Bl,i,strat);
3379  j--;
3380  }
3381  }
3382  j--;
3383  }
3384  }
3385  /*
3386  *the elements of B enter L
3387  */
3388  kMergeBintoL(strat);
3389  }
3390  else
3391  {
3392  for (j=strat->Ll; j>=0; j--)
3393  {
3394  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3395  {
3396  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3397  {
3398  deleteInL(strat->L,&strat->Ll,j,strat);
3399  strat->c3++;
3400  }
3401  }
3402  }
3403  /*
3404  *this is our MODIFICATION of GEBAUER-MOELLER:
3405  *First the elements of B enter L,
3406  *then we fix a lcm and the "best" element in L
3407  *(i.e the last in L with this lcm and of type (s,p))
3408  *and cancel all the other elements of type (r,p) with this lcm
3409  *except the case the element (s,r) has also the same lcm
3410  *and is on the worst position with respect to (s,p) and (r,p)
3411  */
3412  /*
3413  *B enters to L/their order with respect to B is permutated for elements
3414  *B[i].p with the same leading term
3415  */
3416  kMergeBintoL(strat);
3417  j = strat->Ll;
3418  loop /*cannot be changed into a for !!! */
3419  {
3420  if (j <= 0)
3421  {
3422  /*now L[0] cannot be canceled any more and the tail can be removed*/
3423  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3424  break;
3425  }
3426  if (strat->L[j].p2 == p)
3427  {
3428  i = j-1;
3429  loop
3430  {
3431  if (i < 0) break;
3432  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3433  {
3434  /*L[i] could be canceled but we search for a better one to cancel*/
3435  strat->c3++;
3436  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3437  && (pNext(strat->L[l].p) == strat->tail)
3438  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3439  && pDivisibleBy(p,strat->L[l].lcm))
3440  {
3441  /*
3442  *"NOT equal(...)" because in case of "equal" the element L[l]
3443  *is "older" and has to be from theoretical point of view behind
3444  *L[i], but we do not want to reorder L
3445  */
3446  strat->L[i].p2 = strat->tail;
3447  /*
3448  *L[l] will be canceled, we cannot cancel L[i] later on,
3449  *so we mark it with "tail"
3450  */
3451  deleteInL(strat->L,&strat->Ll,l,strat);
3452  i--;
3453  }
3454  else
3455  {
3456  deleteInL(strat->L,&strat->Ll,i,strat);
3457  }
3458  j--;
3459  }
3460  i--;
3461  }
3462  }
3463  else if (strat->L[j].p2 == strat->tail)
3464  {
3465  /*now L[j] cannot be canceled any more and the tail can be removed*/
3466  strat->L[j].p2 = p;
3467  }
3468  j--;
3469  }
3470  }
3471 }
3472 /*2
3473 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3474 *without the chain-criterion in B and L and enters B to L
3475 */
3476 void chainCritOpt_1 (poly,int,kStrategy strat)
3477 {
3478  if (strat->pairtest!=NULL)
3479  {
3480  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3481  strat->pairtest=NULL;
3482  }
3483  /*
3484  *the elements of B enter L
3485  */
3486  kMergeBintoL(strat);
3487 }
3488 /*2
3489 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3490 *using the chain-criterion in B and L and enters B to L
3491 */
3492 void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3493 {
3494  int i,j,l;
3495  kMergeBintoLSba(strat);
3496  j = strat->Ll;
3497  loop /*cannot be changed into a for !!! */
3498  {
3499  if (j <= 0)
3500  {
3501  /*now L[0] cannot be canceled any more and the tail can be removed*/
3502  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3503  break;
3504  }
3505  if (strat->L[j].p2 == p)
3506  {
3507  i = j-1;
3508  loop
3509  {
3510  if (i < 0) break;
3511  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3512  {
3513  /*L[i] could be canceled but we search for a better one to cancel*/
3514  strat->c3++;
3515  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3516  && (pNext(strat->L[l].p) == strat->tail)
3517  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3518  && pDivisibleBy(p,strat->L[l].lcm))
3519  {
3520  /*
3521  *"NOT equal(...)" because in case of "equal" the element L[l]
3522  *is "older" and has to be from theoretical point of view behind
3523  *L[i], but we do not want to reorder L
3524  */
3525  strat->L[i].p2 = strat->tail;
3526  /*
3527  *L[l] will be canceled, we cannot cancel L[i] later on,
3528  *so we mark it with "tail"
3529  */
3530  deleteInL(strat->L,&strat->Ll,l,strat);
3531  i--;
3532  }
3533  else
3534  {
3535  deleteInL(strat->L,&strat->Ll,i,strat);
3536  }
3537  j--;
3538  }
3539  i--;
3540  }
3541  }
3542  else if (strat->L[j].p2 == strat->tail)
3543  {
3544  /*now L[j] cannot be canceled any more and the tail can be removed*/
3545  strat->L[j].p2 = p;
3546  }
3547  j--;
3548  }
3549 }
3550 #ifdef HAVE_RATGRING
3551 void chainCritPart (poly p,int ecart,kStrategy strat)
3552 {
3553  int i,j,l;
3554 
3555  /*
3556  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3557  *In this case all elements in B such
3558  *that their lcm is divisible by the leading term of S[i] can be canceled
3559  */
3560  if (strat->pairtest!=NULL)
3561  {
3562  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3563  for (j=0; j<=strat->sl; j++)
3564  {
3565  if (strat->pairtest[j])
3566  {
3567  for (i=strat->Bl; i>=0; i--)
3568  {
3569  if (_p_LmDivisibleByPart(strat->S[j],currRing,
3570  strat->B[i].lcm,currRing,
3571  currRing->real_var_start,currRing->real_var_end))
3572  {
3573  if(TEST_OPT_DEBUG)
3574  {
3575  Print("chain-crit-part: S[%d]=",j);
3576  p_wrp(strat->S[j],currRing);
3577  Print(" divide B[%d].lcm=",i);
3578  p_wrp(strat->B[i].lcm,currRing);
3579  PrintLn();
3580  }
3581  deleteInL(strat->B,&strat->Bl,i,strat);
3582  strat->c3++;
3583  }
3584  }
3585  }
3586  }
3587  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3588  strat->pairtest=NULL;
3589  }
3590  if (strat->Gebauer || strat->fromT)
3591  {
3592  if (strat->sugarCrit)
3593  {
3594  /*
3595  *suppose L[j] == (s,r) and p/lcm(s,r)
3596  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3597  *and in case the sugar is o.k. then L[j] can be canceled
3598  */
3599  for (j=strat->Ll; j>=0; j--)
3600  {
3601  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3602  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3603  && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3604  {
3605  if (strat->L[j].p == strat->tail)
3606  {
3607  if(TEST_OPT_DEBUG)
3608  {
3609  PrintS("chain-crit-part: pCompareChainPart p=");
3610  p_wrp(p,currRing);
3611  Print(" delete L[%d]",j);
3612  p_wrp(strat->L[j].lcm,currRing);
3613  PrintLn();
3614  }
3615  deleteInL(strat->L,&strat->Ll,j,strat);
3616  strat->c3++;
3617  }
3618  }
3619  }
3620  /*
3621  *this is GEBAUER-MOELLER:
3622  *in B all elements with the same lcm except the "best"
3623  *(i.e. the last one in B with this property) will be canceled
3624  */
3625  j = strat->Bl;
3626  loop /*cannot be changed into a for !!! */
3627  {
3628  if (j <= 0) break;
3629  i = j-1;
3630  loop
3631  {
3632  if (i < 0) break;
3633  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3634  {
3635  strat->c3++;
3636  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3637  {
3638  if(TEST_OPT_DEBUG)
3639  {
3640  Print("chain-crit-part: sugar B[%d].lcm=",j);
3641  p_wrp(strat->B[j].lcm,currRing);
3642  Print(" delete B[%d]",i);
3643  p_wrp(strat->B[i].lcm,currRing);
3644  PrintLn();
3645  }
3646  deleteInL(strat->B,&strat->Bl,i,strat);
3647  j--;
3648  }
3649  else
3650  {
3651  if(TEST_OPT_DEBUG)
3652  {
3653  Print("chain-crit-part: sugar B[%d].lcm=",i);
3654  p_wrp(strat->B[i].lcm,currRing);
3655  Print(" delete B[%d]",j);
3656  p_wrp(strat->B[j].lcm,currRing);
3657  PrintLn();
3658  }
3659  deleteInL(strat->B,&strat->Bl,j,strat);
3660  break;
3661  }
3662  }
3663  i--;
3664  }
3665  j--;
3666  }
3667  }
3668  else /*sugarCrit*/
3669  {
3670  /*
3671  *suppose L[j] == (s,r) and p/lcm(s,r)
3672  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3673  *and in case the sugar is o.k. then L[j] can be canceled
3674  */
3675  for (j=strat->Ll; j>=0; j--)
3676  {
3677  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3678  {
3679  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3680  {
3681  if(TEST_OPT_DEBUG)
3682  {
3683  PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3684  p_wrp(p,currRing);
3685  Print(" delete L[%d]",j);
3686  p_wrp(strat->L[j].lcm,currRing);
3687  PrintLn();
3688  }
3689  deleteInL(strat->L,&strat->Ll,j,strat);
3690  strat->c3++;
3691  }
3692  }
3693  }
3694  /*
3695  *this is GEBAUER-MOELLER:
3696  *in B all elements with the same lcm except the "best"
3697  *(i.e. the last one in B with this property) will be canceled
3698  */
3699  j = strat->Bl;
3700  loop /*cannot be changed into a for !!! */
3701  {
3702  if (j <= 0) break;
3703  for(i=j-1; i>=0; i--)
3704  {
3705  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3706  {
3707  if(TEST_OPT_DEBUG)
3708  {
3709  Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3710  p_wrp(strat->B[j].lcm,currRing);
3711  Print(" delete B[%d]\n",i);
3712  }
3713  strat->c3++;
3714  deleteInL(strat->B,&strat->Bl,i,strat);
3715  j--;
3716  }
3717  }
3718  j--;
3719  }
3720  }
3721  /*
3722  *the elements of B enter L
3723  */
3724  kMergeBintoL(strat);
3725  }
3726  else
3727  {
3728  for (j=strat->Ll; j>=0; j--)
3729  {
3730  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3731  {
3732  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3733  {
3734  if(TEST_OPT_DEBUG)
3735  {
3736  PrintS("chain-crit-part: pCompareChainPart p=");
3737  p_wrp(p,currRing);
3738  Print(" delete L[%d]",j);
3739  p_wrp(strat->L[j].lcm,currRing);
3740  PrintLn();
3741  }
3742  deleteInL(strat->L,&strat->Ll,j,strat);
3743  strat->c3++;
3744  }
3745  }
3746  }
3747  /*
3748  *this is our MODIFICATION of GEBAUER-MOELLER:
3749  *First the elements of B enter L,
3750  *then we fix a lcm and the "best" element in L
3751  *(i.e the last in L with this lcm and of type (s,p))
3752  *and cancel all the other elements of type (r,p) with this lcm
3753  *except the case the element (s,r) has also the same lcm
3754  *and is on the worst position with respect to (s,p) and (r,p)
3755  */
3756  /*
3757  *B enters to L/their order with respect to B is permutated for elements
3758  *B[i].p with the same leading term
3759  */
3760  kMergeBintoL(strat);
3761  j = strat->Ll;
3762  loop /*cannot be changed into a for !!! */
3763  {
3764  if (j <= 0)
3765  {
3766  /*now L[0] cannot be canceled any more and the tail can be removed*/
3767  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3768  break;
3769  }
3770  if (strat->L[j].p2 == p)
3771  {
3772  i = j-1;
3773  loop
3774  {
3775  if (i < 0) break;
3776  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3777  {
3778  /*L[i] could be canceled but we search for a better one to cancel*/
3779  strat->c3++;
3780  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3781  && (pNext(strat->L[l].p) == strat->tail)
3782  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3784  strat->L[l].lcm,currRing,
3785  currRing->real_var_start, currRing->real_var_end))
3786 
3787  {
3788  /*
3789  *"NOT equal(...)" because in case of "equal" the element L[l]
3790  *is "older" and has to be from theoretical point of view behind
3791  *L[i], but we do not want to reorder L
3792  */
3793  strat->L[i].p2 = strat->tail;
3794  /*
3795  *L[l] will be canceled, we cannot cancel L[i] later on,
3796  *so we mark it with "tail"
3797  */
3798  if(TEST_OPT_DEBUG)
3799  {
3800  PrintS("chain-crit-part: divisible_by p=");
3801  p_wrp(p,currRing);
3802  Print(" delete L[%d]",l);
3803  p_wrp(strat->L[l].lcm,currRing);
3804  PrintLn();
3805  }
3806  deleteInL(strat->L,&strat->Ll,l,strat);
3807  i--;
3808  }
3809  else
3810  {
3811  if(TEST_OPT_DEBUG)
3812  {
3813  PrintS("chain-crit-part: divisible_by(2) p=");
3814  p_wrp(p,currRing);
3815  Print(" delete L[%d]",i);
3816  p_wrp(strat->L[i].lcm,currRing);
3817  PrintLn();
3818  }
3819  deleteInL(strat->L,&strat->Ll,i,strat);
3820  }
3821  j--;
3822  }
3823  i--;
3824  }
3825  }
3826  else if (strat->L[j].p2 == strat->tail)
3827  {
3828  /*now L[j] cannot be canceled any more and the tail can be removed*/
3829  strat->L[j].p2 = p;
3830  }
3831  j--;
3832  }
3833  }
3834 }
3835 #endif
3836 
3837 /*2
3838 *(s[0],h),...,(s[k],h) will be put to the pairset L
3839 */
3840 void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR/* = -1*/)
3841 {
3842 
3843  if ((strat->syzComp==0)
3844  || (pGetComp(h)<=strat->syzComp))
3845  {
3846  int j;
3847  BOOLEAN new_pair=FALSE;
3848 
3849  if (pGetComp(h)==0)
3850  {
3851  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3852  if ((isFromQ)&&(strat->fromQ!=NULL))
3853  {
3854  for (j=0; j<=k; j++)
3855  {
3856  if (!strat->fromQ[j])
3857  {
3858  new_pair=TRUE;
3859  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3860  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3861  }
3862  }
3863  }
3864  else
3865  {
3866  new_pair=TRUE;
3867  for (j=0; j<=k; j++)
3868  {
3869  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3870  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3871  }
3872  }
3873  }
3874  else
3875  {
3876  for (j=0; j<=k; j++)
3877  {
3878  if ((pGetComp(h)==pGetComp(strat->S[j]))
3879  || (pGetComp(strat->S[j])==0))
3880  {
3881  new_pair=TRUE;
3882  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3883  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3884  }
3885  }
3886  }
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  kMergeBintoL(strat);
3897  }
3898 }
3899 
3900 /*2
3901 *(s[0],h),...,(s[k],h) will be put to the pairset L
3902 *using signatures <= only for signature-based standard basis algorithms
3903 */
3904 
3905 void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3906 {
3907 
3908  if ((strat->syzComp==0)
3909  || (pGetComp(h)<=strat->syzComp))
3910  {
3911  int j;
3912  BOOLEAN new_pair=FALSE;
3913 
3914  if (pGetComp(h)==0)
3915  {
3916  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3917  if ((isFromQ)&&(strat->fromQ!=NULL))
3918  {
3919  for (j=0; j<=k; j++)
3920  {
3921  if (!strat->fromQ[j])
3922  {
3923  new_pair=TRUE;
3924  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3925  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3926  }
3927  }
3928  }
3929  else
3930  {
3931  new_pair=TRUE;
3932  for (j=0; j<=k; j++)
3933  {
3934  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3935  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3936  }
3937  }
3938  }
3939  else
3940  {
3941  for (j=0; j<=k; j++)
3942  {
3943  if ((pGetComp(h)==pGetComp(strat->S[j]))
3944  || (pGetComp(strat->S[j])==0))
3945  {
3946  new_pair=TRUE;
3947  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3948  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3949  }
3950  }
3951  }
3952 
3953  if (new_pair)
3954  {
3955 #ifdef HAVE_RATGRING
3956  if (currRing->real_var_start>0)
3957  chainCritPart(h,ecart,strat);
3958  else
3959 #endif
3960  strat->chainCrit(h,ecart,strat);
3961  }
3962  }
3963 }
3964 
3965 void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3966 {
3967 
3968  if ((strat->syzComp==0)
3969  || (pGetComp(h)<=strat->syzComp))
3970  {
3971  int j;
3972 
3973  if (pGetComp(h)==0)
3974  {
3975  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3976  if ((isFromQ)&&(strat->fromQ!=NULL))
3977  {
3978  for (j=0; j<=k && !strat->sigdrop; j++)
3979  {
3980  if (!strat->fromQ[j])
3981  {
3982  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3983  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3984  }
3985  }
3986  }
3987  else
3988  {
3989  for (j=0; j<=k && !strat->sigdrop; j++)
3990  {
3991  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3992  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3993  }
3994  }
3995  }
3996  else
3997  {
3998  for (j=0; j<=k && !strat->sigdrop; j++)
3999  {
4000  if ((pGetComp(h)==pGetComp(strat->S[j]))
4001  || (pGetComp(strat->S[j])==0))
4002  {
4003  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4004  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4005  }
4006  }
4007  }
4008 
4009 #if 0
4010  if (new_pair)
4011  {
4012 #ifdef HAVE_RATGRING
4013  if (currRing->real_var_start>0)
4014  chainCritPart(h,ecart,strat);
4015  else
4016 #endif
4017  strat->chainCrit(h,ecart,strat);
4018  }
4019 #endif
4020  }
4021 }
4022 #ifdef HAVE_RINGS
4023 /*2
4024 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
4025 *using the chain-criterion in B and L and enters B to L
4026 */
4027 void chainCritRing (poly p,int, kStrategy strat)
4028 {
4029  int i,j,l;
4030  /*
4031  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4032  *In this case all elements in B such
4033  *that their lcm is divisible by the leading term of S[i] can be canceled
4034  */
4035  if (strat->pairtest!=NULL)
4036  {
4037  {
4038  /*- i.e. there is an i with pairtest[i]==TRUE -*/
4039  for (j=0; j<=strat->sl; j++)
4040  {
4041  if (strat->pairtest[j])
4042  {
4043  for (i=strat->Bl; i>=0; i--)
4044  {
4045  if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4046  {
4047 #ifdef KDEBUG
4048  if (TEST_OPT_DEBUG)
4049  {
4050  PrintS("--- chain criterion func chainCritRing type 1\n");
4051  PrintS("strat->S[j]:");
4052  wrp(strat->S[j]);
4053  PrintS(" strat->B[i].lcm:");
4054  wrp(strat->B[i].lcm);PrintLn();
4055  pWrite(strat->B[i].p);
4056  pWrite(strat->B[i].p1);
4057  pWrite(strat->B[i].p2);
4058  wrp(strat->B[i].lcm);
4059  PrintLn();
4060  }
4061 #endif
4062  deleteInL(strat->B,&strat->Bl,i,strat);
4063  strat->c3++;
4064  }
4065  }
4066  }
4067  }
4068  }
4069  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4070  strat->pairtest=NULL;
4071  }
4072  assume(!(strat->Gebauer || strat->fromT));
4073  for (j=strat->Ll; j>=0; j--)
4074  {
4075  if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4076  {
4077  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4078  {
4079  if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4080  {
4081  deleteInL(strat->L,&strat->Ll,j,strat);
4082  strat->c3++;
4083 #ifdef KDEBUG
4084  if (TEST_OPT_DEBUG)
4085  {
4086  PrintS("--- chain criterion func chainCritRing type 2\n");
4087  PrintS("strat->L[j].p:");
4088  wrp(strat->L[j].p);
4089  PrintS(" p:");
4090  wrp(p);
4091  PrintLn();
4092  }
4093 #endif
4094  }
4095  }
4096  }
4097  }
4098  /*
4099  *this is our MODIFICATION of GEBAUER-MOELLER:
4100  *First the elements of B enter L,
4101  *then we fix a lcm and the "best" element in L
4102  *(i.e the last in L with this lcm and of type (s,p))
4103  *and cancel all the other elements of type (r,p) with this lcm
4104  *except the case the element (s,r) has also the same lcm
4105  *and is on the worst position with respect to (s,p) and (r,p)
4106  */
4107  /*
4108  *B enters to L/their order with respect to B is permutated for elements
4109  *B[i].p with the same leading term
4110  */
4111  kMergeBintoL(strat);
4112  j = strat->Ll;
4113  loop /*cannot be changed into a for !!! */
4114  {
4115  if (j <= 0)
4116  {
4117  /*now L[0] cannot be canceled any more and the tail can be removed*/
4118  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4119  break;
4120  }
4121  if (strat->L[j].p2 == p) // Was the element added from B?
4122  {
4123  i = j-1;
4124  loop
4125  {
4126  if (i < 0) break;
4127  // Element is from B and has the same lcm as L[j]
4128  if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4129  && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4130  {
4131  /*L[i] could be canceled but we search for a better one to cancel*/
4132  strat->c3++;
4133 #ifdef KDEBUG
4134  if (TEST_OPT_DEBUG)
4135  {
4136  PrintS("--- chain criterion func chainCritRing type 3\n");
4137  PrintS("strat->L[j].lcm:");
4138  wrp(strat->L[j].lcm);
4139  PrintS(" strat->L[i].lcm:");
4140  wrp(strat->L[i].lcm);
4141  PrintLn();
4142  }
4143 #endif
4144  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4145  && (pNext(strat->L[l].p) == strat->tail)
4146  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4147  && pDivisibleBy(p,strat->L[l].lcm))
4148  {
4149  /*
4150  *"NOT equal(...)" because in case of "equal" the element L[l]
4151  *is "older" and has to be from theoretical point of view behind
4152  *L[i], but we do not want to reorder L
4153  */
4154  strat->L[i].p2 = strat->tail;
4155  /*
4156  *L[l] will be canceled, we cannot cancel L[i] later on,
4157  *so we mark it with "tail"
4158  */
4159  deleteInL(strat->L,&strat->Ll,l,strat);
4160  i--;
4161  }
4162  else
4163  {
4164  deleteInL(strat->L,&strat->Ll,i,strat);
4165  }
4166  j--;
4167  }
4168  i--;
4169  }
4170  }
4171  else if (strat->L[j].p2 == strat->tail)
4172  {
4173  /*now L[j] cannot be canceled any more and the tail can be removed*/
4174  strat->L[j].p2 = p;
4175  }
4176  j--;
4177  }
4178 }
4179 #endif
4180 
4181 #ifdef HAVE_RINGS
4182 long ind2(long arg)
4183 {
4184  long ind = 0;
4185  if (arg <= 0) return 0;
4186  while (arg%2 == 0)
4187  {
4188  arg = arg / 2;
4189  ind++;
4190  }
4191  return ind;
4192 }
4193 
4194 long ind_fact_2(long arg)
4195 {
4196  long ind = 0;
4197  if (arg <= 0) return 0;
4198  if (arg%2 == 1) { arg--; }
4199  while (arg > 0)
4200  {
4201  ind += ind2(arg);
4202  arg = arg - 2;
4203  }
4204  return ind;
4205 }
4206 #endif
4207 
4208 #ifdef HAVE_VANIDEAL
4209 long twoPow(long arg)
4210 {
4211  return 1L << arg;
4212 }
4213 
4214 /*2
4215 * put the pair (p, f) in B and f in T
4216 */
4217 void enterOneZeroPairRing (poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR = -1)
4218 {
4219  int l,j,compare,compareCoeff;
4220  LObject Lp;
4221 
4222 #ifdef KDEBUG
4223  Lp.ecart=0; Lp.length=0;
4224 #endif
4225  /*- computes the lcm(s[i],p) -*/
4226  Lp.lcm = p_Lcm(p,f,Lp.lcm,currRing);
4227  pSetCoeff(Lp.lcm, nLcm(pGetCoeff(p), pGetCoeff(f), currRing));
4228  assume(!strat->sugarCrit);
4229  assume(!strat->fromT);
4230  /*
4231  *the set B collects the pairs of type (S[j],p)
4232  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
4233  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
4234  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
4235  */
4236  for(j = strat->Bl;j>=0;j--)
4237  {
4238  compare=pDivCompRing(strat->B[j].lcm,Lp.lcm);
4239  compareCoeff = nDivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(Lp.lcm));
4240  if (compareCoeff == 0 || compare == compareCoeff)
4241  {
4242  if (compare == 1)
4243  {
4244  strat->c3++;
4245  pLmDelete(Lp.lcm);
4246  return;
4247  }
4248  else
4249  if (compare == -1)
4250  {
4251  deleteInL(strat->B,&strat->Bl,j,strat);
4252  strat->c3++;
4253  }
4254  }
4255  if (compare == pDivComp_EQUAL)
4256  {
4257  // Add hint for same LM and direction of LC (later) (TODO Oliver)
4258  if (compareCoeff == 1)
4259  {
4260  strat->c3++;
4261  pLmDelete(Lp.lcm);
4262  return;
4263  }
4264  else
4265  if (compareCoeff == -1)
4266  {
4267  deleteInL(strat->B,&strat->Bl,j,strat);
4268  strat->c3++;
4269  }
4270  }
4271  }
4272  /*
4273  *the pair (S[i],p) enters B if the spoly != 0
4274  */
4275  /*- compute the short s-polynomial -*/
4276  if ((f==NULL) || (p==NULL)) return;
4277  pNorm(p);
4278  {
4279  Lp.p = ksCreateShortSpoly(f, p, strat->tailRing);
4280  }
4281  if (Lp.p == NULL) //deactivated, as we are adding pairs with zeropoly and not from S
4282  {
4283  /*- the case that the s-poly is 0 -*/
4284 // if (strat->pairtest==NULL) initPairtest(strat);
4285 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
4286 // strat->pairtest[strat->sl+1] = TRUE;
4287  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
4288  /*
4289  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
4290  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
4291  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
4292  *term of p divides the lcm(s,r)
4293  *(this canceling should be done here because
4294  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
4295  *the first case is handeled in chainCrit
4296  */
4297  if (Lp.lcm!=NULL) pLmDelete(Lp.lcm);
4298  }
4299  else
4300  {
4301  /*- the pair (S[i],p) enters B -*/
4302  Lp.p1 = f;
4303  Lp.p2 = p;
4304 
4305  pNext(Lp.p) = strat->tail;
4306 
4307  LObject tmp_h(f, currRing, strat->tailRing);
4308  tmp_h.SetShortExpVector();
4309  strat->initEcart(&tmp_h);
4310  tmp_h.sev = pGetShortExpVector(tmp_h.p);
4311  tmp_h.t_p = t_p;
4312 
4313  enterT(tmp_h, strat, strat->tl + 1);
4314 
4315  if (atR >= 0)
4316  {
4317  Lp.i_r2 = atR;
4318  Lp.i_r1 = strat->tl;
4319  }
4320 
4321  strat->initEcartPair(&Lp,f,p,0/*strat->ecartS[i]*/,ecart); // Attention: TODO: break ecart
4322  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
4323  enterL(&strat->B, &strat->Bl, &strat->Bmax, Lp, l);
4324  }
4325 }
4326 
4327 /* Helper for kCreateZeroPoly
4328  * enumerating the exponents
4329 ring r = 2^2, (a, b, c), lp; ideal G0 = system("createG0"); ideal G = interred(G0); ncols(G0); ncols(G);
4330  */
4331 
4332 int nextZeroSimplexExponent (long exp[], long ind[], long cexp[], long cind[], long* cabsind, long step[], long bound, long N)
4333 /* gives the next exponent from the set H_1 */
4334 {
4335  long add = ind2(cexp[1] + 2);
4336  if ((*cabsind < bound) && (*cabsind - step[1] + add < bound))
4337  {
4338  cexp[1] += 2;
4339  cind[1] += add;
4340  *cabsind += add;
4341  }
4342  else
4343  {
4344  // cabsind >= habsind
4345  if (N == 1) return 0;
4346  int i = 1;
4347  while (exp[i] == cexp[i] && i <= N) i++;
4348  cexp[i] = exp[i];
4349  *cabsind -= cind[i];
4350  cind[i] = ind[i];
4351  step[i] = 500000;
4352  *cabsind += cind[i];
4353  // Print("in: %d\n", *cabsind);
4354  i += 1;
4355  if (i > N) return 0;
4356  do
4357  {
4358  step[1] = 500000;
4359  for (int j = i + 1; j <= N; j++)
4360  {
4361  if (step[1] > step[j]) step[1] = step[j];
4362  }
4363  add = ind2(cexp[i] + 2);
4364  if (*cabsind - step[1] + add >= bound)
4365  {
4366  cexp[i] = exp[i];
4367  *cabsind -= cind[i];
4368  cind[i] = ind[i];
4369  *cabsind += cind[i];
4370  step[i] = 500000;
4371  i += 1;
4372  if (i > N) return 0;
4373  }
4374  else step[1] = -1;
4375  } while (step[1] != -1);
4376  step[1] = 500000;
4377  cexp[i] += 2;
4378  cind[i] += add;
4379  *cabsind += add;
4380  if (add < step[i]) step[i] = add;
4381  for (i = 2; i <= N; i++)
4382  {
4383  if (step[1] > step[i]) step[1] = step[i];
4384  }
4385  }
4386  return 1;
4387 }
4388 
4389 /*
4390  * Creates the zero Polynomial on position exp
4391  * long exp[] : exponent of leading term
4392  * cabsind : total 2-ind of exp (if -1 will be computed)
4393  * poly* t_p : will hold the LT in tailRing
4394  * leadRing : ring for the LT
4395  * tailRing : ring for the tail
4396  */
4397 
4398 poly kCreateZeroPoly(long exp[], long cabsind, poly* t_p, ring leadRing, ring tailRing)
4399 {
4400 
4401  poly zeroPoly = NULL;
4402 
4403  number tmp1;
4404  poly tmp2, tmp3;
4405 
4406  if (cabsind == -1)
4407  {
4408  cabsind = 0;
4409  for (int i = 1; i <= leadRing->N; i++)
4410  {
4411  cabsind += ind_fact_2(exp[i]);
4412  }
4413 // Print("cabsind: %d\n", cabsind);
4414  }
4415  if (cabsind < leadRing->ch)
4416  {
4417  zeroPoly = p_ISet(twoPow(leadRing->ch - cabsind), tailRing);
4418  }
4419  else
4420  {
4421  zeroPoly = p_ISet(1, tailRing);
4422  }
4423  for (int i = 1; i <= leadRing->N; i++)
4424  {
4425  for (long j = 1; j <= exp[i]; j++)
4426  {
4427  tmp1 = nInit(j);
4428  tmp2 = p_ISet(1, tailRing);
4429  p_SetExp(tmp2, i, 1, tailRing);
4430  p_Setm(tmp2, tailRing);
4431  if (nIsZero(tmp1))
4432  { // should nowbe obsolet, test ! TODO OLIVER
4433  zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
4434  }
4435  else
4436  {
4437  tmp3 = p_NSet(nCopy(tmp1), tailRing);
4438  zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing);
4439  }
4440  }
4441  }
4442  tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing);
4443  for (int i = 1; i <= leadRing->N; i++)
4444  {
4445  pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
4446  }
4447  p_Setm(tmp2, leadRing);
4448  *t_p = zeroPoly;
4449  zeroPoly = pNext(zeroPoly);
4450  pNext(*t_p) = NULL;
4451  pNext(tmp2) = zeroPoly;
4452  return tmp2;
4453 }
4454 
4455 // #define OLI_DEBUG
4456 
4457 /*
4458  * Generate the s-polynomial for the virtual set of zero-polynomials
4459  */
4460 
4461 void initenterzeropairsRing (poly p, int ecart, kStrategy strat, int atR)
4462 {
4463  // Initialize
4464  long exp[50]; // The exponent of \hat{X} (basepoint)
4465  long cexp[50]; // The current exponent for iterating over all
4466  long ind[50]; // The power of 2 in the i-th component of exp
4467  long cind[50]; // analog for cexp
4468  long mult[50]; // How to multiply the elements of G
4469  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4470  long habsind = 0; // The abs. index of the coefficient of h
4471  long step[50]; // The last increases
4472  for (int i = 1; i <= currRing->N; i++)
4473  {
4474  exp[i] = p_GetExp(p, i, currRing);
4475  if (exp[i] & 1 != 0)
4476  {
4477  exp[i] = exp[i] - 1;
4478  mult[i] = 1;
4479  }
4480  cexp[i] = exp[i];
4481  ind[i] = ind_fact_2(exp[i]);
4482  cabsind += ind[i];
4483  cind[i] = ind[i];
4484  step[i] = 500000;
4485  }
4486  step[1] = 500000;
4487  habsind = ind2(n_Int(pGetCoeff(p), currRing->cf);
4488  long bound = currRing->ch - habsind;
4489 #ifdef OLI_DEBUG
4490  PrintS("-------------\npoly :");
4491  wrp(p);
4492  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4493  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4494  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4495  Print("bound : %d\n", bound);
4496  Print("cind : %d\n", cabsind);
4497 #endif
4498  if (cabsind == 0)
4499  {
4500  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4501  {
4502  return;
4503  }
4504  }
4505  // Now the whole simplex
4506  do
4507  {
4508  // Build s-polynomial
4509  // 2**ind-def * mult * g - exp-def * h
4510  poly t_p;
4511  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, strat->tailRing);
4512 #ifdef OLI_DEBUG
4513  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4514  PrintS("zPoly : ");
4515  wrp(zeroPoly);
4516  PrintLn();
4517 #endif
4518  enterOneZeroPairRing(zeroPoly, t_p, p, ecart, strat, atR);
4519  }
4520  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4521 }
4522 
4523 /*
4524  * Create the Groebner basis of the vanishing polynomials.
4525  */
4526 
4527 ideal createG0()
4528 {
4529  // Initialize
4530  long exp[50]; // The exponent of \hat{X} (basepoint)
4531  long cexp[50]; // The current exponent for iterating over all
4532  long ind[50]; // The power of 2 in the i-th component of exp
4533  long cind[50]; // analog for cexp
4534  long mult[50]; // How to multiply the elements of G
4535  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4536  long habsind = 0; // The abs. index of the coefficient of h
4537  long step[50]; // The last increases
4538  for (int i = 1; i <= currRing->N; i++)
4539  {
4540  exp[i] = 0;
4541  cexp[i] = exp[i];
4542  ind[i] = 0;
4543  step[i] = 500000;
4544  cind[i] = ind[i];
4545  }
4546  long bound = currRing->ch;
4547  step[1] = 500000;
4548 #ifdef OLI_DEBUG
4549  PrintS("-------------\npoly :");
4550 // wrp(p);
4551  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4552  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4553  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4554  Print("bound : %d\n", bound);
4555  Print("cind : %d\n", cabsind);
4556 #endif
4557  if (cabsind == 0)
4558  {
4559  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4560  {
4561  return idInit(1, 1);
4562  }
4563  }
4564  ideal G0 = idInit(1, 1);
4565  // Now the whole simplex
4566  do
4567  {
4568  // Build s-polynomial
4569  // 2**ind-def * mult * g - exp-def * h
4570  poly t_p;
4571  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, currRing);
4572 #ifdef OLI_DEBUG
4573  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4574  PrintS("zPoly : ");
4575  wrp(zeroPoly);
4576  PrintLn();
4577 #endif
4578  // Add to ideal
4579  pEnlargeSet(&(G0->m), IDELEMS(G0), 1);
4580  IDELEMS(G0) += 1;
4581  G0->m[IDELEMS(G0) - 1] = zeroPoly;
4582  }
4583  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4584  idSkipZeroes(G0);
4585  return G0;
4586 }
4587 #endif
4588 
4589 #ifdef HAVE_RINGS
4590 /*2
4591 *(s[0],h),...,(s[k],h) will be put to the pairset L
4592 */
4593 void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4594 {
4595  if (!nIsOne(pGetCoeff(h)))
4596  {
4597  int j;
4598  BOOLEAN new_pair=FALSE;
4599 
4600  if (pGetComp(h)==0)
4601  {
4602  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4603  if ((isFromQ)&&(strat->fromQ!=NULL))
4604  {
4605  for (j=0; j<=k; j++)
4606  {
4607  if (!strat->fromQ[j])
4608  {
4609  new_pair=TRUE;
4610  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4611  }
4612  }
4613  }
4614  else
4615  {
4616  new_pair=TRUE;
4617  for (j=0; j<=k; j++)
4618  {
4619  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4620  }
4621  }
4622  }
4623  else
4624  {
4625  for (j=0; j<=k; j++)
4626  {
4627  if ((pGetComp(h)==pGetComp(strat->S[j]))
4628  || (pGetComp(strat->S[j])==0))
4629  {
4630  new_pair=TRUE;
4631  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4632  }
4633  }
4634  }
4635  if (new_pair)
4636  {
4637  #ifdef HAVE_RATGRING
4638  if (currRing->real_var_start>0)
4639  chainCritPart(h,ecart,strat);
4640  else
4641  #endif
4642  strat->chainCrit(h,ecart,strat);
4643  }
4644  kMergeBintoL(strat);
4645  }
4646 }
4647 
4648 static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4649 {
4650  const int iCompH = pGetComp(h);
4651  if (!nIsOne(pGetCoeff(h)))
4652  {
4653  int j;
4654 
4655  for (j=0; j<=k && !strat->sigdrop; j++)
4656  {
4657  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4658 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4659 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4660  if (((iCompH == pGetComp(strat->S[j]))
4661  || (0 == pGetComp(strat->S[j])))
4662  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4663  {
4664  enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4665  }
4666  }
4667  }
4668 }
4669 #endif
4670 
4671 #ifdef HAVE_RINGS
4672 /*2
4673 * Generates spoly(0, h) if applicable. Assumes ring in Z/2^n.
4674 */
4676 {
4677  if (nIsOne(pGetCoeff(h))) return;
4678  number gcd;
4679  bool go = false;
4680  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4681  {
4682  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4683  go = true;
4684  }
4685  else
4686  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4687  if (go || !nIsOne(gcd))
4688  {
4689  poly p = h->next;
4690  if (!go)
4691  {
4692  number tmp = gcd;
4693  gcd = n_Ann(gcd,currRing->cf);
4694  nDelete(&tmp);
4695  }
4696  p_Test(p,strat->tailRing);
4697  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4698  nDelete(&gcd);
4699 
4700  if (p != NULL)
4701  {
4702  if (TEST_OPT_PROT)
4703  {
4704  PrintS("Z");
4705  }
4706 #ifdef KDEBUG
4707  if (TEST_OPT_DEBUG)
4708  {
4709  PrintS("--- create zero spoly: ");
4710  p_wrp(h,currRing,strat->tailRing);
4711  PrintS(" ---> ");
4712  }
4713 #endif
4714  poly tmp = pInit();
4715  pSetCoeff0(tmp, pGetCoeff(p));
4716  for (int i = 1; i <= rVar(currRing); i++)
4717  {
4718  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4719  }
4721  {
4722  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4723  }
4724  p_Setm(tmp, currRing);
4725  p = p_LmFreeAndNext(p, strat->tailRing);
4726  pNext(tmp) = p;
4727  LObject Lp;
4728  Lp.Init();
4729  Lp.p = tmp;
4730  Lp.tailRing = strat->tailRing;
4731  int posx;
4732  if (Lp.p!=NULL)
4733  {
4734  strat->initEcart(&Lp);
4735  if (strat->Ll==-1)
4736  posx =0;
4737  else
4738  posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4739  Lp.sev = pGetShortExpVector(Lp.p);
4740  if (strat->tailRing != currRing)
4741  {
4742  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4743  }
4744 #ifdef KDEBUG
4745  if (TEST_OPT_DEBUG)
4746  {
4747  p_wrp(tmp,currRing,strat->tailRing);
4748  PrintLn();
4749  }
4750 #endif
4751  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4752  }
4753  }
4754  }
4755  nDelete(&gcd);
4756 }
4757 
4758 void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
4759 {
4760  if (nIsOne(pGetCoeff(h))) return;
4761  number gcd;
4762  bool go = false;
4763  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4764  {
4765  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4766  go = true;
4767  }
4768  else
4769  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4770  if (go || !nIsOne(gcd))
4771  {
4772  poly p = h->next;
4773  if (!go)
4774  {
4775  number tmp = gcd;
4776  gcd = n_Ann(gcd,currRing->cf);
4777  nDelete(&tmp);
4778  }
4779  p_Test(p,strat->tailRing);
4780  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4781 
4782  if (p != NULL)
4783  {
4784  if (TEST_OPT_PROT)
4785  {
4786  PrintS("Z");
4787  }
4788 #ifdef KDEBUG
4789  if (TEST_OPT_DEBUG)
4790  {
4791  PrintS("--- create zero spoly: ");
4792  p_wrp(h,currRing,strat->tailRing);
4793  PrintS(" ---> ");
4794  }
4795 #endif
4796  poly tmp = pInit();
4797  pSetCoeff0(tmp, pGetCoeff(p));
4798  for (int i = 1; i <= rVar(currRing); i++)
4799  {
4800  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4801  }
4803  {
4804  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4805  }
4806  p_Setm(tmp, currRing);
4807  p = p_LmFreeAndNext(p, strat->tailRing);
4808  pNext(tmp) = p;
4809  LObject Lp;
4810  Lp.Init();
4811  Lp.p = tmp;
4812  //printf("\nOld\n");pWrite(h);pWrite(hSig);
4813  #if EXT_POLY_NEW
4814  Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4815  if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4816  {
4817  strat->sigdrop = TRUE;
4818  //Try to reduce it as far as we can via redRing
4819  int red_result = redRing(&Lp,strat);
4820  if(red_result == 0)
4821  {
4822  // Cancel the sigdrop
4823  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4824  strat->sigdrop = FALSE;
4825  return;
4826  }
4827  else
4828  {
4829  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4830  #if 1
4831  strat->enterS(Lp,0,strat,strat->tl);
4832  #endif
4833  return;
4834  }
4835 
4836  }
4837  #else
4838  Lp.sig = pOne();
4839  if(strat->Ll >= 0)
4840  p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4841  else
4842  p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4843  #endif
4844  Lp.tailRing = strat->tailRing;
4845  int posx;
4846  if (Lp.p!=NULL)
4847  {
4848  strat->initEcart(&Lp);
4849  if (strat->Ll==-1)
4850  posx =0;
4851  else
4852  posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4853  Lp.sev = pGetShortExpVector(Lp.p);
4854  if (strat->tailRing != currRing)
4855  {
4856  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4857  }
4858 #ifdef KDEBUG
4859  if (TEST_OPT_DEBUG)
4860  {
4861  p_wrp(tmp,currRing,strat->tailRing);
4862  PrintLn();
4863  }
4864 #endif
4865  //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4866  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4867  }
4868  }
4869  nDelete(&gcd);
4870  }
4871  nDelete(&gcd);
4872 }
4873 #endif
4874 
4875 #ifdef HAVE_RINGS
4876 void clearSbatch (poly h,int k,int pos,kStrategy strat)
4877 {
4878  int j = pos;
4879  if ( (!strat->fromT)
4880  && ((strat->syzComp==0)
4881  ||(pGetComp(h)<=strat->syzComp)
4882  ))
4883  {
4884  // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4885  unsigned long h_sev = pGetShortExpVector(h);
4886  loop
4887  {
4888  if (j > k) break;
4889  clearS(h,h_sev, &j,&k,strat);
4890  j++;
4891  }
4892  // Print("end clearS sl=%d\n",strat->sl);
4893  }
4894 }
4895 #endif
4896 
4897 #ifdef HAVE_RINGS
4898 /*2
4899 * Generates a sufficient set of spolys (maybe just a finite generating
4900 * set of the syzygys)
4901 */
4902 void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4903 {
4905 #if HAVE_SHIFTBBA
4906  assume(!rIsLPRing(currRing)); /* LP should use enterpairsShift */
4907 #endif
4908  // enter also zero divisor * poly, if this is non zero and of smaller degree
4909  if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat);
4910  initenterstrongPairs(h, k, ecart, 0, strat, atR);
4911  initenterpairs(h, k, ecart, 0, strat, atR);
4912  clearSbatch(h, k, pos, strat);
4913 }
4914 
4915 void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4916 {
4918  // enter also zero divisor * poly, if this is non zero and of smaller degree
4919  if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4920  if(strat->sigdrop) return;
4921  initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4922  if(strat->sigdrop) return;
4923  initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4924  if(strat->sigdrop) return;
4925  clearSbatch(h, k, pos, strat);
4926 }
4927 #endif
4928 
4929 /*2
4930 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4931 *superfluous elements in S will be deleted
4932 */
4933 void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4934 {
4935  int j=pos;
4936 
4938  initenterpairs(h,k,ecart,0,strat, atR);
4939  if ( (!strat->fromT)
4940  && ((strat->syzComp==0)
4941  ||(pGetComp(h)<=strat->syzComp)))
4942  {
4943  unsigned long h_sev = pGetShortExpVector(h);
4944  loop
4945  {
4946  if (j > k) break;
4947  clearS(h,h_sev, &j,&k,strat);
4948  j++;
4949  }
4950  }
4951 }
4952 
4953 /*2
4954 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4955 *superfluous elements in S will be deleted
4956 *this is a special variant of signature-based algorithms including the
4957 *signatures for criteria checks
4958 */
4959 void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4960 {
4961  int j=pos;
4963  initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4964  if ( (!strat->fromT)
4965  && ((strat->syzComp==0)
4966  ||(pGetComp(h)<=strat->syzComp)))
4967  {
4968  unsigned long h_sev = pGetShortExpVector(h);
4969  loop
4970  {
4971  if (j > k) break;
4972  clearS(h,h_sev, &j,&k,strat);
4973  j++;
4974  }
4975  }
4976 }
4977 
4978 /*2
4979 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4980 *superfluous elements in S will be deleted
4981 */
4982 void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4983 {
4984  int j;
4985  const int iCompH = pGetComp(h);
4986 
4987  if (rField_is_Ring(currRing))
4988  {
4989  for (j=0; j<=k; j++)
4990  {
4991  const int iCompSj = pGetComp(strat->S[j]);
4992  if ((iCompH==iCompSj)
4993  //|| (0==iCompH) // can only happen,if iCompSj==0
4994  || (0==iCompSj))
4995  {
4996  enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4997  }
4998  }
4999  kMergeBintoL(strat);
5000  }
5001  else
5002  {
5003  for (j=0; j<=k; j++)
5004  {
5005  const int iCompSj = pGetComp(strat->S[j]);
5006  if ((iCompH==iCompSj)
5007  //|| (0==iCompH) // can only happen,if iCompSj==0
5008  || (0==iCompSj))
5009  {
5010  enterOnePairSpecial(j,h,ecart,strat, atR);
5011  }
5012  }
5013  }
5014 
5015  if (strat->noClearS) return;
5016 
5017 // #ifdef HAVE_PLURAL
5018 /*
5019  if (rIsPluralRing(currRing))
5020  {
5021  j=pos;
5022  loop
5023  {
5024  if (j > k) break;
5025 
5026  if (pLmDivisibleBy(h, strat->S[j]))
5027  {
5028  deleteInS(j, strat);
5029  j--;
5030  k--;
5031  }
5032 
5033  j++;
5034  }
5035  }
5036  else
5037 */
5038 // #endif // ??? Why was the following cancelation disabled for non-commutative rings?
5039  {
5040  j=pos;
5041  loop
5042  {
5043  unsigned long h_sev = pGetShortExpVector(h);
5044  if (j > k) break;
5045  clearS(h,h_sev,&j,&k,strat);
5046  j++;
5047  }
5048  }
5049 }
5050 
5051 /*2
5052 *reorders s with respect to posInS,
5053 *suc is the first changed index or zero
5054 */
5055 
5056 void reorderS (int* suc,kStrategy strat)
5057 {
5058  int i,j,at,ecart, s2r;
5059  int fq=0;
5060  unsigned long sev;
5061  poly p;
5062  int new_suc=strat->sl+1;
5063  i= *suc;
5064  if (i<0) i=0;
5065 
5066  for (; i<=strat->sl; i++)
5067  {
5068  at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
5069  if (at != i)
5070  {
5071  if (new_suc > at) new_suc = at;
5072  p = strat->S[i];
5073  ecart = strat->ecartS[i];
5074  sev = strat->sevS[i];
5075  s2r = strat->S_2_R[i];
5076  if (strat->fromQ!=NULL) fq=strat->fromQ[i];
5077  for (j=i; j>=at+1; j--)
5078  {
5079  strat->S[j] = strat->S[j-1];
5080  strat->ecartS[j] = strat->ecartS[j-1];
5081  strat->sevS[j] = strat->sevS[j-1];
5082  strat->S_2_R[j] = strat->S_2_R[j-1];
5083  }
5084  strat->S[at] = p;
5085  strat->ecartS[at] = ecart;
5086  strat->sevS[at] = sev;
5087  strat->S_2_R[at] = s2r;
5088  if (strat->fromQ!=NULL)
5089  {
5090  for (j=i; j>=at+1; j--)
5091  {
5092  strat->fromQ[j] = strat->fromQ[j-1];
5093  }
5094  strat->fromQ[at]=fq;
5095  }
5096  }
5097  }
5098  if (new_suc <= strat->sl) *suc=new_suc;
5099  else *suc=-1;
5100 }
5101 
5102 
5103 /*2
5104 *looks up the position of p in set
5105 *set[0] is the smallest with respect to the ordering-procedure deg/pComp
5106 * Assumption: posInS only depends on the leading term
5107 * otherwise, bba has to be changed
5108 */
5109 int posInS (const kStrategy strat, const int length,const poly p,
5110  const int ecart_p)
5111 {
5112  if(length==-1) return 0;
5113  polyset set=strat->S;
5114  int i;
5115  int an = 0;
5116  int en = length;
5117  int cmp_int = currRing->OrdSgn;
5119 #ifdef HAVE_PLURAL
5120  && (currRing->real_var_start==0)
5121 #endif
5122 #if 0
5123  || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
5124 #endif
5125  )
5126  {
5127  int o=p_Deg(p,currRing);
5128  int oo=p_Deg(set[length],currRing);
5129 
5130  if ((oo<o)
5131  || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
5132  return length+1;
5133 
5134  loop
5135  {
5136  if (an >= en-1)
5137  {
5138  if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
5139  {
5140  return an;
5141  }
5142  return en;
5143  }
5144  i=(an+en) / 2;
5145  if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
5146  else an=i;
5147  }
5148  }
5149  else
5150  {
5151  if (rField_is_Ring(currRing))
5152  {
5153  if (pLmCmp(set[length],p)== -cmp_int)
5154  return length+1;
5155  int cmp;
5156  loop
5157  {
5158  if (an >= en-1)
5159  {
5160  cmp = pLmCmp(set[an],p);
5161  if (cmp == cmp_int) return an;
5162  if (cmp == -cmp_int) return en;
5163  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
5164  return an;
5165  }
5166  i = (an+en) / 2;
5167  cmp = pLmCmp(set[i],p);
5168  if (cmp == cmp_int) en = i;
5169  else if (cmp == -cmp_int) an = i;
5170  else
5171  {
5172  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
5173  else en = i;
5174  }
5175  }
5176  }
5177  else
5178  if (pLmCmp(set[length],p)== -cmp_int)
5179  return length+1;
5180 
5181  loop
5182  {
5183  if (an >= en-1)
5184  {
5185  if (pLmCmp(set[an],p) == cmp_int) return an;
5186  if (pLmCmp(set[an],p) == -cmp_int) return en;
5187  if ((cmp_int!=1)
5188  && ((strat->ecartS[an])>ecart_p))
5189  return an;
5190  return en;
5191  }
5192  i=(an+en) / 2;
5193  if (pLmCmp(set[i],p) == cmp_int) en=i;
5194  else if (pLmCmp(set[i],p) == -cmp_int) an=i;
5195  else
5196  {
5197  if ((cmp_int!=1)
5198  &&((strat->ecartS[i])<ecart_p))
5199  en=i;
5200  else
5201  an=i;
5202  }
5203  }
5204  }
5205 }
5206 
5207 
5208 // sorts by degree and pLtCmp
5209 // but puts pure monomials at the beginning
5210 int posInSMonFirst (const kStrategy strat, const int length,const poly p)
5211 {
5212  if (length<0) return 0;
5213  polyset set=strat->S;
5214  if(pNext(p) == NULL)
5215  {
5216  int mon = 0;
5217  for(int i = 0;i<=length;i++)
5218  {
5219  if(set[i] != NULL && pNext(set[i]) == NULL)
5220  mon++;
5221  }
5222  int o = p_Deg(p,currRing);
5223  int op = p_Deg(set[mon],currRing);
5224 
5225  if ((op < o)
5226  || ((op == o) && (pLtCmp(set[mon],p) == -1)))
5227  return length+1;
5228  int i;
5229  int an = 0;
5230  int en= mon;
5231  loop
5232  {
5233  if (an >= en-1)
5234  {
5235  op = p_Deg(set[an],currRing);
5236  if ((op < o)
5237  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5238  return en;
5239  return an;
5240  }
5241  i=(an+en) / 2;
5242  op = p_Deg(set[i],currRing);
5243  if ((op < o)
5244  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5245  an=i;
5246  else
5247  en=i;
5248  }
5249  }
5250  else /*if(pNext(p) != NULL)*/
5251  {
5252  int o = p_Deg(p,currRing);
5253  int op = p_Deg(set[length],currRing);
5254 
5255  if ((op < o)
5256  || ((op == o) && (pLtCmp(set[length],p) == -1)))
5257  return length+1;
5258  int i;
5259  int an = 0;
5260  for(i=0;i<=length;i++)
5261  if(set[i] != NULL && pNext(set[i]) == NULL)
5262  an++;
5263  int en= length;
5264  loop
5265  {
5266  if (an >= en-1)
5267  {
5268  op = p_Deg(set[an],currRing);
5269  if ((op < o)
5270  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5271  return en;
5272  return an;
5273  }
5274  i=(an+en) / 2;
5275  op = p_Deg(set[i],currRing);
5276  if ((op < o)
5277  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5278  an=i;
5279  else
5280  en=i;
5281  }
5282  }
5283 }
5284 
5285 // sorts by degree and pLtCmp in the block between start,end;
5286 // but puts pure monomials at the beginning
5287 int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
5288 {
5289  if(end < 0 || end >= IDELEMS(F))
5290  end = IDELEMS(F);
5291  if (end<0) return 0;
5292  if(pNext(p) == NULL) return start;
5293  polyset set=F->m;
5294  int o = p_Deg(p,currRing);
5295  int op;
5296  int i;
5297  int an = start;
5298  for(i=start;i<end;i++)
5299  if(set[i] != NULL && pNext(set[i]) == NULL)
5300  an++;
5301  if(an == end-1)
5302  return end;
5303  int en= end;
5304  loop
5305  {
5306  if(an>=en)
5307  return en;
5308  if (an == en-1)
5309  {
5310  op = p_Deg(set[an],currRing);
5311  if ((op < o)
5312  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5313  return en;
5314  return an;
5315  }
5316  i=(an+en) / 2;
5317  op = p_Deg(set[i],currRing);
5318  if ((op < o)
5319  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5320  an=i;
5321  else
5322  en=i;
5323  }
5324 }
5325 
5326 
5327 /*2
5328 * looks up the position of p in set
5329 * the position is the last one
5330 */
5331 int posInT0 (const TSet,const int length,LObject &)
5332 {
5333  return (length+1);
5334 }
5335 
5336 
5337 /*2
5338 * looks up the position of p in T
5339 * set[0] is the smallest with respect to the ordering-procedure
5340 * pComp
5341 */
5342 int posInT1 (const TSet set,const int length,LObject &p)
5343 {
5344  if (length==-1) return 0;
5345 
5346  if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
5347 
5348  int i;
5349  int an = 0;
5350  int en= length;
5351 
5352  loop
5353  {
5354  if (an >= en-1)
5355  {
5356  if (pLmCmp(set[an].p,p.p) == currRing->OrdSgn) return an;
5357  return en;
5358  }
5359  i=(an+en) / 2;
5360  if (pLmCmp(set[i].p,p.p) == currRing->OrdSgn) en=i;
5361  else an=i;
5362  }
5363 }
5364 
5365 /*2
5366 * looks up the position of p in T
5367 * set[0] is the smallest with respect to the ordering-procedure
5368 * length
5369 */
5370 int posInT2 (const TSet set,const int length,LObject &p)
5371 {
5372  p.GetpLength();
5373  if (length==-1)
5374  return 0;
5375  if (set[length].length<p.length)
5376  return length+1;
5377 
5378  int i;
5379  int an = 0;
5380  int en= length;
5381 
5382  loop
5383  {
5384  if (an >= en-1)
5385  {
5386  if (set[an].length>p.length) return an;
5387  return en;
5388  }
5389  i=(an+en) / 2;
5390  if (set[i].length>p.length) en=i;
5391  else an=i;
5392  }
5393 }
5394 
5395 /*2
5396 * looks up the position of p in T
5397 * set[0] is the smallest with respect to the ordering-procedure
5398 * totaldegree,pComp
5399 */
5400 int posInT11 (const TSet set,const int length,LObject &p)
5401 {
5402  if (length==-1) return 0;
5403 
5404  int o = p.GetpFDeg();
5405  int op = set[length].GetpFDeg();
5406 
5407  if ((op < o)
5408  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5409  return length+1;
5410 
5411  int i;
5412  int an = 0;
5413  int en= length;
5414 
5415  loop
5416  {
5417  if (an >= en-1)
5418  {
5419  op= set[an].GetpFDeg();
5420  if ((op > o)
5421  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5422  return an;
5423  return en;
5424  }
5425  i=(an+en) / 2;
5426  op = set[i].GetpFDeg();
5427  if (( op > o)
5428  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5429  en=i;
5430  else
5431  an=i;
5432  }
5433 }
5434 
5435 #ifdef HAVE_RINGS
5436 int posInT11Ring (const TSet set,const int length,LObject &p)
5437 {
5438  if (length==-1) return 0;
5439 
5440  int o = p.GetpFDeg();
5441  int op = set[length].GetpFDeg();
5442 
5443  if ((op < o)
5444  || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5445  return length+1;
5446 
5447  int i;
5448  int an = 0;
5449  int en= length;
5450 
5451  loop
5452  {
5453  if (an >= en-1)
5454  {
5455  op= set[an].GetpFDeg();
5456  if ((op > o)
5457  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5458  return an;
5459  return en;
5460  }
5461  i=(an+en) / 2;
5462  op = set[i].GetpFDeg();
5463  if (( op > o)
5464  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5465  en=i;
5466  else
5467  an=i;
5468  }
5469 }
5470 #endif
5471 
5472 /*2 Pos for rings T: Here I am
5473 * looks up the position of p in T
5474 * set[0] is the smallest with respect to the ordering-procedure
5475 * totaldegree,pComp
5476 */
5477 int posInTrg0 (const TSet set,const int length,LObject &p)
5478 {
5479  if (length==-1) return 0;
5480  int o = p.GetpFDeg();
5481  int op = set[length].GetpFDeg();
5482  int i;
5483  int an = 0;
5484  int en = length;
5485  int cmp_int = currRing->OrdSgn;
5486  if ((op < o) || (pLmCmp(set[length].p,p.p)== -cmp_int))
5487  return length+1;
5488  int cmp;
5489  loop
5490  {
5491  if (an >= en-1)
5492  {
5493  op = set[an].GetpFDeg();
5494  if (op > o) return an;
5495  if (op < 0) return en;
5496  cmp = pLmCmp(set[an].p,p.p);
5497  if (cmp == cmp_int) return an;
5498  if (cmp == -cmp_int) return en;
5499  if (nGreater(pGetCoeff(p.p), pGetCoeff(set[an].p))) return en;
5500  return an;
5501  }
5502  i = (an + en) / 2;
5503  op = set[i].GetpFDeg();
5504  if (op > o) en = i;
5505  else if (op < o) an = i;
5506  else
5507  {
5508  cmp = pLmCmp(set[i].p,p.p);
5509  if (cmp == cmp_int) en = i;
5510  else if (cmp == -cmp_int) an = i;
5511  else if (nGreater(pGetCoeff(p.p), pGetCoeff(set[i].p))) an = i;
5512  else en = i;
5513  }
5514  }
5515 }
5516 /*
5517  int o = p.GetpFDeg();
5518  int op = set[length].GetpFDeg();
5519 
5520  if ((op < o)
5521  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5522  return length+1;
5523 
5524  int i;
5525  int an = 0;
5526  int en= length;
5527 
5528  loop
5529  {
5530  if (an >= en-1)
5531  {
5532  op= set[an].GetpFDeg();
5533  if ((op > o)
5534  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5535  return an;
5536  return en;
5537  }
5538  i=(an+en) / 2;
5539  op = set[i].GetpFDeg();
5540  if (( op > o)
5541  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5542  en=i;
5543  else
5544  an=i;
5545  }
5546 }
5547  */
5548 /*2
5549 * looks up the position of p in T
5550 * set[0] is the smallest with respect to the ordering-procedure
5551 * totaldegree,pComp
5552 */
5553 int posInT110 (const TSet set,const int length,LObject &p)
5554 {
5555  p.GetpLength();
5556  if (length==-1) return 0;
5557 
5558  int o = p.GetpFDeg();
5559  int op = set[length].GetpFDeg();
5560 
5561  if (( op < o)
5562  || (( op == o) && (set[length].length<p.length))
5563  || (( op == o) && (set[length].length == p.length)
5564  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5565  return length+1;
5566 
5567  int i;
5568  int an = 0;
5569  int en= length;
5570  loop
5571  {
5572  if (an >= en-1)
5573  {
5574  op = set[an].GetpFDeg();
5575  if (( op > o)
5576  || (( op == o) && (set[an].length > p.length))
5577  || (( op == o) && (set[an].length == p.length)
5578  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5579  return an;
5580  return en;
5581  }
5582  i=(an+en) / 2;
5583  op = set[i].GetpFDeg();
5584  if (( op > o)
5585  || (( op == o) && (set[i].length > p.length))
5586  || (( op == o) && (set[i].length == p.length)
5587  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5588  en=i;
5589  else
5590  an=i;
5591  }
5592 }
5593 
5594 #ifdef HAVE_RINGS
5595 int posInT110Ring (const TSet set,const int length,LObject &p)
5596 {
5597  p.GetpLength();
5598  if (length==-1) return 0;
5599 
5600  int o = p.GetpFDeg();
5601  int op = set[length].GetpFDeg();
5602 
5603  if (( op < o)
5604  || (( op == o) && (set[length].length<p.length))
5605  || (( op == o) && (set[length].length == p.length)
5606  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5607  return length+1;
5608 
5609  int i;
5610  int an = 0;
5611  int en= length;
5612  loop
5613  {
5614  if (an >= en-1)
5615  {
5616  op = set[an].GetpFDeg();
5617  if (( op > o)
5618  || (( op == o) && (set[an].length > p.length))
5619  || (( op == o) && (set[an].length == p.length)
5620  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5621  return an;
5622  return en;
5623  }
5624  i=(an+en) / 2;
5625  op = set[i].GetpFDeg();
5626  if (( op > o)
5627  || (( op == o) && (set[i].length > p.length))
5628  || (( op == o) && (set[i].length == p.length)
5629  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5630  en=i;
5631  else
5632  an=i;
5633  }
5634 }
5635 #endif
5636 
5637 /*2
5638 * looks up the position of p in set
5639 * set[0] is the smallest with respect to the ordering-procedure
5640 * pFDeg
5641 */
5642 int posInT13 (const TSet set,const int length,LObject &p)
5643 {
5644  if (length==-1) return 0;
5645 
5646  int o = p.GetpFDeg();
5647 
5648  if (set[length].GetpFDeg() <= o)
5649  return length+1;
5650 
5651  int i;
5652  int an = 0;
5653  int en= length;
5654  loop
5655  {
5656  if (an >= en-1)
5657  {
5658  if (set[an].GetpFDeg() > o)
5659  return an;
5660  return en;
5661  }
5662  i=(an+en) / 2;
5663  if (set[i].GetpFDeg() > o)
5664  en=i;
5665  else
5666  an=i;
5667  }
5668 }
5669 
5670 // determines the position based on: 1.) Ecart 2.) pLength
5671 int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5672 {
5673  int ol = p.GetpLength();
5674  if (length==-1) return 0;
5675 
5676  int op=p.ecart;
5677 
5678  int oo=set[length].ecart;
5679  if ((oo < op) || ((oo==op) && (set[length].length <= ol)))
5680  return length+1;
5681 
5682  int i;
5683  int an = 0;
5684  int en= length;
5685  loop
5686  {
5687  if (an >= en-1)
5688  {
5689  int oo=set[an].ecart;
5690  if((oo > op)
5691  || ((oo==op) && (set[an].pLength > ol)))
5692  return an;
5693  return en;
5694  }
5695  i=(an+en) / 2;
5696  int oo=set[i].ecart;
5697  if ((oo > op)
5698  || ((oo == op) && (set[i].pLength > ol)))
5699  en=i;
5700  else
5701  an=i;
5702  }
5703 }
5704 
5705 /*2
5706 * looks up the position of p in set
5707 * set[0] is the smallest with respect to the ordering-procedure
5708 * maximaldegree, pComp
5709 */
5710 int posInT15 (const TSet set,const int length,LObject &p)
5711 /*{
5712  *int j=0;
5713  * int o;
5714  *
5715  * o = p.GetpFDeg()+p.ecart;
5716  * loop
5717  * {
5718  * if ((set[j].GetpFDeg()+set[j].ecart > o)
5719  * || ((set[j].GetpFDeg()+set[j].ecart == o)
5720  * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5721  * {
5722  * return j;
5723  * }
5724  * j++;
5725  * if (j > length) return j;
5726  * }
5727  *}
5728  */
5729 {
5730  if (length==-1) return 0;
5731 
5732  int o = p.GetpFDeg() + p.ecart;
5733  int op = set[length].GetpFDeg()+set[length].ecart;
5734 
5735  if ((op < o)
5736  || ((op == o)
5737  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5738  return length+1;
5739 
5740  int i;
5741  int an = 0;
5742  int en= length;
5743  loop
5744  {
5745  if (an >= en-1)
5746  {
5747  op = set[an].GetpFDeg()+set[an].ecart;
5748  if (( op > o)
5749  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5750  return an;
5751  return en;
5752  }
5753  i=(an+en) / 2;
5754  op = set[i].GetpFDeg()+set[i].ecart;
5755  if (( op > o)
5756  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5757  en=i;
5758  else
5759  an=i;
5760  }
5761 }
5762 
5763 #ifdef HAVE_RINGS
5764 int posInT15Ring (const TSet set,const int length,LObject &p)
5765 {
5766  if (length==-1) return 0;
5767 
5768  int o = p.GetpFDeg() + p.ecart;
5769  int op = set[length].GetpFDeg()+set[length].ecart;
5770 
5771  if ((op < o)
5772  || ((op == o)
5773  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5774  return length+1;
5775 
5776  int i;
5777  int an = 0;
5778  int en= length;
5779  loop
5780  {
5781  if (an >= en-1)
5782  {
5783  op = set[an].GetpFDeg()+set[an].ecart;
5784  if (( op > o)
5785  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5786  return an;
5787  return en;
5788  }
5789  i=(an+en) / 2;
5790  op = set[i].GetpFDeg()+set[i].ecart;
5791  if (( op > o)
5792  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5793  en=i;
5794  else
5795  an=i;
5796  }
5797 }
5798 #endif
5799 
5800 /*2
5801 * looks up the position of p in set
5802 * set[0] is the smallest with respect to the ordering-procedure
5803 * pFDeg+ecart, ecart, pComp
5804 */
5805 int posInT17 (const TSet set,const int length,LObject &p)
5806 /*
5807 *{
5808 * int j=0;
5809 * int o;
5810 *
5811 * o = p.GetpFDeg()+p.ecart;
5812 * loop
5813 * {
5814 * if ((pFDeg(set[j].p)+set[j].ecart > o)
5815 * || (((pFDeg(set[j].p)+set[j].ecart == o)
5816 * && (set[j].ecart < p.ecart)))
5817 * || ((pFDeg(set[j].p)+set[j].ecart == o)
5818 * && (set[j].ecart==p.ecart)
5819 * && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5820 * return j;
5821 * j++;
5822 * if (j > length) return j;
5823 * }
5824 * }
5825 */
5826 {
5827  if (length==-1) return 0;
5828 
5829  int o = p.GetpFDeg() + p.ecart;
5830  int op = set[length].GetpFDeg()+set[length].ecart;
5831 
5832  if ((op < o)
5833  || (( op == o) && (set[length].ecart > p.ecart))
5834  || (( op == o) && (set[length].ecart==p.ecart)
5835  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5836  return length+1;
5837 
5838  int i;
5839  int an = 0;
5840  int en= length;
5841  loop
5842  {
5843  if (an >= en-1)
5844  {
5845  op = set[an].GetpFDeg()+set[an].ecart;
5846  if (( op > o)
5847  || (( op == o) && (set[an].ecart < p.ecart))
5848  || (( op == o) && (set[an].ecart==p.ecart)
5849  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5850  return an;
5851  return en;
5852  }
5853  i=(an+en) / 2;
5854  op = set[i].GetpFDeg()+set[i].ecart;
5855  if ((op > o)
5856  || (( op == o) && (set[i].ecart < p.ecart))
5857  || (( op == o) && (set[i].ecart == p.ecart)
5858  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5859  en=i;
5860  else
5861  an=i;
5862  }
5863 }
5864 
5865 #ifdef HAVE_RINGS
5866 int posInT17Ring (const TSet set,const int length,LObject &p)
5867 {
5868  if (length==-1) return 0;
5869 
5870  int o = p.GetpFDeg() + p.ecart;
5871  int op = set[length].GetpFDeg()+set[length].ecart;
5872 
5873  if ((op < o)
5874  || (( op == o) && (set[length].ecart > p.ecart))
5875  || (( op == o) && (set[length].ecart==p.ecart)
5876  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5877  return length+1;
5878 
5879  int i;
5880  int an = 0;
5881  int en= length;
5882  loop
5883  {
5884  if (an >= en-1)
5885  {
5886  op = set[an].GetpFDeg()+set[an].ecart;
5887  if (( op > o)
5888  || (( op == o) && (set[an].ecart < p.ecart))
5889  || (( op == o) && (set[an].ecart==p.ecart)
5890  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5891  return an;
5892  return en;
5893  }
5894  i=(an+en) / 2;
5895  op = set[i].GetpFDeg()+set[i].ecart;
5896  if ((op > o)
5897  || (( op == o) && (set[i].ecart < p.ecart))
5898  || (( op == o) && (set[i].ecart == p.ecart)
5899  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5900  en=i;
5901  else
5902  an=i;
5903  }
5904 }
5905 #endif
5906 
5907 /*2
5908 * looks up the position of p in set
5909 * set[0] is the smallest with respect to the ordering-procedure
5910 * pGetComp, pFDeg+ecart, ecart, pComp
5911 */
5912 int posInT17_c (const TSet set,const int length,LObject &p)
5913 {
5914  if (length==-1) return 0;
5915 
5916  int cc = (-1+2*currRing->order[0]==ringorder_c);
5917  /* cc==1 for (c,..), cc==-1 for (C,..) */
5918  int o = p.GetpFDeg() + p.ecart;
5919  int c = pGetComp(p.p)*cc;
5920 
5921  if (pGetComp(set[length].p)*cc < c)
5922  return length+1;
5923  if (pGetComp(set[length].p)*cc == c)
5924  {
5925  int op = set[length].GetpFDeg()+set[length].ecart;
5926  if ((op < o)
5927  || ((op == o) && (set[length].ecart > p.ecart))
5928  || ((op == o) && (set[length].ecart==p.ecart)
5929  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5930  return length+1;
5931  }
5932 
5933  int i;
5934  int an = 0;
5935  int en= length;
5936  loop
5937  {
5938  if (an >= en-1)
5939  {
5940  if (pGetComp(set[an].p)*cc < c)
5941  return en;
5942  if (pGetComp(set[an].p)*cc == c)
5943  {
5944  int op = set[an].GetpFDeg()+set[an].ecart;
5945  if ((op > o)
5946  || ((op == o) && (set[an].ecart < p.ecart))
5947  || ((op == o) && (set[an].ecart==p.ecart)
5948  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5949  return an;
5950  }
5951  return en;
5952  }
5953  i=(an+en) / 2;
5954  if (pGetComp(set[i].p)*cc > c)
5955  en=i;
5956  else if (pGetComp(set[i].p)*cc == c)
5957  {
5958  int op = set[i].GetpFDeg()+set[i].ecart;
5959  if ((op > o)
5960  || ((op == o) && (set[i].ecart < p.ecart))
5961  || ((op == o) && (set[i].ecart == p.ecart)
5962  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5963  en=i;
5964  else
5965  an=i;
5966  }
5967  else
5968  an=i;
5969  }
5970 }
5971 
5972 #ifdef HAVE_RINGS
5973 int posInT17_cRing (const TSet set,const int length,LObject &p)
5974 {
5975  if (length==-1) return 0;
5976 
5977  int cc = (-1+2*currRing->order[0]==ringorder_c);
5978  /* cc==1 for (c,..), cc==-1 for (C,..) */
5979  int o = p.GetpFDeg() + p.ecart;
5980  int c = pGetComp(p.p)*cc;
5981 
5982  if (pGetComp(set[length].p)*cc < c)
5983  return length+1;
5984  if (pGetComp(set[length].p)*cc == c)
5985  {
5986  int op = set[length].GetpFDeg()+set[length].ecart;
5987  if ((op < o)
5988  || ((op == o) && (set[length].ecart > p.ecart))
5989  || ((op == o) && (set[length].ecart==p.ecart)
5990  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5991  return length+1;
5992  }
5993 
5994  int i;
5995  int an = 0;
5996  int en= length;
5997  loop
5998  {
5999  if (an >= en-1)
6000  {
6001  if (pGetComp(set[an].p)*cc < c)
6002  return en;
6003  if (pGetComp(set[an].p)*cc == c)
6004  {
6005  int op = set[an].GetpFDeg()+set[an].ecart;
6006  if ((op > o)
6007  || ((op == o) && (set[an].ecart < p.ecart))
6008  || ((op == o) && (set[an].ecart==p.ecart)
6009  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
6010  return an;
6011  }
6012  return en;
6013  }
6014  i=(an+en) / 2;
6015  if (pGetComp(set[i].p)*cc > c)
6016  en=i;
6017  else if (pGetComp(set[i].p)*cc == c)
6018  {
6019  int op = set[i].GetpFDeg()+set[i].ecart;
6020  if ((op > o)
6021  || ((op == o) && (set[i].ecart < p.ecart))
6022  || ((op == o) && (set[i].ecart == p.ecart)
6023  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
6024  en=i;
6025  else
6026  an=i;
6027  }
6028  else
6029  an=i;
6030  }
6031 }
6032 #endif
6033 
6034 /*2
6035 * looks up the position of p in set
6036 * set[0] is the smallest with respect to
6037 * ecart, pFDeg, length
6038 */
6039 int posInT19 (const TSet set,const int length,LObject &p)
6040 {
6041  p.GetpLength();
6042  if (length==-1) return 0;
6043 
6044  int o = p.ecart;
6045  int op=p.GetpFDeg();
6046 
6047  if (set[length].ecart < o)
6048  return length+1;
6049  if (set[length].ecart == o)
6050  {
6051  int oo=set[length].GetpFDeg();
6052  if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
6053  return length+1;
6054  }
6055 
6056  int i;
6057  int an = 0;
6058  int en= length;
6059  loop
6060  {
6061  if (an >= en-1)
6062  {
6063  if (set[an].ecart > o)
6064  return an;
6065  if (set[an].ecart == o)
6066  {
6067  int oo=set[an].GetpFDeg();
6068  if((oo > op)
6069  || ((oo==op) && (set[an].length > p.length)))
6070  return an;
6071  }
6072  return en;
6073  }
6074  i=(an+en) / 2;
6075  if (set[i].ecart > o)
6076  en=i;
6077  else if (set[i].ecart == o)
6078  {
6079  int oo=set[i].GetpFDeg();
6080  if ((oo > op)
6081  || ((oo == op) && (set[i].length > p.length)))
6082  en=i;
6083  else
6084  an=i;
6085  }
6086  else
6087  an=i;
6088  }
6089 }
6090 
6091 /*2
6092 *looks up the position of polynomial p in set
6093 *set[length] is the smallest element in set with respect
6094 *to the ordering-procedure pComp
6095 */
6096 int posInLSpecial (const LSet set, const int length,
6097  LObject *p,const kStrategy)
6098 {
6099  if (length<0) return 0;
6100 
6101  int d=p->GetpFDeg();
6102  int op=set[length].GetpFDeg();
6103 
6104  if ((op > d)
6105  || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
6106  || (pLmCmp(set[length].p,p->p)== currRing->OrdSgn))
6107  return length+1;
6108 
6109  int i;
6110  int an = 0;
6111  int en= length;
6112  loop
6113  {
6114  if (an >= en-1)
6115  {
6116  op=set[an].GetpFDeg();
6117  if ((op > d)
6118  || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
6119  || (pLmCmp(set[an].p,p->p)== currRing->OrdSgn))
6120  return en;
6121  return an;
6122  }
6123  i=(an+en) / 2;
6124  op=set[i].GetpFDeg();
6125  if ((op>d)
6126  || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
6127  || (pLmCmp(set[i].p,p->p) == currRing->OrdSgn))
6128  an=i;
6129  else
6130  en=i;
6131  }
6132 }
6133 
6134 /*2
6135 *looks up the position of polynomial p in set
6136 *set[length] is the smallest element in set with respect
6137 *to the ordering-procedure pComp
6138 */
6139 int posInL0 (const LSet set, const int length,
6140  LObject* p,const kStrategy)
6141 {
6142  if (length<0) return 0;
6143 
6144  if (pLmCmp(set[length].p,p->p)== currRing->OrdSgn)
6145  return length+1;
6146 
6147  int i;
6148  int an = 0;
6149  int en= length;
6150  loop
6151  {
6152  if (an >= en-1)
6153  {
6154  if (pLmCmp(set[an].p,p->p) == currRing->OrdSgn) return en;
6155  return an;
6156  }
6157  i=(an+en) / 2;
6158  if (pLmCmp(set[i].p,p->p) == currRing->OrdSgn) an=i;
6159  else en=i;
6160  /*aend. fuer lazy == in !=- machen */
6161  }
6162 }
6163 
6164 #ifdef HAVE_RINGS
6165 int posInL0Ring (const LSet set, const int length,
6166  LObject* p,const kStrategy)
6167 {
6168  if (length<0) return 0;
6169 
6170  if (pLtCmpOrdSgnEqP(set[length].p,p->p))
6171  return length+1;
6172 
6173  int i;
6174  int an = 0;
6175  int en= length;
6176  loop
6177  {
6178  if (an >= en-1)
6179  {
6180  if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
6181  return an;
6182  }
6183  i=(an+en) / 2;
6184  if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
6185  else en=i;
6186  /*aend. fuer lazy == in !=- machen */
6187  }
6188 }
6189 #endif
6190 
6191 /*2
6192 * looks up the position of polynomial p in set
6193 * e is the ecart of p
6194 * set[length] is the smallest element in set with respect
6195 * to the signature order
6196 */
6197 int posInLSig (const LSet set, const int length,
6198  LObject* p,const kStrategy /*strat*/)
6199 {
6200  if (length<0) return 0;
6201  if (pLtCmp(set[length].sig,p->sig)== currRing->OrdSgn)
6202  return length+1;
6203 
6204  int i;
6205  int an = 0;
6206  int en= length;
6207  loop
6208  {
6209  if (an >= en-1)
6210  {
6211  if (pLtCmp(set[an].sig,p->sig) == currRing->OrdSgn) return en;
6212  return an;
6213  }
6214  i=(an+en) / 2;
6215  if (pLtCmp(set[i].sig,p->sig) == currRing->OrdSgn) an=i;
6216  else en=i;
6217  /*aend. fuer lazy == in !=- machen */
6218  }
6219 }
6220 //sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
6221 int posInLSigRing (const LSet set, const int length,
6222  LObject* p,const kStrategy /*strat*/)
6223 {
6224  assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
6225  if (length<0) return 0;
6226  if (pLtCmp(set[length].sig,p->sig)== 1)
6227  return length+1;
6228 
6229  int an,en,i;
6230  an = 0;
6231  en = length+1;
6232  int cmp;
6233  loop
6234  {
6235  if (an >= en-1)
6236  {
6237  if(an == en)
6238  return en;
6239  cmp = pLtCmp(set[an].sig,p->sig);
6240  if (cmp == 1)
6241  return en;
6242  if (cmp == -1)
6243  return an;
6244  if (cmp == 0)
6245  {
6246  if (set[an].FDeg > p->FDeg)
6247  return en;
6248  if (set[an].FDeg < p->FDeg)
6249  return an;
6250  if (set[an].FDeg == p->FDeg)
6251  {
6252  cmp = pLtCmp(set[an].p,p->p);
6253  if(cmp == 1)
6254  return en;
6255  else
6256  return an;
6257  }
6258  }
6259  }
6260  i=(an+en) / 2;
6261  cmp = pLtCmp(set[i].sig,p->sig);
6262  if (cmp == 1)
6263  an = i;
6264  if (cmp == -1)
6265  en = i;
6266  if (cmp == 0)
6267  {
6268  if (set[i].FDeg > p->FDeg)
6269  an = i;
6270  if (set[i].FDeg < p->FDeg)
6271  en = i;
6272  if (set[i].FDeg == p->FDeg)
6273  {
6274  cmp = pLtCmp(set[i].p,p->p);
6275  if(cmp == 1)
6276  an = i;
6277  else
6278  en = i;
6279  }
6280  }
6281  }
6282 }
6283 
6284 int posInLRing (const LSet set, const int length,
6285  LObject* p,const kStrategy /*strat*/)
6286 {
6287  if (length < 0) return 0;
6288  if (set[length].FDeg > p->FDeg)
6289  return length+1;
6290  if (set[length].FDeg == p->FDeg)
6291  if(set[length].GetpLength() > p->GetpLength())
6292  return length+1;
6293  int i;
6294  int an = 0;
6295  int en= length+1;
6296  loop
6297  {
6298  if (an >= en-1)
6299  {
6300  if(an == en)
6301  return en;
6302  if (set[an].FDeg > p->FDeg)
6303  return en;
6304  if(set[an].FDeg == p->FDeg)
6305  {
6306  if(set[an].GetpLength() > p->GetpLength())
6307  return en;
6308  else
6309  {
6310  if(set[an].GetpLength() == p->GetpLength())
6311  {
6312  if(nGreater(set[an].p->coef, p->p->coef))
6313  return en;
6314  else
6315  return an;
6316  }
6317  else
6318  {
6319  return an;
6320  }
6321  }
6322  }
6323  else
6324  return an;
6325  }
6326  i=(an+en) / 2;
6327  if (set[i].FDeg > p->FDeg)
6328  an=i;
6329  else
6330  {
6331  if(set[i].FDeg == p->FDeg)
6332  {
6333  if(set[i].GetpLength() > p->GetpLength())
6334  an=i;
6335  else
6336  {
6337  if(set[i].GetpLength() == p->GetpLength())
6338  {
6339  if(nGreater(set[i].p->coef, p->p->coef))
6340  an = i;
6341  else
6342  en = i;
6343  }
6344  else
6345  {
6346  en=i;
6347  }
6348  }
6349  }
6350  else
6351  en=i;
6352  }
6353  }
6354 }
6355 
6356 // for sba, sorting syzygies
6357 int posInSyz (const kStrategy strat, poly sig)
6358 {
6359  if (strat->syzl==0) return 0;
6360  if (pLtCmp(strat->syz[strat->syzl-1],sig) != currRing->OrdSgn)
6361  return strat->syzl;
6362  int i;
6363  int an = 0;
6364  int en= strat->syzl-1;
6365  loop
6366  {
6367  if (an >= en-1)
6368  {
6369  if (pLtCmp(strat->syz[an],sig) != currRing->OrdSgn) return en;
6370  return an;
6371  }
6372  i=(an+en) / 2;
6373  if (pLtCmp(strat->syz[i],sig) != currRing->OrdSgn) an=i;
6374  else en=i;
6375  /*aend. fuer lazy == in !=- machen */
6376  }
6377 }
6378 
6379 /*2
6380 *
6381 * is only used in F5C, must ensure that the interreduction process does add new
6382 * critical pairs to strat->L only behind all other critical pairs which are
6383 * still in strat->L!
6384 */
6385 int posInLF5C (const LSet /*set*/, const int /*length*/,
6386  LObject* /*p*/,const kStrategy strat)
6387 {
6388  return strat->Ll+1;
6389 }
6390 
6391 /*2
6392 * looks up the position of polynomial p in set
6393 * e is the ecart of p
6394 * set[length] is the smallest element in set with respect
6395 * to the ordering-procedure totaldegree,pComp
6396 */
6397 int posInL11 (const LSet set, const int length,
6398  LObject* p,const kStrategy)
6399 {
6400  if (length<0) return 0;
6401 
6402  int o = p->GetpFDeg();
6403  int op = set[length].GetpFDeg();
6404 
6405  if ((op > o)
6406  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6407  return length+1;
6408  int i;
6409  int an = 0;
6410  int en= length;
6411  loop
6412  {
6413  if (an >= en-1)
6414  {
6415  op = set[an].GetpFDeg();
6416  if ((op > o)
6417  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6418  return en;
6419  return an;
6420  }
6421  i=(an+en) / 2;
6422  op = set[i].GetpFDeg();
6423  if ((op > o)
6424  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6425  an=i;
6426  else
6427  en=i;
6428  }
6429 }
6430 
6431 #ifdef HAVE_RINGS
6432 /*2
6433 * looks up the position of polynomial p in set
6434 * set[length] is the smallest element in set with respect
6435 * to the ordering-procedure pLmCmp,totaldegree,coefficient
6436 * For the same totaldegree, original pairs (from F) will
6437 * be put at the end and smalles coefficents
6438 */
6439 int posInL11Ring (const LSet set, const int length,
6440  LObject* p,const kStrategy)
6441 {
6442  if (length<0) return 0;
6443 
6444  int o = p->GetpFDeg();
6445  int op = set[length].GetpFDeg();
6446 
6447  if ((op > o)
6448  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6449  return length+1;
6450  int i;
6451  int an = 0;
6452  int en= length;
6453  loop
6454  {
6455  if (an >= en-1)
6456  {
6457  op = set[an].GetpFDeg();
6458  if ((op > o)
6459  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6460  return en;
6461  return an;
6462  }
6463  i=(an+en) / 2;
6464  op = set[i].GetpFDeg();
6465  if ((op > o)
6466  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6467  an=i;
6468  else
6469  en=i;
6470  }
6471 }
6472 
6473 int posInLF5CRing (const LSet set, int start,const int length,
6474  LObject* p,const kStrategy)
6475 {
6476  if (length<0) return 0;
6477  if(start == (length +1)) return (length+1);
6478  int o = p->GetpFDeg();
6479  int op = set[length].GetpFDeg();
6480 
6481  if ((op > o)
6482  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6483  return length+1;
6484  int i;
6485  int an = start;
6486  int en= length;
6487  loop
6488  {
6489  if (an >= en-1)
6490  {
6491  op = set[an].GetpFDeg();
6492  if ((op > o)
6493  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6494  return en;
6495  return an;
6496  }
6497  i=(an+en) / 2;
6498  op = set[i].GetpFDeg();
6499  if ((op > o)
6500  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6501  an=i;
6502  else
6503  en=i;
6504  }
6505 }
6506 #endif
6507 
6508 #ifdef HAVE_RINGS
6509 int posInL11Ringls (const LSet set, const int length,
6510  LObject* p,const kStrategy)
6511 {
6512  if (length < 0) return 0;
6513  int an,en,i;
6514  an = 0;
6515  en = length+1;
6516  loop
6517  {
6518  if (an >= en-1)
6519  {
6520  if(an == en)
6521  return en;
6522  if (set[an].FDeg > p->FDeg)
6523  return en;
6524  if (set[an].FDeg < p->FDeg)
6525  return an;
6526  if (set[an].FDeg == p->FDeg)
6527  {
6528  number lcset,lcp;
6529  lcset = pGetCoeff(set[an].p);
6530  lcp = pGetCoeff(p->p);
6531  if(!nGreaterZero(lcset))
6532  {
6533  set[an].p=p_Neg(set[an].p,currRing);
6534  if (set[an].t_p!=NULL)
6535  pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
6536  lcset=pGetCoeff(set[an].p);
6537  }
6538  if(!nGreaterZero(lcp))
6539  {
6540  p->p=p_Neg(p->p,currRing);
6541  if (p->t_p!=NULL)
6542  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6543  lcp=pGetCoeff(p->p);
6544  }
6545  if(nGreater(lcset, lcp))
6546  {
6547  return en;
6548  }
6549  else
6550  {
6551  return an;
6552  }
6553  }
6554  }
6555  i=(an+en) / 2;
6556  if (set[i].FDeg > p->FDeg)
6557  an=i;
6558  if (set[i].FDeg < p->FDeg)
6559  en=i;
6560  if (set[i].FDeg == p->FDeg)
6561  {
6562  number lcset,lcp;
6563  lcset = pGetCoeff(set[i].p);
6564  lcp = pGetCoeff(p->p);
6565  if(!nGreaterZero(lcset))
6566  {
6567  set[i].p=p_Neg(set[i].p,currRing);
6568  if (set[i].t_p!=NULL)
6569  pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6570  lcset=pGetCoeff(set[i].p);
6571  }
6572  if(!nGreaterZero(lcp))
6573  {
6574  p->p=p_Neg(p->p,currRing);
6575  if (p->t_p!=NULL)
6576  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6577  lcp=pGetCoeff(p->p);
6578  }
6579  if(nGreater(lcset, lcp))
6580  {
6581  an = i;
6582  }
6583  else
6584  {
6585  en = i;
6586  }
6587  }
6588  }
6589 }
6590 #endif
6591 
6592 /*2 Position for rings L: Here I am
6593 * looks up the position of polynomial p in set
6594 * e is the ecart of p
6595 * set[length] is the smallest element in set with respect
6596 * to the ordering-procedure totaldegree,pComp
6597 */
6598 inline int getIndexRng(long coeff)
6599 {
6600  if (coeff == 0) return -1;
6601  long tmp = coeff;
6602  int ind = 0;
6603  while (tmp % 2 == 0)
6604  {
6605  tmp = tmp / 2;
6606  ind++;
6607  }
6608  return ind;
6609 }
6610 
6611 int posInLrg0 (const LSet set, const int length,
6612  LObject* p,const kStrategy)
6613 /* if (nGreater(pGetCoeff(p), pGetCoeff(set[an]))) return en;
6614  if (pLmCmp(set[i],p) == cmp_int) en = i;
6615  else if (pLmCmp(set[i],p) == -cmp_int) an = i;
6616  else
6617  {
6618  if (nGreater(pGetCoeff(p), pGetCoeff(set[i]))) an = i;
6619  else en = i;
6620  }*/
6621 {
6622  if (length < 0) return 0;
6623 
6624  int o = p->GetpFDeg();
6625  int op = set[length].GetpFDeg();
6626 
6627  if ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6628  return length + 1;
6629  int i;
6630  int an = 0;
6631  int en = length;
6632  loop
6633  {
6634  if (an >= en - 1)
6635  {
6636  op = set[an].GetpFDeg();
6637  if ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6638  return en;
6639  return an;
6640  }
6641  i = (an+en) / 2;
6642  op = set[i].GetpFDeg();
6643  if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6644  an = i;
6645  else
6646  en = i;
6647  }
6648 }
6649 
6650 /*{
6651  if (length < 0) return 0;
6652 
6653  int o = p->GetpFDeg();
6654  int op = set[length].GetpFDeg();
6655 
6656  int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6657  int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6658  int inda;
6659  int indi;
6660 
6661  if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6662  return length + 1;
6663  int i;
6664  int an = 0;
6665  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6666  int en = length;
6667  loop
6668  {
6669  if (an >= en-1)
6670  {
6671  op = set[an].GetpFDeg();
6672  if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6673  return en;
6674  return an;
6675  }
6676  i = (an + en) / 2;
6677  indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6678  op = set[i].GetpFDeg();
6679  if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6680  // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6681  {
6682  an = i;
6683  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6684  }
6685  else
6686  en = i;
6687  }
6688 } */
6689 
6690 /*2
6691 * looks up the position of polynomial p in set
6692 * set[length] is the smallest element in set with respect
6693 * to the ordering-procedure totaldegree,pLength0
6694 */
6695 int posInL110 (const LSet set, const int length,
6696  LObject* p,const kStrategy)
6697 {
6698  if (length<0) return 0;
6699 
6700  int o = p->GetpFDeg();
6701  int op = set[length].GetpFDeg();
6702 
6703  if ((op > o)
6704  || ((op == o) && (set[length].length >p->length))
6705  || ((op == o) && (set[length].length <= p->length)
6706  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6707  return length+1;
6708  int i;
6709  int an = 0;
6710  int en= length;
6711  loop
6712  {
6713  if (an >= en-1)
6714  {
6715  op = set[an].GetpFDeg();
6716  if ((op > o)
6717  || ((op == o) && (set[an].length >p->length))
6718  || ((op == o) && (set[an].length <=p->length)
6719  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6720  return en;
6721  return an;
6722  }
6723  i=(an+en) / 2;
6724  op = set[i].GetpFDeg();
6725  if ((op > o)
6726  || ((op == o) && (set[i].length > p->length))
6727  || ((op == o) && (set[i].length <= p->length)
6728  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6729  an=i;
6730  else
6731  en=i;
6732  }
6733 }
6734 
6735 #ifdef HAVE_RINGS
6736 int posInL110Ring (const LSet set, const int length,
6737  LObject* p,const kStrategy)
6738 {
6739  if (length<0) return 0;
6740 
6741  int o = p->GetpFDeg();
6742  int op = set[length].GetpFDeg();
6743 
6744  if ((op > o)
6745  || ((op == o) && (set[length].length >p->length))
6746  || ((op == o) && (set[length].length <= p->length)
6747  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6748  return length+1;
6749  int i;
6750  int an = 0;
6751  int en= length;
6752  loop
6753  {
6754  if (an >= en-1)
6755  {
6756  op = set[an].GetpFDeg();
6757  if ((op > o)
6758  || ((op == o) && (set[an].length >p->length))
6759  || ((op == o) && (set[an].length <=p->length)
6760  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6761  return en;
6762  return an;
6763  }
6764  i=(an+en) / 2;
6765  op = set[i].GetpFDeg();
6766  if ((op > o)
6767  || ((op == o) && (set[i].length > p->length))
6768  || ((op == o) && (set[i].length <= p->length)
6769  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6770  an=i;
6771  else
6772  en=i;
6773  }
6774 }
6775 #endif
6776 
6777 /*2
6778 * looks up the position of polynomial p in set
6779 * e is the ecart of p
6780 * set[length] is the smallest element in set with respect
6781 * to the ordering-procedure totaldegree
6782 */
6783 int posInL13 (const LSet set, const int length,
6784  LObject* p,const kStrategy)
6785 {
6786  if (length<0) return 0;
6787 
6788  int o = p->GetpFDeg();
6789 
6790  if (set[length].GetpFDeg() > o)
6791  return length+1;
6792 
6793  int i;
6794  int an = 0;
6795  int en= length;
6796  loop
6797  {
6798  if (an >= en-1)
6799  {
6800  if (set[an].GetpFDeg() >= o)
6801  return en;
6802  return an;
6803  }
6804  i=(an+en) / 2;
6805  if (set[i].GetpFDeg() >= o)
6806  an=i;
6807  else
6808  en=i;
6809  }
6810 }
6811 
6812 /*2
6813 * looks up the position of polynomial p in set
6814 * e is the ecart of p
6815 * set[length] is the smallest element in set with respect
6816 * to the ordering-procedure maximaldegree,pComp
6817 */
6818 int posInL15 (const LSet set, const int length,
6819  LObject* p,const kStrategy)
6820 {
6821  if (length<0) return 0;
6822 
6823  int o = p->GetpFDeg() + p->ecart;
6824  int op = set[length].GetpFDeg() + set[length].ecart;
6825 
6826  if ((op > o)
6827  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6828  return length+1;
6829  int i;
6830  int an = 0;
6831  int en= length;
6832  loop
6833  {
6834  if (an >= en-1)
6835  {
6836  op = set[an].GetpFDeg() + set[an].ecart;
6837  if ((op > o)
6838  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6839  return en;
6840  return an;
6841  }
6842  i=(an+en) / 2;
6843  op = set[i].GetpFDeg() + set[i].ecart;
6844  if ((op > o)
6845  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6846  an=i;
6847  else
6848  en=i;
6849  }
6850 }
6851 
6852 #ifdef HAVE_RINGS
6853 int posInL15Ring (const LSet set, const int length,
6854  LObject* p,const kStrategy)
6855 {
6856  if (length<0) return 0;
6857 
6858  int o = p->GetpFDeg() + p->ecart;
6859  int op = set[length].GetpFDeg() + set[length].ecart;
6860 
6861  if ((op > o)
6862  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6863  return length+1;
6864  int i;
6865  int an = 0;
6866  int en= length;
6867  loop
6868  {
6869  if (an >= en-1)
6870  {
6871  op = set[an].GetpFDeg() + set[an].ecart;
6872  if ((op > o)
6873  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6874  return en;
6875  return an;
6876  }
6877  i=(an+en) / 2;
6878  op = set[i].GetpFDeg() + set[i].ecart;
6879  if ((op > o)
6880  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6881  an=i;
6882  else
6883  en=i;
6884  }
6885 }
6886 #endif
6887 
6888 /*2
6889 * looks up the position of polynomial p in set
6890 * e is the ecart of p
6891 * set[length] is the smallest element in set with respect
6892 * to the ordering-procedure totaldegree
6893 */
6894 int posInL17 (const LSet set, const int length,
6895  LObject* p,const kStrategy)
6896 {
6897  if (length<0) return 0;
6898 
6899  int o = p->GetpFDeg() + p->ecart;
6900 
6901  if ((set[length].GetpFDeg() + set[length].ecart > o)
6902  || ((set[length].GetpFDeg() + set[length].ecart == o)
6903  && (set[length].ecart > p->ecart))
6904  || ((set[length].GetpFDeg() + set[length].ecart == o)
6905  && (set[length].ecart == p->ecart)
6906  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6907  return length+1;
6908  int i;
6909  int an = 0;
6910  int en= length;
6911  loop
6912  {
6913  if (an >= en-1)
6914  {
6915  if ((set[an].GetpFDeg() + set[an].ecart > o)
6916  || ((set[an].GetpFDeg() + set[an].ecart == o)
6917  && (set[an].ecart > p->ecart))
6918  || ((set[an].GetpFDeg() + set[an].ecart == o)
6919  && (set[an].ecart == p->ecart)
6920  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6921  return en;
6922  return an;
6923  }
6924  i=(an+en) / 2;
6925  if ((set[i].GetpFDeg() + set[i].ecart > o)
6926  || ((set[i].GetpFDeg() + set[i].ecart == o)
6927  && (set[i].ecart > p->ecart))
6928  || ((set[i].GetpFDeg() +set[i].ecart == o)
6929  && (set[i].ecart == p->ecart)
6930  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6931  an=i;
6932  else
6933  en=i;
6934  }
6935 }
6936 
6937 #ifdef HAVE_RINGS
6938 int posInL17Ring (const LSet set, const int length,
6939  LObject* p,const kStrategy)
6940 {
6941  if (length<0) return 0;
6942 
6943  int o = p->GetpFDeg() + p->ecart;
6944 
6945  if ((set[length].GetpFDeg() + set[length].ecart > o)
6946  || ((set[length].GetpFDeg() + set[length].ecart == o)
6947  && (set[length].ecart > p->ecart))
6948  || ((set[length].GetpFDeg() + set[length].ecart == o)
6949  && (set[length].ecart == p->ecart)
6950  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6951  return length+1;
6952  int i;
6953  int an = 0;
6954  int en= length;
6955  loop
6956  {
6957  if (an >= en-1)
6958  {
6959  if ((set[an].GetpFDeg() + set[an].ecart > o)
6960  || ((set[an].GetpFDeg() + set[an].ecart == o)
6961  && (set[an].ecart > p->ecart))
6962  || ((set[an].GetpFDeg() + set[an].ecart == o)
6963  && (set[an].ecart == p->ecart)
6964  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6965  return en;
6966  return an;
6967  }
6968  i=(an+en) / 2;
6969  if ((set[i].GetpFDeg() + set[i].ecart > o)
6970  || ((set[i].GetpFDeg() + set[i].ecart == o)
6971  && (set[i].ecart > p->ecart))
6972  || ((set[i].GetpFDeg() +set[i].ecart == o)
6973  && (set[i].ecart == p->ecart)
6974  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6975  an=i;
6976  else
6977  en=i;
6978  }
6979 }
6980 #endif
6981 
6982 /*2
6983 * looks up the position of polynomial p in set
6984 * e is the ecart of p
6985 * set[length] is the smallest element in set with respect
6986 * to the ordering-procedure pComp
6987 */
6988 int posInL17_c (const LSet set, const int length,
6989  LObject* p,const kStrategy)
6990 {
6991  if (length<0) return 0;
6992 
6993  int cc = (-1+2*currRing->order[0]==ringorder_c);
6994  /* cc==1 for (c,..), cc==-1 for (C,..) */
6995  long c = pGetComp(p->p)*cc;
6996  int o = p->GetpFDeg() + p->ecart;
6997 
6998  if (pGetComp(set[length].p)*cc > c)
6999  return length+1;
7000  if (pGetComp(set[length].p)*cc == c)
7001  {
7002  if ((set[length].GetpFDeg() + set[length].ecart > o)
7003  || ((set[length].GetpFDeg() + set[length].ecart == o)
7004  && (set[length].ecart > p->ecart))
7005  || ((set[length].GetpFDeg() + set[length].ecart == o)
7006  && (set[length].ecart == p->ecart)
7007  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
7008  return length+1;
7009  }
7010  int i;
7011  int an = 0;
7012  int en= length;
7013  loop
7014  {
7015  if (an >= en-1)
7016  {
7017  if (pGetComp(set[an].p)*cc > c)
7018  return en;
7019  if (pGetComp(set[an].p)*cc == c)
7020  {
7021  if ((set[an].GetpFDeg() + set[an].ecart > o)
7022  || ((set[an].GetpFDeg() + set[an].ecart == o)
7023  && (set[an].ecart > p->ecart))
7024  || ((set[an].GetpFDeg() + set[an].ecart == o)
7025  && (set[an].ecart == p->ecart)
7026  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
7027  return en;
7028  }
7029  return an;
7030  }
7031  i=(an+en) / 2;
7032  if (pGetComp(set[i].p)*cc > c)
7033  an=i;
7034  else if (pGetComp(set[i].p)*cc == c)
7035  {
7036  if ((set[i].GetpFDeg() + set[i].ecart > o)
7037  || ((set[i].GetpFDeg() + set[i].ecart == o)
7038  && (set[i].ecart > p->ecart))
7039  || ((set[i].GetpFDeg() +set[i].ecart == o)
7040  && (set[i].ecart == p->ecart)
7041  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
7042  an=i;
7043  else
7044  en=i;
7045  }
7046  else
7047  en=i;
7048  }
7049 }
7050 
7051 #ifdef HAVE_RINGS
7052 int posInL17_cRing (const LSet set, const int length,
7053  LObject* p,const kStrategy)
7054 {
7055  if (length<0) return 0;
7056 
7057  int cc = (-1+2*currRing->order[0]==ringorder_c);
7058  /* cc==1 for (c,..), cc==-1 for (C,..) */
7059  unsigned long c = pGetComp(p->p)*cc;
7060  int o = p->GetpFDeg() + p->ecart;
7061 
7062  if (pGetComp(set[length].p)*cc > c)
7063  return length+1;
7064  if (pGetComp(set[length].p)*cc == c)
7065  {
7066  if ((set[length].GetpFDeg() + set[length].ecart > o)
7067  || ((set[length].GetpFDeg() + set[length].ecart == o)
7068  && (set[length].ecart > p->ecart))
7069  || ((set[length].GetpFDeg() + set[length].ecart == o)
7070  && (set[length].ecart == p->ecart)
7071  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
7072  return length+1;
7073  }
7074  int i;
7075  int an = 0;
7076  int en= length;
7077  loop
7078  {
7079  if (an >= en-1)
7080  {
7081  if (pGetComp(set[an].p)*cc > c)
7082  return en;
7083  if (pGetComp(set[an].p)*cc == c)
7084  {
7085  if ((set[an].GetpFDeg() + set[an].ecart > o)
7086  || ((set[an].GetpFDeg() + set[an].ecart == o)
7087  && (set[an].ecart > p->ecart))
7088  || ((set[an].GetpFDeg() + set[an].ecart == o)
7089  && (set[an].ecart == p->ecart)
7090  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
7091  return en;
7092  }
7093  return an;
7094  }
7095  i=(an+en) / 2;
7096  if (pGetComp(set[i].p)*cc > c)
7097  an=i;
7098  else if (pGetComp(set[i].p)*cc == c)
7099  {
7100  if ((set[i].GetpFDeg() + set[i].ecart > o)
7101  || ((set[i].GetpFDeg() + set[i].ecart == o)
7102  && (set[i].ecart > p->ecart))
7103  || ((set[i].GetpFDeg() +set[i].ecart == o)
7104  && (set[i].ecart == p->ecart)
7105  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
7106  an=i;
7107  else
7108  en=i;
7109  }
7110  else
7111  en=i;
7112  }
7113 }
7114 #endif
7115 
7116 /*
7117  * SYZYGY CRITERION for signature-based standard basis algorithms
7118  */
7119 BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
7120 {
7121 //#if 1
7122 #ifdef DEBUGF5
7123  PrintS("syzygy criterion checks: ");
7124  pWrite(sig);
7125 #endif
7126  for (int k=0; k<strat->syzl; k++)
7127  {
7128  //printf("-%d",k);
7129 //#if 1
7130 #ifdef DEBUGF5
7131  Print("checking with: %d / %d -- \n",k,strat->syzl);
7132  pWrite(pHead(strat->syz[k]));
7133 #endif
7134  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7135  && (!rField_is_Ring(currRing) ||
7136  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7137  {
7138 //#if 1
7139 #ifdef DEBUGF5
7140  PrintS("DELETE!\n");
7141 #endif
7142  strat->nrsyzcrit++;
7143  //printf("- T -\n\n");
7144  return TRUE;
7145  }
7146  }
7147  //printf("- F -\n\n");
7148  return FALSE;
7149 }
7150 
7151 /*
7152  * SYZYGY CRITERION for signature-based standard basis algorithms
7153  */
7154 BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
7155 {
7156 //#if 1
7157  if(sig == NULL)
7158  return FALSE;
7159 #ifdef DEBUGF5
7160  PrintS("--- syzygy criterion checks: ");
7161  pWrite(sig);
7162 #endif
7163  int comp = __p_GetComp(sig, currRing);
7164  int min, max;
7165  if (comp<=1)
7166  return FALSE;
7167  else
7168  {
7169  min = strat->syzIdx[comp-2];
7170  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
7171  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
7172  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
7173  if (comp == strat->currIdx)
7174  {
7175  max = strat->syzl;
7176  }
7177  else
7178  {
7179  max = strat->syzIdx[comp-1];
7180  }
7181  for (int k=min; k<max; k++)
7182  {
7183 #ifdef F5DEBUG
7184  Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
7185  Print("checking with: %d -- ",k);
7186  pWrite(pHead(strat->syz[k]));
7187 #endif
7188  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7189  && (!rField_is_Ring(currRing) ||
7190  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7191  {
7192  strat->nrsyzcrit++;
7193  return TRUE;
7194  }
7195  }
7196  return FALSE;
7197  }
7198 }
7199 
7200 /*
7201  * REWRITTEN CRITERION for signature-based standard basis algorithms
7202  */
7203 BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
7204 {
7205  //printf("Faugere Rewritten Criterion\n");
7207  return FALSE;
7208 //#if 1
7209 #ifdef DEBUGF5
7210  PrintS("rewritten criterion checks: ");
7211  pWrite(sig);
7212 #endif
7213  for(int k = strat->sl; k>=start; k--)
7214  {
7215 //#if 1
7216 #ifdef DEBUGF5
7217  PrintS("checking with: ");
7218  pWrite(strat->sig[k]);
7219  pWrite(pHead(strat->S[k]));
7220 #endif
7221  if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
7222  {
7223 //#if 1
7224 #ifdef DEBUGF5
7225  PrintS("DELETE!\n");
7226 #endif
7227  strat->nrrewcrit++;
7228  return TRUE;
7229  }
7230  //k--;
7231  }
7232 #ifdef DEBUGF5
7233  PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
7234  for(int kk = 0; kk<strat->sl+1; kk++)
7235  {
7236  pWrite(pHead(strat->S[kk]));
7237  }
7238  PrintS("------------------------------\n");
7239 #endif
7240  return FALSE;
7241 }
7242 
7243 /*
7244  * REWRITTEN CRITERION for signature-based standard basis algorithms
7245  ***************************************************************************
7246  * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
7247  ***************************************************************************
7248  */
7249 
7250 // real implementation of arri's rewritten criterion, only called once in
7251 // kstd2.cc, right before starting reduction
7252 // IDEA: Arri says that it is enough to consider 1 polynomial for each unique
7253 // signature appearing during the computations. Thus we first of all go
7254 // through strat->L and delete all other pairs of the same signature,
7255 // keeping only the one with least possible leading monomial. After this
7256 // we check if we really need to compute this critical pair at all: There
7257 // can be elements already in strat->S whose signatures divide the
7258 // signature of the critical pair in question and whose multiplied
7259 // leading monomials are smaller than the leading monomial of the
7260 // critical pair. In this situation we can discard the critical pair
7261 // completely.
7262 BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
7263 {
7265  return FALSE;
7266  poly p1 = pOne();
7267  poly p2 = pOne();
7268  for (int ii=strat->sl; ii>start; ii--)
7269  {
7270  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
7271  {
7272  p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
7273  p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
7274  if (!(pLmCmp(p1,p2) == 1))
7275  {
7276  pDelete(&p1);
7277  pDelete(&p2);
7278  return TRUE;
7279  }
7280  }
7281  }
7282  pDelete(&p1);
7283  pDelete(&p2);
7284  return FALSE;
7285 }
7286 
7287 BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
7288 {
7289  //Over Rings, there are still some changes to do: considering coeffs
7291  return FALSE;
7292  int found = -1;
7293  for (int i=strat->Bl; i>-1; i--)
7294  {
7295  if (pLmEqual(strat->B[i].sig,sig))
7296  {
7297  found = i;
7298  break;
7299  }
7300  }
7301  if (found != -1)
7302  {
7303  if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
7304  {
7305  deleteInL(strat->B,&strat->Bl,found,strat);
7306  }
7307  else
7308  {
7309  return TRUE;
7310  }
7311  }
7312  poly p1 = pOne();
7313  poly p2 = pOne();
7314  for (int ii=strat->sl; ii>-1; ii--)
7315  {
7316  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
7317  {
7318  p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
7319  p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
7320  if (!(pLmCmp(p1,p2) == 1))
7321  {
7322  pDelete(&p1);
7323  pDelete(&p2);
7324  return TRUE;
7325  }
7326  }
7327  }
7328  pDelete(&p1);
7329  pDelete(&p2);
7330  return FALSE;
7331 }
7332 
7333 /***************************************************************
7334  *
7335  * Tail reductions
7336  *
7337  ***************************************************************/
7338 TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
7339 {
7340  int j = 0;
7341  const unsigned long not_sev = ~L->sev;
7342  const unsigned long* sev = strat->sevS;
7343  poly p;
7344  ring r;
7345  L->GetLm(p, r);
7346 
7347  assume(~not_sev == p_GetShortExpVector(p, r));
7348 
7349  if (r == currRing)
7350  {
7351  if(!rField_is_Ring(r))
7352  {
7353  loop
7354  {
7355  if (j > end_pos) return NULL;
7356  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7357  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7358  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7359  {
7360  break;
7361  }
7362  #else
7363  if (!(sev[j] & not_sev) &&
7364  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7365  p_LmDivisibleBy(strat->S[j], p, r))
7366  {
7367  break;
7368  }
7369  #endif
7370  j++;
7371  }
7372  }
7373  #ifdef HAVE_RINGS
7374  else
7375  {
7376  loop
7377  {
7378  if (j > end_pos) return NULL;
7379  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7380  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7381  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7382  {
7383  break;
7384  }
7385  #else
7386  if (!(sev[j] & not_sev) &&
7387  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7388  p_LmDivisibleBy(strat->S[j], p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7389  {
7390  break;
7391  }
7392  #endif
7393  j++;
7394  }
7395  }
7396  #endif
7397  // if called from NF, T objects do not exist:
7398  if (strat->tl < 0 || strat->S_2_R[j] == -1)
7399  {
7400  T->Set(strat->S[j], r, strat->tailRing);
7401  assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
7402  return T;
7403  }
7404  else
7405  {
7406 ///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
7407 ///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
7408 // assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
7409  return strat->S_2_T(j);
7410  }
7411  }
7412  else
7413  {
7414  TObject* t;
7415  if(!rField_is_Ring(r))
7416  {
7417  loop
7418  {
7419  if (j > end_pos) return NULL;
7420  assume(strat->S_2_R[j] != -1);
7421  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7422  t = strat->S_2_T(j);
7423  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7424  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7425  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7426  {
7427  t->pLength=pLength(t->t_p);
7428  return t;
7429  }
7430  #else
7431  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7432  {
7433  t = strat->S_2_T(j);
7434  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7435  if (p_LmDivisibleBy(t->t_p, p, r))
7436  {
7437  t->pLength=pLength(t->t_p);
7438  return t;
7439  }
7440  }
7441  #endif
7442  j++;
7443  }
7444  }
7445  #ifdef HAVE_RINGS
7446  else
7447  {
7448  loop
7449  {
7450  if (j > end_pos) return NULL;
7451  assume(strat->S_2_R[j] != -1);
7452  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7453  t = strat->S_2_T(j);
7454  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7455  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7456  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7457  {
7458  t->pLength=pLength(t->t_p);
7459  return t;
7460  }
7461  #else
7462  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7463  {
7464  t = strat->S_2_T(j);
7465  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7466  if (p_LmDivisibleBy(t->t_p, p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7467  {
7468  t->pLength=pLength(t->t_p);
7469  return t;
7470  }
7471  }
7472  #endif
7473  j++;
7474  }
7475  }
7476  #endif
7477  }
7478 }
7479 
7480 poly redtail (LObject* L, int end_pos, kStrategy strat)
7481 {
7482  poly h, hn;
7483  strat->redTailChange=FALSE;
7484 
7485  L->GetP();
7486  poly p = L->p;
7487  if (strat->noTailReduction || pNext(p) == NULL)
7488  return p;
7489 
7490  LObject Ln(strat->tailRing);
7491  TObject* With;
7492  // placeholder in case strat->tl < 0
7493  TObject With_s(strat->tailRing);
7494  h = p;
7495  hn = pNext(h);
7496  long op = strat->tailRing->pFDeg(hn, strat->tailRing);
7497  long e;
7498  int l;
7499  BOOLEAN save_HE=strat->kHEdgeFound;
7500  strat->kHEdgeFound |=
7501  ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
7502 
7503  while(hn != NULL)
7504  {
7505  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7506  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7507  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7508  loop
7509  {
7510  Ln.Set(hn, strat->tailRing);
7511  Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
7512  if (strat->kHEdgeFound)
7513  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7514  else
7515  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
7516  if (With == NULL) break;
7517  With->length=0;
7518  With->pLength=0;
7519  strat->redTailChange=TRUE;
7520  if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
7521  {
7522  // reducing the tail would violate the exp bound
7523  if (kStratChangeTailRing(strat, L))
7524  {
7525  strat->kHEdgeFound = save_HE;
7526  return redtail(L, end_pos, strat);
7527  }
7528  else
7529  return NULL;
7530  }
7531  hn = pNext(h);
7532  if (hn == NULL) goto all_done;
7533  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7534  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7535  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7536  }
7537  h = hn;
7538  hn = pNext(h);
7539  }
7540 
7541  all_done:
7542  if (strat->redTailChange)
7543  {
7544  L->pLength = 0;
7545  }
7546  strat->kHEdgeFound = save_HE;
7547  return p;
7548 }
7549 
7550 poly redtail (poly p, int end_pos, kStrategy strat)
7551 {
7552  LObject L(p, currRing);
7553  return redtail(&L, end_pos, strat);
7554 }
7555 
7556 poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
7557 {
7558 #define REDTAIL_CANONICALIZE 100
7559  strat->redTailChange=FALSE;
7560  if (strat->noTailReduction) return L->GetLmCurrRing();
7561  poly h, p;
7562  p = h = L->GetLmTailRing();
7563  if ((h==NULL) || (pNext(h)==NULL))
7564  return L->GetLmCurrRing();
7565 
7566  TObject* With;
7567  // placeholder in case strat->tl < 0
7568  TObject With_s(strat->tailRing);
7569 
7570  LObject Ln(pNext(h), strat->tailRing);
7571  Ln.GetpLength();
7572 
7573  pNext(h) = NULL;
7574  if (L->p != NULL)
7575  {
7576  pNext(L->p) = NULL;
7577  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7578  }
7579  L->pLength = 1;
7580 
7581  Ln.PrepareRed(strat->use_buckets);
7582 
7583  int cnt=REDTAIL_CANONICALIZE;
7584  while(!Ln.IsNull())
7585  {
7586  loop
7587  {
7588  if (TEST_OPT_IDLIFT)
7589  {
7590  if (Ln.p!=NULL)
7591  {
7592  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7593  }
7594  else
7595  {
7596  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7597  }
7598  }
7599  Ln.SetShortExpVector();
7600  if (withT)
7601  {
7602  int j;
7603  j = kFindDivisibleByInT(strat, &Ln);
7604  if (j < 0) break;
7605  With = &(strat->T[j]);
7606  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7607  }
7608  else
7609  {
7610  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7611  if (With == NULL) break;
7612  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7613  }
7614  cnt--;
7615  if (cnt==0)
7616  {
7618  /*poly tmp=*/Ln.CanonicalizeP();
7619  if (normalize)
7620  {
7621  Ln.Normalize();
7622  //pNormalize(tmp);
7623  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7624  }
7625  }
7626  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7627  {
7628  With->pNorm();
7629  }
7630  strat->redTailChange=TRUE;
7631  if (ksReducePolyTail(L, With, &Ln))
7632  {
7633  // reducing the tail would violate the exp bound
7634  // set a flag and hope for a retry (in bba)
7635  strat->completeReduce_retry=TRUE;
7636  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7637  do
7638  {
7639  pNext(h) = Ln.LmExtractAndIter();
7640  pIter(h);
7641  L->pLength++;
7642  } while (!Ln.IsNull());
7643  goto all_done;
7644  }
7645  if (Ln.IsNull()) goto all_done;
7646  if (! withT) With_s.Init(currRing);
7647  }
7648  pNext(h) = Ln.LmExtractAndIter();
7649  pIter(h);
7650  pNormalize(h);
7651  L->pLength++;
7652  }
7653 
7654  all_done:
7655  Ln.Delete();
7656  if (L->p != NULL) pNext(L->p) = pNext(p);
7657 
7658  if (strat->redTailChange)
7659  {
7660  L->length = 0;
7661  L->pLength = 0;
7662  }
7663 
7664  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7665  //L->Normalize(); // HANNES: should have a test
7666  kTest_L(L,strat->tailRing);
7667  return L->GetLmCurrRing();
7668 }
7669 
7670 poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7671 {
7672  strat->redTailChange=FALSE;
7673  if (strat->noTailReduction) return L->GetLmCurrRing();
7674  poly h, p;
7675  p = h = L->GetLmTailRing();
7676  if ((h==NULL) || (pNext(h)==NULL))
7677  return L->GetLmCurrRing();
7678 
7679  TObject* With;
7680  // placeholder in case strat->tl < 0
7681  TObject With_s(strat->tailRing);
7682 
7683  LObject Ln(pNext(h), strat->tailRing);
7684  Ln.pLength = L->GetpLength() - 1;
7685 
7686  pNext(h) = NULL;
7687  if (L->p != NULL) pNext(L->p) = NULL;
7688  L->pLength = 1;
7689 
7690  Ln.PrepareRed(strat->use_buckets);
7691 
7692  int cnt=REDTAIL_CANONICALIZE;
7693  while(!Ln.IsNull())
7694  {
7695  loop
7696  {
7697  if (TEST_OPT_IDLIFT)
7698  {
7699  if (Ln.p!=NULL)
7700  {
7701  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7702  }
7703  else
7704  {
7705  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7706  }
7707  }
7708  Ln.SetShortExpVector();
7709  if (withT)
7710  {
7711  int j;
7712  j = kFindDivisibleByInT(strat, &Ln);
7713  if (j < 0) break;
7714  With = &(strat->T[j]);
7715  }
7716  else
7717  {
7718  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7719  if (With == NULL) break;
7720  }
7721  cnt--;
7722  if (cnt==0)
7723  {
7725  /*poly tmp=*/Ln.CanonicalizeP();
7726  if (normalize)
7727  {
7728  Ln.Normalize();
7729  //pNormalize(tmp);
7730  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7731  }
7732  }
7733  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7734  {
7735  With->pNorm();
7736  }
7737  strat->redTailChange=TRUE;
7738  if (ksReducePolyTail(L, With, &Ln))
7739  {
7740  // reducing the tail would violate the exp bound
7741  // set a flag and hope for a retry (in bba)
7742  strat->completeReduce_retry=TRUE;
7743  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7744  do
7745  {
7746  pNext(h) = Ln.LmExtractAndIter();
7747  pIter(h);
7748  L->pLength++;
7749  } while (!Ln.IsNull());
7750  goto all_done;
7751  }
7752  if(!Ln.IsNull())
7753  {
7754  Ln.GetP();
7755  Ln.p = pJet(Ln.p,bound);
7756  }
7757  if (Ln.IsNull())
7758  {
7759  goto all_done;
7760  }
7761  if (! withT) With_s.Init(currRing);
7762  }
7763  pNext(h) = Ln.LmExtractAndIter();
7764  pIter(h);
7765  pNormalize(h);
7766  L->pLength++;
7767  }
7768 
7769  all_done:
7770  Ln.Delete();
7771  if (L->p != NULL) pNext(L->p) = pNext(p);
7772 
7773  if (strat->redTailChange)
7774  {
7775  L->length = 0;
7776  L->pLength = 0;
7777  }
7778 
7779  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7780  //L->Normalize(); // HANNES: should have a test
7781  kTest_L(L,strat->tailRing);
7782  return L->GetLmCurrRing();
7783 }
7784 
7785 #ifdef HAVE_RINGS
7786 void redtailBbaAlsoLC_Z (LObject* L, int end_pos, kStrategy strat )
7787 // normalize=FALSE, withT=FALSE, coeff=Z
7788 {
7789  strat->redTailChange=FALSE;
7790 
7791  poly h, p;
7792  p = h = L->GetLmTailRing();
7793  if ((h==NULL) || (pNext(h)==NULL))
7794  return;
7795 
7796  TObject* With;
7797  LObject Ln(pNext(h), strat->tailRing);
7798  Ln.GetpLength();
7799 
7800  pNext(h) = NULL;
7801  if (L->p != NULL)
7802  {
7803  pNext(L->p) = NULL;
7804  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7805  }
7806  L->pLength = 1;
7807 
7808  Ln.PrepareRed(strat->use_buckets);
7809 
7810  int cnt=REDTAIL_CANONICALIZE;
7811 
7812  while(!Ln.IsNull())
7813  {
7814  loop
7815  {
7816  if (TEST_OPT_IDLIFT)
7817  {
7818  if (Ln.p!=NULL)
7819  {
7820  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7821  }
7822  else
7823  {
7824  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7825  }
7826  }
7827  Ln.SetShortExpVector();
7828  int j;
7829  j = kFindDivisibleByInT(strat, &Ln);
7830  if (j < 0)
7831  {
7832  j = kFindDivisibleByInT_Z(strat, &Ln);
7833  if (j < 0)
7834  {
7835  break;
7836  }
7837  else
7838  {
7839  /* reduction not cancelling a tail term, but reducing its coefficient */
7840  With = &(strat->T[j]);
7841  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7842  cnt--;
7843  if (cnt==0)
7844  {
7846  /*poly tmp=*/Ln.CanonicalizeP();
7847  }
7848  strat->redTailChange=TRUE;
7849  /* reduction cancelling a tail term */
7850  if (ksReducePolyTailLC_Z(L, With, &Ln))
7851  {
7852  // reducing the tail would violate the exp bound
7853  // set a flag and hope for a retry (in bba)
7854  strat->completeReduce_retry=TRUE;
7855  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7856  do
7857  {
7858  pNext(h) = Ln.LmExtractAndIter();
7859  pIter(h);
7860  L->pLength++;
7861  } while (!Ln.IsNull());
7862  goto all_done;
7863  }
7864  /* we have to break since we did not cancel the term, but only decreased
7865  * its coefficient. */
7866  break;
7867  }
7868  } else {
7869  With = &(strat->T[j]);
7870  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7871  cnt--;
7872  if (cnt==0)
7873  {
7875  /*poly tmp=*/Ln.CanonicalizeP();
7876  }
7877  strat->redTailChange=TRUE;
7878  /* reduction cancelling a tail term */
7879  if (ksReducePolyTail_Z(L, With, &Ln))
7880  {
7881  // reducing the tail would violate the exp bound
7882  // set a flag and hope for a retry (in bba)
7883  strat->completeReduce_retry=TRUE;
7884  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7885  do
7886  {
7887  pNext(h) = Ln.LmExtractAndIter();
7888  pIter(h);
7889  L->pLength++;
7890  } while (!Ln.IsNull());
7891  goto all_done;
7892  }
7893  }
7894  if (Ln.IsNull()) goto all_done;
7895  }
7896  pNext(h) = Ln.LmExtractAndIter();
7897  pIter(h);
7898  L->pLength++;
7899  }
7900 
7901  all_done:
7902  Ln.Delete();
7903  if (L->p != NULL) pNext(L->p) = pNext(p);
7904 
7905  if (strat->redTailChange)
7906  {
7907  L->length = 0;
7908  L->pLength = 0;
7909  }
7910 
7911  kTest_L(L, strat->tailRing);
7912  return;
7913 }
7914 
7915 poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7916 // normalize=FALSE, withT=FALSE, coeff=Z
7917 {
7918  strat->redTailChange=FALSE;
7919  if (strat->noTailReduction) return L->GetLmCurrRing();
7920  poly h, p;
7921  p = h = L->GetLmTailRing();
7922  if ((h==NULL) || (pNext(h)==NULL))
7923  return L->GetLmCurrRing();
7924 
7925  TObject* With;
7926  // placeholder in case strat->tl < 0
7927  TObject With_s(strat->tailRing);
7928 
7929  LObject Ln(pNext(h), strat->tailRing);
7930  Ln.pLength = L->GetpLength() - 1;
7931 
7932  pNext(h) = NULL;
7933  if (L->p != NULL) pNext(L->p) = NULL;
7934  L->pLength = 1;
7935 
7936  Ln.PrepareRed(strat->use_buckets);
7937 
7938  int cnt=REDTAIL_CANONICALIZE;
7939  while(!Ln.IsNull())
7940  {
7941  loop
7942  {
7943  Ln.SetShortExpVector();
7944  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7945  if (With == NULL) break;
7946  cnt--;
7947  if (cnt==0)
7948  {
7950  /*poly tmp=*/Ln.CanonicalizeP();
7951  }
7952  // we are in Z, do not call pNorm
7953  strat->redTailChange=TRUE;
7954  // test divisibility of coefs:
7955  poly p_Ln=Ln.GetLmCurrRing();
7956  poly p_With=With->GetLmCurrRing();
7957  number z=n_IntMod(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf);
7958  if (!nIsZero(z))
7959  {
7960  // subtract z*Ln, add z.Ln to L
7961  poly m=pHead(p_Ln);
7962  pSetCoeff(m,z);
7963  poly mm=pHead(m);
7964  pNext(h) = m;
7965  pIter(h);
7966  L->pLength++;
7967  mm=pNeg(mm);
7968  if (Ln.bucket!=NULL)
7969  {
7970  int dummy=1;
7971  kBucket_Add_q(Ln.bucket,mm,&dummy);
7972  }
7973  else
7974  {
7975  if ((Ln.t_p!=NULL)&&(Ln.p==NULL))
7976  Ln.GetP();
7977  if (Ln.p!=NULL)
7978  {
7979  Ln.p=pAdd(Ln.p,mm);
7980  if (Ln.t_p!=NULL)
7981  {
7982  pNext(Ln.t_p)=NULL;
7983  p_LmDelete(Ln.t_p,strat->tailRing);
7984  }
7985  }
7986  }
7987  }
7988  else
7989  nDelete(&z);
7990 
7991  if (ksReducePolyTail(L, With, &Ln))
7992  {
7993  // reducing the tail would violate the exp bound
7994  // set a flag and hope for a retry (in bba)
7995  strat->completeReduce_retry=TRUE;
7996  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7997  do
7998  {
7999  pNext(h) = Ln.LmExtractAndIter();
8000  pIter(h);
8001  L->pLength++;
8002  } while (!Ln.IsNull());
8003  goto all_done;
8004  }
8005  if (Ln.IsNull()) goto all_done;
8006  With_s.Init(currRing);
8007  }
8008  pNext(h) = Ln.LmExtractAndIter();
8009  pIter(h);
8010  pNormalize(h);
8011  L->pLength++;
8012  }
8013 
8014  all_done:
8015  Ln.Delete();
8016  if (L->p != NULL) pNext(L->p) = pNext(p);
8017 
8018  if (strat->redTailChange)
8019  {
8020  L->length = 0;
8021  }
8022 
8023  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
8024  //L->Normalize(); // HANNES: should have a test
8025  kTest_L(L,strat->tailRing);
8026  return L->GetLmCurrRing();
8027 }
8028 #endif
8029 
8030 /*2
8031 *checks the change degree and write progress report
8032 */
8033 void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
8034 {
8035  if (i != *olddeg)
8036  {
8037  Print("%d",i);
8038  *olddeg = i;
8039  }
8040  if (TEST_OPT_OLDSTD)
8041  {
8042  if (strat->Ll != *reduc)
8043  {
8044  if (strat->Ll != *reduc-1)
8045  Print("(%d)",strat->Ll+1);
8046  else
8047  PrintS("-");
8048  *reduc = strat->Ll;
8049  }
8050  else
8051  PrintS(".");
8052  mflush();
8053  }
8054  else
8055  {
8056  if (red_result == 0)
8057  PrintS("-");
8058  else if (red_result < 0)
8059  PrintS(".");
8060  if ((red_result > 0) || ((strat->Ll % 100)==99))
8061  {
8062  if (strat->Ll != *reduc && strat->Ll > 0)
8063  {
8064  Print("(%d)",strat->Ll+1);
8065  *reduc = strat->Ll;
8066  }
8067  }
8068  }
8069 }
8070 
8071 /*2
8072 *statistics
8073 */
8074 void messageStat (int hilbcount,kStrategy strat)
8075 {
8076  //PrintS("\nUsage/Allocation of temporary storage:\n");
8077  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
8078  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
8079  Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
8080  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
8081  #ifdef HAVE_SHIFTBBA
8082  /* in usual case strat->cv is 0, it gets changed only in shift routines */
8083  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
8084  #endif
8085 }
8086 
8087 void messageStatSBA (int hilbcount,kStrategy strat)
8088 {
8089  //PrintS("\nUsage/Allocation of temporary storage:\n");
8090  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
8091  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
8092  Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
8093  //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
8094  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
8095  #ifdef HAVE_SHIFTBBA
8096  /* in usual case strat->cv is 0, it gets changed only in shift routines */
8097  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
8098  #endif
8099 }
8100 
8101 #ifdef KDEBUG
8102 /*2
8103 *debugging output: all internal sets, if changed
8104 *for testing purpuse only/has to be changed for later use
8105 */
8107 {
8108  int i;
8109  if (strat->news)
8110  {
8111  PrintS("set S");
8112  for (i=0; i<=strat->sl; i++)
8113  {
8114  Print("\n %d:",i);
8115  p_wrp(strat->S[i], currRing, strat->tailRing);
8116  if (strat->fromQ!=NULL && strat->fromQ[i])
8117  Print(" (from Q)");
8118  }
8119  strat->news = FALSE;
8120  }
8121  if (strat->newt)
8122  {
8123  PrintS("\nset T");
8124  for (i=0; i<=strat->tl; i++)
8125  {
8126  Print("\n %d:",i);
8127  strat->T[i].wrp();
8128  if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
8129  Print(" o:%ld e:%d l:%d",
8130  strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
8131  }
8132  strat->newt = FALSE;
8133  }
8134  PrintS("\nset L");
8135  for (i=strat->Ll; i>=0; i--)
8136  {
8137  Print("\n%d:",i);
8138  p_wrp(strat->L[i].p1, currRing, strat->tailRing);
8139  PrintS(" ");
8140  p_wrp(strat->L[i].p2, currRing, strat->tailRing);
8141  PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
8142  PrintS("\n p : ");
8143  strat->L[i].wrp();
8144  Print(" o:%ld e:%d l:%d",
8145  strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
8146  }
8147  PrintLn();
8148 }
8149 
8150 #endif
8151 
8152 
8153 /*2
8154 *construct the set s from F
8155 */
8156 void initS (ideal F, ideal Q, kStrategy strat)
8157 {
8158  int i,pos;
8159 
8160  if (Q!=NULL) i=((IDELEMS(F)+IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8161  else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8162  strat->ecartS=initec(i);
8163  strat->sevS=initsevS(i);
8164  strat->S_2_R=initS_2_R(i);
8165  strat->fromQ=NULL;
8166  strat->Shdl=idInit(i,F->rank);
8167  strat->S=strat->Shdl->m;
8168  /*- put polys into S -*/
8169  if (Q!=NULL)
8170  {
8171  strat->fromQ=initec(i);
8172  memset(strat->fromQ,0,i*sizeof(int));
8173  for (i=0; i<IDELEMS(Q); i++)
8174  {
8175  if (Q->m[i]!=NULL)
8176  {
8177  LObject h;
8178  h.p = pCopy(Q->m[i]);
8180  {
8181  h.pCleardenom(); // also does remove Content
8182  }
8183  else
8184  {
8185  h.pNorm();
8186  }
8188  {
8189  deleteHC(&h, strat);
8190  }
8191  if (h.p!=NULL)
8192  {
8193  strat->initEcart(&h);
8194  if (strat->sl==-1)
8195  pos =0;
8196  else
8197  {
8198  pos = posInS(strat,strat->sl,h.p,h.ecart);
8199  }
8200  h.sev = pGetShortExpVector(h.p);
8201  strat->enterS(h,pos,strat,-1);
8202  strat->fromQ[pos]=1;
8203  }
8204  }
8205  }
8206  }
8207  for (i=0; i<IDELEMS(F); i++)
8208  {
8209  if (F->m[i]!=NULL)
8210  {
8211  LObject h;
8212  h.p = pCopy(F->m[i]);
8214  {
8215  cancelunit(&h); /*- tries to cancel a unit -*/
8216  deleteHC(&h, strat);
8217  }
8218  if (h.p!=NULL)
8219  // do not rely on the input being a SB!
8220  {
8222  {
8223  h.pCleardenom(); // also does remove Content
8224  }
8225  else
8226  {
8227  h.pNorm();
8228  }
8229  strat->initEcart(&h);
8230  if (strat->sl==-1)
8231  pos =0;
8232  else
8233  pos = posInS(strat,strat->sl,h.p,h.ecart);
8234  h.sev = pGetShortExpVector(h.p);
8235  strat->enterS(h,pos,strat,-1);
8236  }
8237  }
8238  }
8239  /*- test, if a unit is in F -*/
8240  if ((strat->sl>=0)
8241 #ifdef HAVE_RINGS
8242  && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
8243 #endif
8244  && pIsConstant(strat->S[0]))
8245  {
8246  while (strat->sl>0) deleteInS(strat->sl,strat);
8247  }
8248 }
8249 
8250 void initSL (ideal F, ideal Q,kStrategy strat)
8251 {
8252  int i,pos;
8253 
8254  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8255  else i=setmaxT;
8256  strat->ecartS=initec(i);
8257  strat->sevS=initsevS(i);
8258  strat->S_2_R=initS_2_R(i);
8259  strat->fromQ=NULL;
8260  strat->Shdl=idInit(i,F->rank);
8261  strat->S=strat->Shdl->m;
8262  /*- put polys into S -*/
8263  if (Q!=NULL)
8264  {
8265  strat->fromQ=initec(i);
8266  memset(strat->fromQ,0,i*sizeof(int));
8267  for (i=0; i<IDELEMS(Q); i++)
8268  {
8269  if (Q->m[i]!=NULL)
8270  {
8271  LObject h;
8272  h.p = pCopy(Q->m[i]);
8274  {
8275  deleteHC(&h,strat);
8276  }
8278  {
8279  h.pCleardenom(); // also does remove Content
8280  }
8281  else
8282  {
8283  h.pNorm();
8284  }
8285  if (h.p!=NULL)
8286  {
8287  strat->initEcart(&h);
8288  if (strat->sl==-1)
8289  pos =0;
8290  else
8291  {
8292  pos = posInS(strat,strat->sl,h.p,h.ecart);
8293  }
8294  h.sev = pGetShortExpVector(h.p);
8295  strat->enterS(h,pos,strat,-1);
8296  strat->fromQ[pos]=1;
8297  }
8298  }
8299  }
8300  }
8301  for (i=0; i<IDELEMS(F); i++)
8302  {
8303  if (F->m[i]!=NULL)
8304  {
8305  LObject h;
8306  h.p = pCopy(F->m[i]);
8307  if (h.p!=NULL)
8308  {
8310  {
8311  cancelunit(&h); /*- tries to cancel a unit -*/
8312  deleteHC(&h, strat);
8313  }
8314  if (h.p!=NULL)
8315  {
8317  {
8318  h.pCleardenom(); // also does remove Content
8319  }
8320  else
8321  {
8322  h.pNorm();
8323  }
8324  strat->initEcart(&h);
8325  if (strat->Ll==-1)
8326  pos =0;
8327  else
8328  pos = strat->posInL(strat->L,strat->Ll,&h,strat);
8329  h.sev = pGetShortExpVector(h.p);
8330  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8331  }
8332  }
8333  }
8334  }
8335  /*- test, if a unit is in F -*/
8336 
8337  if ((strat->Ll>=0)
8338 #ifdef HAVE_RINGS
8339  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8340 #endif
8341  && pIsConstant(strat->L[strat->Ll].p))
8342  {
8343  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8344  }
8345 }
8346 
8347 void initSLSba (ideal F, ideal Q,kStrategy strat)
8348 {
8349  int i,pos;
8350  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8351  else i=setmaxT;
8352  strat->ecartS = initec(i);
8353  strat->sevS = initsevS(i);
8354  strat->sevSig = initsevS(i);
8355  strat->S_2_R = initS_2_R(i);
8356  strat->fromQ = NULL;
8357  strat->Shdl = idInit(i,F->rank);
8358  strat->S = strat->Shdl->m;
8359  strat->sig = (poly *)omAlloc0(i*sizeof(poly));
8360  if (strat->sbaOrder != 1)
8361  {
8362  strat->syz = (poly *)omAlloc0(i*sizeof(poly));
8363  strat->sevSyz = initsevS(i);
8364  strat->syzmax = i;
8365  strat->syzl = 0;
8366  }
8367  /*- put polys into S -*/
8368  if (Q!=NULL)
8369  {
8370  strat->fromQ=initec(i);
8371  memset(strat->fromQ,0,i*sizeof(int));
8372  for (i=0; i<IDELEMS(Q); i++)
8373  {
8374  if (Q->m[i]!=NULL)
8375  {
8376  LObject h;
8377  h.p = pCopy(Q->m[i]);
8379  {
8380  deleteHC(&h,strat);
8381  }
8383  {
8384  h.pCleardenom(); // also does remove Content
8385  }
8386  else
8387  {
8388  h.pNorm();
8389  }
8390  if (h.p!=NULL)
8391  {
8392  strat->initEcart(&h);
8393  if (strat->sl==-1)
8394  pos =0;
8395  else
8396  {
8397  pos = posInS(strat,strat->sl,h.p,h.ecart);
8398  }
8399  h.sev = pGetShortExpVector(h.p);
8400  strat->enterS(h,pos,strat,-1);
8401  strat->fromQ[pos]=1;
8402  }
8403  }
8404  }
8405  }
8406  for (i=0; i<IDELEMS(F); i++)
8407  {
8408  if (F->m[i]!=NULL)
8409  {
8410  LObject h;
8411  h.p = pCopy(F->m[i]);
8412  h.sig = pOne();
8413  //h.sig = pInit();
8414  //p_SetCoeff(h.sig,nInit(1),currRing);
8415  p_SetComp(h.sig,i+1,currRing);
8416  // if we are working with the Schreyer order we generate it
8417  // by multiplying the initial signatures with the leading monomial
8418  // of the corresponding initial polynomials generating the ideal
8419  // => we can keep the underlying monomial order and get a Schreyer
8420  // order without any bigger overhead
8421  if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
8422  {
8423  p_ExpVectorAdd (h.sig,F->m[i],currRing);
8424  }
8425  h.sevSig = pGetShortExpVector(h.sig);
8426 #ifdef DEBUGF5
8427  pWrite(h.p);
8428  pWrite(h.sig);
8429 #endif
8430  if (h.p!=NULL)
8431  {
8433  {
8434  cancelunit(&h); /*- tries to cancel a unit -*/
8435  deleteHC(&h, strat);
8436  }
8437  if (h.p!=NULL)
8438  {
8440  {
8441  h.pCleardenom(); // also does remove Content
8442  }
8443  else
8444  {
8445  h.pNorm();
8446  }
8447  strat->initEcart(&h);
8448  if (strat->Ll==-1)
8449  pos =0;
8450  else
8451  pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
8452  h.sev = pGetShortExpVector(h.p);
8453  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8454  }
8455  }
8456  /*
8457  if (strat->sbaOrder != 1)
8458  {
8459  for(j=0;j<i;j++)
8460  {
8461  strat->syz[ctr] = pCopy(F->m[j]);
8462  p_SetCompP(strat->syz[ctr],i+1,currRing);
8463  // add LM(F->m[i]) to the signature to get a Schreyer order
8464  // without changing the underlying polynomial ring at all
8465  p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
8466  // since p_Add_q() destroys all input
8467  // data we need to recreate help
8468  // each time
8469  poly help = pCopy(F->m[i]);
8470  p_SetCompP(help,j+1,currRing);
8471  pWrite(strat->syz[ctr]);
8472  pWrite(help);
8473  printf("%d\n",pLmCmp(strat->syz[ctr],help));
8474  strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
8475  printf("%d. SYZ ",ctr);
8476  pWrite(strat->syz[ctr]);
8477  strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
8478  ctr++;
8479  }
8480  strat->syzl = ps;
8481  }
8482  */
8483  }
8484  }
8485  /*- test, if a unit is in F -*/
8486 
8487  if ((strat->Ll>=0)
8488 #ifdef HAVE_RINGS
8489  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8490 #endif
8491  && pIsConstant(strat->L[strat->Ll].p))
8492  {
8493  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8494  }
8495 }
8496 
8498 {
8499  if( strat->S[0] )
8500  {
8501  if( strat->S[1] && !rField_is_Ring(currRing))
8502  {
8503  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
8504  omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
8505  omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
8506  }
8507  int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
8508  /************************************************************
8509  * computing the length of the syzygy array needed
8510  ***********************************************************/
8511  for(i=1; i<=strat->sl; i++)
8512  {
8513  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8514  {
8515  ps += i;
8516  }
8517  }
8518  ps += strat->sl+1;
8519  //comp = pGetComp (strat->P.sig);
8520  comp = strat->currIdx;
8521  strat->syzIdx = initec(comp);
8522  strat->sevSyz = initsevS(ps);
8523  strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8524  strat->syzmax = ps;
8525  strat->syzl = 0;
8526  strat->syzidxmax = comp;
8527 #if defined(DEBUGF5) || defined(DEBUGF51)
8528  PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8529 #endif
8530  i = 1;
8531  j = 0;
8532  /************************************************************
8533  * generating the leading terms of the principal syzygies
8534  ***********************************************************/
8535  while (i <= strat->sl)
8536  {
8537  /**********************************************************
8538  * principal syzygies start with component index 2
8539  * the array syzIdx starts with index 0
8540  * => the rules for a signature with component comp start
8541  * at strat->syz[strat->syzIdx[comp-2]] !
8542  *********************************************************/
8543  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8544  {
8545  comp = pGetComp(strat->sig[i]);
8546  comp_old = pGetComp(strat->sig[i-1]);
8547  diff = comp - comp_old - 1;
8548  // diff should be zero, but sometimes also the initial generating
8549  // elements of the input ideal reduce to zero. then there is an
8550  // index-gap between the signatures. for these inbetween signatures we
8551  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8552  // in the following.
8553  // doing this, we keep the relation "j = comp - 2" alive, which makes
8554  // jumps way easier when checking criteria
8555  while (diff>0)
8556  {
8557  strat->syzIdx[j] = 0;
8558  diff--;
8559  j++;
8560  }
8561  strat->syzIdx[j] = ctr;
8562  j++;
8563  LObject Q;
8564  int pos;
8565  for (k = 0; k<i; k++)
8566  {
8567  Q.sig = pOne();
8569  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8570  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8571  p_SetCompP (Q.sig, comp, currRing);
8572  poly q = p_One(currRing);
8575  p_ExpVectorCopy(q,strat->S[i],currRing);
8576  q = p_Neg (q, currRing);
8577  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8578  Q.sig = p_Add_q (Q.sig, q, currRing);
8579  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8580  pos = posInSyz(strat, Q.sig);
8581  enterSyz(Q, strat, pos);
8582  ctr++;
8583  }
8584  }
8585  i++;
8586  }
8587  /**************************************************************
8588  * add syzygies for upcoming first element of new iteration step
8589  **************************************************************/
8590  comp = strat->currIdx;
8591  comp_old = pGetComp(strat->sig[i-1]);
8592  diff = comp - comp_old - 1;
8593  // diff should be zero, but sometimes also the initial generating
8594  // elements of the input ideal reduce to zero. then there is an
8595  // index-gap between the signatures. for these inbetween signatures we
8596  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8597  // in the following.
8598  // doing this, we keep the relation "j = comp - 2" alive, which makes
8599  // jumps way easier when checking criteria
8600  while (diff>0)
8601  {
8602  strat->syzIdx[j] = 0;
8603  diff--;
8604  j++;
8605  }
8606  strat->syzIdx[j] = ctr;
8607  LObject Q;
8608  int pos;
8609  for (k = 0; k<strat->sl+1; k++)
8610  {
8611  Q.sig = pOne();
8613  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8614  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8615  p_SetCompP (Q.sig, comp, currRing);
8616  poly q = p_One(currRing);
8618  p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8619  p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8620  q = p_Neg (q, currRing);
8621  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8622  Q.sig = p_Add_q (Q.sig, q, currRing);
8623  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8624  pos = posInSyz(strat, Q.sig);
8625  enterSyz(Q, strat, pos);
8626  ctr++;
8627  }
8628 //#if 1
8629 #ifdef DEBUGF5
8630  PrintS("Principal syzygies:\n");
8631  Print("syzl %d\n",strat->syzl);
8632  Print("syzmax %d\n",strat->syzmax);
8633  Print("ps %d\n",ps);
8634  PrintS("--------------------------------\n");
8635  for(i=0;i<=strat->syzl-1;i++)
8636  {
8637  Print("%d - ",i);
8638  pWrite(strat->syz[i]);
8639  }
8640  for(i=0;i<strat->currIdx;i++)
8641  {
8642  Print("%d - %d\n",i,strat->syzIdx[i]);
8643  }
8644  PrintS("--------------------------------\n");
8645 #endif
8646  }
8647 }
8648 
8649 /*2
8650 *construct the set s from F and {P}
8651 */
8652 void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8653 {
8654  int i,pos;
8655 
8656  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8657  else i=setmaxT;
8658  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8659  strat->ecartS=initec(i);
8660  strat->sevS=initsevS(i);
8661  strat->S_2_R=initS_2_R(i);
8662  strat->fromQ=NULL;
8663  strat->Shdl=idInit(i,F->rank);
8664  strat->S=strat->Shdl->m;
8665 
8666  /*- put polys into S -*/
8667  if (Q!=NULL)
8668  {
8669  strat->fromQ=initec(i);
8670  memset(strat->fromQ,0,i*sizeof(int));
8671  for (i=0; i<IDELEMS(Q); i++)
8672  {
8673  if (Q->m[i]!=NULL)
8674  {
8675  LObject h;
8676  h.p = pCopy(Q->m[i]);
8677  //if (TEST_OPT_INTSTRATEGY)
8678  //{
8679  // h.pCleardenom(); // also does remove Content
8680  //}
8681  //else
8682  //{
8683  // h.pNorm();
8684  //}
8686  {
8687  deleteHC(&h,strat);
8688  }
8689  if (h.p!=NULL)
8690  {
8691  strat->initEcart(&h);
8692  if (strat->sl==-1)
8693  pos =0;
8694  else
8695  {
8696  pos = posInS(strat,strat->sl,h.p,h.ecart);
8697  }
8698  h.sev = pGetShortExpVector(h.p);
8699  strat->enterS(h,pos,strat, strat->tl+1);
8700  enterT(h, strat);
8701  strat->fromQ[pos]=1;
8702  }
8703  }
8704  }
8705  }
8706  /*- put polys into S -*/
8707  for (i=0; i<IDELEMS(F); i++)
8708  {
8709  if (F->m[i]!=NULL)
8710  {
8711  LObject h;
8712  h.p = pCopy(F->m[i]);
8714  {
8715  deleteHC(&h,strat);
8716  }
8717  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8718  {
8719  h.p=redtailBba(h.p,strat->sl,strat);
8720  }
8721  if (h.p!=NULL)
8722  {
8723  strat->initEcart(&h);
8724  if (strat->sl==-1)
8725  pos =0;
8726  else
8727  pos = posInS(strat,strat->sl,h.p,h.ecart);
8728  h.sev = pGetShortExpVector(h.p);
8729  strat->enterS(h,pos,strat, strat->tl+1);
8730  enterT(h,strat);
8731  }
8732  }
8733  }
8734  for (i=0; i<IDELEMS(P); i++)
8735  {
8736  if (P->m[i]!=NULL)
8737  {
8738  LObject h;
8739  h.p=pCopy(P->m[i]);
8741  {
8742  h.pCleardenom();
8743  }
8744  else
8745  {
8746  h.pNorm();
8747  }
8748  if(strat->sl>=0)
8749  {
8751  {
8752  h.p=redBba(h.p,strat->sl,strat);
8753  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8754  {
8755  h.p=redtailBba(h.p,strat->sl,strat);
8756  }
8757  }
8758  else
8759  {
8760  h.p=redMora(h.p,strat->sl,strat);
8761  }
8762  if(h.p!=NULL)
8763  {
8764  strat->initEcart(&h);
8766  {
8767  h.pCleardenom();
8768  }
8769  else
8770  {
8771  h.is_normalized = 0;
8772  h.pNorm();
8773  }
8774  h.sev = pGetShortExpVector(h.p);
8775  h.SetpFDeg();
8776  pos = posInS(strat,strat->sl,h.p,h.ecart);
8777  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8778  strat->enterS(h,pos,strat, strat->tl+1);
8779  enterT(h,strat);
8780  }
8781  }
8782  else
8783  {
8784  h.sev = pGetShortExpVector(h.p);
8785  strat->initEcart(&h);
8786  strat->enterS(h,0,strat, strat->tl+1);
8787  enterT(h,strat);
8788  }
8789  }
8790  }
8791 }
8792 /*2
8793 *construct the set s from F and {P}
8794 */
8795 
8796 void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8797 {
8798  int i,pos;
8799 
8800  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8801  else i=setmaxT;
8802  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8803  strat->sevS=initsevS(i);
8804  strat->sevSig=initsevS(i);
8805  strat->S_2_R=initS_2_R(i);
8806  strat->fromQ=NULL;
8807  strat->Shdl=idInit(i,F->rank);
8808  strat->S=strat->Shdl->m;
8809  strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8810  /*- put polys into S -*/
8811  if (Q!=NULL)
8812  {
8813  strat->fromQ=initec(i);
8814  memset(strat->fromQ,0,i*sizeof(int));
8815  for (i=0; i<IDELEMS(Q); i++)
8816  {
8817  if (Q->m[i]!=NULL)
8818  {
8819  LObject h;
8820  h.p = pCopy(Q->m[i]);
8821  //if (TEST_OPT_INTSTRATEGY)
8822  //{
8823  // h.pCleardenom(); // also does remove Content
8824  //}
8825  //else
8826  //{
8827  // h.pNorm();
8828  //}
8830  {
8831  deleteHC(&h,strat);
8832  }
8833  if (h.p!=NULL)
8834  {
8835  strat->initEcart(&h);
8836  if (strat->sl==-1)
8837  pos =0;
8838  else
8839  {
8840  pos = posInS(strat,strat->sl,h.p,h.ecart);
8841  }
8842  h.sev = pGetShortExpVector(h.p);
8843  strat->enterS(h,pos,strat, strat->tl+1);
8844  enterT(h, strat);
8845  strat->fromQ[pos]=1;
8846  }
8847  }
8848  }
8849  }
8850  /*- put polys into S -*/
8851  for (i=0; i<IDELEMS(F); i++)
8852  {
8853  if (F->m[i]!=NULL)
8854  {
8855  LObject h;
8856  h.p = pCopy(F->m[i]);
8858  {
8859  deleteHC(&h,strat);
8860  }
8861  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8862  {
8863  h.p=redtailBba(h.p,strat->sl,strat);
8864  }
8865  if (h.p!=NULL)
8866  {
8867  strat->initEcart(&h);
8868  if (strat->sl==-1)
8869  pos =0;
8870  else
8871  pos = posInS(strat,strat->sl,h.p,h.ecart);
8872  h.sev = pGetShortExpVector(h.p);
8873  strat->enterS(h,pos,strat, strat->tl+1);
8874  enterT(h,strat);
8875  }
8876  }
8877  }
8878  for (i=0; i<IDELEMS(P); i++)
8879  {
8880  if (P->m[i]!=NULL)
8881  {
8882  LObject h;
8883  h.p=pCopy(P->m[i]);
8885  {
8886  h.pCleardenom();
8887  }
8888  else
8889  {
8890  h.pNorm();
8891  }
8892  if(strat->sl>=0)
8893  {
8895  {
8896  h.p=redBba(h.p,strat->sl,strat);
8897  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8898  {
8899  h.p=redtailBba(h.p,strat->sl,strat);
8900  }
8901  }
8902  else
8903  {
8904  h.p=redMora(h.p,strat->sl,strat);
8905  }
8906  if(h.p!=NULL)
8907  {
8908  strat->initEcart(&h);
8910  {
8911  h.pCleardenom();
8912  }
8913  else
8914  {
8915  h.is_normalized = 0;
8916  h.pNorm();
8917  }
8918  h.sev = pGetShortExpVector(h.p);
8919  h.SetpFDeg();
8920  pos = posInS(strat,strat->sl,h.p,h.ecart);
8921  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8922  strat->enterS(h,pos,strat, strat->tl+1);
8923  enterT(h,strat);
8924  }
8925  }
8926  else
8927  {
8928  h.sev = pGetShortExpVector(h.p);
8929  strat->initEcart(&h);
8930  strat->enterS(h,0,strat, strat->tl+1);
8931  enterT(h,strat);
8932  }
8933  }
8934  }
8935 }
8936 
8937 /*2
8938 * reduces h using the set S
8939 * procedure used in cancelunit1
8940 */
8941 static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8942 {
8943  int j = 0;
8944  unsigned long not_sev = ~ pGetShortExpVector(h);
8945 
8946  while (j <= maxIndex)
8947  {
8948  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8949  return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8950  else j++;
8951  }
8952  return h;
8953 }
8954 
8955 /*2
8956 *tests if p.p=monomial*unit and cancels the unit
8957 */
8958 void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8959 {
8960  int k;
8961  poly r,h,h1,q;
8962 
8963  if (!pIsVector((*p).p) && ((*p).ecart != 0))
8964  {
8965 #ifdef HAVE_RINGS
8966  // Leading coef have to be a unit: no
8967  // example 2x+4x2 should be simplified to 2x*(1+2x)
8968  // and 2 is not a unit in Z
8969  //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8970 #endif
8971  k = 0;
8972  h1 = r = pCopy((*p).p);
8973  h =pNext(r);
8974  loop
8975  {
8976  if (h==NULL)
8977  {
8978  pDelete(&r);
8979  pDelete(&(pNext((*p).p)));
8980  (*p).ecart = 0;
8981  (*p).length = 1;
8982  (*p).pLength = 1;
8983  (*suc)=0;
8984  return;
8985  }
8986  if (!pDivisibleBy(r,h))
8987  {
8988  q=redBba1(h,index ,strat);
8989  if (q != h)
8990  {
8991  k++;
8992  pDelete(&h);
8993  pNext(h1) = h = q;
8994  }
8995  else
8996  {
8997  pDelete(&r);
8998  return;
8999  }
9000  }
9001  else
9002  {
9003  h1 = h;
9004  pIter(h);
9005  }
9006  if (k > 10)
9007  {
9008  pDelete(&r);
9009  return;
9010  }
9011  }
9012  }
9013 }
9014 
9015 #if 0
9016 /*2
9017 * reduces h using the elements from Q in the set S
9018 * procedure used in updateS
9019 * must not be used for elements of Q or elements of an ideal !
9020 */
9021 static poly redQ (poly h, int j, kStrategy strat)
9022 {
9023  int start;
9024  unsigned long not_sev = ~ pGetShortExpVector(h);
9025  while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
9026  start=j;
9027  while (j<=strat->sl)
9028  {
9029  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
9030  {
9031  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
9032  if (h==NULL) return NULL;
9033  j = start;
9034  not_sev = ~ pGetShortExpVector(h);
9035  }
9036  else j++;
9037  }
9038  return h;
9039 }
9040 #endif
9041 
9042 /*2
9043 * reduces h using the set S
9044 * procedure used in updateS
9045 */
9046 static poly redBba (poly h,int maxIndex,kStrategy strat)
9047 {
9048  int j = 0;
9049  unsigned long not_sev = ~ pGetShortExpVector(h);
9050 
9051  while (j <= maxIndex)
9052  {
9053  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
9054  {
9055  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
9056  if (h==NULL) return NULL;
9057  j = 0;
9058  not_sev = ~ pGetShortExpVector(h);
9059  }
9060  else j++;
9061  }
9062  return h;
9063 }
9064 
9065 /*2
9066 * reduces h using the set S
9067 *e is the ecart of h
9068 *procedure used in updateS
9069 */
9070 static poly redMora (poly h,int maxIndex,kStrategy strat)
9071 {
9072  int j=0;
9073  int e,l;
9074  unsigned long not_sev = ~ pGetShortExpVector(h);
9075 
9076  if (maxIndex >= 0)
9077  {
9078  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
9079  do
9080  {
9081  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
9082  && ((e >= strat->ecartS[j]) || strat->kHEdgeFound))
9083  {
9084 #ifdef KDEBUG
9085  if (TEST_OPT_DEBUG)
9086  {
9087  PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
9088  }
9089 #endif
9090  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
9091 #ifdef KDEBUG
9092  if(TEST_OPT_DEBUG)
9093  {
9094  PrintS(")\nto "); wrp(h); PrintLn();
9095  }
9096 #endif
9097  // pDelete(&h);
9098  if (h == NULL) return NULL;
9099  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
9100  j = 0;
9101  not_sev = ~ pGetShortExpVector(h);
9102  }
9103  else j++;
9104  }
9105  while (j <= maxIndex);
9106  }
9107  return h;
9108 }
9109 
9110 /*2
9111 *updates S:
9112 *the result is a set of polynomials which are in
9113 *normalform with respect to S
9114 */
9115 void updateS(BOOLEAN toT,kStrategy strat)
9116 {
9117  LObject h;
9118  int i, suc=0;
9119  poly redSi=NULL;
9120  BOOLEAN change,any_change;
9121 // Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
9122 // for (i=0; i<=(strat->sl); i++)
9123 // {
9124 // Print("s%d:",i);
9125 // if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
9126 // pWrite(strat->S[i]);
9127 // }
9128 // Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
9129  any_change=FALSE;
9131  {
9132  while (suc != -1)
9133  {
9134  i=suc+1;
9135  while (i<=strat->sl)
9136  {
9137  change=FALSE;
9139  any_change = FALSE;
9140  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
9141  {
9142  redSi = pHead(strat->S[i]);
9143  strat->S[i] = redBba(strat->S[i],i-1,strat);
9144  //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
9145  // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
9146  if (pCmp(redSi,strat->S[i])!=0)
9147  {
9148  change=TRUE;
9149  any_change=TRUE;
9150  #ifdef KDEBUG
9151  if (TEST_OPT_DEBUG)
9152  {
9153  PrintS("reduce:");
9154  wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
9155  }
9156  #endif
9157  if (TEST_OPT_PROT)
9158  {
9159  if (strat->S[i]==NULL)
9160  PrintS("V");
9161  else
9162  PrintS("v");
9163  mflush();
9164  }
9165  }
9166  pLmDelete(&redSi);
9167  if (strat->S[i]==NULL)
9168  {
9169  deleteInS(i,strat);
9170  i--;
9171  }
9172  else if (change)
9173  {
9175  {
9176  if (TEST_OPT_CONTENTSB)
9177  {
9178  number n;
9179  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
9180  if (!nIsOne(n))
9181  {
9183  denom->n=nInvers(n);
9184  denom->next=DENOMINATOR_LIST;
9185  DENOMINATOR_LIST=denom;
9186  }
9187  nDelete(&n);
9188  }
9189  else
9190  {
9191  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
9192  }
9193  }
9194  else
9195  {
9196  pNorm(strat->S[i]);
9197  }
9198  strat->sevS[i] = pGetShortExpVector(strat->S[i]);
9199  }
9200  }
9201  i++;
9202  }
9203  if (any_change) reorderS(&suc,strat);
9204  else break;
9205  }
9206  if (toT)
9207  {
9208  for (i=0; i<=strat->sl; i++)
9209  {
9210  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9211  {
9212  h.p = redtailBba(strat->S[i],i-1,strat);
9214  {
9215  h.pCleardenom();// also does remove Content
9216  }
9217  }
9218  else
9219  {
9220  h.p = strat->S[i];
9221  }
9222  strat->initEcart(&h);
9223  if (strat->honey)
9224  {
9225  strat->ecartS[i] = h.ecart;
9226  }
9227  if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
9228  else assume(strat->sevS[i] == pGetShortExpVector(h.p));
9229  h.sev = strat->sevS[i];
9230  /*puts the elements of S also to T*/
9231  strat->initEcart(&h);
9232  /*if (toT) - already checked*/ enterT(h,strat);
9233  strat->S_2_R[i] = strat->tl;
9234 #ifdef HAVE_SHIFTBBA
9235  if (/*(toT) && */(currRing->isLPring))
9236  enterTShift(h, strat);
9237 #endif
9238  }
9239  }
9240  }
9241  else
9242  {
9243  while (suc != -1)
9244  {
9245  i=suc;
9246  while (i<=strat->sl)
9247  {
9248  change=FALSE;
9249  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
9250  {
9251  redSi=pHead((strat->S)[i]);
9252  (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
9253  if ((strat->S)[i]==NULL)
9254  {
9255  deleteInS(i,strat);
9256  i--;
9257  }
9258  else if (pCmp((strat->S)[i],redSi)!=0)
9259  {
9260  any_change=TRUE;
9261  h.p = strat->S[i];
9262  strat->initEcart(&h);
9263  strat->ecartS[i] = h.ecart;
9265  {
9266  if (TEST_OPT_CONTENTSB)
9267  {
9268  number n;
9269  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
9270  if (!nIsOne(n))
9271  {
9273  denom->n=nInvers(n);
9274  denom->next=DENOMINATOR_LIST;
9275  DENOMINATOR_LIST=denom;
9276  }
9277  nDelete(&n);
9278  }
9279  else
9280  {
9281  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
9282  }
9283  }
9284  else
9285  {
9286  pNorm(strat->S[i]); // == h.p
9287  }
9288  h.sev = pGetShortExpVector(h.p);
9289  strat->sevS[i] = h.sev;
9290  }
9291  pLmDelete(&redSi);
9292  kTest(strat);
9293  }
9294  i++;
9295  }
9296 #ifdef KDEBUG
9297  kTest(strat);
9298 #endif
9299  if (any_change) reorderS(&suc,strat);
9300  else { suc=-1; break; }
9301  if (h.p!=NULL)
9302  {
9303  if (!strat->kHEdgeFound)
9304  {
9305  /*strat->kHEdgeFound =*/ HEckeTest(h.p,strat);
9306  }
9307  if (strat->kHEdgeFound)
9308  newHEdge(strat);
9309  }
9310  }
9311  for (i=0; i<=strat->sl; i++)
9312  {
9313  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9314  {
9315  strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
9316  strat->initEcart(&h);
9317  strat->ecartS[i] = h.ecart;
9318  h.sev = pGetShortExpVector(h.p);
9319  strat->sevS[i] = h.sev;
9320  }
9321  else
9322  {
9323  h.p = strat->S[i];
9324  h.ecart=strat->ecartS[i];
9325  h.sev = strat->sevS[i];
9326  h.length = h.pLength = pLength(h.p);
9327  }
9328  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9329  cancelunit1(&h,&suc,strat->sl,strat);
9330  h.SetpFDeg();
9331  /*puts the elements of S also to T*/
9332  enterT(h,strat);
9333  strat->S_2_R[i] = strat->tl;
9334 #ifdef HAVE_SHIFTBBA
9335  if (currRing->isLPring)
9336  enterTShift(h, strat);
9337 #endif
9338  }
9339  if (suc!= -1) updateS(toT,strat);
9340  }
9341 #ifdef KDEBUG
9342  kTest(strat);
9343 #endif
9344 }
9345 
9346 /*2
9347 * -puts p to the standardbasis s at position at
9348 * -saves the result in S
9349 */
9350 void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
9351 {
9352  strat->news = TRUE;
9353  /*- puts p to the standardbasis s at position at -*/
9354  if (strat->sl == IDELEMS(strat->Shdl)-1)
9355  {
9356  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9357  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9358  (IDELEMS(strat->Shdl)+setmaxTinc)
9359  *sizeof(unsigned long));
9360  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9361  IDELEMS(strat->Shdl)*sizeof(int),
9362  (IDELEMS(strat->Shdl)+setmaxTinc)
9363  *sizeof(int));
9364  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9365  IDELEMS(strat->Shdl)*sizeof(int),
9366  (IDELEMS(strat->Shdl)+setmaxTinc)
9367  *sizeof(int));
9368  if (strat->lenS!=NULL)
9369  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9370  IDELEMS(strat->Shdl)*sizeof(int),
9371  (IDELEMS(strat->Shdl)+setmaxTinc)
9372  *sizeof(int));
9373  if (strat->lenSw!=NULL)
9374  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9375  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9376  (IDELEMS(strat->Shdl)+setmaxTinc)
9377  *sizeof(wlen_type));
9378  if (strat->fromQ!=NULL)
9379  {
9380  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9381  IDELEMS(strat->Shdl)*sizeof(int),
9382  (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9383  }
9384  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
9385  IDELEMS(strat->Shdl)+=setmaxTinc;
9386  strat->Shdl->m=strat->S;
9387  }
9388  if (atS <= strat->sl)
9389  {
9390 #ifdef ENTER_USE_MEMMOVE
9391  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9392  (strat->sl - atS + 1)*sizeof(poly));
9393  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9394  (strat->sl - atS + 1)*sizeof(int));
9395  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9396  (strat->sl - atS + 1)*sizeof(unsigned long));
9397  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9398  (strat->sl - atS + 1)*sizeof(int));
9399  if (strat->lenS!=NULL)
9400  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9401  (strat->sl - atS + 1)*sizeof(int));
9402  if (strat->lenSw!=NULL)
9403  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9404  (strat->sl - atS + 1)*sizeof(wlen_type));
9405 #else
9406  for (i=strat->sl+1; i>=atS+1; i--)
9407  {
9408  strat->S[i] = strat->S[i-1];
9409  strat->ecartS[i] = strat->ecartS[i-1];
9410  strat->sevS[i] = strat->sevS[i-1];
9411  strat->S_2_R[i] = strat->S_2_R[i-1];
9412  }
9413  if (strat->lenS!=NULL)
9414  for (i=strat->sl+1; i>=atS+1; i--)
9415  strat->lenS[i] = strat->lenS[i-1];
9416  if (strat->lenSw!=NULL)
9417  for (i=strat->sl+1; i>=atS+1; i--)
9418  strat->lenSw[i] = strat->lenSw[i-1];
9419 #endif
9420  }
9421  if (strat->fromQ!=NULL)
9422  {
9423 #ifdef ENTER_USE_MEMMOVE
9424  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9425  (strat->sl - atS + 1)*sizeof(int));
9426 #else
9427  for (i=strat->sl+1; i>=atS+1; i--)
9428  {
9429  strat->fromQ[i] = strat->fromQ[i-1];
9430  }
9431 #endif
9432  strat->fromQ[atS]=0;
9433  }
9434 
9435  /*- save result -*/
9436  poly pp=p.p;
9437  strat->S[atS] = pp;
9438  if (strat->honey) strat->ecartS[atS] = p.ecart;
9439  if (p.sev == 0)
9440  p.sev = pGetShortExpVector(pp);
9441  else
9442  assume(p.sev == pGetShortExpVector(pp));
9443  strat->sevS[atS] = p.sev;
9444  strat->ecartS[atS] = p.ecart;
9445  strat->S_2_R[atS] = atR;
9446  strat->sl++;
9447 }
9448 
9449 #ifdef HAVE_SHIFTBBA
9450 void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR)
9451 {
9452  enterSBba(p, atS, strat, atR);
9453 
9454  int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
9455  for (int i = maxPossibleShift; i > 0; i--)
9456  {
9457  // NOTE: don't use "shared tails" here. In rare cases it can cause problems
9458  // in `kNF2` because of lazy poly normalizations.
9459  LObject qq(p_Copy(p.p, strat->tailRing));
9460  p_mLPshift(qq.p, i, strat->tailRing);
9461  qq.shift = i;
9462  strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
9463  int atS = posInS(strat, strat->sl, qq.p, qq.ecart); // S needs to stay sorted because this is for example assumed when searching S later
9464  enterSBba(qq, atS, strat, -1);
9465  }
9466 }
9467 #endif
9468 
9469 /*2
9470 * -puts p to the standardbasis s at position at
9471 * -saves the result in S
9472 */
9473 void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
9474 {
9475  strat->news = TRUE;
9476  /*- puts p to the standardbasis s at position at -*/
9477  if (strat->sl == IDELEMS(strat->Shdl)-1)
9478  {
9479  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9480  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9481  (IDELEMS(strat->Shdl)+setmax)
9482  *sizeof(unsigned long));
9483  strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
9484  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9485  (IDELEMS(strat->Shdl)+setmax)
9486  *sizeof(unsigned long));
9487  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9488  IDELEMS(strat->Shdl)*sizeof(int),
9489  (IDELEMS(strat->Shdl)+setmax)
9490  *sizeof(int));
9491  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9492  IDELEMS(strat->Shdl)*sizeof(int),
9493  (IDELEMS(strat->Shdl)+setmax)
9494  *sizeof(int));
9495  if (strat->lenS!=NULL)
9496  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9497  IDELEMS(strat->Shdl)*sizeof(int),
9498  (IDELEMS(strat->Shdl)+setmax)
9499  *sizeof(int));
9500  if (strat->lenSw!=NULL)
9501  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9502  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9503  (IDELEMS(strat->Shdl)+setmax)
9504  *sizeof(wlen_type));
9505  if (strat->fromQ!=NULL)
9506  {
9507  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9508  IDELEMS(strat->Shdl)*sizeof(int),
9509  (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
9510  }
9511  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
9512  pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
9513  IDELEMS(strat->Shdl)+=setmax;
9514  strat->Shdl->m=strat->S;
9515  }
9516  // in a signature-based algorithm the following situation will never
9517  // appear due to the fact that the critical pairs are already sorted
9518  // by increasing signature.
9519  // True. However, in the case of integers we need to put the element
9520  // that caused the signature drop on the first position
9521  if (atS <= strat->sl)
9522  {
9523 #ifdef ENTER_USE_MEMMOVE
9524  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9525  (strat->sl - atS + 1)*sizeof(poly));
9526  memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9527  (strat->sl - atS + 1)*sizeof(poly));
9528  memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9529  (strat->sl - atS + 1)*sizeof(unsigned long));
9530  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9531  (strat->sl - atS + 1)*sizeof(int));
9532  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9533  (strat->sl - atS + 1)*sizeof(unsigned long));
9534  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9535  (strat->sl - atS + 1)*sizeof(int));
9536  if (strat->lenS!=NULL)
9537  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9538  (strat->sl - atS + 1)*sizeof(int));
9539  if (strat->lenSw!=NULL)
9540  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9541  (strat->sl - atS + 1)*sizeof(wlen_type));
9542 #else
9543  for (i=strat->sl+1; i>=atS+1; i--)
9544  {
9545  strat->S[i] = strat->S[i-1];
9546  strat->ecartS[i] = strat->ecartS[i-1];
9547  strat->sevS[i] = strat->sevS[i-1];
9548  strat->S_2_R[i] = strat->S_2_R[i-1];
9549  strat->sig[i] = strat->sig[i-1];
9550  strat->sevSig[i] = strat->sevSig[i-1];
9551  }
9552  if (strat->lenS!=NULL)
9553  for (i=strat->sl+1; i>=atS+1; i--)
9554  strat->lenS[i] = strat->lenS[i-1];
9555  if (strat->lenSw!=NULL)
9556  for (i=strat->sl+1; i>=atS+1; i--)
9557  strat->lenSw[i] = strat->lenSw[i-1];
9558 #endif
9559  }
9560  if (strat->fromQ!=NULL)
9561  {
9562 #ifdef ENTER_USE_MEMMOVE
9563  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9564  (strat->sl - atS + 1)*sizeof(int));
9565 #else
9566  for (i=strat->sl+1; i>=atS+1; i--)
9567  {
9568  strat->fromQ[i] = strat->fromQ[i-1];
9569  }
9570 #endif
9571  strat->fromQ[atS]=0;
9572  }
9573 
9574  /*- save result -*/
9575  strat->S[atS] = p.p;
9576  strat->sig[atS] = p.sig; // TODO: get ths correct signature in here!
9577  if (strat->honey) strat->ecartS[atS] = p.ecart;
9578  if (p.sev == 0)
9579  p.sev = pGetShortExpVector(p.p);
9580  else
9581  assume(p.sev == pGetShortExpVector(p.p));
9582  strat->sevS[atS] = p.sev;
9583  // during the interreduction process of a signature-based algorithm we do not
9584  // compute the signature at this point, but when the whole interreduction
9585  // process finishes, i.e. f5c terminates!
9586  if (p.sig != NULL)
9587  {
9588  if (p.sevSig == 0)
9589  p.sevSig = pGetShortExpVector(p.sig);
9590  else
9591  assume(p.sevSig == pGetShortExpVector(p.sig));
9592  strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9593  }
9594  strat->ecartS[atS] = p.ecart;
9595  strat->S_2_R[atS] = atR;
9596  strat->sl++;
9597 #ifdef DEBUGF5
9598  int k;
9599  Print("--- LIST S: %d ---\n",strat->sl);
9600  for(k=0;k<=strat->sl;k++)
9601  {
9602  pWrite(strat->sig[k]);
9603  }
9604  PrintS("--- LIST S END ---\n");
9605 #endif
9606 }
9607 
9608 void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
9609 {
9610  p.GetP(strat->lmBin);
9611  if (strat->homog) strat->initEcart(&p);
9612  strat->redTailChange=FALSE;
9614  {
9615  p.pCleardenom();
9617  {
9618 #ifdef HAVE_SHIFTBBA
9619  if (rIsLPRing(currRing))
9620  p.p = redtailBba(&p,strat->tl,strat, TRUE,!TEST_OPT_CONTENTSB);
9621  else
9622 #endif
9623  {
9624  p.p = redtailBba(&p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9625  }
9626  p.pCleardenom();
9627  if (strat->redTailChange)
9628  p.t_p=NULL;
9629  if (strat->P.p!=NULL) strat->P.sev=p_GetShortExpVector(strat->P.p,currRing);
9630  else strat->P.sev=0;
9631  }
9632  }
9633 
9634  assume(strat->tailRing == p.tailRing);
9635  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9636 
9637  int i, j, pos;
9638  poly tp = strat->T[tj].p;
9639 
9640  /* enter p to T set */
9641  enterT(p, strat);
9642 
9643  for (j = 0; j <= strat->sl; ++j)
9644  {
9645  if (pLtCmp(tp, strat->S[j]) == 0)
9646  {
9647  break;
9648  }
9649  }
9650  /* it may be that the exchanged element
9651  * is until now only in T and not in S */
9652  if (j <= strat->sl)
9653  {
9654  deleteInS(j, strat);
9655  }
9656 
9657  pos = posInS(strat, strat->sl, p.p, p.ecart);
9658 
9659  pp_Test(p.p, currRing, p.tailRing);
9660  assume(p.FDeg == p.pFDeg());
9661 
9662  /* remove useless pairs from L set */
9663  for (i = 0; i <= strat->Ll; ++i)
9664  {
9665  if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0)
9666  {
9667  deleteInL(strat->L, &(strat->Ll), i, strat);
9668  i--;
9669  continue;
9670  }
9671  if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0)
9672  {
9673  deleteInL(strat->L, &(strat->Ll), i, strat);
9674  i--;
9675  }
9676  }
9677 #ifdef HAVE_SHIFTBBA
9678  if (rIsLPRing(currRing))
9679  enterpairsShift(p.p, strat->sl, p.ecart, pos, strat, strat->tl); // TODO LP
9680  else
9681 #endif
9682  {
9683  /* generate new pairs with p, probably removing older, now useless pairs */
9684  superenterpairs(p.p, strat->sl, p.ecart, pos, strat, strat->tl);
9685  }
9686  /* enter p to S set */
9687  strat->enterS(p, pos, strat, strat->tl);
9688 
9689 #ifdef HAVE_SHIFTBBA
9690  /* do this after enterS so that the index in R (which is strat->tl) is correct */
9691  if (rIsLPRing(currRing) && !strat->rightGB)
9692  enterTShift(p,strat);
9693 #endif
9694 }
9695 
9696 /*2
9697 * puts p to the set T at position atT
9698 */
9699 void enterT(LObject &p, kStrategy strat, int atT)
9700 {
9701  int i;
9702 
9703 #ifdef PDEBUG
9704 #ifdef HAVE_SHIFTBBA
9705  if (currRing->isLPring && p.shift > 0)
9706  {
9707  // in this case, the order is not correct. test LM and tail separately
9708  p_LmTest(p.p, currRing);
9709  p_Test(pNext(p.p), currRing);
9710  }
9711  else
9712 #endif
9713  {
9714  pp_Test(p.p, currRing, p.tailRing);
9715  }
9716 #endif
9717  assume(strat->tailRing == p.tailRing);
9718  // redMoraNF complains about this -- but, we don't really
9719  // neeed this so far
9720  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9721  assume(p.FDeg == p.pFDeg());
9722  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9723 
9724 #ifdef KDEBUG
9725  // do not put an LObject twice into T:
9726  for(i=strat->tl;i>=0;i--)
9727  {
9728  if (p.p==strat->T[i].p)
9729  {
9730  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9731  return;
9732  }
9733  }
9734 #endif
9735 
9736 #ifdef HAVE_TAIL_RING
9737  if (currRing!=strat->tailRing)
9738  {
9739  p.t_p=p.GetLmTailRing();
9740  }
9741 #endif
9742  strat->newt = TRUE;
9743  if (atT < 0)
9744  atT = strat->posInT(strat->T, strat->tl, p);
9745  if (strat->tl == strat->tmax-1)
9746  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9747  if (atT <= strat->tl)
9748  {
9749 #ifdef ENTER_USE_MEMMOVE
9750  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9751  (strat->tl-atT+1)*sizeof(TObject));
9752  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9753  (strat->tl-atT+1)*sizeof(unsigned long));
9754 #endif
9755  for (i=strat->tl+1; i>=atT+1; i--)
9756  {
9757 #ifndef ENTER_USE_MEMMOVE
9758  strat->T[i] = strat->T[i-1];
9759  strat->sevT[i] = strat->sevT[i-1];
9760 #endif
9761  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9762  }
9763  }
9764 
9765  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9766  {
9767 #ifdef HAVE_SHIFTBBA
9768  // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9769  if (!(currRing->isLPring && p.shift > 0))
9770 #endif
9771  {
9773  (strat->tailRing != NULL ?
9774  strat->tailRing : currRing),
9775  strat->tailBin);
9776  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9777  }
9778  }
9779  strat->T[atT] = (TObject) p;
9780  //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9781 
9782  if (pNext(p.p) != NULL)
9783  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9784  else
9785  strat->T[atT].max_exp = NULL;
9786 
9787  strat->tl++;
9788  strat->R[strat->tl] = &(strat->T[atT]);
9789  strat->T[atT].i_r = strat->tl;
9790  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9791  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9792  kTest_T(&(strat->T[atT]));
9793 }
9794 
9795 /*2
9796 * puts p to the set T at position atT
9797 */
9798 #ifdef HAVE_RINGS
9799 void enterT_strong(LObject &p, kStrategy strat, int atT)
9800 {
9802  int i;
9803 
9804  pp_Test(p.p, currRing, p.tailRing);
9805  assume(strat->tailRing == p.tailRing);
9806  // redMoraNF complains about this -- but, we don't really
9807  // neeed this so far
9808  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9809  assume(p.FDeg == p.pFDeg());
9810  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9811 
9812 #ifdef KDEBUG
9813  // do not put an LObject twice into T:
9814  for(i=strat->tl;i>=0;i--)
9815  {
9816  if (p.p==strat->T[i].p)
9817  {
9818  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9819  return;
9820  }
9821  }
9822 #endif
9823 
9824 #ifdef HAVE_TAIL_RING
9825  if (currRing!=strat->tailRing)
9826  {
9827  p.t_p=p.GetLmTailRing();
9828  }
9829 #endif
9830  strat->newt = TRUE;
9831  if (atT < 0)
9832  atT = strat->posInT(strat->T, strat->tl, p);
9833  if (strat->tl == strat->tmax-1)
9834  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9835  if (atT <= strat->tl)
9836  {
9837 #ifdef ENTER_USE_MEMMOVE
9838  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9839  (strat->tl-atT+1)*sizeof(TObject));
9840  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9841  (strat->tl-atT+1)*sizeof(unsigned long));
9842 #endif
9843  for (i=strat->tl+1; i>=atT+1; i--)
9844  {
9845 #ifndef ENTER_USE_MEMMOVE
9846  strat->T[i] = strat->T[i-1];
9847  strat->sevT[i] = strat->sevT[i-1];
9848 #endif
9849  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9850  }
9851  }
9852 
9853  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9854  {
9856  (strat->tailRing != NULL ?
9857  strat->tailRing : currRing),
9858  strat->tailBin);
9859  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9860  }
9861  strat->T[atT] = (TObject) p;
9862  //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9863 
9864  if (pNext(p.p) != NULL)
9865  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9866  else
9867  strat->T[atT].max_exp = NULL;
9868 
9869  strat->tl++;
9870  strat->R[strat->tl] = &(strat->T[atT]);
9871  strat->T[atT].i_r = strat->tl;
9872  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9873  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9874  #if 1
9876  && !n_IsUnit(p.p->coef, currRing->cf))
9877  {
9878  for(i=strat->tl;i>=0;i--)
9879  {
9880  if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9881  {
9882  enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9883  }
9884  }
9885  }
9886  /*
9887  printf("\nThis is T:\n");
9888  for(i=strat->tl;i>=0;i--)
9889  {
9890  pWrite(strat->T[i].p);
9891  }
9892  //getchar();*/
9893  #endif
9894  kTest_T(&(strat->T[atT]));
9895 }
9896 #endif
9897 
9898 /*2
9899 * puts signature p.sig to the set syz
9900 */
9901 void enterSyz(LObject &p, kStrategy strat, int atT)
9902 {
9903  int i;
9904  strat->newt = TRUE;
9905  if (strat->syzl == strat->syzmax-1)
9906  {
9907  pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9908  strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9909  (strat->syzmax)*sizeof(unsigned long),
9910  ((strat->syzmax)+setmax)
9911  *sizeof(unsigned long));
9912  strat->syzmax += setmax;
9913  }
9914  if (atT < strat->syzl)
9915  {
9916 #ifdef ENTER_USE_MEMMOVE
9917  memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9918  (strat->syzl-atT+1)*sizeof(poly));
9919  memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9920  (strat->syzl-atT+1)*sizeof(unsigned long));
9921 #endif
9922  for (i=strat->syzl; i>=atT+1; i--)
9923  {
9924 #ifndef ENTER_USE_MEMMOVE
9925  strat->syz[i] = strat->syz[i-1];
9926  strat->sevSyz[i] = strat->sevSyz[i-1];
9927 #endif
9928  }
9929  }
9930  //i = strat->syzl;
9931  i = atT;
9932  //Makes sure the syz saves just the signature
9933  #ifdef HAVE_RINGS
9935  pNext(p.sig) = NULL;
9936  #endif
9937  strat->syz[atT] = p.sig;
9938  strat->sevSyz[atT] = p.sevSig;
9939  strat->syzl++;
9940 #if F5DEBUG
9941  Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9942  pWrite(strat->syz[atT]);
9943 #endif
9944  // recheck pairs in strat->L with new rule and delete correspondingly
9945  int cc = strat->Ll;
9946  while (cc>-1)
9947  {
9948  //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9949  //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);
9950  if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9951  strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9952  #ifdef HAVE_RINGS
9953  &&((!rField_is_Ring(currRing))
9954  || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9955  #endif
9956  )
9957  {
9958  //printf("\nYES!\n");
9959  deleteInL(strat->L,&strat->Ll,cc,strat);
9960  }
9961  cc--;
9962  }
9963 //#if 1
9964 #ifdef DEBUGF5
9965  PrintS("--- Syzygies ---\n");
9966  Print("syzl %d\n",strat->syzl);
9967  Print("syzmax %d\n",strat->syzmax);
9968  PrintS("--------------------------------\n");
9969  for(i=0;i<=strat->syzl-1;i++)
9970  {
9971  Print("%d - ",i);
9972  pWrite(strat->syz[i]);
9973  }
9974  PrintS("--------------------------------\n");
9975 #endif
9976 }
9977 
9978 
9979 void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9980 {
9981 
9982  //if the ordering is local, then hilb criterion
9983  //can be used also if the ideal is not homogenous
9985  {
9987  *hilb=NULL;
9988  else
9989  return;
9990  }
9991  if (strat->homog!=isHomog)
9992  {
9993  *hilb=NULL;
9994  }
9995 }
9996 
9998 {
10000  strat->chainCrit=chainCritNormal;
10001  if (TEST_OPT_SB_1)
10002  strat->chainCrit=chainCritOpt_1;
10003 #ifdef HAVE_RINGS
10004  if (rField_is_Ring(currRing))
10005  {
10007  strat->chainCrit=chainCritRing;
10008  }
10009 #endif
10010 #ifdef HAVE_RATGRING
10011  if (rIsRatGRing(currRing))
10012  {
10013  strat->chainCrit=chainCritPart;
10014  /* enterOnePairNormal get rational part in it */
10015  }
10016 #endif
10017  if (TEST_OPT_IDLIFT
10018  && (strat->syzComp==1)
10019  && (!rIsPluralRing(currRing)))
10021 
10022  strat->sugarCrit = TEST_OPT_SUGARCRIT;
10023  strat->Gebauer = strat->homog || strat->sugarCrit;
10024  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
10025  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
10026  strat->pairtest = NULL;
10027  /* alway use tailreduction, except:
10028  * - in local rings, - in lex order case, -in ring over extensions */
10030  //if(rHasMixedOrdering(currRing)==2)
10031  //{
10032  // strat->noTailReduction =TRUE;
10033  //}
10034 
10035 #ifdef HAVE_PLURAL
10036  // and r is plural_ring
10037  // hence this holds for r a rational_plural_ring
10038  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
10039  { //or it has non-quasi-comm type... later
10040  strat->sugarCrit = FALSE;
10041  strat->Gebauer = FALSE;
10042  strat->honey = FALSE;
10043  }
10044 #endif
10045 
10046  // Coefficient ring?
10047  if (rField_is_Ring(currRing))
10048  {
10049  strat->sugarCrit = FALSE;
10050  strat->Gebauer = FALSE ;
10051  strat->honey = FALSE;
10052  }
10053  #ifdef KDEBUG
10054  if (TEST_OPT_DEBUG)
10055  {
10056  if (strat->homog) PrintS("ideal/module is homogeneous\n");
10057  else PrintS("ideal/module is not homogeneous\n");
10058  }
10059  #endif
10060 }
10061 
10063 {
10064  //strat->enterOnePair=enterOnePairNormal;
10066  //strat->chainCrit=chainCritNormal;
10067  strat->chainCrit = chainCritSig;
10068  /******************************************
10069  * rewCrit1 and rewCrit2 are already set in
10070  * kSba() in kstd1.cc
10071  *****************************************/
10072  //strat->rewCrit1 = faugereRewCriterion;
10073  if (strat->sbaOrder == 1)
10074  {
10075  strat->syzCrit = syzCriterionInc;
10076  }
10077  else
10078  {
10079  strat->syzCrit = syzCriterion;
10080  }
10081 #ifdef HAVE_RINGS
10082  if (rField_is_Ring(currRing))
10083  {
10085  strat->chainCrit=chainCritRing;
10086  }
10087 #endif
10088 #ifdef HAVE_RATGRING
10089  if (rIsRatGRing(currRing))
10090  {
10091  strat->chainCrit=chainCritPart;
10092  /* enterOnePairNormal get rational part in it */
10093  }
10094 #endif
10095 
10096  strat->sugarCrit = TEST_OPT_SUGARCRIT;
10097  strat->Gebauer = strat->homog || strat->sugarCrit;
10098  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
10099  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
10100  strat->pairtest = NULL;
10101  /* alway use tailreduction, except:
10102  * - in local rings, - in lex order case, -in ring over extensions */
10105 
10106 #ifdef HAVE_PLURAL
10107  // and r is plural_ring
10108  // hence this holds for r a rational_plural_ring
10109  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
10110  { //or it has non-quasi-comm type... later
10111  strat->sugarCrit = FALSE;
10112  strat->Gebauer = FALSE;
10113  strat->honey = FALSE;
10114  }
10115 #endif
10116 
10117  // Coefficient ring?
10118  if (rField_is_Ring(currRing))
10119  {
10120  strat->sugarCrit = FALSE;
10121  strat->Gebauer = FALSE ;
10122  strat->honey = FALSE;
10123  }
10124  #ifdef KDEBUG
10125  if (TEST_OPT_DEBUG)
10126  {
10127  if (strat->homog) PrintS("ideal/module is homogeneous\n");
10128  else PrintS("ideal/module is not homogeneous\n");
10129  }
10130  #endif
10131 }
10132 
10134  (const LSet set, const int length,
10135  LObject* L,const kStrategy strat))
10136 {
10137  if (pos_in_l == posInL110
10138  || pos_in_l == posInL10
10139  #ifdef HAVE_RINGS
10140  || pos_in_l == posInL110Ring
10141  || pos_in_l == posInLRing
10142  #endif
10143  )
10144  return TRUE;
10145 
10146  return FALSE;
10147 }
10148 
10150 {
10152  {
10153  if (strat->honey)
10154  {
10155  strat->posInL = posInL15;
10156  // ok -- here is the deal: from my experiments for Singular-2-0
10157  // I conclude that that posInT_EcartpLength is the best of
10158  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10159  // see the table at the end of this file
10160  if (TEST_OPT_OLDSTD)
10161  strat->posInT = posInT15;
10162  else
10163  strat->posInT = posInT_EcartpLength;
10164  }
10165  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10166  {
10167  strat->posInL = posInL11;
10168  strat->posInT = posInT11;
10169  }
10170  else if (TEST_OPT_INTSTRATEGY)
10171  {
10172  strat->posInL = posInL11;
10173  strat->posInT = posInT11;
10174  }
10175  else
10176  {
10177  strat->posInL = posInL0;
10178  strat->posInT = posInT0;
10179  }
10180  //if (strat->minim>0) strat->posInL =posInLSpecial;
10181  if (strat->homog)
10182  {
10183  strat->posInL = posInL110;
10184  strat->posInT = posInT110;
10185  }
10186  }
10187  else
10188  {
10189  if (strat->homog)
10190  {
10191  strat->posInL = posInL11;
10192  strat->posInT = posInT11;
10193  }
10194  else
10195  {
10196  if ((currRing->order[0]==ringorder_c)
10197  ||(currRing->order[0]==ringorder_C))
10198  {
10199  strat->posInL = posInL17_c;
10200  strat->posInT = posInT17_c;
10201  }
10202  else
10203  {
10204  strat->posInL = posInL17;
10205  strat->posInT = posInT17;
10206  }
10207  }
10208  }
10209  if (strat->minim>0) strat->posInL =posInLSpecial;
10210  // for further tests only
10211  if ((BTEST1(11)) || (BTEST1(12)))
10212  strat->posInL = posInL11;
10213  else if ((BTEST1(13)) || (BTEST1(14)))
10214  strat->posInL = posInL13;
10215  else if ((BTEST1(15)) || (BTEST1(16)))
10216  strat->posInL = posInL15;
10217  else if ((BTEST1(17)) || (BTEST1(18)))
10218  strat->posInL = posInL17;
10219  if (BTEST1(11))
10220  strat->posInT = posInT11;
10221  else if (BTEST1(13))
10222  strat->posInT = posInT13;
10223  else if (BTEST1(15))
10224  strat->posInT = posInT15;
10225  else if ((BTEST1(17)))
10226  strat->posInT = posInT17;
10227  else if ((BTEST1(19)))
10228  strat->posInT = posInT19;
10229  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10230  strat->posInT = posInT1;
10232 }
10233 
10234 #ifdef HAVE_RINGS
10236 {
10238  {
10239  if (strat->honey)
10240  {
10241  strat->posInL = posInL15Ring;
10242  // ok -- here is the deal: from my experiments for Singular-2-0
10243  // I conclude that that posInT_EcartpLength is the best of
10244  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10245  // see the table at the end of this file
10246  if (TEST_OPT_OLDSTD)
10247  strat->posInT = posInT15Ring;
10248  else
10249  strat->posInT = posInT_EcartpLength;
10250  }
10251  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10252  {
10253  strat->posInL = posInL11Ring;
10254  strat->posInT = posInT11;
10255  }
10256  else if (TEST_OPT_INTSTRATEGY)
10257  {
10258  strat->posInL = posInL11Ring;
10259  strat->posInT = posInT11;
10260  }
10261  else
10262  {
10263  strat->posInL = posInL0Ring;
10264  strat->posInT = posInT0;
10265  }
10266  //if (strat->minim>0) strat->posInL =posInLSpecial;
10267  if (strat->homog)
10268  {
10269  strat->posInL = posInL110Ring;
10270  strat->posInT = posInT110Ring;
10271  }
10272  }
10273  else
10274  {
10275  if (strat->homog)
10276  {
10277  //printf("\nHere 3\n");
10278  strat->posInL = posInL11Ring;
10279  strat->posInT = posInT11Ring;
10280  }
10281  else
10282  {
10283  if ((currRing->order[0]==ringorder_c)
10284  ||(currRing->order[0]==ringorder_C))
10285  {
10286  strat->posInL = posInL17_cRing;
10287  strat->posInT = posInT17_cRing;
10288  }
10289  else
10290  {
10291  strat->posInL = posInL11Ringls;
10292  strat->posInT = posInT17Ring;
10293  }
10294  }
10295  }
10296  if (strat->minim>0) strat->posInL =posInLSpecial;
10297  // for further tests only
10298  if ((BTEST1(11)) || (BTEST1(12)))
10299  strat->posInL = posInL11Ring;
10300  else if ((BTEST1(13)) || (BTEST1(14)))
10301  strat->posInL = posInL13;
10302  else if ((BTEST1(15)) || (BTEST1(16)))
10303  strat->posInL = posInL15Ring;
10304  else if ((BTEST1(17)) || (BTEST1(18)))
10305  strat->posInL = posInL17Ring;
10306  if (BTEST1(11))
10307  strat->posInT = posInT11Ring;
10308  else if (BTEST1(13))
10309  strat->posInT = posInT13;
10310  else if (BTEST1(15))
10311  strat->posInT = posInT15Ring;
10312  else if ((BTEST1(17)))
10313  strat->posInT = posInT17Ring;
10314  else if ((BTEST1(19)))
10315  strat->posInT = posInT19;
10316  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10317  strat->posInT = posInT1;
10319 }
10320 #endif
10321 
10322 void initBuchMora (ideal F,ideal Q,kStrategy strat)
10323 {
10324  strat->interpt = BTEST1(OPT_INTERRUPT);
10325  strat->kHEdge=NULL;
10327  /*- creating temp data structures------------------- -*/
10328  strat->cp = 0;
10329  strat->c3 = 0;
10330 #ifdef HAVE_SHIFTBBA
10331  strat->cv = 0;
10332 #endif
10333  strat->tail = pInit();
10334  /*- set s -*/
10335  strat->sl = -1;
10336  /*- set L -*/
10337  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10338  strat->Ll = -1;
10339  strat->L = initL(strat->Lmax);
10340  /*- set B -*/
10341  strat->Bmax = setmaxL;
10342  strat->Bl = -1;
10343  strat->B = initL();
10344  /*- set T -*/
10345  strat->tl = -1;
10346  strat->tmax = setmaxT;
10347  strat->T = initT();
10348  strat->R = initR();
10349  strat->sevT = initsevT();
10350  /*- init local data struct.---------------------------------------- -*/
10351  strat->P.ecart=0;
10352  strat->P.length=0;
10353  strat->P.pLength=0;
10355  {
10356  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
10357  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
10358  }
10360  {
10361  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10362  }
10363  else
10364  {
10365  if(TEST_OPT_SB_1)
10366  {
10367  int i;
10368  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10369  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10370  {
10371  P->m[i-strat->newIdeal] = F->m[i];
10372  F->m[i] = NULL;
10373  }
10374  initSSpecial(F,Q,P,strat);
10375  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10376  {
10377  F->m[i] = P->m[i-strat->newIdeal];
10378  P->m[i-strat->newIdeal] = NULL;
10379  }
10380  idDelete(&P);
10381  }
10382  else
10383  {
10384  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10385  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
10386  }
10387  }
10388  strat->fromT = FALSE;
10390  if ((!TEST_OPT_SB_1)
10391  || (rField_is_Ring(currRing))
10392  )
10393  {
10394  updateS(TRUE,strat);
10395  }
10396 #ifdef HAVE_SHIFTBBA
10397  if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
10398 #endif
10399  {
10400  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10401  strat->fromQ=NULL;
10402  }
10403  assume(kTest_TS(strat));
10404 }
10405 
10407 {
10408  /*- release temp data -*/
10409  cleanT(strat);
10410  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10411  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10412  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10413  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10414  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10415  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10416  /*- set L: should be empty -*/
10417  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10418  /*- set B: should be empty -*/
10419  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10420  pLmFree(&strat->tail);
10421  strat->syzComp=0;
10422 
10423 #ifdef HAVE_SHIFTBBA
10424  if (rIsLPRing(currRing) && strat->rightGB)
10425  {
10426  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10427  strat->fromQ=NULL;
10428  }
10429 #endif
10430 }
10431 
10432 void initSbaPos (kStrategy strat)
10433 {
10435  {
10436  if (strat->honey)
10437  {
10438  strat->posInL = posInL15;
10439  // ok -- here is the deal: from my experiments for Singular-2-0
10440  // I conclude that that posInT_EcartpLength is the best of
10441  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10442  // see the table at the end of this file
10443  if (TEST_OPT_OLDSTD)
10444  strat->posInT = posInT15;
10445  else
10446  strat->posInT = posInT_EcartpLength;
10447  }
10448  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10449  {
10450  strat->posInL = posInL11;
10451  strat->posInT = posInT11;
10452  }
10453  else if (TEST_OPT_INTSTRATEGY)
10454  {
10455  strat->posInL = posInL11;
10456  strat->posInT = posInT11;
10457  }
10458  else
10459  {
10460  strat->posInL = posInL0;
10461  strat->posInT = posInT0;
10462  }
10463  //if (strat->minim>0) strat->posInL =posInLSpecial;
10464  if (strat->homog)
10465  {
10466  strat->posInL = posInL110;
10467  strat->posInT = posInT110;
10468  }
10469  }
10470  else
10471  {
10472  if (strat->homog)
10473  {
10474  strat->posInL = posInL11;
10475  strat->posInT = posInT11;
10476  }
10477  else
10478  {
10479  if ((currRing->order[0]==ringorder_c)
10480  ||(currRing->order[0]==ringorder_C))
10481  {
10482  strat->posInL = posInL17_c;
10483  strat->posInT = posInT17_c;
10484  }
10485  else
10486  {
10487  strat->posInL = posInL17;
10488  strat->posInT = posInT17;
10489  }
10490  }
10491  }
10492  if (strat->minim>0) strat->posInL =posInLSpecial;
10493  // for further tests only
10494  if ((BTEST1(11)) || (BTEST1(12)))
10495  strat->posInL = posInL11;
10496  else if ((BTEST1(13)) || (BTEST1(14)))
10497  strat->posInL = posInL13;
10498  else if ((BTEST1(15)) || (BTEST1(16)))
10499  strat->posInL = posInL15;
10500  else if ((BTEST1(17)) || (BTEST1(18)))
10501  strat->posInL = posInL17;
10502  if (BTEST1(11))
10503  strat->posInT = posInT11;
10504  else if (BTEST1(13))
10505  strat->posInT = posInT13;
10506  else if (BTEST1(15))
10507  strat->posInT = posInT15;
10508  else if ((BTEST1(17)))
10509  strat->posInT = posInT17;
10510  else if ((BTEST1(19)))
10511  strat->posInT = posInT19;
10512  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10513  strat->posInT = posInT1;
10514  if (rField_is_Ring(currRing))
10515  {
10516  strat->posInL = posInL11Ring;
10517  if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
10518  strat->posInL = posInL11Ringls;
10519  strat->posInT = posInT11;
10520  }
10521  strat->posInLDependsOnLength = FALSE;
10522  strat->posInLSba = posInLSig;
10523  //strat->posInL = posInLSig;
10524  strat->posInL = posInLF5C;
10525  /*
10526  if (rField_is_Ring(currRing))
10527  {
10528  strat->posInLSba = posInLSigRing;
10529  strat->posInL = posInL11Ring;
10530  }*/
10531  //strat->posInT = posInTSig;
10532 }
10533 
10534 void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10535 {
10536  strat->interpt = BTEST1(OPT_INTERRUPT);
10537  strat->kHEdge=NULL;
10539  /*- creating temp data structures------------------- -*/
10540  strat->cp = 0;
10541  strat->c3 = 0;
10542  strat->tail = pInit();
10543  /*- set s -*/
10544  strat->sl = -1;
10545  /*- set ps -*/
10546  strat->syzl = -1;
10547  /*- set L -*/
10548  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10549  strat->Ll = -1;
10550  strat->L = initL(strat->Lmax);
10551  /*- set B -*/
10552  strat->Bmax = setmaxL;
10553  strat->Bl = -1;
10554  strat->B = initL();
10555  /*- set T -*/
10556  strat->tl = -1;
10557  strat->tmax = setmaxT;
10558  strat->T = initT();
10559  strat->R = initR();
10560  strat->sevT = initsevT();
10561  /*- init local data struct.---------------------------------------- -*/
10562  strat->P.ecart=0;
10563  strat->P.length=0;
10565  {
10566  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
10567  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
10568  }
10570  {
10571  /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10572  }
10573  else
10574  {
10575  if(TEST_OPT_SB_1)
10576  {
10577  int i;
10578  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10579  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10580  {
10581  P->m[i-strat->newIdeal] = F->m[i];
10582  F->m[i] = NULL;
10583  }
10584  initSSpecialSba(F,Q,P,strat);
10585  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10586  {
10587  F->m[i] = P->m[i-strat->newIdeal];
10588  P->m[i-strat->newIdeal] = NULL;
10589  }
10590  idDelete(&P);
10591  }
10592  else
10593  {
10594  initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10595  }
10596  }
10597  strat->fromT = FALSE;
10598  if (!TEST_OPT_SB_1)
10599  {
10600  if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10601  }
10602  //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10603  //strat->fromQ=NULL;
10604  assume(kTest_TS(strat));
10605 }
10606 
10607 void exitSba (kStrategy strat)
10608 {
10609  /*- release temp data -*/
10611  cleanTSbaRing(strat);
10612  else
10613  cleanT(strat);
10614  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10615  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10616  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10617  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10618  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10619  omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10620  if(strat->syzmax>0)
10621  {
10622  omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10623  omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10624  if (strat->sbaOrder == 1)
10625  {
10626  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10627  }
10628  }
10629  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10630  /*- set L: should be empty -*/
10631  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10632  /*- set B: should be empty -*/
10633  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10634  /*- set sig: no need for the signatures anymore -*/
10635  omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10636  pLmDelete(&strat->tail);
10637  strat->syzComp=0;
10638 }
10639 
10640 /*2
10641 * in the case of a standardbase of a module over a qring:
10642 * replace polynomials in i by ak vectors,
10643 * (the polynomial * unit vectors gen(1)..gen(ak)
10644 * in every case (also for ideals:)
10645 * deletes divisible vectors/polynomials
10646 */
10647 void updateResult(ideal r,ideal Q, kStrategy strat)
10648 {
10649  int l;
10650  if (strat->ak>0)
10651  {
10652  for (l=IDELEMS(r)-1;l>=0;l--)
10653  {
10654  if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10655  {
10656  pDelete(&r->m[l]); // and set it to NULL
10657  }
10658  }
10659  int q;
10660  poly p;
10661  if(!rField_is_Ring(currRing))
10662  {
10663  for (l=IDELEMS(r)-1;l>=0;l--)
10664  {
10665  if ((r->m[l]!=NULL)
10666  //&& (strat->syzComp>0)
10667  //&& (pGetComp(r->m[l])<=strat->syzComp)
10668  )
10669  {
10670  for(q=IDELEMS(Q)-1; q>=0;q--)
10671  {
10672  if ((Q->m[q]!=NULL)
10673  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10674  {
10675  if (TEST_OPT_REDSB)
10676  {
10677  p=r->m[l];
10678  r->m[l]=kNF(Q,NULL,p);
10679  pDelete(&p);
10680  }
10681  else
10682  {
10683  pDelete(&r->m[l]); // and set it to NULL
10684  }
10685  break;
10686  }
10687  }
10688  }
10689  }
10690  }
10691  #ifdef HAVE_RINGS
10692  else
10693  {
10694  for (l=IDELEMS(r)-1;l>=0;l--)
10695  {
10696  if ((r->m[l]!=NULL)
10697  //&& (strat->syzComp>0)
10698  //&& (pGetComp(r->m[l])<=strat->syzComp)
10699  )
10700  {
10701  for(q=IDELEMS(Q)-1; q>=0;q--)
10702  {
10703  if ((Q->m[q]!=NULL)
10704  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10705  {
10706  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10707  {
10708  if (TEST_OPT_REDSB)
10709  {
10710  p=r->m[l];
10711  r->m[l]=kNF(Q,NULL,p);
10712  pDelete(&p);
10713  }
10714  else
10715  {
10716  pDelete(&r->m[l]); // and set it to NULL
10717  }
10718  break;
10719  }
10720  }
10721  }
10722  }
10723  }
10724  }
10725  #endif
10726  }
10727  else
10728  {
10729  int q;
10730  poly p;
10731  BOOLEAN reduction_found=FALSE;
10732  if (!rField_is_Ring(currRing))
10733  {
10734  for (l=IDELEMS(r)-1;l>=0;l--)
10735  {
10736  if (r->m[l]!=NULL)
10737  {
10738  for(q=IDELEMS(Q)-1; q>=0;q--)
10739  {
10740  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10741  {
10742  if (TEST_OPT_REDSB)
10743  {
10744  p=r->m[l];
10745  r->m[l]=kNF(Q,NULL,p);
10746  pDelete(&p);
10747  reduction_found=TRUE;
10748  }
10749  else
10750  {
10751  pDelete(&r->m[l]); // and set it to NULL
10752  }
10753  break;
10754  }
10755  }
10756  }
10757  }
10758  }
10759  #ifdef HAVE_RINGS
10760  //Also need divisibility of the leading coefficients
10761  else
10762  {
10763  for (l=IDELEMS(r)-1;l>=0;l--)
10764  {
10765  if (r->m[l]!=NULL)
10766  {
10767  for(q=IDELEMS(Q)-1; q>=0;q--)
10768  {
10769  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10770  {
10771  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10772  {
10773  if (TEST_OPT_REDSB)
10774  {
10775  p=r->m[l];
10776  r->m[l]=kNF(Q,NULL,p);
10777  pDelete(&p);
10778  reduction_found=TRUE;
10779  }
10780  else
10781  {
10782  pDelete(&r->m[l]); // and set it to NULL
10783  }
10784  break;
10785  }
10786  }
10787  }
10788  }
10789  }
10790  }
10791  #endif
10792  if (/*TEST_OPT_REDSB &&*/ reduction_found)
10793  {
10794  #ifdef HAVE_RINGS
10796  {
10797  for (l=IDELEMS(r)-1;l>=0;l--)
10798  {
10799  if (r->m[l]!=NULL)
10800  {
10801  for(q=IDELEMS(r)-1;q>=0;q--)
10802  {
10803  if ((l!=q)
10804  && (r->m[q]!=NULL)
10805  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10806  &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10807  )
10808  {
10809  //If they are equal then take the one with the smallest length
10810  if(pLmDivisibleBy(r->m[q],r->m[l])
10811  && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10812  && (pLength(r->m[q]) < pLength(r->m[l]) ||
10813  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10814  {
10815  pDelete(&r->m[l]);
10816  break;
10817  }
10818  else
10819  pDelete(&r->m[q]);
10820  }
10821  }
10822  }
10823  }
10824  }
10825  else
10826  #endif
10827  {
10828  for (l=IDELEMS(r)-1;l>=0;l--)
10829  {
10830  if (r->m[l]!=NULL)
10831  {
10832  for(q=IDELEMS(r)-1;q>=0;q--)
10833  {
10834  if ((l!=q)
10835  && (r->m[q]!=NULL)
10836  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10837  )
10838  {
10839  //If they are equal then take the one with the smallest length
10840  if(pLmDivisibleBy(r->m[q],r->m[l])
10841  &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10842  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10843  {
10844  pDelete(&r->m[l]);
10845  break;
10846  }
10847  else
10848  pDelete(&r->m[q]);
10849  }
10850  }
10851  }
10852  }
10853  }
10854  }
10855  }
10856  idSkipZeroes(r);
10857 }
10858 
10859 void completeReduce (kStrategy strat, BOOLEAN withT)
10860 {
10861  int i;
10862  int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10863  LObject L;
10864 
10865 #ifdef KDEBUG
10866  // need to set this: during tailreductions of T[i], T[i].max is out of
10867  // sync
10868  sloppy_max = TRUE;
10869 #endif
10870 
10871  strat->noTailReduction = FALSE;
10872  //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10873  if (TEST_OPT_PROT)
10874  {
10875  PrintLn();
10876 // if (timerv) writeTime("standard base computed:");
10877  }
10878  if (TEST_OPT_PROT)
10879  {
10880  Print("(S:%d)",strat->sl);mflush();
10881  }
10882  for (i=strat->sl; i>=low; i--)
10883  {
10884  int end_pos=strat->sl;
10885  if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10886  if (strat->ak==0) end_pos=i-1;
10887  TObject* T_j = strat->s_2_t(i);
10888  if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10889  {
10890  L = *T_j;
10891  #ifdef KDEBUG
10892  if (TEST_OPT_DEBUG)
10893  {
10894  Print("test S[%d]:",i);
10895  p_wrp(L.p,currRing,strat->tailRing);
10896  PrintLn();
10897  }
10898  #endif
10900  strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10901  else
10902  strat->S[i] = redtail(&L, strat->sl, strat);
10903  #ifdef KDEBUG
10904  if (TEST_OPT_DEBUG)
10905  {
10906  Print("to (tailR) S[%d]:",i);
10907  p_wrp(strat->S[i],currRing,strat->tailRing);
10908  PrintLn();
10909  }
10910  #endif
10911 
10912  if (strat->redTailChange)
10913  {
10914  if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10915  if (pNext(T_j->p) != NULL)
10916  T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10917  else
10918  T_j->max_exp = NULL;
10919  }
10921  T_j->pCleardenom();
10922  }
10923  else
10924  {
10925  assume(currRing == strat->tailRing);
10926  #ifdef KDEBUG
10927  if (TEST_OPT_DEBUG)
10928  {
10929  Print("test S[%d]:",i);
10930  p_wrp(strat->S[i],currRing,strat->tailRing);
10931  PrintLn();
10932  }
10933  #endif
10935  strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10936  else
10937  strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10939  {
10940  if (TEST_OPT_CONTENTSB)
10941  {
10942  number n;
10943  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10944  if (!nIsOne(n))
10945  {
10947  denom->n=nInvers(n);
10948  denom->next=DENOMINATOR_LIST;
10949  DENOMINATOR_LIST=denom;
10950  }
10951  nDelete(&n);
10952  }
10953  else
10954  {
10955  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10956  }
10957  }
10958  #ifdef KDEBUG
10959  if (TEST_OPT_DEBUG)
10960  {
10961  Print("to (-tailR) S[%d]:",i);
10962  p_wrp(strat->S[i],currRing,strat->tailRing);
10963  PrintLn();
10964  }
10965  #endif
10966  }
10967  if (TEST_OPT_PROT)
10968  PrintS("-");
10969  }
10970  if (TEST_OPT_PROT) PrintLn();
10971 #ifdef KDEBUG
10972  sloppy_max = FALSE;
10973 #endif
10974 }
10975 
10976 
10977 /*2
10978 * computes the new strat->kHEdge and the new pNoether,
10979 * returns TRUE, if pNoether has changed
10980 */
10982 {
10983  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10984  return FALSE;
10985  int i,j;
10986  poly newNoether;
10987 
10988 #if 0
10989  if (currRing->weight_all_1)
10990  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10991  else
10992  scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10993 #else
10994  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10995 #endif
10996  if (strat->kHEdge==NULL) return FALSE;
10997  if (strat->t_kHEdge != NULL) p_LmFree(strat->t_kHEdge, strat->tailRing);
10998  if (strat->tailRing != currRing)
10999  strat->t_kHEdge = k_LmInit_currRing_2_tailRing(strat->kHEdge, strat->tailRing);
11000  /* compare old and new noether*/
11001  newNoether = pLmInit(strat->kHEdge);
11002  pSetCoeff0(newNoether,nInit(1));
11003  j = p_FDeg(newNoether,currRing);
11004  for (i=1; i<=(currRing->N); i++)
11005  {
11006  if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
11007  }
11008  pSetm(newNoether);
11009  if (j < strat->HCord) /*- statistics -*/
11010  {
11011  if (TEST_OPT_PROT)
11012  {
11013  Print("H(%d)",j);
11014  mflush();
11015  }
11016  strat->HCord=j;
11017  #ifdef KDEBUG
11018  if (TEST_OPT_DEBUG)
11019  {
11020  Print("H(%d):",j);
11021  wrp(strat->kHEdge);
11022  PrintLn();
11023  }
11024  #endif
11025  }
11026  if (pCmp(strat->kNoether,newNoether)!=1)
11027  {
11028  if (strat->kNoether!=NULL) pLmDelete(&strat->kNoether);
11029  strat->kNoether=newNoether;
11030  if (strat->t_kNoether != NULL) p_LmFree(strat->t_kNoether, strat->tailRing);
11031  if (strat->tailRing != currRing)
11032  strat->t_kNoether = k_LmInit_currRing_2_tailRing(strat->kNoether, strat->tailRing);
11033 
11034  return TRUE;
11035  }
11036  pLmDelete(newNoether);
11037  return FALSE;
11038 }
11039 
11040 /***************************************************************
11041  *
11042  * Routines related for ring changes during std computations
11043  *
11044  ***************************************************************/
11045 BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
11046 {
11047  if (strat->overflow) return FALSE;
11048  assume(L->p1 != NULL && L->p2 != NULL);
11049  // shift changes: from 0 to -1
11050  assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
11051  assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
11052 
11053  if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
11054  return FALSE;
11055  // shift changes: extra case inserted
11056  if ((L->i_r1 == -1) || (L->i_r2 == -1) )
11057  {
11058  return TRUE;
11059  }
11060  poly p1_max=NULL;
11061  if ((L->i_r1>=0)&&(strat->R[L->i_r1]!=NULL)) p1_max = (strat->R[L->i_r1])->max_exp;
11062  poly p2_max=NULL;
11063  if ((L->i_r2>=0)&&(strat->R[L->i_r2]!=NULL)) p2_max = (strat->R[L->i_r2])->max_exp;
11064 
11065  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
11066  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
11067  {
11068  p_LmFree(m1, strat->tailRing);
11069  p_LmFree(m2, strat->tailRing);
11070  m1 = NULL;
11071  m2 = NULL;
11072  return FALSE;
11073  }
11074  return TRUE;
11075 }
11076 
11077 #ifdef HAVE_RINGS
11078 /***************************************************************
11079  *
11080  * Checks, if we can compute the gcd poly / strong pair
11081  * gcd-poly = m1 * R[atR] + m2 * S[atS]
11082  *
11083  ***************************************************************/
11084 BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
11085 {
11086  assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
11087  //assume(strat->tailRing != currRing);
11088 
11089  poly p1_max = (strat->R[atR])->max_exp;
11090  poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
11091 
11092  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
11093  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
11094  {
11095  return FALSE;
11096  }
11097  return TRUE;
11098 }
11099 #endif
11100 
11101 #ifdef HAVE_RINGS
11102 /*!
11103  used for GB over ZZ: look for constant and monomial elements in the ideal
11104  background: any known constant element of ideal suppresses
11105  intermediate coefficient swell
11106 */
11107 poly preIntegerCheck(const ideal Forig, const ideal Q)
11108 {
11109  if(!nCoeff_is_Z(currRing->cf))
11110  return NULL;
11111  ideal F = idCopy(Forig);
11112  idSkipZeroes(F);
11113  poly pmon;
11114  ring origR = currRing;
11115  ideal monred = idInit(1,1);
11116  for(int i=0; i<idElem(F); i++)
11117  {
11118  if(pNext(F->m[i]) == NULL)
11119  idInsertPoly(monred, pCopy(F->m[i]));
11120  }
11121  int posconst = idPosConstant(F);
11122  if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
11123  {
11124  idDelete(&F);
11125  idDelete(&monred);
11126  return NULL;
11127  }
11128  int idelemQ = 0;
11129  if(Q!=NULL)
11130  {
11131  idelemQ = IDELEMS(Q);
11132  for(int i=0; i<idelemQ; i++)
11133  {
11134  if(pNext(Q->m[i]) == NULL)
11135  idInsertPoly(monred, pCopy(Q->m[i]));
11136  }
11137  idSkipZeroes(monred);
11138  posconst = idPosConstant(monred);
11139  //the constant, if found, will be from Q
11140  if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
11141  {
11142  pmon = pCopy(monred->m[posconst]);
11143  idDelete(&F);
11144  idDelete(&monred);
11145  return pmon;
11146  }
11147  }
11148  ring QQ_ring = rCopy0(currRing,FALSE);
11149  nKillChar(QQ_ring->cf);
11150  QQ_ring->cf = nInitChar(n_Q, NULL);
11151  rComplete(QQ_ring,1);
11152  QQ_ring = rAssure_c_dp(QQ_ring);
11153  rChangeCurrRing(QQ_ring);
11154  nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
11155  ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
11156  for(int i = 0, j = 0; i<IDELEMS(F); i++)
11157  II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
11158  for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
11159  II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
11160  ideal one = kStd(II, NULL, isNotHomog, NULL);
11161  idSkipZeroes(one);
11162  if(idIsConstant(one))
11163  {
11164  //one should be <1>
11165  for(int i = IDELEMS(II)-1; i>=0; i--)
11166  if(II->m[i] != NULL)
11167  II->m[i+1] = II->m[i];
11168  II->m[0] = pOne();
11169  ideal syz = idSyzygies(II, isNotHomog, NULL);
11170  poly integer = NULL;
11171  for(int i = IDELEMS(syz)-1;i>=0; i--)
11172  {
11173  if(pGetComp(syz->m[i]) == 1)
11174  {
11175  pSetComp(syz->m[i],0);
11176  if(pIsConstant(pHead(syz->m[i])))
11177  {
11178  integer = pHead(syz->m[i]);
11179  break;
11180  }
11181  }
11182  }
11183  rChangeCurrRing(origR);
11184  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
11185  pmon = prMapR(integer, nMap2, QQ_ring, origR);
11186  idDelete(&monred);
11187  idDelete(&F);
11188  id_Delete(&II,QQ_ring);
11189  id_Delete(&one,QQ_ring);
11190  id_Delete(&syz,QQ_ring);
11191  p_Delete(&integer,QQ_ring);
11192  rDelete(QQ_ring);
11193  return pmon;
11194  }
11195  else
11196  {
11197  if(idIs0(monred))
11198  {
11199  poly mindegmon = NULL;
11200  for(int i = 0; i<IDELEMS(one); i++)
11201  {
11202  if(pNext(one->m[i]) == NULL)
11203  {
11204  if(mindegmon == NULL)
11205  mindegmon = pCopy(one->m[i]);
11206  else
11207  {
11208  if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
11209  mindegmon = pCopy(one->m[i]);
11210  }
11211  }
11212  }
11213  if(mindegmon != NULL)
11214  {
11215  for(int i = IDELEMS(II)-1; i>=0; i--)
11216  if(II->m[i] != NULL)
11217  II->m[i+1] = II->m[i];
11218  II->m[0] = pCopy(mindegmon);
11219  ideal syz = idSyzygies(II, isNotHomog, NULL);
11220  bool found = FALSE;
11221  for(int i = IDELEMS(syz)-1;i>=0; i--)
11222  {
11223  if(pGetComp(syz->m[i]) == 1)
11224  {
11225  pSetComp(syz->m[i],0);
11226  if(pIsConstant(pHead(syz->m[i])))
11227  {
11228  pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
11229  found = TRUE;
11230  break;
11231  }
11232  }
11233  }
11234  id_Delete(&syz,QQ_ring);
11235  if (found == FALSE)
11236  {
11237  rChangeCurrRing(origR);
11238  idDelete(&monred);
11239  idDelete(&F);
11240  id_Delete(&II,QQ_ring);
11241  id_Delete(&one,QQ_ring);
11242  rDelete(QQ_ring);
11243  return NULL;
11244  }
11245  rChangeCurrRing(origR);
11246  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
11247  pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
11248  idDelete(&monred);
11249  idDelete(&F);
11250  id_Delete(&II,QQ_ring);
11251  id_Delete(&one,QQ_ring);
11252  id_Delete(&syz,QQ_ring);
11253  rDelete(QQ_ring);
11254  return pmon;
11255  }
11256  }
11257  }
11258  rChangeCurrRing(origR);
11259  idDelete(&monred);
11260  idDelete(&F);
11261  id_Delete(&II,QQ_ring);
11262  id_Delete(&one,QQ_ring);
11263  rDelete(QQ_ring);
11264  return NULL;
11265 }
11266 #endif
11267 
11268 #ifdef HAVE_RINGS
11269 /*!
11270  used for GB over ZZ: intermediate reduction by monomial elements
11271  background: any known constant element of ideal suppresses
11272  intermediate coefficient swell
11273 */
11275 {
11276  if(!nCoeff_is_Z(currRing->cf))
11277  return;
11278  poly pH = h->GetP();
11279  poly p,pp;
11280  p = pH;
11281  bool deleted = FALSE, ok = FALSE;
11282  for(int i = 0; i<=strat->sl; i++)
11283  {
11284  p = pH;
11285  if(pNext(strat->S[i]) == NULL)
11286  {
11287  //pWrite(p);
11288  //pWrite(strat->S[i]);
11289  while(ok == FALSE && p != NULL)
11290  {
11291  if(pLmDivisibleBy(strat->S[i], p)
11292 #ifdef HAVE_SHIFTBBA
11293  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], p))
11294 #endif
11295  )
11296  {
11297  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11298  p_SetCoeff(p,dummy,currRing);
11299  }
11300  if(nIsZero(p->coef))
11301  {
11302  pLmDelete(&p);
11303  h->p = p;
11304  deleted = TRUE;
11305  }
11306  else
11307  {
11308  ok = TRUE;
11309  }
11310  }
11311  if (p!=NULL)
11312  {
11313  pp = pNext(p);
11314  while(pp != NULL)
11315  {
11316  if(pLmDivisibleBy(strat->S[i], pp)
11317 #ifdef HAVE_SHIFTBBA
11318  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], pp))
11319 #endif
11320  )
11321  {
11322  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11323  p_SetCoeff(pp,dummy,currRing);
11324  if(nIsZero(pp->coef))
11325  {
11326  pLmDelete(&pNext(p));
11327  pp = pNext(p);
11328  deleted = TRUE;
11329  }
11330  else
11331  {
11332  p = pp;
11333  pp = pNext(p);
11334  }
11335  }
11336  else
11337  {
11338  p = pp;
11339  pp = pNext(p);
11340  }
11341  }
11342  }
11343  }
11344  }
11345  h->SetLmCurrRing();
11346  if((deleted)&&(h->p!=NULL))
11347  strat->initEcart(h);
11348 }
11349 
11351 {
11352  if(!nCoeff_is_Z(currRing->cf))
11353  return;
11354  poly hSig = h->sig;
11355  poly pH = h->GetP();
11356  poly p,pp;
11357  p = pH;
11358  bool deleted = FALSE, ok = FALSE;
11359  for(int i = 0; i<=strat->sl; i++)
11360  {
11361  p = pH;
11362  if(pNext(strat->S[i]) == NULL)
11363  {
11364  while(ok == FALSE && p!=NULL)
11365  {
11366  if(pLmDivisibleBy(strat->S[i], p))
11367  {
11368  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11369  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11370  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11371  {
11372  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11373  p_SetCoeff(p,dummy,currRing);
11374  }
11375  pDelete(&sigMult);
11376  }
11377  if(nIsZero(p->coef))
11378  {
11379  pLmDelete(&p);
11380  h->p = p;
11381  deleted = TRUE;
11382  }
11383  else
11384  {
11385  ok = TRUE;
11386  }
11387  }
11388  if(p == NULL)
11389  return;
11390  pp = pNext(p);
11391  while(pp != NULL)
11392  {
11393  if(pLmDivisibleBy(strat->S[i], pp))
11394  {
11395  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11396  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11397  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11398  {
11399  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11400  p_SetCoeff(pp,dummy,currRing);
11401  if(nIsZero(pp->coef))
11402  {
11403  pLmDelete(&pNext(p));
11404  pp = pNext(p);
11405  deleted = TRUE;
11406  }
11407  else
11408  {
11409  p = pp;
11410  pp = pNext(p);
11411  }
11412  }
11413  else
11414  {
11415  p = pp;
11416  pp = pNext(p);
11417  }
11418  pDelete(&sigMult);
11419  }
11420  else
11421  {
11422  p = pp;
11423  pp = pNext(p);
11424  }
11425  }
11426  }
11427  }
11428  h->SetLmCurrRing();
11429  if(deleted)
11430  strat->initEcart(h);
11431 
11432 }
11433 
11434 /*!
11435  used for GB over ZZ: final reduction by constant elements
11436  background: any known constant element of ideal suppresses
11437  intermediate coefficient swell and beautifies output
11438 */
11440 {
11441  assume(strat->tl<0); /* can only be called with no elements in T:
11442  i.e. after exitBuchMora */
11443  /* do not use strat->S, strat->sl as they may be out of sync*/
11444  if(!nCoeff_is_Z(currRing->cf))
11445  return;
11446  poly p,pp;
11447  for(int j = 0; j<IDELEMS(strat->Shdl); j++)
11448  {
11449  if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
11450  {
11451  for(int i = 0; i<IDELEMS(strat->Shdl); i++)
11452  {
11453  if((i != j) && (strat->Shdl->m[i] != NULL))
11454  {
11455  p = strat->Shdl->m[i];
11456  while((p!=NULL) && (pLmDivisibleBy(strat->Shdl->m[j], p)
11457 #if HAVE_SHIFTBBA
11458  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], p))
11459 #endif
11460  ))
11461  {
11462  number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
11463  if (!nEqual(dummy,p->coef))
11464  {
11465  if (nIsZero(dummy))
11466  {
11467  nDelete(&dummy);
11468  pLmDelete(&strat->Shdl->m[i]);
11469  p=strat->Shdl->m[i];
11470  }
11471  else
11472  {
11473  p_SetCoeff(p,dummy,currRing);
11474  break;
11475  }
11476  }
11477  else
11478  {
11479  nDelete(&dummy);
11480  break;
11481  }
11482  }
11483  if (p!=NULL)
11484  {
11485  pp = pNext(p);
11486  while(pp != NULL)
11487  {
11488  if(pLmDivisibleBy(strat->Shdl->m[j], pp)
11489 #if HAVE_SHIFTBBA
11490  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], pp))
11491 #endif
11492  )
11493  {
11494  number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
11495  if (!nEqual(dummy,pp->coef))
11496  {
11497  p_SetCoeff(pp,dummy,currRing);
11498  if(nIsZero(pp->coef))
11499  {
11500  pLmDelete(&pNext(p));
11501  pp = pNext(p);
11502  }
11503  else
11504  {
11505  p = pp;
11506  pp = pNext(p);
11507  }
11508  }
11509  else
11510  {
11511  nDelete(&dummy);
11512  p = pp;
11513  pp = pNext(p);
11514  }
11515  }
11516  else
11517  {
11518  p = pp;
11519  pp = pNext(p);
11520  }
11521  }
11522  }
11523  }
11524  }
11525  //idPrint(strat->Shdl);
11526  }
11527  }
11528  idSkipZeroes(strat->Shdl);
11529 }
11530 #endif
11531 
11532 BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
11533 {
11534  assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11535  /* initial setup or extending */
11536 
11537  if (rIsLPRing(currRing)) return TRUE;
11538  if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11539  if (expbound >= currRing->bitmask) return FALSE;
11540  strat->overflow=FALSE;
11541  ring new_tailRing = rModifyRing(currRing,
11542  // Hmmm .. the condition pFDeg == p_Deg
11543  // might be too strong
11544  (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11545  (strat->ak==0), // omit_comp if the input is an ideal
11546  expbound); // exp_limit
11547 
11548  if (new_tailRing == currRing) return TRUE;
11549 
11550  strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11551  strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11552 
11553  if (currRing->pFDeg != currRing->pFDegOrig)
11554  {
11555  new_tailRing->pFDeg = currRing->pFDeg;
11556  new_tailRing->pLDeg = currRing->pLDeg;
11557  }
11558 
11559  if (TEST_OPT_PROT)
11560  Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11561  kTest_TS(strat);
11562  assume(new_tailRing != strat->tailRing);
11563  pShallowCopyDeleteProc p_shallow_copy_delete
11564  = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11565 
11566  omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11567 
11568  int i;
11569  for (i=0; i<=strat->tl; i++)
11570  {
11571  strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11572  p_shallow_copy_delete);
11573  }
11574  for (i=0; i<=strat->Ll; i++)
11575  {
11576  assume(strat->L[i].p != NULL);
11577  if (pNext(strat->L[i].p) != strat->tail)
11578  strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11579  }
11580  if ((strat->P.t_p != NULL) ||
11581  ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11582  strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11583 
11584  if ((L != NULL) && (L->tailRing != new_tailRing))
11585  {
11586  if (L->i_r < 0)
11587  L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11588  else
11589  {
11590  assume(L->i_r <= strat->tl);
11591  TObject* t_l = strat->R[L->i_r];
11592  assume(t_l != NULL);
11593  L->tailRing = new_tailRing;
11594  L->p = t_l->p;
11595  L->t_p = t_l->t_p;
11596  L->max_exp = t_l->max_exp;
11597  }
11598  }
11599 
11600  if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11601  T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11602 
11603  omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11604  if (strat->tailRing != currRing)
11605  rKillModifiedRing(strat->tailRing);
11606 
11607  strat->tailRing = new_tailRing;
11608  strat->tailBin = new_tailBin;
11609  strat->p_shallow_copy_delete
11610  = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11611 
11612  if (strat->kHEdge != NULL)
11613  {
11614  if (strat->t_kHEdge != NULL)
11615  p_LmFree(strat->t_kHEdge, strat->tailRing);
11616  strat->t_kHEdge=k_LmInit_currRing_2_tailRing(strat->kHEdge, new_tailRing);
11617  }
11618 
11619  if (strat->kNoether != NULL)
11620  {
11621  if (strat->t_kNoether != NULL)
11622  p_LmFree(strat->t_kNoether, strat->tailRing);
11624  new_tailRing);
11625  }
11626  kTest_TS(strat);
11627  if (TEST_OPT_PROT)
11628  PrintS("]");
11629  return TRUE;
11630 }
11631 
11633 {
11634  unsigned long l = 0;
11635  int i;
11636  long e;
11637 
11638  assume(strat->tailRing == currRing);
11639 
11640  for (i=0; i<= strat->Ll; i++)
11641  {
11642  l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11643  }
11644  for (i=0; i<=strat->tl; i++)
11645  {
11646  // Hmm ... this we could do in one Step
11647  l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11648  }
11649  if (rField_is_Ring(currRing))
11650  {
11651  l *= 2;
11652  }
11653  e = p_GetMaxExp(l, currRing);
11654  if (e <= 1) e = 2;
11655  if (rIsLPRing(currRing)) e = 1;
11656 
11657  kStratChangeTailRing(strat, NULL, NULL, e);
11658 }
11659 
11660 ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11661 {
11662  int n = rBlocks(r); // Including trailing zero!
11663  // if sbaOrder == 1 => use (C,monomial order from r)
11664  if (strat->sbaOrder == 1)
11665  {
11666  if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11667  {
11668  return r;
11669  }
11670  ring res = rCopy0(r, TRUE, FALSE);
11671  res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11672  res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11673  res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11674  int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11675  res->wvhdl = wvhdl;
11676  for (int i=1; i<n; i++)
11677  {
11678  res->order[i] = r->order[i-1];
11679  res->block0[i] = r->block0[i-1];
11680  res->block1[i] = r->block1[i-1];
11681  res->wvhdl[i] = r->wvhdl[i-1];
11682  }
11683 
11684  // new 1st block
11685  res->order[0] = ringorder_C; // Prefix
11686  // removes useless secondary component order if defined in old ring
11687  for (int i=rBlocks(res); i>0; --i)
11688  {
11689  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11690  {
11691  res->order[i] = (rRingOrder_t)0;
11692  }
11693  }
11694  rComplete(res, 1);
11695 #ifdef HAVE_PLURAL
11696  if (rIsPluralRing(r))
11697  {
11698  if ( nc_rComplete(r, res, false) ) // no qideal!
11699  {
11700 #ifndef SING_NDEBUG
11701  WarnS("error in nc_rComplete");
11702 #endif
11703  // cleanup?
11704 
11705  // rDelete(res);
11706  // return r;
11707 
11708  // just go on..
11709  }
11710  }
11711 #endif
11712  strat->tailRing = res;
11713  return (res);
11714  }
11715  // if sbaOrder == 3 => degree - position - ring order
11716  if (strat->sbaOrder == 3)
11717  {
11718  ring res = rCopy0(r, TRUE, FALSE);
11719  res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11720  res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11721  res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11722  int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11723  res->wvhdl = wvhdl;
11724  for (int i=2; i<n+2; i++)
11725  {
11726  res->order[i] = r->order[i-2];
11727  res->block0[i] = r->block0[i-2];
11728  res->block1[i] = r->block1[i-2];
11729  res->wvhdl[i] = r->wvhdl[i-2];
11730  }
11731 
11732  // new 1st block
11733  res->order[0] = ringorder_a; // Prefix
11734  res->block0[0] = 1;
11735  res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11736  for (int i=0; i<res->N; ++i)
11737  res->wvhdl[0][i] = 1;
11738  res->block1[0] = si_min(res->N, rVar(res));
11739  // new 2nd block
11740  res->order[1] = ringorder_C; // Prefix
11741  res->wvhdl[1] = NULL;
11742  // removes useless secondary component order if defined in old ring
11743  for (int i=rBlocks(res); i>1; --i)
11744  {
11745  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11746  {
11747  res->order[i] = (rRingOrder_t)0;
11748  }
11749  }
11750  rComplete(res, 1);
11751 #ifdef HAVE_PLURAL
11752  if (rIsPluralRing(r))
11753  {
11754  if ( nc_rComplete(r, res, false) ) // no qideal!
11755  {
11756 #ifndef SING_NDEBUG
11757  WarnS("error in nc_rComplete");
11758 #endif
11759  // cleanup?
11760 
11761  // rDelete(res);
11762  // return r;
11763 
11764  // just go on..
11765  }
11766  }
11767 #endif
11768  strat->tailRing = res;
11769  return (res);
11770  }
11771 
11772  // not sbaOrder == 1 => use Schreyer order
11773  // this is done by a trick when initializing the signatures
11774  // in initSLSba():
11775  // Instead of using the signature 1e_i for F->m[i], we start
11776  // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11777  // Schreyer order w.r.t. the underlying monomial order.
11778  // => we do not need to change the underlying polynomial ring at all!
11779 
11780  // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11781 
11782  /*
11783  else
11784  {
11785  ring res = rCopy0(r, FALSE, FALSE);
11786  // Create 2 more blocks for prefix/suffix:
11787  res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11788  res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11789  res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11790  int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11791 
11792  // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11793  // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11794 
11795  // new 1st block
11796  int j = 0;
11797  res->order[j] = ringorder_IS; // Prefix
11798  res->block0[j] = res->block1[j] = 0;
11799  // wvhdl[j] = NULL;
11800  j++;
11801 
11802  for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11803  {
11804  res->order [j] = r->order [i];
11805  res->block0[j] = r->block0[i];
11806  res->block1[j] = r->block1[i];
11807 
11808  if (r->wvhdl[i] != NULL)
11809  {
11810  wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11811  } // else wvhdl[j] = NULL;
11812  }
11813 
11814  // new last block
11815  res->order [j] = ringorder_IS; // Suffix
11816  res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11817  // wvhdl[j] = NULL;
11818  j++;
11819 
11820  // res->order [j] = 0; // The End!
11821  res->wvhdl = wvhdl;
11822 
11823  // j == the last zero block now!
11824  assume(j == (n+1));
11825  assume(res->order[0]==ringorder_IS);
11826  assume(res->order[j-1]==ringorder_IS);
11827  assume(res->order[j]==0);
11828 
11829  if (complete)
11830  {
11831  rComplete(res, 1);
11832 
11833 #ifdef HAVE_PLURAL
11834  if (rIsPluralRing(r))
11835  {
11836  if ( nc_rComplete(r, res, false) ) // no qideal!
11837  {
11838  }
11839  }
11840  assume(rIsPluralRing(r) == rIsPluralRing(res));
11841 #endif
11842 
11843 
11844 #ifdef HAVE_PLURAL
11845  ring old_ring = r;
11846 
11847 #endif
11848 
11849  if (r->qideal!=NULL)
11850  {
11851  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11852 
11853  assume(idRankFreeModule(res->qideal, res) == 0);
11854 
11855 #ifdef HAVE_PLURAL
11856  if( rIsPluralRing(res) )
11857  if( nc_SetupQuotient(res, r, true) )
11858  {
11859  // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11860  }
11861 
11862 #endif
11863  assume(idRankFreeModule(res->qideal, res) == 0);
11864  }
11865 
11866 #ifdef HAVE_PLURAL
11867  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11868  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11869  assume(rIsSCA(res) == rIsSCA(old_ring));
11870  assume(ncRingType(res) == ncRingType(old_ring));
11871 #endif
11872  }
11873  strat->tailRing = res;
11874  return res;
11875  }
11876  */
11877 
11878  assume(FALSE);
11879  return(NULL);
11880 }
11881 
11883 {
11884  memset(this, 0, sizeof(skStrategy));
11885  strat_nr++;
11886  nr=strat_nr;
11887  tailRing = currRing;
11888  P.tailRing = currRing;
11889  tl = -1;
11890  sl = -1;
11891 #ifdef HAVE_LM_BIN
11892  lmBin = omGetStickyBinOfBin(currRing->PolyBin);
11893 #endif
11894 #ifdef HAVE_TAIL_BIN
11895  tailBin = omGetStickyBinOfBin(currRing->PolyBin);
11896 #endif
11897  pOrigFDeg = currRing->pFDeg;
11898  pOrigLDeg = currRing->pLDeg;
11899 }
11900 
11901 
11903 {
11904  if (lmBin != NULL)
11906  if (tailBin != NULL)// && !rField_is_Ring(currRing))
11908  ((tailRing != NULL) ? tailRing->PolyBin:
11909  currRing->PolyBin));
11910  if (t_kHEdge != NULL)
11912  if (t_kNoether != NULL)
11914 
11915  if (currRing != tailRing)
11918 }
11919 
11920 #if 0
11921 Timings for the different possibilities of posInT:
11922  T15 EDL DL EL L 1-2-3
11923 Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11924 Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11925 Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11926 ahml 4.48 4.03 4.03 4.38 4.96 26.50
11927 c7 15.02 13.98 15.16 13.24 17.31 47.89
11928 c8 505.09 407.46 852.76 413.21 499.19 n/a
11929 f855 12.65 9.27 14.97 8.78 14.23 33.12
11930 gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11931 gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11932 ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11933 noon8 40.68 37.02 37.99 36.82 35.59 877.16
11934 rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11935 rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11936 schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11937 test016 16.39 14.17 14.40 13.50 14.26 34.07
11938 test017 34.70 36.01 33.16 35.48 32.75 71.45
11939 test042 10.76 10.99 10.27 11.57 10.45 23.04
11940 test058 6.78 6.75 6.51 6.95 6.22 9.47
11941 test066 10.71 10.94 10.76 10.61 10.56 19.06
11942 test073 10.75 11.11 10.17 10.79 8.63 58.10
11943 test086 12.23 11.81 12.88 12.24 13.37 66.68
11944 test103 5.05 4.80 5.47 4.64 4.89 11.90
11945 test154 12.96 11.64 13.51 12.46 14.61 36.35
11946 test162 65.27 64.01 67.35 59.79 67.54 196.46
11947 test164 7.50 6.50 7.68 6.70 7.96 17.13
11948 virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11949 #endif
11950 
11951 
11952 //#ifdef HAVE_MORE_POS_IN_T
11953 #if 1
11954 // determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11955 int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p)
11956 {
11957 
11958  if (length==-1) return 0;
11959 
11960  int o = p.ecart;
11961  int op=p.GetpFDeg();
11962  int ol = p.GetpLength();
11963 
11964  if (set[length].ecart < o)
11965  return length+1;
11966  if (set[length].ecart == o)
11967  {
11968  int oo=set[length].GetpFDeg();
11969  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11970  return length+1;
11971  }
11972 
11973  int i;
11974  int an = 0;
11975  int en= length;
11976  loop
11977  {
11978  if (an >= en-1)
11979  {
11980  if (set[an].ecart > o)
11981  return an;
11982  if (set[an].ecart == o)
11983  {
11984  int oo=set[an].GetpFDeg();
11985  if((oo > op)
11986  || ((oo==op) && (set[an].pLength > ol)))
11987  return an;
11988  }
11989  return en;
11990  }
11991  i=(an+en) / 2;
11992  if (set[i].ecart > o)
11993  en=i;
11994  else if (set[i].ecart == o)
11995  {
11996  int oo=set[i].GetpFDeg();
11997  if ((oo > op)
11998  || ((oo == op) && (set[i].pLength > ol)))
11999  en=i;
12000  else
12001  an=i;
12002  }
12003  else
12004  an=i;
12005  }
12006 }
12007 
12008 // determines the position based on: 1.) FDeg 2.) pLength
12009 int posInT_FDegpLength(const TSet set,const int length,LObject &p)
12010 {
12011 
12012  if (length==-1) return 0;
12013 
12014  int op=p.GetpFDeg();
12015  int ol = p.GetpLength();
12016 
12017  int oo=set[length].GetpFDeg();
12018  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
12019  return length+1;
12020 
12021  int i;
12022  int an = 0;
12023  int en= length;
12024  loop
12025  {
12026  if (an >= en-1)
12027  {
12028  int oo=set[an].GetpFDeg();
12029  if((oo > op)
12030  || ((oo==op) && (set[an].pLength > ol)))
12031  return an;
12032  return en;
12033  }
12034  i=(an+en) / 2;
12035  int oo=set[i].GetpFDeg();
12036  if ((oo > op)
12037  || ((oo == op) && (set[i].pLength > ol)))
12038  en=i;
12039  else
12040  an=i;
12041  }
12042 }
12043 
12044 
12045 // determines the position based on: 1.) pLength
12046 int posInT_pLength(const TSet set,const int length,LObject &p)
12047 {
12048  int ol = p.GetpLength();
12049  if (length==-1)
12050  return 0;
12051  if (set[length].length<p.length)
12052  return length+1;
12053 
12054  int i;
12055  int an = 0;
12056  int en= length;
12057 
12058  loop
12059  {
12060  if (an >= en-1)
12061  {
12062  if (set[an].pLength>ol) return an;
12063  return en;
12064  }
12065  i=(an+en) / 2;
12066  if (set[i].pLength>ol) en=i;
12067  else an=i;
12068  }
12069 }
12070 #endif
12071 
12072 // kstd1.cc:
12073 int redFirst (LObject* h,kStrategy strat);
12074 int redEcart (LObject* h,kStrategy strat);
12075 void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
12076 void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
12077 // ../Singular/misc.cc:
12078 extern char * showOption();
12079 
12081 {
12082  PrintS("red: ");
12083  if (strat->red==redFirst) PrintS("redFirst\n");
12084  else if (strat->red==redHoney) PrintS("redHoney\n");
12085  else if (strat->red==redEcart) PrintS("redEcart\n");
12086  else if (strat->red==redHomog) PrintS("redHomog\n");
12087  else if (strat->red==redLazy) PrintS("redLazy\n");
12088  else if (strat->red==redLiftstd) PrintS("redLiftstd\n");
12089  else Print("%p\n",(void*)strat->red);
12090  PrintS("posInT: ");
12091  if (strat->posInT==posInT0) PrintS("posInT0\n");
12092  else if (strat->posInT==posInT1) PrintS("posInT1\n");
12093  else if (strat->posInT==posInT11) PrintS("posInT11\n");
12094  else if (strat->posInT==posInT110) PrintS("posInT110\n");
12095  else if (strat->posInT==posInT13) PrintS("posInT13\n");
12096  else if (strat->posInT==posInT15) PrintS("posInT15\n");
12097  else if (strat->posInT==posInT17) PrintS("posInT17\n");
12098  else if (strat->posInT==posInT17_c) PrintS("posInT17_c\n");
12099  else if (strat->posInT==posInT19) PrintS("posInT19\n");
12100  else if (strat->posInT==posInT2) PrintS("posInT2\n");
12101  #ifdef HAVE_RINGS
12102  else if (strat->posInT==posInT11Ring) PrintS("posInT11Ring\n");
12103  else if (strat->posInT==posInT110Ring) PrintS("posInT110Ring\n");
12104  else if (strat->posInT==posInT15Ring) PrintS("posInT15Ring\n");
12105  else if (strat->posInT==posInT17Ring) PrintS("posInT17Ring\n");
12106  else if (strat->posInT==posInT17_cRing) PrintS("posInT17_cRing\n");
12107  #endif
12108 #ifdef HAVE_MORE_POS_IN_T
12109  else if (strat->posInT==posInT_EcartFDegpLength) PrintS("posInT_EcartFDegpLength\n");
12110  else if (strat->posInT==posInT_FDegpLength) PrintS("posInT_FDegpLength\n");
12111  else if (strat->posInT==posInT_pLength) PrintS("posInT_pLength\n");
12112 #endif
12113  else if (strat->posInT==posInT_EcartpLength) PrintS("posInT_EcartpLength\n");
12114  else if (strat->posInT==posInTrg0) PrintS("posInTrg0\n");
12115  else Print("%p\n",(void*)strat->posInT);
12116  PrintS("posInL: ");
12117  if (strat->posInL==posInL0) PrintS("posInL0\n");
12118  else if (strat->posInL==posInL10) PrintS("posInL10\n");
12119  else if (strat->posInL==posInL11) PrintS("posInL11\n");
12120  else if (strat->posInL==posInL110) PrintS("posInL110\n");
12121  else if (strat->posInL==posInL13) PrintS("posInL13\n");
12122  else if (strat->posInL==posInL15) PrintS("posInL15\n");
12123  else if (strat->posInL==posInL17) PrintS("posInL17\n");
12124  else if (strat->posInL==posInL17_c) PrintS("posInL17_c\n");
12125  #ifdef HAVE_RINGS
12126  else if (strat->posInL==posInL0) PrintS("posInL0Ring\n");
12127  else if (strat->posInL==posInL11Ring) PrintS("posInL11Ring\n");
12128  else if (strat->posInL==posInL11Ringls) PrintS("posInL11Ringls\n");
12129  else if (strat->posInL==posInL110Ring) PrintS("posInL110Ring\n");
12130  else if (strat->posInL==posInL15Ring) PrintS("posInL15Ring\n");
12131  else if (strat->posInL==posInL17Ring) PrintS("posInL17Ring\n");
12132  else if (strat->posInL==posInL17_cRing) PrintS("posInL17_cRing\n");
12133  #endif
12134  else if (strat->posInL==posInLSpecial) PrintS("posInLSpecial\n");
12135  else if (strat->posInL==posInLrg0) PrintS("posInLrg0\n");
12136  else Print("%p\n",(void*)strat->posInL);
12137  PrintS("enterS: ");
12138  if (strat->enterS==enterSBba) PrintS("enterSBba\n");
12139  else if (strat->enterS==enterSMora) PrintS("enterSMora\n");
12140  else if (strat->enterS==enterSMoraNF) PrintS("enterSMoraNF\n");
12141  else Print("%p\n",(void*)strat->enterS);
12142  PrintS("initEcart: ");
12143  if (strat->initEcart==initEcartBBA) PrintS("initEcartBBA\n");
12144  else if (strat->initEcart==initEcartNormal) PrintS("initEcartNormal\n");
12145  else Print("%p\n",(void*)strat->initEcart);
12146  PrintS("initEcartPair: ");
12147  if (strat->initEcartPair==initEcartPairBba) PrintS("initEcartPairBba\n");
12148  else if (strat->initEcartPair==initEcartPairMora) PrintS("initEcartPairMora\n");
12149  else Print("%p\n",(void*)strat->initEcartPair);
12150  Print("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
12151  strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
12152  Print("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
12153  strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
12154  PrintS("chainCrit: ");
12155  if (strat->chainCrit==chainCritNormal) PrintS("chainCritNormal\n");
12156  else if (strat->chainCrit==chainCritOpt_1) PrintS("chainCritOpt_1\n");
12157  else Print("%p\n",(void*)strat->chainCrit);
12158  Print("posInLDependsOnLength=%d\n",
12159  strat->posInLDependsOnLength);
12160  PrintS(showOption());PrintLn();
12161  PrintS("LDeg: ");
12162  if (currRing->pLDeg==pLDeg0) PrintS("pLDeg0");
12163  else if (currRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
12164  else if (currRing->pLDeg==pLDegb) PrintS("pLDegb");
12165  else if (currRing->pLDeg==pLDeg1) PrintS("pLDeg1");
12166  else if (currRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
12167  else if (currRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
12168  else if (currRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
12169  else if (currRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
12170  else if (currRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
12171  else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
12172  else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
12173  else if (currRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
12174  else Print("? (%lx)", (long)currRing->pLDeg);
12175  PrintS(" / ");
12176  if (strat->tailRing->pLDeg==pLDeg0) PrintS("pLDeg0");
12177  else if (strat->tailRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
12178  else if (strat->tailRing->pLDeg==pLDegb) PrintS("pLDegb");
12179  else if (strat->tailRing->pLDeg==pLDeg1) PrintS("pLDeg1");
12180  else if (strat->tailRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
12181  else if (strat->tailRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
12182  else if (strat->tailRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
12183  else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
12184  else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
12185  else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
12186  else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
12187  else if (strat->tailRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
12188  else Print("? (%lx)", (long)strat->tailRing->pLDeg);
12189  PrintLn();
12190  PrintS("currRing->pFDeg: ");
12191  if (currRing->pFDeg==p_Totaldegree) PrintS("p_Totaldegree");
12192  else if (currRing->pFDeg==p_WFirstTotalDegree) PrintS("pWFirstTotalDegree");
12193  else if (currRing->pFDeg==p_Deg) PrintS("p_Deg");
12194  else if (currRing->pFDeg==kHomModDeg) PrintS("kHomModDeg");
12195  else if (currRing->pFDeg==totaldegreeWecart) PrintS("totaldegreeWecart");
12196  else if (currRing->pFDeg==p_WTotaldegree) PrintS("p_WTotaldegree");
12197  else Print("? (%lx)", (long)currRing->pFDeg);
12198  PrintLn();
12199  Print(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
12200  if(TEST_OPT_DEGBOUND)
12201  Print(" degBound: %d\n", Kstd1_deg);
12202 
12203  if( ecartWeights != NULL )
12204  {
12205  PrintS("ecartWeights: ");
12206  for (int i = rVar(currRing); i > 0; i--)
12207  Print("%hd ", ecartWeights[i]);
12208  PrintLn();
12210  }
12211 
12212 #ifndef SING_NDEBUG
12214 #endif
12215 }
12216 
12217 #ifdef HAVE_SHIFTBBA
12218 poly pMove2CurrTail(poly p, kStrategy strat)
12219 {
12220  /* assume: p is completely in currRing */
12221  /* produces an object with LM in curring
12222  and TAIL in tailring */
12223  if (pNext(p)!=NULL)
12224  {
12225  pNext(p) = prMoveR(pNext(p), /* src */ currRing, /* dest */ strat->tailRing);
12226  }
12227  return(p);
12228 }
12229 #endif
12230 
12231 #ifdef HAVE_SHIFTBBA
12232 poly pMoveCurrTail2poly(poly p, kStrategy strat)
12233 {
12234  /* assume: p has LM in curring and TAIL in tailring */
12235  /* convert it to complete currRing */
12236 
12237  /* check that LM is in currRing */
12239 
12240  if (pNext(p)!=NULL)
12241  {
12242  pNext(p) = prMoveR(pNext(p), /* src */ strat->tailRing, /* dest */currRing);
12243  }
12244  return(p);
12245 }
12246 #endif
12247 
12248 #ifdef HAVE_SHIFTBBA
12250 {
12251  /* restores a poly in currRing from LObject */
12252  LObject h = H;
12253  h.Copy();
12254  poly p;
12255  if (h.p == NULL)
12256  {
12257  if (h.t_p != NULL)
12258  {
12259  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing, /* dest. ring: */ currRing);
12260  return(p);
12261  }
12262  else
12263  {
12264  /* h.tp == NULL -> the object is NULL */
12265  return(NULL);
12266  }
12267  }
12268  /* we're here if h.p != NULL */
12269  if (h.t_p == NULL)
12270  {
12271  /* then h.p is the whole poly in currRing */
12272  p = h.p;
12273  return(p);
12274  }
12275  /* we're here if h.p != NULL and h.t_p != NULL */
12276  // clean h.p, get poly from t_p
12277  pNext(h.p)=NULL;
12278  pLmDelete(&h.p);
12279  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing,
12280  /* dest. ring: */ currRing);
12281  // no need to clean h: we re-used the polys
12282  return(p);
12283 }
12284 #endif
12285 
12286 //LObject pCopyp2L(poly p, kStrategy strat)
12287 //{
12288  /* creates LObject from the poly in currRing */
12289  /* actually put p into L.p and make L.t_p=NULL : does not work */
12290 
12291 //}
12292 
12293 // poly pCopyL2p(LObject H, kStrategy strat)
12294 // {
12295 // /* restores a poly in currRing from LObject */
12296 // LObject h = H;
12297 // h.Copy();
12298 // poly p;
12299 // if (h.p == NULL)
12300 // {
12301 // if (h.t_p != NULL)
12302 // {
12303 // p = p_ShallowCopyDelete(h.t_p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12304 // return(p);
12305 // }
12306 // else
12307 // {
12308 // /* h.tp == NULL -> the object is NULL */
12309 // return(NULL);
12310 // }
12311 // }
12312 // /* we're here if h.p != NULL */
12313 
12314 // if (h.t_p == NULL)
12315 // {
12316 // /* then h.p is the whole poly in tailRing */
12317 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12318 // {
12319 // p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12320 // }
12321 // return(p);
12322 // }
12323 // /* we're here if h.p != NULL and h.t_p != NULL */
12324 // p = pCopy(pHead(h.p)); // in currRing
12325 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12326 // {
12327 // // pNext(p) = p_ShallowCopyDelete(pNext(h.t_p), (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12328 // poly pp = p_Copy(pNext(h.p), strat->tailRing);
12329 // // poly p3 = p_Copy(pNext(h.p), currRing); // error
12330 // // p_ShallowCopyDelete(pNext(h.p), currRing, strat->tailBin); // the same as pp
12331 // poly p5 = p_ShallowCopyDelete(pNext(h.p), strat->tailRing, strat->tailBin);
12332 // pNext(p) = p_ShallowCopyDelete(h.t_p, strat->tailRing, strat->tailBin);
12333 // poly p4 = p_Copy(h.t_p, strat->tailRing);
12334 // // if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
12335 // }
12336 // // pTest(p);
12337 // return(p);
12338 // }
12339 
12340 /*2
12341 * put the lcm(q,p) into the set B, q is the shift of some s[i]
12342 */
12343 #ifdef HAVE_SHIFTBBA
12344 static BOOLEAN enterOneStrongPolyShift (poly q, poly p, int /*ecart*/, int /*isFromQ*/, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
12345 {
12346  number d, s, t;
12347  /* assume(atR >= 0); */
12348  assume(ifromS <= strat->sl);
12350  poly m1, m2, gcd;
12351  //printf("\n--------------------------------\n");
12352  //pWrite(p);pWrite(si);
12353  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q), &s, &t, currRing->cf);
12354 
12355  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
12356  {
12357  nDelete(&d);
12358  nDelete(&s);
12359  nDelete(&t);
12360  return FALSE;
12361  }
12362 
12363  assume(pIsInV(p));
12364 
12365  k_GetStrongLeadTerms(p, q, currRing, m1, m2, gcd, strat->tailRing);
12366 
12367  /* the V criterion */
12368  if (!pmIsInV(gcd))
12369  {
12370  strat->cv++;
12371  nDelete(&d);
12372  nDelete(&s);
12373  nDelete(&t);
12374  pLmFree(gcd);
12375  return FALSE;
12376  }
12377 
12378  // disabled for Letterplace because it is not so easy to check
12379  /* if (!rHasLocalOrMixedOrdering(currRing)) { */
12380  /* unsigned long sev = pGetShortExpVector(gcd); */
12381 
12382  /* for (int j = 0; j < strat->sl; j++) { */
12383  /* if (j == i) */
12384  /* continue; */
12385 
12386  /* if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) && */
12387  /* !(strat->sevS[j] & ~sev) && */
12388  /* p_LmDivisibleBy(strat->S[j], gcd, currRing)) { */
12389  /* nDelete(&d); */
12390  /* nDelete(&s); */
12391  /* nDelete(&t); */
12392  /* return FALSE; */
12393  /* } */
12394  /* } */
12395  /* } */
12396 
12397  poly m12, m22;
12398  assume(p_mFirstVblock(p, currRing) <= 1 || p_mFirstVblock(q, currRing) <= 1);
12400  k_SplitFrame(m2, m22, si_max(p_mFirstVblock(q, currRing), 1), currRing);
12401  // manually free the coeffs, because pSetCoeff0 is used in the next step
12402  n_Delete(&(m1->coef), currRing->cf);
12403  n_Delete(&(m2->coef), currRing->cf);
12404 
12405  //p_Test(m1,strat->tailRing);
12406  //p_Test(m2,strat->tailRing);
12407  /*if(!enterTstrong)
12408  {
12409  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
12410  {
12411  memset(&(strat->P), 0, sizeof(strat->P));
12412  kStratChangeTailRing(strat);
12413  strat->P = *(strat->R[atR]);
12414  p_LmFree(m1, strat->tailRing);
12415  p_LmFree(m2, strat->tailRing);
12416  p_LmFree(gcd, currRing);
12417  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
12418  }
12419  }*/
12420  pSetCoeff0(m1, s);
12421  pSetCoeff0(m2, t);
12422  pSetCoeff0(gcd, d);
12423  p_Test(m1,strat->tailRing);
12424  p_Test(m2,strat->tailRing);
12425  p_Test(m12,strat->tailRing);
12426  p_Test(m22,strat->tailRing);
12427  assume(pmIsInV(m1));
12428  assume(pmIsInV(m2));
12429  assume(pmIsInV(m12));
12430  assume(pmIsInV(m22));
12431  //printf("\n===================================\n");
12432  //pWrite(m1);pWrite(m2);pWrite(gcd);
12433 #ifdef KDEBUG
12434  if (TEST_OPT_DEBUG)
12435  {
12436  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
12437  PrintS("m1 = ");
12438  p_wrp(m1, strat->tailRing);
12439  PrintS("m12 = ");
12440  p_wrp(m12, strat->tailRing);
12441  PrintS(" ; m2 = ");
12442  p_wrp(m2, strat->tailRing);
12443  PrintS(" ; m22 = ");
12444  p_wrp(m22, strat->tailRing);
12445  PrintS(" ; gcd = ");
12446  wrp(gcd);
12447  PrintS("\n--- create strong gcd poly: ");
12448  PrintS("\n p: ");
12449  wrp(p);
12450  Print("\n q (strat->S[%d]): ", ifromS);
12451  wrp(q);
12452  PrintS(" ---> ");
12453  }
12454 #endif
12455 
12456  pNext(gcd) = p_Add_q(pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing), pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing), strat->tailRing);
12457  p_LmDelete(m1, strat->tailRing);
12458  p_LmDelete(m2, strat->tailRing);
12459  p_LmDelete(m12, strat->tailRing);
12460  p_LmDelete(m22, strat->tailRing);
12461 
12462  assume(pIsInV(gcd));
12463 
12464 #ifdef KDEBUG
12465  if (TEST_OPT_DEBUG)
12466  {
12467  wrp(gcd);
12468  PrintLn();
12469  }
12470 #endif
12471 
12472  LObject h;
12473  h.p = gcd;
12474  h.tailRing = strat->tailRing;
12475  int posx;
12476  h.pCleardenom();
12477  strat->initEcart(&h);
12478  h.sev = pGetShortExpVector(h.p);
12479  h.i_r1 = -1;h.i_r2 = -1;
12480  if (currRing!=strat->tailRing)
12481  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12482 #if 1
12483  h.p1 = p;
12484  h.p2 = q;
12485 #endif
12486  if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12487  {
12488  h.i_r2 = kFindInT(h.p1, strat);
12489  h.i_r1 = atR;
12490  }
12491  else
12492  {
12493  h.i_r1 = -1;
12494  h.i_r2 = -1;
12495  }
12496  if (strat->Ll==-1)
12497  posx =0;
12498  else
12499  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
12500 
12501  assume(pIsInV(h.p));
12502  assume(pIsInV(h.p1));
12503 
12504  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
12505  return TRUE;
12506 }
12507 #endif
12508 
12509 
12510 /*2
12511 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i] (ring case)
12512 */
12513 #ifdef HAVE_SHIFTBBA
12514 static void enterOnePairRingShift (poly q, poly p, int /*ecart*/, int isFromQ, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
12515 {
12516  /* assume(atR >= 0); */
12517  /* assume(i<=strat->sl); */
12518  assume(p!=NULL);
12520  assume(pIsInV(p));
12521  #if ALL_VS_JUST
12522  //Over rings, if we construct the strong pair, do not add the spair
12524  {
12525  number s,t,d;
12526  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q, &s, &t, currRing->cf);
12527 
12528  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
12529  {
12530  nDelete(&d);
12531  nDelete(&s);
12532  nDelete(&t);
12533  return;
12534  }
12535  nDelete(&d);
12536  nDelete(&s);
12537  nDelete(&t);
12538  }
12539  #endif
12540  int j,compare,compareCoeff;
12541  LObject h;
12542 
12543 #ifdef KDEBUG
12544  h.ecart=0; h.length=0;
12545 #endif
12546  /*- computes the lcm(s[i],p) -*/
12547  if(pHasNotCFRing(p,q))
12548  {
12549  strat->cp++;
12550  return;
12551  }
12552  h.lcm = p_Lcm(p,q,currRing);
12553  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(q), currRing->cf));
12554  if (nIsZero(pGetCoeff(h.lcm)))
12555  {
12556  strat->cp++;
12557  pLmDelete(h.lcm);
12558  return;
12559  }
12560 
12561  /* the V criterion */
12562  if (!pmIsInV(h.lcm))
12563  {
12564  strat->cv++;
12565  pLmDelete(h.lcm);
12566  return;
12567  }
12568  // basic chain criterion
12569  /*
12570  *the set B collects the pairs of type (S[j],p)
12571  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
12572  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12573  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12574  */
12575 
12576  for(j = strat->Bl;j>=0;j--)
12577  {
12578  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
12579  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
12580  if(compare == pDivComp_EQUAL)
12581  {
12582  //They have the same LM
12583  if(compareCoeff == pDivComp_LESS)
12584  {
12585  if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12586  {
12587  strat->c3++;
12588  pLmDelete(h.lcm);
12589  return;
12590  }
12591  break;
12592  }
12593  if(compareCoeff == pDivComp_GREATER)
12594  {
12595  deleteInL(strat->B,&strat->Bl,j,strat);
12596  strat->c3++;
12597  }
12598  if(compareCoeff == pDivComp_EQUAL)
12599  {
12600  if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12601  {
12602  strat->c3++;
12603  pLmDelete(h.lcm);
12604  return;
12605  }
12606  break;
12607  }
12608  }
12609  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
12610  {
12611  if(compare == pDivComp_LESS)
12612  {
12613  if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12614  {
12615  strat->c3++;
12616  pLmDelete(h.lcm);
12617  return;
12618  }
12619  break;
12620  }
12621  if(compare == pDivComp_GREATER)
12622  {
12623  deleteInL(strat->B,&strat->Bl,j,strat);
12624  strat->c3++;
12625  }
12626  }
12627  }
12628  number s, t;
12629  poly m1, m2, gcd = NULL;
12630  s = pGetCoeff(q);
12631  t = pGetCoeff(p);
12632  k_GetLeadTerms(p,q,currRing,m1,m2,currRing);
12633 
12634  poly m12, m22;
12635  assume(p_mFirstVblock(p, currRing) <= 1 || p_mFirstVblock(q, currRing) <= 1);
12637  k_SplitFrame(m2, m22, si_max(p_mFirstVblock(q, currRing), 1), currRing);
12638  // manually free the coeffs, because pSetCoeff0 is used in the next step
12639  n_Delete(&(m1->coef), currRing->cf);
12640  n_Delete(&(m2->coef), currRing->cf);
12641 
12642  ksCheckCoeff(&s, &t, currRing->cf);
12643  pSetCoeff0(m1, s);
12644  pSetCoeff0(m2, t);
12645  m2 = pNeg(m2);
12646  p_Test(m1,strat->tailRing);
12647  p_Test(m2,strat->tailRing);
12648  p_Test(m12,strat->tailRing);
12649  p_Test(m22,strat->tailRing);
12650  assume(pmIsInV(m1));
12651  assume(pmIsInV(m2));
12652  assume(pmIsInV(m12));
12653  assume(pmIsInV(m22));
12654  poly pm1 = pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing);
12655  poly sim2 = pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing);
12656  assume(pIsInV(pm1));
12657  assume(pIsInV(sim2));
12658  p_LmDelete(m1, currRing);
12659  p_LmDelete(m2, currRing);
12660  p_LmDelete(m12, currRing);
12661  p_LmDelete(m22, currRing);
12662  if(sim2 == NULL)
12663  {
12664  if(pm1 == NULL)
12665  {
12666  if(h.lcm != NULL)
12667  {
12668  pLmDelete(h.lcm);
12669  h.lcm=NULL;
12670  }
12671  h.Clear();
12672  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12673  /* if (strat->pairtest==NULL) initPairtest(strat); */
12674  /* strat->pairtest[i] = TRUE; */
12675  /* strat->pairtest[strat->sl+1] = TRUE; */
12676  return;
12677  }
12678  else
12679  {
12680  gcd = pm1;
12681  pm1 = NULL;
12682  }
12683  }
12684  else
12685  {
12686  if((pGetComp(q) == 0) && (0 != pGetComp(p)))
12687  {
12688  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
12689  pSetmComp(sim2);
12690  }
12691  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
12692  gcd = p_Add_q(pm1, sim2, strat->tailRing);
12693  }
12694  p_Test(gcd, strat->tailRing);
12695  assume(pIsInV(gcd));
12696 #ifdef KDEBUG
12697  if (TEST_OPT_DEBUG)
12698  {
12699  wrp(gcd);
12700  PrintLn();
12701  }
12702 #endif
12703  h.p = gcd;
12704  h.i_r = -1;
12705  if(h.p == NULL)
12706  {
12707  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12708  /* if (strat->pairtest==NULL) initPairtest(strat); */
12709  /* strat->pairtest[i] = TRUE; */
12710  /* strat->pairtest[strat->sl+1] = TRUE; */
12711  return;
12712  }
12713  h.tailRing = strat->tailRing;
12714  int posx;
12715  //h.pCleardenom();
12716  //pSetm(h.p);
12717  h.i_r1 = -1;h.i_r2 = -1;
12718  strat->initEcart(&h);
12719  #if 1
12720  h.p1 = p;
12721  h.p2 = q;
12722  #endif
12723  #if 1
12724  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12725  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12726  if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12727  {
12728  h.i_r2 = kFindInT(h.p1, strat); //strat->S_2_R[i];
12729  h.i_r1 = atR;
12730  }
12731  else
12732  {
12733  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12734  h.i_r1 = -1;
12735  h.i_r2 = -1;
12736  }
12737  #endif
12738  if (strat->Bl==-1)
12739  posx =0;
12740  else
12741  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
12742  h.sev = pGetShortExpVector(h.p);
12743  if (currRing!=strat->tailRing)
12744  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12745 
12746  assume(pIsInV(h.p));
12747  assume(pIsInV(h.p1));
12748  assume(h.lcm != NULL);
12749  assume(pIsInV(h.lcm));
12750 
12751  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
12752  kTest_TS(strat);
12753 }
12754 #endif
12755 
12756 #ifdef HAVE_SHIFTBBA
12757 // adds the strong pair and the normal pair for rings (aka gpoly and spoly)
12758 static void enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12759 {
12760  enterOneStrongPolyShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "gpoly"
12761  enterOnePairRingShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "spoly"
12762 }
12763 #endif
12764 
12765 #ifdef HAVE_SHIFTBBA
12766 // creates if possible (q,p), (shifts(q),p)
12767 static void enterOnePairWithShifts (int q_inS /*also i*/, poly q, poly p, int ecartp, int p_isFromQ, kStrategy strat, int atR, int p_lastVblock, int q_lastVblock)
12768 {
12769  // note: ecart and isFromQ is for p
12770  assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12771  assume(pmFirstVblock(p) == 1);
12772  assume(pmFirstVblock(q) == 1);
12773  assume(p_lastVblock == pmLastVblock(p));
12774  assume(q_lastVblock == pmLastVblock(q));
12775 
12776  // TODO: is ecartq = 0 still ok?
12777  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12778 
12779  int q_isFromQ = 0;
12780  if (strat->fromQ != NULL && q_inS >= 0)
12781  q_isFromQ = strat->fromQ[q_inS];
12782 
12783  void (*enterPair)(poly, poly, int, int, kStrategy, int, int, int, int, int);
12784 #ifdef HAVE_RINGS
12785  if (rField_is_Ring(currRing))
12787  else
12788 #endif
12789  enterPair = enterOnePairShift;
12790 
12791  int degbound = currRing->N/currRing->isLPring;
12792  int neededShift = p_lastVblock - ((pGetComp(p) > 0 || pGetComp(q) > 0) ? 0 : 1); // in the module case, product criterion does not hold
12793  int maxPossibleShift = degbound - q_lastVblock;
12794  int maxShift = si_min(neededShift, maxPossibleShift);
12795  int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12796  for (int j = firstShift; j <= maxShift; j++)
12797  {
12798  poly qq = pLPCopyAndShiftLM(q, j);
12799  enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS);
12800  }
12801 
12802 #ifdef HAVE_RINGS
12803  if (rField_is_Ring(currRing) && p_lastVblock >= firstShift && p_lastVblock <= maxPossibleShift)
12804  {
12805  // add pairs (m*shifts(q), p) where m is a monomial and the pair has no overlap
12806  for (int j = p_lastVblock; j <= maxPossibleShift; j++)
12807  {
12808  ideal fillers = id_MaxIdeal(j - p_lastVblock, currRing);
12809  for (int k = 0; k < IDELEMS(fillers); k++)
12810  {
12811  poly qq = pLPCopyAndShiftLM(pp_mm_Mult(q, fillers->m[k], currRing), p_lastVblock);
12812  enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, p_lastVblock, q_inS);
12813  }
12814  idDelete(&fillers);
12815  }
12816  }
12817 #endif
12818 }
12819 #endif
12820 
12821 #ifdef HAVE_SHIFTBBA
12822 // creates (q,p), use it when q is already shifted
12823 static void enterOnePairWithoutShifts (int p_inS /*also i*/, poly q, poly p, int ecartq, int q_isFromQ, kStrategy strat, int atR, int p_lastVblock, int q_shift)
12824 {
12825  // note: ecart and isFromQ is for p
12826  assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12827  assume(pmFirstVblock(p) == 1);
12828  assume(p_lastVblock == pmLastVblock(p));
12829  assume(q_shift == pmFirstVblock(q) - 1);
12830 
12831  // TODO: is ecartp = 0 still ok?
12832  int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12833 
12834  int p_isFromQ = 0;
12835  if (strat->fromQ != NULL && p_inS >= 0)
12836  p_isFromQ = strat->fromQ[p_inS];
12837 
12838 #ifdef HAVE_RINGS
12839  if (rField_is_Ring(currRing))
12840  {
12841  assume(q_shift <= p_lastVblock); // we allow the special case where there is no overlap
12842  enterOneStrongPolyAndEnterOnePairRingShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12843  }
12844  else
12845 #endif
12846  {
12847  assume(q_shift <= p_lastVblock - ((pGetComp(q) > 0 || pGetComp(p) > 0) ? 0 : 1)); // there should be an overlap (in the module case epsilon overlap is also allowed)
12848  enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12849  }
12850 }
12851 #endif
12852 
12853 
12854 #ifdef KDEBUG
12855 // enable to print which pairs are considered or discarded and why
12856 /* #define CRITERION_DEBUG */
12857 #endif
12858 /*2
12859 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12860 */
12861 #ifdef HAVE_SHIFTBBA
12862 void enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12863 {
12864 #ifdef CRITERION_DEBUG
12865  if (TEST_OPT_DEBUG)
12866  {
12867  PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12868  // also write the LMs in separate lines:
12869  poly lmq = pHead(q);
12870  poly lmp = pHead(p);
12871  pSetCoeff(lmq, n_Init(1, currRing->cf));
12872  pSetCoeff(lmp, n_Init(1, currRing->cf));
12873  Print(" %s\n", pString(lmq));
12874  Print(" %s\n", pString(lmp));
12875  pLmDelete(lmq);
12876  pLmDelete(lmp);
12877  }
12878 #endif
12879 
12880  /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12881 
12882  /* check this Formats: */
12884  assume(p_CheckIsFromRing(pNext(q),strat->tailRing));
12887 
12888  /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12889 
12890  int qfromQ = qisFromQ;
12891 
12892  /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12893 
12894  int l,j,compare;
12895  LObject Lp;
12896  Lp.i_r = -1;
12897 
12898 #ifdef KDEBUG
12899  Lp.ecart=0; Lp.length=0;
12900 #endif
12901  /*- computes the lcm(s[i],p) -*/
12902  Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12903 
12904  /* the V criterion */
12905  if (!pmIsInV(Lp.lcm))
12906  {
12907  strat->cv++; // counter for applying the V criterion
12908  pLmFree(Lp.lcm);
12909 #ifdef CRITERION_DEBUG
12910  if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12911 #endif
12912  return;
12913  }
12914 
12915  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12916  {
12917  if((!((ecartq>0)&&(ecart>0)))
12918  && pHasNotCF(p,q))
12919  {
12920  /*
12921  *the product criterion has applied for (s,p),
12922  *i.e. lcm(s,p)=product of the leading terms of s and p.
12923  *Suppose (s,r) is in L and the leading term
12924  *of p divides lcm(s,r)
12925  *(==> the leading term of p divides the leading term of r)
12926  *but the leading term of s does not divide the leading term of r
12927  *(notice that this condition is automatically satisfied if r is still
12928  *in S), then (s,r) can be cancelled.
12929  *This should be done here because the
12930  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12931  *
12932  *Moreover, skipping (s,r) holds also for the noncommutative case.
12933  */
12934  strat->cp++;
12935  pLmFree(Lp.lcm);
12936 #ifdef CRITERION_DEBUG
12937  if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12938 #endif
12939  return;
12940  }
12941  else
12942  Lp.ecart = si_max(ecart,ecartq);
12943  if (strat->fromT && (ecartq>ecart))
12944  {
12945  pLmFree(Lp.lcm);
12946 #ifdef CRITERION_DEBUG
12947  if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12948 #endif
12949  return;
12950  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12951  }
12952  /*
12953  *the set B collects the pairs of type (S[j],p)
12954  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12955  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12956  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12957  */
12958  {
12959  j = strat->Bl;
12960  loop
12961  {
12962  if (j < 0) break;
12963  compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12964  if ((compare==1)
12965  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12966  {
12967  strat->c3++;
12968  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12969  {
12970  pLmFree(Lp.lcm);
12971 #ifdef CRITERION_DEBUG
12972  if (TEST_OPT_DEBUG)
12973  {
12974  Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12975  }
12976 #endif
12977  return;
12978  }
12979  break;
12980  }
12981  else
12982  if ((compare ==-1)
12983  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12984  {
12985 #ifdef CRITERION_DEBUG
12986  if (TEST_OPT_DEBUG)
12987  {
12988  Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12989  }
12990 #endif
12991  deleteInL(strat->B,&strat->Bl,j,strat);
12992  strat->c3++;
12993  }
12994  j--;
12995  }
12996  }
12997  }
12998  else /*sugarcrit*/
12999  {
13000  if (ALLOW_PROD_CRIT(strat))
13001  {
13002  // if currRing->nc_type!=quasi (or skew)
13003  // TODO: enable productCrit for super commutative algebras...
13004  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
13005  pHasNotCF(p,q))
13006  {
13007  /*
13008  *the product criterion has applied for (s,p),
13009  *i.e. lcm(s,p)=product of the leading terms of s and p.
13010  *Suppose (s,r) is in L and the leading term
13011  *of p divides lcm(s,r)
13012  *(==> the leading term of p divides the leading term of r)
13013  *but the leading term of s does not divide the leading term of r
13014  *(notice that tis condition is automatically satisfied if r is still
13015  *in S), then (s,r) can be canceled.
13016  *This should be done here because the
13017  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
13018  */
13019  strat->cp++;
13020  pLmFree(Lp.lcm);
13021 #ifdef CRITERION_DEBUG
13022  if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
13023 #endif
13024  return;
13025  }
13026  if (strat->fromT && (ecartq>ecart))
13027  {
13028  pLmFree(Lp.lcm);
13029 #ifdef CRITERION_DEBUG
13030  if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
13031 #endif
13032  return;
13033  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
13034  }
13035  /*
13036  *the set B collects the pairs of type (S[j],p)
13037  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
13038  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
13039  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
13040  */
13041  for(j = strat->Bl;j>=0;j--)
13042  {
13043  compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
13044  if (compare==1)
13045  {
13046  strat->c3++;
13047  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
13048  {
13049  pLmFree(Lp.lcm);
13050 #ifdef CRITERION_DEBUG
13051  if (TEST_OPT_DEBUG)
13052  {
13053  Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
13054  }
13055 #endif
13056  return;
13057  }
13058  break;
13059  }
13060  else
13061  if (compare ==-1)
13062  {
13063 #ifdef CRITERION_DEBUG
13064  if (TEST_OPT_DEBUG)
13065  {
13066  Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
13067  }
13068 #endif
13069  deleteInL(strat->B,&strat->Bl,j,strat);
13070  strat->c3++;
13071  }
13072  }
13073  }
13074  }
13075  /*
13076  *the pair (S[i],p) enters B if the spoly != 0
13077  */
13078  /*- compute the short s-polynomial -*/
13079  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
13080  pNorm(p);
13081  if ((q==NULL) || (p==NULL))
13082  {
13083 #ifdef CRITERION_DEBUG
13084  if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
13085 #endif
13086  return;
13087  }
13088  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
13089  {
13090  Lp.p=NULL;
13091 #ifdef CRITERION_DEBUG
13092  if (TEST_OPT_DEBUG) PrintS("--- pair is from Q\n");
13093 #endif
13094  }
13095  else
13096  {
13097 // if ( rIsPluralRing(currRing) )
13098 // {
13099 // if(pHasNotCF(p, q))
13100 // {
13101 // if(ncRingType(currRing) == nc_lie)
13102 // {
13103 // // generalized prod-crit for lie-type
13104 // strat->cp++;
13105 // Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
13106 // }
13107 // else
13108 // if( ALLOW_PROD_CRIT(strat) )
13109 // {
13110 // // product criterion for homogeneous case in SCA
13111 // strat->cp++;
13112 // Lp.p = NULL;
13113 // }
13114 // else
13115 // Lp.p = nc_CreateSpoly(q,p,currRing); // ?
13116 // }
13117 // else Lp.p = nc_CreateSpoly(q,p,currRing);
13118 // }
13119 // else
13120 // {
13121 
13122  /* ksCreateShortSpoly needs two Lobject-kind presentations */
13123  /* p is already in this form, so convert q */
13124  // q = pMove2CurrTail(q, strat);
13125  Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
13126  // }
13127  }
13128  if (Lp.p == NULL)
13129  {
13130  /*- the case that the s-poly is 0 -*/
13131  // TODO: currently ifromS is only > 0 if called from enterOnePairWithShifts
13132  if (ifromS > 0)
13133  {
13134  if (strat->pairtest==NULL) initPairtest(strat);
13135  strat->pairtest[ifromS] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
13136  strat->pairtest[strat->sl+1] = TRUE;
13137  }
13138  //if (TEST_OPT_DEBUG){Print("!");} // option teach
13139  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
13140  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
13141  /*
13142  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
13143  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
13144  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
13145  *term of p divides the lcm(s,r)
13146  *(this canceling should be done here because
13147  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
13148  *the first case is handeled in chainCrit
13149  */
13150  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
13151 #ifdef CRITERION_DEBUG
13152  if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
13153 #endif
13154  }
13155  else
13156  {
13157  /*- the pair (S[i],p) enters B -*/
13158  /* both of them should have their LM in currRing and TAIL in tailring */
13159  Lp.p1 = q; // already in the needed form
13160  Lp.p2 = p; // already in the needed form
13161 
13162  if ( !rIsPluralRing(currRing) )
13163  pNext(Lp.p) = strat->tail;
13164 
13165  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
13166  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
13167  if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
13168  {
13169  Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
13170  Lp.i_r2 = atR;
13171  }
13172  else
13173  {
13174  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
13175  Lp.i_r1 = -1;
13176  Lp.i_r2 = -1;
13177  }
13178  strat->initEcartPair(&Lp,q,p,ecartq,ecart);
13179 
13181  {
13182  if (!rIsPluralRing(currRing)
13184  && (Lp.p->coef!=NULL))
13185  nDelete(&(Lp.p->coef));
13186  }
13187 
13188  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
13189  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
13190 #ifdef CRITERION_DEBUG
13191  if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
13192 #endif
13193  }
13194 }
13195 #endif
13196 
13197 /*3
13198 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
13199 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
13200 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
13201 */
13202 #ifdef HAVE_SHIFTBBA
13203 void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
13204 {
13205  int h_lastVblock = pmLastVblock(h);
13206  assume(h_lastVblock != 0 || pLmIsConstantComp(h));
13207  // TODO: is it allowed to skip pairs with constants? also with constants from other components?
13208  if (h_lastVblock == 0) return;
13209  assume(pmFirstVblock(h) == 1);
13210  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13211  // atR = -1;
13212  if ((strat->syzComp==0)
13213  || (pGetComp(h)<=strat->syzComp))
13214  {
13215  int i,j;
13216  BOOLEAN new_pair=FALSE;
13217 
13218  int degbound = currRing->N/currRing->isLPring;
13219  int maxShift = degbound - h_lastVblock;
13220 
13221  if (pGetComp(h)==0)
13222  {
13223  if (strat->rightGB)
13224  {
13225  if (isFromQ)
13226  {
13227  // pairs (shifts(h),s[1..k]), (h, s[1..k])
13228  for (i=0; i<=maxShift; i++)
13229  {
13230  poly hh = pLPCopyAndShiftLM(h, i);
13231  for (j=0; j<=k; j++)
13232  {
13233  if (strat->fromQ == NULL || !strat->fromQ[j])
13234  {
13235  new_pair=TRUE;
13236  poly s = strat->S[j];
13237  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13238  }
13239  }
13240  }
13241  }
13242  else
13243  {
13244  new_pair=TRUE;
13245  for (j=0; j<=k; j++)
13246  {
13247  poly s = strat->S[j];
13248  if (strat->fromQ != NULL && strat->fromQ[j])
13249  {
13250  // pairs (shifts(s[j]),h), (s[j],h)
13251  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13252  }
13253  else
13254  {
13255  // pair (h, s[j])
13256  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13257  }
13258  }
13259  }
13260  }
13261  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
13262  else if ((isFromQ)&&(strat->fromQ!=NULL))
13263  {
13264  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13265  for (j=0; j<=k; j++)
13266  {
13267  if (!strat->fromQ[j])
13268  {
13269  new_pair=TRUE;
13270  poly s = strat->S[j];
13271  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13272  }
13273  }
13274  // pairs (shifts(h),s[1..k])
13275  if (new_pair)
13276  {
13277  for (i=1; i<=maxShift; i++)
13278  {
13279  poly hh = pLPCopyAndShiftLM(h, i);
13280  for (j=0; j<=k; j++)
13281  {
13282  if (!strat->fromQ[j])
13283  {
13284  poly s = strat->S[j];
13285  int s_lastVblock = pmLastVblock(s);
13286  if (i < s_lastVblock || (pGetComp(s) > 0 && i == s_lastVblock)) // in the module case, product criterion does not hold (note: comp h is always zero here)
13287  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
13288 #ifdef HAVE_RINGS
13289  else if (rField_is_Ring(currRing))
13290  {
13291  assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13292  ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13293  for (int k = 0; k < IDELEMS(fillers); k++)
13294  {
13295  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13296  enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13297  }
13298  idDelete(&fillers);
13299  }
13300 #endif
13301  }
13302  }
13303  }
13304  }
13305  }
13306  else
13307  {
13308  new_pair=TRUE;
13309  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13310  for (j=0; j<=k; j++)
13311  {
13312  poly s = strat->S[j];
13313  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13314  }
13315  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13316  for (i=1; i<=maxShift; i++)
13317  {
13318  poly hh = pLPCopyAndShiftLM(h, i);
13319  for (j=0; j<=k; j++)
13320  {
13321  poly s = strat->S[j];
13322  int s_lastVblock = pmLastVblock(s);
13323  if (i < s_lastVblock || (pGetComp(s) > 0 && i == s_lastVblock)) // in the module case, product criterion does not hold (note: comp h is always zero here)
13324  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
13325 #ifdef HAVE_RINGS
13326  else if (rField_is_Ring(currRing))
13327  {
13328  assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13329  ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13330  for (int k = 0; k < IDELEMS(fillers); k++)
13331  {
13332  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13333  enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13334  }
13335  idDelete(&fillers);
13336  }
13337 #endif
13338  }
13339  if (i < h_lastVblock) // in the module case, product criterion does not hold (note: comp h is always zero here)
13340  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13341 #ifdef HAVE_RINGS
13342  else if (rField_is_Ring(currRing))
13343  {
13344  assume(i >= h_lastVblock); // this is always the case, but just to be very sure
13345  ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
13346  for (int k = 0; k < IDELEMS(fillers); k++)
13347  {
13348  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
13349  enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock);
13350  }
13351  idDelete(&fillers);
13352  }
13353 #endif
13354  }
13355  }
13356  }
13357  else
13358  {
13359  assume(isFromQ == 0); // an element from Q should always has 0 component
13360  new_pair=TRUE;
13361  if (strat->rightGB)
13362  {
13363  for (j=0; j<=k; j++)
13364  {
13365  if ((pGetComp(h)==pGetComp(strat->S[j]))
13366  || (pGetComp(strat->S[j])==0))
13367  {
13368  poly s = strat->S[j];
13369  if (strat->fromQ != NULL && strat->fromQ[j])
13370  {
13371  // pairs (shifts(s[j]),h), (s[j],h)
13372  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13373  }
13374  else
13375  {
13376  // pair (h, s[j])
13377  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13378  }
13379  }
13380  }
13381  }
13382  else
13383  {
13384  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13385  for (j=0; j<=k; j++)
13386  {
13387  if ((pGetComp(h)==pGetComp(strat->S[j]))
13388  || (pGetComp(strat->S[j])==0))
13389  {
13390  poly s = strat->S[j];
13391  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13392  }
13393  }
13394  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13395  for (i=1; i<=maxShift; i++)
13396  {
13397  poly hh = pLPCopyAndShiftLM(h, i);
13398  for (j=0; j<=k; j++)
13399  {
13400  if ((pGetComp(h)==pGetComp(strat->S[j]))
13401  || (pGetComp(strat->S[j])==0))
13402  {
13403  poly s = strat->S[j];
13404  int s_lastVblock = pmLastVblock(s);
13405  if (i <= s_lastVblock) // in the module case, product criterion does not hold
13406  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
13407 #ifdef HAVE_RINGS
13408  else if (rField_is_Ring(currRing))
13409  {
13410  assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13411  ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13412  for (int k = 0; k < IDELEMS(fillers); k++)
13413  {
13414  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13415  enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13416  }
13417  idDelete(&fillers);
13418  }
13419 #endif
13420  }
13421  }
13422  if (i <= h_lastVblock) // in the module case, product criterion does not hold
13423  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13424 #ifdef HAVE_RINGS
13425  else if (rField_is_Ring(currRing))
13426  {
13427  assume(i >= h_lastVblock); // this is always the case, but just to be very sure
13428  ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
13429  for (int k = 0; k < IDELEMS(fillers); k++)
13430  {
13431  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
13432  enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock);
13433  }
13434  idDelete(&fillers);
13435  }
13436 #endif
13437  }
13438  }
13439  }
13440 
13441  if (new_pair)
13442  {
13443  strat->chainCrit(h,ecart,strat);
13444  }
13445  kMergeBintoL(strat);
13446  }
13447 }
13448 #endif
13449 
13450 /*3
13451 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
13452 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
13453 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
13454 */
13455 #ifdef HAVE_SHIFTBBA
13456 void initenterstrongPairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
13457 {
13458  int h_lastVblock = pmLastVblock(h);
13459  assume(h_lastVblock != 0 || pLmIsConstantComp(h));
13460  // TODO: is it allowed to skip pairs with constants? also with constants from other components?
13461  if (h_lastVblock == 0) return;
13462  assume(pmFirstVblock(h) == 1);
13463  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13464  // atR = -1;
13465  if ((strat->syzComp==0)
13466  || (pGetComp(h)<=strat->syzComp))
13467  {
13468  int i,j;
13469  BOOLEAN new_pair=FALSE;
13470 
13471  int degbound = currRing->N/currRing->isLPring;
13472  int maxShift = degbound - h_lastVblock;
13473 
13474  if (pGetComp(h)==0)
13475  {
13476  if (strat->rightGB)
13477  {
13478  if (isFromQ)
13479  {
13480  // pairs (shifts(h),s[1..k]), (h, s[1..k])
13481  for (i=0; i<=maxShift; i++)
13482  {
13483  poly hh = pLPCopyAndShiftLM(h, i);
13484  for (j=0; j<=k; j++)
13485  {
13486  if (strat->fromQ == NULL || !strat->fromQ[j])
13487  {
13488  new_pair=TRUE;
13489  poly s = strat->S[j];
13490  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13491  }
13492  }
13493  }
13494  }
13495  else
13496  {
13497  new_pair=TRUE;
13498  for (j=0; j<=k; j++)
13499  {
13500  poly s = strat->S[j];
13501  if (strat->fromQ != NULL && strat->fromQ[j])
13502  {
13503  // pairs (shifts(s[j]),h), (s[j],h)
13504  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13505  }
13506  else
13507  {
13508  // pair (h, s[j])
13509  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13510  }
13511  }
13512  }
13513  }
13514  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
13515  else if ((isFromQ)&&(strat->fromQ!=NULL))
13516  {
13517  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13518  for (j=0; j<=k; j++)
13519  {
13520  if (!strat->fromQ[j])
13521  {
13522  new_pair=TRUE;
13523  poly s = strat->S[j];
13524  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13525  }
13526  }
13527  // pairs (shifts(h),s[1..k])
13528  if (new_pair)
13529  {
13530  for (i=1; i<=maxShift; i++)
13531  {
13532  poly hh = pLPCopyAndShiftLM(h, i);
13533  for (j=0; j<=k; j++)
13534  {
13535  if (!strat->fromQ[j])
13536  {
13537  poly s = strat->S[j];
13538  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13539  }
13540  }
13541  }
13542  }
13543  }
13544  else
13545  {
13546  new_pair=TRUE;
13547  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13548  for (j=0; j<=k; j++)
13549  {
13550  poly s = strat->S[j];
13551  // TODO: cache lastVblock of s[1..k] for later use
13552  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13553  }
13554  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13555  for (i=1; i<=maxShift; i++)
13556  {
13557  poly hh = pLPCopyAndShiftLM(h, i);
13558  for (j=0; j<=k; j++)
13559  {
13560  poly s = strat->S[j];
13561  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13562  }
13563  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13564  }
13565  }
13566  }
13567  else
13568  {
13569  new_pair=TRUE;
13570  if (strat->rightGB)
13571  {
13572  for (j=0; j<=k; j++)
13573  {
13574  if ((pGetComp(h)==pGetComp(strat->S[j]))
13575  || (pGetComp(strat->S[j])==0))
13576  {
13577  assume(isFromQ == 0); // this case is not handeled here and should also never happen
13578  poly s = strat->S[j];
13579  if (strat->fromQ != NULL && strat->fromQ[j])
13580  {
13581  // pairs (shifts(s[j]),h), (s[j],h)
13582  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13583  }
13584  else
13585  {
13586  // pair (h, s[j])
13587  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13588  }
13589  }
13590  }
13591  }
13592  else
13593  {
13594  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13595  for (j=0; j<=k; j++)
13596  {
13597  if ((pGetComp(h)==pGetComp(strat->S[j]))
13598  || (pGetComp(strat->S[j])==0))
13599  {
13600  poly s = strat->S[j];
13601  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13602  }
13603  }
13604  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13605  for (i=1; i<=maxShift; i++)
13606  {
13607  poly hh = pLPCopyAndShiftLM(h, i);
13608  for (j=0; j<=k; j++)
13609  {
13610  if ((pGetComp(h)==pGetComp(strat->S[j]))
13611  || (pGetComp(strat->S[j])==0))
13612  {
13613  poly s = strat->S[j];
13614  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13615  }
13616  }
13617  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13618  }
13619  }
13620  }
13621 
13622  if (new_pair)
13623  {
13624  strat->chainCrit(h,ecart,strat);
13625  }
13626  kMergeBintoL(strat);
13627  }
13628 }
13629 #endif
13630 
13631 /*2
13632 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
13633 *superfluous elements in S will be deleted
13634 */
13635 #ifdef HAVE_SHIFTBBA
13636 void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
13637 {
13638  /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13639  /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
13640  int j=pos;
13641 
13642  /* if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat); */ // TODO: enterExtendedSpoly not for LP yet
13643  initenterpairsShift(h,k,ecart,0,strat, atR);
13644  if ( (!strat->fromT)
13645  && ((strat->syzComp==0)
13646  ||(pGetComp(h)<=strat->syzComp)))
13647  {
13648  unsigned long h_sev = pGetShortExpVector(h);
13649  loop
13650  {
13651  if (j > k) break;
13652  // TODO this currently doesn't clear all possible elements because of commutative division
13653  if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
13654  clearS(h,h_sev, &j,&k,strat);
13655  j++;
13656  }
13657  }
13658 }
13659 #endif
13660 
13661 /*2
13662 * enteres all admissible shifts of p into T
13663 * assumes that p is already in T!
13664 */
13665 #ifdef HAVE_SHIFTBBA
13666 void enterTShift(LObject p, kStrategy strat, int atT)
13667 {
13668  /* determine how many elements we have to insert */
13669  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
13670  /* hence, a total number of elt's to add is: */
13671  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
13672  pAssume(p.p != NULL);
13673 
13674  int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
13675 
13676  for (int i = 1; i <= maxPossibleShift; i++)
13677  {
13678  LObject qq;
13679  qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
13680  qq.shift = i;
13681  strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
13682 
13683  enterT(qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
13684  }
13685 }
13686 #endif
13687 
13688 #ifdef HAVE_SHIFTBBA
13689 poly redtailBbaShift (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
13690 {
13691  /* for the shift case need to run it with withT = TRUE */
13692  strat->redTailChange=FALSE;
13693  if (strat->noTailReduction) return L->GetLmCurrRing();
13694  poly h, p;
13695  p = h = L->GetLmTailRing();
13696  if ((h==NULL) || (pNext(h)==NULL))
13697  return L->GetLmCurrRing();
13698 
13699  TObject* With;
13700  // placeholder in case strat->tl < 0
13701  TObject With_s(strat->tailRing);
13702 
13703  LObject Ln(pNext(h), strat->tailRing);
13704  Ln.pLength = L->GetpLength() - 1;
13705 
13706  pNext(h) = NULL;
13707  if (L->p != NULL) pNext(L->p) = NULL;
13708  L->pLength = 1;
13709 
13710  Ln.PrepareRed(strat->use_buckets);
13711 
13712  while(!Ln.IsNull())
13713  {
13714  loop
13715  {
13716  Ln.SetShortExpVector();
13717  if (withT)
13718  {
13719  int j;
13720  j = kFindDivisibleByInT(strat, &Ln);
13721  if (j < 0) break;
13722  With = &(strat->T[j]);
13723  }
13724  else
13725  {
13726  With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
13727  if (With == NULL) break;
13728  }
13729  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
13730  {
13731  With->pNorm();
13732  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
13733  }
13734  strat->redTailChange=TRUE;
13735  if (ksReducePolyTail(L, With, &Ln))
13736  {
13737  // reducing the tail would violate the exp bound
13738  // set a flag and hope for a retry (in bba)
13739  strat->completeReduce_retry=TRUE;
13740  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
13741  do
13742  {
13743  pNext(h) = Ln.LmExtractAndIter();
13744  pIter(h);
13745  L->pLength++;
13746  } while (!Ln.IsNull());
13747  goto all_done;
13748  }
13749  if (Ln.IsNull()) goto all_done;
13750  if (! withT) With_s.Init(currRing);
13751  }
13752  pNext(h) = Ln.LmExtractAndIter();
13753  pIter(h);
13754  L->pLength++;
13755  }
13756 
13757  all_done:
13758  Ln.Delete();
13759  if (L->p != NULL) pNext(L->p) = pNext(p);
13760 
13761  if (strat->redTailChange)
13762  {
13763  L->length = 0;
13764  }
13765  L->Normalize(); // HANNES: should have a test
13766  kTest_L(L,strat->tailRing);
13767  return L->GetLmCurrRing();
13768 }
13769 #endif
static int si_max(const int a, const int b)
Definition: auxiliary.h:124
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
void * ADDRESS
Definition: auxiliary.h:119
static int si_min(const int a, const int b)
Definition: auxiliary.h:125
CanonicalForm lc(const CanonicalForm &f)
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:676
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:56
int l
Definition: cfEzgcd.cc:100
int m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
int p
Definition: cfModGcd.cc:4080
bool equal
Definition: cfModGcd.cc:4128
CanonicalForm b
Definition: cfModGcd.cc:4105
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
FILE * f
Definition: checklibs.c:9
Definition: intvec.h:23
poly p
Definition: kutil.h:69
poly t_p
Definition: kutil.h:70
ring tailRing
Definition: kutil.h:72
void wrp()
Definition: kutil.cc:773
KINLINE poly kNoetherTail()
Definition: kInline.h:66
unsigned long * sevSyz
Definition: kutil.h:320
kStrategy next
Definition: kutil.h:274
bool sigdrop
Definition: kutil.h:359
poly t_kNoether
Definition: kutil.h:330
int syzComp
Definition: kutil.h:353
int * S_2_R
Definition: kutil.h:341
ring tailRing
Definition: kutil.h:342
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:288
char noTailReduction
Definition: kutil.h:378
int currIdx
Definition: kutil.h:314
~skStrategy()
Definition: kutil.cc:11902
skStrategy()
Definition: kutil.cc:11882
int nrsyzcrit
Definition: kutil.h:360
intset lenS
Definition: kutil.h:316
int nrrewcrit
Definition: kutil.h:361
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:295
int Ll
Definition: kutil.h:350
TSet T
Definition: kutil.h:323
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:290
char news
Definition: kutil.h:400
omBin lmBin
Definition: kutil.h:343
int syzmax
Definition: kutil.h:348
int Bl
Definition: kutil.h:351
intset ecartS
Definition: kutil.h:306
int syzidxmax
Definition: kutil.h:348
char honey
Definition: kutil.h:377
char rightGB
Definition: kutil.h:369
polyset S
Definition: kutil.h:303
int minim
Definition: kutil.h:357
poly kNoether
Definition: kutil.h:327
BOOLEAN * NotUsedAxis
Definition: kutil.h:331
LSet B
Definition: kutil.h:325
BOOLEAN * pairtest
Definition: kutil.h:332
int cp
Definition: kutil.h:346
int ak
Definition: kutil.h:352
TObject ** R
Definition: kutil.h:339
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:292
poly kHEdge
Definition: kutil.h:326
poly t_kHEdge
Definition: kutil.h:328
int tl
Definition: kutil.h:349
unsigned long * sevT
Definition: kutil.h:322
unsigned long * sevSig
Definition: kutil.h:321
int nr
Definition: kutil.h:345
poly tail
Definition: kutil.h:333
char sugarCrit
Definition: kutil.h:377
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:281
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:47
intset syzIdx
Definition: kutil.h:310
ideal Shdl
Definition: kutil.h:300
int syzl
Definition: kutil.h:348
unsigned sbaOrder
Definition: kutil.h:313
pFDegProc pOrigFDeg
Definition: kutil.h:293
int tmax
Definition: kutil.h:349
polyset sig
Definition: kutil.h:305
polyset syz
Definition: kutil.h:304
char LDegLast
Definition: kutil.h:385
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:284
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.h:289
wlen_set lenSw
Definition: kutil.h:317
int cv
Definition: kutil.h:368
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:337
char Gebauer
Definition: kutil.h:378
intset fromQ
Definition: kutil.h:318
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:283
char newt
Definition: kutil.h:401
char use_buckets
Definition: kutil.h:383
char interpt
Definition: kutil.h:371
char redTailChange
Definition: kutil.h:399
int newIdeal
Definition: kutil.h:356
char fromT
Definition: kutil.h:379
char completeReduce_retry
Definition: kutil.h:403
void(* initEcart)(TObject *L)
Definition: kutil.h:277
omBin tailBin
Definition: kutil.h:344
LObject P
Definition: kutil.h:299
KINLINE TObject * S_2_T(int i)
Definition: kInline.h:38
char noClearS
Definition: kutil.h:402
int Lmax
Definition: kutil.h:350
char z2homog
Definition: kutil.h:374
int LazyPass
Definition: kutil.h:352
char overflow
Definition: kutil.h:404
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.h:287
LSet L
Definition: kutil.h:324
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:278
int(* red)(LObject *L, kStrategy strat)
Definition: kutil.h:275
int sl
Definition: kutil.h:347
int LazyDegree
Definition: kutil.h:352
char kHEdgeFound
Definition: kutil.h:376
char posInLDependsOnLength
Definition: kutil.h:389
unsigned long * sevS
Definition: kutil.h:319
int HCord
Definition: kutil.h:354
char homog
Definition: kutil.h:372
pLDegProc pOrigLDeg
Definition: kutil.h:294
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:279
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:296
int Bmax
Definition: kutil.h:351
int c3
Definition: kutil.h:346
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:548
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:840
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:31
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:687
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:516
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:702
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:723
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:353
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:456
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:713
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:694
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:539
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:629
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:777
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition: coeffs.h:523
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:74
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:513
#define Print
Definition: emacs.cc:80
#define WarnS
Definition: emacs.cc:78
const CanonicalForm int s
Definition: facAbsFact.cc:51
CanonicalForm res
Definition: facAbsFact.cc:60
CanonicalForm H
Definition: facAbsFact.cc:60
bool found
Definition: facFactorize.cc:55
CFList tmp1
Definition: facFqBivar.cc:72
CFList tmp2
Definition: facFqBivar.cc:72
int j
Definition: facHensel.cc:110
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
static int min(int a, int b)
Definition: fast_mult.cc:268
static int max(int a, int b)
Definition: fast_mult.cc:264
#define STATIC_VAR
Definition: globaldefs.h:7
#define VAR
Definition: globaldefs.h:5
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge, ring tailRing)
Definition: hdegree.cc:1078
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition: ideals.cc:830
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
#define idIsConstant(I)
Definition: ideals.h:40
BOOLEAN idInsertPoly(ideal h1, poly h2)
insert h2 into h1 (if h2 is not the zero polynomial) return TRUE iff h2 was indeed inserted
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
ideal idCopy(ideal A)
Definition: ideals.h:60
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition: ideals.h:37
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:257
STATIC_VAR jList * T
Definition: janet.cc:30
STATIC_VAR Poly * h
Definition: janet.cc:971
STATIC_VAR jList * Q
Definition: janet.cc:30
KINLINE unsigned long * initsevT()
Definition: kInline.h:100
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:927
KINLINE TSet initT()
Definition: kInline.h:84
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:1029
KINLINE int ksReducePolyTailLC_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1077
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1142
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1115
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1152
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1200
KINLINE TObject ** initR()
Definition: kInline.h:95
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:986
KINLINE int ksReducePolyTail_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1095
int redLiftstd(LObject *h, kStrategy strat)
Definition: kLiftstd.cc:161
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:521
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
Definition: kbuckets.cc:197
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:216
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:493
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
Definition: kbuckets.cc:660
int ksCheckCoeff(number *a, number *b)
BOOLEAN pCompareChainPart(poly p, poly p1, poly p2, poly lcm, const ring R)
Definition: kpolys.cc:71
BOOLEAN pCompareChain(poly p, poly p1, poly p2, poly lcm, const ring R)
Returns TRUE if.
Definition: kpolys.cc:17
poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing)
Definition: kspoly.cc:1415
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition: kstd1.cc:1331
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2406
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:3158
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:2419
int kFindDivisibleByInT_Z(const kStrategy strat, const LObject *L, const int start)
Definition: kstd2.cc:207
int redHoney(LObject *h, kStrategy strat)
Definition: kstd2.cc:1842
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:902
int redLazy(LObject *h, kStrategy strat)
Definition: kstd2.cc:1648
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:795
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:288
VAR int strat_nr
Definition: kstdfac.cc:21
void initSbaPos(kStrategy strat)
Definition: kutil.cc:10432
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:8033
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7480
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6938
#define pDivComp_LESS
Definition: kutil.cc:136
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:7052
int getIndexRng(long coeff)
Definition: kutil.cc:6598
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6695
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5805
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10322
poly pMove2CurrTail(poly p, kStrategy strat)
Definition: kutil.cc:12218
int posInTrg0(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5477
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:784
VAR int HCord
Definition: kutil.cc:246
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3197
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition: kutil.cc:524
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition: kutil.cc:7287
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9901
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6439
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:169
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5400
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9699
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5342
void enterTShift(LObject p, kStrategy strat, int atT)
Definition: kutil.cc:13666
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5595
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7262
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9473
BOOLEAN kTest(kStrategy strat)
Definition: kutil.cc:1010
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3965
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1649
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7670
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5671
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:5331
poly pMoveCurrTail2poly(poly p, kStrategy strat)
Definition: kutil.cc:12232
BOOLEAN kTest_TS(kStrategy strat)
Definition: kutil.cc:1071
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:1975
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:718
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition: kutil.cc:11084
VAR int Kstd1_mu
Definition: kutil.cc:248
void initenterstrongPairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:13456
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4959
static void enterOnePairRingShift(poly q, poly p, int, int isFromQ, kStrategy strat, int atR, int, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12514
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1301
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7203
long ind_fact_2(long arg)
Definition: kutil.cc:4194
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4876
static int pLPDivComp(poly p, poly q)
Definition: kutil.cc:232
int posInT2(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5370
BOOLEAN kTest_L(LObject *L, ring strat_tailRing, BOOLEAN testp, int lpos, TSet T, int tlength)
Definition: kutil.cc:925
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6783
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6736
#define kFalseReturn(x)
Definition: kutil.cc:780
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:12046
static intset initec(const int maxnr)
Definition: kutil.cc:510
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition: kutil.cc:10133
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4933
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5642
void redtailBbaAlsoLC_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7786
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:7154
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9979
void chainCritSig(poly p, int, kStrategy strat)
Definition: kutil.cc:3492
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition: kutil.cc:5210
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1347
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4593
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4915
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:9070
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6165
static int pDivCompRing(poly p, poly q)
Definition: kutil.cc:144
BOOLEAN isInPairsetB(poly q, int *k, kStrategy strat)
Definition: kutil.cc:703
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:10149
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:3840
static void enterOnePairWithoutShifts(int p_inS, poly q, poly p, int ecartq, int q_isFromQ, kStrategy strat, int atR, int p_lastVblock, int q_shift)
Definition: kutil.cc:12823
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8156
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11532
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7556
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7915
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11660
void initPairtest(kStrategy strat)
Definition: kutil.cc:673
static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
Definition: kutil.cc:2238
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6139
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8652
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3476
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5436
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:1367
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:9046
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition: kutil.cc:8958
poly pCopyL2p(LObject H, kStrategy strat)
Definition: kutil.cc:12249
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:13203
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4648
poly kCreateZeroPoly(long exp[], long cabsind, poly *t_p, ring leadRing, ring tailRing)
Definition: kutil.cc:4398
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3905
static BOOLEAN enterOneStrongPolyShift(poly q, poly p, int, int, kStrategy strat, int atR, int, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12344
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6818
static void enlargeL(LSet *L, int *length, const int incr)
Definition: kutil.cc:663
int posInT17_c(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5912
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:13689
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11955
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5710
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9799
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:11274
long ind2(long arg)
Definition: kutil.cc:4182
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:7119
void HEckeTest(poly pp, kStrategy strat)
Definition: kutil.cc:475
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6096
ideal createG0()
Definition: kutil.cc:4527
static void enterOnePairWithShifts(int q_inS, poly q, poly p, int ecartp, int p_isFromQ, kStrategy strat, int atR, int p_lastVblock, int q_lastVblock)
Definition: kutil.cc:12767
STATIC_VAR BOOLEAN sloppy_max
Definition: kutil.cc:800
VAR int Kstd1_deg
Definition: kutil.cc:247
int nextZeroSimplexExponent(long exp[], long ind[], long cexp[], long cind[], long *cabsind, long step[], long bound, long N)
Definition: kutil.cc:4332
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition: kutil.cc:4758
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:13636
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2469
void enterOnePairShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12862
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:10406
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:8087
void initEcartNormal(TObject *h)
Definition: kutil.cc:1325
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:5109
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:9115
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8347
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6509
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3128
void enterOneZeroPairRing(poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:4217
char * showOption()
Definition: misc_ip.cc:721
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6894
void initSyzRules(kStrategy strat)
Definition: kutil.cc:8497
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6197
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10534
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:11045
void cleanT(kStrategy strat)
Definition: kutil.cc:545
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2257
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5553
BOOLEAN kTest_S(kStrategy strat)
Definition: kutil.cc:1053
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:6357
void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
Definition: kutil.cc:9608
static const char * kTest_LmEqual(poly p, poly t_p, ring tailRing)
Definition: kutil.cc:783
void reorderS(int *suc, kStrategy strat)
Definition: kutil.cc:5056
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4675
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6853
#define pDivComp_INCOMP
Definition: kutil.cc:138
void kMergeBintoLSba(kStrategy strat)
Definition: kutil.cc:3218
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:254
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10647
long twoPow(long arg)
Definition: kutil.cc:4209
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4902
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition: kutil.cc:1358
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:6039
static void enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12758
#define pDivComp_GREATER
Definition: kutil.cc:137
void exitSba(kStrategy strat)
Definition: kutil.cc:10607
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition: kutil.cc:7338
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5764
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5866
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition: kutil.cc:1571
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition: kutil.cc:12080
int posInLrg0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6611
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1244
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11632
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3551
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1595
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9997
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:604
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5973
void deleteInSSba(int i, kStrategy strat)
Definition: kutil.cc:1189
static int pDivComp(poly p, poly q)
Definition: kutil.cc:183
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:10859
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6988
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:10235
int kFindInTShift(poly p, TSet T, int tlength)
Definition: kutil.cc:743
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:11350
BOOLEAN kTest_T(TObject *T, ring strat_tailRing, int i, char TN)
Definition: kutil.cc:801
void messageSets(kStrategy strat)
Definition: kutil.cc:8106
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1137
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8941
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:12009
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6221
void initenterzeropairsRing(poly p, int ecart, kStrategy strat, int atR)
Definition: kutil.cc:4461
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition: kutil.cc:682
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition: kutil.cc:1722
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6473
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:11107
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:4982
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3240
void initEcartBBA(TObject *h)
Definition: kutil.cc:1333
VAR denominator_list DENOMINATOR_LIST
Definition: kutil.cc:84
int posInLRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6284
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2726
void enterSBbaShift(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9450
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6397
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:6385
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:515
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1340
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:8074
#define REDTAIL_CANONICALIZE
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1780
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:4027
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8796
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8250
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:5287
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:11439
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9350
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:10062
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10981
#define pDivComp_EQUAL
Definition: kutil.cc:135
static int * initS_2_R(const int maxnr)
Definition: kutil.cc:519
void cancelunit(LObject *L, BOOLEAN inNF)
Definition: kutil.cc:343
denominator_list_s * denominator_list
Definition: kutil.h:59
TObject * TSet
Definition: kutil.h:55
#define setmaxL
Definition: kutil.h:30
#define setmaxTinc
Definition: kutil.h:34
#define setmax
Definition: kutil.h:29
int64 wlen_type
Definition: kutil.h:50
static LSet initL(int nr=setmaxL)
Definition: kutil.h:421
LObject * LSet
Definition: kutil.h:56
denominator_list next
Definition: kutil.h:61
static void kDeleteLcm(LObject *P)
Definition: kutil.h:877
int * intset
Definition: kutil.h:49
#define ALLOW_PROD_CRIT(A)
Definition: kutil.h:395
#define setmaxT
Definition: kutil.h:33
#define setmaxLinc
Definition: kutil.h:31
class sTObject TObject
Definition: kutil.h:53
class sLObject LObject
Definition: kutil.h:54
if(yy_init)
Definition: libparse.cc:1420
static bool rIsSCA(const ring r)
Definition: nc.h:190
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
Definition: old.gring.cc:1879
@ nc_lie
Definition: nc.h:18
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
Definition: old.gring.cc:2243
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:159
void mult(unsigned long *result, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:647
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:709
STATIC_VAR unsigned add[]
Definition: misc_ip.cc:115
#define assume(x)
Definition: mod2.h:387
#define r_assume(x)
Definition: mod2.h:388
int dReportError(const char *fmt,...)
Definition: dError.cc:43
#define p_GetComp(p, r)
Definition: monomials.h:64
#define pFalseReturn(cond)
Definition: monomials.h:139
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44
#define pSetCoeff0(p, n)
Definition: monomials.h:59
#define p_GetCoeff(p, r)
Definition: monomials.h:50
#define __p_GetComp(p, r)
Definition: monomials.h:63
#define rRing_has_Comp(r)
Definition: monomials.h:266
#define pAssume(cond)
Definition: monomials.h:90
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357
STATIC_VAR gmp_float * diff
Definition: mpr_complex.cc:45
#define nDelete(n)
Definition: numbers.h:16
#define nIsZero(n)
Definition: numbers.h:19
#define nEqual(n1, n2)
Definition: numbers.h:20
#define nCopy(n)
Definition: numbers.h:15
#define nGreater(a, b)
Definition: numbers.h:28
#define nGreaterZero(n)
Definition: numbers.h:27
#define nInvers(a)
Definition: numbers.h:33
#define nIsOne(n)
Definition: numbers.h:25
#define nInit(i)
Definition: numbers.h:24
#define nTest(a)
Definition: numbers.h:35
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omCheckBinAddrSize(addr, size)
Definition: omAllocDecl.h:326
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221
#define omSizeWOfBin(bin_ptr)
#define NULL
Definition: omList.c:12
omBin_t * omBin
Definition: omStructs.h:12
#define REGISTER
Definition: omalloc.h:27
#define TEST_OPT_WEIGHTM
Definition: options.h:120
#define TEST_OPT_IDLIFT
Definition: options.h:128
#define TEST_OPT_INTSTRATEGY
Definition: options.h:109
#define TEST_OPT_REDTAIL
Definition: options.h:115
#define TEST_OPT_INFREDTAIL
Definition: options.h:117
#define TEST_OPT_SUGARCRIT
Definition: options.h:106
#define TEST_OPT_OLDSTD
Definition: options.h:122
#define TEST_OPT_REDSB
Definition: options.h:103
#define TEST_OPT_DEGBOUND
Definition: options.h:112
#define TEST_OPT_SB_1
Definition: options.h:118
#define TEST_OPT_NOT_SUGAR
Definition: options.h:105
#define TEST_OPT_PROT
Definition: options.h:102
#define OPT_INTERRUPT
Definition: options.h:78
#define TEST_OPT_CANCELUNIT
Definition: options.h:127
#define BTEST1(a)
Definition: options.h:33
#define TEST_OPT_DEBUG
Definition: options.h:107
#define TEST_OPT_CONTENTSB
Definition: options.h:126
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
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:1133
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:3009
long pLDegb(poly p, int *l, const ring r)
Definition: p_polys.cc:806
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:970
long p_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:591
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1033
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3719
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1063
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition: p_polys.cc:4552
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1292
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:936
long pLDeg1(poly p, int *l, const ring r)
Definition: p_polys.cc:836
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4807
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:905
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:608
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition: p_polys.cc:1203
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2900
long pLDeg1c(poly p, int *l, const ring r)
Definition: p_polys.cc:872
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1000
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:765
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:1170
long pLDeg0(poly p, int *l, const ring r)
Definition: p_polys.cc:734
poly p_One(const ring r)
Definition: p_polys.cc:1308
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1977
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1460
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3766
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:582
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition: p_polys.cc:1642
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1067
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1385
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:896
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:711
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1074
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1371
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:100
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:1822
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:380
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition: p_polys.h:747
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition: p_polys.h:1273
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1695
#define __pp_Mult_nn(p, n, r)
Definition: p_polys.h:962
static poly pp_mm_Mult(poly p, poly m, const ring r)
Definition: p_polys.h:1001
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:991
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition: p_polys.h:1607
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:254
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:488
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:164
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:247
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:233
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:412
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1540
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1897
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:469
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:69
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1863
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:888
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:861
static unsigned pLength(poly a)
Definition: p_polys.h:191
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:110
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:703
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1011
static void p_LmFree(poly p, ring)
Definition: p_polys.h:683
#define p_LmTest(p, r)
Definition: p_polys.h:163
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:812
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1467
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition: p_polys.h:2007
#define p_Test(p, r)
Definition: p_polys.h:162
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:373
void rChangeCurrRing(ring r)
Definition: polys.cc:15
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
Compatiblity layer for legacy polynomial operations (over currRing)
#define pAdd(p, q)
Definition: polys.h:203
#define pLtCmp(p, q)
Definition: polys.h:123
#define pLtCmpOrdSgnDiffM(p, q)
Definition: polys.h:125
#define pDelete(p_ptr)
Definition: polys.h:186
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL
Definition: polys.h:67
#define pLmIsConstantComp(p)
like above, except that p must be != NULL
Definition: polys.h:242
#define pSetm(p)
Definition: polys.h:271
#define pIsConstant(p)
like above, except that Comp must be 0
Definition: polys.h:238
#define pHasNotCF(p1, p2)
Definition: polys.h:263
#define pLtCmpOrdSgnDiffP(p, q)
Definition: polys.h:126
#define pNeg(p)
Definition: polys.h:198
#define pLmEqual(p1, p2)
Definition: polys.h:111
#define ppMult_mm(p, m)
Definition: polys.h:201
#define pGetComp(p)
Component.
Definition: polys.h:37
#define pIsVector(p)
Definition: polys.h:250
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
#define pJet(p, m)
Definition: polys.h:368
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition: polys.h:146
#define pCmp(p1, p2)
pCmp: args may be NULL returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
Definition: polys.h:115
#define pDivideM(a, b)
Definition: polys.h:294
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
#define pSetComp(p, v)
Definition: polys.h:38
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl....
Definition: polys.h:152
void wrp(poly p)
Definition: polys.h:310
#define pLmDivisibleBy(a, b)
like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
Definition: polys.h:140
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
void pWrite(poly p)
Definition: polys.h:308
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
#define pSetmComp(p)
TODO:
Definition: polys.h:273
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:363
#define pHasNotCFRing(p1, p2)
Definition: polys.h:262
#define pNormalize(p)
Definition: polys.h:317
#define pIsPurePower(p)
Definition: polys.h:248
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:61
#define pEqualPolys(p1, p2)
Definition: polys.h:400
#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
#define pSetExp(p, i, v)
Definition: polys.h:42
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:105
#define pLtCmpOrdSgnEqP(p, q)
Definition: polys.h:128
#define pCopy(p)
return a copy of the poly
Definition: polys.h:185
#define pOne()
Definition: polys.h:315
char * pString(poly p)
Definition: polys.h:306
poly * polyset
Definition: polys.h:259
#define pDecrExp(p, i)
Definition: polys.h:44
#define pLcm(a, b, m)
Definition: polys.h:295
poly prMoveR(poly &p, ring src_r, ring dest_r)
Definition: prCopy.cc:89
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
Definition: prCopy.cc:45
void pLcmRat(poly a, poly b, poly m, int rat_shift)
Definition: ratgring.cc:30
void PrintS(const char *s)
Definition: reporter.cc:284
void PrintLn()
Definition: reporter.cc:310
#define mflush()
Definition: reporter.h:58
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:3403
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5657
void rKillModifiedRing(ring r)
Definition: ring.cc:3007
ring rAssure_c_dp(const ring r)
Definition: ring.cc:4940
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2646
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1366
void rDebugPrint(const ring r)
Definition: ring.cc:4075
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:449
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:489
static int rBlocks(ring r)
Definition: ring.h:573
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:400
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:728
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:492
static BOOLEAN rIsRatGRing(const ring r)
Definition: ring.h:430
static BOOLEAN rIsLPRing(const ring r)
Definition: ring.h:411
rRingOrder_t
order stuff
Definition: ring.h:68
@ ringorder_a
Definition: ring.h:70
@ ringorder_C
Definition: ring.h:73
@ ringorder_c
Definition: ring.h:72
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:766
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:725
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:44
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:597
BOOLEAN rHasGlobalOrdering(const ring r)
Definition: ring.h:764
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:765
int p_mLPmaxPossibleShift(poly p, const ring r)
Definition: shiftgb.cc:45
#define pLPCopyAndShiftLM(p, sh)
Definition: shiftgb.h:15
BOOLEAN _p_LPLmDivisibleByNoComp(poly a, poly b, const ring r)
Definition: shiftop.cc:793
int p_mFirstVblock(poly p, const ring ri)
Definition: shiftop.cc:475
void k_SplitFrame(poly &m1, poly &m2, int at, const ring r)
Definition: shiftop.cc:597
void p_mLPshift(poly m, int sh, const ring ri)
Definition: shiftop.cc:359
#define pmFirstVblock(p)
Definition: shiftop.h:35
#define pLPDivisibleBy(a, b)
Definition: shiftop.h:57
#define pIsInV(p)
Definition: shiftop.h:50
#define pmIsInV(p)
Definition: shiftop.h:51
#define pmLastVblock(p)
Definition: shiftop.h:33
#define pLPLmDivisibleBy(a, b)
Definition: shiftop.h:58
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
int idElem(const ideal F)
count non-zero elements
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
ideal id_MaxIdeal(const ring r)
initialise the maximal ideal (at 0)
Definition: simpleideals.cc:98
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
#define IDELEMS(i)
Definition: simpleideals.h:23
#define R
Definition: sirandom.c:27
@ isHomog
Definition: structs.h:42
@ isNotHomog
Definition: structs.h:41
skStrategy * kStrategy
Definition: structs.h:63
#define loop
Definition: structs.h:80
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition: syz3.cc:1026
#define degbound(p)
Definition: tgb.cc:153
int gcd(int a, int b)
Definition: walkSupport.cc:836
long totaldegreeWecart(poly p, ring r)
Definition: weight.cc:217
long maxdegreeWecart(poly p, int *l, ring r)
Definition: weight.cc:247
EXTERN_VAR short * ecartWeights
Definition: weight.h:12
#define omGetStickyBinOfBin(B)
Definition: xalloc.h:294
#define omMergeStickyBinIntoBin(A, B)
Definition: xalloc.h:323