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 /*2
1268 *cancels the j-th polynomial in the set
1269 */
1270 void deleteInL (LSet set, int *length, int j,kStrategy strat)
1271 {
1272  if (set[j].lcm!=NULL)
1273  {
1274  kDeleteLcm(&set[j]);
1275  }
1276  if (set[j].sig!=NULL)
1277  {
1278 #ifdef HAVE_RINGS
1279  if (pGetCoeff(set[j].sig) != NULL)
1280  pLmDelete(set[j].sig);
1281  else
1282 #endif
1283  pLmFree(set[j].sig);
1284  }
1285  if (set[j].p!=NULL)
1286  {
1287  if (pNext(set[j].p) == strat->tail)
1288  {
1289 #ifdef HAVE_RINGS
1290  if (pGetCoeff(set[j].p) != NULL)
1291  pLmDelete(set[j].p);
1292  else
1293 #endif
1294  pLmFree(set[j].p);
1295  /*- tail belongs to several int spolys -*/
1296  }
1297  else
1298  {
1299  // search p in T, if it is there, do not delete it
1300  if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1301  {
1302  // assure that for global orderings kFindInT fails
1303  //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1304  set[j].Delete();
1305  }
1306  }
1307  }
1308  if (*length > 0 && j < *length)
1309  {
1310 #ifdef ENTER_USE_MEMMOVE
1311  memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1312 #else
1313  int i;
1314  for (i=j; i < (*length); i++)
1315  set[i] = set[i+1];
1316 #endif
1317  }
1318 #ifdef KDEBUG
1319  memset(&(set[*length]),0,sizeof(LObject));
1320 #endif
1321  (*length)--;
1322 }
1323 
1324 /*2
1325 *enters p at position at in L
1326 */
1327 void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1328 {
1329  // this should be corrected
1330  assume(p.FDeg == p.pFDeg());
1331 
1332  if ((*length)>=0)
1333  {
1334  if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1335  if (at <= (*length))
1336 #ifdef ENTER_USE_MEMMOVE
1337  memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1338 #else
1339  for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1340 #endif
1341  }
1342  else at = 0;
1343  (*set)[at] = p;
1344  (*length)++;
1345 }
1346 
1347 /*2
1348 * computes the normal ecart;
1349 * used in mora case and if pLexOrder & sugar in bba case
1350 */
1352 {
1353  h->FDeg = h->pFDeg();
1354  h->ecart = h->pLDeg() - h->FDeg;
1355  // h->length is set by h->pLDeg
1356  h->length=h->pLength=pLength(h->p);
1357 }
1358 
1360 {
1361  h->FDeg = h->pFDeg();
1362  (*h).ecart = 0;
1363  h->length=h->pLength=pLength(h->p);
1364 }
1365 
1366 void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1367 {
1368  Lp->FDeg = Lp->pFDeg();
1369  (*Lp).ecart = 0;
1370  (*Lp).length = 0;
1371 }
1372 
1373 void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1374 {
1375  Lp->FDeg = Lp->pFDeg();
1376  (*Lp).ecart = si_max(ecartF,ecartG);
1377  (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1378  (*Lp).length = 0;
1379 }
1380 
1381 /*2
1382 *if ecart1<=ecart2 it returns TRUE
1383 */
1384 static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1385 {
1386  return (ecart1 <= ecart2);
1387 }
1388 
1389 #ifdef HAVE_RINGS
1390 /*2
1391 * put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1392 */
1393 static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1394 {
1395  assume(atR >= 0);
1396  assume(i<=strat->sl);
1397  assume(p!=NULL);
1399  #if ALL_VS_JUST
1400  //Over rings, if we construct the strong pair, do not add the spair
1402  {
1403  number s,t,d;
1404  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1405 
1406  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1407  {
1408  nDelete(&d);
1409  nDelete(&s);
1410  nDelete(&t);
1411  return;
1412  }
1413  nDelete(&d);
1414  nDelete(&s);
1415  nDelete(&t);
1416  }
1417  #endif
1418  int j,compare,compareCoeff;
1419  LObject h;
1420 
1421 #ifdef KDEBUG
1422  h.ecart=0; h.length=0;
1423 #endif
1424  /*- computes the lcm(s[i],p) -*/
1425  if(pHasNotCFRing(p,strat->S[i]))
1426  {
1427  strat->cp++;
1428  return;
1429  }
1430  h.lcm = p_Lcm(p,strat->S[i],currRing);
1431  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1432  if (nIsZero(pGetCoeff(h.lcm)))
1433  {
1434  strat->cp++;
1435  pLmDelete(h.lcm);
1436  return;
1437  }
1438  // basic chain criterion
1439  /*
1440  *the set B collects the pairs of type (S[j],p)
1441  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1442  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
1443  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
1444  */
1445 
1446  for(j = strat->Bl;j>=0;j--)
1447  {
1448  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1449  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1450  if(compare == pDivComp_EQUAL)
1451  {
1452  //They have the same LM
1453  if(compareCoeff == pDivComp_LESS)
1454  {
1455  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1456  {
1457  strat->c3++;
1458  pLmDelete(h.lcm);
1459  return;
1460  }
1461  break;
1462  }
1463  if(compareCoeff == pDivComp_GREATER)
1464  {
1465  deleteInL(strat->B,&strat->Bl,j,strat);
1466  strat->c3++;
1467  }
1468  if(compareCoeff == pDivComp_EQUAL)
1469  {
1470  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1471  {
1472  strat->c3++;
1473  pLmDelete(h.lcm);
1474  return;
1475  }
1476  break;
1477  }
1478  }
1479  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1480  {
1481  if(compare == pDivComp_LESS)
1482  {
1483  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1484  {
1485  strat->c3++;
1486  pLmDelete(h.lcm);
1487  return;
1488  }
1489  break;
1490  }
1491  if(compare == pDivComp_GREATER)
1492  {
1493  deleteInL(strat->B,&strat->Bl,j,strat);
1494  strat->c3++;
1495  }
1496  }
1497  }
1498  number s, t;
1499  poly m1, m2, gcd = NULL;
1500  s = pGetCoeff(strat->S[i]);
1501  t = pGetCoeff(p);
1502  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1503  ksCheckCoeff(&s, &t, currRing->cf);
1504  pSetCoeff0(m1, s);
1505  pSetCoeff0(m2, t);
1506  m2 = pNeg(m2);
1507  p_Test(m1,strat->tailRing);
1508  p_Test(m2,strat->tailRing);
1509  poly si = pCopy(strat->S[i]);
1510  poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1511  poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1512  pDelete(&si);
1513  p_LmDelete(m1, currRing);
1514  p_LmDelete(m2, currRing);
1515  if(sim2 == NULL)
1516  {
1517  if(pm1 == NULL)
1518  {
1519  if(h.lcm != NULL)
1520  {
1521  pLmDelete(h.lcm);
1522  h.lcm=NULL;
1523  }
1524  h.Clear();
1525  if (strat->pairtest==NULL) initPairtest(strat);
1526  strat->pairtest[i] = TRUE;
1527  strat->pairtest[strat->sl+1] = TRUE;
1528  return;
1529  }
1530  else
1531  {
1532  gcd = pm1;
1533  pm1 = NULL;
1534  }
1535  }
1536  else
1537  {
1538  if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1539  {
1540  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1541  pSetmComp(sim2);
1542  }
1543  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1544  gcd = p_Add_q(pm1, sim2, strat->tailRing);
1545  }
1546  p_Test(gcd, strat->tailRing);
1547 #ifdef KDEBUG
1548  if (TEST_OPT_DEBUG)
1549  {
1550  wrp(gcd);
1551  PrintLn();
1552  }
1553 #endif
1554  h.p = gcd;
1555  h.i_r = -1;
1556  if(h.p == NULL)
1557  {
1558  if (strat->pairtest==NULL) initPairtest(strat);
1559  strat->pairtest[i] = TRUE;
1560  strat->pairtest[strat->sl+1] = TRUE;
1561  return;
1562  }
1563  h.tailRing = strat->tailRing;
1564  int posx;
1565  //h.pCleardenom();
1566  //pSetm(h.p);
1567  h.i_r1 = -1;h.i_r2 = -1;
1568  strat->initEcart(&h);
1569  #if 1
1570  h.p2 = strat->S[i];
1571  h.p1 = p;
1572  #endif
1573  #if 1
1574  if (atR >= 0)
1575  {
1576  h.i_r1 = atR;
1577  h.i_r2 = strat->S_2_R[i];
1578  }
1579  #endif
1580  if (strat->Bl==-1)
1581  posx =0;
1582  else
1583  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1584  h.sev = pGetShortExpVector(h.p);
1585  if (currRing!=strat->tailRing)
1586  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1587  if (strat->P.p!=NULL) strat->P.sev = pGetShortExpVector(strat->P.p);
1588  else strat->P.sev=0L;
1589  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1590  kTest_TS(strat);
1591 }
1592 
1593 /*2
1594 * put the lcm(s[i],p) into the set B
1595 */
1596 
1597 static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1598 {
1599  number d, s, t;
1600  assume(atR >= 0);
1602  poly m1, m2, gcd,si;
1603  if(!enterTstrong)
1604  {
1605  assume(i<=strat->sl);
1606  si = strat->S[i];
1607  }
1608  else
1609  {
1610  assume(i<=strat->tl);
1611  si = strat->T[i].p;
1612  }
1613  //printf("\n--------------------------------\n");
1614  //pWrite(p);pWrite(si);
1615  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1616 
1617  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1618  {
1619  nDelete(&d);
1620  nDelete(&s);
1621  nDelete(&t);
1622  return FALSE;
1623  }
1624 
1625  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1626 
1628  {
1629  unsigned long sev = pGetShortExpVector(gcd);
1630 
1631  for (int j = 0; j < strat->sl; j++)
1632  {
1633  if (j == i)
1634  continue;
1635 
1636  if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf)
1637  && !(strat->sevS[j] & ~sev)
1638  && p_LmDivisibleBy(strat->S[j], gcd, currRing))
1639  {
1640  nDelete(&d);
1641  nDelete(&s);
1642  nDelete(&t);
1643  return FALSE;
1644  }
1645  }
1646  }
1647 
1648  //p_Test(m1,strat->tailRing);
1649  //p_Test(m2,strat->tailRing);
1650  /*if(!enterTstrong)
1651  {
1652  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1653  {
1654  memset(&(strat->P), 0, sizeof(strat->P));
1655  kStratChangeTailRing(strat);
1656  strat->P = *(strat->R[atR]);
1657  p_LmFree(m1, strat->tailRing);
1658  p_LmFree(m2, strat->tailRing);
1659  p_LmFree(gcd, currRing);
1660  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1661  }
1662  }*/
1663  pSetCoeff0(m1, s);
1664  pSetCoeff0(m2, t);
1665  pSetCoeff0(gcd, d);
1666  p_Test(m1,strat->tailRing);
1667  p_Test(m2,strat->tailRing);
1668  //printf("\n===================================\n");
1669  //pWrite(m1);pWrite(m2);pWrite(gcd);
1670 #ifdef KDEBUG
1671  if (TEST_OPT_DEBUG)
1672  {
1673  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1674  PrintS("m1 = ");
1675  p_wrp(m1, strat->tailRing);
1676  PrintS(" ; m2 = ");
1677  p_wrp(m2, strat->tailRing);
1678  PrintS(" ; gcd = ");
1679  wrp(gcd);
1680  PrintS("\n--- create strong gcd poly: ");
1681  Print("\n p: %d", i);
1682  wrp(p);
1683  Print("\n strat->S[%d]: ", i);
1684  wrp(si);
1685  PrintS(" ---> ");
1686  }
1687 #endif
1688 
1689  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1690  p_LmDelete(m1, strat->tailRing);
1691  p_LmDelete(m2, strat->tailRing);
1692 #ifdef KDEBUG
1693  if (TEST_OPT_DEBUG)
1694  {
1695  wrp(gcd);
1696  PrintLn();
1697  }
1698 #endif
1699 
1700  LObject h;
1701  h.p = gcd;
1702  h.tailRing = strat->tailRing;
1703  int posx;
1704  strat->initEcart(&h);
1705  h.sev = pGetShortExpVector(h.p);
1706  h.i_r1 = -1;h.i_r2 = -1;
1707  if (currRing!=strat->tailRing)
1708  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1709  if(!enterTstrong)
1710  {
1711  #if 1
1712  h.p1 = p;h.p2 = strat->S[i];
1713  #endif
1714  if (atR >= 0)
1715  {
1716  h.i_r2 = strat->S_2_R[i];
1717  h.i_r1 = atR;
1718  }
1719  else
1720  {
1721  h.i_r1 = -1;
1722  h.i_r2 = -1;
1723  }
1724  if (strat->Ll==-1)
1725  posx =0;
1726  else
1727  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1728  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1729  }
1730  else
1731  {
1732  if(h.IsNull()) return FALSE;
1733  //int red_result;
1734  //reduzieren ist teur!!!
1735  //if(strat->L != NULL)
1736  //red_result = strat->red(&h,strat);
1737  if(!h.IsNull())
1738  {
1739  enterT(h, strat,-1);
1740  //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1741  //strat->enterS(h,pos,strat,-1);
1742  }
1743  }
1744  return TRUE;
1745 }
1746 
1748 {
1749  if(strat->sl < 0) return FALSE;
1750  int i;
1751  for(i=0;i<strat->sl;i++)
1752  {
1753  //Construct the gcd pair between h and S[i]
1754  number d, s, t;
1755  poly m1, m2, gcd;
1756  d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1757  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1758  {
1759  nDelete(&d);
1760  nDelete(&s);
1761  nDelete(&t);
1762  }
1763  else
1764  {
1765  k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1766  pSetCoeff0(m1, s);
1767  pSetCoeff0(m2, t);
1768  pSetCoeff0(gcd, d);
1769  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);
1770  poly pSigMult = p_Copy(h->sig,currRing);
1771  poly sSigMult = p_Copy(strat->sig[i],currRing);
1772  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1773  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1774  p_LmDelete(m1, strat->tailRing);
1775  p_LmDelete(m2, strat->tailRing);
1776  poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1777  if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1778  {
1779  pDelete(&h->p);
1780  h->p = gcd;
1781  pDelete(&h->sig);
1782  h->sig = pairsig;
1783  pNext(h->sig) = NULL;
1784  strat->initEcart(h);
1785  h->sev = pGetShortExpVector(h->p);
1786  h->sevSig = pGetShortExpVector(h->sig);
1787  h->i_r1 = -1;h->i_r2 = -1;
1788  if(h->lcm != NULL)
1789  {
1790  pLmDelete(h->lcm);
1791  h->lcm = NULL;
1792  }
1793  if (currRing!=strat->tailRing)
1794  h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1795  return TRUE;
1796  }
1797  //Delete what you didn't use
1798  pDelete(&gcd);
1799  pDelete(&pairsig);
1800  }
1801  }
1802  return FALSE;
1803 }
1804 
1805 static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1806 {
1807  number d, s, t;
1808  assume(atR >= 0);
1809  poly m1, m2, gcd,si;
1810  assume(i<=strat->sl);
1811  si = strat->S[i];
1812  //printf("\n--------------------------------\n");
1813  //pWrite(p);pWrite(si);
1814  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1815 
1816  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1817  {
1818  nDelete(&d);
1819  nDelete(&s);
1820  nDelete(&t);
1821  return FALSE;
1822  }
1823 
1824  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1825  //p_Test(m1,strat->tailRing);
1826  //p_Test(m2,strat->tailRing);
1827  /*if(!enterTstrong)
1828  {
1829  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1830  {
1831  memset(&(strat->P), 0, sizeof(strat->P));
1832  kStratChangeTailRing(strat);
1833  strat->P = *(strat->R[atR]);
1834  p_LmFree(m1, strat->tailRing);
1835  p_LmFree(m2, strat->tailRing);
1836  p_LmFree(gcd, currRing);
1837  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1838  }
1839  }*/
1840  pSetCoeff0(m1, s);
1841  pSetCoeff0(m2, t);
1842  pSetCoeff0(gcd, d);
1843  p_Test(m1,strat->tailRing);
1844  p_Test(m2,strat->tailRing);
1845  //printf("\n===================================\n");
1846  //pWrite(m1);pWrite(m2);pWrite(gcd);
1847 #ifdef KDEBUG
1848  if (TEST_OPT_DEBUG)
1849  {
1850  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1851  PrintS("m1 = ");
1852  p_wrp(m1, strat->tailRing);
1853  PrintS(" ; m2 = ");
1854  p_wrp(m2, strat->tailRing);
1855  PrintS(" ; gcd = ");
1856  wrp(gcd);
1857  PrintS("\n--- create strong gcd poly: ");
1858  Print("\n p: %d", i);
1859  wrp(p);
1860  Print("\n strat->S[%d]: ", i);
1861  wrp(si);
1862  PrintS(" ---> ");
1863  }
1864 #endif
1865 
1866  pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1867 
1868 #ifdef KDEBUG
1869  if (TEST_OPT_DEBUG)
1870  {
1871  wrp(gcd);
1872  PrintLn();
1873  }
1874 #endif
1875 
1876  //Check and set the signatures
1877  poly pSigMult = p_Copy(sig,currRing);
1878  poly sSigMult = p_Copy(strat->sig[i],currRing);
1879  pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1880  sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1881  p_LmDelete(m1, strat->tailRing);
1882  p_LmDelete(m2, strat->tailRing);
1883  poly pairsig;
1884  if(pLmCmp(pSigMult,sSigMult) == 0)
1885  {
1886  //Same lm, have to add them
1887  pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1888  //This might be zero
1889  }
1890  else
1891  {
1892  //Set the sig to either pSigMult or sSigMult
1893  if(pLtCmp(pSigMult,sSigMult)==1)
1894  {
1895  pairsig = pSigMult;
1896  pDelete(&sSigMult);
1897  }
1898  else
1899  {
1900  pairsig = sSigMult;
1901  pDelete(&pSigMult);
1902  }
1903  }
1904 
1905  LObject h;
1906  h.p = gcd;
1907  h.tailRing = strat->tailRing;
1908  h.sig = pairsig;
1909  int posx;
1910  strat->initEcart(&h);
1911  h.sev = pGetShortExpVector(h.p);
1912  h.i_r1 = -1;h.i_r2 = -1;
1913  if (currRing!=strat->tailRing)
1914  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1915  if(h.sig == NULL)
1916  {
1917  //sigdrop since we loose the signature
1918  strat->sigdrop = TRUE;
1919  //Try to reduce it as far as we can via redRing
1920  int red_result = redRing(&h,strat);
1921  if(red_result == 0)
1922  {
1923  // Cancel the sigdrop
1924  p_Delete(&h.sig,currRing);h.sig = NULL;
1925  strat->sigdrop = FALSE;
1926  return FALSE;
1927  }
1928  else
1929  {
1930  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1931  #if 1
1932  strat->enterS(h,0,strat,strat->tl);
1933  #endif
1934  return FALSE;
1935  }
1936  }
1937  if(!nGreaterZero(pGetCoeff(h.sig)))
1938  {
1939  h.sig = pNeg(h.sig);
1940  h.p = pNeg(h.p);
1941  }
1942 
1943  if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1944  {
1945  strat->sigdrop = TRUE;
1946  // Completely reduce it
1947  int red_result = redRing(&h,strat);
1948  if(red_result == 0)
1949  {
1950  // Reduced to 0
1951  strat->sigdrop = FALSE;
1952  p_Delete(&h.sig,currRing);h.sig = NULL;
1953  return FALSE;
1954  }
1955  else
1956  {
1957  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1958  // 0 - add just the original poly causing the sigdrop, 1 - add also this
1959  #if 1
1960  strat->enterS(h,0,strat, strat->tl+1);
1961  #endif
1962  return FALSE;
1963  }
1964  }
1965  //Check for sigdrop
1966  if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1967  {
1968  strat->sigdrop = TRUE;
1969  //Enter this element to S
1970  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1971  strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1972  }
1973  #if 1
1974  h.p1 = p;h.p2 = strat->S[i];
1975  #endif
1976  if (atR >= 0)
1977  {
1978  h.i_r2 = strat->S_2_R[i];
1979  h.i_r1 = atR;
1980  }
1981  else
1982  {
1983  h.i_r1 = -1;
1984  h.i_r2 = -1;
1985  }
1986  if (strat->Ll==-1)
1987  posx =0;
1988  else
1989  posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1990  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1991  return TRUE;
1992 }
1993 #endif
1994 
1995 /*2
1996 * put the pair (s[i],p) into the set B, ecart=ecart(p)
1997 */
1998 
1999 void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2000 {
2001  assume(i<=strat->sl);
2002 
2003  int l,j,compare;
2004  LObject Lp;
2005  Lp.i_r = -1;
2006 
2007 #ifdef KDEBUG
2008  Lp.ecart=0; Lp.length=0;
2009 #endif
2010  /*- computes the lcm(s[i],p) -*/
2011  Lp.lcm = pInit();
2012 
2013 #ifndef HAVE_RATGRING
2014  pLcm(p,strat->S[i],Lp.lcm);
2015 #elif defined(HAVE_RATGRING)
2016  if (rIsRatGRing(currRing))
2017  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2018  else
2019  pLcm(p,strat->S[i],Lp.lcm);
2020 #endif
2021  pSetm(Lp.lcm);
2022 
2023 
2024  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
2025  {
2026  if (strat->fromT && (strat->ecartS[i]>ecart))
2027  {
2028  pLmFree(Lp.lcm);
2029  return;
2030  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2031  }
2032  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2033  && pHasNotCF(p,strat->S[i]))
2034  {
2035  /*
2036  *the product criterion has applied for (s,p),
2037  *i.e. lcm(s,p)=product of the leading terms of s and p.
2038  *Suppose (s,r) is in L and the leading term
2039  *of p divides lcm(s,r)
2040  *(==> the leading term of p divides the leading term of r)
2041  *but the leading term of s does not divide the leading term of r
2042  *(notice that tis condition is automatically satisfied if r is still
2043  *in S), then (s,r) can be cancelled.
2044  *This should be done here because the
2045  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2046  *
2047  *Moreover, skipping (s,r) holds also for the noncommutative case.
2048  */
2049  strat->cp++;
2050  pLmFree(Lp.lcm);
2051  return;
2052  }
2053  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2054  /*
2055  *the set B collects the pairs of type (S[j],p)
2056  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2057  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2058  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2059  */
2060  {
2061  j = strat->Bl;
2062  loop
2063  {
2064  if (j < 0) break;
2065  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2066  if ((compare==1)
2067  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2068  {
2069  strat->c3++;
2070  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2071  {
2072  pLmFree(Lp.lcm);
2073  return;
2074  }
2075  break;
2076  }
2077  else
2078  if ((compare ==-1)
2079  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2080  {
2081  deleteInL(strat->B,&strat->Bl,j,strat);
2082  strat->c3++;
2083  }
2084  j--;
2085  }
2086  }
2087  }
2088  else /*sugarcrit*/
2089  {
2090  if (ALLOW_PROD_CRIT(strat))
2091  {
2092  if (strat->fromT && (strat->ecartS[i]>ecart))
2093  {
2094  pLmFree(Lp.lcm);
2095  return;
2096  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2097  }
2098  // if currRing->nc_type!=quasi (or skew)
2099  // TODO: enable productCrit for super commutative algebras...
2100  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2101  pHasNotCF(p,strat->S[i]))
2102  {
2103  /*
2104  *the product criterion has applied for (s,p),
2105  *i.e. lcm(s,p)=product of the leading terms of s and p.
2106  *Suppose (s,r) is in L and the leading term
2107  *of p divides lcm(s,r)
2108  *(==> the leading term of p divides the leading term of r)
2109  *but the leading term of s does not divide the leading term of r
2110  *(notice that tis condition is automatically satisfied if r is still
2111  *in S), then (s,r) can be canceled.
2112  *This should be done here because the
2113  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2114  */
2115  strat->cp++;
2116  pLmFree(Lp.lcm);
2117  return;
2118  }
2119  /*
2120  *the set B collects the pairs of type (S[j],p)
2121  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2122  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2123  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2124  */
2125  for(j = strat->Bl;j>=0;j--)
2126  {
2127  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2128  if (compare==1)
2129  {
2130  strat->c3++;
2131  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2132  {
2133  pLmFree(Lp.lcm);
2134  return;
2135  }
2136  break;
2137  }
2138  else
2139  if (compare ==-1)
2140  {
2141  deleteInL(strat->B,&strat->Bl,j,strat);
2142  strat->c3++;
2143  }
2144  }
2145  }
2146  }
2147  /*
2148  *the pair (S[i],p) enters B if the spoly != 0
2149  */
2150  /*- compute the short s-polynomial -*/
2151  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2152  pNorm(p);
2153 
2154  if ((strat->S[i]==NULL) || (p==NULL))
2155  return;
2156 
2157  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2158  Lp.p=NULL;
2159  else
2160  {
2161  #ifdef HAVE_PLURAL
2162  if ( rIsPluralRing(currRing) )
2163  {
2164  if(pHasNotCF(p, strat->S[i]))
2165  {
2166  if(ncRingType(currRing) == nc_lie)
2167  {
2168  // generalized prod-crit for lie-type
2169  strat->cp++;
2170  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2171  }
2172  else
2173  if( ALLOW_PROD_CRIT(strat) )
2174  {
2175  // product criterion for homogeneous case in SCA
2176  strat->cp++;
2177  Lp.p = NULL;
2178  }
2179  else
2180  {
2181  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2182  nc_CreateShortSpoly(strat->S[i], p, currRing);
2183  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2184  pNext(Lp.p) = strat->tail; // !!!
2185  }
2186  }
2187  else
2188  {
2189  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2190  nc_CreateShortSpoly(strat->S[i], p, currRing);
2191 
2192  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2193  pNext(Lp.p) = strat->tail; // !!!
2194  }
2195  }
2196  else
2197  #endif
2198  {
2200  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2201  }
2202  }
2203  if (Lp.p == NULL)
2204  {
2205  /*- the case that the s-poly is 0 -*/
2206  if (strat->pairtest==NULL) initPairtest(strat);
2207  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2208  strat->pairtest[strat->sl+1] = TRUE;
2209  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2210  /*
2211  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2212  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2213  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2214  *term of p divides the lcm(s,r)
2215  *(this canceling should be done here because
2216  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2217  *the first case is handeled in chainCrit
2218  */
2219  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2220  }
2221  else
2222  {
2223  /*- the pair (S[i],p) enters B -*/
2224  Lp.p1 = strat->S[i];
2225  Lp.p2 = p;
2226 
2227  if (
2229 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2230  )
2231  {
2232  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2233  pNext(Lp.p) = strat->tail; // !!!
2234  }
2235 
2236  if (atR >= 0)
2237  {
2238  Lp.i_r1 = strat->S_2_R[i];
2239  Lp.i_r2 = atR;
2240  }
2241  else
2242  {
2243  Lp.i_r1 = -1;
2244  Lp.i_r2 = -1;
2245  }
2246  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2247 
2249  {
2250  if (!rIsPluralRing(currRing)
2252  && (Lp.p->coef!=NULL))
2253  nDelete(&(Lp.p->coef));
2254  }
2255 
2256  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2257  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2258  }
2259 }
2260 
2261 /// p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
2262 static inline BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2263 {
2264  int i = rVar(r);
2265  loop
2266  {
2267  if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2268  return FALSE;
2269  i--;
2270  if (i == 0)
2271  return TRUE;
2272  }
2273 }
2274 
2275 /*2
2276 * put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2277 * (in the special case: idLift for ideals, i.e. strat->syzComp==1)
2278 * (prod.crit applies)
2279 */
2280 
2281 static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2282 {
2283  assume(ALLOW_PROD_CRIT(strat));
2285  assume(i<=strat->sl);
2286  assume(strat->syzComp==1);
2287 
2288  if ((strat->S[i]==NULL) || (p==NULL))
2289  return;
2290 
2291  int l,j,compare;
2292  LObject Lp;
2293  Lp.i_r = -1;
2294 
2295 #ifdef KDEBUG
2296  Lp.ecart=0; Lp.length=0;
2297 #endif
2298  /*- computes the lcm(s[i],p) -*/
2299  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2300 
2301  if (strat->sugarCrit)
2302  {
2303  if((!((strat->ecartS[i]>0)&&(ecart>0)))
2304  && p_HasNotCF_Lift(p,strat->S[i],currRing))
2305  {
2306  /*
2307  *the product criterion has applied for (s,p),
2308  *i.e. lcm(s,p)=product of the leading terms of s and p.
2309  *Suppose (s,r) is in L and the leading term
2310  *of p divides lcm(s,r)
2311  *(==> the leading term of p divides the leading term of r)
2312  *but the leading term of s does not divide the leading term of r
2313  *(notice that tis condition is automatically satisfied if r is still
2314  *in S), then (s,r) can be cancelled.
2315  *This should be done here because the
2316  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2317  *
2318  *Moreover, skipping (s,r) holds also for the noncommutative case.
2319  */
2320  strat->cp++;
2321  pLmFree(Lp.lcm);
2322  return;
2323  }
2324  else
2325  Lp.ecart = si_max(ecart,strat->ecartS[i]);
2326  if (strat->fromT && (strat->ecartS[i]>ecart))
2327  {
2328  pLmFree(Lp.lcm);
2329  return;
2330  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2331  }
2332  /*
2333  *the set B collects the pairs of type (S[j],p)
2334  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2335  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2336  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2337  */
2338  {
2339  j = strat->Bl;
2340  loop
2341  {
2342  if (j < 0) break;
2343  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2344  if ((compare==1)
2345  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2346  {
2347  strat->c3++;
2348  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2349  {
2350  pLmFree(Lp.lcm);
2351  return;
2352  }
2353  break;
2354  }
2355  else
2356  if ((compare ==-1)
2357  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2358  {
2359  deleteInL(strat->B,&strat->Bl,j,strat);
2360  strat->c3++;
2361  }
2362  j--;
2363  }
2364  }
2365  }
2366  else /*sugarcrit*/
2367  {
2368  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2369  p_HasNotCF_Lift(p,strat->S[i],currRing))
2370  {
2371  /*
2372  *the product criterion has applied for (s,p),
2373  *i.e. lcm(s,p)=product of the leading terms of s and p.
2374  *Suppose (s,r) is in L and the leading term
2375  *of p divides lcm(s,r)
2376  *(==> the leading term of p divides the leading term of r)
2377  *but the leading term of s does not divide the leading term of r
2378  *(notice that tis condition is automatically satisfied if r is still
2379  *in S), then (s,r) can be canceled.
2380  *This should be done here because the
2381  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2382  */
2383  strat->cp++;
2384  pLmFree(Lp.lcm);
2385  return;
2386  }
2387  if (strat->fromT && (strat->ecartS[i]>ecart))
2388  {
2389  pLmFree(Lp.lcm);
2390  return;
2391  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2392  }
2393  /*
2394  *the set B collects the pairs of type (S[j],p)
2395  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2396  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2397  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2398  */
2399  for(j = strat->Bl;j>=0;j--)
2400  {
2401  compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2402  if (compare==1)
2403  {
2404  strat->c3++;
2405  if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2406  {
2407  pLmFree(Lp.lcm);
2408  return;
2409  }
2410  break;
2411  }
2412  else
2413  if (compare ==-1)
2414  {
2415  deleteInL(strat->B,&strat->Bl,j,strat);
2416  strat->c3++;
2417  }
2418  }
2419  }
2420  /*
2421  *the pair (S[i],p) enters B if the spoly != 0
2422  */
2423  /*- compute the short s-polynomial -*/
2424  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2425  pNorm(p);
2426 
2427  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2428  Lp.p=NULL;
2429  else
2430  {
2432  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2433  }
2434  if (Lp.p == NULL)
2435  {
2436  /*- the case that the s-poly is 0 -*/
2437  if (strat->pairtest==NULL) initPairtest(strat);
2438  strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2439  strat->pairtest[strat->sl+1] = TRUE;
2440  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2441  /*
2442  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2443  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2444  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2445  *term of p divides the lcm(s,r)
2446  *(this canceling should be done here because
2447  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2448  *the first case is handeled in chainCrit
2449  */
2450  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2451  }
2452  else
2453  {
2454  /*- the pair (S[i],p) enters B -*/
2455  Lp.p1 = strat->S[i];
2456  Lp.p2 = p;
2457 
2458  pNext(Lp.p) = strat->tail; // !!!
2459 
2460  if (atR >= 0)
2461  {
2462  Lp.i_r1 = strat->S_2_R[i];
2463  Lp.i_r2 = atR;
2464  }
2465  else
2466  {
2467  Lp.i_r1 = -1;
2468  Lp.i_r2 = -1;
2469  }
2470  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2471 
2473  {
2474  if (!rIsPluralRing(currRing)
2476  && (Lp.p->coef!=NULL))
2477  nDelete(&(Lp.p->coef));
2478  }
2479 
2480  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2481  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2482  }
2483 }
2484 
2485 /*2
2486 * put the pair (s[i],p) into the set B, ecart=ecart(p)
2487 * NOTE: here we need to add the signature-based criteria
2488 */
2489 
2490 #ifdef DEBUGF5
2491 static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2492 #else
2493 static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2494 #endif
2495 {
2496  assume(i<=strat->sl);
2497 
2498  int l;
2499  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2500  // the corresponding signatures for criteria checks
2501  LObject Lp;
2502  poly pSigMult = p_Copy(pSig,currRing);
2503  poly sSigMult = p_Copy(strat->sig[i],currRing);
2504  unsigned long pSigMultNegSev,sSigMultNegSev;
2505  Lp.i_r = -1;
2506 
2507 #ifdef KDEBUG
2508  Lp.ecart=0; Lp.length=0;
2509 #endif
2510  /*- computes the lcm(s[i],p) -*/
2511  Lp.lcm = pInit();
2512  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2513 #ifndef HAVE_RATGRING
2514  pLcm(p,strat->S[i],Lp.lcm);
2515 #elif defined(HAVE_RATGRING)
2516  if (rIsRatGRing(currRing))
2517  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2518  else
2519  pLcm(p,strat->S[i],Lp.lcm);
2520 #endif
2521  pSetm(Lp.lcm);
2522 
2523  // set coeffs of multipliers m1 and m2
2524  pSetCoeff0(m1, nInit(1));
2525  pSetCoeff0(m2, nInit(1));
2526 //#if 1
2527 #ifdef DEBUGF5
2528  PrintS("P1 ");
2529  pWrite(pHead(p));
2530  PrintS("P2 ");
2531  pWrite(pHead(strat->S[i]));
2532  PrintS("M1 ");
2533  pWrite(m1);
2534  PrintS("M2 ");
2535  pWrite(m2);
2536 #endif
2537  // get multiplied signatures for testing
2538  pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2539  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2540  sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2541  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2542 
2543 //#if 1
2544 #ifdef DEBUGF5
2545  PrintS("----------------\n");
2546  pWrite(pSigMult);
2547  pWrite(sSigMult);
2548  PrintS("----------------\n");
2549  Lp.checked = 0;
2550 #endif
2551  int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2552 //#if 1
2553 #if DEBUGF5
2554  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2555  pWrite(pSigMult);
2556  pWrite(sSigMult);
2557 #endif
2558  if(sigCmp==0)
2559  {
2560  // printf("!!!! EQUAL SIGS !!!!\n");
2561  // pSig = sSig, delete element due to Rewritten Criterion
2562  pDelete(&pSigMult);
2563  pDelete(&sSigMult);
2564  if (rField_is_Ring(currRing))
2565  pLmDelete(Lp.lcm);
2566  else
2567  pLmFree(Lp.lcm);
2568  pDelete (&m1);
2569  pDelete (&m2);
2570  return;
2571  }
2572  // testing by syzCrit = F5 Criterion
2573  // testing by rewCrit1 = Rewritten Criterion
2574  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2575  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2576  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2577  || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2578  )
2579  {
2580  pDelete(&pSigMult);
2581  pDelete(&sSigMult);
2582  if (rField_is_Ring(currRing))
2583  pLmDelete(Lp.lcm);
2584  else
2585  pLmFree(Lp.lcm);
2586  pDelete (&m1);
2587  pDelete (&m2);
2588  return;
2589  }
2590  /*
2591  *the pair (S[i],p) enters B if the spoly != 0
2592  */
2593  /*- compute the short s-polynomial -*/
2594  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2595  pNorm(p);
2596 
2597  if ((strat->S[i]==NULL) || (p==NULL))
2598  return;
2599 
2600  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2601  Lp.p=NULL;
2602  else
2603  {
2604  #ifdef HAVE_PLURAL
2605  if ( rIsPluralRing(currRing) )
2606  {
2607  if(pHasNotCF(p, strat->S[i]))
2608  {
2609  if(ncRingType(currRing) == nc_lie)
2610  {
2611  // generalized prod-crit for lie-type
2612  strat->cp++;
2613  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2614  }
2615  else
2616  if( ALLOW_PROD_CRIT(strat) )
2617  {
2618  // product criterion for homogeneous case in SCA
2619  strat->cp++;
2620  Lp.p = NULL;
2621  }
2622  else
2623  {
2624  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2625  nc_CreateShortSpoly(strat->S[i], p, currRing);
2626 
2627  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2628  pNext(Lp.p) = strat->tail; // !!!
2629  }
2630  }
2631  else
2632  {
2633  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2634  nc_CreateShortSpoly(strat->S[i], p, currRing);
2635 
2636  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2637  pNext(Lp.p) = strat->tail; // !!!
2638  }
2639  }
2640  else
2641  #endif
2642  {
2644  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2645  }
2646  }
2647  // store from which element this pair comes from for further tests
2648  //Lp.from = strat->sl+1;
2649  if(sigCmp==currRing->OrdSgn)
2650  {
2651  // pSig > sSig
2652  pDelete (&sSigMult);
2653  Lp.sig = pSigMult;
2654  Lp.sevSig = ~pSigMultNegSev;
2655  }
2656  else
2657  {
2658  // pSig < sSig
2659  pDelete (&pSigMult);
2660  Lp.sig = sSigMult;
2661  Lp.sevSig = ~sSigMultNegSev;
2662  }
2663  if (Lp.p == NULL)
2664  {
2665  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2666  int pos = posInSyz(strat, Lp.sig);
2667  enterSyz(Lp, strat, pos);
2668  }
2669  else
2670  {
2671  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2672  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2673  {
2674  pLmFree(Lp.lcm);
2675  pDelete(&Lp.sig);
2676  pDelete (&m1);
2677  pDelete (&m2);
2678  return;
2679  }
2680  // in any case Lp is checked up to the next strat->P which is added
2681  // to S right after this critical pair creation.
2682  // NOTE: this even holds if the 2nd generator gives the bigger signature
2683  // moreover, this improves rewCriterion,
2684  // i.e. strat->checked > strat->from if and only if the 2nd generator
2685  // gives the bigger signature.
2686  Lp.checked = strat->sl+1;
2687  // at this point it is clear that the pair will be added to L, since it has
2688  // passed all tests up to now
2689 
2690  // adds buchberger's first criterion
2691  if (pLmCmp(m2,pHead(p)) == 0)
2692  {
2693  Lp.prod_crit = TRUE; // Product Criterion
2694 #if 0
2695  int pos = posInSyz(strat, Lp.sig);
2696  enterSyz(Lp, strat, pos);
2697  pDelete (&m1);
2698  pDelete (&m2);
2699  return;
2700 #endif
2701  }
2702  pDelete (&m1);
2703  pDelete (&m2);
2704 #if DEBUGF5
2705  PrintS("SIGNATURE OF PAIR: ");
2706  pWrite(Lp.sig);
2707 #endif
2708  /*- the pair (S[i],p) enters B -*/
2709  Lp.p1 = strat->S[i];
2710  Lp.p2 = p;
2711 
2712  if (
2714 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2715  )
2716  {
2717  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2718  pNext(Lp.p) = strat->tail; // !!!
2719  }
2720 
2721  if (atR >= 0)
2722  {
2723  Lp.i_r1 = strat->S_2_R[i];
2724  Lp.i_r2 = atR;
2725  }
2726  else
2727  {
2728  Lp.i_r1 = -1;
2729  Lp.i_r2 = -1;
2730  }
2731  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2732 
2734  {
2735  if (!rIsPluralRing(currRing)
2737  && (Lp.p->coef!=NULL))
2738  nDelete(&(Lp.p->coef));
2739  }
2740 
2741  l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2742  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2743  }
2744 }
2745 
2746 
2747 #ifdef DEBUGF5
2748 static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2749 #else
2750 static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2751 #endif
2752 {
2753  #if ALL_VS_JUST
2754  //Over rings, if we construct the strong pair, do not add the spair
2756  {
2757  number s,t,d;
2758  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2759 
2760  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2761  {
2762  nDelete(&d);
2763  nDelete(&s);
2764  nDelete(&t);
2765  return;
2766  }
2767  nDelete(&d);
2768  nDelete(&s);
2769  nDelete(&t);
2770  }
2771  #endif
2772  assume(i<=strat->sl);
2773  int l;
2774  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2775  // the corresponding signatures for criteria checks
2776  LObject Lp;
2777  poly pSigMult = p_Copy(pSig,currRing);
2778  poly sSigMult = p_Copy(strat->sig[i],currRing);
2779  unsigned long pSigMultNegSev,sSigMultNegSev;
2780  Lp.i_r = -1;
2781 
2782 #ifdef KDEBUG
2783  Lp.ecart=0; Lp.length=0;
2784 #endif
2785  /*- computes the lcm(s[i],p) -*/
2786  Lp.lcm = pInit();
2787  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2788 #ifndef HAVE_RATGRING
2789  pLcm(p,strat->S[i],Lp.lcm);
2790 #elif defined(HAVE_RATGRING)
2791  if (rIsRatGRing(currRing))
2792  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2793  else
2794  pLcm(p,strat->S[i],Lp.lcm);
2795 #endif
2796  pSetm(Lp.lcm);
2797 
2798  // set coeffs of multipliers m1 and m2
2800  {
2801  number s = nCopy(pGetCoeff(strat->S[i]));
2802  number t = nCopy(pGetCoeff(p));
2803  pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2804  ksCheckCoeff(&s, &t, currRing->cf);
2805  pSetCoeff0(m1,s);
2806  pSetCoeff0(m2,t);
2807  }
2808  else
2809  {
2810  pSetCoeff0(m1, nInit(1));
2811  pSetCoeff0(m2, nInit(1));
2812  }
2813 #ifdef DEBUGF5
2814  Print("P1 ");
2815  pWrite(pHead(p));
2816  Print("P2 ");
2817  pWrite(pHead(strat->S[i]));
2818  Print("M1 ");
2819  pWrite(m1);
2820  Print("M2 ");
2821  pWrite(m2);
2822 #endif
2823 
2824  // get multiplied signatures for testing
2825  pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2826  if(pSigMult != NULL)
2827  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2828  sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2829  if(sSigMult != NULL)
2830  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2831 //#if 1
2832 #ifdef DEBUGF5
2833  Print("----------------\n");
2834  pWrite(pSigMult);
2835  pWrite(sSigMult);
2836  Print("----------------\n");
2837  Lp.checked = 0;
2838 #endif
2839  int sigCmp;
2840  if(pSigMult != NULL && sSigMult != NULL)
2841  {
2843  sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2844  else
2845  sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2846  }
2847  else
2848  {
2849  if(pSigMult == NULL)
2850  {
2851  if(sSigMult == NULL)
2852  sigCmp = 0;
2853  else
2854  sigCmp = -1;
2855  }
2856  else
2857  sigCmp = 1;
2858  }
2859 //#if 1
2860 #if DEBUGF5
2861  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2862  pWrite(pSigMult);
2863  pWrite(sSigMult);
2864 #endif
2865  //In the ring case we already build the sig
2867  {
2868  if(sigCmp == 0)
2869  {
2870  //sigdrop since we loose the signature
2871  strat->sigdrop = TRUE;
2872  //Try to reduce it as far as we can via redRing
2874  {
2875  poly p1 = p_Copy(p,currRing);
2876  poly p2 = p_Copy(strat->S[i],currRing);
2877  p1 = p_Mult_mm(p1,m1,currRing);
2878  p2 = p_Mult_mm(p2,m2,currRing);
2879  Lp.p = p_Sub(p1,p2,currRing);
2880  if(Lp.p != NULL)
2881  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2882  }
2883  int red_result = redRing(&Lp,strat);
2884  if(red_result == 0)
2885  {
2886  // Cancel the sigdrop
2887  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2888  strat->sigdrop = FALSE;
2889  return;
2890  }
2891  else
2892  {
2893  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2894  #if 1
2895  strat->enterS(Lp,0,strat,strat->tl);
2896  #endif
2897  return;
2898  }
2899  }
2900  if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2901  {
2902  //Same lm, have to substract
2903  Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2904  }
2905  else
2906  {
2907  if(sigCmp == 1)
2908  {
2909  Lp.sig = pCopy(pSigMult);
2910  }
2911  if(sigCmp == -1)
2912  {
2913  Lp.sig = pNeg(pCopy(sSigMult));
2914  }
2915  }
2916  Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2917  }
2918 
2919  #if 0
2920  if(sigCmp==0)
2921  {
2922  // printf("!!!! EQUAL SIGS !!!!\n");
2923  // pSig = sSig, delete element due to Rewritten Criterion
2924  pDelete(&pSigMult);
2925  pDelete(&sSigMult);
2926  if (rField_is_Ring(currRing))
2927  pLmDelete(Lp.lcm);
2928  else
2929  pLmFree(Lp.lcm);
2930  pDelete (&m1);
2931  pDelete (&m2);
2932  return;
2933  }
2934  #endif
2935  // testing by syzCrit = F5 Criterion
2936  // testing by rewCrit1 = Rewritten Criterion
2937  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2938  if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2939  strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2940  // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2941  //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2942  )
2943  {
2944  pDelete(&pSigMult);
2945  pDelete(&sSigMult);
2946  if (rField_is_Ring(currRing))
2947  pLmDelete(Lp.lcm);
2948  else
2949  pLmFree(Lp.lcm);
2950  pDelete (&m1);
2951  pDelete (&m2);
2952  return;
2953  }
2954  /*
2955  *the pair (S[i],p) enters B if the spoly != 0
2956  */
2957  /*- compute the short s-polynomial -*/
2958  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2959  pNorm(p);
2960 
2961  if ((strat->S[i]==NULL) || (p==NULL))
2962  return;
2963 
2964  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2965  Lp.p=NULL;
2966  else
2967  {
2968  //Build p
2970  {
2971  poly p1 = p_Copy(p,currRing);
2972  poly p2 = p_Copy(strat->S[i],currRing);
2973  p1 = p_Mult_mm(p1,m1,currRing);
2974  p2 = p_Mult_mm(p2,m2,currRing);
2975  Lp.p = p_Sub(p1,p2,currRing);
2976  if(Lp.p != NULL)
2977  Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2978  }
2979  else
2980  {
2981  #ifdef HAVE_PLURAL
2982  if ( rIsPluralRing(currRing) )
2983  {
2984  if(ncRingType(currRing) == nc_lie)
2985  {
2986  // generalized prod-crit for lie-type
2987  strat->cp++;
2988  Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2989  }
2990  else
2991  if( ALLOW_PROD_CRIT(strat) )
2992  {
2993  // product criterion for homogeneous case in SCA
2994  strat->cp++;
2995  Lp.p = NULL;
2996  }
2997  else
2998  {
2999  Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
3000  nc_CreateShortSpoly(strat->S[i], p, currRing);
3001 
3002  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3003  pNext(Lp.p) = strat->tail; // !!!
3004  }
3005  }
3006  else
3007  #endif
3008  {
3010  Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
3011  }
3012  }
3013  }
3014  // store from which element this pair comes from for further tests
3015  //Lp.from = strat->sl+1;
3017  {
3018  //Put the sig to be > 0
3019  if(!nGreaterZero(pGetCoeff(Lp.sig)))
3020  {
3021  Lp.sig = pNeg(Lp.sig);
3022  Lp.p = pNeg(Lp.p);
3023  }
3024  }
3025  else
3026  {
3027  if(sigCmp==currRing->OrdSgn)
3028  {
3029  // pSig > sSig
3030  pDelete (&sSigMult);
3031  Lp.sig = pSigMult;
3032  Lp.sevSig = ~pSigMultNegSev;
3033  }
3034  else
3035  {
3036  // pSig < sSig
3037  pDelete (&pSigMult);
3038  Lp.sig = sSigMult;
3039  Lp.sevSig = ~sSigMultNegSev;
3040  }
3041  }
3042  if (Lp.p == NULL)
3043  {
3044  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
3045  int pos = posInSyz(strat, Lp.sig);
3046  enterSyz(Lp, strat, pos);
3047  }
3048  else
3049  {
3050  // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
3051  if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
3052  {
3053  pLmFree(Lp.lcm);
3054  pDelete(&Lp.sig);
3055  pDelete (&m1);
3056  pDelete (&m2);
3057  return;
3058  }
3059  // in any case Lp is checked up to the next strat->P which is added
3060  // to S right after this critical pair creation.
3061  // NOTE: this even holds if the 2nd generator gives the bigger signature
3062  // moreover, this improves rewCriterion,
3063  // i.e. strat->checked > strat->from if and only if the 2nd generator
3064  // gives the bigger signature.
3065  Lp.checked = strat->sl+1;
3066  // at this point it is clear that the pair will be added to L, since it has
3067  // passed all tests up to now
3068 
3069  // adds buchberger's first criterion
3070  if (pLmCmp(m2,pHead(p)) == 0)
3071  {
3072  Lp.prod_crit = TRUE; // Product Criterion
3073 #if 0
3074  int pos = posInSyz(strat, Lp.sig);
3075  enterSyz(Lp, strat, pos);
3076  pDelete (&m1);
3077  pDelete (&m2);
3078  return;
3079 #endif
3080  }
3081  pDelete (&m1);
3082  pDelete (&m2);
3083 #if DEBUGF5
3084  PrintS("SIGNATURE OF PAIR: ");
3085  pWrite(Lp.sig);
3086 #endif
3087  /*- the pair (S[i],p) enters B -*/
3088  Lp.p1 = strat->S[i];
3089  Lp.p2 = p;
3090 
3091  if (
3093 // || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3095  )
3096  {
3097  assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3098  pNext(Lp.p) = strat->tail; // !!!
3099  }
3100 
3101  if (atR >= 0)
3102  {
3103  Lp.i_r1 = strat->S_2_R[i];
3104  Lp.i_r2 = atR;
3105  }
3106  else
3107  {
3108  Lp.i_r1 = -1;
3109  Lp.i_r2 = -1;
3110  }
3111  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3112 
3114  {
3115  if (!rIsPluralRing(currRing)
3117  && (Lp.p->coef!=NULL))
3118  nDelete(&(Lp.p->coef));
3119  }
3120  // Check for sigdrop
3121  if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3122  {
3123  strat->sigdrop = TRUE;
3124  // Completely reduce it
3125  int red_result = redRing(&Lp,strat);
3126  if(red_result == 0)
3127  {
3128  // Reduced to 0
3129  strat->sigdrop = FALSE;
3130  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3131  return;
3132  }
3133  else
3134  {
3135  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3136  // 0 - add just the original poly causing the sigdrop, 1 - add also this
3137  #if 1
3138  strat->enterS(Lp,0,strat, strat->tl+1);
3139  #endif
3140  return;
3141  }
3142  }
3143  l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3144  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3145  }
3146 }
3147 
3148 /*2
3149 * put the pair (s[i],p) into the set L, ecart=ecart(p)
3150 * in the case that s forms a SB of (s)
3151 */
3152 void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3153 {
3154  //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3155  if(pHasNotCF(p,strat->S[i]))
3156  {
3157  //PrintS("prod-crit\n");
3158  if(ALLOW_PROD_CRIT(strat))
3159  {
3160  //PrintS("prod-crit\n");
3161  strat->cp++;
3162  return;
3163  }
3164  }
3165 
3166  int l;
3167  LObject Lp;
3168  Lp.i_r = -1;
3169 
3170  Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3171  /*- compute the short s-polynomial -*/
3172 
3173  #ifdef HAVE_PLURAL
3174  if (rIsPluralRing(currRing))
3175  {
3176  Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3177  }
3178  else
3179  #endif
3180  Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3181 
3182  if (Lp.p == NULL)
3183  {
3184  //PrintS("short spoly==NULL\n");
3185  pLmFree(Lp.lcm);
3186  }
3187  else
3188  {
3189  /*- the pair (S[i],p) enters L -*/
3190  Lp.p1 = strat->S[i];
3191  Lp.p2 = p;
3192  if (atR >= 0)
3193  {
3194  Lp.i_r1 = strat->S_2_R[i];
3195  Lp.i_r2 = atR;
3196  }
3197  else
3198  {
3199  Lp.i_r1 = -1;
3200  Lp.i_r2 = -1;
3201  }
3202  assume(pNext(Lp.p) == NULL);
3203  pNext(Lp.p) = strat->tail;
3204  strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3206  {
3207  if (!rIsPluralRing(currRing)
3209  && (Lp.p->coef!=NULL))
3210  nDelete(&(Lp.p->coef));
3211  }
3212  l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3213  //Print("-> L[%d]\n",l);
3214  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3215  }
3216 }
3217 
3218 /*2
3219 * merge set B into L
3220 */
3222 {
3223  int j=strat->Ll+strat->Bl+1;
3224  if (j>strat->Lmax)
3225  {
3226  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3227  enlargeL(&(strat->L),&(strat->Lmax),j);
3228  }
3229  j = strat->Ll;
3230  int i;
3231  for (i=strat->Bl; i>=0; i--)
3232  {
3233  j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3234  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3235  }
3236  strat->Bl = -1;
3237 }
3238 
3239 /*2
3240 * merge set B into L
3241 */
3243 {
3244  int j=strat->Ll+strat->Bl+1;
3245  if (j>strat->Lmax)
3246  {
3247  j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3248  enlargeL(&(strat->L),&(strat->Lmax),j);
3249  }
3250  j = strat->Ll;
3251  int i;
3252  for (i=strat->Bl; i>=0; i--)
3253  {
3254  j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3255  enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3256  }
3257  strat->Bl = -1;
3258 }
3259 
3260 /*2
3261 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3262 *using the chain-criterion in B and L and enters B to L
3263 */
3264 void chainCritNormal (poly p,int ecart,kStrategy strat)
3265 {
3266  int i,j,l;
3267 
3268  /*
3269  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3270  *In this case all elements in B such
3271  *that their lcm is divisible by the leading term of S[i] can be canceled
3272  */
3273  if (strat->pairtest!=NULL)
3274  {
3275 #ifdef HAVE_SHIFTBBA
3276  // only difference is pLPDivisibleBy instead of pDivisibleBy
3277  if (rIsLPRing(currRing))
3278  {
3279  for (j=0; j<=strat->sl; j++)
3280  {
3281  if (strat->pairtest[j])
3282  {
3283  for (i=strat->Bl; i>=0; i--)
3284  {
3285  if (pLPDivisibleBy(strat->S[j],strat->B[i].lcm))
3286  {
3287  deleteInL(strat->B,&strat->Bl,i,strat);
3288  strat->c3++;
3289  }
3290  }
3291  }
3292  }
3293  }
3294  else
3295 #endif
3296  {
3297  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3298  for (j=0; j<=strat->sl; j++)
3299  {
3300  if (strat->pairtest[j])
3301  {
3302  for (i=strat->Bl; i>=0; i--)
3303  {
3304  if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3305  {
3306  deleteInL(strat->B,&strat->Bl,i,strat);
3307  strat->c3++;
3308  }
3309  }
3310  }
3311  }
3312  }
3313  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3314  strat->pairtest=NULL;
3315  }
3316  if (strat->Gebauer || strat->fromT)
3317  {
3318  if (strat->sugarCrit)
3319  {
3320  /*
3321  *suppose L[j] == (s,r) and p/lcm(s,r)
3322  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3323  *and in case the sugar is o.k. then L[j] can be canceled
3324  */
3325  for (j=strat->Ll; j>=0; j--)
3326  {
3327  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3328  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3329  && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3330  {
3331  if (strat->L[j].p == strat->tail)
3332  {
3333  deleteInL(strat->L,&strat->Ll,j,strat);
3334  strat->c3++;
3335  }
3336  }
3337  }
3338  /*
3339  *this is GEBAUER-MOELLER:
3340  *in B all elements with the same lcm except the "best"
3341  *(i.e. the last one in B with this property) will be canceled
3342  */
3343  j = strat->Bl;
3344  loop /*cannot be changed into a for !!! */
3345  {
3346  if (j <= 0) break;
3347  i = j-1;
3348  loop
3349  {
3350  if (i < 0) break;
3351  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3352  {
3353  strat->c3++;
3354  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3355  {
3356  deleteInL(strat->B,&strat->Bl,i,strat);
3357  j--;
3358  }
3359  else
3360  {
3361  deleteInL(strat->B,&strat->Bl,j,strat);
3362  break;
3363  }
3364  }
3365  i--;
3366  }
3367  j--;
3368  }
3369  }
3370  else /*sugarCrit*/
3371  {
3372  /*
3373  *suppose L[j] == (s,r) and p/lcm(s,r)
3374  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3375  *and in case the sugar is o.k. then L[j] can be canceled
3376  */
3377  for (j=strat->Ll; j>=0; j--)
3378  {
3379  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3380  {
3381  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3382  {
3383  deleteInL(strat->L,&strat->Ll,j,strat);
3384  strat->c3++;
3385  }
3386  }
3387  }
3388  /*
3389  *this is GEBAUER-MOELLER:
3390  *in B all elements with the same lcm except the "best"
3391  *(i.e. the last one in B with this property) will be canceled
3392  */
3393  j = strat->Bl;
3394  loop /*cannot be changed into a for !!! */
3395  {
3396  if (j <= 0) break;
3397  for(i=j-1; i>=0; i--)
3398  {
3399  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3400  {
3401  strat->c3++;
3402  deleteInL(strat->B,&strat->Bl,i,strat);
3403  j--;
3404  }
3405  }
3406  j--;
3407  }
3408  }
3409  /*
3410  *the elements of B enter L
3411  */
3412  kMergeBintoL(strat);
3413  }
3414  else
3415  {
3416  for (j=strat->Ll; j>=0; j--)
3417  {
3418  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3419  {
3420  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3421  {
3422  deleteInL(strat->L,&strat->Ll,j,strat);
3423  strat->c3++;
3424  }
3425  }
3426  }
3427  /*
3428  *this is our MODIFICATION of GEBAUER-MOELLER:
3429  *First the elements of B enter L,
3430  *then we fix a lcm and the "best" element in L
3431  *(i.e the last in L with this lcm and of type (s,p))
3432  *and cancel all the other elements of type (r,p) with this lcm
3433  *except the case the element (s,r) has also the same lcm
3434  *and is on the worst position with respect to (s,p) and (r,p)
3435  */
3436  /*
3437  *B enters to L/their order with respect to B is permutated for elements
3438  *B[i].p with the same leading term
3439  */
3440  kMergeBintoL(strat);
3441  j = strat->Ll;
3442  loop /*cannot be changed into a for !!! */
3443  {
3444  if (j <= 0)
3445  {
3446  /*now L[0] cannot be canceled any more and the tail can be removed*/
3447  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3448  break;
3449  }
3450  if (strat->L[j].p2 == p)
3451  {
3452  i = j-1;
3453  loop
3454  {
3455  if (i < 0) break;
3456  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3457  {
3458  /*L[i] could be canceled but we search for a better one to cancel*/
3459  strat->c3++;
3460  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3461  && (pNext(strat->L[l].p) == strat->tail)
3462  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3463  && pDivisibleBy(p,strat->L[l].lcm))
3464  {
3465  /*
3466  *"NOT equal(...)" because in case of "equal" the element L[l]
3467  *is "older" and has to be from theoretical point of view behind
3468  *L[i], but we do not want to reorder L
3469  */
3470  strat->L[i].p2 = strat->tail;
3471  /*
3472  *L[l] will be canceled, we cannot cancel L[i] later on,
3473  *so we mark it with "tail"
3474  */
3475  deleteInL(strat->L,&strat->Ll,l,strat);
3476  i--;
3477  }
3478  else
3479  {
3480  deleteInL(strat->L,&strat->Ll,i,strat);
3481  }
3482  j--;
3483  }
3484  i--;
3485  }
3486  }
3487  else if (strat->L[j].p2 == strat->tail)
3488  {
3489  /*now L[j] cannot be canceled any more and the tail can be removed*/
3490  strat->L[j].p2 = p;
3491  }
3492  j--;
3493  }
3494  }
3495 }
3496 /*2
3497 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3498 *without the chain-criterion in B and L and enters B to L
3499 */
3500 void chainCritOpt_1 (poly,int,kStrategy strat)
3501 {
3502  if (strat->pairtest!=NULL)
3503  {
3504  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3505  strat->pairtest=NULL;
3506  }
3507  /*
3508  *the elements of B enter L
3509  */
3510  kMergeBintoL(strat);
3511 }
3512 /*2
3513 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3514 *using the chain-criterion in B and L and enters B to L
3515 */
3516 void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3517 {
3518  int i,j,l;
3519  kMergeBintoLSba(strat);
3520  j = strat->Ll;
3521  loop /*cannot be changed into a for !!! */
3522  {
3523  if (j <= 0)
3524  {
3525  /*now L[0] cannot be canceled any more and the tail can be removed*/
3526  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3527  break;
3528  }
3529  if (strat->L[j].p2 == p)
3530  {
3531  i = j-1;
3532  loop
3533  {
3534  if (i < 0) break;
3535  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3536  {
3537  /*L[i] could be canceled but we search for a better one to cancel*/
3538  strat->c3++;
3539  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3540  && (pNext(strat->L[l].p) == strat->tail)
3541  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3542  && pDivisibleBy(p,strat->L[l].lcm))
3543  {
3544  /*
3545  *"NOT equal(...)" because in case of "equal" the element L[l]
3546  *is "older" and has to be from theoretical point of view behind
3547  *L[i], but we do not want to reorder L
3548  */
3549  strat->L[i].p2 = strat->tail;
3550  /*
3551  *L[l] will be canceled, we cannot cancel L[i] later on,
3552  *so we mark it with "tail"
3553  */
3554  deleteInL(strat->L,&strat->Ll,l,strat);
3555  i--;
3556  }
3557  else
3558  {
3559  deleteInL(strat->L,&strat->Ll,i,strat);
3560  }
3561  j--;
3562  }
3563  i--;
3564  }
3565  }
3566  else if (strat->L[j].p2 == strat->tail)
3567  {
3568  /*now L[j] cannot be canceled any more and the tail can be removed*/
3569  strat->L[j].p2 = p;
3570  }
3571  j--;
3572  }
3573 }
3574 #ifdef HAVE_RATGRING
3575 void chainCritPart (poly p,int ecart,kStrategy strat)
3576 {
3577  int i,j,l;
3578 
3579  /*
3580  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3581  *In this case all elements in B such
3582  *that their lcm is divisible by the leading term of S[i] can be canceled
3583  */
3584  if (strat->pairtest!=NULL)
3585  {
3586  /*- i.e. there is an i with pairtest[i]==TRUE -*/
3587  for (j=0; j<=strat->sl; j++)
3588  {
3589  if (strat->pairtest[j])
3590  {
3591  for (i=strat->Bl; i>=0; i--)
3592  {
3593  if (_p_LmDivisibleByPart(strat->S[j],currRing,
3594  strat->B[i].lcm,currRing,
3595  currRing->real_var_start,currRing->real_var_end))
3596  {
3597  if(TEST_OPT_DEBUG)
3598  {
3599  Print("chain-crit-part: S[%d]=",j);
3600  p_wrp(strat->S[j],currRing);
3601  Print(" divide B[%d].lcm=",i);
3602  p_wrp(strat->B[i].lcm,currRing);
3603  PrintLn();
3604  }
3605  deleteInL(strat->B,&strat->Bl,i,strat);
3606  strat->c3++;
3607  }
3608  }
3609  }
3610  }
3611  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3612  strat->pairtest=NULL;
3613  }
3614  if (strat->Gebauer || strat->fromT)
3615  {
3616  if (strat->sugarCrit)
3617  {
3618  /*
3619  *suppose L[j] == (s,r) and p/lcm(s,r)
3620  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3621  *and in case the sugar is o.k. then L[j] can be canceled
3622  */
3623  for (j=strat->Ll; j>=0; j--)
3624  {
3625  if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3626  && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3627  && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3628  {
3629  if (strat->L[j].p == strat->tail)
3630  {
3631  if(TEST_OPT_DEBUG)
3632  {
3633  PrintS("chain-crit-part: pCompareChainPart p=");
3634  p_wrp(p,currRing);
3635  Print(" delete L[%d]",j);
3636  p_wrp(strat->L[j].lcm,currRing);
3637  PrintLn();
3638  }
3639  deleteInL(strat->L,&strat->Ll,j,strat);
3640  strat->c3++;
3641  }
3642  }
3643  }
3644  /*
3645  *this is GEBAUER-MOELLER:
3646  *in B all elements with the same lcm except the "best"
3647  *(i.e. the last one in B with this property) will be canceled
3648  */
3649  j = strat->Bl;
3650  loop /*cannot be changed into a for !!! */
3651  {
3652  if (j <= 0) break;
3653  i = j-1;
3654  loop
3655  {
3656  if (i < 0) break;
3657  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3658  {
3659  strat->c3++;
3660  if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3661  {
3662  if(TEST_OPT_DEBUG)
3663  {
3664  Print("chain-crit-part: sugar B[%d].lcm=",j);
3665  p_wrp(strat->B[j].lcm,currRing);
3666  Print(" delete B[%d]",i);
3667  p_wrp(strat->B[i].lcm,currRing);
3668  PrintLn();
3669  }
3670  deleteInL(strat->B,&strat->Bl,i,strat);
3671  j--;
3672  }
3673  else
3674  {
3675  if(TEST_OPT_DEBUG)
3676  {
3677  Print("chain-crit-part: sugar B[%d].lcm=",i);
3678  p_wrp(strat->B[i].lcm,currRing);
3679  Print(" delete B[%d]",j);
3680  p_wrp(strat->B[j].lcm,currRing);
3681  PrintLn();
3682  }
3683  deleteInL(strat->B,&strat->Bl,j,strat);
3684  break;
3685  }
3686  }
3687  i--;
3688  }
3689  j--;
3690  }
3691  }
3692  else /*sugarCrit*/
3693  {
3694  /*
3695  *suppose L[j] == (s,r) and p/lcm(s,r)
3696  *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3697  *and in case the sugar is o.k. then L[j] can be canceled
3698  */
3699  for (j=strat->Ll; j>=0; j--)
3700  {
3701  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3702  {
3703  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3704  {
3705  if(TEST_OPT_DEBUG)
3706  {
3707  PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3708  p_wrp(p,currRing);
3709  Print(" delete L[%d]",j);
3710  p_wrp(strat->L[j].lcm,currRing);
3711  PrintLn();
3712  }
3713  deleteInL(strat->L,&strat->Ll,j,strat);
3714  strat->c3++;
3715  }
3716  }
3717  }
3718  /*
3719  *this is GEBAUER-MOELLER:
3720  *in B all elements with the same lcm except the "best"
3721  *(i.e. the last one in B with this property) will be canceled
3722  */
3723  j = strat->Bl;
3724  loop /*cannot be changed into a for !!! */
3725  {
3726  if (j <= 0) break;
3727  for(i=j-1; i>=0; i--)
3728  {
3729  if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3730  {
3731  if(TEST_OPT_DEBUG)
3732  {
3733  Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3734  p_wrp(strat->B[j].lcm,currRing);
3735  Print(" delete B[%d]\n",i);
3736  }
3737  strat->c3++;
3738  deleteInL(strat->B,&strat->Bl,i,strat);
3739  j--;
3740  }
3741  }
3742  j--;
3743  }
3744  }
3745  /*
3746  *the elements of B enter L
3747  */
3748  kMergeBintoL(strat);
3749  }
3750  else
3751  {
3752  for (j=strat->Ll; j>=0; j--)
3753  {
3754  if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3755  {
3756  if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3757  {
3758  if(TEST_OPT_DEBUG)
3759  {
3760  PrintS("chain-crit-part: pCompareChainPart p=");
3761  p_wrp(p,currRing);
3762  Print(" delete L[%d]",j);
3763  p_wrp(strat->L[j].lcm,currRing);
3764  PrintLn();
3765  }
3766  deleteInL(strat->L,&strat->Ll,j,strat);
3767  strat->c3++;
3768  }
3769  }
3770  }
3771  /*
3772  *this is our MODIFICATION of GEBAUER-MOELLER:
3773  *First the elements of B enter L,
3774  *then we fix a lcm and the "best" element in L
3775  *(i.e the last in L with this lcm and of type (s,p))
3776  *and cancel all the other elements of type (r,p) with this lcm
3777  *except the case the element (s,r) has also the same lcm
3778  *and is on the worst position with respect to (s,p) and (r,p)
3779  */
3780  /*
3781  *B enters to L/their order with respect to B is permutated for elements
3782  *B[i].p with the same leading term
3783  */
3784  kMergeBintoL(strat);
3785  j = strat->Ll;
3786  loop /*cannot be changed into a for !!! */
3787  {
3788  if (j <= 0)
3789  {
3790  /*now L[0] cannot be canceled any more and the tail can be removed*/
3791  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3792  break;
3793  }
3794  if (strat->L[j].p2 == p)
3795  {
3796  i = j-1;
3797  loop
3798  {
3799  if (i < 0) break;
3800  if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3801  {
3802  /*L[i] could be canceled but we search for a better one to cancel*/
3803  strat->c3++;
3804  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3805  && (pNext(strat->L[l].p) == strat->tail)
3806  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3808  strat->L[l].lcm,currRing,
3809  currRing->real_var_start, currRing->real_var_end))
3810 
3811  {
3812  /*
3813  *"NOT equal(...)" because in case of "equal" the element L[l]
3814  *is "older" and has to be from theoretical point of view behind
3815  *L[i], but we do not want to reorder L
3816  */
3817  strat->L[i].p2 = strat->tail;
3818  /*
3819  *L[l] will be canceled, we cannot cancel L[i] later on,
3820  *so we mark it with "tail"
3821  */
3822  if(TEST_OPT_DEBUG)
3823  {
3824  PrintS("chain-crit-part: divisible_by p=");
3825  p_wrp(p,currRing);
3826  Print(" delete L[%d]",l);
3827  p_wrp(strat->L[l].lcm,currRing);
3828  PrintLn();
3829  }
3830  deleteInL(strat->L,&strat->Ll,l,strat);
3831  i--;
3832  }
3833  else
3834  {
3835  if(TEST_OPT_DEBUG)
3836  {
3837  PrintS("chain-crit-part: divisible_by(2) p=");
3838  p_wrp(p,currRing);
3839  Print(" delete L[%d]",i);
3840  p_wrp(strat->L[i].lcm,currRing);
3841  PrintLn();
3842  }
3843  deleteInL(strat->L,&strat->Ll,i,strat);
3844  }
3845  j--;
3846  }
3847  i--;
3848  }
3849  }
3850  else if (strat->L[j].p2 == strat->tail)
3851  {
3852  /*now L[j] cannot be canceled any more and the tail can be removed*/
3853  strat->L[j].p2 = p;
3854  }
3855  j--;
3856  }
3857  }
3858 }
3859 #endif
3860 
3861 /*2
3862 *(s[0],h),...,(s[k],h) will be put to the pairset L
3863 */
3864 void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR/* = -1*/)
3865 {
3866 
3867  if ((strat->syzComp==0)
3868  || (pGetComp(h)<=strat->syzComp))
3869  {
3870  int j;
3871  BOOLEAN new_pair=FALSE;
3872 
3873  if (pGetComp(h)==0)
3874  {
3875  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3876  if ((isFromQ)&&(strat->fromQ!=NULL))
3877  {
3878  for (j=0; j<=k; j++)
3879  {
3880  if (!strat->fromQ[j])
3881  {
3882  new_pair=TRUE;
3883  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3884  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3885  }
3886  }
3887  }
3888  else
3889  {
3890  new_pair=TRUE;
3891  for (j=0; j<=k; j++)
3892  {
3893  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3894  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3895  }
3896  }
3897  }
3898  else
3899  {
3900  for (j=0; j<=k; j++)
3901  {
3902  if ((pGetComp(h)==pGetComp(strat->S[j]))
3903  || (pGetComp(strat->S[j])==0))
3904  {
3905  new_pair=TRUE;
3906  strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3907  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3908  }
3909  }
3910  }
3911  if (new_pair)
3912  {
3913  #ifdef HAVE_RATGRING
3914  if (currRing->real_var_start>0)
3915  chainCritPart(h,ecart,strat);
3916  else
3917  #endif
3918  strat->chainCrit(h,ecart,strat);
3919  }
3920  kMergeBintoL(strat);
3921  }
3922 }
3923 
3924 /*2
3925 *(s[0],h),...,(s[k],h) will be put to the pairset L
3926 *using signatures <= only for signature-based standard basis algorithms
3927 */
3928 
3929 void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3930 {
3931 
3932  if ((strat->syzComp==0)
3933  || (pGetComp(h)<=strat->syzComp))
3934  {
3935  int j;
3936  BOOLEAN new_pair=FALSE;
3937 
3938  if (pGetComp(h)==0)
3939  {
3940  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3941  if ((isFromQ)&&(strat->fromQ!=NULL))
3942  {
3943  for (j=0; j<=k; j++)
3944  {
3945  if (!strat->fromQ[j])
3946  {
3947  new_pair=TRUE;
3948  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3949  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3950  }
3951  }
3952  }
3953  else
3954  {
3955  new_pair=TRUE;
3956  for (j=0; j<=k; j++)
3957  {
3958  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3959  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3960  }
3961  }
3962  }
3963  else
3964  {
3965  for (j=0; j<=k; j++)
3966  {
3967  if ((pGetComp(h)==pGetComp(strat->S[j]))
3968  || (pGetComp(strat->S[j])==0))
3969  {
3970  new_pair=TRUE;
3971  enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3972  //Print("j:%d, Ll:%d\n",j,strat->Ll);
3973  }
3974  }
3975  }
3976 
3977  if (new_pair)
3978  {
3979 #ifdef HAVE_RATGRING
3980  if (currRing->real_var_start>0)
3981  chainCritPart(h,ecart,strat);
3982  else
3983 #endif
3984  strat->chainCrit(h,ecart,strat);
3985  }
3986  }
3987 }
3988 
3989 void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3990 {
3991 
3992  if ((strat->syzComp==0)
3993  || (pGetComp(h)<=strat->syzComp))
3994  {
3995  int j;
3996 
3997  if (pGetComp(h)==0)
3998  {
3999  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4000  if ((isFromQ)&&(strat->fromQ!=NULL))
4001  {
4002  for (j=0; j<=k && !strat->sigdrop; j++)
4003  {
4004  if (!strat->fromQ[j])
4005  {
4006  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4007  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4008  }
4009  }
4010  }
4011  else
4012  {
4013  for (j=0; j<=k && !strat->sigdrop; j++)
4014  {
4015  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4016  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4017  }
4018  }
4019  }
4020  else
4021  {
4022  for (j=0; j<=k && !strat->sigdrop; j++)
4023  {
4024  if ((pGetComp(h)==pGetComp(strat->S[j]))
4025  || (pGetComp(strat->S[j])==0))
4026  {
4027  enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4028  //Print("j:%d, Ll:%d\n",j,strat->Ll);
4029  }
4030  }
4031  }
4032 
4033 #if 0
4034  if (new_pair)
4035  {
4036 #ifdef HAVE_RATGRING
4037  if (currRing->real_var_start>0)
4038  chainCritPart(h,ecart,strat);
4039  else
4040 #endif
4041  strat->chainCrit(h,ecart,strat);
4042  }
4043 #endif
4044  }
4045 }
4046 #ifdef HAVE_RINGS
4047 /*2
4048 *the pairset B of pairs of type (s[i],p) is complete now. It will be updated
4049 *using the chain-criterion in B and L and enters B to L
4050 */
4051 void chainCritRing (poly p,int, kStrategy strat)
4052 {
4053  int i,j,l;
4054  /*
4055  *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4056  *In this case all elements in B such
4057  *that their lcm is divisible by the leading term of S[i] can be canceled
4058  */
4059  if (strat->pairtest!=NULL)
4060  {
4061  {
4062  /*- i.e. there is an i with pairtest[i]==TRUE -*/
4063  for (j=0; j<=strat->sl; j++)
4064  {
4065  if (strat->pairtest[j])
4066  {
4067  for (i=strat->Bl; i>=0; i--)
4068  {
4069  if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4070  {
4071 #ifdef KDEBUG
4072  if (TEST_OPT_DEBUG)
4073  {
4074  PrintS("--- chain criterion func chainCritRing type 1\n");
4075  PrintS("strat->S[j]:");
4076  wrp(strat->S[j]);
4077  PrintS(" strat->B[i].lcm:");
4078  wrp(strat->B[i].lcm);PrintLn();
4079  pWrite(strat->B[i].p);
4080  pWrite(strat->B[i].p1);
4081  pWrite(strat->B[i].p2);
4082  wrp(strat->B[i].lcm);
4083  PrintLn();
4084  }
4085 #endif
4086  deleteInL(strat->B,&strat->Bl,i,strat);
4087  strat->c3++;
4088  }
4089  }
4090  }
4091  }
4092  }
4093  omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4094  strat->pairtest=NULL;
4095  }
4096  assume(!(strat->Gebauer || strat->fromT));
4097  for (j=strat->Ll; j>=0; j--)
4098  {
4099  if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4100  {
4101  if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4102  {
4103  if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4104  {
4105  deleteInL(strat->L,&strat->Ll,j,strat);
4106  strat->c3++;
4107 #ifdef KDEBUG
4108  if (TEST_OPT_DEBUG)
4109  {
4110  PrintS("--- chain criterion func chainCritRing type 2\n");
4111  PrintS("strat->L[j].p:");
4112  wrp(strat->L[j].p);
4113  PrintS(" p:");
4114  wrp(p);
4115  PrintLn();
4116  }
4117 #endif
4118  }
4119  }
4120  }
4121  }
4122  /*
4123  *this is our MODIFICATION of GEBAUER-MOELLER:
4124  *First the elements of B enter L,
4125  *then we fix a lcm and the "best" element in L
4126  *(i.e the last in L with this lcm and of type (s,p))
4127  *and cancel all the other elements of type (r,p) with this lcm
4128  *except the case the element (s,r) has also the same lcm
4129  *and is on the worst position with respect to (s,p) and (r,p)
4130  */
4131  /*
4132  *B enters to L/their order with respect to B is permutated for elements
4133  *B[i].p with the same leading term
4134  */
4135  kMergeBintoL(strat);
4136  j = strat->Ll;
4137  loop /*cannot be changed into a for !!! */
4138  {
4139  if (j <= 0)
4140  {
4141  /*now L[0] cannot be canceled any more and the tail can be removed*/
4142  if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4143  break;
4144  }
4145  if (strat->L[j].p2 == p) // Was the element added from B?
4146  {
4147  i = j-1;
4148  loop
4149  {
4150  if (i < 0) break;
4151  // Element is from B and has the same lcm as L[j]
4152  if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4153  && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4154  {
4155  /*L[i] could be canceled but we search for a better one to cancel*/
4156  strat->c3++;
4157 #ifdef KDEBUG
4158  if (TEST_OPT_DEBUG)
4159  {
4160  PrintS("--- chain criterion func chainCritRing type 3\n");
4161  PrintS("strat->L[j].lcm:");
4162  wrp(strat->L[j].lcm);
4163  PrintS(" strat->L[i].lcm:");
4164  wrp(strat->L[i].lcm);
4165  PrintLn();
4166  }
4167 #endif
4168  if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4169  && (pNext(strat->L[l].p) == strat->tail)
4170  && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4171  && pDivisibleBy(p,strat->L[l].lcm))
4172  {
4173  /*
4174  *"NOT equal(...)" because in case of "equal" the element L[l]
4175  *is "older" and has to be from theoretical point of view behind
4176  *L[i], but we do not want to reorder L
4177  */
4178  strat->L[i].p2 = strat->tail;
4179  /*
4180  *L[l] will be canceled, we cannot cancel L[i] later on,
4181  *so we mark it with "tail"
4182  */
4183  deleteInL(strat->L,&strat->Ll,l,strat);
4184  i--;
4185  }
4186  else
4187  {
4188  deleteInL(strat->L,&strat->Ll,i,strat);
4189  }
4190  j--;
4191  }
4192  i--;
4193  }
4194  }
4195  else if (strat->L[j].p2 == strat->tail)
4196  {
4197  /*now L[j] cannot be canceled any more and the tail can be removed*/
4198  strat->L[j].p2 = p;
4199  }
4200  j--;
4201  }
4202 }
4203 #endif
4204 
4205 #ifdef HAVE_RINGS
4206 /*2
4207 *(s[0],h),...,(s[k],h) will be put to the pairset L
4208 */
4209 void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4210 {
4211  if (!nIsOne(pGetCoeff(h)))
4212  {
4213  int j;
4214  BOOLEAN new_pair=FALSE;
4215 
4216  if (pGetComp(h)==0)
4217  {
4218  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4219  if ((isFromQ)&&(strat->fromQ!=NULL))
4220  {
4221  for (j=0; j<=k; j++)
4222  {
4223  if (!strat->fromQ[j])
4224  {
4225  new_pair=TRUE;
4226  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4227  }
4228  }
4229  }
4230  else
4231  {
4232  new_pair=TRUE;
4233  for (j=0; j<=k; j++)
4234  {
4235  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4236  }
4237  }
4238  }
4239  else
4240  {
4241  for (j=0; j<=k; j++)
4242  {
4243  if ((pGetComp(h)==pGetComp(strat->S[j]))
4244  || (pGetComp(strat->S[j])==0))
4245  {
4246  new_pair=TRUE;
4247  enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4248  }
4249  }
4250  }
4251  if (new_pair)
4252  {
4253  #ifdef HAVE_RATGRING
4254  if (currRing->real_var_start>0)
4255  chainCritPart(h,ecart,strat);
4256  else
4257  #endif
4258  strat->chainCrit(h,ecart,strat);
4259  }
4260  kMergeBintoL(strat);
4261  }
4262 }
4263 
4264 static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4265 {
4266  const int iCompH = pGetComp(h);
4267  if (!nIsOne(pGetCoeff(h)))
4268  {
4269  int j;
4270 
4271  for (j=0; j<=k && !strat->sigdrop; j++)
4272  {
4273  // Print("j:%d, Ll:%d\n",j,strat->Ll);
4274 // if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4275 // ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4276  if (((iCompH == pGetComp(strat->S[j]))
4277  || (0 == pGetComp(strat->S[j])))
4278  && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4279  {
4280  enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4281  }
4282  }
4283  }
4284 }
4285 #endif
4286 
4287 #ifdef HAVE_RINGS
4288 /*2
4289 * Generates spoly(0, h) if applicable. Assumes ring in Z/2^n.
4290 */
4292 {
4293  if (nIsOne(pGetCoeff(h))) return;
4294  number gcd;
4295  bool go = false;
4296  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4297  {
4298  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4299  go = true;
4300  }
4301  else
4302  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4303  if (go || !nIsOne(gcd))
4304  {
4305  poly p = h->next;
4306  if (!go)
4307  {
4308  number tmp = gcd;
4309  gcd = n_Ann(gcd,currRing->cf);
4310  nDelete(&tmp);
4311  }
4312  p_Test(p,strat->tailRing);
4313  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4314  nDelete(&gcd);
4315 
4316  if (p != NULL)
4317  {
4318  if (TEST_OPT_PROT)
4319  {
4320  PrintS("Z");
4321  }
4322 #ifdef KDEBUG
4323  if (TEST_OPT_DEBUG)
4324  {
4325  PrintS("--- create zero spoly: ");
4326  p_wrp(h,currRing,strat->tailRing);
4327  PrintS(" ---> ");
4328  }
4329 #endif
4330  poly tmp = pInit();
4331  pSetCoeff0(tmp, pGetCoeff(p));
4332  for (int i = 1; i <= rVar(currRing); i++)
4333  {
4334  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4335  }
4337  {
4338  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4339  }
4340  p_Setm(tmp, currRing);
4341  p = p_LmFreeAndNext(p, strat->tailRing);
4342  pNext(tmp) = p;
4343  LObject Lp;
4344  Lp.Init();
4345  Lp.p = tmp;
4346  Lp.tailRing = strat->tailRing;
4347  int posx;
4348  if (Lp.p!=NULL)
4349  {
4350  strat->initEcart(&Lp);
4351  if (strat->Ll==-1)
4352  posx =0;
4353  else
4354  posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4355  Lp.sev = pGetShortExpVector(Lp.p);
4356  if (strat->tailRing != currRing)
4357  {
4358  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4359  }
4360 #ifdef KDEBUG
4361  if (TEST_OPT_DEBUG)
4362  {
4363  p_wrp(tmp,currRing,strat->tailRing);
4364  PrintLn();
4365  }
4366 #endif
4367  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4368  }
4369  }
4370  }
4371  nDelete(&gcd);
4372 }
4373 
4374 void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
4375 {
4376  if (nIsOne(pGetCoeff(h))) return;
4377  number gcd;
4378  bool go = false;
4379  if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4380  {
4381  gcd = n_Ann(pGetCoeff(h),currRing->cf);
4382  go = true;
4383  }
4384  else
4385  gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4386  if (go || !nIsOne(gcd))
4387  {
4388  poly p = h->next;
4389  if (!go)
4390  {
4391  number tmp = gcd;
4392  gcd = n_Ann(gcd,currRing->cf);
4393  nDelete(&tmp);
4394  }
4395  p_Test(p,strat->tailRing);
4396  p = __pp_Mult_nn(p, gcd, strat->tailRing);
4397 
4398  if (p != NULL)
4399  {
4400  if (TEST_OPT_PROT)
4401  {
4402  PrintS("Z");
4403  }
4404 #ifdef KDEBUG
4405  if (TEST_OPT_DEBUG)
4406  {
4407  PrintS("--- create zero spoly: ");
4408  p_wrp(h,currRing,strat->tailRing);
4409  PrintS(" ---> ");
4410  }
4411 #endif
4412  poly tmp = pInit();
4413  pSetCoeff0(tmp, pGetCoeff(p));
4414  for (int i = 1; i <= rVar(currRing); i++)
4415  {
4416  pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4417  }
4419  {
4420  p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4421  }
4422  p_Setm(tmp, currRing);
4423  p = p_LmFreeAndNext(p, strat->tailRing);
4424  pNext(tmp) = p;
4425  LObject Lp;
4426  Lp.Init();
4427  Lp.p = tmp;
4428  //printf("\nOld\n");pWrite(h);pWrite(hSig);
4429  #if EXT_POLY_NEW
4430  Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4431  if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4432  {
4433  strat->sigdrop = TRUE;
4434  //Try to reduce it as far as we can via redRing
4435  int red_result = redRing(&Lp,strat);
4436  if(red_result == 0)
4437  {
4438  // Cancel the sigdrop
4439  p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4440  strat->sigdrop = FALSE;
4441  return;
4442  }
4443  else
4444  {
4445  strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4446  #if 1
4447  strat->enterS(Lp,0,strat,strat->tl);
4448  #endif
4449  return;
4450  }
4451 
4452  }
4453  #else
4454  Lp.sig = pOne();
4455  if(strat->Ll >= 0)
4456  p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4457  else
4458  p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4459  #endif
4460  Lp.tailRing = strat->tailRing;
4461  int posx;
4462  if (Lp.p!=NULL)
4463  {
4464  strat->initEcart(&Lp);
4465  if (strat->Ll==-1)
4466  posx =0;
4467  else
4468  posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4469  Lp.sev = pGetShortExpVector(Lp.p);
4470  if (strat->tailRing != currRing)
4471  {
4472  Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4473  }
4474 #ifdef KDEBUG
4475  if (TEST_OPT_DEBUG)
4476  {
4477  p_wrp(tmp,currRing,strat->tailRing);
4478  PrintLn();
4479  }
4480 #endif
4481  //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4482  enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4483  }
4484  }
4485  nDelete(&gcd);
4486  }
4487  nDelete(&gcd);
4488 }
4489 #endif
4490 
4491 #ifdef HAVE_RINGS
4492 void clearSbatch (poly h,int k,int pos,kStrategy strat)
4493 {
4494  int j = pos;
4495  if ( (!strat->fromT)
4496  && ((strat->syzComp==0)
4497  ||(pGetComp(h)<=strat->syzComp)
4498  ))
4499  {
4500  // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4501  unsigned long h_sev = pGetShortExpVector(h);
4502  loop
4503  {
4504  if (j > k) break;
4505  clearS(h,h_sev, &j,&k,strat);
4506  j++;
4507  }
4508  // Print("end clearS sl=%d\n",strat->sl);
4509  }
4510 }
4511 #endif
4512 
4513 #ifdef HAVE_RINGS
4514 /*2
4515 * Generates a sufficient set of spolys (maybe just a finite generating
4516 * set of the syzygys)
4517 */
4518 void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4519 {
4521 #if HAVE_SHIFTBBA
4522  assume(!rIsLPRing(currRing)); /* LP should use enterpairsShift */
4523 #endif
4524  // enter also zero divisor * poly, if this is non zero and of smaller degree
4525  if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat);
4526  initenterstrongPairs(h, k, ecart, 0, strat, atR);
4527  initenterpairs(h, k, ecart, 0, strat, atR);
4528  clearSbatch(h, k, pos, strat);
4529 }
4530 
4531 void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4532 {
4534  // enter also zero divisor * poly, if this is non zero and of smaller degree
4535  if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4536  if(strat->sigdrop) return;
4537  initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4538  if(strat->sigdrop) return;
4539  initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4540  if(strat->sigdrop) return;
4541  clearSbatch(h, k, pos, strat);
4542 }
4543 #endif
4544 
4545 /*2
4546 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4547 *superfluous elements in S will be deleted
4548 */
4549 void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4550 {
4551  int j=pos;
4552 
4554  initenterpairs(h,k,ecart,0,strat, atR);
4555  if ( (!strat->fromT)
4556  && ((strat->syzComp==0)
4557  ||(pGetComp(h)<=strat->syzComp)))
4558  {
4559  unsigned long h_sev = pGetShortExpVector(h);
4560  loop
4561  {
4562  if (j > k) break;
4563  clearS(h,h_sev, &j,&k,strat);
4564  j++;
4565  }
4566  }
4567 }
4568 
4569 /*2
4570 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4571 *superfluous elements in S will be deleted
4572 *this is a special variant of signature-based algorithms including the
4573 *signatures for criteria checks
4574 */
4575 void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4576 {
4577  int j=pos;
4579  initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4580  if ( (!strat->fromT)
4581  && ((strat->syzComp==0)
4582  ||(pGetComp(h)<=strat->syzComp)))
4583  {
4584  unsigned long h_sev = pGetShortExpVector(h);
4585  loop
4586  {
4587  if (j > k) break;
4588  clearS(h,h_sev, &j,&k,strat);
4589  j++;
4590  }
4591  }
4592 }
4593 
4594 /*2
4595 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4596 *superfluous elements in S will be deleted
4597 */
4598 void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4599 {
4600  int j;
4601  const int iCompH = pGetComp(h);
4602 
4603  if (rField_is_Ring(currRing))
4604  {
4605  for (j=0; j<=k; j++)
4606  {
4607  const int iCompSj = pGetComp(strat->S[j]);
4608  if ((iCompH==iCompSj)
4609  //|| (0==iCompH) // can only happen,if iCompSj==0
4610  || (0==iCompSj))
4611  {
4612  enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4613  }
4614  }
4615  kMergeBintoL(strat);
4616  }
4617  else
4618  {
4619  for (j=0; j<=k; j++)
4620  {
4621  const int iCompSj = pGetComp(strat->S[j]);
4622  if ((iCompH==iCompSj)
4623  //|| (0==iCompH) // can only happen,if iCompSj==0
4624  || (0==iCompSj))
4625  {
4626  enterOnePairSpecial(j,h,ecart,strat, atR);
4627  }
4628  }
4629  }
4630 
4631  if (strat->noClearS) return;
4632 
4633 // #ifdef HAVE_PLURAL
4634 /*
4635  if (rIsPluralRing(currRing))
4636  {
4637  j=pos;
4638  loop
4639  {
4640  if (j > k) break;
4641 
4642  if (pLmDivisibleBy(h, strat->S[j]))
4643  {
4644  deleteInS(j, strat);
4645  j--;
4646  k--;
4647  }
4648 
4649  j++;
4650  }
4651  }
4652  else
4653 */
4654 // #endif // ??? Why was the following cancelation disabled for non-commutative rings?
4655  {
4656  j=pos;
4657  loop
4658  {
4659  unsigned long h_sev = pGetShortExpVector(h);
4660  if (j > k) break;
4661  clearS(h,h_sev,&j,&k,strat);
4662  j++;
4663  }
4664  }
4665 }
4666 
4667 /*2
4668 *reorders s with respect to posInS,
4669 *suc is the first changed index or zero
4670 */
4671 
4672 void reorderS (int* suc,kStrategy strat)
4673 {
4674  int i,j,at,ecart, s2r;
4675  int fq=0;
4676  unsigned long sev;
4677  poly p;
4678  int new_suc=strat->sl+1;
4679  i= *suc;
4680  if (i<0) i=0;
4681 
4682  for (; i<=strat->sl; i++)
4683  {
4684  at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4685  if (at != i)
4686  {
4687  if (new_suc > at) new_suc = at;
4688  p = strat->S[i];
4689  ecart = strat->ecartS[i];
4690  sev = strat->sevS[i];
4691  s2r = strat->S_2_R[i];
4692  if (strat->fromQ!=NULL) fq=strat->fromQ[i];
4693  for (j=i; j>=at+1; j--)
4694  {
4695  strat->S[j] = strat->S[j-1];
4696  strat->ecartS[j] = strat->ecartS[j-1];
4697  strat->sevS[j] = strat->sevS[j-1];
4698  strat->S_2_R[j] = strat->S_2_R[j-1];
4699  }
4700  strat->S[at] = p;
4701  strat->ecartS[at] = ecart;
4702  strat->sevS[at] = sev;
4703  strat->S_2_R[at] = s2r;
4704  if (strat->fromQ!=NULL)
4705  {
4706  for (j=i; j>=at+1; j--)
4707  {
4708  strat->fromQ[j] = strat->fromQ[j-1];
4709  }
4710  strat->fromQ[at]=fq;
4711  }
4712  }
4713  }
4714  if (new_suc <= strat->sl) *suc=new_suc;
4715  else *suc=-1;
4716 }
4717 
4718 
4719 /*2
4720 *looks up the position of p in set
4721 *set[0] is the smallest with respect to the ordering-procedure deg/pComp
4722 * Assumption: posInS only depends on the leading term
4723 * otherwise, bba has to be changed
4724 */
4725 int posInS (const kStrategy strat, const int length,const poly p,
4726  const int ecart_p)
4727 {
4728  if(length==-1) return 0;
4729  polyset set=strat->S;
4730  int i;
4731  int an = 0;
4732  int en = length;
4733  int cmp_int = currRing->OrdSgn;
4735 #ifdef HAVE_PLURAL
4736  && (currRing->real_var_start==0)
4737 #endif
4738 #if 0
4739  || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
4740 #endif
4741  )
4742  {
4743  int o=p_Deg(p,currRing);
4744  int oo=p_Deg(set[length],currRing);
4745 
4746  if ((oo<o)
4747  || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
4748  return length+1;
4749 
4750  loop
4751  {
4752  if (an >= en-1)
4753  {
4754  if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
4755  {
4756  return an;
4757  }
4758  return en;
4759  }
4760  i=(an+en) / 2;
4761  if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
4762  else an=i;
4763  }
4764  }
4765  else
4766  {
4767  if (rField_is_Ring(currRing))
4768  {
4769  if (pLmCmp(set[length],p)== -cmp_int)
4770  return length+1;
4771  int cmp;
4772  loop
4773  {
4774  if (an >= en-1)
4775  {
4776  cmp = pLmCmp(set[an],p);
4777  if (cmp == cmp_int) return an;
4778  if (cmp == -cmp_int) return en;
4779  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
4780  return an;
4781  }
4782  i = (an+en) / 2;
4783  cmp = pLmCmp(set[i],p);
4784  if (cmp == cmp_int) en = i;
4785  else if (cmp == -cmp_int) an = i;
4786  else
4787  {
4788  if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
4789  else en = i;
4790  }
4791  }
4792  }
4793  else
4794  if (pLmCmp(set[length],p)== -cmp_int)
4795  return length+1;
4796 
4797  loop
4798  {
4799  if (an >= en-1)
4800  {
4801  if (pLmCmp(set[an],p) == cmp_int) return an;
4802  if (pLmCmp(set[an],p) == -cmp_int) return en;
4803  if ((cmp_int!=1)
4804  && ((strat->ecartS[an])>ecart_p))
4805  return an;
4806  return en;
4807  }
4808  i=(an+en) / 2;
4809  if (pLmCmp(set[i],p) == cmp_int) en=i;
4810  else if (pLmCmp(set[i],p) == -cmp_int) an=i;
4811  else
4812  {
4813  if ((cmp_int!=1)
4814  &&((strat->ecartS[i])<ecart_p))
4815  en=i;
4816  else
4817  an=i;
4818  }
4819  }
4820  }
4821 }
4822 
4823 
4824 // sorts by degree and pLtCmp
4825 // but puts pure monomials at the beginning
4826 int posInSMonFirst (const kStrategy strat, const int length,const poly p)
4827 {
4828  if (length<0) return 0;
4829  polyset set=strat->S;
4830  if(pNext(p) == NULL)
4831  {
4832  int mon = 0;
4833  for(int i = 0;i<=length;i++)
4834  {
4835  if(set[i] != NULL && pNext(set[i]) == NULL)
4836  mon++;
4837  }
4838  int o = p_Deg(p,currRing);
4839  int op = p_Deg(set[mon],currRing);
4840 
4841  if ((op < o)
4842  || ((op == o) && (pLtCmp(set[mon],p) == -1)))
4843  return length+1;
4844  int i;
4845  int an = 0;
4846  int en= mon;
4847  loop
4848  {
4849  if (an >= en-1)
4850  {
4851  op = p_Deg(set[an],currRing);
4852  if ((op < o)
4853  || ((op == o) && (pLtCmp(set[an],p) == -1)))
4854  return en;
4855  return an;
4856  }
4857  i=(an+en) / 2;
4858  op = p_Deg(set[i],currRing);
4859  if ((op < o)
4860  || ((op == o) && (pLtCmp(set[i],p) == -1)))
4861  an=i;
4862  else
4863  en=i;
4864  }
4865  }
4866  else /*if(pNext(p) != NULL)*/
4867  {
4868  int o = p_Deg(p,currRing);
4869  int op = p_Deg(set[length],currRing);
4870 
4871  if ((op < o)
4872  || ((op == o) && (pLtCmp(set[length],p) == -1)))
4873  return length+1;
4874  int i;
4875  int an = 0;
4876  for(i=0;i<=length;i++)
4877  if(set[i] != NULL && pNext(set[i]) == NULL)
4878  an++;
4879  int en= length;
4880  loop
4881  {
4882  if (an >= en-1)
4883  {
4884  op = p_Deg(set[an],currRing);
4885  if ((op < o)
4886  || ((op == o) && (pLtCmp(set[an],p) == -1)))
4887  return en;
4888  return an;
4889  }
4890  i=(an+en) / 2;
4891  op = p_Deg(set[i],currRing);
4892  if ((op < o)
4893  || ((op == o) && (pLtCmp(set[i],p) == -1)))
4894  an=i;
4895  else
4896  en=i;
4897  }
4898  }
4899 }
4900 
4901 // sorts by degree and pLtCmp in the block between start,end;
4902 // but puts pure monomials at the beginning
4903 int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
4904 {
4905  if(end < 0 || end >= IDELEMS(F))
4906  end = IDELEMS(F);
4907  if (end<0) return 0;
4908  if(pNext(p) == NULL) return start;
4909  polyset set=F->m;
4910  int o = p_Deg(p,currRing);
4911  int op;
4912  int i;
4913  int an = start;
4914  for(i=start;i<end;i++)
4915  if(set[i] != NULL && pNext(set[i]) == NULL)
4916  an++;
4917  if(an == end-1)
4918  return end;
4919  int en= end;
4920  loop
4921  {
4922  if(an>=en)
4923  return en;
4924  if (an == en-1)
4925  {
4926  op = p_Deg(set[an],currRing);
4927  if ((op < o)
4928  || ((op == o) && (pLtCmp(set[an],p) == -1)))
4929  return en;
4930  return an;
4931  }
4932  i=(an+en) / 2;
4933  op = p_Deg(set[i],currRing);
4934  if ((op < o)
4935  || ((op == o) && (pLtCmp(set[i],p) == -1)))
4936  an=i;
4937  else
4938  en=i;
4939  }
4940 }
4941 
4942 
4943 /*2
4944 * looks up the position of p in set
4945 * the position is the last one
4946 */
4947 int posInT0 (const TSet,const int length,LObject &)
4948 {
4949  return (length+1);
4950 }
4951 
4952 
4953 /*2
4954 * looks up the position of p in T
4955 * set[0] is the smallest with respect to the ordering-procedure
4956 * pComp
4957 */
4958 int posInT1 (const TSet set,const int length,LObject &p)
4959 {
4960  if (length==-1) return 0;
4961 
4962  if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
4963 
4964  int i;
4965  int an = 0;
4966  int en= length;
4967 
4968  loop
4969  {
4970  if (an >= en-1)
4971  {
4972  if (pLmCmp(set[an].p,p.p) == currRing->OrdSgn) return an;
4973  return en;
4974  }
4975  i=(an+en) / 2;
4976  if (pLmCmp(set[i].p,p.p) == currRing->OrdSgn) en=i;
4977  else an=i;
4978  }
4979 }
4980 
4981 /*2
4982 * looks up the position of p in T
4983 * set[0] is the smallest with respect to the ordering-procedure
4984 * length
4985 */
4986 int posInT2 (const TSet set,const int length,LObject &p)
4987 {
4988  if (length==-1) return 0;
4989  p.GetpLength();
4990  if (set[length].length<p.length) return length+1;
4991 
4992  int i;
4993  int an = 0;
4994  int en= length;
4995 
4996  loop
4997  {
4998  if (an >= en-1)
4999  {
5000  if (set[an].length>p.length) return an;
5001  return en;
5002  }
5003  i=(an+en) / 2;
5004  if (set[i].length>p.length) en=i;
5005  else an=i;
5006  }
5007 }
5008 
5009 /*2
5010 * looks up the position of p in T
5011 * set[0] is the smallest with respect to the ordering-procedure
5012 * totaldegree,pComp
5013 */
5014 int posInT11 (const TSet set,const int length,LObject &p)
5015 {
5016  if (length==-1) return 0;
5017 
5018  int o = p.GetpFDeg();
5019  int op = set[length].GetpFDeg();
5020 
5021  if ((op < o)
5022  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5023  return length+1;
5024 
5025  int i;
5026  int an = 0;
5027  int en= length;
5028 
5029  loop
5030  {
5031  if (an >= en-1)
5032  {
5033  op= set[an].GetpFDeg();
5034  if ((op > o)
5035  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5036  return an;
5037  return en;
5038  }
5039  i=(an+en) / 2;
5040  op = set[i].GetpFDeg();
5041  if (( op > o)
5042  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5043  en=i;
5044  else
5045  an=i;
5046  }
5047 }
5048 
5049 #ifdef HAVE_RINGS
5050 int posInT11Ring (const TSet set,const int length,LObject &p)
5051 {
5052  if (length==-1) return 0;
5053 
5054  int o = p.GetpFDeg();
5055  int op = set[length].GetpFDeg();
5056 
5057  if ((op < o)
5058  || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5059  return length+1;
5060 
5061  int i;
5062  int an = 0;
5063  int en= length;
5064 
5065  loop
5066  {
5067  if (an >= en-1)
5068  {
5069  op= set[an].GetpFDeg();
5070  if ((op > o)
5071  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5072  return an;
5073  return en;
5074  }
5075  i=(an+en) / 2;
5076  op = set[i].GetpFDeg();
5077  if (( op > o)
5078  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5079  en=i;
5080  else
5081  an=i;
5082  }
5083 }
5084 #endif
5085 
5086 /*2 Pos for rings T: Here I am
5087 * looks up the position of p in T
5088 * set[0] is the smallest with respect to the ordering-procedure
5089 * totaldegree,pComp
5090 */
5091 int posInTrg0 (const TSet set,const int length,LObject &p)
5092 {
5093  if (length==-1) return 0;
5094  int o = p.GetpFDeg();
5095  int op = set[length].GetpFDeg();
5096  int i;
5097  int an = 0;
5098  int en = length;
5099  int cmp_int = currRing->OrdSgn;
5100  if ((op < o) || (pLmCmp(set[length].p,p.p)== -cmp_int))
5101  return length+1;
5102  int cmp;
5103  loop
5104  {
5105  if (an >= en-1)
5106  {
5107  op = set[an].GetpFDeg();
5108  if (op > o) return an;
5109  if (op < 0) return en;
5110  cmp = pLmCmp(set[an].p,p.p);
5111  if (cmp == cmp_int) return an;
5112  if (cmp == -cmp_int) return en;
5113  if (nGreater(pGetCoeff(p.p), pGetCoeff(set[an].p))) return en;
5114  return an;
5115  }
5116  i = (an + en) / 2;
5117  op = set[i].GetpFDeg();
5118  if (op > o) en = i;
5119  else if (op < o) an = i;
5120  else
5121  {
5122  cmp = pLmCmp(set[i].p,p.p);
5123  if (cmp == cmp_int) en = i;
5124  else if (cmp == -cmp_int) an = i;
5125  else if (nGreater(pGetCoeff(p.p), pGetCoeff(set[i].p))) an = i;
5126  else en = i;
5127  }
5128  }
5129 }
5130 /*
5131  int o = p.GetpFDeg();
5132  int op = set[length].GetpFDeg();
5133 
5134  if ((op < o)
5135  || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5136  return length+1;
5137 
5138  int i;
5139  int an = 0;
5140  int en= length;
5141 
5142  loop
5143  {
5144  if (an >= en-1)
5145  {
5146  op= set[an].GetpFDeg();
5147  if ((op > o)
5148  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5149  return an;
5150  return en;
5151  }
5152  i=(an+en) / 2;
5153  op = set[i].GetpFDeg();
5154  if (( op > o)
5155  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5156  en=i;
5157  else
5158  an=i;
5159  }
5160 }
5161  */
5162 /*2
5163 * looks up the position of p in T
5164 * set[0] is the smallest with respect to the ordering-procedure
5165 * totaldegree,pComp
5166 */
5167 int posInT110 (const TSet set,const int length,LObject &p)
5168 {
5169  if (length==-1) return 0;
5170  p.GetpLength();
5171 
5172  int o = p.GetpFDeg();
5173  int op = set[length].GetpFDeg();
5174 
5175  if (( op < o)
5176  || (( op == o) && (set[length].length<p.length))
5177  || (( op == o) && (set[length].length == p.length)
5178  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5179  return length+1;
5180 
5181  int i;
5182  int an = 0;
5183  int en= length;
5184  loop
5185  {
5186  if (an >= en-1)
5187  {
5188  op = set[an].GetpFDeg();
5189  if (( op > o)
5190  || (( op == o) && (set[an].length > p.length))
5191  || (( op == o) && (set[an].length == p.length)
5192  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5193  return an;
5194  return en;
5195  }
5196  i=(an+en) / 2;
5197  op = set[i].GetpFDeg();
5198  if (( op > o)
5199  || (( op == o) && (set[i].length > p.length))
5200  || (( op == o) && (set[i].length == p.length)
5201  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5202  en=i;
5203  else
5204  an=i;
5205  }
5206 }
5207 
5208 #ifdef HAVE_RINGS
5209 int posInT110Ring (const TSet set,const int length,LObject &p)
5210 {
5211  if (length==-1) return 0;
5212  p.GetpLength();
5213 
5214  int o = p.GetpFDeg();
5215  int op = set[length].GetpFDeg();
5216 
5217  if (( op < o)
5218  || (( op == o) && (set[length].length<p.length))
5219  || (( op == o) && (set[length].length == p.length)
5220  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5221  return length+1;
5222 
5223  int i;
5224  int an = 0;
5225  int en= length;
5226  loop
5227  {
5228  if (an >= en-1)
5229  {
5230  op = set[an].GetpFDeg();
5231  if (( op > o)
5232  || (( op == o) && (set[an].length > p.length))
5233  || (( op == o) && (set[an].length == p.length)
5234  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5235  return an;
5236  return en;
5237  }
5238  i=(an+en) / 2;
5239  op = set[i].GetpFDeg();
5240  if (( op > o)
5241  || (( op == o) && (set[i].length > p.length))
5242  || (( op == o) && (set[i].length == p.length)
5243  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5244  en=i;
5245  else
5246  an=i;
5247  }
5248 }
5249 #endif
5250 
5251 /*2
5252 * looks up the position of p in set
5253 * set[0] is the smallest with respect to the ordering-procedure
5254 * pFDeg
5255 */
5256 int posInT13 (const TSet set,const int length,LObject &p)
5257 {
5258  if (length==-1) return 0;
5259 
5260  int o = p.GetpFDeg();
5261 
5262  if (set[length].GetpFDeg() <= o)
5263  return length+1;
5264 
5265  int i;
5266  int an = 0;
5267  int en= length;
5268  loop
5269  {
5270  if (an >= en-1)
5271  {
5272  if (set[an].GetpFDeg() > o)
5273  return an;
5274  return en;
5275  }
5276  i=(an+en) / 2;
5277  if (set[i].GetpFDeg() > o)
5278  en=i;
5279  else
5280  an=i;
5281  }
5282 }
5283 
5284 // determines the position based on: 1.) Ecart 2.) pLength
5285 int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5286 {
5287  if (length==-1) return 0;
5288  int ol = p.GetpLength();
5289  int op=p.ecart;
5290  int oo=set[length].ecart;
5291 
5292  if ((oo < op) || ((oo==op) && (set[length].length <= ol)))
5293  return length+1;
5294 
5295  int i;
5296  int an = 0;
5297  int en= length;
5298  loop
5299  {
5300  if (an >= en-1)
5301  {
5302  int oo=set[an].ecart;
5303  if((oo > op)
5304  || ((oo==op) && (set[an].pLength > ol)))
5305  return an;
5306  return en;
5307  }
5308  i=(an+en) / 2;
5309  int oo=set[i].ecart;
5310  if ((oo > op)
5311  || ((oo == op) && (set[i].pLength > ol)))
5312  en=i;
5313  else
5314  an=i;
5315  }
5316 }
5317 
5318 /*2
5319 * looks up the position of p in set
5320 * set[0] is the smallest with respect to the ordering-procedure
5321 * maximaldegree, pComp
5322 */
5323 int posInT15 (const TSet set,const int length,LObject &p)
5324 /*{
5325  *int j=0;
5326  * int o;
5327  *
5328  * o = p.GetpFDeg()+p.ecart;
5329  * loop
5330  * {
5331  * if ((set[j].GetpFDeg()+set[j].ecart > o)
5332  * || ((set[j].GetpFDeg()+set[j].ecart == o)
5333  * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5334  * {
5335  * return j;
5336  * }
5337  * j++;
5338  * if (j > length) return j;
5339  * }
5340  *}
5341  */
5342 {
5343  if (length==-1) return 0;
5344 
5345  int o = p.GetpFDeg() + p.ecart;
5346  int op = set[length].GetpFDeg()+set[length].ecart;
5347 
5348  if ((op < o)
5349  || ((op == o)
5350  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5351  return length+1;
5352 
5353  int i;
5354  int an = 0;
5355  int en= length;
5356  loop
5357  {
5358  if (an >= en-1)
5359  {
5360  op = set[an].GetpFDeg()+set[an].ecart;
5361  if (( op > o)
5362  || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5363  return an;
5364  return en;
5365  }
5366  i=(an+en) / 2;
5367  op = set[i].GetpFDeg()+set[i].ecart;
5368  if (( op > o)
5369  || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5370  en=i;
5371  else
5372  an=i;
5373  }
5374 }
5375 
5376 #ifdef HAVE_RINGS
5377 int posInT15Ring (const TSet set,const int length,LObject &p)
5378 {
5379  if (length==-1) return 0;
5380 
5381  int o = p.GetpFDeg() + p.ecart;
5382  int op = set[length].GetpFDeg()+set[length].ecart;
5383 
5384  if ((op < o)
5385  || ((op == o)
5386  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5387  return length+1;
5388 
5389  int i;
5390  int an = 0;
5391  int en= length;
5392  loop
5393  {
5394  if (an >= en-1)
5395  {
5396  op = set[an].GetpFDeg()+set[an].ecart;
5397  if (( op > o)
5398  || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5399  return an;
5400  return en;
5401  }
5402  i=(an+en) / 2;
5403  op = set[i].GetpFDeg()+set[i].ecart;
5404  if (( op > o)
5405  || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5406  en=i;
5407  else
5408  an=i;
5409  }
5410 }
5411 #endif
5412 
5413 /*2
5414 * looks up the position of p in set
5415 * set[0] is the smallest with respect to the ordering-procedure
5416 * pFDeg+ecart, ecart, pComp
5417 */
5418 int posInT17 (const TSet set,const int length,LObject &p)
5419 /*
5420 *{
5421 * int j=0;
5422 * int o;
5423 *
5424 * o = p.GetpFDeg()+p.ecart;
5425 * loop
5426 * {
5427 * if ((pFDeg(set[j].p)+set[j].ecart > o)
5428 * || (((pFDeg(set[j].p)+set[j].ecart == o)
5429 * && (set[j].ecart < p.ecart)))
5430 * || ((pFDeg(set[j].p)+set[j].ecart == o)
5431 * && (set[j].ecart==p.ecart)
5432 * && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5433 * return j;
5434 * j++;
5435 * if (j > length) return j;
5436 * }
5437 * }
5438 */
5439 {
5440  if (length==-1) return 0;
5441 
5442  int o = p.GetpFDeg() + p.ecart;
5443  int op = set[length].GetpFDeg()+set[length].ecart;
5444 
5445  if ((op < o)
5446  || (( op == o) && (set[length].ecart > p.ecart))
5447  || (( op == o) && (set[length].ecart==p.ecart)
5448  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5449  return length+1;
5450 
5451  int i;
5452  int an = 0;
5453  int en= length;
5454  loop
5455  {
5456  if (an >= en-1)
5457  {
5458  op = set[an].GetpFDeg()+set[an].ecart;
5459  if (( op > o)
5460  || (( op == o) && (set[an].ecart < p.ecart))
5461  || (( op == o) && (set[an].ecart==p.ecart)
5462  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5463  return an;
5464  return en;
5465  }
5466  i=(an+en) / 2;
5467  op = set[i].GetpFDeg()+set[i].ecart;
5468  if ((op > o)
5469  || (( op == o) && (set[i].ecart < p.ecart))
5470  || (( op == o) && (set[i].ecart == p.ecart)
5471  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5472  en=i;
5473  else
5474  an=i;
5475  }
5476 }
5477 
5478 #ifdef HAVE_RINGS
5479 int posInT17Ring (const TSet set,const int length,LObject &p)
5480 {
5481  if (length==-1) return 0;
5482 
5483  int o = p.GetpFDeg() + p.ecart;
5484  int op = set[length].GetpFDeg()+set[length].ecart;
5485 
5486  if ((op < o)
5487  || (( op == o) && (set[length].ecart > p.ecart))
5488  || (( op == o) && (set[length].ecart==p.ecart)
5489  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5490  return length+1;
5491 
5492  int i;
5493  int an = 0;
5494  int en= length;
5495  loop
5496  {
5497  if (an >= en-1)
5498  {
5499  op = set[an].GetpFDeg()+set[an].ecart;
5500  if (( op > o)
5501  || (( op == o) && (set[an].ecart < p.ecart))
5502  || (( op == o) && (set[an].ecart==p.ecart)
5503  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5504  return an;
5505  return en;
5506  }
5507  i=(an+en) / 2;
5508  op = set[i].GetpFDeg()+set[i].ecart;
5509  if ((op > o)
5510  || (( op == o) && (set[i].ecart < p.ecart))
5511  || (( op == o) && (set[i].ecart == p.ecart)
5512  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5513  en=i;
5514  else
5515  an=i;
5516  }
5517 }
5518 #endif
5519 
5520 /*2
5521 * looks up the position of p in set
5522 * set[0] is the smallest with respect to the ordering-procedure
5523 * pGetComp, pFDeg+ecart, ecart, pComp
5524 */
5525 int posInT17_c (const TSet set,const int length,LObject &p)
5526 {
5527  if (length==-1) return 0;
5528 
5529  int cc = (-1+2*currRing->order[0]==ringorder_c);
5530  /* cc==1 for (c,..), cc==-1 for (C,..) */
5531  int o = p.GetpFDeg() + p.ecart;
5532  int c = pGetComp(p.p)*cc;
5533 
5534  if (pGetComp(set[length].p)*cc < c)
5535  return length+1;
5536  if (pGetComp(set[length].p)*cc == c)
5537  {
5538  int op = set[length].GetpFDeg()+set[length].ecart;
5539  if ((op < o)
5540  || ((op == o) && (set[length].ecart > p.ecart))
5541  || ((op == o) && (set[length].ecart==p.ecart)
5542  && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5543  return length+1;
5544  }
5545 
5546  int i;
5547  int an = 0;
5548  int en= length;
5549  loop
5550  {
5551  if (an >= en-1)
5552  {
5553  if (pGetComp(set[an].p)*cc < c)
5554  return en;
5555  if (pGetComp(set[an].p)*cc == c)
5556  {
5557  int op = set[an].GetpFDeg()+set[an].ecart;
5558  if ((op > o)
5559  || ((op == o) && (set[an].ecart < p.ecart))
5560  || ((op == o) && (set[an].ecart==p.ecart)
5561  && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5562  return an;
5563  }
5564  return en;
5565  }
5566  i=(an+en) / 2;
5567  if (pGetComp(set[i].p)*cc > c)
5568  en=i;
5569  else if (pGetComp(set[i].p)*cc == c)
5570  {
5571  int op = set[i].GetpFDeg()+set[i].ecart;
5572  if ((op > o)
5573  || ((op == o) && (set[i].ecart < p.ecart))
5574  || ((op == o) && (set[i].ecart == p.ecart)
5575  && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5576  en=i;
5577  else
5578  an=i;
5579  }
5580  else
5581  an=i;
5582  }
5583 }
5584 
5585 #ifdef HAVE_RINGS
5586 int posInT17_cRing (const TSet set,const int length,LObject &p)
5587 {
5588  if (length==-1) return 0;
5589 
5590  int cc = (-1+2*currRing->order[0]==ringorder_c);
5591  /* cc==1 for (c,..), cc==-1 for (C,..) */
5592  int o = p.GetpFDeg() + p.ecart;
5593  int c = pGetComp(p.p)*cc;
5594 
5595  if (pGetComp(set[length].p)*cc < c)
5596  return length+1;
5597  if (pGetComp(set[length].p)*cc == c)
5598  {
5599  int op = set[length].GetpFDeg()+set[length].ecart;
5600  if ((op < o)
5601  || ((op == o) && (set[length].ecart > p.ecart))
5602  || ((op == o) && (set[length].ecart==p.ecart)
5603  && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5604  return length+1;
5605  }
5606 
5607  int i;
5608  int an = 0;
5609  int en= length;
5610  loop
5611  {
5612  if (an >= en-1)
5613  {
5614  if (pGetComp(set[an].p)*cc < c)
5615  return en;
5616  if (pGetComp(set[an].p)*cc == c)
5617  {
5618  int op = set[an].GetpFDeg()+set[an].ecart;
5619  if ((op > o)
5620  || ((op == o) && (set[an].ecart < p.ecart))
5621  || ((op == o) && (set[an].ecart==p.ecart)
5622  && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5623  return an;
5624  }
5625  return en;
5626  }
5627  i=(an+en) / 2;
5628  if (pGetComp(set[i].p)*cc > c)
5629  en=i;
5630  else if (pGetComp(set[i].p)*cc == c)
5631  {
5632  int op = set[i].GetpFDeg()+set[i].ecart;
5633  if ((op > o)
5634  || ((op == o) && (set[i].ecart < p.ecart))
5635  || ((op == o) && (set[i].ecart == p.ecart)
5636  && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5637  en=i;
5638  else
5639  an=i;
5640  }
5641  else
5642  an=i;
5643  }
5644 }
5645 #endif
5646 
5647 /*2
5648 * looks up the position of p in set
5649 * set[0] is the smallest with respect to
5650 * ecart, pFDeg, length
5651 */
5652 int posInT19 (const TSet set,const int length,LObject &p)
5653 {
5654  p.GetpLength();
5655  if (length==-1) return 0;
5656 
5657  int o = p.ecart;
5658  int op=p.GetpFDeg();
5659 
5660  if (set[length].ecart < o)
5661  return length+1;
5662  if (set[length].ecart == o)
5663  {
5664  int oo=set[length].GetpFDeg();
5665  if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5666  return length+1;
5667  }
5668 
5669  int i;
5670  int an = 0;
5671  int en= length;
5672  loop
5673  {
5674  if (an >= en-1)
5675  {
5676  if (set[an].ecart > o)
5677  return an;
5678  if (set[an].ecart == o)
5679  {
5680  int oo=set[an].GetpFDeg();
5681  if((oo > op)
5682  || ((oo==op) && (set[an].length > p.length)))
5683  return an;
5684  }
5685  return en;
5686  }
5687  i=(an+en) / 2;
5688  if (set[i].ecart > o)
5689  en=i;
5690  else if (set[i].ecart == o)
5691  {
5692  int oo=set[i].GetpFDeg();
5693  if ((oo > op)
5694  || ((oo == op) && (set[i].length > p.length)))
5695  en=i;
5696  else
5697  an=i;
5698  }
5699  else
5700  an=i;
5701  }
5702 }
5703 
5704 /*2
5705 *looks up the position of polynomial p in set
5706 *set[length] is the smallest element in set with respect
5707 *to the ordering-procedure pComp
5708 */
5709 int posInLSpecial (const LSet set, const int length,
5710  LObject *p,const kStrategy)
5711 {
5712  if (length<0) return 0;
5713 
5714  int d=p->GetpFDeg();
5715  int op=set[length].GetpFDeg();
5716 
5717  if ((op > d)
5718  || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
5719  || (pLmCmp(set[length].p,p->p)== currRing->OrdSgn))
5720  return length+1;
5721 
5722  int i;
5723  int an = 0;
5724  int en= length;
5725  loop
5726  {
5727  if (an >= en-1)
5728  {
5729  op=set[an].GetpFDeg();
5730  if ((op > d)
5731  || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
5732  || (pLmCmp(set[an].p,p->p)== currRing->OrdSgn))
5733  return en;
5734  return an;
5735  }
5736  i=(an+en) / 2;
5737  op=set[i].GetpFDeg();
5738  if ((op>d)
5739  || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
5740  || (pLmCmp(set[i].p,p->p) == currRing->OrdSgn))
5741  an=i;
5742  else
5743  en=i;
5744  }
5745 }
5746 
5747 /*2
5748 *looks up the position of polynomial p in set
5749 *set[length] is the smallest element in set with respect
5750 *to the ordering-procedure pComp
5751 */
5752 int posInL0 (const LSet set, const int length,
5753  LObject* p,const kStrategy)
5754 {
5755  if (length<0) return 0;
5756 
5757  if (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  if (pLmCmp(set[an].p,p->p) == currRing->OrdSgn) return en;
5768  return an;
5769  }
5770  i=(an+en) / 2;
5771  if (pLmCmp(set[i].p,p->p) == currRing->OrdSgn) an=i;
5772  else en=i;
5773  /*aend. fuer lazy == in !=- machen */
5774  }
5775 }
5776 
5777 #ifdef HAVE_RINGS
5778 int posInL0Ring (const LSet set, const int length,
5779  LObject* p,const kStrategy)
5780 {
5781  if (length<0) return 0;
5782 
5783  if (pLtCmpOrdSgnEqP(set[length].p,p->p))
5784  return length+1;
5785 
5786  int i;
5787  int an = 0;
5788  int en= length;
5789  loop
5790  {
5791  if (an >= en-1)
5792  {
5793  if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
5794  return an;
5795  }
5796  i=(an+en) / 2;
5797  if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
5798  else en=i;
5799  /*aend. fuer lazy == in !=- machen */
5800  }
5801 }
5802 #endif
5803 
5804 /*2
5805 * looks up the position of polynomial p in set
5806 * e is the ecart of p
5807 * set[length] is the smallest element in set with respect
5808 * to the signature order
5809 */
5810 int posInLSig (const LSet set, const int length,
5811  LObject* p,const kStrategy /*strat*/)
5812 {
5813  if (length<0) return 0;
5814  if (pLtCmp(set[length].sig,p->sig)== currRing->OrdSgn)
5815  return length+1;
5816 
5817  int i;
5818  int an = 0;
5819  int en= length;
5820  loop
5821  {
5822  if (an >= en-1)
5823  {
5824  if (pLtCmp(set[an].sig,p->sig) == currRing->OrdSgn) return en;
5825  return an;
5826  }
5827  i=(an+en) / 2;
5828  if (pLtCmp(set[i].sig,p->sig) == currRing->OrdSgn) an=i;
5829  else en=i;
5830  /*aend. fuer lazy == in !=- machen */
5831  }
5832 }
5833 //sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
5834 int posInLSigRing (const LSet set, const int length,
5835  LObject* p,const kStrategy /*strat*/)
5836 {
5837  assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
5838  if (length<0) return 0;
5839  if (pLtCmp(set[length].sig,p->sig)== 1)
5840  return length+1;
5841 
5842  int an,en,i;
5843  an = 0;
5844  en = length+1;
5845  int cmp;
5846  loop
5847  {
5848  if (an >= en-1)
5849  {
5850  if(an == en)
5851  return en;
5852  cmp = pLtCmp(set[an].sig,p->sig);
5853  if (cmp == 1)
5854  return en;
5855  if (cmp == -1)
5856  return an;
5857  if (cmp == 0)
5858  {
5859  if (set[an].FDeg > p->FDeg)
5860  return en;
5861  if (set[an].FDeg < p->FDeg)
5862  return an;
5863  if (set[an].FDeg == p->FDeg)
5864  {
5865  cmp = pLtCmp(set[an].p,p->p);
5866  if(cmp == 1)
5867  return en;
5868  else
5869  return an;
5870  }
5871  }
5872  }
5873  i=(an+en) / 2;
5874  cmp = pLtCmp(set[i].sig,p->sig);
5875  if (cmp == 1)
5876  an = i;
5877  if (cmp == -1)
5878  en = i;
5879  if (cmp == 0)
5880  {
5881  if (set[i].FDeg > p->FDeg)
5882  an = i;
5883  if (set[i].FDeg < p->FDeg)
5884  en = i;
5885  if (set[i].FDeg == p->FDeg)
5886  {
5887  cmp = pLtCmp(set[i].p,p->p);
5888  if(cmp == 1)
5889  an = i;
5890  else
5891  en = i;
5892  }
5893  }
5894  }
5895 }
5896 
5897 int posInLRing (const LSet set, const int length,
5898  LObject* p,const kStrategy /*strat*/)
5899 {
5900  if (length < 0) return 0;
5901  if (set[length].FDeg > p->FDeg)
5902  return length+1;
5903  if (set[length].FDeg == p->FDeg)
5904  if(set[length].GetpLength() > p->GetpLength())
5905  return length+1;
5906  int i;
5907  int an = 0;
5908  int en= length+1;
5909  loop
5910  {
5911  if (an >= en-1)
5912  {
5913  if(an == en)
5914  return en;
5915  if (set[an].FDeg > p->FDeg)
5916  return en;
5917  if(set[an].FDeg == p->FDeg)
5918  {
5919  if(set[an].GetpLength() > p->GetpLength())
5920  return en;
5921  else
5922  {
5923  if(set[an].GetpLength() == p->GetpLength())
5924  {
5925  if(nGreater(set[an].p->coef, p->p->coef))
5926  return en;
5927  else
5928  return an;
5929  }
5930  else
5931  {
5932  return an;
5933  }
5934  }
5935  }
5936  else
5937  return an;
5938  }
5939  i=(an+en) / 2;
5940  if (set[i].FDeg > p->FDeg)
5941  an=i;
5942  else
5943  {
5944  if(set[i].FDeg == p->FDeg)
5945  {
5946  if(set[i].GetpLength() > p->GetpLength())
5947  an=i;
5948  else
5949  {
5950  if(set[i].GetpLength() == p->GetpLength())
5951  {
5952  if(nGreater(set[i].p->coef, p->p->coef))
5953  an = i;
5954  else
5955  en = i;
5956  }
5957  else
5958  {
5959  en=i;
5960  }
5961  }
5962  }
5963  else
5964  en=i;
5965  }
5966  }
5967 }
5968 
5969 // for sba, sorting syzygies
5970 int posInSyz (const kStrategy strat, poly sig)
5971 {
5972  if (strat->syzl==0) return 0;
5973  if (pLtCmp(strat->syz[strat->syzl-1],sig) != currRing->OrdSgn)
5974  return strat->syzl;
5975  int i;
5976  int an = 0;
5977  int en= strat->syzl-1;
5978  loop
5979  {
5980  if (an >= en-1)
5981  {
5982  if (pLtCmp(strat->syz[an],sig) != currRing->OrdSgn) return en;
5983  return an;
5984  }
5985  i=(an+en) / 2;
5986  if (pLtCmp(strat->syz[i],sig) != currRing->OrdSgn) an=i;
5987  else en=i;
5988  /*aend. fuer lazy == in !=- machen */
5989  }
5990 }
5991 
5992 /*2
5993 *
5994 * is only used in F5C, must ensure that the interreduction process does add new
5995 * critical pairs to strat->L only behind all other critical pairs which are
5996 * still in strat->L!
5997 */
5998 int posInLF5C (const LSet /*set*/, const int /*length*/,
5999  LObject* /*p*/,const kStrategy strat)
6000 {
6001  return strat->Ll+1;
6002 }
6003 
6004 /*2
6005 * looks up the position of polynomial p in set
6006 * e is the ecart of p
6007 * set[length] is the smallest element in set with respect
6008 * to the ordering-procedure totaldegree,pComp
6009 */
6010 int posInL11 (const LSet set, const int length,
6011  LObject* p,const kStrategy)
6012 {
6013  if (length<0) return 0;
6014 
6015  int o = p->GetpFDeg();
6016  int op = set[length].GetpFDeg();
6017 
6018  if ((op > o)
6019  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6020  return length+1;
6021  int i;
6022  int an = 0;
6023  int en= length;
6024  loop
6025  {
6026  if (an >= en-1)
6027  {
6028  op = set[an].GetpFDeg();
6029  if ((op > o)
6030  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6031  return en;
6032  return an;
6033  }
6034  i=(an+en) / 2;
6035  op = set[i].GetpFDeg();
6036  if ((op > o)
6037  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6038  an=i;
6039  else
6040  en=i;
6041  }
6042 }
6043 
6044 #ifdef HAVE_RINGS
6045 /*2
6046 * looks up the position of polynomial p in set
6047 * set[length] is the smallest element in set with respect
6048 * to the ordering-procedure pLmCmp,totaldegree,coefficient
6049 * For the same totaldegree, original pairs (from F) will
6050 * be put at the end and smalles coefficents
6051 */
6052 int posInL11Ring (const LSet set, const int length,
6053  LObject* p,const kStrategy)
6054 {
6055  if (length<0) return 0;
6056 
6057  int o = p->GetpFDeg();
6058  int op = set[length].GetpFDeg();
6059 
6060  if ((op > o)
6061  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6062  return length+1;
6063  int i;
6064  int an = 0;
6065  int en= length;
6066  loop
6067  {
6068  if (an >= en-1)
6069  {
6070  op = set[an].GetpFDeg();
6071  if ((op > o)
6072  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6073  return en;
6074  return an;
6075  }
6076  i=(an+en) / 2;
6077  op = set[i].GetpFDeg();
6078  if ((op > o)
6079  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6080  an=i;
6081  else
6082  en=i;
6083  }
6084 }
6085 
6086 int posInLF5CRing (const LSet set, int start,const int length,
6087  LObject* p,const kStrategy)
6088 {
6089  if (length<0) return 0;
6090  if(start == (length +1)) return (length+1);
6091  int o = p->GetpFDeg();
6092  int op = set[length].GetpFDeg();
6093 
6094  if ((op > o)
6095  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6096  return length+1;
6097  int i;
6098  int an = start;
6099  int en= length;
6100  loop
6101  {
6102  if (an >= en-1)
6103  {
6104  op = set[an].GetpFDeg();
6105  if ((op > o)
6106  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6107  return en;
6108  return an;
6109  }
6110  i=(an+en) / 2;
6111  op = set[i].GetpFDeg();
6112  if ((op > o)
6113  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6114  an=i;
6115  else
6116  en=i;
6117  }
6118 }
6119 #endif
6120 
6121 #ifdef HAVE_RINGS
6122 int posInL11Ringls (const LSet set, const int length,
6123  LObject* p,const kStrategy)
6124 {
6125  if (length < 0) return 0;
6126  int an,en,i;
6127  an = 0;
6128  en = length+1;
6129  loop
6130  {
6131  if (an >= en-1)
6132  {
6133  if(an == en)
6134  return en;
6135  if (set[an].FDeg > p->FDeg)
6136  return en;
6137  if (set[an].FDeg < p->FDeg)
6138  return an;
6139  if (set[an].FDeg == p->FDeg)
6140  {
6141  number lcset,lcp;
6142  lcset = pGetCoeff(set[an].p);
6143  lcp = pGetCoeff(p->p);
6144  if(!nGreaterZero(lcset))
6145  {
6146  set[an].p=p_Neg(set[an].p,currRing);
6147  if (set[an].t_p!=NULL)
6148  pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
6149  lcset=pGetCoeff(set[an].p);
6150  }
6151  if(!nGreaterZero(lcp))
6152  {
6153  p->p=p_Neg(p->p,currRing);
6154  if (p->t_p!=NULL)
6155  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6156  lcp=pGetCoeff(p->p);
6157  }
6158  if(nGreater(lcset, lcp))
6159  {
6160  return en;
6161  }
6162  else
6163  {
6164  return an;
6165  }
6166  }
6167  }
6168  i=(an+en) / 2;
6169  if (set[i].FDeg > p->FDeg)
6170  an=i;
6171  if (set[i].FDeg < p->FDeg)
6172  en=i;
6173  if (set[i].FDeg == p->FDeg)
6174  {
6175  number lcset,lcp;
6176  lcset = pGetCoeff(set[i].p);
6177  lcp = pGetCoeff(p->p);
6178  if(!nGreaterZero(lcset))
6179  {
6180  set[i].p=p_Neg(set[i].p,currRing);
6181  if (set[i].t_p!=NULL)
6182  pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6183  lcset=pGetCoeff(set[i].p);
6184  }
6185  if(!nGreaterZero(lcp))
6186  {
6187  p->p=p_Neg(p->p,currRing);
6188  if (p->t_p!=NULL)
6189  pSetCoeff0(p->t_p,pGetCoeff(p->p));
6190  lcp=pGetCoeff(p->p);
6191  }
6192  if(nGreater(lcset, lcp))
6193  {
6194  an = i;
6195  }
6196  else
6197  {
6198  en = i;
6199  }
6200  }
6201  }
6202 }
6203 #endif
6204 
6205 /*2 Position for rings L: Here I am
6206 * looks up the position of polynomial p in set
6207 * e is the ecart of p
6208 * set[length] is the smallest element in set with respect
6209 * to the ordering-procedure totaldegree,pComp
6210 */
6211 inline int getIndexRng(long coeff)
6212 {
6213  if (coeff == 0) return -1;
6214  long tmp = coeff;
6215  int ind = 0;
6216  while (tmp % 2 == 0)
6217  {
6218  tmp = tmp / 2;
6219  ind++;
6220  }
6221  return ind;
6222 }
6223 
6224 int posInLrg0 (const LSet set, const int length,
6225  LObject* p,const kStrategy)
6226 /* if (nGreater(pGetCoeff(p), pGetCoeff(set[an]))) return en;
6227  if (pLmCmp(set[i],p) == cmp_int) en = i;
6228  else if (pLmCmp(set[i],p) == -cmp_int) an = i;
6229  else
6230  {
6231  if (nGreater(pGetCoeff(p), pGetCoeff(set[i]))) an = i;
6232  else en = i;
6233  }*/
6234 {
6235  if (length < 0) return 0;
6236 
6237  int o = p->GetpFDeg();
6238  int op = set[length].GetpFDeg();
6239 
6240  if ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6241  return length + 1;
6242  int i;
6243  int an = 0;
6244  int en = length;
6245  loop
6246  {
6247  if (an >= en - 1)
6248  {
6249  op = set[an].GetpFDeg();
6250  if ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6251  return en;
6252  return an;
6253  }
6254  i = (an+en) / 2;
6255  op = set[i].GetpFDeg();
6256  if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6257  an = i;
6258  else
6259  en = i;
6260  }
6261 }
6262 
6263 /*{
6264  if (length < 0) return 0;
6265 
6266  int o = p->GetpFDeg();
6267  int op = set[length].GetpFDeg();
6268 
6269  int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6270  int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6271  int inda;
6272  int indi;
6273 
6274  if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6275  return length + 1;
6276  int i;
6277  int an = 0;
6278  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6279  int en = length;
6280  loop
6281  {
6282  if (an >= en-1)
6283  {
6284  op = set[an].GetpFDeg();
6285  if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6286  return en;
6287  return an;
6288  }
6289  i = (an + en) / 2;
6290  indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6291  op = set[i].GetpFDeg();
6292  if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6293  // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6294  {
6295  an = i;
6296  inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6297  }
6298  else
6299  en = i;
6300  }
6301 } */
6302 
6303 /*2
6304 * looks up the position of polynomial p in set
6305 * set[length] is the smallest element in set with respect
6306 * to the ordering-procedure totaldegree,pLength0
6307 */
6308 int posInL110 (const LSet set, const int length,
6309  LObject* p,const kStrategy)
6310 {
6311  if (length<0) return 0;
6312 
6313  int o = p->GetpFDeg();
6314  int op = set[length].GetpFDeg();
6315 
6316  if ((op > o)
6317  || ((op == o) && (set[length].length >p->length))
6318  || ((op == o) && (set[length].length <= p->length)
6319  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6320  return length+1;
6321  int i;
6322  int an = 0;
6323  int en= length;
6324  loop
6325  {
6326  if (an >= en-1)
6327  {
6328  op = set[an].GetpFDeg();
6329  if ((op > o)
6330  || ((op == o) && (set[an].length >p->length))
6331  || ((op == o) && (set[an].length <=p->length)
6332  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6333  return en;
6334  return an;
6335  }
6336  i=(an+en) / 2;
6337  op = set[i].GetpFDeg();
6338  if ((op > o)
6339  || ((op == o) && (set[i].length > p->length))
6340  || ((op == o) && (set[i].length <= p->length)
6341  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6342  an=i;
6343  else
6344  en=i;
6345  }
6346 }
6347 
6348 #ifdef HAVE_RINGS
6349 int posInL110Ring (const LSet set, const int length,
6350  LObject* p,const kStrategy)
6351 {
6352  if (length<0) return 0;
6353 
6354  int o = p->GetpFDeg();
6355  int op = set[length].GetpFDeg();
6356 
6357  if ((op > o)
6358  || ((op == o) && (set[length].length >p->length))
6359  || ((op == o) && (set[length].length <= p->length)
6360  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6361  return length+1;
6362  int i;
6363  int an = 0;
6364  int en= length;
6365  loop
6366  {
6367  if (an >= en-1)
6368  {
6369  op = set[an].GetpFDeg();
6370  if ((op > o)
6371  || ((op == o) && (set[an].length >p->length))
6372  || ((op == o) && (set[an].length <=p->length)
6373  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6374  return en;
6375  return an;
6376  }
6377  i=(an+en) / 2;
6378  op = set[i].GetpFDeg();
6379  if ((op > o)
6380  || ((op == o) && (set[i].length > p->length))
6381  || ((op == o) && (set[i].length <= p->length)
6382  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6383  an=i;
6384  else
6385  en=i;
6386  }
6387 }
6388 #endif
6389 
6390 /*2
6391 * looks up the position of polynomial p in set
6392 * e is the ecart of p
6393 * set[length] is the smallest element in set with respect
6394 * to the ordering-procedure totaldegree
6395 */
6396 int posInL13 (const LSet set, const int length,
6397  LObject* p,const kStrategy)
6398 {
6399  if (length<0) return 0;
6400 
6401  int o = p->GetpFDeg();
6402 
6403  if (set[length].GetpFDeg() > o)
6404  return length+1;
6405 
6406  int i;
6407  int an = 0;
6408  int en= length;
6409  loop
6410  {
6411  if (an >= en-1)
6412  {
6413  if (set[an].GetpFDeg() >= o)
6414  return en;
6415  return an;
6416  }
6417  i=(an+en) / 2;
6418  if (set[i].GetpFDeg() >= o)
6419  an=i;
6420  else
6421  en=i;
6422  }
6423 }
6424 
6425 /*2
6426 * looks up the position of polynomial p in set
6427 * e is the ecart of p
6428 * set[length] is the smallest element in set with respect
6429 * to the ordering-procedure maximaldegree,pComp
6430 */
6431 int posInL15 (const LSet set, const int length,
6432  LObject* p,const kStrategy)
6433 {
6434  if (length<0) return 0;
6435 
6436  int o = p->GetpFDeg() + p->ecart;
6437  int op = set[length].GetpFDeg() + set[length].ecart;
6438 
6439  if ((op > o)
6440  || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6441  return length+1;
6442  int i;
6443  int an = 0;
6444  int en= length;
6445  loop
6446  {
6447  if (an >= en-1)
6448  {
6449  op = set[an].GetpFDeg() + set[an].ecart;
6450  if ((op > o)
6451  || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6452  return en;
6453  return an;
6454  }
6455  i=(an+en) / 2;
6456  op = set[i].GetpFDeg() + set[i].ecart;
6457  if ((op > o)
6458  || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6459  an=i;
6460  else
6461  en=i;
6462  }
6463 }
6464 
6465 #ifdef HAVE_RINGS
6466 int posInL15Ring (const LSet set, const int length,
6467  LObject* p,const kStrategy)
6468 {
6469  if (length<0) return 0;
6470 
6471  int o = p->GetpFDeg() + p->ecart;
6472  int op = set[length].GetpFDeg() + set[length].ecart;
6473 
6474  if ((op > o)
6475  || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6476  return length+1;
6477  int i;
6478  int an = 0;
6479  int en= length;
6480  loop
6481  {
6482  if (an >= en-1)
6483  {
6484  op = set[an].GetpFDeg() + set[an].ecart;
6485  if ((op > o)
6486  || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6487  return en;
6488  return an;
6489  }
6490  i=(an+en) / 2;
6491  op = set[i].GetpFDeg() + set[i].ecart;
6492  if ((op > o)
6493  || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6494  an=i;
6495  else
6496  en=i;
6497  }
6498 }
6499 #endif
6500 
6501 /*2
6502 * looks up the position of polynomial p in set
6503 * e is the ecart of p
6504 * set[length] is the smallest element in set with respect
6505 * to the ordering-procedure totaldegree
6506 */
6507 int posInL17 (const LSet set, const int length,
6508  LObject* p,const kStrategy)
6509 {
6510  if (length<0) return 0;
6511 
6512  int o = p->GetpFDeg() + p->ecart;
6513 
6514  if ((set[length].GetpFDeg() + set[length].ecart > o)
6515  || ((set[length].GetpFDeg() + set[length].ecart == o)
6516  && (set[length].ecart > p->ecart))
6517  || ((set[length].GetpFDeg() + set[length].ecart == o)
6518  && (set[length].ecart == p->ecart)
6519  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6520  return length+1;
6521  int i;
6522  int an = 0;
6523  int en= length;
6524  loop
6525  {
6526  if (an >= en-1)
6527  {
6528  if ((set[an].GetpFDeg() + set[an].ecart > o)
6529  || ((set[an].GetpFDeg() + set[an].ecart == o)
6530  && (set[an].ecart > p->ecart))
6531  || ((set[an].GetpFDeg() + set[an].ecart == o)
6532  && (set[an].ecart == p->ecart)
6533  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6534  return en;
6535  return an;
6536  }
6537  i=(an+en) / 2;
6538  if ((set[i].GetpFDeg() + set[i].ecart > o)
6539  || ((set[i].GetpFDeg() + set[i].ecart == o)
6540  && (set[i].ecart > p->ecart))
6541  || ((set[i].GetpFDeg() +set[i].ecart == o)
6542  && (set[i].ecart == p->ecart)
6543  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6544  an=i;
6545  else
6546  en=i;
6547  }
6548 }
6549 
6550 #ifdef HAVE_RINGS
6551 int posInL17Ring (const LSet set, const int length,
6552  LObject* p,const kStrategy)
6553 {
6554  if (length<0) return 0;
6555 
6556  int o = p->GetpFDeg() + p->ecart;
6557 
6558  if ((set[length].GetpFDeg() + set[length].ecart > o)
6559  || ((set[length].GetpFDeg() + set[length].ecart == o)
6560  && (set[length].ecart > p->ecart))
6561  || ((set[length].GetpFDeg() + set[length].ecart == o)
6562  && (set[length].ecart == p->ecart)
6563  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6564  return length+1;
6565  int i;
6566  int an = 0;
6567  int en= length;
6568  loop
6569  {
6570  if (an >= en-1)
6571  {
6572  if ((set[an].GetpFDeg() + set[an].ecart > o)
6573  || ((set[an].GetpFDeg() + set[an].ecart == o)
6574  && (set[an].ecart > p->ecart))
6575  || ((set[an].GetpFDeg() + set[an].ecart == o)
6576  && (set[an].ecart == p->ecart)
6577  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6578  return en;
6579  return an;
6580  }
6581  i=(an+en) / 2;
6582  if ((set[i].GetpFDeg() + set[i].ecart > o)
6583  || ((set[i].GetpFDeg() + set[i].ecart == o)
6584  && (set[i].ecart > p->ecart))
6585  || ((set[i].GetpFDeg() +set[i].ecart == o)
6586  && (set[i].ecart == p->ecart)
6587  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6588  an=i;
6589  else
6590  en=i;
6591  }
6592 }
6593 #endif
6594 
6595 /*2
6596 * looks up the position of polynomial p in set
6597 * e is the ecart of p
6598 * set[length] is the smallest element in set with respect
6599 * to the ordering-procedure pComp
6600 */
6601 int posInL17_c (const LSet set, const int length,
6602  LObject* p,const kStrategy)
6603 {
6604  if (length<0) return 0;
6605 
6606  int cc = (-1+2*currRing->order[0]==ringorder_c);
6607  /* cc==1 for (c,..), cc==-1 for (C,..) */
6608  long c = pGetComp(p->p)*cc;
6609  int o = p->GetpFDeg() + p->ecart;
6610 
6611  if (pGetComp(set[length].p)*cc > c)
6612  return length+1;
6613  if (pGetComp(set[length].p)*cc == c)
6614  {
6615  if ((set[length].GetpFDeg() + set[length].ecart > o)
6616  || ((set[length].GetpFDeg() + set[length].ecart == o)
6617  && (set[length].ecart > p->ecart))
6618  || ((set[length].GetpFDeg() + set[length].ecart == o)
6619  && (set[length].ecart == p->ecart)
6620  && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6621  return length+1;
6622  }
6623  int i;
6624  int an = 0;
6625  int en= length;
6626  loop
6627  {
6628  if (an >= en-1)
6629  {
6630  if (pGetComp(set[an].p)*cc > c)
6631  return en;
6632  if (pGetComp(set[an].p)*cc == c)
6633  {
6634  if ((set[an].GetpFDeg() + set[an].ecart > o)
6635  || ((set[an].GetpFDeg() + set[an].ecart == o)
6636  && (set[an].ecart > p->ecart))
6637  || ((set[an].GetpFDeg() + set[an].ecart == o)
6638  && (set[an].ecart == p->ecart)
6639  && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6640  return en;
6641  }
6642  return an;
6643  }
6644  i=(an+en) / 2;
6645  if (pGetComp(set[i].p)*cc > c)
6646  an=i;
6647  else if (pGetComp(set[i].p)*cc == c)
6648  {
6649  if ((set[i].GetpFDeg() + set[i].ecart > o)
6650  || ((set[i].GetpFDeg() + set[i].ecart == o)
6651  && (set[i].ecart > p->ecart))
6652  || ((set[i].GetpFDeg() +set[i].ecart == o)
6653  && (set[i].ecart == p->ecart)
6654  && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6655  an=i;
6656  else
6657  en=i;
6658  }
6659  else
6660  en=i;
6661  }
6662 }
6663 
6664 #ifdef HAVE_RINGS
6665 int posInL17_cRing (const LSet set, const int length,
6666  LObject* p,const kStrategy)
6667 {
6668  if (length<0) return 0;
6669 
6670  int cc = (-1+2*currRing->order[0]==ringorder_c);
6671  /* cc==1 for (c,..), cc==-1 for (C,..) */
6672  unsigned long c = pGetComp(p->p)*cc;
6673  int o = p->GetpFDeg() + p->ecart;
6674 
6675  if (pGetComp(set[length].p)*cc > c)
6676  return length+1;
6677  if (pGetComp(set[length].p)*cc == c)
6678  {
6679  if ((set[length].GetpFDeg() + set[length].ecart > o)
6680  || ((set[length].GetpFDeg() + set[length].ecart == o)
6681  && (set[length].ecart > p->ecart))
6682  || ((set[length].GetpFDeg() + set[length].ecart == o)
6683  && (set[length].ecart == p->ecart)
6684  && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6685  return length+1;
6686  }
6687  int i;
6688  int an = 0;
6689  int en= length;
6690  loop
6691  {
6692  if (an >= en-1)
6693  {
6694  if (pGetComp(set[an].p)*cc > c)
6695  return en;
6696  if (pGetComp(set[an].p)*cc == c)
6697  {
6698  if ((set[an].GetpFDeg() + set[an].ecart > o)
6699  || ((set[an].GetpFDeg() + set[an].ecart == o)
6700  && (set[an].ecart > p->ecart))
6701  || ((set[an].GetpFDeg() + set[an].ecart == o)
6702  && (set[an].ecart == p->ecart)
6703  && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6704  return en;
6705  }
6706  return an;
6707  }
6708  i=(an+en) / 2;
6709  if (pGetComp(set[i].p)*cc > c)
6710  an=i;
6711  else if (pGetComp(set[i].p)*cc == c)
6712  {
6713  if ((set[i].GetpFDeg() + set[i].ecart > o)
6714  || ((set[i].GetpFDeg() + set[i].ecart == o)
6715  && (set[i].ecart > p->ecart))
6716  || ((set[i].GetpFDeg() +set[i].ecart == o)
6717  && (set[i].ecart == p->ecart)
6718  && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6719  an=i;
6720  else
6721  en=i;
6722  }
6723  else
6724  en=i;
6725  }
6726 }
6727 #endif
6728 
6729 /*
6730  * SYZYGY CRITERION for signature-based standard basis algorithms
6731  */
6732 BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6733 {
6734 //#if 1
6735 #ifdef DEBUGF5
6736  PrintS("syzygy criterion checks: ");
6737  pWrite(sig);
6738 #endif
6739  for (int k=0; k<strat->syzl; k++)
6740  {
6741  //printf("-%d",k);
6742 //#if 1
6743 #ifdef DEBUGF5
6744  Print("checking with: %d / %d -- \n",k,strat->syzl);
6745  pWrite(pHead(strat->syz[k]));
6746 #endif
6747  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6748  && (!rField_is_Ring(currRing) ||
6749  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6750  {
6751 //#if 1
6752 #ifdef DEBUGF5
6753  PrintS("DELETE!\n");
6754 #endif
6755  strat->nrsyzcrit++;
6756  //printf("- T -\n\n");
6757  return TRUE;
6758  }
6759  }
6760  //printf("- F -\n\n");
6761  return FALSE;
6762 }
6763 
6764 /*
6765  * SYZYGY CRITERION for signature-based standard basis algorithms
6766  */
6767 BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6768 {
6769 //#if 1
6770  if(sig == NULL)
6771  return FALSE;
6772 #ifdef DEBUGF5
6773  PrintS("--- syzygy criterion checks: ");
6774  pWrite(sig);
6775 #endif
6776  int comp = __p_GetComp(sig, currRing);
6777  int min, max;
6778  if (comp<=1)
6779  return FALSE;
6780  else
6781  {
6782  min = strat->syzIdx[comp-2];
6783  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
6784  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
6785  //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
6786  if (comp == strat->currIdx)
6787  {
6788  max = strat->syzl;
6789  }
6790  else
6791  {
6792  max = strat->syzIdx[comp-1];
6793  }
6794  for (int k=min; k<max; k++)
6795  {
6796 #ifdef F5DEBUG
6797  Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
6798  Print("checking with: %d -- ",k);
6799  pWrite(pHead(strat->syz[k]));
6800 #endif
6801  if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6802  && (!rField_is_Ring(currRing) ||
6803  (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6804  {
6805  strat->nrsyzcrit++;
6806  return TRUE;
6807  }
6808  }
6809  return FALSE;
6810  }
6811 }
6812 
6813 /*
6814  * REWRITTEN CRITERION for signature-based standard basis algorithms
6815  */
6816 BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
6817 {
6818  //printf("Faugere Rewritten Criterion\n");
6820  return FALSE;
6821 //#if 1
6822 #ifdef DEBUGF5
6823  PrintS("rewritten criterion checks: ");
6824  pWrite(sig);
6825 #endif
6826  for(int k = strat->sl; k>=start; k--)
6827  {
6828 //#if 1
6829 #ifdef DEBUGF5
6830  PrintS("checking with: ");
6831  pWrite(strat->sig[k]);
6832  pWrite(pHead(strat->S[k]));
6833 #endif
6834  if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
6835  {
6836 //#if 1
6837 #ifdef DEBUGF5
6838  PrintS("DELETE!\n");
6839 #endif
6840  strat->nrrewcrit++;
6841  return TRUE;
6842  }
6843  //k--;
6844  }
6845 #ifdef DEBUGF5
6846  PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
6847  for(int kk = 0; kk<strat->sl+1; kk++)
6848  {
6849  pWrite(pHead(strat->S[kk]));
6850  }
6851  PrintS("------------------------------\n");
6852 #endif
6853  return FALSE;
6854 }
6855 
6856 /*
6857  * REWRITTEN CRITERION for signature-based standard basis algorithms
6858  ***************************************************************************
6859  * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
6860  ***************************************************************************
6861  */
6862 
6863 // real implementation of arri's rewritten criterion, only called once in
6864 // kstd2.cc, right before starting reduction
6865 // IDEA: Arri says that it is enough to consider 1 polynomial for each unique
6866 // signature appearing during the computations. Thus we first of all go
6867 // through strat->L and delete all other pairs of the same signature,
6868 // keeping only the one with least possible leading monomial. After this
6869 // we check if we really need to compute this critical pair at all: There
6870 // can be elements already in strat->S whose signatures divide the
6871 // signature of the critical pair in question and whose multiplied
6872 // leading monomials are smaller than the leading monomial of the
6873 // critical pair. In this situation we can discard the critical pair
6874 // completely.
6875 BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
6876 {
6878  return FALSE;
6879  poly p1 = pOne();
6880  poly p2 = pOne();
6881  for (int ii=strat->sl; ii>start; ii--)
6882  {
6883  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
6884  {
6885  p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
6886  p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
6887  if (!(pLmCmp(p1,p2) == 1))
6888  {
6889  pDelete(&p1);
6890  pDelete(&p2);
6891  return TRUE;
6892  }
6893  }
6894  }
6895  pDelete(&p1);
6896  pDelete(&p2);
6897  return FALSE;
6898 }
6899 
6900 BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
6901 {
6902  //Over Rings, there are still some changes to do: considering coeffs
6904  return FALSE;
6905  int found = -1;
6906  for (int i=strat->Bl; i>-1; i--)
6907  {
6908  if (pLmEqual(strat->B[i].sig,sig))
6909  {
6910  found = i;
6911  break;
6912  }
6913  }
6914  if (found != -1)
6915  {
6916  if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
6917  {
6918  deleteInL(strat->B,&strat->Bl,found,strat);
6919  }
6920  else
6921  {
6922  return TRUE;
6923  }
6924  }
6925  poly p1 = pOne();
6926  poly p2 = pOne();
6927  for (int ii=strat->sl; ii>-1; ii--)
6928  {
6929  if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
6930  {
6931  p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
6932  p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
6933  if (!(pLmCmp(p1,p2) == 1))
6934  {
6935  pDelete(&p1);
6936  pDelete(&p2);
6937  return TRUE;
6938  }
6939  }
6940  }
6941  pDelete(&p1);
6942  pDelete(&p2);
6943  return FALSE;
6944 }
6945 
6946 /***************************************************************
6947  *
6948  * Tail reductions
6949  *
6950  ***************************************************************/
6951 TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
6952 {
6953  int j = 0;
6954  const unsigned long not_sev = ~L->sev;
6955  const unsigned long* sev = strat->sevS;
6956  poly p;
6957  ring r;
6958  L->GetLm(p, r);
6959 
6960  assume(~not_sev == p_GetShortExpVector(p, r));
6961 
6962  if (r == currRing)
6963  {
6964  if(!rField_is_Ring(r))
6965  {
6966  loop
6967  {
6968  if (j > end_pos) return NULL;
6969  #if defined(PDEBUG) || defined(PDIV_DEBUG)
6970  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
6971  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6972  {
6973  break;
6974  }
6975  #else
6976  if (!(sev[j] & not_sev) &&
6977  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
6978  p_LmDivisibleBy(strat->S[j], p, r))
6979  {
6980  break;
6981  }
6982  #endif
6983  j++;
6984  }
6985  }
6986  #ifdef HAVE_RINGS
6987  else
6988  {
6989  loop
6990  {
6991  if (j > end_pos) return NULL;
6992  #if defined(PDEBUG) || defined(PDIV_DEBUG)
6993  if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
6994  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6995  {
6996  break;
6997  }
6998  #else
6999  if (!(sev[j] & not_sev) &&
7000  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7001  p_LmDivisibleBy(strat->S[j], p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7002  {
7003  break;
7004  }
7005  #endif
7006  j++;
7007  }
7008  }
7009  #endif
7010  // if called from NF, T objects do not exist:
7011  if (strat->tl < 0 || strat->S_2_R[j] == -1)
7012  {
7013  T->Set(strat->S[j], r, strat->tailRing);
7014  assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
7015  return T;
7016  }
7017  else
7018  {
7019 ///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
7020 ///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
7021 // assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
7022  return strat->S_2_T(j);
7023  }
7024  }
7025  else
7026  {
7027  TObject* t;
7028  if(!rField_is_Ring(r))
7029  {
7030  loop
7031  {
7032  if (j > end_pos) return NULL;
7033  assume(strat->S_2_R[j] != -1);
7034  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7035  t = strat->S_2_T(j);
7036  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7037  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7038  (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7039  {
7040  t->pLength=pLength(t->t_p);
7041  return t;
7042  }
7043  #else
7044  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7045  {
7046  t = strat->S_2_T(j);
7047  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7048  if (p_LmDivisibleBy(t->t_p, p, r))
7049  {
7050  t->pLength=pLength(t->t_p);
7051  return t;
7052  }
7053  }
7054  #endif
7055  j++;
7056  }
7057  }
7058  #ifdef HAVE_RINGS
7059  else
7060  {
7061  loop
7062  {
7063  if (j > end_pos) return NULL;
7064  assume(strat->S_2_R[j] != -1);
7065  #if defined(PDEBUG) || defined(PDIV_DEBUG)
7066  t = strat->S_2_T(j);
7067  assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7068  if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7069  (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7070  {
7071  t->pLength=pLength(t->t_p);
7072  return t;
7073  }
7074  #else
7075  if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7076  {
7077  t = strat->S_2_T(j);
7078  assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7079  if (p_LmDivisibleBy(t->t_p, p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7080  {
7081  t->pLength=pLength(t->t_p);
7082  return t;
7083  }
7084  }
7085  #endif
7086  j++;
7087  }
7088  }
7089  #endif
7090  }
7091 }
7092 
7093 poly redtail (LObject* L, int end_pos, kStrategy strat)
7094 {
7095  poly h, hn;
7096  strat->redTailChange=FALSE;
7097 
7098  L->GetP();
7099  poly p = L->p;
7100  if (strat->noTailReduction || pNext(p) == NULL)
7101  return p;
7102 
7103  LObject Ln(strat->tailRing);
7104  TObject* With;
7105  // placeholder in case strat->tl < 0
7106  TObject With_s(strat->tailRing);
7107  h = p;
7108  hn = pNext(h);
7109  long op = strat->tailRing->pFDeg(hn, strat->tailRing);
7110  long e;
7111  int l;
7112  BOOLEAN save_HE=strat->kAllAxis;
7113  strat->kAllAxis |=
7114  ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
7115 
7116  while(hn != NULL)
7117  {
7118  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7119  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7120  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7121  loop
7122  {
7123  Ln.Set(hn, strat->tailRing);
7124  Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
7125  if (strat->kAllAxis)
7126  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7127  else
7128  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
7129  if (With == NULL) break;
7130  With->length=0;
7131  With->pLength=0;
7132  strat->redTailChange=TRUE;
7133  if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
7134  {
7135  // reducing the tail would violate the exp bound
7136  if (kStratChangeTailRing(strat, L))
7137  {
7138  strat->kAllAxis = save_HE;
7139  return redtail(L, end_pos, strat);
7140  }
7141  else
7142  return NULL;
7143  }
7144  hn = pNext(h);
7145  if (hn == NULL) goto all_done;
7146  op = strat->tailRing->pFDeg(hn, strat->tailRing);
7147  if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7148  e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7149  }
7150  h = hn;
7151  hn = pNext(h);
7152  }
7153 
7154  all_done:
7155  if (strat->redTailChange)
7156  {
7157  L->pLength = 0;
7158  }
7159  strat->kAllAxis = save_HE;
7160  return p;
7161 }
7162 
7163 poly redtail (poly p, int end_pos, kStrategy strat)
7164 {
7165  LObject L(p, currRing);
7166  return redtail(&L, end_pos, strat);
7167 }
7168 
7169 poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
7170 {
7171  strat->redTailChange=FALSE;
7172  if (strat->noTailReduction) return L->GetLmCurrRing();
7173  poly h, p;
7174  p = h = L->GetLmTailRing();
7175  if ((h==NULL) || (pNext(h)==NULL))
7176  return L->GetLmCurrRing();
7177 
7178  TObject* With;
7179  // placeholder in case strat->tl < 0
7180  TObject With_s(strat->tailRing);
7181 
7182  LObject Ln(pNext(h), strat->tailRing);
7183  Ln.GetpLength();
7184 
7185  pNext(h) = NULL;
7186  if (L->p != NULL)
7187  {
7188  pNext(L->p) = NULL;
7189  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7190  }
7191  L->pLength = 1;
7192 
7193  Ln.PrepareRed(strat->use_buckets);
7194 
7195  int cnt=REDTAIL_CANONICALIZE;
7196  while(!Ln.IsNull())
7197  {
7198  loop
7199  {
7200  if (TEST_OPT_IDLIFT)
7201  {
7202  if (Ln.p!=NULL)
7203  {
7204  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7205  }
7206  else
7207  {
7208  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7209  }
7210  }
7211  Ln.SetShortExpVector();
7212  if (withT)
7213  {
7214  int j;
7215  j = kFindDivisibleByInT(strat, &Ln);
7216  if (j < 0) break;
7217  With = &(strat->T[j]);
7218  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7219  }
7220  else
7221  {
7222  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7223  if (With == NULL) break;
7224  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7225  }
7226  cnt--;
7227  if (cnt==0)
7228  {
7230  /*poly tmp=*/Ln.CanonicalizeP();
7231  if (normalize)
7232  {
7233  Ln.Normalize();
7234  //pNormalize(tmp);
7235  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7236  }
7237  }
7238  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7239  {
7240  With->pNorm();
7241  }
7242  strat->redTailChange=TRUE;
7243  if (ksReducePolyTail(L, With, &Ln))
7244  {
7245  // reducing the tail would violate the exp bound
7246  // set a flag and hope for a retry (in bba)
7247  strat->completeReduce_retry=TRUE;
7248  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7249  do
7250  {
7251  pNext(h) = Ln.LmExtractAndIter();
7252  pIter(h);
7253  L->pLength++;
7254  } while (!Ln.IsNull());
7255  goto all_done;
7256  }
7257  if (Ln.IsNull()) goto all_done;
7258  if (! withT) With_s.Init(currRing);
7259  }
7260  pNext(h) = Ln.LmExtractAndIter();
7261  pIter(h);
7262  pNormalize(h);
7263  L->pLength++;
7264  }
7265 
7266  all_done:
7267  Ln.Delete();
7268  if (L->p != NULL) pNext(L->p) = pNext(p);
7269 
7270  if (strat->redTailChange)
7271  {
7272  L->length = 0;
7273  L->pLength = 0;
7274  }
7275 
7276  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7277  //L->Normalize(); // HANNES: should have a test
7278  kTest_L(L,strat);
7279  return L->GetLmCurrRing();
7280 }
7281 
7282 poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7283 {
7284  strat->redTailChange=FALSE;
7285  if (strat->noTailReduction) return L->GetLmCurrRing();
7286  poly h, p;
7287  p = h = L->GetLmTailRing();
7288  if ((h==NULL) || (pNext(h)==NULL))
7289  return L->GetLmCurrRing();
7290 
7291  TObject* With;
7292  // placeholder in case strat->tl < 0
7293  TObject With_s(strat->tailRing);
7294 
7295  LObject Ln(pNext(h), strat->tailRing);
7296  Ln.pLength = L->GetpLength() - 1;
7297 
7298  pNext(h) = NULL;
7299  if (L->p != NULL) pNext(L->p) = NULL;
7300  L->pLength = 1;
7301 
7302  Ln.PrepareRed(strat->use_buckets);
7303 
7304  int cnt=REDTAIL_CANONICALIZE;
7305  while(!Ln.IsNull())
7306  {
7307  loop
7308  {
7309  if (TEST_OPT_IDLIFT)
7310  {
7311  if (Ln.p!=NULL)
7312  {
7313  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7314  }
7315  else
7316  {
7317  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7318  }
7319  }
7320  Ln.SetShortExpVector();
7321  if (withT)
7322  {
7323  int j;
7324  j = kFindDivisibleByInT(strat, &Ln);
7325  if (j < 0) break;
7326  With = &(strat->T[j]);
7327  }
7328  else
7329  {
7330  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7331  if (With == NULL) break;
7332  }
7333  cnt--;
7334  if (cnt==0)
7335  {
7337  /*poly tmp=*/Ln.CanonicalizeP();
7338  if (normalize)
7339  {
7340  Ln.Normalize();
7341  //pNormalize(tmp);
7342  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7343  }
7344  }
7345  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7346  {
7347  With->pNorm();
7348  }
7349  strat->redTailChange=TRUE;
7350  if (ksReducePolyTail(L, With, &Ln))
7351  {
7352  // reducing the tail would violate the exp bound
7353  // set a flag and hope for a retry (in bba)
7354  strat->completeReduce_retry=TRUE;
7355  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7356  do
7357  {
7358  pNext(h) = Ln.LmExtractAndIter();
7359  pIter(h);
7360  L->pLength++;
7361  } while (!Ln.IsNull());
7362  goto all_done;
7363  }
7364  if(!Ln.IsNull())
7365  {
7366  Ln.GetP();
7367  Ln.p = pJet(Ln.p,bound);
7368  }
7369  if (Ln.IsNull())
7370  {
7371  goto all_done;
7372  }
7373  if (! withT) With_s.Init(currRing);
7374  }
7375  pNext(h) = Ln.LmExtractAndIter();
7376  pIter(h);
7377  pNormalize(h);
7378  L->pLength++;
7379  }
7380 
7381  all_done:
7382  Ln.Delete();
7383  if (L->p != NULL) pNext(L->p) = pNext(p);
7384 
7385  if (strat->redTailChange)
7386  {
7387  L->length = 0;
7388  L->pLength = 0;
7389  }
7390 
7391  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7392  //L->Normalize(); // HANNES: should have a test
7393  kTest_L(L,strat);
7394  return L->GetLmCurrRing();
7395 }
7396 
7397 #ifdef HAVE_RINGS
7398 void redtailBbaAlsoLC_Z (LObject* L, int end_pos, kStrategy strat )
7399 // normalize=FALSE, withT=FALSE, coeff=Z
7400 {
7401  strat->redTailChange=FALSE;
7402 
7403  poly h, p;
7404  p = h = L->GetLmTailRing();
7405  if ((h==NULL) || (pNext(h)==NULL))
7406  return;
7407 
7408  TObject* With;
7409  LObject Ln(pNext(h), strat->tailRing);
7410  Ln.GetpLength();
7411 
7412  pNext(h) = NULL;
7413  if (L->p != NULL)
7414  {
7415  pNext(L->p) = NULL;
7416  if (L->t_p != NULL) pNext(L->t_p) = NULL;
7417  }
7418  L->pLength = 1;
7419 
7420  Ln.PrepareRed(strat->use_buckets);
7421 
7422  int cnt=REDTAIL_CANONICALIZE;
7423 
7424  while(!Ln.IsNull())
7425  {
7426  loop
7427  {
7428  if (TEST_OPT_IDLIFT)
7429  {
7430  if (Ln.p!=NULL)
7431  {
7432  if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7433  }
7434  else
7435  {
7436  if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7437  }
7438  }
7439  Ln.SetShortExpVector();
7440  int j;
7441  j = kFindDivisibleByInT(strat, &Ln);
7442  if (j < 0)
7443  {
7444  j = kFindDivisibleByInT_Z(strat, &Ln);
7445  if (j < 0)
7446  {
7447  break;
7448  }
7449  else
7450  {
7451  /* reduction not cancelling a tail term, but reducing its coefficient */
7452  With = &(strat->T[j]);
7453  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7454  cnt--;
7455  if (cnt==0)
7456  {
7458  /*poly tmp=*/Ln.CanonicalizeP();
7459  }
7460  strat->redTailChange=TRUE;
7461  /* reduction cancelling a tail term */
7462  if (ksReducePolyTailLC_Z(L, With, &Ln))
7463  {
7464  // reducing the tail would violate the exp bound
7465  // set a flag and hope for a retry (in bba)
7466  strat->completeReduce_retry=TRUE;
7467  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7468  do
7469  {
7470  pNext(h) = Ln.LmExtractAndIter();
7471  pIter(h);
7472  L->pLength++;
7473  } while (!Ln.IsNull());
7474  goto all_done;
7475  }
7476  /* we have to break since we did not cancel the term, but only decreased
7477  * its coefficient. */
7478  break;
7479  }
7480  } else {
7481  With = &(strat->T[j]);
7482  assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7483  cnt--;
7484  if (cnt==0)
7485  {
7487  /*poly tmp=*/Ln.CanonicalizeP();
7488  }
7489  strat->redTailChange=TRUE;
7490  /* reduction cancelling a tail term */
7491  if (ksReducePolyTail_Z(L, With, &Ln))
7492  {
7493  // reducing the tail would violate the exp bound
7494  // set a flag and hope for a retry (in bba)
7495  strat->completeReduce_retry=TRUE;
7496  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7497  do
7498  {
7499  pNext(h) = Ln.LmExtractAndIter();
7500  pIter(h);
7501  L->pLength++;
7502  } while (!Ln.IsNull());
7503  goto all_done;
7504  }
7505  }
7506  if (Ln.IsNull()) goto all_done;
7507  }
7508  pNext(h) = Ln.LmExtractAndIter();
7509  pIter(h);
7510  L->pLength++;
7511  }
7512 
7513  all_done:
7514  Ln.Delete();
7515  if (L->p != NULL) pNext(L->p) = pNext(p);
7516 
7517  if (strat->redTailChange)
7518  {
7519  L->length = 0;
7520  L->pLength = 0;
7521  }
7522 
7523  kTest_L(L, strat);
7524  return;
7525 }
7526 
7527 poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7528 // normalize=FALSE, withT=FALSE, coeff=Z
7529 {
7530  strat->redTailChange=FALSE;
7531  if (strat->noTailReduction) return L->GetLmCurrRing();
7532  poly h, p;
7533  p = h = L->GetLmTailRing();
7534  if ((h==NULL) || (pNext(h)==NULL))
7535  return L->GetLmCurrRing();
7536 
7537  TObject* With;
7538  // placeholder in case strat->tl < 0
7539  TObject With_s(strat->tailRing);
7540 
7541  LObject Ln(pNext(h), strat->tailRing);
7542  Ln.pLength = L->GetpLength() - 1;
7543 
7544  pNext(h) = NULL;
7545  if (L->p != NULL) pNext(L->p) = NULL;
7546  L->pLength = 1;
7547 
7548  Ln.PrepareRed(strat->use_buckets);
7549 
7550  int cnt=REDTAIL_CANONICALIZE;
7551  while(!Ln.IsNull())
7552  {
7553  loop
7554  {
7555  Ln.SetShortExpVector();
7556  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7557  if (With == NULL) break;
7558  cnt--;
7559  if (cnt==0)
7560  {
7562  /*poly tmp=*/Ln.CanonicalizeP();
7563  }
7564  // we are in Z, do not call pNorm
7565  strat->redTailChange=TRUE;
7566  // test divisibility of coefs:
7567  poly p_Ln=Ln.GetLmCurrRing();
7568  poly p_With=With->GetLmCurrRing();
7569  number z=n_IntMod(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf);
7570  if (!nIsZero(z))
7571  {
7572  // subtract z*Ln, add z.Ln to L
7573  poly m=pHead(p_Ln);
7574  pSetCoeff(m,z);
7575  poly mm=pHead(m);
7576  pNext(h) = m;
7577  pIter(h);
7578  L->pLength++;
7579  mm=pNeg(mm);
7580  if (Ln.bucket!=NULL)
7581  {
7582  int dummy=1;
7583  kBucket_Add_q(Ln.bucket,mm,&dummy);
7584  }
7585  else
7586  {
7587  if ((Ln.t_p!=NULL)&&(Ln.p==NULL))
7588  Ln.GetP();
7589  if (Ln.p!=NULL)
7590  {
7591  Ln.p=pAdd(Ln.p,mm);
7592  if (Ln.t_p!=NULL)
7593  {
7594  pNext(Ln.t_p)=NULL;
7595  p_LmDelete(Ln.t_p,strat->tailRing);
7596  }
7597  }
7598  }
7599  }
7600  else
7601  nDelete(&z);
7602 
7603  if (ksReducePolyTail_Z(L, With, &Ln))
7604  {
7605  // reducing the tail would violate the exp bound
7606  // set a flag and hope for a retry (in bba)
7607  strat->completeReduce_retry=TRUE;
7608  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7609  do
7610  {
7611  pNext(h) = Ln.LmExtractAndIter();
7612  pIter(h);
7613  L->pLength++;
7614  } while (!Ln.IsNull());
7615  goto all_done;
7616  }
7617  if (Ln.IsNull()) goto all_done;
7618  With_s.Init(currRing);
7619  }
7620  pNext(h) = Ln.LmExtractAndIter();
7621  pIter(h);
7622  pNormalize(h);
7623  L->pLength++;
7624  }
7625 
7626  all_done:
7627  Ln.Delete();
7628  if (L->p != NULL) pNext(L->p) = pNext(p);
7629 
7630  if (strat->redTailChange)
7631  {
7632  L->length = 0;
7633  }
7634 
7635  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7636  //L->Normalize(); // HANNES: should have a test
7637  kTest_L(L,strat);
7638  return L->GetLmCurrRing();
7639 }
7640 
7641 poly redtailBba_Ring (LObject* L, int end_pos, kStrategy strat )
7642 // normalize=FALSE, withT=FALSE, coeff=Z
7643 {
7644  strat->redTailChange=FALSE;
7645  if (strat->noTailReduction) return L->GetLmCurrRing();
7646  poly h, p;
7647  p = h = L->GetLmTailRing();
7648  if ((h==NULL) || (pNext(h)==NULL))
7649  return L->GetLmCurrRing();
7650 
7651  TObject* With;
7652  // placeholder in case strat->tl < 0
7653  TObject With_s(strat->tailRing);
7654 
7655  LObject Ln(pNext(h), strat->tailRing);
7656  Ln.pLength = L->GetpLength() - 1;
7657 
7658  pNext(h) = NULL;
7659  if (L->p != NULL) pNext(L->p) = NULL;
7660  L->pLength = 1;
7661 
7662  Ln.PrepareRed(strat->use_buckets);
7663 
7664  int cnt=REDTAIL_CANONICALIZE;
7665  while(!Ln.IsNull())
7666  {
7667  loop
7668  {
7669  Ln.SetShortExpVector();
7670  With_s.Init(currRing);
7671  With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7672  if (With == NULL) break;
7673  cnt--;
7674  if (cnt==0)
7675  {
7677  /*poly tmp=*/Ln.CanonicalizeP();
7678  }
7679  // we are in a ring, do not call pNorm
7680  // test divisibility of coefs:
7681  poly p_Ln=Ln.GetLmCurrRing();
7682  poly p_With=With->GetLmCurrRing();
7683  if (n_DivBy(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf))
7684  {
7685  strat->redTailChange=TRUE;
7686 
7687  if (ksReducePolyTail_Z(L, With, &Ln))
7688  {
7689  // reducing the tail would violate the exp bound
7690  // set a flag and hope for a retry (in bba)
7691  strat->completeReduce_retry=TRUE;
7692  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7693  do
7694  {
7695  pNext(h) = Ln.LmExtractAndIter();
7696  pIter(h);
7697  L->pLength++;
7698  } while (!Ln.IsNull());
7699  goto all_done;
7700  }
7701  }
7702  else break; /*proceed to next monomial*/
7703  if (Ln.IsNull()) goto all_done;
7704  }
7705  pNext(h) = Ln.LmExtractAndIter();
7706  pIter(h);
7707  pNormalize(h);
7708  L->pLength++;
7709  }
7710 
7711  all_done:
7712  Ln.Delete();
7713  if (L->p != NULL) pNext(L->p) = pNext(p);
7714 
7715  if (strat->redTailChange)
7716  {
7717  L->length = 0;
7718  }
7719 
7720  //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7721  //L->Normalize(); // HANNES: should have a test
7722  kTest_L(L,strat);
7723  return L->GetLmCurrRing();
7724 }
7725 #endif
7726 
7727 /*2
7728 *checks the change degree and write progress report
7729 */
7730 void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7731 {
7732  if (i != *olddeg)
7733  {
7734  Print("%d",i);
7735  *olddeg = i;
7736  }
7737  if (TEST_OPT_OLDSTD)
7738  {
7739  if (strat->Ll != *reduc)
7740  {
7741  if (strat->Ll != *reduc-1)
7742  Print("(%d)",strat->Ll+1);
7743  else
7744  PrintS("-");
7745  *reduc = strat->Ll;
7746  }
7747  else
7748  PrintS(".");
7749  mflush();
7750  }
7751  else
7752  {
7753  if (red_result == 0)
7754  PrintS("-");
7755  else if (red_result < 0)
7756  PrintS(".");
7757  if ((red_result > 0) || ((strat->Ll % 100)==99))
7758  {
7759  if (strat->Ll != *reduc && strat->Ll > 0)
7760  {
7761  Print("(%d)",strat->Ll+1);
7762  *reduc = strat->Ll;
7763  }
7764  }
7765  }
7766 }
7767 
7768 /*2
7769 *statistics
7770 */
7771 void messageStat (int hilbcount,kStrategy strat)
7772 {
7773  //PrintS("\nUsage/Allocation of temporary storage:\n");
7774  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7775  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7776  Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7777  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7778  #ifdef HAVE_SHIFTBBA
7779  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7780  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7781  #endif
7782 }
7783 
7784 void messageStatSBA (int hilbcount,kStrategy strat)
7785 {
7786  //PrintS("\nUsage/Allocation of temporary storage:\n");
7787  //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7788  //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7789  Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7790  //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7791  if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7792  #ifdef HAVE_SHIFTBBA
7793  /* in usual case strat->cv is 0, it gets changed only in shift routines */
7794  if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7795  #endif
7796 }
7797 
7798 #ifdef KDEBUG
7799 /*2
7800 *debugging output: all internal sets, if changed
7801 *for testing purpuse only/has to be changed for later use
7802 */
7804 {
7805  int i;
7806  if (strat->news)
7807  {
7808  PrintS("set S");
7809  for (i=0; i<=strat->sl; i++)
7810  {
7811  Print("\n %d:",i);
7812  p_wrp(strat->S[i], currRing, strat->tailRing);
7813  if (strat->fromQ!=NULL && strat->fromQ[i])
7814  Print(" (from Q)");
7815  }
7816  strat->news = FALSE;
7817  }
7818  if (strat->newt)
7819  {
7820  PrintS("\nset T");
7821  for (i=0; i<=strat->tl; i++)
7822  {
7823  Print("\n %d:",i);
7824  strat->T[i].wrp();
7825  if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7826  Print(" o:%ld e:%d l:%d",
7827  strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7828  }
7829  strat->newt = FALSE;
7830  }
7831  PrintS("\nset L");
7832  for (i=strat->Ll; i>=0; i--)
7833  {
7834  Print("\n%d:",i);
7835  p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7836  PrintS(" ");
7837  p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7838  PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7839  PrintS("\n p : ");
7840  strat->L[i].wrp();
7841  Print(" o:%ld e:%d l:%d",
7842  strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7843  }
7844  PrintLn();
7845 }
7846 
7847 #endif
7848 
7849 
7850 /*2
7851 *construct the set s from F
7852 */
7853 void initS (ideal F, ideal Q, kStrategy strat)
7854 {
7855  int i,pos;
7856 
7857  if (Q!=NULL) i=((IDELEMS(F)+IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7858  else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7859  strat->ecartS=initec(i);
7860  strat->sevS=initsevS(i);
7861  strat->S_2_R=initS_2_R(i);
7862  strat->fromQ=NULL;
7863  strat->Shdl=idInit(i,F->rank);
7864  strat->S=strat->Shdl->m;
7865  /*- put polys into S -*/
7866  if (Q!=NULL)
7867  {
7868  strat->fromQ=initec(i);
7869  memset(strat->fromQ,0,i*sizeof(int));
7870  for (i=0; i<IDELEMS(Q); i++)
7871  {
7872  if (Q->m[i]!=NULL)
7873  {
7874  LObject h;
7875  h.p = pCopy(Q->m[i]);
7877  {
7878  h.pCleardenom(); // also does remove Content
7879  }
7880  else
7881  {
7882  h.pNorm();
7883  }
7885  {
7886  deleteHC(&h, strat);
7887  }
7888  if (h.p!=NULL)
7889  {
7890  strat->initEcart(&h);
7891  if (strat->sl==-1)
7892  pos =0;
7893  else
7894  {
7895  pos = posInS(strat,strat->sl,h.p,h.ecart);
7896  }
7897  h.sev = pGetShortExpVector(h.p);
7898  strat->enterS(h,pos,strat,-1);
7899  strat->fromQ[pos]=1;
7900  }
7901  }
7902  }
7903  }
7904  for (i=0; i<IDELEMS(F); i++)
7905  {
7906  if (F->m[i]!=NULL)
7907  {
7908  LObject h;
7909  h.p = pCopy(F->m[i]);
7911  {
7912  cancelunit(&h); /*- tries to cancel a unit -*/
7913  deleteHC(&h, strat);
7914  }
7915  if (h.p!=NULL)
7916  // do not rely on the input being a SB!
7917  {
7919  {
7920  h.pCleardenom(); // also does remove Content
7921  }
7922  else
7923  {
7924  h.pNorm();
7925  }
7926  strat->initEcart(&h);
7927  if (strat->sl==-1)
7928  pos =0;
7929  else
7930  pos = posInS(strat,strat->sl,h.p,h.ecart);
7931  h.sev = pGetShortExpVector(h.p);
7932  strat->enterS(h,pos,strat,-1);
7933  }
7934  }
7935  }
7936  /*- test, if a unit is in F -*/
7937  if ((strat->sl>=0)
7938 #ifdef HAVE_RINGS
7939  && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7940 #endif
7941  && pIsConstant(strat->S[0]))
7942  {
7943  while (strat->sl>0) deleteInS(strat->sl,strat);
7944  }
7945 }
7946 
7947 void initSL (ideal F, ideal Q,kStrategy strat)
7948 {
7949  int i,pos;
7950 
7951  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7952  else i=setmaxT;
7953  strat->ecartS=initec(i);
7954  strat->sevS=initsevS(i);
7955  strat->S_2_R=initS_2_R(i);
7956  strat->fromQ=NULL;
7957  strat->Shdl=idInit(i,F->rank);
7958  strat->S=strat->Shdl->m;
7959  /*- put polys into S -*/
7960  if (Q!=NULL)
7961  {
7962  strat->fromQ=initec(i);
7963  memset(strat->fromQ,0,i*sizeof(int));
7964  for (i=0; i<IDELEMS(Q); i++)
7965  {
7966  if (Q->m[i]!=NULL)
7967  {
7968  LObject h;
7969  h.p = pCopy(Q->m[i]);
7971  {
7972  deleteHC(&h,strat);
7973  }
7975  {
7976  h.pCleardenom(); // also does remove Content
7977  }
7978  else
7979  {
7980  h.pNorm();
7981  }
7982  if (h.p!=NULL)
7983  {
7984  strat->initEcart(&h);
7985  if (strat->sl==-1)
7986  pos =0;
7987  else
7988  {
7989  pos = posInS(strat,strat->sl,h.p,h.ecart);
7990  }
7991  h.sev = pGetShortExpVector(h.p);
7992  strat->enterS(h,pos,strat,-1);
7993  strat->fromQ[pos]=1;
7994  }
7995  }
7996  }
7997  }
7998  for (i=0; i<IDELEMS(F); i++)
7999  {
8000  if (F->m[i]!=NULL)
8001  {
8002  LObject h;
8003  h.p = pCopy(F->m[i]);
8004  if (h.p!=NULL)
8005  {
8007  {
8008  cancelunit(&h); /*- tries to cancel a unit -*/
8009  deleteHC(&h, strat);
8010  }
8011  if (h.p!=NULL)
8012  {
8014  {
8015  h.pCleardenom(); // also does remove Content
8016  }
8017  else
8018  {
8019  h.pNorm();
8020  }
8021  strat->initEcart(&h);
8022  if (strat->Ll==-1)
8023  pos =0;
8024  else
8025  pos = strat->posInL(strat->L,strat->Ll,&h,strat);
8026  h.sev = pGetShortExpVector(h.p);
8027  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8028  }
8029  }
8030  }
8031  }
8032  /*- test, if a unit is in F -*/
8033 
8034  if ((strat->Ll>=0)
8035 #ifdef HAVE_RINGS
8036  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8037 #endif
8038  && pIsConstant(strat->L[strat->Ll].p))
8039  {
8040  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8041  }
8042 }
8043 
8044 void initSLSba (ideal F, ideal Q,kStrategy strat)
8045 {
8046  int i,pos;
8047  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8048  else i=setmaxT;
8049  strat->ecartS = initec(i);
8050  strat->sevS = initsevS(i);
8051  strat->sevSig = initsevS(i);
8052  strat->S_2_R = initS_2_R(i);
8053  strat->fromQ = NULL;
8054  strat->Shdl = idInit(i,F->rank);
8055  strat->S = strat->Shdl->m;
8056  strat->sig = (poly *)omAlloc0(i*sizeof(poly));
8057  if (strat->sbaOrder != 1)
8058  {
8059  strat->syz = (poly *)omAlloc0(i*sizeof(poly));
8060  strat->sevSyz = initsevS(i);
8061  strat->syzmax = i;
8062  strat->syzl = 0;
8063  }
8064  /*- put polys into S -*/
8065  if (Q!=NULL)
8066  {
8067  strat->fromQ=initec(i);
8068  memset(strat->fromQ,0,i*sizeof(int));
8069  for (i=0; i<IDELEMS(Q); i++)
8070  {
8071  if (Q->m[i]!=NULL)
8072  {
8073  LObject h;
8074  h.p = pCopy(Q->m[i]);
8076  {
8077  deleteHC(&h,strat);
8078  }
8080  {
8081  h.pCleardenom(); // also does remove Content
8082  }
8083  else
8084  {
8085  h.pNorm();
8086  }
8087  if (h.p!=NULL)
8088  {
8089  strat->initEcart(&h);
8090  if (strat->sl==-1)
8091  pos =0;
8092  else
8093  {
8094  pos = posInS(strat,strat->sl,h.p,h.ecart);
8095  }
8096  h.sev = pGetShortExpVector(h.p);
8097  strat->enterS(h,pos,strat,-1);
8098  strat->fromQ[pos]=1;
8099  }
8100  }
8101  }
8102  }
8103  for (i=0; i<IDELEMS(F); i++)
8104  {
8105  if (F->m[i]!=NULL)
8106  {
8107  LObject h;
8108  h.p = pCopy(F->m[i]);
8109  h.sig = pOne();
8110  //h.sig = pInit();
8111  //p_SetCoeff(h.sig,nInit(1),currRing);
8112  p_SetComp(h.sig,i+1,currRing);
8113  // if we are working with the Schreyer order we generate it
8114  // by multiplying the initial signatures with the leading monomial
8115  // of the corresponding initial polynomials generating the ideal
8116  // => we can keep the underlying monomial order and get a Schreyer
8117  // order without any bigger overhead
8118  if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
8119  {
8120  p_ExpVectorAdd (h.sig,F->m[i],currRing);
8121  }
8122  h.sevSig = pGetShortExpVector(h.sig);
8123 #ifdef DEBUGF5
8124  pWrite(h.p);
8125  pWrite(h.sig);
8126 #endif
8127  if (h.p!=NULL)
8128  {
8130  {
8131  cancelunit(&h); /*- tries to cancel a unit -*/
8132  deleteHC(&h, strat);
8133  }
8134  if (h.p!=NULL)
8135  {
8137  {
8138  h.pCleardenom(); // also does remove Content
8139  }
8140  else
8141  {
8142  h.pNorm();
8143  }
8144  strat->initEcart(&h);
8145  if (strat->Ll==-1)
8146  pos =0;
8147  else
8148  pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
8149  h.sev = pGetShortExpVector(h.p);
8150  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8151  }
8152  }
8153  /*
8154  if (strat->sbaOrder != 1)
8155  {
8156  for(j=0;j<i;j++)
8157  {
8158  strat->syz[ctr] = pCopy(F->m[j]);
8159  p_SetCompP(strat->syz[ctr],i+1,currRing);
8160  // add LM(F->m[i]) to the signature to get a Schreyer order
8161  // without changing the underlying polynomial ring at all
8162  p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
8163  // since p_Add_q() destroys all input
8164  // data we need to recreate help
8165  // each time
8166  poly help = pCopy(F->m[i]);
8167  p_SetCompP(help,j+1,currRing);
8168  pWrite(strat->syz[ctr]);
8169  pWrite(help);
8170  printf("%d\n",pLmCmp(strat->syz[ctr],help));
8171  strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
8172  printf("%d. SYZ ",ctr);
8173  pWrite(strat->syz[ctr]);
8174  strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
8175  ctr++;
8176  }
8177  strat->syzl = ps;
8178  }
8179  */
8180  }
8181  }
8182  /*- test, if a unit is in F -*/
8183 
8184  if ((strat->Ll>=0)
8185 #ifdef HAVE_RINGS
8186  && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8187 #endif
8188  && pIsConstant(strat->L[strat->Ll].p))
8189  {
8190  while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8191  }
8192 }
8193 
8195 {
8196  if( strat->S[0] )
8197  {
8198  if( strat->S[1] && !rField_is_Ring(currRing))
8199  {
8200  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
8201  omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
8202  omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
8203  }
8204  int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
8205  /************************************************************
8206  * computing the length of the syzygy array needed
8207  ***********************************************************/
8208  for(i=1; i<=strat->sl; i++)
8209  {
8210  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8211  {
8212  ps += i;
8213  }
8214  }
8215  ps += strat->sl+1;
8216  //comp = pGetComp (strat->P.sig);
8217  comp = strat->currIdx;
8218  strat->syzIdx = initec(comp);
8219  strat->sevSyz = initsevS(ps);
8220  strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8221  strat->syzmax = ps;
8222  strat->syzl = 0;
8223  strat->syzidxmax = comp;
8224 #if defined(DEBUGF5) || defined(DEBUGF51)
8225  PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8226 #endif
8227  i = 1;
8228  j = 0;
8229  /************************************************************
8230  * generating the leading terms of the principal syzygies
8231  ***********************************************************/
8232  while (i <= strat->sl)
8233  {
8234  /**********************************************************
8235  * principal syzygies start with component index 2
8236  * the array syzIdx starts with index 0
8237  * => the rules for a signature with component comp start
8238  * at strat->syz[strat->syzIdx[comp-2]] !
8239  *********************************************************/
8240  if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8241  {
8242  comp = pGetComp(strat->sig[i]);
8243  comp_old = pGetComp(strat->sig[i-1]);
8244  diff = comp - comp_old - 1;
8245  // diff should be zero, but sometimes also the initial generating
8246  // elements of the input ideal reduce to zero. then there is an
8247  // index-gap between the signatures. for these inbetween signatures we
8248  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8249  // in the following.
8250  // doing this, we keep the relation "j = comp - 2" alive, which makes
8251  // jumps way easier when checking criteria
8252  while (diff>0)
8253  {
8254  strat->syzIdx[j] = 0;
8255  diff--;
8256  j++;
8257  }
8258  strat->syzIdx[j] = ctr;
8259  j++;
8260  LObject Q;
8261  int pos;
8262  for (k = 0; k<i; k++)
8263  {
8264  Q.sig = pOne();
8266  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8267  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8268  p_SetCompP (Q.sig, comp, currRing);
8269  poly q = p_One(currRing);
8272  p_ExpVectorCopy(q,strat->S[i],currRing);
8273  q = p_Neg (q, currRing);
8274  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8275  Q.sig = p_Add_q (Q.sig, q, currRing);
8276  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8277  pos = posInSyz(strat, Q.sig);
8278  enterSyz(Q, strat, pos);
8279  ctr++;
8280  }
8281  }
8282  i++;
8283  }
8284  /**************************************************************
8285  * add syzygies for upcoming first element of new iteration step
8286  **************************************************************/
8287  comp = strat->currIdx;
8288  comp_old = pGetComp(strat->sig[i-1]);
8289  diff = comp - comp_old - 1;
8290  // diff should be zero, but sometimes also the initial generating
8291  // elements of the input ideal reduce to zero. then there is an
8292  // index-gap between the signatures. for these inbetween signatures we
8293  // can safely set syzIdx[j] = 0 as no such element will be ever computed
8294  // in the following.
8295  // doing this, we keep the relation "j = comp - 2" alive, which makes
8296  // jumps way easier when checking criteria
8297  while (diff>0)
8298  {
8299  strat->syzIdx[j] = 0;
8300  diff--;
8301  j++;
8302  }
8303  strat->syzIdx[j] = ctr;
8304  LObject Q;
8305  int pos;
8306  for (k = 0; k<strat->sl+1; k++)
8307  {
8308  Q.sig = pOne();
8310  p_SetCoeff(Q.sig,nCopy(p_GetCoeff(strat->S[k],currRing)),currRing);
8311  p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8312  p_SetCompP (Q.sig, comp, currRing);
8313  poly q = p_One(currRing);
8315  p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8316  p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8317  q = p_Neg (q, currRing);
8318  p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8319  Q.sig = p_Add_q (Q.sig, q, currRing);
8320  Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8321  pos = posInSyz(strat, Q.sig);
8322  enterSyz(Q, strat, pos);
8323  ctr++;
8324  }
8325 //#if 1
8326 #ifdef DEBUGF5
8327  PrintS("Principal syzygies:\n");
8328  Print("syzl %d\n",strat->syzl);
8329  Print("syzmax %d\n",strat->syzmax);
8330  Print("ps %d\n",ps);
8331  PrintS("--------------------------------\n");
8332  for(i=0;i<=strat->syzl-1;i++)
8333  {
8334  Print("%d - ",i);
8335  pWrite(strat->syz[i]);
8336  }
8337  for(i=0;i<strat->currIdx;i++)
8338  {
8339  Print("%d - %d\n",i,strat->syzIdx[i]);
8340  }
8341  PrintS("--------------------------------\n");
8342 #endif
8343  }
8344 }
8345 
8346 /*2
8347 *construct the set s from F and {P}
8348 */
8349 void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8350 {
8351  int i,pos;
8352 
8353  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8354  else i=setmaxT;
8355  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8356  strat->ecartS=initec(i);
8357  strat->sevS=initsevS(i);
8358  strat->S_2_R=initS_2_R(i);
8359  strat->fromQ=NULL;
8360  strat->Shdl=idInit(i,F->rank);
8361  strat->S=strat->Shdl->m;
8362 
8363  /*- put polys into S -*/
8364  if (Q!=NULL)
8365  {
8366  strat->fromQ=initec(i);
8367  memset(strat->fromQ,0,i*sizeof(int));
8368  for (i=0; i<IDELEMS(Q); i++)
8369  {
8370  if (Q->m[i]!=NULL)
8371  {
8372  LObject h;
8373  h.p = pCopy(Q->m[i]);
8374  //if (TEST_OPT_INTSTRATEGY)
8375  //{
8376  // h.pCleardenom(); // also does remove Content
8377  //}
8378  //else
8379  //{
8380  // h.pNorm();
8381  //}
8383  {
8384  deleteHC(&h,strat);
8385  }
8386  if (h.p!=NULL)
8387  {
8388  strat->initEcart(&h);
8389  if (strat->sl==-1)
8390  pos =0;
8391  else
8392  {
8393  pos = posInS(strat,strat->sl,h.p,h.ecart);
8394  }
8395  h.sev = pGetShortExpVector(h.p);
8396  strat->enterS(h,pos,strat, strat->tl+1);
8397  enterT(h, strat);
8398  strat->fromQ[pos]=1;
8399  }
8400  }
8401  }
8402  }
8403  /*- put polys into S -*/
8404  for (i=0; i<IDELEMS(F); i++)
8405  {
8406  if (F->m[i]!=NULL)
8407  {
8408  LObject h;
8409  h.p = pCopy(F->m[i]);
8411  {
8412  deleteHC(&h,strat);
8413  }
8414  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8415  {
8416  h.p=redtailBba(h.p,strat->sl,strat);
8417  }
8418  if (h.p!=NULL)
8419  {
8420  strat->initEcart(&h);
8421  if (strat->sl==-1)
8422  pos =0;
8423  else
8424  pos = posInS(strat,strat->sl,h.p,h.ecart);
8425  h.sev = pGetShortExpVector(h.p);
8426  strat->enterS(h,pos,strat, strat->tl+1);
8427  enterT(h,strat);
8428  }
8429  }
8430  }
8431  for (i=0; i<IDELEMS(P); i++)
8432  {
8433  if (P->m[i]!=NULL)
8434  {
8435  LObject h;
8436  h.p=pCopy(P->m[i]);
8438  {
8439  h.pCleardenom();
8440  }
8441  else
8442  {
8443  h.pNorm();
8444  }
8445  if(strat->sl>=0)
8446  {
8448  {
8449  h.p=redBba(h.p,strat->sl,strat);
8450  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8451  {
8452  h.p=redtailBba(h.p,strat->sl,strat);
8453  }
8454  }
8455  else
8456  {
8457  h.p=redMora(h.p,strat->sl,strat);
8458  }
8459  if(h.p!=NULL)
8460  {
8461  strat->initEcart(&h);
8463  {
8464  h.pCleardenom();
8465  }
8466  else
8467  {
8468  h.is_normalized = 0;
8469  h.pNorm();
8470  }
8471  h.sev = pGetShortExpVector(h.p);
8472  h.SetpFDeg();
8473  pos = posInS(strat,strat->sl,h.p,h.ecart);
8474  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8475  strat->enterS(h,pos,strat, strat->tl+1);
8476  enterT(h,strat);
8477  }
8478  }
8479  else
8480  {
8481  h.sev = pGetShortExpVector(h.p);
8482  strat->initEcart(&h);
8483  strat->enterS(h,0,strat, strat->tl+1);
8484  enterT(h,strat);
8485  }
8486  }
8487  }
8488 }
8489 /*2
8490 *construct the set s from F and {P}
8491 */
8492 
8493 void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8494 {
8495  int i,pos;
8496 
8497  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
8498  else i=setmaxT;
8499  i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8500  strat->sevS=initsevS(i);
8501  strat->sevSig=initsevS(i);
8502  strat->S_2_R=initS_2_R(i);
8503  strat->fromQ=NULL;
8504  strat->Shdl=idInit(i,F->rank);
8505  strat->S=strat->Shdl->m;
8506  strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8507  /*- put polys into S -*/
8508  if (Q!=NULL)
8509  {
8510  strat->fromQ=initec(i);
8511  memset(strat->fromQ,0,i*sizeof(int));
8512  for (i=0; i<IDELEMS(Q); i++)
8513  {
8514  if (Q->m[i]!=NULL)
8515  {
8516  LObject h;
8517  h.p = pCopy(Q->m[i]);
8518  //if (TEST_OPT_INTSTRATEGY)
8519  //{
8520  // h.pCleardenom(); // also does remove Content
8521  //}
8522  //else
8523  //{
8524  // h.pNorm();
8525  //}
8527  {
8528  deleteHC(&h,strat);
8529  }
8530  if (h.p!=NULL)
8531  {
8532  strat->initEcart(&h);
8533  if (strat->sl==-1)
8534  pos =0;
8535  else
8536  {
8537  pos = posInS(strat,strat->sl,h.p,h.ecart);
8538  }
8539  h.sev = pGetShortExpVector(h.p);
8540  strat->enterS(h,pos,strat, strat->tl+1);
8541  enterT(h, strat);
8542  strat->fromQ[pos]=1;
8543  }
8544  }
8545  }
8546  }
8547  /*- put polys into S -*/
8548  for (i=0; i<IDELEMS(F); i++)
8549  {
8550  if (F->m[i]!=NULL)
8551  {
8552  LObject h;
8553  h.p = pCopy(F->m[i]);
8555  {
8556  deleteHC(&h,strat);
8557  }
8558  else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8559  {
8560  h.p=redtailBba(h.p,strat->sl,strat);
8561  }
8562  if (h.p!=NULL)
8563  {
8564  strat->initEcart(&h);
8565  if (strat->sl==-1)
8566  pos =0;
8567  else
8568  pos = posInS(strat,strat->sl,h.p,h.ecart);
8569  h.sev = pGetShortExpVector(h.p);
8570  strat->enterS(h,pos,strat, strat->tl+1);
8571  enterT(h,strat);
8572  }
8573  }
8574  }
8575  for (i=0; i<IDELEMS(P); i++)
8576  {
8577  if (P->m[i]!=NULL)
8578  {
8579  LObject h;
8580  h.p=pCopy(P->m[i]);
8582  {
8583  h.pCleardenom();
8584  }
8585  else
8586  {
8587  h.pNorm();
8588  }
8589  if(strat->sl>=0)
8590  {
8592  {
8593  h.p=redBba(h.p,strat->sl,strat);
8594  if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8595  {
8596  h.p=redtailBba(h.p,strat->sl,strat);
8597  }
8598  }
8599  else
8600  {
8601  h.p=redMora(h.p,strat->sl,strat);
8602  }
8603  if(h.p!=NULL)
8604  {
8605  strat->initEcart(&h);
8607  {
8608  h.pCleardenom();
8609  }
8610  else
8611  {
8612  h.is_normalized = 0;
8613  h.pNorm();
8614  }
8615  h.sev = pGetShortExpVector(h.p);
8616  h.SetpFDeg();
8617  pos = posInS(strat,strat->sl,h.p,h.ecart);
8618  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8619  strat->enterS(h,pos,strat, strat->tl+1);
8620  enterT(h,strat);
8621  }
8622  }
8623  else
8624  {
8625  h.sev = pGetShortExpVector(h.p);
8626  strat->initEcart(&h);
8627  strat->enterS(h,0,strat, strat->tl+1);
8628  enterT(h,strat);
8629  }
8630  }
8631  }
8632 }
8633 
8634 /*2
8635 * reduces h using the set S
8636 * procedure used in cancelunit1
8637 */
8638 static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8639 {
8640  int j = 0;
8641  unsigned long not_sev = ~ pGetShortExpVector(h);
8642 
8643  while (j <= maxIndex)
8644  {
8645  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8646  return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8647  else j++;
8648  }
8649  return h;
8650 }
8651 
8652 /*2
8653 *tests if p.p=monomial*unit and cancels the unit
8654 */
8655 void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8656 {
8657  int k;
8658  poly r,h,h1,q;
8659 
8660  if (!pIsVector((*p).p) && ((*p).ecart != 0))
8661  {
8662 #ifdef HAVE_RINGS
8663  // Leading coef have to be a unit: no
8664  // example 2x+4x2 should be simplified to 2x*(1+2x)
8665  // and 2 is not a unit in Z
8666  //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8667 #endif
8668  k = 0;
8669  h1 = r = pCopy((*p).p);
8670  h =pNext(r);
8671  loop
8672  {
8673  if (h==NULL)
8674  {
8675  pDelete(&r);
8676  pDelete(&(pNext((*p).p)));
8677  (*p).ecart = 0;
8678  (*p).length = 1;
8679  (*p).pLength = 1;
8680  (*suc)=0;
8681  return;
8682  }
8683  if (!pDivisibleBy(r,h))
8684  {
8685  q=redBba1(h,index ,strat);
8686  if (q != h)
8687  {
8688  k++;
8689  pDelete(&h);
8690  pNext(h1) = h = q;
8691  }
8692  else
8693  {
8694  pDelete(&r);
8695  return;
8696  }
8697  }
8698  else
8699  {
8700  h1 = h;
8701  pIter(h);
8702  }
8703  if (k > 10)
8704  {
8705  pDelete(&r);
8706  return;
8707  }
8708  }
8709  }
8710 }
8711 
8712 #if 0
8713 /*2
8714 * reduces h using the elements from Q in the set S
8715 * procedure used in updateS
8716 * must not be used for elements of Q or elements of an ideal !
8717 */
8718 static poly redQ (poly h, int j, kStrategy strat)
8719 {
8720  int start;
8721  unsigned long not_sev = ~ pGetShortExpVector(h);
8722  while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8723  start=j;
8724  while (j<=strat->sl)
8725  {
8726  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8727  {
8728  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8729  if (h==NULL) return NULL;
8730  j = start;
8731  not_sev = ~ pGetShortExpVector(h);
8732  }
8733  else j++;
8734  }
8735  return h;
8736 }
8737 #endif
8738 
8739 /*2
8740 * reduces h using the set S
8741 * procedure used in updateS
8742 */
8743 static poly redBba (poly h,int maxIndex,kStrategy strat)
8744 {
8745  int j = 0;
8746  unsigned long not_sev = ~ pGetShortExpVector(h);
8747 
8748  while (j <= maxIndex)
8749  {
8750  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8751  {
8752  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8753  if (h==NULL) return NULL;
8754  j = 0;
8755  not_sev = ~ pGetShortExpVector(h);
8756  }
8757  else j++;
8758  }
8759  return h;
8760 }
8761 
8762 /*2
8763 * reduces h using the set S
8764 *e is the ecart of h
8765 *procedure used in updateS
8766 */
8767 static poly redMora (poly h,int maxIndex,kStrategy strat)
8768 {
8769  int j=0;
8770  int e,l;
8771  unsigned long not_sev = ~ pGetShortExpVector(h);
8772 
8773  if (maxIndex >= 0)
8774  {
8775  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8776  do
8777  {
8778  if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8779  && ((e >= strat->ecartS[j]) || (strat->kNoether!=NULL)))
8780  {
8781 #ifdef KDEBUG
8782  if (TEST_OPT_DEBUG)
8783  {
8784  PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8785  }
8786 #endif
8787  h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8788 #ifdef KDEBUG
8789  if(TEST_OPT_DEBUG)
8790  {
8791  PrintS(")\nto "); wrp(h); PrintLn();
8792  }
8793 #endif
8794  // pDelete(&h);
8795  if (h == NULL) return NULL;
8796  e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8797  j = 0;
8798  not_sev = ~ pGetShortExpVector(h);
8799  }
8800  else j++;
8801  }
8802  while (j <= maxIndex);
8803  }
8804  return h;
8805 }
8806 
8807 /*2
8808 *updates S:
8809 *the result is a set of polynomials which are in
8810 *normalform with respect to S
8811 */
8812 void updateS(BOOLEAN toT,kStrategy strat)
8813 {
8814  LObject h;
8815  int i, suc=0;
8816  poly redSi=NULL;
8817  BOOLEAN change,any_change;
8818 // Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8819 // for (i=0; i<=(strat->sl); i++)
8820 // {
8821 // Print("s%d:",i);
8822 // if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8823 // pWrite(strat->S[i]);
8824 // }
8825 // Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8826  any_change=FALSE;
8828  {
8829  while (suc != -1)
8830  {
8831  i=suc+1;
8832  while (i<=strat->sl)
8833  {
8834  change=FALSE;
8836  any_change = FALSE;
8837  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8838  {
8839  redSi = pHead(strat->S[i]);
8840  strat->S[i] = redBba(strat->S[i],i-1,strat);
8841  //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8842  // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8843  if (pCmp(redSi,strat->S[i])!=0)
8844  {
8845  change=TRUE;
8846  any_change=TRUE;
8847  #ifdef KDEBUG
8848  if (TEST_OPT_DEBUG)
8849  {
8850  PrintS("reduce:");
8851  wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8852  }
8853  #endif
8854  if (TEST_OPT_PROT)
8855  {
8856  if (strat->S[i]==NULL)
8857  PrintS("V");
8858  else
8859  PrintS("v");
8860  mflush();
8861  }
8862  }
8863  pLmDelete(&redSi);
8864  if (strat->S[i]==NULL)
8865  {
8866  deleteInS(i,strat);
8867  i--;
8868  }
8869  else if (change)
8870  {
8872  {
8873  if (TEST_OPT_CONTENTSB)
8874  {
8875  number n;
8876  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8877  if (!nIsOne(n))
8878  {
8880  denom->n=nInvers(n);
8881  denom->next=DENOMINATOR_LIST;
8882  DENOMINATOR_LIST=denom;
8883  }
8884  nDelete(&n);
8885  }
8886  else
8887  {
8888  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8889  }
8890  }
8891  else
8892  {
8893  pNorm(strat->S[i]);
8894  }
8895  strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8896  }
8897  }
8898  i++;
8899  }
8900  if (any_change) reorderS(&suc,strat);
8901  else break;
8902  }
8903  if (toT)
8904  {
8905  for (i=0; i<=strat->sl; i++)
8906  {
8907  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8908  {
8909  h.p = redtailBba(strat->S[i],i-1,strat);
8911  {
8912  h.pCleardenom();// also does remove Content
8913  }
8914  }
8915  else
8916  {
8917  h.p = strat->S[i];
8918  }
8919  strat->initEcart(&h);
8920  if (strat->honey)
8921  {
8922  strat->ecartS[i] = h.ecart;
8923  }
8924  if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8925  else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8926  h.sev = strat->sevS[i];
8927  /*puts the elements of S also to T*/
8928  strat->initEcart(&h);
8929  /*if (toT) - already checked*/ enterT(h,strat);
8930  strat->S_2_R[i] = strat->tl;
8931 #ifdef HAVE_SHIFTBBA
8932  if (/*(toT) && */(currRing->isLPring))
8933  enterTShift(h, strat);
8934 #endif
8935  }
8936  }
8937  }
8938  else
8939  {
8940  while (suc != -1)
8941  {
8942  i=suc;
8943  while (i<=strat->sl)
8944  {
8945  change=FALSE;
8946  if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8947  {
8948  redSi=pHead((strat->S)[i]);
8949  (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
8950  if ((strat->S)[i]==NULL)
8951  {
8952  deleteInS(i,strat);
8953  i--;
8954  }
8955  else if (pCmp((strat->S)[i],redSi)!=0)
8956  {
8957  any_change=TRUE;
8958  h.p = strat->S[i];
8959  strat->initEcart(&h);
8960  strat->ecartS[i] = h.ecart;
8962  {
8963  if (TEST_OPT_CONTENTSB)
8964  {
8965  number n;
8966  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8967  if (!nIsOne(n))
8968  {
8970  denom->n=nInvers(n);
8971  denom->next=DENOMINATOR_LIST;
8972  DENOMINATOR_LIST=denom;
8973  }
8974  nDelete(&n);
8975  }
8976  else
8977  {
8978  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8979  }
8980  }
8981  else
8982  {
8983  pNorm(strat->S[i]); // == h.p
8984  }
8985  h.sev = pGetShortExpVector(h.p);
8986  strat->sevS[i] = h.sev;
8987  }
8988  pLmDelete(&redSi);
8989  kTest(strat);
8990  }
8991  i++;
8992  }
8993 #ifdef KDEBUG
8994  kTest(strat);
8995 #endif
8996  if (any_change) reorderS(&suc,strat);
8997  else { suc=-1; break; }
8998  if (h.p!=NULL)
8999  {
9000  if (!strat->kAllAxis)
9001  {
9002  /*strat->kAllAxis =*/ HEckeTest(h.p,strat);
9003  }
9004  if (strat->kAllAxis)
9005  newHEdge(strat);
9006  }
9007  }
9008  for (i=0; i<=strat->sl; i++)
9009  {
9010  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9011  {
9012  strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
9013  strat->initEcart(&h);
9014  strat->ecartS[i] = h.ecart;
9015  h.sev = pGetShortExpVector(h.p);
9016  strat->sevS[i] = h.sev;
9017  }
9018  else
9019  {
9020  h.p = strat->S[i];
9021  h.ecart=strat->ecartS[i];
9022  h.sev = strat->sevS[i];
9023  h.length = h.pLength = pLength(h.p);
9024  }
9025  if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9026  cancelunit1(&h,&suc,strat->sl,strat);
9027  h.SetpFDeg();
9028  /*puts the elements of S also to T*/
9029  enterT(h,strat);
9030  strat->S_2_R[i] = strat->tl;
9031 #ifdef HAVE_SHIFTBBA
9032  if (currRing->isLPring)
9033  enterTShift(h, strat);
9034 #endif
9035  }
9036  if (suc!= -1) updateS(toT,strat);
9037  }
9038 #ifdef KDEBUG
9039  kTest(strat);
9040 #endif
9041 }
9042 
9043 /*2
9044 * -puts p to the standardbasis s at position at
9045 * -saves the result in S
9046 */
9047 void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
9048 {
9049  strat->news = TRUE;
9050  /*- puts p to the standardbasis s at position at -*/
9051  if (strat->sl == IDELEMS(strat->Shdl)-1)
9052  {
9053  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9054  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9055  (IDELEMS(strat->Shdl)+setmaxTinc)
9056  *sizeof(unsigned long));
9057  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9058  IDELEMS(strat->Shdl)*sizeof(int),
9059  (IDELEMS(strat->Shdl)+setmaxTinc)
9060  *sizeof(int));
9061  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9062  IDELEMS(strat->Shdl)*sizeof(int),
9063  (IDELEMS(strat->Shdl)+setmaxTinc)
9064  *sizeof(int));
9065  if (strat->lenS!=NULL)
9066  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9067  IDELEMS(strat->Shdl)*sizeof(int),
9068  (IDELEMS(strat->Shdl)+setmaxTinc)
9069  *sizeof(int));
9070  if (strat->lenSw!=NULL)
9071  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9072  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9073  (IDELEMS(strat->Shdl)+setmaxTinc)
9074  *sizeof(wlen_type));
9075  if (strat->fromQ!=NULL)
9076  {
9077  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9078  IDELEMS(strat->Shdl)*sizeof(int),
9079  (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9080  }
9081  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
9082  IDELEMS(strat->Shdl)+=setmaxTinc;
9083  strat->Shdl->m=strat->S;
9084  }
9085  if (atS <= strat->sl)
9086  {
9087 #ifdef ENTER_USE_MEMMOVE
9088  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9089  (strat->sl - atS + 1)*sizeof(poly));
9090  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9091  (strat->sl - atS + 1)*sizeof(int));
9092  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9093  (strat->sl - atS + 1)*sizeof(unsigned long));
9094  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9095  (strat->sl - atS + 1)*sizeof(int));
9096  if (strat->lenS!=NULL)
9097  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9098  (strat->sl - atS + 1)*sizeof(int));
9099  if (strat->lenSw!=NULL)
9100  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9101  (strat->sl - atS + 1)*sizeof(wlen_type));
9102 #else
9103  for (i=strat->sl+1; i>=atS+1; i--)
9104  {
9105  strat->S[i] = strat->S[i-1];
9106  strat->ecartS[i] = strat->ecartS[i-1];
9107  strat->sevS[i] = strat->sevS[i-1];
9108  strat->S_2_R[i] = strat->S_2_R[i-1];
9109  }
9110  if (strat->lenS!=NULL)
9111  for (i=strat->sl+1; i>=atS+1; i--)
9112  strat->lenS[i] = strat->lenS[i-1];
9113  if (strat->lenSw!=NULL)
9114  for (i=strat->sl+1; i>=atS+1; i--)
9115  strat->lenSw[i] = strat->lenSw[i-1];
9116 #endif
9117  }
9118  if (strat->fromQ!=NULL)
9119  {
9120 #ifdef ENTER_USE_MEMMOVE
9121  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9122  (strat->sl - atS + 1)*sizeof(int));
9123 #else
9124  for (i=strat->sl+1; i>=atS+1; i--)
9125  {
9126  strat->fromQ[i] = strat->fromQ[i-1];
9127  }
9128 #endif
9129  strat->fromQ[atS]=0;
9130  }
9131 
9132  /*- save result -*/
9133  poly pp=p.p;
9134  strat->S[atS] = pp;
9135  if (strat->honey) strat->ecartS[atS] = p.ecart;
9136  if (p.sev == 0)
9137  p.sev = pGetShortExpVector(pp);
9138  else
9139  assume(p.sev == pGetShortExpVector(pp));
9140  strat->sevS[atS] = p.sev;
9141  strat->ecartS[atS] = p.ecart;
9142  strat->S_2_R[atS] = atR;
9143  strat->sl++;
9144 }
9145 
9146 #ifdef HAVE_SHIFTBBA
9147 void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR)
9148 {
9149  enterSBba(p, atS, strat, atR);
9150 
9151  int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
9152  for (int i = maxPossibleShift; i > 0; i--)
9153  {
9154  // NOTE: don't use "shared tails" here. In rare cases it can cause problems
9155  // in `kNF2` because of lazy poly normalizations.
9156  LObject qq(p_Copy(p.p, strat->tailRing));
9157  p_mLPshift(qq.p, i, strat->tailRing);
9158  qq.shift = i;
9159  strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
9160  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
9161  enterSBba(qq, atS, strat, -1);
9162  }
9163 }
9164 #endif
9165 
9166 /*2
9167 * -puts p to the standardbasis s at position at
9168 * -saves the result in S
9169 */
9170 void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
9171 {
9172  strat->news = TRUE;
9173  /*- puts p to the standardbasis s at position at -*/
9174  if (strat->sl == IDELEMS(strat->Shdl)-1)
9175  {
9176  strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9177  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9178  (IDELEMS(strat->Shdl)+setmax)
9179  *sizeof(unsigned long));
9180  strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
9181  IDELEMS(strat->Shdl)*sizeof(unsigned long),
9182  (IDELEMS(strat->Shdl)+setmax)
9183  *sizeof(unsigned long));
9184  strat->ecartS = (intset)omReallocSize(strat->ecartS,
9185  IDELEMS(strat->Shdl)*sizeof(int),
9186  (IDELEMS(strat->Shdl)+setmax)
9187  *sizeof(int));
9188  strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9189  IDELEMS(strat->Shdl)*sizeof(int),
9190  (IDELEMS(strat->Shdl)+setmax)
9191  *sizeof(int));
9192  if (strat->lenS!=NULL)
9193  strat->lenS=(int*)omRealloc0Size(strat->lenS,
9194  IDELEMS(strat->Shdl)*sizeof(int),
9195  (IDELEMS(strat->Shdl)+setmax)
9196  *sizeof(int));
9197  if (strat->lenSw!=NULL)
9198  strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9199  IDELEMS(strat->Shdl)*sizeof(wlen_type),
9200  (IDELEMS(strat->Shdl)+setmax)
9201  *sizeof(wlen_type));
9202  if (strat->fromQ!=NULL)
9203  {
9204  strat->fromQ = (intset)omReallocSize(strat->fromQ,
9205  IDELEMS(strat->Shdl)*sizeof(int),
9206  (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
9207  }
9208  pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
9209  pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
9210  IDELEMS(strat->Shdl)+=setmax;
9211  strat->Shdl->m=strat->S;
9212  }
9213  // in a signature-based algorithm the following situation will never
9214  // appear due to the fact that the critical pairs are already sorted
9215  // by increasing signature.
9216  // True. However, in the case of integers we need to put the element
9217  // that caused the signature drop on the first position
9218  if (atS <= strat->sl)
9219  {
9220 #ifdef ENTER_USE_MEMMOVE
9221  memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9222  (strat->sl - atS + 1)*sizeof(poly));
9223  memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9224  (strat->sl - atS + 1)*sizeof(poly));
9225  memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9226  (strat->sl - atS + 1)*sizeof(unsigned long));
9227  memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9228  (strat->sl - atS + 1)*sizeof(int));
9229  memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9230  (strat->sl - atS + 1)*sizeof(unsigned long));
9231  memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9232  (strat->sl - atS + 1)*sizeof(int));
9233  if (strat->lenS!=NULL)
9234  memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9235  (strat->sl - atS + 1)*sizeof(int));
9236  if (strat->lenSw!=NULL)
9237  memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9238  (strat->sl - atS + 1)*sizeof(wlen_type));
9239 #else
9240  for (i=strat->sl+1; i>=atS+1; i--)
9241  {
9242  strat->S[i] = strat->S[i-1];
9243  strat->ecartS[i] = strat->ecartS[i-1];
9244  strat->sevS[i] = strat->sevS[i-1];
9245  strat->S_2_R[i] = strat->S_2_R[i-1];
9246  strat->sig[i] = strat->sig[i-1];
9247  strat->sevSig[i] = strat->sevSig[i-1];
9248  }
9249  if (strat->lenS!=NULL)
9250  for (i=strat->sl+1; i>=atS+1; i--)
9251  strat->lenS[i] = strat->lenS[i-1];
9252  if (strat->lenSw!=NULL)
9253  for (i=strat->sl+1; i>=atS+1; i--)
9254  strat->lenSw[i] = strat->lenSw[i-1];
9255 #endif
9256  }
9257  if (strat->fromQ!=NULL)
9258  {
9259 #ifdef ENTER_USE_MEMMOVE
9260  memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9261  (strat->sl - atS + 1)*sizeof(int));
9262 #else
9263  for (i=strat->sl+1; i>=atS+1; i--)
9264  {
9265  strat->fromQ[i] = strat->fromQ[i-1];
9266  }
9267 #endif
9268  strat->fromQ[atS]=0;
9269  }
9270 
9271  /*- save result -*/
9272  strat->S[atS] = p.p;
9273  strat->sig[atS] = p.sig; // TODO: get ths correct signature in here!
9274  if (strat->honey) strat->ecartS[atS] = p.ecart;
9275  if (p.sev == 0)
9276  p.sev = pGetShortExpVector(p.p);
9277  else
9278  assume(p.sev == pGetShortExpVector(p.p));
9279  strat->sevS[atS] = p.sev;
9280  // during the interreduction process of a signature-based algorithm we do not
9281  // compute the signature at this point, but when the whole interreduction
9282  // process finishes, i.e. f5c terminates!
9283  if (p.sig != NULL)
9284  {
9285  if (p.sevSig == 0)
9286  p.sevSig = pGetShortExpVector(p.sig);
9287  else
9288  assume(p.sevSig == pGetShortExpVector(p.sig));
9289  strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9290  }
9291  strat->ecartS[atS] = p.ecart;
9292  strat->S_2_R[atS] = atR;
9293  strat->sl++;
9294 #ifdef DEBUGF5
9295  int k;
9296  Print("--- LIST S: %d ---\n",strat->sl);
9297  for(k=0;k<=strat->sl;k++)
9298  {
9299  pWrite(strat->sig[k]);
9300  }
9301  PrintS("--- LIST S END ---\n");
9302 #endif
9303 }
9304 
9305 void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
9306 {
9307  p.GetP(strat->lmBin);
9308  if (strat->homog) strat->initEcart(&p);
9309  strat->redTailChange=FALSE;
9311  {
9312  p.pCleardenom();
9314  {
9315 #ifdef HAVE_SHIFTBBA
9316  if (rIsLPRing(currRing))
9317  p.p = redtailBba(&p,strat->tl,strat, TRUE,!TEST_OPT_CONTENTSB);
9318  else
9319 #endif
9320  {
9321  p.p = redtailBba(&p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9322  }
9323  p.pCleardenom();
9324  if (strat->redTailChange)
9325  p.t_p=NULL;
9326  if (strat->P.p!=NULL) strat->P.sev=p_GetShortExpVector(strat->P.p,currRing);
9327  else strat->P.sev=0;
9328  }
9329  }
9330 
9331  assume(strat->tailRing == p.tailRing);
9332  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9333 
9334  int i, j, pos;
9335  poly tp = strat->T[tj].p;
9336 
9337  /* enter p to T set */
9338  enterT(p, strat);
9339 
9340  for (j = 0; j <= strat->sl; ++j)
9341  {
9342  if (pLtCmp(tp, strat->S[j]) == 0)
9343  {
9344  break;
9345  }
9346  }
9347  /* it may be that the exchanged element
9348  * is until now only in T and not in S */
9349  if (j <= strat->sl)
9350  {
9351  deleteInS(j, strat);
9352  }
9353 
9354  pos = posInS(strat, strat->sl, p.p, p.ecart);
9355 
9356  pp_Test(p.p, currRing, p.tailRing);
9357  assume(p.FDeg == p.pFDeg());
9358 
9359  /* remove useless pairs from L set */
9360  for (i = 0; i <= strat->Ll; ++i)
9361  {
9362  if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0)
9363  {
9364  deleteInL(strat->L, &(strat->Ll), i, strat);
9365  i--;
9366  continue;
9367  }
9368  if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0)
9369  {
9370  deleteInL(strat->L, &(strat->Ll), i, strat);
9371  i--;
9372  }
9373  }
9374 #ifdef HAVE_SHIFTBBA
9375  if (rIsLPRing(currRing))
9376  enterpairsShift(p.p, strat->sl, p.ecart, pos, strat, strat->tl); // TODO LP
9377  else
9378 #endif
9379  {
9380  /* generate new pairs with p, probably removing older, now useless pairs */
9381  superenterpairs(p.p, strat->sl, p.ecart, pos, strat, strat->tl);
9382  }
9383  /* enter p to S set */
9384  strat->enterS(p, pos, strat, strat->tl);
9385 
9386 #ifdef HAVE_SHIFTBBA
9387  /* do this after enterS so that the index in R (which is strat->tl) is correct */
9388  if (rIsLPRing(currRing) && !strat->rightGB)
9389  enterTShift(p,strat);
9390 #endif
9391 }
9392 
9393 /*2
9394 * puts p to the set T at position atT
9395 */
9396 void enterT(LObject &p, kStrategy strat, int atT)
9397 {
9398  int i;
9399 
9400 #ifdef PDEBUG
9401 #ifdef HAVE_SHIFTBBA
9402  if (currRing->isLPring && p.shift > 0)
9403  {
9404  // in this case, the order is not correct. test LM and tail separately
9405  p_LmTest(p.p, currRing);
9406  p_Test(pNext(p.p), currRing);
9407  }
9408  else
9409 #endif
9410  {
9411  pp_Test(p.p, currRing, p.tailRing);
9412  }
9413 #endif
9414  assume(strat->tailRing == p.tailRing);
9415  // redMoraNF complains about this -- but, we don't really
9416  // neeed this so far
9417  assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9418  assume(!strat->homog || (p.FDeg == p.pFDeg()));
9419  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9420 
9421 #ifdef KDEBUG
9422  // do not put an LObject twice into T:
9423  for(i=strat->tl;i>=0;i--)
9424  {
9425  if (p.p==strat->T[i].p)
9426  {
9427  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9428  return;
9429  }
9430  }
9431 #endif
9432 
9433 #ifdef HAVE_TAIL_RING
9434  if (currRing!=strat->tailRing)
9435  {
9436  p.t_p=p.GetLmTailRing();
9437  }
9438 #endif
9439  strat->newt = TRUE;
9440  if (atT < 0)
9441  atT = strat->posInT(strat->T, strat->tl, p);
9442  if (strat->tl == strat->tmax-1)
9443  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9444  if (atT <= strat->tl)
9445  {
9446 #ifdef ENTER_USE_MEMMOVE
9447  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9448  (strat->tl-atT+1)*sizeof(TObject));
9449  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9450  (strat->tl-atT+1)*sizeof(unsigned long));
9451 #endif
9452  for (i=strat->tl+1; i>=atT+1; i--)
9453  {
9454 #ifndef ENTER_USE_MEMMOVE
9455  strat->T[i] = strat->T[i-1];
9456  strat->sevT[i] = strat->sevT[i-1];
9457 #endif
9458  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9459  }
9460  }
9461 
9462  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9463  {
9464 #ifdef HAVE_SHIFTBBA
9465  // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9466  if (!(currRing->isLPring && p.shift > 0))
9467 #endif
9468  {
9470  (strat->tailRing != NULL ?
9471  strat->tailRing : currRing),
9472  strat->tailBin);
9473  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9474  }
9475  }
9476  strat->T[atT] = (TObject) p;
9477  //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9478 
9479  if (pNext(p.p) != NULL)
9480  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9481  else
9482  strat->T[atT].max_exp = NULL;
9483 
9484  strat->tl++;
9485  strat->R[strat->tl] = &(strat->T[atT]);
9486  strat->T[atT].i_r = strat->tl;
9487  assume((p.sev == 0) || (pGetShortExpVector(p.p) == p.sev));
9488  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9489  kTest_T(&(strat->T[atT]),strat);
9490 }
9491 
9492 /*2
9493 * puts p to the set T at position atT
9494 */
9495 #ifdef HAVE_RINGS
9496 void enterT_strong(LObject &p, kStrategy strat, int atT)
9497 {
9499  int i;
9500 
9501  pp_Test(p.p, currRing, p.tailRing);
9502  assume(strat->tailRing == p.tailRing);
9503  // redMoraNF complains about this -- but, we don't really
9504  // neeed this so far
9505  assume(p.pLength == 0 || (int)pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9506  assume(p.FDeg == p.pFDeg());
9507  assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9508 
9509 #ifdef KDEBUG
9510  // do not put an LObject twice into T:
9511  for(i=strat->tl;i>=0;i--)
9512  {
9513  if (p.p==strat->T[i].p)
9514  {
9515  printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9516  return;
9517  }
9518  }
9519 #endif
9520 
9521 #ifdef HAVE_TAIL_RING
9522  if (currRing!=strat->tailRing)
9523  {
9524  p.t_p=p.GetLmTailRing();
9525  }
9526 #endif
9527  strat->newt = TRUE;
9528  if (atT < 0)
9529  atT = strat->posInT(strat->T, strat->tl, p);
9530  if (strat->tl == strat->tmax-1)
9531  enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9532  if (atT <= strat->tl)
9533  {
9534 #ifdef ENTER_USE_MEMMOVE
9535  memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9536  (strat->tl-atT+1)*sizeof(TObject));
9537  memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9538  (strat->tl-atT+1)*sizeof(unsigned long));
9539 #endif
9540  for (i=strat->tl+1; i>=atT+1; i--)
9541  {
9542 #ifndef ENTER_USE_MEMMOVE
9543  strat->T[i] = strat->T[i-1];
9544  strat->sevT[i] = strat->sevT[i-1];
9545 #endif
9546  strat->R[strat->T[i].i_r] = &(strat->T[i]);
9547  }
9548  }
9549 
9550  if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9551  {
9553  (strat->tailRing != NULL ?
9554  strat->tailRing : currRing),
9555  strat->tailBin);
9556  if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9557  }
9558  strat->T[atT] = (TObject) p;
9559  //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9560 
9561  if (pNext(p.p) != NULL)
9562  strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9563  else
9564  strat->T[atT].max_exp = NULL;
9565 
9566  strat->tl++;
9567  strat->R[strat->tl] = &(strat->T[atT]);
9568  strat->T[atT].i_r = strat->tl;
9569  assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9570  strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9571  #if 1
9573  && !n_IsUnit(p.p->coef, currRing->cf))
9574  {
9575  for(i=strat->tl;i>=0;i--)
9576  {
9577  if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9578  {
9579  enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9580  }
9581  }
9582  }
9583  /*
9584  printf("\nThis is T:\n");
9585  for(i=strat->tl;i>=0;i--)
9586  {
9587  pWrite(strat->T[i].p);
9588  }
9589  //getchar();*/
9590  #endif
9591  kTest_T(&(strat->T[atT]),strat);
9592 }
9593 #endif
9594 
9595 /*2
9596 * puts signature p.sig to the set syz
9597 */
9598 void enterSyz(LObject &p, kStrategy strat, int atT)
9599 {
9600  int i;
9601  strat->newt = TRUE;
9602  if (strat->syzl == strat->syzmax-1)
9603  {
9604  pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9605  strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9606  (strat->syzmax)*sizeof(unsigned long),
9607  ((strat->syzmax)+setmax)
9608  *sizeof(unsigned long));
9609  strat->syzmax += setmax;
9610  }
9611  if (atT < strat->syzl)
9612  {
9613 #ifdef ENTER_USE_MEMMOVE
9614  memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9615  (strat->syzl-atT+1)*sizeof(poly));
9616  memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9617  (strat->syzl-atT+1)*sizeof(unsigned long));
9618 #endif
9619  for (i=strat->syzl; i>=atT+1; i--)
9620  {
9621 #ifndef ENTER_USE_MEMMOVE
9622  strat->syz[i] = strat->syz[i-1];
9623  strat->sevSyz[i] = strat->sevSyz[i-1];
9624 #endif
9625  }
9626  }
9627  //i = strat->syzl;
9628  i = atT;
9629  //Makes sure the syz saves just the signature
9630  #ifdef HAVE_RINGS
9632  pNext(p.sig) = NULL;
9633  #endif
9634  strat->syz[atT] = p.sig;
9635  strat->sevSyz[atT] = p.sevSig;
9636  strat->syzl++;
9637 #if F5DEBUG
9638  Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9639  pWrite(strat->syz[atT]);
9640 #endif
9641  // recheck pairs in strat->L with new rule and delete correspondingly
9642  int cc = strat->Ll;
9643  while (cc>-1)
9644  {
9645  //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9646  //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);
9647  if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9648  strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9649  #ifdef HAVE_RINGS
9650  &&((!rField_is_Ring(currRing))
9651  || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9652  #endif
9653  )
9654  {
9655  //printf("\nYES!\n");
9656  deleteInL(strat->L,&strat->Ll,cc,strat);
9657  }
9658  cc--;
9659  }
9660 //#if 1
9661 #ifdef DEBUGF5
9662  PrintS("--- Syzygies ---\n");
9663  Print("syzl %d\n",strat->syzl);
9664  Print("syzmax %d\n",strat->syzmax);
9665  PrintS("--------------------------------\n");
9666  for(i=0;i<=strat->syzl-1;i++)
9667  {
9668  Print("%d - ",i);
9669  pWrite(strat->syz[i]);
9670  }
9671  PrintS("--------------------------------\n");
9672 #endif
9673 }
9674 
9675 
9676 void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9677 {
9678 
9679  //if the ordering is local, then hilb criterion
9680  //can be used also if the ideal is not homogenous
9682  {
9684  *hilb=NULL;
9685  else
9686  return;
9687  }
9688  if (strat->homog!=isHomog)
9689  {
9690  *hilb=NULL;
9691  }
9692 }
9693 
9695 {
9697  strat->chainCrit=chainCritNormal;
9698  if (TEST_OPT_SB_1)
9699  strat->chainCrit=chainCritOpt_1;
9700 #ifdef HAVE_RINGS
9701  if (rField_is_Ring(currRing))
9702  {
9704  strat->chainCrit=chainCritRing;
9705  }
9706 #endif
9707 #ifdef HAVE_RATGRING
9708  if (rIsRatGRing(currRing))
9709  {
9710  strat->chainCrit=chainCritPart;
9711  /* enterOnePairNormal get rational part in it */
9712  }
9713 #endif
9714  if (TEST_OPT_IDLIFT
9715  && (strat->syzComp==1)
9716  && (!rIsPluralRing(currRing)))
9718 
9719  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9720  strat->Gebauer = strat->homog || strat->sugarCrit;
9721  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9722  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9723  strat->pairtest = NULL;
9724  /* alway use tailreduction, except:
9725  * - in local rings, - in lex order case, -in ring over extensions */
9727  //if(rHasMixedOrdering(currRing)==2)
9728  //{
9729  // strat->noTailReduction =TRUE;
9730  //}
9731 
9732 #ifdef HAVE_PLURAL
9733  // and r is plural_ring
9734  // hence this holds for r a rational_plural_ring
9735  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9736  { //or it has non-quasi-comm type... later
9737  strat->sugarCrit = FALSE;
9738  strat->Gebauer = FALSE;
9739  strat->honey = FALSE;
9740  }
9741 #endif
9742 
9743  // Coefficient ring?
9744  if (rField_is_Ring(currRing))
9745  {
9746  strat->sugarCrit = FALSE;
9747  strat->Gebauer = FALSE;
9748  strat->honey = FALSE;
9749  }
9750  #ifdef KDEBUG
9751  if (TEST_OPT_DEBUG)
9752  {
9753  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9754  else PrintS("ideal/module is not homogeneous\n");
9755  }
9756  #endif
9757 }
9758 
9760 {
9761  //strat->enterOnePair=enterOnePairNormal;
9763  //strat->chainCrit=chainCritNormal;
9764  strat->chainCrit = chainCritSig;
9765  /******************************************
9766  * rewCrit1 and rewCrit2 are already set in
9767  * kSba() in kstd1.cc
9768  *****************************************/
9769  //strat->rewCrit1 = faugereRewCriterion;
9770  if (strat->sbaOrder == 1)
9771  {
9772  strat->syzCrit = syzCriterionInc;
9773  }
9774  else
9775  {
9776  strat->syzCrit = syzCriterion;
9777  }
9778 #ifdef HAVE_RINGS
9779  if (rField_is_Ring(currRing))
9780  {
9782  strat->chainCrit=chainCritRing;
9783  }
9784 #endif
9785 #ifdef HAVE_RATGRING
9786  if (rIsRatGRing(currRing))
9787  {
9788  strat->chainCrit=chainCritPart;
9789  /* enterOnePairNormal get rational part in it */
9790  }
9791 #endif
9792 
9793  strat->sugarCrit = TEST_OPT_SUGARCRIT;
9794  strat->Gebauer = strat->homog || strat->sugarCrit;
9795  strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9796  if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9797  strat->pairtest = NULL;
9798  /* alway use tailreduction, except:
9799  * - in local rings, - in lex order case, -in ring over extensions */
9802 
9803 #ifdef HAVE_PLURAL
9804  // and r is plural_ring
9805  // hence this holds for r a rational_plural_ring
9806  if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9807  { //or it has non-quasi-comm type... later
9808  strat->sugarCrit = FALSE;
9809  strat->Gebauer = FALSE;
9810  strat->honey = FALSE;
9811  }
9812 #endif
9813 
9814  // Coefficient ring?
9815  if (rField_is_Ring(currRing))
9816  {
9817  strat->sugarCrit = FALSE;
9818  strat->Gebauer = FALSE ;
9819  strat->honey = FALSE;
9820  }
9821  #ifdef KDEBUG
9822  if (TEST_OPT_DEBUG)
9823  {
9824  if (strat->homog) PrintS("ideal/module is homogeneous\n");
9825  else PrintS("ideal/module is not homogeneous\n");
9826  }
9827  #endif
9828 }
9829 
9831  (const LSet set, const int length,
9832  LObject* L,const kStrategy strat))
9833 {
9834  if (pos_in_l == posInL110
9835  || pos_in_l == posInL10
9836  #ifdef HAVE_RINGS
9837  || pos_in_l == posInL110Ring
9838  || pos_in_l == posInLRing
9839  #endif
9840  )
9841  return TRUE;
9842 
9843  return FALSE;
9844 }
9845 
9847 {
9849  {
9850  if (strat->honey)
9851  {
9852  strat->posInL = posInL15;
9853  // ok -- here is the deal: from my experiments for Singular-2-0
9854  // I conclude that that posInT_EcartpLength is the best of
9855  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9856  // see the table at the end of this file
9857  if (TEST_OPT_OLDSTD)
9858  strat->posInT = posInT15;
9859  else
9860  strat->posInT = posInT_EcartpLength;
9861  }
9862  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9863  {
9864  strat->posInL = posInL11;
9865  strat->posInT = posInT11;
9866  }
9867  else if (TEST_OPT_INTSTRATEGY)
9868  {
9869  strat->posInL = posInL11;
9870  strat->posInT = posInT11;
9871  }
9872  else
9873  {
9874  strat->posInL = posInL0;
9875  strat->posInT = posInT0;
9876  }
9877  //if (strat->minim>0) strat->posInL =posInLSpecial;
9878  if (strat->homog)
9879  {
9880  strat->posInL = posInL110;
9881  strat->posInT = posInT110;
9882  }
9883  }
9884  else /* local/mixed ordering */
9885  {
9886  if (strat->homog)
9887  {
9888  strat->posInL = posInL11;
9889  strat->posInT = posInT11;
9890  }
9891  else
9892  {
9893  if ((currRing->order[0]==ringorder_c)
9894  ||(currRing->order[0]==ringorder_C))
9895  {
9896  strat->posInL = posInL17_c;
9897  strat->posInT = posInT17_c;
9898  }
9899  else
9900  {
9901  strat->posInL = posInL17;
9902  strat->posInT = posInT17;
9903  }
9904  }
9905  }
9906  if (strat->minim>0) strat->posInL =posInLSpecial;
9907  // for further tests only
9908  if ((BTEST1(11)) || (BTEST1(12)))
9909  strat->posInL = posInL11;
9910  else if ((BTEST1(13)) || (BTEST1(14)))
9911  strat->posInL = posInL13;
9912  else if ((BTEST1(15)) || (BTEST1(16)))
9913  strat->posInL = posInL15;
9914  else if ((BTEST1(17)) || (BTEST1(18)))
9915  strat->posInL = posInL17;
9916  if (BTEST1(11))
9917  strat->posInT = posInT11;
9918  else if (BTEST1(13))
9919  strat->posInT = posInT13;
9920  else if (BTEST1(15))
9921  strat->posInT = posInT15;
9922  else if ((BTEST1(17)))
9923  strat->posInT = posInT17;
9924  else if ((BTEST1(19)))
9925  strat->posInT = posInT19;
9926  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9927  strat->posInT = posInT1;
9929 }
9930 
9931 #ifdef HAVE_RINGS
9933 {
9935  {
9936  if (strat->honey)
9937  {
9938  strat->posInL = posInL15Ring;
9939  // ok -- here is the deal: from my experiments for Singular-2-0
9940  // I conclude that that posInT_EcartpLength is the best of
9941  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9942  // see the table at the end of this file
9943  if (TEST_OPT_OLDSTD)
9944  strat->posInT = posInT15Ring;
9945  else
9946  strat->posInT = posInT_EcartpLength;
9947  }
9948  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9949  {
9950  strat->posInL = posInL11Ring;
9951  strat->posInT = posInT11;
9952  }
9953  else if (TEST_OPT_INTSTRATEGY)
9954  {
9955  strat->posInL = posInL11Ring;
9956  strat->posInT = posInT11;
9957  }
9958  else
9959  {
9960  strat->posInL = posInL0Ring;
9961  strat->posInT = posInT0;
9962  }
9963  //if (strat->minim>0) strat->posInL =posInLSpecial;
9964  if (strat->homog)
9965  {
9966  strat->posInL = posInL110Ring;
9967  strat->posInT = posInT110Ring;
9968  }
9969  }
9970  else
9971  {
9972  if (strat->homog)
9973  {
9974  //printf("\nHere 3\n");
9975  strat->posInL = posInL11Ring;
9976  strat->posInT = posInT11Ring;
9977  }
9978  else
9979  {
9980  if ((currRing->order[0]==ringorder_c)
9981  ||(currRing->order[0]==ringorder_C))
9982  {
9983  strat->posInL = posInL17_cRing;
9984  strat->posInT = posInT17_cRing;
9985  }
9986  else
9987  {
9988  strat->posInL = posInL11Ringls;
9989  strat->posInT = posInT17Ring;
9990  }
9991  }
9992  }
9993  if (strat->minim>0) strat->posInL =posInLSpecial;
9994  // for further tests only
9995  if ((BTEST1(11)) || (BTEST1(12)))
9996  strat->posInL = posInL11Ring;
9997  else if ((BTEST1(13)) || (BTEST1(14)))
9998  strat->posInL = posInL13;
9999  else if ((BTEST1(15)) || (BTEST1(16)))
10000  strat->posInL = posInL15Ring;
10001  else if ((BTEST1(17)) || (BTEST1(18)))
10002  strat->posInL = posInL17Ring;
10003  if (BTEST1(11))
10004  strat->posInT = posInT11Ring;
10005  else if (BTEST1(13))
10006  strat->posInT = posInT13;
10007  else if (BTEST1(15))
10008  strat->posInT = posInT15Ring;
10009  else if ((BTEST1(17)))
10010  strat->posInT = posInT17Ring;
10011  else if ((BTEST1(19)))
10012  strat->posInT = posInT19;
10013  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10014  strat->posInT = posInT1;
10016 }
10017 #endif
10018 
10019 void initBuchMora (ideal F,ideal Q,kStrategy strat)
10020 {
10021  strat->interpt = BTEST1(OPT_INTERRUPT);
10022  /*- creating temp data structures------------------- -*/
10023  //strat->cp = 0; // already by skStragy()
10024  //strat->c3 = 0; // already by skStragy()
10025 #ifdef HAVE_SHIFTBBA
10026  strat->cv = 0; // already by skStragy()
10027 #endif
10028  strat->tail = pInit();
10029  /*- set s -*/
10030  strat->sl = -1;
10031  /*- set L -*/
10032  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10033  strat->Ll = -1;
10034  strat->L = initL(strat->Lmax);
10035  /*- set B -*/
10036  strat->Bmax = setmaxL;
10037  strat->Bl = -1;
10038  strat->B = initL();
10039  /*- set T -*/
10040  strat->tl = -1;
10041  strat->tmax = setmaxT;
10042  strat->T = initT();
10043  strat->R = initR();
10044  strat->sevT = initsevT();
10045  /*- init local data struct.---------------------------------------- -*/
10046  //strat->P.ecart=0; // already by skStragy()
10047  //strat->P.length=0; // already by skStragy()
10048  //strat->P.pLength=0; // already by skStragy()
10050  {
10051  if (strat->kNoether!=NULL)
10052  {
10053  pSetComp(strat->kNoether, strat->ak);
10054  pSetComp(strat->kNoetherTail(), strat->ak);
10055  }
10056  }
10058  {
10059  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10060  }
10061  else
10062  {
10063  if(TEST_OPT_SB_1)
10064  {
10065  int i;
10066  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10067  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10068  {
10069  P->m[i-strat->newIdeal] = F->m[i];
10070  F->m[i] = NULL;
10071  }
10072  initSSpecial(F,Q,P,strat);
10073  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10074  {
10075  F->m[i] = P->m[i-strat->newIdeal];
10076  P->m[i-strat->newIdeal] = NULL;
10077  }
10078  idDelete(&P);
10079  }
10080  else
10081  {
10082  /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10083  // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
10084  }
10085  }
10086  strat->fromT = FALSE;
10088  if ((!TEST_OPT_SB_1)
10089  || (rField_is_Ring(currRing))
10090  )
10091  {
10092  updateS(TRUE,strat);
10093  }
10094 #ifdef HAVE_SHIFTBBA
10095  if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
10096 #endif
10097  {
10098  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10099  strat->fromQ=NULL;
10100  }
10101  assume(kTest_TS(strat));
10102 }
10103 
10105 {
10106  /*- release temp data -*/
10107  cleanT(strat);
10108  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10109  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10110  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10111  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10112  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10113  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10114  /*- set L: should be empty -*/
10115  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10116  /*- set B: should be empty -*/
10117  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10118  pLmFree(&strat->tail);
10119  strat->syzComp=0;
10120 
10121 #ifdef HAVE_SHIFTBBA
10122  if (rIsLPRing(currRing) && strat->rightGB)
10123  {
10124  if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10125  strat->fromQ=NULL;
10126  }
10127 #endif
10128 }
10129 
10130 void initSbaPos (kStrategy strat)
10131 {
10133  {
10134  if (strat->honey)
10135  {
10136  strat->posInL = posInL15;
10137  // ok -- here is the deal: from my experiments for Singular-2-0
10138  // I conclude that that posInT_EcartpLength is the best of
10139  // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10140  // see the table at the end of this file
10141  if (TEST_OPT_OLDSTD)
10142  strat->posInT = posInT15;
10143  else
10144  strat->posInT = posInT_EcartpLength;
10145  }
10146  else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10147  {
10148  strat->posInL = posInL11;
10149  strat->posInT = posInT11;
10150  }
10151  else if (TEST_OPT_INTSTRATEGY)
10152  {
10153  strat->posInL = posInL11;
10154  strat->posInT = posInT11;
10155  }
10156  else
10157  {
10158  strat->posInL = posInL0;
10159  strat->posInT = posInT0;
10160  }
10161  //if (strat->minim>0) strat->posInL =posInLSpecial;
10162  if (strat->homog)
10163  {
10164  strat->posInL = posInL110;
10165  strat->posInT = posInT110;
10166  }
10167  }
10168  else
10169  {
10170  if (strat->homog)
10171  {
10172  strat->posInL = posInL11;
10173  strat->posInT = posInT11;
10174  }
10175  else
10176  {
10177  if ((currRing->order[0]==ringorder_c)
10178  ||(currRing->order[0]==ringorder_C))
10179  {
10180  strat->posInL = posInL17_c;
10181  strat->posInT = posInT17_c;
10182  }
10183  else
10184  {
10185  strat->posInL = posInL17;
10186  strat->posInT = posInT17;
10187  }
10188  }
10189  }
10190  if (strat->minim>0) strat->posInL =posInLSpecial;
10191  // for further tests only
10192  if ((BTEST1(11)) || (BTEST1(12)))
10193  strat->posInL = posInL11;
10194  else if ((BTEST1(13)) || (BTEST1(14)))
10195  strat->posInL = posInL13;
10196  else if ((BTEST1(15)) || (BTEST1(16)))
10197  strat->posInL = posInL15;
10198  else if ((BTEST1(17)) || (BTEST1(18)))
10199  strat->posInL = posInL17;
10200  if (BTEST1(11))
10201  strat->posInT = posInT11;
10202  else if (BTEST1(13))
10203  strat->posInT = posInT13;
10204  else if (BTEST1(15))
10205  strat->posInT = posInT15;
10206  else if ((BTEST1(17)))
10207  strat->posInT = posInT17;
10208  else if ((BTEST1(19)))
10209  strat->posInT = posInT19;
10210  else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10211  strat->posInT = posInT1;
10212  if (rField_is_Ring(currRing))
10213  {
10214  strat->posInL = posInL11Ring;
10215  if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
10216  strat->posInL = posInL11Ringls;
10217  strat->posInT = posInT11;
10218  }
10219  strat->posInLDependsOnLength = FALSE;
10220  strat->posInLSba = posInLSig;
10221  //strat->posInL = posInLSig;
10222  strat->posInL = posInLF5C;
10223  /*
10224  if (rField_is_Ring(currRing))
10225  {
10226  strat->posInLSba = posInLSigRing;
10227  strat->posInL = posInL11Ring;
10228  }*/
10229  //strat->posInT = posInTSig;
10230 }
10231 
10232 void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10233 {
10234  strat->interpt = BTEST1(OPT_INTERRUPT);
10235  //strat->kNoether=NULL; // done by skStrategy
10236  /*- creating temp data structures------------------- -*/
10237  //strat->cp = 0; // done by skStrategy
10238  //strat->c3 = 0; // done by skStrategy
10239  strat->tail = pInit();
10240  /*- set s -*/
10241  strat->sl = -1;
10242  /*- set ps -*/
10243  strat->syzl = -1;
10244  /*- set L -*/
10245  strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10246  strat->Ll = -1;
10247  strat->L = initL(strat->Lmax);
10248  /*- set B -*/
10249  strat->Bmax = setmaxL;
10250  strat->Bl = -1;
10251  strat->B = initL();
10252  /*- set T -*/
10253  strat->tl = -1;
10254  strat->tmax = setmaxT;
10255  strat->T = initT();
10256  strat->R = initR();
10257  strat->sevT = initsevT();
10258  /*- init local data struct.---------------------------------------- -*/
10259  //strat->P.ecart=0; // done by skStrategy
10260  //strat->P.length=0; // done by skStrategy
10262  {
10263  if (strat->kNoether!=NULL)
10264  {
10265  pSetComp(strat->kNoether, strat->ak);
10266  pSetComp(strat->kNoetherTail(), strat->ak);
10267  }
10268  }
10270  {
10271  /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10272  }
10273  else
10274  {
10275  if(TEST_OPT_SB_1)
10276  {
10277  int i;
10278  ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10279  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10280  {
10281  P->m[i-strat->newIdeal] = F->m[i];
10282  F->m[i] = NULL;
10283  }
10284  initSSpecialSba(F,Q,P,strat);
10285  for (i=strat->newIdeal;i<IDELEMS(F);i++)
10286  {
10287  F->m[i] = P->m[i-strat->newIdeal];
10288  P->m[i-strat->newIdeal] = NULL;
10289  }
10290  idDelete(&P);
10291  }
10292  else
10293  {
10294  initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10295  }
10296  }
10297  //strat->fromT = FALSE; // done by skStrategy
10298  if (!TEST_OPT_SB_1)
10299  {
10300  if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10301  }
10302  //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10303  //strat->fromQ=NULL;
10304  assume(kTest_TS(strat));
10305 }
10306 
10307 void exitSba (kStrategy strat)
10308 {
10309  /*- release temp data -*/
10311  cleanTSbaRing(strat);
10312  else
10313  cleanT(strat);
10314  omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10315  omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10316  omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10317  omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10318  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10319  omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10320  if(strat->syzmax>0)
10321  {
10322  omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10323  omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10324  if (strat->sbaOrder == 1)
10325  {
10326  omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10327  }
10328  }
10329  omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10330  /*- set L: should be empty -*/
10331  omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10332  /*- set B: should be empty -*/
10333  omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10334  /*- set sig: no need for the signatures anymore -*/
10335  omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10336  pLmDelete(&strat->tail);
10337  strat->syzComp=0;
10338 }
10339 
10340 /*2
10341 * in the case of a standardbase of a module over a qring:
10342 * replace polynomials in i by ak vectors,
10343 * (the polynomial * unit vectors gen(1)..gen(ak)
10344 * in every case (also for ideals:)
10345 * deletes divisible vectors/polynomials
10346 */
10347 void updateResult(ideal r,ideal Q, kStrategy strat)
10348 {
10349  int l;
10350  if (strat->ak>0)
10351  {
10352  for (l=IDELEMS(r)-1;l>=0;l--)
10353  {
10354  if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10355  {
10356  pDelete(&r->m[l]); // and set it to NULL
10357  }
10358  }
10359  int q;
10360  poly p;
10361  if(!rField_is_Ring(currRing))
10362  {
10363  for (l=IDELEMS(r)-1;l>=0;l--)
10364  {
10365  if ((r->m[l]!=NULL)
10366  //&& (strat->syzComp>0)
10367  //&& (pGetComp(r->m[l])<=strat->syzComp)
10368  )
10369  {
10370  for(q=IDELEMS(Q)-1; q>=0;q--)
10371  {
10372  if ((Q->m[q]!=NULL)
10373  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10374  {
10375  if (TEST_OPT_REDSB)
10376  {
10377  p=r->m[l];
10378  r->m[l]=kNF(Q,NULL,p);
10379  pDelete(&p);
10380  }
10381  else
10382  {
10383  pDelete(&r->m[l]); // and set it to NULL
10384  }
10385  break;
10386  }
10387  }
10388  }
10389  }
10390  }
10391  #ifdef HAVE_RINGS
10392  else
10393  {
10394  for (l=IDELEMS(r)-1;l>=0;l--)
10395  {
10396  if ((r->m[l]!=NULL)
10397  //&& (strat->syzComp>0)
10398  //&& (pGetComp(r->m[l])<=strat->syzComp)
10399  )
10400  {
10401  for(q=IDELEMS(Q)-1; q>=0;q--)
10402  {
10403  if ((Q->m[q]!=NULL)
10404  &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10405  {
10406  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10407  {
10408  if (TEST_OPT_REDSB)
10409  {
10410  p=r->m[l];
10411  r->m[l]=kNF(Q,NULL,p);
10412  pDelete(&p);
10413  }
10414  else
10415  {
10416  pDelete(&r->m[l]); // and set it to NULL
10417  }
10418  break;
10419  }
10420  }
10421  }
10422  }
10423  }
10424  }
10425  #endif
10426  }
10427  else
10428  {
10429  int q;
10430  poly p;
10431  BOOLEAN reduction_found=FALSE;
10432  if (!rField_is_Ring(currRing))
10433  {
10434  for (l=IDELEMS(r)-1;l>=0;l--)
10435  {
10436  if (r->m[l]!=NULL)
10437  {
10438  for(q=IDELEMS(Q)-1; q>=0;q--)
10439  {
10440  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10441  {
10442  if (TEST_OPT_REDSB)
10443  {
10444  p=r->m[l];
10445  r->m[l]=kNF(Q,NULL,p);
10446  pDelete(&p);
10447  reduction_found=TRUE;
10448  }
10449  else
10450  {
10451  pDelete(&r->m[l]); // and set it to NULL
10452  }
10453  break;
10454  }
10455  }
10456  }
10457  }
10458  }
10459  #ifdef HAVE_RINGS
10460  //Also need divisibility of the leading coefficients
10461  else
10462  {
10463  for (l=IDELEMS(r)-1;l>=0;l--)
10464  {
10465  if (r->m[l]!=NULL)
10466  {
10467  for(q=IDELEMS(Q)-1; q>=0;q--)
10468  {
10469  if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10470  {
10471  if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10472  {
10473  if (TEST_OPT_REDSB)
10474  {
10475  p=r->m[l];
10476  r->m[l]=kNF(Q,NULL,p);
10477  pDelete(&p);
10478  reduction_found=TRUE;
10479  }
10480  else
10481  {
10482  pDelete(&r->m[l]); // and set it to NULL
10483  }
10484  break;
10485  }
10486  }
10487  }
10488  }
10489  }
10490  }
10491  #endif
10492  if (/*TEST_OPT_REDSB &&*/ reduction_found)
10493  {
10494  #ifdef HAVE_RINGS
10496  {
10497  for (l=IDELEMS(r)-1;l>=0;l--)
10498  {
10499  if (r->m[l]!=NULL)
10500  {
10501  for(q=IDELEMS(r)-1;q>=0;q--)
10502  {
10503  if ((l!=q)
10504  && (r->m[q]!=NULL)
10505  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10506  &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10507  )
10508  {
10509  //If they are equal then take the one with the smallest length
10510  if(pLmDivisibleBy(r->m[q],r->m[l])
10511  && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10512  && (pLength(r->m[q]) < pLength(r->m[l]) ||
10513  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10514  {
10515  pDelete(&r->m[l]);
10516  break;
10517  }
10518  else
10519  pDelete(&r->m[q]);
10520  }
10521  }
10522  }
10523  }
10524  }
10525  else
10526  #endif
10527  {
10528  for (l=IDELEMS(r)-1;l>=0;l--)
10529  {
10530  if (r->m[l]!=NULL)
10531  {
10532  for(q=IDELEMS(r)-1;q>=0;q--)
10533  {
10534  if ((l!=q)
10535  && (r->m[q]!=NULL)
10536  &&(pLmDivisibleBy(r->m[l],r->m[q]))
10537  )
10538  {
10539  //If they are equal then take the one with the smallest length
10540  if(pLmDivisibleBy(r->m[q],r->m[l])
10541  &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10542  (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10543  {
10544  pDelete(&r->m[l]);
10545  break;
10546  }
10547  else
10548  pDelete(&r->m[q]);
10549  }
10550  }
10551  }
10552  }
10553  }
10554  }
10555  }
10556  idSkipZeroes(r);
10557 }
10558 
10559 void completeReduce (kStrategy strat, BOOLEAN withT)
10560 {
10561  int i;
10562  int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10563  LObject L;
10564 
10565 #ifdef KDEBUG
10566  // need to set this: during tailreductions of T[i], T[i].max is out of
10567  // sync
10568  sloppy_max = TRUE;
10569 #endif
10570 
10571  strat->noTailReduction = FALSE;
10572  //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10573  if (TEST_OPT_PROT)
10574  {
10575  PrintLn();
10576 // if (timerv) writeTime("standard base computed:");
10577  }
10578  if (TEST_OPT_PROT)
10579  {
10580  Print("(S:%d)",strat->sl);mflush();
10581  }
10582  for (i=strat->sl; i>=low; i--)
10583  {
10584  int end_pos=strat->sl;
10585  if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10586  if (strat->ak==0) end_pos=i-1;
10587  TObject* T_j = strat->s_2_t(i);
10588  if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10589  {
10590  L = *T_j;
10591  #ifdef KDEBUG
10592  if (TEST_OPT_DEBUG)
10593  {
10594  Print("test S[%d]:",i);
10595  p_wrp(L.p,currRing,strat->tailRing);
10596  PrintLn();
10597  }
10598  #endif
10600  strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10601  else
10602  strat->S[i] = redtail(&L, strat->sl, strat);
10603  #ifdef KDEBUG
10604  if (TEST_OPT_DEBUG)
10605  {
10606  Print("to (tailR) S[%d]:",i);
10607  p_wrp(strat->S[i],currRing,strat->tailRing);
10608  PrintLn();
10609  }
10610  #endif
10611 
10612  if (strat->redTailChange)
10613  {
10614  if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10615  if (pNext(T_j->p) != NULL)
10616  T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10617  else
10618  T_j->max_exp = NULL;
10619  }
10621  T_j->pCleardenom();
10622  }
10623  else
10624  {
10625  assume(currRing == strat->tailRing);
10626  #ifdef KDEBUG
10627  if (TEST_OPT_DEBUG)
10628  {
10629  Print("test S[%d]:",i);
10630  p_wrp(strat->S[i],currRing,strat->tailRing);
10631  PrintLn();
10632  }
10633  #endif
10635  strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10636  else
10637  strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10639  {
10640  if (TEST_OPT_CONTENTSB)
10641  {
10642  number n;
10643  p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10644  if (!nIsOne(n))
10645  {
10647  denom->n=nInvers(n);
10648  denom->next=DENOMINATOR_LIST;
10649  DENOMINATOR_LIST=denom;
10650  }
10651  nDelete(&n);
10652  }
10653  else
10654  {
10655  strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10656  }
10657  }
10658  #ifdef KDEBUG
10659  if (TEST_OPT_DEBUG)
10660  {
10661  Print("to (-tailR) S[%d]:",i);
10662  p_wrp(strat->S[i],currRing,strat->tailRing);
10663  PrintLn();
10664  }
10665  #endif
10666  }
10667  if (TEST_OPT_PROT)
10668  PrintS("-");
10669  }
10670  if (TEST_OPT_PROT) PrintLn();
10671 #ifdef KDEBUG
10672  sloppy_max = FALSE;
10673 #endif
10674 }
10675 
10676 
10677 /*2
10678 * computes the new strat->kNoether and the new pNoether,
10679 * returns TRUE, if pNoether has changed
10680 */
10682 {
10683  if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10684  return FALSE;
10685  int i,j;
10686  poly newNoether;
10687 
10688 #if 0
10689  if (currRing->weight_all_1)
10690  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether, strat->tailRing);
10691  else
10692  scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kNoether, strat->tailRing);
10693 #else
10694  scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether, strat->tailRing);
10695 #endif
10696  if (strat->kNoether==NULL) return FALSE;
10697  if (strat->t_kNoether != NULL)
10698  {
10699  p_LmFree(strat->t_kNoether, strat->tailRing);
10700  strat->t_kNoether=NULL;
10701  }
10702  if (strat->tailRing != currRing)
10703  strat->t_kNoether = k_LmInit_currRing_2_tailRing(strat->kNoether, strat->tailRing);
10704  /* compare old and new noether*/
10705  newNoether = pLmInit(strat->kNoether);
10706  pSetCoeff0(newNoether,nInit(1));
10707  j = p_FDeg(newNoether,currRing);
10708  for (i=1; i<=(currRing->N); i++)
10709  {
10710  if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
10711  }
10712  pSetm(newNoether);
10713  if (j < HCord) /*- statistics -*/
10714  {
10715  if (TEST_OPT_PROT)
10716  {
10717  Print("H(%d)",j);
10718  mflush();
10719  }
10720  HCord=j;
10721  #ifdef KDEBUG
10722  if (TEST_OPT_DEBUG)
10723  {
10724  Print("H(%d):",j);
10725  wrp(strat->kNoether);
10726  PrintLn();
10727  }
10728  #endif
10729  }
10730  if (pCmp(strat->kNoether,newNoether)!=1)
10731  {
10732  if (strat->kNoether!=NULL) p_LmDelete0(strat->kNoether,currRing);
10733  strat->kNoether=newNoether;
10734  if (strat->t_kNoether != NULL)
10735  {
10736  p_LmFree(strat->t_kNoether, strat->tailRing);
10737  strat->t_kNoether=NULL;
10738  }
10739  if (strat->tailRing != currRing)
10740  strat->t_kNoether = k_LmInit_currRing_2_tailRing(strat->kNoether, strat->tailRing);
10741 
10742  return TRUE;
10743  }
10744  pLmDelete(newNoether);
10745  return FALSE;
10746 }
10747 
10748 /***************************************************************
10749  *
10750  * Routines related for ring changes during std computations
10751  *
10752  ***************************************************************/
10753 BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10754 {
10755  if (strat->overflow) return FALSE;
10756  assume(L->p1 != NULL && L->p2 != NULL);
10757  // shift changes: from 0 to -1
10758  assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10759  assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10760 
10761  if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10762  return FALSE;
10763  // shift changes: extra case inserted
10764  if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10765  {
10766  return TRUE;
10767  }
10768  poly p1_max=NULL;
10769  if ((L->i_r1>=0)&&(strat->R[L->i_r1]!=NULL)) p1_max = (strat->R[L->i_r1])->max_exp;
10770  poly p2_max=NULL;
10771  if ((L->i_r2>=0)&&(strat->R[L->i_r2]!=NULL)) p2_max = (strat->R[L->i_r2])->max_exp;
10772 
10773  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10774  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10775  {
10776  p_LmFree(m1, strat->tailRing);
10777  p_LmFree(m2, strat->tailRing);
10778  m1 = NULL;
10779  m2 = NULL;
10780  return FALSE;
10781  }
10782  return TRUE;
10783 }
10784 
10785 #ifdef HAVE_RINGS
10786 /***************************************************************
10787  *
10788  * Checks, if we can compute the gcd poly / strong pair
10789  * gcd-poly = m1 * R[atR] + m2 * S[atS]
10790  *
10791  ***************************************************************/
10792 BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10793 {
10794  assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10795  //assume(strat->tailRing != currRing);
10796 
10797  poly p1_max = (strat->R[atR])->max_exp;
10798  poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10799 
10800  if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10801  ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10802  {
10803  return FALSE;
10804  }
10805  return TRUE;
10806 }
10807 #endif
10808 
10809 #ifdef HAVE_RINGS
10810 /*!
10811  used for GB over ZZ: look for constant and monomial elements in the ideal
10812  background: any known constant element of ideal suppresses
10813  intermediate coefficient swell
10814 */
10815 poly preIntegerCheck(const ideal Forig, const ideal Q)
10816 {
10817  if(!nCoeff_is_Z(currRing->cf))
10818  return NULL;
10819  ideal F = idCopy(Forig);
10820  idSkipZeroes(F);
10821  poly pmon;
10822  ring origR = currRing;
10823  ideal monred = idInit(1,1);
10824  for(int i=0; i<idElem(F); i++)
10825  {
10826  if(pNext(F->m[i]) == NULL)
10827  idInsertPoly(monred, pCopy(F->m[i]));
10828  }
10829  int posconst = idPosConstant(F);
10830  if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10831  {
10832  idDelete(&F);
10833  idDelete(&monred);
10834  return NULL;
10835  }
10836  int idelemQ = 0;
10837  if(Q!=NULL)
10838  {
10839  idelemQ = IDELEMS(Q);
10840  for(int i=0; i<idelemQ; i++)
10841  {
10842  if(pNext(Q->m[i]) == NULL)
10843  idInsertPoly(monred, pCopy(Q->m[i]));
10844  }
10845  idSkipZeroes(monred);
10846  posconst = idPosConstant(monred);
10847  //the constant, if found, will be from Q
10848  if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10849  {
10850  pmon = pCopy(monred->m[posconst]);
10851  idDelete(&F);
10852  idDelete(&monred);
10853  return pmon;
10854  }
10855  }
10856  ring QQ_ring = rCopy0(currRing,FALSE);
10857  nKillChar(QQ_ring->cf);
10858  QQ_ring->cf = nInitChar(n_Q, NULL);
10859  rComplete(QQ_ring,1);
10860  QQ_ring = rAssure_c_dp(QQ_ring);
10861  rChangeCurrRing(QQ_ring);
10862  nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10863  ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10864  for(int i = 0, j = 0; i<IDELEMS(F); i++)
10865  II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10866  for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10867  II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10868  ideal one = kStd(II, NULL, isNotHomog, NULL);
10869  idSkipZeroes(one);
10870  if(idIsConstant(one))
10871  {
10872  //one should be <1>
10873  for(int i = IDELEMS(II)-1; i>=0; i--)
10874  if(II->m[i] != NULL)
10875  II->m[i+1] = II->m[i];
10876  II->m[0] = pOne();
10877  ideal syz = idSyzygies(II, isNotHomog, NULL);
10878  poly integer = NULL;
10879  for(int i = IDELEMS(syz)-1;i>=0; i--)
10880  {
10881  if(pGetComp(syz->m[i]) == 1)
10882  {
10883  pSetComp(syz->m[i],0);
10884  if(pIsConstant(pHead(syz->m[i])))
10885  {
10886  integer = pHead(syz->m[i]);
10887  break;
10888  }
10889  }
10890  }
10891  rChangeCurrRing(origR);
10892  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10893  pmon = prMapR(integer, nMap2, QQ_ring, origR);
10894  idDelete(&monred);
10895  idDelete(&F);
10896  id_Delete(&II,QQ_ring);
10897  id_Delete(&one,QQ_ring);
10898  id_Delete(&syz,QQ_ring);
10899  p_Delete(&integer,QQ_ring);
10900  rDelete(QQ_ring);
10901  return pmon;
10902  }
10903  else
10904  {
10905  if(idIs0(monred))
10906  {
10907  poly mindegmon = NULL;
10908  for(int i = 0; i<IDELEMS(one); i++)
10909  {
10910  if(pNext(one->m[i]) == NULL)
10911  {
10912  if(mindegmon == NULL)
10913  mindegmon = pCopy(one->m[i]);
10914  else
10915  {
10916  if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10917  mindegmon = pCopy(one->m[i]);
10918  }
10919  }
10920  }
10921  if(mindegmon != NULL)
10922  {
10923  for(int i = IDELEMS(II)-1; i>=0; i--)
10924  if(II->m[i] != NULL)
10925  II->m[i+1] = II->m[i];
10926  II->m[0] = pCopy(mindegmon);
10927  ideal syz = idSyzygies(II, isNotHomog, NULL);
10928  bool found = FALSE;
10929  for(int i = IDELEMS(syz)-1;i>=0; i--)
10930  {
10931  if(pGetComp(syz->m[i]) == 1)
10932  {
10933  pSetComp(syz->m[i],0);
10934  if(pIsConstant(pHead(syz->m[i])))
10935  {
10936  pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10937  found = TRUE;
10938  break;
10939  }
10940  }
10941  }
10942  id_Delete(&syz,QQ_ring);
10943  if (found == FALSE)
10944  {
10945  rChangeCurrRing(origR);
10946  idDelete(&monred);
10947  idDelete(&F);
10948  id_Delete(&II,QQ_ring);
10949  id_Delete(&one,QQ_ring);
10950  rDelete(QQ_ring);
10951  return NULL;
10952  }
10953  rChangeCurrRing(origR);
10954  nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10955  pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
10956  idDelete(&monred);
10957  idDelete(&F);
10958  id_Delete(&II,QQ_ring);
10959  id_Delete(&one,QQ_ring);
10960  id_Delete(&syz,QQ_ring);
10961  rDelete(QQ_ring);
10962  return pmon;
10963  }
10964  }
10965  }
10966  rChangeCurrRing(origR);
10967  idDelete(&monred);
10968  idDelete(&F);
10969  id_Delete(&II,QQ_ring);
10970  id_Delete(&one,QQ_ring);
10971  rDelete(QQ_ring);
10972  return NULL;
10973 }
10974 #endif
10975 
10976 #ifdef HAVE_RINGS
10977 /*!
10978  used for GB over ZZ: intermediate reduction by monomial elements
10979  background: any known constant element of ideal suppresses
10980  intermediate coefficient swell
10981 */
10983 {
10984  if(!nCoeff_is_Z(currRing->cf))
10985  return;
10986  poly pH = h->GetP();
10987  poly p,pp;
10988  p = pH;
10989  bool deleted = FALSE, ok = FALSE;
10990  for(int i = 0; i<=strat->sl; i++)
10991  {
10992  p = pH;
10993  if(pNext(strat->S[i]) == NULL)
10994  {
10995  //pWrite(p);
10996  //pWrite(strat->S[i]);
10997  while(ok == FALSE && p != NULL)
10998  {
10999  if(pLmDivisibleBy(strat->S[i], p)
11000 #ifdef HAVE_SHIFTBBA
11001  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], p))
11002 #endif
11003  )
11004  {
11005  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11006  p_SetCoeff(p,dummy,currRing);
11007  }
11008  if(nIsZero(p->coef))
11009  {
11010  pLmDelete(&p);
11011  h->p = p;
11012  deleted = TRUE;
11013  }
11014  else
11015  {
11016  ok = TRUE;
11017  }
11018  }
11019  if (p!=NULL)
11020  {
11021  pp = pNext(p);
11022  while(pp != NULL)
11023  {
11024  if(pLmDivisibleBy(strat->S[i], pp)
11025 #ifdef HAVE_SHIFTBBA
11026  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], pp))
11027 #endif
11028  )
11029  {
11030  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11031  p_SetCoeff(pp,dummy,currRing);
11032  if(nIsZero(pp->coef))
11033  {
11034  pLmDelete(&pNext(p));
11035  pp = pNext(p);
11036  deleted = TRUE;
11037  }
11038  else
11039  {
11040  p = pp;
11041  pp = pNext(p);
11042  }
11043  }
11044  else
11045  {
11046  p = pp;
11047  pp = pNext(p);
11048  }
11049  }
11050  }
11051  }
11052  }
11053  h->SetLmCurrRing();
11054  if((deleted)&&(h->p!=NULL))
11055  strat->initEcart(h);
11056 }
11057 
11059 {
11060  if(!nCoeff_is_Z(currRing->cf))
11061  return;
11062  poly hSig = h->sig;
11063  poly pH = h->GetP();
11064  poly p,pp;
11065  p = pH;
11066  bool deleted = FALSE, ok = FALSE;
11067  for(int i = 0; i<=strat->sl; i++)
11068  {
11069  p = pH;
11070  if(pNext(strat->S[i]) == NULL)
11071  {
11072  while(ok == FALSE && p!=NULL)
11073  {
11074  if(pLmDivisibleBy(strat->S[i], p))
11075  {
11076  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11077  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11078  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11079  {
11080  number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11081  p_SetCoeff(p,dummy,currRing);
11082  }
11083  pDelete(&sigMult);
11084  }
11085  if(nIsZero(p->coef))
11086  {
11087  pLmDelete(&p);
11088  h->p = p;
11089  deleted = TRUE;
11090  }
11091  else
11092  {
11093  ok = TRUE;
11094  }
11095  }
11096  if(p == NULL)
11097  return;
11098  pp = pNext(p);
11099  while(pp != NULL)
11100  {
11101  if(pLmDivisibleBy(strat->S[i], pp))
11102  {
11103  poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11104  sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11105  if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11106  {
11107  number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11108  p_SetCoeff(pp,dummy,currRing);
11109  if(nIsZero(pp->coef))
11110  {
11111  pLmDelete(&pNext(p));
11112  pp = pNext(p);
11113  deleted = TRUE;
11114  }
11115  else
11116  {
11117  p = pp;
11118  pp = pNext(p);
11119  }
11120  }
11121  else
11122  {
11123  p = pp;
11124  pp = pNext(p);
11125  }
11126  pDelete(&sigMult);
11127  }
11128  else
11129  {
11130  p = pp;
11131  pp = pNext(p);
11132  }
11133  }
11134  }
11135  }
11136  h->SetLmCurrRing();
11137  if(deleted)
11138  strat->initEcart(h);
11139 
11140 }
11141 
11142 /*!
11143  used for GB over ZZ: final reduction by constant elements
11144  background: any known constant element of ideal suppresses
11145  intermediate coefficient swell and beautifies output
11146 */
11148 {
11149  assume(strat->tl<0); /* can only be called with no elements in T:
11150  i.e. after exitBuchMora */
11151  /* do not use strat->S, strat->sl as they may be out of sync*/
11152  if(!nCoeff_is_Z(currRing->cf))
11153  return;
11154  poly p,pp;
11155  for(int j = 0; j<IDELEMS(strat->Shdl); j++)
11156  {
11157  if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
11158  {
11159  for(int i = 0; i<IDELEMS(strat->Shdl); i++)
11160  {
11161  if((i != j) && (strat->Shdl->m[i] != NULL))
11162  {
11163  p = strat->Shdl->m[i];
11164  while((p!=NULL) && (pLmDivisibleBy(strat->Shdl->m[j], p)
11165 #if HAVE_SHIFTBBA
11166  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], p))
11167 #endif
11168  ))
11169  {
11170  number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
11171  if (!nEqual(dummy,p->coef))
11172  {
11173  if (nIsZero(dummy))
11174  {
11175  nDelete(&dummy);
11176  pLmDelete(&strat->Shdl->m[i]);
11177  p=strat->Shdl->m[i];
11178  }
11179  else
11180  {
11181  p_SetCoeff(p,dummy,currRing);
11182  break;
11183  }
11184  }
11185  else
11186  {
11187  nDelete(&dummy);
11188  break;
11189  }
11190  }
11191  if (p!=NULL)
11192  {
11193  pp = pNext(p);
11194  while(pp != NULL)
11195  {
11196  if(pLmDivisibleBy(strat->Shdl->m[j], pp)
11197 #if HAVE_SHIFTBBA
11198  || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], pp))
11199 #endif
11200  )
11201  {
11202  number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
11203  if (!nEqual(dummy,pp->coef))
11204  {
11205  p_SetCoeff(pp,dummy,currRing);
11206  if(nIsZero(pp->coef))
11207  {
11208  pLmDelete(&pNext(p));
11209  pp = pNext(p);
11210  }
11211  else
11212  {
11213  p = pp;
11214  pp = pNext(p);
11215  }
11216  }
11217  else
11218  {
11219  nDelete(&dummy);
11220  p = pp;
11221  pp = pNext(p);
11222  }
11223  }
11224  else
11225  {
11226  p = pp;
11227  pp = pNext(p);
11228  }
11229  }
11230  }
11231  }
11232  }
11233  //idPrint(strat->Shdl);
11234  }
11235  }
11236  idSkipZeroes(strat->Shdl);
11237 }
11238 #endif
11239 
11240 BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
11241 {
11242  assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11243  /* initial setup or extending */
11244 
11245  if (rIsLPRing(currRing)) return TRUE;
11246  if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11247  if (expbound >= currRing->bitmask) return FALSE;
11248  strat->overflow=FALSE;
11249  ring new_tailRing = rModifyRing(currRing,
11250  // Hmmm .. the condition pFDeg == p_Deg
11251  // might be too strong
11252  (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11253  (strat->ak==0), // omit_comp if the input is an ideal
11254  expbound); // exp_limit
11255 
11256  if (new_tailRing == currRing) return TRUE;
11257 
11258  strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11259  strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11260 
11261  if (currRing->pFDeg != currRing->pFDegOrig)
11262  {
11263  new_tailRing->pFDeg = currRing->pFDeg;
11264  new_tailRing->pLDeg = currRing->pLDeg;
11265  }
11266 
11267  if (TEST_OPT_PROT)
11268  Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11269  kTest_TS(strat);
11270  assume(new_tailRing != strat->tailRing);
11271  pShallowCopyDeleteProc p_shallow_copy_delete
11272  = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11273 
11274  omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11275 
11276  int i;
11277  for (i=0; i<=strat->tl; i++)
11278  {
11279  strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11280  p_shallow_copy_delete);
11281  }
11282  for (i=0; i<=strat->Ll; i++)
11283  {
11284  assume(strat->L[i].p != NULL);
11285  if (pNext(strat->L[i].p) != strat->tail)
11286  strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11287  }
11288  if ((strat->P.t_p != NULL) ||
11289  ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11290  strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11291 
11292  if ((L != NULL) && (L->tailRing != new_tailRing))
11293  {
11294  if (L->i_r < 0)
11295  L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11296  else
11297  {
11298  assume(L->i_r <= strat->tl);
11299  TObject* t_l = strat->R[L->i_r];
11300  assume(t_l != NULL);
11301  L->tailRing = new_tailRing;
11302  L->p = t_l->p;
11303  L->t_p = t_l->t_p;
11304  L->max_exp = t_l->max_exp;
11305  }
11306  }
11307 
11308  if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11309  T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11310 
11311  omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11312  if (strat->tailRing != currRing)
11313  rKillModifiedRing(strat->tailRing);
11314 
11315  strat->tailRing = new_tailRing;
11316  strat->tailBin = new_tailBin;
11317  strat->p_shallow_copy_delete
11318  = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11319 
11320  if (strat->kNoether != NULL)
11321  {
11322  if (strat->t_kNoether != NULL)
11323  p_LmFree(strat->t_kNoether, strat->tailRing);
11324  strat->t_kNoether=k_LmInit_currRing_2_tailRing(strat->kNoether, new_tailRing);
11325  }
11326 
11327  kTest_TS(strat);
11328  if (TEST_OPT_PROT)
11329  PrintS("]");
11330  return TRUE;
11331 }
11332 
11334 {
11335  unsigned long l = 0;
11336  int i;
11337  long e;
11338 
11339  assume(strat->tailRing == currRing);
11340 
11341  for (i=0; i<= strat->Ll; i++)
11342  {
11343  l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11344  }
11345  for (i=0; i<=strat->tl; i++)
11346  {
11347  // Hmm ... this we could do in one Step
11348  l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11349  }
11350  if (rField_is_Ring(currRing))
11351  {
11352  l *= 2;
11353  }
11354  e = p_GetMaxExp(l, currRing);
11355  if (e <= 1) e = 2;
11356  if (rIsLPRing(currRing)) e = 1;
11357 
11358  kStratChangeTailRing(strat, NULL, NULL, e);
11359 }
11360 
11361 ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11362 {
11363  int n = rBlocks(r); // Including trailing zero!
11364  // if sbaOrder == 1 => use (C,monomial order from r)
11365  if (strat->sbaOrder == 1)
11366  {
11367  if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11368  {
11369  return r;
11370  }
11371  ring res = rCopy0(r, TRUE, FALSE);
11372  res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11373  res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11374  res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11375  int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11376  res->wvhdl = wvhdl;
11377  for (int i=1; i<n; i++)
11378  {
11379  res->order[i] = r->order[i-1];
11380  res->block0[i] = r->block0[i-1];
11381  res->block1[i] = r->block1[i-1];
11382  res->wvhdl[i] = r->wvhdl[i-1];
11383  }
11384 
11385  // new 1st block
11386  res->order[0] = ringorder_C; // Prefix
11387  // removes useless secondary component order if defined in old ring
11388  for (int i=rBlocks(res); i>0; --i)
11389  {
11390  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11391  {
11392  res->order[i] = (rRingOrder_t)0;
11393  }
11394  }
11395  rComplete(res, 1);
11396 #ifdef HAVE_PLURAL
11397  if (rIsPluralRing(r))
11398  {
11399  if ( nc_rComplete(r, res, false) ) // no qideal!
11400  {
11401 #ifndef SING_NDEBUG
11402  WarnS("error in nc_rComplete");
11403 #endif
11404  // cleanup?
11405 
11406  // rDelete(res);
11407  // return r;
11408 
11409  // just go on..
11410  }
11411  }
11412 #endif
11413  strat->tailRing = res;
11414  return (res);
11415  }
11416  // if sbaOrder == 3 => degree - position - ring order
11417  if (strat->sbaOrder == 3)
11418  {
11419  ring res = rCopy0(r, TRUE, FALSE);
11420  res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11421  res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11422  res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11423  int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11424  res->wvhdl = wvhdl;
11425  for (int i=2; i<n+2; i++)
11426  {
11427  res->order[i] = r->order[i-2];
11428  res->block0[i] = r->block0[i-2];
11429  res->block1[i] = r->block1[i-2];
11430  res->wvhdl[i] = r->wvhdl[i-2];
11431  }
11432 
11433  // new 1st block
11434  res->order[0] = ringorder_a; // Prefix
11435  res->block0[0] = 1;
11436  res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11437  for (int i=0; i<res->N; ++i)
11438  res->wvhdl[0][i] = 1;
11439  res->block1[0] = si_min(res->N, rVar(res));
11440  // new 2nd block
11441  res->order[1] = ringorder_C; // Prefix
11442  res->wvhdl[1] = NULL;
11443  // removes useless secondary component order if defined in old ring
11444  for (int i=rBlocks(res); i>1; --i)
11445  {
11446  if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11447  {
11448  res->order[i] = (rRingOrder_t)0;
11449  }
11450  }
11451  rComplete(res, 1);
11452 #ifdef HAVE_PLURAL
11453  if (rIsPluralRing(r))
11454  {
11455  if ( nc_rComplete(r, res, false) ) // no qideal!
11456  {
11457 #ifndef SING_NDEBUG
11458  WarnS("error in nc_rComplete");
11459 #endif
11460  // cleanup?
11461 
11462  // rDelete(res);
11463  // return r;
11464 
11465  // just go on..
11466  }
11467  }
11468 #endif
11469  strat->tailRing = res;
11470  return (res);
11471  }
11472 
11473  // not sbaOrder == 1 => use Schreyer order
11474  // this is done by a trick when initializing the signatures
11475  // in initSLSba():
11476  // Instead of using the signature 1e_i for F->m[i], we start
11477  // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11478  // Schreyer order w.r.t. the underlying monomial order.
11479  // => we do not need to change the underlying polynomial ring at all!
11480 
11481  // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11482 
11483  /*
11484  else
11485  {
11486  ring res = rCopy0(r, FALSE, FALSE);
11487  // Create 2 more blocks for prefix/suffix:
11488  res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11489  res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11490  res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11491  int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11492 
11493  // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11494  // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11495 
11496  // new 1st block
11497  int j = 0;
11498  res->order[j] = ringorder_IS; // Prefix
11499  res->block0[j] = res->block1[j] = 0;
11500  // wvhdl[j] = NULL;
11501  j++;
11502 
11503  for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11504  {
11505  res->order [j] = r->order [i];
11506  res->block0[j] = r->block0[i];
11507  res->block1[j] = r->block1[i];
11508 
11509  if (r->wvhdl[i] != NULL)
11510  {
11511  wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11512  } // else wvhdl[j] = NULL;
11513  }
11514 
11515  // new last block
11516  res->order [j] = ringorder_IS; // Suffix
11517  res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11518  // wvhdl[j] = NULL;
11519  j++;
11520 
11521  // res->order [j] = 0; // The End!
11522  res->wvhdl = wvhdl;
11523 
11524  // j == the last zero block now!
11525  assume(j == (n+1));
11526  assume(res->order[0]==ringorder_IS);
11527  assume(res->order[j-1]==ringorder_IS);
11528  assume(res->order[j]==0);
11529 
11530  if (complete)
11531  {
11532  rComplete(res, 1);
11533 
11534 #ifdef HAVE_PLURAL
11535  if (rIsPluralRing(r))
11536  {
11537  if ( nc_rComplete(r, res, false) ) // no qideal!
11538  {
11539  }
11540  }
11541  assume(rIsPluralRing(r) == rIsPluralRing(res));
11542 #endif
11543 
11544 
11545 #ifdef HAVE_PLURAL
11546  ring old_ring = r;
11547 
11548 #endif
11549 
11550  if (r->qideal!=NULL)
11551  {
11552  res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11553 
11554  assume(idRankFreeModule(res->qideal, res) == 0);
11555 
11556 #ifdef HAVE_PLURAL
11557  if( rIsPluralRing(res) )
11558  if( nc_SetupQuotient(res, r, true) )
11559  {
11560  // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11561  }
11562 
11563 #endif
11564  assume(idRankFreeModule(res->qideal, res) == 0);
11565  }
11566 
11567 #ifdef HAVE_PLURAL
11568  assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11569  assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11570  assume(rIsSCA(res) == rIsSCA(old_ring));
11571  assume(ncRingType(res) == ncRingType(old_ring));
11572 #endif
11573  }
11574  strat->tailRing = res;
11575  return res;
11576  }
11577  */
11578 
11579  assume(FALSE);
11580  return(NULL);
11581 }
11582 
11584 {
11585  memset(this, 0, sizeof(skStrategy));
11586  strat_nr++;
11587  nr=strat_nr;
11588  tailRing = currRing;
11589  P.tailRing = currRing;
11590  tl = -1;
11591  sl = -1;
11592 #ifdef HAVE_LM_BIN
11593  lmBin = omGetStickyBinOfBin(currRing->PolyBin);
11594 #endif
11595 #ifdef HAVE_TAIL_BIN
11596  tailBin = omGetStickyBinOfBin(currRing->PolyBin);
11597 #endif
11598  pOrigFDeg = currRing->pFDeg;
11599  pOrigLDeg = currRing->pLDeg;
11600 }
11601 
11602 
11604 {
11605  if (lmBin != NULL)
11607  if (tailBin != NULL)// && !rField_is_Ring(currRing))
11609  ((tailRing != NULL) ? tailRing->PolyBin:
11610  currRing->PolyBin));
11611  if (t_kNoether != NULL)
11613 
11614  if (currRing != tailRing)
11617 }
11618 
11619 #if 0
11620 Timings for the different possibilities of posInT:
11621  T15 EDL DL EL L 1-2-3
11622 Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11623 Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11624 Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11625 ahml 4.48 4.03 4.03 4.38 4.96 26.50
11626 c7 15.02 13.98 15.16 13.24 17.31 47.89
11627 c8 505.09 407.46 852.76 413.21 499.19 n/a
11628 f855 12.65 9.27 14.97 8.78 14.23 33.12
11629 gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11630 gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11631 ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11632 noon8 40.68 37.02 37.99 36.82 35.59 877.16
11633 rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11634 rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11635 schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11636 test016 16.39 14.17 14.40 13.50 14.26 34.07
11637 test017 34.70 36.01 33.16 35.48 32.75 71.45
11638 test042 10.76 10.99 10.27 11.57 10.45 23.04
11639 test058 6.78 6.75 6.51 6.95 6.22 9.47
11640 test066 10.71 10.94 10.76 10.61 10.56 19.06
11641 test073 10.75 11.11 10.17 10.79 8.63 58.10
11642 test086 12.23 11.81 12.88 12.24 13.37 66.68
11643 test103 5.05 4.80 5.47 4.64 4.89 11.90
11644 test154 12.96 11.64 13.51 12.46 14.61 36.35
11645 test162 65.27 64.01 67.35 59.79 67.54 196.46
11646 test164 7.50 6.50 7.68 6.70 7.96 17.13
11647 virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11648 #endif
11649 
11650 
11651 //#ifdef HAVE_MORE_POS_IN_T
11652 #if 1
11653 // determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11654 int posInT_EcartFDegpLength(const TSet set,const int length,LObject &p)
11655 {
11656 
11657  if (length==-1) return 0;
11658 
11659  int o = p.ecart;
11660  int op=p.GetpFDeg();
11661  int ol = p.GetpLength();
11662 
11663  if (set[length].ecart < o)
11664  return length+1;
11665  if (set[length].ecart == o)
11666  {
11667  int oo=set[length].GetpFDeg();
11668  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11669  return length+1;
11670  }
11671 
11672  int i;
11673  int an = 0;
11674  int en= length;
11675  loop
11676  {
11677  if (an >= en-1)
11678  {
11679  if (set[an].ecart > o)
11680  return an;
11681  if (set[an].ecart == o)
11682  {
11683  int oo=set[an].GetpFDeg();
11684  if((oo > op)
11685  || ((oo==op) && (set[an].pLength > ol)))
11686  return an;
11687  }
11688  return en;
11689  }
11690  i=(an+en) / 2;
11691  if (set[i].ecart > o)
11692  en=i;
11693  else if (set[i].ecart == o)
11694  {
11695  int oo=set[i].GetpFDeg();
11696  if ((oo > op)
11697  || ((oo == op) && (set[i].pLength > ol)))
11698  en=i;
11699  else
11700  an=i;
11701  }
11702  else
11703  an=i;
11704  }
11705 }
11706 
11707 // determines the position based on: 1.) FDeg 2.) pLength
11708 int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11709 {
11710 
11711  if (length==-1) return 0;
11712 
11713  int op=p.GetpFDeg();
11714  int ol = p.GetpLength();
11715 
11716  int oo=set[length].GetpFDeg();
11717  if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11718  return length+1;
11719 
11720  int i;
11721  int an = 0;
11722  int en= length;
11723  loop
11724  {
11725  if (an >= en-1)
11726  {
11727  int oo=set[an].GetpFDeg();
11728  if((oo > op)
11729  || ((oo==op) && (set[an].pLength > ol)))
11730  return an;
11731  return en;
11732  }
11733  i=(an+en) / 2;
11734  int oo=set[i].GetpFDeg();
11735  if ((oo > op)
11736  || ((oo == op) && (set[i].pLength > ol)))
11737  en=i;
11738  else
11739  an=i;
11740  }
11741 }
11742 
11743 
11744 // determines the position based on: 1.) pLength
11745 int posInT_pLength(const TSet set,const int length,LObject &p)
11746 {
11747  int ol = p.GetpLength();
11748  if (length==-1)
11749  return 0;
11750  if (set[length].length<p.length)
11751  return length+1;
11752 
11753  int i;
11754  int an = 0;
11755  int en= length;
11756 
11757  loop
11758  {
11759  if (an >= en-1)
11760  {
11761  if (set[an].pLength>ol) return an;
11762  return en;
11763  }
11764  i=(an+en) / 2;
11765  if (set[i].pLength>ol) en=i;
11766  else an=i;
11767  }
11768 }
11769 #endif
11770 
11771 // kstd1.cc:
11772 int redFirst (LObject* h,kStrategy strat);
11773 int redEcart (LObject* h,kStrategy strat);
11774 void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11775 void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11776 // ../Singular/misc.cc:
11777 extern char * showOption();
11778 
11780 {
11781  PrintS("red: ");
11782  if (strat->red==redFirst) PrintS("redFirst\n");
11783  else if (strat->red==redHoney) PrintS("redHoney\n");
11784  else if (strat->red==redEcart) PrintS("redEcart\n");
11785  else if (strat->red==redHomog) PrintS("redHomog\n");
11786  else if (strat->red==redLazy) PrintS("redLazy\n");
11787  else if (strat->red==redLiftstd) PrintS("redLiftstd\n");
11788  else Print("%p\n",(void*)strat->red);
11789  PrintS("posInT: ");
11790  if (strat->posInT==posInT0) PrintS("posInT0\n");
11791  else if (strat->posInT==posInT1) PrintS("posInT1\n");
11792  else if (strat->posInT==posInT11) PrintS("posInT11\n");
11793  else if (strat->posInT==posInT110) PrintS("posInT110\n");
11794  else if (strat->posInT==posInT13) PrintS("posInT13\n");
11795  else if (strat->posInT==posInT15) PrintS("posInT15\n");
11796  else if (strat->posInT==posInT17) PrintS("posInT17\n");
11797  else if (strat->posInT==posInT17_c) PrintS("posInT17_c\n");
11798  else if (strat->posInT==posInT19) PrintS("posInT19\n");
11799  else if (strat->posInT==posInT2) PrintS("posInT2\n");
11800  #ifdef HAVE_RINGS
11801  else if (strat->posInT==posInT11Ring) PrintS("posInT11Ring\n");
11802  else if (strat->posInT==posInT110Ring) PrintS("posInT110Ring\n");
11803  else if (strat->posInT==posInT15Ring) PrintS("posInT15Ring\n");
11804  else if (strat->posInT==posInT17Ring) PrintS("posInT17Ring\n");
11805  else if (strat->posInT==posInT17_cRing) PrintS("posInT17_cRing\n");
11806  #endif
11807 #ifdef HAVE_MORE_POS_IN_T
11808  else if (strat->posInT==posInT_EcartFDegpLength) PrintS("posInT_EcartFDegpLength\n");
11809  else if (strat->posInT==posInT_FDegpLength) PrintS("posInT_FDegpLength\n");
11810  else if (strat->posInT==posInT_pLength) PrintS("posInT_pLength\n");
11811 #endif
11812  else if (strat->posInT==posInT_EcartpLength) PrintS("posInT_EcartpLength\n");
11813  else if (strat->posInT==posInTrg0) PrintS("posInTrg0\n");
11814  else Print("%p\n",(void*)strat->posInT);
11815  PrintS("posInL: ");
11816  if (strat->posInL==posInL0) PrintS("posInL0\n");
11817  else if (strat->posInL==posInL10) PrintS("posInL10\n");
11818  else if (strat->posInL==posInL11) PrintS("posInL11\n");
11819  else if (strat->posInL==posInL110) PrintS("posInL110\n");
11820  else if (strat->posInL==posInL13) PrintS("posInL13\n");
11821  else if (strat->posInL==posInL15) PrintS("posInL15\n");
11822  else if (strat->posInL==posInL17) PrintS("posInL17\n");
11823  else if (strat->posInL==posInL17_c) PrintS("posInL17_c\n");
11824  #ifdef HAVE_RINGS
11825  else if (strat->posInL==posInL0) PrintS("posInL0Ring\n");
11826  else if (strat->posInL==posInL11Ring) PrintS("posInL11Ring\n");
11827  else if (strat->posInL==posInL11Ringls) PrintS("posInL11Ringls\n");
11828  else if (strat->posInL==posInL110Ring) PrintS("posInL110Ring\n");
11829  else if (strat->posInL==posInL15Ring) PrintS("posInL15Ring\n");
11830  else if (strat->posInL==posInL17Ring) PrintS("posInL17Ring\n");
11831  else if (strat->posInL==posInL17_cRing) PrintS("posInL17_cRing\n");
11832  #endif
11833  else if (strat->posInL==posInLSpecial) PrintS("posInLSpecial\n");
11834  else if (strat->posInL==posInLrg0) PrintS("posInLrg0\n");
11835  else Print("%p\n",(void*)strat->posInL);
11836  PrintS("enterS: ");
11837  if (strat->enterS==enterSBba) PrintS("enterSBba\n");
11838  else if (strat->enterS==enterSMora) PrintS("enterSMora\n");
11839  else if (strat->enterS==enterSMoraNF) PrintS("enterSMoraNF\n");
11840  else Print("%p\n",(void*)strat->enterS);
11841  PrintS("initEcart: ");
11842  if (strat->initEcart==initEcartBBA) PrintS("initEcartBBA\n");
11843  else if (strat->initEcart==initEcartNormal) PrintS("initEcartNormal\n");
11844  else Print("%p\n",(void*)strat->initEcart);
11845  PrintS("initEcartPair: ");
11846  if (strat->initEcartPair==initEcartPairBba) PrintS("initEcartPairBba\n");
11847  else if (strat->initEcartPair==initEcartPairMora) PrintS("initEcartPairMora\n");
11848  else Print("%p\n",(void*)strat->initEcartPair);
11849  Print("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11850  strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11851  Print("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11852  strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11853  PrintS("chainCrit: ");
11854  if (strat->chainCrit==chainCritNormal) PrintS("chainCritNormal\n");
11855  else if (strat->chainCrit==chainCritOpt_1) PrintS("chainCritOpt_1\n");
11856  else Print("%p\n",(void*)strat->chainCrit);
11857  Print("posInLDependsOnLength=%d\n",
11858  strat->posInLDependsOnLength);
11859  PrintS(showOption());PrintLn();
11860  PrintS("LDeg: ");
11861  if (currRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11862  else if (currRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11863  else if (currRing->pLDeg==pLDegb) PrintS("pLDegb");
11864  else if (currRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11865  else if (currRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11866  else if (currRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11867  else if (currRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11868  else if (currRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11869  else if (currRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11870  else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11871  else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11872  else if (currRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11873  else Print("? (%lx)", (long)currRing->pLDeg);
11874  PrintS(" / ");
11875  if (strat->tailRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11876  else if (strat->tailRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11877  else if (strat->tailRing->pLDeg==pLDegb) PrintS("pLDegb");
11878  else if (strat->tailRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11879  else if (strat->tailRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11880  else if (strat->tailRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11881  else if (strat->tailRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11882  else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11883  else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11884  else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11885  else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11886  else if (strat->tailRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11887  else Print("? (%lx)", (long)strat->tailRing->pLDeg);
11888  PrintLn();
11889  PrintS("currRing->pFDeg: ");
11890  if (currRing->pFDeg==p_Totaldegree) PrintS("p_Totaldegree");
11891  else if (currRing->pFDeg==p_WFirstTotalDegree) PrintS("pWFirstTotalDegree");
11892  else if (currRing->pFDeg==p_Deg) PrintS("p_Deg");
11893  else if (currRing->pFDeg==kHomModDeg) PrintS("kHomModDeg");
11894  else if (currRing->pFDeg==totaldegreeWecart) PrintS("totaldegreeWecart");
11895  else if (currRing->pFDeg==p_WTotaldegree) PrintS("p_WTotaldegree");
11896  else Print("? (%lx)", (long)currRing->pFDeg);
11897  PrintLn();
11898  Print(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11899  if(TEST_OPT_DEGBOUND)
11900  Print(" degBound: %d\n", Kstd1_deg);
11901 
11902  if( ecartWeights != NULL )
11903  {
11904  PrintS("ecartWeights: ");
11905  for (int i = rVar(currRing); i > 0; i--)
11906  Print("%hd ", ecartWeights[i]);
11907  PrintLn();
11909  }
11910 
11911 #ifndef SING_NDEBUG
11913 #endif
11914 }
11915 
11916 #ifdef HAVE_SHIFTBBA
11917 poly pMove2CurrTail(poly p, kStrategy strat)
11918 {
11919  /* assume: p is completely in currRing */
11920  /* produces an object with LM in curring
11921  and TAIL in tailring */
11922  if (pNext(p)!=NULL)
11923  {
11924  pNext(p) = prMoveR(pNext(p), /* src */ currRing, /* dest */ strat->tailRing);
11925  }
11926  return(p);
11927 }
11928 #endif
11929 
11930 #ifdef HAVE_SHIFTBBA
11931 poly pMoveCurrTail2poly(poly p, kStrategy strat)
11932 {
11933  /* assume: p has LM in curring and TAIL in tailring */
11934  /* convert it to complete currRing */
11935 
11936  /* check that LM is in currRing */
11938 
11939  if (pNext(p)!=NULL)
11940  {
11941  pNext(p) = prMoveR(pNext(p), /* src */ strat->tailRing, /* dest */currRing);
11942  }
11943  return(p);
11944 }
11945 #endif
11946 
11947 #ifdef HAVE_SHIFTBBA
11949 {
11950  /* restores a poly in currRing from LObject */
11951  LObject h = H;
11952  h.Copy();
11953  poly p;
11954  if (h.p == NULL)
11955  {
11956  if (h.t_p != NULL)
11957  {
11958  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing, /* dest. ring: */ currRing);
11959  return(p);
11960  }
11961  else
11962  {
11963  /* h.tp == NULL -> the object is NULL */
11964  return(NULL);
11965  }
11966  }
11967  /* we're here if h.p != NULL */
11968  if (h.t_p == NULL)
11969  {
11970  /* then h.p is the whole poly in currRing */
11971  p = h.p;
11972  return(p);
11973  }
11974  /* we're here if h.p != NULL and h.t_p != NULL */
11975  // clean h.p, get poly from t_p
11976  pNext(h.p)=NULL;
11977  pLmDelete(&h.p);
11978  p = prMoveR(h.t_p, /* source ring: */ strat->tailRing,
11979  /* dest. ring: */ currRing);
11980  // no need to clean h: we re-used the polys
11981  return(p);
11982 }
11983 #endif
11984 
11985 //LObject pCopyp2L(poly p, kStrategy strat)
11986 //{
11987  /* creates LObject from the poly in currRing */
11988  /* actually put p into L.p and make L.t_p=NULL : does not work */
11989 
11990 //}
11991 
11992 // poly pCopyL2p(LObject H, kStrategy strat)
11993 // {
11994 // /* restores a poly in currRing from LObject */
11995 // LObject h = H;
11996 // h.Copy();
11997 // poly p;
11998 // if (h.p == NULL)
11999 // {
12000 // if (h.t_p != NULL)
12001 // {
12002 // p = p_ShallowCopyDelete(h.t_p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12003 // return(p);
12004 // }
12005 // else
12006 // {
12007 // /* h.tp == NULL -> the object is NULL */
12008 // return(NULL);
12009 // }
12010 // }
12011 // /* we're here if h.p != NULL */
12012 
12013 // if (h.t_p == NULL)
12014 // {
12015 // /* then h.p is the whole poly in tailRing */
12016 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12017 // {
12018 // p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12019 // }
12020 // return(p);
12021 // }
12022 // /* we're here if h.p != NULL and h.t_p != NULL */
12023 // p = pCopy(pHead(h.p)); // in currRing
12024 // if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12025 // {
12026 // // pNext(p) = p_ShallowCopyDelete(pNext(h.t_p), (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12027 // poly pp = p_Copy(pNext(h.p), strat->tailRing);
12028 // // poly p3 = p_Copy(pNext(h.p), currRing); // error
12029 // // p_ShallowCopyDelete(pNext(h.p), currRing, strat->tailBin); // the same as pp
12030 // poly p5 = p_ShallowCopyDelete(pNext(h.p), strat->tailRing, strat->tailBin);
12031 // pNext(p) = p_ShallowCopyDelete(h.t_p, strat->tailRing, strat->tailBin);
12032 // poly p4 = p_Copy(h.t_p, strat->tailRing);
12033 // // if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
12034 // }
12035 // // pTest(p);
12036 // return(p);
12037 // }
12038 
12039 /*2
12040 * put the lcm(q,p) into the set B, q is the shift of some s[i]
12041 */
12042 #ifdef HAVE_SHIFTBBA
12043 static BOOLEAN enterOneStrongPolyShift (poly q, poly p, int /*ecart*/, int /*isFromQ*/, kStrategy strat, int atR, int /*ecartq*/, int /*qisFromQ*/, int shiftcount, int ifromS)
12044 {
12045  number d, s, t;
12046  /* assume(atR >= 0); */
12047  assume(ifromS <= strat->sl);
12049  poly m1, m2, gcd;
12050  //printf("\n--------------------------------\n");
12051  //pWrite(p);pWrite(si);
12052  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q), &s, &t, currRing->cf);
12053 
12054  if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
12055  {
12056  nDelete(&d);
12057  nDelete(&s);
12058  nDelete(&t);
12059  return FALSE;
12060  }
12061 
12062  assume(pIsInV(p));
12063 
12064  k_GetStrongLeadTerms(p, q, currRing, m1, m2, gcd, strat->tailRing);
12065 
12066  /* the V criterion */
12067  if (!pmIsInV(gcd))
12068  {
12069  strat->cv++;
12070  nDelete(&d);
12071  nDelete(&s);
12072  nDelete(&t);
12073  pLmFree(gcd);
12074  return FALSE;
12075  }
12076 
12077  // disabled for Letterplace because it is not so easy to check
12078  /* if (!rHasLocalOrMixedOrdering(currRing)) { */
12079  /* unsigned long sev = pGetShortExpVector(gcd); */
12080 
12081  /* for (int j = 0; j < strat->sl; j++) { */
12082  /* if (j == i) */
12083  /* continue; */
12084 
12085  /* if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) && */
12086  /* !(strat->sevS[j] & ~sev) && */
12087  /* p_LmDivisibleBy(strat->S[j], gcd, currRing)) { */
12088  /* nDelete(&d); */
12089  /* nDelete(&s); */
12090  /* nDelete(&t); */
12091  /* return FALSE; */
12092  /* } */
12093  /* } */
12094  /* } */
12095 
12096  poly m12, m22;
12097  assume(p_mFirstVblock(p, currRing) <= 1 || p_mFirstVblock(q, currRing) <= 1);
12099  k_SplitFrame(m2, m22, si_max(p_mFirstVblock(q, currRing), 1), currRing);
12100  // manually free the coeffs, because pSetCoeff0 is used in the next step
12101  n_Delete(&(m1->coef), currRing->cf);
12102  n_Delete(&(m2->coef), currRing->cf);
12103 
12104  //p_Test(m1,strat->tailRing);
12105  //p_Test(m2,strat->tailRing);
12106  /*if(!enterTstrong)
12107  {
12108  while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
12109  {
12110  memset(&(strat->P), 0, sizeof(strat->P));
12111  kStratChangeTailRing(strat);
12112  strat->P = *(strat->R[atR]);
12113  p_LmFree(m1, strat->tailRing);
12114  p_LmFree(m2, strat->tailRing);
12115  p_LmFree(gcd, currRing);
12116  k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
12117  }
12118  }*/
12119  pSetCoeff0(m1, s);
12120  pSetCoeff0(m2, t);
12121  pSetCoeff0(gcd, d);
12122  p_Test(m1,strat->tailRing);
12123  p_Test(m2,strat->tailRing);
12124  p_Test(m12,strat->tailRing);
12125  p_Test(m22,strat->tailRing);
12126  assume(pmIsInV(m1));
12127  assume(pmIsInV(m2));
12128  assume(pmIsInV(m12));
12129  assume(pmIsInV(m22));
12130  //printf("\n===================================\n");
12131  //pWrite(m1);pWrite(m2);pWrite(gcd);
12132 #ifdef KDEBUG
12133  if (TEST_OPT_DEBUG)
12134  {
12135  // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
12136  PrintS("m1 = ");
12137  p_wrp(m1, strat->tailRing);
12138  PrintS("m12 = ");
12139  p_wrp(m12, strat->tailRing);
12140  PrintS(" ; m2 = ");
12141  p_wrp(m2, strat->tailRing);
12142  PrintS(" ; m22 = ");
12143  p_wrp(m22, strat->tailRing);
12144  PrintS(" ; gcd = ");
12145  wrp(gcd);
12146  PrintS("\n--- create strong gcd poly: ");
12147  PrintS("\n p: ");
12148  wrp(p);
12149  Print("\n q (strat->S[%d]): ", ifromS);
12150  wrp(q);
12151  PrintS(" ---> ");
12152  }
12153 #endif
12154 
12155  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);
12156  p_LmDelete(m1, strat->tailRing);
12157  p_LmDelete(m2, strat->tailRing);
12158  p_LmDelete(m12, strat->tailRing);
12159  p_LmDelete(m22, strat->tailRing);
12160 
12161  assume(pIsInV(gcd));
12162 
12163 #ifdef KDEBUG
12164  if (TEST_OPT_DEBUG)
12165  {
12166  wrp(gcd);
12167  PrintLn();
12168  }
12169 #endif
12170 
12171  LObject h;
12172  h.p = gcd;
12173  h.tailRing = strat->tailRing;
12174  int posx;
12175  strat->initEcart(&h);
12176  h.sev = pGetShortExpVector(h.p);
12177  h.i_r1 = -1;h.i_r2 = -1;
12178  if (currRing!=strat->tailRing)
12179  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12180 #if 1
12181  h.p1 = p;
12182  h.p2 = q;
12183 #endif
12184  if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12185  {
12186  h.i_r2 = kFindInT(h.p1, strat);
12187  h.i_r1 = atR;
12188  }
12189  else
12190  {
12191  h.i_r1 = -1;
12192  h.i_r2 = -1;
12193  }
12194  if (strat->Ll==-1)
12195  posx =0;
12196  else
12197  posx = strat->posInL(strat->L,strat->Ll,&h,strat);
12198 
12199  assume(pIsInV(h.p));
12200  assume(pIsInV(h.p1));
12201 
12202  enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
12203  return TRUE;
12204 }
12205 #endif
12206 
12207 
12208 /*2
12209 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i] (ring case)
12210 */
12211 #ifdef HAVE_SHIFTBBA
12212 static void enterOnePairRingShift (poly q, poly p, int /*ecart*/, int isFromQ, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
12213 {
12214  /* assume(atR >= 0); */
12215  /* assume(i<=strat->sl); */
12216  assume(p!=NULL);
12218  assume(pIsInV(p));
12219  #if ALL_VS_JUST
12220  //Over rings, if we construct the strong pair, do not add the spair
12222  {
12223  number s,t,d;
12224  d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q, &s, &t, currRing->cf);
12225 
12226  if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
12227  {
12228  nDelete(&d);
12229  nDelete(&s);
12230  nDelete(&t);
12231  return;
12232  }
12233  nDelete(&d);
12234  nDelete(&s);
12235  nDelete(&t);
12236  }
12237  #endif
12238  int j,compare,compareCoeff;
12239  LObject h;
12240 
12241 #ifdef KDEBUG
12242  h.ecart=0; h.length=0;
12243 #endif
12244  /*- computes the lcm(s[i],p) -*/
12245  if(pHasNotCFRing(p,q))
12246  {
12247  strat->cp++;
12248  return;
12249  }
12250  h.lcm = p_Lcm(p,q,currRing);
12251  pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(q), currRing->cf));
12252  if (nIsZero(pGetCoeff(h.lcm)))
12253  {
12254  strat->cp++;
12255  pLmDelete(h.lcm);
12256  return;
12257  }
12258 
12259  /* the V criterion */
12260  if (!pmIsInV(h.lcm))
12261  {
12262  strat->cv++;
12263  pLmDelete(h.lcm);
12264  return;
12265  }
12266  // basic chain criterion
12267  /*
12268  *the set B collects the pairs of type (S[j],p)
12269  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
12270  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12271  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12272  */
12273 
12274  for(j = strat->Bl;j>=0;j--)
12275  {
12276  compare=pDivCompRing(strat->B[j].lcm,h.lcm);
12277  compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
12278  if(compare == pDivComp_EQUAL)
12279  {
12280  //They have the same LM
12281  if(compareCoeff == pDivComp_LESS)
12282  {
12283  if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12284  {
12285  strat->c3++;
12286  pLmDelete(h.lcm);
12287  return;
12288  }
12289  break;
12290  }
12291  if(compareCoeff == pDivComp_GREATER)
12292  {
12293  deleteInL(strat->B,&strat->Bl,j,strat);
12294  strat->c3++;
12295  }
12296  if(compareCoeff == pDivComp_EQUAL)
12297  {
12298  if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12299  {
12300  strat->c3++;
12301  pLmDelete(h.lcm);
12302  return;
12303  }
12304  break;
12305  }
12306  }
12307  if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
12308  {
12309  if(compare == pDivComp_LESS)
12310  {
12311  if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12312  {
12313  strat->c3++;
12314  pLmDelete(h.lcm);
12315  return;
12316  }
12317  break;
12318  }
12319  if(compare == pDivComp_GREATER)
12320  {
12321  deleteInL(strat->B,&strat->Bl,j,strat);
12322  strat->c3++;
12323  }
12324  }
12325  }
12326  number s, t;
12327  poly m1, m2, gcd = NULL;
12328  s = pGetCoeff(q);
12329  t = pGetCoeff(p);
12330  k_GetLeadTerms(p,q,currRing,m1,m2,currRing);
12331 
12332  poly m12, m22;
12333  assume(p_mFirstVblock(p, currRing) <= 1 || p_mFirstVblock(q, currRing) <= 1);
12335  k_SplitFrame(m2, m22, si_max(p_mFirstVblock(q, currRing), 1), currRing);
12336  // manually free the coeffs, because pSetCoeff0 is used in the next step
12337  n_Delete(&(m1->coef), currRing->cf);
12338  n_Delete(&(m2->coef), currRing->cf);
12339 
12340  ksCheckCoeff(&s, &t, currRing->cf);
12341  pSetCoeff0(m1, s);
12342  pSetCoeff0(m2, t);
12343  m2 = pNeg(m2);
12344  p_Test(m1,strat->tailRing);
12345  p_Test(m2,strat->tailRing);
12346  p_Test(m12,strat->tailRing);
12347  p_Test(m22,strat->tailRing);
12348  assume(pmIsInV(m1));
12349  assume(pmIsInV(m2));
12350  assume(pmIsInV(m12));
12351  assume(pmIsInV(m22));
12352  poly pm1 = pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing);
12353  poly sim2 = pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing);
12354  assume(pIsInV(pm1));
12355  assume(pIsInV(sim2));
12356  p_LmDelete(m1, currRing);
12357  p_LmDelete(m2, currRing);
12358  p_LmDelete(m12, currRing);
12359  p_LmDelete(m22, currRing);
12360  if(sim2 == NULL)
12361  {
12362  if(pm1 == NULL)
12363  {
12364  if(h.lcm != NULL)
12365  {
12366  pLmDelete(h.lcm);
12367  h.lcm=NULL;
12368  }
12369  h.Clear();
12370  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12371  /* if (strat->pairtest==NULL) initPairtest(strat); */
12372  /* strat->pairtest[i] = TRUE; */
12373  /* strat->pairtest[strat->sl+1] = TRUE; */
12374  return;
12375  }
12376  else
12377  {
12378  gcd = pm1;
12379  pm1 = NULL;
12380  }
12381  }
12382  else
12383  {
12384  if((pGetComp(q) == 0) && (0 != pGetComp(p)))
12385  {
12386  p_SetCompP(sim2, pGetComp(p), strat->tailRing);
12387  pSetmComp(sim2);
12388  }
12389  //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
12390  gcd = p_Add_q(pm1, sim2, strat->tailRing);
12391  }
12392  p_Test(gcd, strat->tailRing);
12393  assume(pIsInV(gcd));
12394 #ifdef KDEBUG
12395  if (TEST_OPT_DEBUG)
12396  {
12397  wrp(gcd);
12398  PrintLn();
12399  }
12400 #endif
12401  h.p = gcd;
12402  h.i_r = -1;
12403  if(h.p == NULL)
12404  {
12405  /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12406  /* if (strat->pairtest==NULL) initPairtest(strat); */
12407  /* strat->pairtest[i] = TRUE; */
12408  /* strat->pairtest[strat->sl+1] = TRUE; */
12409  return;
12410  }
12411  h.tailRing = strat->tailRing;
12412  int posx;
12413  //h.pCleardenom();
12414  //pSetm(h.p);
12415  h.i_r1 = -1;h.i_r2 = -1;
12416  strat->initEcart(&h);
12417  #if 1
12418  h.p1 = p;
12419  h.p2 = q;
12420  #endif
12421  #if 1
12422  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12423  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12424  if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12425  {
12426  h.i_r2 = kFindInT(h.p1, strat); //strat->S_2_R[i];
12427  h.i_r1 = atR;
12428  }
12429  else
12430  {
12431  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12432  h.i_r1 = -1;
12433  h.i_r2 = -1;
12434  }
12435  #endif
12436  if (strat->Bl==-1)
12437  posx =0;
12438  else
12439  posx = strat->posInL(strat->B,strat->Bl,&h,strat);
12440  h.sev = pGetShortExpVector(h.p);
12441  if (currRing!=strat->tailRing)
12442  h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12443 
12444  assume(pIsInV(h.p));
12445  assume(pIsInV(h.p1));
12446  assume(h.lcm != NULL);
12447  assume(pIsInV(h.lcm));
12448 
12449  enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
12450  kTest_TS(strat);
12451 }
12452 #endif
12453 
12454 #ifdef HAVE_SHIFTBBA
12455 // adds the strong pair and the normal pair for rings (aka gpoly and spoly)
12456 static void enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12457 {
12458  enterOneStrongPolyShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "gpoly"
12459  enterOnePairRingShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "spoly"
12460 }
12461 #endif
12462 
12463 #ifdef HAVE_SHIFTBBA
12464 // creates if possible (q,p), (shifts(q),p)
12465 static void enterOnePairWithShifts (int q_inS /*also i*/, poly q, poly p, int ecartp, int p_isFromQ, kStrategy strat, int /*atR*/, int p_lastVblock, int q_lastVblock)
12466 {
12467  // note: ecart and isFromQ is for p
12468  assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12469  assume(pmFirstVblock(p) == 1);
12470  assume(pmFirstVblock(q) == 1);
12471  assume(p_lastVblock == pmLastVblock(p));
12472  assume(q_lastVblock == pmLastVblock(q));
12473 
12474  // TODO: is ecartq = 0 still ok?
12475  int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12476 
12477  int q_isFromQ = 0;
12478  if (strat->fromQ != NULL && q_inS >= 0)
12479  q_isFromQ = strat->fromQ[q_inS];
12480 
12481  void (*enterPair)(poly, poly, int, int, kStrategy, int, int, int, int, int);
12482 #ifdef HAVE_RINGS
12483  if (rField_is_Ring(currRing))
12485  else
12486 #endif
12487  enterPair = enterOnePairShift;
12488 
12489  int degbound = currRing->N/currRing->isLPring;
12490  int neededShift = p_lastVblock - ((pGetComp(p) > 0 || pGetComp(q) > 0) ? 0 : 1); // in the module case, product criterion does not hold
12491  int maxPossibleShift = degbound - q_lastVblock;
12492  int maxShift = si_min(neededShift, maxPossibleShift);
12493  int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12494  for (int j = firstShift; j <= maxShift; j++)
12495  {
12496  poly qq = pLPCopyAndShiftLM(q, j);
12497  enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS);
12498  // TODO: dekete qq, if not it does not enter the pair set
12499  }
12500 
12501 #ifdef HAVE_RINGS
12502  if (rField_is_Ring(currRing) && p_lastVblock >= firstShift && p_lastVblock <= maxPossibleShift)
12503  {
12504  // add pairs (m*shifts(q), p) where m is a monomial and the pair has no overlap
12505  for (int j = p_lastVblock; j <= maxPossibleShift; j++)
12506  {
12507  ideal fillers = id_MaxIdeal(j - p_lastVblock, currRing);
12508  for (int k = 0; k < IDELEMS(fillers); k++)
12509  {
12510  poly qq = pLPCopyAndShiftLM(pp_mm_Mult(q, fillers->m[k], currRing), p_lastVblock);
12511  enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, p_lastVblock, q_inS);
12512  }
12513  idDelete(&fillers);
12514  }
12515  }
12516 #endif
12517 }
12518 #endif
12519 
12520 #ifdef HAVE_SHIFTBBA
12521 // creates (q,p), use it when q is already shifted
12522 static void enterOnePairWithoutShifts (int p_inS /*also i*/, poly q, poly p, int ecartq, int q_isFromQ, kStrategy strat, int /*atR*/, int p_lastVblock, int q_shift)
12523 {
12524  // note: ecart and isFromQ is for p
12525  assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12526  assume(pmFirstVblock(p) == 1);
12527  assume(p_lastVblock == pmLastVblock(p));
12528  assume(q_shift == pmFirstVblock(q) - 1);
12529 
12530  // TODO: is ecartp = 0 still ok?
12531  int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12532 
12533  int p_isFromQ = 0;
12534  if (strat->fromQ != NULL && p_inS >= 0)
12535  p_isFromQ = strat->fromQ[p_inS];
12536 
12537 #ifdef HAVE_RINGS
12538  if (rField_is_Ring(currRing))
12539  {
12540  assume(q_shift <= p_lastVblock); // we allow the special case where there is no overlap
12541  enterOneStrongPolyAndEnterOnePairRingShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12542  }
12543  else
12544 #endif
12545  {
12546  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)
12547  enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12548  }
12549 }
12550 #endif
12551 
12552 
12553 #ifdef KDEBUG
12554 // enable to print which pairs are considered or discarded and why
12555 /* #define CRITERION_DEBUG */
12556 #endif
12557 /*2
12558 * put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12559 */
12560 #ifdef HAVE_SHIFTBBA
12561 void enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12562 {
12563 #ifdef CRITERION_DEBUG
12564  if (TEST_OPT_DEBUG)
12565  {
12566  PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12567  // also write the LMs in separate lines:
12568  poly lmq = pHead(q);
12569  poly lmp = pHead(p);
12570  pSetCoeff(lmq, n_Init(1, currRing->cf));
12571  pSetCoeff(lmp, n_Init(1, currRing->cf));
12572  Print(" %s\n", pString(lmq));
12573  Print(" %s\n", pString(lmp));
12574  pLmDelete(lmq);
12575  pLmDelete(lmp);
12576  }
12577 #endif
12578 
12579  /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12580 
12581  /* check this Formats: */
12583  assume(p_CheckIsFromRing(pNext(q),strat->tailRing));
12586 
12587  /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12588 
12589  int qfromQ = qisFromQ;
12590 
12591  /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12592 
12593  int l,j,compare;
12594  LObject Lp;
12595  Lp.i_r = -1;
12596 
12597 #ifdef KDEBUG
12598  Lp.ecart=0; Lp.length=0;
12599 #endif
12600  /*- computes the lcm(s[i],p) -*/
12601  Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12602 
12603  /* the V criterion */
12604  if (!pmIsInV(Lp.lcm))
12605  {
12606  strat->cv++; // counter for applying the V criterion
12607  pLmFree(Lp.lcm);
12608 #ifdef CRITERION_DEBUG
12609  if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12610 #endif
12611  return;
12612  }
12613 
12614  if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12615  {
12616  if((!((ecartq>0)&&(ecart>0)))
12617  && pHasNotCF(p,q))
12618  {
12619  /*
12620  *the product criterion has applied for (s,p),
12621  *i.e. lcm(s,p)=product of the leading terms of s and p.
12622  *Suppose (s,r) is in L and the leading term
12623  *of p divides lcm(s,r)
12624  *(==> the leading term of p divides the leading term of r)
12625  *but the leading term of s does not divide the leading term of r
12626  *(notice that this condition is automatically satisfied if r is still
12627  *in S), then (s,r) can be cancelled.
12628  *This should be done here because the
12629  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12630  *
12631  *Moreover, skipping (s,r) holds also for the noncommutative case.
12632  */
12633  strat->cp++;
12634  pLmFree(Lp.lcm);
12635 #ifdef CRITERION_DEBUG
12636  if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12637 #endif
12638  return;
12639  }
12640  else
12641  Lp.ecart = si_max(ecart,ecartq);
12642  if (strat->fromT && (ecartq>ecart))
12643  {
12644  pLmFree(Lp.lcm);
12645 #ifdef CRITERION_DEBUG
12646  if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12647 #endif
12648  return;
12649  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12650  }
12651  /*
12652  *the set B collects the pairs of type (S[j],p)
12653  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12654  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12655  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12656  */
12657  {
12658  j = strat->Bl;
12659  loop
12660  {
12661  if (j < 0) break;
12662  compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12663  if ((compare==1)
12664  &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12665  {
12666  strat->c3++;
12667  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12668  {
12669  pLmFree(Lp.lcm);
12670 #ifdef CRITERION_DEBUG
12671  if (TEST_OPT_DEBUG)
12672  {
12673  Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12674  }
12675 #endif
12676  return;
12677  }
12678  break;
12679  }
12680  else
12681  if ((compare ==-1)
12682  && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12683  {
12684 #ifdef CRITERION_DEBUG
12685  if (TEST_OPT_DEBUG)
12686  {
12687  Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12688  }
12689 #endif
12690  deleteInL(strat->B,&strat->Bl,j,strat);
12691  strat->c3++;
12692  }
12693  j--;
12694  }
12695  }
12696  }
12697  else /*sugarcrit*/
12698  {
12699  if (ALLOW_PROD_CRIT(strat))
12700  {
12701  // if currRing->nc_type!=quasi (or skew)
12702  // TODO: enable productCrit for super commutative algebras...
12703  if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12704  pHasNotCF(p,q))
12705  {
12706  /*
12707  *the product criterion has applied for (s,p),
12708  *i.e. lcm(s,p)=product of the leading terms of s and p.
12709  *Suppose (s,r) is in L and the leading term
12710  *of p divides lcm(s,r)
12711  *(==> the leading term of p divides the leading term of r)
12712  *but the leading term of s does not divide the leading term of r
12713  *(notice that tis condition is automatically satisfied if r is still
12714  *in S), then (s,r) can be canceled.
12715  *This should be done here because the
12716  *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12717  */
12718  strat->cp++;
12719  pLmFree(Lp.lcm);
12720 #ifdef CRITERION_DEBUG
12721  if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12722 #endif
12723  return;
12724  }
12725  if (strat->fromT && (ecartq>ecart))
12726  {
12727  pLmFree(Lp.lcm);
12728 #ifdef CRITERION_DEBUG
12729  if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12730 #endif
12731  return;
12732  /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12733  }
12734  /*
12735  *the set B collects the pairs of type (S[j],p)
12736  *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12737  *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12738  *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12739  */
12740  for(j = strat->Bl;j>=0;j--)
12741  {
12742  compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12743  if (compare==1)
12744  {
12745  strat->c3++;
12746  if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12747  {
12748  pLmFree(Lp.lcm);
12749 #ifdef CRITERION_DEBUG
12750  if (TEST_OPT_DEBUG)
12751  {
12752  Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12753  }
12754 #endif
12755  return;
12756  }
12757  break;
12758  }
12759  else
12760  if (compare ==-1)
12761  {
12762 #ifdef CRITERION_DEBUG
12763  if (TEST_OPT_DEBUG)
12764  {
12765  Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12766  }
12767 #endif
12768  deleteInL(strat->B,&strat->Bl,j,strat);
12769  strat->c3++;
12770  }
12771  }
12772  }
12773  }
12774  /*
12775  *the pair (S[i],p) enters B if the spoly != 0
12776  */
12777  /*- compute the short s-polynomial -*/
12778  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12779  pNorm(p);
12780  if ((q==NULL) || (p==NULL))
12781  {
12782 #ifdef CRITERION_DEBUG
12783  if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
12784 #endif
12785  return;
12786  }
12787  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12788  {
12789  Lp.p=NULL;
12790 #ifdef CRITERION_DEBUG
12791  if (TEST_OPT_DEBUG) PrintS("--- pair is from Q\n");
12792 #endif
12793  }
12794  else
12795  {
12796 // if ( rIsPluralRing(currRing) )
12797 // {
12798 // if(pHasNotCF(p, q))
12799 // {
12800 // if(ncRingType(currRing) == nc_lie)
12801 // {
12802 // // generalized prod-crit for lie-type
12803 // strat->cp++;
12804 // Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12805 // }
12806 // else
12807 // if( ALLOW_PROD_CRIT(strat) )
12808 // {
12809 // // product criterion for homogeneous case in SCA
12810 // strat->cp++;
12811 // Lp.p = NULL;
12812 // }
12813 // else
12814 // Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12815 // }
12816 // else Lp.p = nc_CreateSpoly(q,p,currRing);
12817 // }
12818 // else
12819 // {
12820 
12821  /* ksCreateShortSpoly needs two Lobject-kind presentations */
12822  /* p is already in this form, so convert q */
12823  // q = pMove2CurrTail(q, strat);
12824  Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12825  // }
12826  }
12827  if (Lp.p == NULL)
12828  {
12829  /*- the case that the s-poly is 0 -*/
12830  // TODO: currently ifromS is only > 0 if called from enterOnePairWithShifts
12831  if (ifromS > 0)
12832  {
12833  if (strat->pairtest==NULL) initPairtest(strat);
12834  strat->pairtest[ifromS] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12835  strat->pairtest[strat->sl+1] = TRUE;
12836  }
12837  //if (TEST_OPT_DEBUG){Print("!");} // option teach
12838  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12839  /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12840  /*
12841  *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12842  *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12843  *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12844  *term of p divides the lcm(s,r)
12845  *(this canceling should be done here because
12846  *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12847  *the first case is handeled in chainCrit
12848  */
12849  if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12850 #ifdef CRITERION_DEBUG
12851  if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
12852 #endif
12853  }
12854  else
12855  {
12856  /*- the pair (S[i],p) enters B -*/
12857  /* both of them should have their LM in currRing and TAIL in tailring */
12858  Lp.p1 = q; // already in the needed form
12859  Lp.p2 = p; // already in the needed form
12860 
12861  if ( !rIsPluralRing(currRing) )
12862  pNext(Lp.p) = strat->tail;
12863 
12864  /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12865  /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12866  if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12867  {
12868  Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12869  Lp.i_r2 = atR;
12870  }
12871  else
12872  {
12873  /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12874  Lp.i_r1 = -1;
12875  Lp.i_r2 = -1;
12876  }
12877  strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12878 
12880  {
12881  if (!rIsPluralRing(currRing)
12883  && (Lp.p->coef!=NULL))
12884  nDelete(&(Lp.p->coef));
12885  }
12886 
12887  l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12888  enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12889 #ifdef CRITERION_DEBUG
12890  if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
12891 #endif
12892  }
12893 }
12894 #endif
12895 
12896 /*3
12897 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12898 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12899 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
12900 */
12901 #ifdef HAVE_SHIFTBBA
12902 void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12903 {
12904  int h_lastVblock = pmLastVblock(h);
12905  assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12906  // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12907  if (h_lastVblock == 0) return;
12908  assume(pmFirstVblock(h) == 1);
12909  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12910  // atR = -1;
12911  if ((strat->syzComp==0)
12912  || (pGetComp(h)<=strat->syzComp))
12913  {
12914  int i,j;
12915  BOOLEAN new_pair=FALSE;
12916 
12917  int degbound = currRing->N/currRing->isLPring;
12918  int maxShift = degbound - h_lastVblock;
12919 
12920  if (pGetComp(h)==0)
12921  {
12922  if (strat->rightGB)
12923  {
12924  if (isFromQ)
12925  {
12926  // pairs (shifts(h),s[1..k]), (h, s[1..k])
12927  for (i=0; i<=maxShift; i++)
12928  {
12929  poly hh = pLPCopyAndShiftLM(h, i);
12930  for (j=0; j<=k; j++)
12931  {
12932  if (strat->fromQ == NULL || !strat->fromQ[j])
12933  {
12934  new_pair=TRUE;
12935  poly s = strat->S[j];
12936  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12937  }
12938  }
12939  }
12940  }
12941  else
12942  {
12943  new_pair=TRUE;
12944  for (j=0; j<=k; j++)
12945  {
12946  poly s = strat->S[j];
12947  if (strat->fromQ != NULL && strat->fromQ[j])
12948  {
12949  // pairs (shifts(s[j]),h), (s[j],h)
12950  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12951  }
12952  else
12953  {
12954  // pair (h, s[j])
12955  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12956  }
12957  }
12958  }
12959  }
12960  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12961  else if ((isFromQ)&&(strat->fromQ!=NULL))
12962  {
12963  // pairs (shifts(s[1..k]),h), (s[1..k],h)
12964  for (j=0; j<=k; j++)
12965  {
12966  if (!strat->fromQ[j])
12967  {
12968  new_pair=TRUE;
12969  poly s = strat->S[j];
12970  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12971  }
12972  }
12973  // pairs (shifts(h),s[1..k])
12974  if (new_pair)
12975  {
12976  for (i=1; i<=maxShift; i++)
12977  {
12978  poly hh = pLPCopyAndShiftLM(h, i);
12979  for (j=0; j<=k; j++)
12980  {
12981  if (!strat->fromQ[j])
12982  {
12983  poly s = strat->S[j];
12984  int s_lastVblock = pmLastVblock(s);
12985  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)
12986  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
12987 #ifdef HAVE_RINGS
12988  else if (rField_is_Ring(currRing))
12989  {
12990  assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12991  ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12992  for (int k = 0; k < IDELEMS(fillers); k++)
12993  {
12994  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12995  enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12996  }
12997  idDelete(&fillers);
12998  }
12999 #endif
13000  }
13001  }
13002  }
13003  }
13004  }
13005  else
13006  {
13007  new_pair=TRUE;
13008  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13009  for (j=0; j<=k; j++)
13010  {
13011  poly s = strat->S[j];
13012  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13013  }
13014  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13015  for (i=1; i<=maxShift; i++)
13016  {
13017  poly hh = pLPCopyAndShiftLM(h, i);
13018  for (j=0; j<=k; j++)
13019  {
13020  poly s = strat->S[j];
13021  int s_lastVblock = pmLastVblock(s);
13022  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)
13023  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
13024 #ifdef HAVE_RINGS
13025  else if (rField_is_Ring(currRing))
13026  {
13027  assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13028  ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13029  for (int k = 0; k < IDELEMS(fillers); k++)
13030  {
13031  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13032  enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13033  }
13034  idDelete(&fillers);
13035  }
13036 #endif
13037  }
13038  if (i < h_lastVblock) // in the module case, product criterion does not hold (note: comp h is always zero here)
13039  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13040 #ifdef HAVE_RINGS
13041  else if (rField_is_Ring(currRing))
13042  {
13043  assume(i >= h_lastVblock); // this is always the case, but just to be very sure
13044  ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
13045  for (int k = 0; k < IDELEMS(fillers); k++)
13046  {
13047  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
13048  enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock);
13049  }
13050  idDelete(&fillers);
13051  }
13052 #endif
13053  }
13054  }
13055  }
13056  else
13057  {
13058  assume(isFromQ == 0); // an element from Q should always has 0 component
13059  new_pair=TRUE;
13060  if (strat->rightGB)
13061  {
13062  for (j=0; j<=k; j++)
13063  {
13064  if ((pGetComp(h)==pGetComp(strat->S[j]))
13065  || (pGetComp(strat->S[j])==0))
13066  {
13067  poly s = strat->S[j];
13068  if (strat->fromQ != NULL && strat->fromQ[j])
13069  {
13070  // pairs (shifts(s[j]),h), (s[j],h)
13071  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13072  }
13073  else
13074  {
13075  // pair (h, s[j])
13076  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13077  }
13078  }
13079  }
13080  }
13081  else
13082  {
13083  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13084  for (j=0; j<=k; j++)
13085  {
13086  if ((pGetComp(h)==pGetComp(strat->S[j]))
13087  || (pGetComp(strat->S[j])==0))
13088  {
13089  poly s = strat->S[j];
13090  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13091  }
13092  }
13093  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13094  for (i=1; i<=maxShift; i++)
13095  {
13096  poly hh = pLPCopyAndShiftLM(h, i);
13097  for (j=0; j<=k; j++)
13098  {
13099  if ((pGetComp(h)==pGetComp(strat->S[j]))
13100  || (pGetComp(strat->S[j])==0))
13101  {
13102  poly s = strat->S[j];
13103  int s_lastVblock = pmLastVblock(s);
13104  if (i <= s_lastVblock) // in the module case, product criterion does not hold
13105  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
13106 #ifdef HAVE_RINGS
13107  else if (rField_is_Ring(currRing))
13108  {
13109  assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13110  ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13111  for (int k = 0; k < IDELEMS(fillers); k++)
13112  {
13113  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13114  enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13115  }
13116  idDelete(&fillers);
13117  }
13118 #endif
13119  }
13120  }
13121  if (i <= h_lastVblock) // in the module case, product criterion does not hold
13122  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13123 #ifdef HAVE_RINGS
13124  else if (rField_is_Ring(currRing))
13125  {
13126  assume(i >= h_lastVblock); // this is always the case, but just to be very sure
13127  ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
13128  for (int k = 0; k < IDELEMS(fillers); k++)
13129  {
13130  poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
13131  enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock);
13132  }
13133  idDelete(&fillers);
13134  }
13135 #endif
13136  }
13137  }
13138  }
13139 
13140  if (new_pair)
13141  {
13142  strat->chainCrit(h,ecart,strat);
13143  }
13144  kMergeBintoL(strat);
13145  }
13146 }
13147 #endif
13148 
13149 /*3
13150 *(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
13151 * also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
13152 * additionally we put the pairs (h, s \sdot h) for s>=1 to L
13153 */
13154 #ifdef HAVE_SHIFTBBA
13155 void initenterstrongPairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
13156 {
13157  int h_lastVblock = pmLastVblock(h);
13158  assume(h_lastVblock != 0 || pLmIsConstantComp(h));
13159  // TODO: is it allowed to skip pairs with constants? also with constants from other components?
13160  if (h_lastVblock == 0) return;
13161  assume(pmFirstVblock(h) == 1);
13162  /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13163  // atR = -1;
13164  if ((strat->syzComp==0)
13165  || (pGetComp(h)<=strat->syzComp))
13166  {
13167  int i,j;
13168  BOOLEAN new_pair=FALSE;
13169 
13170  int degbound = currRing->N/currRing->isLPring;
13171  int maxShift = degbound - h_lastVblock;
13172 
13173  if (pGetComp(h)==0)
13174  {
13175  if (strat->rightGB)
13176  {
13177  if (isFromQ)
13178  {
13179  // pairs (shifts(h),s[1..k]), (h, s[1..k])
13180  for (i=0; i<=maxShift; i++)
13181  {
13182  poly hh = pLPCopyAndShiftLM(h, i);
13183  for (j=0; j<=k; j++)
13184  {
13185  if (strat->fromQ == NULL || !strat->fromQ[j])
13186  {
13187  new_pair=TRUE;
13188  poly s = strat->S[j];
13189  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13190  }
13191  }
13192  }
13193  }
13194  else
13195  {
13196  new_pair=TRUE;
13197  for (j=0; j<=k; j++)
13198  {
13199  poly s = strat->S[j];
13200  if (strat->fromQ != NULL && strat->fromQ[j])
13201  {
13202  // pairs (shifts(s[j]),h), (s[j],h)
13203  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13204  }
13205  else
13206  {
13207  // pair (h, s[j])
13208  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13209  }
13210  }
13211  }
13212  }
13213  /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
13214  else if ((isFromQ)&&(strat->fromQ!=NULL))
13215  {
13216  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13217  for (j=0; j<=k; j++)
13218  {
13219  if (!strat->fromQ[j])
13220  {
13221  new_pair=TRUE;
13222  poly s = strat->S[j];
13223  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13224  }
13225  }
13226  // pairs (shifts(h),s[1..k])
13227  if (new_pair)
13228  {
13229  for (i=1; i<=maxShift; i++)
13230  {
13231  poly hh = pLPCopyAndShiftLM(h, i);
13232  for (j=0; j<=k; j++)
13233  {
13234  if (!strat->fromQ[j])
13235  {
13236  poly s = strat->S[j];
13237  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13238  }
13239  }
13240  }
13241  }
13242  }
13243  else
13244  {
13245  new_pair=TRUE;
13246  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13247  for (j=0; j<=k; j++)
13248  {
13249  poly s = strat->S[j];
13250  // TODO: cache lastVblock of s[1..k] for later use
13251  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13252  }
13253  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13254  for (i=1; i<=maxShift; i++)
13255  {
13256  poly hh = pLPCopyAndShiftLM(h, i);
13257  for (j=0; j<=k; j++)
13258  {
13259  poly s = strat->S[j];
13260  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13261  }
13262  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13263  }
13264  }
13265  }
13266  else
13267  {
13268  new_pair=TRUE;
13269  if (strat->rightGB)
13270  {
13271  for (j=0; j<=k; j++)
13272  {
13273  if ((pGetComp(h)==pGetComp(strat->S[j]))
13274  || (pGetComp(strat->S[j])==0))
13275  {
13276  assume(isFromQ == 0); // this case is not handeled here and should also never happen
13277  poly s = strat->S[j];
13278  if (strat->fromQ != NULL && strat->fromQ[j])
13279  {
13280  // pairs (shifts(s[j]),h), (s[j],h)
13281  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13282  }
13283  else
13284  {
13285  // pair (h, s[j])
13286  enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13287  }
13288  }
13289  }
13290  }
13291  else
13292  {
13293  // pairs (shifts(s[1..k]),h), (s[1..k],h)
13294  for (j=0; j<=k; j++)
13295  {
13296  if ((pGetComp(h)==pGetComp(strat->S[j]))
13297  || (pGetComp(strat->S[j])==0))
13298  {
13299  poly s = strat->S[j];
13300  enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13301  }
13302  }
13303  // pairs (shifts(h),s[1..k]), (shifts(h), h)
13304  for (i=1; i<=maxShift; i++)
13305  {
13306  poly hh = pLPCopyAndShiftLM(h, i);
13307  for (j=0; j<=k; j++)
13308  {
13309  if ((pGetComp(h)==pGetComp(strat->S[j]))
13310  || (pGetComp(strat->S[j])==0))
13311  {
13312  poly s = strat->S[j];
13313  enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13314  }
13315  }
13316  enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13317  }
13318  }
13319  }
13320 
13321  if (new_pair)
13322  {
13323  strat->chainCrit(h,ecart,strat);
13324  }
13325  kMergeBintoL(strat);
13326  }
13327 }
13328 #endif
13329 
13330 /*2
13331 *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
13332 *superfluous elements in S will be deleted
13333 */
13334 #ifdef HAVE_SHIFTBBA
13335 void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
13336 {
13337  /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13338  /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
13339  int j=pos;
13340 
13341  /* if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat); */ // TODO: enterExtendedSpoly not for LP yet
13342  initenterpairsShift(h,k,ecart,0,strat, atR);
13343  if ( (!strat->fromT)
13344  && ((strat->syzComp==0)
13345  ||(pGetComp(h)<=strat->syzComp)))
13346  {
13347  unsigned long h_sev = pGetShortExpVector(h);
13348  loop
13349  {
13350  if (j > k) break;
13351  // TODO this currently doesn't clear all possible elements because of commutative division
13352  if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
13353  clearS(h,h_sev, &j,&k,strat);
13354  j++;
13355  }
13356  }
13357 }
13358 #endif
13359 
13360 /*2
13361 * enteres all admissible shifts of p into T
13362 * assumes that p is already in T!
13363 */
13364 #ifdef HAVE_SHIFTBBA
13365 void enterTShift(LObject p, kStrategy strat, int atT)
13366 {
13367  /* determine how many elements we have to insert */
13368  /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
13369  /* hence, a total number of elt's to add is: */
13370  /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
13371  pAssume(p.p != NULL);
13372 
13373  int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
13374 
13375  for (int i = 1; i <= maxPossibleShift; i++)
13376  {
13377  LObject qq;
13378  qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
13379  qq.shift = i;
13380  strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
13381 
13382  enterT(qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
13383  }
13384 }
13385 #endif
13386 
13387 #ifdef HAVE_SHIFTBBA
13388 poly redtailBbaShift (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
13389 {
13390  /* for the shift case need to run it with withT = TRUE */
13391  strat->redTailChange=FALSE;
13392  if (strat->noTailReduction) return L->GetLmCurrRing();
13393  poly h, p;
13394  p = h = L->GetLmTailRing();
13395  if ((h==NULL) || (pNext(h)==NULL))
13396  return L->GetLmCurrRing();
13397 
13398  TObject* With;
13399  // placeholder in case strat->tl < 0
13400  TObject With_s(strat->tailRing);
13401 
13402  LObject Ln(pNext(h), strat->tailRing);
13403  Ln.pLength = L->GetpLength() - 1;
13404 
13405  pNext(h) = NULL;
13406  if (L->p != NULL) pNext(L->p) = NULL;
13407  L->pLength = 1;
13408 
13409  Ln.PrepareRed(strat->use_buckets);
13410 
13411  while(!Ln.IsNull())
13412  {
13413  loop
13414  {
13415  Ln.SetShortExpVector();
13416  if (withT)
13417  {
13418  int j;
13419  j = kFindDivisibleByInT(strat, &Ln);
13420  if (j < 0) break;
13421  With = &(strat->T[j]);
13422  }
13423  else
13424  {
13425  With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
13426  if (With == NULL) break;
13427  }
13428  if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
13429  {
13430  With->pNorm();
13431  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
13432  }
13433  strat->redTailChange=TRUE;
13434  if (ksReducePolyTail(L, With, &Ln))
13435  {
13436  // reducing the tail would violate the exp bound
13437  // set a flag and hope for a retry (in bba)
13438  strat->completeReduce_retry=TRUE;
13439  if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
13440  do
13441  {
13442  pNext(h) = Ln.LmExtractAndIter();
13443  pIter(h);
13444  L->pLength++;
13445  } while (!Ln.IsNull());
13446  goto all_done;
13447  }
13448  if (Ln.IsNull()) goto all_done;
13449  if (! withT) With_s.Init(currRing);
13450  }
13451  pNext(h) = Ln.LmExtractAndIter();
13452  pIter(h);
13453  L->pLength++;
13454  }
13455 
13456  all_done:
13457  Ln.Delete();
13458  if (L->p != NULL) pNext(L->p) = pNext(p);
13459 
13460  if (strat->redTailChange)
13461  {
13462  L->length = 0;
13463  }
13464  L->Normalize(); // HANNES: should have a test
13465  kTest_L(L,strat);
13466  return L->GetLmCurrRing();
13467 }
13468 #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:11603
skStrategy()
Definition: kutil.cc:11583
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:969
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:1071
KINLINE int ksReducePolyTailLC_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1119
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1184
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1157
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1194
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1247
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:1028
KINLINE int ksReducePolyTail_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1137
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:1897
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:934
int redLazy(LObject *h, kStrategy strat)
Definition: kstd2.cc:1692
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:827
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:10130
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7730
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7093
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6551
#define pDivComp_LESS
Definition: kutil.cc:136
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6665
int getIndexRng(long coeff)
Definition: kutil.cc:6211
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6308
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5418
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10019
poly pMove2CurrTail(poly p, kStrategy strat)
Definition: kutil.cc:11917
int posInTrg0(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5091
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:797
VAR int HCord
Definition: kutil.cc:246
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3221
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:6900
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9598
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6052
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:169
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5014
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9396
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:4958
void enterTShift(LObject p, kStrategy strat, int atT)
Definition: kutil.cc:13365
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5209
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:6875
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9170
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:3989
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:7282
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5285
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:4947
poly pMoveCurrTail2poly(poly p, kStrategy strat)
Definition: kutil.cc:11931
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:1999
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:10792
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:13155
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4575
static void enterOnePairRingShift(poly q, poly p, int, int isFromQ, kStrategy strat, int atR, int, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12212
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1327
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:6816
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4492
static int pLPDivComp(poly p, poly q)
Definition: kutil.cc:232
int posInT2(const TSet set, const int length, LObject &p)
Definition: kutil.cc:4986
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6396
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6349
#define kFalseReturn(x)
Definition: kutil.cc:804
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11745
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:9830
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4549
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5256
void redtailBbaAlsoLC_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7398
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6767
static void deleteHCBucket(LObject *L, kStrategy strat)
Definition: kutil.cc:250
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9676
void chainCritSig(poly p, int, kStrategy strat)
Definition: kutil.cc:3516
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition: kutil.cc:4826
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1373
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4209
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4531
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8767
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5778
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:9846
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:3864
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7853
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11240
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7169
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7527
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11361
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:2262
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5752
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8349
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3500
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5050
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:1393
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8743
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition: kutil.cc:8655
poly pCopyL2p(LObject H, kStrategy strat)
Definition: kutil.cc:11948
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:12902
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4264
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3929
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6431
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:5525
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:13388
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11654
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5323
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9496
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:10982
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6732
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:5709
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:4374
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:13335
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2493
BOOLEAN kTest_L(LObject *L, kStrategy strat, BOOLEAN testp, int lpos, TSet T, int tlength)
Definition: kutil.cc:950
void enterOnePairShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12561
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:10104
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:7784
void initEcartNormal(TObject *h)
Definition: kutil.cc:1351
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:4725
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:8812
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8044
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6122
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3152
char * showOption()
Definition: misc_ip.cc:713
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6507
void initSyzRules(kStrategy strat)
Definition: kutil.cc:8194
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5810
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10232
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10753
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:2281
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5167
BOOLEAN kTest_S(kStrategy strat)
Definition: kutil.cc:1079
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:5970
void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
Definition: kutil.cc:9305
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:4672
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4291
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6466
#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:3242
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:294
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10347
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4518
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition: kutil.cc:1384
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5652
static void enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12456
#define pDivComp_GREATER
Definition: kutil.cc:137
void exitSba(kStrategy strat)
Definition: kutil.cc:10307
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition: kutil.cc:6951
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5377
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5479
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition: kutil.cc:1597
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition: kutil.cc:11779
int posInLrg0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6224
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1270
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11333
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3575
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1615
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9694
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:628
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5586
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:10559
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6601
static void 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:12522
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:9932
int kFindInTShift(poly p, TSet T, int tlength)
Definition: kutil.cc:767
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:11058
static void 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:12465
static BOOLEAN enterOneStrongPolyShift(poly q, poly p, int, int, kStrategy strat, int atR, int, int, int shiftcount, int ifromS)
Definition: kutil.cc:12043
void messageSets(kStrategy strat)
Definition: kutil.cc:7803
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1163
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8638
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11708
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5834
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:1747
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6086
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:10815
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:4598
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3264
void initEcartBBA(TObject *h)
Definition: kutil.cc:1359
VAR denominator_list DENOMINATOR_LIST
Definition: kutil.cc:84
int posInLRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5897
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2750
void enterSBbaShift(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9147
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6010
poly redtailBba_Ring(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7641
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:5998
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:539
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1366
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7771
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1805
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:4051
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8493
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7947
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:4903
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:11147
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9047
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:9759
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10681
#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
#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:873
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:795
int p_mFirstVblock(poly p, const ring ri)
Definition: shiftop.cc:477
void k_SplitFrame(poly &m1, poly &m2, int at, const ring r)
Definition: shiftop.cc:599
void p_mLPshift(poly m, int sh, const ring ri)
Definition: shiftop.cc:361
#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:41
@ isNotHomog
Definition: structs.h:40
skStrategy * kStrategy
Definition: structs.h:62
#define loop
Definition: structs.h:79
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