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 //#define ADIDEBUG 1
15 //All vs Just strategy over rings:
16 // 1 - Just
17 // 0 - All
18 #define ALL_VS_JUST 0
19 //Extended Spoly Strategy:
20 // 0 - new gen sig
21 // 1 - ann*old sig
22 #define EXT_POLY_NEW 0
23 
24 #include <kernel/mod2.h>
25 
26 #include <misc/mylimits.h>
27 #include <misc/options.h>
28 #include <polys/nc/nc.h>
29 #include <polys/nc/sca.h>
30 #include <polys/weight.h> /* for kDebugPrint: maxdegreeWecart*/
31 
32 #include <stdlib.h>
33 #include <string.h>
34 
35 #ifdef KDEBUG
36 #undef KDEBUG
37 #define KDEBUG 2
38 #endif
39 
40 #ifdef DEBUGF5
41 #undef DEBUGF5
42 //#define DEBUGF5 1
43 #endif
44 
45 #ifdef HAVE_RINGS
46 #include <kernel/ideals.h>
47 #endif
48 
49 // define if enterL, enterT should use memmove instead of doing it manually
50 // on topgun, this is slightly faster (see monodromy_l.tst, homog_gonnet.sing)
51 #ifndef SunOS_4
52 #define ENTER_USE_MEMMOVE
53 #endif
54 
55 // define, if the my_memmove inlines should be used instead of
56 // system memmove -- it does not seem to pay off, though
57 // #define ENTER_USE_MYMEMMOVE
58 
59 #include <kernel/GBEngine/kutil.h>
60 #include <polys/kbuckets.h>
61 #include <omalloc/omalloc.h>
62 #include <coeffs/numbers.h>
63 #include <kernel/polys.h>
64 #include <polys/monomials/ring.h>
65 #include <kernel/ideals.h>
66 //#include "cntrlc.h"
68 #include <kernel/GBEngine/kstd1.h>
70 
71 /* shiftgb stuff */
73 #include <polys/prCopy.h>
74 
75 #ifdef HAVE_RATGRING
77 #endif
78 
79 #ifdef KDEBUG
80 #undef KDEBUG
81 #define KDEBUG 2
82 #endif
83 
84 #ifdef DEBUGF5
85 #undef DEBUGF5
86 #define DEBUGF5 2
87 #endif
88 
90 
91 
92 #ifdef ENTER_USE_MYMEMMOVE
93 inline void _my_memmove_d_gt_s(unsigned long* d, unsigned long* s, long l)
94 {
95  register unsigned long* _dl = (unsigned long*) d;
96  register unsigned long* _sl = (unsigned long*) s;
97  register long _i = l - 1;
98 
99  do
100  {
101  _dl[_i] = _sl[_i];
102  _i--;
103  }
104  while (_i >= 0);
105 }
106 
107 inline void _my_memmove_d_lt_s(unsigned long* d, unsigned long* s, long l)
108 {
109  register long _ll = l;
110  register unsigned long* _dl = (unsigned long*) d;
111  register unsigned long* _sl = (unsigned long*) s;
112  register long _i = 0;
113 
114  do
115  {
116  _dl[_i] = _sl[_i];
117  _i++;
118  }
119  while (_i < _ll);
120 }
121 
122 inline void _my_memmove(void* d, void* s, long l)
123 {
124  unsigned long _d = (unsigned long) d;
125  unsigned long _s = (unsigned long) s;
126  unsigned long _l = ((l) + SIZEOF_LONG - 1) >> LOG_SIZEOF_LONG;
127 
128  if (_d > _s) _my_memmove_d_gt_s(_d, _s, _l);
129  else _my_memmove_d_lt_s(_d, _s, _l);
130 }
131 
132 #undef memmove
133 #define memmove(d,s,l) _my_memmove(d, s, l)
134 #endif
135 
136 static poly redMora (poly h,int maxIndex,kStrategy strat);
137 static poly redBba (poly h,int maxIndex,kStrategy strat);
138 
139 #ifdef HAVE_RINGS
140 #define pDivComp_EQUAL 2
141 #define pDivComp_LESS 1
142 #define pDivComp_GREATER -1
143 #define pDivComp_INCOMP 0
144 /* Checks the relation of LM(p) and LM(q)
145  LM(p) = LM(q) => return pDivComp_EQUAL
146  LM(p) | LM(q) => return pDivComp_LESS
147  LM(q) | LM(p) => return pDivComp_GREATER
148  else return pDivComp_INCOMP */
149 static inline int pDivCompRing(poly p, poly q)
150 {
151  if (pGetComp(p) == pGetComp(q))
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 (pGetComp(p) == pGetComp(q))
190  {
191 #ifdef HAVE_RATGRING
192  if (rIsRatGRing(currRing))
193  {
195  q,currRing,
196  currRing->real_var_start, currRing->real_var_end))
197  return 0;
198  return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
199  }
200 #endif
201  BOOLEAN a=FALSE, b=FALSE;
202  int i;
203  unsigned long la, lb;
204  unsigned long divmask = currRing->divmask;
205  for (i=0; i<currRing->VarL_Size; i++)
206  {
207  la = p->exp[currRing->VarL_Offset[i]];
208  lb = q->exp[currRing->VarL_Offset[i]];
209  if (la != lb)
210  {
211  if (la < lb)
212  {
213  if (b) return 0;
214  if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
215  return 0;
216  a = TRUE;
217  }
218  else
219  {
220  if (a) return 0;
221  if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
222  return 0;
223  b = TRUE;
224  }
225  }
226  }
227  if (a) { /*assume(pLmCmp(q,p)==1);*/ return 1; }
228  if (b) { /*assume(pLmCmp(q,p)==-1);*/return -1; }
229  /*assume(pLmCmp(q,p)==0);*/
230  }
231  return 0;
232 }
233 
234 
235 int HCord;
237 int Kstd1_mu=32000;
238 
239 /*2
240 *deletes higher monomial of p, re-compute ecart and length
241 *works only for orderings with ecart =pFDeg(end)-pFDeg(start)
242 */
243 void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
244 {
245  if (strat->kHEdgeFound)
246  {
247  kTest_L(L);
248  poly p1;
249  poly p = L->GetLmTailRing();
250  int l = 1;
252  if (L->bucket != NULL)
253  {
254  kBucketClear(L->bucket, &pNext(p), &L->pLength);
255  L->pLength++;
256  bucket = L->bucket;
257  L->bucket = NULL;
258  }
259 
260  if (!fromNext && p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
261  {
262  L->Delete();
263  L->Clear();
264  L->ecart = -1;
265  if (bucket != NULL) kBucketDestroy(&bucket);
266  return;
267  }
268  p1 = p;
269  while (pNext(p1)!=NULL)
270  {
271  if (p_LmCmp(pNext(p1), strat->kNoetherTail(), L->tailRing) == -1)
272  {
273  p_Delete(&pNext(p1), L->tailRing);
274  if (p1 == p)
275  {
276  if (L->t_p != NULL)
277  {
278  assume(L->p != NULL && p == L->t_p);
279  pNext(L->p) = NULL;
280  }
281  L->max_exp = NULL;
282  }
283  else if (fromNext)
284  L->max_exp = p_GetMaxExpP(pNext(L->p), L->tailRing ); // p1;
285  //if (L->pLength != 0)
286  L->pLength = l;
287  // Hmmm when called from updateT, then only
288  // reset ecart when cut
289  if (fromNext)
290  L->ecart = L->pLDeg() - L->GetpFDeg();
291  break;
292  }
293  l++;
294  pIter(p1);
295  }
296  if (! fromNext)
297  {
298  L->SetpFDeg();
299  L->ecart = L->pLDeg(strat->LDegLast) - L->GetpFDeg();
300  }
301  if (bucket != NULL)
302  {
303  if (L->pLength > 1)
304  {
305  kBucketInit(bucket, pNext(p), L->pLength - 1);
306  pNext(p) = NULL;
307  if (L->t_p != NULL) pNext(L->t_p) = NULL;
308  L->pLength = 0;
309  L->bucket = bucket;
310  }
311  else
312  kBucketDestroy(&bucket);
313  }
314  kTest_L(L);
315  }
316 }
317 
318 void deleteHC(poly* p, int* e, int* l,kStrategy strat)
319 {
320  LObject L(*p, currRing, strat->tailRing);
321 
322  deleteHC(&L, strat);
323  *p = L.p;
324  *e = L.ecart;
325  *l = L.length;
326  if (L.t_p != NULL) p_LmFree(L.t_p, strat->tailRing);
327 }
328 
329 /*2
330 *tests if p.p=monomial*unit and cancels the unit
331 */
332 void cancelunit (LObject* L,BOOLEAN inNF)
333 {
334  int i;
335  poly h;
336  number lc;
337 
338  if(rHasGlobalOrdering (currRing)) return;
339  if(TEST_OPT_CANCELUNIT) return;
340 
341  ring r = L->tailRing;
342  poly p = L->GetLmTailRing();
343 
344  if (rField_is_Ring(r) /*&& (rHasLocalOrMixedOrdering(r))*/)
345  lc = pGetCoeff(p);
346  #ifdef ADIDEBUG
347  printf("\n cancelunit\n");
348  pWrite(p);
349  #endif
350 #ifdef HAVE_RINGS
351  // Leading coef have to be a unit
352  // example 2x+4x2 should be simplified to 2x*(1+2x)
353  // and 2 is not a unit in Z
354  //if ( !(n_IsUnit(pGetCoeff(p), r->cf)) ) return;
355 #endif
356 
357  if(p_GetComp(p, r) != 0 && !p_OneComp(p, r)) return;
358 
359 // for(i=r->N;i>0;i--)
360 // {
361 // if ((p_GetExp(p,i,r)>0) && (rIsPolyVar(i, r)==TRUE)) return;
362 // }
363  h = pNext(p);
364 
366  {
367  loop
368  {
369  if (h==NULL)
370  {
371  p_Delete(&pNext(p), r);
372  if (!inNF)
373  {
374  number eins= nCopy(lc);
375  if (L->p != NULL)
376  {
377  pSetCoeff(L->p,eins);
378  if (L->t_p != NULL)
379  pSetCoeff0(L->t_p,eins);
380  }
381  else
382  pSetCoeff(L->t_p,eins);
383  /* p and t_p share the same coeff, if both are !=NULL */
384  /* p==NULL==t_p cannot happen here */
385  }
386  L->ecart = 0;
387  L->length = 1;
388  //if (L->pLength > 0)
389  L->pLength = 1;
390  L->max_exp = NULL;
391 
392  if (L->t_p != NULL && pNext(L->t_p) != NULL)
393  p_Delete(&pNext(L->t_p),r);
394  if (L->p != NULL && pNext(L->p) != NULL)
395  pNext(L->p) = NULL;
396 
397  return;
398  }
399  i = rVar(r);
400  loop
401  {
402  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
403  i--;
404  if (i == 0) break; // does divide, try next monom
405  }
406  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
407  // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
408  // domains), no zerodivisor test needed CAUTION
409  #ifdef ADIDEBUG
410  pWrite(h);
411  #endif
412  if (!n_DivBy(pGetCoeff(h),lc,r->cf))
413  {
414  #ifdef ADIDEBUG
415  printf("\nDoes not divide\n");
416  #endif
417  return;
418  }
419  #ifdef ADIDEBUG
420  printf("\nDivides. Go On\n");
421  #endif
422  pIter(h);
423  }
424  }
425  else
426  {
427  loop
428  {
429  if (h==NULL)
430  {
431  p_Delete(&pNext(p), r);
432  if (!inNF)
433  {
434  number eins=nInit(1);
435  if (L->p != NULL)
436  {
437  pSetCoeff(L->p,eins);
438  if (L->t_p != NULL)
439  pSetCoeff0(L->t_p,eins);
440  }
441  else
442  pSetCoeff(L->t_p,eins);
443  /* p and t_p share the same coeff, if both are !=NULL */
444  /* p==NULL==t_p cannot happen here */
445  }
446  L->ecart = 0;
447  L->length = 1;
448  //if (L->pLength > 0)
449  L->pLength = 1;
450  L->max_exp = NULL;
451 
452  if (L->t_p != NULL && pNext(L->t_p) != NULL)
453  p_Delete(&pNext(L->t_p),r);
454  if (L->p != NULL && pNext(L->p) != NULL)
455  pNext(L->p) = NULL;
456 
457  return;
458  }
459  i = rVar(r);
460  loop
461  {
462  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
463  i--;
464  if (i == 0) break; // does divide, try next monom
465  }
466  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
467  pIter(h);
468  }
469  }
470 }
471 
472 /*2
473 *pp is the new element in s
474 *returns TRUE (in strat->kHEdgeFound) if
475 *-HEcke is allowed
476 *-we are in the last componente of the vector
477 *-on all axis are monomials (all elements in NotUsedAxis are FALSE)
478 *returns FALSE for pLexOrderings,
479 *assumes in module case an ordering of type c* !!
480 * HEckeTest is only called with strat->kHEdgeFound==FALSE !
481 */
483 {
484  int j,/*k,*/p;
485 
486  strat->kHEdgeFound=FALSE;
487  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
488  {
489  return;
490  }
491  if (strat->ak > 1) /*we are in the module case*/
492  {
493  return; // until ....
494  //if (!pVectorOut) /*pVectorOut <=> order = c,* */
495  // return FALSE;
496  //if (pGetComp(pp) < strat->ak) /* ak is the number of the last component */
497  // return FALSE;
498  }
499  // k = 0;
500  p=pIsPurePower(pp);
501  if (rField_is_Ring(currRing) && (!n_IsUnit(pGetCoeff(pp),currRing->cf))) return;
502  if (p!=0) strat->NotUsedAxis[p] = FALSE;
503  /*- the leading term of pp is a power of the p-th variable -*/
504  for (j=(currRing->N);j>0; j--)
505  {
506  if (strat->NotUsedAxis[j])
507  {
508  return;
509  }
510  }
511  strat->kHEdgeFound=TRUE;
512 }
513 
514 /*2
515 *utilities for TSet, LSet
516 */
517 inline static intset initec (const int maxnr)
518 {
519  return (intset)omAlloc(maxnr*sizeof(int));
520 }
521 
522 inline static unsigned long* initsevS (const int maxnr)
523 {
524  return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
525 }
526 inline static int* initS_2_R (const int maxnr)
527 {
528  return (int*)omAlloc0(maxnr*sizeof(int));
529 }
530 
531 static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
532  int &length, const int incr)
533 {
534  assume(T!=NULL);
535  assume(sevT!=NULL);
536  assume(R!=NULL);
537  assume((length+incr) > 0);
538 
539  int i;
540  T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
541  (length+incr)*sizeof(TObject));
542 
543  sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
544  (length+incr)*sizeof(long*));
545 
546  R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
547  (length+incr)*sizeof(TObject*));
548  for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
549  length += incr;
550 }
551 
552 void cleanT (kStrategy strat)
553 {
554  int i,j;
555  poly p;
556  assume(currRing == strat->tailRing || strat->tailRing != NULL);
557 
558  pShallowCopyDeleteProc p_shallow_copy_delete =
559  (strat->tailRing != currRing ?
561  NULL);
562  for (j=0; j<=strat->tl; j++)
563  {
564  p = strat->T[j].p;
565  strat->T[j].p=NULL;
566  if (strat->T[j].max_exp != NULL)
567  {
568  p_LmFree(strat->T[j].max_exp, strat->tailRing);
569  }
570  i = -1;
571  loop
572  {
573  i++;
574  if (i>strat->sl)
575  {
576  if (strat->T[j].t_p != NULL)
577  {
578  p_Delete(&(strat->T[j].t_p), strat->tailRing);
579  p_LmFree(p, currRing);
580  }
581  else
582  {
583  pDelete(&p);
584  }
585  break;
586  }
587  if (p == strat->S[i])
588  {
589  if (strat->T[j].t_p != NULL)
590  {
591  assume(p_shallow_copy_delete != NULL);
592  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
593  currRing->PolyBin);
594  p_LmFree(strat->T[j].t_p, strat->tailRing);
595  }
596  break;
597  }
598  }
599  }
600  strat->tl=-1;
601 }
602 
604 {
605  int i,j;
606  poly p;
607  assume(currRing == strat->tailRing || strat->tailRing != NULL);
608 
609  pShallowCopyDeleteProc p_shallow_copy_delete =
610  (strat->tailRing != currRing ?
612  NULL);
613  for (j=0; j<=strat->tl; j++)
614  {
615  p = strat->T[j].p;
616  strat->T[j].p=NULL;
617  if (strat->T[j].max_exp != NULL)
618  {
619  p_LmFree(strat->T[j].max_exp, strat->tailRing);
620  }
621  i = -1;
622  loop
623  {
624  i++;
625  if (i>strat->sl)
626  {
627  if (strat->T[j].t_p != NULL)
628  {
629  p_Delete(&(strat->T[j].t_p), strat->tailRing);
630  p_LmFree(p, currRing);
631  }
632  else
633  {
634  //pDelete(&p);
635  p = NULL;
636  }
637  break;
638  }
639  if (p == strat->S[i])
640  {
641  if (strat->T[j].t_p != NULL)
642  {
643  assume(p_shallow_copy_delete != NULL);
644  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
645  currRing->PolyBin);
646  p_LmFree(strat->T[j].t_p, strat->tailRing);
647  }
648  break;
649  }
650  }
651  }
652  strat->tl=-1;
653 }
654 
655 //LSet initL ()
656 //{
657 // int i;
658 // LSet l = (LSet)omAlloc(setmaxL*sizeof(LObject));
659 // return l;
660 //}
661 
662 static inline void enlargeL (LSet* L,int* length,const int incr)
663 {
664  assume((*L)!=NULL);
665  assume(((*length)+incr)>0);
666 
667  *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
668  ((*length)+incr)*sizeof(LObject));
669  (*length) += incr;
670 }
671 
673 {
674  strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
675 }
676 
677 /*2
678 *test whether (p1,p2) or (p2,p1) is in L up position length
679 *it returns TRUE if yes and the position k
680 */
681 BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
682 {
683  LObject *p=&(strat->L[length]);
684 
685  *k = length;
686  loop
687  {
688  if ((*k) < 0) return FALSE;
689  if (((p1 == (*p).p1) && (p2 == (*p).p2))
690  || ((p1 == (*p).p2) && (p2 == (*p).p1)))
691  return TRUE;
692  (*k)--;
693  p--;
694  }
695 }
696 
697 /*2
698 *in B all pairs have the same element p on the right
699 *it tests whether (q,p) is in B and returns TRUE if yes
700 *and the position k
701 */
703 {
704  LObject *p=&(strat->B[strat->Bl]);
705 
706  *k = strat->Bl;
707  loop
708  {
709  if ((*k) < 0) return FALSE;
710  if (q == (*p).p1)
711  return TRUE;
712  (*k)--;
713  p--;
714  }
715 }
716 
717 int kFindInT(poly p, TSet T, int tlength)
718 {
719  int i;
720 
721  for (i=0; i<=tlength; i++)
722  {
723  if (T[i].p == p) return i;
724  }
725  return -1;
726 }
727 
729 {
730  int i;
731  do
732  {
733  i = kFindInT(p, strat->T, strat->tl);
734  if (i >= 0) return i;
735  strat = strat->next;
736  }
737  while (strat != NULL);
738  return -1;
739 }
740 
741 #ifdef KDEBUG
742 
743 void sTObject::wrp()
744 {
745  if (t_p != NULL) p_wrp(t_p, tailRing);
746  else if (p != NULL) p_wrp(p, currRing, tailRing);
747  else ::wrp(NULL);
748 }
749 
750 #define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
751 
752 // check that Lm's of a poly from T are "equal"
753 static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
754 {
755  int i;
756  for (i=1; i<=tailRing->N; i++)
757  {
758  if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
759  return "Lm[i] different";
760  }
761  if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
762  return "Lm[0] different";
763  if (pNext(p) != pNext(t_p))
764  return "Lm.next different";
765  if (pGetCoeff(p) != pGetCoeff(t_p))
766  return "Lm.coeff different";
767  return NULL;
768 }
769 
770 static BOOLEAN sloppy_max = FALSE;
771 BOOLEAN kTest_T(TObject * T, ring strat_tailRing, int i, char TN)
772 {
773  ring tailRing = T->tailRing;
774  if (strat_tailRing == NULL) strat_tailRing = tailRing;
775  r_assume(strat_tailRing == tailRing);
776 
777  poly p = T->p;
778  // ring r = currRing;
779 
780  if (T->p == NULL && T->t_p == NULL && i >= 0)
781  return dReportError("%c[%d].poly is NULL", TN, i);
782 
783  if (T->tailRing != currRing)
784  {
785  if (T->t_p == NULL && i > 0)
786  return dReportError("%c[%d].t_p is NULL", TN, i);
787  pFalseReturn(p_Test(T->t_p, T->tailRing));
788  if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
789  if (T->p != NULL && T->t_p != NULL)
790  {
791  const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
792  if (msg != NULL)
793  return dReportError("%c[%d] %s", TN, i, msg);
794  // r = T->tailRing;
795  p = T->t_p;
796  }
797  if (T->p == NULL)
798  {
799  p = T->t_p;
800  // r = T->tailRing;
801  }
802  if (T->t_p != NULL && i >= 0 && TN == 'T')
803  {
804  if (pNext(T->t_p) == NULL)
805  {
806  if (T->max_exp != NULL)
807  return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
808  }
809  else
810  {
811  if (T->max_exp == NULL)
812  return dReportError("%c[%d].max_exp is NULL", TN, i);
813  if (pNext(T->max_exp) != NULL)
814  return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
815 
816  pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
817  omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
818 #if KDEBUG > 0
819  if (! sloppy_max)
820  {
821  poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
822  p_Setm(T->max_exp, tailRing);
823  p_Setm(test_max, tailRing);
824  BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
825  if (! equal)
826  return dReportError("%c[%d].max out of sync", TN, i);
827  p_LmFree(test_max, tailRing);
828  }
829 #endif
830  }
831  }
832  }
833  else
834  {
835  if (T->p == NULL && i > 0)
836  return dReportError("%c[%d].p is NULL", TN, i);
838  }
839 
840  if ((i >= 0) && (T->pLength != 0)
841  && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
842  {
843  int l=T->pLength;
844  T->pLength=pLength(p);
845  return dReportError("%c[%d] pLength error: has %d, specified to have %d",
846  TN, i , pLength(p), l);
847  }
848 
849  // check FDeg, for elements in L and T
850  if (i >= 0 && (TN == 'T' || TN == 'L'))
851  {
852  // FDeg has ir element from T of L set
853  if (T->FDeg != T->pFDeg())
854  {
855  int d=T->FDeg;
856  T->FDeg=T->pFDeg();
857  return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
858  TN, i , T->pFDeg(), d);
859  }
860  }
861 
862  // check is_normalized for elements in T
863  if (i >= 0 && TN == 'T')
864  {
865  if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
866  return dReportError("T[%d] is_normalized error", i);
867 
868  }
869  return TRUE;
870 }
871 
872 BOOLEAN kTest_L(LObject *L, ring strat_tailRing,
873  BOOLEAN testp, int lpos, TSet T, int tlength)
874 {
875  if (testp)
876  {
877  poly pn = NULL;
878  if (L->bucket != NULL)
879  {
880  kFalseReturn(kbTest(L->bucket));
881  r_assume(L->bucket->bucket_ring == L->tailRing);
882  if (L->p != NULL && pNext(L->p) != NULL)
883  {
884  pn = pNext(L->p);
885  pNext(L->p) = NULL;
886  }
887  }
888  if (testp!=2) kFalseReturn(kTest_T(L, strat_tailRing, lpos, 'L'));
889  if (pn != NULL)
890  pNext(L->p) = pn;
891 
892  ring r;
893  poly p;
894  L->GetLm(p, r);
895  if (L->sev != 0 && p_GetShortExpVector(p, r) != L->sev)
896  {
897  return dReportError("L[%d] wrong sev: has %o, specified to have %o",
898  lpos, p_GetShortExpVector(p, r), L->sev);
899  }
900  }
901  if (L->p1 == NULL)
902  {
903  // L->p2 either NULL or "normal" poly
904  pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
905  }
906  else if (tlength > 0 && T != NULL && (lpos >=0) && (testp!=2))
907  {
908  // now p1 and p2 must be != NULL and must be contained in T
909  // unless for SHIFTGB: here each p_i must be in T or
910  // be shifted from an element in T -> to difficult to test
911  int i;
912  i = kFindInT(L->p1, T, tlength);
913  if (i < 0)
914  return dReportError("L[%d].p1 not in T",lpos);
915  i = kFindInT(L->p2, T, tlength);
916  if (i < 0)
917  return dReportError("L[%d].p2 not in T",lpos);
918  }
919  return TRUE;
920 }
921 
922 BOOLEAN kTest (kStrategy strat)
923 {
924  int i;
925  // test P
926  kFalseReturn(kTest_L(&(strat->P), strat->tailRing,
927  (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
928  -1, strat->T, strat->tl));
929 
930  // test T
931  if (strat->T != NULL)
932  {
933  for (i=0; i<=strat->tl; i++)
934  {
935  kFalseReturn(kTest_T(&(strat->T[i]), strat->tailRing, i, 'T'));
936  if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
937  return dReportError("strat->sevT[%d] out of sync", i);
938  }
939  }
940 
941  // test L
942  if (strat->L != NULL)
943  {
944  #ifdef HAVE_SHIFTBBA
945  if (strat->red==redFirstShift) // is this in bbaShift ?
946  {
947  for (i=0; i<=strat->Ll; i++)
948  {
949  kFalseReturn(kTest_L(&(strat->L[i]), strat->tailRing,
950  2, i,
951  strat->T, strat->tl));
952  }
953  }
954  else
955  #endif
956  for (i=0; i<=strat->Ll; i++)
957  {
958  kFalseReturn(kTest_L(&(strat->L[i]), strat->tailRing,
959  strat->L[i].Next() != strat->tail, i,
960  strat->T, strat->tl));
961  // may be unused
962  //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
963  // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
964  //{
965  // assume(strat->L[i].bucket != NULL);
966  //}
967  }
968  }
969 
970  // test S
971  if (strat->S != NULL)
972  kFalseReturn(kTest_S(strat));
973 
974  return TRUE;
975 }
976 
978 {
979  int i;
980  BOOLEAN ret = TRUE;
981  for (i=0; i<=strat->sl; i++)
982  {
983  if (strat->S[i] != NULL &&
984  strat->sevS[i] != pGetShortExpVector(strat->S[i]))
985  {
986  return dReportError("S[%d] wrong sev: has %o, specified to have %o",
987  i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
988  }
989  }
990  return ret;
991 }
992 
993 
994 
996 {
997  int i, j;
998  // BOOLEAN ret = TRUE;
999  kFalseReturn(kTest(strat));
1000 
1001  // test strat->R, strat->T[i].i_r
1002  for (i=0; i<=strat->tl; i++)
1003  {
1004  if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1005  return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1006  strat->T[i].i_r);
1007  if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1008  return dReportError("T[%d].i_r with R out of sync", i);
1009  }
1010  // test containment of S inT
1011  if (strat->S != NULL)
1012  {
1013  for (i=0; i<=strat->sl; i++)
1014  {
1015  j = kFindInT(strat->S[i], strat->T, strat->tl);
1016  if (j < 0)
1017  return dReportError("S[%d] not in T", i);
1018  if (strat->S_2_R[i] != strat->T[j].i_r)
1019  return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1020  i, strat->S_2_R[i], j, strat->T[j].i_r);
1021  }
1022  }
1023  // test strat->L[i].i_r1
1024  #ifdef HAVE_SHIFTBBA
1025  if (strat->red!=redFirstShift) // not from bbaShift
1026  #endif
1027  for (i=0; i<=strat->Ll; i++)
1028  {
1029  if (strat->L[i].p1 != NULL && strat->L[i].p2)
1030  {
1031  if (strat->L[i].i_r1 < 0 ||
1032  strat->L[i].i_r1 > strat->tl ||
1033  strat->L[i].T_1(strat)->p != strat->L[i].p1)
1034  return dReportError("L[%d].i_r1 out of sync", i);
1035  if (strat->L[i].i_r2 < 0 ||
1036  strat->L[i].i_r2 > strat->tl ||
1037  strat->L[i].T_2(strat)->p != strat->L[i].p2)
1038  return dReportError("L[%d].i_r2 out of sync", i);
1039  }
1040  else
1041  {
1042  if (strat->L[i].i_r1 != -1)
1043  return dReportError("L[%d].i_r1 out of sync", i);
1044  if (strat->L[i].i_r2 != -1)
1045  return dReportError("L[%d].i_r2 out of sync", i);
1046  }
1047  if (strat->L[i].i_r != -1)
1048  return dReportError("L[%d].i_r out of sync", i);
1049  }
1050  return TRUE;
1051 }
1052 
1053 #endif // KDEBUG
1054 
1055 /*2
1056 *cancels the i-th polynomial in the standardbase s
1057 */
1058 void deleteInS (int i,kStrategy strat)
1059 {
1060 #ifdef ENTER_USE_MEMMOVE
1061  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1062  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1063  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1064  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1065 #else
1066  int j;
1067  for (j=i; j<strat->sl; j++)
1068  {
1069  strat->S[j] = strat->S[j+1];
1070  strat->ecartS[j] = strat->ecartS[j+1];
1071  strat->sevS[j] = strat->sevS[j+1];
1072  strat->S_2_R[j] = strat->S_2_R[j+1];
1073  }
1074 #endif
1075  if (strat->lenS!=NULL)
1076  {
1077 #ifdef ENTER_USE_MEMMOVE
1078  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1079 #else
1080  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1081 #endif
1082  }
1083  if (strat->lenSw!=NULL)
1084  {
1085 #ifdef ENTER_USE_MEMMOVE
1086  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1087 #else
1088  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1089 #endif
1090  }
1091  if (strat->fromQ!=NULL)
1092  {
1093 #ifdef ENTER_USE_MEMMOVE
1094  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1095 #else
1096  for (j=i; j<strat->sl; j++)
1097  {
1098  strat->fromQ[j] = strat->fromQ[j+1];
1099  }
1100 #endif
1101  }
1102  strat->S[strat->sl] = NULL;
1103  strat->sl--;
1104 }
1105 
1106 
1107 /*2
1108 *cancels the i-th polynomial in the standardbase s
1109 */
1110 void deleteInSSba (int i,kStrategy strat)
1111 {
1112 #ifdef ENTER_USE_MEMMOVE
1113  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1114  memmove(&(strat->sig[i]), &(strat->sig[i+1]), (strat->sl - i)*sizeof(poly));
1115  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1116  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1117  memmove(&(strat->sevSig[i]),&(strat->sevSig[i+1]),(strat->sl - i)*sizeof(unsigned long));
1118  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1119 #else
1120  int j;
1121  for (j=i; j<strat->sl; j++)
1122  {
1123  strat->S[j] = strat->S[j+1];
1124  strat->sig[j] = strat->sig[j+1];
1125  strat->ecartS[j] = strat->ecartS[j+1];
1126  strat->sevS[j] = strat->sevS[j+1];
1127  strat->sevSig[j] = strat->sevSig[j+1];
1128  strat->S_2_R[j] = strat->S_2_R[j+1];
1129  }
1130 #endif
1131  if (strat->lenS!=NULL)
1132  {
1133 #ifdef ENTER_USE_MEMMOVE
1134  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1135 #else
1136  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1137 #endif
1138  }
1139  if (strat->lenSw!=NULL)
1140  {
1141 #ifdef ENTER_USE_MEMMOVE
1142  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1143 #else
1144  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1145 #endif
1146  }
1147  if (strat->fromQ!=NULL)
1148  {
1149 #ifdef ENTER_USE_MEMMOVE
1150  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1151 #else
1152  for (j=i; j<strat->sl; j++)
1153  {
1154  strat->fromQ[j] = strat->fromQ[j+1];
1155  }
1156 #endif
1157  }
1158  strat->S[strat->sl] = NULL;
1159  strat->sl--;
1160 }
1161 
1162 /*2
1163 *cancels the j-th polynomial in the set
1164 */
1165 void deleteInL (LSet set, int *length, int j,kStrategy strat)
1166 {
1167  if (set[j].lcm!=NULL)
1168  {
1169 #ifdef HAVE_RINGS
1170  if (pGetCoeff(set[j].lcm) != NULL)
1171  pLmDelete(set[j].lcm);
1172  else
1173 #endif
1174  pLmFree(set[j].lcm);
1175  }
1176  if (set[j].sig!=NULL)
1177  {
1178 #ifdef HAVE_RINGS
1179  if (pGetCoeff(set[j].sig) != NULL)
1180  pLmDelete(set[j].sig);
1181  else
1182 #endif
1183  pLmFree(set[j].sig);
1184  }
1185  if (set[j].p!=NULL)
1186  {
1187  if (pNext(set[j].p) == strat->tail)
1188  {
1189 #ifdef HAVE_RINGS
1190  if (pGetCoeff(set[j].p) != NULL)
1191  pLmDelete(set[j].p);
1192  else
1193 #endif
1194  pLmFree(set[j].p);
1195  /*- tail belongs to several int spolys -*/
1196  }
1197  else
1198  {
1199  // search p in T, if it is there, do not delete it
1200  if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1201  {
1202  // assure that for global orderings kFindInT fails
1203  //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1204  set[j].Delete();
1205  }
1206  }
1207  }
1208  if (*length > 0 && j < *length)
1209  {
1210 #ifdef ENTER_USE_MEMMOVE
1211  memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1212 #else
1213  int i;
1214  for (i=j; i < (*length); i++)
1215  set[i] = set[i+1];
1216 #endif
1217  }
1218 #ifdef KDEBUG
1219  memset(&(set[*length]),0,sizeof(LObject));
1220 #endif
1221  (*length)--;
1222 }
1223 
1224 /*2
1225 *enters p at position at in L
1226 */
1227 void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1228 {
1229  // this should be corrected
1230  assume(p.FDeg == p.pFDeg());
1231 
1232  if ((*length)>=0)
1233  {
1234  if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1235  if (at <= (*length))
1236 #ifdef ENTER_USE_MEMMOVE
1237  memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1238 #else
1239  for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1240 #endif
1241  }
1242  else at = 0;
1243  (*set)[at] = p;
1244  (*length)++;
1245 }
1246 
1247 /*2
1248 * computes the normal ecart;
1249 * used in mora case and if pLexOrder & sugar in bba case
1250 */
1252 {
1253  h->FDeg = h->pFDeg();
1254  h->ecart = h->pLDeg() - h->FDeg;
1255  // h->length is set by h->pLDeg
1256  h->length=h->pLength=pLength(h->p);
1257 }
1258 
1260 {
1261  h->FDeg = h->pFDeg();
1262  (*h).ecart = 0;
1263  h->length=h->pLength=pLength(h->p);
1264 }
1265 
1266 void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1267 {
1268  Lp->FDeg = Lp->pFDeg();
1269  (*Lp).ecart = 0;
1270  (*Lp).length = 0;
1271 }
1272 
1273 void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1274 {
1275  Lp->FDeg = Lp->pFDeg();
1276  (*Lp).ecart = si_max(ecartF,ecartG);
1277  (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1278  (*Lp).length = 0;
1279 }
1280 
1281 /*2
1282 *if ecart1<=ecart2 it returns TRUE
1283 */
1284 static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1285 {
1286  return (ecart1 <= ecart2);
1287 }
1288 
1289 #ifdef HAVE_RINGS
1290 /*2
1291 * put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1292 */
1293 static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1294 {
1295  assume(atR >= 0);
1296  assume(i<=strat->sl);
1297  assume(p!=NULL);
1298  #if ALL_VS_JUST
1299  //Over rings, if we construct the strong pair, do not add the spair
1301  {
1302  number s,t,d;
1303  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1304 
1305  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1306  {
1307  nDelete(&d);
1308  nDelete(&s);
1309  nDelete(&t);
1310  return;
1311  }
1312  nDelete(&d);
1313  nDelete(&s);
1314  nDelete(&t);
1315  }
1316  #endif
1317  int j,compare,compareCoeff;
1318  LObject h;
1319 
1320 #ifdef KDEBUG
1321  h.ecart=0; h.length=0;
1322 #endif
1323  /*- computes the lcm(s[i],p) -*/
1324  h.lcm = pInit();
1325  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1326  if (nIsZero(pGetCoeff(h.lcm)))
1327  {
1328  strat->cp++;
1329  pLmDelete(h.lcm);
1330  return;
1331  }
1332  // basic chain criterion
1333  pLcm(p,strat->S[i],h.lcm);
1334  pSetm(h.lcm);
1335  /*
1336  *the set B collects the pairs of type (S[j],p)
1337  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1338  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
1339  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
1340  */
1341 
1342  for(j = strat->Bl;j>=0;j--)
1343  {
1344  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1345  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1346  #ifdef ADIDEBUG
1347  printf("\nChainCrit in enteronepairring\n");
1348  printf("\nB[j]\n");
1349  pWrite(strat->B[j].p);
1350  pWrite(strat->B[j].p1);
1351  pWrite(strat->B[j].p2);
1352  pWrite(strat->B[j].lcm);
1353  printf("\nh - neue Paar\n");
1354  pWrite(h.p);
1355  pWrite(p);
1356  pWrite(strat->S[i]);
1357  pWrite(h.lcm);
1358  printf("\ncompare = %i\ncompareCoeff = %i\n",compare,compareCoeff);
1359  #endif
1360  if(compare == pDivComp_EQUAL)
1361  {
1362  //They have the same LM
1363  if(compareCoeff == pDivComp_LESS)
1364  {
1365  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1366  {
1367  #ifdef ADIDEBUG
1368  printf("\nGelöscht h\n");
1369  #endif
1370  strat->c3++;
1371  pLmDelete(h.lcm);
1372  return;
1373  }
1374  break;
1375  }
1376  if(compareCoeff == pDivComp_GREATER)
1377  {
1378  #ifdef ADIDEBUG
1379  printf("\nGelöscht: B[j]\n");
1380  #endif
1381  deleteInL(strat->B,&strat->Bl,j,strat);
1382  strat->c3++;
1383  }
1384  if(compareCoeff == pDivComp_EQUAL)
1385  {
1386  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1387  {
1388  #ifdef ADIDEBUG
1389  printf("\nGelöscht h\n");
1390  #endif
1391  strat->c3++;
1392  pLmDelete(h.lcm);
1393  return;
1394  }
1395  break;
1396  }
1397  }
1398  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1399  {
1400  if(compare == pDivComp_LESS)
1401  {
1402  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1403  {
1404  #ifdef ADIDEBUG
1405  printf("\nGelöscht h\n");
1406  #endif
1407  strat->c3++;
1408  pLmDelete(h.lcm);
1409  return;
1410  }
1411  break;
1412  }
1413  if(compare == pDivComp_GREATER)
1414  {
1415  #ifdef ADIDEBUG
1416  printf("\nGelöscht: B[j]\n");
1417  #endif
1418  deleteInL(strat->B,&strat->Bl,j,strat);
1419  strat->c3++;
1420  }
1421  }
1422  }
1423  number s, t;
1424  poly m1, m2, gcd = NULL;
1425  #ifdef ADIDEBUG
1426  printf("\nTrying to add spair S[%i] und p\n",i);pWrite(strat->S[i]);pWrite(p);
1427  #endif
1428  s = pGetCoeff(strat->S[i]);
1429  t = pGetCoeff(p);
1430  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1431  ksCheckCoeff(&s, &t, currRing->cf);
1432  pSetCoeff0(m1, s);
1433  pSetCoeff0(m2, t);
1434  m2 = pNeg(m2);
1435  p_Test(m1,strat->tailRing);
1436  p_Test(m2,strat->tailRing);
1437  poly si = pCopy(strat->S[i]);
1438  poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1439  poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1440  pDelete(&si);
1441  if(sim2 == NULL)
1442  {
1443  pDelete(&m1);
1444  pDelete(&m2);
1445  if(pm1 == NULL)
1446  {
1447  if(h.lcm != NULL)
1448  {
1449  pLmDelete(h.lcm);
1450  h.lcm=NULL;
1451  }
1452  h.Clear();
1453  if (strat->pairtest==NULL) initPairtest(strat);
1454  strat->pairtest[i] = TRUE;
1455  strat->pairtest[strat->sl+1] = TRUE;
1456  return;
1457  }
1458  else
1459  {
1460  gcd = pm1;
1461  pm1 = NULL;
1462  }
1463  }
1464  else
1465  {
1466  if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1467  {
1468  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1469  pSetmComp(sim2);
1470  }
1471  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1472  gcd = p_Add_q(pm1, sim2, strat->tailRing);
1473  }
1474  p_Test(gcd, strat->tailRing);
1475  //p_LmDelete(m1, strat->tailRing);
1476  //p_LmDelete(m2, strat->tailRing);
1477 #ifdef KDEBUG
1478  if (TEST_OPT_DEBUG)
1479  {
1480  wrp(gcd);
1481  PrintLn();
1482  }
1483 #endif
1484  h.p = gcd;
1485  h.i_r = -1;
1486  if(h.p == NULL)
1487  {
1488  if (strat->pairtest==NULL) initPairtest(strat);
1489  strat->pairtest[i] = TRUE;
1490  strat->pairtest[strat->sl+1] = TRUE;
1491  return;
1492  }
1493  h.tailRing = strat->tailRing;
1494  int posx;
1495  //h.pCleardenom();
1496  //pSetm(h.p);
1497  #ifdef ADIDEBUG
1498  printf("\nThis is afterwards:\n");
1499  pWrite(h.p);
1500  #endif
1501  h.i_r1 = -1;h.i_r2 = -1;
1502  strat->initEcart(&h);
1503  #if 1
1504  h.p2 = strat->S[i];
1505  h.p1 = p;
1506  #endif
1507  #if 1
1508  if (atR >= 0)
1509  {
1510  h.i_r1 = atR;
1511  h.i_r2 = strat->S_2_R[i];
1512  }
1513  #endif
1514  if (strat->Bl==-1)
1515  posx =0;
1516  else
1517  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1518  h.sev = pGetShortExpVector(h.p);
1519  if (currRing!=strat->tailRing)
1520  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1521  #ifdef ADIDEBUG
1522  printf("\nThis s-poly was added to B:\n");pWrite(h.p);pWrite(h.p1);pWrite(h.p2);printf("\ni_r1 = %i, i_r2 = %i\n",h.i_r1, h.i_r2);pWrite(strat->T[h.i_r1].p);pWrite(strat->T[h.i_r2].p);
1523  #endif
1524  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1525  kTest_TS(strat);
1526 }
1527 
1528 
1529 /*2
1530 * put the lcm(s[i],p) into the set B
1531 */
1532 
1533 static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1534 {
1535  number d, s, t;
1536  assume(atR >= 0);
1537  poly m1, m2, gcd,si;
1538  if(!enterTstrong)
1539  {
1540  assume(i<=strat->sl);
1541  si = strat->S[i];
1542  }
1543  else
1544  {
1545  assume(i<=strat->tl);
1546  si = strat->T[i].p;
1547  }
1548  //printf("\n--------------------------------\n");
1549  //pWrite(p);pWrite(si);
1550  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1551 
1552  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1553  {
1554  nDelete(&d);
1555  nDelete(&s);
1556  nDelete(&t);
1557  return FALSE;
1558  }
1559 
1560  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1561  //p_Test(m1,strat->tailRing);
1562  //p_Test(m2,strat->tailRing);
1563  /*if(!enterTstrong)
1564  {
1565  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1566  {
1567  memset(&(strat->P), 0, sizeof(strat->P));
1568  kStratChangeTailRing(strat);
1569  strat->P = *(strat->R[atR]);
1570  p_LmFree(m1, strat->tailRing);
1571  p_LmFree(m2, strat->tailRing);
1572  p_LmFree(gcd, currRing);
1573  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1574  }
1575  }*/
1576  pSetCoeff0(m1, s);
1577  pSetCoeff0(m2, t);
1578  pSetCoeff0(gcd, d);
1579  p_Test(m1,strat->tailRing);
1580  p_Test(m2,strat->tailRing);
1581  //printf("\n===================================\n");
1582  //pWrite(m1);pWrite(m2);pWrite(gcd);
1583 #ifdef KDEBUG
1584  if (TEST_OPT_DEBUG)
1585  {
1586  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1587  PrintS("m1 = ");
1588  p_wrp(m1, strat->tailRing);
1589  PrintS(" ; m2 = ");
1590  p_wrp(m2, strat->tailRing);
1591  PrintS(" ; gcd = ");
1592  wrp(gcd);
1593  PrintS("\n--- create strong gcd poly: ");
1594  Print("\n p: %d", i);
1595  wrp(p);
1596  Print("\n strat->S[%d]: ", i);
1597  wrp(si);
1598  PrintS(" ---> ");
1599  }
1600 #endif
1601 
1602  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1603  p_LmDelete(m1, strat->tailRing);
1604  p_LmDelete(m2, strat->tailRing);
1605 #ifdef KDEBUG
1606  if (TEST_OPT_DEBUG)
1607  {
1608  wrp(gcd);
1609  PrintLn();
1610  }
1611 #endif
1612 
1613  LObject h;
1614  h.p = gcd;
1615  h.tailRing = strat->tailRing;
1616  int posx;
1617  h.pCleardenom();
1618  strat->initEcart(&h);
1619  h.sev = pGetShortExpVector(h.p);
1620  h.i_r1 = -1;h.i_r2 = -1;
1621  if (currRing!=strat->tailRing)
1622  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1623  if(!enterTstrong)
1624  {
1625  #if 1
1626  h.p1 = p;h.p2 = strat->S[i];
1627  #endif
1628  if (atR >= 0)
1629  {
1630  h.i_r2 = strat->S_2_R[i];
1631  h.i_r1 = atR;
1632  }
1633  else
1634  {
1635  h.i_r1 = -1;
1636  h.i_r2 = -1;
1637  }
1638  if (strat->Ll==-1)
1639  posx =0;
1640  else
1641  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1642  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1643  }
1644  else
1645  {
1646  if(h.IsNull()) return FALSE;
1647  //int red_result;
1648  //reduzieren ist teur!!!
1649  //if(strat->L != NULL)
1650  //red_result = strat->red(&h,strat);
1651  if(!h.IsNull())
1652  {
1653  enterT(h, strat,-1);
1654  //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1655  //strat->enterS(h,pos,strat,-1);
1656  }
1657  }
1658  //#if 1
1659  #ifdef ADIDEBUG
1660  printf("\nThis strong poly was added to L:\n");pWrite(h.p);pWrite(h.p1);pWrite(h.p2);
1661  #endif
1662  return TRUE;
1663 }
1664 
1666 {
1667  if(strat->sl < 0) return FALSE;
1668  int i;
1669  for(i=0;i<strat->sl;i++)
1670  {
1671  //Construct the gcd pair between h and S[i]
1672  number d, s, t;
1673  poly m1, m2, gcd;
1674  d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1675  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1676  {
1677  nDelete(&d);
1678  nDelete(&s);
1679  nDelete(&t);
1680  }
1681  else
1682  {
1683  k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1684  pSetCoeff0(m1, s);
1685  pSetCoeff0(m2, t);
1686  pSetCoeff0(gcd, d);
1687  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);
1688  poly pSigMult = p_Copy(h->sig,currRing);
1689  poly sSigMult = p_Copy(strat->sig[i],currRing);
1690  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1691  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1692  p_LmDelete(m1, strat->tailRing);
1693  p_LmDelete(m2, strat->tailRing);
1694  poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1695  if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1696  {
1697  #ifdef ADIDEBUG
1698  printf("\nCan replace * (sig = *) with * (sig = *) since of * with sig *\n");
1699  pWrite(h->p);pWrite(h->sig);pWrite(gcd);pWrite(pairsig);pWrite(strat->S[i]);pWrite(strat->sig[i]);
1700  //getchar();
1701  #endif
1702  pDelete(&h->p);
1703  h->p = gcd;
1704  pDelete(&h->sig);
1705  h->sig = pairsig;
1706  pNext(h->sig) = NULL;
1707  strat->initEcart(h);
1708  h->sev = pGetShortExpVector(h->p);
1709  h->sevSig = pGetShortExpVector(h->sig);
1710  h->i_r1 = -1;h->i_r2 = -1;
1711  if(h->lcm != NULL)
1712  {
1713  pLmDelete(h->lcm);
1714  h->lcm = NULL;
1715  }
1716  if (currRing!=strat->tailRing)
1717  h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1718  return TRUE;
1719  }
1720  //Delete what you didn't use
1721  pDelete(&gcd);
1722  pDelete(&pairsig);
1723  }
1724  }
1725  return FALSE;
1726 }
1727 
1728 static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1729 {
1730  number d, s, t;
1731  assume(atR >= 0);
1732  poly m1, m2, gcd,si;
1733  assume(i<=strat->sl);
1734  si = strat->S[i];
1735  //printf("\n--------------------------------\n");
1736  //pWrite(p);pWrite(si);
1737  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1738 
1739  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1740  {
1741  nDelete(&d);
1742  nDelete(&s);
1743  nDelete(&t);
1744  return FALSE;
1745  }
1746 
1747  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1748  //p_Test(m1,strat->tailRing);
1749  //p_Test(m2,strat->tailRing);
1750  /*if(!enterTstrong)
1751  {
1752  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1753  {
1754  memset(&(strat->P), 0, sizeof(strat->P));
1755  kStratChangeTailRing(strat);
1756  strat->P = *(strat->R[atR]);
1757  p_LmFree(m1, strat->tailRing);
1758  p_LmFree(m2, strat->tailRing);
1759  p_LmFree(gcd, currRing);
1760  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1761  }
1762  }*/
1763  pSetCoeff0(m1, s);
1764  pSetCoeff0(m2, t);
1765  pSetCoeff0(gcd, d);
1766  p_Test(m1,strat->tailRing);
1767  p_Test(m2,strat->tailRing);
1768  //printf("\n===================================\n");
1769  //pWrite(m1);pWrite(m2);pWrite(gcd);
1770 #ifdef KDEBUG
1771  if (TEST_OPT_DEBUG)
1772  {
1773  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1774  PrintS("m1 = ");
1775  p_wrp(m1, strat->tailRing);
1776  PrintS(" ; m2 = ");
1777  p_wrp(m2, strat->tailRing);
1778  PrintS(" ; gcd = ");
1779  wrp(gcd);
1780  PrintS("\n--- create strong gcd poly: ");
1781  Print("\n p: %d", i);
1782  wrp(p);
1783  Print("\n strat->S[%d]: ", i);
1784  wrp(si);
1785  PrintS(" ---> ");
1786  }
1787 #endif
1788 
1789  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1790 
1791 #ifdef KDEBUG
1792  if (TEST_OPT_DEBUG)
1793  {
1794  wrp(gcd);
1795  PrintLn();
1796  }
1797 #endif
1798 
1799  //Check and set the signatures
1800  poly pSigMult = p_Copy(sig,currRing);
1801  poly sSigMult = p_Copy(strat->sig[i],currRing);
1802  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1803  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1804  p_LmDelete(m1, strat->tailRing);
1805  p_LmDelete(m2, strat->tailRing);
1806  poly pairsig;
1807  if(pLmCmp(pSigMult,sSigMult) == 0)
1808  {
1809  //Same lm, have to add them
1810  pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1811  //This might be zero
1812  }
1813  else
1814  {
1815  //Set the sig to either pSigMult or sSigMult
1816  if(pLtCmp(pSigMult,sSigMult)==1)
1817  {
1818  pairsig = pSigMult;
1819  pDelete(&sSigMult);
1820  }
1821  else
1822  {
1823  pairsig = sSigMult;
1824  pDelete(&pSigMult);
1825  }
1826  }
1827 
1828  LObject h;
1829  h.p = gcd;
1830  h.tailRing = strat->tailRing;
1831  h.sig = pairsig;
1832  int posx;
1833  h.pCleardenom();
1834  strat->initEcart(&h);
1835  h.sev = pGetShortExpVector(h.p);
1836  h.i_r1 = -1;h.i_r2 = -1;
1837  if (currRing!=strat->tailRing)
1838  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1839  if(h.sig == NULL)
1840  {
1841  #ifdef ADIDEBUG
1842  printf("\nPossible sigdrop in enterpairstrongSig (due to lost of sig)\n");
1843  #endif
1844  //sigdrop since we loose the signature
1845  strat->sigdrop = TRUE;
1846  //Try to reduce it as far as we can via redRing
1847  int red_result = redRing(&h,strat);
1848  #ifdef ADIDEBUG
1849  printf("\nAfter redRing reduce:\n");pWrite(h.p);
1850  #endif
1851  if(red_result == 0)
1852  {
1853  // Cancel the sigdrop
1854  #ifdef ADIDEBUG
1855  printf("\nCancel the sigdrop. It reduced to 0\n");
1856  #endif
1857  p_Delete(&h.sig,currRing);h.sig = NULL;
1858  strat->sigdrop = FALSE;
1859  return FALSE;
1860  }
1861  else
1862  {
1863  #ifdef ADIDEBUG
1864  printf("\nSigdrop. end\n");
1865  #endif
1866  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1867  #if 1
1868  strat->enterS(h,0,strat,strat->tl);
1869  #endif
1870  return FALSE;
1871  }
1872  }
1873  if(!nGreaterZero(pGetCoeff(h.sig)))
1874  {
1875  h.sig = pNeg(h.sig);
1876  h.p = pNeg(h.p);
1877  }
1878 
1879  if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1880  {
1881  #ifdef ADIDEBUG
1882  printf("\nSigDrop in enteronestrongpolySig\n");
1883  pWrite(h.sig);
1884  pWrite(p);pWrite(sig);
1885  pWrite(strat->S[i]);pWrite(strat->sig[i]);
1886  #endif
1887  strat->sigdrop = TRUE;
1888  // Completely reduce it
1889  int red_result = redRing(&h,strat);
1890  if(red_result == 0)
1891  {
1892  // Reduced to 0
1893  #ifdef ADIDEBUG
1894  printf("\nCancel the sigdrop after redRing (=0)\n");
1895  #endif
1896  strat->sigdrop = FALSE;
1897  p_Delete(&h.sig,currRing);h.sig = NULL;
1898  return FALSE;
1899  }
1900  else
1901  {
1902  #ifdef ADIDEBUG
1903  printf("\nAfter redRing still sigdrop:\n");pWrite(h.p);
1904  #endif
1905  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1906  // 0 - add just the original poly causing the sigdrop, 1 - add also this
1907  #if 1
1908  strat->enterS(h,0,strat, strat->tl+1);
1909  #endif
1910  return FALSE;
1911  }
1912  }
1913  #ifdef ADIDEBUG
1914  printf("\nThis strong poly was added to L:\n");pWrite(h.p);pWrite(h.p1);pWrite(h.p2);pWrite(h.sig);
1915  #endif
1916  //Check for sigdrop
1917  if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1918  {
1919  #ifdef ADIDEBUG
1920  printf("\nSigDrop in strongpair\noriginals: ");pWrite(sig);pWrite(strat->sig[i]);
1921  printf("\nnow: ");pWrite(pairsig);
1922  #endif
1923  strat->sigdrop = TRUE;
1924  //Enter this element to S
1925  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1926  strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1927  }
1928  #if 1
1929  h.p1 = p;h.p2 = strat->S[i];
1930  #endif
1931  if (atR >= 0)
1932  {
1933  h.i_r2 = strat->S_2_R[i];
1934  h.i_r1 = atR;
1935  }
1936  else
1937  {
1938  h.i_r1 = -1;
1939  h.i_r2 = -1;
1940  }
1941  if (strat->Ll==-1)
1942  posx =0;
1943  else
1944  posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1945  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1946  return TRUE;
1947 }
1948 #endif
1949 
1950 /*2
1951 * put the pair (s[i],p) into the set B, ecart=ecart(p)
1952 */
1953 
1954 void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1955 {
1956  assume(i<=strat->sl);
1957 
1958  int l,j,compare;
1959  LObject Lp;
1960  Lp.i_r = -1;
1961 
1962 #ifdef KDEBUG
1963  Lp.ecart=0; Lp.length=0;
1964 #endif
1965  /*- computes the lcm(s[i],p) -*/
1966  Lp.lcm = pInit();
1967 
1968 #ifndef HAVE_RATGRING
1969  pLcm(p,strat->S[i],Lp.lcm);
1970 #elif defined(HAVE_RATGRING)
1971  if (rIsRatGRing(currRing))
1972  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1973  else
1974  pLcm(p,strat->S[i],Lp.lcm);
1975 #endif
1976  pSetm(Lp.lcm);
1977 
1978 
1979  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
1980  {
1981  if((!((strat->ecartS[i]>0)&&(ecart>0)))
1982  && pHasNotCF(p,strat->S[i]))
1983  {
1984  /*
1985  *the product criterion has applied for (s,p),
1986  *i.e. lcm(s,p)=product of the leading terms of s and p.
1987  *Suppose (s,r) is in L and the leading term
1988  *of p divides lcm(s,r)
1989  *(==> the leading term of p divides the leading term of r)
1990  *but the leading term of s does not divide the leading term of r
1991  *(notice that tis condition is automatically satisfied if r is still
1992  *in S), then (s,r) can be cancelled.
1993  *This should be done here because the
1994  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1995  *
1996  *Moreover, skipping (s,r) holds also for the noncommutative case.
1997  */
1998  strat->cp++;
1999  pLmFree(Lp.lcm);
2000  Lp.lcm=NULL;
2001  return;
2002  }
2003  else
2004  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2005  if (strat->fromT && (strat->ecartS[i]>ecart))
2006  {
2007  pLmFree(Lp.lcm);
2008  Lp.lcm=NULL;
2009  return;
2010  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2011  }
2012  /*
2013  *the set B collects the pairs of type (S[j],p)
2014  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2015  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2016  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2017  */
2018  {
2019  j = strat->Bl;
2020  loop
2021  {
2022  if (j < 0) break;
2023  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2024  if ((compare==1)
2025  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2026  {
2027  strat->c3++;
2028  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2029  {
2030  pLmFree(Lp.lcm);
2031  return;
2032  }
2033  break;
2034  }
2035  else
2036  if ((compare ==-1)
2037  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2038  {
2039  deleteInL(strat->B,&strat->Bl,j,strat);
2040  strat->c3++;
2041  }
2042  j--;
2043  }
2044  }
2045  }
2046  else /*sugarcrit*/
2047  {
2048  if (ALLOW_PROD_CRIT(strat))
2049  {
2050  // if currRing->nc_type!=quasi (or skew)
2051  // TODO: enable productCrit for super commutative algebras...
2052  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2053  pHasNotCF(p,strat->S[i]))
2054  {
2055  /*
2056  *the product criterion has applied for (s,p),
2057  *i.e. lcm(s,p)=product of the leading terms of s and p.
2058  *Suppose (s,r) is in L and the leading term
2059  *of p devides lcm(s,r)
2060  *(==> the leading term of p devides the leading term of r)
2061  *but the leading term of s does not devide the leading term of r
2062  *(notice that tis condition is automatically satisfied if r is still
2063  *in S), then (s,r) can be canceled.
2064  *This should be done here because the
2065  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2066  */
2067  strat->cp++;
2068  pLmFree(Lp.lcm);
2069  Lp.lcm=NULL;
2070  return;
2071  }
2072  if (strat->fromT && (strat->ecartS[i]>ecart))
2073  {
2074  pLmFree(Lp.lcm);
2075  Lp.lcm=NULL;
2076  return;
2077  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2078  }
2079  /*
2080  *the set B collects the pairs of type (S[j],p)
2081  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2082  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2083  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2084  */
2085  for(j = strat->Bl;j>=0;j--)
2086  {
2087  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2088  if (compare==1)
2089  {
2090  strat->c3++;
2091  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2092  {
2093  pLmFree(Lp.lcm);
2094  return;
2095  }
2096  break;
2097  }
2098  else
2099  if (compare ==-1)
2100  {
2101  deleteInL(strat->B,&strat->Bl,j,strat);
2102  strat->c3++;
2103  }
2104  }
2105  }
2106  }
2107  /*
2108  *the pair (S[i],p) enters B if the spoly != 0
2109  */
2110  /*- compute the short s-polynomial -*/
2111  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2112  pNorm(p);
2113 
2114  if ((strat->S[i]==NULL) || (p==NULL))
2115  return;
2116 
2117  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2118  Lp.p=NULL;
2119  else
2120  {
2121  #ifdef HAVE_PLURAL
2122  if ( rIsPluralRing(currRing) )
2123  {
2124  if(pHasNotCF(p, strat->S[i]))
2125  {
2126  if(ncRingType(currRing) == nc_lie)
2127  {
2128  // generalized prod-crit for lie-type
2129  strat->cp++;
2130  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2131  }
2132  else
2133  if( ALLOW_PROD_CRIT(strat) )
2134  {
2135  // product criterion for homogeneous case in SCA
2136  strat->cp++;
2137  Lp.p = NULL;
2138  }
2139  else
2140  {
2141  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2142  nc_CreateShortSpoly(strat->S[i], p, currRing);
2143  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2144  pNext(Lp.p) = strat->tail; // !!!
2145  }
2146  }
2147  else
2148  {
2149  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2150  nc_CreateShortSpoly(strat->S[i], p, currRing);
2151 
2152  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2153  pNext(Lp.p) = strat->tail; // !!!
2154  }
2155  }
2156  else
2157  #endif
2158  {
2160  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2161  }
2162  }
2163  if (Lp.p == NULL)
2164  {
2165  /*- the case that the s-poly is 0 -*/
2166  if (strat->pairtest==NULL) initPairtest(strat);
2167  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2168  strat->pairtest[strat->sl+1] = TRUE;
2169  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2170  /*
2171  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2172  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2173  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2174  *term of p devides the lcm(s,r)
2175  *(this canceling should be done here because
2176  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2177  *the first case is handeled in chainCrit
2178  */
2179  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2180  }
2181  else
2182  {
2183  /*- the pair (S[i],p) enters B -*/
2184  Lp.p1 = strat->S[i];
2185  Lp.p2 = p;
2186 
2187  if (
2189 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2190  )
2191  {
2192  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2193  pNext(Lp.p) = strat->tail; // !!!
2194  }
2195 
2196  if (atR >= 0)
2197  {
2198  Lp.i_r1 = strat->S_2_R[i];
2199  Lp.i_r2 = atR;
2200  }
2201  else
2202  {
2203  Lp.i_r1 = -1;
2204  Lp.i_r2 = -1;
2205  }
2206  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2207 
2209  {
2210  if (!rIsPluralRing(currRing))
2211  nDelete(&(Lp.p->coef));
2212  }
2213 
2214  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2215  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2216  }
2217 }
2218 
2219 /// p_HasNotCF for the IDLIFT case: ignore component
2220 static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2221 {
2222  int i = rVar(r);
2223  loop
2224  {
2225  if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2226  return FALSE;
2227  i--;
2228  if (i == 0)
2229  return TRUE;
2230  }
2231 }
2232 
2233 /*2
2234 * put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2235 */
2236 
2237 static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2238 {
2239  assume(ALLOW_PROD_CRIT(strat));
2241  assume(strat->syzComp==1);
2242  assume(i<=strat->sl);
2243 
2244  int l,j,compare;
2245  LObject Lp;
2246  Lp.i_r = -1;
2247 
2248 #ifdef KDEBUG
2249  Lp.ecart=0; Lp.length=0;
2250 #endif
2251  /*- computes the lcm(s[i],p) -*/
2252  Lp.lcm = pInit();
2253 
2254  pLcm(p,strat->S[i],Lp.lcm);
2255  pSetm(Lp.lcm);
2256 
2257  if (strat->sugarCrit)
2258  {
2259  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2260  && p_HasNotCF_Lift(p,strat->S[i],currRing))
2261  {
2262  /*
2263  *the product criterion has applied for (s,p),
2264  *i.e. lcm(s,p)=product of the leading terms of s and p.
2265  *Suppose (s,r) is in L and the leading term
2266  *of p divides lcm(s,r)
2267  *(==> the leading term of p divides the leading term of r)
2268  *but the leading term of s does not divide the leading term of r
2269  *(notice that tis condition is automatically satisfied if r is still
2270  *in S), then (s,r) can be cancelled.
2271  *This should be done here because the
2272  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2273  *
2274  *Moreover, skipping (s,r) holds also for the noncommutative case.
2275  */
2276  strat->cp++;
2277  pLmFree(Lp.lcm);
2278  Lp.lcm=NULL;
2279  return;
2280  }
2281  else
2282  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2283  if (strat->fromT && (strat->ecartS[i]>ecart))
2284  {
2285  pLmFree(Lp.lcm);
2286  Lp.lcm=NULL;
2287  return;
2288  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2289  }
2290  /*
2291  *the set B collects the pairs of type (S[j],p)
2292  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2293  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2294  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2295  */
2296  {
2297  j = strat->Bl;
2298  loop
2299  {
2300  if (j < 0) break;
2301  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2302  if ((compare==1)
2303  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2304  {
2305  strat->c3++;
2306  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2307  {
2308  pLmFree(Lp.lcm);
2309  return;
2310  }
2311  break;
2312  }
2313  else
2314  if ((compare ==-1)
2315  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2316  {
2317  deleteInL(strat->B,&strat->Bl,j,strat);
2318  strat->c3++;
2319  }
2320  j--;
2321  }
2322  }
2323  }
2324  else /*sugarcrit*/
2325  {
2326  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2327  p_HasNotCF_Lift(p,strat->S[i],currRing))
2328  {
2329  /*
2330  *the product criterion has applied for (s,p),
2331  *i.e. lcm(s,p)=product of the leading terms of s and p.
2332  *Suppose (s,r) is in L and the leading term
2333  *of p devides lcm(s,r)
2334  *(==> the leading term of p devides the leading term of r)
2335  *but the leading term of s does not devide the leading term of r
2336  *(notice that tis condition is automatically satisfied if r is still
2337  *in S), then (s,r) can be canceled.
2338  *This should be done here because the
2339  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2340  */
2341  strat->cp++;
2342  pLmFree(Lp.lcm);
2343  Lp.lcm=NULL;
2344  return;
2345  }
2346  if (strat->fromT && (strat->ecartS[i]>ecart))
2347  {
2348  pLmFree(Lp.lcm);
2349  Lp.lcm=NULL;
2350  return;
2351  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2352  }
2353  /*
2354  *the set B collects the pairs of type (S[j],p)
2355  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2356  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2357  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2358  */
2359  for(j = strat->Bl;j>=0;j--)
2360  {
2361  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2362  if (compare==1)
2363  {
2364  strat->c3++;
2365  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2366  {
2367  pLmFree(Lp.lcm);
2368  return;
2369  }
2370  break;
2371  }
2372  else
2373  if (compare ==-1)
2374  {
2375  deleteInL(strat->B,&strat->Bl,j,strat);
2376  strat->c3++;
2377  }
2378  }
2379  }
2380  /*
2381  *the pair (S[i],p) enters B if the spoly != 0
2382  */
2383  /*- compute the short s-polynomial -*/
2384  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2385  pNorm(p);
2386 
2387  if ((strat->S[i]==NULL) || (p==NULL))
2388  return;
2389 
2390  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2391  Lp.p=NULL;
2392  else
2393  {
2395  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2396  }
2397  if (Lp.p == NULL)
2398  {
2399  /*- the case that the s-poly is 0 -*/
2400  if (strat->pairtest==NULL) initPairtest(strat);
2401  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2402  strat->pairtest[strat->sl+1] = TRUE;
2403  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2404  /*
2405  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2406  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2407  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2408  *term of p devides the lcm(s,r)
2409  *(this canceling should be done here because
2410  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2411  *the first case is handeled in chainCrit
2412  */
2413  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2414  }
2415  else
2416  {
2417  /*- the pair (S[i],p) enters B -*/
2418  Lp.p1 = strat->S[i];
2419  Lp.p2 = p;
2420 
2421  pNext(Lp.p) = strat->tail; // !!!
2422 
2423  if (atR >= 0)
2424  {
2425  Lp.i_r1 = strat->S_2_R[i];
2426  Lp.i_r2 = atR;
2427  }
2428  else
2429  {
2430  Lp.i_r1 = -1;
2431  Lp.i_r2 = -1;
2432  }
2433  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2434 
2436  {
2437  nDelete(&(Lp.p->coef));
2438  }
2439 
2440  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2441  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2442  }
2443 }
2444 
2445 /*2
2446 * put the pair (s[i],p) into the set B, ecart=ecart(p)
2447 * NOTE: here we need to add the signature-based criteria
2448 */
2449 
2450 #ifdef DEBUGF5
2451 static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2452 #else
2453 static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2454 #endif
2455 {
2456  assume(i<=strat->sl);
2457 
2458  int l;
2459  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2460  // the corresponding signatures for criteria checks
2461  LObject Lp;
2462  poly pSigMult = p_Copy(pSig,currRing);
2463  poly sSigMult = p_Copy(strat->sig[i],currRing);
2464  unsigned long pSigMultNegSev,sSigMultNegSev;
2465  Lp.i_r = -1;
2466 
2467 #ifdef KDEBUG
2468  Lp.ecart=0; Lp.length=0;
2469 #endif
2470  /*- computes the lcm(s[i],p) -*/
2471  Lp.lcm = pInit();
2472  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2473 #ifndef HAVE_RATGRING
2474  pLcm(p,strat->S[i],Lp.lcm);
2475 #elif defined(HAVE_RATGRING)
2476  // if (rIsRatGRing(currRing))
2477  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2478 #endif
2479  pSetm(Lp.lcm);
2480 
2481  // set coeffs of multipliers m1 and m2
2482  pSetCoeff0(m1, nInit(1));
2483  pSetCoeff0(m2, nInit(1));
2484 //#if 1
2485 #ifdef DEBUGF5
2486  PrintS("P1 ");
2487  pWrite(pHead(p));
2488  PrintS("P2 ");
2489  pWrite(pHead(strat->S[i]));
2490  PrintS("M1 ");
2491  pWrite(m1);
2492  PrintS("M2 ");
2493  pWrite(m2);
2494 #endif
2495  // get multiplied signatures for testing
2496  pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2497  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2498  sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2499  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2500 
2501 //#if 1
2502 #ifdef DEBUGF5
2503  PrintS("----------------\n");
2504  pWrite(pSigMult);
2505  pWrite(sSigMult);
2506  PrintS("----------------\n");
2507  Lp.checked = 0;
2508 #endif
2509  int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2510 //#if 1
2511 #if DEBUGF5
2512  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2513  pWrite(pSigMult);
2514  pWrite(sSigMult);
2515 #endif
2516  if(sigCmp==0)
2517  {
2518  // printf("!!!! EQUAL SIGS !!!!\n");
2519  // pSig = sSig, delete element due to Rewritten Criterion
2520  pDelete(&pSigMult);
2521  pDelete(&sSigMult);
2522  if (rField_is_Ring(currRing))
2523  pLmDelete(Lp.lcm);
2524  else
2525  pLmFree(Lp.lcm);
2526  Lp.lcm=NULL;
2527  pDelete (&m1);
2528  pDelete (&m2);
2529  return;
2530  }
2531  // testing by syzCrit = F5 Criterion
2532  // testing by rewCrit1 = Rewritten Criterion
2533  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2534  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2535  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2536  || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2537  )
2538  {
2539  pDelete(&pSigMult);
2540  pDelete(&sSigMult);
2541  if (rField_is_Ring(currRing))
2542  pLmDelete(Lp.lcm);
2543  else
2544  pLmFree(Lp.lcm);
2545  Lp.lcm=NULL;
2546  pDelete (&m1);
2547  pDelete (&m2);
2548  return;
2549  }
2550  /*
2551  *the pair (S[i],p) enters B if the spoly != 0
2552  */
2553  /*- compute the short s-polynomial -*/
2554  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2555  pNorm(p);
2556 
2557  if ((strat->S[i]==NULL) || (p==NULL))
2558  return;
2559 
2560  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2561  Lp.p=NULL;
2562  else
2563  {
2564  #ifdef HAVE_PLURAL
2565  if ( rIsPluralRing(currRing) )
2566  {
2567  if(pHasNotCF(p, strat->S[i]))
2568  {
2569  if(ncRingType(currRing) == nc_lie)
2570  {
2571  // generalized prod-crit for lie-type
2572  strat->cp++;
2573  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2574  }
2575  else
2576  if( ALLOW_PROD_CRIT(strat) )
2577  {
2578  // product criterion for homogeneous case in SCA
2579  strat->cp++;
2580  Lp.p = NULL;
2581  }
2582  else
2583  {
2584  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2585  nc_CreateShortSpoly(strat->S[i], p, currRing);
2586 
2587  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2588  pNext(Lp.p) = strat->tail; // !!!
2589  }
2590  }
2591  else
2592  {
2593  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2594  nc_CreateShortSpoly(strat->S[i], p, currRing);
2595 
2596  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2597  pNext(Lp.p) = strat->tail; // !!!
2598  }
2599  }
2600  else
2601  #endif
2602  {
2604  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2605  }
2606  }
2607  // store from which element this pair comes from for further tests
2608  //Lp.from = strat->sl+1;
2609  if(sigCmp==currRing->OrdSgn)
2610  {
2611  // pSig > sSig
2612  pDelete (&sSigMult);
2613  Lp.sig = pSigMult;
2614  Lp.sevSig = ~pSigMultNegSev;
2615  }
2616  else
2617  {
2618  // pSig < sSig
2619  pDelete (&pSigMult);
2620  Lp.sig = sSigMult;
2621  Lp.sevSig = ~sSigMultNegSev;
2622  }
2623  if (Lp.p == NULL)
2624  {
2625  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2626  int pos = posInSyz(strat, Lp.sig);
2627  enterSyz(Lp, strat, pos);
2628  }
2629  else
2630  {
2631  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2632  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2633  {
2634  pLmFree(Lp.lcm);
2635  pDelete(&Lp.sig);
2636  Lp.lcm=NULL;
2637  pDelete (&m1);
2638  pDelete (&m2);
2639  return;
2640  }
2641  // in any case Lp is checked up to the next strat->P which is added
2642  // to S right after this critical pair creation.
2643  // NOTE: this even holds if the 2nd generator gives the bigger signature
2644  // moreover, this improves rewCriterion,
2645  // i.e. strat->checked > strat->from if and only if the 2nd generator
2646  // gives the bigger signature.
2647  Lp.checked = strat->sl+1;
2648  // at this point it is clear that the pair will be added to L, since it has
2649  // passed all tests up to now
2650 
2651  // adds buchberger's first criterion
2652  if (pLmCmp(m2,pHead(p)) == 0)
2653  {
2654  Lp.prod_crit = TRUE; // Product Criterion
2655 #if 0
2656  int pos = posInSyz(strat, Lp.sig);
2657  enterSyz(Lp, strat, pos);
2658  Lp.lcm=NULL;
2659  pDelete (&m1);
2660  pDelete (&m2);
2661  return;
2662 #endif
2663  }
2664  pDelete (&m1);
2665  pDelete (&m2);
2666 #if DEBUGF5
2667  PrintS("SIGNATURE OF PAIR: ");
2668  pWrite(Lp.sig);
2669 #endif
2670  /*- the pair (S[i],p) enters B -*/
2671  Lp.p1 = strat->S[i];
2672  Lp.p2 = p;
2673 
2674  if (
2676 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2677  )
2678  {
2679  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2680  pNext(Lp.p) = strat->tail; // !!!
2681  }
2682 
2683  if (atR >= 0)
2684  {
2685  Lp.i_r1 = strat->S_2_R[i];
2686  Lp.i_r2 = atR;
2687  }
2688  else
2689  {
2690  Lp.i_r1 = -1;
2691  Lp.i_r2 = -1;
2692  }
2693  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2694 
2696  {
2697  if (!rIsPluralRing(currRing))
2698  nDelete(&(Lp.p->coef));
2699  }
2700 
2701  l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2702  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2703  }
2704 }
2705 
2706 
2707 #ifdef DEBUGF5
2708 static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2709 #else
2710 static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2711 #endif
2712 {
2713  #ifdef ADIDEBUG
2714  printf("\nTrying to add p and S[%i]\n",i);
2715  pWrite(p);pWrite(pSig);
2716  pWrite(strat->S[i]);pWrite(strat->sig[i]);
2717  #endif
2718  #if ALL_VS_JUST
2719  //Over rings, if we construct the strong pair, do not add the spair
2721  {
2722  number s,t,d;
2723  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2724 
2725  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2726  {
2727  nDelete(&d);
2728  nDelete(&s);
2729  nDelete(&t);
2730  return;
2731  }
2732  nDelete(&d);
2733  nDelete(&s);
2734  nDelete(&t);
2735  }
2736  #endif
2737  assume(i<=strat->sl);
2738  int l;
2739  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2740  // the corresponding signatures for criteria checks
2741  LObject Lp;
2742  poly pSigMult = p_Copy(pSig,currRing);
2743  poly sSigMult = p_Copy(strat->sig[i],currRing);
2744  unsigned long pSigMultNegSev,sSigMultNegSev;
2745  Lp.i_r = -1;
2746 
2747 #ifdef KDEBUG
2748  Lp.ecart=0; Lp.length=0;
2749 #endif
2750  /*- computes the lcm(s[i],p) -*/
2751  Lp.lcm = pInit();
2752  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2753 #ifndef HAVE_RATGRING
2754  pLcm(p,strat->S[i],Lp.lcm);
2755 #elif defined(HAVE_RATGRING)
2756  // if (rIsRatGRing(currRing))
2757  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2758 #endif
2759  pSetm(Lp.lcm);
2760 
2761  // set coeffs of multipliers m1 and m2
2763  {
2764  number s = nCopy(pGetCoeff(strat->S[i]));
2765  number t = nCopy(pGetCoeff(p));
2766  pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2767  ksCheckCoeff(&s, &t, currRing->cf);
2768  pSetCoeff0(m1,s);
2769  pSetCoeff0(m2,t);
2770  #ifdef ADIDEBUG
2771  printf("\nIn Spoly: m1, m2 :\n");pWrite(m1);pWrite(m2);
2772  #endif
2773  }
2774  else
2775  {
2776  pSetCoeff0(m1, nInit(1));
2777  pSetCoeff0(m2, nInit(1));
2778  }
2779 #ifdef DEBUGF5
2780  Print("P1 ");
2781  pWrite(pHead(p));
2782  Print("P2 ");
2783  pWrite(pHead(strat->S[i]));
2784  Print("M1 ");
2785  pWrite(m1);
2786  Print("M2 ");
2787  pWrite(m2);
2788 #endif
2789 
2790  // get multiplied signatures for testing
2791  pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2792  if(pSigMult != NULL)
2793  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2794  sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2795  if(sSigMult != NULL)
2796  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2797 //#if 1
2798 #ifdef DEBUGF5
2799  Print("----------------\n");
2800  pWrite(pSigMult);
2801  pWrite(sSigMult);
2802  Print("----------------\n");
2803  Lp.checked = 0;
2804 #endif
2805  int sigCmp;
2806  if(pSigMult != NULL && sSigMult != NULL)
2807  {
2809  sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2810  else
2811  sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2812  }
2813  else
2814  {
2815  if(pSigMult == NULL)
2816  {
2817  if(sSigMult == NULL)
2818  sigCmp = 0;
2819  else
2820  sigCmp = -1;
2821  }
2822  else
2823  sigCmp = 1;
2824  }
2825 //#if 1
2826 #if DEBUGF5
2827  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2828  pWrite(pSigMult);
2829  pWrite(sSigMult);
2830 #endif
2831  //In the ring case we already build the sig
2833  {
2834  if(sigCmp == 0)
2835  {
2836  #ifdef ADIDEBUG
2837  printf("\nPossible sigdrop in enterpairSig (due to lost of sig)\n");
2838  #endif
2839  //sigdrop since we loose the signature
2840  strat->sigdrop = TRUE;
2841  //Try to reduce it as far as we can via redRing
2843  {
2844  poly p1 = p_Copy(p,currRing);
2845  poly p2 = p_Copy(strat->S[i],currRing);
2846  p1 = p_Mult_mm(p1,m1,currRing);
2847  p2 = p_Mult_mm(p2,m2,currRing);
2848  Lp.p = p_Sub(p1,p2,currRing);
2849  if(Lp.p != NULL)
2850  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2851  }
2852  int red_result = redRing(&Lp,strat);
2853  #ifdef ADIDEBUG
2854  printf("\nAfter redRing reduce:\n");pWrite(Lp.p);
2855  #endif
2856  if(red_result == 0)
2857  {
2858  // Cancel the sigdrop
2859  #ifdef ADIDEBUG
2860  printf("\nCancel the sigdrop. It reduced to 0\n");
2861  #endif
2862  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2863  strat->sigdrop = FALSE;
2864  return;
2865  }
2866  else
2867  {
2868  #ifdef ADIDEBUG
2869  printf("\nSigdrop. end\n");
2870  #endif
2871  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2872  #if 1
2873  strat->enterS(Lp,0,strat,strat->tl);
2874  #endif
2875  return;
2876  }
2877  }
2878  if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2879  {
2880  //Same lm, have to substract
2881  Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2882  }
2883  else
2884  {
2885  if(sigCmp == 1)
2886  {
2887  Lp.sig = pCopy(pSigMult);
2888  }
2889  if(sigCmp == -1)
2890  {
2891  Lp.sig = pNeg(pCopy(sSigMult));
2892  }
2893  }
2894  Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2895  }
2896 
2897  #if 0
2898  if(sigCmp==0)
2899  {
2900  // printf("!!!! EQUAL SIGS !!!!\n");
2901  // pSig = sSig, delete element due to Rewritten Criterion
2902  pDelete(&pSigMult);
2903  pDelete(&sSigMult);
2904  if (rField_is_Ring(currRing))
2905  pLmDelete(Lp.lcm);
2906  else
2907  pLmFree(Lp.lcm);
2908  Lp.lcm=NULL;
2909  pDelete (&m1);
2910  pDelete (&m2);
2911  return;
2912  }
2913  #endif
2914  // testing by syzCrit = F5 Criterion
2915  // testing by rewCrit1 = Rewritten Criterion
2916  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2917  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2918  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2919  // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2920  //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2921  )
2922  {
2923  #ifdef ADIDEBUG
2924  printf("\nDELETED!\n");
2925  #endif
2926  pDelete(&pSigMult);
2927  pDelete(&sSigMult);
2928  if (rField_is_Ring(currRing))
2929  pLmDelete(Lp.lcm);
2930  else
2931  pLmFree(Lp.lcm);
2932  Lp.lcm=NULL;
2933  pDelete (&m1);
2934  pDelete (&m2);
2935  return;
2936  }
2937  /*
2938  *the pair (S[i],p) enters B if the spoly != 0
2939  */
2940  /*- compute the short s-polynomial -*/
2941  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2942  pNorm(p);
2943 
2944  if ((strat->S[i]==NULL) || (p==NULL))
2945  return;
2946 
2947  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2948  Lp.p=NULL;
2949  else
2950  {
2951  //Build p
2953  {
2954  poly p1 = p_Copy(p,currRing);
2955  poly p2 = p_Copy(strat->S[i],currRing);
2956  p1 = p_Mult_mm(p1,m1,currRing);
2957  p2 = p_Mult_mm(p2,m2,currRing);
2958  Lp.p = p_Sub(p1,p2,currRing);
2959  if(Lp.p != NULL)
2960  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2961  }
2962  else
2963  {
2964  #ifdef HAVE_PLURAL
2965  if ( rIsPluralRing(currRing) )
2966  {
2967  if(ncRingType(currRing) == nc_lie)
2968  {
2969  // generalized prod-crit for lie-type
2970  strat->cp++;
2971  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2972  }
2973  else
2974  if( ALLOW_PROD_CRIT(strat) )
2975  {
2976  // product criterion for homogeneous case in SCA
2977  strat->cp++;
2978  Lp.p = NULL;
2979  }
2980  else
2981  {
2982  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2983  nc_CreateShortSpoly(strat->S[i], p, currRing);
2984 
2985  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2986  pNext(Lp.p) = strat->tail; // !!!
2987  }
2988  }
2989  else
2990  #endif
2991  {
2993  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2994  }
2995  }
2996  }
2997  // store from which element this pair comes from for further tests
2998  //Lp.from = strat->sl+1;
3000  {
3001  //Put the sig to be > 0
3002  if(!nGreaterZero(pGetCoeff(Lp.sig)))
3003  {
3004  Lp.sig = pNeg(Lp.sig);
3005  Lp.p = pNeg(Lp.p);
3006  }
3007  }
3008  else
3009  {
3010  if(sigCmp==currRing->OrdSgn)
3011  {
3012  // pSig > sSig
3013  pDelete (&sSigMult);
3014  Lp.sig = pSigMult;
3015  Lp.sevSig = ~pSigMultNegSev;
3016  }
3017  else
3018  {
3019  // pSig < sSig
3020  pDelete (&pSigMult);
3021  Lp.sig = sSigMult;
3022  Lp.sevSig = ~sSigMultNegSev;
3023  }
3024  }
3025  if (Lp.p == NULL)
3026  {
3027  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
3028  int pos = posInSyz(strat, Lp.sig);
3029  enterSyz(Lp, strat, pos);
3030  }
3031  else
3032  {
3033  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
3034  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
3035  {
3036  pLmFree(Lp.lcm);
3037  #ifdef ADIDEBUG
3038  printf("\nrewCrit3 deletes it!\n");
3039  #endif
3040  pDelete(&Lp.sig);
3041  Lp.lcm=NULL;
3042  pDelete (&m1);
3043  pDelete (&m2);
3044  return;
3045  }
3046  // in any case Lp is checked up to the next strat->P which is added
3047  // to S right after this critical pair creation.
3048  // NOTE: this even holds if the 2nd generator gives the bigger signature
3049  // moreover, this improves rewCriterion,
3050  // i.e. strat->checked > strat->from if and only if the 2nd generator
3051  // gives the bigger signature.
3052  Lp.checked = strat->sl+1;
3053  // at this point it is clear that the pair will be added to L, since it has
3054  // passed all tests up to now
3055 
3056  // adds buchberger's first criterion
3057  if (pLmCmp(m2,pHead(p)) == 0)
3058  {
3059  Lp.prod_crit = TRUE; // Product Criterion
3060 #if 0
3061  int pos = posInSyz(strat, Lp.sig);
3062  enterSyz(Lp, strat, pos);
3063  Lp.lcm=NULL;
3064  pDelete (&m1);
3065  pDelete (&m2);
3066  return;
3067 #endif
3068  }
3069  pDelete (&m1);
3070  pDelete (&m2);
3071 #if DEBUGF5
3072  PrintS("SIGNATURE OF PAIR: ");
3073  pWrite(Lp.sig);
3074 #endif
3075  /*- the pair (S[i],p) enters B -*/
3076  Lp.p1 = strat->S[i];
3077  Lp.p2 = p;
3078 
3079  if (
3081 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3083  )
3084  {
3085  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3086  pNext(Lp.p) = strat->tail; // !!!
3087  }
3088 
3089  if (atR >= 0)
3090  {
3091  Lp.i_r1 = strat->S_2_R[i];
3092  Lp.i_r2 = atR;
3093  }
3094  else
3095  {
3096  Lp.i_r1 = -1;
3097  Lp.i_r2 = -1;
3098  }
3099  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3100 
3102  {
3104  nDelete(&(Lp.p->coef));
3105  }
3106  // Check for sigdrop
3107  if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3108  {
3109  #ifdef ADIDEBUG
3110  printf("\nSigDrop in enteronepairSig\n");pWrite(Lp.sig);
3111  pWrite(p);pWrite(pSig);
3112  pWrite(strat->S[i]);pWrite(strat->sig[i]);
3113  #endif
3114  strat->sigdrop = TRUE;
3115  // Completely reduce it
3116  int red_result = redRing(&Lp,strat);
3117  if(red_result == 0)
3118  {
3119  // Reduced to 0
3120  #ifdef ADIDEBUG
3121  printf("\nCancel the sigdrop after redRing (=0)\n");
3122  #endif
3123  strat->sigdrop = FALSE;
3124  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3125  return;
3126  }
3127  else
3128  {
3129  #ifdef ADIDEBUG
3130  printf("\nAfter redRing still sigdrop:\n");pWrite(Lp.p);
3131  #endif
3132  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3133  // 0 - add just the original poly causing the sigdrop, 1 - add also this
3134  #if 1
3135  strat->enterS(Lp,0,strat, strat->tl+1);
3136  #endif
3137  return;
3138  }
3139  }
3140  #ifdef ADIDEBUG
3141  printf("\nThis spair was added to B:\n");
3142  pWrite(Lp.p);
3143  pWrite(Lp.p1);
3144  pWrite(Lp.p2);
3145  pWrite(Lp.sig);
3146  #endif
3147  l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3148  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3149  }
3150 }
3151 
3152 /*2
3153 * put the pair (s[i],p) into the set L, ecart=ecart(p)
3154 * in the case that s forms a SB of (s)
3155 */
3156 void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3157 {
3158  //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3159  if(pHasNotCF(p,strat->S[i]))
3160  {
3161  //PrintS("prod-crit\n");
3162  if(ALLOW_PROD_CRIT(strat))
3163  {
3164  //PrintS("prod-crit\n");
3165  strat->cp++;
3166  return;
3167  }
3168  }
3169 
3170  int l;
3171  LObject Lp;
3172  Lp.i_r = -1;
3173 
3174  Lp.lcm = pInit();
3175  pLcm(p,strat->S[i],Lp.lcm);
3176  pSetm(Lp.lcm);
3177  /*- compute the short s-polynomial -*/
3178 
3179  #ifdef HAVE_PLURAL
3180  if (rIsPluralRing(currRing))
3181  {
3182  Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3183  }
3184  else
3185  #endif
3186  Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3187 
3188  if (Lp.p == NULL)
3189  {
3190  //PrintS("short spoly==NULL\n");
3191  pLmFree(Lp.lcm);
3192  }
3193  else
3194  {
3195  /*- the pair (S[i],p) enters L -*/
3196  Lp.p1 = strat->S[i];
3197  Lp.p2 = p;
3198  if (atR >= 0)
3199  {
3200  Lp.i_r1 = strat->S_2_R[i];
3201  Lp.i_r2 = atR;
3202  }
3203  else
3204  {
3205  Lp.i_r1 = -1;
3206  Lp.i_r2 = -1;
3207  }
3208  assume(pNext(Lp.p) == NULL);
3209  pNext(Lp.p) = strat->tail;
3210  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3212  {
3213  nDelete(&(Lp.p->coef));
3214  }
3215  l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3216  //Print("-> L[%d]\n",l);
3217  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3218  }
3219 }
3220 
3221 /*2
3222 * merge set B into L
3223 */
3225 {
3226  int j=strat->Ll+strat->Bl+1;
3227  if (j>strat->Lmax)
3228  {
3229  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
3230  strat->L = (LSet)omReallocSize(strat->L,strat->Lmax*sizeof(LObject),
3231  j*sizeof(LObject));
3232  strat->Lmax=j;
3233  }
3234  j = strat->Ll;
3235  int i;
3236  for (i=strat->Bl; i>=0; i--)
3237  {
3238  j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3239  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3240  }
3241  strat->Bl = -1;
3242 }
3243 
3244 /*2
3245 * merge set B into L
3246 */
3248 {
3249  int j=strat->Ll+strat->Bl+1;
3250  if (j>strat->Lmax)
3251  {
3252  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
3253  strat->L = (LSet)omReallocSize(strat->L,strat->Lmax*sizeof(LObject),
3254  j*sizeof(LObject));
3255  strat->Lmax=j;
3256  }
3257  j = strat->Ll;
3258  int i;
3259  for (i=strat->Bl; i>=0; i--)
3260  {
3261  j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3262  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3263  }
3264  strat->Bl = -1;
3265 }
3266 /*2
3267 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3268 *using the chain-criterion in B and L and enters B to L
3269 */
3270 void chainCritNormal (poly p,int ecart,kStrategy strat)
3271 {
3272  int i,j,l;
3273 
3274  /*
3275  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3276  *In this case all elements in B such
3277  *that their lcm is divisible by the leading term of S[i] can be canceled
3278  */
3279  if (strat->pairtest!=NULL)
3280  {
3281  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3282  for (j=0; j<=strat->sl; j++)
3283  {
3284  if (strat->pairtest[j])
3285  {
3286  for (i=strat->Bl; i>=0; i--)
3287  {
3288  if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3289  {
3290  deleteInL(strat->B,&strat->Bl,i,strat);
3291  strat->c3++;
3292  }
3293  }
3294  }
3295  }
3296  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3297  strat->pairtest=NULL;
3298  }
3299  if (strat->Gebauer || strat->fromT)
3300  {
3301  if (strat->sugarCrit)
3302  {
3303  /*
3304  *suppose L[j] == (s,r) and p/lcm(s,r)
3305  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3306  *and in case the sugar is o.k. then L[j] can be canceled
3307  */
3308  for (j=strat->Ll; j>=0; j--)
3309  {
3310  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3311  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3312  && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3313  {
3314  if (strat->L[j].p == strat->tail)
3315  {
3316  deleteInL(strat->L,&strat->Ll,j,strat);
3317  strat->c3++;
3318  }
3319  }
3320  }
3321  /*
3322  *this is GEBAUER-MOELLER:
3323  *in B all elements with the same lcm except the "best"
3324  *(i.e. the last one in B with this property) will be canceled
3325  */
3326  j = strat->Bl;
3327  loop /*cannot be changed into a for !!! */
3328  {
3329  if (j <= 0) break;
3330  i = j-1;
3331  loop
3332  {
3333  if (i < 0) break;
3334  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3335  {
3336  strat->c3++;
3337  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3338  {
3339  deleteInL(strat->B,&strat->Bl,i,strat);
3340  j--;
3341  }
3342  else
3343  {
3344  deleteInL(strat->B,&strat->Bl,j,strat);
3345  break;
3346  }
3347  }
3348  i--;
3349  }
3350  j--;
3351  }
3352  }
3353  else /*sugarCrit*/
3354  {
3355  /*
3356  *suppose L[j] == (s,r) and p/lcm(s,r)
3357  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3358  *and in case the sugar is o.k. then L[j] can be canceled
3359  */
3360  for (j=strat->Ll; j>=0; j--)
3361  {
3362  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3363  {
3364  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3365  {
3366  deleteInL(strat->L,&strat->Ll,j,strat);
3367  strat->c3++;
3368  }
3369  }
3370  }
3371  /*
3372  *this is GEBAUER-MOELLER:
3373  *in B all elements with the same lcm except the "best"
3374  *(i.e. the last one in B with this property) will be canceled
3375  */
3376  j = strat->Bl;
3377  loop /*cannot be changed into a for !!! */
3378  {
3379  if (j <= 0) break;
3380  for(i=j-1; i>=0; i--)
3381  {
3382  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3383  {
3384  strat->c3++;
3385  deleteInL(strat->B,&strat->Bl,i,strat);
3386  j--;
3387  }
3388  }
3389  j--;
3390  }
3391  }
3392  /*
3393  *the elements of B enter L
3394  */
3395  kMergeBintoL(strat);
3396  }
3397  else
3398  {
3399  for (j=strat->Ll; j>=0; j--)
3400  {
3401  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3402  {
3403  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3404  {
3405  deleteInL(strat->L,&strat->Ll,j,strat);
3406  strat->c3++;
3407  }
3408  }
3409  }
3410  /*
3411  *this is our MODIFICATION of GEBAUER-MOELLER:
3412  *First the elements of B enter L,
3413  *then we fix a lcm and the "best" element in L
3414  *(i.e the last in L with this lcm and of type (s,p))
3415  *and cancel all the other elements of type (r,p) with this lcm
3416  *except the case the element (s,r) has also the same lcm
3417  *and is on the worst position with respect to (s,p) and (r,p)
3418  */
3419  /*
3420  *B enters to L/their order with respect to B is permutated for elements
3421  *B[i].p with the same leading term
3422  */
3423  kMergeBintoL(strat);
3424  j = strat->Ll;
3425  loop /*cannot be changed into a for !!! */
3426  {
3427  if (j <= 0)
3428  {
3429  /*now L[0] cannot be canceled any more and the tail can be removed*/
3430  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3431  break;
3432  }
3433  if (strat->L[j].p2 == p)
3434  {
3435  i = j-1;
3436  loop
3437  {
3438  if (i < 0) break;
3439  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3440  {
3441  /*L[i] could be canceled but we search for a better one to cancel*/
3442  strat->c3++;
3443  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3444  && (pNext(strat->L[l].p) == strat->tail)
3445  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3446  && pDivisibleBy(p,strat->L[l].lcm))
3447  {
3448  /*
3449  *"NOT equal(...)" because in case of "equal" the element L[l]
3450  *is "older" and has to be from theoretical point of view behind
3451  *L[i], but we do not want to reorder L
3452  */
3453  strat->L[i].p2 = strat->tail;
3454  /*
3455  *L[l] will be canceled, we cannot cancel L[i] later on,
3456  *so we mark it with "tail"
3457  */
3458  deleteInL(strat->L,&strat->Ll,l,strat);
3459  i--;
3460  }
3461  else
3462  {
3463  deleteInL(strat->L,&strat->Ll,i,strat);
3464  }
3465  j--;
3466  }
3467  i--;
3468  }
3469  }
3470  else if (strat->L[j].p2 == strat->tail)
3471  {
3472  /*now L[j] cannot be canceled any more and the tail can be removed*/
3473  strat->L[j].p2 = p;
3474  }
3475  j--;
3476  }
3477  }
3478 }
3479 /*2
3480 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3481 *without the chain-criterion in B and L and enters B to L
3482 */
3484 {
3485  if (strat->pairtest!=NULL)
3486  {
3487  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3488  strat->pairtest=NULL;
3489  }
3490  /*
3491  *the elements of B enter L
3492  */
3493  kMergeBintoL(strat);
3494 }
3495 /*2
3496 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3497 *using the chain-criterion in B and L and enters B to L
3498 */
3499 void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3500 {
3501  int i,j,l;
3502  kMergeBintoLSba(strat);
3503  j = strat->Ll;
3504  loop /*cannot be changed into a for !!! */
3505  {
3506  if (j <= 0)
3507  {
3508  /*now L[0] cannot be canceled any more and the tail can be removed*/
3509  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3510  break;
3511  }
3512  if (strat->L[j].p2 == p)
3513  {
3514  i = j-1;
3515  loop
3516  {
3517  if (i < 0) break;
3518  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3519  {
3520  /*L[i] could be canceled but we search for a better one to cancel*/
3521  strat->c3++;
3522  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3523  && (pNext(strat->L[l].p) == strat->tail)
3524  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3525  && pDivisibleBy(p,strat->L[l].lcm))
3526  {
3527  /*
3528  *"NOT equal(...)" because in case of "equal" the element L[l]
3529  *is "older" and has to be from theoretical point of view behind
3530  *L[i], but we do not want to reorder L
3531  */
3532  strat->L[i].p2 = strat->tail;
3533  /*
3534  *L[l] will be canceled, we cannot cancel L[i] later on,
3535  *so we mark it with "tail"
3536  */
3537  deleteInL(strat->L,&strat->Ll,l,strat);
3538  i--;
3539  }
3540  else
3541  {
3542  deleteInL(strat->L,&strat->Ll,i,strat);
3543  }
3544  j--;
3545  }
3546  i--;
3547  }
3548  }
3549  else if (strat->L[j].p2 == strat->tail)
3550  {
3551  /*now L[j] cannot be canceled any more and the tail can be removed*/
3552  strat->L[j].p2 = p;
3553  }
3554  j--;
3555  }
3556 }
3557 #ifdef HAVE_RATGRING
3558 void chainCritPart (poly p,int ecart,kStrategy strat)
3559 {
3560  int i,j,l;
3561 
3562  /*
3563  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3564  *In this case all elements in B such
3565  *that their lcm is divisible by the leading term of S[i] can be canceled
3566  */
3567  if (strat->pairtest!=NULL)
3568  {
3569  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3570  for (j=0; j<=strat->sl; j++)
3571  {
3572  if (strat->pairtest[j])
3573  {
3574  for (i=strat->Bl; i>=0; i--)
3575  {
3576  if (_p_LmDivisibleByPart(strat->S[j],currRing,
3577  strat->B[i].lcm,currRing,
3578  currRing->real_var_start,currRing->real_var_end))
3579  {
3580  if(TEST_OPT_DEBUG)
3581  {
3582  Print("chain-crit-part: S[%d]=",j);
3583  p_wrp(strat->S[j],currRing);
3584  Print(" divide B[%d].lcm=",i);
3585  p_wrp(strat->B[i].lcm,currRing);
3586  PrintLn();
3587  }
3588  deleteInL(strat->B,&strat->Bl,i,strat);
3589  strat->c3++;
3590  }
3591  }
3592  }
3593  }
3594  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3595  strat->pairtest=NULL;
3596  }
3597  if (strat->Gebauer || strat->fromT)
3598  {
3599  if (strat->sugarCrit)
3600  {
3601  /*
3602  *suppose L[j] == (s,r) and p/lcm(s,r)
3603  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3604  *and in case the sugar is o.k. then L[j] can be canceled
3605  */
3606  for (j=strat->Ll; j>=0; j--)
3607  {
3608  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3609  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3610  && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3611  {
3612  if (strat->L[j].p == strat->tail)
3613  {
3614  if(TEST_OPT_DEBUG)
3615  {
3616  PrintS("chain-crit-part: pCompareChainPart p=");
3617  p_wrp(p,currRing);
3618  Print(" delete L[%d]",j);
3619  p_wrp(strat->L[j].lcm,currRing);
3620  PrintLn();
3621  }
3622  deleteInL(strat->L,&strat->Ll,j,strat);
3623  strat->c3++;
3624  }
3625  }
3626  }
3627  /*
3628  *this is GEBAUER-MOELLER:
3629  *in B all elements with the same lcm except the "best"
3630  *(i.e. the last one in B with this property) will be canceled
3631  */
3632  j = strat->Bl;
3633  loop /*cannot be changed into a for !!! */
3634  {
3635  if (j <= 0) break;
3636  i = j-1;
3637  loop
3638  {
3639  if (i < 0) break;
3640  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3641  {
3642  strat->c3++;
3643  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3644  {
3645  if(TEST_OPT_DEBUG)
3646  {
3647  Print("chain-crit-part: sugar B[%d].lcm=",j);
3648  p_wrp(strat->B[j].lcm,currRing);
3649  Print(" delete B[%d]",i);
3650  p_wrp(strat->B[i].lcm,currRing);
3651  PrintLn();
3652  }
3653  deleteInL(strat->B,&strat->Bl,i,strat);
3654  j--;
3655  }
3656  else
3657  {
3658  if(TEST_OPT_DEBUG)
3659  {
3660  Print("chain-crit-part: sugar B[%d].lcm=",i);
3661  p_wrp(strat->B[i].lcm,currRing);
3662  Print(" delete B[%d]",j);
3663  p_wrp(strat->B[j].lcm,currRing);
3664  PrintLn();
3665  }
3666  deleteInL(strat->B,&strat->Bl,j,strat);
3667  break;
3668  }
3669  }
3670  i--;
3671  }
3672  j--;
3673  }
3674  }
3675  else /*sugarCrit*/
3676  {
3677  /*
3678  *suppose L[j] == (s,r) and p/lcm(s,r)
3679  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3680  *and in case the sugar is o.k. then L[j] can be canceled
3681  */
3682  for (j=strat->Ll; j>=0; j--)
3683  {
3684  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3685  {
3686  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3687  {
3688  if(TEST_OPT_DEBUG)
3689  {
3690  PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3691  p_wrp(p,currRing);
3692  Print(" delete L[%d]",j);
3693  p_wrp(strat->L[j].lcm,currRing);
3694  PrintLn();
3695  }
3696  deleteInL(strat->L,&strat->Ll,j,strat);
3697  strat->c3++;
3698  }
3699  }
3700  }
3701  /*
3702  *this is GEBAUER-MOELLER:
3703  *in B all elements with the same lcm except the "best"
3704  *(i.e. the last one in B with this property) will be canceled
3705  */
3706  j = strat->Bl;
3707  loop /*cannot be changed into a for !!! */
3708  {
3709  if (j <= 0) break;
3710  for(i=j-1; i>=0; i--)
3711  {
3712  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3713  {
3714  if(TEST_OPT_DEBUG)
3715  {
3716  Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3717  p_wrp(strat->B[j].lcm,currRing);
3718  Print(" delete B[%d]\n",i);
3719  }
3720  strat->c3++;
3721  deleteInL(strat->B,&strat->Bl,i,strat);
3722  j--;
3723  }
3724  }
3725  j--;
3726  }
3727  }
3728  /*
3729  *the elements of B enter L
3730  */
3731  kMergeBintoL(strat);
3732  }
3733  else
3734  {
3735  for (j=strat->Ll; j>=0; j--)
3736  {
3737  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3738  {
3739  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3740  {
3741  if(TEST_OPT_DEBUG)
3742  {
3743  PrintS("chain-crit-part: pCompareChainPart p=");
3744  p_wrp(p,currRing);
3745  Print(" delete L[%d]",j);
3746  p_wrp(strat->L[j].lcm,currRing);
3747  PrintLn();
3748  }
3749  deleteInL(strat->L,&strat->Ll,j,strat);
3750  strat->c3++;
3751  }
3752  }
3753  }
3754  /*
3755  *this is our MODIFICATION of GEBAUER-MOELLER:
3756  *First the elements of B enter L,
3757  *then we fix a lcm and the "best" element in L
3758  *(i.e the last in L with this lcm and of type (s,p))
3759  *and cancel all the other elements of type (r,p) with this lcm
3760  *except the case the element (s,r) has also the same lcm
3761  *and is on the worst position with respect to (s,p) and (r,p)
3762  */
3763  /*
3764  *B enters to L/their order with respect to B is permutated for elements
3765  *B[i].p with the same leading term
3766  */
3767  kMergeBintoL(strat);
3768  j = strat->Ll;
3769  loop /*cannot be changed into a for !!! */
3770  {
3771  if (j <= 0)
3772  {
3773  /*now L[0] cannot be canceled any more and the tail can be removed*/
3774  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3775  break;
3776  }
3777  if (strat->L[j].p2 == p)
3778  {
3779  i = j-1;
3780  loop
3781  {
3782  if (i < 0) break;
3783  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3784  {
3785  /*L[i] could be canceled but we search for a better one to cancel*/
3786  strat->c3++;
3787  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3788  && (pNext(strat->L[l].p) == strat->tail)
3789  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3791  strat->L[l].lcm,currRing,
3792  currRing->real_var_start, currRing->real_var_end))
3793 
3794  {
3795  /*
3796  *"NOT equal(...)" because in case of "equal" the element L[l]
3797  *is "older" and has to be from theoretical point of view behind
3798  *L[i], but we do not want to reorder L
3799  */
3800  strat->L[i].p2 = strat->tail;
3801  /*
3802  *L[l] will be canceled, we cannot cancel L[i] later on,
3803  *so we mark it with "tail"
3804  */
3805  if(TEST_OPT_DEBUG)
3806  {
3807  PrintS("chain-crit-part: divisible_by p=");
3808  p_wrp(p,currRing);
3809  Print(" delete L[%d]",l);
3810  p_wrp(strat->L[l].lcm,currRing);
3811  PrintLn();
3812  }
3813  deleteInL(strat->L,&strat->Ll,l,strat);
3814  i--;
3815  }
3816  else
3817  {
3818  if(TEST_OPT_DEBUG)
3819  {
3820  PrintS("chain-crit-part: divisible_by(2) p=");
3821  p_wrp(p,currRing);
3822  Print(" delete L[%d]",i);
3823  p_wrp(strat->L[i].lcm,currRing);
3824  PrintLn();
3825  }
3826  deleteInL(strat->L,&strat->Ll,i,strat);
3827  }
3828  j--;
3829  }
3830  i--;
3831  }
3832  }
3833  else if (strat->L[j].p2 == strat->tail)
3834  {
3835  /*now L[j] cannot be canceled any more and the tail can be removed*/
3836  strat->L[j].p2 = p;
3837  }
3838  j--;
3839  }
3840  }
3841 }
3842 #endif
3843 
3844 /*2
3845 *(s[0],h),...,(s[k],h) will be put to the pairset L
3846 */
3847 void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3848 {
3849 
3850  if ((strat->syzComp==0)
3851  || (pGetComp(h)<=strat->syzComp))
3852  {
3853  int j;
3854  BOOLEAN new_pair=FALSE;
3855 
3856  if (pGetComp(h)==0)
3857  {
3858  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3859  if ((isFromQ)&&(strat->fromQ!=NULL))
3860  {
3861  for (j=0; j<=k; j++)
3862  {
3863  if (!strat->fromQ[j])
3864  {
3865  new_pair=TRUE;
3866  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3867  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3868  }
3869  }
3870  }
3871  else
3872  {
3873  new_pair=TRUE;
3874  for (j=0; j<=k; j++)
3875  {
3876  #ifdef ADIDEBUG
3877  PrintS("\n Trying to add spoly : \n");
3878  PrintS(" ");p_Write(h, strat->tailRing);
3879  PrintS(" ");p_Write(strat->S[j],strat->tailRing);
3880  #endif
3881  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3882  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3883  }
3884  }
3885  }
3886  else
3887  {
3888  for (j=0; j<=k; j++)
3889  {
3890  if ((pGetComp(h)==pGetComp(strat->S[j]))
3891  || (pGetComp(strat->S[j])==0))
3892  {
3893  new_pair=TRUE;
3894  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3895  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3896  }
3897  }
3898  }
3899  if (new_pair)
3900  {
3901  #ifdef HAVE_RATGRING
3902  if (currRing->real_var_start>0)
3903  chainCritPart(h,ecart,strat);
3904  else
3905  #endif
3906  strat->chainCrit(h,ecart,strat);
3907  }
3908  kMergeBintoL(strat);
3909  }
3910 }
3911 
3912 /*2
3913 *(s[0],h),...,(s[k],h) will be put to the pairset L
3914 *using signatures <= only for signature-based standard basis algorithms
3915 */
3916 
3917 void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3918 {
3919 
3920  if ((strat->syzComp==0)
3921  || (pGetComp(h)<=strat->syzComp))
3922  {
3923  int j;
3924  BOOLEAN new_pair=FALSE;
3925 
3926  if (pGetComp(h)==0)
3927  {
3928  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3929  if ((isFromQ)&&(strat->fromQ!=NULL))
3930  {
3931  for (j=0; j<=k; j++)
3932  {
3933  if (!strat->fromQ[j])
3934  {
3935  new_pair=TRUE;
3936  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3937  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3938  }
3939  }
3940  }
3941  else
3942  {
3943  new_pair=TRUE;
3944  for (j=0; j<=k; j++)
3945  {
3946  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3947  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3948  }
3949  }
3950  }
3951  else
3952  {
3953  for (j=0; j<=k; j++)
3954  {
3955  if ((pGetComp(h)==pGetComp(strat->S[j]))
3956  || (pGetComp(strat->S[j])==0))
3957  {
3958  new_pair=TRUE;
3959  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3960  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3961  }
3962  }
3963  }
3964 
3965  if (new_pair)
3966  {
3967 #ifdef HAVE_RATGRING
3968  if (currRing->real_var_start>0)
3969  chainCritPart(h,ecart,strat);
3970  else
3971 #endif
3972  strat->chainCrit(h,ecart,strat);
3973  }
3974  }
3975 }
3976 
3977 void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3978 {
3979 
3980  if ((strat->syzComp==0)
3981  || (pGetComp(h)<=strat->syzComp))
3982  {
3983  int j;
3984 
3985  if (pGetComp(h)==0)
3986  {
3987  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3988  if ((isFromQ)&&(strat->fromQ!=NULL))
3989  {
3990  for (j=0; j<=k && !strat->sigdrop; j++)
3991  {
3992  if (!strat->fromQ[j])
3993  {
3994  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3995  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3996  }
3997  }
3998  }
3999  else
4000  {
4001  for (j=0; j<=k && !strat->sigdrop; j++)
4002  {
4003  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4004  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4005  }
4006  }
4007  }
4008  else
4009  {
4010  for (j=0; j<=k && !strat->sigdrop; j++)
4011  {
4012  if ((pGetComp(h)==pGetComp(strat->S[j]))
4013  || (pGetComp(strat->S[j])==0))
4014  {
4015  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4016  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4017  }
4018  }
4019  }
4020 
4021 #if 0
4022  if (new_pair)
4023  {
4024 #ifdef HAVE_RATGRING
4025  if (currRing->real_var_start>0)
4026  chainCritPart(h,ecart,strat);
4027  else
4028 #endif
4029  strat->chainCrit(h,ecart,strat);
4030  }
4031 #endif
4032  }
4033 }
4034 
4035 #ifdef HAVE_RINGS
4036 /*2
4037 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
4038 *using the chain-criterion in B and L and enters B to L
4039 */
4040 void chainCritRing (poly p,int, kStrategy strat)
4041 {
4042  int i,j,l;
4043  /*
4044  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4045  *In this case all elements in B such
4046  *that their lcm is divisible by the leading term of S[i] can be canceled
4047  */
4048  if (strat->pairtest!=NULL)
4049  {
4050  {
4051  /*- i.e. there is an i with pairtest[i]==TRUE -*/
4052  for (j=0; j<=strat->sl; j++)
4053  {
4054  if (strat->pairtest[j])
4055  {
4056  for (i=strat->Bl; i>=0; i--)
4057  {
4058  if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4059  {
4060 #ifdef KDEBUG
4061  if (TEST_OPT_DEBUG)
4062  {
4063  PrintS("--- chain criterion func chainCritRing type 1\n");
4064  PrintS("strat->S[j]:");
4065  wrp(strat->S[j]);
4066  PrintS(" strat->B[i].lcm:");
4067  wrp(strat->B[i].lcm);PrintLn();
4068  pWrite(strat->B[i].p);
4069  pWrite(strat->B[i].p1);
4070  pWrite(strat->B[i].p2);
4071  wrp(strat->B[i].lcm);
4072  PrintLn();
4073  }
4074 #endif
4075  #ifdef ADIDEBUG
4076  printf("\nChainCrit1\n");
4077  pWrite(strat->B[i].p);
4078  pWrite(strat->B[i].p1);
4079  pWrite(strat->B[i].p2);
4080  #endif
4081  deleteInL(strat->B,&strat->Bl,i,strat);
4082  strat->c3++;
4083  }
4084  }
4085  }
4086  }
4087  }
4088  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4089  strat->pairtest=NULL;
4090  }
4091  assume(!(strat->Gebauer || strat->fromT));
4092  for (j=strat->Ll; j>=0; j--)
4093  {
4094  if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4095  {
4096  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4097  {
4098  if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4099  {
4100  #ifdef ADIDEBUG
4101  printf("\nChainCrit2\n");
4102  pWrite(strat->L[j].p);
4103  pWrite(strat->L[j].p1);
4104  pWrite(strat->L[j].p2);
4105  #endif
4106  deleteInL(strat->L,&strat->Ll,j,strat);
4107  strat->c3++;
4108 #ifdef KDEBUG
4109  if (TEST_OPT_DEBUG)
4110  {
4111  PrintS("--- chain criterion func chainCritRing type 2\n");
4112  PrintS("strat->L[j].p:");
4113  wrp(strat->L[j].p);
4114  PrintS(" p:");
4115  wrp(p);
4116  PrintLn();
4117  }
4118 #endif
4119  }
4120  }
4121  }
4122  }
4123  /*
4124  *this is our MODIFICATION of GEBAUER-MOELLER:
4125  *First the elements of B enter L,
4126  *then we fix a lcm and the "best" element in L
4127  *(i.e the last in L with this lcm and of type (s,p))
4128  *and cancel all the other elements of type (r,p) with this lcm
4129  *except the case the element (s,r) has also the same lcm
4130  *and is on the worst position with respect to (s,p) and (r,p)
4131  */
4132  /*
4133  *B enters to L/their order with respect to B is permutated for elements
4134  *B[i].p with the same leading term
4135  */
4136  kMergeBintoL(strat);
4137  j = strat->Ll;
4138  loop /*cannot be changed into a for !!! */
4139  {
4140  if (j <= 0)
4141  {
4142  /*now L[0] cannot be canceled any more and the tail can be removed*/
4143  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4144  break;
4145  }
4146  if (strat->L[j].p2 == p) // Was the element added from B?
4147  {
4148  i = j-1;
4149  loop
4150  {
4151  if (i < 0) break;
4152  // Element is from B and has the same lcm as L[j]
4153  if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4154  && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4155  {
4156  /*L[i] could be canceled but we search for a better one to cancel*/
4157  strat->c3++;
4158 #ifdef KDEBUG
4159  if (TEST_OPT_DEBUG)
4160  {
4161  PrintS("--- chain criterion func chainCritRing type 3\n");
4162  PrintS("strat->L[j].lcm:");
4163  wrp(strat->L[j].lcm);
4164  PrintS(" strat->L[i].lcm:");
4165  wrp(strat->L[i].lcm);
4166  PrintLn();
4167  }
4168 #endif
4169  #ifdef ADIDEBUG
4170  printf("\nChainCrit3\n");
4171  pWrite(strat->L[j].p);
4172  pWrite(strat->L[j].p1);
4173  pWrite(strat->L[j].p2);
4174  #endif
4175  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4176  && (pNext(strat->L[l].p) == strat->tail)
4177  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4178  && pDivisibleBy(p,strat->L[l].lcm))
4179  {
4180  /*
4181  *"NOT equal(...)" because in case of "equal" the element L[l]
4182  *is "older" and has to be from theoretical point of view behind
4183  *L[i], but we do not want to reorder L
4184  */
4185  strat->L[i].p2 = strat->tail;
4186  /*
4187  *L[l] will be canceled, we cannot cancel L[i] later on,
4188  *so we mark it with "tail"
4189  */
4190  deleteInL(strat->L,&strat->Ll,l,strat);
4191  i--;
4192  }
4193  else
4194  {
4195  deleteInL(strat->L,&strat->Ll,i,strat);
4196  }
4197  j--;
4198  }
4199  i--;
4200  }
4201  }
4202  else if (strat->L[j].p2 == strat->tail)
4203  {
4204  /*now L[j] cannot be canceled any more and the tail can be removed*/
4205  strat->L[j].p2 = p;
4206  }
4207  j--;
4208  }
4209 }
4210 #endif
4211 
4212 #ifdef HAVE_RINGS
4213 long ind2(long arg)
4214 {
4215  long ind = 0;
4216  if (arg <= 0) return 0;
4217  while (arg%2 == 0)
4218  {
4219  arg = arg / 2;
4220  ind++;
4221  }
4222  return ind;
4223 }
4224 
4225 long ind_fact_2(long arg)
4226 {
4227  long ind = 0;
4228  if (arg <= 0) return 0;
4229  if (arg%2 == 1) { arg--; }
4230  while (arg > 0)
4231  {
4232  ind += ind2(arg);
4233  arg = arg - 2;
4234  }
4235  return ind;
4236 }
4237 #endif
4238 
4239 #ifdef HAVE_VANIDEAL
4240 long twoPow(long arg)
4241 {
4242  return 1L << arg;
4243 }
4244 
4245 /*2
4246 * put the pair (p, f) in B and f in T
4247 */
4248 void enterOneZeroPairRing (poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR = -1)
4249 {
4250  int l,j,compare,compareCoeff;
4251  LObject Lp;
4252 
4253 #ifdef KDEBUG
4254  Lp.ecart=0; Lp.length=0;
4255 #endif
4256  /*- computes the lcm(s[i],p) -*/
4257  Lp.lcm = pInit();
4258 
4259  pLcm(p,f,Lp.lcm);
4260  pSetm(Lp.lcm);
4261  pSetCoeff(Lp.lcm, nLcm(pGetCoeff(p), pGetCoeff(f), currRing));
4262  assume(!strat->sugarCrit);
4263  assume(!strat->fromT);
4264  /*
4265  *the set B collects the pairs of type (S[j],p)
4266  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
4267  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
4268  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
4269  */
4270  for(j = strat->Bl;j>=0;j--)
4271  {
4272  compare=pDivCompRing(strat->B[j].lcm,Lp.lcm);
4273  compareCoeff = nDivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(Lp.lcm));
4274  if (compareCoeff == 0 || compare == compareCoeff)
4275  {
4276  if (compare == 1)
4277  {
4278  strat->c3++;
4279  pLmDelete(Lp.lcm);
4280  return;
4281  }
4282  else
4283  if (compare == -1)
4284  {
4285  deleteInL(strat->B,&strat->Bl,j,strat);
4286  strat->c3++;
4287  }
4288  }
4289  if (compare == pDivComp_EQUAL)
4290  {
4291  // Add hint for same LM and direction of LC (later) (TODO Oliver)
4292  if (compareCoeff == 1)
4293  {
4294  strat->c3++;
4295  pLmDelete(Lp.lcm);
4296  return;
4297  }
4298  else
4299  if (compareCoeff == -1)
4300  {
4301  deleteInL(strat->B,&strat->Bl,j,strat);
4302  strat->c3++;
4303  }
4304  }
4305  }
4306  /*
4307  *the pair (S[i],p) enters B if the spoly != 0
4308  */
4309  /*- compute the short s-polynomial -*/
4310  if ((f==NULL) || (p==NULL)) return;
4311  pNorm(p);
4312  {
4313  Lp.p = ksCreateShortSpoly(f, p, strat->tailRing);
4314  }
4315  if (Lp.p == NULL) //deactivated, as we are adding pairs with zeropoly and not from S
4316  {
4317  /*- the case that the s-poly is 0 -*/
4318 // if (strat->pairtest==NULL) initPairtest(strat);
4319 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
4320 // strat->pairtest[strat->sl+1] = TRUE;
4321  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
4322  /*
4323  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
4324  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
4325  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
4326  *term of p devides the lcm(s,r)
4327  *(this canceling should be done here because
4328  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
4329  *the first case is handeled in chainCrit
4330  */
4331  if (Lp.lcm!=NULL) pLmDelete(Lp.lcm);
4332  }
4333  else
4334  {
4335  /*- the pair (S[i],p) enters B -*/
4336  Lp.p1 = f;
4337  Lp.p2 = p;
4338 
4339  pNext(Lp.p) = strat->tail;
4340 
4341  LObject tmp_h(f, currRing, strat->tailRing);
4342  tmp_h.SetShortExpVector();
4343  strat->initEcart(&tmp_h);
4344  tmp_h.sev = pGetShortExpVector(tmp_h.p);
4345  tmp_h.t_p = t_p;
4346 
4347  enterT(tmp_h, strat, strat->tl + 1);
4348 
4349  if (atR >= 0)
4350  {
4351  Lp.i_r2 = atR;
4352  Lp.i_r1 = strat->tl;
4353  }
4354 
4355  strat->initEcartPair(&Lp,f,p,0/*strat->ecartS[i]*/,ecart); // Attention: TODO: break ecart
4356  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
4357  enterL(&strat->B, &strat->Bl, &strat->Bmax, Lp, l);
4358  }
4359 }
4360 
4361 /* Helper for kCreateZeroPoly
4362  * enumerating the exponents
4363 ring r = 2^2, (a, b, c), lp; ideal G0 = system("createG0"); ideal G = interred(G0); ncols(G0); ncols(G);
4364  */
4365 
4366 int nextZeroSimplexExponent (long exp[], long ind[], long cexp[], long cind[], long* cabsind, long step[], long bound, long N)
4367 /* gives the next exponent from the set H_1 */
4368 {
4369  long add = ind2(cexp[1] + 2);
4370  if ((*cabsind < bound) && (*cabsind - step[1] + add < bound))
4371  {
4372  cexp[1] += 2;
4373  cind[1] += add;
4374  *cabsind += add;
4375  }
4376  else
4377  {
4378  // cabsind >= habsind
4379  if (N == 1) return 0;
4380  int i = 1;
4381  while (exp[i] == cexp[i] && i <= N) i++;
4382  cexp[i] = exp[i];
4383  *cabsind -= cind[i];
4384  cind[i] = ind[i];
4385  step[i] = 500000;
4386  *cabsind += cind[i];
4387  // Print("in: %d\n", *cabsind);
4388  i += 1;
4389  if (i > N) return 0;
4390  do
4391  {
4392  step[1] = 500000;
4393  for (int j = i + 1; j <= N; j++)
4394  {
4395  if (step[1] > step[j]) step[1] = step[j];
4396  }
4397  add = ind2(cexp[i] + 2);
4398  if (*cabsind - step[1] + add >= bound)
4399  {
4400  cexp[i] = exp[i];
4401  *cabsind -= cind[i];
4402  cind[i] = ind[i];
4403  *cabsind += cind[i];
4404  step[i] = 500000;
4405  i += 1;
4406  if (i > N) return 0;
4407  }
4408  else step[1] = -1;
4409  } while (step[1] != -1);
4410  step[1] = 500000;
4411  cexp[i] += 2;
4412  cind[i] += add;
4413  *cabsind += add;
4414  if (add < step[i]) step[i] = add;
4415  for (i = 2; i <= N; i++)
4416  {
4417  if (step[1] > step[i]) step[1] = step[i];
4418  }
4419  }
4420  return 1;
4421 }
4422 
4423 /*
4424  * Creates the zero Polynomial on position exp
4425  * long exp[] : exponent of leading term
4426  * cabsind : total 2-ind of exp (if -1 will be computed)
4427  * poly* t_p : will hold the LT in tailRing
4428  * leadRing : ring for the LT
4429  * tailRing : ring for the tail
4430  */
4431 
4432 poly kCreateZeroPoly(long exp[], long cabsind, poly* t_p, ring leadRing, ring tailRing)
4433 {
4434 
4435  poly zeroPoly = NULL;
4436 
4437  number tmp1;
4438  poly tmp2, tmp3;
4439 
4440  if (cabsind == -1)
4441  {
4442  cabsind = 0;
4443  for (int i = 1; i <= leadRing->N; i++)
4444  {
4445  cabsind += ind_fact_2(exp[i]);
4446  }
4447 // Print("cabsind: %d\n", cabsind);
4448  }
4449  if (cabsind < leadRing->ch)
4450  {
4451  zeroPoly = p_ISet(twoPow(leadRing->ch - cabsind), tailRing);
4452  }
4453  else
4454  {
4455  zeroPoly = p_ISet(1, tailRing);
4456  }
4457  for (int i = 1; i <= leadRing->N; i++)
4458  {
4459  for (long j = 1; j <= exp[i]; j++)
4460  {
4461  tmp1 = nInit(j);
4462  tmp2 = p_ISet(1, tailRing);
4463  p_SetExp(tmp2, i, 1, tailRing);
4464  p_Setm(tmp2, tailRing);
4465  if (nIsZero(tmp1))
4466  { // should nowbe obsolet, test ! TODO OLIVER
4467  zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
4468  }
4469  else
4470  {
4471  tmp3 = p_NSet(nCopy(tmp1), tailRing);
4472  zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing);
4473  }
4474  }
4475  }
4476  tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing);
4477  for (int i = 1; i <= leadRing->N; i++)
4478  {
4479  pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
4480  }
4481  p_Setm(tmp2, leadRing);
4482  *t_p = zeroPoly;
4483  zeroPoly = pNext(zeroPoly);
4484  pNext(*t_p) = NULL;
4485  pNext(tmp2) = zeroPoly;
4486  return tmp2;
4487 }
4488 
4489 // #define OLI_DEBUG
4490 
4491 /*
4492  * Generate the s-polynomial for the virtual set of zero-polynomials
4493  */
4494 
4495 void initenterzeropairsRing (poly p, int ecart, kStrategy strat, int atR)
4496 {
4497  // Initialize
4498  long exp[50]; // The exponent of \hat{X} (basepoint)
4499  long cexp[50]; // The current exponent for iterating over all
4500  long ind[50]; // The power of 2 in the i-th component of exp
4501  long cind[50]; // analog for cexp
4502  long mult[50]; // How to multiply the elements of G
4503  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4504  long habsind = 0; // The abs. index of the coefficient of h
4505  long step[50]; // The last increases
4506  for (int i = 1; i <= currRing->N; i++)
4507  {
4508  exp[i] = p_GetExp(p, i, currRing);
4509  if (exp[i] & 1 != 0)
4510  {
4511  exp[i] = exp[i] - 1;
4512  mult[i] = 1;
4513  }
4514  cexp[i] = exp[i];
4515  ind[i] = ind_fact_2(exp[i]);
4516  cabsind += ind[i];
4517  cind[i] = ind[i];
4518  step[i] = 500000;
4519  }
4520  step[1] = 500000;
4521  habsind = ind2(n_Int(pGetCoeff(p), currRing->cf);
4522  long bound = currRing->ch - habsind;
4523 #ifdef OLI_DEBUG
4524  PrintS("-------------\npoly :");
4525  wrp(p);
4526  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4527  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4528  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4529  Print("bound : %d\n", bound);
4530  Print("cind : %d\n", cabsind);
4531 #endif
4532  if (cabsind == 0)
4533  {
4534  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4535  {
4536  return;
4537  }
4538  }
4539  // Now the whole simplex
4540  do
4541  {
4542  // Build s-polynomial
4543  // 2**ind-def * mult * g - exp-def * h
4544  poly t_p;
4545  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, strat->tailRing);
4546 #ifdef OLI_DEBUG
4547  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4548  PrintS("zPoly : ");
4549  wrp(zeroPoly);
4550  PrintLn();
4551 #endif
4552  enterOneZeroPairRing(zeroPoly, t_p, p, ecart, strat, atR);
4553  }
4554  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4555 }
4556 
4557 /*
4558  * Create the Groebner basis of the vanishing polynomials.
4559  */
4560 
4561 ideal createG0()
4562 {
4563  // Initialize
4564  long exp[50]; // The exponent of \hat{X} (basepoint)
4565  long cexp[50]; // The current exponent for iterating over all
4566  long ind[50]; // The power of 2 in the i-th component of exp
4567  long cind[50]; // analog for cexp
4568  long mult[50]; // How to multiply the elements of G
4569  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4570  long habsind = 0; // The abs. index of the coefficient of h
4571  long step[50]; // The last increases
4572  for (int i = 1; i <= currRing->N; i++)
4573  {
4574  exp[i] = 0;
4575  cexp[i] = exp[i];
4576  ind[i] = 0;
4577  step[i] = 500000;
4578  cind[i] = ind[i];
4579  }
4580  long bound = currRing->ch;
4581  step[1] = 500000;
4582 #ifdef OLI_DEBUG
4583  PrintS("-------------\npoly :");
4584 // wrp(p);
4585  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4586  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4587  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4588  Print("bound : %d\n", bound);
4589  Print("cind : %d\n", cabsind);
4590 #endif
4591  if (cabsind == 0)
4592  {
4593  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4594  {
4595  return idInit(1, 1);
4596  }
4597  }
4598  ideal G0 = idInit(1, 1);
4599  // Now the whole simplex
4600  do
4601  {
4602  // Build s-polynomial
4603  // 2**ind-def * mult * g - exp-def * h
4604  poly t_p;
4605  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, currRing);
4606 #ifdef OLI_DEBUG
4607  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4608  PrintS("zPoly : ");
4609  wrp(zeroPoly);
4610  PrintLn();
4611 #endif
4612  // Add to ideal
4613  pEnlargeSet(&(G0->m), IDELEMS(G0), 1);
4614  IDELEMS(G0) += 1;
4615  G0->m[IDELEMS(G0) - 1] = zeroPoly;
4616  }
4617  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4618  idSkipZeroes(G0);
4619  return G0;
4620 }
4621 #endif
4622 
4623 #ifdef HAVE_RINGS
4624 /*2
4625 *(s[0],h),...,(s[k],h) will be put to the pairset L
4626 */
4627 void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4628 {
4629  const int iCompH = pGetComp(h);
4630  if (!nIsOne(pGetCoeff(h)))
4631  {
4632  int j;
4633 
4634  for (j=0; j<=k; j++)
4635  {
4636  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4637 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4638 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4639  if (((iCompH == pGetComp(strat->S[j]))
4640  || (0 == pGetComp(strat->S[j])))
4641  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4642  {
4643  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4644  }
4645  }
4646  }
4647 }
4648 
4649 static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4650 {
4651  const int iCompH = pGetComp(h);
4652  if (!nIsOne(pGetCoeff(h)))
4653  {
4654  int j;
4655 
4656  for (j=0; j<=k && !strat->sigdrop; j++)
4657  {
4658  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4659 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4660 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4661  if (((iCompH == pGetComp(strat->S[j]))
4662  || (0 == pGetComp(strat->S[j])))
4663  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4664  {
4665  enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4666  }
4667  }
4668  }
4669 }
4670 #endif
4671 
4672 #ifdef HAVE_RINGS
4673 /*2
4674 * Generates spoly(0, h) if applicable. Assumes ring in Z/2^n.
4675 */
4677 {
4678  if (nIsOne(pGetCoeff(h))) return;
4679  number gcd;
4680  bool go = false;
4681  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4682  {
4683  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4684  go = true;
4685  }
4686  else
4687  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4688  if (go || !nIsOne(gcd))
4689  {
4690  poly p = h->next;
4691  if (!go)
4692  {
4693  number tmp = gcd;
4694  gcd = n_Ann(gcd,currRing->cf);
4695  nDelete(&tmp);
4696  }
4697  p_Test(p,strat->tailRing);
4698  p = pp_Mult_nn(p, gcd, strat->tailRing);
4699  nDelete(&gcd);
4700 
4701  if (p != NULL)
4702  {
4703  if (TEST_OPT_PROT)
4704  {
4705  PrintS("Z");
4706  }
4707 #ifdef KDEBUG
4708  if (TEST_OPT_DEBUG)
4709  {
4710  PrintS("--- create zero spoly: ");
4711  p_wrp(h,currRing,strat->tailRing);
4712  PrintS(" ---> ");
4713  }
4714 #endif
4715  poly tmp = pInit();
4716  pSetCoeff0(tmp, pGetCoeff(p));
4717  for (int i = 1; i <= rVar(currRing); i++)
4718  {
4719  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4720  }
4722  {
4723  p_SetComp(tmp, p_GetComp(p, strat->tailRing), currRing);
4724  }
4725  p_Setm(tmp, currRing);
4726  p = p_LmFreeAndNext(p, strat->tailRing);
4727  pNext(tmp) = p;
4728  LObject Lp;
4729  Lp.Init();
4730  Lp.p = tmp;
4731  Lp.tailRing = strat->tailRing;
4732  int posx;
4733  if (Lp.p!=NULL)
4734  {
4735  strat->initEcart(&Lp);
4736  if (strat->Ll==-1)
4737  posx =0;
4738  else
4739  posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4740  Lp.sev = pGetShortExpVector(Lp.p);
4741  if (strat->tailRing != currRing)
4742  {
4743  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4744  }
4745 #ifdef KDEBUG
4746  if (TEST_OPT_DEBUG)
4747  {
4748  p_wrp(tmp,currRing,strat->tailRing);
4749  PrintLn();
4750  }
4751 #endif
4752  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4753  }
4754  }
4755  }
4756  nDelete(&gcd);
4757 }
4758 
4760 {
4761  if (nIsOne(pGetCoeff(h))) return;
4762  number gcd;
4763  bool go = false;
4764  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4765  {
4766  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4767  go = true;
4768  }
4769  else
4770  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4771  if (go || !nIsOne(gcd))
4772  {
4773  poly p = h->next;
4774  if (!go)
4775  {
4776  number tmp = gcd;
4777  gcd = n_Ann(gcd,currRing->cf);
4778  nDelete(&tmp);
4779  }
4780  p_Test(p,strat->tailRing);
4781  p = pp_Mult_nn(p, gcd, strat->tailRing);
4782 
4783  if (p != NULL)
4784  {
4785  if (TEST_OPT_PROT)
4786  {
4787  PrintS("Z");
4788  }
4789 #ifdef KDEBUG
4790  if (TEST_OPT_DEBUG)
4791  {
4792  PrintS("--- create zero spoly: ");
4793  p_wrp(h,currRing,strat->tailRing);
4794  PrintS(" ---> ");
4795  }
4796 #endif
4797  poly tmp = pInit();
4798  pSetCoeff0(tmp, pGetCoeff(p));
4799  for (int i = 1; i <= rVar(currRing); i++)
4800  {
4801  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4802  }
4804  {
4805  p_SetComp(tmp, p_GetComp(p, strat->tailRing), currRing);
4806  }
4807  p_Setm(tmp, currRing);
4808  p = p_LmFreeAndNext(p, strat->tailRing);
4809  pNext(tmp) = p;
4810  LObject Lp;
4811  Lp.Init();
4812  Lp.p = tmp;
4813  //printf("\nOld\n");pWrite(h);pWrite(hSig);
4814  #if EXT_POLY_NEW
4815  Lp.sig = pp_Mult_nn(hSig, gcd, currRing);
4816  if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4817  {
4818  #ifdef ADIDEBUG
4819  printf("\nSigdrop in enterextended spoly\n");pWrite(h);pWrite(hSig);
4820  #endif
4821  strat->sigdrop = TRUE;
4822  //Try to reduce it as far as we can via redRing
4823  int red_result = redRing(&Lp,strat);
4824  #ifdef ADIDEBUG
4825  printf("\nAfter redRing reduce:\n");pWrite(Lp.p);
4826  #endif
4827  if(red_result == 0)
4828  {
4829  // Cancel the sigdrop
4830  #ifdef ADIDEBUG
4831  printf("\nCancel the sigdrop. It reduced to 0\n");
4832  #endif
4833  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4834  strat->sigdrop = FALSE;
4835  return;
4836  }
4837  else
4838  {
4839  #ifdef ADIDEBUG
4840  printf("\nSigdrop. end\n");
4841  #endif
4842  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4843  #if 1
4844  strat->enterS(Lp,0,strat,strat->tl);
4845  #endif
4846  return;
4847  }
4848 
4849  }
4850  #else
4851  Lp.sig = pOne();
4852  if(strat->Ll >= 0)
4853  p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4854  else
4855  p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4856  #endif
4857  Lp.tailRing = strat->tailRing;
4858  int posx;
4859  if (Lp.p!=NULL)
4860  {
4861  strat->initEcart(&Lp);
4862  if (strat->Ll==-1)
4863  posx =0;
4864  else
4865  posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4866  Lp.sev = pGetShortExpVector(Lp.p);
4867  if (strat->tailRing != currRing)
4868  {
4869  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4870  }
4871 #ifdef KDEBUG
4872  if (TEST_OPT_DEBUG)
4873  {
4874  p_wrp(tmp,currRing,strat->tailRing);
4875  PrintLn();
4876  }
4877 #endif
4878  //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4879  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4880  }
4881  }
4882  nDelete(&gcd);
4883  }
4884  nDelete(&gcd);
4885 }
4886 #endif
4887 
4888 #ifdef HAVE_RINGS
4889 void clearSbatch (poly h,int k,int pos,kStrategy strat)
4890 {
4891  int j = pos;
4892  if ( (!strat->fromT)
4893  && ((strat->syzComp==0)
4894  ||(pGetComp(h)<=strat->syzComp)
4895  ))
4896  {
4897  // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4898  unsigned long h_sev = pGetShortExpVector(h);
4899  loop
4900  {
4901  if (j > k) break;
4902  clearS(h,h_sev, &j,&k,strat);
4903  j++;
4904  }
4905  // Print("end clearS sl=%d\n",strat->sl);
4906  }
4907 }
4908 #endif
4909 
4910 #ifdef HAVE_RINGS
4911 /*2
4912 * Generates a sufficient set of spolys (maybe just a finite generating
4913 * set of the syzygys)
4914 */
4915 void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4916 {
4918  // enter also zero divisor * poly, if this is non zero and of smaller degree
4919  if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat);
4920  initenterpairs(h, k, ecart, 0, strat, atR);
4921  initenterstrongPairs(h, k, ecart, 0, strat, atR);
4922  clearSbatch(h, k, pos, strat);
4923 }
4924 
4925 void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4926 {
4928  // enter also zero divisor * poly, if this is non zero and of smaller degree
4929  #ifdef ADIDEBUG
4930  printf("\n Trying to add extended spolys\n");
4931  #endif
4932  if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4933  if(strat->sigdrop) return;
4934  #ifdef ADIDEBUG
4935  printf("\n Trying to add spolys\n");
4936  #endif
4937  initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4938  if(strat->sigdrop) return;
4939  #ifdef ADIDEBUG
4940  printf("\n Trying to add gcd-polys\n");
4941  #endif
4942  initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4943  if(strat->sigdrop) return;
4944  clearSbatch(h, k, pos, strat);
4945 }
4946 #endif
4947 
4948 /*2
4949 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4950 *superfluous elements in S will be deleted
4951 */
4952 void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4953 {
4954  int j=pos;
4955 
4957  initenterpairs(h,k,ecart,0,strat, atR);
4958  if ( (!strat->fromT)
4959  && ((strat->syzComp==0)
4960  ||(pGetComp(h)<=strat->syzComp)))
4961  {
4962  unsigned long h_sev = pGetShortExpVector(h);
4963  loop
4964  {
4965  if (j > k) break;
4966  clearS(h,h_sev, &j,&k,strat);
4967  j++;
4968  }
4969  }
4970 }
4971 
4972 /*2
4973 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4974 *superfluous elements in S will be deleted
4975 *this is a special variant of signature-based algorithms including the
4976 *signatures for criteria checks
4977 */
4978 void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4979 {
4980  int j=pos;
4982  initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4983  if ( (!strat->fromT)
4984  && ((strat->syzComp==0)
4985  ||(pGetComp(h)<=strat->syzComp)))
4986  {
4987  unsigned long h_sev = pGetShortExpVector(h);
4988  loop
4989  {
4990  if (j > k) break;
4991  clearS(h,h_sev, &j,&k,strat);
4992  j++;
4993  }
4994  }
4995 }
4996 
4997 /*2
4998 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4999 *superfluous elements in S will be deleted
5000 */
5001 void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
5002 {
5003  int j;
5004  const int iCompH = pGetComp(h);
5005 
5006  if (rField_is_Ring(currRing))
5007  {
5008  for (j=0; j<=k; j++)
5009  {
5010  const int iCompSj = pGetComp(strat->S[j]);
5011  if ((iCompH==iCompSj)
5012  //|| (0==iCompH) // can only happen,if iCompSj==0
5013  || (0==iCompSj))
5014  {
5015  enterOnePairRing(j,h,ecart,FALSE,strat, atR);
5016  }
5017  }
5018  kMergeBintoL(strat);
5019  }
5020  else
5021  {
5022  for (j=0; j<=k; j++)
5023  {
5024  const int iCompSj = pGetComp(strat->S[j]);
5025  if ((iCompH==iCompSj)
5026  //|| (0==iCompH) // can only happen,if iCompSj==0
5027  || (0==iCompSj))
5028  {
5029  enterOnePairSpecial(j,h,ecart,strat, atR);
5030  }
5031  }
5032  }
5033 
5034  if (strat->noClearS) return;
5035 
5036 // #ifdef HAVE_PLURAL
5037 /*
5038  if (rIsPluralRing(currRing))
5039  {
5040  j=pos;
5041  loop
5042  {
5043  if (j > k) break;
5044 
5045  if (pLmDivisibleBy(h, strat->S[j]))
5046  {
5047  deleteInS(j, strat);
5048  j--;
5049  k--;
5050  }
5051 
5052  j++;
5053  }
5054  }
5055  else
5056 */
5057 // #endif // ??? Why was the following cancelation disabled for non-commutative rings?
5058  {
5059  j=pos;
5060  loop
5061  {
5062  unsigned long h_sev = pGetShortExpVector(h);
5063  if (j > k) break;
5064  clearS(h,h_sev,&j,&k,strat);
5065  j++;
5066  }
5067  }
5068 }
5069 
5070 /*2
5071 *reorders s with respect to posInS,
5072 *suc is the first changed index or zero
5073 */
5074 
5075 void reorderS (int* suc,kStrategy strat)
5076 {
5077  int i,j,at,ecart, s2r;
5078  int fq=0;
5079  unsigned long sev;
5080  poly p;
5081  int new_suc=strat->sl+1;
5082  i= *suc;
5083  if (i<0) i=0;
5084 
5085  for (; i<=strat->sl; i++)
5086  {
5087  at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
5088  if (at != i)
5089  {
5090  if (new_suc > at) new_suc = at;
5091  p = strat->S[i];
5092  ecart = strat->ecartS[i];
5093  sev = strat->sevS[i];
5094  s2r = strat->S_2_R[i];
5095  if (strat->fromQ!=NULL) fq=strat->fromQ[i];
5096  for (j=i; j>=at+1; j--)
5097  {
5098  strat->S[j] = strat->S[j-1];
5099  strat->ecartS[j] = strat->ecartS[j-1];
5100  strat->sevS[j] = strat->sevS[j-1];
5101  strat->S_2_R[j] = strat->S_2_R[j-1];
5102  }
5103  strat->S[at] = p;
5104  strat->ecartS[at] = ecart;
5105  strat->sevS[at] = sev;
5106  strat->S_2_R[at] = s2r;
5107  if (strat->fromQ!=NULL)
5108  {
5109  for (j=i; j>=at+1; j--)
5110  {
5111  strat->fromQ[j] = strat->fromQ[j-1];
5112  }
5113  strat->fromQ[at]=fq;
5114  }
5115  }
5116  }
5117  if (new_suc <= strat->sl) *suc=new_suc;
5118  else *suc=-1;
5119 }
5120 
5121 
5122 /*2
5123 *looks up the position of p in set
5124 *set[0] is the smallest with respect to the ordering-procedure deg/pComp
5125 * Assumption: posInS only depends on the leading term
5126 * otherwise, bba has to be changed
5127 */
5128 int posInS (const kStrategy strat, const int length,const poly p,
5129  const int ecart_p)
5130 {
5131  if(length==-1) return 0;
5132  polyset set=strat->S;
5133  int i;
5134  int an = 0;
5135  int en = length;
5136  int cmp_int = currRing->OrdSgn;
5138 #ifdef HAVE_PLURAL
5139  && (currRing->real_var_start==0)
5140 #endif
5141 #if 0
5142  || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
5143 #endif
5144  )
5145  {
5146  int o=p_Deg(p,currRing);
5147  int oo=p_Deg(set[length],currRing);
5148 
5149  if ((oo<o)
5150  || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
5151  return length+1;
5152 
5153  loop
5154  {
5155  if (an >= en-1)
5156  {
5157  if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
5158  {
5159  return an;
5160  }
5161  return en;
5162  }
5163  i=(an+en) / 2;
5164  if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
5165  else an=i;
5166  }
5167  }
5168  else
5169  {
5170  if (rField_is_Ring(currRing))
5171  {
5172  if (pLmCmp(set[length],p)== -cmp_int)
5173  return length+1;
5174  int cmp;
5175  loop
5176  {
5177  if (an >= en-1)
5178  {
5179  cmp = pLmCmp(set[an],p);
5180  if (cmp == cmp_int) return an;
5181  if (cmp == -cmp_int) return en;
5182  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
5183  return an;
5184  }
5185  i = (an+en) / 2;
5186  cmp = pLmCmp(set[i],p);
5187  if (cmp == cmp_int) en = i;
5188  else if (cmp == -cmp_int) an = i;
5189  else
5190  {
5191  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
5192  else en = i;
5193  }
5194  }
5195  }
5196  else
5197  if (pLmCmp(set[length],p)== -cmp_int)
5198  return length+1;
5199 
5200  loop
5201  {
5202  if (an >= en-1)
5203  {
5204  if (pLmCmp(set[an],p) == cmp_int) return an;
5205  if (pLmCmp(set[an],p) == -cmp_int) return en;
5206  if ((cmp_int!=1)
5207  && ((strat->ecartS[an])>ecart_p))
5208  return an;
5209  return en;
5210  }
5211  i=(an+en) / 2;
5212  if (pLmCmp(set[i],p) == cmp_int) en=i;
5213  else if (pLmCmp(set[i],p) == -cmp_int) an=i;
5214  else
5215  {
5216  if ((cmp_int!=1)
5217  &&((strat->ecartS[i])<ecart_p))
5218  en=i;
5219  else
5220  an=i;
5221  }
5222  }
5223  }
5224 }
5225 
5226 
5227 // sorts by degree and pLtCmp
5228 // but puts pure monomials at the beginning
5229 int posInSMonFirst (const kStrategy strat, const int length,const poly p)
5230 {
5231  if (length<0) return 0;
5232  polyset set=strat->S;
5233  if(pNext(p) == NULL)
5234  {
5235  int mon = 0;
5236  for(int i = 0;i<=length;i++)
5237  {
5238  if(set[i] != NULL && pNext(set[i]) == NULL)
5239  mon++;
5240  }
5241  int o = p_Deg(p,currRing);
5242  int op = p_Deg(set[mon],currRing);
5243 
5244  if ((op < o)
5245  || ((op == o) && (pLtCmp(set[mon],p) == -1)))
5246  return length+1;
5247  int i;
5248  int an = 0;
5249  int en= mon;
5250  loop
5251  {
5252  if (an >= en-1)
5253  {
5254  op = p_Deg(set[an],currRing);
5255  if ((op < o)
5256  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5257  return en;
5258  return an;
5259  }
5260  i=(an+en) / 2;
5261  op = p_Deg(set[i],currRing);
5262  if ((op < o)
5263  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5264  an=i;
5265  else
5266  en=i;
5267  }
5268  }
5269  else /*if(pNext(p) != NULL)*/
5270  {
5271  int o = p_Deg(p,currRing);
5272  int op = p_Deg(set[length],currRing);
5273 
5274  if ((op < o)
5275  || ((op == o) && (pLtCmp(set[length],p) == -1)))
5276  return length+1;
5277  int i;
5278  int an = 0;
5279  for(i=0;i<=length;i++)
5280  if(set[i] != NULL && pNext(set[i]) == NULL)
5281  an++;
5282  int en= length;
5283  loop
5284  {
5285  if (an >= en-1)
5286  {
5287  op = p_Deg(set[an],currRing);
5288  if ((op < o)
5289  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5290  return en;
5291  return an;
5292  }
5293  i=(an+en) / 2;
5294  op = p_Deg(set[i],currRing);
5295  if ((op < o)
5296  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5297  an=i;
5298  else
5299  en=i;
5300  }
5301  }
5302 }
5303 
5304 // sorts by degree and pLtCmp in the block between start,end;
5305 // but puts pure monomials at the beginning
5306 int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
5307 {
5308  if(end < 0 || end >= IDELEMS(F))
5309  end = IDELEMS(F);
5310  if (end<0) return 0;
5311  if(pNext(p) == NULL) return start;
5312  polyset set=F->m;
5313  int o = p_Deg(p,currRing);
5314  int op;
5315  int i;
5316  int an = start;
5317  for(i=start;i<end;i++)
5318  if(set[i] != NULL && pNext(set[i]) == NULL)
5319  an++;
5320  if(an == end-1)
5321  return end;
5322  int en= end;
5323  loop
5324  {
5325  if(an>=en)
5326  return en;
5327  if (an == en-1)
5328  {
5329  op = p_Deg(set[an],currRing);
5330  if ((op < o)
5331  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5332  return en;
5333  return an;
5334  }
5335  i=(an+en) / 2;
5336  op = p_Deg(set[i],currRing);
5337  if ((op < o)
5338  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5339  an=i;
5340  else
5341  en=i;
5342  }
5343 }
5344 
5345 
5346 /*2
5347 * looks up the position of p in set
5348 * the position is the last one
5349 */
5350 int posInT0 (const TSet,const int length,LObject &)
5351 {
5352  return (length+1);
5353 }
5354 
5355 
5356 /*2
5357 * looks up the position of p in T
5358 * set[0] is the smallest with respect to the ordering-procedure
5359 * pComp
5360 */
5361 int posInT1 (const TSet set,const int length,LObject &p)
5362 {
5363  if (length==-1) return 0;
5364 
5365  if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
5366 
5367  int i;
5368  int an = 0;
5369  int en= length;
5370 
5371  loop
5372  {
5373  if (an >= en-1)
5374  {
5375  if (pLmCmp(set[an].p,p.p) == currRing->OrdSgn) return an;
5376  return en;
5377  }
5378  i=(an+en) / 2;
5379  if (pLmCmp(set[i].p,p.p) == currRing->OrdSgn) en=i;
5380  else an=i;
5381  }
5382 }
5383 
5384 /*2
5385 * looks up the position of p in T
5386 * set[0] is the smallest with respect to the ordering-procedure
5387 * length
5388 */
5389 int posInT2 (const TSet set,const int length,LObject &p)
5390 {
5391  p.GetpLength();
5392  if (length==-1)
5393  return 0;
5394  if (set[length].length<p.length)
5395  return length+1;
5396 
5397  int i;
5398  int an = 0;
5399  int en= length;
5400 
5401  loop
5402  {
5403  if (an >= en-1)
5404  {
5405  if (set[an].length>p.length) return an;
5406  return en;
5407  }
5408  i=(an+en) / 2;
5409  if (set[i].length>p.length) en=i;
5410  else an=i;
5411  }
5412 }
5413 
5414 /*2
5415 * looks up the position of p in T
5416 * set[0] is the smallest with respect to the ordering-procedure
5417 * totaldegree,pComp
5418 */
5419 int posInT11 (const TSet set,const int length,LObject &p)
5420 {
5421  if (length==-1) return 0;
5422 
5423  int o = p.GetpFDeg();
5424  int op = set[length].GetpFDeg();
5425 
5426  if ((op < o)
5427  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5428  return length+1;
5429 
5430  int i;
5431  int an = 0;
5432  int en= length;
5433 
5434  loop
5435  {
5436  if (an >= en-1)
5437  {
5438  op= set[an].GetpFDeg();
5439  if ((op > o)
5440  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5441  return an;
5442  return en;
5443  }
5444  i=(an+en) / 2;
5445  op = set[i].GetpFDeg();
5446  if (( op > o)
5447  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5448  en=i;
5449  else
5450  an=i;
5451  }
5452 }
5453 
5454 #ifdef HAVE_RINGS
5455 int posInT11Ring (const TSet set,const int length,LObject &p)
5456 {
5457  if (length==-1) return 0;
5458 
5459  int o = p.GetpFDeg();
5460  int op = set[length].GetpFDeg();
5461 
5462  if ((op < o)
5463  || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5464  return length+1;
5465 
5466  int i;
5467  int an = 0;
5468  int en= length;
5469 
5470  loop
5471  {
5472  if (an >= en-1)
5473  {
5474  op= set[an].GetpFDeg();
5475  if ((op > o)
5476  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5477  return an;
5478  return en;
5479  }
5480  i=(an+en) / 2;
5481  op = set[i].GetpFDeg();
5482  if (( op > o)
5483  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5484  en=i;
5485  else
5486  an=i;
5487  }
5488 }
5489 #endif
5490 
5491 /*2 Pos for rings T: Here I am
5492 * looks up the position of p in T
5493 * set[0] is the smallest with respect to the ordering-procedure
5494 * totaldegree,pComp
5495 */
5496 int posInTrg0 (const TSet set,const int length,LObject &p)
5497 {
5498  if (length==-1) return 0;
5499  int o = p.GetpFDeg();
5500  int op = set[length].GetpFDeg();
5501  int i;
5502  int an = 0;
5503  int en = length;
5504  int cmp_int = currRing->OrdSgn;
5505  if ((op < o) || (pLmCmp(set[length].p,p.p)== -cmp_int))
5506  return length+1;
5507  int cmp;
5508  loop
5509  {
5510  if (an >= en-1)
5511  {
5512  op = set[an].GetpFDeg();
5513  if (op > o) return an;
5514  if (op < 0) return en;
5515  cmp = pLmCmp(set[an].p,p.p);
5516  if (cmp == cmp_int) return an;
5517  if (cmp == -cmp_int) return en;
5518  if (nGreater(pGetCoeff(p.p), pGetCoeff(set[an].p))) return en;
5519  return an;
5520  }
5521  i = (an + en) / 2;
5522  op = set[i].GetpFDeg();
5523  if (op > o) en = i;
5524  else if (op < o) an = i;
5525  else
5526  {
5527  cmp = pLmCmp(set[i].p,p.p);
5528  if (cmp == cmp_int) en = i;
5529  else if (cmp == -cmp_int) an = i;
5530  else if (nGreater(pGetCoeff(p.p), pGetCoeff(set[i].p))) an = i;
5531  else en = i;
5532  }
5533  }
5534 }
5535 /*
5536  int o = p.GetpFDeg();
5537  int op = set[length].GetpFDeg();
5538 
5539  if ((op < o)
5540  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5541  return length+1;
5542 
5543  int i;
5544  int an = 0;
5545  int en= length;
5546 
5547  loop
5548  {
5549  if (an >= en-1)
5550  {
5551  op= set[an].GetpFDeg();
5552  if ((op > o)
5553  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5554  return an;
5555  return en;
5556  }
5557  i=(an+en) / 2;
5558  op = set[i].GetpFDeg();
5559  if (( op > o)
5560  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5561  en=i;
5562  else
5563  an=i;
5564  }
5565 }
5566  */
5567 /*2
5568 * looks up the position of p in T
5569 * set[0] is the smallest with respect to the ordering-procedure
5570 * totaldegree,pComp
5571 */
5572 int posInT110 (const TSet set,const int length,LObject &p)
5573 {
5574  p.GetpLength();
5575  if (length==-1) return 0;
5576 
5577  int o = p.GetpFDeg();
5578  int op = set[length].GetpFDeg();
5579 
5580  if (( op < o)
5581  || (( op == o) && (set[length].length<p.length))
5582  || (( op == o) && (set[length].length == p.length)
5583  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5584  return length+1;
5585 
5586  int i;
5587  int an = 0;
5588  int en= length;
5589  loop
5590  {
5591  if (an >= en-1)
5592  {
5593  op = set[an].GetpFDeg();
5594  if (( op > o)
5595  || (( op == o) && (set[an].length > p.length))
5596  || (( op == o) && (set[an].length == p.length)
5597  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5598  return an;
5599  return en;
5600  }
5601  i=(an+en) / 2;
5602  op = set[i].GetpFDeg();
5603  if (( op > o)
5604  || (( op == o) && (set[i].length > p.length))
5605  || (( op == o) && (set[i].length == p.length)
5606  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5607  en=i;
5608  else
5609  an=i;
5610  }
5611 }
5612 
5613 #ifdef HAVE_RINGS
5614 int posInT110Ring (const TSet set,const int length,LObject &p)
5615 {
5616  p.GetpLength();
5617  if (length==-1) return 0;
5618 
5619  int o = p.GetpFDeg();
5620  int op = set[length].GetpFDeg();
5621 
5622  if (( op < o)
5623  || (( op == o) && (set[length].length<p.length))
5624  || (( op == o) && (set[length].length == p.length)
5625  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5626  return length+1;
5627 
5628  int i;
5629  int an = 0;
5630  int en= length;
5631  loop
5632  {
5633  if (an >= en-1)
5634  {
5635  op = set[an].GetpFDeg();
5636  if (( op > o)
5637  || (( op == o) && (set[an].length > p.length))
5638  || (( op == o) && (set[an].length == p.length)
5639  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5640  return an;
5641  return en;
5642  }
5643  i=(an+en) / 2;
5644  op = set[i].GetpFDeg();
5645  if (( op > o)
5646  || (( op == o) && (set[i].length > p.length))
5647  || (( op == o) && (set[i].length == p.length)
5648  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5649  en=i;
5650  else
5651  an=i;
5652  }
5653 }
5654 #endif
5655 
5656 /*2
5657 * looks up the position of p in set
5658 * set[0] is the smallest with respect to the ordering-procedure
5659 * pFDeg
5660 */
5661 int posInT13 (const TSet set,const int length,LObject &p)
5662 {
5663  if (length==-1) return 0;
5664 
5665  int o = p.GetpFDeg();
5666 
5667  if (set[length].GetpFDeg() <= o)
5668  return length+1;
5669 
5670  int i;
5671  int an = 0;
5672  int en= length;
5673  loop
5674  {
5675  if (an >= en-1)
5676  {
5677  if (set[an].GetpFDeg() > o)
5678  return an;
5679  return en;
5680  }
5681  i=(an+en) / 2;
5682  if (set[i].GetpFDeg() > o)
5683  en=i;
5684  else
5685  an=i;
5686  }
5687 }
5688 
5689 // determines the position based on: 1.) Ecart 2.) pLength
5690 int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5691 {
5692  int ol = p.GetpLength();
5693  if (length==-1) return 0;
5694 
5695  int op=p.ecart;
5696 
5697  int oo=set[length].ecart;
5698  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
5699  return length+1;
5700 
5701  int i;
5702  int an = 0;
5703  int en= length;
5704  loop
5705  {
5706  if (an >= en-1)
5707  {
5708  int oo=set[an].ecart;
5709  if((oo > op)
5710  || ((oo==op) && (set[an].pLength > ol)))
5711  return an;
5712  return en;
5713  }
5714  i=(an+en) / 2;
5715  int oo=set[i].ecart;
5716  if ((oo > op)
5717  || ((oo == op) && (set[i].pLength > ol)))
5718  en=i;
5719  else
5720  an=i;
5721  }
5722 }
5723 
5724 /*2
5725 * looks up the position of p in set
5726 * set[0] is the smallest with respect to the ordering-procedure
5727 * maximaldegree, pComp
5728 */
5729 int posInT15 (const TSet set,const int length,LObject &p)
5730 /*{
5731  *int j=0;
5732  * int o;
5733  *
5734  * o = p.GetpFDeg()+p.ecart;
5735  * loop
5736  * {
5737  * if ((set[j].GetpFDeg()+set[j].ecart > o)
5738  * || ((set[j].GetpFDeg()+set[j].ecart == o)
5739  * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5740  * {
5741  * return j;
5742  * }
5743  * j++;
5744  * if (j > length) return j;
5745  * }
5746  *}
5747  */
5748 {
5749  if (length==-1) return 0;
5750 
5751  int o = p.GetpFDeg() + p.ecart;
5752  int op = set[length].GetpFDeg()+set[length].ecart;
5753 
5754  if ((op < o)
5755  || ((op == o)
5756  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5757  return length+1;
5758 
5759  int i;
5760  int an = 0;
5761  int en= length;
5762  loop
5763  {
5764  if (an >= en-1)
5765  {
5766  op = set[an].GetpFDeg()+set[an].ecart;
5767  if (( op > o)
5768  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5769  return an;
5770  return en;
5771  }
5772  i=(an+en) / 2;
5773  op = set[i].GetpFDeg()+set[i].ecart;
5774  if (( op > o)
5775  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5776  en=i;
5777  else
5778  an=i;
5779  }
5780 }
5781 
5782 #ifdef HAVE_RINGS
5783 int posInT15Ring (const TSet set,const int length,LObject &p)
5784 {
5785  if (length==-1) return 0;
5786 
5787  int o = p.GetpFDeg() + p.ecart;
5788  int op = set[length].GetpFDeg()+set[length].ecart;
5789 
5790  if ((op < o)
5791  || ((op == o)
5792  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5793  return length+1;
5794 
5795  int i;
5796  int an = 0;
5797  int en= length;
5798  loop
5799  {
5800  if (an >= en-1)
5801  {
5802  op = set[an].GetpFDeg()+set[an].ecart;
5803  if (( op > o)
5804  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5805  return an;
5806  return en;
5807  }
5808  i=(an+en) / 2;
5809  op = set[i].GetpFDeg()+set[i].ecart;
5810  if (( op > o)
5811  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5812  en=i;
5813  else
5814  an=i;
5815  }
5816 }
5817 #endif
5818 
5819 /*2
5820 * looks up the position of p in set
5821 * set[0] is the smallest with respect to the ordering-procedure
5822 * pFDeg+ecart, ecart, pComp
5823 */
5824 int posInT17 (const TSet set,const int length,LObject &p)
5825 /*
5826 *{
5827 * int j=0;
5828 * int o;
5829 *
5830 * o = p.GetpFDeg()+p.ecart;
5831 * loop
5832 * {
5833 * if ((pFDeg(set[j].p)+set[j].ecart > o)
5834 * || (((pFDeg(set[j].p)+set[j].ecart == o)
5835 * && (set[j].ecart < p.ecart)))
5836 * || ((pFDeg(set[j].p)+set[j].ecart == o)
5837 * && (set[j].ecart==p.ecart)
5838 * && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5839 * return j;
5840 * j++;
5841 * if (j > length) return j;
5842 * }
5843 * }
5844 */
5845 {
5846  if (length==-1) return 0;
5847 
5848  int o = p.GetpFDeg() + p.ecart;
5849  int op = set[length].GetpFDeg()+set[length].ecart;
5850 
5851  if ((op < o)
5852  || (( op == o) && (set[length].ecart > p.ecart))
5853  || (( op == o) && (set[length].ecart==p.ecart)
5854  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5855  return length+1;
5856 
5857  int i;
5858  int an = 0;
5859  int en= length;
5860  loop
5861  {
5862  if (an >= en-1)
5863  {
5864  op = set[an].GetpFDeg()+set[an].ecart;
5865  if (( op > o)
5866  || (( op == o) && (set[an].ecart < p.ecart))
5867  || (( op == o) && (set[an].ecart==p.ecart)
5868  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5869  return an;
5870  return en;
5871  }
5872  i=(an+en) / 2;
5873  op = set[i].GetpFDeg()+set[i].ecart;
5874  if ((op > o)
5875  || (( op == o) && (set[i].ecart < p.ecart))
5876  || (( op == o) && (set[i].ecart == p.ecart)
5877  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5878  en=i;
5879  else
5880  an=i;
5881  }
5882 }
5883 
5884 #ifdef HAVE_RINGS
5885 int posInT17Ring (const TSet set,const int length,LObject &p)
5886 {
5887  if (length==-1) return 0;
5888 
5889  int o = p.GetpFDeg() + p.ecart;
5890  int op = set[length].GetpFDeg()+set[length].ecart;
5891 
5892  if ((op < o)
5893  || (( op == o) && (set[length].ecart > p.ecart))
5894  || (( op == o) && (set[length].ecart==p.ecart)
5895  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5896  return length+1;
5897 
5898  int i;
5899  int an = 0;
5900  int en= length;
5901  loop
5902  {
5903  if (an >= en-1)
5904  {
5905  op = set[an].GetpFDeg()+set[an].ecart;
5906  if (( op > o)
5907  || (( op == o) && (set[an].ecart < p.ecart))
5908  || (( op == o) && (set[an].ecart==p.ecart)
5909  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5910  return an;
5911  return en;
5912  }
5913  i=(an+en) / 2;
5914  op = set[i].GetpFDeg()+set[i].ecart;
5915  if ((op > o)
5916  || (( op == o) && (set[i].ecart < p.ecart))
5917  || (( op == o) && (set[i].ecart == p.ecart)
5918  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5919  en=i;
5920  else
5921  an=i;
5922  }
5923 }
5924 #endif
5925 
5926 /*2
5927 * looks up the position of p in set
5928 * set[0] is the smallest with respect to the ordering-procedure
5929 * pGetComp, pFDeg+ecart, ecart, pComp
5930 */
5931 int posInT17_c (const TSet set,const int length,LObject &p)
5932 {
5933  if (length==-1) return 0;
5934 
5935  int cc = (-1+2*currRing->order[0]==ringorder_c);
5936  /* cc==1 for (c,..), cc==-1 for (C,..) */
5937  int o = p.GetpFDeg() + p.ecart;
5938  int c = pGetComp(p.p)*cc;
5939 
5940  if (pGetComp(set[length].p)*cc < c)
5941  return length+1;
5942  if (pGetComp(set[length].p)*cc == c)
5943  {
5944  int op = set[length].GetpFDeg()+set[length].ecart;
5945  if ((op < o)
5946  || ((op == o) && (set[length].ecart > p.ecart))
5947  || ((op == o) && (set[length].ecart==p.ecart)
5948  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5949  return length+1;
5950  }
5951 
5952  int i;
5953  int an = 0;
5954  int en= length;
5955  loop
5956  {
5957  if (an >= en-1)
5958  {
5959  if (pGetComp(set[an].p)*cc < c)
5960  return en;
5961  if (pGetComp(set[an].p)*cc == c)
5962  {
5963  int op = set[an].GetpFDeg()+set[an].ecart;
5964  if ((op > o)
5965  || ((op == o) && (set[an].ecart < p.ecart))
5966  || ((op == o) && (set[an].ecart==p.ecart)
5967  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5968  return an;
5969  }
5970  return en;
5971  }
5972  i=(an+en) / 2;
5973  if (pGetComp(set[i].p)*cc > c)
5974  en=i;
5975  else if (pGetComp(set[i].p)*cc == c)
5976  {
5977  int op = set[i].GetpFDeg()+set[i].ecart;
5978  if ((op > o)
5979  || ((op == o) && (set[i].ecart < p.ecart))
5980  || ((op == o) && (set[i].ecart == p.ecart)
5981  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5982  en=i;
5983  else
5984  an=i;
5985  }
5986  else
5987  an=i;
5988  }
5989 }
5990 
5991 #ifdef HAVE_RINGS
5992 int posInT17_cRing (const TSet set,const int length,LObject &p)
5993 {
5994  if (length==-1) return 0;
5995 
5996  int cc = (-1+2*currRing->order[0]==ringorder_c);
5997  /* cc==1 for (c,..), cc==-1 for (C,..) */
5998  int o = p.GetpFDeg() + p.ecart;
5999  int c = pGetComp(p.p)*cc;
6000 
6001  if (pGetComp(set[length].p)*cc < c)
6002  return length+1;
6003  if (pGetComp(set[length].p)*cc == c)
6004  {
6005  int op = set[length].GetpFDeg()+set[length].ecart;
6006  if ((op < o)
6007  || ((op == o) && (set[length].ecart > p.ecart))
6008  || ((op == o) && (set[length].ecart==p.ecart)
6009  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
6010  return length+1;
6011  }
6012 
6013  int i;
6014  int an = 0;
6015  int en= length;
6016  loop
6017  {
6018  if (an >= en-1)
6019  {
6020  if (pGetComp(set[an].p)*cc < c)
6021  return en;
6022  if (pGetComp(set[an].p)*cc == c)
6023  {
6024  int op = set[an].GetpFDeg()+set[an].ecart;
6025  if ((op > o)
6026  || ((op == o) && (set[an].ecart < p.ecart))
6027  || ((op == o) && (set[an].ecart==p.ecart)
6028  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
6029  return an;
6030  }
6031  return en;
6032  }
6033  i=(an+en) / 2;
6034  if (pGetComp(set[i].p)*cc > c)
6035  en=i;
6036  else if (pGetComp(set[i].p)*cc == c)
6037  {
6038  int op = set[i].GetpFDeg()+set[i].ecart;
6039  if ((op > o)
6040  || ((op == o) && (set[i].ecart < p.ecart))
6041  || ((op == o) && (set[i].ecart == p.ecart)
6042  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
6043  en=i;
6044  else
6045  an=i;
6046  }
6047  else
6048  an=i;
6049  }
6050 }
6051 #endif
6052 
6053 /*2
6054 * looks up the position of p in set
6055 * set[0] is the smallest with respect to
6056 * ecart, pFDeg, length
6057 */
6058 int posInT19 (const TSet set,const int length,LObject &p)
6059 {
6060  p.GetpLength();
6061  if (length==-1) return 0;
6062 
6063  int o = p.ecart;
6064  int op=p.GetpFDeg();
6065 
6066  if (set[length].ecart < o)
6067  return length+1;
6068  if (set[length].ecart == o)
6069  {
6070  int oo=set[length].GetpFDeg();
6071  if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
6072  return length+1;
6073  }
6074 
6075  int i;
6076  int an = 0;
6077  int en= length;
6078  loop
6079  {
6080  if (an >= en-1)
6081  {
6082  if (set[an].ecart > o)
6083  return an;
6084  if (set[an].ecart == o)
6085  {
6086  int oo=set[an].GetpFDeg();
6087  if((oo > op)
6088  || ((oo==op) && (set[an].length > p.length)))
6089  return an;
6090  }
6091  return en;
6092  }
6093  i=(an+en) / 2;
6094  if (set[i].ecart > o)
6095  en=i;
6096  else if (set[i].ecart == o)
6097  {
6098  int oo=set[i].GetpFDeg();
6099  if ((oo > op)
6100  || ((oo == op) && (set[i].length > p.length)))
6101  en=i;
6102  else
6103  an=i;
6104  }
6105  else
6106  an=i;
6107  }
6108 }
6109 
6110 /*2
6111 *looks up the position of polynomial p in set
6112 *set[length] is the smallest element in set with respect
6113 *to the ordering-procedure pComp
6114 */
6115 int posInLSpecial (const LSet set, const int length,
6116  LObject *p,const kStrategy)
6117 {
6118  if (length<0) return 0;
6119 
6120  int d=p->GetpFDeg();
6121  int op=set[length].GetpFDeg();
6122 
6123  if ((op > d)
6124  || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
6125  || (pLmCmp(set[length].p,p->p)== currRing->OrdSgn))
6126  return length+1;
6127 
6128  int i;
6129  int an = 0;
6130  int en= length;
6131  loop
6132  {
6133  if (an >= en-1)
6134  {
6135  op=set[an].GetpFDeg();
6136  if ((op > d)
6137  || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
6138  || (pLmCmp(set[an].p,p->p)== currRing->OrdSgn))
6139  return en;
6140  return an;
6141  }
6142  i=(an+en) / 2;
6143  op=set[i].GetpFDeg();
6144  if ((op>d)
6145  || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
6146  || (pLmCmp(set[i].p,p->p) == currRing->OrdSgn))
6147  an=i;
6148  else
6149  en=i;
6150  }
6151 }
6152 
6153 /*2
6154 *looks up the position of polynomial p in set
6155 *set[length] is the smallest element in set with respect
6156 *to the ordering-procedure pComp
6157 */
6158 int posInL0 (const LSet set, const int length,
6159  LObject* p,const kStrategy)
6160 {
6161  if (length<0) return 0;
6162 
6163  if (pLmCmp(set[length].p,p->p)== currRing->OrdSgn)
6164  return length+1;
6165 
6166  int i;
6167  int an = 0;
6168  int en= length;
6169  loop
6170  {
6171  if (an >= en-1)
6172  {
6173  if (pLmCmp(set[an].p,p->p) == currRing->OrdSgn) return en;
6174  return an;
6175  }
6176  i=(an+en) / 2;
6177  if (pLmCmp(set[i].p,p->p) == currRing->OrdSgn) an=i;
6178  else en=i;
6179  /*aend. fuer lazy == in !=- machen */
6180  }
6181 }
6182 
6183 #ifdef HAVE_RINGS
6184 int posInL0Ring (const LSet set, const int length,
6185  LObject* p,const kStrategy)
6186 {
6187  if (length<0) return 0;
6188 
6189  if (pLtCmpOrdSgnEqP(set[length].p,p->p))
6190  return length+1;
6191 
6192  int i;
6193  int an = 0;
6194  int en= length;
6195  loop
6196  {
6197  if (an >= en-1)
6198  {
6199  if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
6200  return an;
6201  }
6202  i=(an+en) / 2;
6203  if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
6204  else en=i;
6205  /*aend. fuer lazy == in !=- machen */
6206  }
6207 }
6208 #endif
6209 
6210 /*2
6211 * looks up the position of polynomial p in set
6212 * e is the ecart of p
6213 * set[length] is the smallest element in set with respect
6214 * to the signature order
6215 */
6216 int posInLSig (const LSet set, const int length,
6217  LObject* p,const kStrategy /*strat*/)
6218 {
6219  if (length<0) return 0;
6220  if (pLtCmp(set[length].sig,p->sig)== currRing->OrdSgn)
6221  return length+1;
6222 
6223  int i;
6224  int an = 0;
6225  int en= length;
6226  loop
6227  {
6228  if (an >= en-1)
6229  {
6230  if (pLtCmp(set[an].sig,p->sig) == currRing->OrdSgn) return en;
6231  return an;
6232  }
6233  i=(an+en) / 2;
6234  if (pLtCmp(set[i].sig,p->sig) == currRing->OrdSgn) an=i;
6235  else en=i;
6236  /*aend. fuer lazy == in !=- machen */
6237  }
6238 }
6239 //sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
6240 int posInLSigRing (const LSet set, const int length,
6241  LObject* p,const kStrategy /*strat*/)
6242 {
6243  assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
6244  if (length<0) return 0;
6245  if (pLtCmp(set[length].sig,p->sig)== 1)
6246  return length+1;
6247 
6248  int an,en,i;
6249  an = 0;
6250  en = length+1;
6251  int cmp;
6252  loop
6253  {
6254  if (an >= en-1)
6255  {
6256  if(an == en)
6257  return en;
6258  cmp = pLtCmp(set[an].sig,p->sig);
6259  if (cmp == 1)
6260  return en;
6261  if (cmp == -1)
6262  return an;
6263  if (cmp == 0)
6264  {
6265  if (set[an].FDeg > p->FDeg)
6266  return en;
6267  if (set[an].FDeg < p->FDeg)
6268  return an;
6269  if (set[an].FDeg == p->FDeg)
6270  {
6271  cmp = pLtCmp(set[an].p,p->p);
6272  if(cmp == 1)
6273  return en;
6274  else
6275  return an;
6276  }
6277  }
6278  }
6279  i=(an+en) / 2;
6280  cmp = pLtCmp(set[i].sig,p->sig);
6281  if (cmp == 1)
6282  an = i;
6283  if (cmp == -1)
6284  en = i;
6285  if (cmp == 0)
6286  {
6287  if (set[i].FDeg > p->FDeg)
6288  an = i;
6289  if (set[i].FDeg < p->FDeg)
6290  en = i;
6291  if (set[i].FDeg == p->FDeg)
6292  {
6293  cmp = pLtCmp(set[i].p,p->p);
6294  if(cmp == 1)
6295  an = i;
6296  else
6297  en = i;
6298  }
6299  }
6300  }
6301 }
6302 
6303 int posInLRing (const LSet set, const int length,
6304  LObject* p,const kStrategy /*strat*/)
6305 {
6306  if (length < 0) return 0;
6307  if (set[length].FDeg > p->FDeg)
6308  return length+1;
6309  if (set[length].FDeg == p->FDeg)
6310  if(set[length].GetpLength() > p->GetpLength())
6311  return length+1;
6312  int i;
6313  int an = 0;
6314  int en= length+1;
6315  loop
6316  {
6317  if (an >= en-1)
6318  {
6319  if(an == en)
6320  return en;
6321  if (set[an].FDeg > p->FDeg)
6322  return en;
6323  if(set[an].FDeg == p->FDeg)
6324  {
6325  if(set[an].GetpLength() > p->GetpLength())
6326  return en;
6327  else
6328  {
6329  if(set[an].GetpLength() == p->GetpLength())
6330  {
6331  if(nGreater(set[an].p->coef, p->p->coef))
6332  return en;
6333  else
6334  return an;
6335  }
6336  else
6337  {
6338  return an;
6339  }
6340  }
6341  }
6342  else
6343  return an;
6344  }
6345  i=(an+en) / 2;
6346  if (set[i].FDeg > p->FDeg)
6347  an=i;
6348  else
6349  {
6350  if(set[i].FDeg == p->FDeg)
6351  {
6352  if(set[i].GetpLength() > p->GetpLength())
6353  an=i;
6354  else
6355  {
6356  if(set[i].GetpLength() == p->GetpLength())
6357  {
6358  if(nGreater(set[i].p->coef, p->p->coef))
6359  an = i;
6360  else
6361  en = i;
6362  }
6363  else
6364  {
6365  en=i;
6366  }
6367  }
6368  }
6369  else
6370  en=i;
6371  }
6372  }
6373 }
6374 
6375 // for sba, sorting syzygies
6376 int posInSyz (const kStrategy strat, poly sig)
6377 {
6378  if (strat->syzl==0) return 0;
6379  if (pLtCmp(strat->syz[strat->syzl-1],sig) != currRing->OrdSgn)
6380  return strat->syzl;
6381  int i;
6382  int an = 0;
6383  int en= strat->syzl-1;
6384  loop
6385  {
6386  if (an >= en-1)
6387  {
6388  if (pLtCmp(strat->syz[an],sig) != currRing->OrdSgn) return en;
6389  return an;
6390  }
6391  i=(an+en) / 2;
6392  if (pLtCmp(strat->syz[i],sig) != currRing->OrdSgn) an=i;
6393  else en=i;
6394  /*aend. fuer lazy == in !=- machen */
6395  }
6396 }
6397 
6398 /*2
6399 *
6400 * is only used in F5C, must ensure that the interreduction process does add new
6401 * critical pairs to strat->L only behind all other critical pairs which are
6402 * still in strat->L!
6403 */
6404 int posInLF5C (const LSet /*set*/, const int /*length*/,
6405  LObject* /*p*/,const kStrategy strat)
6406 {
6407  return strat->Ll+1;
6408 }
6409 
6410 /*2
6411 * looks up the position of polynomial p in set
6412 * e is the ecart of p
6413 * set[length] is the smallest element in set with respect
6414 * to the ordering-procedure totaldegree,pComp
6415 */
6416 int posInL11 (const LSet set, const int length,
6417  LObject* p,const kStrategy)
6418 {
6419  if (length<0) return 0;
6420 
6421  int o = p->GetpFDeg();
6422  int op = set[length].GetpFDeg();
6423 
6424  if ((op > o)
6425  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6426  return length+1;
6427  int i;
6428  int an = 0;
6429  int en= length;
6430  loop
6431  {
6432  if (an >= en-1)
6433  {
6434  op = set[an].GetpFDeg();
6435  if ((op > o)
6436  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6437  return en;
6438  return an;
6439  }
6440  i=(an+en) / 2;
6441  op = set[i].GetpFDeg();
6442  if ((op > o)
6443  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6444  an=i;
6445  else
6446  en=i;
6447  }
6448 }
6449 
6450 #ifdef HAVE_RINGS
6451 /*2
6452 * looks up the position of polynomial p in set
6453 * set[length] is the smallest element in set with respect
6454 * to the ordering-procedure pLmCmp,totaldegree,coefficient
6455 * For the same totaldegree, original pairs (from F) will
6456 * be put at the end and smalles coefficents
6457 */
6458 int posInL11Ring (const LSet set, const int length,
6459  LObject* p,const kStrategy)
6460 {
6461  if (length<0) return 0;
6462 
6463  int o = p->GetpFDeg();
6464  int op = set[length].GetpFDeg();
6465 
6466  if ((op > o)
6467  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6468  return length+1;
6469  int i;
6470  int an = 0;
6471  int en= length;
6472  loop
6473  {
6474  if (an >= en-1)
6475  {
6476  op = set[an].GetpFDeg();
6477  if ((op > o)
6478  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6479  return en;
6480  return an;
6481  }
6482  i=(an+en) / 2;
6483  op = set[i].GetpFDeg();
6484  if ((op > o)
6485  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6486  an=i;
6487  else
6488  en=i;
6489  }
6490 }
6491 
6492 int posInLF5CRing (const LSet set, int start,const int length,
6493  LObject* p,const kStrategy)
6494 {
6495  if (length<0) return 0;
6496  if(start == (length +1)) return (length+1);
6497  int o = p->GetpFDeg();
6498  int op = set[length].GetpFDeg();
6499 
6500  if ((op > o)
6501  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6502  return length+1;
6503  int i;
6504  int an = start;
6505  int en= length;
6506  loop
6507  {
6508  if (an >= en-1)
6509  {
6510  op = set[an].GetpFDeg();
6511  if ((op > o)
6512  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6513  return en;
6514  return an;
6515  }
6516  i=(an+en) / 2;
6517  op = set[i].GetpFDeg();
6518  if ((op > o)
6519  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6520  an=i;
6521  else
6522  en=i;
6523  }
6524 }
6525 #endif
6526 
6527 #ifdef HAVE_RINGS
6528 int posInL11Ringls (const LSet set, const int length,
6529  LObject* p,const kStrategy)
6530 {
6531  if (length < 0) return 0;
6532  int an,en,i;
6533  an = 0;
6534  en = length+1;
6535  loop
6536  {
6537  if (an >= en-1)
6538  {
6539  if(an == en)
6540  return en;
6541  if (set[an].FDeg > p->FDeg)
6542  return en;
6543  if (set[an].FDeg < p->FDeg)
6544  return an;
6545  if (set[an].FDeg == p->FDeg)
6546  {
6547  number lcset,lcp;
6548  lcset = pGetCoeff(set[an].p);
6549  lcp = pGetCoeff(p->p);
6550  if(!nGreaterZero(lcset))
6551  {
6552  set[an].p=p_Neg(set[an].p,currRing);
6553  if (set[an].t_p!=NULL)
6554  pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
6555  lcset=pGetCoeff(set[an].p);
6556  }
6557  if(!nGreaterZero(lcp))
6558  {
6559  p->p=p_Neg(p->p,currRing);
6560  if (p->t_p!=NULL)
6561  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6562  lcp=pGetCoeff(p->p);
6563  }
6564  if(nGreater(lcset, lcp))
6565  {
6566  return en;
6567  }
6568  else
6569  {
6570  return an;
6571  }
6572  }
6573  }
6574  i=(an+en) / 2;
6575  if (set[i].FDeg > p->FDeg)
6576  an=i;
6577  if (set[i].FDeg < p->FDeg)
6578  en=i;
6579  if (set[i].FDeg == p->FDeg)
6580  {
6581  number lcset,lcp;
6582  lcset = pGetCoeff(set[i].p);
6583  lcp = pGetCoeff(p->p);
6584  if(!nGreaterZero(lcset))
6585  {
6586  set[i].p=p_Neg(set[i].p,currRing);
6587  if (set[i].t_p!=NULL)
6588  pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6589  lcset=pGetCoeff(set[i].p);
6590  }
6591  if(!nGreaterZero(lcp))
6592  {
6593  p->p=p_Neg(p->p,currRing);
6594  if (p->t_p!=NULL)
6595  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6596  lcp=pGetCoeff(p->p);
6597  }
6598  if(nGreater(lcset, lcp))
6599  {
6600  an = i;
6601  }
6602  else
6603  {
6604  en = i;
6605  }
6606  }
6607  }
6608 }
6609 #endif
6610 
6611 /*2 Position for rings L: Here I am
6612 * looks up the position of polynomial p in set
6613 * e is the ecart of p
6614 * set[length] is the smallest element in set with respect
6615 * to the ordering-procedure totaldegree,pComp
6616 */
6617 inline int getIndexRng(long coeff)
6618 {
6619  if (coeff == 0) return -1;
6620  long tmp = coeff;
6621  int ind = 0;
6622  while (tmp % 2 == 0)
6623  {
6624  tmp = tmp / 2;
6625  ind++;
6626  }
6627  return ind;
6628 }
6629 
6630 int posInLrg0 (const LSet set, const int length,
6631  LObject* p,const kStrategy)
6632 /* if (nGreater(pGetCoeff(p), pGetCoeff(set[an]))) return en;
6633  if (pLmCmp(set[i],p) == cmp_int) en = i;
6634  else if (pLmCmp(set[i],p) == -cmp_int) an = i;
6635  else
6636  {
6637  if (nGreater(pGetCoeff(p), pGetCoeff(set[i]))) an = i;
6638  else en = i;
6639  }*/
6640 {
6641  if (length < 0) return 0;
6642 
6643  int o = p->GetpFDeg();
6644  int op = set[length].GetpFDeg();
6645 
6646  if ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6647  return length + 1;
6648  int i;
6649  int an = 0;
6650  int en = length;
6651  loop
6652  {
6653  if (an >= en - 1)
6654  {
6655  op = set[an].GetpFDeg();
6656  if ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6657  return en;
6658  return an;
6659  }
6660  i = (an+en) / 2;
6661  op = set[i].GetpFDeg();
6662  if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6663  an = i;
6664  else
6665  en = i;
6666  }
6667 }
6668 
6669 /*{
6670  if (length < 0) return 0;
6671 
6672  int o = p->GetpFDeg();
6673  int op = set[length].GetpFDeg();
6674 
6675  int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6676  int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6677  int inda;
6678  int indi;
6679 
6680  if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6681  return length + 1;
6682  int i;
6683  int an = 0;
6684  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6685  int en = length;
6686  loop
6687  {
6688  if (an >= en-1)
6689  {
6690  op = set[an].GetpFDeg();
6691  if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6692  return en;
6693  return an;
6694  }
6695  i = (an + en) / 2;
6696  indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6697  op = set[i].GetpFDeg();
6698  if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6699  // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6700  {
6701  an = i;
6702  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6703  }
6704  else
6705  en = i;
6706  }
6707 } */
6708 
6709 /*2
6710 * looks up the position of polynomial p in set
6711 * set[length] is the smallest element in set with respect
6712 * to the ordering-procedure totaldegree,pLength0
6713 */
6714 int posInL110 (const LSet set, const int length,
6715  LObject* p,const kStrategy)
6716 {
6717  if (length<0) return 0;
6718 
6719  int o = p->GetpFDeg();
6720  int op = set[length].GetpFDeg();
6721 
6722  if ((op > o)
6723  || ((op == o) && (set[length].length >p->length))
6724  || ((op == o) && (set[length].length <= p->length)
6725  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6726  return length+1;
6727  int i;
6728  int an = 0;
6729  int en= length;
6730  loop
6731  {
6732  if (an >= en-1)
6733  {
6734  op = set[an].GetpFDeg();
6735  if ((op > o)
6736  || ((op == o) && (set[an].length >p->length))
6737  || ((op == o) && (set[an].length <=p->length)
6738  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6739  return en;
6740  return an;
6741  }
6742  i=(an+en) / 2;
6743  op = set[i].GetpFDeg();
6744  if ((op > o)
6745  || ((op == o) && (set[i].length > p->length))
6746  || ((op == o) && (set[i].length <= p->length)
6747  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6748  an=i;
6749  else
6750  en=i;
6751  }
6752 }
6753 
6754 #ifdef HAVE_RINGS
6755 int posInL110Ring (const LSet set, const int length,
6756  LObject* p,const kStrategy)
6757 {
6758  if (length<0) return 0;
6759 
6760  int o = p->GetpFDeg();
6761  int op = set[length].GetpFDeg();
6762 
6763  if ((op > o)
6764  || ((op == o) && (set[length].length >p->length))
6765  || ((op == o) && (set[length].length <= p->length)
6766  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6767  return length+1;
6768  int i;
6769  int an = 0;
6770  int en= length;
6771  loop
6772  {
6773  if (an >= en-1)
6774  {
6775  op = set[an].GetpFDeg();
6776  if ((op > o)
6777  || ((op == o) && (set[an].length >p->length))
6778  || ((op == o) && (set[an].length <=p->length)
6779  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6780  return en;
6781  return an;
6782  }
6783  i=(an+en) / 2;
6784  op = set[i].GetpFDeg();
6785  if ((op > o)
6786  || ((op == o) && (set[i].length > p->length))
6787  || ((op == o) && (set[i].length <= p->length)
6788  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6789  an=i;
6790  else
6791  en=i;
6792  }
6793 }
6794 #endif
6795 
6796 /*2
6797 * looks up the position of polynomial p in set
6798 * e is the ecart of p
6799 * set[length] is the smallest element in set with respect
6800 * to the ordering-procedure totaldegree
6801 */
6802 int posInL13 (const LSet set, const int length,
6803  LObject* p,const kStrategy)
6804 {
6805  if (length<0) return 0;
6806 
6807  int o = p->GetpFDeg();
6808 
6809  if (set[length].GetpFDeg() > o)
6810  return length+1;
6811 
6812  int i;
6813  int an = 0;
6814  int en= length;
6815  loop
6816  {
6817  if (an >= en-1)
6818  {
6819  if (set[an].GetpFDeg() >= o)
6820  return en;
6821  return an;
6822  }
6823  i=(an+en) / 2;
6824  if (set[i].GetpFDeg() >= o)
6825  an=i;
6826  else
6827  en=i;
6828  }
6829 }
6830 
6831 /*2
6832 * looks up the position of polynomial p in set
6833 * e is the ecart of p
6834 * set[length] is the smallest element in set with respect
6835 * to the ordering-procedure maximaldegree,pComp
6836 */
6837 int posInL15 (const LSet set, const int length,
6838  LObject* p,const kStrategy)
6839 {
6840  if (length<0) return 0;
6841 
6842  int o = p->GetpFDeg() + p->ecart;
6843  int op = set[length].GetpFDeg() + set[length].ecart;
6844 
6845  if ((op > o)
6846  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6847  return length+1;
6848  int i;
6849  int an = 0;
6850  int en= length;
6851  loop
6852  {
6853  if (an >= en-1)
6854  {
6855  op = set[an].GetpFDeg() + set[an].ecart;
6856  if ((op > o)
6857  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6858  return en;
6859  return an;
6860  }
6861  i=(an+en) / 2;
6862  op = set[i].GetpFDeg() + set[i].ecart;
6863  if ((op > o)
6864  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6865  an=i;
6866  else
6867  en=i;
6868  }
6869 }
6870 
6871 #ifdef HAVE_RINGS
6872 int posInL15Ring (const LSet set, const int length,
6873  LObject* p,const kStrategy)
6874 {
6875  if (length<0) return 0;
6876 
6877  int o = p->GetpFDeg() + p->ecart;
6878  int op = set[length].GetpFDeg() + set[length].ecart;
6879 
6880  if ((op > o)
6881  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6882  return length+1;
6883  int i;
6884  int an = 0;
6885  int en= length;
6886  loop
6887  {
6888  if (an >= en-1)
6889  {
6890  op = set[an].GetpFDeg() + set[an].ecart;
6891  if ((op > o)
6892  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6893  return en;
6894  return an;
6895  }
6896  i=(an+en) / 2;
6897  op = set[i].GetpFDeg() + set[i].ecart;
6898  if ((op > o)
6899  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6900  an=i;
6901  else
6902  en=i;
6903  }
6904 }
6905 #endif
6906 
6907 /*2
6908 * looks up the position of polynomial p in set
6909 * e is the ecart of p
6910 * set[length] is the smallest element in set with respect
6911 * to the ordering-procedure totaldegree
6912 */
6913 int posInL17 (const LSet set, const int length,
6914  LObject* p,const kStrategy)
6915 {
6916  if (length<0) return 0;
6917 
6918  int o = p->GetpFDeg() + p->ecart;
6919 
6920  if ((set[length].GetpFDeg() + set[length].ecart > o)
6921  || ((set[length].GetpFDeg() + set[length].ecart == o)
6922  && (set[length].ecart > p->ecart))
6923  || ((set[length].GetpFDeg() + set[length].ecart == o)
6924  && (set[length].ecart == p->ecart)
6925  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6926  return length+1;
6927  int i;
6928  int an = 0;
6929  int en= length;
6930  loop
6931  {
6932  if (an >= en-1)
6933  {
6934  if ((set[an].GetpFDeg() + set[an].ecart > o)
6935  || ((set[an].GetpFDeg() + set[an].ecart == o)
6936  && (set[an].ecart > p->ecart))
6937  || ((set[an].GetpFDeg() + set[an].ecart == o)
6938  && (set[an].ecart == p->ecart)
6939  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6940  return en;
6941  return an;
6942  }
6943  i=(an+en) / 2;
6944  if ((set[i].GetpFDeg() + set[i].ecart > o)
6945  || ((set[i].GetpFDeg() + set[i].ecart == o)
6946  && (set[i].ecart > p->ecart))
6947  || ((set[i].GetpFDeg() +set[i].ecart == o)
6948  && (set[i].ecart == p->ecart)
6949  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6950  an=i;
6951  else
6952  en=i;
6953  }
6954 }
6955 
6956 #ifdef HAVE_RINGS
6957 int posInL17Ring (const LSet set, const int length,
6958  LObject* p,const kStrategy)
6959 {
6960  if (length<0) return 0;
6961 
6962  int o = p->GetpFDeg() + p->ecart;
6963 
6964  if ((set[length].GetpFDeg() + set[length].ecart > o)
6965  || ((set[length].GetpFDeg() + set[length].ecart == o)
6966  && (set[length].ecart > p->ecart))
6967  || ((set[length].GetpFDeg() + set[length].ecart == o)
6968  && (set[length].ecart == p->ecart)
6969  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6970  return length+1;
6971  int i;
6972  int an = 0;
6973  int en= length;
6974  loop
6975  {
6976  if (an >= en-1)
6977  {
6978  if ((set[an].GetpFDeg() + set[an].ecart > o)
6979  || ((set[an].GetpFDeg() + set[an].ecart == o)
6980  && (set[an].ecart > p->ecart))
6981  || ((set[an].GetpFDeg() + set[an].ecart == o)
6982  && (set[an].ecart == p->ecart)
6983  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6984  return en;
6985  return an;
6986  }
6987  i=(an+en) / 2;
6988  if ((set[i].GetpFDeg() + set[i].ecart > o)
6989  || ((set[i].GetpFDeg() + set[i].ecart == o)
6990  && (set[i].ecart > p->ecart))
6991  || ((set[i].GetpFDeg() +set[i].ecart == o)
6992  && (set[i].ecart == p->ecart)
6993  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6994  an=i;
6995  else
6996  en=i;
6997  }
6998 }
6999 #endif
7000 
7001 /*2
7002 * looks up the position of polynomial p in set
7003 * e is the ecart of p
7004 * set[length] is the smallest element in set with respect
7005 * to the ordering-procedure pComp
7006 */
7007 int posInL17_c (const LSet set, const int length,
7008  LObject* p,const kStrategy)
7009 {
7010  if (length<0) return 0;
7011 
7012  int cc = (-1+2*currRing->order[0]==ringorder_c);
7013  /* cc==1 for (c,..), cc==-1 for (C,..) */
7014  unsigned long c = pGetComp(p->p)*cc;
7015  int o = p->GetpFDeg() + p->ecart;
7016 
7017  if (pGetComp(set[length].p)*cc > c)
7018  return length+1;
7019  if (pGetComp(set[length].p)*cc == c)
7020  {
7021  if ((set[length].GetpFDeg() + set[length].ecart > o)
7022  || ((set[length].GetpFDeg() + set[length].ecart == o)
7023  && (set[length].ecart > p->ecart))
7024  || ((set[length].GetpFDeg() + set[length].ecart == o)
7025  && (set[length].ecart == p->ecart)
7026  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
7027  return length+1;
7028  }
7029  int i;
7030  int an = 0;
7031  int en= length;
7032  loop
7033  {
7034  if (an >= en-1)
7035  {
7036  if (pGetComp(set[an].p)*cc > c)
7037  return en;
7038  if (pGetComp(set[an].p)*cc == c)
7039  {
7040  if ((set[an].GetpFDeg() + set[an].ecart > o)
7041  || ((set[an].GetpFDeg() + set[an].ecart == o)
7042  && (set[an].ecart > p->ecart))
7043  || ((set[an].GetpFDeg() + set[an].ecart == o)
7044  && (set[an].ecart == p->ecart)
7045  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
7046  return en;
7047  }
7048  return an;
7049  }
7050  i=(an+en) / 2;
7051  if (pGetComp(set[i].p)*cc > c)
7052  an=i;
7053  else if (pGetComp(set[i].p)*cc == c)
7054  {
7055  if ((set[i].GetpFDeg() + set[i].ecart > o)
7056  || ((set[i].GetpFDeg() + set[i].ecart == o)
7057  && (set[i].ecart > p->ecart))
7058  || ((set[i].GetpFDeg() +set[i].ecart == o)
7059  && (set[i].ecart == p->ecart)
7060  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
7061  an=i;
7062  else
7063  en=i;
7064  }
7065  else
7066  en=i;
7067  }
7068 }
7069 
7070 #ifdef HAVE_RINGS
7071 int posInL17_cRing (const LSet set, const int length,
7072  LObject* p,const kStrategy)
7073 {
7074  if (length<0) return 0;
7075 
7076  int cc = (-1+2*currRing->order[0]==ringorder_c);
7077  /* cc==1 for (c,..), cc==-1 for (C,..) */
7078  unsigned long c = pGetComp(p->p)*cc;
7079  int o = p->GetpFDeg() + p->ecart;
7080 
7081  if (pGetComp(set[length].p)*cc > c)
7082  return length+1;
7083  if (pGetComp(set[length].p)*cc == c)
7084  {
7085  if ((set[length].GetpFDeg() + set[length].ecart > o)
7086  || ((set[length].GetpFDeg() + set[length].ecart == o)
7087  && (set[length].ecart > p->ecart))
7088  || ((set[length].GetpFDeg() + set[length].ecart == o)
7089  && (set[length].ecart == p->ecart)
7090  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
7091  return length+1;
7092  }
7093  int i;
7094  int an = 0;
7095  int en= length;
7096  loop
7097  {
7098  if (an >= en-1)
7099  {
7100  if (pGetComp(set[an].p)*cc > c)
7101  return en;
7102  if (pGetComp(set[an].p)*cc == c)
7103  {
7104  if ((set[an].GetpFDeg() + set[an].ecart > o)
7105  || ((set[an].GetpFDeg() + set[an].ecart == o)
7106  && (set[an].ecart > p->ecart))
7107  || ((set[an].GetpFDeg() + set[an].ecart == o)
7108  && (set[an].ecart == p->ecart)
7109  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
7110  return en;
7111  }
7112  return an;
7113  }
7114  i=(an+en) / 2;
7115  if (pGetComp(set[i].p)*cc > c)
7116  an=i;
7117  else if (pGetComp(set[i].p)*cc == c)
7118  {
7119  if ((set[i].GetpFDeg() + set[i].ecart > o)
7120  || ((set[i].GetpFDeg() + set[i].ecart == o)
7121  && (set[i].ecart > p->ecart))
7122  || ((set[i].GetpFDeg() +set[i].ecart == o)
7123  && (set[i].ecart == p->ecart)
7124  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
7125  an=i;
7126  else
7127  en=i;
7128  }
7129  else
7130  en=i;
7131  }
7132 }
7133 #endif
7134 
7135 /*
7136  * SYZYGY CRITERION for signature-based standard basis algorithms
7137  */
7138 BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
7139 {
7140 //#if 1
7141 #ifdef DEBUGF5
7142  PrintS("syzygy criterion checks: ");
7143  pWrite(sig);
7144 #endif
7145  for (int k=0; k<strat->syzl; k++)
7146  {
7147  //printf("-%d",k);
7148 //#if 1
7149 #ifdef DEBUGF5
7150  Print("checking with: %d / %d -- \n",k,strat->syzl);
7151  pWrite(pHead(strat->syz[k]));
7152 #endif
7153  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7154  && (!rField_is_Ring(currRing) ||
7155  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7156  {
7157 //#if 1
7158 #ifdef DEBUGF5
7159  PrintS("DELETE!\n");
7160 #endif
7161  #ifdef ADIDEBUG
7162  printf("\nsyzCrit:\n");pWrite(strat->syz[k]);pWrite(sig);
7163  #endif
7164  strat->nrsyzcrit++;
7165  //printf("- T -\n\n");
7166  return TRUE;
7167  }
7168  }
7169  //printf("- F -\n\n");
7170  return FALSE;
7171 }
7172 
7173 /*
7174  * SYZYGY CRITERION for signature-based standard basis algorithms
7175  */
7176 BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
7177 {
7178 //#if 1
7179  if(sig == NULL)
7180  return FALSE;
7181 #ifdef DEBUGF5
7182  PrintS("--- syzygy criterion checks: ");
7183  pWrite(sig);
7184 #endif
7185  int comp = p_GetComp(sig, currRing);
7186  int min, max;
7187  if (comp<=1)
7188  return FALSE;
7189  else
7190  {
7191  min = strat->syzIdx[comp-2];
7192  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
7193  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
7194  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
7195  if (comp == strat->currIdx)
7196  {
7197  max = strat->syzl;
7198  }
7199  else
7200  {
7201  max = strat->syzIdx[comp-1];
7202  }
7203  for (int k=min; k<max; k++)
7204  {
7205 #ifdef F5DEBUG
7206  Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
7207  Print("checking with: %d -- ",k);
7208  pWrite(pHead(strat->syz[k]));
7209 #endif
7210  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7211  && (!rField_is_Ring(currRing) ||
7212  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7213  {
7214  #ifdef ADIDEBUG
7215  printf("\nsyzCrit:\n");pWrite(strat->syz[k]);pWrite(sig);
7216  #endif
7217  strat->nrsyzcrit++;
7218  return TRUE;
7219  }
7220  }
7221  return FALSE;
7222  }
7223 }
7224 
7225 /*
7226  * REWRITTEN CRITERION for signature-based standard basis algorithms
7227  */
7228 BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
7229 {
7230  //printf("Faugere Rewritten Criterion\n");
7232  return FALSE;
7233 //#if 1
7234 #ifdef DEBUGF5
7235  PrintS("rewritten criterion checks: ");
7236  pWrite(sig);
7237 #endif
7238  for(int k = strat->sl; k>=start; k--)
7239  {
7240 //#if 1
7241 #ifdef DEBUGF5
7242  PrintS("checking with: ");
7243  pWrite(strat->sig[k]);
7244  pWrite(pHead(strat->S[k]));
7245 #endif
7246  if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
7247  {
7248 //#if 1
7249 #ifdef DEBUGF5
7250  PrintS("DELETE!\n");
7251 #endif
7252  #ifdef ADIDEBUG
7253  printf("\nFaugere RewCrit: * divisible by *\n");pWrite(sig);pWrite(strat->sig[k]);
7254  #endif
7255  strat->nrrewcrit++;
7256  return TRUE;
7257  }
7258  //k--;
7259  }
7260 #ifdef DEBUGF5
7261  PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
7262  for(int kk = 0; kk<strat->sl+1; kk++)
7263  {
7264  pWrite(pHead(strat->S[kk]));
7265  }
7266  PrintS("------------------------------\n");
7267 #endif
7268  return FALSE;
7269 }
7270 
7271 /*
7272  * REWRITTEN CRITERION for signature-based standard basis algorithms
7273  ***************************************************************************
7274  * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
7275  ***************************************************************************
7276  */
7277 
7278 // real implementation of arri's rewritten criterion, only called once in
7279 // kstd2.cc, right before starting reduction
7280 // IDEA: Arri says that it is enough to consider 1 polynomial for each unique
7281 // signature appearing during the computations. Thus we first of all go
7282 // through strat->L and delete all other pairs of the same signature,
7283 // keeping only the one with least possible leading monomial. After this
7284 // we check if we really need to compute this critical pair at all: There
7285 // can be elements already in strat->S whose signatures divide the
7286 // signature of the critical pair in question and whose multiplied
7287 // leading monomials are smaller than the leading monomial of the
7288 // critical pair. In this situation we can discard the critical pair
7289 // completely.
7290 BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
7291 {
7292  #ifdef ADIDEBUG
7293  printf("\narriRewCrit\n");
7294  #endif
7296  return FALSE;
7297  poly p1 = pOne();
7298  poly p2 = pOne();
7299  for (int ii=strat->sl; ii>start; ii--)
7300  {
7301  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
7302  {
7303  p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
7304  p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
7305  if (!(pLmCmp(p1,p2) == 1))
7306  {
7307  #ifdef ADIDEBUG
7308  printf("\narriRewCrit deleted: sig, P.sig\n");
7309  #endif
7310  pDelete(&p1);
7311  pDelete(&p2);
7312  return TRUE;
7313  }
7314  }
7315  }
7316  pDelete(&p1);
7317  pDelete(&p2);
7318  return FALSE;
7319 }
7320 
7321 BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
7322 {
7323  #ifdef ADIDEBUG
7324  printf("\narriRewCritPre\n");
7325  #endif
7326  //Over Rings, there are still some changes to do: considering coeffs
7328  return FALSE;
7329  int found = -1;
7330  for (int i=strat->Bl; i>-1; i--) {
7331  if (pLmEqual(strat->B[i].sig,sig))
7332  {
7333  found = i;
7334  break;
7335  }
7336  }
7337  if (found != -1)
7338  {
7339  if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
7340  {
7341  deleteInL(strat->B,&strat->Bl,found,strat);
7342  #ifdef ADIDEBUG
7343  printf("\nDelete!\n");
7344  #endif
7345  }
7346  else
7347  {
7348  #ifdef ADIDEBUG
7349  printf("\nDelete this one!\n");
7350  #endif
7351  return TRUE;
7352  }
7353  }
7354  poly p1 = pOne();
7355  poly p2 = pOne();
7356  for (int ii=strat->sl; ii>-1; ii--)
7357  {
7358  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
7359  {
7360  p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
7361  p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
7362  if (!(pLmCmp(p1,p2) == 1))
7363  {
7364  pDelete(&p1);
7365  pDelete(&p2);
7366  #ifdef ADIDEBUG
7367  printf("\nDelete this one!\n");
7368  #endif
7369  return TRUE;
7370  }
7371  }
7372  }
7373  pDelete(&p1);
7374  pDelete(&p2);
7375  return FALSE;
7376 }
7377 
7378 /***************************************************************
7379  *
7380  * Tail reductions
7381  *
7382  ***************************************************************/
7383 TObject*
7385  long ecart)
7386 {
7387  int j = 0;
7388  const unsigned long not_sev = ~L->sev;
7389  const unsigned long* sev = strat->sevS;
7390  poly p;
7391  ring r;
7392  L->GetLm(p, r);
7393 
7394  assume(~not_sev == p_GetShortExpVector(p, r));
7395 
7396  if (r == currRing)
7397  {
7398  if(!rField_is_Ring(r))
7399  {
7400  loop
7401  {
7402  if (j > pos) return NULL;
7403  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7404  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7405  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7406  {
7407  break;
7408  }
7409  #else
7410  if (!(sev[j] & not_sev) &&
7411  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7412  p_LmDivisibleBy(strat->S[j], p, r))
7413  {
7414  break;
7415  }
7416  #endif
7417  j++;
7418  }
7419  }
7420  #ifdef HAVE_RINGS
7421  else
7422  {
7423  loop
7424  {
7425  if (j > pos) return NULL;
7426  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7427  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7428  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7429  {
7430  break;
7431  }
7432  #else
7433  if (!(sev[j] & not_sev) &&
7434  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7435  p_LmDivisibleBy(strat->S[j], p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7436  {
7437  break;
7438  }
7439  #endif
7440  j++;
7441  }
7442  }
7443  #endif
7444  // if called from NF, T objects do not exist:
7445  if (strat->tl < 0 || strat->S_2_R[j] == -1)
7446  {
7447  T->Set(strat->S[j], r, strat->tailRing);
7448  return T;
7449  }
7450  else
7451  {
7452 ///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
7453 ///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
7454 // assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
7455  return strat->S_2_T(j);
7456  }
7457  }
7458  else
7459  {
7460  TObject* t;
7461  if(!rField_is_Ring(r))
7462  {
7463  loop
7464  {
7465  if (j > pos) return NULL;
7466  assume(strat->S_2_R[j] != -1);
7467  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7468  t = strat->S_2_T(j);
7469  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7470  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7471  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7472  {
7473  return t;
7474  }
7475  #else
7476  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7477  {
7478  t = strat->S_2_T(j);
7479  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7480  if (p_LmDivisibleBy(t->t_p, p, r))
7481  {
7482  return t;
7483  }
7484  }
7485  #endif
7486  j++;
7487  }
7488  }
7489  #ifdef HAVE_RINGS
7490  else
7491  {
7492  loop
7493  {
7494  if (j > pos) return NULL;
7495  assume(strat->S_2_R[j] != -1);
7496  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7497  t = strat->S_2_T(j);
7498  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7499  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7500  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7501  {
7502  return t;
7503  }
7504  #else
7505  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7506  {
7507  t = strat->S_2_T(j);
7508  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7509  if (p_LmDivisibleBy(t->t_p, p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7510  {
7511  return t;
7512  }
7513  }
7514  #endif
7515  j++;
7516  }
7517  }
7518  #endif
7519  }
7520 }
7521 
7522 poly redtail (LObject* L, int pos, kStrategy strat)
7523 {
7524  poly h, hn;
7525  strat->redTailChange=FALSE;
7526 
7527  L->GetP();
7528  poly p = L->p;
7529  if (strat->noTailReduction || pNext(p) == NULL)
7530  return p;
7531 
7532  LObject Ln(strat->tailRing);
7533  TObject* With;
7534  // placeholder in case strat->tl < 0
7535  TObject With_s(strat->tailRing);
7536  h = p;
7537  hn = pNext(h);
7538  long op = strat->tailRing->pFDeg(hn, strat->tailRing);
7539  long e;
7540  int l;
7541  BOOLEAN save_HE=strat->kHEdgeFound;
7542  strat->kHEdgeFound |=
7543  ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
7544 
7545  while(hn != NULL)
7546  {
7547  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7548  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7549  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7550  loop
7551  {
7552  Ln.Set(hn, strat->tailRing);
7553  Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
7554  if (strat->kHEdgeFound)
7555  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
7556  else
7557  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s, e);
7558  if (With == NULL) break;
7559  With->length=0;
7560  With->pLength=0;
7561  strat->redTailChange=TRUE;
7562  if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
7563  {
7564  // reducing the tail would violate the exp bound
7565  if (kStratChangeTailRing(strat, L))
7566  {
7567  strat->kHEdgeFound = save_HE;
7568  return redtail(L, pos, strat);
7569  }
7570  else
7571  return NULL;
7572  }
7573  hn = pNext(h);
7574  if (hn == NULL) goto all_done;
7575  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7576  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7577  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7578  }
7579  h = hn;
7580  hn = pNext(h);
7581  }
7582 
7583  all_done:
7584  if (strat->redTailChange)
7585  {
7586  L->pLength = 0;
7587  }
7588  strat->kHEdgeFound = save_HE;
7589  return p;
7590 }
7591 
7592 poly redtail (poly p, int pos, kStrategy strat)
7593 {
7594  LObject L(p, currRing);
7595  return redtail(&L, pos, strat);
7596 }
7597 
7599 {
7600 #define REDTAIL_CANONICALIZE 100
7601  strat->redTailChange=FALSE;
7602  if (strat->noTailReduction) return L->GetLmCurrRing();
7603  poly h, p;
7604  p = h = L->GetLmTailRing();
7605  if ((h==NULL) || (pNext(h)==NULL))
7606  return L->GetLmCurrRing();
7607 
7608  TObject* With;
7609  // placeholder in case strat->tl < 0
7610  TObject With_s(strat->tailRing);
7611 
7612  LObject Ln(pNext(h), strat->tailRing);
7613  Ln.pLength = L->GetpLength() - 1;
7614 
7615  pNext(h) = NULL;
7616  if (L->p != NULL) pNext(L->p) = NULL;
7617  L->pLength = 1;
7618 
7619  Ln.PrepareRed(strat->use_buckets);
7620 
7621  int cnt=REDTAIL_CANONICALIZE;
7622  while(!Ln.IsNull())
7623  {
7624  loop
7625  {
7626  if (TEST_OPT_IDLIFT)
7627  {
7628  if (Ln.p!=NULL)
7629  {
7630  if (p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7631  }
7632  else
7633  {
7634  if (p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7635  }
7636  }
7637  Ln.SetShortExpVector();
7638  if (withT)
7639  {
7640  int j;
7641  j = kFindDivisibleByInT(strat, &Ln);
7642  if (j < 0) break;
7643  With = &(strat->T[j]);
7644  }
7645  else
7646  {
7647  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
7648  if (With == NULL) break;
7649  }
7650  cnt--;
7651  if (cnt==0)
7652  {
7654  /*poly tmp=*/Ln.CanonicalizeP();
7655  if (normalize)
7656  {
7657  Ln.Normalize();
7658  //pNormalize(tmp);
7659  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7660  }
7661  }
7662  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7663  {
7664  With->pNorm();
7665  }
7666  strat->redTailChange=TRUE;
7667  if (ksReducePolyTail(L, With, &Ln))
7668  {
7669  // reducing the tail would violate the exp bound
7670  // set a flag and hope for a retry (in bba)
7671  strat->completeReduce_retry=TRUE;
7672  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7673  do
7674  {
7675  pNext(h) = Ln.LmExtractAndIter();
7676  pIter(h);
7677  L->pLength++;
7678  } while (!Ln.IsNull());
7679  goto all_done;
7680  }
7681  if (Ln.IsNull()) goto all_done;
7682  if (! withT) With_s.Init(currRing);
7683  }
7684  pNext(h) = Ln.LmExtractAndIter();
7685  pIter(h);
7686  pNormalize(h);
7687  L->pLength++;
7688  }
7689 
7690  all_done:
7691  Ln.Delete();
7692  if (L->p != NULL) pNext(L->p) = pNext(p);
7693 
7694  if (strat->redTailChange)
7695  {
7696  L->length = 0;
7697  L->pLength = 0;
7698  }
7699 
7700  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7701  //L->Normalize(); // HANNES: should have a test
7702  kTest_L(L);
7703  return L->GetLmCurrRing();
7704 }
7705 
7707 {
7708 #define REDTAIL_CANONICALIZE 100
7709  strat->redTailChange=FALSE;
7710  if (strat->noTailReduction) return L->GetLmCurrRing();
7711  poly h, p;
7712  p = h = L->GetLmTailRing();
7713  if ((h==NULL) || (pNext(h)==NULL))
7714  return L->GetLmCurrRing();
7715 
7716  TObject* With;
7717  // placeholder in case strat->tl < 0
7718  TObject With_s(strat->tailRing);
7719 
7720  LObject Ln(pNext(h), strat->tailRing);
7721  Ln.pLength = L->GetpLength() - 1;
7722 
7723  pNext(h) = NULL;
7724  if (L->p != NULL) pNext(L->p) = NULL;
7725  L->pLength = 1;
7726 
7727  Ln.PrepareRed(strat->use_buckets);
7728 
7729  int cnt=REDTAIL_CANONICALIZE;
7730  while(!Ln.IsNull())
7731  {
7732  loop
7733  {
7734  if (TEST_OPT_IDLIFT)
7735  {
7736  if (Ln.p!=NULL)
7737  {
7738  if (p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7739  }
7740  else
7741  {
7742  if (p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7743  }
7744  }
7745  Ln.SetShortExpVector();
7746  if (withT)
7747  {
7748  int j;
7749  j = kFindDivisibleByInT(strat, &Ln);
7750  if (j < 0) break;
7751  With = &(strat->T[j]);
7752  }
7753  else
7754  {
7755  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
7756  if (With == NULL) break;
7757  }
7758  cnt--;
7759  if (cnt==0)
7760  {
7762  /*poly tmp=*/Ln.CanonicalizeP();
7763  if (normalize)
7764  {
7765  Ln.Normalize();
7766  //pNormalize(tmp);
7767  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7768  }
7769  }
7770  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7771  {
7772  With->pNorm();
7773  }
7774  strat->redTailChange=TRUE;
7775  if (ksReducePolyTail(L, With, &Ln))
7776  {
7777  // reducing the tail would violate the exp bound
7778  // set a flag and hope for a retry (in bba)
7779  strat->completeReduce_retry=TRUE;
7780  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7781  do
7782  {
7783  pNext(h) = Ln.LmExtractAndIter();
7784  pIter(h);
7785  L->pLength++;
7786  } while (!Ln.IsNull());
7787  goto all_done;
7788  }
7789  if(!Ln.IsNull())
7790  {
7791  Ln.GetP();
7792  Ln.p = pJet(Ln.p,bound);
7793  }
7794  if (Ln.IsNull())
7795  {
7796  goto all_done;
7797  }
7798  if (! withT) With_s.Init(currRing);
7799  }
7800  pNext(h) = Ln.LmExtractAndIter();
7801  pIter(h);
7802  pNormalize(h);
7803  L->pLength++;
7804  }
7805 
7806  all_done:
7807  Ln.Delete();
7808  if (L->p != NULL) pNext(L->p) = pNext(p);
7809 
7810  if (strat->redTailChange)
7811  {
7812  L->length = 0;
7813  L->pLength = 0;
7814  }
7815 
7816  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7817  //L->Normalize(); // HANNES: should have a test
7818  kTest_L(L);
7819  return L->GetLmCurrRing();
7820 }
7821 
7822 #ifdef HAVE_RINGS
7823 poly redtailBba_Z (LObject* L, int pos, kStrategy strat )
7824 // normalize=FALSE, withT=FALSE, coeff=Z
7825 {
7826  strat->redTailChange=FALSE;
7827  if (strat->noTailReduction) return L->GetLmCurrRing();
7828  poly h, p;
7829  p = h = L->GetLmTailRing();
7830  if ((h==NULL) || (pNext(h)==NULL))
7831  return L->GetLmCurrRing();
7832 
7833  TObject* With;
7834  // placeholder in case strat->tl < 0
7835  TObject With_s(strat->tailRing);
7836 
7837  LObject Ln(pNext(h), strat->tailRing);
7838  Ln.pLength = L->GetpLength() - 1;
7839 
7840  pNext(h) = NULL;
7841  if (L->p != NULL) pNext(L->p) = NULL;
7842  L->pLength = 1;
7843 
7844  Ln.PrepareRed(strat->use_buckets);
7845 
7846  int cnt=REDTAIL_CANONICALIZE;
7847  while(!Ln.IsNull())
7848  {
7849  loop
7850  {
7851  Ln.SetShortExpVector();
7852  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
7853  if (With == NULL) break;
7854  cnt--;
7855  if (cnt==0)
7856  {
7858  /*poly tmp=*/Ln.CanonicalizeP();
7859  }
7860  // we are in Z, do not call pNorm
7861  strat->redTailChange=TRUE;
7862  // test divisibility of coefs:
7863  poly p_Ln=Ln.GetLmCurrRing();
7864  poly p_With=With->GetLmCurrRing();
7865  number z=n_IntMod(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf);
7866  if (!nIsZero(z))
7867  {
7868  // subtract z*Ln, add z.Ln to L
7869  poly m=pHead(p_Ln);
7870  pSetCoeff(m,z);
7871  poly mm=pHead(m);
7872  pNext(h) = m;
7873  pIter(h);
7874  L->pLength++;
7875  mm=pNeg(mm);
7876  if (Ln.bucket!=NULL)
7877  {
7878  int dummy=1;
7879  kBucket_Add_q(Ln.bucket,mm,&dummy);
7880  }
7881  else
7882  {
7883  if ((Ln.t_p!=NULL)&&(Ln.p==NULL))
7884  Ln.GetP();
7885  if (Ln.p!=NULL)
7886  {
7887  Ln.p=pAdd(Ln.p,mm);
7888  if (Ln.t_p!=NULL)
7889  {
7890  pNext(Ln.t_p)=NULL;
7891  p_LmDelete(Ln.t_p,strat->tailRing);
7892  }
7893  }
7894  }
7895  }
7896  else
7897  nDelete(&z);
7898 
7899  if (ksReducePolyTail(L, With, &Ln))
7900  {
7901  // reducing the tail would violate the exp bound
7902  // set a flag and hope for a retry (in bba)
7903  strat->completeReduce_retry=TRUE;
7904  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7905  do
7906  {
7907  pNext(h) = Ln.LmExtractAndIter();
7908  pIter(h);
7909  L->pLength++;
7910  } while (!Ln.IsNull());
7911  goto all_done;
7912  }
7913  if (Ln.IsNull()) goto all_done;
7914  With_s.Init(currRing);
7915  }
7916  pNext(h) = Ln.LmExtractAndIter();
7917  pIter(h);
7918  pNormalize(h);
7919  L->pLength++;
7920  }
7921 
7922  all_done:
7923  Ln.Delete();
7924  if (L->p != NULL) pNext(L->p) = pNext(p);
7925 
7926  if (strat->redTailChange)
7927  {
7928  L->length = 0;
7929  }
7930 
7931  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7932  //L->Normalize(); // HANNES: should have a test
7933  kTest_L(L);
7934  return L->GetLmCurrRing();
7935 }
7936 #endif
7937 
7938 /*2
7939 *checks the change degree and write progress report
7940 */
7941 void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7942 {
7943  if (i != *olddeg)
7944  {
7945  Print("%d",i);
7946  *olddeg = i;
7947  }
7948  if (TEST_OPT_OLDSTD)
7949  {
7950  if (strat->Ll != *reduc)
7951  {
7952  if (strat->Ll != *reduc-1)
7953  Print("(%d)",strat->Ll+1);
7954  else
7955  PrintS("-");
7956  *reduc = strat->Ll;
7957  }
7958  else
7959  PrintS(".");
7960  mflush();
7961  }
7962  else
7963  {
7964  if (red_result == 0)
7965  PrintS("-");
7966  else if (red_result < 0)
7967  PrintS(".");
7968  if ((red_result > 0) || ((strat->Ll % 100)==99))
7969  {
7970  if (strat->Ll != *reduc && strat->Ll > 0)
7971  {
7972  Print("(%d)",strat->Ll+1);
7973  *reduc = strat->Ll;
7974  }
7975  }
7976  }
7977 }
7978 
7979 /*2
7980 *statistics
7981 */
7982 void messageStat (int hilbcount,kStrategy strat)
7983 {
7984  //PrintS("\nUsage/Allocation of temporary storage:\n");
7985  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7986  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7987  Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7988  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7989  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7990  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7991  /*mflush();*/
7992 }
7993 
7994 void messageStatSBA (int hilbcount,kStrategy strat)
7995 {
7996  //PrintS("\nUsage/Allocation of temporary storage:\n");
7997  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7998  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7999  Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
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  /* in usual case strat->cv is 0, it gets changed only in shift routines */
8003  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
8004  /*mflush();*/
8005 }
8006 
8007 #ifdef KDEBUG
8008 /*2
8009 *debugging output: all internal sets, if changed
8010 *for testing purpuse only/has to be changed for later use
8011 */
8012 void messageSets (kStrategy strat)
8013 {
8014  int i;
8015  if (strat->news)
8016  {
8017  PrintS("set S");
8018  for (i=0; i<=strat->sl; i++)
8019  {
8020  Print("\n %d:",i);
8021  p_wrp(strat->S[i], currRing, strat->tailRing);
8022  }
8023  strat->news = FALSE;
8024  }
8025  if (strat->newt)
8026  {
8027  PrintS("\nset T");
8028  for (i=0; i<=strat->tl; i++)
8029  {
8030  Print("\n %d:",i);
8031  strat->T[i].wrp();
8032  Print(" o:%ld e:%d l:%d",
8033  strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
8034  }
8035  strat->newt = FALSE;
8036  }
8037  PrintS("\nset L");
8038  for (i=strat->Ll; i>=0; i--)
8039  {
8040  Print("\n%d:",i);
8041  p_wrp(strat->L[i].p1, currRing, strat->tailRing);
8042  PrintS(" ");
8043  p_wrp(strat->L[i].p2, currRing, strat->tailRing);
8044  PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
8045  PrintS("\n p : ");
8046  strat->L[i].wrp();
8047  Print(" o:%ld e:%d l:%d",
8048  strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
8049  }
8050  PrintLn();
8051 }
8052 
8053 #endif
8054 
8055 
8056 /*2
8057 *construct the set s from F
8058 */
8059 void initS (ideal F, ideal Q, kStrategy strat)
8060 {
8061  int i,pos;
8062 
8063  if (Q!=NULL) i=((IDELEMS(F)+IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8064  else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8065  strat->ecartS=initec(i);
8066  strat->sevS=initsevS(i);
8067  strat->S_2_R=initS_2_R(i);
8068  strat->fromQ=NULL;
8069  strat->Shdl=idInit(i,F->rank);
8070  strat->S=strat->Shdl->m;
8071  /*- put polys into S -*/
8072  if (Q!=NULL)
8073  {
8074  strat->fromQ=initec(i);
8075  memset(strat->fromQ,0,i*sizeof(int));
8076  for (i=0; i<IDELEMS(Q); i++)
8077  {
8078  if (Q->m[i]!=NULL)
8079  {
8080  LObject h;
8081  h.p = pCopy(Q->m[i]);
8083  {
8084  //pContent(h.p);
8085  h.pCleardenom(); // also does a pContent
8086  }
8087  else
8088  {
8089  h.pNorm();
8090  }
8092  {
8093  deleteHC(&h, strat);
8094  }
8095  if (h.p!=NULL)
8096  {
8097  strat->initEcart(&h);
8098  if (strat->sl==-1)
8099  pos =0;
8100  else
8101  {
8102  pos = posInS(strat,strat->sl,h.p,h.ecart);
8103  }
8104  h.sev = pGetShortExpVector(h.p);
8105  strat->enterS(h,pos,strat,-1);
8106  strat->fromQ[pos]=1;
8107  }
8108  }
8109  }
8110  }
8111  for (i=0; i<IDELEMS(F); i++)
8112  {
8113  if (F->m[i]!=NULL)
8114  {
8115  LObject h;
8116  h.p = pCopy(F->m[i]);
8118  {
8119  cancelunit(&h); /*- tries to cancel a unit -*/
8120  deleteHC(&h, strat);
8121  }
8122  if (h.p!=NULL)
8123  // do not rely on the input being a SB!
8124  {
8126  {
8127  //pContent(h.p);
8128  h.pCleardenom(); // also does a pContent
8129  }
8130  else
8131  {
8132  h.pNorm();
8133  }
8134  strat->initEcart(&h);
8135  if (strat->sl==-1)
8136  pos =0;
8137  else
8138  pos = posInS(strat,strat->sl,h.p,h.ecart);
8139  h.sev = pGetShortExpVector(h.p);
8140  strat->enterS(h,pos,strat,-1);
8141  }
8142  }
8143  }
8144  /*- test, if a unit is in F -*/
8145  if ((strat->sl>=0)
8146 #ifdef HAVE_RINGS
8147  && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
8148 #endif
8149  && pIsConstant(strat->S[0]))
8150  {
8151  while (strat->sl>0) deleteInS(strat->sl,strat);
8152  }
8153 }
8154 
8155 void initSL (ideal F, ideal Q,kStrategy strat)
8156 {
8157  int i,pos;
8158 
8159  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8160  else i=setmaxT;
8161  strat->ecartS=initec(i);
8162  strat->sevS=initsevS(i);
8163  strat->S_2_R=initS_2_R(i);
8164  strat->fromQ=NULL;
8165  strat->Shdl=idInit(i,F->rank);
8166  strat->S=strat->Shdl->m;
8167  /*- put polys into S -*/
8168  if (Q!=NULL)
8169  {
8170  strat->fromQ=initec(i);
8171  memset(strat->fromQ,0,i*sizeof(int));
8172  for (i=0; i<IDELEMS(Q); i++)
8173  {
8174  if (Q->m[i]!=NULL)
8175  {
8176  LObject h;
8177  h.p = pCopy(Q->m[i]);
8179  {
8180  deleteHC(&h,strat);
8181  }
8183  {
8184  //pContent(h.p);
8185  h.pCleardenom(); // also does a pContent
8186  }
8187  else
8188  {
8189  h.pNorm();
8190  }
8191  if (h.p!=NULL)
8192  {
8193  strat->initEcart(&h);
8194  if (strat->sl==-1)
8195  pos =0;
8196  else
8197  {
8198  pos = posInS(strat,strat->sl,h.p,h.ecart);
8199  }
8200  h.sev = pGetShortExpVector(h.p);
8201  strat->enterS(h,pos,strat,-1);
8202  strat->fromQ[pos]=1;
8203  }
8204  }
8205  }
8206  }
8207  for (i=0; i<IDELEMS(F); i++)
8208  {
8209  if (F->m[i]!=NULL)
8210  {
8211  LObject h;
8212  h.p = pCopy(F->m[i]);
8213  if (h.p!=NULL)
8214  {
8216  {
8217  cancelunit(&h); /*- tries to cancel a unit -*/
8218  deleteHC(&h, strat);
8219  }
8220  if (h.p!=NULL)
8221  {
8223  {
8224  //pContent(h.p);
8225  h.pCleardenom(); // also does a pContent
8226  }
8227  else
8228  {
8229  h.pNorm();
8230  }
8231  strat->initEcart(&h);
8232  if (strat->Ll==-1)
8233  pos =0;
8234  else
8235  pos = strat->posInL(strat->L,strat->Ll,&h,strat);
8236  h.sev = pGetShortExpVector(h.p);
8237  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8238  }
8239  }
8240  }
8241  }
8242  /*- test, if a unit is in F -*/
8243 
8244  if ((strat->Ll>=0)
8245 #ifdef HAVE_RINGS
8246  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8247 #endif
8248  && pIsConstant(strat->L[strat->Ll].p))
8249  {
8250  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8251  }
8252 }
8253 
8254 void initSLSba (ideal F, ideal Q,kStrategy strat)
8255 {
8256  int i,pos;
8257  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8258  else i=setmaxT;
8259  strat->ecartS = initec(i);
8260  strat->sevS = initsevS(i);
8261  strat->sevSig = initsevS(i);
8262  strat->S_2_R = initS_2_R(i);
8263  strat->fromQ = NULL;
8264  strat->Shdl = idInit(i,F->rank);
8265  strat->S = strat->Shdl->m;
8266  strat->sig = (poly *)omAlloc0(i*sizeof(poly));
8267  if (strat->sbaOrder != 1)
8268  {
8269  strat->syz = (poly *)omAlloc0(i*sizeof(poly));
8270  strat->sevSyz = initsevS(i);
8271  strat->syzmax = i;
8272  strat->syzl = 0;
8273  }
8274  /*- put polys into S -*/
8275  if (Q!=NULL)
8276  {
8277  strat->fromQ=initec(i);
8278  memset(strat->fromQ,0,i*sizeof(int));
8279  for (i=0; i<IDELEMS(Q); i++)
8280  {
8281  if (Q->m[i]!=NULL)
8282  {
8283  LObject h;
8284  h.p = pCopy(Q->m[i]);
8286  {
8287  deleteHC(&h,strat);
8288  }
8290  {
8291  //pContent(h.p);
8292  h.pCleardenom(); // also does a pContent
8293  }
8294  else
8295  {
8296  h.pNorm();
8297  }
8298  if (h.p!=NULL)
8299  {
8300  strat->initEcart(&h);
8301  if (strat->sl==-1)
8302  pos =0;
8303  else
8304  {
8305  pos = posInS(strat,strat->sl,h.p,h.ecart);
8306  }
8307  h.sev = pGetShortExpVector(h.p);
8308  strat->enterS(h,pos,strat,-1);
8309  strat->fromQ[pos]=1;
8310  }
8311  }
8312  }
8313  }
8314  for (i=0; i<IDELEMS(F); i++)
8315  {
8316  if (F->m[i]!=NULL)
8317  {
8318  LObject h;
8319  h.p = pCopy(F->m[i]);
8320  h.sig = pOne();
8321  //h.sig = pInit();
8322  //p_SetCoeff(h.sig,nInit(1),currRing);
8323  p_SetComp(h.sig,i+1,currRing);
8324  // if we are working with the Schreyer order we generate it
8325  // by multiplying the initial signatures with the leading monomial
8326  // of the corresponding initial polynomials generating the ideal
8327  // => we can keep the underlying monomial order and get a Schreyer
8328  // order without any bigger overhead
8329  if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
8330  {
8331  p_ExpVectorAdd (h.sig,F->m[i],currRing);
8332  }
8333  h.sevSig = pGetShortExpVector(h.sig);
8334 #ifdef DEBUGF5
8335  pWrite(h.p);
8336  pWrite(h.sig);
8337 #endif
8338  if (h.p!=NULL)
8339  {
8341  {
8342  cancelunit(&h); /*- tries to cancel a unit -*/
8343  deleteHC(&h, strat);
8344  }
8345  if (h.p!=NULL)
8346  {
8348  {
8349  //pContent(h.p);
8350  h.pCleardenom(); // also does a pContent
8351  }
8352  else
8353  {
8354  h.pNorm();
8355  }
8356  strat->initEcart(&h);
8357  if (strat->Ll==-1)
8358  pos =0;
8359  else
8360  pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
8361  h.sev = pGetShortExpVector(h.p);
8362  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8363  }
8364  }
8365  /*
8366  if (strat->sbaOrder != 1)
8367  {
8368  for(j=0;j<i;j++)
8369  {
8370  strat->syz[ctr] = pCopy(F->m[j]);
8371  p_SetCompP(strat->syz[ctr],i+1,currRing);
8372  // add LM(F->m[i]) to the signature to get a Schreyer order
8373  // without changing the underlying polynomial ring at all
8374  p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
8375  // since p_Add_q() destroys all input
8376  // data we need to recreate help
8377  // each time
8378  poly help = pCopy(F->m[i]);
8379  p_SetCompP(help,j+1,currRing);
8380  pWrite(strat->syz[ctr]);
8381  pWrite(help);
8382  printf("%d\n",pLmCmp(strat->syz[ctr],help));
8383  strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
8384  printf("%d. SYZ ",ctr);
8385  pWrite(strat->syz[ctr]);
8386  strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
8387  ctr++;
8388  }
8389  strat->syzl = ps;
8390  }
8391  */
8392  }
8393  }
8394  /*- test, if a unit is in F -*/
8395 
8396  if ((strat->Ll>=0)
8397 #ifdef HAVE_RINGS
8398  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8399 #endif
8400  && pIsConstant(strat->L[strat->Ll].p))
8401  {
8402  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8403  }
8404 }
8405 
8407 {
8408  if( strat->S[0] )
8409  {
8410  if( strat->S[1] && !rField_is_Ring(currRing))
8411  {
8412  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
8413  omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
8414  omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
8415  }
8416  int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
8417  /************************************************************
8418  * computing the length of the syzygy array needed
8419  ***********************************************************/
8420  for(i=1; i<=strat->sl; i++)
8421  {
8422  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8423  {
8424  ps += i;
8425  }
8426  }
8427  ps += strat->sl+1;
8428  //comp = pGetComp (strat->P.sig);
8429  comp = strat->currIdx;
8430  strat->syzIdx = initec(comp);
8431  strat->sevSyz = initsevS(ps);
8432  strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8433  strat->syzmax = ps;
8434  strat->syzl = 0;
8435  strat->syzidxmax = comp;
8436 #if defined(DEBUGF5) || defined(DEBUGF51)
8437  PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8438 #endif
8439  i = 1;
8440  j = 0;
8441  /************************************************************
8442  * generating the leading terms of the principal syzygies
8443  ***********************************************************/
8444  while (i <= strat->sl)
8445  {
8446  /**********************************************************
8447  * principal syzygies start with component index 2
8448  * the array syzIdx starts with index 0
8449  * => the rules for a signature with component comp start
8450  * at strat->syz[strat->syzIdx[comp-2]] !
8451  *********************************************************/
8452  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8453  {
8454  comp = pGetComp(strat->sig[i]);
8455  comp_old = pGetComp(strat->sig[i-1]);
8456  diff = comp - comp_old - 1;
8457  // diff should be zero, but sometimes also the initial generating
8458  // elements of the input ideal reduce to zero. then there is an
8459  // index-gap between the signatures. for these inbetween signatures we
8460  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8461  // in the following.
8462  // doing this, we keep the relation "j = comp - 2" alive, which makes
8463  // jumps way easier when checking criteria
8464  while (diff>0)
8465  {
8466  strat->syzIdx[j] = 0;
8467  diff--;
8468  j++;
8469  }
8470  strat->syzIdx[j] = ctr;
8471  j++;
8472  LObject Q;
8473  int pos;
8474  for (k = 0; k<i; k++)
8475  {
8476  Q.sig = pOne();
8478  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8479  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8480  p_SetCompP (Q.sig, comp, currRing);
8481  poly q = p_One(currRing);
8483  p_SetCoeff(q,nCopy(p_GetCoeff(strat->S[i],currRing)),currRing);
8484  p_ExpVectorCopy(q,strat->S[i],currRing);
8485  q = p_Neg (q, currRing);
8486  p_SetCompP (q, p_GetComp(strat->sig[k], currRing), currRing);
8487  Q.sig = p_Add_q (Q.sig, q, currRing);
8488  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8489  pos = posInSyz(strat, Q.sig);
8490  enterSyz(Q, strat, pos);
8491  ctr++;
8492  }
8493  }
8494  i++;
8495  }
8496  /**************************************************************
8497  * add syzygies for upcoming first element of new iteration step
8498  **************************************************************/
8499  comp = strat->currIdx;
8500  comp_old = pGetComp(strat->sig[i-1]);
8501  diff = comp - comp_old - 1;
8502  // diff should be zero, but sometimes also the initial generating
8503  // elements of the input ideal reduce to zero. then there is an
8504  // index-gap between the signatures. for these inbetween signatures we
8505  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8506  // in the following.
8507  // doing this, we keep the relation "j = comp - 2" alive, which makes
8508  // jumps way easier when checking criteria
8509  while (diff>0)
8510  {
8511  strat->syzIdx[j] = 0;
8512  diff--;
8513  j++;
8514  }
8515  strat->syzIdx[j] = ctr;
8516  LObject Q;
8517  int pos;
8518  for (k = 0; k<strat->sl+1; k++)
8519  {
8520  Q.sig = pOne();
8522  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8523  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8524  p_SetCompP (Q.sig, comp, currRing);
8525  poly q = p_One(currRing);
8527  p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8528  p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8529  q = p_Neg (q, currRing);
8530  p_SetCompP (q, p_GetComp(strat->sig[k], currRing), currRing);
8531  Q.sig = p_Add_q (Q.sig, q, currRing);
8532  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8533  pos = posInSyz(strat, Q.sig);
8534  enterSyz(Q, strat, pos);
8535  ctr++;
8536  }
8537 //#if 1
8538 #ifdef DEBUGF5
8539  PrintS("Principal syzygies:\n");
8540  Print("syzl %d\n",strat->syzl);
8541  Print("syzmax %d\n",strat->syzmax);
8542  Print("ps %d\n",ps);
8543  PrintS("--------------------------------\n");
8544  for(i=0;i<=strat->syzl-1;i++)
8545  {
8546  Print("%d - ",i);
8547  pWrite(strat->syz[i]);
8548  }
8549  for(i=0;i<strat->currIdx;i++)
8550  {
8551  Print("%d - %d\n",i,strat->syzIdx[i]);
8552  }
8553  PrintS("--------------------------------\n");
8554 #endif
8555  }
8556 }
8557 
8558 /*2
8559 *construct the set s from F and {P}
8560 */
8561 void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8562 {
8563  int i,pos;
8564 
8565  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8566  else i=setmaxT;
8567  i=((i+IDELEMS(F)+IDELEMS(P)+15)/16)*16;
8568  strat->ecartS=initec(i);
8569  strat->sevS=initsevS(i);
8570  strat->S_2_R=initS_2_R(i);
8571  strat->fromQ=NULL;
8572  strat->Shdl=idInit(i,F->rank);
8573  strat->S=strat->Shdl->m;
8574 
8575  /*- put polys into S -*/
8576  if (Q!=NULL)
8577  {
8578  strat->fromQ=initec(i);
8579  memset(strat->fromQ,0,i*sizeof(int));
8580  for (i=0; i<IDELEMS(Q); i++)
8581  {
8582  if (Q->m[i]!=NULL)
8583  {
8584  LObject h;
8585  h.p = pCopy(Q->m[i]);
8586  //if (TEST_OPT_INTSTRATEGY)
8587  //{
8588  // //pContent(h.p);
8589  // h.pCleardenom(); // also does a pContent
8590  //}
8591  //else
8592  //{
8593  // h.pNorm();
8594  //}
8596  {
8597  deleteHC(&h,strat);
8598  }
8599  if (h.p!=NULL)
8600  {
8601  strat->initEcart(&h);
8602  if (strat->sl==-1)
8603  pos =0;
8604  else
8605  {
8606  pos = posInS(strat,strat->sl,h.p,h.ecart);
8607  }
8608  h.sev = pGetShortExpVector(h.p);
8609  strat->enterS(h,pos,strat, strat->tl+1);
8610  enterT(h, strat);
8611  strat->fromQ[pos]=1;
8612  }
8613  }
8614  }
8615  }
8616  /*- put polys into S -*/
8617  for (i=0; i<IDELEMS(F); i++)
8618  {
8619  if (F->m[i]!=NULL)
8620  {
8621  LObject h;
8622  h.p = pCopy(F->m[i]);
8624  {
8625  deleteHC(&h,strat);
8626  }
8627  else
8628  {
8629  h.p=redtailBba(h.p,strat->sl,strat);
8630  }
8631  if (h.p!=NULL)
8632  {
8633  strat->initEcart(&h);
8634  if (strat->sl==-1)
8635  pos =0;
8636  else
8637  pos = posInS(strat,strat->sl,h.p,h.ecart);
8638  h.sev = pGetShortExpVector(h.p);
8639  strat->enterS(h,pos,strat, strat->tl+1);
8640  enterT(h,strat);
8641  }
8642  }
8643  }
8644  for (i=0; i<IDELEMS(P); i++)
8645  {
8646  if (P->m[i]!=NULL)
8647  {
8648  LObject h;
8649  h.p=pCopy(P->m[i]);
8651  {
8652  h.pCleardenom();
8653  }
8654  else
8655  {
8656  h.pNorm();
8657  }
8658  if(strat->sl>=0)
8659  {
8661  {
8662  h.p=redBba(h.p,strat->sl,strat);
8663  if (h.p!=NULL)
8664  {
8665  h.p=redtailBba(h.p,strat->sl,strat);
8666  }
8667  }
8668  else
8669  {
8670  h.p=redMora(h.p,strat->sl,strat);
8671  }
8672  if(h.p!=NULL)
8673  {
8674  strat->initEcart(&h);
8676  {
8677  h.pCleardenom();
8678  }
8679  else
8680  {
8681  h.is_normalized = 0;
8682  h.pNorm();
8683  }
8684  h.sev = pGetShortExpVector(h.p);
8685  h.SetpFDeg();
8686  pos = posInS(strat,strat->sl,h.p,h.ecart);
8687  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8688  strat->enterS(h,pos,strat, strat->tl+1);
8689  enterT(h,strat);
8690  }
8691  }
8692  else
8693  {
8694  h.sev = pGetShortExpVector(h.p);
8695  strat->initEcart(&h);
8696  strat->enterS(h,0,strat, strat->tl+1);
8697  enterT(h,strat);
8698  }
8699  }
8700  }
8701 }
8702 /*2
8703 *construct the set s from F and {P}
8704 */
8705 
8706 void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8707 {
8708  int i,pos;
8709 
8710  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8711  else i=setmaxT;
8712  i=((i+IDELEMS(F)+IDELEMS(P)+15)/16)*16;
8713  strat->sevS=initsevS(i);
8714  strat->sevSig=initsevS(i);
8715  strat->S_2_R=initS_2_R(i);
8716  strat->fromQ=NULL;
8717  strat->Shdl=idInit(i,F->rank);
8718  strat->S=strat->Shdl->m;
8719  strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8720  /*- put polys into S -*/
8721  if (Q!=NULL)
8722  {
8723  strat->fromQ=initec(i);
8724  memset(strat->fromQ,0,i*sizeof(int));
8725  for (i=0; i<IDELEMS(Q); i++)
8726  {
8727  if (Q->m[i]!=NULL)
8728  {
8729  LObject h;
8730  h.p = pCopy(Q->m[i]);
8731  //if (TEST_OPT_INTSTRATEGY)
8732  //{
8733  // //pContent(h.p);
8734  // h.pCleardenom(); // also does a pContent
8735  //}
8736  //else
8737  //{
8738  // h.pNorm();
8739  //}
8741  {
8742  deleteHC(&h,strat);
8743  }
8744  if (h.p!=NULL)
8745  {
8746  strat->initEcart(&h);
8747  if (strat->sl==-1)
8748  pos =0;
8749  else
8750  {
8751  pos = posInS(strat,strat->sl,h.p,h.ecart);
8752  }
8753  h.sev = pGetShortExpVector(h.p);
8754  strat->enterS(h,pos,strat, strat->tl+1);
8755  enterT(h, strat);
8756  strat->fromQ[pos]=1;
8757  }
8758  }
8759  }
8760  }
8761  /*- put polys into S -*/
8762  for (i=0; i<IDELEMS(F); i++)
8763  {
8764  if (F->m[i]!=NULL)
8765  {
8766  LObject h;
8767  h.p = pCopy(F->m[i]);
8769  {
8770  deleteHC(&h,strat);
8771  }
8772  else
8773  {
8774  h.p=redtailBba(h.p,strat->sl,strat);
8775  }
8776  if (h.p!=NULL)
8777  {
8778  strat->initEcart(&h);
8779  if (strat->sl==-1)
8780  pos =0;
8781  else
8782  pos = posInS(strat,strat->sl,h.p,h.ecart);
8783  h.sev = pGetShortExpVector(h.p);
8784  strat->enterS(h,pos,strat, strat->tl+1);
8785  enterT(h,strat);
8786  }
8787  }
8788  }
8789  for (i=0; i<IDELEMS(P); i++)
8790  {
8791  if (P->m[i]!=NULL)
8792  {
8793  LObject h;
8794  h.p=pCopy(P->m[i]);
8796  {
8797  h.pCleardenom();
8798  }
8799  else
8800  {
8801  h.pNorm();
8802  }
8803  if(strat->sl>=0)
8804  {
8806  {
8807  h.p=redBba(h.p,strat->sl,strat);
8808  if (h.p!=NULL)
8809  {
8810  h.p=redtailBba(h.p,strat->sl,strat);
8811  }
8812  }
8813  else
8814  {
8815  h.p=redMora(h.p,strat->sl,strat);
8816  }
8817  if(h.p!=NULL)
8818  {
8819  strat->initEcart(&h);
8821  {
8822  h.pCleardenom();
8823  }
8824  else
8825  {
8826  h.is_normalized = 0;
8827  h.pNorm();
8828  }
8829  h.sev = pGetShortExpVector(h.p);
8830  h.SetpFDeg();
8831  pos = posInS(strat,strat->sl,h.p,h.ecart);
8832  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8833  strat->enterS(h,pos,strat, strat->tl+1);
8834  enterT(h,strat);
8835  }
8836  }
8837  else
8838  {
8839  h.sev = pGetShortExpVector(h.p);
8840  strat->initEcart(&h);
8841  strat->enterS(h,0,strat, strat->tl+1);
8842  enterT(h,strat);
8843  }
8844  }
8845  }
8846 }
8847 
8848 /*2
8849 * reduces h using the set S
8850 * procedure used in cancelunit1
8851 */
8852 static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8853 {
8854  int j = 0;
8855  unsigned long not_sev = ~ pGetShortExpVector(h);
8856 
8857  while (j <= maxIndex)
8858  {
8859  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8860  return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8861  else j++;
8862  }
8863  return h;
8864 }
8865 
8866 /*2
8867 *tests if p.p=monomial*unit and cancels the unit
8868 */
8869 void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8870 {
8871  int k;
8872  poly r,h,h1,q;
8873 
8874  if (!pIsVector((*p).p) && ((*p).ecart != 0))
8875  {
8876 #ifdef HAVE_RINGS
8877  // Leading coef have to be a unit: no
8878  // example 2x+4x2 should be simplified to 2x*(1+2x)
8879  // and 2 is not a unit in Z
8880  //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8881 #endif
8882  k = 0;
8883  h1 = r = pCopy((*p).p);
8884  h =pNext(r);
8885  loop
8886  {
8887  if (h==NULL)
8888  {
8889  pDelete(&r);
8890  pDelete(&(pNext((*p).p)));
8891  (*p).ecart = 0;
8892  (*p).length = 1;
8893  (*p).pLength = 1;
8894  (*suc)=0;
8895  return;
8896  }
8897  if (!pDivisibleBy(r,h))
8898  {
8899  q=redBba1(h,index ,strat);
8900  if (q != h)
8901  {
8902  k++;
8903  pDelete(&h);
8904  pNext(h1) = h = q;
8905  }
8906  else
8907  {
8908  pDelete(&r);
8909  return;
8910  }
8911  }
8912  else
8913  {
8914  h1 = h;
8915  pIter(h);
8916  }
8917  if (k > 10)
8918  {
8919  pDelete(&r);
8920  return;
8921  }
8922  }
8923  }
8924 }
8925 
8926 #if 0
8927 /*2
8928 * reduces h using the elements from Q in the set S
8929 * procedure used in updateS
8930 * must not be used for elements of Q or elements of an ideal !
8931 */
8932 static poly redQ (poly h, int j, kStrategy strat)
8933 {
8934  int start;
8935  unsigned long not_sev = ~ pGetShortExpVector(h);
8936  while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8937  start=j;
8938  while (j<=strat->sl)
8939  {
8940  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8941  {
8942  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8943  if (h==NULL) return NULL;
8944  j = start;
8945  not_sev = ~ pGetShortExpVector(h);
8946  }
8947  else j++;
8948  }
8949  return h;
8950 }
8951 #endif
8952 
8953 /*2
8954 * reduces h using the set S
8955 * procedure used in updateS
8956 */
8957 static poly redBba (poly h,int maxIndex,kStrategy strat)
8958 {
8959  int j = 0;
8960  unsigned long not_sev = ~ pGetShortExpVector(h);
8961 
8962  while (j <= maxIndex)
8963  {
8964  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8965  {
8966  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8967  if (h==NULL) return NULL;
8968  j = 0;
8969  not_sev = ~ pGetShortExpVector(h);
8970  }
8971  else j++;
8972  }
8973  return h;
8974 }
8975 
8976 /*2
8977 * reduces h using the set S
8978 *e is the ecart of h
8979 *procedure used in updateS
8980 */
8981 static poly redMora (poly h,int maxIndex,kStrategy strat)
8982 {
8983  int j=0;
8984  int e,l;
8985  unsigned long not_sev = ~ pGetShortExpVector(h);
8986 
8987  if (maxIndex >= 0)
8988  {
8989  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8990  do
8991  {
8992  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8993  && ((e >= strat->ecartS[j]) || strat->kHEdgeFound))
8994  {
8995 #ifdef KDEBUG
8996  if (TEST_OPT_DEBUG)
8997  {
8998  PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8999  }
9000 #endif
9001  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
9002 #ifdef KDEBUG
9003  if(TEST_OPT_DEBUG)
9004  {
9005  PrintS(")\nto "); wrp(h); PrintLn();
9006  }
9007 #endif
9008  // pDelete(&h);
9009  if (h == NULL) return NULL;
9010  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
9011  j = 0;
9012  not_sev = ~ pGetShortExpVector(h);
9013  }
9014  else j++;
9015  }
9016  while (j <= maxIndex);
9017  }
9018  return h;
9019 }
9020 
9021 /*2
9022 *updates S:
9023 *the result is a set of polynomials which are in
9024 *normalform with respect to S
9025 */
9026 void updateS(BOOLEAN toT,kStrategy strat)
9027 {
9028  LObject h;
9029  int i, suc=0;
9030  poly redSi=NULL;
9031  BOOLEAN change,any_change;
9032 // Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
9033 // for (i=0; i<=(strat->sl); i++)
9034 // {
9035 // Print("s%d:",i);
9036 // if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
9037 // pWrite(strat->S[i]);
9038 // }
9039 // Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
9040  any_change=FALSE;
9042  {
9043  while (suc != -1)
9044  {
9045  i=suc+1;
9046  while (i<=strat->sl)
9047  {
9048  change=FALSE;
9050  any_change = FALSE;
9051  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
9052  {
9053  redSi = pHead(strat->S[i]);
9054  strat->S[i] = redBba(strat->S[i],i-1,strat);
9055  //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
9056  // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
9057  if (pCmp(redSi,strat->S[i])!=0)
9058  {
9059  change=TRUE;
9060  any_change=TRUE;
9061  #ifdef KDEBUG
9062  if (TEST_OPT_DEBUG)
9063  {
9064  PrintS("reduce:");
9065  wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
9066  }
9067  #endif
9068  if (TEST_OPT_PROT)
9069  {
9070  if (strat->S[i]==NULL)
9071  PrintS("V");
9072  else
9073  PrintS("v");
9074  mflush();
9075  }
9076  }
9077  pLmDelete(&redSi);
9078  if (strat->S[i]==NULL)
9079  {
9080  deleteInS(i,strat);
9081  i--;
9082  }
9083  else if (change)
9084  {
9086  {
9087  if (TEST_OPT_CONTENTSB)
9088  {
9089  number n;
9090  p_Cleardenom_n(strat->S[i], currRing, n);// also does a pContent
9091  if (!nIsOne(n))
9092  {
9094  denom->n=nInvers(n);
9095  denom->next=DENOMINATOR_LIST;
9096  DENOMINATOR_LIST=denom;
9097  }
9098  nDelete(&n);
9099  }
9100  else
9101  {
9102  //pContent(strat->S[i]);
9103  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does a pContent
9104  }
9105  }
9106  else
9107  {
9108  pNorm(strat->S[i]);
9109  }
9110  strat->sevS[i] = pGetShortExpVector(strat->S[i]);
9111  }
9112  }
9113  i++;
9114  }
9115  if (any_change) reorderS(&suc,strat);
9116  else break;
9117  }
9118  if (toT)
9119  {
9120  for (i=0; i<=strat->sl; i++)
9121  {
9122  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9123  {
9124  h.p = redtailBba(strat->S[i],i-1,strat);
9126  {
9127  h.pCleardenom();// also does a pContent
9128  }
9129  }
9130  else
9131  {
9132  h.p = strat->S[i];
9133  }
9134  strat->initEcart(&h);
9135  if (strat->honey)
9136  {
9137  strat->ecartS[i] = h.ecart;
9138  }
9139  if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
9140  else assume(strat->sevS[i] == pGetShortExpVector(h.p));
9141  h.sev = strat->sevS[i];
9142  /*puts the elements of S also to T*/
9143  strat->initEcart(&h);
9144  enterT(h,strat);
9145  strat->S_2_R[i] = strat->tl;
9146  }
9147  }
9148  }
9149  else
9150  {
9151  while (suc != -1)
9152  {
9153  i=suc;
9154  while (i<=strat->sl)
9155  {
9156  change=FALSE;
9157  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
9158  {
9159  redSi=pHead((strat->S)[i]);
9160  (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
9161  if ((strat->S)[i]==NULL)
9162  {
9163  deleteInS(i,strat);
9164  i--;
9165  }
9166  else if (pCmp((strat->S)[i],redSi)!=0)
9167  {
9168  any_change=TRUE;
9169  h.p = strat->S[i];
9170  strat->initEcart(&h);
9171  strat->ecartS[i] = h.ecart;
9173  {
9174  if (TEST_OPT_CONTENTSB)
9175  {
9176  number n;
9177  p_Cleardenom_n(strat->S[i], currRing, n);// also does a pContent
9178  if (!nIsOne(n))
9179  {
9181  denom->n=nInvers(n);
9182  denom->next=DENOMINATOR_LIST;
9183  DENOMINATOR_LIST=denom;
9184  }
9185  nDelete(&n);
9186  }
9187  else
9188  {
9189  //pContent(strat->S[i]);
9190  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does a pContent
9191  }
9192  }
9193  else
9194  {
9195  pNorm(strat->S[i]); // == h.p
9196  }
9197  h.sev = pGetShortExpVector(h.p);
9198  strat->sevS[i] = h.sev;
9199  }
9200  pLmDelete(&redSi);
9201  kTest(strat);
9202  }
9203  i++;
9204  }
9205 #ifdef KDEBUG
9206  kTest(strat);
9207 #endif
9208  if (any_change) reorderS(&suc,strat);
9209  else { suc=-1; break; }
9210  if (h.p!=NULL)
9211  {
9212  if (!strat->kHEdgeFound)
9213  {
9214  /*strat->kHEdgeFound =*/ HEckeTest(h.p,strat);
9215  }
9216  if (strat->kHEdgeFound)
9217  newHEdge(strat);
9218  }
9219  }
9220  for (i=0; i<=strat->sl; i++)
9221  {
9222  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9223  {
9224  strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
9225  strat->initEcart(&h);
9226  strat->ecartS[i] = h.ecart;
9227  h.sev = pGetShortExpVector(h.p);
9228  strat->sevS[i] = h.sev;
9229  }
9230  else
9231  {
9232  h.p = strat->S[i];
9233  h.ecart=strat->ecartS[i];
9234  h.sev = strat->sevS[i];
9235  h.length = h.pLength = pLength(h.p);
9236  }
9237  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9238  cancelunit1(&h,&suc,strat->sl,strat);
9239  h.SetpFDeg();
9240  /*puts the elements of S also to T*/
9241  enterT(h,strat);
9242  strat->S_2_R[i] = strat->tl;
9243  }
9244  if (suc!= -1) updateS(toT,strat);
9245  }
9246 #ifdef KDEBUG
9247  kTest(strat);
9248 #endif
9249 }
9250 
9251 /*2
9252 * -puts p to the standardbasis s at position at
9253 * -saves the result in S
9254 */
9255 void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
9256 {
9257  strat->news = TRUE;
9258  /*- puts p to the standardbasis s at position at -*/
9259  if (strat->sl == IDELEMS(strat->Shdl)-1)
9260  {
9261  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9262  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9263  (IDELEMS(strat->Shdl)+setmaxTinc)
9264  *sizeof(unsigned long));
9265  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9266  IDELEMS(strat->Shdl)*sizeof(int),
9267  (IDELEMS(strat->Shdl)+setmaxTinc)
9268  *sizeof(int));
9269  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9270  IDELEMS(strat->Shdl)*sizeof(int),
9271  (IDELEMS(strat->Shdl)+setmaxTinc)
9272  *sizeof(int));
9273  if (strat->lenS!=NULL)
9274  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9275  IDELEMS(strat->Shdl)*sizeof(int),
9276  (IDELEMS(strat->Shdl)+setmaxTinc)
9277  *sizeof(int));
9278  if (strat->lenSw!=NULL)
9279  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9280  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9281  (IDELEMS(strat->Shdl)+setmaxTinc)
9282  *sizeof(wlen_type));
9283  if (strat->fromQ!=NULL)
9284  {
9285  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9286  IDELEMS(strat->Shdl)*sizeof(int),
9287  (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9288  }
9289  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
9290  IDELEMS(strat->Shdl)+=setmaxTinc;
9291  strat->Shdl->m=strat->S;
9292  }
9293  if (atS <= strat->sl)
9294  {
9295 #ifdef ENTER_USE_MEMMOVE
9296  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9297  (strat->sl - atS + 1)*sizeof(poly));
9298  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9299  (strat->sl - atS + 1)*sizeof(int));
9300  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9301  (strat->sl - atS + 1)*sizeof(unsigned long));
9302  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9303  (strat->sl - atS + 1)*sizeof(int));
9304  if (strat->lenS!=NULL)
9305  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9306  (strat->sl - atS + 1)*sizeof(int));
9307  if (strat->lenSw!=NULL)
9308  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9309  (strat->sl - atS + 1)*sizeof(wlen_type));
9310 #else
9311  for (i=strat->sl+1; i>=atS+1; i--)
9312  {
9313  strat->S[i] = strat->S[i-1];
9314  strat->ecartS[i] = strat->ecartS[i-1];
9315  strat->sevS[i] = strat->sevS[i-1];
9316  strat->S_2_R[i] = strat->S_2_R[i-1];
9317  }
9318  if (strat->lenS!=NULL)
9319  for (i=strat->sl+1; i>=atS+1; i--)
9320  strat->lenS[i] = strat->lenS[i-1];
9321  if (strat->lenSw!=NULL)
9322  for (i=strat->sl+1; i>=atS+1; i--)
9323  strat->lenSw[i] = strat->lenSw[i-1];
9324 #endif
9325  }
9326  if (strat->fromQ!=NULL)
9327  {
9328 #ifdef ENTER_USE_MEMMOVE
9329  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9330  (strat->sl - atS + 1)*sizeof(int));
9331 #else
9332  for (i=strat->sl+1; i>=atS+1; i--)
9333  {
9334  strat->fromQ[i] = strat->fromQ[i-1];
9335  }
9336 #endif
9337  strat->fromQ[atS]=0;
9338  }
9339 
9340  /*- save result -*/
9341  strat->S[atS] = p.p;
9342  if (strat->honey) strat->ecartS[atS] = p.ecart;
9343  if (p.sev == 0)
9344  p.sev = pGetShortExpVector(p.p);
9345  else
9346  assume(p.sev == pGetShortExpVector(p.p));
9347  strat->sevS[atS] = p.sev;
9348  strat->ecartS[atS] = p.ecart;
9349  strat->S_2_R[atS] = atR;
9350  strat->sl++;
9351 }
9352 
9353 /*2
9354 * -puts p to the standardbasis s at position at
9355 * -saves the result in S
9356 */
9357 void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
9358 {
9359  strat->news = TRUE;
9360  /*- puts p to the standardbasis s at position at -*/
9361  if (strat->sl == IDELEMS(strat->Shdl)-1)
9362  {
9363  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9364  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9365  (IDELEMS(strat->Shdl)+setmaxTinc)
9366  *sizeof(unsigned long));
9367  strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
9368  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9369  (IDELEMS(strat->Shdl)+setmaxTinc)
9370  *sizeof(unsigned long));
9371  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9372  IDELEMS(strat->Shdl)*sizeof(int),
9373  (IDELEMS(strat->Shdl)+setmaxTinc)
9374  *sizeof(int));
9375  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9376  IDELEMS(strat->Shdl)*sizeof(int),
9377  (IDELEMS(strat->Shdl)+setmaxTinc)
9378  *sizeof(int));
9379  if (strat->lenS!=NULL)
9380  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9381  IDELEMS(strat->Shdl)*sizeof(int),
9382  (IDELEMS(strat->Shdl)+setmaxTinc)
9383  *sizeof(int));
9384  if (strat->lenSw!=NULL)
9385  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9386  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9387  (IDELEMS(strat->Shdl)+setmaxTinc)
9388  *sizeof(wlen_type));
9389  if (strat->fromQ!=NULL)
9390  {
9391  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9392  IDELEMS(strat->Shdl)*sizeof(int),
9393  (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9394  }
9395  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
9396  pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmaxTinc);
9397  IDELEMS(strat->Shdl)+=setmaxTinc;
9398  strat->Shdl->m=strat->S;
9399  }
9400  // in a signature-based algorithm the following situation will never
9401  // appear due to the fact that the critical pairs are already sorted
9402  // by increasing signature.
9403  // True. However, in the case of integers we need to put the element
9404  // that caused the signature drop on the first position
9405  if (atS <= strat->sl)
9406  {
9407 #ifdef ENTER_USE_MEMMOVE
9408  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9409  (strat->sl - atS + 1)*sizeof(poly));
9410  memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9411  (strat->sl - atS + 1)*sizeof(poly));
9412  memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9413  (strat->sl - atS + 1)*sizeof(unsigned long));
9414  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9415  (strat->sl - atS + 1)*sizeof(int));
9416  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9417  (strat->sl - atS + 1)*sizeof(unsigned long));
9418  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9419  (strat->sl - atS + 1)*sizeof(int));
9420  if (strat->lenS!=NULL)
9421  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9422  (strat->sl - atS + 1)*sizeof(int));
9423  if (strat->lenSw!=NULL)
9424  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9425  (strat->sl - atS + 1)*sizeof(wlen_type));
9426 #else
9427  for (i=strat->sl+1; i>=atS+1; i--)
9428  {
9429  strat->S[i] = strat->S[i-1];
9430  strat->ecartS[i] = strat->ecartS[i-1];
9431  strat->sevS[i] = strat->sevS[i-1];
9432  strat->S_2_R[i] = strat->S_2_R[i-1];
9433  strat->sig[i] = strat->sig[i-1];
9434  strat->sevSig[i] = strat->sevSig[i-1];
9435  }
9436  if (strat->lenS!=NULL)
9437  for (i=strat->sl+1; i>=atS+1; i--)
9438  strat->lenS[i] = strat->lenS[i-1];
9439  if (strat->lenSw!=NULL)
9440  for (i=strat->sl+1; i>=atS+1; i--)
9441  strat->lenSw[i] = strat->lenSw[i-1];
9442 #endif
9443  }
9444  if (strat->fromQ!=NULL)
9445  {
9446 #ifdef ENTER_USE_MEMMOVE
9447  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9448  (strat->sl - atS + 1)*sizeof(int));
9449 #else
9450  for (i=strat->sl+1; i>=atS+1; i--)
9451  {
9452  strat->fromQ[i] = strat->fromQ[i-1];
9453  }
9454 #endif
9455  strat->fromQ[atS]=0;
9456  }
9457 
9458  /*- save result -*/
9459  strat->S[atS] = p.p;
9460  strat->sig[atS] = p.sig; // TODO: get ths correct signature in here!
9461  if (strat->honey) strat->ecartS[atS] = p.ecart;
9462  if (p.sev == 0)
9463  p.sev = pGetShortExpVector(p.p);
9464  else
9465  assume(p.sev == pGetShortExpVector(p.p));
9466  strat->sevS[atS] = p.sev;
9467  // during the interreduction process of a signature-based algorithm we do not
9468  // compute the signature at this point, but when the whole interreduction
9469  // process finishes, i.e. f5c terminates!
9470  if (p.sig != NULL)
9471  {
9472  if (p.sevSig == 0)
9473  p.sevSig = pGetShortExpVector(p.sig);
9474  else
9475  assume(p.sevSig == pGetShortExpVector(p.sig));
9476  strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9477  }
9478  strat->ecartS[atS] = p.ecart;
9479  strat->S_2_R[atS] = atR;
9480  strat->sl++;
9481 #ifdef DEBUGF5
9482  int k;
9483  Print("--- LIST S: %d ---\n",strat->sl);
9484  for(k=0;k<=strat->sl;k++)
9485  {
9486  pWrite(strat->sig[k]);
9487  }
9488  PrintS("--- LIST S END ---\n");
9489 #endif
9490 }
9491 
9492 /*2
9493 * puts p to the set T at position atT
9494 */
9495 void enterT(LObject &p, kStrategy strat, int atT)
9496 {
9497  int i;
9498 
9499  pp_Test(p.p, currRing, p.tailRing);
9500  assume(strat->tailRing == p.tailRing);
9501  // redMoraNF complains about this -- but, we don't really
9502  // neeed this so far
9503  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9504  assume(p.FDeg == p.pFDeg());
9505  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9506 
9507 #ifdef KDEBUG
9508  // do not put an LObject twice into T:
9509  for(i=strat->tl;i>=0;i--)
9510  {
9511  if (p.p==strat->T[i].p)
9512  {
9513  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9514  return;
9515  }
9516  }
9517 #endif
9518 
9519 #ifdef HAVE_TAIL_RING
9520  if (currRing!=strat->tailRing)
9521  {
9522  p.t_p=p.GetLmTailRing();
9523  }
9524 #endif
9525  strat->newt = TRUE;
9526  if (atT < 0)
9527  atT = strat->posInT(strat->T, strat->tl, p);
9528  if (strat->tl == strat->tmax-1)
9529  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9530  if (atT <= strat->tl)
9531  {
9532 #ifdef ENTER_USE_MEMMOVE
9533  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9534  (strat->tl-atT+1)*sizeof(TObject));
9535  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9536  (strat->tl-atT+1)*sizeof(unsigned long));
9537 #endif
9538  for (i=strat->tl+1; i>=atT+1; i--)
9539  {
9540 #ifndef ENTER_USE_MEMMOVE
9541  strat->T[i] = strat->T[i-1];
9542  strat->sevT[i] = strat->sevT[i-1];
9543 #endif
9544  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9545  }
9546  }
9547 
9548  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9549  {
9550  pNext(p.p)=p_ShallowCopyDelete(pNext(p.p),
9551  (strat->tailRing != NULL ?
9552  strat->tailRing : currRing),
9553  strat->tailBin);
9554  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9555  }
9556  strat->T[atT] = (TObject) p;
9557  #ifdef ADIDEBUG
9558  printf("\nenterT: add in position %i\n",atT);
9559  p_Write(p.p,strat->tailRing);p_Write(p.sig,currRing);
9560  #endif
9561  //printf("\nenterT: neue hingefügt: länge = %i, ecart = %i\n",p.length,p.ecart);
9562 
9563  if (pNext(p.p) != NULL)
9564  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9565  else
9566  strat->T[atT].max_exp = NULL;
9567 
9568  strat->tl++;
9569  strat->R[strat->tl] = &(strat->T[atT]);
9570  strat->T[atT].i_r = strat->tl;
9571  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9572  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9573  kTest_T(&(strat->T[atT]));
9574 }
9575 
9576 /*2
9577 * puts p to the set T at position atT
9578 */
9579 #ifdef HAVE_RINGS
9580 void enterT_strong(LObject &p, kStrategy strat, int atT)
9581 {
9583  int i;
9584 
9585  pp_Test(p.p, currRing, p.tailRing);
9586  assume(strat->tailRing == p.tailRing);
9587  // redMoraNF complains about this -- but, we don't really
9588  // neeed this so far
9589  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9590  assume(p.FDeg == p.pFDeg());
9591  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9592 
9593 #ifdef KDEBUG
9594  // do not put an LObject twice into T:
9595  for(i=strat->tl;i>=0;i--)
9596  {
9597  if (p.p==strat->T[i].p)
9598  {
9599  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9600  return;
9601  }
9602  }
9603 #endif
9604 
9605 #ifdef HAVE_TAIL_RING
9606  if (currRing!=strat->tailRing)
9607  {
9608  p.t_p=p.GetLmTailRing();
9609  }
9610 #endif
9611  strat->newt = TRUE;
9612  if (atT < 0)
9613  atT = strat->posInT(strat->T, strat->tl, p);
9614  if (strat->tl == strat->tmax-1)
9615  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9616  if (atT <= strat->tl)
9617  {
9618 #ifdef ENTER_USE_MEMMOVE
9619  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9620  (strat->tl-atT+1)*sizeof(TObject));
9621  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9622  (strat->tl-atT+1)*sizeof(unsigned long));
9623 #endif
9624  for (i=strat->tl+1; i>=atT+1; i--)
9625  {
9626 #ifndef ENTER_USE_MEMMOVE
9627  strat->T[i] = strat->T[i-1];
9628  strat->sevT[i] = strat->sevT[i-1];
9629 #endif
9630  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9631  }
9632  }
9633 
9634  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9635  {
9636  pNext(p.p)=p_ShallowCopyDelete(pNext(p.p),
9637  (strat->tailRing != NULL ?
9638  strat->tailRing : currRing),
9639  strat->tailBin);
9640  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9641  }
9642  strat->T[atT] = (TObject) p;
9643  #ifdef ADIDEBUG
9644  printf("\nenterT_strong: add in position %i\n",atT);
9645  pWrite(p.p);
9646  #endif
9647  //printf("\nenterT_strong: neue hingefügt: länge = %i, ecart = %i\n",p.length,p.ecart);
9648 
9649  if (pNext(p.p) != NULL)
9650  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9651  else
9652  strat->T[atT].max_exp = NULL;
9653 
9654  strat->tl++;
9655  strat->R[strat->tl] = &(strat->T[atT]);
9656  strat->T[atT].i_r = strat->tl;
9657  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9658  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9659  #if 1
9661  && !n_IsUnit(p.p->coef, currRing->cf))
9662  {
9663  #ifdef ADIDEBUG
9664  printf("\nDas ist p:\n");pWrite(p.p);
9665  #endif
9666  for(i=strat->tl;i>=0;i--)
9667  {
9668  if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9669  {
9670  #ifdef ADIDEBUG
9671  printf("\nFound one: %i\n",i);pWrite(strat->T[i].p);
9672  #endif
9673  enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9674  }
9675  }
9676  }
9677  /*
9678  printf("\nThis is T:\n");
9679  for(i=strat->tl;i>=0;i--)
9680  {
9681  pWrite(strat->T[i].p);
9682  }
9683  //getchar();*/
9684  #endif
9685  kTest_T(&(strat->T[atT]));
9686 }
9687 #endif
9688 
9689 /*2
9690 * puts signature p.sig to the set syz
9691 */
9692 void enterSyz(LObject &p, kStrategy strat, int atT)
9693 {
9694  #ifdef ADIDEBUG
9695  printf("\n Entersyz:\n");pWrite(p.sig);
9696  #endif
9697  int i;
9698  strat->newt = TRUE;
9699  if (strat->syzl == strat->syzmax-1)
9700  {
9701  pEnlargeSet(&strat->syz,strat->syzmax,setmaxTinc);
9702  strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9703  (strat->syzmax)*sizeof(unsigned long),
9704  ((strat->syzmax)+setmaxTinc)
9705  *sizeof(unsigned long));
9706  strat->syzmax += setmaxTinc;
9707  }
9708  if (atT < strat->syzl)
9709  {
9710 #ifdef ENTER_USE_MEMMOVE
9711  memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9712  (strat->syzl-atT+1)*sizeof(poly));
9713  memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9714  (strat->syzl-atT+1)*sizeof(unsigned long));
9715 #endif
9716  for (i=strat->syzl; i>=atT+1; i--)
9717  {
9718 #ifndef ENTER_USE_MEMMOVE
9719  strat->syz[i] = strat->syz[i-1];
9720  strat->sevSyz[i] = strat->sevSyz[i-1];
9721 #endif
9722  }
9723  }
9724  //i = strat->syzl;
9725  i = atT;
9726  //Makes sure the syz saves just the signature
9727  #ifdef HAVE_RINGS
9729  pNext(p.sig) = NULL;
9730  #endif
9731  strat->syz[atT] = p.sig;
9732  strat->sevSyz[atT] = p.sevSig;
9733  strat->syzl++;
9734 #if F5DEBUG
9735  Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9736  pWrite(strat->syz[atT]);
9737 #endif
9738  // recheck pairs in strat->L with new rule and delete correspondingly
9739  int cc = strat->Ll;
9740  while (cc>-1)
9741  {
9742  //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9743  //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);
9744  if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9745  strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9746  #ifdef HAVE_RINGS
9747  &&((!rField_is_Ring(currRing))
9748  || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9749  #endif
9750  )
9751  {
9752  //printf("\nYES!\n");
9753  #ifdef ADIDEBUG
9754  printf("\n syzCrit deleted!\n");pWrite(strat->L[cc].p);pWrite(strat->L[cc].sig);
9755  #endif
9756  deleteInL(strat->L,&strat->Ll,cc,strat);
9757  }
9758  cc--;
9759  }
9760 //#if 1
9761 #ifdef DEBUGF5
9762  PrintS("--- Syzygies ---\n");
9763  Print("syzl %d\n",strat->syzl);
9764  Print("syzmax %d\n",strat->syzmax);
9765  PrintS("--------------------------------\n");
9766  for(i=0;i<=strat->syzl-1;i++)
9767  {
9768  Print("%d - ",i);
9769  pWrite(strat->syz[i]);
9770  }
9771  PrintS("--------------------------------\n");
9772 #endif
9773 }
9774 
9775 
9776 void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9777 {
9778 
9779  //if the ordering is local, then hilb criterion
9780  //can be used also if the ideal is not homogenous
9782  {
9784  *hilb=NULL;
9785  else
9786  return;
9787  }
9788  if (strat->homog!=isHomog)
9789  {
9790  *hilb=NULL;
9791  }
9792 }
9793 
9795 {
9797  strat->chainCrit=chainCritNormal;
9798  if (TEST_OPT_SB_1)
9799  strat->chainCrit=chainCritOpt_1;
9800 #ifdef HAVE_RINGS
9801  if (rField_is_Ring(currRing))
9802  {
9804  strat->chainCrit=chainCritRing;
9805  }
9806 #endif
9807 #ifdef HAVE_RATGRING
9808  if (rIsRatGRing(currRing))
9809  {
9810  strat->chainCrit=chainCritPart;
9811  /* enterOnePairNormal get rational part in it */
9812  }
9813 #endif
9814  if (TEST_OPT_IDLIFT /* i.e. also strat->syzComp==1 */
9815  && (!rIsPluralRing(currRing)))
9817 
9818  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9819  strat->Gebauer = strat->homog || strat->sugarCrit;
9820  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9821  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9822  strat->pairtest = NULL;
9823  /* alway use tailreduction, except:
9824  * - in local rings, - in lex order case, -in ring over extensions */
9826  //if(rHasMixedOrdering(currRing)==2)
9827  //{
9828  // strat->noTailReduction =TRUE;
9829  //}
9830 
9831 #ifdef HAVE_PLURAL
9832  // and r is plural_ring
9833  // hence this holds for r a rational_plural_ring
9834  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9835  { //or it has non-quasi-comm type... later
9836  strat->sugarCrit = FALSE;
9837  strat->Gebauer = FALSE;
9838  strat->honey = FALSE;
9839  }
9840 #endif
9841 
9842  // Coefficient ring?
9843  if (rField_is_Ring(currRing))
9844  {
9845  strat->sugarCrit = FALSE;
9846  strat->Gebauer = FALSE ;
9847  strat->honey = FALSE;
9848  }
9849  #ifdef KDEBUG
9850  if (TEST_OPT_DEBUG)
9851  {
9852  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9853  else PrintS("ideal/module is not homogeneous\n");
9854  }
9855  #endif
9856 }
9857 
9859 {
9860  //strat->enterOnePair=enterOnePairNormal;
9862  //strat->chainCrit=chainCritNormal;
9863  strat->chainCrit = chainCritSig;
9864  /******************************************
9865  * rewCrit1 and rewCrit2 are already set in
9866  * kSba() in kstd1.cc
9867  *****************************************/
9868  //strat->rewCrit1 = faugereRewCriterion;
9869  if (strat->sbaOrder == 1)
9870  {
9871  strat->syzCrit = syzCriterionInc;
9872  }
9873  else
9874  {
9875  strat->syzCrit = syzCriterion;
9876  }
9877 #ifdef HAVE_RINGS
9878  if (rField_is_Ring(currRing))
9879  {
9881  strat->chainCrit=chainCritRing;
9882  }
9883 #endif
9884 #ifdef HAVE_RATGRING
9885  if (rIsRatGRing(currRing))
9886  {
9887  strat->chainCrit=chainCritPart;
9888  /* enterOnePairNormal get rational part in it */
9889  }
9890 #endif
9891 
9892  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9893  strat->Gebauer = strat->homog || strat->sugarCrit;
9894  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9895  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9896  strat->pairtest = NULL;
9897  /* alway use tailreduction, except:
9898  * - in local rings, - in lex order case, -in ring over extensions */
9901 
9902 #ifdef HAVE_PLURAL
9903  // and r is plural_ring
9904  // hence this holds for r a rational_plural_ring
9905  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9906  { //or it has non-quasi-comm type... later
9907  strat->sugarCrit = FALSE;
9908  strat->Gebauer = FALSE;
9909  strat->honey = FALSE;
9910  }
9911 #endif
9912 
9913  // Coefficient ring?
9914  if (rField_is_Ring(currRing))
9915  {
9916  strat->sugarCrit = FALSE;
9917  strat->Gebauer = FALSE ;
9918  strat->honey = FALSE;
9919  }
9920  #ifdef KDEBUG
9921  if (TEST_OPT_DEBUG)
9922  {
9923  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9924  else PrintS("ideal/module is not homogeneous\n");
9925  }
9926  #endif
9927 }
9928 
9930  (const LSet set, const int length,
9931  LObject* L,const kStrategy strat))
9932 {
9933  if (pos_in_l == posInL110
9934  || pos_in_l == posInL10
9935  #ifdef HAVE_RINGS
9936  || pos_in_l == posInL110Ring
9937  || pos_in_l == posInLRing
9938  #endif
9939  )
9940  return TRUE;
9941 
9942  return FALSE;
9943 }
9944 
9946 {
9948  {
9949  if (strat->honey)
9950  {
9951  strat->posInL = posInL15;
9952  // ok -- here is the deal: from my experiments for Singular-2-0
9953  // I conclude that that posInT_EcartpLength is the best of
9954  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9955  // see the table at the end of this file
9956  if (TEST_OPT_OLDSTD)
9957  strat->posInT = posInT15;
9958  else
9959  strat->posInT = posInT_EcartpLength;
9960  }
9961  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9962  {
9963  strat->posInL = posInL11;
9964  strat->posInT = posInT11;
9965  }
9966  else if (TEST_OPT_INTSTRATEGY)
9967  {
9968  strat->posInL = posInL11;
9969  strat->posInT = posInT11;
9970  }
9971  else
9972  {
9973  strat->posInL = posInL0;
9974  strat->posInT = posInT0;
9975  }
9976  //if (strat->minim>0) strat->posInL =posInLSpecial;
9977  if (strat->homog)
9978  {
9979  strat->posInL = posInL110;
9980  strat->posInT = posInT110;
9981  }
9982  }
9983  else
9984  {
9985  if (strat->homog)
9986  {
9987  strat->posInL = posInL11;
9988  strat->posInT = posInT11;
9989  }
9990  else
9991  {
9992  if ((currRing->order[0]==ringorder_c)
9993  ||(currRing->order[0]==ringorder_C))
9994  {
9995  strat->posInL = posInL17_c;
9996  strat->posInT = posInT17_c;
9997  }
9998  else
9999  {
10000  strat->posInL = posInL17;
10001  strat->posInT = posInT17;
10002  }
10003  }
10004  }
10005  if (strat->minim>0) strat->posInL =posInLSpecial;
10006  // for further tests only
10007  if ((BTEST1(11)) || (BTEST1(12)))
10008  strat->posInL = posInL11;
10009  else if ((BTEST1(13)) || (BTEST1(14)))
10010  strat->posInL = posInL13;
10011  else if ((BTEST1(15)) || (BTEST1(16)))
10012  strat->posInL = posInL15;
10013  else if ((BTEST1(17)) || (BTEST1(18)))
10014  strat->posInL = posInL17;
10015  if (BTEST1(11))
10016  strat->posInT = posInT11;
10017  else if (BTEST1(13))
10018  strat->posInT = posInT13;
10019  else if (BTEST1(15))
10020  strat->posInT = posInT15;
10021  else if ((BTEST1(17)))
10022  strat->posInT = posInT17;
10023  else if ((BTEST1(19)))
10024  strat->posInT = posInT19;
10025  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10026  strat->posInT = posInT1;
10028 }
10029 
10030 #ifdef HAVE_RINGS
10032 {
10034  {
10035  if (strat->honey)
10036  {
10037  strat->posInL = posInL15Ring;
10038  // ok -- here is the deal: from my experiments for Singular-2-0
10039  // I conclude that that posInT_EcartpLength is the best of
10040  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10041  // see the table at the end of this file
10042  if (TEST_OPT_OLDSTD)
10043  strat->posInT = posInT15Ring;
10044  else
10045  strat->posInT = posInT_EcartpLength;
10046  }
10047  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10048  {
10049  strat->posInL = posInL11Ring;
10050  strat->posInT = posInT11;
10051  }
10052  else if (TEST_OPT_INTSTRATEGY)
10053  {
10054  strat->posInL = posInL11Ring;
10055  strat->posInT = posInT11;
10056  }
10057  else
10058  {
10059  strat->posInL = posInL0Ring;
10060  strat->posInT = posInT0;
10061  }
10062  //if (strat->minim>0) strat->posInL =posInLSpecial;
10063  if (strat->homog)
10064  {
10065  strat->posInL = posInL110Ring;
10066  strat->posInT = posInT110Ring;
10067  }
10068  }
10069  else
10070  {
10071  if (strat->homog)
10072  {
10073  //printf("\nHere 3\n");
10074  strat->posInL = posInL11Ring;
10075  strat->posInT = posInT11Ring;
10076  }
10077  else
10078  {
10079  if ((currRing->order[0]==ringorder_c)
10080  ||(currRing->order[0]==ringorder_C))
10081  {
10082  strat->posInL = posInL17_cRing;
10083  strat->posInT = posInT17_cRing;
10084  }
10085  else
10086  {
10087  strat->posInL = posInL11Ringls;
10088  strat->posInT = posInT17Ring;
10089  }
10090  }
10091  }
10092  if (strat->minim>0) strat->posInL =posInLSpecial;
10093  // for further tests only
10094  if ((BTEST1(11)) || (BTEST1(12)))
10095  strat->posInL = posInL11Ring;
10096  else if ((BTEST1(13)) || (BTEST1(14)))
10097  strat->posInL = posInL13;
10098  else if ((BTEST1(15)) || (BTEST1(16)))
10099  strat->posInL = posInL15Ring;
10100  else if ((BTEST1(17)) || (BTEST1(18)))
10101  strat->posInL = posInL17Ring;
10102  if (BTEST1(11))
10103  strat->posInT = posInT11Ring;
10104  else if (BTEST1(13))
10105  strat->posInT = posInT13;
10106  else if (BTEST1(15))
10107  strat->posInT = posInT15Ring;
10108  else if ((BTEST1(17)))
10109  strat->posInT = posInT17Ring;
10110  else if ((BTEST1(19)))
10111  strat->posInT = posInT19;
10112  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10113  strat->posInT = posInT1;
10115 }
10116 #endif
10117 
10118 void initBuchMora (ideal F,ideal Q,kStrategy strat)
10119 {
10120  strat->interpt = BTEST1(OPT_INTERRUPT);
10121  strat->kHEdge=NULL;
10123  /*- creating temp data structures------------------- -*/
10124  strat->cp = 0;
10125  strat->c3 = 0;
10126  strat->tail = pInit();
10127  /*- set s -*/
10128  strat->sl = -1;
10129  /*- set L -*/
10130  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10131  strat->Ll = -1;
10132  strat->L = initL(((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc);
10133  /*- set B -*/
10134  strat->Bmax = setmaxL;
10135  strat->Bl = -1;
10136  strat->B = initL();
10137  /*- set T -*/
10138  strat->tl = -1;
10139  strat->tmax = setmaxT;
10140  strat->T = initT();
10141  strat->R = initR();
10142  strat->sevT = initsevT();
10143  /*- init local data struct.---------------------------------------- -*/
10144  strat->P.ecart=0;
10145  strat->P.length=0;
10146  strat->P.pLength=0;
10148  {
10149  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
10150  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
10151  }
10153  {
10154  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10155  }
10156  else
10157  {
10158  if(TEST_OPT_SB_1)
10159  {
10160  int i;
10161  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10162  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10163  {
10164  P->m[i-strat->newIdeal] = F->m[i];
10165  F->m[i] = NULL;
10166  }
10167  initSSpecial(F,Q,P,strat);
10168  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10169  {
10170  F->m[i] = P->m[i-strat->newIdeal];
10171  P->m[i-strat->newIdeal] = NULL;
10172  }
10173  idDelete(&P);
10174  }
10175  else
10176  {
10177  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10178  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
10179  }
10180  }
10181  strat->fromT = FALSE;
10183  if ((!TEST_OPT_SB_1)
10184  || (rField_is_Ring(currRing))
10185  )
10186  {
10187  updateS(TRUE,strat);
10188  }
10189  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10190  strat->fromQ=NULL;
10191  assume(kTest_TS(strat));
10192 }
10193 
10195 {
10196  /*- release temp data -*/
10197  cleanT(strat);
10198  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10199  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10200  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10201  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10202  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10203  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10204  /*- set L: should be empty -*/
10205  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10206  /*- set B: should be empty -*/
10207  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10208  pLmDelete(&strat->tail);
10209  strat->syzComp=0;
10210 }
10211 
10212 void initSbaPos (kStrategy strat)
10213 {
10215  {
10216  if (strat->honey)
10217  {
10218  strat->posInL = posInL15;
10219  // ok -- here is the deal: from my experiments for Singular-2-0
10220  // I conclude that that posInT_EcartpLength is the best of
10221  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10222  // see the table at the end of this file
10223  if (TEST_OPT_OLDSTD)
10224  strat->posInT = posInT15;
10225  else
10226  strat->posInT = posInT_EcartpLength;
10227  }
10228  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10229  {
10230  strat->posInL = posInL11;
10231  strat->posInT = posInT11;
10232  }
10233  else if (TEST_OPT_INTSTRATEGY)
10234  {
10235  strat->posInL = posInL11;
10236  strat->posInT = posInT11;
10237  }
10238  else
10239  {
10240  strat->posInL = posInL0;
10241  strat->posInT = posInT0;
10242  }
10243  //if (strat->minim>0) strat->posInL =posInLSpecial;
10244  if (strat->homog)
10245  {
10246  strat->posInL = posInL110;
10247  strat->posInT = posInT110;
10248  }
10249  }
10250  else
10251  {
10252  if (strat->homog)
10253  {
10254  strat->posInL = posInL11;
10255  strat->posInT = posInT11;
10256  }
10257  else
10258  {
10259  if ((currRing->order[0]==ringorder_c)
10260  ||(currRing->order[0]==ringorder_C))
10261  {
10262  strat->posInL = posInL17_c;
10263  strat->posInT = posInT17_c;
10264  }
10265  else
10266  {
10267  strat->posInL = posInL17;
10268  strat->posInT = posInT17;
10269  }
10270  }
10271  }
10272  if (strat->minim>0) strat->posInL =posInLSpecial;
10273  // for further tests only
10274  if ((BTEST1(11)) || (BTEST1(12)))
10275  strat->posInL = posInL11;
10276  else if ((BTEST1(13)) || (BTEST1(14)))
10277  strat->posInL = posInL13;
10278  else if ((BTEST1(15)) || (BTEST1(16)))
10279  strat->posInL = posInL15;
10280  else if ((BTEST1(17)) || (BTEST1(18)))
10281  strat->posInL = posInL17;
10282  if (BTEST1(11))
10283  strat->posInT = posInT11;
10284  else if (BTEST1(13))
10285  strat->posInT = posInT13;
10286  else if (BTEST1(15))
10287  strat->posInT = posInT15;
10288  else if ((BTEST1(17)))
10289  strat->posInT = posInT17;
10290  else if ((BTEST1(19)))
10291  strat->posInT = posInT19;
10292  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10293  strat->posInT = posInT1;
10294  if (rField_is_Ring(currRing))
10295  {
10296  strat->posInL = posInL11Ring;
10297  if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
10298  strat->posInL = posInL11Ringls;
10299  strat->posInT = posInT11;
10300  }
10301  strat->posInLDependsOnLength = FALSE;
10302  strat->posInLSba = posInLSig;
10303  //strat->posInL = posInLSig;
10304  strat->posInL = posInLF5C;
10305  /*
10306  if (rField_is_Ring(currRing))
10307  {
10308  strat->posInLSba = posInLSigRing;
10309  strat->posInL = posInL11Ring;
10310  }*/
10311  //strat->posInT = posInTSig;
10312 }
10313 
10314 void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10315 {
10316  strat->interpt = BTEST1(OPT_INTERRUPT);
10317  strat->kHEdge=NULL;
10319  /*- creating temp data structures------------------- -*/
10320  strat->cp = 0;
10321  strat->c3 = 0;
10322  strat->tail = pInit();
10323  /*- set s -*/
10324  strat->sl = -1;
10325  /*- set ps -*/
10326  strat->syzl = -1;
10327  /*- set L -*/
10328  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10329  strat->Ll = -1;
10330  strat->L = initL(((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc);
10331  /*- set B -*/
10332  strat->Bmax = setmaxL;
10333  strat->Bl = -1;
10334  strat->B = initL();
10335  /*- set T -*/
10336  strat->tl = -1;
10337  strat->tmax = setmaxT;
10338  strat->T = initT();
10339  strat->R = initR();
10340  strat->sevT = initsevT();
10341  /*- init local data struct.---------------------------------------- -*/
10342  strat->P.ecart=0;
10343  strat->P.length=0;
10345  {
10346  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
10347  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
10348  }
10350  {
10351  /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10352  }
10353  else
10354  {
10355  if(TEST_OPT_SB_1)
10356  {
10357  int i;
10358  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10359  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10360  {
10361  P->m[i-strat->newIdeal] = F->m[i];
10362  F->m[i] = NULL;
10363  }
10364  initSSpecialSba(F,Q,P,strat);
10365  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10366  {
10367  F->m[i] = P->m[i-strat->newIdeal];
10368  P->m[i-strat->newIdeal] = NULL;
10369  }
10370  idDelete(&P);
10371  }
10372  else
10373  {
10374  initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10375  }
10376  }
10377  strat->fromT = FALSE;
10378  if (!TEST_OPT_SB_1)
10379  {
10380  if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10381  }
10382  //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10383  //strat->fromQ=NULL;
10384  assume(kTest_TS(strat));
10385 }
10386 
10387 void exitSba (kStrategy strat)
10388 {
10389  /*- release temp data -*/
10391  cleanTSbaRing(strat);
10392  else
10393  cleanT(strat);
10394  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10395  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10396  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10397  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10398  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10399  omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10400  if(strat->syzmax>0)
10401  {
10402  omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10403  omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10404  if (strat->sbaOrder == 1)
10405  {
10406  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10407  }
10408  }
10409  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10410  /*- set L: should be empty -*/
10411  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10412  /*- set B: should be empty -*/
10413  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10414  /*- set sig: no need for the signatures anymore -*/
10415  omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10416  pLmDelete(&strat->tail);
10417  strat->syzComp=0;
10418 }
10419 
10420 /*2
10421 * in the case of a standardbase of a module over a qring:
10422 * replace polynomials in i by ak vectors,
10423 * (the polynomial * unit vectors gen(1)..gen(ak)
10424 * in every case (also for ideals:)
10425 * deletes divisible vectors/polynomials
10426 */
10427 void updateResult(ideal r,ideal Q, kStrategy strat)
10428 {
10429  int l;
10430  if (strat->ak>0)
10431  {
10432  for (l=IDELEMS(r)-1;l>=0;l--)
10433  {
10434  if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10435  {
10436  pDelete(&r->m[l]); // and set it to NULL
10437  }
10438  }
10439  int q;
10440  poly p;
10441  if(!rField_is_Ring(currRing))
10442  {
10443  for (l=IDELEMS(r)-1;l>=0;l--)
10444  {
10445  if ((r->m[l]!=NULL)
10446  //&& (strat->syzComp>0)
10447  //&& (pGetComp(r->m[l])<=strat->syzComp)
10448  )
10449  {
10450  for(q=IDELEMS(Q)-1; q>=0;q--)
10451  {
10452  if ((Q->m[q]!=NULL)
10453  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10454  {
10455  if (TEST_OPT_REDSB)
10456  {
10457  p=r->m[l];
10458  r->m[l]=kNF(Q,NULL,p);
10459  pDelete(&p);
10460  }
10461  else
10462  {
10463  pDelete(&r->m[l]); // and set it to NULL
10464  }
10465  break;
10466  }
10467  }
10468  }
10469  }
10470  }
10471  #ifdef HAVE_RINGS
10472  else
10473  {
10474  for (l=IDELEMS(r)-1;l>=0;l--)
10475  {
10476  if ((r->m[l]!=NULL)
10477  //&& (strat->syzComp>0)
10478  //&& (pGetComp(r->m[l])<=strat->syzComp)
10479  )
10480  {
10481  for(q=IDELEMS(Q)-1; q>=0;q--)
10482  {
10483  if ((Q->m[q]!=NULL)
10484  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10485  {
10486  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10487  {
10488  if (TEST_OPT_REDSB)
10489  {
10490  p=r->m[l];
10491  r->m[l]=kNF(Q,NULL,p);
10492  pDelete(&p);
10493  }
10494  else
10495  {
10496  pDelete(&r->m[l]); // and set it to NULL
10497  }
10498  break;
10499  }
10500  }
10501  }
10502  }
10503  }
10504  }
10505  #endif
10506  }
10507  else
10508  {
10509  int q;
10510  poly p;
10511  BOOLEAN reduction_found=FALSE;
10512  if (!rField_is_Ring(currRing))
10513  {
10514  for (l=IDELEMS(r)-1;l>=0;l--)
10515  {
10516  if (r->m[l]!=NULL)
10517  {
10518  for(q=IDELEMS(Q)-1; q>=0;q--)
10519  {
10520  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10521  {
10522  if (TEST_OPT_REDSB)
10523  {
10524  p=r->m[l];
10525  r->m[l]=kNF(Q,NULL,p);
10526  pDelete(&p);
10527  reduction_found=TRUE;
10528  }
10529  else
10530  {
10531  pDelete(&r->m[l]); // and set it to NULL
10532  }
10533  break;
10534  }
10535  }
10536  }
10537  }
10538  }
10539  #ifdef HAVE_RINGS
10540  //Also need divisibility of the leading coefficients
10541  else
10542  {
10543  for (l=IDELEMS(r)-1;l>=0;l--)
10544  {
10545  if (r->m[l]!=NULL)
10546  {
10547  for(q=IDELEMS(Q)-1; q>=0;q--)
10548  {
10549  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10550  {
10551  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10552  {
10553  if (TEST_OPT_REDSB)
10554  {
10555  p=r->m[l];
10556  r->m[l]=kNF(Q,NULL,p);
10557  pDelete(&p);
10558  reduction_found=TRUE;
10559  }
10560  else
10561  {
10562  pDelete(&r->m[l]); // and set it to NULL
10563  }
10564  break;
10565  }
10566  }
10567  }
10568  }
10569  }
10570  }
10571  #endif
10572  if (/*TEST_OPT_REDSB &&*/ reduction_found)
10573  {
10574  #ifdef HAVE_RINGS
10576  {
10577  for (l=IDELEMS(r)-1;l>=0;l--)
10578  {
10579  if (r->m[l]!=NULL)
10580  {
10581  for(q=IDELEMS(r)-1;q>=0;q--)
10582  {
10583  if ((l!=q)
10584  && (r->m[q]!=NULL)
10585  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10586  &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10587  )
10588  {
10589  //If they are equal then take the one with the smallest length
10590  if(pLmDivisibleBy(r->m[q],r->m[l])
10591  && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10592  && (pLength(r->m[q]) < pLength(r->m[l]) ||
10593  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10594  {
10595  pDelete(&r->m[l]);
10596  break;
10597  }
10598  else
10599  pDelete(&r->m[q]);
10600  }
10601  }
10602  }
10603  }
10604  }
10605  else
10606  #endif
10607  {
10608  for (l=IDELEMS(r)-1;l>=0;l--)
10609  {
10610  if (r->m[l]!=NULL)
10611  {
10612  for(q=IDELEMS(r)-1;q>=0;q--)
10613  {
10614  if ((l!=q)
10615  && (r->m[q]!=NULL)
10616  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10617  )
10618  {
10619  //If they are equal then take the one with the smallest length
10620  if(pLmDivisibleBy(r->m[q],r->m[l])
10621  &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10622  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10623  {
10624  pDelete(&r->m[l]);
10625  break;
10626  }
10627  else
10628  pDelete(&r->m[q]);
10629  }
10630  }
10631  }
10632  }
10633  }
10634  }
10635  }
10636  idSkipZeroes(r);
10637 }
10638 
10639 void completeReduce (kStrategy strat, BOOLEAN withT)
10640 {
10641  int i;
10642  int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10643  LObject L;
10644 
10645 #ifdef KDEBUG
10646  // need to set this: during tailreductions of T[i], T[i].max is out of
10647  // sync
10648  sloppy_max = TRUE;
10649 #endif
10650 
10651  strat->noTailReduction = FALSE;
10652  //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10653  if (TEST_OPT_PROT)
10654  {
10655  PrintLn();
10656 // if (timerv) writeTime("standard base computed:");
10657  }
10658  if (TEST_OPT_PROT)
10659  {
10660  Print("(S:%d)",strat->sl);mflush();
10661  }
10662  for (i=strat->sl; i>=low; i--)
10663  {
10664  int end_pos=strat->sl;
10665  if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10666  if (strat->ak==0) end_pos=i-1;
10667  TObject* T_j = strat->s_2_t(i);
10668  if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10669  {
10670  L = *T_j;
10671  #ifdef KDEBUG
10672  if (TEST_OPT_DEBUG)
10673  {
10674  Print("test S[%d]:",i);
10675  p_wrp(L.p,currRing,strat->tailRing);
10676  PrintLn();
10677  }
10678  #endif
10680  strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10681  else
10682  strat->S[i] = redtail(&L, strat->sl, strat);
10683  #ifdef KDEBUG
10684  if (TEST_OPT_DEBUG)
10685  {
10686  Print("to (tailR) S[%d]:",i);
10687  p_wrp(strat->S[i],currRing,strat->tailRing);
10688  PrintLn();
10689  }
10690  #endif
10691 
10692  if (strat->redTailChange)
10693  {
10694  if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10695  if (pNext(T_j->p) != NULL)
10696  T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10697  else
10698  T_j->max_exp = NULL;
10699  }
10701  T_j->pCleardenom();
10702  }
10703  else
10704  {
10705  assume(currRing == strat->tailRing);
10706  #ifdef KDEBUG
10707  if (TEST_OPT_DEBUG)
10708  {
10709  Print("test S[%d]:",i);
10710  p_wrp(strat->S[i],currRing,strat->tailRing);
10711  PrintLn();
10712  }
10713  #endif
10715  strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10716  else
10717  strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10719  {
10720  if (TEST_OPT_CONTENTSB)
10721  {
10722  number n;
10723  p_Cleardenom_n(strat->S[i], currRing, n);// also does a pContent
10724  if (!nIsOne(n))
10725  {
10727  denom->n=nInvers(n);
10728  denom->next=DENOMINATOR_LIST;
10729  DENOMINATOR_LIST=denom;
10730  }
10731  nDelete(&n);
10732  }
10733  else
10734  {
10735  //pContent(strat->S[i]);
10736  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does a pContent
10737  }
10738  }
10739  #ifdef KDEBUG
10740  if (TEST_OPT_DEBUG)
10741  {
10742  Print("to (-tailR) S[%d]:",i);
10743  p_wrp(strat->S[i],currRing,strat->tailRing);
10744  PrintLn();
10745  }
10746  #endif
10747  }
10748  if (TEST_OPT_PROT)
10749  PrintS("-");
10750  }
10751  if (TEST_OPT_PROT) PrintLn();
10752 #ifdef KDEBUG
10753  sloppy_max = FALSE;
10754 #endif
10755 }
10756 
10757 
10758 /*2
10759 * computes the new strat->kHEdge and the new pNoether,
10760 * returns TRUE, if pNoether has changed
10761 */
10763 {
10764  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10765  return FALSE;
10766  int i,j;
10767  poly newNoether;
10768 
10769 #if 0
10770  if (currRing->weight_all_1)
10771  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10772  else
10773  scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10774 #else
10775  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10776 #endif
10777  if (strat->kHEdge==NULL) return FALSE;
10778  if (strat->t_kHEdge != NULL) p_LmFree(strat->t_kHEdge, strat->tailRing);
10779  if (strat->tailRing != currRing)
10780  strat->t_kHEdge = k_LmInit_currRing_2_tailRing(strat->kHEdge, strat->tailRing);
10781  /* compare old and new noether*/
10782  newNoether = pLmInit(strat->kHEdge);
10783  j = p_FDeg(newNoether,currRing);
10784  for (i=1; i<=(currRing->N); i++)
10785  {
10786  if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
10787  }
10788  pSetm(newNoether);
10789  if (j < strat->HCord) /*- statistics -*/
10790  {
10791  if (TEST_OPT_PROT)
10792  {
10793  Print("H(%d)",j);
10794  mflush();
10795  }
10796  strat->HCord=j;
10797  #ifdef KDEBUG
10798  if (TEST_OPT_DEBUG)
10799  {
10800  Print("H(%d):",j);
10801  wrp(strat->kHEdge);
10802  PrintLn();
10803  }
10804  #endif
10805  }
10806  if (pCmp(strat->kNoether,newNoether)!=1)
10807  {
10808  pDelete(&strat->kNoether);
10809  strat->kNoether=newNoether;
10810  if (strat->t_kNoether != NULL) p_LmFree(strat->t_kNoether, strat->tailRing);
10811  if (strat->tailRing != currRing)
10812  strat->t_kNoether = k_LmInit_currRing_2_tailRing(strat->kNoether, strat->tailRing);
10813 
10814  return TRUE;
10815  }
10816  if (rField_is_Ring(currRing))
10817  pLmDelete(newNoether);
10818  else
10819  pLmFree(newNoether);
10820  return FALSE;
10821 }
10822 
10823 /***************************************************************
10824  *
10825  * Routines related for ring changes during std computations
10826  *
10827  ***************************************************************/
10829 {
10830  if (strat->overflow) return FALSE;
10831  assume(L->p1 != NULL && L->p2 != NULL);
10832  // shift changes: from 0 to -1
10833  assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10834  assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10835  assume(strat->tailRing != currRing);
10836 
10837  if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10838  return FALSE;
10839  // shift changes: extra case inserted
10840  if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10841  {
10842  return TRUE;
10843  }
10844  poly p1_max = (strat->R[L->i_r1])->max_exp;
10845  poly p2_max = (strat->R[L->i_r2])->max_exp;
10846 
10847  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10848  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10849  {
10850  p_LmFree(m1, strat->tailRing);
10851  p_LmFree(m2, strat->tailRing);
10852  m1 = NULL;
10853  m2 = NULL;
10854  return FALSE;
10855  }
10856  return TRUE;
10857 }
10858 
10859 #ifdef HAVE_RINGS
10860 /***************************************************************
10861  *
10862  * Checks, if we can compute the gcd poly / strong pair
10863  * gcd-poly = m1 * R[atR] + m2 * S[atS]
10864  *
10865  ***************************************************************/
10866 BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10867 {
10868  assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10869  //assume(strat->tailRing != currRing);
10870 
10871  poly p1_max = (strat->R[atR])->max_exp;
10872  poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10873 
10874  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10875  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10876  {
10877  return FALSE;
10878  }
10879  return TRUE;
10880 }
10881 #endif
10882 
10883 #ifdef HAVE_RINGS
10884 /*!
10885  used for GB over ZZ: look for constant and monomial elements in the ideal
10886  background: any known constant element of ideal suppresses
10887  intermediate coefficient swell
10888 */
10889 poly preIntegerCheck(const ideal Forig, const ideal Q)
10890 {
10892  if(!nCoeff_is_Ring_Z(currRing->cf))
10893  return NULL;
10894  ideal F = idCopy(Forig);
10895  idSkipZeroes(F);
10896  poly pmon;
10897  ring origR = currRing;
10898  ideal monred = idInit(1,1);
10899  for(int i=0; i<idElem(F); i++)
10900  {
10901  if(pNext(F->m[i]) == NULL)
10902  idInsertPoly(monred, pCopy(F->m[i]));
10903  }
10904  int posconst = idPosConstant(F);
10905  if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10906  {
10907  idDelete(&F);
10908  idDelete(&monred);
10909  return NULL;
10910  }
10911  int idelemQ = 0;
10912  if(Q!=NULL)
10913  {
10914  idelemQ = IDELEMS(Q);
10915  for(int i=0; i<idelemQ; i++)
10916  {
10917  if(pNext(Q->m[i]) == NULL)
10918  idInsertPoly(monred, pCopy(Q->m[i]));
10919  }
10920  idSkipZeroes(monred);
10921  posconst = idPosConstant(monred);
10922  //the constant, if found, will be from Q
10923  if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10924  {
10925  pmon = pCopy(monred->m[posconst]);
10926  idDelete(&F);
10927  idDelete(&monred);
10928  return pmon;
10929  }
10930  }
10931  ring QQ_ring = rCopy0(currRing,FALSE);
10932  nKillChar(QQ_ring->cf);
10933  QQ_ring->cf = nInitChar(n_Q, NULL);
10934  rComplete(QQ_ring,1);
10935  QQ_ring = rAssure_c_dp(QQ_ring);
10936  rChangeCurrRing(QQ_ring);
10937  nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10938  ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10939  for(int i = 0, j = 0; i<IDELEMS(F); i++)
10940  II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10941  for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10942  II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10943  ideal one = kStd(II, NULL, isNotHomog, NULL);
10944  idSkipZeroes(one);
10945  if(idIsConstant(one))
10946  {
10947  //one should be <1>
10948  for(int i = IDELEMS(II)-1; i>=0; i--)
10949  if(II->m[i] != NULL)
10950  II->m[i+1] = II->m[i];
10951  II->m[0] = pOne();
10952  ideal syz = idSyzygies(II, isNotHomog, NULL);
10953  poly integer = NULL;
10954  for(int i = IDELEMS(syz)-1;i>=0; i--)
10955  {
10956  if(pGetComp(syz->m[i]) == 1)
10957  {
10958  pSetComp(syz->m[i],0);
10959  if(pIsConstant(pHead(syz->m[i])))
10960  {
10961  integer = pHead(syz->m[i]);
10962  break;
10963  }
10964  }
10965  }
10966  rChangeCurrRing(origR);
10967  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10968  pmon = prMapR(integer, nMap2, QQ_ring, origR);
10969  idDelete(&monred);
10970  idDelete(&F);
10971  id_Delete(&II,QQ_ring);
10972  id_Delete(&one,QQ_ring);
10973  id_Delete(&syz,QQ_ring);
10974  p_Delete(&integer,QQ_ring);
10975  rDelete(QQ_ring);
10976  return pmon;
10977  }
10978  else
10979  {
10980  if(idIs0(monred))
10981  {
10982  poly mindegmon = NULL;
10983  for(int i = 0; i<IDELEMS(one); i++)
10984  {
10985  if(pNext(one->m[i]) == NULL)
10986  {
10987  if(mindegmon == NULL)
10988  mindegmon = pCopy(one->m[i]);
10989  else
10990  {
10991  if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10992  mindegmon = pCopy(one->m[i]);
10993  }
10994  }
10995  }
10996  if(mindegmon != NULL)
10997  {
10998  for(int i = IDELEMS(II)-1; i>=0; i--)
10999  if(II->m[i] != NULL)
11000  II->m[i+1] = II->m[i];
11001  II->m[0] = pCopy(mindegmon);
11002  ideal syz = idSyzygies(II, isNotHomog, NULL);
11003  bool found = FALSE;
11004  for(int i = IDELEMS(syz)-1;i>=0; i--)
11005  {
11006  if(pGetComp(syz->m[i]) == 1)
11007  {
11008  pSetComp(syz->m[i],0);
11009  if(pIsConstant(pHead(syz->m[i])))
11010  {
11011  pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
11012  found = TRUE;
11013  break;
11014  }
11015  }
11016  }
11017  id_Delete(&syz,QQ_ring);
11018  if (found == FALSE)
11019  {
11020  rChangeCurrRing(origR);
11021  idDelete(&monred);
11022  idDelete(&F);
11023  id_Delete(&II,QQ_ring);
11024  id_Delete(&one,QQ_ring);
11025  rDelete(QQ_ring);
11026  return NULL;
11027  }
11028  rChangeCurrRing(origR);
11029  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
11030  pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
11031  idDelete(&monred);
11032  idDelete(&F);
11033  id_Delete(&II,QQ_ring);
11034  id_Delete(&one,QQ_ring);
11035  id_Delete(&syz,QQ_ring);
11036  rDelete(QQ_ring);
11037  return pmon;
11038  }
11039  }
11040  }
11041  rChangeCurrRing(origR);
11042  idDelete(&monred);
11043  idDelete(&F);
11044  id_Delete(&II,QQ_ring);
11045  id_Delete(&one,QQ_ring);
11046  rDelete(QQ_ring);
11047  return NULL;
11048 }
11049 #endif
11050 
11051 #ifdef HAVE_RINGS
11052 /*!
11053  used for GB over ZZ: intermediate reduction by monomial elements
11054  background: any known constant element of ideal suppresses
11055  intermediate coefficient swell
11056 */
11058 {
11059  if(!nCoeff_is_Ring_Z(currRing->cf))
11060  return;
11061  poly pH = h->GetP();
11062  poly p,pp;
11063  p = pH;
11064  bool deleted = FALSE, ok = FALSE;
11065  for(int i = 0; i<=strat->sl; i++)
11066  {
11067  p = pH;
11068  if(pNext(strat->S[i]) == NULL)
11069  {
11070  //pWrite(p);
11071  //pWrite(strat->S[i]);
11072  while(ok == FALSE && p != NULL)
11073  {
11074  if(pLmDivisibleBy(strat->S[i], p))
11075  {
11076  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11077  p_SetCoeff(p,dummy,currRing);
11078  }
11079  if(nIsZero(p->coef))
11080  {
11081  pLmDelete(&p);
11082  h->p = p;
11083  deleted = TRUE;
11084  }
11085  else
11086  {
11087  ok = TRUE;
11088  }
11089  }
11090  if (p!=NULL)
11091  {
11092  pp = pNext(p);
11093  while(pp != NULL)
11094  {
11095  if(pLmDivisibleBy(strat->S[i], pp))
11096  {
11097  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11098  p_SetCoeff(pp,dummy,currRing);
11099  if(nIsZero(pp->coef))
11100  {
11101  pLmDelete(&pNext(p));
11102  pp = pNext(p);
11103  deleted = TRUE;
11104  }
11105  else
11106  {
11107  p = pp;
11108  pp = pNext(p);
11109  }
11110  }
11111  else
11112  {
11113  p = pp;
11114  pp = pNext(p);
11115  }
11116  }
11117  }
11118  }
11119  }
11120  h->SetLmCurrRing();
11121  if((deleted)&&(h->p!=NULL))
11122  strat->initEcart(h);
11123 }
11124 
11126 {
11127  if(!nCoeff_is_Ring_Z(currRing->cf))
11128  return;
11129  poly hSig = h->sig;
11130  poly pH = h->GetP();
11131  poly p,pp;
11132  p = pH;
11133  bool deleted = FALSE, ok = FALSE;
11134  for(int i = 0; i<=strat->sl; i++)
11135  {
11136  p = pH;
11137  if(pNext(strat->S[i]) == NULL)
11138  {
11139  while(ok == FALSE && p!=NULL)
11140  {
11141  if(pLmDivisibleBy(strat->S[i], p))
11142  {
11143  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11144  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11145  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11146  {
11147  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11148  p_SetCoeff(p,dummy,currRing);
11149  }
11150  pDelete(&sigMult);
11151  }
11152  if(nIsZero(p->coef))
11153  {
11154  pLmDelete(&p);
11155  h->p = p;
11156  deleted = TRUE;
11157  }
11158  else
11159  {
11160  ok = TRUE;
11161  }
11162  }
11163  if(p == NULL)
11164  return;
11165  pp = pNext(p);
11166  while(pp != NULL)
11167  {
11168  if(pLmDivisibleBy(strat->S[i], pp))
11169  {
11170  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11171  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11172  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11173  {
11174  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11175  p_SetCoeff(pp,dummy,currRing);
11176  if(nIsZero(pp->coef))
11177  {
11178  pLmDelete(&pNext(p));
11179  pp = pNext(p);
11180  deleted = TRUE;
11181  }
11182  else
11183  {
11184  p = pp;
11185  pp = pNext(p);
11186  }
11187  }
11188  else
11189  {
11190  p = pp;
11191  pp = pNext(p);
11192  }
11193  pDelete(&sigMult);
11194  }
11195  else
11196  {
11197  p = pp;
11198  pp = pNext(p);
11199  }
11200  }
11201  }
11202  }
11203  h->SetLmCurrRing();
11204  if(deleted)
11205  strat->initEcart(h);
11206 
11207 }
11208 
11209 /*!
11210  used for GB over ZZ: final reduction by constant elements
11211  background: any known constant element of ideal suppresses
11212  intermediate coefficient swell and beautifies output
11213 */
11215 {
11216  if(!nCoeff_is_Ring_Z(currRing->cf))
11217  return;
11218  poly p,pp;
11219  for(int j = 0; j<=strat->sl; j++)
11220  {
11221  if((strat->S[j]!=NULL)&&(pNext(strat->S[j]) == NULL))
11222  {
11223  for(int i = 0; i<=strat->sl; i++)
11224  {
11225  if((i != j) && (strat->S[i] != NULL))
11226  {
11227  p = strat->S[i];
11228  if(pLmDivisibleBy(strat->S[j], p))
11229  {
11230  number dummy = n_IntMod(p->coef, strat->S[j]->coef, currRing->cf);
11231  p_SetCoeff(p,dummy,currRing);
11232  }
11233  pp = pNext(p);
11234  if((pp == NULL) && (nIsZero(p->coef)))
11235  {
11236  deleteInS(i, strat);
11237  }
11238  else
11239  {
11240  while(pp != NULL)
11241  {
11242  if(pLmDivisibleBy(strat->S[j], pp))
11243  {
11244  number dummy = n_IntMod(pp->coef, strat->S[j]->coef, currRing->cf);
11245  p_SetCoeff(pp,dummy,currRing);
11246  if(nIsZero(pp->coef))
11247  {
11248  pLmDelete(&pNext(p));
11249  pp = pNext(p);
11250  }
11251  else
11252  {
11253  p = pp;
11254  pp = pNext(p);
11255  }
11256  }
11257  else
11258  {
11259  p = pp;
11260  pp = pNext(p);
11261  }
11262  }
11263  }
11264  if(strat->S[i]!= NULL && nIsZero(pGetCoeff(strat->S[i])))
11265  {
11266  if(pNext(strat->S[i]) == NULL)
11267  strat->S[i]=NULL;
11268  else
11269  strat->S[i]=pNext(strat->S[i]);
11270  }
11271  }
11272  }
11273  //idPrint(strat->Shdl);
11274  }
11275  }
11276  //idSkipZeroes(strat->Shdl);
11277 }
11278 #endif
11279 
11280 BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
11281 {
11282  assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11283  /* initial setup or extending */
11284 
11285  if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11286  if (expbound >= currRing->bitmask) return FALSE;
11287  strat->overflow=FALSE;
11288  ring new_tailRing = rModifyRing(currRing,
11289  // Hmmm .. the condition pFDeg == p_Deg
11290  // might be too strong
11291  (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11292  (strat->ak==0), // omit_comp if the input is an ideal
11293  expbound); // exp_limit
11294 
11295  if (new_tailRing == currRing) return TRUE;
11296 
11297  strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11298  strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11299 
11300  if (currRing->pFDeg != currRing->pFDegOrig)
11301  {
11302  new_tailRing->pFDeg = currRing->pFDeg;
11303  new_tailRing->pLDeg = currRing->pLDeg;
11304  }
11305 
11306  if (TEST_OPT_PROT)
11307  Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11308  kTest_TS(strat);
11309  assume(new_tailRing != strat->tailRing);
11310  pShallowCopyDeleteProc p_shallow_copy_delete
11311  = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11312 
11313  omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11314 
11315  int i;
11316  for (i=0; i<=strat->tl; i++)
11317  {
11318  strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11319  p_shallow_copy_delete);
11320  }
11321  for (i=0; i<=strat->Ll; i++)
11322  {
11323  assume(strat->L[i].p != NULL);
11324  if (pNext(strat->L[i].p) != strat->tail)
11325  strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11326  }
11327  if ((strat->P.t_p != NULL) ||
11328  ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11329  strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11330 
11331  if ((L != NULL) && (L->tailRing != new_tailRing))
11332  {
11333  if (L->i_r < 0)
11334  L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11335  else
11336  {
11337  assume(L->i_r <= strat->tl);
11338  TObject* t_l = strat->R[L->i_r];
11339  assume(t_l != NULL);
11340  L->tailRing = new_tailRing;
11341  L->p = t_l->p;
11342  L->t_p = t_l->t_p;
11343  L->max_exp = t_l->max_exp;
11344  }
11345  }
11346 
11347  if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11348  T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11349 
11350  omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11351  if (strat->tailRing != currRing)
11352  rKillModifiedRing(strat->tailRing);
11353 
11354  strat->tailRing = new_tailRing;
11355  strat->tailBin = new_tailBin;
11356  strat->p_shallow_copy_delete
11357  = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11358 
11359  if (strat->kHEdge != NULL)
11360  {
11361  if (strat->t_kHEdge != NULL)
11362  p_LmFree(strat->t_kHEdge, strat->tailRing);
11363  strat->t_kHEdge=k_LmInit_currRing_2_tailRing(strat->kHEdge, new_tailRing);
11364  }
11365 
11366  if (strat->kNoether != NULL)
11367  {
11368  if (strat->t_kNoether != NULL)
11369  p_LmFree(strat->t_kNoether, strat->tailRing);
11371  new_tailRing);
11372  }
11373  kTest_TS(strat);
11374  if (TEST_OPT_PROT)
11375  PrintS("]");
11376  return TRUE;
11377 }
11378 
11380 {
11381  unsigned long l = 0;
11382  int i;
11383  long e;
11384 
11385  assume(strat->tailRing == currRing);
11386 
11387  for (i=0; i<= strat->Ll; i++)
11388  {
11389  l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11390  }
11391  for (i=0; i<=strat->tl; i++)
11392  {
11393  // Hmm ... this we could do in one Step
11394  l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11395  }
11396  if (rField_is_Ring(currRing))
11397  {
11398  l *= 2;
11399  }
11400  e = p_GetMaxExp(l, currRing);
11401  if (e <= 1) e = 2;
11402 
11403  kStratChangeTailRing(strat, NULL, NULL, e);
11404 }
11405 
11406 ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11407 {
11408  int n = rBlocks(r); // Including trailing zero!
11409  // if sbaOrder == 1 => use (C,monomial order from r)
11410  if (strat->sbaOrder == 1)
11411  {
11412  if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11413  {
11414  return r;
11415  }
11416  ring res = rCopy0(r, TRUE, FALSE);
11417  res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11418  res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11419  res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11420  int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11421  res->wvhdl = wvhdl;
11422  for (int i=1; i<n; i++)
11423  {
11424  res->order[i] = r->order[i-1];
11425  res->block0[i] = r->block0[i-1];
11426  res->block1[i] = r->block1[i-1];
11427  res->wvhdl[i] = r->wvhdl[i-1];
11428  }
11429 
11430  // new 1st block
11431  res->order[0] = ringorder_C; // Prefix
11432  // removes useless secondary component order if defined in old ring
11433  for (int i=rBlocks(res); i>0; --i)
11434  {
11435  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11436  {
11437  res->order[i] = (rRingOrder_t)0;
11438  }
11439  }
11440  rComplete(res, 1);
11441 #ifdef HAVE_PLURAL
11442  if (rIsPluralRing(r))
11443  {
11444  if ( nc_rComplete(r, res, false) ) // no qideal!
11445  {
11446 #ifndef SING_NDEBUG
11447  WarnS("error in nc_rComplete");
11448 #endif
11449  // cleanup?
11450 
11451  // rDelete(res);
11452  // return r;
11453 
11454  // just go on..
11455  }
11456  }
11457 #endif
11458  strat->tailRing = res;
11459  return (res);
11460  }
11461  // if sbaOrder == 3 => degree - position - ring order
11462  if (strat->sbaOrder == 3)
11463  {
11464  ring res = rCopy0(r, TRUE, FALSE);
11465  res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11466  res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11467  res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11468  int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11469  res->wvhdl = wvhdl;
11470  for (int i=2; i<n+2; i++)
11471  {
11472  res->order[i] = r->order[i-2];
11473  res->block0[i] = r->block0[i-2];
11474  res->block1[i] = r->block1[i-2];
11475  res->wvhdl[i] = r->wvhdl[i-2];
11476  }
11477 
11478  // new 1st block
11479  res->order[0] = ringorder_a; // Prefix
11480  res->block0[0] = 1;
11481  res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11482  for (int i=0; i<res->N; ++i)
11483  res->wvhdl[0][i] = 1;
11484  res->block1[0] = si_min(res->N, rVar(res));
11485  // new 2nd block
11486  res->order[1] = ringorder_C; // Prefix
11487  res->wvhdl[1] = NULL;
11488  // removes useless secondary component order if defined in old ring
11489  for (int i=rBlocks(res); i>1; --i)
11490  {
11491  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11492  {
11493  res->order[i] = (rRingOrder_t)0;
11494  }
11495  }
11496  rComplete(res, 1);
11497 #ifdef HAVE_PLURAL
11498  if (rIsPluralRing(r))
11499  {
11500  if ( nc_rComplete(r, res, false) ) // no qideal!
11501  {
11502 #ifndef SING_NDEBUG
11503  WarnS("error in nc_rComplete");
11504 #endif
11505  // cleanup?
11506 
11507  // rDelete(res);
11508  // return r;
11509 
11510  // just go on..
11511  }
11512  }
11513 #endif
11514  strat->tailRing = res;
11515  return (res);
11516  }
11517 
11518  // not sbaOrder == 1 => use Schreyer order
11519  // this is done by a trick when initializing the signatures
11520  // in initSLSba():
11521  // Instead of using the signature 1e_i for F->m[i], we start
11522  // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11523  // Schreyer order w.r.t. the underlying monomial order.
11524  // => we do not need to change the underlying polynomial ring at all!
11525 
11526  // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11527 
11528  /*
11529  else
11530  {
11531  ring res = rCopy0(r, FALSE, FALSE);
11532  // Create 2 more blocks for prefix/suffix:
11533  res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11534  res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11535  res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11536  int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11537 
11538  // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11539  // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11540 
11541  // new 1st block
11542  int j = 0;
11543  res->order[j] = ringorder_IS; // Prefix
11544  res->block0[j] = res->block1[j] = 0;
11545  // wvhdl[j] = NULL;
11546  j++;
11547 
11548  for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11549  {
11550  res->order [j] = r->order [i];
11551  res->block0[j] = r->block0[i];
11552  res->block1[j] = r->block1[i];
11553 
11554  if (r->wvhdl[i] != NULL)
11555  {
11556  wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11557  } // else wvhdl[j] = NULL;
11558  }
11559 
11560  // new last block
11561  res->order [j] = ringorder_IS; // Suffix
11562  res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11563  // wvhdl[j] = NULL;
11564  j++;
11565 
11566  // res->order [j] = 0; // The End!
11567  res->wvhdl = wvhdl;
11568 
11569  // j == the last zero block now!
11570  assume(j == (n+1));
11571  assume(res->order[0]==ringorder_IS);
11572  assume(res->order[j-1]==ringorder_IS);
11573  assume(res->order[j]==0);
11574 
11575  if (complete)
11576  {
11577  rComplete(res, 1);
11578 
11579 #ifdef HAVE_PLURAL
11580  if (rIsPluralRing(r))
11581  {
11582  if ( nc_rComplete(r, res, false) ) // no qideal!
11583  {
11584  }
11585  }
11586  assume(rIsPluralRing(r) == rIsPluralRing(res));
11587 #endif
11588 
11589 
11590 #ifdef HAVE_PLURAL
11591  ring old_ring = r;
11592 
11593 #endif
11594 
11595  if (r->qideal!=NULL)
11596  {
11597  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11598 
11599  assume(idRankFreeModule(res->qideal, res) == 0);
11600 
11601 #ifdef HAVE_PLURAL
11602  if( rIsPluralRing(res) )
11603  if( nc_SetupQuotient(res, r, true) )
11604  {
11605  // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11606  }
11607 
11608 #endif
11609  assume(idRankFreeModule(res->qideal, res) == 0);
11610  }
11611 
11612 #ifdef HAVE_PLURAL
11613  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11614  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11615  assume(rIsSCA(res) == rIsSCA(old_ring));
11616  assume(ncRingType(res) == ncRingType(old_ring));
11617 #endif
11618  }
11619  strat->tailRing = res;
11620  return res;
11621  }
11622  */
11623 
11624  assume(FALSE);
11625  return(NULL);
11626 }
11627 
11629 {
11630  memset(this, 0, sizeof(skStrategy));
11631  strat_nr++;
11632  nr=strat_nr;
11633  tailRing = currRing;
11634  P.tailRing = currRing;
11635  tl = -1;
11636  sl = -1;
11637 #ifdef HAVE_LM_BIN
11638  lmBin = omGetStickyBinOfBin(currRing->PolyBin);
11639 #endif
11640 #ifdef HAVE_TAIL_BIN
11641  tailBin = omGetStickyBinOfBin(currRing->PolyBin);
11642 #endif
11643  pOrigFDeg = currRing->pFDeg;
11644  pOrigLDeg = currRing->pLDeg;
11645 }
11646 
11647 
11649 {
11650  if (lmBin != NULL)
11651  omMergeStickyBinIntoBin(lmBin, currRing->PolyBin);
11652  if (tailBin != NULL)// && !rField_is_Ring(currRing))
11653  omMergeStickyBinIntoBin(tailBin,
11654  (tailRing != NULL ? tailRing->PolyBin:
11655  currRing->PolyBin));
11656  if (t_kHEdge != NULL)
11657  p_LmFree(t_kHEdge, tailRing);
11658  if (t_kNoether != NULL)
11659  p_LmFree(t_kNoether, tailRing);
11660 
11661  if (currRing != tailRing)
11663  pRestoreDegProcs(currRing,pOrigFDeg, pOrigLDeg);
11664 }
11665 
11666 #if 0
11667 Timings for the different possibilities of posInT:
11668  T15 EDL DL EL L 1-2-3
11669 Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11670 Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11671 Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11672 ahml 4.48 4.03 4.03 4.38 4.96 26.50
11673 c7 15.02 13.98 15.16 13.24 17.31 47.89
11674 c8 505.09 407.46 852.76 413.21 499.19 n/a
11675 f855 12.65 9.27 14.97 8.78 14.23 33.12
11676 gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11677 gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11678 ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11679 noon8 40.68 37.02 37.99 36.82 35.59 877.16
11680 rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11681 rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11682 schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11683 test016 16.39 14.17 14.40 13.50 14.26 34.07
11684 test017 34.70 36.01 33.16 35.48 32.75 71.45
11685 test042 10.76 10.99 10.27 11.57 10.45 23.04
11686 test058 6.78 6.75 6.51 6.95 6.22 9.47
11687 test066 10.71 10.94 10.76 10.61 10.56 19.06
11688 test073 10.75 11.11 10.17 10.79 8.63 58.10
11689 test086 12.23 11.81 12.88 12.24 13.37 66.68
11690 test103 5.05 4.80 5.47 4.64 4.89 11.90
11691 test154 12.96 11.64 13.51 12.46 14.61 36.35
11692 test162 65.27 64.01 67.35 59.79 67.54 196.46
11693 test164 7.50 6.50 7.68 6.70 7.96 17.13
11694 virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11695 #endif
11696 
11697 
11698 //#ifdef HAVE_MORE_POS_IN_T
11699 #if 1
11700 // determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11701 int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p)
11702 {
11703 
11704  if (length==-1) return 0;
11705 
11706  int o = p.ecart;
11707  int op=p.GetpFDeg();
11708  int ol = p.GetpLength();
11709 
11710  if (set[length].ecart < o)
11711  return length+1;
11712  if (set[length].ecart == o)
11713  {
11714  int oo=set[length].GetpFDeg();
11715  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11716  return length+1;
11717  }
11718 
11719  int i;
11720  int an = 0;
11721  int en= length;
11722  loop
11723  {
11724  if (an >= en-1)
11725  {
11726  if (set[an].ecart > o)
11727  return an;
11728  if (set[an].ecart == o)
11729  {
11730  int oo=set[an].GetpFDeg();
11731  if((oo > op)
11732  || ((oo==op) && (set[an].pLength > ol)))
11733  return an;
11734  }
11735  return en;
11736  }
11737  i=(an+en) / 2;
11738  if (set[i].ecart > o)
11739  en=i;
11740  else if (set[i].ecart == o)
11741  {
11742  int oo=set[i].GetpFDeg();
11743  if ((oo > op)
11744  || ((oo == op) && (set[i].pLength > ol)))
11745  en=i;
11746  else
11747  an=i;
11748  }
11749  else
11750  an=i;
11751  }
11752 }
11753 
11754 // determines the position based on: 1.) FDeg 2.) pLength
11755 int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11756 {
11757 
11758  if (length==-1) return 0;
11759 
11760  int op=p.GetpFDeg();
11761  int ol = p.GetpLength();
11762 
11763  int oo=set[length].GetpFDeg();
11764  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11765  return length+1;
11766 
11767  int i;
11768  int an = 0;
11769  int en= length;
11770  loop
11771  {
11772  if (an >= en-1)
11773  {
11774  int oo=set[an].GetpFDeg();
11775  if((oo > op)
11776  || ((oo==op) && (set[an].pLength > ol)))
11777  return an;
11778  return en;
11779  }
11780  i=(an+en) / 2;
11781  int oo=set[i].GetpFDeg();
11782  if ((oo > op)
11783  || ((oo == op) && (set[i].pLength > ol)))
11784  en=i;
11785  else
11786  an=i;
11787  }
11788 }
11789 
11790 
11791 // determines the position based on: 1.) pLength
11792 int posInT_pLength(const TSet set,const int length,LObject &p)
11793 {
11794  int ol = p.GetpLength();
11795  if (length==-1)
11796  return 0;
11797  if (set[length].length<p.length)
11798  return length+1;
11799 
11800  int i;
11801  int an = 0;
11802  int en= length;
11803 
11804  loop
11805  {
11806  if (an >= en-1)
11807  {
11808  if (set[an].pLength>ol) return an;
11809  return en;
11810  }
11811  i=(an+en) / 2;
11812  if (set[i].pLength>ol) en=i;
11813  else an=i;
11814  }
11815 }
11816 #endif
11817 
11818 // kstd1.cc:
11819 int redFirst (LObject* h,kStrategy strat);
11820 int redEcart (LObject* h,kStrategy strat);
11821 void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11822 void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11823 // ../Singular/misc.cc:
11824 extern char * showOption();
11825 
11827 {
11828  PrintS("red: ");
11829  if (strat->red==redFirst) PrintS("redFirst\n");
11830  else if (strat->red==redHoney) PrintS("redHoney\n");
11831  else if (strat->red==redEcart) PrintS("redEcart\n");
11832  else if (strat->red==redHomog) PrintS("redHomog\n");
11833  else Print("%p\n",(void*)strat->red);
11834  PrintS("posInT: ");
11835  if (strat->posInT==posInT0) PrintS("posInT0\n");
11836  else if (strat->posInT==posInT1) PrintS("posInT1\n");
11837  else if (strat->posInT==posInT11) PrintS("posInT11\n");
11838  else if (strat->posInT==posInT110) PrintS("posInT110\n");
11839  else if (strat->posInT==posInT13) PrintS("posInT13\n");
11840  else if (strat->posInT==posInT15) PrintS("posInT15\n");
11841  else if (strat->posInT==posInT17) PrintS("posInT17\n");
11842  else if (strat->posInT==posInT17_c) PrintS("posInT17_c\n");
11843  else if (strat->posInT==posInT19) PrintS("posInT19\n");
11844  else if (strat->posInT==posInT2) PrintS("posInT2\n");
11845  #ifdef HAVE_RINGS
11846  else if (strat->posInT==posInT11Ring) PrintS("posInT11Ring\n");
11847  else if (strat->posInT==posInT110Ring) PrintS("posInT110Ring\n");
11848  else if (strat->posInT==posInT15Ring) PrintS("posInT15Ring\n");
11849  else if (strat->posInT==posInT17Ring) PrintS("posInT17Ring\n");
11850  else if (strat->posInT==posInT17_cRing) PrintS("posInT17_cRing\n");
11851  #endif
11852 #ifdef HAVE_MORE_POS_IN_T
11853  else if (strat->posInT==posInT_EcartFDegpLength) PrintS("posInT_EcartFDegpLength\n");
11854  else if (strat->posInT==posInT_FDegpLength) PrintS("posInT_FDegpLength\n");
11855  else if (strat->posInT==posInT_pLength) PrintS("posInT_pLength\n");
11856 #endif
11857  else if (strat->posInT==posInT_EcartpLength) PrintS("posInT_EcartpLength\n");
11858  else if (strat->posInT==posInTrg0) PrintS("posInTrg0\n");
11859  else Print("%p\n",(void*)strat->posInT);
11860  PrintS("posInL: ");
11861  if (strat->posInL==posInL0) PrintS("posInL0\n");
11862  else if (strat->posInL==posInL10) PrintS("posInL10\n");
11863  else if (strat->posInL==posInL11) PrintS("posInL11\n");
11864  else if (strat->posInL==posInL110) PrintS("posInL110\n");
11865  else if (strat->posInL==posInL13) PrintS("posInL13\n");
11866  else if (strat->posInL==posInL15) PrintS("posInL15\n");
11867  else if (strat->posInL==posInL17) PrintS("posInL17\n");
11868  else if (strat->posInL==posInL17_c) PrintS("posInL17_c\n");
11869  #ifdef HAVE_RINGS
11870  else if (strat->posInL==posInL0) PrintS("posInL0Ring\n");
11871  else if (strat->posInL==posInL11Ring) PrintS("posInL11Ring\n");
11872  else if (strat->posInL==posInL11Ringls) PrintS("posInL11Ringls\n");
11873  else if (strat->posInL==posInL110Ring) PrintS("posInL110Ring\n");
11874  else if (strat->posInL==posInL15Ring) PrintS("posInL15Ring\n");
11875  else if (strat->posInL==posInL17Ring) PrintS("posInL17Ring\n");
11876  else if (strat->posInL==posInL17_cRing) PrintS("posInL17_cRing\n");
11877  #endif
11878  else if (strat->posInL==posInLSpecial) PrintS("posInLSpecial\n");
11879  else if (strat->posInL==posInLrg0) PrintS("posInLrg0\n");
11880  else Print("%p\n",(void*)strat->posInL);
11881  PrintS("enterS: ");
11882  if (strat->enterS==enterSBba) PrintS("enterSBba\n");
11883  else if (strat->enterS==enterSMora) PrintS("enterSMora\n");
11884  else if (strat->enterS==enterSMoraNF) PrintS("enterSMoraNF\n");
11885  else Print("%p\n",(void*)strat->enterS);
11886  PrintS("initEcart: ");
11887  if (strat->initEcart==initEcartBBA) PrintS("initEcartBBA\n");
11888  else if (strat->initEcart==initEcartNormal) PrintS("initEcartNormal\n");
11889  else Print("%p\n",(void*)strat->initEcart);
11890  PrintS("initEcartPair: ");
11891  if (strat->initEcartPair==initEcartPairBba) PrintS("initEcartPairBba\n");
11892  else if (strat->initEcartPair==initEcartPairMora) PrintS("initEcartPairMora\n");
11893  else Print("%p\n",(void*)strat->initEcartPair);
11894  Print("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11895  strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11896  Print("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11897  strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11898  PrintS("chainCrit: ");
11899  if (strat->chainCrit==chainCritNormal) PrintS("chainCritNormal\n");
11900  else if (strat->chainCrit==chainCritOpt_1) PrintS("chainCritOpt_1\n");
11901  else Print("%p\n",(void*)strat->chainCrit);
11902  Print("posInLDependsOnLength=%d\n",
11903  strat->posInLDependsOnLength);
11904  PrintS(showOption());PrintLn();
11905  PrintS("LDeg: ");
11906  if (currRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11907  else if (currRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11908  else if (currRing->pLDeg==pLDegb) PrintS("pLDegb");
11909  else if (currRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11910  else if (currRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11911  else if (currRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11912  else if (currRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11913  else if (currRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11914  else if (currRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11915  else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11916  else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11917  else if (currRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11918  else Print("? (%lx)", (long)currRing->pLDeg);
11919  PrintS(" / ");
11920  if (strat->tailRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11921  else if (strat->tailRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11922  else if (strat->tailRing->pLDeg==pLDegb) PrintS("pLDegb");
11923  else if (strat->tailRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11924  else if (strat->tailRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11925  else if (strat->tailRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11926  else if (strat->tailRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11927  else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11928  else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11929  else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11930  else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11931  else if (strat->tailRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11932  else Print("? (%lx)", (long)strat->tailRing->pLDeg);
11933  PrintLn();
11934  PrintS("currRing->pFDeg: ");
11935  if (currRing->pFDeg==p_Totaldegree) PrintS("p_Totaldegree");
11936  else if (currRing->pFDeg==p_WFirstTotalDegree) PrintS("pWFirstTotalDegree");
11937  else if (currRing->pFDeg==p_Deg) PrintS("p_Deg");
11938  else if (currRing->pFDeg==kHomModDeg) PrintS("kHomModDeg");
11939  else if (currRing->pFDeg==totaldegreeWecart) PrintS("totaldegreeWecart");
11940  else if (currRing->pFDeg==p_WTotaldegree) PrintS("p_WTotaldegree");
11941  else Print("? (%lx)", (long)currRing->pFDeg);
11942  PrintLn();
11943  Print(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11944  if(TEST_OPT_DEGBOUND)
11945  Print(" degBound: %d\n", Kstd1_deg);
11946 
11947  if( ecartWeights != NULL )
11948  {
11949  PrintS("ecartWeights: ");
11950  for (int i = rVar(currRing); i > 0; i--)
11951  Print("%hd ", ecartWeights[i]);
11952  PrintLn();
11954  }
11955 
11956 #ifndef SING_NDEBUG
11958 #endif
11959 }
11960 
11961 #ifdef HAVE_SHIFTBBA
11963 {
11964  /* assume: p is completely in currRing */
11965  /* produces an object with LM in curring
11966  and TAIL in tailring */
11967  if (pNext(p)!=NULL)
11968  {
11969  pNext(p) = prMoveR(pNext(p), /* src */ currRing, /* dest */ strat->tailRing);
11970  }
11971  return(p);
11972 }
11973 #endif
11974 
11975 #ifdef HAVE_SHIFTBBA
11977 {
11978  /* assume: p has LM in curring and TAIL in tailring */
11979  /* convert it to complete currRing */
11980 
11981  /* check that LM is in currRing */
11983 
11984  if (pNext(p)!=NULL)
11985  {
11986  pNext(p) = prMoveR(pNext(p), /* src */ strat->tailRing, /* dest */currRing);
11987  }
11988  return(p);
11989 }
11990 #endif
11991 
11992 #ifdef HAVE_SHIFTBBA
11994 {
11995  /* restores a poly in currRing from LObject */
11996  LObject h = H;
11997  h.Copy();
11998  poly p;
11999  if (h.p == NULL)
12000  {
12001  if (h.t_p != NULL)
12002  {
12003  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing, /* dest. ring: */ currRing);
12004  return(p);
12005  }
12006  else
12007  {
12008  /* h.tp == NULL -> the object is NULL */
12009  return(NULL);
12010  }
12011  }
12012  /* we're here if h.p != NULL */
12013  if (h.t_p == NULL)
12014  {
12015  /* then h.p is the whole poly in currRing */
12016  p = h.p;
12017  return(p);
12018  }
12019  /* we're here if h.p != NULL and h.t_p != NULL */
12020  // clean h.p, get poly from t_p
12021  pNext(h.p)=NULL;
12022  pLmDelete(&h.p);
12023  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing,
12024  /* dest. ring: */ currRing);
12025  // no need to clean h: we re-used the polys
12026  return(p);
12027 }
12028 #endif
12029 
12030 //LObject pCopyp2L(poly p, kStrategy strat)
12031 //{
12032  /* creates LObject from the poly in currRing */
12033  /* actually put p into L.p and make L.t_p=NULL : does not work */
12034 
12035 //}
12036 
12037 // poly pCopyL2p(LObject H, kStrategy strat)
12038 // {
12039 // /* restores a poly in currRing from LObject */
12040 // LObject h = H;
12041 // h.Copy();
12042 // poly p;
12043 // if (h.p == NULL)
12044 // {
12045 // if (h.t_p != NULL)
12046 // {
12047 // p = p_ShallowCopyDelete(h.t_p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12048 // return(p);
12049 // }
12050 // else
12051 // {
12052 // /* h.tp == NULL -> the object is NULL */
12053 // return(NULL);
12054 // }
12055 // }
12056 // /* we're here if h.p != NULL */
12057 
12058 // if (h.t_p == NULL)
12059 // {
12060 // /* then h.p is the whole poly in tailRing */
12061 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12062 // {
12063 // p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12064 // }
12065 // return(p);
12066 // }
12067 // /* we're here if h.p != NULL and h.t_p != NULL */
12068 // p = pCopy(pHead(h.p)); // in currRing
12069 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12070 // {
12071 // // pNext(p) = p_ShallowCopyDelete(pNext(h.t_p), (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12072 // poly pp = p_Copy(pNext(h.p), strat->tailRing);
12073 // // poly p3 = p_Copy(pNext(h.p), currRing); // error
12074 // // p_ShallowCopyDelete(pNext(h.p), currRing, strat->tailBin); // the same as pp
12075 // poly p5 = p_ShallowCopyDelete(pNext(h.p), strat->tailRing, strat->tailBin);
12076 // pNext(p) = p_ShallowCopyDelete(h.t_p, strat->tailRing, strat->tailBin);
12077 // poly p4 = p_Copy(h.t_p, strat->tailRing);
12078 // // if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
12079 // }
12080 // // pTest(p);
12081 // return(p);
12082 // }
12083 
12084 #ifdef HAVE_SHIFTBBA
12085 /* including the self pairs */
12086 void updateSShift(kStrategy strat,int uptodeg,int lV)
12087 {
12088  /* to use after updateS(toT=FALSE,strat) */
12089  /* fills T with shifted elt's of S */
12090  int i;
12091  LObject h;
12092  int atT = -1; // or figure out smth better
12093  strat->tl = -1; // init
12094  for (i=0; i<=strat->sl; i++)
12095  {
12096  memset(&h,0,sizeof(h));
12097  h.p = strat->S[i]; // lm in currRing, tail in TR
12098  strat->initEcart(&h);
12099  h.sev = strat->sevS[i];
12100  h.t_p = NULL;
12101  h.GetTP(); // creates correct t_p
12102  /*puts the elements of S with their shifts to T*/
12103  // int atT, int uptodeg, int lV)
12104  strat->S_2_R[i] = strat->tl + 1; // the el't with shift 0 will be inserted first
12105  // need a small check for above; we insert >=1 elements
12106  // insert this check into kTest_TS ?
12107  enterTShift(h,strat,atT,uptodeg,lV);
12108  }
12109  /* what about setting strat->tl? */
12110 }
12111 #endif
12112 
12113 #ifdef HAVE_SHIFTBBA
12114 void initBuchMoraShift (ideal F,ideal Q,kStrategy strat)
12115 {
12116  strat->interpt = BTEST1(OPT_INTERRUPT);
12117  strat->kHEdge=NULL;
12119  /*- creating temp data structures------------------- -*/
12120  strat->cp = 0;
12121  strat->c3 = 0;
12122  strat->cv = 0;
12123  strat->tail = pInit();
12124  /*- set s -*/
12125  strat->sl = -1;
12126  /*- set L -*/
12127  strat->Lmax = setmaxL;
12128  strat->Ll = -1;
12129  strat->L = initL();
12130  /*- set B -*/
12131  strat->Bmax = setmaxL;
12132  strat->Bl = -1;
12133  strat->B = initL();
12134  /*- set T -*/
12135  strat->tl = -1;
12136  strat->tmax = setmaxT;
12137  strat->T = initT();
12138  strat->R = initR();
12139  strat->sevT = initsevT();
12140  /*- init local data struct.---------------------------------------- -*/
12141  strat->P.ecart=0;
12142  strat->P.length=0;
12144  {
12145  if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak);
12146  if (strat->kNoether!=NULL) pSetComp(strat->kNoetherTail(), strat->ak);
12147  }
12149  {
12150  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
12151  }
12152  {
12153  if(TEST_OPT_SB_1)
12154  {
12155  int i;
12156  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
12157  for (i=strat->newIdeal;i<IDELEMS(F);i++)
12158  {
12159  P->m[i-strat->newIdeal] = F->m[i];
12160  F->m[i] = NULL;
12161  }
12162  initSSpecial(F,Q,P,strat);
12163  for (i=strat->newIdeal;i<IDELEMS(F);i++)
12164  {
12165  F->m[i] = P->m[i-strat->newIdeal];
12166  P->m[i-strat->newIdeal] = NULL;
12167  }
12168  idDelete(&P);
12169  }
12170  else
12171  {
12172  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
12173  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
12174  }
12175  }
12176  strat->fromT = FALSE;
12177  if (!TEST_OPT_SB_1)
12178  {
12179  /* the only change: we do not fill the set T*/
12180  if(!rField_is_Ring(currRing)) updateS(FALSE,strat);
12181  }
12182  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
12183  strat->fromQ=NULL;
12184  /* more changes: fill the set T with all the shifts of elts of S*/
12185  /* is done by other procedure */
12186 }
12187 #endif
12188 
12189 #ifdef HAVE_SHIFTBBA
12190 /*1
12191 * put the pairs (sh \dot s[i],p) into the set B, ecart=ecart(p)
12192 */
12193 static void enterOnePairManyShifts (int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
12194 {
12195  /* p comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12196 
12198  assume(p_CheckIsFromRing(pNext(p),strat->tailRing));
12199 
12200  /* cycles through all shifts of s[i] until uptodeg - lastVblock(s[i]) */
12201  /* that is create the pairs (f, s \dot g) */
12202 
12203  poly qq = strat->S[i]; // lm in currRing, tail in tailRing
12204 
12205  // poly q = pCopy(pHead(strat->S[i])); // lm in currRing
12206  // pNext(q) = prCopyR(pNext(strat->S[i]),strat->tailRing,currRing); // zero shift
12207 
12208  /* determine how many elements we have to insert for a given s[i] */
12209  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12210  /* hence, a total number of elt's to add is: */
12211  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12212  int toInsert = itoInsert(qq, uptodeg, lV, strat->tailRing);
12213 
12214 #ifdef KDEBUG
12215  if (TEST_OPT_DEBUG)
12216  {
12217  // Print("entered ManyShifts: with toInsert=%d",toInsert); PrintLn();
12218  }
12219 #endif
12220 
12221  assume(i<=strat->sl); // from OnePair
12222 
12223  /* these vars hold for all shifts of s[i] */
12224  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12225 
12226  int qfromQ;
12227  if (strat->fromQ != NULL)
12228  {
12229  qfromQ = strat->fromQ[i];
12230  }
12231  else
12232  {
12233  qfromQ = -1;
12234  }
12235 
12236  int j;
12237 
12238  poly q/*, s*/;
12239 
12240  // for the 0th shift: insert the orig. pair
12241  enterOnePairShift(qq, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, 0, i, uptodeg, lV);
12242 
12243  for (j=1; j<= toInsert; j++)
12244  {
12245  // q = pLPshift(strat->S[i],j,uptodeg,lV);
12246  q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing);
12247  // q = p_mLPshift(qq,j,uptodeg,lV,currRing); // lm in currRing, shift this monomial
12248  // s = p_LPshift(pNext(qq), j, uptodeg, lV, strat->tailRing); // from tailRing
12249  // pNext(q) = s; // in tailRing
12250  /* here we need to call enterOnePair with two polys ... */
12251 
12252 #ifdef KDEBUG
12253  //if (TEST_OPT_DEBUG)
12254  //{
12255  // PrintS("ManyShifts: calling enterOnePairShift(q,p)"); PrintLn();
12256  //}
12257 #endif
12258  //kFindInTShift(q,atR,strat);
12259  enterOnePairShift(q, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, j, i, uptodeg, lV);
12260  }
12261 }
12262 #endif
12263 
12264 #ifdef HAVE_SHIFTBBA
12265 /*1
12266 * put the pairs (sh \dot qq,p) into the set B, ecart=ecart(p)
12267 * despite the name, not only self shifts
12268 */
12269 void enterOnePairSelfShifts (poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int /*atR*/, int uptodeg, int lV)
12270 {
12271 
12272  /* format: p,qq are in LObject form: lm in CR, tail in TR */
12273  /* for true self pairs qq ==p */
12274  /* we test both qq and p */
12276  assume(p_CheckIsFromRing(pNext(qq),strat->tailRing));
12278  assume(p_CheckIsFromRing(pNext(p),strat->tailRing));
12279 
12280  /* since this proc is applied twice for (h, s*g) and (g,s*h), init j with 1 only */
12281 
12282  // int j = 0;
12283  int j = 1;
12284 
12285  /* for such self pairs start with 1, not with 0 */
12286  if (qq == p) j=1;
12287 
12288  /* should cycle through all shifts of q until uptodeg - lastVblock(q) */
12289  /* that is create the pairs (f, s \dot g) */
12290 
12291  int toInsert = itoInsert(qq, uptodeg, lV, strat->tailRing);
12292 
12293 #ifdef KDEBUG
12294  //if (TEST_OPT_DEBUG)
12295  //{
12296  // Print("entered SelfShifts: with toInsert=%d",toInsert); PrintLn();
12297  //}
12298 #endif
12299 
12300  poly q;
12301 
12302  /* these vars hold for all shifts of s[i] */
12303  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12304  int qfromQ = 0; // strat->fromQ[i];
12305 
12306  for (; j<= toInsert; j++)
12307  {
12308  // q = pLPshift(strat->S[i],j,uptodeg,lV);
12309  /* we increase shifts by one; must delete q there*/
12310  // q = qq; q = pMoveCurrTail2poly(q,strat);
12311  // q = pLPshift(q,j,uptodeg,lV); //,currRing);
12312  q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing);
12313  // q = p_mLPshift(qq,j,uptodeg,lV,currRing); // lm in currRing, shift this monomial
12314  // s = p_LPshift(pNext(qq), j, uptodeg, lV, strat->tailRing); // from tailRing
12315  // pNext(q) = s; // in tailRing
12316  /* here we need to call enterOnePair with two polys ... */
12317 #ifdef KDEBUG
12318  //if (TEST_OPT_DEBUG)
12319  //{
12320  // PrintS("SelfShifts: calling enterOnePairShift(q,p)"); PrintLn();
12321  //}
12322 #endif
12323  enterOnePairShift(q, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, j, -1, uptodeg, lV);
12324  }
12325 }
12326 #endif
12327 
12328 #ifdef HAVE_SHIFTBBA
12329 /*2
12330 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12331 */
12332 void enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS, int /*uptodeg*/, int lV)
12333 {
12334 
12335  /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12336 
12337  /* check this Formats: */
12339  assume(p_CheckIsFromRing(pNext(q),strat->tailRing));
12341  assume(p_CheckIsFromRing(pNext(p),strat->tailRing));
12342 
12343 #ifdef KDEBUG
12344 // if (TEST_OPT_DEBUG)
12345 // {
12346 // PrintS("enterOnePairShift(q,p) invoked with q = ");
12347 // wrp(q); // wrp(pHead(q));
12348 // PrintS(", p = ");
12349 // wrp(p); //wrp(pHead(p));
12350 // PrintLn();
12351 // }
12352 #endif
12353 
12354  /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12355 
12356  int qfromQ = qisFromQ;
12357 
12358  /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12359 
12360  int l,j,compare;
12361  LObject Lp;
12362  Lp.i_r = -1;
12363 
12364 #ifdef KDEBUG
12365  Lp.ecart=0; Lp.length=0;
12366 #endif
12367  /*- computes the lcm(s[i],p) -*/
12368  Lp.lcm = pInit();
12369 
12370  pLcm(p,q, Lp.lcm); // q is what was strat->S[i], so a poly in LM/TR presentation
12371  pSetm(Lp.lcm);
12372 
12373  /* apply the V criterion */
12374  if (!isInV(Lp.lcm, lV))
12375  {
12376 #ifdef KDEBUG
12377  if (TEST_OPT_DEBUG)
12378  {
12379  PrintS("V crit applied to q = ");
12380  wrp(q); // wrp(pHead(q));
12381  PrintS(", p = ");
12382  wrp(p); //wrp(pHead(p));
12383  PrintLn();
12384  }
12385 #endif
12386  pLmFree(Lp.lcm);
12387  Lp.lcm=NULL;
12388  /* + counter for applying the V criterion */
12389  strat->cv++;
12390  return;
12391  }
12392 
12393  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12394  {
12395  if((!((ecartq>0)&&(ecart>0)))
12396  && pHasNotCF(p,q))
12397  {
12398  /*
12399  *the product criterion has applied for (s,p),
12400  *i.e. lcm(s,p)=product of the leading terms of s and p.
12401  *Suppose (s,r) is in L and the leading term
12402  *of p divides lcm(s,r)
12403  *(==> the leading term of p divides the leading term of r)
12404  *but the leading term of s does not divide the leading term of r
12405  *(notice that this condition is automatically satisfied if r is still
12406  *in S), then (s,r) can be cancelled.
12407  *This should be done here because the
12408  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12409  *
12410  *Moreover, skipping (s,r) holds also for the noncommutative case.
12411  */
12412  strat->cp++;
12413  pLmFree(Lp.lcm);
12414  Lp.lcm=NULL;
12415  return;
12416  }
12417  else
12418  Lp.ecart = si_max(ecart,ecartq);
12419  if (strat->fromT && (ecartq>ecart))
12420  {
12421  pLmFree(Lp.lcm);
12422  Lp.lcm=NULL;
12423  return;
12424  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12425  }
12426  /*
12427  *the set B collects the pairs of type (S[j],p)
12428  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12429  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12430  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12431  */
12432  {
12433  j = strat->Bl;
12434  loop
12435  {
12436  if (j < 0) break;
12437  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12438  if ((compare==1)
12439  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12440  {
12441  strat->c3++;
12442  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12443  {
12444  pLmFree(Lp.lcm);
12445  return;
12446  }
12447  break;
12448  }
12449  else
12450  if ((compare ==-1)
12451  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12452  {
12453  deleteInL(strat->B,&strat->Bl,j,strat);
12454  strat->c3++;
12455  }
12456  j--;
12457  }
12458  }
12459  }
12460  else /*sugarcrit*/
12461  {
12462  if (ALLOW_PROD_CRIT(strat))
12463  {
12464  // if currRing->nc_type!=quasi (or skew)
12465  // TODO: enable productCrit for super commutative algebras...
12466  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12467  pHasNotCF(p,q))
12468  {
12469  /*
12470  *the product criterion has applied for (s,p),
12471  *i.e. lcm(s,p)=product of the leading terms of s and p.
12472  *Suppose (s,r) is in L and the leading term
12473  *of p devides lcm(s,r)
12474  *(==> the leading term of p devides the leading term of r)
12475  *but the leading term of s does not devide the leading term of r
12476  *(notice that tis condition is automatically satisfied if r is still
12477  *in S), then (s,r) can be canceled.
12478  *This should be done here because the
12479  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12480  */
12481  strat->cp++;
12482  pLmFree(Lp.lcm);
12483  Lp.lcm=NULL;
12484  return;
12485  }
12486  if (strat->fromT && (ecartq>ecart))
12487  {
12488  pLmFree(Lp.lcm);
12489  Lp.lcm=NULL;
12490  return;
12491  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12492  }
12493  /*
12494  *the set B collects the pairs of type (S[j],p)
12495  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12496  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12497  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12498  */
12499  for(j = strat->Bl;j>=0;j--)
12500  {
12501  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12502  if (compare==1)
12503  {
12504  strat->c3++;
12505  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12506  {
12507  pLmFree(Lp.lcm);
12508  return;
12509  }
12510  break;
12511  }
12512  else
12513  if (compare ==-1)
12514  {
12515  deleteInL(strat->B,&strat->Bl,j,strat);
12516  strat->c3++;
12517  }
12518  }
12519  }
12520  }
12521  /*
12522  *the pair (S[i],p) enters B if the spoly != 0
12523  */
12524  /*- compute the short s-polynomial -*/
12525  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12526  pNorm(p);
12527  if ((q==NULL) || (p==NULL))
12528  return;
12529  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12530  Lp.p=NULL;
12531  else
12532  {
12533 // if ( rIsPluralRing(currRing) )
12534 // {
12535 // if(pHasNotCF(p, q))
12536 // {
12537 // if(ncRingType(currRing) == nc_lie)
12538 // {
12539 // // generalized prod-crit for lie-type
12540 // strat->cp++;
12541 // Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12542 // }
12543 // else
12544 // if( ALLOW_PROD_CRIT(strat) )
12545 // {
12546 // // product criterion for homogeneous case in SCA
12547 // strat->cp++;
12548 // Lp.p = NULL;
12549 // }
12550 // else
12551 // Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12552 // }
12553 // else Lp.p = nc_CreateSpoly(q,p,currRing);
12554 // }
12555 // else
12556 // {
12557 
12558  /* ksCreateShortSpoly needs two Lobject-kind presentations */
12559  /* p is already in this form, so convert q */
12560  // q = pMove2CurrTail(q, strat);
12561  Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12562  // }
12563  }
12564  if (Lp.p == NULL)
12565  {
12566  /*- the case that the s-poly is 0 -*/
12567  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12568 // if (strat->pairtest==NULL) initPairtest(strat);
12569 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12570 // strat->pairtest[strat->sl+1] = TRUE;
12571  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12572  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12573  /*
12574  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12575  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12576  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12577  *term of p devides the lcm(s,r)
12578  *(this canceling should be done here because
12579  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12580  *the first case is handeled in chainCrit
12581  */
12582  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12583  }
12584  else
12585  {
12586  /*- the pair (S[i],p) enters B -*/
12587  /* both of them should have their LM in currRing and TAIL in tailring */
12588  Lp.p1 = q; // already in the needed form
12589  Lp.p2 = p; // already in the needed form
12590 
12591  if ( !rIsPluralRing(currRing) )
12592  pNext(Lp.p) = strat->tail;
12593 
12594  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12595  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12596  if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12597  {
12598  Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12599  Lp.i_r2 = atR;
12600  }
12601  else
12602  {
12603  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12604  Lp.i_r1 = -1;
12605  Lp.i_r2 = -1;
12606  }
12607  strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12608 
12610  {
12611  if (!rIsPluralRing(currRing))
12612  nDelete(&(Lp.p->coef));
12613  }
12614 
12615  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12616  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12617  }
12618 }
12619 #endif
12620 
12621 #ifdef HAVE_SHIFTBBA
12622 /*3
12623 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12624 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12625 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
12626 */
12627 void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
12628 {
12629  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12630  // atR = -1;
12631  if ((strat->syzComp==0)
12632  || (pGetComp(h)<=strat->syzComp))
12633  {
12634  int j;
12635  BOOLEAN new_pair=FALSE;
12636 
12637  if (pGetComp(h)==0)
12638  {
12639  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12640  if ((isFromQ)&&(strat->fromQ!=NULL))
12641  {
12642  for (j=0; j<=k; j++)
12643  {
12644  if (!strat->fromQ[j])
12645  {
12646  new_pair=TRUE;
12647  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR,uptodeg,lV);
12648  // other side pairs:
12649  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12650  //Print("j:%d, Ll:%d\n",j,strat->Ll);
12651  }
12652  }
12653  }
12654  else
12655  {
12656  new_pair=TRUE;
12657  for (j=0; j<=k; j++)
12658  {
12659  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR,uptodeg,lV);
12660  // other side pairs
12661  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12662  }
12663  /* HERE we put (h, s*h) pairs */
12664  /* enterOnePairSelfShifts (poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV); */
12665  enterOnePairSelfShifts (h, h, ecart, isFromQ, strat, atR, uptodeg, lV);
12666  }
12667  }
12668  else
12669  {
12670  for (j=0; j<=k; j++)
12671  {
12672  if ((pGetComp(h)==pGetComp(strat->S[j]))
12673  || (pGetComp(strat->S[j])==0))
12674  {
12675  new_pair=TRUE;
12676  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR, uptodeg, lV);
12677  // other side pairs
12678  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12679  //Print("j:%d, Ll:%d\n",j,strat->Ll);
12680  }
12681  }
12682  /* HERE we put (h, s*h) pairs */
12683  enterOnePairSelfShifts (h, h, ecart, isFromQ, strat, atR, uptodeg, lV);
12684  }
12685 
12686  if (new_pair)
12687  {
12688  strat->chainCrit(h,ecart,strat);
12689  }
12690 
12691  }
12692 }
12693 #endif
12694 
12695 #ifdef HAVE_SHIFTBBA
12696 /*2
12697 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
12698 *superfluous elements in S will be deleted
12699 */
12700 void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR,int uptodeg, int lV)
12701 {
12702  /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12703  /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
12704  int j=pos;
12705 
12707  initenterpairsShift(h,k,ecart,0,strat, atR,uptodeg,lV);
12708  if ( (!strat->fromT)
12709  && ((strat->syzComp==0)
12710  ||(pGetComp(h)<=strat->syzComp)))
12711  {
12712  //Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
12713  unsigned long h_sev = pGetShortExpVector(h);
12714  loop
12715  {
12716  if (j > k) break;
12717  clearS(h,h_sev, &j,&k,strat);
12718  j++;
12719  }
12720  //Print("end clearS sl=%d\n",strat->sl);
12721  }
12722  // PrintS("end enterpairs\n");
12723 }
12724 #endif
12725 
12726 #ifdef HAVE_SHIFTBBA
12727 /*2
12728 * puts p to the set T, starting with the at position atT
12729 * and inserts all admissible shifts of p
12730 */
12731 void enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV)
12732 {
12733  /* determine how many elements we have to insert */
12734  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12735  /* hence, a total number of elt's to add is: */
12736  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12737 
12738  int toInsert = itoInsert(p.p, uptodeg, lV, strat->tailRing);
12739 
12740 #ifdef PDEBUG
12741  // Print("enterTShift uses toInsert: %d", toInsert); PrintLn();
12742 #endif
12743  int i;
12744 
12745  if (atT < 0)
12746  atT = strat->posInT(strat->T, strat->tl, p);
12747 
12748  /* can call enterT in a sequence, e.g. */
12749 
12750  /* shift0 = it's our model for further shifts */
12751  enterT(p,strat,atT);
12752  LObject qq;
12753  for (i=1; i<=toInsert; i++) // toIns - 1?
12754  {
12755  qq = p; //qq.Copy();
12756  qq.p = NULL;
12757  qq.max_exp = NULL;
12758  qq.t_p = p_LPshift(p_Copy(p.t_p,strat->tailRing), i, uptodeg, lV, strat->tailRing); // direct shift
12759  qq.GetP();
12760  // update q.sev
12761  qq.sev = pGetShortExpVector(qq.p);
12762  /* enter it into T, first el't is with the shift 0 */
12763  // compute the position for qq
12764  atT = strat->posInT(strat->T, strat->tl, qq);
12765  enterT(qq,strat,atT);
12766  }
12767 /* Q: what to do with this one in the orig enterT ? */
12768 /* strat->R[strat->tl] = &(strat->T[atT]); */
12769 /* Solution: it is done by enterT each time separately */
12770 }
12771 #endif
12772 
12773 #ifdef HAVE_SHIFTBBA
12775 {
12776  /* for the shift case need to run it with withT = TRUE */
12777  strat->redTailChange=FALSE;
12778  if (strat->noTailReduction) return L->GetLmCurrRing();
12779  poly h, p;
12780  p = h = L->GetLmTailRing();
12781  if ((h==NULL) || (pNext(h)==NULL))
12782  return L->GetLmCurrRing();
12783 
12784  TObject* With;
12785  // placeholder in case strat->tl < 0
12786  TObject With_s(strat->tailRing);
12787 
12788  LObject Ln(pNext(h), strat->tailRing);
12789  Ln.pLength = L->GetpLength() - 1;
12790 
12791  pNext(h) = NULL;
12792  if (L->p != NULL) pNext(L->p) = NULL;
12793  L->pLength = 1;
12794 
12795  Ln.PrepareRed(strat->use_buckets);
12796 
12797  while(!Ln.IsNull())
12798  {
12799  loop
12800  {
12801  Ln.SetShortExpVector();
12802  if (withT)
12803  {
12804  int j;
12805  j = kFindDivisibleByInT(strat, &Ln);
12806  if (j < 0) break;
12807  With = &(strat->T[j]);
12808  }
12809  else
12810  {
12811  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
12812  if (With == NULL) break;
12813  }
12814  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
12815  {
12816  With->pNorm();
12817  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
12818  }
12819  strat->redTailChange=TRUE;
12820  if (ksReducePolyTail(L, With, &Ln))
12821  {
12822  // reducing the tail would violate the exp bound
12823  // set a flag and hope for a retry (in bba)
12824  strat->completeReduce_retry=TRUE;
12825  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
12826  do
12827  {
12828  pNext(h) = Ln.LmExtractAndIter();
12829  pIter(h);
12830  L->pLength++;
12831  } while (!Ln.IsNull());
12832  goto all_done;
12833  }
12834  if (Ln.IsNull()) goto all_done;
12835  if (! withT) With_s.Init(currRing);
12836  }
12837  pNext(h) = Ln.LmExtractAndIter();
12838  pIter(h);
12839  L->pLength++;
12840  }
12841 
12842  all_done:
12843  Ln.Delete();
12844  if (L->p != NULL) pNext(L->p) = pNext(p);
12845 
12846  if (strat->redTailChange)
12847  {
12848  L->length = 0;
12849  }
12850  L->Normalize(); // HANNES: should have a test
12851  kTest_L(L);
12852  return L->GetLmCurrRing();
12853 }
12854 #endif
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:751
#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:318
#define TEST_OPT_INFREDTAIL
Definition: options.h:112
#define pSetmComp(p)
TODO:
Definition: polys.h:255
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1266
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:495
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2453
int getIndexRng(long coeff)
Definition: kutil.cc:6617
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6416
poly redtailBbaBound(LObject *L, int pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7706
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
Definition: kbuckets.cc:181
denominator_list_s * denominator_list
Definition: kutil.h:65
polyset sig
Definition: kutil.h:302
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11792
#define TEST_OPT_REDTAIL
Definition: options.h:111
#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:278
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:1174
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:632
#define pIsPurePower(p)
Definition: polys.h:231
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:690
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition: kutil.cc:5229
KINLINE TObject ** initR()
Definition: kInline.h:92
const CanonicalForm int s
Definition: facAbsFact.cc:55
int posInTrg0(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5496
void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin)
Definition: omBin.c:396
void initSbaPos(kStrategy strat)
Definition: kutil.cc:10212
poly redtail(LObject *L, int pos, kStrategy strat)
Definition: kutil.cc:7522
void enterOnePairShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS, int, int lV)
Definition: kutil.cc:12332
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
Definition: old.gring.cc:2307
BOOLEAN honey
Definition: kutil.h:374
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9357
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6913
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:935
int itoInsert(poly p, int uptodeg, int lV, const ring r)
Definition: shiftgb.cc:324
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:2971
#define pSetm(p)
Definition: polys.h:253
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:432
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1362
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition: syz3.cc:1027
static FORCE_INLINE BOOLEAN n_IsUnit(number n, const coeffs r)
TRUE iff n has a multiplicative inverse in the given coeff field/ring r.
Definition: coeffs.h:519
#define pDivComp_LESS
Definition: kutil.cc:141
static gmp_float * diff
Definition: mpr_complex.cc:47
#define setmaxL
Definition: kutil.h:29
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:711
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:467
const poly a
Definition: syzextra.cc:212
int HCord
Definition: kutil.cc:235
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:5389
#define Print
Definition: emacs.cc:83
int syzComp
Definition: kutil.h:350
long pLDeg1(poly p, int *l, const ring r)
Definition: p_polys.cc:840
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1615
KINLINE unsigned long * initsevT()
Definition: kInline.h:97
#define TEST_OPT_DEGBOUND
Definition: options.h:108
#define pAdd(p, q)
Definition: polys.h:186
#define pDivComp_EQUAL
Definition: kutil.cc:140
void pLcmRat(poly a, poly b, poly m, int rat_shift)
Definition: ratgring.cc:30
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:9945
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4889
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:287
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:71
int syzmax
Definition: kutil.h:345
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6458
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7941
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6528
poly kHEdge
Definition: kutil.h:323
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:293
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1004
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6492
static int * initS_2_R(const int maxnr)
Definition: kutil.cc:526
class sLObject LObject
Definition: kutil.h:60
#define r_assume(x)
Definition: mod2.h:395
TObject * TSet
Definition: kutil.h:61
KINLINE TSet initT()
Definition: kInline.h:81
#define pLtCmpOrdSgnDiffM(p, q)
Definition: polys.h:125
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7982
bool sigdrop
Definition: kutil.h:356
#define TEST_OPT_PROT
Definition: options.h:98
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:11125
wlen_set lenSw
Definition: kutil.h:314
loop
Definition: myNF.cc:98
static int min(int a, int b)
Definition: fast_mult.cc:268
int Ll
Definition: kutil.h:347
#define pSetExp(p, i, v)
Definition: polys.h:42
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6872
static int si_min(const int a, const int b)
Definition: auxiliary.h:121
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7228
#define kTest_S(T)
Definition: kutil.h:651
long pLDeg1c(poly p, int *l, const ring r)
Definition: p_polys.cc:876
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:5306
#define FALSE
Definition: auxiliary.h:94
BOOLEAN noTailReduction
Definition: kutil.h:375
Compatiblity layer for legacy polynomial operations (over currRing)
int * S_2_R
Definition: kutil.h:338
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5361
long totaldegreeWecart(poly p, ring r)
Definition: weight.cc:225
return P p
Definition: myNF.cc:203
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3270
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3847
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1026
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2237
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6957
int posInLrg0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6630
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5497
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10118
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:968
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
Definition: p_polys.cc:1442
static void enterOnePairManyShifts(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
Definition: kutil.cc:12193
#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:343
char news
Definition: kutil.h:397
short * ecartWeights
Definition: weight0.c:28
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:242
static unsigned add[]
Definition: misc_ip.cc:83
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:711
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition: kutil.cc:8869
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6837
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3977
#define p_GetComp(p, r)
Definition: monomials.h:72
poly prMoveR(poly &p, ring src_r, ring dest_r)
Definition: prCopy.cc:91
void reorderS(int *suc, kStrategy strat)
Definition: kutil.cc:5075
char newt
Definition: kutil.h:398
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:714
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4627
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition: p_polys.h:1911
static poly pp_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:922
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6802
static BOOLEAN rIsRatGRing(const ring r)
Definition: ring.h:415
BOOLEAN * NotUsedAxis
Definition: kutil.h:328
#define TEST_OPT_CONTENTSB
Definition: options.h:121
#define pDecrExp(p, i)
Definition: polys.h:44
BOOLEAN posInLDependsOnLength
Definition: kutil.h:386
rational (GMP) numbers
Definition: coeffs.h:31
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_Z(const coeffs r)
Definition: coeffs.h:759
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:717
#define ppMult_mm(p, m)
Definition: polys.h:184
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:276
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6755
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:603
int length
Definition: kutil.h:80
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
static int pDivComp(poly p, poly q)
Definition: kutil.cc:187
int cv
Definition: kutil.h:366
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:1665
#define pNeg(p)
Definition: polys.h:181
void initSyzRules(kStrategy strat)
Definition: kutil.cc:8406
BOOLEAN * pairtest
Definition: kutil.h:329
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5783
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:769
BOOLEAN z2homog
Definition: kutil.h:371
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4952
poly kNoether
Definition: kutil.h:324
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition: p_polys.h:742
int strat_nr
Definition: kstdfac.cc:27
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3917
int tl
Definition: kutil.h:346
int Bl
Definition: kutil.h:348
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8155
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2601
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge, ring tailRing)
Definition: hdegree.cc:1005
int posInLRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6303
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
#define BTEST1(a)
Definition: options.h:32
#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
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:957
static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
p_HasNotCF for the IDLIFT case: ignore component
Definition: kutil.cc:2220
char noClearS
Definition: kutil.h:399
#define TRUE
Definition: auxiliary.h:98
#define nIsOne(n)
Definition: numbers.h:25
denominator_list DENOMINATOR_LIST
Definition: kutil.cc:89
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:5001
#define TEST_OPT_REDSB
Definition: options.h:99
poly pMove2CurrTail(poly p, kStrategy strat)
Definition: kutil.cc:11962
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
Definition: kstd1.cc:2231
#define pHasNotCF(p1, p2)
Definition: polys.h:245
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8706
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1430
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1058
#define kTest(A)
Definition: kutil.h:648
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:480
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:334
#define pLcm(a, b, m)
Definition: polys.h:277
unsigned long * sevT
Definition: kutil.h:319
void * ADDRESS
Definition: auxiliary.h:115
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:289
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:281
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11406
void pWrite(poly p)
Definition: polys.h:290
int ak
Definition: kutil.h:349
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:10889
#define setmaxLinc
Definition: kutil.h:30
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8254
void cancelunit(LObject *L, BOOLEAN inNF)
Definition: kutil.cc:332
poly max_exp
Definition: kutil.h:77
int k
Definition: cfEzgcd.cc:93
KINLINE void pNorm()
Definition: kInline.h:463
poly kCreateZeroPoly(long exp[], long cabsind, poly *t_p, ring leadRing, ring tailRing)
Definition: kutil.cc:4432
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10314
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
Definition: old.gring.cc:1938
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1728
#define TEST_OPT_DEBUG
Definition: options.h:103
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1227
#define Q
Definition: sirandom.c:25
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2710
char * showOption()
Definition: misc_ip.cc:717
#define pLmDivisibleBy(a, b)
like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
Definition: polys.h:140
poly redtailBba(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7598
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:6404
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:909
#define WarnS
Definition: emacs.cc:81
poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing)
Definition: kspoly.cc:1017
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR, int uptodeg, int lV)
Definition: kutil.cc:12700
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:522
ring rAssure_c_dp(const ring r)
Definition: ring.cc:4863
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:7071
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5729
int(* red)(LObject *L, kStrategy strat)
Definition: kutil.h:272
#define omAlloc(size)
Definition: omAllocDecl.h:210
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:10031
int nextZeroSimplexExponent(long exp[], long ind[], long cexp[], long cind[], long *cabsind, long step[], long bound, long N)
Definition: kutil.cc:4366
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:542
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:1293
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8852
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:275
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:407
void HEckeTest(poly pp, kStrategy strat)
Definition: kutil.cc:482
#define omCheckBinAddrSize(addr, size)
Definition: omAllocDecl.h:326
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1943
void chainCritSig(poly p, int, kStrategy strat)
Definition: kutil.cc:3499
int currIdx
Definition: kutil.h:311
static void p_LmFree(poly p, ring)
Definition: p_polys.h:678
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4978
#define pGetComp(p)
Component.
Definition: polys.h:37
int Kstd1_mu
Definition: kutil.cc:237
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6714
int minim
Definition: kutil.h:354
#define pLtCmpOrdSgnDiffP(p, q)
Definition: polys.h:126
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:5350
int Bmax
Definition: kutil.h:348
int redFirstShift(LObject *h, kStrategy strat)
Definition: kstd2.cc:4405
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:804
poly pp
Definition: myNF.cc:296
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:1954
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4676
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:705
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.h:286
skStrategy()
Definition: kutil.cc:11628
char completeReduce_retry
Definition: kutil.h:400
bool found
Definition: facFactorize.cc:56
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
Definition: kutil.cc:12627
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11379
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8957
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6216
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:940
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:9929
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9495
int HCord
Definition: kutil.h:351
#define mflush()
Definition: reporter.h:57
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
Definition: prCopy.cc:47
int redHoney(LObject *h, kStrategy strat)
Definition: kstd2.cc:1456
poly t_p
Definition: kutil.h:76
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2875
poly p_LPshift(poly p, int sh, int uptodeg, int lV, const ring r)
Definition: shiftgb.cc:77
#define pIter(p)
Definition: monomials.h:44
KINLINE int GetpLength()
Definition: kInline.h:268
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1165
void updateSShift(kStrategy strat, int uptodeg, int lV)
Definition: kutil.cc:12086
poly res
Definition: myNF.cc:322
BOOLEAN interpt
Definition: kutil.h:368
#define pFalseReturn(cond)
Definition: monomials.h:147
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:111
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
void(* initEcart)(TObject *L)
Definition: kutil.h:274
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
#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:284
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8059
bool equal
Definition: cfModGcd.cc:4067
long twoPow(long arg)
Definition: kutil.cc:4240
void enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV)
Definition: kutil.cc:12731
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5419
static int rBlocks(ring r)
Definition: ring.h:559
int nrsyzcrit
Definition: kutil.h:357
BOOLEAN fromT
Definition: kutil.h:376
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8561
int posInT17_c(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5931
int nrrewcrit
Definition: kutil.h:358
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:586
const ring r
Definition: syzextra.cc:208
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:876
BOOLEAN homog
Definition: kutil.h:369
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:4040
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5455
KINLINE TObject * S_2_T(int i)
Definition: kInline.h:35
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:200
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1273
#define TEST_OPT_INTSTRATEGY
Definition: options.h:105
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:249
Definition: intvec.h:14
long FDeg
Definition: kutil.h:79
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:101
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:551
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition: kutil.cc:531
#define setmaxT
Definition: kutil.h:32
#define kTest_TS(A)
Definition: kutil.h:649
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
poly p_One(const ring r)
Definition: p_polys.cc:1312
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:3356
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:464
int j
Definition: myNF.cc:70
static int max(int a, int b)
Definition: fast_mult.cc:264
END_NAMESPACE BEGIN_NAMESPACE_SINGULARXX ideal poly int syzComp
Definition: myNF.cc:291
#define nGreaterZero(n)
Definition: numbers.h:27
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition: kutil.cc:681
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition: kutil.cc:4759
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9776
BOOLEAN Gebauer
Definition: kutil.h:375
#define TEST_OPT_OLDSTD
Definition: options.h:117
#define assume(x)
Definition: mod2.h:394
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
intset fromQ
Definition: kutil.h:315
#define messageSets(s)
Definition: kutil.h:536
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3156
long p_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:595
LObject * LSet
Definition: kutil.h:62
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1323
void initEcartBBA(TObject *h)
Definition: kutil.cc:1259
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5885
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:7994
#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:276
#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:4248
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether &#39;a&#39; is divisible &#39;b&#39;; for r encoding a field: TRUE iff &#39;b&#39; does not represent zero in Z:...
Definition: coeffs.h:787
long pLDeg0(poly p, int *l, const ring r)
Definition: p_polys.cc:738
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition: polys.h:146
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:162
BOOLEAN pCompareChain(poly p, poly p1, poly p2, poly lcm, const ring R)
Returns TRUE if.
Definition: kpolys.cc:20
pNormalize(P.p)
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:280
const ring R
Definition: DebugPrint.cc:36
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2218
poly pMoveCurrTail2poly(poly p, kStrategy strat)
Definition: kutil.cc:11976
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1802
rRingOrder_t
order stuff
Definition: ring.h:75
#define kTest_L(T)
Definition: kutil.h:652
P bucket
Definition: myNF.cc:79
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:375
#define pSetComp(p, v)
Definition: polys.h:38
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1467
#define pJet(p, m)
Definition: polys.h:350
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11280
int m
Definition: cfEzgcd.cc:119
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6158
LObject P
Definition: kutil.h:296
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:221
TObject * kFindDivisibleByInS(kStrategy strat, int pos, LObject *L, TObject *T, long ecart)
Definition: kutil.cc:7384
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9794
unsigned sbaOrder
Definition: kutil.h:310
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:869
static int si_max(const int a, const int b)
Definition: auxiliary.h:120
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:7007
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition: p_polys.h:1236
void exitSba(kStrategy strat)
Definition: kutil.cc:10387
void rDebugPrint(const ring r)
Definition: ring.cc:4003
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:284
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition: kutil.cc:11826
int isInV(poly p, int lV)
Definition: shiftgb.cc:241
poly tail
Definition: kutil.h:330
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:243
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4925
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1334
#define pOne()
Definition: polys.h:297
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5824
CanonicalForm H
Definition: facAbsFact.cc:64
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:698
TObject ** R
Definition: kutil.h:336
#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:1110
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition: coeffs.h:526
polyset S
Definition: kutil.h:300
#define IDELEMS(i)
Definition: simpleideals.h:24
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1768
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:725
CFList tmp2
Definition: facFqBivar.cc:70
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
BOOLEAN sugarCrit
Definition: kutil.h:374
intset lenS
Definition: kutil.h:313
#define p_LmTest(p, r)
Definition: p_polys.h:161
#define nDelete(n)
Definition: numbers.h:16
int tmax
Definition: kutil.h:346
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:716
omBin omGetStickyBinOfBin(omBin bin)
Definition: omBin.c:373
void initBuchMoraShift(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:12114
int Kstd1_deg
Definition: kutil.cc:236
int cp
Definition: kutil.h:343
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:752
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9580
ideal idCopy(ideal A)
Definition: ideals.h:60
static void enlargeL(LSet *L, int *length, const int incr)
Definition: kutil.cc:662
#define p_Test(p, r)
Definition: p_polys.h:160
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:1727
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:3547
void rChangeCurrRing(ring r)
Definition: polys.cc:12
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1063
int pLength
Definition: kutil.h:80
poly redtailBba_Z(LObject *L, int pos, kStrategy strat)
Definition: kutil.cc:7823
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10828
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:7138
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7290
poly sig
Definition: kutil.h:74
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1416
int int kStrategy strat
Definition: myNF.cc:68
#define rRing_has_Comp(r)
Definition: monomials.h:274
#define nInvers(a)
Definition: numbers.h:33
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11701
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
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:697
BOOLEAN kHEdgeFound
Definition: kutil.h:373
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4627
intset ecartS
Definition: kutil.h:303
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
poly t_kHEdge
Definition: kutil.h:325
poly p_LPshiftT(poly p, int sh, int uptodeg, int lV, kStrategy strat, const ring r)
Definition: shiftgb.cc:45
void kMergeBintoLSba(kStrategy strat)
Definition: kutil.cc:3247
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:483
void initenterzeropairsRing(poly p, int ecart, kStrategy strat, int atR)
Definition: kutil.cc:4495
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:52
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition: kutil.cc:7321
#define TEST_OPT_SUGARCRIT
Definition: options.h:102
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:7176
#define TEST_OPT_WEIGHTM
Definition: options.h:115
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:285
void initPairtest(kStrategy strat)
Definition: kutil.cc:672
long pLDegb(poly p, int *l, const ring r)
Definition: p_polys.cc:810
void mult(unsigned long *result, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:649
LSet L
Definition: kutil.h:321
BOOLEAN LDegLast
Definition: kutil.h:382
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:11057
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:101
#define nIsZero(n)
Definition: numbers.h:19
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:477
#define NULL
Definition: omList.c:10
#define TEST_OPT_IDLIFT
Definition: options.h:123
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition: kutil.cc:1533
void cleanT(kStrategy strat)
Definition: kutil.cc:552
poly * polyset
Definition: hutil.h:15
#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:3594
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:974
LSet B
Definition: kutil.h:322
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4915
int Lmax
Definition: kutil.h:347
int64 wlen_type
Definition: kutil.h:56
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:172
#define pLtCmpOrdSgnEqP(p, q)
Definition: polys.h:128
BOOLEAN rHasGlobalOrdering(const ring r)
Definition: ring.h:750
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:450
long ind_fact_2(long arg)
Definition: kutil.cc:4225
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:6376
ring tailRing
Definition: kutil.h:339
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5572
int gcd(int a, int b)
Definition: walkSupport.cc:839
#define TEST_OPT_SB_1
Definition: options.h:113
denominator_list next
Definition: kutil.h:67
CFList tmp1
Definition: facFqBivar.cc:70
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:61
poly t_kNoether
Definition: kutil.h:327
omBin tailBin
Definition: kutil.h:341
#define TEST_OPT_CANCELUNIT
Definition: options.h:122
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:9858
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:5128
#define pDelete(p_ptr)
Definition: polys.h:169
char overflow
Definition: kutil.h:401
#define omSizeWOfBin(bin_ptr)
int syzidxmax
Definition: kutil.h:345
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:9026
~skStrategy()
Definition: kutil.cc:11648
unsigned long * sevS
Definition: kutil.h:316
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5614
#define nCopy(n)
Definition: numbers.h:15
static bool rIsSCA(const ring r)
Definition: nc.h:206
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:10639
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6184
#define REDTAIL_CANONICALIZE
#define pNext(p)
Definition: monomials.h:43
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition: kutil.cc:10866
unsigned long * sevSyz
Definition: kutil.h:317
#define setmaxTinc
Definition: kutil.h:33
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3483
void rKillModifiedRing(ring r)
Definition: ring.cc:2967
long maxdegreeWecart(poly p, int *l, ring r)
Definition: weight.cc:255
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:228
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10427
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:55
#define pSetCoeff0(p, n)
Definition: monomials.h:67
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1122
#define p_GetCoeff(p, r)
Definition: monomials.h:57
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:44
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1037
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:601
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6115
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:978
polyset syz
Definition: kutil.h:301
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:175
static intset initec(const int maxnr)
Definition: kutil.cc:517
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1053
static int pDivCompRing(poly p, poly q)
Definition: kutil.cc:149
int sl
Definition: kutil.h:344
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1067
poly pCopyL2p(LObject H, kStrategy strat)
Definition: kutil.cc:11993
int idElem(const ideal F)
count non-zero elements
int dReportError(const char *fmt,...)
Definition: dError.cc:45
TSet T
Definition: kutil.h:320
p exp[i]
Definition: DebugPrint.cc:39
#define ALLOW_PROD_CRIT(A)
Definition: kutil.h:392
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1013
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:706
BOOLEAN isInPairsetB(poly q, int *k, kStrategy strat)
Definition: kutil.cc:702
long ind2(long arg)
Definition: kutil.cc:4213
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4649
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:612
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8981
BOOLEAN use_buckets
Definition: kutil.h:380
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3224
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:237
void p_Write(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:206
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1348
int kFindDivisibleByInT(const kStrategy strat, const LObject *L, const int start)
return -1 if no divisor is found number of first divisor in T, otherwise
Definition: kstd2.cc:88
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10762
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:6058
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:12774
void initEcartNormal(TObject *h)
Definition: kutil.cc:1251
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition: p_polys.cc:4373
ideal createG0()
Definition: kutil.cc:4561
void wrp(poly p)
Definition: polys.h:292
#define pDivComp_GREATER
Definition: kutil.cc:142
#define kTest_T(T)
Definition: kutil.h:650
kBucketDestroy & P
Definition: myNF.cc:191
#define pDivComp_INCOMP
Definition: kutil.cc:143
int LazyPass
Definition: kutil.h:349
static jList * T
Definition: janet.cc:37
polyrec * poly
Definition: hilb.h:10
static LSet initL(int nr=setmaxL)
Definition: kutil.h:418
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:877
int newIdeal
Definition: kutil.h:353
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:11214
ideal Shdl
Definition: kutil.h:297
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11755
#define nInit(i)
Definition: numbers.h:24
#define OPT_INTERRUPT
Definition: options.h:74
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5690
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:85
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg)
Definition: ideals.cc:515
kStrategy next
Definition: kutil.h:271
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
const poly b
Definition: syzextra.cc:213
KINLINE poly kNoetherTail()
Definition: kInline.h:63
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition: kutil.cc:1284
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2747
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3558
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:504
int ecart
Definition: kutil.h:80
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1296
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1020
char redTailChange
Definition: kutil.h:396
void enterOnePairSelfShifts(poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int, int uptodeg, int lV)
Definition: kutil.cc:12269
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:10194
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:292
#define pLmEqual(p1, p2)
Definition: polys.h:111
int syzl
Definition: kutil.h:345
#define ENTER_USE_MEMMOVE
Definition: kutil.cc:52
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition: kstd1.cc:1098
int LazyDegree
Definition: kutil.h:349
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition: p_polys.h:1527
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5992
class sTObject TObject
Definition: kutil.h:59
Definition: nc.h:26
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5661
ring tailRing
Definition: kutil.h:78
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9692
poly p
Definition: kutil.h:75
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9255
intset syzIdx
Definition: kutil.h:307
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition: p_polys.cc:1207
#define nGreater(a, b)
Definition: numbers.h:28
#define pCopy(p)
return a copy of the poly
Definition: polys.h:168
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:341
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
Definition: kbuckets.cc:628
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:1137
#define pIsVector(p)
Definition: polys.h:233
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6240
BOOLEAN pCompareChainPart(poly p, poly p1, poly p2, poly lcm, const ring R)
Definition: kpolys.cc:74
#define idIsConstant(I)
Definition: ideals.h:40
KINLINE long GetpFDeg() const
Definition: kInline.h:404