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 KDEBUG
75#undef KDEBUG
76#define KDEBUG 2
77#endif
78
79#ifdef DEBUGF5
80#undef DEBUGF5
81#define DEBUGF5 2
82#endif
83
85
86
87#ifdef ENTER_USE_MYMEMMOVE
88inline void _my_memmove_d_gt_s(unsigned long* d, unsigned long* s, long l)
89{
90 REGISTER unsigned long* _dl = (unsigned long*) d;
91 REGISTER unsigned long* _sl = (unsigned long*) s;
92 REGISTER long _i = l - 1;
93
94 do
95 {
96 _dl[_i] = _sl[_i];
97 _i--;
98 }
99 while (_i >= 0);
100}
101
102inline void _my_memmove_d_lt_s(unsigned long* d, unsigned long* s, long l)
103{
104 REGISTER long _ll = l;
105 REGISTER unsigned long* _dl = (unsigned long*) d;
106 REGISTER unsigned long* _sl = (unsigned long*) s;
107 REGISTER long _i = 0;
108
109 do
110 {
111 _dl[_i] = _sl[_i];
112 _i++;
113 }
114 while (_i < _ll);
115}
116
117inline void _my_memmove(void* d, void* s, long l)
118{
119 unsigned long _d = (unsigned long) d;
120 unsigned long _s = (unsigned long) s;
121 unsigned long _l = ((l) + SIZEOF_LONG - 1) >> LOG_SIZEOF_LONG;
122
123 if (_d > _s) _my_memmove_d_gt_s(_d, _s, _l);
124 else _my_memmove_d_lt_s(_d, _s, _l);
125}
126
127#undef memmove
128#define memmove(d,s,l) _my_memmove(d, s, l)
129#endif
130
131static poly redMora (poly h,int maxIndex,kStrategy strat);
132static poly redBba (poly h,int maxIndex,kStrategy strat);
133
134#ifdef HAVE_RINGS
135#define pDivComp_EQUAL 2
136#define pDivComp_LESS 1
137#define pDivComp_GREATER -1
138#define pDivComp_INCOMP 0
139/* Checks the relation of LM(p) and LM(q)
140 LM(p) = LM(q) => return pDivComp_EQUAL
141 LM(p) | LM(q) => return pDivComp_LESS
142 LM(q) | LM(p) => return pDivComp_GREATER
143 else return pDivComp_INCOMP */
144static inline int pDivCompRing(poly p, poly q)
145{
146 if ((currRing->pCompIndex < 0)
148 {
149 BOOLEAN a=FALSE, b=FALSE;
150 int i;
151 unsigned long la, lb;
152 unsigned long divmask = currRing->divmask;
153 for (i=0; i<currRing->VarL_Size; i++)
154 {
155 la = p->exp[currRing->VarL_Offset[i]];
156 lb = q->exp[currRing->VarL_Offset[i]];
157 if (la != lb)
158 {
159 if (la < lb)
160 {
161 if (b) return pDivComp_INCOMP;
162 if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
163 return pDivComp_INCOMP;
164 a = TRUE;
165 }
166 else
167 {
168 if (a) return pDivComp_INCOMP;
169 if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
170 return pDivComp_INCOMP;
171 b = TRUE;
172 }
173 }
174 }
175 if (a) return pDivComp_LESS;
176 if (b) return pDivComp_GREATER;
177 if (!a & !b) return pDivComp_EQUAL;
178 }
179 return pDivComp_INCOMP;
180}
181#endif
182
183static inline int pDivComp(poly p, poly q)
184{
185 if ((currRing->pCompIndex < 0)
187 {
188#ifdef HAVE_RATGRING
190 {
192 q,currRing,
193 currRing->real_var_start, currRing->real_var_end))
194 return 0;
195 return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
196 }
197#endif
198 BOOLEAN a=FALSE, b=FALSE;
199 int i;
200 unsigned long la, lb;
201 unsigned long divmask = currRing->divmask;
202 for (i=0; i<currRing->VarL_Size; i++)
203 {
204 la = p->exp[currRing->VarL_Offset[i]];
205 lb = q->exp[currRing->VarL_Offset[i]];
206 if (la != lb)
207 {
208 if (la < lb)
209 {
210 if (b) return 0;
211 if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
212 return 0;
213 a = TRUE;
214 }
215 else
216 {
217 if (a) return 0;
218 if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
219 return 0;
220 b = TRUE;
221 }
222 }
223 }
224 if (a) { /*assume(pLmCmp(q,p)==1);*/ return 1; }
225 if (b) { /*assume(pLmCmp(q,p)==-1);*/return -1; }
226 /*assume(pLmCmp(q,p)==0);*/
227 }
228 return 0;
229}
230
231#ifdef HAVE_SHIFTBBA
232static inline int pLPDivComp(poly p, poly q)
233{
234 if ((currRing->pCompIndex < 0) || (__p_GetComp(p,currRing) == __p_GetComp(q,currRing)))
235 {
236 // maybe there is a more performant way to do this? This will get called quite often in bba.
237 if (_p_LPLmDivisibleByNoComp(p, q, currRing)) return 1;
238 if (_p_LPLmDivisibleByNoComp(q, p, currRing)) return -1;
239 }
240
241 return 0;
242}
243#endif
244
245
249
250static void deleteHCBucket(LObject *L, kStrategy strat)
251{
252 if ((strat->kNoether!=NULL)
253 && (L->bucket != NULL))
254 {
255 for (int i=1; i<= (int) L->bucket->buckets_used; i++)
256 {
257 poly p=L->bucket->buckets[i];
258 if(p!=NULL)
259 {
260 if (p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
261 {
262 L->bucket->buckets[i]=NULL;
263 L->bucket->buckets_length[i]=0;
264 }
265 else
266 {
267 do
268 {
269 if (p_Cmp(pNext(p),strat->kNoetherTail(), L->tailRing) == -1)
270 {
271 p_Delete(&pNext(p), L->tailRing);
272 L->bucket->buckets_length[i]=pLength(L->bucket->buckets[i]);
273 break;
274 }
275 pIter(p);
276 } while(p!=NULL);
277 }
278 }
279 }
280 int i=L->bucket->buckets_used;
281 while ((i>0)&&(L->bucket->buckets[i]==NULL))
282 {
283 i--;
284 L->bucket->buckets_used=i;
285 }
286 }
287}
288
289/*2
290*deletes higher monomial of p, re-compute ecart and length
291*works only for orderings with ecart =pFDeg(end)-pFDeg(start)
292*/
294{
295 if (strat->kNoether!=NULL)
296 {
297 kTest_L(L,strat);
298 poly p1;
299 poly p = L->GetLmTailRing();
300 int l = 1;
301
302 if (!fromNext && p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
303 {
304 if (L->bucket != NULL) kBucketDestroy(&L->bucket);
305 L->Delete();
306 L->Clear();
307 L->ecart = -1;
308 return;
309 }
310 if (L->bucket != NULL)
311 {
312 deleteHCBucket(L,strat);
313 return;
314 }
316 p1 = p;
317 while (pNext(p1)!=NULL)
318 {
319 if (p_LmCmp(pNext(p1), strat->kNoetherTail(), L->tailRing) == -1)
320 {
321 cut=(pNext(p1)!=NULL);
322 if (cut)
323 {
324 p_Delete(&pNext(p1), L->tailRing);
325
326 if (p1 == p)
327 {
328 if (L->t_p != NULL)
329 {
330 assume(L->p != NULL && p == L->t_p);
331 pNext(L->p) = NULL;
332 }
333 L->max_exp = NULL;
334 }
335 else if (fromNext)
336 L->max_exp = p_GetMaxExpP(pNext(L->p), L->tailRing ); // p1;
337 //if (L->pLength != 0)
338 L->pLength = l;
339 // Hmmm when called from updateT, then only
340 // reset ecart when cut
341 if (fromNext)
342 L->ecart = L->pLDeg() - L->GetpFDeg();
343 }
344 break;
345 }
346 l++;
347 pIter(p1);
348 }
349 if ((!fromNext) && cut)
350 {
351 L->SetpFDeg();
352 L->ecart = L->pLDeg(strat->LDegLast) - L->GetpFDeg();
353 }
354 kTest_L(L,strat);
355 }
356}
357
358void deleteHC(poly* p, int* e, int* l,kStrategy strat)
359{
360 LObject L(*p, currRing, strat->tailRing);
361
362 deleteHC(&L, strat);
363 *p = L.p;
364 *e = L.ecart;
365 *l = L.length;
366 if (L.t_p != NULL) p_LmFree(L.t_p, strat->tailRing);
367}
368
369/*2
370*tests if p.p=monomial*unit and cancels the unit
371*/
373{
374 if(rHasGlobalOrdering (currRing)) return;
375 if(TEST_OPT_CANCELUNIT) return;
376
377 ring r = L->tailRing;
378 poly p = L->GetLmTailRing();
379 if(p_GetComp(p, r) != 0 && !p_OneComp(p, r)) return;
380
381 number lc=NULL; /*dummy, is always set if rField_is_Ring(r) */
382 if (rField_is_Ring(r) /*&& (rHasLocalOrMixedOrdering(r))*/)
383 lc = pGetCoeff(p);
384
385 // Leading coef have to be a unit
386 // example 2x+4x2 should be simplified to 2x*(1+2x)
387 // and 2 is not a unit in Z
388 //if ( !(n_IsUnit(pGetCoeff(p), r->cf)) ) return;
389
390 poly h = pNext(p);
391 int i;
392
394 {
395 loop
396 {
397 if (h==NULL)
398 {
399 p_Delete(&pNext(p), r);
400 if (!inNF)
401 {
403 if (L->p != NULL)
404 {
405 pSetCoeff(L->p,eins);
406 if (L->t_p != NULL)
407 pSetCoeff0(L->t_p,eins);
408 }
409 else
410 pSetCoeff(L->t_p,eins);
411 /* p and t_p share the same coeff, if both are !=NULL */
412 /* p==NULL==t_p cannot happen here */
413 }
414 L->ecart = 0;
415 L->length = 1;
416 //if (L->pLength > 0)
417 L->pLength = 1;
418 L->max_exp = NULL;
419
420 if (L->t_p != NULL && pNext(L->t_p) != NULL)
421 p_Delete(&pNext(L->t_p),r);
422 if (L->p != NULL && pNext(L->p) != NULL)
423 pNext(L->p) = NULL;
424 return;
425 }
426 i = rVar(r);
427 loop
428 {
429 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
430 i--;
431 if (i == 0) break; // does divide, try next monom
432 }
433 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
434 // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
435 // domains), no zerodivisor test needed CAUTION
436 if (!n_DivBy(pGetCoeff(h),lc,r->cf))
437 {
438 return;
439 }
440 pIter(h);
441 }
442 }
443 else
444 {
445 loop
446 {
447 if (h==NULL)
448 {
449 p_Delete(&pNext(p), r);
450 if (!inNF)
451 {
452 number eins=nInit(1);
453 if (L->p != NULL)
454 {
455 pSetCoeff(L->p,eins);
456 if (L->t_p != NULL)
457 pSetCoeff0(L->t_p,eins);
458 }
459 else
460 pSetCoeff(L->t_p,eins);
461 /* p and t_p share the same coeff, if both are !=NULL */
462 /* p==NULL==t_p cannot happen here */
463 }
464 L->ecart = 0;
465 L->length = 1;
466 //if (L->pLength > 0)
467 L->pLength = 1;
468 L->max_exp = NULL;
469
470 if (L->t_p != NULL && pNext(L->t_p) != NULL)
471 p_Delete(&pNext(L->t_p),r);
472 if (L->p != NULL && pNext(L->p) != NULL)
473 pNext(L->p) = NULL;
474
475 return;
476 }
477 i = rVar(r);
478 loop
479 {
480 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
481 i--;
482 if (i == 0) break; // does divide, try next monom
483 }
484 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
485 pIter(h);
486 }
487 }
488}
489
490/*2
491*pp is the new element in s
492*returns TRUE (in strat->kAllAxis) if
493*-HEcke is allowed
494*-we are in the last componente of the vector
495*-on all axis are monomials (all elements in NotUsedAxis are FALSE)
496*returns FALSE for pLexOrderings,
497*assumes in module case an ordering of type c* !!
498* HEckeTest is only called with strat->kAllAxis==FALSE !
499*/
500void HEckeTest (poly pp,kStrategy strat)
501{
502 int j,/*k,*/p;
503
504 if (currRing->pLexOrder
506 || (strat->ak >1)
508 {
509 return;
510 }
512 if (p!=0)
513 strat->NotUsedAxis[p] = FALSE;
514 /*- the leading term of pp is a power of the p-th variable -*/
515 for (j=(currRing->N);j>0; j--)
516 {
517 if (strat->NotUsedAxis[j])
518 {
519 strat->kAllAxis=FALSE;
520 return;
521 }
522 }
523 strat->kAllAxis=TRUE;
524}
525
526/*2
527*utilities for TSet, LSet
528*/
529inline static intset initec (const int maxnr)
530{
531 return (intset)omAlloc(maxnr*sizeof(int));
532}
533
534inline static unsigned long* initsevS (const int maxnr)
535{
536 return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
537}
538inline static int* initS_2_R (const int maxnr)
539{
540 return (int*)omAlloc0(maxnr*sizeof(int));
541}
542
543static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
544 int &length, const int incr)
545{
546 assume(T!=NULL);
547 assume(sevT!=NULL);
548 assume(R!=NULL);
549 assume((length+incr) > 0);
550
551 int i;
552 T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
553 (length+incr)*sizeof(TObject));
554
555 sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
556 (length+incr)*sizeof(long*));
557
558 R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
559 (length+incr)*sizeof(TObject*));
560 for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
561 length += incr;
562}
563
564void cleanT (kStrategy strat)
565{
566 int i,j;
567 poly p;
568 assume(currRing == strat->tailRing || strat->tailRing != NULL);
569
570 pShallowCopyDeleteProc p_shallow_copy_delete =
571 (strat->tailRing != currRing ?
573 NULL);
574 for (j=0; j<=strat->tl; j++)
575 {
576 p = strat->T[j].p;
577 strat->T[j].p=NULL;
578 if (strat->T[j].max_exp != NULL)
579 {
580 p_LmFree(strat->T[j].max_exp, strat->tailRing);
581 }
582 i = -1;
583 loop
584 {
585 i++;
586 if (i>strat->sl)
587 {
588 if (strat->T[j].t_p != NULL)
589 {
590 p_Delete(&(strat->T[j].t_p), strat->tailRing);
592 }
593 else
594 {
595#ifdef HAVE_SHIFTBBA
596 if (currRing->isLPring && strat->T[j].shift > 0)
597 {
598 pNext(p) = NULL; // pNext(p) points to the unshifted tail, don't try to delete it here
599 }
600#endif
601 pDelete(&p);
602 }
603 break;
604 }
605 if (p == strat->S[i])
606 {
607 if (strat->T[j].t_p != NULL)
608 {
609 if (p_shallow_copy_delete!=NULL)
610 {
611 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
612 currRing->PolyBin);
613 }
614 p_LmFree(strat->T[j].t_p, strat->tailRing);
615 }
616 break;
617 }
618 }
619 }
620 strat->tl=-1;
621}
622
624{
625 int i,j;
626 poly p;
627 assume(currRing == strat->tailRing || strat->tailRing != NULL);
628
629 pShallowCopyDeleteProc p_shallow_copy_delete =
630 (strat->tailRing != currRing ?
632 NULL);
633 for (j=0; j<=strat->tl; j++)
634 {
635 p = strat->T[j].p;
636 strat->T[j].p=NULL;
637 if (strat->T[j].max_exp != NULL)
638 {
639 p_LmFree(strat->T[j].max_exp, strat->tailRing);
640 }
641 i = -1;
642 loop
643 {
644 i++;
645 if (i>strat->sl)
646 {
647 if (strat->T[j].t_p != NULL)
648 {
649 p_Delete(&(strat->T[j].t_p), strat->tailRing);
651 }
652 else
653 {
654 //pDelete(&p);
655 p = NULL;
656 }
657 break;
658 }
659 if (p == strat->S[i])
660 {
661 if (strat->T[j].t_p != NULL)
662 {
663 assume(p_shallow_copy_delete != NULL);
664 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
665 currRing->PolyBin);
666 p_LmFree(strat->T[j].t_p, strat->tailRing);
667 }
668 break;
669 }
670 }
671 }
672 strat->tl=-1;
673}
674
675//LSet initL ()
676//{
677// int i;
678// LSet l = (LSet)omAlloc(setmaxL*sizeof(LObject));
679// return l;
680//}
681
682static inline void enlargeL (LSet* L,int* length,const int incr)
683{
684 assume((*L)!=NULL);
685 assume(((*length)+incr)>0);
686
687 *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
688 ((*length)+incr)*sizeof(LObject));
689 (*length) += incr;
690}
691
693{
694 strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
695}
696
697/*2
698*test whether (p1,p2) or (p2,p1) is in L up position length
699*it returns TRUE if yes and the position k
700*/
701BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
702{
703 LObject *p=&(strat->L[length]);
704
705 *k = length;
706 loop
707 {
708 if ((*k) < 0) return FALSE;
709 if (((p1 == (*p).p1) && (p2 == (*p).p2))
710 || ((p1 == (*p).p2) && (p2 == (*p).p1)))
711 return TRUE;
712 (*k)--;
713 p--;
714 }
715}
716
717int kFindInT(poly p, TSet T, int tlength)
718{
719 int i;
720
721 for (i=0; i<=tlength; i++)
722 {
723 if (T[i].p == p) return i;
724 }
725 return -1;
726}
727
728int kFindInT(poly p, kStrategy strat)
729{
730 int i;
731 do
732 {
733 i = kFindInT(p, strat->T, strat->tl);
734 if (i >= 0) return i;
735 strat = strat->next;
736 }
737 while (strat != NULL);
738 return -1;
739}
740
741#ifdef HAVE_SHIFTBBA
742int kFindInTShift(poly p, TSet T, int tlength)
743{
744 int i;
745
746 for (i=0; i<=tlength; i++)
747 {
748 // in the Letterplace ring the LMs in T and L are copies thus we have to use pEqualPolys() instead of ==
749 if (pEqualPolys(T[i].p, p)) return i;
750 }
751 return -1;
752}
753#endif
754
755#ifdef HAVE_SHIFTBBA
756int kFindInTShift(poly p, kStrategy strat)
757{
758 int i;
759 do
760 {
761 i = kFindInTShift(p, strat->T, strat->tl);
762 if (i >= 0) return i;
763 strat = strat->next;
764 }
765 while (strat != NULL);
766 return -1;
767}
768#endif
769
770#ifdef KDEBUG
771
773{
774 if (t_p != NULL) p_wrp(t_p, tailRing);
775 else if (p != NULL) p_wrp(p, currRing, tailRing);
776 else ::wrp(NULL);
777}
778
779#define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
780
781// check that Lm's of a poly from T are "equal"
782static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
783{
784 int i;
785 for (i=1; i<=tailRing->N; i++)
786 {
787 if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
788 return "Lm[i] different";
789 }
790 if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
791 return "Lm[0] different";
792 if (pNext(p) != pNext(t_p))
793 return "Lm.next different";
794 if (pGetCoeff(p) != pGetCoeff(t_p))
795 return "Lm.coeff different";
796 return NULL;
797}
798
800BOOLEAN kTest_T(TObject * T, kStrategy strat, int i, char TN)
801{
802 ring tailRing = T->tailRing;
804 if (strat_tailRing == NULL) strat_tailRing = tailRing;
805 r_assume(strat_tailRing == tailRing);
806
807 poly p = T->p;
808 // ring r = currRing;
809
810 if (T->p == NULL && T->t_p == NULL && i >= 0)
811 return dReportError("%c[%d].poly is NULL", TN, i);
812
813 if (T->p!=NULL)
814 {
815 nTest(pGetCoeff(T->p));
816 if ((T->t_p==NULL)&&(pNext(T->p)!=NULL)) p_Test(pNext(T->p),currRing);
817 }
818 if (T->t_p!=NULL)
819 {
820 nTest(pGetCoeff(T->t_p));
821 if (pNext(T->t_p)!=NULL) p_Test(pNext(T->t_p),strat_tailRing);
822 }
823 if ((T->p!=NULL)&&(T->t_p!=NULL)) assume(pGetCoeff(T->p)==pGetCoeff(T->t_p));
824
825 if (T->tailRing != currRing)
826 {
827 if (T->t_p == NULL && i > 0)
828 return dReportError("%c[%d].t_p is NULL", TN, i);
829 pFalseReturn(p_Test(T->t_p, T->tailRing));
830 if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
831 if ((T->p != NULL) && (T->t_p != NULL))
832 {
833 const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
834 if (msg != NULL)
835 return dReportError("%c[%d] %s", TN, i, msg);
836 // r = T->tailRing;
837 p = T->t_p;
838 }
839 if (T->p == NULL)
840 {
841 p = T->t_p;
842 // r = T->tailRing;
843 }
844 if (T->t_p != NULL && i >= 0 && TN == 'T')
845 {
846 if (pNext(T->t_p) == NULL)
847 {
848 if (T->max_exp != NULL)
849 return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
850 }
851 else
852 {
853 if (T->max_exp == NULL)
854 return dReportError("%c[%d].max_exp is NULL", TN, i);
855 if (pNext(T->max_exp) != NULL)
856 return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
857
858 pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
859 omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
860#if KDEBUG > 0
861 if (! sloppy_max)
862 {
863 poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
864 p_Setm(T->max_exp, tailRing);
865 p_Setm(test_max, tailRing);
866 BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
867 if (! equal)
868 return dReportError("%c[%d].max out of sync", TN, i);
869 p_LmFree(test_max, tailRing);
870 }
871#endif
872 }
873 }
874 }
875 else
876 {
877 if (T->p == NULL && i > 0)
878 return dReportError("%c[%d].p is NULL", TN, i);
879#ifdef HAVE_SHIFTBBA
880 if (currRing->isLPring && T->shift > 0)
881 {
882 // in this case, the order is not correct. test LM and tail separately
885 }
886 else
887#endif
888 {
890 }
891 }
892
893 if ((i >= 0) && (T->pLength != 0)
894 && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
895 {
896 int l=T->pLength;
897 T->pLength=pLength(p);
898 return dReportError("%c[%d] pLength error: has %d, specified to have %d",
899 TN, i , pLength(p), l);
900 }
901
902 // check FDeg, for elements in L and T
903 if (i >= 0 && (TN == 'T' || TN == 'L'))
904 {
905 // FDeg has ir element from T of L set
906 if (strat->homog && (T->FDeg != T->pFDeg()))
907 {
908 int d=T->FDeg;
909 T->FDeg=T->pFDeg();
910 return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
911 TN, i , T->pFDeg(), d);
912 }
913 }
914
915 // check is_normalized for elements in T
916 if (i >= 0 && TN == 'T')
917 {
918 if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
919 return dReportError("T[%d] is_normalized error", i);
920
921 }
922 return TRUE;
923}
924
926 BOOLEAN testp, int lpos, TSet T, int tlength)
927{
929 if (L->p!=NULL)
930 {
931 if ((L->t_p==NULL)
932 &&(pNext(L->p)!=NULL)
933 &&(pGetCoeff(pNext(L->p))!=NULL)) /* !=strat->tail*/
934 {
935 p_Test(pNext(L->p),currRing);
936 nTest(pGetCoeff(L->p));
937 }
938 }
939 if (L->t_p!=NULL)
940 {
941 if ((pNext(L->t_p)!=NULL)
942 &&(pGetCoeff(pNext(L->t_p))!=NULL)) /* !=strat->tail*/
943 {
944 p_Test(pNext(L->t_p),strat_tailRing);
945 nTest(pGetCoeff(L->t_p));
946 }
947 }
948 if ((L->p!=NULL)&&(L->t_p!=NULL)) assume(pGetCoeff(L->p)==pGetCoeff(L->t_p));
949
950 if (testp)
951 {
952 poly pn = NULL;
953 if (L->bucket != NULL)
954 {
955 kFalseReturn(kbTest(L->bucket));
956 r_assume(L->bucket->bucket_ring == L->tailRing);
957 if (L->p != NULL && pNext(L->p) != NULL)
958 {
959 pn = pNext(L->p);
960 pNext(L->p) = NULL;
961 }
962 }
963 kFalseReturn(kTest_T(L, strat, lpos, 'L'));
964 if (pn != NULL)
965 pNext(L->p) = pn;
966
967 ring r;
968 poly p;
969 L->GetLm(p, r);
970 if (L->sev != 0L)
971 {
972 if (p_GetShortExpVector(p, r) != L->sev)
973 {
974 return dReportError("L[%d] wrong sev: has %lo, specified to have %lo",
975 lpos, p_GetShortExpVector(p, r), L->sev);
976 }
977 }
978 }
979 if (L->p1 == NULL)
980 {
981 // L->p2 either NULL or "normal" poly
982 pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
983 }
984 else if (tlength > 0 && T != NULL && (lpos >=0))
985 {
986 // now p1 and p2 must be != NULL and must be contained in T
987 int i;
988#ifdef HAVE_SHIFTBBA
989 if (rIsLPRing(currRing))
990 i = kFindInTShift(L->p1, T, tlength);
991 else
992#endif
993 i = kFindInT(L->p1, T, tlength);
994 if (i < 0)
995 return dReportError("L[%d].p1 not in T",lpos);
996#ifdef HAVE_SHIFTBBA
997 if (rIsLPRing(currRing))
998 {
999 if (rField_is_Ring(currRing)) return TRUE; // m*shift(q) is not in T
1000 i = kFindInTShift(L->p2, T, tlength);
1001 }
1002 else
1003#endif
1004 i = kFindInT(L->p2, T, tlength);
1005 if (i < 0)
1006 return dReportError("L[%d].p2 not in T",lpos);
1007 }
1008 return TRUE;
1009}
1010
1012{
1013 int i;
1014 // test P
1015 kFalseReturn(kTest_L(&(strat->P), strat,
1016 (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
1017 -1, strat->T, strat->tl));
1018
1019 // test T
1020 if (strat->T != NULL)
1021 {
1022 for (i=0; i<=strat->tl; i++)
1023 {
1024 kFalseReturn(kTest_T(&(strat->T[i]), strat, i, 'T'));
1025 if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
1026 return dReportError("strat->sevT[%d] out of sync", i);
1027 }
1028 }
1029
1030 // test L
1031 if (strat->L != NULL)
1032 {
1033 for (i=0; i<=strat->Ll; i++)
1034 {
1035 kFalseReturn(kTest_L(&(strat->L[i]), strat,
1036 strat->L[i].Next() != strat->tail, i,
1037 strat->T, strat->tl));
1038 // may be unused
1039 //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
1040 // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
1041 //{
1042 // assume(strat->L[i].bucket != NULL);
1043 //}
1044 }
1045 }
1046
1047 // test S
1048 if (strat->S != NULL)
1049 kFalseReturn(kTest_S(strat));
1050
1051 return TRUE;
1052}
1053
1055{
1056 int i;
1057 BOOLEAN ret = TRUE;
1058 for (i=0; i<=strat->sl; i++)
1059 {
1060 if (strat->S[i] != NULL &&
1061 strat->sevS[i] != pGetShortExpVector(strat->S[i]))
1062 {
1063 return dReportError("S[%d] wrong sev: has %o, specified to have %o",
1064 i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
1065 }
1066 }
1067 return ret;
1068}
1069
1070
1071
1073{
1074 int i, j;
1075 // BOOLEAN ret = TRUE;
1076 kFalseReturn(kTest(strat));
1077
1078 // test strat->R, strat->T[i].i_r
1079 for (i=0; i<=strat->tl; i++)
1080 {
1081 if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1082 return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1083 strat->T[i].i_r);
1084 if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1085 return dReportError("T[%d].i_r with R out of sync", i);
1086 }
1087 // test containment of S inT
1088 if ((strat->S != NULL)&&(strat->tl>=0))
1089 {
1090 for (i=0; i<=strat->sl; i++)
1091 {
1092 j = kFindInT(strat->S[i], strat->T, strat->tl);
1093 if (j < 0)
1094 return dReportError("S[%d] not in T", i);
1095 if (strat->S_2_R[i] != strat->T[j].i_r)
1096 return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1097 i, strat->S_2_R[i], j, strat->T[j].i_r);
1098 }
1099 }
1100 // test strat->L[i].i_r1
1101 #ifdef HAVE_SHIFTBBA
1102 if (!rIsLPRing(currRing)) // in the Letterplace ring we currently don't set/use i_r1 and i_r2
1103 #endif
1104 if (strat->L!=NULL)
1105 {
1106 for (i=0; i<=strat->Ll; i++)
1107 {
1108 if (strat->L[i].p1 != NULL && strat->L[i].p2)
1109 {
1110 if (strat->L[i].i_r1 < 0 ||
1111 strat->L[i].i_r1 > strat->tl ||
1112 strat->L[i].T_1(strat)->p != strat->L[i].p1)
1113 return dReportError("L[%d].i_r1 out of sync", i);
1114 if (strat->L[i].i_r2 < 0 ||
1115 strat->L[i].i_r2 > strat->tl ||
1116 strat->L[i].T_2(strat)->p != strat->L[i].p2)
1117 return dReportError("L[%d].i_r2 out of sync", i);
1118 }
1119 else
1120 {
1121 if (strat->L[i].i_r1 != -1)
1122 return dReportError("L[%d].i_r1 out of sync", i);
1123 if (strat->L[i].i_r2 != -1)
1124 return dReportError("L[%d].i_r2 out of sync", i);
1125 }
1126 if (strat->L[i].i_r != -1)
1127 return dReportError("L[%d].i_r out of sync", i);
1128 }
1129 }
1130 return TRUE;
1131}
1132
1133#endif // KDEBUG
1134
1135/*2
1136*cancels the i-th polynomial in the standardbase s
1137*/
1138void deleteInS (int i,kStrategy strat)
1139{
1140#ifdef ENTER_USE_MEMMOVE
1141 memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1142 memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1143 memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1144 memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1145#else
1146 int j;
1147 for (j=i; j<strat->sl; j++)
1148 {
1149 strat->S[j] = strat->S[j+1];
1150 strat->ecartS[j] = strat->ecartS[j+1];
1151 strat->sevS[j] = strat->sevS[j+1];
1152 strat->S_2_R[j] = strat->S_2_R[j+1];
1153 }
1154#endif
1155 if (strat->lenS!=NULL)
1156 {
1157#ifdef ENTER_USE_MEMMOVE
1158 memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1159#else
1160 for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1161#endif
1162 }
1163 if (strat->lenSw!=NULL)
1164 {
1165#ifdef ENTER_USE_MEMMOVE
1166 memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1167#else
1168 for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1169#endif
1170 }
1171 if (strat->fromQ!=NULL)
1172 {
1173#ifdef ENTER_USE_MEMMOVE
1174 memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1175#else
1176 for (j=i; j<strat->sl; j++)
1177 {
1178 strat->fromQ[j] = strat->fromQ[j+1];
1179 }
1180#endif
1181 }
1182 strat->S[strat->sl] = NULL;
1183 strat->sl--;
1184}
1185
1186#ifdef HAVE_SHIFTBBA
1187static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
1188{
1189 if (rIsLPRing(currRing)
1190 && (strat->P.p1!=NULL))
1191 {
1192 // clean up strat->P.p1: may be shifted
1193 poly p=strat->P.p1;
1194 int lv=currRing->isLPring;
1196 for (int i=lv;i>0;i--)
1197 {
1198 if (pGetExp(p,i)!=0) { is_shifted=FALSE; break;}
1199 }
1200 if (is_shifted
1201 && (kFindInL1(p, strat)<0)
1202 && (kFindInT(p, strat->T, strat->tl) < 0)
1203 )
1204 {
1205 return TRUE;
1206 }
1207 }
1208 return FALSE;
1209}
1210#endif
1211/*2
1212*cancels the j-th polynomial in the set
1213*/
1214void deleteInL (LSet set, int *length, int j,kStrategy strat)
1215{
1216 if (set[j].lcm!=NULL)
1217 {
1218 kDeleteLcm(&set[j]);
1219 }
1220 if (set[j].sig!=NULL)
1221 {
1222#ifdef HAVE_RINGS
1223 if (pGetCoeff(set[j].sig) != NULL)
1224 pLmDelete(set[j].sig);
1225 else
1226#endif
1227 pLmFree(set[j].sig);
1228 }
1229 if (set[j].p!=NULL)
1230 {
1231 if (pNext(set[j].p) == strat->tail)
1232 {
1233#ifdef HAVE_RINGS
1234 if (pGetCoeff(set[j].p) != NULL)
1235 pLmDelete(set[j].p);
1236 else
1237#endif
1238 pLmFree(set[j].p);
1239 /*- tail belongs to several int spolys -*/
1240 }
1241 else
1242 {
1243 // search p in T, if it is there, do not delete it
1244 if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1245 {
1246 // assure that for global orderings kFindInT fails
1247 //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1248 set[j].Delete();
1249 }
1250 }
1251 }
1252 #ifdef HAVE_SHIFTBBA
1253 if (is_shifted_p1(strat->P.p1,strat))
1254 {
1255 // clean up strat->P.p1: may be shifted
1256 pLmDelete(strat->P.p1);
1257 strat->P.p1=NULL;
1258 }
1259 #endif
1260 if (*length > 0 && j < *length)
1261 {
1262#ifdef ENTER_USE_MEMMOVE
1263 memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1264#else
1265 int i;
1266 for (i=j; i < (*length); i++)
1267 set[i] = set[i+1];
1268#endif
1269 }
1270#ifdef KDEBUG
1271 set[*length].Init();
1272#endif
1273 (*length)--;
1274}
1275
1276/*2
1277*enters p at position at in L
1278*/
1279void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1280{
1281 // this should be corrected
1282 assume(p.FDeg == p.pFDeg());
1283
1284 if ((*length)>=0)
1285 {
1286 if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1287 if (at <= (*length))
1288#ifdef ENTER_USE_MEMMOVE
1289 memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1290#else
1291 for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1292#endif
1293 }
1294 else at = 0;
1295 (*set)[at] = p;
1296 (*length)++;
1297}
1298
1299/*2
1300* computes the normal ecart;
1301* used in mora case and if pLexOrder & sugar in bba case
1302*/
1304{
1305 h->FDeg = h->pFDeg();
1306 h->ecart = h->pLDeg() - h->FDeg;
1307 // h->length is set by h->pLDeg
1308 h->length=h->pLength=pLength(h->p);
1309}
1310
1312{
1313 h->FDeg = h->pFDeg();
1314 (*h).ecart = 0;
1315 h->length=h->pLength=pLength(h->p);
1316}
1317
1318void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1319{
1320 Lp->FDeg = Lp->pFDeg();
1321 (*Lp).ecart = 0;
1322 (*Lp).length = 0;
1323}
1324
1325void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1326{
1327 Lp->FDeg = Lp->pFDeg();
1328 (*Lp).ecart = si_max(ecartF,ecartG);
1329 (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1330 (*Lp).length = 0;
1331}
1332
1333/*2
1334*if ecart1<=ecart2 it returns TRUE
1335*/
1336static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1337{
1338 return (ecart1 <= ecart2);
1339}
1340
1341#ifdef HAVE_RINGS
1342/*2
1343* put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1344*/
1345static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1346{
1347 assume(atR >= 0);
1348 assume(i<=strat->sl);
1349 assume(p!=NULL);
1351 #if ALL_VS_JUST
1352 //Over rings, if we construct the strong pair, do not add the spair
1354 {
1355 number s,t,d;
1356 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1357
1358 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1359 {
1360 nDelete(&d);
1361 nDelete(&s);
1362 nDelete(&t);
1363 return;
1364 }
1365 nDelete(&d);
1366 nDelete(&s);
1367 nDelete(&t);
1368 }
1369 #endif
1370 int j,compare,compareCoeff;
1371 LObject h;
1372
1373#ifdef KDEBUG
1374 h.ecart=0; h.length=0;
1375#endif
1376 /*- computes the lcm(s[i],p) -*/
1377 if(pHasNotCFRing(p,strat->S[i]))
1378 {
1379 strat->cp++;
1380 return;
1381 }
1382 h.lcm = p_Lcm(p,strat->S[i],currRing);
1383 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1384 if (nIsZero(pGetCoeff(h.lcm)))
1385 {
1386 strat->cp++;
1387 pLmDelete(h.lcm);
1388 return;
1389 }
1390 // basic chain criterion
1391 /*
1392 *the set B collects the pairs of type (S[j],p)
1393 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1394 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
1395 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
1396 */
1397
1398 for(j = strat->Bl;j>=0;j--)
1399 {
1400 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1401 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1402 if(compare == pDivComp_EQUAL)
1403 {
1404 //They have the same LM
1406 {
1407 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1408 {
1409 strat->c3++;
1410 pLmDelete(h.lcm);
1411 return;
1412 }
1413 break;
1414 }
1416 {
1417 deleteInL(strat->B,&strat->Bl,j,strat);
1418 strat->c3++;
1419 }
1421 {
1422 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1423 {
1424 strat->c3++;
1425 pLmDelete(h.lcm);
1426 return;
1427 }
1428 break;
1429 }
1430 }
1431 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1432 {
1433 if(compare == pDivComp_LESS)
1434 {
1435 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1436 {
1437 strat->c3++;
1438 pLmDelete(h.lcm);
1439 return;
1440 }
1441 break;
1442 }
1443 if(compare == pDivComp_GREATER)
1444 {
1445 deleteInL(strat->B,&strat->Bl,j,strat);
1446 strat->c3++;
1447 }
1448 }
1449 }
1450 number s, t;
1451 poly m1, m2, gcd = NULL;
1452 s = pGetCoeff(strat->S[i]);
1453 t = pGetCoeff(p);
1454 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1455 ksCheckCoeff(&s, &t, currRing->cf);
1456 pSetCoeff0(m1, s);
1457 pSetCoeff0(m2, t);
1458 m2 = pNeg(m2);
1459 p_Test(m1,strat->tailRing);
1460 p_Test(m2,strat->tailRing);
1461 poly si = pCopy(strat->S[i]);
1462 poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1463 poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1464 pDelete(&si);
1465 p_LmDelete(m1, currRing);
1466 p_LmDelete(m2, currRing);
1467 if(sim2 == NULL)
1468 {
1469 if(pm1 == NULL)
1470 {
1471 if(h.lcm != NULL)
1472 {
1473 pLmDelete(h.lcm);
1474 h.lcm=NULL;
1475 }
1476 h.Clear();
1477 if (strat->pairtest==NULL) initPairtest(strat);
1478 strat->pairtest[i] = TRUE;
1479 strat->pairtest[strat->sl+1] = TRUE;
1480 return;
1481 }
1482 else
1483 {
1484 gcd = pm1;
1485 pm1 = NULL;
1486 }
1487 }
1488 else
1489 {
1490 if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1491 {
1492 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1493 pSetmComp(sim2);
1494 }
1495 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1496 gcd = p_Add_q(pm1, sim2, strat->tailRing);
1497 }
1498 p_Test(gcd, strat->tailRing);
1499#ifdef KDEBUG
1500 if (TEST_OPT_DEBUG)
1501 {
1502 wrp(gcd);
1503 PrintLn();
1504 }
1505#endif
1506 h.p = gcd;
1507 h.i_r = -1;
1508 if(h.p == NULL)
1509 {
1510 if (strat->pairtest==NULL) initPairtest(strat);
1511 strat->pairtest[i] = TRUE;
1512 strat->pairtest[strat->sl+1] = TRUE;
1513 return;
1514 }
1515 h.tailRing = strat->tailRing;
1516 int posx;
1517 //h.pCleardenom();
1518 //pSetm(h.p);
1519 h.i_r1 = -1;h.i_r2 = -1;
1520 strat->initEcart(&h);
1521 #if 1
1522 h.p2 = strat->S[i];
1523 h.p1 = p;
1524 #endif
1525 #if 1
1526 if (atR >= 0)
1527 {
1528 h.i_r1 = atR;
1529 h.i_r2 = strat->S_2_R[i];
1530 }
1531 #endif
1532 if (strat->Bl==-1)
1533 posx =0;
1534 else
1535 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1536 h.sev = pGetShortExpVector(h.p);
1537 if (currRing!=strat->tailRing)
1538 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1539 if (strat->P.p!=NULL) strat->P.sev = pGetShortExpVector(strat->P.p);
1540 else strat->P.sev=0L;
1541 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1542 kTest_TS(strat);
1543}
1544
1545/*2
1546* put the lcm(s[i],p) into the set B
1547*/
1548
1549static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1550{
1551 number d, s, t;
1552 assume(atR >= 0);
1554 poly m1, m2, gcd,si;
1555 if(!enterTstrong)
1556 {
1557 assume(i<=strat->sl);
1558 si = strat->S[i];
1559 }
1560 else
1561 {
1562 assume(i<=strat->tl);
1563 si = strat->T[i].p;
1564 }
1565 //printf("\n--------------------------------\n");
1566 //pWrite(p);pWrite(si);
1567 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1568
1569 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1570 {
1571 nDelete(&d);
1572 nDelete(&s);
1573 nDelete(&t);
1574 return FALSE;
1575 }
1576
1577 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1578
1580 {
1581 unsigned long sev = pGetShortExpVector(gcd);
1582
1583 for (int j = 0; j < strat->sl; j++)
1584 {
1585 if (j == i)
1586 continue;
1587
1588 if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf)
1589 && !(strat->sevS[j] & ~sev)
1590 && p_LmDivisibleBy(strat->S[j], gcd, currRing))
1591 {
1592 nDelete(&d);
1593 nDelete(&s);
1594 nDelete(&t);
1595 return FALSE;
1596 }
1597 }
1598 }
1599
1600 //p_Test(m1,strat->tailRing);
1601 //p_Test(m2,strat->tailRing);
1602 /*if(!enterTstrong)
1603 {
1604 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1605 {
1606 memset(&(strat->P), 0, sizeof(strat->P));
1607 kStratChangeTailRing(strat);
1608 strat->P = *(strat->R[atR]);
1609 p_LmFree(m1, strat->tailRing);
1610 p_LmFree(m2, strat->tailRing);
1611 p_LmFree(gcd, currRing);
1612 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1613 }
1614 }*/
1615 pSetCoeff0(m1, s);
1616 pSetCoeff0(m2, t);
1617 pSetCoeff0(gcd, d);
1618 p_Test(m1,strat->tailRing);
1619 p_Test(m2,strat->tailRing);
1620 //printf("\n===================================\n");
1621 //pWrite(m1);pWrite(m2);pWrite(gcd);
1622#ifdef KDEBUG
1623 if (TEST_OPT_DEBUG)
1624 {
1625 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1626 PrintS("m1 = ");
1627 p_wrp(m1, strat->tailRing);
1628 PrintS(" ; m2 = ");
1629 p_wrp(m2, strat->tailRing);
1630 PrintS(" ; gcd = ");
1631 wrp(gcd);
1632 PrintS("\n--- create strong gcd poly: ");
1633 Print("\n p: %d", i);
1634 wrp(p);
1635 Print("\n strat->S[%d]: ", i);
1636 wrp(si);
1637 PrintS(" ---> ");
1638 }
1639#endif
1640
1641 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1642 p_LmDelete(m1, strat->tailRing);
1643 p_LmDelete(m2, strat->tailRing);
1644#ifdef KDEBUG
1645 if (TEST_OPT_DEBUG)
1646 {
1647 wrp(gcd);
1648 PrintLn();
1649 }
1650#endif
1651
1652 LObject h;
1653 h.p = gcd;
1654 h.tailRing = strat->tailRing;
1655 int posx;
1656 strat->initEcart(&h);
1657 h.sev = pGetShortExpVector(h.p);
1658 h.i_r1 = -1;h.i_r2 = -1;
1659 if (currRing!=strat->tailRing)
1660 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1661 if(!enterTstrong)
1662 {
1663 #if 1
1664 h.p1 = p;h.p2 = strat->S[i];
1665 #endif
1666 if (atR >= 0)
1667 {
1668 h.i_r2 = strat->S_2_R[i];
1669 h.i_r1 = atR;
1670 }
1671 else
1672 {
1673 h.i_r1 = -1;
1674 h.i_r2 = -1;
1675 }
1676 if (strat->Ll==-1)
1677 posx =0;
1678 else
1679 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1680 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1681 }
1682 else
1683 {
1684 if(h.IsNull()) return FALSE;
1685 //int red_result;
1686 //reduzieren ist teur!!!
1687 //if(strat->L != NULL)
1688 //red_result = strat->red(&h,strat);
1689 if(!h.IsNull())
1690 {
1691 enterT(h, strat,-1);
1692 //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1693 //strat->enterS(h,pos,strat,-1);
1694 }
1695 }
1696 return TRUE;
1697}
1698
1700{
1701 if(strat->sl < 0) return FALSE;
1702 int i;
1703 for(i=0;i<strat->sl;i++)
1704 {
1705 //Construct the gcd pair between h and S[i]
1706 number d, s, t;
1707 poly m1, m2, gcd;
1708 d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1709 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1710 {
1711 nDelete(&d);
1712 nDelete(&s);
1713 nDelete(&t);
1714 }
1715 else
1716 {
1717 k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1718 pSetCoeff0(m1, s);
1719 pSetCoeff0(m2, t);
1720 pSetCoeff0(gcd, d);
1721 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);
1722 poly pSigMult = p_Copy(h->sig,currRing);
1723 poly sSigMult = p_Copy(strat->sig[i],currRing);
1726 p_LmDelete(m1, strat->tailRing);
1727 p_LmDelete(m2, strat->tailRing);
1729 if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1730 {
1731 pDelete(&h->p);
1732 h->p = gcd;
1733 pDelete(&h->sig);
1734 h->sig = pairsig;
1735 pNext(h->sig) = NULL;
1736 strat->initEcart(h);
1737 h->sev = pGetShortExpVector(h->p);
1738 h->sevSig = pGetShortExpVector(h->sig);
1739 h->i_r1 = -1;h->i_r2 = -1;
1740 if(h->lcm != NULL)
1741 {
1742 pLmDelete(h->lcm);
1743 h->lcm = NULL;
1744 }
1745 if (currRing!=strat->tailRing)
1746 h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1747 return TRUE;
1748 }
1749 //Delete what you didn't use
1750 pDelete(&gcd);
1751 pDelete(&pairsig);
1752 }
1753 }
1754 return FALSE;
1755}
1756
1757static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1758{
1759 number d, s, t;
1760 assume(atR >= 0);
1761 poly m1, m2, gcd,si;
1762 assume(i<=strat->sl);
1763 si = strat->S[i];
1764 //printf("\n--------------------------------\n");
1765 //pWrite(p);pWrite(si);
1766 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1767
1768 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1769 {
1770 nDelete(&d);
1771 nDelete(&s);
1772 nDelete(&t);
1773 return FALSE;
1774 }
1775
1776 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1777 //p_Test(m1,strat->tailRing);
1778 //p_Test(m2,strat->tailRing);
1779 /*if(!enterTstrong)
1780 {
1781 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1782 {
1783 memset(&(strat->P), 0, sizeof(strat->P));
1784 kStratChangeTailRing(strat);
1785 strat->P = *(strat->R[atR]);
1786 p_LmFree(m1, strat->tailRing);
1787 p_LmFree(m2, strat->tailRing);
1788 p_LmFree(gcd, currRing);
1789 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1790 }
1791 }*/
1792 pSetCoeff0(m1, s);
1793 pSetCoeff0(m2, t);
1794 pSetCoeff0(gcd, d);
1795 p_Test(m1,strat->tailRing);
1796 p_Test(m2,strat->tailRing);
1797 //printf("\n===================================\n");
1798 //pWrite(m1);pWrite(m2);pWrite(gcd);
1799#ifdef KDEBUG
1800 if (TEST_OPT_DEBUG)
1801 {
1802 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1803 PrintS("m1 = ");
1804 p_wrp(m1, strat->tailRing);
1805 PrintS(" ; m2 = ");
1806 p_wrp(m2, strat->tailRing);
1807 PrintS(" ; gcd = ");
1808 wrp(gcd);
1809 PrintS("\n--- create strong gcd poly: ");
1810 Print("\n p: %d", i);
1811 wrp(p);
1812 Print("\n strat->S[%d]: ", i);
1813 wrp(si);
1814 PrintS(" ---> ");
1815 }
1816#endif
1817
1818 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1819
1820#ifdef KDEBUG
1821 if (TEST_OPT_DEBUG)
1822 {
1823 wrp(gcd);
1824 PrintLn();
1825 }
1826#endif
1827
1828 //Check and set the signatures
1829 poly pSigMult = p_Copy(sig,currRing);
1830 poly sSigMult = p_Copy(strat->sig[i],currRing);
1833 p_LmDelete(m1, strat->tailRing);
1834 p_LmDelete(m2, strat->tailRing);
1835 poly pairsig;
1836 if(pLmCmp(pSigMult,sSigMult) == 0)
1837 {
1838 //Same lm, have to add them
1840 //This might be zero
1841 }
1842 else
1843 {
1844 //Set the sig to either pSigMult or sSigMult
1845 if(pLtCmp(pSigMult,sSigMult)==1)
1846 {
1847 pairsig = pSigMult;
1848 pDelete(&sSigMult);
1849 }
1850 else
1851 {
1852 pairsig = sSigMult;
1853 pDelete(&pSigMult);
1854 }
1855 }
1856
1857 LObject h;
1858 h.p = gcd;
1859 h.tailRing = strat->tailRing;
1860 h.sig = pairsig;
1861 int posx;
1862 strat->initEcart(&h);
1863 h.sev = pGetShortExpVector(h.p);
1864 h.i_r1 = -1;h.i_r2 = -1;
1865 if (currRing!=strat->tailRing)
1866 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1867 if(h.sig == NULL)
1868 {
1869 //sigdrop since we loose the signature
1870 strat->sigdrop = TRUE;
1871 //Try to reduce it as far as we can via redRing
1872 int red_result = redRing(&h,strat);
1873 if(red_result == 0)
1874 {
1875 // Cancel the sigdrop
1876 p_Delete(&h.sig,currRing);h.sig = NULL;
1877 strat->sigdrop = FALSE;
1878 return FALSE;
1879 }
1880 else
1881 {
1882 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1883 #if 1
1884 strat->enterS(h,0,strat,strat->tl);
1885 #endif
1886 return FALSE;
1887 }
1888 }
1889 if(!nGreaterZero(pGetCoeff(h.sig)))
1890 {
1891 h.sig = pNeg(h.sig);
1892 h.p = pNeg(h.p);
1893 }
1894
1895 if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1896 {
1897 strat->sigdrop = TRUE;
1898 // Completely reduce it
1899 int red_result = redRing(&h,strat);
1900 if(red_result == 0)
1901 {
1902 // Reduced to 0
1903 strat->sigdrop = FALSE;
1904 p_Delete(&h.sig,currRing);h.sig = NULL;
1905 return FALSE;
1906 }
1907 else
1908 {
1909 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1910 // 0 - add just the original poly causing the sigdrop, 1 - add also this
1911 #if 1
1912 strat->enterS(h,0,strat, strat->tl+1);
1913 #endif
1914 return FALSE;
1915 }
1916 }
1917 //Check for sigdrop
1918 if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1919 {
1920 strat->sigdrop = TRUE;
1921 //Enter this element to S
1922 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1923 strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1924 }
1925 #if 1
1926 h.p1 = p;h.p2 = strat->S[i];
1927 #endif
1928 if (atR >= 0)
1929 {
1930 h.i_r2 = strat->S_2_R[i];
1931 h.i_r1 = atR;
1932 }
1933 else
1934 {
1935 h.i_r1 = -1;
1936 h.i_r2 = -1;
1937 }
1938 if (strat->Ll==-1)
1939 posx =0;
1940 else
1941 posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1942 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1943 return TRUE;
1944}
1945#endif
1946
1947/*2
1948* put the pair (s[i],p) into the set B, ecart=ecart(p)
1949*/
1950
1951void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1952{
1953 assume(i<=strat->sl);
1954
1955 int l,j,compare;
1956 LObject Lp;
1957 Lp.i_r = -1;
1958
1959#ifdef KDEBUG
1960 Lp.ecart=0; Lp.length=0;
1961#endif
1962 /*- computes the lcm(s[i],p) -*/
1963 Lp.lcm = pInit();
1964
1965#ifndef HAVE_RATGRING
1966 pLcm(p,strat->S[i],Lp.lcm);
1967#elif defined(HAVE_RATGRING)
1968 if (rIsRatGRing(currRing))
1969 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1970 else
1971 pLcm(p,strat->S[i],Lp.lcm);
1972#endif
1973 pSetm(Lp.lcm);
1974
1975
1976 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
1977 {
1978 if (strat->fromT && (strat->ecartS[i]>ecart))
1979 {
1980 pLmFree(Lp.lcm);
1981 return;
1982 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
1983 }
1984 if((!((strat->ecartS[i]>0)&&(ecart>0)))
1985 && pHasNotCF(p,strat->S[i]))
1986 {
1987 /*
1988 *the product criterion has applied for (s,p),
1989 *i.e. lcm(s,p)=product of the leading terms of s and p.
1990 *Suppose (s,r) is in L and the leading term
1991 *of p divides lcm(s,r)
1992 *(==> the leading term of p divides the leading term of r)
1993 *but the leading term of s does not divide the leading term of r
1994 *(notice that tis condition is automatically satisfied if r is still
1995 *in S), then (s,r) can be cancelled.
1996 *This should be done here because the
1997 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1998 *
1999 *Moreover, skipping (s,r) holds also for the noncommutative case.
2000 */
2001 strat->cp++;
2002 pLmFree(Lp.lcm);
2003 return;
2004 }
2005 Lp.ecart = si_max(ecart,strat->ecartS[i]);
2006 /*
2007 *the set B collects the pairs of type (S[j],p)
2008 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2009 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2010 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2011 */
2012 {
2013 j = strat->Bl;
2014 loop
2015 {
2016 if (j < 0) break;
2017 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2018 if ((compare==1)
2019 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2020 {
2021 strat->c3++;
2022 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2023 {
2024 pLmFree(Lp.lcm);
2025 return;
2026 }
2027 break;
2028 }
2029 else
2030 if ((compare ==-1)
2031 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2032 {
2033 deleteInL(strat->B,&strat->Bl,j,strat);
2034 strat->c3++;
2035 }
2036 j--;
2037 }
2038 }
2039 }
2040 else /*sugarcrit*/
2041 {
2042 if (ALLOW_PROD_CRIT(strat))
2043 {
2044 if (strat->fromT && (strat->ecartS[i]>ecart))
2045 {
2046 pLmFree(Lp.lcm);
2047 return;
2048 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2049 }
2050 // if currRing->nc_type!=quasi (or skew)
2051 // TODO: enable productCrit for super commutative algebras...
2052 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2053 pHasNotCF(p,strat->S[i]))
2054 {
2055 /*
2056 *the product criterion has applied for (s,p),
2057 *i.e. lcm(s,p)=product of the leading terms of s and p.
2058 *Suppose (s,r) is in L and the leading term
2059 *of p divides lcm(s,r)
2060 *(==> the leading term of p divides the leading term of r)
2061 *but the leading term of s does not divide the leading term of r
2062 *(notice that tis condition is automatically satisfied if r is still
2063 *in S), then (s,r) can be canceled.
2064 *This should be done here because the
2065 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2066 */
2067 strat->cp++;
2068 pLmFree(Lp.lcm);
2069 return;
2070 }
2071 /*
2072 *the set B collects the pairs of type (S[j],p)
2073 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2074 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2075 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2076 */
2077 for(j = strat->Bl;j>=0;j--)
2078 {
2079 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2080 if (compare==1)
2081 {
2082 strat->c3++;
2083 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2084 {
2085 pLmFree(Lp.lcm);
2086 return;
2087 }
2088 break;
2089 }
2090 else
2091 if (compare ==-1)
2092 {
2093 deleteInL(strat->B,&strat->Bl,j,strat);
2094 strat->c3++;
2095 }
2096 }
2097 }
2098 }
2099 /*
2100 *the pair (S[i],p) enters B if the spoly != 0
2101 */
2102 /*- compute the short s-polynomial -*/
2103 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2104 pNorm(p);
2105
2106 if ((strat->S[i]==NULL) || (p==NULL))
2107 return;
2108
2109 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2110 Lp.p=NULL;
2111 else
2112 {
2113 #ifdef HAVE_PLURAL
2114 if ( rIsPluralRing(currRing) )
2115 {
2116 if(pHasNotCF(p, strat->S[i]))
2117 {
2118 if(ncRingType(currRing) == nc_lie)
2119 {
2120 // generalized prod-crit for lie-type
2121 strat->cp++;
2122 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2123 }
2124 else
2125 if( ALLOW_PROD_CRIT(strat) )
2126 {
2127 // product criterion for homogeneous case in SCA
2128 strat->cp++;
2129 Lp.p = NULL;
2130 }
2131 else
2132 {
2133 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2134 nc_CreateShortSpoly(strat->S[i], p, currRing);
2135 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2136 pNext(Lp.p) = strat->tail; // !!!
2137 }
2138 }
2139 else
2140 {
2141 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2142 nc_CreateShortSpoly(strat->S[i], p, currRing);
2143
2144 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2145 pNext(Lp.p) = strat->tail; // !!!
2146 }
2147 }
2148 else
2149 #endif
2150 {
2152 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2153 }
2154 }
2155 if (Lp.p == NULL)
2156 {
2157 /*- the case that the s-poly is 0 -*/
2158 if (strat->pairtest==NULL) initPairtest(strat);
2159 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2160 strat->pairtest[strat->sl+1] = TRUE;
2161 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2162 /*
2163 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2164 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2165 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2166 *term of p divides the lcm(s,r)
2167 *(this canceling should be done here because
2168 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2169 *the first case is handled in chainCrit
2170 */
2171 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2172 }
2173 else
2174 {
2175 /*- the pair (S[i],p) enters B -*/
2176 Lp.p1 = strat->S[i];
2177 Lp.p2 = p;
2178
2179 if (
2181// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2182 )
2183 {
2184 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2185 pNext(Lp.p) = strat->tail; // !!!
2186 }
2187
2188 if (atR >= 0)
2189 {
2190 Lp.i_r1 = strat->S_2_R[i];
2191 Lp.i_r2 = atR;
2192 }
2193 else
2194 {
2195 Lp.i_r1 = -1;
2196 Lp.i_r2 = -1;
2197 }
2198 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2199
2201 {
2204 && (Lp.p->coef!=NULL))
2205 nDelete(&(Lp.p->coef));
2206 }
2207
2208 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2209 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2210 }
2211}
2212
2213/// p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
2214static inline BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2215{
2216 int i = rVar(r);
2217 loop
2218 {
2219 if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2220 return FALSE;
2221 i--;
2222 if (i == 0)
2223 return TRUE;
2224 }
2225}
2226
2227/*2
2228* put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2229* (in the special case: idLift for ideals, i.e. strat->syzComp==1)
2230* (prod.crit applies)
2231*/
2232
2233static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2234{
2235 assume(ALLOW_PROD_CRIT(strat));
2237 assume(i<=strat->sl);
2238 assume(strat->syzComp==1);
2239
2240 if ((strat->S[i]==NULL) || (p==NULL))
2241 return;
2242
2243 int l,j,compare;
2244 LObject Lp;
2245 Lp.i_r = -1;
2246
2247#ifdef KDEBUG
2248 Lp.ecart=0; Lp.length=0;
2249#endif
2250 /*- computes the lcm(s[i],p) -*/
2251 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2252
2253 if (strat->sugarCrit)
2254 {
2255 if((!((strat->ecartS[i]>0)&&(ecart>0)))
2256 && p_HasNotCF_Lift(p,strat->S[i],currRing))
2257 {
2258 /*
2259 *the product criterion has applied for (s,p),
2260 *i.e. lcm(s,p)=product of the leading terms of s and p.
2261 *Suppose (s,r) is in L and the leading term
2262 *of p divides lcm(s,r)
2263 *(==> the leading term of p divides the leading term of r)
2264 *but the leading term of s does not divide the leading term of r
2265 *(notice that tis condition is automatically satisfied if r is still
2266 *in S), then (s,r) can be cancelled.
2267 *This should be done here because the
2268 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2269 *
2270 *Moreover, skipping (s,r) holds also for the noncommutative case.
2271 */
2272 strat->cp++;
2273 pLmFree(Lp.lcm);
2274 return;
2275 }
2276 else
2277 Lp.ecart = si_max(ecart,strat->ecartS[i]);
2278 if (strat->fromT && (strat->ecartS[i]>ecart))
2279 {
2280 pLmFree(Lp.lcm);
2281 return;
2282 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2283 }
2284 /*
2285 *the set B collects the pairs of type (S[j],p)
2286 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2287 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2288 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2289 */
2290 {
2291 j = strat->Bl;
2292 loop
2293 {
2294 if (j < 0) break;
2295 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2296 if ((compare==1)
2297 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2298 {
2299 strat->c3++;
2300 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2301 {
2302 pLmFree(Lp.lcm);
2303 return;
2304 }
2305 break;
2306 }
2307 else
2308 if ((compare ==-1)
2309 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2310 {
2311 deleteInL(strat->B,&strat->Bl,j,strat);
2312 strat->c3++;
2313 }
2314 j--;
2315 }
2316 }
2317 }
2318 else /*sugarcrit*/
2319 {
2320 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2321 p_HasNotCF_Lift(p,strat->S[i],currRing))
2322 {
2323 /*
2324 *the product criterion has applied for (s,p),
2325 *i.e. lcm(s,p)=product of the leading terms of s and p.
2326 *Suppose (s,r) is in L and the leading term
2327 *of p divides lcm(s,r)
2328 *(==> the leading term of p divides the leading term of r)
2329 *but the leading term of s does not divide the leading term of r
2330 *(notice that tis condition is automatically satisfied if r is still
2331 *in S), then (s,r) can be canceled.
2332 *This should be done here because the
2333 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2334 */
2335 strat->cp++;
2336 pLmFree(Lp.lcm);
2337 return;
2338 }
2339 if (strat->fromT && (strat->ecartS[i]>ecart))
2340 {
2341 pLmFree(Lp.lcm);
2342 return;
2343 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2344 }
2345 /*
2346 *the set B collects the pairs of type (S[j],p)
2347 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2348 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2349 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2350 */
2351 for(j = strat->Bl;j>=0;j--)
2352 {
2353 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2354 if (compare==1)
2355 {
2356 strat->c3++;
2357 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2358 {
2359 pLmFree(Lp.lcm);
2360 return;
2361 }
2362 break;
2363 }
2364 else
2365 if (compare ==-1)
2366 {
2367 deleteInL(strat->B,&strat->Bl,j,strat);
2368 strat->c3++;
2369 }
2370 }
2371 }
2372 /*
2373 *the pair (S[i],p) enters B if the spoly != 0
2374 */
2375 /*- compute the short s-polynomial -*/
2376 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2377 pNorm(p);
2378
2379 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2380 Lp.p=NULL;
2381 else
2382 {
2384 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2385 }
2386 if (Lp.p == NULL)
2387 {
2388 /*- the case that the s-poly is 0 -*/
2389 if (strat->pairtest==NULL) initPairtest(strat);
2390 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2391 strat->pairtest[strat->sl+1] = TRUE;
2392 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2393 /*
2394 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2395 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2396 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2397 *term of p divides the lcm(s,r)
2398 *(this canceling should be done here because
2399 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2400 *the first case is handled in chainCrit
2401 */
2402 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2403 }
2404 else
2405 {
2406 /*- the pair (S[i],p) enters B -*/
2407 Lp.p1 = strat->S[i];
2408 Lp.p2 = p;
2409
2410 pNext(Lp.p) = strat->tail; // !!!
2411
2412 if (atR >= 0)
2413 {
2414 Lp.i_r1 = strat->S_2_R[i];
2415 Lp.i_r2 = atR;
2416 }
2417 else
2418 {
2419 Lp.i_r1 = -1;
2420 Lp.i_r2 = -1;
2421 }
2422 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2423
2425 {
2428 && (Lp.p->coef!=NULL))
2429 nDelete(&(Lp.p->coef));
2430 }
2431
2432 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2433 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2434 }
2435}
2436
2437/*2
2438* put the pair (s[i],p) into the set B, ecart=ecart(p)
2439* NOTE: here we need to add the signature-based criteria
2440*/
2441
2442#ifdef DEBUGF5
2443static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2444#else
2445static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2446#endif
2447{
2448 assume(i<=strat->sl);
2449
2450 int l;
2451 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2452 // the corresponding signatures for criteria checks
2453 LObject Lp;
2454 poly pSigMult = p_Copy(pSig,currRing);
2455 poly sSigMult = p_Copy(strat->sig[i],currRing);
2456 unsigned long pSigMultNegSev,sSigMultNegSev;
2457 Lp.i_r = -1;
2458
2459#ifdef KDEBUG
2460 Lp.ecart=0; Lp.length=0;
2461#endif
2462 /*- computes the lcm(s[i],p) -*/
2463 Lp.lcm = pInit();
2464 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2465#ifndef HAVE_RATGRING
2466 pLcm(p,strat->S[i],Lp.lcm);
2467#elif defined(HAVE_RATGRING)
2468 if (rIsRatGRing(currRing))
2469 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2470 else
2471 pLcm(p,strat->S[i],Lp.lcm);
2472#endif
2473 pSetm(Lp.lcm);
2474
2475 // set coeffs of multipliers m1 and m2
2476 pSetCoeff0(m1, nInit(1));
2477 pSetCoeff0(m2, nInit(1));
2478//#if 1
2479#ifdef DEBUGF5
2480 PrintS("P1 ");
2481 pWrite(pHead(p));
2482 PrintS("P2 ");
2483 pWrite(pHead(strat->S[i]));
2484 PrintS("M1 ");
2485 pWrite(m1);
2486 PrintS("M2 ");
2487 pWrite(m2);
2488#endif
2489 // get multiplied signatures for testing
2490 pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2491 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2492 sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2493 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2494
2495//#if 1
2496#ifdef DEBUGF5
2497 PrintS("----------------\n");
2500 PrintS("----------------\n");
2501 Lp.checked = 0;
2502#endif
2504//#if 1
2505#if DEBUGF5
2506 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2509#endif
2510 if(sigCmp==0)
2511 {
2512 // printf("!!!! EQUAL SIGS !!!!\n");
2513 // pSig = sSig, delete element due to Rewritten Criterion
2514 pDelete(&pSigMult);
2515 pDelete(&sSigMult);
2517 pLmDelete(Lp.lcm);
2518 else
2519 pLmFree(Lp.lcm);
2520 pDelete (&m1);
2521 pDelete (&m2);
2522 return;
2523 }
2524 // testing by syzCrit = F5 Criterion
2525 // testing by rewCrit1 = Rewritten Criterion
2526 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2527 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2528 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2529 || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2530 )
2531 {
2532 pDelete(&pSigMult);
2533 pDelete(&sSigMult);
2535 pLmDelete(Lp.lcm);
2536 else
2537 pLmFree(Lp.lcm);
2538 pDelete (&m1);
2539 pDelete (&m2);
2540 return;
2541 }
2542 /*
2543 *the pair (S[i],p) enters B if the spoly != 0
2544 */
2545 /*- compute the short s-polynomial -*/
2546 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2547 pNorm(p);
2548
2549 if ((strat->S[i]==NULL) || (p==NULL))
2550 return;
2551
2552 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2553 Lp.p=NULL;
2554 else
2555 {
2556 #ifdef HAVE_PLURAL
2557 if ( rIsPluralRing(currRing) )
2558 {
2559 if(pHasNotCF(p, strat->S[i]))
2560 {
2561 if(ncRingType(currRing) == nc_lie)
2562 {
2563 // generalized prod-crit for lie-type
2564 strat->cp++;
2565 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2566 }
2567 else
2568 if( ALLOW_PROD_CRIT(strat) )
2569 {
2570 // product criterion for homogeneous case in SCA
2571 strat->cp++;
2572 Lp.p = NULL;
2573 }
2574 else
2575 {
2576 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2577 nc_CreateShortSpoly(strat->S[i], p, currRing);
2578
2579 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2580 pNext(Lp.p) = strat->tail; // !!!
2581 }
2582 }
2583 else
2584 {
2585 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2586 nc_CreateShortSpoly(strat->S[i], p, currRing);
2587
2588 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2589 pNext(Lp.p) = strat->tail; // !!!
2590 }
2591 }
2592 else
2593 #endif
2594 {
2596 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2597 }
2598 }
2599 // store from which element this pair comes from for further tests
2600 //Lp.from = strat->sl+1;
2601 if(sigCmp==currRing->OrdSgn)
2602 {
2603 // pSig > sSig
2604 pDelete (&sSigMult);
2605 Lp.sig = pSigMult;
2606 Lp.sevSig = ~pSigMultNegSev;
2607 }
2608 else
2609 {
2610 // pSig < sSig
2611 pDelete (&pSigMult);
2612 Lp.sig = sSigMult;
2613 Lp.sevSig = ~sSigMultNegSev;
2614 }
2615 if (Lp.p == NULL)
2616 {
2617 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2618 int pos = posInSyz(strat, Lp.sig);
2619 enterSyz(Lp, strat, pos);
2620 }
2621 else
2622 {
2623 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2624 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2625 {
2626 pLmFree(Lp.lcm);
2627 pDelete(&Lp.sig);
2628 pDelete (&m1);
2629 pDelete (&m2);
2630 return;
2631 }
2632 // in any case Lp is checked up to the next strat->P which is added
2633 // to S right after this critical pair creation.
2634 // NOTE: this even holds if the 2nd generator gives the bigger signature
2635 // moreover, this improves rewCriterion,
2636 // i.e. strat->checked > strat->from if and only if the 2nd generator
2637 // gives the bigger signature.
2638 Lp.checked = strat->sl+1;
2639 // at this point it is clear that the pair will be added to L, since it has
2640 // passed all tests up to now
2641
2642 // adds buchberger's first criterion
2643 if (pLmCmp(m2,pHead(p)) == 0)
2644 {
2645 Lp.prod_crit = TRUE; // Product Criterion
2646#if 0
2647 int pos = posInSyz(strat, Lp.sig);
2648 enterSyz(Lp, strat, pos);
2649 pDelete (&m1);
2650 pDelete (&m2);
2651 return;
2652#endif
2653 }
2654 pDelete (&m1);
2655 pDelete (&m2);
2656#if DEBUGF5
2657 PrintS("SIGNATURE OF PAIR: ");
2658 pWrite(Lp.sig);
2659#endif
2660 /*- the pair (S[i],p) enters B -*/
2661 Lp.p1 = strat->S[i];
2662 Lp.p2 = p;
2663
2664 if (
2666// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2667 )
2668 {
2669 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2670 pNext(Lp.p) = strat->tail; // !!!
2671 }
2672
2673 if (atR >= 0)
2674 {
2675 Lp.i_r1 = strat->S_2_R[i];
2676 Lp.i_r2 = atR;
2677 }
2678 else
2679 {
2680 Lp.i_r1 = -1;
2681 Lp.i_r2 = -1;
2682 }
2683 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2684
2686 {
2689 && (Lp.p->coef!=NULL))
2690 nDelete(&(Lp.p->coef));
2691 }
2692
2693 l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2694 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2695 }
2696}
2697
2698
2699#ifdef DEBUGF5
2700static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2701#else
2702static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2703#endif
2704{
2705 #if ALL_VS_JUST
2706 //Over rings, if we construct the strong pair, do not add the spair
2708 {
2709 number s,t,d;
2710 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2711
2712 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2713 {
2714 nDelete(&d);
2715 nDelete(&s);
2716 nDelete(&t);
2717 return;
2718 }
2719 nDelete(&d);
2720 nDelete(&s);
2721 nDelete(&t);
2722 }
2723 #endif
2724 assume(i<=strat->sl);
2725 int l;
2726 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2727 // the corresponding signatures for criteria checks
2728 LObject Lp;
2729 poly pSigMult = p_Copy(pSig,currRing);
2730 poly sSigMult = p_Copy(strat->sig[i],currRing);
2731 unsigned long pSigMultNegSev,sSigMultNegSev;
2732 Lp.i_r = -1;
2733
2734#ifdef KDEBUG
2735 Lp.ecart=0; Lp.length=0;
2736#endif
2737 /*- computes the lcm(s[i],p) -*/
2738 Lp.lcm = pInit();
2739 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2740#ifndef HAVE_RATGRING
2741 pLcm(p,strat->S[i],Lp.lcm);
2742#elif defined(HAVE_RATGRING)
2743 if (rIsRatGRing(currRing))
2744 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2745 else
2746 pLcm(p,strat->S[i],Lp.lcm);
2747#endif
2748 pSetm(Lp.lcm);
2749
2750 // set coeffs of multipliers m1 and m2
2752 {
2753 number s = nCopy(pGetCoeff(strat->S[i]));
2754 number t = nCopy(pGetCoeff(p));
2755 pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2756 ksCheckCoeff(&s, &t, currRing->cf);
2757 pSetCoeff0(m1,s);
2758 pSetCoeff0(m2,t);
2759 }
2760 else
2761 {
2762 pSetCoeff0(m1, nInit(1));
2763 pSetCoeff0(m2, nInit(1));
2764 }
2765#ifdef DEBUGF5
2766 Print("P1 ");
2767 pWrite(pHead(p));
2768 Print("P2 ");
2769 pWrite(pHead(strat->S[i]));
2770 Print("M1 ");
2771 pWrite(m1);
2772 Print("M2 ");
2773 pWrite(m2);
2774#endif
2775
2776 // get multiplied signatures for testing
2778 if(pSigMult != NULL)
2779 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2781 if(sSigMult != NULL)
2782 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2783//#if 1
2784#ifdef DEBUGF5
2785 Print("----------------\n");
2788 Print("----------------\n");
2789 Lp.checked = 0;
2790#endif
2791 int sigCmp;
2792 if(pSigMult != NULL && sSigMult != NULL)
2793 {
2796 else
2798 }
2799 else
2800 {
2801 if(pSigMult == NULL)
2802 {
2803 if(sSigMult == NULL)
2804 sigCmp = 0;
2805 else
2806 sigCmp = -1;
2807 }
2808 else
2809 sigCmp = 1;
2810 }
2811//#if 1
2812#if DEBUGF5
2813 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2816#endif
2817 //In the ring case we already build the sig
2819 {
2820 if(sigCmp == 0)
2821 {
2822 //sigdrop since we loose the signature
2823 strat->sigdrop = TRUE;
2824 //Try to reduce it as far as we can via redRing
2826 {
2827 poly p1 = p_Copy(p,currRing);
2828 poly p2 = p_Copy(strat->S[i],currRing);
2829 p1 = p_Mult_mm(p1,m1,currRing);
2830 p2 = p_Mult_mm(p2,m2,currRing);
2831 Lp.p = p_Sub(p1,p2,currRing);
2832 if(Lp.p != NULL)
2834 }
2835 int red_result = redRing(&Lp,strat);
2836 if(red_result == 0)
2837 {
2838 // Cancel the sigdrop
2839 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2840 strat->sigdrop = FALSE;
2841 return;
2842 }
2843 else
2844 {
2845 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2846 #if 1
2847 strat->enterS(Lp,0,strat,strat->tl);
2848 #endif
2849 return;
2850 }
2851 }
2853 {
2854 //Same lm, have to subtract
2856 }
2857 else
2858 {
2859 if(sigCmp == 1)
2860 {
2861 Lp.sig = pCopy(pSigMult);
2862 }
2863 if(sigCmp == -1)
2864 {
2865 Lp.sig = pNeg(pCopy(sSigMult));
2866 }
2867 }
2868 Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2869 }
2870
2871 #if 0
2872 if(sigCmp==0)
2873 {
2874 // printf("!!!! EQUAL SIGS !!!!\n");
2875 // pSig = sSig, delete element due to Rewritten Criterion
2876 pDelete(&pSigMult);
2877 pDelete(&sSigMult);
2879 pLmDelete(Lp.lcm);
2880 else
2881 pLmFree(Lp.lcm);
2882 pDelete (&m1);
2883 pDelete (&m2);
2884 return;
2885 }
2886 #endif
2887 // testing by syzCrit = F5 Criterion
2888 // testing by rewCrit1 = Rewritten Criterion
2889 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2890 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2891 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2892 // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2893 //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2894 )
2895 {
2896 pDelete(&pSigMult);
2897 pDelete(&sSigMult);
2899 pLmDelete(Lp.lcm);
2900 else
2901 pLmFree(Lp.lcm);
2902 pDelete (&m1);
2903 pDelete (&m2);
2904 return;
2905 }
2906 /*
2907 *the pair (S[i],p) enters B if the spoly != 0
2908 */
2909 /*- compute the short s-polynomial -*/
2910 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2911 pNorm(p);
2912
2913 if ((strat->S[i]==NULL) || (p==NULL))
2914 return;
2915
2916 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2917 Lp.p=NULL;
2918 else
2919 {
2920 //Build p
2922 {
2923 poly p1 = p_Copy(p,currRing);
2924 poly p2 = p_Copy(strat->S[i],currRing);
2925 p1 = p_Mult_mm(p1,m1,currRing);
2926 p2 = p_Mult_mm(p2,m2,currRing);
2927 Lp.p = p_Sub(p1,p2,currRing);
2928 if(Lp.p != NULL)
2930 }
2931 else
2932 {
2933 #ifdef HAVE_PLURAL
2934 if ( rIsPluralRing(currRing) )
2935 {
2936 if(ncRingType(currRing) == nc_lie)
2937 {
2938 // generalized prod-crit for lie-type
2939 strat->cp++;
2940 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2941 }
2942 else
2943 if( ALLOW_PROD_CRIT(strat) )
2944 {
2945 // product criterion for homogeneous case in SCA
2946 strat->cp++;
2947 Lp.p = NULL;
2948 }
2949 else
2950 {
2951 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2952 nc_CreateShortSpoly(strat->S[i], p, currRing);
2953
2954 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2955 pNext(Lp.p) = strat->tail; // !!!
2956 }
2957 }
2958 else
2959 #endif
2960 {
2962 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2963 }
2964 }
2965 }
2966 // store from which element this pair comes from for further tests
2967 //Lp.from = strat->sl+1;
2969 {
2970 //Put the sig to be > 0
2971 if(!nGreaterZero(pGetCoeff(Lp.sig)))
2972 {
2973 Lp.sig = pNeg(Lp.sig);
2974 Lp.p = pNeg(Lp.p);
2975 }
2976 }
2977 else
2978 {
2979 if(sigCmp==currRing->OrdSgn)
2980 {
2981 // pSig > sSig
2982 pDelete (&sSigMult);
2983 Lp.sig = pSigMult;
2984 Lp.sevSig = ~pSigMultNegSev;
2985 }
2986 else
2987 {
2988 // pSig < sSig
2989 pDelete (&pSigMult);
2990 Lp.sig = sSigMult;
2991 Lp.sevSig = ~sSigMultNegSev;
2992 }
2993 }
2994 if (Lp.p == NULL)
2995 {
2996 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2997 int pos = posInSyz(strat, Lp.sig);
2998 enterSyz(Lp, strat, pos);
2999 }
3000 else
3001 {
3002 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
3003 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
3004 {
3005 pLmFree(Lp.lcm);
3006 pDelete(&Lp.sig);
3007 pDelete (&m1);
3008 pDelete (&m2);
3009 return;
3010 }
3011 // in any case Lp is checked up to the next strat->P which is added
3012 // to S right after this critical pair creation.
3013 // NOTE: this even holds if the 2nd generator gives the bigger signature
3014 // moreover, this improves rewCriterion,
3015 // i.e. strat->checked > strat->from if and only if the 2nd generator
3016 // gives the bigger signature.
3017 Lp.checked = strat->sl+1;
3018 // at this point it is clear that the pair will be added to L, since it has
3019 // passed all tests up to now
3020
3021 // adds buchberger's first criterion
3022 if (pLmCmp(m2,pHead(p)) == 0)
3023 {
3024 Lp.prod_crit = TRUE; // Product Criterion
3025#if 0
3026 int pos = posInSyz(strat, Lp.sig);
3027 enterSyz(Lp, strat, pos);
3028 pDelete (&m1);
3029 pDelete (&m2);
3030 return;
3031#endif
3032 }
3033 pDelete (&m1);
3034 pDelete (&m2);
3035#if DEBUGF5
3036 PrintS("SIGNATURE OF PAIR: ");
3037 pWrite(Lp.sig);
3038#endif
3039 /*- the pair (S[i],p) enters B -*/
3040 Lp.p1 = strat->S[i];
3041 Lp.p2 = p;
3042
3043 if (
3045// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3047 )
3048 {
3049 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3050 pNext(Lp.p) = strat->tail; // !!!
3051 }
3052
3053 if (atR >= 0)
3054 {
3055 Lp.i_r1 = strat->S_2_R[i];
3056 Lp.i_r2 = atR;
3057 }
3058 else
3059 {
3060 Lp.i_r1 = -1;
3061 Lp.i_r2 = -1;
3062 }
3063 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3064
3066 {
3069 && (Lp.p->coef!=NULL))
3070 nDelete(&(Lp.p->coef));
3071 }
3072 // Check for sigdrop
3073 if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3074 {
3075 strat->sigdrop = TRUE;
3076 // Completely reduce it
3077 int red_result = redRing(&Lp,strat);
3078 if(red_result == 0)
3079 {
3080 // Reduced to 0
3081 strat->sigdrop = FALSE;
3082 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3083 return;
3084 }
3085 else
3086 {
3087 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3088 // 0 - add just the original poly causing the sigdrop, 1 - add also this
3089 #if 1
3090 strat->enterS(Lp,0,strat, strat->tl+1);
3091 #endif
3092 return;
3093 }
3094 }
3095 l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3096 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3097 }
3098}
3099
3100/*2
3101* put the pair (s[i],p) into the set L, ecart=ecart(p)
3102* in the case that s forms a SB of (s)
3103*/
3104void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3105{
3106 //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3107 if(pHasNotCF(p,strat->S[i]))
3108 {
3109 //PrintS("prod-crit\n");
3110 if(ALLOW_PROD_CRIT(strat))
3111 {
3112 //PrintS("prod-crit\n");
3113 strat->cp++;
3114 return;
3115 }
3116 }
3117
3118 int l;
3119 LObject Lp;
3120 Lp.i_r = -1;
3121
3122 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3123 /*- compute the short s-polynomial -*/
3124
3125 #ifdef HAVE_PLURAL
3127 {
3128 Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3129 }
3130 else
3131 #endif
3132 Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3133
3134 if (Lp.p == NULL)
3135 {
3136 //PrintS("short spoly==NULL\n");
3137 pLmFree(Lp.lcm);
3138 }
3139 else
3140 {
3141 /*- the pair (S[i],p) enters L -*/
3142 Lp.p1 = strat->S[i];
3143 Lp.p2 = p;
3144 if (atR >= 0)
3145 {
3146 Lp.i_r1 = strat->S_2_R[i];
3147 Lp.i_r2 = atR;
3148 }
3149 else
3150 {
3151 Lp.i_r1 = -1;
3152 Lp.i_r2 = -1;
3153 }
3154 assume(pNext(Lp.p) == NULL);
3155 pNext(Lp.p) = strat->tail;
3156 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3158 {
3161 && (Lp.p->coef!=NULL))
3162 nDelete(&(Lp.p->coef));
3163 }
3164 l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3165 //Print("-> L[%d]\n",l);
3166 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3167 }
3168}
3169
3170/*2
3171* merge set B into L
3172*/
3174{
3175 int j=strat->Ll+strat->Bl+1;
3176 if (j>strat->Lmax)
3177 {
3178 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3179 enlargeL(&(strat->L),&(strat->Lmax),j);
3180 }
3181 j = strat->Ll;
3182 int i;
3183 for (i=strat->Bl; i>=0; i--)
3184 {
3185 j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3186 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3187 }
3188 strat->Bl = -1;
3189}
3190
3191/*2
3192* merge set B into L
3193*/
3195{
3196 int j=strat->Ll+strat->Bl+1;
3197 if (j>strat->Lmax)
3198 {
3199 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3200 enlargeL(&(strat->L),&(strat->Lmax),j);
3201 }
3202 j = strat->Ll;
3203 int i;
3204 for (i=strat->Bl; i>=0; i--)
3205 {
3206 j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3207 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3208 }
3209 strat->Bl = -1;
3210}
3211
3212/*2
3213*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3214*using the chain-criterion in B and L and enters B to L
3215*/
3216void chainCritNormal (poly p,int ecart,kStrategy strat)
3217{
3218 int i,j,l;
3219
3220 /*
3221 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3222 *In this case all elements in B such
3223 *that their lcm is divisible by the leading term of S[i] can be canceled
3224 */
3225 if (strat->pairtest!=NULL)
3226 {
3227#ifdef HAVE_SHIFTBBA
3228 // only difference is pLPDivisibleBy instead of pDivisibleBy
3229 if (rIsLPRing(currRing))
3230 {
3231 for (j=0; j<=strat->sl; j++)
3232 {
3233 if (strat->pairtest[j])
3234 {
3235 for (i=strat->Bl; i>=0; i--)
3236 {
3237 if (pLPDivisibleBy(strat->S[j],strat->B[i].lcm))
3238 {
3239 deleteInL(strat->B,&strat->Bl,i,strat);
3240 strat->c3++;
3241 }
3242 }
3243 }
3244 }
3245 }
3246 else
3247#endif
3248 {
3249 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3250 for (j=0; j<=strat->sl; j++)
3251 {
3252 if (strat->pairtest[j])
3253 {
3254 for (i=strat->Bl; i>=0; i--)
3255 {
3256 if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3257 {
3258 deleteInL(strat->B,&strat->Bl,i,strat);
3259 strat->c3++;
3260 }
3261 }
3262 }
3263 }
3264 }
3265 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3266 strat->pairtest=NULL;
3267 }
3268 if (strat->Gebauer || strat->fromT)
3269 {
3270 if (strat->sugarCrit)
3271 {
3272 /*
3273 *suppose L[j] == (s,r) and p/lcm(s,r)
3274 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3275 *and in case the sugar is o.k. then L[j] can be canceled
3276 */
3277 for (j=strat->Ll; j>=0; j--)
3278 {
3279 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3280 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3281 && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3282 {
3283 if (strat->L[j].p == strat->tail)
3284 {
3285 deleteInL(strat->L,&strat->Ll,j,strat);
3286 strat->c3++;
3287 }
3288 }
3289 }
3290 /*
3291 *this is GEBAUER-MOELLER:
3292 *in B all elements with the same lcm except the "best"
3293 *(i.e. the last one in B with this property) will be canceled
3294 */
3295 j = strat->Bl;
3296 loop /*cannot be changed into a for !!! */
3297 {
3298 if (j <= 0) break;
3299 i = j-1;
3300 loop
3301 {
3302 if (i < 0) break;
3303 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3304 {
3305 strat->c3++;
3306 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3307 {
3308 deleteInL(strat->B,&strat->Bl,i,strat);
3309 j--;
3310 }
3311 else
3312 {
3313 deleteInL(strat->B,&strat->Bl,j,strat);
3314 break;
3315 }
3316 }
3317 i--;
3318 }
3319 j--;
3320 }
3321 }
3322 else /*sugarCrit*/
3323 {
3324 /*
3325 *suppose L[j] == (s,r) and p/lcm(s,r)
3326 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3327 *and in case the sugar is o.k. then L[j] can be canceled
3328 */
3329 for (j=strat->Ll; j>=0; j--)
3330 {
3331 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3332 {
3333 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3334 {
3335 deleteInL(strat->L,&strat->Ll,j,strat);
3336 strat->c3++;
3337 }
3338 }
3339 }
3340 /*
3341 *this is GEBAUER-MOELLER:
3342 *in B all elements with the same lcm except the "best"
3343 *(i.e. the last one in B with this property) will be canceled
3344 */
3345 j = strat->Bl;
3346 loop /*cannot be changed into a for !!! */
3347 {
3348 if (j <= 0) break;
3349 for(i=j-1; i>=0; i--)
3350 {
3351 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3352 {
3353 strat->c3++;
3354 deleteInL(strat->B,&strat->Bl,i,strat);
3355 j--;
3356 }
3357 }
3358 j--;
3359 }
3360 }
3361 /*
3362 *the elements of B enter L
3363 */
3364 kMergeBintoL(strat);
3365 }
3366 else
3367 {
3368 for (j=strat->Ll; j>=0; j--)
3369 {
3370 #ifdef HAVE_SHIFTBBA
3371 if ((strat->L[j].p1!=NULL) &&
3372 pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3373 #else
3374 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3375 #endif
3376 {
3377 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3378 {
3379 deleteInL(strat->L,&strat->Ll,j,strat);
3380 strat->c3++;
3381 }
3382 }
3383 }
3384 /*
3385 *this is our MODIFICATION of GEBAUER-MOELLER:
3386 *First the elements of B enter L,
3387 *then we fix a lcm and the "best" element in L
3388 *(i.e the last in L with this lcm and of type (s,p))
3389 *and cancel all the other elements of type (r,p) with this lcm
3390 *except the case the element (s,r) has also the same lcm
3391 *and is on the worst position with respect to (s,p) and (r,p)
3392 */
3393 /*
3394 *B enters to L/their order with respect to B is permutated for elements
3395 *B[i].p with the same leading term
3396 */
3397 kMergeBintoL(strat);
3398 j = strat->Ll;
3399 loop /*cannot be changed into a for !!! */
3400 {
3401 if (j <= 0)
3402 {
3403 /*now L[0] cannot be canceled any more and the tail can be removed*/
3404 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3405 break;
3406 }
3407 if (strat->L[j].p2 == p)
3408 {
3409 i = j-1;
3410 loop
3411 {
3412 if (i < 0) break;
3413 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3414 {
3415 /*L[i] could be canceled but we search for a better one to cancel*/
3416 strat->c3++;
3417 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3418 && (pNext(strat->L[l].p) == strat->tail)
3419 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3420 && pDivisibleBy(p,strat->L[l].lcm))
3421 {
3422 /*
3423 *"NOT equal(...)" because in case of "equal" the element L[l]
3424 *is "older" and has to be from theoretical point of view behind
3425 *L[i], but we do not want to reorder L
3426 */
3427 strat->L[i].p2 = strat->tail;
3428 /*
3429 *L[l] will be canceled, we cannot cancel L[i] later on,
3430 *so we mark it with "tail"
3431 */
3432 deleteInL(strat->L,&strat->Ll,l,strat);
3433 i--;
3434 }
3435 else
3436 {
3437 deleteInL(strat->L,&strat->Ll,i,strat);
3438 }
3439 j--;
3440 }
3441 i--;
3442 }
3443 }
3444 else if (strat->L[j].p2 == strat->tail)
3445 {
3446 /*now L[j] cannot be canceled any more and the tail can be removed*/
3447 strat->L[j].p2 = p;
3448 }
3449 j--;
3450 }
3451 }
3452}
3453/*2
3454*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3455*without the chain-criterion in B and L and enters B to L
3456*/
3457void chainCritOpt_1 (poly,int,kStrategy strat)
3458{
3459 if (strat->pairtest!=NULL)
3460 {
3461 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3462 strat->pairtest=NULL;
3463 }
3464 /*
3465 *the elements of B enter L
3466 */
3467 kMergeBintoL(strat);
3468}
3469/*2
3470*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3471*using the chain-criterion in B and L and enters B to L
3472*/
3473void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3474{
3475 int i,j,l;
3476 kMergeBintoLSba(strat);
3477 j = strat->Ll;
3478 loop /*cannot be changed into a for !!! */
3479 {
3480 if (j <= 0)
3481 {
3482 /*now L[0] cannot be canceled any more and the tail can be removed*/
3483 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3484 break;
3485 }
3486 if (strat->L[j].p2 == p)
3487 {
3488 i = j-1;
3489 loop
3490 {
3491 if (i < 0) break;
3492 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3493 {
3494 /*L[i] could be canceled but we search for a better one to cancel*/
3495 strat->c3++;
3496 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3497 && (pNext(strat->L[l].p) == strat->tail)
3498 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3499 && pDivisibleBy(p,strat->L[l].lcm))
3500 {
3501 /*
3502 *"NOT equal(...)" because in case of "equal" the element L[l]
3503 *is "older" and has to be from theoretical point of view behind
3504 *L[i], but we do not want to reorder L
3505 */
3506 strat->L[i].p2 = strat->tail;
3507 /*
3508 *L[l] will be canceled, we cannot cancel L[i] later on,
3509 *so we mark it with "tail"
3510 */
3511 deleteInL(strat->L,&strat->Ll,l,strat);
3512 i--;
3513 }
3514 else
3515 {
3516 deleteInL(strat->L,&strat->Ll,i,strat);
3517 }
3518 j--;
3519 }
3520 i--;
3521 }
3522 }
3523 else if (strat->L[j].p2 == strat->tail)
3524 {
3525 /*now L[j] cannot be canceled any more and the tail can be removed*/
3526 strat->L[j].p2 = p;
3527 }
3528 j--;
3529 }
3530}
3531#ifdef HAVE_RATGRING
3532void chainCritPart (poly p,int ecart,kStrategy strat)
3533{
3534 int i,j,l;
3535
3536 /*
3537 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3538 *In this case all elements in B such
3539 *that their lcm is divisible by the leading term of S[i] can be canceled
3540 */
3541 if (strat->pairtest!=NULL)
3542 {
3543 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3544 for (j=0; j<=strat->sl; j++)
3545 {
3546 if (strat->pairtest[j])
3547 {
3548 for (i=strat->Bl; i>=0; i--)
3549 {
3550 if (_p_LmDivisibleByPart(strat->S[j],currRing,
3551 strat->B[i].lcm,currRing,
3552 currRing->real_var_start,currRing->real_var_end))
3553 {
3554 if(TEST_OPT_DEBUG)
3555 {
3556 Print("chain-crit-part: S[%d]=",j);
3557 p_wrp(strat->S[j],currRing);
3558 Print(" divide B[%d].lcm=",i);
3559 p_wrp(strat->B[i].lcm,currRing);
3560 PrintLn();
3561 }
3562 deleteInL(strat->B,&strat->Bl,i,strat);
3563 strat->c3++;
3564 }
3565 }
3566 }
3567 }
3568 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3569 strat->pairtest=NULL;
3570 }
3571 if (strat->Gebauer || strat->fromT)
3572 {
3573 if (strat->sugarCrit)
3574 {
3575 /*
3576 *suppose L[j] == (s,r) and p/lcm(s,r)
3577 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3578 *and in case the sugar is o.k. then L[j] can be canceled
3579 */
3580 for (j=strat->Ll; j>=0; j--)
3581 {
3582 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3583 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3584 && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3585 {
3586 if (strat->L[j].p == strat->tail)
3587 {
3588 if(TEST_OPT_DEBUG)
3589 {
3590 PrintS("chain-crit-part: pCompareChainPart p=");
3591 p_wrp(p,currRing);
3592 Print(" delete L[%d]",j);
3593 p_wrp(strat->L[j].lcm,currRing);
3594 PrintLn();
3595 }
3596 deleteInL(strat->L,&strat->Ll,j,strat);
3597 strat->c3++;
3598 }
3599 }
3600 }
3601 /*
3602 *this is GEBAUER-MOELLER:
3603 *in B all elements with the same lcm except the "best"
3604 *(i.e. the last one in B with this property) will be canceled
3605 */
3606 j = strat->Bl;
3607 loop /*cannot be changed into a for !!! */
3608 {
3609 if (j <= 0) break;
3610 i = j-1;
3611 loop
3612 {
3613 if (i < 0) break;
3614 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3615 {
3616 strat->c3++;
3617 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3618 {
3619 if(TEST_OPT_DEBUG)
3620 {
3621 Print("chain-crit-part: sugar B[%d].lcm=",j);
3622 p_wrp(strat->B[j].lcm,currRing);
3623 Print(" delete B[%d]",i);
3624 p_wrp(strat->B[i].lcm,currRing);
3625 PrintLn();
3626 }
3627 deleteInL(strat->B,&strat->Bl,i,strat);
3628 j--;
3629 }
3630 else
3631 {
3632 if(TEST_OPT_DEBUG)
3633 {
3634 Print("chain-crit-part: sugar B[%d].lcm=",i);
3635 p_wrp(strat->B[i].lcm,currRing);
3636 Print(" delete B[%d]",j);
3637 p_wrp(strat->B[j].lcm,currRing);
3638 PrintLn();
3639 }
3640 deleteInL(strat->B,&strat->Bl,j,strat);
3641 break;
3642 }
3643 }
3644 i--;
3645 }
3646 j--;
3647 }
3648 }
3649 else /*sugarCrit*/
3650 {
3651 /*
3652 *suppose L[j] == (s,r) and p/lcm(s,r)
3653 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3654 *and in case the sugar is o.k. then L[j] can be canceled
3655 */
3656 for (j=strat->Ll; j>=0; j--)
3657 {
3658 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3659 {
3660 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3661 {
3662 if(TEST_OPT_DEBUG)
3663 {
3664 PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3665 p_wrp(p,currRing);
3666 Print(" delete L[%d]",j);
3667 p_wrp(strat->L[j].lcm,currRing);
3668 PrintLn();
3669 }
3670 deleteInL(strat->L,&strat->Ll,j,strat);
3671 strat->c3++;
3672 }
3673 }
3674 }
3675 /*
3676 *this is GEBAUER-MOELLER:
3677 *in B all elements with the same lcm except the "best"
3678 *(i.e. the last one in B with this property) will be canceled
3679 */
3680 j = strat->Bl;
3681 loop /*cannot be changed into a for !!! */
3682 {
3683 if (j <= 0) break;
3684 for(i=j-1; i>=0; i--)
3685 {
3686 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3687 {
3688 if(TEST_OPT_DEBUG)
3689 {
3690 Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3691 p_wrp(strat->B[j].lcm,currRing);
3692 Print(" delete B[%d]\n",i);
3693 }
3694 strat->c3++;
3695 deleteInL(strat->B,&strat->Bl,i,strat);
3696 j--;
3697 }
3698 }
3699 j--;
3700 }
3701 }
3702 /*
3703 *the elements of B enter L
3704 */
3705 kMergeBintoL(strat);
3706 }
3707 else
3708 {
3709 for (j=strat->Ll; j>=0; j--)
3710 {
3711 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3712 {
3713 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3714 {
3715 if(TEST_OPT_DEBUG)
3716 {
3717 PrintS("chain-crit-part: pCompareChainPart p=");
3718 p_wrp(p,currRing);
3719 Print(" delete L[%d]",j);
3720 p_wrp(strat->L[j].lcm,currRing);
3721 PrintLn();
3722 }
3723 deleteInL(strat->L,&strat->Ll,j,strat);
3724 strat->c3++;
3725 }
3726 }
3727 }
3728 /*
3729 *this is our MODIFICATION of GEBAUER-MOELLER:
3730 *First the elements of B enter L,
3731 *then we fix a lcm and the "best" element in L
3732 *(i.e the last in L with this lcm and of type (s,p))
3733 *and cancel all the other elements of type (r,p) with this lcm
3734 *except the case the element (s,r) has also the same lcm
3735 *and is on the worst position with respect to (s,p) and (r,p)
3736 */
3737 /*
3738 *B enters to L/their order with respect to B is permutated for elements
3739 *B[i].p with the same leading term
3740 */
3741 kMergeBintoL(strat);
3742 j = strat->Ll;
3743 loop /*cannot be changed into a for !!! */
3744 {
3745 if (j <= 0)
3746 {
3747 /*now L[0] cannot be canceled any more and the tail can be removed*/
3748 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3749 break;
3750 }
3751 if (strat->L[j].p2 == p)
3752 {
3753 i = j-1;
3754 loop
3755 {
3756 if (i < 0) break;
3757 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3758 {
3759 /*L[i] could be canceled but we search for a better one to cancel*/
3760 strat->c3++;
3761 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3762 && (pNext(strat->L[l].p) == strat->tail)
3763 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3765 strat->L[l].lcm,currRing,
3766 currRing->real_var_start, currRing->real_var_end))
3767
3768 {
3769 /*
3770 *"NOT equal(...)" because in case of "equal" the element L[l]
3771 *is "older" and has to be from theoretical point of view behind
3772 *L[i], but we do not want to reorder L
3773 */
3774 strat->L[i].p2 = strat->tail;
3775 /*
3776 *L[l] will be canceled, we cannot cancel L[i] later on,
3777 *so we mark it with "tail"
3778 */
3779 if(TEST_OPT_DEBUG)
3780 {
3781 PrintS("chain-crit-part: divisible_by p=");
3782 p_wrp(p,currRing);
3783 Print(" delete L[%d]",l);
3784 p_wrp(strat->L[l].lcm,currRing);
3785 PrintLn();
3786 }
3787 deleteInL(strat->L,&strat->Ll,l,strat);
3788 i--;
3789 }
3790 else
3791 {
3792 if(TEST_OPT_DEBUG)
3793 {
3794 PrintS("chain-crit-part: divisible_by(2) p=");
3795 p_wrp(p,currRing);
3796 Print(" delete L[%d]",i);
3797 p_wrp(strat->L[i].lcm,currRing);
3798 PrintLn();
3799 }
3800 deleteInL(strat->L,&strat->Ll,i,strat);
3801 }
3802 j--;
3803 }
3804 i--;
3805 }
3806 }
3807 else if (strat->L[j].p2 == strat->tail)
3808 {
3809 /*now L[j] cannot be canceled any more and the tail can be removed*/
3810 strat->L[j].p2 = p;
3811 }
3812 j--;
3813 }
3814 }
3815}
3816#endif
3817
3818/*2
3819*(s[0],h),...,(s[k],h) will be put to the pairset L
3820*/
3821void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR/* = -1*/)
3822{
3823
3824 if ((strat->syzComp==0)
3825 || (pGetComp(h)<=strat->syzComp))
3826 {
3827 int j;
3829
3830 if (pGetComp(h)==0)
3831 {
3832 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3833 if ((isFromQ)&&(strat->fromQ!=NULL))
3834 {
3835 for (j=0; j<=k; j++)
3836 {
3837 if (!strat->fromQ[j])
3838 {
3839 new_pair=TRUE;
3840 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3841 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3842 }
3843 }
3844 }
3845 else
3846 {
3847 new_pair=TRUE;
3848 for (j=0; j<=k; j++)
3849 {
3850 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3851 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3852 }
3853 }
3854 }
3855 else
3856 {
3857 for (j=0; j<=k; j++)
3858 {
3859 if ((pGetComp(h)==pGetComp(strat->S[j]))
3860 || (pGetComp(strat->S[j])==0))
3861 {
3862 new_pair=TRUE;
3863 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3864 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3865 }
3866 }
3867 }
3868 if (new_pair)
3869 {
3870 #ifdef HAVE_RATGRING
3871 if (currRing->real_var_start>0)
3872 chainCritPart(h,ecart,strat);
3873 else
3874 #endif
3875 strat->chainCrit(h,ecart,strat);
3876 }
3877 kMergeBintoL(strat);
3878 }
3879}
3880
3881/*2
3882*(s[0],h),...,(s[k],h) will be put to the pairset L
3883*using signatures <= only for signature-based standard basis algorithms
3884*/
3885
3886void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3887{
3888
3889 if ((strat->syzComp==0)
3890 || (pGetComp(h)<=strat->syzComp))
3891 {
3892 int j;
3894
3895 if (pGetComp(h)==0)
3896 {
3897 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3898 if ((isFromQ)&&(strat->fromQ!=NULL))
3899 {
3900 for (j=0; j<=k; j++)
3901 {
3902 if (!strat->fromQ[j])
3903 {
3904 new_pair=TRUE;
3905 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3906 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3907 }
3908 }
3909 }
3910 else
3911 {
3912 new_pair=TRUE;
3913 for (j=0; j<=k; j++)
3914 {
3915 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3916 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3917 }
3918 }
3919 }
3920 else
3921 {
3922 for (j=0; j<=k; j++)
3923 {
3924 if ((pGetComp(h)==pGetComp(strat->S[j]))
3925 || (pGetComp(strat->S[j])==0))
3926 {
3927 new_pair=TRUE;
3928 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3929 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3930 }
3931 }
3932 }
3933
3934 if (new_pair)
3935 {
3936#ifdef HAVE_RATGRING
3937 if (currRing->real_var_start>0)
3938 chainCritPart(h,ecart,strat);
3939 else
3940#endif
3941 strat->chainCrit(h,ecart,strat);
3942 }
3943 }
3944}
3945
3946void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3947{
3948
3949 if ((strat->syzComp==0)
3950 || (pGetComp(h)<=strat->syzComp))
3951 {
3952 int j;
3953
3954 if (pGetComp(h)==0)
3955 {
3956 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3957 if ((isFromQ)&&(strat->fromQ!=NULL))
3958 {
3959 for (j=0; j<=k && !strat->sigdrop; j++)
3960 {
3961 if (!strat->fromQ[j])
3962 {
3963 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3964 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3965 }
3966 }
3967 }
3968 else
3969 {
3970 for (j=0; j<=k && !strat->sigdrop; j++)
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 else
3978 {
3979 for (j=0; j<=k && !strat->sigdrop; j++)
3980 {
3981 if ((pGetComp(h)==pGetComp(strat->S[j]))
3982 || (pGetComp(strat->S[j])==0))
3983 {
3984 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3985 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3986 }
3987 }
3988 }
3989
3990#if 0
3991 if (new_pair)
3992 {
3993#ifdef HAVE_RATGRING
3994 if (currRing->real_var_start>0)
3995 chainCritPart(h,ecart,strat);
3996 else
3997#endif
3998 strat->chainCrit(h,ecart,strat);
3999 }
4000#endif
4001 }
4002}
4003#ifdef HAVE_RINGS
4004/*2
4005*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
4006*using the chain-criterion in B and L and enters B to L
4007*/
4008void chainCritRing (poly p,int, kStrategy strat)
4009{
4010 int i,j,l;
4011 /*
4012 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4013 *In this case all elements in B such
4014 *that their lcm is divisible by the leading term of S[i] can be canceled
4015 */
4016 if (strat->pairtest!=NULL)
4017 {
4018 {
4019 /*- i.e. there is an i with pairtest[i]==TRUE -*/
4020 for (j=0; j<=strat->sl; j++)
4021 {
4022 if (strat->pairtest[j])
4023 {
4024 for (i=strat->Bl; i>=0; i--)
4025 {
4026 if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4027 {
4028#ifdef KDEBUG
4029 if (TEST_OPT_DEBUG)
4030 {
4031 PrintS("--- chain criterion func chainCritRing type 1\n");
4032 PrintS("strat->S[j]:");
4033 wrp(strat->S[j]);
4034 PrintS(" strat->B[i].lcm:");
4035 wrp(strat->B[i].lcm);PrintLn();
4036 pWrite(strat->B[i].p);
4037 pWrite(strat->B[i].p1);
4038 pWrite(strat->B[i].p2);
4039 wrp(strat->B[i].lcm);
4040 PrintLn();
4041 }
4042#endif
4043 deleteInL(strat->B,&strat->Bl,i,strat);
4044 strat->c3++;
4045 }
4046 }
4047 }
4048 }
4049 }
4050 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4051 strat->pairtest=NULL;
4052 }
4053 assume(!(strat->Gebauer || strat->fromT));
4054 for (j=strat->Ll; j>=0; j--)
4055 {
4056 if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4057 {
4058 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4059 {
4060 if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4061 {
4062 deleteInL(strat->L,&strat->Ll,j,strat);
4063 strat->c3++;
4064#ifdef KDEBUG
4065 if (TEST_OPT_DEBUG)
4066 {
4067 PrintS("--- chain criterion func chainCritRing type 2\n");
4068 PrintS("strat->L[j].p:");
4069 wrp(strat->L[j].p);
4070 PrintS(" p:");
4071 wrp(p);
4072 PrintLn();
4073 }
4074#endif
4075 }
4076 }
4077 }
4078 }
4079 /*
4080 *this is our MODIFICATION of GEBAUER-MOELLER:
4081 *First the elements of B enter L,
4082 *then we fix a lcm and the "best" element in L
4083 *(i.e the last in L with this lcm and of type (s,p))
4084 *and cancel all the other elements of type (r,p) with this lcm
4085 *except the case the element (s,r) has also the same lcm
4086 *and is on the worst position with respect to (s,p) and (r,p)
4087 */
4088 /*
4089 *B enters to L/their order with respect to B is permutated for elements
4090 *B[i].p with the same leading term
4091 */
4092 kMergeBintoL(strat);
4093 j = strat->Ll;
4094 loop /*cannot be changed into a for !!! */
4095 {
4096 if (j <= 0)
4097 {
4098 /*now L[0] cannot be canceled any more and the tail can be removed*/
4099 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4100 break;
4101 }
4102 if (strat->L[j].p2 == p) // Was the element added from B?
4103 {
4104 i = j-1;
4105 loop
4106 {
4107 if (i < 0) break;
4108 // Element is from B and has the same lcm as L[j]
4109 if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4110 && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4111 {
4112 /*L[i] could be canceled but we search for a better one to cancel*/
4113 strat->c3++;
4114#ifdef KDEBUG
4115 if (TEST_OPT_DEBUG)
4116 {
4117 PrintS("--- chain criterion func chainCritRing type 3\n");
4118 PrintS("strat->L[j].lcm:");
4119 wrp(strat->L[j].lcm);
4120 PrintS(" strat->L[i].lcm:");
4121 wrp(strat->L[i].lcm);
4122 PrintLn();
4123 }
4124#endif
4125 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4126 && (pNext(strat->L[l].p) == strat->tail)
4127 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4128 && pDivisibleBy(p,strat->L[l].lcm))
4129 {
4130 /*
4131 *"NOT equal(...)" because in case of "equal" the element L[l]
4132 *is "older" and has to be from theoretical point of view behind
4133 *L[i], but we do not want to reorder L
4134 */
4135 strat->L[i].p2 = strat->tail;
4136 /*
4137 *L[l] will be canceled, we cannot cancel L[i] later on,
4138 *so we mark it with "tail"
4139 */
4140 deleteInL(strat->L,&strat->Ll,l,strat);
4141 i--;
4142 }
4143 else
4144 {
4145 deleteInL(strat->L,&strat->Ll,i,strat);
4146 }
4147 j--;
4148 }
4149 i--;
4150 }
4151 }
4152 else if (strat->L[j].p2 == strat->tail)
4153 {
4154 /*now L[j] cannot be canceled any more and the tail can be removed*/
4155 strat->L[j].p2 = p;
4156 }
4157 j--;
4158 }
4159}
4160#endif
4161
4162#ifdef HAVE_RINGS
4163/*2
4164*(s[0],h),...,(s[k],h) will be put to the pairset L
4165*/
4166void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4167{
4168 if (!nIsOne(pGetCoeff(h)))
4169 {
4170 int j;
4172
4173 if (pGetComp(h)==0)
4174 {
4175 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4176 if ((isFromQ)&&(strat->fromQ!=NULL))
4177 {
4178 for (j=0; j<=k; j++)
4179 {
4180 if (!strat->fromQ[j])
4181 {
4182 new_pair=TRUE;
4183 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4184 }
4185 }
4186 }
4187 else
4188 {
4189 new_pair=TRUE;
4190 for (j=0; j<=k; j++)
4191 {
4192 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4193 }
4194 }
4195 }
4196 else
4197 {
4198 for (j=0; j<=k; j++)
4199 {
4200 if ((pGetComp(h)==pGetComp(strat->S[j]))
4201 || (pGetComp(strat->S[j])==0))
4202 {
4203 new_pair=TRUE;
4204 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4205 }
4206 }
4207 }
4208 if (new_pair)
4209 {
4210 #ifdef HAVE_RATGRING
4211 if (currRing->real_var_start>0)
4212 chainCritPart(h,ecart,strat);
4213 else
4214 #endif
4215 strat->chainCrit(h,ecart,strat);
4216 }
4217 kMergeBintoL(strat);
4218 }
4219}
4220
4221static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4222{
4223 const int iCompH = pGetComp(h);
4224 if (!nIsOne(pGetCoeff(h)))
4225 {
4226 int j;
4227
4228 for (j=0; j<=k && !strat->sigdrop; j++)
4229 {
4230 // Print("j:%d, Ll:%d\n",j,strat->Ll);
4231// if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4232// ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4233 if (((iCompH == pGetComp(strat->S[j]))
4234 || (0 == pGetComp(strat->S[j])))
4235 && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4236 {
4237 enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4238 }
4239 }
4240 }
4241}
4242#endif
4243
4244#ifdef HAVE_RINGS
4245/*2
4246* Generates spoly(0, h) if applicable. Assumes ring has zero divisors
4247*/
4249{
4250 if (nIsOne(pGetCoeff(h))) return;
4251 number gcd;
4252 number zero=n_Init(0,currRing->cf);
4253 bool go = false;
4254 if (n_DivBy(zero, pGetCoeff(h), currRing->cf))
4255 {
4256 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4257 go = true;
4258 }
4259 else
4260 gcd = n_Gcd(zero, pGetCoeff(h), strat->tailRing->cf);
4261 if (go || !nIsOne(gcd))
4262 {
4263 poly p = h->next;
4264 if (!go)
4265 {
4266 number tmp = gcd;
4267 gcd = n_Ann(gcd,currRing->cf);
4268 nDelete(&tmp);
4269 }
4270 p_Test(p,strat->tailRing);
4271 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4272
4273 if (p != NULL)
4274 {
4275 if (TEST_OPT_PROT)
4276 {
4277 PrintS("Z");
4278 }
4279#ifdef KDEBUG
4280 if (TEST_OPT_DEBUG)
4281 {
4282 PrintS("--- create zero spoly: ");
4283 p_wrp(h,currRing,strat->tailRing);
4284 PrintS(" ---> ");
4285 }
4286#endif
4287 poly tmp = pInit();
4289 for (int i = 1; i <= rVar(currRing); i++)
4290 {
4291 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4292 }
4294 {
4296 }
4298 p = p_LmFreeAndNext(p, strat->tailRing);
4299 pNext(tmp) = p;
4300 LObject Lp;
4301 Lp.Init();
4302 Lp.p = tmp;
4303 Lp.tailRing = strat->tailRing;
4304 int posx;
4305 if (Lp.p!=NULL)
4306 {
4307 strat->initEcart(&Lp);
4308 if (strat->Ll==-1)
4309 posx =0;
4310 else
4311 posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4312 Lp.sev = pGetShortExpVector(Lp.p);
4313 if (strat->tailRing != currRing)
4314 {
4315 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4316 }
4317#ifdef KDEBUG
4318 if (TEST_OPT_DEBUG)
4319 {
4320 p_wrp(tmp,currRing,strat->tailRing);
4321 PrintLn();
4322 }
4323#endif
4324 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4325 }
4326 }
4327 }
4328 nDelete(&zero);
4329 nDelete(&gcd);
4330}
4331
4333{
4334 if (nIsOne(pGetCoeff(h))) return;
4335 number gcd;
4336 number zero=n_Init(0,currRing->cf);
4337 bool go = false;
4338 if (n_DivBy(zero, pGetCoeff(h), currRing->cf))
4339 {
4340 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4341 go = true;
4342 }
4343 else
4344 gcd = n_Gcd(zero, pGetCoeff(h), strat->tailRing->cf);
4345 if (go || !nIsOne(gcd))
4346 {
4347 poly p = h->next;
4348 if (!go)
4349 {
4350 number tmp = gcd;
4351 gcd = n_Ann(gcd,currRing->cf);
4352 nDelete(&tmp);
4353 }
4354 p_Test(p,strat->tailRing);
4355 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4356
4357 if (p != NULL)
4358 {
4359 if (TEST_OPT_PROT)
4360 {
4361 PrintS("Z");
4362 }
4363#ifdef KDEBUG
4364 if (TEST_OPT_DEBUG)
4365 {
4366 PrintS("--- create zero spoly: ");
4367 p_wrp(h,currRing,strat->tailRing);
4368 PrintS(" ---> ");
4369 }
4370#endif
4371 poly tmp = pInit();
4373 for (int i = 1; i <= rVar(currRing); i++)
4374 {
4375 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4376 }
4378 {
4380 }
4382 p = p_LmFreeAndNext(p, strat->tailRing);
4383 pNext(tmp) = p;
4384 LObject Lp;
4385 Lp.Init();
4386 Lp.p = tmp;
4387 //printf("\nOld\n");pWrite(h);pWrite(hSig);
4388 #if EXT_POLY_NEW
4389 Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4390 if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4391 {
4392 strat->sigdrop = TRUE;
4393 //Try to reduce it as far as we can via redRing
4394 int red_result = redRing(&Lp,strat);
4395 if(red_result == 0)
4396 {
4397 // Cancel the sigdrop
4398 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4399 strat->sigdrop = FALSE;
4400 }
4401 else
4402 {
4403 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4404 #if 1
4405 strat->enterS(Lp,0,strat,strat->tl);
4406 #endif
4407 }
4408 nDelete(&zero);
4409 nDelete(&gcd);
4410 return;
4411 }
4412 #else
4413 Lp.sig = pOne();
4414 if(strat->Ll >= 0)
4415 p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4416 else
4418 #endif
4419 Lp.tailRing = strat->tailRing;
4420 int posx;
4421 if (Lp.p!=NULL)
4422 {
4423 strat->initEcart(&Lp);
4424 if (strat->Ll==-1)
4425 posx =0;
4426 else
4427 posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4428 Lp.sev = pGetShortExpVector(Lp.p);
4429 if (strat->tailRing != currRing)
4430 {
4431 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4432 }
4433#ifdef KDEBUG
4434 if (TEST_OPT_DEBUG)
4435 {
4436 p_wrp(tmp,currRing,strat->tailRing);
4437 PrintLn();
4438 }
4439#endif
4440 //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4441 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4442 }
4443 }
4444 }
4445 nDelete(&gcd);
4446 nDelete(&zero);
4447}
4448#endif
4449
4450#ifdef HAVE_RINGS
4451void clearSbatch (poly h,int k,int pos,kStrategy strat)
4452{
4453 int j = pos;
4454 if ( (!strat->fromT)
4455 && ((strat->syzComp==0)
4456 ||(pGetComp(h)<=strat->syzComp)
4457 ))
4458 {
4459 // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4460 unsigned long h_sev = pGetShortExpVector(h);
4461 loop
4462 {
4463 if (j > k) break;
4464 clearS(h,h_sev, &j,&k,strat);
4465 j++;
4466 }
4467 // Print("end clearS sl=%d\n",strat->sl);
4468 }
4469}
4470#endif
4471
4472#ifdef HAVE_RINGS
4473/*2
4474* Generates a sufficient set of spolys (maybe just a finite generating
4475* set of the syzygys)
4476*/
4477void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4478{
4480#if HAVE_SHIFTBBA
4481 assume(!rIsLPRing(currRing)); /* LP should use enterpairsShift */
4482#endif
4483 // enter also zero divisor * poly, if this is non zero and of smaller degree
4485 initenterstrongPairs(h, k, ecart, 0, strat, atR);
4486 initenterpairs(h, k, ecart, 0, strat, atR);
4487 clearSbatch(h, k, pos, strat);
4488}
4489
4490void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4491{
4493 // enter also zero divisor * poly, if this is non zero and of smaller degree
4495 if(strat->sigdrop) return;
4496 initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4497 if(strat->sigdrop) return;
4498 initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4499 if(strat->sigdrop) return;
4500 clearSbatch(h, k, pos, strat);
4501}
4502#endif
4503
4504/*2
4505*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4506*superfluous elements in S will be deleted
4507*/
4508void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4509{
4510 int j=pos;
4511
4513 initenterpairs(h,k,ecart,0,strat, atR);
4514 if ( (!strat->fromT)
4515 && ((strat->syzComp==0)
4516 ||(pGetComp(h)<=strat->syzComp)))
4517 {
4518 unsigned long h_sev = pGetShortExpVector(h);
4519 loop
4520 {
4521 if (j > k) break;
4522 clearS(h,h_sev, &j,&k,strat);
4523 j++;
4524 }
4525 }
4526}
4527
4528/*2
4529*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4530*superfluous elements in S will be deleted
4531*this is a special variant of signature-based algorithms including the
4532*signatures for criteria checks
4533*/
4534void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4535{
4536 int j=pos;
4538 initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4539 if ( (!strat->fromT)
4540 && ((strat->syzComp==0)
4541 ||(pGetComp(h)<=strat->syzComp)))
4542 {
4543 unsigned long h_sev = pGetShortExpVector(h);
4544 loop
4545 {
4546 if (j > k) break;
4547 clearS(h,h_sev, &j,&k,strat);
4548 j++;
4549 }
4550 }
4551}
4552
4553/*2
4554*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4555*superfluous elements in S will be deleted
4556*/
4557void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4558{
4559 int j;
4560 const int iCompH = pGetComp(h);
4561
4563 {
4564 for (j=0; j<=k; j++)
4565 {
4566 const int iCompSj = pGetComp(strat->S[j]);
4567 if ((iCompH==iCompSj)
4568 //|| (0==iCompH) // can only happen,if iCompSj==0
4569 || (0==iCompSj))
4570 {
4571 enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4572 }
4573 }
4574 kMergeBintoL(strat);
4575 }
4576 else
4577 {
4578 for (j=0; j<=k; j++)
4579 {
4580 const int iCompSj = pGetComp(strat->S[j]);
4581 if ((iCompH==iCompSj)
4582 //|| (0==iCompH) // can only happen,if iCompSj==0
4583 || (0==iCompSj))
4584 {
4585 enterOnePairSpecial(j,h,ecart,strat, atR);
4586 }
4587 }
4588 }
4589
4590 if (strat->noClearS) return;
4591
4592// #ifdef HAVE_PLURAL
4593/*
4594 if (rIsPluralRing(currRing))
4595 {
4596 j=pos;
4597 loop
4598 {
4599 if (j > k) break;
4600
4601 if (pLmDivisibleBy(h, strat->S[j]))
4602 {
4603 deleteInS(j, strat);
4604 j--;
4605 k--;
4606 }
4607
4608 j++;
4609 }
4610 }
4611 else
4612*/
4613// #endif // ??? Why was the following cancellation disabled for non-commutative rings?
4614 {
4615 j=pos;
4616 loop
4617 {
4618 unsigned long h_sev = pGetShortExpVector(h);
4619 if (j > k) break;
4620 clearS(h,h_sev,&j,&k,strat);
4621 j++;
4622 }
4623 }
4624}
4625
4626/*2
4627*reorders s with respect to posInS,
4628*suc is the first changed index or zero
4629*/
4630
4631void reorderS (int* suc,kStrategy strat)
4632{
4633 int i,j,at,ecart, s2r;
4634 int fq=0;
4635 unsigned long sev;
4636 poly p;
4637 int new_suc=strat->sl+1;
4638 i= *suc;
4639 if (i<0) i=0;
4640
4641 for (; i<=strat->sl; i++)
4642 {
4643 at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4644 if (at != i)
4645 {
4646 if (new_suc > at) new_suc = at;
4647 p = strat->S[i];
4648 ecart = strat->ecartS[i];
4649 sev = strat->sevS[i];
4650 s2r = strat->S_2_R[i];
4651 if (strat->fromQ!=NULL) fq=strat->fromQ[i];
4652 for (j=i; j>=at+1; j--)
4653 {
4654 strat->S[j] = strat->S[j-1];
4655 strat->ecartS[j] = strat->ecartS[j-1];
4656 strat->sevS[j] = strat->sevS[j-1];
4657 strat->S_2_R[j] = strat->S_2_R[j-1];
4658 }
4659 strat->S[at] = p;
4660 strat->ecartS[at] = ecart;
4661 strat->sevS[at] = sev;
4662 strat->S_2_R[at] = s2r;
4663 if (strat->fromQ!=NULL)
4664 {
4665 for (j=i; j>=at+1; j--)
4666 {
4667 strat->fromQ[j] = strat->fromQ[j-1];
4668 }
4669 strat->fromQ[at]=fq;
4670 }
4671 }
4672 }
4674 else *suc=-1;
4675}
4676
4677
4678/*2
4679*looks up the position of p in set
4680*set[0] is the smallest with respect to the ordering-procedure deg/pComp
4681* Assumption: posInS only depends on the leading term
4682* otherwise, bba has to be changed
4683*/
4684int posInS (const kStrategy strat, const int length,const poly p,
4685 const int ecart_p)
4686{
4687 if(length==-1) return 0;
4688 polyset set=strat->S;
4689 int i;
4690 int an = 0;
4691 int en = length;
4692 int cmp_int = currRing->OrdSgn;
4695 && (currRing->real_var_start==0)
4696#endif
4697#if 0
4698 || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
4699#endif
4700 )
4701 {
4702 int o=p_Deg(p,currRing);
4703 int oo=p_Deg(set[length],currRing);
4704
4705 if ((oo<o)
4706 || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
4707 return length+1;
4708
4709 loop
4710 {
4711 if (an >= en-1)
4712 {
4713 if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
4714 {
4715 return an;
4716 }
4717 return en;
4718 }
4719 i=(an+en) / 2;
4720 if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
4721 else an=i;
4722 }
4723 }
4724 else
4725 {
4727 {
4728 if (pLmCmp(set[length],p)== -cmp_int)
4729 return length+1;
4730 int cmp;
4731 loop
4732 {
4733 if (an >= en-1)
4734 {
4735 cmp = pLmCmp(set[an],p);
4736 if (cmp == cmp_int) return an;
4737 if (cmp == -cmp_int) return en;
4738 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
4739 return an;
4740 }
4741 i = (an+en) / 2;
4742 cmp = pLmCmp(set[i],p);
4743 if (cmp == cmp_int) en = i;
4744 else if (cmp == -cmp_int) an = i;
4745 else
4746 {
4747 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
4748 else en = i;
4749 }
4750 }
4751 }
4752 else
4753 if (pLmCmp(set[length],p)== -cmp_int)
4754 return length+1;
4755
4756 loop
4757 {
4758 if (an >= en-1)
4759 {
4760 if (pLmCmp(set[an],p) == cmp_int) return an;
4761 if (pLmCmp(set[an],p) == -cmp_int) return en;
4762 if ((cmp_int!=1)
4763 && ((strat->ecartS[an])>ecart_p))
4764 return an;
4765 return en;
4766 }
4767 i=(an+en) / 2;
4768 if (pLmCmp(set[i],p) == cmp_int) en=i;
4769 else if (pLmCmp(set[i],p) == -cmp_int) an=i;
4770 else
4771 {
4772 if ((cmp_int!=1)
4773 &&((strat->ecartS[i])<ecart_p))
4774 en=i;
4775 else
4776 an=i;
4777 }
4778 }
4779 }
4780}
4781
4782
4783// sorts by degree and pLtCmp
4784// but puts pure monomials at the beginning
4785int posInSMonFirst (const kStrategy strat, const int length,const poly p)
4786{
4787 if (length<0) return 0;
4788 polyset set=strat->S;
4789 if(pNext(p) == NULL)
4790 {
4791 int mon = 0;
4792 for(int i = 0;i<=length;i++)
4793 {
4794 if(set[i] != NULL && pNext(set[i]) == NULL)
4795 mon++;
4796 }
4797 int o = p_Deg(p,currRing);
4798 int op = p_Deg(set[mon],currRing);
4799
4800 if ((op < o)
4801 || ((op == o) && (pLtCmp(set[mon],p) == -1)))
4802 return length+1;
4803 int i;
4804 int an = 0;
4805 int en= mon;
4806 loop
4807 {
4808 if (an >= en-1)
4809 {
4810 op = p_Deg(set[an],currRing);
4811 if ((op < o)
4812 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4813 return en;
4814 return an;
4815 }
4816 i=(an+en) / 2;
4817 op = p_Deg(set[i],currRing);
4818 if ((op < o)
4819 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4820 an=i;
4821 else
4822 en=i;
4823 }
4824 }
4825 else /*if(pNext(p) != NULL)*/
4826 {
4827 int o = p_Deg(p,currRing);
4828 int op = p_Deg(set[length],currRing);
4829
4830 if ((op < o)
4831 || ((op == o) && (pLtCmp(set[length],p) == -1)))
4832 return length+1;
4833 int i;
4834 int an = 0;
4835 for(i=0;i<=length;i++)
4836 if(set[i] != NULL && pNext(set[i]) == NULL)
4837 an++;
4838 int en= length;
4839 loop
4840 {
4841 if (an >= en-1)
4842 {
4843 op = p_Deg(set[an],currRing);
4844 if ((op < o)
4845 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4846 return en;
4847 return an;
4848 }
4849 i=(an+en) / 2;
4850 op = p_Deg(set[i],currRing);
4851 if ((op < o)
4852 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4853 an=i;
4854 else
4855 en=i;
4856 }
4857 }
4858}
4859
4860// sorts by degree and pLtCmp in the block between start,end;
4861// but puts pure monomials at the beginning
4862int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
4863{
4865 end = IDELEMS(F);
4866 if (end<0) return 0;
4867 if(pNext(p) == NULL) return start;
4868 polyset set=F->m;
4869 int o = p_Deg(p,currRing);
4870 int op;
4871 int i;
4872 int an = start;
4873 for(i=start;i<end;i++)
4874 if(set[i] != NULL && pNext(set[i]) == NULL)
4875 an++;
4876 if(an == end-1)
4877 return end;
4878 int en= end;
4879 loop
4880 {
4881 if(an>=en)
4882 return en;
4883 if (an == en-1)
4884 {
4885 op = p_Deg(set[an],currRing);
4886 if ((op < o)
4887 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4888 return en;
4889 return an;
4890 }
4891 i=(an+en) / 2;
4892 op = p_Deg(set[i],currRing);
4893 if ((op < o)
4894 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4895 an=i;
4896 else
4897 en=i;
4898 }
4899}
4900
4901
4902/*2
4903* looks up the position of p in set
4904* the position is the last one
4905*/
4906int posInT0 (const TSet,const int length,LObject &)
4907{
4908 return (length+1);
4909}
4910
4911
4912/*2
4913* looks up the position of p in T
4914* set[0] is the smallest with respect to the ordering-procedure
4915* pComp
4916*/
4917int posInT1 (const TSet set,const int length,LObject &p)
4918{
4919 if (length==-1) return 0;
4920
4921 if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
4922
4923 int i;
4924 int an = 0;
4925 int en= length;
4926 int cmp_int=currRing->OrdSgn;
4927
4928 loop
4929 {
4930 if (an >= en-1)
4931 {
4932 if (pLmCmp(set[an].p,p.p) == cmp_int) return an;
4933 return en;
4934 }
4935 i=(an+en) / 2;
4936 if (pLmCmp(set[i].p,p.p) == cmp_int) en=i;
4937 else an=i;
4938 }
4939}
4940
4941/*2
4942* looks up the position of p in T
4943* set[0] is the smallest with respect to the ordering-procedure
4944* length
4945*/
4946int posInT2 (const TSet set,const int length,LObject &p)
4947{
4948 if (length==-1) return 0;
4949 p.GetpLength();
4950 if (set[length].length<p.length) return length+1;
4951
4952 int i;
4953 int an = 0;
4954 int en= length;
4955
4956 loop
4957 {
4958 if (an >= en-1)
4959 {
4960 if (set[an].length>p.length) return an;
4961 return en;
4962 }
4963 i=(an+en) / 2;
4964 if (set[i].length>p.length) en=i;
4965 else an=i;
4966 }
4967}
4968
4969/*2
4970* looks up the position of p in T
4971* set[0] is the smallest with respect to the ordering-procedure
4972* totaldegree,pComp
4973*/
4974int posInT11 (const TSet set,const int length,LObject &p)
4975{
4976 if (length==-1) return 0;
4977
4978 int o = p.GetpFDeg();
4979 int op = set[length].GetpFDeg();
4980 int cmp_int=currRing->OrdSgn;
4981
4982 if ((op < o)
4983 || ((op == o) && (pLmCmp(set[length].p,p.p) != cmp_int)))
4984 return length+1;
4985
4986 int i;
4987 int an = 0;
4988 int en= length;
4989
4990 loop
4991 {
4992 if (an >= en-1)
4993 {
4994 op= set[an].GetpFDeg();
4995 if ((op > o)
4996 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
4997 return an;
4998 return en;
4999 }
5000 i=(an+en) / 2;
5001 op = set[i].GetpFDeg();
5002 if (( op > o)
5003 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
5004 en=i;
5005 else
5006 an=i;
5007 }
5008}
5009
5010#ifdef HAVE_RINGS
5011int posInT11Ring (const TSet set,const int length,LObject &p)
5012{
5013 if (length==-1) return 0;
5014
5015 int o = p.GetpFDeg();
5016 int op = set[length].GetpFDeg();
5017
5018 if ((op < o)
5019 || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5020 return length+1;
5021
5022 int i;
5023 int an = 0;
5024 int en= length;
5025
5026 loop
5027 {
5028 if (an >= en-1)
5029 {
5030 op= set[an].GetpFDeg();
5031 if ((op > o)
5032 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5033 return an;
5034 return en;
5035 }
5036 i=(an+en) / 2;
5037 op = set[i].GetpFDeg();
5038 if (( op > o)
5039 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5040 en=i;
5041 else
5042 an=i;
5043 }
5044}
5045#endif
5046
5047/*2
5048* looks up the position of p in T
5049* set[0] is the smallest with respect to the ordering-procedure
5050* totaldegree,pComp
5051*/
5052int posInT110 (const TSet set,const int length,LObject &p)
5053{
5054 if (length==-1) return 0;
5055 p.GetpLength();
5056
5057 int o = p.GetpFDeg();
5058 int op = set[length].GetpFDeg();
5059 int cmp_int=currRing->OrdSgn;
5060
5061 if (( op < o)
5062 || (( op == o) && (set[length].length<p.length))
5063 || (( op == o) && (set[length].length == p.length)
5064 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5065 return length+1;
5066
5067 int i;
5068 int an = 0;
5069 int en= length;
5070 loop
5071 {
5072 if (an >= en-1)
5073 {
5074 op = set[an].GetpFDeg();
5075 if (( op > o)
5076 || (( op == o) && (set[an].length > p.length))
5077 || (( op == o) && (set[an].length == p.length)
5078 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5079 return an;
5080 return en;
5081 }
5082 i=(an+en) / 2;
5083 op = set[i].GetpFDeg();
5084 if (( op > o)
5085 || (( op == o) && (set[i].length > p.length))
5086 || (( op == o) && (set[i].length == p.length)
5087 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5088 en=i;
5089 else
5090 an=i;
5091 }
5092}
5093
5094#ifdef HAVE_RINGS
5095int posInT110Ring (const TSet set,const int length,LObject &p)
5096{
5097 if (length==-1) return 0;
5098 p.GetpLength();
5099
5100 int o = p.GetpFDeg();
5101 int op = set[length].GetpFDeg();
5102
5103 if (( op < o)
5104 || (( op == o) && (set[length].length<p.length))
5105 || (( op == o) && (set[length].length == p.length)
5106 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5107 return length+1;
5108
5109 int i;
5110 int an = 0;
5111 int en= length;
5112 loop
5113 {
5114 if (an >= en-1)
5115 {
5116 op = set[an].GetpFDeg();
5117 if (( op > o)
5118 || (( op == o) && (set[an].length > p.length))
5119 || (( op == o) && (set[an].length == p.length)
5120 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5121 return an;
5122 return en;
5123 }
5124 i=(an+en) / 2;
5125 op = set[i].GetpFDeg();
5126 if (( op > o)
5127 || (( op == o) && (set[i].length > p.length))
5128 || (( op == o) && (set[i].length == p.length)
5129 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5130 en=i;
5131 else
5132 an=i;
5133 }
5134}
5135#endif
5136
5137/*2
5138* looks up the position of p in set
5139* set[0] is the smallest with respect to the ordering-procedure
5140* pFDeg
5141*/
5142int posInT13 (const TSet set,const int length,LObject &p)
5143{
5144 if (length==-1) return 0;
5145
5146 int o = p.GetpFDeg();
5147
5148 if (set[length].GetpFDeg() <= o)
5149 return length+1;
5150
5151 int i;
5152 int an = 0;
5153 int en= length;
5154 loop
5155 {
5156 if (an >= en-1)
5157 {
5158 if (set[an].GetpFDeg() > o)
5159 return an;
5160 return en;
5161 }
5162 i=(an+en) / 2;
5163 if (set[i].GetpFDeg() > o)
5164 en=i;
5165 else
5166 an=i;
5167 }
5168}
5169
5170// determines the position based on: 1.) Ecart 2.) pLength
5171int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5172{
5173 if (length==-1) return 0;
5174 int ol = p.GetpLength();
5175 int op=p.ecart;
5176 int oo=set[length].ecart;
5177
5178 if ((oo < op) || ((oo==op) && (set[length].length <= ol)))
5179 return length+1;
5180
5181 int i;
5182 int an = 0;
5183 int en= length;
5184 loop
5185 {
5186 if (an >= en-1)
5187 {
5188 int oo=set[an].ecart;
5189 if((oo > op)
5190 || ((oo==op) && (set[an].pLength > ol)))
5191 return an;
5192 return en;
5193 }
5194 i=(an+en) / 2;
5195 int oo=set[i].ecart;
5196 if ((oo > op)
5197 || ((oo == op) && (set[i].pLength > ol)))
5198 en=i;
5199 else
5200 an=i;
5201 }
5202}
5203
5204/*2
5205* looks up the position of p in set
5206* set[0] is the smallest with respect to the ordering-procedure
5207* maximaldegree, pComp
5208*/
5209int posInT15 (const TSet set,const int length,LObject &p)
5210/*{
5211 *int j=0;
5212 * int o;
5213 *
5214 * o = p.GetpFDeg()+p.ecart;
5215 * loop
5216 * {
5217 * if ((set[j].GetpFDeg()+set[j].ecart > o)
5218 * || ((set[j].GetpFDeg()+set[j].ecart == o)
5219 * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5220 * {
5221 * return j;
5222 * }
5223 * j++;
5224 * if (j > length) return j;
5225 * }
5226 *}
5227 */
5228{
5229 if (length==-1) return 0;
5230
5231 int o = p.GetpFDeg() + p.ecart;
5232 int op = set[length].GetpFDeg()+set[length].ecart;
5233 int cmp_int=currRing->OrdSgn;
5234
5235 if ((op < o)
5236 || ((op == o)
5237 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5238 return length+1;
5239
5240 int i;
5241 int an = 0;
5242 int en= length;
5243 loop
5244 {
5245 if (an >= en-1)
5246 {
5247 op = set[an].GetpFDeg()+set[an].ecart;
5248 if (( op > o)
5249 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
5250 return an;
5251 return en;
5252 }
5253 i=(an+en) / 2;
5254 op = set[i].GetpFDeg()+set[i].ecart;
5255 if (( op > o)
5256 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
5257 en=i;
5258 else
5259 an=i;
5260 }
5261}
5262
5263#ifdef HAVE_RINGS
5264int posInT15Ring (const TSet set,const int length,LObject &p)
5265{
5266 if (length==-1) return 0;
5267
5268 int o = p.GetpFDeg() + p.ecart;
5269 int op = set[length].GetpFDeg()+set[length].ecart;
5270
5271 if ((op < o)
5272 || ((op == o)
5273 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5274 return length+1;
5275
5276 int i;
5277 int an = 0;
5278 int en= length;
5279 loop
5280 {
5281 if (an >= en-1)
5282 {
5283 op = set[an].GetpFDeg()+set[an].ecart;
5284 if (( op > o)
5285 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5286 return an;
5287 return en;
5288 }
5289 i=(an+en) / 2;
5290 op = set[i].GetpFDeg()+set[i].ecart;
5291 if (( op > o)
5292 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5293 en=i;
5294 else
5295 an=i;
5296 }
5297}
5298#endif
5299
5300/*2
5301* looks up the position of p in set
5302* set[0] is the smallest with respect to the ordering-procedure
5303* pFDeg+ecart, ecart, pComp
5304*/
5305int posInT17 (const TSet set,const int length,LObject &p)
5306/*
5307*{
5308* int j=0;
5309* int o;
5310*
5311* o = p.GetpFDeg()+p.ecart;
5312* loop
5313* {
5314* if ((pFDeg(set[j].p)+set[j].ecart > o)
5315* || (((pFDeg(set[j].p)+set[j].ecart == o)
5316* && (set[j].ecart < p.ecart)))
5317* || ((pFDeg(set[j].p)+set[j].ecart == o)
5318* && (set[j].ecart==p.ecart)
5319* && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5320* return j;
5321* j++;
5322* if (j > length) return j;
5323* }
5324* }
5325*/
5326{
5327 if (length==-1) return 0;
5328
5329 int o = p.GetpFDeg() + p.ecart;
5330 int op = set[length].GetpFDeg()+set[length].ecart;
5331 int cmp_int=currRing->OrdSgn;
5332
5333 if ((op < o)
5334 || (( op == o) && (set[length].ecart > p.ecart))
5335 || (( op == o) && (set[length].ecart==p.ecart)
5336 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5337 return length+1;
5338
5339 int i;
5340 int an = 0;
5341 int en= length;
5342 loop
5343 {
5344 if (an >= en-1)
5345 {
5346 op = set[an].GetpFDeg()+set[an].ecart;
5347 if (( op > o)
5348 || (( op == o) && (set[an].ecart < p.ecart))
5349 || (( op == o) && (set[an].ecart==p.ecart)
5350 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5351 return an;
5352 return en;
5353 }
5354 i=(an+en) / 2;
5355 op = set[i].GetpFDeg()+set[i].ecart;
5356 if ((op > o)
5357 || (( op == o) && (set[i].ecart < p.ecart))
5358 || (( op == o) && (set[i].ecart == p.ecart)
5359 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5360 en=i;
5361 else
5362 an=i;
5363 }
5364}
5365
5366#ifdef HAVE_RINGS
5367int posInT17Ring (const TSet set,const int length,LObject &p)
5368{
5369 if (length==-1) return 0;
5370
5371 int o = p.GetpFDeg() + p.ecart;
5372 int op = set[length].GetpFDeg()+set[length].ecart;
5373
5374 if ((op < o)
5375 || (( op == o) && (set[length].ecart > p.ecart))
5376 || (( op == o) && (set[length].ecart==p.ecart)
5377 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5378 return length+1;
5379
5380 int i;
5381 int an = 0;
5382 int en= length;
5383 loop
5384 {
5385 if (an >= en-1)
5386 {
5387 op = set[an].GetpFDeg()+set[an].ecart;
5388 if (( op > o)
5389 || (( op == o) && (set[an].ecart < p.ecart))
5390 || (( op == o) && (set[an].ecart==p.ecart)
5391 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5392 return an;
5393 return en;
5394 }
5395 i=(an+en) / 2;
5396 op = set[i].GetpFDeg()+set[i].ecart;
5397 if ((op > o)
5398 || (( op == o) && (set[i].ecart < p.ecart))
5399 || (( op == o) && (set[i].ecart == p.ecart)
5400 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5401 en=i;
5402 else
5403 an=i;
5404 }
5405}
5406#endif
5407
5408/*2
5409* looks up the position of p in set
5410* set[0] is the smallest with respect to the ordering-procedure
5411* pGetComp, pFDeg+ecart, ecart, pComp
5412*/
5413int posInT17_c (const TSet set,const int length,LObject &p)
5414{
5415 if (length==-1) return 0;
5416
5417 int cc = (-1+2*currRing->order[0]==ringorder_c);
5418 /* cc==1 for (c,..), cc==-1 for (C,..) */
5419 int o = p.GetpFDeg() + p.ecart;
5420 int c = pGetComp(p.p)*cc;
5421 int cmp_int=currRing->OrdSgn;
5422
5423 if (pGetComp(set[length].p)*cc < c)
5424 return length+1;
5425 if (pGetComp(set[length].p)*cc == c)
5426 {
5427 int op = set[length].GetpFDeg()+set[length].ecart;
5428 if ((op < o)
5429 || ((op == o) && (set[length].ecart > p.ecart))
5430 || ((op == o) && (set[length].ecart==p.ecart)
5431 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5432 return length+1;
5433 }
5434
5435 int i;
5436 int an = 0;
5437 int en= length;
5438 loop
5439 {
5440 if (an >= en-1)
5441 {
5442 if (pGetComp(set[an].p)*cc < c)
5443 return en;
5444 if (pGetComp(set[an].p)*cc == c)
5445 {
5446 int op = set[an].GetpFDeg()+set[an].ecart;
5447 if ((op > o)
5448 || ((op == o) && (set[an].ecart < p.ecart))
5449 || ((op == o) && (set[an].ecart==p.ecart)
5450 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5451 return an;
5452 }
5453 return en;
5454 }
5455 i=(an+en) / 2;
5456 if (pGetComp(set[i].p)*cc > c)
5457 en=i;
5458 else if (pGetComp(set[i].p)*cc == c)
5459 {
5460 int op = set[i].GetpFDeg()+set[i].ecart;
5461 if ((op > o)
5462 || ((op == o) && (set[i].ecart < p.ecart))
5463 || ((op == o) && (set[i].ecart == p.ecart)
5464 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5465 en=i;
5466 else
5467 an=i;
5468 }
5469 else
5470 an=i;
5471 }
5472}
5473
5474#ifdef HAVE_RINGS
5475int posInT17_cRing (const TSet set,const int length,LObject &p)
5476{
5477 if (length==-1) return 0;
5478
5479 int cc = (-1+2*currRing->order[0]==ringorder_c);
5480 /* cc==1 for (c,..), cc==-1 for (C,..) */
5481 int o = p.GetpFDeg() + p.ecart;
5482 int c = pGetComp(p.p)*cc;
5483
5484 if (pGetComp(set[length].p)*cc < c)
5485 return length+1;
5486 if (pGetComp(set[length].p)*cc == c)
5487 {
5488 int op = set[length].GetpFDeg()+set[length].ecart;
5489 if ((op < o)
5490 || ((op == o) && (set[length].ecart > p.ecart))
5491 || ((op == o) && (set[length].ecart==p.ecart)
5492 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5493 return length+1;
5494 }
5495
5496 int i;
5497 int an = 0;
5498 int en= length;
5499 loop
5500 {
5501 if (an >= en-1)
5502 {
5503 if (pGetComp(set[an].p)*cc < c)
5504 return en;
5505 if (pGetComp(set[an].p)*cc == c)
5506 {
5507 int op = set[an].GetpFDeg()+set[an].ecart;
5508 if ((op > o)
5509 || ((op == o) && (set[an].ecart < p.ecart))
5510 || ((op == o) && (set[an].ecart==p.ecart)
5511 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5512 return an;
5513 }
5514 return en;
5515 }
5516 i=(an+en) / 2;
5517 if (pGetComp(set[i].p)*cc > c)
5518 en=i;
5519 else if (pGetComp(set[i].p)*cc == c)
5520 {
5521 int op = set[i].GetpFDeg()+set[i].ecart;
5522 if ((op > o)
5523 || ((op == o) && (set[i].ecart < p.ecart))
5524 || ((op == o) && (set[i].ecart == p.ecart)
5525 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5526 en=i;
5527 else
5528 an=i;
5529 }
5530 else
5531 an=i;
5532 }
5533}
5534#endif
5535
5536/*2
5537* looks up the position of p in set
5538* set[0] is the smallest with respect to
5539* ecart, pFDeg, length
5540*/
5541int posInT19 (const TSet set,const int length,LObject &p)
5542{
5543 p.GetpLength();
5544 if (length==-1) return 0;
5545
5546 int o = p.ecart;
5547 int op=p.GetpFDeg();
5548
5549 if (set[length].ecart < o)
5550 return length+1;
5551 if (set[length].ecart == o)
5552 {
5553 int oo=set[length].GetpFDeg();
5554 if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5555 return length+1;
5556 }
5557
5558 int i;
5559 int an = 0;
5560 int en= length;
5561 loop
5562 {
5563 if (an >= en-1)
5564 {
5565 if (set[an].ecart > o)
5566 return an;
5567 if (set[an].ecart == o)
5568 {
5569 int oo=set[an].GetpFDeg();
5570 if((oo > op)
5571 || ((oo==op) && (set[an].length > p.length)))
5572 return an;
5573 }
5574 return en;
5575 }
5576 i=(an+en) / 2;
5577 if (set[i].ecart > o)
5578 en=i;
5579 else if (set[i].ecart == o)
5580 {
5581 int oo=set[i].GetpFDeg();
5582 if ((oo > op)
5583 || ((oo == op) && (set[i].length > p.length)))
5584 en=i;
5585 else
5586 an=i;
5587 }
5588 else
5589 an=i;
5590 }
5591}
5592
5593/*2
5594*looks up the position of polynomial p in set
5595*set[length] is the smallest element in set with respect
5596*to the ordering-procedure pComp
5597*/
5598int posInLSpecial (const LSet set, const int length,
5599 LObject *p,const kStrategy)
5600{
5601 if (length<0) return 0;
5602
5603 int d=p->GetpFDeg();
5604 int op=set[length].GetpFDeg();
5605 int cmp_int=currRing->OrdSgn;
5606
5607 if ((op > d)
5608 || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
5609 || (pLmCmp(set[length].p,p->p)== cmp_int))
5610 return length+1;
5611
5612 int i;
5613 int an = 0;
5614 int en= length;
5615 loop
5616 {
5617 if (an >= en-1)
5618 {
5619 op=set[an].GetpFDeg();
5620 if ((op > d)
5621 || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
5622 || (pLmCmp(set[an].p,p->p)== cmp_int))
5623 return en;
5624 return an;
5625 }
5626 i=(an+en) / 2;
5627 op=set[i].GetpFDeg();
5628 if ((op>d)
5629 || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
5630 || (pLmCmp(set[i].p,p->p) == cmp_int))
5631 an=i;
5632 else
5633 en=i;
5634 }
5635}
5636
5637/*2
5638*looks up the position of polynomial p in set
5639*set[length] is the smallest element in set with respect
5640*to the ordering-procedure pComp
5641*/
5642int posInL0 (const LSet set, const int length,
5643 LObject* p,const kStrategy)
5644{
5645 if (length<0) return 0;
5646
5647 int cmp_int=currRing->OrdSgn;
5648
5649 if (pLmCmp(set[length].p,p->p)== cmp_int)
5650 return length+1;
5651
5652 int i;
5653 int an = 0;
5654 int en= length;
5655 loop
5656 {
5657 if (an >= en-1)
5658 {
5659 if (pLmCmp(set[an].p,p->p) == cmp_int) return en;
5660 return an;
5661 }
5662 i=(an+en) / 2;
5663 if (pLmCmp(set[i].p,p->p) == cmp_int) an=i;
5664 else en=i;
5665 /*aend. fuer lazy == in !=- machen */
5666 }
5667}
5668
5669#ifdef HAVE_RINGS
5670int posInL0Ring (const LSet set, const int length,
5671 LObject* p,const kStrategy)
5672{
5673 if (length<0) return 0;
5674
5675 if (pLtCmpOrdSgnEqP(set[length].p,p->p))
5676 return length+1;
5677
5678 int i;
5679 int an = 0;
5680 int en= length;
5681 loop
5682 {
5683 if (an >= en-1)
5684 {
5685 if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
5686 return an;
5687 }
5688 i=(an+en) / 2;
5689 if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
5690 else en=i;
5691 /*aend. fuer lazy == in !=- machen */
5692 }
5693}
5694#endif
5695
5696/*2
5697* looks up the position of polynomial p in set
5698* e is the ecart of p
5699* set[length] is the smallest element in set with respect
5700* to the signature order
5701*/
5702int posInLSig (const LSet set, const int length,
5703 LObject* p,const kStrategy /*strat*/)
5704{
5705 if (length<0) return 0;
5706 int cmp_int=currRing->OrdSgn;
5707 if (pLtCmp(set[length].sig,p->sig)==cmp_int)
5708 return length+1;
5709
5710 int i;
5711 int an = 0;
5712 int en= length;
5713 loop
5714 {
5715 if (an >= en-1)
5716 {
5717 if (pLtCmp(set[an].sig,p->sig) == cmp_int) return en;
5718 return an;
5719 }
5720 i=(an+en) / 2;
5721 if (pLtCmp(set[i].sig,p->sig) == cmp_int) an=i;
5722 else en=i;
5723 /*aend. fuer lazy == in !=- machen */
5724 }
5725}
5726//sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
5727int posInLSigRing (const LSet set, const int length,
5728 LObject* p,const kStrategy /*strat*/)
5729{
5730 assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
5731 if (length<0) return 0;
5732 if (pLtCmp(set[length].sig,p->sig)== 1)
5733 return length+1;
5734
5735 int an,en,i;
5736 an = 0;
5737 en = length+1;
5738 int cmp;
5739 loop
5740 {
5741 if (an >= en-1)
5742 {
5743 if(an == en)
5744 return en;
5745 cmp = pLtCmp(set[an].sig,p->sig);
5746 if (cmp == 1)
5747 return en;
5748 if (cmp == -1)
5749 return an;
5750 if (cmp == 0)
5751 {
5752 if (set[an].FDeg > p->FDeg)
5753 return en;
5754 if (set[an].FDeg < p->FDeg)
5755 return an;
5756 if (set[an].FDeg == p->FDeg)
5757 {
5758 cmp = pLtCmp(set[an].p,p->p);
5759 if(cmp == 1)
5760 return en;
5761 else
5762 return an;
5763 }
5764 }
5765 }
5766 i=(an+en) / 2;
5767 cmp = pLtCmp(set[i].sig,p->sig);
5768 if (cmp == 1)
5769 an = i;
5770 if (cmp == -1)
5771 en = i;
5772 if (cmp == 0)
5773 {
5774 if (set[i].FDeg > p->FDeg)
5775 an = i;
5776 if (set[i].FDeg < p->FDeg)
5777 en = i;
5778 if (set[i].FDeg == p->FDeg)
5779 {
5780 cmp = pLtCmp(set[i].p,p->p);
5781 if(cmp == 1)
5782 an = i;
5783 else
5784 en = i;
5785 }
5786 }
5787 }
5788}
5789
5790// for sba, sorting syzygies
5791int posInSyz (const kStrategy strat, poly sig)
5792{
5793 if (strat->syzl==0) return 0;
5794 int cmp_int=currRing->OrdSgn;
5795 if (pLtCmp(strat->syz[strat->syzl-1],sig) != cmp_int)
5796 return strat->syzl;
5797 int i;
5798 int an = 0;
5799 int en= strat->syzl-1;
5800 loop
5801 {
5802 if (an >= en-1)
5803 {
5804 if (pLtCmp(strat->syz[an],sig) != cmp_int) return en;
5805 return an;
5806 }
5807 i=(an+en) / 2;
5808 if (pLtCmp(strat->syz[i],sig) != cmp_int) an=i;
5809 else en=i;
5810 /*aend. fuer lazy == in !=- machen */
5811 }
5812}
5813
5814/*2
5815*
5816* is only used in F5C, must ensure that the interreduction process does add new
5817* critical pairs to strat->L only behind all other critical pairs which are
5818* still in strat->L!
5819*/
5820int posInLF5C (const LSet /*set*/, const int /*length*/,
5821 LObject* /*p*/,const kStrategy strat)
5822{
5823 return strat->Ll+1;
5824}
5825
5826/*2
5827* looks up the position of polynomial p in set
5828* e is the ecart of p
5829* set[length] is the smallest element in set with respect
5830* to the ordering-procedure totaldegree,pComp
5831*/
5832int posInL11 (const LSet set, const int length,
5833 LObject* p,const kStrategy)
5834{
5835 if (length<0) return 0;
5836
5837 int o = p->GetpFDeg();
5838 int op = set[length].GetpFDeg();
5839 int cmp_int= -currRing->OrdSgn;
5840
5841 if ((op > o)
5842 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
5843 return length+1;
5844 int i;
5845 int an = 0;
5846 int en= length;
5847 loop
5848 {
5849 if (an >= en-1)
5850 {
5851 op = set[an].GetpFDeg();
5852 if ((op > o)
5853 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
5854 return en;
5855 return an;
5856 }
5857 i=(an+en) / 2;
5858 op = set[i].GetpFDeg();
5859 if ((op > o)
5860 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
5861 an=i;
5862 else
5863 en=i;
5864 }
5865}
5866
5867#ifdef HAVE_RINGS
5868/*2
5869* looks up the position of polynomial p in set
5870* set[length] is the smallest element in set with respect
5871* to the ordering-procedure pLmCmp,totaldegree,coefficient
5872* For the same totaldegree, original pairs (from F) will
5873* be put at the end and smallest coefficients
5874*/
5875int posInL11Ring (const LSet set, const int length,
5876 LObject* p,const kStrategy)
5877{
5878 if (length<0) return 0;
5879
5880 int o = p->GetpFDeg();
5881 int op = set[length].GetpFDeg();
5882
5883 if ((op > o)
5884 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5885 return length+1;
5886 int i;
5887 int an = 0;
5888 int en= length;
5889 loop
5890 {
5891 if (an >= en-1)
5892 {
5893 op = set[an].GetpFDeg();
5894 if ((op > o)
5895 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5896 return en;
5897 return an;
5898 }
5899 i=(an+en) / 2;
5900 op = set[i].GetpFDeg();
5901 if ((op > o)
5902 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5903 an=i;
5904 else
5905 en=i;
5906 }
5907}
5908
5909int posInLF5CRing (const LSet set, int start,const int length,
5910 LObject* p,const kStrategy)
5911{
5912 if (length<0) return 0;
5913 if(start == (length +1)) return (length+1);
5914 int o = p->GetpFDeg();
5915 int op = set[length].GetpFDeg();
5916
5917 if ((op > o)
5918 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5919 return length+1;
5920 int i;
5921 int an = start;
5922 int en= length;
5923 loop
5924 {
5925 if (an >= en-1)
5926 {
5927 op = set[an].GetpFDeg();
5928 if ((op > o)
5929 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5930 return en;
5931 return an;
5932 }
5933 i=(an+en) / 2;
5934 op = set[i].GetpFDeg();
5935 if ((op > o)
5936 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5937 an=i;
5938 else
5939 en=i;
5940 }
5941}
5942#endif
5943
5944#ifdef HAVE_RINGS
5945int posInL11Ringls (const LSet set, const int length,
5946 LObject* p,const kStrategy)
5947{
5948 if (length < 0) return 0;
5949 int an,en,i;
5950 an = 0;
5951 en = length+1;
5952 loop
5953 {
5954 if (an >= en-1)
5955 {
5956 if(an == en)
5957 return en;
5958 if (set[an].FDeg > p->FDeg)
5959 return en;
5960 if (set[an].FDeg < p->FDeg)
5961 return an;
5962 if (set[an].FDeg == p->FDeg)
5963 {
5965 lcset = pGetCoeff(set[an].p);
5966 lcp = pGetCoeff(p->p);
5967 if(!nGreaterZero(lcset))
5968 {
5969 set[an].p=p_Neg(set[an].p,currRing);
5970 if (set[an].t_p!=NULL)
5971 pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
5972 lcset=pGetCoeff(set[an].p);
5973 }
5974 if(!nGreaterZero(lcp))
5975 {
5976 p->p=p_Neg(p->p,currRing);
5977 if (p->t_p!=NULL)
5978 pSetCoeff0(p->t_p,pGetCoeff(p->p));
5979 lcp=pGetCoeff(p->p);
5980 }
5981 if(nGreater(lcset, lcp))
5982 {
5983 return en;
5984 }
5985 else
5986 {
5987 return an;
5988 }
5989 }
5990 }
5991 i=(an+en) / 2;
5992 if (set[i].FDeg > p->FDeg)
5993 an=i;
5994 if (set[i].FDeg < p->FDeg)
5995 en=i;
5996 if (set[i].FDeg == p->FDeg)
5997 {
5999 lcset = pGetCoeff(set[i].p);
6000 lcp = pGetCoeff(p->p);
6001 if(!nGreaterZero(lcset))
6002 {
6003 set[i].p=p_Neg(set[i].p,currRing);
6004 if (set[i].t_p!=NULL)
6005 pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6006 lcset=pGetCoeff(set[i].p);
6007 }
6008 if(!nGreaterZero(lcp))
6009 {
6010 p->p=p_Neg(p->p,currRing);
6011 if (p->t_p!=NULL)
6012 pSetCoeff0(p->t_p,pGetCoeff(p->p));
6013 lcp=pGetCoeff(p->p);
6014 }
6015 if(nGreater(lcset, lcp))
6016 {
6017 an = i;
6018 }
6019 else
6020 {
6021 en = i;
6022 }
6023 }
6024 }
6025}
6026#endif
6027
6028/*2 Position for rings L: Here I am
6029* looks up the position of polynomial p in set
6030* e is the ecart of p
6031* set[length] is the smallest element in set with respect
6032* to the ordering-procedure totaldegree,pComp
6033*/
6034inline int getIndexRng(long coeff)
6035{
6036 if (coeff == 0) return -1;
6037 long tmp = coeff;
6038 int ind = 0;
6039 while (tmp % 2 == 0)
6040 {
6041 tmp = tmp / 2;
6042 ind++;
6043 }
6044 return ind;
6045}
6046
6047/*{
6048 if (length < 0) return 0;
6049
6050 int o = p->GetpFDeg();
6051 int op = set[length].GetpFDeg();
6052
6053 int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6054 int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6055 int inda;
6056 int indi;
6057
6058 if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6059 return length + 1;
6060 int i;
6061 int an = 0;
6062 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6063 int en = length;
6064 loop
6065 {
6066 if (an >= en-1)
6067 {
6068 op = set[an].GetpFDeg();
6069 if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6070 return en;
6071 return an;
6072 }
6073 i = (an + en) / 2;
6074 indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6075 op = set[i].GetpFDeg();
6076 if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6077 // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6078 {
6079 an = i;
6080 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6081 }
6082 else
6083 en = i;
6084 }
6085} */
6086
6087/*2
6088* looks up the position of polynomial p in set
6089* set[length] is the smallest element in set with respect
6090* to the ordering-procedure totaldegree,pLength0
6091*/
6092int posInL110 (const LSet set, const int length,
6093 LObject* p,const kStrategy)
6094{
6095 if (length<0) return 0;
6096
6097 int o = p->GetpFDeg();
6098 int op = set[length].GetpFDeg();
6099 int cmp_int= -currRing->OrdSgn;
6100
6101 if ((op > o)
6102 || ((op == o) && (set[length].length >p->length))
6103 || ((op == o) && (set[length].length <= p->length)
6104 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6105 return length+1;
6106 int i;
6107 int an = 0;
6108 int en= length;
6109 loop
6110 {
6111 if (an >= en-1)
6112 {
6113 op = set[an].GetpFDeg();
6114 if ((op > o)
6115 || ((op == o) && (set[an].length >p->length))
6116 || ((op == o) && (set[an].length <=p->length)
6117 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6118 return en;
6119 return an;
6120 }
6121 i=(an+en) / 2;
6122 op = set[i].GetpFDeg();
6123 if ((op > o)
6124 || ((op == o) && (set[i].length > p->length))
6125 || ((op == o) && (set[i].length <= p->length)
6126 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6127 an=i;
6128 else
6129 en=i;
6130 }
6131}
6132
6133#ifdef HAVE_RINGS
6134int posInL110Ring (const LSet set, const int length,
6135 LObject* p,const kStrategy)
6136{
6137 if (length<0) return 0;
6138
6139 int o = p->GetpFDeg();
6140 int op = set[length].GetpFDeg();
6141
6142 if ((op > o)
6143 || ((op == o) && (set[length].length >p->length))
6144 || ((op == o) && (set[length].length <= p->length)
6145 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6146 return length+1;
6147 int i;
6148 int an = 0;
6149 int en= length;
6150 loop
6151 {
6152 if (an >= en-1)
6153 {
6154 op = set[an].GetpFDeg();
6155 if ((op > o)
6156 || ((op == o) && (set[an].length >p->length))
6157 || ((op == o) && (set[an].length <=p->length)
6158 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6159 return en;
6160 return an;
6161 }
6162 i=(an+en) / 2;
6163 op = set[i].GetpFDeg();
6164 if ((op > o)
6165 || ((op == o) && (set[i].length > p->length))
6166 || ((op == o) && (set[i].length <= p->length)
6167 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6168 an=i;
6169 else
6170 en=i;
6171 }
6172}
6173#endif
6174
6175/*2
6176* looks up the position of polynomial p in set
6177* e is the ecart of p
6178* set[length] is the smallest element in set with respect
6179* to the ordering-procedure totaldegree
6180*/
6181int posInL13 (const LSet set, const int length,
6182 LObject* p,const kStrategy)
6183{
6184 if (length<0) return 0;
6185
6186 int o = p->GetpFDeg();
6187
6188 if (set[length].GetpFDeg() > o)
6189 return length+1;
6190
6191 int i;
6192 int an = 0;
6193 int en= length;
6194 loop
6195 {
6196 if (an >= en-1)
6197 {
6198 if (set[an].GetpFDeg() >= o)
6199 return en;
6200 return an;
6201 }
6202 i=(an+en) / 2;
6203 if (set[i].GetpFDeg() >= o)
6204 an=i;
6205 else
6206 en=i;
6207 }
6208}
6209
6210/*2
6211* looks up the position of polynomial p in set
6212* e is the ecart of p
6213* set[length] is the smallest element in set with respect
6214* to the ordering-procedure maximaldegree,pComp
6215*/
6216int posInL15 (const LSet set, const int length,
6217 LObject* p,const kStrategy)
6218{
6219 if (length<0) return 0;
6220
6221 int o = p->GetpFDeg() + p->ecart;
6222 int op = set[length].GetpFDeg() + set[length].ecart;
6223 int cmp_int= -currRing->OrdSgn;
6224
6225 if ((op > o)
6226 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
6227 return length+1;
6228 int i;
6229 int an = 0;
6230 int en= length;
6231 loop
6232 {
6233 if (an >= en-1)
6234 {
6235 op = set[an].GetpFDeg() + set[an].ecart;
6236 if ((op > o)
6237 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
6238 return en;
6239 return an;
6240 }
6241 i=(an+en) / 2;
6242 op = set[i].GetpFDeg() + set[i].ecart;
6243 if ((op > o)
6244 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
6245 an=i;
6246 else
6247 en=i;
6248 }
6249}
6250
6251#ifdef HAVE_RINGS
6252int posInL15Ring (const LSet set, const int length,
6253 LObject* p,const kStrategy)
6254{
6255 if (length<0) return 0;
6256
6257 int o = p->GetpFDeg() + p->ecart;
6258 int op = set[length].GetpFDeg() + set[length].ecart;
6259
6260 if ((op > o)
6261 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6262 return length+1;
6263 int i;
6264 int an = 0;
6265 int en= length;
6266 loop
6267 {
6268 if (an >= en-1)
6269 {
6270 op = set[an].GetpFDeg() + set[an].ecart;
6271 if ((op > o)
6272 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6273 return en;
6274 return an;
6275 }
6276 i=(an+en) / 2;
6277 op = set[i].GetpFDeg() + set[i].ecart;
6278 if ((op > o)
6279 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6280 an=i;
6281 else
6282 en=i;
6283 }
6284}
6285#endif
6286
6287/*2
6288* looks up the position of polynomial p in set
6289* e is the ecart of p
6290* set[length] is the smallest element in set with respect
6291* to the ordering-procedure totaldegree
6292*/
6293int posInL17 (const LSet set, const int length,
6294 LObject* p,const kStrategy)
6295{
6296 if (length<0) return 0;
6297
6298 int o = p->GetpFDeg() + p->ecart;
6299 int cmp_int= -currRing->OrdSgn;
6300
6301 if ((set[length].GetpFDeg() + set[length].ecart > o)
6302 || ((set[length].GetpFDeg() + set[length].ecart == o)
6303 && (set[length].ecart > p->ecart))
6304 || ((set[length].GetpFDeg() + set[length].ecart == o)
6305 && (set[length].ecart == p->ecart)
6306 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6307 return length+1;
6308 int i;
6309 int an = 0;
6310 int en= length;
6311 loop
6312 {
6313 if (an >= en-1)
6314 {
6315 if ((set[an].GetpFDeg() + set[an].ecart > o)
6316 || ((set[an].GetpFDeg() + set[an].ecart == o)
6317 && (set[an].ecart > p->ecart))
6318 || ((set[an].GetpFDeg() + set[an].ecart == o)
6319 && (set[an].ecart == p->ecart)
6320 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6321 return en;
6322 return an;
6323 }
6324 i=(an+en) / 2;
6325 if ((set[i].GetpFDeg() + set[i].ecart > o)
6326 || ((set[i].GetpFDeg() + set[i].ecart == o)
6327 && (set[i].ecart > p->ecart))
6328 || ((set[i].GetpFDeg() +set[i].ecart == o)
6329 && (set[i].ecart == p->ecart)
6330 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6331 an=i;
6332 else
6333 en=i;
6334 }
6335}
6336
6337#ifdef HAVE_RINGS
6338int posInL17Ring (const LSet set, const int length,
6339 LObject* p,const kStrategy)
6340{
6341 if (length<0) return 0;
6342
6343 int o = p->GetpFDeg() + p->ecart;
6344
6345 if ((set[length].GetpFDeg() + set[length].ecart > o)
6346 || ((set[length].GetpFDeg() + set[length].ecart == o)
6347 && (set[length].ecart > p->ecart))
6348 || ((set[length].GetpFDeg() + set[length].ecart == o)
6349 && (set[length].ecart == p->ecart)
6350 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6351 return length+1;
6352 int i;
6353 int an = 0;
6354 int en= length;
6355 loop
6356 {
6357 if (an >= en-1)
6358 {
6359 if ((set[an].GetpFDeg() + set[an].ecart > o)
6360 || ((set[an].GetpFDeg() + set[an].ecart == o)
6361 && (set[an].ecart > p->ecart))
6362 || ((set[an].GetpFDeg() + set[an].ecart == o)
6363 && (set[an].ecart == p->ecart)
6364 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6365 return en;
6366 return an;
6367 }
6368 i=(an+en) / 2;
6369 if ((set[i].GetpFDeg() + set[i].ecart > o)
6370 || ((set[i].GetpFDeg() + set[i].ecart == o)
6371 && (set[i].ecart > p->ecart))
6372 || ((set[i].GetpFDeg() +set[i].ecart == o)
6373 && (set[i].ecart == p->ecart)
6374 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6375 an=i;
6376 else
6377 en=i;
6378 }
6379}
6380#endif
6381
6382/*2
6383* looks up the position of polynomial p in set
6384* e is the ecart of p
6385* set[length] is the smallest element in set with respect
6386* to the ordering-procedure pComp
6387*/
6388int posInL17_c (const LSet set, const int length,
6389 LObject* p,const kStrategy)
6390{
6391 if (length<0) return 0;
6392
6393 int cc = (-1+2*currRing->order[0]==ringorder_c);
6394 /* cc==1 for (c,..), cc==-1 for (C,..) */
6395 long c = pGetComp(p->p)*cc;
6396 int o = p->GetpFDeg() + p->ecart;
6397 int cmp_int= -currRing->OrdSgn;
6398
6399 if (pGetComp(set[length].p)*cc > c)
6400 return length+1;
6401 if (pGetComp(set[length].p)*cc == c)
6402 {
6403 if ((set[length].GetpFDeg() + set[length].ecart > o)
6404 || ((set[length].GetpFDeg() + set[length].ecart == o)
6405 && (set[length].ecart > p->ecart))
6406 || ((set[length].GetpFDeg() + set[length].ecart == o)
6407 && (set[length].ecart == p->ecart)
6408 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6409 return length+1;
6410 }
6411 int i;
6412 int an = 0;
6413 int en= length;
6414 loop
6415 {
6416 if (an >= en-1)
6417 {
6418 if (pGetComp(set[an].p)*cc > c)
6419 return en;
6420 if (pGetComp(set[an].p)*cc == c)
6421 {
6422 if ((set[an].GetpFDeg() + set[an].ecart > o)
6423 || ((set[an].GetpFDeg() + set[an].ecart == o)
6424 && (set[an].ecart > p->ecart))
6425 || ((set[an].GetpFDeg() + set[an].ecart == o)
6426 && (set[an].ecart == p->ecart)
6427 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6428 return en;
6429 }
6430 return an;
6431 }
6432 i=(an+en) / 2;
6433 if (pGetComp(set[i].p)*cc > c)
6434 an=i;
6435 else if (pGetComp(set[i].p)*cc == c)
6436 {
6437 if ((set[i].GetpFDeg() + set[i].ecart > o)
6438 || ((set[i].GetpFDeg() + set[i].ecart == o)
6439 && (set[i].ecart > p->ecart))
6440 || ((set[i].GetpFDeg() +set[i].ecart == o)
6441 && (set[i].ecart == p->ecart)
6442 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6443 an=i;
6444 else
6445 en=i;
6446 }
6447 else
6448 en=i;
6449 }
6450}
6451
6452#ifdef HAVE_RINGS
6453int posInL17_cRing (const LSet set, const int length,
6454 LObject* p,const kStrategy)
6455{
6456 if (length<0) return 0;
6457
6458 int cc = (-1+2*currRing->order[0]==ringorder_c);
6459 /* cc==1 for (c,..), cc==-1 for (C,..) */
6460 long c = pGetComp(p->p)*cc;
6461 int o = p->GetpFDeg() + p->ecart;
6462
6463 if (pGetComp(set[length].p)*cc > c)
6464 return length+1;
6465 if (pGetComp(set[length].p)*cc == c)
6466 {
6467 if ((set[length].GetpFDeg() + set[length].ecart > o)
6468 || ((set[length].GetpFDeg() + set[length].ecart == o)
6469 && (set[length].ecart > p->ecart))
6470 || ((set[length].GetpFDeg() + set[length].ecart == o)
6471 && (set[length].ecart == p->ecart)
6472 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6473 return length+1;
6474 }
6475 int i;
6476 int an = 0;
6477 int en= length;
6478 loop
6479 {
6480 if (an >= en-1)
6481 {
6482 if (pGetComp(set[an].p)*cc > c)
6483 return en;
6484 if (pGetComp(set[an].p)*cc == c)
6485 {
6486 if ((set[an].GetpFDeg() + set[an].ecart > o)
6487 || ((set[an].GetpFDeg() + set[an].ecart == o)
6488 && (set[an].ecart > p->ecart))
6489 || ((set[an].GetpFDeg() + set[an].ecart == o)
6490 && (set[an].ecart == p->ecart)
6491 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6492 return en;
6493 }
6494 return an;
6495 }
6496 i=(an+en) / 2;
6497 if (pGetComp(set[i].p)*cc > c)
6498 an=i;
6499 else if (pGetComp(set[i].p)*cc == c)
6500 {
6501 if ((set[i].GetpFDeg() + set[i].ecart > o)
6502 || ((set[i].GetpFDeg() + set[i].ecart == o)
6503 && (set[i].ecart > p->ecart))
6504 || ((set[i].GetpFDeg() +set[i].ecart == o)
6505 && (set[i].ecart == p->ecart)
6506 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6507 an=i;
6508 else
6509 en=i;
6510 }
6511 else
6512 en=i;
6513 }
6514}
6515#endif
6516
6517/*
6518 * SYZYGY CRITERION for signature-based standard basis algorithms
6519 */
6520BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6521{
6522//#if 1
6523#ifdef DEBUGF5
6524 PrintS("syzygy criterion checks: ");
6525 pWrite(sig);
6526#endif
6527 for (int k=0; k<strat->syzl; k++)
6528 {
6529 //printf("-%d",k);
6530//#if 1
6531#ifdef DEBUGF5
6532 Print("checking with: %d / %d -- \n",k,strat->syzl);
6533 pWrite(pHead(strat->syz[k]));
6534#endif
6535 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6536 && (!rField_is_Ring(currRing) ||
6537 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6538 {
6539//#if 1
6540#ifdef DEBUGF5
6541 PrintS("DELETE!\n");
6542#endif
6543 strat->nrsyzcrit++;
6544 //printf("- T -\n\n");
6545 return TRUE;
6546 }
6547 }
6548 //printf("- F -\n\n");
6549 return FALSE;
6550}
6551
6552/*
6553 * SYZYGY CRITERION for signature-based standard basis algorithms
6554 */
6555BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6556{
6557//#if 1
6558 if(sig == NULL)
6559 return FALSE;
6560#ifdef DEBUGF5
6561 PrintS("--- syzygy criterion checks: ");
6562 pWrite(sig);
6563#endif
6564 int comp = (int)__p_GetComp(sig, currRing);
6565 int min, max;
6566 if (comp<=1)
6567 return FALSE;
6568 else
6569 {
6570 min = strat->syzIdx[comp-2];
6571 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
6572 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
6573 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
6574 if (comp == strat->currIdx)
6575 {
6576 max = strat->syzl;
6577 }
6578 else
6579 {
6580 max = strat->syzIdx[comp-1];
6581 }
6582 for (int k=min; k<max; k++)
6583 {
6584#ifdef F5DEBUG
6585 Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
6586 Print("checking with: %d -- ",k);
6587 pWrite(pHead(strat->syz[k]));
6588#endif
6589 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6590 && (!rField_is_Ring(currRing) ||
6591 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6592 {
6593 strat->nrsyzcrit++;
6594 return TRUE;
6595 }
6596 }
6597 return FALSE;
6598 }
6599}
6600
6601/*
6602 * REWRITTEN CRITERION for signature-based standard basis algorithms
6603 */
6604BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
6605{
6606 //printf("Faugere Rewritten Criterion\n");
6608 return FALSE;
6609//#if 1
6610#ifdef DEBUGF5
6611 PrintS("rewritten criterion checks: ");
6612 pWrite(sig);
6613#endif
6614 for(int k = strat->sl; k>=start; k--)
6615 {
6616//#if 1
6617#ifdef DEBUGF5
6618 PrintS("checking with: ");
6619 pWrite(strat->sig[k]);
6620 pWrite(pHead(strat->S[k]));
6621#endif
6622 if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
6623 {
6624//#if 1
6625#ifdef DEBUGF5
6626 PrintS("DELETE!\n");
6627#endif
6628 strat->nrrewcrit++;
6629 return TRUE;
6630 }
6631 //k--;
6632 }
6633#ifdef DEBUGF5
6634 PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
6635 for(int kk = 0; kk<strat->sl+1; kk++)
6636 {
6637 pWrite(pHead(strat->S[kk]));
6638 }
6639 PrintS("------------------------------\n");
6640#endif
6641 return FALSE;
6642}
6643
6644/*
6645 * REWRITTEN CRITERION for signature-based standard basis algorithms
6646 ***************************************************************************
6647 * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
6648 ***************************************************************************
6649 */
6650
6651// real implementation of arri's rewritten criterion, only called once in
6652// kstd2.cc, right before starting reduction
6653// IDEA: Arri says that it is enough to consider 1 polynomial for each unique
6654// signature appearing during the computations. Thus we first of all go
6655// through strat->L and delete all other pairs of the same signature,
6656// keeping only the one with least possible leading monomial. After this
6657// we check if we really need to compute this critical pair at all: There
6658// can be elements already in strat->S whose signatures divide the
6659// signature of the critical pair in question and whose multiplied
6660// leading monomials are smaller than the leading monomial of the
6661// critical pair. In this situation we can discard the critical pair
6662// completely.
6663BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
6664{
6666 return FALSE;
6667 poly p1 = pOne();
6668 poly p2 = pOne();
6669 for (int ii=strat->sl; ii>start; ii--)
6670 {
6671 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
6672 {
6673 p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
6674 p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
6675 if (!(pLmCmp(p1,p2) == 1))
6676 {
6677 pDelete(&p1);
6678 pDelete(&p2);
6679 return TRUE;
6680 }
6681 }
6682 }
6683 pDelete(&p1);
6684 pDelete(&p2);
6685 return FALSE;
6686}
6687
6688BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
6689{
6690 //Over Rings, there are still some changes to do: considering coeffs
6692 return FALSE;
6693 int found = -1;
6694 for (int i=strat->Bl; i>-1; i--)
6695 {
6696 if (pLmEqual(strat->B[i].sig,sig))
6697 {
6698 found = i;
6699 break;
6700 }
6701 }
6702 if (found != -1)
6703 {
6704 if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
6705 {
6706 deleteInL(strat->B,&strat->Bl,found,strat);
6707 }
6708 else
6709 {
6710 return TRUE;
6711 }
6712 }
6713 poly p1 = pOne();
6714 poly p2 = pOne();
6715 for (int ii=strat->sl; ii>-1; ii--)
6716 {
6717 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
6718 {
6719 p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
6720 p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
6721 if (!(pLmCmp(p1,p2) == 1))
6722 {
6723 pDelete(&p1);
6724 pDelete(&p2);
6725 return TRUE;
6726 }
6727 }
6728 }
6729 pDelete(&p1);
6730 pDelete(&p2);
6731 return FALSE;
6732}
6733
6734/***************************************************************
6735 *
6736 * Tail reductions
6737 *
6738 ***************************************************************/
6740{
6741 int j = 0;
6742 const unsigned long not_sev = ~L->sev;
6743 const unsigned long* sev = strat->sevS;
6744 poly p;
6745 ring r;
6746 L->GetLm(p, r);
6747
6749
6750 if (r == currRing)
6751 {
6752 if(!rField_is_Ring(r))
6753 {
6754 loop
6755 {
6756 if (j > end_pos) return NULL;
6757 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6758 if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
6759 (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6760 #else
6761 if (!(sev[j] & not_sev) &&
6762 (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
6763 p_LmDivisibleBy(strat->S[j], p, r))
6764 #endif
6765 {
6766 break;
6767 }
6768 j++;
6769 }
6770 }
6771 #ifdef HAVE_RINGS
6772 else
6773 {
6774 loop
6775 {
6776 if (j > end_pos) return NULL;
6777 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6778 if (strat->S[j]!= NULL
6779 && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r)
6780 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6781 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6782 #else
6783 if (!(sev[j] & not_sev)
6784 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6785 && p_LmDivisibleBy(strat->S[j], p, r)
6786 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6787 #endif
6788 {
6789 break; // found
6790 }
6791 j++;
6792 }
6793 }
6794 #endif
6795 // if called from NF, T objects do not exist:
6796 if (strat->tl < 0 || strat->S_2_R[j] == -1)
6797 {
6798 T->Set(strat->S[j], r, strat->tailRing);
6799 assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
6800 return T;
6801 }
6802 else
6803 {
6804///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
6805///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
6806// assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
6807 return strat->S_2_T(j);
6808 }
6809 }
6810 else
6811 {
6812 TObject* t;
6813 if(!rField_is_Ring(r))
6814 {
6815 loop
6816 {
6817 if (j > end_pos) return NULL;
6818 assume(strat->S_2_R[j] != -1);
6819 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6820 t = strat->S_2_T(j);
6821 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6822 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6823 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6824 {
6825 t->pLength=pLength(t->t_p);
6826 return t;
6827 }
6828 #else
6829 if (! (sev[j] & not_sev)
6830 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6831 {
6832 t = strat->S_2_T(j);
6833 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6834 if (p_LmDivisibleBy(t->t_p, p, r))
6835 {
6836 t->pLength=pLength(t->t_p);
6837 return t;
6838 }
6839 }
6840 #endif
6841 j++;
6842 }
6843 }
6844 #ifdef HAVE_RINGS
6845 else
6846 {
6847 loop
6848 {
6849 if (j > end_pos) return NULL;
6850 assume(strat->S_2_R[j] != -1);
6851 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6852 t = strat->S_2_T(j);
6853 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6854 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6855 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6856 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6857 {
6858 t->pLength=pLength(t->t_p);
6859 return t;
6860 }
6861 #else
6862 if (! (sev[j] & not_sev)
6863 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6864 {
6865 t = strat->S_2_T(j);
6866 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6867 if (p_LmDivisibleBy(t->t_p, p, r)
6868 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6869 {
6870 t->pLength=pLength(t->t_p);
6871 return t;
6872 }
6873 }
6874 #endif
6875 j++;
6876 }
6877 }
6878 #endif
6879 }
6880}
6881
6882poly redtail (LObject* L, int end_pos, kStrategy strat)
6883{
6884 poly h, hn;
6885 strat->redTailChange=FALSE;
6886
6887 L->GetP();
6888 poly p = L->p;
6889 if (strat->noTailReduction || pNext(p) == NULL)
6890 return p;
6891
6892 LObject Ln(strat->tailRing);
6893 TObject* With;
6894 // placeholder in case strat->tl < 0
6895 TObject With_s(strat->tailRing);
6896 h = p;
6897 hn = pNext(h);
6898 long op = strat->tailRing->pFDeg(hn, strat->tailRing);
6899 long e;
6900 int l;
6901 BOOLEAN save_HE=strat->kAllAxis;
6902 strat->kAllAxis |=
6903 ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
6904
6905 while(hn != NULL)
6906 {
6907 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6908 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6909 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6910 loop
6911 {
6912 Ln.Set(hn, strat->tailRing);
6913 Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
6914 if (strat->kAllAxis)
6916 else
6917 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
6918 if (With == NULL) break;
6919 With->length=0;
6920 With->pLength=0;
6921 strat->redTailChange=TRUE;
6922 if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
6923 {
6924 // reducing the tail would violate the exp bound
6925 if (kStratChangeTailRing(strat, L))
6926 {
6927 strat->kAllAxis = save_HE;
6928 return redtail(L, end_pos, strat);
6929 }
6930 else
6931 return NULL;
6932 }
6933 hn = pNext(h);
6934 if (hn == NULL) goto all_done;
6935 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6936 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6937 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6938 }
6939 h = hn;
6940 hn = pNext(h);
6941 }
6942
6943 all_done:
6944 if (strat->redTailChange)
6945 {
6946 L->pLength = 0;
6947 }
6948 strat->kAllAxis = save_HE;
6949 return p;
6950}
6951
6952poly redtail (poly p, int end_pos, kStrategy strat)
6953{
6954 LObject L(p, currRing);
6955 return redtail(&L, end_pos, strat);
6956}
6957
6959{
6960 strat->redTailChange=FALSE;
6961 if (strat->noTailReduction) return L->GetLmCurrRing();
6962 poly h, p;
6963 p = h = L->GetLmTailRing();
6964 if ((h==NULL) || (pNext(h)==NULL))
6965 return L->GetLmCurrRing();
6966
6967 TObject* With;
6968 // placeholder in case strat->tl < 0
6969 TObject With_s(strat->tailRing);
6970
6971 LObject Ln(pNext(h), strat->tailRing);
6972 Ln.GetpLength();
6973
6974 pNext(h) = NULL;
6975 if (L->p != NULL)
6976 {
6977 pNext(L->p) = NULL;
6978 if (L->t_p != NULL) pNext(L->t_p) = NULL;
6979 }
6980 L->pLength = 1;
6981
6982 Ln.PrepareRed(strat->use_buckets);
6983
6984 int cnt=REDTAIL_CANONICALIZE;
6985 while(!Ln.IsNull())
6986 {
6987 loop
6988 {
6989 if (TEST_OPT_IDLIFT)
6990 {
6991 if (Ln.p!=NULL)
6992 {
6993 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
6994 }
6995 else
6996 {
6997 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
6998 }
6999 }
7000 Ln.SetShortExpVector();
7001 if (withT)
7002 {
7003 int j;
7004 j = kFindDivisibleByInT(strat, &Ln);
7005 if (j < 0) break;
7006 With = &(strat->T[j]);
7007 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7008 }
7009 else
7010 {
7012 if (With == NULL) break;
7013 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7014 }
7015 cnt--;
7016 if (cnt==0)
7017 {
7019 /*poly tmp=*/Ln.CanonicalizeP();
7020 if (normalize)
7021 {
7022 Ln.Normalize();
7023 //pNormalize(tmp);
7024 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7025 }
7026 }
7027 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7028 {
7029 With->pNorm();
7030 }
7031 strat->redTailChange=TRUE;
7032 if (ksReducePolyTail(L, With, &Ln))
7033 {
7034 // reducing the tail would violate the exp bound
7035 // set a flag and hope for a retry (in bba)
7037 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7038 do
7039 {
7040 pNext(h) = Ln.LmExtractAndIter();
7041 pIter(h);
7042 L->pLength++;
7043 } while (!Ln.IsNull());
7044 goto all_done;
7045 }
7046 if (Ln.IsNull()) goto all_done;
7047 if (! withT) With_s.Init(currRing);
7048 }
7049 pNext(h) = Ln.LmExtractAndIter();
7050 pIter(h);
7051 pNormalize(h);
7052 L->pLength++;
7053 }
7054
7055 all_done:
7056 Ln.Delete();
7057 if (L->p != NULL) pNext(L->p) = pNext(p);
7058
7059 if (strat->redTailChange)
7060 {
7061 L->length = 0;
7062 L->pLength = 0;
7063 }
7064
7065 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7066 //L->Normalize(); // HANNES: should have a test
7067 kTest_L(L,strat);
7068 return L->GetLmCurrRing();
7069}
7070
7072{
7073 strat->redTailChange=FALSE;
7074 if (strat->noTailReduction) return L->GetLmCurrRing();
7075 poly h, p;
7076 p = h = L->GetLmTailRing();
7077 if ((h==NULL) || (pNext(h)==NULL))
7078 return L->GetLmCurrRing();
7079
7080 TObject* With;
7081 // placeholder in case strat->tl < 0
7082 TObject With_s(strat->tailRing);
7083
7084 LObject Ln(pNext(h), strat->tailRing);
7085 Ln.pLength = L->GetpLength() - 1;
7086
7087 pNext(h) = NULL;
7088 if (L->p != NULL) pNext(L->p) = NULL;
7089 L->pLength = 1;
7090
7091 Ln.PrepareRed(strat->use_buckets);
7092
7093 int cnt=REDTAIL_CANONICALIZE;
7094 while(!Ln.IsNull())
7095 {
7096 loop
7097 {
7098 if (TEST_OPT_IDLIFT)
7099 {
7100 if (Ln.p!=NULL)
7101 {
7102 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7103 }
7104 else
7105 {
7106 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7107 }
7108 }
7109 Ln.SetShortExpVector();
7110 if (withT)
7111 {
7112 int j;
7113 j = kFindDivisibleByInT(strat, &Ln);
7114 if (j < 0) break;
7115 With = &(strat->T[j]);
7116 }
7117 else
7118 {
7120 if (With == NULL) break;
7121 }
7122 cnt--;
7123 if (cnt==0)
7124 {
7126 /*poly tmp=*/Ln.CanonicalizeP();
7127 if (normalize)
7128 {
7129 Ln.Normalize();
7130 //pNormalize(tmp);
7131 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7132 }
7133 }
7134 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7135 {
7136 With->pNorm();
7137 }
7138 strat->redTailChange=TRUE;
7139 if (ksReducePolyTail(L, With, &Ln))
7140 {
7141 // reducing the tail would violate the exp bound
7142 // set a flag and hope for a retry (in bba)
7144 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7145 do
7146 {
7147 pNext(h) = Ln.LmExtractAndIter();
7148 pIter(h);
7149 L->pLength++;
7150 } while (!Ln.IsNull());
7151 goto all_done;
7152 }
7153 if(!Ln.IsNull())
7154 {
7155 Ln.GetP();
7156 Ln.p = pJet(Ln.p,bound);
7157 }
7158 if (Ln.IsNull())
7159 {
7160 goto all_done;
7161 }
7162 if (! withT) With_s.Init(currRing);
7163 }
7164 pNext(h) = Ln.LmExtractAndIter();
7165 pIter(h);
7166 pNormalize(h);
7167 L->pLength++;
7168 }
7169
7170 all_done:
7171 Ln.Delete();
7172 if (L->p != NULL) pNext(L->p) = pNext(p);
7173
7174 if (strat->redTailChange)
7175 {
7176 L->length = 0;
7177 L->pLength = 0;
7178 }
7179
7180 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7181 //L->Normalize(); // HANNES: should have a test
7182 kTest_L(L,strat);
7183 return L->GetLmCurrRing();
7184}
7185
7186#ifdef HAVE_RINGS
7188// normalize=FALSE, withT=FALSE, coeff=Z
7189{
7190 strat->redTailChange=FALSE;
7191
7192 poly h, p;
7193 p = h = L->GetLmTailRing();
7194 if ((h==NULL) || (pNext(h)==NULL))
7195 return;
7196
7197 TObject* With;
7198 LObject Ln(pNext(h), strat->tailRing);
7199 Ln.GetpLength();
7200
7201 pNext(h) = NULL;
7202 if (L->p != NULL)
7203 {
7204 pNext(L->p) = NULL;
7205 if (L->t_p != NULL) pNext(L->t_p) = NULL;
7206 }
7207 L->pLength = 1;
7208
7209 Ln.PrepareRed(strat->use_buckets);
7210
7211 int cnt=REDTAIL_CANONICALIZE;
7212
7213 while(!Ln.IsNull())
7214 {
7215 loop
7216 {
7217 if (TEST_OPT_IDLIFT)
7218 {
7219 if (Ln.p!=NULL)
7220 {
7221 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7222 }
7223 else
7224 {
7225 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7226 }
7227 }
7228 Ln.SetShortExpVector();
7229 int j;
7230 j = kFindDivisibleByInT(strat, &Ln);
7231 if (j < 0)
7232 {
7233 j = kFindDivisibleByInT_Z(strat, &Ln);
7234 if (j < 0)
7235 {
7236 break;
7237 }
7238 else
7239 {
7240 /* reduction not cancelling a tail term, but reducing its coefficient */
7241 With = &(strat->T[j]);
7242 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7243 cnt--;
7244 if (cnt==0)
7245 {
7247 /*poly tmp=*/Ln.CanonicalizeP();
7248 }
7249 strat->redTailChange=TRUE;
7250 /* reduction cancelling a tail term */
7251 if (ksReducePolyTailLC_Z(L, With, &Ln))
7252 {
7253 // reducing the tail would violate the exp bound
7254 // set a flag and hope for a retry (in bba)
7256 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7257 do
7258 {
7259 pNext(h) = Ln.LmExtractAndIter();
7260 pIter(h);
7261 L->pLength++;
7262 } while (!Ln.IsNull());
7263 goto all_done;
7264 }
7265 /* we have to break since we did not cancel the term, but only decreased
7266 * its coefficient. */
7267 break;
7268 }
7269 } else {
7270 With = &(strat->T[j]);
7271 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7272 cnt--;
7273 if (cnt==0)
7274 {
7276 /*poly tmp=*/Ln.CanonicalizeP();
7277 }
7278 strat->redTailChange=TRUE;
7279 /* reduction cancelling a tail term */
7280 if (ksReducePolyTail_Z(L, With, &Ln))
7281 {
7282 // reducing the tail would violate the exp bound
7283 // set a flag and hope for a retry (in bba)
7285 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7286 do
7287 {
7288 pNext(h) = Ln.LmExtractAndIter();
7289 pIter(h);
7290 L->pLength++;
7291 } while (!Ln.IsNull());
7292 goto all_done;
7293 }
7294 }
7295 if (Ln.IsNull()) goto all_done;
7296 }
7297 pNext(h) = Ln.LmExtractAndIter();
7298 pIter(h);
7299 L->pLength++;
7300 }
7301
7302 all_done:
7303 Ln.Delete();
7304 if (L->p != NULL) pNext(L->p) = pNext(p);
7305
7306 if (strat->redTailChange)
7307 {
7308 L->length = 0;
7309 L->pLength = 0;
7310 }
7311
7312 kTest_L(L, strat);
7313 return;
7314}
7315
7317// normalize=FALSE, withT=FALSE, coeff=Z
7318{
7319 strat->redTailChange=FALSE;
7320 if (strat->noTailReduction) return L->GetLmCurrRing();
7321 poly h, p;
7322 p = h = L->GetLmTailRing();
7323 if ((h==NULL) || (pNext(h)==NULL))
7324 return L->GetLmCurrRing();
7325
7326 TObject* With;
7327 // placeholder in case strat->tl < 0
7328 TObject With_s(strat->tailRing);
7329
7330 LObject Ln(pNext(h), strat->tailRing);
7331 Ln.pLength = L->GetpLength() - 1;
7332
7333 pNext(h) = NULL;
7334 if (L->p != NULL) pNext(L->p) = NULL;
7335 L->pLength = 1;
7336
7337 Ln.PrepareRed(strat->use_buckets);
7338
7339 int cnt=REDTAIL_CANONICALIZE;
7340 while(!Ln.IsNull())
7341 {
7342 loop
7343 {
7344 Ln.SetShortExpVector();
7346 if (With == NULL) break;
7347 cnt--;
7348 if (cnt==0)
7349 {
7351 /*poly tmp=*/Ln.CanonicalizeP();
7352 }
7353 // we are in Z, do not call pNorm
7354 strat->redTailChange=TRUE;
7355 // test divisibility of coefs:
7356 poly p_Ln=Ln.GetLmCurrRing();
7357 poly p_With=With->GetLmCurrRing();
7358
7359 if (ksReducePolyTail_Z(L, With, &Ln))
7360 {
7361 // reducing the tail would violate the exp bound
7362 // set a flag and hope for a retry (in bba)
7364 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7365 do
7366 {
7367 pNext(h) = Ln.LmExtractAndIter();
7368 pIter(h);
7369 L->pLength++;
7370 } while (!Ln.IsNull());
7371 goto all_done;
7372 }
7373 if (Ln.IsNull()) goto all_done;
7374 With_s.Init(currRing);
7375 }
7376 pNext(h) = Ln.LmExtractAndIter();
7377 pIter(h);
7378 pNormalize(h);
7379 L->pLength++;
7380 }
7381
7382 all_done:
7383 Ln.Delete();
7384 if (L->p != NULL) pNext(L->p) = pNext(p);
7385
7386 if (strat->redTailChange)
7387 {
7388 L->length = 0;
7389 }
7390
7391 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7392 //L->Normalize(); // HANNES: should have a test
7393 kTest_L(L,strat);
7394 return L->GetLmCurrRing();
7395}
7396
7397poly redtailBba_NF (poly p, kStrategy strat )
7398{
7399 strat->redTailChange=FALSE;
7400 if (strat->noTailReduction) return p;
7401 if ((p==NULL) || (pNext(p)==NULL))
7402 return p;
7403
7404 int max_ind;
7405 poly h=p;
7406 p=pNext(p);
7407 pNext(h)=NULL;
7408 while(p!=NULL)
7409 {
7410 p=redNF(p,max_ind,1,strat);
7411 if (p!=NULL)
7412 {
7413 poly hh=p;
7414 p=pNext(p);
7415 pNext(hh)=NULL;
7417 }
7418 }
7419 return h;
7420}
7421
7423// normalize=FALSE, withT=FALSE, coeff=Ring
7424{
7425 strat->redTailChange=FALSE;
7426 if (strat->noTailReduction) return L->GetLmCurrRing();
7427 poly h, p;
7428 p = h = L->GetLmTailRing();
7429 if ((h==NULL) || (pNext(h)==NULL))
7430 return L->GetLmCurrRing();
7431
7432 TObject* With;
7433 // placeholder in case strat->tl < 0
7434 TObject With_s(strat->tailRing);
7435
7436 LObject Ln(pNext(h), strat->tailRing);
7437 Ln.pLength = L->GetpLength() - 1;
7438
7439 pNext(h) = NULL;
7440 if (L->p != NULL) pNext(L->p) = NULL;
7441 L->pLength = 1;
7442
7443 Ln.PrepareRed(strat->use_buckets);
7444
7445 int cnt=REDTAIL_CANONICALIZE;
7446 while(!Ln.IsNull())
7447 {
7448 loop
7449 {
7450 Ln.SetShortExpVector();
7451 With_s.Init(currRing);
7453 if (With == NULL) break;
7454 cnt--;
7455 if (cnt==0)
7456 {
7458 /*poly tmp=*/Ln.CanonicalizeP();
7459 }
7460 // we are in a ring, do not call pNorm
7461 // test divisibility of coefs:
7462 poly p_Ln=Ln.GetLmCurrRing();
7463 poly p_With=With->GetLmCurrRing();
7465 {
7466 strat->redTailChange=TRUE;
7467
7468 if (ksReducePolyTail_Z(L, With, &Ln))
7469 {
7470 // reducing the tail would violate the exp bound
7471 // set a flag and hope for a retry (in bba)
7473 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7474 do
7475 {
7476 pNext(h) = Ln.LmExtractAndIter();
7477 pIter(h);
7478 L->pLength++;
7479 } while (!Ln.IsNull());
7480 goto all_done;
7481 }
7482 }
7483 else break; /*proceed to next monomial*/
7484 if (Ln.IsNull()) goto all_done;
7485 }
7486 pNext(h) = Ln.LmExtractAndIter();
7487 pIter(h);
7488 pNormalize(h);
7489 L->pLength++;
7490 }
7491
7492 all_done:
7493 Ln.Delete();
7494 if (L->p != NULL) pNext(L->p) = pNext(p);
7495
7496 if (strat->redTailChange)
7497 {
7498 L->length = 0;
7499 }
7500
7501 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7502 //L->Normalize(); // HANNES: should have a test
7503 kTest_L(L,strat);
7504 return L->GetLmCurrRing();
7505}
7506#endif
7507
7508/*2
7509*checks the change degree and write progress report
7510*/
7511void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7512{
7513 if (i != *olddeg)
7514 {
7515 Print("%d",i);
7516 *olddeg = i;
7517 }
7518 if (TEST_OPT_OLDSTD)
7519 {
7520 if (strat->Ll != *reduc)
7521 {
7522 if (strat->Ll != *reduc-1)
7523 Print("(%d)",strat->Ll+1);
7524 else
7525 PrintS("-");
7526 *reduc = strat->Ll;
7527 }
7528 else
7529 PrintS(".");
7530 mflush();
7531 }
7532 else
7533 {
7534 if (red_result == 0)
7535 PrintS("-");
7536 else if (red_result < 0)
7537 PrintS(".");
7538 if ((red_result > 0) || ((strat->Ll % 100)==99))
7539 {
7540 if (strat->Ll != *reduc && strat->Ll > 0)
7541 {
7542 Print("(%d)",strat->Ll+1);
7543 *reduc = strat->Ll;
7544 }
7545 }
7546 }
7547}
7548
7549/*2
7550*statistics
7551*/
7553{
7554 //PrintS("\nUsage/Allocation of temporary storage:\n");
7555 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7556 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7557 Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7558 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7559 #ifdef HAVE_SHIFTBBA
7560 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7561 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7562 #endif
7563}
7564
7566{
7567 //PrintS("\nUsage/Allocation of temporary storage:\n");
7568 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7569 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7570 Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7571 //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7572 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7573 #ifdef HAVE_SHIFTBBA
7574 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7575 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7576 #endif
7577}
7578
7579#ifdef KDEBUG
7580/*2
7581*debugging output: all internal sets, if changed
7582*for testing purpuse only/has to be changed for later use
7583*/
7585{
7586 int i;
7587 if (strat->news)
7588 {
7589 PrintS("set S");
7590 for (i=0; i<=strat->sl; i++)
7591 {
7592 Print("\n %d:",i);
7593 p_wrp(strat->S[i], currRing, strat->tailRing);
7594 if (strat->fromQ!=NULL && strat->fromQ[i])
7595 Print(" (from Q)");
7596 }
7597 strat->news = FALSE;
7598 }
7599 if (strat->newt)
7600 {
7601 PrintS("\nset T");
7602 for (i=0; i<=strat->tl; i++)
7603 {
7604 Print("\n %d:",i);
7605 strat->T[i].wrp();
7606 if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7607 Print(" o:%ld e:%d l:%d",
7608 strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7609 }
7610 strat->newt = FALSE;
7611 }
7612 PrintS("\nset L");
7613 for (i=strat->Ll; i>=0; i--)
7614 {
7615 Print("\n%d:",i);
7616 p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7617 PrintS(" ");
7618 p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7619 PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7620 PrintS("\n p : ");
7621 strat->L[i].wrp();
7622 Print(" o:%ld e:%d l:%d",
7623 strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7624 }
7625 PrintLn();
7626}
7627
7628#endif
7629
7630
7631/*2
7632*construct the set s from F
7633*/
7634void initS (ideal F, ideal Q, kStrategy strat)
7635{
7636 int i,pos;
7637
7639 else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7640 strat->ecartS=initec(i);
7641 strat->sevS=initsevS(i);
7642 strat->S_2_R=initS_2_R(i);
7643 strat->fromQ=NULL;
7644 strat->Shdl=idInit(i,F->rank);
7645 strat->S=strat->Shdl->m;
7646 /*- put polys into S -*/
7647 if (Q!=NULL)
7648 {
7649 strat->fromQ=initec(i);
7650 memset(strat->fromQ,0,i*sizeof(int));
7651 for (i=0; i<IDELEMS(Q); i++)
7652 {
7653 if (Q->m[i]!=NULL)
7654 {
7655 LObject h;
7656 h.p = pCopy(Q->m[i]);
7658 {
7659 h.pCleardenom(); // also does remove Content
7660 }
7661 else
7662 {
7663 h.pNorm();
7664 }
7666 {
7667 deleteHC(&h, strat);
7668 }
7669 if (h.p!=NULL)
7670 {
7671 strat->initEcart(&h);
7672 if (strat->sl==-1)
7673 pos =0;
7674 else
7675 {
7676 pos = posInS(strat,strat->sl,h.p,h.ecart);
7677 }
7678 h.sev = pGetShortExpVector(h.p);
7679 strat->enterS(h,pos,strat,-1);
7680 strat->fromQ[pos]=1;
7681 }
7682 }
7683 }
7684 }
7685 for (i=0; i<IDELEMS(F); i++)
7686 {
7687 if (F->m[i]!=NULL)
7688 {
7689 LObject h;
7690 h.p = pCopy(F->m[i]);
7692 {
7693 cancelunit(&h); /*- tries to cancel a unit -*/
7694 deleteHC(&h, strat);
7695 }
7696 if (h.p!=NULL)
7697 // do not rely on the input being a SB!
7698 {
7700 {
7701 h.pCleardenom(); // also does remove Content
7702 }
7703 else
7704 {
7705 h.pNorm();
7706 }
7707 strat->initEcart(&h);
7708 if (strat->sl==-1)
7709 pos =0;
7710 else
7711 pos = posInS(strat,strat->sl,h.p,h.ecart);
7712 h.sev = pGetShortExpVector(h.p);
7713 strat->enterS(h,pos,strat,-1);
7714 }
7715 }
7716 }
7717 /*- test, if a unit is in F -*/
7718 if ((strat->sl>=0)
7720 && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7721#endif
7722 && pIsConstant(strat->S[0]))
7723 {
7724 while (strat->sl>0) deleteInS(strat->sl,strat);
7725 }
7726}
7727
7729{
7730 int i,pos;
7731
7733 else i=setmaxT;
7734 strat->ecartS=initec(i);
7735 strat->sevS=initsevS(i);
7736 strat->S_2_R=initS_2_R(i);
7737 strat->fromQ=NULL;
7738 strat->Shdl=idInit(i,F->rank);
7739 strat->S=strat->Shdl->m;
7740 /*- put polys into S -*/
7741 if (Q!=NULL)
7742 {
7743 strat->fromQ=initec(i);
7744 memset(strat->fromQ,0,i*sizeof(int));
7745 for (i=0; i<IDELEMS(Q); i++)
7746 {
7747 if (Q->m[i]!=NULL)
7748 {
7749 LObject h;
7750 h.p = pCopy(Q->m[i]);
7752 {
7753 deleteHC(&h,strat);
7754 }
7756 {
7757 h.pCleardenom(); // also does remove Content
7758 }
7759 else
7760 {
7761 h.pNorm();
7762 }
7763 if (h.p!=NULL)
7764 {
7765 strat->initEcart(&h);
7766 if (strat->sl==-1)
7767 pos =0;
7768 else
7769 {
7770 pos = posInS(strat,strat->sl,h.p,h.ecart);
7771 }
7772 h.sev = pGetShortExpVector(h.p);
7773 strat->enterS(h,pos,strat,-1);
7774 strat->fromQ[pos]=1;
7775 }
7776 }
7777 }
7778 }
7779 for (i=0; i<IDELEMS(F); i++)
7780 {
7781 if (F->m[i]!=NULL)
7782 {
7783 LObject h;
7784 h.p = pCopy(F->m[i]);
7785 if (h.p!=NULL)
7786 {
7788 {
7789 cancelunit(&h); /*- tries to cancel a unit -*/
7790 deleteHC(&h, strat);
7791 }
7792 if (h.p!=NULL)
7793 {
7795 {
7796 h.pCleardenom(); // also does remove Content
7797 }
7798 else
7799 {
7800 h.pNorm();
7801 }
7802 strat->initEcart(&h);
7803 if (strat->Ll==-1)
7804 pos =0;
7805 else
7806 pos = strat->posInL(strat->L,strat->Ll,&h,strat);
7807 h.sev = pGetShortExpVector(h.p);
7808 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7809 }
7810 }
7811 }
7812 }
7813 /*- test, if a unit is in F -*/
7814
7815 if ((strat->Ll>=0)
7817 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7818#endif
7819 && pIsConstant(strat->L[strat->Ll].p))
7820 {
7821 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7822 }
7823}
7824
7826{
7827 int i,pos;
7829 else i=setmaxT;
7830 strat->ecartS = initec(i);
7831 strat->sevS = initsevS(i);
7832 strat->sevSig = initsevS(i);
7833 strat->S_2_R = initS_2_R(i);
7834 strat->fromQ = NULL;
7835 strat->Shdl = idInit(i,F->rank);
7836 strat->S = strat->Shdl->m;
7837 strat->sig = (poly *)omAlloc0(i*sizeof(poly));
7838 if (strat->sbaOrder != 1)
7839 {
7840 strat->syz = (poly *)omAlloc0(i*sizeof(poly));
7841 strat->sevSyz = initsevS(i);
7842 strat->syzmax = i;
7843 strat->syzl = 0;
7844 }
7845 /*- put polys into S -*/
7846 if (Q!=NULL)
7847 {
7848 strat->fromQ=initec(i);
7849 memset(strat->fromQ,0,i*sizeof(int));
7850 for (i=0; i<IDELEMS(Q); i++)
7851 {
7852 if (Q->m[i]!=NULL)
7853 {
7854 LObject h;
7855 h.p = pCopy(Q->m[i]);
7857 {
7858 deleteHC(&h,strat);
7859 }
7861 {
7862 h.pCleardenom(); // also does remove Content
7863 }
7864 else
7865 {
7866 h.pNorm();
7867 }
7868 if (h.p!=NULL)
7869 {
7870 strat->initEcart(&h);
7871 if (strat->sl==-1)
7872 pos =0;
7873 else
7874 {
7875 pos = posInS(strat,strat->sl,h.p,h.ecart);
7876 }
7877 h.sev = pGetShortExpVector(h.p);
7878 strat->enterS(h,pos,strat,-1);
7879 strat->fromQ[pos]=1;
7880 }
7881 }
7882 }
7883 }
7884 for (i=0; i<IDELEMS(F); i++)
7885 {
7886 if (F->m[i]!=NULL)
7887 {
7888 LObject h;
7889 h.p = pCopy(F->m[i]);
7890 h.sig = pOne();
7891 //h.sig = pInit();
7892 //p_SetCoeff(h.sig,nInit(1),currRing);
7893 p_SetComp(h.sig,i+1,currRing);
7894 // if we are working with the Schreyer order we generate it
7895 // by multiplying the initial signatures with the leading monomial
7896 // of the corresponding initial polynomials generating the ideal
7897 // => we can keep the underlying monomial order and get a Schreyer
7898 // order without any bigger overhead
7899 if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
7900 {
7901 p_ExpVectorAdd (h.sig,F->m[i],currRing);
7902 }
7903 h.sevSig = pGetShortExpVector(h.sig);
7904#ifdef DEBUGF5
7905 pWrite(h.p);
7906 pWrite(h.sig);
7907#endif
7908 if (h.p!=NULL)
7909 {
7911 {
7912 cancelunit(&h); /*- tries to cancel a unit -*/
7913 deleteHC(&h, strat);
7914 }
7915 if (h.p!=NULL)
7916 {
7918 {
7919 h.pCleardenom(); // also does remove Content
7920 }
7921 else
7922 {
7923 h.pNorm();
7924 }
7925 strat->initEcart(&h);
7926 if (strat->Ll==-1)
7927 pos =0;
7928 else
7929 pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
7930 h.sev = pGetShortExpVector(h.p);
7931 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7932 }
7933 }
7934 /*
7935 if (strat->sbaOrder != 1)
7936 {
7937 for(j=0;j<i;j++)
7938 {
7939 strat->syz[ctr] = pCopy(F->m[j]);
7940 p_SetCompP(strat->syz[ctr],i+1,currRing);
7941 // add LM(F->m[i]) to the signature to get a Schreyer order
7942 // without changing the underlying polynomial ring at all
7943 p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
7944 // since p_Add_q() destroys all input
7945 // data we need to recreate help
7946 // each time
7947 poly help = pCopy(F->m[i]);
7948 p_SetCompP(help,j+1,currRing);
7949 pWrite(strat->syz[ctr]);
7950 pWrite(help);
7951 printf("%d\n",pLmCmp(strat->syz[ctr],help));
7952 strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
7953 printf("%d. SYZ ",ctr);
7954 pWrite(strat->syz[ctr]);
7955 strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
7956 ctr++;
7957 }
7958 strat->syzl = ps;
7959 }
7960 */
7961 }
7962 }
7963 /*- test, if a unit is in F -*/
7964
7965 if ((strat->Ll>=0)
7967 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7968#endif
7969 && pIsConstant(strat->L[strat->Ll].p))
7970 {
7971 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7972 }
7973}
7974
7976{
7977 if( strat->S[0] )
7978 {
7979 if( strat->S[1] && !rField_is_Ring(currRing))
7980 {
7981 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
7982 omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
7983 omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
7984 }
7985 int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
7986 /************************************************************
7987 * computing the length of the syzygy array needed
7988 ***********************************************************/
7989 for(i=1; i<=strat->sl; i++)
7990 {
7991 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
7992 {
7993 ps += i;
7994 }
7995 }
7996 ps += strat->sl+1;
7997 //comp = pGetComp (strat->P.sig);
7998 comp = strat->currIdx;
7999 strat->syzIdx = initec(comp);
8000 strat->sevSyz = initsevS(ps);
8001 strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8002 strat->syzmax = ps;
8003 strat->syzl = 0;
8004 strat->syzidxmax = comp;
8005#if defined(DEBUGF5) || defined(DEBUGF51)
8006 PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8007#endif
8008 i = 1;
8009 j = 0;
8010 /************************************************************
8011 * generating the leading terms of the principal syzygies
8012 ***********************************************************/
8013 while (i <= strat->sl)
8014 {
8015 /**********************************************************
8016 * principal syzygies start with component index 2
8017 * the array syzIdx starts with index 0
8018 * => the rules for a signature with component comp start
8019 * at strat->syz[strat->syzIdx[comp-2]] !
8020 *********************************************************/
8021 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8022 {
8023 comp = pGetComp(strat->sig[i]);
8024 comp_old = pGetComp(strat->sig[i-1]);
8025 diff = comp - comp_old - 1;
8026 // diff should be zero, but sometimes also the initial generating
8027 // elements of the input ideal reduce to zero. then there is an
8028 // index-gap between the signatures. for these in-between signatures we
8029 // can safely set syzIdx[j] = 0 as no such element will be ever computed
8030 // in the following.
8031 // doing this, we keep the relation "j = comp - 2" alive, which makes
8032 // jumps way easier when checking criteria
8033 while (diff>0)
8034 {
8035 strat->syzIdx[j] = 0;
8036 diff--;
8037 j++;
8038 }
8039 strat->syzIdx[j] = ctr;
8040 j++;
8041 LObject Q;
8042 int pos;
8043 for (k = 0; k<i; k++)
8044 {
8045 Q.sig = pOne();
8048 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8049 p_SetCompP (Q.sig, comp, currRing);
8050 poly q = p_One(currRing);
8053 p_ExpVectorCopy(q,strat->S[i],currRing);
8054 q = p_Neg (q, currRing);
8055 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8056 Q.sig = p_Add_q (Q.sig, q, currRing);
8057 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8058 pos = posInSyz(strat, Q.sig);
8059 enterSyz(Q, strat, pos);
8060 ctr++;
8061 }
8062 }
8063 i++;
8064 }
8065 /**************************************************************
8066 * add syzygies for upcoming first element of new iteration step
8067 **************************************************************/
8068 comp = strat->currIdx;
8069 comp_old = pGetComp(strat->sig[i-1]);
8070 diff = comp - comp_old - 1;
8071 // diff should be zero, but sometimes also the initial generating
8072 // elements of the input ideal reduce to zero. then there is an
8073 // index-gap between the signatures. for these in-between signatures we
8074 // can safely set syzIdx[j] = 0 as no such element will be ever computed
8075 // in the following.
8076 // doing this, we keep the relation "j = comp - 2" alive, which makes
8077 // jumps way easier when checking criteria
8078 while (diff>0)
8079 {
8080 strat->syzIdx[j] = 0;
8081 diff--;
8082 j++;
8083 }
8084 strat->syzIdx[j] = ctr;
8085 LObject Q;
8086 int pos;
8087 for (k = 0; k<strat->sl+1; k++)
8088 {
8089 Q.sig = pOne();
8092 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8093 p_SetCompP (Q.sig, comp, currRing);
8094 poly q = p_One(currRing);
8096 p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8097 p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8098 q = p_Neg (q, currRing);
8099 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8100 Q.sig = p_Add_q (Q.sig, q, currRing);
8101 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8102 pos = posInSyz(strat, Q.sig);
8103 enterSyz(Q, strat, pos);
8104 ctr++;
8105 }
8106//#if 1
8107#ifdef DEBUGF5
8108 PrintS("Principal syzygies:\n");
8109 Print("syzl %d\n",strat->syzl);
8110 Print("syzmax %d\n",strat->syzmax);
8111 Print("ps %d\n",ps);
8112 PrintS("--------------------------------\n");
8113 for(i=0;i<=strat->syzl-1;i++)
8114 {
8115 Print("%d - ",i);
8116 pWrite(strat->syz[i]);
8117 }
8118 for(i=0;i<strat->currIdx;i++)
8119 {
8120 Print("%d - %d\n",i,strat->syzIdx[i]);
8121 }
8122 PrintS("--------------------------------\n");
8123#endif
8124 }
8125}
8126
8127/*2
8128*construct the set s from F and {P}
8129*/
8131{
8132 int i,pos;
8133
8135 else i=setmaxT;
8136 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8137 strat->ecartS=initec(i);
8138 strat->sevS=initsevS(i);
8139 strat->S_2_R=initS_2_R(i);
8140 strat->fromQ=NULL;
8141 strat->Shdl=idInit(i,F->rank);
8142 strat->S=strat->Shdl->m;
8143
8144 /*- put polys into S -*/
8145 if (Q!=NULL)
8146 {
8147 strat->fromQ=initec(i);
8148 memset(strat->fromQ,0,i*sizeof(int));
8149 for (i=0; i<IDELEMS(Q); i++)
8150 {
8151 if (Q->m[i]!=NULL)
8152 {
8153 LObject h;
8154 h.p = pCopy(Q->m[i]);
8155 //if (TEST_OPT_INTSTRATEGY)
8156 //{
8157 // h.pCleardenom(); // also does remove Content
8158 //}
8159 //else
8160 //{
8161 // h.pNorm();
8162 //}
8164 {
8165 deleteHC(&h,strat);
8166 }
8167 if (h.p!=NULL)
8168 {
8169 strat->initEcart(&h);
8170 if (strat->sl==-1)
8171 pos =0;
8172 else
8173 {
8174 pos = posInS(strat,strat->sl,h.p,h.ecart);
8175 }
8176 h.sev = pGetShortExpVector(h.p);
8177 strat->enterS(h,pos,strat, strat->tl+1);
8178 enterT(h, strat);
8179 strat->fromQ[pos]=1;
8180 }
8181 }
8182 }
8183 }
8184 /*- put polys into S -*/
8185 for (i=0; i<IDELEMS(F); i++)
8186 {
8187 if (F->m[i]!=NULL)
8188 {
8189 LObject h;
8190 h.p = pCopy(F->m[i]);
8192 {
8193 deleteHC(&h,strat);
8194 }
8195 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8196 {
8197 h.p=redtailBba(h.p,strat->sl,strat);
8198 }
8199 if (h.p!=NULL)
8200 {
8201 strat->initEcart(&h);
8202 if (strat->sl==-1)
8203 pos =0;
8204 else
8205 pos = posInS(strat,strat->sl,h.p,h.ecart);
8206 h.sev = pGetShortExpVector(h.p);
8207 strat->enterS(h,pos,strat, strat->tl+1);
8208 enterT(h,strat);
8209 }
8210 }
8211 }
8212 for (i=0; i<IDELEMS(P); i++)
8213 {
8214 if (P->m[i]!=NULL)
8215 {
8216 LObject h;
8217 h.p=pCopy(P->m[i]);
8219 {
8220 h.pCleardenom();
8221 }
8222 else
8223 {
8224 h.pNorm();
8225 }
8226 if(strat->sl>=0)
8227 {
8229 {
8230 h.p=redBba(h.p,strat->sl,strat);
8231 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8232 {
8233 h.p=redtailBba(h.p,strat->sl,strat);
8234 }
8235 }
8236 else
8237 {
8238 h.p=redMora(h.p,strat->sl,strat);
8239 }
8240 if(h.p!=NULL)
8241 {
8242 strat->initEcart(&h);
8244 {
8245 h.pCleardenom();
8246 }
8247 else
8248 {
8249 h.is_normalized = 0;
8250 h.pNorm();
8251 }
8252 h.sev = pGetShortExpVector(h.p);
8253 h.SetpFDeg();
8254 pos = posInS(strat,strat->sl,h.p,h.ecart);
8255 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8256 strat->enterS(h,pos,strat, strat->tl+1);
8257 enterT(h,strat);
8258 }
8259 }
8260 else
8261 {
8262 h.sev = pGetShortExpVector(h.p);
8263 strat->initEcart(&h);
8264 strat->enterS(h,0,strat, strat->tl+1);
8265 enterT(h,strat);
8266 }
8267 }
8268 }
8269}
8270/*2
8271*construct the set s from F and {P}
8272*/
8273
8275{
8276 int i,pos;
8277
8279 else i=setmaxT;
8280 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8281 strat->sevS=initsevS(i);
8282 strat->sevSig=initsevS(i);
8283 strat->S_2_R=initS_2_R(i);
8284 strat->fromQ=NULL;
8285 strat->Shdl=idInit(i,F->rank);
8286 strat->S=strat->Shdl->m;
8287 strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8288 /*- put polys into S -*/
8289 if (Q!=NULL)
8290 {
8291 strat->fromQ=initec(i);
8292 memset(strat->fromQ,0,i*sizeof(int));
8293 for (i=0; i<IDELEMS(Q); i++)
8294 {
8295 if (Q->m[i]!=NULL)
8296 {
8297 LObject h;
8298 h.p = pCopy(Q->m[i]);
8299 //if (TEST_OPT_INTSTRATEGY)
8300 //{
8301 // h.pCleardenom(); // also does remove Content
8302 //}
8303 //else
8304 //{
8305 // h.pNorm();
8306 //}
8308 {
8309 deleteHC(&h,strat);
8310 }
8311 if (h.p!=NULL)
8312 {
8313 strat->initEcart(&h);
8314 if (strat->sl==-1)
8315 pos =0;
8316 else
8317 {
8318 pos = posInS(strat,strat->sl,h.p,h.ecart);
8319 }
8320 h.sev = pGetShortExpVector(h.p);
8321 strat->enterS(h,pos,strat, strat->tl+1);
8322 enterT(h, strat);
8323 strat->fromQ[pos]=1;
8324 }
8325 }
8326 }
8327 }
8328 /*- put polys into S -*/
8329 for (i=0; i<IDELEMS(F); i++)
8330 {
8331 if (F->m[i]!=NULL)
8332 {
8333 LObject h;
8334 h.p = pCopy(F->m[i]);
8336 {
8337 deleteHC(&h,strat);
8338 }
8339 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8340 {
8341 h.p=redtailBba(h.p,strat->sl,strat);
8342 }
8343 if (h.p!=NULL)
8344 {
8345 strat->initEcart(&h);
8346 if (strat->sl==-1)
8347 pos =0;
8348 else
8349 pos = posInS(strat,strat->sl,h.p,h.ecart);
8350 h.sev = pGetShortExpVector(h.p);
8351 strat->enterS(h,pos,strat, strat->tl+1);
8352 enterT(h,strat);
8353 }
8354 }
8355 }
8356 for (i=0; i<IDELEMS(P); i++)
8357 {
8358 if (P->m[i]!=NULL)
8359 {
8360 LObject h;
8361 h.p=pCopy(P->m[i]);
8363 {
8364 h.pCleardenom();
8365 }
8366 else
8367 {
8368 h.pNorm();
8369 }
8370 if(strat->sl>=0)
8371 {
8373 {
8374 h.p=redBba(h.p,strat->sl,strat);
8375 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8376 {
8377 h.p=redtailBba(h.p,strat->sl,strat);
8378 }
8379 }
8380 else
8381 {
8382 h.p=redMora(h.p,strat->sl,strat);
8383 }
8384 if(h.p!=NULL)
8385 {
8386 strat->initEcart(&h);
8388 {
8389 h.pCleardenom();
8390 }
8391 else
8392 {
8393 h.is_normalized = 0;
8394 h.pNorm();
8395 }
8396 h.sev = pGetShortExpVector(h.p);
8397 h.SetpFDeg();
8398 pos = posInS(strat,strat->sl,h.p,h.ecart);
8399 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8400 strat->enterS(h,pos,strat, strat->tl+1);
8401 enterT(h,strat);
8402 }
8403 }
8404 else
8405 {
8406 h.sev = pGetShortExpVector(h.p);
8407 strat->initEcart(&h);
8408 strat->enterS(h,0,strat, strat->tl+1);
8409 enterT(h,strat);
8410 }
8411 }
8412 }
8413}
8414
8415/*2
8416* reduces h using the set S
8417* procedure used in cancelunit1
8418*/
8419static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8420{
8421 int j = 0;
8422 unsigned long not_sev = ~ pGetShortExpVector(h);
8423
8424 while (j <= maxIndex)
8425 {
8426 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8427 return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8428 else j++;
8429 }
8430 return h;
8431}
8432
8433/*2
8434*tests if p.p=monomial*unit and cancels the unit
8435*/
8436void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8437{
8438 int k;
8439 poly r,h,h1,q;
8440
8441 if (!pIsVector((*p).p) && ((*p).ecart != 0))
8442 {
8443#ifdef HAVE_RINGS
8444 // Leading coef have to be a unit: no
8445 // example 2x+4x2 should be simplified to 2x*(1+2x)
8446 // and 2 is not a unit in Z
8447 //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8448#endif
8449 k = 0;
8450 h1 = r = pCopy((*p).p);
8451 h =pNext(r);
8452 loop
8453 {
8454 if (h==NULL)
8455 {
8456 pDelete(&r);
8457 pDelete(&(pNext((*p).p)));
8458 (*p).ecart = 0;
8459 (*p).length = 1;
8460 (*p).pLength = 1;
8461 (*suc)=0;
8462 return;
8463 }
8464 if (!pDivisibleBy(r,h))
8465 {
8466 q=redBba1(h,index ,strat);
8467 if (q != h)
8468 {
8469 k++;
8470 pDelete(&h);
8471 pNext(h1) = h = q;
8472 }
8473 else
8474 {
8475 pDelete(&r);
8476 return;
8477 }
8478 }
8479 else
8480 {
8481 h1 = h;
8482 pIter(h);
8483 }
8484 if (k > 10)
8485 {
8486 pDelete(&r);
8487 return;
8488 }
8489 }
8490 }
8491}
8492
8493#if 0
8494/*2
8495* reduces h using the elements from Q in the set S
8496* procedure used in updateS
8497* must not be used for elements of Q or elements of an ideal !
8498*/
8499static poly redQ (poly h, int j, kStrategy strat)
8500{
8501 int start;
8502 unsigned long not_sev = ~ pGetShortExpVector(h);
8503 while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8504 start=j;
8505 while (j<=strat->sl)
8506 {
8507 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8508 {
8509 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8510 if (h==NULL) return NULL;
8511 j = start;
8513 }
8514 else j++;
8515 }
8516 return h;
8517}
8518#endif
8519
8520/*2
8521* reduces h using the set S
8522* procedure used in updateS
8523*/
8524static poly redBba (poly h,int maxIndex,kStrategy strat)
8525{
8526 int j = 0;
8527 unsigned long not_sev = ~ pGetShortExpVector(h);
8528
8529 while (j <= maxIndex)
8530 {
8531 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8532 {
8533 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8534 if (h==NULL) return NULL;
8535 j = 0;
8537 }
8538 else j++;
8539 }
8540 return h;
8541}
8542
8543/*2
8544* reduces h using the set S
8545*e is the ecart of h
8546*procedure used in updateS
8547*/
8548static poly redMora (poly h,int maxIndex,kStrategy strat)
8549{
8550 int j=0;
8551 int e,l;
8552 unsigned long not_sev = ~ pGetShortExpVector(h);
8553
8554 if (maxIndex >= 0)
8555 {
8556 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8557 do
8558 {
8559 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8560 && ((e >= strat->ecartS[j]) || (strat->kNoether!=NULL)))
8561 {
8562#ifdef KDEBUG
8563 if (TEST_OPT_DEBUG)
8564 {
8565 PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8566 }
8567#endif
8568 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8569#ifdef KDEBUG
8570 if(TEST_OPT_DEBUG)
8571 {
8572 PrintS(")\nto "); wrp(h); PrintLn();
8573 }
8574#endif
8575 // pDelete(&h);
8576 if (h == NULL) return NULL;
8577 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8578 j = 0;
8580 }
8581 else j++;
8582 }
8583 while (j <= maxIndex);
8584 }
8585 return h;
8586}
8587
8588/*2
8589*updates S:
8590*the result is a set of polynomials which are in
8591*normalform with respect to S
8592*/
8594{
8595 LObject h;
8596 int i, suc=0;
8597 poly redSi=NULL;
8599// Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8600// for (i=0; i<=(strat->sl); i++)
8601// {
8602// Print("s%d:",i);
8603// if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8604// pWrite(strat->S[i]);
8605// }
8606// Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8609 {
8610 while (suc != -1)
8611 {
8612 i=suc+1;
8613 while (i<=strat->sl)
8614 {
8615 change=FALSE;
8617 any_change = FALSE;
8618 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8619 {
8620 redSi = pHead(strat->S[i]);
8621 strat->S[i] = redBba(strat->S[i],i-1,strat);
8622 //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8623 // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8624 if (pCmp(redSi,strat->S[i])!=0)
8625 {
8626 change=TRUE;
8628 #ifdef KDEBUG
8629 if (TEST_OPT_DEBUG)
8630 {
8631 PrintS("reduce:");
8632 wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8633 }
8634 #endif
8635 if (TEST_OPT_PROT)
8636 {
8637 if (strat->S[i]==NULL)
8638 PrintS("V");
8639 else
8640 PrintS("v");
8641 mflush();
8642 }
8643 }
8644 pLmDelete(&redSi);
8645 if (strat->S[i]==NULL)
8646 {
8647 deleteInS(i,strat);
8648 i--;
8649 }
8650 else if (change)
8651 {
8653 {
8655 {
8656 number n;
8657 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8658 if (!nIsOne(n))
8659 {
8661 denom->n=nInvers(n);
8662 denom->next=DENOMINATOR_LIST;
8664 }
8665 nDelete(&n);
8666 }
8667 else
8668 {
8669 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8670 }
8671 }
8672 else
8673 {
8674 pNorm(strat->S[i]);
8675 }
8676 strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8677 }
8678 }
8679 i++;
8680 }
8681 if (any_change) reorderS(&suc,strat);
8682 else break;
8683 }
8684 if (toT)
8685 {
8686 for (i=0; i<=strat->sl; i++)
8687 {
8688 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8689 {
8690 h.p = redtailBba(strat->S[i],i-1,strat);
8692 {
8693 h.pCleardenom();// also does remove Content
8694 }
8695 }
8696 else
8697 {
8698 h.p = strat->S[i];
8699 }
8700 strat->initEcart(&h);
8701 if (strat->honey)
8702 {
8703 strat->ecartS[i] = h.ecart;
8704 }
8705 if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8706 else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8707 h.sev = strat->sevS[i];
8708 /*puts the elements of S also to T*/
8709 strat->initEcart(&h);
8710 /*if (toT) - already checked*/ enterT(h,strat);
8711 strat->S_2_R[i] = strat->tl;
8712#ifdef HAVE_SHIFTBBA
8713 if (/*(toT) && */(currRing->isLPring))
8714 enterTShift(h, strat);
8715#endif
8716 }
8717 }
8718 }
8719 else
8720 {
8721 while (suc != -1)
8722 {
8723 i=suc;
8724 while (i<=strat->sl)
8725 {
8726 change=FALSE;
8727 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8728 {
8729 redSi=pHead((strat->S)[i]);
8730 (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
8731 if ((strat->S)[i]==NULL)
8732 {
8733 deleteInS(i,strat);
8734 i--;
8735 }
8736 else if (pCmp((strat->S)[i],redSi)!=0)
8737 {
8739 h.p = strat->S[i];
8740 strat->initEcart(&h);
8741 strat->ecartS[i] = h.ecart;
8743 {
8745 {
8746 number n;
8747 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8748 if (!nIsOne(n))
8749 {
8751 denom->n=nInvers(n);
8752 denom->next=DENOMINATOR_LIST;
8754 }
8755 nDelete(&n);
8756 }
8757 else
8758 {
8759 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8760 }
8761 }
8762 else
8763 {
8764 pNorm(strat->S[i]); // == h.p
8765 }
8766 h.sev = pGetShortExpVector(h.p);
8767 strat->sevS[i] = h.sev;
8768 }
8769 pLmDelete(&redSi);
8770 kTest(strat);
8771 }
8772 i++;
8773 }
8774#ifdef KDEBUG
8775 kTest(strat);
8776#endif
8777 if (any_change) reorderS(&suc,strat);
8778 else { suc=-1; break; }
8779 if (h.p!=NULL)
8780 {
8781 if (!strat->kAllAxis)
8782 {
8783 /*strat->kAllAxis =*/ HEckeTest(h.p,strat);
8784 }
8785 if (strat->kAllAxis)
8786 newHEdge(strat);
8787 }
8788 }
8789 for (i=0; i<=strat->sl; i++)
8790 {
8791 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8792 {
8793 strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
8794 strat->initEcart(&h);
8795 strat->ecartS[i] = h.ecart;
8796 h.sev = pGetShortExpVector(h.p);
8797 strat->sevS[i] = h.sev;
8798 }
8799 else
8800 {
8801 h.p = strat->S[i];
8802 h.ecart=strat->ecartS[i];
8803 h.sev = strat->sevS[i];
8804 h.length = h.pLength = pLength(h.p);
8805 }
8806 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8807 cancelunit1(&h,&suc,strat->sl,strat);
8808 h.SetpFDeg();
8809 /*puts the elements of S also to T*/
8810 enterT(h,strat);
8811 strat->S_2_R[i] = strat->tl;
8812#ifdef HAVE_SHIFTBBA
8813 if (currRing->isLPring)
8814 enterTShift(h, strat);
8815#endif
8816 }
8817 if (suc!= -1) updateS(toT,strat);
8818 }
8819#ifdef KDEBUG
8820 kTest(strat);
8821#endif
8822}
8823
8824/*2
8825* -puts p to the standardbasis s at position at
8826* -saves the result in S
8827*/
8828void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
8829{
8830 strat->news = TRUE;
8831 /*- puts p to the standardbasis s at position at -*/
8832 if (strat->sl == IDELEMS(strat->Shdl)-1)
8833 {
8834 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8835 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8836 (IDELEMS(strat->Shdl)+setmaxTinc)
8837 *sizeof(unsigned long));
8838 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8839 IDELEMS(strat->Shdl)*sizeof(int),
8840 (IDELEMS(strat->Shdl)+setmaxTinc)
8841 *sizeof(int));
8842 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8843 IDELEMS(strat->Shdl)*sizeof(int),
8844 (IDELEMS(strat->Shdl)+setmaxTinc)
8845 *sizeof(int));
8846 if (strat->lenS!=NULL)
8847 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8848 IDELEMS(strat->Shdl)*sizeof(int),
8849 (IDELEMS(strat->Shdl)+setmaxTinc)
8850 *sizeof(int));
8851 if (strat->lenSw!=NULL)
8852 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8853 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8854 (IDELEMS(strat->Shdl)+setmaxTinc)
8855 *sizeof(wlen_type));
8856 if (strat->fromQ!=NULL)
8857 {
8858 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8859 IDELEMS(strat->Shdl)*sizeof(int),
8860 (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
8861 }
8862 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
8863 IDELEMS(strat->Shdl)+=setmaxTinc;
8864 strat->Shdl->m=strat->S;
8865 }
8866 if (atS <= strat->sl)
8867 {
8868#ifdef ENTER_USE_MEMMOVE
8869 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
8870 (strat->sl - atS + 1)*sizeof(poly));
8871 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
8872 (strat->sl - atS + 1)*sizeof(int));
8873 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
8874 (strat->sl - atS + 1)*sizeof(unsigned long));
8875 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
8876 (strat->sl - atS + 1)*sizeof(int));
8877 if (strat->lenS!=NULL)
8878 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
8879 (strat->sl - atS + 1)*sizeof(int));
8880 if (strat->lenSw!=NULL)
8881 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
8882 (strat->sl - atS + 1)*sizeof(wlen_type));
8883#else
8884 for (i=strat->sl+1; i>=atS+1; i--)
8885 {
8886 strat->S[i] = strat->S[i-1];
8887 strat->ecartS[i] = strat->ecartS[i-1];
8888 strat->sevS[i] = strat->sevS[i-1];
8889 strat->S_2_R[i] = strat->S_2_R[i-1];
8890 }
8891 if (strat->lenS!=NULL)
8892 for (i=strat->sl+1; i>=atS+1; i--)
8893 strat->lenS[i] = strat->lenS[i-1];
8894 if (strat->lenSw!=NULL)
8895 for (i=strat->sl+1; i>=atS+1; i--)
8896 strat->lenSw[i] = strat->lenSw[i-1];
8897#endif
8898 }
8899 if (strat->fromQ!=NULL)
8900 {
8901#ifdef ENTER_USE_MEMMOVE
8902 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
8903 (strat->sl - atS + 1)*sizeof(int));
8904#else
8905 for (i=strat->sl+1; i>=atS+1; i--)
8906 {
8907 strat->fromQ[i] = strat->fromQ[i-1];
8908 }
8909#endif
8910 strat->fromQ[atS]=0;
8911 }
8912
8913 /*- save result -*/
8914 poly pp=p.p;
8915 strat->S[atS] = pp;
8916 if (strat->honey) strat->ecartS[atS] = p.ecart;
8917 if (p.sev == 0)
8918 p.sev = pGetShortExpVector(pp);
8919 else
8920 assume(p.sev == pGetShortExpVector(pp));
8921 strat->sevS[atS] = p.sev;
8922 strat->ecartS[atS] = p.ecart;
8923 strat->S_2_R[atS] = atR;
8924 strat->sl++;
8925}
8926
8927#ifdef HAVE_SHIFTBBA
8928void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR)
8929{
8930 enterSBba(p, atS, strat, atR);
8931
8933 for (int i = maxPossibleShift; i > 0; i--)
8934 {
8935 // NOTE: don't use "shared tails" here. In rare cases it can cause problems
8936 // in `kNF2` because of lazy poly normalizations.
8937 LObject qq(p_Copy(p.p, strat->tailRing));
8938 p_mLPshift(qq.p, i, strat->tailRing);
8939 qq.shift = i;
8940 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
8941 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
8942 enterSBba(qq, atS, strat, -1);
8943 }
8944}
8945#endif
8946
8947/*2
8948* -puts p to the standardbasis s at position at
8949* -saves the result in S
8950*/
8951void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
8952{
8953 strat->news = TRUE;
8954 /*- puts p to the standardbasis s at position at -*/
8955 if (strat->sl == IDELEMS(strat->Shdl)-1)
8956 {
8957 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8958 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8959 (IDELEMS(strat->Shdl)+setmax)
8960 *sizeof(unsigned long));
8961 strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
8962 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8963 (IDELEMS(strat->Shdl)+setmax)
8964 *sizeof(unsigned long));
8965 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8966 IDELEMS(strat->Shdl)*sizeof(int),
8967 (IDELEMS(strat->Shdl)+setmax)
8968 *sizeof(int));
8969 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8970 IDELEMS(strat->Shdl)*sizeof(int),
8971 (IDELEMS(strat->Shdl)+setmax)
8972 *sizeof(int));
8973 if (strat->lenS!=NULL)
8974 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8975 IDELEMS(strat->Shdl)*sizeof(int),
8976 (IDELEMS(strat->Shdl)+setmax)
8977 *sizeof(int));
8978 if (strat->lenSw!=NULL)
8979 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8980 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8981 (IDELEMS(strat->Shdl)+setmax)
8982 *sizeof(wlen_type));
8983 if (strat->fromQ!=NULL)
8984 {
8985 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8986 IDELEMS(strat->Shdl)*sizeof(int),
8987 (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
8988 }
8989 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
8990 pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
8991 IDELEMS(strat->Shdl)+=setmax;
8992 strat->Shdl->m=strat->S;
8993 }
8994 // in a signature-based algorithm the following situation will never
8995 // appear due to the fact that the critical pairs are already sorted
8996 // by increasing signature.
8997 // True. However, in the case of integers we need to put the element
8998 // that caused the signature drop on the first position
8999 if (atS <= strat->sl)
9000 {
9001#ifdef ENTER_USE_MEMMOVE
9002 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9003 (strat->sl - atS + 1)*sizeof(poly));
9004 memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9005 (strat->sl - atS + 1)*sizeof(poly));
9006 memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9007 (strat->sl - atS + 1)*sizeof(unsigned long));
9008 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9009 (strat->sl - atS + 1)*sizeof(int));
9010 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9011 (strat->sl - atS + 1)*sizeof(unsigned long));
9012 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9013 (strat->sl - atS + 1)*sizeof(int));
9014 if (strat->lenS!=NULL)
9015 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9016 (strat->sl - atS + 1)*sizeof(int));
9017 if (strat->lenSw!=NULL)
9018 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9019 (strat->sl - atS + 1)*sizeof(wlen_type));
9020#else
9021 for (i=strat->sl+1; i>=atS+1; i--)
9022 {
9023 strat->S[i] = strat->S[i-1];
9024 strat->ecartS[i] = strat->ecartS[i-1];
9025 strat->sevS[i] = strat->sevS[i-1];
9026 strat->S_2_R[i] = strat->S_2_R[i-1];
9027 strat->sig[i] = strat->sig[i-1];
9028 strat->sevSig[i] = strat->sevSig[i-1];
9029 }
9030 if (strat->lenS!=NULL)
9031 for (i=strat->sl+1; i>=atS+1; i--)
9032 strat->lenS[i] = strat->lenS[i-1];
9033 if (strat->lenSw!=NULL)
9034 for (i=strat->sl+1; i>=atS+1; i--)
9035 strat->lenSw[i] = strat->lenSw[i-1];
9036#endif
9037 }
9038 if (strat->fromQ!=NULL)
9039 {
9040#ifdef ENTER_USE_MEMMOVE
9041 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9042 (strat->sl - atS + 1)*sizeof(int));
9043#else
9044 for (i=strat->sl+1; i>=atS+1; i--)
9045 {
9046 strat->fromQ[i] = strat->fromQ[i-1];
9047 }
9048#endif
9049 strat->fromQ[atS]=0;
9050 }
9051
9052 /*- save result -*/
9053 strat->S[atS] = p.p;
9054 strat->sig[atS] = p.sig; // TODO: get the correct signature in here!
9055 if (strat->honey) strat->ecartS[atS] = p.ecart;
9056 if (p.sev == 0)
9057 p.sev = pGetShortExpVector(p.p);
9058 else
9059 assume(p.sev == pGetShortExpVector(p.p));
9060 strat->sevS[atS] = p.sev;
9061 // during the interreduction process of a signature-based algorithm we do not
9062 // compute the signature at this point, but when the whole interreduction
9063 // process finishes, i.e. f5c terminates!
9064 if (p.sig != NULL)
9065 {
9066 if (p.sevSig == 0)
9067 p.sevSig = pGetShortExpVector(p.sig);
9068 else
9069 assume(p.sevSig == pGetShortExpVector(p.sig));
9070 strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9071 }
9072 strat->ecartS[atS] = p.ecart;
9073 strat->S_2_R[atS] = atR;
9074 strat->sl++;
9075#ifdef DEBUGF5
9076 int k;
9077 Print("--- LIST S: %d ---\n",strat->sl);
9078 for(k=0;k<=strat->sl;k++)
9079 {
9080 pWrite(strat->sig[k]);
9081 }
9082 PrintS("--- LIST S END ---\n");
9083#endif
9084}
9085
9087{
9088 p.GetP(strat->lmBin);
9089 if (strat->homog) strat->initEcart(&p);
9090 strat->redTailChange=FALSE;
9092 {
9093 p.pCleardenom();
9095 {
9096#ifdef HAVE_SHIFTBBA
9097 if (rIsLPRing(currRing))
9098 p.p = redtailBba(&p,strat->tl,strat, TRUE,!TEST_OPT_CONTENTSB);
9099 else
9100#endif
9101 {
9102 p.p = redtailBba(&p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9103 }
9104 p.pCleardenom();
9105 if (strat->redTailChange)
9106 p.t_p=NULL;
9107 if (strat->P.p!=NULL) strat->P.sev=p_GetShortExpVector(strat->P.p,currRing);
9108 else strat->P.sev=0;
9109 }
9110 }
9111
9112 assume(strat->tailRing == p.tailRing);
9113 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9114
9115 int i, j, pos;
9116 poly tp = strat->T[tj].p;
9117
9118 /* enter p to T set */
9119 enterT(p, strat);
9120
9121 for (j = 0; j <= strat->sl; ++j)
9122 {
9123 if (pLtCmp(tp, strat->S[j]) == 0)
9124 {
9125 break;
9126 }
9127 }
9128 /* it may be that the exchanged element
9129 * is until now only in T and not in S */
9130 if (j <= strat->sl)
9131 {
9132 deleteInS(j, strat);
9133 }
9134
9135 pos = posInS(strat, strat->sl, p.p, p.ecart);
9136
9137 pp_Test(p.p, currRing, p.tailRing);
9138 assume(p.FDeg == p.pFDeg());
9139
9140 /* remove useless pairs from L set */
9141 for (i = 0; i <= strat->Ll; ++i)
9142 {
9143 if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0)
9144 {
9145 deleteInL(strat->L, &(strat->Ll), i, strat);
9146 i--;
9147 continue;
9148 }
9149 if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0)
9150 {
9151 deleteInL(strat->L, &(strat->Ll), i, strat);
9152 i--;
9153 }
9154 }
9155#ifdef HAVE_SHIFTBBA
9156 if (rIsLPRing(currRing))
9157 enterpairsShift(p.p, strat->sl, p.ecart, pos, strat, strat->tl); // TODO LP
9158 else
9159#endif
9160 {
9161 /* generate new pairs with p, probably removing older, now useless pairs */
9162 superenterpairs(p.p, strat->sl, p.ecart, pos, strat, strat->tl);
9163 }
9164 /* enter p to S set */
9165 strat->enterS(p, pos, strat, strat->tl);
9166
9167#ifdef HAVE_SHIFTBBA
9168 /* do this after enterS so that the index in R (which is strat->tl) is correct */
9169 if (rIsLPRing(currRing) && !strat->rightGB)
9170 enterTShift(p,strat);
9171#endif
9172}
9173
9174/*2
9175* puts p to the set T at position atT
9176*/
9177void enterT(LObject &p, kStrategy strat, int atT)
9178{
9179 int i;
9180
9181#ifdef PDEBUG
9182#ifdef HAVE_SHIFTBBA
9183 if (currRing->isLPring && p.shift > 0)
9184 {
9185 // in this case, the order is not correct. test LM and tail separately
9186 p_LmTest(p.p, currRing);
9187 p_Test(pNext(p.p), currRing);
9188 }
9189 else
9190#endif
9191 {
9192 pp_Test(p.p, currRing, p.tailRing);
9193 }
9194#endif
9195 assume(strat->tailRing == p.tailRing);
9196 // redMoraNF complains about this -- but, we don't really
9197 // need this so far
9198 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9199 assume(!strat->homog || (p.FDeg == p.pFDeg()));
9200 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9201
9202#ifdef KDEBUG
9203 // do not put an LObject twice into T:
9204 for(i=strat->tl;i>=0;i--)
9205 {
9206 if (p.p==strat->T[i].p)
9207 {
9208 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9209 return;
9210 }
9211 }
9212#endif
9213
9214#ifdef HAVE_TAIL_RING
9215 if (currRing!=strat->tailRing)
9216 {
9217 p.t_p=p.GetLmTailRing();
9218 }
9219#endif
9220 strat->newt = TRUE;
9221 if (atT < 0)
9222 atT = strat->posInT(strat->T, strat->tl, p);
9223 if (strat->tl == strat->tmax-1)
9224 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9225 if (atT <= strat->tl)
9226 {
9227#ifdef ENTER_USE_MEMMOVE
9228 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9229 (strat->tl-atT+1)*sizeof(TObject));
9230 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9231 (strat->tl-atT+1)*sizeof(unsigned long));
9232#endif
9233 for (i=strat->tl+1; i>=atT+1; i--)
9234 {
9235#ifndef ENTER_USE_MEMMOVE
9236 strat->T[i] = strat->T[i-1];
9237 strat->sevT[i] = strat->sevT[i-1];
9238#endif
9239 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9240 }
9241 }
9242
9243 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9244 {
9245#ifdef HAVE_SHIFTBBA
9246 // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9247 if (!(currRing->isLPring && p.shift > 0))
9248#endif
9249 {
9251 (strat->tailRing != NULL ?
9252 strat->tailRing : currRing),
9253 strat->tailBin);
9254 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9255 }
9256 }
9257 strat->T[atT] = (TObject) p;
9258 //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9259
9260 if ((pNext(p.p) != NULL) && (!rIsLPRing(currRing)))
9261 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9262 else
9263 strat->T[atT].max_exp = NULL;
9264
9265 strat->tl++;
9266 strat->R[strat->tl] = &(strat->T[atT]);
9267 strat->T[atT].i_r = strat->tl;
9268 assume((p.sev == 0) || (pGetShortExpVector(p.p) == p.sev));
9269 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9270 kTest_T(&(strat->T[atT]),strat);
9271}
9272
9273/*2
9274* puts p to the set T at position atT
9275*/
9276#ifdef HAVE_RINGS
9278{
9280 int i;
9281
9282 pp_Test(p.p, currRing, p.tailRing);
9283 assume(strat->tailRing == p.tailRing);
9284 // redMoraNF complains about this -- but, we don't really
9285 // need this so far
9286 assume(p.pLength == 0 || (int)pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9287 assume(p.FDeg == p.pFDeg());
9288 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9289
9290#ifdef KDEBUG
9291 // do not put an LObject twice into T:
9292 for(i=strat->tl;i>=0;i--)
9293 {
9294 if (p.p==strat->T[i].p)
9295 {
9296 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9297 return;
9298 }
9299 }
9300#endif
9301
9302#ifdef HAVE_TAIL_RING
9303 if (currRing!=strat->tailRing)
9304 {
9305 p.t_p=p.GetLmTailRing();
9306 }
9307#endif
9308 strat->newt = TRUE;
9309 if (atT < 0)
9310 atT = strat->posInT(strat->T, strat->tl, p);
9311 if (strat->tl == strat->tmax-1)
9312 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9313 if (atT <= strat->tl)
9314 {
9315#ifdef ENTER_USE_MEMMOVE
9316 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9317 (strat->tl-atT+1)*sizeof(TObject));
9318 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9319 (strat->tl-atT+1)*sizeof(unsigned long));
9320#endif
9321 for (i=strat->tl+1; i>=atT+1; i--)
9322 {
9323#ifndef ENTER_USE_MEMMOVE
9324 strat->T[i] = strat->T[i-1];
9325 strat->sevT[i] = strat->sevT[i-1];
9326#endif
9327 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9328 }
9329 }
9330
9331 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9332 {
9334 (strat->tailRing != NULL ?
9335 strat->tailRing : currRing),
9336 strat->tailBin);
9337 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9338 }
9339 strat->T[atT] = (TObject) p;
9340 //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9341
9342 if (pNext(p.p) != NULL)
9343 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9344 else
9345 strat->T[atT].max_exp = NULL;
9346
9347 strat->tl++;
9348 strat->R[strat->tl] = &(strat->T[atT]);
9349 strat->T[atT].i_r = strat->tl;
9350 assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9351 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9352 #if 1
9354 && !n_IsUnit(p.p->coef, currRing->cf))
9355 {
9356 for(i=strat->tl;i>=0;i--)
9357 {
9358 if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9359 {
9360 enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9361 }
9362 }
9363 }
9364 /*
9365 printf("\nThis is T:\n");
9366 for(i=strat->tl;i>=0;i--)
9367 {
9368 pWrite(strat->T[i].p);
9369 }
9370 //getchar();*/
9371 #endif
9372 kTest_T(&(strat->T[atT]),strat);
9373}
9374#endif
9375
9376/*2
9377* puts signature p.sig to the set syz
9378*/
9379void enterSyz(LObject &p, kStrategy strat, int atT)
9380{
9381 int i;
9382 strat->newt = TRUE;
9383 if (strat->syzl == strat->syzmax-1)
9384 {
9385 pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9386 strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9387 (strat->syzmax)*sizeof(unsigned long),
9388 ((strat->syzmax)+setmax)
9389 *sizeof(unsigned long));
9390 strat->syzmax += setmax;
9391 }
9392 if (atT < strat->syzl)
9393 {
9394#ifdef ENTER_USE_MEMMOVE
9395 memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9396 (strat->syzl-atT+1)*sizeof(poly));
9397 memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9398 (strat->syzl-atT+1)*sizeof(unsigned long));
9399#endif
9400 for (i=strat->syzl; i>=atT+1; i--)
9401 {
9402#ifndef ENTER_USE_MEMMOVE
9403 strat->syz[i] = strat->syz[i-1];
9404 strat->sevSyz[i] = strat->sevSyz[i-1];
9405#endif
9406 }
9407 }
9408 //i = strat->syzl;
9409 i = atT;
9410 //Makes sure the syz saves just the signature
9411 #ifdef HAVE_RINGS
9413 pNext(p.sig) = NULL;
9414 #endif
9415 strat->syz[atT] = p.sig;
9416 strat->sevSyz[atT] = p.sevSig;
9417 strat->syzl++;
9418#if F5DEBUG
9419 Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9420 pWrite(strat->syz[atT]);
9421#endif
9422 // recheck pairs in strat->L with new rule and delete correspondingly
9423 int cc = strat->Ll;
9424 while (cc>-1)
9425 {
9426 //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9427 //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);
9428 if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9429 strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9432 || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9433 #endif
9434 )
9435 {
9436 //printf("\nYES!\n");
9437 deleteInL(strat->L,&strat->Ll,cc,strat);
9438 }
9439 cc--;
9440 }
9441//#if 1
9442#ifdef DEBUGF5
9443 PrintS("--- Syzygies ---\n");
9444 Print("syzl %d\n",strat->syzl);
9445 Print("syzmax %d\n",strat->syzmax);
9446 PrintS("--------------------------------\n");
9447 for(i=0;i<=strat->syzl-1;i++)
9448 {
9449 Print("%d - ",i);
9450 pWrite(strat->syz[i]);
9451 }
9452 PrintS("--------------------------------\n");
9453#endif
9454}
9455
9456
9457void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9458{
9459
9460 //if the ordering is local, then hilb criterion
9461 //can be used also if the ideal is not homogeneous
9463 {
9465 *hilb=NULL;
9466 else
9467 return;
9468 }
9469 if (strat->homog!=isHomog)
9470 {
9471 *hilb=NULL;
9472 }
9473}
9474
9476{
9479 if (TEST_OPT_SB_1)
9481#ifdef HAVE_RINGS
9483 {
9485 strat->chainCrit=chainCritRing;
9486 }
9487#endif
9488#ifdef HAVE_RATGRING
9489 if (rIsRatGRing(currRing))
9490 {
9491 strat->chainCrit=chainCritPart;
9492 /* enterOnePairNormal get rational part in it */
9493 }
9494#endif
9495 if (TEST_OPT_IDLIFT
9496 && (strat->syzComp==1)
9497 && (!rIsPluralRing(currRing)))
9499
9501 strat->Gebauer = strat->homog || strat->sugarCrit;
9502 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9503 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9504 strat->pairtest = NULL;
9505 /* always use tailreduction, except:
9506 * - in local rings, - in lex order case, -in ring over extensions */
9508 //if(rHasMixedOrdering(currRing)==2)
9509 //{
9510 // strat->noTailReduction =TRUE;
9511 //}
9512
9513#ifdef HAVE_PLURAL
9514 // and r is plural_ring
9515 // hence this holds for r a rational_plural_ring
9516 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9517 { //or it has non-quasi-comm type... later
9518 strat->sugarCrit = FALSE;
9519 strat->Gebauer = FALSE;
9520 strat->honey = FALSE;
9521 }
9522#endif
9523
9524 // Coefficient ring?
9526 {
9527 strat->sugarCrit = FALSE;
9528 strat->Gebauer = FALSE;
9529 strat->honey = FALSE;
9530 }
9531 #ifdef KDEBUG
9532 if (TEST_OPT_DEBUG)
9533 {
9534 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9535 else PrintS("ideal/module is not homogeneous\n");
9536 }
9537 #endif
9538}
9539
9541{
9542 //strat->enterOnePair=enterOnePairNormal;
9544 //strat->chainCrit=chainCritNormal;
9545 strat->chainCrit = chainCritSig;
9546 /******************************************
9547 * rewCrit1 and rewCrit2 are already set in
9548 * kSba() in kstd1.cc
9549 *****************************************/
9550 //strat->rewCrit1 = faugereRewCriterion;
9551 if (strat->sbaOrder == 1)
9552 {
9553 strat->syzCrit = syzCriterionInc;
9554 }
9555 else
9556 {
9557 strat->syzCrit = syzCriterion;
9558 }
9559#ifdef HAVE_RINGS
9561 {
9563 strat->chainCrit=chainCritRing;
9564 }
9565#endif
9566#ifdef HAVE_RATGRING
9567 if (rIsRatGRing(currRing))
9568 {
9569 strat->chainCrit=chainCritPart;
9570 /* enterOnePairNormal get rational part in it */
9571 }
9572#endif
9573
9575 strat->Gebauer = strat->homog || strat->sugarCrit;
9576 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9577 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9578 strat->pairtest = NULL;
9579 /* always use tailreduction, except:
9580 * - in local rings, - in lex order case, -in ring over extensions */
9583
9584#ifdef HAVE_PLURAL
9585 // and r is plural_ring
9586 // hence this holds for r a rational_plural_ring
9587 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9588 { //or it has non-quasi-comm type... later
9589 strat->sugarCrit = FALSE;
9590 strat->Gebauer = FALSE;
9591 strat->honey = FALSE;
9592 }
9593#endif
9594
9595 // Coefficient ring?
9597 {
9598 strat->sugarCrit = FALSE;
9599 strat->Gebauer = FALSE ;
9600 strat->honey = FALSE;
9601 }
9602 #ifdef KDEBUG
9603 if (TEST_OPT_DEBUG)
9604 {
9605 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9606 else PrintS("ideal/module is not homogeneous\n");
9607 }
9608 #endif
9609}
9610
9612 (const LSet set, const int length,
9613 LObject* L,const kStrategy strat))
9614{
9615 if (pos_in_l == posInL110
9616 || pos_in_l == posInL10
9619 #endif
9620 )
9621 return TRUE;
9622
9623 return FALSE;
9624}
9625
9627{
9629 {
9630 if (strat->honey)
9631 {
9632 strat->posInL = posInL15;
9633 // ok -- here is the deal: from my experiments for Singular-2-0
9634 // I conclude that that posInT_EcartpLength is the best of
9635 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9636 // see the table at the end of this file
9637 if (TEST_OPT_OLDSTD)
9638 strat->posInT = posInT15;
9639 else
9640 strat->posInT = posInT_EcartpLength;
9641 }
9642 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9643 {
9644 strat->posInL = posInL11;
9645 strat->posInT = posInT11;
9646 }
9647 else if (TEST_OPT_INTSTRATEGY)
9648 {
9649 strat->posInL = posInL11;
9650 strat->posInT = posInT11;
9651 }
9652 else
9653 {
9654 strat->posInL = posInL0;
9655 strat->posInT = posInT0;
9656 }
9657 //if (strat->minim>0) strat->posInL =posInLSpecial;
9658 if (strat->homog)
9659 {
9660 strat->posInL = posInL110;
9661 strat->posInT = posInT110;
9662 }
9663 }
9664 else /* local/mixed ordering */
9665 {
9666 if (strat->homog)
9667 {
9668 strat->posInL = posInL11;
9669 strat->posInT = posInT11;
9670 }
9671 else
9672 {
9673 if ((currRing->order[0]==ringorder_c)
9674 ||(currRing->order[0]==ringorder_C))
9675 {
9676 strat->posInL = posInL17_c;
9677 strat->posInT = posInT17_c;
9678 }
9679 else
9680 {
9681 strat->posInL = posInL17;
9682 strat->posInT = posInT17;
9683 }
9684 }
9685 }
9686 if (strat->minim>0) strat->posInL =posInLSpecial;
9687 // for further tests only
9688 if ((BTEST1(11)) || (BTEST1(12)))
9689 strat->posInL = posInL11;
9690 else if ((BTEST1(13)) || (BTEST1(14)))
9691 strat->posInL = posInL13;
9692 else if ((BTEST1(15)) || (BTEST1(16)))
9693 strat->posInL = posInL15;
9694 else if ((BTEST1(17)) || (BTEST1(18)))
9695 strat->posInL = posInL17;
9696 if (BTEST1(11))
9697 strat->posInT = posInT11;
9698 else if (BTEST1(13))
9699 strat->posInT = posInT13;
9700 else if (BTEST1(15))
9701 strat->posInT = posInT15;
9702 else if ((BTEST1(17)))
9703 strat->posInT = posInT17;
9704 else if ((BTEST1(19)))
9705 strat->posInT = posInT19;
9706 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9707 strat->posInT = posInT1;
9709}
9710
9711#ifdef HAVE_RINGS
9713{
9715 {
9716 if (strat->honey)
9717 {
9718 strat->posInL = posInL15Ring;
9719 // ok -- here is the deal: from my experiments for Singular-2-0
9720 // I conclude that that posInT_EcartpLength is the best of
9721 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9722 // see the table at the end of this file
9723 if (TEST_OPT_OLDSTD)
9724 strat->posInT = posInT15Ring;
9725 else
9726 strat->posInT = posInT_EcartpLength;
9727 }
9728 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9729 {
9730 strat->posInL = posInL11Ring;
9731 strat->posInT = posInT11;
9732 }
9733 else if (TEST_OPT_INTSTRATEGY)
9734 {
9735 strat->posInL = posInL11Ring;
9736 strat->posInT = posInT11;
9737 }
9738 else
9739 {
9740 strat->posInL = posInL0Ring;
9741 strat->posInT = posInT0;
9742 }
9743 //if (strat->minim>0) strat->posInL =posInLSpecial;
9744 if (strat->homog)
9745 {
9746 strat->posInL = posInL110Ring;
9747 strat->posInT = posInT110Ring;
9748 }
9749 }
9750 else
9751 {
9752 if (strat->homog)
9753 {
9754 //printf("\nHere 3\n");
9755 strat->posInL = posInL11Ring;
9756 strat->posInT = posInT11Ring;
9757 }
9758 else
9759 {
9760 if ((currRing->order[0]==ringorder_c)
9761 ||(currRing->order[0]==ringorder_C))
9762 {
9763 strat->posInL = posInL17_cRing;
9764 strat->posInT = posInT17_cRing;
9765 }
9766 else
9767 {
9768 strat->posInL = posInL11Ringls;
9769 strat->posInT = posInT17Ring;
9770 }
9771 }
9772 }
9773 if (strat->minim>0) strat->posInL =posInLSpecial;
9774 // for further tests only
9775 if ((BTEST1(11)) || (BTEST1(12)))
9776 strat->posInL = posInL11Ring;
9777 else if ((BTEST1(13)) || (BTEST1(14)))
9778 strat->posInL = posInL13;
9779 else if ((BTEST1(15)) || (BTEST1(16)))
9780 strat->posInL = posInL15Ring;
9781 else if ((BTEST1(17)) || (BTEST1(18)))
9782 strat->posInL = posInL17Ring;
9783 if (BTEST1(11))
9784 strat->posInT = posInT11Ring;
9785 else if (BTEST1(13))
9786 strat->posInT = posInT13;
9787 else if (BTEST1(15))
9788 strat->posInT = posInT15Ring;
9789 else if ((BTEST1(17)))
9790 strat->posInT = posInT17Ring;
9791 else if ((BTEST1(19)))
9792 strat->posInT = posInT19;
9793 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9794 strat->posInT = posInT1;
9796}
9797#endif
9798
9800{
9801 strat->interpt = BTEST1(OPT_INTERRUPT);
9802 /*- creating temp data structures------------------- -*/
9803 //strat->cp = 0; // already by skStragy()
9804 //strat->c3 = 0; // already by skStragy()
9805#ifdef HAVE_SHIFTBBA
9806 strat->cv = 0; // already by skStragy()
9807#endif
9808 strat->tail = pInit();
9809 /*- set s -*/
9810 strat->sl = -1;
9811 /*- set L -*/
9812 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9813 strat->Ll = -1;
9814 strat->L = initL(strat->Lmax);
9815 /*- set B -*/
9816 strat->Bmax = setmaxL;
9817 strat->Bl = -1;
9818 strat->B = initL();
9819 /*- set T -*/
9820 strat->tl = -1;
9821 strat->tmax = setmaxT;
9822 strat->T = initT();
9823 strat->R = initR();
9824 strat->sevT = initsevT();
9825 /*- init local data struct.---------------------------------------- -*/
9826 //strat->P.ecart=0; // already by skStragy()
9827 //strat->P.length=0; // already by skStragy()
9828 //strat->P.pLength=0; // already by skStragy()
9830 {
9831 if (strat->kNoether!=NULL)
9832 {
9833 pSetComp(strat->kNoether, strat->ak);
9834 pSetComp(strat->kNoetherTail(), strat->ak);
9835 }
9836 }
9838 {
9839 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9840 }
9841 else
9842 {
9843 if(TEST_OPT_SB_1)
9844 {
9845 int i;
9846 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
9847 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9848 {
9849 P->m[i-strat->newIdeal] = F->m[i];
9850 F->m[i] = NULL;
9851 }
9852 initSSpecial(F,Q,P,strat);
9853 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9854 {
9855 F->m[i] = P->m[i-strat->newIdeal];
9856 P->m[i-strat->newIdeal] = NULL;
9857 }
9858 idDelete(&P);
9859 }
9860 else
9861 {
9862 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9863 // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
9864 }
9865 }
9866 strat->fromT = FALSE;
9868 if ((!TEST_OPT_SB_1)
9870 )
9871 {
9872 updateS(TRUE,strat);
9873 }
9874#ifdef HAVE_SHIFTBBA
9875 if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
9876#endif
9877 {
9878 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9879 strat->fromQ=NULL;
9880 }
9881 assume(kTest_TS(strat));
9882}
9883
9885{
9886 /*- release temp data -*/
9887 cleanT(strat);
9888 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
9889 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
9890 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
9891 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
9892 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
9893 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
9894 /*- set L: should be empty -*/
9895 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
9896 /*- set B: should be empty -*/
9897 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
9898 pLmFree(&strat->tail);
9899 strat->syzComp=0;
9900
9901#ifdef HAVE_SHIFTBBA
9902 if (rIsLPRing(currRing) && strat->rightGB)
9903 {
9904 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9905 strat->fromQ=NULL;
9906 }
9907#endif
9908}
9909
9911{
9913 {
9914 if (strat->honey)
9915 {
9916 strat->posInL = posInL15;
9917 // ok -- here is the deal: from my experiments for Singular-2-0
9918 // I conclude that that posInT_EcartpLength is the best of
9919 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9920 // see the table at the end of this file
9921 if (TEST_OPT_OLDSTD)
9922 strat->posInT = posInT15;
9923 else
9924 strat->posInT = posInT_EcartpLength;
9925 }
9926 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9927 {
9928 strat->posInL = posInL11;
9929 strat->posInT = posInT11;
9930 }
9931 else if (TEST_OPT_INTSTRATEGY)
9932 {
9933 strat->posInL = posInL11;
9934 strat->posInT = posInT11;
9935 }
9936 else
9937 {
9938 strat->posInL = posInL0;
9939 strat->posInT = posInT0;
9940 }
9941 //if (strat->minim>0) strat->posInL =posInLSpecial;
9942 if (strat->homog)
9943 {
9944 strat->posInL = posInL110;
9945 strat->posInT = posInT110;
9946 }
9947 }
9948 else
9949 {
9950 if (strat->homog)
9951 {
9952 strat->posInL = posInL11;
9953 strat->posInT = posInT11;
9954 }
9955 else
9956 {
9957 if ((currRing->order[0]==ringorder_c)
9958 ||(currRing->order[0]==ringorder_C))
9959 {
9960 strat->posInL = posInL17_c;
9961 strat->posInT = posInT17_c;
9962 }
9963 else
9964 {
9965 strat->posInL = posInL17;
9966 strat->posInT = posInT17;
9967 }
9968 }
9969 }
9970 if (strat->minim>0) strat->posInL =posInLSpecial;
9971 // for further tests only
9972 if ((BTEST1(11)) || (BTEST1(12)))
9973 strat->posInL = posInL11;
9974 else if ((BTEST1(13)) || (BTEST1(14)))
9975 strat->posInL = posInL13;
9976 else if ((BTEST1(15)) || (BTEST1(16)))
9977 strat->posInL = posInL15;
9978 else if ((BTEST1(17)) || (BTEST1(18)))
9979 strat->posInL = posInL17;
9980 if (BTEST1(11))
9981 strat->posInT = posInT11;
9982 else if (BTEST1(13))
9983 strat->posInT = posInT13;
9984 else if (BTEST1(15))
9985 strat->posInT = posInT15;
9986 else if ((BTEST1(17)))
9987 strat->posInT = posInT17;
9988 else if ((BTEST1(19)))
9989 strat->posInT = posInT19;
9990 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9991 strat->posInT = posInT1;
9993 {
9994 strat->posInL = posInL11Ring;
9995 if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
9996 strat->posInL = posInL11Ringls;
9997 strat->posInT = posInT11;
9998 }
10000 strat->posInLSba = posInLSig;
10001 //strat->posInL = posInLSig;
10002 strat->posInL = posInLF5C;
10003 /*
10004 if (rField_is_Ring(currRing))
10005 {
10006 strat->posInLSba = posInLSigRing;
10007 strat->posInL = posInL11Ring;
10008 }*/
10009 //strat->posInT = posInTSig;
10010}
10011
10013{
10014 strat->interpt = BTEST1(OPT_INTERRUPT);
10015 //strat->kNoether=NULL; // done by skStrategy
10016 /*- creating temp data structures------------------- -*/
10017 //strat->cp = 0; // done by skStrategy
10018 //strat->c3 = 0; // done by skStrategy
10019 strat->tail = pInit();
10020 /*- set s -*/
10021 strat->sl = -1;
10022 /*- set ps -*/
10023 strat->syzl = -1;
10024 /*- set L -*/
10025 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10026 strat->Ll = -1;
10027 strat->L = initL(strat->Lmax);
10028 /*- set B -*/
10029 strat->Bmax = setmaxL;
10030 strat->Bl = -1;
10031 strat->B = initL();
10032 /*- set T -*/
10033 strat->tl = -1;
10034 strat->tmax = setmaxT;
10035 strat->T = initT();
10036 strat->R = initR();
10037 strat->sevT = initsevT();
10038 /*- init local data struct.---------------------------------------- -*/
10039 //strat->P.ecart=0; // done by skStrategy
10040 //strat->P.length=0; // done by skStrategy
10042 {
10043 if (strat->kNoether!=NULL)
10044 {
10045 pSetComp(strat->kNoether, strat->ak);
10046 pSetComp(strat->kNoetherTail(), strat->ak);
10047 }
10048 }
10050 {
10051 /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10052 }
10053 else
10054 {
10055 if(TEST_OPT_SB_1)
10056 {
10057 int i;
10058 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10059 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10060 {
10061 P->m[i-strat->newIdeal] = F->m[i];
10062 F->m[i] = NULL;
10063 }
10064 initSSpecialSba(F,Q,P,strat);
10065 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10066 {
10067 F->m[i] = P->m[i-strat->newIdeal];
10068 P->m[i-strat->newIdeal] = NULL;
10069 }
10070 idDelete(&P);
10071 }
10072 else
10073 {
10074 initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10075 }
10076 }
10077 //strat->fromT = FALSE; // done by skStrategy
10078 if (!TEST_OPT_SB_1)
10079 {
10080 if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10081 }
10082 //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10083 //strat->fromQ=NULL;
10084 assume(kTest_TS(strat));
10085}
10086
10087void exitSba (kStrategy strat)
10088{
10089 /*- release temp data -*/
10091 cleanTSbaRing(strat);
10092 else
10093 cleanT(strat);
10094 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10095 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10096 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10097 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10098 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10099 omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10100 if(strat->syzmax>0)
10101 {
10102 omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10103 omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10104 if (strat->sbaOrder == 1)
10105 {
10106 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10107 }
10108 }
10109 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10110 /*- set L: should be empty -*/
10111 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10112 /*- set B: should be empty -*/
10113 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10114 /*- set sig: no need for the signatures anymore -*/
10115 omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10116 pLmDelete(&strat->tail);
10117 strat->syzComp=0;
10118}
10119
10120/*2
10121* in the case of a standardbase of a module over a qring:
10122* replace polynomials in i by ak vectors,
10123* (the polynomial * unit vectors gen(1)..gen(ak)
10124* in every case (also for ideals:)
10125* deletes divisible vectors/polynomials
10126*/
10128{
10129 int l;
10130 if (strat->ak>0)
10131 {
10132 for (l=IDELEMS(r)-1;l>=0;l--)
10133 {
10134 if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10135 {
10136 pDelete(&r->m[l]); // and set it to NULL
10137 }
10138 }
10139 int q;
10140 poly p;
10142 {
10143 for (l=IDELEMS(r)-1;l>=0;l--)
10144 {
10145 if ((r->m[l]!=NULL)
10146 //&& (strat->syzComp>0)
10147 //&& (pGetComp(r->m[l])<=strat->syzComp)
10148 )
10149 {
10150 for(q=IDELEMS(Q)-1; q>=0;q--)
10151 {
10152 if ((Q->m[q]!=NULL)
10153 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10154 {
10155 if (TEST_OPT_REDSB)
10156 {
10157 p=r->m[l];
10158 r->m[l]=kNF(Q,NULL,p);
10159 pDelete(&p);
10160 }
10161 else
10162 {
10163 pDelete(&r->m[l]); // and set it to NULL
10164 }
10165 break;
10166 }
10167 }
10168 }
10169 }
10170 }
10171 #ifdef HAVE_RINGS
10172 else
10173 {
10174 for (l=IDELEMS(r)-1;l>=0;l--)
10175 {
10176 if ((r->m[l]!=NULL)
10177 //&& (strat->syzComp>0)
10178 //&& (pGetComp(r->m[l])<=strat->syzComp)
10179 )
10180 {
10181 for(q=IDELEMS(Q)-1; q>=0;q--)
10182 {
10183 if ((Q->m[q]!=NULL)
10184 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10185 {
10186 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10187 {
10188 if (TEST_OPT_REDSB)
10189 {
10190 p=r->m[l];
10191 r->m[l]=kNF(Q,NULL,p);
10192 pDelete(&p);
10193 }
10194 else
10195 {
10196 pDelete(&r->m[l]); // and set it to NULL
10197 }
10198 break;
10199 }
10200 }
10201 }
10202 }
10203 }
10204 }
10205 #endif
10206 }
10207 else
10208 {
10209 int q;
10210 poly p;
10213 {
10214 for (l=IDELEMS(r)-1;l>=0;l--)
10215 {
10216 if (r->m[l]!=NULL)
10217 {
10218 for(q=IDELEMS(Q)-1; q>=0;q--)
10219 {
10220 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10221 {
10222 if (TEST_OPT_REDSB)
10223 {
10224 p=r->m[l];
10225 r->m[l]=kNF(Q,NULL,p);
10226 pDelete(&p);
10228 }
10229 else
10230 {
10231 pDelete(&r->m[l]); // and set it to NULL
10232 }
10233 break;
10234 }
10235 }
10236 }
10237 }
10238 }
10239 #ifdef HAVE_RINGS
10240 //Also need divisibility of the leading coefficients
10241 else
10242 {
10243 for (l=IDELEMS(r)-1;l>=0;l--)
10244 {
10245 if (r->m[l]!=NULL)
10246 {
10247 for(q=IDELEMS(Q)-1; q>=0;q--)
10248 {
10249 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10250 {
10251 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10252 {
10253 if (TEST_OPT_REDSB)
10254 {
10255 p=r->m[l];
10256 r->m[l]=kNF(Q,NULL,p);
10257 pDelete(&p);
10259 }
10260 else
10261 {
10262 pDelete(&r->m[l]); // and set it to NULL
10263 }
10264 break;
10265 }
10266 }
10267 }
10268 }
10269 }
10270 }
10271 #endif
10272 if (/*TEST_OPT_REDSB &&*/ reduction_found)
10273 {
10274 #ifdef HAVE_RINGS
10276 {
10277 for (l=IDELEMS(r)-1;l>=0;l--)
10278 {
10279 if (r->m[l]!=NULL)
10280 {
10281 for(q=IDELEMS(r)-1;q>=0;q--)
10282 {
10283 if ((l!=q)
10284 && (r->m[q]!=NULL)
10285 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10286 &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10287 )
10288 {
10289 //If they are equal then take the one with the smallest length
10290 if(pLmDivisibleBy(r->m[q],r->m[l])
10291 && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10292 && (pLength(r->m[q]) < pLength(r->m[l]) ||
10293 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10294 {
10295 pDelete(&r->m[l]);
10296 break;
10297 }
10298 else
10299 pDelete(&r->m[q]);
10300 }
10301 }
10302 }
10303 }
10304 }
10305 else
10306 #endif
10307 {
10308 for (l=IDELEMS(r)-1;l>=0;l--)
10309 {
10310 if (r->m[l]!=NULL)
10311 {
10312 for(q=IDELEMS(r)-1;q>=0;q--)
10313 {
10314 if ((l!=q)
10315 && (r->m[q]!=NULL)
10316 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10317 )
10318 {
10319 //If they are equal then take the one with the smallest length
10320 if(pLmDivisibleBy(r->m[q],r->m[l])
10321 &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10322 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10323 {
10324 pDelete(&r->m[l]);
10325 break;
10326 }
10327 else
10328 pDelete(&r->m[q]);
10329 }
10330 }
10331 }
10332 }
10333 }
10334 }
10335 }
10336 idSkipZeroes(r);
10337}
10338
10340{
10341 int i;
10342 int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10343 LObject L;
10344
10345#ifdef KDEBUG
10346 // need to set this: during tailreductions of T[i], T[i].max is out of
10347 // sync
10348 sloppy_max = TRUE;
10349#endif
10350
10351 strat->noTailReduction = FALSE;
10352 //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10353 if (TEST_OPT_PROT)
10354 {
10355 PrintLn();
10356// if (timerv) writeTime("standard base computed:");
10357 }
10358 if (TEST_OPT_PROT)
10359 {
10360 Print("(S:%d)",strat->sl);mflush();
10361 }
10362 for (i=strat->sl; i>=low; i--)
10363 {
10364 int end_pos=strat->sl;
10365 if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10366 if (strat->ak==0) end_pos=i-1;
10367 TObject* T_j = strat->s_2_t(i);
10368 if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10369 {
10370 L = *T_j;
10371 #ifdef KDEBUG
10372 if (TEST_OPT_DEBUG)
10373 {
10374 Print("test S[%d]:",i);
10375 p_wrp(L.p,currRing,strat->tailRing);
10376 PrintLn();
10377 }
10378 #endif
10380 strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10381 else
10382 strat->S[i] = redtail(&L, strat->sl, strat);
10383 #ifdef KDEBUG
10384 if (TEST_OPT_DEBUG)
10385 {
10386 Print("to (tailR) S[%d]:",i);
10387 p_wrp(strat->S[i],currRing,strat->tailRing);
10388 PrintLn();
10389 }
10390 #endif
10391
10392 if (strat->redTailChange)
10393 {
10394 if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10395 if (pNext(T_j->p) != NULL)
10396 T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10397 else
10398 T_j->max_exp = NULL;
10399 }
10401 T_j->pCleardenom();
10402 }
10403 else
10404 {
10405 assume(currRing == strat->tailRing);
10406 #ifdef KDEBUG
10407 if (TEST_OPT_DEBUG)
10408 {
10409 Print("test S[%d]:",i);
10410 p_wrp(strat->S[i],currRing,strat->tailRing);
10411 PrintLn();
10412 }
10413 #endif
10415 strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10416 else
10417 strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10419 {
10421 {
10422 number n;
10423 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10424 if (!nIsOne(n))
10425 {
10427 denom->n=nInvers(n);
10428 denom->next=DENOMINATOR_LIST;
10430 }
10431 nDelete(&n);
10432 }
10433 else
10434 {
10435 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10436 }
10437 }
10438 #ifdef KDEBUG
10439 if (TEST_OPT_DEBUG)
10440 {
10441 Print("to (-tailR) S[%d]:",i);
10442 p_wrp(strat->S[i],currRing,strat->tailRing);
10443 PrintLn();
10444 }
10445 #endif
10446 }
10447 if (TEST_OPT_PROT)
10448 PrintS("-");
10449 }
10450 if (TEST_OPT_PROT) PrintLn();
10451#ifdef KDEBUG
10452 sloppy_max = FALSE;
10453#endif
10454}
10455
10456
10457/*2
10458* computes the new strat->kNoether and the new pNoether,
10459* returns TRUE, if pNoether has changed
10460*/
10462{
10463 if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10464 return FALSE;
10465 int i,j;
10466 poly newNoether;
10467
10468#if 0
10469 if (currRing->weight_all_1)
10470 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10471 else
10472 scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kNoether);
10473#else
10474 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10475#endif
10476 if (strat->kNoether==NULL) return FALSE;
10477 if (strat->t_kNoether != NULL)
10478 {
10479 p_LmFree(strat->t_kNoether, strat->tailRing);
10480 strat->t_kNoether=NULL;
10481 }
10482 if (strat->tailRing != currRing)
10484 /* compare old and new noether*/
10485 newNoether = pLmInit(strat->kNoether);
10488 for (i=1; i<=(currRing->N); i++)
10489 {
10491 }
10493 if (j < HCord) /*- statistics -*/
10494 {
10495 if (TEST_OPT_PROT)
10496 {
10497 Print("H(%d)",j);
10498 mflush();
10499 }
10500 HCord=j;
10501 #ifdef KDEBUG
10502 if (TEST_OPT_DEBUG)
10503 {
10504 Print("H(%d):",j);
10505 wrp(strat->kNoether);
10506 PrintLn();
10507 }
10508 #endif
10509 }
10510 if (pCmp(strat->kNoether,newNoether)!=1)
10511 {
10512 if (strat->kNoether!=NULL) p_LmDelete0(strat->kNoether,currRing);
10513 strat->kNoether=newNoether;
10514 if (strat->t_kNoether != NULL)
10515 {
10516 p_LmFree(strat->t_kNoether, strat->tailRing);
10517 strat->t_kNoether=NULL;
10518 }
10519 if (strat->tailRing != currRing)
10521
10522 return TRUE;
10523 }
10525 return FALSE;
10526}
10527
10528/***************************************************************
10529 *
10530 * Routines related for ring changes during std computations
10531 *
10532 ***************************************************************/
10533BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10534{
10535 if (strat->overflow) return FALSE;
10536 assume(L->p1 != NULL && L->p2 != NULL);
10537 // shift changes: from 0 to -1
10538 assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10539 assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10540
10541 if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10542 return FALSE;
10543 // shift changes: extra case inserted
10544 if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10545 {
10546 return TRUE;
10547 }
10548 poly p1_max=NULL;
10549 if ((L->i_r1>=0)&&(strat->R[L->i_r1]!=NULL)) p1_max = (strat->R[L->i_r1])->max_exp;
10550 poly p2_max=NULL;
10551 if ((L->i_r2>=0)&&(strat->R[L->i_r2]!=NULL)) p2_max = (strat->R[L->i_r2])->max_exp;
10552
10553 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10554 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10555 {
10556 p_LmFree(m1, strat->tailRing);
10557 p_LmFree(m2, strat->tailRing);
10558 m1 = NULL;
10559 m2 = NULL;
10560 return FALSE;
10561 }
10562 return TRUE;
10563}
10564
10565#ifdef HAVE_RINGS
10566/***************************************************************
10567 *
10568 * Checks, if we can compute the gcd poly / strong pair
10569 * gcd-poly = m1 * R[atR] + m2 * S[atS]
10570 *
10571 ***************************************************************/
10572BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10573{
10574 assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10575 //assume(strat->tailRing != currRing);
10576
10577 poly p1_max = (strat->R[atR])->max_exp;
10578 poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10579
10580 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10581 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10582 {
10583 return FALSE;
10584 }
10585 return TRUE;
10586}
10587#endif
10588
10589#ifdef HAVE_RINGS
10590/*!
10591 used for GB over ZZ: look for constant and monomial elements in the ideal
10592 background: any known constant element of ideal suppresses
10593 intermediate coefficient swell
10594*/
10596{
10597 if(!nCoeff_is_Z(currRing->cf))
10598 return NULL;
10599 ideal F = idCopy(Forig);
10600 idSkipZeroes(F);
10601 poly pmon;
10603 ideal monred = idInit(1,1);
10604 for(int i=0; i<idElem(F); i++)
10605 {
10606 if(pNext(F->m[i]) == NULL)
10607 idInsertPoly(monred, pCopy(F->m[i]));
10608 }
10609 int posconst = idPosConstant(F);
10610 if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10611 {
10612 idDelete(&F);
10613 idDelete(&monred);
10614 return NULL;
10615 }
10616 int idelemQ = 0;
10617 if(Q!=NULL)
10618 {
10619 idelemQ = IDELEMS(Q);
10620 for(int i=0; i<idelemQ; i++)
10621 {
10622 if(pNext(Q->m[i]) == NULL)
10623 idInsertPoly(monred, pCopy(Q->m[i]));
10624 }
10627 //the constant, if found, will be from Q
10628 if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10629 {
10630 pmon = pCopy(monred->m[posconst]);
10631 idDelete(&F);
10632 idDelete(&monred);
10633 return pmon;
10634 }
10635 }
10637 nKillChar(QQ_ring->cf);
10638 QQ_ring->cf = nInitChar(n_Q, NULL);
10639 rComplete(QQ_ring,1);
10642 nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10644 for(int i = 0, j = 0; i<IDELEMS(F); i++)
10645 II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10646 for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10647 II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10648 ideal one = kStd(II, NULL, isNotHomog, NULL);
10649 idSkipZeroes(one);
10650 if(idIsConstant(one))
10651 {
10652 //one should be <1>
10653 for(int i = IDELEMS(II)-1; i>=0; i--)
10654 if(II->m[i] != NULL)
10655 II->m[i+1] = II->m[i];
10656 II->m[0] = pOne();
10658 poly integer = NULL;
10659 for(int i = IDELEMS(syz)-1;i>=0; i--)
10660 {
10661 if(pGetComp(syz->m[i]) == 1)
10662 {
10663 pSetComp(syz->m[i],0);
10664 if(pIsConstant(pHead(syz->m[i])))
10665 {
10666 integer = pHead(syz->m[i]);
10667 break;
10668 }
10669 }
10670 }
10672 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10674 idDelete(&monred);
10675 idDelete(&F);
10677 id_Delete(&one,QQ_ring);
10678 id_Delete(&syz,QQ_ring);
10681 return pmon;
10682 }
10683 else
10684 {
10685 if(idIs0(monred))
10686 {
10687 poly mindegmon = NULL;
10688 for(int i = 0; i<IDELEMS(one); i++)
10689 {
10690 if(pNext(one->m[i]) == NULL)
10691 {
10692 if(mindegmon == NULL)
10693 mindegmon = pCopy(one->m[i]);
10694 else
10695 {
10696 if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10697 mindegmon = pCopy(one->m[i]);
10698 }
10699 }
10700 }
10701 if(mindegmon != NULL)
10702 {
10703 for(int i = IDELEMS(II)-1; i>=0; i--)
10704 if(II->m[i] != NULL)
10705 II->m[i+1] = II->m[i];
10706 II->m[0] = pCopy(mindegmon);
10708 bool found = FALSE;
10709 for(int i = IDELEMS(syz)-1;i>=0; i--)
10710 {
10711 if(pGetComp(syz->m[i]) == 1)
10712 {
10713 pSetComp(syz->m[i],0);
10714 if(pIsConstant(pHead(syz->m[i])))
10715 {
10716 pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10717 found = TRUE;
10718 break;
10719 }
10720 }
10721 }
10722 id_Delete(&syz,QQ_ring);
10723 if (found == FALSE)
10724 {
10726 idDelete(&monred);
10727 idDelete(&F);
10729 id_Delete(&one,QQ_ring);
10731 return NULL;
10732 }
10734 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10736 idDelete(&monred);
10737 idDelete(&F);
10739 id_Delete(&one,QQ_ring);
10740 id_Delete(&syz,QQ_ring);
10742 return pmon;
10743 }
10744 }
10745 }
10747 idDelete(&monred);
10748 idDelete(&F);
10750 id_Delete(&one,QQ_ring);
10752 return NULL;
10753}
10754#endif
10755
10756#ifdef HAVE_RINGS
10757/*!
10758 used for GB over ZZ: intermediate reduction by monomial elements
10759 background: any known constant element of ideal suppresses
10760 intermediate coefficient swell
10761*/
10763{
10764 if(!nCoeff_is_Z(currRing->cf))
10765 return;
10766 poly pH = h->GetP();
10767 poly p,pp;
10768 p = pH;
10769 bool deleted = FALSE, ok = FALSE;
10770 for(int i = 0; i<=strat->sl; i++)
10771 {
10772 p = pH;
10773 if(pNext(strat->S[i]) == NULL)
10774 {
10775 //pWrite(p);
10776 //pWrite(strat->S[i]);
10777 while(ok == FALSE && p != NULL)
10778 {
10779 if(pLmDivisibleBy(strat->S[i], p)
10781 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], p))
10782#endif
10783 )
10784 {
10785 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10787 }
10788 if(nIsZero(p->coef))
10789 {
10790 pLmDelete(&p);
10791 h->p = p;
10792 deleted = TRUE;
10793 }
10794 else
10795 {
10796 ok = TRUE;
10797 }
10798 }
10799 if (p!=NULL)
10800 {
10801 pp = pNext(p);
10802 while(pp != NULL)
10803 {
10804 if(pLmDivisibleBy(strat->S[i], pp)
10806 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], pp))
10807#endif
10808 )
10809 {
10810 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10812 if(nIsZero(pp->coef))
10813 {
10814 pLmDelete(&pNext(p));
10815 pp = pNext(p);
10816 deleted = TRUE;
10817 }
10818 else
10819 {
10820 p = pp;
10821 pp = pNext(p);
10822 }
10823 }
10824 else
10825 {
10826 p = pp;
10827 pp = pNext(p);
10828 }
10829 }
10830 }
10831 }
10832 }
10833 h->SetLmCurrRing();
10834 if((deleted)&&(h->p!=NULL))
10835 strat->initEcart(h);
10836}
10837
10839{
10840 if(!nCoeff_is_Z(currRing->cf))
10841 return;
10842 poly hSig = h->sig;
10843 poly pH = h->GetP();
10844 poly p,pp;
10845 p = pH;
10846 bool deleted = FALSE, ok = FALSE;
10847 for(int i = 0; i<=strat->sl; i++)
10848 {
10849 p = pH;
10850 if(pNext(strat->S[i]) == NULL)
10851 {
10852 while(ok == FALSE && p!=NULL)
10853 {
10854 if(pLmDivisibleBy(strat->S[i], p))
10855 {
10856 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10857 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10858 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10859 {
10860 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10862 }
10863 pDelete(&sigMult);
10864 }
10865 if(nIsZero(p->coef))
10866 {
10867 pLmDelete(&p);
10868 h->p = p;
10869 deleted = TRUE;
10870 }
10871 else
10872 {
10873 ok = TRUE;
10874 }
10875 }
10876 if(p == NULL)
10877 return;
10878 pp = pNext(p);
10879 while(pp != NULL)
10880 {
10881 if(pLmDivisibleBy(strat->S[i], pp))
10882 {
10883 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10884 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10885 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10886 {
10887 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10889 if(nIsZero(pp->coef))
10890 {
10891 pLmDelete(&pNext(p));
10892 pp = pNext(p);
10893 deleted = TRUE;
10894 }
10895 else
10896 {
10897 p = pp;
10898 pp = pNext(p);
10899 }
10900 }
10901 else
10902 {
10903 p = pp;
10904 pp = pNext(p);
10905 }
10906 pDelete(&sigMult);
10907 }
10908 else
10909 {
10910 p = pp;
10911 pp = pNext(p);
10912 }
10913 }
10914 }
10915 }
10916 h->SetLmCurrRing();
10917 if(deleted)
10918 strat->initEcart(h);
10919
10920}
10921
10922/*!
10923 used for GB over ZZ: final reduction by constant elements
10924 background: any known constant element of ideal suppresses
10925 intermediate coefficient swell and beautifies output
10926*/
10928{
10929 assume(strat->tl<0); /* can only be called with no elements in T:
10930 i.e. after exitBuchMora */
10931 /* do not use strat->S, strat->sl as they may be out of sync*/
10932 if(!nCoeff_is_Z(currRing->cf))
10933 return;
10934 poly p,pp;
10935 for(int j = 0; j<IDELEMS(strat->Shdl); j++)
10936 {
10937 if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
10938 {
10939 for(int i = 0; i<IDELEMS(strat->Shdl); i++)
10940 {
10941 if((i != j) && (strat->Shdl->m[i] != NULL))
10942 {
10943 p = strat->Shdl->m[i];
10944 while((p!=NULL) && (pLmDivisibleBy(strat->Shdl->m[j], p)
10945#if HAVE_SHIFTBBA
10946 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], p))
10947#endif
10948 ))
10949 {
10950 number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
10951 if (!nEqual(dummy,p->coef))
10952 {
10953 if (nIsZero(dummy))
10954 {
10955 nDelete(&dummy);
10956 pLmDelete(&strat->Shdl->m[i]);
10957 p=strat->Shdl->m[i];
10958 }
10959 else
10960 {
10962 break;
10963 }
10964 }
10965 else
10966 {
10967 nDelete(&dummy);
10968 break;
10969 }
10970 }
10971 if (p!=NULL)
10972 {
10973 pp = pNext(p);
10974 while(pp != NULL)
10975 {
10976 if(pLmDivisibleBy(strat->Shdl->m[j], pp)
10977#if HAVE_SHIFTBBA
10978 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], pp))
10979#endif
10980 )
10981 {
10982 number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
10983 if (!nEqual(dummy,pp->coef))
10984 {
10986 if(nIsZero(pp->coef))
10987 {
10988 pLmDelete(&pNext(p));
10989 pp = pNext(p);
10990 }
10991 else
10992 {
10993 p = pp;
10994 pp = pNext(p);
10995 }
10996 }
10997 else
10998 {
10999 nDelete(&dummy);
11000 p = pp;
11001 pp = pNext(p);
11002 }
11003 }
11004 else
11005 {
11006 p = pp;
11007 pp = pNext(p);
11008 }
11009 }
11010 }
11011 }
11012 }
11013 //idPrint(strat->Shdl);
11014 }
11015 }
11016 idSkipZeroes(strat->Shdl);
11017}
11018#endif
11019
11021{
11022 assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11023 /* initial setup or extending */
11024
11025 if (rIsLPRing(currRing)) return TRUE;
11026 if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11027 if (expbound >= currRing->bitmask) return FALSE;
11028 strat->overflow=FALSE;
11030 // Hmmm .. the condition pFDeg == p_Deg
11031 // might be too strong
11032 (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11033 (strat->ak==0), // omit_comp if the input is an ideal
11034 expbound); // exp_limit
11035
11036 if (new_tailRing == currRing) return TRUE;
11037
11038 strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11039 strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11040
11041 if (currRing->pFDeg != currRing->pFDegOrig)
11042 {
11043 new_tailRing->pFDeg = currRing->pFDeg;
11044 new_tailRing->pLDeg = currRing->pLDeg;
11045 }
11046
11047 if (TEST_OPT_PROT)
11048 Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11049 kTest_TS(strat);
11050 assume(new_tailRing != strat->tailRing);
11051 pShallowCopyDeleteProc p_shallow_copy_delete
11053
11055
11056 int i;
11057 for (i=0; i<=strat->tl; i++)
11058 {
11059 strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11060 p_shallow_copy_delete);
11061 }
11062 for (i=0; i<=strat->Ll; i++)
11063 {
11064 assume(strat->L[i].p != NULL);
11065 if (pNext(strat->L[i].p) != strat->tail)
11066 strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11067 }
11068 if ((strat->P.t_p != NULL) ||
11069 ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11070 strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11071
11072 if ((L != NULL) && (L->tailRing != new_tailRing))
11073 {
11074 if (L->i_r < 0)
11075 L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11076 else
11077 {
11078 assume(L->i_r <= strat->tl);
11079 TObject* t_l = strat->R[L->i_r];
11080 assume(t_l != NULL);
11081 L->tailRing = new_tailRing;
11082 L->p = t_l->p;
11083 L->t_p = t_l->t_p;
11084 L->max_exp = t_l->max_exp;
11085 }
11086 }
11087
11088 if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11089 T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11090
11091 omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11092 if (strat->tailRing != currRing)
11094
11095 strat->tailRing = new_tailRing;
11096 strat->tailBin = new_tailBin;
11099
11100 if (strat->kNoether != NULL)
11101 {
11102 if (strat->t_kNoether != NULL)
11103 p_LmFree(strat->t_kNoether, strat->tailRing);
11105 }
11106
11107 kTest_TS(strat);
11108 if (TEST_OPT_PROT)
11109 PrintS("]");
11110 return TRUE;
11111}
11112
11114{
11115 unsigned long l = 0;
11116 int i;
11117 long e;
11118
11119 assume(strat->tailRing == currRing);
11120
11121 for (i=0; i<= strat->Ll; i++)
11122 {
11123 l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11124 }
11125 for (i=0; i<=strat->tl; i++)
11126 {
11127 // Hmm ... this we could do in one Step
11128 l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11129 }
11131 {
11132 l *= 2;
11133 }
11134 e = p_GetMaxExp(l, currRing);
11135 if (e <= 1) e = 2;
11136 if (rIsLPRing(currRing)) e = 1;
11137
11138 kStratChangeTailRing(strat, NULL, NULL, e);
11139}
11140
11141ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11142{
11143 int n = rBlocks(r); // Including trailing zero!
11144 // if sbaOrder == 1 => use (C,monomial order from r)
11145 if (strat->sbaOrder == 1)
11146 {
11147 if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11148 {
11149 return r;
11150 }
11151 ring res = rCopy0(r, TRUE, FALSE);
11152 res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11153 res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11154 res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11155 int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11156 res->wvhdl = wvhdl;
11157 for (int i=1; i<n; i++)
11158 {
11159 res->order[i] = r->order[i-1];
11160 res->block0[i] = r->block0[i-1];
11161 res->block1[i] = r->block1[i-1];
11162 res->wvhdl[i] = r->wvhdl[i-1];
11163 }
11164
11165 // new 1st block
11166 res->order[0] = ringorder_C; // Prefix
11167 // removes useless secondary component order if defined in old ring
11168 for (int i=rBlocks(res); i>0; --i)
11169 {
11170 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11171 {
11172 res->order[i] = (rRingOrder_t)0;
11173 }
11174 }
11175 rComplete(res, 1);
11176#ifdef HAVE_PLURAL
11177 if (rIsPluralRing(r))
11178 {
11179 if ( nc_rComplete(r, res, false) ) // no qideal!
11180 {
11181#ifndef SING_NDEBUG
11182 WarnS("error in nc_rComplete");
11183#endif
11184 // cleanup?
11185
11186 // rDelete(res);
11187 // return r;
11188
11189 // just go on..
11190 }
11191 }
11192#endif
11193 strat->tailRing = res;
11194 return (res);
11195 }
11196 // if sbaOrder == 3 => degree - position - ring order
11197 if (strat->sbaOrder == 3)
11198 {
11199 ring res = rCopy0(r, TRUE, FALSE);
11200 res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11201 res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11202 res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11203 int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11204 res->wvhdl = wvhdl;
11205 for (int i=2; i<n+2; i++)
11206 {
11207 res->order[i] = r->order[i-2];
11208 res->block0[i] = r->block0[i-2];
11209 res->block1[i] = r->block1[i-2];
11210 res->wvhdl[i] = r->wvhdl[i-2];
11211 }
11212
11213 // new 1st block
11214 res->order[0] = ringorder_a; // Prefix
11215 res->block0[0] = 1;
11216 res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11217 for (int i=0; i<res->N; ++i)
11218 res->wvhdl[0][i] = 1;
11219 res->block1[0] = si_min(res->N, rVar(res));
11220 // new 2nd block
11221 res->order[1] = ringorder_C; // Prefix
11222 res->wvhdl[1] = NULL;
11223 // removes useless secondary component order if defined in old ring
11224 for (int i=rBlocks(res); i>1; --i)
11225 {
11226 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11227 {
11228 res->order[i] = (rRingOrder_t)0;
11229 }
11230 }
11231 rComplete(res, 1);
11232#ifdef HAVE_PLURAL
11233 if (rIsPluralRing(r))
11234 {
11235 if ( nc_rComplete(r, res, false) ) // no qideal!
11236 {
11237#ifndef SING_NDEBUG
11238 WarnS("error in nc_rComplete");
11239#endif
11240 // cleanup?
11241
11242 // rDelete(res);
11243 // return r;
11244
11245 // just go on..
11246 }
11247 }
11248#endif
11249 strat->tailRing = res;
11250 return (res);
11251 }
11252
11253 // not sbaOrder == 1 => use Schreyer order
11254 // this is done by a trick when initializing the signatures
11255 // in initSLSba():
11256 // Instead of using the signature 1e_i for F->m[i], we start
11257 // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11258 // Schreyer order w.r.t. the underlying monomial order.
11259 // => we do not need to change the underlying polynomial ring at all!
11260
11261 // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11262
11263 /*
11264 else
11265 {
11266 ring res = rCopy0(r, FALSE, FALSE);
11267 // Create 2 more blocks for prefix/suffix:
11268 res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11269 res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11270 res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11271 int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11272
11273 // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11274 // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11275
11276 // new 1st block
11277 int j = 0;
11278 res->order[j] = ringorder_IS; // Prefix
11279 res->block0[j] = res->block1[j] = 0;
11280 // wvhdl[j] = NULL;
11281 j++;
11282
11283 for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11284 {
11285 res->order [j] = r->order [i];
11286 res->block0[j] = r->block0[i];
11287 res->block1[j] = r->block1[i];
11288
11289 if (r->wvhdl[i] != NULL)
11290 {
11291 wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11292 } // else wvhdl[j] = NULL;
11293 }
11294
11295 // new last block
11296 res->order [j] = ringorder_IS; // Suffix
11297 res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11298 // wvhdl[j] = NULL;
11299 j++;
11300
11301 // res->order [j] = 0; // The End!
11302 res->wvhdl = wvhdl;
11303
11304 // j == the last zero block now!
11305 assume(j == (n+1));
11306 assume(res->order[0]==ringorder_IS);
11307 assume(res->order[j-1]==ringorder_IS);
11308 assume(res->order[j]==0);
11309
11310 if (complete)
11311 {
11312 rComplete(res, 1);
11313
11314#ifdef HAVE_PLURAL
11315 if (rIsPluralRing(r))
11316 {
11317 if ( nc_rComplete(r, res, false) ) // no qideal!
11318 {
11319 }
11320 }
11321 assume(rIsPluralRing(r) == rIsPluralRing(res));
11322#endif
11323
11324
11325#ifdef HAVE_PLURAL
11326 ring old_ring = r;
11327
11328#endif
11329
11330 if (r->qideal!=NULL)
11331 {
11332 res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11333
11334 assume(idRankFreeModule(res->qideal, res) == 0);
11335
11336#ifdef HAVE_PLURAL
11337 if( rIsPluralRing(res) )
11338 if( nc_SetupQuotient(res, r, true) )
11339 {
11340 // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11341 }
11342
11343#endif
11344 assume(idRankFreeModule(res->qideal, res) == 0);
11345 }
11346
11347#ifdef HAVE_PLURAL
11348 assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11349 assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11350 assume(rIsSCA(res) == rIsSCA(old_ring));
11351 assume(ncRingType(res) == ncRingType(old_ring));
11352#endif
11353 }
11354 strat->tailRing = res;
11355 return res;
11356 }
11357 */
11358
11359 assume(FALSE);
11360 return(NULL);
11361}
11362
11364{
11365 memset(this, 0, sizeof(skStrategy));
11366 strat_nr++;
11367 nr=strat_nr;
11369 P.tailRing = currRing;
11370 tl = -1;
11371 sl = -1;
11372#ifdef HAVE_LM_BIN
11374#endif
11375#ifdef HAVE_TAIL_BIN
11377#endif
11378 pOrigFDeg = currRing->pFDeg;
11379 pOrigLDeg = currRing->pLDeg;
11380}
11381
11382
11384{
11385 if (lmBin != NULL)
11387 if (tailBin != NULL)// && !rField_is_Ring(currRing))
11389 ((tailRing != NULL) ? tailRing->PolyBin:
11390 currRing->PolyBin));
11391 if (t_kNoether != NULL)
11393
11394 if (currRing != tailRing)
11397}
11398
11399#if 0
11401 T15 EDL DL EL L 1-2-3
11402Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11403Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11404Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11405ahml 4.48 4.03 4.03 4.38 4.96 26.50
11406c7 15.02 13.98 15.16 13.24 17.31 47.89
11407c8 505.09 407.46 852.76 413.21 499.19 n/a
11408f855 12.65 9.27 14.97 8.78 14.23 33.12
11409gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11410gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11411ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11412noon8 40.68 37.02 37.99 36.82 35.59 877.16
11413rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11414rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11415schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11416test016 16.39 14.17 14.40 13.50 14.26 34.07
11417test017 34.70 36.01 33.16 35.48 32.75 71.45
11418test042 10.76 10.99 10.27 11.57 10.45 23.04
11419test058 6.78 6.75 6.51 6.95 6.22 9.47
11420test066 10.71 10.94 10.76 10.61 10.56 19.06
11421test073 10.75 11.11 10.17 10.79 8.63 58.10
11422test086 12.23 11.81 12.88 12.24 13.37 66.68
11423test103 5.05 4.80 5.47 4.64 4.89 11.90
11424test154 12.96 11.64 13.51 12.46 14.61 36.35
11425test162 65.27 64.01 67.35 59.79 67.54 196.46
11426test164 7.50 6.50 7.68 6.70 7.96 17.13
11427virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11428#endif
11429
11430
11431//#ifdef HAVE_MORE_POS_IN_T
11432#if 1
11433// determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11435{
11436
11437 if (length==-1) return 0;
11438
11439 int o = p.ecart;
11440 int op=p.GetpFDeg();
11441 int ol = p.GetpLength();
11442
11443 if (set[length].ecart < o)
11444 return length+1;
11445 if (set[length].ecart == o)
11446 {
11447 int oo=set[length].GetpFDeg();
11448 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11449 return length+1;
11450 }
11451
11452 int i;
11453 int an = 0;
11454 int en= length;
11455 loop
11456 {
11457 if (an >= en-1)
11458 {
11459 if (set[an].ecart > o)
11460 return an;
11461 if (set[an].ecart == o)
11462 {
11463 int oo=set[an].GetpFDeg();
11464 if((oo > op)
11465 || ((oo==op) && (set[an].pLength > ol)))
11466 return an;
11467 }
11468 return en;
11469 }
11470 i=(an+en) / 2;
11471 if (set[i].ecart > o)
11472 en=i;
11473 else if (set[i].ecart == o)
11474 {
11475 int oo=set[i].GetpFDeg();
11476 if ((oo > op)
11477 || ((oo == op) && (set[i].pLength > ol)))
11478 en=i;
11479 else
11480 an=i;
11481 }
11482 else
11483 an=i;
11484 }
11485}
11486
11487// determines the position based on: 1.) FDeg 2.) pLength
11488int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11489{
11490
11491 if (length==-1) return 0;
11492
11493 int op=p.GetpFDeg();
11494 int ol = p.GetpLength();
11495
11496 int oo=set[length].GetpFDeg();
11497 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11498 return length+1;
11499
11500 int i;
11501 int an = 0;
11502 int en= length;
11503 loop
11504 {
11505 if (an >= en-1)
11506 {
11507 int oo=set[an].GetpFDeg();
11508 if((oo > op)
11509 || ((oo==op) && (set[an].pLength > ol)))
11510 return an;
11511 return en;
11512 }
11513 i=(an+en) / 2;
11514 int oo=set[i].GetpFDeg();
11515 if ((oo > op)
11516 || ((oo == op) && (set[i].pLength > ol)))
11517 en=i;
11518 else
11519 an=i;
11520 }
11521}
11522
11523
11524// determines the position based on: 1.) pLength
11525int posInT_pLength(const TSet set,const int length,LObject &p)
11526{
11527 int ol = p.GetpLength();
11528 if (length==-1)
11529 return 0;
11530 if (set[length].length<p.length)
11531 return length+1;
11532
11533 int i;
11534 int an = 0;
11535 int en= length;
11536
11537 loop
11538 {
11539 if (an >= en-1)
11540 {
11541 if (set[an].pLength>ol) return an;
11542 return en;
11543 }
11544 i=(an+en) / 2;
11545 if (set[i].pLength>ol) en=i;
11546 else an=i;
11547 }
11548}
11549#endif
11550
11551// kstd1.cc:
11552int redFirst (LObject* h,kStrategy strat);
11553int redEcart (LObject* h,kStrategy strat);
11554void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11555void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11556// ../Singular/misc.cc:
11557extern char * showOption();
11558
11560{
11561 printf("red: ");
11562 if (strat->red==redFirst) printf("redFirst\n");
11563 else if (strat->red==redHoney) printf("redHoney\n");
11564 else if (strat->red==redEcart) printf("redEcart\n");
11565 else if (strat->red==redHomog) printf("redHomog\n");
11566 else if (strat->red==redLazy) printf("redLazy\n");
11567 else if (strat->red==redLiftstd) printf("redLiftstd\n");
11568 else printf("%p\n",(void*)strat->red);
11569 printf("posInT: ");
11570 if (strat->posInT==posInT0) printf("posInT0\n");
11571 else if (strat->posInT==posInT1) printf("posInT1\n");
11572 else if (strat->posInT==posInT11) printf("posInT11\n");
11573 else if (strat->posInT==posInT110) printf("posInT110\n");
11574 else if (strat->posInT==posInT13) printf("posInT13\n");
11575 else if (strat->posInT==posInT15) printf("posInT15\n");
11576 else if (strat->posInT==posInT17) printf("posInT17\n");
11577 else if (strat->posInT==posInT17_c) printf("posInT17_c\n");
11578 else if (strat->posInT==posInT19) printf("posInT19\n");
11579 else if (strat->posInT==posInT2) printf("posInT2\n");
11580 #ifdef HAVE_RINGS
11581 else if (strat->posInT==posInT11Ring) printf("posInT11Ring\n");
11582 else if (strat->posInT==posInT110Ring) printf("posInT110Ring\n");
11583 else if (strat->posInT==posInT15Ring) printf("posInT15Ring\n");
11584 else if (strat->posInT==posInT17Ring) printf("posInT17Ring\n");
11585 else if (strat->posInT==posInT17_cRing) printf("posInT17_cRing\n");
11586 #endif
11587#ifdef HAVE_MORE_POS_IN_T
11588 else if (strat->posInT==posInT_EcartFDegpLength) printf("posInT_EcartFDegpLength\n");
11589 else if (strat->posInT==posInT_FDegpLength) printf("posInT_FDegpLength\n");
11590 else if (strat->posInT==posInT_pLength) printf("posInT_pLength\n");
11591#endif
11592 else if (strat->posInT==posInT_EcartpLength) printf("posInT_EcartpLength\n");
11593 else printf("%p\n",(void*)strat->posInT);
11594 printf("posInL: ");
11595 if (strat->posInL==posInL0) printf("posInL0\n");
11596 else if (strat->posInL==posInL10) printf("posInL10\n");
11597 else if (strat->posInL==posInL11) printf("posInL11\n");
11598 else if (strat->posInL==posInL110) printf("posInL110\n");
11599 else if (strat->posInL==posInL13) printf("posInL13\n");
11600 else if (strat->posInL==posInL15) printf("posInL15\n");
11601 else if (strat->posInL==posInL17) printf("posInL17\n");
11602 else if (strat->posInL==posInL17_c) printf("posInL17_c\n");
11603 #ifdef HAVE_RINGS
11604 else if (strat->posInL==posInL0) printf("posInL0Ring\n");
11605 else if (strat->posInL==posInL11Ring) printf("posInL11Ring\n");
11606 else if (strat->posInL==posInL11Ringls) printf("posInL11Ringls\n");
11607 else if (strat->posInL==posInL110Ring) printf("posInL110Ring\n");
11608 else if (strat->posInL==posInL15Ring) printf("posInL15Ring\n");
11609 else if (strat->posInL==posInL17Ring) printf("posInL17Ring\n");
11610 else if (strat->posInL==posInL17_cRing) printf("posInL17_cRing\n");
11611 #endif
11612 else if (strat->posInL==posInLSpecial) printf("posInLSpecial\n");
11613 else printf("%p\n",(void*)strat->posInL);
11614 printf("enterS: ");
11615 if (strat->enterS==enterSBba) printf("enterSBba\n");
11616 else if (strat->enterS==enterSMora) printf("enterSMora\n");
11617 else if (strat->enterS==enterSMoraNF) printf("enterSMoraNF\n");
11618 else printf("%p\n",(void*)strat->enterS);
11619 printf("initEcart: ");
11620 if (strat->initEcart==initEcartBBA) printf("initEcartBBA\n");
11621 else if (strat->initEcart==initEcartNormal) printf("initEcartNormal\n");
11622 else printf("%p\n",(void*)strat->initEcart);
11623 printf("initEcartPair: ");
11624 if (strat->initEcartPair==initEcartPairBba) printf("initEcartPairBba\n");
11625 else if (strat->initEcartPair==initEcartPairMora) printf("initEcartPairMora\n");
11626 else printf("%p\n",(void*)strat->initEcartPair);
11627 printf("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11628 strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11629 printf("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11630 strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11631 printf("chainCrit: ");
11632 if (strat->chainCrit==chainCritNormal) printf("chainCritNormal\n");
11633 else if (strat->chainCrit==chainCritOpt_1) printf("chainCritOpt_1\n");
11634 else printf("%p\n",(void*)strat->chainCrit);
11635 printf("posInLDependsOnLength=%d\n",
11636 strat->posInLDependsOnLength);
11637 printf("%s\n",showOption());
11638 printf("LDeg: ");
11639 if (currRing->pLDeg==pLDeg0) printf("pLDeg0");
11640 else if (currRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11641 else if (currRing->pLDeg==pLDegb) printf("pLDegb");
11642 else if (currRing->pLDeg==pLDeg1) printf("pLDeg1");
11643 else if (currRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11644 else if (currRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11645 else if (currRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11646 else if (currRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11647 else if (currRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11648 else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11649 else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11650 else if (currRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11651 else printf("? (%lx)", (long)currRing->pLDeg);
11652 printf(" / ");
11653 if (strat->tailRing->pLDeg==pLDeg0) printf("pLDeg0");
11654 else if (strat->tailRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11655 else if (strat->tailRing->pLDeg==pLDegb) printf("pLDegb");
11656 else if (strat->tailRing->pLDeg==pLDeg1) printf("pLDeg1");
11657 else if (strat->tailRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11658 else if (strat->tailRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11659 else if (strat->tailRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11660 else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11661 else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11662 else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11663 else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11664 else if (strat->tailRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11665 else printf("? (%lx)", (long)strat->tailRing->pLDeg);
11666 printf("\n");
11667 printf("currRing->pFDeg: ");
11668 if (currRing->pFDeg==p_Totaldegree) printf("p_Totaldegree");
11669 else if (currRing->pFDeg==p_WFirstTotalDegree) printf("pWFirstTotalDegree");
11670 else if (currRing->pFDeg==p_Deg) printf("p_Deg");
11671 else if (currRing->pFDeg==kHomModDeg) printf("kHomModDeg");
11672 else if (currRing->pFDeg==totaldegreeWecart) printf("totaldegreeWecart");
11673 else if (currRing->pFDeg==p_WTotaldegree) printf("p_WTotaldegree");
11674 else printf("? (%lx)", (long)currRing->pFDeg);
11675 printf("\n");
11676 printf(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11678 printf(" degBound: %d\n", Kstd1_deg);
11679
11680 if( ecartWeights != NULL )
11681 {
11682 printf("ecartWeights: ");
11683 for (int i = rVar(currRing); i > 0; i--)
11684 printf("%hd ", ecartWeights[i]);
11685 printf("\n");
11687 }
11688
11689#ifndef SING_NDEBUG
11691#endif
11692}
11693
11694//LObject pCopyp2L(poly p, kStrategy strat)
11695//{
11696 /* creates LObject from the poly in currRing */
11697 /* actually put p into L.p and make L.t_p=NULL : does not work */
11698
11699//}
11700
11701/*2
11702* put the lcm(q,p) into the set B, q is the shift of some s[i]
11703*/
11704#ifdef HAVE_SHIFTBBA
11705static BOOLEAN enterOneStrongPolyShift (poly q, poly p, int /*ecart*/, int /*isFromQ*/, kStrategy strat, int atR, int /*ecartq*/, int /*qisFromQ*/, int shiftcount, int ifromS)
11706{
11707 number d, s, t;
11708 /* assume(atR >= 0); */
11711 poly m1, m2, gcd;
11712 //printf("\n--------------------------------\n");
11713 //pWrite(p);pWrite(si);
11714 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q), &s, &t, currRing->cf);
11715
11716 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
11717 {
11718 nDelete(&d);
11719 nDelete(&s);
11720 nDelete(&t);
11721 return FALSE;
11722 }
11723
11724 assume(pIsInV(p));
11725
11726 k_GetStrongLeadTerms(p, q, currRing, m1, m2, gcd, strat->tailRing);
11727
11728 /* the V criterion */
11729 if (!pmIsInV(gcd))
11730 {
11731 strat->cv++;
11732 nDelete(&d);
11733 nDelete(&s);
11734 nDelete(&t);
11735 pLmFree(gcd);
11736 return FALSE;
11737 }
11738
11739 // disabled for Letterplace because it is not so easy to check
11740 /* if (!rHasLocalOrMixedOrdering(currRing)) { */
11741 /* unsigned long sev = pGetShortExpVector(gcd); */
11742
11743 /* for (int j = 0; j < strat->sl; j++) { */
11744 /* if (j == i) */
11745 /* continue; */
11746
11747 /* if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) && */
11748 /* !(strat->sevS[j] & ~sev) && */
11749 /* p_LmDivisibleBy(strat->S[j], gcd, currRing)) { */
11750 /* nDelete(&d); */
11751 /* nDelete(&s); */
11752 /* nDelete(&t); */
11753 /* return FALSE; */
11754 /* } */
11755 /* } */
11756 /* } */
11757
11758 poly m12, m22;
11762 // manually free the coeffs, because pSetCoeff0 is used in the next step
11763 n_Delete(&(m1->coef), currRing->cf);
11764 n_Delete(&(m2->coef), currRing->cf);
11765
11766 //p_Test(m1,strat->tailRing);
11767 //p_Test(m2,strat->tailRing);
11768 /*if(!enterTstrong)
11769 {
11770 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
11771 {
11772 memset(&(strat->P), 0, sizeof(strat->P));
11773 kStratChangeTailRing(strat);
11774 strat->P = *(strat->R[atR]);
11775 p_LmFree(m1, strat->tailRing);
11776 p_LmFree(m2, strat->tailRing);
11777 p_LmFree(gcd, currRing);
11778 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
11779 }
11780 }*/
11781 pSetCoeff0(m1, s);
11782 pSetCoeff0(m2, t);
11783 pSetCoeff0(gcd, d);
11784 p_Test(m1,strat->tailRing);
11785 p_Test(m2,strat->tailRing);
11786 p_Test(m12,strat->tailRing);
11787 p_Test(m22,strat->tailRing);
11788 assume(pmIsInV(m1));
11789 assume(pmIsInV(m2));
11790 assume(pmIsInV(m12));
11791 assume(pmIsInV(m22));
11792 //printf("\n===================================\n");
11793 //pWrite(m1);pWrite(m2);pWrite(gcd);
11794#ifdef KDEBUG
11795 if (TEST_OPT_DEBUG)
11796 {
11797 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
11798 PrintS("m1 = ");
11799 p_wrp(m1, strat->tailRing);
11800 PrintS("m12 = ");
11801 p_wrp(m12, strat->tailRing);
11802 PrintS(" ; m2 = ");
11803 p_wrp(m2, strat->tailRing);
11804 PrintS(" ; m22 = ");
11805 p_wrp(m22, strat->tailRing);
11806 PrintS(" ; gcd = ");
11807 wrp(gcd);
11808 PrintS("\n--- create strong gcd poly: ");
11809 PrintS("\n p: ");
11810 wrp(p);
11811 Print("\n q (strat->S[%d]): ", ifromS);
11812 wrp(q);
11813 PrintS(" ---> ");
11814 }
11815#endif
11816
11817 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);
11818 p_LmDelete(m1, strat->tailRing);
11819 p_LmDelete(m2, strat->tailRing);
11820 p_LmDelete(m12, strat->tailRing);
11821 p_LmDelete(m22, strat->tailRing);
11822
11823 assume(pIsInV(gcd));
11824
11825#ifdef KDEBUG
11826 if (TEST_OPT_DEBUG)
11827 {
11828 wrp(gcd);
11829 PrintLn();
11830 }
11831#endif
11832
11833 LObject h;
11834 h.p = gcd;
11835 h.tailRing = strat->tailRing;
11836 int posx;
11837 strat->initEcart(&h);
11838 h.sev = pGetShortExpVector(h.p);
11839 h.i_r1 = -1;h.i_r2 = -1;
11840 if (currRing!=strat->tailRing)
11841 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
11842#if 1
11843 h.p1 = p;
11844 h.p2 = q;
11845#endif
11846 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
11847 {
11848 h.i_r2 = kFindInT(h.p1, strat);
11849 h.i_r1 = atR;
11850 }
11851 else
11852 {
11853 h.i_r1 = -1;
11854 h.i_r2 = -1;
11855 }
11856 if (strat->Ll==-1)
11857 posx =0;
11858 else
11859 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
11860
11861 assume(pIsInV(h.p));
11862 assume(pIsInV(h.p1));
11863
11864 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
11865 return TRUE;
11866}
11867#endif
11868
11869
11870/*2
11871* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i] (ring case)
11872*/
11873#ifdef HAVE_SHIFTBBA
11874static void enterOnePairRingShift (poly q, poly p, int /*ecart*/, int isFromQ, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
11875{
11876 /* assume(atR >= 0); */
11877 /* assume(i<=strat->sl); */
11878 assume(p!=NULL);
11880 assume(pIsInV(p));
11881 #if ALL_VS_JUST
11882 //Over rings, if we construct the strong pair, do not add the spair
11884 {
11885 number s,t,d;
11886 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q, &s, &t, currRing->cf);
11887
11888 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
11889 {
11890 nDelete(&d);
11891 nDelete(&s);
11892 nDelete(&t);
11893 return;
11894 }
11895 nDelete(&d);
11896 nDelete(&s);
11897 nDelete(&t);
11898 }
11899 #endif
11900 int j,compare,compareCoeff;
11901 LObject h;
11902
11903#ifdef KDEBUG
11904 h.ecart=0; h.length=0;
11905#endif
11906 /*- computes the lcm(s[i],p) -*/
11907 if(pHasNotCFRing(p,q))
11908 {
11909 strat->cp++;
11910 return;
11911 }
11912 h.lcm = p_Lcm(p,q,currRing);
11913 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(q), currRing->cf));
11914 if (nIsZero(pGetCoeff(h.lcm)))
11915 {
11916 strat->cp++;
11917 pLmDelete(h.lcm);
11918 return;
11919 }
11920
11921 /* the V criterion */
11922 if (!pmIsInV(h.lcm))
11923 {
11924 strat->cv++;
11925 pLmDelete(h.lcm);
11926 return;
11927 }
11928 // basic chain criterion
11929 /*
11930 *the set B collects the pairs of type (S[j],p)
11931 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
11932 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
11933 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
11934 */
11935
11936 for(j = strat->Bl;j>=0;j--)
11937 {
11938 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
11939 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
11940 if(compare == pDivComp_EQUAL)
11941 {
11942 //They have the same LM
11944 {
11945 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11946 {
11947 strat->c3++;
11948 pLmDelete(h.lcm);
11949 return;
11950 }
11951 break;
11952 }
11954 {
11955 deleteInL(strat->B,&strat->Bl,j,strat);
11956 strat->c3++;
11957 }
11959 {
11960 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11961 {
11962 strat->c3++;
11963 pLmDelete(h.lcm);
11964 return;
11965 }
11966 break;
11967 }
11968 }
11969 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
11970 {
11971 if(compare == pDivComp_LESS)
11972 {
11973 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11974 {
11975 strat->c3++;
11976 pLmDelete(h.lcm);
11977 return;
11978 }
11979 break;
11980 }
11981 if(compare == pDivComp_GREATER)
11982 {
11983 deleteInL(strat->B,&strat->Bl,j,strat);
11984 strat->c3++;
11985 }
11986 }
11987 }
11988 number s, t;
11989 poly m1, m2, gcd = NULL;
11990 s = pGetCoeff(q);
11991 t = pGetCoeff(p);
11993
11994 poly m12, m22;
11998 // manually free the coeffs, because pSetCoeff0 is used in the next step
11999 n_Delete(&(m1->coef), currRing->cf);
12000 n_Delete(&(m2->coef), currRing->cf);
12001
12002 ksCheckCoeff(&s, &t, currRing->cf);
12003 pSetCoeff0(m1, s);
12004 pSetCoeff0(m2, t);
12005 m2 = pNeg(m2);
12006 p_Test(m1,strat->tailRing);
12007 p_Test(m2,strat->tailRing);
12008 p_Test(m12,strat->tailRing);
12009 p_Test(m22,strat->tailRing);
12010 assume(pmIsInV(m1));
12011 assume(pmIsInV(m2));
12012 assume(pmIsInV(m12));
12013 assume(pmIsInV(m22));
12014 poly pm1 = pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing);
12015 poly sim2 = pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing);
12016 assume(pIsInV(pm1));
12017 assume(pIsInV(sim2));
12018 p_LmDelete(m1, currRing);
12019 p_LmDelete(m2, currRing);
12022 if(sim2 == NULL)
12023 {
12024 if(pm1 == NULL)
12025 {
12026 if(h.lcm != NULL)
12027 {
12028 pLmDelete(h.lcm);
12029 h.lcm=NULL;
12030 }
12031 h.Clear();
12032 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12033 /* if (strat->pairtest==NULL) initPairtest(strat); */
12034 /* strat->pairtest[i] = TRUE; */
12035 /* strat->pairtest[strat->sl+1] = TRUE; */
12036 return;
12037 }
12038 else
12039 {
12040 gcd = pm1;
12041 pm1 = NULL;
12042 }
12043 }
12044 else
12045 {
12046 if((pGetComp(q) == 0) && (0 != pGetComp(p)))
12047 {
12048 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
12049 pSetmComp(sim2);
12050 }
12051 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
12052 gcd = p_Add_q(pm1, sim2, strat->tailRing);
12053 }
12054 p_Test(gcd, strat->tailRing);
12055 assume(pIsInV(gcd));
12056#ifdef KDEBUG
12057 if (TEST_OPT_DEBUG)
12058 {
12059 wrp(gcd);
12060 PrintLn();
12061 }
12062#endif
12063 h.p = gcd;
12064 h.i_r = -1;
12065 if(h.p == NULL)
12066 {
12067 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12068 /* if (strat->pairtest==NULL) initPairtest(strat); */
12069 /* strat->pairtest[i] = TRUE; */
12070 /* strat->pairtest[strat->sl+1] = TRUE; */
12071 return;
12072 }
12073 h.tailRing = strat->tailRing;
12074 int posx;
12075 //h.pCleardenom();
12076 //pSetm(h.p);
12077 h.i_r1 = -1;h.i_r2 = -1;
12078 strat->initEcart(&h);
12079 #if 1
12080 h.p1 = p;
12081 h.p2 = q;
12082 #endif
12083 #if 1
12084 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12085 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12086 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12087 {
12088 h.i_r2 = kFindInT(h.p1, strat); //strat->S_2_R[i];
12089 h.i_r1 = atR;
12090 }
12091 else
12092 {
12093 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12094 h.i_r1 = -1;
12095 h.i_r2 = -1;
12096 }
12097 #endif
12098 if (strat->Bl==-1)
12099 posx =0;
12100 else
12101 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
12102 h.sev = pGetShortExpVector(h.p);
12103 if (currRing!=strat->tailRing)
12104 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12105
12106 assume(pIsInV(h.p));
12107 assume(pIsInV(h.p1));
12108 assume(h.lcm != NULL);
12109 assume(pIsInV(h.lcm));
12110
12111 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
12112 kTest_TS(strat);
12113}
12114#endif
12115
12116#ifdef HAVE_SHIFTBBA
12117// adds the strong pair and the normal pair for rings (aka gpoly and spoly)
12118static BOOLEAN enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12119{
12120 enterOneStrongPolyShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "gpoly"
12121 enterOnePairRingShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "spoly"
12122 return FALSE; // TODO: delete q?
12123}
12124#endif
12125
12126#ifdef HAVE_SHIFTBBA
12127// creates if possible (q,p), (shifts(q),p)
12128static 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)
12129{
12130 // note: ecart and isFromQ is for p
12131 assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12132 assume(pmFirstVblock(p) == 1);
12133 assume(pmFirstVblock(q) == 1);
12136
12137 // TODO: is ecartq = 0 still ok?
12138 int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12139
12140 int q_isFromQ = 0;
12141 if (strat->fromQ != NULL && q_inS >= 0)
12142 q_isFromQ = strat->fromQ[q_inS];
12143
12144 BOOLEAN (*enterPair)(poly, poly, int, int, kStrategy, int, int, int, int, int);
12145#ifdef HAVE_RINGS
12148 else
12149#endif
12151
12152 int degbound = currRing->N/currRing->isLPring;
12153 int neededShift = p_lastVblock - ((pGetComp(p) > 0 || pGetComp(q) > 0) ? 0 : 1); // in the module case, product criterion does not hold
12156 int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12158 for (int j = firstShift; j <= maxShift; j++)
12159 {
12160 poly qq = pLPCopyAndShiftLM(q, j);
12161 if (enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS))
12162 {
12163 if (j>0) pLmDelete(qq);
12164 // delete qq, if not it does not enter the pair set
12165 }
12166 else
12168 }
12169
12170#ifdef HAVE_RINGS
12172 {
12173 // add pairs (m*shifts(q), p) where m is a monomial and the pair has no overlap
12174 for (int j = p_lastVblock; j <= maxPossibleShift; j++)
12175 {
12177 for (int k = 0; k < IDELEMS(fillers); k++)
12178 {
12181 }
12182 idDelete(&fillers);
12183 }
12184 }
12185#endif
12186 return delete_pair;
12187}
12188#endif
12189
12190#ifdef HAVE_SHIFTBBA
12191// creates (q,p), use it when q is already shifted
12192// return TRUE, if (q,p) is discarded
12193static 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)
12194{
12195 // note: ecart and isFromQ is for p
12196 assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12197 assume(pmFirstVblock(p) == 1);
12199 assume(q_shift == pmFirstVblock(q) - 1);
12200
12201 // TODO: is ecartp = 0 still ok?
12202 int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12203
12204 int p_isFromQ = 0;
12205 if (strat->fromQ != NULL && p_inS >= 0)
12206 p_isFromQ = strat->fromQ[p_inS];
12207
12208#ifdef HAVE_RINGS
12210 {
12211 assume(q_shift <= p_lastVblock); // we allow the special case where there is no overlap
12213 }
12214 else
12215#endif
12216 {
12217 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)
12218 return enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12219 }
12220}
12221#endif
12222
12223
12224#ifdef KDEBUG
12225// enable to print which pairs are considered or discarded and why
12226/* #define CRITERION_DEBUG */
12227#endif
12228/*2
12229* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12230* return TRUE, if (q,p) does not enter B
12231*/
12232#ifdef HAVE_SHIFTBBA
12233BOOLEAN enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12234{
12235#ifdef CRITERION_DEBUG
12236 if (TEST_OPT_DEBUG)
12237 {
12238 PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12239 // also write the LMs in separate lines:
12240 poly lmq = pHead(q);
12241 poly lmp = pHead(p);
12242 pSetCoeff(lmq, n_Init(1, currRing->cf));
12243 pSetCoeff(lmp, n_Init(1, currRing->cf));
12244 Print(" %s\n", pString(lmq));
12245 Print(" %s\n", pString(lmp));
12246 pLmDelete(lmq);
12247 pLmDelete(lmp);
12248 }
12249#endif
12250
12251 /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12252
12253 /* check this Formats: */
12258
12259 /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12260
12261 int qfromQ = qisFromQ;
12262
12263 /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12264
12265 int l,j,compare;
12266 LObject Lp;
12267 Lp.i_r = -1;
12268
12269#ifdef KDEBUG
12270 Lp.ecart=0; Lp.length=0;
12271#endif
12272 /*- computes the lcm(s[i],p) -*/
12273 Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12274
12275 /* the V criterion */
12276 if (!pmIsInV(Lp.lcm))
12277 {
12278 strat->cv++; // counter for applying the V criterion
12279 pLmFree(Lp.lcm);
12280#ifdef CRITERION_DEBUG
12281 if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12282#endif
12283 return TRUE;
12284 }
12285
12286 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12287 {
12288 if((!((ecartq>0)&&(ecart>0)))
12289 && pHasNotCF(p,q))
12290 {
12291 /*
12292 *the product criterion has applied for (s,p),
12293 *i.e. lcm(s,p)=product of the leading terms of s and p.
12294 *Suppose (s,r) is in L and the leading term
12295 *of p divides lcm(s,r)
12296 *(==> the leading term of p divides the leading term of r)
12297 *but the leading term of s does not divide the leading term of r
12298 *(notice that this condition is automatically satisfied if r is still
12299 *in S), then (s,r) can be cancelled.
12300 *This should be done here because the
12301 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12302 *
12303 *Moreover, skipping (s,r) holds also for the noncommutative case.
12304 */
12305 strat->cp++;
12306 pLmFree(Lp.lcm);
12307#ifdef CRITERION_DEBUG
12308 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12309#endif
12310 return TRUE;
12311 }
12312 else
12313 Lp.ecart = si_max(ecart,ecartq);
12314 if (strat->fromT && (ecartq>ecart))
12315 {
12316 pLmFree(Lp.lcm);
12317#ifdef CRITERION_DEBUG
12318 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12319#endif
12320 return TRUE;
12321 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12322 }
12323 /*
12324 *the set B collects the pairs of type (S[j],p)
12325 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12326 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12327 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12328 */
12329 {
12330 j = strat->Bl;
12331 loop
12332 {
12333 if (j < 0) break;
12334 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12335 if ((compare==1)
12336 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12337 {
12338 strat->c3++;
12339 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12340 {
12341 pLmFree(Lp.lcm);
12342#ifdef CRITERION_DEBUG
12343 if (TEST_OPT_DEBUG)
12344 {
12345 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12346 }
12347#endif
12348 return TRUE;
12349 }
12350 break;
12351 }
12352 else
12353 if ((compare ==-1)
12354 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12355 {
12356#ifdef CRITERION_DEBUG
12357 if (TEST_OPT_DEBUG)
12358 {
12359 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12360 }
12361#endif
12362 deleteInL(strat->B,&strat->Bl,j,strat);
12363 strat->c3++;
12364 }
12365 j--;
12366 }
12367 }
12368 }
12369 else /*sugarcrit*/
12370 {
12371 if (ALLOW_PROD_CRIT(strat))
12372 {
12373 // if currRing->nc_type!=quasi (or skew)
12374 // TODO: enable productCrit for super commutative algebras...
12375 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12376 pHasNotCF(p,q))
12377 {
12378 /*
12379 *the product criterion has applied for (s,p),
12380 *i.e. lcm(s,p)=product of the leading terms of s and p.
12381 *Suppose (s,r) is in L and the leading term
12382 *of p divides lcm(s,r)
12383 *(==> the leading term of p divides the leading term of r)
12384 *but the leading term of s does not divide the leading term of r
12385 *(notice that tis condition is automatically satisfied if r is still
12386 *in S), then (s,r) can be canceled.
12387 *This should be done here because the
12388 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12389 */
12390 strat->cp++;
12391 pLmFree(Lp.lcm);
12392#ifdef CRITERION_DEBUG
12393 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12394#endif
12395 return TRUE;
12396 }
12397 if (strat->fromT && (ecartq>ecart))
12398 {
12399 pLmFree(Lp.lcm);
12400#ifdef CRITERION_DEBUG
12401 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12402#endif
12403 return TRUE;
12404 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12405 }
12406 /*
12407 *the set B collects the pairs of type (S[j],p)
12408 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12409 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12410 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12411 */
12412 for(j = strat->Bl;j>=0;j--)
12413 {
12414 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12415 if (compare==1)
12416 {
12417 strat->c3++;
12418 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12419 {
12420 pLmFree(Lp.lcm);
12421#ifdef CRITERION_DEBUG
12422 if (TEST_OPT_DEBUG)
12423 {
12424 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12425 }
12426#endif
12427 return TRUE;
12428 }
12429 break;
12430 }
12431 else
12432 if (compare ==-1)
12433 {
12434#ifdef CRITERION_DEBUG
12435 if (TEST_OPT_DEBUG)
12436 {
12437 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12438 }
12439#endif
12440 deleteInL(strat->B,&strat->Bl,j,strat);
12441 strat->c3++;
12442 }
12443 }
12444 }
12445 }
12446 /*
12447 *the pair (S[i],p) enters B if the spoly != 0
12448 */
12449 /*- compute the short s-polynomial -*/
12450 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12451 pNorm(p);
12452 if ((q==NULL) || (p==NULL))
12453 {
12454#ifdef CRITERION_DEBUG
12455 if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
12456#endif
12457 return FALSE;
12458 }
12459 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12460 {
12461 Lp.p=NULL;
12462#ifdef CRITERION_DEBUG
12463 if (TEST_OPT_DEBUG) PrintS("--- pair is from Q\n");
12464#endif
12465 }
12466 else
12467 {
12468// if ( rIsPluralRing(currRing) )
12469// {
12470// if(pHasNotCF(p, q))
12471// {
12472// if(ncRingType(currRing) == nc_lie)
12473// {
12474// // generalized prod-crit for lie-type
12475// strat->cp++;
12476// Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12477// }
12478// else
12479// if( ALLOW_PROD_CRIT(strat) )
12480// {
12481// // product criterion for homogeneous case in SCA
12482// strat->cp++;
12483// Lp.p = NULL;
12484// }
12485// else
12486// Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12487// }
12488// else Lp.p = nc_CreateSpoly(q,p,currRing);
12489// }
12490// else
12491// {
12492
12493 /* ksCreateShortSpoly needs two Lobject-kind presentations */
12494 /* p is already in this form, so convert q */
12495 Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12496 // }
12497 }
12498 if (Lp.p == NULL)
12499 {
12500 /*- the case that the s-poly is 0 -*/
12501 // TODO: currently ifromS is only > 0 if called from enterOnePairWithShifts
12502 if (ifromS > 0)
12503 {
12504 if (strat->pairtest==NULL) initPairtest(strat);
12505 strat->pairtest[ifromS] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12506 strat->pairtest[strat->sl+1] = TRUE;
12507 }
12508 //if (TEST_OPT_DEBUG){Print("!");} // option teach
12509 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12510 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12511 /*
12512 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12513 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12514 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12515 *term of p divides the lcm(s,r)
12516 *(this canceling should be done here because
12517 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12518 *the first case is handled in chainCrit
12519 */
12520 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12521#ifdef CRITERION_DEBUG
12522 if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
12523#endif
12524 return TRUE;
12525 }
12526 else
12527 {
12528 /*- the pair (S[i],p) enters B -*/
12529 /* both of them should have their LM in currRing and TAIL in tailring */
12530 Lp.p1 = q; // already in the needed form
12531 Lp.p2 = p; // already in the needed form
12532
12533 if ( !rIsPluralRing(currRing) )
12534 pNext(Lp.p) = strat->tail;
12535
12536 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12537 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12538 if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12539 {
12540 Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12541 Lp.i_r2 = atR;
12542 }
12543 else
12544 {
12545 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12546 Lp.i_r1 = -1;
12547 Lp.i_r2 = -1;
12548 }
12549 strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12550
12552 {
12555 && (Lp.p->coef!=NULL))
12556 nDelete(&(Lp.p->coef));
12557 }
12558
12559 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12560 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12561#ifdef CRITERION_DEBUG
12562 if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
12563#endif
12564 }
12565 return FALSE;
12566}
12567#endif
12568
12569/*3
12570*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12571* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12572* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12573*/
12574#ifdef HAVE_SHIFTBBA
12575void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12576{
12579 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12580 if (h_lastVblock == 0) return;
12581 assume(pmFirstVblock(h) == 1);
12582 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12583 // atR = -1;
12584 if ((strat->syzComp==0)
12585 || (pGetComp(h)<=strat->syzComp))
12586 {
12587 int i,j;
12589
12590 int degbound = currRing->N/currRing->isLPring;
12592
12593 if (pGetComp(h)==0)
12594 {
12595 if (strat->rightGB)
12596 {
12597 if (isFromQ)
12598 {
12599 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12600 for (i=0; i<=maxShift; i++)
12601 {
12602 poly hh = pLPCopyAndShiftLM(h, i);
12604 for (j=0; j<=k; j++)
12605 {
12606 if (strat->fromQ == NULL || !strat->fromQ[j])
12607 {
12608 new_pair=TRUE;
12609 poly s = strat->S[j];
12610 if (!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12612 }
12613 }
12614 if (delete_hh) pLmDelete(hh);
12615 }
12616 }
12617 else
12618 {
12619 new_pair=TRUE;
12620 for (j=0; j<=k; j++)
12621 {
12622 poly s = strat->S[j];
12623 if (strat->fromQ != NULL && strat->fromQ[j])
12624 {
12625 // pairs (shifts(s[j]),h), (s[j],h)
12627 }
12628 else
12629 {
12630 // pair (h, s[j])
12631 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12632 }
12633 }
12634 }
12635 }
12636 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12637 else if ((isFromQ)&&(strat->fromQ!=NULL))
12638 {
12639 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12640 for (j=0; j<=k; j++)
12641 {
12642 if (!strat->fromQ[j])
12643 {
12644 new_pair=TRUE;
12645 poly s = strat->S[j];
12647 }
12648 }
12649 // pairs (shifts(h),s[1..k])
12650 if (new_pair)
12651 {
12652 for (i=1; i<=maxShift; i++)
12653 {
12655 poly hh = pLPCopyAndShiftLM(h, i);
12656 for (j=0; j<=k; j++)
12657 {
12658 if (!strat->fromQ[j])
12659 {
12660 poly s = strat->S[j];
12662 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)
12663 {
12664 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i))
12666 }
12667#ifdef HAVE_RINGS
12668 else if (rField_is_Ring(currRing))
12669 {
12670 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12672 for (int k = 0; k < IDELEMS(fillers); k++)
12673 {
12676 }
12677 idDelete(&fillers);
12678 }
12679#endif
12680 }
12681 }
12683 }
12684 }
12685 }
12686 else
12687 {
12688 new_pair=TRUE;
12689 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12690 for (j=0; j<=k; j++)
12691 {
12692 poly s = strat->S[j];
12694 }
12695 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12696 for (i=1; i<=maxShift; i++)
12697 {
12698 poly hh = pLPCopyAndShiftLM(h, i);
12700 for (j=0; j<=k; j++)
12701 {
12702 poly s = strat->S[j];
12704 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)
12706 && delete_hh;
12707#ifdef HAVE_RINGS
12708 else if (rField_is_Ring(currRing))
12709 {
12710 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12712 for (int k = 0; k < IDELEMS(fillers); k++)
12713 {
12716 }
12717 idDelete(&fillers);
12718 }
12719#endif
12720 }
12721 if (i < h_lastVblock) // in the module case, product criterion does not hold (note: comp h is always zero here)
12723 && delete_hh;
12724#ifdef HAVE_RINGS
12725 else if (rField_is_Ring(currRing))
12726 {
12727 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12729 for (int k = 0; k < IDELEMS(fillers); k++)
12730 {
12733 }
12734 idDelete(&fillers);
12735 }
12736#endif
12737 if (delete_hh) pLmDelete(hh);
12738 }
12739 }
12740 }
12741 else
12742 {
12743 assume(isFromQ == 0); // an element from Q should always has 0 component
12744 new_pair=TRUE;
12745 if (strat->rightGB)
12746 {
12747 for (j=0; j<=k; j++)
12748 {
12749 if ((pGetComp(h)==pGetComp(strat->S[j]))
12750 || (pGetComp(strat->S[j])==0))
12751 {
12752 poly s = strat->S[j];
12753 if (strat->fromQ != NULL && strat->fromQ[j])
12754 {
12755 // pairs (shifts(s[j]),h), (s[j],h)
12757 }
12758 else
12759 {
12760 // pair (h, s[j])
12761 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12762 }
12763 }
12764 }
12765 }
12766 else
12767 {
12768 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12769 for (j=0; j<=k; j++)
12770 {
12771 if ((pGetComp(h)==pGetComp(strat->S[j]))
12772 || (pGetComp(strat->S[j])==0))
12773 {
12774 poly s = strat->S[j];
12776 }
12777 }
12778 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12779 for (i=1; i<=maxShift; i++)
12780 {
12781 poly hh = pLPCopyAndShiftLM(h, i);
12782 for (j=0; j<=k; j++)
12783 {
12784 if ((pGetComp(h)==pGetComp(strat->S[j]))
12785 || (pGetComp(strat->S[j])==0))
12786 {
12787 poly s = strat->S[j];
12789 if (i <= s_lastVblock) // in the module case, product criterion does not hold
12790 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
12791#ifdef HAVE_RINGS
12792 else if (rField_is_Ring(currRing))
12793 {
12794 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12796 for (int k = 0; k < IDELEMS(fillers); k++)
12797 {
12800 }
12801 idDelete(&fillers);
12802 }
12803#endif
12804 }
12805 }
12806 if (i <= h_lastVblock) // in the module case, product criterion does not hold
12807 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12808#ifdef HAVE_RINGS
12809 else if (rField_is_Ring(currRing))
12810 {
12811 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12813 for (int k = 0; k < IDELEMS(fillers); k++)
12814 {
12820 }
12821 idDelete(&fillers);
12822 }
12823#endif
12824 }
12825 }
12826 }
12827
12828 if (new_pair)
12829 {
12830 strat->chainCrit(h,ecart,strat);
12831 }
12832 kMergeBintoL(strat);
12833 }
12834}
12835#endif
12836
12837/*3
12838*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12839* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12840* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12841*/
12842#ifdef HAVE_SHIFTBBA
12843void initenterstrongPairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12844{
12847 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12848 if (h_lastVblock == 0) return;
12849 assume(pmFirstVblock(h) == 1);
12850 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12851 // atR = -1;
12852 if ((strat->syzComp==0)
12853 || (pGetComp(h)<=strat->syzComp))
12854 {
12855 int i,j;
12857
12858 int degbound = currRing->N/currRing->isLPring;
12860
12861 if (pGetComp(h)==0)
12862 {
12863 if (strat->rightGB)
12864 {
12865 if (isFromQ)
12866 {
12867 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12868 for (i=0; i<=maxShift; i++)
12869 {
12870 poly hh = pLPCopyAndShiftLM(h, i);
12871 for (j=0; j<=k; j++)
12872 {
12873 if (strat->fromQ == NULL || !strat->fromQ[j])
12874 {
12875 new_pair=TRUE;
12876 poly s = strat->S[j];
12877 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12878 }
12879 }
12880 }
12881 }
12882 else
12883 {
12884 new_pair=TRUE;
12885 for (j=0; j<=k; j++)
12886 {
12887 poly s = strat->S[j];
12888 if (strat->fromQ != NULL && strat->fromQ[j])
12889 {
12890 // pairs (shifts(s[j]),h), (s[j],h)
12892 }
12893 else
12894 {
12895 // pair (h, s[j])
12896 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12897 }
12898 }
12899 }
12900 }
12901 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12902 else if ((isFromQ)&&(strat->fromQ!=NULL))
12903 {
12904 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12905 for (j=0; j<=k; j++)
12906 {
12907 if (!strat->fromQ[j])
12908 {
12909 new_pair=TRUE;
12910 poly s = strat->S[j];
12912 }
12913 }
12914 // pairs (shifts(h),s[1..k])
12915 if (new_pair)
12916 {
12917 for (i=1; i<=maxShift; i++)
12918 {
12919 poly hh = pLPCopyAndShiftLM(h, i);
12920 for (j=0; j<=k; j++)
12921 {
12922 if (!strat->fromQ[j])
12923 {
12924 poly s = strat->S[j];
12925 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12926 }
12927 }
12928 }
12929 }
12930 }
12931 else
12932 {
12933 new_pair=TRUE;
12934 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12935 for (j=0; j<=k; j++)
12936 {
12937 poly s = strat->S[j];
12938 // TODO: cache lastVblock of s[1..k] for later use
12940 }
12941 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12942 for (i=1; i<=maxShift; i++)
12943 {
12944 poly hh = pLPCopyAndShiftLM(h, i);
12946 for (j=0; j<=k; j++)
12947 {
12948 poly s = strat->S[j];
12949 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12951 }
12952 if(!enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i))
12955 }
12956 }
12957 }
12958 else
12959 {
12960 new_pair=TRUE;
12961 if (strat->rightGB)
12962 {
12963 for (j=0; j<=k; j++)
12964 {
12965 if ((pGetComp(h)==pGetComp(strat->S[j]))
12966 || (pGetComp(strat->S[j])==0))
12967 {
12968 assume(isFromQ == 0); // this case is not handled here and should also never happen
12969 poly s = strat->S[j];
12970 if (strat->fromQ != NULL && strat->fromQ[j])
12971 {
12972 // pairs (shifts(s[j]),h), (s[j],h)
12974 }
12975 else
12976 {
12977 // pair (h, s[j])
12978 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12979 }
12980 }
12981 }
12982 }
12983 else
12984 {
12985 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12986 for (j=0; j<=k; j++)
12987 {
12988 if ((pGetComp(h)==pGetComp(strat->S[j]))
12989 || (pGetComp(strat->S[j])==0))
12990 {
12991 poly s = strat->S[j];
12993 }
12994 }
12995 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12996 for (i=1; i<=maxShift; i++)
12997 {
12998 poly hh = pLPCopyAndShiftLM(h, i);
12999 for (j=0; j<=k; j++)
13000 {
13001 if ((pGetComp(h)==pGetComp(strat->S[j]))
13002 || (pGetComp(strat->S[j])==0))
13003 {
13004 poly s = strat->S[j];
13005 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13006 }
13007 }
13008 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13009 }
13010 }
13011 }
13012
13013 if (new_pair)
13014 {
13015 strat->chainCrit(h,ecart,strat);
13016 }
13017 kMergeBintoL(strat);
13018 }
13019}
13020#endif
13021
13022/*2
13023*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
13024*superfluous elements in S will be deleted
13025*/
13026#ifdef HAVE_SHIFTBBA
13027void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
13028{
13029 /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13030 /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
13031 int j=pos;
13032
13033 /* if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat); */ // TODO: enterExtendedSpoly not for LP yet
13034 initenterpairsShift(h,k,ecart,0,strat, atR);
13035 if ( (!strat->fromT)
13036 && ((strat->syzComp==0)
13037 ||(pGetComp(h)<=strat->syzComp)))
13038 {
13039 unsigned long h_sev = pGetShortExpVector(h);
13040 loop
13041 {
13042 if (j > k) break;
13043 // TODO this currently doesn't clear all possible elements because of commutative division
13044 if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
13045 clearS(h,h_sev, &j,&k,strat);
13046 j++;
13047 }
13048 }
13049}
13050#endif
13051
13052/*2
13053* enteres all admissible shifts of p into T
13054* assumes that p is already in T!
13055*/
13056#ifdef HAVE_SHIFTBBA
13058{
13059 /* determine how many elements we have to insert */
13060 /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
13061 /* hence, a total number of elt's to add is: */
13062 /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
13063 pAssume(p.p != NULL);
13064
13066
13067 for (int i = 1; i <= maxPossibleShift; i++)
13068 {
13069 LObject qq;
13070 qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
13071 qq.shift = i;
13072 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
13073
13074 enterT(qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
13075 }
13076}
13077#endif
13078
13079#ifdef HAVE_SHIFTBBA
13081{
13082 /* for the shift case need to run it with withT = TRUE */
13083 strat->redTailChange=FALSE;
13084 if (strat->noTailReduction) return L->GetLmCurrRing();
13085 poly h, p;
13086 p = h = L->GetLmTailRing();
13087 if ((h==NULL) || (pNext(h)==NULL))
13088 return L->GetLmCurrRing();
13089
13090 TObject* With;
13091 // placeholder in case strat->tl < 0
13092 TObject With_s(strat->tailRing);
13093
13094 LObject Ln(pNext(h), strat->tailRing);
13095 Ln.pLength = L->GetpLength() - 1;
13096
13097 pNext(h) = NULL;
13098 if (L->p != NULL) pNext(L->p) = NULL;
13099 L->pLength = 1;
13100
13101 Ln.PrepareRed(strat->use_buckets);
13102
13103 while(!Ln.IsNull())
13104 {
13105 loop
13106 {
13107 Ln.SetShortExpVector();
13108 if (withT)
13109 {
13110 int j;
13111 j = kFindDivisibleByInT(strat, &Ln);
13112 if (j < 0) break;
13113 With = &(strat->T[j]);
13114 }
13115 else
13116 {
13117 With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
13118 if (With == NULL) break;
13119 }
13120 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
13121 {
13122 With->pNorm();
13123 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
13124 }
13125 strat->redTailChange=TRUE;
13126 if (ksReducePolyTail(L, With, &Ln))
13127 {
13128 // reducing the tail would violate the exp bound
13129 // set a flag and hope for a retry (in bba)
13131 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
13132 do
13133 {
13134 pNext(h) = Ln.LmExtractAndIter();
13135 pIter(h);
13136 L->pLength++;
13137 } while (!Ln.IsNull());
13138 goto all_done;
13139 }
13140 if (Ln.IsNull()) goto all_done;
13141 if (! withT) With_s.Init(currRing);
13142 }
13143 pNext(h) = Ln.LmExtractAndIter();
13144 pIter(h);
13145 L->pLength++;
13146 }
13147
13148 all_done:
13149 Ln.Delete();
13150 if (L->p != NULL) pNext(L->p) = pNext(p);
13151
13152 if (strat->redTailChange)
13153 {
13154 L->length = 0;
13155 }
13156 L->Normalize(); // HANNES: should have a test
13157 kTest_L(L,strat);
13158 return L->GetLmCurrRing();
13159}
13160#endif
static int si_max(const int a, const int b)
Definition auxiliary.h:124
int BOOLEAN
Definition auxiliary.h:87
#define TRUE
Definition auxiliary.h:100
#define FALSE
Definition auxiliary.h:96
static int si_min(const int a, const int b)
Definition auxiliary.h:125
CanonicalForm lc(const CanonicalForm &f)
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition cf_gcd.cc:676
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
int p
Definition cfModGcd.cc:4078
bool equal
Definition cfModGcd.cc:4126
CanonicalForm b
Definition cfModGcd.cc:4103
static CanonicalForm bound(const CFMatrix &M)
Definition cf_linsys.cc:460
int length() const
poly p
Definition kutil.h:73
poly t_p
Definition kutil.h:74
ring tailRing
Definition kutil.h:76
void wrp()
Definition kutil.cc:772
KINLINE poly kNoetherTail()
Definition kInline.h:66
unsigned long * sevSyz
Definition kutil.h:323
kStrategy next
Definition kutil.h:277
bool sigdrop
Definition kutil.h:359
poly t_kNoether
Definition kutil.h:330
int syzComp
Definition kutil.h:354
int * S_2_R
Definition kutil.h:342
ring tailRing
Definition kutil.h:343
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition kutil.h:291
char noTailReduction
Definition kutil.h:378
int currIdx
Definition kutil.h:317
int nrsyzcrit
Definition kutil.h:360
intset lenS
Definition kutil.h:319
int nrrewcrit
Definition kutil.h:361
pFDegProc pOrigFDeg_TailRing
Definition kutil.h:298
int Ll
Definition kutil.h:351
TSet T
Definition kutil.h:326
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition kutil.h:293
char news
Definition kutil.h:400
omBin lmBin
Definition kutil.h:344
int syzmax
Definition kutil.h:349
int Bl
Definition kutil.h:352
intset ecartS
Definition kutil.h:309
int syzidxmax
Definition kutil.h:349
char honey
Definition kutil.h:377
char rightGB
Definition kutil.h:369
polyset S
Definition kutil.h:306
int minim
Definition kutil.h:357
poly kNoether
Definition kutil.h:329
BOOLEAN * NotUsedAxis
Definition kutil.h:332
LSet B
Definition kutil.h:328
BOOLEAN * pairtest
Definition kutil.h:333
int cp
Definition kutil.h:347
int ak
Definition kutil.h:353
TObject ** R
Definition kutil.h:340
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition kutil.h:295
int tl
Definition kutil.h:350
unsigned long * sevT
Definition kutil.h:325
unsigned long * sevSig
Definition kutil.h:324
int nr
Definition kutil.h:346
poly tail
Definition kutil.h:334
char sugarCrit
Definition kutil.h:377
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition kutil.h:284
KINLINE TObject * s_2_t(int i)
Definition kInline.h:47
intset syzIdx
Definition kutil.h:313
ideal Shdl
Definition kutil.h:303
int syzl
Definition kutil.h:349
unsigned sbaOrder
Definition kutil.h:316
pFDegProc pOrigFDeg
Definition kutil.h:296
int tmax
Definition kutil.h:350
polyset sig
Definition kutil.h:308
polyset syz
Definition kutil.h:307
char LDegLast
Definition kutil.h:385
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition kutil.h:287
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.h:292
wlen_set lenSw
Definition kutil.h:320
char kAllAxis
Definition kutil.h:376
int cv
Definition kutil.h:368
pShallowCopyDeleteProc p_shallow_copy_delete
Definition kutil.h:338
char Gebauer
Definition kutil.h:378
intset fromQ
Definition kutil.h:321
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition kutil.h:286
char newt
Definition kutil.h:401
char use_buckets
Definition kutil.h:383
char interpt
Definition kutil.h:371
char redTailChange
Definition kutil.h:399
int newIdeal
Definition kutil.h:356
char fromT
Definition kutil.h:379
char completeReduce_retry
Definition kutil.h:403
void(* initEcart)(TObject *L)
Definition kutil.h:280
omBin tailBin
Definition kutil.h:345
LObject P
Definition kutil.h:302
KINLINE TObject * S_2_T(int i)
Definition kInline.h:38
char noClearS
Definition kutil.h:402
int Lmax
Definition kutil.h:351
char z2homog
Definition kutil.h:374
int LazyPass
Definition kutil.h:353
char overflow
Definition kutil.h:404
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.h:290
LSet L
Definition kutil.h:327
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition kutil.h:281
int(* red)(LObject *L, kStrategy strat)
Definition kutil.h:278
int sl
Definition kutil.h:348
int LazyDegree
Definition kutil.h:353
char posInLDependsOnLength
Definition kutil.h:389
unsigned long * sevS
Definition kutil.h:322
char homog
Definition kutil.h:372
pLDegProc pOrigLDeg
Definition kutil.h:297
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition kutil.h:282
pLDegProc pOrigLDeg_TailRing
Definition kutil.h:299
int Bmax
Definition kutil.h:352
int c3
Definition kutil.h:347
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition coeffs.h:813
@ 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:661
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:512
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:676
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:697
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:414
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:452
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:687
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:668
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:535
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:625
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether 'a' is divisible 'b'; for r encoding a field: TRUE iff 'b' does not represent zero in Z:...
Definition coeffs.h:750
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition coeffs.h:519
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:73
void nKillChar(coeffs r)
undo all initialisations
Definition numbers.cc:569
#define Print
Definition emacs.cc:80
#define WarnS
Definition emacs.cc:78
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
bool found
int j
Definition facHensel.cc:110
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
static int min(int a, int b)
Definition fast_mult.cc:268
static int max(int a, int b)
Definition fast_mult.cc:264
#define STATIC_VAR
Definition globaldefs.h:7
#define VAR
Definition globaldefs.h:5
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge)
Definition hdegree.cc:1100
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition ideals.cc:830
#define idDelete(H)
delete an ideal
Definition ideals.h:29
#define idIsConstant(I)
Definition ideals.h:40
BOOLEAN idInsertPoly(ideal h1, poly h2)
insert h2 into h1 (if h2 is not the zero polynomial) return TRUE iff h2 was indeed inserted
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
ideal idCopy(ideal A)
Definition ideals.h:60
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition ideals.h:37
static BOOLEAN length(leftv result, leftv arg)
Definition interval.cc:257
STATIC_VAR jList * T
Definition janet.cc:30
STATIC_VAR Poly * h
Definition janet.cc:971
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition kInline.h:958
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:1108
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition kInline.h:1175
KINLINE TObject ** initR()
Definition kInline.h:95
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition kInline.h:1148
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition kInline.h:1185
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition kInline.h:1238
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:1017
KINLINE int ksReducePolyTail_Z(LObject *PR, TObject *PW, LObject *Red)
Definition kInline.h:1126
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:1453
long kHomModDeg(poly p, const ring r)
Definition kstd1.cc:2436
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition kstd1.cc:1365
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition kstd1.cc:3235
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
Definition kstd1.cc:2483
int kFindDivisibleByInT_Z(const kStrategy strat, const LObject *L, const int start)
Definition kstd2.cc:213
int redHoney(LObject *h, kStrategy strat)
Definition kstd2.cc:2074
int redHomog(LObject *h, kStrategy strat)
Definition kstd2.cc:1114
int redLazy(LObject *h, kStrategy strat)
Definition kstd2.cc:1869
poly redNF(poly h, int &max_ind, int nonorm, kStrategy strat)
Definition kstd2.cc:2309
int redRing(LObject *h, kStrategy strat)
Definition kstd2.cc:951
int kFindDivisibleByInT(const kStrategy strat, const LObject *L, const int start)
return -1 if no divisor is found number of first divisor in T, otherwise
Definition kstd2.cc:321
void initSbaPos(kStrategy strat)
Definition kutil.cc:9910
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition kutil.cc:7511
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:6882
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6338
#define pDivComp_LESS
Definition kutil.cc:136
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6453
int getIndexRng(long coeff)
Definition kutil.cc:6034
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6092
int posInT17(const TSet set, const int length, LObject &p)
Definition kutil.cc:5305
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:9799
int redFirst(LObject *h, kStrategy strat)
Definition kstd1.cc:797
VAR int HCord
Definition kutil.cc:246
void kMergeBintoL(kStrategy strat)
Definition kutil.cc:3173
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition kutil.cc:543
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition kutil.cc:6688
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9379
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5875
int redEcart(LObject *h, kStrategy strat)
Definition kstd1.cc:169
int posInT11(const TSet set, const int length, LObject &p)
Definition kutil.cc:4974
void enterT(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9177
int posInT1(const TSet set, const int length, LObject &p)
Definition kutil.cc:4917
void enterTShift(LObject p, kStrategy strat, int atT)
Definition kutil.cc:13057
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5095
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition kutil.cc:6663
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8951
BOOLEAN kTest(kStrategy strat)
Definition kutil.cc:1011
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:3946
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition kstd1.cc:1681
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:7071
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:5171
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition kutil.cc:6739
int posInT0(const TSet, const int length, LObject &)
Definition kutil.cc:4906
BOOLEAN kTest_TS(kStrategy strat)
Definition kutil.cc:1072
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:1951
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition kutil.cc:717
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition kutil.cc:10572
VAR int Kstd1_mu
Definition kutil.cc:248
void initenterstrongPairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:12843
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4534
static void enterOnePairRingShift(poly q, poly p, int, int isFromQ, kStrategy strat, int atR, int, int qisFromQ, int shiftcount, int ifromS)
Definition kutil.cc:11874
static const char * kTest_LmEqual(poly p, poly t_p, ring tailRing)
Definition kutil.cc:782
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition kutil.cc:1279
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition kutil.cc:6604
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:12118
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition kutil.cc:4451
static int pLPDivComp(poly p, poly q)
Definition kutil.cc:232
int posInT2(const TSet set, const int length, LObject &p)
Definition kutil.cc:4946
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6181
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6134
#define kFalseReturn(x)
Definition kutil.cc:779
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:12128
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11525
static intset initec(const int maxnr)
Definition kutil.cc:529
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition kutil.cc:9611
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4508
int posInT13(const TSet set, const int length, LObject &p)
Definition kutil.cc:5142
void redtailBbaAlsoLC_Z(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7187
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.cc:6555
static void deleteHCBucket(LObject *L, kStrategy strat)
Definition kutil.cc:250
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition kutil.cc:9457
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:12193
void chainCritSig(poly p, int, kStrategy strat)
Definition kutil.cc:3473
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition kutil.cc:4785
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition kutil.cc:1325
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:4166
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4490
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8548
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5670
static int pDivCompRing(poly p, poly q)
Definition kutil.cc:144
void initBuchMoraPos(kStrategy strat)
Definition kutil.cc:9626
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:3821
void initS(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7634
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition kutil.cc:11020
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:6958
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7316
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition kutil.cc:11141
void initPairtest(kStrategy strat)
Definition kutil.cc:692
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:2214
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5642
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition kutil.cc:8130
void chainCritOpt_1(poly, int, kStrategy strat)
Definition kutil.cc:3457
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5011
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:1345
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8524
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition kutil.cc:8436
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:12575
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:4221
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:3886
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6216
static void enlargeL(LSet *L, int *length, const int incr)
Definition kutil.cc:682
int posInT17_c(const TSet set, const int length, LObject &p)
Definition kutil.cc:5413
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:13080
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11434
int posInT15(const TSet set, const int length, LObject &p)
Definition kutil.cc:5209
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9277
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition kutil.cc:10762
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.cc:6520
void HEckeTest(poly pp, kStrategy strat)
Definition kutil.cc:500
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5598
STATIC_VAR BOOLEAN sloppy_max
Definition kutil.cc:799
VAR int Kstd1_deg
Definition kutil.cc:247
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition kutil.cc:4332
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:13027
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:2445
BOOLEAN kTest_L(LObject *L, kStrategy strat, BOOLEAN testp, int lpos, TSet T, int tlength)
Definition kutil.cc:925
void exitBuchMora(kStrategy strat)
Definition kutil.cc:9884
void messageStatSBA(int hilbcount, kStrategy strat)
Definition kutil.cc:7565
void initEcartNormal(TObject *h)
Definition kutil.cc:1303
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition kutil.cc:4684
void updateS(BOOLEAN toT, kStrategy strat)
Definition kutil.cc:8593
static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
Definition kutil.cc:1187
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7825
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5945
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition kutil.cc:3104
static int * initS_2_R(const int maxnr)
Definition kutil.cc:538
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6293
void initSyzRules(kStrategy strat)
Definition kutil.cc:7975
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5702
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:10012
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition kutil.cc:10533
void cleanT(kStrategy strat)
Definition kutil.cc:564
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:2233
int posInT110(const TSet set, const int length, LObject &p)
Definition kutil.cc:5052
BOOLEAN kTest_S(kStrategy strat)
Definition kutil.cc:1054
int posInSyz(const kStrategy strat, poly sig)
Definition kutil.cc:5791
void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
Definition kutil.cc:9086
void reorderS(int *suc, kStrategy strat)
Definition kutil.cc:4631
void enterExtendedSpoly(poly h, kStrategy strat)
Definition kutil.cc:4248
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6252
#define pDivComp_INCOMP
Definition kutil.cc:138
BOOLEAN kTest_T(TObject *T, kStrategy strat, int i, char TN)
Definition kutil.cc:800
void kMergeBintoLSba(kStrategy strat)
Definition kutil.cc:3194
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition kutil.cc:293
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition kutil.cc:10127
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4477
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition kutil.cc:1336
int posInT19(const TSet set, const int length, LObject &p)
Definition kutil.cc:5541
poly redtailBba_NF(poly p, kStrategy strat)
Definition kutil.cc:7397
#define pDivComp_GREATER
Definition kutil.cc:137
void exitSba(kStrategy strat)
Definition kutil.cc:10087
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5264
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5367
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition kutil.cc:1549
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:12233
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition kutil.cc:11559
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition kutil.cc:1214
void kStratInitChangeTailRing(kStrategy strat)
Definition kutil.cc:11113
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition kutil.cc:3532
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition kstd1.cc:1628
void initBuchMoraCrit(kStrategy strat)
Definition kutil.cc:9475
void cleanTSbaRing(kStrategy strat)
Definition kutil.cc:623
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition kutil.cc:5475
static int pDivComp(poly p, poly q)
Definition kutil.cc:183
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition kutil.cc:10339
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6388
void initBuchMoraPosRing(kStrategy strat)
Definition kutil.cc:9712
int kFindInTShift(poly p, TSet T, int tlength)
Definition kutil.cc:742
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition kutil.cc:10838
static BOOLEAN enterOneStrongPolyShift(poly q, poly p, int, int, kStrategy strat, int atR, int, int, int shiftcount, int ifromS)
Definition kutil.cc:11705
void messageSets(kStrategy strat)
Definition kutil.cc:7584
void deleteInS(int i, kStrategy strat)
Definition kutil.cc:1138
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8419
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11488
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5727
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition kutil.cc:701
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition kutil.cc:1699
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5909
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:10595
static unsigned long * initsevS(const int maxnr)
Definition kutil.cc:534
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition kutil.cc:4557
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition kutil.cc:3216
void initEcartBBA(TObject *h)
Definition kutil.cc:1311
VAR denominator_list DENOMINATOR_LIST
Definition kutil.cc:84
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:2702
void enterSBbaShift(LObject &p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8928
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5832
char * showOption()
Definition misc_ip.cc:709
poly redtailBba_Ring(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7422
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition kutil.cc:5820
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition kutil.cc:1318
void messageStat(int hilbcount, kStrategy strat)
Definition kutil.cc:7552
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition kutil.cc:1757
void chainCritRing(poly p, int, kStrategy strat)
Definition kutil.cc:4008
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition kutil.cc:8274
void initSL(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7728
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition kutil.cc:4862
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition kutil.cc:10927
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8828
void initSbaCrit(kStrategy strat)
Definition kutil.cc:9540
BOOLEAN newHEdge(kStrategy strat)
Definition kutil.cc:10461
#define pDivComp_EQUAL
Definition kutil.cc:135
void cancelunit(LObject *L, BOOLEAN inNF)
Definition kutil.cc:372
denominator_list_s * denominator_list
Definition kutil.h:63
TObject * TSet
Definition kutil.h:59
#define setmaxL
Definition kutil.h:30
#define setmaxTinc
Definition kutil.h:34
static int kFindInL1(const poly p, const kStrategy strat)
Definition kutil.h:851
#define setmax
Definition kutil.h:29
EXTERN_VAR int strat_nr
Definition kutil.h:181
int64 wlen_type
Definition kutil.h:54
static LSet initL(int nr=setmaxL)
Definition kutil.h:420
LObject * LSet
Definition kutil.h:60
static void kDeleteLcm(LObject *P)
Definition kutil.h:880
int * intset
Definition kutil.h:53
#define ALLOW_PROD_CRIT(A)
Definition kutil.h:395
#define setmaxT
Definition kutil.h:33
#define setmaxLinc
Definition kutil.h:31
class sTObject TObject
Definition kutil.h:57
#define REDTAIL_CANONICALIZE
Definition kutil.h:38
class sLObject LObject
Definition kutil.h:58
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:121
#define TEST_OPT_IDLIFT
Definition options.h:129
#define TEST_OPT_INTSTRATEGY
Definition options.h:110
#define TEST_OPT_REDTAIL
Definition options.h:116
#define TEST_OPT_INFREDTAIL
Definition options.h:118
#define TEST_OPT_SUGARCRIT
Definition options.h:107
#define TEST_OPT_OLDSTD
Definition options.h:123
#define TEST_OPT_REDSB
Definition options.h:104
#define TEST_OPT_DEGBOUND
Definition options.h:113
#define TEST_OPT_SB_1
Definition options.h:119
#define TEST_OPT_NOT_SUGAR
Definition options.h:106
#define TEST_OPT_PROT
Definition options.h:103
#define OPT_INTERRUPT
Definition options.h:79
#define TEST_OPT_CANCELUNIT
Definition options.h:128
#define BTEST1(a)
Definition options.h:34
#define TEST_OPT_DEBUG
Definition options.h:108
#define TEST_OPT_CONTENTSB
Definition options.h:127
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
static int index(p_Length length, p_Ord ord)
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:1138
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition p_polys.cc:2954
long pLDegb(poly p, int *l, const ring r)
Definition p_polys.cc:811
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition p_polys.cc:975
long p_WFirstTotalDegree(poly p, const ring r)
Definition p_polys.cc:596
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition p_polys.cc:1038
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition p_polys.cc:3649
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition p_polys.cc:1068
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition p_polys.cc:4526
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition p_polys.cc:941
long pLDeg1(poly p, int *l, const ring r)
Definition p_polys.cc:841
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition p_polys.cc:4780
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition p_polys.cc:910
long p_WTotaldegree(poly p, const ring r)
Definition p_polys.cc:613
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition p_polys.cc:1208
poly p_Cleardenom(poly p, const ring r)
Definition p_polys.cc:2845
long pLDeg1c(poly p, int *l, const ring r)
Definition p_polys.cc:877
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition p_polys.cc:1005
long pLDeg0c(poly p, int *l, const ring r)
Definition p_polys.cc:770
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:1175
long pLDeg0(poly p, int *l, const ring r)
Definition p_polys.cc:739
poly p_One(const ring r)
Definition p_polys.cc:1313
poly p_Sub(poly p1, poly p2, const ring r)
Definition p_polys.cc:1990
void pEnlargeSet(poly **p, int l, int increment)
Definition p_polys.cc:3696
long p_Deg(poly a, const ring r)
Definition p_polys.cc:587
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition p_polys.cc:1655
static poly p_Neg(poly p, const ring r)
Definition p_polys.h:1107
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:1425
static poly p_Add_q(poly p, poly q, const ring r)
Definition p_polys.h:936
static void p_LmDelete(poly p, const ring r)
Definition p_polys.h:723
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition p_polys.h:1411
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:1856
static long p_FDeg(const poly p, const ring r)
Definition p_polys.h:380
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition p_polys.h:781
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition p_polys.h:1313
static void p_LmDelete0(poly p, const ring r)
Definition p_polys.h:733
static int p_Cmp(poly p1, poly p2, ring r)
Definition p_polys.h:1727
#define __pp_Mult_nn(p, n, r)
Definition p_polys.h:1002
static poly pp_mm_Mult(poly p, poly m, const ring r)
Definition p_polys.h:1041
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition p_polys.h:1031
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition p_polys.h:1647
static void p_SetCompP(poly p, int i, ring r)
Definition p_polys.h:254
#define pp_Test(p, lmRing, tailRing)
Definition p_polys.h:163
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition p_polys.h:247
static void p_Setm(poly p, const ring r)
Definition p_polys.h:233
static number p_SetCoeff(poly p, number n, ring r)
Definition p_polys.h:412
static int p_LmCmp(poly p, poly q, const ring r)
Definition p_polys.h:1580
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition p_polys.h:1910
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition p_polys.h:469
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition pDebug.cc:74
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition p_polys.h:1891
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition p_polys.h:928
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:901
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition pDebug.cc:115
static poly p_LmFreeAndNext(poly p, ring)
Definition p_polys.h:711
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition p_polys.h:1051
static void p_LmFree(poly p, ring)
Definition p_polys.h:683
#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:846
static long p_Totaldegree(poly p, const ring r)
Definition p_polys.h:1507
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition p_polys.h:1999
#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:15
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:123
#define pLtCmpOrdSgnDiffM(p, q)
Definition polys.h:125
#define pDelete(p_ptr)
Definition polys.h:186
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL
Definition polys.h:67
#define pLmIsConstantComp(p)
like above, except that p must be != NULL
Definition polys.h:242
#define pSetm(p)
Definition polys.h:271
#define pIsConstant(p)
like above, except that Comp must be 0
Definition polys.h:238
#define pHasNotCF(p1, p2)
Definition polys.h:263
#define pLtCmpOrdSgnDiffP(p, q)
Definition polys.h:126
#define pNeg(p)
Definition polys.h:198
#define pLmEqual(p1, p2)
Definition polys.h:111
#define ppMult_mm(p, m)
Definition polys.h:201
#define pGetComp(p)
Component.
Definition polys.h:37
#define pIsVector(p)
Definition polys.h:250
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition polys.h:31
void pNorm(poly p)
Definition polys.h:362
#define pJet(p, m)
Definition polys.h:367
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition polys.h:146
#define pCmp(p1, p2)
pCmp: args may be NULL returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
Definition polys.h:115
#define pDivideM(a, b)
Definition polys.h:294
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition polys.h:64
#define pSetComp(p, v)
Definition polys.h:38
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition polys.h:76
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl....
Definition polys.h:152
void wrp(poly p)
Definition polys.h:310
#define pLmDivisibleBy(a, b)
like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
Definition polys.h:140
static void pLmFree(poly p)
frees the space of the monomial m, assumes m != NULL coef is not freed, m is not advanced
Definition polys.h:70
void pWrite(poly p)
Definition polys.h:308
#define pGetExp(p, i)
Exponent.
Definition polys.h:41
#define pSetmComp(p)
TODO:
Definition polys.h:273
#define pHasNotCFRing(p1, p2)
Definition polys.h:262
#define pNormalize(p)
Definition polys.h:317
#define pIsPurePower(p)
Definition polys.h:248
#define pInit()
allocates a new monomial and initializes everything to 0
Definition polys.h:61
#define pEqualPolys(p1, p2)
Definition polys.h:399
#define pDivisibleBy(a, b)
returns TRUE, if leading monom of a divides leading monom of b i.e., if there exists a expvector c > ...
Definition polys.h:138
#define pSetExp(p, i, v)
Definition polys.h:42
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition polys.h:105
#define pLtCmpOrdSgnEqP(p, q)
Definition polys.h:128
char * pString(poly p)
Definition polys.h:306
#define pCopy(p)
return a copy of the poly
Definition polys.h:185
#define pOne()
Definition polys.h:315
poly * polyset
Definition polys.h:259
#define pDecrExp(p, i)
Definition polys.h:44
#define pLcm(a, b, m)
Definition polys.h:295
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
Definition prCopy.cc:45
void pLcmRat(poly a, poly b, poly m, int rat_shift)
Definition ratgring.cc:30
void PrintS(const char *s)
Definition reporter.cc:284
void PrintLn()
Definition reporter.cc:310
#define mflush()
Definition reporter.h:58
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition ring.cc:3464
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition ring.cc:5751
void rKillModifiedRing(ring r)
Definition ring.cc:3073
ring rAssure_c_dp(const ring r)
Definition ring.cc:5056
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition ring.cc:2712
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition ring.cc:1421
void rDebugPrint(const ring r)
Definition ring.cc:4136
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:450
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition ring.h:400
static int rBlocks(const ring r)
Definition ring.h:568
static int rGetCurrSyzLimit(const ring r)
Definition ring.h:723
static BOOLEAN rField_is_Domain(const ring r)
Definition ring.h:487
static BOOLEAN rIsRatGRing(const ring r)
Definition ring.h:427
static BOOLEAN rIsLPRing(const ring r)
Definition ring.h:411
rRingOrder_t
order stuff
Definition ring.h:68
@ ringorder_a
Definition ring.h:70
@ ringorder_C
Definition ring.h:73
@ ringorder_c
Definition ring.h:72
BOOLEAN rHasMixedOrdering(const ring r)
Definition ring.h:763
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition ring.h:720
poly(* pShallowCopyDeleteProc)(poly s_p, ring source_r, ring dest_r, omBin dest_bin)
returns a poly from dest_r which is a ShallowCopy of s_p from source_r assumes that source_r->N == de...
Definition ring.h:44
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition ring.h:592
BOOLEAN rHasGlobalOrdering(const ring r)
Definition ring.h:761
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition ring.h:762
#define rField_is_Ring(R)
Definition ring.h:485
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:37
@ isNotHomog
Definition structs.h:36
skStrategy * kStrategy
Definition structs.h:58
#define loop
Definition structs.h:75
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition syz3.cc: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