kutil.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT: kernel: utils for kStd
6 */
7 
8 // #define PDEBUG 2
9 // #define PDIV_DEBUG
10 #define KUTIL_CC
11 
12 #define MYTEST 0
13 
14 //All vs Just strategy over rings:
15 // 1 - Just
16 // 0 - All
17 #define ALL_VS_JUST 0
18 //Extended Spoly Strategy:
19 // 0 - new gen sig
20 // 1 - ann*old sig
21 #define EXT_POLY_NEW 0
22 
23 #include "kernel/mod2.h"
24 
25 #include "misc/mylimits.h"
26 #include "misc/options.h"
27 #include "polys/nc/nc.h"
28 #include "polys/nc/sca.h"
29 #include "polys/weight.h" /* for kDebugPrint: maxdegreeWecart*/
30 
31 #include <stdlib.h>
32 #include <string.h>
33 
34 #ifdef KDEBUG
35 #undef KDEBUG
36 #define KDEBUG 2
37 #endif
38 
39 #ifdef DEBUGF5
40 #undef DEBUGF5
41 //#define DEBUGF5 1
42 #endif
43 
44 #ifdef HAVE_RINGS
45 #include "kernel/ideals.h"
46 #endif
47 
48 // define if enterL, enterT should use memmove instead of doing it manually
49 // on topgun, this is slightly faster (see monodromy_l.tst, homog_gonnet.sing)
50 #ifndef SunOS_4
51 #define ENTER_USE_MEMMOVE
52 #endif
53 
54 // define, if the my_memmove inlines should be used instead of
55 // system memmove -- it does not seem to pay off, though
56 // #define ENTER_USE_MYMEMMOVE
57 
58 #include "kernel/GBEngine/kutil.h"
59 #include "polys/kbuckets.h"
60 #include "coeffs/numbers.h"
61 #include "kernel/polys.h"
62 #include "polys/monomials/ring.h"
63 #include "kernel/ideals.h"
65 #include "kernel/GBEngine/kstd1.h"
67 
68 #ifdef HAVE_SHIFTBBA
69 #include "polys/shiftop.h"
70 #endif
71 
72 #include "polys/prCopy.h"
73 
74 #ifdef HAVE_RATGRING
76 #endif
77 
78 #ifdef KDEBUG
79 #undef KDEBUG
80 #define KDEBUG 2
81 #endif
82 
83 #ifdef DEBUGF5
84 #undef DEBUGF5
85 #define DEBUGF5 2
86 #endif
87 
89 
90 
91 #ifdef ENTER_USE_MYMEMMOVE
92 inline void _my_memmove_d_gt_s(unsigned long* d, unsigned long* s, long l)
93 {
94  REGISTER unsigned long* _dl = (unsigned long*) d;
95  REGISTER unsigned long* _sl = (unsigned long*) s;
96  REGISTER long _i = l - 1;
97 
98  do
99  {
100  _dl[_i] = _sl[_i];
101  _i--;
102  }
103  while (_i >= 0);
104 }
105 
106 inline void _my_memmove_d_lt_s(unsigned long* d, unsigned long* s, long l)
107 {
108  REGISTER long _ll = l;
109  REGISTER unsigned long* _dl = (unsigned long*) d;
110  REGISTER unsigned long* _sl = (unsigned long*) s;
111  REGISTER long _i = 0;
112 
113  do
114  {
115  _dl[_i] = _sl[_i];
116  _i++;
117  }
118  while (_i < _ll);
119 }
120 
121 inline void _my_memmove(void* d, void* s, long l)
122 {
123  unsigned long _d = (unsigned long) d;
124  unsigned long _s = (unsigned long) s;
125  unsigned long _l = ((l) + SIZEOF_LONG - 1) >> LOG_SIZEOF_LONG;
126 
127  if (_d > _s) _my_memmove_d_gt_s(_d, _s, _l);
128  else _my_memmove_d_lt_s(_d, _s, _l);
129 }
130 
131 #undef memmove
132 #define memmove(d,s,l) _my_memmove(d, s, l)
133 #endif
134 
135 static poly redMora (poly h,int maxIndex,kStrategy strat);
136 static poly redBba (poly h,int maxIndex,kStrategy strat);
137 
138 #ifdef HAVE_RINGS
139 #define pDivComp_EQUAL 2
140 #define pDivComp_LESS 1
141 #define pDivComp_GREATER -1
142 #define pDivComp_INCOMP 0
143 /* Checks the relation of LM(p) and LM(q)
144  LM(p) = LM(q) => return pDivComp_EQUAL
145  LM(p) | LM(q) => return pDivComp_LESS
146  LM(q) | LM(p) => return pDivComp_GREATER
147  else return pDivComp_INCOMP */
148 static inline int pDivCompRing(poly p, poly q)
149 {
150  if ((currRing->pCompIndex < 0)
152  {
153  BOOLEAN a=FALSE, b=FALSE;
154  int i;
155  unsigned long la, lb;
156  unsigned long divmask = currRing->divmask;
157  for (i=0; i<currRing->VarL_Size; i++)
158  {
159  la = p->exp[currRing->VarL_Offset[i]];
160  lb = q->exp[currRing->VarL_Offset[i]];
161  if (la != lb)
162  {
163  if (la < lb)
164  {
165  if (b) return pDivComp_INCOMP;
166  if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
167  return pDivComp_INCOMP;
168  a = TRUE;
169  }
170  else
171  {
172  if (a) return pDivComp_INCOMP;
173  if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
174  return pDivComp_INCOMP;
175  b = TRUE;
176  }
177  }
178  }
179  if (a) return pDivComp_LESS;
180  if (b) return pDivComp_GREATER;
181  if (!a & !b) return pDivComp_EQUAL;
182  }
183  return pDivComp_INCOMP;
184 }
185 #endif
186 
187 static inline int pDivComp(poly p, poly q)
188 {
189  if ((currRing->pCompIndex < 0)
191  {
192 #ifdef HAVE_RATGRING
193  if (rIsRatGRing(currRing))
194  {
196  q,currRing,
197  currRing->real_var_start, currRing->real_var_end))
198  return 0;
199  return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
200  }
201 #endif
202  BOOLEAN a=FALSE, b=FALSE;
203  int i;
204  unsigned long la, lb;
205  unsigned long divmask = currRing->divmask;
206  for (i=0; i<currRing->VarL_Size; i++)
207  {
208  la = p->exp[currRing->VarL_Offset[i]];
209  lb = q->exp[currRing->VarL_Offset[i]];
210  if (la != lb)
211  {
212  if (la < lb)
213  {
214  if (b) return 0;
215  if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
216  return 0;
217  a = TRUE;
218  }
219  else
220  {
221  if (a) return 0;
222  if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
223  return 0;
224  b = TRUE;
225  }
226  }
227  }
228  if (a) { /*assume(pLmCmp(q,p)==1);*/ return 1; }
229  if (b) { /*assume(pLmCmp(q,p)==-1);*/return -1; }
230  /*assume(pLmCmp(q,p)==0);*/
231  }
232  return 0;
233 }
234 
235 
236 VAR int HCord;
238 VAR int Kstd1_mu=32000;
239 
240 /*2
241 *deletes higher monomial of p, re-compute ecart and length
242 *works only for orderings with ecart =pFDeg(end)-pFDeg(start)
243 */
244 void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
245 {
246  if (strat->kHEdgeFound)
247  {
248  kTest_L(L,strat->tailRing);
249  poly p1;
250  poly p = L->GetLmTailRing();
251  int l = 1;
252  kBucket_pt bucket = NULL;
253  if (L->bucket != NULL)
254  {
255  kBucketClear(L->bucket, &pNext(p), &L->pLength);
256  L->pLength++;
257  bucket = L->bucket;
258  L->bucket = NULL;
259  }
260 
261  if (!fromNext && p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
262  {
263  L->Delete();
264  L->Clear();
265  L->ecart = -1;
266  if (bucket != NULL) kBucketDestroy(&bucket);
267  return;
268  }
269  p1 = p;
270  while (pNext(p1)!=NULL)
271  {
272  if (p_LmCmp(pNext(p1), strat->kNoetherTail(), L->tailRing) == -1)
273  {
274  p_Delete(&pNext(p1), L->tailRing);
275  if (p1 == p)
276  {
277  if (L->t_p != NULL)
278  {
279  assume(L->p != NULL && p == L->t_p);
280  pNext(L->p) = NULL;
281  }
282  L->max_exp = NULL;
283  }
284  else if (fromNext)
285  L->max_exp = p_GetMaxExpP(pNext(L->p), L->tailRing ); // p1;
286  //if (L->pLength != 0)
287  L->pLength = l;
288  // Hmmm when called from updateT, then only
289  // reset ecart when cut
290  if (fromNext)
291  L->ecart = L->pLDeg() - L->GetpFDeg();
292  break;
293  }
294  l++;
295  pIter(p1);
296  }
297  if (! fromNext)
298  {
299  L->SetpFDeg();
300  L->ecart = L->pLDeg(strat->LDegLast) - L->GetpFDeg();
301  }
302  if (bucket != NULL)
303  {
304  if (L->pLength > 1)
305  {
306  kBucketInit(bucket, pNext(p), L->pLength - 1);
307  pNext(p) = NULL;
308  if (L->t_p != NULL) pNext(L->t_p) = NULL;
309  L->pLength = 0;
310  L->bucket = bucket;
311  }
312  else
313  kBucketDestroy(&bucket);
314  }
315  kTest_L(L,strat->tailRing);
316  }
317 }
318 
319 void deleteHC(poly* p, int* e, int* l,kStrategy strat)
320 {
321  LObject L(*p, currRing, strat->tailRing);
322 
323  deleteHC(&L, strat);
324  *p = L.p;
325  *e = L.ecart;
326  *l = L.length;
327  if (L.t_p != NULL) p_LmFree(L.t_p, strat->tailRing);
328 }
329 
330 /*2
331 *tests if p.p=monomial*unit and cancels the unit
332 */
333 void cancelunit (LObject* L,BOOLEAN inNF)
334 {
335  number lc;
336 
337  if(rHasGlobalOrdering (currRing)) return;
338  if(TEST_OPT_CANCELUNIT) return;
339 
340  ring r = L->tailRing;
341  poly p = L->GetLmTailRing();
342  if(p_GetComp(p, r) != 0 && !p_OneComp(p, r)) return;
343 
344  if (rField_is_Ring(r) /*&& (rHasLocalOrMixedOrdering(r))*/)
345  lc = pGetCoeff(p);
346 #ifdef HAVE_RINGS
347  // Leading coef have to be a unit
348  // example 2x+4x2 should be simplified to 2x*(1+2x)
349  // and 2 is not a unit in Z
350  //if ( !(n_IsUnit(pGetCoeff(p), r->cf)) ) return;
351 #endif
352 
353 
354 // for(i=r->N;i>0;i--)
355 // {
356 // if ((p_GetExp(p,i,r)>0) && (rIsPolyVar(i, r)==TRUE)) return;
357 // }
358  poly h = pNext(p);
359  int i;
360 
362  {
363  loop
364  {
365  if (h==NULL)
366  {
367  p_Delete(&pNext(p), r);
368  if (!inNF)
369  {
370  number eins= nCopy(lc);
371  if (L->p != NULL)
372  {
373  pSetCoeff(L->p,eins);
374  if (L->t_p != NULL)
375  pSetCoeff0(L->t_p,eins);
376  }
377  else
378  pSetCoeff(L->t_p,eins);
379  /* p and t_p share the same coeff, if both are !=NULL */
380  /* p==NULL==t_p cannot happen here */
381  }
382  L->ecart = 0;
383  L->length = 1;
384  //if (L->pLength > 0)
385  L->pLength = 1;
386  L->max_exp = NULL;
387 
388  if (L->t_p != NULL && pNext(L->t_p) != NULL)
389  p_Delete(&pNext(L->t_p),r);
390  if (L->p != NULL && pNext(L->p) != NULL)
391  pNext(L->p) = NULL;
392  return;
393  }
394  i = rVar(r);
395  loop
396  {
397  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
398  i--;
399  if (i == 0) break; // does divide, try next monom
400  }
401  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
402  // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
403  // domains), no zerodivisor test needed CAUTION
404  if (!n_DivBy(pGetCoeff(h),lc,r->cf))
405  {
406  return;
407  }
408  pIter(h);
409  }
410  }
411  else
412  {
413  loop
414  {
415  if (h==NULL)
416  {
417  p_Delete(&pNext(p), r);
418  if (!inNF)
419  {
420  number eins=nInit(1);
421  if (L->p != NULL)
422  {
423  pSetCoeff(L->p,eins);
424  if (L->t_p != NULL)
425  pSetCoeff0(L->t_p,eins);
426  }
427  else
428  pSetCoeff(L->t_p,eins);
429  /* p and t_p share the same coeff, if both are !=NULL */
430  /* p==NULL==t_p cannot happen here */
431  }
432  L->ecart = 0;
433  L->length = 1;
434  //if (L->pLength > 0)
435  L->pLength = 1;
436  L->max_exp = NULL;
437 
438  if (L->t_p != NULL && pNext(L->t_p) != NULL)
439  p_Delete(&pNext(L->t_p),r);
440  if (L->p != NULL && pNext(L->p) != NULL)
441  pNext(L->p) = NULL;
442 
443  return;
444  }
445  i = rVar(r);
446  loop
447  {
448  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
449  i--;
450  if (i == 0) break; // does divide, try next monom
451  }
452  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
453  pIter(h);
454  }
455  }
456 }
457 
458 /*2
459 *pp is the new element in s
460 *returns TRUE (in strat->kHEdgeFound) if
461 *-HEcke is allowed
462 *-we are in the last componente of the vector
463 *-on all axis are monomials (all elements in NotUsedAxis are FALSE)
464 *returns FALSE for pLexOrderings,
465 *assumes in module case an ordering of type c* !!
466 * HEckeTest is only called with strat->kHEdgeFound==FALSE !
467 */
468 void HEckeTest (poly pp,kStrategy strat)
469 {
470  int j,/*k,*/p;
471 
472  strat->kHEdgeFound=FALSE;
473  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
474  {
475  return;
476  }
477  if (strat->ak > 1) /*we are in the module case*/
478  {
479  return; // until ....
480  //if (!pVectorOut) /*pVectorOut <=> order = c,* */
481  // return FALSE;
482  //if (pGetComp(pp) < strat->ak) /* ak is the number of the last component */
483  // return FALSE;
484  }
485  // k = 0;
486  p=pIsPurePower(pp);
487  if (rField_is_Ring(currRing) && (!n_IsUnit(pGetCoeff(pp),currRing->cf))) return;
488  if (p!=0) strat->NotUsedAxis[p] = FALSE;
489  /*- the leading term of pp is a power of the p-th variable -*/
490  for (j=(currRing->N);j>0; j--)
491  {
492  if (strat->NotUsedAxis[j])
493  {
494  return;
495  }
496  }
497  strat->kHEdgeFound=TRUE;
498 }
499 
500 /*2
501 *utilities for TSet, LSet
502 */
503 inline static intset initec (const int maxnr)
504 {
505  return (intset)omAlloc(maxnr*sizeof(int));
506 }
507 
508 inline static unsigned long* initsevS (const int maxnr)
509 {
510  return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
511 }
512 inline static int* initS_2_R (const int maxnr)
513 {
514  return (int*)omAlloc0(maxnr*sizeof(int));
515 }
516 
517 static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
518  int &length, const int incr)
519 {
520  assume(T!=NULL);
521  assume(sevT!=NULL);
522  assume(R!=NULL);
523  assume((length+incr) > 0);
524 
525  int i;
526  T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
527  (length+incr)*sizeof(TObject));
528 
529  sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
530  (length+incr)*sizeof(long*));
531 
532  R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
533  (length+incr)*sizeof(TObject*));
534  for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
535  length += incr;
536 }
537 
538 void cleanT (kStrategy strat)
539 {
540  int i,j;
541  poly p;
542  assume(currRing == strat->tailRing || strat->tailRing != NULL);
543 
544  pShallowCopyDeleteProc p_shallow_copy_delete =
545  (strat->tailRing != currRing ?
547  NULL);
548  for (j=0; j<=strat->tl; j++)
549  {
550  p = strat->T[j].p;
551  strat->T[j].p=NULL;
552  if (strat->T[j].max_exp != NULL)
553  {
554  p_LmFree(strat->T[j].max_exp, strat->tailRing);
555  }
556  i = -1;
557  loop
558  {
559  i++;
560  if (i>strat->sl)
561  {
562  if (strat->T[j].t_p != NULL)
563  {
564  p_Delete(&(strat->T[j].t_p), strat->tailRing);
565  p_LmFree(p, currRing);
566  }
567  else
568  {
569 #ifdef HAVE_SHIFTBBA
570  if (currRing->isLPring && strat->T[j].shift > 0)
571  {
572  pNext(p) = NULL; // pNext(p) points to the unshifted tail, don't try to delete it here
573  }
574 #endif
575  pDelete(&p);
576  }
577  break;
578  }
579  if (p == strat->S[i])
580  {
581  if (strat->T[j].t_p != NULL)
582  {
583  if (p_shallow_copy_delete!=NULL)
584  {
585  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
586  currRing->PolyBin);
587  }
588  p_LmFree(strat->T[j].t_p, strat->tailRing);
589  }
590  break;
591  }
592  }
593  }
594  strat->tl=-1;
595 }
596 
598 {
599  int i,j;
600  poly p;
601  assume(currRing == strat->tailRing || strat->tailRing != NULL);
602 
603  pShallowCopyDeleteProc p_shallow_copy_delete =
604  (strat->tailRing != currRing ?
606  NULL);
607  for (j=0; j<=strat->tl; j++)
608  {
609  p = strat->T[j].p;
610  strat->T[j].p=NULL;
611  if (strat->T[j].max_exp != NULL)
612  {
613  p_LmFree(strat->T[j].max_exp, strat->tailRing);
614  }
615  i = -1;
616  loop
617  {
618  i++;
619  if (i>strat->sl)
620  {
621  if (strat->T[j].t_p != NULL)
622  {
623  p_Delete(&(strat->T[j].t_p), strat->tailRing);
624  p_LmFree(p, currRing);
625  }
626  else
627  {
628  //pDelete(&p);
629  p = NULL;
630  }
631  break;
632  }
633  if (p == strat->S[i])
634  {
635  if (strat->T[j].t_p != NULL)
636  {
637  assume(p_shallow_copy_delete != NULL);
638  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
639  currRing->PolyBin);
640  p_LmFree(strat->T[j].t_p, strat->tailRing);
641  }
642  break;
643  }
644  }
645  }
646  strat->tl=-1;
647 }
648 
649 //LSet initL ()
650 //{
651 // int i;
652 // LSet l = (LSet)omAlloc(setmaxL*sizeof(LObject));
653 // return l;
654 //}
655 
656 static inline void enlargeL (LSet* L,int* length,const int incr)
657 {
658  assume((*L)!=NULL);
659  assume(((*length)+incr)>0);
660 
661  *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
662  ((*length)+incr)*sizeof(LObject));
663  (*length) += incr;
664 }
665 
667 {
668  strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
669 }
670 
671 /*2
672 *test whether (p1,p2) or (p2,p1) is in L up position length
673 *it returns TRUE if yes and the position k
674 */
675 BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
676 {
677  LObject *p=&(strat->L[length]);
678 
679  *k = length;
680  loop
681  {
682  if ((*k) < 0) return FALSE;
683  if (((p1 == (*p).p1) && (p2 == (*p).p2))
684  || ((p1 == (*p).p2) && (p2 == (*p).p1)))
685  return TRUE;
686  (*k)--;
687  p--;
688  }
689 }
690 
691 /*2
692 *in B all pairs have the same element p on the right
693 *it tests whether (q,p) is in B and returns TRUE if yes
694 *and the position k
695 */
696 BOOLEAN isInPairsetB(poly q,int* k,kStrategy strat)
697 {
698  LObject *p=&(strat->B[strat->Bl]);
699 
700  *k = strat->Bl;
701  loop
702  {
703  if ((*k) < 0) return FALSE;
704  if (q == (*p).p1)
705  return TRUE;
706  (*k)--;
707  p--;
708  }
709 }
710 
711 int kFindInT(poly p, TSet T, int tlength)
712 {
713  int i;
714 
715  for (i=0; i<=tlength; i++)
716  {
717  if (T[i].p == p) return i;
718  }
719  return -1;
720 }
721 
722 int kFindInT(poly p, kStrategy strat)
723 {
724  int i;
725  do
726  {
727  i = kFindInT(p, strat->T, strat->tl);
728  if (i >= 0) return i;
729  strat = strat->next;
730  }
731  while (strat != NULL);
732  return -1;
733 }
734 
735 #ifdef KDEBUG
736 
737 void sTObject::wrp()
738 {
739  if (t_p != NULL) p_wrp(t_p, tailRing);
740  else if (p != NULL) p_wrp(p, currRing, tailRing);
741  else ::wrp(NULL);
742 }
743 
744 #define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
745 
746 // check that Lm's of a poly from T are "equal"
747 static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
748 {
749  int i;
750  for (i=1; i<=tailRing->N; i++)
751  {
752  if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
753  return "Lm[i] different";
754  }
755  if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
756  return "Lm[0] different";
757  if (pNext(p) != pNext(t_p))
758  return "Lm.next different";
759  if (pGetCoeff(p) != pGetCoeff(t_p))
760  return "Lm.coeff different";
761  return NULL;
762 }
763 
764 STATIC_VAR BOOLEAN sloppy_max = FALSE;
765 BOOLEAN kTest_T(TObject * T, ring strat_tailRing, int i, char TN)
766 {
767  ring tailRing = T->tailRing;
768  if (strat_tailRing == NULL) strat_tailRing = tailRing;
769  r_assume(strat_tailRing == tailRing);
770 
771  poly p = T->p;
772  // ring r = currRing;
773 
774  if (T->p == NULL && T->t_p == NULL && i >= 0)
775  return dReportError("%c[%d].poly is NULL", TN, i);
776 
777  if (T->p!=NULL)
778  {
779  nTest(pGetCoeff(T->p));
780  if ((T->t_p==NULL)&&(pNext(T->p)!=NULL)) p_Test(pNext(T->p),currRing);
781  }
782  if (T->t_p!=NULL)
783  {
784  nTest(pGetCoeff(T->t_p));
785  if (pNext(T->t_p)!=NULL) p_Test(pNext(T->t_p),strat_tailRing);
786  }
787  if ((T->p!=NULL)&&(T->t_p!=NULL)) assume(pGetCoeff(T->p)==pGetCoeff(T->t_p));
788 
789  if (T->tailRing != currRing)
790  {
791  if (T->t_p == NULL && i > 0)
792  return dReportError("%c[%d].t_p is NULL", TN, i);
793  pFalseReturn(p_Test(T->t_p, T->tailRing));
794  if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
795  if (T->p != NULL && T->t_p != NULL)
796  {
797  const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
798  if (msg != NULL)
799  return dReportError("%c[%d] %s", TN, i, msg);
800  // r = T->tailRing;
801  p = T->t_p;
802  }
803  if (T->p == NULL)
804  {
805  p = T->t_p;
806  // r = T->tailRing;
807  }
808  if (T->t_p != NULL && i >= 0 && TN == 'T')
809  {
810  if (pNext(T->t_p) == NULL)
811  {
812  if (T->max_exp != NULL)
813  return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
814  }
815  else
816  {
817  if (T->max_exp == NULL)
818  return dReportError("%c[%d].max_exp is NULL", TN, i);
819  if (pNext(T->max_exp) != NULL)
820  return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
821 
822  pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
823  omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
824 #if KDEBUG > 0
825  if (! sloppy_max)
826  {
827  poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
828  p_Setm(T->max_exp, tailRing);
829  p_Setm(test_max, tailRing);
830  BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
831  if (! equal)
832  return dReportError("%c[%d].max out of sync", TN, i);
833  p_LmFree(test_max, tailRing);
834  }
835 #endif
836  }
837  }
838  }
839  else
840  {
841  if (T->p == NULL && i > 0)
842  return dReportError("%c[%d].p is NULL", TN, i);
843 #ifdef HAVE_SHIFTBBA
844  if (currRing->isLPring && T->shift > 0)
845  {
846  // in this case, the order is not correct. test LM and tail separately
849  }
850  else
851 #endif
852  {
854  }
855  }
856 
857  if ((i >= 0) && (T->pLength != 0)
858  && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
859  {
860  int l=T->pLength;
861  T->pLength=pLength(p);
862  return dReportError("%c[%d] pLength error: has %d, specified to have %d",
863  TN, i , pLength(p), l);
864  }
865 
866  // check FDeg, for elements in L and T
867  if (i >= 0 && (TN == 'T' || TN == 'L'))
868  {
869  // FDeg has ir element from T of L set
870  if (T->FDeg != T->pFDeg())
871  {
872  int d=T->FDeg;
873  T->FDeg=T->pFDeg();
874  return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
875  TN, i , T->pFDeg(), d);
876  }
877  }
878 
879  // check is_normalized for elements in T
880  if (i >= 0 && TN == 'T')
881  {
882  if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
883  return dReportError("T[%d] is_normalized error", i);
884 
885  }
886  return TRUE;
887 }
888 
889 BOOLEAN kTest_L(LObject *L, ring strat_tailRing,
890  BOOLEAN testp, int lpos, TSet T, int tlength)
891 {
892  if (L->p!=NULL)
893  {
894  if ((L->t_p==NULL)
895  &&(pNext(L->p)!=NULL)
896  &&(pGetCoeff(pNext(L->p))!=NULL)) /* !=strat->tail*/
897  {
898  p_Test(pNext(L->p),currRing);
899  nTest(pGetCoeff(L->p));
900  }
901  }
902  if (L->t_p!=NULL)
903  {
904  if ((pNext(L->t_p)!=NULL)
905  &&(pGetCoeff(pNext(L->t_p))!=NULL)) /* !=strat->tail*/
906  {
907  p_Test(pNext(L->t_p),strat_tailRing);
908  nTest(pGetCoeff(L->t_p));
909  }
910  }
911  if ((L->p!=NULL)&&(L->t_p!=NULL)) assume(pGetCoeff(L->p)==pGetCoeff(L->t_p));
912 
913  if (testp)
914  {
915  poly pn = NULL;
916  if (L->bucket != NULL)
917  {
918  kFalseReturn(kbTest(L->bucket));
919  r_assume(L->bucket->bucket_ring == L->tailRing);
920  if (L->p != NULL && pNext(L->p) != NULL)
921  {
922  pn = pNext(L->p);
923  pNext(L->p) = NULL;
924  }
925  }
926  if (testp!=2) kFalseReturn(kTest_T(L, strat_tailRing, lpos, 'L'));
927  if (pn != NULL)
928  pNext(L->p) = pn;
929 
930  ring r;
931  poly p;
932  L->GetLm(p, r);
933  if (L->sev != 0 && p_GetShortExpVector(p, r) != L->sev)
934  {
935  return dReportError("L[%d] wrong sev: has %o, specified to have %o",
936  lpos, p_GetShortExpVector(p, r), L->sev);
937  }
938  }
939  if (L->p1 == NULL)
940  {
941  // L->p2 either NULL or "normal" poly
942  pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
943  }
944  else if (tlength > 0 && T != NULL && (lpos >=0) && (testp!=2))
945  {
946  // now p1 and p2 must be != NULL and must be contained in T
947  // unless for SHIFTGB: here each p_i must be in T or
948  // be shifted from an element in T -> to difficult to test
949  int i;
950  i = kFindInT(L->p1, T, tlength);
951  if (i < 0)
952  return dReportError("L[%d].p1 not in T",lpos);
953  i = kFindInT(L->p2, T, tlength);
954  if (i < 0)
955  return dReportError("L[%d].p2 not in T",lpos);
956  }
957  return TRUE;
958 }
959 
960 BOOLEAN kTest (kStrategy strat)
961 {
962  int i;
963  // test P
964  kFalseReturn(kTest_L(&(strat->P), strat->tailRing,
965  (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
966  -1, strat->T, strat->tl));
967 
968  // test T
969  if (strat->T != NULL)
970  {
971  for (i=0; i<=strat->tl; i++)
972  {
973  kFalseReturn(kTest_T(&(strat->T[i]), strat->tailRing, i, 'T'));
974  if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
975  return dReportError("strat->sevT[%d] out of sync", i);
976  }
977  }
978 
979  // test L
980  if (strat->L != NULL)
981  {
982  #ifdef HAVE_SHIFTBBA
983  if (strat->red==redFirstShift) // is this in bbaShift ?
984  {
985  for (i=0; i<=strat->Ll; i++)
986  {
987  kFalseReturn(kTest_L(&(strat->L[i]), strat->tailRing,
988  2, i,
989  strat->T, strat->tl));
990  }
991  }
992  else
993  #endif
994  for (i=0; i<=strat->Ll; i++)
995  {
996  kFalseReturn(kTest_L(&(strat->L[i]), strat->tailRing,
997  strat->L[i].Next() != strat->tail, i,
998  strat->T, strat->tl));
999  // may be unused
1000  //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
1001  // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
1002  //{
1003  // assume(strat->L[i].bucket != NULL);
1004  //}
1005  }
1006  }
1007 
1008  // test S
1009  if (strat->S != NULL)
1010  kFalseReturn(kTest_S(strat));
1011 
1012  return TRUE;
1013 }
1014 
1015 BOOLEAN kTest_S(kStrategy strat)
1016 {
1017  int i;
1018  BOOLEAN ret = TRUE;
1019  for (i=0; i<=strat->sl; i++)
1020  {
1021  if (strat->S[i] != NULL &&
1022  strat->sevS[i] != pGetShortExpVector(strat->S[i]))
1023  {
1024  return dReportError("S[%d] wrong sev: has %o, specified to have %o",
1025  i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
1026  }
1027  }
1028  return ret;
1029 }
1030 
1031 
1032 
1033 BOOLEAN kTest_TS(kStrategy strat)
1034 {
1035  int i, j;
1036  // BOOLEAN ret = TRUE;
1037  kFalseReturn(kTest(strat));
1038 
1039  // test strat->R, strat->T[i].i_r
1040  for (i=0; i<=strat->tl; i++)
1041  {
1042  if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1043  return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1044  strat->T[i].i_r);
1045  if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1046  return dReportError("T[%d].i_r with R out of sync", i);
1047  }
1048  // test containment of S inT
1049  if (strat->S != NULL)
1050  {
1051  for (i=0; i<=strat->sl; i++)
1052  {
1053  j = kFindInT(strat->S[i], strat->T, strat->tl);
1054  if (j < 0)
1055  return dReportError("S[%d] not in T", i);
1056  if (strat->S_2_R[i] != strat->T[j].i_r)
1057  return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1058  i, strat->S_2_R[i], j, strat->T[j].i_r);
1059  }
1060  }
1061  // test strat->L[i].i_r1
1062  #ifdef HAVE_SHIFTBBA
1063  if (strat->red!=redFirstShift) // not from bbaShift
1064  #endif
1065  for (i=0; i<=strat->Ll; i++)
1066  {
1067  if (strat->L[i].p1 != NULL && strat->L[i].p2)
1068  {
1069  if (strat->L[i].i_r1 < 0 ||
1070  strat->L[i].i_r1 > strat->tl ||
1071  strat->L[i].T_1(strat)->p != strat->L[i].p1)
1072  return dReportError("L[%d].i_r1 out of sync", i);
1073  if (strat->L[i].i_r2 < 0 ||
1074  strat->L[i].i_r2 > strat->tl ||
1075  strat->L[i].T_2(strat)->p != strat->L[i].p2)
1076  return dReportError("L[%d].i_r2 out of sync", i);
1077  }
1078  else
1079  {
1080  if (strat->L[i].i_r1 != -1)
1081  return dReportError("L[%d].i_r1 out of sync", i);
1082  if (strat->L[i].i_r2 != -1)
1083  return dReportError("L[%d].i_r2 out of sync", i);
1084  }
1085  if (strat->L[i].i_r != -1)
1086  return dReportError("L[%d].i_r out of sync", i);
1087  }
1088  return TRUE;
1089 }
1090 
1091 #endif // KDEBUG
1092 
1093 /*2
1094 *cancels the i-th polynomial in the standardbase s
1095 */
1096 void deleteInS (int i,kStrategy strat)
1097 {
1098 #ifdef ENTER_USE_MEMMOVE
1099  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1100  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1101  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1102  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1103 #else
1104  int j;
1105  for (j=i; j<strat->sl; j++)
1106  {
1107  strat->S[j] = strat->S[j+1];
1108  strat->ecartS[j] = strat->ecartS[j+1];
1109  strat->sevS[j] = strat->sevS[j+1];
1110  strat->S_2_R[j] = strat->S_2_R[j+1];
1111  }
1112 #endif
1113  if (strat->lenS!=NULL)
1114  {
1115 #ifdef ENTER_USE_MEMMOVE
1116  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1117 #else
1118  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1119 #endif
1120  }
1121  if (strat->lenSw!=NULL)
1122  {
1123 #ifdef ENTER_USE_MEMMOVE
1124  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1125 #else
1126  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1127 #endif
1128  }
1129  if (strat->fromQ!=NULL)
1130  {
1131 #ifdef ENTER_USE_MEMMOVE
1132  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1133 #else
1134  for (j=i; j<strat->sl; j++)
1135  {
1136  strat->fromQ[j] = strat->fromQ[j+1];
1137  }
1138 #endif
1139  }
1140  strat->S[strat->sl] = NULL;
1141  strat->sl--;
1142 }
1143 
1144 
1145 /*2
1146 *cancels the i-th polynomial in the standardbase s
1147 */
1148 void deleteInSSba (int i,kStrategy strat)
1149 {
1150 #ifdef ENTER_USE_MEMMOVE
1151  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1152  memmove(&(strat->sig[i]), &(strat->sig[i+1]), (strat->sl - i)*sizeof(poly));
1153  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1154  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1155  memmove(&(strat->sevSig[i]),&(strat->sevSig[i+1]),(strat->sl - i)*sizeof(unsigned long));
1156  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1157 #else
1158  int j;
1159  for (j=i; j<strat->sl; j++)
1160  {
1161  strat->S[j] = strat->S[j+1];
1162  strat->sig[j] = strat->sig[j+1];
1163  strat->ecartS[j] = strat->ecartS[j+1];
1164  strat->sevS[j] = strat->sevS[j+1];
1165  strat->sevSig[j] = strat->sevSig[j+1];
1166  strat->S_2_R[j] = strat->S_2_R[j+1];
1167  }
1168 #endif
1169  if (strat->lenS!=NULL)
1170  {
1171 #ifdef ENTER_USE_MEMMOVE
1172  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1173 #else
1174  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1175 #endif
1176  }
1177  if (strat->lenSw!=NULL)
1178  {
1179 #ifdef ENTER_USE_MEMMOVE
1180  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1181 #else
1182  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1183 #endif
1184  }
1185  if (strat->fromQ!=NULL)
1186  {
1187 #ifdef ENTER_USE_MEMMOVE
1188  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1189 #else
1190  for (j=i; j<strat->sl; j++)
1191  {
1192  strat->fromQ[j] = strat->fromQ[j+1];
1193  }
1194 #endif
1195  }
1196  strat->S[strat->sl] = NULL;
1197  strat->sl--;
1198 }
1199 
1200 /*2
1201 *cancels the j-th polynomial in the set
1202 */
1203 void deleteInL (LSet set, int *length, int j,kStrategy strat)
1204 {
1205  if (set[j].lcm!=NULL)
1206  {
1207  kDeleteLcm(&set[j]);
1208  }
1209  if (set[j].sig!=NULL)
1210  {
1211 #ifdef HAVE_RINGS
1212  if (pGetCoeff(set[j].sig) != NULL)
1213  pLmDelete(set[j].sig);
1214  else
1215 #endif
1216  pLmFree(set[j].sig);
1217  }
1218  if (set[j].p!=NULL)
1219  {
1220  if (pNext(set[j].p) == strat->tail)
1221  {
1222 #ifdef HAVE_RINGS
1223  if (pGetCoeff(set[j].p) != NULL)
1224  pLmDelete(set[j].p);
1225  else
1226 #endif
1227  pLmFree(set[j].p);
1228  /*- tail belongs to several int spolys -*/
1229  }
1230  else
1231  {
1232  // search p in T, if it is there, do not delete it
1233  if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1234  {
1235  // assure that for global orderings kFindInT fails
1236  //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1237  set[j].Delete();
1238  }
1239  }
1240  }
1241  if (*length > 0 && j < *length)
1242  {
1243 #ifdef ENTER_USE_MEMMOVE
1244  memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1245 #else
1246  int i;
1247  for (i=j; i < (*length); i++)
1248  set[i] = set[i+1];
1249 #endif
1250  }
1251 #ifdef KDEBUG
1252  memset(&(set[*length]),0,sizeof(LObject));
1253 #endif
1254  (*length)--;
1255 }
1256 
1257 /*2
1258 *enters p at position at in L
1259 */
1260 void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1261 {
1262  // this should be corrected
1263  assume(p.FDeg == p.pFDeg());
1264 
1265  if ((*length)>=0)
1266  {
1267  if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1268  if (at <= (*length))
1269 #ifdef ENTER_USE_MEMMOVE
1270  memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1271 #else
1272  for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1273 #endif
1274  }
1275  else at = 0;
1276  (*set)[at] = p;
1277  (*length)++;
1278 }
1279 
1280 /*2
1281 * computes the normal ecart;
1282 * used in mora case and if pLexOrder & sugar in bba case
1283 */
1285 {
1286  h->FDeg = h->pFDeg();
1287  h->ecart = h->pLDeg() - h->FDeg;
1288  // h->length is set by h->pLDeg
1289  h->length=h->pLength=pLength(h->p);
1290 }
1291 
1293 {
1294  h->FDeg = h->pFDeg();
1295  (*h).ecart = 0;
1296  h->length=h->pLength=pLength(h->p);
1297 }
1298 
1299 void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1300 {
1301  Lp->FDeg = Lp->pFDeg();
1302  (*Lp).ecart = 0;
1303  (*Lp).length = 0;
1304 }
1305 
1306 void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1307 {
1308  Lp->FDeg = Lp->pFDeg();
1309  (*Lp).ecart = si_max(ecartF,ecartG);
1310  (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1311  (*Lp).length = 0;
1312 }
1313 
1314 /*2
1315 *if ecart1<=ecart2 it returns TRUE
1316 */
1317 static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1318 {
1319  return (ecart1 <= ecart2);
1320 }
1321 
1322 #ifdef HAVE_RINGS
1323 /*2
1324 * put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1325 */
1326 static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1327 {
1328  assume(atR >= 0);
1329  assume(i<=strat->sl);
1330  assume(p!=NULL);
1332  #if ALL_VS_JUST
1333  //Over rings, if we construct the strong pair, do not add the spair
1335  {
1336  number s,t,d;
1337  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1338 
1339  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1340  {
1341  nDelete(&d);
1342  nDelete(&s);
1343  nDelete(&t);
1344  return;
1345  }
1346  nDelete(&d);
1347  nDelete(&s);
1348  nDelete(&t);
1349  }
1350  #endif
1351  int j,compare,compareCoeff;
1352  LObject h;
1353 
1354 #ifdef KDEBUG
1355  h.ecart=0; h.length=0;
1356 #endif
1357  /*- computes the lcm(s[i],p) -*/
1358  if(pHasNotCFRing(p,strat->S[i]))
1359  {
1360  strat->cp++;
1361  return;
1362  }
1363  h.lcm = p_Lcm(p,strat->S[i],currRing);
1364  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1365  if (nIsZero(pGetCoeff(h.lcm)))
1366  {
1367  strat->cp++;
1368  pLmDelete(h.lcm);
1369  return;
1370  }
1371  // basic chain criterion
1372  /*
1373  *the set B collects the pairs of type (S[j],p)
1374  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1375  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
1376  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
1377  */
1378 
1379  for(j = strat->Bl;j>=0;j--)
1380  {
1381  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1382  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1383  if(compare == pDivComp_EQUAL)
1384  {
1385  //They have the same LM
1386  if(compareCoeff == pDivComp_LESS)
1387  {
1388  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1389  {
1390  strat->c3++;
1391  pLmDelete(h.lcm);
1392  return;
1393  }
1394  break;
1395  }
1396  if(compareCoeff == pDivComp_GREATER)
1397  {
1398  deleteInL(strat->B,&strat->Bl,j,strat);
1399  strat->c3++;
1400  }
1401  if(compareCoeff == pDivComp_EQUAL)
1402  {
1403  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1404  {
1405  strat->c3++;
1406  pLmDelete(h.lcm);
1407  return;
1408  }
1409  break;
1410  }
1411  }
1412  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1413  {
1414  if(compare == pDivComp_LESS)
1415  {
1416  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1417  {
1418  strat->c3++;
1419  pLmDelete(h.lcm);
1420  return;
1421  }
1422  break;
1423  }
1424  if(compare == pDivComp_GREATER)
1425  {
1426  deleteInL(strat->B,&strat->Bl,j,strat);
1427  strat->c3++;
1428  }
1429  }
1430  }
1431  number s, t;
1432  poly m1, m2, gcd = NULL;
1433  s = pGetCoeff(strat->S[i]);
1434  t = pGetCoeff(p);
1435  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1436  ksCheckCoeff(&s, &t, currRing->cf);
1437  pSetCoeff0(m1, s);
1438  pSetCoeff0(m2, t);
1439  m2 = pNeg(m2);
1440  p_Test(m1,strat->tailRing);
1441  p_Test(m2,strat->tailRing);
1442  poly si = pCopy(strat->S[i]);
1443  poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1444  poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1445  pDelete(&si);
1446  p_LmDelete(m1, currRing);
1447  p_LmDelete(m2, currRing);
1448  if(sim2 == NULL)
1449  {
1450  if(pm1 == NULL)
1451  {
1452  if(h.lcm != NULL)
1453  {
1454  pLmDelete(h.lcm);
1455  h.lcm=NULL;
1456  }
1457  h.Clear();
1458  if (strat->pairtest==NULL) initPairtest(strat);
1459  strat->pairtest[i] = TRUE;
1460  strat->pairtest[strat->sl+1] = TRUE;
1461  return;
1462  }
1463  else
1464  {
1465  gcd = pm1;
1466  pm1 = NULL;
1467  }
1468  }
1469  else
1470  {
1471  if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1472  {
1473  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1474  pSetmComp(sim2);
1475  }
1476  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1477  gcd = p_Add_q(pm1, sim2, strat->tailRing);
1478  }
1479  p_Test(gcd, strat->tailRing);
1480 #ifdef KDEBUG
1481  if (TEST_OPT_DEBUG)
1482  {
1483  wrp(gcd);
1484  PrintLn();
1485  }
1486 #endif
1487  h.p = gcd;
1488  h.i_r = -1;
1489  if(h.p == NULL)
1490  {
1491  if (strat->pairtest==NULL) initPairtest(strat);
1492  strat->pairtest[i] = TRUE;
1493  strat->pairtest[strat->sl+1] = TRUE;
1494  return;
1495  }
1496  h.tailRing = strat->tailRing;
1497  int posx;
1498  //h.pCleardenom();
1499  //pSetm(h.p);
1500  h.i_r1 = -1;h.i_r2 = -1;
1501  strat->initEcart(&h);
1502  #if 1
1503  h.p2 = strat->S[i];
1504  h.p1 = p;
1505  #endif
1506  #if 1
1507  if (atR >= 0)
1508  {
1509  h.i_r1 = atR;
1510  h.i_r2 = strat->S_2_R[i];
1511  }
1512  #endif
1513  if (strat->Bl==-1)
1514  posx =0;
1515  else
1516  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1517  h.sev = pGetShortExpVector(h.p);
1518  if (currRing!=strat->tailRing)
1519  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1520  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1521  kTest_TS(strat);
1522 }
1523 
1524 /*2
1525 * put the lcm(s[i],p) into the set B
1526 */
1527 
1528 static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1529 {
1530  number d, s, t;
1531  assume(atR >= 0);
1533  poly m1, m2, gcd,si;
1534  if(!enterTstrong)
1535  {
1536  assume(i<=strat->sl);
1537  si = strat->S[i];
1538  }
1539  else
1540  {
1541  assume(i<=strat->tl);
1542  si = strat->T[i].p;
1543  }
1544  //printf("\n--------------------------------\n");
1545  //pWrite(p);pWrite(si);
1546  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1547 
1548  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1549  {
1550  nDelete(&d);
1551  nDelete(&s);
1552  nDelete(&t);
1553  return FALSE;
1554  }
1555 
1556  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1557 
1559  unsigned long sev = pGetShortExpVector(gcd);
1560 
1561  for (int j = 0; j < strat->sl; j++) {
1562  if (j == i)
1563  continue;
1564 
1565  if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) &&
1566  !(strat->sevS[j] & ~sev) &&
1567  p_LmDivisibleBy(strat->S[j], gcd, currRing)) {
1568  nDelete(&d);
1569  nDelete(&s);
1570  nDelete(&t);
1571  return FALSE;
1572  }
1573  }
1574  }
1575 
1576  //p_Test(m1,strat->tailRing);
1577  //p_Test(m2,strat->tailRing);
1578  /*if(!enterTstrong)
1579  {
1580  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1581  {
1582  memset(&(strat->P), 0, sizeof(strat->P));
1583  kStratChangeTailRing(strat);
1584  strat->P = *(strat->R[atR]);
1585  p_LmFree(m1, strat->tailRing);
1586  p_LmFree(m2, strat->tailRing);
1587  p_LmFree(gcd, currRing);
1588  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1589  }
1590  }*/
1591  pSetCoeff0(m1, s);
1592  pSetCoeff0(m2, t);
1593  pSetCoeff0(gcd, d);
1594  p_Test(m1,strat->tailRing);
1595  p_Test(m2,strat->tailRing);
1596  //printf("\n===================================\n");
1597  //pWrite(m1);pWrite(m2);pWrite(gcd);
1598 #ifdef KDEBUG
1599  if (TEST_OPT_DEBUG)
1600  {
1601  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1602  PrintS("m1 = ");
1603  p_wrp(m1, strat->tailRing);
1604  PrintS(" ; m2 = ");
1605  p_wrp(m2, strat->tailRing);
1606  PrintS(" ; gcd = ");
1607  wrp(gcd);
1608  PrintS("\n--- create strong gcd poly: ");
1609  Print("\n p: %d", i);
1610  wrp(p);
1611  Print("\n strat->S[%d]: ", i);
1612  wrp(si);
1613  PrintS(" ---> ");
1614  }
1615 #endif
1616 
1617  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1618  p_LmDelete(m1, strat->tailRing);
1619  p_LmDelete(m2, strat->tailRing);
1620 #ifdef KDEBUG
1621  if (TEST_OPT_DEBUG)
1622  {
1623  wrp(gcd);
1624  PrintLn();
1625  }
1626 #endif
1627 
1628  LObject h;
1629  h.p = gcd;
1630  h.tailRing = strat->tailRing;
1631  int posx;
1632  h.pCleardenom();
1633  strat->initEcart(&h);
1634  h.sev = pGetShortExpVector(h.p);
1635  h.i_r1 = -1;h.i_r2 = -1;
1636  if (currRing!=strat->tailRing)
1637  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1638  if(!enterTstrong)
1639  {
1640  #if 1
1641  h.p1 = p;h.p2 = strat->S[i];
1642  #endif
1643  if (atR >= 0)
1644  {
1645  h.i_r2 = strat->S_2_R[i];
1646  h.i_r1 = atR;
1647  }
1648  else
1649  {
1650  h.i_r1 = -1;
1651  h.i_r2 = -1;
1652  }
1653  if (strat->Ll==-1)
1654  posx =0;
1655  else
1656  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1657  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1658  }
1659  else
1660  {
1661  if(h.IsNull()) return FALSE;
1662  //int red_result;
1663  //reduzieren ist teur!!!
1664  //if(strat->L != NULL)
1665  //red_result = strat->red(&h,strat);
1666  if(!h.IsNull())
1667  {
1668  enterT(h, strat,-1);
1669  //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1670  //strat->enterS(h,pos,strat,-1);
1671  }
1672  }
1673  return TRUE;
1674 }
1675 
1677 {
1678  if(strat->sl < 0) return FALSE;
1679  int i;
1680  for(i=0;i<strat->sl;i++)
1681  {
1682  //Construct the gcd pair between h and S[i]
1683  number d, s, t;
1684  poly m1, m2, gcd;
1685  d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1686  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1687  {
1688  nDelete(&d);
1689  nDelete(&s);
1690  nDelete(&t);
1691  }
1692  else
1693  {
1694  k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1695  pSetCoeff0(m1, s);
1696  pSetCoeff0(m2, t);
1697  pSetCoeff0(gcd, d);
1698  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);
1699  poly pSigMult = p_Copy(h->sig,currRing);
1700  poly sSigMult = p_Copy(strat->sig[i],currRing);
1701  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1702  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1703  p_LmDelete(m1, strat->tailRing);
1704  p_LmDelete(m2, strat->tailRing);
1705  poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1706  if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1707  {
1708  pDelete(&h->p);
1709  h->p = gcd;
1710  pDelete(&h->sig);
1711  h->sig = pairsig;
1712  pNext(h->sig) = NULL;
1713  strat->initEcart(h);
1714  h->sev = pGetShortExpVector(h->p);
1715  h->sevSig = pGetShortExpVector(h->sig);
1716  h->i_r1 = -1;h->i_r2 = -1;
1717  if(h->lcm != NULL)
1718  {
1719  pLmDelete(h->lcm);
1720  h->lcm = NULL;
1721  }
1722  if (currRing!=strat->tailRing)
1723  h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1724  return TRUE;
1725  }
1726  //Delete what you didn't use
1727  pDelete(&gcd);
1728  pDelete(&pairsig);
1729  }
1730  }
1731  return FALSE;
1732 }
1733 
1734 static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1735 {
1736  number d, s, t;
1737  assume(atR >= 0);
1738  poly m1, m2, gcd,si;
1739  assume(i<=strat->sl);
1740  si = strat->S[i];
1741  //printf("\n--------------------------------\n");
1742  //pWrite(p);pWrite(si);
1743  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1744 
1745  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1746  {
1747  nDelete(&d);
1748  nDelete(&s);
1749  nDelete(&t);
1750  return FALSE;
1751  }
1752 
1753  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1754  //p_Test(m1,strat->tailRing);
1755  //p_Test(m2,strat->tailRing);
1756  /*if(!enterTstrong)
1757  {
1758  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1759  {
1760  memset(&(strat->P), 0, sizeof(strat->P));
1761  kStratChangeTailRing(strat);
1762  strat->P = *(strat->R[atR]);
1763  p_LmFree(m1, strat->tailRing);
1764  p_LmFree(m2, strat->tailRing);
1765  p_LmFree(gcd, currRing);
1766  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1767  }
1768  }*/
1769  pSetCoeff0(m1, s);
1770  pSetCoeff0(m2, t);
1771  pSetCoeff0(gcd, d);
1772  p_Test(m1,strat->tailRing);
1773  p_Test(m2,strat->tailRing);
1774  //printf("\n===================================\n");
1775  //pWrite(m1);pWrite(m2);pWrite(gcd);
1776 #ifdef KDEBUG
1777  if (TEST_OPT_DEBUG)
1778  {
1779  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1780  PrintS("m1 = ");
1781  p_wrp(m1, strat->tailRing);
1782  PrintS(" ; m2 = ");
1783  p_wrp(m2, strat->tailRing);
1784  PrintS(" ; gcd = ");
1785  wrp(gcd);
1786  PrintS("\n--- create strong gcd poly: ");
1787  Print("\n p: %d", i);
1788  wrp(p);
1789  Print("\n strat->S[%d]: ", i);
1790  wrp(si);
1791  PrintS(" ---> ");
1792  }
1793 #endif
1794 
1795  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1796 
1797 #ifdef KDEBUG
1798  if (TEST_OPT_DEBUG)
1799  {
1800  wrp(gcd);
1801  PrintLn();
1802  }
1803 #endif
1804 
1805  //Check and set the signatures
1806  poly pSigMult = p_Copy(sig,currRing);
1807  poly sSigMult = p_Copy(strat->sig[i],currRing);
1808  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1809  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1810  p_LmDelete(m1, strat->tailRing);
1811  p_LmDelete(m2, strat->tailRing);
1812  poly pairsig;
1813  if(pLmCmp(pSigMult,sSigMult) == 0)
1814  {
1815  //Same lm, have to add them
1816  pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1817  //This might be zero
1818  }
1819  else
1820  {
1821  //Set the sig to either pSigMult or sSigMult
1822  if(pLtCmp(pSigMult,sSigMult)==1)
1823  {
1824  pairsig = pSigMult;
1825  pDelete(&sSigMult);
1826  }
1827  else
1828  {
1829  pairsig = sSigMult;
1830  pDelete(&pSigMult);
1831  }
1832  }
1833 
1834  LObject h;
1835  h.p = gcd;
1836  h.tailRing = strat->tailRing;
1837  h.sig = pairsig;
1838  int posx;
1839  h.pCleardenom();
1840  strat->initEcart(&h);
1841  h.sev = pGetShortExpVector(h.p);
1842  h.i_r1 = -1;h.i_r2 = -1;
1843  if (currRing!=strat->tailRing)
1844  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1845  if(h.sig == NULL)
1846  {
1847  //sigdrop since we loose the signature
1848  strat->sigdrop = TRUE;
1849  //Try to reduce it as far as we can via redRing
1850  int red_result = redRing(&h,strat);
1851  if(red_result == 0)
1852  {
1853  // Cancel the sigdrop
1854  p_Delete(&h.sig,currRing);h.sig = NULL;
1855  strat->sigdrop = FALSE;
1856  return FALSE;
1857  }
1858  else
1859  {
1860  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1861  #if 1
1862  strat->enterS(h,0,strat,strat->tl);
1863  #endif
1864  return FALSE;
1865  }
1866  }
1867  if(!nGreaterZero(pGetCoeff(h.sig)))
1868  {
1869  h.sig = pNeg(h.sig);
1870  h.p = pNeg(h.p);
1871  }
1872 
1873  if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1874  {
1875  strat->sigdrop = TRUE;
1876  // Completely reduce it
1877  int red_result = redRing(&h,strat);
1878  if(red_result == 0)
1879  {
1880  // Reduced to 0
1881  strat->sigdrop = FALSE;
1882  p_Delete(&h.sig,currRing);h.sig = NULL;
1883  return FALSE;
1884  }
1885  else
1886  {
1887  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1888  // 0 - add just the original poly causing the sigdrop, 1 - add also this
1889  #if 1
1890  strat->enterS(h,0,strat, strat->tl+1);
1891  #endif
1892  return FALSE;
1893  }
1894  }
1895  //Check for sigdrop
1896  if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1897  {
1898  strat->sigdrop = TRUE;
1899  //Enter this element to S
1900  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1901  strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1902  }
1903  #if 1
1904  h.p1 = p;h.p2 = strat->S[i];
1905  #endif
1906  if (atR >= 0)
1907  {
1908  h.i_r2 = strat->S_2_R[i];
1909  h.i_r1 = atR;
1910  }
1911  else
1912  {
1913  h.i_r1 = -1;
1914  h.i_r2 = -1;
1915  }
1916  if (strat->Ll==-1)
1917  posx =0;
1918  else
1919  posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1920  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1921  return TRUE;
1922 }
1923 #endif
1924 
1925 /*2
1926 * put the pair (s[i],p) into the set B, ecart=ecart(p)
1927 */
1928 
1929 void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1930 {
1931  assume(i<=strat->sl);
1932 
1933  int l,j,compare;
1934  LObject Lp;
1935  Lp.i_r = -1;
1936 
1937 #ifdef KDEBUG
1938  Lp.ecart=0; Lp.length=0;
1939 #endif
1940  /*- computes the lcm(s[i],p) -*/
1941  Lp.lcm = pInit();
1942 
1943 #ifndef HAVE_RATGRING
1944  pLcm(p,strat->S[i],Lp.lcm);
1945 #elif defined(HAVE_RATGRING)
1946  if (rIsRatGRing(currRing))
1947  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1948  else
1949  pLcm(p,strat->S[i],Lp.lcm);
1950 #endif
1951  pSetm(Lp.lcm);
1952 
1953 
1954  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
1955  {
1956  if((!((strat->ecartS[i]>0)&&(ecart>0)))
1957  && pHasNotCF(p,strat->S[i]))
1958  {
1959  /*
1960  *the product criterion has applied for (s,p),
1961  *i.e. lcm(s,p)=product of the leading terms of s and p.
1962  *Suppose (s,r) is in L and the leading term
1963  *of p divides lcm(s,r)
1964  *(==> the leading term of p divides the leading term of r)
1965  *but the leading term of s does not divide the leading term of r
1966  *(notice that tis condition is automatically satisfied if r is still
1967  *in S), then (s,r) can be cancelled.
1968  *This should be done here because the
1969  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1970  *
1971  *Moreover, skipping (s,r) holds also for the noncommutative case.
1972  */
1973  strat->cp++;
1974  pLmFree(Lp.lcm);
1975  return;
1976  }
1977  else
1978  Lp.ecart = si_max(ecart,strat->ecartS[i]);
1979  if (strat->fromT && (strat->ecartS[i]>ecart))
1980  {
1981  pLmFree(Lp.lcm);
1982  return;
1983  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
1984  }
1985  /*
1986  *the set B collects the pairs of type (S[j],p)
1987  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
1988  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
1989  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
1990  */
1991  {
1992  j = strat->Bl;
1993  loop
1994  {
1995  if (j < 0) break;
1996  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
1997  if ((compare==1)
1998  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
1999  {
2000  strat->c3++;
2001  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2002  {
2003  pLmFree(Lp.lcm);
2004  return;
2005  }
2006  break;
2007  }
2008  else
2009  if ((compare ==-1)
2010  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2011  {
2012  deleteInL(strat->B,&strat->Bl,j,strat);
2013  strat->c3++;
2014  }
2015  j--;
2016  }
2017  }
2018  }
2019  else /*sugarcrit*/
2020  {
2021  if (ALLOW_PROD_CRIT(strat))
2022  {
2023  // if currRing->nc_type!=quasi (or skew)
2024  // TODO: enable productCrit for super commutative algebras...
2025  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2026  pHasNotCF(p,strat->S[i]))
2027  {
2028  /*
2029  *the product criterion has applied for (s,p),
2030  *i.e. lcm(s,p)=product of the leading terms of s and p.
2031  *Suppose (s,r) is in L and the leading term
2032  *of p devides lcm(s,r)
2033  *(==> the leading term of p devides the leading term of r)
2034  *but the leading term of s does not devide the leading term of r
2035  *(notice that tis condition is automatically satisfied if r is still
2036  *in S), then (s,r) can be canceled.
2037  *This should be done here because the
2038  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2039  */
2040  strat->cp++;
2041  pLmFree(Lp.lcm);
2042  return;
2043  }
2044  if (strat->fromT && (strat->ecartS[i]>ecart))
2045  {
2046  pLmFree(Lp.lcm);
2047  return;
2048  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2049  }
2050  /*
2051  *the set B collects the pairs of type (S[j],p)
2052  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2053  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2054  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2055  */
2056  for(j = strat->Bl;j>=0;j--)
2057  {
2058  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2059  if (compare==1)
2060  {
2061  strat->c3++;
2062  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2063  {
2064  pLmFree(Lp.lcm);
2065  return;
2066  }
2067  break;
2068  }
2069  else
2070  if (compare ==-1)
2071  {
2072  deleteInL(strat->B,&strat->Bl,j,strat);
2073  strat->c3++;
2074  }
2075  }
2076  }
2077  }
2078  /*
2079  *the pair (S[i],p) enters B if the spoly != 0
2080  */
2081  /*- compute the short s-polynomial -*/
2082  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2083  pNorm(p);
2084 
2085  if ((strat->S[i]==NULL) || (p==NULL))
2086  return;
2087 
2088  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2089  Lp.p=NULL;
2090  else
2091  {
2092  #ifdef HAVE_PLURAL
2093  if ( rIsPluralRing(currRing) )
2094  {
2095  if(pHasNotCF(p, strat->S[i]))
2096  {
2097  if(ncRingType(currRing) == nc_lie)
2098  {
2099  // generalized prod-crit for lie-type
2100  strat->cp++;
2101  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2102  }
2103  else
2104  if( ALLOW_PROD_CRIT(strat) )
2105  {
2106  // product criterion for homogeneous case in SCA
2107  strat->cp++;
2108  Lp.p = NULL;
2109  }
2110  else
2111  {
2112  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2113  nc_CreateShortSpoly(strat->S[i], p, currRing);
2114  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2115  pNext(Lp.p) = strat->tail; // !!!
2116  }
2117  }
2118  else
2119  {
2120  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2121  nc_CreateShortSpoly(strat->S[i], p, currRing);
2122 
2123  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2124  pNext(Lp.p) = strat->tail; // !!!
2125  }
2126  }
2127  else
2128  #endif
2129  {
2131  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2132  }
2133  }
2134  if (Lp.p == NULL)
2135  {
2136  /*- the case that the s-poly is 0 -*/
2137  if (strat->pairtest==NULL) initPairtest(strat);
2138  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2139  strat->pairtest[strat->sl+1] = TRUE;
2140  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2141  /*
2142  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2143  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2144  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2145  *term of p devides the lcm(s,r)
2146  *(this canceling should be done here because
2147  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2148  *the first case is handeled in chainCrit
2149  */
2150  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2151  }
2152  else
2153  {
2154  /*- the pair (S[i],p) enters B -*/
2155  Lp.p1 = strat->S[i];
2156  Lp.p2 = p;
2157 
2158  if (
2160 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2161  )
2162  {
2163  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2164  pNext(Lp.p) = strat->tail; // !!!
2165  }
2166 
2167  if (atR >= 0)
2168  {
2169  Lp.i_r1 = strat->S_2_R[i];
2170  Lp.i_r2 = atR;
2171  }
2172  else
2173  {
2174  Lp.i_r1 = -1;
2175  Lp.i_r2 = -1;
2176  }
2177  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2178 
2180  {
2181  if (!rIsPluralRing(currRing)
2183  && (Lp.p->coef!=NULL))
2184  nDelete(&(Lp.p->coef));
2185  }
2186 
2187  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2188  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2189  }
2190 }
2191 
2192 /// p_HasNotCF for the IDLIFT case: ignore component
2193 static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2194 {
2195  int i = rVar(r);
2196  loop
2197  {
2198  if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2199  return FALSE;
2200  i--;
2201  if (i == 0)
2202  return TRUE;
2203  }
2204 }
2205 
2206 /*2
2207 * put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2208 */
2209 
2210 static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2211 {
2212  assume(ALLOW_PROD_CRIT(strat));
2214  assume(strat->syzComp==1);
2215  assume(i<=strat->sl);
2216 
2217  if ((strat->S[i]==NULL) || (p==NULL))
2218  return;
2219 
2220  int l,j,compare;
2221  LObject Lp;
2222  Lp.i_r = -1;
2223 
2224 #ifdef KDEBUG
2225  Lp.ecart=0; Lp.length=0;
2226 #endif
2227  /*- computes the lcm(s[i],p) -*/
2228  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2229 
2230  if (strat->sugarCrit)
2231  {
2232  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2233  && p_HasNotCF_Lift(p,strat->S[i],currRing))
2234  {
2235  /*
2236  *the product criterion has applied for (s,p),
2237  *i.e. lcm(s,p)=product of the leading terms of s and p.
2238  *Suppose (s,r) is in L and the leading term
2239  *of p divides lcm(s,r)
2240  *(==> the leading term of p divides the leading term of r)
2241  *but the leading term of s does not divide the leading term of r
2242  *(notice that tis condition is automatically satisfied if r is still
2243  *in S), then (s,r) can be cancelled.
2244  *This should be done here because the
2245  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2246  *
2247  *Moreover, skipping (s,r) holds also for the noncommutative case.
2248  */
2249  strat->cp++;
2250  pLmFree(Lp.lcm);
2251  return;
2252  }
2253  else
2254  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2255  if (strat->fromT && (strat->ecartS[i]>ecart))
2256  {
2257  pLmFree(Lp.lcm);
2258  return;
2259  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2260  }
2261  /*
2262  *the set B collects the pairs of type (S[j],p)
2263  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2264  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2265  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2266  */
2267  {
2268  j = strat->Bl;
2269  loop
2270  {
2271  if (j < 0) break;
2272  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2273  if ((compare==1)
2274  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2275  {
2276  strat->c3++;
2277  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2278  {
2279  pLmFree(Lp.lcm);
2280  return;
2281  }
2282  break;
2283  }
2284  else
2285  if ((compare ==-1)
2286  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2287  {
2288  deleteInL(strat->B,&strat->Bl,j,strat);
2289  strat->c3++;
2290  }
2291  j--;
2292  }
2293  }
2294  }
2295  else /*sugarcrit*/
2296  {
2297  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2298  p_HasNotCF_Lift(p,strat->S[i],currRing))
2299  {
2300  /*
2301  *the product criterion has applied for (s,p),
2302  *i.e. lcm(s,p)=product of the leading terms of s and p.
2303  *Suppose (s,r) is in L and the leading term
2304  *of p devides lcm(s,r)
2305  *(==> the leading term of p devides the leading term of r)
2306  *but the leading term of s does not devide the leading term of r
2307  *(notice that tis condition is automatically satisfied if r is still
2308  *in S), then (s,r) can be canceled.
2309  *This should be done here because the
2310  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2311  */
2312  strat->cp++;
2313  pLmFree(Lp.lcm);
2314  return;
2315  }
2316  if (strat->fromT && (strat->ecartS[i]>ecart))
2317  {
2318  pLmFree(Lp.lcm);
2319  return;
2320  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2321  }
2322  /*
2323  *the set B collects the pairs of type (S[j],p)
2324  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2325  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2326  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2327  */
2328  for(j = strat->Bl;j>=0;j--)
2329  {
2330  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2331  if (compare==1)
2332  {
2333  strat->c3++;
2334  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2335  {
2336  pLmFree(Lp.lcm);
2337  return;
2338  }
2339  break;
2340  }
2341  else
2342  if (compare ==-1)
2343  {
2344  deleteInL(strat->B,&strat->Bl,j,strat);
2345  strat->c3++;
2346  }
2347  }
2348  }
2349  /*
2350  *the pair (S[i],p) enters B if the spoly != 0
2351  */
2352  /*- compute the short s-polynomial -*/
2353  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2354  pNorm(p);
2355 
2356  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2357  Lp.p=NULL;
2358  else
2359  {
2361  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2362  }
2363  if (Lp.p == NULL)
2364  {
2365  /*- the case that the s-poly is 0 -*/
2366  if (strat->pairtest==NULL) initPairtest(strat);
2367  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2368  strat->pairtest[strat->sl+1] = TRUE;
2369  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2370  /*
2371  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2372  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2373  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2374  *term of p devides the lcm(s,r)
2375  *(this canceling should be done here because
2376  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2377  *the first case is handeled in chainCrit
2378  */
2379  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2380  }
2381  else
2382  {
2383  /*- the pair (S[i],p) enters B -*/
2384  Lp.p1 = strat->S[i];
2385  Lp.p2 = p;
2386 
2387  pNext(Lp.p) = strat->tail; // !!!
2388 
2389  if (atR >= 0)
2390  {
2391  Lp.i_r1 = strat->S_2_R[i];
2392  Lp.i_r2 = atR;
2393  }
2394  else
2395  {
2396  Lp.i_r1 = -1;
2397  Lp.i_r2 = -1;
2398  }
2399  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2400 
2402  {
2403  if (!rIsPluralRing(currRing)
2405  && (Lp.p->coef!=NULL))
2406  nDelete(&(Lp.p->coef));
2407  }
2408 
2409  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2410  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2411  }
2412 }
2413 
2414 /*2
2415 * put the pair (s[i],p) into the set B, ecart=ecart(p)
2416 * NOTE: here we need to add the signature-based criteria
2417 */
2418 
2419 #ifdef DEBUGF5
2420 static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2421 #else
2422 static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2423 #endif
2424 {
2425  assume(i<=strat->sl);
2426 
2427  int l;
2428  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2429  // the corresponding signatures for criteria checks
2430  LObject Lp;
2431  poly pSigMult = p_Copy(pSig,currRing);
2432  poly sSigMult = p_Copy(strat->sig[i],currRing);
2433  unsigned long pSigMultNegSev,sSigMultNegSev;
2434  Lp.i_r = -1;
2435 
2436 #ifdef KDEBUG
2437  Lp.ecart=0; Lp.length=0;
2438 #endif
2439  /*- computes the lcm(s[i],p) -*/
2440  Lp.lcm = pInit();
2441  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2442 #ifndef HAVE_RATGRING
2443  pLcm(p,strat->S[i],Lp.lcm);
2444 #elif defined(HAVE_RATGRING)
2445  if (rIsRatGRing(currRing))
2446  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2447  else
2448  pLcm(p,strat->S[i],Lp.lcm);
2449 #endif
2450  pSetm(Lp.lcm);
2451 
2452  // set coeffs of multipliers m1 and m2
2453  pSetCoeff0(m1, nInit(1));
2454  pSetCoeff0(m2, nInit(1));
2455 //#if 1
2456 #ifdef DEBUGF5
2457  PrintS("P1 ");
2458  pWrite(pHead(p));
2459  PrintS("P2 ");
2460  pWrite(pHead(strat->S[i]));
2461  PrintS("M1 ");
2462  pWrite(m1);
2463  PrintS("M2 ");
2464  pWrite(m2);
2465 #endif
2466  // get multiplied signatures for testing
2467  pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2468  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2469  sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2470  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2471 
2472 //#if 1
2473 #ifdef DEBUGF5
2474  PrintS("----------------\n");
2475  pWrite(pSigMult);
2476  pWrite(sSigMult);
2477  PrintS("----------------\n");
2478  Lp.checked = 0;
2479 #endif
2480  int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2481 //#if 1
2482 #if DEBUGF5
2483  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2484  pWrite(pSigMult);
2485  pWrite(sSigMult);
2486 #endif
2487  if(sigCmp==0)
2488  {
2489  // printf("!!!! EQUAL SIGS !!!!\n");
2490  // pSig = sSig, delete element due to Rewritten Criterion
2491  pDelete(&pSigMult);
2492  pDelete(&sSigMult);
2493  if (rField_is_Ring(currRing))
2494  pLmDelete(Lp.lcm);
2495  else
2496  pLmFree(Lp.lcm);
2497  pDelete (&m1);
2498  pDelete (&m2);
2499  return;
2500  }
2501  // testing by syzCrit = F5 Criterion
2502  // testing by rewCrit1 = Rewritten Criterion
2503  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2504  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2505  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2506  || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2507  )
2508  {
2509  pDelete(&pSigMult);
2510  pDelete(&sSigMult);
2511  if (rField_is_Ring(currRing))
2512  pLmDelete(Lp.lcm);
2513  else
2514  pLmFree(Lp.lcm);
2515  pDelete (&m1);
2516  pDelete (&m2);
2517  return;
2518  }
2519  /*
2520  *the pair (S[i],p) enters B if the spoly != 0
2521  */
2522  /*- compute the short s-polynomial -*/
2523  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2524  pNorm(p);
2525 
2526  if ((strat->S[i]==NULL) || (p==NULL))
2527  return;
2528 
2529  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2530  Lp.p=NULL;
2531  else
2532  {
2533  #ifdef HAVE_PLURAL
2534  if ( rIsPluralRing(currRing) )
2535  {
2536  if(pHasNotCF(p, strat->S[i]))
2537  {
2538  if(ncRingType(currRing) == nc_lie)
2539  {
2540  // generalized prod-crit for lie-type
2541  strat->cp++;
2542  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2543  }
2544  else
2545  if( ALLOW_PROD_CRIT(strat) )
2546  {
2547  // product criterion for homogeneous case in SCA
2548  strat->cp++;
2549  Lp.p = NULL;
2550  }
2551  else
2552  {
2553  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2554  nc_CreateShortSpoly(strat->S[i], p, currRing);
2555 
2556  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2557  pNext(Lp.p) = strat->tail; // !!!
2558  }
2559  }
2560  else
2561  {
2562  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2563  nc_CreateShortSpoly(strat->S[i], p, currRing);
2564 
2565  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2566  pNext(Lp.p) = strat->tail; // !!!
2567  }
2568  }
2569  else
2570  #endif
2571  {
2573  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2574  }
2575  }
2576  // store from which element this pair comes from for further tests
2577  //Lp.from = strat->sl+1;
2578  if(sigCmp==currRing->OrdSgn)
2579  {
2580  // pSig > sSig
2581  pDelete (&sSigMult);
2582  Lp.sig = pSigMult;
2583  Lp.sevSig = ~pSigMultNegSev;
2584  }
2585  else
2586  {
2587  // pSig < sSig
2588  pDelete (&pSigMult);
2589  Lp.sig = sSigMult;
2590  Lp.sevSig = ~sSigMultNegSev;
2591  }
2592  if (Lp.p == NULL)
2593  {
2594  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2595  int pos = posInSyz(strat, Lp.sig);
2596  enterSyz(Lp, strat, pos);
2597  }
2598  else
2599  {
2600  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2601  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2602  {
2603  pLmFree(Lp.lcm);
2604  pDelete(&Lp.sig);
2605  pDelete (&m1);
2606  pDelete (&m2);
2607  return;
2608  }
2609  // in any case Lp is checked up to the next strat->P which is added
2610  // to S right after this critical pair creation.
2611  // NOTE: this even holds if the 2nd generator gives the bigger signature
2612  // moreover, this improves rewCriterion,
2613  // i.e. strat->checked > strat->from if and only if the 2nd generator
2614  // gives the bigger signature.
2615  Lp.checked = strat->sl+1;
2616  // at this point it is clear that the pair will be added to L, since it has
2617  // passed all tests up to now
2618 
2619  // adds buchberger's first criterion
2620  if (pLmCmp(m2,pHead(p)) == 0)
2621  {
2622  Lp.prod_crit = TRUE; // Product Criterion
2623 #if 0
2624  int pos = posInSyz(strat, Lp.sig);
2625  enterSyz(Lp, strat, pos);
2626  pDelete (&m1);
2627  pDelete (&m2);
2628  return;
2629 #endif
2630  }
2631  pDelete (&m1);
2632  pDelete (&m2);
2633 #if DEBUGF5
2634  PrintS("SIGNATURE OF PAIR: ");
2635  pWrite(Lp.sig);
2636 #endif
2637  /*- the pair (S[i],p) enters B -*/
2638  Lp.p1 = strat->S[i];
2639  Lp.p2 = p;
2640 
2641  if (
2643 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2644  )
2645  {
2646  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2647  pNext(Lp.p) = strat->tail; // !!!
2648  }
2649 
2650  if (atR >= 0)
2651  {
2652  Lp.i_r1 = strat->S_2_R[i];
2653  Lp.i_r2 = atR;
2654  }
2655  else
2656  {
2657  Lp.i_r1 = -1;
2658  Lp.i_r2 = -1;
2659  }
2660  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2661 
2663  {
2664  if (!rIsPluralRing(currRing)
2666  && (Lp.p->coef!=NULL))
2667  nDelete(&(Lp.p->coef));
2668  }
2669 
2670  l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2671  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2672  }
2673 }
2674 
2675 
2676 #ifdef DEBUGF5
2677 static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2678 #else
2679 static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2680 #endif
2681 {
2682  #if ALL_VS_JUST
2683  //Over rings, if we construct the strong pair, do not add the spair
2685  {
2686  number s,t,d;
2687  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2688 
2689  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2690  {
2691  nDelete(&d);
2692  nDelete(&s);
2693  nDelete(&t);
2694  return;
2695  }
2696  nDelete(&d);
2697  nDelete(&s);
2698  nDelete(&t);
2699  }
2700  #endif
2701  assume(i<=strat->sl);
2702  int l;
2703  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2704  // the corresponding signatures for criteria checks
2705  LObject Lp;
2706  poly pSigMult = p_Copy(pSig,currRing);
2707  poly sSigMult = p_Copy(strat->sig[i],currRing);
2708  unsigned long pSigMultNegSev,sSigMultNegSev;
2709  Lp.i_r = -1;
2710 
2711 #ifdef KDEBUG
2712  Lp.ecart=0; Lp.length=0;
2713 #endif
2714  /*- computes the lcm(s[i],p) -*/
2715  Lp.lcm = pInit();
2716  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2717 #ifndef HAVE_RATGRING
2718  pLcm(p,strat->S[i],Lp.lcm);
2719 #elif defined(HAVE_RATGRING)
2720  if (rIsRatGRing(currRing))
2721  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2722  else
2723  pLcm(p,strat->S[i],Lp.lcm);
2724 #endif
2725  pSetm(Lp.lcm);
2726 
2727  // set coeffs of multipliers m1 and m2
2729  {
2730  number s = nCopy(pGetCoeff(strat->S[i]));
2731  number t = nCopy(pGetCoeff(p));
2732  pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2733  ksCheckCoeff(&s, &t, currRing->cf);
2734  pSetCoeff0(m1,s);
2735  pSetCoeff0(m2,t);
2736  }
2737  else
2738  {
2739  pSetCoeff0(m1, nInit(1));
2740  pSetCoeff0(m2, nInit(1));
2741  }
2742 #ifdef DEBUGF5
2743  Print("P1 ");
2744  pWrite(pHead(p));
2745  Print("P2 ");
2746  pWrite(pHead(strat->S[i]));
2747  Print("M1 ");
2748  pWrite(m1);
2749  Print("M2 ");
2750  pWrite(m2);
2751 #endif
2752 
2753  // get multiplied signatures for testing
2754  pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2755  if(pSigMult != NULL)
2756  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2757  sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2758  if(sSigMult != NULL)
2759  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2760 //#if 1
2761 #ifdef DEBUGF5
2762  Print("----------------\n");
2763  pWrite(pSigMult);
2764  pWrite(sSigMult);
2765  Print("----------------\n");
2766  Lp.checked = 0;
2767 #endif
2768  int sigCmp;
2769  if(pSigMult != NULL && sSigMult != NULL)
2770  {
2772  sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2773  else
2774  sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2775  }
2776  else
2777  {
2778  if(pSigMult == NULL)
2779  {
2780  if(sSigMult == NULL)
2781  sigCmp = 0;
2782  else
2783  sigCmp = -1;
2784  }
2785  else
2786  sigCmp = 1;
2787  }
2788 //#if 1
2789 #if DEBUGF5
2790  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2791  pWrite(pSigMult);
2792  pWrite(sSigMult);
2793 #endif
2794  //In the ring case we already build the sig
2796  {
2797  if(sigCmp == 0)
2798  {
2799  //sigdrop since we loose the signature
2800  strat->sigdrop = TRUE;
2801  //Try to reduce it as far as we can via redRing
2803  {
2804  poly p1 = p_Copy(p,currRing);
2805  poly p2 = p_Copy(strat->S[i],currRing);
2806  p1 = p_Mult_mm(p1,m1,currRing);
2807  p2 = p_Mult_mm(p2,m2,currRing);
2808  Lp.p = p_Sub(p1,p2,currRing);
2809  if(Lp.p != NULL)
2810  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2811  }
2812  int red_result = redRing(&Lp,strat);
2813  if(red_result == 0)
2814  {
2815  // Cancel the sigdrop
2816  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2817  strat->sigdrop = FALSE;
2818  return;
2819  }
2820  else
2821  {
2822  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2823  #if 1
2824  strat->enterS(Lp,0,strat,strat->tl);
2825  #endif
2826  return;
2827  }
2828  }
2829  if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2830  {
2831  //Same lm, have to substract
2832  Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2833  }
2834  else
2835  {
2836  if(sigCmp == 1)
2837  {
2838  Lp.sig = pCopy(pSigMult);
2839  }
2840  if(sigCmp == -1)
2841  {
2842  Lp.sig = pNeg(pCopy(sSigMult));
2843  }
2844  }
2845  Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2846  }
2847 
2848  #if 0
2849  if(sigCmp==0)
2850  {
2851  // printf("!!!! EQUAL SIGS !!!!\n");
2852  // pSig = sSig, delete element due to Rewritten Criterion
2853  pDelete(&pSigMult);
2854  pDelete(&sSigMult);
2855  if (rField_is_Ring(currRing))
2856  pLmDelete(Lp.lcm);
2857  else
2858  pLmFree(Lp.lcm);
2859  pDelete (&m1);
2860  pDelete (&m2);
2861  return;
2862  }
2863  #endif
2864  // testing by syzCrit = F5 Criterion
2865  // testing by rewCrit1 = Rewritten Criterion
2866  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2867  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2868  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2869  // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2870  //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2871  )
2872  {
2873  pDelete(&pSigMult);
2874  pDelete(&sSigMult);
2875  if (rField_is_Ring(currRing))
2876  pLmDelete(Lp.lcm);
2877  else
2878  pLmFree(Lp.lcm);
2879  pDelete (&m1);
2880  pDelete (&m2);
2881  return;
2882  }
2883  /*
2884  *the pair (S[i],p) enters B if the spoly != 0
2885  */
2886  /*- compute the short s-polynomial -*/
2887  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2888  pNorm(p);
2889 
2890  if ((strat->S[i]==NULL) || (p==NULL))
2891  return;
2892 
2893  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2894  Lp.p=NULL;
2895  else
2896  {
2897  //Build p
2899  {
2900  poly p1 = p_Copy(p,currRing);
2901  poly p2 = p_Copy(strat->S[i],currRing);
2902  p1 = p_Mult_mm(p1,m1,currRing);
2903  p2 = p_Mult_mm(p2,m2,currRing);
2904  Lp.p = p_Sub(p1,p2,currRing);
2905  if(Lp.p != NULL)
2906  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2907  }
2908  else
2909  {
2910  #ifdef HAVE_PLURAL
2911  if ( rIsPluralRing(currRing) )
2912  {
2913  if(ncRingType(currRing) == nc_lie)
2914  {
2915  // generalized prod-crit for lie-type
2916  strat->cp++;
2917  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2918  }
2919  else
2920  if( ALLOW_PROD_CRIT(strat) )
2921  {
2922  // product criterion for homogeneous case in SCA
2923  strat->cp++;
2924  Lp.p = NULL;
2925  }
2926  else
2927  {
2928  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2929  nc_CreateShortSpoly(strat->S[i], p, currRing);
2930 
2931  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2932  pNext(Lp.p) = strat->tail; // !!!
2933  }
2934  }
2935  else
2936  #endif
2937  {
2939  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2940  }
2941  }
2942  }
2943  // store from which element this pair comes from for further tests
2944  //Lp.from = strat->sl+1;
2946  {
2947  //Put the sig to be > 0
2948  if(!nGreaterZero(pGetCoeff(Lp.sig)))
2949  {
2950  Lp.sig = pNeg(Lp.sig);
2951  Lp.p = pNeg(Lp.p);
2952  }
2953  }
2954  else
2955  {
2956  if(sigCmp==currRing->OrdSgn)
2957  {
2958  // pSig > sSig
2959  pDelete (&sSigMult);
2960  Lp.sig = pSigMult;
2961  Lp.sevSig = ~pSigMultNegSev;
2962  }
2963  else
2964  {
2965  // pSig < sSig
2966  pDelete (&pSigMult);
2967  Lp.sig = sSigMult;
2968  Lp.sevSig = ~sSigMultNegSev;
2969  }
2970  }
2971  if (Lp.p == NULL)
2972  {
2973  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2974  int pos = posInSyz(strat, Lp.sig);
2975  enterSyz(Lp, strat, pos);
2976  }
2977  else
2978  {
2979  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2980  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2981  {
2982  pLmFree(Lp.lcm);
2983  pDelete(&Lp.sig);
2984  pDelete (&m1);
2985  pDelete (&m2);
2986  return;
2987  }
2988  // in any case Lp is checked up to the next strat->P which is added
2989  // to S right after this critical pair creation.
2990  // NOTE: this even holds if the 2nd generator gives the bigger signature
2991  // moreover, this improves rewCriterion,
2992  // i.e. strat->checked > strat->from if and only if the 2nd generator
2993  // gives the bigger signature.
2994  Lp.checked = strat->sl+1;
2995  // at this point it is clear that the pair will be added to L, since it has
2996  // passed all tests up to now
2997 
2998  // adds buchberger's first criterion
2999  if (pLmCmp(m2,pHead(p)) == 0)
3000  {
3001  Lp.prod_crit = TRUE; // Product Criterion
3002 #if 0
3003  int pos = posInSyz(strat, Lp.sig);
3004  enterSyz(Lp, strat, pos);
3005  pDelete (&m1);
3006  pDelete (&m2);
3007  return;
3008 #endif
3009  }
3010  pDelete (&m1);
3011  pDelete (&m2);
3012 #if DEBUGF5
3013  PrintS("SIGNATURE OF PAIR: ");
3014  pWrite(Lp.sig);
3015 #endif
3016  /*- the pair (S[i],p) enters B -*/
3017  Lp.p1 = strat->S[i];
3018  Lp.p2 = p;
3019 
3020  if (
3022 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3024  )
3025  {
3026  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3027  pNext(Lp.p) = strat->tail; // !!!
3028  }
3029 
3030  if (atR >= 0)
3031  {
3032  Lp.i_r1 = strat->S_2_R[i];
3033  Lp.i_r2 = atR;
3034  }
3035  else
3036  {
3037  Lp.i_r1 = -1;
3038  Lp.i_r2 = -1;
3039  }
3040  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3041 
3043  {
3044  if (!rIsPluralRing(currRing)
3046  && (Lp.p->coef!=NULL))
3047  nDelete(&(Lp.p->coef));
3048  }
3049  // Check for sigdrop
3050  if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3051  {
3052  strat->sigdrop = TRUE;
3053  // Completely reduce it
3054  int red_result = redRing(&Lp,strat);
3055  if(red_result == 0)
3056  {
3057  // Reduced to 0
3058  strat->sigdrop = FALSE;
3059  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3060  return;
3061  }
3062  else
3063  {
3064  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3065  // 0 - add just the original poly causing the sigdrop, 1 - add also this
3066  #if 1
3067  strat->enterS(Lp,0,strat, strat->tl+1);
3068  #endif
3069  return;
3070  }
3071  }
3072  l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3073  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3074  }
3075 }
3076 
3077 /*2
3078 * put the pair (s[i],p) into the set L, ecart=ecart(p)
3079 * in the case that s forms a SB of (s)
3080 */
3081 void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3082 {
3083  //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3084  if(pHasNotCF(p,strat->S[i]))
3085  {
3086  //PrintS("prod-crit\n");
3087  if(ALLOW_PROD_CRIT(strat))
3088  {
3089  //PrintS("prod-crit\n");
3090  strat->cp++;
3091  return;
3092  }
3093  }
3094 
3095  int l;
3096  LObject Lp;
3097  Lp.i_r = -1;
3098 
3099  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3100  /*- compute the short s-polynomial -*/
3101 
3102  #ifdef HAVE_PLURAL
3103  if (rIsPluralRing(currRing))
3104  {
3105  Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3106  }
3107  else
3108  #endif
3109  Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3110 
3111  if (Lp.p == NULL)
3112  {
3113  //PrintS("short spoly==NULL\n");
3114  pLmFree(Lp.lcm);
3115  }
3116  else
3117  {
3118  /*- the pair (S[i],p) enters L -*/
3119  Lp.p1 = strat->S[i];
3120  Lp.p2 = p;
3121  if (atR >= 0)
3122  {
3123  Lp.i_r1 = strat->S_2_R[i];
3124  Lp.i_r2 = atR;
3125  }
3126  else
3127  {
3128  Lp.i_r1 = -1;
3129  Lp.i_r2 = -1;
3130  }
3131  assume(pNext(Lp.p) == NULL);
3132  pNext(Lp.p) = strat->tail;
3133  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3135  {
3136  if (!rIsPluralRing(currRing)
3138  && (Lp.p->coef!=NULL))
3139  nDelete(&(Lp.p->coef));
3140  }
3141  l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3142  //Print("-> L[%d]\n",l);
3143  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3144  }
3145 }
3146 
3147 /*2
3148 * merge set B into L
3149 */
3151 {
3152  int j=strat->Ll+strat->Bl+1;
3153  if (j>strat->Lmax)
3154  {
3155  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3156  enlargeL(&(strat->L),&(strat->Lmax),j);
3157  }
3158  j = strat->Ll;
3159  int i;
3160  for (i=strat->Bl; i>=0; i--)
3161  {
3162  j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3163  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3164  }
3165  strat->Bl = -1;
3166 }
3167 
3168 /*2
3169 * merge set B into L
3170 */
3172 {
3173  int j=strat->Ll+strat->Bl+1;
3174  if (j>strat->Lmax)
3175  {
3176  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3177  enlargeL(&(strat->L),&(strat->Lmax),j);
3178  }
3179  j = strat->Ll;
3180  int i;
3181  for (i=strat->Bl; i>=0; i--)
3182  {
3183  j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3184  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3185  }
3186  strat->Bl = -1;
3187 }
3188 /*2
3189 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3190 *using the chain-criterion in B and L and enters B to L
3191 */
3192 void chainCritNormal (poly p,int ecart,kStrategy strat)
3193 {
3194  int i,j,l;
3195 
3196  /*
3197  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3198  *In this case all elements in B such
3199  *that their lcm is divisible by the leading term of S[i] can be canceled
3200  */
3201  if (strat->pairtest!=NULL)
3202  {
3203  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3204  for (j=0; j<=strat->sl; j++)
3205  {
3206  if (strat->pairtest[j])
3207  {
3208  for (i=strat->Bl; i>=0; i--)
3209  {
3210  if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3211  {
3212  deleteInL(strat->B,&strat->Bl,i,strat);
3213  strat->c3++;
3214  }
3215  }
3216  }
3217  }
3218  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3219  strat->pairtest=NULL;
3220  }
3221  if (strat->Gebauer || strat->fromT)
3222  {
3223  if (strat->sugarCrit)
3224  {
3225  /*
3226  *suppose L[j] == (s,r) and p/lcm(s,r)
3227  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3228  *and in case the sugar is o.k. then L[j] can be canceled
3229  */
3230  for (j=strat->Ll; j>=0; j--)
3231  {
3232  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3233  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3234  && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3235  {
3236  if (strat->L[j].p == strat->tail)
3237  {
3238  deleteInL(strat->L,&strat->Ll,j,strat);
3239  strat->c3++;
3240  }
3241  }
3242  }
3243  /*
3244  *this is GEBAUER-MOELLER:
3245  *in B all elements with the same lcm except the "best"
3246  *(i.e. the last one in B with this property) will be canceled
3247  */
3248  j = strat->Bl;
3249  loop /*cannot be changed into a for !!! */
3250  {
3251  if (j <= 0) break;
3252  i = j-1;
3253  loop
3254  {
3255  if (i < 0) break;
3256  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3257  {
3258  strat->c3++;
3259  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3260  {
3261  deleteInL(strat->B,&strat->Bl,i,strat);
3262  j--;
3263  }
3264  else
3265  {
3266  deleteInL(strat->B,&strat->Bl,j,strat);
3267  break;
3268  }
3269  }
3270  i--;
3271  }
3272  j--;
3273  }
3274  }
3275  else /*sugarCrit*/
3276  {
3277  /*
3278  *suppose L[j] == (s,r) and p/lcm(s,r)
3279  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3280  *and in case the sugar is o.k. then L[j] can be canceled
3281  */
3282  for (j=strat->Ll; j>=0; j--)
3283  {
3284  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3285  {
3286  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3287  {
3288  deleteInL(strat->L,&strat->Ll,j,strat);
3289  strat->c3++;
3290  }
3291  }
3292  }
3293  /*
3294  *this is GEBAUER-MOELLER:
3295  *in B all elements with the same lcm except the "best"
3296  *(i.e. the last one in B with this property) will be canceled
3297  */
3298  j = strat->Bl;
3299  loop /*cannot be changed into a for !!! */
3300  {
3301  if (j <= 0) break;
3302  for(i=j-1; i>=0; i--)
3303  {
3304  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3305  {
3306  strat->c3++;
3307  deleteInL(strat->B,&strat->Bl,i,strat);
3308  j--;
3309  }
3310  }
3311  j--;
3312  }
3313  }
3314  /*
3315  *the elements of B enter L
3316  */
3317  kMergeBintoL(strat);
3318  }
3319  else
3320  {
3321  for (j=strat->Ll; j>=0; j--)
3322  {
3323  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3324  {
3325  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3326  {
3327  deleteInL(strat->L,&strat->Ll,j,strat);
3328  strat->c3++;
3329  }
3330  }
3331  }
3332  /*
3333  *this is our MODIFICATION of GEBAUER-MOELLER:
3334  *First the elements of B enter L,
3335  *then we fix a lcm and the "best" element in L
3336  *(i.e the last in L with this lcm and of type (s,p))
3337  *and cancel all the other elements of type (r,p) with this lcm
3338  *except the case the element (s,r) has also the same lcm
3339  *and is on the worst position with respect to (s,p) and (r,p)
3340  */
3341  /*
3342  *B enters to L/their order with respect to B is permutated for elements
3343  *B[i].p with the same leading term
3344  */
3345  kMergeBintoL(strat);
3346  j = strat->Ll;
3347  loop /*cannot be changed into a for !!! */
3348  {
3349  if (j <= 0)
3350  {
3351  /*now L[0] cannot be canceled any more and the tail can be removed*/
3352  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3353  break;
3354  }
3355  if (strat->L[j].p2 == p)
3356  {
3357  i = j-1;
3358  loop
3359  {
3360  if (i < 0) break;
3361  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3362  {
3363  /*L[i] could be canceled but we search for a better one to cancel*/
3364  strat->c3++;
3365  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3366  && (pNext(strat->L[l].p) == strat->tail)
3367  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3368  && pDivisibleBy(p,strat->L[l].lcm))
3369  {
3370  /*
3371  *"NOT equal(...)" because in case of "equal" the element L[l]
3372  *is "older" and has to be from theoretical point of view behind
3373  *L[i], but we do not want to reorder L
3374  */
3375  strat->L[i].p2 = strat->tail;
3376  /*
3377  *L[l] will be canceled, we cannot cancel L[i] later on,
3378  *so we mark it with "tail"
3379  */
3380  deleteInL(strat->L,&strat->Ll,l,strat);
3381  i--;
3382  }
3383  else
3384  {
3385  deleteInL(strat->L,&strat->Ll,i,strat);
3386  }
3387  j--;
3388  }
3389  i--;
3390  }
3391  }
3392  else if (strat->L[j].p2 == strat->tail)
3393  {
3394  /*now L[j] cannot be canceled any more and the tail can be removed*/
3395  strat->L[j].p2 = p;
3396  }
3397  j--;
3398  }
3399  }
3400 }
3401 /*2
3402 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3403 *without the chain-criterion in B and L and enters B to L
3404 */
3405 void chainCritOpt_1 (poly,int,kStrategy strat)
3406 {
3407  if (strat->pairtest!=NULL)
3408  {
3409  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3410  strat->pairtest=NULL;
3411  }
3412  /*
3413  *the elements of B enter L
3414  */
3415  kMergeBintoL(strat);
3416 }
3417 /*2
3418 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3419 *using the chain-criterion in B and L and enters B to L
3420 */
3421 void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3422 {
3423  int i,j,l;
3424  kMergeBintoLSba(strat);
3425  j = strat->Ll;
3426  loop /*cannot be changed into a for !!! */
3427  {
3428  if (j <= 0)
3429  {
3430  /*now L[0] cannot be canceled any more and the tail can be removed*/
3431  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3432  break;
3433  }
3434  if (strat->L[j].p2 == p)
3435  {
3436  i = j-1;
3437  loop
3438  {
3439  if (i < 0) break;
3440  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3441  {
3442  /*L[i] could be canceled but we search for a better one to cancel*/
3443  strat->c3++;
3444  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3445  && (pNext(strat->L[l].p) == strat->tail)
3446  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3447  && pDivisibleBy(p,strat->L[l].lcm))
3448  {
3449  /*
3450  *"NOT equal(...)" because in case of "equal" the element L[l]
3451  *is "older" and has to be from theoretical point of view behind
3452  *L[i], but we do not want to reorder L
3453  */
3454  strat->L[i].p2 = strat->tail;
3455  /*
3456  *L[l] will be canceled, we cannot cancel L[i] later on,
3457  *so we mark it with "tail"
3458  */
3459  deleteInL(strat->L,&strat->Ll,l,strat);
3460  i--;
3461  }
3462  else
3463  {
3464  deleteInL(strat->L,&strat->Ll,i,strat);
3465  }
3466  j--;
3467  }
3468  i--;
3469  }
3470  }
3471  else if (strat->L[j].p2 == strat->tail)
3472  {
3473  /*now L[j] cannot be canceled any more and the tail can be removed*/
3474  strat->L[j].p2 = p;
3475  }
3476  j--;
3477  }
3478 }
3479 #ifdef HAVE_RATGRING
3480 void chainCritPart (poly p,int ecart,kStrategy strat)
3481 {
3482  int i,j,l;
3483 
3484  /*
3485  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3486  *In this case all elements in B such
3487  *that their lcm is divisible by the leading term of S[i] can be canceled
3488  */
3489  if (strat->pairtest!=NULL)
3490  {
3491  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3492  for (j=0; j<=strat->sl; j++)
3493  {
3494  if (strat->pairtest[j])
3495  {
3496  for (i=strat->Bl; i>=0; i--)
3497  {
3498  if (_p_LmDivisibleByPart(strat->S[j],currRing,
3499  strat->B[i].lcm,currRing,
3500  currRing->real_var_start,currRing->real_var_end))
3501  {
3502  if(TEST_OPT_DEBUG)
3503  {
3504  Print("chain-crit-part: S[%d]=",j);
3505  p_wrp(strat->S[j],currRing);
3506  Print(" divide B[%d].lcm=",i);
3507  p_wrp(strat->B[i].lcm,currRing);
3508  PrintLn();
3509  }
3510  deleteInL(strat->B,&strat->Bl,i,strat);
3511  strat->c3++;
3512  }
3513  }
3514  }
3515  }
3516  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3517  strat->pairtest=NULL;
3518  }
3519  if (strat->Gebauer || strat->fromT)
3520  {
3521  if (strat->sugarCrit)
3522  {
3523  /*
3524  *suppose L[j] == (s,r) and p/lcm(s,r)
3525  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3526  *and in case the sugar is o.k. then L[j] can be canceled
3527  */
3528  for (j=strat->Ll; j>=0; j--)
3529  {
3530  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3531  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3532  && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3533  {
3534  if (strat->L[j].p == strat->tail)
3535  {
3536  if(TEST_OPT_DEBUG)
3537  {
3538  PrintS("chain-crit-part: pCompareChainPart p=");
3539  p_wrp(p,currRing);
3540  Print(" delete L[%d]",j);
3541  p_wrp(strat->L[j].lcm,currRing);
3542  PrintLn();
3543  }
3544  deleteInL(strat->L,&strat->Ll,j,strat);
3545  strat->c3++;
3546  }
3547  }
3548  }
3549  /*
3550  *this is GEBAUER-MOELLER:
3551  *in B all elements with the same lcm except the "best"
3552  *(i.e. the last one in B with this property) will be canceled
3553  */
3554  j = strat->Bl;
3555  loop /*cannot be changed into a for !!! */
3556  {
3557  if (j <= 0) break;
3558  i = j-1;
3559  loop
3560  {
3561  if (i < 0) break;
3562  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3563  {
3564  strat->c3++;
3565  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3566  {
3567  if(TEST_OPT_DEBUG)
3568  {
3569  Print("chain-crit-part: sugar B[%d].lcm=",j);
3570  p_wrp(strat->B[j].lcm,currRing);
3571  Print(" delete B[%d]",i);
3572  p_wrp(strat->B[i].lcm,currRing);
3573  PrintLn();
3574  }
3575  deleteInL(strat->B,&strat->Bl,i,strat);
3576  j--;
3577  }
3578  else
3579  {
3580  if(TEST_OPT_DEBUG)
3581  {
3582  Print("chain-crit-part: sugar B[%d].lcm=",i);
3583  p_wrp(strat->B[i].lcm,currRing);
3584  Print(" delete B[%d]",j);
3585  p_wrp(strat->B[j].lcm,currRing);
3586  PrintLn();
3587  }
3588  deleteInL(strat->B,&strat->Bl,j,strat);
3589  break;
3590  }
3591  }
3592  i--;
3593  }
3594  j--;
3595  }
3596  }
3597  else /*sugarCrit*/
3598  {
3599  /*
3600  *suppose L[j] == (s,r) and p/lcm(s,r)
3601  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3602  *and in case the sugar is o.k. then L[j] can be canceled
3603  */
3604  for (j=strat->Ll; j>=0; j--)
3605  {
3606  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3607  {
3608  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3609  {
3610  if(TEST_OPT_DEBUG)
3611  {
3612  PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3613  p_wrp(p,currRing);
3614  Print(" delete L[%d]",j);
3615  p_wrp(strat->L[j].lcm,currRing);
3616  PrintLn();
3617  }
3618  deleteInL(strat->L,&strat->Ll,j,strat);
3619  strat->c3++;
3620  }
3621  }
3622  }
3623  /*
3624  *this is GEBAUER-MOELLER:
3625  *in B all elements with the same lcm except the "best"
3626  *(i.e. the last one in B with this property) will be canceled
3627  */
3628  j = strat->Bl;
3629  loop /*cannot be changed into a for !!! */
3630  {
3631  if (j <= 0) break;
3632  for(i=j-1; i>=0; i--)
3633  {
3634  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3635  {
3636  if(TEST_OPT_DEBUG)
3637  {
3638  Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3639  p_wrp(strat->B[j].lcm,currRing);
3640  Print(" delete B[%d]\n",i);
3641  }
3642  strat->c3++;
3643  deleteInL(strat->B,&strat->Bl,i,strat);
3644  j--;
3645  }
3646  }
3647  j--;
3648  }
3649  }
3650  /*
3651  *the elements of B enter L
3652  */
3653  kMergeBintoL(strat);
3654  }
3655  else
3656  {
3657  for (j=strat->Ll; j>=0; j--)
3658  {
3659  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3660  {
3661  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3662  {
3663  if(TEST_OPT_DEBUG)
3664  {
3665  PrintS("chain-crit-part: pCompareChainPart p=");
3666  p_wrp(p,currRing);
3667  Print(" delete L[%d]",j);
3668  p_wrp(strat->L[j].lcm,currRing);
3669  PrintLn();
3670  }
3671  deleteInL(strat->L,&strat->Ll,j,strat);
3672  strat->c3++;
3673  }
3674  }
3675  }
3676  /*
3677  *this is our MODIFICATION of GEBAUER-MOELLER:
3678  *First the elements of B enter L,
3679  *then we fix a lcm and the "best" element in L
3680  *(i.e the last in L with this lcm and of type (s,p))
3681  *and cancel all the other elements of type (r,p) with this lcm
3682  *except the case the element (s,r) has also the same lcm
3683  *and is on the worst position with respect to (s,p) and (r,p)
3684  */
3685  /*
3686  *B enters to L/their order with respect to B is permutated for elements
3687  *B[i].p with the same leading term
3688  */
3689  kMergeBintoL(strat);
3690  j = strat->Ll;
3691  loop /*cannot be changed into a for !!! */
3692  {
3693  if (j <= 0)
3694  {
3695  /*now L[0] cannot be canceled any more and the tail can be removed*/
3696  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3697  break;
3698  }
3699  if (strat->L[j].p2 == p)
3700  {
3701  i = j-1;
3702  loop
3703  {
3704  if (i < 0) break;
3705  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3706  {
3707  /*L[i] could be canceled but we search for a better one to cancel*/
3708  strat->c3++;
3709  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3710  && (pNext(strat->L[l].p) == strat->tail)
3711  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3713  strat->L[l].lcm,currRing,
3714  currRing->real_var_start, currRing->real_var_end))
3715 
3716  {
3717  /*
3718  *"NOT equal(...)" because in case of "equal" the element L[l]
3719  *is "older" and has to be from theoretical point of view behind
3720  *L[i], but we do not want to reorder L
3721  */
3722  strat->L[i].p2 = strat->tail;
3723  /*
3724  *L[l] will be canceled, we cannot cancel L[i] later on,
3725  *so we mark it with "tail"
3726  */
3727  if(TEST_OPT_DEBUG)
3728  {
3729  PrintS("chain-crit-part: divisible_by p=");
3730  p_wrp(p,currRing);
3731  Print(" delete L[%d]",l);
3732  p_wrp(strat->L[l].lcm,currRing);
3733  PrintLn();
3734  }
3735  deleteInL(strat->L,&strat->Ll,l,strat);
3736  i--;
3737  }
3738  else
3739  {
3740  if(TEST_OPT_DEBUG)
3741  {
3742  PrintS("chain-crit-part: divisible_by(2) p=");
3743  p_wrp(p,currRing);
3744  Print(" delete L[%d]",i);
3745  p_wrp(strat->L[i].lcm,currRing);
3746  PrintLn();
3747  }
3748  deleteInL(strat->L,&strat->Ll,i,strat);
3749  }
3750  j--;
3751  }
3752  i--;
3753  }
3754  }
3755  else if (strat->L[j].p2 == strat->tail)
3756  {
3757  /*now L[j] cannot be canceled any more and the tail can be removed*/
3758  strat->L[j].p2 = p;
3759  }
3760  j--;
3761  }
3762  }
3763 }
3764 #endif
3765 
3766 /*2
3767 *(s[0],h),...,(s[k],h) will be put to the pairset L
3768 */
3769 void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3770 {
3771 
3772  if ((strat->syzComp==0)
3773  || (pGetComp(h)<=strat->syzComp))
3774  {
3775  int j;
3776  BOOLEAN new_pair=FALSE;
3777 
3778  if (pGetComp(h)==0)
3779  {
3780  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3781  if ((isFromQ)&&(strat->fromQ!=NULL))
3782  {
3783  for (j=0; j<=k; j++)
3784  {
3785  if (!strat->fromQ[j])
3786  {
3787  new_pair=TRUE;
3788  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3789  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3790  }
3791  }
3792  }
3793  else
3794  {
3795  new_pair=TRUE;
3796  for (j=0; j<=k; j++)
3797  {
3798  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3799  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3800  }
3801  }
3802  }
3803  else
3804  {
3805  for (j=0; j<=k; j++)
3806  {
3807  if ((pGetComp(h)==pGetComp(strat->S[j]))
3808  || (pGetComp(strat->S[j])==0))
3809  {
3810  new_pair=TRUE;
3811  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3812  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3813  }
3814  }
3815  }
3816  if (new_pair)
3817  {
3818  #ifdef HAVE_RATGRING
3819  if (currRing->real_var_start>0)
3820  chainCritPart(h,ecart,strat);
3821  else
3822  #endif
3823  strat->chainCrit(h,ecart,strat);
3824  }
3825  kMergeBintoL(strat);
3826  }
3827 }
3828 
3829 /*2
3830 *(s[0],h),...,(s[k],h) will be put to the pairset L
3831 *using signatures <= only for signature-based standard basis algorithms
3832 */
3833 
3834 void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3835 {
3836 
3837  if ((strat->syzComp==0)
3838  || (pGetComp(h)<=strat->syzComp))
3839  {
3840  int j;
3841  BOOLEAN new_pair=FALSE;
3842 
3843  if (pGetComp(h)==0)
3844  {
3845  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3846  if ((isFromQ)&&(strat->fromQ!=NULL))
3847  {
3848  for (j=0; j<=k; j++)
3849  {
3850  if (!strat->fromQ[j])
3851  {
3852  new_pair=TRUE;
3853  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3854  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3855  }
3856  }
3857  }
3858  else
3859  {
3860  new_pair=TRUE;
3861  for (j=0; j<=k; j++)
3862  {
3863  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3864  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3865  }
3866  }
3867  }
3868  else
3869  {
3870  for (j=0; j<=k; j++)
3871  {
3872  if ((pGetComp(h)==pGetComp(strat->S[j]))
3873  || (pGetComp(strat->S[j])==0))
3874  {
3875  new_pair=TRUE;
3876  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3877  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3878  }
3879  }
3880  }
3881 
3882  if (new_pair)
3883  {
3884 #ifdef HAVE_RATGRING
3885  if (currRing->real_var_start>0)
3886  chainCritPart(h,ecart,strat);
3887  else
3888 #endif
3889  strat->chainCrit(h,ecart,strat);
3890  }
3891  }
3892 }
3893 
3894 void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3895 {
3896 
3897  if ((strat->syzComp==0)
3898  || (pGetComp(h)<=strat->syzComp))
3899  {
3900  int j;
3901 
3902  if (pGetComp(h)==0)
3903  {
3904  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3905  if ((isFromQ)&&(strat->fromQ!=NULL))
3906  {
3907  for (j=0; j<=k && !strat->sigdrop; j++)
3908  {
3909  if (!strat->fromQ[j])
3910  {
3911  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3912  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3913  }
3914  }
3915  }
3916  else
3917  {
3918  for (j=0; j<=k && !strat->sigdrop; j++)
3919  {
3920  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3921  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3922  }
3923  }
3924  }
3925  else
3926  {
3927  for (j=0; j<=k && !strat->sigdrop; j++)
3928  {
3929  if ((pGetComp(h)==pGetComp(strat->S[j]))
3930  || (pGetComp(strat->S[j])==0))
3931  {
3932  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3933  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3934  }
3935  }
3936  }
3937 
3938 #if 0
3939  if (new_pair)
3940  {
3941 #ifdef HAVE_RATGRING
3942  if (currRing->real_var_start>0)
3943  chainCritPart(h,ecart,strat);
3944  else
3945 #endif
3946  strat->chainCrit(h,ecart,strat);
3947  }
3948 #endif
3949  }
3950 }
3951 #ifdef HAVE_RINGS
3952 /*2
3953 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3954 *using the chain-criterion in B and L and enters B to L
3955 */
3956 void chainCritRing (poly p,int, kStrategy strat)
3957 {
3958  int i,j,l;
3959  /*
3960  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3961  *In this case all elements in B such
3962  *that their lcm is divisible by the leading term of S[i] can be canceled
3963  */
3964  if (strat->pairtest!=NULL)
3965  {
3966  {
3967  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3968  for (j=0; j<=strat->sl; j++)
3969  {
3970  if (strat->pairtest[j])
3971  {
3972  for (i=strat->Bl; i>=0; i--)
3973  {
3974  if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
3975  {
3976 #ifdef KDEBUG
3977  if (TEST_OPT_DEBUG)
3978  {
3979  PrintS("--- chain criterion func chainCritRing type 1\n");
3980  PrintS("strat->S[j]:");
3981  wrp(strat->S[j]);
3982  PrintS(" strat->B[i].lcm:");
3983  wrp(strat->B[i].lcm);PrintLn();
3984  pWrite(strat->B[i].p);
3985  pWrite(strat->B[i].p1);
3986  pWrite(strat->B[i].p2);
3987  wrp(strat->B[i].lcm);
3988  PrintLn();
3989  }
3990 #endif
3991  deleteInL(strat->B,&strat->Bl,i,strat);
3992  strat->c3++;
3993  }
3994  }
3995  }
3996  }
3997  }
3998  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3999  strat->pairtest=NULL;
4000  }
4001  assume(!(strat->Gebauer || strat->fromT));
4002  for (j=strat->Ll; j>=0; j--)
4003  {
4004  if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4005  {
4006  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4007  {
4008  if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4009  {
4010  deleteInL(strat->L,&strat->Ll,j,strat);
4011  strat->c3++;
4012 #ifdef KDEBUG
4013  if (TEST_OPT_DEBUG)
4014  {
4015  PrintS("--- chain criterion func chainCritRing type 2\n");
4016  PrintS("strat->L[j].p:");
4017  wrp(strat->L[j].p);
4018  PrintS(" p:");
4019  wrp(p);
4020  PrintLn();
4021  }
4022 #endif
4023  }
4024  }
4025  }
4026  }
4027  /*
4028  *this is our MODIFICATION of GEBAUER-MOELLER:
4029  *First the elements of B enter L,
4030  *then we fix a lcm and the "best" element in L
4031  *(i.e the last in L with this lcm and of type (s,p))
4032  *and cancel all the other elements of type (r,p) with this lcm
4033  *except the case the element (s,r) has also the same lcm
4034  *and is on the worst position with respect to (s,p) and (r,p)
4035  */
4036  /*
4037  *B enters to L/their order with respect to B is permutated for elements
4038  *B[i].p with the same leading term
4039  */
4040  kMergeBintoL(strat);
4041  j = strat->Ll;
4042  loop /*cannot be changed into a for !!! */
4043  {
4044  if (j <= 0)
4045  {
4046  /*now L[0] cannot be canceled any more and the tail can be removed*/
4047  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4048  break;
4049  }
4050  if (strat->L[j].p2 == p) // Was the element added from B?
4051  {
4052  i = j-1;
4053  loop
4054  {
4055  if (i < 0) break;
4056  // Element is from B and has the same lcm as L[j]
4057  if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4058  && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4059  {
4060  /*L[i] could be canceled but we search for a better one to cancel*/
4061  strat->c3++;
4062 #ifdef KDEBUG
4063  if (TEST_OPT_DEBUG)
4064  {
4065  PrintS("--- chain criterion func chainCritRing type 3\n");
4066  PrintS("strat->L[j].lcm:");
4067  wrp(strat->L[j].lcm);
4068  PrintS(" strat->L[i].lcm:");
4069  wrp(strat->L[i].lcm);
4070  PrintLn();
4071  }
4072 #endif
4073  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4074  && (pNext(strat->L[l].p) == strat->tail)
4075  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4076  && pDivisibleBy(p,strat->L[l].lcm))
4077  {
4078  /*
4079  *"NOT equal(...)" because in case of "equal" the element L[l]
4080  *is "older" and has to be from theoretical point of view behind
4081  *L[i], but we do not want to reorder L
4082  */
4083  strat->L[i].p2 = strat->tail;
4084  /*
4085  *L[l] will be canceled, we cannot cancel L[i] later on,
4086  *so we mark it with "tail"
4087  */
4088  deleteInL(strat->L,&strat->Ll,l,strat);
4089  i--;
4090  }
4091  else
4092  {
4093  deleteInL(strat->L,&strat->Ll,i,strat);
4094  }
4095  j--;
4096  }
4097  i--;
4098  }
4099  }
4100  else if (strat->L[j].p2 == strat->tail)
4101  {
4102  /*now L[j] cannot be canceled any more and the tail can be removed*/
4103  strat->L[j].p2 = p;
4104  }
4105  j--;
4106  }
4107 }
4108 #endif
4109 
4110 #ifdef HAVE_RINGS
4111 long ind2(long arg)
4112 {
4113  long ind = 0;
4114  if (arg <= 0) return 0;
4115  while (arg%2 == 0)
4116  {
4117  arg = arg / 2;
4118  ind++;
4119  }
4120  return ind;
4121 }
4122 
4123 long ind_fact_2(long arg)
4124 {
4125  long ind = 0;
4126  if (arg <= 0) return 0;
4127  if (arg%2 == 1) { arg--; }
4128  while (arg > 0)
4129  {
4130  ind += ind2(arg);
4131  arg = arg - 2;
4132  }
4133  return ind;
4134 }
4135 #endif
4136 
4137 #ifdef HAVE_VANIDEAL
4138 long twoPow(long arg)
4139 {
4140  return 1L << arg;
4141 }
4142 
4143 /*2
4144 * put the pair (p, f) in B and f in T
4145 */
4146 void enterOneZeroPairRing (poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR = -1)
4147 {
4148  int l,j,compare,compareCoeff;
4149  LObject Lp;
4150 
4151 #ifdef KDEBUG
4152  Lp.ecart=0; Lp.length=0;
4153 #endif
4154  /*- computes the lcm(s[i],p) -*/
4155  Lp.lcm = p_Lcm(p,f,Lp.lcm,currRing);
4156  pSetCoeff(Lp.lcm, nLcm(pGetCoeff(p), pGetCoeff(f), currRing));
4157  assume(!strat->sugarCrit);
4158  assume(!strat->fromT);
4159  /*
4160  *the set B collects the pairs of type (S[j],p)
4161  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
4162  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
4163  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
4164  */
4165  for(j = strat->Bl;j>=0;j--)
4166  {
4167  compare=pDivCompRing(strat->B[j].lcm,Lp.lcm);
4168  compareCoeff = nDivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(Lp.lcm));
4169  if (compareCoeff == 0 || compare == compareCoeff)
4170  {
4171  if (compare == 1)
4172  {
4173  strat->c3++;
4174  pLmDelete(Lp.lcm);
4175  return;
4176  }
4177  else
4178  if (compare == -1)
4179  {
4180  deleteInL(strat->B,&strat->Bl,j,strat);
4181  strat->c3++;
4182  }
4183  }
4184  if (compare == pDivComp_EQUAL)
4185  {
4186  // Add hint for same LM and direction of LC (later) (TODO Oliver)
4187  if (compareCoeff == 1)
4188  {
4189  strat->c3++;
4190  pLmDelete(Lp.lcm);
4191  return;
4192  }
4193  else
4194  if (compareCoeff == -1)
4195  {
4196  deleteInL(strat->B,&strat->Bl,j,strat);
4197  strat->c3++;
4198  }
4199  }
4200  }
4201  /*
4202  *the pair (S[i],p) enters B if the spoly != 0
4203  */
4204  /*- compute the short s-polynomial -*/
4205  if ((f==NULL) || (p==NULL)) return;
4206  pNorm(p);
4207  {
4208  Lp.p = ksCreateShortSpoly(f, p, strat->tailRing);
4209  }
4210  if (Lp.p == NULL) //deactivated, as we are adding pairs with zeropoly and not from S
4211  {
4212  /*- the case that the s-poly is 0 -*/
4213 // if (strat->pairtest==NULL) initPairtest(strat);
4214 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
4215 // strat->pairtest[strat->sl+1] = TRUE;
4216  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
4217  /*
4218  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
4219  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
4220  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
4221  *term of p devides the lcm(s,r)
4222  *(this canceling should be done here because
4223  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
4224  *the first case is handeled in chainCrit
4225  */
4226  if (Lp.lcm!=NULL) pLmDelete(Lp.lcm);
4227  }
4228  else
4229  {
4230  /*- the pair (S[i],p) enters B -*/
4231  Lp.p1 = f;
4232  Lp.p2 = p;
4233 
4234  pNext(Lp.p) = strat->tail;
4235 
4236  LObject tmp_h(f, currRing, strat->tailRing);
4237  tmp_h.SetShortExpVector();
4238  strat->initEcart(&tmp_h);
4239  tmp_h.sev = pGetShortExpVector(tmp_h.p);
4240  tmp_h.t_p = t_p;
4241 
4242  enterT(tmp_h, strat, strat->tl + 1);
4243 
4244  if (atR >= 0)
4245  {
4246  Lp.i_r2 = atR;
4247  Lp.i_r1 = strat->tl;
4248  }
4249 
4250  strat->initEcartPair(&Lp,f,p,0/*strat->ecartS[i]*/,ecart); // Attention: TODO: break ecart
4251  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
4252  enterL(&strat->B, &strat->Bl, &strat->Bmax, Lp, l);
4253  }
4254 }
4255 
4256 /* Helper for kCreateZeroPoly
4257  * enumerating the exponents
4258 ring r = 2^2, (a, b, c), lp; ideal G0 = system("createG0"); ideal G = interred(G0); ncols(G0); ncols(G);
4259  */
4260 
4261 int nextZeroSimplexExponent (long exp[], long ind[], long cexp[], long cind[], long* cabsind, long step[], long bound, long N)
4262 /* gives the next exponent from the set H_1 */
4263 {
4264  long add = ind2(cexp[1] + 2);
4265  if ((*cabsind < bound) && (*cabsind - step[1] + add < bound))
4266  {
4267  cexp[1] += 2;
4268  cind[1] += add;
4269  *cabsind += add;
4270  }
4271  else
4272  {
4273  // cabsind >= habsind
4274  if (N == 1) return 0;
4275  int i = 1;
4276  while (exp[i] == cexp[i] && i <= N) i++;
4277  cexp[i] = exp[i];
4278  *cabsind -= cind[i];
4279  cind[i] = ind[i];
4280  step[i] = 500000;
4281  *cabsind += cind[i];
4282  // Print("in: %d\n", *cabsind);
4283  i += 1;
4284  if (i > N) return 0;
4285  do
4286  {
4287  step[1] = 500000;
4288  for (int j = i + 1; j <= N; j++)
4289  {
4290  if (step[1] > step[j]) step[1] = step[j];
4291  }
4292  add = ind2(cexp[i] + 2);
4293  if (*cabsind - step[1] + add >= bound)
4294  {
4295  cexp[i] = exp[i];
4296  *cabsind -= cind[i];
4297  cind[i] = ind[i];
4298  *cabsind += cind[i];
4299  step[i] = 500000;
4300  i += 1;
4301  if (i > N) return 0;
4302  }
4303  else step[1] = -1;
4304  } while (step[1] != -1);
4305  step[1] = 500000;
4306  cexp[i] += 2;
4307  cind[i] += add;
4308  *cabsind += add;
4309  if (add < step[i]) step[i] = add;
4310  for (i = 2; i <= N; i++)
4311  {
4312  if (step[1] > step[i]) step[1] = step[i];
4313  }
4314  }
4315  return 1;
4316 }
4317 
4318 /*
4319  * Creates the zero Polynomial on position exp
4320  * long exp[] : exponent of leading term
4321  * cabsind : total 2-ind of exp (if -1 will be computed)
4322  * poly* t_p : will hold the LT in tailRing
4323  * leadRing : ring for the LT
4324  * tailRing : ring for the tail
4325  */
4326 
4327 poly kCreateZeroPoly(long exp[], long cabsind, poly* t_p, ring leadRing, ring tailRing)
4328 {
4329 
4330  poly zeroPoly = NULL;
4331 
4332  number tmp1;
4333  poly tmp2, tmp3;
4334 
4335  if (cabsind == -1)
4336  {
4337  cabsind = 0;
4338  for (int i = 1; i <= leadRing->N; i++)
4339  {
4340  cabsind += ind_fact_2(exp[i]);
4341  }
4342 // Print("cabsind: %d\n", cabsind);
4343  }
4344  if (cabsind < leadRing->ch)
4345  {
4346  zeroPoly = p_ISet(twoPow(leadRing->ch - cabsind), tailRing);
4347  }
4348  else
4349  {
4350  zeroPoly = p_ISet(1, tailRing);
4351  }
4352  for (int i = 1; i <= leadRing->N; i++)
4353  {
4354  for (long j = 1; j <= exp[i]; j++)
4355  {
4356  tmp1 = nInit(j);
4357  tmp2 = p_ISet(1, tailRing);
4358  p_SetExp(tmp2, i, 1, tailRing);
4359  p_Setm(tmp2, tailRing);
4360  if (nIsZero(tmp1))
4361  { // should nowbe obsolet, test ! TODO OLIVER
4362  zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
4363  }
4364  else
4365  {
4366  tmp3 = p_NSet(nCopy(tmp1), tailRing);
4367  zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing);
4368  }
4369  }
4370  }
4371  tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing);
4372  for (int i = 1; i <= leadRing->N; i++)
4373  {
4374  pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
4375  }
4376  p_Setm(tmp2, leadRing);
4377  *t_p = zeroPoly;
4378  zeroPoly = pNext(zeroPoly);
4379  pNext(*t_p) = NULL;
4380  pNext(tmp2) = zeroPoly;
4381  return tmp2;
4382 }
4383 
4384 // #define OLI_DEBUG
4385 
4386 /*
4387  * Generate the s-polynomial for the virtual set of zero-polynomials
4388  */
4389 
4390 void initenterzeropairsRing (poly p, int ecart, kStrategy strat, int atR)
4391 {
4392  // Initialize
4393  long exp[50]; // The exponent of \hat{X} (basepoint)
4394  long cexp[50]; // The current exponent for iterating over all
4395  long ind[50]; // The power of 2 in the i-th component of exp
4396  long cind[50]; // analog for cexp
4397  long mult[50]; // How to multiply the elements of G
4398  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4399  long habsind = 0; // The abs. index of the coefficient of h
4400  long step[50]; // The last increases
4401  for (int i = 1; i <= currRing->N; i++)
4402  {
4403  exp[i] = p_GetExp(p, i, currRing);
4404  if (exp[i] & 1 != 0)
4405  {
4406  exp[i] = exp[i] - 1;
4407  mult[i] = 1;
4408  }
4409  cexp[i] = exp[i];
4410  ind[i] = ind_fact_2(exp[i]);
4411  cabsind += ind[i];
4412  cind[i] = ind[i];
4413  step[i] = 500000;
4414  }
4415  step[1] = 500000;
4416  habsind = ind2(n_Int(pGetCoeff(p), currRing->cf);
4417  long bound = currRing->ch - habsind;
4418 #ifdef OLI_DEBUG
4419  PrintS("-------------\npoly :");
4420  wrp(p);
4421  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4422  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4423  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4424  Print("bound : %d\n", bound);
4425  Print("cind : %d\n", cabsind);
4426 #endif
4427  if (cabsind == 0)
4428  {
4429  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4430  {
4431  return;
4432  }
4433  }
4434  // Now the whole simplex
4435  do
4436  {
4437  // Build s-polynomial
4438  // 2**ind-def * mult * g - exp-def * h
4439  poly t_p;
4440  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, strat->tailRing);
4441 #ifdef OLI_DEBUG
4442  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4443  PrintS("zPoly : ");
4444  wrp(zeroPoly);
4445  PrintLn();
4446 #endif
4447  enterOneZeroPairRing(zeroPoly, t_p, p, ecart, strat, atR);
4448  }
4449  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4450 }
4451 
4452 /*
4453  * Create the Groebner basis of the vanishing polynomials.
4454  */
4455 
4456 ideal createG0()
4457 {
4458  // Initialize
4459  long exp[50]; // The exponent of \hat{X} (basepoint)
4460  long cexp[50]; // The current exponent for iterating over all
4461  long ind[50]; // The power of 2 in the i-th component of exp
4462  long cind[50]; // analog for cexp
4463  long mult[50]; // How to multiply the elements of G
4464  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4465  long habsind = 0; // The abs. index of the coefficient of h
4466  long step[50]; // The last increases
4467  for (int i = 1; i <= currRing->N; i++)
4468  {
4469  exp[i] = 0;
4470  cexp[i] = exp[i];
4471  ind[i] = 0;
4472  step[i] = 500000;
4473  cind[i] = ind[i];
4474  }
4475  long bound = currRing->ch;
4476  step[1] = 500000;
4477 #ifdef OLI_DEBUG
4478  PrintS("-------------\npoly :");
4479 // wrp(p);
4480  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4481  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4482  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4483  Print("bound : %d\n", bound);
4484  Print("cind : %d\n", cabsind);
4485 #endif
4486  if (cabsind == 0)
4487  {
4488  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4489  {
4490  return idInit(1, 1);
4491  }
4492  }
4493  ideal G0 = idInit(1, 1);
4494  // Now the whole simplex
4495  do
4496  {
4497  // Build s-polynomial
4498  // 2**ind-def * mult * g - exp-def * h
4499  poly t_p;
4500  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, currRing);
4501 #ifdef OLI_DEBUG
4502  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4503  PrintS("zPoly : ");
4504  wrp(zeroPoly);
4505  PrintLn();
4506 #endif
4507  // Add to ideal
4508  pEnlargeSet(&(G0->m), IDELEMS(G0), 1);
4509  IDELEMS(G0) += 1;
4510  G0->m[IDELEMS(G0) - 1] = zeroPoly;
4511  }
4512  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4513  idSkipZeroes(G0);
4514  return G0;
4515 }
4516 #endif
4517 
4518 #ifdef HAVE_RINGS
4519 /*2
4520 *(s[0],h),...,(s[k],h) will be put to the pairset L
4521 */
4522 void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4523 {
4524  if (!nIsOne(pGetCoeff(h)))
4525  {
4526  int j;
4527  BOOLEAN new_pair=FALSE;
4528 
4529  if (pGetComp(h)==0)
4530  {
4531  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4532  if ((isFromQ)&&(strat->fromQ!=NULL))
4533  {
4534  for (j=0; j<=k; j++)
4535  {
4536  if (!strat->fromQ[j])
4537  {
4538  new_pair=TRUE;
4539  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4540  }
4541  }
4542  }
4543  else
4544  {
4545  new_pair=TRUE;
4546  for (j=0; j<=k; j++)
4547  {
4548  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4549  }
4550  }
4551  }
4552  else
4553  {
4554  for (j=0; j<=k; j++)
4555  {
4556  if ((pGetComp(h)==pGetComp(strat->S[j]))
4557  || (pGetComp(strat->S[j])==0))
4558  {
4559  new_pair=TRUE;
4560  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4561  }
4562  }
4563  }
4564  if (new_pair)
4565  {
4566  #ifdef HAVE_RATGRING
4567  if (currRing->real_var_start>0)
4568  chainCritPart(h,ecart,strat);
4569  else
4570  #endif
4571  strat->chainCrit(h,ecart,strat);
4572  }
4573  kMergeBintoL(strat);
4574  }
4575 }
4576 
4577 static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4578 {
4579  const int iCompH = pGetComp(h);
4580  if (!nIsOne(pGetCoeff(h)))
4581  {
4582  int j;
4583 
4584  for (j=0; j<=k && !strat->sigdrop; j++)
4585  {
4586  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4587 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4588 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4589  if (((iCompH == pGetComp(strat->S[j]))
4590  || (0 == pGetComp(strat->S[j])))
4591  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4592  {
4593  enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4594  }
4595  }
4596  }
4597 }
4598 #endif
4599 
4600 #ifdef HAVE_RINGS
4601 /*2
4602 * Generates spoly(0, h) if applicable. Assumes ring in Z/2^n.
4603 */
4605 {
4606  if (nIsOne(pGetCoeff(h))) return;
4607  number gcd;
4608  bool go = false;
4609  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4610  {
4611  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4612  go = true;
4613  }
4614  else
4615  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4616  if (go || !nIsOne(gcd))
4617  {
4618  poly p = h->next;
4619  if (!go)
4620  {
4621  number tmp = gcd;
4622  gcd = n_Ann(gcd,currRing->cf);
4623  nDelete(&tmp);
4624  }
4625  p_Test(p,strat->tailRing);
4626  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4627  nDelete(&gcd);
4628 
4629  if (p != NULL)
4630  {
4631  if (TEST_OPT_PROT)
4632  {
4633  PrintS("Z");
4634  }
4635 #ifdef KDEBUG
4636  if (TEST_OPT_DEBUG)
4637  {
4638  PrintS("--- create zero spoly: ");
4639  p_wrp(h,currRing,strat->tailRing);
4640  PrintS(" ---> ");
4641  }
4642 #endif
4643  poly tmp = pInit();
4644  pSetCoeff0(tmp, pGetCoeff(p));
4645  for (int i = 1; i <= rVar(currRing); i++)
4646  {
4647  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4648  }
4650  {
4651  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4652  }
4653  p_Setm(tmp, currRing);
4654  p = p_LmFreeAndNext(p, strat->tailRing);
4655  pNext(tmp) = p;
4656  LObject Lp;
4657  Lp.Init();
4658  Lp.p = tmp;
4659  Lp.tailRing = strat->tailRing;
4660  int posx;
4661  if (Lp.p!=NULL)
4662  {
4663  strat->initEcart(&Lp);
4664  if (strat->Ll==-1)
4665  posx =0;
4666  else
4667  posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4668  Lp.sev = pGetShortExpVector(Lp.p);
4669  if (strat->tailRing != currRing)
4670  {
4671  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4672  }
4673 #ifdef KDEBUG
4674  if (TEST_OPT_DEBUG)
4675  {
4676  p_wrp(tmp,currRing,strat->tailRing);
4677  PrintLn();
4678  }
4679 #endif
4680  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4681  }
4682  }
4683  }
4684  nDelete(&gcd);
4685 }
4686 
4687 void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
4688 {
4689  if (nIsOne(pGetCoeff(h))) return;
4690  number gcd;
4691  bool go = false;
4692  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4693  {
4694  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4695  go = true;
4696  }
4697  else
4698  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4699  if (go || !nIsOne(gcd))
4700  {
4701  poly p = h->next;
4702  if (!go)
4703  {
4704  number tmp = gcd;
4705  gcd = n_Ann(gcd,currRing->cf);
4706  nDelete(&tmp);
4707  }
4708  p_Test(p,strat->tailRing);
4709  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4710 
4711  if (p != NULL)
4712  {
4713  if (TEST_OPT_PROT)
4714  {
4715  PrintS("Z");
4716  }
4717 #ifdef KDEBUG
4718  if (TEST_OPT_DEBUG)
4719  {
4720  PrintS("--- create zero spoly: ");
4721  p_wrp(h,currRing,strat->tailRing);
4722  PrintS(" ---> ");
4723  }
4724 #endif
4725  poly tmp = pInit();
4726  pSetCoeff0(tmp, pGetCoeff(p));
4727  for (int i = 1; i <= rVar(currRing); i++)
4728  {
4729  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4730  }
4732  {
4733  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4734  }
4735  p_Setm(tmp, currRing);
4736  p = p_LmFreeAndNext(p, strat->tailRing);
4737  pNext(tmp) = p;
4738  LObject Lp;
4739  Lp.Init();
4740  Lp.p = tmp;
4741  //printf("\nOld\n");pWrite(h);pWrite(hSig);
4742  #if EXT_POLY_NEW
4743  Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4744  if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4745  {
4746  strat->sigdrop = TRUE;
4747  //Try to reduce it as far as we can via redRing
4748  int red_result = redRing(&Lp,strat);
4749  if(red_result == 0)
4750  {
4751  // Cancel the sigdrop
4752  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4753  strat->sigdrop = FALSE;
4754  return;
4755  }
4756  else
4757  {
4758  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4759  #if 1
4760  strat->enterS(Lp,0,strat,strat->tl);
4761  #endif
4762  return;
4763  }
4764 
4765  }
4766  #else
4767  Lp.sig = pOne();
4768  if(strat->Ll >= 0)
4769  p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4770  else
4771  p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4772  #endif
4773  Lp.tailRing = strat->tailRing;
4774  int posx;
4775  if (Lp.p!=NULL)
4776  {
4777  strat->initEcart(&Lp);
4778  if (strat->Ll==-1)
4779  posx =0;
4780  else
4781  posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4782  Lp.sev = pGetShortExpVector(Lp.p);
4783  if (strat->tailRing != currRing)
4784  {
4785  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4786  }
4787 #ifdef KDEBUG
4788  if (TEST_OPT_DEBUG)
4789  {
4790  p_wrp(tmp,currRing,strat->tailRing);
4791  PrintLn();
4792  }
4793 #endif
4794  //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4795  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4796  }
4797  }
4798  nDelete(&gcd);
4799  }
4800  nDelete(&gcd);
4801 }
4802 #endif
4803 
4804 #ifdef HAVE_RINGS
4805 void clearSbatch (poly h,int k,int pos,kStrategy strat)
4806 {
4807  int j = pos;
4808  if ( (!strat->fromT)
4809  && ((strat->syzComp==0)
4810  ||(pGetComp(h)<=strat->syzComp)
4811  ))
4812  {
4813  // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4814  unsigned long h_sev = pGetShortExpVector(h);
4815  loop
4816  {
4817  if (j > k) break;
4818  clearS(h,h_sev, &j,&k,strat);
4819  j++;
4820  }
4821  // Print("end clearS sl=%d\n",strat->sl);
4822  }
4823 }
4824 #endif
4825 
4826 #ifdef HAVE_RINGS
4827 /*2
4828 * Generates a sufficient set of spolys (maybe just a finite generating
4829 * set of the syzygys)
4830 */
4831 void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4832 {
4834  // enter also zero divisor * poly, if this is non zero and of smaller degree
4835  if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat);
4836  initenterstrongPairs(h, k, ecart, 0, strat, atR);
4837  initenterpairs(h, k, ecart, 0, strat, atR);
4838  clearSbatch(h, k, pos, strat);
4839 }
4840 
4841 void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4842 {
4844  // enter also zero divisor * poly, if this is non zero and of smaller degree
4845  if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4846  if(strat->sigdrop) return;
4847  initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4848  if(strat->sigdrop) return;
4849  initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4850  if(strat->sigdrop) return;
4851  clearSbatch(h, k, pos, strat);
4852 }
4853 #endif
4854 
4855 /*2
4856 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4857 *superfluous elements in S will be deleted
4858 */
4859 void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4860 {
4861  int j=pos;
4862 
4864  initenterpairs(h,k,ecart,0,strat, atR);
4865  if ( (!strat->fromT)
4866  && ((strat->syzComp==0)
4867  ||(pGetComp(h)<=strat->syzComp)))
4868  {
4869  unsigned long h_sev = pGetShortExpVector(h);
4870  loop
4871  {
4872  if (j > k) break;
4873  clearS(h,h_sev, &j,&k,strat);
4874  j++;
4875  }
4876  }
4877 }
4878 
4879 /*2
4880 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4881 *superfluous elements in S will be deleted
4882 *this is a special variant of signature-based algorithms including the
4883 *signatures for criteria checks
4884 */
4885 void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4886 {
4887  int j=pos;
4889  initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4890  if ( (!strat->fromT)
4891  && ((strat->syzComp==0)
4892  ||(pGetComp(h)<=strat->syzComp)))
4893  {
4894  unsigned long h_sev = pGetShortExpVector(h);
4895  loop
4896  {
4897  if (j > k) break;
4898  clearS(h,h_sev, &j,&k,strat);
4899  j++;
4900  }
4901  }
4902 }
4903 
4904 /*2
4905 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4906 *superfluous elements in S will be deleted
4907 */
4908 void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4909 {
4910  int j;
4911  const int iCompH = pGetComp(h);
4912 
4913  if (rField_is_Ring(currRing))
4914  {
4915  for (j=0; j<=k; j++)
4916  {
4917  const int iCompSj = pGetComp(strat->S[j]);
4918  if ((iCompH==iCompSj)
4919  //|| (0==iCompH) // can only happen,if iCompSj==0
4920  || (0==iCompSj))
4921  {
4922  enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4923  }
4924  }
4925  kMergeBintoL(strat);
4926  }
4927  else
4928  {
4929  for (j=0; j<=k; j++)
4930  {
4931  const int iCompSj = pGetComp(strat->S[j]);
4932  if ((iCompH==iCompSj)
4933  //|| (0==iCompH) // can only happen,if iCompSj==0
4934  || (0==iCompSj))
4935  {
4936  enterOnePairSpecial(j,h,ecart,strat, atR);
4937  }
4938  }
4939  }
4940 
4941  if (strat->noClearS) return;
4942 
4943 // #ifdef HAVE_PLURAL
4944 /*
4945  if (rIsPluralRing(currRing))
4946  {
4947  j=pos;
4948  loop
4949  {
4950  if (j > k) break;
4951 
4952  if (pLmDivisibleBy(h, strat->S[j]))
4953  {
4954  deleteInS(j, strat);
4955  j--;
4956  k--;
4957  }
4958 
4959  j++;
4960  }
4961  }
4962  else
4963 */
4964 // #endif // ??? Why was the following cancelation disabled for non-commutative rings?
4965  {
4966  j=pos;
4967  loop
4968  {
4969  unsigned long h_sev = pGetShortExpVector(h);
4970  if (j > k) break;
4971  clearS(h,h_sev,&j,&k,strat);
4972  j++;
4973  }
4974  }
4975 }
4976 
4977 /*2
4978 *reorders s with respect to posInS,
4979 *suc is the first changed index or zero
4980 */
4981 
4982 void reorderS (int* suc,kStrategy strat)
4983 {
4984  int i,j,at,ecart, s2r;
4985  int fq=0;
4986  unsigned long sev;
4987  poly p;
4988  int new_suc=strat->sl+1;
4989  i= *suc;
4990  if (i<0) i=0;
4991 
4992  for (; i<=strat->sl; i++)
4993  {
4994  at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4995  if (at != i)
4996  {
4997  if (new_suc > at) new_suc = at;
4998  p = strat->S[i];
4999  ecart = strat->ecartS[i];
5000  sev = strat->sevS[i];
5001  s2r = strat->S_2_R[i];
5002  if (strat->fromQ!=NULL) fq=strat->fromQ[i];
5003  for (j=i; j>=at+1; j--)
5004  {
5005  strat->S[j] = strat->S[j-1];
5006  strat->ecartS[j] = strat->ecartS[j-1];
5007  strat->sevS[j] = strat->sevS[j-1];
5008  strat->S_2_R[j] = strat->S_2_R[j-1];
5009  }
5010  strat->S[at] = p;
5011  strat->ecartS[at] = ecart;
5012  strat->sevS[at] = sev;
5013  strat->S_2_R[at] = s2r;
5014  if (strat->fromQ!=NULL)
5015  {
5016  for (j=i; j>=at+1; j--)
5017  {
5018  strat->fromQ[j] = strat->fromQ[j-1];
5019  }
5020  strat->fromQ[at]=fq;
5021  }
5022  }
5023  }
5024  if (new_suc <= strat->sl) *suc=new_suc;
5025  else *suc=-1;
5026 }
5027 
5028 
5029 /*2
5030 *looks up the position of p in set
5031 *set[0] is the smallest with respect to the ordering-procedure deg/pComp
5032 * Assumption: posInS only depends on the leading term
5033 * otherwise, bba has to be changed
5034 */
5035 int posInS (const kStrategy strat, const int length,const poly p,
5036  const int ecart_p)
5037 {
5038  if(length==-1) return 0;
5039  polyset set=strat->S;
5040  int i;
5041  int an = 0;
5042  int en = length;
5043  int cmp_int = currRing->OrdSgn;
5045 #ifdef HAVE_PLURAL
5046  && (currRing->real_var_start==0)
5047 #endif
5048 #if 0
5049  || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
5050 #endif
5051  )
5052  {
5053  int o=p_Deg(p,currRing);
5054  int oo=p_Deg(set[length],currRing);
5055 
5056  if ((oo<o)
5057  || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
5058  return length+1;
5059 
5060  loop
5061  {
5062  if (an >= en-1)
5063  {
5064  if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
5065  {
5066  return an;
5067  }
5068  return en;
5069  }
5070  i=(an+en) / 2;
5071  if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
5072  else an=i;
5073  }
5074  }
5075  else
5076  {
5077  if (rField_is_Ring(currRing))
5078  {
5079  if (pLmCmp(set[length],p)== -cmp_int)
5080  return length+1;
5081  int cmp;
5082  loop
5083  {
5084  if (an >= en-1)
5085  {
5086  cmp = pLmCmp(set[an],p);
5087  if (cmp == cmp_int) return an;
5088  if (cmp == -cmp_int) return en;
5089  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
5090  return an;
5091  }
5092  i = (an+en) / 2;
5093  cmp = pLmCmp(set[i],p);
5094  if (cmp == cmp_int) en = i;
5095  else if (cmp == -cmp_int) an = i;
5096  else
5097  {
5098  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
5099  else en = i;
5100  }
5101  }
5102  }
5103  else
5104  if (pLmCmp(set[length],p)== -cmp_int)
5105  return length+1;
5106 
5107  loop
5108  {
5109  if (an >= en-1)
5110  {
5111  if (pLmCmp(set[an],p) == cmp_int) return an;
5112  if (pLmCmp(set[an],p) == -cmp_int) return en;
5113  if ((cmp_int!=1)
5114  && ((strat->ecartS[an])>ecart_p))
5115  return an;
5116  return en;
5117  }
5118  i=(an+en) / 2;
5119  if (pLmCmp(set[i],p) == cmp_int) en=i;
5120  else if (pLmCmp(set[i],p) == -cmp_int) an=i;
5121  else
5122  {
5123  if ((cmp_int!=1)
5124  &&((strat->ecartS[i])<ecart_p))
5125  en=i;
5126  else
5127  an=i;
5128  }
5129  }
5130  }
5131 }
5132 
5133 
5134 // sorts by degree and pLtCmp
5135 // but puts pure monomials at the beginning
5136 int posInSMonFirst (const kStrategy strat, const int length,const poly p)
5137 {
5138  if (length<0) return 0;
5139  polyset set=strat->S;
5140  if(pNext(p) == NULL)
5141  {
5142  int mon = 0;
5143  for(int i = 0;i<=length;i++)
5144  {
5145  if(set[i] != NULL && pNext(set[i]) == NULL)
5146  mon++;
5147  }
5148  int o = p_Deg(p,currRing);
5149  int op = p_Deg(set[mon],currRing);
5150 
5151  if ((op < o)
5152  || ((op == o) && (pLtCmp(set[mon],p) == -1)))
5153  return length+1;
5154  int i;
5155  int an = 0;
5156  int en= mon;
5157  loop
5158  {
5159  if (an >= en-1)
5160  {
5161  op = p_Deg(set[an],currRing);
5162  if ((op < o)
5163  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5164  return en;
5165  return an;
5166  }
5167  i=(an+en) / 2;
5168  op = p_Deg(set[i],currRing);
5169  if ((op < o)
5170  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5171  an=i;
5172  else
5173  en=i;
5174  }
5175  }
5176  else /*if(pNext(p) != NULL)*/
5177  {
5178  int o = p_Deg(p,currRing);
5179  int op = p_Deg(set[length],currRing);
5180 
5181  if ((op < o)
5182  || ((op == o) && (pLtCmp(set[length],p) == -1)))
5183  return length+1;
5184  int i;
5185  int an = 0;
5186  for(i=0;i<=length;i++)
5187  if(set[i] != NULL && pNext(set[i]) == NULL)
5188  an++;
5189  int en= length;
5190  loop
5191  {
5192  if (an >= en-1)
5193  {
5194  op = p_Deg(set[an],currRing);
5195  if ((op < o)
5196  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5197  return en;
5198  return an;
5199  }
5200  i=(an+en) / 2;
5201  op = p_Deg(set[i],currRing);
5202  if ((op < o)
5203  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5204  an=i;
5205  else
5206  en=i;
5207  }
5208  }
5209 }
5210 
5211 // sorts by degree and pLtCmp in the block between start,end;
5212 // but puts pure monomials at the beginning
5213 int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
5214 {
5215  if(end < 0 || end >= IDELEMS(F))
5216  end = IDELEMS(F);
5217  if (end<0) return 0;
5218  if(pNext(p) == NULL) return start;
5219  polyset set=F->m;
5220  int o = p_Deg(p,currRing);
5221  int op;
5222  int i;
5223  int an = start;
5224  for(i=start;i<end;i++)
5225  if(set[i] != NULL && pNext(set[i]) == NULL)
5226  an++;
5227  if(an == end-1)
5228  return end;
5229  int en= end;
5230  loop
5231  {
5232  if(an>=en)
5233  return en;
5234  if (an == en-1)
5235  {
5236  op = p_Deg(set[an],currRing);
5237  if ((op < o)
5238  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5239  return en;
5240  return an;
5241  }
5242  i=(an+en) / 2;
5243  op = p_Deg(set[i],currRing);
5244  if ((op < o)
5245  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5246  an=i;
5247  else
5248  en=i;
5249  }
5250 }
5251 
5252 
5253 /*2
5254 * looks up the position of p in set
5255 * the position is the last one
5256 */
5257 int posInT0 (const TSet,const int length,LObject &)
5258 {
5259  return (length+1);
5260 }
5261 
5262 
5263 /*2
5264 * looks up the position of p in T
5265 * set[0] is the smallest with respect to the ordering-procedure
5266 * pComp
5267 */
5268 int posInT1 (const TSet set,const int length,LObject &p)
5269 {
5270  if (length==-1) return 0;
5271 
5272  if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
5273 
5274  int i;
5275  int an = 0;
5276  int en= length;
5277 
5278  loop
5279  {
5280  if (an >= en-1)
5281  {
5282  if (pLmCmp(set[an].p,p.p) == currRing->OrdSgn) return an;
5283  return en;
5284  }
5285  i=(an+en) / 2;
5286  if (pLmCmp(set[i].p,p.p) == currRing->OrdSgn) en=i;
5287  else an=i;
5288  }
5289 }
5290 
5291 /*2
5292 * looks up the position of p in T
5293 * set[0] is the smallest with respect to the ordering-procedure
5294 * length
5295 */
5296 int posInT2 (const TSet set,const int length,LObject &p)
5297 {
5298  p.GetpLength();
5299  if (length==-1)
5300  return 0;
5301  if (set[length].length<p.length)
5302  return length+1;
5303 
5304  int i;
5305  int an = 0;
5306  int en= length;
5307 
5308  loop
5309  {
5310  if (an >= en-1)
5311  {
5312  if (set[an].length>p.length) return an;
5313  return en;
5314  }
5315  i=(an+en) / 2;
5316  if (set[i].length>p.length) en=i;
5317  else an=i;
5318  }
5319 }
5320 
5321 /*2
5322 * looks up the position of p in T
5323 * set[0] is the smallest with respect to the ordering-procedure
5324 * totaldegree,pComp
5325 */
5326 int posInT11 (const TSet set,const int length,LObject &p)
5327 {
5328  if (length==-1) return 0;
5329 
5330  int o = p.GetpFDeg();
5331  int op = set[length].GetpFDeg();
5332 
5333  if ((op < o)
5334  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5335  return length+1;
5336 
5337  int i;
5338  int an = 0;
5339  int en= length;
5340 
5341  loop
5342  {
5343  if (an >= en-1)
5344  {
5345  op= set[an].GetpFDeg();
5346  if ((op > o)
5347  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5348  return an;
5349  return en;
5350  }
5351  i=(an+en) / 2;
5352  op = set[i].GetpFDeg();
5353  if (( op > o)
5354  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5355  en=i;
5356  else
5357  an=i;
5358  }
5359 }
5360 
5361 #ifdef HAVE_RINGS
5362 int posInT11Ring (const TSet set,const int length,LObject &p)
5363 {
5364  if (length==-1) return 0;
5365 
5366  int o = p.GetpFDeg();
5367  int op = set[length].GetpFDeg();
5368 
5369  if ((op < o)
5370  || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5371  return length+1;
5372 
5373  int i;
5374  int an = 0;
5375  int en= length;
5376 
5377  loop
5378  {
5379  if (an >= en-1)
5380  {
5381  op= set[an].GetpFDeg();
5382  if ((op > o)
5383  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5384  return an;
5385  return en;
5386  }
5387  i=(an+en) / 2;
5388  op = set[i].GetpFDeg();
5389  if (( op > o)
5390  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5391  en=i;
5392  else
5393  an=i;
5394  }
5395 }
5396 #endif
5397 
5398 /*2 Pos for rings T: Here I am
5399 * looks up the position of p in T
5400 * set[0] is the smallest with respect to the ordering-procedure
5401 * totaldegree,pComp
5402 */
5403 int posInTrg0 (const TSet set,const int length,LObject &p)
5404 {
5405  if (length==-1) return 0;
5406  int o = p.GetpFDeg();
5407  int op = set[length].GetpFDeg();
5408  int i;
5409  int an = 0;
5410  int en = length;
5411  int cmp_int = currRing->OrdSgn;
5412  if ((op < o) || (pLmCmp(set[length].p,p.p)== -cmp_int))
5413  return length+1;
5414  int cmp;
5415  loop
5416  {
5417  if (an >= en-1)
5418  {
5419  op = set[an].GetpFDeg();
5420  if (op > o) return an;
5421  if (op < 0) return en;
5422  cmp = pLmCmp(set[an].p,p.p);
5423  if (cmp == cmp_int) return an;
5424  if (cmp == -cmp_int) return en;
5425  if (nGreater(pGetCoeff(p.p), pGetCoeff(set[an].p))) return en;
5426  return an;
5427  }
5428  i = (an + en) / 2;
5429  op = set[i].GetpFDeg();
5430  if (op > o) en = i;
5431  else if (op < o) an = i;
5432  else
5433  {
5434  cmp = pLmCmp(set[i].p,p.p);
5435  if (cmp == cmp_int) en = i;
5436  else if (cmp == -cmp_int) an = i;
5437  else if (nGreater(pGetCoeff(p.p), pGetCoeff(set[i].p))) an = i;
5438  else en = i;
5439  }
5440  }
5441 }
5442 /*
5443  int o = p.GetpFDeg();
5444  int op = set[length].GetpFDeg();
5445 
5446  if ((op < o)
5447  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5448  return length+1;
5449 
5450  int i;
5451  int an = 0;
5452  int en= length;
5453 
5454  loop
5455  {
5456  if (an >= en-1)
5457  {
5458  op= set[an].GetpFDeg();
5459  if ((op > o)
5460  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5461  return an;
5462  return en;
5463  }
5464  i=(an+en) / 2;
5465  op = set[i].GetpFDeg();
5466  if (( op > o)
5467  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5468  en=i;
5469  else
5470  an=i;
5471  }
5472 }
5473  */
5474 /*2
5475 * looks up the position of p in T
5476 * set[0] is the smallest with respect to the ordering-procedure
5477 * totaldegree,pComp
5478 */
5479 int posInT110 (const TSet set,const int length,LObject &p)
5480 {
5481  p.GetpLength();
5482  if (length==-1) return 0;
5483 
5484  int o = p.GetpFDeg();
5485  int op = set[length].GetpFDeg();
5486 
5487  if (( op < o)
5488  || (( op == o) && (set[length].length<p.length))
5489  || (( op == o) && (set[length].length == p.length)
5490  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5491  return length+1;
5492 
5493  int i;
5494  int an = 0;
5495  int en= length;
5496  loop
5497  {
5498  if (an >= en-1)
5499  {
5500  op = set[an].GetpFDeg();
5501  if (( op > o)
5502  || (( op == o) && (set[an].length > p.length))
5503  || (( op == o) && (set[an].length == p.length)
5504  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5505  return an;
5506  return en;
5507  }
5508  i=(an+en) / 2;
5509  op = set[i].GetpFDeg();
5510  if (( op > o)
5511  || (( op == o) && (set[i].length > p.length))
5512  || (( op == o) && (set[i].length == p.length)
5513  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5514  en=i;
5515  else
5516  an=i;
5517  }
5518 }
5519 
5520 #ifdef HAVE_RINGS
5521 int posInT110Ring (const TSet set,const int length,LObject &p)
5522 {
5523  p.GetpLength();
5524  if (length==-1) return 0;
5525 
5526  int o = p.GetpFDeg();
5527  int op = set[length].GetpFDeg();
5528 
5529  if (( op < o)
5530  || (( op == o) && (set[length].length<p.length))
5531  || (( op == o) && (set[length].length == p.length)
5532  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5533  return length+1;
5534 
5535  int i;
5536  int an = 0;
5537  int en= length;
5538  loop
5539  {
5540  if (an >= en-1)
5541  {
5542  op = set[an].GetpFDeg();
5543  if (( op > o)
5544  || (( op == o) && (set[an].length > p.length))
5545  || (( op == o) && (set[an].length == p.length)
5546  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5547  return an;
5548  return en;
5549  }
5550  i=(an+en) / 2;
5551  op = set[i].GetpFDeg();
5552  if (( op > o)
5553  || (( op == o) && (set[i].length > p.length))
5554  || (( op == o) && (set[i].length == p.length)
5555  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5556  en=i;
5557  else
5558  an=i;
5559  }
5560 }
5561 #endif
5562 
5563 /*2
5564 * looks up the position of p in set
5565 * set[0] is the smallest with respect to the ordering-procedure
5566 * pFDeg
5567 */
5568 int posInT13 (const TSet set,const int length,LObject &p)
5569 {
5570  if (length==-1) return 0;
5571 
5572  int o = p.GetpFDeg();
5573 
5574  if (set[length].GetpFDeg() <= o)
5575  return length+1;
5576 
5577  int i;
5578  int an = 0;
5579  int en= length;
5580  loop
5581  {
5582  if (an >= en-1)
5583  {
5584  if (set[an].GetpFDeg() > o)
5585  return an;
5586  return en;
5587  }
5588  i=(an+en) / 2;
5589  if (set[i].GetpFDeg() > o)
5590  en=i;
5591  else
5592  an=i;
5593  }
5594 }
5595 
5596 // determines the position based on: 1.) Ecart 2.) pLength
5597 int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5598 {
5599  int ol = p.GetpLength();
5600  if (length==-1) return 0;
5601 
5602  int op=p.ecart;
5603 
5604  int oo=set[length].ecart;
5605  if ((oo < op) || ((oo==op) && (set[length].length <= ol)))
5606  return length+1;
5607 
5608  int i;
5609  int an = 0;
5610  int en= length;
5611  loop
5612  {
5613  if (an >= en-1)
5614  {
5615  int oo=set[an].ecart;
5616  if((oo > op)
5617  || ((oo==op) && (set[an].pLength > ol)))
5618  return an;
5619  return en;
5620  }
5621  i=(an+en) / 2;
5622  int oo=set[i].ecart;
5623  if ((oo > op)
5624  || ((oo == op) && (set[i].pLength > ol)))
5625  en=i;
5626  else
5627  an=i;
5628  }
5629 }
5630 
5631 /*2
5632 * looks up the position of p in set
5633 * set[0] is the smallest with respect to the ordering-procedure
5634 * maximaldegree, pComp
5635 */
5636 int posInT15 (const TSet set,const int length,LObject &p)
5637 /*{
5638  *int j=0;
5639  * int o;
5640  *
5641  * o = p.GetpFDeg()+p.ecart;
5642  * loop
5643  * {
5644  * if ((set[j].GetpFDeg()+set[j].ecart > o)
5645  * || ((set[j].GetpFDeg()+set[j].ecart == o)
5646  * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5647  * {
5648  * return j;
5649  * }
5650  * j++;
5651  * if (j > length) return j;
5652  * }
5653  *}
5654  */
5655 {
5656  if (length==-1) return 0;
5657 
5658  int o = p.GetpFDeg() + p.ecart;
5659  int op = set[length].GetpFDeg()+set[length].ecart;
5660 
5661  if ((op < o)
5662  || ((op == o)
5663  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5664  return length+1;
5665 
5666  int i;
5667  int an = 0;
5668  int en= length;
5669  loop
5670  {
5671  if (an >= en-1)
5672  {
5673  op = set[an].GetpFDeg()+set[an].ecart;
5674  if (( op > o)
5675  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5676  return an;
5677  return en;
5678  }
5679  i=(an+en) / 2;
5680  op = set[i].GetpFDeg()+set[i].ecart;
5681  if (( op > o)
5682  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5683  en=i;
5684  else
5685  an=i;
5686  }
5687 }
5688 
5689 #ifdef HAVE_RINGS
5690 int posInT15Ring (const TSet set,const int length,LObject &p)
5691 {
5692  if (length==-1) return 0;
5693 
5694  int o = p.GetpFDeg() + p.ecart;
5695  int op = set[length].GetpFDeg()+set[length].ecart;
5696 
5697  if ((op < o)
5698  || ((op == o)
5699  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5700  return length+1;
5701 
5702  int i;
5703  int an = 0;
5704  int en= length;
5705  loop
5706  {
5707  if (an >= en-1)
5708  {
5709  op = set[an].GetpFDeg()+set[an].ecart;
5710  if (( op > o)
5711  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5712  return an;
5713  return en;
5714  }
5715  i=(an+en) / 2;
5716  op = set[i].GetpFDeg()+set[i].ecart;
5717  if (( op > o)
5718  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5719  en=i;
5720  else
5721  an=i;
5722  }
5723 }
5724 #endif
5725 
5726 /*2
5727 * looks up the position of p in set
5728 * set[0] is the smallest with respect to the ordering-procedure
5729 * pFDeg+ecart, ecart, pComp
5730 */
5731 int posInT17 (const TSet set,const int length,LObject &p)
5732 /*
5733 *{
5734 * int j=0;
5735 * int o;
5736 *
5737 * o = p.GetpFDeg()+p.ecart;
5738 * loop
5739 * {
5740 * if ((pFDeg(set[j].p)+set[j].ecart > o)
5741 * || (((pFDeg(set[j].p)+set[j].ecart == o)
5742 * && (set[j].ecart < p.ecart)))
5743 * || ((pFDeg(set[j].p)+set[j].ecart == o)
5744 * && (set[j].ecart==p.ecart)
5745 * && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5746 * return j;
5747 * j++;
5748 * if (j > length) return j;
5749 * }
5750 * }
5751 */
5752 {
5753  if (length==-1) return 0;
5754 
5755  int o = p.GetpFDeg() + p.ecart;
5756  int op = set[length].GetpFDeg()+set[length].ecart;
5757 
5758  if ((op < o)
5759  || (( op == o) && (set[length].ecart > p.ecart))
5760  || (( op == o) && (set[length].ecart==p.ecart)
5761  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5762  return length+1;
5763 
5764  int i;
5765  int an = 0;
5766  int en= length;
5767  loop
5768  {
5769  if (an >= en-1)
5770  {
5771  op = set[an].GetpFDeg()+set[an].ecart;
5772  if (( op > o)
5773  || (( op == o) && (set[an].ecart < p.ecart))
5774  || (( op == o) && (set[an].ecart==p.ecart)
5775  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5776  return an;
5777  return en;
5778  }
5779  i=(an+en) / 2;
5780  op = set[i].GetpFDeg()+set[i].ecart;
5781  if ((op > o)
5782  || (( op == o) && (set[i].ecart < p.ecart))
5783  || (( op == o) && (set[i].ecart == p.ecart)
5784  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5785  en=i;
5786  else
5787  an=i;
5788  }
5789 }
5790 
5791 #ifdef HAVE_RINGS
5792 int posInT17Ring (const TSet set,const int length,LObject &p)
5793 {
5794  if (length==-1) return 0;
5795 
5796  int o = p.GetpFDeg() + p.ecart;
5797  int op = set[length].GetpFDeg()+set[length].ecart;
5798 
5799  if ((op < o)
5800  || (( op == o) && (set[length].ecart > p.ecart))
5801  || (( op == o) && (set[length].ecart==p.ecart)
5802  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5803  return length+1;
5804 
5805  int i;
5806  int an = 0;
5807  int en= length;
5808  loop
5809  {
5810  if (an >= en-1)
5811  {
5812  op = set[an].GetpFDeg()+set[an].ecart;
5813  if (( op > o)
5814  || (( op == o) && (set[an].ecart < p.ecart))
5815  || (( op == o) && (set[an].ecart==p.ecart)
5816  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5817  return an;
5818  return en;
5819  }
5820  i=(an+en) / 2;
5821  op = set[i].GetpFDeg()+set[i].ecart;
5822  if ((op > o)
5823  || (( op == o) && (set[i].ecart < p.ecart))
5824  || (( op == o) && (set[i].ecart == p.ecart)
5825  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5826  en=i;
5827  else
5828  an=i;
5829  }
5830 }
5831 #endif
5832 
5833 /*2
5834 * looks up the position of p in set
5835 * set[0] is the smallest with respect to the ordering-procedure
5836 * pGetComp, pFDeg+ecart, ecart, pComp
5837 */
5838 int posInT17_c (const TSet set,const int length,LObject &p)
5839 {
5840  if (length==-1) return 0;
5841 
5842  int cc = (-1+2*currRing->order[0]==ringorder_c);
5843  /* cc==1 for (c,..), cc==-1 for (C,..) */
5844  int o = p.GetpFDeg() + p.ecart;
5845  int c = pGetComp(p.p)*cc;
5846 
5847  if (pGetComp(set[length].p)*cc < c)
5848  return length+1;
5849  if (pGetComp(set[length].p)*cc == c)
5850  {
5851  int op = set[length].GetpFDeg()+set[length].ecart;
5852  if ((op < o)
5853  || ((op == o) && (set[length].ecart > p.ecart))
5854  || ((op == o) && (set[length].ecart==p.ecart)
5855  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5856  return length+1;
5857  }
5858 
5859  int i;
5860  int an = 0;
5861  int en= length;
5862  loop
5863  {
5864  if (an >= en-1)
5865  {
5866  if (pGetComp(set[an].p)*cc < c)
5867  return en;
5868  if (pGetComp(set[an].p)*cc == c)
5869  {
5870  int op = set[an].GetpFDeg()+set[an].ecart;
5871  if ((op > o)
5872  || ((op == o) && (set[an].ecart < p.ecart))
5873  || ((op == o) && (set[an].ecart==p.ecart)
5874  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5875  return an;
5876  }
5877  return en;
5878  }
5879  i=(an+en) / 2;
5880  if (pGetComp(set[i].p)*cc > c)
5881  en=i;
5882  else if (pGetComp(set[i].p)*cc == c)
5883  {
5884  int op = set[i].GetpFDeg()+set[i].ecart;
5885  if ((op > o)
5886  || ((op == o) && (set[i].ecart < p.ecart))
5887  || ((op == o) && (set[i].ecart == p.ecart)
5888  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5889  en=i;
5890  else
5891  an=i;
5892  }
5893  else
5894  an=i;
5895  }
5896 }
5897 
5898 #ifdef HAVE_RINGS
5899 int posInT17_cRing (const TSet set,const int length,LObject &p)
5900 {
5901  if (length==-1) return 0;
5902 
5903  int cc = (-1+2*currRing->order[0]==ringorder_c);
5904  /* cc==1 for (c,..), cc==-1 for (C,..) */
5905  int o = p.GetpFDeg() + p.ecart;
5906  int c = pGetComp(p.p)*cc;
5907 
5908  if (pGetComp(set[length].p)*cc < c)
5909  return length+1;
5910  if (pGetComp(set[length].p)*cc == c)
5911  {
5912  int op = set[length].GetpFDeg()+set[length].ecart;
5913  if ((op < o)
5914  || ((op == o) && (set[length].ecart > p.ecart))
5915  || ((op == o) && (set[length].ecart==p.ecart)
5916  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5917  return length+1;
5918  }
5919 
5920  int i;
5921  int an = 0;
5922  int en= length;
5923  loop
5924  {
5925  if (an >= en-1)
5926  {
5927  if (pGetComp(set[an].p)*cc < c)
5928  return en;
5929  if (pGetComp(set[an].p)*cc == c)
5930  {
5931  int op = set[an].GetpFDeg()+set[an].ecart;
5932  if ((op > o)
5933  || ((op == o) && (set[an].ecart < p.ecart))
5934  || ((op == o) && (set[an].ecart==p.ecart)
5935  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5936  return an;
5937  }
5938  return en;
5939  }
5940  i=(an+en) / 2;
5941  if (pGetComp(set[i].p)*cc > c)
5942  en=i;
5943  else if (pGetComp(set[i].p)*cc == c)
5944  {
5945  int op = set[i].GetpFDeg()+set[i].ecart;
5946  if ((op > o)
5947  || ((op == o) && (set[i].ecart < p.ecart))
5948  || ((op == o) && (set[i].ecart == p.ecart)
5949  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5950  en=i;
5951  else
5952  an=i;
5953  }
5954  else
5955  an=i;
5956  }
5957 }
5958 #endif
5959 
5960 /*2
5961 * looks up the position of p in set
5962 * set[0] is the smallest with respect to
5963 * ecart, pFDeg, length
5964 */
5965 int posInT19 (const TSet set,const int length,LObject &p)
5966 {
5967  p.GetpLength();
5968  if (length==-1) return 0;
5969 
5970  int o = p.ecart;
5971  int op=p.GetpFDeg();
5972 
5973  if (set[length].ecart < o)
5974  return length+1;
5975  if (set[length].ecart == o)
5976  {
5977  int oo=set[length].GetpFDeg();
5978  if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5979  return length+1;
5980  }
5981 
5982  int i;
5983  int an = 0;
5984  int en= length;
5985  loop
5986  {
5987  if (an >= en-1)
5988  {
5989  if (set[an].ecart > o)
5990  return an;
5991  if (set[an].ecart == o)
5992  {
5993  int oo=set[an].GetpFDeg();
5994  if((oo > op)
5995  || ((oo==op) && (set[an].length > p.length)))
5996  return an;
5997  }
5998  return en;
5999  }
6000  i=(an+en) / 2;
6001  if (set[i].ecart > o)
6002  en=i;
6003  else if (set[i].ecart == o)
6004  {
6005  int oo=set[i].GetpFDeg();
6006  if ((oo > op)
6007  || ((oo == op) && (set[i].length > p.length)))
6008  en=i;
6009  else
6010  an=i;
6011  }
6012  else
6013  an=i;
6014  }
6015 }
6016 
6017 /*2
6018 *looks up the position of polynomial p in set
6019 *set[length] is the smallest element in set with respect
6020 *to the ordering-procedure pComp
6021 */
6022 int posInLSpecial (const LSet set, const int length,
6023  LObject *p,const kStrategy)
6024 {
6025  if (length<0) return 0;
6026 
6027  int d=p->GetpFDeg();
6028  int op=set[length].GetpFDeg();
6029 
6030  if ((op > d)
6031  || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
6032  || (pLmCmp(set[length].p,p->p)== currRing->OrdSgn))
6033  return length+1;
6034 
6035  int i;
6036  int an = 0;
6037  int en= length;
6038  loop
6039  {
6040  if (an >= en-1)
6041  {
6042  op=set[an].GetpFDeg();
6043  if ((op > d)
6044  || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
6045  || (pLmCmp(set[an].p,p->p)== currRing->OrdSgn))
6046  return en;
6047  return an;
6048  }
6049  i=(an+en) / 2;
6050  op=set[i].GetpFDeg();
6051  if ((op>d)
6052  || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
6053  || (pLmCmp(set[i].p,p->p) == currRing->OrdSgn))
6054  an=i;
6055  else
6056  en=i;
6057  }
6058 }
6059 
6060 /*2
6061 *looks up the position of polynomial p in set
6062 *set[length] is the smallest element in set with respect
6063 *to the ordering-procedure pComp
6064 */
6065 int posInL0 (const LSet set, const int length,
6066  LObject* p,const kStrategy)
6067 {
6068  if (length<0) return 0;
6069 
6070  if (pLmCmp(set[length].p,p->p)== currRing->OrdSgn)
6071  return length+1;
6072 
6073  int i;
6074  int an = 0;
6075  int en= length;
6076  loop
6077  {
6078  if (an >= en-1)
6079  {
6080  if (pLmCmp(set[an].p,p->p) == currRing->OrdSgn) return en;
6081  return an;
6082  }
6083  i=(an+en) / 2;
6084  if (pLmCmp(set[i].p,p->p) == currRing->OrdSgn) an=i;
6085  else en=i;
6086  /*aend. fuer lazy == in !=- machen */
6087  }
6088 }
6089 
6090 #ifdef HAVE_RINGS
6091 int posInL0Ring (const LSet set, const int length,
6092  LObject* p,const kStrategy)
6093 {
6094  if (length<0) return 0;
6095 
6096  if (pLtCmpOrdSgnEqP(set[length].p,p->p))
6097  return length+1;
6098 
6099  int i;
6100  int an = 0;
6101  int en= length;
6102  loop
6103  {
6104  if (an >= en-1)
6105  {
6106  if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
6107  return an;
6108  }
6109  i=(an+en) / 2;
6110  if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
6111  else en=i;
6112  /*aend. fuer lazy == in !=- machen */
6113  }
6114 }
6115 #endif
6116 
6117 /*2
6118 * looks up the position of polynomial p in set
6119 * e is the ecart of p
6120 * set[length] is the smallest element in set with respect
6121 * to the signature order
6122 */
6123 int posInLSig (const LSet set, const int length,
6124  LObject* p,const kStrategy /*strat*/)
6125 {
6126  if (length<0) return 0;
6127  if (pLtCmp(set[length].sig,p->sig)== currRing->OrdSgn)
6128  return length+1;
6129 
6130  int i;
6131  int an = 0;
6132  int en= length;
6133  loop
6134  {
6135  if (an >= en-1)
6136  {
6137  if (pLtCmp(set[an].sig,p->sig) == currRing->OrdSgn) return en;
6138  return an;
6139  }
6140  i=(an+en) / 2;
6141  if (pLtCmp(set[i].sig,p->sig) == currRing->OrdSgn) an=i;
6142  else en=i;
6143  /*aend. fuer lazy == in !=- machen */
6144  }
6145 }
6146 //sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
6147 int posInLSigRing (const LSet set, const int length,
6148  LObject* p,const kStrategy /*strat*/)
6149 {
6150  assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
6151  if (length<0) return 0;
6152  if (pLtCmp(set[length].sig,p->sig)== 1)
6153  return length+1;
6154 
6155  int an,en,i;
6156  an = 0;
6157  en = length+1;
6158  int cmp;
6159  loop
6160  {
6161  if (an >= en-1)
6162  {
6163  if(an == en)
6164  return en;
6165  cmp = pLtCmp(set[an].sig,p->sig);
6166  if (cmp == 1)
6167  return en;
6168  if (cmp == -1)
6169  return an;
6170  if (cmp == 0)
6171  {
6172  if (set[an].FDeg > p->FDeg)
6173  return en;
6174  if (set[an].FDeg < p->FDeg)
6175  return an;
6176  if (set[an].FDeg == p->FDeg)
6177  {
6178  cmp = pLtCmp(set[an].p,p->p);
6179  if(cmp == 1)
6180  return en;
6181  else
6182  return an;
6183  }
6184  }
6185  }
6186  i=(an+en) / 2;
6187  cmp = pLtCmp(set[i].sig,p->sig);
6188  if (cmp == 1)
6189  an = i;
6190  if (cmp == -1)
6191  en = i;
6192  if (cmp == 0)
6193  {
6194  if (set[i].FDeg > p->FDeg)
6195  an = i;
6196  if (set[i].FDeg < p->FDeg)
6197  en = i;
6198  if (set[i].FDeg == p->FDeg)
6199  {
6200  cmp = pLtCmp(set[i].p,p->p);
6201  if(cmp == 1)
6202  an = i;
6203  else
6204  en = i;
6205  }
6206  }
6207  }
6208 }
6209 
6210 int posInLRing (const LSet set, const int length,
6211  LObject* p,const kStrategy /*strat*/)
6212 {
6213  if (length < 0) return 0;
6214  if (set[length].FDeg > p->FDeg)
6215  return length+1;
6216  if (set[length].FDeg == p->FDeg)
6217  if(set[length].GetpLength() > p->GetpLength())
6218  return length+1;
6219  int i;
6220  int an = 0;
6221  int en= length+1;
6222  loop
6223  {
6224  if (an >= en-1)
6225  {
6226  if(an == en)
6227  return en;
6228  if (set[an].FDeg > p->FDeg)
6229  return en;
6230  if(set[an].FDeg == p->FDeg)
6231  {
6232  if(set[an].GetpLength() > p->GetpLength())
6233  return en;
6234  else
6235  {
6236  if(set[an].GetpLength() == p->GetpLength())
6237  {
6238  if(nGreater(set[an].p->coef, p->p->coef))
6239  return en;
6240  else
6241  return an;
6242  }
6243  else
6244  {
6245  return an;
6246  }
6247  }
6248  }
6249  else
6250  return an;
6251  }
6252  i=(an+en) / 2;
6253  if (set[i].FDeg > p->FDeg)
6254  an=i;
6255  else
6256  {
6257  if(set[i].FDeg == p->FDeg)
6258  {
6259  if(set[i].GetpLength() > p->GetpLength())
6260  an=i;
6261  else
6262  {
6263  if(set[i].GetpLength() == p->GetpLength())
6264  {
6265  if(nGreater(set[i].p->coef, p->p->coef))
6266  an = i;
6267  else
6268  en = i;
6269  }
6270  else
6271  {
6272  en=i;
6273  }
6274  }
6275  }
6276  else
6277  en=i;
6278  }
6279  }
6280 }
6281 
6282 // for sba, sorting syzygies
6283 int posInSyz (const kStrategy strat, poly sig)
6284 {
6285  if (strat->syzl==0) return 0;
6286  if (pLtCmp(strat->syz[strat->syzl-1],sig) != currRing->OrdSgn)
6287  return strat->syzl;
6288  int i;
6289  int an = 0;
6290  int en= strat->syzl-1;
6291  loop
6292  {
6293  if (an >= en-1)
6294  {
6295  if (pLtCmp(strat->syz[an],sig) != currRing->OrdSgn) return en;
6296  return an;
6297  }
6298  i=(an+en) / 2;
6299  if (pLtCmp(strat->syz[i],sig) != currRing->OrdSgn) an=i;
6300  else en=i;
6301  /*aend. fuer lazy == in !=- machen */
6302  }
6303 }
6304 
6305 /*2
6306 *
6307 * is only used in F5C, must ensure that the interreduction process does add new
6308 * critical pairs to strat->L only behind all other critical pairs which are
6309 * still in strat->L!
6310 */
6311 int posInLF5C (const LSet /*set*/, const int /*length*/,
6312  LObject* /*p*/,const kStrategy strat)
6313 {
6314  return strat->Ll+1;
6315 }
6316 
6317 /*2
6318 * looks up the position of polynomial p in set
6319 * e is the ecart of p
6320 * set[length] is the smallest element in set with respect
6321 * to the ordering-procedure totaldegree,pComp
6322 */
6323 int posInL11 (const LSet set, const int length,
6324  LObject* p,const kStrategy)
6325 {
6326  if (length<0) return 0;
6327 
6328  int o = p->GetpFDeg();
6329  int op = set[length].GetpFDeg();
6330 
6331  if ((op > o)
6332  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6333  return length+1;
6334  int i;
6335  int an = 0;
6336  int en= length;
6337  loop
6338  {
6339  if (an >= en-1)
6340  {
6341  op = set[an].GetpFDeg();
6342  if ((op > o)
6343  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6344  return en;
6345  return an;
6346  }
6347  i=(an+en) / 2;
6348  op = set[i].GetpFDeg();
6349  if ((op > o)
6350  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6351  an=i;
6352  else
6353  en=i;
6354  }
6355 }
6356 
6357 #ifdef HAVE_RINGS
6358 /*2
6359 * looks up the position of polynomial p in set
6360 * set[length] is the smallest element in set with respect
6361 * to the ordering-procedure pLmCmp,totaldegree,coefficient
6362 * For the same totaldegree, original pairs (from F) will
6363 * be put at the end and smalles coefficents
6364 */
6365 int posInL11Ring (const LSet set, const int length,
6366  LObject* p,const kStrategy)
6367 {
6368  if (length<0) return 0;
6369 
6370  int o = p->GetpFDeg();
6371  int op = set[length].GetpFDeg();
6372 
6373  if ((op > o)
6374  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6375  return length+1;
6376  int i;
6377  int an = 0;
6378  int en= length;
6379  loop
6380  {
6381  if (an >= en-1)
6382  {
6383  op = set[an].GetpFDeg();
6384  if ((op > o)
6385  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6386  return en;
6387  return an;
6388  }
6389  i=(an+en) / 2;
6390  op = set[i].GetpFDeg();
6391  if ((op > o)
6392  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6393  an=i;
6394  else
6395  en=i;
6396  }
6397 }
6398 
6399 int posInLF5CRing (const LSet set, int start,const int length,
6400  LObject* p,const kStrategy)
6401 {
6402  if (length<0) return 0;
6403  if(start == (length +1)) return (length+1);
6404  int o = p->GetpFDeg();
6405  int op = set[length].GetpFDeg();
6406 
6407  if ((op > o)
6408  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6409  return length+1;
6410  int i;
6411  int an = start;
6412  int en= length;
6413  loop
6414  {
6415  if (an >= en-1)
6416  {
6417  op = set[an].GetpFDeg();
6418  if ((op > o)
6419  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6420  return en;
6421  return an;
6422  }
6423  i=(an+en) / 2;
6424  op = set[i].GetpFDeg();
6425  if ((op > o)
6426  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6427  an=i;
6428  else
6429  en=i;
6430  }
6431 }
6432 #endif
6433 
6434 #ifdef HAVE_RINGS
6435 int posInL11Ringls (const LSet set, const int length,
6436  LObject* p,const kStrategy)
6437 {
6438  if (length < 0) return 0;
6439  int an,en,i;
6440  an = 0;
6441  en = length+1;
6442  loop
6443  {
6444  if (an >= en-1)
6445  {
6446  if(an == en)
6447  return en;
6448  if (set[an].FDeg > p->FDeg)
6449  return en;
6450  if (set[an].FDeg < p->FDeg)
6451  return an;
6452  if (set[an].FDeg == p->FDeg)
6453  {
6454  number lcset,lcp;
6455  lcset = pGetCoeff(set[an].p);
6456  lcp = pGetCoeff(p->p);
6457  if(!nGreaterZero(lcset))
6458  {
6459  set[an].p=p_Neg(set[an].p,currRing);
6460  if (set[an].t_p!=NULL)
6461  pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
6462  lcset=pGetCoeff(set[an].p);
6463  }
6464  if(!nGreaterZero(lcp))
6465  {
6466  p->p=p_Neg(p->p,currRing);
6467  if (p->t_p!=NULL)
6468  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6469  lcp=pGetCoeff(p->p);
6470  }
6471  if(nGreater(lcset, lcp))
6472  {
6473  return en;
6474  }
6475  else
6476  {
6477  return an;
6478  }
6479  }
6480  }
6481  i=(an+en) / 2;
6482  if (set[i].FDeg > p->FDeg)
6483  an=i;
6484  if (set[i].FDeg < p->FDeg)
6485  en=i;
6486  if (set[i].FDeg == p->FDeg)
6487  {
6488  number lcset,lcp;
6489  lcset = pGetCoeff(set[i].p);
6490  lcp = pGetCoeff(p->p);
6491  if(!nGreaterZero(lcset))
6492  {
6493  set[i].p=p_Neg(set[i].p,currRing);
6494  if (set[i].t_p!=NULL)
6495  pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6496  lcset=pGetCoeff(set[i].p);
6497  }
6498  if(!nGreaterZero(lcp))
6499  {
6500  p->p=p_Neg(p->p,currRing);
6501  if (p->t_p!=NULL)
6502  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6503  lcp=pGetCoeff(p->p);
6504  }
6505  if(nGreater(lcset, lcp))
6506  {
6507  an = i;
6508  }
6509  else
6510  {
6511  en = i;
6512  }
6513  }
6514  }
6515 }
6516 #endif
6517 
6518 /*2 Position for rings L: Here I am
6519 * looks up the position of polynomial p in set
6520 * e is the ecart of p
6521 * set[length] is the smallest element in set with respect
6522 * to the ordering-procedure totaldegree,pComp
6523 */
6524 inline int getIndexRng(long coeff)
6525 {
6526  if (coeff == 0) return -1;
6527  long tmp = coeff;
6528  int ind = 0;
6529  while (tmp % 2 == 0)
6530  {
6531  tmp = tmp / 2;
6532  ind++;
6533  }
6534  return ind;
6535 }
6536 
6537 int posInLrg0 (const LSet set, const int length,
6538  LObject* p,const kStrategy)
6539 /* if (nGreater(pGetCoeff(p), pGetCoeff(set[an]))) return en;
6540  if (pLmCmp(set[i],p) == cmp_int) en = i;
6541  else if (pLmCmp(set[i],p) == -cmp_int) an = i;
6542  else
6543  {
6544  if (nGreater(pGetCoeff(p), pGetCoeff(set[i]))) an = i;
6545  else en = i;
6546  }*/
6547 {
6548  if (length < 0) return 0;
6549 
6550  int o = p->GetpFDeg();
6551  int op = set[length].GetpFDeg();
6552 
6553  if ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6554  return length + 1;
6555  int i;
6556  int an = 0;
6557  int en = length;
6558  loop
6559  {
6560  if (an >= en - 1)
6561  {
6562  op = set[an].GetpFDeg();
6563  if ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6564  return en;
6565  return an;
6566  }
6567  i = (an+en) / 2;
6568  op = set[i].GetpFDeg();
6569  if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6570  an = i;
6571  else
6572  en = i;
6573  }
6574 }
6575 
6576 /*{
6577  if (length < 0) return 0;
6578 
6579  int o = p->GetpFDeg();
6580  int op = set[length].GetpFDeg();
6581 
6582  int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6583  int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6584  int inda;
6585  int indi;
6586 
6587  if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6588  return length + 1;
6589  int i;
6590  int an = 0;
6591  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6592  int en = length;
6593  loop
6594  {
6595  if (an >= en-1)
6596  {
6597  op = set[an].GetpFDeg();
6598  if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6599  return en;
6600  return an;
6601  }
6602  i = (an + en) / 2;
6603  indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6604  op = set[i].GetpFDeg();
6605  if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6606  // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6607  {
6608  an = i;
6609  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6610  }
6611  else
6612  en = i;
6613  }
6614 } */
6615 
6616 /*2
6617 * looks up the position of polynomial p in set
6618 * set[length] is the smallest element in set with respect
6619 * to the ordering-procedure totaldegree,pLength0
6620 */
6621 int posInL110 (const LSet set, const int length,
6622  LObject* p,const kStrategy)
6623 {
6624  if (length<0) return 0;
6625 
6626  int o = p->GetpFDeg();
6627  int op = set[length].GetpFDeg();
6628 
6629  if ((op > o)
6630  || ((op == o) && (set[length].length >p->length))
6631  || ((op == o) && (set[length].length <= p->length)
6632  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6633  return length+1;
6634  int i;
6635  int an = 0;
6636  int en= length;
6637  loop
6638  {
6639  if (an >= en-1)
6640  {
6641  op = set[an].GetpFDeg();
6642  if ((op > o)
6643  || ((op == o) && (set[an].length >p->length))
6644  || ((op == o) && (set[an].length <=p->length)
6645  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6646  return en;
6647  return an;
6648  }
6649  i=(an+en) / 2;
6650  op = set[i].GetpFDeg();
6651  if ((op > o)
6652  || ((op == o) && (set[i].length > p->length))
6653  || ((op == o) && (set[i].length <= p->length)
6654  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6655  an=i;
6656  else
6657  en=i;
6658  }
6659 }
6660 
6661 #ifdef HAVE_RINGS
6662 int posInL110Ring (const LSet set, const int length,
6663  LObject* p,const kStrategy)
6664 {
6665  if (length<0) return 0;
6666 
6667  int o = p->GetpFDeg();
6668  int op = set[length].GetpFDeg();
6669 
6670  if ((op > o)
6671  || ((op == o) && (set[length].length >p->length))
6672  || ((op == o) && (set[length].length <= p->length)
6673  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6674  return length+1;
6675  int i;
6676  int an = 0;
6677  int en= length;
6678  loop
6679  {
6680  if (an >= en-1)
6681  {
6682  op = set[an].GetpFDeg();
6683  if ((op > o)
6684  || ((op == o) && (set[an].length >p->length))
6685  || ((op == o) && (set[an].length <=p->length)
6686  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6687  return en;
6688  return an;
6689  }
6690  i=(an+en) / 2;
6691  op = set[i].GetpFDeg();
6692  if ((op > o)
6693  || ((op == o) && (set[i].length > p->length))
6694  || ((op == o) && (set[i].length <= p->length)
6695  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6696  an=i;
6697  else
6698  en=i;
6699  }
6700 }
6701 #endif
6702 
6703 /*2
6704 * looks up the position of polynomial p in set
6705 * e is the ecart of p
6706 * set[length] is the smallest element in set with respect
6707 * to the ordering-procedure totaldegree
6708 */
6709 int posInL13 (const LSet set, const int length,
6710  LObject* p,const kStrategy)
6711 {
6712  if (length<0) return 0;
6713 
6714  int o = p->GetpFDeg();
6715 
6716  if (set[length].GetpFDeg() > o)
6717  return length+1;
6718 
6719  int i;
6720  int an = 0;
6721  int en= length;
6722  loop
6723  {
6724  if (an >= en-1)
6725  {
6726  if (set[an].GetpFDeg() >= o)
6727  return en;
6728  return an;
6729  }
6730  i=(an+en) / 2;
6731  if (set[i].GetpFDeg() >= o)
6732  an=i;
6733  else
6734  en=i;
6735  }
6736 }
6737 
6738 /*2
6739 * looks up the position of polynomial p in set
6740 * e is the ecart of p
6741 * set[length] is the smallest element in set with respect
6742 * to the ordering-procedure maximaldegree,pComp
6743 */
6744 int posInL15 (const LSet set, const int length,
6745  LObject* p,const kStrategy)
6746 {
6747  if (length<0) return 0;
6748 
6749  int o = p->GetpFDeg() + p->ecart;
6750  int op = set[length].GetpFDeg() + set[length].ecart;
6751 
6752  if ((op > o)
6753  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6754  return length+1;
6755  int i;
6756  int an = 0;
6757  int en= length;
6758  loop
6759  {
6760  if (an >= en-1)
6761  {
6762  op = set[an].GetpFDeg() + set[an].ecart;
6763  if ((op > o)
6764  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6765  return en;
6766  return an;
6767  }
6768  i=(an+en) / 2;
6769  op = set[i].GetpFDeg() + set[i].ecart;
6770  if ((op > o)
6771  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6772  an=i;
6773  else
6774  en=i;
6775  }
6776 }
6777 
6778 #ifdef HAVE_RINGS
6779 int posInL15Ring (const LSet set, const int length,
6780  LObject* p,const kStrategy)
6781 {
6782  if (length<0) return 0;
6783 
6784  int o = p->GetpFDeg() + p->ecart;
6785  int op = set[length].GetpFDeg() + set[length].ecart;
6786 
6787  if ((op > o)
6788  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6789  return length+1;
6790  int i;
6791  int an = 0;
6792  int en= length;
6793  loop
6794  {
6795  if (an >= en-1)
6796  {
6797  op = set[an].GetpFDeg() + set[an].ecart;
6798  if ((op > o)
6799  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6800  return en;
6801  return an;
6802  }
6803  i=(an+en) / 2;
6804  op = set[i].GetpFDeg() + set[i].ecart;
6805  if ((op > o)
6806  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6807  an=i;
6808  else
6809  en=i;
6810  }
6811 }
6812 #endif
6813 
6814 /*2
6815 * looks up the position of polynomial p in set
6816 * e is the ecart of p
6817 * set[length] is the smallest element in set with respect
6818 * to the ordering-procedure totaldegree
6819 */
6820 int posInL17 (const LSet set, const int length,
6821  LObject* p,const kStrategy)
6822 {
6823  if (length<0) return 0;
6824 
6825  int o = p->GetpFDeg() + p->ecart;
6826 
6827  if ((set[length].GetpFDeg() + set[length].ecart > o)
6828  || ((set[length].GetpFDeg() + set[length].ecart == o)
6829  && (set[length].ecart > p->ecart))
6830  || ((set[length].GetpFDeg() + set[length].ecart == o)
6831  && (set[length].ecart == p->ecart)
6832  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6833  return length+1;
6834  int i;
6835  int an = 0;
6836  int en= length;
6837  loop
6838  {
6839  if (an >= en-1)
6840  {
6841  if ((set[an].GetpFDeg() + set[an].ecart > o)
6842  || ((set[an].GetpFDeg() + set[an].ecart == o)
6843  && (set[an].ecart > p->ecart))
6844  || ((set[an].GetpFDeg() + set[an].ecart == o)
6845  && (set[an].ecart == p->ecart)
6846  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6847  return en;
6848  return an;
6849  }
6850  i=(an+en) / 2;
6851  if ((set[i].GetpFDeg() + set[i].ecart > o)
6852  || ((set[i].GetpFDeg() + set[i].ecart == o)
6853  && (set[i].ecart > p->ecart))
6854  || ((set[i].GetpFDeg() +set[i].ecart == o)
6855  && (set[i].ecart == p->ecart)
6856  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6857  an=i;
6858  else
6859  en=i;
6860  }
6861 }
6862 
6863 #ifdef HAVE_RINGS
6864 int posInL17Ring (const LSet set, const int length,
6865  LObject* p,const kStrategy)
6866 {
6867  if (length<0) return 0;
6868 
6869  int o = p->GetpFDeg() + p->ecart;
6870 
6871  if ((set[length].GetpFDeg() + set[length].ecart > o)
6872  || ((set[length].GetpFDeg() + set[length].ecart == o)
6873  && (set[length].ecart > p->ecart))
6874  || ((set[length].GetpFDeg() + set[length].ecart == o)
6875  && (set[length].ecart == p->ecart)
6876  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6877  return length+1;
6878  int i;
6879  int an = 0;
6880  int en= length;
6881  loop
6882  {
6883  if (an >= en-1)
6884  {
6885  if ((set[an].GetpFDeg() + set[an].ecart > o)
6886  || ((set[an].GetpFDeg() + set[an].ecart == o)
6887  && (set[an].ecart > p->ecart))
6888  || ((set[an].GetpFDeg() + set[an].ecart == o)
6889  && (set[an].ecart == p->ecart)
6890  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6891  return en;
6892  return an;
6893  }
6894  i=(an+en) / 2;
6895  if ((set[i].GetpFDeg() + set[i].ecart > o)
6896  || ((set[i].GetpFDeg() + set[i].ecart == o)
6897  && (set[i].ecart > p->ecart))
6898  || ((set[i].GetpFDeg() +set[i].ecart == o)
6899  && (set[i].ecart == p->ecart)
6900  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6901  an=i;
6902  else
6903  en=i;
6904  }
6905 }
6906 #endif
6907 
6908 /*2
6909 * looks up the position of polynomial p in set
6910 * e is the ecart of p
6911 * set[length] is the smallest element in set with respect
6912 * to the ordering-procedure pComp
6913 */
6914 int posInL17_c (const LSet set, const int length,
6915  LObject* p,const kStrategy)
6916 {
6917  if (length<0) return 0;
6918 
6919  int cc = (-1+2*currRing->order[0]==ringorder_c);
6920  /* cc==1 for (c,..), cc==-1 for (C,..) */
6921  unsigned long c = pGetComp(p->p)*cc;
6922  int o = p->GetpFDeg() + p->ecart;
6923 
6924  if (pGetComp(set[length].p)*cc > c)
6925  return length+1;
6926  if (pGetComp(set[length].p)*cc == c)
6927  {
6928  if ((set[length].GetpFDeg() + set[length].ecart > o)
6929  || ((set[length].GetpFDeg() + set[length].ecart == o)
6930  && (set[length].ecart > p->ecart))
6931  || ((set[length].GetpFDeg() + set[length].ecart == o)
6932  && (set[length].ecart == p->ecart)
6933  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6934  return length+1;
6935  }
6936  int i;
6937  int an = 0;
6938  int en= length;
6939  loop
6940  {
6941  if (an >= en-1)
6942  {
6943  if (pGetComp(set[an].p)*cc > c)
6944  return en;
6945  if (pGetComp(set[an].p)*cc == c)
6946  {
6947  if ((set[an].GetpFDeg() + set[an].ecart > o)
6948  || ((set[an].GetpFDeg() + set[an].ecart == o)
6949  && (set[an].ecart > p->ecart))
6950  || ((set[an].GetpFDeg() + set[an].ecart == o)
6951  && (set[an].ecart == p->ecart)
6952  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6953  return en;
6954  }
6955  return an;
6956  }
6957  i=(an+en) / 2;
6958  if (pGetComp(set[i].p)*cc > c)
6959  an=i;
6960  else if (pGetComp(set[i].p)*cc == c)
6961  {
6962  if ((set[i].GetpFDeg() + set[i].ecart > o)
6963  || ((set[i].GetpFDeg() + set[i].ecart == o)
6964  && (set[i].ecart > p->ecart))
6965  || ((set[i].GetpFDeg() +set[i].ecart == o)
6966  && (set[i].ecart == p->ecart)
6967  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6968  an=i;
6969  else
6970  en=i;
6971  }
6972  else
6973  en=i;
6974  }
6975 }
6976 
6977 #ifdef HAVE_RINGS
6978 int posInL17_cRing (const LSet set, const int length,
6979  LObject* p,const kStrategy)
6980 {
6981  if (length<0) return 0;
6982 
6983  int cc = (-1+2*currRing->order[0]==ringorder_c);
6984  /* cc==1 for (c,..), cc==-1 for (C,..) */
6985  unsigned long c = pGetComp(p->p)*cc;
6986  int o = p->GetpFDeg() + p->ecart;
6987 
6988  if (pGetComp(set[length].p)*cc > c)
6989  return length+1;
6990  if (pGetComp(set[length].p)*cc == c)
6991  {
6992  if ((set[length].GetpFDeg() + set[length].ecart > o)
6993  || ((set[length].GetpFDeg() + set[length].ecart == o)
6994  && (set[length].ecart > p->ecart))
6995  || ((set[length].GetpFDeg() + set[length].ecart == o)
6996  && (set[length].ecart == p->ecart)
6997  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6998  return length+1;
6999  }
7000  int i;
7001  int an = 0;
7002  int en= length;
7003  loop
7004  {
7005  if (an >= en-1)
7006  {
7007  if (pGetComp(set[an].p)*cc > c)
7008  return en;
7009  if (pGetComp(set[an].p)*cc == c)
7010  {
7011  if ((set[an].GetpFDeg() + set[an].ecart > o)
7012  || ((set[an].GetpFDeg() + set[an].ecart == o)
7013  && (set[an].ecart > p->ecart))
7014  || ((set[an].GetpFDeg() + set[an].ecart == o)
7015  && (set[an].ecart == p->ecart)
7016  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
7017  return en;
7018  }
7019  return an;
7020  }
7021  i=(an+en) / 2;
7022  if (pGetComp(set[i].p)*cc > c)
7023  an=i;
7024  else if (pGetComp(set[i].p)*cc == c)
7025  {
7026  if ((set[i].GetpFDeg() + set[i].ecart > o)
7027  || ((set[i].GetpFDeg() + set[i].ecart == o)
7028  && (set[i].ecart > p->ecart))
7029  || ((set[i].GetpFDeg() +set[i].ecart == o)
7030  && (set[i].ecart == p->ecart)
7031  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
7032  an=i;
7033  else
7034  en=i;
7035  }
7036  else
7037  en=i;
7038  }
7039 }
7040 #endif
7041 
7042 /*
7043  * SYZYGY CRITERION for signature-based standard basis algorithms
7044  */
7045 BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
7046 {
7047 //#if 1
7048 #ifdef DEBUGF5
7049  PrintS("syzygy criterion checks: ");
7050  pWrite(sig);
7051 #endif
7052  for (int k=0; k<strat->syzl; k++)
7053  {
7054  //printf("-%d",k);
7055 //#if 1
7056 #ifdef DEBUGF5
7057  Print("checking with: %d / %d -- \n",k,strat->syzl);
7058  pWrite(pHead(strat->syz[k]));
7059 #endif
7060  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7061  && (!rField_is_Ring(currRing) ||
7062  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7063  {
7064 //#if 1
7065 #ifdef DEBUGF5
7066  PrintS("DELETE!\n");
7067 #endif
7068  strat->nrsyzcrit++;
7069  //printf("- T -\n\n");
7070  return TRUE;
7071  }
7072  }
7073  //printf("- F -\n\n");
7074  return FALSE;
7075 }
7076 
7077 /*
7078  * SYZYGY CRITERION for signature-based standard basis algorithms
7079  */
7080 BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
7081 {
7082 //#if 1
7083  if(sig == NULL)
7084  return FALSE;
7085 #ifdef DEBUGF5
7086  PrintS("--- syzygy criterion checks: ");
7087  pWrite(sig);
7088 #endif
7089  int comp = __p_GetComp(sig, currRing);
7090  int min, max;
7091  if (comp<=1)
7092  return FALSE;
7093  else
7094  {
7095  min = strat->syzIdx[comp-2];
7096  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
7097  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
7098  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
7099  if (comp == strat->currIdx)
7100  {
7101  max = strat->syzl;
7102  }
7103  else
7104  {
7105  max = strat->syzIdx[comp-1];
7106  }
7107  for (int k=min; k<max; k++)
7108  {
7109 #ifdef F5DEBUG
7110  Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
7111  Print("checking with: %d -- ",k);
7112  pWrite(pHead(strat->syz[k]));
7113 #endif
7114  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7115  && (!rField_is_Ring(currRing) ||
7116  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7117  {
7118  strat->nrsyzcrit++;
7119  return TRUE;
7120  }
7121  }
7122  return FALSE;
7123  }
7124 }
7125 
7126 /*
7127  * REWRITTEN CRITERION for signature-based standard basis algorithms
7128  */
7129 BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
7130 {
7131  //printf("Faugere Rewritten Criterion\n");
7133  return FALSE;
7134 //#if 1
7135 #ifdef DEBUGF5
7136  PrintS("rewritten criterion checks: ");
7137  pWrite(sig);
7138 #endif
7139  for(int k = strat->sl; k>=start; k--)
7140  {
7141 //#if 1
7142 #ifdef DEBUGF5
7143  PrintS("checking with: ");
7144  pWrite(strat->sig[k]);
7145  pWrite(pHead(strat->S[k]));
7146 #endif
7147  if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
7148  {
7149 //#if 1
7150 #ifdef DEBUGF5
7151  PrintS("DELETE!\n");
7152 #endif
7153  strat->nrrewcrit++;
7154  return TRUE;
7155  }
7156  //k--;
7157  }
7158 #ifdef DEBUGF5
7159  PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
7160  for(int kk = 0; kk<strat->sl+1; kk++)
7161  {
7162  pWrite(pHead(strat->S[kk]));
7163  }
7164  PrintS("------------------------------\n");
7165 #endif
7166  return FALSE;
7167 }
7168 
7169 /*
7170  * REWRITTEN CRITERION for signature-based standard basis algorithms
7171  ***************************************************************************
7172  * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
7173  ***************************************************************************
7174  */
7175 
7176 // real implementation of arri's rewritten criterion, only called once in
7177 // kstd2.cc, right before starting reduction
7178 // IDEA: Arri says that it is enough to consider 1 polynomial for each unique
7179 // signature appearing during the computations. Thus we first of all go
7180 // through strat->L and delete all other pairs of the same signature,
7181 // keeping only the one with least possible leading monomial. After this
7182 // we check if we really need to compute this critical pair at all: There
7183 // can be elements already in strat->S whose signatures divide the
7184 // signature of the critical pair in question and whose multiplied
7185 // leading monomials are smaller than the leading monomial of the
7186 // critical pair. In this situation we can discard the critical pair
7187 // completely.
7188 BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
7189 {
7191  return FALSE;
7192  poly p1 = pOne();
7193  poly p2 = pOne();
7194  for (int ii=strat->sl; ii>start; ii--)
7195  {
7196  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
7197  {
7198  p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
7199  p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
7200  if (!(pLmCmp(p1,p2) == 1))
7201  {
7202  pDelete(&p1);
7203  pDelete(&p2);
7204  return TRUE;
7205  }
7206  }
7207  }
7208  pDelete(&p1);
7209  pDelete(&p2);
7210  return FALSE;
7211 }
7212 
7213 BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
7214 {
7215  //Over Rings, there are still some changes to do: considering coeffs
7217  return FALSE;
7218  int found = -1;
7219  for (int i=strat->Bl; i>-1; i--) {
7220  if (pLmEqual(strat->B[i].sig,sig))
7221  {
7222  found = i;
7223  break;
7224  }
7225  }
7226  if (found != -1)
7227  {
7228  if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
7229  {
7230  deleteInL(strat->B,&strat->Bl,found,strat);
7231  }
7232  else
7233  {
7234  return TRUE;
7235  }
7236  }
7237  poly p1 = pOne();
7238  poly p2 = pOne();
7239  for (int ii=strat->sl; ii>-1; ii--)
7240  {
7241  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
7242  {
7243  p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
7244  p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
7245  if (!(pLmCmp(p1,p2) == 1))
7246  {
7247  pDelete(&p1);
7248  pDelete(&p2);
7249  return TRUE;
7250  }
7251  }
7252  }
7253  pDelete(&p1);
7254  pDelete(&p2);
7255  return FALSE;
7256 }
7257 
7258 /***************************************************************
7259  *
7260  * Tail reductions
7261  *
7262  ***************************************************************/
7263 TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
7264 {
7265  int j = 0;
7266  const unsigned long not_sev = ~L->sev;
7267  const unsigned long* sev = strat->sevS;
7268  poly p;
7269  ring r;
7270  L->GetLm(p, r);
7271 
7272  assume(~not_sev == p_GetShortExpVector(p, r));
7273 
7274  if (r == currRing)
7275  {
7276  if(!rField_is_Ring(r))
7277  {
7278  loop
7279  {
7280  if (j > end_pos) return NULL;
7281  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7282  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7283  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7284  {
7285  break;
7286  }
7287  #else
7288  if (!(sev[j] & not_sev) &&
7289  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7290  p_LmDivisibleBy(strat->S[j], p, r))
7291  {
7292  break;
7293  }
7294  #endif
7295  j++;
7296  }
7297  }
7298  #ifdef HAVE_RINGS
7299  else
7300  {
7301  loop
7302  {
7303  if (j > end_pos) return NULL;
7304  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7305  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7306  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7307  {
7308  break;
7309  }
7310  #else
7311  if (!(sev[j] & not_sev) &&
7312  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7313  p_LmDivisibleBy(strat->S[j], p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7314  {
7315  break;
7316  }
7317  #endif
7318  j++;
7319  }
7320  }
7321  #endif
7322  // if called from NF, T objects do not exist:
7323  if (strat->tl < 0 || strat->S_2_R[j] == -1)
7324  {
7325  T->Set(strat->S[j], r, strat->tailRing);
7326  assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
7327  return T;
7328  }
7329  else
7330  {
7331 ///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
7332 ///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
7333 // assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
7334  return strat->S_2_T(j);
7335  }
7336  }
7337  else
7338  {
7339  TObject* t;
7340  if(!rField_is_Ring(r))
7341  {
7342  loop
7343  {
7344  if (j > end_pos) return NULL;
7345  assume(strat->S_2_R[j] != -1);
7346  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7347  t = strat->S_2_T(j);
7348  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7349  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7350  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7351  {
7352  t->pLength=pLength(t->t_p);
7353  return t;
7354  }
7355  #else
7356  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7357  {
7358  t = strat->S_2_T(j);
7359  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7360  if (p_LmDivisibleBy(t->t_p, p, r))
7361  {
7362  t->pLength=pLength(t->t_p);
7363  return t;
7364  }
7365  }
7366  #endif
7367  j++;
7368  }
7369  }
7370  #ifdef HAVE_RINGS
7371  else
7372  {
7373  loop
7374  {
7375  if (j > end_pos) return NULL;
7376  assume(strat->S_2_R[j] != -1);
7377  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7378  t = strat->S_2_T(j);
7379  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7380  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7381  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7382  {
7383  t->pLength=pLength(t->t_p);
7384  return t;
7385  }
7386  #else
7387  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7388  {
7389  t = strat->S_2_T(j);
7390  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7391  if (p_LmDivisibleBy(t->t_p, p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7392  {
7393  t->pLength=pLength(t->t_p);
7394  return t;
7395  }
7396  }
7397  #endif
7398  j++;
7399  }
7400  }
7401  #endif
7402  }
7403 }
7404 
7405 poly redtail (LObject* L, int end_pos, kStrategy strat)
7406 {
7407  poly h, hn;
7408  strat->redTailChange=FALSE;
7409 
7410  L->GetP();
7411  poly p = L->p;
7412  if (strat->noTailReduction || pNext(p) == NULL)
7413  return p;
7414 
7415  LObject Ln(strat->tailRing);
7416  TObject* With;
7417  // placeholder in case strat->tl < 0
7418  TObject With_s(strat->tailRing);
7419  h = p;
7420  hn = pNext(h);
7421  long op = strat->tailRing->pFDeg(hn, strat->tailRing);
7422  long e;
7423  int l;
7424  BOOLEAN save_HE=strat->kHEdgeFound;
7425  strat->kHEdgeFound |=
7426  ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
7427 
7428  while(hn != NULL)
7429  {
7430  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7431  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7432  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7433  loop
7434  {
7435  Ln.Set(hn, strat->tailRing);
7436  Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
7437  if (strat->kHEdgeFound)
7438  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7439  else
7440  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
7441  if (With == NULL) break;
7442  With->length=0;
7443  With->pLength=0;
7444  strat->redTailChange=TRUE;
7445  if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
7446  {
7447  // reducing the tail would violate the exp bound
7448  if (kStratChangeTailRing(strat, L))
7449  {
7450  strat->kHEdgeFound = save_HE;
7451  return redtail(L, end_pos, strat);
7452  }
7453  else
7454  return NULL;
7455  }
7456  hn = pNext(h);
7457  if (hn == NULL) goto all_done;
7458  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7459  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7460  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7461  }
7462  h = hn;
7463  hn = pNext(h);
7464  }
7465 
7466  all_done:
7467  if (strat->redTailChange)
7468  {
7469  L->pLength = 0;
7470  }
7471  strat->kHEdgeFound = save_HE;
7472  return p;
7473 }
7474 
7475 poly redtail (poly p, int end_pos, kStrategy strat)
7476 {
7477  LObject L(p, currRing);
7478  return redtail(&L, end_pos, strat);
7479 }
7480 
7481 poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
7482 {
7483 #define REDTAIL_CANONICALIZE 100
7484  strat->redTailChange=FALSE;
7485  if (strat->noTailReduction) return L->GetLmCurrRing();
7486  poly h, p;
7487  p = h = L->GetLmTailRing();
7488  if ((h==NULL) || (pNext(h)==NULL))
7489  return L->GetLmCurrRing();
7490 
7491  TObject* With;
7492  // placeholder in case strat->tl < 0
7493  TObject With_s(strat->tailRing);
7494 
7495  LObject Ln(pNext(h), strat->tailRing);
7496  Ln.GetpLength();
7497 
7498  pNext(h) = NULL;
7499  if (L->p != NULL)
7500  {
7501  pNext(L->p) = NULL;
7502  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7503  }
7504  L->pLength = 1;
7505 
7506  Ln.PrepareRed(strat->use_buckets);
7507 
7508  int cnt=REDTAIL_CANONICALIZE;
7509  while(!Ln.IsNull())
7510  {
7511  loop
7512  {
7513  if (TEST_OPT_IDLIFT)
7514  {
7515  if (Ln.p!=NULL)
7516  {
7517  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7518  }
7519  else
7520  {
7521  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7522  }
7523  }
7524  Ln.SetShortExpVector();
7525  if (withT)
7526  {
7527  int j;
7528  j = kFindDivisibleByInT(strat, &Ln);
7529  if (j < 0) break;
7530  With = &(strat->T[j]);
7531  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7532  }
7533  else
7534  {
7535  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7536  if (With == NULL) break;
7537  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7538  }
7539  cnt--;
7540  if (cnt==0)
7541  {
7543  /*poly tmp=*/Ln.CanonicalizeP();
7544  if (normalize)
7545  {
7546  Ln.Normalize();
7547  //pNormalize(tmp);
7548  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7549  }
7550  }
7551  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7552  {
7553  With->pNorm();
7554  }
7555  strat->redTailChange=TRUE;
7556  if (ksReducePolyTail(L, With, &Ln))
7557  {
7558  // reducing the tail would violate the exp bound
7559  // set a flag and hope for a retry (in bba)
7560  strat->completeReduce_retry=TRUE;
7561  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7562  do
7563  {
7564  pNext(h) = Ln.LmExtractAndIter();
7565  pIter(h);
7566  L->pLength++;
7567  } while (!Ln.IsNull());
7568  goto all_done;
7569  }
7570  if (Ln.IsNull()) goto all_done;
7571  if (! withT) With_s.Init(currRing);
7572  }
7573  pNext(h) = Ln.LmExtractAndIter();
7574  pIter(h);
7575  pNormalize(h);
7576  L->pLength++;
7577  }
7578 
7579  all_done:
7580  Ln.Delete();
7581  if (L->p != NULL) pNext(L->p) = pNext(p);
7582 
7583  if (strat->redTailChange)
7584  {
7585  L->length = 0;
7586  L->pLength = 0;
7587  }
7588 
7589  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7590  //L->Normalize(); // HANNES: should have a test
7591  kTest_L(L,strat->tailRing);
7592  return L->GetLmCurrRing();
7593 }
7594 
7595 poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7596 {
7597  strat->redTailChange=FALSE;
7598  if (strat->noTailReduction) return L->GetLmCurrRing();
7599  poly h, p;
7600  p = h = L->GetLmTailRing();
7601  if ((h==NULL) || (pNext(h)==NULL))
7602  return L->GetLmCurrRing();
7603 
7604  TObject* With;
7605  // placeholder in case strat->tl < 0
7606  TObject With_s(strat->tailRing);
7607 
7608  LObject Ln(pNext(h), strat->tailRing);
7609  Ln.pLength = L->GetpLength() - 1;
7610 
7611  pNext(h) = NULL;
7612  if (L->p != NULL) pNext(L->p) = NULL;
7613  L->pLength = 1;
7614 
7615  Ln.PrepareRed(strat->use_buckets);
7616 
7617  int cnt=REDTAIL_CANONICALIZE;
7618  while(!Ln.IsNull())
7619  {
7620  loop
7621  {
7622  if (TEST_OPT_IDLIFT)
7623  {
7624  if (Ln.p!=NULL)
7625  {
7626  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7627  }
7628  else
7629  {
7630  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7631  }
7632  }
7633  Ln.SetShortExpVector();
7634  if (withT)
7635  {
7636  int j;
7637  j = kFindDivisibleByInT(strat, &Ln);
7638  if (j < 0) break;
7639  With = &(strat->T[j]);
7640  }
7641  else
7642  {
7643  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7644  if (With == NULL) break;
7645  }
7646  cnt--;
7647  if (cnt==0)
7648  {
7650  /*poly tmp=*/Ln.CanonicalizeP();
7651  if (normalize)
7652  {
7653  Ln.Normalize();
7654  //pNormalize(tmp);
7655  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7656  }
7657  }
7658  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7659  {
7660  With->pNorm();
7661  }
7662  strat->redTailChange=TRUE;
7663  if (ksReducePolyTail(L, With, &Ln))
7664  {
7665  // reducing the tail would violate the exp bound
7666  // set a flag and hope for a retry (in bba)
7667  strat->completeReduce_retry=TRUE;
7668  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7669  do
7670  {
7671  pNext(h) = Ln.LmExtractAndIter();
7672  pIter(h);
7673  L->pLength++;
7674  } while (!Ln.IsNull());
7675  goto all_done;
7676  }
7677  if(!Ln.IsNull())
7678  {
7679  Ln.GetP();
7680  Ln.p = pJet(Ln.p,bound);
7681  }
7682  if (Ln.IsNull())
7683  {
7684  goto all_done;
7685  }
7686  if (! withT) With_s.Init(currRing);
7687  }
7688  pNext(h) = Ln.LmExtractAndIter();
7689  pIter(h);
7690  pNormalize(h);
7691  L->pLength++;
7692  }
7693 
7694  all_done:
7695  Ln.Delete();
7696  if (L->p != NULL) pNext(L->p) = pNext(p);
7697 
7698  if (strat->redTailChange)
7699  {
7700  L->length = 0;
7701  L->pLength = 0;
7702  }
7703 
7704  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7705  //L->Normalize(); // HANNES: should have a test
7706  kTest_L(L,strat->tailRing);
7707  return L->GetLmCurrRing();
7708 }
7709 
7710 #ifdef HAVE_RINGS
7711 void redtailBbaAlsoLC_Z (LObject* L, int end_pos, kStrategy strat )
7712 // normalize=FALSE, withT=FALSE, coeff=Z
7713 {
7714  strat->redTailChange=FALSE;
7715 
7716  poly h, p;
7717  p = h = L->GetLmTailRing();
7718  if ((h==NULL) || (pNext(h)==NULL))
7719  return;
7720 
7721  TObject* With;
7722  LObject Ln(pNext(h), strat->tailRing);
7723  Ln.GetpLength();
7724 
7725  pNext(h) = NULL;
7726  if (L->p != NULL)
7727  {
7728  pNext(L->p) = NULL;
7729  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7730  }
7731  L->pLength = 1;
7732 
7733  Ln.PrepareRed(strat->use_buckets);
7734 
7735  int cnt=REDTAIL_CANONICALIZE;
7736 
7737  while(!Ln.IsNull())
7738  {
7739  loop
7740  {
7741  if (TEST_OPT_IDLIFT)
7742  {
7743  if (Ln.p!=NULL)
7744  {
7745  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7746  }
7747  else
7748  {
7749  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7750  }
7751  }
7752  Ln.SetShortExpVector();
7753  int j;
7754  j = kFindDivisibleByInT(strat, &Ln);
7755  if (j < 0) {
7756  j = kFindDivisibleByInT_Z(strat, &Ln);
7757  if (j < 0) {
7758  break;
7759  } else {
7760  /* reduction not cancelling a tail term, but reducing its coefficient */
7761  With = &(strat->T[j]);
7762  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7763  cnt--;
7764  if (cnt==0)
7765  {
7767  /*poly tmp=*/Ln.CanonicalizeP();
7768  }
7769  strat->redTailChange=TRUE;
7770  /* reduction cancelling a tail term */
7771  if (ksReducePolyTailLC_Z(L, With, &Ln))
7772  {
7773  // reducing the tail would violate the exp bound
7774  // set a flag and hope for a retry (in bba)
7775  strat->completeReduce_retry=TRUE;
7776  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7777  do
7778  {
7779  pNext(h) = Ln.LmExtractAndIter();
7780  pIter(h);
7781  L->pLength++;
7782  } while (!Ln.IsNull());
7783  goto all_done;
7784  }
7785  /* we have to break since we did not cancel the term, but only decreased
7786  * its coefficient. */
7787  break;
7788  }
7789  } else {
7790  With = &(strat->T[j]);
7791  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7792  cnt--;
7793  if (cnt==0)
7794  {
7796  /*poly tmp=*/Ln.CanonicalizeP();
7797  }
7798  strat->redTailChange=TRUE;
7799  /* reduction cancelling a tail term */
7800  if (ksReducePolyTail_Z(L, With, &Ln))
7801  {
7802  // reducing the tail would violate the exp bound
7803  // set a flag and hope for a retry (in bba)
7804  strat->completeReduce_retry=TRUE;
7805  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7806  do
7807  {
7808  pNext(h) = Ln.LmExtractAndIter();
7809  pIter(h);
7810  L->pLength++;
7811  } while (!Ln.IsNull());
7812  goto all_done;
7813  }
7814  }
7815  if (Ln.IsNull()) goto all_done;
7816  }
7817  pNext(h) = Ln.LmExtractAndIter();
7818  pIter(h);
7819  L->pLength++;
7820  }
7821 
7822  all_done:
7823  Ln.Delete();
7824  if (L->p != NULL) pNext(L->p) = pNext(p);
7825 
7826  if (strat->redTailChange)
7827  {
7828  L->length = 0;
7829  L->pLength = 0;
7830  }
7831 
7832  kTest_L(L, strat->tailRing);
7833  return;
7834 }
7835 
7836 poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7837 // normalize=FALSE, withT=FALSE, coeff=Z
7838 {
7839  strat->redTailChange=FALSE;
7840  if (strat->noTailReduction) return L->GetLmCurrRing();
7841  poly h, p;
7842  p = h = L->GetLmTailRing();
7843  if ((h==NULL) || (pNext(h)==NULL))
7844  return L->GetLmCurrRing();
7845 
7846  TObject* With;
7847  // placeholder in case strat->tl < 0
7848  TObject With_s(strat->tailRing);
7849 
7850  LObject Ln(pNext(h), strat->tailRing);
7851  Ln.pLength = L->GetpLength() - 1;
7852 
7853  pNext(h) = NULL;
7854  if (L->p != NULL) pNext(L->p) = NULL;
7855  L->pLength = 1;
7856 
7857  Ln.PrepareRed(strat->use_buckets);
7858 
7859  int cnt=REDTAIL_CANONICALIZE;
7860  while(!Ln.IsNull())
7861  {
7862  loop
7863  {
7864  Ln.SetShortExpVector();
7865  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7866  if (With == NULL) break;
7867  cnt--;
7868  if (cnt==0)
7869  {
7871  /*poly tmp=*/Ln.CanonicalizeP();
7872  }
7873  // we are in Z, do not call pNorm
7874  strat->redTailChange=TRUE;
7875  // test divisibility of coefs:
7876  poly p_Ln=Ln.GetLmCurrRing();
7877  poly p_With=With->GetLmCurrRing();
7878  number z=n_IntMod(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf);
7879  if (!nIsZero(z))
7880  {
7881  // subtract z*Ln, add z.Ln to L
7882  poly m=pHead(p_Ln);
7883  pSetCoeff(m,z);
7884  poly mm=pHead(m);
7885  pNext(h) = m;
7886  pIter(h);
7887  L->pLength++;
7888  mm=pNeg(mm);
7889  if (Ln.bucket!=NULL)
7890  {
7891  int dummy=1;
7892  kBucket_Add_q(Ln.bucket,mm,&dummy);
7893  }
7894  else
7895  {
7896  if ((Ln.t_p!=NULL)&&(Ln.p==NULL))
7897  Ln.GetP();
7898  if (Ln.p!=NULL)
7899  {
7900  Ln.p=pAdd(Ln.p,mm);
7901  if (Ln.t_p!=NULL)
7902  {
7903  pNext(Ln.t_p)=NULL;
7904  p_LmDelete(Ln.t_p,strat->tailRing);
7905  }
7906  }
7907  }
7908  }
7909  else
7910  nDelete(&z);
7911 
7912  if (ksReducePolyTail(L, With, &Ln))
7913  {
7914  // reducing the tail would violate the exp bound
7915  // set a flag and hope for a retry (in bba)
7916  strat->completeReduce_retry=TRUE;
7917  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7918  do
7919  {
7920  pNext(h) = Ln.LmExtractAndIter();
7921  pIter(h);
7922  L->pLength++;
7923  } while (!Ln.IsNull());
7924  goto all_done;
7925  }
7926  if (Ln.IsNull()) goto all_done;
7927  With_s.Init(currRing);
7928  }
7929  pNext(h) = Ln.LmExtractAndIter();
7930  pIter(h);
7931  pNormalize(h);
7932  L->pLength++;
7933  }
7934 
7935  all_done:
7936  Ln.Delete();
7937  if (L->p != NULL) pNext(L->p) = pNext(p);
7938 
7939  if (strat->redTailChange)
7940  {
7941  L->length = 0;
7942  }
7943 
7944  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7945  //L->Normalize(); // HANNES: should have a test
7946  kTest_L(L,strat->tailRing);
7947  return L->GetLmCurrRing();
7948 }
7949 #endif
7950 
7951 /*2
7952 *checks the change degree and write progress report
7953 */
7954 void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7955 {
7956  if (i != *olddeg)
7957  {
7958  Print("%d",i);
7959  *olddeg = i;
7960  }
7961  if (TEST_OPT_OLDSTD)
7962  {
7963  if (strat->Ll != *reduc)
7964  {
7965  if (strat->Ll != *reduc-1)
7966  Print("(%d)",strat->Ll+1);
7967  else
7968  PrintS("-");
7969  *reduc = strat->Ll;
7970  }
7971  else
7972  PrintS(".");
7973  mflush();
7974  }
7975  else
7976  {
7977  if (red_result == 0)
7978  PrintS("-");
7979  else if (red_result < 0)
7980  PrintS(".");
7981  if ((red_result > 0) || ((strat->Ll % 100)==99))
7982  {
7983  if (strat->Ll != *reduc && strat->Ll > 0)
7984  {
7985  Print("(%d)",strat->Ll+1);
7986  *reduc = strat->Ll;
7987  }
7988  }
7989  }
7990 }
7991 
7992 /*2
7993 *statistics
7994 */
7995 void messageStat (int hilbcount,kStrategy strat)
7996 {
7997  //PrintS("\nUsage/Allocation of temporary storage:\n");
7998  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7999  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
8000  Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
8001  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
8002  #ifdef HAVE_SHIFTBBA
8003  /* in usual case strat->cv is 0, it gets changed only in shift routines */
8004  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
8005  #endif
8006 }
8007 
8008 void messageStatSBA (int hilbcount,kStrategy strat)
8009 {
8010  //PrintS("\nUsage/Allocation of temporary storage:\n");
8011  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
8012  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
8013  Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
8014  //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
8015  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
8016  #ifdef HAVE_SHIFTBBA
8017  /* in usual case strat->cv is 0, it gets changed only in shift routines */
8018  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
8019  #endif
8020 }
8021 
8022 #ifdef KDEBUG
8023 /*2
8024 *debugging output: all internal sets, if changed
8025 *for testing purpuse only/has to be changed for later use
8026 */
8027 void messageSets (kStrategy strat)
8028 {
8029  int i;
8030  if (strat->news)
8031  {
8032  PrintS("set S");
8033  for (i=0; i<=strat->sl; i++)
8034  {
8035  Print("\n %d:",i);
8036  p_wrp(strat->S[i], currRing, strat->tailRing);
8037  if (strat->fromQ!=NULL && strat->fromQ[i])
8038  Print(" (from Q)");
8039  }
8040  strat->news = FALSE;
8041  }
8042  if (strat->newt)
8043  {
8044  PrintS("\nset T");
8045  for (i=0; i<=strat->tl; i++)
8046  {
8047  Print("\n %d:",i);
8048  strat->T[i].wrp();
8049  if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
8050  Print(" o:%ld e:%d l:%d",
8051  strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
8052  }
8053  strat->newt = FALSE;
8054  }
8055  PrintS("\nset L");
8056  for (i=strat->Ll; i>=0; i--)
8057  {
8058  Print("\n%d:",i);
8059  p_wrp(strat->L[i].p1, currRing, strat->tailRing);
8060  PrintS(" ");
8061  p_wrp(strat->L[i].p2, currRing, strat->tailRing);
8062  PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
8063  PrintS("\n p : ");
8064  strat->L[i].wrp();
8065  Print(" o:%ld e:%d l:%d",
8066  strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
8067  }
8068  PrintLn();
8069 }
8070 
8071 #endif
8072 
8073 
8074 /*2
8075 *construct the set s from F
8076 */
8077 void initS (ideal F, ideal Q, kStrategy strat)
8078 {
8079  int i,pos;
8080 
8081  if (Q!=NULL) i=((IDELEMS(F)+IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8082  else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8083  strat->ecartS=initec(i);
8084  strat->sevS=initsevS(i);
8085  strat->S_2_R=initS_2_R(i);
8086  strat->fromQ=NULL;
8087  strat->Shdl=idInit(i,F->rank);
8088  strat->S=strat->Shdl->m;
8089  /*- put polys into S -*/
8090  if (Q!=NULL)
8091  {
8092  strat->fromQ=initec(i);
8093  memset(strat->fromQ,0,i*sizeof(int));
8094  for (i=0; i<IDELEMS(Q); i++)
8095  {
8096  if (Q->m[i]!=NULL)
8097  {
8098  LObject h;
8099  h.p = pCopy(Q->m[i]);
8101  {
8102  h.pCleardenom(); // also does remove Content
8103  }
8104  else
8105  {
8106  h.pNorm();
8107  }
8109  {
8110  deleteHC(&h, strat);
8111  }
8112  if (h.p!=NULL)
8113  {
8114  strat->initEcart(&h);
8115  if (strat->sl==-1)
8116  pos =0;
8117  else
8118  {
8119  pos = posInS(strat,strat->sl,h.p,h.ecart);
8120  }
8121  h.sev = pGetShortExpVector(h.p);
8122  strat->enterS(h,pos,strat,-1);
8123  strat->fromQ[pos]=1;
8124  }
8125  }
8126  }
8127  }
8128  for (i=0; i<IDELEMS(F); i++)
8129  {
8130  if (F->m[i]!=NULL)
8131  {
8132  LObject h;
8133  h.p = pCopy(F->m[i]);
8135  {
8136  cancelunit(&h); /*- tries to cancel a unit -*/
8137  deleteHC(&h, strat);
8138  }
8139  if (h.p!=NULL)
8140  // do not rely on the input being a SB!
8141  {
8143  {
8144  h.pCleardenom(); // also does remove Content
8145  }
8146  else
8147  {
8148  h.pNorm();
8149  }
8150  strat->initEcart(&h);
8151  if (strat->sl==-1)
8152  pos =0;
8153  else
8154  pos = posInS(strat,strat->sl,h.p,h.ecart);
8155  h.sev = pGetShortExpVector(h.p);
8156  strat->enterS(h,pos,strat,-1);
8157  }
8158  }
8159  }
8160  /*- test, if a unit is in F -*/
8161  if ((strat->sl>=0)
8162 #ifdef HAVE_RINGS
8163  && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
8164 #endif
8165  && pIsConstant(strat->S[0]))
8166  {
8167  while (strat->sl>0) deleteInS(strat->sl,strat);
8168  }
8169 }
8170 
8171 void initSL (ideal F, ideal Q,kStrategy strat)
8172 {
8173  int i,pos;
8174 
8175  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8176  else i=setmaxT;
8177  strat->ecartS=initec(i);
8178  strat->sevS=initsevS(i);
8179  strat->S_2_R=initS_2_R(i);
8180  strat->fromQ=NULL;
8181  strat->Shdl=idInit(i,F->rank);
8182  strat->S=strat->Shdl->m;
8183  /*- put polys into S -*/
8184  if (Q!=NULL)
8185  {
8186  strat->fromQ=initec(i);
8187  memset(strat->fromQ,0,i*sizeof(int));
8188  for (i=0; i<IDELEMS(Q); i++)
8189  {
8190  if (Q->m[i]!=NULL)
8191  {
8192  LObject h;
8193  h.p = pCopy(Q->m[i]);
8195  {
8196  deleteHC(&h,strat);
8197  }
8199  {
8200  h.pCleardenom(); // also does remove Content
8201  }
8202  else
8203  {
8204  h.pNorm();
8205  }
8206  if (h.p!=NULL)
8207  {
8208  strat->initEcart(&h);
8209  if (strat->sl==-1)
8210  pos =0;
8211  else
8212  {
8213  pos = posInS(strat,strat->sl,h.p,h.ecart);
8214  }
8215  h.sev = pGetShortExpVector(h.p);
8216  strat->enterS(h,pos,strat,-1);
8217  strat->fromQ[pos]=1;
8218  }
8219  }
8220  }
8221  }
8222  for (i=0; i<IDELEMS(F); i++)
8223  {
8224  if (F->m[i]!=NULL)
8225  {
8226  LObject h;
8227  h.p = pCopy(F->m[i]);
8228  if (h.p!=NULL)
8229  {
8231  {
8232  cancelunit(&h); /*- tries to cancel a unit -*/
8233  deleteHC(&h, strat);
8234  }
8235  if (h.p!=NULL)
8236  {
8238  {
8239  h.pCleardenom(); // also does remove Content
8240  }
8241  else
8242  {
8243  h.pNorm();
8244  }
8245  strat->initEcart(&h);
8246  if (strat->Ll==-1)
8247  pos =0;
8248  else
8249  pos = strat->posInL(strat->L,strat->Ll,&h,strat);
8250  h.sev = pGetShortExpVector(h.p);
8251  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8252  }
8253  }
8254  }
8255  }
8256  /*- test, if a unit is in F -*/
8257 
8258  if ((strat->Ll>=0)
8259 #ifdef HAVE_RINGS
8260  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8261 #endif
8262  && pIsConstant(strat->L[strat->Ll].p))
8263  {
8264  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8265  }
8266 }
8267 
8268 void initSLSba (ideal F, ideal Q,kStrategy strat)
8269 {
8270  int i,pos;
8271  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8272  else i=setmaxT;
8273  strat->ecartS = initec(i);
8274  strat->sevS = initsevS(i);
8275  strat->sevSig = initsevS(i);
8276  strat->S_2_R = initS_2_R(i);
8277  strat->fromQ = NULL;
8278  strat->Shdl = idInit(i,F->rank);
8279  strat->S = strat->Shdl->m;
8280  strat->sig = (poly *)omAlloc0(i*sizeof(poly));
8281  if (strat->sbaOrder != 1)
8282  {
8283  strat->syz = (poly *)omAlloc0(i*sizeof(poly));
8284  strat->sevSyz = initsevS(i);
8285  strat->syzmax = i;
8286  strat->syzl = 0;
8287  }
8288  /*- put polys into S -*/
8289  if (Q!=NULL)
8290  {
8291  strat->fromQ=initec(i);
8292  memset(strat->fromQ,0,i*sizeof(int));
8293  for (i=0; i<IDELEMS(Q); i++)
8294  {
8295  if (Q->m[i]!=NULL)
8296  {
8297  LObject h;
8298  h.p = pCopy(Q->m[i]);
8300  {
8301  deleteHC(&h,strat);
8302  }
8304  {
8305  h.pCleardenom(); // also does remove Content
8306  }
8307  else
8308  {
8309  h.pNorm();
8310  }
8311  if (h.p!=NULL)
8312  {
8313  strat->initEcart(&h);
8314  if (strat->sl==-1)
8315  pos =0;
8316  else
8317  {
8318  pos = posInS(strat,strat->sl,h.p,h.ecart);
8319  }
8320  h.sev = pGetShortExpVector(h.p);
8321  strat->enterS(h,pos,strat,-1);
8322  strat->fromQ[pos]=1;
8323  }
8324  }
8325  }
8326  }
8327  for (i=0; i<IDELEMS(F); i++)
8328  {
8329  if (F->m[i]!=NULL)
8330  {
8331  LObject h;
8332  h.p = pCopy(F->m[i]);
8333  h.sig = pOne();
8334  //h.sig = pInit();
8335  //p_SetCoeff(h.sig,nInit(1),currRing);
8336  p_SetComp(h.sig,i+1,currRing);
8337  // if we are working with the Schreyer order we generate it
8338  // by multiplying the initial signatures with the leading monomial
8339  // of the corresponding initial polynomials generating the ideal
8340  // => we can keep the underlying monomial order and get a Schreyer
8341  // order without any bigger overhead
8342  if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
8343  {
8344  p_ExpVectorAdd (h.sig,F->m[i],currRing);
8345  }
8346  h.sevSig = pGetShortExpVector(h.sig);
8347 #ifdef DEBUGF5
8348  pWrite(h.p);
8349  pWrite(h.sig);
8350 #endif
8351  if (h.p!=NULL)
8352  {
8354  {
8355  cancelunit(&h); /*- tries to cancel a unit -*/
8356  deleteHC(&h, strat);
8357  }
8358  if (h.p!=NULL)
8359  {
8361  {
8362  h.pCleardenom(); // also does remove Content
8363  }
8364  else
8365  {
8366  h.pNorm();
8367  }
8368  strat->initEcart(&h);
8369  if (strat->Ll==-1)
8370  pos =0;
8371  else
8372  pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
8373  h.sev = pGetShortExpVector(h.p);
8374  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8375  }
8376  }
8377  /*
8378  if (strat->sbaOrder != 1)
8379  {
8380  for(j=0;j<i;j++)
8381  {
8382  strat->syz[ctr] = pCopy(F->m[j]);
8383  p_SetCompP(strat->syz[ctr],i+1,currRing);
8384  // add LM(F->m[i]) to the signature to get a Schreyer order
8385  // without changing the underlying polynomial ring at all
8386  p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
8387  // since p_Add_q() destroys all input
8388  // data we need to recreate help
8389  // each time
8390  poly help = pCopy(F->m[i]);
8391  p_SetCompP(help,j+1,currRing);
8392  pWrite(strat->syz[ctr]);
8393  pWrite(help);
8394  printf("%d\n",pLmCmp(strat->syz[ctr],help));
8395  strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
8396  printf("%d. SYZ ",ctr);
8397  pWrite(strat->syz[ctr]);
8398  strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
8399  ctr++;
8400  }
8401  strat->syzl = ps;
8402  }
8403  */
8404  }
8405  }
8406  /*- test, if a unit is in F -*/
8407 
8408  if ((strat->Ll>=0)
8409 #ifdef HAVE_RINGS
8410  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8411 #endif
8412  && pIsConstant(strat->L[strat->Ll].p))
8413  {
8414  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8415  }
8416 }
8417 
8419 {
8420  if( strat->S[0] )
8421  {
8422  if( strat->S[1] && !rField_is_Ring(currRing))
8423  {
8424  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
8425  omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
8426  omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
8427  }
8428  int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
8429  /************************************************************
8430  * computing the length of the syzygy array needed
8431  ***********************************************************/
8432  for(i=1; i<=strat->sl; i++)
8433  {
8434  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8435  {
8436  ps += i;
8437  }
8438  }
8439  ps += strat->sl+1;
8440  //comp = pGetComp (strat->P.sig);
8441  comp = strat->currIdx;
8442  strat->syzIdx = initec(comp);
8443  strat->sevSyz = initsevS(ps);
8444  strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8445  strat->syzmax = ps;
8446  strat->syzl = 0;
8447  strat->syzidxmax = comp;
8448 #if defined(DEBUGF5) || defined(DEBUGF51)
8449  PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8450 #endif
8451  i = 1;
8452  j = 0;
8453  /************************************************************
8454  * generating the leading terms of the principal syzygies
8455  ***********************************************************/
8456  while (i <= strat->sl)
8457  {
8458  /**********************************************************
8459  * principal syzygies start with component index 2
8460  * the array syzIdx starts with index 0
8461  * => the rules for a signature with component comp start
8462  * at strat->syz[strat->syzIdx[comp-2]] !
8463  *********************************************************/
8464  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8465  {
8466  comp = pGetComp(strat->sig[i]);
8467  comp_old = pGetComp(strat->sig[i-1]);
8468  diff = comp - comp_old - 1;
8469  // diff should be zero, but sometimes also the initial generating
8470  // elements of the input ideal reduce to zero. then there is an
8471  // index-gap between the signatures. for these inbetween signatures we
8472  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8473  // in the following.
8474  // doing this, we keep the relation "j = comp - 2" alive, which makes
8475  // jumps way easier when checking criteria
8476  while (diff>0)
8477  {
8478  strat->syzIdx[j] = 0;
8479  diff--;
8480  j++;
8481  }
8482  strat->syzIdx[j] = ctr;
8483  j++;
8484  LObject Q;
8485  int pos;
8486  for (k = 0; k<i; k++)
8487  {
8488  Q.sig = pOne();
8490  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8491  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8492  p_SetCompP (Q.sig, comp, currRing);
8493  poly q = p_One(currRing);
8495  p_SetCoeff(q,nCopy(p_GetCoeff(strat->S[i],currRing)),currRing);
8496  p_ExpVectorCopy(q,strat->S[i],currRing);
8497  q = p_Neg (q, currRing);
8498  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8499  Q.sig = p_Add_q (Q.sig, q, currRing);
8500  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8501  pos = posInSyz(strat, Q.sig);
8502  enterSyz(Q, strat, pos);
8503  ctr++;
8504  }
8505  }
8506  i++;
8507  }
8508  /**************************************************************
8509  * add syzygies for upcoming first element of new iteration step
8510  **************************************************************/
8511  comp = strat->currIdx;
8512  comp_old = pGetComp(strat->sig[i-1]);
8513  diff = comp - comp_old - 1;
8514  // diff should be zero, but sometimes also the initial generating
8515  // elements of the input ideal reduce to zero. then there is an
8516  // index-gap between the signatures. for these inbetween signatures we
8517  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8518  // in the following.
8519  // doing this, we keep the relation "j = comp - 2" alive, which makes
8520  // jumps way easier when checking criteria
8521  while (diff>0)
8522  {
8523  strat->syzIdx[j] = 0;
8524  diff--;
8525  j++;
8526  }
8527  strat->syzIdx[j] = ctr;
8528  LObject Q;
8529  int pos;
8530  for (k = 0; k<strat->sl+1; k++)
8531  {
8532  Q.sig = pOne();
8534  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8535  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8536  p_SetCompP (Q.sig, comp, currRing);
8537  poly q = p_One(currRing);
8539  p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8540  p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8541  q = p_Neg (q, currRing);
8542  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8543  Q.sig = p_Add_q (Q.sig, q, currRing);
8544  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8545  pos = posInSyz(strat, Q.sig);
8546  enterSyz(Q, strat, pos);
8547  ctr++;
8548  }
8549 //#if 1
8550 #ifdef DEBUGF5
8551  PrintS("Principal syzygies:\n");
8552  Print("syzl %d\n",strat->syzl);
8553  Print("syzmax %d\n",strat->syzmax);
8554  Print("ps %d\n",ps);
8555  PrintS("--------------------------------\n");
8556  for(i=0;i<=strat->syzl-1;i++)
8557  {
8558  Print("%d - ",i);
8559  pWrite(strat->syz[i]);
8560  }
8561  for(i=0;i<strat->currIdx;i++)
8562  {
8563  Print("%d - %d\n",i,strat->syzIdx[i]);
8564  }
8565  PrintS("--------------------------------\n");
8566 #endif
8567  }
8568 }
8569 
8570 /*2
8571 *construct the set s from F and {P}
8572 */
8573 void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8574 {
8575  int i,pos;
8576 
8577  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8578  else i=setmaxT;
8579  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8580  strat->ecartS=initec(i);
8581  strat->sevS=initsevS(i);
8582  strat->S_2_R=initS_2_R(i);
8583  strat->fromQ=NULL;
8584  strat->Shdl=idInit(i,F->rank);
8585  strat->S=strat->Shdl->m;
8586 
8587  /*- put polys into S -*/
8588  if (Q!=NULL)
8589  {
8590  strat->fromQ=initec(i);
8591  memset(strat->fromQ,0,i*sizeof(int));
8592  for (i=0; i<IDELEMS(Q); i++)
8593  {
8594  if (Q->m[i]!=NULL)
8595  {
8596  LObject h;
8597  h.p = pCopy(Q->m[i]);
8598  //if (TEST_OPT_INTSTRATEGY)
8599  //{
8600  // h.pCleardenom(); // also does remove Content
8601  //}
8602  //else
8603  //{
8604  // h.pNorm();
8605  //}
8607  {
8608  deleteHC(&h,strat);
8609  }
8610  if (h.p!=NULL)
8611  {
8612  strat->initEcart(&h);
8613  if (strat->sl==-1)
8614  pos =0;
8615  else
8616  {
8617  pos = posInS(strat,strat->sl,h.p,h.ecart);
8618  }
8619  h.sev = pGetShortExpVector(h.p);
8620  strat->enterS(h,pos,strat, strat->tl+1);
8621  enterT(h, strat);
8622  strat->fromQ[pos]=1;
8623  }
8624  }
8625  }
8626  }
8627  /*- put polys into S -*/
8628  for (i=0; i<IDELEMS(F); i++)
8629  {
8630  if (F->m[i]!=NULL)
8631  {
8632  LObject h;
8633  h.p = pCopy(F->m[i]);
8635  {
8636  deleteHC(&h,strat);
8637  }
8638  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8639  {
8640  h.p=redtailBba(h.p,strat->sl,strat);
8641  }
8642  if (h.p!=NULL)
8643  {
8644  strat->initEcart(&h);
8645  if (strat->sl==-1)
8646  pos =0;
8647  else
8648  pos = posInS(strat,strat->sl,h.p,h.ecart);
8649  h.sev = pGetShortExpVector(h.p);
8650  strat->enterS(h,pos,strat, strat->tl+1);
8651  enterT(h,strat);
8652  }
8653  }
8654  }
8655  for (i=0; i<IDELEMS(P); i++)
8656  {
8657  if (P->m[i]!=NULL)
8658  {
8659  LObject h;
8660  h.p=pCopy(P->m[i]);
8662  {
8663  h.pCleardenom();
8664  }
8665  else
8666  {
8667  h.pNorm();
8668  }
8669  if(strat->sl>=0)
8670  {
8672  {
8673  h.p=redBba(h.p,strat->sl,strat);
8674  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8675  {
8676  h.p=redtailBba(h.p,strat->sl,strat);
8677  }
8678  }
8679  else
8680  {
8681  h.p=redMora(h.p,strat->sl,strat);
8682  }
8683  if(h.p!=NULL)
8684  {
8685  strat->initEcart(&h);
8687  {
8688  h.pCleardenom();
8689  }
8690  else
8691  {
8692  h.is_normalized = 0;
8693  h.pNorm();
8694  }
8695  h.sev = pGetShortExpVector(h.p);
8696  h.SetpFDeg();
8697  pos = posInS(strat,strat->sl,h.p,h.ecart);
8698  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8699  strat->enterS(h,pos,strat, strat->tl+1);
8700  enterT(h,strat);
8701  }
8702  }
8703  else
8704  {
8705  h.sev = pGetShortExpVector(h.p);
8706  strat->initEcart(&h);
8707  strat->enterS(h,0,strat, strat->tl+1);
8708  enterT(h,strat);
8709  }
8710  }
8711  }
8712 }
8713 /*2
8714 *construct the set s from F and {P}
8715 */
8716 
8717 void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8718 {
8719  int i,pos;
8720 
8721  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8722  else i=setmaxT;
8723  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8724  strat->sevS=initsevS(i);
8725  strat->sevSig=initsevS(i);
8726  strat->S_2_R=initS_2_R(i);
8727  strat->fromQ=NULL;
8728  strat->Shdl=idInit(i,F->rank);
8729  strat->S=strat->Shdl->m;
8730  strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8731  /*- put polys into S -*/
8732  if (Q!=NULL)
8733  {
8734  strat->fromQ=initec(i);
8735  memset(strat->fromQ,0,i*sizeof(int));
8736  for (i=0; i<IDELEMS(Q); i++)
8737  {
8738  if (Q->m[i]!=NULL)
8739  {
8740  LObject h;
8741  h.p = pCopy(Q->m[i]);
8742  //if (TEST_OPT_INTSTRATEGY)
8743  //{
8744  // h.pCleardenom(); // also does remove Content
8745  //}
8746  //else
8747  //{
8748  // h.pNorm();
8749  //}
8751  {
8752  deleteHC(&h,strat);
8753  }
8754  if (h.p!=NULL)
8755  {
8756  strat->initEcart(&h);
8757  if (strat->sl==-1)
8758  pos =0;
8759  else
8760  {
8761  pos = posInS(strat,strat->sl,h.p,h.ecart);
8762  }
8763  h.sev = pGetShortExpVector(h.p);
8764  strat->enterS(h,pos,strat, strat->tl+1);
8765  enterT(h, strat);
8766  strat->fromQ[pos]=1;
8767  }
8768  }
8769  }
8770  }
8771  /*- put polys into S -*/
8772  for (i=0; i<IDELEMS(F); i++)
8773  {
8774  if (F->m[i]!=NULL)
8775  {
8776  LObject h;
8777  h.p = pCopy(F->m[i]);
8779  {
8780  deleteHC(&h,strat);
8781  }
8782  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8783  {
8784  h.p=redtailBba(h.p,strat->sl,strat);
8785  }
8786  if (h.p!=NULL)
8787  {
8788  strat->initEcart(&h);
8789  if (strat->sl==-1)
8790  pos =0;
8791  else
8792  pos = posInS(strat,strat->sl,h.p,h.ecart);
8793  h.sev = pGetShortExpVector(h.p);
8794  strat->enterS(h,pos,strat, strat->tl+1);
8795  enterT(h,strat);
8796  }
8797  }
8798  }
8799  for (i=0; i<IDELEMS(P); i++)
8800  {
8801  if (P->m[i]!=NULL)
8802  {
8803  LObject h;
8804  h.p=pCopy(P->m[i]);
8806  {
8807  h.pCleardenom();
8808  }
8809  else
8810  {
8811  h.pNorm();
8812  }
8813  if(strat->sl>=0)
8814  {
8816  {
8817  h.p=redBba(h.p,strat->sl,strat);
8818  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8819  {
8820  h.p=redtailBba(h.p,strat->sl,strat);
8821  }
8822  }
8823  else
8824  {
8825  h.p=redMora(h.p,strat->sl,strat);
8826  }
8827  if(h.p!=NULL)
8828  {
8829  strat->initEcart(&h);
8831  {
8832  h.pCleardenom();
8833  }
8834  else
8835  {
8836  h.is_normalized = 0;
8837  h.pNorm();
8838  }
8839  h.sev = pGetShortExpVector(h.p);
8840  h.SetpFDeg();
8841  pos = posInS(strat,strat->sl,h.p,h.ecart);
8842  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8843  strat->enterS(h,pos,strat, strat->tl+1);
8844  enterT(h,strat);
8845  }
8846  }
8847  else
8848  {
8849  h.sev = pGetShortExpVector(h.p);
8850  strat->initEcart(&h);
8851  strat->enterS(h,0,strat, strat->tl+1);
8852  enterT(h,strat);
8853  }
8854  }
8855  }
8856 }
8857 
8858 /*2
8859 * reduces h using the set S
8860 * procedure used in cancelunit1
8861 */
8862 static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8863 {
8864  int j = 0;
8865  unsigned long not_sev = ~ pGetShortExpVector(h);
8866 
8867  while (j <= maxIndex)
8868  {
8869  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8870  return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8871  else j++;
8872  }
8873  return h;
8874 }
8875 
8876 /*2
8877 *tests if p.p=monomial*unit and cancels the unit
8878 */
8879 void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8880 {
8881  int k;
8882  poly r,h,h1,q;
8883 
8884  if (!pIsVector((*p).p) && ((*p).ecart != 0))
8885  {
8886 #ifdef HAVE_RINGS
8887  // Leading coef have to be a unit: no
8888  // example 2x+4x2 should be simplified to 2x*(1+2x)
8889  // and 2 is not a unit in Z
8890  //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8891 #endif
8892  k = 0;
8893  h1 = r = pCopy((*p).p);
8894  h =pNext(r);
8895  loop
8896  {
8897  if (h==NULL)
8898  {
8899  pDelete(&r);
8900  pDelete(&(pNext((*p).p)));
8901  (*p).ecart = 0;
8902  (*p).length = 1;
8903  (*p).pLength = 1;
8904  (*suc)=0;
8905  return;
8906  }
8907  if (!pDivisibleBy(r,h))
8908  {
8909  q=redBba1(h,index ,strat);
8910  if (q != h)
8911  {
8912  k++;
8913  pDelete(&h);
8914  pNext(h1) = h = q;
8915  }
8916  else
8917  {
8918  pDelete(&r);
8919  return;
8920  }
8921  }
8922  else
8923  {
8924  h1 = h;
8925  pIter(h);
8926  }
8927  if (k > 10)
8928  {
8929  pDelete(&r);
8930  return;
8931  }
8932  }
8933  }
8934 }
8935 
8936 #if 0
8937 /*2
8938 * reduces h using the elements from Q in the set S
8939 * procedure used in updateS
8940 * must not be used for elements of Q or elements of an ideal !
8941 */
8942 static poly redQ (poly h, int j, kStrategy strat)
8943 {
8944  int start;
8945  unsigned long not_sev = ~ pGetShortExpVector(h);
8946  while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8947  start=j;
8948  while (j<=strat->sl)
8949  {
8950  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8951  {
8952  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8953  if (h==NULL) return NULL;
8954  j = start;
8955  not_sev = ~ pGetShortExpVector(h);
8956  }
8957  else j++;
8958  }
8959  return h;
8960 }
8961 #endif
8962 
8963 /*2
8964 * reduces h using the set S
8965 * procedure used in updateS
8966 */
8967 static poly redBba (poly h,int maxIndex,kStrategy strat)
8968 {
8969  int j = 0;
8970  unsigned long not_sev = ~ pGetShortExpVector(h);
8971 
8972  while (j <= maxIndex)
8973  {
8974  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8975  {
8976  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8977  if (h==NULL) return NULL;
8978  j = 0;
8979  not_sev = ~ pGetShortExpVector(h);
8980  }
8981  else j++;
8982  }
8983  return h;
8984 }
8985 
8986 /*2
8987 * reduces h using the set S
8988 *e is the ecart of h
8989 *procedure used in updateS
8990 */
8991 static poly redMora (poly h,int maxIndex,kStrategy strat)
8992 {
8993  int j=0;
8994  int e,l;
8995  unsigned long not_sev = ~ pGetShortExpVector(h);
8996 
8997  if (maxIndex >= 0)
8998  {
8999  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
9000  do
9001  {
9002  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
9003  && ((e >= strat->ecartS[j]) || strat->kHEdgeFound))
9004  {
9005 #ifdef KDEBUG
9006  if (TEST_OPT_DEBUG)
9007  {
9008  PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
9009  }
9010 #endif
9011  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
9012 #ifdef KDEBUG
9013  if(TEST_OPT_DEBUG)
9014  {
9015  PrintS(")\nto "); wrp(h); PrintLn();
9016  }
9017 #endif
9018  // pDelete(&h);
9019  if (h == NULL) return NULL;
9020  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
9021  j = 0;
9022  not_sev = ~ pGetShortExpVector(h);
9023  }
9024  else j++;
9025  }
9026  while (j <= maxIndex);
9027  }
9028  return h;
9029 }
9030 
9031 /*2
9032 *updates S:
9033 *the result is a set of polynomials which are in
9034 *normalform with respect to S
9035 */
9036 void updateS(BOOLEAN toT,kStrategy strat)
9037 {
9038  LObject h;
9039  int i, suc=0;
9040  poly redSi=NULL;
9041  BOOLEAN change,any_change;
9042 // Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
9043 // for (i=0; i<=(strat->sl); i++)
9044 // {
9045 // Print("s%d:",i);
9046 // if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
9047 // pWrite(strat->S[i]);
9048 // }
9049 // Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
9050  any_change=FALSE;
9052  {
9053  while (suc != -1)
9054  {
9055  i=suc+1;
9056  while (i<=strat->sl)
9057  {
9058  change=FALSE;
9060  any_change = FALSE;
9061  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
9062  {
9063  redSi = pHead(strat->S[i]);
9064  strat->S[i] = redBba(strat->S[i],i-1,strat);
9065  //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
9066  // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
9067  if (pCmp(redSi,strat->S[i])!=0)
9068  {
9069  change=TRUE;
9070  any_change=TRUE;
9071  #ifdef KDEBUG
9072  if (TEST_OPT_DEBUG)
9073  {
9074  PrintS("reduce:");
9075  wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
9076  }
9077  #endif
9078  if (TEST_OPT_PROT)
9079  {
9080  if (strat->S[i]==NULL)
9081  PrintS("V");
9082  else
9083  PrintS("v");
9084  mflush();
9085  }
9086  }
9087  pLmDelete(&redSi);
9088  if (strat->S[i]==NULL)
9089  {
9090  deleteInS(i,strat);
9091  i--;
9092  }
9093  else if (change)
9094  {
9096  {
9097  if (TEST_OPT_CONTENTSB)
9098  {
9099  number n;
9100  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
9101  if (!nIsOne(n))
9102  {
9104  denom->n=nInvers(n);
9105  denom->next=DENOMINATOR_LIST;
9106  DENOMINATOR_LIST=denom;
9107  }
9108  nDelete(&n);
9109  }
9110  else
9111  {
9112  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
9113  }
9114  }
9115  else
9116  {
9117  pNorm(strat->S[i]);
9118  }
9119  strat->sevS[i] = pGetShortExpVector(strat->S[i]);
9120  }
9121  }
9122  i++;
9123  }
9124  if (any_change) reorderS(&suc,strat);
9125  else break;
9126  }
9127  if (toT)
9128  {
9129  for (i=0; i<=strat->sl; i++)
9130  {
9131  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9132  {
9133  h.p = redtailBba(strat->S[i],i-1,strat);
9135  {
9136  h.pCleardenom();// also does remove Content
9137  }
9138  }
9139  else
9140  {
9141  h.p = strat->S[i];
9142  }
9143  strat->initEcart(&h);
9144  if (strat->honey)
9145  {
9146  strat->ecartS[i] = h.ecart;
9147  }
9148  if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
9149  else assume(strat->sevS[i] == pGetShortExpVector(h.p));
9150  h.sev = strat->sevS[i];
9151  /*puts the elements of S also to T*/
9152  strat->initEcart(&h);
9153  enterT(h,strat);
9154  strat->S_2_R[i] = strat->tl;
9155 #ifdef HAVE_SHIFTBBA
9156  if (currRing->isLPring)
9157  enterTShift(h, strat);
9158 #endif
9159  }
9160  }
9161  }
9162  else
9163  {
9164  while (suc != -1)
9165  {
9166  i=suc;
9167  while (i<=strat->sl)
9168  {
9169  change=FALSE;
9170  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
9171  {
9172  redSi=pHead((strat->S)[i]);
9173  (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
9174  if ((strat->S)[i]==NULL)
9175  {
9176  deleteInS(i,strat);
9177  i--;
9178  }
9179  else if (pCmp((strat->S)[i],redSi)!=0)
9180  {
9181  any_change=TRUE;
9182  h.p = strat->S[i];
9183  strat->initEcart(&h);
9184  strat->ecartS[i] = h.ecart;
9186  {
9187  if (TEST_OPT_CONTENTSB)
9188  {
9189  number n;
9190  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
9191  if (!nIsOne(n))
9192  {
9194  denom->n=nInvers(n);
9195  denom->next=DENOMINATOR_LIST;
9196  DENOMINATOR_LIST=denom;
9197  }
9198  nDelete(&n);
9199  }
9200  else
9201  {
9202  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
9203  }
9204  }
9205  else
9206  {
9207  pNorm(strat->S[i]); // == h.p
9208  }
9209  h.sev = pGetShortExpVector(h.p);
9210  strat->sevS[i] = h.sev;
9211  }
9212  pLmDelete(&redSi);
9213  kTest(strat);
9214  }
9215  i++;
9216  }
9217 #ifdef KDEBUG
9218  kTest(strat);
9219 #endif
9220  if (any_change) reorderS(&suc,strat);
9221  else { suc=-1; break; }
9222  if (h.p!=NULL)
9223  {
9224  if (!strat->kHEdgeFound)
9225  {
9226  /*strat->kHEdgeFound =*/ HEckeTest(h.p,strat);
9227  }
9228  if (strat->kHEdgeFound)
9229  newHEdge(strat);
9230  }
9231  }
9232  for (i=0; i<=strat->sl; i++)
9233  {
9234  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9235  {
9236  strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
9237  strat->initEcart(&h);
9238  strat->ecartS[i] = h.ecart;
9239  h.sev = pGetShortExpVector(h.p);
9240  strat->sevS[i] = h.sev;
9241  }
9242  else
9243  {
9244  h.p = strat->S[i];
9245  h.ecart=strat->ecartS[i];
9246  h.sev = strat->sevS[i];
9247  h.length = h.pLength = pLength(h.p);
9248  }
9249  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9250  cancelunit1(&h,&suc,strat->sl,strat);
9251  h.SetpFDeg();
9252  /*puts the elements of S also to T*/
9253  enterT(h,strat);
9254  strat->S_2_R[i] = strat->tl;
9255 #ifdef HAVE_SHIFTBBA
9256  if (currRing->isLPring)
9257  enterTShift(h, strat);
9258 #endif
9259  }
9260  if (suc!= -1) updateS(toT,strat);
9261  }
9262 #ifdef KDEBUG
9263  kTest(strat);
9264 #endif
9265 }
9266 
9267 /*2
9268 * -puts p to the standardbasis s at position at
9269 * -saves the result in S
9270 */
9271 void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
9272 {
9273  strat->news = TRUE;
9274  /*- puts p to the standardbasis s at position at -*/
9275  if (strat->sl == IDELEMS(strat->Shdl)-1)
9276  {
9277  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9278  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9279  (IDELEMS(strat->Shdl)+setmaxTinc)
9280  *sizeof(unsigned long));
9281  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9282  IDELEMS(strat->Shdl)*sizeof(int),
9283  (IDELEMS(strat->Shdl)+setmaxTinc)
9284  *sizeof(int));
9285  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9286  IDELEMS(strat->Shdl)*sizeof(int),
9287  (IDELEMS(strat->Shdl)+setmaxTinc)
9288  *sizeof(int));
9289  if (strat->lenS!=NULL)
9290  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9291  IDELEMS(strat->Shdl)*sizeof(int),
9292  (IDELEMS(strat->Shdl)+setmaxTinc)
9293  *sizeof(int));
9294  if (strat->lenSw!=NULL)
9295  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9296  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9297  (IDELEMS(strat->Shdl)+setmaxTinc)
9298  *sizeof(wlen_type));
9299  if (strat->fromQ!=NULL)
9300  {
9301  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9302  IDELEMS(strat->Shdl)*sizeof(int),
9303  (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9304  }
9305  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
9306  IDELEMS(strat->Shdl)+=setmaxTinc;
9307  strat->Shdl->m=strat->S;
9308  }
9309  if (atS <= strat->sl)
9310  {
9311 #ifdef ENTER_USE_MEMMOVE
9312  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9313  (strat->sl - atS + 1)*sizeof(poly));
9314  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9315  (strat->sl - atS + 1)*sizeof(int));
9316  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9317  (strat->sl - atS + 1)*sizeof(unsigned long));
9318  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9319  (strat->sl - atS + 1)*sizeof(int));
9320  if (strat->lenS!=NULL)
9321  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9322  (strat->sl - atS + 1)*sizeof(int));
9323  if (strat->lenSw!=NULL)
9324  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9325  (strat->sl - atS + 1)*sizeof(wlen_type));
9326 #else
9327  for (i=strat->sl+1; i>=atS+1; i--)
9328  {
9329  strat->S[i] = strat->S[i-1];
9330  strat->ecartS[i] = strat->ecartS[i-1];
9331  strat->sevS[i] = strat->sevS[i-1];
9332  strat->S_2_R[i] = strat->S_2_R[i-1];
9333  }
9334  if (strat->lenS!=NULL)
9335  for (i=strat->sl+1; i>=atS+1; i--)
9336  strat->lenS[i] = strat->lenS[i-1];
9337  if (strat->lenSw!=NULL)
9338  for (i=strat->sl+1; i>=atS+1; i--)
9339  strat->lenSw[i] = strat->lenSw[i-1];
9340 #endif
9341  }
9342  if (strat->fromQ!=NULL)
9343  {
9344 #ifdef ENTER_USE_MEMMOVE
9345  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9346  (strat->sl - atS + 1)*sizeof(int));
9347 #else
9348  for (i=strat->sl+1; i>=atS+1; i--)
9349  {
9350  strat->fromQ[i] = strat->fromQ[i-1];
9351  }
9352 #endif
9353  strat->fromQ[atS]=0;
9354  }
9355 
9356  /*- save result -*/
9357  poly pp=p.p;
9358  strat->S[atS] = pp;
9359  if (strat->honey) strat->ecartS[atS] = p.ecart;
9360  if (p.sev == 0)
9361  p.sev = pGetShortExpVector(pp);
9362  else
9363  assume(p.sev == pGetShortExpVector(pp));
9364  strat->sevS[atS] = p.sev;
9365  strat->ecartS[atS] = p.ecart;
9366  strat->S_2_R[atS] = atR;
9367  strat->sl++;
9368 }
9369 
9370 #ifdef HAVE_SHIFTBBA
9371 void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR)
9372 {
9373  int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
9374  for (int i = maxPossibleShift; i > 0; i--)
9375  {
9376  LObject qq;
9377  qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
9378  qq.shift = i;
9379  strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
9380  enterSBba(qq, atS, strat, -1);
9381  }
9382  enterSBba(p, atS, strat, atR);
9383 }
9384 #endif
9385 
9386 /*2
9387 * -puts p to the standardbasis s at position at
9388 * -saves the result in S
9389 */
9390 void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
9391 {
9392  strat->news = TRUE;
9393  /*- puts p to the standardbasis s at position at -*/
9394  if (strat->sl == IDELEMS(strat->Shdl)-1)
9395  {
9396  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9397  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9398  (IDELEMS(strat->Shdl)+setmax)
9399  *sizeof(unsigned long));
9400  strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
9401  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9402  (IDELEMS(strat->Shdl)+setmax)
9403  *sizeof(unsigned long));
9404  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9405  IDELEMS(strat->Shdl)*sizeof(int),
9406  (IDELEMS(strat->Shdl)+setmax)
9407  *sizeof(int));
9408  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9409  IDELEMS(strat->Shdl)*sizeof(int),
9410  (IDELEMS(strat->Shdl)+setmax)
9411  *sizeof(int));
9412  if (strat->lenS!=NULL)
9413  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9414  IDELEMS(strat->Shdl)*sizeof(int),
9415  (IDELEMS(strat->Shdl)+setmax)
9416  *sizeof(int));
9417  if (strat->lenSw!=NULL)
9418  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9419  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9420  (IDELEMS(strat->Shdl)+setmax)
9421  *sizeof(wlen_type));
9422  if (strat->fromQ!=NULL)
9423  {
9424  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9425  IDELEMS(strat->Shdl)*sizeof(int),
9426  (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
9427  }
9428  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
9429  pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
9430  IDELEMS(strat->Shdl)+=setmax;
9431  strat->Shdl->m=strat->S;
9432  }
9433  // in a signature-based algorithm the following situation will never
9434  // appear due to the fact that the critical pairs are already sorted
9435  // by increasing signature.
9436  // True. However, in the case of integers we need to put the element
9437  // that caused the signature drop on the first position
9438  if (atS <= strat->sl)
9439  {
9440 #ifdef ENTER_USE_MEMMOVE
9441  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9442  (strat->sl - atS + 1)*sizeof(poly));
9443  memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9444  (strat->sl - atS + 1)*sizeof(poly));
9445  memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9446  (strat->sl - atS + 1)*sizeof(unsigned long));
9447  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9448  (strat->sl - atS + 1)*sizeof(int));
9449  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9450  (strat->sl - atS + 1)*sizeof(unsigned long));
9451  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9452  (strat->sl - atS + 1)*sizeof(int));
9453  if (strat->lenS!=NULL)
9454  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9455  (strat->sl - atS + 1)*sizeof(int));
9456  if (strat->lenSw!=NULL)
9457  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9458  (strat->sl - atS + 1)*sizeof(wlen_type));
9459 #else
9460  for (i=strat->sl+1; i>=atS+1; i--)
9461  {
9462  strat->S[i] = strat->S[i-1];
9463  strat->ecartS[i] = strat->ecartS[i-1];
9464  strat->sevS[i] = strat->sevS[i-1];
9465  strat->S_2_R[i] = strat->S_2_R[i-1];
9466  strat->sig[i] = strat->sig[i-1];
9467  strat->sevSig[i] = strat->sevSig[i-1];
9468  }
9469  if (strat->lenS!=NULL)
9470  for (i=strat->sl+1; i>=atS+1; i--)
9471  strat->lenS[i] = strat->lenS[i-1];
9472  if (strat->lenSw!=NULL)
9473  for (i=strat->sl+1; i>=atS+1; i--)
9474  strat->lenSw[i] = strat->lenSw[i-1];
9475 #endif
9476  }
9477  if (strat->fromQ!=NULL)
9478  {
9479 #ifdef ENTER_USE_MEMMOVE
9480  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9481  (strat->sl - atS + 1)*sizeof(int));
9482 #else
9483  for (i=strat->sl+1; i>=atS+1; i--)
9484  {
9485  strat->fromQ[i] = strat->fromQ[i-1];
9486  }
9487 #endif
9488  strat->fromQ[atS]=0;
9489  }
9490 
9491  /*- save result -*/
9492  strat->S[atS] = p.p;
9493  strat->sig[atS] = p.sig; // TODO: get ths correct signature in here!
9494  if (strat->honey) strat->ecartS[atS] = p.ecart;
9495  if (p.sev == 0)
9496  p.sev = pGetShortExpVector(p.p);
9497  else
9498  assume(p.sev == pGetShortExpVector(p.p));
9499  strat->sevS[atS] = p.sev;
9500  // during the interreduction process of a signature-based algorithm we do not
9501  // compute the signature at this point, but when the whole interreduction
9502  // process finishes, i.e. f5c terminates!
9503  if (p.sig != NULL)
9504  {
9505  if (p.sevSig == 0)
9506  p.sevSig = pGetShortExpVector(p.sig);
9507  else
9508  assume(p.sevSig == pGetShortExpVector(p.sig));
9509  strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9510  }
9511  strat->ecartS[atS] = p.ecart;
9512  strat->S_2_R[atS] = atR;
9513  strat->sl++;
9514 #ifdef DEBUGF5
9515  int k;
9516  Print("--- LIST S: %d ---\n",strat->sl);
9517  for(k=0;k<=strat->sl;k++)
9518  {
9519  pWrite(strat->sig[k]);
9520  }
9521  PrintS("--- LIST S END ---\n");
9522 #endif
9523 }
9524 
9525 void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
9526 {
9527  p.GetP(strat->lmBin);
9528  if (strat->homog) strat->initEcart(&p);
9529  strat->redTailChange=FALSE;
9531  p.pCleardenom();
9532  if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) {
9533  p.p = redtailBba(&p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9534  p.pCleardenom();
9535  if (strat->redTailChange)
9536  p.t_p=NULL;
9537  }
9538  }
9539 
9540  assume(strat->tailRing == p.tailRing);
9541  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9542 
9543  int i, j, pos;
9544  poly tp = strat->T[tj].p;
9545 
9546  /* enter p to T set */
9547  enterT(p, strat);
9548 
9549  for (j = 0; j <= strat->sl; ++j) {
9550  if (pLtCmp(tp, strat->S[j]) == 0) {
9551  break;
9552  }
9553  }
9554  /* it may be that the exchanged element
9555  * is until now only in T and not in S */
9556  if (j <= strat->sl) {
9557  deleteInS(j, strat);
9558  }
9559 
9560  pos = posInS(strat, strat->sl, p.p, p.ecart);
9561 
9562  pp_Test(p.p, currRing, p.tailRing);
9563  assume(p.FDeg == p.pFDeg());
9564 
9565  /* remove useless pairs from L set */
9566  for (i = 0; i <= strat->Ll; ++i) {
9567  if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0) {
9568  deleteInL(strat->L, &(strat->Ll), i, strat);
9569  i--;
9570  continue;
9571  }
9572  if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0) {
9573  deleteInL(strat->L, &(strat->Ll), i, strat);
9574  i--;
9575  }
9576  }
9577  /* generate new pairs with p, probably removing older, now useless pairs */
9578  superenterpairs(p.p, strat->sl, p.ecart, pos, strat, strat->tl);
9579  /* enter p to S set */
9580  strat->enterS(p, pos, strat, strat->tl);
9581 }
9582 
9583 /*2
9584 * puts p to the set T at position atT
9585 */
9586 void enterT(LObject &p, kStrategy strat, int atT)
9587 {
9588  int i;
9589 
9590 #ifdef PDEBUG
9591 #ifdef HAVE_SHIFTBBA
9592  if (currRing->isLPring && p.shift > 0)
9593  {
9594  // in this case, the order is not correct. test LM and tail separately
9595  p_LmTest(p.p, currRing);
9596  p_Test(pNext(p.p), currRing);
9597  }
9598  else
9599 #endif
9600  {
9601  pp_Test(p.p, currRing, p.tailRing);
9602  }
9603 #endif
9604  assume(strat->tailRing == p.tailRing);
9605  // redMoraNF complains about this -- but, we don't really
9606  // neeed this so far
9607  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9608  assume(p.FDeg == p.pFDeg());
9609  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9610 
9611 #ifdef KDEBUG
9612  // do not put an LObject twice into T:
9613  for(i=strat->tl;i>=0;i--)
9614  {
9615  if (p.p==strat->T[i].p)
9616  {
9617  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9618  return;
9619  }
9620  }
9621 #endif
9622 
9623 #ifdef HAVE_TAIL_RING
9624  if (currRing!=strat->tailRing)
9625  {
9626  p.t_p=p.GetLmTailRing();
9627  }
9628 #endif
9629  strat->newt = TRUE;
9630  if (atT < 0)
9631  atT = strat->posInT(strat->T, strat->tl, p);
9632  if (strat->tl == strat->tmax-1)
9633  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9634  if (atT <= strat->tl)
9635  {
9636 #ifdef ENTER_USE_MEMMOVE
9637  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9638  (strat->tl-atT+1)*sizeof(TObject));
9639  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9640  (strat->tl-atT+1)*sizeof(unsigned long));
9641 #endif
9642  for (i=strat->tl+1; i>=atT+1; i--)
9643  {
9644 #ifndef ENTER_USE_MEMMOVE
9645  strat->T[i] = strat->T[i-1];
9646  strat->sevT[i] = strat->sevT[i-1];
9647 #endif
9648  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9649  }
9650  }
9651 
9652  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9653  {
9654 #ifdef HAVE_SHIFTBBA
9655  // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9656  if (!(currRing->isLPring && p.shift > 0))
9657 #endif
9658  {
9659  pNext(p.p)=p_ShallowCopyDelete(pNext(p.p),
9660  (strat->tailRing != NULL ?
9661  strat->tailRing : currRing),
9662  strat->tailBin);
9663  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9664  }
9665  }
9666  strat->T[atT] = (TObject) p;
9667  //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9668 
9669  if (pNext(p.p) != NULL)
9670  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9671  else
9672  strat->T[atT].max_exp = NULL;
9673 
9674  strat->tl++;
9675  strat->R[strat->tl] = &(strat->T[atT]);
9676  strat->T[atT].i_r = strat->tl;
9677  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9678  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9679  kTest_T(&(strat->T[atT]));
9680 }
9681 
9682 /*2
9683 * puts p to the set T at position atT
9684 */
9685 #ifdef HAVE_RINGS
9686 void enterT_strong(LObject &p, kStrategy strat, int atT)
9687 {
9689  int i;
9690 
9691  pp_Test(p.p, currRing, p.tailRing);
9692  assume(strat->tailRing == p.tailRing);
9693  // redMoraNF complains about this -- but, we don't really
9694  // neeed this so far
9695  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9696  assume(p.FDeg == p.pFDeg());
9697  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9698 
9699 #ifdef KDEBUG
9700  // do not put an LObject twice into T:
9701  for(i=strat->tl;i>=0;i--)
9702  {
9703  if (p.p==strat->T[i].p)
9704  {
9705  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9706  return;
9707  }
9708  }
9709 #endif
9710 
9711 #ifdef HAVE_TAIL_RING
9712  if (currRing!=strat->tailRing)
9713  {
9714  p.t_p=p.GetLmTailRing();
9715  }
9716 #endif
9717  strat->newt = TRUE;
9718  if (atT < 0)
9719  atT = strat->posInT(strat->T, strat->tl, p);
9720  if (strat->tl == strat->tmax-1)
9721  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9722  if (atT <= strat->tl)
9723  {
9724 #ifdef ENTER_USE_MEMMOVE
9725  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9726  (strat->tl-atT+1)*sizeof(TObject));
9727  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9728  (strat->tl-atT+1)*sizeof(unsigned long));
9729 #endif
9730  for (i=strat->tl+1; i>=atT+1; i--)
9731  {
9732 #ifndef ENTER_USE_MEMMOVE
9733  strat->T[i] = strat->T[i-1];
9734  strat->sevT[i] = strat->sevT[i-1];
9735 #endif
9736  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9737  }
9738  }
9739 
9740  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9741  {
9742  pNext(p.p)=p_ShallowCopyDelete(pNext(p.p),
9743  (strat->tailRing != NULL ?
9744  strat->tailRing : currRing),
9745  strat->tailBin);
9746  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9747  }
9748  strat->T[atT] = (TObject) p;
9749  //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9750 
9751  if (pNext(p.p) != NULL)
9752  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9753  else
9754  strat->T[atT].max_exp = NULL;
9755 
9756  strat->tl++;
9757  strat->R[strat->tl] = &(strat->T[atT]);
9758  strat->T[atT].i_r = strat->tl;
9759  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9760  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9761  #if 1
9763  && !n_IsUnit(p.p->coef, currRing->cf))
9764  {
9765  for(i=strat->tl;i>=0;i--)
9766  {
9767  if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9768  {
9769  enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9770  }
9771  }
9772  }
9773  /*
9774  printf("\nThis is T:\n");
9775  for(i=strat->tl;i>=0;i--)
9776  {
9777  pWrite(strat->T[i].p);
9778  }
9779  //getchar();*/
9780  #endif
9781  kTest_T(&(strat->T[atT]));
9782 }
9783 #endif
9784 
9785 /*2
9786 * puts signature p.sig to the set syz
9787 */
9788 void enterSyz(LObject &p, kStrategy strat, int atT)
9789 {
9790  int i;
9791  strat->newt = TRUE;
9792  if (strat->syzl == strat->syzmax-1)
9793  {
9794  pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9795  strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9796  (strat->syzmax)*sizeof(unsigned long),
9797  ((strat->syzmax)+setmax)
9798  *sizeof(unsigned long));
9799  strat->syzmax += setmax;
9800  }
9801  if (atT < strat->syzl)
9802  {
9803 #ifdef ENTER_USE_MEMMOVE
9804  memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9805  (strat->syzl-atT+1)*sizeof(poly));
9806  memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9807  (strat->syzl-atT+1)*sizeof(unsigned long));
9808 #endif
9809  for (i=strat->syzl; i>=atT+1; i--)
9810  {
9811 #ifndef ENTER_USE_MEMMOVE
9812  strat->syz[i] = strat->syz[i-1];
9813  strat->sevSyz[i] = strat->sevSyz[i-1];
9814 #endif
9815  }
9816  }
9817  //i = strat->syzl;
9818  i = atT;
9819  //Makes sure the syz saves just the signature
9820  #ifdef HAVE_RINGS
9822  pNext(p.sig) = NULL;
9823  #endif
9824  strat->syz[atT] = p.sig;
9825  strat->sevSyz[atT] = p.sevSig;
9826  strat->syzl++;
9827 #if F5DEBUG
9828  Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9829  pWrite(strat->syz[atT]);
9830 #endif
9831  // recheck pairs in strat->L with new rule and delete correspondingly
9832  int cc = strat->Ll;
9833  while (cc>-1)
9834  {
9835  //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9836  //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);
9837  if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9838  strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9839  #ifdef HAVE_RINGS
9840  &&((!rField_is_Ring(currRing))
9841  || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9842  #endif
9843  )
9844  {
9845  //printf("\nYES!\n");
9846  deleteInL(strat->L,&strat->Ll,cc,strat);
9847  }
9848  cc--;
9849  }
9850 //#if 1
9851 #ifdef DEBUGF5
9852  PrintS("--- Syzygies ---\n");
9853  Print("syzl %d\n",strat->syzl);
9854  Print("syzmax %d\n",strat->syzmax);
9855  PrintS("--------------------------------\n");
9856  for(i=0;i<=strat->syzl-1;i++)
9857  {
9858  Print("%d - ",i);
9859  pWrite(strat->syz[i]);
9860  }
9861  PrintS("--------------------------------\n");
9862 #endif
9863 }
9864 
9865 
9866 void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9867 {
9868 
9869  //if the ordering is local, then hilb criterion
9870  //can be used also if the ideal is not homogenous
9872  {
9874  *hilb=NULL;
9875  else
9876  return;
9877  }
9878  if (strat->homog!=isHomog)
9879  {
9880  *hilb=NULL;
9881  }
9882 }
9883 
9885 {
9887  strat->chainCrit=chainCritNormal;
9888  if (TEST_OPT_SB_1)
9889  strat->chainCrit=chainCritOpt_1;
9890 #ifdef HAVE_RINGS
9891  if (rField_is_Ring(currRing))
9892  {
9894  strat->chainCrit=chainCritRing;
9895  }
9896 #endif
9897 #ifdef HAVE_RATGRING
9898  if (rIsRatGRing(currRing))
9899  {
9900  strat->chainCrit=chainCritPart;
9901  /* enterOnePairNormal get rational part in it */
9902  }
9903 #endif
9904  if (TEST_OPT_IDLIFT /* i.e. also strat->syzComp==1 */
9905  && (!rIsPluralRing(currRing)))
9907 
9908  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9909  strat->Gebauer = strat->homog || strat->sugarCrit;
9910  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9911  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9912  strat->pairtest = NULL;
9913  /* alway use tailreduction, except:
9914  * - in local rings, - in lex order case, -in ring over extensions */
9916  //if(rHasMixedOrdering(currRing)==2)
9917  //{
9918  // strat->noTailReduction =TRUE;
9919  //}
9920 
9921 #ifdef HAVE_PLURAL
9922  // and r is plural_ring
9923  // hence this holds for r a rational_plural_ring
9924  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9925  { //or it has non-quasi-comm type... later
9926  strat->sugarCrit = FALSE;
9927  strat->Gebauer = FALSE;
9928  strat->honey = FALSE;
9929  }
9930 #endif
9931 
9932  // Coefficient ring?
9933  if (rField_is_Ring(currRing))
9934  {
9935  strat->sugarCrit = FALSE;
9936  strat->Gebauer = FALSE ;
9937  strat->honey = FALSE;
9938  }
9939  #ifdef KDEBUG
9940  if (TEST_OPT_DEBUG)
9941  {
9942  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9943  else PrintS("ideal/module is not homogeneous\n");
9944  }
9945  #endif
9946 }
9947 
9949 {
9950  //strat->enterOnePair=enterOnePairNormal;
9952  //strat->chainCrit=chainCritNormal;
9953  strat->chainCrit = chainCritSig;
9954  /******************************************
9955  * rewCrit1 and rewCrit2 are already set in
9956  * kSba() in kstd1.cc
9957  *****************************************/
9958  //strat->rewCrit1 = faugereRewCriterion;
9959  if (strat->sbaOrder == 1)
9960  {
9961  strat->syzCrit = syzCriterionInc;
9962  }
9963  else
9964  {
9965  strat->syzCrit = syzCriterion;
9966  }
9967 #ifdef HAVE_RINGS
9968  if (rField_is_Ring(currRing))
9969  {
9971  strat->chainCrit=chainCritRing;
9972  }
9973 #endif
9974 #ifdef HAVE_RATGRING
9975  if (rIsRatGRing(currRing))
9976  {
9977  strat->chainCrit=chainCritPart;
9978  /* enterOnePairNormal get rational part in it */
9979  }
9980 #endif
9981 
9982  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9983  strat->Gebauer = strat->homog || strat->sugarCrit;
9984  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9985  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9986  strat->pairtest = NULL;
9987  /* alway use tailreduction, except:
9988  * - in local rings, - in lex order case, -in ring over extensions */
9991 
9992 #ifdef HAVE_PLURAL
9993  // and r is plural_ring
9994  // hence this holds for r a rational_plural_ring
9995  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9996  { //or it has non-quasi-comm type... later
9997  strat->sugarCrit = FALSE;
9998  strat->Gebauer = FALSE;
9999  strat->honey = FALSE;
10000  }
10001 #endif
10002 
10003  // Coefficient ring?
10004  if (rField_is_Ring(currRing))
10005  {
10006  strat->sugarCrit = FALSE;
10007  strat->Gebauer = FALSE ;
10008  strat->honey = FALSE;
10009  }
10010  #ifdef KDEBUG
10011  if (TEST_OPT_DEBUG)
10012  {
10013  if (strat->homog) PrintS("ideal/module is homogeneous\n");
10014  else PrintS("ideal/module is not homogeneous\n");
10015  }
10016  #endif
10017 }
10018 
10020  (const LSet set, const int length,
10021  LObject* L,const kStrategy strat))
10022 {
10023  if (pos_in_l == posInL110
10024  || pos_in_l == posInL10
10025  #ifdef HAVE_RINGS
10026  || pos_in_l == posInL110Ring
10027  || pos_in_l == posInLRing
10028  #endif
10029  )
10030  return TRUE;
10031 
10032  return FALSE;
10033 }
10034 
10036 {
10038  {
10039  if (strat->honey)
10040  {
10041  strat->posInL = posInL15;
10042  // ok -- here is the deal: from my experiments for Singular-2-0
10043  // I conclude that that posInT_EcartpLength is the best of
10044  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10045  // see the table at the end of this file
10046  if (TEST_OPT_OLDSTD)
10047  strat->posInT = posInT15;
10048  else
10049  strat->posInT = posInT_EcartpLength;
10050  }
10051  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10052  {
10053  strat->posInL = posInL11;
10054  strat->posInT = posInT11;
10055  }
10056  else if (TEST_OPT_INTSTRATEGY)
10057  {
10058  strat->posInL = posInL11;
10059  strat->posInT = posInT11;
10060  }
10061  else
10062  {
10063  strat->posInL = posInL0;
10064  strat->posInT = posInT0;
10065  }
10066  //if (strat->minim>0) strat->posInL =posInLSpecial;
10067  if (strat->homog)
10068  {
10069  strat->posInL = posInL110;
10070  strat->posInT = posInT110;
10071  }
10072  }
10073  else
10074  {
10075  if (strat->homog)
10076  {
10077  strat->posInL = posInL11;
10078  strat->posInT = posInT11;
10079  }
10080  else
10081  {
10082  if ((currRing->order[0]==ringorder_c)
10083  ||(currRing->order[0]==ringorder_C))
10084  {
10085  strat->posInL = posInL17_c;
10086  strat->posInT = posInT17_c;
10087  }
10088  else
10089  {
10090  strat->posInL = posInL17;
10091  strat->posInT = posInT17;
10092  }
10093  }
10094  }
10095  if (strat->minim>0) strat->posInL =posInLSpecial;
10096  // for further tests only
10097  if ((BTEST1(11)) || (BTEST1(12)))
10098  strat->posInL = posInL11;
10099  else if ((BTEST1(13)) || (BTEST1(14)))
10100  strat->posInL = posInL13;
10101  else if ((BTEST1(15)) || (BTEST1(16)))
10102  strat->posInL = posInL15;
10103  else if ((BTEST1(17)) || (BTEST1(18)))
10104  strat->posInL = posInL17;
10105  if (BTEST1(11))
10106  strat->posInT = posInT11;
10107  else if (BTEST1(13))
10108  strat->posInT = posInT13;
10109  else if (BTEST1(15))
10110  strat->posInT = posInT15;
10111  else if ((BTEST1(17)))
10112  strat->posInT = posInT17;
10113  else if ((BTEST1(19)))
10114  strat->posInT = posInT19;
10115  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10116  strat->posInT = posInT1;
10118 }
10119 
10120 #ifdef HAVE_RINGS
10122 {
10124  {
10125  if (strat->honey)
10126  {
10127  strat->posInL = posInL15Ring;
10128  // ok -- here is the deal: from my experiments for Singular-2-0
10129  // I conclude that that posInT_EcartpLength is the best of
10130  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10131  // see the table at the end of this file
10132  if (TEST_OPT_OLDSTD)
10133  strat->posInT = posInT15Ring;
10134  else
10135  strat->posInT = posInT_EcartpLength;
10136  }
10137  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10138  {
10139  strat->posInL = posInL11Ring;
10140  strat->posInT = posInT11;
10141  }
10142  else if (TEST_OPT_INTSTRATEGY)
10143  {
10144  strat->posInL = posInL11Ring;
10145  strat->posInT = posInT11;
10146  }
10147  else
10148  {
10149  strat->posInL = posInL0Ring;
10150  strat->posInT = posInT0;
10151  }
10152  //if (strat->minim>0) strat->posInL =posInLSpecial;
10153  if (strat->homog)
10154  {
10155  strat->posInL = posInL110Ring;
10156  strat->posInT = posInT110Ring;
10157  }
10158  }
10159  else
10160  {
10161  if (strat->homog)
10162  {
10163  //printf("\nHere 3\n");
10164  strat->posInL = posInL11Ring;
10165  strat->posInT = posInT11Ring;
10166  }
10167  else
10168  {
10169  if ((currRing->order[0]==ringorder_c)
10170  ||(currRing->order[0]==ringorder_C))
10171  {
10172  strat->posInL = posInL17_cRing;
10173  strat->posInT = posInT17_cRing;
10174  }
10175  else
10176  {
10177  strat->posInL = posInL11Ringls;
10178  strat->posInT = posInT17Ring;
10179  }
10180  }
10181  }
10182  if (strat->minim>0) strat->posInL =posInLSpecial;
10183  // for further tests only
10184  if ((BTEST1(11)) || (BTEST1(12)))
10185  strat->posInL = posInL11Ring;
10186  else if ((BTEST1(13)) || (BTEST1(14)))
10187  strat->posInL = posInL13;
10188  else if ((BTEST1(15)) || (BTEST1(16)))
10189  strat->posInL = posInL15Ring;
10190  else if ((BTEST1(17)) || (BTEST1(18)))
10191  strat->posInL = posInL17Ring;
10192  if (BTEST1(11))
10193  strat->posInT = posInT11Ring;
10194  else if (BTEST1(13))
10195  strat->posInT = posInT13;
10196  else if (BTEST1(15))
10197  strat->posInT = posInT15Ring;
10198  else if ((BTEST1(17)))
10199  strat->posInT = posInT17Ring;
10200  else if ((BTEST1(19)))
10201  strat->posInT = posInT19;
10202  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10203  strat->posInT = posInT1;
10205 }
10206 #endif
10207 
10208 void initBuchMora (ideal F,ideal Q,kStrategy strat)
10209 {
10210  strat->interpt = BTEST1(OPT_INTERRUPT);
10211  strat->kHEdge=NULL;
10213  /*- creating temp data structures------------------- -*/
10214  strat->cp = 0;
10215  strat->c3 = 0;
10216 #ifdef HAVE_SHIFTBBA
10217  strat->cv = 0;
10218 #endif
10219  strat->tail = pInit();
10220  /*- set s -*/
10221  strat->sl = -1;
10222  /*- set L -*/
10223  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10224  strat->Ll = -1;
10225  strat->L = initL(strat->Lmax);
10226  /*- set B -*/
10227  strat->Bmax = setmaxL;
10228  strat->Bl = -1;
10229  strat->B = initL();
10230  /*- set T -*/
10231  strat->tl = -1;
10232  strat->tmax = setmaxT;
10233  strat->T = initT();
10234  strat->R = initR();
10235  strat->sevT = initsevT();
10236  /*- init local data struct.---------------------------------------- -*/
10237  strat->P.ecart=0;
10238  strat->P.length=0;
10239  strat->P.pLength=0;
10241  {
10242  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
10243  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
10244  }
10246  {
10247  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10248  }
10249  else
10250  {
10251  if(TEST_OPT_SB_1)
10252  {
10253  int i;
10254  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10255  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10256  {
10257  P->m[i-strat->newIdeal] = F->m[i];
10258  F->m[i] = NULL;
10259  }
10260  initSSpecial(F,Q,P,strat);
10261  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10262  {
10263  F->m[i] = P->m[i-strat->newIdeal];
10264  P->m[i-strat->newIdeal] = NULL;
10265  }
10266  idDelete(&P);
10267  }
10268  else
10269  {
10270  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10271  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
10272  }
10273  }
10274  strat->fromT = FALSE;
10276  if ((!TEST_OPT_SB_1)
10277  || (rField_is_Ring(currRing))
10278  )
10279  {
10280  updateS(TRUE,strat);
10281  }
10282 #ifdef HAVE_SHIFTBBA
10283  if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
10284 #endif
10285  {
10286  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10287  strat->fromQ=NULL;
10288  }
10289  assume(kTest_TS(strat));
10290 }
10291 
10293 {
10294  /*- release temp data -*/
10295  cleanT(strat);
10296  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10297  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10298  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10299  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10300  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10301  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10302  /*- set L: should be empty -*/
10303  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10304  /*- set B: should be empty -*/
10305  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10306  pLmFree(&strat->tail);
10307  strat->syzComp=0;
10308 
10309 #ifdef HAVE_SHIFTBBA
10310  if (rIsLPRing(currRing) && strat->rightGB)
10311  {
10312  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10313  strat->fromQ=NULL;
10314  }
10315 #endif
10316 }
10317 
10318 void initSbaPos (kStrategy strat)
10319 {
10321  {
10322  if (strat->honey)
10323  {
10324  strat->posInL = posInL15;
10325  // ok -- here is the deal: from my experiments for Singular-2-0
10326  // I conclude that that posInT_EcartpLength is the best of
10327  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10328  // see the table at the end of this file
10329  if (TEST_OPT_OLDSTD)
10330  strat->posInT = posInT15;
10331  else
10332  strat->posInT = posInT_EcartpLength;
10333  }
10334  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10335  {
10336  strat->posInL = posInL11;
10337  strat->posInT = posInT11;
10338  }
10339  else if (TEST_OPT_INTSTRATEGY)
10340  {
10341  strat->posInL = posInL11;
10342  strat->posInT = posInT11;
10343  }
10344  else
10345  {
10346  strat->posInL = posInL0;
10347  strat->posInT = posInT0;
10348  }
10349  //if (strat->minim>0) strat->posInL =posInLSpecial;
10350  if (strat->homog)
10351  {
10352  strat->posInL = posInL110;
10353  strat->posInT = posInT110;
10354  }
10355  }
10356  else
10357  {
10358  if (strat->homog)
10359  {
10360  strat->posInL = posInL11;
10361  strat->posInT = posInT11;
10362  }
10363  else
10364  {
10365  if ((currRing->order[0]==ringorder_c)
10366  ||(currRing->order[0]==ringorder_C))
10367  {
10368  strat->posInL = posInL17_c;
10369  strat->posInT = posInT17_c;
10370  }
10371  else
10372  {
10373  strat->posInL = posInL17;
10374  strat->posInT = posInT17;
10375  }
10376  }
10377  }
10378  if (strat->minim>0) strat->posInL =posInLSpecial;
10379  // for further tests only
10380  if ((BTEST1(11)) || (BTEST1(12)))
10381  strat->posInL = posInL11;
10382  else if ((BTEST1(13)) || (BTEST1(14)))
10383  strat->posInL = posInL13;
10384  else if ((BTEST1(15)) || (BTEST1(16)))
10385  strat->posInL = posInL15;
10386  else if ((BTEST1(17)) || (BTEST1(18)))
10387  strat->posInL = posInL17;
10388  if (BTEST1(11))
10389  strat->posInT = posInT11;
10390  else if (BTEST1(13))
10391  strat->posInT = posInT13;
10392  else if (BTEST1(15))
10393  strat->posInT = posInT15;
10394  else if ((BTEST1(17)))
10395  strat->posInT = posInT17;
10396  else if ((BTEST1(19)))
10397  strat->posInT = posInT19;
10398  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10399  strat->posInT = posInT1;
10400  if (rField_is_Ring(currRing))
10401  {
10402  strat->posInL = posInL11Ring;
10403  if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
10404  strat->posInL = posInL11Ringls;
10405  strat->posInT = posInT11;
10406  }
10407  strat->posInLDependsOnLength = FALSE;
10408  strat->posInLSba = posInLSig;
10409  //strat->posInL = posInLSig;
10410  strat->posInL = posInLF5C;
10411  /*
10412  if (rField_is_Ring(currRing))
10413  {
10414  strat->posInLSba = posInLSigRing;
10415  strat->posInL = posInL11Ring;
10416  }*/
10417  //strat->posInT = posInTSig;
10418 }
10419 
10420 void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10421 {
10422  strat->interpt = BTEST1(OPT_INTERRUPT);
10423  strat->kHEdge=NULL;
10425  /*- creating temp data structures------------------- -*/
10426  strat->cp = 0;
10427  strat->c3 = 0;
10428  strat->tail = pInit();
10429  /*- set s -*/
10430  strat->sl = -1;
10431  /*- set ps -*/
10432  strat->syzl = -1;
10433  /*- set L -*/
10434  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10435  strat->Ll = -1;
10436  strat->L = initL(strat->Lmax);
10437  /*- set B -*/
10438  strat->Bmax = setmaxL;
10439  strat->Bl = -1;
10440  strat->B = initL();
10441  /*- set T -*/
10442  strat->tl = -1;
10443  strat->tmax = setmaxT;
10444  strat->T = initT();
10445  strat->R = initR();
10446  strat->sevT = initsevT();
10447  /*- init local data struct.---------------------------------------- -*/
10448  strat->P.ecart=0;
10449  strat->P.length=0;
10451  {
10452  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
10453  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
10454  }
10456  {
10457  /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10458  }
10459  else
10460  {
10461  if(TEST_OPT_SB_1)
10462  {
10463  int i;
10464  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10465  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10466  {
10467  P->m[i-strat->newIdeal] = F->m[i];
10468  F->m[i] = NULL;
10469  }
10470  initSSpecialSba(F,Q,P,strat);
10471  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10472  {
10473  F->m[i] = P->m[i-strat->newIdeal];
10474  P->m[i-strat->newIdeal] = NULL;
10475  }
10476  idDelete(&P);
10477  }
10478  else
10479  {
10480  initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10481  }
10482  }
10483  strat->fromT = FALSE;
10484  if (!TEST_OPT_SB_1)
10485  {
10486  if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10487  }
10488  //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10489  //strat->fromQ=NULL;
10490  assume(kTest_TS(strat));
10491 }
10492 
10493 void exitSba (kStrategy strat)
10494 {
10495  /*- release temp data -*/
10497  cleanTSbaRing(strat);
10498  else
10499  cleanT(strat);
10500  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10501  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10502  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10503  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10504  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10505  omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10506  if(strat->syzmax>0)
10507  {
10508  omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10509  omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10510  if (strat->sbaOrder == 1)
10511  {
10512  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10513  }
10514  }
10515  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10516  /*- set L: should be empty -*/
10517  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10518  /*- set B: should be empty -*/
10519  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10520  /*- set sig: no need for the signatures anymore -*/
10521  omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10522  pLmDelete(&strat->tail);
10523  strat->syzComp=0;
10524 }
10525 
10526 /*2
10527 * in the case of a standardbase of a module over a qring:
10528 * replace polynomials in i by ak vectors,
10529 * (the polynomial * unit vectors gen(1)..gen(ak)
10530 * in every case (also for ideals:)
10531 * deletes divisible vectors/polynomials
10532 */
10533 void updateResult(ideal r,ideal Q, kStrategy strat)
10534 {
10535  int l;
10536  if (strat->ak>0)
10537  {
10538  for (l=IDELEMS(r)-1;l>=0;l--)
10539  {
10540  if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10541  {
10542  pDelete(&r->m[l]); // and set it to NULL
10543  }
10544  }
10545  int q;
10546  poly p;
10547  if(!rField_is_Ring(currRing))
10548  {
10549  for (l=IDELEMS(r)-1;l>=0;l--)
10550  {
10551  if ((r->m[l]!=NULL)
10552  //&& (strat->syzComp>0)
10553  //&& (pGetComp(r->m[l])<=strat->syzComp)
10554  )
10555  {
10556  for(q=IDELEMS(Q)-1; q>=0;q--)
10557  {
10558  if ((Q->m[q]!=NULL)
10559  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10560  {
10561  if (TEST_OPT_REDSB)
10562  {
10563  p=r->m[l];
10564  r->m[l]=kNF(Q,NULL,p);
10565  pDelete(&p);
10566  }
10567  else
10568  {
10569  pDelete(&r->m[l]); // and set it to NULL
10570  }
10571  break;
10572  }
10573  }
10574  }
10575  }
10576  }
10577  #ifdef HAVE_RINGS
10578  else
10579  {
10580  for (l=IDELEMS(r)-1;l>=0;l--)
10581  {
10582  if ((r->m[l]!=NULL)
10583  //&& (strat->syzComp>0)
10584  //&& (pGetComp(r->m[l])<=strat->syzComp)
10585  )
10586  {
10587  for(q=IDELEMS(Q)-1; q>=0;q--)
10588  {
10589  if ((Q->m[q]!=NULL)
10590  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10591  {
10592  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10593  {
10594  if (TEST_OPT_REDSB)
10595  {
10596  p=r->m[l];
10597  r->m[l]=kNF(Q,NULL,p);
10598  pDelete(&p);
10599  }
10600  else
10601  {
10602  pDelete(&r->m[l]); // and set it to NULL
10603  }
10604  break;
10605  }
10606  }
10607  }
10608  }
10609  }
10610  }
10611  #endif
10612  }
10613  else
10614  {
10615  int q;
10616  poly p;
10617  BOOLEAN reduction_found=FALSE;
10618  if (!rField_is_Ring(currRing))
10619  {
10620  for (l=IDELEMS(r)-1;l>=0;l--)
10621  {
10622  if (r->m[l]!=NULL)
10623  {
10624  for(q=IDELEMS(Q)-1; q>=0;q--)
10625  {
10626  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10627  {
10628  if (TEST_OPT_REDSB)
10629  {
10630  p=r->m[l];
10631  r->m[l]=kNF(Q,NULL,p);
10632  pDelete(&p);
10633  reduction_found=TRUE;
10634  }
10635  else
10636  {
10637  pDelete(&r->m[l]); // and set it to NULL
10638  }
10639  break;
10640  }
10641  }
10642  }
10643  }
10644  }
10645  #ifdef HAVE_RINGS
10646  //Also need divisibility of the leading coefficients
10647  else
10648  {
10649  for (l=IDELEMS(r)-1;l>=0;l--)
10650  {
10651  if (r->m[l]!=NULL)
10652  {
10653  for(q=IDELEMS(Q)-1; q>=0;q--)
10654  {
10655  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10656  {
10657  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10658  {
10659  if (TEST_OPT_REDSB)
10660  {
10661  p=r->m[l];
10662  r->m[l]=kNF(Q,NULL,p);
10663  pDelete(&p);
10664  reduction_found=TRUE;
10665  }
10666  else
10667  {
10668  pDelete(&r->m[l]); // and set it to NULL
10669  }
10670  break;
10671  }
10672  }
10673  }
10674  }
10675  }
10676  }
10677  #endif
10678  if (/*TEST_OPT_REDSB &&*/ reduction_found)
10679  {
10680  #ifdef HAVE_RINGS
10682  {
10683  for (l=IDELEMS(r)-1;l>=0;l--)
10684  {
10685  if (r->m[l]!=NULL)
10686  {
10687  for(q=IDELEMS(r)-1;q>=0;q--)
10688  {
10689  if ((l!=q)
10690  && (r->m[q]!=NULL)
10691  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10692  &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10693  )
10694  {
10695  //If they are equal then take the one with the smallest length
10696  if(pLmDivisibleBy(r->m[q],r->m[l])
10697  && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10698  && (pLength(r->m[q]) < pLength(r->m[l]) ||
10699  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10700  {
10701  pDelete(&r->m[l]);
10702  break;
10703  }
10704  else
10705  pDelete(&r->m[q]);
10706  }
10707  }
10708  }
10709  }
10710  }
10711  else
10712  #endif
10713  {
10714  for (l=IDELEMS(r)-1;l>=0;l--)
10715  {
10716  if (r->m[l]!=NULL)
10717  {
10718  for(q=IDELEMS(r)-1;q>=0;q--)
10719  {
10720  if ((l!=q)
10721  && (r->m[q]!=NULL)
10722  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10723  )
10724  {
10725  //If they are equal then take the one with the smallest length
10726  if(pLmDivisibleBy(r->m[q],r->m[l])
10727  &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10728  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10729  {
10730  pDelete(&r->m[l]);
10731  break;
10732  }
10733  else
10734  pDelete(&r->m[q]);
10735  }
10736  }
10737  }
10738  }
10739  }
10740  }
10741  }
10742  idSkipZeroes(r);
10743 }
10744 
10745 void completeReduce (kStrategy strat, BOOLEAN withT)
10746 {
10747  int i;
10748  int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10749  LObject L;
10750 
10751 #ifdef KDEBUG
10752  // need to set this: during tailreductions of T[i], T[i].max is out of
10753  // sync
10754  sloppy_max = TRUE;
10755 #endif
10756 
10757  strat->noTailReduction = FALSE;
10758  //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10759  if (TEST_OPT_PROT)
10760  {
10761  PrintLn();
10762 // if (timerv) writeTime("standard base computed:");
10763  }
10764  if (TEST_OPT_PROT)
10765  {
10766  Print("(S:%d)",strat->sl);mflush();
10767  }
10768  for (i=strat->sl; i>=low; i--)
10769  {
10770  int end_pos=strat->sl;
10771  if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10772  if (strat->ak==0) end_pos=i-1;
10773  TObject* T_j = strat->s_2_t(i);
10774  if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10775  {
10776  L = *T_j;
10777  #ifdef KDEBUG
10778  if (TEST_OPT_DEBUG)
10779  {
10780  Print("test S[%d]:",i);
10781  p_wrp(L.p,currRing,strat->tailRing);
10782  PrintLn();
10783  }
10784  #endif
10786  strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10787  else
10788  strat->S[i] = redtail(&L, strat->sl, strat);
10789  #ifdef KDEBUG
10790  if (TEST_OPT_DEBUG)
10791  {
10792  Print("to (tailR) S[%d]:",i);
10793  p_wrp(strat->S[i],currRing,strat->tailRing);
10794  PrintLn();
10795  }
10796  #endif
10797 
10798  if (strat->redTailChange)
10799  {
10800  if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10801  if (pNext(T_j->p) != NULL)
10802  T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10803  else
10804  T_j->max_exp = NULL;
10805  }
10807  T_j->pCleardenom();
10808  }
10809  else
10810  {
10811  assume(currRing == strat->tailRing);
10812  #ifdef KDEBUG
10813  if (TEST_OPT_DEBUG)
10814  {
10815  Print("test S[%d]:",i);
10816  p_wrp(strat->S[i],currRing,strat->tailRing);
10817  PrintLn();
10818  }
10819  #endif
10821  strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10822  else
10823  strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10825  {
10826  if (TEST_OPT_CONTENTSB)
10827  {
10828  number n;
10829  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10830  if (!nIsOne(n))
10831  {
10833  denom->n=nInvers(n);
10834  denom->next=DENOMINATOR_LIST;
10835  DENOMINATOR_LIST=denom;
10836  }
10837  nDelete(&n);
10838  }
10839  else
10840  {
10841  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10842  }
10843  }
10844  #ifdef KDEBUG
10845  if (TEST_OPT_DEBUG)
10846  {
10847  Print("to (-tailR) S[%d]:",i);
10848  p_wrp(strat->S[i],currRing,strat->tailRing);
10849  PrintLn();
10850  }
10851  #endif
10852  }
10853  if (TEST_OPT_PROT)
10854  PrintS("-");
10855  }
10856  if (TEST_OPT_PROT) PrintLn();
10857 #ifdef KDEBUG
10858  sloppy_max = FALSE;
10859 #endif
10860 }
10861 
10862 
10863 /*2
10864 * computes the new strat->kHEdge and the new pNoether,
10865 * returns TRUE, if pNoether has changed
10866 */
10868 {
10869  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10870  return FALSE;
10871  int i,j;
10872  poly newNoether;
10873 
10874 #if 0
10875  if (currRing->weight_all_1)
10876  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10877  else
10878  scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10879 #else
10880  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10881 #endif
10882  if (strat->kHEdge==NULL) return FALSE;
10883  if (strat->t_kHEdge != NULL) p_LmFree(strat->t_kHEdge, strat->tailRing);
10884  if (strat->tailRing != currRing)
10885  strat->t_kHEdge = k_LmInit_currRing_2_tailRing(strat->kHEdge, strat->tailRing);
10886  /* compare old and new noether*/
10887  newNoether = pLmInit(strat->kHEdge);
10888  pSetCoeff0(newNoether,nInit(1));
10889  j = p_FDeg(newNoether,currRing);
10890  for (i=1; i<=(currRing->N); i++)
10891  {
10892  if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
10893  }
10894  pSetm(newNoether);
10895  if (j < strat->HCord) /*- statistics -*/
10896  {
10897  if (TEST_OPT_PROT)
10898  {
10899  Print("H(%d)",j);
10900  mflush();
10901  }
10902  strat->HCord=j;
10903  #ifdef KDEBUG
10904  if (TEST_OPT_DEBUG)
10905  {
10906  Print("H(%d):",j);
10907  wrp(strat->kHEdge);
10908  PrintLn();
10909  }
10910  #endif
10911  }
10912  if (pCmp(strat->kNoether,newNoether)!=1)
10913  {
10914  if (strat->kNoether!=NULL) pLmDelete(&strat->kNoether);
10915  strat->kNoether=newNoether;
10916  if (strat->t_kNoether != NULL) p_LmFree(strat->t_kNoether, strat->tailRing);
10917  if (strat->tailRing != currRing)
10918  strat->t_kNoether = k_LmInit_currRing_2_tailRing(strat->kNoether, strat->tailRing);
10919 
10920  return TRUE;
10921  }
10922  pLmDelete(newNoether);
10923  return FALSE;
10924 }
10925 
10926 /***************************************************************
10927  *
10928  * Routines related for ring changes during std computations
10929  *
10930  ***************************************************************/
10931 BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10932 {
10933  if (strat->overflow) return FALSE;
10934  assume(L->p1 != NULL && L->p2 != NULL);
10935  // shift changes: from 0 to -1
10936  assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10937  assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10938  assume(strat->tailRing != currRing);
10939 
10940  if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10941  return FALSE;
10942  // shift changes: extra case inserted
10943  if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10944  {
10945  return TRUE;
10946  }
10947  poly p1_max=NULL;
10948  if (L->i_r1>=0) p1_max = (strat->R[L->i_r1])->max_exp;
10949  poly p2_max=NULL;
10950  if (L->i_r2>=0) p2_max = (strat->R[L->i_r2])->max_exp;
10951 
10952  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10953  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10954  {
10955  p_LmFree(m1, strat->tailRing);
10956  p_LmFree(m2, strat->tailRing);
10957  m1 = NULL;
10958  m2 = NULL;
10959  return FALSE;
10960  }
10961  return TRUE;
10962 }
10963 
10964 #ifdef HAVE_RINGS
10965 /***************************************************************
10966  *
10967  * Checks, if we can compute the gcd poly / strong pair
10968  * gcd-poly = m1 * R[atR] + m2 * S[atS]
10969  *
10970  ***************************************************************/
10971 BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10972 {
10973  assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10974  //assume(strat->tailRing != currRing);
10975 
10976  poly p1_max = (strat->R[atR])->max_exp;
10977  poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10978 
10979  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10980  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10981  {
10982  return FALSE;
10983  }
10984  return TRUE;
10985 }
10986 #endif
10987 
10988 #ifdef HAVE_RINGS
10989 /*!
10990  used for GB over ZZ: look for constant and monomial elements in the ideal
10991  background: any known constant element of ideal suppresses
10992  intermediate coefficient swell
10993 */
10994 poly preIntegerCheck(const ideal Forig, const ideal Q)
10995 {
10996  if(!nCoeff_is_Z(currRing->cf))
10997  return NULL;
10998  ideal F = idCopy(Forig);
10999  idSkipZeroes(F);
11000  poly pmon;
11001  ring origR = currRing;
11002  ideal monred = idInit(1,1);
11003  for(int i=0; i<idElem(F); i++)
11004  {
11005  if(pNext(F->m[i]) == NULL)
11006  idInsertPoly(monred, pCopy(F->m[i]));
11007  }
11008  int posconst = idPosConstant(F);
11009  if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
11010  {
11011  idDelete(&F);
11012  idDelete(&monred);
11013  return NULL;
11014  }
11015  int idelemQ = 0;
11016  if(Q!=NULL)
11017  {
11018  idelemQ = IDELEMS(Q);
11019  for(int i=0; i<idelemQ; i++)
11020  {
11021  if(pNext(Q->m[i]) == NULL)
11022  idInsertPoly(monred, pCopy(Q->m[i]));
11023  }
11024  idSkipZeroes(monred);
11025  posconst = idPosConstant(monred);
11026  //the constant, if found, will be from Q
11027  if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
11028  {
11029  pmon = pCopy(monred->m[posconst]);
11030  idDelete(&F);
11031  idDelete(&monred);
11032  return pmon;
11033  }
11034  }
11035  ring QQ_ring = rCopy0(currRing,FALSE);
11036  nKillChar(QQ_ring->cf);
11037  QQ_ring->cf = nInitChar(n_Q, NULL);
11038  rComplete(QQ_ring,1);
11039  QQ_ring = rAssure_c_dp(QQ_ring);
11040  rChangeCurrRing(QQ_ring);
11041  nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
11042  ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
11043  for(int i = 0, j = 0; i<IDELEMS(F); i++)
11044  II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
11045  for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
11046  II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
11047  ideal one = kStd(II, NULL, isNotHomog, NULL);
11048  idSkipZeroes(one);
11049  if(idIsConstant(one))
11050  {
11051  //one should be <1>
11052  for(int i = IDELEMS(II)-1; i>=0; i--)
11053  if(II->m[i] != NULL)
11054  II->m[i+1] = II->m[i];
11055  II->m[0] = pOne();
11056  ideal syz = idSyzygies(II, isNotHomog, NULL);
11057  poly integer = NULL;
11058  for(int i = IDELEMS(syz)-1;i>=0; i--)
11059  {
11060  if(pGetComp(syz->m[i]) == 1)
11061  {
11062  pSetComp(syz->m[i],0);
11063  if(pIsConstant(pHead(syz->m[i])))
11064  {
11065  integer = pHead(syz->m[i]);
11066  break;
11067  }
11068  }
11069  }
11070  rChangeCurrRing(origR);
11071  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
11072  pmon = prMapR(integer, nMap2, QQ_ring, origR);
11073  idDelete(&monred);
11074  idDelete(&F);
11075  id_Delete(&II,QQ_ring);
11076  id_Delete(&one,QQ_ring);
11077  id_Delete(&syz,QQ_ring);
11078  p_Delete(&integer,QQ_ring);
11079  rDelete(QQ_ring);
11080  return pmon;
11081  }
11082  else
11083  {
11084  if(idIs0(monred))
11085  {
11086  poly mindegmon = NULL;
11087  for(int i = 0; i<IDELEMS(one); i++)
11088  {
11089  if(pNext(one->m[i]) == NULL)
11090  {
11091  if(mindegmon == NULL)
11092  mindegmon = pCopy(one->m[i]);
11093  else
11094  {
11095  if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
11096  mindegmon = pCopy(one->m[i]);
11097  }
11098  }
11099  }
11100  if(mindegmon != NULL)
11101  {
11102  for(int i = IDELEMS(II)-1; i>=0; i--)
11103  if(II->m[i] != NULL)
11104  II->m[i+1] = II->m[i];
11105  II->m[0] = pCopy(mindegmon);
11106  ideal syz = idSyzygies(II, isNotHomog, NULL);
11107  bool found = FALSE;
11108  for(int i = IDELEMS(syz)-1;i>=0; i--)
11109  {
11110  if(pGetComp(syz->m[i]) == 1)
11111  {
11112  pSetComp(syz->m[i],0);
11113  if(pIsConstant(pHead(syz->m[i])))
11114  {
11115  pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
11116  found = TRUE;
11117  break;
11118  }
11119  }
11120  }
11121  id_Delete(&syz,QQ_ring);
11122  if (found == FALSE)
11123  {
11124  rChangeCurrRing(origR);
11125  idDelete(&monred);
11126  idDelete(&F);
11127  id_Delete(&II,QQ_ring);
11128  id_Delete(&one,QQ_ring);
11129  rDelete(QQ_ring);
11130  return NULL;
11131  }
11132  rChangeCurrRing(origR);
11133  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
11134  pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
11135  idDelete(&monred);
11136  idDelete(&F);
11137  id_Delete(&II,QQ_ring);
11138  id_Delete(&one,QQ_ring);
11139  id_Delete(&syz,QQ_ring);
11140  rDelete(QQ_ring);
11141  return pmon;
11142  }
11143  }
11144  }
11145  rChangeCurrRing(origR);
11146  idDelete(&monred);
11147  idDelete(&F);
11148  id_Delete(&II,QQ_ring);
11149  id_Delete(&one,QQ_ring);
11150  rDelete(QQ_ring);
11151  return NULL;
11152 }
11153 #endif
11154 
11155 #ifdef HAVE_RINGS
11156 /*!
11157  used for GB over ZZ: intermediate reduction by monomial elements
11158  background: any known constant element of ideal suppresses
11159  intermediate coefficient swell
11160 */
11162 {
11163  if(!nCoeff_is_Z(currRing->cf))
11164  return;
11165  poly pH = h->GetP();
11166  poly p,pp;
11167  p = pH;
11168  bool deleted = FALSE, ok = FALSE;
11169  for(int i = 0; i<=strat->sl; i++)
11170  {
11171  p = pH;
11172  if(pNext(strat->S[i]) == NULL)
11173  {
11174  //pWrite(p);
11175  //pWrite(strat->S[i]);
11176  while(ok == FALSE && p != NULL)
11177  {
11178  if(pLmDivisibleBy(strat->S[i], p))
11179  {
11180  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11181  p_SetCoeff(p,dummy,currRing);
11182  }
11183  if(nIsZero(p->coef))
11184  {
11185  pLmDelete(&p);
11186  h->p = p;
11187  deleted = TRUE;
11188  }
11189  else
11190  {
11191  ok = TRUE;
11192  }
11193  }
11194  if (p!=NULL)
11195  {
11196  pp = pNext(p);
11197  while(pp != NULL)
11198  {
11199  if(pLmDivisibleBy(strat->S[i], pp))
11200  {
11201  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11202  p_SetCoeff(pp,dummy,currRing);
11203  if(nIsZero(pp->coef))
11204  {
11205  pLmDelete(&pNext(p));
11206  pp = pNext(p);
11207  deleted = TRUE;
11208  }
11209  else
11210  {
11211  p = pp;
11212  pp = pNext(p);
11213  }
11214  }
11215  else
11216  {
11217  p = pp;
11218  pp = pNext(p);
11219  }
11220  }
11221  }
11222  }
11223  }
11224  h->SetLmCurrRing();
11225  if((deleted)&&(h->p!=NULL))
11226  strat->initEcart(h);
11227 }
11228 
11230 {
11231  if(!nCoeff_is_Z(currRing->cf))
11232  return;
11233  poly hSig = h->sig;
11234  poly pH = h->GetP();
11235  poly p,pp;
11236  p = pH;
11237  bool deleted = FALSE, ok = FALSE;
11238  for(int i = 0; i<=strat->sl; i++)
11239  {
11240  p = pH;
11241  if(pNext(strat->S[i]) == NULL)
11242  {
11243  while(ok == FALSE && p!=NULL)
11244  {
11245  if(pLmDivisibleBy(strat->S[i], p))
11246  {
11247  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11248  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11249  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11250  {
11251  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11252  p_SetCoeff(p,dummy,currRing);
11253  }
11254  pDelete(&sigMult);
11255  }
11256  if(nIsZero(p->coef))
11257  {
11258  pLmDelete(&p);
11259  h->p = p;
11260  deleted = TRUE;
11261  }
11262  else
11263  {
11264  ok = TRUE;
11265  }
11266  }
11267  if(p == NULL)
11268  return;
11269  pp = pNext(p);
11270  while(pp != NULL)
11271  {
11272  if(pLmDivisibleBy(strat->S[i], pp))
11273  {
11274  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11275  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11276  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11277  {
11278  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11279  p_SetCoeff(pp,dummy,currRing);
11280  if(nIsZero(pp->coef))
11281  {
11282  pLmDelete(&pNext(p));
11283  pp = pNext(p);
11284  deleted = TRUE;
11285  }
11286  else
11287  {
11288  p = pp;
11289  pp = pNext(p);
11290  }
11291  }
11292  else
11293  {
11294  p = pp;
11295  pp = pNext(p);
11296  }
11297  pDelete(&sigMult);
11298  }
11299  else
11300  {
11301  p = pp;
11302  pp = pNext(p);
11303  }
11304  }
11305  }
11306  }
11307  h->SetLmCurrRing();
11308  if(deleted)
11309  strat->initEcart(h);
11310 
11311 }
11312 
11313 /*!
11314  used for GB over ZZ: final reduction by constant elements
11315  background: any known constant element of ideal suppresses
11316  intermediate coefficient swell and beautifies output
11317 */
11319 {
11320  assume(strat->tl<0); /* can only be called with no elements in T:
11321  i.e. after exitBuchMora */
11322  /* do not use strat->S, strat->sl as they may be out of sync*/
11323  if(!nCoeff_is_Z(currRing->cf))
11324  return;
11325  poly p,pp;
11326  for(int j = 0; j<IDELEMS(strat->Shdl); j++)
11327  {
11328  if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
11329  {
11330  for(int i = 0; i<IDELEMS(strat->Shdl); i++)
11331  {
11332  if((i != j) && (strat->Shdl->m[i] != NULL))
11333  {
11334  p = strat->Shdl->m[i];
11335  while((p!=NULL) && pLmDivisibleBy(strat->Shdl->m[j], p))
11336  {
11337  number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
11338  if (!nEqual(dummy,p->coef))
11339  {
11340  if (nIsZero(dummy))
11341  {
11342  nDelete(&dummy);
11343  pLmDelete(&strat->Shdl->m[i]);
11344  p=strat->Shdl->m[i];
11345  }
11346  else
11347  {
11348  p_SetCoeff(p,dummy,currRing);
11349  break;
11350  }
11351  }
11352  else
11353  {
11354  nDelete(&dummy);
11355  break;
11356  }
11357  }
11358  if (p!=NULL)
11359  {
11360  pp = pNext(p);
11361  while(pp != NULL)
11362  {
11363  if(pLmDivisibleBy(strat->Shdl->m[j], pp))
11364  {
11365  number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
11366  if (!nEqual(dummy,pp->coef))
11367  {
11368  p_SetCoeff(pp,dummy,currRing);
11369  if(nIsZero(pp->coef))
11370  {
11371  pLmDelete(&pNext(p));
11372  pp = pNext(p);
11373  }
11374  else
11375  {
11376  p = pp;
11377  pp = pNext(p);
11378  }
11379  }
11380  else
11381  {
11382  nDelete(&dummy);
11383  p = pp;
11384  pp = pNext(p);
11385  }
11386  }
11387  else
11388  {
11389  p = pp;
11390  pp = pNext(p);
11391  }
11392  }
11393  }
11394  }
11395  }
11396  //idPrint(strat->Shdl);
11397  }
11398  }
11399  idSkipZeroes(strat->Shdl);
11400 }
11401 #endif
11402 
11403 BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
11404 {
11405  assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11406  /* initial setup or extending */
11407 
11408  if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11409  if (expbound >= currRing->bitmask) return FALSE;
11410  strat->overflow=FALSE;
11411  ring new_tailRing = rModifyRing(currRing,
11412  // Hmmm .. the condition pFDeg == p_Deg
11413  // might be too strong
11414  (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11415  (strat->ak==0), // omit_comp if the input is an ideal
11416  expbound); // exp_limit
11417 
11418  if (new_tailRing == currRing) return TRUE;
11419 
11420  strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11421  strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11422 
11423  if (currRing->pFDeg != currRing->pFDegOrig)
11424  {
11425  new_tailRing->pFDeg = currRing->pFDeg;
11426  new_tailRing->pLDeg = currRing->pLDeg;
11427  }
11428 
11429  if (TEST_OPT_PROT)
11430  Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11431  kTest_TS(strat);
11432  assume(new_tailRing != strat->tailRing);
11433  pShallowCopyDeleteProc p_shallow_copy_delete
11434  = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11435 
11436  omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11437 
11438  int i;
11439  for (i=0; i<=strat->tl; i++)
11440  {
11441  strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11442  p_shallow_copy_delete);
11443  }
11444  for (i=0; i<=strat->Ll; i++)
11445  {
11446  assume(strat->L[i].p != NULL);
11447  if (pNext(strat->L[i].p) != strat->tail)
11448  strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11449  }
11450  if ((strat->P.t_p != NULL) ||
11451  ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11452  strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11453 
11454  if ((L != NULL) && (L->tailRing != new_tailRing))
11455  {
11456  if (L->i_r < 0)
11457  L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11458  else
11459  {
11460  assume(L->i_r <= strat->tl);
11461  TObject* t_l = strat->R[L->i_r];
11462  assume(t_l != NULL);
11463  L->tailRing = new_tailRing;
11464  L->p = t_l->p;
11465  L->t_p = t_l->t_p;
11466  L->max_exp = t_l->max_exp;
11467  }
11468  }
11469 
11470  if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11471  T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11472 
11473  omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11474  if (strat->tailRing != currRing)
11475  rKillModifiedRing(strat->tailRing);
11476 
11477  strat->tailRing = new_tailRing;
11478  strat->tailBin = new_tailBin;
11479  strat->p_shallow_copy_delete
11480  = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11481 
11482  if (strat->kHEdge != NULL)
11483  {
11484  if (strat->t_kHEdge != NULL)
11485  p_LmFree(strat->t_kHEdge, strat->tailRing);
11486  strat->t_kHEdge=k_LmInit_currRing_2_tailRing(strat->kHEdge, new_tailRing);
11487  }
11488 
11489  if (strat->kNoether != NULL)
11490  {
11491  if (strat->t_kNoether != NULL)
11492  p_LmFree(strat->t_kNoether, strat->tailRing);
11494  new_tailRing);
11495  }
11496  kTest_TS(strat);
11497  if (TEST_OPT_PROT)
11498  PrintS("]");
11499  return TRUE;
11500 }
11501 
11503 {
11504  unsigned long l = 0;
11505  int i;
11506  long e;
11507 
11508  assume(strat->tailRing == currRing);
11509 
11510  for (i=0; i<= strat->Ll; i++)
11511  {
11512  l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11513  }
11514  for (i=0; i<=strat->tl; i++)
11515  {
11516  // Hmm ... this we could do in one Step
11517  l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11518  }
11519  if (rField_is_Ring(currRing))
11520  {
11521  l *= 2;
11522  }
11523  e = p_GetMaxExp(l, currRing);
11524  if (e <= 1) e = 2;
11525 
11526  kStratChangeTailRing(strat, NULL, NULL, e);
11527 }
11528 
11529 ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11530 {
11531  int n = rBlocks(r); // Including trailing zero!
11532  // if sbaOrder == 1 => use (C,monomial order from r)
11533  if (strat->sbaOrder == 1)
11534  {
11535  if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11536  {
11537  return r;
11538  }
11539  ring res = rCopy0(r, TRUE, FALSE);
11540  res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11541  res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11542  res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11543  int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11544  res->wvhdl = wvhdl;
11545  for (int i=1; i<n; i++)
11546  {
11547  res->order[i] = r->order[i-1];
11548  res->block0[i] = r->block0[i-1];
11549  res->block1[i] = r->block1[i-1];
11550  res->wvhdl[i] = r->wvhdl[i-1];
11551  }
11552 
11553  // new 1st block
11554  res->order[0] = ringorder_C; // Prefix
11555  // removes useless secondary component order if defined in old ring
11556  for (int i=rBlocks(res); i>0; --i)
11557  {
11558  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11559  {
11560  res->order[i] = (rRingOrder_t)0;
11561  }
11562  }
11563  rComplete(res, 1);
11564 #ifdef HAVE_PLURAL
11565  if (rIsPluralRing(r))
11566  {
11567  if ( nc_rComplete(r, res, false) ) // no qideal!
11568  {
11569 #ifndef SING_NDEBUG
11570  WarnS("error in nc_rComplete");
11571 #endif
11572  // cleanup?
11573 
11574  // rDelete(res);
11575  // return r;
11576 
11577  // just go on..
11578  }
11579  }
11580 #endif
11581  strat->tailRing = res;
11582  return (res);
11583  }
11584  // if sbaOrder == 3 => degree - position - ring order
11585  if (strat->sbaOrder == 3)
11586  {
11587  ring res = rCopy0(r, TRUE, FALSE);
11588  res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11589  res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11590  res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11591  int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11592  res->wvhdl = wvhdl;
11593  for (int i=2; i<n+2; i++)
11594  {
11595  res->order[i] = r->order[i-2];
11596  res->block0[i] = r->block0[i-2];
11597  res->block1[i] = r->block1[i-2];
11598  res->wvhdl[i] = r->wvhdl[i-2];
11599  }
11600 
11601  // new 1st block
11602  res->order[0] = ringorder_a; // Prefix
11603  res->block0[0] = 1;
11604  res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11605  for (int i=0; i<res->N; ++i)
11606  res->wvhdl[0][i] = 1;
11607  res->block1[0] = si_min(res->N, rVar(res));
11608  // new 2nd block
11609  res->order[1] = ringorder_C; // Prefix
11610  res->wvhdl[1] = NULL;
11611  // removes useless secondary component order if defined in old ring
11612  for (int i=rBlocks(res); i>1; --i)
11613  {
11614  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11615  {
11616  res->order[i] = (rRingOrder_t)0;
11617  }
11618  }
11619  rComplete(res, 1);
11620 #ifdef HAVE_PLURAL
11621  if (rIsPluralRing(r))
11622  {
11623  if ( nc_rComplete(r, res, false) ) // no qideal!
11624  {
11625 #ifndef SING_NDEBUG
11626  WarnS("error in nc_rComplete");
11627 #endif
11628  // cleanup?
11629 
11630  // rDelete(res);
11631  // return r;
11632 
11633  // just go on..
11634  }
11635  }
11636 #endif
11637  strat->tailRing = res;
11638  return (res);
11639  }
11640 
11641  // not sbaOrder == 1 => use Schreyer order
11642  // this is done by a trick when initializing the signatures
11643  // in initSLSba():
11644  // Instead of using the signature 1e_i for F->m[i], we start
11645  // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11646  // Schreyer order w.r.t. the underlying monomial order.
11647  // => we do not need to change the underlying polynomial ring at all!
11648 
11649  // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11650 
11651  /*
11652  else
11653  {
11654  ring res = rCopy0(r, FALSE, FALSE);
11655  // Create 2 more blocks for prefix/suffix:
11656  res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11657  res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11658  res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11659  int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11660 
11661  // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11662  // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11663 
11664  // new 1st block
11665  int j = 0;
11666  res->order[j] = ringorder_IS; // Prefix
11667  res->block0[j] = res->block1[j] = 0;
11668  // wvhdl[j] = NULL;
11669  j++;
11670 
11671  for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11672  {
11673  res->order [j] = r->order [i];
11674  res->block0[j] = r->block0[i];
11675  res->block1[j] = r->block1[i];
11676 
11677  if (r->wvhdl[i] != NULL)
11678  {
11679  wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11680  } // else wvhdl[j] = NULL;
11681  }
11682 
11683  // new last block
11684  res->order [j] = ringorder_IS; // Suffix
11685  res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11686  // wvhdl[j] = NULL;
11687  j++;
11688 
11689  // res->order [j] = 0; // The End!
11690  res->wvhdl = wvhdl;
11691 
11692  // j == the last zero block now!
11693  assume(j == (n+1));
11694  assume(res->order[0]==ringorder_IS);
11695  assume(res->order[j-1]==ringorder_IS);
11696  assume(res->order[j]==0);
11697 
11698  if (complete)
11699  {
11700  rComplete(res, 1);
11701 
11702 #ifdef HAVE_PLURAL
11703  if (rIsPluralRing(r))
11704  {
11705  if ( nc_rComplete(r, res, false) ) // no qideal!
11706  {
11707  }
11708  }
11709  assume(rIsPluralRing(r) == rIsPluralRing(res));
11710 #endif
11711 
11712 
11713 #ifdef HAVE_PLURAL
11714  ring old_ring = r;
11715 
11716 #endif
11717 
11718  if (r->qideal!=NULL)
11719  {
11720  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11721 
11722  assume(idRankFreeModule(res->qideal, res) == 0);
11723 
11724 #ifdef HAVE_PLURAL
11725  if( rIsPluralRing(res) )
11726  if( nc_SetupQuotient(res, r, true) )
11727  {
11728  // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11729  }
11730 
11731 #endif
11732  assume(idRankFreeModule(res->qideal, res) == 0);
11733  }
11734 
11735 #ifdef HAVE_PLURAL
11736  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11737  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11738  assume(rIsSCA(res) == rIsSCA(old_ring));
11739  assume(ncRingType(res) == ncRingType(old_ring));
11740 #endif
11741  }
11742  strat->tailRing = res;
11743  return res;
11744  }
11745  */
11746 
11747  assume(FALSE);
11748  return(NULL);
11749 }
11750 
11752 {
11753  memset(this, 0, sizeof(skStrategy));
11754  strat_nr++;
11755  nr=strat_nr;
11756  tailRing = currRing;
11757  P.tailRing = currRing;
11758  tl = -1;
11759  sl = -1;
11760 #ifdef HAVE_LM_BIN
11761  lmBin = omGetStickyBinOfBin(currRing->PolyBin);
11762 #endif
11763 #ifdef HAVE_TAIL_BIN
11764  tailBin = omGetStickyBinOfBin(currRing->PolyBin);
11765 #endif
11766  pOrigFDeg = currRing->pFDeg;
11767  pOrigLDeg = currRing->pLDeg;
11768 }
11769 
11770 
11772 {
11773  if (lmBin != NULL)
11774  omMergeStickyBinIntoBin(lmBin, currRing->PolyBin);
11775  if (tailBin != NULL)// && !rField_is_Ring(currRing))
11776  omMergeStickyBinIntoBin(tailBin,
11777  (tailRing != NULL ? tailRing->PolyBin:
11778  currRing->PolyBin));
11779  if (t_kHEdge != NULL)
11780  p_LmFree(t_kHEdge, tailRing);
11781  if (t_kNoether != NULL)
11782  p_LmFree(t_kNoether, tailRing);
11783 
11784  if (currRing != tailRing)
11786  pRestoreDegProcs(currRing,pOrigFDeg, pOrigLDeg);
11787 }
11788 
11789 #if 0
11790 Timings for the different possibilities of posInT:
11791  T15 EDL DL EL L 1-2-3
11792 Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11793 Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11794 Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11795 ahml 4.48 4.03 4.03 4.38 4.96 26.50
11796 c7 15.02 13.98 15.16 13.24 17.31 47.89
11797 c8 505.09 407.46 852.76 413.21 499.19 n/a
11798 f855 12.65 9.27 14.97 8.78 14.23 33.12
11799 gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11800 gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11801 ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11802 noon8 40.68 37.02 37.99 36.82 35.59 877.16
11803 rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11804 rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11805 schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11806 test016 16.39 14.17 14.40 13.50 14.26 34.07
11807 test017 34.70 36.01 33.16 35.48 32.75 71.45
11808 test042 10.76 10.99 10.27 11.57 10.45 23.04
11809 test058 6.78 6.75 6.51 6.95 6.22 9.47
11810 test066 10.71 10.94 10.76 10.61 10.56 19.06
11811 test073 10.75 11.11 10.17 10.79 8.63 58.10
11812 test086 12.23 11.81 12.88 12.24 13.37 66.68
11813 test103 5.05 4.80 5.47 4.64 4.89 11.90
11814 test154 12.96 11.64 13.51 12.46 14.61 36.35
11815 test162 65.27 64.01 67.35 59.79 67.54 196.46
11816 test164 7.50 6.50 7.68 6.70 7.96 17.13
11817 virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11818 #endif
11819 
11820 
11821 //#ifdef HAVE_MORE_POS_IN_T
11822 #if 1
11823 // determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11824 int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p)
11825 {
11826 
11827  if (length==-1) return 0;
11828 
11829  int o = p.ecart;
11830  int op=p.GetpFDeg();
11831  int ol = p.GetpLength();
11832 
11833  if (set[length].ecart < o)
11834  return length+1;
11835  if (set[length].ecart == o)
11836  {
11837  int oo=set[length].GetpFDeg();
11838  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11839  return length+1;
11840  }
11841 
11842  int i;
11843  int an = 0;
11844  int en= length;
11845  loop
11846  {
11847  if (an >= en-1)
11848  {
11849  if (set[an].ecart > o)
11850  return an;
11851  if (set[an].ecart == o)
11852  {
11853  int oo=set[an].GetpFDeg();
11854  if((oo > op)
11855  || ((oo==op) && (set[an].pLength > ol)))
11856  return an;
11857  }
11858  return en;
11859  }
11860  i=(an+en) / 2;
11861  if (set[i].ecart > o)
11862  en=i;
11863  else if (set[i].ecart == o)
11864  {
11865  int oo=set[i].GetpFDeg();
11866  if ((oo > op)
11867  || ((oo == op) && (set[i].pLength > ol)))
11868  en=i;
11869  else
11870  an=i;
11871  }
11872  else
11873  an=i;
11874  }
11875 }
11876 
11877 // determines the position based on: 1.) FDeg 2.) pLength
11878 int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11879 {
11880 
11881  if (length==-1) return 0;
11882 
11883  int op=p.GetpFDeg();
11884  int ol = p.GetpLength();
11885 
11886  int oo=set[length].GetpFDeg();
11887  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11888  return length+1;
11889 
11890  int i;
11891  int an = 0;
11892  int en= length;
11893  loop
11894  {
11895  if (an >= en-1)
11896  {
11897  int oo=set[an].GetpFDeg();
11898  if((oo > op)
11899  || ((oo==op) && (set[an].pLength > ol)))
11900  return an;
11901  return en;
11902  }
11903  i=(an+en) / 2;
11904  int oo=set[i].GetpFDeg();
11905  if ((oo > op)
11906  || ((oo == op) && (set[i].pLength > ol)))
11907  en=i;
11908  else
11909  an=i;
11910  }
11911 }
11912 
11913 
11914 // determines the position based on: 1.) pLength
11915 int posInT_pLength(const TSet set,const int length,LObject &p)
11916 {
11917  int ol = p.GetpLength();
11918  if (length==-1)
11919  return 0;
11920  if (set[length].length<p.length)
11921  return length+1;
11922 
11923  int i;
11924  int an = 0;
11925  int en= length;
11926 
11927  loop
11928  {
11929  if (an >= en-1)
11930  {
11931  if (set[an].pLength>ol) return an;
11932  return en;
11933  }
11934  i=(an+en) / 2;
11935  if (set[i].pLength>ol) en=i;
11936  else an=i;
11937  }
11938 }
11939 #endif
11940 
11941 // kstd1.cc:
11942 int redFirst (LObject* h,kStrategy strat);
11943 int redEcart (LObject* h,kStrategy strat);
11944 void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11945 void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11946 // ../Singular/misc.cc:
11947 extern char * showOption();
11948 
11950 {
11951  PrintS("red: ");
11952  if (strat->red==redFirst) PrintS("redFirst\n");
11953  else if (strat->red==redHoney) PrintS("redHoney\n");
11954  else if (strat->red==redEcart) PrintS("redEcart\n");
11955  else if (strat->red==redHomog) PrintS("redHomog\n");
11956  else Print("%p\n",(void*)strat->red);
11957  PrintS("posInT: ");
11958  if (strat->posInT==posInT0) PrintS("posInT0\n");
11959  else if (strat->posInT==posInT1) PrintS("posInT1\n");
11960  else if (strat->posInT==posInT11) PrintS("posInT11\n");
11961  else if (strat->posInT==posInT110) PrintS("posInT110\n");
11962  else if (strat->posInT==posInT13) PrintS("posInT13\n");
11963  else if (strat->posInT==posInT15) PrintS("posInT15\n");
11964  else if (strat->posInT==posInT17) PrintS("posInT17\n");
11965  else if (strat->posInT==posInT17_c) PrintS("posInT17_c\n");
11966  else if (strat->posInT==posInT19) PrintS("posInT19\n");
11967  else if (strat->posInT==posInT2) PrintS("posInT2\n");
11968  #ifdef HAVE_RINGS
11969  else if (strat->posInT==posInT11Ring) PrintS("posInT11Ring\n");
11970  else if (strat->posInT==posInT110Ring) PrintS("posInT110Ring\n");
11971  else if (strat->posInT==posInT15Ring) PrintS("posInT15Ring\n");
11972  else if (strat->posInT==posInT17Ring) PrintS("posInT17Ring\n");
11973  else if (strat->posInT==posInT17_cRing) PrintS("posInT17_cRing\n");
11974  #endif
11975 #ifdef HAVE_MORE_POS_IN_T
11976  else if (strat->posInT==posInT_EcartFDegpLength) PrintS("posInT_EcartFDegpLength\n");
11977  else if (strat->posInT==posInT_FDegpLength) PrintS("posInT_FDegpLength\n");
11978  else if (strat->posInT==posInT_pLength) PrintS("posInT_pLength\n");
11979 #endif
11980  else if (strat->posInT==posInT_EcartpLength) PrintS("posInT_EcartpLength\n");
11981  else if (strat->posInT==posInTrg0) PrintS("posInTrg0\n");
11982  else Print("%p\n",(void*)strat->posInT);
11983  PrintS("posInL: ");
11984  if (strat->posInL==posInL0) PrintS("posInL0\n");
11985  else if (strat->posInL==posInL10) PrintS("posInL10\n");
11986  else if (strat->posInL==posInL11) PrintS("posInL11\n");
11987  else if (strat->posInL==posInL110) PrintS("posInL110\n");
11988  else if (strat->posInL==posInL13) PrintS("posInL13\n");
11989  else if (strat->posInL==posInL15) PrintS("posInL15\n");
11990  else if (strat->posInL==posInL17) PrintS("posInL17\n");
11991  else if (strat->posInL==posInL17_c) PrintS("posInL17_c\n");
11992  #ifdef HAVE_RINGS
11993  else if (strat->posInL==posInL0) PrintS("posInL0Ring\n");
11994  else if (strat->posInL==posInL11Ring) PrintS("posInL11Ring\n");
11995  else if (strat->posInL==posInL11Ringls) PrintS("posInL11Ringls\n");
11996  else if (strat->posInL==posInL110Ring) PrintS("posInL110Ring\n");
11997  else if (strat->posInL==posInL15Ring) PrintS("posInL15Ring\n");
11998  else if (strat->posInL==posInL17Ring) PrintS("posInL17Ring\n");
11999  else if (strat->posInL==posInL17_cRing) PrintS("posInL17_cRing\n");
12000  #endif
12001  else if (strat->posInL==posInLSpecial) PrintS("posInLSpecial\n");
12002  else if (strat->posInL==posInLrg0) PrintS("posInLrg0\n");
12003  else Print("%p\n",(void*)strat->posInL);
12004  PrintS("enterS: ");
12005  if (strat->enterS==enterSBba) PrintS("enterSBba\n");
12006  else if (strat->enterS==enterSMora) PrintS("enterSMora\n");
12007  else if (strat->enterS==enterSMoraNF) PrintS("enterSMoraNF\n");
12008  else Print("%p\n",(void*)strat->enterS);
12009  PrintS("initEcart: ");
12010  if (strat->initEcart==initEcartBBA) PrintS("initEcartBBA\n");
12011  else if (strat->initEcart==initEcartNormal) PrintS("initEcartNormal\n");
12012  else Print("%p\n",(void*)strat->initEcart);
12013  PrintS("initEcartPair: ");
12014  if (strat->initEcartPair==initEcartPairBba) PrintS("initEcartPairBba\n");
12015  else if (strat->initEcartPair==initEcartPairMora) PrintS("initEcartPairMora\n");
12016  else Print("%p\n",(void*)strat->initEcartPair);
12017  Print("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
12018  strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
12019  Print("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
12020  strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
12021  PrintS("chainCrit: ");
12022  if (strat->chainCrit==chainCritNormal) PrintS("chainCritNormal\n");
12023  else if (strat->chainCrit==chainCritOpt_1) PrintS("chainCritOpt_1\n");
12024  else Print("%p\n",(void*)strat->chainCrit);
12025  Print("posInLDependsOnLength=%d\n",
12026  strat->posInLDependsOnLength);
12027  PrintS(showOption());PrintLn();
12028  PrintS("LDeg: ");
12029  if (currRing->pLDeg==pLDeg0) PrintS("pLDeg0");
12030  else if (currRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
12031  else if (currRing->pLDeg==pLDegb) PrintS("pLDegb");
12032  else if (currRing->pLDeg==pLDeg1) PrintS("pLDeg1");
12033  else if (currRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
12034  else if (currRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
12035  else if (currRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
12036  else if (currRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
12037  else if (currRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
12038  else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
12039  else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
12040  else if (currRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
12041  else Print("? (%lx)", (long)currRing->pLDeg);
12042  PrintS(" / ");
12043  if (strat->tailRing->pLDeg==pLDeg0) PrintS("pLDeg0");
12044  else if (strat->tailRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
12045  else if (strat->tailRing->pLDeg==pLDegb) PrintS("pLDegb");
12046  else if (strat->tailRing->pLDeg==pLDeg1) PrintS("pLDeg1");
12047  else if (strat->tailRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
12048  else if (strat->tailRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
12049  else if (strat->tailRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
12050  else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
12051  else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
12052  else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
12053  else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
12054  else if (strat->tailRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
12055  else Print("? (%lx)", (long)strat->tailRing->pLDeg);
12056  PrintLn();
12057  PrintS("currRing->pFDeg: ");
12058  if (currRing->pFDeg==p_Totaldegree) PrintS("p_Totaldegree");
12059  else if (currRing->pFDeg==p_WFirstTotalDegree) PrintS("pWFirstTotalDegree");
12060  else if (currRing->pFDeg==p_Deg) PrintS("p_Deg");
12061  else if (currRing->pFDeg==kHomModDeg) PrintS("kHomModDeg");
12062  else if (currRing->pFDeg==totaldegreeWecart) PrintS("totaldegreeWecart");
12063  else if (currRing->pFDeg==p_WTotaldegree) PrintS("p_WTotaldegree");
12064  else Print("? (%lx)", (long)currRing->pFDeg);
12065  PrintLn();
12066  Print(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
12067  if(TEST_OPT_DEGBOUND)
12068  Print(" degBound: %d\n", Kstd1_deg);
12069 
12070  if( ecartWeights != NULL )
12071  {
12072  PrintS("ecartWeights: ");
12073  for (int i = rVar(currRing); i > 0; i--)
12074  Print("%hd ", ecartWeights[i]);
12075  PrintLn();
12077  }
12078 
12079 #ifndef SING_NDEBUG
12081 #endif
12082 }
12083 
12084 #ifdef HAVE_SHIFTBBA
12085 poly pMove2CurrTail(poly p, kStrategy strat)
12086 {
12087  /* assume: p is completely in currRing */
12088  /* produces an object with LM in curring
12089  and TAIL in tailring */
12090  if (pNext(p)!=NULL)
12091  {
12092  pNext(p) = prMoveR(pNext(p), /* src */ currRing, /* dest */ strat->tailRing);
12093  }
12094  return(p);
12095 }
12096 #endif
12097 
12098 #ifdef HAVE_SHIFTBBA
12099 poly pMoveCurrTail2poly(poly p, kStrategy strat)
12100 {
12101  /* assume: p has LM in curring and TAIL in tailring */
12102  /* convert it to complete currRing */
12103 
12104  /* check that LM is in currRing */
12106 
12107  if (pNext(p)!=NULL)
12108  {
12109  pNext(p) = prMoveR(pNext(p), /* src */ strat->tailRing, /* dest */currRing);
12110  }
12111  return(p);
12112 }
12113 #endif
12114 
12115 #ifdef HAVE_SHIFTBBA
12117 {
12118  /* restores a poly in currRing from LObject */
12119  LObject h = H;
12120  h.Copy();
12121  poly p;
12122  if (h.p == NULL)
12123  {
12124  if (h.t_p != NULL)
12125  {
12126  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing, /* dest. ring: */ currRing);
12127  return(p);
12128  }
12129  else
12130  {
12131  /* h.tp == NULL -> the object is NULL */
12132  return(NULL);
12133  }
12134  }
12135  /* we're here if h.p != NULL */
12136  if (h.t_p == NULL)
12137  {
12138  /* then h.p is the whole poly in currRing */
12139  p = h.p;
12140  return(p);
12141  }
12142  /* we're here if h.p != NULL and h.t_p != NULL */
12143  // clean h.p, get poly from t_p
12144  pNext(h.p)=NULL;
12145  pLmDelete(&h.p);
12146  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing,
12147  /* dest. ring: */ currRing);
12148  // no need to clean h: we re-used the polys
12149  return(p);
12150 }
12151 #endif
12152 
12153 //LObject pCopyp2L(poly p, kStrategy strat)
12154 //{
12155  /* creates LObject from the poly in currRing */
12156  /* actually put p into L.p and make L.t_p=NULL : does not work */
12157 
12158 //}
12159 
12160 // poly pCopyL2p(LObject H, kStrategy strat)
12161 // {
12162 // /* restores a poly in currRing from LObject */
12163 // LObject h = H;
12164 // h.Copy();
12165 // poly p;
12166 // if (h.p == NULL)
12167 // {
12168 // if (h.t_p != NULL)
12169 // {
12170 // p = p_ShallowCopyDelete(h.t_p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12171 // return(p);
12172 // }
12173 // else
12174 // {
12175 // /* h.tp == NULL -> the object is NULL */
12176 // return(NULL);
12177 // }
12178 // }
12179 // /* we're here if h.p != NULL */
12180 
12181 // if (h.t_p == NULL)
12182 // {
12183 // /* then h.p is the whole poly in tailRing */
12184 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12185 // {
12186 // p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12187 // }
12188 // return(p);
12189 // }
12190 // /* we're here if h.p != NULL and h.t_p != NULL */
12191 // p = pCopy(pHead(h.p)); // in currRing
12192 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12193 // {
12194 // // pNext(p) = p_ShallowCopyDelete(pNext(h.t_p), (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12195 // poly pp = p_Copy(pNext(h.p), strat->tailRing);
12196 // // poly p3 = p_Copy(pNext(h.p), currRing); // error
12197 // // p_ShallowCopyDelete(pNext(h.p), currRing, strat->tailBin); // the same as pp
12198 // poly p5 = p_ShallowCopyDelete(pNext(h.p), strat->tailRing, strat->tailBin);
12199 // pNext(p) = p_ShallowCopyDelete(h.t_p, strat->tailRing, strat->tailBin);
12200 // poly p4 = p_Copy(h.t_p, strat->tailRing);
12201 // // if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
12202 // }
12203 // // pTest(p);
12204 // return(p);
12205 // }
12206 
12207 #ifdef HAVE_SHIFTBBA
12208 // creates if possible (q,p), (shifts(q),p)
12209 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)
12210 {
12211  // note: ecart and isFromQ is for p
12212  assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12213  assume(pmFirstVblock(p) == 1);
12214  assume(pmFirstVblock(q) == 1);
12215  assume(p_lastVblock == pmLastVblock(p));
12216  assume(q_lastVblock == pmLastVblock(q));
12217 
12218  // TODO: is ecartq = 0 still ok?
12219  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12220 
12221  int q_isFromQ = 0;
12222  if (strat->fromQ != NULL && q_inS >= 0)
12223  q_isFromQ = strat->fromQ[q_inS];
12224 
12225  int degbound = currRing->N/currRing->isLPring;
12226  int neededShift = p_lastVblock - 1;
12227  int maxPossibleShift = degbound - q_lastVblock;
12228  int maxShift = si_min(neededShift, maxPossibleShift);
12229  int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12230  for (int j = firstShift; j <= maxShift; j++)
12231  {
12232  poly qq = pLPCopyAndShiftLM(q, j);
12233  enterOnePairShift(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS);
12234  }
12235 }
12236 #endif
12237 
12238 #ifdef HAVE_SHIFTBBA
12239 // creates if possible (q,p), use it when q is already shifted
12240 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)
12241 {
12242  // note: ecart and isFromQ is for p
12243  assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12244  assume(pmFirstVblock(p) == 1);
12245  assume(p_lastVblock == pmLastVblock(p));
12246  assume(q_shift == pmFirstVblock(q) - 1);
12247 
12248  // TODO: is ecartp = 0 still ok?
12249  int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12250 
12251  int p_isFromQ = 0;
12252  if (strat->fromQ != NULL && p_inS >= 0)
12253  p_isFromQ = strat->fromQ[p_inS];
12254 
12255  int maxNeededShift = p_lastVblock - 1;
12256  if (q_shift <= maxNeededShift)
12257  enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12258 }
12259 #endif
12260 
12261 #ifdef HAVE_SHIFTBBA
12262 
12263 #ifdef KDEBUG
12264 // enable to print which pairs are considered or discarded and why
12265 /* #define CRITERION_DEBUG */
12266 #endif
12267 /*2
12268 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12269 */
12270 void enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12271 {
12272 #ifdef CRITERION_DEBUG
12273  if (TEST_OPT_DEBUG)
12274  {
12275  PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12276  // also write the LMs in separate lines:
12277  poly lmq = pHead(q);
12278  poly lmp = pHead(p);
12279  pSetCoeff(lmq, n_Init(1, currRing->cf));
12280  pSetCoeff(lmp, n_Init(1, currRing->cf));
12281  Print(" %s\n", pString(lmq));
12282  Print(" %s\n", pString(lmp));
12283  pLmDelete(lmq);
12284  pLmDelete(lmp);
12285  }
12286 #endif
12287 
12288  /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12289 
12290  /* check this Formats: */
12292  assume(p_CheckIsFromRing(pNext(q),strat->tailRing));
12294  assume(p_CheckIsFromRing(pNext(p),strat->tailRing));
12295 
12296  /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12297 
12298  int qfromQ = qisFromQ;
12299 
12300  /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12301 
12302  int l,j,compare;
12303  LObject Lp;
12304  Lp.i_r = -1;
12305 
12306 #ifdef KDEBUG
12307  Lp.ecart=0; Lp.length=0;
12308 #endif
12309  /*- computes the lcm(s[i],p) -*/
12310  Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12311 
12312  /* the V criterion */
12313  if (!pmIsInV(Lp.lcm))
12314  {
12315  strat->cv++; // counter for applying the V criterion
12316  pLmFree(Lp.lcm);
12317 #ifdef CRITERION_DEBUG
12318  if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12319 #endif
12320  return;
12321  }
12322 
12323  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12324  {
12325  if((!((ecartq>0)&&(ecart>0)))
12326  && pHasNotCF(p,q))
12327  {
12328  /*
12329  *the product criterion has applied for (s,p),
12330  *i.e. lcm(s,p)=product of the leading terms of s and p.
12331  *Suppose (s,r) is in L and the leading term
12332  *of p divides lcm(s,r)
12333  *(==> the leading term of p divides the leading term of r)
12334  *but the leading term of s does not divide the leading term of r
12335  *(notice that this condition is automatically satisfied if r is still
12336  *in S), then (s,r) can be cancelled.
12337  *This should be done here because the
12338  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12339  *
12340  *Moreover, skipping (s,r) holds also for the noncommutative case.
12341  */
12342  strat->cp++;
12343  pLmFree(Lp.lcm);
12344 #ifdef CRITERION_DEBUG
12345  if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12346 #endif
12347  return;
12348  }
12349  else
12350  Lp.ecart = si_max(ecart,ecartq);
12351  if (strat->fromT && (ecartq>ecart))
12352  {
12353  pLmFree(Lp.lcm);
12354 #ifdef CRITERION_DEBUG
12355  if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12356 #endif
12357  return;
12358  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12359  }
12360  /*
12361  *the set B collects the pairs of type (S[j],p)
12362  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12363  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12364  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12365  */
12366  {
12367  j = strat->Bl;
12368  loop
12369  {
12370  if (j < 0) break;
12371  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12372  if ((compare==1)
12373  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12374  {
12375  strat->c3++;
12376  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12377  {
12378  pLmFree(Lp.lcm);
12379 #ifdef CRITERION_DEBUG
12380  if (TEST_OPT_DEBUG) Print("--- divided by B[%d]\n", j);
12381 #endif
12382  return;
12383  }
12384  break;
12385  }
12386  else
12387  if ((compare ==-1)
12388  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12389  {
12390  deleteInL(strat->B,&strat->Bl,j,strat);
12391 #ifdef CRITERION_DEBUG
12392  if (TEST_OPT_DEBUG) Print("divides B[%d] -> delete B[%d]\n", j, j);
12393 #endif
12394  strat->c3++;
12395  }
12396  j--;
12397  }
12398  }
12399  }
12400  else /*sugarcrit*/
12401  {
12402  if (ALLOW_PROD_CRIT(strat))
12403  {
12404  // if currRing->nc_type!=quasi (or skew)
12405  // TODO: enable productCrit for super commutative algebras...
12406  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12407  pHasNotCF(p,q))
12408  {
12409  /*
12410  *the product criterion has applied for (s,p),
12411  *i.e. lcm(s,p)=product of the leading terms of s and p.
12412  *Suppose (s,r) is in L and the leading term
12413  *of p devides lcm(s,r)
12414  *(==> the leading term of p devides the leading term of r)
12415  *but the leading term of s does not devide the leading term of r
12416  *(notice that tis condition is automatically satisfied if r is still
12417  *in S), then (s,r) can be canceled.
12418  *This should be done here because the
12419  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12420  */
12421  strat->cp++;
12422  pLmFree(Lp.lcm);
12423 #ifdef CRITERION_DEBUG
12424  if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12425 #endif
12426  return;
12427  }
12428  if (strat->fromT && (ecartq>ecart))
12429  {
12430  pLmFree(Lp.lcm);
12431 #ifdef CRITERION_DEBUG
12432  if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12433 #endif
12434  return;
12435  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12436  }
12437  /*
12438  *the set B collects the pairs of type (S[j],p)
12439  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12440  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12441  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12442  */
12443  for(j = strat->Bl;j>=0;j--)
12444  {
12445  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12446  if (compare==1)
12447  {
12448  strat->c3++;
12449  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12450  {
12451  pLmFree(Lp.lcm);
12452 #ifdef CRITERION_DEBUG
12453  if (TEST_OPT_DEBUG) Print("--- divided by B[%d]\n", j);
12454 #endif
12455  return;
12456  }
12457  break;
12458  }
12459  else
12460  if (compare ==-1)
12461  {
12462  deleteInL(strat->B,&strat->Bl,j,strat);
12463 #ifdef CRITERION_DEBUG
12464  if (TEST_OPT_DEBUG) Print("divides B[%d] -> delete B[%d]\n", j, j);
12465 #endif
12466  strat->c3++;
12467  }
12468  }
12469  }
12470  }
12471  /*
12472  *the pair (S[i],p) enters B if the spoly != 0
12473  */
12474  /*- compute the short s-polynomial -*/
12475  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12476  pNorm(p);
12477  if ((q==NULL) || (p==NULL))
12478  {
12479 #ifdef CRITERION_DEBUG
12480  if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
12481 #endif
12482  return;
12483  }
12484  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12485  {
12486  Lp.p=NULL;
12487 #ifdef CRITERION_DEBUG
12488  if (TEST_OPT_DEBUG) PrintS("--- pair from Q\n");
12489 #endif
12490  }
12491  else
12492  {
12493 // if ( rIsPluralRing(currRing) )
12494 // {
12495 // if(pHasNotCF(p, q))
12496 // {
12497 // if(ncRingType(currRing) == nc_lie)
12498 // {
12499 // // generalized prod-crit for lie-type
12500 // strat->cp++;
12501 // Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12502 // }
12503 // else
12504 // if( ALLOW_PROD_CRIT(strat) )
12505 // {
12506 // // product criterion for homogeneous case in SCA
12507 // strat->cp++;
12508 // Lp.p = NULL;
12509 // }
12510 // else
12511 // Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12512 // }
12513 // else Lp.p = nc_CreateSpoly(q,p,currRing);
12514 // }
12515 // else
12516 // {
12517 
12518  /* ksCreateShortSpoly needs two Lobject-kind presentations */
12519  /* p is already in this form, so convert q */
12520  // q = pMove2CurrTail(q, strat);
12521  Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12522  // }
12523  }
12524  if (Lp.p == NULL)
12525  {
12526  /*- the case that the s-poly is 0 -*/
12527  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12528 // if (strat->pairtest==NULL) initPairtest(strat);
12529 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12530 // strat->pairtest[strat->sl+1] = TRUE;
12531 // new: visual check how often this happens: ! for the debug situation
12532 #ifdef KDEBUG
12533  Print("!");
12534  //if (TEST_OPT_DEBUG){Print("!");} // option teach
12535 #endif /* KDEBUG */
12536  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12537  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12538  /*
12539  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12540  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12541  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12542  *term of p devides the lcm(s,r)
12543  *(this canceling should be done here because
12544  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12545  *the first case is handeled in chainCrit
12546  */
12547  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12548 #ifdef CRITERION_DEBUG
12549  if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
12550 #endif
12551  }
12552  else
12553  {
12554  /*- the pair (S[i],p) enters B -*/
12555  /* both of them should have their LM in currRing and TAIL in tailring */
12556  Lp.p1 = q; // already in the needed form
12557  Lp.p2 = p; // already in the needed form
12558 
12559  if ( !rIsPluralRing(currRing) )
12560  pNext(Lp.p) = strat->tail;
12561 
12562  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12563  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12564  if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12565  {
12566  Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12567  Lp.i_r2 = atR;
12568  }
12569  else
12570  {
12571  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12572  Lp.i_r1 = -1;
12573  Lp.i_r2 = -1;
12574  }
12575  strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12576 
12578  {
12579  if (!rIsPluralRing(currRing)
12581  && (Lp.p->coef!=NULL))
12582  nDelete(&(Lp.p->coef));
12583  }
12584 
12585  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12586  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12587 #ifdef CRITERION_DEBUG
12588  if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
12589 #endif
12590  }
12591 }
12592 #endif
12593 
12594 #ifdef HAVE_SHIFTBBA
12595 /*3
12596 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12597 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12598 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
12599 */
12600 void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12601 {
12602  int h_lastVblock = pmLastVblock(h);
12603  assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12604  // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12605  if (h_lastVblock == 0) return;
12606  assume(pmFirstVblock(h) == 1);
12607  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12608  // atR = -1;
12609  if ((strat->syzComp==0)
12610  || (pGetComp(h)<=strat->syzComp))
12611  {
12612  int i,j;
12613  BOOLEAN new_pair=FALSE;
12614 
12615  int degbound = currRing->N/currRing->isLPring;
12616  int maxShift = degbound - h_lastVblock;
12617 
12618  if (pGetComp(h)==0)
12619  {
12620  if (strat->rightGB)
12621  {
12622  if (isFromQ)
12623  {
12624  // pairs (shifts(h),s[1..k]), (h, s[1..k])
12625  for (i=0; i<=maxShift; i++)
12626  {
12627  poly hh = pLPCopyAndShiftLM(h, i);
12628  for (j=0; j<=k; j++)
12629  {
12630  if (strat->fromQ == NULL || !strat->fromQ[j])
12631  {
12632  new_pair=TRUE;
12633  poly s = strat->S[j];
12634  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12635  }
12636  }
12637  }
12638  }
12639  else
12640  {
12641  new_pair=TRUE;
12642  for (j=0; j<=k; j++)
12643  {
12644  poly s = strat->S[j];
12645  if (strat->fromQ != NULL && strat->fromQ[j])
12646  {
12647  // pairs (shifts(s[j]),h), (s[j],h)
12648  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12649  }
12650  else
12651  {
12652  // pair (h, s[j])
12653  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12654  }
12655  }
12656  }
12657  }
12658  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12659  else if ((isFromQ)&&(strat->fromQ!=NULL))
12660  {
12661  // pairs (shifts(s[1..k]),h), (s[1..k],h)
12662  for (j=0; j<=k; j++) {
12663  if (!strat->fromQ[j])
12664  {
12665  new_pair=TRUE;
12666  poly s = strat->S[j];
12667  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12668  }
12669  }
12670  // pairs (shifts(h),s[1..k])
12671  if (new_pair)
12672  {
12673  for (i=1; i<=maxShift; i++)
12674  {
12675  poly hh = pLPCopyAndShiftLM(h, i);
12676  for (j=0; j<=k; j++)
12677  {
12678  if (!strat->fromQ[j])
12679  {
12680  poly s = strat->S[j];
12681  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12682  }
12683  }
12684  }
12685  }
12686  }
12687  else
12688  {
12689  new_pair=TRUE;
12690  // pairs (shifts(s[1..k]),h), (s[1..k],h)
12691  for (j=0; j<=k; j++) {
12692  poly s = strat->S[j];
12693  // TODO: cache lastVblock of s[1..k] for later use
12694  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12695  }
12696  // pairs (shifts(h),s[1..k]), (shifts(h), h)
12697  for (i=1; i<=maxShift; i++)
12698  {
12699  poly hh = pLPCopyAndShiftLM(h, i);
12700  for (j=0; j<=k; j++)
12701  {
12702  poly s = strat->S[j];
12703  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12704  }
12705  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12706  }
12707  }
12708  }
12709  else
12710  {
12711  new_pair=TRUE;
12712  if (strat->rightGB)
12713  {
12714  for (j=0; j<=k; j++)
12715  {
12716  if ((pGetComp(h)==pGetComp(strat->S[j]))
12717  || (pGetComp(strat->S[j])==0))
12718  {
12719  assume(isFromQ == 0); // this case is not handeled here and should also never happen
12720  poly s = strat->S[j];
12721  if (strat->fromQ != NULL && strat->fromQ[j])
12722  {
12723  // pairs (shifts(s[j]),h), (s[j],h)
12724  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12725  }
12726  else
12727  {
12728  // pair (h, s[j])
12729  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12730  }
12731  }
12732  }
12733  }
12734  else
12735  {
12736  // pairs (shifts(s[1..k]),h), (s[1..k],h)
12737  for (j=0; j<=k; j++) {
12738  if ((pGetComp(h)==pGetComp(strat->S[j]))
12739  || (pGetComp(strat->S[j])==0))
12740  {
12741  poly s = strat->S[j];
12742  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12743  }
12744  }
12745  // pairs (shifts(h),s[1..k]), (shifts(h), h)
12746  for (i=1; i<=maxShift; i++)
12747  {
12748  poly hh = pLPCopyAndShiftLM(h, i);
12749  for (j=0; j<=k; j++)
12750  {
12751  if ((pGetComp(h)==pGetComp(strat->S[j]))
12752  || (pGetComp(strat->S[j])==0))
12753  {
12754  poly s = strat->S[j];
12755  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12756  }
12757  }
12758  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12759  }
12760  }
12761  }
12762 
12763  if (new_pair)
12764  {
12765  strat->chainCrit(h,ecart,strat);
12766  }
12767  kMergeBintoL(strat);
12768  }
12769 }
12770 #endif
12771 
12772 #ifdef HAVE_SHIFTBBA
12773 /*2
12774 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
12775 *superfluous elements in S will be deleted
12776 */
12777 void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
12778 {
12779  /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12780  /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
12781  int j=pos;
12782 
12784  initenterpairsShift(h,k,ecart,0,strat, atR);
12785  if ( (!strat->fromT)
12786  && ((strat->syzComp==0)
12787  ||(pGetComp(h)<=strat->syzComp)))
12788  {
12789  unsigned long h_sev = pGetShortExpVector(h);
12790  loop
12791  {
12792  if (j > k) break;
12793  // TODO this currently doesn't clear all possible elements because of commutative division
12794  if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
12795  clearS(h,h_sev, &j,&k,strat);
12796  j++;
12797  }
12798  }
12799 }
12800 #endif
12801 
12802 #ifdef HAVE_SHIFTBBA
12803 /*2
12804 * enteres all admissible shifts of p into T
12805 * assumes that p is already in T!
12806 */
12807 void enterTShift(LObject p, kStrategy strat, int atT)
12808 {
12809  /* determine how many elements we have to insert */
12810  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12811  /* hence, a total number of elt's to add is: */
12812  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12813  pAssume(p.p != NULL);
12814 
12815  int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
12816 
12817  for (int i = 1; i <= maxPossibleShift; i++)
12818  {
12819  LObject qq;
12820  qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
12821  qq.shift = i;
12822  strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
12823 
12824  enterT(qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
12825  }
12826 }
12827 #endif
12828 
12829 #ifdef HAVE_SHIFTBBA
12830 poly redtailBbaShift (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
12831 {
12832  /* for the shift case need to run it with withT = TRUE */
12833  strat->redTailChange=FALSE;
12834  if (strat->noTailReduction) return L->GetLmCurrRing();
12835  poly h, p;
12836  p = h = L->GetLmTailRing();
12837  if ((h==NULL) || (pNext(h)==NULL))
12838  return L->GetLmCurrRing();
12839 
12840  TObject* With;
12841  // placeholder in case strat->tl < 0
12842  TObject With_s(strat->tailRing);
12843 
12844  LObject Ln(pNext(h), strat->tailRing);
12845  Ln.pLength = L->GetpLength() - 1;
12846 
12847  pNext(h) = NULL;
12848  if (L->p != NULL) pNext(L->p) = NULL;
12849  L->pLength = 1;
12850 
12851  Ln.PrepareRed(strat->use_buckets);
12852 
12853  while(!Ln.IsNull())
12854  {
12855  loop
12856  {
12857  Ln.SetShortExpVector();
12858  if (withT)
12859  {
12860  int j;
12861  j = kFindDivisibleByInT(strat, &Ln);
12862  if (j < 0) break;
12863  With = &(strat->T[j]);
12864  }
12865  else
12866  {
12867  With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
12868  if (With == NULL) break;
12869  }
12870  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
12871  {
12872  With->pNorm();
12873  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
12874  }
12875  strat->redTailChange=TRUE;
12876  if (ksReducePolyTail(L, With, &Ln))
12877  {
12878  // reducing the tail would violate the exp bound
12879  // set a flag and hope for a retry (in bba)
12880  strat->completeReduce_retry=TRUE;
12881  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
12882  do
12883  {
12884  pNext(h) = Ln.LmExtractAndIter();
12885  pIter(h);
12886  L->pLength++;
12887  } while (!Ln.IsNull());
12888  goto all_done;
12889  }
12890  if (Ln.IsNull()) goto all_done;
12891  if (! withT) With_s.Init(currRing);
12892  }
12893  pNext(h) = Ln.LmExtractAndIter();
12894  pIter(h);
12895  L->pLength++;
12896  }
12897 
12898  all_done:
12899  Ln.Delete();
12900  if (L->p != NULL) pNext(L->p) = pNext(p);
12901 
12902  if (strat->redTailChange)
12903  {
12904  L->length = 0;
12905  }
12906  L->Normalize(); // HANNES: should have a test
12907  kTest_L(L,strat->tailRing);
12908  return L->GetLmCurrRing();
12909 }
12910 #endif
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:755
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition: ideals.h:37
unsigned long * sevSig
Definition: kutil.h:320
#define REGISTER
Definition: omalloc.h:27
#define TEST_OPT_INFREDTAIL
Definition: options.h:115
#define __p_GetComp(p, r)
Definition: monomials.h:63
#define pSetmComp(p)
TODO:
Definition: polys.h:269
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1299
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:521
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2422
int getIndexRng(long coeff)
Definition: kutil.cc:6524
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6323
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
Definition: kbuckets.cc:197
denominator_list_s * denominator_list
Definition: kutil.h:59
void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
Definition: kutil.cc:9525
STATIC_VAR jList * Q
Definition: janet.cc:30
polyset sig
Definition: kutil.h:304
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11915
#define TEST_OPT_REDTAIL
Definition: options.h:114
STATIC_VAR gmp_float * diff
Definition: mpr_complex.cc:45
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:280
unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max)
return the maximal exponent of p in form of the maximal long var
Definition: p_polys.cc:1165
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,b,r) >=0
Definition: coeffs.h:628
#define pIsPurePower(p)
Definition: polys.h:244
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of &#39;a&#39; and &#39;b&#39; in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ...
Definition: coeffs.h:686
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition: kutil.cc:5136
KINLINE TObject ** initR()
Definition: kInline.h:95
const CanonicalForm int s
Definition: facAbsFact.cc:55
int posInTrg0(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5403
void initSbaPos(kStrategy strat)
Definition: kutil.cc:10318
char * pString(poly p)
Definition: polys.h:302
char fromT
Definition: kutil.h:378
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
Definition: old.gring.cc:2243
int j
Definition: facHensel.cc:105
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9390
char kHEdgeFound
Definition: kutil.h:375
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6820
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:964
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2824
#define pSetm(p)
Definition: polys.h:267
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:715
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1270
int kFindDivisibleByInT_Z(const kStrategy strat, const LObject *L, const int start)
Definition: kstd2.cc:139
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition: syz3.cc:1026
static FORCE_INLINE BOOLEAN n_IsUnit(number n, const coeffs r)
TRUE iff n has a multiplicative inverse in the given coeff field/ring r.
Definition: coeffs.h:515
#define pDivComp_LESS
Definition: kutil.cc:140
#define setmaxL
Definition: kutil.h:30
VAR int Kstd1_mu
Definition: kutil.cc:238
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:709
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:493
EXTERN_VAR short * ecartWeights
Definition: weight.h:12
omBin_t * omBin
Definition: omStructs.h:12
void PrintLn()
Definition: reporter.cc:310
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
int posInT2(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5296
#define Print
Definition: emacs.cc:80
int syzComp
Definition: kutil.h:352
long pLDeg1(poly p, int *l, const ring r)
Definition: p_polys.cc:831
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1655
KINLINE unsigned long * initsevT()
Definition: kInline.h:100
#define TEST_OPT_DEGBOUND
Definition: options.h:111
void enterTShift(LObject p, kStrategy strat, int atT)
Definition: kutil.cc:12807
#define pAdd(p, q)
Definition: polys.h:199
#define pDivComp_EQUAL
Definition: kutil.cc:139
void pLcmRat(poly a, poly b, poly m, int rat_shift)
Definition: ratgring.cc:30
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:10035
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:12209
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4805
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:289
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:69
int syzmax
Definition: kutil.h:347
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6365
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7954
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6435
poly kHEdge
Definition: kutil.h:325
char rightGB
Definition: kutil.h:368
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:295
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:995
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6399
#define pHasNotCFRing(p1, p2)
Definition: polys.h:258
static int * initS_2_R(const int maxnr)
Definition: kutil.cc:512
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357
class sLObject LObject
Definition: kutil.h:54
#define r_assume(x)
Definition: mod2.h:391
TObject * TSet
Definition: kutil.h:55
KINLINE TSet initT()
Definition: kInline.h:84
#define pLtCmpOrdSgnDiffM(p, q)
Definition: polys.h:125
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7995
bool sigdrop
Definition: kutil.h:358
#define TEST_OPT_PROT
Definition: options.h:101
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:11229
wlen_set lenSw
Definition: kutil.h:316
static int min(int a, int b)
Definition: fast_mult.cc:268
int Ll
Definition: kutil.h:349
#define pSetExp(p, i, v)
Definition: polys.h:42
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6779
static int si_min(const int a, const int b)
Definition: auxiliary.h:141
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7129
#define kTest_S(T)
Definition: kutil.h:657
long pLDeg1c(poly p, int *l, const ring r)
Definition: p_polys.cc:867
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:5213
#define FALSE
Definition: auxiliary.h:96
Compatiblity layer for legacy polynomial operations (over currRing)
int * S_2_R
Definition: kutil.h:340
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5268
void enterSBbaShift(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9371
char noTailReduction
Definition: kutil.h:377
long totaldegreeWecart(poly p, ring r)
Definition: weight.cc:217
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3192
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3769
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1093
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2210
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6864
int posInLrg0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6537
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5534
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10208
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1000
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1455
#define pAssume(cond)
Definition: monomials.h:90
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:105
int c3
Definition: kutil.h:345
char news
Definition: kutil.h:399
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:246
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:715
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition: kutil.cc:8879
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6744
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3894
#define p_GetComp(p, r)
Definition: monomials.h:64
#define pLPCopyAndShiftLM(p, sh)
Definition: shiftgb.h:15
poly prMoveR(poly &p, ring src_r, ring dest_r)
Definition: prCopy.cc:89
void reorderS(int *suc, kStrategy strat)
Definition: kutil.cc:4982
void redtailBbaAlsoLC_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7711
char newt
Definition: kutil.h:400
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:718
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4522
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition: p_polys.h:1966
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6709
static BOOLEAN rIsRatGRing(const ring r)
Definition: ring.h:423
BOOLEAN * NotUsedAxis
Definition: kutil.h:330
#define TEST_OPT_CONTENTSB
Definition: options.h:124
#define pDecrExp(p, i)
Definition: polys.h:44
rational (GMP) numbers
Definition: coeffs.h:31
char interpt
Definition: kutil.h:370
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:538
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:711
#define ppMult_mm(p, m)
Definition: polys.h:197
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:278
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6662
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:597
KINLINE int ksReducePolyTailLC_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1055
int length
Definition: kutil.h:74
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:587
static int pDivComp(poly p, poly q)
Definition: kutil.cc:187
int cv
Definition: kutil.h:367
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
int ksCheckCoeff(number *a, number *b)
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition: kutil.cc:1676
#define pNeg(p)
Definition: polys.h:194
void initSyzRules(kStrategy strat)
Definition: kutil.cc:8418
BOOLEAN * pairtest
Definition: kutil.h:331
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5690
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:760
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4859
poly kNoether
Definition: kutil.h:326
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition: p_polys.h:746
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3834
int tl
Definition: kutil.h:348
int Bl
Definition: kutil.h:350
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8171
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2642
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge, ring tailRing)
Definition: hdegree.cc:1004
int posInLRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6210
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
#define BTEST1(a)
Definition: options.h:33
#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 pLtCmp(p, q)
Definition: polys.h:123
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition: p_polys.cc:1630
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:990
static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
p_HasNotCF for the IDLIFT case: ignore component
Definition: kutil.cc:2193
char noClearS
Definition: kutil.h:401
#define TRUE
Definition: auxiliary.h:100
#define nIsOne(n)
Definition: numbers.h:25
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:4908
#define TEST_OPT_REDSB
Definition: options.h:102
static void kDeleteLcm(LObject *P)
Definition: kutil.h:869
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7836
poly pMove2CurrTail(poly p, kStrategy strat)
Definition: kutil.cc:12085
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:2088
#define pHasNotCF(p1, p2)
Definition: polys.h:259
#define degbound(p)
Definition: tgb.cc:153
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:12240
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8717
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1446
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1096
#define kTest(A)
Definition: kutil.h:654
char LDegLast
Definition: kutil.h:384
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:482
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:336
#define setmax
Definition: kutil.h:29
#define pLcm(a, b, m)
Definition: polys.h:291
unsigned long * sevT
Definition: kutil.h:321
void * ADDRESS
Definition: auxiliary.h:135
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:291
#define VAR
Definition: globaldefs.h:5
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:283
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11529
void pWrite(poly p)
Definition: polys.h:304
int ak
Definition: kutil.h:351
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:10994
#define setmaxLinc
Definition: kutil.h:31
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8268
void cancelunit(LObject *L, BOOLEAN inNF)
Definition: kutil.cc:333
poly max_exp
Definition: kutil.h:71
int k
Definition: cfEzgcd.cc:92
KINLINE void pNorm()
Definition: kInline.h:507
poly kCreateZeroPoly(long exp[], long cabsind, poly *t_p, ring leadRing, ring tailRing)
Definition: kutil.cc:4327
VAR int HCord
Definition: kutil.cc:236
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10420
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
Definition: old.gring.cc:1879
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1734
#define TEST_OPT_DEBUG
Definition: options.h:106
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1260
#define nEqual(n1, n2)
Definition: numbers.h:20
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2679
char * showOption()
Definition: misc_ip.cc:723
#define pLmDivisibleBy(a, b)
like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
Definition: polys.h:140
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:6311
#define loop
Definition: structs.h:80
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
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:900
#define WarnS
Definition: emacs.cc:78
poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing)
Definition: kspoly.cc:1409
static BOOLEAN rIsLPRing(const ring r)
Definition: ring.h:408
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:508
ring rAssure_c_dp(const ring r)
Definition: ring.cc:4910
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6978
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5636
int(* red)(LObject *L, kStrategy strat)
Definition: kutil.h:274
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omMergeStickyBinIntoBin(A, B)
Definition: xalloc.h:319
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:10121
int nextZeroSimplexExponent(long exp[], long ind[], long cexp[], long cind[], long *cabsind, long step[], long bound, long N)
Definition: kutil.cc:4261
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:822
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:1326
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8862
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:277
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:411
void HEckeTest(poly pp, kStrategy strat)
Definition: kutil.cc:468
#define omCheckBinAddrSize(addr, size)
Definition: omAllocDecl.h:326
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1965
void chainCritSig(poly p, int, kStrategy strat)
Definition: kutil.cc:3421
int currIdx
Definition: kutil.h:313
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:838
static void p_LmFree(poly p, ring)
Definition: p_polys.h:682
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4885
#define pGetComp(p)
Component.
Definition: polys.h:37
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6621
int minim
Definition: kutil.h:356
#define pLtCmpOrdSgnDiffP(p, q)
Definition: polys.h:126
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:5257
char use_buckets
Definition: kutil.h:382
int Bmax
Definition: kutil.h:350
int redFirstShift(LObject *h, kStrategy strat)
Definition: kstd2.cc:4485
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:811
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:1929
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4604
static FORCE_INLINE number n_Ann(number a, const coeffs r)
if r is a ring with zero divisors, return an annihilator!=0 of b otherwise return NULL ...
Definition: coeffs.h:701
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.h:288
skStrategy()
Definition: kutil.cc:11751
char completeReduce_retry
Definition: kutil.h:402
bool found
Definition: facFactorize.cc:56
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11502
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8967
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6123
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:931
CanonicalForm lc(const CanonicalForm &f)
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition: kutil.cc:10019
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9586
int HCord
Definition: kutil.h:353
#define mflush()
Definition: reporter.h:57
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
Definition: prCopy.cc:45
int redHoney(LObject *h, kStrategy strat)
Definition: kstd2.cc:1664
poly t_p
Definition: kutil.h:70
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2900
#define pIter(p)
Definition: monomials.h:37
KINLINE int GetpLength()
Definition: kInline.h:304
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1203
#define pFalseReturn(cond)
Definition: monomials.h:139
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:110
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
void(* initEcart)(TObject *L)
Definition: kutil.h:276
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.h:286
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8077
bool equal
Definition: cfModGcd.cc:4067
long twoPow(long arg)
Definition: kutil.cc:4138
CanonicalForm b
Definition: cfModGcd.cc:4044
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5326
static int rBlocks(ring r)
Definition: ring.h:563
int nrsyzcrit
Definition: kutil.h:359
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8573
int posInT17_c(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5838
int nrrewcrit
Definition: kutil.h:360
int p_mLPmaxPossibleShift(poly p, const ring r)
Definition: shiftgb.cc:45
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:577
char sugarCrit
Definition: kutil.h:376
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:905
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:3956
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5362
KINLINE TObject * S_2_T(int i)
Definition: kInline.h:38
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:216
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1306
#define TEST_OPT_INTSTRATEGY
Definition: options.h:108
#define nTest(a)
Definition: numbers.h:35
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:253
Definition: intvec.h:19
long FDeg
Definition: kutil.h:73
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
#define TEST_OPT_NOT_SUGAR
Definition: options.h:104
static FORCE_INLINE long n_Int(number &n, const coeffs r)
conversion of n to an int; 0 if not possible in Z/pZ: the representing int lying in (-p/2 ...
Definition: coeffs.h:547
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition: kutil.cc:517
#define setmaxT
Definition: kutil.h:33
#define kTest_TS(A)
Definition: kutil.h:655
CanonicalForm res
Definition: facAbsFact.cc:64
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:48
poly p_One(const ring r)
Definition: p_polys.cc:1303
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:3398
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:468
static int max(int a, int b)
Definition: fast_mult.cc:264
#define nGreaterZero(n)
Definition: numbers.h:27
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7405
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition: kutil.cc:675
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition: kutil.cc:4687
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9866
#define TEST_OPT_OLDSTD
Definition: options.h:120
#define assume(x)
Definition: mod2.h:390
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:397
intset fromQ
Definition: kutil.h:317
#define messageSets(s)
Definition: kutil.h:541
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3081
long p_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:586
LObject * LSet
Definition: kutil.h:56
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1365
void initEcartBBA(TObject *h)
Definition: kutil.cc:1292
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:12600
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5792
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:8008
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
#define pDivideM(a, b)
Definition: polys.h:290
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:248
#define kTest_L(T, R)
Definition: kutil.h:658
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl.cc )
Definition: polys.h:152
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
void enterOneZeroPairRing(poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:4146
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether &#39;a&#39; is divisible &#39;b&#39;; for r encoding a field: TRUE iff &#39;b&#39; does not represent zero in Z:...
Definition: coeffs.h:775
long pLDeg0(poly p, int *l, const ring r)
Definition: p_polys.cc:729
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition: polys.h:146
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:164
BOOLEAN pCompareChain(poly p, poly p1, poly p2, poly lcm, const ring R)
Returns TRUE if.
Definition: kpolys.cc:17
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:282
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2075
poly pMoveCurrTail2poly(poly p, kStrategy strat)
Definition: kutil.cc:12099
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1857
#define pmFirstVblock(p)
Definition: shiftop.h:35
rRingOrder_t
order stuff
Definition: ring.h:67
BOOLEAN idInsertPoly(ideal h1, poly h2)
insert h2 into h1 (if h2 is not the zero polynomial) return TRUE iff h2 was indeed inserted ...
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:379
#define pSetComp(p, v)
Definition: polys.h:38
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1500
#define pJet(p, m)
Definition: polys.h:364
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11403
int m
Definition: cfEzgcd.cc:121
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6065
LObject P
Definition: kutil.h:298
#define pIsConstant(p)
like above, except that Comp must be 0
Definition: polys.h:234
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9884
unsigned sbaOrder
Definition: kutil.h:312
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:887
static int si_max(const int a, const int b)
Definition: auxiliary.h:140
#define STATIC_VAR
Definition: globaldefs.h:7
poly * polyset
Definition: polys.h:255
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6914
#define __pp_Mult_nn(p, n, r)
Definition: p_polys.h:961
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition: p_polys.h:1252
#define pmIsInV(p)
Definition: shiftop.h:51
void exitSba(kStrategy strat)
Definition: kutil.cc:10493
void rDebugPrint(const ring r)
Definition: ring.cc:4045
FILE * f
Definition: checklibs.c:9
#define pLmIsConstantComp(p)
like above, except that p must be != NULL
Definition: polys.h:238
int i
Definition: cfEzgcd.cc:125
void PrintS(const char *s)
Definition: reporter.cc:284
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7595
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition: kutil.cc:11949
poly tail
Definition: kutil.h:332
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:244
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4841
#define pmLastVblock(p)
Definition: shiftop.h:33
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1350
VAR int strat_nr
Definition: kstdfac.cc:21
#define pOne()
Definition: polys.h:311
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5731
CanonicalForm H
Definition: facAbsFact.cc:64
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:702
TObject ** R
Definition: kutil.h:338
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL ...
Definition: polys.h:67
void deleteInSSba(int i, kStrategy strat)
Definition: kutil.cc:1148
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition: coeffs.h:522
polyset S
Definition: kutil.h:302
#define IDELEMS(i)
Definition: simpleideals.h:23
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1823
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:721
CFList tmp2
Definition: facFqBivar.cc:70
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
intset lenS
Definition: kutil.h:315
#define p_LmTest(p, r)
Definition: p_polys.h:163
#define nDelete(n)
Definition: numbers.h:16
int tmax
Definition: kutil.h:348
static FORCE_INLINE number n_Lcm(number a, number b, const coeffs r)
in Z: return the lcm of &#39;a&#39; and &#39;b&#39; in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ...
Definition: coeffs.h:712
int cp
Definition: kutil.h:345
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:756
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:12270
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9686
ideal idCopy(ideal A)
Definition: ideals.h:60
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7481
static void enlargeL(LSet *L, int *length, const int incr)
Definition: kutil.cc:656
#define p_Test(p, r)
Definition: p_polys.h:162
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:1782
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3609
void rChangeCurrRing(ring r)
Definition: polys.cc:15
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1130
int pLength
Definition: kutil.h:74
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10931
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:7045
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7188
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition: ideals.cc:728
poly sig
Definition: kutil.h:68
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1324
#define rRing_has_Comp(r)
Definition: monomials.h:266
#define nInvers(a)
Definition: numbers.h:33
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11824
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:860
static FORCE_INLINE number n_ExtGcd(number a, number b, number *s, number *t, const coeffs r)
beware that ExtGCD is only relevant for a few chosen coeff. domains and may perform something unexpec...
Definition: coeffs.h:693
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4687
intset ecartS
Definition: kutil.h:305
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35
STATIC_VAR Poly * h
Definition: janet.cc:971
poly t_kHEdge
Definition: kutil.h:327
void kMergeBintoLSba(kStrategy strat)
Definition: kutil.cc:3171
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
Definition: p_polys.h:487
void initenterzeropairsRing(poly p, int ecart, kStrategy strat, int atR)
Definition: kutil.cc:4390
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
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition: kutil.cc:7213
#define TEST_OPT_SUGARCRIT
Definition: options.h:105
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:7080
#define TEST_OPT_WEIGHTM
Definition: options.h:118
char homog
Definition: kutil.h:371
VAR int Kstd1_deg
Definition: kutil.cc:237
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:287
void initPairtest(kStrategy strat)
Definition: kutil.cc:666
long pLDegb(poly p, int *l, const ring r)
Definition: p_polys.cc:801
void mult(unsigned long *result, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:647
LSet L
Definition: kutil.h:323
char z2homog
Definition: kutil.h:373
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:11161
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:100
#define nIsZero(n)
Definition: numbers.h:19
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:479
#define NULL
Definition: omList.c:12
#define TEST_OPT_IDLIFT
Definition: options.h:126
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition: kutil.cc:1528
void cleanT(kStrategy strat)
Definition: kutil.cc:538
#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
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3656
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:965
LSet B
Definition: kutil.h:324
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4831
int Lmax
Definition: kutil.h:349
int64 wlen_type
Definition: kutil.h:50
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:166
#define pLtCmpOrdSgnEqP(p, q)
Definition: polys.h:128
BOOLEAN rHasGlobalOrdering(const ring r)
Definition: ring.h:754
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:448
long ind_fact_2(long arg)
Definition: kutil.cc:4123
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:6283
ring tailRing
Definition: kutil.h:341
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5479
int gcd(int a, int b)
Definition: walkSupport.cc:836
#define R
Definition: sirandom.c:27
#define TEST_OPT_SB_1
Definition: options.h:116
denominator_list next
Definition: kutil.h:61
CFList tmp1
Definition: facFqBivar.cc:70
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:61
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:263
poly t_kNoether
Definition: kutil.h:329
omBin tailBin
Definition: kutil.h:343
#define TEST_OPT_CANCELUNIT
Definition: options.h:125
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:9948
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:5035
#define pDelete(p_ptr)
Definition: polys.h:182
char overflow
Definition: kutil.h:403
#define omSizeWOfBin(bin_ptr)
int syzidxmax
Definition: kutil.h:347
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:9036
~skStrategy()
Definition: kutil.cc:11771
unsigned long * sevS
Definition: kutil.h:318
#define omGetStickyBinOfBin(B)
Definition: xalloc.h:290
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5521
#define nCopy(n)
Definition: numbers.h:15
static bool rIsSCA(const ring r)
Definition: nc.h:190
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:10745
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6091
STATIC_VAR unsigned add[]
Definition: misc_ip.cc:117
#define REDTAIL_CANONICALIZE
#define pNext(p)
Definition: monomials.h:36
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition: kutil.cc:10971
char honey
Definition: kutil.h:376
unsigned long * sevSyz
Definition: kutil.h:319
#define setmaxTinc
Definition: kutil.h:34
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3405
void rKillModifiedRing(ring r)
Definition: ring.cc:3002
long maxdegreeWecart(poly p, int *l, ring r)
Definition: weight.cc:247
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:232
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10533
static void pLmFree(poly p)
frees the space of the monomial m, assumes m != NULL coef is not freed, m is not advanced ...
Definition: polys.h:70
int * intset
Definition: kutil.h:49
#define pSetCoeff0(p, n)
Definition: monomials.h:59
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1178
#define p_GetCoeff(p, r)
Definition: monomials.h:50
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:47
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1028
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:528
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6022
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:1007
polyset syz
Definition: kutil.h:303
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:159
static intset initec(const int maxnr)
Definition: kutil.cc:503
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1120
static int pDivCompRing(poly p, poly q)
Definition: kutil.cc:148
int sl
Definition: kutil.h:346
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1058
poly pCopyL2p(LObject H, kStrategy strat)
Definition: kutil.cc:12116
int idElem(const ideal F)
count non-zero elements
int dReportError(const char *fmt,...)
Definition: dError.cc:43
TSet T
Definition: kutil.h:322
char posInLDependsOnLength
Definition: kutil.h:388
#define ALLOW_PROD_CRIT(A)
Definition: kutil.h:394
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1046
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:710
BOOLEAN isInPairsetB(poly q, int *k, kStrategy strat)
Definition: kutil.cc:696
omBin lmBin
Definition: kutil.h:342
long ind2(long arg)
Definition: kutil.cc:4111
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4577
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:603
char Gebauer
Definition: kutil.h:377
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8991
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3150
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:373
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1364
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:216
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10867
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5965
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:12830
void initEcartNormal(TObject *h)
Definition: kutil.cc:1284
int p
Definition: cfModGcd.cc:4019
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition: p_polys.cc:4432
ideal createG0()
Definition: kutil.cc:4456
void wrp(poly p)
Definition: polys.h:306
#define pDivComp_GREATER
Definition: kutil.cc:141
#define kTest_T(T)
Definition: kutil.h:656
#define pDivComp_INCOMP
Definition: kutil.cc:142
int LazyPass
Definition: kutil.h:351
static LSet initL(int nr=setmaxL)
Definition: kutil.h:420
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:895
int newIdeal
Definition: kutil.h:355
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:11318
ideal Shdl
Definition: kutil.h:299
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11878
#define nInit(i)
Definition: numbers.h:24
#define OPT_INTERRUPT
Definition: options.h:77
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5597
int BOOLEAN
Definition: auxiliary.h:87
kStrategy next
Definition: kutil.h:273
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
KINLINE poly kNoetherTail()
Definition: kInline.h:66
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition: kutil.cc:1317
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:12777
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2791
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
VAR denominator_list DENOMINATOR_LIST
Definition: kutil.cc:88
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3480
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:510
int ecart
Definition: kutil.h:74
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1287
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1053
KINLINE int ksReducePolyTail_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1073
char redTailChange
Definition: kutil.h:398
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:10292
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:294
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition: kutil.cc:7263
#define pLmEqual(p1, p2)
Definition: polys.h:111
int syzl
Definition: kutil.h:347
#define ENTER_USE_MEMMOVE
Definition: kutil.cc:51
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition: kstd1.cc:1006
int LazyDegree
Definition: kutil.h:351
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93
STATIC_VAR jList * T
Definition: janet.cc:30
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition: p_polys.h:1567
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5899
class sTObject TObject
Definition: kutil.h:53
Definition: nc.h:18
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5568
ring tailRing
Definition: kutil.h:72
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9788
poly p
Definition: kutil.h:69
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9271
intset syzIdx
Definition: kutil.h:309
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition: p_polys.cc:1198
#define nGreater(a, b)
Definition: numbers.h:28
#define pCopy(p)
return a copy of the poly
Definition: polys.h:181
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:349
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
Definition: kbuckets.cc:654
poly p_GetMaxExpP(poly p, const ring r)
return monomial r such that GetExp(r,i) is maximum of all monomials in p; coeff == 0...
Definition: p_polys.cc:1128
#define pNormalize(p)
Definition: polys.h:313
#define pIsVector(p)
Definition: polys.h:246
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6147
BOOLEAN pCompareChainPart(poly p, poly p1, poly p2, poly lcm, const ring R)
Definition: kpolys.cc:71
#define idIsConstant(I)
Definition: ideals.h:40
KINLINE long GetpFDeg() const
Definition: kInline.h:448