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
241VAR int Kstd1_mu=INT_MAX;
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*/
286void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
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 }
308 BOOLEAN cut=FALSE;
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 {
395 number eins= nCopy(lc);
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;
792 ring strat_tailRing = strat->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{
919 ring strat_tailRing=strat->tailRing;
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;
1189 BOOLEAN is_shifted=TRUE;
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
1394 if(compareCoeff == pDivComp_LESS)
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 }
1404 if(compareCoeff == pDivComp_GREATER)
1405 {
1406 deleteInL(strat->B,&strat->Bl,j,strat);
1407 strat->c3++;
1408 }
1409 if(compareCoeff == pDivComp_EQUAL)
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);
1713 pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1714 sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1715 p_LmDelete(m1, strat->tailRing);
1716 p_LmDelete(m2, strat->tailRing);
1717 poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
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);
1820 pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1821 sSigMult = p_Mult_mm(sSigMult,m2,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
1828 pairsig = p_Add_q(pSigMult,sSigMult,currRing);
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->posInL(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");
2486 pWrite(pSigMult);
2487 pWrite(sSigMult);
2488 PrintS("----------------\n");
2489 Lp.checked = 0;
2490#endif
2491 int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2492//#if 1
2493#if DEBUGF5
2494 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2495 pWrite(pSigMult);
2496 pWrite(sSigMult);
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->posInL(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
2765 pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2766 if(pSigMult != NULL)
2767 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2768 sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2769 if(sSigMult != NULL)
2770 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2771//#if 1
2772#ifdef DEBUGF5
2773 Print("----------------\n");
2774 pWrite(pSigMult);
2775 pWrite(sSigMult);
2776 Print("----------------\n");
2777 Lp.checked = 0;
2778#endif
2779 int sigCmp;
2780 if(pSigMult != NULL && sSigMult != NULL)
2781 {
2783 sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2784 else
2785 sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
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);
2802 pWrite(pSigMult);
2803 pWrite(sSigMult);
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)
2821 Lp.sev = p_GetShortExpVector(Lp.p,currRing);
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 }
2840 if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2841 {
2842 //Same lm, have to subtract
2843 Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
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)
2917 Lp.sev = p_GetShortExpVector(Lp.p,currRing);
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->posInL(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->posInL(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;
3816 BOOLEAN new_pair=FALSE;
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;
3881 BOOLEAN new_pair=FALSE;
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;
4157 BOOLEAN new_pair=FALSE;
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();
4272 pSetCoeff0(tmp, pGetCoeff(p));
4273 for (int i = 1; i <= rVar(currRing); i++)
4274 {
4275 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4276 }
4278 {
4279 p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4280 }
4281 p_Setm(tmp, currRing);
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
4316void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
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();
4356 pSetCoeff0(tmp, pGetCoeff(p));
4357 for (int i = 1; i <= rVar(currRing); i++)
4358 {
4359 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4360 }
4362 {
4363 p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4364 }
4365 p_Setm(tmp, currRing);
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
4401 p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
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->posInL(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
4474 if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
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 }
4652 if (new_suc <= strat->sl) *suc=new_suc;
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;
4673#ifdef HAVE_PLURAL
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{
4843 if(end < 0 || end >= IDELEMS(F))
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 pFDeg, p1 == NULL, 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 || ((op == d) && ((p->p1==NULL) == (set[length].p1==NULL)) && (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 || ((op == d) && ((p->p1==NULL) == (set[an].p1==NULL)) && (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 || ((op==d) && ((p->p1==NULL) == (set[i].p1==NULL)) && (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*/
5787// dummy, unused
5788#if 0
5789int posInLF5C (const LSet /*set*/, const int /*length*/,
5790 LObject* /*p*/,const kStrategy strat)
5791{
5792 return strat->Ll+1;
5793}
5794#endif
5795
5796/*2
5797* looks up the position of polynomial p in set
5798* e is the ecart of p
5799* set[length] is the smallest element in set with respect
5800* to the ordering-procedure totaldegree,pComp
5801*/
5802int posInL11 (const LSet set, const int length,
5803 LObject* p,const kStrategy)
5804{
5805 if (length<0) return 0;
5806
5807 int o = p->GetpFDeg();
5808 int op = set[length].GetpFDeg();
5809 int cmp_int= -currRing->OrdSgn;
5810
5811 if ((op > o)
5812 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
5813 return length+1;
5814 int i;
5815 int an = 0;
5816 int en= length;
5817 loop
5818 {
5819 if (an >= en-1)
5820 {
5821 op = set[an].GetpFDeg();
5822 if ((op > o)
5823 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
5824 return en;
5825 return an;
5826 }
5827 i=(an+en) / 2;
5828 op = set[i].GetpFDeg();
5829 if ((op > o)
5830 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
5831 an=i;
5832 else
5833 en=i;
5834 }
5835}
5836
5837/*2
5838* looks up the position of polynomial p in set
5839* set[length] is the smallest element in set with respect
5840* to the ordering-procedure pLmCmp,totaldegree,coefficient
5841* For the same totaldegree, original pairs (from F) will
5842* be put at the end and smallest coefficients
5843*/
5844int posInL11Ring (const LSet set, const int length,
5845 LObject* p,const kStrategy)
5846{
5847 if (length<0) return 0;
5848
5849 int o = p->GetpFDeg();
5850 int op = set[length].GetpFDeg();
5851
5852 if ((op > o)
5853 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5854 return length+1;
5855 int i;
5856 int an = 0;
5857 int en= length;
5858 loop
5859 {
5860 if (an >= en-1)
5861 {
5862 op = set[an].GetpFDeg();
5863 if ((op > o)
5864 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5865 return en;
5866 return an;
5867 }
5868 i=(an+en) / 2;
5869 op = set[i].GetpFDeg();
5870 if ((op > o)
5871 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5872 an=i;
5873 else
5874 en=i;
5875 }
5876}
5877
5878int posInLF5CRing (const LSet set, int start,const int length,
5879 LObject* p,const kStrategy)
5880{
5881 if (length<0) return 0;
5882 if(start == (length +1)) return (length+1);
5883 int o = p->GetpFDeg();
5884 int op = set[length].GetpFDeg();
5885
5886 if ((op > o)
5887 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5888 return length+1;
5889 int i;
5890 int an = start;
5891 int en= length;
5892 loop
5893 {
5894 if (an >= en-1)
5895 {
5896 op = set[an].GetpFDeg();
5897 if ((op > o)
5898 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5899 return en;
5900 return an;
5901 }
5902 i=(an+en) / 2;
5903 op = set[i].GetpFDeg();
5904 if ((op > o)
5905 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5906 an=i;
5907 else
5908 en=i;
5909 }
5910}
5911
5912int posInL11Ringls (const LSet set, const int length,
5913 LObject* p,const kStrategy)
5914{
5915 if (length < 0) return 0;
5916 int an,en,i;
5917 an = 0;
5918 en = length+1;
5919 loop
5920 {
5921 if (an >= en-1)
5922 {
5923 if(an == en)
5924 return en;
5925 if (set[an].FDeg > p->FDeg)
5926 return en;
5927 if (set[an].FDeg < p->FDeg)
5928 return an;
5929 if (set[an].FDeg == p->FDeg)
5930 {
5931 number lcset,lcp;
5932 lcset = pGetCoeff(set[an].p);
5933 lcp = pGetCoeff(p->p);
5934 if(!nGreaterZero(lcset))
5935 {
5936 set[an].p=p_Neg(set[an].p,currRing);
5937 if (set[an].t_p!=NULL)
5938 pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
5939 lcset=pGetCoeff(set[an].p);
5940 }
5941 if(!nGreaterZero(lcp))
5942 {
5943 p->p=p_Neg(p->p,currRing);
5944 if (p->t_p!=NULL)
5945 pSetCoeff0(p->t_p,pGetCoeff(p->p));
5946 lcp=pGetCoeff(p->p);
5947 }
5948 if(nGreater(lcset, lcp))
5949 {
5950 return en;
5951 }
5952 else
5953 {
5954 return an;
5955 }
5956 }
5957 }
5958 i=(an+en) / 2;
5959 if (set[i].FDeg > p->FDeg)
5960 an=i;
5961 if (set[i].FDeg < p->FDeg)
5962 en=i;
5963 if (set[i].FDeg == p->FDeg)
5964 {
5965 number lcset,lcp;
5966 lcset = pGetCoeff(set[i].p);
5967 lcp = pGetCoeff(p->p);
5968 if(!nGreaterZero(lcset))
5969 {
5970 set[i].p=p_Neg(set[i].p,currRing);
5971 if (set[i].t_p!=NULL)
5972 pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
5973 lcset=pGetCoeff(set[i].p);
5974 }
5975 if(!nGreaterZero(lcp))
5976 {
5977 p->p=p_Neg(p->p,currRing);
5978 if (p->t_p!=NULL)
5979 pSetCoeff0(p->t_p,pGetCoeff(p->p));
5980 lcp=pGetCoeff(p->p);
5981 }
5982 if(nGreater(lcset, lcp))
5983 {
5984 an = i;
5985 }
5986 else
5987 {
5988 en = i;
5989 }
5990 }
5991 }
5992}
5993
5994/*2 Position for rings L: Here I am
5995* looks up the position of polynomial p in set
5996* e is the ecart of p
5997* set[length] is the smallest element in set with respect
5998* to the ordering-procedure totaldegree,pComp
5999*/
6000inline int getIndexRng(long coeff)
6001{
6002 if (coeff == 0) return -1;
6003 long tmp = coeff;
6004 int ind = 0;
6005 while (tmp % 2 == 0)
6006 {
6007 tmp = tmp / 2;
6008 ind++;
6009 }
6010 return ind;
6011}
6012
6013/*{
6014 if (length < 0) return 0;
6015
6016 int o = p->GetpFDeg();
6017 int op = set[length].GetpFDeg();
6018
6019 int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6020 int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6021 int inda;
6022 int indi;
6023
6024 if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6025 return length + 1;
6026 int i;
6027 int an = 0;
6028 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6029 int en = length;
6030 loop
6031 {
6032 if (an >= en-1)
6033 {
6034 op = set[an].GetpFDeg();
6035 if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6036 return en;
6037 return an;
6038 }
6039 i = (an + en) / 2;
6040 indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6041 op = set[i].GetpFDeg();
6042 if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6043 // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6044 {
6045 an = i;
6046 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6047 }
6048 else
6049 en = i;
6050 }
6051} */
6052
6053/*2
6054* looks up the position of polynomial p in set
6055* set[length] is the smallest element in set with respect
6056* to the ordering-procedure totaldegree,pLength0
6057*/
6058int posInL110 (const LSet set, const int length,
6059 LObject* p,const kStrategy)
6060{
6061 if (length<0) return 0;
6062
6063 int o = p->GetpFDeg();
6064 int op = set[length].GetpFDeg();
6065 int cmp_int= -currRing->OrdSgn;
6066
6067 if ((op > o)
6068 || ((op == o) && (set[length].length >p->length))
6069 || ((op == o) && (set[length].length == p->length)
6070 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6071 return length+1;
6072 int i;
6073 int an = 0;
6074 int en= length;
6075 loop
6076 {
6077 if (an >= en-1)
6078 {
6079 op = set[an].GetpFDeg();
6080 if ((op > o)
6081 || ((op == o) && (set[an].length >p->length))
6082 || ((op == o) && (set[an].length == p->length)
6083 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6084 return en;
6085 return an;
6086 }
6087 i=(an+en) / 2;
6088 op = set[i].GetpFDeg();
6089 if ((op > o)
6090 || ((op == o) && (set[i].length > p->length))
6091 || ((op == o) && (set[i].length == p->length)
6092 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6093 an=i;
6094 else
6095 en=i;
6096 }
6097}
6098
6099int posInL110Ring (const LSet set, const int length,
6100 LObject* p,const kStrategy)
6101{
6102 if (length<0) return 0;
6103
6104 int o = p->GetpFDeg();
6105 int op = set[length].GetpFDeg();
6106
6107 if ((op > o)
6108 || ((op == o) && (set[length].length >p->length))
6109 || ((op == o) && (set[length].length == p->length)
6110 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6111 return length+1;
6112 int i;
6113 int an = 0;
6114 int en= length;
6115 loop
6116 {
6117 if (an >= en-1)
6118 {
6119 op = set[an].GetpFDeg();
6120 if ((op > o)
6121 || ((op == o) && (set[an].length >p->length))
6122 || ((op == o) && (set[an].length == p->length)
6123 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6124 return en;
6125 return an;
6126 }
6127 i=(an+en) / 2;
6128 op = set[i].GetpFDeg();
6129 if ((op > o)
6130 || ((op == o) && (set[i].length > p->length))
6131 || ((op == o) && (set[i].length == p->length)
6132 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6133 an=i;
6134 else
6135 en=i;
6136 }
6137}
6138
6139/*2
6140* looks up the position of polynomial p in set
6141* e is the ecart of p
6142* set[length] is the smallest element in set with respect
6143* to the ordering-procedure totaldegree
6144*/
6145int posInL13 (const LSet set, const int length,
6146 LObject* p,const kStrategy)
6147{
6148 if (length<0) return 0;
6149
6150 int o = p->GetpFDeg();
6151
6152 if (set[length].GetpFDeg() > o)
6153 return length+1;
6154
6155 int i;
6156 int an = 0;
6157 int en= length;
6158 loop
6159 {
6160 if (an >= en-1)
6161 {
6162 if (set[an].GetpFDeg() >= o)
6163 return en;
6164 return an;
6165 }
6166 i=(an+en) / 2;
6167 if (set[i].GetpFDeg() >= o)
6168 an=i;
6169 else
6170 en=i;
6171 }
6172}
6173
6174/*2
6175* looks up the position of polynomial p in set
6176* e is the ecart of p
6177* set[length] is the smallest element in set with respect
6178* to the ordering-procedure maximaldegree,pComp
6179*/
6180int posInL15 (const LSet set, const int length,
6181 LObject* p,const kStrategy)
6182{
6183 if (length<0) return 0;
6184
6185 int o = p->GetpFDeg() + p->ecart;
6186 int op = set[length].GetpFDeg() + set[length].ecart;
6187 int cmp_int= -currRing->OrdSgn;
6188
6189 if ((op > o)
6190 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
6191 return length+1;
6192 int i;
6193 int an = 0;
6194 int en= length;
6195 loop
6196 {
6197 if (an >= en-1)
6198 {
6199 op = set[an].GetpFDeg() + set[an].ecart;
6200 if ((op > o)
6201 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
6202 return en;
6203 return an;
6204 }
6205 i=(an+en) / 2;
6206 op = set[i].GetpFDeg() + set[i].ecart;
6207 if ((op > o)
6208 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
6209 an=i;
6210 else
6211 en=i;
6212 }
6213}
6214
6215int posInL15Ring (const LSet set, const int length,
6216 LObject* p,const kStrategy)
6217{
6218 if (length<0) return 0;
6219
6220 int o = p->GetpFDeg() + p->ecart;
6221 int op = set[length].GetpFDeg() + set[length].ecart;
6222
6223 if ((op > o)
6224 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6225 return length+1;
6226 int i;
6227 int an = 0;
6228 int en= length;
6229 loop
6230 {
6231 if (an >= en-1)
6232 {
6233 op = set[an].GetpFDeg() + set[an].ecart;
6234 if ((op > o)
6235 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6236 return en;
6237 return an;
6238 }
6239 i=(an+en) / 2;
6240 op = set[i].GetpFDeg() + set[i].ecart;
6241 if ((op > o)
6242 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6243 an=i;
6244 else
6245 en=i;
6246 }
6247}
6248
6249/*2
6250* looks up the position of polynomial p in set
6251* e is the ecart of p
6252* set[length] is the smallest element in set with respect
6253* to the ordering-procedure totaldegree
6254*/
6255int posInL17 (const LSet set, const int length,
6256 LObject* p,const kStrategy)
6257{
6258 if (length<0) return 0;
6259
6260 int o = p->GetpFDeg() + p->ecart;
6261 int cmp_int= -currRing->OrdSgn;
6262
6263 if ((set[length].GetpFDeg() + set[length].ecart > o)
6264 || ((set[length].GetpFDeg() + set[length].ecart == o)
6265 && (set[length].ecart > p->ecart))
6266 || ((set[length].GetpFDeg() + set[length].ecart == o)
6267 && (set[length].ecart == p->ecart)
6268 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6269 return length+1;
6270 int i;
6271 int an = 0;
6272 int en= length;
6273 loop
6274 {
6275 if (an >= en-1)
6276 {
6277 if ((set[an].GetpFDeg() + set[an].ecart > o)
6278 || ((set[an].GetpFDeg() + set[an].ecart == o)
6279 && (set[an].ecart > p->ecart))
6280 || ((set[an].GetpFDeg() + set[an].ecart == o)
6281 && (set[an].ecart == p->ecart)
6282 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6283 return en;
6284 return an;
6285 }
6286 i=(an+en) / 2;
6287 if ((set[i].GetpFDeg() + set[i].ecart > o)
6288 || ((set[i].GetpFDeg() + set[i].ecart == o)
6289 && (set[i].ecart > p->ecart))
6290 || ((set[i].GetpFDeg() +set[i].ecart == o)
6291 && (set[i].ecart == p->ecart)
6292 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6293 an=i;
6294 else
6295 en=i;
6296 }
6297}
6298
6299int posInL17Ring (const LSet set, const int length,
6300 LObject* p,const kStrategy)
6301{
6302 if (length<0) return 0;
6303
6304 int o = p->GetpFDeg() + p->ecart;
6305
6306 if ((set[length].GetpFDeg() + set[length].ecart > o)
6307 || ((set[length].GetpFDeg() + set[length].ecart == o)
6308 && (set[length].ecart > p->ecart))
6309 || ((set[length].GetpFDeg() + set[length].ecart == o)
6310 && (set[length].ecart == p->ecart)
6311 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6312 return length+1;
6313 int i;
6314 int an = 0;
6315 int en= length;
6316 loop
6317 {
6318 if (an >= en-1)
6319 {
6320 if ((set[an].GetpFDeg() + set[an].ecart > o)
6321 || ((set[an].GetpFDeg() + set[an].ecart == o)
6322 && (set[an].ecart > p->ecart))
6323 || ((set[an].GetpFDeg() + set[an].ecart == o)
6324 && (set[an].ecart == p->ecart)
6325 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6326 return en;
6327 return an;
6328 }
6329 i=(an+en) / 2;
6330 if ((set[i].GetpFDeg() + set[i].ecart > o)
6331 || ((set[i].GetpFDeg() + set[i].ecart == o)
6332 && (set[i].ecart > p->ecart))
6333 || ((set[i].GetpFDeg() +set[i].ecart == o)
6334 && (set[i].ecart == p->ecart)
6335 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6336 an=i;
6337 else
6338 en=i;
6339 }
6340}
6341
6342/*2
6343* looks up the position of polynomial p in set
6344* e is the ecart of p
6345* set[length] is the smallest element in set with respect
6346* to the ordering-procedure pComp
6347*/
6348int posInL17_c (const LSet set, const int length,
6349 LObject* p,const kStrategy)
6350{
6351 if (length<0) return 0;
6352
6353 int cc = (-1+2*currRing->order[0]==ringorder_c);
6354 /* cc==1 for (c,..), cc==-1 for (C,..) */
6355 long c = pGetComp(p->p)*cc;
6356 int o = p->GetpFDeg() + p->ecart;
6357 int cmp_int= -currRing->OrdSgn;
6358
6359 if (pGetComp(set[length].p)*cc > c)
6360 return length+1;
6361 if (pGetComp(set[length].p)*cc == c)
6362 {
6363 if ((set[length].GetpFDeg() + set[length].ecart > o)
6364 || ((set[length].GetpFDeg() + set[length].ecart == o)
6365 && (set[length].ecart > p->ecart))
6366 || ((set[length].GetpFDeg() + set[length].ecart == o)
6367 && (set[length].ecart == p->ecart)
6368 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6369 return length+1;
6370 }
6371 int i;
6372 int an = 0;
6373 int en= length;
6374 loop
6375 {
6376 if (an >= en-1)
6377 {
6378 if (pGetComp(set[an].p)*cc > c)
6379 return en;
6380 if (pGetComp(set[an].p)*cc == c)
6381 {
6382 if ((set[an].GetpFDeg() + set[an].ecart > o)
6383 || ((set[an].GetpFDeg() + set[an].ecart == o)
6384 && (set[an].ecart > p->ecart))
6385 || ((set[an].GetpFDeg() + set[an].ecart == o)
6386 && (set[an].ecart == p->ecart)
6387 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6388 return en;
6389 }
6390 return an;
6391 }
6392 i=(an+en) / 2;
6393 if (pGetComp(set[i].p)*cc > c)
6394 an=i;
6395 else if (pGetComp(set[i].p)*cc == c)
6396 {
6397 if ((set[i].GetpFDeg() + set[i].ecart > o)
6398 || ((set[i].GetpFDeg() + set[i].ecart == o)
6399 && (set[i].ecart > p->ecart))
6400 || ((set[i].GetpFDeg() +set[i].ecart == o)
6401 && (set[i].ecart == p->ecart)
6402 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6403 an=i;
6404 else
6405 en=i;
6406 }
6407 else
6408 en=i;
6409 }
6410}
6411
6412int posInL17_cRing (const LSet set, const int length,
6413 LObject* p,const kStrategy)
6414{
6415 if (length<0) return 0;
6416
6417 int cc = (-1+2*currRing->order[0]==ringorder_c);
6418 /* cc==1 for (c,..), cc==-1 for (C,..) */
6419 long c = pGetComp(p->p)*cc;
6420 int o = p->GetpFDeg() + p->ecart;
6421
6422 if (pGetComp(set[length].p)*cc > c)
6423 return length+1;
6424 if (pGetComp(set[length].p)*cc == c)
6425 {
6426 if ((set[length].GetpFDeg() + set[length].ecart > o)
6427 || ((set[length].GetpFDeg() + set[length].ecart == o)
6428 && (set[length].ecart > p->ecart))
6429 || ((set[length].GetpFDeg() + set[length].ecart == o)
6430 && (set[length].ecart == p->ecart)
6431 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6432 return length+1;
6433 }
6434 int i;
6435 int an = 0;
6436 int en= length;
6437 loop
6438 {
6439 if (an >= en-1)
6440 {
6441 if (pGetComp(set[an].p)*cc > c)
6442 return en;
6443 if (pGetComp(set[an].p)*cc == c)
6444 {
6445 if ((set[an].GetpFDeg() + set[an].ecart > o)
6446 || ((set[an].GetpFDeg() + set[an].ecart == o)
6447 && (set[an].ecart > p->ecart))
6448 || ((set[an].GetpFDeg() + set[an].ecart == o)
6449 && (set[an].ecart == p->ecart)
6450 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6451 return en;
6452 }
6453 return an;
6454 }
6455 i=(an+en) / 2;
6456 if (pGetComp(set[i].p)*cc > c)
6457 an=i;
6458 else if (pGetComp(set[i].p)*cc == c)
6459 {
6460 if ((set[i].GetpFDeg() + set[i].ecart > o)
6461 || ((set[i].GetpFDeg() + set[i].ecart == o)
6462 && (set[i].ecart > p->ecart))
6463 || ((set[i].GetpFDeg() +set[i].ecart == o)
6464 && (set[i].ecart == p->ecart)
6465 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6466 an=i;
6467 else
6468 en=i;
6469 }
6470 else
6471 en=i;
6472 }
6473}
6474
6475/*
6476 * SYZYGY CRITERION for signature-based standard basis algorithms
6477 */
6478BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6479{
6480//#if 1
6481#ifdef DEBUGF5
6482 PrintS("syzygy criterion checks: ");
6483 pWrite(sig);
6484#endif
6485 for (int k=0; k<strat->syzl; k++)
6486 {
6487 //printf("-%d",k);
6488//#if 1
6489#ifdef DEBUGF5
6490 Print("checking with: %d / %d -- \n",k,strat->syzl);
6491 pWrite(pHead(strat->syz[k]));
6492#endif
6493 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6494 && (!rField_is_Ring(currRing) ||
6495 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6496 {
6497//#if 1
6498#ifdef DEBUGF5
6499 PrintS("DELETE!\n");
6500#endif
6501 strat->nrsyzcrit++;
6502 //printf("- T -\n\n");
6503 return TRUE;
6504 }
6505 }
6506 //printf("- F -\n\n");
6507 return FALSE;
6508}
6509
6510/*
6511 * SYZYGY CRITERION for signature-based standard basis algorithms
6512 */
6513BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6514{
6515//#if 1
6516 if(sig == NULL)
6517 return FALSE;
6518#ifdef DEBUGF5
6519 PrintS("--- syzygy criterion checks: ");
6520 pWrite(sig);
6521#endif
6522 int comp = (int)__p_GetComp(sig, currRing);
6523 int min, max;
6524 if (comp<=1)
6525 return FALSE;
6526 else
6527 {
6528 min = strat->syzIdx[comp-2];
6529 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
6530 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
6531 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
6532 if (comp == strat->currIdx)
6533 {
6534 max = strat->syzl;
6535 }
6536 else
6537 {
6538 max = strat->syzIdx[comp-1];
6539 }
6540 for (int k=min; k<max; k++)
6541 {
6542#ifdef F5DEBUG
6543 Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
6544 Print("checking with: %d -- ",k);
6545 pWrite(pHead(strat->syz[k]));
6546#endif
6547 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6548 && (!rField_is_Ring(currRing) ||
6549 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6550 {
6551 strat->nrsyzcrit++;
6552 return TRUE;
6553 }
6554 }
6555 return FALSE;
6556 }
6557}
6558
6559/*
6560 * REWRITTEN CRITERION for signature-based standard basis algorithms
6561 */
6562BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
6563{
6564 //printf("Faugere Rewritten Criterion\n");
6566 return FALSE;
6567//#if 1
6568#ifdef DEBUGF5
6569 PrintS("rewritten criterion checks: ");
6570 pWrite(sig);
6571#endif
6572 for(int k = strat->sl; k>=start; k--)
6573 {
6574//#if 1
6575#ifdef DEBUGF5
6576 PrintS("checking with: ");
6577 pWrite(strat->sig[k]);
6578 pWrite(pHead(strat->S[k]));
6579#endif
6580 if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
6581 {
6582//#if 1
6583#ifdef DEBUGF5
6584 PrintS("DELETE!\n");
6585#endif
6586 strat->nrrewcrit++;
6587 return TRUE;
6588 }
6589 //k--;
6590 }
6591#ifdef DEBUGF5
6592 PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
6593 for(int kk = 0; kk<strat->sl+1; kk++)
6594 {
6595 pWrite(pHead(strat->S[kk]));
6596 }
6597 PrintS("------------------------------\n");
6598#endif
6599 return FALSE;
6600}
6601
6602/*
6603 * REWRITTEN CRITERION for signature-based standard basis algorithms
6604 ***************************************************************************
6605 * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
6606 ***************************************************************************
6607 */
6608
6609// real implementation of arri's rewritten criterion, only called once in
6610// kstd2.cc, right before starting reduction
6611// IDEA: Arri says that it is enough to consider 1 polynomial for each unique
6612// signature appearing during the computations. Thus we first of all go
6613// through strat->L and delete all other pairs of the same signature,
6614// keeping only the one with least possible leading monomial. After this
6615// we check if we really need to compute this critical pair at all: There
6616// can be elements already in strat->S whose signatures divide the
6617// signature of the critical pair in question and whose multiplied
6618// leading monomials are smaller than the leading monomial of the
6619// critical pair. In this situation we can discard the critical pair
6620// completely.
6621BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
6622{
6624 return FALSE;
6625 poly p1 = pOne();
6626 poly p2 = pOne();
6627 for (int ii=strat->sl; ii>start; ii--)
6628 {
6629 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
6630 {
6631 p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
6632 p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
6633 if (!(pLmCmp(p1,p2) == 1))
6634 {
6635 pDelete(&p1);
6636 pDelete(&p2);
6637 return TRUE;
6638 }
6639 }
6640 }
6641 pDelete(&p1);
6642 pDelete(&p2);
6643 return FALSE;
6644}
6645
6646BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
6647{
6648 //Over Rings, there are still some changes to do: considering coeffs
6650 return FALSE;
6651 int found = -1;
6652 for (int i=strat->Bl; i>-1; i--)
6653 {
6654 if (pLmEqual(strat->B[i].sig,sig))
6655 {
6656 found = i;
6657 break;
6658 }
6659 }
6660 if (found != -1)
6661 {
6662 if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
6663 {
6664 deleteInL(strat->B,&strat->Bl,found,strat);
6665 }
6666 else
6667 {
6668 return TRUE;
6669 }
6670 }
6671 poly p1 = pOne();
6672 poly p2 = pOne();
6673 for (int ii=strat->sl; ii>-1; ii--)
6674 {
6675 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
6676 {
6677 p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
6678 p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
6679 if (!(pLmCmp(p1,p2) == 1))
6680 {
6681 pDelete(&p1);
6682 pDelete(&p2);
6683 return TRUE;
6684 }
6685 }
6686 }
6687 pDelete(&p1);
6688 pDelete(&p2);
6689 return FALSE;
6690}
6691
6692/***************************************************************
6693 *
6694 * Tail reductions
6695 *
6696 ***************************************************************/
6697TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
6698{
6699 int j = 0;
6700 const unsigned long not_sev = ~L->sev;
6701 const unsigned long* sev = strat->sevS;
6702 poly p;
6703 ring r;
6704 L->GetLm(p, r);
6705
6706 assume(~not_sev == p_GetShortExpVector(p, r));
6707
6708 if (r == currRing)
6709 {
6710 if(!rField_is_Ring(r))
6711 {
6712 loop
6713 {
6714 if (j > end_pos) return NULL;
6715 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6716 if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
6717 (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6718 #else
6719 if (!(sev[j] & not_sev) &&
6720 (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
6721 p_LmDivisibleBy(strat->S[j], p, r))
6722 #endif
6723 {
6724 break;
6725 }
6726 j++;
6727 }
6728 }
6729 else
6730 {
6731 loop
6732 {
6733 if (j > end_pos) return NULL;
6734 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6735 if (strat->S[j]!= NULL
6736 && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r)
6737 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6738 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6739 #else
6740 if (!(sev[j] & not_sev)
6741 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6742 && p_LmDivisibleBy(strat->S[j], p, r)
6743 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6744 #endif
6745 {
6746 break; // found
6747 }
6748 j++;
6749 }
6750 }
6751 // if called from NF, T objects do not exist:
6752 if (strat->tl < 0 || strat->S_2_R[j] == -1)
6753 {
6754 T->Set(strat->S[j], r, strat->tailRing);
6755 assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
6756 return T;
6757 }
6758 else
6759 {
6760///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
6761///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
6762// assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
6763 return strat->S_2_T(j);
6764 }
6765 }
6766 else
6767 {
6768 TObject* t;
6769 if(!rField_is_Ring(r))
6770 {
6771 loop
6772 {
6773 if (j > end_pos) return NULL;
6774 assume(strat->S_2_R[j] != -1);
6775 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6776 t = strat->S_2_T(j);
6777 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6778 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6779 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6780 {
6781 t->pLength=pLength(t->t_p);
6782 return t;
6783 }
6784 #else
6785 if (! (sev[j] & not_sev)
6786 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6787 {
6788 t = strat->S_2_T(j);
6789 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6790 if (p_LmDivisibleBy(t->t_p, p, r))
6791 {
6792 t->pLength=pLength(t->t_p);
6793 return t;
6794 }
6795 }
6796 #endif
6797 j++;
6798 }
6799 }
6800 else
6801 {
6802 loop
6803 {
6804 if (j > end_pos) return NULL;
6805 assume(strat->S_2_R[j] != -1);
6806 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6807 t = strat->S_2_T(j);
6808 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6809 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6810 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6811 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6812 {
6813 t->pLength=pLength(t->t_p);
6814 return t;
6815 }
6816 #else
6817 if (! (sev[j] & not_sev)
6818 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6819 {
6820 t = strat->S_2_T(j);
6821 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6822 if (p_LmDivisibleBy(t->t_p, p, r)
6823 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6824 {
6825 t->pLength=pLength(t->t_p);
6826 return t;
6827 }
6828 }
6829 #endif
6830 j++;
6831 }
6832 }
6833 }
6834}
6835
6836poly redtail (LObject* L, int end_pos, kStrategy strat)
6837{
6838 poly h, hn;
6839 strat->redTailChange=FALSE;
6840
6841 L->GetP();
6842 poly p = L->p;
6843 if (strat->noTailReduction || pNext(p) == NULL)
6844 return p;
6845
6846 LObject Ln(strat->tailRing);
6847 TObject* With;
6848 // placeholder in case strat->tl < 0
6849 TObject With_s(strat->tailRing);
6850 h = p;
6851 hn = pNext(h);
6852 long op = strat->tailRing->pFDeg(hn, strat->tailRing);
6853 long e;
6854 int l;
6855 BOOLEAN save_HE=strat->kAllAxis;
6856 strat->kAllAxis |=
6857 ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
6858
6859 while(hn != NULL)
6860 {
6861 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6862 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6863 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6864 loop
6865 {
6866 Ln.Set(hn, strat->tailRing);
6867 Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
6868 if (strat->kAllAxis)
6869 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
6870 else
6871 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
6872 if (With == NULL) break;
6873 With->length=0;
6874 With->pLength=0;
6875 strat->redTailChange=TRUE;
6876 if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
6877 {
6878 // reducing the tail would violate the exp bound
6879 if (kStratChangeTailRing(strat, L))
6880 {
6881 strat->kAllAxis = save_HE;
6882 return redtail(L, end_pos, strat);
6883 }
6884 else
6885 return NULL;
6886 }
6887 hn = pNext(h);
6888 if (hn == NULL) goto all_done;
6889 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6890 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6891 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6892 }
6893 h = hn;
6894 hn = pNext(h);
6895 }
6896
6897 all_done:
6898 if (strat->redTailChange)
6899 {
6900 L->pLength = 0;
6901 }
6902 strat->kAllAxis = save_HE;
6903 return p;
6904}
6905
6906poly redtail (poly p, int end_pos, kStrategy strat)
6907{
6908 LObject L(p, currRing);
6909 return redtail(&L, end_pos, strat);
6910}
6911
6912poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
6913{
6914 strat->redTailChange=FALSE;
6915 if (strat->noTailReduction) return L->GetLmCurrRing();
6916 poly h, p;
6917 p = h = L->GetLmTailRing();
6918 if ((h==NULL) || (pNext(h)==NULL))
6919 return L->GetLmCurrRing();
6920
6921 TObject* With;
6922 // placeholder in case strat->tl < 0
6923 TObject With_s(strat->tailRing);
6924
6925 LObject Ln(pNext(h), strat->tailRing);
6926 Ln.GetpLength();
6927
6928 pNext(h) = NULL;
6929 if (L->p != NULL)
6930 {
6931 pNext(L->p) = NULL;
6932 if (L->t_p != NULL) pNext(L->t_p) = NULL;
6933 }
6934 L->pLength = 1;
6935
6936 Ln.PrepareRed(strat->use_buckets);
6937
6938 int cnt=REDTAIL_CANONICALIZE;
6939 while(!Ln.IsNull())
6940 {
6941 loop
6942 {
6943 if (TEST_OPT_IDLIFT)
6944 {
6945 if (Ln.p!=NULL)
6946 {
6947 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
6948 }
6949 else
6950 {
6951 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
6952 }
6953 }
6954 Ln.SetShortExpVector();
6955 if (withT)
6956 {
6957 int j;
6958 j = kFindDivisibleByInT(strat, &Ln);
6959 if (j < 0) break;
6960 With = &(strat->T[j]);
6961 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
6962 }
6963 else
6964 {
6965 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
6966 if (With == NULL) break;
6967 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
6968 }
6969 cnt--;
6970 if (cnt==0)
6971 {
6973 /*poly tmp=*/Ln.CanonicalizeP();
6974 if (normalize)
6975 {
6976 Ln.Normalize();
6977 //pNormalize(tmp);
6978 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
6979 }
6980 }
6981 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
6982 {
6983 With->pNorm();
6984 }
6985 strat->redTailChange=TRUE;
6986 if (ksReducePolyTail(L, With, &Ln))
6987 {
6988 // reducing the tail would violate the exp bound
6989 // set a flag and hope for a retry (in bba)
6991 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
6992 do
6993 {
6994 pNext(h) = Ln.LmExtractAndIter();
6995 pIter(h);
6996 L->pLength++;
6997 } while (!Ln.IsNull());
6998 goto all_done;
6999 }
7000 if (Ln.IsNull()) goto all_done;
7001 if (! withT) With_s.Init(currRing);
7002 }
7003 pNext(h) = Ln.LmExtractAndIter();
7004 pIter(h);
7005 pNormalize(h);
7006 L->pLength++;
7007 }
7008
7009 all_done:
7010 Ln.Delete();
7011 if (L->p != NULL) pNext(L->p) = pNext(p);
7012
7013 if (strat->redTailChange)
7014 {
7015 L->length = 0;
7016 L->pLength = 0;
7017 }
7018
7019 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7020 //L->Normalize(); // HANNES: should have a test
7021 kTest_L(L,strat);
7022 return L->GetLmCurrRing();
7023}
7024
7025poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7026{
7027 strat->redTailChange=FALSE;
7028 if (strat->noTailReduction) return L->GetLmCurrRing();
7029 poly h, p;
7030 p = h = L->GetLmTailRing();
7031 if ((h==NULL) || (pNext(h)==NULL))
7032 return L->GetLmCurrRing();
7033
7034 TObject* With;
7035 // placeholder in case strat->tl < 0
7036 TObject With_s(strat->tailRing);
7037
7038 LObject Ln(pNext(h), strat->tailRing);
7039 Ln.pLength = L->GetpLength() - 1;
7040
7041 pNext(h) = NULL;
7042 if (L->p != NULL) pNext(L->p) = NULL;
7043 L->pLength = 1;
7044
7045 Ln.PrepareRed(strat->use_buckets);
7046
7047 int cnt=REDTAIL_CANONICALIZE;
7048 while(!Ln.IsNull())
7049 {
7050 loop
7051 {
7052 if (TEST_OPT_IDLIFT)
7053 {
7054 if (Ln.p!=NULL)
7055 {
7056 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7057 }
7058 else
7059 {
7060 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7061 }
7062 }
7063 Ln.SetShortExpVector();
7064 if (withT)
7065 {
7066 int j;
7067 j = kFindDivisibleByInT(strat, &Ln);
7068 if (j < 0) break;
7069 With = &(strat->T[j]);
7070 }
7071 else
7072 {
7073 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7074 if (With == NULL) break;
7075 }
7076 cnt--;
7077 if (cnt==0)
7078 {
7080 /*poly tmp=*/Ln.CanonicalizeP();
7081 if (normalize)
7082 {
7083 Ln.Normalize();
7084 //pNormalize(tmp);
7085 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7086 }
7087 }
7088 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7089 {
7090 With->pNorm();
7091 }
7092 strat->redTailChange=TRUE;
7093 if (ksReducePolyTail(L, With, &Ln))
7094 {
7095 // reducing the tail would violate the exp bound
7096 // set a flag and hope for a retry (in bba)
7098 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7099 do
7100 {
7101 pNext(h) = Ln.LmExtractAndIter();
7102 pIter(h);
7103 L->pLength++;
7104 } while (!Ln.IsNull());
7105 goto all_done;
7106 }
7107 if(!Ln.IsNull())
7108 {
7109 Ln.GetP();
7110 Ln.p = pJet(Ln.p,bound);
7111 }
7112 if (Ln.IsNull())
7113 {
7114 goto all_done;
7115 }
7116 if (! withT) With_s.Init(currRing);
7117 }
7118 pNext(h) = Ln.LmExtractAndIter();
7119 pIter(h);
7120 pNormalize(h);
7121 L->pLength++;
7122 }
7123
7124 all_done:
7125 Ln.Delete();
7126 if (L->p != NULL) pNext(L->p) = pNext(p);
7127
7128 if (strat->redTailChange)
7129 {
7130 L->length = 0;
7131 L->pLength = 0;
7132 }
7133
7134 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7135 //L->Normalize(); // HANNES: should have a test
7136 kTest_L(L,strat);
7137 return L->GetLmCurrRing();
7138}
7139
7140void redtailBbaAlsoLC_Z (LObject* L, int end_pos, kStrategy strat )
7141// normalize=FALSE, withT=FALSE, coeff=Z
7142{
7143 strat->redTailChange=FALSE;
7144
7145 poly h, p;
7146 p = h = L->GetLmTailRing();
7147 if ((h==NULL) || (pNext(h)==NULL))
7148 return;
7149
7150 TObject* With;
7151 LObject Ln(pNext(h), strat->tailRing);
7152 Ln.GetpLength();
7153
7154 pNext(h) = NULL;
7155 if (L->p != NULL)
7156 {
7157 pNext(L->p) = NULL;
7158 if (L->t_p != NULL) pNext(L->t_p) = NULL;
7159 }
7160 L->pLength = 1;
7161
7162 Ln.PrepareRed(strat->use_buckets);
7163
7164 int cnt=REDTAIL_CANONICALIZE;
7165
7166 while(!Ln.IsNull())
7167 {
7168 loop
7169 {
7170 if (TEST_OPT_IDLIFT)
7171 {
7172 if (Ln.p!=NULL)
7173 {
7174 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7175 }
7176 else
7177 {
7178 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7179 }
7180 }
7181 Ln.SetShortExpVector();
7182 int j;
7183 j = kFindDivisibleByInT(strat, &Ln);
7184 if (j < 0)
7185 {
7186 j = kFindDivisibleByInT_Z(strat, &Ln);
7187 if (j < 0)
7188 {
7189 break;
7190 }
7191 else
7192 {
7193 /* reduction not cancelling a tail term, but reducing its coefficient */
7194 With = &(strat->T[j]);
7195 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7196 cnt--;
7197 if (cnt==0)
7198 {
7200 /*poly tmp=*/Ln.CanonicalizeP();
7201 }
7202 strat->redTailChange=TRUE;
7203 /* reduction cancelling a tail term */
7204 if (ksReducePolyTailLC_Z(L, With, &Ln))
7205 {
7206 // reducing the tail would violate the exp bound
7207 // set a flag and hope for a retry (in bba)
7209 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7210 do
7211 {
7212 pNext(h) = Ln.LmExtractAndIter();
7213 pIter(h);
7214 L->pLength++;
7215 } while (!Ln.IsNull());
7216 goto all_done;
7217 }
7218 /* we have to break since we did not cancel the term, but only decreased
7219 * its coefficient. */
7220 break;
7221 }
7222 } else {
7223 With = &(strat->T[j]);
7224 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7225 cnt--;
7226 if (cnt==0)
7227 {
7229 /*poly tmp=*/Ln.CanonicalizeP();
7230 }
7231 strat->redTailChange=TRUE;
7232 /* reduction cancelling a tail term */
7233 if (ksReducePolyTail_Z(L, With, &Ln))
7234 {
7235 // reducing the tail would violate the exp bound
7236 // set a flag and hope for a retry (in bba)
7238 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7239 do
7240 {
7241 pNext(h) = Ln.LmExtractAndIter();
7242 pIter(h);
7243 L->pLength++;
7244 } while (!Ln.IsNull());
7245 goto all_done;
7246 }
7247 }
7248 if (Ln.IsNull()) goto all_done;
7249 }
7250 pNext(h) = Ln.LmExtractAndIter();
7251 pIter(h);
7252 L->pLength++;
7253 }
7254
7255 all_done:
7256 Ln.Delete();
7257 if (L->p != NULL) pNext(L->p) = pNext(p);
7258
7259 if (strat->redTailChange)
7260 {
7261 L->length = 0;
7262 L->pLength = 0;
7263 }
7264
7265 kTest_L(L, strat);
7266 return;
7267}
7268
7269poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7270// normalize=FALSE, withT=FALSE, coeff=Z
7271{
7272 strat->redTailChange=FALSE;
7273 if (strat->noTailReduction) return L->GetLmCurrRing();
7274 poly h, p;
7275 p = h = L->GetLmTailRing();
7276 if ((h==NULL) || (pNext(h)==NULL))
7277 return L->GetLmCurrRing();
7278
7279 TObject* With;
7280 // placeholder in case strat->tl < 0
7281 TObject With_s(strat->tailRing);
7282
7283 LObject Ln(pNext(h), strat->tailRing);
7284 Ln.pLength = L->GetpLength() - 1;
7285
7286 pNext(h) = NULL;
7287 if (L->p != NULL) pNext(L->p) = NULL;
7288 L->pLength = 1;
7289
7290 Ln.PrepareRed(strat->use_buckets);
7291
7292 int cnt=REDTAIL_CANONICALIZE;
7293 while(!Ln.IsNull())
7294 {
7295 loop
7296 {
7297 Ln.SetShortExpVector();
7298 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7299 if (With == NULL) break;
7300 cnt--;
7301 if (cnt==0)
7302 {
7304 /*poly tmp=*/Ln.CanonicalizeP();
7305 }
7306 // we are in Z, do not call pNorm
7307 strat->redTailChange=TRUE;
7308 // test divisibility of coefs:
7309 Ln.GetLmCurrRing();
7310 With->GetLmCurrRing();
7311
7312 if (ksReducePolyTail_Z(L, With, &Ln))
7313 {
7314 // reducing the tail would violate the exp bound
7315 // set a flag and hope for a retry (in bba)
7317 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7318 do
7319 {
7320 pNext(h) = Ln.LmExtractAndIter();
7321 pIter(h);
7322 L->pLength++;
7323 } while (!Ln.IsNull());
7324 goto all_done;
7325 }
7326 if (Ln.IsNull()) goto all_done;
7327 With_s.Init(currRing);
7328 }
7329 pNext(h) = Ln.LmExtractAndIter();
7330 pIter(h);
7331 pNormalize(h);
7332 L->pLength++;
7333 }
7334
7335 all_done:
7336 Ln.Delete();
7337 if (L->p != NULL) pNext(L->p) = pNext(p);
7338
7339 if (strat->redTailChange)
7340 {
7341 L->length = 0;
7342 }
7343
7344 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7345 //L->Normalize(); // HANNES: should have a test
7346 kTest_L(L,strat);
7347 return L->GetLmCurrRing();
7348}
7349
7350poly redtailBba_NF (poly p, kStrategy strat )
7351{
7352 strat->redTailChange=FALSE;
7353 if (strat->noTailReduction) return p;
7354 if ((p==NULL) || (pNext(p)==NULL))
7355 return p;
7356
7357 int max_ind;
7358 poly h=p;
7359 p=pNext(p);
7360 pNext(h)=NULL;
7361 while(p!=NULL)
7362 {
7363 p=redNF(p,max_ind,1,strat);
7364 if (p!=NULL)
7365 {
7366 poly hh=p;
7367 p=pNext(p);
7368 pNext(hh)=NULL;
7369 h=p_Add_q(h,hh,currRing);
7370 }
7371 }
7372 return h;
7373}
7374
7375poly redtailBba_Ring (LObject* L, int end_pos, kStrategy strat )
7376// normalize=FALSE, withT=FALSE, coeff=Ring
7377{
7378 strat->redTailChange=FALSE;
7379 if (strat->noTailReduction) return L->GetLmCurrRing();
7380 poly h, p;
7381 p = h = L->GetLmTailRing();
7382 if ((h==NULL) || (pNext(h)==NULL))
7383 return L->GetLmCurrRing();
7384
7385 TObject* With;
7386 // placeholder in case strat->tl < 0
7387 TObject With_s(strat->tailRing);
7388
7389 LObject Ln(pNext(h), strat->tailRing);
7390 Ln.pLength = L->GetpLength() - 1;
7391
7392 pNext(h) = NULL;
7393 if (L->p != NULL) pNext(L->p) = NULL;
7394 L->pLength = 1;
7395
7396 Ln.PrepareRed(strat->use_buckets);
7397
7398 int cnt=REDTAIL_CANONICALIZE;
7399 while(!Ln.IsNull())
7400 {
7401 loop
7402 {
7403 Ln.SetShortExpVector();
7404 With_s.Init(currRing);
7405 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7406 if (With == NULL) break;
7407 cnt--;
7408 if (cnt==0)
7409 {
7411 /*poly tmp=*/Ln.CanonicalizeP();
7412 }
7413 // we are in a ring, do not call pNorm
7414 // test divisibility of coefs:
7415 poly p_Ln=Ln.GetLmCurrRing();
7416 poly p_With=With->GetLmCurrRing();
7417 if (n_DivBy(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf))
7418 {
7419 strat->redTailChange=TRUE;
7420
7421 if (ksReducePolyTail_Z(L, With, &Ln))
7422 {
7423 // reducing the tail would violate the exp bound
7424 // set a flag and hope for a retry (in bba)
7426 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7427 do
7428 {
7429 pNext(h) = Ln.LmExtractAndIter();
7430 pIter(h);
7431 L->pLength++;
7432 } while (!Ln.IsNull());
7433 goto all_done;
7434 }
7435 }
7436 else break; /*proceed to next monomial*/
7437 if (Ln.IsNull()) goto all_done;
7438 }
7439 pNext(h) = Ln.LmExtractAndIter();
7440 pIter(h);
7441 pNormalize(h);
7442 L->pLength++;
7443 }
7444
7445 all_done:
7446 Ln.Delete();
7447 if (L->p != NULL) pNext(L->p) = pNext(p);
7448
7449 if (strat->redTailChange)
7450 {
7451 L->length = 0;
7452 }
7453
7454 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7455 //L->Normalize(); // HANNES: should have a test
7456 kTest_L(L,strat);
7457 return L->GetLmCurrRing();
7458}
7459
7460/*2
7461*checks the change degree and write progress report
7462*/
7463void message (int i,int* olddeg,int* reduc,kStrategy strat, int red_result)
7464{
7465 if (i != *olddeg)
7466 {
7467 Print("%d",i);
7468 *olddeg = i;
7469 }
7470 if (TEST_OPT_OLDSTD)
7471 {
7472 if (strat->Ll != *reduc)
7473 {
7474 if (strat->Ll != *reduc-1)
7475 Print("(%d)",strat->Ll+1);
7476 else
7477 PrintS("-");
7478 *reduc = strat->Ll;
7479 }
7480 else
7481 PrintS(".");
7482 mflush();
7483 }
7484 else
7485 {
7486 if (red_result == 0)
7487 PrintS("-");
7488 else if (red_result < 0)
7489 PrintS(".");
7490 if ((red_result > 0) || ((strat->Ll % 100)==99))
7491 {
7492 if (strat->Ll != *reduc && strat->Ll > 0)
7493 {
7494 Print("(%d)",strat->Ll+1);
7495 *reduc = strat->Ll;
7496 }
7497 }
7498 }
7499}
7500
7501/*2
7502*statistics
7503*/
7504void messageStat (int hilbcount,kStrategy strat)
7505{
7506 //PrintS("\nUsage/Allocation of temporary storage:\n");
7507 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7508 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7509 Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7510 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7511 #ifdef HAVE_SHIFTBBA
7512 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7513 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7514 #endif
7515}
7516
7517void messageStatSBA (int hilbcount,kStrategy strat)
7518{
7519 //PrintS("\nUsage/Allocation of temporary storage:\n");
7520 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7521 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7522 Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7523 //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7524 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7525 #ifdef HAVE_SHIFTBBA
7526 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7527 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7528 #endif
7529}
7530
7531#ifdef KDEBUG
7532/*2
7533*debugging output: all internal sets, if changed
7534*for testing purpose only/has to be changed for later use
7535*/
7537{
7538 int i;
7539 if (strat->news)
7540 {
7541 PrintS("set S");
7542 for (i=0; i<=strat->sl; i++)
7543 {
7544 Print("\n %d:",i);
7545 p_wrp(strat->S[i], currRing, strat->tailRing);
7546 if (strat->fromQ!=NULL && strat->fromQ[i])
7547 Print(" (from Q)");
7548 }
7549 strat->news = FALSE;
7550 }
7551 if (strat->newt)
7552 {
7553 PrintS("\nset T");
7554 for (i=0; i<=strat->tl; i++)
7555 {
7556 Print("\n %d:",i);
7557 strat->T[i].wrp();
7558 if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7559 Print(" o:%ld e:%d l:%d",
7560 strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7561 }
7562 strat->newt = FALSE;
7563 }
7564 PrintS("\nset L");
7565 for (i=strat->Ll; i>=0; i--)
7566 {
7567 Print("\n%d:",i);
7568 p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7569 PrintS(" ");
7570 p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7571 PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7572 PrintS("\n p : ");
7573 strat->L[i].wrp();
7574 Print(" o:%ld e:%d l:%d",
7575 strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7576 }
7577 PrintLn();
7578}
7579
7580#endif
7581
7582
7583/*2
7584*construct the set s from F
7585*/
7586void initS (ideal F, ideal Q, kStrategy strat)
7587{
7588 int i,pos;
7589
7591 else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7592 if (i<setmaxTinc) i=setmaxT;
7593 strat->ecartS=initec(i);
7594 strat->sevS=initsevS(i);
7595 strat->S_2_R=initS_2_R(i);
7596 strat->fromQ=NULL;
7597 strat->Shdl=idInit(i,F->rank);
7598 strat->S=strat->Shdl->m;
7599 /*- put polys into S -*/
7600 if (Q!=NULL)
7601 {
7602 strat->fromQ=initec(i);
7603 memset(strat->fromQ,0,i*sizeof(int));
7604 for (i=0; i<IDELEMS(Q); i++)
7605 {
7606 if (Q->m[i]!=NULL)
7607 {
7608 LObject h;
7609 h.p = pCopy(Q->m[i]);
7611 {
7612 h.pCleardenom(); // also does remove Content
7613 }
7614 else
7615 {
7616 h.pNorm();
7617 }
7619 {
7620 deleteHC(&h, strat);
7621 }
7622 if (h.p!=NULL)
7623 {
7624 strat->initEcart(&h);
7625 if (strat->sl==-1)
7626 pos =0;
7627 else
7628 {
7629 pos = posInS(strat,strat->sl,h.p,h.ecart);
7630 }
7631 h.sev = pGetShortExpVector(h.p);
7632 strat->enterS(&h,pos,strat,-1);
7633 strat->fromQ[pos]=1;
7634 }
7635 }
7636 }
7637 }
7638 for (i=0; i<IDELEMS(F); i++)
7639 {
7640 if (F->m[i]!=NULL)
7641 {
7642 LObject h;
7643 h.p = pCopy(F->m[i]);
7645 {
7646 cancelunit(&h); /*- tries to cancel a unit -*/
7647 deleteHC(&h, strat);
7648 }
7649 if (h.p!=NULL)
7650 // do not rely on the input being a SB!
7651 {
7653 {
7654 h.pCleardenom(); // also does remove Content
7655 }
7656 else
7657 {
7658 h.pNorm();
7659 }
7660 strat->initEcart(&h);
7661 if (strat->sl==-1)
7662 pos =0;
7663 else
7664 pos = posInS(strat,strat->sl,h.p,h.ecart);
7665 h.sev = pGetShortExpVector(h.p);
7666 strat->enterS(&h,pos,strat,-1);
7667 }
7668 }
7669 }
7670 /*- test, if a unit is in F -*/
7671 if ((strat->sl>=0)
7672 && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7673 && pIsConstant(strat->S[0]))
7674 {
7675 while (strat->sl>0) deleteInS(strat->sl,strat);
7676 }
7677}
7678
7679void initSL (ideal F, ideal Q,kStrategy strat)
7680{
7681 int i,pos;
7682
7683 if (Q!=NULL)
7684 {
7686 if (i<setmaxTinc) i=setmaxT;
7687 }
7688 else i=setmaxT;
7689 strat->ecartS=initec(i);
7690 strat->sevS=initsevS(i);
7691 strat->S_2_R=initS_2_R(i);
7692 strat->fromQ=NULL;
7693 strat->Shdl=idInit(i,F->rank);
7694 strat->S=strat->Shdl->m;
7695 /*- put polys into S -*/
7696 if (Q!=NULL)
7697 {
7698 strat->fromQ=initec(i);
7699 memset(strat->fromQ,0,i*sizeof(int));
7700 for (i=0; i<IDELEMS(Q); i++)
7701 {
7702 if (Q->m[i]!=NULL)
7703 {
7704 LObject h;
7705 h.p = pCopy(Q->m[i]);
7707 {
7708 deleteHC(&h,strat);
7709 cancelunit(&h); /*- tries to cancel a unit -*/
7710 }
7712 {
7713 h.pCleardenom(); // also does remove Content
7714 }
7715 else
7716 {
7717 h.pNorm();
7718 }
7719 if (h.p!=NULL)
7720 {
7721 strat->initEcart(&h);
7722 if (strat->sl==-1)
7723 pos =0;
7724 else
7725 {
7726 pos = posInS(strat,strat->sl,h.p,h.ecart);
7727 }
7728 h.sev = pGetShortExpVector(h.p);
7729 strat->enterS(&h,pos,strat,-1);
7730 strat->fromQ[pos]=1;
7731 }
7732 if(errorreported) return;
7733 }
7734 }
7735 }
7736 for (i=0; i<IDELEMS(F); i++)
7737 {
7738 if (F->m[i]!=NULL)
7739 {
7740 LObject h;
7741 h.p = pCopy(F->m[i]);
7742 if (h.p!=NULL)
7743 {
7745 {
7746 cancelunit(&h); /*- tries to cancel a unit -*/
7747 deleteHC(&h, strat);
7748 }
7749 if (h.p!=NULL)
7750 {
7752 {
7753 h.pCleardenom(); // also does remove Content
7754 }
7755 else
7756 {
7757 h.pNorm();
7758 }
7759 if(errorreported) return;
7760 strat->initEcart(&h);
7761 if (strat->Ll==-1)
7762 pos =0;
7763 else
7764 pos = strat->posInL(strat->L,strat->Ll,&h,strat);
7765 h.sev = pGetShortExpVector(h.p);
7766 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7767 }
7768 }
7769 }
7770 }
7771 /*- test, if a unit is in F -*/
7772
7773 if ((strat->Ll>=0)
7774 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7775 && pIsConstant(strat->L[strat->Ll].p))
7776 {
7777 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7778 }
7779}
7780
7781void initSLSba (ideal F, ideal Q,kStrategy strat)
7782{
7783 int i,pos;
7784 if (Q!=NULL)
7785 {
7787 if (i<setmaxTinc) i=setmaxT;
7788 }
7789 else i=setmaxT;
7790 strat->ecartS = initec(i);
7791 strat->sevS = initsevS(i);
7792 strat->sevSig = initsevS(i);
7793 strat->S_2_R = initS_2_R(i);
7794 strat->fromQ = NULL;
7795 strat->Shdl = idInit(i,F->rank);
7796 strat->S = strat->Shdl->m;
7797 strat->sig = (poly *)omAlloc0(i*sizeof(poly));
7798 if (strat->sbaOrder != 1)
7799 {
7800 strat->syz = (poly *)omAlloc0(i*sizeof(poly));
7801 strat->sevSyz = initsevS(i);
7802 strat->syzmax = i;
7803 strat->syzl = 0;
7804 }
7805 /*- put polys into S -*/
7806 if (Q!=NULL)
7807 {
7808 strat->fromQ=initec(i);
7809 memset(strat->fromQ,0,i*sizeof(int));
7810 for (i=0; i<IDELEMS(Q); i++)
7811 {
7812 if (Q->m[i]!=NULL)
7813 {
7814 LObject h;
7815 h.p = pCopy(Q->m[i]);
7817 {
7818 deleteHC(&h,strat);
7819 }
7821 {
7822 h.pCleardenom(); // also does remove Content
7823 }
7824 else
7825 {
7826 h.pNorm();
7827 }
7828 if (h.p!=NULL)
7829 {
7830 strat->initEcart(&h);
7831 if (strat->sl==-1)
7832 pos =0;
7833 else
7834 {
7835 pos = posInS(strat,strat->sl,h.p,h.ecart);
7836 }
7837 h.sev = pGetShortExpVector(h.p);
7838 strat->enterS(&h,pos,strat,-1);
7839 strat->fromQ[pos]=1;
7840 }
7841 }
7842 }
7843 }
7844 for (i=0; i<IDELEMS(F); i++)
7845 {
7846 if (F->m[i]!=NULL)
7847 {
7848 LObject h;
7849 h.p = pCopy(F->m[i]);
7850 h.sig = pOne();
7851 //h.sig = pInit();
7852 //p_SetCoeff(h.sig,nInit(1),currRing);
7853 p_SetComp(h.sig,i+1,currRing);
7854 // if we are working with the Schreyer order we generate it
7855 // by multiplying the initial signatures with the leading monomial
7856 // of the corresponding initial polynomials generating the ideal
7857 // => we can keep the underlying monomial order and get a Schreyer
7858 // order without any bigger overhead
7859 if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
7860 {
7861 p_ExpVectorAdd (h.sig,F->m[i],currRing);
7862 }
7863 h.sevSig = pGetShortExpVector(h.sig);
7864#ifdef DEBUGF5
7865 pWrite(h.p);
7866 pWrite(h.sig);
7867#endif
7868 if (h.p!=NULL)
7869 {
7871 {
7872 cancelunit(&h); /*- tries to cancel a unit -*/
7873 deleteHC(&h, strat);
7874 }
7875 if (h.p!=NULL)
7876 {
7878 {
7879 h.pCleardenom(); // also does remove Content
7880 }
7881 else
7882 {
7883 h.pNorm();
7884 }
7885 strat->initEcart(&h);
7886 if (strat->Ll==-1)
7887 pos =0;
7888 else
7889 pos = strat->posInL(strat->L,strat->Ll,&h,strat);
7890 h.sev = pGetShortExpVector(h.p);
7891 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7892 }
7893 }
7894 /*
7895 if (strat->sbaOrder != 1)
7896 {
7897 for(j=0;j<i;j++)
7898 {
7899 strat->syz[ctr] = pCopy(F->m[j]);
7900 p_SetCompP(strat->syz[ctr],i+1,currRing);
7901 // add LM(F->m[i]) to the signature to get a Schreyer order
7902 // without changing the underlying polynomial ring at all
7903 p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
7904 // since p_Add_q() destroys all input
7905 // data we need to recreate help
7906 // each time
7907 poly help = pCopy(F->m[i]);
7908 p_SetCompP(help,j+1,currRing);
7909 pWrite(strat->syz[ctr]);
7910 pWrite(help);
7911 printf("%d\n",pLmCmp(strat->syz[ctr],help));
7912 strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
7913 printf("%d. SYZ ",ctr);
7914 pWrite(strat->syz[ctr]);
7915 strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
7916 ctr++;
7917 }
7918 strat->syzl = ps;
7919 }
7920 */
7921 }
7922 }
7923 /*- test, if a unit is in F -*/
7924
7925 if ((strat->Ll>=0)
7926 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7927 && pIsConstant(strat->L[strat->Ll].p))
7928 {
7929 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7930 }
7931}
7932
7934{
7935 if( strat->S[0] )
7936 {
7937 if( strat->S[1] && !rField_is_Ring(currRing))
7938 {
7939 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
7940 omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
7941 omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
7942 }
7943 int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
7944 /************************************************************
7945 * computing the length of the syzygy array needed
7946 ***********************************************************/
7947 for(i=1; i<=strat->sl; i++)
7948 {
7949 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
7950 {
7951 ps += i;
7952 }
7953 }
7954 ps += strat->sl+1;
7955 //comp = pGetComp (strat->P.sig);
7956 comp = strat->currIdx;
7957 strat->syzIdx = initec(comp);
7958 strat->sevSyz = initsevS(ps);
7959 strat->syz = (poly *)omAlloc(ps*sizeof(poly));
7960 strat->syzmax = ps;
7961 strat->syzl = 0;
7962 strat->syzidxmax = comp;
7963#if defined(DEBUGF5) || defined(DEBUGF51)
7964 PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
7965#endif
7966 i = 1;
7967 j = 0;
7968 /************************************************************
7969 * generating the leading terms of the principal syzygies
7970 ***********************************************************/
7971 while (i <= strat->sl)
7972 {
7973 /**********************************************************
7974 * principal syzygies start with component index 2
7975 * the array syzIdx starts with index 0
7976 * => the rules for a signature with component comp start
7977 * at strat->syz[strat->syzIdx[comp-2]] !
7978 *********************************************************/
7979 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
7980 {
7981 comp = pGetComp(strat->sig[i]);
7982 comp_old = pGetComp(strat->sig[i-1]);
7983 diff = comp - comp_old - 1;
7984 // diff should be zero, but sometimes also the initial generating
7985 // elements of the input ideal reduce to zero. then there is an
7986 // index-gap between the signatures. for these in-between signatures we
7987 // can safely set syzIdx[j] = 0 as no such element will be ever computed
7988 // in the following.
7989 // doing this, we keep the relation "j = comp - 2" alive, which makes
7990 // jumps way easier when checking criteria
7991 while (diff>0)
7992 {
7993 strat->syzIdx[j] = 0;
7994 diff--;
7995 j++;
7996 }
7997 strat->syzIdx[j] = ctr;
7998 j++;
7999 LObject Q;
8000 int pos;
8001 for (k = 0; k<i; k++)
8002 {
8003 Q.sig = pOne();
8006 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8007 p_SetCompP (Q.sig, comp, currRing);
8008 poly q = p_One(currRing);
8011 p_ExpVectorCopy(q,strat->S[i],currRing);
8012 q = p_Neg (q, currRing);
8013 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8014 Q.sig = p_Add_q (Q.sig, q, currRing);
8015 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8016 pos = posInSyz(strat, Q.sig);
8017 enterSyz(Q, strat, pos);
8018 ctr++;
8019 }
8020 }
8021 i++;
8022 }
8023 /**************************************************************
8024 * add syzygies for upcoming first element of new iteration step
8025 **************************************************************/
8026 comp = strat->currIdx;
8027 comp_old = pGetComp(strat->sig[i-1]);
8028 diff = comp - comp_old - 1;
8029 // diff should be zero, but sometimes also the initial generating
8030 // elements of the input ideal reduce to zero. then there is an
8031 // index-gap between the signatures. for these in-between signatures we
8032 // can safely set syzIdx[j] = 0 as no such element will be ever computed
8033 // in the following.
8034 // doing this, we keep the relation "j = comp - 2" alive, which makes
8035 // jumps way easier when checking criteria
8036 while (diff>0)
8037 {
8038 strat->syzIdx[j] = 0;
8039 diff--;
8040 j++;
8041 }
8042 strat->syzIdx[j] = ctr;
8043 LObject Q;
8044 int pos;
8045 for (k = 0; k<strat->sl+1; k++)
8046 {
8047 Q.sig = pOne();
8050 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8051 p_SetCompP (Q.sig, comp, currRing);
8052 poly q = p_One(currRing);
8054 p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8055 p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8056 q = p_Neg (q, currRing);
8057 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8058 Q.sig = p_Add_q (Q.sig, q, currRing);
8059 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8060 pos = posInSyz(strat, Q.sig);
8061 enterSyz(Q, strat, pos);
8062 ctr++;
8063 }
8064//#if 1
8065#ifdef DEBUGF5
8066 PrintS("Principal syzygies:\n");
8067 Print("syzl %d\n",strat->syzl);
8068 Print("syzmax %d\n",strat->syzmax);
8069 Print("ps %d\n",ps);
8070 PrintS("--------------------------------\n");
8071 for(i=0;i<=strat->syzl-1;i++)
8072 {
8073 Print("%d - ",i);
8074 pWrite(strat->syz[i]);
8075 }
8076 for(i=0;i<strat->currIdx;i++)
8077 {
8078 Print("%d - %d\n",i,strat->syzIdx[i]);
8079 }
8080 PrintS("--------------------------------\n");
8081#endif
8082 }
8083}
8084
8085/*2
8086*construct the set s from F and {P}
8087*/
8088void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8089{
8090 int i,pos;
8091
8092 if (Q!=NULL)
8093 {
8095 if (i<setmaxTinc) i=setmaxT;
8096 }
8097 else i=setmaxT;
8098 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8099 strat->ecartS=initec(i);
8100 strat->sevS=initsevS(i);
8101 strat->S_2_R=initS_2_R(i);
8102 strat->fromQ=NULL;
8103 strat->Shdl=idInit(i,F->rank);
8104 strat->S=strat->Shdl->m;
8105
8106 /*- put polys into S -*/
8107 if (Q!=NULL)
8108 {
8109 strat->fromQ=initec(i);
8110 memset(strat->fromQ,0,i*sizeof(int));
8111 for (i=0; i<IDELEMS(Q); i++)
8112 {
8113 if (Q->m[i]!=NULL)
8114 {
8115 LObject h;
8116 h.p = pCopy(Q->m[i]);
8117 //if (TEST_OPT_INTSTRATEGY)
8118 //{
8119 // h.pCleardenom(); // also does remove Content
8120 //}
8121 //else
8122 //{
8123 // h.pNorm();
8124 //}
8126 {
8127 deleteHC(&h,strat);
8128 }
8129 if (h.p!=NULL)
8130 {
8131 strat->initEcart(&h);
8132 if (strat->sl==-1)
8133 pos =0;
8134 else
8135 {
8136 pos = posInS(strat,strat->sl,h.p,h.ecart);
8137 }
8138 h.sev = pGetShortExpVector(h.p);
8139 strat->enterS(&h,pos,strat, strat->tl+1);
8140 enterT(&h, strat);
8141 strat->fromQ[pos]=1;
8142 }
8143 }
8144 }
8145 }
8146 /*- put polys into S -*/
8147 for (i=0; i<IDELEMS(F); i++)
8148 {
8149 if (F->m[i]!=NULL)
8150 {
8151 LObject h;
8152 h.p = pCopy(F->m[i]);
8154 {
8155 deleteHC(&h,strat);
8156 }
8157 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8158 {
8159 h.p=redtailBba(h.p,strat->sl,strat);
8160 }
8161 if (h.p!=NULL)
8162 {
8163 strat->initEcart(&h);
8164 if (strat->sl==-1)
8165 pos =0;
8166 else
8167 pos = posInS(strat,strat->sl,h.p,h.ecart);
8168 h.sev = pGetShortExpVector(h.p);
8169 strat->enterS(&h,pos,strat, strat->tl+1);
8170 enterT(&h,strat);
8171 }
8172 }
8173 }
8174 for (i=0; i<IDELEMS(P); i++)
8175 {
8176 if (P->m[i]!=NULL)
8177 {
8178 LObject h;
8179 h.p=pCopy(P->m[i]);
8181 {
8182 h.pCleardenom();
8183 }
8184 else
8185 {
8186 h.pNorm();
8187 }
8188 if(strat->sl>=0)
8189 {
8191 {
8192 h.p=redBba(h.p,strat->sl,strat);
8193 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8194 {
8195 h.p=redtailBba(h.p,strat->sl,strat);
8196 }
8197 }
8198 else
8199 {
8200 h.p=redMora(h.p,strat->sl,strat);
8201 }
8202 if(h.p!=NULL)
8203 {
8204 strat->initEcart(&h);
8206 {
8207 h.pCleardenom();
8208 }
8209 else
8210 {
8211 h.is_normalized = 0;
8212 h.pNorm();
8213 }
8214 h.sev = pGetShortExpVector(h.p);
8215 h.SetpFDeg();
8216 pos = posInS(strat,strat->sl,h.p,h.ecart);
8217 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8218 strat->enterS(&h,pos,strat, strat->tl+1);
8219 enterT(&h,strat);
8220 }
8221 }
8222 else
8223 {
8224 h.sev = pGetShortExpVector(h.p);
8225 strat->initEcart(&h);
8226 strat->enterS(&h,0,strat, strat->tl+1);
8227 enterT(&h,strat);
8228 }
8229 }
8230 }
8231}
8232/*2
8233*construct the set s from F and {P}
8234*/
8235
8236void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8237{
8238 int i,pos;
8239
8240 if (Q!=NULL)
8241 {
8243 if (i<setmaxTinc) i=setmaxT;
8244 }
8245 else i=setmaxT;
8246 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8247 strat->sevS=initsevS(i);
8248 strat->sevSig=initsevS(i);
8249 strat->S_2_R=initS_2_R(i);
8250 strat->fromQ=NULL;
8251 strat->Shdl=idInit(i,F->rank);
8252 strat->S=strat->Shdl->m;
8253 strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8254 /*- put polys into S -*/
8255 if (Q!=NULL)
8256 {
8257 strat->fromQ=initec(i);
8258 memset(strat->fromQ,0,i*sizeof(int));
8259 for (i=0; i<IDELEMS(Q); i++)
8260 {
8261 if (Q->m[i]!=NULL)
8262 {
8263 LObject h;
8264 h.p = pCopy(Q->m[i]);
8265 //if (TEST_OPT_INTSTRATEGY)
8266 //{
8267 // h.pCleardenom(); // also does remove Content
8268 //}
8269 //else
8270 //{
8271 // h.pNorm();
8272 //}
8274 {
8275 deleteHC(&h,strat);
8276 }
8277 if (h.p!=NULL)
8278 {
8279 strat->initEcart(&h);
8280 if (strat->sl==-1)
8281 pos =0;
8282 else
8283 {
8284 pos = posInS(strat,strat->sl,h.p,h.ecart);
8285 }
8286 h.sev = pGetShortExpVector(h.p);
8287 strat->enterS(&h,pos,strat, strat->tl+1);
8288 enterT(&h, strat);
8289 strat->fromQ[pos]=1;
8290 }
8291 }
8292 }
8293 }
8294 /*- put polys into S -*/
8295 for (i=0; i<IDELEMS(F); i++)
8296 {
8297 if (F->m[i]!=NULL)
8298 {
8299 LObject h;
8300 h.p = pCopy(F->m[i]);
8302 {
8303 deleteHC(&h,strat);
8304 }
8305 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8306 {
8307 h.p=redtailBba(h.p,strat->sl,strat);
8308 }
8309 if (h.p!=NULL)
8310 {
8311 strat->initEcart(&h);
8312 if (strat->sl==-1)
8313 pos =0;
8314 else
8315 pos = posInS(strat,strat->sl,h.p,h.ecart);
8316 h.sev = pGetShortExpVector(h.p);
8317 strat->enterS(&h,pos,strat, strat->tl+1);
8318 enterT(&h,strat);
8319 }
8320 }
8321 }
8322 for (i=0; i<IDELEMS(P); i++)
8323 {
8324 if (P->m[i]!=NULL)
8325 {
8326 LObject h;
8327 h.p=pCopy(P->m[i]);
8329 {
8330 h.pCleardenom();
8331 }
8332 else
8333 {
8334 h.pNorm();
8335 }
8336 if(strat->sl>=0)
8337 {
8339 {
8340 h.p=redBba(h.p,strat->sl,strat);
8341 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8342 {
8343 h.p=redtailBba(h.p,strat->sl,strat);
8344 }
8345 }
8346 else
8347 {
8348 h.p=redMora(h.p,strat->sl,strat);
8349 }
8350 if(h.p!=NULL)
8351 {
8352 strat->initEcart(&h);
8354 {
8355 h.pCleardenom();
8356 }
8357 else
8358 {
8359 h.is_normalized = 0;
8360 h.pNorm();
8361 }
8362 h.sev = pGetShortExpVector(h.p);
8363 h.SetpFDeg();
8364 pos = posInS(strat,strat->sl,h.p,h.ecart);
8365 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8366 strat->enterS(&h,pos,strat, strat->tl+1);
8367 enterT(&h,strat);
8368 }
8369 }
8370 else
8371 {
8372 h.sev = pGetShortExpVector(h.p);
8373 strat->initEcart(&h);
8374 strat->enterS(&h,0,strat, strat->tl+1);
8375 enterT(&h,strat);
8376 }
8377 }
8378 }
8379}
8380
8381/*2
8382* reduces h using the set S
8383* procedure used in cancelunit1
8384*/
8385static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8386{
8387 int j = 0;
8388 unsigned long not_sev = ~ pGetShortExpVector(h);
8389
8390 while (j <= maxIndex)
8391 {
8392 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8393 return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8394 else j++;
8395 }
8396 return h;
8397}
8398
8399/*2
8400*tests if p.p=monomial*unit and cancels the unit
8401*/
8402void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8403{
8404 int k;
8405 poly r,h,h1,q;
8406
8407 if (!pIsVector((*p).p) && ((*p).ecart != 0))
8408 {
8409 // Leading coef have to be a unit: no
8410 // example 2x+4x2 should be simplified to 2x*(1+2x)
8411 // and 2 is not a unit in Z
8412 //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8413 k = 0;
8414 h1 = r = pCopy((*p).p);
8415 h =pNext(r);
8416 loop
8417 {
8418 if (h==NULL)
8419 {
8420 pDelete(&r);
8421 pDelete(&(pNext((*p).p)));
8422 (*p).ecart = 0;
8423 (*p).length = 1;
8424 (*p).pLength = 1;
8425 (*suc)=0;
8426 return;
8427 }
8428 if (!pDivisibleBy(r,h))
8429 {
8430 q=redBba1(h,index ,strat);
8431 if (q != h)
8432 {
8433 k++;
8434 pDelete(&h);
8435 pNext(h1) = h = q;
8436 }
8437 else
8438 {
8439 pDelete(&r);
8440 return;
8441 }
8442 }
8443 else
8444 {
8445 h1 = h;
8446 pIter(h);
8447 }
8448 if (k > 10)
8449 {
8450 pDelete(&r);
8451 return;
8452 }
8453 }
8454 }
8455}
8456
8457#if 0
8458/*2
8459* reduces h using the elements from Q in the set S
8460* procedure used in updateS
8461* must not be used for elements of Q or elements of an ideal !
8462*/
8463static poly redQ (poly h, int j, kStrategy strat)
8464{
8465 int start;
8466 unsigned long not_sev = ~ pGetShortExpVector(h);
8467 while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8468 start=j;
8469 while (j<=strat->sl)
8470 {
8471 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8472 {
8473 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8474 if (h==NULL) return NULL;
8475 j = start;
8476 not_sev = ~ pGetShortExpVector(h);
8477 }
8478 else j++;
8479 }
8480 return h;
8481}
8482#endif
8483
8484/*2
8485* reduces h using the set S
8486* procedure used in updateS
8487*/
8488static poly redBba (poly h,int maxIndex,kStrategy strat)
8489{
8490 int j = 0;
8491 unsigned long not_sev = ~ pGetShortExpVector(h);
8492
8493 while (j <= maxIndex)
8494 {
8495 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8496 {
8497 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8498 if (h==NULL) return NULL;
8499 j = 0;
8500 not_sev = ~ pGetShortExpVector(h);
8501 }
8502 else j++;
8503 }
8504 return h;
8505}
8506
8507/*2
8508* reduces h using the set S
8509*e is the ecart of h
8510*procedure used in updateS
8511*/
8512static poly redMora (poly h,int maxIndex,kStrategy strat)
8513{
8514 int j=0;
8515 int e,l;
8516 unsigned long not_sev = ~ pGetShortExpVector(h);
8517
8518 if (maxIndex >= 0)
8519 {
8520 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8521 do
8522 {
8523 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8524 && ((e >= strat->ecartS[j]) || (strat->kNoether!=NULL)))
8525 {
8526#ifdef KDEBUG
8527 if (TEST_OPT_DEBUG)
8528 {
8529 PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8530 }
8531#endif
8532 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8533#ifdef KDEBUG
8534 if(TEST_OPT_DEBUG)
8535 {
8536 PrintS(")\nto "); wrp(h); PrintLn();
8537 }
8538#endif
8539 // pDelete(&h);
8540 if (h == NULL) return NULL;
8541 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8542 j = 0;
8543 not_sev = ~ pGetShortExpVector(h);
8544 }
8545 else j++;
8546 }
8547 while (j <= maxIndex);
8548 }
8549 return h;
8550}
8551
8552/*2
8553*updates S:
8554*the result is a set of polynomials which are in
8555*normalform with respect to S
8556*/
8558{
8559 LObject h;
8560 int i, suc=0;
8561 poly redSi=NULL;
8562 BOOLEAN change,any_change;
8563// Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8564// for (i=0; i<=(strat->sl); i++)
8565// {
8566// Print("s%d:",i);
8567// if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8568// pWrite(strat->S[i]);
8569// }
8570// Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8571 any_change=FALSE;
8573 {
8574 while (suc != -1)
8575 {
8576 i=suc+1;
8577 while (i<=strat->sl)
8578 {
8579 change=FALSE;
8581 any_change = FALSE;
8582 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8583 {
8584 redSi = pHead(strat->S[i]);
8585 strat->S[i] = redBba(strat->S[i],i-1,strat);
8586 //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8587 // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8588 if (pCmp(redSi,strat->S[i])!=0)
8589 {
8590 change=TRUE;
8591 any_change=TRUE;
8592 #ifdef KDEBUG
8593 if (TEST_OPT_DEBUG)
8594 {
8595 PrintS("reduce:");
8596 wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8597 }
8598 #endif
8599 if (TEST_OPT_PROT)
8600 {
8601 if (strat->S[i]==NULL)
8602 PrintS("V");
8603 else
8604 PrintS("v");
8605 mflush();
8606 }
8607 }
8608 pLmDelete(&redSi);
8609 if (strat->S[i]==NULL)
8610 {
8611 deleteInS(i,strat);
8612 i--;
8613 }
8614 else if (change)
8615 {
8617 {
8619 {
8620 number n;
8621 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8622 if (!nIsOne(n))
8623 {
8625 denom->n=nInvers(n);
8626 denom->next=DENOMINATOR_LIST;
8627 DENOMINATOR_LIST=denom;
8628 }
8629 nDelete(&n);
8630 }
8631 else
8632 {
8633 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8634 }
8635 }
8636 else
8637 {
8638 pNorm(strat->S[i]);
8639 }
8640 strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8641 }
8642 }
8643 i++;
8644 }
8645 if (any_change) reorderS(&suc,strat);
8646 else break;
8647 }
8648 if (toT)
8649 {
8650 for (i=0; i<=strat->sl; i++)
8651 {
8652 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8653 {
8654 h.p = redtailBba(strat->S[i],i-1,strat);
8656 {
8657 h.pCleardenom();// also does remove Content
8658 }
8659 }
8660 else
8661 {
8662 h.p = strat->S[i];
8663 }
8664 strat->initEcart(&h);
8665 if (strat->honey)
8666 {
8667 strat->ecartS[i] = h.ecart;
8668 }
8669 if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8670 else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8671 h.sev = strat->sevS[i];
8672 /*puts the elements of S also to T*/
8673 strat->initEcart(&h);
8674 /*if (toT) - already checked*/ enterT(&h,strat);
8675 strat->S_2_R[i] = strat->tl;
8676#ifdef HAVE_SHIFTBBA
8677 if (/*(toT) && */(currRing->isLPring))
8678 enterTShift(&h, strat);
8679#endif
8680 }
8681 }
8682 }
8683 else
8684 {
8685 while (suc != -1)
8686 {
8687 i=suc;
8688 while (i<=strat->sl)
8689 {
8690 change=FALSE;
8691 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8692 {
8693 redSi=pHead((strat->S)[i]);
8694 (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
8695 if ((strat->S)[i]==NULL)
8696 {
8697 deleteInS(i,strat);
8698 i--;
8699 }
8700 else if (pCmp((strat->S)[i],redSi)!=0)
8701 {
8702 any_change=TRUE;
8703 h.p = strat->S[i];
8704 strat->initEcart(&h);
8705 strat->ecartS[i] = h.ecart;
8707 {
8709 {
8710 number n;
8711 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8712 if (!nIsOne(n))
8713 {
8715 denom->n=nInvers(n);
8716 denom->next=DENOMINATOR_LIST;
8717 DENOMINATOR_LIST=denom;
8718 }
8719 nDelete(&n);
8720 }
8721 else
8722 {
8723 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8724 }
8725 }
8726 else
8727 {
8728 pNorm(strat->S[i]); // == h.p
8729 }
8730 h.sev = pGetShortExpVector(h.p);
8731 strat->sevS[i] = h.sev;
8732 }
8733 pLmDelete(&redSi);
8734 kTest(strat);
8735 }
8736 i++;
8737 }
8738#ifdef KDEBUG
8739 kTest(strat);
8740#endif
8741 if (any_change) reorderS(&suc,strat);
8742 else { suc=-1; break; }
8743 if (h.p!=NULL)
8744 {
8745 if (!strat->kAllAxis)
8746 {
8747 /*strat->kAllAxis =*/ HEckeTest(h.p,strat);
8748 }
8749 if (strat->kAllAxis)
8750 newHEdge(strat);
8751 }
8752 }
8753 for (i=0; i<=strat->sl; i++)
8754 {
8755 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8756 {
8757 strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
8758 strat->initEcart(&h);
8759 strat->ecartS[i] = h.ecart;
8760 h.sev = pGetShortExpVector(h.p);
8761 strat->sevS[i] = h.sev;
8762 }
8763 else
8764 {
8765 h.p = strat->S[i];
8766 h.ecart=strat->ecartS[i];
8767 h.sev = strat->sevS[i];
8768 h.length = h.pLength = pLength(h.p);
8769 }
8770 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8771 cancelunit1(&h,&suc,strat->sl,strat);
8772 h.SetpFDeg();
8773 /*puts the elements of S also to T*/
8774 enterT(&h,strat);
8775 strat->S_2_R[i] = strat->tl;
8776#ifdef HAVE_SHIFTBBA
8777 if (currRing->isLPring)
8778 enterTShift(&h, strat);
8779#endif
8780 }
8781 if (suc!= -1) updateS(toT,strat);
8782 }
8783#ifdef KDEBUG
8784 kTest(strat);
8785#endif
8786}
8787
8788/*2
8789* -puts p to the standardbasis s at position at
8790* -saves the result in S
8791*/
8792void enterSBba (LObject* p,int atS,kStrategy strat, int atR)
8793{
8794 strat->news = TRUE;
8795 /*- puts p to the standardbasis s at position at -*/
8796 if (strat->sl == IDELEMS(strat->Shdl)-1)
8797 {
8798 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8799 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8800 (IDELEMS(strat->Shdl)+setmaxTinc)
8801 *sizeof(unsigned long));
8802 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8803 IDELEMS(strat->Shdl)*sizeof(int),
8804 (IDELEMS(strat->Shdl)+setmaxTinc)
8805 *sizeof(int));
8806 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8807 IDELEMS(strat->Shdl)*sizeof(int),
8808 (IDELEMS(strat->Shdl)+setmaxTinc)
8809 *sizeof(int));
8810 if (strat->lenS!=NULL)
8811 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8812 IDELEMS(strat->Shdl)*sizeof(int),
8813 (IDELEMS(strat->Shdl)+setmaxTinc)
8814 *sizeof(int));
8815 if (strat->lenSw!=NULL)
8816 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8817 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8818 (IDELEMS(strat->Shdl)+setmaxTinc)
8819 *sizeof(wlen_type));
8820 if (strat->fromQ!=NULL)
8821 {
8822 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8823 IDELEMS(strat->Shdl)*sizeof(int),
8824 (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
8825 }
8826 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
8827 IDELEMS(strat->Shdl)+=setmaxTinc;
8828 strat->Shdl->m=strat->S;
8829 }
8830 if (atS <= strat->sl)
8831 {
8832#ifdef ENTER_USE_MEMMOVE
8833 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
8834 (strat->sl - atS + 1)*sizeof(poly));
8835 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
8836 (strat->sl - atS + 1)*sizeof(int));
8837 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
8838 (strat->sl - atS + 1)*sizeof(unsigned long));
8839 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
8840 (strat->sl - atS + 1)*sizeof(int));
8841 if (strat->lenS!=NULL)
8842 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
8843 (strat->sl - atS + 1)*sizeof(int));
8844 if (strat->lenSw!=NULL)
8845 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
8846 (strat->sl - atS + 1)*sizeof(wlen_type));
8847#else
8848 for (i=strat->sl+1; i>=atS+1; i--)
8849 {
8850 strat->S[i] = strat->S[i-1];
8851 strat->ecartS[i] = strat->ecartS[i-1];
8852 strat->sevS[i] = strat->sevS[i-1];
8853 strat->S_2_R[i] = strat->S_2_R[i-1];
8854 }
8855 if (strat->lenS!=NULL)
8856 for (i=strat->sl+1; i>=atS+1; i--)
8857 strat->lenS[i] = strat->lenS[i-1];
8858 if (strat->lenSw!=NULL)
8859 for (i=strat->sl+1; i>=atS+1; i--)
8860 strat->lenSw[i] = strat->lenSw[i-1];
8861#endif
8862 }
8863 if (strat->fromQ!=NULL)
8864 {
8865#ifdef ENTER_USE_MEMMOVE
8866 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
8867 (strat->sl - atS + 1)*sizeof(int));
8868#else
8869 for (i=strat->sl+1; i>=atS+1; i--)
8870 {
8871 strat->fromQ[i] = strat->fromQ[i-1];
8872 }
8873#endif
8874 strat->fromQ[atS]=0;
8875 }
8876
8877 /*- save result -*/
8878 poly pp=p->p;
8879 strat->S[atS] = pp;
8880 if (strat->honey) strat->ecartS[atS] = p->ecart;
8881 if (p->sev == 0)
8882 p->sev = pGetShortExpVector(pp);
8883 else
8884 assume(p->sev == pGetShortExpVector(pp));
8885 strat->sevS[atS] = p->sev;
8886 strat->ecartS[atS] = p->ecart;
8887 strat->S_2_R[atS] = atR;
8888 strat->sl++;
8889}
8890
8891#ifdef HAVE_SHIFTBBA
8892void enterSBbaShift (LObject* p,int atS,kStrategy strat, int atR)
8893{
8894 enterSBba(p, atS, strat, atR);
8895
8896 int maxPossibleShift = p_mLPmaxPossibleShift(p->p, strat->tailRing);
8897 for (int i = maxPossibleShift; i > 0; i--)
8898 {
8899 // NOTE: don't use "shared tails" here. In rare cases it can cause problems
8900 // in `kNF2` because of lazy poly normalizations.
8901 LObject qq(p_Copy(p->p, strat->tailRing));
8902 p_mLPshift(qq.p, i, strat->tailRing);
8903 qq.shift = i;
8904 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
8905 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
8906 enterSBba(&qq, atS, strat, -1);
8907 }
8908}
8909#endif
8910
8911/*2
8912* -puts p to the standardbasis s at position at
8913* -saves the result in S
8914*/
8915void enterSSba (LObject* p,int atS,kStrategy strat, int atR)
8916{
8917 strat->news = TRUE;
8918 /*- puts p to the standardbasis s at position at -*/
8919 if (strat->sl == IDELEMS(strat->Shdl)-1)
8920 {
8921 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8922 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8923 (IDELEMS(strat->Shdl)+setmax)
8924 *sizeof(unsigned long));
8925 strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
8926 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8927 (IDELEMS(strat->Shdl)+setmax)
8928 *sizeof(unsigned long));
8929 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8930 IDELEMS(strat->Shdl)*sizeof(int),
8931 (IDELEMS(strat->Shdl)+setmax)
8932 *sizeof(int));
8933 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8934 IDELEMS(strat->Shdl)*sizeof(int),
8935 (IDELEMS(strat->Shdl)+setmax)
8936 *sizeof(int));
8937 if (strat->lenS!=NULL)
8938 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8939 IDELEMS(strat->Shdl)*sizeof(int),
8940 (IDELEMS(strat->Shdl)+setmax)
8941 *sizeof(int));
8942 if (strat->lenSw!=NULL)
8943 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8944 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8945 (IDELEMS(strat->Shdl)+setmax)
8946 *sizeof(wlen_type));
8947 if (strat->fromQ!=NULL)
8948 {
8949 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8950 IDELEMS(strat->Shdl)*sizeof(int),
8951 (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
8952 }
8953 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
8954 pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
8955 IDELEMS(strat->Shdl)+=setmax;
8956 strat->Shdl->m=strat->S;
8957 }
8958 // in a signature-based algorithm the following situation will never
8959 // appear due to the fact that the critical pairs are already sorted
8960 // by increasing signature.
8961 // True. However, in the case of integers we need to put the element
8962 // that caused the signature drop on the first position
8963 if (atS <= strat->sl)
8964 {
8965#ifdef ENTER_USE_MEMMOVE
8966 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
8967 (strat->sl - atS + 1)*sizeof(poly));
8968 memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
8969 (strat->sl - atS + 1)*sizeof(poly));
8970 memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
8971 (strat->sl - atS + 1)*sizeof(unsigned long));
8972 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
8973 (strat->sl - atS + 1)*sizeof(int));
8974 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
8975 (strat->sl - atS + 1)*sizeof(unsigned long));
8976 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
8977 (strat->sl - atS + 1)*sizeof(int));
8978 if (strat->lenS!=NULL)
8979 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
8980 (strat->sl - atS + 1)*sizeof(int));
8981 if (strat->lenSw!=NULL)
8982 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
8983 (strat->sl - atS + 1)*sizeof(wlen_type));
8984#else
8985 for (i=strat->sl+1; i>=atS+1; i--)
8986 {
8987 strat->S[i] = strat->S[i-1];
8988 strat->ecartS[i] = strat->ecartS[i-1];
8989 strat->sevS[i] = strat->sevS[i-1];
8990 strat->S_2_R[i] = strat->S_2_R[i-1];
8991 strat->sig[i] = strat->sig[i-1];
8992 strat->sevSig[i] = strat->sevSig[i-1];
8993 }
8994 if (strat->lenS!=NULL)
8995 for (i=strat->sl+1; i>=atS+1; i--)
8996 strat->lenS[i] = strat->lenS[i-1];
8997 if (strat->lenSw!=NULL)
8998 for (i=strat->sl+1; i>=atS+1; i--)
8999 strat->lenSw[i] = strat->lenSw[i-1];
9000#endif
9001 }
9002 if (strat->fromQ!=NULL)
9003 {
9004#ifdef ENTER_USE_MEMMOVE
9005 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9006 (strat->sl - atS + 1)*sizeof(int));
9007#else
9008 for (i=strat->sl+1; i>=atS+1; i--)
9009 {
9010 strat->fromQ[i] = strat->fromQ[i-1];
9011 }
9012#endif
9013 strat->fromQ[atS]=0;
9014 }
9015
9016 /*- save result -*/
9017 strat->S[atS] = p->p;
9018 strat->sig[atS] = p->sig; // TODO: get the correct signature in here!
9019 if (strat->honey) strat->ecartS[atS] = p->ecart;
9020 if (p->sev == 0)
9021 p->sev = pGetShortExpVector(p->p);
9022 else
9023 assume(p->sev == pGetShortExpVector(p->p));
9024 strat->sevS[atS] = p->sev;
9025 // during the interreduction process of a signature-based algorithm we do not
9026 // compute the signature at this point, but when the whole interreduction
9027 // process finishes, i.e. f5c terminates!
9028 if (p->sig != NULL)
9029 {
9030 if (p->sevSig == 0)
9031 p->sevSig = pGetShortExpVector(p->sig);
9032 else
9033 assume(p->sevSig == pGetShortExpVector(p->sig));
9034 strat->sevSig[atS] = p->sevSig; // TODO: get the correct signature in here!
9035 }
9036 strat->ecartS[atS] = p->ecart;
9037 strat->S_2_R[atS] = atR;
9038 strat->sl++;
9039#ifdef DEBUGF5
9040 int k;
9041 Print("--- LIST S: %d ---\n",strat->sl);
9042 for(k=0;k<=strat->sl;k++)
9043 {
9044 pWrite(strat->sig[k]);
9045 }
9046 PrintS("--- LIST S END ---\n");
9047#endif
9048}
9049
9050#if STDZ_EXCHANGE_DURING_REDUCTION
9051void replaceInLAndSAndT(LObject* p, int tj, kStrategy strat)
9052{
9053 p->GetP(strat->lmBin);
9054 if (strat->homog) strat->initEcart(p);
9055 strat->redTailChange=FALSE;
9057 {
9058 p->pCleardenom();
9060 {
9061#ifdef HAVE_SHIFTBBA
9062 if (rIsLPRing(currRing))
9063 p->p = redtailBba(p,strat->tl,strat, TRUE,!TEST_OPT_CONTENTSB);
9064 else
9065#endif
9066 {
9067 p->p = redtailBba(p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9068 }
9069 p->pCleardenom();
9070 if (strat->redTailChange)
9071 p->t_p=NULL;
9072 if (strat->P.p!=NULL) strat->P.sev=p_GetShortExpVector(strat->P.p,currRing);
9073 else strat->P.sev=0;
9074 }
9075 }
9076
9077 assume(strat->tailRing == p->tailRing);
9078 assume(p->pLength == 0 || pLength(p->p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9079
9080 int i, j, pos;
9081 poly tp = strat->T[tj].p;
9082
9083 /* enter p to T set */
9084 enterT(p, strat);
9085
9086 for (j = 0; j <= strat->sl; ++j)
9087 {
9088 if (pLtCmp(tp, strat->S[j]) == 0)
9089 {
9090 break;
9091 }
9092 }
9093 /* it may be that the exchanged element
9094 * is until now only in T and not in S */
9095 if (j <= strat->sl)
9096 {
9097 deleteInS(j, strat);
9098 }
9099
9100 pos = posInS(strat, strat->sl, p->p, p->ecart);
9101
9102 pp_Test(p->p, currRing, p->tailRing);
9103 assume(p->FDeg == p->pFDeg());
9104
9105 /* remove useless pairs from L set */
9106 for (i = 0; i <= strat->Ll; ++i)
9107 {
9108 if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0)
9109 {
9110 deleteInL(strat->L, &(strat->Ll), i, strat);
9111 i--;
9112 continue;
9113 }
9114 if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0)
9115 {
9116 deleteInL(strat->L, &(strat->Ll), i, strat);
9117 i--;
9118 }
9119 }
9120#ifdef HAVE_SHIFTBBA
9121 if (rIsLPRing(currRing))
9122 enterpairsShift(p->p, strat->sl, p->ecart, pos, strat, strat->tl); // TODO LP
9123 else
9124#endif
9125 {
9126 /* generate new pairs with p, probably removing older, now useless pairs */
9127 superenterpairs(p->p, strat->sl, p->ecart, pos, strat, strat->tl);
9128 }
9129 /* enter p to S set */
9130 strat->enterS(p, pos, strat, strat->tl);
9131
9132#ifdef HAVE_SHIFTBBA
9133 /* do this after enterS so that the index in R (which is strat->tl) is correct */
9134 if (rIsLPRing(currRing) && !strat->rightGB)
9135 enterTShift(p,strat);
9136#endif
9137}
9138#endif
9139
9140/*2
9141* puts p to the set T at position atT
9142*/
9143void enterT(LObject* p, kStrategy strat, int atT)
9144{
9145 int i;
9146
9147#ifdef PDEBUG
9148#ifdef HAVE_SHIFTBBA
9149 if (currRing->isLPring && p->shift > 0)
9150 {
9151 // in this case, the order is not correct. test LM and tail separately
9152 p_LmTest(p->p, currRing);
9153 p_Test(pNext(p->p), currRing);
9154 }
9155 else
9156#endif
9157 {
9158 pp_Test(p->p, currRing, p->tailRing);
9159 }
9160#endif
9161 assume(strat->tailRing == p->tailRing);
9162 // redMoraNF complains about this -- but, we don't really
9163 // need this so far
9164 assume(p->pLength == 0 || pLength(p->p) == p->pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9165 assume(!strat->homog || (p->FDeg == p->pFDeg()));
9166 assume(!p->is_normalized || nIsOne(pGetCoeff(p->p)));
9167
9168#ifdef KDEBUG
9169 // do not put an LObject twice into T:
9170 for(i=strat->tl;i>=0;i--)
9171 {
9172 if (p->p==strat->T[i].p)
9173 {
9174 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9175 return;
9176 }
9177 }
9178#endif
9179
9180#ifdef HAVE_TAIL_RING
9181 if (currRing!=strat->tailRing)
9182 {
9183 p->t_p=p->GetLmTailRing();
9184 }
9185#endif
9186 strat->newt = TRUE;
9187 if (atT < 0)
9188 atT = strat->posInT(strat->T, strat->tl, *p);
9189 if (strat->tl == strat->tmax-1)
9190 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,strat->tmax);
9191 if (atT <= strat->tl)
9192 {
9193#ifdef ENTER_USE_MEMMOVE
9194 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9195 (strat->tl-atT+1)*sizeof(TObject));
9196 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9197 (strat->tl-atT+1)*sizeof(unsigned long));
9198#endif
9199 for (i=strat->tl+1; i>=atT+1; i--)
9200 {
9201#ifndef ENTER_USE_MEMMOVE
9202 strat->T[i] = strat->T[i-1];
9203 strat->sevT[i] = strat->sevT[i-1];
9204#endif
9205 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9206 }
9207 }
9208
9209 if ((strat->tailBin != NULL) && (pNext(p->p) != NULL))
9210 {
9211#ifdef HAVE_SHIFTBBA
9212 // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9213 if (!(currRing->isLPring && p->shift > 0))
9214#endif
9215 {
9217 (strat->tailRing != NULL ?
9218 strat->tailRing : currRing),
9219 strat->tailBin);
9220 if (p->t_p != NULL) pNext(p->t_p) = pNext(p->p);
9221 }
9222 }
9223 strat->T[atT] = (TObject) *p;
9224 //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9225
9226 if ((pNext(p->p) != NULL) && (!rIsLPRing(currRing)))
9227 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p->p), strat->tailRing);
9228 else
9229 strat->T[atT].max_exp = NULL;
9230
9231 strat->tl++;
9232 strat->R[strat->tl] = &(strat->T[atT]);
9233 strat->T[atT].i_r = strat->tl;
9234 assume((p->sev == 0) || (pGetShortExpVector(p->p) == p->sev));
9235 strat->sevT[atT] = (p->sev == 0 ? pGetShortExpVector(p->p) : p->sev);
9236 kTest_T(&(strat->T[atT]),strat);
9237}
9238
9239/*2
9240* puts p to the set T at position atT
9241*/
9242void enterT_strong(LObject* p, kStrategy strat, int atT)
9243{
9245 int i;
9246
9247 pp_Test(p->p, currRing, p->tailRing);
9248 assume(strat->tailRing == p->tailRing);
9249 // redMoraNF complains about this -- but, we don't really
9250 // need this so far
9251 assume(p->pLength == 0 || (int)pLength(p->p) == p->pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9252 assume(p->FDeg == p->pFDeg());
9253 assume(!p->is_normalized || nIsOne(pGetCoeff(p->p)));
9254
9255#ifdef KDEBUG
9256 // do not put an LObject twice into T:
9257 for(i=strat->tl;i>=0;i--)
9258 {
9259 if (p->p==strat->T[i].p)
9260 {
9261 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9262 return;
9263 }
9264 }
9265#endif
9266
9267#ifdef HAVE_TAIL_RING
9268 if (currRing!=strat->tailRing)
9269 {
9270 p->t_p=p->GetLmTailRing();
9271 }
9272#endif
9273 strat->newt = TRUE;
9274 if (atT < 0)
9275 atT = strat->posInT(strat->T, strat->tl, *p);
9276 if (strat->tl == strat->tmax-1)
9277 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,strat->tmax);
9278 if (atT <= strat->tl)
9279 {
9280#ifdef ENTER_USE_MEMMOVE
9281 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9282 (strat->tl-atT+1)*sizeof(TObject));
9283 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9284 (strat->tl-atT+1)*sizeof(unsigned long));
9285#endif
9286 for (i=strat->tl+1; i>=atT+1; i--)
9287 {
9288#ifndef ENTER_USE_MEMMOVE
9289 strat->T[i] = strat->T[i-1];
9290 strat->sevT[i] = strat->sevT[i-1];
9291#endif
9292 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9293 }
9294 }
9295
9296 if ((strat->tailBin != NULL) && (pNext(p->p) != NULL))
9297 {
9299 (strat->tailRing != NULL ?
9300 strat->tailRing : currRing),
9301 strat->tailBin);
9302 if (p->t_p != NULL) pNext(p->t_p) = pNext(p->p);
9303 }
9304 strat->T[atT] = (TObject) *p;
9305 //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9306
9307 if (pNext(p->p) != NULL)
9308 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p->p), strat->tailRing);
9309 else
9310 strat->T[atT].max_exp = NULL;
9311
9312 strat->tl++;
9313 strat->R[strat->tl] = &(strat->T[atT]);
9314 strat->T[atT].i_r = strat->tl;
9315 assume(p->sev == 0 || pGetShortExpVector(p->p) == p->sev);
9316 strat->sevT[atT] = (p->sev == 0 ? pGetShortExpVector(p->p) : p->sev);
9317 #if 1
9319 && !n_IsUnit(p->p->coef, currRing->cf))
9320 {
9321 for(i=strat->tl;i>=0;i--)
9322 {
9323 if(strat->T[i].ecart <= p->ecart && pLmDivisibleBy(strat->T[i].p,p->p))
9324 {
9325 enterOneStrongPoly(i,p->p,p->ecart,0,strat,0 , TRUE);
9326 }
9327 }
9328 }
9329 /*
9330 printf("\nThis is T:\n");
9331 for(i=strat->tl;i>=0;i--)
9332 {
9333 pWrite(strat->T[i].p);
9334 }
9335 //getchar();*/
9336 #endif
9337 kTest_T(&(strat->T[atT]),strat);
9338}
9339
9340/*2
9341* puts signature p.sig to the set syz
9342*/
9343void enterSyz(LObject &p, kStrategy strat, int atT)
9344{
9345 int i;
9346 strat->newt = TRUE;
9347 if (strat->syzl == strat->syzmax-1)
9348 {
9349 pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9350 strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9351 (strat->syzmax)*sizeof(unsigned long),
9352 ((strat->syzmax)+setmax)
9353 *sizeof(unsigned long));
9354 strat->syzmax += setmax;
9355 }
9356 if (atT < strat->syzl)
9357 {
9358#ifdef ENTER_USE_MEMMOVE
9359 memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9360 (strat->syzl-atT+1)*sizeof(poly));
9361 memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9362 (strat->syzl-atT+1)*sizeof(unsigned long));
9363#endif
9364 for (i=strat->syzl; i>=atT+1; i--)
9365 {
9366#ifndef ENTER_USE_MEMMOVE
9367 strat->syz[i] = strat->syz[i-1];
9368 strat->sevSyz[i] = strat->sevSyz[i-1];
9369#endif
9370 }
9371 }
9372 //i = strat->syzl;
9373 i = atT;
9374 //Makes sure the syz saves just the signature
9376 pNext(p.sig) = NULL;
9377 strat->syz[atT] = p.sig;
9378 strat->sevSyz[atT] = p.sevSig;
9379 strat->syzl++;
9380#if F5DEBUG
9381 Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9382 pWrite(strat->syz[atT]);
9383#endif
9384 // recheck pairs in strat->L with new rule and delete correspondingly
9385 int cc = strat->Ll;
9386 while (cc>-1)
9387 {
9388 //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9389 //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);
9390 if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9391 strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9393 || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9394 )
9395 {
9396 //printf("\nYES!\n");
9397 deleteInL(strat->L,&strat->Ll,cc,strat);
9398 }
9399 cc--;
9400 }
9401//#if 1
9402#ifdef DEBUGF5
9403 PrintS("--- Syzygies ---\n");
9404 Print("syzl %d\n",strat->syzl);
9405 Print("syzmax %d\n",strat->syzmax);
9406 PrintS("--------------------------------\n");
9407 for(i=0;i<=strat->syzl-1;i++)
9408 {
9409 Print("%d - ",i);
9410 pWrite(strat->syz[i]);
9411 }
9412 PrintS("--------------------------------\n");
9413#endif
9414}
9415
9416
9417void initHilbCrit(ideal/*F*/, ideal /*Q*/, bigintmat **hilb,kStrategy strat)
9418{
9419
9420 //if the ordering is local, then hilb criterion
9421 //can be used also if the ideal is not homogeneous
9423 {
9425 *hilb=NULL;
9426 else
9427 return;
9428 }
9429 if (strat->homog!=isHomog)
9430 {
9431 *hilb=NULL;
9432 }
9433}
9434
9436{
9439 if (TEST_OPT_SB_1)
9442 {
9444 strat->chainCrit=chainCritRing;
9445 }
9446#ifdef HAVE_RATGRING
9447 if (rIsRatGRing(currRing))
9448 {
9449 strat->chainCrit=chainCritPart;
9450 /* enterOnePairNormal get rational part in it */
9451 }
9452#endif
9453 if (TEST_OPT_IDLIFT
9454 && (strat->syzComp==1)
9455 && (!rIsPluralRing(currRing)))
9457
9459 strat->Gebauer = strat->homog || strat->sugarCrit;
9460 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9461 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9462 strat->pairtest = NULL;
9463 /* always use tailreduction, except:
9464 * - in local rings, - in lex order case, -in ring over extensions */
9466 //if(rHasMixedOrdering(currRing)==2)
9467 //{
9468 // strat->noTailReduction =TRUE;
9469 //}
9470
9471#ifdef HAVE_PLURAL
9472 // and r is plural_ring
9473 // hence this holds for r a rational_plural_ring
9474 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9475 { //or it has non-quasi-comm type... later
9476 strat->sugarCrit = FALSE;
9477 strat->Gebauer = FALSE;
9478 strat->honey = FALSE;
9479 }
9480#endif
9481
9482 // Coefficient ring?
9484 {
9485 strat->sugarCrit = FALSE;
9486 strat->Gebauer = FALSE;
9487 strat->honey = FALSE;
9488 }
9489 #ifdef KDEBUG
9490 if (TEST_OPT_DEBUG)
9491 {
9492 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9493 else PrintS("ideal/module is not homogeneous\n");
9494 }
9495 #endif
9496}
9497
9499{
9500 //strat->enterOnePair=enterOnePairNormal;
9502 //strat->chainCrit=chainCritNormal;
9503 strat->chainCrit = chainCritSig;
9504 /******************************************
9505 * rewCrit1 and rewCrit2 are already set in
9506 * kSba() in kstd1.cc
9507 *****************************************/
9508 //strat->rewCrit1 = faugereRewCriterion;
9509 if (strat->sbaOrder == 1)
9510 {
9511 strat->syzCrit = syzCriterionInc;
9512 }
9513 else
9514 {
9515 strat->syzCrit = syzCriterion;
9516 }
9518 {
9520 strat->chainCrit=chainCritRing;
9521 }
9522#ifdef HAVE_RATGRING
9523 if (rIsRatGRing(currRing))
9524 {
9525 strat->chainCrit=chainCritPart;
9526 /* enterOnePairNormal get rational part in it */
9527 }
9528#endif
9529
9531 strat->Gebauer = strat->homog || strat->sugarCrit;
9532 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9533 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9534 strat->pairtest = NULL;
9535 /* always use tailreduction, except:
9536 * - in local rings, - in lex order case, -in ring over extensions */
9539
9540#ifdef HAVE_PLURAL
9541 // and r is plural_ring
9542 // hence this holds for r a rational_plural_ring
9543 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9544 { //or it has non-quasi-comm type... later
9545 strat->sugarCrit = FALSE;
9546 strat->Gebauer = FALSE;
9547 strat->honey = FALSE;
9548 }
9549#endif
9550
9551 // Coefficient ring?
9553 {
9554 strat->sugarCrit = FALSE;
9555 strat->Gebauer = FALSE ;
9556 strat->honey = FALSE;
9557 }
9558 #ifdef KDEBUG
9559 if (TEST_OPT_DEBUG)
9560 {
9561 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9562 else PrintS("ideal/module is not homogeneous\n");
9563 }
9564 #endif
9565}
9566
9568 (const LSet set, const int length,
9569 LObject* L,const kStrategy strat))
9570{
9571 if (pos_in_l == posInL110
9572 || pos_in_l == posInL10
9573 || pos_in_l == posInL110Ring
9574 )
9575 return TRUE;
9576
9577 return FALSE;
9578}
9579
9581{
9583 {
9584 if (strat->honey)
9585 {
9586 strat->posInL = posInL15;
9587 // ok -- here is the deal: from my experiments for Singular-2-0
9588 // I conclude that that posInT_EcartpLength is the best of
9589 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9590 // see the table at the end of this file
9591 if (TEST_OPT_OLDSTD)
9592 strat->posInT = posInT15;
9593 else
9594 strat->posInT = posInT_EcartpLength;
9595 }
9596 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9597 {
9598 strat->posInL = posInL11;
9599 strat->posInT = posInT11;
9600 }
9601 else if (TEST_OPT_INTSTRATEGY)
9602 {
9603 strat->posInL = posInL11;
9604 strat->posInT = posInT11;
9605 }
9606 else
9607 {
9608 strat->posInL = posInL0;
9609 strat->posInT = posInT0;
9610 }
9611 if (strat->homog)
9612 {
9613 strat->posInL = posInL110;
9614 strat->posInT = posInT110;
9615 }
9616 }
9617 else /* local/mixed ordering */
9618 {
9619 if (strat->homog)
9620 {
9621 strat->posInL = posInL11;
9622 strat->posInT = posInT11;
9623 }
9624 else
9625 {
9626 if ((currRing->order[0]==ringorder_c)
9627 ||(currRing->order[0]==ringorder_C))
9628 {
9629 strat->posInL = posInL17_c;
9630 strat->posInT = posInT17_c;
9631 }
9632 else
9633 {
9634 strat->posInL = posInL17;
9635 strat->posInT = posInT17;
9636 }
9637 }
9638 }
9639 if (strat->minim>0) strat->posInL =posInLSpecial;
9640 // for further tests only
9641 if ((BTEST1(11)) || (BTEST1(12)))
9642 strat->posInL = posInL11;
9643 else if ((BTEST1(13)) || (BTEST1(14)))
9644 strat->posInL = posInL13;
9645 else if ((BTEST1(15)) || (BTEST1(16)))
9646 strat->posInL = posInL15;
9647 else if ((BTEST1(17)) || (BTEST1(18)))
9648 strat->posInL = posInL17;
9649 if (BTEST1(11))
9650 strat->posInT = posInT11;
9651 else if (BTEST1(13))
9652 strat->posInT = posInT13;
9653 else if (BTEST1(15))
9654 strat->posInT = posInT15;
9655 else if ((BTEST1(17)))
9656 strat->posInT = posInT17;
9657 else if ((BTEST1(19)))
9658 strat->posInT = posInT19;
9659 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9660 strat->posInT = posInT1;
9662}
9663
9665{
9667 {
9668 if (strat->honey)
9669 {
9670 strat->posInL = posInL15Ring;
9671 // ok -- here is the deal: from my experiments for Singular-2-0
9672 // I conclude that that posInT_EcartpLength is the best of
9673 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9674 // see the table at the end of this file
9675 if (TEST_OPT_OLDSTD)
9676 strat->posInT = posInT15Ring;
9677 else
9678 strat->posInT = posInT_EcartpLength;
9679 }
9680 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9681 {
9682 strat->posInL = posInL11Ring;
9683 strat->posInT = posInT11;
9684 }
9685 else if (TEST_OPT_INTSTRATEGY)
9686 {
9687 strat->posInL = posInL11Ring;
9688 strat->posInT = posInT11;
9689 }
9690 else
9691 {
9692 strat->posInL = posInL0Ring;
9693 strat->posInT = posInT0;
9694 }
9695 if (strat->homog)
9696 {
9697 strat->posInL = posInL110Ring;
9698 strat->posInT = posInT110Ring;
9699 }
9700 }
9701 else
9702 {
9703 if (strat->homog)
9704 {
9705 //printf("\nHere 3\n");
9706 strat->posInL = posInL11Ring;
9707 strat->posInT = posInT11Ring;
9708 }
9709 else
9710 {
9711 if ((currRing->order[0]==ringorder_c)
9712 ||(currRing->order[0]==ringorder_C))
9713 {
9714 strat->posInL = posInL17_cRing;
9715 strat->posInT = posInT17_cRing;
9716 }
9717 else
9718 {
9719 strat->posInL = posInL11Ringls;
9720 strat->posInT = posInT17Ring;
9721 }
9722 }
9723 }
9724 if (strat->minim>0) strat->posInL =posInLSpecial;
9725 // for further tests only
9726 if ((BTEST1(11)) || (BTEST1(12)))
9727 strat->posInL = posInL11Ring;
9728 else if ((BTEST1(13)) || (BTEST1(14)))
9729 strat->posInL = posInL13;
9730 else if ((BTEST1(15)) || (BTEST1(16)))
9731 strat->posInL = posInL15Ring;
9732 else if ((BTEST1(17)) || (BTEST1(18)))
9733 strat->posInL = posInL17Ring;
9734 if (BTEST1(11))
9735 strat->posInT = posInT11Ring;
9736 else if (BTEST1(13))
9737 strat->posInT = posInT13;
9738 else if (BTEST1(15))
9739 strat->posInT = posInT15Ring;
9740 else if ((BTEST1(17)))
9741 strat->posInT = posInT17Ring;
9742 else if ((BTEST1(19)))
9743 strat->posInT = posInT19;
9744 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9745 strat->posInT = posInT1;
9747}
9748
9749void initBuchMora (ideal F,ideal Q,kStrategy strat)
9750{
9751 strat->interpt = BTEST1(OPT_INTERRUPT);
9752 /*- creating temp data structures------------------- -*/
9753 //strat->cp = 0; // already by skStragy()
9754 //strat->c3 = 0; // already by skStragy()
9755#ifdef HAVE_SHIFTBBA
9756 strat->cv = 0; // already by skStragy()
9757#endif
9758 strat->tail = pInit();
9759 /*- set s -*/
9760 strat->sl = -1;
9761 /*- set L -*/
9762 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9763 strat->Ll = -1;
9764 strat->L = initL(strat->Lmax);
9765 /*- set B -*/
9766 strat->Bmax = setmaxL;
9767 strat->Bl = -1;
9768 strat->B = initL();
9769 /*- set T -*/
9770 strat->tl = -1;
9771 strat->tmax = setmaxT;
9772 strat->T = initT();
9773 strat->R = initR();
9774 strat->sevT = initsevT();
9775 /*- init local data struct.---------------------------------------- -*/
9776 //strat->P.ecart=0; // already by skStragy()
9777 //strat->P.length=0; // already by skStragy()
9778 //strat->P.pLength=0; // already by skStragy()
9780 {
9781 if (strat->kNoether!=NULL)
9782 {
9783 pSetComp(strat->kNoether, strat->ak);
9784 pSetComp(strat->kNoetherTail(), strat->ak);
9785 }
9786 }
9788 {
9789 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9790 }
9791 else
9792 {
9793 if(TEST_OPT_SB_1)
9794 {
9795 int i;
9796 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
9797 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9798 {
9799 P->m[i-strat->newIdeal] = F->m[i];
9800 F->m[i] = NULL;
9801 }
9802 initSSpecial(F,Q,P,strat);
9803 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9804 {
9805 F->m[i] = P->m[i-strat->newIdeal];
9806 P->m[i-strat->newIdeal] = NULL;
9807 }
9808 idDelete(&P);
9809 }
9810 else
9811 {
9812 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9813 // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
9814 }
9815 if(errorreported) return;
9816 }
9817 strat->fromT = FALSE;
9819 if ((!TEST_OPT_SB_1)
9821 )
9822 {
9823 updateS(TRUE,strat);
9824 }
9825#ifdef HAVE_SHIFTBBA
9826 if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
9827#endif
9828 {
9829 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9830 strat->fromQ=NULL;
9831 }
9832 #ifdef KDEBUG
9833 assume(kTest_TS(strat));
9834 #endif
9835}
9836
9838{
9839 /*- release temp data -*/
9840 cleanT(strat);
9841 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
9842 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
9843 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
9844 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
9845 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
9846 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
9847 /*- set L: should be empty -*/
9848 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
9849 /*- set B: should be empty -*/
9850 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
9851 pLmFree(&strat->tail);
9852 strat->syzComp=0;
9853
9854#ifdef HAVE_SHIFTBBA
9855 if (rIsLPRing(currRing) && strat->rightGB)
9856 {
9857 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9858 strat->fromQ=NULL;
9859 }
9860#endif
9861}
9862
9864{
9866 {
9867 if (strat->honey)
9868 {
9869 if (TEST_OPT_OLDSTD)
9870 strat->posInT = posInT15;
9871 else
9872 strat->posInT = posInT_EcartpLength;
9873 }
9874 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9875 {
9876 strat->posInT = posInT11;
9877 }
9878 else if (TEST_OPT_INTSTRATEGY)
9879 {
9880 strat->posInT = posInT11;
9881 }
9882 else
9883 {
9884 strat->posInT = posInT0;
9885 }
9886 if (strat->homog)
9887 {
9888 strat->posInT = posInT110;
9889 }
9890 }
9891 else
9892 {
9893 if (strat->homog)
9894 {
9895 strat->posInT = posInT11;
9896 }
9897 else
9898 {
9899 if ((currRing->order[0]==ringorder_c)
9900 ||(currRing->order[0]==ringorder_C))
9901 {
9902 strat->posInT = posInT17_c;
9903 }
9904 else
9905 {
9906 strat->posInT = posInT17;
9907 }
9908 }
9909 }
9910 // for further tests only
9911 if (BTEST1(11))
9912 strat->posInT = posInT11;
9913 else if (BTEST1(13))
9914 strat->posInT = posInT13;
9915 else if (BTEST1(15))
9916 strat->posInT = posInT15;
9917 else if ((BTEST1(17)))
9918 strat->posInT = posInT17;
9919 else if ((BTEST1(19)))
9920 strat->posInT = posInT19;
9921 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9922 strat->posInT = posInT1;
9924 {
9925 strat->posInT = posInT11;
9926 }
9928 strat->posInL = posInLSig;
9929 /*
9930 if (rField_is_Ring(currRing))
9931 {
9932 strat->posInL = posInLSigRing;
9933 }*/
9934}
9935
9936void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
9937{
9938 strat->interpt = BTEST1(OPT_INTERRUPT);
9939 //strat->kNoether=NULL; // done by skStrategy
9940 /*- creating temp data structures------------------- -*/
9941 //strat->cp = 0; // done by skStrategy
9942 //strat->c3 = 0; // done by skStrategy
9943 strat->tail = pInit();
9944 /*- set s -*/
9945 strat->sl = -1;
9946 /*- set ps -*/
9947 strat->syzl = -1;
9948 /*- set L -*/
9949 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9950 strat->Ll = -1;
9951 strat->L = initL(strat->Lmax);
9952 /*- set B -*/
9953 strat->Bmax = setmaxL;
9954 strat->Bl = -1;
9955 strat->B = initL();
9956 /*- set T -*/
9957 strat->tl = -1;
9958 strat->tmax = setmaxT;
9959 strat->T = initT();
9960 strat->R = initR();
9961 strat->sevT = initsevT();
9962 /*- init local data struct.---------------------------------------- -*/
9963 //strat->P.ecart=0; // done by skStrategy
9964 //strat->P.length=0; // done by skStrategy
9966 {
9967 if (strat->kNoether!=NULL)
9968 {
9969 pSetComp(strat->kNoether, strat->ak);
9970 pSetComp(strat->kNoetherTail(), strat->ak);
9971 }
9972 }
9974 {
9975 /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
9976 }
9977 else
9978 {
9979 if(TEST_OPT_SB_1)
9980 {
9981 int i;
9982 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
9983 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9984 {
9985 P->m[i-strat->newIdeal] = F->m[i];
9986 F->m[i] = NULL;
9987 }
9988 initSSpecialSba(F,Q,P,strat);
9989 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9990 {
9991 F->m[i] = P->m[i-strat->newIdeal];
9992 P->m[i-strat->newIdeal] = NULL;
9993 }
9994 idDelete(&P);
9995 }
9996 else
9997 {
9998 initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
9999 }
10000 }
10001 //strat->fromT = FALSE; // done by skStrategy
10002 if (!TEST_OPT_SB_1)
10003 {
10004 if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10005 }
10006 //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10007 //strat->fromQ=NULL;
10008 assume(kTest_TS(strat));
10009}
10010
10011void exitSba (kStrategy strat)
10012{
10013 /*- release temp data -*/
10015 cleanTSbaRing(strat);
10016 else
10017 cleanT(strat);
10018 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10019 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10020 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10021 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10022 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10023 omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10024 if(strat->syzmax>0)
10025 {
10026 omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10027 omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10028 if (strat->sbaOrder == 1)
10029 {
10030 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10031 }
10032 }
10033 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10034 /*- set L: should be empty -*/
10035 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10036 /*- set B: should be empty -*/
10037 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10038 /*- set sig: no need for the signatures anymore -*/
10039 omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10040 pLmDelete(&strat->tail);
10041 strat->syzComp=0;
10042}
10043
10044/*2
10045* in the case of a standardbase of a module over a qring:
10046* replace polynomials in i by ak vectors,
10047* (the polynomial * unit vectors gen(1)..gen(ak)
10048* in every case (also for ideals:)
10049* deletes divisible vectors/polynomials
10050*/
10051void updateResult(ideal r,ideal Q, kStrategy strat)
10052{
10053 int l;
10054 if (strat->ak>0)
10055 {
10056 for (l=IDELEMS(r)-1;l>=0;l--)
10057 {
10058 if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10059 {
10060 pDelete(&r->m[l]); // and set it to NULL
10061 }
10062 }
10063 int q;
10064 poly p;
10066 {
10067 for (l=IDELEMS(r)-1;l>=0;l--)
10068 {
10069 if ((r->m[l]!=NULL)
10070 //&& (strat->syzComp>0)
10071 //&& (pGetComp(r->m[l])<=strat->syzComp)
10072 )
10073 {
10074 for(q=IDELEMS(Q)-1; q>=0;q--)
10075 {
10076 if ((Q->m[q]!=NULL)
10077 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10078 {
10079 if (TEST_OPT_REDSB)
10080 {
10081 p=r->m[l];
10082 r->m[l]=kNF(Q,NULL,p);
10083 pDelete(&p);
10084 }
10085 else
10086 {
10087 pDelete(&r->m[l]); // and set it to NULL
10088 }
10089 break;
10090 }
10091 }
10092 }
10093 }
10094 }
10095 else
10096 {
10097 for (l=IDELEMS(r)-1;l>=0;l--)
10098 {
10099 if ((r->m[l]!=NULL)
10100 //&& (strat->syzComp>0)
10101 //&& (pGetComp(r->m[l])<=strat->syzComp)
10102 )
10103 {
10104 for(q=IDELEMS(Q)-1; q>=0;q--)
10105 {
10106 if ((Q->m[q]!=NULL)
10107 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10108 {
10109 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10110 {
10111 if (TEST_OPT_REDSB)
10112 {
10113 p=r->m[l];
10114 r->m[l]=kNF(Q,NULL,p);
10115 pDelete(&p);
10116 }
10117 else
10118 {
10119 pDelete(&r->m[l]); // and set it to NULL
10120 }
10121 break;
10122 }
10123 }
10124 }
10125 }
10126 }
10127 }
10128 }
10129 else
10130 {
10131 int q;
10132 poly p;
10133 BOOLEAN reduction_found=FALSE;
10135 {
10136 for (l=IDELEMS(r)-1;l>=0;l--)
10137 {
10138 if (r->m[l]!=NULL)
10139 {
10140 for(q=IDELEMS(Q)-1; q>=0;q--)
10141 {
10142 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10143 {
10144 if (TEST_OPT_REDSB)
10145 {
10146 p=r->m[l];
10147 r->m[l]=kNF(Q,NULL,p);
10148 pDelete(&p);
10149 reduction_found=TRUE;
10150 }
10151 else
10152 {
10153 pDelete(&r->m[l]); // and set it to NULL
10154 }
10155 break;
10156 }
10157 }
10158 }
10159 }
10160 }
10161 //Also need divisibility of the leading coefficients
10162 else
10163 {
10164 for (l=IDELEMS(r)-1;l>=0;l--)
10165 {
10166 if (r->m[l]!=NULL)
10167 {
10168 for(q=IDELEMS(Q)-1; q>=0;q--)
10169 {
10170 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10171 {
10172 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10173 {
10174 if (TEST_OPT_REDSB)
10175 {
10176 p=r->m[l];
10177 r->m[l]=kNF(Q,NULL,p);
10178 pDelete(&p);
10179 reduction_found=TRUE;
10180 }
10181 else
10182 {
10183 pDelete(&r->m[l]); // and set it to NULL
10184 }
10185 break;
10186 }
10187 }
10188 }
10189 }
10190 }
10191 }
10192 if (/*TEST_OPT_REDSB &&*/ reduction_found)
10193 {
10195 {
10196 for (l=IDELEMS(r)-1;l>=0;l--)
10197 {
10198 if (r->m[l]!=NULL)
10199 {
10200 for(q=IDELEMS(r)-1;q>=0;q--)
10201 {
10202 if ((l!=q)
10203 && (r->m[q]!=NULL)
10204 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10205 &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10206 )
10207 {
10208 //If they are equal then take the one with the smallest length
10209 if(pLmDivisibleBy(r->m[q],r->m[l])
10210 && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10211 && (pLength(r->m[q]) < pLength(r->m[l]) ||
10212 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10213 {
10214 pDelete(&r->m[l]);
10215 break;
10216 }
10217 else
10218 pDelete(&r->m[q]);
10219 }
10220 }
10221 }
10222 }
10223 }
10224 else
10225 {
10226 for (l=IDELEMS(r)-1;l>=0;l--)
10227 {
10228 if (r->m[l]!=NULL)
10229 {
10230 for(q=IDELEMS(r)-1;q>=0;q--)
10231 {
10232 if ((l!=q)
10233 && (r->m[q]!=NULL)
10234 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10235 )
10236 {
10237 //If they are equal then take the one with the smallest length
10238 if(pLmDivisibleBy(r->m[q],r->m[l])
10239 &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10240 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10241 {
10242 pDelete(&r->m[l]);
10243 break;
10244 }
10245 else
10246 pDelete(&r->m[q]);
10247 }
10248 }
10249 }
10250 }
10251 }
10252 }
10253 }
10254 idSkipZeroes(r);
10255}
10256
10258{
10259 int i;
10260 int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10261 LObject L;
10262
10263#ifdef KDEBUG
10264 // need to set this: during tailreductions of T[i], T[i].max is out of
10265 // sync
10266 sloppy_max = TRUE;
10267#endif
10268
10269 strat->noTailReduction = FALSE;
10270 //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10271 if (TEST_OPT_PROT)
10272 {
10273 PrintLn();
10274// if (timerv) writeTime("standard base computed:");
10275 }
10276 if (TEST_OPT_PROT)
10277 {
10278 Print("(S:%d)",strat->sl);mflush();
10279 }
10280 for (i=strat->sl; i>=low; i--)
10281 {
10282 int end_pos=strat->sl;
10283 if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10284 if (strat->ak==0) end_pos=i-1;
10285 TObject* T_j = strat->s_2_t(i);
10286 if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10287 {
10288 L = *T_j;
10289 #ifdef KDEBUG
10290 if (TEST_OPT_DEBUG)
10291 {
10292 Print("test S[%d]:",i);
10293 p_wrp(L.p,currRing,strat->tailRing);
10294 PrintLn();
10295 }
10296 #endif
10298 strat->S[i] = redtailBba(&L, end_pos, strat, withT,FALSE /*no normalize*/);
10299 else
10300 strat->S[i] = redtail(&L, strat->sl, strat);
10301 #ifdef KDEBUG
10302 if (TEST_OPT_DEBUG)
10303 {
10304 Print("to (tailR) S[%d]:",i);
10305 p_wrp(strat->S[i],currRing,strat->tailRing);
10306 PrintLn();
10307 }
10308 #endif
10309
10310 if (strat->redTailChange)
10311 {
10312 if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10313 if (pNext(T_j->p) != NULL)
10314 T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10315 else
10316 T_j->max_exp = NULL;
10317 }
10319 T_j->pCleardenom();
10320 }
10321 else
10322 {
10323 assume(currRing == strat->tailRing);
10324 #ifdef KDEBUG
10325 if (TEST_OPT_DEBUG)
10326 {
10327 Print("test S[%d]:",i);
10328 p_wrp(strat->S[i],currRing,strat->tailRing);
10329 PrintLn();
10330 }
10331 #endif
10333 strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10334 else
10335 strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10337 {
10339 {
10340 number n;
10341 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10342 if (!nIsOne(n))
10343 {
10345 denom->n=nInvers(n);
10346 denom->next=DENOMINATOR_LIST;
10347 DENOMINATOR_LIST=denom;
10348 }
10349 nDelete(&n);
10350 }
10351 else
10352 {
10353 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10354 }
10355 }
10356 #ifdef KDEBUG
10357 if (TEST_OPT_DEBUG)
10358 {
10359 Print("to (-tailR) S[%d]:",i);
10360 p_wrp(strat->S[i],currRing,strat->tailRing);
10361 PrintLn();
10362 }
10363 #endif
10364 }
10365 if (TEST_OPT_PROT)
10366 PrintS("-");
10367 }
10368 if (TEST_OPT_PROT) PrintLn();
10369#ifdef KDEBUG
10370 sloppy_max = FALSE;
10371#endif
10372}
10373
10374
10375/*2
10376* computes the new strat->kNoether and the new pNoether,
10377* returns TRUE, if pNoether has changed
10378*/
10380{
10381 if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10382 return FALSE;
10383 int i,j;
10384 poly newNoether;
10385
10386#if 0
10387 if (currRing->weight_all_1)
10388 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10389 else
10390 scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kNoether);
10391#else
10392 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10393#endif
10394 if (strat->kNoether==NULL) return FALSE;
10395 if (strat->t_kNoether != NULL)
10396 {
10397 p_LmFree(strat->t_kNoether, strat->tailRing);
10398 strat->t_kNoether=NULL;
10399 }
10400 if (strat->tailRing != currRing)
10402 /* compare old and new noether*/
10403 newNoether = pLmInit(strat->kNoether);
10404 pSetCoeff0(newNoether,nInit(1));
10405 j = p_FDeg(newNoether,currRing);
10406 // newNoether is now the new highest edge (on the boundary)
10407 // now find the next monomial after highest monomial in R/I
10408 // (the smallest monomial not in R/I)
10409 for (i=currRing->N-1;i>0; i--)
10410 {
10411 int e;
10412 if ((e=pGetExp(newNoether, i)) > 0)
10413 {
10414 e--;
10415 pSetExp(newNoether,i,e);
10416 }
10417 }
10418 pSetm(newNoether);
10419 if (j < HCord) /*- statistics -*/
10420 {
10421 if (TEST_OPT_PROT)
10422 {
10423 Print("H(%d)",j);
10424 mflush();
10425 }
10426 HCord=j;
10427 #ifdef KDEBUG
10428 if (TEST_OPT_DEBUG)
10429 {
10430 Print("H(%d):",j);
10431 wrp(strat->kNoether);
10432 PrintLn();
10433 }
10434 #endif
10435 }
10436 if (pCmp(strat->kNoether,newNoether)!=1)
10437 {
10438 if (strat->kNoether!=NULL) p_LmDelete0(strat->kNoether,currRing);
10439 strat->kNoether=newNoether;
10440 if (strat->t_kNoether != NULL)
10441 {
10442 p_LmFree(strat->t_kNoether, strat->tailRing);
10443 strat->t_kNoether=NULL;
10444 }
10445 if (strat->tailRing != currRing)
10447
10448 return TRUE;
10449 }
10450 pLmDelete(newNoether);
10451 return FALSE;
10452}
10453
10454/***************************************************************
10455 *
10456 * Routines related for ring changes during std computations
10457 *
10458 ***************************************************************/
10459BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10460{
10461 if (strat->overflow) return FALSE;
10462 assume(L->p1 != NULL && L->p2 != NULL);
10463 // shift changes: from 0 to -1
10464 assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10465 assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10466
10467 if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10468 return FALSE;
10469 // shift changes: extra case inserted
10470 if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10471 {
10472 return TRUE;
10473 }
10474 poly p1_max=NULL;
10475 if ((L->i_r1>=0)&&(strat->R[L->i_r1]!=NULL)) p1_max = (strat->R[L->i_r1])->max_exp;
10476 poly p2_max=NULL;
10477 if ((L->i_r2>=0)&&(strat->R[L->i_r2]!=NULL)) p2_max = (strat->R[L->i_r2])->max_exp;
10478
10479 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10480 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10481 {
10482 p_LmFree(m1, strat->tailRing);
10483 p_LmFree(m2, strat->tailRing);
10484 m1 = NULL;
10485 m2 = NULL;
10486 return FALSE;
10487 }
10488 return TRUE;
10489}
10490
10491/***************************************************************
10492 *
10493 * Checks, if we can compute the gcd poly / strong pair
10494 * gcd-poly = m1 * R[atR] + m2 * S[atS]
10495 *
10496 ***************************************************************/
10497BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10498{
10499 assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10500 //assume(strat->tailRing != currRing);
10501
10502 poly p1_max = (strat->R[atR])->max_exp;
10503 poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10504
10505 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10506 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10507 {
10508 return FALSE;
10509 }
10510 return TRUE;
10511}
10512
10513/*!
10514 used for GB over ZZ: look for constant and monomial elements in the ideal
10515 background: any known constant element of ideal suppresses
10516 intermediate coefficient swell
10517*/
10518poly preIntegerCheck(const ideal Forig, const ideal Q)
10519{
10521 ideal F = idCopy(Forig);
10522 idSkipZeroes(F);
10523 poly pmon;
10524 ring origR = currRing;
10525 ideal monred = idInit(1,1);
10526 for(int i=0; i<idElem(F); i++)
10527 {
10528 if(pNext(F->m[i]) == NULL)
10529 idInsertPoly(monred, pCopy(F->m[i]));
10530 }
10531 int posconst = idPosConstant(F);
10532 if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10533 {
10534 idDelete(&F);
10535 idDelete(&monred);
10536 return NULL;
10537 }
10538 int idelemQ = 0;
10539 if(Q!=NULL)
10540 {
10541 idelemQ = IDELEMS(Q);
10542 for(int i=0; i<idelemQ; i++)
10543 {
10544 if(pNext(Q->m[i]) == NULL)
10545 idInsertPoly(monred, pCopy(Q->m[i]));
10546 }
10547 idSkipZeroes(monred);
10548 posconst = idPosConstant(monred);
10549 //the constant, if found, will be from Q
10550 if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10551 {
10552 pmon = pCopy(monred->m[posconst]);
10553 idDelete(&F);
10554 idDelete(&monred);
10555 return pmon;
10556 }
10557 }
10558 ring QQ_ring = rCopy0(currRing,FALSE);
10559 nKillChar(QQ_ring->cf);
10560 QQ_ring->cf = nInitChar(n_Q, NULL);
10561 rComplete(QQ_ring,1);
10562 QQ_ring = rAssure_c_dp(QQ_ring);
10563 rChangeCurrRing(QQ_ring);
10564 nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10565 ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10566 for(int i = 0, j = 0; i<IDELEMS(F); i++)
10567 II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10568 for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10569 II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10570 ideal one = kStd2(II, NULL, isNotHomog, NULL,(bigintmat*)NULL);
10571 idSkipZeroes(one);
10572 if(idIsConstant(one))
10573 {
10574 //one should be <1>
10575 for(int i = IDELEMS(II)-1; i>=0; i--)
10576 if(II->m[i] != NULL)
10577 II->m[i+1] = II->m[i];
10578 II->m[0] = pOne();
10579 ideal syz = idSyzygies(II, isNotHomog, NULL);
10580 poly integer = NULL;
10581 for(int i = IDELEMS(syz)-1;i>=0; i--)
10582 {
10583 if(pGetComp(syz->m[i]) == 1)
10584 {
10585 pSetComp(syz->m[i],0);
10586 if(pIsConstant(pHead(syz->m[i])))
10587 {
10588 integer = pHead(syz->m[i]);
10589 break;
10590 }
10591 }
10592 }
10593 rChangeCurrRing(origR);
10594 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10595 pmon = prMapR(integer, nMap2, QQ_ring, origR);
10596 idDelete(&monred);
10597 idDelete(&F);
10598 id_Delete(&II,QQ_ring);
10599 id_Delete(&one,QQ_ring);
10600 id_Delete(&syz,QQ_ring);
10601 p_Delete(&integer,QQ_ring);
10602 rDelete(QQ_ring);
10603 return pmon;
10604 }
10605 else
10606 {
10607 if(idIs0(monred))
10608 {
10609 poly mindegmon = NULL;
10610 for(int i = 0; i<IDELEMS(one); i++)
10611 {
10612 if(pNext(one->m[i]) == NULL)
10613 {
10614 if(mindegmon == NULL)
10615 mindegmon = pCopy(one->m[i]);
10616 else
10617 {
10618 if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10619 mindegmon = pCopy(one->m[i]);
10620 }
10621 }
10622 }
10623 if(mindegmon != NULL)
10624 {
10625 for(int i = IDELEMS(II)-1; i>=0; i--)
10626 if(II->m[i] != NULL)
10627 II->m[i+1] = II->m[i];
10628 II->m[0] = pCopy(mindegmon);
10629 ideal syz = idSyzygies(II, isNotHomog, NULL);
10630 bool found = FALSE;
10631 for(int i = IDELEMS(syz)-1;i>=0; i--)
10632 {
10633 if(pGetComp(syz->m[i]) == 1)
10634 {
10635 pSetComp(syz->m[i],0);
10636 if(pIsConstant(pHead(syz->m[i])))
10637 {
10638 pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10639 found = TRUE;
10640 break;
10641 }
10642 }
10643 }
10644 id_Delete(&syz,QQ_ring);
10645 if (found == FALSE)
10646 {
10647 rChangeCurrRing(origR);
10648 idDelete(&monred);
10649 idDelete(&F);
10650 id_Delete(&II,QQ_ring);
10651 id_Delete(&one,QQ_ring);
10652 rDelete(QQ_ring);
10653 return NULL;
10654 }
10655 rChangeCurrRing(origR);
10656 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10657 pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
10658 idDelete(&monred);
10659 idDelete(&F);
10660 id_Delete(&II,QQ_ring);
10661 id_Delete(&one,QQ_ring);
10662 id_Delete(&syz,QQ_ring);
10663 rDelete(QQ_ring);
10664 return pmon;
10665 }
10666 }
10667 }
10668 rChangeCurrRing(origR);
10669 idDelete(&monred);
10670 idDelete(&F);
10671 id_Delete(&II,QQ_ring);
10672 id_Delete(&one,QQ_ring);
10673 rDelete(QQ_ring);
10674 return NULL;
10675}
10676
10677/*!
10678 used for GB over ZZ: intermediate reduction by monomial elements
10679 background: any known constant element of ideal suppresses
10680 intermediate coefficient swell
10681*/
10683{
10684 if(!nCoeff_is_Z(currRing->cf))
10685 return;
10686 poly pH = h->GetP();
10687 poly p,pp;
10688 p = pH;
10689 bool deleted = FALSE, ok = FALSE;
10690 for(int i = 0; i<=strat->sl; i++)
10691 {
10692 p = pH;
10693 if(pNext(strat->S[i]) == NULL)
10694 {
10695 //pWrite(p);
10696 //pWrite(strat->S[i]);
10697 while(ok == FALSE && p != NULL)
10698 {
10699 if(pLmDivisibleBy(strat->S[i], p)
10700#ifdef HAVE_SHIFTBBA
10701 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], p))
10702#endif
10703 )
10704 {
10705 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10706 p_SetCoeff(p,dummy,currRing);
10707 }
10708 if(nIsZero(p->coef))
10709 {
10710 pLmDelete(&p);
10711 h->p = p;
10712 deleted = TRUE;
10713 }
10714 else
10715 {
10716 ok = TRUE;
10717 }
10718 }
10719 if (p!=NULL)
10720 {
10721 pp = pNext(p);
10722 while(pp != NULL)
10723 {
10724 if(pLmDivisibleBy(strat->S[i], pp)
10725#ifdef HAVE_SHIFTBBA
10726 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], pp))
10727#endif
10728 )
10729 {
10730 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10731 p_SetCoeff(pp,dummy,currRing);
10732 if(nIsZero(pp->coef))
10733 {
10734 pLmDelete(&pNext(p));
10735 pp = pNext(p);
10736 deleted = TRUE;
10737 }
10738 else
10739 {
10740 p = pp;
10741 pp = pNext(p);
10742 }
10743 }
10744 else
10745 {
10746 p = pp;
10747 pp = pNext(p);
10748 }
10749 }
10750 }
10751 }
10752 }
10753 h->SetLmCurrRing();
10754 if((deleted)&&(h->p!=NULL))
10755 strat->initEcart(h);
10756}
10757
10759{
10760 if(!nCoeff_is_Z(currRing->cf))
10761 return;
10762 poly hSig = h->sig;
10763 poly pH = h->GetP();
10764 poly p,pp;
10765 p = pH;
10766 bool deleted = FALSE, ok = FALSE;
10767 for(int i = 0; i<=strat->sl; i++)
10768 {
10769 p = pH;
10770 if(pNext(strat->S[i]) == NULL)
10771 {
10772 while(ok == FALSE && p!=NULL)
10773 {
10774 if(pLmDivisibleBy(strat->S[i], p))
10775 {
10776 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10777 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10778 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10779 {
10780 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10781 p_SetCoeff(p,dummy,currRing);
10782 }
10783 pDelete(&sigMult);
10784 }
10785 if(nIsZero(p->coef))
10786 {
10787 pLmDelete(&p);
10788 h->p = p;
10789 deleted = TRUE;
10790 }
10791 else
10792 {
10793 ok = TRUE;
10794 }
10795 }
10796 if(p == NULL)
10797 return;
10798 pp = pNext(p);
10799 while(pp != NULL)
10800 {
10801 if(pLmDivisibleBy(strat->S[i], pp))
10802 {
10803 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10804 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10805 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10806 {
10807 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10808 p_SetCoeff(pp,dummy,currRing);
10809 if(nIsZero(pp->coef))
10810 {
10811 pLmDelete(&pNext(p));
10812 pp = pNext(p);
10813 deleted = TRUE;
10814 }
10815 else
10816 {
10817 p = pp;
10818 pp = pNext(p);
10819 }
10820 }
10821 else
10822 {
10823 p = pp;
10824 pp = pNext(p);
10825 }
10826 pDelete(&sigMult);
10827 }
10828 else
10829 {
10830 p = pp;
10831 pp = pNext(p);
10832 }
10833 }
10834 }
10835 }
10836 h->SetLmCurrRing();
10837 if(deleted)
10838 strat->initEcart(h);
10839
10840}
10841
10842/*!
10843 used for GB over ZZ: final reduction by constant elements
10844 background: any known constant element of ideal suppresses
10845 intermediate coefficient swell and beautifies output
10846*/
10848{
10849 assume(strat->tl<0); /* can only be called with no elements in T:
10850 i.e. after exitBuchMora */
10851 /* do not use strat->S, strat->sl as they may be out of sync*/
10852 if(!nCoeff_is_Z(currRing->cf))
10853 return;
10854 poly p,pp;
10855 for(int j = 0; j<IDELEMS(strat->Shdl); j++)
10856 {
10857 if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
10858 {
10859 for(int i = 0; i<IDELEMS(strat->Shdl); i++)
10860 {
10861 if((i != j) && (strat->Shdl->m[i] != NULL))
10862 {
10863 p = strat->Shdl->m[i];
10864 while((p!=NULL) && (pLmDivisibleBy(strat->Shdl->m[j], p)
10865#if HAVE_SHIFTBBA
10866 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], p))
10867#endif
10868 ))
10869 {
10870 number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
10871 if (!nEqual(dummy,p->coef))
10872 {
10873 if (nIsZero(dummy))
10874 {
10875 nDelete(&dummy);
10876 pLmDelete(&strat->Shdl->m[i]);
10877 p=strat->Shdl->m[i];
10878 }
10879 else
10880 {
10881 p_SetCoeff(p,dummy,currRing);
10882 break;
10883 }
10884 }
10885 else
10886 {
10887 nDelete(&dummy);
10888 break;
10889 }
10890 }
10891 if (p!=NULL)
10892 {
10893 pp = pNext(p);
10894 while(pp != NULL)
10895 {
10896 if(pLmDivisibleBy(strat->Shdl->m[j], pp)
10897#if HAVE_SHIFTBBA
10898 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], pp))
10899#endif
10900 )
10901 {
10902 number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
10903 if (!nEqual(dummy,pp->coef))
10904 {
10905 p_SetCoeff(pp,dummy,currRing);
10906 if(nIsZero(pp->coef))
10907 {
10908 pLmDelete(&pNext(p));
10909 pp = pNext(p);
10910 }
10911 else
10912 {
10913 p = pp;
10914 pp = pNext(p);
10915 }
10916 }
10917 else
10918 {
10919 nDelete(&dummy);
10920 p = pp;
10921 pp = pNext(p);
10922 }
10923 }
10924 else
10925 {
10926 p = pp;
10927 pp = pNext(p);
10928 }
10929 }
10930 }
10931 }
10932 }
10933 //idPrint(strat->Shdl);
10934 }
10935 }
10936 idSkipZeroes(strat->Shdl);
10937}
10938
10939BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
10940{
10941 assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
10942 /* initial setup or extending */
10943
10944 if (rIsLPRing(currRing)) return TRUE;
10945 if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
10946 if (expbound >= currRing->bitmask) return FALSE;
10947 strat->overflow=FALSE;
10948 ring new_tailRing = rModifyRing(currRing,
10949 // Hmmm .. the condition pFDeg == p_Deg
10950 // might be too strong
10951 (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
10952 (strat->ak==0), // omit_comp if the input is an ideal
10953 expbound); // exp_limit
10954
10955 if (new_tailRing == currRing) return TRUE;
10956
10957 strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
10958 strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
10959
10960 if (currRing->pFDeg != currRing->pFDegOrig)
10961 {
10962 new_tailRing->pFDeg = currRing->pFDeg;
10963 new_tailRing->pLDeg = currRing->pLDeg;
10964 }
10965
10966 if (TEST_OPT_PROT)
10967 Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
10968 #ifdef KDEBUG
10969 kTest_TS(strat);
10970 assume(new_tailRing != strat->tailRing);
10971 #endif
10972 pShallowCopyDeleteProc p_shallow_copy_delete
10973 = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
10974
10975 omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
10976
10977 int i;
10978 for (i=0; i<=strat->tl; i++)
10979 {
10980 strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
10981 p_shallow_copy_delete);
10982 }
10983 for (i=0; i<=strat->Ll; i++)
10984 {
10985 assume(strat->L[i].p != NULL);
10986 if (pNext(strat->L[i].p) != strat->tail)
10987 strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
10988 }
10989 if ((strat->P.t_p != NULL) ||
10990 ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
10991 strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
10992
10993 if ((L != NULL) && (L->tailRing != new_tailRing))
10994 {
10995 if (L->i_r < 0)
10996 L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
10997 else
10998 {
10999 assume(L->i_r <= strat->tl);
11000 TObject* t_l = strat->R[L->i_r];
11001 assume(t_l != NULL);
11002 L->tailRing = new_tailRing;
11003 L->p = t_l->p;
11004 L->t_p = t_l->t_p;
11005 L->max_exp = t_l->max_exp;
11006 }
11007 }
11008
11009 if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11010 T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11011
11012 omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11013 if (strat->tailRing != currRing)
11015
11016 strat->tailRing = new_tailRing;
11017 strat->tailBin = new_tailBin;
11019 = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11020
11021 if (strat->kNoether != NULL)
11022 {
11023 if (strat->t_kNoether != NULL)
11024 p_LmFree(strat->t_kNoether, strat->tailRing);
11025 strat->t_kNoether=k_LmInit_currRing_2_tailRing(strat->kNoether, new_tailRing);
11026 }
11027
11028 #ifdef KDEBUG
11029 kTest_TS(strat);
11030 #endif
11031 if (TEST_OPT_PROT)
11032 PrintS("]");
11033 return TRUE;
11034}
11035
11037{
11038 unsigned long l = 0;
11039 int i;
11040 long e;
11041
11042 assume(strat->tailRing == currRing);
11043
11044 for (i=0; i<= strat->Ll; i++)
11045 {
11046 l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11047 }
11048 for (i=0; i<=strat->tl; i++)
11049 {
11050 // Hmm ... this we could do in one Step
11051 l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11052 }
11054 {
11055 l *= 2;
11056 }
11057 e = p_GetMaxExp(l, currRing);
11058 if (e <= 1) e = 2;
11059 if (rIsLPRing(currRing)) e = 1;
11060
11061 kStratChangeTailRing(strat, NULL, NULL, e);
11062}
11063
11064ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11065{
11066 int n = rBlocks(r); // Including trailing zero!
11067 // if sbaOrder == 1 => use (C,monomial order from r)
11068 if (strat->sbaOrder == 1)
11069 {
11070 if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11071 {
11072 return r;
11073 }
11074 ring res = rCopy0(r, TRUE, FALSE);
11075 res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11076 res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11077 res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11078 int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11079 res->wvhdl = wvhdl;
11080 for (int i=1; i<n; i++)
11081 {
11082 res->order[i] = r->order[i-1];
11083 res->block0[i] = r->block0[i-1];
11084 res->block1[i] = r->block1[i-1];
11085 res->wvhdl[i] = r->wvhdl[i-1];
11086 }
11087
11088 // new 1st block
11089 res->order[0] = ringorder_C; // Prefix
11090 // removes useless secondary component order if defined in old ring
11091 for (int i=rBlocks(res); i>0; --i)
11092 {
11093 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11094 {
11095 res->order[i] = (rRingOrder_t)0;
11096 }
11097 }
11098 rComplete(res, 1);
11099#ifdef HAVE_PLURAL
11100 if (rIsPluralRing(r))
11101 {
11102 if ( nc_rComplete(r, res, false) ) // no qideal!
11103 {
11104#ifndef SING_NDEBUG
11105 WarnS("error in nc_rComplete");
11106#endif
11107 // cleanup?
11108
11109 // rDelete(res);
11110 // return r;
11111
11112 // just go on..
11113 }
11114 }
11115#endif
11116 strat->tailRing = res;
11117 return (res);
11118 }
11119 // if sbaOrder == 3 => degree - position - ring order
11120 if (strat->sbaOrder == 3)
11121 {
11122 ring res = rCopy0(r, TRUE, FALSE);
11123 res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11124 res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11125 res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11126 int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11127 res->wvhdl = wvhdl;
11128 for (int i=2; i<n+2; i++)
11129 {
11130 res->order[i] = r->order[i-2];
11131 res->block0[i] = r->block0[i-2];
11132 res->block1[i] = r->block1[i-2];
11133 res->wvhdl[i] = r->wvhdl[i-2];
11134 }
11135
11136 // new 1st block
11137 res->order[0] = ringorder_a; // Prefix
11138 res->block0[0] = 1;
11139 res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11140 for (int i=0; i<res->N; ++i)
11141 res->wvhdl[0][i] = 1;
11142 res->block1[0] = si_min(res->N, rVar(res));
11143 // new 2nd block
11144 res->order[1] = ringorder_C; // Prefix
11145 res->wvhdl[1] = NULL;
11146 // removes useless secondary component order if defined in old ring
11147 for (int i=rBlocks(res); i>1; --i)
11148 {
11149 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11150 {
11151 res->order[i] = (rRingOrder_t)0;
11152 }
11153 }
11154 rComplete(res, 1);
11155#ifdef HAVE_PLURAL
11156 if (rIsPluralRing(r))
11157 {
11158 if ( nc_rComplete(r, res, false) ) // no qideal!
11159 {
11160#ifndef SING_NDEBUG
11161 WarnS("error in nc_rComplete");
11162#endif
11163 // cleanup?
11164
11165 // rDelete(res);
11166 // return r;
11167
11168 // just go on..
11169 }
11170 }
11171#endif
11172 strat->tailRing = res;
11173 return (res);
11174 }
11175
11176 // not sbaOrder == 1 => use Schreyer order
11177 // this is done by a trick when initializing the signatures
11178 // in initSLSba():
11179 // Instead of using the signature 1e_i for F->m[i], we start
11180 // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11181 // Schreyer order w.r.t. the underlying monomial order.
11182 // => we do not need to change the underlying polynomial ring at all!
11183
11184 // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11185
11186 /*
11187 else
11188 {
11189 ring res = rCopy0(r, FALSE, FALSE);
11190 // Create 2 more blocks for prefix/suffix:
11191 res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11192 res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11193 res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11194 int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11195
11196 // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11197 // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11198
11199 // new 1st block
11200 int j = 0;
11201 res->order[j] = ringorder_IS; // Prefix
11202 res->block0[j] = res->block1[j] = 0;
11203 // wvhdl[j] = NULL;
11204 j++;
11205
11206 for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11207 {
11208 res->order [j] = r->order [i];
11209 res->block0[j] = r->block0[i];
11210 res->block1[j] = r->block1[i];
11211
11212 if (r->wvhdl[i] != NULL)
11213 {
11214 wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11215 } // else wvhdl[j] = NULL;
11216 }
11217
11218 // new last block
11219 res->order [j] = ringorder_IS; // Suffix
11220 res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11221 // wvhdl[j] = NULL;
11222 j++;
11223
11224 // res->order [j] = 0; // The End!
11225 res->wvhdl = wvhdl;
11226
11227 // j == the last zero block now!
11228 assume(j == (n+1));
11229 assume(res->order[0]==ringorder_IS);
11230 assume(res->order[j-1]==ringorder_IS);
11231 assume(res->order[j]==0);
11232
11233 if (complete)
11234 {
11235 rComplete(res, 1);
11236
11237#ifdef HAVE_PLURAL
11238 if (rIsPluralRing(r))
11239 {
11240 if ( nc_rComplete(r, res, false) ) // no qideal!
11241 {
11242 }
11243 }
11244 assume(rIsPluralRing(r) == rIsPluralRing(res));
11245#endif
11246
11247
11248#ifdef HAVE_PLURAL
11249 ring old_ring = r;
11250
11251#endif
11252
11253 if (r->qideal!=NULL)
11254 {
11255 res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11256
11257 assume(idRankFreeModule(res->qideal, res) == 0);
11258
11259#ifdef HAVE_PLURAL
11260 if( rIsPluralRing(res) )
11261 if( nc_SetupQuotient(res, r, true) )
11262 {
11263 // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11264 }
11265
11266#endif
11267 assume(idRankFreeModule(res->qideal, res) == 0);
11268 }
11269
11270#ifdef HAVE_PLURAL
11271 assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11272 assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11273 assume(rIsSCA(res) == rIsSCA(old_ring));
11274 assume(ncRingType(res) == ncRingType(old_ring));
11275#endif
11276 }
11277 strat->tailRing = res;
11278 return res;
11279 }
11280 */
11281
11282 assume(FALSE);
11283 return(NULL);
11284}
11285
11287{
11288 memset(this, 0, sizeof(skStrategy));
11289 strat_nr++;
11290 nr=strat_nr;
11292 P.tailRing = currRing;
11293 tl = -1;
11294 sl = -1;
11295#ifdef HAVE_LM_BIN
11297#endif
11298#ifdef HAVE_TAIL_BIN
11300#endif
11301 pOrigFDeg = currRing->pFDeg;
11302 pOrigLDeg = currRing->pLDeg;
11303}
11304
11305
11307{
11309 if (lmBin != NULL)
11311 if (tailBin != NULL)// && !rField_is_Ring(currRing))
11313 ((tailRing != NULL) ? tailRing->PolyBin:
11314 currRing->PolyBin));
11315 if (t_kNoether != NULL)
11317
11318 if (currRing != tailRing)
11321}
11322
11323#if 0
11324Timings for the different possibilities of posInT:
11325 T15 EDL DL EL L 1-2-3
11326Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11327Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11328Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11329ahml 4.48 4.03 4.03 4.38 4.96 26.50
11330c7 15.02 13.98 15.16 13.24 17.31 47.89
11331c8 505.09 407.46 852.76 413.21 499.19 n/a
11332f855 12.65 9.27 14.97 8.78 14.23 33.12
11333gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11334gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11335ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11336noon8 40.68 37.02 37.99 36.82 35.59 877.16
11337rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11338rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11339schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11340test016 16.39 14.17 14.40 13.50 14.26 34.07
11341test017 34.70 36.01 33.16 35.48 32.75 71.45
11342test042 10.76 10.99 10.27 11.57 10.45 23.04
11343test058 6.78 6.75 6.51 6.95 6.22 9.47
11344test066 10.71 10.94 10.76 10.61 10.56 19.06
11345test073 10.75 11.11 10.17 10.79 8.63 58.10
11346test086 12.23 11.81 12.88 12.24 13.37 66.68
11347test103 5.05 4.80 5.47 4.64 4.89 11.90
11348test154 12.96 11.64 13.51 12.46 14.61 36.35
11349test162 65.27 64.01 67.35 59.79 67.54 196.46
11350test164 7.50 6.50 7.68 6.70 7.96 17.13
11351virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11352#endif
11353
11354
11355//#ifdef HAVE_MORE_POS_IN_T
11356#if 1
11357// determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11359{
11360
11361 if (length==-1) return 0;
11362
11363 int o = p.ecart;
11364 int op=p.GetpFDeg();
11365 int ol = p.GetpLength();
11366
11367 if (set[length].ecart < o)
11368 return length+1;
11369 if (set[length].ecart == o)
11370 {
11371 int oo=set[length].GetpFDeg();
11372 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11373 return length+1;
11374 }
11375
11376 int i;
11377 int an = 0;
11378 int en= length;
11379 loop
11380 {
11381 if (an >= en-1)
11382 {
11383 if (set[an].ecart > o)
11384 return an;
11385 if (set[an].ecart == o)
11386 {
11387 int oo=set[an].GetpFDeg();
11388 if((oo > op)
11389 || ((oo==op) && (set[an].pLength > ol)))
11390 return an;
11391 }
11392 return en;
11393 }
11394 i=(an+en) / 2;
11395 if (set[i].ecart > o)
11396 en=i;
11397 else if (set[i].ecart == o)
11398 {
11399 int oo=set[i].GetpFDeg();
11400 if ((oo > op)
11401 || ((oo == op) && (set[i].pLength > ol)))
11402 en=i;
11403 else
11404 an=i;
11405 }
11406 else
11407 an=i;
11408 }
11409}
11410
11411// determines the position based on: 1.) FDeg 2.) pLength
11412int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11413{
11414
11415 if (length==-1) return 0;
11416
11417 int op=p.GetpFDeg();
11418 int ol = p.GetpLength();
11419
11420 int oo=set[length].GetpFDeg();
11421 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11422 return length+1;
11423
11424 int i;
11425 int an = 0;
11426 int en= length;
11427 loop
11428 {
11429 if (an >= en-1)
11430 {
11431 int oo=set[an].GetpFDeg();
11432 if((oo > op)
11433 || ((oo==op) && (set[an].pLength > ol)))
11434 return an;
11435 return en;
11436 }
11437 i=(an+en) / 2;
11438 int oo=set[i].GetpFDeg();
11439 if ((oo > op)
11440 || ((oo == op) && (set[i].pLength > ol)))
11441 en=i;
11442 else
11443 an=i;
11444 }
11445}
11446
11447
11448// determines the position based on: 1.) pLength
11449int posInT_pLength(const TSet set,const int length,LObject &p)
11450{
11451 int ol = p.GetpLength();
11452 if (length==-1)
11453 return 0;
11454 if (set[length].length<p.length)
11455 return length+1;
11456
11457 int i;
11458 int an = 0;
11459 int en= length;
11460
11461 loop
11462 {
11463 if (an >= en-1)
11464 {
11465 if (set[an].pLength>ol) return an;
11466 return en;
11467 }
11468 i=(an+en) / 2;
11469 if (set[i].pLength>ol) en=i;
11470 else an=i;
11471 }
11472}
11473#endif
11474
11475// ../Singular/misc.cc:
11476extern char * showOption();
11477
11479{
11480 printf("red: ");
11481 if (strat->red==redFirst) printf("redFirst\n");
11482 else if (strat->red==redHoney) printf("redHoney\n");
11483 else if (strat->red==redEcart) printf("redEcart\n");
11484 else if (strat->red==redHomog) printf("redHomog\n");
11485 else if (strat->red==redLazy) printf("redLazy\n");
11486 else if (strat->red==redLiftstd) printf("redLiftstd\n");
11487 else printf("%p\n",(void*)strat->red);
11488 printf("posInT: ");
11489 if (strat->posInT==posInT0) printf("posInT0\n");
11490 else if (strat->posInT==posInT1) printf("posInT1\n");
11491 else if (strat->posInT==posInT11) printf("posInT11\n");
11492 else if (strat->posInT==posInT110) printf("posInT110\n");
11493 else if (strat->posInT==posInT13) printf("posInT13\n");
11494 else if (strat->posInT==posInT15) printf("posInT15\n");
11495 else if (strat->posInT==posInT17) printf("posInT17\n");
11496 else if (strat->posInT==posInT17_c) printf("posInT17_c\n");
11497 else if (strat->posInT==posInT19) printf("posInT19\n");
11498 else if (strat->posInT==posInT2) printf("posInT2\n");
11499 else if (strat->posInT==posInT11Ring) printf("posInT11Ring\n");
11500 else if (strat->posInT==posInT110Ring) printf("posInT110Ring\n");
11501 else if (strat->posInT==posInT15Ring) printf("posInT15Ring\n");
11502 else if (strat->posInT==posInT17Ring) printf("posInT17Ring\n");
11503 else if (strat->posInT==posInT17_cRing) printf("posInT17_cRing\n");
11504#ifdef HAVE_MORE_POS_IN_T
11505 else if (strat->posInT==posInT_EcartFDegpLength) printf("posInT_EcartFDegpLength\n");
11506 else if (strat->posInT==posInT_FDegpLength) printf("posInT_FDegpLength\n");
11507 else if (strat->posInT==posInT_pLength) printf("posInT_pLength\n");
11508#endif
11509 else if (strat->posInT==posInT_EcartpLength) printf("posInT_EcartpLength\n");
11510 else printf("%p\n",(void*)strat->posInT);
11511 printf("posInL: ");
11512 if (strat->posInL==posInL0) printf("posInL0\n");
11513 else if (strat->posInL==posInL10) printf("posInL10\n");
11514 else if (strat->posInL==posInL11) printf("posInL11\n");
11515 else if (strat->posInL==posInL110) printf("posInL110\n");
11516 else if (strat->posInL==posInL13) printf("posInL13\n");
11517 else if (strat->posInL==posInL15) printf("posInL15\n");
11518 else if (strat->posInL==posInL17) printf("posInL17\n");
11519 else if (strat->posInL==posInL17_c) printf("posInL17_c\n");
11520 else if (strat->posInL==posInL0) printf("posInL0Ring\n");
11521 else if (strat->posInL==posInL11Ring) printf("posInL11Ring\n");
11522 else if (strat->posInL==posInL11Ringls) printf("posInL11Ringls\n");
11523 else if (strat->posInL==posInL110Ring) printf("posInL110Ring\n");
11524 else if (strat->posInL==posInL15Ring) printf("posInL15Ring\n");
11525 else if (strat->posInL==posInL17Ring) printf("posInL17Ring\n");
11526 else if (strat->posInL==posInL17_cRing) printf("posInL17_cRing\n");
11527 else if (strat->posInL==posInLSpecial) printf("posInLSpecial\n");
11528 else printf("%p\n",(void*)strat->posInL);
11529 printf("enterS: ");
11530 if (strat->enterS==enterSBba) printf("enterSBba\n");
11531 else if (strat->enterS==enterSMora) printf("enterSMora\n");
11532 else if (strat->enterS==enterSMoraNF) printf("enterSMoraNF\n");
11533 else printf("%p\n",(void*)strat->enterS);
11534 printf("initEcart: ");
11535 if (strat->initEcart==initEcartBBA) printf("initEcartBBA\n");
11536 else if (strat->initEcart==initEcartNormal) printf("initEcartNormal\n");
11537 else printf("%p\n",(void*)strat->initEcart);
11538 printf("initEcartPair: ");
11539 if (strat->initEcartPair==initEcartPairBba) printf("initEcartPairBba\n");
11540 else if (strat->initEcartPair==initEcartPairMora) printf("initEcartPairMora\n");
11541 else printf("%p\n",(void*)strat->initEcartPair);
11542 printf("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11543 strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11544 printf("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11545 strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11546 printf("chainCrit: ");
11547 if (strat->chainCrit==chainCritNormal) printf("chainCritNormal\n");
11548 else if (strat->chainCrit==chainCritOpt_1) printf("chainCritOpt_1\n");
11549 else printf("%p\n",(void*)strat->chainCrit);
11550 printf("posInLDependsOnLength=%d\n",
11551 strat->posInLDependsOnLength);
11552 printf("%s\n",showOption());
11553 printf("LDeg: ");
11554 if (currRing->pLDeg==pLDeg0) printf("pLDeg0");
11555 else if (currRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11556 else if (currRing->pLDeg==pLDegb) printf("pLDegb");
11557 else if (currRing->pLDeg==pLDeg1) printf("pLDeg1");
11558 else if (currRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11559 else if (currRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11560 else if (currRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11561 else if (currRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11562 else if (currRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11563 else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11564 else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11565 else if (currRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11566 else printf("? (%lx)", (long)currRing->pLDeg);
11567 printf(" / ");
11568 if (strat->tailRing->pLDeg==pLDeg0) printf("pLDeg0");
11569 else if (strat->tailRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11570 else if (strat->tailRing->pLDeg==pLDegb) printf("pLDegb");
11571 else if (strat->tailRing->pLDeg==pLDeg1) printf("pLDeg1");
11572 else if (strat->tailRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11573 else if (strat->tailRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11574 else if (strat->tailRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11575 else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11576 else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11577 else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11578 else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11579 else if (strat->tailRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11580 else printf("? (%lx)", (long)strat->tailRing->pLDeg);
11581 printf("\n");
11582 printf("currRing->pFDeg: ");
11583 if (currRing->pFDeg==p_Totaldegree) printf("p_Totaldegree");
11584 else if (currRing->pFDeg==p_WFirstTotalDegree) printf("pWFirstTotalDegree");
11585 else if (currRing->pFDeg==p_Deg) printf("p_Deg");
11586 else if (currRing->pFDeg==kHomModDeg) printf("kHomModDeg");
11587 else if (currRing->pFDeg==kModDeg) printf("kModDeg");
11588 else if (currRing->pFDeg==totaldegreeWecart) printf("totaldegreeWecart");
11589 else if (currRing->pFDeg==p_WTotaldegree) printf("p_WTotaldegree");
11590 else printf("? (%lx)", (long)currRing->pFDeg);
11591 printf("\n");
11592 printf(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11594 printf(" degBound: %d\n", Kstd1_deg);
11595
11596 if( ecartWeights != NULL )
11597 {
11598 printf("ecartWeights: ");
11599 for (int i = rVar(currRing); i > 0; i--)
11600 printf("%hd ", ecartWeights[i]);
11601 printf("\n");
11603 }
11604
11605#ifndef SING_NDEBUG
11607#endif
11608}
11609
11610//LObject pCopyp2L(poly p, kStrategy strat)
11611//{
11612 /* creates LObject from the poly in currRing */
11613 /* actually put p into L.p and make L.t_p=NULL : does not work */
11614
11615//}
11616
11617/*2
11618* put the lcm(q,p) into the set B, q is the shift of some s[i]
11619*/
11620#ifdef HAVE_SHIFTBBA
11621static BOOLEAN enterOneStrongPolyShift (poly q, poly p, int /*ecart*/, int /*isFromQ*/, kStrategy strat, int atR, int /*ecartq*/, int /*qisFromQ*/, int shiftcount, int ifromS)
11622{
11623 number d, s, t;
11624 /* assume(atR >= 0); */
11625 assume(ifromS <= strat->sl);
11627 poly m1, m2, gcd;
11628 //printf("\n--------------------------------\n");
11629 //pWrite(p);pWrite(si);
11630 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q), &s, &t, currRing->cf);
11631
11632 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
11633 {
11634 nDelete(&d);
11635 nDelete(&s);
11636 nDelete(&t);
11637 return FALSE;
11638 }
11639
11640 assume(pIsInV(p));
11641
11642 k_GetStrongLeadTerms(p, q, currRing, m1, m2, gcd, strat->tailRing);
11643
11644 /* the V criterion */
11645 if (!pmIsInV(gcd))
11646 {
11647 strat->cv++;
11648 nDelete(&d);
11649 nDelete(&s);
11650 nDelete(&t);
11651 pLmFree(gcd);
11652 return FALSE;
11653 }
11654
11655 // disabled for Letterplace because it is not so easy to check
11656 /* if (!rHasLocalOrMixedOrdering(currRing)) { */
11657 /* unsigned long sev = pGetShortExpVector(gcd); */
11658
11659 /* for (int j = 0; j < strat->sl; j++) { */
11660 /* if (j == i) */
11661 /* continue; */
11662
11663 /* if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) && */
11664 /* !(strat->sevS[j] & ~sev) && */
11665 /* p_LmDivisibleBy(strat->S[j], gcd, currRing)) { */
11666 /* nDelete(&d); */
11667 /* nDelete(&s); */
11668 /* nDelete(&t); */
11669 /* return FALSE; */
11670 /* } */
11671 /* } */
11672 /* } */
11673
11674 poly m12, m22;
11678 // manually free the coeffs, because pSetCoeff0 is used in the next step
11679 n_Delete(&(m1->coef), currRing->cf);
11680 n_Delete(&(m2->coef), currRing->cf);
11681
11682 //p_Test(m1,strat->tailRing);
11683 //p_Test(m2,strat->tailRing);
11684 /*if(!enterTstrong)
11685 {
11686 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
11687 {
11688 memset(&(strat->P), 0, sizeof(strat->P));
11689 kStratChangeTailRing(strat);
11690 strat->P = *(strat->R[atR]);
11691 p_LmFree(m1, strat->tailRing);
11692 p_LmFree(m2, strat->tailRing);
11693 p_LmFree(gcd, currRing);
11694 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
11695 }
11696 }*/
11697 pSetCoeff0(m1, s);
11698 pSetCoeff0(m2, t);
11699 pSetCoeff0(gcd, d);
11700 p_Test(m1,strat->tailRing);
11701 p_Test(m2,strat->tailRing);
11702 p_Test(m12,strat->tailRing);
11703 p_Test(m22,strat->tailRing);
11704 assume(pmIsInV(m1));
11705 assume(pmIsInV(m2));
11706 assume(pmIsInV(m12));
11707 assume(pmIsInV(m22));
11708 //printf("\n===================================\n");
11709 //pWrite(m1);pWrite(m2);pWrite(gcd);
11710#ifdef KDEBUG
11711 if (TEST_OPT_DEBUG)
11712 {
11713 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
11714 PrintS("m1 = ");
11715 p_wrp(m1, strat->tailRing);
11716 PrintS("m12 = ");
11717 p_wrp(m12, strat->tailRing);
11718 PrintS(" ; m2 = ");
11719 p_wrp(m2, strat->tailRing);
11720 PrintS(" ; m22 = ");
11721 p_wrp(m22, strat->tailRing);
11722 PrintS(" ; gcd = ");
11723 wrp(gcd);
11724 PrintS("\n--- create strong gcd poly: ");
11725 PrintS("\n p: ");
11726 wrp(p);
11727 Print("\n q (strat->S[%d]): ", ifromS);
11728 wrp(q);
11729 PrintS(" ---> ");
11730 }
11731#endif
11732
11733 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);
11734 p_LmDelete(m1, strat->tailRing);
11735 p_LmDelete(m2, strat->tailRing);
11736 p_LmDelete(m12, strat->tailRing);
11737 p_LmDelete(m22, strat->tailRing);
11738
11739 assume(pIsInV(gcd));
11740
11741#ifdef KDEBUG
11742 if (TEST_OPT_DEBUG)
11743 {
11744 wrp(gcd);
11745 PrintLn();
11746 }
11747#endif
11748
11749 LObject h;
11750 h.p = gcd;
11751 h.tailRing = strat->tailRing;
11752 int posx;
11753 strat->initEcart(&h);
11754 h.sev = pGetShortExpVector(h.p);
11755 h.i_r1 = -1;h.i_r2 = -1;
11756 if (currRing!=strat->tailRing)
11757 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
11758#if 1
11759 h.p1 = p;
11760 h.p2 = q;
11761#endif
11762 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
11763 {
11764 h.i_r2 = kFindInT(h.p1, strat);
11765 h.i_r1 = atR;
11766 }
11767 else
11768 {
11769 h.i_r1 = -1;
11770 h.i_r2 = -1;
11771 }
11772 if (strat->Ll==-1)
11773 posx =0;
11774 else
11775 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
11776
11777 assume(pIsInV(h.p));
11778 assume(pIsInV(h.p1));
11779
11780 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
11781 return TRUE;
11782}
11783#endif
11784
11785
11786/*2
11787* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i] (ring case)
11788*/
11789#ifdef HAVE_SHIFTBBA
11790static void enterOnePairRingShift (poly q, poly p, int /*ecart*/, int isFromQ, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
11791{
11792 /* assume(atR >= 0); */
11793 /* assume(i<=strat->sl); */
11794 assume(p!=NULL);
11796 assume(pIsInV(p));
11797 #if ALL_VS_JUST
11798 //Over rings, if we construct the strong pair, do not add the spair
11800 {
11801 number s,t,d;
11802 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q, &s, &t, currRing->cf);
11803
11804 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
11805 {
11806 nDelete(&d);
11807 nDelete(&s);
11808 nDelete(&t);
11809 return;
11810 }
11811 nDelete(&d);
11812 nDelete(&s);
11813 nDelete(&t);
11814 }
11815 #endif
11816 int j,compare,compareCoeff;
11817 LObject h;
11818
11819#ifdef KDEBUG
11820 h.ecart=0; h.length=0;
11821#endif
11822 /*- computes the lcm(s[i],p) -*/
11823 if(pHasNotCFRing(p,q))
11824 {
11825 strat->cp++;
11826 return;
11827 }
11828 h.lcm = p_Lcm(p,q,currRing);
11829 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(q), currRing->cf));
11830 if (nIsZero(pGetCoeff(h.lcm)))
11831 {
11832 strat->cp++;
11833 pLmDelete(h.lcm);
11834 return;
11835 }
11836
11837 /* the V criterion */
11838 if (!pmIsInV(h.lcm))
11839 {
11840 strat->cv++;
11841 pLmDelete(h.lcm);
11842 return;
11843 }
11844 // basic chain criterion
11845 /*
11846 *the set B collects the pairs of type (S[j],p)
11847 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
11848 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
11849 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
11850 */
11851
11852 for(j = strat->Bl;j>=0;j--)
11853 {
11854 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
11855 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
11856 if(compare == pDivComp_EQUAL)
11857 {
11858 //They have the same LM
11859 if(compareCoeff == pDivComp_LESS)
11860 {
11861 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11862 {
11863 strat->c3++;
11864 pLmDelete(h.lcm);
11865 return;
11866 }
11867 break;
11868 }
11869 if(compareCoeff == pDivComp_GREATER)
11870 {
11871 deleteInL(strat->B,&strat->Bl,j,strat);
11872 strat->c3++;
11873 }
11874 if(compareCoeff == pDivComp_EQUAL)
11875 {
11876 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11877 {
11878 strat->c3++;
11879 pLmDelete(h.lcm);
11880 return;
11881 }
11882 break;
11883 }
11884 }
11885 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
11886 {
11887 if(compare == pDivComp_LESS)
11888 {
11889 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11890 {
11891 strat->c3++;
11892 pLmDelete(h.lcm);
11893 return;
11894 }
11895 break;
11896 }
11897 if(compare == pDivComp_GREATER)
11898 {
11899 deleteInL(strat->B,&strat->Bl,j,strat);
11900 strat->c3++;
11901 }
11902 }
11903 }
11904 number s, t;
11905 poly m1, m2, gcd = NULL;
11906 s = pGetCoeff(q);
11907 t = pGetCoeff(p);
11909
11910 poly m12, m22;
11914 // manually free the coeffs, because pSetCoeff0 is used in the next step
11915 n_Delete(&(m1->coef), currRing->cf);
11916 n_Delete(&(m2->coef), currRing->cf);
11917
11918 ksCheckCoeff(&s, &t, currRing->cf);
11919 pSetCoeff0(m1, s);
11920 pSetCoeff0(m2, t);
11921 m2 = pNeg(m2);
11922 p_Test(m1,strat->tailRing);
11923 p_Test(m2,strat->tailRing);
11924 p_Test(m12,strat->tailRing);
11925 p_Test(m22,strat->tailRing);
11926 assume(pmIsInV(m1));
11927 assume(pmIsInV(m2));
11928 assume(pmIsInV(m12));
11929 assume(pmIsInV(m22));
11930 poly pm1 = pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing);
11931 poly sim2 = pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing);
11932 assume(pIsInV(pm1));
11933 assume(pIsInV(sim2));
11934 p_LmDelete(m1, currRing);
11935 p_LmDelete(m2, currRing);
11936 p_LmDelete(m12, currRing);
11937 p_LmDelete(m22, currRing);
11938 if(sim2 == NULL)
11939 {
11940 if(pm1 == NULL)
11941 {
11942 if(h.lcm != NULL)
11943 {
11944 pLmDelete(h.lcm);
11945 h.lcm=NULL;
11946 }
11947 h.Clear();
11948 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
11949 /* if (strat->pairtest==NULL) initPairtest(strat); */
11950 /* strat->pairtest[i] = TRUE; */
11951 /* strat->pairtest[strat->sl+1] = TRUE; */
11952 return;
11953 }
11954 else
11955 {
11956 gcd = pm1;
11957 pm1 = NULL;
11958 }
11959 }
11960 else
11961 {
11962 if((pGetComp(q) == 0) && (0 != pGetComp(p)))
11963 {
11964 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
11965 pSetmComp(sim2);
11966 }
11967 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
11968 gcd = p_Add_q(pm1, sim2, strat->tailRing);
11969 }
11970 p_Test(gcd, strat->tailRing);
11971 assume(pIsInV(gcd));
11972#ifdef KDEBUG
11973 if (TEST_OPT_DEBUG)
11974 {
11975 wrp(gcd);
11976 PrintLn();
11977 }
11978#endif
11979 h.p = gcd;
11980 h.i_r = -1;
11981 if(h.p == NULL)
11982 {
11983 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
11984 /* if (strat->pairtest==NULL) initPairtest(strat); */
11985 /* strat->pairtest[i] = TRUE; */
11986 /* strat->pairtest[strat->sl+1] = TRUE; */
11987 return;
11988 }
11989 h.tailRing = strat->tailRing;
11990 int posx;
11991 //h.pCleardenom();
11992 //pSetm(h.p);
11993 h.i_r1 = -1;h.i_r2 = -1;
11994 strat->initEcart(&h);
11995 #if 1
11996 h.p1 = p;
11997 h.p2 = q;
11998 #endif
11999 #if 1
12000 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12001 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12002 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12003 {
12004 h.i_r2 = kFindInT(h.p1, strat); //strat->S_2_R[i];
12005 h.i_r1 = atR;
12006 }
12007 else
12008 {
12009 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12010 h.i_r1 = -1;
12011 h.i_r2 = -1;
12012 }
12013 #endif
12014 if (strat->Bl==-1)
12015 posx =0;
12016 else
12017 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
12018 h.sev = pGetShortExpVector(h.p);
12019 if (currRing!=strat->tailRing)
12020 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12021
12022 assume(pIsInV(h.p));
12023 assume(pIsInV(h.p1));
12024 assume(h.lcm != NULL);
12025 assume(pIsInV(h.lcm));
12026
12027 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
12028 kTest_TS(strat);
12029}
12030#endif
12031
12032#ifdef HAVE_SHIFTBBA
12033// adds the strong pair and the normal pair for rings (aka gpoly and spoly)
12034static BOOLEAN enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12035{
12036 enterOneStrongPolyShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "gpoly"
12037 enterOnePairRingShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "spoly"
12038 return FALSE; // TODO: delete q?
12039}
12040#endif
12041
12042#ifdef HAVE_SHIFTBBA
12043// creates if possible (q,p), (shifts(q),p)
12044static 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)
12045{
12046 // note: ecart and isFromQ is for p
12047 assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12048 assume(pmFirstVblock(p) == 1);
12049 assume(pmFirstVblock(q) == 1);
12050 assume(p_lastVblock == pmLastVblock(p));
12051 assume(q_lastVblock == pmLastVblock(q));
12052
12053 // TODO: is ecartq = 0 still ok?
12054 int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12055
12056 int q_isFromQ = 0;
12057 if (strat->fromQ != NULL && q_inS >= 0)
12058 q_isFromQ = strat->fromQ[q_inS];
12059
12060 BOOLEAN (*enterPair)(poly, poly, int, int, kStrategy, int, int, int, int, int);
12063 else
12064 enterPair = enterOnePairShift;
12065
12066 int degbound = currRing->N/currRing->isLPring;
12067 int neededShift = p_lastVblock - ((pGetComp(p) > 0 || pGetComp(q) > 0) ? 0 : 1); // in the module case, product criterion does not hold
12068 int maxPossibleShift = degbound - q_lastVblock;
12069 int maxShift = si_min(neededShift, maxPossibleShift);
12070 int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12071 BOOLEAN delete_pair=TRUE;
12072 for (int j = firstShift; j <= maxShift; j++)
12073 {
12074 poly qq = pLPCopyAndShiftLM(q, j);
12075 if (enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS))
12076 {
12077 if (j>0) pLmDelete(qq);
12078 // delete qq, if not it does not enter the pair set
12079 }
12080 else
12081 delete_pair=FALSE;
12082 }
12083
12084 if (rField_is_Ring(currRing) && p_lastVblock >= firstShift && p_lastVblock <= maxPossibleShift)
12085 {
12086 // add pairs (m*shifts(q), p) where m is a monomial and the pair has no overlap
12087 for (int j = p_lastVblock; j <= maxPossibleShift; j++)
12088 {
12089 ideal fillers = id_MaxIdeal(j - p_lastVblock, currRing);
12090 for (int k = 0; k < IDELEMS(fillers); k++)
12091 {
12092 poly qq = pLPCopyAndShiftLM(pp_mm_Mult(q, fillers->m[k], currRing), p_lastVblock);
12093 enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, p_lastVblock, q_inS);
12094 }
12095 idDelete(&fillers);
12096 }
12097 }
12098 return delete_pair;
12099}
12100#endif
12101
12102#ifdef HAVE_SHIFTBBA
12103// creates (q,p), use it when q is already shifted
12104// return TRUE, if (q,p) is discarded
12105static 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)
12106{
12107 // note: ecart and isFromQ is for p
12108 assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12109 assume(pmFirstVblock(p) == 1);
12110 assume(p_lastVblock == pmLastVblock(p));
12111 assume(q_shift == pmFirstVblock(q) - 1);
12112
12113 // TODO: is ecartp = 0 still ok?
12114 int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12115
12116 int p_isFromQ = 0;
12117 if (strat->fromQ != NULL && p_inS >= 0)
12118 p_isFromQ = strat->fromQ[p_inS];
12119
12121 {
12122 assume(q_shift <= p_lastVblock); // we allow the special case where there is no overlap
12123 return enterOneStrongPolyAndEnterOnePairRingShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12124 }
12125 else
12126 {
12127 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)
12128 return enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12129 }
12130}
12131#endif
12132
12133
12134#ifdef KDEBUG
12135// enable to print which pairs are considered or discarded and why
12136/* #define CRITERION_DEBUG */
12137#endif
12138/*2
12139* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12140* return TRUE, if (q,p) does not enter B
12141*/
12142#ifdef HAVE_SHIFTBBA
12143BOOLEAN enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12144{
12145#ifdef CRITERION_DEBUG
12146 if (TEST_OPT_DEBUG)
12147 {
12148 PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12149 // also write the LMs in separate lines:
12150 poly lmq = pHead(q);
12151 poly lmp = pHead(p);
12152 pSetCoeff(lmq, n_Init(1, currRing->cf));
12153 pSetCoeff(lmp, n_Init(1, currRing->cf));
12154 Print(" %s\n", pString(lmq));
12155 Print(" %s\n", pString(lmp));
12156 pLmDelete(lmq);
12157 pLmDelete(lmp);
12158 }
12159#endif
12160
12161 /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12162
12163 /* check this Formats: */
12168
12169 /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12170
12171 int qfromQ = qisFromQ;
12172
12173 /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12174
12175 int l,j,compare;
12176 LObject Lp;
12177 Lp.i_r = -1;
12178
12179#ifdef KDEBUG
12180 Lp.ecart=0; Lp.length=0;
12181#endif
12182 /*- computes the lcm(s[i],p) -*/
12183 Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12184
12185 /* the V criterion */
12186 if (!pmIsInV(Lp.lcm))
12187 {
12188 strat->cv++; // counter for applying the V criterion
12189 pLmFree(Lp.lcm);
12190#ifdef CRITERION_DEBUG
12191 if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12192#endif
12193 return TRUE;
12194 }
12195
12196 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12197 {
12198 if((!((ecartq>0)&&(ecart>0)))
12199 && pHasNotCF(p,q))
12200 {
12201 /*
12202 *the product criterion has applied for (s,p),
12203 *i.e. lcm(s,p)=product of the leading terms of s and p.
12204 *Suppose (s,r) is in L and the leading term
12205 *of p divides lcm(s,r)
12206 *(==> the leading term of p divides the leading term of r)
12207 *but the leading term of s does not divide the leading term of r
12208 *(notice that this condition is automatically satisfied if r is still
12209 *in S), then (s,r) can be cancelled.
12210 *This should be done here because the
12211 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12212 *
12213 *Moreover, skipping (s,r) holds also for the noncommutative case.
12214 */
12215 strat->cp++;
12216 pLmFree(Lp.lcm);
12217#ifdef CRITERION_DEBUG
12218 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12219#endif
12220 return TRUE;
12221 }
12222 else
12223 Lp.ecart = si_max(ecart,ecartq);
12224 if (strat->fromT && (ecartq>ecart))
12225 {
12226 pLmFree(Lp.lcm);
12227#ifdef CRITERION_DEBUG
12228 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12229#endif
12230 return TRUE;
12231 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12232 }
12233 /*
12234 *the set B collects the pairs of type (S[j],p)
12235 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12236 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12237 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12238 */
12239 {
12240 j = strat->Bl;
12241 loop
12242 {
12243 if (j < 0) break;
12244 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12245 if ((compare==1)
12246 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12247 {
12248 strat->c3++;
12249 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12250 {
12251 pLmFree(Lp.lcm);
12252#ifdef CRITERION_DEBUG
12253 if (TEST_OPT_DEBUG)
12254 {
12255 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12256 }
12257#endif
12258 return TRUE;
12259 }
12260 break;
12261 }
12262 else
12263 if ((compare ==-1)
12264 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12265 {
12266#ifdef CRITERION_DEBUG
12267 if (TEST_OPT_DEBUG)
12268 {
12269 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12270 }
12271#endif
12272 deleteInL(strat->B,&strat->Bl,j,strat);
12273 strat->c3++;
12274 }
12275 j--;
12276 }
12277 }
12278 }
12279 else /*sugarcrit*/
12280 {
12281 if (ALLOW_PROD_CRIT(strat))
12282 {
12283 // if currRing->nc_type!=quasi (or skew)
12284 // TODO: enable productCrit for super commutative algebras...
12285 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12286 pHasNotCF(p,q))
12287 {
12288 /*
12289 *the product criterion has applied for (s,p),
12290 *i.e. lcm(s,p)=product of the leading terms of s and p.
12291 *Suppose (s,r) is in L and the leading term
12292 *of p divides lcm(s,r)
12293 *(==> the leading term of p divides the leading term of r)
12294 *but the leading term of s does not divide the leading term of r
12295 *(notice that tis condition is automatically satisfied if r is still
12296 *in S), then (s,r) can be canceled.
12297 *This should be done here because the
12298 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12299 */
12300 strat->cp++;
12301 pLmFree(Lp.lcm);
12302#ifdef CRITERION_DEBUG
12303 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12304#endif
12305 return TRUE;
12306 }
12307 if (strat->fromT && (ecartq>ecart))
12308 {
12309 pLmFree(Lp.lcm);
12310#ifdef CRITERION_DEBUG
12311 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12312#endif
12313 return TRUE;
12314 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12315 }
12316 /*
12317 *the set B collects the pairs of type (S[j],p)
12318 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12319 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12320 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12321 */
12322 for(j = strat->Bl;j>=0;j--)
12323 {
12324 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12325 if (compare==1)
12326 {
12327 strat->c3++;
12328 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12329 {
12330 pLmFree(Lp.lcm);
12331#ifdef CRITERION_DEBUG
12332 if (TEST_OPT_DEBUG)
12333 {
12334 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12335 }
12336#endif
12337 return TRUE;
12338 }
12339 break;
12340 }
12341 else
12342 if (compare ==-1)
12343 {
12344#ifdef CRITERION_DEBUG
12345 if (TEST_OPT_DEBUG)
12346 {
12347 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12348 }
12349#endif
12350 deleteInL(strat->B,&strat->Bl,j,strat);
12351 strat->c3++;
12352 }
12353 }
12354 }
12355 }
12356 /*
12357 *the pair (S[i],p) enters B if the spoly != 0
12358 */
12359 /*- compute the short s-polynomial -*/
12360 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12361 pNorm(p);
12362 if ((q==NULL) || (p==NULL))
12363 {
12364#ifdef CRITERION_DEBUG
12365 if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
12366#endif
12367 return FALSE;
12368 }
12369 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12370 {
12371 Lp.p=NULL;
12372#ifdef CRITERION_DEBUG
12373 if (TEST_OPT_DEBUG) PrintS("--- pair is from Q\n");
12374#endif
12375 }
12376 else
12377 {
12378// if ( rIsPluralRing(currRing) )
12379// {
12380// if(pHasNotCF(p, q))
12381// {
12382// if(ncRingType(currRing) == nc_lie)
12383// {
12384// // generalized prod-crit for lie-type
12385// strat->cp++;
12386// Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12387// }
12388// else
12389// if( ALLOW_PROD_CRIT(strat) )
12390// {
12391// // product criterion for homogeneous case in SCA
12392// strat->cp++;
12393// Lp.p = NULL;
12394// }
12395// else
12396// Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12397// }
12398// else Lp.p = nc_CreateSpoly(q,p,currRing);
12399// }
12400// else
12401// {
12402
12403 /* ksCreateShortSpoly needs two Lobject-kind presentations */
12404 /* p is already in this form, so convert q */
12405 Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12406 // }
12407 }
12408 if (Lp.p == NULL)
12409 {
12410 /*- the case that the s-poly is 0 -*/
12411 // TODO: currently ifromS is only > 0 if called from enterOnePairWithShifts
12412 if (ifromS > 0)
12413 {
12414 if (strat->pairtest==NULL) initPairtest(strat);
12415 strat->pairtest[ifromS] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12416 strat->pairtest[strat->sl+1] = TRUE;
12417 }
12418 //if (TEST_OPT_DEBUG){Print("!");} // option teach
12419 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12420 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12421 /*
12422 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12423 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12424 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12425 *term of p divides the lcm(s,r)
12426 *(this canceling should be done here because
12427 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12428 *the first case is handled in chainCrit
12429 */
12430 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12431#ifdef CRITERION_DEBUG
12432 if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
12433#endif
12434 return TRUE;
12435 }
12436 else
12437 {
12438 /*- the pair (S[i],p) enters B -*/
12439 /* both of them should have their LM in currRing and TAIL in tailring */
12440 Lp.p1 = q; // already in the needed form
12441 Lp.p2 = p; // already in the needed form
12442
12443 if ( !rIsPluralRing(currRing) )
12444 pNext(Lp.p) = strat->tail;
12445
12446 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12447 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12448 if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12449 {
12450 Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12451 Lp.i_r2 = atR;
12452 }
12453 else
12454 {
12455 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12456 Lp.i_r1 = -1;
12457 Lp.i_r2 = -1;
12458 }
12459 strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12460
12462 {
12465 && (Lp.p->coef!=NULL))
12466 nDelete(&(Lp.p->coef));
12467 }
12468
12469 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12470 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12471#ifdef CRITERION_DEBUG
12472 if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
12473#endif
12474 }
12475 return FALSE;
12476}
12477#endif
12478
12479/*3
12480*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12481* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12482* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12483*/
12484#ifdef HAVE_SHIFTBBA
12485void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12486{
12487 int h_lastVblock = pmLastVblock(h);
12488 assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12489 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12490 if (h_lastVblock == 0) return;
12491 assume(pmFirstVblock(h) == 1);
12492 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12493 // atR = -1;
12494 if ((strat->syzComp==0)
12495 || (pGetComp(h)<=strat->syzComp))
12496 {
12497 int i,j;
12498 BOOLEAN new_pair=FALSE;
12499
12500 int degbound = currRing->N/currRing->isLPring;
12501 int maxShift = degbound - h_lastVblock;
12502
12503 if (pGetComp(h)==0)
12504 {
12505 if (strat->rightGB)
12506 {
12507 if (isFromQ)
12508 {
12509 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12510 for (i=0; i<=maxShift; i++)
12511 {
12512 poly hh = pLPCopyAndShiftLM(h, i);
12513 BOOLEAN delete_hh=TRUE;
12514 for (j=0; j<=k; j++)
12515 {
12516 if (strat->fromQ == NULL || !strat->fromQ[j])
12517 {
12518 new_pair=TRUE;
12519 poly s = strat->S[j];
12520 if (!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12521 delete_hh=FALSE;
12522 }
12523 }
12524 if (delete_hh) pLmDelete(hh);
12525 }
12526 }
12527 else
12528 {
12529 new_pair=TRUE;
12530 for (j=0; j<=k; j++)
12531 {
12532 poly s = strat->S[j];
12533 if (strat->fromQ != NULL && strat->fromQ[j])
12534 {
12535 // pairs (shifts(s[j]),h), (s[j],h)
12536 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12537 }
12538 else
12539 {
12540 // pair (h, s[j])
12541 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12542 }
12543 }
12544 }
12545 }
12546 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12547 else if ((isFromQ)&&(strat->fromQ!=NULL))
12548 {
12549 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12550 for (j=0; j<=k; j++)
12551 {
12552 if (!strat->fromQ[j])
12553 {
12554 new_pair=TRUE;
12555 poly s = strat->S[j];
12556 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12557 }
12558 }
12559 // pairs (shifts(h),s[1..k])
12560 if (new_pair)
12561 {
12562 for (i=1; i<=maxShift; i++)
12563 {
12564 BOOLEAN delete_hh=TRUE;
12565 poly hh = pLPCopyAndShiftLM(h, i);
12566 for (j=0; j<=k; j++)
12567 {
12568 if (!strat->fromQ[j])
12569 {
12570 poly s = strat->S[j];
12571 int s_lastVblock = pmLastVblock(s);
12572 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)
12573 {
12574 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i))
12575 delete_hh=FALSE;
12576 }
12577 else if (rField_is_Ring(currRing))
12578 {
12579 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12580 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12581 for (int k = 0; k < IDELEMS(fillers); k++)
12582 {
12583 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12584 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12585 }
12586 idDelete(&fillers);
12587 }
12588 }
12589 }
12590 if (delete_hh) p_LmDelete(hh,currRing);
12591 }
12592 }
12593 }
12594 else
12595 {
12596 new_pair=TRUE;
12597 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12598 for (j=0; j<=k; j++)
12599 {
12600 poly s = strat->S[j];
12601 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12602 }
12603 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12604 for (i=1; i<=maxShift; i++)
12605 {
12606 poly hh = pLPCopyAndShiftLM(h, i);
12607 BOOLEAN delete_hh=TRUE;
12608 for (j=0; j<=k; j++)
12609 {
12610 poly s = strat->S[j];
12611 int s_lastVblock = pmLastVblock(s);
12612 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)
12613 delete_hh=enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i)
12614 && delete_hh;
12615 else if (rField_is_Ring(currRing))
12616 {
12617 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12618 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12619 for (int k = 0; k < IDELEMS(fillers); k++)
12620 {
12621 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12622 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12623 }
12624 idDelete(&fillers);
12625 }
12626 }
12627 if (i < h_lastVblock) // in the module case, product criterion does not hold (note: comp h is always zero here)
12628 delete_hh=enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i)
12629 && delete_hh;
12630 else if (rField_is_Ring(currRing))
12631 {
12632 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12633 ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
12634 for (int k = 0; k < IDELEMS(fillers); k++)
12635 {
12636 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
12637 enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock);
12638 }
12639 idDelete(&fillers);
12640 }
12641 if (delete_hh) pLmDelete(hh);
12642 }
12643 }
12644 }
12645 else
12646 {
12647 assume(isFromQ == 0); // an element from Q should always has 0 component
12648 new_pair=TRUE;
12649 if (strat->rightGB)
12650 {
12651 for (j=0; j<=k; j++)
12652 {
12653 if ((pGetComp(h)==pGetComp(strat->S[j]))
12654 || (pGetComp(strat->S[j])==0))
12655 {
12656 poly s = strat->S[j];
12657 if (strat->fromQ != NULL && strat->fromQ[j])
12658 {
12659 // pairs (shifts(s[j]),h), (s[j],h)
12660 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12661 }
12662 else
12663 {
12664 // pair (h, s[j])
12665 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12666 }
12667 }
12668 }
12669 }
12670 else
12671 {
12672 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12673 for (j=0; j<=k; j++)
12674 {
12675 if ((pGetComp(h)==pGetComp(strat->S[j]))
12676 || (pGetComp(strat->S[j])==0))
12677 {
12678 poly s = strat->S[j];
12679 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12680 }
12681 }
12682 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12683 for (i=1; i<=maxShift; i++)
12684 {
12685 poly hh = pLPCopyAndShiftLM(h, i);
12686 for (j=0; j<=k; j++)
12687 {
12688 if ((pGetComp(h)==pGetComp(strat->S[j]))
12689 || (pGetComp(strat->S[j])==0))
12690 {
12691 poly s = strat->S[j];
12692 int s_lastVblock = pmLastVblock(s);
12693 if (i <= s_lastVblock) // in the module case, product criterion does not hold
12694 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
12695 else if (rField_is_Ring(currRing))
12696 {
12697 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12698 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12699 for (int k = 0; k < IDELEMS(fillers); k++)
12700 {
12701 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12702 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12703 }
12704 idDelete(&fillers);
12705 }
12706 }
12707 }
12708 if (i <= h_lastVblock) // in the module case, product criterion does not hold
12709 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12710 else if (rField_is_Ring(currRing))
12711 {
12712 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12713 ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
12714 for (int k = 0; k < IDELEMS(fillers); k++)
12715 {
12716 BOOLEAN delete_hhh=TRUE;
12717 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
12718 if(!enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock))
12719 delete_hhh=FALSE;
12720 if (delete_hhh) p_LmDelete(hhh,currRing);
12721 }
12722 idDelete(&fillers);
12723 }
12724 }
12725 }
12726 }
12727
12728 if (new_pair)
12729 {
12730 strat->chainCrit(h,ecart,strat);
12731 }
12732 kMergeBintoL(strat);
12733 }
12734}
12735#endif
12736
12737/*3
12738*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12739* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12740* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12741*/
12742#ifdef HAVE_SHIFTBBA
12743void initenterstrongPairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12744{
12745 int h_lastVblock = pmLastVblock(h);
12746 assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12747 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12748 if (h_lastVblock == 0) return;
12749 assume(pmFirstVblock(h) == 1);
12750 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12751 // atR = -1;
12752 if ((strat->syzComp==0)
12753 || (pGetComp(h)<=strat->syzComp))
12754 {
12755 int i,j;
12756 BOOLEAN new_pair=FALSE;
12757
12758 int degbound = currRing->N/currRing->isLPring;
12759 int maxShift = degbound - h_lastVblock;
12760
12761 if (pGetComp(h)==0)
12762 {
12763 if (strat->rightGB)
12764 {
12765 if (isFromQ)
12766 {
12767 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12768 for (i=0; i<=maxShift; i++)
12769 {
12770 poly hh = pLPCopyAndShiftLM(h, i);
12771 for (j=0; j<=k; j++)
12772 {
12773 if (strat->fromQ == NULL || !strat->fromQ[j])
12774 {
12775 new_pair=TRUE;
12776 poly s = strat->S[j];
12777 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12778 }
12779 }
12780 }
12781 }
12782 else
12783 {
12784 new_pair=TRUE;
12785 for (j=0; j<=k; j++)
12786 {
12787 poly s = strat->S[j];
12788 if (strat->fromQ != NULL && strat->fromQ[j])
12789 {
12790 // pairs (shifts(s[j]),h), (s[j],h)
12791 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12792 }
12793 else
12794 {
12795 // pair (h, s[j])
12796 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12797 }
12798 }
12799 }
12800 }
12801 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12802 else if ((isFromQ)&&(strat->fromQ!=NULL))
12803 {
12804 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12805 for (j=0; j<=k; j++)
12806 {
12807 if (!strat->fromQ[j])
12808 {
12809 new_pair=TRUE;
12810 poly s = strat->S[j];
12811 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12812 }
12813 }
12814 // pairs (shifts(h),s[1..k])
12815 if (new_pair)
12816 {
12817 for (i=1; i<=maxShift; i++)
12818 {
12819 poly hh = pLPCopyAndShiftLM(h, i);
12820 for (j=0; j<=k; j++)
12821 {
12822 if (!strat->fromQ[j])
12823 {
12824 poly s = strat->S[j];
12825 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12826 }
12827 }
12828 }
12829 }
12830 }
12831 else
12832 {
12833 new_pair=TRUE;
12834 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12835 for (j=0; j<=k; j++)
12836 {
12837 poly s = strat->S[j];
12838 // TODO: cache lastVblock of s[1..k] for later use
12839 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12840 }
12841 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12842 for (i=1; i<=maxShift; i++)
12843 {
12844 poly hh = pLPCopyAndShiftLM(h, i);
12845 BOOLEAN delete_hh=TRUE;
12846 for (j=0; j<=k; j++)
12847 {
12848 poly s = strat->S[j];
12849 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12850 delete_hh=FALSE;
12851 }
12852 if(!enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i))
12853 delete_hh=FALSE;
12854 if (delete_hh) p_LmDelete(hh,currRing);
12855 }
12856 }
12857 }
12858 else
12859 {
12860 new_pair=TRUE;
12861 if (strat->rightGB)
12862 {
12863 for (j=0; j<=k; j++)
12864 {
12865 if ((pGetComp(h)==pGetComp(strat->S[j]))
12866 || (pGetComp(strat->S[j])==0))
12867 {
12868 assume(isFromQ == 0); // this case is not handled here and should also never happen
12869 poly s = strat->S[j];
12870 if (strat->fromQ != NULL && strat->fromQ[j])
12871 {
12872 // pairs (shifts(s[j]),h), (s[j],h)
12873 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12874 }
12875 else
12876 {
12877 // pair (h, s[j])
12878 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12879 }
12880 }
12881 }
12882 }
12883 else
12884 {
12885 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12886 for (j=0; j<=k; j++)
12887 {
12888 if ((pGetComp(h)==pGetComp(strat->S[j]))
12889 || (pGetComp(strat->S[j])==0))
12890 {
12891 poly s = strat->S[j];
12892 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12893 }
12894 }
12895 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12896 for (i=1; i<=maxShift; i++)
12897 {
12898 poly hh = pLPCopyAndShiftLM(h, i);
12899 for (j=0; j<=k; j++)
12900 {
12901 if ((pGetComp(h)==pGetComp(strat->S[j]))
12902 || (pGetComp(strat->S[j])==0))
12903 {
12904 poly s = strat->S[j];
12905 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12906 }
12907 }
12908 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12909 }
12910 }
12911 }
12912
12913 if (new_pair)
12914 {
12915 strat->chainCrit(h,ecart,strat);
12916 }
12917 kMergeBintoL(strat);
12918 }
12919}
12920#endif
12921
12922/*2
12923*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
12924*superfluous elements in S will be deleted
12925*/
12926#ifdef HAVE_SHIFTBBA
12927void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
12928{
12929 /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12930 /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
12931 int j=pos;
12932
12933 /* if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat); */ // TODO: enterExtendedSpoly not for LP yet
12934 initenterpairsShift(h,k,ecart,0,strat, atR);
12935 if ( (!strat->fromT)
12936 && ((strat->syzComp==0)
12937 ||(pGetComp(h)<=strat->syzComp)))
12938 {
12939 unsigned long h_sev = pGetShortExpVector(h);
12940 loop
12941 {
12942 if (j > k) break;
12943 // TODO this currently doesn't clear all possible elements because of commutative division
12944 if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
12945 clearS(h,h_sev, &j,&k,strat);
12946 j++;
12947 }
12948 }
12949}
12950#endif
12951
12952/*2
12953* enteres all admissible shifts of p into T
12954* assumes that p is already in T!
12955*/
12956#ifdef HAVE_SHIFTBBA
12957void enterTShift(LObject* p, kStrategy strat, int atT)
12958{
12959 /* determine how many elements we have to insert */
12960 /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12961 /* hence, a total number of elt's to add is: */
12962 /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12963 pAssume(p->p != NULL);
12964
12965 int maxPossibleShift = p_mLPmaxPossibleShift(p->p, strat->tailRing);
12966
12967 for (int i = 1; i <= maxPossibleShift; i++)
12968 {
12969 LObject qq;
12970 qq.p = pLPCopyAndShiftLM(p->p, i); // don't use Set() because it'll test the poly order
12971 qq.shift = i;
12972 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
12973
12974 enterT(&qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
12975 }
12976}
12977#endif
12978
12979#ifdef HAVE_SHIFTBBA
12981{
12982 /* for the shift case need to run it with withT = TRUE */
12983 strat->redTailChange=FALSE;
12984 if (strat->noTailReduction) return L->GetLmCurrRing();
12985 poly h, p;
12986 p = h = L->GetLmTailRing();
12987 if ((h==NULL) || (pNext(h)==NULL))
12988 return L->GetLmCurrRing();
12989
12990 TObject* With;
12991 // placeholder in case strat->tl < 0
12992 TObject With_s(strat->tailRing);
12993
12994 LObject Ln(pNext(h), strat->tailRing);
12995 Ln.pLength = L->GetpLength() - 1;
12996
12997 pNext(h) = NULL;
12998 if (L->p != NULL) pNext(L->p) = NULL;
12999 L->pLength = 1;
13000
13001 Ln.PrepareRed(strat->use_buckets);
13002
13003 while(!Ln.IsNull())
13004 {
13005 loop
13006 {
13007 Ln.SetShortExpVector();
13008 if (withT)
13009 {
13010 int j;
13011 j = kFindDivisibleByInT(strat, &Ln);
13012 if (j < 0) break;
13013 With = &(strat->T[j]);
13014 }
13015 else
13016 {
13017 With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
13018 if (With == NULL) break;
13019 }
13020 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
13021 {
13022 With->pNorm();
13023 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
13024 }
13025 strat->redTailChange=TRUE;
13026 if (ksReducePolyTail(L, With, &Ln))
13027 {
13028 // reducing the tail would violate the exp bound
13029 // set a flag and hope for a retry (in bba)
13031 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
13032 do
13033 {
13034 pNext(h) = Ln.LmExtractAndIter();
13035 pIter(h);
13036 L->pLength++;
13037 } while (!Ln.IsNull());
13038 goto all_done;
13039 }
13040 if (Ln.IsNull()) goto all_done;
13041 if (! withT) With_s.Init(currRing);
13042 }
13043 pNext(h) = Ln.LmExtractAndIter();
13044 pIter(h);
13045 L->pLength++;
13046 }
13047
13048 all_done:
13049 Ln.Delete();
13050 if (L->p != NULL) pNext(L->p) = pNext(p);
13051
13052 if (strat->redTailChange)
13053 {
13054 L->length = 0;
13055 }
13056 L->Normalize(); // HANNES: should have a test
13057 kTest_L(L,strat);
13058 return L->GetLmCurrRing();
13059}
13060#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
void * ADDRESS
Definition auxiliary.h:120
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
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:322
kStrategy next
Definition kutil.h:278
bool sigdrop
Definition kutil.h:357
poly t_kNoether
Definition kutil.h:329
int syzComp
Definition kutil.h:353
int * S_2_R
Definition kutil.h:341
ring tailRing
Definition kutil.h:342
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition kutil.h:290
char noTailReduction
Definition kutil.h:375
int currIdx
Definition kutil.h:316
int nrsyzcrit
Definition kutil.h:358
intset lenS
Definition kutil.h:318
int nrrewcrit
Definition kutil.h:359
pFDegProc pOrigFDeg_TailRing
Definition kutil.h:297
int Ll
Definition kutil.h:350
TSet T
Definition kutil.h:325
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition kutil.h:292
char news
Definition kutil.h:397
omBin lmBin
Definition kutil.h:343
int syzmax
Definition kutil.h:348
int Bl
Definition kutil.h:351
intset ecartS
Definition kutil.h:308
int syzidxmax
Definition kutil.h:348
char honey
Definition kutil.h:374
char rightGB
Definition kutil.h:366
polyset S
Definition kutil.h:305
int minim
Definition kutil.h:356
poly kNoether
Definition kutil.h:328
BOOLEAN * NotUsedAxis
Definition kutil.h:331
LSet B
Definition kutil.h:327
BOOLEAN * pairtest
Definition kutil.h:332
int cp
Definition kutil.h:346
int ak
Definition kutil.h:352
TObject ** R
Definition kutil.h:339
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition kutil.h:294
int tl
Definition kutil.h:349
unsigned long * sevT
Definition kutil.h:324
unsigned long * sevSig
Definition kutil.h:323
int nr
Definition kutil.h:345
poly tail
Definition kutil.h:333
char sugarCrit
Definition kutil.h:374
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition kutil.h:283
KINLINE TObject * s_2_t(int i)
Definition kInline.h:47
intset syzIdx
Definition kutil.h:312
ideal Shdl
Definition kutil.h:302
int syzl
Definition kutil.h:348
unsigned sbaOrder
Definition kutil.h:315
pFDegProc pOrigFDeg
Definition kutil.h:295
int tmax
Definition kutil.h:349
polyset sig
Definition kutil.h:307
polyset syz
Definition kutil.h:306
char LDegLast
Definition kutil.h:382
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition kutil.h:286
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.h:291
wlen_set lenSw
Definition kutil.h:319
void(* enterS)(LObject *h, int pos, kStrategy strat, int atR)
Definition kutil.h:285
char kAllAxis
Definition kutil.h:373
int cv
Definition kutil.h:365
pShallowCopyDeleteProc p_shallow_copy_delete
Definition kutil.h:337
char Gebauer
Definition kutil.h:375
intset fromQ
Definition kutil.h:320
char newt
Definition kutil.h:398
char use_buckets
Definition kutil.h:380
char interpt
Definition kutil.h:368
char redTailChange
Definition kutil.h:396
int newIdeal
Definition kutil.h:355
char fromT
Definition kutil.h:376
char completeReduce_retry
Definition kutil.h:400
void(* initEcart)(TObject *L)
Definition kutil.h:281
omBin tailBin
Definition kutil.h:344
LObject P
Definition kutil.h:301
KINLINE TObject * S_2_T(int i)
Definition kInline.h:38
char noClearS
Definition kutil.h:399
int Lmax
Definition kutil.h:350
char z2homog
Definition kutil.h:371
int LazyPass
Definition kutil.h:352
char overflow
Definition kutil.h:401
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.h:289
LSet L
Definition kutil.h:326
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:347
int LazyDegree
Definition kutil.h:352
char posInLDependsOnLength
Definition kutil.h:386
unsigned long * sevS
Definition kutil.h:321
char homog
Definition kutil.h:369
pLDegProc pOrigLDeg
Definition kutil.h:296
pLDegProc pOrigLDeg_TailRing
Definition kutil.h:298
int Bmax
Definition kutil.h:351
int c3
Definition kutil.h:346
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition coeffs.h:814
@ 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:747
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
VAR short errorreported
Definition feFopen.cc:23
if(!FE_OPT_NO_SHELL_FLAG)
Definition fehelp.cc:1000
#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:834
#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
long kHomModDeg(poly p, const ring r)
Definition kstd1.cc:2421
int redFirst(LObject *h, kStrategy strat)
Definition kstd1.cc:794
long kModDeg(poly p, const ring r)
Definition kstd1.cc:2411
int redEcart(LObject *h, kStrategy strat)
Definition kstd1.cc:168
void enterSMora(LObject *p, int atS, kStrategy strat, int atR)
Definition kstd1.cc:1629
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:2607
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition kstd1.cc:3230
void enterSMoraNF(LObject *p, int atS, kStrategy strat, int atR)
Definition kstd1.cc:1682
EXTERN_VAR int Kstd1_deg
Definition kstd1.h:70
EXTERN_VAR int Kstd1_mu
Definition kstd1.h:70
int kFindDivisibleByInT_Z(const kStrategy strat, const LObject *L, const int start)
Definition kstd2.cc:209
int redHoney(LObject *h, kStrategy strat)
Definition kstd2.cc:2110
int redHomog(LObject *h, kStrategy strat)
Definition kstd2.cc:1150
int redLazy(LObject *h, kStrategy strat)
Definition kstd2.cc:1905
poly redNF(poly h, int &max_ind, int nonorm, kStrategy strat)
Definition kstd2.cc:2307
int redRing(LObject *h, kStrategy strat)
Definition kstd2.cc:988
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:317
void initSbaPos(kStrategy strat)
Definition kutil.cc:9863
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:6836
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6299
#define pDivComp_LESS
Definition kutil.cc:130
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6412
int getIndexRng(long coeff)
Definition kutil.cc:6000
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6058
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:9749
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:6646
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9343
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5844
int posInT11(const TSet set, const int length, LObject &p)
Definition kutil.cc:4953
int posInT1(const TSet set, const int length, LObject &p)
Definition kutil.cc:4896
void enterSBba(LObject *p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8792
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:7463
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition kutil.cc:6621
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:7025
void enterT_strong(LObject *p, kStrategy strat, int atT)
Definition kutil.cc:9242
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:6697
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:10497
void initenterstrongPairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:12743
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:11790
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:6562
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:12034
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
void enterSBbaShift(LObject *p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8892
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:6145
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6099
#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:12044
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11449
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:9567
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:7140
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.cc:6513
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:12105
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:8512
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:9580
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:7586
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition kutil.cc:10939
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:6912
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7269
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition kutil.cc:11064
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:8088
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:8488
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition kutil.cc:8402
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:12485
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:6180
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:12980
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11358
int posInT15(const TSet set, const int length, LObject &p)
Definition kutil.cc:5184
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition kutil.cc:10682
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.cc:6478
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
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:12927
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:9837
void messageStatSBA(int hilbcount, kStrategy strat)
Definition kutil.cc:7517
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:8557
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7781
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5912
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:6255
void initSyzRules(kStrategy strat)
Definition kutil.cc:7933
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:9936
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition kutil.cc:10459
void enterT(LObject *p, kStrategy strat, int atT)
Definition kutil.cc:9143
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 reorderS(int *suc, kStrategy strat)
Definition kutil.cc:4610
void enterTShift(LObject *p, kStrategy strat, int atT)
Definition kutil.cc:12957
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:6215
#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:10051
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:7350
#define pDivComp_GREATER
Definition kutil.cc:131
void exitSba(kStrategy strat)
Definition kutil.cc:10011
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:12143
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition kutil.cc:11478
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition kutil.cc:1208
void kStratInitChangeTailRing(kStrategy strat)
Definition kutil.cc:11036
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition kutil.cc:3520
void initBuchMoraCrit(kStrategy strat)
Definition kutil.cc:9435
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:10257
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6348
void initBuchMoraPosRing(kStrategy strat)
Definition kutil.cc:9664
void enterSSba(LObject *p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8915
int kFindInTShift(poly p, TSet T, int tlength)
Definition kutil.cc:728
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition kutil.cc:10758
static BOOLEAN enterOneStrongPolyShift(poly q, poly p, int, int, kStrategy strat, int atR, int, int, int shiftcount, int ifromS)
Definition kutil.cc:11621
void messageSets(kStrategy strat)
Definition kutil.cc:7536
void deleteInS(int i, kStrategy strat)
Definition kutil.cc:1132
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8385
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11412
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:5878
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:10518
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
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5802
char * showOption()
Definition misc_ip.cc:713
poly redtailBba_Ring(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7375
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition kutil.cc:1308
void messageStat(int hilbcount, kStrategy strat)
Definition kutil.cc:7504
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:8236
void initSL(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7679
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:10847
void initSbaCrit(kStrategy strat)
Definition kutil.cc:9498
BOOLEAN newHEdge(kStrategy strat)
Definition kutil.cc:10379
#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:9417
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:417
LObject * LSet
Definition kutil.h:61
denominator_list next
Definition kutil.h:66
static void kDeleteLcm(LObject *P)
Definition kutil.h:876
int * intset
Definition kutil.h:54
#define ALLOW_PROD_CRIT(A)
Definition kutil.h:392
#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:3002
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:3774
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:4693
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:4947
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:2893
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:3821
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:774
static BOOLEAN rHasGlobalOrdering(const ring r)
Definition ring.h:773
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:579
static int rGetCurrSyzLimit(const ring r)
Definition ring.h:734
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:731
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:603
static BOOLEAN rHasMixedOrdering(const ring r)
Definition ring.h:775
#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