My Project
kutil.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT: kernel: utils for kStd
6 */
7 
8 // #define PDEBUG 2
9 // #define PDIV_DEBUG
10 #define KUTIL_CC
11 
12 #define MYTEST 0
13 
14 //All vs Just strategy over rings:
15 // 1 - Just
16 // 0 - All
17 #define ALL_VS_JUST 0
18 //Extended Spoly Strategy:
19 // 0 - new gen sig
20 // 1 - ann*old sig
21 #define EXT_POLY_NEW 0
22 
23 #include "kernel/mod2.h"
24 
25 #include "misc/mylimits.h"
26 #include "misc/options.h"
27 #include "polys/nc/nc.h"
28 #include "polys/nc/sca.h"
29 #include "polys/weight.h" /* for kDebugPrint: maxdegreeWecart*/
30 
31 #include <stdlib.h>
32 #include <string.h>
33 
34 #ifdef KDEBUG
35 #undef KDEBUG
36 #define KDEBUG 2
37 #endif
38 
39 #ifdef DEBUGF5
40 #undef DEBUGF5
41 //#define DEBUGF5 1
42 #endif
43 
44 // define if enterL, enterT should use memmove instead of doing it manually
45 // on topgun, this is slightly faster (see monodromy_l.tst, homog_gonnet.sing)
46 #ifndef SunOS_4
47 #define ENTER_USE_MEMMOVE
48 #endif
49 
50 // define, if the my_memmove inlines should be used instead of
51 // system memmove -- it does not seem to pay off, though
52 // #define ENTER_USE_MYMEMMOVE
53 
54 #include "kernel/GBEngine/kutil.h"
55 #include "polys/kbuckets.h"
56 #include "coeffs/numbers.h"
57 #include "kernel/polys.h"
58 #include "polys/monomials/ring.h"
59 #include "kernel/ideals.h"
61 #include "kernel/GBEngine/kstd1.h"
63 
64 #ifdef HAVE_SHIFTBBA
65 #include "polys/shiftop.h"
66 #endif
67 
68 #include "polys/prCopy.h"
69 
70 #ifdef HAVE_RATGRING
72 #endif
73 
74 #ifdef KDEBUG
75 #undef KDEBUG
76 #define KDEBUG 2
77 #endif
78 
79 #ifdef DEBUGF5
80 #undef DEBUGF5
81 #define DEBUGF5 2
82 #endif
83 
85 
86 
87 #ifdef ENTER_USE_MYMEMMOVE
88 inline void _my_memmove_d_gt_s(unsigned long* d, unsigned long* s, long l)
89 {
90  REGISTER unsigned long* _dl = (unsigned long*) d;
91  REGISTER unsigned long* _sl = (unsigned long*) s;
92  REGISTER long _i = l - 1;
93 
94  do
95  {
96  _dl[_i] = _sl[_i];
97  _i--;
98  }
99  while (_i >= 0);
100 }
101 
102 inline void _my_memmove_d_lt_s(unsigned long* d, unsigned long* s, long l)
103 {
104  REGISTER long _ll = l;
105  REGISTER unsigned long* _dl = (unsigned long*) d;
106  REGISTER unsigned long* _sl = (unsigned long*) s;
107  REGISTER long _i = 0;
108 
109  do
110  {
111  _dl[_i] = _sl[_i];
112  _i++;
113  }
114  while (_i < _ll);
115 }
116 
117 inline void _my_memmove(void* d, void* s, long l)
118 {
119  unsigned long _d = (unsigned long) d;
120  unsigned long _s = (unsigned long) s;
121  unsigned long _l = ((l) + SIZEOF_LONG - 1) >> LOG_SIZEOF_LONG;
122 
123  if (_d > _s) _my_memmove_d_gt_s(_d, _s, _l);
124  else _my_memmove_d_lt_s(_d, _s, _l);
125 }
126 
127 #undef memmove
128 #define memmove(d,s,l) _my_memmove(d, s, l)
129 #endif
130 
131 static poly redMora (poly h,int maxIndex,kStrategy strat);
132 static poly redBba (poly h,int maxIndex,kStrategy strat);
133 
134 #ifdef HAVE_RINGS
135 #define pDivComp_EQUAL 2
136 #define pDivComp_LESS 1
137 #define pDivComp_GREATER -1
138 #define pDivComp_INCOMP 0
139 /* Checks the relation of LM(p) and LM(q)
140  LM(p) = LM(q) => return pDivComp_EQUAL
141  LM(p) | LM(q) => return pDivComp_LESS
142  LM(q) | LM(p) => return pDivComp_GREATER
143  else return pDivComp_INCOMP */
144 static inline int pDivCompRing(poly p, poly q)
145 {
146  if ((currRing->pCompIndex < 0)
148  {
149  BOOLEAN a=FALSE, b=FALSE;
150  int i;
151  unsigned long la, lb;
152  unsigned long divmask = currRing->divmask;
153  for (i=0; i<currRing->VarL_Size; i++)
154  {
155  la = p->exp[currRing->VarL_Offset[i]];
156  lb = q->exp[currRing->VarL_Offset[i]];
157  if (la != lb)
158  {
159  if (la < lb)
160  {
161  if (b) return pDivComp_INCOMP;
162  if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
163  return pDivComp_INCOMP;
164  a = TRUE;
165  }
166  else
167  {
168  if (a) return pDivComp_INCOMP;
169  if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
170  return pDivComp_INCOMP;
171  b = TRUE;
172  }
173  }
174  }
175  if (a) return pDivComp_LESS;
176  if (b) return pDivComp_GREATER;
177  if (!a & !b) return pDivComp_EQUAL;
178  }
179  return pDivComp_INCOMP;
180 }
181 #endif
182 
183 static inline int pDivComp(poly p, poly q)
184 {
185  if ((currRing->pCompIndex < 0)
187  {
188 #ifdef HAVE_RATGRING
189  if (rIsRatGRing(currRing))
190  {
192  q,currRing,
193  currRing->real_var_start, currRing->real_var_end))
194  return 0;
195  return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
196  }
197 #endif
198  BOOLEAN a=FALSE, b=FALSE;
199  int i;
200  unsigned long la, lb;
201  unsigned long divmask = currRing->divmask;
202  for (i=0; i<currRing->VarL_Size; i++)
203  {
204  la = p->exp[currRing->VarL_Offset[i]];
205  lb = q->exp[currRing->VarL_Offset[i]];
206  if (la != lb)
207  {
208  if (la < lb)
209  {
210  if (b) return 0;
211  if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
212  return 0;
213  a = TRUE;
214  }
215  else
216  {
217  if (a) return 0;
218  if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
219  return 0;
220  b = TRUE;
221  }
222  }
223  }
224  if (a) { /*assume(pLmCmp(q,p)==1);*/ return 1; }
225  if (b) { /*assume(pLmCmp(q,p)==-1);*/return -1; }
226  /*assume(pLmCmp(q,p)==0);*/
227  }
228  return 0;
229 }
230 
231 #ifdef HAVE_SHIFTBBA
232 static inline int pLPDivComp(poly p, poly q)
233 {
234  if ((currRing->pCompIndex < 0) || (__p_GetComp(p,currRing) == __p_GetComp(q,currRing)))
235  {
236  // maybe there is a more performant way to do this? This will get called quite often in bba.
237  if (_p_LPLmDivisibleByNoComp(p, q, currRing)) return 1;
238  if (_p_LPLmDivisibleByNoComp(q, p, currRing)) return -1;
239  }
240 
241  return 0;
242 }
243 #endif
244 
245 
246 VAR int HCord;
248 VAR int Kstd1_mu=INT_MAX;
249 
250 static void deleteHCBucket(LObject *L, kStrategy strat)
251 {
252  if ((strat->kNoether!=NULL)
253  && (L->bucket != NULL))
254  {
255  poly p1;
256  for (int i=1; i<= (int) L->bucket->buckets_used; i++)
257  {
258  poly p=L->bucket->buckets[i];
259  if(p!=NULL)
260  {
261  if (p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
262  {
263  L->bucket->buckets[i]=NULL;
264  L->bucket->buckets_length[i]=0;
265  }
266  else
267  {
268  do
269  {
270  if (p_Cmp(pNext(p),strat->kNoetherTail(), L->tailRing) == -1)
271  {
272  p_Delete(&pNext(p), L->tailRing);
273  L->bucket->buckets_length[i]=pLength(L->bucket->buckets[i]);
274  break;
275  }
276  pIter(p);
277  } while(p!=NULL);
278  }
279  }
280  }
281  int i=L->bucket->buckets_used;
282  while ((i>0)&&(L->bucket->buckets[i]==NULL))
283  {
284  i--;
285  L->bucket->buckets_used=i;
286  }
287  }
288 }
289 
290 /*2
291 *deletes higher monomial of p, re-compute ecart and length
292 *works only for orderings with ecart =pFDeg(end)-pFDeg(start)
293 */
294 void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
295 {
296  if (strat->kNoether!=NULL)
297  {
298  kTest_L(L,strat);
299  poly p1;
300  poly p = L->GetLmTailRing();
301  int l = 1;
302 
303  if (!fromNext && p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
304  {
305  if (L->bucket != NULL) kBucketDestroy(&L->bucket);
306  L->Delete();
307  L->Clear();
308  L->ecart = -1;
309  return;
310  }
311  if (L->bucket != NULL)
312  {
313  deleteHCBucket(L,strat);
314  return;
315  }
316  BOOLEAN cut=FALSE;
317  p1 = p;
318  while (pNext(p1)!=NULL)
319  {
320  if (p_LmCmp(pNext(p1), strat->kNoetherTail(), L->tailRing) == -1)
321  {
322  cut=(pNext(p1)!=NULL);
323  if (cut)
324  {
325  p_Delete(&pNext(p1), L->tailRing);
326 
327  if (p1 == p)
328  {
329  if (L->t_p != NULL)
330  {
331  assume(L->p != NULL && p == L->t_p);
332  pNext(L->p) = NULL;
333  }
334  L->max_exp = NULL;
335  }
336  else if (fromNext)
337  L->max_exp = p_GetMaxExpP(pNext(L->p), L->tailRing ); // p1;
338  //if (L->pLength != 0)
339  L->pLength = l;
340  // Hmmm when called from updateT, then only
341  // reset ecart when cut
342  if (fromNext)
343  L->ecart = L->pLDeg() - L->GetpFDeg();
344  }
345  break;
346  }
347  l++;
348  pIter(p1);
349  }
350  if ((!fromNext) && cut)
351  {
352  L->SetpFDeg();
353  L->ecart = L->pLDeg(strat->LDegLast) - L->GetpFDeg();
354  }
355  kTest_L(L,strat);
356  }
357 }
358 
359 void deleteHC(poly* p, int* e, int* l,kStrategy strat)
360 {
361  LObject L(*p, currRing, strat->tailRing);
362 
363  deleteHC(&L, strat);
364  *p = L.p;
365  *e = L.ecart;
366  *l = L.length;
367  if (L.t_p != NULL) p_LmFree(L.t_p, strat->tailRing);
368 }
369 
370 /*2
371 *tests if p.p=monomial*unit and cancels the unit
372 */
373 void cancelunit (LObject* L,BOOLEAN inNF)
374 {
375  if(rHasGlobalOrdering (currRing)) return;
376  if(TEST_OPT_CANCELUNIT) return;
377 
378  ring r = L->tailRing;
379  poly p = L->GetLmTailRing();
380  if(p_GetComp(p, r) != 0 && !p_OneComp(p, r)) return;
381 
382  number lc=NULL; /*dummy, is always set if rField_is_Ring(r) */
383  if (rField_is_Ring(r) /*&& (rHasLocalOrMixedOrdering(r))*/)
384  lc = pGetCoeff(p);
385 
386  // Leading coef have to be a unit
387  // example 2x+4x2 should be simplified to 2x*(1+2x)
388  // and 2 is not a unit in Z
389  //if ( !(n_IsUnit(pGetCoeff(p), r->cf)) ) return;
390 
391 // for(i=r->N;i>0;i--)
392 // {
393 // if ((p_GetExp(p,i,r)>0) && (rIsPolyVar(i, r)==TRUE)) return;
394 // }
395  poly h = pNext(p);
396  int i;
397 
399  {
400  loop
401  {
402  if (h==NULL)
403  {
404  p_Delete(&pNext(p), r);
405  if (!inNF)
406  {
407  number eins= nCopy(lc);
408  if (L->p != NULL)
409  {
410  pSetCoeff(L->p,eins);
411  if (L->t_p != NULL)
412  pSetCoeff0(L->t_p,eins);
413  }
414  else
415  pSetCoeff(L->t_p,eins);
416  /* p and t_p share the same coeff, if both are !=NULL */
417  /* p==NULL==t_p cannot happen here */
418  }
419  L->ecart = 0;
420  L->length = 1;
421  //if (L->pLength > 0)
422  L->pLength = 1;
423  L->max_exp = NULL;
424 
425  if (L->t_p != NULL && pNext(L->t_p) != NULL)
426  p_Delete(&pNext(L->t_p),r);
427  if (L->p != NULL && pNext(L->p) != NULL)
428  pNext(L->p) = NULL;
429  return;
430  }
431  i = rVar(r);
432  loop
433  {
434  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
435  i--;
436  if (i == 0) break; // does divide, try next monom
437  }
438  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
439  // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
440  // domains), no zerodivisor test needed CAUTION
441  if (!n_DivBy(pGetCoeff(h),lc,r->cf))
442  {
443  return;
444  }
445  pIter(h);
446  }
447  }
448  else
449  {
450  loop
451  {
452  if (h==NULL)
453  {
454  p_Delete(&pNext(p), r);
455  if (!inNF)
456  {
457  number eins=nInit(1);
458  if (L->p != NULL)
459  {
460  pSetCoeff(L->p,eins);
461  if (L->t_p != NULL)
462  pSetCoeff0(L->t_p,eins);
463  }
464  else
465  pSetCoeff(L->t_p,eins);
466  /* p and t_p share the same coeff, if both are !=NULL */
467  /* p==NULL==t_p cannot happen here */
468  }
469  L->ecart = 0;
470  L->length = 1;
471  //if (L->pLength > 0)
472  L->pLength = 1;
473  L->max_exp = NULL;
474 
475  if (L->t_p != NULL && pNext(L->t_p) != NULL)
476  p_Delete(&pNext(L->t_p),r);
477  if (L->p != NULL && pNext(L->p) != NULL)
478  pNext(L->p) = NULL;
479 
480  return;
481  }
482  i = rVar(r);
483  loop
484  {
485  if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
486  i--;
487  if (i == 0) break; // does divide, try next monom
488  }
489  //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
490  pIter(h);
491  }
492  }
493 }
494 
495 /*2
496 *pp is the new element in s
497 *returns TRUE (in strat->kAllAxis) if
498 *-HEcke is allowed
499 *-we are in the last componente of the vector
500 *-on all axis are monomials (all elements in NotUsedAxis are FALSE)
501 *returns FALSE for pLexOrderings,
502 *assumes in module case an ordering of type c* !!
503 * HEckeTest is only called with strat->kAllAxis==FALSE !
504 */
505 void HEckeTest (poly pp,kStrategy strat)
506 {
507  int j,/*k,*/p;
508 
509  if (currRing->pLexOrder
511  || (strat->ak >1)
513  {
514  return;
515  }
516  p=pIsPurePower(pp);
517  if (p!=0)
518  strat->NotUsedAxis[p] = FALSE;
519  /*- the leading term of pp is a power of the p-th variable -*/
520  for (j=(currRing->N);j>0; j--)
521  {
522  if (strat->NotUsedAxis[j])
523  {
524  strat->kAllAxis=FALSE;
525  return;
526  }
527  }
528  strat->kAllAxis=TRUE;
529 }
530 
531 /*2
532 *utilities for TSet, LSet
533 */
534 inline static intset initec (const int maxnr)
535 {
536  return (intset)omAlloc(maxnr*sizeof(int));
537 }
538 
539 inline static unsigned long* initsevS (const int maxnr)
540 {
541  return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
542 }
543 inline static int* initS_2_R (const int maxnr)
544 {
545  return (int*)omAlloc0(maxnr*sizeof(int));
546 }
547 
548 static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
549  int &length, const int incr)
550 {
551  assume(T!=NULL);
552  assume(sevT!=NULL);
553  assume(R!=NULL);
554  assume((length+incr) > 0);
555 
556  int i;
557  T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
558  (length+incr)*sizeof(TObject));
559 
560  sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
561  (length+incr)*sizeof(long*));
562 
563  R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
564  (length+incr)*sizeof(TObject*));
565  for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
566  length += incr;
567 }
568 
569 void cleanT (kStrategy strat)
570 {
571  int i,j;
572  poly p;
573  assume(currRing == strat->tailRing || strat->tailRing != NULL);
574 
575  pShallowCopyDeleteProc p_shallow_copy_delete =
576  (strat->tailRing != currRing ?
578  NULL);
579  for (j=0; j<=strat->tl; j++)
580  {
581  p = strat->T[j].p;
582  strat->T[j].p=NULL;
583  if (strat->T[j].max_exp != NULL)
584  {
585  p_LmFree(strat->T[j].max_exp, strat->tailRing);
586  }
587  i = -1;
588  loop
589  {
590  i++;
591  if (i>strat->sl)
592  {
593  if (strat->T[j].t_p != NULL)
594  {
595  p_Delete(&(strat->T[j].t_p), strat->tailRing);
596  p_LmFree(p, currRing);
597  }
598  else
599  {
600 #ifdef HAVE_SHIFTBBA
601  if (currRing->isLPring && strat->T[j].shift > 0)
602  {
603  pNext(p) = NULL; // pNext(p) points to the unshifted tail, don't try to delete it here
604  }
605 #endif
606  pDelete(&p);
607  }
608  break;
609  }
610  if (p == strat->S[i])
611  {
612  if (strat->T[j].t_p != NULL)
613  {
614  if (p_shallow_copy_delete!=NULL)
615  {
616  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
617  currRing->PolyBin);
618  }
619  p_LmFree(strat->T[j].t_p, strat->tailRing);
620  }
621  break;
622  }
623  }
624  }
625  strat->tl=-1;
626 }
627 
629 {
630  int i,j;
631  poly p;
632  assume(currRing == strat->tailRing || strat->tailRing != NULL);
633 
634  pShallowCopyDeleteProc p_shallow_copy_delete =
635  (strat->tailRing != currRing ?
637  NULL);
638  for (j=0; j<=strat->tl; j++)
639  {
640  p = strat->T[j].p;
641  strat->T[j].p=NULL;
642  if (strat->T[j].max_exp != NULL)
643  {
644  p_LmFree(strat->T[j].max_exp, strat->tailRing);
645  }
646  i = -1;
647  loop
648  {
649  i++;
650  if (i>strat->sl)
651  {
652  if (strat->T[j].t_p != NULL)
653  {
654  p_Delete(&(strat->T[j].t_p), strat->tailRing);
655  p_LmFree(p, currRing);
656  }
657  else
658  {
659  //pDelete(&p);
660  p = NULL;
661  }
662  break;
663  }
664  if (p == strat->S[i])
665  {
666  if (strat->T[j].t_p != NULL)
667  {
668  assume(p_shallow_copy_delete != NULL);
669  pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
670  currRing->PolyBin);
671  p_LmFree(strat->T[j].t_p, strat->tailRing);
672  }
673  break;
674  }
675  }
676  }
677  strat->tl=-1;
678 }
679 
680 //LSet initL ()
681 //{
682 // int i;
683 // LSet l = (LSet)omAlloc(setmaxL*sizeof(LObject));
684 // return l;
685 //}
686 
687 static inline void enlargeL (LSet* L,int* length,const int incr)
688 {
689  assume((*L)!=NULL);
690  assume(((*length)+incr)>0);
691 
692  *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
693  ((*length)+incr)*sizeof(LObject));
694  (*length) += incr;
695 }
696 
698 {
699  strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
700 }
701 
702 /*2
703 *test whether (p1,p2) or (p2,p1) is in L up position length
704 *it returns TRUE if yes and the position k
705 */
706 BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
707 {
708  LObject *p=&(strat->L[length]);
709 
710  *k = length;
711  loop
712  {
713  if ((*k) < 0) return FALSE;
714  if (((p1 == (*p).p1) && (p2 == (*p).p2))
715  || ((p1 == (*p).p2) && (p2 == (*p).p1)))
716  return TRUE;
717  (*k)--;
718  p--;
719  }
720 }
721 
722 /*2
723 *in B all pairs have the same element p on the right
724 *it tests whether (q,p) is in B and returns TRUE if yes
725 *and the position k
726 */
727 BOOLEAN isInPairsetB(poly q,int* k,kStrategy strat)
728 {
729  LObject *p=&(strat->B[strat->Bl]);
730 
731  *k = strat->Bl;
732  loop
733  {
734  if ((*k) < 0) return FALSE;
735  if (q == (*p).p1)
736  return TRUE;
737  (*k)--;
738  p--;
739  }
740 }
741 
742 int kFindInT(poly p, TSet T, int tlength)
743 {
744  int i;
745 
746  for (i=0; i<=tlength; i++)
747  {
748  if (T[i].p == p) return i;
749  }
750  return -1;
751 }
752 
753 int kFindInT(poly p, kStrategy strat)
754 {
755  int i;
756  do
757  {
758  i = kFindInT(p, strat->T, strat->tl);
759  if (i >= 0) return i;
760  strat = strat->next;
761  }
762  while (strat != NULL);
763  return -1;
764 }
765 
766 #ifdef HAVE_SHIFTBBA
767 int kFindInTShift(poly p, TSet T, int tlength)
768 {
769  int i;
770 
771  for (i=0; i<=tlength; i++)
772  {
773  // in the Letterplace ring the LMs in T and L are copies thus we have to use pEqualPolys() instead of ==
774  if (pEqualPolys(T[i].p, p)) return i;
775  }
776  return -1;
777 }
778 #endif
779 
780 #ifdef HAVE_SHIFTBBA
781 int kFindInTShift(poly p, kStrategy strat)
782 {
783  int i;
784  do
785  {
786  i = kFindInTShift(p, strat->T, strat->tl);
787  if (i >= 0) return i;
788  strat = strat->next;
789  }
790  while (strat != NULL);
791  return -1;
792 }
793 #endif
794 
795 #ifdef KDEBUG
796 
798 {
799  if (t_p != NULL) p_wrp(t_p, tailRing);
800  else if (p != NULL) p_wrp(p, currRing, tailRing);
801  else ::wrp(NULL);
802 }
803 
804 #define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
805 
806 // check that Lm's of a poly from T are "equal"
807 static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
808 {
809  int i;
810  for (i=1; i<=tailRing->N; i++)
811  {
812  if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
813  return "Lm[i] different";
814  }
815  if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
816  return "Lm[0] different";
817  if (pNext(p) != pNext(t_p))
818  return "Lm.next different";
819  if (pGetCoeff(p) != pGetCoeff(t_p))
820  return "Lm.coeff different";
821  return NULL;
822 }
823 
825 BOOLEAN kTest_T(TObject * T, kStrategy strat, int i, char TN)
826 {
827  ring tailRing = T->tailRing;
828  ring strat_tailRing = strat->tailRing;
829  if (strat_tailRing == NULL) strat_tailRing = tailRing;
830  r_assume(strat_tailRing == tailRing);
831 
832  poly p = T->p;
833  // ring r = currRing;
834 
835  if (T->p == NULL && T->t_p == NULL && i >= 0)
836  return dReportError("%c[%d].poly is NULL", TN, i);
837 
838  if (T->p!=NULL)
839  {
840  nTest(pGetCoeff(T->p));
841  if ((T->t_p==NULL)&&(pNext(T->p)!=NULL)) p_Test(pNext(T->p),currRing);
842  }
843  if (T->t_p!=NULL)
844  {
845  nTest(pGetCoeff(T->t_p));
846  if (pNext(T->t_p)!=NULL) p_Test(pNext(T->t_p),strat_tailRing);
847  }
848  if ((T->p!=NULL)&&(T->t_p!=NULL)) assume(pGetCoeff(T->p)==pGetCoeff(T->t_p));
849 
850  if (T->tailRing != currRing)
851  {
852  if (T->t_p == NULL && i > 0)
853  return dReportError("%c[%d].t_p is NULL", TN, i);
854  pFalseReturn(p_Test(T->t_p, T->tailRing));
855  if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
856  if ((T->p != NULL) && (T->t_p != NULL))
857  {
858  const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
859  if (msg != NULL)
860  return dReportError("%c[%d] %s", TN, i, msg);
861  // r = T->tailRing;
862  p = T->t_p;
863  }
864  if (T->p == NULL)
865  {
866  p = T->t_p;
867  // r = T->tailRing;
868  }
869  if (T->t_p != NULL && i >= 0 && TN == 'T')
870  {
871  if (pNext(T->t_p) == NULL)
872  {
873  if (T->max_exp != NULL)
874  return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
875  }
876  else
877  {
878  if (T->max_exp == NULL)
879  return dReportError("%c[%d].max_exp is NULL", TN, i);
880  if (pNext(T->max_exp) != NULL)
881  return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
882 
883  pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
884  omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
885 #if KDEBUG > 0
886  if (! sloppy_max)
887  {
888  poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
889  p_Setm(T->max_exp, tailRing);
890  p_Setm(test_max, tailRing);
891  BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
892  if (! equal)
893  return dReportError("%c[%d].max out of sync", TN, i);
894  p_LmFree(test_max, tailRing);
895  }
896 #endif
897  }
898  }
899  }
900  else
901  {
902  if (T->p == NULL && i > 0)
903  return dReportError("%c[%d].p is NULL", TN, i);
904 #ifdef HAVE_SHIFTBBA
905  if (currRing->isLPring && T->shift > 0)
906  {
907  // in this case, the order is not correct. test LM and tail separately
910  }
911  else
912 #endif
913  {
915  }
916  }
917 
918  if ((i >= 0) && (T->pLength != 0)
919  && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
920  {
921  int l=T->pLength;
922  T->pLength=pLength(p);
923  return dReportError("%c[%d] pLength error: has %d, specified to have %d",
924  TN, i , pLength(p), l);
925  }
926 
927  // check FDeg, for elements in L and T
928  if (i >= 0 && (TN == 'T' || TN == 'L'))
929  {
930  // FDeg has ir element from T of L set
931  if (strat->homog && (T->FDeg != T->pFDeg()))
932  {
933  int d=T->FDeg;
934  T->FDeg=T->pFDeg();
935  return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
936  TN, i , T->pFDeg(), d);
937  }
938  }
939 
940  // check is_normalized for elements in T
941  if (i >= 0 && TN == 'T')
942  {
943  if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
944  return dReportError("T[%d] is_normalized error", i);
945 
946  }
947  return TRUE;
948 }
949 
951  BOOLEAN testp, int lpos, TSet T, int tlength)
952 {
953  ring strat_tailRing=strat->tailRing;
954  if (L->p!=NULL)
955  {
956  if ((L->t_p==NULL)
957  &&(pNext(L->p)!=NULL)
958  &&(pGetCoeff(pNext(L->p))!=NULL)) /* !=strat->tail*/
959  {
960  p_Test(pNext(L->p),currRing);
961  nTest(pGetCoeff(L->p));
962  }
963  }
964  if (L->t_p!=NULL)
965  {
966  if ((pNext(L->t_p)!=NULL)
967  &&(pGetCoeff(pNext(L->t_p))!=NULL)) /* !=strat->tail*/
968  {
969  p_Test(pNext(L->t_p),strat_tailRing);
970  nTest(pGetCoeff(L->t_p));
971  }
972  }
973  if ((L->p!=NULL)&&(L->t_p!=NULL)) assume(pGetCoeff(L->p)==pGetCoeff(L->t_p));
974 
975  if (testp)
976  {
977  poly pn = NULL;
978  if (L->bucket != NULL)
979  {
980  kFalseReturn(kbTest(L->bucket));
981  r_assume(L->bucket->bucket_ring == L->tailRing);
982  if (L->p != NULL && pNext(L->p) != NULL)
983  {
984  pn = pNext(L->p);
985  pNext(L->p) = NULL;
986  }
987  }
988  kFalseReturn(kTest_T(L, strat, lpos, 'L'));
989  if (pn != NULL)
990  pNext(L->p) = pn;
991 
992  ring r;
993  poly p;
994  L->GetLm(p, r);
995  if (L->sev != 0L)
996  {
997  if (p_GetShortExpVector(p, r) != L->sev)
998  {
999  return dReportError("L[%d] wrong sev: has %lo, specified to have %lo",
1000  lpos, p_GetShortExpVector(p, r), L->sev);
1001  }
1002  }
1003  }
1004  if (L->p1 == NULL)
1005  {
1006  // L->p2 either NULL or "normal" poly
1007  pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
1008  }
1009  else if (tlength > 0 && T != NULL && (lpos >=0))
1010  {
1011  // now p1 and p2 must be != NULL and must be contained in T
1012  int i;
1013 #ifdef HAVE_SHIFTBBA
1014  if (rIsLPRing(currRing))
1015  i = kFindInTShift(L->p1, T, tlength);
1016  else
1017 #endif
1018  i = kFindInT(L->p1, T, tlength);
1019  if (i < 0)
1020  return dReportError("L[%d].p1 not in T",lpos);
1021 #ifdef HAVE_SHIFTBBA
1022  if (rIsLPRing(currRing))
1023  {
1024  if (rField_is_Ring(currRing)) return TRUE; // m*shift(q) is not in T
1025  i = kFindInTShift(L->p2, T, tlength);
1026  }
1027  else
1028 #endif
1029  i = kFindInT(L->p2, T, tlength);
1030  if (i < 0)
1031  return dReportError("L[%d].p2 not in T",lpos);
1032  }
1033  return TRUE;
1034 }
1035 
1037 {
1038  int i;
1039  // test P
1040  kFalseReturn(kTest_L(&(strat->P), strat,
1041  (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
1042  -1, strat->T, strat->tl));
1043 
1044  // test T
1045  if (strat->T != NULL)
1046  {
1047  for (i=0; i<=strat->tl; i++)
1048  {
1049  kFalseReturn(kTest_T(&(strat->T[i]), strat, i, 'T'));
1050  if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
1051  return dReportError("strat->sevT[%d] out of sync", i);
1052  }
1053  }
1054 
1055  // test L
1056  if (strat->L != NULL)
1057  {
1058  for (i=0; i<=strat->Ll; i++)
1059  {
1060  kFalseReturn(kTest_L(&(strat->L[i]), strat,
1061  strat->L[i].Next() != strat->tail, i,
1062  strat->T, strat->tl));
1063  // may be unused
1064  //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
1065  // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
1066  //{
1067  // assume(strat->L[i].bucket != NULL);
1068  //}
1069  }
1070  }
1071 
1072  // test S
1073  if (strat->S != NULL)
1074  kFalseReturn(kTest_S(strat));
1075 
1076  return TRUE;
1077 }
1078 
1080 {
1081  int i;
1082  BOOLEAN ret = TRUE;
1083  for (i=0; i<=strat->sl; i++)
1084  {
1085  if (strat->S[i] != NULL &&
1086  strat->sevS[i] != pGetShortExpVector(strat->S[i]))
1087  {
1088  return dReportError("S[%d] wrong sev: has %o, specified to have %o",
1089  i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
1090  }
1091  }
1092  return ret;
1093 }
1094 
1095 
1096 
1098 {
1099  int i, j;
1100  // BOOLEAN ret = TRUE;
1101  kFalseReturn(kTest(strat));
1102 
1103  // test strat->R, strat->T[i].i_r
1104  for (i=0; i<=strat->tl; i++)
1105  {
1106  if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1107  return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1108  strat->T[i].i_r);
1109  if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1110  return dReportError("T[%d].i_r with R out of sync", i);
1111  }
1112  // test containment of S inT
1113  if ((strat->S != NULL)&&(strat->tl>=0))
1114  {
1115  for (i=0; i<=strat->sl; i++)
1116  {
1117  j = kFindInT(strat->S[i], strat->T, strat->tl);
1118  if (j < 0)
1119  return dReportError("S[%d] not in T", i);
1120  if (strat->S_2_R[i] != strat->T[j].i_r)
1121  return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1122  i, strat->S_2_R[i], j, strat->T[j].i_r);
1123  }
1124  }
1125  // test strat->L[i].i_r1
1126  #ifdef HAVE_SHIFTBBA
1127  if (!rIsLPRing(currRing)) // in the Letterplace ring we currently don't set/use i_r1 and i_r2
1128  #endif
1129  if (strat->L!=NULL)
1130  {
1131  for (i=0; i<=strat->Ll; i++)
1132  {
1133  if (strat->L[i].p1 != NULL && strat->L[i].p2)
1134  {
1135  if (strat->L[i].i_r1 < 0 ||
1136  strat->L[i].i_r1 > strat->tl ||
1137  strat->L[i].T_1(strat)->p != strat->L[i].p1)
1138  return dReportError("L[%d].i_r1 out of sync", i);
1139  if (strat->L[i].i_r2 < 0 ||
1140  strat->L[i].i_r2 > strat->tl ||
1141  strat->L[i].T_2(strat)->p != strat->L[i].p2)
1142  return dReportError("L[%d].i_r2 out of sync", i);
1143  }
1144  else
1145  {
1146  if (strat->L[i].i_r1 != -1)
1147  return dReportError("L[%d].i_r1 out of sync", i);
1148  if (strat->L[i].i_r2 != -1)
1149  return dReportError("L[%d].i_r2 out of sync", i);
1150  }
1151  if (strat->L[i].i_r != -1)
1152  return dReportError("L[%d].i_r out of sync", i);
1153  }
1154  }
1155  return TRUE;
1156 }
1157 
1158 #endif // KDEBUG
1159 
1160 /*2
1161 *cancels the i-th polynomial in the standardbase s
1162 */
1163 void deleteInS (int i,kStrategy strat)
1164 {
1165 #ifdef ENTER_USE_MEMMOVE
1166  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1167  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1168  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1169  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1170 #else
1171  int j;
1172  for (j=i; j<strat->sl; j++)
1173  {
1174  strat->S[j] = strat->S[j+1];
1175  strat->ecartS[j] = strat->ecartS[j+1];
1176  strat->sevS[j] = strat->sevS[j+1];
1177  strat->S_2_R[j] = strat->S_2_R[j+1];
1178  }
1179 #endif
1180  if (strat->lenS!=NULL)
1181  {
1182 #ifdef ENTER_USE_MEMMOVE
1183  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1184 #else
1185  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1186 #endif
1187  }
1188  if (strat->lenSw!=NULL)
1189  {
1190 #ifdef ENTER_USE_MEMMOVE
1191  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1192 #else
1193  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1194 #endif
1195  }
1196  if (strat->fromQ!=NULL)
1197  {
1198 #ifdef ENTER_USE_MEMMOVE
1199  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1200 #else
1201  for (j=i; j<strat->sl; j++)
1202  {
1203  strat->fromQ[j] = strat->fromQ[j+1];
1204  }
1205 #endif
1206  }
1207  strat->S[strat->sl] = NULL;
1208  strat->sl--;
1209 }
1210 
1211 
1212 /*2
1213 *cancels the i-th polynomial in the standardbase s
1214 */
1215 void deleteInSSba (int i,kStrategy strat)
1216 {
1217 #ifdef ENTER_USE_MEMMOVE
1218  memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1219  memmove(&(strat->sig[i]), &(strat->sig[i+1]), (strat->sl - i)*sizeof(poly));
1220  memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1221  memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1222  memmove(&(strat->sevSig[i]),&(strat->sevSig[i+1]),(strat->sl - i)*sizeof(unsigned long));
1223  memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1224 #else
1225  int j;
1226  for (j=i; j<strat->sl; j++)
1227  {
1228  strat->S[j] = strat->S[j+1];
1229  strat->sig[j] = strat->sig[j+1];
1230  strat->ecartS[j] = strat->ecartS[j+1];
1231  strat->sevS[j] = strat->sevS[j+1];
1232  strat->sevSig[j] = strat->sevSig[j+1];
1233  strat->S_2_R[j] = strat->S_2_R[j+1];
1234  }
1235 #endif
1236  if (strat->lenS!=NULL)
1237  {
1238 #ifdef ENTER_USE_MEMMOVE
1239  memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1240 #else
1241  for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1242 #endif
1243  }
1244  if (strat->lenSw!=NULL)
1245  {
1246 #ifdef ENTER_USE_MEMMOVE
1247  memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1248 #else
1249  for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1250 #endif
1251  }
1252  if (strat->fromQ!=NULL)
1253  {
1254 #ifdef ENTER_USE_MEMMOVE
1255  memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1256 #else
1257  for (j=i; j<strat->sl; j++)
1258  {
1259  strat->fromQ[j] = strat->fromQ[j+1];
1260  }
1261 #endif
1262  }
1263  strat->S[strat->sl] = NULL;
1264  strat->sl--;
1265 }
1266 
1267 #ifdef HAVE_SHIFTBBA
1268 static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
1269 {
1270  if (rIsLPRing(currRing)
1271  && (strat->P.p1!=NULL))
1272  {
1273  // clean up strat->P.p1: may be shifted
1274  poly p=strat->P.p1;
1275  int lv=currRing->isLPring;
1276  BOOLEAN is_shifted=TRUE;
1277  for (int i=lv;i>0;i--)
1278  {
1279  if (pGetExp(p,i)!=0) { is_shifted=FALSE; break;}
1280  }
1281  if (is_shifted
1282  && (kFindInL1(p, strat)<0)
1283  && (kFindInT(p, strat->T, strat->tl) < 0)
1284  )
1285  {
1286  return TRUE;
1287  }
1288  }
1289  return FALSE;
1290 }
1291 #endif
1292 /*2
1293 *cancels the j-th polynomial in the set
1294 */
1295 void deleteInL (LSet set, int *length, int j,kStrategy strat)
1296 {
1297  if (set[j].lcm!=NULL)
1298  {
1299  kDeleteLcm(&set[j]);
1300  }
1301  if (set[j].sig!=NULL)
1302  {
1303 #ifdef HAVE_RINGS
1304  if (pGetCoeff(set[j].sig) != NULL)
1305  pLmDelete(set[j].sig);
1306  else
1307 #endif
1308  pLmFree(set[j].sig);
1309  }
1310  if (set[j].p!=NULL)
1311  {
1312  if (pNext(set[j].p) == strat->tail)
1313  {
1314 #ifdef HAVE_RINGS
1315  if (pGetCoeff(set[j].p) != NULL)
1316  pLmDelete(set[j].p);
1317  else
1318 #endif
1319  pLmFree(set[j].p);
1320  /*- tail belongs to several int spolys -*/
1321  }
1322  else
1323  {
1324  // search p in T, if it is there, do not delete it
1325  if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1326  {
1327  // assure that for global orderings kFindInT fails
1328  //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1329  set[j].Delete();
1330  }
1331  }
1332  }
1333  #ifdef HAVE_SHIFTBBA
1334  if (is_shifted_p1(strat->P.p1,strat))
1335  {
1336  // clean up strat->P.p1: may be shifted
1337  pLmDelete(strat->P.p1);
1338  strat->P.p1=NULL;
1339  }
1340  #endif
1341  if (*length > 0 && j < *length)
1342  {
1343 #ifdef ENTER_USE_MEMMOVE
1344  memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1345 #else
1346  int i;
1347  for (i=j; i < (*length); i++)
1348  set[i] = set[i+1];
1349 #endif
1350  }
1351 #ifdef KDEBUG
1352  memset(&(set[*length]),0,sizeof(LObject));
1353 #endif
1354  (*length)--;
1355 }
1356 
1357 /*2
1358 *enters p at position at in L
1359 */
1360 void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1361 {
1362  // this should be corrected
1363  assume(p.FDeg == p.pFDeg());
1364 
1365  if ((*length)>=0)
1366  {
1367  if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1368  if (at <= (*length))
1369 #ifdef ENTER_USE_MEMMOVE
1370  memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1371 #else
1372  for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1373 #endif
1374  }
1375  else at = 0;
1376  (*set)[at] = p;
1377  (*length)++;
1378 }
1379 
1380 /*2
1381 * computes the normal ecart;
1382 * used in mora case and if pLexOrder & sugar in bba case
1383 */
1385 {
1386  h->FDeg = h->pFDeg();
1387  h->ecart = h->pLDeg() - h->FDeg;
1388  // h->length is set by h->pLDeg
1389  h->length=h->pLength=pLength(h->p);
1390 }
1391 
1393 {
1394  h->FDeg = h->pFDeg();
1395  (*h).ecart = 0;
1396  h->length=h->pLength=pLength(h->p);
1397 }
1398 
1399 void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1400 {
1401  Lp->FDeg = Lp->pFDeg();
1402  (*Lp).ecart = 0;
1403  (*Lp).length = 0;
1404 }
1405 
1406 void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1407 {
1408  Lp->FDeg = Lp->pFDeg();
1409  (*Lp).ecart = si_max(ecartF,ecartG);
1410  (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1411  (*Lp).length = 0;
1412 }
1413 
1414 /*2
1415 *if ecart1<=ecart2 it returns TRUE
1416 */
1417 static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1418 {
1419  return (ecart1 <= ecart2);
1420 }
1421 
1422 #ifdef HAVE_RINGS
1423 /*2
1424 * put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1425 */
1426 static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1427 {
1428  assume(atR >= 0);
1429  assume(i<=strat->sl);
1430  assume(p!=NULL);
1432  #if ALL_VS_JUST
1433  //Over rings, if we construct the strong pair, do not add the spair
1435  {
1436  number s,t,d;
1437  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1438 
1439  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1440  {
1441  nDelete(&d);
1442  nDelete(&s);
1443  nDelete(&t);
1444  return;
1445  }
1446  nDelete(&d);
1447  nDelete(&s);
1448  nDelete(&t);
1449  }
1450  #endif
1451  int j,compare,compareCoeff;
1452  LObject h;
1453 
1454 #ifdef KDEBUG
1455  h.ecart=0; h.length=0;
1456 #endif
1457  /*- computes the lcm(s[i],p) -*/
1458  if(pHasNotCFRing(p,strat->S[i]))
1459  {
1460  strat->cp++;
1461  return;
1462  }
1463  h.lcm = p_Lcm(p,strat->S[i],currRing);
1464  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1465  if (nIsZero(pGetCoeff(h.lcm)))
1466  {
1467  strat->cp++;
1468  pLmDelete(h.lcm);
1469  return;
1470  }
1471  // basic chain criterion
1472  /*
1473  *the set B collects the pairs of type (S[j],p)
1474  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1475  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
1476  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
1477  */
1478 
1479  for(j = strat->Bl;j>=0;j--)
1480  {
1481  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1482  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1483  if(compare == pDivComp_EQUAL)
1484  {
1485  //They have the same LM
1486  if(compareCoeff == pDivComp_LESS)
1487  {
1488  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1489  {
1490  strat->c3++;
1491  pLmDelete(h.lcm);
1492  return;
1493  }
1494  break;
1495  }
1496  if(compareCoeff == pDivComp_GREATER)
1497  {
1498  deleteInL(strat->B,&strat->Bl,j,strat);
1499  strat->c3++;
1500  }
1501  if(compareCoeff == pDivComp_EQUAL)
1502  {
1503  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1504  {
1505  strat->c3++;
1506  pLmDelete(h.lcm);
1507  return;
1508  }
1509  break;
1510  }
1511  }
1512  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1513  {
1514  if(compare == pDivComp_LESS)
1515  {
1516  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1517  {
1518  strat->c3++;
1519  pLmDelete(h.lcm);
1520  return;
1521  }
1522  break;
1523  }
1524  if(compare == pDivComp_GREATER)
1525  {
1526  deleteInL(strat->B,&strat->Bl,j,strat);
1527  strat->c3++;
1528  }
1529  }
1530  }
1531  number s, t;
1532  poly m1, m2, gcd = NULL;
1533  s = pGetCoeff(strat->S[i]);
1534  t = pGetCoeff(p);
1535  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1536  ksCheckCoeff(&s, &t, currRing->cf);
1537  pSetCoeff0(m1, s);
1538  pSetCoeff0(m2, t);
1539  m2 = pNeg(m2);
1540  p_Test(m1,strat->tailRing);
1541  p_Test(m2,strat->tailRing);
1542  poly si = pCopy(strat->S[i]);
1543  poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1544  poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1545  pDelete(&si);
1546  p_LmDelete(m1, currRing);
1547  p_LmDelete(m2, currRing);
1548  if(sim2 == NULL)
1549  {
1550  if(pm1 == NULL)
1551  {
1552  if(h.lcm != NULL)
1553  {
1554  pLmDelete(h.lcm);
1555  h.lcm=NULL;
1556  }
1557  h.Clear();
1558  if (strat->pairtest==NULL) initPairtest(strat);
1559  strat->pairtest[i] = TRUE;
1560  strat->pairtest[strat->sl+1] = TRUE;
1561  return;
1562  }
1563  else
1564  {
1565  gcd = pm1;
1566  pm1 = NULL;
1567  }
1568  }
1569  else
1570  {
1571  if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1572  {
1573  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1574  pSetmComp(sim2);
1575  }
1576  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1577  gcd = p_Add_q(pm1, sim2, strat->tailRing);
1578  }
1579  p_Test(gcd, strat->tailRing);
1580 #ifdef KDEBUG
1581  if (TEST_OPT_DEBUG)
1582  {
1583  wrp(gcd);
1584  PrintLn();
1585  }
1586 #endif
1587  h.p = gcd;
1588  h.i_r = -1;
1589  if(h.p == NULL)
1590  {
1591  if (strat->pairtest==NULL) initPairtest(strat);
1592  strat->pairtest[i] = TRUE;
1593  strat->pairtest[strat->sl+1] = TRUE;
1594  return;
1595  }
1596  h.tailRing = strat->tailRing;
1597  int posx;
1598  //h.pCleardenom();
1599  //pSetm(h.p);
1600  h.i_r1 = -1;h.i_r2 = -1;
1601  strat->initEcart(&h);
1602  #if 1
1603  h.p2 = strat->S[i];
1604  h.p1 = p;
1605  #endif
1606  #if 1
1607  if (atR >= 0)
1608  {
1609  h.i_r1 = atR;
1610  h.i_r2 = strat->S_2_R[i];
1611  }
1612  #endif
1613  if (strat->Bl==-1)
1614  posx =0;
1615  else
1616  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1617  h.sev = pGetShortExpVector(h.p);
1618  if (currRing!=strat->tailRing)
1619  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1620  if (strat->P.p!=NULL) strat->P.sev = pGetShortExpVector(strat->P.p);
1621  else strat->P.sev=0L;
1622  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1623  kTest_TS(strat);
1624 }
1625 
1626 /*2
1627 * put the lcm(s[i],p) into the set B
1628 */
1629 
1630 static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1631 {
1632  number d, s, t;
1633  assume(atR >= 0);
1635  poly m1, m2, gcd,si;
1636  if(!enterTstrong)
1637  {
1638  assume(i<=strat->sl);
1639  si = strat->S[i];
1640  }
1641  else
1642  {
1643  assume(i<=strat->tl);
1644  si = strat->T[i].p;
1645  }
1646  //printf("\n--------------------------------\n");
1647  //pWrite(p);pWrite(si);
1648  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1649 
1650  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1651  {
1652  nDelete(&d);
1653  nDelete(&s);
1654  nDelete(&t);
1655  return FALSE;
1656  }
1657 
1658  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1659 
1661  {
1662  unsigned long sev = pGetShortExpVector(gcd);
1663 
1664  for (int j = 0; j < strat->sl; j++)
1665  {
1666  if (j == i)
1667  continue;
1668 
1669  if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf)
1670  && !(strat->sevS[j] & ~sev)
1671  && p_LmDivisibleBy(strat->S[j], gcd, currRing))
1672  {
1673  nDelete(&d);
1674  nDelete(&s);
1675  nDelete(&t);
1676  return FALSE;
1677  }
1678  }
1679  }
1680 
1681  //p_Test(m1,strat->tailRing);
1682  //p_Test(m2,strat->tailRing);
1683  /*if(!enterTstrong)
1684  {
1685  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1686  {
1687  memset(&(strat->P), 0, sizeof(strat->P));
1688  kStratChangeTailRing(strat);
1689  strat->P = *(strat->R[atR]);
1690  p_LmFree(m1, strat->tailRing);
1691  p_LmFree(m2, strat->tailRing);
1692  p_LmFree(gcd, currRing);
1693  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1694  }
1695  }*/
1696  pSetCoeff0(m1, s);
1697  pSetCoeff0(m2, t);
1698  pSetCoeff0(gcd, d);
1699  p_Test(m1,strat->tailRing);
1700  p_Test(m2,strat->tailRing);
1701  //printf("\n===================================\n");
1702  //pWrite(m1);pWrite(m2);pWrite(gcd);
1703 #ifdef KDEBUG
1704  if (TEST_OPT_DEBUG)
1705  {
1706  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1707  PrintS("m1 = ");
1708  p_wrp(m1, strat->tailRing);
1709  PrintS(" ; m2 = ");
1710  p_wrp(m2, strat->tailRing);
1711  PrintS(" ; gcd = ");
1712  wrp(gcd);
1713  PrintS("\n--- create strong gcd poly: ");
1714  Print("\n p: %d", i);
1715  wrp(p);
1716  Print("\n strat->S[%d]: ", i);
1717  wrp(si);
1718  PrintS(" ---> ");
1719  }
1720 #endif
1721 
1722  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1723  p_LmDelete(m1, strat->tailRing);
1724  p_LmDelete(m2, strat->tailRing);
1725 #ifdef KDEBUG
1726  if (TEST_OPT_DEBUG)
1727  {
1728  wrp(gcd);
1729  PrintLn();
1730  }
1731 #endif
1732 
1733  LObject h;
1734  h.p = gcd;
1735  h.tailRing = strat->tailRing;
1736  int posx;
1737  strat->initEcart(&h);
1738  h.sev = pGetShortExpVector(h.p);
1739  h.i_r1 = -1;h.i_r2 = -1;
1740  if (currRing!=strat->tailRing)
1741  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1742  if(!enterTstrong)
1743  {
1744  #if 1
1745  h.p1 = p;h.p2 = strat->S[i];
1746  #endif
1747  if (atR >= 0)
1748  {
1749  h.i_r2 = strat->S_2_R[i];
1750  h.i_r1 = atR;
1751  }
1752  else
1753  {
1754  h.i_r1 = -1;
1755  h.i_r2 = -1;
1756  }
1757  if (strat->Ll==-1)
1758  posx =0;
1759  else
1760  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1761  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1762  }
1763  else
1764  {
1765  if(h.IsNull()) return FALSE;
1766  //int red_result;
1767  //reduzieren ist teur!!!
1768  //if(strat->L != NULL)
1769  //red_result = strat->red(&h,strat);
1770  if(!h.IsNull())
1771  {
1772  enterT(h, strat,-1);
1773  //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1774  //strat->enterS(h,pos,strat,-1);
1775  }
1776  }
1777  return TRUE;
1778 }
1779 
1781 {
1782  if(strat->sl < 0) return FALSE;
1783  int i;
1784  for(i=0;i<strat->sl;i++)
1785  {
1786  //Construct the gcd pair between h and S[i]
1787  number d, s, t;
1788  poly m1, m2, gcd;
1789  d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1790  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1791  {
1792  nDelete(&d);
1793  nDelete(&s);
1794  nDelete(&t);
1795  }
1796  else
1797  {
1798  k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1799  pSetCoeff0(m1, s);
1800  pSetCoeff0(m2, t);
1801  pSetCoeff0(gcd, d);
1802  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(h->p), m1, strat->tailRing), pp_Mult_mm(pNext(strat->S[i]), m2, strat->tailRing), strat->tailRing);
1803  poly pSigMult = p_Copy(h->sig,currRing);
1804  poly sSigMult = p_Copy(strat->sig[i],currRing);
1805  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1806  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1807  p_LmDelete(m1, strat->tailRing);
1808  p_LmDelete(m2, strat->tailRing);
1809  poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1810  if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1811  {
1812  pDelete(&h->p);
1813  h->p = gcd;
1814  pDelete(&h->sig);
1815  h->sig = pairsig;
1816  pNext(h->sig) = NULL;
1817  strat->initEcart(h);
1818  h->sev = pGetShortExpVector(h->p);
1819  h->sevSig = pGetShortExpVector(h->sig);
1820  h->i_r1 = -1;h->i_r2 = -1;
1821  if(h->lcm != NULL)
1822  {
1823  pLmDelete(h->lcm);
1824  h->lcm = NULL;
1825  }
1826  if (currRing!=strat->tailRing)
1827  h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1828  return TRUE;
1829  }
1830  //Delete what you didn't use
1831  pDelete(&gcd);
1832  pDelete(&pairsig);
1833  }
1834  }
1835  return FALSE;
1836 }
1837 
1838 static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1839 {
1840  number d, s, t;
1841  assume(atR >= 0);
1842  poly m1, m2, gcd,si;
1843  assume(i<=strat->sl);
1844  si = strat->S[i];
1845  //printf("\n--------------------------------\n");
1846  //pWrite(p);pWrite(si);
1847  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1848 
1849  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1850  {
1851  nDelete(&d);
1852  nDelete(&s);
1853  nDelete(&t);
1854  return FALSE;
1855  }
1856 
1857  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1858  //p_Test(m1,strat->tailRing);
1859  //p_Test(m2,strat->tailRing);
1860  /*if(!enterTstrong)
1861  {
1862  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1863  {
1864  memset(&(strat->P), 0, sizeof(strat->P));
1865  kStratChangeTailRing(strat);
1866  strat->P = *(strat->R[atR]);
1867  p_LmFree(m1, strat->tailRing);
1868  p_LmFree(m2, strat->tailRing);
1869  p_LmFree(gcd, currRing);
1870  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1871  }
1872  }*/
1873  pSetCoeff0(m1, s);
1874  pSetCoeff0(m2, t);
1875  pSetCoeff0(gcd, d);
1876  p_Test(m1,strat->tailRing);
1877  p_Test(m2,strat->tailRing);
1878  //printf("\n===================================\n");
1879  //pWrite(m1);pWrite(m2);pWrite(gcd);
1880 #ifdef KDEBUG
1881  if (TEST_OPT_DEBUG)
1882  {
1883  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1884  PrintS("m1 = ");
1885  p_wrp(m1, strat->tailRing);
1886  PrintS(" ; m2 = ");
1887  p_wrp(m2, strat->tailRing);
1888  PrintS(" ; gcd = ");
1889  wrp(gcd);
1890  PrintS("\n--- create strong gcd poly: ");
1891  Print("\n p: %d", i);
1892  wrp(p);
1893  Print("\n strat->S[%d]: ", i);
1894  wrp(si);
1895  PrintS(" ---> ");
1896  }
1897 #endif
1898 
1899  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1900 
1901 #ifdef KDEBUG
1902  if (TEST_OPT_DEBUG)
1903  {
1904  wrp(gcd);
1905  PrintLn();
1906  }
1907 #endif
1908 
1909  //Check and set the signatures
1910  poly pSigMult = p_Copy(sig,currRing);
1911  poly sSigMult = p_Copy(strat->sig[i],currRing);
1912  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1913  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1914  p_LmDelete(m1, strat->tailRing);
1915  p_LmDelete(m2, strat->tailRing);
1916  poly pairsig;
1917  if(pLmCmp(pSigMult,sSigMult) == 0)
1918  {
1919  //Same lm, have to add them
1920  pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1921  //This might be zero
1922  }
1923  else
1924  {
1925  //Set the sig to either pSigMult or sSigMult
1926  if(pLtCmp(pSigMult,sSigMult)==1)
1927  {
1928  pairsig = pSigMult;
1929  pDelete(&sSigMult);
1930  }
1931  else
1932  {
1933  pairsig = sSigMult;
1934  pDelete(&pSigMult);
1935  }
1936  }
1937 
1938  LObject h;
1939  h.p = gcd;
1940  h.tailRing = strat->tailRing;
1941  h.sig = pairsig;
1942  int posx;
1943  strat->initEcart(&h);
1944  h.sev = pGetShortExpVector(h.p);
1945  h.i_r1 = -1;h.i_r2 = -1;
1946  if (currRing!=strat->tailRing)
1947  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1948  if(h.sig == NULL)
1949  {
1950  //sigdrop since we loose the signature
1951  strat->sigdrop = TRUE;
1952  //Try to reduce it as far as we can via redRing
1953  int red_result = redRing(&h,strat);
1954  if(red_result == 0)
1955  {
1956  // Cancel the sigdrop
1957  p_Delete(&h.sig,currRing);h.sig = NULL;
1958  strat->sigdrop = FALSE;
1959  return FALSE;
1960  }
1961  else
1962  {
1963  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1964  #if 1
1965  strat->enterS(h,0,strat,strat->tl);
1966  #endif
1967  return FALSE;
1968  }
1969  }
1970  if(!nGreaterZero(pGetCoeff(h.sig)))
1971  {
1972  h.sig = pNeg(h.sig);
1973  h.p = pNeg(h.p);
1974  }
1975 
1976  if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1977  {
1978  strat->sigdrop = TRUE;
1979  // Completely reduce it
1980  int red_result = redRing(&h,strat);
1981  if(red_result == 0)
1982  {
1983  // Reduced to 0
1984  strat->sigdrop = FALSE;
1985  p_Delete(&h.sig,currRing);h.sig = NULL;
1986  return FALSE;
1987  }
1988  else
1989  {
1990  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1991  // 0 - add just the original poly causing the sigdrop, 1 - add also this
1992  #if 1
1993  strat->enterS(h,0,strat, strat->tl+1);
1994  #endif
1995  return FALSE;
1996  }
1997  }
1998  //Check for sigdrop
1999  if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
2000  {
2001  strat->sigdrop = TRUE;
2002  //Enter this element to S
2003  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2004  strat->enterS(h,strat->sl+1,strat,strat->tl+1);
2005  }
2006  #if 1
2007  h.p1 = p;h.p2 = strat->S[i];
2008  #endif
2009  if (atR >= 0)
2010  {
2011  h.i_r2 = strat->S_2_R[i];
2012  h.i_r1 = atR;
2013  }
2014  else
2015  {
2016  h.i_r1 = -1;
2017  h.i_r2 = -1;
2018  }
2019  if (strat->Ll==-1)
2020  posx =0;
2021  else
2022  posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
2023  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
2024  return TRUE;
2025 }
2026 #endif
2027 
2028 /*2
2029 * put the pair (s[i],p) into the set B, ecart=ecart(p)
2030 */
2031 
2032 void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2033 {
2034  assume(i<=strat->sl);
2035 
2036  int l,j,compare;
2037  LObject Lp;
2038  Lp.i_r = -1;
2039 
2040 #ifdef KDEBUG
2041  Lp.ecart=0; Lp.length=0;
2042 #endif
2043  /*- computes the lcm(s[i],p) -*/
2044  Lp.lcm = pInit();
2045 
2046 #ifndef HAVE_RATGRING
2047  pLcm(p,strat->S[i],Lp.lcm);
2048 #elif defined(HAVE_RATGRING)
2049  if (rIsRatGRing(currRing))
2050  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2051  else
2052  pLcm(p,strat->S[i],Lp.lcm);
2053 #endif
2054  pSetm(Lp.lcm);
2055 
2056 
2057  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
2058  {
2059  if (strat->fromT && (strat->ecartS[i]>ecart))
2060  {
2061  pLmFree(Lp.lcm);
2062  return;
2063  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2064  }
2065  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2066  && pHasNotCF(p,strat->S[i]))
2067  {
2068  /*
2069  *the product criterion has applied for (s,p),
2070  *i.e. lcm(s,p)=product of the leading terms of s and p.
2071  *Suppose (s,r) is in L and the leading term
2072  *of p divides lcm(s,r)
2073  *(==> the leading term of p divides the leading term of r)
2074  *but the leading term of s does not divide the leading term of r
2075  *(notice that tis condition is automatically satisfied if r is still
2076  *in S), then (s,r) can be cancelled.
2077  *This should be done here because the
2078  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2079  *
2080  *Moreover, skipping (s,r) holds also for the noncommutative case.
2081  */
2082  strat->cp++;
2083  pLmFree(Lp.lcm);
2084  return;
2085  }
2086  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2087  /*
2088  *the set B collects the pairs of type (S[j],p)
2089  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2090  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2091  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2092  */
2093  {
2094  j = strat->Bl;
2095  loop
2096  {
2097  if (j < 0) break;
2098  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2099  if ((compare==1)
2100  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2101  {
2102  strat->c3++;
2103  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2104  {
2105  pLmFree(Lp.lcm);
2106  return;
2107  }
2108  break;
2109  }
2110  else
2111  if ((compare ==-1)
2112  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2113  {
2114  deleteInL(strat->B,&strat->Bl,j,strat);
2115  strat->c3++;
2116  }
2117  j--;
2118  }
2119  }
2120  }
2121  else /*sugarcrit*/
2122  {
2123  if (ALLOW_PROD_CRIT(strat))
2124  {
2125  if (strat->fromT && (strat->ecartS[i]>ecart))
2126  {
2127  pLmFree(Lp.lcm);
2128  return;
2129  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2130  }
2131  // if currRing->nc_type!=quasi (or skew)
2132  // TODO: enable productCrit for super commutative algebras...
2133  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2134  pHasNotCF(p,strat->S[i]))
2135  {
2136  /*
2137  *the product criterion has applied for (s,p),
2138  *i.e. lcm(s,p)=product of the leading terms of s and p.
2139  *Suppose (s,r) is in L and the leading term
2140  *of p divides lcm(s,r)
2141  *(==> the leading term of p divides the leading term of r)
2142  *but the leading term of s does not divide the leading term of r
2143  *(notice that tis condition is automatically satisfied if r is still
2144  *in S), then (s,r) can be canceled.
2145  *This should be done here because the
2146  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2147  */
2148  strat->cp++;
2149  pLmFree(Lp.lcm);
2150  return;
2151  }
2152  /*
2153  *the set B collects the pairs of type (S[j],p)
2154  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2155  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2156  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2157  */
2158  for(j = strat->Bl;j>=0;j--)
2159  {
2160  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2161  if (compare==1)
2162  {
2163  strat->c3++;
2164  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2165  {
2166  pLmFree(Lp.lcm);
2167  return;
2168  }
2169  break;
2170  }
2171  else
2172  if (compare ==-1)
2173  {
2174  deleteInL(strat->B,&strat->Bl,j,strat);
2175  strat->c3++;
2176  }
2177  }
2178  }
2179  }
2180  /*
2181  *the pair (S[i],p) enters B if the spoly != 0
2182  */
2183  /*- compute the short s-polynomial -*/
2184  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2185  pNorm(p);
2186 
2187  if ((strat->S[i]==NULL) || (p==NULL))
2188  return;
2189 
2190  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2191  Lp.p=NULL;
2192  else
2193  {
2194  #ifdef HAVE_PLURAL
2195  if ( rIsPluralRing(currRing) )
2196  {
2197  if(pHasNotCF(p, strat->S[i]))
2198  {
2199  if(ncRingType(currRing) == nc_lie)
2200  {
2201  // generalized prod-crit for lie-type
2202  strat->cp++;
2203  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2204  }
2205  else
2206  if( ALLOW_PROD_CRIT(strat) )
2207  {
2208  // product criterion for homogeneous case in SCA
2209  strat->cp++;
2210  Lp.p = NULL;
2211  }
2212  else
2213  {
2214  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2215  nc_CreateShortSpoly(strat->S[i], p, currRing);
2216  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2217  pNext(Lp.p) = strat->tail; // !!!
2218  }
2219  }
2220  else
2221  {
2222  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2223  nc_CreateShortSpoly(strat->S[i], p, currRing);
2224 
2225  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2226  pNext(Lp.p) = strat->tail; // !!!
2227  }
2228  }
2229  else
2230  #endif
2231  {
2233  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2234  }
2235  }
2236  if (Lp.p == NULL)
2237  {
2238  /*- the case that the s-poly is 0 -*/
2239  if (strat->pairtest==NULL) initPairtest(strat);
2240  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2241  strat->pairtest[strat->sl+1] = TRUE;
2242  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2243  /*
2244  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2245  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2246  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2247  *term of p divides the lcm(s,r)
2248  *(this canceling should be done here because
2249  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2250  *the first case is handeled in chainCrit
2251  */
2252  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2253  }
2254  else
2255  {
2256  /*- the pair (S[i],p) enters B -*/
2257  Lp.p1 = strat->S[i];
2258  Lp.p2 = p;
2259 
2260  if (
2262 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2263  )
2264  {
2265  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2266  pNext(Lp.p) = strat->tail; // !!!
2267  }
2268 
2269  if (atR >= 0)
2270  {
2271  Lp.i_r1 = strat->S_2_R[i];
2272  Lp.i_r2 = atR;
2273  }
2274  else
2275  {
2276  Lp.i_r1 = -1;
2277  Lp.i_r2 = -1;
2278  }
2279  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2280 
2282  {
2283  if (!rIsPluralRing(currRing)
2285  && (Lp.p->coef!=NULL))
2286  nDelete(&(Lp.p->coef));
2287  }
2288 
2289  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2290  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2291  }
2292 }
2293 
2294 /// p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
2295 static inline BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2296 {
2297  int i = rVar(r);
2298  loop
2299  {
2300  if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2301  return FALSE;
2302  i--;
2303  if (i == 0)
2304  return TRUE;
2305  }
2306 }
2307 
2308 /*2
2309 * put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2310 * (in the special case: idLift for ideals, i.e. strat->syzComp==1)
2311 * (prod.crit applies)
2312 */
2313 
2314 static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2315 {
2316  assume(ALLOW_PROD_CRIT(strat));
2318  assume(i<=strat->sl);
2319  assume(strat->syzComp==1);
2320 
2321  if ((strat->S[i]==NULL) || (p==NULL))
2322  return;
2323 
2324  int l,j,compare;
2325  LObject Lp;
2326  Lp.i_r = -1;
2327 
2328 #ifdef KDEBUG
2329  Lp.ecart=0; Lp.length=0;
2330 #endif
2331  /*- computes the lcm(s[i],p) -*/
2332  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2333 
2334  if (strat->sugarCrit)
2335  {
2336  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2337  && p_HasNotCF_Lift(p,strat->S[i],currRing))
2338  {
2339  /*
2340  *the product criterion has applied for (s,p),
2341  *i.e. lcm(s,p)=product of the leading terms of s and p.
2342  *Suppose (s,r) is in L and the leading term
2343  *of p divides lcm(s,r)
2344  *(==> the leading term of p divides the leading term of r)
2345  *but the leading term of s does not divide the leading term of r
2346  *(notice that tis condition is automatically satisfied if r is still
2347  *in S), then (s,r) can be cancelled.
2348  *This should be done here because the
2349  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2350  *
2351  *Moreover, skipping (s,r) holds also for the noncommutative case.
2352  */
2353  strat->cp++;
2354  pLmFree(Lp.lcm);
2355  return;
2356  }
2357  else
2358  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2359  if (strat->fromT && (strat->ecartS[i]>ecart))
2360  {
2361  pLmFree(Lp.lcm);
2362  return;
2363  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2364  }
2365  /*
2366  *the set B collects the pairs of type (S[j],p)
2367  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2368  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2369  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2370  */
2371  {
2372  j = strat->Bl;
2373  loop
2374  {
2375  if (j < 0) break;
2376  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2377  if ((compare==1)
2378  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2379  {
2380  strat->c3++;
2381  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2382  {
2383  pLmFree(Lp.lcm);
2384  return;
2385  }
2386  break;
2387  }
2388  else
2389  if ((compare ==-1)
2390  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2391  {
2392  deleteInL(strat->B,&strat->Bl,j,strat);
2393  strat->c3++;
2394  }
2395  j--;
2396  }
2397  }
2398  }
2399  else /*sugarcrit*/
2400  {
2401  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2402  p_HasNotCF_Lift(p,strat->S[i],currRing))
2403  {
2404  /*
2405  *the product criterion has applied for (s,p),
2406  *i.e. lcm(s,p)=product of the leading terms of s and p.
2407  *Suppose (s,r) is in L and the leading term
2408  *of p divides lcm(s,r)
2409  *(==> the leading term of p divides the leading term of r)
2410  *but the leading term of s does not divide the leading term of r
2411  *(notice that tis condition is automatically satisfied if r is still
2412  *in S), then (s,r) can be canceled.
2413  *This should be done here because the
2414  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2415  */
2416  strat->cp++;
2417  pLmFree(Lp.lcm);
2418  return;
2419  }
2420  if (strat->fromT && (strat->ecartS[i]>ecart))
2421  {
2422  pLmFree(Lp.lcm);
2423  return;
2424  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2425  }
2426  /*
2427  *the set B collects the pairs of type (S[j],p)
2428  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2429  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2430  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2431  */
2432  for(j = strat->Bl;j>=0;j--)
2433  {
2434  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2435  if (compare==1)
2436  {
2437  strat->c3++;
2438  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2439  {
2440  pLmFree(Lp.lcm);
2441  return;
2442  }
2443  break;
2444  }
2445  else
2446  if (compare ==-1)
2447  {
2448  deleteInL(strat->B,&strat->Bl,j,strat);
2449  strat->c3++;
2450  }
2451  }
2452  }
2453  /*
2454  *the pair (S[i],p) enters B if the spoly != 0
2455  */
2456  /*- compute the short s-polynomial -*/
2457  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2458  pNorm(p);
2459 
2460  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2461  Lp.p=NULL;
2462  else
2463  {
2465  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2466  }
2467  if (Lp.p == NULL)
2468  {
2469  /*- the case that the s-poly is 0 -*/
2470  if (strat->pairtest==NULL) initPairtest(strat);
2471  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2472  strat->pairtest[strat->sl+1] = TRUE;
2473  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2474  /*
2475  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2476  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2477  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2478  *term of p divides the lcm(s,r)
2479  *(this canceling should be done here because
2480  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2481  *the first case is handeled in chainCrit
2482  */
2483  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2484  }
2485  else
2486  {
2487  /*- the pair (S[i],p) enters B -*/
2488  Lp.p1 = strat->S[i];
2489  Lp.p2 = p;
2490 
2491  pNext(Lp.p) = strat->tail; // !!!
2492 
2493  if (atR >= 0)
2494  {
2495  Lp.i_r1 = strat->S_2_R[i];
2496  Lp.i_r2 = atR;
2497  }
2498  else
2499  {
2500  Lp.i_r1 = -1;
2501  Lp.i_r2 = -1;
2502  }
2503  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2504 
2506  {
2507  if (!rIsPluralRing(currRing)
2509  && (Lp.p->coef!=NULL))
2510  nDelete(&(Lp.p->coef));
2511  }
2512 
2513  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2514  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2515  }
2516 }
2517 
2518 /*2
2519 * put the pair (s[i],p) into the set B, ecart=ecart(p)
2520 * NOTE: here we need to add the signature-based criteria
2521 */
2522 
2523 #ifdef DEBUGF5
2524 static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2525 #else
2526 static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2527 #endif
2528 {
2529  assume(i<=strat->sl);
2530 
2531  int l;
2532  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2533  // the corresponding signatures for criteria checks
2534  LObject Lp;
2535  poly pSigMult = p_Copy(pSig,currRing);
2536  poly sSigMult = p_Copy(strat->sig[i],currRing);
2537  unsigned long pSigMultNegSev,sSigMultNegSev;
2538  Lp.i_r = -1;
2539 
2540 #ifdef KDEBUG
2541  Lp.ecart=0; Lp.length=0;
2542 #endif
2543  /*- computes the lcm(s[i],p) -*/
2544  Lp.lcm = pInit();
2545  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2546 #ifndef HAVE_RATGRING
2547  pLcm(p,strat->S[i],Lp.lcm);
2548 #elif defined(HAVE_RATGRING)
2549  if (rIsRatGRing(currRing))
2550  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2551  else
2552  pLcm(p,strat->S[i],Lp.lcm);
2553 #endif
2554  pSetm(Lp.lcm);
2555 
2556  // set coeffs of multipliers m1 and m2
2557  pSetCoeff0(m1, nInit(1));
2558  pSetCoeff0(m2, nInit(1));
2559 //#if 1
2560 #ifdef DEBUGF5
2561  PrintS("P1 ");
2562  pWrite(pHead(p));
2563  PrintS("P2 ");
2564  pWrite(pHead(strat->S[i]));
2565  PrintS("M1 ");
2566  pWrite(m1);
2567  PrintS("M2 ");
2568  pWrite(m2);
2569 #endif
2570  // get multiplied signatures for testing
2571  pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2572  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2573  sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2574  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2575 
2576 //#if 1
2577 #ifdef DEBUGF5
2578  PrintS("----------------\n");
2579  pWrite(pSigMult);
2580  pWrite(sSigMult);
2581  PrintS("----------------\n");
2582  Lp.checked = 0;
2583 #endif
2584  int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2585 //#if 1
2586 #if DEBUGF5
2587  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2588  pWrite(pSigMult);
2589  pWrite(sSigMult);
2590 #endif
2591  if(sigCmp==0)
2592  {
2593  // printf("!!!! EQUAL SIGS !!!!\n");
2594  // pSig = sSig, delete element due to Rewritten Criterion
2595  pDelete(&pSigMult);
2596  pDelete(&sSigMult);
2597  if (rField_is_Ring(currRing))
2598  pLmDelete(Lp.lcm);
2599  else
2600  pLmFree(Lp.lcm);
2601  pDelete (&m1);
2602  pDelete (&m2);
2603  return;
2604  }
2605  // testing by syzCrit = F5 Criterion
2606  // testing by rewCrit1 = Rewritten Criterion
2607  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2608  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2609  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2610  || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2611  )
2612  {
2613  pDelete(&pSigMult);
2614  pDelete(&sSigMult);
2615  if (rField_is_Ring(currRing))
2616  pLmDelete(Lp.lcm);
2617  else
2618  pLmFree(Lp.lcm);
2619  pDelete (&m1);
2620  pDelete (&m2);
2621  return;
2622  }
2623  /*
2624  *the pair (S[i],p) enters B if the spoly != 0
2625  */
2626  /*- compute the short s-polynomial -*/
2627  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2628  pNorm(p);
2629 
2630  if ((strat->S[i]==NULL) || (p==NULL))
2631  return;
2632 
2633  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2634  Lp.p=NULL;
2635  else
2636  {
2637  #ifdef HAVE_PLURAL
2638  if ( rIsPluralRing(currRing) )
2639  {
2640  if(pHasNotCF(p, strat->S[i]))
2641  {
2642  if(ncRingType(currRing) == nc_lie)
2643  {
2644  // generalized prod-crit for lie-type
2645  strat->cp++;
2646  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2647  }
2648  else
2649  if( ALLOW_PROD_CRIT(strat) )
2650  {
2651  // product criterion for homogeneous case in SCA
2652  strat->cp++;
2653  Lp.p = NULL;
2654  }
2655  else
2656  {
2657  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2658  nc_CreateShortSpoly(strat->S[i], p, currRing);
2659 
2660  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2661  pNext(Lp.p) = strat->tail; // !!!
2662  }
2663  }
2664  else
2665  {
2666  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2667  nc_CreateShortSpoly(strat->S[i], p, currRing);
2668 
2669  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2670  pNext(Lp.p) = strat->tail; // !!!
2671  }
2672  }
2673  else
2674  #endif
2675  {
2677  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2678  }
2679  }
2680  // store from which element this pair comes from for further tests
2681  //Lp.from = strat->sl+1;
2682  if(sigCmp==currRing->OrdSgn)
2683  {
2684  // pSig > sSig
2685  pDelete (&sSigMult);
2686  Lp.sig = pSigMult;
2687  Lp.sevSig = ~pSigMultNegSev;
2688  }
2689  else
2690  {
2691  // pSig < sSig
2692  pDelete (&pSigMult);
2693  Lp.sig = sSigMult;
2694  Lp.sevSig = ~sSigMultNegSev;
2695  }
2696  if (Lp.p == NULL)
2697  {
2698  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2699  int pos = posInSyz(strat, Lp.sig);
2700  enterSyz(Lp, strat, pos);
2701  }
2702  else
2703  {
2704  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2705  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2706  {
2707  pLmFree(Lp.lcm);
2708  pDelete(&Lp.sig);
2709  pDelete (&m1);
2710  pDelete (&m2);
2711  return;
2712  }
2713  // in any case Lp is checked up to the next strat->P which is added
2714  // to S right after this critical pair creation.
2715  // NOTE: this even holds if the 2nd generator gives the bigger signature
2716  // moreover, this improves rewCriterion,
2717  // i.e. strat->checked > strat->from if and only if the 2nd generator
2718  // gives the bigger signature.
2719  Lp.checked = strat->sl+1;
2720  // at this point it is clear that the pair will be added to L, since it has
2721  // passed all tests up to now
2722 
2723  // adds buchberger's first criterion
2724  if (pLmCmp(m2,pHead(p)) == 0)
2725  {
2726  Lp.prod_crit = TRUE; // Product Criterion
2727 #if 0
2728  int pos = posInSyz(strat, Lp.sig);
2729  enterSyz(Lp, strat, pos);
2730  pDelete (&m1);
2731  pDelete (&m2);
2732  return;
2733 #endif
2734  }
2735  pDelete (&m1);
2736  pDelete (&m2);
2737 #if DEBUGF5
2738  PrintS("SIGNATURE OF PAIR: ");
2739  pWrite(Lp.sig);
2740 #endif
2741  /*- the pair (S[i],p) enters B -*/
2742  Lp.p1 = strat->S[i];
2743  Lp.p2 = p;
2744 
2745  if (
2747 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2748  )
2749  {
2750  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2751  pNext(Lp.p) = strat->tail; // !!!
2752  }
2753 
2754  if (atR >= 0)
2755  {
2756  Lp.i_r1 = strat->S_2_R[i];
2757  Lp.i_r2 = atR;
2758  }
2759  else
2760  {
2761  Lp.i_r1 = -1;
2762  Lp.i_r2 = -1;
2763  }
2764  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2765 
2767  {
2768  if (!rIsPluralRing(currRing)
2770  && (Lp.p->coef!=NULL))
2771  nDelete(&(Lp.p->coef));
2772  }
2773 
2774  l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2775  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2776  }
2777 }
2778 
2779 
2780 #ifdef DEBUGF5
2781 static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2782 #else
2783 static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2784 #endif
2785 {
2786  #if ALL_VS_JUST
2787  //Over rings, if we construct the strong pair, do not add the spair
2789  {
2790  number s,t,d;
2791  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2792 
2793  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2794  {
2795  nDelete(&d);
2796  nDelete(&s);
2797  nDelete(&t);
2798  return;
2799  }
2800  nDelete(&d);
2801  nDelete(&s);
2802  nDelete(&t);
2803  }
2804  #endif
2805  assume(i<=strat->sl);
2806  int l;
2807  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2808  // the corresponding signatures for criteria checks
2809  LObject Lp;
2810  poly pSigMult = p_Copy(pSig,currRing);
2811  poly sSigMult = p_Copy(strat->sig[i],currRing);
2812  unsigned long pSigMultNegSev,sSigMultNegSev;
2813  Lp.i_r = -1;
2814 
2815 #ifdef KDEBUG
2816  Lp.ecart=0; Lp.length=0;
2817 #endif
2818  /*- computes the lcm(s[i],p) -*/
2819  Lp.lcm = pInit();
2820  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2821 #ifndef HAVE_RATGRING
2822  pLcm(p,strat->S[i],Lp.lcm);
2823 #elif defined(HAVE_RATGRING)
2824  if (rIsRatGRing(currRing))
2825  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2826  else
2827  pLcm(p,strat->S[i],Lp.lcm);
2828 #endif
2829  pSetm(Lp.lcm);
2830 
2831  // set coeffs of multipliers m1 and m2
2833  {
2834  number s = nCopy(pGetCoeff(strat->S[i]));
2835  number t = nCopy(pGetCoeff(p));
2836  pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2837  ksCheckCoeff(&s, &t, currRing->cf);
2838  pSetCoeff0(m1,s);
2839  pSetCoeff0(m2,t);
2840  }
2841  else
2842  {
2843  pSetCoeff0(m1, nInit(1));
2844  pSetCoeff0(m2, nInit(1));
2845  }
2846 #ifdef DEBUGF5
2847  Print("P1 ");
2848  pWrite(pHead(p));
2849  Print("P2 ");
2850  pWrite(pHead(strat->S[i]));
2851  Print("M1 ");
2852  pWrite(m1);
2853  Print("M2 ");
2854  pWrite(m2);
2855 #endif
2856 
2857  // get multiplied signatures for testing
2858  pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2859  if(pSigMult != NULL)
2860  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2861  sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2862  if(sSigMult != NULL)
2863  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2864 //#if 1
2865 #ifdef DEBUGF5
2866  Print("----------------\n");
2867  pWrite(pSigMult);
2868  pWrite(sSigMult);
2869  Print("----------------\n");
2870  Lp.checked = 0;
2871 #endif
2872  int sigCmp;
2873  if(pSigMult != NULL && sSigMult != NULL)
2874  {
2876  sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2877  else
2878  sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2879  }
2880  else
2881  {
2882  if(pSigMult == NULL)
2883  {
2884  if(sSigMult == NULL)
2885  sigCmp = 0;
2886  else
2887  sigCmp = -1;
2888  }
2889  else
2890  sigCmp = 1;
2891  }
2892 //#if 1
2893 #if DEBUGF5
2894  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2895  pWrite(pSigMult);
2896  pWrite(sSigMult);
2897 #endif
2898  //In the ring case we already build the sig
2900  {
2901  if(sigCmp == 0)
2902  {
2903  //sigdrop since we loose the signature
2904  strat->sigdrop = TRUE;
2905  //Try to reduce it as far as we can via redRing
2907  {
2908  poly p1 = p_Copy(p,currRing);
2909  poly p2 = p_Copy(strat->S[i],currRing);
2910  p1 = p_Mult_mm(p1,m1,currRing);
2911  p2 = p_Mult_mm(p2,m2,currRing);
2912  Lp.p = p_Sub(p1,p2,currRing);
2913  if(Lp.p != NULL)
2914  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2915  }
2916  int red_result = redRing(&Lp,strat);
2917  if(red_result == 0)
2918  {
2919  // Cancel the sigdrop
2920  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2921  strat->sigdrop = FALSE;
2922  return;
2923  }
2924  else
2925  {
2926  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2927  #if 1
2928  strat->enterS(Lp,0,strat,strat->tl);
2929  #endif
2930  return;
2931  }
2932  }
2933  if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2934  {
2935  //Same lm, have to substract
2936  Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2937  }
2938  else
2939  {
2940  if(sigCmp == 1)
2941  {
2942  Lp.sig = pCopy(pSigMult);
2943  }
2944  if(sigCmp == -1)
2945  {
2946  Lp.sig = pNeg(pCopy(sSigMult));
2947  }
2948  }
2949  Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2950  }
2951 
2952  #if 0
2953  if(sigCmp==0)
2954  {
2955  // printf("!!!! EQUAL SIGS !!!!\n");
2956  // pSig = sSig, delete element due to Rewritten Criterion
2957  pDelete(&pSigMult);
2958  pDelete(&sSigMult);
2959  if (rField_is_Ring(currRing))
2960  pLmDelete(Lp.lcm);
2961  else
2962  pLmFree(Lp.lcm);
2963  pDelete (&m1);
2964  pDelete (&m2);
2965  return;
2966  }
2967  #endif
2968  // testing by syzCrit = F5 Criterion
2969  // testing by rewCrit1 = Rewritten Criterion
2970  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2971  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2972  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2973  // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2974  //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2975  )
2976  {
2977  pDelete(&pSigMult);
2978  pDelete(&sSigMult);
2979  if (rField_is_Ring(currRing))
2980  pLmDelete(Lp.lcm);
2981  else
2982  pLmFree(Lp.lcm);
2983  pDelete (&m1);
2984  pDelete (&m2);
2985  return;
2986  }
2987  /*
2988  *the pair (S[i],p) enters B if the spoly != 0
2989  */
2990  /*- compute the short s-polynomial -*/
2991  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2992  pNorm(p);
2993 
2994  if ((strat->S[i]==NULL) || (p==NULL))
2995  return;
2996 
2997  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2998  Lp.p=NULL;
2999  else
3000  {
3001  //Build p
3003  {
3004  poly p1 = p_Copy(p,currRing);
3005  poly p2 = p_Copy(strat->S[i],currRing);
3006  p1 = p_Mult_mm(p1,m1,currRing);
3007  p2 = p_Mult_mm(p2,m2,currRing);
3008  Lp.p = p_Sub(p1,p2,currRing);
3009  if(Lp.p != NULL)
3010  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
3011  }
3012  else
3013  {
3014  #ifdef HAVE_PLURAL
3015  if ( rIsPluralRing(currRing) )
3016  {
3017  if(ncRingType(currRing) == nc_lie)
3018  {
3019  // generalized prod-crit for lie-type
3020  strat->cp++;
3021  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
3022  }
3023  else
3024  if( ALLOW_PROD_CRIT(strat) )
3025  {
3026  // product criterion for homogeneous case in SCA
3027  strat->cp++;
3028  Lp.p = NULL;
3029  }
3030  else
3031  {
3032  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
3033  nc_CreateShortSpoly(strat->S[i], p, currRing);
3034 
3035  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3036  pNext(Lp.p) = strat->tail; // !!!
3037  }
3038  }
3039  else
3040  #endif
3041  {
3043  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
3044  }
3045  }
3046  }
3047  // store from which element this pair comes from for further tests
3048  //Lp.from = strat->sl+1;
3050  {
3051  //Put the sig to be > 0
3052  if(!nGreaterZero(pGetCoeff(Lp.sig)))
3053  {
3054  Lp.sig = pNeg(Lp.sig);
3055  Lp.p = pNeg(Lp.p);
3056  }
3057  }
3058  else
3059  {
3060  if(sigCmp==currRing->OrdSgn)
3061  {
3062  // pSig > sSig
3063  pDelete (&sSigMult);
3064  Lp.sig = pSigMult;
3065  Lp.sevSig = ~pSigMultNegSev;
3066  }
3067  else
3068  {
3069  // pSig < sSig
3070  pDelete (&pSigMult);
3071  Lp.sig = sSigMult;
3072  Lp.sevSig = ~sSigMultNegSev;
3073  }
3074  }
3075  if (Lp.p == NULL)
3076  {
3077  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
3078  int pos = posInSyz(strat, Lp.sig);
3079  enterSyz(Lp, strat, pos);
3080  }
3081  else
3082  {
3083  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
3084  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
3085  {
3086  pLmFree(Lp.lcm);
3087  pDelete(&Lp.sig);
3088  pDelete (&m1);
3089  pDelete (&m2);
3090  return;
3091  }
3092  // in any case Lp is checked up to the next strat->P which is added
3093  // to S right after this critical pair creation.
3094  // NOTE: this even holds if the 2nd generator gives the bigger signature
3095  // moreover, this improves rewCriterion,
3096  // i.e. strat->checked > strat->from if and only if the 2nd generator
3097  // gives the bigger signature.
3098  Lp.checked = strat->sl+1;
3099  // at this point it is clear that the pair will be added to L, since it has
3100  // passed all tests up to now
3101 
3102  // adds buchberger's first criterion
3103  if (pLmCmp(m2,pHead(p)) == 0)
3104  {
3105  Lp.prod_crit = TRUE; // Product Criterion
3106 #if 0
3107  int pos = posInSyz(strat, Lp.sig);
3108  enterSyz(Lp, strat, pos);
3109  pDelete (&m1);
3110  pDelete (&m2);
3111  return;
3112 #endif
3113  }
3114  pDelete (&m1);
3115  pDelete (&m2);
3116 #if DEBUGF5
3117  PrintS("SIGNATURE OF PAIR: ");
3118  pWrite(Lp.sig);
3119 #endif
3120  /*- the pair (S[i],p) enters B -*/
3121  Lp.p1 = strat->S[i];
3122  Lp.p2 = p;
3123 
3124  if (
3126 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3128  )
3129  {
3130  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3131  pNext(Lp.p) = strat->tail; // !!!
3132  }
3133 
3134  if (atR >= 0)
3135  {
3136  Lp.i_r1 = strat->S_2_R[i];
3137  Lp.i_r2 = atR;
3138  }
3139  else
3140  {
3141  Lp.i_r1 = -1;
3142  Lp.i_r2 = -1;
3143  }
3144  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3145 
3147  {
3148  if (!rIsPluralRing(currRing)
3150  && (Lp.p->coef!=NULL))
3151  nDelete(&(Lp.p->coef));
3152  }
3153  // Check for sigdrop
3154  if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3155  {
3156  strat->sigdrop = TRUE;
3157  // Completely reduce it
3158  int red_result = redRing(&Lp,strat);
3159  if(red_result == 0)
3160  {
3161  // Reduced to 0
3162  strat->sigdrop = FALSE;
3163  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3164  return;
3165  }
3166  else
3167  {
3168  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3169  // 0 - add just the original poly causing the sigdrop, 1 - add also this
3170  #if 1
3171  strat->enterS(Lp,0,strat, strat->tl+1);
3172  #endif
3173  return;
3174  }
3175  }
3176  l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3177  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3178  }
3179 }
3180 
3181 /*2
3182 * put the pair (s[i],p) into the set L, ecart=ecart(p)
3183 * in the case that s forms a SB of (s)
3184 */
3185 void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3186 {
3187  //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3188  if(pHasNotCF(p,strat->S[i]))
3189  {
3190  //PrintS("prod-crit\n");
3191  if(ALLOW_PROD_CRIT(strat))
3192  {
3193  //PrintS("prod-crit\n");
3194  strat->cp++;
3195  return;
3196  }
3197  }
3198 
3199  int l;
3200  LObject Lp;
3201  Lp.i_r = -1;
3202 
3203  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3204  /*- compute the short s-polynomial -*/
3205 
3206  #ifdef HAVE_PLURAL
3207  if (rIsPluralRing(currRing))
3208  {
3209  Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3210  }
3211  else
3212  #endif
3213  Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3214 
3215  if (Lp.p == NULL)
3216  {
3217  //PrintS("short spoly==NULL\n");
3218  pLmFree(Lp.lcm);
3219  }
3220  else
3221  {
3222  /*- the pair (S[i],p) enters L -*/
3223  Lp.p1 = strat->S[i];
3224  Lp.p2 = p;
3225  if (atR >= 0)
3226  {
3227  Lp.i_r1 = strat->S_2_R[i];
3228  Lp.i_r2 = atR;
3229  }
3230  else
3231  {
3232  Lp.i_r1 = -1;
3233  Lp.i_r2 = -1;
3234  }
3235  assume(pNext(Lp.p) == NULL);
3236  pNext(Lp.p) = strat->tail;
3237  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3239  {
3240  if (!rIsPluralRing(currRing)
3242  && (Lp.p->coef!=NULL))
3243  nDelete(&(Lp.p->coef));
3244  }
3245  l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3246  //Print("-> L[%d]\n",l);
3247  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3248  }
3249 }
3250 
3251 /*2
3252 * merge set B into L
3253 */
3255 {
3256  int j=strat->Ll+strat->Bl+1;
3257  if (j>strat->Lmax)
3258  {
3259  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3260  enlargeL(&(strat->L),&(strat->Lmax),j);
3261  }
3262  j = strat->Ll;
3263  int i;
3264  for (i=strat->Bl; i>=0; i--)
3265  {
3266  j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3267  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3268  }
3269  strat->Bl = -1;
3270 }
3271 
3272 /*2
3273 * merge set B into L
3274 */
3276 {
3277  int j=strat->Ll+strat->Bl+1;
3278  if (j>strat->Lmax)
3279  {
3280  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3281  enlargeL(&(strat->L),&(strat->Lmax),j);
3282  }
3283  j = strat->Ll;
3284  int i;
3285  for (i=strat->Bl; i>=0; i--)
3286  {
3287  j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3288  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3289  }
3290  strat->Bl = -1;
3291 }
3292 
3293 /*2
3294 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3295 *using the chain-criterion in B and L and enters B to L
3296 */
3297 void chainCritNormal (poly p,int ecart,kStrategy strat)
3298 {
3299  int i,j,l;
3300 
3301  /*
3302  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3303  *In this case all elements in B such
3304  *that their lcm is divisible by the leading term of S[i] can be canceled
3305  */
3306  if (strat->pairtest!=NULL)
3307  {
3308 #ifdef HAVE_SHIFTBBA
3309  // only difference is pLPDivisibleBy instead of pDivisibleBy
3310  if (rIsLPRing(currRing))
3311  {
3312  for (j=0; j<=strat->sl; j++)
3313  {
3314  if (strat->pairtest[j])
3315  {
3316  for (i=strat->Bl; i>=0; i--)
3317  {
3318  if (pLPDivisibleBy(strat->S[j],strat->B[i].lcm))
3319  {
3320  deleteInL(strat->B,&strat->Bl,i,strat);
3321  strat->c3++;
3322  }
3323  }
3324  }
3325  }
3326  }
3327  else
3328 #endif
3329  {
3330  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3331  for (j=0; j<=strat->sl; j++)
3332  {
3333  if (strat->pairtest[j])
3334  {
3335  for (i=strat->Bl; i>=0; i--)
3336  {
3337  if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3338  {
3339  deleteInL(strat->B,&strat->Bl,i,strat);
3340  strat->c3++;
3341  }
3342  }
3343  }
3344  }
3345  }
3346  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3347  strat->pairtest=NULL;
3348  }
3349  if (strat->Gebauer || strat->fromT)
3350  {
3351  if (strat->sugarCrit)
3352  {
3353  /*
3354  *suppose L[j] == (s,r) and p/lcm(s,r)
3355  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3356  *and in case the sugar is o.k. then L[j] can be canceled
3357  */
3358  for (j=strat->Ll; j>=0; j--)
3359  {
3360  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3361  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3362  && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3363  {
3364  if (strat->L[j].p == strat->tail)
3365  {
3366  deleteInL(strat->L,&strat->Ll,j,strat);
3367  strat->c3++;
3368  }
3369  }
3370  }
3371  /*
3372  *this is GEBAUER-MOELLER:
3373  *in B all elements with the same lcm except the "best"
3374  *(i.e. the last one in B with this property) will be canceled
3375  */
3376  j = strat->Bl;
3377  loop /*cannot be changed into a for !!! */
3378  {
3379  if (j <= 0) break;
3380  i = j-1;
3381  loop
3382  {
3383  if (i < 0) break;
3384  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3385  {
3386  strat->c3++;
3387  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3388  {
3389  deleteInL(strat->B,&strat->Bl,i,strat);
3390  j--;
3391  }
3392  else
3393  {
3394  deleteInL(strat->B,&strat->Bl,j,strat);
3395  break;
3396  }
3397  }
3398  i--;
3399  }
3400  j--;
3401  }
3402  }
3403  else /*sugarCrit*/
3404  {
3405  /*
3406  *suppose L[j] == (s,r) and p/lcm(s,r)
3407  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3408  *and in case the sugar is o.k. then L[j] can be canceled
3409  */
3410  for (j=strat->Ll; j>=0; j--)
3411  {
3412  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3413  {
3414  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3415  {
3416  deleteInL(strat->L,&strat->Ll,j,strat);
3417  strat->c3++;
3418  }
3419  }
3420  }
3421  /*
3422  *this is GEBAUER-MOELLER:
3423  *in B all elements with the same lcm except the "best"
3424  *(i.e. the last one in B with this property) will be canceled
3425  */
3426  j = strat->Bl;
3427  loop /*cannot be changed into a for !!! */
3428  {
3429  if (j <= 0) break;
3430  for(i=j-1; i>=0; i--)
3431  {
3432  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3433  {
3434  strat->c3++;
3435  deleteInL(strat->B,&strat->Bl,i,strat);
3436  j--;
3437  }
3438  }
3439  j--;
3440  }
3441  }
3442  /*
3443  *the elements of B enter L
3444  */
3445  kMergeBintoL(strat);
3446  }
3447  else
3448  {
3449  for (j=strat->Ll; j>=0; j--)
3450  {
3451  #ifdef HAVE_SHIFTBBA
3452  if ((strat->L[j].p1!=NULL) &&
3453  pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3454  #else
3455  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3456  #endif
3457  {
3458  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3459  {
3460  deleteInL(strat->L,&strat->Ll,j,strat);
3461  strat->c3++;
3462  }
3463  }
3464  }
3465  /*
3466  *this is our MODIFICATION of GEBAUER-MOELLER:
3467  *First the elements of B enter L,
3468  *then we fix a lcm and the "best" element in L
3469  *(i.e the last in L with this lcm and of type (s,p))
3470  *and cancel all the other elements of type (r,p) with this lcm
3471  *except the case the element (s,r) has also the same lcm
3472  *and is on the worst position with respect to (s,p) and (r,p)
3473  */
3474  /*
3475  *B enters to L/their order with respect to B is permutated for elements
3476  *B[i].p with the same leading term
3477  */
3478  kMergeBintoL(strat);
3479  j = strat->Ll;
3480  loop /*cannot be changed into a for !!! */
3481  {
3482  if (j <= 0)
3483  {
3484  /*now L[0] cannot be canceled any more and the tail can be removed*/
3485  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3486  break;
3487  }
3488  if (strat->L[j].p2 == p)
3489  {
3490  i = j-1;
3491  loop
3492  {
3493  if (i < 0) break;
3494  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3495  {
3496  /*L[i] could be canceled but we search for a better one to cancel*/
3497  strat->c3++;
3498  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3499  && (pNext(strat->L[l].p) == strat->tail)
3500  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3501  && pDivisibleBy(p,strat->L[l].lcm))
3502  {
3503  /*
3504  *"NOT equal(...)" because in case of "equal" the element L[l]
3505  *is "older" and has to be from theoretical point of view behind
3506  *L[i], but we do not want to reorder L
3507  */
3508  strat->L[i].p2 = strat->tail;
3509  /*
3510  *L[l] will be canceled, we cannot cancel L[i] later on,
3511  *so we mark it with "tail"
3512  */
3513  deleteInL(strat->L,&strat->Ll,l,strat);
3514  i--;
3515  }
3516  else
3517  {
3518  deleteInL(strat->L,&strat->Ll,i,strat);
3519  }
3520  j--;
3521  }
3522  i--;
3523  }
3524  }
3525  else if (strat->L[j].p2 == strat->tail)
3526  {
3527  /*now L[j] cannot be canceled any more and the tail can be removed*/
3528  strat->L[j].p2 = p;
3529  }
3530  j--;
3531  }
3532  }
3533 }
3534 /*2
3535 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3536 *without the chain-criterion in B and L and enters B to L
3537 */
3538 void chainCritOpt_1 (poly,int,kStrategy strat)
3539 {
3540  if (strat->pairtest!=NULL)
3541  {
3542  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3543  strat->pairtest=NULL;
3544  }
3545  /*
3546  *the elements of B enter L
3547  */
3548  kMergeBintoL(strat);
3549 }
3550 /*2
3551 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3552 *using the chain-criterion in B and L and enters B to L
3553 */
3554 void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3555 {
3556  int i,j,l;
3557  kMergeBintoLSba(strat);
3558  j = strat->Ll;
3559  loop /*cannot be changed into a for !!! */
3560  {
3561  if (j <= 0)
3562  {
3563  /*now L[0] cannot be canceled any more and the tail can be removed*/
3564  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3565  break;
3566  }
3567  if (strat->L[j].p2 == p)
3568  {
3569  i = j-1;
3570  loop
3571  {
3572  if (i < 0) break;
3573  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3574  {
3575  /*L[i] could be canceled but we search for a better one to cancel*/
3576  strat->c3++;
3577  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3578  && (pNext(strat->L[l].p) == strat->tail)
3579  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3580  && pDivisibleBy(p,strat->L[l].lcm))
3581  {
3582  /*
3583  *"NOT equal(...)" because in case of "equal" the element L[l]
3584  *is "older" and has to be from theoretical point of view behind
3585  *L[i], but we do not want to reorder L
3586  */
3587  strat->L[i].p2 = strat->tail;
3588  /*
3589  *L[l] will be canceled, we cannot cancel L[i] later on,
3590  *so we mark it with "tail"
3591  */
3592  deleteInL(strat->L,&strat->Ll,l,strat);
3593  i--;
3594  }
3595  else
3596  {
3597  deleteInL(strat->L,&strat->Ll,i,strat);
3598  }
3599  j--;
3600  }
3601  i--;
3602  }
3603  }
3604  else if (strat->L[j].p2 == strat->tail)
3605  {
3606  /*now L[j] cannot be canceled any more and the tail can be removed*/
3607  strat->L[j].p2 = p;
3608  }
3609  j--;
3610  }
3611 }
3612 #ifdef HAVE_RATGRING
3613 void chainCritPart (poly p,int ecart,kStrategy strat)
3614 {
3615  int i,j,l;
3616 
3617  /*
3618  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3619  *In this case all elements in B such
3620  *that their lcm is divisible by the leading term of S[i] can be canceled
3621  */
3622  if (strat->pairtest!=NULL)
3623  {
3624  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3625  for (j=0; j<=strat->sl; j++)
3626  {
3627  if (strat->pairtest[j])
3628  {
3629  for (i=strat->Bl; i>=0; i--)
3630  {
3631  if (_p_LmDivisibleByPart(strat->S[j],currRing,
3632  strat->B[i].lcm,currRing,
3633  currRing->real_var_start,currRing->real_var_end))
3634  {
3635  if(TEST_OPT_DEBUG)
3636  {
3637  Print("chain-crit-part: S[%d]=",j);
3638  p_wrp(strat->S[j],currRing);
3639  Print(" divide B[%d].lcm=",i);
3640  p_wrp(strat->B[i].lcm,currRing);
3641  PrintLn();
3642  }
3643  deleteInL(strat->B,&strat->Bl,i,strat);
3644  strat->c3++;
3645  }
3646  }
3647  }
3648  }
3649  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3650  strat->pairtest=NULL;
3651  }
3652  if (strat->Gebauer || strat->fromT)
3653  {
3654  if (strat->sugarCrit)
3655  {
3656  /*
3657  *suppose L[j] == (s,r) and p/lcm(s,r)
3658  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3659  *and in case the sugar is o.k. then L[j] can be canceled
3660  */
3661  for (j=strat->Ll; j>=0; j--)
3662  {
3663  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3664  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3665  && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3666  {
3667  if (strat->L[j].p == strat->tail)
3668  {
3669  if(TEST_OPT_DEBUG)
3670  {
3671  PrintS("chain-crit-part: pCompareChainPart p=");
3672  p_wrp(p,currRing);
3673  Print(" delete L[%d]",j);
3674  p_wrp(strat->L[j].lcm,currRing);
3675  PrintLn();
3676  }
3677  deleteInL(strat->L,&strat->Ll,j,strat);
3678  strat->c3++;
3679  }
3680  }
3681  }
3682  /*
3683  *this is GEBAUER-MOELLER:
3684  *in B all elements with the same lcm except the "best"
3685  *(i.e. the last one in B with this property) will be canceled
3686  */
3687  j = strat->Bl;
3688  loop /*cannot be changed into a for !!! */
3689  {
3690  if (j <= 0) break;
3691  i = j-1;
3692  loop
3693  {
3694  if (i < 0) break;
3695  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3696  {
3697  strat->c3++;
3698  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3699  {
3700  if(TEST_OPT_DEBUG)
3701  {
3702  Print("chain-crit-part: sugar B[%d].lcm=",j);
3703  p_wrp(strat->B[j].lcm,currRing);
3704  Print(" delete B[%d]",i);
3705  p_wrp(strat->B[i].lcm,currRing);
3706  PrintLn();
3707  }
3708  deleteInL(strat->B,&strat->Bl,i,strat);
3709  j--;
3710  }
3711  else
3712  {
3713  if(TEST_OPT_DEBUG)
3714  {
3715  Print("chain-crit-part: sugar B[%d].lcm=",i);
3716  p_wrp(strat->B[i].lcm,currRing);
3717  Print(" delete B[%d]",j);
3718  p_wrp(strat->B[j].lcm,currRing);
3719  PrintLn();
3720  }
3721  deleteInL(strat->B,&strat->Bl,j,strat);
3722  break;
3723  }
3724  }
3725  i--;
3726  }
3727  j--;
3728  }
3729  }
3730  else /*sugarCrit*/
3731  {
3732  /*
3733  *suppose L[j] == (s,r) and p/lcm(s,r)
3734  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3735  *and in case the sugar is o.k. then L[j] can be canceled
3736  */
3737  for (j=strat->Ll; j>=0; j--)
3738  {
3739  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3740  {
3741  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3742  {
3743  if(TEST_OPT_DEBUG)
3744  {
3745  PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3746  p_wrp(p,currRing);
3747  Print(" delete L[%d]",j);
3748  p_wrp(strat->L[j].lcm,currRing);
3749  PrintLn();
3750  }
3751  deleteInL(strat->L,&strat->Ll,j,strat);
3752  strat->c3++;
3753  }
3754  }
3755  }
3756  /*
3757  *this is GEBAUER-MOELLER:
3758  *in B all elements with the same lcm except the "best"
3759  *(i.e. the last one in B with this property) will be canceled
3760  */
3761  j = strat->Bl;
3762  loop /*cannot be changed into a for !!! */
3763  {
3764  if (j <= 0) break;
3765  for(i=j-1; i>=0; i--)
3766  {
3767  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3768  {
3769  if(TEST_OPT_DEBUG)
3770  {
3771  Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3772  p_wrp(strat->B[j].lcm,currRing);
3773  Print(" delete B[%d]\n",i);
3774  }
3775  strat->c3++;
3776  deleteInL(strat->B,&strat->Bl,i,strat);
3777  j--;
3778  }
3779  }
3780  j--;
3781  }
3782  }
3783  /*
3784  *the elements of B enter L
3785  */
3786  kMergeBintoL(strat);
3787  }
3788  else
3789  {
3790  for (j=strat->Ll; j>=0; j--)
3791  {
3792  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3793  {
3794  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3795  {
3796  if(TEST_OPT_DEBUG)
3797  {
3798  PrintS("chain-crit-part: pCompareChainPart p=");
3799  p_wrp(p,currRing);
3800  Print(" delete L[%d]",j);
3801  p_wrp(strat->L[j].lcm,currRing);
3802  PrintLn();
3803  }
3804  deleteInL(strat->L,&strat->Ll,j,strat);
3805  strat->c3++;
3806  }
3807  }
3808  }
3809  /*
3810  *this is our MODIFICATION of GEBAUER-MOELLER:
3811  *First the elements of B enter L,
3812  *then we fix a lcm and the "best" element in L
3813  *(i.e the last in L with this lcm and of type (s,p))
3814  *and cancel all the other elements of type (r,p) with this lcm
3815  *except the case the element (s,r) has also the same lcm
3816  *and is on the worst position with respect to (s,p) and (r,p)
3817  */
3818  /*
3819  *B enters to L/their order with respect to B is permutated for elements
3820  *B[i].p with the same leading term
3821  */
3822  kMergeBintoL(strat);
3823  j = strat->Ll;
3824  loop /*cannot be changed into a for !!! */
3825  {
3826  if (j <= 0)
3827  {
3828  /*now L[0] cannot be canceled any more and the tail can be removed*/
3829  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3830  break;
3831  }
3832  if (strat->L[j].p2 == p)
3833  {
3834  i = j-1;
3835  loop
3836  {
3837  if (i < 0) break;
3838  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3839  {
3840  /*L[i] could be canceled but we search for a better one to cancel*/
3841  strat->c3++;
3842  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3843  && (pNext(strat->L[l].p) == strat->tail)
3844  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3846  strat->L[l].lcm,currRing,
3847  currRing->real_var_start, currRing->real_var_end))
3848 
3849  {
3850  /*
3851  *"NOT equal(...)" because in case of "equal" the element L[l]
3852  *is "older" and has to be from theoretical point of view behind
3853  *L[i], but we do not want to reorder L
3854  */
3855  strat->L[i].p2 = strat->tail;
3856  /*
3857  *L[l] will be canceled, we cannot cancel L[i] later on,
3858  *so we mark it with "tail"
3859  */
3860  if(TEST_OPT_DEBUG)
3861  {
3862  PrintS("chain-crit-part: divisible_by p=");
3863  p_wrp(p,currRing);
3864  Print(" delete L[%d]",l);
3865  p_wrp(strat->L[l].lcm,currRing);
3866  PrintLn();
3867  }
3868  deleteInL(strat->L,&strat->Ll,l,strat);
3869  i--;
3870  }
3871  else
3872  {
3873  if(TEST_OPT_DEBUG)
3874  {
3875  PrintS("chain-crit-part: divisible_by(2) p=");
3876  p_wrp(p,currRing);
3877  Print(" delete L[%d]",i);
3878  p_wrp(strat->L[i].lcm,currRing);
3879  PrintLn();
3880  }
3881  deleteInL(strat->L,&strat->Ll,i,strat);
3882  }
3883  j--;
3884  }
3885  i--;
3886  }
3887  }
3888  else if (strat->L[j].p2 == strat->tail)
3889  {
3890  /*now L[j] cannot be canceled any more and the tail can be removed*/
3891  strat->L[j].p2 = p;
3892  }
3893  j--;
3894  }
3895  }
3896 }
3897 #endif
3898 
3899 /*2
3900 *(s[0],h),...,(s[k],h) will be put to the pairset L
3901 */
3902 void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR/* = -1*/)
3903 {
3904 
3905  if ((strat->syzComp==0)
3906  || (pGetComp(h)<=strat->syzComp))
3907  {
3908  int j;
3909  BOOLEAN new_pair=FALSE;
3910 
3911  if (pGetComp(h)==0)
3912  {
3913  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3914  if ((isFromQ)&&(strat->fromQ!=NULL))
3915  {
3916  for (j=0; j<=k; j++)
3917  {
3918  if (!strat->fromQ[j])
3919  {
3920  new_pair=TRUE;
3921  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3922  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3923  }
3924  }
3925  }
3926  else
3927  {
3928  new_pair=TRUE;
3929  for (j=0; j<=k; j++)
3930  {
3931  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3932  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3933  }
3934  }
3935  }
3936  else
3937  {
3938  for (j=0; j<=k; j++)
3939  {
3940  if ((pGetComp(h)==pGetComp(strat->S[j]))
3941  || (pGetComp(strat->S[j])==0))
3942  {
3943  new_pair=TRUE;
3944  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3945  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3946  }
3947  }
3948  }
3949  if (new_pair)
3950  {
3951  #ifdef HAVE_RATGRING
3952  if (currRing->real_var_start>0)
3953  chainCritPart(h,ecart,strat);
3954  else
3955  #endif
3956  strat->chainCrit(h,ecart,strat);
3957  }
3958  kMergeBintoL(strat);
3959  }
3960 }
3961 
3962 /*2
3963 *(s[0],h),...,(s[k],h) will be put to the pairset L
3964 *using signatures <= only for signature-based standard basis algorithms
3965 */
3966 
3967 void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3968 {
3969 
3970  if ((strat->syzComp==0)
3971  || (pGetComp(h)<=strat->syzComp))
3972  {
3973  int j;
3974  BOOLEAN new_pair=FALSE;
3975 
3976  if (pGetComp(h)==0)
3977  {
3978  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3979  if ((isFromQ)&&(strat->fromQ!=NULL))
3980  {
3981  for (j=0; j<=k; j++)
3982  {
3983  if (!strat->fromQ[j])
3984  {
3985  new_pair=TRUE;
3986  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3987  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3988  }
3989  }
3990  }
3991  else
3992  {
3993  new_pair=TRUE;
3994  for (j=0; j<=k; j++)
3995  {
3996  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3997  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3998  }
3999  }
4000  }
4001  else
4002  {
4003  for (j=0; j<=k; j++)
4004  {
4005  if ((pGetComp(h)==pGetComp(strat->S[j]))
4006  || (pGetComp(strat->S[j])==0))
4007  {
4008  new_pair=TRUE;
4009  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4010  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4011  }
4012  }
4013  }
4014 
4015  if (new_pair)
4016  {
4017 #ifdef HAVE_RATGRING
4018  if (currRing->real_var_start>0)
4019  chainCritPart(h,ecart,strat);
4020  else
4021 #endif
4022  strat->chainCrit(h,ecart,strat);
4023  }
4024  }
4025 }
4026 
4027 void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4028 {
4029 
4030  if ((strat->syzComp==0)
4031  || (pGetComp(h)<=strat->syzComp))
4032  {
4033  int j;
4034 
4035  if (pGetComp(h)==0)
4036  {
4037  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4038  if ((isFromQ)&&(strat->fromQ!=NULL))
4039  {
4040  for (j=0; j<=k && !strat->sigdrop; j++)
4041  {
4042  if (!strat->fromQ[j])
4043  {
4044  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4045  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4046  }
4047  }
4048  }
4049  else
4050  {
4051  for (j=0; j<=k && !strat->sigdrop; j++)
4052  {
4053  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4054  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4055  }
4056  }
4057  }
4058  else
4059  {
4060  for (j=0; j<=k && !strat->sigdrop; j++)
4061  {
4062  if ((pGetComp(h)==pGetComp(strat->S[j]))
4063  || (pGetComp(strat->S[j])==0))
4064  {
4065  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4066  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4067  }
4068  }
4069  }
4070 
4071 #if 0
4072  if (new_pair)
4073  {
4074 #ifdef HAVE_RATGRING
4075  if (currRing->real_var_start>0)
4076  chainCritPart(h,ecart,strat);
4077  else
4078 #endif
4079  strat->chainCrit(h,ecart,strat);
4080  }
4081 #endif
4082  }
4083 }
4084 #ifdef HAVE_RINGS
4085 /*2
4086 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
4087 *using the chain-criterion in B and L and enters B to L
4088 */
4089 void chainCritRing (poly p,int, kStrategy strat)
4090 {
4091  int i,j,l;
4092  /*
4093  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4094  *In this case all elements in B such
4095  *that their lcm is divisible by the leading term of S[i] can be canceled
4096  */
4097  if (strat->pairtest!=NULL)
4098  {
4099  {
4100  /*- i.e. there is an i with pairtest[i]==TRUE -*/
4101  for (j=0; j<=strat->sl; j++)
4102  {
4103  if (strat->pairtest[j])
4104  {
4105  for (i=strat->Bl; i>=0; i--)
4106  {
4107  if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4108  {
4109 #ifdef KDEBUG
4110  if (TEST_OPT_DEBUG)
4111  {
4112  PrintS("--- chain criterion func chainCritRing type 1\n");
4113  PrintS("strat->S[j]:");
4114  wrp(strat->S[j]);
4115  PrintS(" strat->B[i].lcm:");
4116  wrp(strat->B[i].lcm);PrintLn();
4117  pWrite(strat->B[i].p);
4118  pWrite(strat->B[i].p1);
4119  pWrite(strat->B[i].p2);
4120  wrp(strat->B[i].lcm);
4121  PrintLn();
4122  }
4123 #endif
4124  deleteInL(strat->B,&strat->Bl,i,strat);
4125  strat->c3++;
4126  }
4127  }
4128  }
4129  }
4130  }
4131  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4132  strat->pairtest=NULL;
4133  }
4134  assume(!(strat->Gebauer || strat->fromT));
4135  for (j=strat->Ll; j>=0; j--)
4136  {
4137  if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4138  {
4139  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4140  {
4141  if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4142  {
4143  deleteInL(strat->L,&strat->Ll,j,strat);
4144  strat->c3++;
4145 #ifdef KDEBUG
4146  if (TEST_OPT_DEBUG)
4147  {
4148  PrintS("--- chain criterion func chainCritRing type 2\n");
4149  PrintS("strat->L[j].p:");
4150  wrp(strat->L[j].p);
4151  PrintS(" p:");
4152  wrp(p);
4153  PrintLn();
4154  }
4155 #endif
4156  }
4157  }
4158  }
4159  }
4160  /*
4161  *this is our MODIFICATION of GEBAUER-MOELLER:
4162  *First the elements of B enter L,
4163  *then we fix a lcm and the "best" element in L
4164  *(i.e the last in L with this lcm and of type (s,p))
4165  *and cancel all the other elements of type (r,p) with this lcm
4166  *except the case the element (s,r) has also the same lcm
4167  *and is on the worst position with respect to (s,p) and (r,p)
4168  */
4169  /*
4170  *B enters to L/their order with respect to B is permutated for elements
4171  *B[i].p with the same leading term
4172  */
4173  kMergeBintoL(strat);
4174  j = strat->Ll;
4175  loop /*cannot be changed into a for !!! */
4176  {
4177  if (j <= 0)
4178  {
4179  /*now L[0] cannot be canceled any more and the tail can be removed*/
4180  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4181  break;
4182  }
4183  if (strat->L[j].p2 == p) // Was the element added from B?
4184  {
4185  i = j-1;
4186  loop
4187  {
4188  if (i < 0) break;
4189  // Element is from B and has the same lcm as L[j]
4190  if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4191  && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4192  {
4193  /*L[i] could be canceled but we search for a better one to cancel*/
4194  strat->c3++;
4195 #ifdef KDEBUG
4196  if (TEST_OPT_DEBUG)
4197  {
4198  PrintS("--- chain criterion func chainCritRing type 3\n");
4199  PrintS("strat->L[j].lcm:");
4200  wrp(strat->L[j].lcm);
4201  PrintS(" strat->L[i].lcm:");
4202  wrp(strat->L[i].lcm);
4203  PrintLn();
4204  }
4205 #endif
4206  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4207  && (pNext(strat->L[l].p) == strat->tail)
4208  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4209  && pDivisibleBy(p,strat->L[l].lcm))
4210  {
4211  /*
4212  *"NOT equal(...)" because in case of "equal" the element L[l]
4213  *is "older" and has to be from theoretical point of view behind
4214  *L[i], but we do not want to reorder L
4215  */
4216  strat->L[i].p2 = strat->tail;
4217  /*
4218  *L[l] will be canceled, we cannot cancel L[i] later on,
4219  *so we mark it with "tail"
4220  */
4221  deleteInL(strat->L,&strat->Ll,l,strat);
4222  i--;
4223  }
4224  else
4225  {
4226  deleteInL(strat->L,&strat->Ll,i,strat);
4227  }
4228  j--;
4229  }
4230  i--;
4231  }
4232  }
4233  else if (strat->L[j].p2 == strat->tail)
4234  {
4235  /*now L[j] cannot be canceled any more and the tail can be removed*/
4236  strat->L[j].p2 = p;
4237  }
4238  j--;
4239  }
4240 }
4241 #endif
4242 
4243 #ifdef HAVE_RINGS
4244 /*2
4245 *(s[0],h),...,(s[k],h) will be put to the pairset L
4246 */
4247 void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4248 {
4249  if (!nIsOne(pGetCoeff(h)))
4250  {
4251  int j;
4252  BOOLEAN new_pair=FALSE;
4253 
4254  if (pGetComp(h)==0)
4255  {
4256  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4257  if ((isFromQ)&&(strat->fromQ!=NULL))
4258  {
4259  for (j=0; j<=k; j++)
4260  {
4261  if (!strat->fromQ[j])
4262  {
4263  new_pair=TRUE;
4264  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4265  }
4266  }
4267  }
4268  else
4269  {
4270  new_pair=TRUE;
4271  for (j=0; j<=k; j++)
4272  {
4273  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4274  }
4275  }
4276  }
4277  else
4278  {
4279  for (j=0; j<=k; j++)
4280  {
4281  if ((pGetComp(h)==pGetComp(strat->S[j]))
4282  || (pGetComp(strat->S[j])==0))
4283  {
4284  new_pair=TRUE;
4285  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4286  }
4287  }
4288  }
4289  if (new_pair)
4290  {
4291  #ifdef HAVE_RATGRING
4292  if (currRing->real_var_start>0)
4293  chainCritPart(h,ecart,strat);
4294  else
4295  #endif
4296  strat->chainCrit(h,ecart,strat);
4297  }
4298  kMergeBintoL(strat);
4299  }
4300 }
4301 
4302 static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4303 {
4304  const int iCompH = pGetComp(h);
4305  if (!nIsOne(pGetCoeff(h)))
4306  {
4307  int j;
4308 
4309  for (j=0; j<=k && !strat->sigdrop; j++)
4310  {
4311  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4312 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4313 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4314  if (((iCompH == pGetComp(strat->S[j]))
4315  || (0 == pGetComp(strat->S[j])))
4316  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4317  {
4318  enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4319  }
4320  }
4321  }
4322 }
4323 #endif
4324 
4325 #ifdef HAVE_RINGS
4326 /*2
4327 * Generates spoly(0, h) if applicable. Assumes ring in Z/2^n.
4328 */
4330 {
4331  if (nIsOne(pGetCoeff(h))) return;
4332  number gcd;
4333  bool go = false;
4334  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4335  {
4336  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4337  go = true;
4338  }
4339  else
4340  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4341  if (go || !nIsOne(gcd))
4342  {
4343  poly p = h->next;
4344  if (!go)
4345  {
4346  number tmp = gcd;
4347  gcd = n_Ann(gcd,currRing->cf);
4348  nDelete(&tmp);
4349  }
4350  p_Test(p,strat->tailRing);
4351  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4352  nDelete(&gcd);
4353 
4354  if (p != NULL)
4355  {
4356  if (TEST_OPT_PROT)
4357  {
4358  PrintS("Z");
4359  }
4360 #ifdef KDEBUG
4361  if (TEST_OPT_DEBUG)
4362  {
4363  PrintS("--- create zero spoly: ");
4364  p_wrp(h,currRing,strat->tailRing);
4365  PrintS(" ---> ");
4366  }
4367 #endif
4368  poly tmp = pInit();
4369  pSetCoeff0(tmp, pGetCoeff(p));
4370  for (int i = 1; i <= rVar(currRing); i++)
4371  {
4372  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4373  }
4375  {
4376  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4377  }
4378  p_Setm(tmp, currRing);
4379  p = p_LmFreeAndNext(p, strat->tailRing);
4380  pNext(tmp) = p;
4381  LObject Lp;
4382  Lp.Init();
4383  Lp.p = tmp;
4384  Lp.tailRing = strat->tailRing;
4385  int posx;
4386  if (Lp.p!=NULL)
4387  {
4388  strat->initEcart(&Lp);
4389  if (strat->Ll==-1)
4390  posx =0;
4391  else
4392  posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4393  Lp.sev = pGetShortExpVector(Lp.p);
4394  if (strat->tailRing != currRing)
4395  {
4396  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4397  }
4398 #ifdef KDEBUG
4399  if (TEST_OPT_DEBUG)
4400  {
4401  p_wrp(tmp,currRing,strat->tailRing);
4402  PrintLn();
4403  }
4404 #endif
4405  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4406  }
4407  }
4408  }
4409  nDelete(&gcd);
4410 }
4411 
4412 void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
4413 {
4414  if (nIsOne(pGetCoeff(h))) return;
4415  number gcd;
4416  bool go = false;
4417  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4418  {
4419  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4420  go = true;
4421  }
4422  else
4423  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4424  if (go || !nIsOne(gcd))
4425  {
4426  poly p = h->next;
4427  if (!go)
4428  {
4429  number tmp = gcd;
4430  gcd = n_Ann(gcd,currRing->cf);
4431  nDelete(&tmp);
4432  }
4433  p_Test(p,strat->tailRing);
4434  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4435 
4436  if (p != NULL)
4437  {
4438  if (TEST_OPT_PROT)
4439  {
4440  PrintS("Z");
4441  }
4442 #ifdef KDEBUG
4443  if (TEST_OPT_DEBUG)
4444  {
4445  PrintS("--- create zero spoly: ");
4446  p_wrp(h,currRing,strat->tailRing);
4447  PrintS(" ---> ");
4448  }
4449 #endif
4450  poly tmp = pInit();
4451  pSetCoeff0(tmp, pGetCoeff(p));
4452  for (int i = 1; i <= rVar(currRing); i++)
4453  {
4454  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4455  }
4457  {
4458  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4459  }
4460  p_Setm(tmp, currRing);
4461  p = p_LmFreeAndNext(p, strat->tailRing);
4462  pNext(tmp) = p;
4463  LObject Lp;
4464  Lp.Init();
4465  Lp.p = tmp;
4466  //printf("\nOld\n");pWrite(h);pWrite(hSig);
4467  #if EXT_POLY_NEW
4468  Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4469  if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4470  {
4471  strat->sigdrop = TRUE;
4472  //Try to reduce it as far as we can via redRing
4473  int red_result = redRing(&Lp,strat);
4474  if(red_result == 0)
4475  {
4476  // Cancel the sigdrop
4477  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4478  strat->sigdrop = FALSE;
4479  return;
4480  }
4481  else
4482  {
4483  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4484  #if 1
4485  strat->enterS(Lp,0,strat,strat->tl);
4486  #endif
4487  return;
4488  }
4489 
4490  }
4491  #else
4492  Lp.sig = pOne();
4493  if(strat->Ll >= 0)
4494  p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4495  else
4496  p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4497  #endif
4498  Lp.tailRing = strat->tailRing;
4499  int posx;
4500  if (Lp.p!=NULL)
4501  {
4502  strat->initEcart(&Lp);
4503  if (strat->Ll==-1)
4504  posx =0;
4505  else
4506  posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4507  Lp.sev = pGetShortExpVector(Lp.p);
4508  if (strat->tailRing != currRing)
4509  {
4510  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4511  }
4512 #ifdef KDEBUG
4513  if (TEST_OPT_DEBUG)
4514  {
4515  p_wrp(tmp,currRing,strat->tailRing);
4516  PrintLn();
4517  }
4518 #endif
4519  //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4520  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4521  }
4522  }
4523  nDelete(&gcd);
4524  }
4525  nDelete(&gcd);
4526 }
4527 #endif
4528 
4529 #ifdef HAVE_RINGS
4530 void clearSbatch (poly h,int k,int pos,kStrategy strat)
4531 {
4532  int j = pos;
4533  if ( (!strat->fromT)
4534  && ((strat->syzComp==0)
4535  ||(pGetComp(h)<=strat->syzComp)
4536  ))
4537  {
4538  // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4539  unsigned long h_sev = pGetShortExpVector(h);
4540  loop
4541  {
4542  if (j > k) break;
4543  clearS(h,h_sev, &j,&k,strat);
4544  j++;
4545  }
4546  // Print("end clearS sl=%d\n",strat->sl);
4547  }
4548 }
4549 #endif
4550 
4551 #ifdef HAVE_RINGS
4552 /*2
4553 * Generates a sufficient set of spolys (maybe just a finite generating
4554 * set of the syzygys)
4555 */
4556 void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4557 {
4559 #if HAVE_SHIFTBBA
4560  assume(!rIsLPRing(currRing)); /* LP should use enterpairsShift */
4561 #endif
4562  // enter also zero divisor * poly, if this is non zero and of smaller degree
4563  if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat);
4564  initenterstrongPairs(h, k, ecart, 0, strat, atR);
4565  initenterpairs(h, k, ecart, 0, strat, atR);
4566  clearSbatch(h, k, pos, strat);
4567 }
4568 
4569 void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4570 {
4572  // enter also zero divisor * poly, if this is non zero and of smaller degree
4573  if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4574  if(strat->sigdrop) return;
4575  initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4576  if(strat->sigdrop) return;
4577  initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4578  if(strat->sigdrop) return;
4579  clearSbatch(h, k, pos, strat);
4580 }
4581 #endif
4582 
4583 /*2
4584 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4585 *superfluous elements in S will be deleted
4586 */
4587 void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4588 {
4589  int j=pos;
4590 
4592  initenterpairs(h,k,ecart,0,strat, atR);
4593  if ( (!strat->fromT)
4594  && ((strat->syzComp==0)
4595  ||(pGetComp(h)<=strat->syzComp)))
4596  {
4597  unsigned long h_sev = pGetShortExpVector(h);
4598  loop
4599  {
4600  if (j > k) break;
4601  clearS(h,h_sev, &j,&k,strat);
4602  j++;
4603  }
4604  }
4605 }
4606 
4607 /*2
4608 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4609 *superfluous elements in S will be deleted
4610 *this is a special variant of signature-based algorithms including the
4611 *signatures for criteria checks
4612 */
4613 void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4614 {
4615  int j=pos;
4617  initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4618  if ( (!strat->fromT)
4619  && ((strat->syzComp==0)
4620  ||(pGetComp(h)<=strat->syzComp)))
4621  {
4622  unsigned long h_sev = pGetShortExpVector(h);
4623  loop
4624  {
4625  if (j > k) break;
4626  clearS(h,h_sev, &j,&k,strat);
4627  j++;
4628  }
4629  }
4630 }
4631 
4632 /*2
4633 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4634 *superfluous elements in S will be deleted
4635 */
4636 void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4637 {
4638  int j;
4639  const int iCompH = pGetComp(h);
4640 
4641  if (rField_is_Ring(currRing))
4642  {
4643  for (j=0; j<=k; j++)
4644  {
4645  const int iCompSj = pGetComp(strat->S[j]);
4646  if ((iCompH==iCompSj)
4647  //|| (0==iCompH) // can only happen,if iCompSj==0
4648  || (0==iCompSj))
4649  {
4650  enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4651  }
4652  }
4653  kMergeBintoL(strat);
4654  }
4655  else
4656  {
4657  for (j=0; j<=k; j++)
4658  {
4659  const int iCompSj = pGetComp(strat->S[j]);
4660  if ((iCompH==iCompSj)
4661  //|| (0==iCompH) // can only happen,if iCompSj==0
4662  || (0==iCompSj))
4663  {
4664  enterOnePairSpecial(j,h,ecart,strat, atR);
4665  }
4666  }
4667  }
4668 
4669  if (strat->noClearS) return;
4670 
4671 // #ifdef HAVE_PLURAL
4672 /*
4673  if (rIsPluralRing(currRing))
4674  {
4675  j=pos;
4676  loop
4677  {
4678  if (j > k) break;
4679 
4680  if (pLmDivisibleBy(h, strat->S[j]))
4681  {
4682  deleteInS(j, strat);
4683  j--;
4684  k--;
4685  }
4686 
4687  j++;
4688  }
4689  }
4690  else
4691 */
4692 // #endif // ??? Why was the following cancelation disabled for non-commutative rings?
4693  {
4694  j=pos;
4695  loop
4696  {
4697  unsigned long h_sev = pGetShortExpVector(h);
4698  if (j > k) break;
4699  clearS(h,h_sev,&j,&k,strat);
4700  j++;
4701  }
4702  }
4703 }
4704 
4705 /*2
4706 *reorders s with respect to posInS,
4707 *suc is the first changed index or zero
4708 */
4709 
4710 void reorderS (int* suc,kStrategy strat)
4711 {
4712  int i,j,at,ecart, s2r;
4713  int fq=0;
4714  unsigned long sev;
4715  poly p;
4716  int new_suc=strat->sl+1;
4717  i= *suc;
4718  if (i<0) i=0;
4719 
4720  for (; i<=strat->sl; i++)
4721  {
4722  at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4723  if (at != i)
4724  {
4725  if (new_suc > at) new_suc = at;
4726  p = strat->S[i];
4727  ecart = strat->ecartS[i];
4728  sev = strat->sevS[i];
4729  s2r = strat->S_2_R[i];
4730  if (strat->fromQ!=NULL) fq=strat->fromQ[i];
4731  for (j=i; j>=at+1; j--)
4732  {
4733  strat->S[j] = strat->S[j-1];
4734  strat->ecartS[j] = strat->ecartS[j-1];
4735  strat->sevS[j] = strat->sevS[j-1];
4736  strat->S_2_R[j] = strat->S_2_R[j-1];
4737  }
4738  strat->S[at] = p;
4739  strat->ecartS[at] = ecart;
4740  strat->sevS[at] = sev;
4741  strat->S_2_R[at] = s2r;
4742  if (strat->fromQ!=NULL)
4743  {
4744  for (j=i; j>=at+1; j--)
4745  {
4746  strat->fromQ[j] = strat->fromQ[j-1];
4747  }
4748  strat->fromQ[at]=fq;
4749  }
4750  }
4751  }
4752  if (new_suc <= strat->sl) *suc=new_suc;
4753  else *suc=-1;
4754 }
4755 
4756 
4757 /*2
4758 *looks up the position of p in set
4759 *set[0] is the smallest with respect to the ordering-procedure deg/pComp
4760 * Assumption: posInS only depends on the leading term
4761 * otherwise, bba has to be changed
4762 */
4763 int posInS (const kStrategy strat, const int length,const poly p,
4764  const int ecart_p)
4765 {
4766  if(length==-1) return 0;
4767  polyset set=strat->S;
4768  int i;
4769  int an = 0;
4770  int en = length;
4771  int cmp_int = currRing->OrdSgn;
4773 #ifdef HAVE_PLURAL
4774  && (currRing->real_var_start==0)
4775 #endif
4776 #if 0
4777  || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
4778 #endif
4779  )
4780  {
4781  int o=p_Deg(p,currRing);
4782  int oo=p_Deg(set[length],currRing);
4783 
4784  if ((oo<o)
4785  || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
4786  return length+1;
4787 
4788  loop
4789  {
4790  if (an >= en-1)
4791  {
4792  if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
4793  {
4794  return an;
4795  }
4796  return en;
4797  }
4798  i=(an+en) / 2;
4799  if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
4800  else an=i;
4801  }
4802  }
4803  else
4804  {
4805  if (rField_is_Ring(currRing))
4806  {
4807  if (pLmCmp(set[length],p)== -cmp_int)
4808  return length+1;
4809  int cmp;
4810  loop
4811  {
4812  if (an >= en-1)
4813  {
4814  cmp = pLmCmp(set[an],p);
4815  if (cmp == cmp_int) return an;
4816  if (cmp == -cmp_int) return en;
4817  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
4818  return an;
4819  }
4820  i = (an+en) / 2;
4821  cmp = pLmCmp(set[i],p);
4822  if (cmp == cmp_int) en = i;
4823  else if (cmp == -cmp_int) an = i;
4824  else
4825  {
4826  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
4827  else en = i;
4828  }
4829  }
4830  }
4831  else
4832  if (pLmCmp(set[length],p)== -cmp_int)
4833  return length+1;
4834 
4835  loop
4836  {
4837  if (an >= en-1)
4838  {
4839  if (pLmCmp(set[an],p) == cmp_int) return an;
4840  if (pLmCmp(set[an],p) == -cmp_int) return en;
4841  if ((cmp_int!=1)
4842  && ((strat->ecartS[an])>ecart_p))
4843  return an;
4844  return en;
4845  }
4846  i=(an+en) / 2;
4847  if (pLmCmp(set[i],p) == cmp_int) en=i;
4848  else if (pLmCmp(set[i],p) == -cmp_int) an=i;
4849  else
4850  {
4851  if ((cmp_int!=1)
4852  &&((strat->ecartS[i])<ecart_p))
4853  en=i;
4854  else
4855  an=i;
4856  }
4857  }
4858  }
4859 }
4860 
4861 
4862 // sorts by degree and pLtCmp
4863 // but puts pure monomials at the beginning
4864 int posInSMonFirst (const kStrategy strat, const int length,const poly p)
4865 {
4866  if (length<0) return 0;
4867  polyset set=strat->S;
4868  if(pNext(p) == NULL)
4869  {
4870  int mon = 0;
4871  for(int i = 0;i<=length;i++)
4872  {
4873  if(set[i] != NULL && pNext(set[i]) == NULL)
4874  mon++;
4875  }
4876  int o = p_Deg(p,currRing);
4877  int op = p_Deg(set[mon],currRing);
4878 
4879  if ((op < o)
4880  || ((op == o) && (pLtCmp(set[mon],p) == -1)))
4881  return length+1;
4882  int i;
4883  int an = 0;
4884  int en= mon;
4885  loop
4886  {
4887  if (an >= en-1)
4888  {
4889  op = p_Deg(set[an],currRing);
4890  if ((op < o)
4891  || ((op == o) && (pLtCmp(set[an],p) == -1)))
4892  return en;
4893  return an;
4894  }
4895  i=(an+en) / 2;
4896  op = p_Deg(set[i],currRing);
4897  if ((op < o)
4898  || ((op == o) && (pLtCmp(set[i],p) == -1)))
4899  an=i;
4900  else
4901  en=i;
4902  }
4903  }
4904  else /*if(pNext(p) != NULL)*/
4905  {
4906  int o = p_Deg(p,currRing);
4907  int op = p_Deg(set[length],currRing);
4908 
4909  if ((op < o)
4910  || ((op == o) && (pLtCmp(set[length],p) == -1)))
4911  return length+1;
4912  int i;
4913  int an = 0;
4914  for(i=0;i<=length;i++)
4915  if(set[i] != NULL && pNext(set[i]) == NULL)
4916  an++;
4917  int en= length;
4918  loop
4919  {
4920  if (an >= en-1)
4921  {
4922  op = p_Deg(set[an],currRing);
4923  if ((op < o)
4924  || ((op == o) && (pLtCmp(set[an],p) == -1)))
4925  return en;
4926  return an;
4927  }
4928  i=(an+en) / 2;
4929  op = p_Deg(set[i],currRing);
4930  if ((op < o)
4931  || ((op == o) && (pLtCmp(set[i],p) == -1)))
4932  an=i;
4933  else
4934  en=i;
4935  }
4936  }
4937 }
4938 
4939 // sorts by degree and pLtCmp in the block between start,end;
4940 // but puts pure monomials at the beginning
4941 int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
4942 {
4943  if(end < 0 || end >= IDELEMS(F))
4944  end = IDELEMS(F);
4945  if (end<0) return 0;
4946  if(pNext(p) == NULL) return start;
4947  polyset set=F->m;
4948  int o = p_Deg(p,currRing);
4949  int op;
4950  int i;
4951  int an = start;
4952  for(i=start;i<end;i++)
4953  if(set[i] != NULL && pNext(set[i]) == NULL)
4954  an++;
4955  if(an == end-1)
4956  return end;
4957  int en= end;
4958  loop
4959  {
4960  if(an>=en)
4961  return en;
4962  if (an == en-1)
4963  {
4964  op = p_Deg(set[an],currRing);
4965  if ((op < o)
4966  || ((op == o) && (pLtCmp(set[an],p) == -1)))
4967  return en;
4968  return an;
4969  }
4970  i=(an+en) / 2;
4971  op = p_Deg(set[i],currRing);
4972  if ((op < o)
4973  || ((op == o) && (pLtCmp(set[i],p) == -1)))
4974  an=i;
4975  else
4976  en=i;
4977  }
4978 }
4979 
4980 
4981 /*2
4982 * looks up the position of p in set
4983 * the position is the last one
4984 */
4985 int posInT0 (const TSet,const int length,LObject &)
4986 {
4987  return (length+1);
4988 }
4989 
4990 
4991 /*2
4992 * looks up the position of p in T
4993 * set[0] is the smallest with respect to the ordering-procedure
4994 * pComp
4995 */
4996 int posInT1 (const TSet set,const int length,LObject &p)
4997 {
4998  if (length==-1) return 0;
4999 
5000  if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
5001 
5002  int i;
5003  int an = 0;
5004  int en= length;
5005 
5006  loop
5007  {
5008  if (an >= en-1)
5009  {
5010  if (pLmCmp(set[an].p,p.p) == currRing->OrdSgn) return an;
5011  return en;
5012  }
5013  i=(an+en) / 2;
5014  if (pLmCmp(set[i].p,p.p) == currRing->OrdSgn) en=i;
5015  else an=i;
5016  }
5017 }
5018 
5019 /*2
5020 * looks up the position of p in T
5021 * set[0] is the smallest with respect to the ordering-procedure
5022 * length
5023 */
5024 int posInT2 (const TSet set,const int length,LObject &p)
5025 {
5026  if (length==-1) return 0;
5027  p.GetpLength();
5028  if (set[length].length<p.length) return length+1;
5029 
5030  int i;
5031  int an = 0;
5032  int en= length;
5033 
5034  loop
5035  {
5036  if (an >= en-1)
5037  {
5038  if (set[an].length>p.length) return an;
5039  return en;
5040  }
5041  i=(an+en) / 2;
5042  if (set[i].length>p.length) en=i;
5043  else an=i;
5044  }
5045 }
5046 
5047 /*2
5048 * looks up the position of p in T
5049 * set[0] is the smallest with respect to the ordering-procedure
5050 * totaldegree,pComp
5051 */
5052 int posInT11 (const TSet set,const int length,LObject &p)
5053 {
5054  if (length==-1) return 0;
5055 
5056  int o = p.GetpFDeg();
5057  int op = set[length].GetpFDeg();
5058 
5059  if ((op < o)
5060  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5061  return length+1;
5062 
5063  int i;
5064  int an = 0;
5065  int en= length;
5066 
5067  loop
5068  {
5069  if (an >= en-1)
5070  {
5071  op= set[an].GetpFDeg();
5072  if ((op > o)
5073  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5074  return an;
5075  return en;
5076  }
5077  i=(an+en) / 2;
5078  op = set[i].GetpFDeg();
5079  if (( op > o)
5080  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5081  en=i;
5082  else
5083  an=i;
5084  }
5085 }
5086 
5087 #ifdef HAVE_RINGS
5088 int posInT11Ring (const TSet set,const int length,LObject &p)
5089 {
5090  if (length==-1) return 0;
5091 
5092  int o = p.GetpFDeg();
5093  int op = set[length].GetpFDeg();
5094 
5095  if ((op < o)
5096  || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5097  return length+1;
5098 
5099  int i;
5100  int an = 0;
5101  int en= length;
5102 
5103  loop
5104  {
5105  if (an >= en-1)
5106  {
5107  op= set[an].GetpFDeg();
5108  if ((op > o)
5109  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5110  return an;
5111  return en;
5112  }
5113  i=(an+en) / 2;
5114  op = set[i].GetpFDeg();
5115  if (( op > o)
5116  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5117  en=i;
5118  else
5119  an=i;
5120  }
5121 }
5122 #endif
5123 
5124 /*2 Pos for rings T: Here I am
5125 * looks up the position of p in T
5126 * set[0] is the smallest with respect to the ordering-procedure
5127 * totaldegree,pComp
5128 */
5129 int posInTrg0 (const TSet set,const int length,LObject &p)
5130 {
5131  if (length==-1) return 0;
5132  int o = p.GetpFDeg();
5133  int op = set[length].GetpFDeg();
5134  int i;
5135  int an = 0;
5136  int en = length;
5137  int cmp_int = currRing->OrdSgn;
5138  if ((op < o) || (pLmCmp(set[length].p,p.p)== -cmp_int))
5139  return length+1;
5140  int cmp;
5141  loop
5142  {
5143  if (an >= en-1)
5144  {
5145  op = set[an].GetpFDeg();
5146  if (op > o) return an;
5147  if (op < 0) return en;
5148  cmp = pLmCmp(set[an].p,p.p);
5149  if (cmp == cmp_int) return an;
5150  if (cmp == -cmp_int) return en;
5151  if (nGreater(pGetCoeff(p.p), pGetCoeff(set[an].p))) return en;
5152  return an;
5153  }
5154  i = (an + en) / 2;
5155  op = set[i].GetpFDeg();
5156  if (op > o) en = i;
5157  else if (op < o) an = i;
5158  else
5159  {
5160  cmp = pLmCmp(set[i].p,p.p);
5161  if (cmp == cmp_int) en = i;
5162  else if (cmp == -cmp_int) an = i;
5163  else if (nGreater(pGetCoeff(p.p), pGetCoeff(set[i].p))) an = i;
5164  else en = i;
5165  }
5166  }
5167 }
5168 /*
5169  int o = p.GetpFDeg();
5170  int op = set[length].GetpFDeg();
5171 
5172  if ((op < o)
5173  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5174  return length+1;
5175 
5176  int i;
5177  int an = 0;
5178  int en= length;
5179 
5180  loop
5181  {
5182  if (an >= en-1)
5183  {
5184  op= set[an].GetpFDeg();
5185  if ((op > o)
5186  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5187  return an;
5188  return en;
5189  }
5190  i=(an+en) / 2;
5191  op = set[i].GetpFDeg();
5192  if (( op > o)
5193  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5194  en=i;
5195  else
5196  an=i;
5197  }
5198 }
5199  */
5200 /*2
5201 * looks up the position of p in T
5202 * set[0] is the smallest with respect to the ordering-procedure
5203 * totaldegree,pComp
5204 */
5205 int posInT110 (const TSet set,const int length,LObject &p)
5206 {
5207  if (length==-1) return 0;
5208  p.GetpLength();
5209 
5210  int o = p.GetpFDeg();
5211  int op = set[length].GetpFDeg();
5212 
5213  if (( op < o)
5214  || (( op == o) && (set[length].length<p.length))
5215  || (( op == o) && (set[length].length == p.length)
5216  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5217  return length+1;
5218 
5219  int i;
5220  int an = 0;
5221  int en= length;
5222  loop
5223  {
5224  if (an >= en-1)
5225  {
5226  op = set[an].GetpFDeg();
5227  if (( op > o)
5228  || (( op == o) && (set[an].length > p.length))
5229  || (( op == o) && (set[an].length == p.length)
5230  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5231  return an;
5232  return en;
5233  }
5234  i=(an+en) / 2;
5235  op = set[i].GetpFDeg();
5236  if (( op > o)
5237  || (( op == o) && (set[i].length > p.length))
5238  || (( op == o) && (set[i].length == p.length)
5239  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5240  en=i;
5241  else
5242  an=i;
5243  }
5244 }
5245 
5246 #ifdef HAVE_RINGS
5247 int posInT110Ring (const TSet set,const int length,LObject &p)
5248 {
5249  if (length==-1) return 0;
5250  p.GetpLength();
5251 
5252  int o = p.GetpFDeg();
5253  int op = set[length].GetpFDeg();
5254 
5255  if (( op < o)
5256  || (( op == o) && (set[length].length<p.length))
5257  || (( op == o) && (set[length].length == p.length)
5258  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5259  return length+1;
5260 
5261  int i;
5262  int an = 0;
5263  int en= length;
5264  loop
5265  {
5266  if (an >= en-1)
5267  {
5268  op = set[an].GetpFDeg();
5269  if (( op > o)
5270  || (( op == o) && (set[an].length > p.length))
5271  || (( op == o) && (set[an].length == p.length)
5272  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5273  return an;
5274  return en;
5275  }
5276  i=(an+en) / 2;
5277  op = set[i].GetpFDeg();
5278  if (( op > o)
5279  || (( op == o) && (set[i].length > p.length))
5280  || (( op == o) && (set[i].length == p.length)
5281  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5282  en=i;
5283  else
5284  an=i;
5285  }
5286 }
5287 #endif
5288 
5289 /*2
5290 * looks up the position of p in set
5291 * set[0] is the smallest with respect to the ordering-procedure
5292 * pFDeg
5293 */
5294 int posInT13 (const TSet set,const int length,LObject &p)
5295 {
5296  if (length==-1) return 0;
5297 
5298  int o = p.GetpFDeg();
5299 
5300  if (set[length].GetpFDeg() <= o)
5301  return length+1;
5302 
5303  int i;
5304  int an = 0;
5305  int en= length;
5306  loop
5307  {
5308  if (an >= en-1)
5309  {
5310  if (set[an].GetpFDeg() > o)
5311  return an;
5312  return en;
5313  }
5314  i=(an+en) / 2;
5315  if (set[i].GetpFDeg() > o)
5316  en=i;
5317  else
5318  an=i;
5319  }
5320 }
5321 
5322 // determines the position based on: 1.) Ecart 2.) pLength
5323 int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5324 {
5325  if (length==-1) return 0;
5326  int ol = p.GetpLength();
5327  int op=p.ecart;
5328  int oo=set[length].ecart;
5329 
5330  if ((oo < op) || ((oo==op) && (set[length].length <= ol)))
5331  return length+1;
5332 
5333  int i;
5334  int an = 0;
5335  int en= length;
5336  loop
5337  {
5338  if (an >= en-1)
5339  {
5340  int oo=set[an].ecart;
5341  if((oo > op)
5342  || ((oo==op) && (set[an].pLength > ol)))
5343  return an;
5344  return en;
5345  }
5346  i=(an+en) / 2;
5347  int oo=set[i].ecart;
5348  if ((oo > op)
5349  || ((oo == op) && (set[i].pLength > ol)))
5350  en=i;
5351  else
5352  an=i;
5353  }
5354 }
5355 
5356 /*2
5357 * looks up the position of p in set
5358 * set[0] is the smallest with respect to the ordering-procedure
5359 * maximaldegree, pComp
5360 */
5361 int posInT15 (const TSet set,const int length,LObject &p)
5362 /*{
5363  *int j=0;
5364  * int o;
5365  *
5366  * o = p.GetpFDeg()+p.ecart;
5367  * loop
5368  * {
5369  * if ((set[j].GetpFDeg()+set[j].ecart > o)
5370  * || ((set[j].GetpFDeg()+set[j].ecart == o)
5371  * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5372  * {
5373  * return j;
5374  * }
5375  * j++;
5376  * if (j > length) return j;
5377  * }
5378  *}
5379  */
5380 {
5381  if (length==-1) return 0;
5382 
5383  int o = p.GetpFDeg() + p.ecart;
5384  int op = set[length].GetpFDeg()+set[length].ecart;
5385 
5386  if ((op < o)
5387  || ((op == o)
5388  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5389  return length+1;
5390 
5391  int i;
5392  int an = 0;
5393  int en= length;
5394  loop
5395  {
5396  if (an >= en-1)
5397  {
5398  op = set[an].GetpFDeg()+set[an].ecart;
5399  if (( op > o)
5400  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5401  return an;
5402  return en;
5403  }
5404  i=(an+en) / 2;
5405  op = set[i].GetpFDeg()+set[i].ecart;
5406  if (( op > o)
5407  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5408  en=i;
5409  else
5410  an=i;
5411  }
5412 }
5413 
5414 #ifdef HAVE_RINGS
5415 int posInT15Ring (const TSet set,const int length,LObject &p)
5416 {
5417  if (length==-1) return 0;
5418 
5419  int o = p.GetpFDeg() + p.ecart;
5420  int op = set[length].GetpFDeg()+set[length].ecart;
5421 
5422  if ((op < o)
5423  || ((op == o)
5424  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5425  return length+1;
5426 
5427  int i;
5428  int an = 0;
5429  int en= length;
5430  loop
5431  {
5432  if (an >= en-1)
5433  {
5434  op = set[an].GetpFDeg()+set[an].ecart;
5435  if (( op > o)
5436  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5437  return an;
5438  return en;
5439  }
5440  i=(an+en) / 2;
5441  op = set[i].GetpFDeg()+set[i].ecart;
5442  if (( op > o)
5443  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5444  en=i;
5445  else
5446  an=i;
5447  }
5448 }
5449 #endif
5450 
5451 /*2
5452 * looks up the position of p in set
5453 * set[0] is the smallest with respect to the ordering-procedure
5454 * pFDeg+ecart, ecart, pComp
5455 */
5456 int posInT17 (const TSet set,const int length,LObject &p)
5457 /*
5458 *{
5459 * int j=0;
5460 * int o;
5461 *
5462 * o = p.GetpFDeg()+p.ecart;
5463 * loop
5464 * {
5465 * if ((pFDeg(set[j].p)+set[j].ecart > o)
5466 * || (((pFDeg(set[j].p)+set[j].ecart == o)
5467 * && (set[j].ecart < p.ecart)))
5468 * || ((pFDeg(set[j].p)+set[j].ecart == o)
5469 * && (set[j].ecart==p.ecart)
5470 * && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5471 * return j;
5472 * j++;
5473 * if (j > length) return j;
5474 * }
5475 * }
5476 */
5477 {
5478  if (length==-1) return 0;
5479 
5480  int o = p.GetpFDeg() + p.ecart;
5481  int op = set[length].GetpFDeg()+set[length].ecart;
5482 
5483  if ((op < o)
5484  || (( op == o) && (set[length].ecart > p.ecart))
5485  || (( op == o) && (set[length].ecart==p.ecart)
5486  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5487  return length+1;
5488 
5489  int i;
5490  int an = 0;
5491  int en= length;
5492  loop
5493  {
5494  if (an >= en-1)
5495  {
5496  op = set[an].GetpFDeg()+set[an].ecart;
5497  if (( op > o)
5498  || (( op == o) && (set[an].ecart < p.ecart))
5499  || (( op == o) && (set[an].ecart==p.ecart)
5500  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5501  return an;
5502  return en;
5503  }
5504  i=(an+en) / 2;
5505  op = set[i].GetpFDeg()+set[i].ecart;
5506  if ((op > o)
5507  || (( op == o) && (set[i].ecart < p.ecart))
5508  || (( op == o) && (set[i].ecart == p.ecart)
5509  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5510  en=i;
5511  else
5512  an=i;
5513  }
5514 }
5515 
5516 #ifdef HAVE_RINGS
5517 int posInT17Ring (const TSet set,const int length,LObject &p)
5518 {
5519  if (length==-1) return 0;
5520 
5521  int o = p.GetpFDeg() + p.ecart;
5522  int op = set[length].GetpFDeg()+set[length].ecart;
5523 
5524  if ((op < o)
5525  || (( op == o) && (set[length].ecart > p.ecart))
5526  || (( op == o) && (set[length].ecart==p.ecart)
5527  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5528  return length+1;
5529 
5530  int i;
5531  int an = 0;
5532  int en= length;
5533  loop
5534  {
5535  if (an >= en-1)
5536  {
5537  op = set[an].GetpFDeg()+set[an].ecart;
5538  if (( op > o)
5539  || (( op == o) && (set[an].ecart < p.ecart))
5540  || (( op == o) && (set[an].ecart==p.ecart)
5541  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5542  return an;
5543  return en;
5544  }
5545  i=(an+en) / 2;
5546  op = set[i].GetpFDeg()+set[i].ecart;
5547  if ((op > o)
5548  || (( op == o) && (set[i].ecart < p.ecart))
5549  || (( op == o) && (set[i].ecart == p.ecart)
5550  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5551  en=i;
5552  else
5553  an=i;
5554  }
5555 }
5556 #endif
5557 
5558 /*2
5559 * looks up the position of p in set
5560 * set[0] is the smallest with respect to the ordering-procedure
5561 * pGetComp, pFDeg+ecart, ecart, pComp
5562 */
5563 int posInT17_c (const TSet set,const int length,LObject &p)
5564 {
5565  if (length==-1) return 0;
5566 
5567  int cc = (-1+2*currRing->order[0]==ringorder_c);
5568  /* cc==1 for (c,..), cc==-1 for (C,..) */
5569  int o = p.GetpFDeg() + p.ecart;
5570  int c = pGetComp(p.p)*cc;
5571 
5572  if (pGetComp(set[length].p)*cc < c)
5573  return length+1;
5574  if (pGetComp(set[length].p)*cc == c)
5575  {
5576  int op = set[length].GetpFDeg()+set[length].ecart;
5577  if ((op < o)
5578  || ((op == o) && (set[length].ecart > p.ecart))
5579  || ((op == o) && (set[length].ecart==p.ecart)
5580  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5581  return length+1;
5582  }
5583 
5584  int i;
5585  int an = 0;
5586  int en= length;
5587  loop
5588  {
5589  if (an >= en-1)
5590  {
5591  if (pGetComp(set[an].p)*cc < c)
5592  return en;
5593  if (pGetComp(set[an].p)*cc == c)
5594  {
5595  int op = set[an].GetpFDeg()+set[an].ecart;
5596  if ((op > o)
5597  || ((op == o) && (set[an].ecart < p.ecart))
5598  || ((op == o) && (set[an].ecart==p.ecart)
5599  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5600  return an;
5601  }
5602  return en;
5603  }
5604  i=(an+en) / 2;
5605  if (pGetComp(set[i].p)*cc > c)
5606  en=i;
5607  else if (pGetComp(set[i].p)*cc == c)
5608  {
5609  int op = set[i].GetpFDeg()+set[i].ecart;
5610  if ((op > o)
5611  || ((op == o) && (set[i].ecart < p.ecart))
5612  || ((op == o) && (set[i].ecart == p.ecart)
5613  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5614  en=i;
5615  else
5616  an=i;
5617  }
5618  else
5619  an=i;
5620  }
5621 }
5622 
5623 #ifdef HAVE_RINGS
5624 int posInT17_cRing (const TSet set,const int length,LObject &p)
5625 {
5626  if (length==-1) return 0;
5627 
5628  int cc = (-1+2*currRing->order[0]==ringorder_c);
5629  /* cc==1 for (c,..), cc==-1 for (C,..) */
5630  int o = p.GetpFDeg() + p.ecart;
5631  int c = pGetComp(p.p)*cc;
5632 
5633  if (pGetComp(set[length].p)*cc < c)
5634  return length+1;
5635  if (pGetComp(set[length].p)*cc == c)
5636  {
5637  int op = set[length].GetpFDeg()+set[length].ecart;
5638  if ((op < o)
5639  || ((op == o) && (set[length].ecart > p.ecart))
5640  || ((op == o) && (set[length].ecart==p.ecart)
5641  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5642  return length+1;
5643  }
5644 
5645  int i;
5646  int an = 0;
5647  int en= length;
5648  loop
5649  {
5650  if (an >= en-1)
5651  {
5652  if (pGetComp(set[an].p)*cc < c)
5653  return en;
5654  if (pGetComp(set[an].p)*cc == c)
5655  {
5656  int op = set[an].GetpFDeg()+set[an].ecart;
5657  if ((op > o)
5658  || ((op == o) && (set[an].ecart < p.ecart))
5659  || ((op == o) && (set[an].ecart==p.ecart)
5660  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5661  return an;
5662  }
5663  return en;
5664  }
5665  i=(an+en) / 2;
5666  if (pGetComp(set[i].p)*cc > c)
5667  en=i;
5668  else if (pGetComp(set[i].p)*cc == c)
5669  {
5670  int op = set[i].GetpFDeg()+set[i].ecart;
5671  if ((op > o)
5672  || ((op == o) && (set[i].ecart < p.ecart))
5673  || ((op == o) && (set[i].ecart == p.ecart)
5674  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5675  en=i;
5676  else
5677  an=i;
5678  }
5679  else
5680  an=i;
5681  }
5682 }
5683 #endif
5684 
5685 /*2
5686 * looks up the position of p in set
5687 * set[0] is the smallest with respect to
5688 * ecart, pFDeg, length
5689 */
5690 int posInT19 (const TSet set,const int length,LObject &p)
5691 {
5692  p.GetpLength();
5693  if (length==-1) return 0;
5694 
5695  int o = p.ecart;
5696  int op=p.GetpFDeg();
5697 
5698  if (set[length].ecart < o)
5699  return length+1;
5700  if (set[length].ecart == o)
5701  {
5702  int oo=set[length].GetpFDeg();
5703  if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5704  return length+1;
5705  }
5706 
5707  int i;
5708  int an = 0;
5709  int en= length;
5710  loop
5711  {
5712  if (an >= en-1)
5713  {
5714  if (set[an].ecart > o)
5715  return an;
5716  if (set[an].ecart == o)
5717  {
5718  int oo=set[an].GetpFDeg();
5719  if((oo > op)
5720  || ((oo==op) && (set[an].length > p.length)))
5721  return an;
5722  }
5723  return en;
5724  }
5725  i=(an+en) / 2;
5726  if (set[i].ecart > o)
5727  en=i;
5728  else if (set[i].ecart == o)
5729  {
5730  int oo=set[i].GetpFDeg();
5731  if ((oo > op)
5732  || ((oo == op) && (set[i].length > p.length)))
5733  en=i;
5734  else
5735  an=i;
5736  }
5737  else
5738  an=i;
5739  }
5740 }
5741 
5742 /*2
5743 *looks up the position of polynomial p in set
5744 *set[length] is the smallest element in set with respect
5745 *to the ordering-procedure pComp
5746 */
5747 int posInLSpecial (const LSet set, const int length,
5748  LObject *p,const kStrategy)
5749 {
5750  if (length<0) return 0;
5751 
5752  int d=p->GetpFDeg();
5753  int op=set[length].GetpFDeg();
5754 
5755  if ((op > d)
5756  || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
5757  || (pLmCmp(set[length].p,p->p)== currRing->OrdSgn))
5758  return length+1;
5759 
5760  int i;
5761  int an = 0;
5762  int en= length;
5763  loop
5764  {
5765  if (an >= en-1)
5766  {
5767  op=set[an].GetpFDeg();
5768  if ((op > d)
5769  || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
5770  || (pLmCmp(set[an].p,p->p)== currRing->OrdSgn))
5771  return en;
5772  return an;
5773  }
5774  i=(an+en) / 2;
5775  op=set[i].GetpFDeg();
5776  if ((op>d)
5777  || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
5778  || (pLmCmp(set[i].p,p->p) == currRing->OrdSgn))
5779  an=i;
5780  else
5781  en=i;
5782  }
5783 }
5784 
5785 /*2
5786 *looks up the position of polynomial p in set
5787 *set[length] is the smallest element in set with respect
5788 *to the ordering-procedure pComp
5789 */
5790 int posInL0 (const LSet set, const int length,
5791  LObject* p,const kStrategy)
5792 {
5793  if (length<0) return 0;
5794 
5795  if (pLmCmp(set[length].p,p->p)== currRing->OrdSgn)
5796  return length+1;
5797 
5798  int i;
5799  int an = 0;
5800  int en= length;
5801  loop
5802  {
5803  if (an >= en-1)
5804  {
5805  if (pLmCmp(set[an].p,p->p) == currRing->OrdSgn) return en;
5806  return an;
5807  }
5808  i=(an+en) / 2;
5809  if (pLmCmp(set[i].p,p->p) == currRing->OrdSgn) an=i;
5810  else en=i;
5811  /*aend. fuer lazy == in !=- machen */
5812  }
5813 }
5814 
5815 #ifdef HAVE_RINGS
5816 int posInL0Ring (const LSet set, const int length,
5817  LObject* p,const kStrategy)
5818 {
5819  if (length<0) return 0;
5820 
5821  if (pLtCmpOrdSgnEqP(set[length].p,p->p))
5822  return length+1;
5823 
5824  int i;
5825  int an = 0;
5826  int en= length;
5827  loop
5828  {
5829  if (an >= en-1)
5830  {
5831  if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
5832  return an;
5833  }
5834  i=(an+en) / 2;
5835  if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
5836  else en=i;
5837  /*aend. fuer lazy == in !=- machen */
5838  }
5839 }
5840 #endif
5841 
5842 /*2
5843 * looks up the position of polynomial p in set
5844 * e is the ecart of p
5845 * set[length] is the smallest element in set with respect
5846 * to the signature order
5847 */
5848 int posInLSig (const LSet set, const int length,
5849  LObject* p,const kStrategy /*strat*/)
5850 {
5851  if (length<0) return 0;
5852  if (pLtCmp(set[length].sig,p->sig)== currRing->OrdSgn)
5853  return length+1;
5854 
5855  int i;
5856  int an = 0;
5857  int en= length;
5858  loop
5859  {
5860  if (an >= en-1)
5861  {
5862  if (pLtCmp(set[an].sig,p->sig) == currRing->OrdSgn) return en;
5863  return an;
5864  }
5865  i=(an+en) / 2;
5866  if (pLtCmp(set[i].sig,p->sig) == currRing->OrdSgn) an=i;
5867  else en=i;
5868  /*aend. fuer lazy == in !=- machen */
5869  }
5870 }
5871 //sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
5872 int posInLSigRing (const LSet set, const int length,
5873  LObject* p,const kStrategy /*strat*/)
5874 {
5875  assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
5876  if (length<0) return 0;
5877  if (pLtCmp(set[length].sig,p->sig)== 1)
5878  return length+1;
5879 
5880  int an,en,i;
5881  an = 0;
5882  en = length+1;
5883  int cmp;
5884  loop
5885  {
5886  if (an >= en-1)
5887  {
5888  if(an == en)
5889  return en;
5890  cmp = pLtCmp(set[an].sig,p->sig);
5891  if (cmp == 1)
5892  return en;
5893  if (cmp == -1)
5894  return an;
5895  if (cmp == 0)
5896  {
5897  if (set[an].FDeg > p->FDeg)
5898  return en;
5899  if (set[an].FDeg < p->FDeg)
5900  return an;
5901  if (set[an].FDeg == p->FDeg)
5902  {
5903  cmp = pLtCmp(set[an].p,p->p);
5904  if(cmp == 1)
5905  return en;
5906  else
5907  return an;
5908  }
5909  }
5910  }
5911  i=(an+en) / 2;
5912  cmp = pLtCmp(set[i].sig,p->sig);
5913  if (cmp == 1)
5914  an = i;
5915  if (cmp == -1)
5916  en = i;
5917  if (cmp == 0)
5918  {
5919  if (set[i].FDeg > p->FDeg)
5920  an = i;
5921  if (set[i].FDeg < p->FDeg)
5922  en = i;
5923  if (set[i].FDeg == p->FDeg)
5924  {
5925  cmp = pLtCmp(set[i].p,p->p);
5926  if(cmp == 1)
5927  an = i;
5928  else
5929  en = i;
5930  }
5931  }
5932  }
5933 }
5934 
5935 int posInLRing (const LSet set, const int length,
5936  LObject* p,const kStrategy /*strat*/)
5937 {
5938  if (length < 0) return 0;
5939  if (set[length].FDeg > p->FDeg)
5940  return length+1;
5941  if (set[length].FDeg == p->FDeg)
5942  if(set[length].GetpLength() > p->GetpLength())
5943  return length+1;
5944  int i;
5945  int an = 0;
5946  int en= length+1;
5947  loop
5948  {
5949  if (an >= en-1)
5950  {
5951  if(an == en)
5952  return en;
5953  if (set[an].FDeg > p->FDeg)
5954  return en;
5955  if(set[an].FDeg == p->FDeg)
5956  {
5957  if(set[an].GetpLength() > p->GetpLength())
5958  return en;
5959  else
5960  {
5961  if(set[an].GetpLength() == p->GetpLength())
5962  {
5963  if(nGreater(set[an].p->coef, p->p->coef))
5964  return en;
5965  else
5966  return an;
5967  }
5968  else
5969  {
5970  return an;
5971  }
5972  }
5973  }
5974  else
5975  return an;
5976  }
5977  i=(an+en) / 2;
5978  if (set[i].FDeg > p->FDeg)
5979  an=i;
5980  else
5981  {
5982  if(set[i].FDeg == p->FDeg)
5983  {
5984  if(set[i].GetpLength() > p->GetpLength())
5985  an=i;
5986  else
5987  {
5988  if(set[i].GetpLength() == p->GetpLength())
5989  {
5990  if(nGreater(set[i].p->coef, p->p->coef))
5991  an = i;
5992  else
5993  en = i;
5994  }
5995  else
5996  {
5997  en=i;
5998  }
5999  }
6000  }
6001  else
6002  en=i;
6003  }
6004  }
6005 }
6006 
6007 // for sba, sorting syzygies
6008 int posInSyz (const kStrategy strat, poly sig)
6009 {
6010  if (strat->syzl==0) return 0;
6011  if (pLtCmp(strat->syz[strat->syzl-1],sig) != currRing->OrdSgn)
6012  return strat->syzl;
6013  int i;
6014  int an = 0;
6015  int en= strat->syzl-1;
6016  loop
6017  {
6018  if (an >= en-1)
6019  {
6020  if (pLtCmp(strat->syz[an],sig) != currRing->OrdSgn) return en;
6021  return an;
6022  }
6023  i=(an+en) / 2;
6024  if (pLtCmp(strat->syz[i],sig) != currRing->OrdSgn) an=i;
6025  else en=i;
6026  /*aend. fuer lazy == in !=- machen */
6027  }
6028 }
6029 
6030 /*2
6031 *
6032 * is only used in F5C, must ensure that the interreduction process does add new
6033 * critical pairs to strat->L only behind all other critical pairs which are
6034 * still in strat->L!
6035 */
6036 int posInLF5C (const LSet /*set*/, const int /*length*/,
6037  LObject* /*p*/,const kStrategy strat)
6038 {
6039  return strat->Ll+1;
6040 }
6041 
6042 /*2
6043 * looks up the position of polynomial p in set
6044 * e is the ecart of p
6045 * set[length] is the smallest element in set with respect
6046 * to the ordering-procedure totaldegree,pComp
6047 */
6048 int posInL11 (const LSet set, const int length,
6049  LObject* p,const kStrategy)
6050 {
6051  if (length<0) return 0;
6052 
6053  int o = p->GetpFDeg();
6054  int op = set[length].GetpFDeg();
6055 
6056  if ((op > o)
6057  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6058  return length+1;
6059  int i;
6060  int an = 0;
6061  int en= length;
6062  loop
6063  {
6064  if (an >= en-1)
6065  {
6066  op = set[an].GetpFDeg();
6067  if ((op > o)
6068  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6069  return en;
6070  return an;
6071  }
6072  i=(an+en) / 2;
6073  op = set[i].GetpFDeg();
6074  if ((op > o)
6075  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6076  an=i;
6077  else
6078  en=i;
6079  }
6080 }
6081 
6082 #ifdef HAVE_RINGS
6083 /*2
6084 * looks up the position of polynomial p in set
6085 * set[length] is the smallest element in set with respect
6086 * to the ordering-procedure pLmCmp,totaldegree,coefficient
6087 * For the same totaldegree, original pairs (from F) will
6088 * be put at the end and smalles coefficents
6089 */
6090 int posInL11Ring (const LSet set, const int length,
6091  LObject* p,const kStrategy)
6092 {
6093  if (length<0) return 0;
6094 
6095  int o = p->GetpFDeg();
6096  int op = set[length].GetpFDeg();
6097 
6098  if ((op > o)
6099  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6100  return length+1;
6101  int i;
6102  int an = 0;
6103  int en= length;
6104  loop
6105  {
6106  if (an >= en-1)
6107  {
6108  op = set[an].GetpFDeg();
6109  if ((op > o)
6110  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6111  return en;
6112  return an;
6113  }
6114  i=(an+en) / 2;
6115  op = set[i].GetpFDeg();
6116  if ((op > o)
6117  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6118  an=i;
6119  else
6120  en=i;
6121  }
6122 }
6123 
6124 int posInLF5CRing (const LSet set, int start,const int length,
6125  LObject* p,const kStrategy)
6126 {
6127  if (length<0) return 0;
6128  if(start == (length +1)) return (length+1);
6129  int o = p->GetpFDeg();
6130  int op = set[length].GetpFDeg();
6131 
6132  if ((op > o)
6133  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6134  return length+1;
6135  int i;
6136  int an = start;
6137  int en= length;
6138  loop
6139  {
6140  if (an >= en-1)
6141  {
6142  op = set[an].GetpFDeg();
6143  if ((op > o)
6144  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6145  return en;
6146  return an;
6147  }
6148  i=(an+en) / 2;
6149  op = set[i].GetpFDeg();
6150  if ((op > o)
6151  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6152  an=i;
6153  else
6154  en=i;
6155  }
6156 }
6157 #endif
6158 
6159 #ifdef HAVE_RINGS
6160 int posInL11Ringls (const LSet set, const int length,
6161  LObject* p,const kStrategy)
6162 {
6163  if (length < 0) return 0;
6164  int an,en,i;
6165  an = 0;
6166  en = length+1;
6167  loop
6168  {
6169  if (an >= en-1)
6170  {
6171  if(an == en)
6172  return en;
6173  if (set[an].FDeg > p->FDeg)
6174  return en;
6175  if (set[an].FDeg < p->FDeg)
6176  return an;
6177  if (set[an].FDeg == p->FDeg)
6178  {
6179  number lcset,lcp;
6180  lcset = pGetCoeff(set[an].p);
6181  lcp = pGetCoeff(p->p);
6182  if(!nGreaterZero(lcset))
6183  {
6184  set[an].p=p_Neg(set[an].p,currRing);
6185  if (set[an].t_p!=NULL)
6186  pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
6187  lcset=pGetCoeff(set[an].p);
6188  }
6189  if(!nGreaterZero(lcp))
6190  {
6191  p->p=p_Neg(p->p,currRing);
6192  if (p->t_p!=NULL)
6193  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6194  lcp=pGetCoeff(p->p);
6195  }
6196  if(nGreater(lcset, lcp))
6197  {
6198  return en;
6199  }
6200  else
6201  {
6202  return an;
6203  }
6204  }
6205  }
6206  i=(an+en) / 2;
6207  if (set[i].FDeg > p->FDeg)
6208  an=i;
6209  if (set[i].FDeg < p->FDeg)
6210  en=i;
6211  if (set[i].FDeg == p->FDeg)
6212  {
6213  number lcset,lcp;
6214  lcset = pGetCoeff(set[i].p);
6215  lcp = pGetCoeff(p->p);
6216  if(!nGreaterZero(lcset))
6217  {
6218  set[i].p=p_Neg(set[i].p,currRing);
6219  if (set[i].t_p!=NULL)
6220  pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6221  lcset=pGetCoeff(set[i].p);
6222  }
6223  if(!nGreaterZero(lcp))
6224  {
6225  p->p=p_Neg(p->p,currRing);
6226  if (p->t_p!=NULL)
6227  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6228  lcp=pGetCoeff(p->p);
6229  }
6230  if(nGreater(lcset, lcp))
6231  {
6232  an = i;
6233  }
6234  else
6235  {
6236  en = i;
6237  }
6238  }
6239  }
6240 }
6241 #endif
6242 
6243 /*2 Position for rings L: Here I am
6244 * looks up the position of polynomial p in set
6245 * e is the ecart of p
6246 * set[length] is the smallest element in set with respect
6247 * to the ordering-procedure totaldegree,pComp
6248 */
6249 inline int getIndexRng(long coeff)
6250 {
6251  if (coeff == 0) return -1;
6252  long tmp = coeff;
6253  int ind = 0;
6254  while (tmp % 2 == 0)
6255  {
6256  tmp = tmp / 2;
6257  ind++;
6258  }
6259  return ind;
6260 }
6261 
6262 int posInLrg0 (const LSet set, const int length,
6263  LObject* p,const kStrategy)
6264 /* if (nGreater(pGetCoeff(p), pGetCoeff(set[an]))) return en;
6265  if (pLmCmp(set[i],p) == cmp_int) en = i;
6266  else if (pLmCmp(set[i],p) == -cmp_int) an = i;
6267  else
6268  {
6269  if (nGreater(pGetCoeff(p), pGetCoeff(set[i]))) an = i;
6270  else en = i;
6271  }*/
6272 {
6273  if (length < 0) return 0;
6274 
6275  int o = p->GetpFDeg();
6276  int op = set[length].GetpFDeg();
6277 
6278  if ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6279  return length + 1;
6280  int i;
6281  int an = 0;
6282  int en = length;
6283  loop
6284  {
6285  if (an >= en - 1)
6286  {
6287  op = set[an].GetpFDeg();
6288  if ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6289  return en;
6290  return an;
6291  }
6292  i = (an+en) / 2;
6293  op = set[i].GetpFDeg();
6294  if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6295  an = i;
6296  else
6297  en = i;
6298  }
6299 }
6300 
6301 /*{
6302  if (length < 0) return 0;
6303 
6304  int o = p->GetpFDeg();
6305  int op = set[length].GetpFDeg();
6306 
6307  int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6308  int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6309  int inda;
6310  int indi;
6311 
6312  if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6313  return length + 1;
6314  int i;
6315  int an = 0;
6316  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6317  int en = length;
6318  loop
6319  {
6320  if (an >= en-1)
6321  {
6322  op = set[an].GetpFDeg();
6323  if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6324  return en;
6325  return an;
6326  }
6327  i = (an + en) / 2;
6328  indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6329  op = set[i].GetpFDeg();
6330  if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6331  // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6332  {
6333  an = i;
6334  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6335  }
6336  else
6337  en = i;
6338  }
6339 } */
6340 
6341 /*2
6342 * looks up the position of polynomial p in set
6343 * set[length] is the smallest element in set with respect
6344 * to the ordering-procedure totaldegree,pLength0
6345 */
6346 int posInL110 (const LSet set, const int length,
6347  LObject* p,const kStrategy)
6348 {
6349  if (length<0) return 0;
6350 
6351  int o = p->GetpFDeg();
6352  int op = set[length].GetpFDeg();
6353 
6354  if ((op > o)
6355  || ((op == o) && (set[length].length >p->length))
6356  || ((op == o) && (set[length].length <= p->length)
6357  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6358  return length+1;
6359  int i;
6360  int an = 0;
6361  int en= length;
6362  loop
6363  {
6364  if (an >= en-1)
6365  {
6366  op = set[an].GetpFDeg();
6367  if ((op > o)
6368  || ((op == o) && (set[an].length >p->length))
6369  || ((op == o) && (set[an].length <=p->length)
6370  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6371  return en;
6372  return an;
6373  }
6374  i=(an+en) / 2;
6375  op = set[i].GetpFDeg();
6376  if ((op > o)
6377  || ((op == o) && (set[i].length > p->length))
6378  || ((op == o) && (set[i].length <= p->length)
6379  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6380  an=i;
6381  else
6382  en=i;
6383  }
6384 }
6385 
6386 #ifdef HAVE_RINGS
6387 int posInL110Ring (const LSet set, const int length,
6388  LObject* p,const kStrategy)
6389 {
6390  if (length<0) return 0;
6391 
6392  int o = p->GetpFDeg();
6393  int op = set[length].GetpFDeg();
6394 
6395  if ((op > o)
6396  || ((op == o) && (set[length].length >p->length))
6397  || ((op == o) && (set[length].length <= p->length)
6398  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6399  return length+1;
6400  int i;
6401  int an = 0;
6402  int en= length;
6403  loop
6404  {
6405  if (an >= en-1)
6406  {
6407  op = set[an].GetpFDeg();
6408  if ((op > o)
6409  || ((op == o) && (set[an].length >p->length))
6410  || ((op == o) && (set[an].length <=p->length)
6411  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6412  return en;
6413  return an;
6414  }
6415  i=(an+en) / 2;
6416  op = set[i].GetpFDeg();
6417  if ((op > o)
6418  || ((op == o) && (set[i].length > p->length))
6419  || ((op == o) && (set[i].length <= p->length)
6420  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6421  an=i;
6422  else
6423  en=i;
6424  }
6425 }
6426 #endif
6427 
6428 /*2
6429 * looks up the position of polynomial p in set
6430 * e is the ecart of p
6431 * set[length] is the smallest element in set with respect
6432 * to the ordering-procedure totaldegree
6433 */
6434 int posInL13 (const LSet set, const int length,
6435  LObject* p,const kStrategy)
6436 {
6437  if (length<0) return 0;
6438 
6439  int o = p->GetpFDeg();
6440 
6441  if (set[length].GetpFDeg() > o)
6442  return length+1;
6443 
6444  int i;
6445  int an = 0;
6446  int en= length;
6447  loop
6448  {
6449  if (an >= en-1)
6450  {
6451  if (set[an].GetpFDeg() >= o)
6452  return en;
6453  return an;
6454  }
6455  i=(an+en) / 2;
6456  if (set[i].GetpFDeg() >= o)
6457  an=i;
6458  else
6459  en=i;
6460  }
6461 }
6462 
6463 /*2
6464 * looks up the position of polynomial p in set
6465 * e is the ecart of p
6466 * set[length] is the smallest element in set with respect
6467 * to the ordering-procedure maximaldegree,pComp
6468 */
6469 int posInL15 (const LSet set, const int length,
6470  LObject* p,const kStrategy)
6471 {
6472  if (length<0) return 0;
6473 
6474  int o = p->GetpFDeg() + p->ecart;
6475  int op = set[length].GetpFDeg() + set[length].ecart;
6476 
6477  if ((op > o)
6478  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6479  return length+1;
6480  int i;
6481  int an = 0;
6482  int en= length;
6483  loop
6484  {
6485  if (an >= en-1)
6486  {
6487  op = set[an].GetpFDeg() + set[an].ecart;
6488  if ((op > o)
6489  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6490  return en;
6491  return an;
6492  }
6493  i=(an+en) / 2;
6494  op = set[i].GetpFDeg() + set[i].ecart;
6495  if ((op > o)
6496  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6497  an=i;
6498  else
6499  en=i;
6500  }
6501 }
6502 
6503 #ifdef HAVE_RINGS
6504 int posInL15Ring (const LSet set, const int length,
6505  LObject* p,const kStrategy)
6506 {
6507  if (length<0) return 0;
6508 
6509  int o = p->GetpFDeg() + p->ecart;
6510  int op = set[length].GetpFDeg() + set[length].ecart;
6511 
6512  if ((op > o)
6513  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6514  return length+1;
6515  int i;
6516  int an = 0;
6517  int en= length;
6518  loop
6519  {
6520  if (an >= en-1)
6521  {
6522  op = set[an].GetpFDeg() + set[an].ecart;
6523  if ((op > o)
6524  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6525  return en;
6526  return an;
6527  }
6528  i=(an+en) / 2;
6529  op = set[i].GetpFDeg() + set[i].ecart;
6530  if ((op > o)
6531  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6532  an=i;
6533  else
6534  en=i;
6535  }
6536 }
6537 #endif
6538 
6539 /*2
6540 * looks up the position of polynomial p in set
6541 * e is the ecart of p
6542 * set[length] is the smallest element in set with respect
6543 * to the ordering-procedure totaldegree
6544 */
6545 int posInL17 (const LSet set, const int length,
6546  LObject* p,const kStrategy)
6547 {
6548  if (length<0) return 0;
6549 
6550  int o = p->GetpFDeg() + p->ecart;
6551 
6552  if ((set[length].GetpFDeg() + set[length].ecart > o)
6553  || ((set[length].GetpFDeg() + set[length].ecart == o)
6554  && (set[length].ecart > p->ecart))
6555  || ((set[length].GetpFDeg() + set[length].ecart == o)
6556  && (set[length].ecart == p->ecart)
6557  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6558  return length+1;
6559  int i;
6560  int an = 0;
6561  int en= length;
6562  loop
6563  {
6564  if (an >= en-1)
6565  {
6566  if ((set[an].GetpFDeg() + set[an].ecart > o)
6567  || ((set[an].GetpFDeg() + set[an].ecart == o)
6568  && (set[an].ecart > p->ecart))
6569  || ((set[an].GetpFDeg() + set[an].ecart == o)
6570  && (set[an].ecart == p->ecart)
6571  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6572  return en;
6573  return an;
6574  }
6575  i=(an+en) / 2;
6576  if ((set[i].GetpFDeg() + set[i].ecart > o)
6577  || ((set[i].GetpFDeg() + set[i].ecart == o)
6578  && (set[i].ecart > p->ecart))
6579  || ((set[i].GetpFDeg() +set[i].ecart == o)
6580  && (set[i].ecart == p->ecart)
6581  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6582  an=i;
6583  else
6584  en=i;
6585  }
6586 }
6587 
6588 #ifdef HAVE_RINGS
6589 int posInL17Ring (const LSet set, const int length,
6590  LObject* p,const kStrategy)
6591 {
6592  if (length<0) return 0;
6593 
6594  int o = p->GetpFDeg() + p->ecart;
6595 
6596  if ((set[length].GetpFDeg() + set[length].ecart > o)
6597  || ((set[length].GetpFDeg() + set[length].ecart == o)
6598  && (set[length].ecart > p->ecart))
6599  || ((set[length].GetpFDeg() + set[length].ecart == o)
6600  && (set[length].ecart == p->ecart)
6601  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6602  return length+1;
6603  int i;
6604  int an = 0;
6605  int en= length;
6606  loop
6607  {
6608  if (an >= en-1)
6609  {
6610  if ((set[an].GetpFDeg() + set[an].ecart > o)
6611  || ((set[an].GetpFDeg() + set[an].ecart == o)
6612  && (set[an].ecart > p->ecart))
6613  || ((set[an].GetpFDeg() + set[an].ecart == o)
6614  && (set[an].ecart == p->ecart)
6615  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6616  return en;
6617  return an;
6618  }
6619  i=(an+en) / 2;
6620  if ((set[i].GetpFDeg() + set[i].ecart > o)
6621  || ((set[i].GetpFDeg() + set[i].ecart == o)
6622  && (set[i].ecart > p->ecart))
6623  || ((set[i].GetpFDeg() +set[i].ecart == o)
6624  && (set[i].ecart == p->ecart)
6625  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6626  an=i;
6627  else
6628  en=i;
6629  }
6630 }
6631 #endif
6632 
6633 /*2
6634 * looks up the position of polynomial p in set
6635 * e is the ecart of p
6636 * set[length] is the smallest element in set with respect
6637 * to the ordering-procedure pComp
6638 */
6639 int posInL17_c (const LSet set, const int length,
6640  LObject* p,const kStrategy)
6641 {
6642  if (length<0) return 0;
6643 
6644  int cc = (-1+2*currRing->order[0]==ringorder_c);
6645  /* cc==1 for (c,..), cc==-1 for (C,..) */
6646  long c = pGetComp(p->p)*cc;
6647  int o = p->GetpFDeg() + p->ecart;
6648 
6649  if (pGetComp(set[length].p)*cc > c)
6650  return length+1;
6651  if (pGetComp(set[length].p)*cc == c)
6652  {
6653  if ((set[length].GetpFDeg() + set[length].ecart > o)
6654  || ((set[length].GetpFDeg() + set[length].ecart == o)
6655  && (set[length].ecart > p->ecart))
6656  || ((set[length].GetpFDeg() + set[length].ecart == o)
6657  && (set[length].ecart == p->ecart)
6658  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6659  return length+1;
6660  }
6661  int i;
6662  int an = 0;
6663  int en= length;
6664  loop
6665  {
6666  if (an >= en-1)
6667  {
6668  if (pGetComp(set[an].p)*cc > c)
6669  return en;
6670  if (pGetComp(set[an].p)*cc == c)
6671  {
6672  if ((set[an].GetpFDeg() + set[an].ecart > o)
6673  || ((set[an].GetpFDeg() + set[an].ecart == o)
6674  && (set[an].ecart > p->ecart))
6675  || ((set[an].GetpFDeg() + set[an].ecart == o)
6676  && (set[an].ecart == p->ecart)
6677  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6678  return en;
6679  }
6680  return an;
6681  }
6682  i=(an+en) / 2;
6683  if (pGetComp(set[i].p)*cc > c)
6684  an=i;
6685  else if (pGetComp(set[i].p)*cc == c)
6686  {
6687  if ((set[i].GetpFDeg() + set[i].ecart > o)
6688  || ((set[i].GetpFDeg() + set[i].ecart == o)
6689  && (set[i].ecart > p->ecart))
6690  || ((set[i].GetpFDeg() +set[i].ecart == o)
6691  && (set[i].ecart == p->ecart)
6692  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6693  an=i;
6694  else
6695  en=i;
6696  }
6697  else
6698  en=i;
6699  }
6700 }
6701 
6702 #ifdef HAVE_RINGS
6703 int posInL17_cRing (const LSet set, const int length,
6704  LObject* p,const kStrategy)
6705 {
6706  if (length<0) return 0;
6707 
6708  int cc = (-1+2*currRing->order[0]==ringorder_c);
6709  /* cc==1 for (c,..), cc==-1 for (C,..) */
6710  unsigned long c = pGetComp(p->p)*cc;
6711  int o = p->GetpFDeg() + p->ecart;
6712 
6713  if (pGetComp(set[length].p)*cc > c)
6714  return length+1;
6715  if (pGetComp(set[length].p)*cc == c)
6716  {
6717  if ((set[length].GetpFDeg() + set[length].ecart > o)
6718  || ((set[length].GetpFDeg() + set[length].ecart == o)
6719  && (set[length].ecart > p->ecart))
6720  || ((set[length].GetpFDeg() + set[length].ecart == o)
6721  && (set[length].ecart == p->ecart)
6722  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6723  return length+1;
6724  }
6725  int i;
6726  int an = 0;
6727  int en= length;
6728  loop
6729  {
6730  if (an >= en-1)
6731  {
6732  if (pGetComp(set[an].p)*cc > c)
6733  return en;
6734  if (pGetComp(set[an].p)*cc == c)
6735  {
6736  if ((set[an].GetpFDeg() + set[an].ecart > o)
6737  || ((set[an].GetpFDeg() + set[an].ecart == o)
6738  && (set[an].ecart > p->ecart))
6739  || ((set[an].GetpFDeg() + set[an].ecart == o)
6740  && (set[an].ecart == p->ecart)
6741  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6742  return en;
6743  }
6744  return an;
6745  }
6746  i=(an+en) / 2;
6747  if (pGetComp(set[i].p)*cc > c)
6748  an=i;
6749  else if (pGetComp(set[i].p)*cc == c)
6750  {
6751  if ((set[i].GetpFDeg() + set[i].ecart > o)
6752  || ((set[i].GetpFDeg() + set[i].ecart == o)
6753  && (set[i].ecart > p->ecart))
6754  || ((set[i].GetpFDeg() +set[i].ecart == o)
6755  && (set[i].ecart == p->ecart)
6756  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6757  an=i;
6758  else
6759  en=i;
6760  }
6761  else
6762  en=i;
6763  }
6764 }
6765 #endif
6766 
6767 /*
6768  * SYZYGY CRITERION for signature-based standard basis algorithms
6769  */
6770 BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6771 {
6772 //#if 1
6773 #ifdef DEBUGF5
6774  PrintS("syzygy criterion checks: ");
6775  pWrite(sig);
6776 #endif
6777  for (int k=0; k<strat->syzl; k++)
6778  {
6779  //printf("-%d",k);
6780 //#if 1
6781 #ifdef DEBUGF5
6782  Print("checking with: %d / %d -- \n",k,strat->syzl);
6783  pWrite(pHead(strat->syz[k]));
6784 #endif
6785  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6786  && (!rField_is_Ring(currRing) ||
6787  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6788  {
6789 //#if 1
6790 #ifdef DEBUGF5
6791  PrintS("DELETE!\n");
6792 #endif
6793  strat->nrsyzcrit++;
6794  //printf("- T -\n\n");
6795  return TRUE;
6796  }
6797  }
6798  //printf("- F -\n\n");
6799  return FALSE;
6800 }
6801 
6802 /*
6803  * SYZYGY CRITERION for signature-based standard basis algorithms
6804  */
6805 BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6806 {
6807 //#if 1
6808  if(sig == NULL)
6809  return FALSE;
6810 #ifdef DEBUGF5
6811  PrintS("--- syzygy criterion checks: ");
6812  pWrite(sig);
6813 #endif
6814  int comp = __p_GetComp(sig, currRing);
6815  int min, max;
6816  if (comp<=1)
6817  return FALSE;
6818  else
6819  {
6820  min = strat->syzIdx[comp-2];
6821  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
6822  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
6823  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
6824  if (comp == strat->currIdx)
6825  {
6826  max = strat->syzl;
6827  }
6828  else
6829  {
6830  max = strat->syzIdx[comp-1];
6831  }
6832  for (int k=min; k<max; k++)
6833  {
6834 #ifdef F5DEBUG
6835  Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
6836  Print("checking with: %d -- ",k);
6837  pWrite(pHead(strat->syz[k]));
6838 #endif
6839  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6840  && (!rField_is_Ring(currRing) ||
6841  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6842  {
6843  strat->nrsyzcrit++;
6844  return TRUE;
6845  }
6846  }
6847  return FALSE;
6848  }
6849 }
6850 
6851 /*
6852  * REWRITTEN CRITERION for signature-based standard basis algorithms
6853  */
6854 BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
6855 {
6856  //printf("Faugere Rewritten Criterion\n");
6858  return FALSE;
6859 //#if 1
6860 #ifdef DEBUGF5
6861  PrintS("rewritten criterion checks: ");
6862  pWrite(sig);
6863 #endif
6864  for(int k = strat->sl; k>=start; k--)
6865  {
6866 //#if 1
6867 #ifdef DEBUGF5
6868  PrintS("checking with: ");
6869  pWrite(strat->sig[k]);
6870  pWrite(pHead(strat->S[k]));
6871 #endif
6872  if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
6873  {
6874 //#if 1
6875 #ifdef DEBUGF5
6876  PrintS("DELETE!\n");
6877 #endif
6878  strat->nrrewcrit++;
6879  return TRUE;
6880  }
6881  //k--;
6882  }
6883 #ifdef DEBUGF5
6884  PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
6885  for(int kk = 0; kk<strat->sl+1; kk++)
6886  {
6887  pWrite(pHead(strat->S[kk]));
6888  }
6889  PrintS("------------------------------\n");
6890 #endif
6891  return FALSE;
6892 }
6893 
6894 /*
6895  * REWRITTEN CRITERION for signature-based standard basis algorithms
6896  ***************************************************************************
6897  * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
6898  ***************************************************************************
6899  */
6900 
6901 // real implementation of arri's rewritten criterion, only called once in
6902 // kstd2.cc, right before starting reduction
6903 // IDEA: Arri says that it is enough to consider 1 polynomial for each unique
6904 // signature appearing during the computations. Thus we first of all go
6905 // through strat->L and delete all other pairs of the same signature,
6906 // keeping only the one with least possible leading monomial. After this
6907 // we check if we really need to compute this critical pair at all: There
6908 // can be elements already in strat->S whose signatures divide the
6909 // signature of the critical pair in question and whose multiplied
6910 // leading monomials are smaller than the leading monomial of the
6911 // critical pair. In this situation we can discard the critical pair
6912 // completely.
6913 BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
6914 {
6916  return FALSE;
6917  poly p1 = pOne();
6918  poly p2 = pOne();
6919  for (int ii=strat->sl; ii>start; ii--)
6920  {
6921  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
6922  {
6923  p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
6924  p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
6925  if (!(pLmCmp(p1,p2) == 1))
6926  {
6927  pDelete(&p1);
6928  pDelete(&p2);
6929  return TRUE;
6930  }
6931  }
6932  }
6933  pDelete(&p1);
6934  pDelete(&p2);
6935  return FALSE;
6936 }
6937 
6938 BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
6939 {
6940  //Over Rings, there are still some changes to do: considering coeffs
6942  return FALSE;
6943  int found = -1;
6944  for (int i=strat->Bl; i>-1; i--)
6945  {
6946  if (pLmEqual(strat->B[i].sig,sig))
6947  {
6948  found = i;
6949  break;
6950  }
6951  }
6952  if (found != -1)
6953  {
6954  if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
6955  {
6956  deleteInL(strat->B,&strat->Bl,found,strat);
6957  }
6958  else
6959  {
6960  return TRUE;
6961  }
6962  }
6963  poly p1 = pOne();
6964  poly p2 = pOne();
6965  for (int ii=strat->sl; ii>-1; ii--)
6966  {
6967  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
6968  {
6969  p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
6970  p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
6971  if (!(pLmCmp(p1,p2) == 1))
6972  {
6973  pDelete(&p1);
6974  pDelete(&p2);
6975  return TRUE;
6976  }
6977  }
6978  }
6979  pDelete(&p1);
6980  pDelete(&p2);
6981  return FALSE;
6982 }
6983 
6984 /***************************************************************
6985  *
6986  * Tail reductions
6987  *
6988  ***************************************************************/
6989 TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
6990 {
6991  int j = 0;
6992  const unsigned long not_sev = ~L->sev;
6993  const unsigned long* sev = strat->sevS;
6994  poly p;
6995  ring r;
6996  L->GetLm(p, r);
6997 
6998  assume(~not_sev == p_GetShortExpVector(p, r));
6999 
7000  if (r == currRing)
7001  {
7002  if(!rField_is_Ring(r))
7003  {
7004  loop
7005  {
7006  if (j > end_pos) return NULL;
7007  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7008  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7009  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7010  {
7011  break;
7012  }
7013  #else
7014  if (!(sev[j] & not_sev) &&
7015  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7016  p_LmDivisibleBy(strat->S[j], p, r))
7017  {
7018  break;
7019  }
7020  #endif
7021  j++;
7022  }
7023  }
7024  #ifdef HAVE_RINGS
7025  else
7026  {
7027  loop
7028  {
7029  if (j > end_pos) return NULL;
7030  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7031  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7032  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7033  {
7034  break;
7035  }
7036  #else
7037  if (!(sev[j] & not_sev) &&
7038  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7039  p_LmDivisibleBy(strat->S[j], p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7040  {
7041  break;
7042  }
7043  #endif
7044  j++;
7045  }
7046  }
7047  #endif
7048  // if called from NF, T objects do not exist:
7049  if (strat->tl < 0 || strat->S_2_R[j] == -1)
7050  {
7051  T->Set(strat->S[j], r, strat->tailRing);
7052  assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
7053  return T;
7054  }
7055  else
7056  {
7057 ///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
7058 ///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
7059 // assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
7060  return strat->S_2_T(j);
7061  }
7062  }
7063  else
7064  {
7065  TObject* t;
7066  if(!rField_is_Ring(r))
7067  {
7068  loop
7069  {
7070  if (j > end_pos) return NULL;
7071  assume(strat->S_2_R[j] != -1);
7072  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7073  t = strat->S_2_T(j);
7074  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7075  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7076  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7077  {
7078  t->pLength=pLength(t->t_p);
7079  return t;
7080  }
7081  #else
7082  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7083  {
7084  t = strat->S_2_T(j);
7085  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7086  if (p_LmDivisibleBy(t->t_p, p, r))
7087  {
7088  t->pLength=pLength(t->t_p);
7089  return t;
7090  }
7091  }
7092  #endif
7093  j++;
7094  }
7095  }
7096  #ifdef HAVE_RINGS
7097  else
7098  {
7099  loop
7100  {
7101  if (j > end_pos) return NULL;
7102  assume(strat->S_2_R[j] != -1);
7103  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7104  t = strat->S_2_T(j);
7105  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7106  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7107  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7108  {
7109  t->pLength=pLength(t->t_p);
7110  return t;
7111  }
7112  #else
7113  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7114  {
7115  t = strat->S_2_T(j);
7116  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7117  if (p_LmDivisibleBy(t->t_p, p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7118  {
7119  t->pLength=pLength(t->t_p);
7120  return t;
7121  }
7122  }
7123  #endif
7124  j++;
7125  }
7126  }
7127  #endif
7128  }
7129 }
7130 
7131 poly redtail (LObject* L, int end_pos, kStrategy strat)
7132 {
7133  poly h, hn;
7134  strat->redTailChange=FALSE;
7135 
7136  L->GetP();
7137  poly p = L->p;
7138  if (strat->noTailReduction || pNext(p) == NULL)
7139  return p;
7140 
7141  LObject Ln(strat->tailRing);
7142  TObject* With;
7143  // placeholder in case strat->tl < 0
7144  TObject With_s(strat->tailRing);
7145  h = p;
7146  hn = pNext(h);
7147  long op = strat->tailRing->pFDeg(hn, strat->tailRing);
7148  long e;
7149  int l;
7150  BOOLEAN save_HE=strat->kAllAxis;
7151  strat->kAllAxis |=
7152  ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
7153 
7154  while(hn != NULL)
7155  {
7156  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7157  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7158  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7159  loop
7160  {
7161  Ln.Set(hn, strat->tailRing);
7162  Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
7163  if (strat->kAllAxis)
7164  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7165  else
7166  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
7167  if (With == NULL) break;
7168  With->length=0;
7169  With->pLength=0;
7170  strat->redTailChange=TRUE;
7171  if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
7172  {
7173  // reducing the tail would violate the exp bound
7174  if (kStratChangeTailRing(strat, L))
7175  {
7176  strat->kAllAxis = save_HE;
7177  return redtail(L, end_pos, strat);
7178  }
7179  else
7180  return NULL;
7181  }
7182  hn = pNext(h);
7183  if (hn == NULL) goto all_done;
7184  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7185  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7186  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7187  }
7188  h = hn;
7189  hn = pNext(h);
7190  }
7191 
7192  all_done:
7193  if (strat->redTailChange)
7194  {
7195  L->pLength = 0;
7196  }
7197  strat->kAllAxis = save_HE;
7198  return p;
7199 }
7200 
7201 poly redtail (poly p, int end_pos, kStrategy strat)
7202 {
7203  LObject L(p, currRing);
7204  return redtail(&L, end_pos, strat);
7205 }
7206 
7207 poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
7208 {
7209  strat->redTailChange=FALSE;
7210  if (strat->noTailReduction) return L->GetLmCurrRing();
7211  poly h, p;
7212  p = h = L->GetLmTailRing();
7213  if ((h==NULL) || (pNext(h)==NULL))
7214  return L->GetLmCurrRing();
7215 
7216  TObject* With;
7217  // placeholder in case strat->tl < 0
7218  TObject With_s(strat->tailRing);
7219 
7220  LObject Ln(pNext(h), strat->tailRing);
7221  Ln.GetpLength();
7222 
7223  pNext(h) = NULL;
7224  if (L->p != NULL)
7225  {
7226  pNext(L->p) = NULL;
7227  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7228  }
7229  L->pLength = 1;
7230 
7231  Ln.PrepareRed(strat->use_buckets);
7232 
7233  int cnt=REDTAIL_CANONICALIZE;
7234  while(!Ln.IsNull())
7235  {
7236  loop
7237  {
7238  if (TEST_OPT_IDLIFT)
7239  {
7240  if (Ln.p!=NULL)
7241  {
7242  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7243  }
7244  else
7245  {
7246  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7247  }
7248  }
7249  Ln.SetShortExpVector();
7250  if (withT)
7251  {
7252  int j;
7253  j = kFindDivisibleByInT(strat, &Ln);
7254  if (j < 0) break;
7255  With = &(strat->T[j]);
7256  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7257  }
7258  else
7259  {
7260  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7261  if (With == NULL) break;
7262  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7263  }
7264  cnt--;
7265  if (cnt==0)
7266  {
7268  /*poly tmp=*/Ln.CanonicalizeP();
7269  if (normalize)
7270  {
7271  Ln.Normalize();
7272  //pNormalize(tmp);
7273  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7274  }
7275  }
7276  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7277  {
7278  With->pNorm();
7279  }
7280  strat->redTailChange=TRUE;
7281  if (ksReducePolyTail(L, With, &Ln))
7282  {
7283  // reducing the tail would violate the exp bound
7284  // set a flag and hope for a retry (in bba)
7285  strat->completeReduce_retry=TRUE;
7286  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7287  do
7288  {
7289  pNext(h) = Ln.LmExtractAndIter();
7290  pIter(h);
7291  L->pLength++;
7292  } while (!Ln.IsNull());
7293  goto all_done;
7294  }
7295  if (Ln.IsNull()) goto all_done;
7296  if (! withT) With_s.Init(currRing);
7297  }
7298  pNext(h) = Ln.LmExtractAndIter();
7299  pIter(h);
7300  pNormalize(h);
7301  L->pLength++;
7302  }
7303 
7304  all_done:
7305  Ln.Delete();
7306  if (L->p != NULL) pNext(L->p) = pNext(p);
7307 
7308  if (strat->redTailChange)
7309  {
7310  L->length = 0;
7311  L->pLength = 0;
7312  }
7313 
7314  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7315  //L->Normalize(); // HANNES: should have a test
7316  kTest_L(L,strat);
7317  return L->GetLmCurrRing();
7318 }
7319 
7320 poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7321 {
7322  strat->redTailChange=FALSE;
7323  if (strat->noTailReduction) return L->GetLmCurrRing();
7324  poly h, p;
7325  p = h = L->GetLmTailRing();
7326  if ((h==NULL) || (pNext(h)==NULL))
7327  return L->GetLmCurrRing();
7328 
7329  TObject* With;
7330  // placeholder in case strat->tl < 0
7331  TObject With_s(strat->tailRing);
7332 
7333  LObject Ln(pNext(h), strat->tailRing);
7334  Ln.pLength = L->GetpLength() - 1;
7335 
7336  pNext(h) = NULL;
7337  if (L->p != NULL) pNext(L->p) = NULL;
7338  L->pLength = 1;
7339 
7340  Ln.PrepareRed(strat->use_buckets);
7341 
7342  int cnt=REDTAIL_CANONICALIZE;
7343  while(!Ln.IsNull())
7344  {
7345  loop
7346  {
7347  if (TEST_OPT_IDLIFT)
7348  {
7349  if (Ln.p!=NULL)
7350  {
7351  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7352  }
7353  else
7354  {
7355  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7356  }
7357  }
7358  Ln.SetShortExpVector();
7359  if (withT)
7360  {
7361  int j;
7362  j = kFindDivisibleByInT(strat, &Ln);
7363  if (j < 0) break;
7364  With = &(strat->T[j]);
7365  }
7366  else
7367  {
7368  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7369  if (With == NULL) break;
7370  }
7371  cnt--;
7372  if (cnt==0)
7373  {
7375  /*poly tmp=*/Ln.CanonicalizeP();
7376  if (normalize)
7377  {
7378  Ln.Normalize();
7379  //pNormalize(tmp);
7380  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7381  }
7382  }
7383  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7384  {
7385  With->pNorm();
7386  }
7387  strat->redTailChange=TRUE;
7388  if (ksReducePolyTail(L, With, &Ln))
7389  {
7390  // reducing the tail would violate the exp bound
7391  // set a flag and hope for a retry (in bba)
7392  strat->completeReduce_retry=TRUE;
7393  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7394  do
7395  {
7396  pNext(h) = Ln.LmExtractAndIter();
7397  pIter(h);
7398  L->pLength++;
7399  } while (!Ln.IsNull());
7400  goto all_done;
7401  }
7402  if(!Ln.IsNull())
7403  {
7404  Ln.GetP();
7405  Ln.p = pJet(Ln.p,bound);
7406  }
7407  if (Ln.IsNull())
7408  {
7409  goto all_done;
7410  }
7411  if (! withT) With_s.Init(currRing);
7412  }
7413  pNext(h) = Ln.LmExtractAndIter();
7414  pIter(h);
7415  pNormalize(h);
7416  L->pLength++;
7417  }
7418 
7419  all_done:
7420  Ln.Delete();
7421  if (L->p != NULL) pNext(L->p) = pNext(p);
7422 
7423  if (strat->redTailChange)
7424  {
7425  L->length = 0;
7426  L->pLength = 0;
7427  }
7428 
7429  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7430  //L->Normalize(); // HANNES: should have a test
7431  kTest_L(L,strat);
7432  return L->GetLmCurrRing();
7433 }
7434 
7435 #ifdef HAVE_RINGS
7436 void redtailBbaAlsoLC_Z (LObject* L, int end_pos, kStrategy strat )
7437 // normalize=FALSE, withT=FALSE, coeff=Z
7438 {
7439  strat->redTailChange=FALSE;
7440 
7441  poly h, p;
7442  p = h = L->GetLmTailRing();
7443  if ((h==NULL) || (pNext(h)==NULL))
7444  return;
7445 
7446  TObject* With;
7447  LObject Ln(pNext(h), strat->tailRing);
7448  Ln.GetpLength();
7449 
7450  pNext(h) = NULL;
7451  if (L->p != NULL)
7452  {
7453  pNext(L->p) = NULL;
7454  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7455  }
7456  L->pLength = 1;
7457 
7458  Ln.PrepareRed(strat->use_buckets);
7459 
7460  int cnt=REDTAIL_CANONICALIZE;
7461 
7462  while(!Ln.IsNull())
7463  {
7464  loop
7465  {
7466  if (TEST_OPT_IDLIFT)
7467  {
7468  if (Ln.p!=NULL)
7469  {
7470  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7471  }
7472  else
7473  {
7474  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7475  }
7476  }
7477  Ln.SetShortExpVector();
7478  int j;
7479  j = kFindDivisibleByInT(strat, &Ln);
7480  if (j < 0)
7481  {
7482  j = kFindDivisibleByInT_Z(strat, &Ln);
7483  if (j < 0)
7484  {
7485  break;
7486  }
7487  else
7488  {
7489  /* reduction not cancelling a tail term, but reducing its coefficient */
7490  With = &(strat->T[j]);
7491  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7492  cnt--;
7493  if (cnt==0)
7494  {
7496  /*poly tmp=*/Ln.CanonicalizeP();
7497  }
7498  strat->redTailChange=TRUE;
7499  /* reduction cancelling a tail term */
7500  if (ksReducePolyTailLC_Z(L, With, &Ln))
7501  {
7502  // reducing the tail would violate the exp bound
7503  // set a flag and hope for a retry (in bba)
7504  strat->completeReduce_retry=TRUE;
7505  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7506  do
7507  {
7508  pNext(h) = Ln.LmExtractAndIter();
7509  pIter(h);
7510  L->pLength++;
7511  } while (!Ln.IsNull());
7512  goto all_done;
7513  }
7514  /* we have to break since we did not cancel the term, but only decreased
7515  * its coefficient. */
7516  break;
7517  }
7518  } else {
7519  With = &(strat->T[j]);
7520  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7521  cnt--;
7522  if (cnt==0)
7523  {
7525  /*poly tmp=*/Ln.CanonicalizeP();
7526  }
7527  strat->redTailChange=TRUE;
7528  /* reduction cancelling a tail term */
7529  if (ksReducePolyTail_Z(L, With, &Ln))
7530  {
7531  // reducing the tail would violate the exp bound
7532  // set a flag and hope for a retry (in bba)
7533  strat->completeReduce_retry=TRUE;
7534  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7535  do
7536  {
7537  pNext(h) = Ln.LmExtractAndIter();
7538  pIter(h);
7539  L->pLength++;
7540  } while (!Ln.IsNull());
7541  goto all_done;
7542  }
7543  }
7544  if (Ln.IsNull()) goto all_done;
7545  }
7546  pNext(h) = Ln.LmExtractAndIter();
7547  pIter(h);
7548  L->pLength++;
7549  }
7550 
7551  all_done:
7552  Ln.Delete();
7553  if (L->p != NULL) pNext(L->p) = pNext(p);
7554 
7555  if (strat->redTailChange)
7556  {
7557  L->length = 0;
7558  L->pLength = 0;
7559  }
7560 
7561  kTest_L(L, strat);
7562  return;
7563 }
7564 
7565 poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7566 // normalize=FALSE, withT=FALSE, coeff=Z
7567 {
7568  strat->redTailChange=FALSE;
7569  if (strat->noTailReduction) return L->GetLmCurrRing();
7570  poly h, p;
7571  p = h = L->GetLmTailRing();
7572  if ((h==NULL) || (pNext(h)==NULL))
7573  return L->GetLmCurrRing();
7574 
7575  TObject* With;
7576  // placeholder in case strat->tl < 0
7577  TObject With_s(strat->tailRing);
7578 
7579  LObject Ln(pNext(h), strat->tailRing);
7580  Ln.pLength = L->GetpLength() - 1;
7581 
7582  pNext(h) = NULL;
7583  if (L->p != NULL) pNext(L->p) = NULL;
7584  L->pLength = 1;
7585 
7586  Ln.PrepareRed(strat->use_buckets);
7587 
7588  int cnt=REDTAIL_CANONICALIZE;
7589  while(!Ln.IsNull())
7590  {
7591  loop
7592  {
7593  Ln.SetShortExpVector();
7594  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7595  if (With == NULL) break;
7596  cnt--;
7597  if (cnt==0)
7598  {
7600  /*poly tmp=*/Ln.CanonicalizeP();
7601  }
7602  // we are in Z, do not call pNorm
7603  strat->redTailChange=TRUE;
7604  // test divisibility of coefs:
7605  poly p_Ln=Ln.GetLmCurrRing();
7606  poly p_With=With->GetLmCurrRing();
7607  number z=n_IntMod(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf);
7608  if (!nIsZero(z))
7609  {
7610  // subtract z*Ln, add z.Ln to L
7611  poly m=pHead(p_Ln);
7612  pSetCoeff(m,z);
7613  poly mm=pHead(m);
7614  pNext(h) = m;
7615  pIter(h);
7616  L->pLength++;
7617  mm=pNeg(mm);
7618  if (Ln.bucket!=NULL)
7619  {
7620  int dummy=1;
7621  kBucket_Add_q(Ln.bucket,mm,&dummy);
7622  }
7623  else
7624  {
7625  if ((Ln.t_p!=NULL)&&(Ln.p==NULL))
7626  Ln.GetP();
7627  if (Ln.p!=NULL)
7628  {
7629  Ln.p=pAdd(Ln.p,mm);
7630  if (Ln.t_p!=NULL)
7631  {
7632  pNext(Ln.t_p)=NULL;
7633  p_LmDelete(Ln.t_p,strat->tailRing);
7634  }
7635  }
7636  }
7637  }
7638  else
7639  nDelete(&z);
7640 
7641  if (ksReducePolyTail_Z(L, With, &Ln))
7642  {
7643  // reducing the tail would violate the exp bound
7644  // set a flag and hope for a retry (in bba)
7645  strat->completeReduce_retry=TRUE;
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  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  }
7672 
7673  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7674  //L->Normalize(); // HANNES: should have a test
7675  kTest_L(L,strat);
7676  return L->GetLmCurrRing();
7677 }
7678 
7679 poly redtailBba_Ring (LObject* L, int end_pos, kStrategy strat )
7680 // normalize=FALSE, withT=FALSE, coeff=Z
7681 {
7682  strat->redTailChange=FALSE;
7683  if (strat->noTailReduction) return L->GetLmCurrRing();
7684  poly h, p;
7685  p = h = L->GetLmTailRing();
7686  if ((h==NULL) || (pNext(h)==NULL))
7687  return L->GetLmCurrRing();
7688 
7689  TObject* With;
7690  // placeholder in case strat->tl < 0
7691  TObject With_s(strat->tailRing);
7692 
7693  LObject Ln(pNext(h), strat->tailRing);
7694  Ln.pLength = L->GetpLength() - 1;
7695 
7696  pNext(h) = NULL;
7697  if (L->p != NULL) pNext(L->p) = NULL;
7698  L->pLength = 1;
7699 
7700  Ln.PrepareRed(strat->use_buckets);
7701 
7702  int cnt=REDTAIL_CANONICALIZE;
7703  while(!Ln.IsNull())
7704  {
7705  loop
7706  {
7707  Ln.SetShortExpVector();
7708  With_s.Init(currRing);
7709  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7710  if (With == NULL) break;
7711  cnt--;
7712  if (cnt==0)
7713  {
7715  /*poly tmp=*/Ln.CanonicalizeP();
7716  }
7717  // we are in a ring, do not call pNorm
7718  // test divisibility of coefs:
7719  poly p_Ln=Ln.GetLmCurrRing();
7720  poly p_With=With->GetLmCurrRing();
7721  if (n_DivBy(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf))
7722  {
7723  strat->redTailChange=TRUE;
7724 
7725  if (ksReducePolyTail_Z(L, With, &Ln))
7726  {
7727  // reducing the tail would violate the exp bound
7728  // set a flag and hope for a retry (in bba)
7729  strat->completeReduce_retry=TRUE;
7730  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7731  do
7732  {
7733  pNext(h) = Ln.LmExtractAndIter();
7734  pIter(h);
7735  L->pLength++;
7736  } while (!Ln.IsNull());
7737  goto all_done;
7738  }
7739  }
7740  else break; /*proceed to next monomial*/
7741  if (Ln.IsNull()) goto all_done;
7742  }
7743  pNext(h) = Ln.LmExtractAndIter();
7744  pIter(h);
7745  pNormalize(h);
7746  L->pLength++;
7747  }
7748 
7749  all_done:
7750  Ln.Delete();
7751  if (L->p != NULL) pNext(L->p) = pNext(p);
7752 
7753  if (strat->redTailChange)
7754  {
7755  L->length = 0;
7756  }
7757 
7758  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7759  //L->Normalize(); // HANNES: should have a test
7760  kTest_L(L,strat);
7761  return L->GetLmCurrRing();
7762 }
7763 #endif
7764 
7765 /*2
7766 *checks the change degree and write progress report
7767 */
7768 void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7769 {
7770  if (i != *olddeg)
7771  {
7772  Print("%d",i);
7773  *olddeg = i;
7774  }
7775  if (TEST_OPT_OLDSTD)
7776  {
7777  if (strat->Ll != *reduc)
7778  {
7779  if (strat->Ll != *reduc-1)
7780  Print("(%d)",strat->Ll+1);
7781  else
7782  PrintS("-");
7783  *reduc = strat->Ll;
7784  }
7785  else
7786  PrintS(".");
7787  mflush();
7788  }
7789  else
7790  {
7791  if (red_result == 0)
7792  PrintS("-");
7793  else if (red_result < 0)
7794  PrintS(".");
7795  if ((red_result > 0) || ((strat->Ll % 100)==99))
7796  {
7797  if (strat->Ll != *reduc && strat->Ll > 0)
7798  {
7799  Print("(%d)",strat->Ll+1);
7800  *reduc = strat->Ll;
7801  }
7802  }
7803  }
7804 }
7805 
7806 /*2
7807 *statistics
7808 */
7809 void messageStat (int hilbcount,kStrategy strat)
7810 {
7811  //PrintS("\nUsage/Allocation of temporary storage:\n");
7812  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7813  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7814  Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7815  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7816  #ifdef HAVE_SHIFTBBA
7817  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7818  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7819  #endif
7820 }
7821 
7822 void messageStatSBA (int hilbcount,kStrategy strat)
7823 {
7824  //PrintS("\nUsage/Allocation of temporary storage:\n");
7825  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7826  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7827  Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7828  //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7829  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7830  #ifdef HAVE_SHIFTBBA
7831  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7832  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7833  #endif
7834 }
7835 
7836 #ifdef KDEBUG
7837 /*2
7838 *debugging output: all internal sets, if changed
7839 *for testing purpuse only/has to be changed for later use
7840 */
7842 {
7843  int i;
7844  if (strat->news)
7845  {
7846  PrintS("set S");
7847  for (i=0; i<=strat->sl; i++)
7848  {
7849  Print("\n %d:",i);
7850  p_wrp(strat->S[i], currRing, strat->tailRing);
7851  if (strat->fromQ!=NULL && strat->fromQ[i])
7852  Print(" (from Q)");
7853  }
7854  strat->news = FALSE;
7855  }
7856  if (strat->newt)
7857  {
7858  PrintS("\nset T");
7859  for (i=0; i<=strat->tl; i++)
7860  {
7861  Print("\n %d:",i);
7862  strat->T[i].wrp();
7863  if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7864  Print(" o:%ld e:%d l:%d",
7865  strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7866  }
7867  strat->newt = FALSE;
7868  }
7869  PrintS("\nset L");
7870  for (i=strat->Ll; i>=0; i--)
7871  {
7872  Print("\n%d:",i);
7873  p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7874  PrintS(" ");
7875  p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7876  PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7877  PrintS("\n p : ");
7878  strat->L[i].wrp();
7879  Print(" o:%ld e:%d l:%d",
7880  strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7881  }
7882  PrintLn();
7883 }
7884 
7885 #endif
7886 
7887 
7888 /*2
7889 *construct the set s from F
7890 */
7891 void initS (ideal F, ideal Q, kStrategy strat)
7892 {
7893  int i,pos;
7894 
7895  if (Q!=NULL) i=((IDELEMS(F)+IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7896  else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7897  strat->ecartS=initec(i);
7898  strat->sevS=initsevS(i);
7899  strat->S_2_R=initS_2_R(i);
7900  strat->fromQ=NULL;
7901  strat->Shdl=idInit(i,F->rank);
7902  strat->S=strat->Shdl->m;
7903  /*- put polys into S -*/
7904  if (Q!=NULL)
7905  {
7906  strat->fromQ=initec(i);
7907  memset(strat->fromQ,0,i*sizeof(int));
7908  for (i=0; i<IDELEMS(Q); i++)
7909  {
7910  if (Q->m[i]!=NULL)
7911  {
7912  LObject h;
7913  h.p = pCopy(Q->m[i]);
7915  {
7916  h.pCleardenom(); // also does remove Content
7917  }
7918  else
7919  {
7920  h.pNorm();
7921  }
7923  {
7924  deleteHC(&h, strat);
7925  }
7926  if (h.p!=NULL)
7927  {
7928  strat->initEcart(&h);
7929  if (strat->sl==-1)
7930  pos =0;
7931  else
7932  {
7933  pos = posInS(strat,strat->sl,h.p,h.ecart);
7934  }
7935  h.sev = pGetShortExpVector(h.p);
7936  strat->enterS(h,pos,strat,-1);
7937  strat->fromQ[pos]=1;
7938  }
7939  }
7940  }
7941  }
7942  for (i=0; i<IDELEMS(F); i++)
7943  {
7944  if (F->m[i]!=NULL)
7945  {
7946  LObject h;
7947  h.p = pCopy(F->m[i]);
7949  {
7950  cancelunit(&h); /*- tries to cancel a unit -*/
7951  deleteHC(&h, strat);
7952  }
7953  if (h.p!=NULL)
7954  // do not rely on the input being a SB!
7955  {
7957  {
7958  h.pCleardenom(); // also does remove Content
7959  }
7960  else
7961  {
7962  h.pNorm();
7963  }
7964  strat->initEcart(&h);
7965  if (strat->sl==-1)
7966  pos =0;
7967  else
7968  pos = posInS(strat,strat->sl,h.p,h.ecart);
7969  h.sev = pGetShortExpVector(h.p);
7970  strat->enterS(h,pos,strat,-1);
7971  }
7972  }
7973  }
7974  /*- test, if a unit is in F -*/
7975  if ((strat->sl>=0)
7976 #ifdef HAVE_RINGS
7977  && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7978 #endif
7979  && pIsConstant(strat->S[0]))
7980  {
7981  while (strat->sl>0) deleteInS(strat->sl,strat);
7982  }
7983 }
7984 
7985 void initSL (ideal F, ideal Q,kStrategy strat)
7986 {
7987  int i,pos;
7988 
7989  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7990  else i=setmaxT;
7991  strat->ecartS=initec(i);
7992  strat->sevS=initsevS(i);
7993  strat->S_2_R=initS_2_R(i);
7994  strat->fromQ=NULL;
7995  strat->Shdl=idInit(i,F->rank);
7996  strat->S=strat->Shdl->m;
7997  /*- put polys into S -*/
7998  if (Q!=NULL)
7999  {
8000  strat->fromQ=initec(i);
8001  memset(strat->fromQ,0,i*sizeof(int));
8002  for (i=0; i<IDELEMS(Q); i++)
8003  {
8004  if (Q->m[i]!=NULL)
8005  {
8006  LObject h;
8007  h.p = pCopy(Q->m[i]);
8009  {
8010  deleteHC(&h,strat);
8011  }
8013  {
8014  h.pCleardenom(); // also does remove Content
8015  }
8016  else
8017  {
8018  h.pNorm();
8019  }
8020  if (h.p!=NULL)
8021  {
8022  strat->initEcart(&h);
8023  if (strat->sl==-1)
8024  pos =0;
8025  else
8026  {
8027  pos = posInS(strat,strat->sl,h.p,h.ecart);
8028  }
8029  h.sev = pGetShortExpVector(h.p);
8030  strat->enterS(h,pos,strat,-1);
8031  strat->fromQ[pos]=1;
8032  }
8033  }
8034  }
8035  }
8036  for (i=0; i<IDELEMS(F); i++)
8037  {
8038  if (F->m[i]!=NULL)
8039  {
8040  LObject h;
8041  h.p = pCopy(F->m[i]);
8042  if (h.p!=NULL)
8043  {
8045  {
8046  cancelunit(&h); /*- tries to cancel a unit -*/
8047  deleteHC(&h, strat);
8048  }
8049  if (h.p!=NULL)
8050  {
8052  {
8053  h.pCleardenom(); // also does remove Content
8054  }
8055  else
8056  {
8057  h.pNorm();
8058  }
8059  strat->initEcart(&h);
8060  if (strat->Ll==-1)
8061  pos =0;
8062  else
8063  pos = strat->posInL(strat->L,strat->Ll,&h,strat);
8064  h.sev = pGetShortExpVector(h.p);
8065  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8066  }
8067  }
8068  }
8069  }
8070  /*- test, if a unit is in F -*/
8071 
8072  if ((strat->Ll>=0)
8073 #ifdef HAVE_RINGS
8074  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8075 #endif
8076  && pIsConstant(strat->L[strat->Ll].p))
8077  {
8078  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8079  }
8080 }
8081 
8082 void initSLSba (ideal F, ideal Q,kStrategy strat)
8083 {
8084  int i,pos;
8085  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8086  else i=setmaxT;
8087  strat->ecartS = initec(i);
8088  strat->sevS = initsevS(i);
8089  strat->sevSig = initsevS(i);
8090  strat->S_2_R = initS_2_R(i);
8091  strat->fromQ = NULL;
8092  strat->Shdl = idInit(i,F->rank);
8093  strat->S = strat->Shdl->m;
8094  strat->sig = (poly *)omAlloc0(i*sizeof(poly));
8095  if (strat->sbaOrder != 1)
8096  {
8097  strat->syz = (poly *)omAlloc0(i*sizeof(poly));
8098  strat->sevSyz = initsevS(i);
8099  strat->syzmax = i;
8100  strat->syzl = 0;
8101  }
8102  /*- put polys into S -*/
8103  if (Q!=NULL)
8104  {
8105  strat->fromQ=initec(i);
8106  memset(strat->fromQ,0,i*sizeof(int));
8107  for (i=0; i<IDELEMS(Q); i++)
8108  {
8109  if (Q->m[i]!=NULL)
8110  {
8111  LObject h;
8112  h.p = pCopy(Q->m[i]);
8114  {
8115  deleteHC(&h,strat);
8116  }
8118  {
8119  h.pCleardenom(); // also does remove Content
8120  }
8121  else
8122  {
8123  h.pNorm();
8124  }
8125  if (h.p!=NULL)
8126  {
8127  strat->initEcart(&h);
8128  if (strat->sl==-1)
8129  pos =0;
8130  else
8131  {
8132  pos = posInS(strat,strat->sl,h.p,h.ecart);
8133  }
8134  h.sev = pGetShortExpVector(h.p);
8135  strat->enterS(h,pos,strat,-1);
8136  strat->fromQ[pos]=1;
8137  }
8138  }
8139  }
8140  }
8141  for (i=0; i<IDELEMS(F); i++)
8142  {
8143  if (F->m[i]!=NULL)
8144  {
8145  LObject h;
8146  h.p = pCopy(F->m[i]);
8147  h.sig = pOne();
8148  //h.sig = pInit();
8149  //p_SetCoeff(h.sig,nInit(1),currRing);
8150  p_SetComp(h.sig,i+1,currRing);
8151  // if we are working with the Schreyer order we generate it
8152  // by multiplying the initial signatures with the leading monomial
8153  // of the corresponding initial polynomials generating the ideal
8154  // => we can keep the underlying monomial order and get a Schreyer
8155  // order without any bigger overhead
8156  if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
8157  {
8158  p_ExpVectorAdd (h.sig,F->m[i],currRing);
8159  }
8160  h.sevSig = pGetShortExpVector(h.sig);
8161 #ifdef DEBUGF5
8162  pWrite(h.p);
8163  pWrite(h.sig);
8164 #endif
8165  if (h.p!=NULL)
8166  {
8168  {
8169  cancelunit(&h); /*- tries to cancel a unit -*/
8170  deleteHC(&h, strat);
8171  }
8172  if (h.p!=NULL)
8173  {
8175  {
8176  h.pCleardenom(); // also does remove Content
8177  }
8178  else
8179  {
8180  h.pNorm();
8181  }
8182  strat->initEcart(&h);
8183  if (strat->Ll==-1)
8184  pos =0;
8185  else
8186  pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
8187  h.sev = pGetShortExpVector(h.p);
8188  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8189  }
8190  }
8191  /*
8192  if (strat->sbaOrder != 1)
8193  {
8194  for(j=0;j<i;j++)
8195  {
8196  strat->syz[ctr] = pCopy(F->m[j]);
8197  p_SetCompP(strat->syz[ctr],i+1,currRing);
8198  // add LM(F->m[i]) to the signature to get a Schreyer order
8199  // without changing the underlying polynomial ring at all
8200  p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
8201  // since p_Add_q() destroys all input
8202  // data we need to recreate help
8203  // each time
8204  poly help = pCopy(F->m[i]);
8205  p_SetCompP(help,j+1,currRing);
8206  pWrite(strat->syz[ctr]);
8207  pWrite(help);
8208  printf("%d\n",pLmCmp(strat->syz[ctr],help));
8209  strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
8210  printf("%d. SYZ ",ctr);
8211  pWrite(strat->syz[ctr]);
8212  strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
8213  ctr++;
8214  }
8215  strat->syzl = ps;
8216  }
8217  */
8218  }
8219  }
8220  /*- test, if a unit is in F -*/
8221 
8222  if ((strat->Ll>=0)
8223 #ifdef HAVE_RINGS
8224  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8225 #endif
8226  && pIsConstant(strat->L[strat->Ll].p))
8227  {
8228  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8229  }
8230 }
8231 
8233 {
8234  if( strat->S[0] )
8235  {
8236  if( strat->S[1] && !rField_is_Ring(currRing))
8237  {
8238  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
8239  omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
8240  omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
8241  }
8242  int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
8243  /************************************************************
8244  * computing the length of the syzygy array needed
8245  ***********************************************************/
8246  for(i=1; i<=strat->sl; i++)
8247  {
8248  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8249  {
8250  ps += i;
8251  }
8252  }
8253  ps += strat->sl+1;
8254  //comp = pGetComp (strat->P.sig);
8255  comp = strat->currIdx;
8256  strat->syzIdx = initec(comp);
8257  strat->sevSyz = initsevS(ps);
8258  strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8259  strat->syzmax = ps;
8260  strat->syzl = 0;
8261  strat->syzidxmax = comp;
8262 #if defined(DEBUGF5) || defined(DEBUGF51)
8263  PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8264 #endif
8265  i = 1;
8266  j = 0;
8267  /************************************************************
8268  * generating the leading terms of the principal syzygies
8269  ***********************************************************/
8270  while (i <= strat->sl)
8271  {
8272  /**********************************************************
8273  * principal syzygies start with component index 2
8274  * the array syzIdx starts with index 0
8275  * => the rules for a signature with component comp start
8276  * at strat->syz[strat->syzIdx[comp-2]] !
8277  *********************************************************/
8278  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8279  {
8280  comp = pGetComp(strat->sig[i]);
8281  comp_old = pGetComp(strat->sig[i-1]);
8282  diff = comp - comp_old - 1;
8283  // diff should be zero, but sometimes also the initial generating
8284  // elements of the input ideal reduce to zero. then there is an
8285  // index-gap between the signatures. for these inbetween signatures we
8286  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8287  // in the following.
8288  // doing this, we keep the relation "j = comp - 2" alive, which makes
8289  // jumps way easier when checking criteria
8290  while (diff>0)
8291  {
8292  strat->syzIdx[j] = 0;
8293  diff--;
8294  j++;
8295  }
8296  strat->syzIdx[j] = ctr;
8297  j++;
8298  LObject Q;
8299  int pos;
8300  for (k = 0; k<i; k++)
8301  {
8302  Q.sig = pOne();
8304  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8305  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8306  p_SetCompP (Q.sig, comp, currRing);
8307  poly q = p_One(currRing);
8310  p_ExpVectorCopy(q,strat->S[i],currRing);
8311  q = p_Neg (q, currRing);
8312  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8313  Q.sig = p_Add_q (Q.sig, q, currRing);
8314  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8315  pos = posInSyz(strat, Q.sig);
8316  enterSyz(Q, strat, pos);
8317  ctr++;
8318  }
8319  }
8320  i++;
8321  }
8322  /**************************************************************
8323  * add syzygies for upcoming first element of new iteration step
8324  **************************************************************/
8325  comp = strat->currIdx;
8326  comp_old = pGetComp(strat->sig[i-1]);
8327  diff = comp - comp_old - 1;
8328  // diff should be zero, but sometimes also the initial generating
8329  // elements of the input ideal reduce to zero. then there is an
8330  // index-gap between the signatures. for these inbetween signatures we
8331  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8332  // in the following.
8333  // doing this, we keep the relation "j = comp - 2" alive, which makes
8334  // jumps way easier when checking criteria
8335  while (diff>0)
8336  {
8337  strat->syzIdx[j] = 0;
8338  diff--;
8339  j++;
8340  }
8341  strat->syzIdx[j] = ctr;
8342  LObject Q;
8343  int pos;
8344  for (k = 0; k<strat->sl+1; k++)
8345  {
8346  Q.sig = pOne();
8348  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8349  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8350  p_SetCompP (Q.sig, comp, currRing);
8351  poly q = p_One(currRing);
8353  p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8354  p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8355  q = p_Neg (q, currRing);
8356  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8357  Q.sig = p_Add_q (Q.sig, q, currRing);
8358  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8359  pos = posInSyz(strat, Q.sig);
8360  enterSyz(Q, strat, pos);
8361  ctr++;
8362  }
8363 //#if 1
8364 #ifdef DEBUGF5
8365  PrintS("Principal syzygies:\n");
8366  Print("syzl %d\n",strat->syzl);
8367  Print("syzmax %d\n",strat->syzmax);
8368  Print("ps %d\n",ps);
8369  PrintS("--------------------------------\n");
8370  for(i=0;i<=strat->syzl-1;i++)
8371  {
8372  Print("%d - ",i);
8373  pWrite(strat->syz[i]);
8374  }
8375  for(i=0;i<strat->currIdx;i++)
8376  {
8377  Print("%d - %d\n",i,strat->syzIdx[i]);
8378  }
8379  PrintS("--------------------------------\n");
8380 #endif
8381  }
8382 }
8383 
8384 /*2
8385 *construct the set s from F and {P}
8386 */
8387 void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8388 {
8389  int i,pos;
8390 
8391  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8392  else i=setmaxT;
8393  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8394  strat->ecartS=initec(i);
8395  strat->sevS=initsevS(i);
8396  strat->S_2_R=initS_2_R(i);
8397  strat->fromQ=NULL;
8398  strat->Shdl=idInit(i,F->rank);
8399  strat->S=strat->Shdl->m;
8400 
8401  /*- put polys into S -*/
8402  if (Q!=NULL)
8403  {
8404  strat->fromQ=initec(i);
8405  memset(strat->fromQ,0,i*sizeof(int));
8406  for (i=0; i<IDELEMS(Q); i++)
8407  {
8408  if (Q->m[i]!=NULL)
8409  {
8410  LObject h;
8411  h.p = pCopy(Q->m[i]);
8412  //if (TEST_OPT_INTSTRATEGY)
8413  //{
8414  // h.pCleardenom(); // also does remove Content
8415  //}
8416  //else
8417  //{
8418  // h.pNorm();
8419  //}
8421  {
8422  deleteHC(&h,strat);
8423  }
8424  if (h.p!=NULL)
8425  {
8426  strat->initEcart(&h);
8427  if (strat->sl==-1)
8428  pos =0;
8429  else
8430  {
8431  pos = posInS(strat,strat->sl,h.p,h.ecart);
8432  }
8433  h.sev = pGetShortExpVector(h.p);
8434  strat->enterS(h,pos,strat, strat->tl+1);
8435  enterT(h, strat);
8436  strat->fromQ[pos]=1;
8437  }
8438  }
8439  }
8440  }
8441  /*- put polys into S -*/
8442  for (i=0; i<IDELEMS(F); i++)
8443  {
8444  if (F->m[i]!=NULL)
8445  {
8446  LObject h;
8447  h.p = pCopy(F->m[i]);
8449  {
8450  deleteHC(&h,strat);
8451  }
8452  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8453  {
8454  h.p=redtailBba(h.p,strat->sl,strat);
8455  }
8456  if (h.p!=NULL)
8457  {
8458  strat->initEcart(&h);
8459  if (strat->sl==-1)
8460  pos =0;
8461  else
8462  pos = posInS(strat,strat->sl,h.p,h.ecart);
8463  h.sev = pGetShortExpVector(h.p);
8464  strat->enterS(h,pos,strat, strat->tl+1);
8465  enterT(h,strat);
8466  }
8467  }
8468  }
8469  for (i=0; i<IDELEMS(P); i++)
8470  {
8471  if (P->m[i]!=NULL)
8472  {
8473  LObject h;
8474  h.p=pCopy(P->m[i]);
8476  {
8477  h.pCleardenom();
8478  }
8479  else
8480  {
8481  h.pNorm();
8482  }
8483  if(strat->sl>=0)
8484  {
8486  {
8487  h.p=redBba(h.p,strat->sl,strat);
8488  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8489  {
8490  h.p=redtailBba(h.p,strat->sl,strat);
8491  }
8492  }
8493  else
8494  {
8495  h.p=redMora(h.p,strat->sl,strat);
8496  }
8497  if(h.p!=NULL)
8498  {
8499  strat->initEcart(&h);
8501  {
8502  h.pCleardenom();
8503  }
8504  else
8505  {
8506  h.is_normalized = 0;
8507  h.pNorm();
8508  }
8509  h.sev = pGetShortExpVector(h.p);
8510  h.SetpFDeg();
8511  pos = posInS(strat,strat->sl,h.p,h.ecart);
8512  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8513  strat->enterS(h,pos,strat, strat->tl+1);
8514  enterT(h,strat);
8515  }
8516  }
8517  else
8518  {
8519  h.sev = pGetShortExpVector(h.p);
8520  strat->initEcart(&h);
8521  strat->enterS(h,0,strat, strat->tl+1);
8522  enterT(h,strat);
8523  }
8524  }
8525  }
8526 }
8527 /*2
8528 *construct the set s from F and {P}
8529 */
8530 
8531 void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8532 {
8533  int i,pos;
8534 
8535  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8536  else i=setmaxT;
8537  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8538  strat->sevS=initsevS(i);
8539  strat->sevSig=initsevS(i);
8540  strat->S_2_R=initS_2_R(i);
8541  strat->fromQ=NULL;
8542  strat->Shdl=idInit(i,F->rank);
8543  strat->S=strat->Shdl->m;
8544  strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8545  /*- put polys into S -*/
8546  if (Q!=NULL)
8547  {
8548  strat->fromQ=initec(i);
8549  memset(strat->fromQ,0,i*sizeof(int));
8550  for (i=0; i<IDELEMS(Q); i++)
8551  {
8552  if (Q->m[i]!=NULL)
8553  {
8554  LObject h;
8555  h.p = pCopy(Q->m[i]);
8556  //if (TEST_OPT_INTSTRATEGY)
8557  //{
8558  // h.pCleardenom(); // also does remove Content
8559  //}
8560  //else
8561  //{
8562  // h.pNorm();
8563  //}
8565  {
8566  deleteHC(&h,strat);
8567  }
8568  if (h.p!=NULL)
8569  {
8570  strat->initEcart(&h);
8571  if (strat->sl==-1)
8572  pos =0;
8573  else
8574  {
8575  pos = posInS(strat,strat->sl,h.p,h.ecart);
8576  }
8577  h.sev = pGetShortExpVector(h.p);
8578  strat->enterS(h,pos,strat, strat->tl+1);
8579  enterT(h, strat);
8580  strat->fromQ[pos]=1;
8581  }
8582  }
8583  }
8584  }
8585  /*- put polys into S -*/
8586  for (i=0; i<IDELEMS(F); i++)
8587  {
8588  if (F->m[i]!=NULL)
8589  {
8590  LObject h;
8591  h.p = pCopy(F->m[i]);
8593  {
8594  deleteHC(&h,strat);
8595  }
8596  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8597  {
8598  h.p=redtailBba(h.p,strat->sl,strat);
8599  }
8600  if (h.p!=NULL)
8601  {
8602  strat->initEcart(&h);
8603  if (strat->sl==-1)
8604  pos =0;
8605  else
8606  pos = posInS(strat,strat->sl,h.p,h.ecart);
8607  h.sev = pGetShortExpVector(h.p);
8608  strat->enterS(h,pos,strat, strat->tl+1);
8609  enterT(h,strat);
8610  }
8611  }
8612  }
8613  for (i=0; i<IDELEMS(P); i++)
8614  {
8615  if (P->m[i]!=NULL)
8616  {
8617  LObject h;
8618  h.p=pCopy(P->m[i]);
8620  {
8621  h.pCleardenom();
8622  }
8623  else
8624  {
8625  h.pNorm();
8626  }
8627  if(strat->sl>=0)
8628  {
8630  {
8631  h.p=redBba(h.p,strat->sl,strat);
8632  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8633  {
8634  h.p=redtailBba(h.p,strat->sl,strat);
8635  }
8636  }
8637  else
8638  {
8639  h.p=redMora(h.p,strat->sl,strat);
8640  }
8641  if(h.p!=NULL)
8642  {
8643  strat->initEcart(&h);
8645  {
8646  h.pCleardenom();
8647  }
8648  else
8649  {
8650  h.is_normalized = 0;
8651  h.pNorm();
8652  }
8653  h.sev = pGetShortExpVector(h.p);
8654  h.SetpFDeg();
8655  pos = posInS(strat,strat->sl,h.p,h.ecart);
8656  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8657  strat->enterS(h,pos,strat, strat->tl+1);
8658  enterT(h,strat);
8659  }
8660  }
8661  else
8662  {
8663  h.sev = pGetShortExpVector(h.p);
8664  strat->initEcart(&h);
8665  strat->enterS(h,0,strat, strat->tl+1);
8666  enterT(h,strat);
8667  }
8668  }
8669  }
8670 }
8671 
8672 /*2
8673 * reduces h using the set S
8674 * procedure used in cancelunit1
8675 */
8676 static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8677 {
8678  int j = 0;
8679  unsigned long not_sev = ~ pGetShortExpVector(h);
8680 
8681  while (j <= maxIndex)
8682  {
8683  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8684  return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8685  else j++;
8686  }
8687  return h;
8688 }
8689 
8690 /*2
8691 *tests if p.p=monomial*unit and cancels the unit
8692 */
8693 void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8694 {
8695  int k;
8696  poly r,h,h1,q;
8697 
8698  if (!pIsVector((*p).p) && ((*p).ecart != 0))
8699  {
8700 #ifdef HAVE_RINGS
8701  // Leading coef have to be a unit: no
8702  // example 2x+4x2 should be simplified to 2x*(1+2x)
8703  // and 2 is not a unit in Z
8704  //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8705 #endif
8706  k = 0;
8707  h1 = r = pCopy((*p).p);
8708  h =pNext(r);
8709  loop
8710  {
8711  if (h==NULL)
8712  {
8713  pDelete(&r);
8714  pDelete(&(pNext((*p).p)));
8715  (*p).ecart = 0;
8716  (*p).length = 1;
8717  (*p).pLength = 1;
8718  (*suc)=0;
8719  return;
8720  }
8721  if (!pDivisibleBy(r,h))
8722  {
8723  q=redBba1(h,index ,strat);
8724  if (q != h)
8725  {
8726  k++;
8727  pDelete(&h);
8728  pNext(h1) = h = q;
8729  }
8730  else
8731  {
8732  pDelete(&r);
8733  return;
8734  }
8735  }
8736  else
8737  {
8738  h1 = h;
8739  pIter(h);
8740  }
8741  if (k > 10)
8742  {
8743  pDelete(&r);
8744  return;
8745  }
8746  }
8747  }
8748 }
8749 
8750 #if 0
8751 /*2
8752 * reduces h using the elements from Q in the set S
8753 * procedure used in updateS
8754 * must not be used for elements of Q or elements of an ideal !
8755 */
8756 static poly redQ (poly h, int j, kStrategy strat)
8757 {
8758  int start;
8759  unsigned long not_sev = ~ pGetShortExpVector(h);
8760  while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8761  start=j;
8762  while (j<=strat->sl)
8763  {
8764  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8765  {
8766  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8767  if (h==NULL) return NULL;
8768  j = start;
8769  not_sev = ~ pGetShortExpVector(h);
8770  }
8771  else j++;
8772  }
8773  return h;
8774 }
8775 #endif
8776 
8777 /*2
8778 * reduces h using the set S
8779 * procedure used in updateS
8780 */
8781 static poly redBba (poly h,int maxIndex,kStrategy strat)
8782 {
8783  int j = 0;
8784  unsigned long not_sev = ~ pGetShortExpVector(h);
8785 
8786  while (j <= maxIndex)
8787  {
8788  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8789  {
8790  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8791  if (h==NULL) return NULL;
8792  j = 0;
8793  not_sev = ~ pGetShortExpVector(h);
8794  }
8795  else j++;
8796  }
8797  return h;
8798 }
8799 
8800 /*2
8801 * reduces h using the set S
8802 *e is the ecart of h
8803 *procedure used in updateS
8804 */
8805 static poly redMora (poly h,int maxIndex,kStrategy strat)
8806 {
8807  int j=0;
8808  int e,l;
8809  unsigned long not_sev = ~ pGetShortExpVector(h);
8810 
8811  if (maxIndex >= 0)
8812  {
8813  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8814  do
8815  {
8816  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8817  && ((e >= strat->ecartS[j]) || (strat->kNoether!=NULL)))
8818  {
8819 #ifdef KDEBUG
8820  if (TEST_OPT_DEBUG)
8821  {
8822  PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8823  }
8824 #endif
8825  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8826 #ifdef KDEBUG
8827  if(TEST_OPT_DEBUG)
8828  {
8829  PrintS(")\nto "); wrp(h); PrintLn();
8830  }
8831 #endif
8832  // pDelete(&h);
8833  if (h == NULL) return NULL;
8834  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8835  j = 0;
8836  not_sev = ~ pGetShortExpVector(h);
8837  }
8838  else j++;
8839  }
8840  while (j <= maxIndex);
8841  }
8842  return h;
8843 }
8844 
8845 /*2
8846 *updates S:
8847 *the result is a set of polynomials which are in
8848 *normalform with respect to S
8849 */
8850 void updateS(BOOLEAN toT,kStrategy strat)
8851 {
8852  LObject h;
8853  int i, suc=0;
8854  poly redSi=NULL;
8855  BOOLEAN change,any_change;
8856 // Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8857 // for (i=0; i<=(strat->sl); i++)
8858 // {
8859 // Print("s%d:",i);
8860 // if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8861 // pWrite(strat->S[i]);
8862 // }
8863 // Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8864  any_change=FALSE;
8866  {
8867  while (suc != -1)
8868  {
8869  i=suc+1;
8870  while (i<=strat->sl)
8871  {
8872  change=FALSE;
8874  any_change = FALSE;
8875  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8876  {
8877  redSi = pHead(strat->S[i]);
8878  strat->S[i] = redBba(strat->S[i],i-1,strat);
8879  //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8880  // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8881  if (pCmp(redSi,strat->S[i])!=0)
8882  {
8883  change=TRUE;
8884  any_change=TRUE;
8885  #ifdef KDEBUG
8886  if (TEST_OPT_DEBUG)
8887  {
8888  PrintS("reduce:");
8889  wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8890  }
8891  #endif
8892  if (TEST_OPT_PROT)
8893  {
8894  if (strat->S[i]==NULL)
8895  PrintS("V");
8896  else
8897  PrintS("v");
8898  mflush();
8899  }
8900  }
8901  pLmDelete(&redSi);
8902  if (strat->S[i]==NULL)
8903  {
8904  deleteInS(i,strat);
8905  i--;
8906  }
8907  else if (change)
8908  {
8910  {
8911  if (TEST_OPT_CONTENTSB)
8912  {
8913  number n;
8914  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8915  if (!nIsOne(n))
8916  {
8918  denom->n=nInvers(n);
8919  denom->next=DENOMINATOR_LIST;
8920  DENOMINATOR_LIST=denom;
8921  }
8922  nDelete(&n);
8923  }
8924  else
8925  {
8926  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8927  }
8928  }
8929  else
8930  {
8931  pNorm(strat->S[i]);
8932  }
8933  strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8934  }
8935  }
8936  i++;
8937  }
8938  if (any_change) reorderS(&suc,strat);
8939  else break;
8940  }
8941  if (toT)
8942  {
8943  for (i=0; i<=strat->sl; i++)
8944  {
8945  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8946  {
8947  h.p = redtailBba(strat->S[i],i-1,strat);
8949  {
8950  h.pCleardenom();// also does remove Content
8951  }
8952  }
8953  else
8954  {
8955  h.p = strat->S[i];
8956  }
8957  strat->initEcart(&h);
8958  if (strat->honey)
8959  {
8960  strat->ecartS[i] = h.ecart;
8961  }
8962  if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8963  else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8964  h.sev = strat->sevS[i];
8965  /*puts the elements of S also to T*/
8966  strat->initEcart(&h);
8967  /*if (toT) - already checked*/ enterT(h,strat);
8968  strat->S_2_R[i] = strat->tl;
8969 #ifdef HAVE_SHIFTBBA
8970  if (/*(toT) && */(currRing->isLPring))
8971  enterTShift(h, strat);
8972 #endif
8973  }
8974  }
8975  }
8976  else
8977  {
8978  while (suc != -1)
8979  {
8980  i=suc;
8981  while (i<=strat->sl)
8982  {
8983  change=FALSE;
8984  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8985  {
8986  redSi=pHead((strat->S)[i]);
8987  (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
8988  if ((strat->S)[i]==NULL)
8989  {
8990  deleteInS(i,strat);
8991  i--;
8992  }
8993  else if (pCmp((strat->S)[i],redSi)!=0)
8994  {
8995  any_change=TRUE;
8996  h.p = strat->S[i];
8997  strat->initEcart(&h);
8998  strat->ecartS[i] = h.ecart;
9000  {
9001  if (TEST_OPT_CONTENTSB)
9002  {
9003  number n;
9004  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
9005  if (!nIsOne(n))
9006  {
9008  denom->n=nInvers(n);
9009  denom->next=DENOMINATOR_LIST;
9010  DENOMINATOR_LIST=denom;
9011  }
9012  nDelete(&n);
9013  }
9014  else
9015  {
9016  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
9017  }
9018  }
9019  else
9020  {
9021  pNorm(strat->S[i]); // == h.p
9022  }
9023  h.sev = pGetShortExpVector(h.p);
9024  strat->sevS[i] = h.sev;
9025  }
9026  pLmDelete(&redSi);
9027  kTest(strat);
9028  }
9029  i++;
9030  }
9031 #ifdef KDEBUG
9032  kTest(strat);
9033 #endif
9034  if (any_change) reorderS(&suc,strat);
9035  else { suc=-1; break; }
9036  if (h.p!=NULL)
9037  {
9038  if (!strat->kAllAxis)
9039  {
9040  /*strat->kAllAxis =*/ HEckeTest(h.p,strat);
9041  }
9042  if (strat->kAllAxis)
9043  newHEdge(strat);
9044  }
9045  }
9046  for (i=0; i<=strat->sl; i++)
9047  {
9048  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9049  {
9050  strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
9051  strat->initEcart(&h);
9052  strat->ecartS[i] = h.ecart;
9053  h.sev = pGetShortExpVector(h.p);
9054  strat->sevS[i] = h.sev;
9055  }
9056  else
9057  {
9058  h.p = strat->S[i];
9059  h.ecart=strat->ecartS[i];
9060  h.sev = strat->sevS[i];
9061  h.length = h.pLength = pLength(h.p);
9062  }
9063  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9064  cancelunit1(&h,&suc,strat->sl,strat);
9065  h.SetpFDeg();
9066  /*puts the elements of S also to T*/
9067  enterT(h,strat);
9068  strat->S_2_R[i] = strat->tl;
9069 #ifdef HAVE_SHIFTBBA
9070  if (currRing->isLPring)
9071  enterTShift(h, strat);
9072 #endif
9073  }
9074  if (suc!= -1) updateS(toT,strat);
9075  }
9076 #ifdef KDEBUG
9077  kTest(strat);
9078 #endif
9079 }
9080 
9081 /*2
9082 * -puts p to the standardbasis s at position at
9083 * -saves the result in S
9084 */
9085 void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
9086 {
9087  strat->news = TRUE;
9088  /*- puts p to the standardbasis s at position at -*/
9089  if (strat->sl == IDELEMS(strat->Shdl)-1)
9090  {
9091  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9092  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9093  (IDELEMS(strat->Shdl)+setmaxTinc)
9094  *sizeof(unsigned long));
9095  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9096  IDELEMS(strat->Shdl)*sizeof(int),
9097  (IDELEMS(strat->Shdl)+setmaxTinc)
9098  *sizeof(int));
9099  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9100  IDELEMS(strat->Shdl)*sizeof(int),
9101  (IDELEMS(strat->Shdl)+setmaxTinc)
9102  *sizeof(int));
9103  if (strat->lenS!=NULL)
9104  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9105  IDELEMS(strat->Shdl)*sizeof(int),
9106  (IDELEMS(strat->Shdl)+setmaxTinc)
9107  *sizeof(int));
9108  if (strat->lenSw!=NULL)
9109  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9110  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9111  (IDELEMS(strat->Shdl)+setmaxTinc)
9112  *sizeof(wlen_type));
9113  if (strat->fromQ!=NULL)
9114  {
9115  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9116  IDELEMS(strat->Shdl)*sizeof(int),
9117  (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9118  }
9119  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
9120  IDELEMS(strat->Shdl)+=setmaxTinc;
9121  strat->Shdl->m=strat->S;
9122  }
9123  if (atS <= strat->sl)
9124  {
9125 #ifdef ENTER_USE_MEMMOVE
9126  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9127  (strat->sl - atS + 1)*sizeof(poly));
9128  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9129  (strat->sl - atS + 1)*sizeof(int));
9130  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9131  (strat->sl - atS + 1)*sizeof(unsigned long));
9132  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9133  (strat->sl - atS + 1)*sizeof(int));
9134  if (strat->lenS!=NULL)
9135  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9136  (strat->sl - atS + 1)*sizeof(int));
9137  if (strat->lenSw!=NULL)
9138  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9139  (strat->sl - atS + 1)*sizeof(wlen_type));
9140 #else
9141  for (i=strat->sl+1; i>=atS+1; i--)
9142  {
9143  strat->S[i] = strat->S[i-1];
9144  strat->ecartS[i] = strat->ecartS[i-1];
9145  strat->sevS[i] = strat->sevS[i-1];
9146  strat->S_2_R[i] = strat->S_2_R[i-1];
9147  }
9148  if (strat->lenS!=NULL)
9149  for (i=strat->sl+1; i>=atS+1; i--)
9150  strat->lenS[i] = strat->lenS[i-1];
9151  if (strat->lenSw!=NULL)
9152  for (i=strat->sl+1; i>=atS+1; i--)
9153  strat->lenSw[i] = strat->lenSw[i-1];
9154 #endif
9155  }
9156  if (strat->fromQ!=NULL)
9157  {
9158 #ifdef ENTER_USE_MEMMOVE
9159  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9160  (strat->sl - atS + 1)*sizeof(int));
9161 #else
9162  for (i=strat->sl+1; i>=atS+1; i--)
9163  {
9164  strat->fromQ[i] = strat->fromQ[i-1];
9165  }
9166 #endif
9167  strat->fromQ[atS]=0;
9168  }
9169 
9170  /*- save result -*/
9171  poly pp=p.p;
9172  strat->S[atS] = pp;
9173  if (strat->honey) strat->ecartS[atS] = p.ecart;
9174  if (p.sev == 0)
9175  p.sev = pGetShortExpVector(pp);
9176  else
9177  assume(p.sev == pGetShortExpVector(pp));
9178  strat->sevS[atS] = p.sev;
9179  strat->ecartS[atS] = p.ecart;
9180  strat->S_2_R[atS] = atR;
9181  strat->sl++;
9182 }
9183 
9184 #ifdef HAVE_SHIFTBBA
9185 void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR)
9186 {
9187  enterSBba(p, atS, strat, atR);
9188 
9189  int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
9190  for (int i = maxPossibleShift; i > 0; i--)
9191  {
9192  // NOTE: don't use "shared tails" here. In rare cases it can cause problems
9193  // in `kNF2` because of lazy poly normalizations.
9194  LObject qq(p_Copy(p.p, strat->tailRing));
9195  p_mLPshift(qq.p, i, strat->tailRing);
9196  qq.shift = i;
9197  strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
9198  int atS = posInS(strat, strat->sl, qq.p, qq.ecart); // S needs to stay sorted because this is for example assumed when searching S later
9199  enterSBba(qq, atS, strat, -1);
9200  }
9201 }
9202 #endif
9203 
9204 /*2
9205 * -puts p to the standardbasis s at position at
9206 * -saves the result in S
9207 */
9208 void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
9209 {
9210  strat->news = TRUE;
9211  /*- puts p to the standardbasis s at position at -*/
9212  if (strat->sl == IDELEMS(strat->Shdl)-1)
9213  {
9214  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9215  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9216  (IDELEMS(strat->Shdl)+setmax)
9217  *sizeof(unsigned long));
9218  strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
9219  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9220  (IDELEMS(strat->Shdl)+setmax)
9221  *sizeof(unsigned long));
9222  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9223  IDELEMS(strat->Shdl)*sizeof(int),
9224  (IDELEMS(strat->Shdl)+setmax)
9225  *sizeof(int));
9226  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9227  IDELEMS(strat->Shdl)*sizeof(int),
9228  (IDELEMS(strat->Shdl)+setmax)
9229  *sizeof(int));
9230  if (strat->lenS!=NULL)
9231  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9232  IDELEMS(strat->Shdl)*sizeof(int),
9233  (IDELEMS(strat->Shdl)+setmax)
9234  *sizeof(int));
9235  if (strat->lenSw!=NULL)
9236  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9237  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9238  (IDELEMS(strat->Shdl)+setmax)
9239  *sizeof(wlen_type));
9240  if (strat->fromQ!=NULL)
9241  {
9242  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9243  IDELEMS(strat->Shdl)*sizeof(int),
9244  (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
9245  }
9246  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
9247  pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
9248  IDELEMS(strat->Shdl)+=setmax;
9249  strat->Shdl->m=strat->S;
9250  }
9251  // in a signature-based algorithm the following situation will never
9252  // appear due to the fact that the critical pairs are already sorted
9253  // by increasing signature.
9254  // True. However, in the case of integers we need to put the element
9255  // that caused the signature drop on the first position
9256  if (atS <= strat->sl)
9257  {
9258 #ifdef ENTER_USE_MEMMOVE
9259  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9260  (strat->sl - atS + 1)*sizeof(poly));
9261  memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9262  (strat->sl - atS + 1)*sizeof(poly));
9263  memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9264  (strat->sl - atS + 1)*sizeof(unsigned long));
9265  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9266  (strat->sl - atS + 1)*sizeof(int));
9267  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9268  (strat->sl - atS + 1)*sizeof(unsigned long));
9269  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9270  (strat->sl - atS + 1)*sizeof(int));
9271  if (strat->lenS!=NULL)
9272  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9273  (strat->sl - atS + 1)*sizeof(int));
9274  if (strat->lenSw!=NULL)
9275  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9276  (strat->sl - atS + 1)*sizeof(wlen_type));
9277 #else
9278  for (i=strat->sl+1; i>=atS+1; i--)
9279  {
9280  strat->S[i] = strat->S[i-1];
9281  strat->ecartS[i] = strat->ecartS[i-1];
9282  strat->sevS[i] = strat->sevS[i-1];
9283  strat->S_2_R[i] = strat->S_2_R[i-1];
9284  strat->sig[i] = strat->sig[i-1];
9285  strat->sevSig[i] = strat->sevSig[i-1];
9286  }
9287  if (strat->lenS!=NULL)
9288  for (i=strat->sl+1; i>=atS+1; i--)
9289  strat->lenS[i] = strat->lenS[i-1];
9290  if (strat->lenSw!=NULL)
9291  for (i=strat->sl+1; i>=atS+1; i--)
9292  strat->lenSw[i] = strat->lenSw[i-1];
9293 #endif
9294  }
9295  if (strat->fromQ!=NULL)
9296  {
9297 #ifdef ENTER_USE_MEMMOVE
9298  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9299  (strat->sl - atS + 1)*sizeof(int));
9300 #else
9301  for (i=strat->sl+1; i>=atS+1; i--)
9302  {
9303  strat->fromQ[i] = strat->fromQ[i-1];
9304  }
9305 #endif
9306  strat->fromQ[atS]=0;
9307  }
9308 
9309  /*- save result -*/
9310  strat->S[atS] = p.p;
9311  strat->sig[atS] = p.sig; // TODO: get ths correct signature in here!
9312  if (strat->honey) strat->ecartS[atS] = p.ecart;
9313  if (p.sev == 0)
9314  p.sev = pGetShortExpVector(p.p);
9315  else
9316  assume(p.sev == pGetShortExpVector(p.p));
9317  strat->sevS[atS] = p.sev;
9318  // during the interreduction process of a signature-based algorithm we do not
9319  // compute the signature at this point, but when the whole interreduction
9320  // process finishes, i.e. f5c terminates!
9321  if (p.sig != NULL)
9322  {
9323  if (p.sevSig == 0)
9324  p.sevSig = pGetShortExpVector(p.sig);
9325  else
9326  assume(p.sevSig == pGetShortExpVector(p.sig));
9327  strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9328  }
9329  strat->ecartS[atS] = p.ecart;
9330  strat->S_2_R[atS] = atR;
9331  strat->sl++;
9332 #ifdef DEBUGF5
9333  int k;
9334  Print("--- LIST S: %d ---\n",strat->sl);
9335  for(k=0;k<=strat->sl;k++)
9336  {
9337  pWrite(strat->sig[k]);
9338  }
9339  PrintS("--- LIST S END ---\n");
9340 #endif
9341 }
9342 
9343 void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
9344 {
9345  p.GetP(strat->lmBin);
9346  if (strat->homog) strat->initEcart(&p);
9347  strat->redTailChange=FALSE;
9349  {
9350  p.pCleardenom();
9352  {
9353 #ifdef HAVE_SHIFTBBA
9354  if (rIsLPRing(currRing))
9355  p.p = redtailBba(&p,strat->tl,strat, TRUE,!TEST_OPT_CONTENTSB);
9356  else
9357 #endif
9358  {
9359  p.p = redtailBba(&p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9360  }
9361  p.pCleardenom();
9362  if (strat->redTailChange)
9363  p.t_p=NULL;
9364  if (strat->P.p!=NULL) strat->P.sev=p_GetShortExpVector(strat->P.p,currRing);
9365  else strat->P.sev=0;
9366  }
9367  }
9368 
9369  assume(strat->tailRing == p.tailRing);
9370  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9371 
9372  int i, j, pos;
9373  poly tp = strat->T[tj].p;
9374 
9375  /* enter p to T set */
9376  enterT(p, strat);
9377 
9378  for (j = 0; j <= strat->sl; ++j)
9379  {
9380  if (pLtCmp(tp, strat->S[j]) == 0)
9381  {
9382  break;
9383  }
9384  }
9385  /* it may be that the exchanged element
9386  * is until now only in T and not in S */
9387  if (j <= strat->sl)
9388  {
9389  deleteInS(j, strat);
9390  }
9391 
9392  pos = posInS(strat, strat->sl, p.p, p.ecart);
9393 
9394  pp_Test(p.p, currRing, p.tailRing);
9395  assume(p.FDeg == p.pFDeg());
9396 
9397  /* remove useless pairs from L set */
9398  for (i = 0; i <= strat->Ll; ++i)
9399  {
9400  if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0)
9401  {
9402  deleteInL(strat->L, &(strat->Ll), i, strat);
9403  i--;
9404  continue;
9405  }
9406  if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0)
9407  {
9408  deleteInL(strat->L, &(strat->Ll), i, strat);
9409  i--;
9410  }
9411  }
9412 #ifdef HAVE_SHIFTBBA
9413  if (rIsLPRing(currRing))
9414  enterpairsShift(p.p, strat->sl, p.ecart, pos, strat, strat->tl); // TODO LP
9415  else
9416 #endif
9417  {
9418  /* generate new pairs with p, probably removing older, now useless pairs */
9419  superenterpairs(p.p, strat->sl, p.ecart, pos, strat, strat->tl);
9420  }
9421  /* enter p to S set */
9422  strat->enterS(p, pos, strat, strat->tl);
9423 
9424 #ifdef HAVE_SHIFTBBA
9425  /* do this after enterS so that the index in R (which is strat->tl) is correct */
9426  if (rIsLPRing(currRing) && !strat->rightGB)
9427  enterTShift(p,strat);
9428 #endif
9429 }
9430 
9431 /*2
9432 * puts p to the set T at position atT
9433 */
9434 void enterT(LObject &p, kStrategy strat, int atT)
9435 {
9436  int i;
9437 
9438 #ifdef PDEBUG
9439 #ifdef HAVE_SHIFTBBA
9440  if (currRing->isLPring && p.shift > 0)
9441  {
9442  // in this case, the order is not correct. test LM and tail separately
9443  p_LmTest(p.p, currRing);
9444  p_Test(pNext(p.p), currRing);
9445  }
9446  else
9447 #endif
9448  {
9449  pp_Test(p.p, currRing, p.tailRing);
9450  }
9451 #endif
9452  assume(strat->tailRing == p.tailRing);
9453  // redMoraNF complains about this -- but, we don't really
9454  // neeed this so far
9455  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9456  assume(!strat->homog || (p.FDeg == p.pFDeg()));
9457  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9458 
9459 #ifdef KDEBUG
9460  // do not put an LObject twice into T:
9461  for(i=strat->tl;i>=0;i--)
9462  {
9463  if (p.p==strat->T[i].p)
9464  {
9465  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9466  return;
9467  }
9468  }
9469 #endif
9470 
9471 #ifdef HAVE_TAIL_RING
9472  if (currRing!=strat->tailRing)
9473  {
9474  p.t_p=p.GetLmTailRing();
9475  }
9476 #endif
9477  strat->newt = TRUE;
9478  if (atT < 0)
9479  atT = strat->posInT(strat->T, strat->tl, p);
9480  if (strat->tl == strat->tmax-1)
9481  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9482  if (atT <= strat->tl)
9483  {
9484 #ifdef ENTER_USE_MEMMOVE
9485  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9486  (strat->tl-atT+1)*sizeof(TObject));
9487  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9488  (strat->tl-atT+1)*sizeof(unsigned long));
9489 #endif
9490  for (i=strat->tl+1; i>=atT+1; i--)
9491  {
9492 #ifndef ENTER_USE_MEMMOVE
9493  strat->T[i] = strat->T[i-1];
9494  strat->sevT[i] = strat->sevT[i-1];
9495 #endif
9496  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9497  }
9498  }
9499 
9500  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9501  {
9502 #ifdef HAVE_SHIFTBBA
9503  // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9504  if (!(currRing->isLPring && p.shift > 0))
9505 #endif
9506  {
9508  (strat->tailRing != NULL ?
9509  strat->tailRing : currRing),
9510  strat->tailBin);
9511  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9512  }
9513  }
9514  strat->T[atT] = (TObject) p;
9515  //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9516 
9517  if ((pNext(p.p) != NULL) && (!rIsLPRing(currRing)))
9518  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9519  else
9520  strat->T[atT].max_exp = NULL;
9521 
9522  strat->tl++;
9523  strat->R[strat->tl] = &(strat->T[atT]);
9524  strat->T[atT].i_r = strat->tl;
9525  assume((p.sev == 0) || (pGetShortExpVector(p.p) == p.sev));
9526  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9527  kTest_T(&(strat->T[atT]),strat);
9528 }
9529 
9530 /*2
9531 * puts p to the set T at position atT
9532 */
9533 #ifdef HAVE_RINGS
9534 void enterT_strong(LObject &p, kStrategy strat, int atT)
9535 {
9537  int i;
9538 
9539  pp_Test(p.p, currRing, p.tailRing);
9540  assume(strat->tailRing == p.tailRing);
9541  // redMoraNF complains about this -- but, we don't really
9542  // neeed this so far
9543  assume(p.pLength == 0 || (int)pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9544  assume(p.FDeg == p.pFDeg());
9545  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9546 
9547 #ifdef KDEBUG
9548  // do not put an LObject twice into T:
9549  for(i=strat->tl;i>=0;i--)
9550  {
9551  if (p.p==strat->T[i].p)
9552  {
9553  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9554  return;
9555  }
9556  }
9557 #endif
9558 
9559 #ifdef HAVE_TAIL_RING
9560  if (currRing!=strat->tailRing)
9561  {
9562  p.t_p=p.GetLmTailRing();
9563  }
9564 #endif
9565  strat->newt = TRUE;
9566  if (atT < 0)
9567  atT = strat->posInT(strat->T, strat->tl, p);
9568  if (strat->tl == strat->tmax-1)
9569  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9570  if (atT <= strat->tl)
9571  {
9572 #ifdef ENTER_USE_MEMMOVE
9573  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9574  (strat->tl-atT+1)*sizeof(TObject));
9575  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9576  (strat->tl-atT+1)*sizeof(unsigned long));
9577 #endif
9578  for (i=strat->tl+1; i>=atT+1; i--)
9579  {
9580 #ifndef ENTER_USE_MEMMOVE
9581  strat->T[i] = strat->T[i-1];
9582  strat->sevT[i] = strat->sevT[i-1];
9583 #endif
9584  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9585  }
9586  }
9587 
9588  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9589  {
9591  (strat->tailRing != NULL ?
9592  strat->tailRing : currRing),
9593  strat->tailBin);
9594  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9595  }
9596  strat->T[atT] = (TObject) p;
9597  //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9598 
9599  if (pNext(p.p) != NULL)
9600  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9601  else
9602  strat->T[atT].max_exp = NULL;
9603 
9604  strat->tl++;
9605  strat->R[strat->tl] = &(strat->T[atT]);
9606  strat->T[atT].i_r = strat->tl;
9607  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9608  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9609  #if 1
9611  && !n_IsUnit(p.p->coef, currRing->cf))
9612  {
9613  for(i=strat->tl;i>=0;i--)
9614  {
9615  if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9616  {
9617  enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9618  }
9619  }
9620  }
9621  /*
9622  printf("\nThis is T:\n");
9623  for(i=strat->tl;i>=0;i--)
9624  {
9625  pWrite(strat->T[i].p);
9626  }
9627  //getchar();*/
9628  #endif
9629  kTest_T(&(strat->T[atT]),strat);
9630 }
9631 #endif
9632 
9633 /*2
9634 * puts signature p.sig to the set syz
9635 */
9636 void enterSyz(LObject &p, kStrategy strat, int atT)
9637 {
9638  int i;
9639  strat->newt = TRUE;
9640  if (strat->syzl == strat->syzmax-1)
9641  {
9642  pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9643  strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9644  (strat->syzmax)*sizeof(unsigned long),
9645  ((strat->syzmax)+setmax)
9646  *sizeof(unsigned long));
9647  strat->syzmax += setmax;
9648  }
9649  if (atT < strat->syzl)
9650  {
9651 #ifdef ENTER_USE_MEMMOVE
9652  memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9653  (strat->syzl-atT+1)*sizeof(poly));
9654  memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9655  (strat->syzl-atT+1)*sizeof(unsigned long));
9656 #endif
9657  for (i=strat->syzl; i>=atT+1; i--)
9658  {
9659 #ifndef ENTER_USE_MEMMOVE
9660  strat->syz[i] = strat->syz[i-1];
9661  strat->sevSyz[i] = strat->sevSyz[i-1];
9662 #endif
9663  }
9664  }
9665  //i = strat->syzl;
9666  i = atT;
9667  //Makes sure the syz saves just the signature
9668  #ifdef HAVE_RINGS
9670  pNext(p.sig) = NULL;
9671  #endif
9672  strat->syz[atT] = p.sig;
9673  strat->sevSyz[atT] = p.sevSig;
9674  strat->syzl++;
9675 #if F5DEBUG
9676  Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9677  pWrite(strat->syz[atT]);
9678 #endif
9679  // recheck pairs in strat->L with new rule and delete correspondingly
9680  int cc = strat->Ll;
9681  while (cc>-1)
9682  {
9683  //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9684  //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);
9685  if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9686  strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9687  #ifdef HAVE_RINGS
9688  &&((!rField_is_Ring(currRing))
9689  || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9690  #endif
9691  )
9692  {
9693  //printf("\nYES!\n");
9694  deleteInL(strat->L,&strat->Ll,cc,strat);
9695  }
9696  cc--;
9697  }
9698 //#if 1
9699 #ifdef DEBUGF5
9700  PrintS("--- Syzygies ---\n");
9701  Print("syzl %d\n",strat->syzl);
9702  Print("syzmax %d\n",strat->syzmax);
9703  PrintS("--------------------------------\n");
9704  for(i=0;i<=strat->syzl-1;i++)
9705  {
9706  Print("%d - ",i);
9707  pWrite(strat->syz[i]);
9708  }
9709  PrintS("--------------------------------\n");
9710 #endif
9711 }
9712 
9713 
9714 void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9715 {
9716 
9717  //if the ordering is local, then hilb criterion
9718  //can be used also if the ideal is not homogenous
9720  {
9722  *hilb=NULL;
9723  else
9724  return;
9725  }
9726  if (strat->homog!=isHomog)
9727  {
9728  *hilb=NULL;
9729  }
9730 }
9731 
9733 {
9735  strat->chainCrit=chainCritNormal;
9736  if (TEST_OPT_SB_1)
9737  strat->chainCrit=chainCritOpt_1;
9738 #ifdef HAVE_RINGS
9739  if (rField_is_Ring(currRing))
9740  {
9742  strat->chainCrit=chainCritRing;
9743  }
9744 #endif
9745 #ifdef HAVE_RATGRING
9746  if (rIsRatGRing(currRing))
9747  {
9748  strat->chainCrit=chainCritPart;
9749  /* enterOnePairNormal get rational part in it */
9750  }
9751 #endif
9752  if (TEST_OPT_IDLIFT
9753  && (strat->syzComp==1)
9754  && (!rIsPluralRing(currRing)))
9756 
9757  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9758  strat->Gebauer = strat->homog || strat->sugarCrit;
9759  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9760  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9761  strat->pairtest = NULL;
9762  /* alway use tailreduction, except:
9763  * - in local rings, - in lex order case, -in ring over extensions */
9765  //if(rHasMixedOrdering(currRing)==2)
9766  //{
9767  // strat->noTailReduction =TRUE;
9768  //}
9769 
9770 #ifdef HAVE_PLURAL
9771  // and r is plural_ring
9772  // hence this holds for r a rational_plural_ring
9773  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9774  { //or it has non-quasi-comm type... later
9775  strat->sugarCrit = FALSE;
9776  strat->Gebauer = FALSE;
9777  strat->honey = FALSE;
9778  }
9779 #endif
9780 
9781  // Coefficient ring?
9782  if (rField_is_Ring(currRing))
9783  {
9784  strat->sugarCrit = FALSE;
9785  strat->Gebauer = FALSE;
9786  strat->honey = FALSE;
9787  }
9788  #ifdef KDEBUG
9789  if (TEST_OPT_DEBUG)
9790  {
9791  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9792  else PrintS("ideal/module is not homogeneous\n");
9793  }
9794  #endif
9795 }
9796 
9798 {
9799  //strat->enterOnePair=enterOnePairNormal;
9801  //strat->chainCrit=chainCritNormal;
9802  strat->chainCrit = chainCritSig;
9803  /******************************************
9804  * rewCrit1 and rewCrit2 are already set in
9805  * kSba() in kstd1.cc
9806  *****************************************/
9807  //strat->rewCrit1 = faugereRewCriterion;
9808  if (strat->sbaOrder == 1)
9809  {
9810  strat->syzCrit = syzCriterionInc;
9811  }
9812  else
9813  {
9814  strat->syzCrit = syzCriterion;
9815  }
9816 #ifdef HAVE_RINGS
9817  if (rField_is_Ring(currRing))
9818  {
9820  strat->chainCrit=chainCritRing;
9821  }
9822 #endif
9823 #ifdef HAVE_RATGRING
9824  if (rIsRatGRing(currRing))
9825  {
9826  strat->chainCrit=chainCritPart;
9827  /* enterOnePairNormal get rational part in it */
9828  }
9829 #endif
9830 
9831  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9832  strat->Gebauer = strat->homog || strat->sugarCrit;
9833  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9834  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9835  strat->pairtest = NULL;
9836  /* alway use tailreduction, except:
9837  * - in local rings, - in lex order case, -in ring over extensions */
9840 
9841 #ifdef HAVE_PLURAL
9842  // and r is plural_ring
9843  // hence this holds for r a rational_plural_ring
9844  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9845  { //or it has non-quasi-comm type... later
9846  strat->sugarCrit = FALSE;
9847  strat->Gebauer = FALSE;
9848  strat->honey = FALSE;
9849  }
9850 #endif
9851 
9852  // Coefficient ring?
9853  if (rField_is_Ring(currRing))
9854  {
9855  strat->sugarCrit = FALSE;
9856  strat->Gebauer = FALSE ;
9857  strat->honey = FALSE;
9858  }
9859  #ifdef KDEBUG
9860  if (TEST_OPT_DEBUG)
9861  {
9862  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9863  else PrintS("ideal/module is not homogeneous\n");
9864  }
9865  #endif
9866 }
9867 
9869  (const LSet set, const int length,
9870  LObject* L,const kStrategy strat))
9871 {
9872  if (pos_in_l == posInL110
9873  || pos_in_l == posInL10
9874  #ifdef HAVE_RINGS
9875  || pos_in_l == posInL110Ring
9876  || pos_in_l == posInLRing
9877  #endif
9878  )
9879  return TRUE;
9880 
9881  return FALSE;
9882 }
9883 
9885 {
9887  {
9888  if (strat->honey)
9889  {
9890  strat->posInL = posInL15;
9891  // ok -- here is the deal: from my experiments for Singular-2-0
9892  // I conclude that that posInT_EcartpLength is the best of
9893  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9894  // see the table at the end of this file
9895  if (TEST_OPT_OLDSTD)
9896  strat->posInT = posInT15;
9897  else
9898  strat->posInT = posInT_EcartpLength;
9899  }
9900  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9901  {
9902  strat->posInL = posInL11;
9903  strat->posInT = posInT11;
9904  }
9905  else if (TEST_OPT_INTSTRATEGY)
9906  {
9907  strat->posInL = posInL11;
9908  strat->posInT = posInT11;
9909  }
9910  else
9911  {
9912  strat->posInL = posInL0;
9913  strat->posInT = posInT0;
9914  }
9915  //if (strat->minim>0) strat->posInL =posInLSpecial;
9916  if (strat->homog)
9917  {
9918  strat->posInL = posInL110;
9919  strat->posInT = posInT110;
9920  }
9921  }
9922  else /* local/mixed ordering */
9923  {
9924  if (strat->homog)
9925  {
9926  strat->posInL = posInL11;
9927  strat->posInT = posInT11;
9928  }
9929  else
9930  {
9931  if ((currRing->order[0]==ringorder_c)
9932  ||(currRing->order[0]==ringorder_C))
9933  {
9934  strat->posInL = posInL17_c;
9935  strat->posInT = posInT17_c;
9936  }
9937  else
9938  {
9939  strat->posInL = posInL17;
9940  strat->posInT = posInT17;
9941  }
9942  }
9943  }
9944  if (strat->minim>0) strat->posInL =posInLSpecial;
9945  // for further tests only
9946  if ((BTEST1(11)) || (BTEST1(12)))
9947  strat->posInL = posInL11;
9948  else if ((BTEST1(13)) || (BTEST1(14)))
9949  strat->posInL = posInL13;
9950  else if ((BTEST1(15)) || (BTEST1(16)))
9951  strat->posInL = posInL15;
9952  else if ((BTEST1(17)) || (BTEST1(18)))
9953  strat->posInL = posInL17;
9954  if (BTEST1(11))
9955  strat->posInT = posInT11;
9956  else if (BTEST1(13))
9957  strat->posInT = posInT13;
9958  else if (BTEST1(15))
9959  strat->posInT = posInT15;
9960  else if ((BTEST1(17)))
9961  strat->posInT = posInT17;
9962  else if ((BTEST1(19)))
9963  strat->posInT = posInT19;
9964  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9965  strat->posInT = posInT1;
9967 }
9968 
9969 #ifdef HAVE_RINGS
9971 {
9973  {
9974  if (strat->honey)
9975  {
9976  strat->posInL = posInL15Ring;
9977  // ok -- here is the deal: from my experiments for Singular-2-0
9978  // I conclude that that posInT_EcartpLength is the best of
9979  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9980  // see the table at the end of this file
9981  if (TEST_OPT_OLDSTD)
9982  strat->posInT = posInT15Ring;
9983  else
9984  strat->posInT = posInT_EcartpLength;
9985  }
9986  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9987  {
9988  strat->posInL = posInL11Ring;
9989  strat->posInT = posInT11;
9990  }
9991  else if (TEST_OPT_INTSTRATEGY)
9992  {
9993  strat->posInL = posInL11Ring;
9994  strat->posInT = posInT11;
9995  }
9996  else
9997  {
9998  strat->posInL = posInL0Ring;
9999  strat->posInT = posInT0;
10000  }
10001  //if (strat->minim>0) strat->posInL =posInLSpecial;
10002  if (strat->homog)
10003  {
10004  strat->posInL = posInL110Ring;
10005  strat->posInT = posInT110Ring;
10006  }
10007  }
10008  else
10009  {
10010  if (strat->homog)
10011  {
10012  //printf("\nHere 3\n");
10013  strat->posInL = posInL11Ring;
10014  strat->posInT = posInT11Ring;
10015  }
10016  else
10017  {
10018  if ((currRing->order[0]==ringorder_c)
10019  ||(currRing->order[0]==ringorder_C))
10020  {
10021  strat->posInL = posInL17_cRing;
10022  strat->posInT = posInT17_cRing;
10023  }
10024  else
10025  {
10026  strat->posInL = posInL11Ringls;
10027  strat->posInT = posInT17Ring;
10028  }
10029  }
10030  }
10031  if (strat->minim>0) strat->posInL =posInLSpecial;
10032  // for further tests only
10033  if ((BTEST1(11)) || (BTEST1(12)))
10034  strat->posInL = posInL11Ring;
10035  else if ((BTEST1(13)) || (BTEST1(14)))
10036  strat->posInL = posInL13;
10037  else if ((BTEST1(15)) || (BTEST1(16)))
10038  strat->posInL = posInL15Ring;
10039  else if ((BTEST1(17)) || (BTEST1(18)))
10040  strat->posInL = posInL17Ring;
10041  if (BTEST1(11))
10042  strat->posInT = posInT11Ring;
10043  else if (BTEST1(13))
10044  strat->posInT = posInT13;
10045  else if (BTEST1(15))
10046  strat->posInT = posInT15Ring;
10047  else if ((BTEST1(17)))
10048  strat->posInT = posInT17Ring;
10049  else if ((BTEST1(19)))
10050  strat->posInT = posInT19;
10051  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10052  strat->posInT = posInT1;
10054 }
10055 #endif
10056 
10057 void initBuchMora (ideal F,ideal Q,kStrategy strat)
10058 {
10059  strat->interpt = BTEST1(OPT_INTERRUPT);
10060  /*- creating temp data structures------------------- -*/
10061  //strat->cp = 0; // already by skStragy()
10062  //strat->c3 = 0; // already by skStragy()
10063 #ifdef HAVE_SHIFTBBA
10064  strat->cv = 0; // already by skStragy()
10065 #endif
10066  strat->tail = pInit();
10067  /*- set s -*/
10068  strat->sl = -1;
10069  /*- set L -*/
10070  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10071  strat->Ll = -1;
10072  strat->L = initL(strat->Lmax);
10073  /*- set B -*/
10074  strat->Bmax = setmaxL;
10075  strat->Bl = -1;
10076  strat->B = initL();
10077  /*- set T -*/
10078  strat->tl = -1;
10079  strat->tmax = setmaxT;
10080  strat->T = initT();
10081  strat->R = initR();
10082  strat->sevT = initsevT();
10083  /*- init local data struct.---------------------------------------- -*/
10084  //strat->P.ecart=0; // already by skStragy()
10085  //strat->P.length=0; // already by skStragy()
10086  //strat->P.pLength=0; // already by skStragy()
10088  {
10089  if (strat->kNoether!=NULL)
10090  {
10091  pSetComp(strat->kNoether, strat->ak);
10092  pSetComp(strat->kNoetherTail(), strat->ak);
10093  }
10094  }
10096  {
10097  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10098  }
10099  else
10100  {
10101  if(TEST_OPT_SB_1)
10102  {
10103  int i;
10104  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10105  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10106  {
10107  P->m[i-strat->newIdeal] = F->m[i];
10108  F->m[i] = NULL;
10109  }
10110  initSSpecial(F,Q,P,strat);
10111  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10112  {
10113  F->m[i] = P->m[i-strat->newIdeal];
10114  P->m[i-strat->newIdeal] = NULL;
10115  }
10116  idDelete(&P);
10117  }
10118  else
10119  {
10120  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10121  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
10122  }
10123  }
10124  strat->fromT = FALSE;
10126  if ((!TEST_OPT_SB_1)
10127  || (rField_is_Ring(currRing))
10128  )
10129  {
10130  updateS(TRUE,strat);
10131  }
10132 #ifdef HAVE_SHIFTBBA
10133  if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
10134 #endif
10135  {
10136  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10137  strat->fromQ=NULL;
10138  }
10139  assume(kTest_TS(strat));
10140 }
10141 
10143 {
10144  /*- release temp data -*/
10145  cleanT(strat);
10146  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10147  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10148  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10149  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10150  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10151  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10152  /*- set L: should be empty -*/
10153  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10154  /*- set B: should be empty -*/
10155  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10156  pLmFree(&strat->tail);
10157  strat->syzComp=0;
10158 
10159 #ifdef HAVE_SHIFTBBA
10160  if (rIsLPRing(currRing) && strat->rightGB)
10161  {
10162  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10163  strat->fromQ=NULL;
10164  }
10165 #endif
10166 }
10167 
10168 void initSbaPos (kStrategy strat)
10169 {
10171  {
10172  if (strat->honey)
10173  {
10174  strat->posInL = posInL15;
10175  // ok -- here is the deal: from my experiments for Singular-2-0
10176  // I conclude that that posInT_EcartpLength is the best of
10177  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10178  // see the table at the end of this file
10179  if (TEST_OPT_OLDSTD)
10180  strat->posInT = posInT15;
10181  else
10182  strat->posInT = posInT_EcartpLength;
10183  }
10184  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10185  {
10186  strat->posInL = posInL11;
10187  strat->posInT = posInT11;
10188  }
10189  else if (TEST_OPT_INTSTRATEGY)
10190  {
10191  strat->posInL = posInL11;
10192  strat->posInT = posInT11;
10193  }
10194  else
10195  {
10196  strat->posInL = posInL0;
10197  strat->posInT = posInT0;
10198  }
10199  //if (strat->minim>0) strat->posInL =posInLSpecial;
10200  if (strat->homog)
10201  {
10202  strat->posInL = posInL110;
10203  strat->posInT = posInT110;
10204  }
10205  }
10206  else
10207  {
10208  if (strat->homog)
10209  {
10210  strat->posInL = posInL11;
10211  strat->posInT = posInT11;
10212  }
10213  else
10214  {
10215  if ((currRing->order[0]==ringorder_c)
10216  ||(currRing->order[0]==ringorder_C))
10217  {
10218  strat->posInL = posInL17_c;
10219  strat->posInT = posInT17_c;
10220  }
10221  else
10222  {
10223  strat->posInL = posInL17;
10224  strat->posInT = posInT17;
10225  }
10226  }
10227  }
10228  if (strat->minim>0) strat->posInL =posInLSpecial;
10229  // for further tests only
10230  if ((BTEST1(11)) || (BTEST1(12)))
10231  strat->posInL = posInL11;
10232  else if ((BTEST1(13)) || (BTEST1(14)))
10233  strat->posInL = posInL13;
10234  else if ((BTEST1(15)) || (BTEST1(16)))
10235  strat->posInL = posInL15;
10236  else if ((BTEST1(17)) || (BTEST1(18)))
10237  strat->posInL = posInL17;
10238  if (BTEST1(11))
10239  strat->posInT = posInT11;
10240  else if (BTEST1(13))
10241  strat->posInT = posInT13;
10242  else if (BTEST1(15))
10243  strat->posInT = posInT15;
10244  else if ((BTEST1(17)))
10245  strat->posInT = posInT17;
10246  else if ((BTEST1(19)))
10247  strat->posInT = posInT19;
10248  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10249  strat->posInT = posInT1;
10250  if (rField_is_Ring(currRing))
10251  {
10252  strat->posInL = posInL11Ring;
10253  if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
10254  strat->posInL = posInL11Ringls;
10255  strat->posInT = posInT11;
10256  }
10257  strat->posInLDependsOnLength = FALSE;
10258  strat->posInLSba = posInLSig;
10259  //strat->posInL = posInLSig;
10260  strat->posInL = posInLF5C;
10261  /*
10262  if (rField_is_Ring(currRing))
10263  {
10264  strat->posInLSba = posInLSigRing;
10265  strat->posInL = posInL11Ring;
10266  }*/
10267  //strat->posInT = posInTSig;
10268 }
10269 
10270 void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10271 {
10272  strat->interpt = BTEST1(OPT_INTERRUPT);
10273  //strat->kNoether=NULL; // done by skStrategy
10274  /*- creating temp data structures------------------- -*/
10275  //strat->cp = 0; // done by skStrategy
10276  //strat->c3 = 0; // done by skStrategy
10277  strat->tail = pInit();
10278  /*- set s -*/
10279  strat->sl = -1;
10280  /*- set ps -*/
10281  strat->syzl = -1;
10282  /*- set L -*/
10283  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10284  strat->Ll = -1;
10285  strat->L = initL(strat->Lmax);
10286  /*- set B -*/
10287  strat->Bmax = setmaxL;
10288  strat->Bl = -1;
10289  strat->B = initL();
10290  /*- set T -*/
10291  strat->tl = -1;
10292  strat->tmax = setmaxT;
10293  strat->T = initT();
10294  strat->R = initR();
10295  strat->sevT = initsevT();
10296  /*- init local data struct.---------------------------------------- -*/
10297  //strat->P.ecart=0; // done by skStrategy
10298  //strat->P.length=0; // done by skStrategy
10300  {
10301  if (strat->kNoether!=NULL)
10302  {
10303  pSetComp(strat->kNoether, strat->ak);
10304  pSetComp(strat->kNoetherTail(), strat->ak);
10305  }
10306  }
10308  {
10309  /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10310  }
10311  else
10312  {
10313  if(TEST_OPT_SB_1)
10314  {
10315  int i;
10316  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10317  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10318  {
10319  P->m[i-strat->newIdeal] = F->m[i];
10320  F->m[i] = NULL;
10321  }
10322  initSSpecialSba(F,Q,P,strat);
10323  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10324  {
10325  F->m[i] = P->m[i-strat->newIdeal];
10326  P->m[i-strat->newIdeal] = NULL;
10327  }
10328  idDelete(&P);
10329  }
10330  else
10331  {
10332  initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10333  }
10334  }
10335  //strat->fromT = FALSE; // done by skStrategy
10336  if (!TEST_OPT_SB_1)
10337  {
10338  if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10339  }
10340  //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10341  //strat->fromQ=NULL;
10342  assume(kTest_TS(strat));
10343 }
10344 
10345 void exitSba (kStrategy strat)
10346 {
10347  /*- release temp data -*/
10349  cleanTSbaRing(strat);
10350  else
10351  cleanT(strat);
10352  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10353  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10354  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10355  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10356  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10357  omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10358  if(strat->syzmax>0)
10359  {
10360  omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10361  omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10362  if (strat->sbaOrder == 1)
10363  {
10364  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10365  }
10366  }
10367  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10368  /*- set L: should be empty -*/
10369  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10370  /*- set B: should be empty -*/
10371  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10372  /*- set sig: no need for the signatures anymore -*/
10373  omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10374  pLmDelete(&strat->tail);
10375  strat->syzComp=0;
10376 }
10377 
10378 /*2
10379 * in the case of a standardbase of a module over a qring:
10380 * replace polynomials in i by ak vectors,
10381 * (the polynomial * unit vectors gen(1)..gen(ak)
10382 * in every case (also for ideals:)
10383 * deletes divisible vectors/polynomials
10384 */
10385 void updateResult(ideal r,ideal Q, kStrategy strat)
10386 {
10387  int l;
10388  if (strat->ak>0)
10389  {
10390  for (l=IDELEMS(r)-1;l>=0;l--)
10391  {
10392  if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10393  {
10394  pDelete(&r->m[l]); // and set it to NULL
10395  }
10396  }
10397  int q;
10398  poly p;
10399  if(!rField_is_Ring(currRing))
10400  {
10401  for (l=IDELEMS(r)-1;l>=0;l--)
10402  {
10403  if ((r->m[l]!=NULL)
10404  //&& (strat->syzComp>0)
10405  //&& (pGetComp(r->m[l])<=strat->syzComp)
10406  )
10407  {
10408  for(q=IDELEMS(Q)-1; q>=0;q--)
10409  {
10410  if ((Q->m[q]!=NULL)
10411  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10412  {
10413  if (TEST_OPT_REDSB)
10414  {
10415  p=r->m[l];
10416  r->m[l]=kNF(Q,NULL,p);
10417  pDelete(&p);
10418  }
10419  else
10420  {
10421  pDelete(&r->m[l]); // and set it to NULL
10422  }
10423  break;
10424  }
10425  }
10426  }
10427  }
10428  }
10429  #ifdef HAVE_RINGS
10430  else
10431  {
10432  for (l=IDELEMS(r)-1;l>=0;l--)
10433  {
10434  if ((r->m[l]!=NULL)
10435  //&& (strat->syzComp>0)
10436  //&& (pGetComp(r->m[l])<=strat->syzComp)
10437  )
10438  {
10439  for(q=IDELEMS(Q)-1; q>=0;q--)
10440  {
10441  if ((Q->m[q]!=NULL)
10442  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10443  {
10444  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10445  {
10446  if (TEST_OPT_REDSB)
10447  {
10448  p=r->m[l];
10449  r->m[l]=kNF(Q,NULL,p);
10450  pDelete(&p);
10451  }
10452  else
10453  {
10454  pDelete(&r->m[l]); // and set it to NULL
10455  }
10456  break;
10457  }
10458  }
10459  }
10460  }
10461  }
10462  }
10463  #endif
10464  }
10465  else
10466  {
10467  int q;
10468  poly p;
10469  BOOLEAN reduction_found=FALSE;
10470  if (!rField_is_Ring(currRing))
10471  {
10472  for (l=IDELEMS(r)-1;l>=0;l--)
10473  {
10474  if (r->m[l]!=NULL)
10475  {
10476  for(q=IDELEMS(Q)-1; q>=0;q--)
10477  {
10478  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10479  {
10480  if (TEST_OPT_REDSB)
10481  {
10482  p=r->m[l];
10483  r->m[l]=kNF(Q,NULL,p);
10484  pDelete(&p);
10485  reduction_found=TRUE;
10486  }
10487  else
10488  {
10489  pDelete(&r->m[l]); // and set it to NULL
10490  }
10491  break;
10492  }
10493  }
10494  }
10495  }
10496  }
10497  #ifdef HAVE_RINGS
10498  //Also need divisibility of the leading coefficients
10499  else
10500  {
10501  for (l=IDELEMS(r)-1;l>=0;l--)
10502  {
10503  if (r->m[l]!=NULL)
10504  {
10505  for(q=IDELEMS(Q)-1; q>=0;q--)
10506  {
10507  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10508  {
10509  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10510  {
10511  if (TEST_OPT_REDSB)
10512  {
10513  p=r->m[l];
10514  r->m[l]=kNF(Q,NULL,p);
10515  pDelete(&p);
10516  reduction_found=TRUE;
10517  }
10518  else
10519  {
10520  pDelete(&r->m[l]); // and set it to NULL
10521  }
10522  break;
10523  }
10524  }
10525  }
10526  }
10527  }
10528  }
10529  #endif
10530  if (/*TEST_OPT_REDSB &&*/ reduction_found)
10531  {
10532  #ifdef HAVE_RINGS
10534  {
10535  for (l=IDELEMS(r)-1;l>=0;l--)
10536  {
10537  if (r->m[l]!=NULL)
10538  {
10539  for(q=IDELEMS(r)-1;q>=0;q--)
10540  {
10541  if ((l!=q)
10542  && (r->m[q]!=NULL)
10543  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10544  &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10545  )
10546  {
10547  //If they are equal then take the one with the smallest length
10548  if(pLmDivisibleBy(r->m[q],r->m[l])
10549  && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10550  && (pLength(r->m[q]) < pLength(r->m[l]) ||
10551  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10552  {
10553  pDelete(&r->m[l]);
10554  break;
10555  }
10556  else
10557  pDelete(&r->m[q]);
10558  }
10559  }
10560  }
10561  }
10562  }
10563  else
10564  #endif
10565  {
10566  for (l=IDELEMS(r)-1;l>=0;l--)
10567  {
10568  if (r->m[l]!=NULL)
10569  {
10570  for(q=IDELEMS(r)-1;q>=0;q--)
10571  {
10572  if ((l!=q)
10573  && (r->m[q]!=NULL)
10574  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10575  )
10576  {
10577  //If they are equal then take the one with the smallest length
10578  if(pLmDivisibleBy(r->m[q],r->m[l])
10579  &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10580  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10581  {
10582  pDelete(&r->m[l]);
10583  break;
10584  }
10585  else
10586  pDelete(&r->m[q]);
10587  }
10588  }
10589  }
10590  }
10591  }
10592  }
10593  }
10594  idSkipZeroes(r);
10595 }
10596 
10597 void completeReduce (kStrategy strat, BOOLEAN withT)
10598 {
10599  int i;
10600  int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10601  LObject L;
10602 
10603 #ifdef KDEBUG
10604  // need to set this: during tailreductions of T[i], T[i].max is out of
10605  // sync
10606  sloppy_max = TRUE;
10607 #endif
10608 
10609  strat->noTailReduction = FALSE;
10610  //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10611  if (TEST_OPT_PROT)
10612  {
10613  PrintLn();
10614 // if (timerv) writeTime("standard base computed:");
10615  }
10616  if (TEST_OPT_PROT)
10617  {
10618  Print("(S:%d)",strat->sl);mflush();
10619  }
10620  for (i=strat->sl; i>=low; i--)
10621  {
10622  int end_pos=strat->sl;
10623  if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10624  if (strat->ak==0) end_pos=i-1;
10625  TObject* T_j = strat->s_2_t(i);
10626  if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10627  {
10628  L = *T_j;
10629  #ifdef KDEBUG
10630  if (TEST_OPT_DEBUG)
10631  {
10632  Print("test S[%d]:",i);
10633  p_wrp(L.p,currRing,strat->tailRing);
10634  PrintLn();
10635  }
10636  #endif
10638  strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10639  else
10640  strat->S[i] = redtail(&L, strat->sl, strat);
10641  #ifdef KDEBUG
10642  if (TEST_OPT_DEBUG)
10643  {
10644  Print("to (tailR) S[%d]:",i);
10645  p_wrp(strat->S[i],currRing,strat->tailRing);
10646  PrintLn();
10647  }
10648  #endif
10649 
10650  if (strat->redTailChange)
10651  {
10652  if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10653  if (pNext(T_j->p) != NULL)
10654  T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10655  else
10656  T_j->max_exp = NULL;
10657  }
10659  T_j->pCleardenom();
10660  }
10661  else
10662  {
10663  assume(currRing == strat->tailRing);
10664  #ifdef KDEBUG
10665  if (TEST_OPT_DEBUG)
10666  {
10667  Print("test S[%d]:",i);
10668  p_wrp(strat->S[i],currRing,strat->tailRing);
10669  PrintLn();
10670  }
10671  #endif
10673  strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10674  else
10675  strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10677  {
10678  if (TEST_OPT_CONTENTSB)
10679  {
10680  number n;
10681  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10682  if (!nIsOne(n))
10683  {
10685  denom->n=nInvers(n);
10686  denom->next=DENOMINATOR_LIST;
10687  DENOMINATOR_LIST=denom;
10688  }
10689  nDelete(&n);
10690  }
10691  else
10692  {
10693  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10694  }
10695  }
10696  #ifdef KDEBUG
10697  if (TEST_OPT_DEBUG)
10698  {
10699  Print("to (-tailR) S[%d]:",i);
10700  p_wrp(strat->S[i],currRing,strat->tailRing);
10701  PrintLn();
10702  }
10703  #endif
10704  }
10705  if (TEST_OPT_PROT)
10706  PrintS("-");
10707  }
10708  if (TEST_OPT_PROT) PrintLn();
10709 #ifdef KDEBUG
10710  sloppy_max = FALSE;
10711 #endif
10712 }
10713 
10714 
10715 /*2
10716 * computes the new strat->kNoether and the new pNoether,
10717 * returns TRUE, if pNoether has changed
10718 */
10720 {
10721  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10722  return FALSE;
10723  int i,j;
10724  poly newNoether;
10725 
10726 #if 0
10727  if (currRing->weight_all_1)
10728  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether, strat->tailRing);
10729  else
10730  scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kNoether, strat->tailRing);
10731 #else
10732  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether, strat->tailRing);
10733 #endif
10734  if (strat->kNoether==NULL) return FALSE;
10735  if (strat->t_kNoether != NULL)
10736  {
10737  p_LmFree(strat->t_kNoether, strat->tailRing);
10738  strat->t_kNoether=NULL;
10739  }
10740  if (strat->tailRing != currRing)
10741  strat->t_kNoether = k_LmInit_currRing_2_tailRing(strat->kNoether, strat->tailRing);
10742  /* compare old and new noether*/
10743  newNoether = pLmInit(strat->kNoether);
10744  pSetCoeff0(newNoether,nInit(1));
10745  j = p_FDeg(newNoether,currRing);
10746  for (i=1; i<=(currRing->N); i++)
10747  {
10748  if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
10749  }
10750  pSetm(newNoether);
10751  if (j < HCord) /*- statistics -*/
10752  {
10753  if (TEST_OPT_PROT)
10754  {
10755  Print("H(%d)",j);
10756  mflush();
10757  }
10758  HCord=j;
10759  #ifdef KDEBUG
10760  if (TEST_OPT_DEBUG)
10761  {
10762  Print("H(%d):",j);
10763  wrp(strat->kNoether);
10764  PrintLn();
10765  }
10766  #endif
10767  }
10768  if (pCmp(strat->kNoether,newNoether)!=1)
10769  {
10770  if (strat->kNoether!=NULL) p_LmDelete0(strat->kNoether,currRing);
10771  strat->kNoether=newNoether;
10772  if (strat->t_kNoether != NULL)
10773  {
10774  p_LmFree(strat->t_kNoether, strat->tailRing);
10775  strat->t_kNoether=NULL;
10776  }
10777  if (strat->tailRing != currRing)
10778  strat->t_kNoether = k_LmInit_currRing_2_tailRing(strat->kNoether, strat->tailRing);
10779 
10780  return TRUE;
10781  }
10782  pLmDelete(newNoether);
10783  return FALSE;
10784 }
10785 
10786 /***************************************************************
10787  *
10788  * Routines related for ring changes during std computations
10789  *
10790  ***************************************************************/
10791 BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10792 {
10793  if (strat->overflow) return FALSE;
10794  assume(L->p1 != NULL && L->p2 != NULL);
10795  // shift changes: from 0 to -1
10796  assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10797  assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10798 
10799  if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10800  return FALSE;
10801  // shift changes: extra case inserted
10802  if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10803  {
10804  return TRUE;
10805  }
10806  poly p1_max=NULL;
10807  if ((L->i_r1>=0)&&(strat->R[L->i_r1]!=NULL)) p1_max = (strat->R[L->i_r1])->max_exp;
10808  poly p2_max=NULL;
10809  if ((L->i_r2>=0)&&(strat->R[L->i_r2]!=NULL)) p2_max = (strat->R[L->i_r2])->max_exp;
10810 
10811  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10812  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10813  {
10814  p_LmFree(m1, strat->tailRing);
10815  p_LmFree(m2, strat->tailRing);
10816  m1 = NULL;
10817  m2 = NULL;
10818  return FALSE;
10819  }
10820  return TRUE;
10821 }
10822 
10823 #ifdef HAVE_RINGS
10824 /***************************************************************
10825  *
10826  * Checks, if we can compute the gcd poly / strong pair
10827  * gcd-poly = m1 * R[atR] + m2 * S[atS]
10828  *
10829  ***************************************************************/
10830 BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10831 {
10832  assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10833  //assume(strat->tailRing != currRing);
10834 
10835  poly p1_max = (strat->R[atR])->max_exp;
10836  poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10837 
10838  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10839  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10840  {
10841  return FALSE;
10842  }
10843  return TRUE;
10844 }
10845 #endif
10846 
10847 #ifdef HAVE_RINGS
10848 /*!
10849  used for GB over ZZ: look for constant and monomial elements in the ideal
10850  background: any known constant element of ideal suppresses
10851  intermediate coefficient swell
10852 */
10853 poly preIntegerCheck(const ideal Forig, const ideal Q)
10854 {
10855  if(!nCoeff_is_Z(currRing->cf))
10856  return NULL;
10857  ideal F = idCopy(Forig);
10858  idSkipZeroes(F);
10859  poly pmon;
10860  ring origR = currRing;
10861  ideal monred = idInit(1,1);
10862  for(int i=0; i<idElem(F); i++)
10863  {
10864  if(pNext(F->m[i]) == NULL)
10865  idInsertPoly(monred, pCopy(F->m[i]));
10866  }
10867  int posconst = idPosConstant(F);
10868  if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10869  {
10870  idDelete(&F);
10871  idDelete(&monred);
10872  return NULL;
10873  }
10874  int idelemQ = 0;
10875  if(Q!=NULL)
10876  {
10877  idelemQ = IDELEMS(Q);
10878  for(int i=0; i<idelemQ; i++)
10879  {
10880  if(pNext(Q->m[i]) == NULL)
10881  idInsertPoly(monred, pCopy(Q->m[i]));
10882  }
10883  idSkipZeroes(monred);
10884  posconst = idPosConstant(monred);
10885  //the constant, if found, will be from Q
10886  if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10887  {
10888  pmon = pCopy(monred->m[posconst]);
10889  idDelete(&F);
10890  idDelete(&monred);
10891  return pmon;
10892  }
10893  }
10894  ring QQ_ring = rCopy0(currRing,FALSE);
10895  nKillChar(QQ_ring->cf);
10896  QQ_ring->cf = nInitChar(n_Q, NULL);
10897  rComplete(QQ_ring,1);
10898  QQ_ring = rAssure_c_dp(QQ_ring);
10899  rChangeCurrRing(QQ_ring);
10900  nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10901  ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10902  for(int i = 0, j = 0; i<IDELEMS(F); i++)
10903  II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10904  for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10905  II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10906  ideal one = kStd(II, NULL, isNotHomog, NULL);
10907  idSkipZeroes(one);
10908  if(idIsConstant(one))
10909  {
10910  //one should be <1>
10911  for(int i = IDELEMS(II)-1; i>=0; i--)
10912  if(II->m[i] != NULL)
10913  II->m[i+1] = II->m[i];
10914  II->m[0] = pOne();
10915  ideal syz = idSyzygies(II, isNotHomog, NULL);
10916  poly integer = NULL;
10917  for(int i = IDELEMS(syz)-1;i>=0; i--)
10918  {
10919  if(pGetComp(syz->m[i]) == 1)
10920  {
10921  pSetComp(syz->m[i],0);
10922  if(pIsConstant(pHead(syz->m[i])))
10923  {
10924  integer = pHead(syz->m[i]);
10925  break;
10926  }
10927  }
10928  }
10929  rChangeCurrRing(origR);
10930  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10931  pmon = prMapR(integer, nMap2, QQ_ring, origR);
10932  idDelete(&monred);
10933  idDelete(&F);
10934  id_Delete(&II,QQ_ring);
10935  id_Delete(&one,QQ_ring);
10936  id_Delete(&syz,QQ_ring);
10937  p_Delete(&integer,QQ_ring);
10938  rDelete(QQ_ring);
10939  return pmon;
10940  }
10941  else
10942  {
10943  if(idIs0(monred))
10944  {
10945  poly mindegmon = NULL;
10946  for(int i = 0; i<IDELEMS(one); i++)
10947  {
10948  if(pNext(one->m[i]) == NULL)
10949  {
10950  if(mindegmon == NULL)
10951  mindegmon = pCopy(one->m[i]);
10952  else
10953  {
10954  if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10955  mindegmon = pCopy(one->m[i]);
10956  }
10957  }
10958  }
10959  if(mindegmon != NULL)
10960  {
10961  for(int i = IDELEMS(II)-1; i>=0; i--)
10962  if(II->m[i] != NULL)
10963  II->m[i+1] = II->m[i];
10964  II->m[0] = pCopy(mindegmon);
10965  ideal syz = idSyzygies(II, isNotHomog, NULL);
10966  bool found = FALSE;
10967  for(int i = IDELEMS(syz)-1;i>=0; i--)
10968  {
10969  if(pGetComp(syz->m[i]) == 1)
10970  {
10971  pSetComp(syz->m[i],0);
10972  if(pIsConstant(pHead(syz->m[i])))
10973  {
10974  pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10975  found = TRUE;
10976  break;
10977  }
10978  }
10979  }
10980  id_Delete(&syz,QQ_ring);
10981  if (found == FALSE)
10982  {
10983  rChangeCurrRing(origR);
10984  idDelete(&monred);
10985  idDelete(&F);
10986  id_Delete(&II,QQ_ring);
10987  id_Delete(&one,QQ_ring);
10988  rDelete(QQ_ring);
10989  return NULL;
10990  }
10991  rChangeCurrRing(origR);
10992  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10993  pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
10994  idDelete(&monred);
10995  idDelete(&F);
10996  id_Delete(&II,QQ_ring);
10997  id_Delete(&one,QQ_ring);
10998  id_Delete(&syz,QQ_ring);
10999  rDelete(QQ_ring);
11000  return pmon;
11001  }
11002  }
11003  }
11004  rChangeCurrRing(origR);
11005  idDelete(&monred);
11006  idDelete(&F);
11007  id_Delete(&II,QQ_ring);
11008  id_Delete(&one,QQ_ring);
11009  rDelete(QQ_ring);
11010  return NULL;
11011 }
11012 #endif
11013 
11014 #ifdef HAVE_RINGS
11015 /*!
11016  used for GB over ZZ: intermediate reduction by monomial elements
11017  background: any known constant element of ideal suppresses
11018  intermediate coefficient swell
11019 */
11021 {
11022  if(!nCoeff_is_Z(currRing->cf))
11023  return;
11024  poly pH = h->GetP();
11025  poly p,pp;
11026  p = pH;
11027  bool deleted = FALSE, ok = FALSE;
11028  for(int i = 0; i<=strat->sl; i++)
11029  {
11030  p = pH;
11031  if(pNext(strat->S[i]) == NULL)
11032  {
11033  //pWrite(p);
11034  //pWrite(strat->S[i]);
11035  while(ok == FALSE && p != NULL)
11036  {
11037  if(pLmDivisibleBy(strat->S[i], p)
11038 #ifdef HAVE_SHIFTBBA
11039  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], p))
11040 #endif
11041  )
11042  {
11043  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11044  p_SetCoeff(p,dummy,currRing);
11045  }
11046  if(nIsZero(p->coef))
11047  {
11048  pLmDelete(&p);
11049  h->p = p;
11050  deleted = TRUE;
11051  }
11052  else
11053  {
11054  ok = TRUE;
11055  }
11056  }
11057  if (p!=NULL)
11058  {
11059  pp = pNext(p);
11060  while(pp != NULL)
11061  {
11062  if(pLmDivisibleBy(strat->S[i], pp)
11063 #ifdef HAVE_SHIFTBBA
11064  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], pp))
11065 #endif
11066  )
11067  {
11068  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11069  p_SetCoeff(pp,dummy,currRing);
11070  if(nIsZero(pp->coef))
11071  {
11072  pLmDelete(&pNext(p));
11073  pp = pNext(p);
11074  deleted = TRUE;
11075  }
11076  else
11077  {
11078  p = pp;
11079  pp = pNext(p);
11080  }
11081  }
11082  else
11083  {
11084  p = pp;
11085  pp = pNext(p);
11086  }
11087  }
11088  }
11089  }
11090  }
11091  h->SetLmCurrRing();
11092  if((deleted)&&(h->p!=NULL))
11093  strat->initEcart(h);
11094 }
11095 
11097 {
11098  if(!nCoeff_is_Z(currRing->cf))
11099  return;
11100  poly hSig = h->sig;
11101  poly pH = h->GetP();
11102  poly p,pp;
11103  p = pH;
11104  bool deleted = FALSE, ok = FALSE;
11105  for(int i = 0; i<=strat->sl; i++)
11106  {
11107  p = pH;
11108  if(pNext(strat->S[i]) == NULL)
11109  {
11110  while(ok == FALSE && p!=NULL)
11111  {
11112  if(pLmDivisibleBy(strat->S[i], p))
11113  {
11114  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11115  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11116  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11117  {
11118  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11119  p_SetCoeff(p,dummy,currRing);
11120  }
11121  pDelete(&sigMult);
11122  }
11123  if(nIsZero(p->coef))
11124  {
11125  pLmDelete(&p);
11126  h->p = p;
11127  deleted = TRUE;
11128  }
11129  else
11130  {
11131  ok = TRUE;
11132  }
11133  }
11134  if(p == NULL)
11135  return;
11136  pp = pNext(p);
11137  while(pp != NULL)
11138  {
11139  if(pLmDivisibleBy(strat->S[i], pp))
11140  {
11141  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11142  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11143  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11144  {
11145  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11146  p_SetCoeff(pp,dummy,currRing);
11147  if(nIsZero(pp->coef))
11148  {
11149  pLmDelete(&pNext(p));
11150  pp = pNext(p);
11151  deleted = TRUE;
11152  }
11153  else
11154  {
11155  p = pp;
11156  pp = pNext(p);
11157  }
11158  }
11159  else
11160  {
11161  p = pp;
11162  pp = pNext(p);
11163  }
11164  pDelete(&sigMult);
11165  }
11166  else
11167  {
11168  p = pp;
11169  pp = pNext(p);
11170  }
11171  }
11172  }
11173  }
11174  h->SetLmCurrRing();
11175  if(deleted)
11176  strat->initEcart(h);
11177 
11178 }
11179 
11180 /*!
11181  used for GB over ZZ: final reduction by constant elements
11182  background: any known constant element of ideal suppresses
11183  intermediate coefficient swell and beautifies output
11184 */
11186 {
11187  assume(strat->tl<0); /* can only be called with no elements in T:
11188  i.e. after exitBuchMora */
11189  /* do not use strat->S, strat->sl as they may be out of sync*/
11190  if(!nCoeff_is_Z(currRing->cf))
11191  return;
11192  poly p,pp;
11193  for(int j = 0; j<IDELEMS(strat->Shdl); j++)
11194  {
11195  if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
11196  {
11197  for(int i = 0; i<IDELEMS(strat->Shdl); i++)
11198  {
11199  if((i != j) && (strat->Shdl->m[i] != NULL))
11200  {
11201  p = strat->Shdl->m[i];
11202  while((p!=NULL) && (pLmDivisibleBy(strat->Shdl->m[j], p)
11203 #if HAVE_SHIFTBBA
11204  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], p))
11205 #endif
11206  ))
11207  {
11208  number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
11209  if (!nEqual(dummy,p->coef))
11210  {
11211  if (nIsZero(dummy))
11212  {
11213  nDelete(&dummy);
11214  pLmDelete(&strat->Shdl->m[i]);
11215  p=strat->Shdl->m[i];
11216  }
11217  else
11218  {
11219  p_SetCoeff(p,dummy,currRing);
11220  break;
11221  }
11222  }
11223  else
11224  {
11225  nDelete(&dummy);
11226  break;
11227  }
11228  }
11229  if (p!=NULL)
11230  {
11231  pp = pNext(p);
11232  while(pp != NULL)
11233  {
11234  if(pLmDivisibleBy(strat->Shdl->m[j], pp)
11235 #if HAVE_SHIFTBBA
11236  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], pp))
11237 #endif
11238  )
11239  {
11240  number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
11241  if (!nEqual(dummy,pp->coef))
11242  {
11243  p_SetCoeff(pp,dummy,currRing);
11244  if(nIsZero(pp->coef))
11245  {
11246  pLmDelete(&pNext(p));
11247  pp = pNext(p);
11248  }
11249  else
11250  {
11251  p = pp;
11252  pp = pNext(p);
11253  }
11254  }
11255  else
11256  {
11257  nDelete(&dummy);
11258  p = pp;
11259  pp = pNext(p);
11260  }
11261  }
11262  else
11263  {
11264  p = pp;
11265  pp = pNext(p);
11266  }
11267  }
11268  }
11269  }
11270  }
11271  //idPrint(strat->Shdl);
11272  }
11273  }
11274  idSkipZeroes(strat->Shdl);
11275 }
11276 #endif
11277 
11278 BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
11279 {
11280  assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11281  /* initial setup or extending */
11282 
11283  if (rIsLPRing(currRing)) return TRUE;
11284  if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11285  if (expbound >= currRing->bitmask) return FALSE;
11286  strat->overflow=FALSE;
11287  ring new_tailRing = rModifyRing(currRing,
11288  // Hmmm .. the condition pFDeg == p_Deg
11289  // might be too strong
11290  (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11291  (strat->ak==0), // omit_comp if the input is an ideal
11292  expbound); // exp_limit
11293 
11294  if (new_tailRing == currRing) return TRUE;
11295 
11296  strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11297  strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11298 
11299  if (currRing->pFDeg != currRing->pFDegOrig)
11300  {
11301  new_tailRing->pFDeg = currRing->pFDeg;
11302  new_tailRing->pLDeg = currRing->pLDeg;
11303  }
11304 
11305  if (TEST_OPT_PROT)
11306  Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11307  kTest_TS(strat);
11308  assume(new_tailRing != strat->tailRing);
11309  pShallowCopyDeleteProc p_shallow_copy_delete
11310  = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11311 
11312  omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11313 
11314  int i;
11315  for (i=0; i<=strat->tl; i++)
11316  {
11317  strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11318  p_shallow_copy_delete);
11319  }
11320  for (i=0; i<=strat->Ll; i++)
11321  {
11322  assume(strat->L[i].p != NULL);
11323  if (pNext(strat->L[i].p) != strat->tail)
11324  strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11325  }
11326  if ((strat->P.t_p != NULL) ||
11327  ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11328  strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11329 
11330  if ((L != NULL) && (L->tailRing != new_tailRing))
11331  {
11332  if (L->i_r < 0)
11333  L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11334  else
11335  {
11336  assume(L->i_r <= strat->tl);
11337  TObject* t_l = strat->R[L->i_r];
11338  assume(t_l != NULL);
11339  L->tailRing = new_tailRing;
11340  L->p = t_l->p;
11341  L->t_p = t_l->t_p;
11342  L->max_exp = t_l->max_exp;
11343  }
11344  }
11345 
11346  if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11347  T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11348 
11349  omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11350  if (strat->tailRing != currRing)
11351  rKillModifiedRing(strat->tailRing);
11352 
11353  strat->tailRing = new_tailRing;
11354  strat->tailBin = new_tailBin;
11355  strat->p_shallow_copy_delete
11356  = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11357 
11358  if (strat->kNoether != NULL)
11359  {
11360  if (strat->t_kNoether != NULL)
11361  p_LmFree(strat->t_kNoether, strat->tailRing);
11362  strat->t_kNoether=k_LmInit_currRing_2_tailRing(strat->kNoether, new_tailRing);
11363  }
11364 
11365  kTest_TS(strat);
11366  if (TEST_OPT_PROT)
11367  PrintS("]");
11368  return TRUE;
11369 }
11370 
11372 {
11373  unsigned long l = 0;
11374  int i;
11375  long e;
11376 
11377  assume(strat->tailRing == currRing);
11378 
11379  for (i=0; i<= strat->Ll; i++)
11380  {
11381  l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11382  }
11383  for (i=0; i<=strat->tl; i++)
11384  {
11385  // Hmm ... this we could do in one Step
11386  l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11387  }
11388  if (rField_is_Ring(currRing))
11389  {
11390  l *= 2;
11391  }
11392  e = p_GetMaxExp(l, currRing);
11393  if (e <= 1) e = 2;
11394  if (rIsLPRing(currRing)) e = 1;
11395 
11396  kStratChangeTailRing(strat, NULL, NULL, e);
11397 }
11398 
11399 ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11400 {
11401  int n = rBlocks(r); // Including trailing zero!
11402  // if sbaOrder == 1 => use (C,monomial order from r)
11403  if (strat->sbaOrder == 1)
11404  {
11405  if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11406  {
11407  return r;
11408  }
11409  ring res = rCopy0(r, TRUE, FALSE);
11410  res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11411  res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11412  res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11413  int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11414  res->wvhdl = wvhdl;
11415  for (int i=1; i<n; i++)
11416  {
11417  res->order[i] = r->order[i-1];
11418  res->block0[i] = r->block0[i-1];
11419  res->block1[i] = r->block1[i-1];
11420  res->wvhdl[i] = r->wvhdl[i-1];
11421  }
11422 
11423  // new 1st block
11424  res->order[0] = ringorder_C; // Prefix
11425  // removes useless secondary component order if defined in old ring
11426  for (int i=rBlocks(res); i>0; --i)
11427  {
11428  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11429  {
11430  res->order[i] = (rRingOrder_t)0;
11431  }
11432  }
11433  rComplete(res, 1);
11434 #ifdef HAVE_PLURAL
11435  if (rIsPluralRing(r))
11436  {
11437  if ( nc_rComplete(r, res, false) ) // no qideal!
11438  {
11439 #ifndef SING_NDEBUG
11440  WarnS("error in nc_rComplete");
11441 #endif
11442  // cleanup?
11443 
11444  // rDelete(res);
11445  // return r;
11446 
11447  // just go on..
11448  }
11449  }
11450 #endif
11451  strat->tailRing = res;
11452  return (res);
11453  }
11454  // if sbaOrder == 3 => degree - position - ring order
11455  if (strat->sbaOrder == 3)
11456  {
11457  ring res = rCopy0(r, TRUE, FALSE);
11458  res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11459  res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11460  res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11461  int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11462  res->wvhdl = wvhdl;
11463  for (int i=2; i<n+2; i++)
11464  {
11465  res->order[i] = r->order[i-2];
11466  res->block0[i] = r->block0[i-2];
11467  res->block1[i] = r->block1[i-2];
11468  res->wvhdl[i] = r->wvhdl[i-2];
11469  }
11470 
11471  // new 1st block
11472  res->order[0] = ringorder_a; // Prefix
11473  res->block0[0] = 1;
11474  res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11475  for (int i=0; i<res->N; ++i)
11476  res->wvhdl[0][i] = 1;
11477  res->block1[0] = si_min(res->N, rVar(res));
11478  // new 2nd block
11479  res->order[1] = ringorder_C; // Prefix
11480  res->wvhdl[1] = NULL;
11481  // removes useless secondary component order if defined in old ring
11482  for (int i=rBlocks(res); i>1; --i)
11483  {
11484  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11485  {
11486  res->order[i] = (rRingOrder_t)0;
11487  }
11488  }
11489  rComplete(res, 1);
11490 #ifdef HAVE_PLURAL
11491  if (rIsPluralRing(r))
11492  {
11493  if ( nc_rComplete(r, res, false) ) // no qideal!
11494  {
11495 #ifndef SING_NDEBUG
11496  WarnS("error in nc_rComplete");
11497 #endif
11498  // cleanup?
11499 
11500  // rDelete(res);
11501  // return r;
11502 
11503  // just go on..
11504  }
11505  }
11506 #endif
11507  strat->tailRing = res;
11508  return (res);
11509  }
11510 
11511  // not sbaOrder == 1 => use Schreyer order
11512  // this is done by a trick when initializing the signatures
11513  // in initSLSba():
11514  // Instead of using the signature 1e_i for F->m[i], we start
11515  // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11516  // Schreyer order w.r.t. the underlying monomial order.
11517  // => we do not need to change the underlying polynomial ring at all!
11518 
11519  // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11520 
11521  /*
11522  else
11523  {
11524  ring res = rCopy0(r, FALSE, FALSE);
11525  // Create 2 more blocks for prefix/suffix:
11526  res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11527  res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11528  res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11529  int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11530 
11531  // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11532  // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11533 
11534  // new 1st block
11535  int j = 0;
11536  res->order[j] = ringorder_IS; // Prefix
11537  res->block0[j] = res->block1[j] = 0;
11538  // wvhdl[j] = NULL;
11539  j++;
11540 
11541  for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11542  {
11543  res->order [j] = r->order [i];
11544  res->block0[j] = r->block0[i];
11545  res->block1[j] = r->block1[i];
11546 
11547  if (r->wvhdl[i] != NULL)
11548  {
11549  wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11550  } // else wvhdl[j] = NULL;
11551  }
11552 
11553  // new last block
11554  res->order [j] = ringorder_IS; // Suffix
11555  res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11556  // wvhdl[j] = NULL;
11557  j++;
11558 
11559  // res->order [j] = 0; // The End!
11560  res->wvhdl = wvhdl;
11561 
11562  // j == the last zero block now!
11563  assume(j == (n+1));
11564  assume(res->order[0]==ringorder_IS);
11565  assume(res->order[j-1]==ringorder_IS);
11566  assume(res->order[j]==0);
11567 
11568  if (complete)
11569  {
11570  rComplete(res, 1);
11571 
11572 #ifdef HAVE_PLURAL
11573  if (rIsPluralRing(r))
11574  {
11575  if ( nc_rComplete(r, res, false) ) // no qideal!
11576  {
11577  }
11578  }
11579  assume(rIsPluralRing(r) == rIsPluralRing(res));
11580 #endif
11581 
11582 
11583 #ifdef HAVE_PLURAL
11584  ring old_ring = r;
11585 
11586 #endif
11587 
11588  if (r->qideal!=NULL)
11589  {
11590  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11591 
11592  assume(idRankFreeModule(res->qideal, res) == 0);
11593 
11594 #ifdef HAVE_PLURAL
11595  if( rIsPluralRing(res) )
11596  if( nc_SetupQuotient(res, r, true) )
11597  {
11598  // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11599  }
11600 
11601 #endif
11602  assume(idRankFreeModule(res->qideal, res) == 0);
11603  }
11604 
11605 #ifdef HAVE_PLURAL
11606  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11607  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11608  assume(rIsSCA(res) == rIsSCA(old_ring));
11609  assume(ncRingType(res) == ncRingType(old_ring));
11610 #endif
11611  }
11612  strat->tailRing = res;
11613  return res;
11614  }
11615  */
11616 
11617  assume(FALSE);
11618  return(NULL);
11619 }
11620 
11622 {
11623  memset(this, 0, sizeof(skStrategy));
11624  strat_nr++;
11625  nr=strat_nr;
11626  tailRing = currRing;
11627  P.tailRing = currRing;
11628  tl = -1;
11629  sl = -1;
11630 #ifdef HAVE_LM_BIN
11631  lmBin = omGetStickyBinOfBin(currRing->PolyBin);
11632 #endif
11633 #ifdef HAVE_TAIL_BIN
11634  tailBin = omGetStickyBinOfBin(currRing->PolyBin);
11635 #endif
11636  pOrigFDeg = currRing->pFDeg;
11637  pOrigLDeg = currRing->pLDeg;
11638 }
11639 
11640 
11642 {
11643  if (lmBin != NULL)
11645  if (tailBin != NULL)// && !rField_is_Ring(currRing))
11647  ((tailRing != NULL) ? tailRing->PolyBin:
11648  currRing->PolyBin));
11649  if (t_kNoether != NULL)
11651 
11652  if (currRing != tailRing)
11655 }
11656 
11657 #if 0
11658 Timings for the different possibilities of posInT:
11659  T15 EDL DL EL L 1-2-3
11660 Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11661 Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11662 Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11663 ahml 4.48 4.03 4.03 4.38 4.96 26.50
11664 c7 15.02 13.98 15.16 13.24 17.31 47.89
11665 c8 505.09 407.46 852.76 413.21 499.19 n/a
11666 f855 12.65 9.27 14.97 8.78 14.23 33.12
11667 gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11668 gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11669 ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11670 noon8 40.68 37.02 37.99 36.82 35.59 877.16
11671 rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11672 rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11673 schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11674 test016 16.39 14.17 14.40 13.50 14.26 34.07
11675 test017 34.70 36.01 33.16 35.48 32.75 71.45
11676 test042 10.76 10.99 10.27 11.57 10.45 23.04
11677 test058 6.78 6.75 6.51 6.95 6.22 9.47
11678 test066 10.71 10.94 10.76 10.61 10.56 19.06
11679 test073 10.75 11.11 10.17 10.79 8.63 58.10
11680 test086 12.23 11.81 12.88 12.24 13.37 66.68
11681 test103 5.05 4.80 5.47 4.64 4.89 11.90
11682 test154 12.96 11.64 13.51 12.46 14.61 36.35
11683 test162 65.27 64.01 67.35 59.79 67.54 196.46
11684 test164 7.50 6.50 7.68 6.70 7.96 17.13
11685 virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11686 #endif
11687 
11688 
11689 //#ifdef HAVE_MORE_POS_IN_T
11690 #if 1
11691 // determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11692 int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p)
11693 {
11694 
11695  if (length==-1) return 0;
11696 
11697  int o = p.ecart;
11698  int op=p.GetpFDeg();
11699  int ol = p.GetpLength();
11700 
11701  if (set[length].ecart < o)
11702  return length+1;
11703  if (set[length].ecart == o)
11704  {
11705  int oo=set[length].GetpFDeg();
11706  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11707  return length+1;
11708  }
11709 
11710  int i;
11711  int an = 0;
11712  int en= length;
11713  loop
11714  {
11715  if (an >= en-1)
11716  {
11717  if (set[an].ecart > o)
11718  return an;
11719  if (set[an].ecart == o)
11720  {
11721  int oo=set[an].GetpFDeg();
11722  if((oo > op)
11723  || ((oo==op) && (set[an].pLength > ol)))
11724  return an;
11725  }
11726  return en;
11727  }
11728  i=(an+en) / 2;
11729  if (set[i].ecart > o)
11730  en=i;
11731  else if (set[i].ecart == o)
11732  {
11733  int oo=set[i].GetpFDeg();
11734  if ((oo > op)
11735  || ((oo == op) && (set[i].pLength > ol)))
11736  en=i;
11737  else
11738  an=i;
11739  }
11740  else
11741  an=i;
11742  }
11743 }
11744 
11745 // determines the position based on: 1.) FDeg 2.) pLength
11746 int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11747 {
11748 
11749  if (length==-1) return 0;
11750 
11751  int op=p.GetpFDeg();
11752  int ol = p.GetpLength();
11753 
11754  int oo=set[length].GetpFDeg();
11755  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11756  return length+1;
11757 
11758  int i;
11759  int an = 0;
11760  int en= length;
11761  loop
11762  {
11763  if (an >= en-1)
11764  {
11765  int oo=set[an].GetpFDeg();
11766  if((oo > op)
11767  || ((oo==op) && (set[an].pLength > ol)))
11768  return an;
11769  return en;
11770  }
11771  i=(an+en) / 2;
11772  int oo=set[i].GetpFDeg();
11773  if ((oo > op)
11774  || ((oo == op) && (set[i].pLength > ol)))
11775  en=i;
11776  else
11777  an=i;
11778  }
11779 }
11780 
11781 
11782 // determines the position based on: 1.) pLength
11783 int posInT_pLength(const TSet set,const int length,LObject &p)
11784 {
11785  int ol = p.GetpLength();
11786  if (length==-1)
11787  return 0;
11788  if (set[length].length<p.length)
11789  return length+1;
11790 
11791  int i;
11792  int an = 0;
11793  int en= length;
11794 
11795  loop
11796  {
11797  if (an >= en-1)
11798  {
11799  if (set[an].pLength>ol) return an;
11800  return en;
11801  }
11802  i=(an+en) / 2;
11803  if (set[i].pLength>ol) en=i;
11804  else an=i;
11805  }
11806 }
11807 #endif
11808 
11809 // kstd1.cc:
11810 int redFirst (LObject* h,kStrategy strat);
11811 int redEcart (LObject* h,kStrategy strat);
11812 void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11813 void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11814 // ../Singular/misc.cc:
11815 extern char * showOption();
11816 
11818 {
11819  PrintS("red: ");
11820  if (strat->red==redFirst) PrintS("redFirst\n");
11821  else if (strat->red==redHoney) PrintS("redHoney\n");
11822  else if (strat->red==redEcart) PrintS("redEcart\n");
11823  else if (strat->red==redHomog) PrintS("redHomog\n");
11824  else if (strat->red==redLazy) PrintS("redLazy\n");
11825  else if (strat->red==redLiftstd) PrintS("redLiftstd\n");
11826  else Print("%p\n",(void*)strat->red);
11827  PrintS("posInT: ");
11828  if (strat->posInT==posInT0) PrintS("posInT0\n");
11829  else if (strat->posInT==posInT1) PrintS("posInT1\n");
11830  else if (strat->posInT==posInT11) PrintS("posInT11\n");
11831  else if (strat->posInT==posInT110) PrintS("posInT110\n");
11832  else if (strat->posInT==posInT13) PrintS("posInT13\n");
11833  else if (strat->posInT==posInT15) PrintS("posInT15\n");
11834  else if (strat->posInT==posInT17) PrintS("posInT17\n");
11835  else if (strat->posInT==posInT17_c) PrintS("posInT17_c\n");
11836  else if (strat->posInT==posInT19) PrintS("posInT19\n");
11837  else if (strat->posInT==posInT2) PrintS("posInT2\n");
11838  #ifdef HAVE_RINGS
11839  else if (strat->posInT==posInT11Ring) PrintS("posInT11Ring\n");
11840  else if (strat->posInT==posInT110Ring) PrintS("posInT110Ring\n");
11841  else if (strat->posInT==posInT15Ring) PrintS("posInT15Ring\n");
11842  else if (strat->posInT==posInT17Ring) PrintS("posInT17Ring\n");
11843  else if (strat->posInT==posInT17_cRing) PrintS("posInT17_cRing\n");
11844  #endif
11845 #ifdef HAVE_MORE_POS_IN_T
11846  else if (strat->posInT==posInT_EcartFDegpLength) PrintS("posInT_EcartFDegpLength\n");
11847  else if (strat->posInT==posInT_FDegpLength) PrintS("posInT_FDegpLength\n");
11848  else if (strat->posInT==posInT_pLength) PrintS("posInT_pLength\n");
11849 #endif
11850  else if (strat->posInT==posInT_EcartpLength) PrintS("posInT_EcartpLength\n");
11851  else if (strat->posInT==posInTrg0) PrintS("posInTrg0\n");
11852  else Print("%p\n",(void*)strat->posInT);
11853  PrintS("posInL: ");
11854  if (strat->posInL==posInL0) PrintS("posInL0\n");
11855  else if (strat->posInL==posInL10) PrintS("posInL10\n");
11856  else if (strat->posInL==posInL11) PrintS("posInL11\n");
11857  else if (strat->posInL==posInL110) PrintS("posInL110\n");
11858  else if (strat->posInL==posInL13) PrintS("posInL13\n");
11859  else if (strat->posInL==posInL15) PrintS("posInL15\n");
11860  else if (strat->posInL==posInL17) PrintS("posInL17\n");
11861  else if (strat->posInL==posInL17_c) PrintS("posInL17_c\n");
11862  #ifdef HAVE_RINGS
11863  else if (strat->posInL==posInL0) PrintS("posInL0Ring\n");
11864  else if (strat->posInL==posInL11Ring) PrintS("posInL11Ring\n");
11865  else if (strat->posInL==posInL11Ringls) PrintS("posInL11Ringls\n");
11866  else if (strat->posInL==posInL110Ring) PrintS("posInL110Ring\n");
11867  else if (strat->posInL==posInL15Ring) PrintS("posInL15Ring\n");
11868  else if (strat->posInL==posInL17Ring) PrintS("posInL17Ring\n");
11869  else if (strat->posInL==posInL17_cRing) PrintS("posInL17_cRing\n");
11870  #endif
11871  else if (strat->posInL==posInLSpecial) PrintS("posInLSpecial\n");
11872  else if (strat->posInL==posInLrg0) PrintS("posInLrg0\n");
11873  else Print("%p\n",(void*)strat->posInL);
11874  PrintS("enterS: ");
11875  if (strat->enterS==enterSBba) PrintS("enterSBba\n");
11876  else if (strat->enterS==enterSMora) PrintS("enterSMora\n");
11877  else if (strat->enterS==enterSMoraNF) PrintS("enterSMoraNF\n");
11878  else Print("%p\n",(void*)strat->enterS);
11879  PrintS("initEcart: ");
11880  if (strat->initEcart==initEcartBBA) PrintS("initEcartBBA\n");
11881  else if (strat->initEcart==initEcartNormal) PrintS("initEcartNormal\n");
11882  else Print("%p\n",(void*)strat->initEcart);
11883  PrintS("initEcartPair: ");
11884  if (strat->initEcartPair==initEcartPairBba) PrintS("initEcartPairBba\n");
11885  else if (strat->initEcartPair==initEcartPairMora) PrintS("initEcartPairMora\n");
11886  else Print("%p\n",(void*)strat->initEcartPair);
11887  Print("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11888  strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11889  Print("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11890  strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11891  PrintS("chainCrit: ");
11892  if (strat->chainCrit==chainCritNormal) PrintS("chainCritNormal\n");
11893  else if (strat->chainCrit==chainCritOpt_1) PrintS("chainCritOpt_1\n");
11894  else Print("%p\n",(void*)strat->chainCrit);
11895  Print("posInLDependsOnLength=%d\n",
11896  strat->posInLDependsOnLength);
11897  PrintS(showOption());PrintLn();
11898  PrintS("LDeg: ");
11899  if (currRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11900  else if (currRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11901  else if (currRing->pLDeg==pLDegb) PrintS("pLDegb");
11902  else if (currRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11903  else if (currRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11904  else if (currRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11905  else if (currRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11906  else if (currRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11907  else if (currRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11908  else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11909  else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11910  else if (currRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11911  else Print("? (%lx)", (long)currRing->pLDeg);
11912  PrintS(" / ");
11913  if (strat->tailRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11914  else if (strat->tailRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11915  else if (strat->tailRing->pLDeg==pLDegb) PrintS("pLDegb");
11916  else if (strat->tailRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11917  else if (strat->tailRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11918  else if (strat->tailRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11919  else if (strat->tailRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11920  else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11921  else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11922  else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11923  else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11924  else if (strat->tailRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11925  else Print("? (%lx)", (long)strat->tailRing->pLDeg);
11926  PrintLn();
11927  PrintS("currRing->pFDeg: ");
11928  if (currRing->pFDeg==p_Totaldegree) PrintS("p_Totaldegree");
11929  else if (currRing->pFDeg==p_WFirstTotalDegree) PrintS("pWFirstTotalDegree");
11930  else if (currRing->pFDeg==p_Deg) PrintS("p_Deg");
11931  else if (currRing->pFDeg==kHomModDeg) PrintS("kHomModDeg");
11932  else if (currRing->pFDeg==totaldegreeWecart) PrintS("totaldegreeWecart");
11933  else if (currRing->pFDeg==p_WTotaldegree) PrintS("p_WTotaldegree");
11934  else Print("? (%lx)", (long)currRing->pFDeg);
11935  PrintLn();
11936  Print(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11937  if(TEST_OPT_DEGBOUND)
11938  Print(" degBound: %d\n", Kstd1_deg);
11939 
11940  if( ecartWeights != NULL )
11941  {
11942  PrintS("ecartWeights: ");
11943  for (int i = rVar(currRing); i > 0; i--)
11944  Print("%hd ", ecartWeights[i]);
11945  PrintLn();
11947  }
11948 
11949 #ifndef SING_NDEBUG
11951 #endif
11952 }
11953 
11954 #ifdef HAVE_SHIFTBBA
11955 poly pMove2CurrTail(poly p, kStrategy strat)
11956 {
11957  /* assume: p is completely in currRing */
11958  /* produces an object with LM in curring
11959  and TAIL in tailring */
11960  if (pNext(p)!=NULL)
11961  {
11962  pNext(p) = prMoveR(pNext(p), /* src */ currRing, /* dest */ strat->tailRing);
11963  }
11964  return(p);
11965 }
11966 #endif
11967 
11968 #ifdef HAVE_SHIFTBBA
11969 poly pMoveCurrTail2poly(poly p, kStrategy strat)
11970 {
11971  /* assume: p has LM in curring and TAIL in tailring */
11972  /* convert it to complete currRing */
11973 
11974  /* check that LM is in currRing */
11976 
11977  if (pNext(p)!=NULL)
11978  {
11979  pNext(p) = prMoveR(pNext(p), /* src */ strat->tailRing, /* dest */currRing);
11980  }
11981  return(p);
11982 }
11983 #endif
11984 
11985 #ifdef HAVE_SHIFTBBA
11987 {
11988  /* restores a poly in currRing from LObject */
11989  LObject h = H;
11990  h.Copy();
11991  poly p;
11992  if (h.p == NULL)
11993  {
11994  if (h.t_p != NULL)
11995  {
11996  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing, /* dest. ring: */ currRing);
11997  return(p);
11998  }
11999  else
12000  {
12001  /* h.tp == NULL -> the object is NULL */
12002  return(NULL);
12003  }
12004  }
12005  /* we're here if h.p != NULL */
12006  if (h.t_p == NULL)
12007  {
12008  /* then h.p is the whole poly in currRing */
12009  p = h.p;
12010  return(p);
12011  }
12012  /* we're here if h.p != NULL and h.t_p != NULL */
12013  // clean h.p, get poly from t_p
12014  pNext(h.p)=NULL;
12015  pLmDelete(&h.p);
12016  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing,
12017  /* dest. ring: */ currRing);
12018  // no need to clean h: we re-used the polys
12019  return(p);
12020 }
12021 #endif
12022 
12023 //LObject pCopyp2L(poly p, kStrategy strat)
12024 //{
12025  /* creates LObject from the poly in currRing */
12026  /* actually put p into L.p and make L.t_p=NULL : does not work */
12027 
12028 //}
12029 
12030 // poly pCopyL2p(LObject H, kStrategy strat)
12031 // {
12032 // /* restores a poly in currRing from LObject */
12033 // LObject h = H;
12034 // h.Copy();
12035 // poly p;
12036 // if (h.p == NULL)
12037 // {
12038 // if (h.t_p != NULL)
12039 // {
12040 // p = p_ShallowCopyDelete(h.t_p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12041 // return(p);
12042 // }
12043 // else
12044 // {
12045 // /* h.tp == NULL -> the object is NULL */
12046 // return(NULL);
12047 // }
12048 // }
12049 // /* we're here if h.p != NULL */
12050 
12051 // if (h.t_p == NULL)
12052 // {
12053 // /* then h.p is the whole poly in tailRing */
12054 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12055 // {
12056 // p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12057 // }
12058 // return(p);
12059 // }
12060 // /* we're here if h.p != NULL and h.t_p != NULL */
12061 // p = pCopy(pHead(h.p)); // in currRing
12062 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12063 // {
12064 // // pNext(p) = p_ShallowCopyDelete(pNext(h.t_p), (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12065 // poly pp = p_Copy(pNext(h.p), strat->tailRing);
12066 // // poly p3 = p_Copy(pNext(h.p), currRing); // error
12067 // // p_ShallowCopyDelete(pNext(h.p), currRing, strat->tailBin); // the same as pp
12068 // poly p5 = p_ShallowCopyDelete(pNext(h.p), strat->tailRing, strat->tailBin);
12069 // pNext(p) = p_ShallowCopyDelete(h.t_p, strat->tailRing, strat->tailBin);
12070 // poly p4 = p_Copy(h.t_p, strat->tailRing);
12071 // // if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
12072 // }
12073 // // pTest(p);
12074 // return(p);
12075 // }
12076 
12077 /*2
12078 * put the lcm(q,p) into the set B, q is the shift of some s[i]
12079 */
12080 #ifdef HAVE_SHIFTBBA
12081 static BOOLEAN enterOneStrongPolyShift (poly q, poly p, int /*ecart*/, int /*isFromQ*/, kStrategy strat, int atR, int /*ecartq*/, int /*qisFromQ*/, int shiftcount, int ifromS)
12082 {
12083  number d, s, t;
12084  /* assume(atR >= 0); */
12085  assume(ifromS <= strat->sl);
12087  poly m1, m2, gcd;
12088  //printf("\n--------------------------------\n");
12089  //pWrite(p);pWrite(si);
12090  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q), &s, &t, currRing->cf);
12091 
12092  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
12093  {
12094  nDelete(&d);
12095  nDelete(&s);
12096  nDelete(&t);
12097  return FALSE;
12098  }
12099 
12100  assume(pIsInV(p));
12101 
12102  k_GetStrongLeadTerms(p, q, currRing, m1, m2, gcd, strat->tailRing);
12103 
12104  /* the V criterion */
12105  if (!pmIsInV(gcd))
12106  {
12107  strat->cv++;
12108  nDelete(&d);
12109  nDelete(&s);
12110  nDelete(&t);
12111  pLmFree(gcd);
12112  return FALSE;
12113  }
12114 
12115  // disabled for Letterplace because it is not so easy to check
12116  /* if (!rHasLocalOrMixedOrdering(currRing)) { */
12117  /* unsigned long sev = pGetShortExpVector(gcd); */
12118 
12119  /* for (int j = 0; j < strat->sl; j++) { */
12120  /* if (j == i) */
12121  /* continue; */
12122 
12123  /* if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) && */
12124  /* !(strat->sevS[j] & ~sev) && */
12125  /* p_LmDivisibleBy(strat->S[j], gcd, currRing)) { */
12126  /* nDelete(&d); */
12127  /* nDelete(&s); */
12128  /* nDelete(&t); */
12129  /* return FALSE; */
12130  /* } */
12131  /* } */
12132  /* } */
12133 
12134  poly m12, m22;
12135  assume(p_mFirstVblock(p, currRing) <= 1 || p_mFirstVblock(q, currRing) <= 1);
12137  k_SplitFrame(m2, m22, si_max(p_mFirstVblock(q, currRing), 1), currRing);
12138  // manually free the coeffs, because pSetCoeff0 is used in the next step
12139  n_Delete(&(m1->coef), currRing->cf);
12140  n_Delete(&(m2->coef), currRing->cf);
12141 
12142  //p_Test(m1,strat->tailRing);
12143  //p_Test(m2,strat->tailRing);
12144  /*if(!enterTstrong)
12145  {
12146  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
12147  {
12148  memset(&(strat->P), 0, sizeof(strat->P));
12149  kStratChangeTailRing(strat);
12150  strat->P = *(strat->R[atR]);
12151  p_LmFree(m1, strat->tailRing);
12152  p_LmFree(m2, strat->tailRing);
12153  p_LmFree(gcd, currRing);
12154  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
12155  }
12156  }*/
12157  pSetCoeff0(m1, s);
12158  pSetCoeff0(m2, t);
12159  pSetCoeff0(gcd, d);
12160  p_Test(m1,strat->tailRing);
12161  p_Test(m2,strat->tailRing);
12162  p_Test(m12,strat->tailRing);
12163  p_Test(m22,strat->tailRing);
12164  assume(pmIsInV(m1));
12165  assume(pmIsInV(m2));
12166  assume(pmIsInV(m12));
12167  assume(pmIsInV(m22));
12168  //printf("\n===================================\n");
12169  //pWrite(m1);pWrite(m2);pWrite(gcd);
12170 #ifdef KDEBUG
12171  if (TEST_OPT_DEBUG)
12172  {
12173  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
12174  PrintS("m1 = ");
12175  p_wrp(m1, strat->tailRing);
12176  PrintS("m12 = ");
12177  p_wrp(m12, strat->tailRing);
12178  PrintS(" ; m2 = ");
12179  p_wrp(m2, strat->tailRing);
12180  PrintS(" ; m22 = ");
12181  p_wrp(m22, strat->tailRing);
12182  PrintS(" ; gcd = ");
12183  wrp(gcd);
12184  PrintS("\n--- create strong gcd poly: ");
12185  PrintS("\n p: ");
12186  wrp(p);
12187  Print("\n q (strat->S[%d]): ", ifromS);
12188  wrp(q);
12189  PrintS(" ---> ");
12190  }
12191 #endif
12192 
12193  pNext(gcd) = p_Add_q(pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing), pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing), strat->tailRing);
12194  p_LmDelete(m1, strat->tailRing);
12195  p_LmDelete(m2, strat->tailRing);
12196  p_LmDelete(m12, strat->tailRing);
12197  p_LmDelete(m22, strat->tailRing);
12198 
12199  assume(pIsInV(gcd));
12200 
12201 #ifdef KDEBUG
12202  if (TEST_OPT_DEBUG)
12203  {
12204  wrp(gcd);
12205  PrintLn();
12206  }
12207 #endif
12208 
12209  LObject h;
12210  h.p = gcd;
12211  h.tailRing = strat->tailRing;
12212  int posx;
12213  strat->initEcart(&h);
12214  h.sev = pGetShortExpVector(h.p);
12215  h.i_r1 = -1;h.i_r2 = -1;
12216  if (currRing!=strat->tailRing)
12217  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12218 #if 1
12219  h.p1 = p;
12220  h.p2 = q;
12221 #endif
12222  if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12223  {
12224  h.i_r2 = kFindInT(h.p1, strat);
12225  h.i_r1 = atR;
12226  }
12227  else
12228  {
12229  h.i_r1 = -1;
12230  h.i_r2 = -1;
12231  }
12232  if (strat->Ll==-1)
12233  posx =0;
12234  else
12235  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
12236 
12237  assume(pIsInV(h.p));
12238  assume(pIsInV(h.p1));
12239 
12240  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
12241  return TRUE;
12242 }
12243 #endif
12244 
12245 
12246 /*2
12247 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i] (ring case)
12248 */
12249 #ifdef HAVE_SHIFTBBA
12250 static void enterOnePairRingShift (poly q, poly p, int /*ecart*/, int isFromQ, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
12251 {
12252  /* assume(atR >= 0); */
12253  /* assume(i<=strat->sl); */
12254  assume(p!=NULL);
12256  assume(pIsInV(p));
12257  #if ALL_VS_JUST
12258  //Over rings, if we construct the strong pair, do not add the spair
12260  {
12261  number s,t,d;
12262  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q, &s, &t, currRing->cf);
12263 
12264  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
12265  {
12266  nDelete(&d);
12267  nDelete(&s);
12268  nDelete(&t);
12269  return;
12270  }
12271  nDelete(&d);
12272  nDelete(&s);
12273  nDelete(&t);
12274  }
12275  #endif
12276  int j,compare,compareCoeff;
12277  LObject h;
12278 
12279 #ifdef KDEBUG
12280  h.ecart=0; h.length=0;
12281 #endif
12282  /*- computes the lcm(s[i],p) -*/
12283  if(pHasNotCFRing(p,q))
12284  {
12285  strat->cp++;
12286  return;
12287  }
12288  h.lcm = p_Lcm(p,q,currRing);
12289  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(q), currRing->cf));
12290  if (nIsZero(pGetCoeff(h.lcm)))
12291  {
12292  strat->cp++;
12293  pLmDelete(h.lcm);
12294  return;
12295  }
12296 
12297  /* the V criterion */
12298  if (!pmIsInV(h.lcm))
12299  {
12300  strat->cv++;
12301  pLmDelete(h.lcm);
12302  return;
12303  }
12304  // basic chain criterion
12305  /*
12306  *the set B collects the pairs of type (S[j],p)
12307  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
12308  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12309  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12310  */
12311 
12312  for(j = strat->Bl;j>=0;j--)
12313  {
12314  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
12315  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
12316  if(compare == pDivComp_EQUAL)
12317  {
12318  //They have the same LM
12319  if(compareCoeff == pDivComp_LESS)
12320  {
12321  if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12322  {
12323  strat->c3++;
12324  pLmDelete(h.lcm);
12325  return;
12326  }
12327  break;
12328  }
12329  if(compareCoeff == pDivComp_GREATER)
12330  {
12331  deleteInL(strat->B,&strat->Bl,j,strat);
12332  strat->c3++;
12333  }
12334  if(compareCoeff == pDivComp_EQUAL)
12335  {
12336  if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12337  {
12338  strat->c3++;
12339  pLmDelete(h.lcm);
12340  return;
12341  }
12342  break;
12343  }
12344  }
12345  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
12346  {
12347  if(compare == pDivComp_LESS)
12348  {
12349  if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12350  {
12351  strat->c3++;
12352  pLmDelete(h.lcm);
12353  return;
12354  }
12355  break;
12356  }
12357  if(compare == pDivComp_GREATER)
12358  {
12359  deleteInL(strat->B,&strat->Bl,j,strat);
12360  strat->c3++;
12361  }
12362  }
12363  }
12364  number s, t;
12365  poly m1, m2, gcd = NULL;
12366  s = pGetCoeff(q);
12367  t = pGetCoeff(p);
12368  k_GetLeadTerms(p,q,currRing,m1,m2,currRing);
12369 
12370  poly m12, m22;
12371  assume(p_mFirstVblock(p, currRing) <= 1 || p_mFirstVblock(q, currRing) <= 1);
12373  k_SplitFrame(m2, m22, si_max(p_mFirstVblock(q, currRing), 1), currRing);
12374  // manually free the coeffs, because pSetCoeff0 is used in the next step
12375  n_Delete(&(m1->coef), currRing->cf);
12376  n_Delete(&(m2->coef), currRing->cf);
12377 
12378  ksCheckCoeff(&s, &t, currRing->cf);
12379  pSetCoeff0(m1, s);
12380  pSetCoeff0(m2, t);
12381  m2 = pNeg(m2);
12382  p_Test(m1,strat->tailRing);
12383  p_Test(m2,strat->tailRing);
12384  p_Test(m12,strat->tailRing);
12385  p_Test(m22,strat->tailRing);
12386  assume(pmIsInV(m1));
12387  assume(pmIsInV(m2));
12388  assume(pmIsInV(m12));
12389  assume(pmIsInV(m22));
12390  poly pm1 = pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing);
12391  poly sim2 = pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing);
12392  assume(pIsInV(pm1));
12393  assume(pIsInV(sim2));
12394  p_LmDelete(m1, currRing);
12395  p_LmDelete(m2, currRing);
12396  p_LmDelete(m12, currRing);
12397  p_LmDelete(m22, currRing);
12398  if(sim2 == NULL)
12399  {
12400  if(pm1 == NULL)
12401  {
12402  if(h.lcm != NULL)
12403  {
12404  pLmDelete(h.lcm);
12405  h.lcm=NULL;
12406  }
12407  h.Clear();
12408  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12409  /* if (strat->pairtest==NULL) initPairtest(strat); */
12410  /* strat->pairtest[i] = TRUE; */
12411  /* strat->pairtest[strat->sl+1] = TRUE; */
12412  return;
12413  }
12414  else
12415  {
12416  gcd = pm1;
12417  pm1 = NULL;
12418  }
12419  }
12420  else
12421  {
12422  if((pGetComp(q) == 0) && (0 != pGetComp(p)))
12423  {
12424  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
12425  pSetmComp(sim2);
12426  }
12427  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
12428  gcd = p_Add_q(pm1, sim2, strat->tailRing);
12429  }
12430  p_Test(gcd, strat->tailRing);
12431  assume(pIsInV(gcd));
12432 #ifdef KDEBUG
12433  if (TEST_OPT_DEBUG)
12434  {
12435  wrp(gcd);
12436  PrintLn();
12437  }
12438 #endif
12439  h.p = gcd;
12440  h.i_r = -1;
12441  if(h.p == NULL)
12442  {
12443  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12444  /* if (strat->pairtest==NULL) initPairtest(strat); */
12445  /* strat->pairtest[i] = TRUE; */
12446  /* strat->pairtest[strat->sl+1] = TRUE; */
12447  return;
12448  }
12449  h.tailRing = strat->tailRing;
12450  int posx;
12451  //h.pCleardenom();
12452  //pSetm(h.p);
12453  h.i_r1 = -1;h.i_r2 = -1;
12454  strat->initEcart(&h);
12455  #if 1
12456  h.p1 = p;
12457  h.p2 = q;
12458  #endif
12459  #if 1
12460  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12461  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12462  if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12463  {
12464  h.i_r2 = kFindInT(h.p1, strat); //strat->S_2_R[i];
12465  h.i_r1 = atR;
12466  }
12467  else
12468  {
12469  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12470  h.i_r1 = -1;
12471  h.i_r2 = -1;
12472  }
12473  #endif
12474  if (strat->Bl==-1)
12475  posx =0;
12476  else
12477  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
12478  h.sev = pGetShortExpVector(h.p);
12479  if (currRing!=strat->tailRing)
12480  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12481 
12482  assume(pIsInV(h.p));
12483  assume(pIsInV(h.p1));
12484  assume(h.lcm != NULL);
12485  assume(pIsInV(h.lcm));
12486 
12487  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
12488  kTest_TS(strat);
12489 }
12490 #endif
12491 
12492 #ifdef HAVE_SHIFTBBA
12493 // adds the strong pair and the normal pair for rings (aka gpoly and spoly)
12494 static BOOLEAN enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12495 {
12496  enterOneStrongPolyShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "gpoly"
12497  enterOnePairRingShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "spoly"
12498  return FALSE; // TODO: delete q?
12499 }
12500 #endif
12501 
12502 #ifdef HAVE_SHIFTBBA
12503 // creates if possible (q,p), (shifts(q),p)
12504 static BOOLEAN enterOnePairWithShifts (int q_inS /*also i*/, poly q, poly p, int ecartp, int p_isFromQ, kStrategy strat, int /*atR*/, int p_lastVblock, int q_lastVblock)
12505 {
12506  // note: ecart and isFromQ is for p
12507  assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12508  assume(pmFirstVblock(p) == 1);
12509  assume(pmFirstVblock(q) == 1);
12510  assume(p_lastVblock == pmLastVblock(p));
12511  assume(q_lastVblock == pmLastVblock(q));
12512 
12513  // TODO: is ecartq = 0 still ok?
12514  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12515 
12516  int q_isFromQ = 0;
12517  if (strat->fromQ != NULL && q_inS >= 0)
12518  q_isFromQ = strat->fromQ[q_inS];
12519 
12520  BOOLEAN (*enterPair)(poly, poly, int, int, kStrategy, int, int, int, int, int);
12521 #ifdef HAVE_RINGS
12522  if (rField_is_Ring(currRing))
12524  else
12525 #endif
12526  enterPair = enterOnePairShift;
12527 
12528  int degbound = currRing->N/currRing->isLPring;
12529  int neededShift = p_lastVblock - ((pGetComp(p) > 0 || pGetComp(q) > 0) ? 0 : 1); // in the module case, product criterion does not hold
12530  int maxPossibleShift = degbound - q_lastVblock;
12531  int maxShift = si_min(neededShift, maxPossibleShift);
12532  int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12533  BOOLEAN delete_pair=TRUE;
12534  for (int j = firstShift; j <= maxShift; j++)
12535  {
12536  poly qq = pLPCopyAndShiftLM(q, j);
12537  if (enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS))
12538  {
12539  if (j>0) pLmDelete(qq);
12540  // delete qq, if not it does not enter the pair set
12541  }
12542  else
12543  delete_pair=FALSE;
12544  }
12545 
12546 #ifdef HAVE_RINGS
12547  if (rField_is_Ring(currRing) && p_lastVblock >= firstShift && p_lastVblock <= maxPossibleShift)
12548  {
12549  // add pairs (m*shifts(q), p) where m is a monomial and the pair has no overlap
12550  for (int j = p_lastVblock; j <= maxPossibleShift; j++)
12551  {
12552  ideal fillers = id_MaxIdeal(j - p_lastVblock, currRing);
12553  for (int k = 0; k < IDELEMS(fillers); k++)
12554  {
12555  poly qq = pLPCopyAndShiftLM(pp_mm_Mult(q, fillers->m[k], currRing), p_lastVblock);
12556  enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, p_lastVblock, q_inS);
12557  }
12558  idDelete(&fillers);
12559  }
12560  }
12561 #endif
12562  return delete_pair;
12563 }
12564 #endif
12565 
12566 #ifdef HAVE_SHIFTBBA
12567 // creates (q,p), use it when q is already shifted
12568 // return TRUE, if (q,p) is discarded
12569 static BOOLEAN enterOnePairWithoutShifts (int p_inS /*also i*/, poly q, poly p, int ecartq, int q_isFromQ, kStrategy strat, int /*atR*/, int p_lastVblock, int q_shift)
12570 {
12571  // note: ecart and isFromQ is for p
12572  assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12573  assume(pmFirstVblock(p) == 1);
12574  assume(p_lastVblock == pmLastVblock(p));
12575  assume(q_shift == pmFirstVblock(q) - 1);
12576 
12577  // TODO: is ecartp = 0 still ok?
12578  int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12579 
12580  int p_isFromQ = 0;
12581  if (strat->fromQ != NULL && p_inS >= 0)
12582  p_isFromQ = strat->fromQ[p_inS];
12583 
12584 #ifdef HAVE_RINGS
12585  if (rField_is_Ring(currRing))
12586  {
12587  assume(q_shift <= p_lastVblock); // we allow the special case where there is no overlap
12588  return enterOneStrongPolyAndEnterOnePairRingShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12589  }
12590  else
12591 #endif
12592  {
12593  assume(q_shift <= p_lastVblock - ((pGetComp(q) > 0 || pGetComp(p) > 0) ? 0 : 1)); // there should be an overlap (in the module case epsilon overlap is also allowed)
12594  return enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12595  }
12596 }
12597 #endif
12598 
12599 
12600 #ifdef KDEBUG
12601 // enable to print which pairs are considered or discarded and why
12602 /* #define CRITERION_DEBUG */
12603 #endif
12604 /*2
12605 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12606 * return TRUE, if (q,p) does not enter B
12607 */
12608 #ifdef HAVE_SHIFTBBA
12609 BOOLEAN enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12610 {
12611 #ifdef CRITERION_DEBUG
12612  if (TEST_OPT_DEBUG)
12613  {
12614  PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12615  // also write the LMs in separate lines:
12616  poly lmq = pHead(q);
12617  poly lmp = pHead(p);
12618  pSetCoeff(lmq, n_Init(1, currRing->cf));
12619  pSetCoeff(lmp, n_Init(1, currRing->cf));
12620  Print(" %s\n", pString(lmq));
12621  Print(" %s\n", pString(lmp));
12622  pLmDelete(lmq);
12623  pLmDelete(lmp);
12624  }
12625 #endif
12626 
12627  /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12628 
12629  /* check this Formats: */
12631  assume(p_CheckIsFromRing(pNext(q),strat->tailRing));
12634 
12635  /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12636 
12637  int qfromQ = qisFromQ;
12638 
12639  /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12640 
12641  int l,j,compare;
12642  LObject Lp;
12643  Lp.i_r = -1;
12644 
12645 #ifdef KDEBUG
12646  Lp.ecart=0; Lp.length=0;
12647 #endif
12648  /*- computes the lcm(s[i],p) -*/
12649  Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12650 
12651  /* the V criterion */
12652  if (!pmIsInV(Lp.lcm))
12653  {
12654  strat->cv++; // counter for applying the V criterion
12655  pLmFree(Lp.lcm);
12656 #ifdef CRITERION_DEBUG
12657  if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12658 #endif
12659  return TRUE;
12660  }
12661 
12662  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12663  {
12664  if((!((ecartq>0)&&(ecart>0)))
12665  && pHasNotCF(p,q))
12666  {
12667  /*
12668  *the product criterion has applied for (s,p),
12669  *i.e. lcm(s,p)=product of the leading terms of s and p.
12670  *Suppose (s,r) is in L and the leading term
12671  *of p divides lcm(s,r)
12672  *(==> the leading term of p divides the leading term of r)
12673  *but the leading term of s does not divide the leading term of r
12674  *(notice that this condition is automatically satisfied if r is still
12675  *in S), then (s,r) can be cancelled.
12676  *This should be done here because the
12677  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12678  *
12679  *Moreover, skipping (s,r) holds also for the noncommutative case.
12680  */
12681  strat->cp++;
12682  pLmFree(Lp.lcm);
12683 #ifdef CRITERION_DEBUG
12684  if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12685 #endif
12686  return TRUE;
12687  }
12688  else
12689  Lp.ecart = si_max(ecart,ecartq);
12690  if (strat->fromT && (ecartq>ecart))
12691  {
12692  pLmFree(Lp.lcm);
12693 #ifdef CRITERION_DEBUG
12694  if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12695 #endif
12696  return TRUE;
12697  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12698  }
12699  /*
12700  *the set B collects the pairs of type (S[j],p)
12701  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12702  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12703  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12704  */
12705  {
12706  j = strat->Bl;
12707  loop
12708  {
12709  if (j < 0) break;
12710  compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12711  if ((compare==1)
12712  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12713  {
12714  strat->c3++;
12715  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12716  {
12717  pLmFree(Lp.lcm);
12718 #ifdef CRITERION_DEBUG
12719  if (TEST_OPT_DEBUG)
12720  {
12721  Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12722  }
12723 #endif
12724  return TRUE;
12725  }
12726  break;
12727  }
12728  else
12729  if ((compare ==-1)
12730  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12731  {
12732 #ifdef CRITERION_DEBUG
12733  if (TEST_OPT_DEBUG)
12734  {
12735  Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12736  }
12737 #endif
12738  deleteInL(strat->B,&strat->Bl,j,strat);
12739  strat->c3++;
12740  }
12741  j--;
12742  }
12743  }
12744  }
12745  else /*sugarcrit*/
12746  {
12747  if (ALLOW_PROD_CRIT(strat))
12748  {
12749  // if currRing->nc_type!=quasi (or skew)
12750  // TODO: enable productCrit for super commutative algebras...
12751  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12752  pHasNotCF(p,q))
12753  {
12754  /*
12755  *the product criterion has applied for (s,p),
12756  *i.e. lcm(s,p)=product of the leading terms of s and p.
12757  *Suppose (s,r) is in L and the leading term
12758  *of p divides lcm(s,r)
12759  *(==> the leading term of p divides the leading term of r)
12760  *but the leading term of s does not divide the leading term of r
12761  *(notice that tis condition is automatically satisfied if r is still
12762  *in S), then (s,r) can be canceled.
12763  *This should be done here because the
12764  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12765  */
12766  strat->cp++;
12767  pLmFree(Lp.lcm);
12768 #ifdef CRITERION_DEBUG
12769  if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12770 #endif
12771  return TRUE;
12772  }
12773  if (strat->fromT && (ecartq>ecart))
12774  {
12775  pLmFree(Lp.lcm);
12776 #ifdef CRITERION_DEBUG
12777  if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12778 #endif
12779  return TRUE;
12780  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12781  }
12782  /*
12783  *the set B collects the pairs of type (S[j],p)
12784  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12785  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12786  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12787  */
12788  for(j = strat->Bl;j>=0;j--)
12789  {
12790  compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12791  if (compare==1)
12792  {
12793  strat->c3++;
12794  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12795  {
12796  pLmFree(Lp.lcm);
12797 #ifdef CRITERION_DEBUG
12798  if (TEST_OPT_DEBUG)
12799  {
12800  Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12801  }
12802 #endif
12803  return TRUE;
12804  }
12805  break;
12806  }
12807  else
12808  if (compare ==-1)
12809  {
12810 #ifdef CRITERION_DEBUG
12811  if (TEST_OPT_DEBUG)
12812  {
12813  Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12814  }
12815 #endif
12816  deleteInL(strat->B,&strat->Bl,j,strat);
12817  strat->c3++;
12818  }
12819  }
12820  }
12821  }
12822  /*
12823  *the pair (S[i],p) enters B if the spoly != 0
12824  */
12825  /*- compute the short s-polynomial -*/
12826  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12827  pNorm(p);
12828  if ((q==NULL) || (p==NULL))
12829  {
12830 #ifdef CRITERION_DEBUG
12831  if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
12832 #endif
12833  return FALSE;
12834  }
12835  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12836  {
12837  Lp.p=NULL;
12838 #ifdef CRITERION_DEBUG
12839  if (TEST_OPT_DEBUG) PrintS("--- pair is from Q\n");
12840 #endif
12841  }
12842  else
12843  {
12844 // if ( rIsPluralRing(currRing) )
12845 // {
12846 // if(pHasNotCF(p, q))
12847 // {
12848 // if(ncRingType(currRing) == nc_lie)
12849 // {
12850 // // generalized prod-crit for lie-type
12851 // strat->cp++;
12852 // Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12853 // }
12854 // else
12855 // if( ALLOW_PROD_CRIT(strat) )
12856 // {
12857 // // product criterion for homogeneous case in SCA
12858 // strat->cp++;
12859 // Lp.p = NULL;
12860 // }
12861 // else
12862 // Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12863 // }
12864 // else Lp.p = nc_CreateSpoly(q,p,currRing);
12865 // }
12866 // else
12867 // {
12868 
12869  /* ksCreateShortSpoly needs two Lobject-kind presentations */
12870  /* p is already in this form, so convert q */
12871  // q = pMove2CurrTail(q, strat);
12872  Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12873  // }
12874  }
12875  if (Lp.p == NULL)
12876  {
12877  /*- the case that the s-poly is 0 -*/
12878  // TODO: currently ifromS is only > 0 if called from enterOnePairWithShifts
12879  if (ifromS > 0)
12880  {
12881  if (strat->pairtest==NULL) initPairtest(strat);
12882  strat->pairtest[ifromS] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12883  strat->pairtest[strat->sl+1] = TRUE;
12884  }
12885  //if (TEST_OPT_DEBUG){Print("!");} // option teach
12886  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12887  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12888  /*
12889  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12890  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12891  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12892  *term of p divides the lcm(s,r)
12893  *(this canceling should be done here because
12894  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12895  *the first case is handeled in chainCrit
12896  */
12897  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12898 #ifdef CRITERION_DEBUG
12899  if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
12900 #endif
12901  return TRUE;
12902  }
12903  else
12904  {
12905  /*- the pair (S[i],p) enters B -*/
12906  /* both of them should have their LM in currRing and TAIL in tailring */
12907  Lp.p1 = q; // already in the needed form
12908  Lp.p2 = p; // already in the needed form
12909 
12910  if ( !rIsPluralRing(currRing) )
12911  pNext(Lp.p) = strat->tail;
12912 
12913  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12914  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12915  if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12916  {
12917  Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12918  Lp.i_r2 = atR;
12919  }
12920  else
12921  {
12922  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12923  Lp.i_r1 = -1;
12924  Lp.i_r2 = -1;
12925  }
12926  strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12927 
12929  {
12930  if (!rIsPluralRing(currRing)
12932  && (Lp.p->coef!=NULL))
12933  nDelete(&(Lp.p->coef));
12934  }
12935 
12936  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12937  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12938 #ifdef CRITERION_DEBUG
12939  if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
12940 #endif
12941  }
12942  return FALSE;
12943 }
12944 #endif
12945 
12946 /*3
12947 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12948 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12949 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
12950 */
12951 #ifdef HAVE_SHIFTBBA
12952 void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12953 {
12954  int h_lastVblock = pmLastVblock(h);
12955  assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12956  // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12957  if (h_lastVblock == 0) return;
12958  assume(pmFirstVblock(h) == 1);
12959  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12960  // atR = -1;
12961  if ((strat->syzComp==0)
12962  || (pGetComp(h)<=strat->syzComp))
12963  {
12964  int i,j;
12965  BOOLEAN new_pair=FALSE;
12966 
12967  int degbound = currRing->N/currRing->isLPring;
12968  int maxShift = degbound - h_lastVblock;
12969 
12970  if (pGetComp(h)==0)
12971  {
12972  if (strat->rightGB)
12973  {
12974  if (isFromQ)
12975  {
12976  // pairs (shifts(h),s[1..k]), (h, s[1..k])
12977  for (i=0; i<=maxShift; i++)
12978  {
12979  poly hh = pLPCopyAndShiftLM(h, i);
12980  BOOLEAN delete_hh=TRUE;
12981  for (j=0; j<=k; j++)
12982  {
12983  if (strat->fromQ == NULL || !strat->fromQ[j])
12984  {
12985  new_pair=TRUE;
12986  poly s = strat->S[j];
12987  if (!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12988  delete_hh=FALSE;
12989  }
12990  }
12991  if (delete_hh) pLmDelete(hh);
12992  }
12993  }
12994  else
12995  {
12996  new_pair=TRUE;
12997  for (j=0; j<=k; j++)
12998  {
12999  poly s = strat->S[j];
13000  if (strat->fromQ != NULL && strat->fromQ[j])
13001  {
13002  // pairs (shifts(s[j]),h), (s[j],h)
13003  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13004  }
13005  else
13006  {
13007  // pair (h, s[j])
13008  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13009  }
13010  }
13011  }
13012  }
13013  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
13014  else if ((isFromQ)&&(strat->fromQ!=NULL))
13015  {
13016  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13017  for (j=0; j<=k; j++)
13018  {
13019  if (!strat->fromQ[j])
13020  {
13021  new_pair=TRUE;
13022  poly s = strat->S[j];
13023  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13024  }
13025  }
13026  // pairs (shifts(h),s[1..k])
13027  if (new_pair)
13028  {
13029  for (i=1; i<=maxShift; i++)
13030  {
13031  BOOLEAN delete_hh=TRUE;
13032  poly hh = pLPCopyAndShiftLM(h, i);
13033  for (j=0; j<=k; j++)
13034  {
13035  if (!strat->fromQ[j])
13036  {
13037  poly s = strat->S[j];
13038  int s_lastVblock = pmLastVblock(s);
13039  if (i < s_lastVblock || (pGetComp(s) > 0 && i == s_lastVblock)) // in the module case, product criterion does not hold (note: comp h is always zero here)
13040  if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i))
13041  delete_hh=FALSE;
13042 #ifdef HAVE_RINGS
13043  else if (rField_is_Ring(currRing))
13044  {
13045  assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13046  ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13047  for (int k = 0; k < IDELEMS(fillers); k++)
13048  {
13049  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13050  enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13051  }
13052  idDelete(&fillers);
13053  }
13054 #endif
13055  }
13056  }
13057  if (delete_hh) p_LmDelete(hh,currRing);
13058  }
13059  }
13060  }
13061  else
13062  {
13063  new_pair=TRUE;
13064  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13065  for (j=0; j<=k; j++)
13066  {
13067  poly s = strat->S[j];
13068  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13069  }
13070  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13071  for (i=1; i<=maxShift; i++)
13072  {
13073  poly hh = pLPCopyAndShiftLM(h, i);
13074  BOOLEAN delete_hh=TRUE;
13075  for (j=0; j<=k; j++)
13076  {
13077  poly s = strat->S[j];
13078  int s_lastVblock = pmLastVblock(s);
13079  if (i < s_lastVblock || (pGetComp(s) > 0 && i == s_lastVblock)) // in the module case, product criterion does not hold (note: comp h is always zero here)
13080  delete_hh=enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i)
13081  && delete_hh;
13082 #ifdef HAVE_RINGS
13083  else if (rField_is_Ring(currRing))
13084  {
13085  assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13086  ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13087  for (int k = 0; k < IDELEMS(fillers); k++)
13088  {
13089  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13090  enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13091  }
13092  idDelete(&fillers);
13093  }
13094 #endif
13095  }
13096  if (i < h_lastVblock) // in the module case, product criterion does not hold (note: comp h is always zero here)
13097  delete_hh=enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i)
13098  && delete_hh;
13099 #ifdef HAVE_RINGS
13100  else if (rField_is_Ring(currRing))
13101  {
13102  assume(i >= h_lastVblock); // this is always the case, but just to be very sure
13103  ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
13104  for (int k = 0; k < IDELEMS(fillers); k++)
13105  {
13106  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
13107  enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock);
13108  }
13109  idDelete(&fillers);
13110  }
13111 #endif
13112  if (delete_hh) pLmDelete(hh);
13113  }
13114  }
13115  }
13116  else
13117  {
13118  assume(isFromQ == 0); // an element from Q should always has 0 component
13119  new_pair=TRUE;
13120  if (strat->rightGB)
13121  {
13122  for (j=0; j<=k; j++)
13123  {
13124  if ((pGetComp(h)==pGetComp(strat->S[j]))
13125  || (pGetComp(strat->S[j])==0))
13126  {
13127  poly s = strat->S[j];
13128  if (strat->fromQ != NULL && strat->fromQ[j])
13129  {
13130  // pairs (shifts(s[j]),h), (s[j],h)
13131  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13132  }
13133  else
13134  {
13135  // pair (h, s[j])
13136  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13137  }
13138  }
13139  }
13140  }
13141  else
13142  {
13143  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13144  for (j=0; j<=k; j++)
13145  {
13146  if ((pGetComp(h)==pGetComp(strat->S[j]))
13147  || (pGetComp(strat->S[j])==0))
13148  {
13149  poly s = strat->S[j];
13150  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13151  }
13152  }
13153  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13154  for (i=1; i<=maxShift; i++)
13155  {
13156  poly hh = pLPCopyAndShiftLM(h, i);
13157  for (j=0; j<=k; j++)
13158  {
13159  if ((pGetComp(h)==pGetComp(strat->S[j]))
13160  || (pGetComp(strat->S[j])==0))
13161  {
13162  poly s = strat->S[j];
13163  int s_lastVblock = pmLastVblock(s);
13164  if (i <= s_lastVblock) // in the module case, product criterion does not hold
13165  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
13166 #ifdef HAVE_RINGS
13167  else if (rField_is_Ring(currRing))
13168  {
13169  assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13170  ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13171  for (int k = 0; k < IDELEMS(fillers); k++)
13172  {
13173  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13174  enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13175  }
13176  idDelete(&fillers);
13177  }
13178 #endif
13179  }
13180  }
13181  if (i <= h_lastVblock) // in the module case, product criterion does not hold
13182  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13183 #ifdef HAVE_RINGS
13184  else if (rField_is_Ring(currRing))
13185  {
13186  assume(i >= h_lastVblock); // this is always the case, but just to be very sure
13187  ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
13188  for (int k = 0; k < IDELEMS(fillers); k++)
13189  {
13190  BOOLEAN delete_hhh=TRUE;
13191  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
13192  if(!enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock))
13193  delete_hhh=FALSE;
13194  if (delete_hhh) p_LmDelete(hhh,currRing);
13195  }
13196  idDelete(&fillers);
13197  }
13198 #endif
13199  }
13200  }
13201  }
13202 
13203  if (new_pair)
13204  {
13205  strat->chainCrit(h,ecart,strat);
13206  }
13207  kMergeBintoL(strat);
13208  }
13209 }
13210 #endif
13211 
13212 /*3
13213 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
13214 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
13215 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
13216 */
13217 #ifdef HAVE_SHIFTBBA
13218 void initenterstrongPairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
13219 {
13220  int h_lastVblock = pmLastVblock(h);
13221  assume(h_lastVblock != 0 || pLmIsConstantComp(h));
13222  // TODO: is it allowed to skip pairs with constants? also with constants from other components?
13223  if (h_lastVblock == 0) return;
13224  assume(pmFirstVblock(h) == 1);
13225  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13226  // atR = -1;
13227  if ((strat->syzComp==0)
13228  || (pGetComp(h)<=strat->syzComp))
13229  {
13230  int i,j;
13231  BOOLEAN new_pair=FALSE;
13232 
13233  int degbound = currRing->N/currRing->isLPring;
13234  int maxShift = degbound - h_lastVblock;
13235 
13236  if (pGetComp(h)==0)
13237  {
13238  if (strat->rightGB)
13239  {
13240  if (isFromQ)
13241  {
13242  // pairs (shifts(h),s[1..k]), (h, s[1..k])
13243  for (i=0; i<=maxShift; i++)
13244  {
13245  poly hh = pLPCopyAndShiftLM(h, i);
13246  for (j=0; j<=k; j++)
13247  {
13248  if (strat->fromQ == NULL || !strat->fromQ[j])
13249  {
13250  new_pair=TRUE;
13251  poly s = strat->S[j];
13252  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13253  }
13254  }
13255  }
13256  }
13257  else
13258  {
13259  new_pair=TRUE;
13260  for (j=0; j<=k; j++)
13261  {
13262  poly s = strat->S[j];
13263  if (strat->fromQ != NULL && strat->fromQ[j])
13264  {
13265  // pairs (shifts(s[j]),h), (s[j],h)
13266  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13267  }
13268  else
13269  {
13270  // pair (h, s[j])
13271  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13272  }
13273  }
13274  }
13275  }
13276  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
13277  else if ((isFromQ)&&(strat->fromQ!=NULL))
13278  {
13279  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13280  for (j=0; j<=k; j++)
13281  {
13282  if (!strat->fromQ[j])
13283  {
13284  new_pair=TRUE;
13285  poly s = strat->S[j];
13286  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13287  }
13288  }
13289  // pairs (shifts(h),s[1..k])
13290  if (new_pair)
13291  {
13292  for (i=1; i<=maxShift; i++)
13293  {
13294  poly hh = pLPCopyAndShiftLM(h, i);
13295  for (j=0; j<=k; j++)
13296  {
13297  if (!strat->fromQ[j])
13298  {
13299  poly s = strat->S[j];
13300  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13301  }
13302  }
13303  }
13304  }
13305  }
13306  else
13307  {
13308  new_pair=TRUE;
13309  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13310  for (j=0; j<=k; j++)
13311  {
13312  poly s = strat->S[j];
13313  // TODO: cache lastVblock of s[1..k] for later use
13314  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13315  }
13316  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13317  for (i=1; i<=maxShift; i++)
13318  {
13319  poly hh = pLPCopyAndShiftLM(h, i);
13320  BOOLEAN delete_hh=TRUE;
13321  for (j=0; j<=k; j++)
13322  {
13323  poly s = strat->S[j];
13324  if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
13325  delete_hh=FALSE;
13326  }
13327  if(!enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i))
13328  delete_hh=FALSE;
13329  if (delete_hh) p_LmDelete(hh,currRing);
13330  }
13331  }
13332  }
13333  else
13334  {
13335  new_pair=TRUE;
13336  if (strat->rightGB)
13337  {
13338  for (j=0; j<=k; j++)
13339  {
13340  if ((pGetComp(h)==pGetComp(strat->S[j]))
13341  || (pGetComp(strat->S[j])==0))
13342  {
13343  assume(isFromQ == 0); // this case is not handeled here and should also never happen
13344  poly s = strat->S[j];
13345  if (strat->fromQ != NULL && strat->fromQ[j])
13346  {
13347  // pairs (shifts(s[j]),h), (s[j],h)
13348  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13349  }
13350  else
13351  {
13352  // pair (h, s[j])
13353  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13354  }
13355  }
13356  }
13357  }
13358  else
13359  {
13360  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13361  for (j=0; j<=k; j++)
13362  {
13363  if ((pGetComp(h)==pGetComp(strat->S[j]))
13364  || (pGetComp(strat->S[j])==0))
13365  {
13366  poly s = strat->S[j];
13367  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13368  }
13369  }
13370  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13371  for (i=1; i<=maxShift; i++)
13372  {
13373  poly hh = pLPCopyAndShiftLM(h, i);
13374  for (j=0; j<=k; j++)
13375  {
13376  if ((pGetComp(h)==pGetComp(strat->S[j]))
13377  || (pGetComp(strat->S[j])==0))
13378  {
13379  poly s = strat->S[j];
13380  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13381  }
13382  }
13383  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13384  }
13385  }
13386  }
13387 
13388  if (new_pair)
13389  {
13390  strat->chainCrit(h,ecart,strat);
13391  }
13392  kMergeBintoL(strat);
13393  }
13394 }
13395 #endif
13396 
13397 /*2
13398 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
13399 *superfluous elements in S will be deleted
13400 */
13401 #ifdef HAVE_SHIFTBBA
13402 void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
13403 {
13404  /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13405  /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
13406  int j=pos;
13407 
13408  /* if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat); */ // TODO: enterExtendedSpoly not for LP yet
13409  initenterpairsShift(h,k,ecart,0,strat, atR);
13410  if ( (!strat->fromT)
13411  && ((strat->syzComp==0)
13412  ||(pGetComp(h)<=strat->syzComp)))
13413  {
13414  unsigned long h_sev = pGetShortExpVector(h);
13415  loop
13416  {
13417  if (j > k) break;
13418  // TODO this currently doesn't clear all possible elements because of commutative division
13419  if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
13420  clearS(h,h_sev, &j,&k,strat);
13421  j++;
13422  }
13423  }
13424 }
13425 #endif
13426 
13427 /*2
13428 * enteres all admissible shifts of p into T
13429 * assumes that p is already in T!
13430 */
13431 #ifdef HAVE_SHIFTBBA
13432 void enterTShift(LObject p, kStrategy strat, int atT)
13433 {
13434  /* determine how many elements we have to insert */
13435  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
13436  /* hence, a total number of elt's to add is: */
13437  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
13438  pAssume(p.p != NULL);
13439 
13440  int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
13441 
13442  for (int i = 1; i <= maxPossibleShift; i++)
13443  {
13444  LObject qq;
13445  qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
13446  qq.shift = i;
13447  strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
13448 
13449  enterT(qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
13450  }
13451 }
13452 #endif
13453 
13454 #ifdef HAVE_SHIFTBBA
13455 poly redtailBbaShift (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
13456 {
13457  /* for the shift case need to run it with withT = TRUE */
13458  strat->redTailChange=FALSE;
13459  if (strat->noTailReduction) return L->GetLmCurrRing();
13460  poly h, p;
13461  p = h = L->GetLmTailRing();
13462  if ((h==NULL) || (pNext(h)==NULL))
13463  return L->GetLmCurrRing();
13464 
13465  TObject* With;
13466  // placeholder in case strat->tl < 0
13467  TObject With_s(strat->tailRing);
13468 
13469  LObject Ln(pNext(h), strat->tailRing);
13470  Ln.pLength = L->GetpLength() - 1;
13471 
13472  pNext(h) = NULL;
13473  if (L->p != NULL) pNext(L->p) = NULL;
13474  L->pLength = 1;
13475 
13476  Ln.PrepareRed(strat->use_buckets);
13477 
13478  while(!Ln.IsNull())
13479  {
13480  loop
13481  {
13482  Ln.SetShortExpVector();
13483  if (withT)
13484  {
13485  int j;
13486  j = kFindDivisibleByInT(strat, &Ln);
13487  if (j < 0) break;
13488  With = &(strat->T[j]);
13489  }
13490  else
13491  {
13492  With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
13493  if (With == NULL) break;
13494  }
13495  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
13496  {
13497  With->pNorm();
13498  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
13499  }
13500  strat->redTailChange=TRUE;
13501  if (ksReducePolyTail(L, With, &Ln))
13502  {
13503  // reducing the tail would violate the exp bound
13504  // set a flag and hope for a retry (in bba)
13505  strat->completeReduce_retry=TRUE;
13506  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
13507  do
13508  {
13509  pNext(h) = Ln.LmExtractAndIter();
13510  pIter(h);
13511  L->pLength++;
13512  } while (!Ln.IsNull());
13513  goto all_done;
13514  }
13515  if (Ln.IsNull()) goto all_done;
13516  if (! withT) With_s.Init(currRing);
13517  }
13518  pNext(h) = Ln.LmExtractAndIter();
13519  pIter(h);
13520  L->pLength++;
13521  }
13522 
13523  all_done:
13524  Ln.Delete();
13525  if (L->p != NULL) pNext(L->p) = pNext(p);
13526 
13527  if (strat->redTailChange)
13528  {
13529  L->length = 0;
13530  }
13531  L->Normalize(); // HANNES: should have a test
13532  kTest_L(L,strat);
13533  return L->GetLmCurrRing();
13534 }
13535 #endif
static int si_max(const int a, const int b)
Definition: auxiliary.h:124
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
void * ADDRESS
Definition: auxiliary.h:119
static int si_min(const int a, const int b)
Definition: auxiliary.h:125
CanonicalForm lc(const CanonicalForm &f)
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:676
int l
Definition: cfEzgcd.cc:100
int m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
int p
Definition: cfModGcd.cc:4078
bool equal
Definition: cfModGcd.cc:4126
CanonicalForm b
Definition: cfModGcd.cc:4103
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
Definition: intvec.h:23
poly p
Definition: kutil.h:73
poly t_p
Definition: kutil.h:74
ring tailRing
Definition: kutil.h:76
void wrp()
Definition: kutil.cc:797
KINLINE poly kNoetherTail()
Definition: kInline.h:66
unsigned long * sevSyz
Definition: kutil.h:323
kStrategy next
Definition: kutil.h:277
bool sigdrop
Definition: kutil.h:359
poly t_kNoether
Definition: kutil.h:330
int syzComp
Definition: kutil.h:354
int * S_2_R
Definition: kutil.h:342
ring tailRing
Definition: kutil.h:343
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:291
char noTailReduction
Definition: kutil.h:378
int currIdx
Definition: kutil.h:317
~skStrategy()
Definition: kutil.cc:11641
skStrategy()
Definition: kutil.cc:11621
int nrsyzcrit
Definition: kutil.h:360
intset lenS
Definition: kutil.h:319
int nrrewcrit
Definition: kutil.h:361
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:298
int Ll
Definition: kutil.h:351
TSet T
Definition: kutil.h:326
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:293
char news
Definition: kutil.h:400
omBin lmBin
Definition: kutil.h:344
int syzmax
Definition: kutil.h:349
int Bl
Definition: kutil.h:352
intset ecartS
Definition: kutil.h:309
int syzidxmax
Definition: kutil.h:349
char honey
Definition: kutil.h:377
char rightGB
Definition: kutil.h:369
polyset S
Definition: kutil.h:306
int minim
Definition: kutil.h:357
poly kNoether
Definition: kutil.h:329
BOOLEAN * NotUsedAxis
Definition: kutil.h:332
LSet B
Definition: kutil.h:328
BOOLEAN * pairtest
Definition: kutil.h:333
int cp
Definition: kutil.h:347
int ak
Definition: kutil.h:353
TObject ** R
Definition: kutil.h:340
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:295
int tl
Definition: kutil.h:350
unsigned long * sevT
Definition: kutil.h:325
unsigned long * sevSig
Definition: kutil.h:324
int nr
Definition: kutil.h:346
poly tail
Definition: kutil.h:334
char sugarCrit
Definition: kutil.h:377
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:284
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:47
intset syzIdx
Definition: kutil.h:313
ideal Shdl
Definition: kutil.h:303
int syzl
Definition: kutil.h:349
unsigned sbaOrder
Definition: kutil.h:316
pFDegProc pOrigFDeg
Definition: kutil.h:296
int tmax
Definition: kutil.h:350
polyset sig
Definition: kutil.h:308
polyset syz
Definition: kutil.h:307
char LDegLast
Definition: kutil.h:385
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:287
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.h:292
wlen_set lenSw
Definition: kutil.h:320
char kAllAxis
Definition: kutil.h:376
int cv
Definition: kutil.h:368
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:338
char Gebauer
Definition: kutil.h:378
intset fromQ
Definition: kutil.h:321
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:286
char newt
Definition: kutil.h:401
char use_buckets
Definition: kutil.h:383
char interpt
Definition: kutil.h:371
char redTailChange
Definition: kutil.h:399
int newIdeal
Definition: kutil.h:356
char fromT
Definition: kutil.h:379
char completeReduce_retry
Definition: kutil.h:403
void(* initEcart)(TObject *L)
Definition: kutil.h:280
omBin tailBin
Definition: kutil.h:345
LObject P
Definition: kutil.h:302
KINLINE TObject * S_2_T(int i)
Definition: kInline.h:38
char noClearS
Definition: kutil.h:402
int Lmax
Definition: kutil.h:351
char z2homog
Definition: kutil.h:374
int LazyPass
Definition: kutil.h:353
char overflow
Definition: kutil.h:404
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.h:290
LSet L
Definition: kutil.h:327
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:281
int(* red)(LObject *L, kStrategy strat)
Definition: kutil.h:278
int sl
Definition: kutil.h:348
int LazyDegree
Definition: kutil.h:353
char posInLDependsOnLength
Definition: kutil.h:389
unsigned long * sevS
Definition: kutil.h:322
char homog
Definition: kutil.h:372
pLDegProc pOrigLDeg
Definition: kutil.h:297
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:282
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:299
int Bmax
Definition: kutil.h:352
int c3
Definition: kutil.h:347
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:816
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:30
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition: coeffs.h:664
static FORCE_INLINE BOOLEAN n_IsUnit(number n, const coeffs r)
TRUE iff n has a multiplicative inverse in the given coeff field/ring r.
Definition: coeffs.h:515
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:679
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:700
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:354
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
static FORCE_INLINE number n_Lcm(number a, number b, const coeffs r)
in Z: return the lcm of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition: coeffs.h:690
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:671
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:538
static FORCE_INLINE number n_IntMod(number a, number b, const coeffs r)
for r a field, return n_Init(0,r) always: n_Div(a,b,r)*b+n_IntMod(a,b,r)==a n_IntMod(a,...
Definition: coeffs.h:628
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether 'a' is divisible 'b'; for r encoding a field: TRUE iff 'b' does not represent zero in Z:...
Definition: coeffs.h:753
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition: coeffs.h:522
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:522
#define Print
Definition: emacs.cc:80
#define WarnS
Definition: emacs.cc:78
const CanonicalForm int s
Definition: facAbsFact.cc:51
CanonicalForm res
Definition: facAbsFact.cc:60
CanonicalForm H
Definition: facAbsFact.cc:60
bool found
Definition: facFactorize.cc:55
int j
Definition: facHensel.cc:110
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
static int min(int a, int b)
Definition: fast_mult.cc:268
static int max(int a, int b)
Definition: fast_mult.cc:264
#define STATIC_VAR
Definition: globaldefs.h:7
#define VAR
Definition: globaldefs.h:5
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge, ring tailRing)
Definition: hdegree.cc:1079
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition: ideals.cc:830
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
#define idIsConstant(I)
Definition: ideals.h:40
BOOLEAN idInsertPoly(ideal h1, poly h2)
insert h2 into h1 (if h2 is not the zero polynomial) return TRUE iff h2 was indeed inserted
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
ideal idCopy(ideal A)
Definition: ideals.h:60
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition: ideals.h:37
static BOOLEAN length(leftv result, leftv arg)
Definition: interval.cc:257
STATIC_VAR jList * T
Definition: janet.cc:30
STATIC_VAR Poly * h
Definition: janet.cc:971
STATIC_VAR jList * Q
Definition: janet.cc:30
KINLINE unsigned long * initsevT()
Definition: kInline.h:100
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:970
KINLINE TSet initT()
Definition: kInline.h:84
KINLINE void k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing, poly &m1, poly &m2, poly &lcm, const ring tailRing)
Definition: kInline.h:1072
KINLINE int ksReducePolyTailLC_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1120
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1185
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1158
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1195
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1248
KINLINE TObject ** initR()
Definition: kInline.h:95
KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r, poly &m1, poly &m2, const ring m_r)
Definition: kInline.h:1029
KINLINE int ksReducePolyTail_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1138
int redLiftstd(LObject *h, kStrategy strat)
Definition: kLiftstd.cc:167
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
Definition: kbuckets.cc:197
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:216
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
Definition: kbuckets.cc:660
int ksCheckCoeff(number *a, number *b)
BOOLEAN pCompareChainPart(poly p, poly p1, poly p2, poly lcm, const ring R)
Definition: kpolys.cc:71
BOOLEAN pCompareChain(poly p, poly p1, poly p2, poly lcm, const ring R)
Returns TRUE if.
Definition: kpolys.cc:17
poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing)
Definition: kspoly.cc:1430
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition: kstd1.cc:1352
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2420
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:3167
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:2433
int kFindDivisibleByInT_Z(const kStrategy strat, const LObject *L, const int start)
Definition: kstd2.cc:209
int redHoney(LObject *h, kStrategy strat)
Definition: kstd2.cc:1901
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:938
int redLazy(LObject *h, kStrategy strat)
Definition: kstd2.cc:1696
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:831
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:290
VAR int strat_nr
Definition: kstdfac.cc:21
void initSbaPos(kStrategy strat)
Definition: kutil.cc:10168
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7768
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7131
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6589
#define pDivComp_LESS
Definition: kutil.cc:136
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6703
int getIndexRng(long coeff)
Definition: kutil.cc:6249
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6346
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5456
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10057
poly pMove2CurrTail(poly p, kStrategy strat)
Definition: kutil.cc:11955
int posInTrg0(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5129
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:797
VAR int HCord
Definition: kutil.cc:246
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3254
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition: kutil.cc:548
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition: kutil.cc:6938
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9636
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6090
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:169
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5052
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9434
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:4996
void enterTShift(LObject p, kStrategy strat, int atT)
Definition: kutil.cc:13432
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5247
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:6913
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9208
BOOLEAN kTest(kStrategy strat)
Definition: kutil.cc:1036
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4027
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1668
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7320
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5323
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:4985
poly pMoveCurrTail2poly(poly p, kStrategy strat)
Definition: kutil.cc:11969
BOOLEAN kTest_TS(kStrategy strat)
Definition: kutil.cc:1097
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2032
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:742
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition: kutil.cc:10830
VAR int Kstd1_mu
Definition: kutil.cc:248
void initenterstrongPairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:13218
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4613
static void enterOnePairRingShift(poly q, poly p, int, int isFromQ, kStrategy strat, int atR, int, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12250
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1360
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:6854
static BOOLEAN enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12494
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4530
static int pLPDivComp(poly p, poly q)
Definition: kutil.cc:232
int posInT2(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5024
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6434
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6387
#define kFalseReturn(x)
Definition: kutil.cc:804
static BOOLEAN enterOnePairWithShifts(int q_inS, poly q, poly p, int ecartp, int p_isFromQ, kStrategy strat, int, int p_lastVblock, int q_lastVblock)
Definition: kutil.cc:12504
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11783
static intset initec(const int maxnr)
Definition: kutil.cc:534
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition: kutil.cc:9868
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4587
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5294
void redtailBbaAlsoLC_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7436
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6805
static void deleteHCBucket(LObject *L, kStrategy strat)
Definition: kutil.cc:250
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9714
static BOOLEAN enterOnePairWithoutShifts(int p_inS, poly q, poly p, int ecartq, int q_isFromQ, kStrategy strat, int, int p_lastVblock, int q_shift)
Definition: kutil.cc:12569
void chainCritSig(poly p, int, kStrategy strat)
Definition: kutil.cc:3554
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition: kutil.cc:4864
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1406
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4247
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4569
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8805
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5816
static int pDivCompRing(poly p, poly q)
Definition: kutil.cc:144
BOOLEAN isInPairsetB(poly q, int *k, kStrategy strat)
Definition: kutil.cc:727
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:9884
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:3902
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7891
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11278
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7207
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7565
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11399
void initPairtest(kStrategy strat)
Definition: kutil.cc:697
static BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
Definition: kutil.cc:2295
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5790
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8387
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3538
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5088
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:1426
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8781
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition: kutil.cc:8693
poly pCopyL2p(LObject H, kStrategy strat)
Definition: kutil.cc:11986
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:12952
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4302
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3967
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6469
static void enlargeL(LSet *L, int *length, const int incr)
Definition: kutil.cc:687
int posInT17_c(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5563
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:13455
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11692
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5361
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9534
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:11020
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6770
void HEckeTest(poly pp, kStrategy strat)
Definition: kutil.cc:505
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5747
STATIC_VAR BOOLEAN sloppy_max
Definition: kutil.cc:824
VAR int Kstd1_deg
Definition: kutil.cc:247
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition: kutil.cc:4412
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:13402
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2526
BOOLEAN kTest_L(LObject *L, kStrategy strat, BOOLEAN testp, int lpos, TSet T, int tlength)
Definition: kutil.cc:950
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:10142
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:7822
void initEcartNormal(TObject *h)
Definition: kutil.cc:1384
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:4763
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:8850
static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
Definition: kutil.cc:1268
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8082
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6160
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3185
char * showOption()
Definition: misc_ip.cc:709
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6545
void initSyzRules(kStrategy strat)
Definition: kutil.cc:8232
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5848
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10270
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10791
void cleanT(kStrategy strat)
Definition: kutil.cc:569
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2314
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5205
BOOLEAN kTest_S(kStrategy strat)
Definition: kutil.cc:1079
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:6008
void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
Definition: kutil.cc:9343
static const char * kTest_LmEqual(poly p, poly t_p, ring tailRing)
Definition: kutil.cc:807
void reorderS(int *suc, kStrategy strat)
Definition: kutil.cc:4710
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4329
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6504
#define pDivComp_INCOMP
Definition: kutil.cc:138
BOOLEAN kTest_T(TObject *T, kStrategy strat, int i, char TN)
Definition: kutil.cc:825
void kMergeBintoLSba(kStrategy strat)
Definition: kutil.cc:3275
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:294
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10385
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4556
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition: kutil.cc:1417
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5690
#define pDivComp_GREATER
Definition: kutil.cc:137
void exitSba(kStrategy strat)
Definition: kutil.cc:10345
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition: kutil.cc:6989
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5415
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5517
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition: kutil.cc:1630
BOOLEAN enterOnePairShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12609
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition: kutil.cc:11817
int posInLrg0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6262
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1295
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11371
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3613
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1615
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9732
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:628
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5624
void deleteInSSba(int i, kStrategy strat)
Definition: kutil.cc:1215
static int pDivComp(poly p, poly q)
Definition: kutil.cc:183
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:10597
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6639
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:9970
int kFindInTShift(poly p, TSet T, int tlength)
Definition: kutil.cc:767
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:11096
static BOOLEAN enterOneStrongPolyShift(poly q, poly p, int, int, kStrategy strat, int atR, int, int, int shiftcount, int ifromS)
Definition: kutil.cc:12081
void messageSets(kStrategy strat)
Definition: kutil.cc:7841
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1163
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8676
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11746
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5872
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition: kutil.cc:706
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition: kutil.cc:1780
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6124
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:10853
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:4636
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3297
void initEcartBBA(TObject *h)
Definition: kutil.cc:1392
VAR denominator_list DENOMINATOR_LIST
Definition: kutil.cc:84
int posInLRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5935
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2783
void enterSBbaShift(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9185
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6048
poly redtailBba_Ring(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7679
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:6036
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:539
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1399
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7809
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1838
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:4089
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8531
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7985
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:4941
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:11185
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9085
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:9797
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10719
#define pDivComp_EQUAL
Definition: kutil.cc:135
static int * initS_2_R(const int maxnr)
Definition: kutil.cc:543
void cancelunit(LObject *L, BOOLEAN inNF)
Definition: kutil.cc:373
denominator_list_s * denominator_list
Definition: kutil.h:63
TObject * TSet
Definition: kutil.h:59
#define setmaxL
Definition: kutil.h:30
#define setmaxTinc
Definition: kutil.h:34
static int kFindInL1(const poly p, const kStrategy strat)
Definition: kutil.h:850
#define setmax
Definition: kutil.h:29
int64 wlen_type
Definition: kutil.h:54
static LSet initL(int nr=setmaxL)
Definition: kutil.h:421
LObject * LSet
Definition: kutil.h:60
denominator_list next
Definition: kutil.h:65
static void kDeleteLcm(LObject *P)
Definition: kutil.h:885
int * intset
Definition: kutil.h:53
#define ALLOW_PROD_CRIT(A)
Definition: kutil.h:395
#define setmaxT
Definition: kutil.h:33
#define setmaxLinc
Definition: kutil.h:31
class sTObject TObject
Definition: kutil.h:57
#define REDTAIL_CANONICALIZE
Definition: kutil.h:38
class sLObject LObject
Definition: kutil.h:58
if(yy_init)
Definition: libparse.cc:1420
static bool rIsSCA(const ring r)
Definition: nc.h:190
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
Definition: old.gring.cc:1879
@ nc_lie
Definition: nc.h:18
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
Definition: old.gring.cc:2243
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:159
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:709
#define assume(x)
Definition: mod2.h:387
#define r_assume(x)
Definition: mod2.h:388
int dReportError(const char *fmt,...)
Definition: dError.cc:43
#define p_GetComp(p, r)
Definition: monomials.h:64
#define pFalseReturn(cond)
Definition: monomials.h:139
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44
#define pSetCoeff0(p, n)
Definition: monomials.h:59
#define p_GetCoeff(p, r)
Definition: monomials.h:50
#define __p_GetComp(p, r)
Definition: monomials.h:63
#define rRing_has_Comp(r)
Definition: monomials.h:266
#define pAssume(cond)
Definition: monomials.h:90
STATIC_VAR gmp_float * diff
Definition: mpr_complex.cc:45
#define nDelete(n)
Definition: numbers.h:16
#define nIsZero(n)
Definition: numbers.h:19
#define nEqual(n1, n2)
Definition: numbers.h:20
#define nCopy(n)
Definition: numbers.h:15
#define nGreater(a, b)
Definition: numbers.h:28
#define nGreaterZero(n)
Definition: numbers.h:27
#define nInvers(a)
Definition: numbers.h:33
#define nIsOne(n)
Definition: numbers.h:25
#define nInit(i)
Definition: numbers.h:24
#define nTest(a)
Definition: numbers.h:35
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omCheckBinAddrSize(addr, size)
Definition: omAllocDecl.h:326
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221
#define omSizeWOfBin(bin_ptr)
#define NULL
Definition: omList.c:12
omBin_t * omBin
Definition: omStructs.h:12
#define REGISTER
Definition: omalloc.h:27
#define TEST_OPT_WEIGHTM
Definition: options.h:121
#define TEST_OPT_IDLIFT
Definition: options.h:129
#define TEST_OPT_INTSTRATEGY
Definition: options.h:110
#define TEST_OPT_REDTAIL
Definition: options.h:116
#define TEST_OPT_INFREDTAIL
Definition: options.h:118
#define TEST_OPT_SUGARCRIT
Definition: options.h:107
#define TEST_OPT_OLDSTD
Definition: options.h:123
#define TEST_OPT_REDSB
Definition: options.h:104
#define TEST_OPT_DEGBOUND
Definition: options.h:113
#define TEST_OPT_SB_1
Definition: options.h:119
#define TEST_OPT_NOT_SUGAR
Definition: options.h:106
#define TEST_OPT_PROT
Definition: options.h:103
#define OPT_INTERRUPT
Definition: options.h:79
#define TEST_OPT_CANCELUNIT
Definition: options.h:128
#define BTEST1(a)
Definition: options.h:33
#define TEST_OPT_DEBUG
Definition: options.h:108
#define TEST_OPT_CONTENTSB
Definition: options.h:127
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
poly p_GetMaxExpP(poly p, const ring r)
return monomial r such that GetExp(r,i) is maximum of all monomials in p; coeff == 0,...
Definition: p_polys.cc:1134
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:3015
long pLDegb(poly p, int *l, const ring r)
Definition: p_polys.cc:807
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:971
long p_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:592
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1034
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3723
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1064
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition: p_polys.cc:4559
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:937
long pLDeg1(poly p, int *l, const ring r)
Definition: p_polys.cc:837
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4814
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:906
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:609
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition: p_polys.cc:1204
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2906
long pLDeg1c(poly p, int *l, const ring r)
Definition: p_polys.cc:873
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1001
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:766
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:1171
long pLDeg0(poly p, int *l, const ring r)
Definition: p_polys.cc:735
poly p_One(const ring r)
Definition: p_polys.cc:1309
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1982
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3770
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:583
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition: p_polys.cc:1647
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1079
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1397
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:908
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:711
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1383
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:102
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:1834
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:380
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition: p_polys.h:753
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition: p_polys.h:1285
static void p_LmDelete0(poly p, const ring r)
Definition: p_polys.h:717
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1707
#define __pp_Mult_nn(p, n, r)
Definition: p_polys.h:974
static poly pp_mm_Mult(poly p, poly m, const ring r)
Definition: p_polys.h:1013
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1003
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition: p_polys.h:1619
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:254
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:164
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:247
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:233
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:412
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1552
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1909
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:469
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:71
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1875
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:900
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:873
static unsigned pLength(poly a)
Definition: p_polys.h:191
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:112
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:703
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1023
static void p_LmFree(poly p, ring)
Definition: p_polys.h:683
#define p_LmTest(p, r)
Definition: p_polys.h:163
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:818
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1479
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition: p_polys.h:2018
#define p_Test(p, r)
Definition: p_polys.h:162
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:373
void rChangeCurrRing(ring r)
Definition: polys.cc:15
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
Compatiblity layer for legacy polynomial operations (over currRing)
#define pAdd(p, q)
Definition: polys.h:203
#define pLtCmp(p, q)
Definition: polys.h:123
#define pLtCmpOrdSgnDiffM(p, q)
Definition: polys.h:125
#define pDelete(p_ptr)
Definition: polys.h:186
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL
Definition: polys.h:67
#define pLmIsConstantComp(p)
like above, except that p must be != NULL
Definition: polys.h:242
#define pSetm(p)
Definition: polys.h:271
#define pIsConstant(p)
like above, except that Comp must be 0
Definition: polys.h:238
#define pHasNotCF(p1, p2)
Definition: polys.h:263
#define pLtCmpOrdSgnDiffP(p, q)
Definition: polys.h:126
#define pNeg(p)
Definition: polys.h:198
#define pLmEqual(p1, p2)
Definition: polys.h:111
#define ppMult_mm(p, m)
Definition: polys.h:201
#define pGetComp(p)
Component.
Definition: polys.h:37
#define pIsVector(p)
Definition: polys.h:250
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
void pNorm(poly p)
Definition: polys.h:363
#define pJet(p, m)
Definition: polys.h:368
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition: polys.h:146
#define pCmp(p1, p2)
pCmp: args may be NULL returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
Definition: polys.h:115
#define pDivideM(a, b)
Definition: polys.h:294
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
#define pSetComp(p, v)
Definition: polys.h:38
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl....
Definition: polys.h:152
void wrp(poly p)
Definition: polys.h:310
#define pLmDivisibleBy(a, b)
like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
Definition: polys.h:140
static void pLmFree(poly p)
frees the space of the monomial m, assumes m != NULL coef is not freed, m is not advanced
Definition: polys.h:70
void pWrite(poly p)
Definition: polys.h:308
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
#define pSetmComp(p)
TODO:
Definition: polys.h:273
#define pHasNotCFRing(p1, p2)
Definition: polys.h:262
#define pNormalize(p)
Definition: polys.h:317
#define pIsPurePower(p)
Definition: polys.h:248
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:61
#define pEqualPolys(p1, p2)
Definition: polys.h:400
#define pDivisibleBy(a, b)
returns TRUE, if leading monom of a divides leading monom of b i.e., if there exists a expvector c > ...
Definition: polys.h:138
#define pSetExp(p, i, v)
Definition: polys.h:42
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:105
#define pLtCmpOrdSgnEqP(p, q)
Definition: polys.h:128
#define pCopy(p)
return a copy of the poly
Definition: polys.h:185
#define pOne()
Definition: polys.h:315
char * pString(poly p)
Definition: polys.h:306
poly * polyset
Definition: polys.h:259
#define pDecrExp(p, i)
Definition: polys.h:44
#define pLcm(a, b, m)
Definition: polys.h:295
poly prMoveR(poly &p, ring src_r, ring dest_r)
Definition: prCopy.cc:89
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
Definition: prCopy.cc:45
void pLcmRat(poly a, poly b, poly m, int rat_shift)
Definition: ratgring.cc:30
void PrintS(const char *s)
Definition: reporter.cc:284
void PrintLn()
Definition: reporter.cc:310
#define mflush()
Definition: reporter.h:58
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition: ring.cc:3395
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5647
void rKillModifiedRing(ring r)
Definition: ring.cc:3004
ring rAssure_c_dp(const ring r)
Definition: ring.cc:4931
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2643
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1363
void rDebugPrint(const ring r)
Definition: ring.cc:4067
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:449
static int rBlocks(ring r)
Definition: ring.h:569
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:400
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:724
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:488
static BOOLEAN rIsRatGRing(const ring r)
Definition: ring.h:427
static BOOLEAN rIsLPRing(const ring r)
Definition: ring.h:411
rRingOrder_t
order stuff
Definition: ring.h:68
@ ringorder_a
Definition: ring.h:70
@ ringorder_C
Definition: ring.h:73
@ ringorder_c
Definition: ring.h:72
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:762
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:721
poly(* pShallowCopyDeleteProc)(poly s_p, ring source_r, ring dest_r, omBin dest_bin)
returns a poly from dest_r which is a ShallowCopy of s_p from source_r assumes that source_r->N == de...
Definition: ring.h:44
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:593
BOOLEAN rHasGlobalOrdering(const ring r)
Definition: ring.h:760
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:761
#define rField_is_Ring(R)
Definition: ring.h:486
int p_mLPmaxPossibleShift(poly p, const ring r)
Definition: shiftgb.cc:45
#define pLPCopyAndShiftLM(p, sh)
Definition: shiftgb.h:15
BOOLEAN _p_LPLmDivisibleByNoComp(poly a, poly b, const ring r)
Definition: shiftop.cc:794
int p_mFirstVblock(poly p, const ring ri)
Definition: shiftop.cc:476
void k_SplitFrame(poly &m1, poly &m2, int at, const ring r)
Definition: shiftop.cc:598
void p_mLPshift(poly m, int sh, const ring ri)
Definition: shiftop.cc:360
#define pmFirstVblock(p)
Definition: shiftop.h:35
#define pLPDivisibleBy(a, b)
Definition: shiftop.h:57
#define pIsInV(p)
Definition: shiftop.h:50
#define pmIsInV(p)
Definition: shiftop.h:51
#define pmLastVblock(p)
Definition: shiftop.h:33
#define pLPLmDivisibleBy(a, b)
Definition: shiftop.h:58
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
int idElem(const ideal F)
count non-zero elements
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
ideal id_MaxIdeal(const ring r)
initialise the maximal ideal (at 0)
Definition: simpleideals.cc:98
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
#define IDELEMS(i)
Definition: simpleideals.h:23
#define R
Definition: sirandom.c:27
@ isHomog
Definition: structs.h:37
@ isNotHomog
Definition: structs.h:36
skStrategy * kStrategy
Definition: structs.h:58
#define loop
Definition: structs.h:75
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition: syz3.cc:1026
#define degbound(p)
Definition: tgb.cc:153
int gcd(int a, int b)
Definition: walkSupport.cc:836
long totaldegreeWecart(poly p, ring r)
Definition: weight.cc:217
long maxdegreeWecart(poly p, int *l, ring r)
Definition: weight.cc:247
EXTERN_VAR short * ecartWeights
Definition: weight.h:12
#define omGetStickyBinOfBin(B)
Definition: xalloc.h:300
#define omMergeStickyBinIntoBin(A, B)
Definition: xalloc.h:329