My Project
Loading...
Searching...
No Matches
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
55#include "polys/kbuckets.h"
56#include "coeffs/numbers.h"
57#include "kernel/polys.h"
59#include "kernel/ideals.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 DEBUGF5
75#undef DEBUGF5
76#define DEBUGF5 2
77#endif
78
80
81
82#ifdef ENTER_USE_MYMEMMOVE
83inline void _my_memmove_d_gt_s(unsigned long* d, unsigned long* s, long l)
84{
85 REGISTER unsigned long* _dl = (unsigned long*) d;
86 REGISTER unsigned long* _sl = (unsigned long*) s;
87 REGISTER long _i = l - 1;
88
89 do
90 {
91 _dl[_i] = _sl[_i];
92 _i--;
93 }
94 while (_i >= 0);
95}
96
97inline void _my_memmove_d_lt_s(unsigned long* d, unsigned long* s, long l)
98{
99 REGISTER long _ll = l;
100 REGISTER unsigned long* _dl = (unsigned long*) d;
101 REGISTER unsigned long* _sl = (unsigned long*) s;
102 REGISTER long _i = 0;
103
104 do
105 {
106 _dl[_i] = _sl[_i];
107 _i++;
108 }
109 while (_i < _ll);
110}
111
112inline void _my_memmove(void* d, void* s, long l)
113{
114 unsigned long _d = (unsigned long) d;
115 unsigned long _s = (unsigned long) s;
116 unsigned long _l = ((l) + SIZEOF_LONG - 1) >> LOG_SIZEOF_LONG;
117
118 if (_d > _s) _my_memmove_d_gt_s(_d, _s, _l);
119 else _my_memmove_d_lt_s(_d, _s, _l);
120}
121
122#undef memmove
123#define memmove(d,s,l) _my_memmove(d, s, l)
124#endif
125
126static poly redMora (poly h,int maxIndex,kStrategy strat);
127static poly redBba (poly h,int maxIndex,kStrategy strat);
128
129#define pDivComp_EQUAL 2
130#define pDivComp_LESS 1
131#define pDivComp_GREATER -1
132#define pDivComp_INCOMP 0
133/* Checks the relation of LM(p) and LM(q)
134 LM(p) = LM(q) => return pDivComp_EQUAL
135 LM(p) | LM(q) => return pDivComp_LESS
136 LM(q) | LM(p) => return pDivComp_GREATER
137 else return pDivComp_INCOMP */
138static inline int pDivCompRing(poly p, poly q)
139{
140 if ((currRing->pCompIndex < 0)
142 {
143 BOOLEAN a=FALSE, b=FALSE;
144 int i;
145 unsigned long la, lb;
146 unsigned long divmask = currRing->divmask;
147 for (i=0; i<currRing->VarL_Size; i++)
148 {
149 la = p->exp[currRing->VarL_Offset[i]];
150 lb = q->exp[currRing->VarL_Offset[i]];
151 if (la != lb)
152 {
153 if (la < lb)
154 {
155 if (b) return pDivComp_INCOMP;
156 if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
157 return pDivComp_INCOMP;
158 a = TRUE;
159 }
160 else
161 {
162 if (a) return pDivComp_INCOMP;
163 if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
164 return pDivComp_INCOMP;
165 b = TRUE;
166 }
167 }
168 }
169 if (a) return pDivComp_LESS;
170 if (b) return pDivComp_GREATER;
171 if (!a & !b) return pDivComp_EQUAL;
172 }
173 return pDivComp_INCOMP;
174}
175
176static inline int pDivComp(poly p, poly q)
177{
178 if ((currRing->pCompIndex < 0)
180 {
181#ifdef HAVE_RATGRING
183 {
185 q,currRing,
186 currRing->real_var_start, currRing->real_var_end))
187 return 0;
188 return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
189 }
190#endif
191 BOOLEAN a=FALSE, b=FALSE;
192 int i;
193 unsigned long la, lb;
194 unsigned long divmask = currRing->divmask;
195 for (i=0; i<currRing->VarL_Size; i++)
196 {
197 la = p->exp[currRing->VarL_Offset[i]];
198 lb = q->exp[currRing->VarL_Offset[i]];
199 if (la != lb)
200 {
201 if (la < lb)
202 {
203 if (b) return 0;
204 if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
205 return 0;
206 a = TRUE;
207 }
208 else
209 {
210 if (a) return 0;
211 if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
212 return 0;
213 b = TRUE;
214 }
215 }
216 }
217 if (a) { /*assume(pLmCmp(q,p)==1);*/ return 1; }
218 if (b) { /*assume(pLmCmp(q,p)==-1);*/return -1; }
219 /*assume(pLmCmp(q,p)==0);*/
220 }
221 return 0;
222}
223
224#ifdef HAVE_SHIFTBBA
225static inline int pLPDivComp(poly p, poly q)
226{
227 if ((currRing->pCompIndex < 0) || (__p_GetComp(p,currRing) == __p_GetComp(q,currRing)))
228 {
229 // maybe there is a more performant way to do this? This will get called quite often in bba.
230 if (_p_LPLmDivisibleByNoComp(p, q, currRing)) return 1;
231 if (_p_LPLmDivisibleByNoComp(q, p, currRing)) return -1;
232 }
233
234 return 0;
235}
236#endif
237
238
242
243static void deleteHCBucket(LObject *L, kStrategy strat)
244{
245 if ((strat->kNoether!=NULL)
246 && (L->bucket != NULL))
247 {
248 for (int i=1; i<= (int) L->bucket->buckets_used; i++)
249 {
250 poly p=L->bucket->buckets[i];
251 if(p!=NULL)
252 {
253 if (p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
254 {
255 L->bucket->buckets[i]=NULL;
256 L->bucket->buckets_length[i]=0;
257 }
258 else
259 {
260 do
261 {
262 if (p_Cmp(pNext(p),strat->kNoetherTail(), L->tailRing) == -1)
263 {
264 p_Delete(&pNext(p), L->tailRing);
265 L->bucket->buckets_length[i]=pLength(L->bucket->buckets[i]);
266 break;
267 }
268 pIter(p);
269 } while(p!=NULL);
270 }
271 }
272 }
273 int i=L->bucket->buckets_used;
274 while ((i>0)&&(L->bucket->buckets[i]==NULL))
275 {
276 i--;
277 L->bucket->buckets_used=i;
278 }
279 }
280}
281
282/*2
283*deletes higher monomial of p, re-compute ecart and length
284*works only for orderings with ecart =pFDeg(end)-pFDeg(start)
285*/
287{
288 if (strat->kNoether!=NULL)
289 {
290 kTest_L(L,strat);
291 poly p1;
292 poly p = L->GetLmTailRing();
293 int l = 1;
294
295 if (!fromNext && p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
296 {
297 if (L->bucket != NULL) kBucketDestroy(&L->bucket);
298 L->Delete();
299 L->Clear();
300 L->ecart = -1;
301 return;
302 }
303 if (L->bucket != NULL)
304 {
305 deleteHCBucket(L,strat);
306 return;
307 }
309 p1 = p;
310 while (pNext(p1)!=NULL)
311 {
312 if (p_LmCmp(pNext(p1), strat->kNoetherTail(), L->tailRing) == -1)
313 {
314 cut=(pNext(p1)!=NULL);
315 if (cut)
316 {
317 p_Delete(&pNext(p1), L->tailRing);
318
319 if (p1 == p)
320 {
321 if (L->t_p != NULL)
322 {
323 assume(L->p != NULL && p == L->t_p);
324 pNext(L->p) = NULL;
325 }
326 L->max_exp = NULL;
327 }
328 else if (fromNext)
329 L->max_exp = p_GetMaxExpP(pNext(L->p), L->tailRing ); // p1;
330 //if (L->pLength != 0)
331 L->pLength = l;
332 // Hmmm when called from updateT, then only
333 // reset ecart when cut
334 if (fromNext)
335 L->ecart = L->pLDeg() - L->GetpFDeg();
336 }
337 break;
338 }
339 l++;
340 pIter(p1);
341 }
342 if ((!fromNext) && cut)
343 {
344 L->SetpFDeg();
345 L->ecart = L->pLDeg(strat->LDegLast) - L->GetpFDeg();
346 }
347 kTest_L(L,strat);
348 }
349}
350
351void deleteHC(poly* p, int* e, int* l,kStrategy strat)
352{
353 LObject L(*p, currRing, strat->tailRing);
354
355 deleteHC(&L, strat);
356 *p = L.p;
357 *e = L.ecart;
358 *l = L.length;
359 if (L.t_p != NULL) p_LmFree(L.t_p, strat->tailRing);
360}
361
362/*2
363*tests if p.p=monomial*unit and cancels the unit
364*/
366{
367 if(rHasGlobalOrdering (currRing)) return;
368 if(TEST_OPT_CANCELUNIT) return;
369
370 ring r = L->tailRing;
371 poly p = L->GetLmTailRing();
372 if(p_GetComp(p, r) != 0 && !p_OneComp(p, r)) return;
373
374 number lc=NULL; /*dummy, is always set if rField_is_Ring(r) */
375 if (rField_is_Ring(r) /*&& (rHasLocalOrMixedOrdering(r))*/)
376 lc = pGetCoeff(p);
377
378 // Leading coef have to be a unit
379 // example 2x+4x2 should be simplified to 2x*(1+2x)
380 // and 2 is not a unit in Z
381 //if ( !(n_IsUnit(pGetCoeff(p), r->cf)) ) return;
382
383 poly h = pNext(p);
384 int i;
385
387 {
388 loop
389 {
390 if (h==NULL)
391 {
392 p_Delete(&pNext(p), r);
393 if (!inNF)
394 {
396 if (L->p != NULL)
397 {
398 pSetCoeff(L->p,eins);
399 if (L->t_p != NULL)
400 pSetCoeff0(L->t_p,eins);
401 }
402 else
403 pSetCoeff(L->t_p,eins);
404 /* p and t_p share the same coeff, if both are !=NULL */
405 /* p==NULL==t_p cannot happen here */
406 }
407 L->ecart = 0;
408 L->length = 1;
409 //if (L->pLength > 0)
410 L->pLength = 1;
411 L->max_exp = NULL;
412
413 if (L->t_p != NULL && pNext(L->t_p) != NULL)
414 p_Delete(&pNext(L->t_p),r);
415 if (L->p != NULL && pNext(L->p) != NULL)
416 pNext(L->p) = NULL;
417 return;
418 }
419 i = rVar(r);
420 loop
421 {
422 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
423 i--;
424 if (i == 0) break; // does divide, try next monom
425 }
426 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
427 // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
428 // domains), no zerodivisor test needed CAUTION
429 if (!n_DivBy(pGetCoeff(h),lc,r->cf))
430 {
431 return;
432 }
433 pIter(h);
434 }
435 }
436 else
437 {
438 loop
439 {
440 if (h==NULL)
441 {
442 p_Delete(&pNext(p), r);
443 if (!inNF)
444 {
445 number eins=nInit(1);
446 if (L->p != NULL)
447 {
448 pSetCoeff(L->p,eins);
449 if (L->t_p != NULL)
450 pSetCoeff0(L->t_p,eins);
451 }
452 else
453 pSetCoeff(L->t_p,eins);
454 /* p and t_p share the same coeff, if both are !=NULL */
455 /* p==NULL==t_p cannot happen here */
456 }
457 L->ecart = 0;
458 L->length = 1;
459 //if (L->pLength > 0)
460 L->pLength = 1;
461 L->max_exp = NULL;
462
463 if (L->t_p != NULL && pNext(L->t_p) != NULL)
464 p_Delete(&pNext(L->t_p),r);
465 if (L->p != NULL && pNext(L->p) != NULL)
466 pNext(L->p) = NULL;
467
468 return;
469 }
470 i = rVar(r);
471 loop
472 {
473 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
474 i--;
475 if (i == 0) break; // does divide, try next monom
476 }
477 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
478 pIter(h);
479 }
480 }
481}
482
483/*2
484*pp is the new element in s
485*returns TRUE (in strat->kAllAxis) if
486*-HEcke is allowed
487*-we are in the last componente of the vector
488*-on all axis are monomials (all elements in NotUsedAxis are FALSE)
489*returns FALSE for pLexOrderings,
490*assumes in module case an ordering of type c* !!
491* HEckeTest is only called with strat->kAllAxis==FALSE !
492*/
493void HEckeTest (poly pp,kStrategy strat)
494{
495 int j,p;
496
497 if (currRing->pLexOrder
499 || (strat->ak >1)
501 {
502 return;
503 }
505 if (p!=0)
506 strat->NotUsedAxis[p] = FALSE;
507 /*- the leading term of pp is a power of the p-th variable -*/
508 for (j=(currRing->N);j>0; j--)
509 {
510 if (strat->NotUsedAxis[j])
511 {
512 strat->kAllAxis=FALSE;
513 return;
514 }
515 }
516 strat->kAllAxis=TRUE;
517}
518
519/*2
520*utilities for TSet, LSet
521*/
522inline static intset initec (const int maxnr)
523{
524 return (intset)omAlloc(maxnr*sizeof(int));
525}
526
527inline static unsigned long* initsevS (const int maxnr)
528{
529 return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
530}
531inline static int* initS_2_R (const int maxnr)
532{
533 return (int*)omAlloc0(maxnr*sizeof(int));
534}
535
536static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
537 int &length, const int incr)
538{
539 assume(T!=NULL);
540 assume(sevT!=NULL);
541 assume(R!=NULL);
542 assume((length+incr) > 0);
543
544 int i;
545 T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
546 (length+incr)*sizeof(TObject));
547
548 sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
549 (length+incr)*sizeof(long*));
550
551 R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
552 (length+incr)*sizeof(TObject*));
553 for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
554 length += incr;
555}
556
557void cleanT (kStrategy strat)
558{
559 int i,j;
560 poly p;
561 assume(currRing == strat->tailRing || strat->tailRing != NULL);
562
563 pShallowCopyDeleteProc p_shallow_copy_delete =
564 (strat->tailRing != currRing ?
566 NULL);
567 for (j=0; j<=strat->tl; j++)
568 {
569 p = strat->T[j].p;
570 strat->T[j].p=NULL;
571 if (strat->T[j].max_exp != NULL)
572 {
573 p_LmFree(strat->T[j].max_exp, strat->tailRing);
574 }
575 i = -1;
576 loop
577 {
578 i++;
579 if (i>strat->sl)
580 {
581 if (strat->T[j].t_p != NULL)
582 {
583 p_Delete(&(strat->T[j].t_p), strat->tailRing);
585 }
586 else
587 {
588#ifdef HAVE_SHIFTBBA
589 if (currRing->isLPring && strat->T[j].shift > 0)
590 {
591 pNext(p) = NULL; // pNext(p) points to the unshifted tail, don't try to delete it here
592 }
593#endif
594 pDelete(&p);
595 }
596 break;
597 }
598 if (p == strat->S[i])
599 {
600 if (strat->T[j].t_p != NULL)
601 {
602 if (p_shallow_copy_delete!=NULL)
603 {
604 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
605 currRing->PolyBin);
606 }
607 p_LmFree(strat->T[j].t_p, strat->tailRing);
608 }
609 break;
610 }
611 }
612 }
613 strat->tl=-1;
614}
615
617{
618 int i,j;
619 poly p;
620 assume(currRing == strat->tailRing || strat->tailRing != NULL);
621
622 pShallowCopyDeleteProc p_shallow_copy_delete =
623 (strat->tailRing != currRing ?
625 NULL);
626 for (j=0; j<=strat->tl; j++)
627 {
628 p = strat->T[j].p;
629 strat->T[j].p=NULL;
630 if (strat->T[j].max_exp != NULL)
631 {
632 p_LmFree(strat->T[j].max_exp, strat->tailRing);
633 }
634 i = -1;
635 loop
636 {
637 i++;
638 if (i>strat->sl)
639 {
640 if (strat->T[j].t_p != NULL)
641 {
642 p_Delete(&(strat->T[j].t_p), strat->tailRing);
644 }
645 else
646 {
647 //pDelete(&p);
648 p = NULL;
649 }
650 break;
651 }
652 if (p == strat->S[i])
653 {
654 if (strat->T[j].t_p != NULL)
655 {
656 assume(p_shallow_copy_delete != NULL);
657 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
658 currRing->PolyBin);
659 p_LmFree(strat->T[j].t_p, strat->tailRing);
660 }
661 break;
662 }
663 }
664 }
665 strat->tl=-1;
666}
667
668static inline void enlargeL (LSet* L,int* length,const int incr)
669{
670 assume((*L)!=NULL);
671 assume(((*length)+incr)>0);
672
673 *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
674 ((*length)+incr)*sizeof(LObject));
675 (*length) += incr;
676}
677
679{
680 strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
681}
682
683/*2
684*test whether (p1,p2) or (p2,p1) is in L up position length
685*it returns TRUE if yes and the position k
686*/
687BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
688{
689 LObject *p=&(strat->L[length]);
690
691 *k = length;
692 loop
693 {
694 if ((*k) < 0) return FALSE;
695 if (((p1 == (*p).p1) && (p2 == (*p).p2))
696 || ((p1 == (*p).p2) && (p2 == (*p).p1)))
697 return TRUE;
698 (*k)--;
699 p--;
700 }
701}
702
703int kFindInT(poly p, TSet T, int tlength)
704{
705 int i;
706
707 for (i=0; i<=tlength; i++)
708 {
709 if (T[i].p == p) return i;
710 }
711 return -1;
712}
713
714int kFindInT(poly p, kStrategy strat)
715{
716 int i;
717 do
718 {
719 i = kFindInT(p, strat->T, strat->tl);
720 if (i >= 0) return i;
721 strat = strat->next;
722 }
723 while (strat != NULL);
724 return -1;
725}
726
727#ifdef HAVE_SHIFTBBA
728int kFindInTShift(poly p, TSet T, int tlength)
729{
730 int i;
731
732 for (i=0; i<=tlength; i++)
733 {
734 // in the Letterplace ring the LMs in T and L are copies thus we have to use pEqualPolys() instead of ==
735 if (pEqualPolys(T[i].p, p)) return i;
736 }
737 return -1;
738}
739#endif
740
741#ifdef HAVE_SHIFTBBA
742int kFindInTShift(poly p, kStrategy strat)
743{
744 int i;
745 do
746 {
747 i = kFindInTShift(p, strat->T, strat->tl);
748 if (i >= 0) return i;
749 strat = strat->next;
750 }
751 while (strat != NULL);
752 return -1;
753}
754#endif
755
756#ifdef KDEBUG
758{
759 if (t_p != NULL) p_wrp(t_p, tailRing);
760 else if (p != NULL) p_wrp(p, currRing, tailRing);
761 else ::wrp(NULL);
762}
763#endif
764
765#define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
766
767#ifdef KDEBUG
768// check that Lm's of a poly from T are "equal"
769static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
770{
771 int i;
772 for (i=1; i<=tailRing->N; i++)
773 {
774 if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
775 return "Lm[i] different";
776 }
777 if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
778 return "Lm[0] different";
779 if (pNext(p) != pNext(t_p))
780 return "Lm.next different";
781 if (pGetCoeff(p) != pGetCoeff(t_p))
782 return "Lm.coeff different";
783 return NULL;
784}
785#endif
786
787#ifdef KDEBUG
789BOOLEAN kTest_T(TObject * T, kStrategy strat, int i, char TN)
790{
791 ring tailRing = T->tailRing;
793 if (strat_tailRing == NULL) strat_tailRing = tailRing;
794 r_assume(strat_tailRing == tailRing);
795
796 poly p = T->p;
797 // ring r = currRing;
798
799 if (T->p == NULL && T->t_p == NULL && i >= 0)
800 return dReportError("%c[%d].poly is NULL", TN, i);
801
802 if (T->p!=NULL)
803 {
804 nTest(pGetCoeff(T->p));
805 if ((T->t_p==NULL)&&(pNext(T->p)!=NULL)) p_Test(pNext(T->p),currRing);
806 }
807 if (T->t_p!=NULL)
808 {
809 nTest(pGetCoeff(T->t_p));
810 if (pNext(T->t_p)!=NULL) p_Test(pNext(T->t_p),strat_tailRing);
811 }
812 if ((T->p!=NULL)&&(T->t_p!=NULL)) assume(pGetCoeff(T->p)==pGetCoeff(T->t_p));
813
814 if (T->tailRing != currRing)
815 {
816 if (T->t_p == NULL && i > 0)
817 return dReportError("%c[%d].t_p is NULL", TN, i);
818 pFalseReturn(p_Test(T->t_p, T->tailRing));
819 if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
820 if ((T->p != NULL) && (T->t_p != NULL))
821 {
822 const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
823 if (msg != NULL)
824 return dReportError("%c[%d] %s", TN, i, msg);
825 // r = T->tailRing;
826 p = T->t_p;
827 }
828 if (T->p == NULL)
829 {
830 p = T->t_p;
831 // r = T->tailRing;
832 }
833 if (T->t_p != NULL && i >= 0 && TN == 'T')
834 {
835 if (pNext(T->t_p) == NULL)
836 {
837 if (T->max_exp != NULL)
838 return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
839 }
840 else
841 {
842 if (T->max_exp == NULL)
843 return dReportError("%c[%d].max_exp is NULL", TN, i);
844 if (pNext(T->max_exp) != NULL)
845 return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
846
847 pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
848 omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
849#if KDEBUG > 0
850 if (! sloppy_max)
851 {
852 poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
853 p_Setm(T->max_exp, tailRing);
854 p_Setm(test_max, tailRing);
855 BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
856 if (! equal)
857 return dReportError("%c[%d].max out of sync", TN, i);
858 p_LmFree(test_max, tailRing);
859 }
860#endif
861 }
862 }
863 }
864 else
865 {
866 if (T->p == NULL && i > 0)
867 return dReportError("%c[%d].p is NULL", TN, i);
868#ifdef HAVE_SHIFTBBA
869 if (currRing->isLPring && T->shift > 0)
870 {
871 // in this case, the order is not correct. test LM and tail separately
874 }
875 else
876#endif
877 {
879 }
880 }
881
882 if ((i >= 0) && (T->pLength != 0)
883 && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
884 {
885 int l=T->pLength;
886 T->pLength=pLength(p);
887 return dReportError("%c[%d] pLength error: has %d, specified to have %d",
888 TN, i , pLength(p), l);
889 }
890
891 // check FDeg, for elements in L and T
892 if (i >= 0 && (TN == 'T' || TN == 'L'))
893 {
894 // FDeg has ir element from T of L set
895 if (strat->homog && (T->FDeg != T->pFDeg()))
896 {
897 int d=T->FDeg;
898 T->FDeg=T->pFDeg();
899 return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
900 TN, i , T->pFDeg(), d);
901 }
902 }
903
904 // check is_normalized for elements in T
905 if (i >= 0 && TN == 'T')
906 {
907 if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
908 return dReportError("T[%d] is_normalized error", i);
909
910 }
911 return TRUE;
912}
913#endif
914
915#ifdef KDEBUG
917 BOOLEAN testp, int lpos, TSet T, int tlength)
918{
920 if (L->p!=NULL)
921 {
922 if ((L->t_p==NULL)
923 &&(pNext(L->p)!=NULL)
924 &&(pGetCoeff(pNext(L->p))!=NULL)) /* !=strat->tail*/
925 {
926 p_Test(pNext(L->p),currRing);
927 nTest(pGetCoeff(L->p));
928 }
929 }
930 if (L->t_p!=NULL)
931 {
932 if ((pNext(L->t_p)!=NULL)
933 &&(pGetCoeff(pNext(L->t_p))!=NULL)) /* !=strat->tail*/
934 {
935 p_Test(pNext(L->t_p),strat_tailRing);
936 nTest(pGetCoeff(L->t_p));
937 }
938 }
939 if ((L->p!=NULL)&&(L->t_p!=NULL)) assume(pGetCoeff(L->p)==pGetCoeff(L->t_p));
940
941 if (testp)
942 {
943 poly pn = NULL;
944 if (L->bucket != NULL)
945 {
946 kFalseReturn(kbTest(L->bucket));
947 r_assume(L->bucket->bucket_ring == L->tailRing);
948 if (L->p != NULL && pNext(L->p) != NULL)
949 {
950 pn = pNext(L->p);
951 pNext(L->p) = NULL;
952 }
953 }
954 kFalseReturn(kTest_T(L, strat, lpos, 'L'));
955 if (pn != NULL)
956 pNext(L->p) = pn;
957
958 ring r;
959 poly p;
960 L->GetLm(p, r);
961 if (L->sev != 0L)
962 {
963 if (p_GetShortExpVector(p, r) != L->sev)
964 {
965 return dReportError("L[%d] wrong sev: has %lo, specified to have %lo",
966 lpos, p_GetShortExpVector(p, r), L->sev);
967 }
968 }
969 }
970 if (L->p1 == NULL)
971 {
972 // L->p2 either NULL or "normal" poly
973 pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
974 }
975 else if (tlength > 0 && T != NULL && (lpos >=0))
976 {
977 // now p1 and p2 must be != NULL and must be contained in T
978 int i;
979#ifdef HAVE_SHIFTBBA
980 if (rIsLPRing(currRing))
981 i = kFindInTShift(L->p1, T, tlength);
982 else
983#endif
984 i = kFindInT(L->p1, T, tlength);
985 if (i < 0)
986 return dReportError("L[%d].p1 not in T",lpos);
987#ifdef HAVE_SHIFTBBA
988 if (rIsLPRing(currRing))
989 {
990 if (rField_is_Ring(currRing)) return TRUE; // m*shift(q) is not in T
991 i = kFindInTShift(L->p2, T, tlength);
992 }
993 else
994#endif
995 i = kFindInT(L->p2, T, tlength);
996 if (i < 0)
997 return dReportError("L[%d].p2 not in T",lpos);
998 }
999 return TRUE;
1000}
1001#endif
1002
1003#ifdef KDEBUG
1005{
1006 int i;
1007 // test P
1008 kFalseReturn(kTest_L(&(strat->P), strat,
1009 (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
1010 -1, strat->T, strat->tl));
1011
1012 // test T
1013 if (strat->T != NULL)
1014 {
1015 for (i=0; i<=strat->tl; i++)
1016 {
1017 kFalseReturn(kTest_T(&(strat->T[i]), strat, i, 'T'));
1018 if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
1019 return dReportError("strat->sevT[%d] out of sync", i);
1020 }
1021 }
1022
1023 // test L
1024 if (strat->L != NULL)
1025 {
1026 for (i=0; i<=strat->Ll; i++)
1027 {
1028 kFalseReturn(kTest_L(&(strat->L[i]), strat,
1029 strat->L[i].Next() != strat->tail, i,
1030 strat->T, strat->tl));
1031 // may be unused
1032 //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
1033 // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
1034 //{
1035 // assume(strat->L[i].bucket != NULL);
1036 //}
1037 }
1038 }
1039
1040 // test S
1041 if (strat->S != NULL)
1042 kFalseReturn(kTest_S(strat));
1043
1044 return TRUE;
1045}
1046#endif
1047
1048#ifdef KDEBUG
1050{
1051 int i;
1052 BOOLEAN ret = TRUE;
1053 for (i=0; i<=strat->sl; i++)
1054 {
1055 if (strat->S[i] != NULL &&
1056 strat->sevS[i] != pGetShortExpVector(strat->S[i]))
1057 {
1058 return dReportError("S[%d] wrong sev: has %o, specified to have %o",
1059 i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
1060 }
1061 }
1062 return ret;
1063}
1064#endif
1065
1066#ifdef KDEBUG
1068{
1069 int i, j;
1070 // BOOLEAN ret = TRUE;
1071 kFalseReturn(kTest(strat));
1072
1073 // test strat->R, strat->T[i].i_r
1074 for (i=0; i<=strat->tl; i++)
1075 {
1076 if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1077 return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1078 strat->T[i].i_r);
1079 if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1080 return dReportError("T[%d].i_r with R out of sync", i);
1081 }
1082 // test containment of S inT
1083 if ((strat->S != NULL)&&(strat->tl>=0))
1084 {
1085 for (i=0; i<=strat->sl; i++)
1086 {
1087 j = kFindInT(strat->S[i], strat->T, strat->tl);
1088 if (j < 0)
1089 return dReportError("S[%d] not in T", i);
1090 if (strat->S_2_R[i] != strat->T[j].i_r)
1091 return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1092 i, strat->S_2_R[i], j, strat->T[j].i_r);
1093 }
1094 }
1095 // test strat->L[i].i_r1
1096 #ifdef HAVE_SHIFTBBA
1097 if (!rIsLPRing(currRing)) // in the Letterplace ring we currently don't set/use i_r1 and i_r2
1098 #endif
1099 if (strat->L!=NULL)
1100 {
1101 for (i=0; i<=strat->Ll; i++)
1102 {
1103 if (strat->L[i].p1 != NULL && strat->L[i].p2)
1104 {
1105 if (strat->L[i].i_r1 < 0 ||
1106 strat->L[i].i_r1 > strat->tl ||
1107 strat->L[i].T_1(strat)->p != strat->L[i].p1)
1108 return dReportError("L[%d].i_r1 out of sync", i);
1109 if (strat->L[i].i_r2 < 0 ||
1110 strat->L[i].i_r2 > strat->tl ||
1111 strat->L[i].T_2(strat)->p != strat->L[i].p2)
1112 return dReportError("L[%d].i_r2 out of sync", i);
1113 }
1114 else
1115 {
1116 if (strat->L[i].i_r1 != -1)
1117 return dReportError("L[%d].i_r1 out of sync", i);
1118 if (strat->L[i].i_r2 != -1)
1119 return dReportError("L[%d].i_r2 out of sync", i);
1120 }
1121 if (strat->L[i].i_r != -1)
1122 return dReportError("L[%d].i_r out of sync", i);
1123 }
1124 }
1125 return TRUE;
1126}
1127#endif // KDEBUG
1128
1129/*2
1130*cancels the i-th polynomial in the standardbase s
1131*/
1132void deleteInS (int i,kStrategy strat)
1133{
1134#ifdef ENTER_USE_MEMMOVE
1135 memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1136 memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1137 memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1138 memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1139#else
1140 int j;
1141 for (j=i; j<strat->sl; j++)
1142 {
1143 strat->S[j] = strat->S[j+1];
1144 strat->ecartS[j] = strat->ecartS[j+1];
1145 strat->sevS[j] = strat->sevS[j+1];
1146 strat->S_2_R[j] = strat->S_2_R[j+1];
1147 }
1148#endif
1149 if (strat->lenS!=NULL)
1150 {
1151#ifdef ENTER_USE_MEMMOVE
1152 memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1153#else
1154 for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1155#endif
1156 }
1157 if (strat->lenSw!=NULL)
1158 {
1159#ifdef ENTER_USE_MEMMOVE
1160 memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1161#else
1162 for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1163#endif
1164 }
1165 if (strat->fromQ!=NULL)
1166 {
1167#ifdef ENTER_USE_MEMMOVE
1168 memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1169#else
1170 for (j=i; j<strat->sl; j++)
1171 {
1172 strat->fromQ[j] = strat->fromQ[j+1];
1173 }
1174#endif
1175 }
1176 strat->S[strat->sl] = NULL;
1177 strat->sl--;
1178}
1179
1180#ifdef HAVE_SHIFTBBA
1182{
1183 if (rIsLPRing(currRing)
1184 && (strat->P.p1!=NULL))
1185 {
1186 // clean up strat->P.p1: may be shifted
1187 poly p=strat->P.p1;
1188 int lv=currRing->isLPring;
1190 for (int i=lv;i>0;i--)
1191 {
1192 if (pGetExp(p,i)!=0) { is_shifted=FALSE; break;}
1193 }
1194 if (is_shifted
1195 && (kFindInL1(p, strat)<0)
1196 && (kFindInT(p, strat->T, strat->tl) < 0)
1197 )
1198 {
1199 return TRUE;
1200 }
1201 }
1202 return FALSE;
1203}
1204#endif
1205/*2
1206*cancels the j-th polynomial in the set
1207*/
1208void deleteInL (LSet set, int *length, int j,kStrategy strat)
1209{
1210 if (set[j].lcm!=NULL)
1211 {
1212 kDeleteLcm(&set[j]);
1213 }
1214 if (set[j].sig!=NULL)
1215 {
1216 if (pGetCoeff(set[j].sig) != NULL)
1217 pLmDelete(set[j].sig);
1218 else
1219 pLmFree(set[j].sig);
1220 }
1221 if (set[j].p!=NULL)
1222 {
1223 if (pNext(set[j].p) == strat->tail)
1224 {
1225 if (pGetCoeff(set[j].p) != NULL)
1226 pLmDelete(set[j].p);
1227 else
1228 pLmFree(set[j].p);
1229 /*- tail belongs to several int spolys -*/
1230 }
1231 else
1232 {
1233 // search p in T, if it is there, do not delete it
1234 if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1235 {
1236 // assure that for global orderings kFindInT fails
1237 //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1238 set[j].Delete();
1239 }
1240 }
1241 }
1242 #ifdef HAVE_SHIFTBBA
1243 if (is_shifted_p1(/*strat->P.p1,*/strat))
1244 {
1245 // clean up strat->P.p1: may be shifted
1246 pLmDelete(strat->P.p1);
1247 strat->P.p1=NULL;
1248 }
1249 #endif
1250 if (*length > 0 && j < *length)
1251 {
1252#ifdef ENTER_USE_MEMMOVE
1253 memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1254#else
1255 int i;
1256 for (i=j; i < (*length); i++)
1257 set[i] = set[i+1];
1258#endif
1259 }
1260#ifdef KDEBUG
1261 set[*length].Init();
1262#endif
1263 (*length)--;
1264}
1265
1266/*2
1267*enters p at position at in L
1268*/
1269void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1270{
1271 // this should be corrected
1272 assume(p.FDeg == p.pFDeg());
1273
1274 if ((*length)>=0)
1275 {
1276 if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,*LSetmax);
1277 if (at <= (*length))
1278#ifdef ENTER_USE_MEMMOVE
1279 memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1280#else
1281 for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1282#endif
1283 }
1284 else at = 0;
1285 (*set)[at] = p;
1286 (*length)++;
1287}
1288
1289/*2
1290* computes the normal ecart;
1291* used in mora case and if pLexOrder & sugar in bba case
1292*/
1294{
1295 h->FDeg = h->pFDeg();
1296 h->ecart = h->pLDeg() - h->FDeg;
1297 // h->length is set by h->pLDeg
1298 h->length=h->pLength=pLength(h->p);
1299}
1300
1302{
1303 h->FDeg = h->pFDeg();
1304 (*h).ecart = 0;
1305 h->length=h->pLength=pLength(h->p);
1306}
1307
1308void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1309{
1310 Lp->FDeg = Lp->pFDeg();
1311 (*Lp).ecart = 0;
1312 (*Lp).length = 0;
1313}
1314
1315void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1316{
1317 Lp->FDeg = Lp->pFDeg();
1318 (*Lp).ecart = si_max(ecartF,ecartG);
1319 (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1320 (*Lp).length = 0;
1321}
1322
1323/*2
1324*if ecart1<=ecart2 it returns TRUE
1325*/
1326static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1327{
1328 return (ecart1 <= ecart2);
1329}
1330
1331/*2
1332* put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1333*/
1334static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1335{
1336 assume(atR >= 0);
1337 assume(i<=strat->sl);
1338 assume(p!=NULL);
1340 #if ALL_VS_JUST
1341 //Over rings, if we construct the strong pair, do not add the spair
1343 {
1344 number s,t,d;
1345 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1346
1347 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1348 {
1349 nDelete(&d);
1350 nDelete(&s);
1351 nDelete(&t);
1352 return;
1353 }
1354 nDelete(&d);
1355 nDelete(&s);
1356 nDelete(&t);
1357 }
1358 #endif
1359 int j,compare,compareCoeff;
1360 LObject h;
1361
1362#ifdef KDEBUG
1363 h.ecart=0; h.length=0;
1364#endif
1365 /*- computes the lcm(s[i],p) -*/
1366 if(pHasNotCFRing(p,strat->S[i]))
1367 {
1368 strat->cp++;
1369 return;
1370 }
1371 h.lcm = p_Lcm(p,strat->S[i],currRing);
1372 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1373 if (nIsZero(pGetCoeff(h.lcm)))
1374 {
1375 strat->cp++;
1376 pLmDelete(h.lcm);
1377 return;
1378 }
1379 // basic chain criterion
1380 /*
1381 *the set B collects the pairs of type (S[j],p)
1382 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1383 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
1384 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
1385 */
1386
1387 for(j = strat->Bl;j>=0;j--)
1388 {
1389 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1390 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1391 if(compare == pDivComp_EQUAL)
1392 {
1393 //They have the same LM
1395 {
1396 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1397 {
1398 strat->c3++;
1399 pLmDelete(h.lcm);
1400 return;
1401 }
1402 break;
1403 }
1405 {
1406 deleteInL(strat->B,&strat->Bl,j,strat);
1407 strat->c3++;
1408 }
1410 {
1411 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1412 {
1413 strat->c3++;
1414 pLmDelete(h.lcm);
1415 return;
1416 }
1417 break;
1418 }
1419 }
1420 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1421 {
1422 if(compare == pDivComp_LESS)
1423 {
1424 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1425 {
1426 strat->c3++;
1427 pLmDelete(h.lcm);
1428 return;
1429 }
1430 break;
1431 }
1432 if(compare == pDivComp_GREATER)
1433 {
1434 deleteInL(strat->B,&strat->Bl,j,strat);
1435 strat->c3++;
1436 }
1437 }
1438 }
1439 number s, t;
1440 poly m1, m2, gcd = NULL;
1441 s = pGetCoeff(strat->S[i]);
1442 t = pGetCoeff(p);
1443 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1444 ksCheckCoeff(&s, &t, currRing->cf);
1445 pSetCoeff0(m1, s);
1446 pSetCoeff0(m2, t);
1447 m2 = pNeg(m2);
1448 p_Test(m1,strat->tailRing);
1449 p_Test(m2,strat->tailRing);
1450 poly si = pCopy(strat->S[i]);
1451 poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1452 poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1453 pDelete(&si);
1454 p_LmDelete(m1, currRing);
1455 p_LmDelete(m2, currRing);
1456 if(sim2 == NULL)
1457 {
1458 if(pm1 == NULL)
1459 {
1460 if(h.lcm != NULL)
1461 {
1462 pLmDelete(h.lcm);
1463 h.lcm=NULL;
1464 }
1465 h.Clear();
1466 if (strat->pairtest==NULL) initPairtest(strat);
1467 strat->pairtest[i] = TRUE;
1468 strat->pairtest[strat->sl+1] = TRUE;
1469 return;
1470 }
1471 else
1472 {
1473 gcd = pm1;
1474 pm1 = NULL;
1475 }
1476 }
1477 else
1478 {
1479 if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1480 {
1481 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1482 pSetmComp(sim2);
1483 }
1484 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1485 gcd = p_Add_q(pm1, sim2, strat->tailRing);
1486 }
1487 p_Test(gcd, strat->tailRing);
1488#ifdef KDEBUG
1489 if (TEST_OPT_DEBUG)
1490 {
1491 wrp(gcd);
1492 PrintLn();
1493 }
1494#endif
1495 h.p = gcd;
1496 h.i_r = -1;
1497 if(h.p == NULL)
1498 {
1499 if (strat->pairtest==NULL) initPairtest(strat);
1500 strat->pairtest[i] = TRUE;
1501 strat->pairtest[strat->sl+1] = TRUE;
1502 return;
1503 }
1504 h.tailRing = strat->tailRing;
1505 int posx;
1506 //h.pCleardenom();
1507 //pSetm(h.p);
1508 h.i_r1 = -1;h.i_r2 = -1;
1509 strat->initEcart(&h);
1510 #if 1
1511 h.p2 = strat->S[i];
1512 h.p1 = p;
1513 #endif
1514 #if 1
1515 if (atR >= 0)
1516 {
1517 h.i_r1 = atR;
1518 h.i_r2 = strat->S_2_R[i];
1519 }
1520 #endif
1521 if (strat->Bl==-1)
1522 posx =0;
1523 else
1524 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1525 h.sev = pGetShortExpVector(h.p);
1526 if (currRing!=strat->tailRing)
1527 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1528 if (strat->P.p!=NULL) strat->P.sev = pGetShortExpVector(strat->P.p);
1529 else strat->P.sev=0L;
1530 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1531 kTest_TS(strat);
1532}
1533
1534/*2
1535* put the lcm(s[i],p) into the set B
1536*/
1537
1538static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1539{
1540 number d, s, t;
1541 assume(atR >= 0);
1543 poly m1, m2, gcd,si;
1544 if(!enterTstrong)
1545 {
1546 assume(i<=strat->sl);
1547 si = strat->S[i];
1548 }
1549 else
1550 {
1551 assume(i<=strat->tl);
1552 si = strat->T[i].p;
1553 }
1554 //printf("\n--------------------------------\n");
1555 //pWrite(p);pWrite(si);
1556 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1557
1558 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1559 {
1560 nDelete(&d);
1561 nDelete(&s);
1562 nDelete(&t);
1563 return FALSE;
1564 }
1565
1566 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1567
1569 {
1570 unsigned long sev = pGetShortExpVector(gcd);
1571
1572 for (int j = 0; j < strat->sl; j++)
1573 {
1574 if (j == i)
1575 continue;
1576
1577 if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf)
1578 && !(strat->sevS[j] & ~sev)
1579 && p_LmDivisibleBy(strat->S[j], gcd, currRing))
1580 {
1581 nDelete(&d);
1582 nDelete(&s);
1583 nDelete(&t);
1584 return FALSE;
1585 }
1586 }
1587 }
1588
1589 //p_Test(m1,strat->tailRing);
1590 //p_Test(m2,strat->tailRing);
1591 /*if(!enterTstrong)
1592 {
1593 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1594 {
1595 memset(&(strat->P), 0, sizeof(strat->P));
1596 kStratChangeTailRing(strat);
1597 strat->P = *(strat->R[atR]);
1598 p_LmFree(m1, strat->tailRing);
1599 p_LmFree(m2, strat->tailRing);
1600 p_LmFree(gcd, currRing);
1601 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1602 }
1603 }*/
1604 pSetCoeff0(m1, s);
1605 pSetCoeff0(m2, t);
1606 pSetCoeff0(gcd, d);
1607 p_Test(m1,strat->tailRing);
1608 p_Test(m2,strat->tailRing);
1609 //printf("\n===================================\n");
1610 //pWrite(m1);pWrite(m2);pWrite(gcd);
1611#ifdef KDEBUG
1612 if (TEST_OPT_DEBUG)
1613 {
1614 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1615 PrintS("m1 = ");
1616 p_wrp(m1, strat->tailRing);
1617 PrintS(" ; m2 = ");
1618 p_wrp(m2, strat->tailRing);
1619 PrintS(" ; gcd = ");
1620 wrp(gcd);
1621 PrintS("\n--- create strong gcd poly: ");
1622 Print("\n p: %d", i);
1623 wrp(p);
1624 Print("\n strat->S[%d]: ", i);
1625 wrp(si);
1626 PrintS(" ---> ");
1627 }
1628#endif
1629
1630 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1631 p_LmDelete(m1, strat->tailRing);
1632 p_LmDelete(m2, strat->tailRing);
1633#ifdef KDEBUG
1634 if (TEST_OPT_DEBUG)
1635 {
1636 wrp(gcd);
1637 PrintLn();
1638 }
1639#endif
1640
1641 LObject h;
1642 h.p = gcd;
1643 h.tailRing = strat->tailRing;
1644 int posx;
1645 strat->initEcart(&h);
1646 h.sev = pGetShortExpVector(h.p);
1647 h.i_r1 = -1;h.i_r2 = -1;
1648 if (currRing!=strat->tailRing)
1649 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1650 if(!enterTstrong)
1651 {
1652 #if 1
1653 h.p1 = p;h.p2 = strat->S[i];
1654 #endif
1655 if (atR >= 0)
1656 {
1657 h.i_r2 = strat->S_2_R[i];
1658 h.i_r1 = atR;
1659 }
1660 else
1661 {
1662 h.i_r1 = -1;
1663 h.i_r2 = -1;
1664 }
1665 if (strat->Ll==-1)
1666 posx =0;
1667 else
1668 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1669 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1670 }
1671 else
1672 {
1673 if(h.IsNull()) return FALSE;
1674 //int red_result;
1675 //reduzieren ist teur!!!
1676 //if(strat->L != NULL)
1677 //red_result = strat->red(&h,strat);
1678 if(!h.IsNull())
1679 {
1680 enterT(h, strat,-1);
1681 //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1682 //strat->enterS(h,pos,strat,-1);
1683 }
1684 }
1685 return TRUE;
1686}
1687
1689{
1690 if(strat->sl < 0) return FALSE;
1691 int i;
1692 for(i=0;i<strat->sl;i++)
1693 {
1694 //Construct the gcd pair between h and S[i]
1695 number d, s, t;
1696 poly m1, m2, gcd;
1697 d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1698 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1699 {
1700 nDelete(&d);
1701 nDelete(&s);
1702 nDelete(&t);
1703 }
1704 else
1705 {
1706 k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1707 pSetCoeff0(m1, s);
1708 pSetCoeff0(m2, t);
1709 pSetCoeff0(gcd, d);
1710 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);
1711 poly pSigMult = p_Copy(h->sig,currRing);
1712 poly sSigMult = p_Copy(strat->sig[i],currRing);
1715 p_LmDelete(m1, strat->tailRing);
1716 p_LmDelete(m2, strat->tailRing);
1718 if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1719 {
1720 pDelete(&h->p);
1721 h->p = gcd;
1722 pDelete(&h->sig);
1723 h->sig = pairsig;
1724 pNext(h->sig) = NULL;
1725 strat->initEcart(h);
1726 h->sev = pGetShortExpVector(h->p);
1727 h->sevSig = pGetShortExpVector(h->sig);
1728 h->i_r1 = -1;h->i_r2 = -1;
1729 if(h->lcm != NULL)
1730 {
1731 pLmDelete(h->lcm);
1732 h->lcm = NULL;
1733 }
1734 if (currRing!=strat->tailRing)
1735 h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1736 return TRUE;
1737 }
1738 //Delete what you didn't use
1739 pDelete(&gcd);
1740 pDelete(&pairsig);
1741 }
1742 }
1743 return FALSE;
1744}
1745
1746static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1747{
1748 number d, s, t;
1749 assume(atR >= 0);
1750 poly m1, m2, gcd,si;
1751 assume(i<=strat->sl);
1752 si = strat->S[i];
1753 //printf("\n--------------------------------\n");
1754 //pWrite(p);pWrite(si);
1755 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1756
1757 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1758 {
1759 nDelete(&d);
1760 nDelete(&s);
1761 nDelete(&t);
1762 return FALSE;
1763 }
1764
1765 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1766 //p_Test(m1,strat->tailRing);
1767 //p_Test(m2,strat->tailRing);
1768 /*if(!enterTstrong)
1769 {
1770 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1771 {
1772 memset(&(strat->P), 0, sizeof(strat->P));
1773 kStratChangeTailRing(strat);
1774 strat->P = *(strat->R[atR]);
1775 p_LmFree(m1, strat->tailRing);
1776 p_LmFree(m2, strat->tailRing);
1777 p_LmFree(gcd, currRing);
1778 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1779 }
1780 }*/
1781 pSetCoeff0(m1, s);
1782 pSetCoeff0(m2, t);
1783 pSetCoeff0(gcd, d);
1784 p_Test(m1,strat->tailRing);
1785 p_Test(m2,strat->tailRing);
1786 //printf("\n===================================\n");
1787 //pWrite(m1);pWrite(m2);pWrite(gcd);
1788#ifdef KDEBUG
1789 if (TEST_OPT_DEBUG)
1790 {
1791 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1792 PrintS("m1 = ");
1793 p_wrp(m1, strat->tailRing);
1794 PrintS(" ; m2 = ");
1795 p_wrp(m2, strat->tailRing);
1796 PrintS(" ; gcd = ");
1797 wrp(gcd);
1798 PrintS("\n--- create strong gcd poly: ");
1799 Print("\n p: %d", i);
1800 wrp(p);
1801 Print("\n strat->S[%d]: ", i);
1802 wrp(si);
1803 PrintS(" ---> ");
1804 }
1805#endif
1806
1807 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1808
1809#ifdef KDEBUG
1810 if (TEST_OPT_DEBUG)
1811 {
1812 wrp(gcd);
1813 PrintLn();
1814 }
1815#endif
1816
1817 //Check and set the signatures
1818 poly pSigMult = p_Copy(sig,currRing);
1819 poly sSigMult = p_Copy(strat->sig[i],currRing);
1822 p_LmDelete(m1, strat->tailRing);
1823 p_LmDelete(m2, strat->tailRing);
1824 poly pairsig;
1825 if(pLmCmp(pSigMult,sSigMult) == 0)
1826 {
1827 //Same lm, have to add them
1829 //This might be zero
1830 }
1831 else
1832 {
1833 //Set the sig to either pSigMult or sSigMult
1834 if(pLtCmp(pSigMult,sSigMult)==1)
1835 {
1836 pairsig = pSigMult;
1837 pDelete(&sSigMult);
1838 }
1839 else
1840 {
1841 pairsig = sSigMult;
1842 pDelete(&pSigMult);
1843 }
1844 }
1845
1846 LObject h;
1847 h.p = gcd;
1848 h.tailRing = strat->tailRing;
1849 h.sig = pairsig;
1850 int posx;
1851 strat->initEcart(&h);
1852 h.sev = pGetShortExpVector(h.p);
1853 h.i_r1 = -1;h.i_r2 = -1;
1854 if (currRing!=strat->tailRing)
1855 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1856 if(h.sig == NULL)
1857 {
1858 //sigdrop since we loose the signature
1859 strat->sigdrop = TRUE;
1860 //Try to reduce it as far as we can via redRing
1861 int red_result = redRing(&h,strat);
1862 if(red_result == 0)
1863 {
1864 // Cancel the sigdrop
1865 p_Delete(&h.sig,currRing);h.sig = NULL;
1866 strat->sigdrop = FALSE;
1867 return FALSE;
1868 }
1869 else
1870 {
1871 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1872 #if 1
1873 strat->enterS(h,0,strat,strat->tl);
1874 #endif
1875 return FALSE;
1876 }
1877 }
1878 if(!nGreaterZero(pGetCoeff(h.sig)))
1879 {
1880 h.sig = pNeg(h.sig);
1881 h.p = pNeg(h.p);
1882 }
1883
1884 if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1885 {
1886 strat->sigdrop = TRUE;
1887 // Completely reduce it
1888 int red_result = redRing(&h,strat);
1889 if(red_result == 0)
1890 {
1891 // Reduced to 0
1892 strat->sigdrop = FALSE;
1893 p_Delete(&h.sig,currRing);h.sig = NULL;
1894 return FALSE;
1895 }
1896 else
1897 {
1898 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1899 // 0 - add just the original poly causing the sigdrop, 1 - add also this
1900 #if 1
1901 strat->enterS(h,0,strat, strat->tl+1);
1902 #endif
1903 return FALSE;
1904 }
1905 }
1906 //Check for sigdrop
1907 if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1908 {
1909 strat->sigdrop = TRUE;
1910 //Enter this element to S
1911 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1912 strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1913 }
1914 #if 1
1915 h.p1 = p;h.p2 = strat->S[i];
1916 #endif
1917 if (atR >= 0)
1918 {
1919 h.i_r2 = strat->S_2_R[i];
1920 h.i_r1 = atR;
1921 }
1922 else
1923 {
1924 h.i_r1 = -1;
1925 h.i_r2 = -1;
1926 }
1927 if (strat->Ll==-1)
1928 posx =0;
1929 else
1930 posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1931 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1932 return TRUE;
1933}
1934
1935/*2
1936* put the pair (s[i],p) into the set B, ecart=ecart(p)
1937*/
1938
1939void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1940{
1941 assume(i<=strat->sl);
1942
1943 int l,j,compare;
1944 LObject Lp;
1945 Lp.i_r = -1;
1946
1947#ifdef KDEBUG
1948 Lp.ecart=0; Lp.length=0;
1949#endif
1950 /*- computes the lcm(s[i],p) -*/
1951 Lp.lcm = pInit();
1952
1953#ifndef HAVE_RATGRING
1954 pLcm(p,strat->S[i],Lp.lcm);
1955#elif defined(HAVE_RATGRING)
1956 if (rIsRatGRing(currRing))
1957 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1958 else
1959 pLcm(p,strat->S[i],Lp.lcm);
1960#endif
1961 pSetm(Lp.lcm);
1962
1963
1964 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
1965 {
1966 if (strat->fromT && (strat->ecartS[i]>ecart))
1967 {
1968 pLmFree(Lp.lcm);
1969 return;
1970 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
1971 }
1972 if((!((strat->ecartS[i]>0)&&(ecart>0)))
1973 && pHasNotCF(p,strat->S[i]))
1974 {
1975 /*
1976 *the product criterion has applied for (s,p),
1977 *i.e. lcm(s,p)=product of the leading terms of s and p.
1978 *Suppose (s,r) is in L and the leading term
1979 *of p divides lcm(s,r)
1980 *(==> the leading term of p divides the leading term of r)
1981 *but the leading term of s does not divide the leading term of r
1982 *(notice that tis condition is automatically satisfied if r is still
1983 *in S), then (s,r) can be cancelled.
1984 *This should be done here because the
1985 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1986 *
1987 *Moreover, skipping (s,r) holds also for the noncommutative case.
1988 */
1989 strat->cp++;
1990 pLmFree(Lp.lcm);
1991 return;
1992 }
1993 Lp.ecart = si_max(ecart,strat->ecartS[i]);
1994 /*
1995 *the set B collects the pairs of type (S[j],p)
1996 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
1997 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
1998 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
1999 */
2000 {
2001 j = strat->Bl;
2002 loop
2003 {
2004 if (j < 0) break;
2005 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2006 if ((compare==1)
2007 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2008 {
2009 strat->c3++;
2010 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2011 {
2012 pLmFree(Lp.lcm);
2013 return;
2014 }
2015 break;
2016 }
2017 else
2018 if ((compare ==-1)
2019 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2020 {
2021 deleteInL(strat->B,&strat->Bl,j,strat);
2022 strat->c3++;
2023 }
2024 j--;
2025 }
2026 }
2027 }
2028 else /*sugarcrit*/
2029 {
2030 if (ALLOW_PROD_CRIT(strat))
2031 {
2032 if (strat->fromT && (strat->ecartS[i]>ecart))
2033 {
2034 pLmFree(Lp.lcm);
2035 return;
2036 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2037 }
2038 // if currRing->nc_type!=quasi (or skew)
2039 // TODO: enable productCrit for super commutative algebras...
2040 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2041 pHasNotCF(p,strat->S[i]))
2042 {
2043 /*
2044 *the product criterion has applied for (s,p),
2045 *i.e. lcm(s,p)=product of the leading terms of s and p.
2046 *Suppose (s,r) is in L and the leading term
2047 *of p divides lcm(s,r)
2048 *(==> the leading term of p divides the leading term of r)
2049 *but the leading term of s does not divide the leading term of r
2050 *(notice that tis condition is automatically satisfied if r is still
2051 *in S), then (s,r) can be canceled.
2052 *This should be done here because the
2053 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2054 */
2055 strat->cp++;
2056 pLmFree(Lp.lcm);
2057 return;
2058 }
2059 /*
2060 *the set B collects the pairs of type (S[j],p)
2061 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2062 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2063 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2064 */
2065 for(j = strat->Bl;j>=0;j--)
2066 {
2067 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2068 if (compare==1)
2069 {
2070 strat->c3++;
2071 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2072 {
2073 pLmFree(Lp.lcm);
2074 return;
2075 }
2076 break;
2077 }
2078 else
2079 if (compare ==-1)
2080 {
2081 deleteInL(strat->B,&strat->Bl,j,strat);
2082 strat->c3++;
2083 }
2084 }
2085 }
2086 }
2087 /*
2088 *the pair (S[i],p) enters B if the spoly != 0
2089 */
2090 /*- compute the short s-polynomial -*/
2091 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2092 pNorm(p);
2093
2094 if ((strat->S[i]==NULL) || (p==NULL))
2095 return;
2096
2097 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2098 Lp.p=NULL;
2099 else
2100 {
2101 #ifdef HAVE_PLURAL
2102 if ( rIsPluralRing(currRing) )
2103 {
2104 if(pHasNotCF(p, strat->S[i]))
2105 {
2106 if(ncRingType(currRing) == nc_lie)
2107 {
2108 // generalized prod-crit for lie-type
2109 strat->cp++;
2110 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2111 }
2112 else
2113 if( ALLOW_PROD_CRIT(strat) )
2114 {
2115 // product criterion for homogeneous case in SCA
2116 strat->cp++;
2117 Lp.p = NULL;
2118 }
2119 else
2120 {
2121 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2122 nc_CreateShortSpoly(strat->S[i], p, currRing);
2123 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2124 pNext(Lp.p) = strat->tail; // !!!
2125 }
2126 }
2127 else
2128 {
2129 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2130 nc_CreateShortSpoly(strat->S[i], p, currRing);
2131
2132 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2133 pNext(Lp.p) = strat->tail; // !!!
2134 }
2135 }
2136 else
2137 #endif
2138 {
2140 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2141 }
2142 }
2143 if (Lp.p == NULL)
2144 {
2145 /*- the case that the s-poly is 0 -*/
2146 if (strat->pairtest==NULL) initPairtest(strat);
2147 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2148 strat->pairtest[strat->sl+1] = TRUE;
2149 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2150 /*
2151 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2152 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2153 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2154 *term of p divides the lcm(s,r)
2155 *(this canceling should be done here because
2156 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2157 *the first case is handled in chainCrit
2158 */
2159 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2160 }
2161 else
2162 {
2163 /*- the pair (S[i],p) enters B -*/
2164 Lp.p1 = strat->S[i];
2165 Lp.p2 = p;
2166
2167 if (
2169// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2170 )
2171 {
2172 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2173 pNext(Lp.p) = strat->tail; // !!!
2174 }
2175
2176 if (atR >= 0)
2177 {
2178 Lp.i_r1 = strat->S_2_R[i];
2179 Lp.i_r2 = atR;
2180 }
2181 else
2182 {
2183 Lp.i_r1 = -1;
2184 Lp.i_r2 = -1;
2185 }
2186 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2187
2189 {
2192 && (Lp.p->coef!=NULL))
2193 nDelete(&(Lp.p->coef));
2194 }
2195
2196 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2197 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2198 }
2199}
2200
2201/// p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
2202static inline BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2203{
2204 int i = rVar(r);
2205 loop
2206 {
2207 if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2208 return FALSE;
2209 i--;
2210 if (i == 0)
2211 return TRUE;
2212 }
2213}
2214
2215/*2
2216* put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2217* (in the special case: idLift for ideals, i.e. strat->syzComp==1)
2218* (prod.crit applies)
2219*/
2220
2221static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2222{
2223 assume(ALLOW_PROD_CRIT(strat));
2225 assume(i<=strat->sl);
2226 assume(strat->syzComp==1);
2227
2228 if ((strat->S[i]==NULL) || (p==NULL))
2229 return;
2230
2231 int l,j,compare;
2232 LObject Lp;
2233 Lp.i_r = -1;
2234
2235#ifdef KDEBUG
2236 Lp.ecart=0; Lp.length=0;
2237#endif
2238 /*- computes the lcm(s[i],p) -*/
2239 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2240
2241 if (strat->sugarCrit)
2242 {
2243 if((!((strat->ecartS[i]>0)&&(ecart>0)))
2244 && p_HasNotCF_Lift(p,strat->S[i],currRing))
2245 {
2246 /*
2247 *the product criterion has applied for (s,p),
2248 *i.e. lcm(s,p)=product of the leading terms of s and p.
2249 *Suppose (s,r) is in L and the leading term
2250 *of p divides lcm(s,r)
2251 *(==> the leading term of p divides the leading term of r)
2252 *but the leading term of s does not divide the leading term of r
2253 *(notice that tis condition is automatically satisfied if r is still
2254 *in S), then (s,r) can be cancelled.
2255 *This should be done here because the
2256 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2257 *
2258 *Moreover, skipping (s,r) holds also for the noncommutative case.
2259 */
2260 strat->cp++;
2261 pLmFree(Lp.lcm);
2262 return;
2263 }
2264 else
2265 Lp.ecart = si_max(ecart,strat->ecartS[i]);
2266 if (strat->fromT && (strat->ecartS[i]>ecart))
2267 {
2268 pLmFree(Lp.lcm);
2269 return;
2270 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2271 }
2272 /*
2273 *the set B collects the pairs of type (S[j],p)
2274 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2275 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2276 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2277 */
2278 {
2279 j = strat->Bl;
2280 loop
2281 {
2282 if (j < 0) break;
2283 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2284 if ((compare==1)
2285 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2286 {
2287 strat->c3++;
2288 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2289 {
2290 pLmFree(Lp.lcm);
2291 return;
2292 }
2293 break;
2294 }
2295 else
2296 if ((compare ==-1)
2297 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2298 {
2299 deleteInL(strat->B,&strat->Bl,j,strat);
2300 strat->c3++;
2301 }
2302 j--;
2303 }
2304 }
2305 }
2306 else /*sugarcrit*/
2307 {
2308 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2309 p_HasNotCF_Lift(p,strat->S[i],currRing))
2310 {
2311 /*
2312 *the product criterion has applied for (s,p),
2313 *i.e. lcm(s,p)=product of the leading terms of s and p.
2314 *Suppose (s,r) is in L and the leading term
2315 *of p divides lcm(s,r)
2316 *(==> the leading term of p divides the leading term of r)
2317 *but the leading term of s does not divide the leading term of r
2318 *(notice that tis condition is automatically satisfied if r is still
2319 *in S), then (s,r) can be canceled.
2320 *This should be done here because the
2321 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2322 */
2323 strat->cp++;
2324 pLmFree(Lp.lcm);
2325 return;
2326 }
2327 if (strat->fromT && (strat->ecartS[i]>ecart))
2328 {
2329 pLmFree(Lp.lcm);
2330 return;
2331 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2332 }
2333 /*
2334 *the set B collects the pairs of type (S[j],p)
2335 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2336 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2337 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2338 */
2339 for(j = strat->Bl;j>=0;j--)
2340 {
2341 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2342 if (compare==1)
2343 {
2344 strat->c3++;
2345 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2346 {
2347 pLmFree(Lp.lcm);
2348 return;
2349 }
2350 break;
2351 }
2352 else
2353 if (compare ==-1)
2354 {
2355 deleteInL(strat->B,&strat->Bl,j,strat);
2356 strat->c3++;
2357 }
2358 }
2359 }
2360 /*
2361 *the pair (S[i],p) enters B if the spoly != 0
2362 */
2363 /*- compute the short s-polynomial -*/
2364 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2365 pNorm(p);
2366
2367 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2368 Lp.p=NULL;
2369 else
2370 {
2372 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2373 }
2374 if (Lp.p == NULL)
2375 {
2376 /*- the case that the s-poly is 0 -*/
2377 if (strat->pairtest==NULL) initPairtest(strat);
2378 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2379 strat->pairtest[strat->sl+1] = TRUE;
2380 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2381 /*
2382 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2383 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2384 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2385 *term of p divides the lcm(s,r)
2386 *(this canceling should be done here because
2387 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2388 *the first case is handled in chainCrit
2389 */
2390 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2391 }
2392 else
2393 {
2394 /*- the pair (S[i],p) enters B -*/
2395 Lp.p1 = strat->S[i];
2396 Lp.p2 = p;
2397
2398 pNext(Lp.p) = strat->tail; // !!!
2399
2400 if (atR >= 0)
2401 {
2402 Lp.i_r1 = strat->S_2_R[i];
2403 Lp.i_r2 = atR;
2404 }
2405 else
2406 {
2407 Lp.i_r1 = -1;
2408 Lp.i_r2 = -1;
2409 }
2410 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2411
2413 {
2416 && (Lp.p->coef!=NULL))
2417 nDelete(&(Lp.p->coef));
2418 }
2419
2420 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2421 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2422 }
2423}
2424
2425/*2
2426* put the pair (s[i],p) into the set B, ecart=ecart(p)
2427* NOTE: here we need to add the signature-based criteria
2428*/
2429
2430#ifdef DEBUGF5
2431static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2432#else
2433static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2434#endif
2435{
2436 assume(i<=strat->sl);
2437
2438 int l;
2439 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2440 // the corresponding signatures for criteria checks
2441 LObject Lp;
2442 poly pSigMult = p_Copy(pSig,currRing);
2443 poly sSigMult = p_Copy(strat->sig[i],currRing);
2444 unsigned long pSigMultNegSev,sSigMultNegSev;
2445 Lp.i_r = -1;
2446
2447#ifdef KDEBUG
2448 Lp.ecart=0; Lp.length=0;
2449#endif
2450 /*- computes the lcm(s[i],p) -*/
2451 Lp.lcm = pInit();
2452 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2453#ifndef HAVE_RATGRING
2454 pLcm(p,strat->S[i],Lp.lcm);
2455#elif defined(HAVE_RATGRING)
2456 if (rIsRatGRing(currRing))
2457 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2458 else
2459 pLcm(p,strat->S[i],Lp.lcm);
2460#endif
2461 pSetm(Lp.lcm);
2462
2463 // set coeffs of multipliers m1 and m2
2464 pSetCoeff0(m1, nInit(1));
2465 pSetCoeff0(m2, nInit(1));
2466//#if 1
2467#ifdef DEBUGF5
2468 PrintS("P1 ");
2469 pWrite(pHead(p));
2470 PrintS("P2 ");
2471 pWrite(pHead(strat->S[i]));
2472 PrintS("M1 ");
2473 pWrite(m1);
2474 PrintS("M2 ");
2475 pWrite(m2);
2476#endif
2477 // get multiplied signatures for testing
2478 pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2479 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2480 sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2481 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2482
2483//#if 1
2484#ifdef DEBUGF5
2485 PrintS("----------------\n");
2488 PrintS("----------------\n");
2489 Lp.checked = 0;
2490#endif
2492//#if 1
2493#if DEBUGF5
2494 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2497#endif
2498 if(sigCmp==0)
2499 {
2500 // printf("!!!! EQUAL SIGS !!!!\n");
2501 // pSig = sSig, delete element due to Rewritten Criterion
2502 pDelete(&pSigMult);
2503 pDelete(&sSigMult);
2505 pLmDelete(Lp.lcm);
2506 else
2507 pLmFree(Lp.lcm);
2508 pDelete (&m1);
2509 pDelete (&m2);
2510 return;
2511 }
2512 // testing by syzCrit = F5 Criterion
2513 // testing by rewCrit1 = Rewritten Criterion
2514 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2515 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2516 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2517 || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2518 )
2519 {
2520 pDelete(&pSigMult);
2521 pDelete(&sSigMult);
2523 pLmDelete(Lp.lcm);
2524 else
2525 pLmFree(Lp.lcm);
2526 pDelete (&m1);
2527 pDelete (&m2);
2528 return;
2529 }
2530 /*
2531 *the pair (S[i],p) enters B if the spoly != 0
2532 */
2533 /*- compute the short s-polynomial -*/
2534 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2535 pNorm(p);
2536
2537 if ((strat->S[i]==NULL) || (p==NULL))
2538 return;
2539
2540 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2541 Lp.p=NULL;
2542 else
2543 {
2544 #ifdef HAVE_PLURAL
2545 if ( rIsPluralRing(currRing) )
2546 {
2547 if(pHasNotCF(p, strat->S[i]))
2548 {
2549 if(ncRingType(currRing) == nc_lie)
2550 {
2551 // generalized prod-crit for lie-type
2552 strat->cp++;
2553 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2554 }
2555 else
2556 if( ALLOW_PROD_CRIT(strat) )
2557 {
2558 // product criterion for homogeneous case in SCA
2559 strat->cp++;
2560 Lp.p = NULL;
2561 }
2562 else
2563 {
2564 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2565 nc_CreateShortSpoly(strat->S[i], p, currRing);
2566
2567 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2568 pNext(Lp.p) = strat->tail; // !!!
2569 }
2570 }
2571 else
2572 {
2573 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2574 nc_CreateShortSpoly(strat->S[i], p, currRing);
2575
2576 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2577 pNext(Lp.p) = strat->tail; // !!!
2578 }
2579 }
2580 else
2581 #endif
2582 {
2584 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2585 }
2586 }
2587 // store from which element this pair comes from for further tests
2588 //Lp.from = strat->sl+1;
2589 if(sigCmp==currRing->OrdSgn)
2590 {
2591 // pSig > sSig
2592 pDelete (&sSigMult);
2593 Lp.sig = pSigMult;
2594 Lp.sevSig = ~pSigMultNegSev;
2595 }
2596 else
2597 {
2598 // pSig < sSig
2599 pDelete (&pSigMult);
2600 Lp.sig = sSigMult;
2601 Lp.sevSig = ~sSigMultNegSev;
2602 }
2603 if (Lp.p == NULL)
2604 {
2605 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2606 int pos = posInSyz(strat, Lp.sig);
2607 enterSyz(Lp, strat, pos);
2608 }
2609 else
2610 {
2611 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2612 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2613 {
2614 pLmFree(Lp.lcm);
2615 pDelete(&Lp.sig);
2616 pDelete (&m1);
2617 pDelete (&m2);
2618 return;
2619 }
2620 // in any case Lp is checked up to the next strat->P which is added
2621 // to S right after this critical pair creation.
2622 // NOTE: this even holds if the 2nd generator gives the bigger signature
2623 // moreover, this improves rewCriterion,
2624 // i.e. strat->checked > strat->from if and only if the 2nd generator
2625 // gives the bigger signature.
2626 Lp.checked = strat->sl+1;
2627 // at this point it is clear that the pair will be added to L, since it has
2628 // passed all tests up to now
2629
2630 // adds buchberger's first criterion
2631 if (pLmCmp(m2,pHead(p)) == 0)
2632 {
2633 Lp.prod_crit = TRUE; // Product Criterion
2634#if 0
2635 int pos = posInSyz(strat, Lp.sig);
2636 enterSyz(Lp, strat, pos);
2637 pDelete (&m1);
2638 pDelete (&m2);
2639 return;
2640#endif
2641 }
2642 pDelete (&m1);
2643 pDelete (&m2);
2644#if DEBUGF5
2645 PrintS("SIGNATURE OF PAIR: ");
2646 pWrite(Lp.sig);
2647#endif
2648 /*- the pair (S[i],p) enters B -*/
2649 Lp.p1 = strat->S[i];
2650 Lp.p2 = p;
2651
2652 if (
2654// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2655 )
2656 {
2657 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2658 pNext(Lp.p) = strat->tail; // !!!
2659 }
2660
2661 if (atR >= 0)
2662 {
2663 Lp.i_r1 = strat->S_2_R[i];
2664 Lp.i_r2 = atR;
2665 }
2666 else
2667 {
2668 Lp.i_r1 = -1;
2669 Lp.i_r2 = -1;
2670 }
2671 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2672
2674 {
2677 && (Lp.p->coef!=NULL))
2678 nDelete(&(Lp.p->coef));
2679 }
2680
2681 l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2682 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2683 }
2684}
2685
2686
2687#ifdef DEBUGF5
2688static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2689#else
2690static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2691#endif
2692{
2693 #if ALL_VS_JUST
2694 //Over rings, if we construct the strong pair, do not add the spair
2696 {
2697 number s,t,d;
2698 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2699
2700 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2701 {
2702 nDelete(&d);
2703 nDelete(&s);
2704 nDelete(&t);
2705 return;
2706 }
2707 nDelete(&d);
2708 nDelete(&s);
2709 nDelete(&t);
2710 }
2711 #endif
2712 assume(i<=strat->sl);
2713 int l;
2714 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2715 // the corresponding signatures for criteria checks
2716 LObject Lp;
2717 poly pSigMult = p_Copy(pSig,currRing);
2718 poly sSigMult = p_Copy(strat->sig[i],currRing);
2719 unsigned long pSigMultNegSev,sSigMultNegSev;
2720 Lp.i_r = -1;
2721
2722#ifdef KDEBUG
2723 Lp.ecart=0; Lp.length=0;
2724#endif
2725 /*- computes the lcm(s[i],p) -*/
2726 Lp.lcm = pInit();
2727 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2728#ifndef HAVE_RATGRING
2729 pLcm(p,strat->S[i],Lp.lcm);
2730#elif defined(HAVE_RATGRING)
2731 if (rIsRatGRing(currRing))
2732 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2733 else
2734 pLcm(p,strat->S[i],Lp.lcm);
2735#endif
2736 pSetm(Lp.lcm);
2737
2738 // set coeffs of multipliers m1 and m2
2740 {
2741 number s = nCopy(pGetCoeff(strat->S[i]));
2742 number t = nCopy(pGetCoeff(p));
2743 pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2744 ksCheckCoeff(&s, &t, currRing->cf);
2745 pSetCoeff0(m1,s);
2746 pSetCoeff0(m2,t);
2747 }
2748 else
2749 {
2750 pSetCoeff0(m1, nInit(1));
2751 pSetCoeff0(m2, nInit(1));
2752 }
2753#ifdef DEBUGF5
2754 Print("P1 ");
2755 pWrite(pHead(p));
2756 Print("P2 ");
2757 pWrite(pHead(strat->S[i]));
2758 Print("M1 ");
2759 pWrite(m1);
2760 Print("M2 ");
2761 pWrite(m2);
2762#endif
2763
2764 // get multiplied signatures for testing
2766 if(pSigMult != NULL)
2767 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2769 if(sSigMult != NULL)
2770 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2771//#if 1
2772#ifdef DEBUGF5
2773 Print("----------------\n");
2776 Print("----------------\n");
2777 Lp.checked = 0;
2778#endif
2779 int sigCmp;
2780 if(pSigMult != NULL && sSigMult != NULL)
2781 {
2784 else
2786 }
2787 else
2788 {
2789 if(pSigMult == NULL)
2790 {
2791 if(sSigMult == NULL)
2792 sigCmp = 0;
2793 else
2794 sigCmp = -1;
2795 }
2796 else
2797 sigCmp = 1;
2798 }
2799//#if 1
2800#if DEBUGF5
2801 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2804#endif
2805 //In the ring case we already build the sig
2807 {
2808 if(sigCmp == 0)
2809 {
2810 //sigdrop since we loose the signature
2811 strat->sigdrop = TRUE;
2812 //Try to reduce it as far as we can via redRing
2814 {
2815 poly p1 = p_Copy(p,currRing);
2816 poly p2 = p_Copy(strat->S[i],currRing);
2817 p1 = p_Mult_mm(p1,m1,currRing);
2818 p2 = p_Mult_mm(p2,m2,currRing);
2819 Lp.p = p_Sub(p1,p2,currRing);
2820 if(Lp.p != NULL)
2822 }
2823 int red_result = redRing(&Lp,strat);
2824 if(red_result == 0)
2825 {
2826 // Cancel the sigdrop
2827 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2828 strat->sigdrop = FALSE;
2829 return;
2830 }
2831 else
2832 {
2833 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2834 #if 1
2835 strat->enterS(Lp,0,strat,strat->tl);
2836 #endif
2837 return;
2838 }
2839 }
2841 {
2842 //Same lm, have to subtract
2844 }
2845 else
2846 {
2847 if(sigCmp == 1)
2848 {
2849 Lp.sig = pCopy(pSigMult);
2850 }
2851 if(sigCmp == -1)
2852 {
2853 Lp.sig = pNeg(pCopy(sSigMult));
2854 }
2855 }
2856 Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2857 }
2858
2859 #if 0
2860 if(sigCmp==0)
2861 {
2862 // printf("!!!! EQUAL SIGS !!!!\n");
2863 // pSig = sSig, delete element due to Rewritten Criterion
2864 pDelete(&pSigMult);
2865 pDelete(&sSigMult);
2867 pLmDelete(Lp.lcm);
2868 else
2869 pLmFree(Lp.lcm);
2870 pDelete (&m1);
2871 pDelete (&m2);
2872 return;
2873 }
2874 #endif
2875 // testing by syzCrit = F5 Criterion
2876 // testing by rewCrit1 = Rewritten Criterion
2877 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2878 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2879 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2880 // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2881 //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2882 )
2883 {
2884 pDelete(&pSigMult);
2885 pDelete(&sSigMult);
2887 pLmDelete(Lp.lcm);
2888 else
2889 pLmFree(Lp.lcm);
2890 pDelete (&m1);
2891 pDelete (&m2);
2892 return;
2893 }
2894 /*
2895 *the pair (S[i],p) enters B if the spoly != 0
2896 */
2897 /*- compute the short s-polynomial -*/
2898 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2899 pNorm(p);
2900
2901 if ((strat->S[i]==NULL) || (p==NULL))
2902 return;
2903
2904 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2905 Lp.p=NULL;
2906 else
2907 {
2908 //Build p
2910 {
2911 poly p1 = p_Copy(p,currRing);
2912 poly p2 = p_Copy(strat->S[i],currRing);
2913 p1 = p_Mult_mm(p1,m1,currRing);
2914 p2 = p_Mult_mm(p2,m2,currRing);
2915 Lp.p = p_Sub(p1,p2,currRing);
2916 if(Lp.p != NULL)
2918 }
2919 else
2920 {
2921 #ifdef HAVE_PLURAL
2922 if ( rIsPluralRing(currRing) )
2923 {
2924 if(ncRingType(currRing) == nc_lie)
2925 {
2926 // generalized prod-crit for lie-type
2927 strat->cp++;
2928 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2929 }
2930 else
2931 if( ALLOW_PROD_CRIT(strat) )
2932 {
2933 // product criterion for homogeneous case in SCA
2934 strat->cp++;
2935 Lp.p = NULL;
2936 }
2937 else
2938 {
2939 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2940 nc_CreateShortSpoly(strat->S[i], p, currRing);
2941
2942 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2943 pNext(Lp.p) = strat->tail; // !!!
2944 }
2945 }
2946 else
2947 #endif
2948 {
2950 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2951 }
2952 }
2953 }
2954 // store from which element this pair comes from for further tests
2955 //Lp.from = strat->sl+1;
2957 {
2958 //Put the sig to be > 0
2959 if(!nGreaterZero(pGetCoeff(Lp.sig)))
2960 {
2961 Lp.sig = pNeg(Lp.sig);
2962 Lp.p = pNeg(Lp.p);
2963 }
2964 }
2965 else
2966 {
2967 if(sigCmp==currRing->OrdSgn)
2968 {
2969 // pSig > sSig
2970 pDelete (&sSigMult);
2971 Lp.sig = pSigMult;
2972 Lp.sevSig = ~pSigMultNegSev;
2973 }
2974 else
2975 {
2976 // pSig < sSig
2977 pDelete (&pSigMult);
2978 Lp.sig = sSigMult;
2979 Lp.sevSig = ~sSigMultNegSev;
2980 }
2981 }
2982 if (Lp.p == NULL)
2983 {
2984 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2985 int pos = posInSyz(strat, Lp.sig);
2986 enterSyz(Lp, strat, pos);
2987 }
2988 else
2989 {
2990 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2991 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2992 {
2993 pLmFree(Lp.lcm);
2994 pDelete(&Lp.sig);
2995 pDelete (&m1);
2996 pDelete (&m2);
2997 return;
2998 }
2999 // in any case Lp is checked up to the next strat->P which is added
3000 // to S right after this critical pair creation.
3001 // NOTE: this even holds if the 2nd generator gives the bigger signature
3002 // moreover, this improves rewCriterion,
3003 // i.e. strat->checked > strat->from if and only if the 2nd generator
3004 // gives the bigger signature.
3005 Lp.checked = strat->sl+1;
3006 // at this point it is clear that the pair will be added to L, since it has
3007 // passed all tests up to now
3008
3009 // adds buchberger's first criterion
3010 if (pLmCmp(m2,pHead(p)) == 0)
3011 {
3012 Lp.prod_crit = TRUE; // Product Criterion
3013#if 0
3014 int pos = posInSyz(strat, Lp.sig);
3015 enterSyz(Lp, strat, pos);
3016 pDelete (&m1);
3017 pDelete (&m2);
3018 return;
3019#endif
3020 }
3021 pDelete (&m1);
3022 pDelete (&m2);
3023#if DEBUGF5
3024 PrintS("SIGNATURE OF PAIR: ");
3025 pWrite(Lp.sig);
3026#endif
3027 /*- the pair (S[i],p) enters B -*/
3028 Lp.p1 = strat->S[i];
3029 Lp.p2 = p;
3030
3031 if (
3033// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3035 )
3036 {
3037 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3038 pNext(Lp.p) = strat->tail; // !!!
3039 }
3040
3041 if (atR >= 0)
3042 {
3043 Lp.i_r1 = strat->S_2_R[i];
3044 Lp.i_r2 = atR;
3045 }
3046 else
3047 {
3048 Lp.i_r1 = -1;
3049 Lp.i_r2 = -1;
3050 }
3051 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3052
3054 {
3057 && (Lp.p->coef!=NULL))
3058 nDelete(&(Lp.p->coef));
3059 }
3060 // Check for sigdrop
3061 if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3062 {
3063 strat->sigdrop = TRUE;
3064 // Completely reduce it
3065 int red_result = redRing(&Lp,strat);
3066 if(red_result == 0)
3067 {
3068 // Reduced to 0
3069 strat->sigdrop = FALSE;
3070 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3071 return;
3072 }
3073 else
3074 {
3075 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3076 // 0 - add just the original poly causing the sigdrop, 1 - add also this
3077 #if 1
3078 strat->enterS(Lp,0,strat, strat->tl+1);
3079 #endif
3080 return;
3081 }
3082 }
3083 l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3084 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3085 }
3086}
3087
3088/*2
3089* put the pair (s[i],p) into the set L, ecart=ecart(p)
3090* in the case that s forms a SB of (s)
3091*/
3092void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3093{
3094 //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3095 if(pHasNotCF(p,strat->S[i]))
3096 {
3097 //PrintS("prod-crit\n");
3098 if(ALLOW_PROD_CRIT(strat))
3099 {
3100 //PrintS("prod-crit\n");
3101 strat->cp++;
3102 return;
3103 }
3104 }
3105
3106 int l;
3107 LObject Lp;
3108 Lp.i_r = -1;
3109
3110 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3111 /*- compute the short s-polynomial -*/
3112
3113 #ifdef HAVE_PLURAL
3115 {
3116 Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3117 }
3118 else
3119 #endif
3120 Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3121
3122 if (Lp.p == NULL)
3123 {
3124 //PrintS("short spoly==NULL\n");
3125 pLmFree(Lp.lcm);
3126 }
3127 else
3128 {
3129 /*- the pair (S[i],p) enters L -*/
3130 Lp.p1 = strat->S[i];
3131 Lp.p2 = p;
3132 if (atR >= 0)
3133 {
3134 Lp.i_r1 = strat->S_2_R[i];
3135 Lp.i_r2 = atR;
3136 }
3137 else
3138 {
3139 Lp.i_r1 = -1;
3140 Lp.i_r2 = -1;
3141 }
3142 assume(pNext(Lp.p) == NULL);
3143 pNext(Lp.p) = strat->tail;
3144 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3146 {
3149 && (Lp.p->coef!=NULL))
3150 nDelete(&(Lp.p->coef));
3151 }
3152 l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3153 //Print("-> L[%d]\n",l);
3154 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3155 }
3156}
3157
3158/*2
3159* merge set B into L
3160*/
3162{
3163 int j=strat->Ll+strat->Bl+1;
3164 if (j>strat->Lmax)
3165 {
3166 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3167 enlargeL(&(strat->L),&(strat->Lmax),j);
3168 }
3169 j = strat->Ll;
3170 int i;
3171 for (i=strat->Bl; i>=0; i--)
3172 {
3173 j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3174 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3175 }
3176 strat->Bl = -1;
3177}
3178
3179/*2
3180* merge set B into L
3181*/
3183{
3184 int j=strat->Ll+strat->Bl+1;
3185 if (j>strat->Lmax)
3186 {
3187 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3188 enlargeL(&(strat->L),&(strat->Lmax),j);
3189 }
3190 j = strat->Ll;
3191 int i;
3192 for (i=strat->Bl; i>=0; i--)
3193 {
3194 j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3195 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3196 }
3197 strat->Bl = -1;
3198}
3199
3200/*2
3201*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3202*using the chain-criterion in B and L and enters B to L
3203*/
3204void chainCritNormal (poly p,int ecart,kStrategy strat)
3205{
3206 int i,j,l;
3207
3208 /*
3209 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3210 *In this case all elements in B such
3211 *that their lcm is divisible by the leading term of S[i] can be canceled
3212 */
3213 if (strat->pairtest!=NULL)
3214 {
3215#ifdef HAVE_SHIFTBBA
3216 // only difference is pLPDivisibleBy instead of pDivisibleBy
3217 if (rIsLPRing(currRing))
3218 {
3219 for (j=0; j<=strat->sl; j++)
3220 {
3221 if (strat->pairtest[j])
3222 {
3223 for (i=strat->Bl; i>=0; i--)
3224 {
3225 if (pLPDivisibleBy(strat->S[j],strat->B[i].lcm))
3226 {
3227 deleteInL(strat->B,&strat->Bl,i,strat);
3228 strat->c3++;
3229 }
3230 }
3231 }
3232 }
3233 }
3234 else
3235#endif
3236 {
3237 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3238 for (j=0; j<=strat->sl; j++)
3239 {
3240 if (strat->pairtest[j])
3241 {
3242 for (i=strat->Bl; i>=0; i--)
3243 {
3244 if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3245 {
3246 deleteInL(strat->B,&strat->Bl,i,strat);
3247 strat->c3++;
3248 }
3249 }
3250 }
3251 }
3252 }
3253 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3254 strat->pairtest=NULL;
3255 }
3256 if (strat->Gebauer || strat->fromT)
3257 {
3258 if (strat->sugarCrit)
3259 {
3260 /*
3261 *suppose L[j] == (s,r) and p/lcm(s,r)
3262 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3263 *and in case the sugar is o.k. then L[j] can be canceled
3264 */
3265 for (j=strat->Ll; j>=0; j--)
3266 {
3267 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3268 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3269 && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3270 {
3271 if (strat->L[j].p == strat->tail)
3272 {
3273 deleteInL(strat->L,&strat->Ll,j,strat);
3274 strat->c3++;
3275 }
3276 }
3277 }
3278 /*
3279 *this is GEBAUER-MOELLER:
3280 *in B all elements with the same lcm except the "best"
3281 *(i.e. the last one in B with this property) will be canceled
3282 */
3283 j = strat->Bl;
3284 loop /*cannot be changed into a for !!! */
3285 {
3286 if (j <= 0) break;
3287 i = j-1;
3288 loop
3289 {
3290 if (i < 0) break;
3291 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3292 {
3293 strat->c3++;
3294 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3295 {
3296 deleteInL(strat->B,&strat->Bl,i,strat);
3297 j--;
3298 }
3299 else
3300 {
3301 deleteInL(strat->B,&strat->Bl,j,strat);
3302 break;
3303 }
3304 }
3305 i--;
3306 }
3307 j--;
3308 }
3309 }
3310 else /*sugarCrit*/
3311 {
3312 /*
3313 *suppose L[j] == (s,r) and p/lcm(s,r)
3314 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3315 *and in case the sugar is o.k. then L[j] can be canceled
3316 */
3317 for (j=strat->Ll; j>=0; j--)
3318 {
3319 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3320 {
3321 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3322 {
3323 deleteInL(strat->L,&strat->Ll,j,strat);
3324 strat->c3++;
3325 }
3326 }
3327 }
3328 /*
3329 *this is GEBAUER-MOELLER:
3330 *in B all elements with the same lcm except the "best"
3331 *(i.e. the last one in B with this property) will be canceled
3332 */
3333 j = strat->Bl;
3334 loop /*cannot be changed into a for !!! */
3335 {
3336 if (j <= 0) break;
3337 for(i=j-1; i>=0; i--)
3338 {
3339 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3340 {
3341 strat->c3++;
3342 deleteInL(strat->B,&strat->Bl,i,strat);
3343 j--;
3344 }
3345 }
3346 j--;
3347 }
3348 }
3349 /*
3350 *the elements of B enter L
3351 */
3352 kMergeBintoL(strat);
3353 }
3354 else
3355 {
3356 for (j=strat->Ll; j>=0; j--)
3357 {
3358 #ifdef HAVE_SHIFTBBA
3359 if ((strat->L[j].p1!=NULL) &&
3360 pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3361 #else
3362 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3363 #endif
3364 {
3365 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3366 {
3367 deleteInL(strat->L,&strat->Ll,j,strat);
3368 strat->c3++;
3369 }
3370 }
3371 }
3372 /*
3373 *this is our MODIFICATION of GEBAUER-MOELLER:
3374 *First the elements of B enter L,
3375 *then we fix a lcm and the "best" element in L
3376 *(i.e the last in L with this lcm and of type (s,p))
3377 *and cancel all the other elements of type (r,p) with this lcm
3378 *except the case the element (s,r) has also the same lcm
3379 *and is on the worst position with respect to (s,p) and (r,p)
3380 */
3381 /*
3382 *B enters to L/their order with respect to B is permutated for elements
3383 *B[i].p with the same leading term
3384 */
3385 kMergeBintoL(strat);
3386 j = strat->Ll;
3387 loop /*cannot be changed into a for !!! */
3388 {
3389 if (j <= 0)
3390 {
3391 /*now L[0] cannot be canceled any more and the tail can be removed*/
3392 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3393 break;
3394 }
3395 if (strat->L[j].p2 == p)
3396 {
3397 i = j-1;
3398 loop
3399 {
3400 if (i < 0) break;
3401 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3402 {
3403 /*L[i] could be canceled but we search for a better one to cancel*/
3404 strat->c3++;
3405 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3406 && (pNext(strat->L[l].p) == strat->tail)
3407 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3408 && pDivisibleBy(p,strat->L[l].lcm))
3409 {
3410 /*
3411 *"NOT equal(...)" because in case of "equal" the element L[l]
3412 *is "older" and has to be from theoretical point of view behind
3413 *L[i], but we do not want to reorder L
3414 */
3415 strat->L[i].p2 = strat->tail;
3416 /*
3417 *L[l] will be canceled, we cannot cancel L[i] later on,
3418 *so we mark it with "tail"
3419 */
3420 deleteInL(strat->L,&strat->Ll,l,strat);
3421 i--;
3422 }
3423 else
3424 {
3425 deleteInL(strat->L,&strat->Ll,i,strat);
3426 }
3427 j--;
3428 }
3429 i--;
3430 }
3431 }
3432 else if (strat->L[j].p2 == strat->tail)
3433 {
3434 /*now L[j] cannot be canceled any more and the tail can be removed*/
3435 strat->L[j].p2 = p;
3436 }
3437 j--;
3438 }
3439 }
3440}
3441/*2
3442*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3443*without the chain-criterion in B and L and enters B to L
3444*/
3445void chainCritOpt_1 (poly,int,kStrategy strat)
3446{
3447 if (strat->pairtest!=NULL)
3448 {
3449 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3450 strat->pairtest=NULL;
3451 }
3452 /*
3453 *the elements of B enter L
3454 */
3455 kMergeBintoL(strat);
3456}
3457/*2
3458*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3459*using the chain-criterion in B and L and enters B to L
3460*/
3461void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3462{
3463 int i,j,l;
3464 kMergeBintoLSba(strat);
3465 j = strat->Ll;
3466 loop /*cannot be changed into a for !!! */
3467 {
3468 if (j <= 0)
3469 {
3470 /*now L[0] cannot be canceled any more and the tail can be removed*/
3471 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3472 break;
3473 }
3474 if (strat->L[j].p2 == p)
3475 {
3476 i = j-1;
3477 loop
3478 {
3479 if (i < 0) break;
3480 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3481 {
3482 /*L[i] could be canceled but we search for a better one to cancel*/
3483 strat->c3++;
3484 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3485 && (pNext(strat->L[l].p) == strat->tail)
3486 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3487 && pDivisibleBy(p,strat->L[l].lcm))
3488 {
3489 /*
3490 *"NOT equal(...)" because in case of "equal" the element L[l]
3491 *is "older" and has to be from theoretical point of view behind
3492 *L[i], but we do not want to reorder L
3493 */
3494 strat->L[i].p2 = strat->tail;
3495 /*
3496 *L[l] will be canceled, we cannot cancel L[i] later on,
3497 *so we mark it with "tail"
3498 */
3499 deleteInL(strat->L,&strat->Ll,l,strat);
3500 i--;
3501 }
3502 else
3503 {
3504 deleteInL(strat->L,&strat->Ll,i,strat);
3505 }
3506 j--;
3507 }
3508 i--;
3509 }
3510 }
3511 else if (strat->L[j].p2 == strat->tail)
3512 {
3513 /*now L[j] cannot be canceled any more and the tail can be removed*/
3514 strat->L[j].p2 = p;
3515 }
3516 j--;
3517 }
3518}
3519#ifdef HAVE_RATGRING
3520void chainCritPart (poly p,int ecart,kStrategy strat)
3521{
3522 int i,j,l;
3523
3524 /*
3525 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3526 *In this case all elements in B such
3527 *that their lcm is divisible by the leading term of S[i] can be canceled
3528 */
3529 if (strat->pairtest!=NULL)
3530 {
3531 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3532 for (j=0; j<=strat->sl; j++)
3533 {
3534 if (strat->pairtest[j])
3535 {
3536 for (i=strat->Bl; i>=0; i--)
3537 {
3538 if (_p_LmDivisibleByPart(strat->S[j],currRing,
3539 strat->B[i].lcm,currRing,
3540 currRing->real_var_start,currRing->real_var_end))
3541 {
3542 if(TEST_OPT_DEBUG)
3543 {
3544 Print("chain-crit-part: S[%d]=",j);
3545 p_wrp(strat->S[j],currRing);
3546 Print(" divide B[%d].lcm=",i);
3547 p_wrp(strat->B[i].lcm,currRing);
3548 PrintLn();
3549 }
3550 deleteInL(strat->B,&strat->Bl,i,strat);
3551 strat->c3++;
3552 }
3553 }
3554 }
3555 }
3556 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3557 strat->pairtest=NULL;
3558 }
3559 if (strat->Gebauer || strat->fromT)
3560 {
3561 if (strat->sugarCrit)
3562 {
3563 /*
3564 *suppose L[j] == (s,r) and p/lcm(s,r)
3565 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3566 *and in case the sugar is o.k. then L[j] can be canceled
3567 */
3568 for (j=strat->Ll; j>=0; j--)
3569 {
3570 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3571 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3572 && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3573 {
3574 if (strat->L[j].p == strat->tail)
3575 {
3576 if(TEST_OPT_DEBUG)
3577 {
3578 PrintS("chain-crit-part: pCompareChainPart p=");
3579 p_wrp(p,currRing);
3580 Print(" delete L[%d]",j);
3581 p_wrp(strat->L[j].lcm,currRing);
3582 PrintLn();
3583 }
3584 deleteInL(strat->L,&strat->Ll,j,strat);
3585 strat->c3++;
3586 }
3587 }
3588 }
3589 /*
3590 *this is GEBAUER-MOELLER:
3591 *in B all elements with the same lcm except the "best"
3592 *(i.e. the last one in B with this property) will be canceled
3593 */
3594 j = strat->Bl;
3595 loop /*cannot be changed into a for !!! */
3596 {
3597 if (j <= 0) break;
3598 i = j-1;
3599 loop
3600 {
3601 if (i < 0) break;
3602 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3603 {
3604 strat->c3++;
3605 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3606 {
3607 if(TEST_OPT_DEBUG)
3608 {
3609 Print("chain-crit-part: sugar B[%d].lcm=",j);
3610 p_wrp(strat->B[j].lcm,currRing);
3611 Print(" delete B[%d]",i);
3612 p_wrp(strat->B[i].lcm,currRing);
3613 PrintLn();
3614 }
3615 deleteInL(strat->B,&strat->Bl,i,strat);
3616 j--;
3617 }
3618 else
3619 {
3620 if(TEST_OPT_DEBUG)
3621 {
3622 Print("chain-crit-part: sugar B[%d].lcm=",i);
3623 p_wrp(strat->B[i].lcm,currRing);
3624 Print(" delete B[%d]",j);
3625 p_wrp(strat->B[j].lcm,currRing);
3626 PrintLn();
3627 }
3628 deleteInL(strat->B,&strat->Bl,j,strat);
3629 break;
3630 }
3631 }
3632 i--;
3633 }
3634 j--;
3635 }
3636 }
3637 else /*sugarCrit*/
3638 {
3639 /*
3640 *suppose L[j] == (s,r) and p/lcm(s,r)
3641 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3642 *and in case the sugar is o.k. then L[j] can be canceled
3643 */
3644 for (j=strat->Ll; j>=0; j--)
3645 {
3646 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3647 {
3648 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3649 {
3650 if(TEST_OPT_DEBUG)
3651 {
3652 PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3653 p_wrp(p,currRing);
3654 Print(" delete L[%d]",j);
3655 p_wrp(strat->L[j].lcm,currRing);
3656 PrintLn();
3657 }
3658 deleteInL(strat->L,&strat->Ll,j,strat);
3659 strat->c3++;
3660 }
3661 }
3662 }
3663 /*
3664 *this is GEBAUER-MOELLER:
3665 *in B all elements with the same lcm except the "best"
3666 *(i.e. the last one in B with this property) will be canceled
3667 */
3668 j = strat->Bl;
3669 loop /*cannot be changed into a for !!! */
3670 {
3671 if (j <= 0) break;
3672 for(i=j-1; i>=0; i--)
3673 {
3674 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3675 {
3676 if(TEST_OPT_DEBUG)
3677 {
3678 Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3679 p_wrp(strat->B[j].lcm,currRing);
3680 Print(" delete B[%d]\n",i);
3681 }
3682 strat->c3++;
3683 deleteInL(strat->B,&strat->Bl,i,strat);
3684 j--;
3685 }
3686 }
3687 j--;
3688 }
3689 }
3690 /*
3691 *the elements of B enter L
3692 */
3693 kMergeBintoL(strat);
3694 }
3695 else
3696 {
3697 for (j=strat->Ll; j>=0; j--)
3698 {
3699 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3700 {
3701 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3702 {
3703 if(TEST_OPT_DEBUG)
3704 {
3705 PrintS("chain-crit-part: pCompareChainPart p=");
3706 p_wrp(p,currRing);
3707 Print(" delete L[%d]",j);
3708 p_wrp(strat->L[j].lcm,currRing);
3709 PrintLn();
3710 }
3711 deleteInL(strat->L,&strat->Ll,j,strat);
3712 strat->c3++;
3713 }
3714 }
3715 }
3716 /*
3717 *this is our MODIFICATION of GEBAUER-MOELLER:
3718 *First the elements of B enter L,
3719 *then we fix a lcm and the "best" element in L
3720 *(i.e the last in L with this lcm and of type (s,p))
3721 *and cancel all the other elements of type (r,p) with this lcm
3722 *except the case the element (s,r) has also the same lcm
3723 *and is on the worst position with respect to (s,p) and (r,p)
3724 */
3725 /*
3726 *B enters to L/their order with respect to B is permutated for elements
3727 *B[i].p with the same leading term
3728 */
3729 kMergeBintoL(strat);
3730 j = strat->Ll;
3731 loop /*cannot be changed into a for !!! */
3732 {
3733 if (j <= 0)
3734 {
3735 /*now L[0] cannot be canceled any more and the tail can be removed*/
3736 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3737 break;
3738 }
3739 if (strat->L[j].p2 == p)
3740 {
3741 i = j-1;
3742 loop
3743 {
3744 if (i < 0) break;
3745 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3746 {
3747 /*L[i] could be canceled but we search for a better one to cancel*/
3748 strat->c3++;
3749 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3750 && (pNext(strat->L[l].p) == strat->tail)
3751 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3753 strat->L[l].lcm,currRing,
3754 currRing->real_var_start, currRing->real_var_end))
3755
3756 {
3757 /*
3758 *"NOT equal(...)" because in case of "equal" the element L[l]
3759 *is "older" and has to be from theoretical point of view behind
3760 *L[i], but we do not want to reorder L
3761 */
3762 strat->L[i].p2 = strat->tail;
3763 /*
3764 *L[l] will be canceled, we cannot cancel L[i] later on,
3765 *so we mark it with "tail"
3766 */
3767 if(TEST_OPT_DEBUG)
3768 {
3769 PrintS("chain-crit-part: divisible_by p=");
3770 p_wrp(p,currRing);
3771 Print(" delete L[%d]",l);
3772 p_wrp(strat->L[l].lcm,currRing);
3773 PrintLn();
3774 }
3775 deleteInL(strat->L,&strat->Ll,l,strat);
3776 i--;
3777 }
3778 else
3779 {
3780 if(TEST_OPT_DEBUG)
3781 {
3782 PrintS("chain-crit-part: divisible_by(2) p=");
3783 p_wrp(p,currRing);
3784 Print(" delete L[%d]",i);
3785 p_wrp(strat->L[i].lcm,currRing);
3786 PrintLn();
3787 }
3788 deleteInL(strat->L,&strat->Ll,i,strat);
3789 }
3790 j--;
3791 }
3792 i--;
3793 }
3794 }
3795 else if (strat->L[j].p2 == strat->tail)
3796 {
3797 /*now L[j] cannot be canceled any more and the tail can be removed*/
3798 strat->L[j].p2 = p;
3799 }
3800 j--;
3801 }
3802 }
3803}
3804#endif
3805
3806/*2
3807*(s[0],h),...,(s[k],h) will be put to the pairset L
3808*/
3809void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR/* = -1*/)
3810{
3811
3812 if ((strat->syzComp==0)
3813 || (pGetComp(h)<=strat->syzComp))
3814 {
3815 int j;
3817
3818 if (pGetComp(h)==0)
3819 {
3820 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3821 if ((isFromQ)&&(strat->fromQ!=NULL))
3822 {
3823 for (j=0; j<=k; j++)
3824 {
3825 if (!strat->fromQ[j])
3826 {
3827 new_pair=TRUE;
3828 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3829 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3830 }
3831 }
3832 }
3833 else
3834 {
3835 new_pair=TRUE;
3836 for (j=0; j<=k; j++)
3837 {
3838 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3839 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3840 }
3841 }
3842 }
3843 else
3844 {
3845 for (j=0; j<=k; j++)
3846 {
3847 if ((pGetComp(h)==pGetComp(strat->S[j]))
3848 || (pGetComp(strat->S[j])==0))
3849 {
3850 new_pair=TRUE;
3851 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3852 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3853 }
3854 }
3855 }
3856 if (new_pair)
3857 {
3858 #ifdef HAVE_RATGRING
3859 if (currRing->real_var_start>0)
3860 chainCritPart(h,ecart,strat);
3861 else
3862 #endif
3863 strat->chainCrit(h,ecart,strat);
3864 }
3865 kMergeBintoL(strat);
3866 }
3867}
3868
3869/*2
3870*(s[0],h),...,(s[k],h) will be put to the pairset L
3871*using signatures <= only for signature-based standard basis algorithms
3872*/
3873
3874void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3875{
3876
3877 if ((strat->syzComp==0)
3878 || (pGetComp(h)<=strat->syzComp))
3879 {
3880 int j;
3882
3883 if (pGetComp(h)==0)
3884 {
3885 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3886 if ((isFromQ)&&(strat->fromQ!=NULL))
3887 {
3888 for (j=0; j<=k; j++)
3889 {
3890 if (!strat->fromQ[j])
3891 {
3892 new_pair=TRUE;
3893 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3894 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3895 }
3896 }
3897 }
3898 else
3899 {
3900 new_pair=TRUE;
3901 for (j=0; j<=k; j++)
3902 {
3903 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3904 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3905 }
3906 }
3907 }
3908 else
3909 {
3910 for (j=0; j<=k; j++)
3911 {
3912 if ((pGetComp(h)==pGetComp(strat->S[j]))
3913 || (pGetComp(strat->S[j])==0))
3914 {
3915 new_pair=TRUE;
3916 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3917 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3918 }
3919 }
3920 }
3921
3922 if (new_pair)
3923 {
3924#ifdef HAVE_RATGRING
3925 if (currRing->real_var_start>0)
3926 chainCritPart(h,ecart,strat);
3927 else
3928#endif
3929 strat->chainCrit(h,ecart,strat);
3930 }
3931 }
3932}
3933
3934void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3935{
3936
3937 if ((strat->syzComp==0)
3938 || (pGetComp(h)<=strat->syzComp))
3939 {
3940 int j;
3941
3942 if (pGetComp(h)==0)
3943 {
3944 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3945 if ((isFromQ)&&(strat->fromQ!=NULL))
3946 {
3947 for (j=0; j<=k && !strat->sigdrop; j++)
3948 {
3949 if (!strat->fromQ[j])
3950 {
3951 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3952 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3953 }
3954 }
3955 }
3956 else
3957 {
3958 for (j=0; j<=k && !strat->sigdrop; j++)
3959 {
3960 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3961 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3962 }
3963 }
3964 }
3965 else
3966 {
3967 for (j=0; j<=k && !strat->sigdrop; j++)
3968 {
3969 if ((pGetComp(h)==pGetComp(strat->S[j]))
3970 || (pGetComp(strat->S[j])==0))
3971 {
3972 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3973 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3974 }
3975 }
3976 }
3977
3978#if 0
3979 if (new_pair)
3980 {
3981#ifdef HAVE_RATGRING
3982 if (currRing->real_var_start>0)
3983 chainCritPart(h,ecart,strat);
3984 else
3985#endif
3986 strat->chainCrit(h,ecart,strat);
3987 }
3988#endif
3989 }
3990}
3991
3992/*2
3993*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3994*using the chain-criterion in B and L and enters B to L
3995*/
3996void chainCritRing (poly p,int, kStrategy strat)
3997{
3998 int i,j,l;
3999 /*
4000 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4001 *In this case all elements in B such
4002 *that their lcm is divisible by the leading term of S[i] can be canceled
4003 */
4004 if (strat->pairtest!=NULL)
4005 {
4006 {
4007 /*- i.e. there is an i with pairtest[i]==TRUE -*/
4008 for (j=0; j<=strat->sl; j++)
4009 {
4010 if (strat->pairtest[j])
4011 {
4012 for (i=strat->Bl; i>=0; i--)
4013 {
4014 if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4015 {
4016#ifdef KDEBUG
4017 if (TEST_OPT_DEBUG)
4018 {
4019 PrintS("--- chain criterion func chainCritRing type 1\n");
4020 PrintS("strat->S[j]:");
4021 wrp(strat->S[j]);
4022 PrintS(" strat->B[i].lcm:");
4023 wrp(strat->B[i].lcm);PrintLn();
4024 pWrite(strat->B[i].p);
4025 pWrite(strat->B[i].p1);
4026 pWrite(strat->B[i].p2);
4027 wrp(strat->B[i].lcm);
4028 PrintLn();
4029 }
4030#endif
4031 deleteInL(strat->B,&strat->Bl,i,strat);
4032 strat->c3++;
4033 }
4034 }
4035 }
4036 }
4037 }
4038 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4039 strat->pairtest=NULL;
4040 }
4041 assume(!(strat->Gebauer || strat->fromT));
4042 for (j=strat->Ll; j>=0; j--)
4043 {
4044 if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4045 {
4046 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4047 {
4048 if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4049 {
4050 deleteInL(strat->L,&strat->Ll,j,strat);
4051 strat->c3++;
4052#ifdef KDEBUG
4053 if (TEST_OPT_DEBUG)
4054 {
4055 PrintS("--- chain criterion func chainCritRing type 2\n");
4056 PrintS("strat->L[j].p:");
4057 wrp(strat->L[j].p);
4058 PrintS(" p:");
4059 wrp(p);
4060 PrintLn();
4061 }
4062#endif
4063 }
4064 }
4065 }
4066 }
4067 /*
4068 *this is our MODIFICATION of GEBAUER-MOELLER:
4069 *First the elements of B enter L,
4070 *then we fix a lcm and the "best" element in L
4071 *(i.e the last in L with this lcm and of type (s,p))
4072 *and cancel all the other elements of type (r,p) with this lcm
4073 *except the case the element (s,r) has also the same lcm
4074 *and is on the worst position with respect to (s,p) and (r,p)
4075 */
4076 /*
4077 *B enters to L/their order with respect to B is permutated for elements
4078 *B[i].p with the same leading term
4079 */
4080 kMergeBintoL(strat);
4081 j = strat->Ll;
4082 loop /*cannot be changed into a for !!! */
4083 {
4084 if (j <= 0)
4085 {
4086 /*now L[0] cannot be canceled any more and the tail can be removed*/
4087 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4088 break;
4089 }
4090 if (strat->L[j].p2 == p) // Was the element added from B?
4091 {
4092 i = j-1;
4093 loop
4094 {
4095 if (i < 0) break;
4096 // Element is from B and has the same lcm as L[j]
4097 if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4098 && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4099 {
4100 /*L[i] could be canceled but we search for a better one to cancel*/
4101 strat->c3++;
4102#ifdef KDEBUG
4103 if (TEST_OPT_DEBUG)
4104 {
4105 PrintS("--- chain criterion func chainCritRing type 3\n");
4106 PrintS("strat->L[j].lcm:");
4107 wrp(strat->L[j].lcm);
4108 PrintS(" strat->L[i].lcm:");
4109 wrp(strat->L[i].lcm);
4110 PrintLn();
4111 }
4112#endif
4113 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4114 && (pNext(strat->L[l].p) == strat->tail)
4115 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4116 && pDivisibleBy(p,strat->L[l].lcm))
4117 {
4118 /*
4119 *"NOT equal(...)" because in case of "equal" the element L[l]
4120 *is "older" and has to be from theoretical point of view behind
4121 *L[i], but we do not want to reorder L
4122 */
4123 strat->L[i].p2 = strat->tail;
4124 /*
4125 *L[l] will be canceled, we cannot cancel L[i] later on,
4126 *so we mark it with "tail"
4127 */
4128 deleteInL(strat->L,&strat->Ll,l,strat);
4129 i--;
4130 }
4131 else
4132 {
4133 deleteInL(strat->L,&strat->Ll,i,strat);
4134 }
4135 j--;
4136 }
4137 i--;
4138 }
4139 }
4140 else if (strat->L[j].p2 == strat->tail)
4141 {
4142 /*now L[j] cannot be canceled any more and the tail can be removed*/
4143 strat->L[j].p2 = p;
4144 }
4145 j--;
4146 }
4147}
4148
4149/*2
4150*(s[0],h),...,(s[k],h) will be put to the pairset L
4151*/
4152void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4153{
4154 if (!nIsOne(pGetCoeff(h)))
4155 {
4156 int j;
4158
4159 if (pGetComp(h)==0)
4160 {
4161 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4162 if ((isFromQ)&&(strat->fromQ!=NULL))
4163 {
4164 for (j=0; j<=k; j++)
4165 {
4166 if (!strat->fromQ[j])
4167 {
4168 new_pair=TRUE;
4169 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4170 }
4171 }
4172 }
4173 else
4174 {
4175 new_pair=TRUE;
4176 for (j=0; j<=k; j++)
4177 {
4178 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4179 }
4180 }
4181 }
4182 else
4183 {
4184 for (j=0; j<=k; j++)
4185 {
4186 if ((pGetComp(h)==pGetComp(strat->S[j]))
4187 || (pGetComp(strat->S[j])==0))
4188 {
4189 new_pair=TRUE;
4190 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4191 }
4192 }
4193 }
4194 if (new_pair)
4195 {
4196 #ifdef HAVE_RATGRING
4197 if (currRing->real_var_start>0)
4198 chainCritPart(h,ecart,strat);
4199 else
4200 #endif
4201 strat->chainCrit(h,ecart,strat);
4202 }
4203 kMergeBintoL(strat);
4204 }
4205}
4206
4207static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4208{
4209 const int iCompH = pGetComp(h);
4210 if (!nIsOne(pGetCoeff(h)))
4211 {
4212 int j;
4213
4214 for (j=0; j<=k && !strat->sigdrop; j++)
4215 {
4216 // Print("j:%d, Ll:%d\n",j,strat->Ll);
4217// if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4218// ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4219 if (((iCompH == pGetComp(strat->S[j]))
4220 || (0 == pGetComp(strat->S[j])))
4221 && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4222 {
4223 enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4224 }
4225 }
4226 }
4227}
4228
4229/*2
4230* Generates spoly(0, h) if applicable. Assumes ring has zero divisors
4231*/
4233{
4234 if (nIsOne(pGetCoeff(h))) return;
4235 number gcd;
4236 number zero=n_Init(0,currRing->cf);
4237 bool go = false;
4238 if (n_DivBy(zero, pGetCoeff(h), currRing->cf))
4239 {
4240 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4241 go = true;
4242 }
4243 else
4244 gcd = n_Gcd(zero, pGetCoeff(h), strat->tailRing->cf);
4245 if (go || !nIsOne(gcd))
4246 {
4247 poly p = h->next;
4248 if (!go)
4249 {
4250 number tmp = gcd;
4251 gcd = n_Ann(gcd,currRing->cf);
4252 nDelete(&tmp);
4253 }
4254 p_Test(p,strat->tailRing);
4255 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4256
4257 if (p != NULL)
4258 {
4259 if (TEST_OPT_PROT)
4260 {
4261 PrintS("Z");
4262 }
4263#ifdef KDEBUG
4264 if (TEST_OPT_DEBUG)
4265 {
4266 PrintS("--- create zero spoly: ");
4267 p_wrp(h,currRing,strat->tailRing);
4268 PrintS(" ---> ");
4269 }
4270#endif
4271 poly tmp = pInit();
4273 for (int i = 1; i <= rVar(currRing); i++)
4274 {
4275 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4276 }
4278 {
4280 }
4282 p = p_LmFreeAndNext(p, strat->tailRing);
4283 pNext(tmp) = p;
4284 LObject Lp;
4285 Lp.Init();
4286 Lp.p = tmp;
4287 Lp.tailRing = strat->tailRing;
4288 int posx;
4289 if (Lp.p!=NULL)
4290 {
4291 strat->initEcart(&Lp);
4292 if (strat->Ll==-1)
4293 posx =0;
4294 else
4295 posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4296 Lp.sev = pGetShortExpVector(Lp.p);
4297 if (strat->tailRing != currRing)
4298 {
4299 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4300 }
4301#ifdef KDEBUG
4302 if (TEST_OPT_DEBUG)
4303 {
4304 p_wrp(tmp,currRing,strat->tailRing);
4305 PrintLn();
4306 }
4307#endif
4308 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4309 }
4310 }
4311 }
4312 nDelete(&zero);
4313 nDelete(&gcd);
4314}
4315
4317{
4318 if (nIsOne(pGetCoeff(h))) return;
4319 number gcd;
4320 number zero=n_Init(0,currRing->cf);
4321 bool go = false;
4322 if (n_DivBy(zero, pGetCoeff(h), currRing->cf))
4323 {
4324 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4325 go = true;
4326 }
4327 else
4328 gcd = n_Gcd(zero, pGetCoeff(h), strat->tailRing->cf);
4329 if (go || !nIsOne(gcd))
4330 {
4331 poly p = h->next;
4332 if (!go)
4333 {
4334 number tmp = gcd;
4335 gcd = n_Ann(gcd,currRing->cf);
4336 nDelete(&tmp);
4337 }
4338 p_Test(p,strat->tailRing);
4339 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4340
4341 if (p != NULL)
4342 {
4343 if (TEST_OPT_PROT)
4344 {
4345 PrintS("Z");
4346 }
4347#ifdef KDEBUG
4348 if (TEST_OPT_DEBUG)
4349 {
4350 PrintS("--- create zero spoly: ");
4351 p_wrp(h,currRing,strat->tailRing);
4352 PrintS(" ---> ");
4353 }
4354#endif
4355 poly tmp = pInit();
4357 for (int i = 1; i <= rVar(currRing); i++)
4358 {
4359 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4360 }
4362 {
4364 }
4366 p = p_LmFreeAndNext(p, strat->tailRing);
4367 pNext(tmp) = p;
4368 LObject Lp;
4369 Lp.Init();
4370 Lp.p = tmp;
4371 //printf("\nOld\n");pWrite(h);pWrite(hSig);
4372 #if EXT_POLY_NEW
4373 Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4374 if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4375 {
4376 strat->sigdrop = TRUE;
4377 //Try to reduce it as far as we can via redRing
4378 int red_result = redRing(&Lp,strat);
4379 if(red_result == 0)
4380 {
4381 // Cancel the sigdrop
4382 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4383 strat->sigdrop = FALSE;
4384 }
4385 else
4386 {
4387 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4388 #if 1
4389 strat->enterS(Lp,0,strat,strat->tl);
4390 #endif
4391 }
4392 nDelete(&zero);
4393 nDelete(&gcd);
4394 return;
4395 }
4396 #else
4397 Lp.sig = pOne();
4398 if(strat->Ll >= 0)
4399 p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4400 else
4402 #endif
4403 Lp.tailRing = strat->tailRing;
4404 int posx;
4405 if (Lp.p!=NULL)
4406 {
4407 strat->initEcart(&Lp);
4408 if (strat->Ll==-1)
4409 posx =0;
4410 else
4411 posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4412 Lp.sev = pGetShortExpVector(Lp.p);
4413 if (strat->tailRing != currRing)
4414 {
4415 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4416 }
4417#ifdef KDEBUG
4418 if (TEST_OPT_DEBUG)
4419 {
4420 p_wrp(tmp,currRing,strat->tailRing);
4421 PrintLn();
4422 }
4423#endif
4424 //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4425 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4426 }
4427 }
4428 }
4429 nDelete(&gcd);
4430 nDelete(&zero);
4431}
4432
4433void clearSbatch (poly h,int k,int pos,kStrategy strat)
4434{
4435 int j = pos;
4436 if ( (!strat->fromT)
4437 && ((strat->syzComp==0)
4438 ||(pGetComp(h)<=strat->syzComp)
4439 ))
4440 {
4441 // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4442 unsigned long h_sev = pGetShortExpVector(h);
4443 loop
4444 {
4445 if (j > k) break;
4446 clearS(h,h_sev, &j,&k,strat);
4447 j++;
4448 }
4449 // Print("end clearS sl=%d\n",strat->sl);
4450 }
4451}
4452
4453/*2
4454* Generates a sufficient set of spolys (maybe just a finite generating
4455* set of the syzygys)
4456*/
4457void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4458{
4460#if HAVE_SHIFTBBA
4461 assume(!rIsLPRing(currRing)); /* LP should use enterpairsShift */
4462#endif
4463 // enter also zero divisor * poly, if this is non zero and of smaller degree
4465 initenterstrongPairs(h, k, ecart, 0, strat, atR);
4466 initenterpairs(h, k, ecart, 0, strat, atR);
4467 clearSbatch(h, k, pos, strat);
4468}
4469
4470void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4471{
4473 // enter also zero divisor * poly, if this is non zero and of smaller degree
4475 if(strat->sigdrop) return;
4476 initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4477 if(strat->sigdrop) return;
4478 initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4479 if(strat->sigdrop) return;
4480 clearSbatch(h, k, pos, strat);
4481}
4482
4483/*2
4484*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4485*superfluous elements in S will be deleted
4486*/
4487void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4488{
4489 int j=pos;
4490
4492 initenterpairs(h,k,ecart,0,strat, atR);
4493 if ( (!strat->fromT)
4494 && ((strat->syzComp==0)
4495 ||(pGetComp(h)<=strat->syzComp)))
4496 {
4497 unsigned long h_sev = pGetShortExpVector(h);
4498 loop
4499 {
4500 if (j > k) break;
4501 clearS(h,h_sev, &j,&k,strat);
4502 j++;
4503 }
4504 }
4505}
4506
4507/*2
4508*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4509*superfluous elements in S will be deleted
4510*this is a special variant of signature-based algorithms including the
4511*signatures for criteria checks
4512*/
4513void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4514{
4515 int j=pos;
4517 initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4518 if ( (!strat->fromT)
4519 && ((strat->syzComp==0)
4520 ||(pGetComp(h)<=strat->syzComp)))
4521 {
4522 unsigned long h_sev = pGetShortExpVector(h);
4523 loop
4524 {
4525 if (j > k) break;
4526 clearS(h,h_sev, &j,&k,strat);
4527 j++;
4528 }
4529 }
4530}
4531
4532/*2
4533*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4534*superfluous elements in S will be deleted
4535*/
4536void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4537{
4538 int j;
4539 const int iCompH = pGetComp(h);
4540
4542 {
4543 for (j=0; j<=k; j++)
4544 {
4545 const int iCompSj = pGetComp(strat->S[j]);
4546 if ((iCompH==iCompSj)
4547 //|| (0==iCompH) // can only happen,if iCompSj==0
4548 || (0==iCompSj))
4549 {
4550 enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4551 }
4552 }
4553 kMergeBintoL(strat);
4554 }
4555 else
4556 {
4557 for (j=0; j<=k; j++)
4558 {
4559 const int iCompSj = pGetComp(strat->S[j]);
4560 if ((iCompH==iCompSj)
4561 //|| (0==iCompH) // can only happen,if iCompSj==0
4562 || (0==iCompSj))
4563 {
4564 enterOnePairSpecial(j,h,ecart,strat, atR);
4565 }
4566 }
4567 }
4568
4569 if (strat->noClearS) return;
4570
4571// #ifdef HAVE_PLURAL
4572/*
4573 if (rIsPluralRing(currRing))
4574 {
4575 j=pos;
4576 loop
4577 {
4578 if (j > k) break;
4579
4580 if (pLmDivisibleBy(h, strat->S[j]))
4581 {
4582 deleteInS(j, strat);
4583 j--;
4584 k--;
4585 }
4586
4587 j++;
4588 }
4589 }
4590 else
4591*/
4592// #endif // ??? Why was the following cancellation disabled for non-commutative rings?
4593 {
4594 j=pos;
4595 loop
4596 {
4597 unsigned long h_sev = pGetShortExpVector(h);
4598 if (j > k) break;
4599 clearS(h,h_sev,&j,&k,strat);
4600 j++;
4601 }
4602 }
4603}
4604
4605/*2
4606*reorders s with respect to posInS,
4607*suc is the first changed index or zero
4608*/
4609
4610void reorderS (int* suc,kStrategy strat)
4611{
4612 int i,j,at,ecart, s2r;
4613 int fq=0;
4614 unsigned long sev;
4615 poly p;
4616 int new_suc=strat->sl+1;
4617 i= *suc;
4618 if (i<0) i=0;
4619
4620 for (; i<=strat->sl; i++)
4621 {
4622 at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4623 if (at != i)
4624 {
4625 if (new_suc > at) new_suc = at;
4626 p = strat->S[i];
4627 ecart = strat->ecartS[i];
4628 sev = strat->sevS[i];
4629 s2r = strat->S_2_R[i];
4630 if (strat->fromQ!=NULL) fq=strat->fromQ[i];
4631 for (j=i; j>=at+1; j--)
4632 {
4633 strat->S[j] = strat->S[j-1];
4634 strat->ecartS[j] = strat->ecartS[j-1];
4635 strat->sevS[j] = strat->sevS[j-1];
4636 strat->S_2_R[j] = strat->S_2_R[j-1];
4637 }
4638 strat->S[at] = p;
4639 strat->ecartS[at] = ecart;
4640 strat->sevS[at] = sev;
4641 strat->S_2_R[at] = s2r;
4642 if (strat->fromQ!=NULL)
4643 {
4644 for (j=i; j>=at+1; j--)
4645 {
4646 strat->fromQ[j] = strat->fromQ[j-1];
4647 }
4648 strat->fromQ[at]=fq;
4649 }
4650 }
4651 }
4653 else *suc=-1;
4654}
4655
4656
4657/*2
4658*looks up the position of p in set
4659*set[0] is the smallest with respect to the ordering-procedure deg/pComp
4660* Assumption: posInS only depends on the leading term
4661* otherwise, bba has to be changed
4662*/
4663int posInS (const kStrategy strat, const int length,const poly p,
4664 const int ecart_p)
4665{
4666 if(length==-1) return 0;
4667 polyset set=strat->S;
4668 int i;
4669 int an = 0;
4670 int en = length;
4671 int cmp_int = currRing->OrdSgn;
4674 && (currRing->real_var_start==0)
4675#endif
4676#if 0
4677 || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
4678#endif
4679 )
4680 {
4681 int o=p_Deg(p,currRing);
4682 int oo=p_Deg(set[length],currRing);
4683
4684 if ((oo<o)
4685 || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
4686 return length+1;
4687
4688 loop
4689 {
4690 if (an >= en-1)
4691 {
4692 if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
4693 {
4694 return an;
4695 }
4696 return en;
4697 }
4698 i=(an+en) / 2;
4699 if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
4700 else an=i;
4701 }
4702 }
4703 else
4704 {
4706 {
4707 if (pLmCmp(set[length],p)== -cmp_int)
4708 return length+1;
4709 int cmp;
4710 loop
4711 {
4712 if (an >= en-1)
4713 {
4714 cmp = pLmCmp(set[an],p);
4715 if (cmp == cmp_int) return an;
4716 if (cmp == -cmp_int) return en;
4717 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
4718 return an;
4719 }
4720 i = (an+en) / 2;
4721 cmp = pLmCmp(set[i],p);
4722 if (cmp == cmp_int) en = i;
4723 else if (cmp == -cmp_int) an = i;
4724 else
4725 {
4726 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
4727 else en = i;
4728 }
4729 }
4730 }
4731 else
4732 if (pLmCmp(set[length],p)== -cmp_int)
4733 return length+1;
4734
4735 loop
4736 {
4737 if (an >= en-1)
4738 {
4739 if (pLmCmp(set[an],p) == cmp_int) return an;
4740 if (pLmCmp(set[an],p) == -cmp_int) return en;
4741 if ((cmp_int!=1)
4742 && ((strat->ecartS[an])>ecart_p))
4743 return an;
4744 return en;
4745 }
4746 i=(an+en) / 2;
4747 if (pLmCmp(set[i],p) == cmp_int) en=i;
4748 else if (pLmCmp(set[i],p) == -cmp_int) an=i;
4749 else
4750 {
4751 if ((cmp_int!=1)
4752 &&((strat->ecartS[i])<ecart_p))
4753 en=i;
4754 else
4755 an=i;
4756 }
4757 }
4758 }
4759}
4760
4761
4762// sorts by degree and pLtCmp
4763// but puts pure monomials at the beginning
4764int posInSMonFirst (const kStrategy strat, const int length,const poly p)
4765{
4766 if (length<0) return 0;
4767 polyset set=strat->S;
4768 if(pNext(p) == NULL)
4769 {
4770 int mon = 0;
4771 for(int i = 0;i<=length;i++)
4772 {
4773 if(set[i] != NULL && pNext(set[i]) == NULL)
4774 mon++;
4775 }
4776 int o = p_Deg(p,currRing);
4777 int op = p_Deg(set[mon],currRing);
4778
4779 if ((op < o)
4780 || ((op == o) && (pLtCmp(set[mon],p) == -1)))
4781 return length+1;
4782 int i;
4783 int an = 0;
4784 int en= mon;
4785 loop
4786 {
4787 if (an >= en-1)
4788 {
4789 op = p_Deg(set[an],currRing);
4790 if ((op < o)
4791 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4792 return en;
4793 return an;
4794 }
4795 i=(an+en) / 2;
4796 op = p_Deg(set[i],currRing);
4797 if ((op < o)
4798 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4799 an=i;
4800 else
4801 en=i;
4802 }
4803 }
4804 else /*if(pNext(p) != NULL)*/
4805 {
4806 int o = p_Deg(p,currRing);
4807 int op = p_Deg(set[length],currRing);
4808
4809 if ((op < o)
4810 || ((op == o) && (pLtCmp(set[length],p) == -1)))
4811 return length+1;
4812 int i;
4813 int an = 0;
4814 for(i=0;i<=length;i++)
4815 if(set[i] != NULL && pNext(set[i]) == NULL)
4816 an++;
4817 int en= length;
4818 loop
4819 {
4820 if (an >= en-1)
4821 {
4822 op = p_Deg(set[an],currRing);
4823 if ((op < o)
4824 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4825 return en;
4826 return an;
4827 }
4828 i=(an+en) / 2;
4829 op = p_Deg(set[i],currRing);
4830 if ((op < o)
4831 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4832 an=i;
4833 else
4834 en=i;
4835 }
4836 }
4837}
4838
4839// sorts by degree and pLtCmp in the block between start,end;
4840// but puts pure monomials at the beginning
4841int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
4842{
4844 end = IDELEMS(F);
4845 if (end<0) return 0;
4846 if(pNext(p) == NULL) return start;
4847 polyset set=F->m;
4848 int o = p_Deg(p,currRing);
4849 int op;
4850 int i;
4851 int an = start;
4852 for(i=start;i<end;i++)
4853 if(set[i] != NULL && pNext(set[i]) == NULL)
4854 an++;
4855 if(an == end-1)
4856 return end;
4857 int en= end;
4858 loop
4859 {
4860 if(an>=en)
4861 return en;
4862 if (an == en-1)
4863 {
4864 op = p_Deg(set[an],currRing);
4865 if ((op < o)
4866 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4867 return en;
4868 return an;
4869 }
4870 i=(an+en) / 2;
4871 op = p_Deg(set[i],currRing);
4872 if ((op < o)
4873 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4874 an=i;
4875 else
4876 en=i;
4877 }
4878}
4879
4880
4881/*2
4882* looks up the position of p in set
4883* the position is the last one
4884*/
4885int posInT0 (const TSet,const int length,LObject &)
4886{
4887 return (length+1);
4888}
4889
4890
4891/*2
4892* looks up the position of p in T
4893* set[0] is the smallest with respect to the ordering-procedure
4894* pComp
4895*/
4896int posInT1 (const TSet set,const int length,LObject &p)
4897{
4898 if (length==-1) return 0;
4899
4900 if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
4901
4902 int i;
4903 int an = 0;
4904 int en= length;
4905 int cmp_int=currRing->OrdSgn;
4906
4907 loop
4908 {
4909 if (an >= en-1)
4910 {
4911 if (pLmCmp(set[an].p,p.p) == cmp_int) return an;
4912 return en;
4913 }
4914 i=(an+en) / 2;
4915 if (pLmCmp(set[i].p,p.p) == cmp_int) en=i;
4916 else an=i;
4917 }
4918}
4919
4920/*2
4921* looks up the position of p in T
4922* set[0] is the smallest with respect to the ordering-procedure
4923* length
4924*/
4925int posInT2 (const TSet set,const int length,LObject &p)
4926{
4927 if (length==-1) return 0;
4928 p.GetpLength();
4929 if (set[length].length<p.length) return length+1;
4930
4931 int i;
4932 int an = 0;
4933 int en= length;
4934
4935 loop
4936 {
4937 if (an >= en-1)
4938 {
4939 if (set[an].length>p.length) return an;
4940 return en;
4941 }
4942 i=(an+en) / 2;
4943 if (set[i].length>p.length) en=i;
4944 else an=i;
4945 }
4946}
4947
4948/*2
4949* looks up the position of p in T
4950* set[0] is the smallest with respect to the ordering-procedure
4951* totaldegree,pComp
4952*/
4953int posInT11 (const TSet set,const int length,LObject &p)
4954{
4955 if (length==-1) return 0;
4956
4957 int o = p.GetpFDeg();
4958 int op = set[length].GetpFDeg();
4959 int cmp_int=currRing->OrdSgn;
4960
4961 if ((op < o)
4962 || ((op == o) && (pLmCmp(set[length].p,p.p) != cmp_int)))
4963 return length+1;
4964
4965 int i;
4966 int an = 0;
4967 int en= length;
4968
4969 loop
4970 {
4971 if (an >= en-1)
4972 {
4973 op= set[an].GetpFDeg();
4974 if ((op > o)
4975 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
4976 return an;
4977 return en;
4978 }
4979 i=(an+en) / 2;
4980 op = set[i].GetpFDeg();
4981 if (( op > o)
4982 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
4983 en=i;
4984 else
4985 an=i;
4986 }
4987}
4988
4989int posInT11Ring (const TSet set,const int length,LObject &p)
4990{
4991 if (length==-1) return 0;
4992
4993 int o = p.GetpFDeg();
4994 int op = set[length].GetpFDeg();
4995
4996 if ((op < o)
4997 || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
4998 return length+1;
4999
5000 int i;
5001 int an = 0;
5002 int en= length;
5003
5004 loop
5005 {
5006 if (an >= en-1)
5007 {
5008 op= set[an].GetpFDeg();
5009 if ((op > o)
5010 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5011 return an;
5012 return en;
5013 }
5014 i=(an+en) / 2;
5015 op = set[i].GetpFDeg();
5016 if (( op > o)
5017 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5018 en=i;
5019 else
5020 an=i;
5021 }
5022}
5023
5024/*2
5025* looks up the position of p in T
5026* set[0] is the smallest with respect to the ordering-procedure
5027* totaldegree,pComp
5028*/
5029int posInT110 (const TSet set,const int length,LObject &p)
5030{
5031 if (length==-1) return 0;
5032 p.GetpLength();
5033
5034 int o = p.GetpFDeg();
5035 int op = set[length].GetpFDeg();
5036 int cmp_int=currRing->OrdSgn;
5037
5038 if (( op < o)
5039 || (( op == o) && (set[length].length<p.length))
5040 || (( op == o) && (set[length].length == p.length)
5041 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5042 return length+1;
5043
5044 int i;
5045 int an = 0;
5046 int en= length;
5047 loop
5048 {
5049 if (an >= en-1)
5050 {
5051 op = set[an].GetpFDeg();
5052 if (( op > o)
5053 || (( op == o) && (set[an].length > p.length))
5054 || (( op == o) && (set[an].length == p.length)
5055 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5056 return an;
5057 return en;
5058 }
5059 i=(an+en) / 2;
5060 op = set[i].GetpFDeg();
5061 if (( op > o)
5062 || (( op == o) && (set[i].length > p.length))
5063 || (( op == o) && (set[i].length == p.length)
5064 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5065 en=i;
5066 else
5067 an=i;
5068 }
5069}
5070
5071int posInT110Ring (const TSet set,const int length,LObject &p)
5072{
5073 if (length==-1) return 0;
5074 p.GetpLength();
5075
5076 int o = p.GetpFDeg();
5077 int op = set[length].GetpFDeg();
5078
5079 if (( op < o)
5080 || (( op == o) && (set[length].length<p.length))
5081 || (( op == o) && (set[length].length == p.length)
5082 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5083 return length+1;
5084
5085 int i;
5086 int an = 0;
5087 int en= length;
5088 loop
5089 {
5090 if (an >= en-1)
5091 {
5092 op = set[an].GetpFDeg();
5093 if (( op > o)
5094 || (( op == o) && (set[an].length > p.length))
5095 || (( op == o) && (set[an].length == p.length)
5096 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5097 return an;
5098 return en;
5099 }
5100 i=(an+en) / 2;
5101 op = set[i].GetpFDeg();
5102 if (( op > o)
5103 || (( op == o) && (set[i].length > p.length))
5104 || (( op == o) && (set[i].length == p.length)
5105 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5106 en=i;
5107 else
5108 an=i;
5109 }
5110}
5111
5112/*2
5113* looks up the position of p in set
5114* set[0] is the smallest with respect to the ordering-procedure
5115* pFDeg
5116*/
5117int posInT13 (const TSet set,const int length,LObject &p)
5118{
5119 if (length==-1) return 0;
5120
5121 int o = p.GetpFDeg();
5122
5123 if (set[length].GetpFDeg() <= o)
5124 return length+1;
5125
5126 int i;
5127 int an = 0;
5128 int en= length;
5129 loop
5130 {
5131 if (an >= en-1)
5132 {
5133 if (set[an].GetpFDeg() > o)
5134 return an;
5135 return en;
5136 }
5137 i=(an+en) / 2;
5138 if (set[i].GetpFDeg() > o)
5139 en=i;
5140 else
5141 an=i;
5142 }
5143}
5144
5145// determines the position based on: 1.) Ecart 2.) pLength
5146int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5147{
5148 if (length==-1) return 0;
5149 int ol = p.GetpLength();
5150 int op=p.ecart;
5151 int oo=set[length].ecart;
5152
5153 if ((oo < op) || ((oo==op) && (set[length].length <= ol)))
5154 return length+1;
5155
5156 int i;
5157 int an = 0;
5158 int en= length;
5159 loop
5160 {
5161 if (an >= en-1)
5162 {
5163 int oo=set[an].ecart;
5164 if((oo > op)
5165 || ((oo==op) && (set[an].pLength > ol)))
5166 return an;
5167 return en;
5168 }
5169 i=(an+en) / 2;
5170 int oo=set[i].ecart;
5171 if ((oo > op)
5172 || ((oo == op) && (set[i].pLength > ol)))
5173 en=i;
5174 else
5175 an=i;
5176 }
5177}
5178
5179/*2
5180* looks up the position of p in set
5181* set[0] is the smallest with respect to the ordering-procedure
5182* maximaldegree, pComp
5183*/
5184int posInT15 (const TSet set,const int length,LObject &p)
5185/*{
5186 *int j=0;
5187 * int o;
5188 *
5189 * o = p.GetpFDeg()+p.ecart;
5190 * loop
5191 * {
5192 * if ((set[j].GetpFDeg()+set[j].ecart > o)
5193 * || ((set[j].GetpFDeg()+set[j].ecart == o)
5194 * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5195 * {
5196 * return j;
5197 * }
5198 * j++;
5199 * if (j > length) return j;
5200 * }
5201 *}
5202 */
5203{
5204 if (length==-1) return 0;
5205
5206 int o = p.GetpFDeg() + p.ecart;
5207 int op = set[length].GetpFDeg()+set[length].ecart;
5208 int cmp_int=currRing->OrdSgn;
5209
5210 if ((op < o)
5211 || ((op == o)
5212 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5213 return length+1;
5214
5215 int i;
5216 int an = 0;
5217 int en= length;
5218 loop
5219 {
5220 if (an >= en-1)
5221 {
5222 op = set[an].GetpFDeg()+set[an].ecart;
5223 if (( op > o)
5224 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
5225 return an;
5226 return en;
5227 }
5228 i=(an+en) / 2;
5229 op = set[i].GetpFDeg()+set[i].ecart;
5230 if (( op > o)
5231 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
5232 en=i;
5233 else
5234 an=i;
5235 }
5236}
5237
5238int posInT15Ring (const TSet set,const int length,LObject &p)
5239{
5240 if (length==-1) return 0;
5241
5242 int o = p.GetpFDeg() + p.ecart;
5243 int op = set[length].GetpFDeg()+set[length].ecart;
5244
5245 if ((op < o)
5246 || ((op == o)
5247 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5248 return length+1;
5249
5250 int i;
5251 int an = 0;
5252 int en= length;
5253 loop
5254 {
5255 if (an >= en-1)
5256 {
5257 op = set[an].GetpFDeg()+set[an].ecart;
5258 if (( op > o)
5259 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5260 return an;
5261 return en;
5262 }
5263 i=(an+en) / 2;
5264 op = set[i].GetpFDeg()+set[i].ecart;
5265 if (( op > o)
5266 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5267 en=i;
5268 else
5269 an=i;
5270 }
5271}
5272
5273/*2
5274* looks up the position of p in set
5275* set[0] is the smallest with respect to the ordering-procedure
5276* pFDeg+ecart, ecart, pComp
5277*/
5278int posInT17 (const TSet set,const int length,LObject &p)
5279/*
5280*{
5281* int j=0;
5282* int o;
5283*
5284* o = p.GetpFDeg()+p.ecart;
5285* loop
5286* {
5287* if ((pFDeg(set[j].p)+set[j].ecart > o)
5288* || (((pFDeg(set[j].p)+set[j].ecart == o)
5289* && (set[j].ecart < p.ecart)))
5290* || ((pFDeg(set[j].p)+set[j].ecart == o)
5291* && (set[j].ecart==p.ecart)
5292* && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5293* return j;
5294* j++;
5295* if (j > length) return j;
5296* }
5297* }
5298*/
5299{
5300 if (length==-1) return 0;
5301
5302 int o = p.GetpFDeg() + p.ecart;
5303 int op = set[length].GetpFDeg()+set[length].ecart;
5304 int cmp_int=currRing->OrdSgn;
5305
5306 if ((op < o)
5307 || (( op == o) && (set[length].ecart > p.ecart))
5308 || (( op == o) && (set[length].ecart==p.ecart)
5309 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5310 return length+1;
5311
5312 int i;
5313 int an = 0;
5314 int en= length;
5315 loop
5316 {
5317 if (an >= en-1)
5318 {
5319 op = set[an].GetpFDeg()+set[an].ecart;
5320 if (( op > o)
5321 || (( op == o) && (set[an].ecart < p.ecart))
5322 || (( op == o) && (set[an].ecart==p.ecart)
5323 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5324 return an;
5325 return en;
5326 }
5327 i=(an+en) / 2;
5328 op = set[i].GetpFDeg()+set[i].ecart;
5329 if ((op > o)
5330 || (( op == o) && (set[i].ecart < p.ecart))
5331 || (( op == o) && (set[i].ecart == p.ecart)
5332 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5333 en=i;
5334 else
5335 an=i;
5336 }
5337}
5338
5339int posInT17Ring (const TSet set,const int length,LObject &p)
5340{
5341 if (length==-1) return 0;
5342
5343 int o = p.GetpFDeg() + p.ecart;
5344 int op = set[length].GetpFDeg()+set[length].ecart;
5345
5346 if ((op < o)
5347 || (( op == o) && (set[length].ecart > p.ecart))
5348 || (( op == o) && (set[length].ecart==p.ecart)
5349 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5350 return length+1;
5351
5352 int i;
5353 int an = 0;
5354 int en= length;
5355 loop
5356 {
5357 if (an >= en-1)
5358 {
5359 op = set[an].GetpFDeg()+set[an].ecart;
5360 if (( op > o)
5361 || (( op == o) && (set[an].ecart < p.ecart))
5362 || (( op == o) && (set[an].ecart==p.ecart)
5363 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5364 return an;
5365 return en;
5366 }
5367 i=(an+en) / 2;
5368 op = set[i].GetpFDeg()+set[i].ecart;
5369 if ((op > o)
5370 || (( op == o) && (set[i].ecart < p.ecart))
5371 || (( op == o) && (set[i].ecart == p.ecart)
5372 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5373 en=i;
5374 else
5375 an=i;
5376 }
5377}
5378
5379/*2
5380* looks up the position of p in set
5381* set[0] is the smallest with respect to the ordering-procedure
5382* pGetComp, pFDeg+ecart, ecart, pComp
5383*/
5384int posInT17_c (const TSet set,const int length,LObject &p)
5385{
5386 if (length==-1) return 0;
5387
5388 int cc = (-1+2*currRing->order[0]==ringorder_c);
5389 /* cc==1 for (c,..), cc==-1 for (C,..) */
5390 int o = p.GetpFDeg() + p.ecart;
5391 int c = pGetComp(p.p)*cc;
5392 int cmp_int=currRing->OrdSgn;
5393
5394 if (pGetComp(set[length].p)*cc < c)
5395 return length+1;
5396 if (pGetComp(set[length].p)*cc == c)
5397 {
5398 int op = set[length].GetpFDeg()+set[length].ecart;
5399 if ((op < o)
5400 || ((op == o) && (set[length].ecart > p.ecart))
5401 || ((op == o) && (set[length].ecart==p.ecart)
5402 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5403 return length+1;
5404 }
5405
5406 int i;
5407 int an = 0;
5408 int en= length;
5409 loop
5410 {
5411 if (an >= en-1)
5412 {
5413 if (pGetComp(set[an].p)*cc < c)
5414 return en;
5415 if (pGetComp(set[an].p)*cc == c)
5416 {
5417 int op = set[an].GetpFDeg()+set[an].ecart;
5418 if ((op > o)
5419 || ((op == o) && (set[an].ecart < p.ecart))
5420 || ((op == o) && (set[an].ecart==p.ecart)
5421 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5422 return an;
5423 }
5424 return en;
5425 }
5426 i=(an+en) / 2;
5427 if (pGetComp(set[i].p)*cc > c)
5428 en=i;
5429 else if (pGetComp(set[i].p)*cc == c)
5430 {
5431 int op = set[i].GetpFDeg()+set[i].ecart;
5432 if ((op > o)
5433 || ((op == o) && (set[i].ecart < p.ecart))
5434 || ((op == o) && (set[i].ecart == p.ecart)
5435 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5436 en=i;
5437 else
5438 an=i;
5439 }
5440 else
5441 an=i;
5442 }
5443}
5444
5445int posInT17_cRing (const TSet set,const int length,LObject &p)
5446{
5447 if (length==-1) return 0;
5448
5449 int cc = (-1+2*currRing->order[0]==ringorder_c);
5450 /* cc==1 for (c,..), cc==-1 for (C,..) */
5451 int o = p.GetpFDeg() + p.ecart;
5452 int c = pGetComp(p.p)*cc;
5453
5454 if (pGetComp(set[length].p)*cc < c)
5455 return length+1;
5456 if (pGetComp(set[length].p)*cc == c)
5457 {
5458 int op = set[length].GetpFDeg()+set[length].ecart;
5459 if ((op < o)
5460 || ((op == o) && (set[length].ecart > p.ecart))
5461 || ((op == o) && (set[length].ecart==p.ecart)
5462 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5463 return length+1;
5464 }
5465
5466 int i;
5467 int an = 0;
5468 int en= length;
5469 loop
5470 {
5471 if (an >= en-1)
5472 {
5473 if (pGetComp(set[an].p)*cc < c)
5474 return en;
5475 if (pGetComp(set[an].p)*cc == c)
5476 {
5477 int op = set[an].GetpFDeg()+set[an].ecart;
5478 if ((op > o)
5479 || ((op == o) && (set[an].ecart < p.ecart))
5480 || ((op == o) && (set[an].ecart==p.ecart)
5481 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5482 return an;
5483 }
5484 return en;
5485 }
5486 i=(an+en) / 2;
5487 if (pGetComp(set[i].p)*cc > c)
5488 en=i;
5489 else if (pGetComp(set[i].p)*cc == c)
5490 {
5491 int op = set[i].GetpFDeg()+set[i].ecart;
5492 if ((op > o)
5493 || ((op == o) && (set[i].ecart < p.ecart))
5494 || ((op == o) && (set[i].ecart == p.ecart)
5495 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5496 en=i;
5497 else
5498 an=i;
5499 }
5500 else
5501 an=i;
5502 }
5503}
5504
5505/*2
5506* looks up the position of p in set
5507* set[0] is the smallest with respect to
5508* ecart, pFDeg, length
5509*/
5510int posInT19 (const TSet set,const int length,LObject &p)
5511{
5512 p.GetpLength();
5513 if (length==-1) return 0;
5514
5515 int o = p.ecart;
5516 int op=p.GetpFDeg();
5517
5518 if (set[length].ecart < o)
5519 return length+1;
5520 if (set[length].ecart == o)
5521 {
5522 int oo=set[length].GetpFDeg();
5523 if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5524 return length+1;
5525 }
5526
5527 int i;
5528 int an = 0;
5529 int en= length;
5530 loop
5531 {
5532 if (an >= en-1)
5533 {
5534 if (set[an].ecart > o)
5535 return an;
5536 if (set[an].ecart == o)
5537 {
5538 int oo=set[an].GetpFDeg();
5539 if((oo > op)
5540 || ((oo==op) && (set[an].length > p.length)))
5541 return an;
5542 }
5543 return en;
5544 }
5545 i=(an+en) / 2;
5546 if (set[i].ecart > o)
5547 en=i;
5548 else if (set[i].ecart == o)
5549 {
5550 int oo=set[i].GetpFDeg();
5551 if ((oo > op)
5552 || ((oo == op) && (set[i].length > p.length)))
5553 en=i;
5554 else
5555 an=i;
5556 }
5557 else
5558 an=i;
5559 }
5560}
5561
5562/*2
5563*looks up the position of polynomial p in set
5564*set[length] is the smallest element in set with respect
5565*to the ordering-procedure pComp
5566*/
5567int posInLSpecial (const LSet set, const int length,
5568 LObject *p,const kStrategy)
5569{
5570 if (length<0) return 0;
5571
5572 int d=p->GetpFDeg();
5573 int op=set[length].GetpFDeg();
5574 int cmp_int=currRing->OrdSgn;
5575
5576 if ((op > d)
5577 || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
5578 || (pLmCmp(set[length].p,p->p)== cmp_int))
5579 return length+1;
5580
5581 int i;
5582 int an = 0;
5583 int en= length;
5584 loop
5585 {
5586 if (an >= en-1)
5587 {
5588 op=set[an].GetpFDeg();
5589 if ((op > d)
5590 || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
5591 || (pLmCmp(set[an].p,p->p)== cmp_int))
5592 return en;
5593 return an;
5594 }
5595 i=(an+en) / 2;
5596 op=set[i].GetpFDeg();
5597 if ((op>d)
5598 || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
5599 || (pLmCmp(set[i].p,p->p) == cmp_int))
5600 an=i;
5601 else
5602 en=i;
5603 }
5604}
5605
5606/*2
5607*looks up the position of polynomial p in set
5608*set[length] is the smallest element in set with respect
5609*to the ordering-procedure pComp
5610*/
5611int posInL0 (const LSet set, const int length,
5612 LObject* p,const kStrategy)
5613{
5614 if (length<0) return 0;
5615
5616 int cmp_int=currRing->OrdSgn;
5617
5618 if (pLmCmp(set[length].p,p->p)== cmp_int)
5619 return length+1;
5620
5621 int i;
5622 int an = 0;
5623 int en= length;
5624 loop
5625 {
5626 if (an >= en-1)
5627 {
5628 if (pLmCmp(set[an].p,p->p) == cmp_int) return en;
5629 return an;
5630 }
5631 i=(an+en) / 2;
5632 if (pLmCmp(set[i].p,p->p) == cmp_int) an=i;
5633 else en=i;
5634 /*aend. fuer lazy == in !=- machen */
5635 }
5636}
5637
5638int posInL0Ring (const LSet set, const int length,
5639 LObject* p,const kStrategy)
5640{
5641 if (length<0) return 0;
5642
5643 if (pLtCmpOrdSgnEqP(set[length].p,p->p))
5644 return length+1;
5645
5646 int i;
5647 int an = 0;
5648 int en= length;
5649 loop
5650 {
5651 if (an >= en-1)
5652 {
5653 if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
5654 return an;
5655 }
5656 i=(an+en) / 2;
5657 if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
5658 else en=i;
5659 /*aend. fuer lazy == in !=- machen */
5660 }
5661}
5662
5663/*2
5664* looks up the position of polynomial p in set
5665* e is the ecart of p
5666* set[length] is the smallest element in set with respect
5667* to the signature order
5668*/
5669int posInLSig (const LSet set, const int length,
5670 LObject* p,const kStrategy /*strat*/)
5671{
5672 if (length<0) return 0;
5673 int cmp_int=currRing->OrdSgn;
5674 if (pLtCmp(set[length].sig,p->sig)==cmp_int)
5675 return length+1;
5676
5677 int i;
5678 int an = 0;
5679 int en= length;
5680 loop
5681 {
5682 if (an >= en-1)
5683 {
5684 if (pLtCmp(set[an].sig,p->sig) == cmp_int) return en;
5685 return an;
5686 }
5687 i=(an+en) / 2;
5688 if (pLtCmp(set[i].sig,p->sig) == cmp_int) an=i;
5689 else en=i;
5690 /*aend. fuer lazy == in !=- machen */
5691 }
5692}
5693//sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
5694int posInLSigRing (const LSet set, const int length,
5695 LObject* p,const kStrategy /*strat*/)
5696{
5697 assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
5698 if (length<0) return 0;
5699 if (pLtCmp(set[length].sig,p->sig)== 1)
5700 return length+1;
5701
5702 int an,en,i;
5703 an = 0;
5704 en = length+1;
5705 int cmp;
5706 loop
5707 {
5708 if (an >= en-1)
5709 {
5710 if(an == en)
5711 return en;
5712 cmp = pLtCmp(set[an].sig,p->sig);
5713 if (cmp == 1)
5714 return en;
5715 if (cmp == -1)
5716 return an;
5717 if (cmp == 0)
5718 {
5719 if (set[an].FDeg > p->FDeg)
5720 return en;
5721 if (set[an].FDeg < p->FDeg)
5722 return an;
5723 if (set[an].FDeg == p->FDeg)
5724 {
5725 cmp = pLtCmp(set[an].p,p->p);
5726 if(cmp == 1)
5727 return en;
5728 else
5729 return an;
5730 }
5731 }
5732 }
5733 i=(an+en) / 2;
5734 cmp = pLtCmp(set[i].sig,p->sig);
5735 if (cmp == 1)
5736 an = i;
5737 if (cmp == -1)
5738 en = i;
5739 if (cmp == 0)
5740 {
5741 if (set[i].FDeg > p->FDeg)
5742 an = i;
5743 if (set[i].FDeg < p->FDeg)
5744 en = i;
5745 if (set[i].FDeg == p->FDeg)
5746 {
5747 cmp = pLtCmp(set[i].p,p->p);
5748 if(cmp == 1)
5749 an = i;
5750 else
5751 en = i;
5752 }
5753 }
5754 }
5755}
5756
5757// for sba, sorting syzygies
5758int posInSyz (const kStrategy strat, poly sig)
5759{
5760 if (strat->syzl==0) return 0;
5761 int cmp_int=currRing->OrdSgn;
5762 if (pLtCmp(strat->syz[strat->syzl-1],sig) != cmp_int)
5763 return strat->syzl;
5764 int i;
5765 int an = 0;
5766 int en= strat->syzl-1;
5767 loop
5768 {
5769 if (an >= en-1)
5770 {
5771 if (pLtCmp(strat->syz[an],sig) != cmp_int) return en;
5772 return an;
5773 }
5774 i=(an+en) / 2;
5775 if (pLtCmp(strat->syz[i],sig) != cmp_int) an=i;
5776 else en=i;
5777 /*aend. fuer lazy == in !=- machen */
5778 }
5779}
5780
5781/*2
5782*
5783* is only used in F5C, must ensure that the interreduction process does add new
5784* critical pairs to strat->L only behind all other critical pairs which are
5785* still in strat->L!
5786*/
5787int posInLF5C (const LSet /*set*/, const int /*length*/,
5788 LObject* /*p*/,const kStrategy strat)
5789{
5790 return strat->Ll+1;
5791}
5792
5793/*2
5794* looks up the position of polynomial p in set
5795* e is the ecart of p
5796* set[length] is the smallest element in set with respect
5797* to the ordering-procedure totaldegree,pComp
5798*/
5799int posInL11 (const LSet set, const int length,
5800 LObject* p,const kStrategy)
5801{
5802 if (length<0) return 0;
5803
5804 int o = p->GetpFDeg();
5805 int op = set[length].GetpFDeg();
5806 int cmp_int= -currRing->OrdSgn;
5807
5808 if ((op > o)
5809 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
5810 return length+1;
5811 int i;
5812 int an = 0;
5813 int en= length;
5814 loop
5815 {
5816 if (an >= en-1)
5817 {
5818 op = set[an].GetpFDeg();
5819 if ((op > o)
5820 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
5821 return en;
5822 return an;
5823 }
5824 i=(an+en) / 2;
5825 op = set[i].GetpFDeg();
5826 if ((op > o)
5827 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
5828 an=i;
5829 else
5830 en=i;
5831 }
5832}
5833
5834/*2
5835* looks up the position of polynomial p in set
5836* set[length] is the smallest element in set with respect
5837* to the ordering-procedure pLmCmp,totaldegree,coefficient
5838* For the same totaldegree, original pairs (from F) will
5839* be put at the end and smallest coefficients
5840*/
5841int posInL11Ring (const LSet set, const int length,
5842 LObject* p,const kStrategy)
5843{
5844 if (length<0) return 0;
5845
5846 int o = p->GetpFDeg();
5847 int op = set[length].GetpFDeg();
5848
5849 if ((op > o)
5850 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5851 return length+1;
5852 int i;
5853 int an = 0;
5854 int en= length;
5855 loop
5856 {
5857 if (an >= en-1)
5858 {
5859 op = set[an].GetpFDeg();
5860 if ((op > o)
5861 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5862 return en;
5863 return an;
5864 }
5865 i=(an+en) / 2;
5866 op = set[i].GetpFDeg();
5867 if ((op > o)
5868 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5869 an=i;
5870 else
5871 en=i;
5872 }
5873}
5874
5875int posInLF5CRing (const LSet set, int start,const int length,
5876 LObject* p,const kStrategy)
5877{
5878 if (length<0) return 0;
5879 if(start == (length +1)) return (length+1);
5880 int o = p->GetpFDeg();
5881 int op = set[length].GetpFDeg();
5882
5883 if ((op > o)
5884 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5885 return length+1;
5886 int i;
5887 int an = start;
5888 int en= length;
5889 loop
5890 {
5891 if (an >= en-1)
5892 {
5893 op = set[an].GetpFDeg();
5894 if ((op > o)
5895 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5896 return en;
5897 return an;
5898 }
5899 i=(an+en) / 2;
5900 op = set[i].GetpFDeg();
5901 if ((op > o)
5902 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5903 an=i;
5904 else
5905 en=i;
5906 }
5907}
5908
5909int posInL11Ringls (const LSet set, const int length,
5910 LObject* p,const kStrategy)
5911{
5912 if (length < 0) return 0;
5913 int an,en,i;
5914 an = 0;
5915 en = length+1;
5916 loop
5917 {
5918 if (an >= en-1)
5919 {
5920 if(an == en)
5921 return en;
5922 if (set[an].FDeg > p->FDeg)
5923 return en;
5924 if (set[an].FDeg < p->FDeg)
5925 return an;
5926 if (set[an].FDeg == p->FDeg)
5927 {
5929 lcset = pGetCoeff(set[an].p);
5930 lcp = pGetCoeff(p->p);
5931 if(!nGreaterZero(lcset))
5932 {
5933 set[an].p=p_Neg(set[an].p,currRing);
5934 if (set[an].t_p!=NULL)
5935 pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
5936 lcset=pGetCoeff(set[an].p);
5937 }
5938 if(!nGreaterZero(lcp))
5939 {
5940 p->p=p_Neg(p->p,currRing);
5941 if (p->t_p!=NULL)
5942 pSetCoeff0(p->t_p,pGetCoeff(p->p));
5943 lcp=pGetCoeff(p->p);
5944 }
5945 if(nGreater(lcset, lcp))
5946 {
5947 return en;
5948 }
5949 else
5950 {
5951 return an;
5952 }
5953 }
5954 }
5955 i=(an+en) / 2;
5956 if (set[i].FDeg > p->FDeg)
5957 an=i;
5958 if (set[i].FDeg < p->FDeg)
5959 en=i;
5960 if (set[i].FDeg == p->FDeg)
5961 {
5963 lcset = pGetCoeff(set[i].p);
5964 lcp = pGetCoeff(p->p);
5965 if(!nGreaterZero(lcset))
5966 {
5967 set[i].p=p_Neg(set[i].p,currRing);
5968 if (set[i].t_p!=NULL)
5969 pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
5970 lcset=pGetCoeff(set[i].p);
5971 }
5972 if(!nGreaterZero(lcp))
5973 {
5974 p->p=p_Neg(p->p,currRing);
5975 if (p->t_p!=NULL)
5976 pSetCoeff0(p->t_p,pGetCoeff(p->p));
5977 lcp=pGetCoeff(p->p);
5978 }
5979 if(nGreater(lcset, lcp))
5980 {
5981 an = i;
5982 }
5983 else
5984 {
5985 en = i;
5986 }
5987 }
5988 }
5989}
5990
5991/*2 Position for rings L: Here I am
5992* looks up the position of polynomial p in set
5993* e is the ecart of p
5994* set[length] is the smallest element in set with respect
5995* to the ordering-procedure totaldegree,pComp
5996*/
5997inline int getIndexRng(long coeff)
5998{
5999 if (coeff == 0) return -1;
6000 long tmp = coeff;
6001 int ind = 0;
6002 while (tmp % 2 == 0)
6003 {
6004 tmp = tmp / 2;
6005 ind++;
6006 }
6007 return ind;
6008}
6009
6010/*{
6011 if (length < 0) return 0;
6012
6013 int o = p->GetpFDeg();
6014 int op = set[length].GetpFDeg();
6015
6016 int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6017 int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6018 int inda;
6019 int indi;
6020
6021 if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6022 return length + 1;
6023 int i;
6024 int an = 0;
6025 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6026 int en = length;
6027 loop
6028 {
6029 if (an >= en-1)
6030 {
6031 op = set[an].GetpFDeg();
6032 if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6033 return en;
6034 return an;
6035 }
6036 i = (an + en) / 2;
6037 indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6038 op = set[i].GetpFDeg();
6039 if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6040 // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6041 {
6042 an = i;
6043 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6044 }
6045 else
6046 en = i;
6047 }
6048} */
6049
6050/*2
6051* looks up the position of polynomial p in set
6052* set[length] is the smallest element in set with respect
6053* to the ordering-procedure totaldegree,pLength0
6054*/
6055int posInL110 (const LSet set, const int length,
6056 LObject* p,const kStrategy)
6057{
6058 if (length<0) return 0;
6059
6060 int o = p->GetpFDeg();
6061 int op = set[length].GetpFDeg();
6062 int cmp_int= -currRing->OrdSgn;
6063
6064 if ((op > o)
6065 || ((op == o) && (set[length].length >p->length))
6066 || ((op == o) && (set[length].length <= p->length)
6067 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6068 return length+1;
6069 int i;
6070 int an = 0;
6071 int en= length;
6072 loop
6073 {
6074 if (an >= en-1)
6075 {
6076 op = set[an].GetpFDeg();
6077 if ((op > o)
6078 || ((op == o) && (set[an].length >p->length))
6079 || ((op == o) && (set[an].length <=p->length)
6080 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6081 return en;
6082 return an;
6083 }
6084 i=(an+en) / 2;
6085 op = set[i].GetpFDeg();
6086 if ((op > o)
6087 || ((op == o) && (set[i].length > p->length))
6088 || ((op == o) && (set[i].length <= p->length)
6089 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6090 an=i;
6091 else
6092 en=i;
6093 }
6094}
6095
6096int posInL110Ring (const LSet set, const int length,
6097 LObject* p,const kStrategy)
6098{
6099 if (length<0) return 0;
6100
6101 int o = p->GetpFDeg();
6102 int op = set[length].GetpFDeg();
6103
6104 if ((op > o)
6105 || ((op == o) && (set[length].length >p->length))
6106 || ((op == o) && (set[length].length <= p->length)
6107 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6108 return length+1;
6109 int i;
6110 int an = 0;
6111 int en= length;
6112 loop
6113 {
6114 if (an >= en-1)
6115 {
6116 op = set[an].GetpFDeg();
6117 if ((op > o)
6118 || ((op == o) && (set[an].length >p->length))
6119 || ((op == o) && (set[an].length <=p->length)
6120 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6121 return en;
6122 return an;
6123 }
6124 i=(an+en) / 2;
6125 op = set[i].GetpFDeg();
6126 if ((op > o)
6127 || ((op == o) && (set[i].length > p->length))
6128 || ((op == o) && (set[i].length <= p->length)
6129 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6130 an=i;
6131 else
6132 en=i;
6133 }
6134}
6135
6136/*2
6137* looks up the position of polynomial p in set
6138* e is the ecart of p
6139* set[length] is the smallest element in set with respect
6140* to the ordering-procedure totaldegree
6141*/
6142int posInL13 (const LSet set, const int length,
6143 LObject* p,const kStrategy)
6144{
6145 if (length<0) return 0;
6146
6147 int o = p->GetpFDeg();
6148
6149 if (set[length].GetpFDeg() > o)
6150 return length+1;
6151
6152 int i;
6153 int an = 0;
6154 int en= length;
6155 loop
6156 {
6157 if (an >= en-1)
6158 {
6159 if (set[an].GetpFDeg() >= o)
6160 return en;
6161 return an;
6162 }
6163 i=(an+en) / 2;
6164 if (set[i].GetpFDeg() >= o)
6165 an=i;
6166 else
6167 en=i;
6168 }
6169}
6170
6171/*2
6172* looks up the position of polynomial p in set
6173* e is the ecart of p
6174* set[length] is the smallest element in set with respect
6175* to the ordering-procedure maximaldegree,pComp
6176*/
6177int posInL15 (const LSet set, const int length,
6178 LObject* p,const kStrategy)
6179{
6180 if (length<0) return 0;
6181
6182 int o = p->GetpFDeg() + p->ecart;
6183 int op = set[length].GetpFDeg() + set[length].ecart;
6184 int cmp_int= -currRing->OrdSgn;
6185
6186 if ((op > o)
6187 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
6188 return length+1;
6189 int i;
6190 int an = 0;
6191 int en= length;
6192 loop
6193 {
6194 if (an >= en-1)
6195 {
6196 op = set[an].GetpFDeg() + set[an].ecart;
6197 if ((op > o)
6198 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
6199 return en;
6200 return an;
6201 }
6202 i=(an+en) / 2;
6203 op = set[i].GetpFDeg() + set[i].ecart;
6204 if ((op > o)
6205 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
6206 an=i;
6207 else
6208 en=i;
6209 }
6210}
6211
6212int posInL15Ring (const LSet set, const int length,
6213 LObject* p,const kStrategy)
6214{
6215 if (length<0) return 0;
6216
6217 int o = p->GetpFDeg() + p->ecart;
6218 int op = set[length].GetpFDeg() + set[length].ecart;
6219
6220 if ((op > o)
6221 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6222 return length+1;
6223 int i;
6224 int an = 0;
6225 int en= length;
6226 loop
6227 {
6228 if (an >= en-1)
6229 {
6230 op = set[an].GetpFDeg() + set[an].ecart;
6231 if ((op > o)
6232 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6233 return en;
6234 return an;
6235 }
6236 i=(an+en) / 2;
6237 op = set[i].GetpFDeg() + set[i].ecart;
6238 if ((op > o)
6239 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6240 an=i;
6241 else
6242 en=i;
6243 }
6244}
6245
6246/*2
6247* looks up the position of polynomial p in set
6248* e is the ecart of p
6249* set[length] is the smallest element in set with respect
6250* to the ordering-procedure totaldegree
6251*/
6252int posInL17 (const LSet set, const int length,
6253 LObject* p,const kStrategy)
6254{
6255 if (length<0) return 0;
6256
6257 int o = p->GetpFDeg() + p->ecart;
6258 int cmp_int= -currRing->OrdSgn;
6259
6260 if ((set[length].GetpFDeg() + set[length].ecart > o)
6261 || ((set[length].GetpFDeg() + set[length].ecart == o)
6262 && (set[length].ecart > p->ecart))
6263 || ((set[length].GetpFDeg() + set[length].ecart == o)
6264 && (set[length].ecart == p->ecart)
6265 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6266 return length+1;
6267 int i;
6268 int an = 0;
6269 int en= length;
6270 loop
6271 {
6272 if (an >= en-1)
6273 {
6274 if ((set[an].GetpFDeg() + set[an].ecart > o)
6275 || ((set[an].GetpFDeg() + set[an].ecart == o)
6276 && (set[an].ecart > p->ecart))
6277 || ((set[an].GetpFDeg() + set[an].ecart == o)
6278 && (set[an].ecart == p->ecart)
6279 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6280 return en;
6281 return an;
6282 }
6283 i=(an+en) / 2;
6284 if ((set[i].GetpFDeg() + set[i].ecart > o)
6285 || ((set[i].GetpFDeg() + set[i].ecart == o)
6286 && (set[i].ecart > p->ecart))
6287 || ((set[i].GetpFDeg() +set[i].ecart == o)
6288 && (set[i].ecart == p->ecart)
6289 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6290 an=i;
6291 else
6292 en=i;
6293 }
6294}
6295
6296int posInL17Ring (const LSet set, const int length,
6297 LObject* p,const kStrategy)
6298{
6299 if (length<0) return 0;
6300
6301 int o = p->GetpFDeg() + p->ecart;
6302
6303 if ((set[length].GetpFDeg() + set[length].ecart > o)
6304 || ((set[length].GetpFDeg() + set[length].ecart == o)
6305 && (set[length].ecart > p->ecart))
6306 || ((set[length].GetpFDeg() + set[length].ecart == o)
6307 && (set[length].ecart == p->ecart)
6308 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6309 return length+1;
6310 int i;
6311 int an = 0;
6312 int en= length;
6313 loop
6314 {
6315 if (an >= en-1)
6316 {
6317 if ((set[an].GetpFDeg() + set[an].ecart > o)
6318 || ((set[an].GetpFDeg() + set[an].ecart == o)
6319 && (set[an].ecart > p->ecart))
6320 || ((set[an].GetpFDeg() + set[an].ecart == o)
6321 && (set[an].ecart == p->ecart)
6322 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6323 return en;
6324 return an;
6325 }
6326 i=(an+en) / 2;
6327 if ((set[i].GetpFDeg() + set[i].ecart > o)
6328 || ((set[i].GetpFDeg() + set[i].ecart == o)
6329 && (set[i].ecart > p->ecart))
6330 || ((set[i].GetpFDeg() +set[i].ecart == o)
6331 && (set[i].ecart == p->ecart)
6332 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6333 an=i;
6334 else
6335 en=i;
6336 }
6337}
6338
6339/*2
6340* looks up the position of polynomial p in set
6341* e is the ecart of p
6342* set[length] is the smallest element in set with respect
6343* to the ordering-procedure pComp
6344*/
6345int posInL17_c (const LSet set, const int length,
6346 LObject* p,const kStrategy)
6347{
6348 if (length<0) return 0;
6349
6350 int cc = (-1+2*currRing->order[0]==ringorder_c);
6351 /* cc==1 for (c,..), cc==-1 for (C,..) */
6352 long c = pGetComp(p->p)*cc;
6353 int o = p->GetpFDeg() + p->ecart;
6354 int cmp_int= -currRing->OrdSgn;
6355
6356 if (pGetComp(set[length].p)*cc > c)
6357 return length+1;
6358 if (pGetComp(set[length].p)*cc == c)
6359 {
6360 if ((set[length].GetpFDeg() + set[length].ecart > o)
6361 || ((set[length].GetpFDeg() + set[length].ecart == o)
6362 && (set[length].ecart > p->ecart))
6363 || ((set[length].GetpFDeg() + set[length].ecart == o)
6364 && (set[length].ecart == p->ecart)
6365 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6366 return length+1;
6367 }
6368 int i;
6369 int an = 0;
6370 int en= length;
6371 loop
6372 {
6373 if (an >= en-1)
6374 {
6375 if (pGetComp(set[an].p)*cc > c)
6376 return en;
6377 if (pGetComp(set[an].p)*cc == c)
6378 {
6379 if ((set[an].GetpFDeg() + set[an].ecart > o)
6380 || ((set[an].GetpFDeg() + set[an].ecart == o)
6381 && (set[an].ecart > p->ecart))
6382 || ((set[an].GetpFDeg() + set[an].ecart == o)
6383 && (set[an].ecart == p->ecart)
6384 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6385 return en;
6386 }
6387 return an;
6388 }
6389 i=(an+en) / 2;
6390 if (pGetComp(set[i].p)*cc > c)
6391 an=i;
6392 else if (pGetComp(set[i].p)*cc == c)
6393 {
6394 if ((set[i].GetpFDeg() + set[i].ecart > o)
6395 || ((set[i].GetpFDeg() + set[i].ecart == o)
6396 && (set[i].ecart > p->ecart))
6397 || ((set[i].GetpFDeg() +set[i].ecart == o)
6398 && (set[i].ecart == p->ecart)
6399 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6400 an=i;
6401 else
6402 en=i;
6403 }
6404 else
6405 en=i;
6406 }
6407}
6408
6409int posInL17_cRing (const LSet set, const int length,
6410 LObject* p,const kStrategy)
6411{
6412 if (length<0) return 0;
6413
6414 int cc = (-1+2*currRing->order[0]==ringorder_c);
6415 /* cc==1 for (c,..), cc==-1 for (C,..) */
6416 long c = pGetComp(p->p)*cc;
6417 int o = p->GetpFDeg() + p->ecart;
6418
6419 if (pGetComp(set[length].p)*cc > c)
6420 return length+1;
6421 if (pGetComp(set[length].p)*cc == c)
6422 {
6423 if ((set[length].GetpFDeg() + set[length].ecart > o)
6424 || ((set[length].GetpFDeg() + set[length].ecart == o)
6425 && (set[length].ecart > p->ecart))
6426 || ((set[length].GetpFDeg() + set[length].ecart == o)
6427 && (set[length].ecart == p->ecart)
6428 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6429 return length+1;
6430 }
6431 int i;
6432 int an = 0;
6433 int en= length;
6434 loop
6435 {
6436 if (an >= en-1)
6437 {
6438 if (pGetComp(set[an].p)*cc > c)
6439 return en;
6440 if (pGetComp(set[an].p)*cc == c)
6441 {
6442 if ((set[an].GetpFDeg() + set[an].ecart > o)
6443 || ((set[an].GetpFDeg() + set[an].ecart == o)
6444 && (set[an].ecart > p->ecart))
6445 || ((set[an].GetpFDeg() + set[an].ecart == o)
6446 && (set[an].ecart == p->ecart)
6447 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6448 return en;
6449 }
6450 return an;
6451 }
6452 i=(an+en) / 2;
6453 if (pGetComp(set[i].p)*cc > c)
6454 an=i;
6455 else if (pGetComp(set[i].p)*cc == c)
6456 {
6457 if ((set[i].GetpFDeg() + set[i].ecart > o)
6458 || ((set[i].GetpFDeg() + set[i].ecart == o)
6459 && (set[i].ecart > p->ecart))
6460 || ((set[i].GetpFDeg() +set[i].ecart == o)
6461 && (set[i].ecart == p->ecart)
6462 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6463 an=i;
6464 else
6465 en=i;
6466 }
6467 else
6468 en=i;
6469 }
6470}
6471
6472/*
6473 * SYZYGY CRITERION for signature-based standard basis algorithms
6474 */
6475BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6476{
6477//#if 1
6478#ifdef DEBUGF5
6479 PrintS("syzygy criterion checks: ");
6480 pWrite(sig);
6481#endif
6482 for (int k=0; k<strat->syzl; k++)
6483 {
6484 //printf("-%d",k);
6485//#if 1
6486#ifdef DEBUGF5
6487 Print("checking with: %d / %d -- \n",k,strat->syzl);
6488 pWrite(pHead(strat->syz[k]));
6489#endif
6490 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6491 && (!rField_is_Ring(currRing) ||
6492 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6493 {
6494//#if 1
6495#ifdef DEBUGF5
6496 PrintS("DELETE!\n");
6497#endif
6498 strat->nrsyzcrit++;
6499 //printf("- T -\n\n");
6500 return TRUE;
6501 }
6502 }
6503 //printf("- F -\n\n");
6504 return FALSE;
6505}
6506
6507/*
6508 * SYZYGY CRITERION for signature-based standard basis algorithms
6509 */
6510BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6511{
6512//#if 1
6513 if(sig == NULL)
6514 return FALSE;
6515#ifdef DEBUGF5
6516 PrintS("--- syzygy criterion checks: ");
6517 pWrite(sig);
6518#endif
6519 int comp = (int)__p_GetComp(sig, currRing);
6520 int min, max;
6521 if (comp<=1)
6522 return FALSE;
6523 else
6524 {
6525 min = strat->syzIdx[comp-2];
6526 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
6527 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
6528 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
6529 if (comp == strat->currIdx)
6530 {
6531 max = strat->syzl;
6532 }
6533 else
6534 {
6535 max = strat->syzIdx[comp-1];
6536 }
6537 for (int k=min; k<max; k++)
6538 {
6539#ifdef F5DEBUG
6540 Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
6541 Print("checking with: %d -- ",k);
6542 pWrite(pHead(strat->syz[k]));
6543#endif
6544 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6545 && (!rField_is_Ring(currRing) ||
6546 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6547 {
6548 strat->nrsyzcrit++;
6549 return TRUE;
6550 }
6551 }
6552 return FALSE;
6553 }
6554}
6555
6556/*
6557 * REWRITTEN CRITERION for signature-based standard basis algorithms
6558 */
6559BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
6560{
6561 //printf("Faugere Rewritten Criterion\n");
6563 return FALSE;
6564//#if 1
6565#ifdef DEBUGF5
6566 PrintS("rewritten criterion checks: ");
6567 pWrite(sig);
6568#endif
6569 for(int k = strat->sl; k>=start; k--)
6570 {
6571//#if 1
6572#ifdef DEBUGF5
6573 PrintS("checking with: ");
6574 pWrite(strat->sig[k]);
6575 pWrite(pHead(strat->S[k]));
6576#endif
6577 if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
6578 {
6579//#if 1
6580#ifdef DEBUGF5
6581 PrintS("DELETE!\n");
6582#endif
6583 strat->nrrewcrit++;
6584 return TRUE;
6585 }
6586 //k--;
6587 }
6588#ifdef DEBUGF5
6589 PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
6590 for(int kk = 0; kk<strat->sl+1; kk++)
6591 {
6592 pWrite(pHead(strat->S[kk]));
6593 }
6594 PrintS("------------------------------\n");
6595#endif
6596 return FALSE;
6597}
6598
6599/*
6600 * REWRITTEN CRITERION for signature-based standard basis algorithms
6601 ***************************************************************************
6602 * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
6603 ***************************************************************************
6604 */
6605
6606// real implementation of arri's rewritten criterion, only called once in
6607// kstd2.cc, right before starting reduction
6608// IDEA: Arri says that it is enough to consider 1 polynomial for each unique
6609// signature appearing during the computations. Thus we first of all go
6610// through strat->L and delete all other pairs of the same signature,
6611// keeping only the one with least possible leading monomial. After this
6612// we check if we really need to compute this critical pair at all: There
6613// can be elements already in strat->S whose signatures divide the
6614// signature of the critical pair in question and whose multiplied
6615// leading monomials are smaller than the leading monomial of the
6616// critical pair. In this situation we can discard the critical pair
6617// completely.
6618BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
6619{
6621 return FALSE;
6622 poly p1 = pOne();
6623 poly p2 = pOne();
6624 for (int ii=strat->sl; ii>start; ii--)
6625 {
6626 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
6627 {
6628 p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
6629 p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
6630 if (!(pLmCmp(p1,p2) == 1))
6631 {
6632 pDelete(&p1);
6633 pDelete(&p2);
6634 return TRUE;
6635 }
6636 }
6637 }
6638 pDelete(&p1);
6639 pDelete(&p2);
6640 return FALSE;
6641}
6642
6643BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
6644{
6645 //Over Rings, there are still some changes to do: considering coeffs
6647 return FALSE;
6648 int found = -1;
6649 for (int i=strat->Bl; i>-1; i--)
6650 {
6651 if (pLmEqual(strat->B[i].sig,sig))
6652 {
6653 found = i;
6654 break;
6655 }
6656 }
6657 if (found != -1)
6658 {
6659 if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
6660 {
6661 deleteInL(strat->B,&strat->Bl,found,strat);
6662 }
6663 else
6664 {
6665 return TRUE;
6666 }
6667 }
6668 poly p1 = pOne();
6669 poly p2 = pOne();
6670 for (int ii=strat->sl; ii>-1; ii--)
6671 {
6672 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
6673 {
6674 p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
6675 p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
6676 if (!(pLmCmp(p1,p2) == 1))
6677 {
6678 pDelete(&p1);
6679 pDelete(&p2);
6680 return TRUE;
6681 }
6682 }
6683 }
6684 pDelete(&p1);
6685 pDelete(&p2);
6686 return FALSE;
6687}
6688
6689/***************************************************************
6690 *
6691 * Tail reductions
6692 *
6693 ***************************************************************/
6695{
6696 int j = 0;
6697 const unsigned long not_sev = ~L->sev;
6698 const unsigned long* sev = strat->sevS;
6699 poly p;
6700 ring r;
6701 L->GetLm(p, r);
6702
6704
6705 if (r == currRing)
6706 {
6707 if(!rField_is_Ring(r))
6708 {
6709 loop
6710 {
6711 if (j > end_pos) return NULL;
6712 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6713 if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
6714 (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6715 #else
6716 if (!(sev[j] & not_sev) &&
6717 (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
6718 p_LmDivisibleBy(strat->S[j], p, r))
6719 #endif
6720 {
6721 break;
6722 }
6723 j++;
6724 }
6725 }
6726 else
6727 {
6728 loop
6729 {
6730 if (j > end_pos) return NULL;
6731 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6732 if (strat->S[j]!= NULL
6733 && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r)
6734 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6735 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6736 #else
6737 if (!(sev[j] & not_sev)
6738 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6739 && p_LmDivisibleBy(strat->S[j], p, r)
6740 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6741 #endif
6742 {
6743 break; // found
6744 }
6745 j++;
6746 }
6747 }
6748 // if called from NF, T objects do not exist:
6749 if (strat->tl < 0 || strat->S_2_R[j] == -1)
6750 {
6751 T->Set(strat->S[j], r, strat->tailRing);
6752 assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
6753 return T;
6754 }
6755 else
6756 {
6757///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
6758///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
6759// assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
6760 return strat->S_2_T(j);
6761 }
6762 }
6763 else
6764 {
6765 TObject* t;
6766 if(!rField_is_Ring(r))
6767 {
6768 loop
6769 {
6770 if (j > end_pos) return NULL;
6771 assume(strat->S_2_R[j] != -1);
6772 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6773 t = strat->S_2_T(j);
6774 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6775 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6776 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6777 {
6778 t->pLength=pLength(t->t_p);
6779 return t;
6780 }
6781 #else
6782 if (! (sev[j] & not_sev)
6783 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6784 {
6785 t = strat->S_2_T(j);
6786 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6787 if (p_LmDivisibleBy(t->t_p, p, r))
6788 {
6789 t->pLength=pLength(t->t_p);
6790 return t;
6791 }
6792 }
6793 #endif
6794 j++;
6795 }
6796 }
6797 else
6798 {
6799 loop
6800 {
6801 if (j > end_pos) return NULL;
6802 assume(strat->S_2_R[j] != -1);
6803 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6804 t = strat->S_2_T(j);
6805 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6806 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6807 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6808 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6809 {
6810 t->pLength=pLength(t->t_p);
6811 return t;
6812 }
6813 #else
6814 if (! (sev[j] & not_sev)
6815 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6816 {
6817 t = strat->S_2_T(j);
6818 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6819 if (p_LmDivisibleBy(t->t_p, p, r)
6820 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6821 {
6822 t->pLength=pLength(t->t_p);
6823 return t;
6824 }
6825 }
6826 #endif
6827 j++;
6828 }
6829 }
6830 }
6831}
6832
6833poly redtail (LObject* L, int end_pos, kStrategy strat)
6834{
6835 poly h, hn;
6836 strat->redTailChange=FALSE;
6837
6838 L->GetP();
6839 poly p = L->p;
6840 if (strat->noTailReduction || pNext(p) == NULL)
6841 return p;
6842
6843 LObject Ln(strat->tailRing);
6844 TObject* With;
6845 // placeholder in case strat->tl < 0
6846 TObject With_s(strat->tailRing);
6847 h = p;
6848 hn = pNext(h);
6849 long op = strat->tailRing->pFDeg(hn, strat->tailRing);
6850 long e;
6851 int l;
6852 BOOLEAN save_HE=strat->kAllAxis;
6853 strat->kAllAxis |=
6854 ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
6855
6856 while(hn != NULL)
6857 {
6858 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6859 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6860 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6861 loop
6862 {
6863 Ln.Set(hn, strat->tailRing);
6864 Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
6865 if (strat->kAllAxis)
6867 else
6868 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
6869 if (With == NULL) break;
6870 With->length=0;
6871 With->pLength=0;
6872 strat->redTailChange=TRUE;
6873 if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
6874 {
6875 // reducing the tail would violate the exp bound
6876 if (kStratChangeTailRing(strat, L))
6877 {
6878 strat->kAllAxis = save_HE;
6879 return redtail(L, end_pos, strat);
6880 }
6881 else
6882 return NULL;
6883 }
6884 hn = pNext(h);
6885 if (hn == NULL) goto all_done;
6886 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6887 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6888 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6889 }
6890 h = hn;
6891 hn = pNext(h);
6892 }
6893
6894 all_done:
6895 if (strat->redTailChange)
6896 {
6897 L->pLength = 0;
6898 }
6899 strat->kAllAxis = save_HE;
6900 return p;
6901}
6902
6903poly redtail (poly p, int end_pos, kStrategy strat)
6904{
6905 LObject L(p, currRing);
6906 return redtail(&L, end_pos, strat);
6907}
6908
6910{
6911 strat->redTailChange=FALSE;
6912 if (strat->noTailReduction) return L->GetLmCurrRing();
6913 poly h, p;
6914 p = h = L->GetLmTailRing();
6915 if ((h==NULL) || (pNext(h)==NULL))
6916 return L->GetLmCurrRing();
6917
6918 TObject* With;
6919 // placeholder in case strat->tl < 0
6920 TObject With_s(strat->tailRing);
6921
6922 LObject Ln(pNext(h), strat->tailRing);
6923 Ln.GetpLength();
6924
6925 pNext(h) = NULL;
6926 if (L->p != NULL)
6927 {
6928 pNext(L->p) = NULL;
6929 if (L->t_p != NULL) pNext(L->t_p) = NULL;
6930 }
6931 L->pLength = 1;
6932
6933 Ln.PrepareRed(strat->use_buckets);
6934
6935 int cnt=REDTAIL_CANONICALIZE;
6936 while(!Ln.IsNull())
6937 {
6938 loop
6939 {
6940 if (TEST_OPT_IDLIFT)
6941 {
6942 if (Ln.p!=NULL)
6943 {
6944 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
6945 }
6946 else
6947 {
6948 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
6949 }
6950 }
6951 Ln.SetShortExpVector();
6952 if (withT)
6953 {
6954 int j;
6955 j = kFindDivisibleByInT(strat, &Ln);
6956 if (j < 0) break;
6957 With = &(strat->T[j]);
6958 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
6959 }
6960 else
6961 {
6963 if (With == NULL) break;
6964 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
6965 }
6966 cnt--;
6967 if (cnt==0)
6968 {
6970 /*poly tmp=*/Ln.CanonicalizeP();
6971 if (normalize)
6972 {
6973 Ln.Normalize();
6974 //pNormalize(tmp);
6975 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
6976 }
6977 }
6978 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
6979 {
6980 With->pNorm();
6981 }
6982 strat->redTailChange=TRUE;
6983 if (ksReducePolyTail(L, With, &Ln))
6984 {
6985 // reducing the tail would violate the exp bound
6986 // set a flag and hope for a retry (in bba)
6988 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
6989 do
6990 {
6991 pNext(h) = Ln.LmExtractAndIter();
6992 pIter(h);
6993 L->pLength++;
6994 } while (!Ln.IsNull());
6995 goto all_done;
6996 }
6997 if (Ln.IsNull()) goto all_done;
6998 if (! withT) With_s.Init(currRing);
6999 }
7000 pNext(h) = Ln.LmExtractAndIter();
7001 pIter(h);
7002 pNormalize(h);
7003 L->pLength++;
7004 }
7005
7006 all_done:
7007 Ln.Delete();
7008 if (L->p != NULL) pNext(L->p) = pNext(p);
7009
7010 if (strat->redTailChange)
7011 {
7012 L->length = 0;
7013 L->pLength = 0;
7014 }
7015
7016 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7017 //L->Normalize(); // HANNES: should have a test
7018 kTest_L(L,strat);
7019 return L->GetLmCurrRing();
7020}
7021
7023{
7024 strat->redTailChange=FALSE;
7025 if (strat->noTailReduction) return L->GetLmCurrRing();
7026 poly h, p;
7027 p = h = L->GetLmTailRing();
7028 if ((h==NULL) || (pNext(h)==NULL))
7029 return L->GetLmCurrRing();
7030
7031 TObject* With;
7032 // placeholder in case strat->tl < 0
7033 TObject With_s(strat->tailRing);
7034
7035 LObject Ln(pNext(h), strat->tailRing);
7036 Ln.pLength = L->GetpLength() - 1;
7037
7038 pNext(h) = NULL;
7039 if (L->p != NULL) pNext(L->p) = NULL;
7040 L->pLength = 1;
7041
7042 Ln.PrepareRed(strat->use_buckets);
7043
7044 int cnt=REDTAIL_CANONICALIZE;
7045 while(!Ln.IsNull())
7046 {
7047 loop
7048 {
7049 if (TEST_OPT_IDLIFT)
7050 {
7051 if (Ln.p!=NULL)
7052 {
7053 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7054 }
7055 else
7056 {
7057 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7058 }
7059 }
7060 Ln.SetShortExpVector();
7061 if (withT)
7062 {
7063 int j;
7064 j = kFindDivisibleByInT(strat, &Ln);
7065 if (j < 0) break;
7066 With = &(strat->T[j]);
7067 }
7068 else
7069 {
7071 if (With == NULL) break;
7072 }
7073 cnt--;
7074 if (cnt==0)
7075 {
7077 /*poly tmp=*/Ln.CanonicalizeP();
7078 if (normalize)
7079 {
7080 Ln.Normalize();
7081 //pNormalize(tmp);
7082 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7083 }
7084 }
7085 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7086 {
7087 With->pNorm();
7088 }
7089 strat->redTailChange=TRUE;
7090 if (ksReducePolyTail(L, With, &Ln))
7091 {
7092 // reducing the tail would violate the exp bound
7093 // set a flag and hope for a retry (in bba)
7095 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7096 do
7097 {
7098 pNext(h) = Ln.LmExtractAndIter();
7099 pIter(h);
7100 L->pLength++;
7101 } while (!Ln.IsNull());
7102 goto all_done;
7103 }
7104 if(!Ln.IsNull())
7105 {
7106 Ln.GetP();
7107 Ln.p = pJet(Ln.p,bound);
7108 }
7109 if (Ln.IsNull())
7110 {
7111 goto all_done;
7112 }
7113 if (! withT) With_s.Init(currRing);
7114 }
7115 pNext(h) = Ln.LmExtractAndIter();
7116 pIter(h);
7117 pNormalize(h);
7118 L->pLength++;
7119 }
7120
7121 all_done:
7122 Ln.Delete();
7123 if (L->p != NULL) pNext(L->p) = pNext(p);
7124
7125 if (strat->redTailChange)
7126 {
7127 L->length = 0;
7128 L->pLength = 0;
7129 }
7130
7131 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7132 //L->Normalize(); // HANNES: should have a test
7133 kTest_L(L,strat);
7134 return L->GetLmCurrRing();
7135}
7136
7138// normalize=FALSE, withT=FALSE, coeff=Z
7139{
7140 strat->redTailChange=FALSE;
7141
7142 poly h, p;
7143 p = h = L->GetLmTailRing();
7144 if ((h==NULL) || (pNext(h)==NULL))
7145 return;
7146
7147 TObject* With;
7148 LObject Ln(pNext(h), strat->tailRing);
7149 Ln.GetpLength();
7150
7151 pNext(h) = NULL;
7152 if (L->p != NULL)
7153 {
7154 pNext(L->p) = NULL;
7155 if (L->t_p != NULL) pNext(L->t_p) = NULL;
7156 }
7157 L->pLength = 1;
7158
7159 Ln.PrepareRed(strat->use_buckets);
7160
7161 int cnt=REDTAIL_CANONICALIZE;
7162
7163 while(!Ln.IsNull())
7164 {
7165 loop
7166 {
7167 if (TEST_OPT_IDLIFT)
7168 {
7169 if (Ln.p!=NULL)
7170 {
7171 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7172 }
7173 else
7174 {
7175 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7176 }
7177 }
7178 Ln.SetShortExpVector();
7179 int j;
7180 j = kFindDivisibleByInT(strat, &Ln);
7181 if (j < 0)
7182 {
7183 j = kFindDivisibleByInT_Z(strat, &Ln);
7184 if (j < 0)
7185 {
7186 break;
7187 }
7188 else
7189 {
7190 /* reduction not cancelling a tail term, but reducing its coefficient */
7191 With = &(strat->T[j]);
7192 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7193 cnt--;
7194 if (cnt==0)
7195 {
7197 /*poly tmp=*/Ln.CanonicalizeP();
7198 }
7199 strat->redTailChange=TRUE;
7200 /* reduction cancelling a tail term */
7201 if (ksReducePolyTailLC_Z(L, With, &Ln))
7202 {
7203 // reducing the tail would violate the exp bound
7204 // set a flag and hope for a retry (in bba)
7206 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7207 do
7208 {
7209 pNext(h) = Ln.LmExtractAndIter();
7210 pIter(h);
7211 L->pLength++;
7212 } while (!Ln.IsNull());
7213 goto all_done;
7214 }
7215 /* we have to break since we did not cancel the term, but only decreased
7216 * its coefficient. */
7217 break;
7218 }
7219 } else {
7220 With = &(strat->T[j]);
7221 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7222 cnt--;
7223 if (cnt==0)
7224 {
7226 /*poly tmp=*/Ln.CanonicalizeP();
7227 }
7228 strat->redTailChange=TRUE;
7229 /* reduction cancelling a tail term */
7230 if (ksReducePolyTail_Z(L, With, &Ln))
7231 {
7232 // reducing the tail would violate the exp bound
7233 // set a flag and hope for a retry (in bba)
7235 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7236 do
7237 {
7238 pNext(h) = Ln.LmExtractAndIter();
7239 pIter(h);
7240 L->pLength++;
7241 } while (!Ln.IsNull());
7242 goto all_done;
7243 }
7244 }
7245 if (Ln.IsNull()) goto all_done;
7246 }
7247 pNext(h) = Ln.LmExtractAndIter();
7248 pIter(h);
7249 L->pLength++;
7250 }
7251
7252 all_done:
7253 Ln.Delete();
7254 if (L->p != NULL) pNext(L->p) = pNext(p);
7255
7256 if (strat->redTailChange)
7257 {
7258 L->length = 0;
7259 L->pLength = 0;
7260 }
7261
7262 kTest_L(L, strat);
7263 return;
7264}
7265
7267// normalize=FALSE, withT=FALSE, coeff=Z
7268{
7269 strat->redTailChange=FALSE;
7270 if (strat->noTailReduction) return L->GetLmCurrRing();
7271 poly h, p;
7272 p = h = L->GetLmTailRing();
7273 if ((h==NULL) || (pNext(h)==NULL))
7274 return L->GetLmCurrRing();
7275
7276 TObject* With;
7277 // placeholder in case strat->tl < 0
7278 TObject With_s(strat->tailRing);
7279
7280 LObject Ln(pNext(h), strat->tailRing);
7281 Ln.pLength = L->GetpLength() - 1;
7282
7283 pNext(h) = NULL;
7284 if (L->p != NULL) pNext(L->p) = NULL;
7285 L->pLength = 1;
7286
7287 Ln.PrepareRed(strat->use_buckets);
7288
7289 int cnt=REDTAIL_CANONICALIZE;
7290 while(!Ln.IsNull())
7291 {
7292 loop
7293 {
7294 Ln.SetShortExpVector();
7296 if (With == NULL) break;
7297 cnt--;
7298 if (cnt==0)
7299 {
7301 /*poly tmp=*/Ln.CanonicalizeP();
7302 }
7303 // we are in Z, do not call pNorm
7304 strat->redTailChange=TRUE;
7305 // test divisibility of coefs:
7306 Ln.GetLmCurrRing();
7307 With->GetLmCurrRing();
7308
7309 if (ksReducePolyTail_Z(L, With, &Ln))
7310 {
7311 // reducing the tail would violate the exp bound
7312 // set a flag and hope for a retry (in bba)
7314 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7315 do
7316 {
7317 pNext(h) = Ln.LmExtractAndIter();
7318 pIter(h);
7319 L->pLength++;
7320 } while (!Ln.IsNull());
7321 goto all_done;
7322 }
7323 if (Ln.IsNull()) goto all_done;
7324 With_s.Init(currRing);
7325 }
7326 pNext(h) = Ln.LmExtractAndIter();
7327 pIter(h);
7328 pNormalize(h);
7329 L->pLength++;
7330 }
7331
7332 all_done:
7333 Ln.Delete();
7334 if (L->p != NULL) pNext(L->p) = pNext(p);
7335
7336 if (strat->redTailChange)
7337 {
7338 L->length = 0;
7339 }
7340
7341 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7342 //L->Normalize(); // HANNES: should have a test
7343 kTest_L(L,strat);
7344 return L->GetLmCurrRing();
7345}
7346
7347poly redtailBba_NF (poly p, kStrategy strat )
7348{
7349 strat->redTailChange=FALSE;
7350 if (strat->noTailReduction) return p;
7351 if ((p==NULL) || (pNext(p)==NULL))
7352 return p;
7353
7354 int max_ind;
7355 poly h=p;
7356 p=pNext(p);
7357 pNext(h)=NULL;
7358 while(p!=NULL)
7359 {
7360 p=redNF(p,max_ind,1,strat);
7361 if (p!=NULL)
7362 {
7363 poly hh=p;
7364 p=pNext(p);
7365 pNext(hh)=NULL;
7367 }
7368 }
7369 return h;
7370}
7371
7373// normalize=FALSE, withT=FALSE, coeff=Ring
7374{
7375 strat->redTailChange=FALSE;
7376 if (strat->noTailReduction) return L->GetLmCurrRing();
7377 poly h, p;
7378 p = h = L->GetLmTailRing();
7379 if ((h==NULL) || (pNext(h)==NULL))
7380 return L->GetLmCurrRing();
7381
7382 TObject* With;
7383 // placeholder in case strat->tl < 0
7384 TObject With_s(strat->tailRing);
7385
7386 LObject Ln(pNext(h), strat->tailRing);
7387 Ln.pLength = L->GetpLength() - 1;
7388
7389 pNext(h) = NULL;
7390 if (L->p != NULL) pNext(L->p) = NULL;
7391 L->pLength = 1;
7392
7393 Ln.PrepareRed(strat->use_buckets);
7394
7395 int cnt=REDTAIL_CANONICALIZE;
7396 while(!Ln.IsNull())
7397 {
7398 loop
7399 {
7400 Ln.SetShortExpVector();
7401 With_s.Init(currRing);
7403 if (With == NULL) break;
7404 cnt--;
7405 if (cnt==0)
7406 {
7408 /*poly tmp=*/Ln.CanonicalizeP();
7409 }
7410 // we are in a ring, do not call pNorm
7411 // test divisibility of coefs:
7412 poly p_Ln=Ln.GetLmCurrRing();
7413 poly p_With=With->GetLmCurrRing();
7415 {
7416 strat->redTailChange=TRUE;
7417
7418 if (ksReducePolyTail_Z(L, With, &Ln))
7419 {
7420 // reducing the tail would violate the exp bound
7421 // set a flag and hope for a retry (in bba)
7423 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7424 do
7425 {
7426 pNext(h) = Ln.LmExtractAndIter();
7427 pIter(h);
7428 L->pLength++;
7429 } while (!Ln.IsNull());
7430 goto all_done;
7431 }
7432 }
7433 else break; /*proceed to next monomial*/
7434 if (Ln.IsNull()) goto all_done;
7435 }
7436 pNext(h) = Ln.LmExtractAndIter();
7437 pIter(h);
7438 pNormalize(h);
7439 L->pLength++;
7440 }
7441
7442 all_done:
7443 Ln.Delete();
7444 if (L->p != NULL) pNext(L->p) = pNext(p);
7445
7446 if (strat->redTailChange)
7447 {
7448 L->length = 0;
7449 }
7450
7451 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7452 //L->Normalize(); // HANNES: should have a test
7453 kTest_L(L,strat);
7454 return L->GetLmCurrRing();
7455}
7456
7457/*2
7458*checks the change degree and write progress report
7459*/
7460void message (int i,int* olddeg,int* reduc,kStrategy strat, int red_result)
7461{
7462 if (i != *olddeg)
7463 {
7464 Print("%d",i);
7465 *olddeg = i;
7466 }
7467 if (TEST_OPT_OLDSTD)
7468 {
7469 if (strat->Ll != *reduc)
7470 {
7471 if (strat->Ll != *reduc-1)
7472 Print("(%d)",strat->Ll+1);
7473 else
7474 PrintS("-");
7475 *reduc = strat->Ll;
7476 }
7477 else
7478 PrintS(".");
7479 mflush();
7480 }
7481 else
7482 {
7483 if (red_result == 0)
7484 PrintS("-");
7485 else if (red_result < 0)
7486 PrintS(".");
7487 if ((red_result > 0) || ((strat->Ll % 100)==99))
7488 {
7489 if (strat->Ll != *reduc && strat->Ll > 0)
7490 {
7491 Print("(%d)",strat->Ll+1);
7492 *reduc = strat->Ll;
7493 }
7494 }
7495 }
7496}
7497
7498/*2
7499*statistics
7500*/
7502{
7503 //PrintS("\nUsage/Allocation of temporary storage:\n");
7504 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7505 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7506 Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7507 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7508 #ifdef HAVE_SHIFTBBA
7509 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7510 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7511 #endif
7512}
7513
7515{
7516 //PrintS("\nUsage/Allocation of temporary storage:\n");
7517 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7518 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7519 Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7520 //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7521 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7522 #ifdef HAVE_SHIFTBBA
7523 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7524 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7525 #endif
7526}
7527
7528#ifdef KDEBUG
7529/*2
7530*debugging output: all internal sets, if changed
7531*for testing purpose only/has to be changed for later use
7532*/
7534{
7535 int i;
7536 if (strat->news)
7537 {
7538 PrintS("set S");
7539 for (i=0; i<=strat->sl; i++)
7540 {
7541 Print("\n %d:",i);
7542 p_wrp(strat->S[i], currRing, strat->tailRing);
7543 if (strat->fromQ!=NULL && strat->fromQ[i])
7544 Print(" (from Q)");
7545 }
7546 strat->news = FALSE;
7547 }
7548 if (strat->newt)
7549 {
7550 PrintS("\nset T");
7551 for (i=0; i<=strat->tl; i++)
7552 {
7553 Print("\n %d:",i);
7554 strat->T[i].wrp();
7555 if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7556 Print(" o:%ld e:%d l:%d",
7557 strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7558 }
7559 strat->newt = FALSE;
7560 }
7561 PrintS("\nset L");
7562 for (i=strat->Ll; i>=0; i--)
7563 {
7564 Print("\n%d:",i);
7565 p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7566 PrintS(" ");
7567 p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7568 PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7569 PrintS("\n p : ");
7570 strat->L[i].wrp();
7571 Print(" o:%ld e:%d l:%d",
7572 strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7573 }
7574 PrintLn();
7575}
7576
7577#endif
7578
7579
7580/*2
7581*construct the set s from F
7582*/
7583void initS (ideal F, ideal Q, kStrategy strat)
7584{
7585 int i,pos;
7586
7588 else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7589 if (i<setmaxTinc) i=setmaxT;
7590 strat->ecartS=initec(i);
7591 strat->sevS=initsevS(i);
7592 strat->S_2_R=initS_2_R(i);
7593 strat->fromQ=NULL;
7594 strat->Shdl=idInit(i,F->rank);
7595 strat->S=strat->Shdl->m;
7596 /*- put polys into S -*/
7597 if (Q!=NULL)
7598 {
7599 strat->fromQ=initec(i);
7600 memset(strat->fromQ,0,i*sizeof(int));
7601 for (i=0; i<IDELEMS(Q); i++)
7602 {
7603 if (Q->m[i]!=NULL)
7604 {
7605 LObject h;
7606 h.p = pCopy(Q->m[i]);
7608 {
7609 h.pCleardenom(); // also does remove Content
7610 }
7611 else
7612 {
7613 h.pNorm();
7614 }
7616 {
7617 deleteHC(&h, strat);
7618 }
7619 if (h.p!=NULL)
7620 {
7621 strat->initEcart(&h);
7622 if (strat->sl==-1)
7623 pos =0;
7624 else
7625 {
7626 pos = posInS(strat,strat->sl,h.p,h.ecart);
7627 }
7628 h.sev = pGetShortExpVector(h.p);
7629 strat->enterS(h,pos,strat,-1);
7630 strat->fromQ[pos]=1;
7631 }
7632 }
7633 }
7634 }
7635 for (i=0; i<IDELEMS(F); i++)
7636 {
7637 if (F->m[i]!=NULL)
7638 {
7639 LObject h;
7640 h.p = pCopy(F->m[i]);
7642 {
7643 cancelunit(&h); /*- tries to cancel a unit -*/
7644 deleteHC(&h, strat);
7645 }
7646 if (h.p!=NULL)
7647 // do not rely on the input being a SB!
7648 {
7650 {
7651 h.pCleardenom(); // also does remove Content
7652 }
7653 else
7654 {
7655 h.pNorm();
7656 }
7657 strat->initEcart(&h);
7658 if (strat->sl==-1)
7659 pos =0;
7660 else
7661 pos = posInS(strat,strat->sl,h.p,h.ecart);
7662 h.sev = pGetShortExpVector(h.p);
7663 strat->enterS(h,pos,strat,-1);
7664 }
7665 }
7666 }
7667 /*- test, if a unit is in F -*/
7668 if ((strat->sl>=0)
7669 && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7670 && pIsConstant(strat->S[0]))
7671 {
7672 while (strat->sl>0) deleteInS(strat->sl,strat);
7673 }
7674}
7675
7677{
7678 int i,pos;
7679
7680 if (Q!=NULL)
7681 {
7683 if (i<setmaxTinc) i=setmaxT;
7684 }
7685 else i=setmaxT;
7686 strat->ecartS=initec(i);
7687 strat->sevS=initsevS(i);
7688 strat->S_2_R=initS_2_R(i);
7689 strat->fromQ=NULL;
7690 strat->Shdl=idInit(i,F->rank);
7691 strat->S=strat->Shdl->m;
7692 /*- put polys into S -*/
7693 if (Q!=NULL)
7694 {
7695 strat->fromQ=initec(i);
7696 memset(strat->fromQ,0,i*sizeof(int));
7697 for (i=0; i<IDELEMS(Q); i++)
7698 {
7699 if (Q->m[i]!=NULL)
7700 {
7701 LObject h;
7702 h.p = pCopy(Q->m[i]);
7704 {
7705 deleteHC(&h,strat);
7706 cancelunit(&h); /*- tries to cancel a unit -*/
7707 }
7709 {
7710 h.pCleardenom(); // also does remove Content
7711 }
7712 else
7713 {
7714 h.pNorm();
7715 }
7716 if (h.p!=NULL)
7717 {
7718 strat->initEcart(&h);
7719 if (strat->sl==-1)
7720 pos =0;
7721 else
7722 {
7723 pos = posInS(strat,strat->sl,h.p,h.ecart);
7724 }
7725 h.sev = pGetShortExpVector(h.p);
7726 strat->enterS(h,pos,strat,-1);
7727 strat->fromQ[pos]=1;
7728 }
7729 }
7730 }
7731 }
7732 for (i=0; i<IDELEMS(F); i++)
7733 {
7734 if (F->m[i]!=NULL)
7735 {
7736 LObject h;
7737 h.p = pCopy(F->m[i]);
7738 if (h.p!=NULL)
7739 {
7741 {
7742 cancelunit(&h); /*- tries to cancel a unit -*/
7743 deleteHC(&h, strat);
7744 }
7745 if (h.p!=NULL)
7746 {
7748 {
7749 h.pCleardenom(); // also does remove Content
7750 }
7751 else
7752 {
7753 h.pNorm();
7754 }
7755 strat->initEcart(&h);
7756 if (strat->Ll==-1)
7757 pos =0;
7758 else
7759 pos = strat->posInL(strat->L,strat->Ll,&h,strat);
7760 h.sev = pGetShortExpVector(h.p);
7761 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7762 }
7763 }
7764 }
7765 }
7766 /*- test, if a unit is in F -*/
7767
7768 if ((strat->Ll>=0)
7769 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7770 && pIsConstant(strat->L[strat->Ll].p))
7771 {
7772 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7773 }
7774}
7775
7777{
7778 int i,pos;
7779 if (Q!=NULL)
7780 {
7782 if (i<setmaxTinc) i=setmaxT;
7783 }
7784 else i=setmaxT;
7785 strat->ecartS = initec(i);
7786 strat->sevS = initsevS(i);
7787 strat->sevSig = initsevS(i);
7788 strat->S_2_R = initS_2_R(i);
7789 strat->fromQ = NULL;
7790 strat->Shdl = idInit(i,F->rank);
7791 strat->S = strat->Shdl->m;
7792 strat->sig = (poly *)omAlloc0(i*sizeof(poly));
7793 if (strat->sbaOrder != 1)
7794 {
7795 strat->syz = (poly *)omAlloc0(i*sizeof(poly));
7796 strat->sevSyz = initsevS(i);
7797 strat->syzmax = i;
7798 strat->syzl = 0;
7799 }
7800 /*- put polys into S -*/
7801 if (Q!=NULL)
7802 {
7803 strat->fromQ=initec(i);
7804 memset(strat->fromQ,0,i*sizeof(int));
7805 for (i=0; i<IDELEMS(Q); i++)
7806 {
7807 if (Q->m[i]!=NULL)
7808 {
7809 LObject h;
7810 h.p = pCopy(Q->m[i]);
7812 {
7813 deleteHC(&h,strat);
7814 }
7816 {
7817 h.pCleardenom(); // also does remove Content
7818 }
7819 else
7820 {
7821 h.pNorm();
7822 }
7823 if (h.p!=NULL)
7824 {
7825 strat->initEcart(&h);
7826 if (strat->sl==-1)
7827 pos =0;
7828 else
7829 {
7830 pos = posInS(strat,strat->sl,h.p,h.ecart);
7831 }
7832 h.sev = pGetShortExpVector(h.p);
7833 strat->enterS(h,pos,strat,-1);
7834 strat->fromQ[pos]=1;
7835 }
7836 }
7837 }
7838 }
7839 for (i=0; i<IDELEMS(F); i++)
7840 {
7841 if (F->m[i]!=NULL)
7842 {
7843 LObject h;
7844 h.p = pCopy(F->m[i]);
7845 h.sig = pOne();
7846 //h.sig = pInit();
7847 //p_SetCoeff(h.sig,nInit(1),currRing);
7848 p_SetComp(h.sig,i+1,currRing);
7849 // if we are working with the Schreyer order we generate it
7850 // by multiplying the initial signatures with the leading monomial
7851 // of the corresponding initial polynomials generating the ideal
7852 // => we can keep the underlying monomial order and get a Schreyer
7853 // order without any bigger overhead
7854 if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
7855 {
7856 p_ExpVectorAdd (h.sig,F->m[i],currRing);
7857 }
7858 h.sevSig = pGetShortExpVector(h.sig);
7859#ifdef DEBUGF5
7860 pWrite(h.p);
7861 pWrite(h.sig);
7862#endif
7863 if (h.p!=NULL)
7864 {
7866 {
7867 cancelunit(&h); /*- tries to cancel a unit -*/
7868 deleteHC(&h, strat);
7869 }
7870 if (h.p!=NULL)
7871 {
7873 {
7874 h.pCleardenom(); // also does remove Content
7875 }
7876 else
7877 {
7878 h.pNorm();
7879 }
7880 strat->initEcart(&h);
7881 if (strat->Ll==-1)
7882 pos =0;
7883 else
7884 pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
7885 h.sev = pGetShortExpVector(h.p);
7886 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7887 }
7888 }
7889 /*
7890 if (strat->sbaOrder != 1)
7891 {
7892 for(j=0;j<i;j++)
7893 {
7894 strat->syz[ctr] = pCopy(F->m[j]);
7895 p_SetCompP(strat->syz[ctr],i+1,currRing);
7896 // add LM(F->m[i]) to the signature to get a Schreyer order
7897 // without changing the underlying polynomial ring at all
7898 p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
7899 // since p_Add_q() destroys all input
7900 // data we need to recreate help
7901 // each time
7902 poly help = pCopy(F->m[i]);
7903 p_SetCompP(help,j+1,currRing);
7904 pWrite(strat->syz[ctr]);
7905 pWrite(help);
7906 printf("%d\n",pLmCmp(strat->syz[ctr],help));
7907 strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
7908 printf("%d. SYZ ",ctr);
7909 pWrite(strat->syz[ctr]);
7910 strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
7911 ctr++;
7912 }
7913 strat->syzl = ps;
7914 }
7915 */
7916 }
7917 }
7918 /*- test, if a unit is in F -*/
7919
7920 if ((strat->Ll>=0)
7921 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7922 && pIsConstant(strat->L[strat->Ll].p))
7923 {
7924 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7925 }
7926}
7927
7929{
7930 if( strat->S[0] )
7931 {
7932 if( strat->S[1] && !rField_is_Ring(currRing))
7933 {
7934 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
7935 omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
7936 omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
7937 }
7938 int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
7939 /************************************************************
7940 * computing the length of the syzygy array needed
7941 ***********************************************************/
7942 for(i=1; i<=strat->sl; i++)
7943 {
7944 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
7945 {
7946 ps += i;
7947 }
7948 }
7949 ps += strat->sl+1;
7950 //comp = pGetComp (strat->P.sig);
7951 comp = strat->currIdx;
7952 strat->syzIdx = initec(comp);
7953 strat->sevSyz = initsevS(ps);
7954 strat->syz = (poly *)omAlloc(ps*sizeof(poly));
7955 strat->syzmax = ps;
7956 strat->syzl = 0;
7957 strat->syzidxmax = comp;
7958#if defined(DEBUGF5) || defined(DEBUGF51)
7959 PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
7960#endif
7961 i = 1;
7962 j = 0;
7963 /************************************************************
7964 * generating the leading terms of the principal syzygies
7965 ***********************************************************/
7966 while (i <= strat->sl)
7967 {
7968 /**********************************************************
7969 * principal syzygies start with component index 2
7970 * the array syzIdx starts with index 0
7971 * => the rules for a signature with component comp start
7972 * at strat->syz[strat->syzIdx[comp-2]] !
7973 *********************************************************/
7974 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
7975 {
7976 comp = pGetComp(strat->sig[i]);
7977 comp_old = pGetComp(strat->sig[i-1]);
7978 diff = comp - comp_old - 1;
7979 // diff should be zero, but sometimes also the initial generating
7980 // elements of the input ideal reduce to zero. then there is an
7981 // index-gap between the signatures. for these in-between signatures we
7982 // can safely set syzIdx[j] = 0 as no such element will be ever computed
7983 // in the following.
7984 // doing this, we keep the relation "j = comp - 2" alive, which makes
7985 // jumps way easier when checking criteria
7986 while (diff>0)
7987 {
7988 strat->syzIdx[j] = 0;
7989 diff--;
7990 j++;
7991 }
7992 strat->syzIdx[j] = ctr;
7993 j++;
7994 LObject Q;
7995 int pos;
7996 for (k = 0; k<i; k++)
7997 {
7998 Q.sig = pOne();
8001 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8002 p_SetCompP (Q.sig, comp, currRing);
8003 poly q = p_One(currRing);
8006 p_ExpVectorCopy(q,strat->S[i],currRing);
8007 q = p_Neg (q, currRing);
8008 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8009 Q.sig = p_Add_q (Q.sig, q, currRing);
8010 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8011 pos = posInSyz(strat, Q.sig);
8012 enterSyz(Q, strat, pos);
8013 ctr++;
8014 }
8015 }
8016 i++;
8017 }
8018 /**************************************************************
8019 * add syzygies for upcoming first element of new iteration step
8020 **************************************************************/
8021 comp = strat->currIdx;
8022 comp_old = pGetComp(strat->sig[i-1]);
8023 diff = comp - comp_old - 1;
8024 // diff should be zero, but sometimes also the initial generating
8025 // elements of the input ideal reduce to zero. then there is an
8026 // index-gap between the signatures. for these in-between signatures we
8027 // can safely set syzIdx[j] = 0 as no such element will be ever computed
8028 // in the following.
8029 // doing this, we keep the relation "j = comp - 2" alive, which makes
8030 // jumps way easier when checking criteria
8031 while (diff>0)
8032 {
8033 strat->syzIdx[j] = 0;
8034 diff--;
8035 j++;
8036 }
8037 strat->syzIdx[j] = ctr;
8038 LObject Q;
8039 int pos;
8040 for (k = 0; k<strat->sl+1; k++)
8041 {
8042 Q.sig = pOne();
8045 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8046 p_SetCompP (Q.sig, comp, currRing);
8047 poly q = p_One(currRing);
8049 p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8050 p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8051 q = p_Neg (q, currRing);
8052 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8053 Q.sig = p_Add_q (Q.sig, q, currRing);
8054 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8055 pos = posInSyz(strat, Q.sig);
8056 enterSyz(Q, strat, pos);
8057 ctr++;
8058 }
8059//#if 1
8060#ifdef DEBUGF5
8061 PrintS("Principal syzygies:\n");
8062 Print("syzl %d\n",strat->syzl);
8063 Print("syzmax %d\n",strat->syzmax);
8064 Print("ps %d\n",ps);
8065 PrintS("--------------------------------\n");
8066 for(i=0;i<=strat->syzl-1;i++)
8067 {
8068 Print("%d - ",i);
8069 pWrite(strat->syz[i]);
8070 }
8071 for(i=0;i<strat->currIdx;i++)
8072 {
8073 Print("%d - %d\n",i,strat->syzIdx[i]);
8074 }
8075 PrintS("--------------------------------\n");
8076#endif
8077 }
8078}
8079
8080/*2
8081*construct the set s from F and {P}
8082*/
8084{
8085 int i,pos;
8086
8087 if (Q!=NULL)
8088 {
8090 if (i<setmaxTinc) i=setmaxT;
8091 }
8092 else i=setmaxT;
8093 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8094 strat->ecartS=initec(i);
8095 strat->sevS=initsevS(i);
8096 strat->S_2_R=initS_2_R(i);
8097 strat->fromQ=NULL;
8098 strat->Shdl=idInit(i,F->rank);
8099 strat->S=strat->Shdl->m;
8100
8101 /*- put polys into S -*/
8102 if (Q!=NULL)
8103 {
8104 strat->fromQ=initec(i);
8105 memset(strat->fromQ,0,i*sizeof(int));
8106 for (i=0; i<IDELEMS(Q); i++)
8107 {
8108 if (Q->m[i]!=NULL)
8109 {
8110 LObject h;
8111 h.p = pCopy(Q->m[i]);
8112 //if (TEST_OPT_INTSTRATEGY)
8113 //{
8114 // h.pCleardenom(); // also does remove Content
8115 //}
8116 //else
8117 //{
8118 // h.pNorm();
8119 //}
8121 {
8122 deleteHC(&h,strat);
8123 }
8124 if (h.p!=NULL)
8125 {
8126 strat->initEcart(&h);
8127 if (strat->sl==-1)
8128 pos =0;
8129 else
8130 {
8131 pos = posInS(strat,strat->sl,h.p,h.ecart);
8132 }
8133 h.sev = pGetShortExpVector(h.p);
8134 strat->enterS(h,pos,strat, strat->tl+1);
8135 enterT(h, strat);
8136 strat->fromQ[pos]=1;
8137 }
8138 }
8139 }
8140 }
8141 /*- put polys into S -*/
8142 for (i=0; i<IDELEMS(F); i++)
8143 {
8144 if (F->m[i]!=NULL)
8145 {
8146 LObject h;
8147 h.p = pCopy(F->m[i]);
8149 {
8150 deleteHC(&h,strat);
8151 }
8152 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8153 {
8154 h.p=redtailBba(h.p,strat->sl,strat);
8155 }
8156 if (h.p!=NULL)
8157 {
8158 strat->initEcart(&h);
8159 if (strat->sl==-1)
8160 pos =0;
8161 else
8162 pos = posInS(strat,strat->sl,h.p,h.ecart);
8163 h.sev = pGetShortExpVector(h.p);
8164 strat->enterS(h,pos,strat, strat->tl+1);
8165 enterT(h,strat);
8166 }
8167 }
8168 }
8169 for (i=0; i<IDELEMS(P); i++)
8170 {
8171 if (P->m[i]!=NULL)
8172 {
8173 LObject h;
8174 h.p=pCopy(P->m[i]);
8176 {
8177 h.pCleardenom();
8178 }
8179 else
8180 {
8181 h.pNorm();
8182 }
8183 if(strat->sl>=0)
8184 {
8186 {
8187 h.p=redBba(h.p,strat->sl,strat);
8188 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8189 {
8190 h.p=redtailBba(h.p,strat->sl,strat);
8191 }
8192 }
8193 else
8194 {
8195 h.p=redMora(h.p,strat->sl,strat);
8196 }
8197 if(h.p!=NULL)
8198 {
8199 strat->initEcart(&h);
8201 {
8202 h.pCleardenom();
8203 }
8204 else
8205 {
8206 h.is_normalized = 0;
8207 h.pNorm();
8208 }
8209 h.sev = pGetShortExpVector(h.p);
8210 h.SetpFDeg();
8211 pos = posInS(strat,strat->sl,h.p,h.ecart);
8212 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8213 strat->enterS(h,pos,strat, strat->tl+1);
8214 enterT(h,strat);
8215 }
8216 }
8217 else
8218 {
8219 h.sev = pGetShortExpVector(h.p);
8220 strat->initEcart(&h);
8221 strat->enterS(h,0,strat, strat->tl+1);
8222 enterT(h,strat);
8223 }
8224 }
8225 }
8226}
8227/*2
8228*construct the set s from F and {P}
8229*/
8230
8232{
8233 int i,pos;
8234
8235 if (Q!=NULL)
8236 {
8238 if (i<setmaxTinc) i=setmaxT;
8239 }
8240 else i=setmaxT;
8241 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8242 strat->sevS=initsevS(i);
8243 strat->sevSig=initsevS(i);
8244 strat->S_2_R=initS_2_R(i);
8245 strat->fromQ=NULL;
8246 strat->Shdl=idInit(i,F->rank);
8247 strat->S=strat->Shdl->m;
8248 strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8249 /*- put polys into S -*/
8250 if (Q!=NULL)
8251 {
8252 strat->fromQ=initec(i);
8253 memset(strat->fromQ,0,i*sizeof(int));
8254 for (i=0; i<IDELEMS(Q); i++)
8255 {
8256 if (Q->m[i]!=NULL)
8257 {
8258 LObject h;
8259 h.p = pCopy(Q->m[i]);
8260 //if (TEST_OPT_INTSTRATEGY)
8261 //{
8262 // h.pCleardenom(); // also does remove Content
8263 //}
8264 //else
8265 //{
8266 // h.pNorm();
8267 //}
8269 {
8270 deleteHC(&h,strat);
8271 }
8272 if (h.p!=NULL)
8273 {
8274 strat->initEcart(&h);
8275 if (strat->sl==-1)
8276 pos =0;
8277 else
8278 {
8279 pos = posInS(strat,strat->sl,h.p,h.ecart);
8280 }
8281 h.sev = pGetShortExpVector(h.p);
8282 strat->enterS(h,pos,strat, strat->tl+1);
8283 enterT(h, strat);
8284 strat->fromQ[pos]=1;
8285 }
8286 }
8287 }
8288 }
8289 /*- put polys into S -*/
8290 for (i=0; i<IDELEMS(F); i++)
8291 {
8292 if (F->m[i]!=NULL)
8293 {
8294 LObject h;
8295 h.p = pCopy(F->m[i]);
8297 {
8298 deleteHC(&h,strat);
8299 }
8300 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8301 {
8302 h.p=redtailBba(h.p,strat->sl,strat);
8303 }
8304 if (h.p!=NULL)
8305 {
8306 strat->initEcart(&h);
8307 if (strat->sl==-1)
8308 pos =0;
8309 else
8310 pos = posInS(strat,strat->sl,h.p,h.ecart);
8311 h.sev = pGetShortExpVector(h.p);
8312 strat->enterS(h,pos,strat, strat->tl+1);
8313 enterT(h,strat);
8314 }
8315 }
8316 }
8317 for (i=0; i<IDELEMS(P); i++)
8318 {
8319 if (P->m[i]!=NULL)
8320 {
8321 LObject h;
8322 h.p=pCopy(P->m[i]);
8324 {
8325 h.pCleardenom();
8326 }
8327 else
8328 {
8329 h.pNorm();
8330 }
8331 if(strat->sl>=0)
8332 {
8334 {
8335 h.p=redBba(h.p,strat->sl,strat);
8336 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8337 {
8338 h.p=redtailBba(h.p,strat->sl,strat);
8339 }
8340 }
8341 else
8342 {
8343 h.p=redMora(h.p,strat->sl,strat);
8344 }
8345 if(h.p!=NULL)
8346 {
8347 strat->initEcart(&h);
8349 {
8350 h.pCleardenom();
8351 }
8352 else
8353 {
8354 h.is_normalized = 0;
8355 h.pNorm();
8356 }
8357 h.sev = pGetShortExpVector(h.p);
8358 h.SetpFDeg();
8359 pos = posInS(strat,strat->sl,h.p,h.ecart);
8360 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8361 strat->enterS(h,pos,strat, strat->tl+1);
8362 enterT(h,strat);
8363 }
8364 }
8365 else
8366 {
8367 h.sev = pGetShortExpVector(h.p);
8368 strat->initEcart(&h);
8369 strat->enterS(h,0,strat, strat->tl+1);
8370 enterT(h,strat);
8371 }
8372 }
8373 }
8374}
8375
8376/*2
8377* reduces h using the set S
8378* procedure used in cancelunit1
8379*/
8380static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8381{
8382 int j = 0;
8383 unsigned long not_sev = ~ pGetShortExpVector(h);
8384
8385 while (j <= maxIndex)
8386 {
8387 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8388 return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8389 else j++;
8390 }
8391 return h;
8392}
8393
8394/*2
8395*tests if p.p=monomial*unit and cancels the unit
8396*/
8397void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8398{
8399 int k;
8400 poly r,h,h1,q;
8401
8402 if (!pIsVector((*p).p) && ((*p).ecart != 0))
8403 {
8404 // Leading coef have to be a unit: no
8405 // example 2x+4x2 should be simplified to 2x*(1+2x)
8406 // and 2 is not a unit in Z
8407 //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8408 k = 0;
8409 h1 = r = pCopy((*p).p);
8410 h =pNext(r);
8411 loop
8412 {
8413 if (h==NULL)
8414 {
8415 pDelete(&r);
8416 pDelete(&(pNext((*p).p)));
8417 (*p).ecart = 0;
8418 (*p).length = 1;
8419 (*p).pLength = 1;
8420 (*suc)=0;
8421 return;
8422 }
8423 if (!pDivisibleBy(r,h))
8424 {
8425 q=redBba1(h,index ,strat);
8426 if (q != h)
8427 {
8428 k++;
8429 pDelete(&h);
8430 pNext(h1) = h = q;
8431 }
8432 else
8433 {
8434 pDelete(&r);
8435 return;
8436 }
8437 }
8438 else
8439 {
8440 h1 = h;
8441 pIter(h);
8442 }
8443 if (k > 10)
8444 {
8445 pDelete(&r);
8446 return;
8447 }
8448 }
8449 }
8450}
8451
8452#if 0
8453/*2
8454* reduces h using the elements from Q in the set S
8455* procedure used in updateS
8456* must not be used for elements of Q or elements of an ideal !
8457*/
8458static poly redQ (poly h, int j, kStrategy strat)
8459{
8460 int start;
8461 unsigned long not_sev = ~ pGetShortExpVector(h);
8462 while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8463 start=j;
8464 while (j<=strat->sl)
8465 {
8466 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8467 {
8468 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8469 if (h==NULL) return NULL;
8470 j = start;
8472 }
8473 else j++;
8474 }
8475 return h;
8476}
8477#endif
8478
8479/*2
8480* reduces h using the set S
8481* procedure used in updateS
8482*/
8483static poly redBba (poly h,int maxIndex,kStrategy strat)
8484{
8485 int j = 0;
8486 unsigned long not_sev = ~ pGetShortExpVector(h);
8487
8488 while (j <= maxIndex)
8489 {
8490 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8491 {
8492 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8493 if (h==NULL) return NULL;
8494 j = 0;
8496 }
8497 else j++;
8498 }
8499 return h;
8500}
8501
8502/*2
8503* reduces h using the set S
8504*e is the ecart of h
8505*procedure used in updateS
8506*/
8507static poly redMora (poly h,int maxIndex,kStrategy strat)
8508{
8509 int j=0;
8510 int e,l;
8511 unsigned long not_sev = ~ pGetShortExpVector(h);
8512
8513 if (maxIndex >= 0)
8514 {
8515 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8516 do
8517 {
8518 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8519 && ((e >= strat->ecartS[j]) || (strat->kNoether!=NULL)))
8520 {
8521#ifdef KDEBUG
8522 if (TEST_OPT_DEBUG)
8523 {
8524 PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8525 }
8526#endif
8527 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8528#ifdef KDEBUG
8529 if(TEST_OPT_DEBUG)
8530 {
8531 PrintS(")\nto "); wrp(h); PrintLn();
8532 }
8533#endif
8534 // pDelete(&h);
8535 if (h == NULL) return NULL;
8536 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8537 j = 0;
8539 }
8540 else j++;
8541 }
8542 while (j <= maxIndex);
8543 }
8544 return h;
8545}
8546
8547/*2
8548*updates S:
8549*the result is a set of polynomials which are in
8550*normalform with respect to S
8551*/
8553{
8554 LObject h;
8555 int i, suc=0;
8556 poly redSi=NULL;
8558// Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8559// for (i=0; i<=(strat->sl); i++)
8560// {
8561// Print("s%d:",i);
8562// if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8563// pWrite(strat->S[i]);
8564// }
8565// Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8568 {
8569 while (suc != -1)
8570 {
8571 i=suc+1;
8572 while (i<=strat->sl)
8573 {
8574 change=FALSE;
8576 any_change = FALSE;
8577 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8578 {
8579 redSi = pHead(strat->S[i]);
8580 strat->S[i] = redBba(strat->S[i],i-1,strat);
8581 //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8582 // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8583 if (pCmp(redSi,strat->S[i])!=0)
8584 {
8585 change=TRUE;
8587 #ifdef KDEBUG
8588 if (TEST_OPT_DEBUG)
8589 {
8590 PrintS("reduce:");
8591 wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8592 }
8593 #endif
8594 if (TEST_OPT_PROT)
8595 {
8596 if (strat->S[i]==NULL)
8597 PrintS("V");
8598 else
8599 PrintS("v");
8600 mflush();
8601 }
8602 }
8603 pLmDelete(&redSi);
8604 if (strat->S[i]==NULL)
8605 {
8606 deleteInS(i,strat);
8607 i--;
8608 }
8609 else if (change)
8610 {
8612 {
8614 {
8615 number n;
8616 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8617 if (!nIsOne(n))
8618 {
8620 denom->n=nInvers(n);
8621 denom->next=DENOMINATOR_LIST;
8623 }
8624 nDelete(&n);
8625 }
8626 else
8627 {
8628 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8629 }
8630 }
8631 else
8632 {
8633 pNorm(strat->S[i]);
8634 }
8635 strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8636 }
8637 }
8638 i++;
8639 }
8640 if (any_change) reorderS(&suc,strat);
8641 else break;
8642 }
8643 if (toT)
8644 {
8645 for (i=0; i<=strat->sl; i++)
8646 {
8647 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8648 {
8649 h.p = redtailBba(strat->S[i],i-1,strat);
8651 {
8652 h.pCleardenom();// also does remove Content
8653 }
8654 }
8655 else
8656 {
8657 h.p = strat->S[i];
8658 }
8659 strat->initEcart(&h);
8660 if (strat->honey)
8661 {
8662 strat->ecartS[i] = h.ecart;
8663 }
8664 if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8665 else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8666 h.sev = strat->sevS[i];
8667 /*puts the elements of S also to T*/
8668 strat->initEcart(&h);
8669 /*if (toT) - already checked*/ enterT(h,strat);
8670 strat->S_2_R[i] = strat->tl;
8671#ifdef HAVE_SHIFTBBA
8672 if (/*(toT) && */(currRing->isLPring))
8673 enterTShift(h, strat);
8674#endif
8675 }
8676 }
8677 }
8678 else
8679 {
8680 while (suc != -1)
8681 {
8682 i=suc;
8683 while (i<=strat->sl)
8684 {
8685 change=FALSE;
8686 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8687 {
8688 redSi=pHead((strat->S)[i]);
8689 (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
8690 if ((strat->S)[i]==NULL)
8691 {
8692 deleteInS(i,strat);
8693 i--;
8694 }
8695 else if (pCmp((strat->S)[i],redSi)!=0)
8696 {
8698 h.p = strat->S[i];
8699 strat->initEcart(&h);
8700 strat->ecartS[i] = h.ecart;
8702 {
8704 {
8705 number n;
8706 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8707 if (!nIsOne(n))
8708 {
8710 denom->n=nInvers(n);
8711 denom->next=DENOMINATOR_LIST;
8713 }
8714 nDelete(&n);
8715 }
8716 else
8717 {
8718 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8719 }
8720 }
8721 else
8722 {
8723 pNorm(strat->S[i]); // == h.p
8724 }
8725 h.sev = pGetShortExpVector(h.p);
8726 strat->sevS[i] = h.sev;
8727 }
8728 pLmDelete(&redSi);
8729 kTest(strat);
8730 }
8731 i++;
8732 }
8733#ifdef KDEBUG
8734 kTest(strat);
8735#endif
8736 if (any_change) reorderS(&suc,strat);
8737 else { suc=-1; break; }
8738 if (h.p!=NULL)
8739 {
8740 if (!strat->kAllAxis)
8741 {
8742 /*strat->kAllAxis =*/ HEckeTest(h.p,strat);
8743 }
8744 if (strat->kAllAxis)
8745 newHEdge(strat);
8746 }
8747 }
8748 for (i=0; i<=strat->sl; i++)
8749 {
8750 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8751 {
8752 strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
8753 strat->initEcart(&h);
8754 strat->ecartS[i] = h.ecart;
8755 h.sev = pGetShortExpVector(h.p);
8756 strat->sevS[i] = h.sev;
8757 }
8758 else
8759 {
8760 h.p = strat->S[i];
8761 h.ecart=strat->ecartS[i];
8762 h.sev = strat->sevS[i];
8763 h.length = h.pLength = pLength(h.p);
8764 }
8765 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8766 cancelunit1(&h,&suc,strat->sl,strat);
8767 h.SetpFDeg();
8768 /*puts the elements of S also to T*/
8769 enterT(h,strat);
8770 strat->S_2_R[i] = strat->tl;
8771#ifdef HAVE_SHIFTBBA
8772 if (currRing->isLPring)
8773 enterTShift(h, strat);
8774#endif
8775 }
8776 if (suc!= -1) updateS(toT,strat);
8777 }
8778#ifdef KDEBUG
8779 kTest(strat);
8780#endif
8781}
8782
8783/*2
8784* -puts p to the standardbasis s at position at
8785* -saves the result in S
8786*/
8787void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
8788{
8789 strat->news = TRUE;
8790 /*- puts p to the standardbasis s at position at -*/
8791 if (strat->sl == IDELEMS(strat->Shdl)-1)
8792 {
8793 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8794 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8795 (IDELEMS(strat->Shdl)+setmaxTinc)
8796 *sizeof(unsigned long));
8797 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8798 IDELEMS(strat->Shdl)*sizeof(int),
8799 (IDELEMS(strat->Shdl)+setmaxTinc)
8800 *sizeof(int));
8801 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8802 IDELEMS(strat->Shdl)*sizeof(int),
8803 (IDELEMS(strat->Shdl)+setmaxTinc)
8804 *sizeof(int));
8805 if (strat->lenS!=NULL)
8806 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8807 IDELEMS(strat->Shdl)*sizeof(int),
8808 (IDELEMS(strat->Shdl)+setmaxTinc)
8809 *sizeof(int));
8810 if (strat->lenSw!=NULL)
8811 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8812 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8813 (IDELEMS(strat->Shdl)+setmaxTinc)
8814 *sizeof(wlen_type));
8815 if (strat->fromQ!=NULL)
8816 {
8817 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8818 IDELEMS(strat->Shdl)*sizeof(int),
8819 (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
8820 }
8821 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
8822 IDELEMS(strat->Shdl)+=setmaxTinc;
8823 strat->Shdl->m=strat->S;
8824 }
8825 if (atS <= strat->sl)
8826 {
8827#ifdef ENTER_USE_MEMMOVE
8828 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
8829 (strat->sl - atS + 1)*sizeof(poly));
8830 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
8831 (strat->sl - atS + 1)*sizeof(int));
8832 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
8833 (strat->sl - atS + 1)*sizeof(unsigned long));
8834 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
8835 (strat->sl - atS + 1)*sizeof(int));
8836 if (strat->lenS!=NULL)
8837 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
8838 (strat->sl - atS + 1)*sizeof(int));
8839 if (strat->lenSw!=NULL)
8840 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
8841 (strat->sl - atS + 1)*sizeof(wlen_type));
8842#else
8843 for (i=strat->sl+1; i>=atS+1; i--)
8844 {
8845 strat->S[i] = strat->S[i-1];
8846 strat->ecartS[i] = strat->ecartS[i-1];
8847 strat->sevS[i] = strat->sevS[i-1];
8848 strat->S_2_R[i] = strat->S_2_R[i-1];
8849 }
8850 if (strat->lenS!=NULL)
8851 for (i=strat->sl+1; i>=atS+1; i--)
8852 strat->lenS[i] = strat->lenS[i-1];
8853 if (strat->lenSw!=NULL)
8854 for (i=strat->sl+1; i>=atS+1; i--)
8855 strat->lenSw[i] = strat->lenSw[i-1];
8856#endif
8857 }
8858 if (strat->fromQ!=NULL)
8859 {
8860#ifdef ENTER_USE_MEMMOVE
8861 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
8862 (strat->sl - atS + 1)*sizeof(int));
8863#else
8864 for (i=strat->sl+1; i>=atS+1; i--)
8865 {
8866 strat->fromQ[i] = strat->fromQ[i-1];
8867 }
8868#endif
8869 strat->fromQ[atS]=0;
8870 }
8871
8872 /*- save result -*/
8873 poly pp=p.p;
8874 strat->S[atS] = pp;
8875 if (strat->honey) strat->ecartS[atS] = p.ecart;
8876 if (p.sev == 0)
8877 p.sev = pGetShortExpVector(pp);
8878 else
8879 assume(p.sev == pGetShortExpVector(pp));
8880 strat->sevS[atS] = p.sev;
8881 strat->ecartS[atS] = p.ecart;
8882 strat->S_2_R[atS] = atR;
8883 strat->sl++;
8884}
8885
8886#ifdef HAVE_SHIFTBBA
8887void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR)
8888{
8889 enterSBba(p, atS, strat, atR);
8890
8892 for (int i = maxPossibleShift; i > 0; i--)
8893 {
8894 // NOTE: don't use "shared tails" here. In rare cases it can cause problems
8895 // in `kNF2` because of lazy poly normalizations.
8896 LObject qq(p_Copy(p.p, strat->tailRing));
8897 p_mLPshift(qq.p, i, strat->tailRing);
8898 qq.shift = i;
8899 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
8900 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
8901 enterSBba(qq, atS, strat, -1);
8902 }
8903}
8904#endif
8905
8906/*2
8907* -puts p to the standardbasis s at position at
8908* -saves the result in S
8909*/
8910void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
8911{
8912 strat->news = TRUE;
8913 /*- puts p to the standardbasis s at position at -*/
8914 if (strat->sl == IDELEMS(strat->Shdl)-1)
8915 {
8916 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8917 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8918 (IDELEMS(strat->Shdl)+setmax)
8919 *sizeof(unsigned long));
8920 strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
8921 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8922 (IDELEMS(strat->Shdl)+setmax)
8923 *sizeof(unsigned long));
8924 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8925 IDELEMS(strat->Shdl)*sizeof(int),
8926 (IDELEMS(strat->Shdl)+setmax)
8927 *sizeof(int));
8928 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8929 IDELEMS(strat->Shdl)*sizeof(int),
8930 (IDELEMS(strat->Shdl)+setmax)
8931 *sizeof(int));
8932 if (strat->lenS!=NULL)
8933 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8934 IDELEMS(strat->Shdl)*sizeof(int),
8935 (IDELEMS(strat->Shdl)+setmax)
8936 *sizeof(int));
8937 if (strat->lenSw!=NULL)
8938 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8939 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8940 (IDELEMS(strat->Shdl)+setmax)
8941 *sizeof(wlen_type));
8942 if (strat->fromQ!=NULL)
8943 {
8944 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8945 IDELEMS(strat->Shdl)*sizeof(int),
8946 (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
8947 }
8948 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
8949 pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
8950 IDELEMS(strat->Shdl)+=setmax;
8951 strat->Shdl->m=strat->S;
8952 }
8953 // in a signature-based algorithm the following situation will never
8954 // appear due to the fact that the critical pairs are already sorted
8955 // by increasing signature.
8956 // True. However, in the case of integers we need to put the element
8957 // that caused the signature drop on the first position
8958 if (atS <= strat->sl)
8959 {
8960#ifdef ENTER_USE_MEMMOVE
8961 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
8962 (strat->sl - atS + 1)*sizeof(poly));
8963 memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
8964 (strat->sl - atS + 1)*sizeof(poly));
8965 memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
8966 (strat->sl - atS + 1)*sizeof(unsigned long));
8967 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
8968 (strat->sl - atS + 1)*sizeof(int));
8969 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
8970 (strat->sl - atS + 1)*sizeof(unsigned long));
8971 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
8972 (strat->sl - atS + 1)*sizeof(int));
8973 if (strat->lenS!=NULL)
8974 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
8975 (strat->sl - atS + 1)*sizeof(int));
8976 if (strat->lenSw!=NULL)
8977 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
8978 (strat->sl - atS + 1)*sizeof(wlen_type));
8979#else
8980 for (i=strat->sl+1; i>=atS+1; i--)
8981 {
8982 strat->S[i] = strat->S[i-1];
8983 strat->ecartS[i] = strat->ecartS[i-1];
8984 strat->sevS[i] = strat->sevS[i-1];
8985 strat->S_2_R[i] = strat->S_2_R[i-1];
8986 strat->sig[i] = strat->sig[i-1];
8987 strat->sevSig[i] = strat->sevSig[i-1];
8988 }
8989 if (strat->lenS!=NULL)
8990 for (i=strat->sl+1; i>=atS+1; i--)
8991 strat->lenS[i] = strat->lenS[i-1];
8992 if (strat->lenSw!=NULL)
8993 for (i=strat->sl+1; i>=atS+1; i--)
8994 strat->lenSw[i] = strat->lenSw[i-1];
8995#endif
8996 }
8997 if (strat->fromQ!=NULL)
8998 {
8999#ifdef ENTER_USE_MEMMOVE
9000 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9001 (strat->sl - atS + 1)*sizeof(int));
9002#else
9003 for (i=strat->sl+1; i>=atS+1; i--)
9004 {
9005 strat->fromQ[i] = strat->fromQ[i-1];
9006 }
9007#endif
9008 strat->fromQ[atS]=0;
9009 }
9010
9011 /*- save result -*/
9012 strat->S[atS] = p.p;
9013 strat->sig[atS] = p.sig; // TODO: get the correct signature in here!
9014 if (strat->honey) strat->ecartS[atS] = p.ecart;
9015 if (p.sev == 0)
9016 p.sev = pGetShortExpVector(p.p);
9017 else
9018 assume(p.sev == pGetShortExpVector(p.p));
9019 strat->sevS[atS] = p.sev;
9020 // during the interreduction process of a signature-based algorithm we do not
9021 // compute the signature at this point, but when the whole interreduction
9022 // process finishes, i.e. f5c terminates!
9023 if (p.sig != NULL)
9024 {
9025 if (p.sevSig == 0)
9026 p.sevSig = pGetShortExpVector(p.sig);
9027 else
9028 assume(p.sevSig == pGetShortExpVector(p.sig));
9029 strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9030 }
9031 strat->ecartS[atS] = p.ecart;
9032 strat->S_2_R[atS] = atR;
9033 strat->sl++;
9034#ifdef DEBUGF5
9035 int k;
9036 Print("--- LIST S: %d ---\n",strat->sl);
9037 for(k=0;k<=strat->sl;k++)
9038 {
9039 pWrite(strat->sig[k]);
9040 }
9041 PrintS("--- LIST S END ---\n");
9042#endif
9043}
9044
9046{
9047 p.GetP(strat->lmBin);
9048 if (strat->homog) strat->initEcart(&p);
9049 strat->redTailChange=FALSE;
9051 {
9052 p.pCleardenom();
9054 {
9055#ifdef HAVE_SHIFTBBA
9056 if (rIsLPRing(currRing))
9057 p.p = redtailBba(&p,strat->tl,strat, TRUE,!TEST_OPT_CONTENTSB);
9058 else
9059#endif
9060 {
9061 p.p = redtailBba(&p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9062 }
9063 p.pCleardenom();
9064 if (strat->redTailChange)
9065 p.t_p=NULL;
9066 if (strat->P.p!=NULL) strat->P.sev=p_GetShortExpVector(strat->P.p,currRing);
9067 else strat->P.sev=0;
9068 }
9069 }
9070
9071 assume(strat->tailRing == p.tailRing);
9072 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9073
9074 int i, j, pos;
9075 poly tp = strat->T[tj].p;
9076
9077 /* enter p to T set */
9078 enterT(p, strat);
9079
9080 for (j = 0; j <= strat->sl; ++j)
9081 {
9082 if (pLtCmp(tp, strat->S[j]) == 0)
9083 {
9084 break;
9085 }
9086 }
9087 /* it may be that the exchanged element
9088 * is until now only in T and not in S */
9089 if (j <= strat->sl)
9090 {
9091 deleteInS(j, strat);
9092 }
9093
9094 pos = posInS(strat, strat->sl, p.p, p.ecart);
9095
9096 pp_Test(p.p, currRing, p.tailRing);
9097 assume(p.FDeg == p.pFDeg());
9098
9099 /* remove useless pairs from L set */
9100 for (i = 0; i <= strat->Ll; ++i)
9101 {
9102 if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0)
9103 {
9104 deleteInL(strat->L, &(strat->Ll), i, strat);
9105 i--;
9106 continue;
9107 }
9108 if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0)
9109 {
9110 deleteInL(strat->L, &(strat->Ll), i, strat);
9111 i--;
9112 }
9113 }
9114#ifdef HAVE_SHIFTBBA
9115 if (rIsLPRing(currRing))
9116 enterpairsShift(p.p, strat->sl, p.ecart, pos, strat, strat->tl); // TODO LP
9117 else
9118#endif
9119 {
9120 /* generate new pairs with p, probably removing older, now useless pairs */
9121 superenterpairs(p.p, strat->sl, p.ecart, pos, strat, strat->tl);
9122 }
9123 /* enter p to S set */
9124 strat->enterS(p, pos, strat, strat->tl);
9125
9126#ifdef HAVE_SHIFTBBA
9127 /* do this after enterS so that the index in R (which is strat->tl) is correct */
9128 if (rIsLPRing(currRing) && !strat->rightGB)
9129 enterTShift(p,strat);
9130#endif
9131}
9132
9133/*2
9134* puts p to the set T at position atT
9135*/
9136void enterT(LObject &p, kStrategy strat, int atT)
9137{
9138 int i;
9139
9140#ifdef PDEBUG
9141#ifdef HAVE_SHIFTBBA
9142 if (currRing->isLPring && p.shift > 0)
9143 {
9144 // in this case, the order is not correct. test LM and tail separately
9145 p_LmTest(p.p, currRing);
9146 p_Test(pNext(p.p), currRing);
9147 }
9148 else
9149#endif
9150 {
9151 pp_Test(p.p, currRing, p.tailRing);
9152 }
9153#endif
9154 assume(strat->tailRing == p.tailRing);
9155 // redMoraNF complains about this -- but, we don't really
9156 // need this so far
9157 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9158 assume(!strat->homog || (p.FDeg == p.pFDeg()));
9159 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9160
9161#ifdef KDEBUG
9162 // do not put an LObject twice into T:
9163 for(i=strat->tl;i>=0;i--)
9164 {
9165 if (p.p==strat->T[i].p)
9166 {
9167 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9168 return;
9169 }
9170 }
9171#endif
9172
9173#ifdef HAVE_TAIL_RING
9174 if (currRing!=strat->tailRing)
9175 {
9176 p.t_p=p.GetLmTailRing();
9177 }
9178#endif
9179 strat->newt = TRUE;
9180 if (atT < 0)
9181 atT = strat->posInT(strat->T, strat->tl, p);
9182 if (strat->tl == strat->tmax-1)
9183 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,strat->tmax);
9184 if (atT <= strat->tl)
9185 {
9186#ifdef ENTER_USE_MEMMOVE
9187 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9188 (strat->tl-atT+1)*sizeof(TObject));
9189 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9190 (strat->tl-atT+1)*sizeof(unsigned long));
9191#endif
9192 for (i=strat->tl+1; i>=atT+1; i--)
9193 {
9194#ifndef ENTER_USE_MEMMOVE
9195 strat->T[i] = strat->T[i-1];
9196 strat->sevT[i] = strat->sevT[i-1];
9197#endif
9198 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9199 }
9200 }
9201
9202 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9203 {
9204#ifdef HAVE_SHIFTBBA
9205 // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9206 if (!(currRing->isLPring && p.shift > 0))
9207#endif
9208 {
9210 (strat->tailRing != NULL ?
9211 strat->tailRing : currRing),
9212 strat->tailBin);
9213 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9214 }
9215 }
9216 strat->T[atT] = (TObject) p;
9217 //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9218
9219 if ((pNext(p.p) != NULL) && (!rIsLPRing(currRing)))
9220 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9221 else
9222 strat->T[atT].max_exp = NULL;
9223
9224 strat->tl++;
9225 strat->R[strat->tl] = &(strat->T[atT]);
9226 strat->T[atT].i_r = strat->tl;
9227 assume((p.sev == 0) || (pGetShortExpVector(p.p) == p.sev));
9228 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9229 kTest_T(&(strat->T[atT]),strat);
9230}
9231
9232/*2
9233* puts p to the set T at position atT
9234*/
9236{
9238 int i;
9239
9240 pp_Test(p.p, currRing, p.tailRing);
9241 assume(strat->tailRing == p.tailRing);
9242 // redMoraNF complains about this -- but, we don't really
9243 // need this so far
9244 assume(p.pLength == 0 || (int)pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9245 assume(p.FDeg == p.pFDeg());
9246 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9247
9248#ifdef KDEBUG
9249 // do not put an LObject twice into T:
9250 for(i=strat->tl;i>=0;i--)
9251 {
9252 if (p.p==strat->T[i].p)
9253 {
9254 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9255 return;
9256 }
9257 }
9258#endif
9259
9260#ifdef HAVE_TAIL_RING
9261 if (currRing!=strat->tailRing)
9262 {
9263 p.t_p=p.GetLmTailRing();
9264 }
9265#endif
9266 strat->newt = TRUE;
9267 if (atT < 0)
9268 atT = strat->posInT(strat->T, strat->tl, p);
9269 if (strat->tl == strat->tmax-1)
9270 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,strat->tmax);
9271 if (atT <= strat->tl)
9272 {
9273#ifdef ENTER_USE_MEMMOVE
9274 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9275 (strat->tl-atT+1)*sizeof(TObject));
9276 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9277 (strat->tl-atT+1)*sizeof(unsigned long));
9278#endif
9279 for (i=strat->tl+1; i>=atT+1; i--)
9280 {
9281#ifndef ENTER_USE_MEMMOVE
9282 strat->T[i] = strat->T[i-1];
9283 strat->sevT[i] = strat->sevT[i-1];
9284#endif
9285 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9286 }
9287 }
9288
9289 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9290 {
9292 (strat->tailRing != NULL ?
9293 strat->tailRing : currRing),
9294 strat->tailBin);
9295 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9296 }
9297 strat->T[atT] = (TObject) p;
9298 //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9299
9300 if (pNext(p.p) != NULL)
9301 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9302 else
9303 strat->T[atT].max_exp = NULL;
9304
9305 strat->tl++;
9306 strat->R[strat->tl] = &(strat->T[atT]);
9307 strat->T[atT].i_r = strat->tl;
9308 assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9309 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9310 #if 1
9312 && !n_IsUnit(p.p->coef, currRing->cf))
9313 {
9314 for(i=strat->tl;i>=0;i--)
9315 {
9316 if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9317 {
9318 enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9319 }
9320 }
9321 }
9322 /*
9323 printf("\nThis is T:\n");
9324 for(i=strat->tl;i>=0;i--)
9325 {
9326 pWrite(strat->T[i].p);
9327 }
9328 //getchar();*/
9329 #endif
9330 kTest_T(&(strat->T[atT]),strat);
9331}
9332
9333/*2
9334* puts signature p.sig to the set syz
9335*/
9336void enterSyz(LObject &p, kStrategy strat, int atT)
9337{
9338 int i;
9339 strat->newt = TRUE;
9340 if (strat->syzl == strat->syzmax-1)
9341 {
9342 pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9343 strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9344 (strat->syzmax)*sizeof(unsigned long),
9345 ((strat->syzmax)+setmax)
9346 *sizeof(unsigned long));
9347 strat->syzmax += setmax;
9348 }
9349 if (atT < strat->syzl)
9350 {
9351#ifdef ENTER_USE_MEMMOVE
9352 memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9353 (strat->syzl-atT+1)*sizeof(poly));
9354 memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9355 (strat->syzl-atT+1)*sizeof(unsigned long));
9356#endif
9357 for (i=strat->syzl; i>=atT+1; i--)
9358 {
9359#ifndef ENTER_USE_MEMMOVE
9360 strat->syz[i] = strat->syz[i-1];
9361 strat->sevSyz[i] = strat->sevSyz[i-1];
9362#endif
9363 }
9364 }
9365 //i = strat->syzl;
9366 i = atT;
9367 //Makes sure the syz saves just the signature
9369 pNext(p.sig) = NULL;
9370 strat->syz[atT] = p.sig;
9371 strat->sevSyz[atT] = p.sevSig;
9372 strat->syzl++;
9373#if F5DEBUG
9374 Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9375 pWrite(strat->syz[atT]);
9376#endif
9377 // recheck pairs in strat->L with new rule and delete correspondingly
9378 int cc = strat->Ll;
9379 while (cc>-1)
9380 {
9381 //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9382 //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);
9383 if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9384 strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9386 || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9387 )
9388 {
9389 //printf("\nYES!\n");
9390 deleteInL(strat->L,&strat->Ll,cc,strat);
9391 }
9392 cc--;
9393 }
9394//#if 1
9395#ifdef DEBUGF5
9396 PrintS("--- Syzygies ---\n");
9397 Print("syzl %d\n",strat->syzl);
9398 Print("syzmax %d\n",strat->syzmax);
9399 PrintS("--------------------------------\n");
9400 for(i=0;i<=strat->syzl-1;i++)
9401 {
9402 Print("%d - ",i);
9403 pWrite(strat->syz[i]);
9404 }
9405 PrintS("--------------------------------\n");
9406#endif
9407}
9408
9409
9411{
9412
9413 //if the ordering is local, then hilb criterion
9414 //can be used also if the ideal is not homogeneous
9416 {
9418 *hilb=NULL;
9419 else
9420 return;
9421 }
9422 if (strat->homog!=isHomog)
9423 {
9424 *hilb=NULL;
9425 }
9426}
9427
9429{
9432 if (TEST_OPT_SB_1)
9435 {
9437 strat->chainCrit=chainCritRing;
9438 }
9439#ifdef HAVE_RATGRING
9440 if (rIsRatGRing(currRing))
9441 {
9442 strat->chainCrit=chainCritPart;
9443 /* enterOnePairNormal get rational part in it */
9444 }
9445#endif
9446 if (TEST_OPT_IDLIFT
9447 && (strat->syzComp==1)
9448 && (!rIsPluralRing(currRing)))
9450
9452 strat->Gebauer = strat->homog || strat->sugarCrit;
9453 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9454 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9455 strat->pairtest = NULL;
9456 /* always use tailreduction, except:
9457 * - in local rings, - in lex order case, -in ring over extensions */
9459 //if(rHasMixedOrdering(currRing)==2)
9460 //{
9461 // strat->noTailReduction =TRUE;
9462 //}
9463
9464#ifdef HAVE_PLURAL
9465 // and r is plural_ring
9466 // hence this holds for r a rational_plural_ring
9467 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9468 { //or it has non-quasi-comm type... later
9469 strat->sugarCrit = FALSE;
9470 strat->Gebauer = FALSE;
9471 strat->honey = FALSE;
9472 }
9473#endif
9474
9475 // Coefficient ring?
9477 {
9478 strat->sugarCrit = FALSE;
9479 strat->Gebauer = FALSE;
9480 strat->honey = FALSE;
9481 }
9482 #ifdef KDEBUG
9483 if (TEST_OPT_DEBUG)
9484 {
9485 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9486 else PrintS("ideal/module is not homogeneous\n");
9487 }
9488 #endif
9489}
9490
9492{
9493 //strat->enterOnePair=enterOnePairNormal;
9495 //strat->chainCrit=chainCritNormal;
9496 strat->chainCrit = chainCritSig;
9497 /******************************************
9498 * rewCrit1 and rewCrit2 are already set in
9499 * kSba() in kstd1.cc
9500 *****************************************/
9501 //strat->rewCrit1 = faugereRewCriterion;
9502 if (strat->sbaOrder == 1)
9503 {
9504 strat->syzCrit = syzCriterionInc;
9505 }
9506 else
9507 {
9508 strat->syzCrit = syzCriterion;
9509 }
9511 {
9513 strat->chainCrit=chainCritRing;
9514 }
9515#ifdef HAVE_RATGRING
9516 if (rIsRatGRing(currRing))
9517 {
9518 strat->chainCrit=chainCritPart;
9519 /* enterOnePairNormal get rational part in it */
9520 }
9521#endif
9522
9524 strat->Gebauer = strat->homog || strat->sugarCrit;
9525 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9526 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9527 strat->pairtest = NULL;
9528 /* always use tailreduction, except:
9529 * - in local rings, - in lex order case, -in ring over extensions */
9532
9533#ifdef HAVE_PLURAL
9534 // and r is plural_ring
9535 // hence this holds for r a rational_plural_ring
9536 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9537 { //or it has non-quasi-comm type... later
9538 strat->sugarCrit = FALSE;
9539 strat->Gebauer = FALSE;
9540 strat->honey = FALSE;
9541 }
9542#endif
9543
9544 // Coefficient ring?
9546 {
9547 strat->sugarCrit = FALSE;
9548 strat->Gebauer = FALSE ;
9549 strat->honey = FALSE;
9550 }
9551 #ifdef KDEBUG
9552 if (TEST_OPT_DEBUG)
9553 {
9554 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9555 else PrintS("ideal/module is not homogeneous\n");
9556 }
9557 #endif
9558}
9559
9561 (const LSet set, const int length,
9562 LObject* L,const kStrategy strat))
9563{
9564 if (pos_in_l == posInL110
9565 || pos_in_l == posInL10
9567 )
9568 return TRUE;
9569
9570 return FALSE;
9571}
9572
9574{
9576 {
9577 if (strat->honey)
9578 {
9579 strat->posInL = posInL15;
9580 // ok -- here is the deal: from my experiments for Singular-2-0
9581 // I conclude that that posInT_EcartpLength is the best of
9582 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9583 // see the table at the end of this file
9584 if (TEST_OPT_OLDSTD)
9585 strat->posInT = posInT15;
9586 else
9587 strat->posInT = posInT_EcartpLength;
9588 }
9589 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9590 {
9591 strat->posInL = posInL11;
9592 strat->posInT = posInT11;
9593 }
9594 else if (TEST_OPT_INTSTRATEGY)
9595 {
9596 strat->posInL = posInL11;
9597 strat->posInT = posInT11;
9598 }
9599 else
9600 {
9601 strat->posInL = posInL0;
9602 strat->posInT = posInT0;
9603 }
9604 //if (strat->minim>0) strat->posInL =posInLSpecial;
9605 if (strat->homog)
9606 {
9607 strat->posInL = posInL110;
9608 strat->posInT = posInT110;
9609 }
9610 }
9611 else /* local/mixed ordering */
9612 {
9613 if (strat->homog)
9614 {
9615 strat->posInL = posInL11;
9616 strat->posInT = posInT11;
9617 }
9618 else
9619 {
9620 if ((currRing->order[0]==ringorder_c)
9621 ||(currRing->order[0]==ringorder_C))
9622 {
9623 strat->posInL = posInL17_c;
9624 strat->posInT = posInT17_c;
9625 }
9626 else
9627 {
9628 strat->posInL = posInL17;
9629 strat->posInT = posInT17;
9630 }
9631 }
9632 }
9633 if (strat->minim>0) strat->posInL =posInLSpecial;
9634 // for further tests only
9635 if ((BTEST1(11)) || (BTEST1(12)))
9636 strat->posInL = posInL11;
9637 else if ((BTEST1(13)) || (BTEST1(14)))
9638 strat->posInL = posInL13;
9639 else if ((BTEST1(15)) || (BTEST1(16)))
9640 strat->posInL = posInL15;
9641 else if ((BTEST1(17)) || (BTEST1(18)))
9642 strat->posInL = posInL17;
9643 if (BTEST1(11))
9644 strat->posInT = posInT11;
9645 else if (BTEST1(13))
9646 strat->posInT = posInT13;
9647 else if (BTEST1(15))
9648 strat->posInT = posInT15;
9649 else if ((BTEST1(17)))
9650 strat->posInT = posInT17;
9651 else if ((BTEST1(19)))
9652 strat->posInT = posInT19;
9653 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9654 strat->posInT = posInT1;
9656}
9657
9659{
9661 {
9662 if (strat->honey)
9663 {
9664 strat->posInL = posInL15Ring;
9665 // ok -- here is the deal: from my experiments for Singular-2-0
9666 // I conclude that that posInT_EcartpLength is the best of
9667 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9668 // see the table at the end of this file
9669 if (TEST_OPT_OLDSTD)
9670 strat->posInT = posInT15Ring;
9671 else
9672 strat->posInT = posInT_EcartpLength;
9673 }
9674 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9675 {
9676 strat->posInL = posInL11Ring;
9677 strat->posInT = posInT11;
9678 }
9679 else if (TEST_OPT_INTSTRATEGY)
9680 {
9681 strat->posInL = posInL11Ring;
9682 strat->posInT = posInT11;
9683 }
9684 else
9685 {
9686 strat->posInL = posInL0Ring;
9687 strat->posInT = posInT0;
9688 }
9689 //if (strat->minim>0) strat->posInL =posInLSpecial;
9690 if (strat->homog)
9691 {
9692 strat->posInL = posInL110Ring;
9693 strat->posInT = posInT110Ring;
9694 }
9695 }
9696 else
9697 {
9698 if (strat->homog)
9699 {
9700 //printf("\nHere 3\n");
9701 strat->posInL = posInL11Ring;
9702 strat->posInT = posInT11Ring;
9703 }
9704 else
9705 {
9706 if ((currRing->order[0]==ringorder_c)
9707 ||(currRing->order[0]==ringorder_C))
9708 {
9709 strat->posInL = posInL17_cRing;
9710 strat->posInT = posInT17_cRing;
9711 }
9712 else
9713 {
9714 strat->posInL = posInL11Ringls;
9715 strat->posInT = posInT17Ring;
9716 }
9717 }
9718 }
9719 if (strat->minim>0) strat->posInL =posInLSpecial;
9720 // for further tests only
9721 if ((BTEST1(11)) || (BTEST1(12)))
9722 strat->posInL = posInL11Ring;
9723 else if ((BTEST1(13)) || (BTEST1(14)))
9724 strat->posInL = posInL13;
9725 else if ((BTEST1(15)) || (BTEST1(16)))
9726 strat->posInL = posInL15Ring;
9727 else if ((BTEST1(17)) || (BTEST1(18)))
9728 strat->posInL = posInL17Ring;
9729 if (BTEST1(11))
9730 strat->posInT = posInT11Ring;
9731 else if (BTEST1(13))
9732 strat->posInT = posInT13;
9733 else if (BTEST1(15))
9734 strat->posInT = posInT15Ring;
9735 else if ((BTEST1(17)))
9736 strat->posInT = posInT17Ring;
9737 else if ((BTEST1(19)))
9738 strat->posInT = posInT19;
9739 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9740 strat->posInT = posInT1;
9742}
9743
9745{
9746 strat->interpt = BTEST1(OPT_INTERRUPT);
9747 /*- creating temp data structures------------------- -*/
9748 //strat->cp = 0; // already by skStragy()
9749 //strat->c3 = 0; // already by skStragy()
9750#ifdef HAVE_SHIFTBBA
9751 strat->cv = 0; // already by skStragy()
9752#endif
9753 strat->tail = pInit();
9754 /*- set s -*/
9755 strat->sl = -1;
9756 /*- set L -*/
9757 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9758 strat->Ll = -1;
9759 strat->L = initL(strat->Lmax);
9760 /*- set B -*/
9761 strat->Bmax = setmaxL;
9762 strat->Bl = -1;
9763 strat->B = initL();
9764 /*- set T -*/
9765 strat->tl = -1;
9766 strat->tmax = setmaxT;
9767 strat->T = initT();
9768 strat->R = initR();
9769 strat->sevT = initsevT();
9770 /*- init local data struct.---------------------------------------- -*/
9771 //strat->P.ecart=0; // already by skStragy()
9772 //strat->P.length=0; // already by skStragy()
9773 //strat->P.pLength=0; // already by skStragy()
9775 {
9776 if (strat->kNoether!=NULL)
9777 {
9778 pSetComp(strat->kNoether, strat->ak);
9779 pSetComp(strat->kNoetherTail(), strat->ak);
9780 }
9781 }
9783 {
9784 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9785 }
9786 else
9787 {
9788 if(TEST_OPT_SB_1)
9789 {
9790 int i;
9791 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
9792 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9793 {
9794 P->m[i-strat->newIdeal] = F->m[i];
9795 F->m[i] = NULL;
9796 }
9797 initSSpecial(F,Q,P,strat);
9798 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9799 {
9800 F->m[i] = P->m[i-strat->newIdeal];
9801 P->m[i-strat->newIdeal] = NULL;
9802 }
9803 idDelete(&P);
9804 }
9805 else
9806 {
9807 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9808 // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
9809 }
9810 }
9811 strat->fromT = FALSE;
9813 if ((!TEST_OPT_SB_1)
9815 )
9816 {
9817 updateS(TRUE,strat);
9818 }
9819#ifdef HAVE_SHIFTBBA
9820 if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
9821#endif
9822 {
9823 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9824 strat->fromQ=NULL;
9825 }
9826 #ifdef KDEBUG
9827 assume(kTest_TS(strat));
9828 #endif
9829}
9830
9832{
9833 /*- release temp data -*/
9834 cleanT(strat);
9835 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
9836 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
9837 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
9838 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
9839 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
9840 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
9841 /*- set L: should be empty -*/
9842 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
9843 /*- set B: should be empty -*/
9844 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
9845 pLmFree(&strat->tail);
9846 strat->syzComp=0;
9847
9848#ifdef HAVE_SHIFTBBA
9849 if (rIsLPRing(currRing) && strat->rightGB)
9850 {
9851 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9852 strat->fromQ=NULL;
9853 }
9854#endif
9855}
9856
9858{
9860 {
9861 if (strat->honey)
9862 {
9863 strat->posInL = posInL15;
9864 // ok -- here is the deal: from my experiments for Singular-2-0
9865 // I conclude that that posInT_EcartpLength is the best of
9866 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9867 // see the table at the end of this file
9868 if (TEST_OPT_OLDSTD)
9869 strat->posInT = posInT15;
9870 else
9871 strat->posInT = posInT_EcartpLength;
9872 }
9873 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9874 {
9875 strat->posInL = posInL11;
9876 strat->posInT = posInT11;
9877 }
9878 else if (TEST_OPT_INTSTRATEGY)
9879 {
9880 strat->posInL = posInL11;
9881 strat->posInT = posInT11;
9882 }
9883 else
9884 {
9885 strat->posInL = posInL0;
9886 strat->posInT = posInT0;
9887 }
9888 //if (strat->minim>0) strat->posInL =posInLSpecial;
9889 if (strat->homog)
9890 {
9891 strat->posInL = posInL110;
9892 strat->posInT = posInT110;
9893 }
9894 }
9895 else
9896 {
9897 if (strat->homog)
9898 {
9899 strat->posInL = posInL11;
9900 strat->posInT = posInT11;
9901 }
9902 else
9903 {
9904 if ((currRing->order[0]==ringorder_c)
9905 ||(currRing->order[0]==ringorder_C))
9906 {
9907 strat->posInL = posInL17_c;
9908 strat->posInT = posInT17_c;
9909 }
9910 else
9911 {
9912 strat->posInL = posInL17;
9913 strat->posInT = posInT17;
9914 }
9915 }
9916 }
9917 if (strat->minim>0) strat->posInL =posInLSpecial;
9918 // for further tests only
9919 if ((BTEST1(11)) || (BTEST1(12)))
9920 strat->posInL = posInL11;
9921 else if ((BTEST1(13)) || (BTEST1(14)))
9922 strat->posInL = posInL13;
9923 else if ((BTEST1(15)) || (BTEST1(16)))
9924 strat->posInL = posInL15;
9925 else if ((BTEST1(17)) || (BTEST1(18)))
9926 strat->posInL = posInL17;
9927 if (BTEST1(11))
9928 strat->posInT = posInT11;
9929 else if (BTEST1(13))
9930 strat->posInT = posInT13;
9931 else if (BTEST1(15))
9932 strat->posInT = posInT15;
9933 else if ((BTEST1(17)))
9934 strat->posInT = posInT17;
9935 else if ((BTEST1(19)))
9936 strat->posInT = posInT19;
9937 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9938 strat->posInT = posInT1;
9940 {
9941 strat->posInL = posInL11Ring;
9942 if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
9943 strat->posInL = posInL11Ringls;
9944 strat->posInT = posInT11;
9945 }
9947 strat->posInLSba = posInLSig;
9948 //strat->posInL = posInLSig;
9949 strat->posInL = posInLF5C;
9950 /*
9951 if (rField_is_Ring(currRing))
9952 {
9953 strat->posInLSba = posInLSigRing;
9954 strat->posInL = posInL11Ring;
9955 }*/
9956 //strat->posInT = posInTSig;
9957}
9958
9960{
9961 strat->interpt = BTEST1(OPT_INTERRUPT);
9962 //strat->kNoether=NULL; // done by skStrategy
9963 /*- creating temp data structures------------------- -*/
9964 //strat->cp = 0; // done by skStrategy
9965 //strat->c3 = 0; // done by skStrategy
9966 strat->tail = pInit();
9967 /*- set s -*/
9968 strat->sl = -1;
9969 /*- set ps -*/
9970 strat->syzl = -1;
9971 /*- set L -*/
9972 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9973 strat->Ll = -1;
9974 strat->L = initL(strat->Lmax);
9975 /*- set B -*/
9976 strat->Bmax = setmaxL;
9977 strat->Bl = -1;
9978 strat->B = initL();
9979 /*- set T -*/
9980 strat->tl = -1;
9981 strat->tmax = setmaxT;
9982 strat->T = initT();
9983 strat->R = initR();
9984 strat->sevT = initsevT();
9985 /*- init local data struct.---------------------------------------- -*/
9986 //strat->P.ecart=0; // done by skStrategy
9987 //strat->P.length=0; // done by skStrategy
9989 {
9990 if (strat->kNoether!=NULL)
9991 {
9992 pSetComp(strat->kNoether, strat->ak);
9993 pSetComp(strat->kNoetherTail(), strat->ak);
9994 }
9995 }
9997 {
9998 /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
9999 }
10000 else
10001 {
10002 if(TEST_OPT_SB_1)
10003 {
10004 int i;
10005 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10006 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10007 {
10008 P->m[i-strat->newIdeal] = F->m[i];
10009 F->m[i] = NULL;
10010 }
10011 initSSpecialSba(F,Q,P,strat);
10012 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10013 {
10014 F->m[i] = P->m[i-strat->newIdeal];
10015 P->m[i-strat->newIdeal] = NULL;
10016 }
10017 idDelete(&P);
10018 }
10019 else
10020 {
10021 initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10022 }
10023 }
10024 //strat->fromT = FALSE; // done by skStrategy
10025 if (!TEST_OPT_SB_1)
10026 {
10027 if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10028 }
10029 //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10030 //strat->fromQ=NULL;
10031 assume(kTest_TS(strat));
10032}
10033
10034void exitSba (kStrategy strat)
10035{
10036 /*- release temp data -*/
10038 cleanTSbaRing(strat);
10039 else
10040 cleanT(strat);
10041 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10042 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10043 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10044 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10045 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10046 omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10047 if(strat->syzmax>0)
10048 {
10049 omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10050 omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10051 if (strat->sbaOrder == 1)
10052 {
10053 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10054 }
10055 }
10056 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10057 /*- set L: should be empty -*/
10058 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10059 /*- set B: should be empty -*/
10060 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10061 /*- set sig: no need for the signatures anymore -*/
10062 omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10063 pLmDelete(&strat->tail);
10064 strat->syzComp=0;
10065}
10066
10067/*2
10068* in the case of a standardbase of a module over a qring:
10069* replace polynomials in i by ak vectors,
10070* (the polynomial * unit vectors gen(1)..gen(ak)
10071* in every case (also for ideals:)
10072* deletes divisible vectors/polynomials
10073*/
10075{
10076 int l;
10077 if (strat->ak>0)
10078 {
10079 for (l=IDELEMS(r)-1;l>=0;l--)
10080 {
10081 if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10082 {
10083 pDelete(&r->m[l]); // and set it to NULL
10084 }
10085 }
10086 int q;
10087 poly p;
10089 {
10090 for (l=IDELEMS(r)-1;l>=0;l--)
10091 {
10092 if ((r->m[l]!=NULL)
10093 //&& (strat->syzComp>0)
10094 //&& (pGetComp(r->m[l])<=strat->syzComp)
10095 )
10096 {
10097 for(q=IDELEMS(Q)-1; q>=0;q--)
10098 {
10099 if ((Q->m[q]!=NULL)
10100 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10101 {
10102 if (TEST_OPT_REDSB)
10103 {
10104 p=r->m[l];
10105 r->m[l]=kNF(Q,NULL,p);
10106 pDelete(&p);
10107 }
10108 else
10109 {
10110 pDelete(&r->m[l]); // and set it to NULL
10111 }
10112 break;
10113 }
10114 }
10115 }
10116 }
10117 }
10118 else
10119 {
10120 for (l=IDELEMS(r)-1;l>=0;l--)
10121 {
10122 if ((r->m[l]!=NULL)
10123 //&& (strat->syzComp>0)
10124 //&& (pGetComp(r->m[l])<=strat->syzComp)
10125 )
10126 {
10127 for(q=IDELEMS(Q)-1; q>=0;q--)
10128 {
10129 if ((Q->m[q]!=NULL)
10130 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10131 {
10132 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10133 {
10134 if (TEST_OPT_REDSB)
10135 {
10136 p=r->m[l];
10137 r->m[l]=kNF(Q,NULL,p);
10138 pDelete(&p);
10139 }
10140 else
10141 {
10142 pDelete(&r->m[l]); // and set it to NULL
10143 }
10144 break;
10145 }
10146 }
10147 }
10148 }
10149 }
10150 }
10151 }
10152 else
10153 {
10154 int q;
10155 poly p;
10158 {
10159 for (l=IDELEMS(r)-1;l>=0;l--)
10160 {
10161 if (r->m[l]!=NULL)
10162 {
10163 for(q=IDELEMS(Q)-1; q>=0;q--)
10164 {
10165 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10166 {
10167 if (TEST_OPT_REDSB)
10168 {
10169 p=r->m[l];
10170 r->m[l]=kNF(Q,NULL,p);
10171 pDelete(&p);
10173 }
10174 else
10175 {
10176 pDelete(&r->m[l]); // and set it to NULL
10177 }
10178 break;
10179 }
10180 }
10181 }
10182 }
10183 }
10184 //Also need divisibility of the leading coefficients
10185 else
10186 {
10187 for (l=IDELEMS(r)-1;l>=0;l--)
10188 {
10189 if (r->m[l]!=NULL)
10190 {
10191 for(q=IDELEMS(Q)-1; q>=0;q--)
10192 {
10193 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10194 {
10195 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10196 {
10197 if (TEST_OPT_REDSB)
10198 {
10199 p=r->m[l];
10200 r->m[l]=kNF(Q,NULL,p);
10201 pDelete(&p);
10203 }
10204 else
10205 {
10206 pDelete(&r->m[l]); // and set it to NULL
10207 }
10208 break;
10209 }
10210 }
10211 }
10212 }
10213 }
10214 }
10215 if (/*TEST_OPT_REDSB &&*/ reduction_found)
10216 {
10218 {
10219 for (l=IDELEMS(r)-1;l>=0;l--)
10220 {
10221 if (r->m[l]!=NULL)
10222 {
10223 for(q=IDELEMS(r)-1;q>=0;q--)
10224 {
10225 if ((l!=q)
10226 && (r->m[q]!=NULL)
10227 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10228 &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10229 )
10230 {
10231 //If they are equal then take the one with the smallest length
10232 if(pLmDivisibleBy(r->m[q],r->m[l])
10233 && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10234 && (pLength(r->m[q]) < pLength(r->m[l]) ||
10235 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10236 {
10237 pDelete(&r->m[l]);
10238 break;
10239 }
10240 else
10241 pDelete(&r->m[q]);
10242 }
10243 }
10244 }
10245 }
10246 }
10247 else
10248 {
10249 for (l=IDELEMS(r)-1;l>=0;l--)
10250 {
10251 if (r->m[l]!=NULL)
10252 {
10253 for(q=IDELEMS(r)-1;q>=0;q--)
10254 {
10255 if ((l!=q)
10256 && (r->m[q]!=NULL)
10257 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10258 )
10259 {
10260 //If they are equal then take the one with the smallest length
10261 if(pLmDivisibleBy(r->m[q],r->m[l])
10262 &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10263 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10264 {
10265 pDelete(&r->m[l]);
10266 break;
10267 }
10268 else
10269 pDelete(&r->m[q]);
10270 }
10271 }
10272 }
10273 }
10274 }
10275 }
10276 }
10277 idSkipZeroes(r);
10278}
10279
10281{
10282 int i;
10283 int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10284 LObject L;
10285
10286#ifdef KDEBUG
10287 // need to set this: during tailreductions of T[i], T[i].max is out of
10288 // sync
10289 sloppy_max = TRUE;
10290#endif
10291
10292 strat->noTailReduction = FALSE;
10293 //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10294 if (TEST_OPT_PROT)
10295 {
10296 PrintLn();
10297// if (timerv) writeTime("standard base computed:");
10298 }
10299 if (TEST_OPT_PROT)
10300 {
10301 Print("(S:%d)",strat->sl);mflush();
10302 }
10303 for (i=strat->sl; i>=low; i--)
10304 {
10305 int end_pos=strat->sl;
10306 if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10307 if (strat->ak==0) end_pos=i-1;
10308 TObject* T_j = strat->s_2_t(i);
10309 if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10310 {
10311 L = *T_j;
10312 #ifdef KDEBUG
10313 if (TEST_OPT_DEBUG)
10314 {
10315 Print("test S[%d]:",i);
10316 p_wrp(L.p,currRing,strat->tailRing);
10317 PrintLn();
10318 }
10319 #endif
10321 strat->S[i] = redtailBba(&L, end_pos, strat, withT,FALSE /*no normalize*/);
10322 else
10323 strat->S[i] = redtail(&L, strat->sl, strat);
10324 #ifdef KDEBUG
10325 if (TEST_OPT_DEBUG)
10326 {
10327 Print("to (tailR) S[%d]:",i);
10328 p_wrp(strat->S[i],currRing,strat->tailRing);
10329 PrintLn();
10330 }
10331 #endif
10332
10333 if (strat->redTailChange)
10334 {
10335 if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10336 if (pNext(T_j->p) != NULL)
10337 T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10338 else
10339 T_j->max_exp = NULL;
10340 }
10342 T_j->pCleardenom();
10343 }
10344 else
10345 {
10346 assume(currRing == strat->tailRing);
10347 #ifdef KDEBUG
10348 if (TEST_OPT_DEBUG)
10349 {
10350 Print("test S[%d]:",i);
10351 p_wrp(strat->S[i],currRing,strat->tailRing);
10352 PrintLn();
10353 }
10354 #endif
10356 strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10357 else
10358 strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10360 {
10362 {
10363 number n;
10364 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10365 if (!nIsOne(n))
10366 {
10368 denom->n=nInvers(n);
10369 denom->next=DENOMINATOR_LIST;
10371 }
10372 nDelete(&n);
10373 }
10374 else
10375 {
10376 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10377 }
10378 }
10379 #ifdef KDEBUG
10380 if (TEST_OPT_DEBUG)
10381 {
10382 Print("to (-tailR) S[%d]:",i);
10383 p_wrp(strat->S[i],currRing,strat->tailRing);
10384 PrintLn();
10385 }
10386 #endif
10387 }
10388 if (TEST_OPT_PROT)
10389 PrintS("-");
10390 }
10391 if (TEST_OPT_PROT) PrintLn();
10392#ifdef KDEBUG
10393 sloppy_max = FALSE;
10394#endif
10395}
10396
10397
10398/*2
10399* computes the new strat->kNoether and the new pNoether,
10400* returns TRUE, if pNoether has changed
10401*/
10403{
10404 if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10405 return FALSE;
10406 int i,j;
10407 poly newNoether;
10408
10409#if 0
10410 if (currRing->weight_all_1)
10411 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10412 else
10413 scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kNoether);
10414#else
10415 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10416#endif
10417 if (strat->kNoether==NULL) return FALSE;
10418 if (strat->t_kNoether != NULL)
10419 {
10420 p_LmFree(strat->t_kNoether, strat->tailRing);
10421 strat->t_kNoether=NULL;
10422 }
10423 if (strat->tailRing != currRing)
10425 /* compare old and new noether*/
10426 newNoether = pLmInit(strat->kNoether);
10429 // newNoether is now the new highest edge (on the boundary)
10430 // now find the next monomial after highest monomial in R/I
10431 // (the smallest monomial not in R/I)
10432 for (i=currRing->N-1;i>0; i--)
10433 {
10434 int e;
10435 if ((e=pGetExp(newNoether, i)) > 0)
10436 {
10437 e--;
10438 pSetExp(newNoether,i,e);
10439 }
10440 }
10442 if (j < HCord) /*- statistics -*/
10443 {
10444 if (TEST_OPT_PROT)
10445 {
10446 Print("H(%d)",j);
10447 mflush();
10448 }
10449 HCord=j;
10450 #ifdef KDEBUG
10451 if (TEST_OPT_DEBUG)
10452 {
10453 Print("H(%d):",j);
10454 wrp(strat->kNoether);
10455 PrintLn();
10456 }
10457 #endif
10458 }
10459 if (pCmp(strat->kNoether,newNoether)!=1)
10460 {
10461 if (strat->kNoether!=NULL) p_LmDelete0(strat->kNoether,currRing);
10462 strat->kNoether=newNoether;
10463 if (strat->t_kNoether != NULL)
10464 {
10465 p_LmFree(strat->t_kNoether, strat->tailRing);
10466 strat->t_kNoether=NULL;
10467 }
10468 if (strat->tailRing != currRing)
10470
10471 return TRUE;
10472 }
10474 return FALSE;
10475}
10476
10477/***************************************************************
10478 *
10479 * Routines related for ring changes during std computations
10480 *
10481 ***************************************************************/
10482BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10483{
10484 if (strat->overflow) return FALSE;
10485 assume(L->p1 != NULL && L->p2 != NULL);
10486 // shift changes: from 0 to -1
10487 assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10488 assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10489
10490 if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10491 return FALSE;
10492 // shift changes: extra case inserted
10493 if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10494 {
10495 return TRUE;
10496 }
10497 poly p1_max=NULL;
10498 if ((L->i_r1>=0)&&(strat->R[L->i_r1]!=NULL)) p1_max = (strat->R[L->i_r1])->max_exp;
10499 poly p2_max=NULL;
10500 if ((L->i_r2>=0)&&(strat->R[L->i_r2]!=NULL)) p2_max = (strat->R[L->i_r2])->max_exp;
10501
10502 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10503 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10504 {
10505 p_LmFree(m1, strat->tailRing);
10506 p_LmFree(m2, strat->tailRing);
10507 m1 = NULL;
10508 m2 = NULL;
10509 return FALSE;
10510 }
10511 return TRUE;
10512}
10513
10514/***************************************************************
10515 *
10516 * Checks, if we can compute the gcd poly / strong pair
10517 * gcd-poly = m1 * R[atR] + m2 * S[atS]
10518 *
10519 ***************************************************************/
10520BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10521{
10522 assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10523 //assume(strat->tailRing != currRing);
10524
10525 poly p1_max = (strat->R[atR])->max_exp;
10526 poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10527
10528 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10529 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10530 {
10531 return FALSE;
10532 }
10533 return TRUE;
10534}
10535
10536/*!
10537 used for GB over ZZ: look for constant and monomial elements in the ideal
10538 background: any known constant element of ideal suppresses
10539 intermediate coefficient swell
10540*/
10542{
10544 ideal F = idCopy(Forig);
10545 idSkipZeroes(F);
10546 poly pmon;
10548 ideal monred = idInit(1,1);
10549 for(int i=0; i<idElem(F); i++)
10550 {
10551 if(pNext(F->m[i]) == NULL)
10552 idInsertPoly(monred, pCopy(F->m[i]));
10553 }
10554 int posconst = idPosConstant(F);
10555 if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10556 {
10557 idDelete(&F);
10558 idDelete(&monred);
10559 return NULL;
10560 }
10561 int idelemQ = 0;
10562 if(Q!=NULL)
10563 {
10564 idelemQ = IDELEMS(Q);
10565 for(int i=0; i<idelemQ; i++)
10566 {
10567 if(pNext(Q->m[i]) == NULL)
10568 idInsertPoly(monred, pCopy(Q->m[i]));
10569 }
10572 //the constant, if found, will be from Q
10573 if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10574 {
10575 pmon = pCopy(monred->m[posconst]);
10576 idDelete(&F);
10577 idDelete(&monred);
10578 return pmon;
10579 }
10580 }
10582 nKillChar(QQ_ring->cf);
10583 QQ_ring->cf = nInitChar(n_Q, NULL);
10584 rComplete(QQ_ring,1);
10587 nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10589 for(int i = 0, j = 0; i<IDELEMS(F); i++)
10590 II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10591 for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10592 II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10594 idSkipZeroes(one);
10595 if(idIsConstant(one))
10596 {
10597 //one should be <1>
10598 for(int i = IDELEMS(II)-1; i>=0; i--)
10599 if(II->m[i] != NULL)
10600 II->m[i+1] = II->m[i];
10601 II->m[0] = pOne();
10603 poly integer = NULL;
10604 for(int i = IDELEMS(syz)-1;i>=0; i--)
10605 {
10606 if(pGetComp(syz->m[i]) == 1)
10607 {
10608 pSetComp(syz->m[i],0);
10609 if(pIsConstant(pHead(syz->m[i])))
10610 {
10611 integer = pHead(syz->m[i]);
10612 break;
10613 }
10614 }
10615 }
10617 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10619 idDelete(&monred);
10620 idDelete(&F);
10622 id_Delete(&one,QQ_ring);
10623 id_Delete(&syz,QQ_ring);
10626 return pmon;
10627 }
10628 else
10629 {
10630 if(idIs0(monred))
10631 {
10632 poly mindegmon = NULL;
10633 for(int i = 0; i<IDELEMS(one); i++)
10634 {
10635 if(pNext(one->m[i]) == NULL)
10636 {
10637 if(mindegmon == NULL)
10638 mindegmon = pCopy(one->m[i]);
10639 else
10640 {
10641 if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10642 mindegmon = pCopy(one->m[i]);
10643 }
10644 }
10645 }
10646 if(mindegmon != NULL)
10647 {
10648 for(int i = IDELEMS(II)-1; i>=0; i--)
10649 if(II->m[i] != NULL)
10650 II->m[i+1] = II->m[i];
10651 II->m[0] = pCopy(mindegmon);
10653 bool found = FALSE;
10654 for(int i = IDELEMS(syz)-1;i>=0; i--)
10655 {
10656 if(pGetComp(syz->m[i]) == 1)
10657 {
10658 pSetComp(syz->m[i],0);
10659 if(pIsConstant(pHead(syz->m[i])))
10660 {
10661 pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10662 found = TRUE;
10663 break;
10664 }
10665 }
10666 }
10667 id_Delete(&syz,QQ_ring);
10668 if (found == FALSE)
10669 {
10671 idDelete(&monred);
10672 idDelete(&F);
10674 id_Delete(&one,QQ_ring);
10676 return NULL;
10677 }
10679 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10681 idDelete(&monred);
10682 idDelete(&F);
10684 id_Delete(&one,QQ_ring);
10685 id_Delete(&syz,QQ_ring);
10687 return pmon;
10688 }
10689 }
10690 }
10692 idDelete(&monred);
10693 idDelete(&F);
10695 id_Delete(&one,QQ_ring);
10697 return NULL;
10698}
10699
10700/*!
10701 used for GB over ZZ: intermediate reduction by monomial elements
10702 background: any known constant element of ideal suppresses
10703 intermediate coefficient swell
10704*/
10706{
10707 if(!nCoeff_is_Z(currRing->cf))
10708 return;
10709 poly pH = h->GetP();
10710 poly p,pp;
10711 p = pH;
10712 bool deleted = FALSE, ok = FALSE;
10713 for(int i = 0; i<=strat->sl; i++)
10714 {
10715 p = pH;
10716 if(pNext(strat->S[i]) == NULL)
10717 {
10718 //pWrite(p);
10719 //pWrite(strat->S[i]);
10720 while(ok == FALSE && p != NULL)
10721 {
10722 if(pLmDivisibleBy(strat->S[i], p)
10724 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], p))
10725#endif
10726 )
10727 {
10728 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10730 }
10731 if(nIsZero(p->coef))
10732 {
10733 pLmDelete(&p);
10734 h->p = p;
10735 deleted = TRUE;
10736 }
10737 else
10738 {
10739 ok = TRUE;
10740 }
10741 }
10742 if (p!=NULL)
10743 {
10744 pp = pNext(p);
10745 while(pp != NULL)
10746 {
10747 if(pLmDivisibleBy(strat->S[i], pp)
10749 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], pp))
10750#endif
10751 )
10752 {
10753 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10755 if(nIsZero(pp->coef))
10756 {
10757 pLmDelete(&pNext(p));
10758 pp = pNext(p);
10759 deleted = TRUE;
10760 }
10761 else
10762 {
10763 p = pp;
10764 pp = pNext(p);
10765 }
10766 }
10767 else
10768 {
10769 p = pp;
10770 pp = pNext(p);
10771 }
10772 }
10773 }
10774 }
10775 }
10776 h->SetLmCurrRing();
10777 if((deleted)&&(h->p!=NULL))
10778 strat->initEcart(h);
10779}
10780
10782{
10783 if(!nCoeff_is_Z(currRing->cf))
10784 return;
10785 poly hSig = h->sig;
10786 poly pH = h->GetP();
10787 poly p,pp;
10788 p = pH;
10789 bool deleted = FALSE, ok = FALSE;
10790 for(int i = 0; i<=strat->sl; i++)
10791 {
10792 p = pH;
10793 if(pNext(strat->S[i]) == NULL)
10794 {
10795 while(ok == FALSE && p!=NULL)
10796 {
10797 if(pLmDivisibleBy(strat->S[i], p))
10798 {
10799 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10800 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10801 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10802 {
10803 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10805 }
10806 pDelete(&sigMult);
10807 }
10808 if(nIsZero(p->coef))
10809 {
10810 pLmDelete(&p);
10811 h->p = p;
10812 deleted = TRUE;
10813 }
10814 else
10815 {
10816 ok = TRUE;
10817 }
10818 }
10819 if(p == NULL)
10820 return;
10821 pp = pNext(p);
10822 while(pp != NULL)
10823 {
10824 if(pLmDivisibleBy(strat->S[i], pp))
10825 {
10826 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10827 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10828 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10829 {
10830 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10832 if(nIsZero(pp->coef))
10833 {
10834 pLmDelete(&pNext(p));
10835 pp = pNext(p);
10836 deleted = TRUE;
10837 }
10838 else
10839 {
10840 p = pp;
10841 pp = pNext(p);
10842 }
10843 }
10844 else
10845 {
10846 p = pp;
10847 pp = pNext(p);
10848 }
10849 pDelete(&sigMult);
10850 }
10851 else
10852 {
10853 p = pp;
10854 pp = pNext(p);
10855 }
10856 }
10857 }
10858 }
10859 h->SetLmCurrRing();
10860 if(deleted)
10861 strat->initEcart(h);
10862
10863}
10864
10865/*!
10866 used for GB over ZZ: final reduction by constant elements
10867 background: any known constant element of ideal suppresses
10868 intermediate coefficient swell and beautifies output
10869*/
10871{
10872 assume(strat->tl<0); /* can only be called with no elements in T:
10873 i.e. after exitBuchMora */
10874 /* do not use strat->S, strat->sl as they may be out of sync*/
10875 if(!nCoeff_is_Z(currRing->cf))
10876 return;
10877 poly p,pp;
10878 for(int j = 0; j<IDELEMS(strat->Shdl); j++)
10879 {
10880 if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
10881 {
10882 for(int i = 0; i<IDELEMS(strat->Shdl); i++)
10883 {
10884 if((i != j) && (strat->Shdl->m[i] != NULL))
10885 {
10886 p = strat->Shdl->m[i];
10887 while((p!=NULL) && (pLmDivisibleBy(strat->Shdl->m[j], p)
10888#if HAVE_SHIFTBBA
10889 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], p))
10890#endif
10891 ))
10892 {
10893 number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
10894 if (!nEqual(dummy,p->coef))
10895 {
10896 if (nIsZero(dummy))
10897 {
10898 nDelete(&dummy);
10899 pLmDelete(&strat->Shdl->m[i]);
10900 p=strat->Shdl->m[i];
10901 }
10902 else
10903 {
10905 break;
10906 }
10907 }
10908 else
10909 {
10910 nDelete(&dummy);
10911 break;
10912 }
10913 }
10914 if (p!=NULL)
10915 {
10916 pp = pNext(p);
10917 while(pp != NULL)
10918 {
10919 if(pLmDivisibleBy(strat->Shdl->m[j], pp)
10920#if HAVE_SHIFTBBA
10921 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], pp))
10922#endif
10923 )
10924 {
10925 number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
10926 if (!nEqual(dummy,pp->coef))
10927 {
10929 if(nIsZero(pp->coef))
10930 {
10931 pLmDelete(&pNext(p));
10932 pp = pNext(p);
10933 }
10934 else
10935 {
10936 p = pp;
10937 pp = pNext(p);
10938 }
10939 }
10940 else
10941 {
10942 nDelete(&dummy);
10943 p = pp;
10944 pp = pNext(p);
10945 }
10946 }
10947 else
10948 {
10949 p = pp;
10950 pp = pNext(p);
10951 }
10952 }
10953 }
10954 }
10955 }
10956 //idPrint(strat->Shdl);
10957 }
10958 }
10959 idSkipZeroes(strat->Shdl);
10960}
10961
10963{
10964 assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
10965 /* initial setup or extending */
10966
10967 if (rIsLPRing(currRing)) return TRUE;
10968 if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
10969 if (expbound >= currRing->bitmask) return FALSE;
10970 strat->overflow=FALSE;
10972 // Hmmm .. the condition pFDeg == p_Deg
10973 // might be too strong
10974 (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
10975 (strat->ak==0), // omit_comp if the input is an ideal
10976 expbound); // exp_limit
10977
10978 if (new_tailRing == currRing) return TRUE;
10979
10980 strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
10981 strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
10982
10983 if (currRing->pFDeg != currRing->pFDegOrig)
10984 {
10985 new_tailRing->pFDeg = currRing->pFDeg;
10986 new_tailRing->pLDeg = currRing->pLDeg;
10987 }
10988
10989 if (TEST_OPT_PROT)
10990 Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
10991 #ifdef KDEBUG
10992 kTest_TS(strat);
10993 assume(new_tailRing != strat->tailRing);
10994 #endif
10995 pShallowCopyDeleteProc p_shallow_copy_delete
10997
10999
11000 int i;
11001 for (i=0; i<=strat->tl; i++)
11002 {
11003 strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11004 p_shallow_copy_delete);
11005 }
11006 for (i=0; i<=strat->Ll; i++)
11007 {
11008 assume(strat->L[i].p != NULL);
11009 if (pNext(strat->L[i].p) != strat->tail)
11010 strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11011 }
11012 if ((strat->P.t_p != NULL) ||
11013 ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11014 strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11015
11016 if ((L != NULL) && (L->tailRing != new_tailRing))
11017 {
11018 if (L->i_r < 0)
11019 L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11020 else
11021 {
11022 assume(L->i_r <= strat->tl);
11023 TObject* t_l = strat->R[L->i_r];
11024 assume(t_l != NULL);
11025 L->tailRing = new_tailRing;
11026 L->p = t_l->p;
11027 L->t_p = t_l->t_p;
11028 L->max_exp = t_l->max_exp;
11029 }
11030 }
11031
11032 if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11033 T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11034
11035 omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11036 if (strat->tailRing != currRing)
11038
11039 strat->tailRing = new_tailRing;
11040 strat->tailBin = new_tailBin;
11043
11044 if (strat->kNoether != NULL)
11045 {
11046 if (strat->t_kNoether != NULL)
11047 p_LmFree(strat->t_kNoether, strat->tailRing);
11049 }
11050
11051 #ifdef KDEBUG
11052 kTest_TS(strat);
11053 #endif
11054 if (TEST_OPT_PROT)
11055 PrintS("]");
11056 return TRUE;
11057}
11058
11060{
11061 unsigned long l = 0;
11062 int i;
11063 long e;
11064
11065 assume(strat->tailRing == currRing);
11066
11067 for (i=0; i<= strat->Ll; i++)
11068 {
11069 l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11070 }
11071 for (i=0; i<=strat->tl; i++)
11072 {
11073 // Hmm ... this we could do in one Step
11074 l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11075 }
11077 {
11078 l *= 2;
11079 }
11080 e = p_GetMaxExp(l, currRing);
11081 if (e <= 1) e = 2;
11082 if (rIsLPRing(currRing)) e = 1;
11083
11084 kStratChangeTailRing(strat, NULL, NULL, e);
11085}
11086
11087ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11088{
11089 int n = rBlocks(r); // Including trailing zero!
11090 // if sbaOrder == 1 => use (C,monomial order from r)
11091 if (strat->sbaOrder == 1)
11092 {
11093 if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11094 {
11095 return r;
11096 }
11097 ring res = rCopy0(r, TRUE, FALSE);
11098 res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11099 res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11100 res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11101 int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11102 res->wvhdl = wvhdl;
11103 for (int i=1; i<n; i++)
11104 {
11105 res->order[i] = r->order[i-1];
11106 res->block0[i] = r->block0[i-1];
11107 res->block1[i] = r->block1[i-1];
11108 res->wvhdl[i] = r->wvhdl[i-1];
11109 }
11110
11111 // new 1st block
11112 res->order[0] = ringorder_C; // Prefix
11113 // removes useless secondary component order if defined in old ring
11114 for (int i=rBlocks(res); i>0; --i)
11115 {
11116 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11117 {
11118 res->order[i] = (rRingOrder_t)0;
11119 }
11120 }
11121 rComplete(res, 1);
11122#ifdef HAVE_PLURAL
11123 if (rIsPluralRing(r))
11124 {
11125 if ( nc_rComplete(r, res, false) ) // no qideal!
11126 {
11127#ifndef SING_NDEBUG
11128 WarnS("error in nc_rComplete");
11129#endif
11130 // cleanup?
11131
11132 // rDelete(res);
11133 // return r;
11134
11135 // just go on..
11136 }
11137 }
11138#endif
11139 strat->tailRing = res;
11140 return (res);
11141 }
11142 // if sbaOrder == 3 => degree - position - ring order
11143 if (strat->sbaOrder == 3)
11144 {
11145 ring res = rCopy0(r, TRUE, FALSE);
11146 res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11147 res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11148 res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11149 int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11150 res->wvhdl = wvhdl;
11151 for (int i=2; i<n+2; i++)
11152 {
11153 res->order[i] = r->order[i-2];
11154 res->block0[i] = r->block0[i-2];
11155 res->block1[i] = r->block1[i-2];
11156 res->wvhdl[i] = r->wvhdl[i-2];
11157 }
11158
11159 // new 1st block
11160 res->order[0] = ringorder_a; // Prefix
11161 res->block0[0] = 1;
11162 res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11163 for (int i=0; i<res->N; ++i)
11164 res->wvhdl[0][i] = 1;
11165 res->block1[0] = si_min(res->N, rVar(res));
11166 // new 2nd block
11167 res->order[1] = ringorder_C; // Prefix
11168 res->wvhdl[1] = NULL;
11169 // removes useless secondary component order if defined in old ring
11170 for (int i=rBlocks(res); i>1; --i)
11171 {
11172 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11173 {
11174 res->order[i] = (rRingOrder_t)0;
11175 }
11176 }
11177 rComplete(res, 1);
11178#ifdef HAVE_PLURAL
11179 if (rIsPluralRing(r))
11180 {
11181 if ( nc_rComplete(r, res, false) ) // no qideal!
11182 {
11183#ifndef SING_NDEBUG
11184 WarnS("error in nc_rComplete");
11185#endif
11186 // cleanup?
11187
11188 // rDelete(res);
11189 // return r;
11190
11191 // just go on..
11192 }
11193 }
11194#endif
11195 strat->tailRing = res;
11196 return (res);
11197 }
11198
11199 // not sbaOrder == 1 => use Schreyer order
11200 // this is done by a trick when initializing the signatures
11201 // in initSLSba():
11202 // Instead of using the signature 1e_i for F->m[i], we start
11203 // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11204 // Schreyer order w.r.t. the underlying monomial order.
11205 // => we do not need to change the underlying polynomial ring at all!
11206
11207 // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11208
11209 /*
11210 else
11211 {
11212 ring res = rCopy0(r, FALSE, FALSE);
11213 // Create 2 more blocks for prefix/suffix:
11214 res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11215 res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11216 res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11217 int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11218
11219 // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11220 // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11221
11222 // new 1st block
11223 int j = 0;
11224 res->order[j] = ringorder_IS; // Prefix
11225 res->block0[j] = res->block1[j] = 0;
11226 // wvhdl[j] = NULL;
11227 j++;
11228
11229 for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11230 {
11231 res->order [j] = r->order [i];
11232 res->block0[j] = r->block0[i];
11233 res->block1[j] = r->block1[i];
11234
11235 if (r->wvhdl[i] != NULL)
11236 {
11237 wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11238 } // else wvhdl[j] = NULL;
11239 }
11240
11241 // new last block
11242 res->order [j] = ringorder_IS; // Suffix
11243 res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11244 // wvhdl[j] = NULL;
11245 j++;
11246
11247 // res->order [j] = 0; // The End!
11248 res->wvhdl = wvhdl;
11249
11250 // j == the last zero block now!
11251 assume(j == (n+1));
11252 assume(res->order[0]==ringorder_IS);
11253 assume(res->order[j-1]==ringorder_IS);
11254 assume(res->order[j]==0);
11255
11256 if (complete)
11257 {
11258 rComplete(res, 1);
11259
11260#ifdef HAVE_PLURAL
11261 if (rIsPluralRing(r))
11262 {
11263 if ( nc_rComplete(r, res, false) ) // no qideal!
11264 {
11265 }
11266 }
11267 assume(rIsPluralRing(r) == rIsPluralRing(res));
11268#endif
11269
11270
11271#ifdef HAVE_PLURAL
11272 ring old_ring = r;
11273
11274#endif
11275
11276 if (r->qideal!=NULL)
11277 {
11278 res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11279
11280 assume(idRankFreeModule(res->qideal, res) == 0);
11281
11282#ifdef HAVE_PLURAL
11283 if( rIsPluralRing(res) )
11284 if( nc_SetupQuotient(res, r, true) )
11285 {
11286 // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11287 }
11288
11289#endif
11290 assume(idRankFreeModule(res->qideal, res) == 0);
11291 }
11292
11293#ifdef HAVE_PLURAL
11294 assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11295 assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11296 assume(rIsSCA(res) == rIsSCA(old_ring));
11297 assume(ncRingType(res) == ncRingType(old_ring));
11298#endif
11299 }
11300 strat->tailRing = res;
11301 return res;
11302 }
11303 */
11304
11305 assume(FALSE);
11306 return(NULL);
11307}
11308
11310{
11311 memset(this, 0, sizeof(skStrategy));
11312 strat_nr++;
11313 nr=strat_nr;
11315 P.tailRing = currRing;
11316 tl = -1;
11317 sl = -1;
11318#ifdef HAVE_LM_BIN
11320#endif
11321#ifdef HAVE_TAIL_BIN
11323#endif
11324 pOrigFDeg = currRing->pFDeg;
11325 pOrigLDeg = currRing->pLDeg;
11326}
11327
11328
11330{
11332 if (lmBin != NULL)
11334 if (tailBin != NULL)// && !rField_is_Ring(currRing))
11336 ((tailRing != NULL) ? tailRing->PolyBin:
11337 currRing->PolyBin));
11338 if (t_kNoether != NULL)
11340
11341 if (currRing != tailRing)
11344}
11345
11346#if 0
11348 T15 EDL DL EL L 1-2-3
11349Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11350Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11351Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11352ahml 4.48 4.03 4.03 4.38 4.96 26.50
11353c7 15.02 13.98 15.16 13.24 17.31 47.89
11354c8 505.09 407.46 852.76 413.21 499.19 n/a
11355f855 12.65 9.27 14.97 8.78 14.23 33.12
11356gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11357gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11358ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11359noon8 40.68 37.02 37.99 36.82 35.59 877.16
11360rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11361rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11362schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11363test016 16.39 14.17 14.40 13.50 14.26 34.07
11364test017 34.70 36.01 33.16 35.48 32.75 71.45
11365test042 10.76 10.99 10.27 11.57 10.45 23.04
11366test058 6.78 6.75 6.51 6.95 6.22 9.47
11367test066 10.71 10.94 10.76 10.61 10.56 19.06
11368test073 10.75 11.11 10.17 10.79 8.63 58.10
11369test086 12.23 11.81 12.88 12.24 13.37 66.68
11370test103 5.05 4.80 5.47 4.64 4.89 11.90
11371test154 12.96 11.64 13.51 12.46 14.61 36.35
11372test162 65.27 64.01 67.35 59.79 67.54 196.46
11373test164 7.50 6.50 7.68 6.70 7.96 17.13
11374virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11375#endif
11376
11377
11378//#ifdef HAVE_MORE_POS_IN_T
11379#if 1
11380// determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11382{
11383
11384 if (length==-1) return 0;
11385
11386 int o = p.ecart;
11387 int op=p.GetpFDeg();
11388 int ol = p.GetpLength();
11389
11390 if (set[length].ecart < o)
11391 return length+1;
11392 if (set[length].ecart == o)
11393 {
11394 int oo=set[length].GetpFDeg();
11395 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11396 return length+1;
11397 }
11398
11399 int i;
11400 int an = 0;
11401 int en= length;
11402 loop
11403 {
11404 if (an >= en-1)
11405 {
11406 if (set[an].ecart > o)
11407 return an;
11408 if (set[an].ecart == o)
11409 {
11410 int oo=set[an].GetpFDeg();
11411 if((oo > op)
11412 || ((oo==op) && (set[an].pLength > ol)))
11413 return an;
11414 }
11415 return en;
11416 }
11417 i=(an+en) / 2;
11418 if (set[i].ecart > o)
11419 en=i;
11420 else if (set[i].ecart == o)
11421 {
11422 int oo=set[i].GetpFDeg();
11423 if ((oo > op)
11424 || ((oo == op) && (set[i].pLength > ol)))
11425 en=i;
11426 else
11427 an=i;
11428 }
11429 else
11430 an=i;
11431 }
11432}
11433
11434// determines the position based on: 1.) FDeg 2.) pLength
11435int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11436{
11437
11438 if (length==-1) return 0;
11439
11440 int op=p.GetpFDeg();
11441 int ol = p.GetpLength();
11442
11443 int oo=set[length].GetpFDeg();
11444 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11445 return length+1;
11446
11447 int i;
11448 int an = 0;
11449 int en= length;
11450 loop
11451 {
11452 if (an >= en-1)
11453 {
11454 int oo=set[an].GetpFDeg();
11455 if((oo > op)
11456 || ((oo==op) && (set[an].pLength > ol)))
11457 return an;
11458 return en;
11459 }
11460 i=(an+en) / 2;
11461 int oo=set[i].GetpFDeg();
11462 if ((oo > op)
11463 || ((oo == op) && (set[i].pLength > ol)))
11464 en=i;
11465 else
11466 an=i;
11467 }
11468}
11469
11470
11471// determines the position based on: 1.) pLength
11472int posInT_pLength(const TSet set,const int length,LObject &p)
11473{
11474 int ol = p.GetpLength();
11475 if (length==-1)
11476 return 0;
11477 if (set[length].length<p.length)
11478 return length+1;
11479
11480 int i;
11481 int an = 0;
11482 int en= length;
11483
11484 loop
11485 {
11486 if (an >= en-1)
11487 {
11488 if (set[an].pLength>ol) return an;
11489 return en;
11490 }
11491 i=(an+en) / 2;
11492 if (set[i].pLength>ol) en=i;
11493 else an=i;
11494 }
11495}
11496#endif
11497
11498// ../Singular/misc.cc:
11499extern char * showOption();
11500
11502{
11503 printf("red: ");
11504 if (strat->red==redFirst) printf("redFirst\n");
11505 else if (strat->red==redHoney) printf("redHoney\n");
11506 else if (strat->red==redEcart) printf("redEcart\n");
11507 else if (strat->red==redHomog) printf("redHomog\n");
11508 else if (strat->red==redLazy) printf("redLazy\n");
11509 else if (strat->red==redLiftstd) printf("redLiftstd\n");
11510 else printf("%p\n",(void*)strat->red);
11511 printf("posInT: ");
11512 if (strat->posInT==posInT0) printf("posInT0\n");
11513 else if (strat->posInT==posInT1) printf("posInT1\n");
11514 else if (strat->posInT==posInT11) printf("posInT11\n");
11515 else if (strat->posInT==posInT110) printf("posInT110\n");
11516 else if (strat->posInT==posInT13) printf("posInT13\n");
11517 else if (strat->posInT==posInT15) printf("posInT15\n");
11518 else if (strat->posInT==posInT17) printf("posInT17\n");
11519 else if (strat->posInT==posInT17_c) printf("posInT17_c\n");
11520 else if (strat->posInT==posInT19) printf("posInT19\n");
11521 else if (strat->posInT==posInT2) printf("posInT2\n");
11522 else if (strat->posInT==posInT11Ring) printf("posInT11Ring\n");
11523 else if (strat->posInT==posInT110Ring) printf("posInT110Ring\n");
11524 else if (strat->posInT==posInT15Ring) printf("posInT15Ring\n");
11525 else if (strat->posInT==posInT17Ring) printf("posInT17Ring\n");
11526 else if (strat->posInT==posInT17_cRing) printf("posInT17_cRing\n");
11527#ifdef HAVE_MORE_POS_IN_T
11528 else if (strat->posInT==posInT_EcartFDegpLength) printf("posInT_EcartFDegpLength\n");
11529 else if (strat->posInT==posInT_FDegpLength) printf("posInT_FDegpLength\n");
11530 else if (strat->posInT==posInT_pLength) printf("posInT_pLength\n");
11531#endif
11532 else if (strat->posInT==posInT_EcartpLength) printf("posInT_EcartpLength\n");
11533 else printf("%p\n",(void*)strat->posInT);
11534 printf("posInL: ");
11535 if (strat->posInL==posInL0) printf("posInL0\n");
11536 else if (strat->posInL==posInL10) printf("posInL10\n");
11537 else if (strat->posInL==posInL11) printf("posInL11\n");
11538 else if (strat->posInL==posInL110) printf("posInL110\n");
11539 else if (strat->posInL==posInL13) printf("posInL13\n");
11540 else if (strat->posInL==posInL15) printf("posInL15\n");
11541 else if (strat->posInL==posInL17) printf("posInL17\n");
11542 else if (strat->posInL==posInL17_c) printf("posInL17_c\n");
11543 else if (strat->posInL==posInL0) printf("posInL0Ring\n");
11544 else if (strat->posInL==posInL11Ring) printf("posInL11Ring\n");
11545 else if (strat->posInL==posInL11Ringls) printf("posInL11Ringls\n");
11546 else if (strat->posInL==posInL110Ring) printf("posInL110Ring\n");
11547 else if (strat->posInL==posInL15Ring) printf("posInL15Ring\n");
11548 else if (strat->posInL==posInL17Ring) printf("posInL17Ring\n");
11549 else if (strat->posInL==posInL17_cRing) printf("posInL17_cRing\n");
11550 else if (strat->posInL==posInLSpecial) printf("posInLSpecial\n");
11551 else printf("%p\n",(void*)strat->posInL);
11552 printf("enterS: ");
11553 if (strat->enterS==enterSBba) printf("enterSBba\n");
11554 else if (strat->enterS==enterSMora) printf("enterSMora\n");
11555 else if (strat->enterS==enterSMoraNF) printf("enterSMoraNF\n");
11556 else printf("%p\n",(void*)strat->enterS);
11557 printf("initEcart: ");
11558 if (strat->initEcart==initEcartBBA) printf("initEcartBBA\n");
11559 else if (strat->initEcart==initEcartNormal) printf("initEcartNormal\n");
11560 else printf("%p\n",(void*)strat->initEcart);
11561 printf("initEcartPair: ");
11562 if (strat->initEcartPair==initEcartPairBba) printf("initEcartPairBba\n");
11563 else if (strat->initEcartPair==initEcartPairMora) printf("initEcartPairMora\n");
11564 else printf("%p\n",(void*)strat->initEcartPair);
11565 printf("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11566 strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11567 printf("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11568 strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11569 printf("chainCrit: ");
11570 if (strat->chainCrit==chainCritNormal) printf("chainCritNormal\n");
11571 else if (strat->chainCrit==chainCritOpt_1) printf("chainCritOpt_1\n");
11572 else printf("%p\n",(void*)strat->chainCrit);
11573 printf("posInLDependsOnLength=%d\n",
11574 strat->posInLDependsOnLength);
11575 printf("%s\n",showOption());
11576 printf("LDeg: ");
11577 if (currRing->pLDeg==pLDeg0) printf("pLDeg0");
11578 else if (currRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11579 else if (currRing->pLDeg==pLDegb) printf("pLDegb");
11580 else if (currRing->pLDeg==pLDeg1) printf("pLDeg1");
11581 else if (currRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11582 else if (currRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11583 else if (currRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11584 else if (currRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11585 else if (currRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11586 else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11587 else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11588 else if (currRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11589 else printf("? (%lx)", (long)currRing->pLDeg);
11590 printf(" / ");
11591 if (strat->tailRing->pLDeg==pLDeg0) printf("pLDeg0");
11592 else if (strat->tailRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11593 else if (strat->tailRing->pLDeg==pLDegb) printf("pLDegb");
11594 else if (strat->tailRing->pLDeg==pLDeg1) printf("pLDeg1");
11595 else if (strat->tailRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11596 else if (strat->tailRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11597 else if (strat->tailRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11598 else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11599 else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11600 else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11601 else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11602 else if (strat->tailRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11603 else printf("? (%lx)", (long)strat->tailRing->pLDeg);
11604 printf("\n");
11605 printf("currRing->pFDeg: ");
11606 if (currRing->pFDeg==p_Totaldegree) printf("p_Totaldegree");
11607 else if (currRing->pFDeg==p_WFirstTotalDegree) printf("pWFirstTotalDegree");
11608 else if (currRing->pFDeg==p_Deg) printf("p_Deg");
11609 else if (currRing->pFDeg==kHomModDeg) printf("kHomModDeg");
11610 else if (currRing->pFDeg==kModDeg) printf("kModDeg");
11611 else if (currRing->pFDeg==totaldegreeWecart) printf("totaldegreeWecart");
11612 else if (currRing->pFDeg==p_WTotaldegree) printf("p_WTotaldegree");
11613 else printf("? (%lx)", (long)currRing->pFDeg);
11614 printf("\n");
11615 printf(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11617 printf(" degBound: %d\n", Kstd1_deg);
11618
11619 if( ecartWeights != NULL )
11620 {
11621 printf("ecartWeights: ");
11622 for (int i = rVar(currRing); i > 0; i--)
11623 printf("%hd ", ecartWeights[i]);
11624 printf("\n");
11626 }
11627
11628#ifndef SING_NDEBUG
11630#endif
11631}
11632
11633//LObject pCopyp2L(poly p, kStrategy strat)
11634//{
11635 /* creates LObject from the poly in currRing */
11636 /* actually put p into L.p and make L.t_p=NULL : does not work */
11637
11638//}
11639
11640/*2
11641* put the lcm(q,p) into the set B, q is the shift of some s[i]
11642*/
11643#ifdef HAVE_SHIFTBBA
11644static BOOLEAN enterOneStrongPolyShift (poly q, poly p, int /*ecart*/, int /*isFromQ*/, kStrategy strat, int atR, int /*ecartq*/, int /*qisFromQ*/, int shiftcount, int ifromS)
11645{
11646 number d, s, t;
11647 /* assume(atR >= 0); */
11650 poly m1, m2, gcd;
11651 //printf("\n--------------------------------\n");
11652 //pWrite(p);pWrite(si);
11653 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q), &s, &t, currRing->cf);
11654
11655 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
11656 {
11657 nDelete(&d);
11658 nDelete(&s);
11659 nDelete(&t);
11660 return FALSE;
11661 }
11662
11663 assume(pIsInV(p));
11664
11665 k_GetStrongLeadTerms(p, q, currRing, m1, m2, gcd, strat->tailRing);
11666
11667 /* the V criterion */
11668 if (!pmIsInV(gcd))
11669 {
11670 strat->cv++;
11671 nDelete(&d);
11672 nDelete(&s);
11673 nDelete(&t);
11674 pLmFree(gcd);
11675 return FALSE;
11676 }
11677
11678 // disabled for Letterplace because it is not so easy to check
11679 /* if (!rHasLocalOrMixedOrdering(currRing)) { */
11680 /* unsigned long sev = pGetShortExpVector(gcd); */
11681
11682 /* for (int j = 0; j < strat->sl; j++) { */
11683 /* if (j == i) */
11684 /* continue; */
11685
11686 /* if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) && */
11687 /* !(strat->sevS[j] & ~sev) && */
11688 /* p_LmDivisibleBy(strat->S[j], gcd, currRing)) { */
11689 /* nDelete(&d); */
11690 /* nDelete(&s); */
11691 /* nDelete(&t); */
11692 /* return FALSE; */
11693 /* } */
11694 /* } */
11695 /* } */
11696
11697 poly m12, m22;
11701 // manually free the coeffs, because pSetCoeff0 is used in the next step
11702 n_Delete(&(m1->coef), currRing->cf);
11703 n_Delete(&(m2->coef), currRing->cf);
11704
11705 //p_Test(m1,strat->tailRing);
11706 //p_Test(m2,strat->tailRing);
11707 /*if(!enterTstrong)
11708 {
11709 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
11710 {
11711 memset(&(strat->P), 0, sizeof(strat->P));
11712 kStratChangeTailRing(strat);
11713 strat->P = *(strat->R[atR]);
11714 p_LmFree(m1, strat->tailRing);
11715 p_LmFree(m2, strat->tailRing);
11716 p_LmFree(gcd, currRing);
11717 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
11718 }
11719 }*/
11720 pSetCoeff0(m1, s);
11721 pSetCoeff0(m2, t);
11722 pSetCoeff0(gcd, d);
11723 p_Test(m1,strat->tailRing);
11724 p_Test(m2,strat->tailRing);
11725 p_Test(m12,strat->tailRing);
11726 p_Test(m22,strat->tailRing);
11727 assume(pmIsInV(m1));
11728 assume(pmIsInV(m2));
11729 assume(pmIsInV(m12));
11730 assume(pmIsInV(m22));
11731 //printf("\n===================================\n");
11732 //pWrite(m1);pWrite(m2);pWrite(gcd);
11733#ifdef KDEBUG
11734 if (TEST_OPT_DEBUG)
11735 {
11736 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
11737 PrintS("m1 = ");
11738 p_wrp(m1, strat->tailRing);
11739 PrintS("m12 = ");
11740 p_wrp(m12, strat->tailRing);
11741 PrintS(" ; m2 = ");
11742 p_wrp(m2, strat->tailRing);
11743 PrintS(" ; m22 = ");
11744 p_wrp(m22, strat->tailRing);
11745 PrintS(" ; gcd = ");
11746 wrp(gcd);
11747 PrintS("\n--- create strong gcd poly: ");
11748 PrintS("\n p: ");
11749 wrp(p);
11750 Print("\n q (strat->S[%d]): ", ifromS);
11751 wrp(q);
11752 PrintS(" ---> ");
11753 }
11754#endif
11755
11756 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);
11757 p_LmDelete(m1, strat->tailRing);
11758 p_LmDelete(m2, strat->tailRing);
11759 p_LmDelete(m12, strat->tailRing);
11760 p_LmDelete(m22, strat->tailRing);
11761
11762 assume(pIsInV(gcd));
11763
11764#ifdef KDEBUG
11765 if (TEST_OPT_DEBUG)
11766 {
11767 wrp(gcd);
11768 PrintLn();
11769 }
11770#endif
11771
11772 LObject h;
11773 h.p = gcd;
11774 h.tailRing = strat->tailRing;
11775 int posx;
11776 strat->initEcart(&h);
11777 h.sev = pGetShortExpVector(h.p);
11778 h.i_r1 = -1;h.i_r2 = -1;
11779 if (currRing!=strat->tailRing)
11780 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
11781#if 1
11782 h.p1 = p;
11783 h.p2 = q;
11784#endif
11785 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
11786 {
11787 h.i_r2 = kFindInT(h.p1, strat);
11788 h.i_r1 = atR;
11789 }
11790 else
11791 {
11792 h.i_r1 = -1;
11793 h.i_r2 = -1;
11794 }
11795 if (strat->Ll==-1)
11796 posx =0;
11797 else
11798 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
11799
11800 assume(pIsInV(h.p));
11801 assume(pIsInV(h.p1));
11802
11803 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
11804 return TRUE;
11805}
11806#endif
11807
11808
11809/*2
11810* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i] (ring case)
11811*/
11812#ifdef HAVE_SHIFTBBA
11813static void enterOnePairRingShift (poly q, poly p, int /*ecart*/, int isFromQ, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
11814{
11815 /* assume(atR >= 0); */
11816 /* assume(i<=strat->sl); */
11817 assume(p!=NULL);
11819 assume(pIsInV(p));
11820 #if ALL_VS_JUST
11821 //Over rings, if we construct the strong pair, do not add the spair
11823 {
11824 number s,t,d;
11825 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q, &s, &t, currRing->cf);
11826
11827 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
11828 {
11829 nDelete(&d);
11830 nDelete(&s);
11831 nDelete(&t);
11832 return;
11833 }
11834 nDelete(&d);
11835 nDelete(&s);
11836 nDelete(&t);
11837 }
11838 #endif
11839 int j,compare,compareCoeff;
11840 LObject h;
11841
11842#ifdef KDEBUG
11843 h.ecart=0; h.length=0;
11844#endif
11845 /*- computes the lcm(s[i],p) -*/
11846 if(pHasNotCFRing(p,q))
11847 {
11848 strat->cp++;
11849 return;
11850 }
11851 h.lcm = p_Lcm(p,q,currRing);
11852 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(q), currRing->cf));
11853 if (nIsZero(pGetCoeff(h.lcm)))
11854 {
11855 strat->cp++;
11856 pLmDelete(h.lcm);
11857 return;
11858 }
11859
11860 /* the V criterion */
11861 if (!pmIsInV(h.lcm))
11862 {
11863 strat->cv++;
11864 pLmDelete(h.lcm);
11865 return;
11866 }
11867 // basic chain criterion
11868 /*
11869 *the set B collects the pairs of type (S[j],p)
11870 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
11871 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
11872 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
11873 */
11874
11875 for(j = strat->Bl;j>=0;j--)
11876 {
11877 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
11878 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
11879 if(compare == pDivComp_EQUAL)
11880 {
11881 //They have the same LM
11883 {
11884 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11885 {
11886 strat->c3++;
11887 pLmDelete(h.lcm);
11888 return;
11889 }
11890 break;
11891 }
11893 {
11894 deleteInL(strat->B,&strat->Bl,j,strat);
11895 strat->c3++;
11896 }
11898 {
11899 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11900 {
11901 strat->c3++;
11902 pLmDelete(h.lcm);
11903 return;
11904 }
11905 break;
11906 }
11907 }
11908 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
11909 {
11910 if(compare == pDivComp_LESS)
11911 {
11912 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11913 {
11914 strat->c3++;
11915 pLmDelete(h.lcm);
11916 return;
11917 }
11918 break;
11919 }
11920 if(compare == pDivComp_GREATER)
11921 {
11922 deleteInL(strat->B,&strat->Bl,j,strat);
11923 strat->c3++;
11924 }
11925 }
11926 }
11927 number s, t;
11928 poly m1, m2, gcd = NULL;
11929 s = pGetCoeff(q);
11930 t = pGetCoeff(p);
11932
11933 poly m12, m22;
11937 // manually free the coeffs, because pSetCoeff0 is used in the next step
11938 n_Delete(&(m1->coef), currRing->cf);
11939 n_Delete(&(m2->coef), currRing->cf);
11940
11941 ksCheckCoeff(&s, &t, currRing->cf);
11942 pSetCoeff0(m1, s);
11943 pSetCoeff0(m2, t);
11944 m2 = pNeg(m2);
11945 p_Test(m1,strat->tailRing);
11946 p_Test(m2,strat->tailRing);
11947 p_Test(m12,strat->tailRing);
11948 p_Test(m22,strat->tailRing);
11949 assume(pmIsInV(m1));
11950 assume(pmIsInV(m2));
11951 assume(pmIsInV(m12));
11952 assume(pmIsInV(m22));
11953 poly pm1 = pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing);
11954 poly sim2 = pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing);
11955 assume(pIsInV(pm1));
11956 assume(pIsInV(sim2));
11957 p_LmDelete(m1, currRing);
11958 p_LmDelete(m2, currRing);
11961 if(sim2 == NULL)
11962 {
11963 if(pm1 == NULL)
11964 {
11965 if(h.lcm != NULL)
11966 {
11967 pLmDelete(h.lcm);
11968 h.lcm=NULL;
11969 }
11970 h.Clear();
11971 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
11972 /* if (strat->pairtest==NULL) initPairtest(strat); */
11973 /* strat->pairtest[i] = TRUE; */
11974 /* strat->pairtest[strat->sl+1] = TRUE; */
11975 return;
11976 }
11977 else
11978 {
11979 gcd = pm1;
11980 pm1 = NULL;
11981 }
11982 }
11983 else
11984 {
11985 if((pGetComp(q) == 0) && (0 != pGetComp(p)))
11986 {
11987 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
11988 pSetmComp(sim2);
11989 }
11990 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
11991 gcd = p_Add_q(pm1, sim2, strat->tailRing);
11992 }
11993 p_Test(gcd, strat->tailRing);
11994 assume(pIsInV(gcd));
11995#ifdef KDEBUG
11996 if (TEST_OPT_DEBUG)
11997 {
11998 wrp(gcd);
11999 PrintLn();
12000 }
12001#endif
12002 h.p = gcd;
12003 h.i_r = -1;
12004 if(h.p == NULL)
12005 {
12006 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12007 /* if (strat->pairtest==NULL) initPairtest(strat); */
12008 /* strat->pairtest[i] = TRUE; */
12009 /* strat->pairtest[strat->sl+1] = TRUE; */
12010 return;
12011 }
12012 h.tailRing = strat->tailRing;
12013 int posx;
12014 //h.pCleardenom();
12015 //pSetm(h.p);
12016 h.i_r1 = -1;h.i_r2 = -1;
12017 strat->initEcart(&h);
12018 #if 1
12019 h.p1 = p;
12020 h.p2 = q;
12021 #endif
12022 #if 1
12023 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12024 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12025 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12026 {
12027 h.i_r2 = kFindInT(h.p1, strat); //strat->S_2_R[i];
12028 h.i_r1 = atR;
12029 }
12030 else
12031 {
12032 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12033 h.i_r1 = -1;
12034 h.i_r2 = -1;
12035 }
12036 #endif
12037 if (strat->Bl==-1)
12038 posx =0;
12039 else
12040 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
12041 h.sev = pGetShortExpVector(h.p);
12042 if (currRing!=strat->tailRing)
12043 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12044
12045 assume(pIsInV(h.p));
12046 assume(pIsInV(h.p1));
12047 assume(h.lcm != NULL);
12048 assume(pIsInV(h.lcm));
12049
12050 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
12051 kTest_TS(strat);
12052}
12053#endif
12054
12055#ifdef HAVE_SHIFTBBA
12056// adds the strong pair and the normal pair for rings (aka gpoly and spoly)
12057static BOOLEAN enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12058{
12059 enterOneStrongPolyShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "gpoly"
12060 enterOnePairRingShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "spoly"
12061 return FALSE; // TODO: delete q?
12062}
12063#endif
12064
12065#ifdef HAVE_SHIFTBBA
12066// creates if possible (q,p), (shifts(q),p)
12067static BOOLEAN enterOnePairWithShifts (int q_inS /*also i*/, poly q, poly p, int ecartp, int p_isFromQ, kStrategy strat, int /*atR*/, int p_lastVblock, int q_lastVblock)
12068{
12069 // note: ecart and isFromQ is for p
12070 assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12071 assume(pmFirstVblock(p) == 1);
12072 assume(pmFirstVblock(q) == 1);
12075
12076 // TODO: is ecartq = 0 still ok?
12077 int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12078
12079 int q_isFromQ = 0;
12080 if (strat->fromQ != NULL && q_inS >= 0)
12081 q_isFromQ = strat->fromQ[q_inS];
12082
12083 BOOLEAN (*enterPair)(poly, poly, int, int, kStrategy, int, int, int, int, int);
12086 else
12088
12089 int degbound = currRing->N/currRing->isLPring;
12090 int neededShift = p_lastVblock - ((pGetComp(p) > 0 || pGetComp(q) > 0) ? 0 : 1); // in the module case, product criterion does not hold
12093 int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12095 for (int j = firstShift; j <= maxShift; j++)
12096 {
12097 poly qq = pLPCopyAndShiftLM(q, j);
12098 if (enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS))
12099 {
12100 if (j>0) pLmDelete(qq);
12101 // delete qq, if not it does not enter the pair set
12102 }
12103 else
12105 }
12106
12108 {
12109 // add pairs (m*shifts(q), p) where m is a monomial and the pair has no overlap
12110 for (int j = p_lastVblock; j <= maxPossibleShift; j++)
12111 {
12113 for (int k = 0; k < IDELEMS(fillers); k++)
12114 {
12117 }
12118 idDelete(&fillers);
12119 }
12120 }
12121 return delete_pair;
12122}
12123#endif
12124
12125#ifdef HAVE_SHIFTBBA
12126// creates (q,p), use it when q is already shifted
12127// return TRUE, if (q,p) is discarded
12128static BOOLEAN enterOnePairWithoutShifts (int p_inS /*also i*/, poly q, poly p, int ecartq, int q_isFromQ, kStrategy strat, int /*atR*/, int p_lastVblock, int q_shift)
12129{
12130 // note: ecart and isFromQ is for p
12131 assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12132 assume(pmFirstVblock(p) == 1);
12134 assume(q_shift == pmFirstVblock(q) - 1);
12135
12136 // TODO: is ecartp = 0 still ok?
12137 int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12138
12139 int p_isFromQ = 0;
12140 if (strat->fromQ != NULL && p_inS >= 0)
12141 p_isFromQ = strat->fromQ[p_inS];
12142
12144 {
12145 assume(q_shift <= p_lastVblock); // we allow the special case where there is no overlap
12147 }
12148 else
12149 {
12150 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)
12151 return enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12152 }
12153}
12154#endif
12155
12156
12157#ifdef KDEBUG
12158// enable to print which pairs are considered or discarded and why
12159/* #define CRITERION_DEBUG */
12160#endif
12161/*2
12162* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12163* return TRUE, if (q,p) does not enter B
12164*/
12165#ifdef HAVE_SHIFTBBA
12166BOOLEAN enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12167{
12168#ifdef CRITERION_DEBUG
12169 if (TEST_OPT_DEBUG)
12170 {
12171 PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12172 // also write the LMs in separate lines:
12173 poly lmq = pHead(q);
12174 poly lmp = pHead(p);
12175 pSetCoeff(lmq, n_Init(1, currRing->cf));
12176 pSetCoeff(lmp, n_Init(1, currRing->cf));
12177 Print(" %s\n", pString(lmq));
12178 Print(" %s\n", pString(lmp));
12179 pLmDelete(lmq);
12180 pLmDelete(lmp);
12181 }
12182#endif
12183
12184 /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12185
12186 /* check this Formats: */
12191
12192 /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12193
12194 int qfromQ = qisFromQ;
12195
12196 /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12197
12198 int l,j,compare;
12199 LObject Lp;
12200 Lp.i_r = -1;
12201
12202#ifdef KDEBUG
12203 Lp.ecart=0; Lp.length=0;
12204#endif
12205 /*- computes the lcm(s[i],p) -*/
12206 Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12207
12208 /* the V criterion */
12209 if (!pmIsInV(Lp.lcm))
12210 {
12211 strat->cv++; // counter for applying the V criterion
12212 pLmFree(Lp.lcm);
12213#ifdef CRITERION_DEBUG
12214 if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12215#endif
12216 return TRUE;
12217 }
12218
12219 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12220 {
12221 if((!((ecartq>0)&&(ecart>0)))
12222 && pHasNotCF(p,q))
12223 {
12224 /*
12225 *the product criterion has applied for (s,p),
12226 *i.e. lcm(s,p)=product of the leading terms of s and p.
12227 *Suppose (s,r) is in L and the leading term
12228 *of p divides lcm(s,r)
12229 *(==> the leading term of p divides the leading term of r)
12230 *but the leading term of s does not divide the leading term of r
12231 *(notice that this condition is automatically satisfied if r is still
12232 *in S), then (s,r) can be cancelled.
12233 *This should be done here because the
12234 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12235 *
12236 *Moreover, skipping (s,r) holds also for the noncommutative case.
12237 */
12238 strat->cp++;
12239 pLmFree(Lp.lcm);
12240#ifdef CRITERION_DEBUG
12241 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12242#endif
12243 return TRUE;
12244 }
12245 else
12246 Lp.ecart = si_max(ecart,ecartq);
12247 if (strat->fromT && (ecartq>ecart))
12248 {
12249 pLmFree(Lp.lcm);
12250#ifdef CRITERION_DEBUG
12251 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12252#endif
12253 return TRUE;
12254 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12255 }
12256 /*
12257 *the set B collects the pairs of type (S[j],p)
12258 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12259 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12260 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12261 */
12262 {
12263 j = strat->Bl;
12264 loop
12265 {
12266 if (j < 0) break;
12267 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12268 if ((compare==1)
12269 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12270 {
12271 strat->c3++;
12272 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12273 {
12274 pLmFree(Lp.lcm);
12275#ifdef CRITERION_DEBUG
12276 if (TEST_OPT_DEBUG)
12277 {
12278 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12279 }
12280#endif
12281 return TRUE;
12282 }
12283 break;
12284 }
12285 else
12286 if ((compare ==-1)
12287 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12288 {
12289#ifdef CRITERION_DEBUG
12290 if (TEST_OPT_DEBUG)
12291 {
12292 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12293 }
12294#endif
12295 deleteInL(strat->B,&strat->Bl,j,strat);
12296 strat->c3++;
12297 }
12298 j--;
12299 }
12300 }
12301 }
12302 else /*sugarcrit*/
12303 {
12304 if (ALLOW_PROD_CRIT(strat))
12305 {
12306 // if currRing->nc_type!=quasi (or skew)
12307 // TODO: enable productCrit for super commutative algebras...
12308 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12309 pHasNotCF(p,q))
12310 {
12311 /*
12312 *the product criterion has applied for (s,p),
12313 *i.e. lcm(s,p)=product of the leading terms of s and p.
12314 *Suppose (s,r) is in L and the leading term
12315 *of p divides lcm(s,r)
12316 *(==> the leading term of p divides the leading term of r)
12317 *but the leading term of s does not divide the leading term of r
12318 *(notice that tis condition is automatically satisfied if r is still
12319 *in S), then (s,r) can be canceled.
12320 *This should be done here because the
12321 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12322 */
12323 strat->cp++;
12324 pLmFree(Lp.lcm);
12325#ifdef CRITERION_DEBUG
12326 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12327#endif
12328 return TRUE;
12329 }
12330 if (strat->fromT && (ecartq>ecart))
12331 {
12332 pLmFree(Lp.lcm);
12333#ifdef CRITERION_DEBUG
12334 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12335#endif
12336 return TRUE;
12337 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12338 }
12339 /*
12340 *the set B collects the pairs of type (S[j],p)
12341 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12342 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12343 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12344 */
12345 for(j = strat->Bl;j>=0;j--)
12346 {
12347 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12348 if (compare==1)
12349 {
12350 strat->c3++;
12351 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12352 {
12353 pLmFree(Lp.lcm);
12354#ifdef CRITERION_DEBUG
12355 if (TEST_OPT_DEBUG)
12356 {
12357 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12358 }
12359#endif
12360 return TRUE;
12361 }
12362 break;
12363 }
12364 else
12365 if (compare ==-1)
12366 {
12367#ifdef CRITERION_DEBUG
12368 if (TEST_OPT_DEBUG)
12369 {
12370 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12371 }
12372#endif
12373 deleteInL(strat->B,&strat->Bl,j,strat);
12374 strat->c3++;
12375 }
12376 }
12377 }
12378 }
12379 /*
12380 *the pair (S[i],p) enters B if the spoly != 0
12381 */
12382 /*- compute the short s-polynomial -*/
12383 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12384 pNorm(p);
12385 if ((q==NULL) || (p==NULL))
12386 {
12387#ifdef CRITERION_DEBUG
12388 if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
12389#endif
12390 return FALSE;
12391 }
12392 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12393 {
12394 Lp.p=NULL;
12395#ifdef CRITERION_DEBUG
12396 if (TEST_OPT_DEBUG) PrintS("--- pair is from Q\n");
12397#endif
12398 }
12399 else
12400 {
12401// if ( rIsPluralRing(currRing) )
12402// {
12403// if(pHasNotCF(p, q))
12404// {
12405// if(ncRingType(currRing) == nc_lie)
12406// {
12407// // generalized prod-crit for lie-type
12408// strat->cp++;
12409// Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12410// }
12411// else
12412// if( ALLOW_PROD_CRIT(strat) )
12413// {
12414// // product criterion for homogeneous case in SCA
12415// strat->cp++;
12416// Lp.p = NULL;
12417// }
12418// else
12419// Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12420// }
12421// else Lp.p = nc_CreateSpoly(q,p,currRing);
12422// }
12423// else
12424// {
12425
12426 /* ksCreateShortSpoly needs two Lobject-kind presentations */
12427 /* p is already in this form, so convert q */
12428 Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12429 // }
12430 }
12431 if (Lp.p == NULL)
12432 {
12433 /*- the case that the s-poly is 0 -*/
12434 // TODO: currently ifromS is only > 0 if called from enterOnePairWithShifts
12435 if (ifromS > 0)
12436 {
12437 if (strat->pairtest==NULL) initPairtest(strat);
12438 strat->pairtest[ifromS] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12439 strat->pairtest[strat->sl+1] = TRUE;
12440 }
12441 //if (TEST_OPT_DEBUG){Print("!");} // option teach
12442 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12443 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12444 /*
12445 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12446 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12447 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12448 *term of p divides the lcm(s,r)
12449 *(this canceling should be done here because
12450 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12451 *the first case is handled in chainCrit
12452 */
12453 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12454#ifdef CRITERION_DEBUG
12455 if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
12456#endif
12457 return TRUE;
12458 }
12459 else
12460 {
12461 /*- the pair (S[i],p) enters B -*/
12462 /* both of them should have their LM in currRing and TAIL in tailring */
12463 Lp.p1 = q; // already in the needed form
12464 Lp.p2 = p; // already in the needed form
12465
12466 if ( !rIsPluralRing(currRing) )
12467 pNext(Lp.p) = strat->tail;
12468
12469 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12470 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12471 if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12472 {
12473 Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12474 Lp.i_r2 = atR;
12475 }
12476 else
12477 {
12478 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12479 Lp.i_r1 = -1;
12480 Lp.i_r2 = -1;
12481 }
12482 strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12483
12485 {
12488 && (Lp.p->coef!=NULL))
12489 nDelete(&(Lp.p->coef));
12490 }
12491
12492 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12493 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12494#ifdef CRITERION_DEBUG
12495 if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
12496#endif
12497 }
12498 return FALSE;
12499}
12500#endif
12501
12502/*3
12503*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12504* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12505* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12506*/
12507#ifdef HAVE_SHIFTBBA
12508void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12509{
12512 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12513 if (h_lastVblock == 0) return;
12514 assume(pmFirstVblock(h) == 1);
12515 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12516 // atR = -1;
12517 if ((strat->syzComp==0)
12518 || (pGetComp(h)<=strat->syzComp))
12519 {
12520 int i,j;
12522
12523 int degbound = currRing->N/currRing->isLPring;
12525
12526 if (pGetComp(h)==0)
12527 {
12528 if (strat->rightGB)
12529 {
12530 if (isFromQ)
12531 {
12532 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12533 for (i=0; i<=maxShift; i++)
12534 {
12535 poly hh = pLPCopyAndShiftLM(h, i);
12537 for (j=0; j<=k; j++)
12538 {
12539 if (strat->fromQ == NULL || !strat->fromQ[j])
12540 {
12541 new_pair=TRUE;
12542 poly s = strat->S[j];
12543 if (!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12545 }
12546 }
12547 if (delete_hh) pLmDelete(hh);
12548 }
12549 }
12550 else
12551 {
12552 new_pair=TRUE;
12553 for (j=0; j<=k; j++)
12554 {
12555 poly s = strat->S[j];
12556 if (strat->fromQ != NULL && strat->fromQ[j])
12557 {
12558 // pairs (shifts(s[j]),h), (s[j],h)
12560 }
12561 else
12562 {
12563 // pair (h, s[j])
12564 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12565 }
12566 }
12567 }
12568 }
12569 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12570 else if ((isFromQ)&&(strat->fromQ!=NULL))
12571 {
12572 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12573 for (j=0; j<=k; j++)
12574 {
12575 if (!strat->fromQ[j])
12576 {
12577 new_pair=TRUE;
12578 poly s = strat->S[j];
12580 }
12581 }
12582 // pairs (shifts(h),s[1..k])
12583 if (new_pair)
12584 {
12585 for (i=1; i<=maxShift; i++)
12586 {
12588 poly hh = pLPCopyAndShiftLM(h, i);
12589 for (j=0; j<=k; j++)
12590 {
12591 if (!strat->fromQ[j])
12592 {
12593 poly s = strat->S[j];
12595 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)
12596 {
12597 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i))
12599 }
12600 else if (rField_is_Ring(currRing))
12601 {
12602 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12604 for (int k = 0; k < IDELEMS(fillers); k++)
12605 {
12608 }
12609 idDelete(&fillers);
12610 }
12611 }
12612 }
12614 }
12615 }
12616 }
12617 else
12618 {
12619 new_pair=TRUE;
12620 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12621 for (j=0; j<=k; j++)
12622 {
12623 poly s = strat->S[j];
12625 }
12626 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12627 for (i=1; i<=maxShift; i++)
12628 {
12629 poly hh = pLPCopyAndShiftLM(h, i);
12631 for (j=0; j<=k; j++)
12632 {
12633 poly s = strat->S[j];
12635 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)
12637 && delete_hh;
12638 else if (rField_is_Ring(currRing))
12639 {
12640 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12642 for (int k = 0; k < IDELEMS(fillers); k++)
12643 {
12646 }
12647 idDelete(&fillers);
12648 }
12649 }
12650 if (i < h_lastVblock) // in the module case, product criterion does not hold (note: comp h is always zero here)
12652 && delete_hh;
12653 else if (rField_is_Ring(currRing))
12654 {
12655 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12657 for (int k = 0; k < IDELEMS(fillers); k++)
12658 {
12661 }
12662 idDelete(&fillers);
12663 }
12664 if (delete_hh) pLmDelete(hh);
12665 }
12666 }
12667 }
12668 else
12669 {
12670 assume(isFromQ == 0); // an element from Q should always has 0 component
12671 new_pair=TRUE;
12672 if (strat->rightGB)
12673 {
12674 for (j=0; j<=k; j++)
12675 {
12676 if ((pGetComp(h)==pGetComp(strat->S[j]))
12677 || (pGetComp(strat->S[j])==0))
12678 {
12679 poly s = strat->S[j];
12680 if (strat->fromQ != NULL && strat->fromQ[j])
12681 {
12682 // pairs (shifts(s[j]),h), (s[j],h)
12684 }
12685 else
12686 {
12687 // pair (h, s[j])
12688 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12689 }
12690 }
12691 }
12692 }
12693 else
12694 {
12695 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12696 for (j=0; j<=k; j++)
12697 {
12698 if ((pGetComp(h)==pGetComp(strat->S[j]))
12699 || (pGetComp(strat->S[j])==0))
12700 {
12701 poly s = strat->S[j];
12703 }
12704 }
12705 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12706 for (i=1; i<=maxShift; i++)
12707 {
12708 poly hh = pLPCopyAndShiftLM(h, i);
12709 for (j=0; j<=k; j++)
12710 {
12711 if ((pGetComp(h)==pGetComp(strat->S[j]))
12712 || (pGetComp(strat->S[j])==0))
12713 {
12714 poly s = strat->S[j];
12716 if (i <= s_lastVblock) // in the module case, product criterion does not hold
12717 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
12718 else if (rField_is_Ring(currRing))
12719 {
12720 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12722 for (int k = 0; k < IDELEMS(fillers); k++)
12723 {
12726 }
12727 idDelete(&fillers);
12728 }
12729 }
12730 }
12731 if (i <= h_lastVblock) // in the module case, product criterion does not hold
12732 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12733 else if (rField_is_Ring(currRing))
12734 {
12735 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12737 for (int k = 0; k < IDELEMS(fillers); k++)
12738 {
12744 }
12745 idDelete(&fillers);
12746 }
12747 }
12748 }
12749 }
12750
12751 if (new_pair)
12752 {
12753 strat->chainCrit(h,ecart,strat);
12754 }
12755 kMergeBintoL(strat);
12756 }
12757}
12758#endif
12759
12760/*3
12761*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12762* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12763* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12764*/
12765#ifdef HAVE_SHIFTBBA
12766void initenterstrongPairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12767{
12770 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12771 if (h_lastVblock == 0) return;
12772 assume(pmFirstVblock(h) == 1);
12773 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12774 // atR = -1;
12775 if ((strat->syzComp==0)
12776 || (pGetComp(h)<=strat->syzComp))
12777 {
12778 int i,j;
12780
12781 int degbound = currRing->N/currRing->isLPring;
12783
12784 if (pGetComp(h)==0)
12785 {
12786 if (strat->rightGB)
12787 {
12788 if (isFromQ)
12789 {
12790 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12791 for (i=0; i<=maxShift; i++)
12792 {
12793 poly hh = pLPCopyAndShiftLM(h, i);
12794 for (j=0; j<=k; j++)
12795 {
12796 if (strat->fromQ == NULL || !strat->fromQ[j])
12797 {
12798 new_pair=TRUE;
12799 poly s = strat->S[j];
12800 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12801 }
12802 }
12803 }
12804 }
12805 else
12806 {
12807 new_pair=TRUE;
12808 for (j=0; j<=k; j++)
12809 {
12810 poly s = strat->S[j];
12811 if (strat->fromQ != NULL && strat->fromQ[j])
12812 {
12813 // pairs (shifts(s[j]),h), (s[j],h)
12815 }
12816 else
12817 {
12818 // pair (h, s[j])
12819 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12820 }
12821 }
12822 }
12823 }
12824 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12825 else if ((isFromQ)&&(strat->fromQ!=NULL))
12826 {
12827 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12828 for (j=0; j<=k; j++)
12829 {
12830 if (!strat->fromQ[j])
12831 {
12832 new_pair=TRUE;
12833 poly s = strat->S[j];
12835 }
12836 }
12837 // pairs (shifts(h),s[1..k])
12838 if (new_pair)
12839 {
12840 for (i=1; i<=maxShift; i++)
12841 {
12842 poly hh = pLPCopyAndShiftLM(h, i);
12843 for (j=0; j<=k; j++)
12844 {
12845 if (!strat->fromQ[j])
12846 {
12847 poly s = strat->S[j];
12848 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12849 }
12850 }
12851 }
12852 }
12853 }
12854 else
12855 {
12856 new_pair=TRUE;
12857 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12858 for (j=0; j<=k; j++)
12859 {
12860 poly s = strat->S[j];
12861 // TODO: cache lastVblock of s[1..k] for later use
12863 }
12864 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12865 for (i=1; i<=maxShift; i++)
12866 {
12867 poly hh = pLPCopyAndShiftLM(h, i);
12869 for (j=0; j<=k; j++)
12870 {
12871 poly s = strat->S[j];
12872 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12874 }
12875 if(!enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i))
12878 }
12879 }
12880 }
12881 else
12882 {
12883 new_pair=TRUE;
12884 if (strat->rightGB)
12885 {
12886 for (j=0; j<=k; j++)
12887 {
12888 if ((pGetComp(h)==pGetComp(strat->S[j]))
12889 || (pGetComp(strat->S[j])==0))
12890 {
12891 assume(isFromQ == 0); // this case is not handled here and should also never happen
12892 poly s = strat->S[j];
12893 if (strat->fromQ != NULL && strat->fromQ[j])
12894 {
12895 // pairs (shifts(s[j]),h), (s[j],h)
12897 }
12898 else
12899 {
12900 // pair (h, s[j])
12901 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12902 }
12903 }
12904 }
12905 }
12906 else
12907 {
12908 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12909 for (j=0; j<=k; j++)
12910 {
12911 if ((pGetComp(h)==pGetComp(strat->S[j]))
12912 || (pGetComp(strat->S[j])==0))
12913 {
12914 poly s = strat->S[j];
12916 }
12917 }
12918 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12919 for (i=1; i<=maxShift; i++)
12920 {
12921 poly hh = pLPCopyAndShiftLM(h, i);
12922 for (j=0; j<=k; j++)
12923 {
12924 if ((pGetComp(h)==pGetComp(strat->S[j]))
12925 || (pGetComp(strat->S[j])==0))
12926 {
12927 poly s = strat->S[j];
12928 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12929 }
12930 }
12931 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12932 }
12933 }
12934 }
12935
12936 if (new_pair)
12937 {
12938 strat->chainCrit(h,ecart,strat);
12939 }
12940 kMergeBintoL(strat);
12941 }
12942}
12943#endif
12944
12945/*2
12946*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
12947*superfluous elements in S will be deleted
12948*/
12949#ifdef HAVE_SHIFTBBA
12950void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
12951{
12952 /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12953 /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
12954 int j=pos;
12955
12956 /* if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat); */ // TODO: enterExtendedSpoly not for LP yet
12957 initenterpairsShift(h,k,ecart,0,strat, atR);
12958 if ( (!strat->fromT)
12959 && ((strat->syzComp==0)
12960 ||(pGetComp(h)<=strat->syzComp)))
12961 {
12962 unsigned long h_sev = pGetShortExpVector(h);
12963 loop
12964 {
12965 if (j > k) break;
12966 // TODO this currently doesn't clear all possible elements because of commutative division
12967 if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
12968 clearS(h,h_sev, &j,&k,strat);
12969 j++;
12970 }
12971 }
12972}
12973#endif
12974
12975/*2
12976* enteres all admissible shifts of p into T
12977* assumes that p is already in T!
12978*/
12979#ifdef HAVE_SHIFTBBA
12981{
12982 /* determine how many elements we have to insert */
12983 /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12984 /* hence, a total number of elt's to add is: */
12985 /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12986 pAssume(p.p != NULL);
12987
12989
12990 for (int i = 1; i <= maxPossibleShift; i++)
12991 {
12992 LObject qq;
12993 qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
12994 qq.shift = i;
12995 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
12996
12997 enterT(qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
12998 }
12999}
13000#endif
13001
13002#ifdef HAVE_SHIFTBBA
13004{
13005 /* for the shift case need to run it with withT = TRUE */
13006 strat->redTailChange=FALSE;
13007 if (strat->noTailReduction) return L->GetLmCurrRing();
13008 poly h, p;
13009 p = h = L->GetLmTailRing();
13010 if ((h==NULL) || (pNext(h)==NULL))
13011 return L->GetLmCurrRing();
13012
13013 TObject* With;
13014 // placeholder in case strat->tl < 0
13015 TObject With_s(strat->tailRing);
13016
13017 LObject Ln(pNext(h), strat->tailRing);
13018 Ln.pLength = L->GetpLength() - 1;
13019
13020 pNext(h) = NULL;
13021 if (L->p != NULL) pNext(L->p) = NULL;
13022 L->pLength = 1;
13023
13024 Ln.PrepareRed(strat->use_buckets);
13025
13026 while(!Ln.IsNull())
13027 {
13028 loop
13029 {
13030 Ln.SetShortExpVector();
13031 if (withT)
13032 {
13033 int j;
13034 j = kFindDivisibleByInT(strat, &Ln);
13035 if (j < 0) break;
13036 With = &(strat->T[j]);
13037 }
13038 else
13039 {
13040 With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
13041 if (With == NULL) break;
13042 }
13043 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
13044 {
13045 With->pNorm();
13046 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
13047 }
13048 strat->redTailChange=TRUE;
13049 if (ksReducePolyTail(L, With, &Ln))
13050 {
13051 // reducing the tail would violate the exp bound
13052 // set a flag and hope for a retry (in bba)
13054 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
13055 do
13056 {
13057 pNext(h) = Ln.LmExtractAndIter();
13058 pIter(h);
13059 L->pLength++;
13060 } while (!Ln.IsNull());
13061 goto all_done;
13062 }
13063 if (Ln.IsNull()) goto all_done;
13064 if (! withT) With_s.Init(currRing);
13065 }
13066 pNext(h) = Ln.LmExtractAndIter();
13067 pIter(h);
13068 L->pLength++;
13069 }
13070
13071 all_done:
13072 Ln.Delete();
13073 if (L->p != NULL) pNext(L->p) = pNext(p);
13074
13075 if (strat->redTailChange)
13076 {
13077 L->length = 0;
13078 }
13079 L->Normalize(); // HANNES: should have a test
13080 kTest_L(L,strat);
13081 return L->GetLmCurrRing();
13082}
13083#endif
static int si_max(const int a, const int b)
Definition auxiliary.h:125
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
static int si_min(const int a, const int b)
Definition auxiliary.h:126
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 i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
int p
Definition cfModGcd.cc:4086
bool equal
Definition cfModGcd.cc:4134
CanonicalForm b
Definition cfModGcd.cc:4111
static CanonicalForm bound(const CFMatrix &M)
Definition cf_linsys.cc:460
int length() const
Matrices of numbers.
Definition bigintmat.h:51
poly p
Definition kutil.h:74
poly t_p
Definition kutil.h:75
ring tailRing
Definition kutil.h:77
void wrp()
Definition kutil.cc:757
KINLINE poly kNoetherTail()
Definition kInline.h:66
unsigned long * sevSyz
Definition kutil.h:324
kStrategy next
Definition kutil.h:278
bool sigdrop
Definition kutil.h:359
poly t_kNoether
Definition kutil.h:331
int syzComp
Definition kutil.h:355
int * S_2_R
Definition kutil.h:343
ring tailRing
Definition kutil.h:344
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition kutil.h:292
char noTailReduction
Definition kutil.h:377
int currIdx
Definition kutil.h:318
int nrsyzcrit
Definition kutil.h:360
intset lenS
Definition kutil.h:320
int nrrewcrit
Definition kutil.h:361
pFDegProc pOrigFDeg_TailRing
Definition kutil.h:299
int Ll
Definition kutil.h:352
TSet T
Definition kutil.h:327
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition kutil.h:294
char news
Definition kutil.h:399
omBin lmBin
Definition kutil.h:345
int syzmax
Definition kutil.h:350
int Bl
Definition kutil.h:353
intset ecartS
Definition kutil.h:310
int syzidxmax
Definition kutil.h:350
char honey
Definition kutil.h:376
char rightGB
Definition kutil.h:368
polyset S
Definition kutil.h:307
int minim
Definition kutil.h:358
poly kNoether
Definition kutil.h:330
BOOLEAN * NotUsedAxis
Definition kutil.h:333
LSet B
Definition kutil.h:329
BOOLEAN * pairtest
Definition kutil.h:334
int cp
Definition kutil.h:348
int ak
Definition kutil.h:354
TObject ** R
Definition kutil.h:341
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition kutil.h:296
int tl
Definition kutil.h:351
unsigned long * sevT
Definition kutil.h:326
unsigned long * sevSig
Definition kutil.h:325
int nr
Definition kutil.h:347
poly tail
Definition kutil.h:335
char sugarCrit
Definition kutil.h:376
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition kutil.h:285
KINLINE TObject * s_2_t(int i)
Definition kInline.h:47
intset syzIdx
Definition kutil.h:314
ideal Shdl
Definition kutil.h:304
int syzl
Definition kutil.h:350
unsigned sbaOrder
Definition kutil.h:317
pFDegProc pOrigFDeg
Definition kutil.h:297
int tmax
Definition kutil.h:351
polyset sig
Definition kutil.h:309
polyset syz
Definition kutil.h:308
char LDegLast
Definition kutil.h:384
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition kutil.h:288
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.h:293
wlen_set lenSw
Definition kutil.h:321
char kAllAxis
Definition kutil.h:375
int cv
Definition kutil.h:367
pShallowCopyDeleteProc p_shallow_copy_delete
Definition kutil.h:339
char Gebauer
Definition kutil.h:377
intset fromQ
Definition kutil.h:322
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition kutil.h:287
char newt
Definition kutil.h:400
char use_buckets
Definition kutil.h:382
char interpt
Definition kutil.h:370
char redTailChange
Definition kutil.h:398
int newIdeal
Definition kutil.h:357
char fromT
Definition kutil.h:378
char completeReduce_retry
Definition kutil.h:402
void(* initEcart)(TObject *L)
Definition kutil.h:281
omBin tailBin
Definition kutil.h:346
LObject P
Definition kutil.h:303
KINLINE TObject * S_2_T(int i)
Definition kInline.h:38
char noClearS
Definition kutil.h:401
int Lmax
Definition kutil.h:352
char z2homog
Definition kutil.h:373
int LazyPass
Definition kutil.h:354
char overflow
Definition kutil.h:403
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.h:291
LSet L
Definition kutil.h:328
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition kutil.h:282
int(* red)(LObject *L, kStrategy strat)
Definition kutil.h:279
int sl
Definition kutil.h:349
int LazyDegree
Definition kutil.h:354
char posInLDependsOnLength
Definition kutil.h:388
unsigned long * sevS
Definition kutil.h:323
char homog
Definition kutil.h:371
pLDegProc pOrigLDeg
Definition kutil.h:298
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition kutil.h:283
pLDegProc pOrigLDeg_TailRing
Definition kutil.h:300
int Bmax
Definition kutil.h:353
int c3
Definition kutil.h:348
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition coeffs.h:811
@ 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:667
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:521
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:682
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:703
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:412
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461
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:693
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:674
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:541
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:631
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:750
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition coeffs.h:527
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
void nKillChar(coeffs r)
undo all initialisations
Definition numbers.cc:563
#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
bool found
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)
Definition hdegree.cc:1074
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition ideals.cc:836
#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
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition kInline.h:959
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:1060
KINLINE int ksReducePolyTailLC_Z(LObject *PR, TObject *PW, LObject *Red)
Definition kInline.h:1107
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition kInline.h:1174
KINLINE TObject ** initR()
Definition kInline.h:95
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition kInline.h:1147
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition kInline.h:1184
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition kInline.h:1235
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:1018
KINLINE int ksReducePolyTail_Z(LObject *PR, TObject *PW, LObject *Red)
Definition kInline.h:1125
KINLINE unsigned long * initsevT()
Definition kInline.h:100
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
int ksCheckCoeff(number *a, number *b, const coeffs r)
Definition kbuckets.cc:1504
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:1446
void enterSMora(LObject &p, int atS, kStrategy strat, int atR)
Definition kstd1.cc:1629
long kHomModDeg(poly p, const ring r)
Definition kstd1.cc:2426
int redFirst(LObject *h, kStrategy strat)
Definition kstd1.cc:794
long kModDeg(poly p, const ring r)
Definition kstd1.cc:2416
int redEcart(LObject *h, kStrategy strat)
Definition kstd1.cc:168
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR)
Definition kstd1.cc:1682
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition kstd1.cc:1360
ideal kStd2(ideal F, ideal Q, tHomog h, intvec **w, bigintmat *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
generic interface to GB/SB computations, large hilbert vectors
Definition kstd1.cc:2611
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition kstd1.cc:3233
int kFindDivisibleByInT_Z(const kStrategy strat, const LObject *L, const int start)
Definition kstd2.cc:213
int redHoney(LObject *h, kStrategy strat)
Definition kstd2.cc:2114
int redHomog(LObject *h, kStrategy strat)
Definition kstd2.cc:1154
int redLazy(LObject *h, kStrategy strat)
Definition kstd2.cc:1909
poly redNF(poly h, int &max_ind, int nonorm, kStrategy strat)
Definition kstd2.cc:2311
int redRing(LObject *h, kStrategy strat)
Definition kstd2.cc:992
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:321
void initSbaPos(kStrategy strat)
Definition kutil.cc:9857
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:6833
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6296
#define pDivComp_LESS
Definition kutil.cc:130
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6409
int getIndexRng(long coeff)
Definition kutil.cc:5997
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6055
int posInT17(const TSet set, const int length, LObject &p)
Definition kutil.cc:5278
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:9744
VAR int HCord
Definition kutil.cc:239
void kMergeBintoL(kStrategy strat)
Definition kutil.cc:3161
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition kutil.cc:536
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition kutil.cc:6643
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9336
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5841
int posInT11(const TSet set, const int length, LObject &p)
Definition kutil.cc:4953
void enterT(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9136
int posInT1(const TSet set, const int length, LObject &p)
Definition kutil.cc:4896
void enterTShift(LObject p, kStrategy strat, int atT)
Definition kutil.cc:12980
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5071
void message(int i, int *olddeg, int *reduc, kStrategy strat, int red_result)
Definition kutil.cc:7460
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition kutil.cc:6618
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8910
BOOLEAN kTest(kStrategy strat)
Definition kutil.cc:1004
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:3934
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:7022
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:5146
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition kutil.cc:6694
int posInT0(const TSet, const int length, LObject &)
Definition kutil.cc:4885
BOOLEAN kTest_TS(kStrategy strat)
Definition kutil.cc:1067
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:1939
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition kutil.cc:703
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition kutil.cc:10520
VAR int Kstd1_mu
Definition kutil.cc:241
void initenterstrongPairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:12766
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4513
static void enterOnePairRingShift(poly q, poly p, int, int isFromQ, kStrategy strat, int atR, int, int qisFromQ, int shiftcount, int ifromS)
Definition kutil.cc:11813
static const char * kTest_LmEqual(poly p, poly t_p, ring tailRing)
Definition kutil.cc:769
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition kutil.cc:1269
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition kutil.cc:6559
static BOOLEAN enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
Definition kutil.cc:12057
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition kutil.cc:4433
static int pLPDivComp(poly p, poly q)
Definition kutil.cc:225
int posInT2(const TSet set, const int length, LObject &p)
Definition kutil.cc:4925
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6142
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6096
#define kFalseReturn(x)
Definition kutil.cc:765
static BOOLEAN enterOnePairWithShifts(int q_inS, poly q, poly p, int ecartp, int p_isFromQ, kStrategy strat, int, int p_lastVblock, int q_lastVblock)
Definition kutil.cc:12067
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11472
static intset initec(const int maxnr)
Definition kutil.cc:522
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition kutil.cc:9560
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4487
int posInT13(const TSet set, const int length, LObject &p)
Definition kutil.cc:5117
void redtailBbaAlsoLC_Z(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7137
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.cc:6510
static void deleteHCBucket(LObject *L, kStrategy strat)
Definition kutil.cc:243
static BOOLEAN enterOnePairWithoutShifts(int p_inS, poly q, poly p, int ecartq, int q_isFromQ, kStrategy strat, int, int p_lastVblock, int q_shift)
Definition kutil.cc:12128
void chainCritSig(poly p, int, kStrategy strat)
Definition kutil.cc:3461
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition kutil.cc:4764
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition kutil.cc:1315
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:4152
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4470
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8507
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5638
static int pDivCompRing(poly p, poly q)
Definition kutil.cc:138
void initBuchMoraPos(kStrategy strat)
Definition kutil.cc:9573
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:3809
void initS(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7583
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition kutil.cc:10962
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:6909
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7266
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition kutil.cc:11087
void initPairtest(kStrategy strat)
Definition kutil.cc:678
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:2202
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5611
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition kutil.cc:8083
void chainCritOpt_1(poly, int, kStrategy strat)
Definition kutil.cc:3445
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:4989
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:1334
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8483
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition kutil.cc:8397
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:12508
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:4207
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:3874
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6177
static void enlargeL(LSet *L, int *length, const int incr)
Definition kutil.cc:668
int posInT17_c(const TSet set, const int length, LObject &p)
Definition kutil.cc:5384
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:13003
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11381
int posInT15(const TSet set, const int length, LObject &p)
Definition kutil.cc:5184
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9235
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition kutil.cc:10705
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.cc:6475
void HEckeTest(poly pp, kStrategy strat)
Definition kutil.cc:493
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5567
STATIC_VAR BOOLEAN sloppy_max
Definition kutil.cc:788
VAR int Kstd1_deg
Definition kutil.cc:240
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition kutil.cc:4316
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:12950
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:2433
BOOLEAN kTest_L(LObject *L, kStrategy strat, BOOLEAN testp, int lpos, TSet T, int tlength)
Definition kutil.cc:916
void exitBuchMora(kStrategy strat)
Definition kutil.cc:9831
void messageStatSBA(int hilbcount, kStrategy strat)
Definition kutil.cc:7514
void initEcartNormal(TObject *h)
Definition kutil.cc:1293
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition kutil.cc:4663
void updateS(BOOLEAN toT, kStrategy strat)
Definition kutil.cc:8552
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7776
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5909
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition kutil.cc:3092
static int * initS_2_R(const int maxnr)
Definition kutil.cc:531
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6252
void initSyzRules(kStrategy strat)
Definition kutil.cc:7928
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5669
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:9959
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition kutil.cc:10482
void cleanT(kStrategy strat)
Definition kutil.cc:557
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:2221
int posInT110(const TSet set, const int length, LObject &p)
Definition kutil.cc:5029
BOOLEAN kTest_S(kStrategy strat)
Definition kutil.cc:1049
int posInSyz(const kStrategy strat, poly sig)
Definition kutil.cc:5758
void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
Definition kutil.cc:9045
void reorderS(int *suc, kStrategy strat)
Definition kutil.cc:4610
void enterExtendedSpoly(poly h, kStrategy strat)
Definition kutil.cc:4232
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6212
#define pDivComp_INCOMP
Definition kutil.cc:132
BOOLEAN kTest_T(TObject *T, kStrategy strat, int i, char TN)
Definition kutil.cc:789
void kMergeBintoLSba(kStrategy strat)
Definition kutil.cc:3182
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition kutil.cc:286
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition kutil.cc:10074
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4457
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition kutil.cc:1326
int posInT19(const TSet set, const int length, LObject &p)
Definition kutil.cc:5510
poly redtailBba_NF(poly p, kStrategy strat)
Definition kutil.cc:7347
#define pDivComp_GREATER
Definition kutil.cc:131
void exitSba(kStrategy strat)
Definition kutil.cc:10034
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5238
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5339
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition kutil.cc:1538
BOOLEAN enterOnePairShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
Definition kutil.cc:12166
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition kutil.cc:11501
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition kutil.cc:1208
void kStratInitChangeTailRing(kStrategy strat)
Definition kutil.cc:11059
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition kutil.cc:3520
void initBuchMoraCrit(kStrategy strat)
Definition kutil.cc:9428
void cleanTSbaRing(kStrategy strat)
Definition kutil.cc:616
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition kutil.cc:5445
static int pDivComp(poly p, poly q)
Definition kutil.cc:176
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition kutil.cc:10280
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6345
void initBuchMoraPosRing(kStrategy strat)
Definition kutil.cc:9658
int kFindInTShift(poly p, TSet T, int tlength)
Definition kutil.cc:728
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition kutil.cc:10781
static BOOLEAN enterOneStrongPolyShift(poly q, poly p, int, int, kStrategy strat, int atR, int, int, int shiftcount, int ifromS)
Definition kutil.cc:11644
void messageSets(kStrategy strat)
Definition kutil.cc:7533
void deleteInS(int i, kStrategy strat)
Definition kutil.cc:1132
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8380
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11435
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5694
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition kutil.cc:687
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition kutil.cc:1688
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5875
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:10541
static unsigned long * initsevS(const int maxnr)
Definition kutil.cc:527
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition kutil.cc:4536
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition kutil.cc:3204
static BOOLEAN is_shifted_p1(const kStrategy strat)
Definition kutil.cc:1181
void initEcartBBA(TObject *h)
Definition kutil.cc:1301
VAR denominator_list DENOMINATOR_LIST
Definition kutil.cc:79
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:2690
void enterSBbaShift(LObject &p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8887
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5799
char * showOption()
Definition misc_ip.cc:711
poly redtailBba_Ring(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7372
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition kutil.cc:5787
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition kutil.cc:1308
void messageStat(int hilbcount, kStrategy strat)
Definition kutil.cc:7501
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition kutil.cc:1746
void chainCritRing(poly p, int, kStrategy strat)
Definition kutil.cc:3996
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition kutil.cc:8231
void initSL(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7676
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition kutil.cc:4841
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition kutil.cc:10870
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8787
void initSbaCrit(kStrategy strat)
Definition kutil.cc:9491
BOOLEAN newHEdge(kStrategy strat)
Definition kutil.cc:10402
#define pDivComp_EQUAL
Definition kutil.cc:129
void cancelunit(LObject *L, BOOLEAN inNF)
Definition kutil.cc:365
void initHilbCrit(ideal, ideal, bigintmat **hilb, kStrategy strat)
Definition kutil.cc:9410
denominator_list_s * denominator_list
Definition kutil.h:64
TObject * TSet
Definition kutil.h:60
#define setmaxL
Definition kutil.h:31
#define setmaxTinc
Definition kutil.h:35
static int kFindInL1(const poly p, const kStrategy strat)
Definition kutil.h:852
#define setmax
Definition kutil.h:30
EXTERN_VAR int strat_nr
Definition kutil.h:182
int64 wlen_type
Definition kutil.h:55
static LSet initL(int nr=setmaxL)
Definition kutil.h:419
LObject * LSet
Definition kutil.h:61
static void kDeleteLcm(LObject *P)
Definition kutil.h:881
int * intset
Definition kutil.h:54
#define ALLOW_PROD_CRIT(A)
Definition kutil.h:394
#define setmaxT
Definition kutil.h:34
#define setmaxLinc
Definition kutil.h:32
class sTObject TObject
Definition kutil.h:58
#define REDTAIL_CANONICALIZE
Definition kutil.h:39
class sLObject LObject
Definition kutil.h:59
static bool rIsSCA(const ring r)
Definition nc.h:190
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
@ nc_lie
Definition nc.h:18
static nc_type & ncRingType(nc_struct *p)
Definition nc.h:159
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
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:389
#define r_assume(x)
Definition mod2.h:390
int dReportError(const char *fmt,...)
Definition dError.cc:44
#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
#define pSetCoeff0(p, n)
Definition monomials.h:59
#define p_GetCoeff(p, r)
Definition monomials.h:50
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 __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
#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)
#define omCheckBinAddrSize(addr, size)
#define omAlloc(size)
#define omReallocSize(addr, o_size, size)
#define omAlloc0(size)
#define omRealloc0Size(addr, o_size, size)
#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:123
#define TEST_OPT_IDLIFT
Definition options.h:131
#define TEST_OPT_INTSTRATEGY
Definition options.h:112
#define TEST_OPT_REDTAIL
Definition options.h:118
#define TEST_OPT_INFREDTAIL
Definition options.h:120
#define TEST_OPT_SUGARCRIT
Definition options.h:109
#define TEST_OPT_OLDSTD
Definition options.h:125
#define TEST_OPT_REDSB
Definition options.h:106
#define TEST_OPT_DEGBOUND
Definition options.h:115
#define TEST_OPT_SB_1
Definition options.h:121
#define TEST_OPT_NOT_SUGAR
Definition options.h:108
#define TEST_OPT_PROT
Definition options.h:105
#define OPT_INTERRUPT
Definition options.h:80
#define TEST_OPT_CANCELUNIT
Definition options.h:130
#define BTEST1(a)
Definition options.h:34
#define TEST_OPT_DEBUG
Definition options.h:110
#define TEST_OPT_CONTENTSB
Definition options.h:129
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
static int index(p_Length length, p_Ord ord)
poly p_GetMaxExpP(poly p, const ring r)
return monomial r such that GetExp(r,i) is maximum of all monomials in p; coeff == 0,...
Definition p_polys.cc:1139
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition p_polys.cc:2958
long pLDegb(poly p, int *l, const ring r)
Definition p_polys.cc:812
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition p_polys.cc:976
long p_WFirstTotalDegree(poly p, const ring r)
Definition p_polys.cc:595
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition p_polys.cc:1039
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition p_polys.cc:3729
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition p_polys.cc:1069
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition p_polys.cc:4635
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition p_polys.cc:942
long pLDeg1(poly p, int *l, const ring r)
Definition p_polys.cc:842
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition p_polys.cc:4889
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition p_polys.cc:911
long p_WTotaldegree(poly p, const ring r)
Definition p_polys.cc:612
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition p_polys.cc:1209
poly p_Cleardenom(poly p, const ring r)
Definition p_polys.cc:2849
long pLDeg1c(poly p, int *l, const ring r)
Definition p_polys.cc:878
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition p_polys.cc:1006
long pLDeg0c(poly p, int *l, const ring r)
Definition p_polys.cc:771
unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max)
return the maximal exponent of p in form of the maximal long var
Definition p_polys.cc:1176
long pLDeg0(poly p, int *l, const ring r)
Definition p_polys.cc:740
poly p_One(const ring r)
Definition p_polys.cc:1314
poly p_Sub(poly p1, poly p2, const ring r)
Definition p_polys.cc:1994
void pEnlargeSet(poly **p, int l, int increment)
Definition p_polys.cc:3776
long p_Deg(poly a, const ring r)
Definition p_polys.cc:586
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition p_polys.cc:1659
static poly p_Neg(poly p, const ring r)
Definition p_polys.h:1114
static int pLength(poly a)
Definition p_polys.h:190
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition p_polys.h:1446
static poly p_Add_q(poly p, poly q, const ring r)
Definition p_polys.h:938
static void p_LmDelete(poly p, const ring r)
Definition p_polys.h:725
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition p_polys.h:1432
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition pDebug.cc:105
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:1877
static long p_FDeg(const poly p, const ring r)
Definition p_polys.h:382
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition p_polys.h:783
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition p_polys.h:1334
static void p_LmDelete0(poly p, const ring r)
Definition p_polys.h:735
static int p_Cmp(poly p1, poly p2, ring r)
Definition p_polys.h:1748
#define __pp_Mult_nn(p, n, r)
Definition p_polys.h:1004
static poly pp_mm_Mult(poly p, poly m, const ring r)
Definition p_polys.h:1043
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition p_polys.h:1033
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition p_polys.h:1668
static void p_SetCompP(poly p, int i, ring r)
Definition p_polys.h:256
#define pp_Test(p, lmRing, tailRing)
Definition p_polys.h:163
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition p_polys.h:249
static void p_Setm(poly p, const ring r)
Definition p_polys.h:235
static number p_SetCoeff(poly p, number n, ring r)
Definition p_polys.h:414
static int p_LmCmp(poly p, poly q, const ring r)
Definition p_polys.h:1601
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition p_polys.h:1931
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:471
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition pDebug.cc:74
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition p_polys.h:1912
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition p_polys.h:930
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition pDebug.cc:115
static poly p_LmFreeAndNext(poly p, ring)
Definition p_polys.h:713
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition p_polys.h:1053
static void p_LmFree(poly p, ring)
Definition p_polys.h:685
#define p_LmTest(p, r)
Definition p_polys.h:162
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition p_polys.h:848
static long p_Totaldegree(poly p, const ring r)
Definition p_polys.h:1528
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition p_polys.h:2020
#define p_Test(p, r)
Definition p_polys.h:161
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:373
void rChangeCurrRing(ring r)
Definition polys.cc:16
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
Compatibility layer for legacy polynomial operations (over currRing)
#define pLtCmp(p, q)
Definition polys.h:124
#define pLtCmpOrdSgnDiffM(p, q)
Definition polys.h:126
#define pDelete(p_ptr)
Definition polys.h:187
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL
Definition polys.h:68
#define pLmIsConstantComp(p)
like above, except that p must be != NULL
Definition polys.h:243
#define pSetm(p)
Definition polys.h:272
#define pIsConstant(p)
like above, except that Comp must be 0
Definition polys.h:239
#define pHasNotCF(p1, p2)
Definition polys.h:264
#define pLtCmpOrdSgnDiffP(p, q)
Definition polys.h:127
#define pNeg(p)
Definition polys.h:199
#define pLmEqual(p1, p2)
Definition polys.h:112
#define ppMult_mm(p, m)
Definition polys.h:202
#define pGetComp(p)
Component.
Definition polys.h:38
#define pIsVector(p)
Definition polys.h:251
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition polys.h:32
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:147
#define pCmp(p1, p2)
pCmp: args may be NULL returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
Definition polys.h:116
#define pDivideM(a, b)
Definition polys.h:295
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition polys.h:65
#define pSetComp(p, v)
Definition polys.h:39
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition polys.h:77
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl....
Definition polys.h:153
void wrp(poly p)
Definition polys.h:311
#define pLmDivisibleBy(a, b)
like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
Definition polys.h:141
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:71
void pWrite(poly p)
Definition polys.h:309
#define pGetExp(p, i)
Exponent.
Definition polys.h:42
#define pSetmComp(p)
TODO:
Definition polys.h:274
#define pHasNotCFRing(p1, p2)
Definition polys.h:263
#define pNormalize(p)
Definition polys.h:318
#define pIsPurePower(p)
Definition polys.h:249
#define pInit()
allocates a new monomial and initializes everything to 0
Definition polys.h:62
#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:139
#define pSetExp(p, i, v)
Definition polys.h:43
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition polys.h:106
#define pLtCmpOrdSgnEqP(p, q)
Definition polys.h:129
char * pString(poly p)
Definition polys.h:307
#define pCopy(p)
return a copy of the poly
Definition polys.h:186
#define pOne()
Definition polys.h:316
poly * polyset
Definition polys.h:260
#define pLcm(a, b, m)
Definition polys.h:296
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:288
void PrintLn()
Definition reporter.cc:314
#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:3527
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition ring.cc:5833
void rKillModifiedRing(ring r)
Definition ring.cc:3119
ring rAssure_c_dp(const ring r)
Definition ring.cc:5134
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition ring.cc:2758
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition ring.cc:1427
void rDebugPrint(const ring r)
Definition ring.cc:4214
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:454
static BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition ring.h:769
static BOOLEAN rHasGlobalOrdering(const ring r)
Definition ring.h:768
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition ring.h:406
static int rBlocks(const ring r)
Definition ring.h:574
static int rGetCurrSyzLimit(const ring r)
Definition ring.h:729
static BOOLEAN rField_is_Domain(const ring r)
Definition ring.h:493
static BOOLEAN rIsRatGRing(const ring r)
Definition ring.h:433
static BOOLEAN rIsLPRing(const ring r)
Definition ring.h:417
rRingOrder_t
order stuff
Definition ring.h:69
@ ringorder_a
Definition ring.h:71
@ ringorder_C
Definition ring.h:74
@ ringorder_c
Definition ring.h:73
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition ring.h:726
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:45
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition ring.h:598
static BOOLEAN rHasMixedOrdering(const ring r)
Definition ring.h:770
#define rField_is_Ring(R)
Definition ring.h:491
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:796
int p_mFirstVblock(poly p, const ring ri)
Definition shiftop.cc:478
void k_SplitFrame(poly &m1, poly &m2, int at, const ring r)
Definition shiftop.cc:600
void p_mLPshift(poly m, int sh, const ring ri)
Definition shiftop.cc:362
#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
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
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)
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
#define IDELEMS(i)
static int idElem(const ideal F)
number of non-zero polys in F
#define R
Definition sirandom.c:27
#define Q
Definition sirandom.c:26
@ isHomog
Definition structs.h:33
@ isNotHomog
Definition structs.h:32
skStrategy * kStrategy
Definition structs.h:54
#define loop
Definition structs.h:71
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition syz3.cc:1027
#define degbound(p)
Definition tgb.cc:153
int gcd(int a, int b)
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:247
#define omMergeStickyBinIntoBin(A, B)
Definition xalloc.h:275