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 */
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
313  }
314  kTest_L(L);
315  }
316 }
317 
318 void deleteHC(poly* p, int* e, int* l,kStrategy strat)
319 {
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 
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  }
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 
553 {
554  int i,j;
555  poly p;
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;
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 */
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 
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 
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 &&
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 */
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 */
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 = p_Lcm(p,strat->S[i],currRing);
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  /*
1334  *the set B collects the pairs of type (S[j],p)
1335  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1336  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
1337  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
1338  */
1339 
1340  for(j = strat->Bl;j>=0;j--)
1341  {
1342  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1343  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1344  #ifdef ADIDEBUG
1345  printf("\nChainCrit in enteronepairring\n");
1346  printf("\nB[j]\n");
1347  pWrite(strat->B[j].p);
1348  pWrite(strat->B[j].p1);
1349  pWrite(strat->B[j].p2);
1350  pWrite(strat->B[j].lcm);
1351  printf("\nh - neue Paar\n");
1352  pWrite(h.p);
1353  pWrite(p);
1354  pWrite(strat->S[i]);
1355  pWrite(h.lcm);
1356  printf("\ncompare = %i\ncompareCoeff = %i\n",compare,compareCoeff);
1357  #endif
1358  if(compare == pDivComp_EQUAL)
1359  {
1360  //They have the same LM
1361  if(compareCoeff == pDivComp_LESS)
1362  {
1363  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1364  {
1365  #ifdef ADIDEBUG
1366  printf("\nGelöscht h\n");
1367  #endif
1368  strat->c3++;
1369  pLmDelete(h.lcm);
1370  return;
1371  }
1372  break;
1373  }
1374  if(compareCoeff == pDivComp_GREATER)
1375  {
1376  #ifdef ADIDEBUG
1377  printf("\nGelöscht: B[j]\n");
1378  #endif
1379  deleteInL(strat->B,&strat->Bl,j,strat);
1380  strat->c3++;
1381  }
1382  if(compareCoeff == pDivComp_EQUAL)
1383  {
1384  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1385  {
1386  #ifdef ADIDEBUG
1387  printf("\nGelöscht h\n");
1388  #endif
1389  strat->c3++;
1390  pLmDelete(h.lcm);
1391  return;
1392  }
1393  break;
1394  }
1395  }
1396  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1397  {
1398  if(compare == pDivComp_LESS)
1399  {
1400  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1401  {
1402  #ifdef ADIDEBUG
1403  printf("\nGelöscht h\n");
1404  #endif
1405  strat->c3++;
1406  pLmDelete(h.lcm);
1407  return;
1408  }
1409  break;
1410  }
1411  if(compare == pDivComp_GREATER)
1412  {
1413  #ifdef ADIDEBUG
1414  printf("\nGelöscht: B[j]\n");
1415  #endif
1416  deleteInL(strat->B,&strat->Bl,j,strat);
1417  strat->c3++;
1418  }
1419  }
1420  }
1421  number s, t;
1422  poly m1, m2, gcd = NULL;
1423  #ifdef ADIDEBUG
1424  printf("\nTrying to add spair S[%i] und p\n",i);pWrite(strat->S[i]);pWrite(p);
1425  #endif
1426  s = pGetCoeff(strat->S[i]);
1427  t = pGetCoeff(p);
1429  ksCheckCoeff(&s, &t, currRing->cf);
1430  pSetCoeff0(m1, s);
1431  pSetCoeff0(m2, t);
1432  m2 = pNeg(m2);
1433  p_Test(m1,strat->tailRing);
1434  p_Test(m2,strat->tailRing);
1435  poly si = pCopy(strat->S[i]);
1436  poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1437  poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1438  pDelete(&si);
1439  if(sim2 == NULL)
1440  {
1441  pDelete(&m1);
1442  pDelete(&m2);
1443  if(pm1 == NULL)
1444  {
1445  if(h.lcm != NULL)
1446  {
1447  pLmDelete(h.lcm);
1448  h.lcm=NULL;
1449  }
1450  h.Clear();
1452  strat->pairtest[i] = TRUE;
1453  strat->pairtest[strat->sl+1] = TRUE;
1454  return;
1455  }
1456  else
1457  {
1458  gcd = pm1;
1459  pm1 = NULL;
1460  }
1461  }
1462  else
1463  {
1464  if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1465  {
1466  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1467  pSetmComp(sim2);
1468  }
1469  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1470  gcd = p_Add_q(pm1, sim2, strat->tailRing);
1471  }
1472  p_Test(gcd, strat->tailRing);
1473  //p_LmDelete(m1, strat->tailRing);
1474  //p_LmDelete(m2, strat->tailRing);
1475 #ifdef KDEBUG
1476  if (TEST_OPT_DEBUG)
1477  {
1478  wrp(gcd);
1479  PrintLn();
1480  }
1481 #endif
1482  h.p = gcd;
1483  h.i_r = -1;
1484  if(h.p == NULL)
1485  {
1487  strat->pairtest[i] = TRUE;
1488  strat->pairtest[strat->sl+1] = TRUE;
1489  return;
1490  }
1491  h.tailRing = strat->tailRing;
1492  int posx;
1493  //h.pCleardenom();
1494  //pSetm(h.p);
1495  #ifdef ADIDEBUG
1496  printf("\nThis is afterwards:\n");
1497  pWrite(h.p);
1498  #endif
1499  h.i_r1 = -1;h.i_r2 = -1;
1500  strat->initEcart(&h);
1501  #if 1
1502  h.p2 = strat->S[i];
1503  h.p1 = p;
1504  #endif
1505  #if 1
1506  if (atR >= 0)
1507  {
1508  h.i_r1 = atR;
1509  h.i_r2 = strat->S_2_R[i];
1510  }
1511  #endif
1512  if (strat->Bl==-1)
1513  posx =0;
1514  else
1515  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1516  h.sev = pGetShortExpVector(h.p);
1517  if (currRing!=strat->tailRing)
1519  #ifdef ADIDEBUG
1520  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);
1521  #endif
1522  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1523  kTest_TS(strat);
1524 }
1525 
1526 
1527 /*2
1528 * put the lcm(s[i],p) into the set B
1529 */
1530 
1531 static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1532 {
1533  number d, s, t;
1534  assume(atR >= 0);
1535  poly m1, m2, gcd,si;
1536  if(!enterTstrong)
1537  {
1538  assume(i<=strat->sl);
1539  si = strat->S[i];
1540  }
1541  else
1542  {
1543  assume(i<=strat->tl);
1544  si = strat->T[i].p;
1545  }
1546  //printf("\n--------------------------------\n");
1547  //pWrite(p);pWrite(si);
1548  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1549 
1550  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1551  {
1552  nDelete(&d);
1553  nDelete(&s);
1554  nDelete(&t);
1555  return FALSE;
1556  }
1557 
1558  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1559  //p_Test(m1,strat->tailRing);
1560  //p_Test(m2,strat->tailRing);
1561  /*if(!enterTstrong)
1562  {
1563  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1564  {
1565  memset(&(strat->P), 0, sizeof(strat->P));
1566  kStratChangeTailRing(strat);
1567  strat->P = *(strat->R[atR]);
1568  p_LmFree(m1, strat->tailRing);
1569  p_LmFree(m2, strat->tailRing);
1570  p_LmFree(gcd, currRing);
1571  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1572  }
1573  }*/
1574  pSetCoeff0(m1, s);
1575  pSetCoeff0(m2, t);
1576  pSetCoeff0(gcd, d);
1577  p_Test(m1,strat->tailRing);
1578  p_Test(m2,strat->tailRing);
1579  //printf("\n===================================\n");
1580  //pWrite(m1);pWrite(m2);pWrite(gcd);
1581 #ifdef KDEBUG
1582  if (TEST_OPT_DEBUG)
1583  {
1584  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1585  PrintS("m1 = ");
1586  p_wrp(m1, strat->tailRing);
1587  PrintS(" ; m2 = ");
1588  p_wrp(m2, strat->tailRing);
1589  PrintS(" ; gcd = ");
1590  wrp(gcd);
1591  PrintS("\n--- create strong gcd poly: ");
1592  Print("\n p: %d", i);
1593  wrp(p);
1594  Print("\n strat->S[%d]: ", i);
1595  wrp(si);
1596  PrintS(" ---> ");
1597  }
1598 #endif
1599 
1601  p_LmDelete(m1, strat->tailRing);
1602  p_LmDelete(m2, strat->tailRing);
1603 #ifdef KDEBUG
1604  if (TEST_OPT_DEBUG)
1605  {
1606  wrp(gcd);
1607  PrintLn();
1608  }
1609 #endif
1610 
1611  LObject h;
1612  h.p = gcd;
1613  h.tailRing = strat->tailRing;
1614  int posx;
1615  h.pCleardenom();
1616  strat->initEcart(&h);
1617  h.sev = pGetShortExpVector(h.p);
1618  h.i_r1 = -1;h.i_r2 = -1;
1619  if (currRing!=strat->tailRing)
1621  if(!enterTstrong)
1622  {
1623  #if 1
1624  h.p1 = p;h.p2 = strat->S[i];
1625  #endif
1626  if (atR >= 0)
1627  {
1628  h.i_r2 = strat->S_2_R[i];
1629  h.i_r1 = atR;
1630  }
1631  else
1632  {
1633  h.i_r1 = -1;
1634  h.i_r2 = -1;
1635  }
1636  if (strat->Ll==-1)
1637  posx =0;
1638  else
1639  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1640  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1641  }
1642  else
1643  {
1644  if(h.IsNull()) return FALSE;
1645  //int red_result;
1646  //reduzieren ist teur!!!
1647  //if(strat->L != NULL)
1648  //red_result = strat->red(&h,strat);
1649  if(!h.IsNull())
1650  {
1651  enterT(h, strat,-1);
1652  //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1653  //strat->enterS(h,pos,strat,-1);
1654  }
1655  }
1656  //#if 1
1657  #ifdef ADIDEBUG
1658  printf("\nThis strong poly was added to L:\n");pWrite(h.p);pWrite(h.p1);pWrite(h.p2);
1659  #endif
1660  return TRUE;
1661 }
1662 
1664 {
1665  if(strat->sl < 0) return FALSE;
1666  int i;
1667  for(i=0;i<strat->sl;i++)
1668  {
1669  //Construct the gcd pair between h and S[i]
1670  number d, s, t;
1671  poly m1, m2, gcd;
1672  d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1673  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1674  {
1675  nDelete(&d);
1676  nDelete(&s);
1677  nDelete(&t);
1678  }
1679  else
1680  {
1681  k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1682  pSetCoeff0(m1, s);
1683  pSetCoeff0(m2, t);
1684  pSetCoeff0(gcd, d);
1686  poly pSigMult = p_Copy(h->sig,currRing);
1687  poly sSigMult = p_Copy(strat->sig[i],currRing);
1688  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1689  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1690  p_LmDelete(m1, strat->tailRing);
1691  p_LmDelete(m2, strat->tailRing);
1692  poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1693  if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1694  {
1695  #ifdef ADIDEBUG
1696  printf("\nCan replace * (sig = *) with * (sig = *) since of * with sig *\n");
1697  pWrite(h->p);pWrite(h->sig);pWrite(gcd);pWrite(pairsig);pWrite(strat->S[i]);pWrite(strat->sig[i]);
1698  //getchar();
1699  #endif
1700  pDelete(&h->p);
1701  h->p = gcd;
1702  pDelete(&h->sig);
1703  h->sig = pairsig;
1704  pNext(h->sig) = NULL;
1705  strat->initEcart(h);
1706  h->sev = pGetShortExpVector(h->p);
1707  h->sevSig = pGetShortExpVector(h->sig);
1708  h->i_r1 = -1;h->i_r2 = -1;
1709  if(h->lcm != NULL)
1710  {
1711  pLmDelete(h->lcm);
1712  h->lcm = NULL;
1713  }
1714  if (currRing!=strat->tailRing)
1716  return TRUE;
1717  }
1718  //Delete what you didn't use
1719  pDelete(&gcd);
1720  pDelete(&pairsig);
1721  }
1722  }
1723  return FALSE;
1724 }
1725 
1726 static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1727 {
1728  number d, s, t;
1729  assume(atR >= 0);
1730  poly m1, m2, gcd,si;
1731  assume(i<=strat->sl);
1732  si = strat->S[i];
1733  //printf("\n--------------------------------\n");
1734  //pWrite(p);pWrite(si);
1735  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1736 
1737  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1738  {
1739  nDelete(&d);
1740  nDelete(&s);
1741  nDelete(&t);
1742  return FALSE;
1743  }
1744 
1745  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1746  //p_Test(m1,strat->tailRing);
1747  //p_Test(m2,strat->tailRing);
1748  /*if(!enterTstrong)
1749  {
1750  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1751  {
1752  memset(&(strat->P), 0, sizeof(strat->P));
1753  kStratChangeTailRing(strat);
1754  strat->P = *(strat->R[atR]);
1755  p_LmFree(m1, strat->tailRing);
1756  p_LmFree(m2, strat->tailRing);
1757  p_LmFree(gcd, currRing);
1758  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1759  }
1760  }*/
1761  pSetCoeff0(m1, s);
1762  pSetCoeff0(m2, t);
1763  pSetCoeff0(gcd, d);
1764  p_Test(m1,strat->tailRing);
1765  p_Test(m2,strat->tailRing);
1766  //printf("\n===================================\n");
1767  //pWrite(m1);pWrite(m2);pWrite(gcd);
1768 #ifdef KDEBUG
1769  if (TEST_OPT_DEBUG)
1770  {
1771  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1772  PrintS("m1 = ");
1773  p_wrp(m1, strat->tailRing);
1774  PrintS(" ; m2 = ");
1775  p_wrp(m2, strat->tailRing);
1776  PrintS(" ; gcd = ");
1777  wrp(gcd);
1778  PrintS("\n--- create strong gcd poly: ");
1779  Print("\n p: %d", i);
1780  wrp(p);
1781  Print("\n strat->S[%d]: ", i);
1782  wrp(si);
1783  PrintS(" ---> ");
1784  }
1785 #endif
1786 
1788 
1789 #ifdef KDEBUG
1790  if (TEST_OPT_DEBUG)
1791  {
1792  wrp(gcd);
1793  PrintLn();
1794  }
1795 #endif
1796 
1797  //Check and set the signatures
1798  poly pSigMult = p_Copy(sig,currRing);
1799  poly sSigMult = p_Copy(strat->sig[i],currRing);
1800  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1801  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1802  p_LmDelete(m1, strat->tailRing);
1803  p_LmDelete(m2, strat->tailRing);
1804  poly pairsig;
1805  if(pLmCmp(pSigMult,sSigMult) == 0)
1806  {
1807  //Same lm, have to add them
1808  pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1809  //This might be zero
1810  }
1811  else
1812  {
1813  //Set the sig to either pSigMult or sSigMult
1814  if(pLtCmp(pSigMult,sSigMult)==1)
1815  {
1816  pairsig = pSigMult;
1817  pDelete(&sSigMult);
1818  }
1819  else
1820  {
1821  pairsig = sSigMult;
1822  pDelete(&pSigMult);
1823  }
1824  }
1825 
1826  LObject h;
1827  h.p = gcd;
1828  h.tailRing = strat->tailRing;
1829  h.sig = pairsig;
1830  int posx;
1831  h.pCleardenom();
1832  strat->initEcart(&h);
1833  h.sev = pGetShortExpVector(h.p);
1834  h.i_r1 = -1;h.i_r2 = -1;
1835  if (currRing!=strat->tailRing)
1837  if(h.sig == NULL)
1838  {
1839  #ifdef ADIDEBUG
1840  printf("\nPossible sigdrop in enterpairstrongSig (due to lost of sig)\n");
1841  #endif
1842  //sigdrop since we loose the signature
1843  strat->sigdrop = TRUE;
1844  //Try to reduce it as far as we can via redRing
1845  int red_result = redRing(&h,strat);
1846  #ifdef ADIDEBUG
1847  printf("\nAfter redRing reduce:\n");pWrite(h.p);
1848  #endif
1849  if(red_result == 0)
1850  {
1851  // Cancel the sigdrop
1852  #ifdef ADIDEBUG
1853  printf("\nCancel the sigdrop. It reduced to 0\n");
1854  #endif
1855  p_Delete(&h.sig,currRing);h.sig = NULL;
1856  strat->sigdrop = FALSE;
1857  return FALSE;
1858  }
1859  else
1860  {
1861  #ifdef ADIDEBUG
1862  printf("\nSigdrop. end\n");
1863  #endif
1864  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1865  #if 1
1866  strat->enterS(h,0,strat,strat->tl);
1867  #endif
1868  return FALSE;
1869  }
1870  }
1871  if(!nGreaterZero(pGetCoeff(h.sig)))
1872  {
1873  h.sig = pNeg(h.sig);
1874  h.p = pNeg(h.p);
1875  }
1876 
1877  if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1878  {
1879  #ifdef ADIDEBUG
1880  printf("\nSigDrop in enteronestrongpolySig\n");
1881  pWrite(h.sig);
1882  pWrite(p);pWrite(sig);
1883  pWrite(strat->S[i]);pWrite(strat->sig[i]);
1884  #endif
1885  strat->sigdrop = TRUE;
1886  // Completely reduce it
1887  int red_result = redRing(&h,strat);
1888  if(red_result == 0)
1889  {
1890  // Reduced to 0
1891  #ifdef ADIDEBUG
1892  printf("\nCancel the sigdrop after redRing (=0)\n");
1893  #endif
1894  strat->sigdrop = FALSE;
1895  p_Delete(&h.sig,currRing);h.sig = NULL;
1896  return FALSE;
1897  }
1898  else
1899  {
1900  #ifdef ADIDEBUG
1901  printf("\nAfter redRing still sigdrop:\n");pWrite(h.p);
1902  #endif
1903  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1904  // 0 - add just the original poly causing the sigdrop, 1 - add also this
1905  #if 1
1906  strat->enterS(h,0,strat, strat->tl+1);
1907  #endif
1908  return FALSE;
1909  }
1910  }
1911  #ifdef ADIDEBUG
1912  printf("\nThis strong poly was added to L:\n");pWrite(h.p);pWrite(h.p1);pWrite(h.p2);pWrite(h.sig);
1913  #endif
1914  //Check for sigdrop
1915  if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1916  {
1917  #ifdef ADIDEBUG
1918  printf("\nSigDrop in strongpair\noriginals: ");pWrite(sig);pWrite(strat->sig[i]);
1919  printf("\nnow: ");pWrite(pairsig);
1920  #endif
1921  strat->sigdrop = TRUE;
1922  //Enter this element to S
1923  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1924  strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1925  }
1926  #if 1
1927  h.p1 = p;h.p2 = strat->S[i];
1928  #endif
1929  if (atR >= 0)
1930  {
1931  h.i_r2 = strat->S_2_R[i];
1932  h.i_r1 = atR;
1933  }
1934  else
1935  {
1936  h.i_r1 = -1;
1937  h.i_r2 = -1;
1938  }
1939  if (strat->Ll==-1)
1940  posx =0;
1941  else
1942  posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1943  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1944  return TRUE;
1945 }
1946 #endif
1947 
1948 /*2
1949 * put the pair (s[i],p) into the set B, ecart=ecart(p)
1950 */
1951 
1952 void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1953 {
1954  assume(i<=strat->sl);
1955 
1956  int l,j,compare;
1957  LObject Lp;
1958  Lp.i_r = -1;
1959 
1960 #ifdef KDEBUG
1961  Lp.ecart=0; Lp.length=0;
1962 #endif
1963  /*- computes the lcm(s[i],p) -*/
1964  Lp.lcm = pInit();
1965 
1966 #ifndef HAVE_RATGRING
1967  pLcm(p,strat->S[i],Lp.lcm);
1968 #elif defined(HAVE_RATGRING)
1969  if (rIsRatGRing(currRing))
1970  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1971  else
1972  pLcm(p,strat->S[i],Lp.lcm);
1973 #endif
1974  pSetm(Lp.lcm);
1975 
1976 
1978  {
1979  if((!((strat->ecartS[i]>0)&&(ecart>0)))
1980  && pHasNotCF(p,strat->S[i]))
1981  {
1982  /*
1983  *the product criterion has applied for (s,p),
1984  *i.e. lcm(s,p)=product of the leading terms of s and p.
1985  *Suppose (s,r) is in L and the leading term
1986  *of p divides lcm(s,r)
1987  *(==> the leading term of p divides the leading term of r)
1988  *but the leading term of s does not divide the leading term of r
1989  *(notice that tis condition is automatically satisfied if r is still
1990  *in S), then (s,r) can be cancelled.
1991  *This should be done here because the
1992  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1993  *
1994  *Moreover, skipping (s,r) holds also for the noncommutative case.
1995  */
1996  strat->cp++;
1997  pLmFree(Lp.lcm);
1998  return;
1999  }
2000  else
2001  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2002  if (strat->fromT && (strat->ecartS[i]>ecart))
2003  {
2004  pLmFree(Lp.lcm);
2005  return;
2006  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2007  }
2008  /*
2009  *the set B collects the pairs of type (S[j],p)
2010  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2011  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2012  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2013  */
2014  {
2015  j = strat->Bl;
2016  loop
2017  {
2018  if (j < 0) break;
2019  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2020  if ((compare==1)
2021  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2022  {
2023  strat->c3++;
2024  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2025  {
2026  pLmFree(Lp.lcm);
2027  return;
2028  }
2029  break;
2030  }
2031  else
2032  if ((compare ==-1)
2033  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2034  {
2035  deleteInL(strat->B,&strat->Bl,j,strat);
2036  strat->c3++;
2037  }
2038  j--;
2039  }
2040  }
2041  }
2042  else /*sugarcrit*/
2043  {
2044  if (ALLOW_PROD_CRIT(strat))
2045  {
2046  // if currRing->nc_type!=quasi (or skew)
2047  // TODO: enable productCrit for super commutative algebras...
2048  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2049  pHasNotCF(p,strat->S[i]))
2050  {
2051  /*
2052  *the product criterion has applied for (s,p),
2053  *i.e. lcm(s,p)=product of the leading terms of s and p.
2054  *Suppose (s,r) is in L and the leading term
2055  *of p devides lcm(s,r)
2056  *(==> the leading term of p devides the leading term of r)
2057  *but the leading term of s does not devide the leading term of r
2058  *(notice that tis condition is automatically satisfied if r is still
2059  *in S), then (s,r) can be canceled.
2060  *This should be done here because the
2061  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2062  */
2063  strat->cp++;
2064  pLmFree(Lp.lcm);
2065  return;
2066  }
2067  if (strat->fromT && (strat->ecartS[i]>ecart))
2068  {
2069  pLmFree(Lp.lcm);
2070  return;
2071  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2072  }
2073  /*
2074  *the set B collects the pairs of type (S[j],p)
2075  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2076  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2077  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2078  */
2079  for(j = strat->Bl;j>=0;j--)
2080  {
2081  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2082  if (compare==1)
2083  {
2084  strat->c3++;
2085  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2086  {
2087  pLmFree(Lp.lcm);
2088  return;
2089  }
2090  break;
2091  }
2092  else
2093  if (compare ==-1)
2094  {
2095  deleteInL(strat->B,&strat->Bl,j,strat);
2096  strat->c3++;
2097  }
2098  }
2099  }
2100  }
2101  /*
2102  *the pair (S[i],p) enters B if the spoly != 0
2103  */
2104  /*- compute the short s-polynomial -*/
2105  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2106  pNorm(p);
2107 
2108  if ((strat->S[i]==NULL) || (p==NULL))
2109  return;
2110 
2111  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2112  Lp.p=NULL;
2113  else
2114  {
2115  #ifdef HAVE_PLURAL
2116  if ( rIsPluralRing(currRing) )
2117  {
2118  if(pHasNotCF(p, strat->S[i]))
2119  {
2120  if(ncRingType(currRing) == nc_lie)
2121  {
2122  // generalized prod-crit for lie-type
2123  strat->cp++;
2124  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2125  }
2126  else
2127  if( ALLOW_PROD_CRIT(strat) )
2128  {
2129  // product criterion for homogeneous case in SCA
2130  strat->cp++;
2131  Lp.p = NULL;
2132  }
2133  else
2134  {
2135  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2137  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2138  pNext(Lp.p) = strat->tail; // !!!
2139  }
2140  }
2141  else
2142  {
2143  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2145 
2146  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2147  pNext(Lp.p) = strat->tail; // !!!
2148  }
2149  }
2150  else
2151  #endif
2152  {
2154  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2155  }
2156  }
2157  if (Lp.p == NULL)
2158  {
2159  /*- the case that the s-poly is 0 -*/
2161  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2162  strat->pairtest[strat->sl+1] = TRUE;
2163  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2164  /*
2165  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2166  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2167  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2168  *term of p devides the lcm(s,r)
2169  *(this canceling should be done here because
2170  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2171  *the first case is handeled in chainCrit
2172  */
2173  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2174  }
2175  else
2176  {
2177  /*- the pair (S[i],p) enters B -*/
2178  Lp.p1 = strat->S[i];
2179  Lp.p2 = p;
2180 
2181  if (
2183 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2184  )
2185  {
2186  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2187  pNext(Lp.p) = strat->tail; // !!!
2188  }
2189 
2190  if (atR >= 0)
2191  {
2192  Lp.i_r1 = strat->S_2_R[i];
2193  Lp.i_r2 = atR;
2194  }
2195  else
2196  {
2197  Lp.i_r1 = -1;
2198  Lp.i_r2 = -1;
2199  }
2200  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2201 
2203  {
2204  if (!rIsPluralRing(currRing))
2205  nDelete(&(Lp.p->coef));
2206  }
2207 
2208  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2209  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2210  }
2211 }
2212 
2213 /// p_HasNotCF for the IDLIFT case: ignore component
2214 static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2215 {
2216  int i = rVar(r);
2217  loop
2218  {
2219  if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2220  return FALSE;
2221  i--;
2222  if (i == 0)
2223  return TRUE;
2224  }
2225 }
2226 
2227 /*2
2228 * put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2229 */
2230 
2231 static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2232 {
2235  assume(strat->syzComp==1);
2236  assume(i<=strat->sl);
2237 
2238  if ((strat->S[i]==NULL) || (p==NULL))
2239  return;
2240 
2241  int l,j,compare;
2242  LObject Lp;
2243  Lp.i_r = -1;
2244 
2245 #ifdef KDEBUG
2246  Lp.ecart=0; Lp.length=0;
2247 #endif
2248  /*- computes the lcm(s[i],p) -*/
2249  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2250 
2251  if (strat->sugarCrit)
2252  {
2253  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2255  {
2256  /*
2257  *the product criterion has applied for (s,p),
2258  *i.e. lcm(s,p)=product of the leading terms of s and p.
2259  *Suppose (s,r) is in L and the leading term
2260  *of p divides lcm(s,r)
2261  *(==> the leading term of p divides the leading term of r)
2262  *but the leading term of s does not divide the leading term of r
2263  *(notice that tis condition is automatically satisfied if r is still
2264  *in S), then (s,r) can be cancelled.
2265  *This should be done here because the
2266  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2267  *
2268  *Moreover, skipping (s,r) holds also for the noncommutative case.
2269  */
2270  strat->cp++;
2271  pLmFree(Lp.lcm);
2272  return;
2273  }
2274  else
2275  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2276  if (strat->fromT && (strat->ecartS[i]>ecart))
2277  {
2278  pLmFree(Lp.lcm);
2279  return;
2280  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2281  }
2282  /*
2283  *the set B collects the pairs of type (S[j],p)
2284  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2285  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2286  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2287  */
2288  {
2289  j = strat->Bl;
2290  loop
2291  {
2292  if (j < 0) break;
2293  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2294  if ((compare==1)
2295  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2296  {
2297  strat->c3++;
2298  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2299  {
2300  pLmFree(Lp.lcm);
2301  return;
2302  }
2303  break;
2304  }
2305  else
2306  if ((compare ==-1)
2307  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2308  {
2309  deleteInL(strat->B,&strat->Bl,j,strat);
2310  strat->c3++;
2311  }
2312  j--;
2313  }
2314  }
2315  }
2316  else /*sugarcrit*/
2317  {
2318  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2320  {
2321  /*
2322  *the product criterion has applied for (s,p),
2323  *i.e. lcm(s,p)=product of the leading terms of s and p.
2324  *Suppose (s,r) is in L and the leading term
2325  *of p devides lcm(s,r)
2326  *(==> the leading term of p devides the leading term of r)
2327  *but the leading term of s does not devide the leading term of r
2328  *(notice that tis condition is automatically satisfied if r is still
2329  *in S), then (s,r) can be canceled.
2330  *This should be done here because the
2331  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2332  */
2333  strat->cp++;
2334  pLmFree(Lp.lcm);
2335  return;
2336  }
2337  if (strat->fromT && (strat->ecartS[i]>ecart))
2338  {
2339  pLmFree(Lp.lcm);
2340  return;
2341  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2342  }
2343  /*
2344  *the set B collects the pairs of type (S[j],p)
2345  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2346  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
2347  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
2348  */
2349  for(j = strat->Bl;j>=0;j--)
2350  {
2351  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2352  if (compare==1)
2353  {
2354  strat->c3++;
2355  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2356  {
2357  pLmFree(Lp.lcm);
2358  return;
2359  }
2360  break;
2361  }
2362  else
2363  if (compare ==-1)
2364  {
2365  deleteInL(strat->B,&strat->Bl,j,strat);
2366  strat->c3++;
2367  }
2368  }
2369  }
2370  /*
2371  *the pair (S[i],p) enters B if the spoly != 0
2372  */
2373  /*- compute the short s-polynomial -*/
2374  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2375  pNorm(p);
2376 
2377  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2378  Lp.p=NULL;
2379  else
2380  {
2382  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2383  }
2384  if (Lp.p == NULL)
2385  {
2386  /*- the case that the s-poly is 0 -*/
2388  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2389  strat->pairtest[strat->sl+1] = TRUE;
2390  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2391  /*
2392  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2393  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2394  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2395  *term of p devides the lcm(s,r)
2396  *(this canceling should be done here because
2397  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2398  *the first case is handeled in chainCrit
2399  */
2400  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2401  }
2402  else
2403  {
2404  /*- the pair (S[i],p) enters B -*/
2405  Lp.p1 = strat->S[i];
2406  Lp.p2 = p;
2407 
2408  pNext(Lp.p) = strat->tail; // !!!
2409 
2410  if (atR >= 0)
2411  {
2412  Lp.i_r1 = strat->S_2_R[i];
2413  Lp.i_r2 = atR;
2414  }
2415  else
2416  {
2417  Lp.i_r1 = -1;
2418  Lp.i_r2 = -1;
2419  }
2420  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2421 
2423  {
2424  nDelete(&(Lp.p->coef));
2425  }
2426 
2427  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2428  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2429  }
2430 }
2431 
2432 /*2
2433 * put the pair (s[i],p) into the set B, ecart=ecart(p)
2434 * NOTE: here we need to add the signature-based criteria
2435 */
2436 
2437 #ifdef DEBUGF5
2438 static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2439 #else
2440 static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2441 #endif
2442 {
2443  assume(i<=strat->sl);
2444 
2445  int l;
2446  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2447  // the corresponding signatures for criteria checks
2448  LObject Lp;
2449  poly pSigMult = p_Copy(pSig,currRing);
2450  poly sSigMult = p_Copy(strat->sig[i],currRing);
2451  unsigned long pSigMultNegSev,sSigMultNegSev;
2452  Lp.i_r = -1;
2453 
2454 #ifdef KDEBUG
2455  Lp.ecart=0; Lp.length=0;
2456 #endif
2457  /*- computes the lcm(s[i],p) -*/
2458  Lp.lcm = pInit();
2460 #ifndef HAVE_RATGRING
2461  pLcm(p,strat->S[i],Lp.lcm);
2462 #elif defined(HAVE_RATGRING)
2463  if (rIsRatGRing(currRing))
2464  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2465  else
2466  pLcm(p,strat->S[i],Lp.lcm);
2467 #endif
2468  pSetm(Lp.lcm);
2469 
2470  // set coeffs of multipliers m1 and m2
2471  pSetCoeff0(m1, nInit(1));
2472  pSetCoeff0(m2, nInit(1));
2473 //#if 1
2474 #ifdef DEBUGF5
2475  PrintS("P1 ");
2476  pWrite(pHead(p));
2477  PrintS("P2 ");
2478  pWrite(pHead(strat->S[i]));
2479  PrintS("M1 ");
2480  pWrite(m1);
2481  PrintS("M2 ");
2482  pWrite(m2);
2483 #endif
2484  // get multiplied signatures for testing
2485  pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2486  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2487  sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2488  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2489 
2490 //#if 1
2491 #ifdef DEBUGF5
2492  PrintS("----------------\n");
2493  pWrite(pSigMult);
2494  pWrite(sSigMult);
2495  PrintS("----------------\n");
2496  Lp.checked = 0;
2497 #endif
2498  int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2499 //#if 1
2500 #if DEBUGF5
2501  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2502  pWrite(pSigMult);
2503  pWrite(sSigMult);
2504 #endif
2505  if(sigCmp==0)
2506  {
2507  // printf("!!!! EQUAL SIGS !!!!\n");
2508  // pSig = sSig, delete element due to Rewritten Criterion
2509  pDelete(&pSigMult);
2510  pDelete(&sSigMult);
2511  if (rField_is_Ring(currRing))
2512  pLmDelete(Lp.lcm);
2513  else
2514  pLmFree(Lp.lcm);
2515  pDelete (&m1);
2516  pDelete (&m2);
2517  return;
2518  }
2519  // testing by syzCrit = F5 Criterion
2520  // testing by rewCrit1 = Rewritten Criterion
2521  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2522  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2523  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2524  || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2525  )
2526  {
2527  pDelete(&pSigMult);
2528  pDelete(&sSigMult);
2529  if (rField_is_Ring(currRing))
2530  pLmDelete(Lp.lcm);
2531  else
2532  pLmFree(Lp.lcm);
2533  pDelete (&m1);
2534  pDelete (&m2);
2535  return;
2536  }
2537  /*
2538  *the pair (S[i],p) enters B if the spoly != 0
2539  */
2540  /*- compute the short s-polynomial -*/
2541  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2542  pNorm(p);
2543 
2544  if ((strat->S[i]==NULL) || (p==NULL))
2545  return;
2546 
2547  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2548  Lp.p=NULL;
2549  else
2550  {
2551  #ifdef HAVE_PLURAL
2552  if ( rIsPluralRing(currRing) )
2553  {
2554  if(pHasNotCF(p, strat->S[i]))
2555  {
2556  if(ncRingType(currRing) == nc_lie)
2557  {
2558  // generalized prod-crit for lie-type
2559  strat->cp++;
2560  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2561  }
2562  else
2563  if( ALLOW_PROD_CRIT(strat) )
2564  {
2565  // product criterion for homogeneous case in SCA
2566  strat->cp++;
2567  Lp.p = NULL;
2568  }
2569  else
2570  {
2571  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2573 
2574  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2575  pNext(Lp.p) = strat->tail; // !!!
2576  }
2577  }
2578  else
2579  {
2580  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2582 
2583  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2584  pNext(Lp.p) = strat->tail; // !!!
2585  }
2586  }
2587  else
2588  #endif
2589  {
2591  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2592  }
2593  }
2594  // store from which element this pair comes from for further tests
2595  //Lp.from = strat->sl+1;
2596  if(sigCmp==currRing->OrdSgn)
2597  {
2598  // pSig > sSig
2599  pDelete (&sSigMult);
2600  Lp.sig = pSigMult;
2601  Lp.sevSig = ~pSigMultNegSev;
2602  }
2603  else
2604  {
2605  // pSig < sSig
2606  pDelete (&pSigMult);
2607  Lp.sig = sSigMult;
2608  Lp.sevSig = ~sSigMultNegSev;
2609  }
2610  if (Lp.p == NULL)
2611  {
2612  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2613  int pos = posInSyz(strat, Lp.sig);
2614  enterSyz(Lp, strat, pos);
2615  }
2616  else
2617  {
2618  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2619  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2620  {
2621  pLmFree(Lp.lcm);
2622  pDelete(&Lp.sig);
2623  pDelete (&m1);
2624  pDelete (&m2);
2625  return;
2626  }
2627  // in any case Lp is checked up to the next strat->P which is added
2628  // to S right after this critical pair creation.
2629  // NOTE: this even holds if the 2nd generator gives the bigger signature
2630  // moreover, this improves rewCriterion,
2631  // i.e. strat->checked > strat->from if and only if the 2nd generator
2632  // gives the bigger signature.
2633  Lp.checked = strat->sl+1;
2634  // at this point it is clear that the pair will be added to L, since it has
2635  // passed all tests up to now
2636 
2637  // adds buchberger's first criterion
2638  if (pLmCmp(m2,pHead(p)) == 0)
2639  {
2640  Lp.prod_crit = TRUE; // Product Criterion
2641 #if 0
2642  int pos = posInSyz(strat, Lp.sig);
2643  enterSyz(Lp, strat, pos);
2644  pDelete (&m1);
2645  pDelete (&m2);
2646  return;
2647 #endif
2648  }
2649  pDelete (&m1);
2650  pDelete (&m2);
2651 #if DEBUGF5
2652  PrintS("SIGNATURE OF PAIR: ");
2653  pWrite(Lp.sig);
2654 #endif
2655  /*- the pair (S[i],p) enters B -*/
2656  Lp.p1 = strat->S[i];
2657  Lp.p2 = p;
2658 
2659  if (
2661 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2662  )
2663  {
2664  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2665  pNext(Lp.p) = strat->tail; // !!!
2666  }
2667 
2668  if (atR >= 0)
2669  {
2670  Lp.i_r1 = strat->S_2_R[i];
2671  Lp.i_r2 = atR;
2672  }
2673  else
2674  {
2675  Lp.i_r1 = -1;
2676  Lp.i_r2 = -1;
2677  }
2678  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2679 
2681  {
2682  if (!rIsPluralRing(currRing))
2683  nDelete(&(Lp.p->coef));
2684  }
2685 
2686  l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2687  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2688  }
2689 }
2690 
2691 
2692 #ifdef DEBUGF5
2693 static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2694 #else
2695 static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2696 #endif
2697 {
2698  #ifdef ADIDEBUG
2699  printf("\nTrying to add p and S[%i]\n",i);
2700  pWrite(p);pWrite(pSig);
2701  pWrite(strat->S[i]);pWrite(strat->sig[i]);
2702  #endif
2703  #if ALL_VS_JUST
2704  //Over rings, if we construct the strong pair, do not add the spair
2706  {
2707  number s,t,d;
2708  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2709 
2710  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2711  {
2712  nDelete(&d);
2713  nDelete(&s);
2714  nDelete(&t);
2715  return;
2716  }
2717  nDelete(&d);
2718  nDelete(&s);
2719  nDelete(&t);
2720  }
2721  #endif
2722  assume(i<=strat->sl);
2723  int l;
2724  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2725  // the corresponding signatures for criteria checks
2726  LObject Lp;
2727  poly pSigMult = p_Copy(pSig,currRing);
2728  poly sSigMult = p_Copy(strat->sig[i],currRing);
2729  unsigned long pSigMultNegSev,sSigMultNegSev;
2730  Lp.i_r = -1;
2731 
2732 #ifdef KDEBUG
2733  Lp.ecart=0; Lp.length=0;
2734 #endif
2735  /*- computes the lcm(s[i],p) -*/
2736  Lp.lcm = pInit();
2738 #ifndef HAVE_RATGRING
2739  pLcm(p,strat->S[i],Lp.lcm);
2740 #elif defined(HAVE_RATGRING)
2741  if (rIsRatGRing(currRing))
2742  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2743  else
2744  pLcm(p,strat->S[i],Lp.lcm);
2745 #endif
2746  pSetm(Lp.lcm);
2747 
2748  // set coeffs of multipliers m1 and m2
2750  {
2751  number s = nCopy(pGetCoeff(strat->S[i]));
2752  number t = nCopy(pGetCoeff(p));
2753  pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2754  ksCheckCoeff(&s, &t, currRing->cf);
2755  pSetCoeff0(m1,s);
2756  pSetCoeff0(m2,t);
2757  #ifdef ADIDEBUG
2758  printf("\nIn Spoly: m1, m2 :\n");pWrite(m1);pWrite(m2);
2759  #endif
2760  }
2761  else
2762  {
2763  pSetCoeff0(m1, nInit(1));
2764  pSetCoeff0(m2, nInit(1));
2765  }
2766 #ifdef DEBUGF5
2767  Print("P1 ");
2768  pWrite(pHead(p));
2769  Print("P2 ");
2770  pWrite(pHead(strat->S[i]));
2771  Print("M1 ");
2772  pWrite(m1);
2773  Print("M2 ");
2774  pWrite(m2);
2775 #endif
2776 
2777  // get multiplied signatures for testing
2778  pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2779  if(pSigMult != NULL)
2780  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2781  sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2782  if(sSigMult != NULL)
2783  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2784 //#if 1
2785 #ifdef DEBUGF5
2786  Print("----------------\n");
2787  pWrite(pSigMult);
2788  pWrite(sSigMult);
2789  Print("----------------\n");
2790  Lp.checked = 0;
2791 #endif
2792  int sigCmp;
2793  if(pSigMult != NULL && sSigMult != NULL)
2794  {
2796  sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2797  else
2798  sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2799  }
2800  else
2801  {
2802  if(pSigMult == NULL)
2803  {
2804  if(sSigMult == NULL)
2805  sigCmp = 0;
2806  else
2807  sigCmp = -1;
2808  }
2809  else
2810  sigCmp = 1;
2811  }
2812 //#if 1
2813 #if DEBUGF5
2814  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2815  pWrite(pSigMult);
2816  pWrite(sSigMult);
2817 #endif
2818  //In the ring case we already build the sig
2820  {
2821  if(sigCmp == 0)
2822  {
2823  #ifdef ADIDEBUG
2824  printf("\nPossible sigdrop in enterpairSig (due to lost of sig)\n");
2825  #endif
2826  //sigdrop since we loose the signature
2827  strat->sigdrop = TRUE;
2828  //Try to reduce it as far as we can via redRing
2830  {
2831  poly p1 = p_Copy(p,currRing);
2832  poly p2 = p_Copy(strat->S[i],currRing);
2833  p1 = p_Mult_mm(p1,m1,currRing);
2834  p2 = p_Mult_mm(p2,m2,currRing);
2835  Lp.p = p_Sub(p1,p2,currRing);
2836  if(Lp.p != NULL)
2837  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2838  }
2839  int red_result = redRing(&Lp,strat);
2840  #ifdef ADIDEBUG
2841  printf("\nAfter redRing reduce:\n");pWrite(Lp.p);
2842  #endif
2843  if(red_result == 0)
2844  {
2845  // Cancel the sigdrop
2846  #ifdef ADIDEBUG
2847  printf("\nCancel the sigdrop. It reduced to 0\n");
2848  #endif
2849  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2850  strat->sigdrop = FALSE;
2851  return;
2852  }
2853  else
2854  {
2855  #ifdef ADIDEBUG
2856  printf("\nSigdrop. end\n");
2857  #endif
2858  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2859  #if 1
2860  strat->enterS(Lp,0,strat,strat->tl);
2861  #endif
2862  return;
2863  }
2864  }
2865  if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2866  {
2867  //Same lm, have to substract
2868  Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2869  }
2870  else
2871  {
2872  if(sigCmp == 1)
2873  {
2874  Lp.sig = pCopy(pSigMult);
2875  }
2876  if(sigCmp == -1)
2877  {
2878  Lp.sig = pNeg(pCopy(sSigMult));
2879  }
2880  }
2881  Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2882  }
2883 
2884  #if 0
2885  if(sigCmp==0)
2886  {
2887  // printf("!!!! EQUAL SIGS !!!!\n");
2888  // pSig = sSig, delete element due to Rewritten Criterion
2889  pDelete(&pSigMult);
2890  pDelete(&sSigMult);
2891  if (rField_is_Ring(currRing))
2892  pLmDelete(Lp.lcm);
2893  else
2894  pLmFree(Lp.lcm);
2895  pDelete (&m1);
2896  pDelete (&m2);
2897  return;
2898  }
2899  #endif
2900  // testing by syzCrit = F5 Criterion
2901  // testing by rewCrit1 = Rewritten Criterion
2902  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2903  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2904  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2905  // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2906  //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2907  )
2908  {
2909  #ifdef ADIDEBUG
2910  printf("\nDELETED!\n");
2911  #endif
2912  pDelete(&pSigMult);
2913  pDelete(&sSigMult);
2914  if (rField_is_Ring(currRing))
2915  pLmDelete(Lp.lcm);
2916  else
2917  pLmFree(Lp.lcm);
2918  pDelete (&m1);
2919  pDelete (&m2);
2920  return;
2921  }
2922  /*
2923  *the pair (S[i],p) enters B if the spoly != 0
2924  */
2925  /*- compute the short s-polynomial -*/
2926  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2927  pNorm(p);
2928 
2929  if ((strat->S[i]==NULL) || (p==NULL))
2930  return;
2931 
2932  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2933  Lp.p=NULL;
2934  else
2935  {
2936  //Build p
2938  {
2939  poly p1 = p_Copy(p,currRing);
2940  poly p2 = p_Copy(strat->S[i],currRing);
2941  p1 = p_Mult_mm(p1,m1,currRing);
2942  p2 = p_Mult_mm(p2,m2,currRing);
2943  Lp.p = p_Sub(p1,p2,currRing);
2944  if(Lp.p != NULL)
2945  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2946  }
2947  else
2948  {
2949  #ifdef HAVE_PLURAL
2950  if ( rIsPluralRing(currRing) )
2951  {
2952  if(ncRingType(currRing) == nc_lie)
2953  {
2954  // generalized prod-crit for lie-type
2955  strat->cp++;
2956  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2957  }
2958  else
2959  if( ALLOW_PROD_CRIT(strat) )
2960  {
2961  // product criterion for homogeneous case in SCA
2962  strat->cp++;
2963  Lp.p = NULL;
2964  }
2965  else
2966  {
2967  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2969 
2970  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2971  pNext(Lp.p) = strat->tail; // !!!
2972  }
2973  }
2974  else
2975  #endif
2976  {
2978  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2979  }
2980  }
2981  }
2982  // store from which element this pair comes from for further tests
2983  //Lp.from = strat->sl+1;
2985  {
2986  //Put the sig to be > 0
2987  if(!nGreaterZero(pGetCoeff(Lp.sig)))
2988  {
2989  Lp.sig = pNeg(Lp.sig);
2990  Lp.p = pNeg(Lp.p);
2991  }
2992  }
2993  else
2994  {
2995  if(sigCmp==currRing->OrdSgn)
2996  {
2997  // pSig > sSig
2998  pDelete (&sSigMult);
2999  Lp.sig = pSigMult;
3000  Lp.sevSig = ~pSigMultNegSev;
3001  }
3002  else
3003  {
3004  // pSig < sSig
3005  pDelete (&pSigMult);
3006  Lp.sig = sSigMult;
3007  Lp.sevSig = ~sSigMultNegSev;
3008  }
3009  }
3010  if (Lp.p == NULL)
3011  {
3012  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
3013  int pos = posInSyz(strat, Lp.sig);
3014  enterSyz(Lp, strat, pos);
3015  }
3016  else
3017  {
3018  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
3019  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
3020  {
3021  pLmFree(Lp.lcm);
3022  #ifdef ADIDEBUG
3023  printf("\nrewCrit3 deletes it!\n");
3024  #endif
3025  pDelete(&Lp.sig);
3026  pDelete (&m1);
3027  pDelete (&m2);
3028  return;
3029  }
3030  // in any case Lp is checked up to the next strat->P which is added
3031  // to S right after this critical pair creation.
3032  // NOTE: this even holds if the 2nd generator gives the bigger signature
3033  // moreover, this improves rewCriterion,
3034  // i.e. strat->checked > strat->from if and only if the 2nd generator
3035  // gives the bigger signature.
3036  Lp.checked = strat->sl+1;
3037  // at this point it is clear that the pair will be added to L, since it has
3038  // passed all tests up to now
3039 
3040  // adds buchberger's first criterion
3041  if (pLmCmp(m2,pHead(p)) == 0)
3042  {
3043  Lp.prod_crit = TRUE; // Product Criterion
3044 #if 0
3045  int pos = posInSyz(strat, Lp.sig);
3046  enterSyz(Lp, strat, pos);
3047  pDelete (&m1);
3048  pDelete (&m2);
3049  return;
3050 #endif
3051  }
3052  pDelete (&m1);
3053  pDelete (&m2);
3054 #if DEBUGF5
3055  PrintS("SIGNATURE OF PAIR: ");
3056  pWrite(Lp.sig);
3057 #endif
3058  /*- the pair (S[i],p) enters B -*/
3059  Lp.p1 = strat->S[i];
3060  Lp.p2 = p;
3061 
3062  if (
3064 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3066  )
3067  {
3068  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3069  pNext(Lp.p) = strat->tail; // !!!
3070  }
3071 
3072  if (atR >= 0)
3073  {
3074  Lp.i_r1 = strat->S_2_R[i];
3075  Lp.i_r2 = atR;
3076  }
3077  else
3078  {
3079  Lp.i_r1 = -1;
3080  Lp.i_r2 = -1;
3081  }
3082  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3083 
3085  {
3087  nDelete(&(Lp.p->coef));
3088  }
3089  // Check for sigdrop
3090  if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3091  {
3092  #ifdef ADIDEBUG
3093  printf("\nSigDrop in enteronepairSig\n");pWrite(Lp.sig);
3094  pWrite(p);pWrite(pSig);
3095  pWrite(strat->S[i]);pWrite(strat->sig[i]);
3096  #endif
3097  strat->sigdrop = TRUE;
3098  // Completely reduce it
3099  int red_result = redRing(&Lp,strat);
3100  if(red_result == 0)
3101  {
3102  // Reduced to 0
3103  #ifdef ADIDEBUG
3104  printf("\nCancel the sigdrop after redRing (=0)\n");
3105  #endif
3106  strat->sigdrop = FALSE;
3107  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3108  return;
3109  }
3110  else
3111  {
3112  #ifdef ADIDEBUG
3113  printf("\nAfter redRing still sigdrop:\n");pWrite(Lp.p);
3114  #endif
3115  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3116  // 0 - add just the original poly causing the sigdrop, 1 - add also this
3117  #if 1
3118  strat->enterS(Lp,0,strat, strat->tl+1);
3119  #endif
3120  return;
3121  }
3122  }
3123  #ifdef ADIDEBUG
3124  printf("\nThis spair was added to B:\n");
3125  pWrite(Lp.p);
3126  pWrite(Lp.p1);
3127  pWrite(Lp.p2);
3128  pWrite(Lp.sig);
3129  #endif
3130  l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3131  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3132  }
3133 }
3134 
3135 /*2
3136 * put the pair (s[i],p) into the set L, ecart=ecart(p)
3137 * in the case that s forms a SB of (s)
3138 */
3139 void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3140 {
3141  //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3142  if(pHasNotCF(p,strat->S[i]))
3143  {
3144  //PrintS("prod-crit\n");
3145  if(ALLOW_PROD_CRIT(strat))
3146  {
3147  //PrintS("prod-crit\n");
3148  strat->cp++;
3149  return;
3150  }
3151  }
3152 
3153  int l;
3154  LObject Lp;
3155  Lp.i_r = -1;
3156 
3157  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3158  /*- compute the short s-polynomial -*/
3159 
3160  #ifdef HAVE_PLURAL
3161  if (rIsPluralRing(currRing))
3162  {
3163  Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3164  }
3165  else
3166  #endif
3167  Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3168 
3169  if (Lp.p == NULL)
3170  {
3171  //PrintS("short spoly==NULL\n");
3172  pLmFree(Lp.lcm);
3173  }
3174  else
3175  {
3176  /*- the pair (S[i],p) enters L -*/
3177  Lp.p1 = strat->S[i];
3178  Lp.p2 = p;
3179  if (atR >= 0)
3180  {
3181  Lp.i_r1 = strat->S_2_R[i];
3182  Lp.i_r2 = atR;
3183  }
3184  else
3185  {
3186  Lp.i_r1 = -1;
3187  Lp.i_r2 = -1;
3188  }
3189  assume(pNext(Lp.p) == NULL);
3190  pNext(Lp.p) = strat->tail;
3191  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3193  {
3194  nDelete(&(Lp.p->coef));
3195  }
3196  l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3197  //Print("-> L[%d]\n",l);
3198  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3199  }
3200 }
3201 
3202 /*2
3203 * merge set B into L
3204 */
3206 {
3207  int j=strat->Ll+strat->Bl+1;
3208  if (j>strat->Lmax)
3209  {
3211  enlargeL(&(strat->L),&(strat->Lmax),j);
3212  }
3213  j = strat->Ll;
3214  int i;
3215  for (i=strat->Bl; i>=0; i--)
3216  {
3217  j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3218  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3219  }
3220  strat->Bl = -1;
3221 }
3222 
3223 /*2
3224 * merge set B into L
3225 */
3227 {
3228  int j=strat->Ll+strat->Bl+1;
3229  if (j>strat->Lmax)
3230  {
3232  enlargeL(&(strat->L),&(strat->Lmax),j);
3233  }
3234  j = strat->Ll;
3235  int i;
3236  for (i=strat->Bl; i>=0; i--)
3237  {
3238  j = strat->posInLSba(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 /*2
3244 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3245 *using the chain-criterion in B and L and enters B to L
3246 */
3248 {
3249  int i,j,l;
3250 
3251  /*
3252  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3253  *In this case all elements in B such
3254  *that their lcm is divisible by the leading term of S[i] can be canceled
3255  */
3256  if (strat->pairtest!=NULL)
3257  {
3258  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3259  for (j=0; j<=strat->sl; j++)
3260  {
3261  if (strat->pairtest[j])
3262  {
3263  for (i=strat->Bl; i>=0; i--)
3264  {
3265  if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3266  {
3267  deleteInL(strat->B,&strat->Bl,i,strat);
3268  strat->c3++;
3269  }
3270  }
3271  }
3272  }
3273  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3274  strat->pairtest=NULL;
3275  }
3276  if (strat->Gebauer || strat->fromT)
3277  {
3278  if (strat->sugarCrit)
3279  {
3280  /*
3281  *suppose L[j] == (s,r) and p/lcm(s,r)
3282  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3283  *and in case the sugar is o.k. then L[j] can be canceled
3284  */
3285  for (j=strat->Ll; j>=0; j--)
3286  {
3287  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3288  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3289  && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3290  {
3291  if (strat->L[j].p == strat->tail)
3292  {
3293  deleteInL(strat->L,&strat->Ll,j,strat);
3294  strat->c3++;
3295  }
3296  }
3297  }
3298  /*
3299  *this is GEBAUER-MOELLER:
3300  *in B all elements with the same lcm except the "best"
3301  *(i.e. the last one in B with this property) will be canceled
3302  */
3303  j = strat->Bl;
3304  loop /*cannot be changed into a for !!! */
3305  {
3306  if (j <= 0) break;
3307  i = j-1;
3308  loop
3309  {
3310  if (i < 0) break;
3311  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3312  {
3313  strat->c3++;
3314  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3315  {
3316  deleteInL(strat->B,&strat->Bl,i,strat);
3317  j--;
3318  }
3319  else
3320  {
3321  deleteInL(strat->B,&strat->Bl,j,strat);
3322  break;
3323  }
3324  }
3325  i--;
3326  }
3327  j--;
3328  }
3329  }
3330  else /*sugarCrit*/
3331  {
3332  /*
3333  *suppose L[j] == (s,r) and p/lcm(s,r)
3334  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3335  *and in case the sugar is o.k. then L[j] can be canceled
3336  */
3337  for (j=strat->Ll; j>=0; j--)
3338  {
3339  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3340  {
3341  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3342  {
3343  deleteInL(strat->L,&strat->Ll,j,strat);
3344  strat->c3++;
3345  }
3346  }
3347  }
3348  /*
3349  *this is GEBAUER-MOELLER:
3350  *in B all elements with the same lcm except the "best"
3351  *(i.e. the last one in B with this property) will be canceled
3352  */
3353  j = strat->Bl;
3354  loop /*cannot be changed into a for !!! */
3355  {
3356  if (j <= 0) break;
3357  for(i=j-1; i>=0; i--)
3358  {
3359  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3360  {
3361  strat->c3++;
3362  deleteInL(strat->B,&strat->Bl,i,strat);
3363  j--;
3364  }
3365  }
3366  j--;
3367  }
3368  }
3369  /*
3370  *the elements of B enter L
3371  */
3373  }
3374  else
3375  {
3376  for (j=strat->Ll; j>=0; j--)
3377  {
3378  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3379  {
3380  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3381  {
3382  deleteInL(strat->L,&strat->Ll,j,strat);
3383  strat->c3++;
3384  }
3385  }
3386  }
3387  /*
3388  *this is our MODIFICATION of GEBAUER-MOELLER:
3389  *First the elements of B enter L,
3390  *then we fix a lcm and the "best" element in L
3391  *(i.e the last in L with this lcm and of type (s,p))
3392  *and cancel all the other elements of type (r,p) with this lcm
3393  *except the case the element (s,r) has also the same lcm
3394  *and is on the worst position with respect to (s,p) and (r,p)
3395  */
3396  /*
3397  *B enters to L/their order with respect to B is permutated for elements
3398  *B[i].p with the same leading term
3399  */
3401  j = strat->Ll;
3402  loop /*cannot be changed into a for !!! */
3403  {
3404  if (j <= 0)
3405  {
3406  /*now L[0] cannot be canceled any more and the tail can be removed*/
3407  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3408  break;
3409  }
3410  if (strat->L[j].p2 == p)
3411  {
3412  i = j-1;
3413  loop
3414  {
3415  if (i < 0) break;
3416  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3417  {
3418  /*L[i] could be canceled but we search for a better one to cancel*/
3419  strat->c3++;
3420  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3421  && (pNext(strat->L[l].p) == strat->tail)
3422  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3423  && pDivisibleBy(p,strat->L[l].lcm))
3424  {
3425  /*
3426  *"NOT equal(...)" because in case of "equal" the element L[l]
3427  *is "older" and has to be from theoretical point of view behind
3428  *L[i], but we do not want to reorder L
3429  */
3430  strat->L[i].p2 = strat->tail;
3431  /*
3432  *L[l] will be canceled, we cannot cancel L[i] later on,
3433  *so we mark it with "tail"
3434  */
3435  deleteInL(strat->L,&strat->Ll,l,strat);
3436  i--;
3437  }
3438  else
3439  {
3440  deleteInL(strat->L,&strat->Ll,i,strat);
3441  }
3442  j--;
3443  }
3444  i--;
3445  }
3446  }
3447  else if (strat->L[j].p2 == strat->tail)
3448  {
3449  /*now L[j] cannot be canceled any more and the tail can be removed*/
3450  strat->L[j].p2 = p;
3451  }
3452  j--;
3453  }
3454  }
3455 }
3456 /*2
3457 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3458 *without the chain-criterion in B and L and enters B to L
3459 */
3461 {
3462  if (strat->pairtest!=NULL)
3463  {
3464  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3465  strat->pairtest=NULL;
3466  }
3467  /*
3468  *the elements of B enter L
3469  */
3471 }
3472 /*2
3473 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3474 *using the chain-criterion in B and L and enters B to L
3475 */
3476 void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3477 {
3478  int i,j,l;
3480  j = strat->Ll;
3481  loop /*cannot be changed into a for !!! */
3482  {
3483  if (j <= 0)
3484  {
3485  /*now L[0] cannot be canceled any more and the tail can be removed*/
3486  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3487  break;
3488  }
3489  if (strat->L[j].p2 == p)
3490  {
3491  i = j-1;
3492  loop
3493  {
3494  if (i < 0) break;
3495  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3496  {
3497  /*L[i] could be canceled but we search for a better one to cancel*/
3498  strat->c3++;
3499  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3500  && (pNext(strat->L[l].p) == strat->tail)
3501  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3502  && pDivisibleBy(p,strat->L[l].lcm))
3503  {
3504  /*
3505  *"NOT equal(...)" because in case of "equal" the element L[l]
3506  *is "older" and has to be from theoretical point of view behind
3507  *L[i], but we do not want to reorder L
3508  */
3509  strat->L[i].p2 = strat->tail;
3510  /*
3511  *L[l] will be canceled, we cannot cancel L[i] later on,
3512  *so we mark it with "tail"
3513  */
3514  deleteInL(strat->L,&strat->Ll,l,strat);
3515  i--;
3516  }
3517  else
3518  {
3519  deleteInL(strat->L,&strat->Ll,i,strat);
3520  }
3521  j--;
3522  }
3523  i--;
3524  }
3525  }
3526  else if (strat->L[j].p2 == strat->tail)
3527  {
3528  /*now L[j] cannot be canceled any more and the tail can be removed*/
3529  strat->L[j].p2 = p;
3530  }
3531  j--;
3532  }
3533 }
3534 #ifdef HAVE_RATGRING
3536 {
3537  int i,j,l;
3538 
3539  /*
3540  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3541  *In this case all elements in B such
3542  *that their lcm is divisible by the leading term of S[i] can be canceled
3543  */
3544  if (strat->pairtest!=NULL)
3545  {
3546  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3547  for (j=0; j<=strat->sl; j++)
3548  {
3549  if (strat->pairtest[j])
3550  {
3551  for (i=strat->Bl; i>=0; i--)
3552  {
3554  strat->B[i].lcm,currRing,
3555  currRing->real_var_start,currRing->real_var_end))
3556  {
3557  if(TEST_OPT_DEBUG)
3558  {
3559  Print("chain-crit-part: S[%d]=",j);
3560  p_wrp(strat->S[j],currRing);
3561  Print(" divide B[%d].lcm=",i);
3562  p_wrp(strat->B[i].lcm,currRing);
3563  PrintLn();
3564  }
3565  deleteInL(strat->B,&strat->Bl,i,strat);
3566  strat->c3++;
3567  }
3568  }
3569  }
3570  }
3571  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3572  strat->pairtest=NULL;
3573  }
3574  if (strat->Gebauer || strat->fromT)
3575  {
3576  if (strat->sugarCrit)
3577  {
3578  /*
3579  *suppose L[j] == (s,r) and p/lcm(s,r)
3580  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3581  *and in case the sugar is o.k. then L[j] can be canceled
3582  */
3583  for (j=strat->Ll; j>=0; j--)
3584  {
3585  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3586  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3587  && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3588  {
3589  if (strat->L[j].p == strat->tail)
3590  {
3591  if(TEST_OPT_DEBUG)
3592  {
3593  PrintS("chain-crit-part: pCompareChainPart p=");
3594  p_wrp(p,currRing);
3595  Print(" delete L[%d]",j);
3596  p_wrp(strat->L[j].lcm,currRing);
3597  PrintLn();
3598  }
3599  deleteInL(strat->L,&strat->Ll,j,strat);
3600  strat->c3++;
3601  }
3602  }
3603  }
3604  /*
3605  *this is GEBAUER-MOELLER:
3606  *in B all elements with the same lcm except the "best"
3607  *(i.e. the last one in B with this property) will be canceled
3608  */
3609  j = strat->Bl;
3610  loop /*cannot be changed into a for !!! */
3611  {
3612  if (j <= 0) break;
3613  i = j-1;
3614  loop
3615  {
3616  if (i < 0) break;
3617  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3618  {
3619  strat->c3++;
3620  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3621  {
3622  if(TEST_OPT_DEBUG)
3623  {
3624  Print("chain-crit-part: sugar B[%d].lcm=",j);
3625  p_wrp(strat->B[j].lcm,currRing);
3626  Print(" delete B[%d]",i);
3627  p_wrp(strat->B[i].lcm,currRing);
3628  PrintLn();
3629  }
3630  deleteInL(strat->B,&strat->Bl,i,strat);
3631  j--;
3632  }
3633  else
3634  {
3635  if(TEST_OPT_DEBUG)
3636  {
3637  Print("chain-crit-part: sugar B[%d].lcm=",i);
3638  p_wrp(strat->B[i].lcm,currRing);
3639  Print(" delete B[%d]",j);
3640  p_wrp(strat->B[j].lcm,currRing);
3641  PrintLn();
3642  }
3643  deleteInL(strat->B,&strat->Bl,j,strat);
3644  break;
3645  }
3646  }
3647  i--;
3648  }
3649  j--;
3650  }
3651  }
3652  else /*sugarCrit*/
3653  {
3654  /*
3655  *suppose L[j] == (s,r) and p/lcm(s,r)
3656  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3657  *and in case the sugar is o.k. then L[j] can be canceled
3658  */
3659  for (j=strat->Ll; j>=0; j--)
3660  {
3661  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3662  {
3663  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3664  {
3665  if(TEST_OPT_DEBUG)
3666  {
3667  PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3668  p_wrp(p,currRing);
3669  Print(" delete L[%d]",j);
3670  p_wrp(strat->L[j].lcm,currRing);
3671  PrintLn();
3672  }
3673  deleteInL(strat->L,&strat->Ll,j,strat);
3674  strat->c3++;
3675  }
3676  }
3677  }
3678  /*
3679  *this is GEBAUER-MOELLER:
3680  *in B all elements with the same lcm except the "best"
3681  *(i.e. the last one in B with this property) will be canceled
3682  */
3683  j = strat->Bl;
3684  loop /*cannot be changed into a for !!! */
3685  {
3686  if (j <= 0) break;
3687  for(i=j-1; i>=0; i--)
3688  {
3689  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3690  {
3691  if(TEST_OPT_DEBUG)
3692  {
3693  Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3694  p_wrp(strat->B[j].lcm,currRing);
3695  Print(" delete B[%d]\n",i);
3696  }
3697  strat->c3++;
3698  deleteInL(strat->B,&strat->Bl,i,strat);
3699  j--;
3700  }
3701  }
3702  j--;
3703  }
3704  }
3705  /*
3706  *the elements of B enter L
3707  */
3709  }
3710  else
3711  {
3712  for (j=strat->Ll; j>=0; j--)
3713  {
3714  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3715  {
3716  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3717  {
3718  if(TEST_OPT_DEBUG)
3719  {
3720  PrintS("chain-crit-part: pCompareChainPart p=");
3721  p_wrp(p,currRing);
3722  Print(" delete L[%d]",j);
3723  p_wrp(strat->L[j].lcm,currRing);
3724  PrintLn();
3725  }
3726  deleteInL(strat->L,&strat->Ll,j,strat);
3727  strat->c3++;
3728  }
3729  }
3730  }
3731  /*
3732  *this is our MODIFICATION of GEBAUER-MOELLER:
3733  *First the elements of B enter L,
3734  *then we fix a lcm and the "best" element in L
3735  *(i.e the last in L with this lcm and of type (s,p))
3736  *and cancel all the other elements of type (r,p) with this lcm
3737  *except the case the element (s,r) has also the same lcm
3738  *and is on the worst position with respect to (s,p) and (r,p)
3739  */
3740  /*
3741  *B enters to L/their order with respect to B is permutated for elements
3742  *B[i].p with the same leading term
3743  */
3745  j = strat->Ll;
3746  loop /*cannot be changed into a for !!! */
3747  {
3748  if (j <= 0)
3749  {
3750  /*now L[0] cannot be canceled any more and the tail can be removed*/
3751  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3752  break;
3753  }
3754  if (strat->L[j].p2 == p)
3755  {
3756  i = j-1;
3757  loop
3758  {
3759  if (i < 0) break;
3760  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3761  {
3762  /*L[i] could be canceled but we search for a better one to cancel*/
3763  strat->c3++;
3764  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3765  && (pNext(strat->L[l].p) == strat->tail)
3766  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3768  strat->L[l].lcm,currRing,
3769  currRing->real_var_start, currRing->real_var_end))
3770 
3771  {
3772  /*
3773  *"NOT equal(...)" because in case of "equal" the element L[l]
3774  *is "older" and has to be from theoretical point of view behind
3775  *L[i], but we do not want to reorder L
3776  */
3777  strat->L[i].p2 = strat->tail;
3778  /*
3779  *L[l] will be canceled, we cannot cancel L[i] later on,
3780  *so we mark it with "tail"
3781  */
3782  if(TEST_OPT_DEBUG)
3783  {
3784  PrintS("chain-crit-part: divisible_by p=");
3785  p_wrp(p,currRing);
3786  Print(" delete L[%d]",l);
3787  p_wrp(strat->L[l].lcm,currRing);
3788  PrintLn();
3789  }
3790  deleteInL(strat->L,&strat->Ll,l,strat);
3791  i--;
3792  }
3793  else
3794  {
3795  if(TEST_OPT_DEBUG)
3796  {
3797  PrintS("chain-crit-part: divisible_by(2) p=");
3798  p_wrp(p,currRing);
3799  Print(" delete L[%d]",i);
3800  p_wrp(strat->L[i].lcm,currRing);
3801  PrintLn();
3802  }
3803  deleteInL(strat->L,&strat->Ll,i,strat);
3804  }
3805  j--;
3806  }
3807  i--;
3808  }
3809  }
3810  else if (strat->L[j].p2 == strat->tail)
3811  {
3812  /*now L[j] cannot be canceled any more and the tail can be removed*/
3813  strat->L[j].p2 = p;
3814  }
3815  j--;
3816  }
3817  }
3818 }
3819 #endif
3820 
3821 /*2
3822 *(s[0],h),...,(s[k],h) will be put to the pairset L
3823 */
3824 void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3825 {
3826 
3827  if ((strat->syzComp==0)
3828  || (pGetComp(h)<=strat->syzComp))
3829  {
3830  int j;
3831  BOOLEAN new_pair=FALSE;
3832 
3833  if (pGetComp(h)==0)
3834  {
3835  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3836  if ((isFromQ)&&(strat->fromQ!=NULL))
3837  {
3838  for (j=0; j<=k; j++)
3839  {
3840  if (!strat->fromQ[j])
3841  {
3842  new_pair=TRUE;
3843  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3844  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3845  }
3846  }
3847  }
3848  else
3849  {
3850  new_pair=TRUE;
3851  for (j=0; j<=k; j++)
3852  {
3853  #ifdef ADIDEBUG
3854  PrintS("\n Trying to add spoly : \n");
3855  PrintS(" ");p_Write(h, strat->tailRing);
3856  PrintS(" ");p_Write(strat->S[j],strat->tailRing);
3857  #endif
3858  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3859  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3860  }
3861  }
3862  }
3863  else
3864  {
3865  for (j=0; j<=k; j++)
3866  {
3867  if ((pGetComp(h)==pGetComp(strat->S[j]))
3868  || (pGetComp(strat->S[j])==0))
3869  {
3870  new_pair=TRUE;
3871  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3872  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3873  }
3874  }
3875  }
3876  if (new_pair)
3877  {
3878  #ifdef HAVE_RATGRING
3879  if (currRing->real_var_start>0)
3880  chainCritPart(h,ecart,strat);
3881  else
3882  #endif
3883  strat->chainCrit(h,ecart,strat);
3884  }
3886  }
3887 }
3888 
3889 /*2
3890 *(s[0],h),...,(s[k],h) will be put to the pairset L
3891 *using signatures <= only for signature-based standard basis algorithms
3892 */
3893 
3894 void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3895 {
3896 
3897  if ((strat->syzComp==0)
3898  || (pGetComp(h)<=strat->syzComp))
3899  {
3900  int j;
3901  BOOLEAN new_pair=FALSE;
3902 
3903  if (pGetComp(h)==0)
3904  {
3905  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3906  if ((isFromQ)&&(strat->fromQ!=NULL))
3907  {
3908  for (j=0; j<=k; j++)
3909  {
3910  if (!strat->fromQ[j])
3911  {
3912  new_pair=TRUE;
3913  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3914  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3915  }
3916  }
3917  }
3918  else
3919  {
3920  new_pair=TRUE;
3921  for (j=0; j<=k; j++)
3922  {
3923  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3924  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3925  }
3926  }
3927  }
3928  else
3929  {
3930  for (j=0; j<=k; j++)
3931  {
3932  if ((pGetComp(h)==pGetComp(strat->S[j]))
3933  || (pGetComp(strat->S[j])==0))
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 
3942  if (new_pair)
3943  {
3944 #ifdef HAVE_RATGRING
3945  if (currRing->real_var_start>0)
3946  chainCritPart(h,ecart,strat);
3947  else
3948 #endif
3949  strat->chainCrit(h,ecart,strat);
3950  }
3951  }
3952 }
3953 
3954 void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3955 {
3956 
3957  if ((strat->syzComp==0)
3958  || (pGetComp(h)<=strat->syzComp))
3959  {
3960  int j;
3961 
3962  if (pGetComp(h)==0)
3963  {
3964  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3965  if ((isFromQ)&&(strat->fromQ!=NULL))
3966  {
3967  for (j=0; j<=k && !strat->sigdrop; j++)
3968  {
3969  if (!strat->fromQ[j])
3970  {
3971  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3972  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3973  }
3974  }
3975  }
3976  else
3977  {
3978  for (j=0; j<=k && !strat->sigdrop; j++)
3979  {
3980  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3981  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3982  }
3983  }
3984  }
3985  else
3986  {
3987  for (j=0; j<=k && !strat->sigdrop; j++)
3988  {
3989  if ((pGetComp(h)==pGetComp(strat->S[j]))
3990  || (pGetComp(strat->S[j])==0))
3991  {
3992  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3993  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3994  }
3995  }
3996  }
3997 
3998 #if 0
3999  if (new_pair)
4000  {
4001 #ifdef HAVE_RATGRING
4002  if (currRing->real_var_start>0)
4003  chainCritPart(h,ecart,strat);
4004  else
4005 #endif
4006  strat->chainCrit(h,ecart,strat);
4007  }
4008 #endif
4009  }
4010 }
4011 
4012 #ifdef HAVE_RINGS
4013 /*2
4014 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
4015 *using the chain-criterion in B and L and enters B to L
4016 */
4018 {
4019  int i,j,l;
4020  /*
4021  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4022  *In this case all elements in B such
4023  *that their lcm is divisible by the leading term of S[i] can be canceled
4024  */
4025  if (strat->pairtest!=NULL)
4026  {
4027  {
4028  /*- i.e. there is an i with pairtest[i]==TRUE -*/
4029  for (j=0; j<=strat->sl; j++)
4030  {
4031  if (strat->pairtest[j])
4032  {
4033  for (i=strat->Bl; i>=0; i--)
4034  {
4035  if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4036  {
4037 #ifdef KDEBUG
4038  if (TEST_OPT_DEBUG)
4039  {
4040  PrintS("--- chain criterion func chainCritRing type 1\n");
4041  PrintS("strat->S[j]:");
4042  wrp(strat->S[j]);
4043  PrintS(" strat->B[i].lcm:");
4044  wrp(strat->B[i].lcm);PrintLn();
4045  pWrite(strat->B[i].p);
4046  pWrite(strat->B[i].p1);
4047  pWrite(strat->B[i].p2);
4048  wrp(strat->B[i].lcm);
4049  PrintLn();
4050  }
4051 #endif
4052  #ifdef ADIDEBUG
4053  printf("\nChainCrit1\n");
4054  pWrite(strat->B[i].p);
4055  pWrite(strat->B[i].p1);
4056  pWrite(strat->B[i].p2);
4057  #endif
4058  deleteInL(strat->B,&strat->Bl,i,strat);
4059  strat->c3++;
4060  }
4061  }
4062  }
4063  }
4064  }
4065  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4066  strat->pairtest=NULL;
4067  }
4068  assume(!(strat->Gebauer || strat->fromT));
4069  for (j=strat->Ll; j>=0; j--)
4070  {
4071  if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4072  {
4073  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4074  {
4075  if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4076  {
4077  #ifdef ADIDEBUG
4078  printf("\nChainCrit2\n");
4079  pWrite(strat->L[j].p);
4080  pWrite(strat->L[j].p1);
4081  pWrite(strat->L[j].p2);
4082  #endif
4083  deleteInL(strat->L,&strat->Ll,j,strat);
4084  strat->c3++;
4085 #ifdef KDEBUG
4086  if (TEST_OPT_DEBUG)
4087  {
4088  PrintS("--- chain criterion func chainCritRing type 2\n");
4089  PrintS("strat->L[j].p:");
4090  wrp(strat->L[j].p);
4091  PrintS(" p:");
4092  wrp(p);
4093  PrintLn();
4094  }
4095 #endif
4096  }
4097  }
4098  }
4099  }
4100  /*
4101  *this is our MODIFICATION of GEBAUER-MOELLER:
4102  *First the elements of B enter L,
4103  *then we fix a lcm and the "best" element in L
4104  *(i.e the last in L with this lcm and of type (s,p))
4105  *and cancel all the other elements of type (r,p) with this lcm
4106  *except the case the element (s,r) has also the same lcm
4107  *and is on the worst position with respect to (s,p) and (r,p)
4108  */
4109  /*
4110  *B enters to L/their order with respect to B is permutated for elements
4111  *B[i].p with the same leading term
4112  */
4114  j = strat->Ll;
4115  loop /*cannot be changed into a for !!! */
4116  {
4117  if (j <= 0)
4118  {
4119  /*now L[0] cannot be canceled any more and the tail can be removed*/
4120  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4121  break;
4122  }
4123  if (strat->L[j].p2 == p) // Was the element added from B?
4124  {
4125  i = j-1;
4126  loop
4127  {
4128  if (i < 0) break;
4129  // Element is from B and has the same lcm as L[j]
4130  if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4131  && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4132  {
4133  /*L[i] could be canceled but we search for a better one to cancel*/
4134  strat->c3++;
4135 #ifdef KDEBUG
4136  if (TEST_OPT_DEBUG)
4137  {
4138  PrintS("--- chain criterion func chainCritRing type 3\n");
4139  PrintS("strat->L[j].lcm:");
4140  wrp(strat->L[j].lcm);
4141  PrintS(" strat->L[i].lcm:");
4142  wrp(strat->L[i].lcm);
4143  PrintLn();
4144  }
4145 #endif
4146  #ifdef ADIDEBUG
4147  printf("\nChainCrit3\n");
4148  pWrite(strat->L[j].p);
4149  pWrite(strat->L[j].p1);
4150  pWrite(strat->L[j].p2);
4151  #endif
4152  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4153  && (pNext(strat->L[l].p) == strat->tail)
4154  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4155  && pDivisibleBy(p,strat->L[l].lcm))
4156  {
4157  /*
4158  *"NOT equal(...)" because in case of "equal" the element L[l]
4159  *is "older" and has to be from theoretical point of view behind
4160  *L[i], but we do not want to reorder L
4161  */
4162  strat->L[i].p2 = strat->tail;
4163  /*
4164  *L[l] will be canceled, we cannot cancel L[i] later on,
4165  *so we mark it with "tail"
4166  */
4167  deleteInL(strat->L,&strat->Ll,l,strat);
4168  i--;
4169  }
4170  else
4171  {
4172  deleteInL(strat->L,&strat->Ll,i,strat);
4173  }
4174  j--;
4175  }
4176  i--;
4177  }
4178  }
4179  else if (strat->L[j].p2 == strat->tail)
4180  {
4181  /*now L[j] cannot be canceled any more and the tail can be removed*/
4182  strat->L[j].p2 = p;
4183  }
4184  j--;
4185  }
4186 }
4187 #endif
4188 
4189 #ifdef HAVE_RINGS
4190 long ind2(long arg)
4191 {
4192  long ind = 0;
4193  if (arg <= 0) return 0;
4194  while (arg%2 == 0)
4195  {
4196  arg = arg / 2;
4197  ind++;
4198  }
4199  return ind;
4200 }
4201 
4202 long ind_fact_2(long arg)
4203 {
4204  long ind = 0;
4205  if (arg <= 0) return 0;
4206  if (arg%2 == 1) { arg--; }
4207  while (arg > 0)
4208  {
4209  ind += ind2(arg);
4210  arg = arg - 2;
4211  }
4212  return ind;
4213 }
4214 #endif
4215 
4216 #ifdef HAVE_VANIDEAL
4217 long twoPow(long arg)
4218 {
4219  return 1L << arg;
4220 }
4221 
4222 /*2
4223 * put the pair (p, f) in B and f in T
4224 */
4225 void enterOneZeroPairRing (poly f, poly t_p, poly p, int ecart, kStrategy strat, int atR = -1)
4226 {
4227  int l,j,compare,compareCoeff;
4228  LObject Lp;
4229 
4230 #ifdef KDEBUG
4231  Lp.ecart=0; Lp.length=0;
4232 #endif
4233  /*- computes the lcm(s[i],p) -*/
4234  Lp.lcm = p_Lcm(p,f,Lp.lcm,currRing);
4235  pSetCoeff(Lp.lcm, nLcm(pGetCoeff(p), pGetCoeff(f), currRing));
4236  assume(!strat->sugarCrit);
4237  assume(!strat->fromT);
4238  /*
4239  *the set B collects the pairs of type (S[j],p)
4240  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
4241  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
4242  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
4243  */
4244  for(j = strat->Bl;j>=0;j--)
4245  {
4246  compare=pDivCompRing(strat->B[j].lcm,Lp.lcm);
4247  compareCoeff = nDivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(Lp.lcm));
4248  if (compareCoeff == 0 || compare == compareCoeff)
4249  {
4250  if (compare == 1)
4251  {
4252  strat->c3++;
4253  pLmDelete(Lp.lcm);
4254  return;
4255  }
4256  else
4257  if (compare == -1)
4258  {
4259  deleteInL(strat->B,&strat->Bl,j,strat);
4260  strat->c3++;
4261  }
4262  }
4263  if (compare == pDivComp_EQUAL)
4264  {
4265  // Add hint for same LM and direction of LC (later) (TODO Oliver)
4266  if (compareCoeff == 1)
4267  {
4268  strat->c3++;
4269  pLmDelete(Lp.lcm);
4270  return;
4271  }
4272  else
4273  if (compareCoeff == -1)
4274  {
4275  deleteInL(strat->B,&strat->Bl,j,strat);
4276  strat->c3++;
4277  }
4278  }
4279  }
4280  /*
4281  *the pair (S[i],p) enters B if the spoly != 0
4282  */
4283  /*- compute the short s-polynomial -*/
4284  if ((f==NULL) || (p==NULL)) return;
4285  pNorm(p);
4286  {
4287  Lp.p = ksCreateShortSpoly(f, p, strat->tailRing);
4288  }
4289  if (Lp.p == NULL) //deactivated, as we are adding pairs with zeropoly and not from S
4290  {
4291  /*- the case that the s-poly is 0 -*/
4292 // if (strat->pairtest==NULL) initPairtest(strat);
4293 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
4294 // strat->pairtest[strat->sl+1] = TRUE;
4295  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
4296  /*
4297  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
4298  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
4299  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
4300  *term of p devides the lcm(s,r)
4301  *(this canceling should be done here because
4302  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
4303  *the first case is handeled in chainCrit
4304  */
4305  if (Lp.lcm!=NULL) pLmDelete(Lp.lcm);
4306  }
4307  else
4308  {
4309  /*- the pair (S[i],p) enters B -*/
4310  Lp.p1 = f;
4311  Lp.p2 = p;
4312 
4313  pNext(Lp.p) = strat->tail;
4314 
4315  LObject tmp_h(f, currRing, strat->tailRing);
4316  tmp_h.SetShortExpVector();
4317  strat->initEcart(&tmp_h);
4318  tmp_h.sev = pGetShortExpVector(tmp_h.p);
4319  tmp_h.t_p = t_p;
4320 
4321  enterT(tmp_h, strat, strat->tl + 1);
4322 
4323  if (atR >= 0)
4324  {
4325  Lp.i_r2 = atR;
4326  Lp.i_r1 = strat->tl;
4327  }
4328 
4329  strat->initEcartPair(&Lp,f,p,0/*strat->ecartS[i]*/,ecart); // Attention: TODO: break ecart
4330  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
4331  enterL(&strat->B, &strat->Bl, &strat->Bmax, Lp, l);
4332  }
4333 }
4334 
4335 /* Helper for kCreateZeroPoly
4336  * enumerating the exponents
4337 ring r = 2^2, (a, b, c), lp; ideal G0 = system("createG0"); ideal G = interred(G0); ncols(G0); ncols(G);
4338  */
4339 
4340 int nextZeroSimplexExponent (long exp[], long ind[], long cexp[], long cind[], long* cabsind, long step[], long bound, long N)
4341 /* gives the next exponent from the set H_1 */
4342 {
4343  long add = ind2(cexp[1] + 2);
4344  if ((*cabsind < bound) && (*cabsind - step[1] + add < bound))
4345  {
4346  cexp[1] += 2;
4347  cind[1] += add;
4348  *cabsind += add;
4349  }
4350  else
4351  {
4352  // cabsind >= habsind
4353  if (N == 1) return 0;
4354  int i = 1;
4355  while (exp[i] == cexp[i] && i <= N) i++;
4356  cexp[i] = exp[i];
4357  *cabsind -= cind[i];
4358  cind[i] = ind[i];
4359  step[i] = 500000;
4360  *cabsind += cind[i];
4361  // Print("in: %d\n", *cabsind);
4362  i += 1;
4363  if (i > N) return 0;
4364  do
4365  {
4366  step[1] = 500000;
4367  for (int j = i + 1; j <= N; j++)
4368  {
4369  if (step[1] > step[j]) step[1] = step[j];
4370  }
4371  add = ind2(cexp[i] + 2);
4372  if (*cabsind - step[1] + add >= bound)
4373  {
4374  cexp[i] = exp[i];
4375  *cabsind -= cind[i];
4376  cind[i] = ind[i];
4377  *cabsind += cind[i];
4378  step[i] = 500000;
4379  i += 1;
4380  if (i > N) return 0;
4381  }
4382  else step[1] = -1;
4383  } while (step[1] != -1);
4384  step[1] = 500000;
4385  cexp[i] += 2;
4386  cind[i] += add;
4387  *cabsind += add;
4388  if (add < step[i]) step[i] = add;
4389  for (i = 2; i <= N; i++)
4390  {
4391  if (step[1] > step[i]) step[1] = step[i];
4392  }
4393  }
4394  return 1;
4395 }
4396 
4397 /*
4398  * Creates the zero Polynomial on position exp
4399  * long exp[] : exponent of leading term
4400  * cabsind : total 2-ind of exp (if -1 will be computed)
4401  * poly* t_p : will hold the LT in tailRing
4402  * leadRing : ring for the LT
4403  * tailRing : ring for the tail
4404  */
4405 
4406 poly kCreateZeroPoly(long exp[], long cabsind, poly* t_p, ring leadRing, ring tailRing)
4407 {
4408 
4409  poly zeroPoly = NULL;
4410 
4411  number tmp1;
4412  poly tmp2, tmp3;
4413 
4414  if (cabsind == -1)
4415  {
4416  cabsind = 0;
4417  for (int i = 1; i <= leadRing->N; i++)
4418  {
4419  cabsind += ind_fact_2(exp[i]);
4420  }
4421 // Print("cabsind: %d\n", cabsind);
4422  }
4423  if (cabsind < leadRing->ch)
4424  {
4425  zeroPoly = p_ISet(twoPow(leadRing->ch - cabsind), tailRing);
4426  }
4427  else
4428  {
4429  zeroPoly = p_ISet(1, tailRing);
4430  }
4431  for (int i = 1; i <= leadRing->N; i++)
4432  {
4433  for (long j = 1; j <= exp[i]; j++)
4434  {
4435  tmp1 = nInit(j);
4436  tmp2 = p_ISet(1, tailRing);
4437  p_SetExp(tmp2, i, 1, tailRing);
4438  p_Setm(tmp2, tailRing);
4439  if (nIsZero(tmp1))
4440  { // should nowbe obsolet, test ! TODO OLIVER
4441  zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing);
4442  }
4443  else
4444  {
4445  tmp3 = p_NSet(nCopy(tmp1), tailRing);
4446  zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing);
4447  }
4448  }
4449  }
4450  tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing);
4451  for (int i = 1; i <= leadRing->N; i++)
4452  {
4453  pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing));
4454  }
4455  p_Setm(tmp2, leadRing);
4456  *t_p = zeroPoly;
4457  zeroPoly = pNext(zeroPoly);
4458  pNext(*t_p) = NULL;
4459  pNext(tmp2) = zeroPoly;
4460  return tmp2;
4461 }
4462 
4463 // #define OLI_DEBUG
4464 
4465 /*
4466  * Generate the s-polynomial for the virtual set of zero-polynomials
4467  */
4468 
4469 void initenterzeropairsRing (poly p, int ecart, kStrategy strat, int atR)
4470 {
4471  // Initialize
4472  long exp[50]; // The exponent of \hat{X} (basepoint)
4473  long cexp[50]; // The current exponent for iterating over all
4474  long ind[50]; // The power of 2 in the i-th component of exp
4475  long cind[50]; // analog for cexp
4476  long mult[50]; // How to multiply the elements of G
4477  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4478  long habsind = 0; // The abs. index of the coefficient of h
4479  long step[50]; // The last increases
4480  for (int i = 1; i <= currRing->N; i++)
4481  {
4482  exp[i] = p_GetExp(p, i, currRing);
4483  if (exp[i] & 1 != 0)
4484  {
4485  exp[i] = exp[i] - 1;
4486  mult[i] = 1;
4487  }
4488  cexp[i] = exp[i];
4489  ind[i] = ind_fact_2(exp[i]);
4490  cabsind += ind[i];
4491  cind[i] = ind[i];
4492  step[i] = 500000;
4493  }
4494  step[1] = 500000;
4495  habsind = ind2(n_Int(pGetCoeff(p), currRing->cf);
4496  long bound = currRing->ch - habsind;
4497 #ifdef OLI_DEBUG
4498  PrintS("-------------\npoly :");
4499  wrp(p);
4500  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4501  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4502  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4503  Print("bound : %d\n", bound);
4504  Print("cind : %d\n", cabsind);
4505 #endif
4506  if (cabsind == 0)
4507  {
4508  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4509  {
4510  return;
4511  }
4512  }
4513  // Now the whole simplex
4514  do
4515  {
4516  // Build s-polynomial
4517  // 2**ind-def * mult * g - exp-def * h
4518  poly t_p;
4519  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, strat->tailRing);
4520 #ifdef OLI_DEBUG
4521  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4522  PrintS("zPoly : ");
4523  wrp(zeroPoly);
4524  PrintLn();
4525 #endif
4526  enterOneZeroPairRing(zeroPoly, t_p, p, ecart, strat, atR);
4527  }
4528  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4529 }
4530 
4531 /*
4532  * Create the Groebner basis of the vanishing polynomials.
4533  */
4534 
4535 ideal createG0()
4536 {
4537  // Initialize
4538  long exp[50]; // The exponent of \hat{X} (basepoint)
4539  long cexp[50]; // The current exponent for iterating over all
4540  long ind[50]; // The power of 2 in the i-th component of exp
4541  long cind[50]; // analog for cexp
4542  long mult[50]; // How to multiply the elements of G
4543  long cabsind = 0; // The abs. index of cexp, i.e. the sum of cind
4544  long habsind = 0; // The abs. index of the coefficient of h
4545  long step[50]; // The last increases
4546  for (int i = 1; i <= currRing->N; i++)
4547  {
4548  exp[i] = 0;
4549  cexp[i] = exp[i];
4550  ind[i] = 0;
4551  step[i] = 500000;
4552  cind[i] = ind[i];
4553  }
4554  long bound = currRing->ch;
4555  step[1] = 500000;
4556 #ifdef OLI_DEBUG
4557  PrintS("-------------\npoly :");
4558 // wrp(p);
4559  Print("\nexp : (%d, %d)\n", exp[1] + mult[1], exp[2] + mult[1]);
4560  Print("cexp : (%d, %d)\n", cexp[1], cexp[2]);
4561  Print("cind : (%d, %d)\n", cind[1], cind[2]);
4562  Print("bound : %d\n", bound);
4563  Print("cind : %d\n", cabsind);
4564 #endif
4565  if (cabsind == 0)
4566  {
4567  if (!(nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N)))
4568  {
4569  return idInit(1, 1);
4570  }
4571  }
4572  ideal G0 = idInit(1, 1);
4573  // Now the whole simplex
4574  do
4575  {
4576  // Build s-polynomial
4577  // 2**ind-def * mult * g - exp-def * h
4578  poly t_p;
4579  poly zeroPoly = kCreateZeroPoly(cexp, cabsind, &t_p, currRing, currRing);
4580 #ifdef OLI_DEBUG
4581  Print("%d, (%d, %d), ind = (%d, %d)\n", cabsind, cexp[1], cexp[2], cind[1], cind[2]);
4582  PrintS("zPoly : ");
4583  wrp(zeroPoly);
4584  PrintLn();
4585 #endif
4586  // Add to ideal
4587  pEnlargeSet(&(G0->m), IDELEMS(G0), 1);
4588  IDELEMS(G0) += 1;
4589  G0->m[IDELEMS(G0) - 1] = zeroPoly;
4590  }
4591  while ( nextZeroSimplexExponent(exp, ind, cexp, cind, &cabsind, step, bound, currRing->N) );
4592  idSkipZeroes(G0);
4593  return G0;
4594 }
4595 #endif
4596 
4597 #ifdef HAVE_RINGS
4598 /*2
4599 *(s[0],h),...,(s[k],h) will be put to the pairset L
4600 */
4601 void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4602 {
4603  const int iCompH = pGetComp(h);
4604  if (!nIsOne(pGetCoeff(h)))
4605  {
4606  int j;
4607 
4608  for (j=0; j<=k; j++)
4609  {
4610  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4611 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4612 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4613  if (((iCompH == pGetComp(strat->S[j]))
4614  || (0 == pGetComp(strat->S[j])))
4615  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4616  {
4617  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4618  }
4619  }
4620  }
4621 }
4622 
4623 static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4624 {
4625  const int iCompH = pGetComp(h);
4626  if (!nIsOne(pGetCoeff(h)))
4627  {
4628  int j;
4629 
4630  for (j=0; j<=k && !strat->sigdrop; j++)
4631  {
4632  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4633 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4634 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4635  if (((iCompH == pGetComp(strat->S[j]))
4636  || (0 == pGetComp(strat->S[j])))
4637  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4638  {
4639  enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4640  }
4641  }
4642  }
4643 }
4644 #endif
4645 
4646 #ifdef HAVE_RINGS
4647 /*2
4648 * Generates spoly(0, h) if applicable. Assumes ring in Z/2^n.
4649 */
4651 {
4652  if (nIsOne(pGetCoeff(h))) return;
4653  number gcd;
4654  bool go = false;
4655  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4656  {
4657  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4658  go = true;
4659  }
4660  else
4661  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4662  if (go || !nIsOne(gcd))
4663  {
4664  poly p = h->next;
4665  if (!go)
4666  {
4667  number tmp = gcd;
4668  gcd = n_Ann(gcd,currRing->cf);
4669  nDelete(&tmp);
4670  }
4671  p_Test(p,strat->tailRing);
4672  p = pp_Mult_nn(p, gcd, strat->tailRing);
4673  nDelete(&gcd);
4674 
4675  if (p != NULL)
4676  {
4677  if (TEST_OPT_PROT)
4678  {
4679  PrintS("Z");
4680  }
4681 #ifdef KDEBUG
4682  if (TEST_OPT_DEBUG)
4683  {
4684  PrintS("--- create zero spoly: ");
4686  PrintS(" ---> ");
4687  }
4688 #endif
4689  poly tmp = pInit();
4690  pSetCoeff0(tmp, pGetCoeff(p));
4691  for (int i = 1; i <= rVar(currRing); i++)
4692  {
4693  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4694  }
4696  {
4698  }
4699  p_Setm(tmp, currRing);
4701  pNext(tmp) = p;
4702  LObject Lp;
4703  Lp.Init();
4704  Lp.p = tmp;
4705  Lp.tailRing = strat->tailRing;
4706  int posx;
4707  if (Lp.p!=NULL)
4708  {
4709  strat->initEcart(&Lp);
4710  if (strat->Ll==-1)
4711  posx =0;
4712  else
4713  posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4714  Lp.sev = pGetShortExpVector(Lp.p);
4715  if (strat->tailRing != currRing)
4716  {
4717  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4718  }
4719 #ifdef KDEBUG
4720  if (TEST_OPT_DEBUG)
4721  {
4722  p_wrp(tmp,currRing,strat->tailRing);
4723  PrintLn();
4724  }
4725 #endif
4726  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4727  }
4728  }
4729  }
4730  nDelete(&gcd);
4731 }
4732 
4734 {
4735  if (nIsOne(pGetCoeff(h))) return;
4736  number gcd;
4737  bool go = false;
4738  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4739  {
4740  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4741  go = true;
4742  }
4743  else
4744  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4745  if (go || !nIsOne(gcd))
4746  {
4747  poly p = h->next;
4748  if (!go)
4749  {
4750  number tmp = gcd;
4751  gcd = n_Ann(gcd,currRing->cf);
4752  nDelete(&tmp);
4753  }
4754  p_Test(p,strat->tailRing);
4755  p = pp_Mult_nn(p, gcd, strat->tailRing);
4756 
4757  if (p != NULL)
4758  {
4759  if (TEST_OPT_PROT)
4760  {
4761  PrintS("Z");
4762  }
4763 #ifdef KDEBUG
4764  if (TEST_OPT_DEBUG)
4765  {
4766  PrintS("--- create zero spoly: ");
4768  PrintS(" ---> ");
4769  }
4770 #endif
4771  poly tmp = pInit();
4772  pSetCoeff0(tmp, pGetCoeff(p));
4773  for (int i = 1; i <= rVar(currRing); i++)
4774  {
4775  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4776  }
4778  {
4780  }
4781  p_Setm(tmp, currRing);
4783  pNext(tmp) = p;
4784  LObject Lp;
4785  Lp.Init();
4786  Lp.p = tmp;
4787  //printf("\nOld\n");pWrite(h);pWrite(hSig);
4788  #if EXT_POLY_NEW
4789  Lp.sig = pp_Mult_nn(hSig, gcd, currRing);
4790  if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4791  {
4792  #ifdef ADIDEBUG
4793  printf("\nSigdrop in enterextended spoly\n");pWrite(h);pWrite(hSig);
4794  #endif
4795  strat->sigdrop = TRUE;
4796  //Try to reduce it as far as we can via redRing
4797  int red_result = redRing(&Lp,strat);
4798  #ifdef ADIDEBUG
4799  printf("\nAfter redRing reduce:\n");pWrite(Lp.p);
4800  #endif
4801  if(red_result == 0)
4802  {
4803  // Cancel the sigdrop
4804  #ifdef ADIDEBUG
4805  printf("\nCancel the sigdrop. It reduced to 0\n");
4806  #endif
4807  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4808  strat->sigdrop = FALSE;
4809  return;
4810  }
4811  else
4812  {
4813  #ifdef ADIDEBUG
4814  printf("\nSigdrop. end\n");
4815  #endif
4816  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4817  #if 1
4818  strat->enterS(Lp,0,strat,strat->tl);
4819  #endif
4820  return;
4821  }
4822 
4823  }
4824  #else
4825  Lp.sig = pOne();
4826  if(strat->Ll >= 0)
4827  p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4828  else
4829  p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4830  #endif
4831  Lp.tailRing = strat->tailRing;
4832  int posx;
4833  if (Lp.p!=NULL)
4834  {
4835  strat->initEcart(&Lp);
4836  if (strat->Ll==-1)
4837  posx =0;
4838  else
4839  posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4840  Lp.sev = pGetShortExpVector(Lp.p);
4841  if (strat->tailRing != currRing)
4842  {
4843  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4844  }
4845 #ifdef KDEBUG
4846  if (TEST_OPT_DEBUG)
4847  {
4848  p_wrp(tmp,currRing,strat->tailRing);
4849  PrintLn();
4850  }
4851 #endif
4852  //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4853  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4854  }
4855  }
4856  nDelete(&gcd);
4857  }
4858  nDelete(&gcd);
4859 }
4860 #endif
4861 
4862 #ifdef HAVE_RINGS
4863 void clearSbatch (poly h,int k,int pos,kStrategy strat)
4864 {
4865  int j = pos;
4866  if ( (!strat->fromT)
4867  && ((strat->syzComp==0)
4868  ||(pGetComp(h)<=strat->syzComp)
4869  ))
4870  {
4871  // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4872  unsigned long h_sev = pGetShortExpVector(h);
4873  loop
4874  {
4875  if (j > k) break;
4876  clearS(h,h_sev, &j,&k,strat);
4877  j++;
4878  }
4879  // Print("end clearS sl=%d\n",strat->sl);
4880  }
4881 }
4882 #endif
4883 
4884 #ifdef HAVE_RINGS
4885 /*2
4886 * Generates a sufficient set of spolys (maybe just a finite generating
4887 * set of the syzygys)
4888 */
4889 void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4890 {
4892  // enter also zero divisor * poly, if this is non zero and of smaller degree
4894  initenterpairs(h, k, ecart, 0, strat, atR);
4895  initenterstrongPairs(h, k, ecart, 0, strat, atR);
4896  clearSbatch(h, k, pos, strat);
4897 }
4898 
4899 void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4900 {
4902  // enter also zero divisor * poly, if this is non zero and of smaller degree
4903  #ifdef ADIDEBUG
4904  printf("\n Trying to add extended spolys\n");
4905  #endif
4907  if(strat->sigdrop) return;
4908  #ifdef ADIDEBUG
4909  printf("\n Trying to add spolys\n");
4910  #endif
4911  initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4912  if(strat->sigdrop) return;
4913  #ifdef ADIDEBUG
4914  printf("\n Trying to add gcd-polys\n");
4915  #endif
4916  initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4917  if(strat->sigdrop) return;
4918  clearSbatch(h, k, pos, strat);
4919 }
4920 #endif
4921 
4922 /*2
4923 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4924 *superfluous elements in S will be deleted
4925 */
4926 void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4927 {
4928  int j=pos;
4929 
4931  initenterpairs(h,k,ecart,0,strat, atR);
4932  if ( (!strat->fromT)
4933  && ((strat->syzComp==0)
4934  ||(pGetComp(h)<=strat->syzComp)))
4935  {
4936  unsigned long h_sev = pGetShortExpVector(h);
4937  loop
4938  {
4939  if (j > k) break;
4940  clearS(h,h_sev, &j,&k,strat);
4941  j++;
4942  }
4943  }
4944 }
4945 
4946 /*2
4947 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4948 *superfluous elements in S will be deleted
4949 *this is a special variant of signature-based algorithms including the
4950 *signatures for criteria checks
4951 */
4952 void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4953 {
4954  int j=pos;
4956  initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4957  if ( (!strat->fromT)
4958  && ((strat->syzComp==0)
4959  ||(pGetComp(h)<=strat->syzComp)))
4960  {
4961  unsigned long h_sev = pGetShortExpVector(h);
4962  loop
4963  {
4964  if (j > k) break;
4965  clearS(h,h_sev, &j,&k,strat);
4966  j++;
4967  }
4968  }
4969 }
4970 
4971 /*2
4972 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4973 *superfluous elements in S will be deleted
4974 */
4975 void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4976 {
4977  int j;
4978  const int iCompH = pGetComp(h);
4979 
4980  if (rField_is_Ring(currRing))
4981  {
4982  for (j=0; j<=k; j++)
4983  {
4984  const int iCompSj = pGetComp(strat->S[j]);
4985  if ((iCompH==iCompSj)
4986  //|| (0==iCompH) // can only happen,if iCompSj==0
4987  || (0==iCompSj))
4988  {
4989  enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4990  }
4991  }
4993  }
4994  else
4995  {
4996  for (j=0; j<=k; j++)
4997  {
4998  const int iCompSj = pGetComp(strat->S[j]);
4999  if ((iCompH==iCompSj)
5000  //|| (0==iCompH) // can only happen,if iCompSj==0
5001  || (0==iCompSj))
5002  {
5003  enterOnePairSpecial(j,h,ecart,strat, atR);
5004  }
5005  }
5006  }
5007 
5008  if (strat->noClearS) return;
5009 
5010 // #ifdef HAVE_PLURAL
5011 /*
5012  if (rIsPluralRing(currRing))
5013  {
5014  j=pos;
5015  loop
5016  {
5017  if (j > k) break;
5018 
5019  if (pLmDivisibleBy(h, strat->S[j]))
5020  {
5021  deleteInS(j, strat);
5022  j--;
5023  k--;
5024  }
5025 
5026  j++;
5027  }
5028  }
5029  else
5030 */
5031 // #endif // ??? Why was the following cancelation disabled for non-commutative rings?
5032  {
5033  j=pos;
5034  loop
5035  {
5036  unsigned long h_sev = pGetShortExpVector(h);
5037  if (j > k) break;
5038  clearS(h,h_sev,&j,&k,strat);
5039  j++;
5040  }
5041  }
5042 }
5043 
5044 /*2
5045 *reorders s with respect to posInS,
5046 *suc is the first changed index or zero
5047 */
5048 
5049 void reorderS (int* suc,kStrategy strat)
5050 {
5051  int i,j,at,ecart, s2r;
5052  int fq=0;
5053  unsigned long sev;
5054  poly p;
5055  int new_suc=strat->sl+1;
5056  i= *suc;
5057  if (i<0) i=0;
5058 
5059  for (; i<=strat->sl; i++)
5060  {
5061  at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
5062  if (at != i)
5063  {
5064  if (new_suc > at) new_suc = at;
5065  p = strat->S[i];
5066  ecart = strat->ecartS[i];
5067  sev = strat->sevS[i];
5068  s2r = strat->S_2_R[i];
5069  if (strat->fromQ!=NULL) fq=strat->fromQ[i];
5070  for (j=i; j>=at+1; j--)
5071  {
5072  strat->S[j] = strat->S[j-1];
5073  strat->ecartS[j] = strat->ecartS[j-1];
5074  strat->sevS[j] = strat->sevS[j-1];
5075  strat->S_2_R[j] = strat->S_2_R[j-1];
5076  }
5077  strat->S[at] = p;
5078  strat->ecartS[at] = ecart;
5079  strat->sevS[at] = sev;
5080  strat->S_2_R[at] = s2r;
5081  if (strat->fromQ!=NULL)
5082  {
5083  for (j=i; j>=at+1; j--)
5084  {
5085  strat->fromQ[j] = strat->fromQ[j-1];
5086  }
5087  strat->fromQ[at]=fq;
5088  }
5089  }
5090  }
5091  if (new_suc <= strat->sl) *suc=new_suc;
5092  else *suc=-1;
5093 }
5094 
5095 
5096 /*2
5097 *looks up the position of p in set
5098 *set[0] is the smallest with respect to the ordering-procedure deg/pComp
5099 * Assumption: posInS only depends on the leading term
5100 * otherwise, bba has to be changed
5101 */
5102 int posInS (const kStrategy strat, const int length,const poly p,
5103  const int ecart_p)
5104 {
5105  if(length==-1) return 0;
5106  polyset set=strat->S;
5107  int i;
5108  int an = 0;
5109  int en = length;
5110  int cmp_int = currRing->OrdSgn;
5112 #ifdef HAVE_PLURAL
5113  && (currRing->real_var_start==0)
5114 #endif
5115 #if 0
5116  || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
5117 #endif
5118  )
5119  {
5120  int o=p_Deg(p,currRing);
5121  int oo=p_Deg(set[length],currRing);
5122 
5123  if ((oo<o)
5124  || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
5125  return length+1;
5126 
5127  loop
5128  {
5129  if (an >= en-1)
5130  {
5131  if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
5132  {
5133  return an;
5134  }
5135  return en;
5136  }
5137  i=(an+en) / 2;
5138  if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
5139  else an=i;
5140  }
5141  }
5142  else
5143  {
5144  if (rField_is_Ring(currRing))
5145  {
5146  if (pLmCmp(set[length],p)== -cmp_int)
5147  return length+1;
5148  int cmp;
5149  loop
5150  {
5151  if (an >= en-1)
5152  {
5153  cmp = pLmCmp(set[an],p);
5154  if (cmp == cmp_int) return an;
5155  if (cmp == -cmp_int) return en;
5156  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
5157  return an;
5158  }
5159  i = (an+en) / 2;
5160  cmp = pLmCmp(set[i],p);
5161  if (cmp == cmp_int) en = i;
5162  else if (cmp == -cmp_int) an = i;
5163  else
5164  {
5165  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
5166  else en = i;
5167  }
5168  }
5169  }
5170  else
5171  if (pLmCmp(set[length],p)== -cmp_int)
5172  return length+1;
5173 
5174  loop
5175  {
5176  if (an >= en-1)
5177  {
5178  if (pLmCmp(set[an],p) == cmp_int) return an;
5179  if (pLmCmp(set[an],p) == -cmp_int) return en;
5180  if ((cmp_int!=1)
5181  && ((strat->ecartS[an])>ecart_p))
5182  return an;
5183  return en;
5184  }
5185  i=(an+en) / 2;
5186  if (pLmCmp(set[i],p) == cmp_int) en=i;
5187  else if (pLmCmp(set[i],p) == -cmp_int) an=i;
5188  else
5189  {
5190  if ((cmp_int!=1)
5191  &&((strat->ecartS[i])<ecart_p))
5192  en=i;
5193  else
5194  an=i;
5195  }
5196  }
5197  }
5198 }
5199 
5200 
5201 // sorts by degree and pLtCmp
5202 // but puts pure monomials at the beginning
5203 int posInSMonFirst (const kStrategy strat, const int length,const poly p)
5204 {
5205  if (length<0) return 0;
5206  polyset set=strat->S;
5207  if(pNext(p) == NULL)
5208  {
5209  int mon = 0;
5210  for(int i = 0;i<=length;i++)
5211  {
5212  if(set[i] != NULL && pNext(set[i]) == NULL)
5213  mon++;
5214  }
5215  int o = p_Deg(p,currRing);
5216  int op = p_Deg(set[mon],currRing);
5217 
5218  if ((op < o)
5219  || ((op == o) && (pLtCmp(set[mon],p) == -1)))
5220  return length+1;
5221  int i;
5222  int an = 0;
5223  int en= mon;
5224  loop
5225  {
5226  if (an >= en-1)
5227  {
5228  op = p_Deg(set[an],currRing);
5229  if ((op < o)
5230  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5231  return en;
5232  return an;
5233  }
5234  i=(an+en) / 2;
5235  op = p_Deg(set[i],currRing);
5236  if ((op < o)
5237  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5238  an=i;
5239  else
5240  en=i;
5241  }
5242  }
5243  else /*if(pNext(p) != NULL)*/
5244  {
5245  int o = p_Deg(p,currRing);
5246  int op = p_Deg(set[length],currRing);
5247 
5248  if ((op < o)
5249  || ((op == o) && (pLtCmp(set[length],p) == -1)))
5250  return length+1;
5251  int i;
5252  int an = 0;
5253  for(i=0;i<=length;i++)
5254  if(set[i] != NULL && pNext(set[i]) == NULL)
5255  an++;
5256  int en= length;
5257  loop
5258  {
5259  if (an >= en-1)
5260  {
5261  op = p_Deg(set[an],currRing);
5262  if ((op < o)
5263  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5264  return en;
5265  return an;
5266  }
5267  i=(an+en) / 2;
5268  op = p_Deg(set[i],currRing);
5269  if ((op < o)
5270  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5271  an=i;
5272  else
5273  en=i;
5274  }
5275  }
5276 }
5277 
5278 // sorts by degree and pLtCmp in the block between start,end;
5279 // but puts pure monomials at the beginning
5280 int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
5281 {
5282  if(end < 0 || end >= IDELEMS(F))
5283  end = IDELEMS(F);
5284  if (end<0) return 0;
5285  if(pNext(p) == NULL) return start;
5286  polyset set=F->m;
5287  int o = p_Deg(p,currRing);
5288  int op;
5289  int i;
5290  int an = start;
5291  for(i=start;i<end;i++)
5292  if(set[i] != NULL && pNext(set[i]) == NULL)
5293  an++;
5294  if(an == end-1)
5295  return end;
5296  int en= end;
5297  loop
5298  {
5299  if(an>=en)
5300  return en;
5301  if (an == en-1)
5302  {
5303  op = p_Deg(set[an],currRing);
5304  if ((op < o)
5305  || ((op == o) && (pLtCmp(set[an],p) == -1)))
5306  return en;
5307  return an;
5308  }
5309  i=(an+en) / 2;
5310  op = p_Deg(set[i],currRing);
5311  if ((op < o)
5312  || ((op == o) && (pLtCmp(set[i],p) == -1)))
5313  an=i;
5314  else
5315  en=i;
5316  }
5317 }
5318 
5319 
5320 /*2
5321 * looks up the position of p in set
5322 * the position is the last one
5323 */
5324 int posInT0 (const TSet,const int length,LObject &)
5325 {
5326  return (length+1);
5327 }
5328 
5329 
5330 /*2
5331 * looks up the position of p in T
5332 * set[0] is the smallest with respect to the ordering-procedure
5333 * pComp
5334 */
5335 int posInT1 (const TSet set,const int length,LObject &p)
5336 {
5337  if (length==-1) return 0;
5338 
5339  if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
5340 
5341  int i;
5342  int an = 0;
5343  int en= length;
5344 
5345  loop
5346  {
5347  if (an >= en-1)
5348  {
5349  if (pLmCmp(set[an].p,p.p) == currRing->OrdSgn) return an;
5350  return en;
5351  }
5352  i=(an+en) / 2;
5353  if (pLmCmp(set[i].p,p.p) == currRing->OrdSgn) en=i;
5354  else an=i;
5355  }
5356 }
5357 
5358 /*2
5359 * looks up the position of p in T
5360 * set[0] is the smallest with respect to the ordering-procedure
5361 * length
5362 */
5363 int posInT2 (const TSet set,const int length,LObject &p)
5364 {
5365  p.GetpLength();
5366  if (length==-1)
5367  return 0;
5368  if (set[length].length<p.length)
5369  return length+1;
5370 
5371  int i;
5372  int an = 0;
5373  int en= length;
5374 
5375  loop
5376  {
5377  if (an >= en-1)
5378  {
5379  if (set[an].length>p.length) return an;
5380  return en;
5381  }
5382  i=(an+en) / 2;
5383  if (set[i].length>p.length) en=i;
5384  else an=i;
5385  }
5386 }
5387 
5388 /*2
5389 * looks up the position of p in T
5390 * set[0] is the smallest with respect to the ordering-procedure
5391 * totaldegree,pComp
5392 */
5393 int posInT11 (const TSet set,const int length,LObject &p)
5394 {
5395  if (length==-1) return 0;
5396 
5397  int o = p.GetpFDeg();
5398  int op = set[length].GetpFDeg();
5399 
5400  if ((op < o)
5401  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5402  return length+1;
5403 
5404  int i;
5405  int an = 0;
5406  int en= length;
5407 
5408  loop
5409  {
5410  if (an >= en-1)
5411  {
5412  op= set[an].GetpFDeg();
5413  if ((op > o)
5414  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5415  return an;
5416  return en;
5417  }
5418  i=(an+en) / 2;
5419  op = set[i].GetpFDeg();
5420  if (( op > o)
5421  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5422  en=i;
5423  else
5424  an=i;
5425  }
5426 }
5427 
5428 #ifdef HAVE_RINGS
5429 int posInT11Ring (const TSet set,const int length,LObject &p)
5430 {
5431  if (length==-1) return 0;
5432 
5433  int o = p.GetpFDeg();
5434  int op = set[length].GetpFDeg();
5435 
5436  if ((op < o)
5437  || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5438  return length+1;
5439 
5440  int i;
5441  int an = 0;
5442  int en= length;
5443 
5444  loop
5445  {
5446  if (an >= en-1)
5447  {
5448  op= set[an].GetpFDeg();
5449  if ((op > o)
5450  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5451  return an;
5452  return en;
5453  }
5454  i=(an+en) / 2;
5455  op = set[i].GetpFDeg();
5456  if (( op > o)
5457  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5458  en=i;
5459  else
5460  an=i;
5461  }
5462 }
5463 #endif
5464 
5465 /*2 Pos for rings T: Here I am
5466 * looks up the position of p in T
5467 * set[0] is the smallest with respect to the ordering-procedure
5468 * totaldegree,pComp
5469 */
5470 int posInTrg0 (const TSet set,const int length,LObject &p)
5471 {
5472  if (length==-1) return 0;
5473  int o = p.GetpFDeg();
5474  int op = set[length].GetpFDeg();
5475  int i;
5476  int an = 0;
5477  int en = length;
5478  int cmp_int = currRing->OrdSgn;
5479  if ((op < o) || (pLmCmp(set[length].p,p.p)== -cmp_int))
5480  return length+1;
5481  int cmp;
5482  loop
5483  {
5484  if (an >= en-1)
5485  {
5486  op = set[an].GetpFDeg();
5487  if (op > o) return an;
5488  if (op < 0) return en;
5489  cmp = pLmCmp(set[an].p,p.p);
5490  if (cmp == cmp_int) return an;
5491  if (cmp == -cmp_int) return en;
5492  if (nGreater(pGetCoeff(p.p), pGetCoeff(set[an].p))) return en;
5493  return an;
5494  }
5495  i = (an + en) / 2;
5496  op = set[i].GetpFDeg();
5497  if (op > o) en = i;
5498  else if (op < o) an = i;
5499  else
5500  {
5501  cmp = pLmCmp(set[i].p,p.p);
5502  if (cmp == cmp_int) en = i;
5503  else if (cmp == -cmp_int) an = i;
5504  else if (nGreater(pGetCoeff(p.p), pGetCoeff(set[i].p))) an = i;
5505  else en = i;
5506  }
5507  }
5508 }
5509 /*
5510  int o = p.GetpFDeg();
5511  int op = set[length].GetpFDeg();
5512 
5513  if ((op < o)
5514  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5515  return length+1;
5516 
5517  int i;
5518  int an = 0;
5519  int en= length;
5520 
5521  loop
5522  {
5523  if (an >= en-1)
5524  {
5525  op= set[an].GetpFDeg();
5526  if ((op > o)
5527  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5528  return an;
5529  return en;
5530  }
5531  i=(an+en) / 2;
5532  op = set[i].GetpFDeg();
5533  if (( op > o)
5534  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5535  en=i;
5536  else
5537  an=i;
5538  }
5539 }
5540  */
5541 /*2
5542 * looks up the position of p in T
5543 * set[0] is the smallest with respect to the ordering-procedure
5544 * totaldegree,pComp
5545 */
5546 int posInT110 (const TSet set,const int length,LObject &p)
5547 {
5548  p.GetpLength();
5549  if (length==-1) return 0;
5550 
5551  int o = p.GetpFDeg();
5552  int op = set[length].GetpFDeg();
5553 
5554  if (( op < o)
5555  || (( op == o) && (set[length].length<p.length))
5556  || (( op == o) && (set[length].length == p.length)
5557  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5558  return length+1;
5559 
5560  int i;
5561  int an = 0;
5562  int en= length;
5563  loop
5564  {
5565  if (an >= en-1)
5566  {
5567  op = set[an].GetpFDeg();
5568  if (( op > o)
5569  || (( op == o) && (set[an].length > p.length))
5570  || (( op == o) && (set[an].length == p.length)
5571  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5572  return an;
5573  return en;
5574  }
5575  i=(an+en) / 2;
5576  op = set[i].GetpFDeg();
5577  if (( op > o)
5578  || (( op == o) && (set[i].length > p.length))
5579  || (( op == o) && (set[i].length == p.length)
5580  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5581  en=i;
5582  else
5583  an=i;
5584  }
5585 }
5586 
5587 #ifdef HAVE_RINGS
5588 int posInT110Ring (const TSet set,const int length,LObject &p)
5589 {
5590  p.GetpLength();
5591  if (length==-1) return 0;
5592 
5593  int o = p.GetpFDeg();
5594  int op = set[length].GetpFDeg();
5595 
5596  if (( op < o)
5597  || (( op == o) && (set[length].length<p.length))
5598  || (( op == o) && (set[length].length == p.length)
5599  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5600  return length+1;
5601 
5602  int i;
5603  int an = 0;
5604  int en= length;
5605  loop
5606  {
5607  if (an >= en-1)
5608  {
5609  op = set[an].GetpFDeg();
5610  if (( op > o)
5611  || (( op == o) && (set[an].length > p.length))
5612  || (( op == o) && (set[an].length == p.length)
5613  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5614  return an;
5615  return en;
5616  }
5617  i=(an+en) / 2;
5618  op = set[i].GetpFDeg();
5619  if (( op > o)
5620  || (( op == o) && (set[i].length > p.length))
5621  || (( op == o) && (set[i].length == p.length)
5622  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5623  en=i;
5624  else
5625  an=i;
5626  }
5627 }
5628 #endif
5629 
5630 /*2
5631 * looks up the position of p in set
5632 * set[0] is the smallest with respect to the ordering-procedure
5633 * pFDeg
5634 */
5635 int posInT13 (const TSet set,const int length,LObject &p)
5636 {
5637  if (length==-1) return 0;
5638 
5639  int o = p.GetpFDeg();
5640 
5641  if (set[length].GetpFDeg() <= o)
5642  return length+1;
5643 
5644  int i;
5645  int an = 0;
5646  int en= length;
5647  loop
5648  {
5649  if (an >= en-1)
5650  {
5651  if (set[an].GetpFDeg() > o)
5652  return an;
5653  return en;
5654  }
5655  i=(an+en) / 2;
5656  if (set[i].GetpFDeg() > o)
5657  en=i;
5658  else
5659  an=i;
5660  }
5661 }
5662 
5663 // determines the position based on: 1.) Ecart 2.) pLength
5664 int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5665 {
5666  int ol = p.GetpLength();
5667  if (length==-1) return 0;
5668 
5669  int op=p.ecart;
5670 
5671  int oo=set[length].ecart;
5672  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
5673  return length+1;
5674 
5675  int i;
5676  int an = 0;
5677  int en= length;
5678  loop
5679  {
5680  if (an >= en-1)
5681  {
5682  int oo=set[an].ecart;
5683  if((oo > op)
5684  || ((oo==op) && (set[an].pLength > ol)))
5685  return an;
5686  return en;
5687  }
5688  i=(an+en) / 2;
5689  int oo=set[i].ecart;
5690  if ((oo > op)
5691  || ((oo == op) && (set[i].pLength > ol)))
5692  en=i;
5693  else
5694  an=i;
5695  }
5696 }
5697 
5698 /*2
5699 * looks up the position of p in set
5700 * set[0] is the smallest with respect to the ordering-procedure
5701 * maximaldegree, pComp
5702 */
5703 int posInT15 (const TSet set,const int length,LObject &p)
5704 /*{
5705  *int j=0;
5706  * int o;
5707  *
5708  * o = p.GetpFDeg()+p.ecart;
5709  * loop
5710  * {
5711  * if ((set[j].GetpFDeg()+set[j].ecart > o)
5712  * || ((set[j].GetpFDeg()+set[j].ecart == o)
5713  * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5714  * {
5715  * return j;
5716  * }
5717  * j++;
5718  * if (j > length) return j;
5719  * }
5720  *}
5721  */
5722 {
5723  if (length==-1) return 0;
5724 
5725  int o = p.GetpFDeg() + p.ecart;
5726  int op = set[length].GetpFDeg()+set[length].ecart;
5727 
5728  if ((op < o)
5729  || ((op == o)
5730  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5731  return length+1;
5732 
5733  int i;
5734  int an = 0;
5735  int en= length;
5736  loop
5737  {
5738  if (an >= en-1)
5739  {
5740  op = set[an].GetpFDeg()+set[an].ecart;
5741  if (( op > o)
5742  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5743  return an;
5744  return en;
5745  }
5746  i=(an+en) / 2;
5747  op = set[i].GetpFDeg()+set[i].ecart;
5748  if (( op > o)
5749  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5750  en=i;
5751  else
5752  an=i;
5753  }
5754 }
5755 
5756 #ifdef HAVE_RINGS
5757 int posInT15Ring (const TSet set,const int length,LObject &p)
5758 {
5759  if (length==-1) return 0;
5760 
5761  int o = p.GetpFDeg() + p.ecart;
5762  int op = set[length].GetpFDeg()+set[length].ecart;
5763 
5764  if ((op < o)
5765  || ((op == o)
5766  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5767  return length+1;
5768 
5769  int i;
5770  int an = 0;
5771  int en= length;
5772  loop
5773  {
5774  if (an >= en-1)
5775  {
5776  op = set[an].GetpFDeg()+set[an].ecart;
5777  if (( op > o)
5778  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5779  return an;
5780  return en;
5781  }
5782  i=(an+en) / 2;
5783  op = set[i].GetpFDeg()+set[i].ecart;
5784  if (( op > o)
5785  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5786  en=i;
5787  else
5788  an=i;
5789  }
5790 }
5791 #endif
5792 
5793 /*2
5794 * looks up the position of p in set
5795 * set[0] is the smallest with respect to the ordering-procedure
5796 * pFDeg+ecart, ecart, pComp
5797 */
5798 int posInT17 (const TSet set,const int length,LObject &p)
5799 /*
5800 *{
5801 * int j=0;
5802 * int o;
5803 *
5804 * o = p.GetpFDeg()+p.ecart;
5805 * loop
5806 * {
5807 * if ((pFDeg(set[j].p)+set[j].ecart > o)
5808 * || (((pFDeg(set[j].p)+set[j].ecart == o)
5809 * && (set[j].ecart < p.ecart)))
5810 * || ((pFDeg(set[j].p)+set[j].ecart == o)
5811 * && (set[j].ecart==p.ecart)
5812 * && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5813 * return j;
5814 * j++;
5815 * if (j > length) return j;
5816 * }
5817 * }
5818 */
5819 {
5820  if (length==-1) return 0;
5821 
5822  int o = p.GetpFDeg() + p.ecart;
5823  int op = set[length].GetpFDeg()+set[length].ecart;
5824 
5825  if ((op < o)
5826  || (( op == o) && (set[length].ecart > p.ecart))
5827  || (( op == o) && (set[length].ecart==p.ecart)
5828  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5829  return length+1;
5830 
5831  int i;
5832  int an = 0;
5833  int en= length;
5834  loop
5835  {
5836  if (an >= en-1)
5837  {
5838  op = set[an].GetpFDeg()+set[an].ecart;
5839  if (( op > o)
5840  || (( op == o) && (set[an].ecart < p.ecart))
5841  || (( op == o) && (set[an].ecart==p.ecart)
5842  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5843  return an;
5844  return en;
5845  }
5846  i=(an+en) / 2;
5847  op = set[i].GetpFDeg()+set[i].ecart;
5848  if ((op > o)
5849  || (( op == o) && (set[i].ecart < p.ecart))
5850  || (( op == o) && (set[i].ecart == p.ecart)
5851  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5852  en=i;
5853  else
5854  an=i;
5855  }
5856 }
5857 
5858 #ifdef HAVE_RINGS
5859 int posInT17Ring (const TSet set,const int length,LObject &p)
5860 {
5861  if (length==-1) return 0;
5862 
5863  int o = p.GetpFDeg() + p.ecart;
5864  int op = set[length].GetpFDeg()+set[length].ecart;
5865 
5866  if ((op < o)
5867  || (( op == o) && (set[length].ecart > p.ecart))
5868  || (( op == o) && (set[length].ecart==p.ecart)
5869  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5870  return length+1;
5871 
5872  int i;
5873  int an = 0;
5874  int en= length;
5875  loop
5876  {
5877  if (an >= en-1)
5878  {
5879  op = set[an].GetpFDeg()+set[an].ecart;
5880  if (( op > o)
5881  || (( op == o) && (set[an].ecart < p.ecart))
5882  || (( op == o) && (set[an].ecart==p.ecart)
5883  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5884  return an;
5885  return en;
5886  }
5887  i=(an+en) / 2;
5888  op = set[i].GetpFDeg()+set[i].ecart;
5889  if ((op > o)
5890  || (( op == o) && (set[i].ecart < p.ecart))
5891  || (( op == o) && (set[i].ecart == p.ecart)
5892  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5893  en=i;
5894  else
5895  an=i;
5896  }
5897 }
5898 #endif
5899 
5900 /*2
5901 * looks up the position of p in set
5902 * set[0] is the smallest with respect to the ordering-procedure
5903 * pGetComp, pFDeg+ecart, ecart, pComp
5904 */
5905 int posInT17_c (const TSet set,const int length,LObject &p)
5906 {
5907  if (length==-1) return 0;
5908 
5909  int cc = (-1+2*currRing->order[0]==ringorder_c);
5910  /* cc==1 for (c,..), cc==-1 for (C,..) */
5911  int o = p.GetpFDeg() + p.ecart;
5912  int c = pGetComp(p.p)*cc;
5913 
5914  if (pGetComp(set[length].p)*cc < c)
5915  return length+1;
5916  if (pGetComp(set[length].p)*cc == c)
5917  {
5918  int op = set[length].GetpFDeg()+set[length].ecart;
5919  if ((op < o)
5920  || ((op == o) && (set[length].ecart > p.ecart))
5921  || ((op == o) && (set[length].ecart==p.ecart)
5922  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5923  return length+1;
5924  }
5925 
5926  int i;
5927  int an = 0;
5928  int en= length;
5929  loop
5930  {
5931  if (an >= en-1)
5932  {
5933  if (pGetComp(set[an].p)*cc < c)
5934  return en;
5935  if (pGetComp(set[an].p)*cc == c)
5936  {
5937  int op = set[an].GetpFDeg()+set[an].ecart;
5938  if ((op > o)
5939  || ((op == o) && (set[an].ecart < p.ecart))
5940  || ((op == o) && (set[an].ecart==p.ecart)
5941  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5942  return an;
5943  }
5944  return en;
5945  }
5946  i=(an+en) / 2;
5947  if (pGetComp(set[i].p)*cc > c)
5948  en=i;
5949  else if (pGetComp(set[i].p)*cc == c)
5950  {
5951  int op = set[i].GetpFDeg()+set[i].ecart;
5952  if ((op > o)
5953  || ((op == o) && (set[i].ecart < p.ecart))
5954  || ((op == o) && (set[i].ecart == p.ecart)
5955  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5956  en=i;
5957  else
5958  an=i;
5959  }
5960  else
5961  an=i;
5962  }
5963 }
5964 
5965 #ifdef HAVE_RINGS
5966 int posInT17_cRing (const TSet set,const int length,LObject &p)
5967 {
5968  if (length==-1) return 0;
5969 
5970  int cc = (-1+2*currRing->order[0]==ringorder_c);
5971  /* cc==1 for (c,..), cc==-1 for (C,..) */
5972  int o = p.GetpFDeg() + p.ecart;
5973  int c = pGetComp(p.p)*cc;
5974 
5975  if (pGetComp(set[length].p)*cc < c)
5976  return length+1;
5977  if (pGetComp(set[length].p)*cc == c)
5978  {
5979  int op = set[length].GetpFDeg()+set[length].ecart;
5980  if ((op < o)
5981  || ((op == o) && (set[length].ecart > p.ecart))
5982  || ((op == o) && (set[length].ecart==p.ecart)
5983  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5984  return length+1;
5985  }
5986 
5987  int i;
5988  int an = 0;
5989  int en= length;
5990  loop
5991  {
5992  if (an >= en-1)
5993  {
5994  if (pGetComp(set[an].p)*cc < c)
5995  return en;
5996  if (pGetComp(set[an].p)*cc == c)
5997  {
5998  int op = set[an].GetpFDeg()+set[an].ecart;
5999  if ((op > o)
6000  || ((op == o) && (set[an].ecart < p.ecart))
6001  || ((op == o) && (set[an].ecart==p.ecart)
6002  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
6003  return an;
6004  }
6005  return en;
6006  }
6007  i=(an+en) / 2;
6008  if (pGetComp(set[i].p)*cc > c)
6009  en=i;
6010  else if (pGetComp(set[i].p)*cc == c)
6011  {
6012  int op = set[i].GetpFDeg()+set[i].ecart;
6013  if ((op > o)
6014  || ((op == o) && (set[i].ecart < p.ecart))
6015  || ((op == o) && (set[i].ecart == p.ecart)
6016  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
6017  en=i;
6018  else
6019  an=i;
6020  }
6021  else
6022  an=i;
6023  }
6024 }
6025 #endif
6026 
6027 /*2
6028 * looks up the position of p in set
6029 * set[0] is the smallest with respect to
6030 * ecart, pFDeg, length
6031 */
6032 int posInT19 (const TSet set,const int length,LObject &p)
6033 {
6034  p.GetpLength();
6035  if (length==-1) return 0;
6036 
6037  int o = p.ecart;
6038  int op=p.GetpFDeg();
6039 
6040  if (set[length].ecart < o)
6041  return length+1;
6042  if (set[length].ecart == o)
6043  {
6044  int oo=set[length].GetpFDeg();
6045  if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
6046  return length+1;
6047  }
6048 
6049  int i;
6050  int an = 0;
6051  int en= length;
6052  loop
6053  {
6054  if (an >= en-1)
6055  {
6056  if (set[an].ecart > o)
6057  return an;
6058  if (set[an].ecart == o)
6059  {
6060  int oo=set[an].GetpFDeg();
6061  if((oo > op)
6062  || ((oo==op) && (set[an].length > p.length)))
6063  return an;
6064  }
6065  return en;
6066  }
6067  i=(an+en) / 2;
6068  if (set[i].ecart > o)
6069  en=i;
6070  else if (set[i].ecart == o)
6071  {
6072  int oo=set[i].GetpFDeg();
6073  if ((oo > op)
6074  || ((oo == op) && (set[i].length > p.length)))
6075  en=i;
6076  else
6077  an=i;
6078  }
6079  else
6080  an=i;
6081  }
6082 }
6083 
6084 /*2
6085 *looks up the position of polynomial p in set
6086 *set[length] is the smallest element in set with respect
6087 *to the ordering-procedure pComp
6088 */
6089 int posInLSpecial (const LSet set, const int length,
6090  LObject *p,const kStrategy)
6091 {
6092  if (length<0) return 0;
6093 
6094  int d=p->GetpFDeg();
6095  int op=set[length].GetpFDeg();
6096 
6097  if ((op > d)
6098  || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
6099  || (pLmCmp(set[length].p,p->p)== currRing->OrdSgn))
6100  return length+1;
6101 
6102  int i;
6103  int an = 0;
6104  int en= length;
6105  loop
6106  {
6107  if (an >= en-1)
6108  {
6109  op=set[an].GetpFDeg();
6110  if ((op > d)
6111  || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
6112  || (pLmCmp(set[an].p,p->p)== currRing->OrdSgn))
6113  return en;
6114  return an;
6115  }
6116  i=(an+en) / 2;
6117  op=set[i].GetpFDeg();
6118  if ((op>d)
6119  || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
6120  || (pLmCmp(set[i].p,p->p) == currRing->OrdSgn))
6121  an=i;
6122  else
6123  en=i;
6124  }
6125 }
6126 
6127 /*2
6128 *looks up the position of polynomial p in set
6129 *set[length] is the smallest element in set with respect
6130 *to the ordering-procedure pComp
6131 */
6132 int posInL0 (const LSet set, const int length,
6133  LObject* p,const kStrategy)
6134 {
6135  if (length<0) return 0;
6136 
6137  if (pLmCmp(set[length].p,p->p)== currRing->OrdSgn)
6138  return length+1;
6139 
6140  int i;
6141  int an = 0;
6142  int en= length;
6143  loop
6144  {
6145  if (an >= en-1)
6146  {
6147  if (pLmCmp(set[an].p,p->p) == currRing->OrdSgn) return en;
6148  return an;
6149  }
6150  i=(an+en) / 2;
6151  if (pLmCmp(set[i].p,p->p) == currRing->OrdSgn) an=i;
6152  else en=i;
6153  /*aend. fuer lazy == in !=- machen */
6154  }
6155 }
6156 
6157 #ifdef HAVE_RINGS
6158 int posInL0Ring (const LSet set, const int length,
6159  LObject* p,const kStrategy)
6160 {
6161  if (length<0) return 0;
6162 
6163  if (pLtCmpOrdSgnEqP(set[length].p,p->p))
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 (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
6174  return an;
6175  }
6176  i=(an+en) / 2;
6177  if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
6178  else en=i;
6179  /*aend. fuer lazy == in !=- machen */
6180  }
6181 }
6182 #endif
6183 
6184 /*2
6185 * looks up the position of polynomial p in set
6186 * e is the ecart of p
6187 * set[length] is the smallest element in set with respect
6188 * to the signature order
6189 */
6190 int posInLSig (const LSet set, const int length,
6191  LObject* p,const kStrategy /*strat*/)
6192 {
6193  if (length<0) return 0;
6194  if (pLtCmp(set[length].sig,p->sig)== currRing->OrdSgn)
6195  return length+1;
6196 
6197  int i;
6198  int an = 0;
6199  int en= length;
6200  loop
6201  {
6202  if (an >= en-1)
6203  {
6204  if (pLtCmp(set[an].sig,p->sig) == currRing->OrdSgn) return en;
6205  return an;
6206  }
6207  i=(an+en) / 2;
6208  if (pLtCmp(set[i].sig,p->sig) == currRing->OrdSgn) an=i;
6209  else en=i;
6210  /*aend. fuer lazy == in !=- machen */
6211  }
6212 }
6213 //sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
6214 int posInLSigRing (const LSet set, const int length,
6215  LObject* p,const kStrategy /*strat*/)
6216 {
6217  assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
6218  if (length<0) return 0;
6219  if (pLtCmp(set[length].sig,p->sig)== 1)
6220  return length+1;
6221 
6222  int an,en,i;
6223  an = 0;
6224  en = length+1;
6225  int cmp;
6226  loop
6227  {
6228  if (an >= en-1)
6229  {
6230  if(an == en)
6231  return en;
6232  cmp = pLtCmp(set[an].sig,p->sig);
6233  if (cmp == 1)
6234  return en;
6235  if (cmp == -1)
6236  return an;
6237  if (cmp == 0)
6238  {
6239  if (set[an].FDeg > p->FDeg)
6240  return en;
6241  if (set[an].FDeg < p->FDeg)
6242  return an;
6243  if (set[an].FDeg == p->FDeg)
6244  {
6245  cmp = pLtCmp(set[an].p,p->p);
6246  if(cmp == 1)
6247  return en;
6248  else
6249  return an;
6250  }
6251  }
6252  }
6253  i=(an+en) / 2;
6254  cmp = pLtCmp(set[i].sig,p->sig);
6255  if (cmp == 1)
6256  an = i;
6257  if (cmp == -1)
6258  en = i;
6259  if (cmp == 0)
6260  {
6261  if (set[i].FDeg > p->FDeg)
6262  an = i;
6263  if (set[i].FDeg < p->FDeg)
6264  en = i;
6265  if (set[i].FDeg == p->FDeg)
6266  {
6267  cmp = pLtCmp(set[i].p,p->p);
6268  if(cmp == 1)
6269  an = i;
6270  else
6271  en = i;
6272  }
6273  }
6274  }
6275 }
6276 
6277 int posInLRing (const LSet set, const int length,
6278  LObject* p,const kStrategy /*strat*/)
6279 {
6280  if (length < 0) return 0;
6281  if (set[length].FDeg > p->FDeg)
6282  return length+1;
6283  if (set[length].FDeg == p->FDeg)
6284  if(set[length].GetpLength() > p->GetpLength())
6285  return length+1;
6286  int i;
6287  int an = 0;
6288  int en= length+1;
6289  loop
6290  {
6291  if (an >= en-1)
6292  {
6293  if(an == en)
6294  return en;
6295  if (set[an].FDeg > p->FDeg)
6296  return en;
6297  if(set[an].FDeg == p->FDeg)
6298  {
6299  if(set[an].GetpLength() > p->GetpLength())
6300  return en;
6301  else
6302  {
6303  if(set[an].GetpLength() == p->GetpLength())
6304  {
6305  if(nGreater(set[an].p->coef, p->p->coef))
6306  return en;
6307  else
6308  return an;
6309  }
6310  else
6311  {
6312  return an;
6313  }
6314  }
6315  }
6316  else
6317  return an;
6318  }
6319  i=(an+en) / 2;
6320  if (set[i].FDeg > p->FDeg)
6321  an=i;
6322  else
6323  {
6324  if(set[i].FDeg == p->FDeg)
6325  {
6326  if(set[i].GetpLength() > p->GetpLength())
6327  an=i;
6328  else
6329  {
6330  if(set[i].GetpLength() == p->GetpLength())
6331  {
6332  if(nGreater(set[i].p->coef, p->p->coef))
6333  an = i;
6334  else
6335  en = i;
6336  }
6337  else
6338  {
6339  en=i;
6340  }
6341  }
6342  }
6343  else
6344  en=i;
6345  }
6346  }
6347 }
6348 
6349 // for sba, sorting syzygies
6350 int posInSyz (const kStrategy strat, poly sig)
6351 {
6352  if (strat->syzl==0) return 0;
6353  if (pLtCmp(strat->syz[strat->syzl-1],sig) != currRing->OrdSgn)
6354  return strat->syzl;
6355  int i;
6356  int an = 0;
6357  int en= strat->syzl-1;
6358  loop
6359  {
6360  if (an >= en-1)
6361  {
6362  if (pLtCmp(strat->syz[an],sig) != currRing->OrdSgn) return en;
6363  return an;
6364  }
6365  i=(an+en) / 2;
6366  if (pLtCmp(strat->syz[i],sig) != currRing->OrdSgn) an=i;
6367  else en=i;
6368  /*aend. fuer lazy == in !=- machen */
6369  }
6370 }
6371 
6372 /*2
6373 *
6374 * is only used in F5C, must ensure that the interreduction process does add new
6375 * critical pairs to strat->L only behind all other critical pairs which are
6376 * still in strat->L!
6377 */
6378 int posInLF5C (const LSet /*set*/, const int /*length*/,
6379  LObject* /*p*/,const kStrategy strat)
6380 {
6381  return strat->Ll+1;
6382 }
6383 
6384 /*2
6385 * looks up the position of polynomial p in set
6386 * e is the ecart of p
6387 * set[length] is the smallest element in set with respect
6388 * to the ordering-procedure totaldegree,pComp
6389 */
6390 int posInL11 (const LSet set, const int length,
6391  LObject* p,const kStrategy)
6392 {
6393  if (length<0) return 0;
6394 
6395  int o = p->GetpFDeg();
6396  int op = set[length].GetpFDeg();
6397 
6398  if ((op > o)
6399  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6400  return length+1;
6401  int i;
6402  int an = 0;
6403  int en= length;
6404  loop
6405  {
6406  if (an >= en-1)
6407  {
6408  op = set[an].GetpFDeg();
6409  if ((op > o)
6410  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6411  return en;
6412  return an;
6413  }
6414  i=(an+en) / 2;
6415  op = set[i].GetpFDeg();
6416  if ((op > o)
6417  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6418  an=i;
6419  else
6420  en=i;
6421  }
6422 }
6423 
6424 #ifdef HAVE_RINGS
6425 /*2
6426 * looks up the position of polynomial p in set
6427 * set[length] is the smallest element in set with respect
6428 * to the ordering-procedure pLmCmp,totaldegree,coefficient
6429 * For the same totaldegree, original pairs (from F) will
6430 * be put at the end and smalles coefficents
6431 */
6432 int posInL11Ring (const LSet set, const int length,
6433  LObject* p,const kStrategy)
6434 {
6435  if (length<0) return 0;
6436 
6437  int o = p->GetpFDeg();
6438  int op = set[length].GetpFDeg();
6439 
6440  if ((op > o)
6441  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6442  return length+1;
6443  int i;
6444  int an = 0;
6445  int en= length;
6446  loop
6447  {
6448  if (an >= en-1)
6449  {
6450  op = set[an].GetpFDeg();
6451  if ((op > o)
6452  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6453  return en;
6454  return an;
6455  }
6456  i=(an+en) / 2;
6457  op = set[i].GetpFDeg();
6458  if ((op > o)
6459  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6460  an=i;
6461  else
6462  en=i;
6463  }
6464 }
6465 
6466 int posInLF5CRing (const LSet set, int start,const int length,
6467  LObject* p,const kStrategy)
6468 {
6469  if (length<0) return 0;
6470  if(start == (length +1)) return (length+1);
6471  int o = p->GetpFDeg();
6472  int op = set[length].GetpFDeg();
6473 
6474  if ((op > o)
6475  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6476  return length+1;
6477  int i;
6478  int an = start;
6479  int en= length;
6480  loop
6481  {
6482  if (an >= en-1)
6483  {
6484  op = set[an].GetpFDeg();
6485  if ((op > o)
6486  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6487  return en;
6488  return an;
6489  }
6490  i=(an+en) / 2;
6491  op = set[i].GetpFDeg();
6492  if ((op > o)
6493  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6494  an=i;
6495  else
6496  en=i;
6497  }
6498 }
6499 #endif
6500 
6501 #ifdef HAVE_RINGS
6502 int posInL11Ringls (const LSet set, const int length,
6503  LObject* p,const kStrategy)
6504 {
6505  if (length < 0) return 0;
6506  int an,en,i;
6507  an = 0;
6508  en = length+1;
6509  loop
6510  {
6511  if (an >= en-1)
6512  {
6513  if(an == en)
6514  return en;
6515  if (set[an].FDeg > p->FDeg)
6516  return en;
6517  if (set[an].FDeg < p->FDeg)
6518  return an;
6519  if (set[an].FDeg == p->FDeg)
6520  {
6521  number lcset,lcp;
6522  lcset = pGetCoeff(set[an].p);
6523  lcp = pGetCoeff(p->p);
6524  if(!nGreaterZero(lcset))
6525  {
6526  set[an].p=p_Neg(set[an].p,currRing);
6527  if (set[an].t_p!=NULL)
6528  pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
6529  lcset=pGetCoeff(set[an].p);
6530  }
6531  if(!nGreaterZero(lcp))
6532  {
6533  p->p=p_Neg(p->p,currRing);
6534  if (p->t_p!=NULL)
6535  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6536  lcp=pGetCoeff(p->p);
6537  }
6538  if(nGreater(lcset, lcp))
6539  {
6540  return en;
6541  }
6542  else
6543  {
6544  return an;
6545  }
6546  }
6547  }
6548  i=(an+en) / 2;
6549  if (set[i].FDeg > p->FDeg)
6550  an=i;
6551  if (set[i].FDeg < p->FDeg)
6552  en=i;
6553  if (set[i].FDeg == p->FDeg)
6554  {
6555  number lcset,lcp;
6556  lcset = pGetCoeff(set[i].p);
6557  lcp = pGetCoeff(p->p);
6558  if(!nGreaterZero(lcset))
6559  {
6560  set[i].p=p_Neg(set[i].p,currRing);
6561  if (set[i].t_p!=NULL)
6562  pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6563  lcset=pGetCoeff(set[i].p);
6564  }
6565  if(!nGreaterZero(lcp))
6566  {
6567  p->p=p_Neg(p->p,currRing);
6568  if (p->t_p!=NULL)
6569  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6570  lcp=pGetCoeff(p->p);
6571  }
6572  if(nGreater(lcset, lcp))
6573  {
6574  an = i;
6575  }
6576  else
6577  {
6578  en = i;
6579  }
6580  }
6581  }
6582 }
6583 #endif
6584 
6585 /*2 Position for rings L: Here I am
6586 * looks up the position of polynomial p in set
6587 * e is the ecart of p
6588 * set[length] is the smallest element in set with respect
6589 * to the ordering-procedure totaldegree,pComp
6590 */
6591 inline int getIndexRng(long coeff)
6592 {
6593  if (coeff == 0) return -1;
6594  long tmp = coeff;
6595  int ind = 0;
6596  while (tmp % 2 == 0)
6597  {
6598  tmp = tmp / 2;
6599  ind++;
6600  }
6601  return ind;
6602 }
6603 
6604 int posInLrg0 (const LSet set, const int length,
6605  LObject* p,const kStrategy)
6606 /* if (nGreater(pGetCoeff(p), pGetCoeff(set[an]))) return en;
6607  if (pLmCmp(set[i],p) == cmp_int) en = i;
6608  else if (pLmCmp(set[i],p) == -cmp_int) an = i;
6609  else
6610  {
6611  if (nGreater(pGetCoeff(p), pGetCoeff(set[i]))) an = i;
6612  else en = i;
6613  }*/
6614 {
6615  if (length < 0) return 0;
6616 
6617  int o = p->GetpFDeg();
6618  int op = set[length].GetpFDeg();
6619 
6620  if ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6621  return length + 1;
6622  int i;
6623  int an = 0;
6624  int en = length;
6625  loop
6626  {
6627  if (an >= en - 1)
6628  {
6629  op = set[an].GetpFDeg();
6630  if ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6631  return en;
6632  return an;
6633  }
6634  i = (an+en) / 2;
6635  op = set[i].GetpFDeg();
6636  if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6637  an = i;
6638  else
6639  en = i;
6640  }
6641 }
6642 
6643 /*{
6644  if (length < 0) return 0;
6645 
6646  int o = p->GetpFDeg();
6647  int op = set[length].GetpFDeg();
6648 
6649  int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6650  int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6651  int inda;
6652  int indi;
6653 
6654  if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6655  return length + 1;
6656  int i;
6657  int an = 0;
6658  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6659  int en = length;
6660  loop
6661  {
6662  if (an >= en-1)
6663  {
6664  op = set[an].GetpFDeg();
6665  if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6666  return en;
6667  return an;
6668  }
6669  i = (an + en) / 2;
6670  indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6671  op = set[i].GetpFDeg();
6672  if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6673  // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6674  {
6675  an = i;
6676  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6677  }
6678  else
6679  en = i;
6680  }
6681 } */
6682 
6683 /*2
6684 * looks up the position of polynomial p in set
6685 * set[length] is the smallest element in set with respect
6686 * to the ordering-procedure totaldegree,pLength0
6687 */
6688 int posInL110 (const LSet set, const int length,
6689  LObject* p,const kStrategy)
6690 {
6691  if (length<0) return 0;
6692 
6693  int o = p->GetpFDeg();
6694  int op = set[length].GetpFDeg();
6695 
6696  if ((op > o)
6697  || ((op == o) && (set[length].length >p->length))
6698  || ((op == o) && (set[length].length <= p->length)
6699  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6700  return length+1;
6701  int i;
6702  int an = 0;
6703  int en= length;
6704  loop
6705  {
6706  if (an >= en-1)
6707  {
6708  op = set[an].GetpFDeg();
6709  if ((op > o)
6710  || ((op == o) && (set[an].length >p->length))
6711  || ((op == o) && (set[an].length <=p->length)
6712  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6713  return en;
6714  return an;
6715  }
6716  i=(an+en) / 2;
6717  op = set[i].GetpFDeg();
6718  if ((op > o)
6719  || ((op == o) && (set[i].length > p->length))
6720  || ((op == o) && (set[i].length <= p->length)
6721  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6722  an=i;
6723  else
6724  en=i;
6725  }
6726 }
6727 
6728 #ifdef HAVE_RINGS
6729 int posInL110Ring (const LSet set, const int length,
6730  LObject* p,const kStrategy)
6731 {
6732  if (length<0) return 0;
6733 
6734  int o = p->GetpFDeg();
6735  int op = set[length].GetpFDeg();
6736 
6737  if ((op > o)
6738  || ((op == o) && (set[length].length >p->length))
6739  || ((op == o) && (set[length].length <= p->length)
6740  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6741  return length+1;
6742  int i;
6743  int an = 0;
6744  int en= length;
6745  loop
6746  {
6747  if (an >= en-1)
6748  {
6749  op = set[an].GetpFDeg();
6750  if ((op > o)
6751  || ((op == o) && (set[an].length >p->length))
6752  || ((op == o) && (set[an].length <=p->length)
6753  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6754  return en;
6755  return an;
6756  }
6757  i=(an+en) / 2;
6758  op = set[i].GetpFDeg();
6759  if ((op > o)
6760  || ((op == o) && (set[i].length > p->length))
6761  || ((op == o) && (set[i].length <= p->length)
6762  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6763  an=i;
6764  else
6765  en=i;
6766  }
6767 }
6768 #endif
6769 
6770 /*2
6771 * looks up the position of polynomial p in set
6772 * e is the ecart of p
6773 * set[length] is the smallest element in set with respect
6774 * to the ordering-procedure totaldegree
6775 */
6776 int posInL13 (const LSet set, const int length,
6777  LObject* p,const kStrategy)
6778 {
6779  if (length<0) return 0;
6780 
6781  int o = p->GetpFDeg();
6782 
6783  if (set[length].GetpFDeg() > o)
6784  return length+1;
6785 
6786  int i;
6787  int an = 0;
6788  int en= length;
6789  loop
6790  {
6791  if (an >= en-1)
6792  {
6793  if (set[an].GetpFDeg() >= o)
6794  return en;
6795  return an;
6796  }
6797  i=(an+en) / 2;
6798  if (set[i].GetpFDeg() >= o)
6799  an=i;
6800  else
6801  en=i;
6802  }
6803 }
6804 
6805 /*2
6806 * looks up the position of polynomial p in set
6807 * e is the ecart of p
6808 * set[length] is the smallest element in set with respect
6809 * to the ordering-procedure maximaldegree,pComp
6810 */
6811 int posInL15 (const LSet set, const int length,
6812  LObject* p,const kStrategy)
6813 {
6814  if (length<0) return 0;
6815 
6816  int o = p->GetpFDeg() + p->ecart;
6817  int op = set[length].GetpFDeg() + set[length].ecart;
6818 
6819  if ((op > o)
6820  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6821  return length+1;
6822  int i;
6823  int an = 0;
6824  int en= length;
6825  loop
6826  {
6827  if (an >= en-1)
6828  {
6829  op = set[an].GetpFDeg() + set[an].ecart;
6830  if ((op > o)
6831  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6832  return en;
6833  return an;
6834  }
6835  i=(an+en) / 2;
6836  op = set[i].GetpFDeg() + set[i].ecart;
6837  if ((op > o)
6838  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6839  an=i;
6840  else
6841  en=i;
6842  }
6843 }
6844 
6845 #ifdef HAVE_RINGS
6846 int posInL15Ring (const LSet set, const int length,
6847  LObject* p,const kStrategy)
6848 {
6849  if (length<0) return 0;
6850 
6851  int o = p->GetpFDeg() + p->ecart;
6852  int op = set[length].GetpFDeg() + set[length].ecart;
6853 
6854  if ((op > o)
6855  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6856  return length+1;
6857  int i;
6858  int an = 0;
6859  int en= length;
6860  loop
6861  {
6862  if (an >= en-1)
6863  {
6864  op = set[an].GetpFDeg() + set[an].ecart;
6865  if ((op > o)
6866  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6867  return en;
6868  return an;
6869  }
6870  i=(an+en) / 2;
6871  op = set[i].GetpFDeg() + set[i].ecart;
6872  if ((op > o)
6873  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6874  an=i;
6875  else
6876  en=i;
6877  }
6878 }
6879 #endif
6880 
6881 /*2
6882 * looks up the position of polynomial p in set
6883 * e is the ecart of p
6884 * set[length] is the smallest element in set with respect
6885 * to the ordering-procedure totaldegree
6886 */
6887 int posInL17 (const LSet set, const int length,
6888  LObject* p,const kStrategy)
6889 {
6890  if (length<0) return 0;
6891 
6892  int o = p->GetpFDeg() + p->ecart;
6893 
6894  if ((set[length].GetpFDeg() + set[length].ecart > o)
6895  || ((set[length].GetpFDeg() + set[length].ecart == o)
6896  && (set[length].ecart > p->ecart))
6897  || ((set[length].GetpFDeg() + set[length].ecart == o)
6898  && (set[length].ecart == p->ecart)
6899  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6900  return length+1;
6901  int i;
6902  int an = 0;
6903  int en= length;
6904  loop
6905  {
6906  if (an >= en-1)
6907  {
6908  if ((set[an].GetpFDeg() + set[an].ecart > o)
6909  || ((set[an].GetpFDeg() + set[an].ecart == o)
6910  && (set[an].ecart > p->ecart))
6911  || ((set[an].GetpFDeg() + set[an].ecart == o)
6912  && (set[an].ecart == p->ecart)
6913  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6914  return en;
6915  return an;
6916  }
6917  i=(an+en) / 2;
6918  if ((set[i].GetpFDeg() + set[i].ecart > o)
6919  || ((set[i].GetpFDeg() + set[i].ecart == o)
6920  && (set[i].ecart > p->ecart))
6921  || ((set[i].GetpFDeg() +set[i].ecart == o)
6922  && (set[i].ecart == p->ecart)
6923  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6924  an=i;
6925  else
6926  en=i;
6927  }
6928 }
6929 
6930 #ifdef HAVE_RINGS
6931 int posInL17Ring (const LSet set, const int length,
6932  LObject* p,const kStrategy)
6933 {
6934  if (length<0) return 0;
6935 
6936  int o = p->GetpFDeg() + p->ecart;
6937 
6938  if ((set[length].GetpFDeg() + set[length].ecart > o)
6939  || ((set[length].GetpFDeg() + set[length].ecart == o)
6940  && (set[length].ecart > p->ecart))
6941  || ((set[length].GetpFDeg() + set[length].ecart == o)
6942  && (set[length].ecart == p->ecart)
6943  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6944  return length+1;
6945  int i;
6946  int an = 0;
6947  int en= length;
6948  loop
6949  {
6950  if (an >= en-1)
6951  {
6952  if ((set[an].GetpFDeg() + set[an].ecart > o)
6953  || ((set[an].GetpFDeg() + set[an].ecart == o)
6954  && (set[an].ecart > p->ecart))
6955  || ((set[an].GetpFDeg() + set[an].ecart == o)
6956  && (set[an].ecart == p->ecart)
6957  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6958  return en;
6959  return an;
6960  }
6961  i=(an+en) / 2;
6962  if ((set[i].GetpFDeg() + set[i].ecart > o)
6963  || ((set[i].GetpFDeg() + set[i].ecart == o)
6964  && (set[i].ecart > p->ecart))
6965  || ((set[i].GetpFDeg() +set[i].ecart == o)
6966  && (set[i].ecart == p->ecart)
6967  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6968  an=i;
6969  else
6970  en=i;
6971  }
6972 }
6973 #endif
6974 
6975 /*2
6976 * looks up the position of polynomial p in set
6977 * e is the ecart of p
6978 * set[length] is the smallest element in set with respect
6979 * to the ordering-procedure pComp
6980 */
6981 int posInL17_c (const LSet set, const int length,
6982  LObject* p,const kStrategy)
6983 {
6984  if (length<0) return 0;
6985 
6986  int cc = (-1+2*currRing->order[0]==ringorder_c);
6987  /* cc==1 for (c,..), cc==-1 for (C,..) */
6988  unsigned long c = pGetComp(p->p)*cc;
6989  int o = p->GetpFDeg() + p->ecart;
6990 
6991  if (pGetComp(set[length].p)*cc > c)
6992  return length+1;
6993  if (pGetComp(set[length].p)*cc == c)
6994  {
6995  if ((set[length].GetpFDeg() + set[length].ecart > o)
6996  || ((set[length].GetpFDeg() + set[length].ecart == o)
6997  && (set[length].ecart > p->ecart))
6998  || ((set[length].GetpFDeg() + set[length].ecart == o)
6999  && (set[length].ecart == p->ecart)
7000  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
7001  return length+1;
7002  }
7003  int i;
7004  int an = 0;
7005  int en= length;
7006  loop
7007  {
7008  if (an >= en-1)
7009  {
7010  if (pGetComp(set[an].p)*cc > c)
7011  return en;
7012  if (pGetComp(set[an].p)*cc == c)
7013  {
7014  if ((set[an].GetpFDeg() + set[an].ecart > o)
7015  || ((set[an].GetpFDeg() + set[an].ecart == o)
7016  && (set[an].ecart > p->ecart))
7017  || ((set[an].GetpFDeg() + set[an].ecart == o)
7018  && (set[an].ecart == p->ecart)
7019  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
7020  return en;
7021  }
7022  return an;
7023  }
7024  i=(an+en) / 2;
7025  if (pGetComp(set[i].p)*cc > c)
7026  an=i;
7027  else if (pGetComp(set[i].p)*cc == c)
7028  {
7029  if ((set[i].GetpFDeg() + set[i].ecart > o)
7030  || ((set[i].GetpFDeg() + set[i].ecart == o)
7031  && (set[i].ecart > p->ecart))
7032  || ((set[i].GetpFDeg() +set[i].ecart == o)
7033  && (set[i].ecart == p->ecart)
7034  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
7035  an=i;
7036  else
7037  en=i;
7038  }
7039  else
7040  en=i;
7041  }
7042 }
7043 
7044 #ifdef HAVE_RINGS
7045 int posInL17_cRing (const LSet set, const int length,
7046  LObject* p,const kStrategy)
7047 {
7048  if (length<0) return 0;
7049 
7050  int cc = (-1+2*currRing->order[0]==ringorder_c);
7051  /* cc==1 for (c,..), cc==-1 for (C,..) */
7052  unsigned long c = pGetComp(p->p)*cc;
7053  int o = p->GetpFDeg() + p->ecart;
7054 
7055  if (pGetComp(set[length].p)*cc > c)
7056  return length+1;
7057  if (pGetComp(set[length].p)*cc == c)
7058  {
7059  if ((set[length].GetpFDeg() + set[length].ecart > o)
7060  || ((set[length].GetpFDeg() + set[length].ecart == o)
7061  && (set[length].ecart > p->ecart))
7062  || ((set[length].GetpFDeg() + set[length].ecart == o)
7063  && (set[length].ecart == p->ecart)
7064  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
7065  return length+1;
7066  }
7067  int i;
7068  int an = 0;
7069  int en= length;
7070  loop
7071  {
7072  if (an >= en-1)
7073  {
7074  if (pGetComp(set[an].p)*cc > c)
7075  return en;
7076  if (pGetComp(set[an].p)*cc == c)
7077  {
7078  if ((set[an].GetpFDeg() + set[an].ecart > o)
7079  || ((set[an].GetpFDeg() + set[an].ecart == o)
7080  && (set[an].ecart > p->ecart))
7081  || ((set[an].GetpFDeg() + set[an].ecart == o)
7082  && (set[an].ecart == p->ecart)
7083  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
7084  return en;
7085  }
7086  return an;
7087  }
7088  i=(an+en) / 2;
7089  if (pGetComp(set[i].p)*cc > c)
7090  an=i;
7091  else if (pGetComp(set[i].p)*cc == c)
7092  {
7093  if ((set[i].GetpFDeg() + set[i].ecart > o)
7094  || ((set[i].GetpFDeg() + set[i].ecart == o)
7095  && (set[i].ecart > p->ecart))
7096  || ((set[i].GetpFDeg() +set[i].ecart == o)
7097  && (set[i].ecart == p->ecart)
7098  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
7099  an=i;
7100  else
7101  en=i;
7102  }
7103  else
7104  en=i;
7105  }
7106 }
7107 #endif
7108 
7109 /*
7110  * SYZYGY CRITERION for signature-based standard basis algorithms
7111  */
7112 BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
7113 {
7114 //#if 1
7115 #ifdef DEBUGF5
7116  PrintS("syzygy criterion checks: ");
7117  pWrite(sig);
7118 #endif
7119  for (int k=0; k<strat->syzl; k++)
7120  {
7121  //printf("-%d",k);
7122 //#if 1
7123 #ifdef DEBUGF5
7124  Print("checking with: %d / %d -- \n",k,strat->syzl);
7125  pWrite(pHead(strat->syz[k]));
7126 #endif
7127  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7128  && (!rField_is_Ring(currRing) ||
7129  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7130  {
7131 //#if 1
7132 #ifdef DEBUGF5
7133  PrintS("DELETE!\n");
7134 #endif
7135  #ifdef ADIDEBUG
7136  printf("\nsyzCrit:\n");pWrite(strat->syz[k]);pWrite(sig);
7137  #endif
7138  strat->nrsyzcrit++;
7139  //printf("- T -\n\n");
7140  return TRUE;
7141  }
7142  }
7143  //printf("- F -\n\n");
7144  return FALSE;
7145 }
7146 
7147 /*
7148  * SYZYGY CRITERION for signature-based standard basis algorithms
7149  */
7150 BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
7151 {
7152 //#if 1
7153  if(sig == NULL)
7154  return FALSE;
7155 #ifdef DEBUGF5
7156  PrintS("--- syzygy criterion checks: ");
7157  pWrite(sig);
7158 #endif
7159  int comp = p_GetComp(sig, currRing);
7160  int min, max;
7161  if (comp<=1)
7162  return FALSE;
7163  else
7164  {
7165  min = strat->syzIdx[comp-2];
7166  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
7167  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
7168  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
7169  if (comp == strat->currIdx)
7170  {
7171  max = strat->syzl;
7172  }
7173  else
7174  {
7175  max = strat->syzIdx[comp-1];
7176  }
7177  for (int k=min; k<max; k++)
7178  {
7179 #ifdef F5DEBUG
7180  Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
7181  Print("checking with: %d -- ",k);
7182  pWrite(pHead(strat->syz[k]));
7183 #endif
7184  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
7185  && (!rField_is_Ring(currRing) ||
7186  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
7187  {
7188  #ifdef ADIDEBUG
7189  printf("\nsyzCrit:\n");pWrite(strat->syz[k]);pWrite(sig);
7190  #endif
7191  strat->nrsyzcrit++;
7192  return TRUE;
7193  }
7194  }
7195  return FALSE;
7196  }
7197 }
7198 
7199 /*
7200  * REWRITTEN CRITERION for signature-based standard basis algorithms
7201  */
7202 BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
7203 {
7204  //printf("Faugere Rewritten Criterion\n");
7206  return FALSE;
7207 //#if 1
7208 #ifdef DEBUGF5
7209  PrintS("rewritten criterion checks: ");
7210  pWrite(sig);
7211 #endif
7212  for(int k = strat->sl; k>=start; k--)
7213  {
7214 //#if 1
7215 #ifdef DEBUGF5
7216  PrintS("checking with: ");
7217  pWrite(strat->sig[k]);
7218  pWrite(pHead(strat->S[k]));
7219 #endif
7220  if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
7221  {
7222 //#if 1
7223 #ifdef DEBUGF5
7224  PrintS("DELETE!\n");
7225 #endif
7226  #ifdef ADIDEBUG
7227  printf("\nFaugere RewCrit: * divisible by *\n");pWrite(sig);pWrite(strat->sig[k]);
7228  #endif
7229  strat->nrrewcrit++;
7230  return TRUE;
7231  }
7232  //k--;
7233  }
7234 #ifdef DEBUGF5
7235  PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
7236  for(int kk = 0; kk<strat->sl+1; kk++)
7237  {
7238  pWrite(pHead(strat->S[kk]));
7239  }
7240  PrintS("------------------------------\n");
7241 #endif
7242  return FALSE;
7243 }
7244 
7245 /*
7246  * REWRITTEN CRITERION for signature-based standard basis algorithms
7247  ***************************************************************************
7248  * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
7249  ***************************************************************************
7250  */
7251 
7252 // real implementation of arri's rewritten criterion, only called once in
7253 // kstd2.cc, right before starting reduction
7254 // IDEA: Arri says that it is enough to consider 1 polynomial for each unique
7255 // signature appearing during the computations. Thus we first of all go
7256 // through strat->L and delete all other pairs of the same signature,
7257 // keeping only the one with least possible leading monomial. After this
7258 // we check if we really need to compute this critical pair at all: There
7259 // can be elements already in strat->S whose signatures divide the
7260 // signature of the critical pair in question and whose multiplied
7261 // leading monomials are smaller than the leading monomial of the
7262 // critical pair. In this situation we can discard the critical pair
7263 // completely.
7264 BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
7265 {
7266  #ifdef ADIDEBUG
7267  printf("\narriRewCrit\n");
7268  #endif
7270  return FALSE;
7271  poly p1 = pOne();
7272  poly p2 = pOne();
7273  for (int ii=strat->sl; ii>start; ii--)
7274  {
7275  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
7276  {
7277  p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
7279  if (!(pLmCmp(p1,p2) == 1))
7280  {
7281  #ifdef ADIDEBUG
7282  printf("\narriRewCrit deleted: sig, P.sig\n");
7283  #endif
7284  pDelete(&p1);
7285  pDelete(&p2);
7286  return TRUE;
7287  }
7288  }
7289  }
7290  pDelete(&p1);
7291  pDelete(&p2);
7292  return FALSE;
7293 }
7294 
7295 BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
7296 {
7297  #ifdef ADIDEBUG
7298  printf("\narriRewCritPre\n");
7299  #endif
7300  //Over Rings, there are still some changes to do: considering coeffs
7302  return FALSE;
7303  int found = -1;
7304  for (int i=strat->Bl; i>-1; i--) {
7305  if (pLmEqual(strat->B[i].sig,sig))
7306  {
7307  found = i;
7308  break;
7309  }
7310  }
7311  if (found != -1)
7312  {
7313  if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
7314  {
7316  #ifdef ADIDEBUG
7317  printf("\nDelete!\n");
7318  #endif
7319  }
7320  else
7321  {
7322  #ifdef ADIDEBUG
7323  printf("\nDelete this one!\n");
7324  #endif
7325  return TRUE;
7326  }
7327  }
7328  poly p1 = pOne();
7329  poly p2 = pOne();
7330  for (int ii=strat->sl; ii>-1; ii--)
7331  {
7332  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
7333  {
7334  p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
7335  p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
7336  if (!(pLmCmp(p1,p2) == 1))
7337  {
7338  pDelete(&p1);
7339  pDelete(&p2);
7340  #ifdef ADIDEBUG
7341  printf("\nDelete this one!\n");
7342  #endif
7343  return TRUE;
7344  }
7345  }
7346  }
7347  pDelete(&p1);
7348  pDelete(&p2);
7349  return FALSE;
7350 }
7351 
7352 /***************************************************************
7353  *
7354  * Tail reductions
7355  *
7356  ***************************************************************/
7357 TObject*
7359  long ecart)
7360 {
7361  int j = 0;
7362  const unsigned long not_sev = ~L->sev;
7363  const unsigned long* sev = strat->sevS;
7364  poly p;
7365  ring r;
7366  L->GetLm(p, r);
7367 
7368  assume(~not_sev == p_GetShortExpVector(p, r));
7369 
7370  if (r == currRing)
7371  {
7372  if(!rField_is_Ring(r))
7373  {
7374  loop
7375  {
7376  if (j > pos) return NULL;
7377  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7378  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7379  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7380  {
7381  break;
7382  }
7383  #else
7384  if (!(sev[j] & not_sev) &&
7385  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7386  p_LmDivisibleBy(strat->S[j], p, r))
7387  {
7388  break;
7389  }
7390  #endif
7391  j++;
7392  }
7393  }
7394  #ifdef HAVE_RINGS
7395  else
7396  {
7397  loop
7398  {
7399  if (j > pos) return NULL;
7400  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7401  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7402  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7403  {
7404  break;
7405  }
7406  #else
7407  if (!(sev[j] & not_sev) &&
7408  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7409  p_LmDivisibleBy(strat->S[j], p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7410  {
7411  break;
7412  }
7413  #endif
7414  j++;
7415  }
7416  }
7417  #endif
7418  // if called from NF, T objects do not exist:
7419  if (strat->tl < 0 || strat->S_2_R[j] == -1)
7420  {
7421  T->Set(strat->S[j], r, strat->tailRing);
7422  return T;
7423  }
7424  else
7425  {
7426 ///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
7427 ///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
7428 // assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
7429  return strat->S_2_T(j);
7430  }
7431  }
7432  else
7433  {
7434  TObject* t;
7435  if(!rField_is_Ring(r))
7436  {
7437  loop
7438  {
7439  if (j > pos) return NULL;
7440  assume(strat->S_2_R[j] != -1);
7441  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7442  t = strat->S_2_T(j);
7443  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7444  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7445  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7446  {
7447  return t;
7448  }
7449  #else
7450  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7451  {
7452  t = strat->S_2_T(j);
7453  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7454  if (p_LmDivisibleBy(t->t_p, p, r))
7455  {
7456  return t;
7457  }
7458  }
7459  #endif
7460  j++;
7461  }
7462  }
7463  #ifdef HAVE_RINGS
7464  else
7465  {
7466  loop
7467  {
7468  if (j > pos) return NULL;
7469  assume(strat->S_2_R[j] != -1);
7470  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7471  t = strat->S_2_T(j);
7472  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7473  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7474  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7475  {
7476  return t;
7477  }
7478  #else
7479  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7480  {
7481  t = strat->S_2_T(j);
7482  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7483  if (p_LmDivisibleBy(t->t_p, p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7484  {
7485  return t;
7486  }
7487  }
7488  #endif
7489  j++;
7490  }
7491  }
7492  #endif
7493  }
7494 }
7495 
7497 {
7498  poly h, hn;
7500 
7501  L->GetP();
7502  poly p = L->p;
7503  if (strat->noTailReduction || pNext(p) == NULL)
7504  return p;
7505 
7506  LObject Ln(strat->tailRing);
7507  TObject* With;
7508  // placeholder in case strat->tl < 0
7509  TObject With_s(strat->tailRing);
7510  h = p;
7511  hn = pNext(h);
7512  long op = strat->tailRing->pFDeg(hn, strat->tailRing);
7513  long e;
7514  int l;
7515  BOOLEAN save_HE=strat->kHEdgeFound;
7516  strat->kHEdgeFound |=
7517  ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
7518 
7519  while(hn != NULL)
7520  {
7521  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7522  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7523  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7524  loop
7525  {
7526  Ln.Set(hn, strat->tailRing);
7527  Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
7528  if (strat->kHEdgeFound)
7529  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
7530  else
7531  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s, e);
7532  if (With == NULL) break;
7533  With->length=0;
7534  With->pLength=0;
7536  if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
7537  {
7538  // reducing the tail would violate the exp bound
7539  if (kStratChangeTailRing(strat, L))
7540  {
7541  strat->kHEdgeFound = save_HE;
7542  return redtail(L, pos, strat);
7543  }
7544  else
7545  return NULL;
7546  }
7547  hn = pNext(h);
7548  if (hn == NULL) goto all_done;
7549  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7550  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7551  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7552  }
7553  h = hn;
7554  hn = pNext(h);
7555  }
7556 
7557  all_done:
7558  if (strat->redTailChange)
7559  {
7560  L->pLength = 0;
7561  }
7562  strat->kHEdgeFound = save_HE;
7563  return p;
7564 }
7565 
7567 {
7568  LObject L(p, currRing);
7569  return redtail(&L, pos, strat);
7570 }
7571 
7573 {
7574 #define REDTAIL_CANONICALIZE 100
7576  if (strat->noTailReduction) return L->GetLmCurrRing();
7577  poly h, p;
7578  p = h = L->GetLmTailRing();
7579  if ((h==NULL) || (pNext(h)==NULL))
7580  return L->GetLmCurrRing();
7581 
7582  TObject* With;
7583  // placeholder in case strat->tl < 0
7584  TObject With_s(strat->tailRing);
7585 
7586  LObject Ln(pNext(h), strat->tailRing);
7587  Ln.pLength = L->GetpLength() - 1;
7588 
7589  pNext(h) = NULL;
7590  if (L->p != NULL) pNext(L->p) = NULL;
7591  L->pLength = 1;
7592 
7593  Ln.PrepareRed(strat->use_buckets);
7594 
7595  int cnt=REDTAIL_CANONICALIZE;
7596  while(!Ln.IsNull())
7597  {
7598  loop
7599  {
7600  if (TEST_OPT_IDLIFT)
7601  {
7602  if (Ln.p!=NULL)
7603  {
7604  if (p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7605  }
7606  else
7607  {
7608  if (p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7609  }
7610  }
7611  Ln.SetShortExpVector();
7612  if (withT)
7613  {
7614  int j;
7615  j = kFindDivisibleByInT(strat, &Ln);
7616  if (j < 0) break;
7617  With = &(strat->T[j]);
7618  }
7619  else
7620  {
7621  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
7622  if (With == NULL) break;
7623  }
7624  cnt--;
7625  if (cnt==0)
7626  {
7628  /*poly tmp=*/Ln.CanonicalizeP();
7629  if (normalize)
7630  {
7631  Ln.Normalize();
7632  //pNormalize(tmp);
7633  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7634  }
7635  }
7636  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7637  {
7638  With->pNorm();
7639  }
7641  if (ksReducePolyTail(L, With, &Ln))
7642  {
7643  // reducing the tail would violate the exp bound
7644  // set a flag and hope for a retry (in bba)
7646  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7647  do
7648  {
7649  pNext(h) = Ln.LmExtractAndIter();
7650  pIter(h);
7651  L->pLength++;
7652  } while (!Ln.IsNull());
7653  goto all_done;
7654  }
7655  if (Ln.IsNull()) goto all_done;
7656  if (! withT) With_s.Init(currRing);
7657  }
7658  pNext(h) = Ln.LmExtractAndIter();
7659  pIter(h);
7660  pNormalize(h);
7661  L->pLength++;
7662  }
7663 
7664  all_done:
7665  Ln.Delete();
7666  if (L->p != NULL) pNext(L->p) = pNext(p);
7667 
7668  if (strat->redTailChange)
7669  {
7670  L->length = 0;
7671  L->pLength = 0;
7672  }
7673 
7674  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7675  //L->Normalize(); // HANNES: should have a test
7676  kTest_L(L);
7677  return L->GetLmCurrRing();
7678 }
7679 
7681 {
7682 #define REDTAIL_CANONICALIZE 100
7684  if (strat->noTailReduction) return L->GetLmCurrRing();
7685  poly h, p;
7686  p = h = L->GetLmTailRing();
7687  if ((h==NULL) || (pNext(h)==NULL))
7688  return L->GetLmCurrRing();
7689 
7690  TObject* With;
7691  // placeholder in case strat->tl < 0
7692  TObject With_s(strat->tailRing);
7693 
7694  LObject Ln(pNext(h), strat->tailRing);
7695  Ln.pLength = L->GetpLength() - 1;
7696 
7697  pNext(h) = NULL;
7698  if (L->p != NULL) pNext(L->p) = NULL;
7699  L->pLength = 1;
7700 
7701  Ln.PrepareRed(strat->use_buckets);
7702 
7703  int cnt=REDTAIL_CANONICALIZE;
7704  while(!Ln.IsNull())
7705  {
7706  loop
7707  {
7708  if (TEST_OPT_IDLIFT)
7709  {
7710  if (Ln.p!=NULL)
7711  {
7712  if (p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7713  }
7714  else
7715  {
7716  if (p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7717  }
7718  }
7719  Ln.SetShortExpVector();
7720  if (withT)
7721  {
7722  int j;
7723  j = kFindDivisibleByInT(strat, &Ln);
7724  if (j < 0) break;
7725  With = &(strat->T[j]);
7726  }
7727  else
7728  {
7729  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
7730  if (With == NULL) break;
7731  }
7732  cnt--;
7733  if (cnt==0)
7734  {
7736  /*poly tmp=*/Ln.CanonicalizeP();
7737  if (normalize)
7738  {
7739  Ln.Normalize();
7740  //pNormalize(tmp);
7741  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7742  }
7743  }
7744  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7745  {
7746  With->pNorm();
7747  }
7749  if (ksReducePolyTail(L, With, &Ln))
7750  {
7751  // reducing the tail would violate the exp bound
7752  // set a flag and hope for a retry (in bba)
7754  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7755  do
7756  {
7757  pNext(h) = Ln.LmExtractAndIter();
7758  pIter(h);
7759  L->pLength++;
7760  } while (!Ln.IsNull());
7761  goto all_done;
7762  }
7763  if(!Ln.IsNull())
7764  {
7765  Ln.GetP();
7766  Ln.p = pJet(Ln.p,bound);
7767  }
7768  if (Ln.IsNull())
7769  {
7770  goto all_done;
7771  }
7772  if (! withT) With_s.Init(currRing);
7773  }
7774  pNext(h) = Ln.LmExtractAndIter();
7775  pIter(h);
7776  pNormalize(h);
7777  L->pLength++;
7778  }
7779 
7780  all_done:
7781  Ln.Delete();
7782  if (L->p != NULL) pNext(L->p) = pNext(p);
7783 
7784  if (strat->redTailChange)
7785  {
7786  L->length = 0;
7787  L->pLength = 0;
7788  }
7789 
7790  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7791  //L->Normalize(); // HANNES: should have a test
7792  kTest_L(L);
7793  return L->GetLmCurrRing();
7794 }
7795 
7796 #ifdef HAVE_RINGS
7798 // normalize=FALSE, withT=FALSE, coeff=Z
7799 {
7801  if (strat->noTailReduction) return L->GetLmCurrRing();
7802  poly h, p;
7803  p = h = L->GetLmTailRing();
7804  if ((h==NULL) || (pNext(h)==NULL))
7805  return L->GetLmCurrRing();
7806 
7807  TObject* With;
7808  // placeholder in case strat->tl < 0
7809  TObject With_s(strat->tailRing);
7810 
7811  LObject Ln(pNext(h), strat->tailRing);
7812  Ln.pLength = L->GetpLength() - 1;
7813 
7814  pNext(h) = NULL;
7815  if (L->p != NULL) pNext(L->p) = NULL;
7816  L->pLength = 1;
7817 
7818  Ln.PrepareRed(strat->use_buckets);
7819 
7820  int cnt=REDTAIL_CANONICALIZE;
7821  while(!Ln.IsNull())
7822  {
7823  loop
7824  {
7825  Ln.SetShortExpVector();
7826  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
7827  if (With == NULL) break;
7828  cnt--;
7829  if (cnt==0)
7830  {
7832  /*poly tmp=*/Ln.CanonicalizeP();
7833  }
7834  // we are in Z, do not call pNorm
7836  // test divisibility of coefs:
7837  poly p_Ln=Ln.GetLmCurrRing();
7838  poly p_With=With->GetLmCurrRing();
7839  number z=n_IntMod(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf);
7840  if (!nIsZero(z))
7841  {
7842  // subtract z*Ln, add z.Ln to L
7843  poly m=pHead(p_Ln);
7844  pSetCoeff(m,z);
7845  poly mm=pHead(m);
7846  pNext(h) = m;
7847  pIter(h);
7848  L->pLength++;
7849  mm=pNeg(mm);
7850  if (Ln.bucket!=NULL)
7851  {
7852  int dummy=1;
7853  kBucket_Add_q(Ln.bucket,mm,&dummy);
7854  }
7855  else
7856  {
7857  if ((Ln.t_p!=NULL)&&(Ln.p==NULL))
7858  Ln.GetP();
7859  if (Ln.p!=NULL)
7860  {
7861  Ln.p=pAdd(Ln.p,mm);
7862  if (Ln.t_p!=NULL)
7863  {
7864  pNext(Ln.t_p)=NULL;
7865  p_LmDelete(Ln.t_p,strat->tailRing);
7866  }
7867  }
7868  }
7869  }
7870  else
7871  nDelete(&z);
7872 
7873  if (ksReducePolyTail(L, With, &Ln))
7874  {
7875  // reducing the tail would violate the exp bound
7876  // set a flag and hope for a retry (in bba)
7878  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7879  do
7880  {
7881  pNext(h) = Ln.LmExtractAndIter();
7882  pIter(h);
7883  L->pLength++;
7884  } while (!Ln.IsNull());
7885  goto all_done;
7886  }
7887  if (Ln.IsNull()) goto all_done;
7888  With_s.Init(currRing);
7889  }
7890  pNext(h) = Ln.LmExtractAndIter();
7891  pIter(h);
7892  pNormalize(h);
7893  L->pLength++;
7894  }
7895 
7896  all_done:
7897  Ln.Delete();
7898  if (L->p != NULL) pNext(L->p) = pNext(p);
7899 
7900  if (strat->redTailChange)
7901  {
7902  L->length = 0;
7903  }
7904 
7905  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7906  //L->Normalize(); // HANNES: should have a test
7907  kTest_L(L);
7908  return L->GetLmCurrRing();
7909 }
7910 #endif
7911 
7912 /*2
7913 *checks the change degree and write progress report
7914 */
7915 void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7916 {
7917  if (i != *olddeg)
7918  {
7919  Print("%d",i);
7920  *olddeg = i;
7921  }
7922  if (TEST_OPT_OLDSTD)
7923  {
7924  if (strat->Ll != *reduc)
7925  {
7926  if (strat->Ll != *reduc-1)
7927  Print("(%d)",strat->Ll+1);
7928  else
7929  PrintS("-");
7930  *reduc = strat->Ll;
7931  }
7932  else
7933  PrintS(".");
7934  mflush();
7935  }
7936  else
7937  {
7938  if (red_result == 0)
7939  PrintS("-");
7940  else if (red_result < 0)
7941  PrintS(".");
7942  if ((red_result > 0) || ((strat->Ll % 100)==99))
7943  {
7944  if (strat->Ll != *reduc && strat->Ll > 0)
7945  {
7946  Print("(%d)",strat->Ll+1);
7947  *reduc = strat->Ll;
7948  }
7949  }
7950  }
7951 }
7952 
7953 /*2
7954 *statistics
7955 */
7956 void messageStat (int hilbcount,kStrategy strat)
7957 {
7958  //PrintS("\nUsage/Allocation of temporary storage:\n");
7959  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7960  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7961  Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7962  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7963  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7964  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7965  /*mflush();*/
7966 }
7967 
7968 void messageStatSBA (int hilbcount,kStrategy strat)
7969 {
7970  //PrintS("\nUsage/Allocation of temporary storage:\n");
7971  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7972  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7973  Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7974  //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7975  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7976  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7977  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7978  /*mflush();*/
7979 }
7980 
7981 #ifdef KDEBUG
7982 /*2
7983 *debugging output: all internal sets, if changed
7984 *for testing purpuse only/has to be changed for later use
7985 */
7987 {
7988  int i;
7989  if (strat->news)
7990  {
7991  PrintS("set S");
7992  for (i=0; i<=strat->sl; i++)
7993  {
7994  Print("\n %d:",i);
7996  }
7997  strat->news = FALSE;
7998  }
7999  if (strat->newt)
8000  {
8001  PrintS("\nset T");
8002  for (i=0; i<=strat->tl; i++)
8003  {
8004  Print("\n %d:",i);
8005  strat->T[i].wrp();
8006  Print(" o:%ld e:%d l:%d",
8007  strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
8008  }
8009  strat->newt = FALSE;
8010  }
8011  PrintS("\nset L");
8012  for (i=strat->Ll; i>=0; i--)
8013  {
8014  Print("\n%d:",i);
8015  p_wrp(strat->L[i].p1, currRing, strat->tailRing);
8016  PrintS(" ");
8017  p_wrp(strat->L[i].p2, currRing, strat->tailRing);
8018  PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
8019  PrintS("\n p : ");
8020  strat->L[i].wrp();
8021  Print(" o:%ld e:%d l:%d",
8022  strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
8023  }
8024  PrintLn();
8025 }
8026 
8027 #endif
8028 
8029 
8030 /*2
8031 *construct the set s from F
8032 */
8033 void initS (ideal F, ideal Q, kStrategy strat)
8034 {
8035  int i,pos;
8036 
8037  if (Q!=NULL) i=((IDELEMS(F)+IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8038  else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8039  strat->ecartS=initec(i);
8040  strat->sevS=initsevS(i);
8041  strat->S_2_R=initS_2_R(i);
8042  strat->fromQ=NULL;
8043  strat->Shdl=idInit(i,F->rank);
8044  strat->S=strat->Shdl->m;
8045  /*- put polys into S -*/
8046  if (Q!=NULL)
8047  {
8048  strat->fromQ=initec(i);
8049  memset(strat->fromQ,0,i*sizeof(int));
8050  for (i=0; i<IDELEMS(Q); i++)
8051  {
8052  if (Q->m[i]!=NULL)
8053  {
8054  LObject h;
8055  h.p = pCopy(Q->m[i]);
8057  {
8058  //pContent(h.p);
8059  h.pCleardenom(); // also does a pContent
8060  }
8061  else
8062  {
8063  h.pNorm();
8064  }
8066  {
8067  deleteHC(&h, strat);
8068  }
8069  if (h.p!=NULL)
8070  {
8071  strat->initEcart(&h);
8072  if (strat->sl==-1)
8073  pos =0;
8074  else
8075  {
8076  pos = posInS(strat,strat->sl,h.p,h.ecart);
8077  }
8078  h.sev = pGetShortExpVector(h.p);
8079  strat->enterS(h,pos,strat,-1);
8080  strat->fromQ[pos]=1;
8081  }
8082  }
8083  }
8084  }
8085  for (i=0; i<IDELEMS(F); i++)
8086  {
8087  if (F->m[i]!=NULL)
8088  {
8089  LObject h;
8090  h.p = pCopy(F->m[i]);
8092  {
8093  cancelunit(&h); /*- tries to cancel a unit -*/
8094  deleteHC(&h, strat);
8095  }
8096  if (h.p!=NULL)
8097  // do not rely on the input being a SB!
8098  {
8100  {
8101  //pContent(h.p);
8102  h.pCleardenom(); // also does a pContent
8103  }
8104  else
8105  {
8106  h.pNorm();
8107  }
8108  strat->initEcart(&h);
8109  if (strat->sl==-1)
8110  pos =0;
8111  else
8112  pos = posInS(strat,strat->sl,h.p,h.ecart);
8113  h.sev = pGetShortExpVector(h.p);
8114  strat->enterS(h,pos,strat,-1);
8115  }
8116  }
8117  }
8118  /*- test, if a unit is in F -*/
8119  if ((strat->sl>=0)
8120 #ifdef HAVE_RINGS
8121  && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
8122 #endif
8123  && pIsConstant(strat->S[0]))
8124  {
8125  while (strat->sl>0) deleteInS(strat->sl,strat);
8126  }
8127 }
8128 
8129 void initSL (ideal F, ideal Q,kStrategy strat)
8130 {
8131  int i,pos;
8132 
8133  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8134  else i=setmaxT;
8135  strat->ecartS=initec(i);
8136  strat->sevS=initsevS(i);
8137  strat->S_2_R=initS_2_R(i);
8138  strat->fromQ=NULL;
8139  strat->Shdl=idInit(i,F->rank);
8140  strat->S=strat->Shdl->m;
8141  /*- put polys into S -*/
8142  if (Q!=NULL)
8143  {
8144  strat->fromQ=initec(i);
8145  memset(strat->fromQ,0,i*sizeof(int));
8146  for (i=0; i<IDELEMS(Q); i++)
8147  {
8148  if (Q->m[i]!=NULL)
8149  {
8150  LObject h;
8151  h.p = pCopy(Q->m[i]);
8153  {
8154  deleteHC(&h,strat);
8155  }
8157  {
8158  //pContent(h.p);
8159  h.pCleardenom(); // also does a pContent
8160  }
8161  else
8162  {
8163  h.pNorm();
8164  }
8165  if (h.p!=NULL)
8166  {
8167  strat->initEcart(&h);
8168  if (strat->sl==-1)
8169  pos =0;
8170  else
8171  {
8172  pos = posInS(strat,strat->sl,h.p,h.ecart);
8173  }
8174  h.sev = pGetShortExpVector(h.p);
8175  strat->enterS(h,pos,strat,-1);
8176  strat->fromQ[pos]=1;
8177  }
8178  }
8179  }
8180  }
8181  for (i=0; i<IDELEMS(F); i++)
8182  {
8183  if (F->m[i]!=NULL)
8184  {
8185  LObject h;
8186  h.p = pCopy(F->m[i]);
8187  if (h.p!=NULL)
8188  {
8190  {
8191  cancelunit(&h); /*- tries to cancel a unit -*/
8192  deleteHC(&h, strat);
8193  }
8194  if (h.p!=NULL)
8195  {
8197  {
8198  //pContent(h.p);
8199  h.pCleardenom(); // also does a pContent
8200  }
8201  else
8202  {
8203  h.pNorm();
8204  }
8205  strat->initEcart(&h);
8206  if (strat->Ll==-1)
8207  pos =0;
8208  else
8209  pos = strat->posInL(strat->L,strat->Ll,&h,strat);
8210  h.sev = pGetShortExpVector(h.p);
8211  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8212  }
8213  }
8214  }
8215  }
8216  /*- test, if a unit is in F -*/
8217 
8218  if ((strat->Ll>=0)
8219 #ifdef HAVE_RINGS
8220  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8221 #endif
8222  && pIsConstant(strat->L[strat->Ll].p))
8223  {
8224  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8225  }
8226 }
8227 
8228 void initSLSba (ideal F, ideal Q,kStrategy strat)
8229 {
8230  int i,pos;
8231  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8232  else i=setmaxT;
8233  strat->ecartS = initec(i);
8234  strat->sevS = initsevS(i);
8235  strat->sevSig = initsevS(i);
8236  strat->S_2_R = initS_2_R(i);
8237  strat->fromQ = NULL;
8238  strat->Shdl = idInit(i,F->rank);
8239  strat->S = strat->Shdl->m;
8240  strat->sig = (poly *)omAlloc0(i*sizeof(poly));
8241  if (strat->sbaOrder != 1)
8242  {
8243  strat->syz = (poly *)omAlloc0(i*sizeof(poly));
8244  strat->sevSyz = initsevS(i);
8245  strat->syzmax = i;
8246  strat->syzl = 0;
8247  }
8248  /*- put polys into S -*/
8249  if (Q!=NULL)
8250  {
8251  strat->fromQ=initec(i);
8252  memset(strat->fromQ,0,i*sizeof(int));
8253  for (i=0; i<IDELEMS(Q); i++)
8254  {
8255  if (Q->m[i]!=NULL)
8256  {
8257  LObject h;
8258  h.p = pCopy(Q->m[i]);
8260  {
8261  deleteHC(&h,strat);
8262  }
8264  {
8265  //pContent(h.p);
8266  h.pCleardenom(); // also does a pContent
8267  }
8268  else
8269  {
8270  h.pNorm();
8271  }
8272  if (h.p!=NULL)
8273  {
8274  strat->initEcart(&h);
8275  if (strat->sl==-1)
8276  pos =0;
8277  else
8278  {
8279  pos = posInS(strat,strat->sl,h.p,h.ecart);
8280  }
8281  h.sev = pGetShortExpVector(h.p);
8282  strat->enterS(h,pos,strat,-1);
8283  strat->fromQ[pos]=1;
8284  }
8285  }
8286  }
8287  }
8288  for (i=0; i<IDELEMS(F); i++)
8289  {
8290  if (F->m[i]!=NULL)
8291  {
8292  LObject h;
8293  h.p = pCopy(F->m[i]);
8294  h.sig = pOne();
8295  //h.sig = pInit();
8296  //p_SetCoeff(h.sig,nInit(1),currRing);
8297  p_SetComp(h.sig,i+1,currRing);
8298  // if we are working with the Schreyer order we generate it
8299  // by multiplying the initial signatures with the leading monomial
8300  // of the corresponding initial polynomials generating the ideal
8301  // => we can keep the underlying monomial order and get a Schreyer
8302  // order without any bigger overhead
8303  if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
8304  {
8305  p_ExpVectorAdd (h.sig,F->m[i],currRing);
8306  }
8307  h.sevSig = pGetShortExpVector(h.sig);
8308 #ifdef DEBUGF5
8309  pWrite(h.p);
8310  pWrite(h.sig);
8311 #endif
8312  if (h.p!=NULL)
8313  {
8315  {
8316  cancelunit(&h); /*- tries to cancel a unit -*/
8317  deleteHC(&h, strat);
8318  }
8319  if (h.p!=NULL)
8320  {
8322  {
8323  //pContent(h.p);
8324  h.pCleardenom(); // also does a pContent
8325  }
8326  else
8327  {
8328  h.pNorm();
8329  }
8330  strat->initEcart(&h);
8331  if (strat->Ll==-1)
8332  pos =0;
8333  else
8334  pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
8335  h.sev = pGetShortExpVector(h.p);
8336  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8337  }
8338  }
8339  /*
8340  if (strat->sbaOrder != 1)
8341  {
8342  for(j=0;j<i;j++)
8343  {
8344  strat->syz[ctr] = pCopy(F->m[j]);
8345  p_SetCompP(strat->syz[ctr],i+1,currRing);
8346  // add LM(F->m[i]) to the signature to get a Schreyer order
8347  // without changing the underlying polynomial ring at all
8348  p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
8349  // since p_Add_q() destroys all input
8350  // data we need to recreate help
8351  // each time
8352  poly help = pCopy(F->m[i]);
8353  p_SetCompP(help,j+1,currRing);
8354  pWrite(strat->syz[ctr]);
8355  pWrite(help);
8356  printf("%d\n",pLmCmp(strat->syz[ctr],help));
8357  strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
8358  printf("%d. SYZ ",ctr);
8359  pWrite(strat->syz[ctr]);
8360  strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
8361  ctr++;
8362  }
8363  strat->syzl = ps;
8364  }
8365  */
8366  }
8367  }
8368  /*- test, if a unit is in F -*/
8369 
8370  if ((strat->Ll>=0)
8371 #ifdef HAVE_RINGS
8372  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8373 #endif
8374  && pIsConstant(strat->L[strat->Ll].p))
8375  {
8376  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8377  }
8378 }
8379 
8381 {
8382  if( strat->S[0] )
8383  {
8384  if( strat->S[1] && !rField_is_Ring(currRing))
8385  {
8386  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
8387  omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
8388  omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
8389  }
8390  int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
8391  /************************************************************
8392  * computing the length of the syzygy array needed
8393  ***********************************************************/
8394  for(i=1; i<=strat->sl; i++)
8395  {
8396  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8397  {
8398  ps += i;
8399  }
8400  }
8401  ps += strat->sl+1;
8402  //comp = pGetComp (strat->P.sig);
8403  comp = strat->currIdx;
8404  strat->syzIdx = initec(comp);
8405  strat->sevSyz = initsevS(ps);
8406  strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8407  strat->syzmax = ps;
8408  strat->syzl = 0;
8409  strat->syzidxmax = comp;
8410 #if defined(DEBUGF5) || defined(DEBUGF51)
8411  PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8412 #endif
8413  i = 1;
8414  j = 0;
8415  /************************************************************
8416  * generating the leading terms of the principal syzygies
8417  ***********************************************************/
8418  while (i <= strat->sl)
8419  {
8420  /**********************************************************
8421  * principal syzygies start with component index 2
8422  * the array syzIdx starts with index 0
8423  * => the rules for a signature with component comp start
8424  * at strat->syz[strat->syzIdx[comp-2]] !
8425  *********************************************************/
8426  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8427  {
8428  comp = pGetComp(strat->sig[i]);
8429  comp_old = pGetComp(strat->sig[i-1]);
8430  diff = comp - comp_old - 1;
8431  // diff should be zero, but sometimes also the initial generating
8432  // elements of the input ideal reduce to zero. then there is an
8433  // index-gap between the signatures. for these inbetween signatures we
8434  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8435  // in the following.
8436  // doing this, we keep the relation "j = comp - 2" alive, which makes
8437  // jumps way easier when checking criteria
8438  while (diff>0)
8439  {
8440  strat->syzIdx[j] = 0;
8441  diff--;
8442  j++;
8443  }
8444  strat->syzIdx[j] = ctr;
8445  j++;
8446  LObject Q;
8447  int pos;
8448  for (k = 0; k<i; k++)
8449  {
8450  Q.sig = pOne();
8453  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8454  p_SetCompP (Q.sig, comp, currRing);
8455  poly q = p_One(currRing);
8459  q = p_Neg (q, currRing);
8461  Q.sig = p_Add_q (Q.sig, q, currRing);
8462  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8463  pos = posInSyz(strat, Q.sig);
8464  enterSyz(Q, strat, pos);
8465  ctr++;
8466  }
8467  }
8468  i++;
8469  }
8470  /**************************************************************
8471  * add syzygies for upcoming first element of new iteration step
8472  **************************************************************/
8473  comp = strat->currIdx;
8474  comp_old = pGetComp(strat->sig[i-1]);
8475  diff = comp - comp_old - 1;
8476  // diff should be zero, but sometimes also the initial generating
8477  // elements of the input ideal reduce to zero. then there is an
8478  // index-gap between the signatures. for these inbetween signatures we
8479  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8480  // in the following.
8481  // doing this, we keep the relation "j = comp - 2" alive, which makes
8482  // jumps way easier when checking criteria
8483  while (diff>0)
8484  {
8485  strat->syzIdx[j] = 0;
8486  diff--;
8487  j++;
8488  }
8489  strat->syzIdx[j] = ctr;
8490  LObject Q;
8491  int pos;
8492  for (k = 0; k<strat->sl+1; k++)
8493  {
8494  Q.sig = pOne();
8497  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8498  p_SetCompP (Q.sig, comp, currRing);
8499  poly q = p_One(currRing);
8503  q = p_Neg (q, currRing);
8505  Q.sig = p_Add_q (Q.sig, q, currRing);
8506  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8507  pos = posInSyz(strat, Q.sig);
8508  enterSyz(Q, strat, pos);
8509  ctr++;
8510  }
8511 //#if 1
8512 #ifdef DEBUGF5
8513  PrintS("Principal syzygies:\n");
8514  Print("syzl %d\n",strat->syzl);
8515  Print("syzmax %d\n",strat->syzmax);
8516  Print("ps %d\n",ps);
8517  PrintS("--------------------------------\n");
8518  for(i=0;i<=strat->syzl-1;i++)
8519  {
8520  Print("%d - ",i);
8521  pWrite(strat->syz[i]);
8522  }
8523  for(i=0;i<strat->currIdx;i++)
8524  {
8525  Print("%d - %d\n",i,strat->syzIdx[i]);
8526  }
8527  PrintS("--------------------------------\n");
8528 #endif
8529  }
8530 }
8531 
8532 /*2
8533 *construct the set s from F and {P}
8534 */
8535 void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8536 {
8537  int i,pos;
8538 
8539  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8540  else i=setmaxT;
8541  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8542  strat->ecartS=initec(i);
8543  strat->sevS=initsevS(i);
8544  strat->S_2_R=initS_2_R(i);
8545  strat->fromQ=NULL;
8546  strat->Shdl=idInit(i,F->rank);
8547  strat->S=strat->Shdl->m;
8548 
8549  /*- put polys into S -*/
8550  if (Q!=NULL)
8551  {
8552  strat->fromQ=initec(i);
8553  memset(strat->fromQ,0,i*sizeof(int));
8554  for (i=0; i<IDELEMS(Q); i++)
8555  {
8556  if (Q->m[i]!=NULL)
8557  {
8558  LObject h;
8559  h.p = pCopy(Q->m[i]);
8560  //if (TEST_OPT_INTSTRATEGY)
8561  //{
8562  // //pContent(h.p);
8563  // h.pCleardenom(); // also does a pContent
8564  //}
8565  //else
8566  //{
8567  // h.pNorm();
8568  //}
8570  {
8571  deleteHC(&h,strat);
8572  }
8573  if (h.p!=NULL)
8574  {
8575  strat->initEcart(&h);
8576  if (strat->sl==-1)
8577  pos =0;
8578  else
8579  {
8580  pos = posInS(strat,strat->sl,h.p,h.ecart);
8581  }
8582  h.sev = pGetShortExpVector(h.p);
8583  strat->enterS(h,pos,strat, strat->tl+1);
8584  enterT(h, strat);
8585  strat->fromQ[pos]=1;
8586  }
8587  }
8588  }
8589  }
8590  /*- put polys into S -*/
8591  for (i=0; i<IDELEMS(F); i++)
8592  {
8593  if (F->m[i]!=NULL)
8594  {
8595  LObject h;
8596  h.p = pCopy(F->m[i]);
8598  {
8599  deleteHC(&h,strat);
8600  }
8601  else
8602  {
8603  h.p=redtailBba(h.p,strat->sl,strat);
8604  }
8605  if (h.p!=NULL)
8606  {
8607  strat->initEcart(&h);
8608  if (strat->sl==-1)
8609  pos =0;
8610  else
8611  pos = posInS(strat,strat->sl,h.p,h.ecart);
8612  h.sev = pGetShortExpVector(h.p);
8613  strat->enterS(h,pos,strat, strat->tl+1);
8614  enterT(h,strat);
8615  }
8616  }
8617  }
8618  for (i=0; i<IDELEMS(P); i++)
8619  {
8620  if (P->m[i]!=NULL)
8621  {
8622  LObject h;
8623  h.p=pCopy(P->m[i]);
8625  {
8626  h.pCleardenom();
8627  }
8628  else
8629  {
8630  h.pNorm();
8631  }
8632  if(strat->sl>=0)
8633  {
8635  {
8636  h.p=redBba(h.p,strat->sl,strat);
8637  if (h.p!=NULL)
8638  {
8639  h.p=redtailBba(h.p,strat->sl,strat);
8640  }
8641  }
8642  else
8643  {
8644  h.p=redMora(h.p,strat->sl,strat);
8645  }
8646  if(h.p!=NULL)
8647  {
8648  strat->initEcart(&h);
8650  {
8651  h.pCleardenom();
8652  }
8653  else
8654  {
8655  h.is_normalized = 0;
8656  h.pNorm();
8657  }
8658  h.sev = pGetShortExpVector(h.p);
8659  h.SetpFDeg();
8660  pos = posInS(strat,strat->sl,h.p,h.ecart);
8661  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8662  strat->enterS(h,pos,strat, strat->tl+1);
8663  enterT(h,strat);
8664  }
8665  }
8666  else
8667  {
8668  h.sev = pGetShortExpVector(h.p);
8669  strat->initEcart(&h);
8670  strat->enterS(h,0,strat, strat->tl+1);
8671  enterT(h,strat);
8672  }
8673  }
8674  }
8675 }
8676 /*2
8677 *construct the set s from F and {P}
8678 */
8679 
8680 void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8681 {
8682  int i,pos;
8683 
8684  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8685  else i=setmaxT;
8686  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8687  strat->sevS=initsevS(i);
8688  strat->sevSig=initsevS(i);
8689  strat->S_2_R=initS_2_R(i);
8690  strat->fromQ=NULL;
8691  strat->Shdl=idInit(i,F->rank);
8692  strat->S=strat->Shdl->m;
8693  strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8694  /*- put polys into S -*/
8695  if (Q!=NULL)
8696  {
8697  strat->fromQ=initec(i);
8698  memset(strat->fromQ,0,i*sizeof(int));
8699  for (i=0; i<IDELEMS(Q); i++)
8700  {
8701  if (Q->m[i]!=NULL)
8702  {
8703  LObject h;
8704  h.p = pCopy(Q->m[i]);
8705  //if (TEST_OPT_INTSTRATEGY)
8706  //{
8707  // //pContent(h.p);
8708  // h.pCleardenom(); // also does a pContent
8709  //}
8710  //else
8711  //{
8712  // h.pNorm();
8713  //}
8715  {
8716  deleteHC(&h,strat);
8717  }
8718  if (h.p!=NULL)
8719  {
8720  strat->initEcart(&h);
8721  if (strat->sl==-1)
8722  pos =0;
8723  else
8724  {
8725  pos = posInS(strat,strat->sl,h.p,h.ecart);
8726  }
8727  h.sev = pGetShortExpVector(h.p);
8728  strat->enterS(h,pos,strat, strat->tl+1);
8729  enterT(h, strat);
8730  strat->fromQ[pos]=1;
8731  }
8732  }
8733  }
8734  }
8735  /*- put polys into S -*/
8736  for (i=0; i<IDELEMS(F); i++)
8737  {
8738  if (F->m[i]!=NULL)
8739  {
8740  LObject h;
8741  h.p = pCopy(F->m[i]);
8743  {
8744  deleteHC(&h,strat);
8745  }
8746  else
8747  {
8748  h.p=redtailBba(h.p,strat->sl,strat);
8749  }
8750  if (h.p!=NULL)
8751  {
8752  strat->initEcart(&h);
8753  if (strat->sl==-1)
8754  pos =0;
8755  else
8756  pos = posInS(strat,strat->sl,h.p,h.ecart);
8757  h.sev = pGetShortExpVector(h.p);
8758  strat->enterS(h,pos,strat, strat->tl+1);
8759  enterT(h,strat);
8760  }
8761  }
8762  }
8763  for (i=0; i<IDELEMS(P); i++)
8764  {
8765  if (P->m[i]!=NULL)
8766  {
8767  LObject h;
8768  h.p=pCopy(P->m[i]);
8770  {
8771  h.pCleardenom();
8772  }
8773  else
8774  {
8775  h.pNorm();
8776  }
8777  if(strat->sl>=0)
8778  {
8780  {
8781  h.p=redBba(h.p,strat->sl,strat);
8782  if (h.p!=NULL)
8783  {
8784  h.p=redtailBba(h.p,strat->sl,strat);
8785  }
8786  }
8787  else
8788  {
8789  h.p=redMora(h.p,strat->sl,strat);
8790  }
8791  if(h.p!=NULL)
8792  {
8793  strat->initEcart(&h);
8795  {
8796  h.pCleardenom();
8797  }
8798  else
8799  {
8800  h.is_normalized = 0;
8801  h.pNorm();
8802  }
8803  h.sev = pGetShortExpVector(h.p);
8804  h.SetpFDeg();
8805  pos = posInS(strat,strat->sl,h.p,h.ecart);
8806  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8807  strat->enterS(h,pos,strat, strat->tl+1);
8808  enterT(h,strat);
8809  }
8810  }
8811  else
8812  {
8813  h.sev = pGetShortExpVector(h.p);
8814  strat->initEcart(&h);
8815  strat->enterS(h,0,strat, strat->tl+1);
8816  enterT(h,strat);
8817  }
8818  }
8819  }
8820 }
8821 
8822 /*2
8823 * reduces h using the set S
8824 * procedure used in cancelunit1
8825 */
8826 static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8827 {
8828  int j = 0;
8829  unsigned long not_sev = ~ pGetShortExpVector(h);
8830 
8831  while (j <= maxIndex)
8832  {
8833  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8834  return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8835  else j++;
8836  }
8837  return h;
8838 }
8839 
8840 /*2
8841 *tests if p.p=monomial*unit and cancels the unit
8842 */
8843 void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8844 {
8845  int k;
8846  poly r,h,h1,q;
8847 
8848  if (!pIsVector((*p).p) && ((*p).ecart != 0))
8849  {
8850 #ifdef HAVE_RINGS
8851  // Leading coef have to be a unit: no
8852  // example 2x+4x2 should be simplified to 2x*(1+2x)
8853  // and 2 is not a unit in Z
8854  //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8855 #endif
8856  k = 0;
8857  h1 = r = pCopy((*p).p);
8858  h =pNext(r);
8859  loop
8860  {
8861  if (h==NULL)
8862  {
8863  pDelete(&r);
8864  pDelete(&(pNext((*p).p)));
8865  (*p).ecart = 0;
8866  (*p).length = 1;
8867  (*p).pLength = 1;
8868  (*suc)=0;
8869  return;
8870  }
8871  if (!pDivisibleBy(r,h))
8872  {
8873  q=redBba1(h,index ,strat);
8874  if (q != h)
8875  {
8876  k++;
8877  pDelete(&h);
8878  pNext(h1) = h = q;
8879  }
8880  else
8881  {
8882  pDelete(&r);
8883  return;
8884  }
8885  }
8886  else
8887  {
8888  h1 = h;
8889  pIter(h);
8890  }
8891  if (k > 10)
8892  {
8893  pDelete(&r);
8894  return;
8895  }
8896  }
8897  }
8898 }
8899 
8900 #if 0
8901 /*2
8902 * reduces h using the elements from Q in the set S
8903 * procedure used in updateS
8904 * must not be used for elements of Q or elements of an ideal !
8905 */
8906 static poly redQ (poly h, int j, kStrategy strat)
8907 {
8908  int start;
8909  unsigned long not_sev = ~ pGetShortExpVector(h);
8910  while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8911  start=j;
8912  while (j<=strat->sl)
8913  {
8914  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8915  {
8917  if (h==NULL) return NULL;
8918  j = start;
8919  not_sev = ~ pGetShortExpVector(h);
8920  }
8921  else j++;
8922  }
8923  return h;
8924 }
8925 #endif
8926 
8927 /*2
8928 * reduces h using the set S
8929 * procedure used in updateS
8930 */
8931 static poly redBba (poly h,int maxIndex,kStrategy strat)
8932 {
8933  int j = 0;
8934  unsigned long not_sev = ~ pGetShortExpVector(h);
8935 
8936  while (j <= maxIndex)
8937  {
8938  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8939  {
8941  if (h==NULL) return NULL;
8942  j = 0;
8943  not_sev = ~ pGetShortExpVector(h);
8944  }
8945  else j++;
8946  }
8947  return h;
8948 }
8949 
8950 /*2
8951 * reduces h using the set S
8952 *e is the ecart of h
8953 *procedure used in updateS
8954 */
8955 static poly redMora (poly h,int maxIndex,kStrategy strat)
8956 {
8957  int j=0;
8958  int e,l;
8959  unsigned long not_sev = ~ pGetShortExpVector(h);
8960 
8961  if (maxIndex >= 0)
8962  {
8963  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8964  do
8965  {
8966  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8967  && ((e >= strat->ecartS[j]) || strat->kHEdgeFound))
8968  {
8969 #ifdef KDEBUG
8970  if (TEST_OPT_DEBUG)
8971  {
8972  PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8973  }
8974 #endif
8976 #ifdef KDEBUG
8977  if(TEST_OPT_DEBUG)
8978  {
8979  PrintS(")\nto "); wrp(h); PrintLn();
8980  }
8981 #endif
8982  // pDelete(&h);
8983  if (h == NULL) return NULL;
8984  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8985  j = 0;
8986  not_sev = ~ pGetShortExpVector(h);
8987  }
8988  else j++;
8989  }
8990  while (j <= maxIndex);
8991  }
8992  return h;
8993 }
8994 
8995 /*2
8996 *updates S:
8997 *the result is a set of polynomials which are in
8998 *normalform with respect to S
8999 */
9001 {
9002  LObject h;
9003  int i, suc=0;
9004  poly redSi=NULL;
9005  BOOLEAN change,any_change;
9006 // Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
9007 // for (i=0; i<=(strat->sl); i++)
9008 // {
9009 // Print("s%d:",i);
9010 // if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
9011 // pWrite(strat->S[i]);
9012 // }
9013 // Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
9014  any_change=FALSE;
9016  {
9017  while (suc != -1)
9018  {
9019  i=suc+1;
9020  while (i<=strat->sl)
9021  {
9022  change=FALSE;
9024  any_change = FALSE;
9025  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
9026  {
9027  redSi = pHead(strat->S[i]);
9028  strat->S[i] = redBba(strat->S[i],i-1,strat);
9029  //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
9030  // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
9031  if (pCmp(redSi,strat->S[i])!=0)
9032  {
9033  change=TRUE;
9034  any_change=TRUE;
9035  #ifdef KDEBUG
9036  if (TEST_OPT_DEBUG)
9037  {
9038  PrintS("reduce:");
9039  wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
9040  }
9041  #endif
9042  if (TEST_OPT_PROT)
9043  {
9044  if (strat->S[i]==NULL)
9045  PrintS("V");
9046  else
9047  PrintS("v");
9048  mflush();
9049  }
9050  }
9051  pLmDelete(&redSi);
9052  if (strat->S[i]==NULL)
9053  {
9054  deleteInS(i,strat);
9055  i--;
9056  }
9057  else if (change)
9058  {
9060  {
9061  if (TEST_OPT_CONTENTSB)
9062  {
9063  number n;
9064  p_Cleardenom_n(strat->S[i], currRing, n);// also does a pContent
9065  if (!nIsOne(n))
9066  {
9068  denom->n=nInvers(n);
9069  denom->next=DENOMINATOR_LIST;
9070  DENOMINATOR_LIST=denom;
9071  }
9072  nDelete(&n);
9073  }
9074  else
9075  {
9076  //pContent(strat->S[i]);
9077  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does a pContent
9078  }
9079  }
9080  else
9081  {
9082  pNorm(strat->S[i]);
9083  }
9085  }
9086  }
9087  i++;
9088  }
9089  if (any_change) reorderS(&suc,strat);
9090  else break;
9091  }
9092  if (toT)
9093  {
9094  for (i=0; i<=strat->sl; i++)
9095  {
9096  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9097  {
9098  h.p = redtailBba(strat->S[i],i-1,strat);
9100  {
9101  h.pCleardenom();// also does a pContent
9102  }
9103  }
9104  else
9105  {
9106  h.p = strat->S[i];
9107  }
9108  strat->initEcart(&h);
9109  if (strat->honey)
9110  {
9111  strat->ecartS[i] = h.ecart;
9112  }
9113  if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
9114  else assume(strat->sevS[i] == pGetShortExpVector(h.p));
9115  h.sev = strat->sevS[i];
9116  /*puts the elements of S also to T*/
9117  strat->initEcart(&h);
9118  enterT(h,strat);
9119  strat->S_2_R[i] = strat->tl;
9120  }
9121  }
9122  }
9123  else
9124  {
9125  while (suc != -1)
9126  {
9127  i=suc;
9128  while (i<=strat->sl)
9129  {
9130  change=FALSE;
9131  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
9132  {
9133  redSi=pHead((strat->S)[i]);
9134  (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
9135  if ((strat->S)[i]==NULL)
9136  {
9137  deleteInS(i,strat);
9138  i--;
9139  }
9140  else if (pCmp((strat->S)[i],redSi)!=0)
9141  {
9142  any_change=TRUE;
9143  h.p = strat->S[i];
9144  strat->initEcart(&h);
9145  strat->ecartS[i] = h.ecart;
9147  {
9148  if (TEST_OPT_CONTENTSB)
9149  {
9150  number n;
9151  p_Cleardenom_n(strat->S[i], currRing, n);// also does a pContent
9152  if (!nIsOne(n))
9153  {
9155  denom->n=nInvers(n);
9156  denom->next=DENOMINATOR_LIST;
9157  DENOMINATOR_LIST=denom;
9158  }
9159  nDelete(&n);
9160  }
9161  else
9162  {
9163  //pContent(strat->S[i]);
9164  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does a pContent
9165  }
9166  }
9167  else
9168  {
9169  pNorm(strat->S[i]); // == h.p
9170  }
9171  h.sev = pGetShortExpVector(h.p);
9172  strat->sevS[i] = h.sev;
9173  }
9174  pLmDelete(&redSi);
9175  kTest(strat);
9176  }
9177  i++;
9178  }
9179 #ifdef KDEBUG
9180  kTest(strat);
9181 #endif
9182  if (any_change) reorderS(&suc,strat);
9183  else { suc=-1; break; }
9184  if (h.p!=NULL)
9185  {
9186  if (!strat->kHEdgeFound)
9187  {
9188  /*strat->kHEdgeFound =*/ HEckeTest(h.p,strat);
9189  }
9190  if (strat->kHEdgeFound)
9191  newHEdge(strat);
9192  }
9193  }
9194  for (i=0; i<=strat->sl; i++)
9195  {
9196  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9197  {
9198  strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
9199  strat->initEcart(&h);
9200  strat->ecartS[i] = h.ecart;
9201  h.sev = pGetShortExpVector(h.p);
9202  strat->sevS[i] = h.sev;
9203  }
9204  else
9205  {
9206  h.p = strat->S[i];
9207  h.ecart=strat->ecartS[i];
9208  h.sev = strat->sevS[i];
9209  h.length = h.pLength = pLength(h.p);
9210  }
9211  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9212  cancelunit1(&h,&suc,strat->sl,strat);
9213  h.SetpFDeg();
9214  /*puts the elements of S also to T*/
9215  enterT(h,strat);
9216  strat->S_2_R[i] = strat->tl;
9217  }
9218  if (suc!= -1) updateS(toT,strat);
9219  }
9220 #ifdef KDEBUG
9221  kTest(strat);
9222 #endif
9223 }
9224 
9225 /*2
9226 * -puts p to the standardbasis s at position at
9227 * -saves the result in S
9228 */
9229 void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
9230 {
9231  strat->news = TRUE;
9232  /*- puts p to the standardbasis s at position at -*/
9233  if (strat->sl == IDELEMS(strat->Shdl)-1)
9234  {
9235  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9236  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9238  *sizeof(unsigned long));
9240  IDELEMS(strat->Shdl)*sizeof(int),
9242  *sizeof(int));
9243  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9244  IDELEMS(strat->Shdl)*sizeof(int),
9246  *sizeof(int));
9247  if (strat->lenS!=NULL)
9249  IDELEMS(strat->Shdl)*sizeof(int),
9251  *sizeof(int));
9252  if (strat->lenSw!=NULL)
9254  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9256  *sizeof(wlen_type));
9257  if (strat->fromQ!=NULL)
9258  {
9260  IDELEMS(strat->Shdl)*sizeof(int),
9261  (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9262  }
9265  strat->Shdl->m=strat->S;
9266  }
9267  if (atS <= strat->sl)
9268  {
9269 #ifdef ENTER_USE_MEMMOVE
9270  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9271  (strat->sl - atS + 1)*sizeof(poly));
9272  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9273  (strat->sl - atS + 1)*sizeof(int));
9274  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9275  (strat->sl - atS + 1)*sizeof(unsigned long));
9276  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9277  (strat->sl - atS + 1)*sizeof(int));
9278  if (strat->lenS!=NULL)
9279  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9280  (strat->sl - atS + 1)*sizeof(int));
9281  if (strat->lenSw!=NULL)
9282  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9283  (strat->sl - atS + 1)*sizeof(wlen_type));
9284 #else
9285  for (i=strat->sl+1; i>=atS+1; i--)
9286  {
9287  strat->S[i] = strat->S[i-1];
9288  strat->ecartS[i] = strat->ecartS[i-1];
9289  strat->sevS[i] = strat->sevS[i-1];
9290  strat->S_2_R[i] = strat->S_2_R[i-1];
9291  }
9292  if (strat->lenS!=NULL)
9293  for (i=strat->sl+1; i>=atS+1; i--)
9294  strat->lenS[i] = strat->lenS[i-1];
9295  if (strat->lenSw!=NULL)
9296  for (i=strat->sl+1; i>=atS+1; i--)
9297  strat->lenSw[i] = strat->lenSw[i-1];
9298 #endif
9299  }
9300  if (strat->fromQ!=NULL)
9301  {
9302 #ifdef ENTER_USE_MEMMOVE
9303  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9304  (strat->sl - atS + 1)*sizeof(int));
9305 #else
9306  for (i=strat->sl+1; i>=atS+1; i--)
9307  {
9308  strat->fromQ[i] = strat->fromQ[i-1];
9309  }
9310 #endif
9311  strat->fromQ[atS]=0;
9312  }
9313 
9314  /*- save result -*/
9315  strat->S[atS] = p.p;
9316  if (strat->honey) strat->ecartS[atS] = p.ecart;
9317  if (p.sev == 0)
9318  p.sev = pGetShortExpVector(p.p);
9319  else
9320  assume(p.sev == pGetShortExpVector(p.p));
9321  strat->sevS[atS] = p.sev;
9322  strat->ecartS[atS] = p.ecart;
9323  strat->S_2_R[atS] = atR;
9324  strat->sl++;
9325 }
9326 
9327 /*2
9328 * -puts p to the standardbasis s at position at
9329 * -saves the result in S
9330 */
9331 void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
9332 {
9333  strat->news = TRUE;
9334  /*- puts p to the standardbasis s at position at -*/
9335  if (strat->sl == IDELEMS(strat->Shdl)-1)
9336  {
9337  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9338  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9339  (IDELEMS(strat->Shdl)+setmax)
9340  *sizeof(unsigned long));
9341  strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
9342  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9343  (IDELEMS(strat->Shdl)+setmax)
9344  *sizeof(unsigned long));
9346  IDELEMS(strat->Shdl)*sizeof(int),
9347  (IDELEMS(strat->Shdl)+setmax)
9348  *sizeof(int));
9349  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9350  IDELEMS(strat->Shdl)*sizeof(int),
9351  (IDELEMS(strat->Shdl)+setmax)
9352  *sizeof(int));
9353  if (strat->lenS!=NULL)
9355  IDELEMS(strat->Shdl)*sizeof(int),
9356  (IDELEMS(strat->Shdl)+setmax)
9357  *sizeof(int));
9358  if (strat->lenSw!=NULL)
9360  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9361  (IDELEMS(strat->Shdl)+setmax)
9362  *sizeof(wlen_type));
9363  if (strat->fromQ!=NULL)
9364  {
9366  IDELEMS(strat->Shdl)*sizeof(int),
9367  (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
9368  }
9371  IDELEMS(strat->Shdl)+=setmax;
9372  strat->Shdl->m=strat->S;
9373  }
9374  // in a signature-based algorithm the following situation will never
9375  // appear due to the fact that the critical pairs are already sorted
9376  // by increasing signature.
9377  // True. However, in the case of integers we need to put the element
9378  // that caused the signature drop on the first position
9379  if (atS <= strat->sl)
9380  {
9381 #ifdef ENTER_USE_MEMMOVE
9382  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9383  (strat->sl - atS + 1)*sizeof(poly));
9384  memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9385  (strat->sl - atS + 1)*sizeof(poly));
9386  memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9387  (strat->sl - atS + 1)*sizeof(unsigned long));
9388  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9389  (strat->sl - atS + 1)*sizeof(int));
9390  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9391  (strat->sl - atS + 1)*sizeof(unsigned long));
9392  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9393  (strat->sl - atS + 1)*sizeof(int));
9394  if (strat->lenS!=NULL)
9395  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9396  (strat->sl - atS + 1)*sizeof(int));
9397  if (strat->lenSw!=NULL)
9398  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9399  (strat->sl - atS + 1)*sizeof(wlen_type));
9400 #else
9401  for (i=strat->sl+1; i>=atS+1; i--)
9402  {
9403  strat->S[i] = strat->S[i-1];
9404  strat->ecartS[i] = strat->ecartS[i-1];
9405  strat->sevS[i] = strat->sevS[i-1];
9406  strat->S_2_R[i] = strat->S_2_R[i-1];
9407  strat->sig[i] = strat->sig[i-1];
9408  strat->sevSig[i] = strat->sevSig[i-1];
9409  }
9410  if (strat->lenS!=NULL)
9411  for (i=strat->sl+1; i>=atS+1; i--)
9412  strat->lenS[i] = strat->lenS[i-1];
9413  if (strat->lenSw!=NULL)
9414  for (i=strat->sl+1; i>=atS+1; i--)
9415  strat->lenSw[i] = strat->lenSw[i-1];
9416 #endif
9417  }
9418  if (strat->fromQ!=NULL)
9419  {
9420 #ifdef ENTER_USE_MEMMOVE
9421  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9422  (strat->sl - atS + 1)*sizeof(int));
9423 #else
9424  for (i=strat->sl+1; i>=atS+1; i--)
9425  {
9426  strat->fromQ[i] = strat->fromQ[i-1];
9427  }
9428 #endif
9429  strat->fromQ[atS]=0;
9430  }
9431 
9432  /*- save result -*/
9433  strat->S[atS] = p.p;
9434  strat->sig[atS] = p.sig; // TODO: get ths correct signature in here!
9435  if (strat->honey) strat->ecartS[atS] = p.ecart;
9436  if (p.sev == 0)
9437  p.sev = pGetShortExpVector(p.p);
9438  else
9439  assume(p.sev == pGetShortExpVector(p.p));
9440  strat->sevS[atS] = p.sev;
9441  // during the interreduction process of a signature-based algorithm we do not
9442  // compute the signature at this point, but when the whole interreduction
9443  // process finishes, i.e. f5c terminates!
9444  if (p.sig != NULL)
9445  {
9446  if (p.sevSig == 0)
9447  p.sevSig = pGetShortExpVector(p.sig);
9448  else
9449  assume(p.sevSig == pGetShortExpVector(p.sig));
9450  strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9451  }
9452  strat->ecartS[atS] = p.ecart;
9453  strat->S_2_R[atS] = atR;
9454  strat->sl++;
9455 #ifdef DEBUGF5
9456  int k;
9457  Print("--- LIST S: %d ---\n",strat->sl);
9458  for(k=0;k<=strat->sl;k++)
9459  {
9460  pWrite(strat->sig[k]);
9461  }
9462  PrintS("--- LIST S END ---\n");
9463 #endif
9464 }
9465 
9466 /*2
9467 * puts p to the set T at position atT
9468 */
9469 void enterT(LObject &p, kStrategy strat, int atT)
9470 {
9471  int i;
9472 
9473  pp_Test(p.p, currRing, p.tailRing);
9474  assume(strat->tailRing == p.tailRing);
9475  // redMoraNF complains about this -- but, we don't really
9476  // neeed this so far
9477  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9478  assume(p.FDeg == p.pFDeg());
9479  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9480 
9481 #ifdef KDEBUG
9482  // do not put an LObject twice into T:
9483  for(i=strat->tl;i>=0;i--)
9484  {
9485  if (p.p==strat->T[i].p)
9486  {
9487  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9488  return;
9489  }
9490  }
9491 #endif
9492 
9493 #ifdef HAVE_TAIL_RING
9494  if (currRing!=strat->tailRing)
9495  {
9496  p.t_p=p.GetLmTailRing();
9497  }
9498 #endif
9499  strat->newt = TRUE;
9500  if (atT < 0)
9501  atT = strat->posInT(strat->T, strat->tl, p);
9502  if (strat->tl == strat->tmax-1)
9504  if (atT <= strat->tl)
9505  {
9506 #ifdef ENTER_USE_MEMMOVE
9507  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9508  (strat->tl-atT+1)*sizeof(TObject));
9509  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9510  (strat->tl-atT+1)*sizeof(unsigned long));
9511 #endif
9512  for (i=strat->tl+1; i>=atT+1; i--)
9513  {
9514 #ifndef ENTER_USE_MEMMOVE
9515  strat->T[i] = strat->T[i-1];
9516  strat->sevT[i] = strat->sevT[i-1];
9517 #endif
9518  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9519  }
9520  }
9521 
9522  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9523  {
9525  (strat->tailRing != NULL ?
9526  strat->tailRing : currRing),
9527  strat->tailBin);
9528  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9529  }
9530  strat->T[atT] = (TObject) p;
9531  #ifdef ADIDEBUG
9532  printf("\nenterT: add in position %i\n",atT);
9534  #endif
9535  //printf("\nenterT: neue hingefügt: länge = %i, ecart = %i\n",p.length,p.ecart);
9536 
9537  if (pNext(p.p) != NULL)
9538  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9539  else
9540  strat->T[atT].max_exp = NULL;
9541 
9542  strat->tl++;
9543  strat->R[strat->tl] = &(strat->T[atT]);
9544  strat->T[atT].i_r = strat->tl;
9545  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9546  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9547  kTest_T(&(strat->T[atT]));
9548 }
9549 
9550 /*2
9551 * puts p to the set T at position atT
9552 */
9553 #ifdef HAVE_RINGS
9555 {
9557  int i;
9558 
9559  pp_Test(p.p, currRing, p.tailRing);
9560  assume(strat->tailRing == p.tailRing);
9561  // redMoraNF complains about this -- but, we don't really
9562  // neeed this so far
9563  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9564  assume(p.FDeg == p.pFDeg());
9565  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9566 
9567 #ifdef KDEBUG
9568  // do not put an LObject twice into T:
9569  for(i=strat->tl;i>=0;i--)
9570  {
9571  if (p.p==strat->T[i].p)
9572  {
9573  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9574  return;
9575  }
9576  }
9577 #endif
9578 
9579 #ifdef HAVE_TAIL_RING
9580  if (currRing!=strat->tailRing)
9581  {
9582  p.t_p=p.GetLmTailRing();
9583  }
9584 #endif
9585  strat->newt = TRUE;
9586  if (atT < 0)
9587  atT = strat->posInT(strat->T, strat->tl, p);
9588  if (strat->tl == strat->tmax-1)
9590  if (atT <= strat->tl)
9591  {
9592 #ifdef ENTER_USE_MEMMOVE
9593  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9594  (strat->tl-atT+1)*sizeof(TObject));
9595  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9596  (strat->tl-atT+1)*sizeof(unsigned long));
9597 #endif
9598  for (i=strat->tl+1; i>=atT+1; i--)
9599  {
9600 #ifndef ENTER_USE_MEMMOVE
9601  strat->T[i] = strat->T[i-1];
9602  strat->sevT[i] = strat->sevT[i-1];
9603 #endif
9604  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9605  }
9606  }
9607 
9608  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9609  {
9611  (strat->tailRing != NULL ?
9612  strat->tailRing : currRing),
9613  strat->tailBin);
9614  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9615  }
9616  strat->T[atT] = (TObject) p;
9617  #ifdef ADIDEBUG
9618  printf("\nenterT_strong: add in position %i\n",atT);
9619  pWrite(p.p);
9620  #endif
9621  //printf("\nenterT_strong: neue hingefügt: länge = %i, ecart = %i\n",p.length,p.ecart);
9622 
9623  if (pNext(p.p) != NULL)
9624  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9625  else
9626  strat->T[atT].max_exp = NULL;
9627 
9628  strat->tl++;
9629  strat->R[strat->tl] = &(strat->T[atT]);
9630  strat->T[atT].i_r = strat->tl;
9631  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9632  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9633  #if 1
9635  && !n_IsUnit(p.p->coef, currRing->cf))
9636  {
9637  #ifdef ADIDEBUG
9638  printf("\nDas ist p:\n");pWrite(p.p);
9639  #endif
9640  for(i=strat->tl;i>=0;i--)
9641  {
9642  if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9643  {
9644  #ifdef ADIDEBUG
9645  printf("\nFound one: %i\n",i);pWrite(strat->T[i].p);
9646  #endif
9647  enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9648  }
9649  }
9650  }
9651  /*
9652  printf("\nThis is T:\n");
9653  for(i=strat->tl;i>=0;i--)
9654  {
9655  pWrite(strat->T[i].p);
9656  }
9657  //getchar();*/
9658  #endif
9659  kTest_T(&(strat->T[atT]));
9660 }
9661 #endif
9662 
9663 /*2
9664 * puts signature p.sig to the set syz
9665 */
9667 {
9668  #ifdef ADIDEBUG
9669  printf("\n Entersyz:\n");pWrite(p.sig);
9670  #endif
9671  int i;
9672  strat->newt = TRUE;
9673  if (strat->syzl == strat->syzmax-1)
9674  {
9676  strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9677  (strat->syzmax)*sizeof(unsigned long),
9678  ((strat->syzmax)+setmax)
9679  *sizeof(unsigned long));
9680  strat->syzmax += setmax;
9681  }
9682  if (atT < strat->syzl)
9683  {
9684 #ifdef ENTER_USE_MEMMOVE
9685  memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9686  (strat->syzl-atT+1)*sizeof(poly));
9687  memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9688  (strat->syzl-atT+1)*sizeof(unsigned long));
9689 #endif
9690  for (i=strat->syzl; i>=atT+1; i--)
9691  {
9692 #ifndef ENTER_USE_MEMMOVE
9693  strat->syz[i] = strat->syz[i-1];
9694  strat->sevSyz[i] = strat->sevSyz[i-1];
9695 #endif
9696  }
9697  }
9698  //i = strat->syzl;
9699  i = atT;
9700  //Makes sure the syz saves just the signature
9701  #ifdef HAVE_RINGS
9703  pNext(p.sig) = NULL;
9704  #endif
9705  strat->syz[atT] = p.sig;
9706  strat->sevSyz[atT] = p.sevSig;
9707  strat->syzl++;
9708 #if F5DEBUG
9709  Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9710  pWrite(strat->syz[atT]);
9711 #endif
9712  // recheck pairs in strat->L with new rule and delete correspondingly
9713  int cc = strat->Ll;
9714  while (cc>-1)
9715  {
9716  //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9717  //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);
9718  if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9719  strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9720  #ifdef HAVE_RINGS
9721  &&((!rField_is_Ring(currRing))
9722  || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9723  #endif
9724  )
9725  {
9726  //printf("\nYES!\n");
9727  #ifdef ADIDEBUG
9728  printf("\n syzCrit deleted!\n");pWrite(strat->L[cc].p);pWrite(strat->L[cc].sig);
9729  #endif
9730  deleteInL(strat->L,&strat->Ll,cc,strat);
9731  }
9732  cc--;
9733  }
9734 //#if 1
9735 #ifdef DEBUGF5
9736  PrintS("--- Syzygies ---\n");
9737  Print("syzl %d\n",strat->syzl);
9738  Print("syzmax %d\n",strat->syzmax);
9739  PrintS("--------------------------------\n");
9740  for(i=0;i<=strat->syzl-1;i++)
9741  {
9742  Print("%d - ",i);
9743  pWrite(strat->syz[i]);
9744  }
9745  PrintS("--------------------------------\n");
9746 #endif
9747 }
9748 
9749 
9750 void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9751 {
9752 
9753  //if the ordering is local, then hilb criterion
9754  //can be used also if the ideal is not homogenous
9756  {
9758  *hilb=NULL;
9759  else
9760  return;
9761  }
9762  if (strat->homog!=isHomog)
9763  {
9764  *hilb=NULL;
9765  }
9766 }
9767 
9769 {
9772  if (TEST_OPT_SB_1)
9774 #ifdef HAVE_RINGS
9775  if (rField_is_Ring(currRing))
9776  {
9779  }
9780 #endif
9781 #ifdef HAVE_RATGRING
9782  if (rIsRatGRing(currRing))
9783  {
9785  /* enterOnePairNormal get rational part in it */
9786  }
9787 #endif
9788  if (TEST_OPT_IDLIFT /* i.e. also strat->syzComp==1 */
9789  && (!rIsPluralRing(currRing)))
9791 
9796  strat->pairtest = NULL;
9797  /* alway use tailreduction, except:
9798  * - in local rings, - in lex order case, -in ring over extensions */
9800  //if(rHasMixedOrdering(currRing)==2)
9801  //{
9802  // strat->noTailReduction =TRUE;
9803  //}
9804 
9805 #ifdef HAVE_PLURAL
9806  // and r is plural_ring
9807  // hence this holds for r a rational_plural_ring
9809  { //or it has non-quasi-comm type... later
9810  strat->sugarCrit = FALSE;
9811  strat->Gebauer = FALSE;
9812  strat->honey = FALSE;
9813  }
9814 #endif
9815 
9816  // Coefficient ring?
9817  if (rField_is_Ring(currRing))
9818  {
9819  strat->sugarCrit = FALSE;
9820  strat->Gebauer = FALSE ;
9821  strat->honey = FALSE;
9822  }
9823  #ifdef KDEBUG
9824  if (TEST_OPT_DEBUG)
9825  {
9826  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9827  else PrintS("ideal/module is not homogeneous\n");
9828  }
9829  #endif
9830 }
9831 
9833 {
9834  //strat->enterOnePair=enterOnePairNormal;
9836  //strat->chainCrit=chainCritNormal;
9838  /******************************************
9839  * rewCrit1 and rewCrit2 are already set in
9840  * kSba() in kstd1.cc
9841  *****************************************/
9842  //strat->rewCrit1 = faugereRewCriterion;
9843  if (strat->sbaOrder == 1)
9844  {
9846  }
9847  else
9848  {
9850  }
9851 #ifdef HAVE_RINGS
9852  if (rField_is_Ring(currRing))
9853  {
9856  }
9857 #endif
9858 #ifdef HAVE_RATGRING
9859  if (rIsRatGRing(currRing))
9860  {
9862  /* enterOnePairNormal get rational part in it */
9863  }
9864 #endif
9865 
9870  strat->pairtest = NULL;
9871  /* alway use tailreduction, except:
9872  * - in local rings, - in lex order case, -in ring over extensions */
9875 
9876 #ifdef HAVE_PLURAL
9877  // and r is plural_ring
9878  // hence this holds for r a rational_plural_ring
9880  { //or it has non-quasi-comm type... later
9881  strat->sugarCrit = FALSE;
9882  strat->Gebauer = FALSE;
9883  strat->honey = FALSE;
9884  }
9885 #endif
9886 
9887  // Coefficient ring?
9888  if (rField_is_Ring(currRing))
9889  {
9890  strat->sugarCrit = FALSE;
9891  strat->Gebauer = FALSE ;
9892  strat->honey = FALSE;
9893  }
9894  #ifdef KDEBUG
9895  if (TEST_OPT_DEBUG)
9896  {
9897  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9898  else PrintS("ideal/module is not homogeneous\n");
9899  }
9900  #endif
9901 }
9902 
9904  (const LSet set, const int length,
9905  LObject* L,const kStrategy strat))
9906 {
9907  if (pos_in_l == posInL110
9908  || pos_in_l == posInL10
9909  #ifdef HAVE_RINGS
9910  || pos_in_l == posInL110Ring
9911  || pos_in_l == posInLRing
9912  #endif
9913  )
9914  return TRUE;
9915 
9916  return FALSE;
9917 }
9918 
9920 {
9922  {
9923  if (strat->honey)
9924  {
9925  strat->posInL = posInL15;
9926  // ok -- here is the deal: from my experiments for Singular-2-0
9927  // I conclude that that posInT_EcartpLength is the best of
9928  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9929  // see the table at the end of this file
9930  if (TEST_OPT_OLDSTD)
9931  strat->posInT = posInT15;
9932  else
9934  }
9935  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9936  {
9937  strat->posInL = posInL11;
9938  strat->posInT = posInT11;
9939  }
9940  else if (TEST_OPT_INTSTRATEGY)
9941  {
9942  strat->posInL = posInL11;
9943  strat->posInT = posInT11;
9944  }
9945  else
9946  {
9947  strat->posInL = posInL0;
9948  strat->posInT = posInT0;
9949  }
9950  //if (strat->minim>0) strat->posInL =posInLSpecial;
9951  if (strat->homog)
9952  {
9953  strat->posInL = posInL110;
9954  strat->posInT = posInT110;
9955  }
9956  }
9957  else
9958  {
9959  if (strat->homog)
9960  {
9961  strat->posInL = posInL11;
9962  strat->posInT = posInT11;
9963  }
9964  else
9965  {
9966  if ((currRing->order[0]==ringorder_c)
9967  ||(currRing->order[0]==ringorder_C))
9968  {
9969  strat->posInL = posInL17_c;
9970  strat->posInT = posInT17_c;
9971  }
9972  else
9973  {
9974  strat->posInL = posInL17;
9975  strat->posInT = posInT17;
9976  }
9977  }
9978  }
9979  if (strat->minim>0) strat->posInL =posInLSpecial;
9980  // for further tests only
9981  if ((BTEST1(11)) || (BTEST1(12)))
9982  strat->posInL = posInL11;
9983  else if ((BTEST1(13)) || (BTEST1(14)))
9984  strat->posInL = posInL13;
9985  else if ((BTEST1(15)) || (BTEST1(16)))
9986  strat->posInL = posInL15;
9987  else if ((BTEST1(17)) || (BTEST1(18)))
9988  strat->posInL = posInL17;
9989  if (BTEST1(11))
9990  strat->posInT = posInT11;
9991  else if (BTEST1(13))
9992  strat->posInT = posInT13;
9993  else if (BTEST1(15))
9994  strat->posInT = posInT15;
9995  else if ((BTEST1(17)))
9996  strat->posInT = posInT17;
9997  else if ((BTEST1(19)))
9998  strat->posInT = posInT19;
9999  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10000  strat->posInT = posInT1;
10002 }
10003 
10004 #ifdef HAVE_RINGS
10006 {
10008  {
10009  if (strat->honey)
10010  {
10012  // ok -- here is the deal: from my experiments for Singular-2-0
10013  // I conclude that that posInT_EcartpLength is the best of
10014  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10015  // see the table at the end of this file
10016  if (TEST_OPT_OLDSTD)
10018  else
10020  }
10021  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10022  {
10024  strat->posInT = posInT11;
10025  }
10026  else if (TEST_OPT_INTSTRATEGY)
10027  {
10029  strat->posInT = posInT11;
10030  }
10031  else
10032  {
10034  strat->posInT = posInT0;
10035  }
10036  //if (strat->minim>0) strat->posInL =posInLSpecial;
10037  if (strat->homog)
10038  {
10041  }
10042  }
10043  else
10044  {
10045  if (strat->homog)
10046  {
10047  //printf("\nHere 3\n");
10050  }
10051  else
10052  {
10053  if ((currRing->order[0]==ringorder_c)
10054  ||(currRing->order[0]==ringorder_C))
10055  {
10058  }
10059  else
10060  {
10063  }
10064  }
10065  }
10066  if (strat->minim>0) strat->posInL =posInLSpecial;
10067  // for further tests only
10068  if ((BTEST1(11)) || (BTEST1(12)))
10070  else if ((BTEST1(13)) || (BTEST1(14)))
10071  strat->posInL = posInL13;
10072  else if ((BTEST1(15)) || (BTEST1(16)))
10074  else if ((BTEST1(17)) || (BTEST1(18)))
10076  if (BTEST1(11))
10078  else if (BTEST1(13))
10079  strat->posInT = posInT13;
10080  else if (BTEST1(15))
10082  else if ((BTEST1(17)))
10084  else if ((BTEST1(19)))
10085  strat->posInT = posInT19;
10086  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10087  strat->posInT = posInT1;
10089 }
10090 #endif
10091 
10092 void initBuchMora (ideal F,ideal Q,kStrategy strat)
10093 {
10095  strat->kHEdge=NULL;
10097  /*- creating temp data structures------------------- -*/
10098  strat->cp = 0;
10099  strat->c3 = 0;
10100  strat->tail = pInit();
10101  /*- set s -*/
10102  strat->sl = -1;
10103  /*- set L -*/
10105  strat->Ll = -1;
10106  strat->L = initL(strat->Lmax);
10107  /*- set B -*/
10108  strat->Bmax = setmaxL;
10109  strat->Bl = -1;
10110  strat->B = initL();
10111  /*- set T -*/
10112  strat->tl = -1;
10113  strat->tmax = setmaxT;
10114  strat->T = initT();
10115  strat->R = initR();
10116  strat->sevT = initsevT();
10117  /*- init local data struct.---------------------------------------- -*/
10118  strat->P.ecart=0;
10119  strat->P.length=0;
10120  strat->P.pLength=0;
10122  {
10125  }
10127  {
10128  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10129  }
10130  else
10131  {
10132  if(TEST_OPT_SB_1)
10133  {
10134  int i;
10135  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10136  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10137  {
10138  P->m[i-strat->newIdeal] = F->m[i];
10139  F->m[i] = NULL;
10140  }
10141  initSSpecial(F,Q,P,strat);
10142  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10143  {
10144  F->m[i] = P->m[i-strat->newIdeal];
10145  P->m[i-strat->newIdeal] = NULL;
10146  }
10147  idDelete(&P);
10148  }
10149  else
10150  {
10151  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10152  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
10153  }
10154  }
10155  strat->fromT = FALSE;
10157  if ((!TEST_OPT_SB_1)
10158  || (rField_is_Ring(currRing))
10159  )
10160  {
10161  updateS(TRUE,strat);
10162  }
10163  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10164  strat->fromQ=NULL;
10165  assume(kTest_TS(strat));
10166 }
10167 
10169 {
10170  /*- release temp data -*/
10171  cleanT(strat);
10172  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10173  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10174  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10175  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10176  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10177  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10178  /*- set L: should be empty -*/
10179  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10180  /*- set B: should be empty -*/
10181  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10182  pLmDelete(&strat->tail);
10183  strat->syzComp=0;
10184 }
10185 
10187 {
10189  {
10190  if (strat->honey)
10191  {
10192  strat->posInL = posInL15;
10193  // ok -- here is the deal: from my experiments for Singular-2-0
10194  // I conclude that that posInT_EcartpLength is the best of
10195  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10196  // see the table at the end of this file
10197  if (TEST_OPT_OLDSTD)
10198  strat->posInT = posInT15;
10199  else
10201  }
10202  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10203  {
10204  strat->posInL = posInL11;
10205  strat->posInT = posInT11;
10206  }
10207  else if (TEST_OPT_INTSTRATEGY)
10208  {
10209  strat->posInL = posInL11;
10210  strat->posInT = posInT11;
10211  }
10212  else
10213  {
10214  strat->posInL = posInL0;
10215  strat->posInT = posInT0;
10216  }
10217  //if (strat->minim>0) strat->posInL =posInLSpecial;
10218  if (strat->homog)
10219  {
10220  strat->posInL = posInL110;
10221  strat->posInT = posInT110;
10222  }
10223  }
10224  else
10225  {
10226  if (strat->homog)
10227  {
10228  strat->posInL = posInL11;
10229  strat->posInT = posInT11;
10230  }
10231  else
10232  {
10233  if ((currRing->order[0]==ringorder_c)
10234  ||(currRing->order[0]==ringorder_C))
10235  {
10236  strat->posInL = posInL17_c;
10237  strat->posInT = posInT17_c;
10238  }
10239  else
10240  {
10241  strat->posInL = posInL17;
10242  strat->posInT = posInT17;
10243  }
10244  }
10245  }
10246  if (strat->minim>0) strat->posInL =posInLSpecial;
10247  // for further tests only
10248  if ((BTEST1(11)) || (BTEST1(12)))
10249  strat->posInL = posInL11;
10250  else if ((BTEST1(13)) || (BTEST1(14)))
10251  strat->posInL = posInL13;
10252  else if ((BTEST1(15)) || (BTEST1(16)))
10253  strat->posInL = posInL15;
10254  else if ((BTEST1(17)) || (BTEST1(18)))
10255  strat->posInL = posInL17;
10256  if (BTEST1(11))
10257  strat->posInT = posInT11;
10258  else if (BTEST1(13))
10259  strat->posInT = posInT13;
10260  else if (BTEST1(15))
10261  strat->posInT = posInT15;
10262  else if ((BTEST1(17)))
10263  strat->posInT = posInT17;
10264  else if ((BTEST1(19)))
10265  strat->posInT = posInT19;
10266  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10267  strat->posInT = posInT1;
10268  if (rField_is_Ring(currRing))
10269  {
10271  if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
10273  strat->posInT = posInT11;
10274  }
10277  //strat->posInL = posInLSig;
10278  strat->posInL = posInLF5C;
10279  /*
10280  if (rField_is_Ring(currRing))
10281  {
10282  strat->posInLSba = posInLSigRing;
10283  strat->posInL = posInL11Ring;
10284  }*/
10285  //strat->posInT = posInTSig;
10286 }
10287 
10288 void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10289 {
10291  strat->kHEdge=NULL;
10293  /*- creating temp data structures------------------- -*/
10294  strat->cp = 0;
10295  strat->c3 = 0;
10296  strat->tail = pInit();
10297  /*- set s -*/
10298  strat->sl = -1;
10299  /*- set ps -*/
10300  strat->syzl = -1;
10301  /*- set L -*/
10303  strat->Ll = -1;
10304  strat->L = initL(strat->Lmax);
10305  /*- set B -*/
10306  strat->Bmax = setmaxL;
10307  strat->Bl = -1;
10308  strat->B = initL();
10309  /*- set T -*/
10310  strat->tl = -1;
10311  strat->tmax = setmaxT;
10312  strat->T = initT();
10313  strat->R = initR();
10314  strat->sevT = initsevT();
10315  /*- init local data struct.---------------------------------------- -*/
10316  strat->P.ecart=0;
10317  strat->P.length=0;
10319  {
10322  }
10324  {
10325  /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10326  }
10327  else
10328  {
10329  if(TEST_OPT_SB_1)
10330  {
10331  int i;
10332  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10333  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10334  {
10335  P->m[i-strat->newIdeal] = F->m[i];
10336  F->m[i] = NULL;
10337  }
10338  initSSpecialSba(F,Q,P,strat);
10339  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10340  {
10341  F->m[i] = P->m[i-strat->newIdeal];
10342  P->m[i-strat->newIdeal] = NULL;
10343  }
10344  idDelete(&P);
10345  }
10346  else
10347  {
10348  initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10349  }
10350  }
10351  strat->fromT = FALSE;
10352  if (!TEST_OPT_SB_1)
10353  {
10355  }
10356  //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10357  //strat->fromQ=NULL;
10358  assume(kTest_TS(strat));
10359 }
10360 
10362 {
10363  /*- release temp data -*/
10366  else
10367  cleanT(strat);
10368  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10369  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10370  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10371  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10372  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10373  omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10374  if(strat->syzmax>0)
10375  {
10376  omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10377  omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10378  if (strat->sbaOrder == 1)
10379  {
10380  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10381  }
10382  }
10383  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10384  /*- set L: should be empty -*/
10385  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10386  /*- set B: should be empty -*/
10387  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10388  /*- set sig: no need for the signatures anymore -*/
10389  omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10390  pLmDelete(&strat->tail);
10391  strat->syzComp=0;
10392 }
10393 
10394 /*2
10395 * in the case of a standardbase of a module over a qring:
10396 * replace polynomials in i by ak vectors,
10397 * (the polynomial * unit vectors gen(1)..gen(ak)
10398 * in every case (also for ideals:)
10399 * deletes divisible vectors/polynomials
10400 */
10401 void updateResult(ideal r,ideal Q, kStrategy strat)
10402 {
10403  int l;
10404  if (strat->ak>0)
10405  {
10406  for (l=IDELEMS(r)-1;l>=0;l--)
10407  {
10408  if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10409  {
10410  pDelete(&r->m[l]); // and set it to NULL
10411  }
10412  }
10413  int q;
10414  poly p;
10415  if(!rField_is_Ring(currRing))
10416  {
10417  for (l=IDELEMS(r)-1;l>=0;l--)
10418  {
10419  if ((r->m[l]!=NULL)
10420  //&& (strat->syzComp>0)
10421  //&& (pGetComp(r->m[l])<=strat->syzComp)
10422  )
10423  {
10424  for(q=IDELEMS(Q)-1; q>=0;q--)
10425  {
10426  if ((Q->m[q]!=NULL)
10427  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10428  {
10429  if (TEST_OPT_REDSB)
10430  {
10431  p=r->m[l];
10432  r->m[l]=kNF(Q,NULL,p);
10433  pDelete(&p);
10434  }
10435  else
10436  {
10437  pDelete(&r->m[l]); // and set it to NULL
10438  }
10439  break;
10440  }
10441  }
10442  }
10443  }
10444  }
10445  #ifdef HAVE_RINGS
10446  else
10447  {
10448  for (l=IDELEMS(r)-1;l>=0;l--)
10449  {
10450  if ((r->m[l]!=NULL)
10451  //&& (strat->syzComp>0)
10452  //&& (pGetComp(r->m[l])<=strat->syzComp)
10453  )
10454  {
10455  for(q=IDELEMS(Q)-1; q>=0;q--)
10456  {
10457  if ((Q->m[q]!=NULL)
10458  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10459  {
10460  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10461  {
10462  if (TEST_OPT_REDSB)
10463  {
10464  p=r->m[l];
10465  r->m[l]=kNF(Q,NULL,p);
10466  pDelete(&p);
10467  }
10468  else
10469  {
10470  pDelete(&r->m[l]); // and set it to NULL
10471  }
10472  break;
10473  }
10474  }
10475  }
10476  }
10477  }
10478  }
10479  #endif
10480  }
10481  else
10482  {
10483  int q;
10484  poly p;
10485  BOOLEAN reduction_found=FALSE;
10486  if (!rField_is_Ring(currRing))
10487  {
10488  for (l=IDELEMS(r)-1;l>=0;l--)
10489  {
10490  if (r->m[l]!=NULL)
10491  {
10492  for(q=IDELEMS(Q)-1; q>=0;q--)
10493  {
10494  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10495  {
10496  if (TEST_OPT_REDSB)
10497  {
10498  p=r->m[l];
10499  r->m[l]=kNF(Q,NULL,p);
10500  pDelete(&p);
10501  reduction_found=TRUE;
10502  }
10503  else
10504  {
10505  pDelete(&r->m[l]); // and set it to NULL
10506  }
10507  break;
10508  }
10509  }
10510  }
10511  }
10512  }
10513  #ifdef HAVE_RINGS
10514  //Also need divisibility of the leading coefficients
10515  else
10516  {
10517  for (l=IDELEMS(r)-1;l>=0;l--)
10518  {
10519  if (r->m[l]!=NULL)
10520  {
10521  for(q=IDELEMS(Q)-1; q>=0;q--)
10522  {
10523  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10524  {
10525  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10526  {
10527  if (TEST_OPT_REDSB)
10528  {
10529  p=r->m[l];
10530  r->m[l]=kNF(Q,NULL,p);
10531  pDelete(&p);
10532  reduction_found=TRUE;
10533  }
10534  else
10535  {
10536  pDelete(&r->m[l]); // and set it to NULL
10537  }
10538  break;
10539  }
10540  }
10541  }
10542  }
10543  }
10544  }
10545  #endif
10546  if (/*TEST_OPT_REDSB &&*/ reduction_found)
10547  {
10548  #ifdef HAVE_RINGS
10550  {
10551  for (l=IDELEMS(r)-1;l>=0;l--)
10552  {
10553  if (r->m[l]!=NULL)
10554  {
10555  for(q=IDELEMS(r)-1;q>=0;q--)
10556  {
10557  if ((l!=q)
10558  && (r->m[q]!=NULL)
10559  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10560  &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10561  )
10562  {
10563  //If they are equal then take the one with the smallest length
10564  if(pLmDivisibleBy(r->m[q],r->m[l])
10565  && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10566  && (pLength(r->m[q]) < pLength(r->m[l]) ||
10567  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10568  {
10569  pDelete(&r->m[l]);
10570  break;
10571  }
10572  else
10573  pDelete(&r->m[q]);
10574  }
10575  }
10576  }
10577  }
10578  }
10579  else
10580  #endif
10581  {
10582  for (l=IDELEMS(r)-1;l>=0;l--)
10583  {
10584  if (r->m[l]!=NULL)
10585  {
10586  for(q=IDELEMS(r)-1;q>=0;q--)
10587  {
10588  if ((l!=q)
10589  && (r->m[q]!=NULL)
10590  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10591  )
10592  {
10593  //If they are equal then take the one with the smallest length
10594  if(pLmDivisibleBy(r->m[q],r->m[l])
10595  &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10596  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10597  {
10598  pDelete(&r->m[l]);
10599  break;
10600  }
10601  else
10602  pDelete(&r->m[q]);
10603  }
10604  }
10605  }
10606  }
10607  }
10608  }
10609  }
10610  idSkipZeroes(r);
10611 }
10612 
10614 {
10615  int i;
10616  int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10617  LObject L;
10618 
10619 #ifdef KDEBUG
10620  // need to set this: during tailreductions of T[i], T[i].max is out of
10621  // sync
10622  sloppy_max = TRUE;
10623 #endif
10624 
10626  //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10627  if (TEST_OPT_PROT)
10628  {
10629  PrintLn();
10630 // if (timerv) writeTime("standard base computed:");
10631  }
10632  if (TEST_OPT_PROT)
10633  {
10634  Print("(S:%d)",strat->sl);mflush();
10635  }
10636  for (i=strat->sl; i>=low; i--)
10637  {
10638  int end_pos=strat->sl;
10639  if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10640  if (strat->ak==0) end_pos=i-1;
10641  TObject* T_j = strat->s_2_t(i);
10642  if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10643  {
10644  L = *T_j;
10645  #ifdef KDEBUG
10646  if (TEST_OPT_DEBUG)
10647  {
10648  Print("test S[%d]:",i);
10649  p_wrp(L.p,currRing,strat->tailRing);
10650  PrintLn();
10651  }
10652  #endif
10654  strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10655  else
10656  strat->S[i] = redtail(&L, strat->sl, strat);
10657  #ifdef KDEBUG
10658  if (TEST_OPT_DEBUG)
10659  {
10660  Print("to (tailR) S[%d]:",i);
10662  PrintLn();
10663  }
10664  #endif
10665 
10666  if (strat->redTailChange)
10667  {
10668  if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10669  if (pNext(T_j->p) != NULL)
10670  T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10671  else
10672  T_j->max_exp = NULL;
10673  }
10675  T_j->pCleardenom();
10676  }
10677  else
10678  {
10680  #ifdef KDEBUG
10681  if (TEST_OPT_DEBUG)
10682  {
10683  Print("test S[%d]:",i);
10685  PrintLn();
10686  }
10687  #endif
10689  strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10690  else
10691  strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10693  {
10694  if (TEST_OPT_CONTENTSB)
10695  {
10696  number n;
10697  p_Cleardenom_n(strat->S[i], currRing, n);// also does a pContent
10698  if (!nIsOne(n))
10699  {
10701  denom->n=nInvers(n);
10702  denom->next=DENOMINATOR_LIST;
10703  DENOMINATOR_LIST=denom;
10704  }
10705  nDelete(&n);
10706  }
10707  else
10708  {
10709  //pContent(strat->S[i]);
10710  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does a pContent
10711  }
10712  }
10713  #ifdef KDEBUG
10714  if (TEST_OPT_DEBUG)
10715  {
10716  Print("to (-tailR) S[%d]:",i);
10718  PrintLn();
10719  }
10720  #endif
10721  }
10722  if (TEST_OPT_PROT)
10723  PrintS("-");
10724  }
10725  if (TEST_OPT_PROT) PrintLn();
10726 #ifdef KDEBUG
10727  sloppy_max = FALSE;
10728 #endif
10729 }
10730 
10731 
10732 /*2
10733 * computes the new strat->kHEdge and the new pNoether,
10734 * returns TRUE, if pNoether has changed
10735 */
10737 {
10738  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10739  return FALSE;
10740  int i,j;
10741  poly newNoether;
10742 
10743 #if 0
10744  if (currRing->weight_all_1)
10746  else
10747  scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
10748 #else
10750 #endif
10751  if (strat->kHEdge==NULL) return FALSE;
10753  if (strat->tailRing != currRing)
10755  /* compare old and new noether*/
10756  newNoether = pLmInit(strat->kHEdge);
10757  j = p_FDeg(newNoether,currRing);
10758  for (i=1; i<=(currRing->N); i++)
10759  {
10760  if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
10761  }
10762  pSetm(newNoether);
10763  if (j < strat->HCord) /*- statistics -*/
10764  {
10765  if (TEST_OPT_PROT)
10766  {
10767  Print("H(%d)",j);
10768  mflush();
10769  }
10770  strat->HCord=j;
10771  #ifdef KDEBUG
10772  if (TEST_OPT_DEBUG)
10773  {
10774  Print("H(%d):",j);
10775  wrp(strat->kHEdge);
10776  PrintLn();
10777  }
10778  #endif
10779  }
10780  if (pCmp(strat->kNoether,newNoether)!=1)
10781  {
10782  pDelete(&strat->kNoether);
10783  strat->kNoether=newNoether;
10785  if (strat->tailRing != currRing)
10787 
10788  return TRUE;
10789  }
10790  if (rField_is_Ring(currRing))
10791  pLmDelete(newNoether);
10792  else
10793  pLmFree(newNoether);
10794  return FALSE;
10795 }
10796 
10797 /***************************************************************
10798  *
10799  * Routines related for ring changes during std computations
10800  *
10801  ***************************************************************/
10803 {
10804  if (strat->overflow) return FALSE;
10805  assume(L->p1 != NULL && L->p2 != NULL);
10806  // shift changes: from 0 to -1
10807  assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10808  assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10810 
10811  if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10812  return FALSE;
10813  // shift changes: extra case inserted
10814  if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10815  {
10816  return TRUE;
10817  }
10818  poly p1_max = (strat->R[L->i_r1])->max_exp;
10819  poly p2_max = (strat->R[L->i_r2])->max_exp;
10820 
10821  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10822  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10823  {
10824  p_LmFree(m1, strat->tailRing);
10825  p_LmFree(m2, strat->tailRing);
10826  m1 = NULL;
10827  m2 = NULL;
10828  return FALSE;
10829  }
10830  return TRUE;
10831 }
10832 
10833 #ifdef HAVE_RINGS
10834 /***************************************************************
10835  *
10836  * Checks, if we can compute the gcd poly / strong pair
10837  * gcd-poly = m1 * R[atR] + m2 * S[atS]
10838  *
10839  ***************************************************************/
10841 {
10842  assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10843  //assume(strat->tailRing != currRing);
10844 
10845  poly p1_max = (strat->R[atR])->max_exp;
10846  poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10847 
10848  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10849  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10850  {
10851  return FALSE;
10852  }
10853  return TRUE;
10854 }
10855 #endif
10856 
10857 #ifdef HAVE_RINGS
10858 /*!
10859  used for GB over ZZ: look for constant and monomial elements in the ideal
10860  background: any known constant element of ideal suppresses
10861  intermediate coefficient swell
10862 */
10863 poly preIntegerCheck(const ideal Forig, const ideal Q)
10864 {
10866  if(!nCoeff_is_Ring_Z(currRing->cf))
10867  return NULL;
10868  ideal F = idCopy(Forig);
10869  idSkipZeroes(F);
10870  poly pmon;
10871  ring origR = currRing;
10872  ideal monred = idInit(1,1);
10873  for(int i=0; i<idElem(F); i++)
10874  {
10875  if(pNext(F->m[i]) == NULL)
10876  idInsertPoly(monred, pCopy(F->m[i]));
10877  }
10878  int posconst = idPosConstant(F);
10879  if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10880  {
10881  idDelete(&F);
10882  idDelete(&monred);
10883  return NULL;
10884  }
10885  int idelemQ = 0;
10886  if(Q!=NULL)
10887  {
10888  idelemQ = IDELEMS(Q);
10889  for(int i=0; i<idelemQ; i++)
10890  {
10891  if(pNext(Q->m[i]) == NULL)
10892  idInsertPoly(monred, pCopy(Q->m[i]));
10893  }
10894  idSkipZeroes(monred);
10895  posconst = idPosConstant(monred);
10896  //the constant, if found, will be from Q
10897  if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10898  {
10899  pmon = pCopy(monred->m[posconst]);
10900  idDelete(&F);
10901  idDelete(&monred);
10902  return pmon;
10903  }
10904  }
10905  ring QQ_ring = rCopy0(currRing,FALSE);
10906  nKillChar(QQ_ring->cf);
10907  QQ_ring->cf = nInitChar(n_Q, NULL);
10908  rComplete(QQ_ring,1);
10909  QQ_ring = rAssure_c_dp(QQ_ring);
10910  rChangeCurrRing(QQ_ring);
10911  nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10912  ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10913  for(int i = 0, j = 0; i<IDELEMS(F); i++)
10914  II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10915  for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10916  II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10917  ideal one = kStd(II, NULL, isNotHomog, NULL);
10918  idSkipZeroes(one);
10919  if(idIsConstant(one))
10920  {
10921  //one should be <1>
10922  for(int i = IDELEMS(II)-1; i>=0; i--)
10923  if(II->m[i] != NULL)
10924  II->m[i+1] = II->m[i];
10925  II->m[0] = pOne();
10926  ideal syz = idSyzygies(II, isNotHomog, NULL);
10927  poly integer = NULL;
10928  for(int i = IDELEMS(syz)-1;i>=0; i--)
10929  {
10930  if(pGetComp(syz->m[i]) == 1)
10931  {
10932  pSetComp(syz->m[i],0);
10933  if(pIsConstant(pHead(syz->m[i])))
10934  {
10935  integer = pHead(syz->m[i]);
10936  break;
10937  }
10938  }
10939  }
10940  rChangeCurrRing(origR);
10941  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10942  pmon = prMapR(integer, nMap2, QQ_ring, origR);
10943  idDelete(&monred);
10944  idDelete(&F);
10945  id_Delete(&II,QQ_ring);
10946  id_Delete(&one,QQ_ring);
10947  id_Delete(&syz,QQ_ring);
10948  p_Delete(&integer,QQ_ring);
10949  rDelete(QQ_ring);
10950  return pmon;
10951  }
10952  else
10953  {
10954  if(idIs0(monred))
10955  {
10956  poly mindegmon = NULL;
10957  for(int i = 0; i<IDELEMS(one); i++)
10958  {
10959  if(pNext(one->m[i]) == NULL)
10960  {
10961  if(mindegmon == NULL)
10962  mindegmon = pCopy(one->m[i]);
10963  else
10964  {
10965  if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10966  mindegmon = pCopy(one->m[i]);
10967  }
10968  }
10969  }
10970  if(mindegmon != NULL)
10971  {
10972  for(int i = IDELEMS(II)-1; i>=0; i--)
10973  if(II->m[i] != NULL)
10974  II->m[i+1] = II->m[i];
10975  II->m[0] = pCopy(mindegmon);
10976  ideal syz = idSyzygies(II, isNotHomog, NULL);
10977  bool found = FALSE;
10978  for(int i = IDELEMS(syz)-1;i>=0; i--)
10979  {
10980  if(pGetComp(syz->m[i]) == 1)
10981  {
10982  pSetComp(syz->m[i],0);
10983  if(pIsConstant(pHead(syz->m[i])))
10984  {
10985  pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10986  found = TRUE;
10987  break;
10988  }
10989  }
10990  }
10991  id_Delete(&syz,QQ_ring);
10992  if (found == FALSE)
10993  {
10994  rChangeCurrRing(origR);
10995  idDelete(&monred);
10996  idDelete(&F);
10997  id_Delete(&II,QQ_ring);
10998  id_Delete(&one,QQ_ring);
10999  rDelete(QQ_ring);
11000  return NULL;
11001  }
11002  rChangeCurrRing(origR);
11003  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
11004  pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
11005  idDelete(&monred);
11006  idDelete(&F);
11007  id_Delete(&II,QQ_ring);
11008  id_Delete(&one,QQ_ring);
11009  id_Delete(&syz,QQ_ring);
11010  rDelete(QQ_ring);
11011  return pmon;
11012  }
11013  }
11014  }
11015  rChangeCurrRing(origR);
11016  idDelete(&monred);
11017  idDelete(&F);
11018  id_Delete(&II,QQ_ring);
11019  id_Delete(&one,QQ_ring);
11020  rDelete(QQ_ring);
11021  return NULL;
11022 }
11023 #endif
11024 
11025 #ifdef HAVE_RINGS
11026 /*!
11027  used for GB over ZZ: intermediate reduction by monomial elements
11028  background: any known constant element of ideal suppresses
11029  intermediate coefficient swell
11030 */
11032 {
11033  if(!nCoeff_is_Ring_Z(currRing->cf))
11034  return;
11035  poly pH = h->GetP();
11036  poly p,pp;
11037  p = pH;
11038  bool deleted = FALSE, ok = FALSE;
11039  for(int i = 0; i<=strat->sl; i++)
11040  {
11041  p = pH;
11042  if(pNext(strat->S[i]) == NULL)
11043  {
11044  //pWrite(p);
11045  //pWrite(strat->S[i]);
11046  while(ok == FALSE && p != NULL)
11047  {
11048  if(pLmDivisibleBy(strat->S[i], p))
11049  {
11050  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11051  p_SetCoeff(p,dummy,currRing);
11052  }
11053  if(nIsZero(p->coef))
11054  {
11055  pLmDelete(&p);
11056  h->p = p;
11057  deleted = TRUE;
11058  }
11059  else
11060  {
11061  ok = TRUE;
11062  }
11063  }
11064  if (p!=NULL)
11065  {
11066  pp = pNext(p);
11067  while(pp != NULL)
11068  {
11069  if(pLmDivisibleBy(strat->S[i], pp))
11070  {
11071  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11072  p_SetCoeff(pp,dummy,currRing);
11073  if(nIsZero(pp->coef))
11074  {
11075  pLmDelete(&pNext(p));
11076  pp = pNext(p);
11077  deleted = TRUE;
11078  }
11079  else
11080  {
11081  p = pp;
11082  pp = pNext(p);
11083  }
11084  }
11085  else
11086  {
11087  p = pp;
11088  pp = pNext(p);
11089  }
11090  }
11091  }
11092  }
11093  }
11094  h->SetLmCurrRing();
11095  if((deleted)&&(h->p!=NULL))
11096  strat->initEcart(h);
11097 }
11098 
11100 {
11101  if(!nCoeff_is_Ring_Z(currRing->cf))
11102  return;
11103  poly hSig = h->sig;
11104  poly pH = h->GetP();
11105  poly p,pp;
11106  p = pH;
11107  bool deleted = FALSE, ok = FALSE;
11108  for(int i = 0; i<=strat->sl; i++)
11109  {
11110  p = pH;
11111  if(pNext(strat->S[i]) == NULL)
11112  {
11113  while(ok == FALSE && p!=NULL)
11114  {
11115  if(pLmDivisibleBy(strat->S[i], p))
11116  {
11117  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11118  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11119  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11120  {
11121  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11122  p_SetCoeff(p,dummy,currRing);
11123  }
11124  pDelete(&sigMult);
11125  }
11126  if(nIsZero(p->coef))
11127  {
11128  pLmDelete(&p);
11129  h->p = p;
11130  deleted = TRUE;
11131  }
11132  else
11133  {
11134  ok = TRUE;
11135  }
11136  }
11137  if(p == NULL)
11138  return;
11139  pp = pNext(p);
11140  while(pp != NULL)
11141  {
11142  if(pLmDivisibleBy(strat->S[i], pp))
11143  {
11144  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11145  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11146  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11147  {
11148  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11149  p_SetCoeff(pp,dummy,currRing);
11150  if(nIsZero(pp->coef))
11151  {
11152  pLmDelete(&pNext(p));
11153  pp = pNext(p);
11154  deleted = TRUE;
11155  }
11156  else
11157  {
11158  p = pp;
11159  pp = pNext(p);
11160  }
11161  }
11162  else
11163  {
11164  p = pp;
11165  pp = pNext(p);
11166  }
11167  pDelete(&sigMult);
11168  }
11169  else
11170  {
11171  p = pp;
11172  pp = pNext(p);
11173  }
11174  }
11175  }
11176  }
11177  h->SetLmCurrRing();
11178  if(deleted)
11179  strat->initEcart(h);
11180 
11181 }
11182 
11183 /*!
11184  used for GB over ZZ: final reduction by constant elements
11185  background: any known constant element of ideal suppresses
11186  intermediate coefficient swell and beautifies output
11187 */
11189 {
11190  if(!nCoeff_is_Ring_Z(currRing->cf))
11191  return;
11192  poly p,pp;
11193  for(int j = 0; j<=strat->sl; j++)
11194  {
11195  if((strat->S[j]!=NULL)&&(pNext(strat->S[j]) == NULL))
11196  {
11197  for(int i = 0; i<=strat->sl; i++)
11198  {
11199  if((i != j) && (strat->S[i] != NULL))
11200  {
11201  p = strat->S[i];
11202  if(pLmDivisibleBy(strat->S[j], p))
11203  {
11204  number dummy = n_IntMod(p->coef, strat->S[j]->coef, currRing->cf);
11205  p_SetCoeff(p,dummy,currRing);
11206  }
11207  pp = pNext(p);
11208  if((pp == NULL) && (nIsZero(p->coef)))
11209  {
11210  deleteInS(i, strat);
11211  }
11212  else
11213  {
11214  while(pp != NULL)
11215  {
11216  if(pLmDivisibleBy(strat->S[j], pp))
11217  {
11218  number dummy = n_IntMod(pp->coef, strat->S[j]->coef, currRing->cf);
11219  p_SetCoeff(pp,dummy,currRing);
11220  if(nIsZero(pp->coef))
11221  {
11222  pLmDelete(&pNext(p));
11223  pp = pNext(p);
11224  }
11225  else
11226  {
11227  p = pp;
11228  pp = pNext(p);
11229  }
11230  }
11231  else
11232  {
11233  p = pp;
11234  pp = pNext(p);
11235  }
11236  }
11237  }
11238  if(strat->S[i]!= NULL && nIsZero(pGetCoeff(strat->S[i])))
11239  {
11240  if(pNext(strat->S[i]) == NULL)
11241  strat->S[i]=NULL;
11242  else
11243  strat->S[i]=pNext(strat->S[i]);
11244  }
11245  }
11246  }
11247  //idPrint(strat->Shdl);
11248  }
11249  }
11250  //idSkipZeroes(strat->Shdl);
11251 }
11252 #endif
11253 
11255 {
11256  assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11257  /* initial setup or extending */
11258 
11259  if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11260  if (expbound >= currRing->bitmask) return FALSE;
11261  strat->overflow=FALSE;
11262  ring new_tailRing = rModifyRing(currRing,
11263  // Hmmm .. the condition pFDeg == p_Deg
11264  // might be too strong
11265  (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11266  (strat->ak==0), // omit_comp if the input is an ideal
11267  expbound); // exp_limit
11268 
11269  if (new_tailRing == currRing) return TRUE;
11270 
11271  strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11272  strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11273 
11274  if (currRing->pFDeg != currRing->pFDegOrig)
11275  {
11276  new_tailRing->pFDeg = currRing->pFDeg;
11277  new_tailRing->pLDeg = currRing->pLDeg;
11278  }
11279 
11280  if (TEST_OPT_PROT)
11281  Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11282  kTest_TS(strat);
11283  assume(new_tailRing != strat->tailRing);
11284  pShallowCopyDeleteProc p_shallow_copy_delete
11285  = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11286 
11287  omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11288 
11289  int i;
11290  for (i=0; i<=strat->tl; i++)
11291  {
11292  strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11293  p_shallow_copy_delete);
11294  }
11295  for (i=0; i<=strat->Ll; i++)
11296  {
11297  assume(strat->L[i].p != NULL);
11298  if (pNext(strat->L[i].p) != strat->tail)
11299  strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11300  }
11301  if ((strat->P.t_p != NULL) ||
11302  ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11303  strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11304 
11305  if ((L != NULL) && (L->tailRing != new_tailRing))
11306  {
11307  if (L->i_r < 0)
11308  L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11309  else
11310  {
11311  assume(L->i_r <= strat->tl);
11312  TObject* t_l = strat->R[L->i_r];
11313  assume(t_l != NULL);
11314  L->tailRing = new_tailRing;
11315  L->p = t_l->p;
11316  L->t_p = t_l->t_p;
11317  L->max_exp = t_l->max_exp;
11318  }
11319  }
11320 
11321  if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11322  T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11323 
11325  if (strat->tailRing != currRing)
11327 
11328  strat->tailRing = new_tailRing;
11329  strat->tailBin = new_tailBin;
11331  = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11332 
11333  if (strat->kHEdge != NULL)
11334  {
11335  if (strat->t_kHEdge != NULL)
11338  }
11339 
11340  if (strat->kNoether != NULL)
11341  {
11342  if (strat->t_kNoether != NULL)
11345  new_tailRing);
11346  }
11347  kTest_TS(strat);
11348  if (TEST_OPT_PROT)
11349  PrintS("]");
11350  return TRUE;
11351 }
11352 
11354 {
11355  unsigned long l = 0;
11356  int i;
11357  long e;
11358 
11360 
11361  for (i=0; i<= strat->Ll; i++)
11362  {
11363  l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11364  }
11365  for (i=0; i<=strat->tl; i++)
11366  {
11367  // Hmm ... this we could do in one Step
11368  l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11369  }
11370  if (rField_is_Ring(currRing))
11371  {
11372  l *= 2;
11373  }
11374  e = p_GetMaxExp(l, currRing);
11375  if (e <= 1) e = 2;
11376 
11378 }
11379 
11380 ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11381 {
11382  int n = rBlocks(r); // Including trailing zero!
11383  // if sbaOrder == 1 => use (C,monomial order from r)
11384  if (strat->sbaOrder == 1)
11385  {
11386  if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11387  {
11388  return r;
11389  }
11390  ring res = rCopy0(r, TRUE, FALSE);
11391  res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11392  res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11393  res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11394  int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11395  res->wvhdl = wvhdl;
11396  for (int i=1; i<n; i++)
11397  {
11398  res->order[i] = r->order[i-1];
11399  res->block0[i] = r->block0[i-1];
11400  res->block1[i] = r->block1[i-1];
11401  res->wvhdl[i] = r->wvhdl[i-1];
11402  }
11403 
11404  // new 1st block
11405  res->order[0] = ringorder_C; // Prefix
11406  // removes useless secondary component order if defined in old ring
11407  for (int i=rBlocks(res); i>0; --i)
11408  {
11409  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11410  {
11411  res->order[i] = (rRingOrder_t)0;
11412  }
11413  }
11414  rComplete(res, 1);
11415 #ifdef HAVE_PLURAL
11416  if (rIsPluralRing(r))
11417  {
11418  if ( nc_rComplete(r, res, false) ) // no qideal!
11419  {
11420 #ifndef SING_NDEBUG
11421  WarnS("error in nc_rComplete");
11422 #endif
11423  // cleanup?
11424 
11425  // rDelete(res);
11426  // return r;
11427 
11428  // just go on..
11429  }
11430  }
11431 #endif
11432  strat->tailRing = res;
11433  return (res);
11434  }
11435  // if sbaOrder == 3 => degree - position - ring order
11436  if (strat->sbaOrder == 3)
11437  {
11438  ring res = rCopy0(r, TRUE, FALSE);
11439  res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11440  res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11441  res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11442  int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11443  res->wvhdl = wvhdl;
11444  for (int i=2; i<n+2; i++)
11445  {
11446  res->order[i] = r->order[i-2];
11447  res->block0[i] = r->block0[i-2];
11448  res->block1[i] = r->block1[i-2];
11449  res->wvhdl[i] = r->wvhdl[i-2];
11450  }
11451 
11452  // new 1st block
11453  res->order[0] = ringorder_a; // Prefix
11454  res->block0[0] = 1;
11455  res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11456  for (int i=0; i<res->N; ++i)
11457  res->wvhdl[0][i] = 1;
11458  res->block1[0] = si_min(res->N, rVar(res));
11459  // new 2nd block
11460  res->order[1] = ringorder_C; // Prefix
11461  res->wvhdl[1] = NULL;
11462  // removes useless secondary component order if defined in old ring
11463  for (int i=rBlocks(res); i>1; --i)
11464  {
11465  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11466  {
11467  res->order[i] = (rRingOrder_t)0;
11468  }
11469  }
11470  rComplete(res, 1);
11471 #ifdef HAVE_PLURAL
11472  if (rIsPluralRing(r))
11473  {
11474  if ( nc_rComplete(r, res, false) ) // no qideal!
11475  {
11476 #ifndef SING_NDEBUG
11477  WarnS("error in nc_rComplete");
11478 #endif
11479  // cleanup?
11480 
11481  // rDelete(res);
11482  // return r;
11483 
11484  // just go on..
11485  }
11486  }
11487 #endif
11488  strat->tailRing = res;
11489  return (res);
11490  }
11491 
11492  // not sbaOrder == 1 => use Schreyer order
11493  // this is done by a trick when initializing the signatures
11494  // in initSLSba():
11495  // Instead of using the signature 1e_i for F->m[i], we start
11496  // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11497  // Schreyer order w.r.t. the underlying monomial order.
11498  // => we do not need to change the underlying polynomial ring at all!
11499 
11500  // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11501 
11502  /*
11503  else
11504  {
11505  ring res = rCopy0(r, FALSE, FALSE);
11506  // Create 2 more blocks for prefix/suffix:
11507  res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11508  res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11509  res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11510  int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11511 
11512  // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11513  // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11514 
11515  // new 1st block
11516  int j = 0;
11517  res->order[j] = ringorder_IS; // Prefix
11518  res->block0[j] = res->block1[j] = 0;
11519  // wvhdl[j] = NULL;
11520  j++;
11521 
11522  for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11523  {
11524  res->order [j] = r->order [i];
11525  res->block0[j] = r->block0[i];
11526  res->block1[j] = r->block1[i];
11527 
11528  if (r->wvhdl[i] != NULL)
11529  {
11530  wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11531  } // else wvhdl[j] = NULL;
11532  }
11533 
11534  // new last block
11535  res->order [j] = ringorder_IS; // Suffix
11536  res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11537  // wvhdl[j] = NULL;
11538  j++;
11539 
11540  // res->order [j] = 0; // The End!
11541  res->wvhdl = wvhdl;
11542 
11543  // j == the last zero block now!
11544  assume(j == (n+1));
11545  assume(res->order[0]==ringorder_IS);
11546  assume(res->order[j-1]==ringorder_IS);
11547  assume(res->order[j]==0);
11548 
11549  if (complete)
11550  {
11551  rComplete(res, 1);
11552 
11553 #ifdef HAVE_PLURAL
11554  if (rIsPluralRing(r))
11555  {
11556  if ( nc_rComplete(r, res, false) ) // no qideal!
11557  {
11558  }
11559  }
11560  assume(rIsPluralRing(r) == rIsPluralRing(res));
11561 #endif
11562 
11563 
11564 #ifdef HAVE_PLURAL
11565  ring old_ring = r;
11566 
11567 #endif
11568 
11569  if (r->qideal!=NULL)
11570  {
11571  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11572 
11573  assume(idRankFreeModule(res->qideal, res) == 0);
11574 
11575 #ifdef HAVE_PLURAL
11576  if( rIsPluralRing(res) )
11577  if( nc_SetupQuotient(res, r, true) )
11578  {
11579  // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11580  }
11581 
11582 #endif
11583  assume(idRankFreeModule(res->qideal, res) == 0);
11584  }
11585 
11586 #ifdef HAVE_PLURAL
11587  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11588  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11589  assume(rIsSCA(res) == rIsSCA(old_ring));
11590  assume(ncRingType(res) == ncRingType(old_ring));
11591 #endif
11592  }
11593  strat->tailRing = res;
11594  return res;
11595  }
11596  */
11597 
11598  assume(FALSE);
11599  return(NULL);
11600 }
11601 
11603 {
11604  memset(this, 0, sizeof(skStrategy));
11605  strat_nr++;
11606  nr=strat_nr;
11607  tailRing = currRing;
11608  P.tailRing = currRing;
11609  tl = -1;
11610  sl = -1;
11611 #ifdef HAVE_LM_BIN
11612  lmBin = omGetStickyBinOfBin(currRing->PolyBin);
11613 #endif
11614 #ifdef HAVE_TAIL_BIN
11615  tailBin = omGetStickyBinOfBin(currRing->PolyBin);
11616 #endif
11617  pOrigFDeg = currRing->pFDeg;
11618  pOrigLDeg = currRing->pLDeg;
11619 }
11620 
11621 
11623 {
11624  if (lmBin != NULL)
11626  if (tailBin != NULL)// && !rField_is_Ring(currRing))
11628  (tailRing != NULL ? tailRing->PolyBin:
11629  currRing->PolyBin));
11630  if (t_kHEdge != NULL)
11632  if (t_kNoether != NULL)
11634 
11635  if (currRing != tailRing)
11638 }
11639 
11640 #if 0
11641 Timings for the different possibilities of posInT:
11642  T15 EDL DL EL L 1-2-3
11643 Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11644 Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11645 Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11646 ahml 4.48 4.03 4.03 4.38 4.96 26.50
11647 c7 15.02 13.98 15.16 13.24 17.31 47.89
11648 c8 505.09 407.46 852.76 413.21 499.19 n/a
11649 f855 12.65 9.27 14.97 8.78 14.23 33.12
11650 gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11651 gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11652 ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11653 noon8 40.68 37.02 37.99 36.82 35.59 877.16
11654 rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11655 rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11656 schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11657 test016 16.39 14.17 14.40 13.50 14.26 34.07
11658 test017 34.70 36.01 33.16 35.48 32.75 71.45
11659 test042 10.76 10.99 10.27 11.57 10.45 23.04
11660 test058 6.78 6.75 6.51 6.95 6.22 9.47
11661 test066 10.71 10.94 10.76 10.61 10.56 19.06
11662 test073 10.75 11.11 10.17 10.79 8.63 58.10
11663 test086 12.23 11.81 12.88 12.24 13.37 66.68
11664 test103 5.05 4.80 5.47 4.64 4.89 11.90
11665 test154 12.96 11.64 13.51 12.46 14.61 36.35
11666 test162 65.27 64.01 67.35 59.79 67.54 196.46
11667 test164 7.50 6.50 7.68 6.70 7.96 17.13
11668 virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11669 #endif
11670 
11671 
11672 //#ifdef HAVE_MORE_POS_IN_T
11673 #if 1
11674 // determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11675 int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p)
11676 {
11677 
11678  if (length==-1) return 0;
11679 
11680  int o = p.ecart;
11681  int op=p.GetpFDeg();
11682  int ol = p.GetpLength();
11683 
11684  if (set[length].ecart < o)
11685  return length+1;
11686  if (set[length].ecart == o)
11687  {
11688  int oo=set[length].GetpFDeg();
11689  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11690  return length+1;
11691  }
11692 
11693  int i;
11694  int an = 0;
11695  int en= length;
11696  loop
11697  {
11698  if (an >= en-1)
11699  {
11700  if (set[an].ecart > o)
11701  return an;
11702  if (set[an].ecart == o)
11703  {
11704  int oo=set[an].GetpFDeg();
11705  if((oo > op)
11706  || ((oo==op) && (set[an].pLength > ol)))
11707  return an;
11708  }
11709  return en;
11710  }
11711  i=(an+en) / 2;
11712  if (set[i].ecart > o)
11713  en=i;
11714  else if (set[i].ecart == o)
11715  {
11716  int oo=set[i].GetpFDeg();
11717  if ((oo > op)
11718  || ((oo == op) && (set[i].pLength > ol)))
11719  en=i;
11720  else
11721  an=i;
11722  }
11723  else
11724  an=i;
11725  }
11726 }
11727 
11728 // determines the position based on: 1.) FDeg 2.) pLength
11729 int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11730 {
11731 
11732  if (length==-1) return 0;
11733 
11734  int op=p.GetpFDeg();
11735  int ol = p.GetpLength();
11736 
11737  int oo=set[length].GetpFDeg();
11738  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11739  return length+1;
11740 
11741  int i;
11742  int an = 0;
11743  int en= length;
11744  loop
11745  {
11746  if (an >= en-1)
11747  {
11748  int oo=set[an].GetpFDeg();
11749  if((oo > op)
11750  || ((oo==op) && (set[an].pLength > ol)))
11751  return an;
11752  return en;
11753  }
11754  i=(an+en) / 2;
11755  int oo=set[i].GetpFDeg();
11756  if ((oo > op)
11757  || ((oo == op) && (set[i].pLength > ol)))
11758  en=i;
11759  else
11760  an=i;
11761  }
11762 }
11763 
11764 
11765 // determines the position based on: 1.) pLength
11766 int posInT_pLength(const TSet set,const int length,LObject &p)
11767 {
11768  int ol = p.GetpLength();
11769  if (length==-1)
11770  return 0;
11771  if (set[length].length<p.length)
11772  return length+1;
11773 
11774  int i;
11775  int an = 0;
11776  int en= length;
11777 
11778  loop
11779  {
11780  if (an >= en-1)
11781  {
11782  if (set[an].pLength>ol) return an;
11783  return en;
11784  }
11785  i=(an+en) / 2;
11786  if (set[i].pLength>ol) en=i;
11787  else an=i;
11788  }
11789 }
11790 #endif
11791 
11792 // kstd1.cc:
11795 void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11796 void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11797 // ../Singular/misc.cc:
11798 extern char * showOption();
11799 
11801 {
11802  PrintS("red: ");
11803  if (strat->red==redFirst) PrintS("redFirst\n");
11804  else if (strat->red==redHoney) PrintS("redHoney\n");
11805  else if (strat->red==redEcart) PrintS("redEcart\n");
11806  else if (strat->red==redHomog) PrintS("redHomog\n");
11807  else Print("%p\n",(void*)strat->red);
11808  PrintS("posInT: ");
11809  if (strat->posInT==posInT0) PrintS("posInT0\n");
11810  else if (strat->posInT==posInT1) PrintS("posInT1\n");
11811  else if (strat->posInT==posInT11) PrintS("posInT11\n");
11812  else if (strat->posInT==posInT110) PrintS("posInT110\n");
11813  else if (strat->posInT==posInT13) PrintS("posInT13\n");
11814  else if (strat->posInT==posInT15) PrintS("posInT15\n");
11815  else if (strat->posInT==posInT17) PrintS("posInT17\n");
11816  else if (strat->posInT==posInT17_c) PrintS("posInT17_c\n");
11817  else if (strat->posInT==posInT19) PrintS("posInT19\n");
11818  else if (strat->posInT==posInT2) PrintS("posInT2\n");
11819  #ifdef HAVE_RINGS
11820  else if (strat->posInT==posInT11Ring) PrintS("posInT11Ring\n");
11821  else if (strat->posInT==posInT110Ring) PrintS("posInT110Ring\n");
11822  else if (strat->posInT==posInT15Ring) PrintS("posInT15Ring\n");
11823  else if (strat->posInT==posInT17Ring) PrintS("posInT17Ring\n");
11824  else if (strat->posInT==posInT17_cRing) PrintS("posInT17_cRing\n");
11825  #endif
11826 #ifdef HAVE_MORE_POS_IN_T
11827  else if (strat->posInT==posInT_EcartFDegpLength) PrintS("posInT_EcartFDegpLength\n");
11828  else if (strat->posInT==posInT_FDegpLength) PrintS("posInT_FDegpLength\n");
11829  else if (strat->posInT==posInT_pLength) PrintS("posInT_pLength\n");
11830 #endif
11831  else if (strat->posInT==posInT_EcartpLength) PrintS("posInT_EcartpLength\n");
11832  else if (strat->posInT==posInTrg0) PrintS("posInTrg0\n");
11833  else Print("%p\n",(void*)strat->posInT);
11834  PrintS("posInL: ");
11835  if (strat->posInL==posInL0) PrintS("posInL0\n");
11836  else if (strat->posInL==posInL10) PrintS("posInL10\n");
11837  else if (strat->posInL==posInL11) PrintS("posInL11\n");
11838  else if (strat->posInL==posInL110) PrintS("posInL110\n");
11839  else if (strat->posInL==posInL13) PrintS("posInL13\n");
11840  else if (strat->posInL==posInL15) PrintS("posInL15\n");
11841  else if (strat->posInL==posInL17) PrintS("posInL17\n");
11842  else if (strat->posInL==posInL17_c) PrintS("posInL17_c\n");
11843  #ifdef HAVE_RINGS
11844  else if (strat->posInL==posInL0) PrintS("posInL0Ring\n");
11845  else if (strat->posInL==posInL11Ring) PrintS("posInL11Ring\n");
11846  else if (strat->posInL==posInL11Ringls) PrintS("posInL11Ringls\n");
11847  else if (strat->posInL==posInL110Ring) PrintS("posInL110Ring\n");
11848  else if (strat->posInL==posInL15Ring) PrintS("posInL15Ring\n");
11849  else if (strat->posInL==posInL17Ring) PrintS("posInL17Ring\n");
11850  else if (strat->posInL==posInL17_cRing) PrintS("posInL17_cRing\n");
11851  #endif
11852  else if (strat->posInL==posInLSpecial) PrintS("posInLSpecial\n");
11853  else if (strat->posInL==posInLrg0) PrintS("posInLrg0\n");
11854  else Print("%p\n",(void*)strat->posInL);
11855  PrintS("enterS: ");
11856  if (strat->enterS==enterSBba) PrintS("enterSBba\n");
11857  else if (strat->enterS==enterSMora) PrintS("enterSMora\n");
11858  else if (strat->enterS==enterSMoraNF) PrintS("enterSMoraNF\n");
11859  else Print("%p\n",(void*)strat->enterS);
11860  PrintS("initEcart: ");
11861  if (strat->initEcart==initEcartBBA) PrintS("initEcartBBA\n");
11862  else if (strat->initEcart==initEcartNormal) PrintS("initEcartNormal\n");
11863  else Print("%p\n",(void*)strat->initEcart);
11864  PrintS("initEcartPair: ");
11865  if (strat->initEcartPair==initEcartPairBba) PrintS("initEcartPairBba\n");
11866  else if (strat->initEcartPair==initEcartPairMora) PrintS("initEcartPairMora\n");
11867  else Print("%p\n",(void*)strat->initEcartPair);
11868  Print("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11870  Print("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11872  PrintS("chainCrit: ");
11873  if (strat->chainCrit==chainCritNormal) PrintS("chainCritNormal\n");
11874  else if (strat->chainCrit==chainCritOpt_1) PrintS("chainCritOpt_1\n");
11875  else Print("%p\n",(void*)strat->chainCrit);
11876  Print("posInLDependsOnLength=%d\n",
11878  PrintS(showOption());PrintLn();
11879  PrintS("LDeg: ");
11880  if (currRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11881  else if (currRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11882  else if (currRing->pLDeg==pLDegb) PrintS("pLDegb");
11883  else if (currRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11884  else if (currRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11885  else if (currRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11886  else if (currRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11887  else if (currRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11888  else if (currRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11889  else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11890  else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11891  else if (currRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11892  else Print("? (%lx)", (long)currRing->pLDeg);
11893  PrintS(" / ");
11894  if (strat->tailRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11895  else if (strat->tailRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11896  else if (strat->tailRing->pLDeg==pLDegb) PrintS("pLDegb");
11897  else if (strat->tailRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11898  else if (strat->tailRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11899  else if (strat->tailRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11900  else if (strat->tailRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11901  else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11902  else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11903  else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11904  else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11905  else if (strat->tailRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11906  else Print("? (%lx)", (long)strat->tailRing->pLDeg);
11907  PrintLn();
11908  PrintS("currRing->pFDeg: ");
11909  if (currRing->pFDeg==p_Totaldegree) PrintS("p_Totaldegree");
11910  else if (currRing->pFDeg==p_WFirstTotalDegree) PrintS("pWFirstTotalDegree");
11911  else if (currRing->pFDeg==p_Deg) PrintS("p_Deg");
11912  else if (currRing->pFDeg==kHomModDeg) PrintS("kHomModDeg");
11913  else if (currRing->pFDeg==totaldegreeWecart) PrintS("totaldegreeWecart");
11914  else if (currRing->pFDeg==p_WTotaldegree) PrintS("p_WTotaldegree");
11915  else Print("? (%lx)", (long)currRing->pFDeg);
11916  PrintLn();
11917  Print(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11918  if(TEST_OPT_DEGBOUND)
11919  Print(" degBound: %d\n", Kstd1_deg);
11920 
11921  if( ecartWeights != NULL )
11922  {
11923  PrintS("ecartWeights: ");
11924  for (int i = rVar(currRing); i > 0; i--)
11925  Print("%hd ", ecartWeights[i]);
11926  PrintLn();
11928  }
11929 
11930 #ifndef SING_NDEBUG
11932 #endif
11933 }
11934 
11935 #ifdef HAVE_SHIFTBBA
11937 {
11938  /* assume: p is completely in currRing */
11939  /* produces an object with LM in curring
11940  and TAIL in tailring */
11941  if (pNext(p)!=NULL)
11942  {
11943  pNext(p) = prMoveR(pNext(p), /* src */ currRing, /* dest */ strat->tailRing);
11944  }
11945  return(p);
11946 }
11947 #endif
11948 
11949 #ifdef HAVE_SHIFTBBA
11951 {
11952  /* assume: p has LM in curring and TAIL in tailring */
11953  /* convert it to complete currRing */
11954 
11955  /* check that LM is in currRing */
11957 
11958  if (pNext(p)!=NULL)
11959  {
11960  pNext(p) = prMoveR(pNext(p), /* src */ strat->tailRing, /* dest */currRing);
11961  }
11962  return(p);
11963 }
11964 #endif
11965 
11966 #ifdef HAVE_SHIFTBBA
11968 {
11969  /* restores a poly in currRing from LObject */
11970  LObject h = H;
11971  h.Copy();
11972  poly p;
11973  if (h.p == NULL)
11974  {
11975  if (h.t_p != NULL)
11976  {
11977  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing, /* dest. ring: */ currRing);
11978  return(p);
11979  }
11980  else
11981  {
11982  /* h.tp == NULL -> the object is NULL */
11983  return(NULL);
11984  }
11985  }
11986  /* we're here if h.p != NULL */
11987  if (h.t_p == NULL)
11988  {
11989  /* then h.p is the whole poly in currRing */
11990  p = h.p;
11991  return(p);
11992  }
11993  /* we're here if h.p != NULL and h.t_p != NULL */
11994  // clean h.p, get poly from t_p
11995  pNext(h.p)=NULL;
11996  pLmDelete(&h.p);
11997  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing,
11998  /* dest. ring: */ currRing);
11999  // no need to clean h: we re-used the polys
12000  return(p);
12001 }
12002 #endif
12003 
12004 //LObject pCopyp2L(poly p, kStrategy strat)
12005 //{
12006  /* creates LObject from the poly in currRing */
12007  /* actually put p into L.p and make L.t_p=NULL : does not work */
12008 
12009 //}
12010 
12011 // poly pCopyL2p(LObject H, kStrategy strat)
12012 // {
12013 // /* restores a poly in currRing from LObject */
12014 // LObject h = H;
12015 // h.Copy();
12016 // poly p;
12017 // if (h.p == NULL)
12018 // {
12019 // if (h.t_p != NULL)
12020 // {
12021 // p = p_ShallowCopyDelete(h.t_p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12022 // return(p);
12023 // }
12024 // else
12025 // {
12026 // /* h.tp == NULL -> the object is NULL */
12027 // return(NULL);
12028 // }
12029 // }
12030 // /* we're here if h.p != NULL */
12031 
12032 // if (h.t_p == NULL)
12033 // {
12034 // /* then h.p is the whole poly in tailRing */
12035 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12036 // {
12037 // p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12038 // }
12039 // return(p);
12040 // }
12041 // /* we're here if h.p != NULL and h.t_p != NULL */
12042 // p = pCopy(pHead(h.p)); // in currRing
12043 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12044 // {
12045 // // pNext(p) = p_ShallowCopyDelete(pNext(h.t_p), (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12046 // poly pp = p_Copy(pNext(h.p), strat->tailRing);
12047 // // poly p3 = p_Copy(pNext(h.p), currRing); // error
12048 // // p_ShallowCopyDelete(pNext(h.p), currRing, strat->tailBin); // the same as pp
12049 // poly p5 = p_ShallowCopyDelete(pNext(h.p), strat->tailRing, strat->tailBin);
12050 // pNext(p) = p_ShallowCopyDelete(h.t_p, strat->tailRing, strat->tailBin);
12051 // poly p4 = p_Copy(h.t_p, strat->tailRing);
12052 // // if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
12053 // }
12054 // // pTest(p);
12055 // return(p);
12056 // }
12057 
12058 #ifdef HAVE_SHIFTBBA
12059 /* including the self pairs */
12060 void updateSShift(kStrategy strat,int uptodeg,int lV)
12061 {
12062  /* to use after updateS(toT=FALSE,strat) */
12063  /* fills T with shifted elt's of S */
12064  int i;
12065  LObject h;
12066  int atT = -1; // or figure out smth better
12067  strat->tl = -1; // init
12068  for (i=0; i<=strat->sl; i++)
12069  {
12070  memset(&h,0,sizeof(h));
12071  h.p = strat->S[i]; // lm in currRing, tail in TR
12072  strat->initEcart(&h);
12073  h.sev = strat->sevS[i];
12074  h.t_p = NULL;
12075  h.GetTP(); // creates correct t_p
12076  /*puts the elements of S with their shifts to T*/
12077  // int atT, int uptodeg, int lV)
12078  strat->S_2_R[i] = strat->tl + 1; // the el't with shift 0 will be inserted first
12079  // need a small check for above; we insert >=1 elements
12080  // insert this check into kTest_TS ?
12081  enterTShift(h,strat,atT,uptodeg,lV);
12082  }
12083  /* what about setting strat->tl? */
12084 }
12085 #endif
12086 
12087 #ifdef HAVE_SHIFTBBA
12088 void initBuchMoraShift (ideal F,ideal Q,kStrategy strat)
12089 {
12091  strat->kHEdge=NULL;
12093  /*- creating temp data structures------------------- -*/
12094  strat->cp = 0;
12095  strat->c3 = 0;
12096  strat->cv = 0;
12097  strat->tail = pInit();
12098  /*- set s -*/
12099  strat->sl = -1;
12100  /*- set L -*/
12101  strat->Lmax = setmaxL;
12102  strat->Ll = -1;
12103  strat->L = initL();
12104  /*- set B -*/
12105  strat->Bmax = setmaxL;
12106  strat->Bl = -1;
12107  strat->B = initL();
12108  /*- set T -*/
12109  strat->tl = -1;
12110  strat->tmax = setmaxT;
12111  strat->T = initT();
12112  strat->R = initR();
12113  strat->sevT = initsevT();
12114  /*- init local data struct.---------------------------------------- -*/
12115  strat->P.ecart=0;
12116  strat->P.length=0;
12118  {
12121  }
12123  {
12124  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
12125  }
12126  {
12127  if(TEST_OPT_SB_1)
12128  {
12129  int i;
12130  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
12131  for (i=strat->newIdeal;i<IDELEMS(F);i++)
12132  {
12133  P->m[i-strat->newIdeal] = F->m[i];
12134  F->m[i] = NULL;
12135  }
12136  initSSpecial(F,Q,P,strat);
12137  for (i=strat->newIdeal;i<IDELEMS(F);i++)
12138  {
12139  F->m[i] = P->m[i-strat->newIdeal];
12140  P->m[i-strat->newIdeal] = NULL;
12141  }
12142  idDelete(&P);
12143  }
12144  else
12145  {
12146  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
12147  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
12148  }
12149  }
12150  strat->fromT = FALSE;
12151  if (!TEST_OPT_SB_1)
12152  {
12153  /* the only change: we do not fill the set T*/
12155  }
12156  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
12157  strat->fromQ=NULL;
12158  /* more changes: fill the set T with all the shifts of elts of S*/
12159  /* is done by other procedure */
12160 }
12161 #endif
12162 
12163 #ifdef HAVE_SHIFTBBA
12164 /*1
12165 * put the pairs (sh \dot s[i],p) into the set B, ecart=ecart(p)
12166 */
12167 static void enterOnePairManyShifts (int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
12168 {
12169  /* p comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12170 
12173 
12174  /* cycles through all shifts of s[i] until uptodeg - lastVblock(s[i]) */
12175  /* that is create the pairs (f, s \dot g) */
12176 
12177  poly qq = strat->S[i]; // lm in currRing, tail in tailRing
12178 
12179  // poly q = pCopy(pHead(strat->S[i])); // lm in currRing
12180  // pNext(q) = prCopyR(pNext(strat->S[i]),strat->tailRing,currRing); // zero shift
12181 
12182  /* determine how many elements we have to insert for a given s[i] */
12183  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12184  /* hence, a total number of elt's to add is: */
12185  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12186  int toInsert = itoInsert(qq, uptodeg, lV, strat->tailRing);
12187 
12188 #ifdef KDEBUG
12189  if (TEST_OPT_DEBUG)
12190  {
12191  // Print("entered ManyShifts: with toInsert=%d",toInsert); PrintLn();
12192  }
12193 #endif
12194 
12195  assume(i<=strat->sl); // from OnePair
12196 
12197  /* these vars hold for all shifts of s[i] */
12198  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12199 
12200  int qfromQ;
12201  if (strat->fromQ != NULL)
12202  {
12203  qfromQ = strat->fromQ[i];
12204  }
12205  else
12206  {
12207  qfromQ = -1;
12208  }
12209 
12210  int j;
12211 
12212  poly q/*, s*/;
12213 
12214  // for the 0th shift: insert the orig. pair
12215  enterOnePairShift(qq, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, 0, i, uptodeg, lV);
12216 
12217  for (j=1; j<= toInsert; j++)
12218  {
12219  // q = pLPshift(strat->S[i],j,uptodeg,lV);
12220  q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing);
12221  // q = p_mLPshift(qq,j,uptodeg,lV,currRing); // lm in currRing, shift this monomial
12222  // s = p_LPshift(pNext(qq), j, uptodeg, lV, strat->tailRing); // from tailRing
12223  // pNext(q) = s; // in tailRing
12224  /* here we need to call enterOnePair with two polys ... */
12225 
12226 #ifdef KDEBUG
12227  //if (TEST_OPT_DEBUG)
12228  //{
12229  // PrintS("ManyShifts: calling enterOnePairShift(q,p)"); PrintLn();
12230  //}
12231 #endif
12232  //kFindInTShift(q,atR,strat);
12233  enterOnePairShift(q, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, j, i, uptodeg, lV);
12234  }
12235 }
12236 #endif
12237 
12238 #ifdef HAVE_SHIFTBBA
12239 /*1
12240 * put the pairs (sh \dot qq,p) into the set B, ecart=ecart(p)
12241 * despite the name, not only self shifts
12242 */
12243 void enterOnePairSelfShifts (poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int /*atR*/, int uptodeg, int lV)
12244 {
12245 
12246  /* format: p,qq are in LObject form: lm in CR, tail in TR */
12247  /* for true self pairs qq ==p */
12248  /* we test both qq and p */
12253 
12254  /* since this proc is applied twice for (h, s*g) and (g,s*h), init j with 1 only */
12255 
12256  // int j = 0;
12257  int j = 1;
12258 
12259  /* for such self pairs start with 1, not with 0 */
12260  if (qq == p) j=1;
12261 
12262  /* should cycle through all shifts of q until uptodeg - lastVblock(q) */
12263  /* that is create the pairs (f, s \dot g) */
12264 
12265  int toInsert = itoInsert(qq, uptodeg, lV, strat->tailRing);
12266 
12267 #ifdef KDEBUG
12268  //if (TEST_OPT_DEBUG)
12269  //{
12270  // Print("entered SelfShifts: with toInsert=%d",toInsert); PrintLn();
12271  //}
12272 #endif
12273 
12274  poly q;
12275 
12276  /* these vars hold for all shifts of s[i] */
12277  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12278  int qfromQ = 0; // strat->fromQ[i];
12279 
12280  for (; j<= toInsert; j++)
12281  {
12282  // q = pLPshift(strat->S[i],j,uptodeg,lV);
12283  /* we increase shifts by one; must delete q there*/
12284  // q = qq; q = pMoveCurrTail2poly(q,strat);
12285  // q = pLPshift(q,j,uptodeg,lV); //,currRing);
12286  q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing);
12287  // q = p_mLPshift(qq,j,uptodeg,lV,currRing); // lm in currRing, shift this monomial
12288  // s = p_LPshift(pNext(qq), j, uptodeg, lV, strat->tailRing); // from tailRing
12289  // pNext(q) = s; // in tailRing
12290  /* here we need to call enterOnePair with two polys ... */
12291 #ifdef KDEBUG
12292  //if (TEST_OPT_DEBUG)
12293  //{
12294  // PrintS("SelfShifts: calling enterOnePairShift(q,p)"); PrintLn();
12295  //}
12296 #endif
12297  enterOnePairShift(q, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, j, -1, uptodeg, lV);
12298  }
12299 }
12300 #endif
12301 
12302 #ifdef HAVE_SHIFTBBA
12303 /*2
12304 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12305 */
12306 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)
12307 {
12308 
12309  /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12310 
12311  /* check this Formats: */
12316 
12317 #ifdef KDEBUG
12318 // if (TEST_OPT_DEBUG)
12319 // {
12320 // PrintS("enterOnePairShift(q,p) invoked with q = ");
12321 // wrp(q); // wrp(pHead(q));
12322 // PrintS(", p = ");
12323 // wrp(p); //wrp(pHead(p));
12324 // PrintLn();
12325 // }
12326 #endif
12327 
12328  /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12329 
12330  int qfromQ = qisFromQ;
12331 
12332  /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12333 
12334  int l,j,compare;
12335  LObject Lp;
12336  Lp.i_r = -1;
12337 
12338 #ifdef KDEBUG
12339  Lp.ecart=0; Lp.length=0;
12340 #endif
12341  /*- computes the lcm(s[i],p) -*/
12342  Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12343 
12344  /* apply the V criterion */
12345  if (!isInV(Lp.lcm, lV))
12346  {
12347 #ifdef KDEBUG
12348  if (TEST_OPT_DEBUG)
12349  {
12350  PrintS("V crit applied to q = ");
12351  wrp(q); // wrp(pHead(q));
12352  PrintS(", p = ");
12353  wrp(p); //wrp(pHead(p));
12354  PrintLn();
12355  }
12356 #endif
12357  pLmFree(Lp.lcm);
12358  /* + counter for applying the V criterion */
12359  strat->cv++;
12360  return;
12361  }
12362 
12364  {
12365  if((!((ecartq>0)&&(ecart>0)))
12366  && pHasNotCF(p,q))
12367  {
12368  /*
12369  *the product criterion has applied for (s,p),
12370  *i.e. lcm(s,p)=product of the leading terms of s and p.
12371  *Suppose (s,r) is in L and the leading term
12372  *of p divides lcm(s,r)
12373  *(==> the leading term of p divides the leading term of r)
12374  *but the leading term of s does not divide the leading term of r
12375  *(notice that this condition is automatically satisfied if r is still
12376  *in S), then (s,r) can be cancelled.
12377  *This should be done here because the
12378  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12379  *
12380  *Moreover, skipping (s,r) holds also for the noncommutative case.
12381  */
12382  strat->cp++;
12383  pLmFree(Lp.lcm);
12384  return;
12385  }
12386  else
12387  Lp.ecart = si_max(ecart,ecartq);
12388  if (strat->fromT && (ecartq>ecart))
12389  {
12390  pLmFree(Lp.lcm);
12391  return;
12392  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12393  }
12394  /*
12395  *the set B collects the pairs of type (S[j],p)
12396  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12397  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12398  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12399  */
12400  {
12401  j = strat->Bl;
12402  loop
12403  {
12404  if (j < 0) break;
12405  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12406  if ((compare==1)
12407  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12408  {
12409  strat->c3++;
12410  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12411  {
12412  pLmFree(Lp.lcm);
12413  return;
12414  }
12415  break;
12416  }
12417  else
12418  if ((compare ==-1)
12419  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12420  {
12421  deleteInL(strat->B,&strat->Bl,j,strat);
12422  strat->c3++;
12423  }
12424  j--;
12425  }
12426  }
12427  }
12428  else /*sugarcrit*/
12429  {
12430  if (ALLOW_PROD_CRIT(strat))
12431  {
12432  // if currRing->nc_type!=quasi (or skew)
12433  // TODO: enable productCrit for super commutative algebras...
12434  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12435  pHasNotCF(p,q))
12436  {
12437  /*
12438  *the product criterion has applied for (s,p),
12439  *i.e. lcm(s,p)=product of the leading terms of s and p.
12440  *Suppose (s,r) is in L and the leading term
12441  *of p devides lcm(s,r)
12442  *(==> the leading term of p devides the leading term of r)
12443  *but the leading term of s does not devide the leading term of r
12444  *(notice that tis condition is automatically satisfied if r is still
12445  *in S), then (s,r) can be canceled.
12446  *This should be done here because the
12447  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12448  */
12449  strat->cp++;
12450  pLmFree(Lp.lcm);
12451  return;
12452  }
12453  if (strat->fromT && (ecartq>ecart))
12454  {
12455  pLmFree(Lp.lcm);
12456  return;
12457  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12458  }
12459  /*
12460  *the set B collects the pairs of type (S[j],p)
12461  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12462  *if the leading term of s devides lcm(r,p) then (r,p) will be canceled
12463  *if the leading term of r devides lcm(s,p) then (s,p) will not enter B
12464  */
12465  for(j = strat->Bl;j>=0;j--)
12466  {
12467  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
12468  if (compare==1)
12469  {
12470  strat->c3++;
12471  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12472  {
12473  pLmFree(Lp.lcm);
12474  return;
12475  }
12476  break;
12477  }
12478  else
12479  if (compare ==-1)
12480  {
12481  deleteInL(strat->B,&strat->Bl,j,strat);
12482  strat->c3++;
12483  }
12484  }
12485  }
12486  }
12487  /*
12488  *the pair (S[i],p) enters B if the spoly != 0
12489  */
12490  /*- compute the short s-polynomial -*/
12491  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12492  pNorm(p);
12493  if ((q==NULL) || (p==NULL))
12494  return;
12495  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12496  Lp.p=NULL;
12497  else
12498  {
12499 // if ( rIsPluralRing(currRing) )
12500 // {
12501 // if(pHasNotCF(p, q))
12502 // {
12503 // if(ncRingType(currRing) == nc_lie)
12504 // {
12505 // // generalized prod-crit for lie-type
12506 // strat->cp++;
12507 // Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12508 // }
12509 // else
12510 // if( ALLOW_PROD_CRIT(strat) )
12511 // {
12512 // // product criterion for homogeneous case in SCA
12513 // strat->cp++;
12514 // Lp.p = NULL;
12515 // }
12516 // else
12517 // Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12518 // }
12519 // else Lp.p = nc_CreateSpoly(q,p,currRing);
12520 // }
12521 // else
12522 // {
12523 
12524  /* ksCreateShortSpoly needs two Lobject-kind presentations */
12525  /* p is already in this form, so convert q */
12526  // q = pMove2CurrTail(q, strat);
12527  Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12528  // }
12529  }
12530  if (Lp.p == NULL)
12531  {
12532  /*- the case that the s-poly is 0 -*/
12533  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12534 // if (strat->pairtest==NULL) initPairtest(strat);
12535 // strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12536 // strat->pairtest[strat->sl+1] = TRUE;
12537  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12538  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12539  /*
12540  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12541  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12542  *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12543  *term of p devides the lcm(s,r)
12544  *(this canceling should be done here because
12545  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12546  *the first case is handeled in chainCrit
12547  */
12548  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12549  }
12550  else
12551  {
12552  /*- the pair (S[i],p) enters B -*/
12553  /* both of them should have their LM in currRing and TAIL in tailring */
12554  Lp.p1 = q; // already in the needed form
12555  Lp.p2 = p; // already in the needed form
12556 
12557  if ( !rIsPluralRing(currRing) )
12558  pNext(Lp.p) = strat->tail;
12559 
12560  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12561  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12562  if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12563  {
12564  Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12565  Lp.i_r2 = atR;
12566  }
12567  else
12568  {
12569  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12570  Lp.i_r1 = -1;
12571  Lp.i_r2 = -1;
12572  }
12573  strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12574 
12576  {
12577  if (!rIsPluralRing(currRing))
12578  nDelete(&(Lp.p->coef));
12579  }
12580 
12581  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12582  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12583  }
12584 }
12585 #endif
12586 
12587 #ifdef HAVE_SHIFTBBA
12588 /*3
12589 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12590 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12591 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
12592 */
12593 void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
12594 {
12595  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12596  // atR = -1;
12597  if ((strat->syzComp==0)
12598  || (pGetComp(h)<=strat->syzComp))
12599  {
12600  int j;
12601  BOOLEAN new_pair=FALSE;
12602 
12603  if (pGetComp(h)==0)
12604  {
12605  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12606  if ((isFromQ)&&(strat->fromQ!=NULL))
12607  {
12608  for (j=0; j<=k; j++)
12609  {
12610  if (!strat->fromQ[j])
12611  {
12612  new_pair=TRUE;
12613  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR,uptodeg,lV);
12614  // other side pairs:
12615  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12616  //Print("j:%d, Ll:%d\n",j,strat->Ll);
12617  }
12618  }
12619  }
12620  else
12621  {
12622  new_pair=TRUE;
12623  for (j=0; j<=k; j++)
12624  {
12625  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR,uptodeg,lV);
12626  // other side pairs
12627  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12628  }
12629  /* HERE we put (h, s*h) pairs */
12630  /* enterOnePairSelfShifts (poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV); */
12631  enterOnePairSelfShifts (h, h, ecart, isFromQ, strat, atR, uptodeg, lV);
12632  }
12633  }
12634  else
12635  {
12636  for (j=0; j<=k; j++)
12637  {
12638  if ((pGetComp(h)==pGetComp(strat->S[j]))
12639  || (pGetComp(strat->S[j])==0))
12640  {
12641  new_pair=TRUE;
12642  enterOnePairManyShifts(j,h,ecart,isFromQ,strat, atR, uptodeg, lV);
12643  // other side pairs
12644  enterOnePairSelfShifts(h,strat->S[j],ecart,isFromQ,strat, atR,uptodeg,lV);
12645  //Print("j:%d, Ll:%d\n",j,strat->Ll);
12646  }
12647  }
12648  /* HERE we put (h, s*h) pairs */
12649  enterOnePairSelfShifts (h, h, ecart, isFromQ, strat, atR, uptodeg, lV);
12650  }
12651 
12652  if (new_pair)
12653  {
12654  strat->chainCrit(h,ecart,strat);
12655  }
12656 
12657  }
12658 }
12659 #endif
12660 
12661 #ifdef HAVE_SHIFTBBA
12662 /*2
12663 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
12664 *superfluous elements in S will be deleted
12665 */
12666 void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR,int uptodeg, int lV)
12667 {
12668  /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12669  /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
12670  int j=pos;
12671 
12673  initenterpairsShift(h,k,ecart,0,strat, atR,uptodeg,lV);
12674  if ( (!strat->fromT)
12675  && ((strat->syzComp==0)
12676  ||(pGetComp(h)<=strat->syzComp)))
12677  {
12678  //Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
12679  unsigned long h_sev = pGetShortExpVector(h);
12680  loop
12681  {
12682  if (j > k) break;
12683  clearS(h,h_sev, &j,&k,strat);
12684  j++;
12685  }
12686  //Print("end clearS sl=%d\n",strat->sl);
12687  }
12688  // PrintS("end enterpairs\n");
12689 }
12690 #endif
12691 
12692 #ifdef HAVE_SHIFTBBA
12693 /*2
12694 * puts p to the set T, starting with the at position atT
12695 * and inserts all admissible shifts of p
12696 */
12697 void enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV)
12698 {
12699  /* determine how many elements we have to insert */
12700  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12701  /* hence, a total number of elt's to add is: */
12702  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12703 
12704  int toInsert = itoInsert(p.p, uptodeg, lV, strat->tailRing);
12705 
12706 #ifdef PDEBUG
12707  // Print("enterTShift uses toInsert: %d", toInsert); PrintLn();
12708 #endif
12709  int i;
12710 
12711  if (atT < 0)
12712  atT = strat->posInT(strat->T, strat->tl, p);
12713 
12714  /* can call enterT in a sequence, e.g. */
12715 
12716  /* shift0 = it's our model for further shifts */
12717  enterT(p,strat,atT);
12718  LObject qq;
12719  for (i=1; i<=toInsert; i++) // toIns - 1?
12720  {
12721  qq = p; //qq.Copy();
12722  qq.p = NULL;
12723  qq.max_exp = NULL;
12724  qq.t_p = p_LPshift(p_Copy(p.t_p,strat->tailRing), i, uptodeg, lV, strat->tailRing); // direct shift
12725  qq.GetP();
12726  // update q.sev
12727  qq.sev = pGetShortExpVector(qq.p);
12728  /* enter it into T, first el't is with the shift 0 */
12729  // compute the position for qq
12730  atT = strat->posInT(strat->T, strat->tl, qq);
12731  enterT(qq,strat,atT);
12732  }
12733 /* Q: what to do with this one in the orig enterT ? */
12734 /* strat->R[strat->tl] = &(strat->T[atT]); */
12735 /* Solution: it is done by enterT each time separately */
12736 }
12737 #endif
12738 
12739 #ifdef HAVE_SHIFTBBA
12741 {
12742  /* for the shift case need to run it with withT = TRUE */
12744  if (strat->noTailReduction) return L->GetLmCurrRing();
12745  poly h, p;
12746  p = h = L->GetLmTailRing();
12747  if ((h==NULL) || (pNext(h)==NULL))
12748  return L->GetLmCurrRing();
12749 
12750  TObject* With;
12751  // placeholder in case strat->tl < 0
12752  TObject With_s(strat->tailRing);
12753 
12754  LObject Ln(pNext(h), strat->tailRing);
12755  Ln.pLength = L->GetpLength() - 1;
12756 
12757  pNext(h) = NULL;
12758  if (L->p != NULL) pNext(L->p) = NULL;
12759  L->pLength = 1;
12760 
12761  Ln.PrepareRed(strat->use_buckets);
12762 
12763  while(!Ln.IsNull())
12764  {
12765  loop
12766  {
12767  Ln.SetShortExpVector();
12768  if (withT)
12769  {
12770  int j;
12771  j = kFindDivisibleByInT(strat, &Ln);
12772  if (j < 0) break;
12773  With = &(strat->T[j]);
12774  }
12775  else
12776  {
12777  With = kFindDivisibleByInS(strat, pos, &Ln, &With_s);
12778  if (With == NULL) break;
12779  }
12780  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
12781  {
12782  With->pNorm();
12783  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
12784  }
12786  if (ksReducePolyTail(L, With, &Ln))
12787  {
12788  // reducing the tail would violate the exp bound
12789  // set a flag and hope for a retry (in bba)
12791  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
12792  do
12793  {
12794  pNext(h) = Ln.LmExtractAndIter();
12795  pIter(h);
12796  L->pLength++;
12797  } while (!Ln.IsNull());
12798  goto all_done;
12799  }
12800  if (Ln.IsNull()) goto all_done;
12801  if (! withT) With_s.Init(currRing);
12802  }
12803  pNext(h) = Ln.LmExtractAndIter();
12804  pIter(h);
12805  L->pLength++;
12806  }
12807 
12808  all_done:
12809  Ln.Delete();
12810  if (L->p != NULL) pNext(L->p) = pNext(p);
12811 
12812  if (strat->redTailChange)
12813  {
12814  L->length = 0;
12815  }
12816  L->Normalize(); // HANNES: should have a test
12817  kTest_L(L);
12818  return L->GetLmCurrRing();
12819 }
12820 #endif
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:752
#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:310
#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:2440
int getIndexRng(long coeff)
Definition: kutil.cc:6591
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6390
poly redtailBbaBound(LObject *L, int pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7680
BOOLEAN kbTest(kBucket_pt bucket)
Tests
Definition: kbuckets.cc:181
denominator_list_s * denominator_list
Definition: kutil.h:57
polyset sig
Definition: kutil.h:294
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11766
#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:270
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:1176
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:5203
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:5470
void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin)
Definition: omBin.c:396
int nr
Definition: kutil.h:334
void initSbaPos(kStrategy strat)
Definition: kutil.cc:10186
poly redtail(LObject *L, int pos, kStrategy strat)
Definition: kutil.cc:7496
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:12306
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
Definition: old.gring.cc:2254
BOOLEAN honey
Definition: kutil.h:366
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9331
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6887
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:28
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:5363
#define Print
Definition: emacs.cc:83
int syzComp
Definition: kutil.h:342
long pLDeg1(poly p, int *l, const ring r)
Definition: p_polys.cc:842
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:9919
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4863
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:279
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:71
int syzmax
Definition: kutil.h:337
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6432
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7915
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6502
poly kHEdge
Definition: kutil.h:315
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:285
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1006
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6466
static int * initS_2_R(const int maxnr)
Definition: kutil.cc:526
class sLObject LObject
Definition: kutil.h:52
#define r_assume(x)
Definition: mod2.h:395
TObject * TSet
Definition: kutil.h:53
KINLINE TSet initT()
Definition: kInline.h:81
#define pLtCmpOrdSgnDiffM(p, q)
Definition: polys.h:125
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7956
bool sigdrop
Definition: kutil.h:348
#define TEST_OPT_PROT
Definition: options.h:98
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:11099
wlen_set lenSw
Definition: kutil.h:306
loop
Definition: myNF.cc:98
static int min(int a, int b)
Definition: fast_mult.cc:268
int Ll
Definition: kutil.h:339
#define pSetExp(p, i, v)
Definition: polys.h:42
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6846
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:7202
#define kTest_S(T)
Definition: kutil.h:643
long pLDeg1c(poly p, int *l, const ring r)
Definition: p_polys.cc:878
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:5280
#define FALSE
Definition: auxiliary.h:94
BOOLEAN noTailReduction
Definition: kutil.h:367
Compatiblity layer for legacy polynomial operations (over currRing)
int * S_2_R
Definition: kutil.h:330
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5335
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:3247
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3824
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:2231
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6931
int posInLrg0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6604
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5533
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10092
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:1444
static void enterOnePairManyShifts(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int uptodeg, int lV)
Definition: kutil.cc:12167
#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:335
char news
Definition: kutil.h:389
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:8843
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6811
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3954
#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:5049
char newt
Definition: kutil.h:390
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:4601
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:6776
static BOOLEAN rIsRatGRing(const ring r)
Definition: ring.h:415
BOOLEAN * NotUsedAxis
Definition: kutil.h:320
#define TEST_OPT_CONTENTSB
Definition: options.h:121
#define pDecrExp(p, i)
Definition: polys.h:44
BEGIN_NAMESPACE_SINGULARXX const ring const ring tailRing
Definition: DebugPrint.h:30
BOOLEAN posInLDependsOnLength
Definition: kutil.h:378
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:268
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6729
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:603
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:358
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:1663
#define pNeg(p)
Definition: polys.h:181
void initSyzRules(kStrategy strat)
Definition: kutil.cc:8380
BOOLEAN * pairtest
Definition: kutil.h:321
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5757
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:771
BOOLEAN z2homog
Definition: kutil.h:363
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4926
poly kNoether
Definition: kutil.h:316
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:3894
int tl
Definition: kutil.h:338
int Bl
Definition: kutil.h:340
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8129
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2606
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:6277
#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
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition: p_polys.cc:1616
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:2214
char noClearS
Definition: kutil.h:391
#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:4975
#define TEST_OPT_REDSB
Definition: options.h:99
poly pMove2CurrTail(poly p, kStrategy strat)
Definition: kutil.cc:11936
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:8680
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:640
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:480
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:326
#define setmax
Definition: kutil.h:27
#define pLcm(a, b, m)
Definition: polys.h:277
unsigned long * sevT
Definition: kutil.h:311
void * ADDRESS
Definition: auxiliary.h:115
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:281
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:273
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11380
void pWrite(poly p)
Definition: polys.h:290
int ak
Definition: kutil.h:341
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:10863
#define setmaxLinc
Definition: kutil.h:29
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8228
void cancelunit(LObject *L, BOOLEAN inNF)
Definition: kutil.cc:332
int k
Definition: cfEzgcd.cc:93
poly kCreateZeroPoly(long exp[], long cabsind, poly *t_p, ring leadRing, ring tailRing)
Definition: kutil.cc:4406
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10288
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
Definition: old.gring.cc:1885
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1726
#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:2695
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:7572
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:6378
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:911
#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:12666
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:522
ring rAssure_c_dp(const ring r)
Definition: ring.cc:4893
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:7045
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5703
int(* red)(LObject *L, kStrategy strat)
Definition: kutil.h:264
#define omAlloc(size)
Definition: omAllocDecl.h:210
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:10005
int nextZeroSimplexExponent(long exp[], long ind[], long cexp[], long cind[], long *cabsind, long step[], long bound, long N)
Definition: kutil.cc:4340
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:8826
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:267
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:1951
void chainCritSig(poly p, int, kStrategy strat)
Definition: kutil.cc:3476
int currIdx
Definition: kutil.h:303
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:4952
#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:6688
int minim
Definition: kutil.h:346
#define pLtCmpOrdSgnDiffP(p, q)
Definition: polys.h:126
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:5324
int Bmax
Definition: kutil.h:340
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:1952
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4650
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:278
skStrategy()
Definition: kutil.cc:11602
char completeReduce_retry
Definition: kutil.h:392
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:12593
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11353
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8931
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6190
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:942
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:9903
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9469
int HCord
Definition: kutil.h:343
#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:68
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2883
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
pFDegProc pOrigFDeg
Definition: kutil.h:282
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:12060
poly res
Definition: myNF.cc:322
BOOLEAN interpt
Definition: kutil.h:360
#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:266
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:276
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8033
bool equal
Definition: cfModGcd.cc:4067
long twoPow(long arg)
Definition: kutil.cc:4217
void enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV)
Definition: kutil.cc:12697
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5393
static int rBlocks(ring r)
Definition: ring.h:559
int nrsyzcrit
Definition: kutil.h:349
BOOLEAN fromT
Definition: kutil.h:368
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8535
int posInT17_c(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5905
int nrrewcrit
Definition: kutil.h:350
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:588
const ring r
Definition: syzextra.cc:208
pLDegProc pOrigLDeg
Definition: kutil.h:283
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:876
BOOLEAN homog
Definition: kutil.h:361
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:4017
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5429
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 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:31
#define kTest_TS(A)
Definition: kutil.h:641
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
poly p_One(const ring r)
Definition: p_polys.cc:1314
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:3365
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:4733
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9750
BOOLEAN Gebauer
Definition: kutil.h:367
#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:307
#define messageSets(s)
Definition: kutil.h:528
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3139
long p_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:597
LObject * LSet
Definition: kutil.h:54
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1325
void initEcartBBA(TObject *h)
Definition: kutil.cc:1259
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5859
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:7968
#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:4225
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:740
#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:272
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:11950
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:644
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:11254
int m
Definition: cfEzgcd.cc:119
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6132
LObject P
Definition: kutil.h:288
#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:7358
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9768
unsigned sbaOrder
Definition: kutil.h:302
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:6981
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:10361
void rDebugPrint(const ring r)
Definition: ring.cc:4012
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:11800
int isInV(poly p, int lV)
Definition: shiftgb.cc:241
poly tail
Definition: kutil.h:322
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:4899
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:5798
CanonicalForm H
Definition: facAbsFact.cc:64
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:698
TObject ** R
Definition: kutil.h:328
static unsigned pLength(poly a)
Definition: p_polys.h:189
#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:292
#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:366
intset lenS
Definition: kutil.h:305
#define p_LmTest(p, r)
Definition: p_polys.h:161
#define nDelete(n)
Definition: numbers.h:16
int tmax
Definition: kutil.h:338
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:12088
int Kstd1_deg
Definition: kutil.cc:236
int cp
Definition: kutil.h:335
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:753
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9554
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:3555
void rChangeCurrRing(ring r)
Definition: polys.cc:12
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1063
poly redtailBba_Z(LObject *L, int pos, kStrategy strat)
Definition: kutil.cc:7797
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10802
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:7112
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:7264
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition: ideals.cc:562
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:11675
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:365
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4635
intset ecartS
Definition: kutil.h:295
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
poly t_kHEdge
Definition: kutil.h:317
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:3226
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:4469
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:7295
#define TEST_OPT_SUGARCRIT
Definition: options.h:102
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:7150
#define TEST_OPT_WEIGHTM
Definition: options.h:115
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:277
void initPairtest(kStrategy strat)
Definition: kutil.cc:672
long pLDegb(poly p, int *l, const ring r)
Definition: p_polys.cc:812
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:313
BOOLEAN LDegLast
Definition: kutil.h:374
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:11031
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:1531
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:3602
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:976
LSet B
Definition: kutil.h:314
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4889
int Lmax
Definition: kutil.h:339
int64 wlen_type
Definition: kutil.h:48
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:751
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:448
long ind_fact_2(long arg)
Definition: kutil.cc:4202
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:6350
ring tailRing
Definition: kutil.h:331
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5546
int gcd(int a, int b)
Definition: walkSupport.cc:839
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:345
#define TEST_OPT_SB_1
Definition: options.h:113
denominator_list next
Definition: kutil.h:59
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:319
omBin tailBin
Definition: kutil.h:333
#define TEST_OPT_CANCELUNIT
Definition: options.h:122
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:9832
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:5102
#define pDelete(p_ptr)
Definition: polys.h:169
char overflow
Definition: kutil.h:393
#define omSizeWOfBin(bin_ptr)
int syzidxmax
Definition: kutil.h:337
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:9000
~skStrategy()
Definition: kutil.cc:11622
unsigned long * sevS
Definition: kutil.h:308
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5588
#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:10613
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6158
#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:10840
unsigned long * sevSyz
Definition: kutil.h:309
#define setmaxTinc
Definition: kutil.h:32
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3460
void rKillModifiedRing(ring r)
Definition: ring.cc:2972
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:10401
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:47
#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:1039
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:6089
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:293
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:336
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1069
poly pCopyL2p(LObject H, kStrategy strat)
Definition: kutil.cc:11967
int idElem(const ideal F)
count non-zero elements
int dReportError(const char *fmt,...)
Definition: dError.cc:45
TSet T
Definition: kutil.h:312
p exp[i]
Definition: DebugPrint.cc:39
#define ALLOW_PROD_CRIT(A)
Definition: kutil.h:384
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
omBin lmBin
Definition: kutil.h:332
long ind2(long arg)
Definition: kutil.cc:4190
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4623
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:614
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8955
BOOLEAN use_buckets
Definition: kutil.h:372
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3205
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:10736
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:6032
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:12740
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:4381
ideal createG0()
Definition: kutil.cc:4535
void wrp(poly p)
Definition: polys.h:292
#define pDivComp_GREATER
Definition: kutil.cc:142
#define kTest_T(T)
Definition: kutil.h:642
kBucketDestroy & P
Definition: myNF.cc:191
#define pDivComp_INCOMP
Definition: kutil.cc:143
int LazyPass
Definition: kutil.h:341
static jList * T
Definition: janet.cc:37
polyrec * poly
Definition: hilb.h:10
static LSet initL(int nr=setmaxL)
Definition: kutil.h:410
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:877
int newIdeal
Definition: kutil.h:345
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:11188
ideal Shdl
Definition: kutil.h:289
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11729
#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:5664
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:85
kStrategy next
Definition: kutil.h:263
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:2755
#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:3535
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:504
poly p_ISet(long i, const ring r)
returns the poly representing the integer i
Definition: p_polys.cc:1298
static poly p_Mult_q(poly p, poly q, const ring r)
Definition: p_polys.h:1020
char redTailChange
Definition: kutil.h:388
void enterOnePairSelfShifts(poly qq, poly p, int ecart, int isFromQ, kStrategy strat, int, int uptodeg, int lV)
Definition: kutil.cc:12243
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:10168
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:284
#define pLmEqual(p1, p2)
Definition: polys.h:111
int syzl
Definition: kutil.h:337
#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:341
#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:5966
class sTObject TObject
Definition: kutil.h:51
Definition: nc.h:26
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5635
ring tailRing
Definition: kutil.h:70
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9666
poly p
Definition: kutil.h:67
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9229
intset syzIdx
Definition: kutil.h:299
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition: p_polys.cc:1209
#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:1139
#define pIsVector(p)
Definition: polys.h:233
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6214
BOOLEAN pCompareChainPart(poly p, poly p1, poly p2, poly lcm, const ring R)
Definition: kpolys.cc:74
#define idIsConstant(I)
Definition: ideals.h:40