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#define pDivComp_EQUAL 2
135#define pDivComp_LESS 1
136#define pDivComp_GREATER -1
137#define pDivComp_INCOMP 0
138/* Checks the relation of LM(p) and LM(q)
139 LM(p) = LM(q) => return pDivComp_EQUAL
140 LM(p) | LM(q) => return pDivComp_LESS
141 LM(q) | LM(p) => return pDivComp_GREATER
142 else return pDivComp_INCOMP */
143static inline int pDivCompRing(poly p, poly q)
144{
145 if ((currRing->pCompIndex < 0)
147 {
148 BOOLEAN a=FALSE, b=FALSE;
149 int i;
150 unsigned long la, lb;
151 unsigned long divmask = currRing->divmask;
152 for (i=0; i<currRing->VarL_Size; i++)
153 {
154 la = p->exp[currRing->VarL_Offset[i]];
155 lb = q->exp[currRing->VarL_Offset[i]];
156 if (la != lb)
157 {
158 if (la < lb)
159 {
160 if (b) return pDivComp_INCOMP;
161 if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
162 return pDivComp_INCOMP;
163 a = TRUE;
164 }
165 else
166 {
167 if (a) return pDivComp_INCOMP;
168 if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
169 return pDivComp_INCOMP;
170 b = TRUE;
171 }
172 }
173 }
174 if (a) return pDivComp_LESS;
175 if (b) return pDivComp_GREATER;
176 if (!a & !b) return pDivComp_EQUAL;
177 }
178 return pDivComp_INCOMP;
179}
180
181static inline int pDivComp(poly p, poly q)
182{
183 if ((currRing->pCompIndex < 0)
185 {
186#ifdef HAVE_RATGRING
188 {
190 q,currRing,
191 currRing->real_var_start, currRing->real_var_end))
192 return 0;
193 return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
194 }
195#endif
196 BOOLEAN a=FALSE, b=FALSE;
197 int i;
198 unsigned long la, lb;
199 unsigned long divmask = currRing->divmask;
200 for (i=0; i<currRing->VarL_Size; i++)
201 {
202 la = p->exp[currRing->VarL_Offset[i]];
203 lb = q->exp[currRing->VarL_Offset[i]];
204 if (la != lb)
205 {
206 if (la < lb)
207 {
208 if (b) return 0;
209 if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
210 return 0;
211 a = TRUE;
212 }
213 else
214 {
215 if (a) return 0;
216 if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
217 return 0;
218 b = TRUE;
219 }
220 }
221 }
222 if (a) { /*assume(pLmCmp(q,p)==1);*/ return 1; }
223 if (b) { /*assume(pLmCmp(q,p)==-1);*/return -1; }
224 /*assume(pLmCmp(q,p)==0);*/
225 }
226 return 0;
227}
228
229#ifdef HAVE_SHIFTBBA
230static inline int pLPDivComp(poly p, poly q)
231{
232 if ((currRing->pCompIndex < 0) || (__p_GetComp(p,currRing) == __p_GetComp(q,currRing)))
233 {
234 // maybe there is a more performant way to do this? This will get called quite often in bba.
235 if (_p_LPLmDivisibleByNoComp(p, q, currRing)) return 1;
236 if (_p_LPLmDivisibleByNoComp(q, p, currRing)) return -1;
237 }
238
239 return 0;
240}
241#endif
242
243
246VAR int Kstd1_mu=INT_MAX;
247
248static void deleteHCBucket(LObject *L, kStrategy strat)
249{
250 if ((strat->kNoether!=NULL)
251 && (L->bucket != NULL))
252 {
253 for (int i=1; i<= (int) L->bucket->buckets_used; i++)
254 {
255 poly p=L->bucket->buckets[i];
256 if(p!=NULL)
257 {
258 if (p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
259 {
260 L->bucket->buckets[i]=NULL;
261 L->bucket->buckets_length[i]=0;
262 }
263 else
264 {
265 do
266 {
267 if (p_Cmp(pNext(p),strat->kNoetherTail(), L->tailRing) == -1)
268 {
269 p_Delete(&pNext(p), L->tailRing);
270 L->bucket->buckets_length[i]=pLength(L->bucket->buckets[i]);
271 break;
272 }
273 pIter(p);
274 } while(p!=NULL);
275 }
276 }
277 }
278 int i=L->bucket->buckets_used;
279 while ((i>0)&&(L->bucket->buckets[i]==NULL))
280 {
281 i--;
282 L->bucket->buckets_used=i;
283 }
284 }
285}
286
287/*2
288*deletes higher monomial of p, re-compute ecart and length
289*works only for orderings with ecart =pFDeg(end)-pFDeg(start)
290*/
291void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
292{
293 if (strat->kNoether!=NULL)
294 {
295 kTest_L(L,strat);
296 poly p1;
297 poly p = L->GetLmTailRing();
298 int l = 1;
299
300 if (!fromNext && p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
301 {
302 if (L->bucket != NULL) kBucketDestroy(&L->bucket);
303 L->Delete();
304 L->Clear();
305 L->ecart = -1;
306 return;
307 }
308 if (L->bucket != NULL)
309 {
310 deleteHCBucket(L,strat);
311 return;
312 }
313 BOOLEAN cut=FALSE;
314 p1 = p;
315 while (pNext(p1)!=NULL)
316 {
317 if (p_LmCmp(pNext(p1), strat->kNoetherTail(), L->tailRing) == -1)
318 {
319 cut=(pNext(p1)!=NULL);
320 if (cut)
321 {
322 p_Delete(&pNext(p1), L->tailRing);
323
324 if (p1 == p)
325 {
326 if (L->t_p != NULL)
327 {
328 assume(L->p != NULL && p == L->t_p);
329 pNext(L->p) = NULL;
330 }
331 L->max_exp = NULL;
332 }
333 else if (fromNext)
334 L->max_exp = p_GetMaxExpP(pNext(L->p), L->tailRing ); // p1;
335 //if (L->pLength != 0)
336 L->pLength = l;
337 // Hmmm when called from updateT, then only
338 // reset ecart when cut
339 if (fromNext)
340 L->ecart = L->pLDeg() - L->GetpFDeg();
341 }
342 break;
343 }
344 l++;
345 pIter(p1);
346 }
347 if ((!fromNext) && cut)
348 {
349 L->SetpFDeg();
350 L->ecart = L->pLDeg(strat->LDegLast) - L->GetpFDeg();
351 }
352 kTest_L(L,strat);
353 }
354}
355
356void deleteHC(poly* p, int* e, int* l,kStrategy strat)
357{
358 LObject L(*p, currRing, strat->tailRing);
359
360 deleteHC(&L, strat);
361 *p = L.p;
362 *e = L.ecart;
363 *l = L.length;
364 if (L.t_p != NULL) p_LmFree(L.t_p, strat->tailRing);
365}
366
367/*2
368*tests if p.p=monomial*unit and cancels the unit
369*/
371{
372 if(rHasGlobalOrdering (currRing)) return;
373 if(TEST_OPT_CANCELUNIT) return;
374
375 ring r = L->tailRing;
376 poly p = L->GetLmTailRing();
377 if(p_GetComp(p, r) != 0 && !p_OneComp(p, r)) return;
378
379 number lc=NULL; /*dummy, is always set if rField_is_Ring(r) */
380 if (rField_is_Ring(r) /*&& (rHasLocalOrMixedOrdering(r))*/)
381 lc = pGetCoeff(p);
382
383 // Leading coef have to be a unit
384 // example 2x+4x2 should be simplified to 2x*(1+2x)
385 // and 2 is not a unit in Z
386 //if ( !(n_IsUnit(pGetCoeff(p), r->cf)) ) return;
387
388 poly h = pNext(p);
389 int i;
390
392 {
393 loop
394 {
395 if (h==NULL)
396 {
397 p_Delete(&pNext(p), r);
398 if (!inNF)
399 {
400 number eins= nCopy(lc);
401 if (L->p != NULL)
402 {
403 pSetCoeff(L->p,eins);
404 if (L->t_p != NULL)
405 pSetCoeff0(L->t_p,eins);
406 }
407 else
408 pSetCoeff(L->t_p,eins);
409 /* p and t_p share the same coeff, if both are !=NULL */
410 /* p==NULL==t_p cannot happen here */
411 }
412 L->ecart = 0;
413 L->length = 1;
414 //if (L->pLength > 0)
415 L->pLength = 1;
416 L->max_exp = NULL;
417
418 if (L->t_p != NULL && pNext(L->t_p) != NULL)
419 p_Delete(&pNext(L->t_p),r);
420 if (L->p != NULL && pNext(L->p) != NULL)
421 pNext(L->p) = NULL;
422 return;
423 }
424 i = rVar(r);
425 loop
426 {
427 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
428 i--;
429 if (i == 0) break; // does divide, try next monom
430 }
431 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
432 // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
433 // domains), no zerodivisor test needed CAUTION
434 if (!n_DivBy(pGetCoeff(h),lc,r->cf))
435 {
436 return;
437 }
438 pIter(h);
439 }
440 }
441 else
442 {
443 loop
444 {
445 if (h==NULL)
446 {
447 p_Delete(&pNext(p), r);
448 if (!inNF)
449 {
450 number eins=nInit(1);
451 if (L->p != NULL)
452 {
453 pSetCoeff(L->p,eins);
454 if (L->t_p != NULL)
455 pSetCoeff0(L->t_p,eins);
456 }
457 else
458 pSetCoeff(L->t_p,eins);
459 /* p and t_p share the same coeff, if both are !=NULL */
460 /* p==NULL==t_p cannot happen here */
461 }
462 L->ecart = 0;
463 L->length = 1;
464 //if (L->pLength > 0)
465 L->pLength = 1;
466 L->max_exp = NULL;
467
468 if (L->t_p != NULL && pNext(L->t_p) != NULL)
469 p_Delete(&pNext(L->t_p),r);
470 if (L->p != NULL && pNext(L->p) != NULL)
471 pNext(L->p) = NULL;
472
473 return;
474 }
475 i = rVar(r);
476 loop
477 {
478 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
479 i--;
480 if (i == 0) break; // does divide, try next monom
481 }
482 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
483 pIter(h);
484 }
485 }
486}
487
488/*2
489*pp is the new element in s
490*returns TRUE (in strat->kAllAxis) if
491*-HEcke is allowed
492*-we are in the last componente of the vector
493*-on all axis are monomials (all elements in NotUsedAxis are FALSE)
494*returns FALSE for pLexOrderings,
495*assumes in module case an ordering of type c* !!
496* HEckeTest is only called with strat->kAllAxis==FALSE !
497*/
498void HEckeTest (poly pp,kStrategy strat)
499{
500 int j,p;
501
502 if (currRing->pLexOrder
504 || (strat->ak >1)
506 {
507 return;
508 }
510 if (p!=0)
511 strat->NotUsedAxis[p] = FALSE;
512 else return; /*nothing new*/
513 /*- the leading term of pp is a power of the p-th variable -*/
514 for (j=(currRing->N);j>0; j--)
515 {
516 if (strat->NotUsedAxis[j])
517 {
518 strat->kAllAxis=FALSE;
519 return;
520 }
521 }
522 strat->kAllAxis=TRUE;
523}
524
525/*2
526*utilities for TSet, LSet
527*/
528inline static intset initec (const int maxnr)
529{
530 return (intset)omAlloc(maxnr*sizeof(int));
531}
532
533inline static unsigned long* initsevS (const int maxnr)
534{
535 return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
536}
537inline static int* initS_2_R (const int maxnr)
538{
539 return (int*)omAlloc0(maxnr*sizeof(int));
540}
541
542static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
543 int &length, const int incr)
544{
545 assume(T!=NULL);
546 assume(sevT!=NULL);
547 assume(R!=NULL);
548 assume((length+incr) > 0);
549
550 int i;
551 T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
552 (length+incr)*sizeof(TObject));
553
554 sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
555 (length+incr)*sizeof(long*));
556
557 R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
558 (length+incr)*sizeof(TObject*));
559 for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
560 length += incr;
561}
562
563void cleanT (kStrategy strat)
564{
565 int i,j;
566 poly p;
567 assume(currRing == strat->tailRing || strat->tailRing != NULL);
568
569 pShallowCopyDeleteProc p_shallow_copy_delete =
570 (strat->tailRing != currRing ?
572 NULL);
573 for (j=0; j<=strat->tl; j++)
574 {
575 p = strat->T[j].p;
576 strat->T[j].p=NULL;
577 if (strat->T[j].max_exp != NULL)
578 {
579 p_LmFree(strat->T[j].max_exp, strat->tailRing);
580 }
581 i = -1;
582 loop
583 {
584 i++;
585 if (i>strat->sl)
586 {
587 if (strat->T[j].t_p != NULL)
588 {
589 p_Delete(&(strat->T[j].t_p), strat->tailRing);
591 }
592 else
593 {
594#ifdef HAVE_SHIFTBBA
595 if (currRing->isLPring && strat->T[j].shift > 0)
596 {
597 pNext(p) = NULL; // pNext(p) points to the unshifted tail, don't try to delete it here
598 }
599#endif
600 pDelete(&p);
601 }
602 break;
603 }
604 if (p == strat->S[i])
605 {
606 if (strat->T[j].t_p != NULL)
607 {
608 if (p_shallow_copy_delete!=NULL)
609 {
610 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
611 currRing->PolyBin);
612 }
613 p_LmFree(strat->T[j].t_p, strat->tailRing);
614 }
615 break;
616 }
617 }
618 }
619 strat->tl=-1;
620}
621
623{
624 int i,j;
625 poly p;
626 assume(currRing == strat->tailRing || strat->tailRing != NULL);
627
628 pShallowCopyDeleteProc p_shallow_copy_delete =
629 (strat->tailRing != currRing ?
631 NULL);
632 for (j=0; j<=strat->tl; j++)
633 {
634 p = strat->T[j].p;
635 strat->T[j].p=NULL;
636 if (strat->T[j].max_exp != NULL)
637 {
638 p_LmFree(strat->T[j].max_exp, strat->tailRing);
639 }
640 i = -1;
641 loop
642 {
643 i++;
644 if (i>strat->sl)
645 {
646 if (strat->T[j].t_p != NULL)
647 {
648 p_Delete(&(strat->T[j].t_p), strat->tailRing);
650 }
651 else
652 {
653 //pDelete(&p);
654 p = NULL;
655 }
656 break;
657 }
658 if (p == strat->S[i])
659 {
660 if (strat->T[j].t_p != NULL)
661 {
662 assume(p_shallow_copy_delete != NULL);
663 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
664 currRing->PolyBin);
665 p_LmFree(strat->T[j].t_p, strat->tailRing);
666 }
667 break;
668 }
669 }
670 }
671 strat->tl=-1;
672}
673
674//LSet initL ()
675//{
676// int i;
677// LSet l = (LSet)omAlloc(setmaxL*sizeof(LObject));
678// return l;
679//}
680
681static inline void enlargeL (LSet* L,int* length,const int incr)
682{
683 assume((*L)!=NULL);
684 assume(((*length)+incr)>0);
685
686 *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
687 ((*length)+incr)*sizeof(LObject));
688 (*length) += incr;
689}
690
692{
693 strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
694}
695
696/*2
697*test whether (p1,p2) or (p2,p1) is in L up position length
698*it returns TRUE if yes and the position k
699*/
700BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
701{
702 LObject *p=&(strat->L[length]);
703
704 *k = length;
705 loop
706 {
707 if ((*k) < 0) return FALSE;
708 if (((p1 == (*p).p1) && (p2 == (*p).p2))
709 || ((p1 == (*p).p2) && (p2 == (*p).p1)))
710 return TRUE;
711 (*k)--;
712 p--;
713 }
714}
715
716int kFindInT(poly p, TSet T, int tlength)
717{
718 int i;
719
720 for (i=0; i<=tlength; i++)
721 {
722 if (T[i].p == p) return i;
723 }
724 return -1;
725}
726
727int kFindInT(poly p, kStrategy strat)
728{
729 int i;
730 do
731 {
732 i = kFindInT(p, strat->T, strat->tl);
733 if (i >= 0) return i;
734 strat = strat->next;
735 }
736 while (strat != NULL);
737 return -1;
738}
739
740#ifdef HAVE_SHIFTBBA
741int kFindInTShift(poly p, TSet T, int tlength)
742{
743 int i;
744
745 for (i=0; i<=tlength; i++)
746 {
747 // in the Letterplace ring the LMs in T and L are copies thus we have to use pEqualPolys() instead of ==
748 if (pEqualPolys(T[i].p, p)) return i;
749 }
750 return -1;
751}
752#endif
753
754#ifdef HAVE_SHIFTBBA
755int kFindInTShift(poly p, kStrategy strat)
756{
757 int i;
758 do
759 {
760 i = kFindInTShift(p, strat->T, strat->tl);
761 if (i >= 0) return i;
762 strat = strat->next;
763 }
764 while (strat != NULL);
765 return -1;
766}
767#endif
768
769#ifdef KDEBUG
770
772{
773 if (t_p != NULL) p_wrp(t_p, tailRing);
774 else if (p != NULL) p_wrp(p, currRing, tailRing);
775 else ::wrp(NULL);
776}
777
778#define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
779
780// check that Lm's of a poly from T are "equal"
781static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
782{
783 int i;
784 for (i=1; i<=tailRing->N; i++)
785 {
786 if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
787 return "Lm[i] different";
788 }
789 if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
790 return "Lm[0] different";
791 if (pNext(p) != pNext(t_p))
792 return "Lm.next different";
793 if (pGetCoeff(p) != pGetCoeff(t_p))
794 return "Lm.coeff different";
795 return NULL;
796}
797
799BOOLEAN kTest_T(TObject * T, kStrategy strat, int i, char TN)
800{
801 ring tailRing = T->tailRing;
802 ring strat_tailRing = strat->tailRing;
803 if (strat_tailRing == NULL) strat_tailRing = tailRing;
804 r_assume(strat_tailRing == tailRing);
805
806 poly p = T->p;
807 // ring r = currRing;
808
809 if (T->p == NULL && T->t_p == NULL && i >= 0)
810 return dReportError("%c[%d].poly is NULL", TN, i);
811
812 if (T->p!=NULL)
813 {
814 nTest(pGetCoeff(T->p));
815 if ((T->t_p==NULL)&&(pNext(T->p)!=NULL)) p_Test(pNext(T->p),currRing);
816 }
817 if (T->t_p!=NULL)
818 {
819 nTest(pGetCoeff(T->t_p));
820 if (pNext(T->t_p)!=NULL) p_Test(pNext(T->t_p),strat_tailRing);
821 }
822 if ((T->p!=NULL)&&(T->t_p!=NULL)) assume(pGetCoeff(T->p)==pGetCoeff(T->t_p));
823
824 if (T->tailRing != currRing)
825 {
826 if (T->t_p == NULL && i > 0)
827 return dReportError("%c[%d].t_p is NULL", TN, i);
828 pFalseReturn(p_Test(T->t_p, T->tailRing));
829 if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
830 if ((T->p != NULL) && (T->t_p != NULL))
831 {
832 const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
833 if (msg != NULL)
834 return dReportError("%c[%d] %s", TN, i, msg);
835 // r = T->tailRing;
836 p = T->t_p;
837 }
838 if (T->p == NULL)
839 {
840 p = T->t_p;
841 // r = T->tailRing;
842 }
843 if (T->t_p != NULL && i >= 0 && TN == 'T')
844 {
845 if (pNext(T->t_p) == NULL)
846 {
847 if (T->max_exp != NULL)
848 return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
849 }
850 else
851 {
852 if (T->max_exp == NULL)
853 return dReportError("%c[%d].max_exp is NULL", TN, i);
854 if (pNext(T->max_exp) != NULL)
855 return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
856
857 pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
858 omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
859#if KDEBUG > 0
860 if (! sloppy_max)
861 {
862 poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
863 p_Setm(T->max_exp, tailRing);
864 p_Setm(test_max, tailRing);
865 BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
866 if (! equal)
867 return dReportError("%c[%d].max out of sync", TN, i);
868 p_LmFree(test_max, tailRing);
869 }
870#endif
871 }
872 }
873 }
874 else
875 {
876 if (T->p == NULL && i > 0)
877 return dReportError("%c[%d].p is NULL", TN, i);
878#ifdef HAVE_SHIFTBBA
879 if (currRing->isLPring && T->shift > 0)
880 {
881 // in this case, the order is not correct. test LM and tail separately
884 }
885 else
886#endif
887 {
889 }
890 }
891
892 if ((i >= 0) && (T->pLength != 0)
893 && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
894 {
895 int l=T->pLength;
896 T->pLength=pLength(p);
897 return dReportError("%c[%d] pLength error: has %d, specified to have %d",
898 TN, i , pLength(p), l);
899 }
900
901 // check FDeg, for elements in L and T
902 if (i >= 0 && (TN == 'T' || TN == 'L'))
903 {
904 // FDeg has ir element from T of L set
905 if (strat->homog && (T->FDeg != T->pFDeg()))
906 {
907 int d=T->FDeg;
908 T->FDeg=T->pFDeg();
909 return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
910 TN, i , T->pFDeg(), d);
911 }
912 }
913
914 // check is_normalized for elements in T
915 if (i >= 0 && TN == 'T')
916 {
917 if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
918 return dReportError("T[%d] is_normalized error", i);
919
920 }
921 return TRUE;
922}
923
925 BOOLEAN testp, int lpos, TSet T, int tlength)
926{
927 ring strat_tailRing=strat->tailRing;
928 if (L->p!=NULL)
929 {
930 if ((L->t_p==NULL)
931 &&(pNext(L->p)!=NULL)
932 &&(pGetCoeff(pNext(L->p))!=NULL)) /* !=strat->tail*/
933 {
934 p_Test(pNext(L->p),currRing);
935 nTest(pGetCoeff(L->p));
936 }
937 }
938 if (L->t_p!=NULL)
939 {
940 if ((pNext(L->t_p)!=NULL)
941 &&(pGetCoeff(pNext(L->t_p))!=NULL)) /* !=strat->tail*/
942 {
943 p_Test(pNext(L->t_p),strat_tailRing);
944 nTest(pGetCoeff(L->t_p));
945 }
946 }
947 if ((L->p!=NULL)&&(L->t_p!=NULL)) assume(pGetCoeff(L->p)==pGetCoeff(L->t_p));
948
949 if (testp)
950 {
951 poly pn = NULL;
952 if (L->bucket != NULL)
953 {
954 kFalseReturn(kbTest(L->bucket));
955 r_assume(L->bucket->bucket_ring == L->tailRing);
956 if (L->p != NULL && pNext(L->p) != NULL)
957 {
958 pn = pNext(L->p);
959 pNext(L->p) = NULL;
960 }
961 }
962 kFalseReturn(kTest_T(L, strat, lpos, 'L'));
963 if (pn != NULL)
964 pNext(L->p) = pn;
965
966 ring r;
967 poly p;
968 L->GetLm(p, r);
969 if (L->sev != 0L)
970 {
971 if (p_GetShortExpVector(p, r) != L->sev)
972 {
973 return dReportError("L[%d] wrong sev: has %lo, specified to have %lo",
974 lpos, p_GetShortExpVector(p, r), L->sev);
975 }
976 }
977 }
978 if (L->p1 == NULL)
979 {
980 // L->p2 either NULL or "normal" poly
981 pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
982 }
983 else if (tlength > 0 && T != NULL && (lpos >=0))
984 {
985 // now p1 and p2 must be != NULL and must be contained in T
986 int i;
987#ifdef HAVE_SHIFTBBA
988 if (rIsLPRing(currRing))
989 i = kFindInTShift(L->p1, T, tlength);
990 else
991#endif
992 i = kFindInT(L->p1, T, tlength);
993 if (i < 0)
994 return dReportError("L[%d].p1 not in T",lpos);
995#ifdef HAVE_SHIFTBBA
996 if (rIsLPRing(currRing))
997 {
998 if (rField_is_Ring(currRing)) return TRUE; // m*shift(q) is not in T
999 i = kFindInTShift(L->p2, T, tlength);
1000 }
1001 else
1002#endif
1003 i = kFindInT(L->p2, T, tlength);
1004 if (i < 0)
1005 return dReportError("L[%d].p2 not in T",lpos);
1006 }
1007 return TRUE;
1008}
1009
1011{
1012 int i;
1013 // test P
1014 kFalseReturn(kTest_L(&(strat->P), strat,
1015 (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
1016 -1, strat->T, strat->tl));
1017
1018 // test T
1019 if (strat->T != NULL)
1020 {
1021 for (i=0; i<=strat->tl; i++)
1022 {
1023 kFalseReturn(kTest_T(&(strat->T[i]), strat, i, 'T'));
1024 if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
1025 return dReportError("strat->sevT[%d] out of sync", i);
1026 }
1027 }
1028
1029 // test L
1030 if (strat->L != NULL)
1031 {
1032 for (i=0; i<=strat->Ll; i++)
1033 {
1034 kFalseReturn(kTest_L(&(strat->L[i]), strat,
1035 strat->L[i].Next() != strat->tail, i,
1036 strat->T, strat->tl));
1037 // may be unused
1038 //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
1039 // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
1040 //{
1041 // assume(strat->L[i].bucket != NULL);
1042 //}
1043 }
1044 }
1045
1046 // test S
1047 if (strat->S != NULL)
1048 kFalseReturn(kTest_S(strat));
1049
1050 return TRUE;
1051}
1052
1054{
1055 int i;
1056 BOOLEAN ret = TRUE;
1057 for (i=0; i<=strat->sl; i++)
1058 {
1059 if (strat->S[i] != NULL &&
1060 strat->sevS[i] != pGetShortExpVector(strat->S[i]))
1061 {
1062 return dReportError("S[%d] wrong sev: has %o, specified to have %o",
1063 i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
1064 }
1065 }
1066 return ret;
1067}
1068
1069
1070
1072{
1073 int i, j;
1074 // BOOLEAN ret = TRUE;
1075 kFalseReturn(kTest(strat));
1076
1077 // test strat->R, strat->T[i].i_r
1078 for (i=0; i<=strat->tl; i++)
1079 {
1080 if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1081 return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1082 strat->T[i].i_r);
1083 if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1084 return dReportError("T[%d].i_r with R out of sync", i);
1085 }
1086 // test containment of S inT
1087 if ((strat->S != NULL)&&(strat->tl>=0))
1088 {
1089 for (i=0; i<=strat->sl; i++)
1090 {
1091 j = kFindInT(strat->S[i], strat->T, strat->tl);
1092 if (j < 0)
1093 return dReportError("S[%d] not in T", i);
1094 if (strat->S_2_R[i] != strat->T[j].i_r)
1095 return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1096 i, strat->S_2_R[i], j, strat->T[j].i_r);
1097 }
1098 }
1099 // test strat->L[i].i_r1
1100 #ifdef HAVE_SHIFTBBA
1101 if (!rIsLPRing(currRing)) // in the Letterplace ring we currently don't set/use i_r1 and i_r2
1102 #endif
1103 if (strat->L!=NULL)
1104 {
1105 for (i=0; i<=strat->Ll; i++)
1106 {
1107 if (strat->L[i].p1 != NULL && strat->L[i].p2)
1108 {
1109 if (strat->L[i].i_r1 < 0 ||
1110 strat->L[i].i_r1 > strat->tl ||
1111 strat->L[i].T_1(strat)->p != strat->L[i].p1)
1112 return dReportError("L[%d].i_r1 out of sync", i);
1113 if (strat->L[i].i_r2 < 0 ||
1114 strat->L[i].i_r2 > strat->tl ||
1115 strat->L[i].T_2(strat)->p != strat->L[i].p2)
1116 return dReportError("L[%d].i_r2 out of sync", i);
1117 }
1118 else
1119 {
1120 if (strat->L[i].i_r1 != -1)
1121 return dReportError("L[%d].i_r1 out of sync", i);
1122 if (strat->L[i].i_r2 != -1)
1123 return dReportError("L[%d].i_r2 out of sync", i);
1124 }
1125 if (strat->L[i].i_r != -1)
1126 return dReportError("L[%d].i_r out of sync", i);
1127 }
1128 }
1129 return TRUE;
1130}
1131
1132#endif // KDEBUG
1133
1134/*2
1135*cancels the i-th polynomial in the standardbase s
1136*/
1137void deleteInS (int i,kStrategy strat)
1138{
1139#ifdef ENTER_USE_MEMMOVE
1140 memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1141 memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1142 memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1143 memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1144#else
1145 int j;
1146 for (j=i; j<strat->sl; j++)
1147 {
1148 strat->S[j] = strat->S[j+1];
1149 strat->ecartS[j] = strat->ecartS[j+1];
1150 strat->sevS[j] = strat->sevS[j+1];
1151 strat->S_2_R[j] = strat->S_2_R[j+1];
1152 }
1153#endif
1154 if (strat->lenS!=NULL)
1155 {
1156#ifdef ENTER_USE_MEMMOVE
1157 memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1158#else
1159 for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1160#endif
1161 }
1162 if (strat->lenSw!=NULL)
1163 {
1164#ifdef ENTER_USE_MEMMOVE
1165 memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1166#else
1167 for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1168#endif
1169 }
1170 if (strat->fromQ!=NULL)
1171 {
1172#ifdef ENTER_USE_MEMMOVE
1173 memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1174#else
1175 for (j=i; j<strat->sl; j++)
1176 {
1177 strat->fromQ[j] = strat->fromQ[j+1];
1178 }
1179#endif
1180 }
1181 strat->S[strat->sl] = NULL;
1182 strat->sl--;
1183}
1184
1185#ifdef HAVE_SHIFTBBA
1186static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
1187{
1188 if (rIsLPRing(currRing)
1189 && (strat->P.p1!=NULL))
1190 {
1191 // clean up strat->P.p1: may be shifted
1192 poly p=strat->P.p1;
1193 int lv=currRing->isLPring;
1194 BOOLEAN is_shifted=TRUE;
1195 for (int i=lv;i>0;i--)
1196 {
1197 if (pGetExp(p,i)!=0) { is_shifted=FALSE; break;}
1198 }
1199 if (is_shifted
1200 && (kFindInL1(p, strat)<0)
1201 && (kFindInT(p, strat->T, strat->tl) < 0)
1202 )
1203 {
1204 return TRUE;
1205 }
1206 }
1207 return FALSE;
1208}
1209#endif
1210/*2
1211*cancels the j-th polynomial in the set
1212*/
1213void deleteInL (LSet set, int *length, int j,kStrategy strat)
1214{
1215 if (set[j].lcm!=NULL)
1216 {
1217 kDeleteLcm(&set[j]);
1218 }
1219 if (set[j].sig!=NULL)
1220 {
1221 if (pGetCoeff(set[j].sig) != NULL)
1222 pLmDelete(set[j].sig);
1223 else
1224 pLmFree(set[j].sig);
1225 }
1226 if (set[j].p!=NULL)
1227 {
1228 if (pNext(set[j].p) == strat->tail)
1229 {
1230 if (pGetCoeff(set[j].p) != NULL)
1231 pLmDelete(set[j].p);
1232 else
1233 pLmFree(set[j].p);
1234 /*- tail belongs to several int spolys -*/
1235 }
1236 else
1237 {
1238 // search p in T, if it is there, do not delete it
1239 if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1240 {
1241 // assure that for global orderings kFindInT fails
1242 //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1243 set[j].Delete();
1244 }
1245 }
1246 }
1247 #ifdef HAVE_SHIFTBBA
1248 if (is_shifted_p1(strat->P.p1,strat))
1249 {
1250 // clean up strat->P.p1: may be shifted
1251 pLmDelete(strat->P.p1);
1252 strat->P.p1=NULL;
1253 }
1254 #endif
1255 if (*length > 0 && j < *length)
1256 {
1257#ifdef ENTER_USE_MEMMOVE
1258 memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1259#else
1260 int i;
1261 for (i=j; i < (*length); i++)
1262 set[i] = set[i+1];
1263#endif
1264 }
1265#ifdef KDEBUG
1266 set[*length].Init();
1267#endif
1268 (*length)--;
1269}
1270
1271/*2
1272*enters p at position at in L
1273*/
1274void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1275{
1276 // this should be corrected
1277 assume(p.FDeg == p.pFDeg());
1278
1279 if ((*length)>=0)
1280 {
1281 if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1282 if (at <= (*length))
1283#ifdef ENTER_USE_MEMMOVE
1284 memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1285#else
1286 for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1287#endif
1288 }
1289 else at = 0;
1290 (*set)[at] = p;
1291 (*length)++;
1292}
1293
1294/*2
1295* computes the normal ecart;
1296* used in mora case and if pLexOrder & sugar in bba case
1297*/
1299{
1300 h->FDeg = h->pFDeg();
1301 h->ecart = h->pLDeg() - h->FDeg;
1302 // h->length is set by h->pLDeg
1303 h->length=h->pLength=pLength(h->p);
1304}
1305
1307{
1308 h->FDeg = h->pFDeg();
1309 (*h).ecart = 0;
1310 h->length=h->pLength=pLength(h->p);
1311}
1312
1313void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1314{
1315 Lp->FDeg = Lp->pFDeg();
1316 (*Lp).ecart = 0;
1317 (*Lp).length = 0;
1318}
1319
1320void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1321{
1322 Lp->FDeg = Lp->pFDeg();
1323 (*Lp).ecart = si_max(ecartF,ecartG);
1324 (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1325 (*Lp).length = 0;
1326}
1327
1328/*2
1329*if ecart1<=ecart2 it returns TRUE
1330*/
1331static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1332{
1333 return (ecart1 <= ecart2);
1334}
1335
1336/*2
1337* put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1338*/
1339static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1340{
1341 assume(atR >= 0);
1342 assume(i<=strat->sl);
1343 assume(p!=NULL);
1345 #if ALL_VS_JUST
1346 //Over rings, if we construct the strong pair, do not add the spair
1348 {
1349 number s,t,d;
1350 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1351
1352 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1353 {
1354 nDelete(&d);
1355 nDelete(&s);
1356 nDelete(&t);
1357 return;
1358 }
1359 nDelete(&d);
1360 nDelete(&s);
1361 nDelete(&t);
1362 }
1363 #endif
1364 int j,compare,compareCoeff;
1365 LObject h;
1366
1367#ifdef KDEBUG
1368 h.ecart=0; h.length=0;
1369#endif
1370 /*- computes the lcm(s[i],p) -*/
1371 if(pHasNotCFRing(p,strat->S[i]))
1372 {
1373 strat->cp++;
1374 return;
1375 }
1376 h.lcm = p_Lcm(p,strat->S[i],currRing);
1377 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1378 if (nIsZero(pGetCoeff(h.lcm)))
1379 {
1380 strat->cp++;
1381 pLmDelete(h.lcm);
1382 return;
1383 }
1384 // basic chain criterion
1385 /*
1386 *the set B collects the pairs of type (S[j],p)
1387 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1388 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
1389 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
1390 */
1391
1392 for(j = strat->Bl;j>=0;j--)
1393 {
1394 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1395 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1396 if(compare == pDivComp_EQUAL)
1397 {
1398 //They have the same LM
1399 if(compareCoeff == pDivComp_LESS)
1400 {
1401 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1402 {
1403 strat->c3++;
1404 pLmDelete(h.lcm);
1405 return;
1406 }
1407 break;
1408 }
1409 if(compareCoeff == pDivComp_GREATER)
1410 {
1411 deleteInL(strat->B,&strat->Bl,j,strat);
1412 strat->c3++;
1413 }
1414 if(compareCoeff == pDivComp_EQUAL)
1415 {
1416 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1417 {
1418 strat->c3++;
1419 pLmDelete(h.lcm);
1420 return;
1421 }
1422 break;
1423 }
1424 }
1425 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1426 {
1427 if(compare == pDivComp_LESS)
1428 {
1429 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1430 {
1431 strat->c3++;
1432 pLmDelete(h.lcm);
1433 return;
1434 }
1435 break;
1436 }
1437 if(compare == pDivComp_GREATER)
1438 {
1439 deleteInL(strat->B,&strat->Bl,j,strat);
1440 strat->c3++;
1441 }
1442 }
1443 }
1444 number s, t;
1445 poly m1, m2, gcd = NULL;
1446 s = pGetCoeff(strat->S[i]);
1447 t = pGetCoeff(p);
1448 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1449 ksCheckCoeff(&s, &t, currRing->cf);
1450 pSetCoeff0(m1, s);
1451 pSetCoeff0(m2, t);
1452 m2 = pNeg(m2);
1453 p_Test(m1,strat->tailRing);
1454 p_Test(m2,strat->tailRing);
1455 poly si = pCopy(strat->S[i]);
1456 poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1457 poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1458 pDelete(&si);
1459 p_LmDelete(m1, currRing);
1460 p_LmDelete(m2, currRing);
1461 if(sim2 == NULL)
1462 {
1463 if(pm1 == NULL)
1464 {
1465 if(h.lcm != NULL)
1466 {
1467 pLmDelete(h.lcm);
1468 h.lcm=NULL;
1469 }
1470 h.Clear();
1471 if (strat->pairtest==NULL) initPairtest(strat);
1472 strat->pairtest[i] = TRUE;
1473 strat->pairtest[strat->sl+1] = TRUE;
1474 return;
1475 }
1476 else
1477 {
1478 gcd = pm1;
1479 pm1 = NULL;
1480 }
1481 }
1482 else
1483 {
1484 if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1485 {
1486 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1487 pSetmComp(sim2);
1488 }
1489 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1490 gcd = p_Add_q(pm1, sim2, strat->tailRing);
1491 }
1492 p_Test(gcd, strat->tailRing);
1493#ifdef KDEBUG
1494 if (TEST_OPT_DEBUG)
1495 {
1496 wrp(gcd);
1497 PrintLn();
1498 }
1499#endif
1500 h.p = gcd;
1501 h.i_r = -1;
1502 if(h.p == NULL)
1503 {
1504 if (strat->pairtest==NULL) initPairtest(strat);
1505 strat->pairtest[i] = TRUE;
1506 strat->pairtest[strat->sl+1] = TRUE;
1507 return;
1508 }
1509 h.tailRing = strat->tailRing;
1510 int posx;
1511 //h.pCleardenom();
1512 //pSetm(h.p);
1513 h.i_r1 = -1;h.i_r2 = -1;
1514 strat->initEcart(&h);
1515 #if 1
1516 h.p2 = strat->S[i];
1517 h.p1 = p;
1518 #endif
1519 #if 1
1520 if (atR >= 0)
1521 {
1522 h.i_r1 = atR;
1523 h.i_r2 = strat->S_2_R[i];
1524 }
1525 #endif
1526 if (strat->Bl==-1)
1527 posx =0;
1528 else
1529 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1530 h.sev = pGetShortExpVector(h.p);
1531 if (currRing!=strat->tailRing)
1532 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1533 if (strat->P.p!=NULL) strat->P.sev = pGetShortExpVector(strat->P.p);
1534 else strat->P.sev=0L;
1535 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1536 kTest_TS(strat);
1537}
1538
1539/*2
1540* put the lcm(s[i],p) into the set B
1541*/
1542
1543static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1544{
1545 number d, s, t;
1546 assume(atR >= 0);
1548 poly m1, m2, gcd,si;
1549 if(!enterTstrong)
1550 {
1551 assume(i<=strat->sl);
1552 si = strat->S[i];
1553 }
1554 else
1555 {
1556 assume(i<=strat->tl);
1557 si = strat->T[i].p;
1558 }
1559 //printf("\n--------------------------------\n");
1560 //pWrite(p);pWrite(si);
1561 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1562
1563 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1564 {
1565 nDelete(&d);
1566 nDelete(&s);
1567 nDelete(&t);
1568 return FALSE;
1569 }
1570
1571 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1572
1574 {
1575 unsigned long sev = pGetShortExpVector(gcd);
1576
1577 for (int j = 0; j < strat->sl; j++)
1578 {
1579 if (j == i)
1580 continue;
1581
1582 if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf)
1583 && !(strat->sevS[j] & ~sev)
1584 && p_LmDivisibleBy(strat->S[j], gcd, currRing))
1585 {
1586 nDelete(&d);
1587 nDelete(&s);
1588 nDelete(&t);
1589 return FALSE;
1590 }
1591 }
1592 }
1593
1594 //p_Test(m1,strat->tailRing);
1595 //p_Test(m2,strat->tailRing);
1596 /*if(!enterTstrong)
1597 {
1598 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1599 {
1600 memset(&(strat->P), 0, sizeof(strat->P));
1601 kStratChangeTailRing(strat);
1602 strat->P = *(strat->R[atR]);
1603 p_LmFree(m1, strat->tailRing);
1604 p_LmFree(m2, strat->tailRing);
1605 p_LmFree(gcd, currRing);
1606 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1607 }
1608 }*/
1609 pSetCoeff0(m1, s);
1610 pSetCoeff0(m2, t);
1611 pSetCoeff0(gcd, d);
1612 p_Test(m1,strat->tailRing);
1613 p_Test(m2,strat->tailRing);
1614 //printf("\n===================================\n");
1615 //pWrite(m1);pWrite(m2);pWrite(gcd);
1616#ifdef KDEBUG
1617 if (TEST_OPT_DEBUG)
1618 {
1619 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1620 PrintS("m1 = ");
1621 p_wrp(m1, strat->tailRing);
1622 PrintS(" ; m2 = ");
1623 p_wrp(m2, strat->tailRing);
1624 PrintS(" ; gcd = ");
1625 wrp(gcd);
1626 PrintS("\n--- create strong gcd poly: ");
1627 Print("\n p: %d", i);
1628 wrp(p);
1629 Print("\n strat->S[%d]: ", i);
1630 wrp(si);
1631 PrintS(" ---> ");
1632 }
1633#endif
1634
1635 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1636 p_LmDelete(m1, strat->tailRing);
1637 p_LmDelete(m2, strat->tailRing);
1638#ifdef KDEBUG
1639 if (TEST_OPT_DEBUG)
1640 {
1641 wrp(gcd);
1642 PrintLn();
1643 }
1644#endif
1645
1646 LObject h;
1647 h.p = gcd;
1648 h.tailRing = strat->tailRing;
1649 int posx;
1650 strat->initEcart(&h);
1651 h.sev = pGetShortExpVector(h.p);
1652 h.i_r1 = -1;h.i_r2 = -1;
1653 if (currRing!=strat->tailRing)
1654 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1655 if(!enterTstrong)
1656 {
1657 #if 1
1658 h.p1 = p;h.p2 = strat->S[i];
1659 #endif
1660 if (atR >= 0)
1661 {
1662 h.i_r2 = strat->S_2_R[i];
1663 h.i_r1 = atR;
1664 }
1665 else
1666 {
1667 h.i_r1 = -1;
1668 h.i_r2 = -1;
1669 }
1670 if (strat->Ll==-1)
1671 posx =0;
1672 else
1673 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1674 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1675 }
1676 else
1677 {
1678 if(h.IsNull()) return FALSE;
1679 //int red_result;
1680 //reduzieren ist teur!!!
1681 //if(strat->L != NULL)
1682 //red_result = strat->red(&h,strat);
1683 if(!h.IsNull())
1684 {
1685 enterT(h, strat,-1);
1686 //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1687 //strat->enterS(h,pos,strat,-1);
1688 }
1689 }
1690 return TRUE;
1691}
1692
1694{
1695 if(strat->sl < 0) return FALSE;
1696 int i;
1697 for(i=0;i<strat->sl;i++)
1698 {
1699 //Construct the gcd pair between h and S[i]
1700 number d, s, t;
1701 poly m1, m2, gcd;
1702 d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1703 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1704 {
1705 nDelete(&d);
1706 nDelete(&s);
1707 nDelete(&t);
1708 }
1709 else
1710 {
1711 k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1712 pSetCoeff0(m1, s);
1713 pSetCoeff0(m2, t);
1714 pSetCoeff0(gcd, d);
1715 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);
1716 poly pSigMult = p_Copy(h->sig,currRing);
1717 poly sSigMult = p_Copy(strat->sig[i],currRing);
1718 pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1719 sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1720 p_LmDelete(m1, strat->tailRing);
1721 p_LmDelete(m2, strat->tailRing);
1722 poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1723 if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1724 {
1725 pDelete(&h->p);
1726 h->p = gcd;
1727 pDelete(&h->sig);
1728 h->sig = pairsig;
1729 pNext(h->sig) = NULL;
1730 strat->initEcart(h);
1731 h->sev = pGetShortExpVector(h->p);
1732 h->sevSig = pGetShortExpVector(h->sig);
1733 h->i_r1 = -1;h->i_r2 = -1;
1734 if(h->lcm != NULL)
1735 {
1736 pLmDelete(h->lcm);
1737 h->lcm = NULL;
1738 }
1739 if (currRing!=strat->tailRing)
1740 h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1741 return TRUE;
1742 }
1743 //Delete what you didn't use
1744 pDelete(&gcd);
1745 pDelete(&pairsig);
1746 }
1747 }
1748 return FALSE;
1749}
1750
1751static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1752{
1753 number d, s, t;
1754 assume(atR >= 0);
1755 poly m1, m2, gcd,si;
1756 assume(i<=strat->sl);
1757 si = strat->S[i];
1758 //printf("\n--------------------------------\n");
1759 //pWrite(p);pWrite(si);
1760 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1761
1762 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1763 {
1764 nDelete(&d);
1765 nDelete(&s);
1766 nDelete(&t);
1767 return FALSE;
1768 }
1769
1770 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1771 //p_Test(m1,strat->tailRing);
1772 //p_Test(m2,strat->tailRing);
1773 /*if(!enterTstrong)
1774 {
1775 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1776 {
1777 memset(&(strat->P), 0, sizeof(strat->P));
1778 kStratChangeTailRing(strat);
1779 strat->P = *(strat->R[atR]);
1780 p_LmFree(m1, strat->tailRing);
1781 p_LmFree(m2, strat->tailRing);
1782 p_LmFree(gcd, currRing);
1783 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1784 }
1785 }*/
1786 pSetCoeff0(m1, s);
1787 pSetCoeff0(m2, t);
1788 pSetCoeff0(gcd, d);
1789 p_Test(m1,strat->tailRing);
1790 p_Test(m2,strat->tailRing);
1791 //printf("\n===================================\n");
1792 //pWrite(m1);pWrite(m2);pWrite(gcd);
1793#ifdef KDEBUG
1794 if (TEST_OPT_DEBUG)
1795 {
1796 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1797 PrintS("m1 = ");
1798 p_wrp(m1, strat->tailRing);
1799 PrintS(" ; m2 = ");
1800 p_wrp(m2, strat->tailRing);
1801 PrintS(" ; gcd = ");
1802 wrp(gcd);
1803 PrintS("\n--- create strong gcd poly: ");
1804 Print("\n p: %d", i);
1805 wrp(p);
1806 Print("\n strat->S[%d]: ", i);
1807 wrp(si);
1808 PrintS(" ---> ");
1809 }
1810#endif
1811
1812 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1813
1814#ifdef KDEBUG
1815 if (TEST_OPT_DEBUG)
1816 {
1817 wrp(gcd);
1818 PrintLn();
1819 }
1820#endif
1821
1822 //Check and set the signatures
1823 poly pSigMult = p_Copy(sig,currRing);
1824 poly sSigMult = p_Copy(strat->sig[i],currRing);
1825 pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1826 sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1827 p_LmDelete(m1, strat->tailRing);
1828 p_LmDelete(m2, strat->tailRing);
1829 poly pairsig;
1830 if(pLmCmp(pSigMult,sSigMult) == 0)
1831 {
1832 //Same lm, have to add them
1833 pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1834 //This might be zero
1835 }
1836 else
1837 {
1838 //Set the sig to either pSigMult or sSigMult
1839 if(pLtCmp(pSigMult,sSigMult)==1)
1840 {
1841 pairsig = pSigMult;
1842 pDelete(&sSigMult);
1843 }
1844 else
1845 {
1846 pairsig = sSigMult;
1847 pDelete(&pSigMult);
1848 }
1849 }
1850
1851 LObject h;
1852 h.p = gcd;
1853 h.tailRing = strat->tailRing;
1854 h.sig = pairsig;
1855 int posx;
1856 strat->initEcart(&h);
1857 h.sev = pGetShortExpVector(h.p);
1858 h.i_r1 = -1;h.i_r2 = -1;
1859 if (currRing!=strat->tailRing)
1860 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1861 if(h.sig == NULL)
1862 {
1863 //sigdrop since we loose the signature
1864 strat->sigdrop = TRUE;
1865 //Try to reduce it as far as we can via redRing
1866 int red_result = redRing(&h,strat);
1867 if(red_result == 0)
1868 {
1869 // Cancel the sigdrop
1870 p_Delete(&h.sig,currRing);h.sig = NULL;
1871 strat->sigdrop = FALSE;
1872 return FALSE;
1873 }
1874 else
1875 {
1876 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1877 #if 1
1878 strat->enterS(h,0,strat,strat->tl);
1879 #endif
1880 return FALSE;
1881 }
1882 }
1883 if(!nGreaterZero(pGetCoeff(h.sig)))
1884 {
1885 h.sig = pNeg(h.sig);
1886 h.p = pNeg(h.p);
1887 }
1888
1889 if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1890 {
1891 strat->sigdrop = TRUE;
1892 // Completely reduce it
1893 int red_result = redRing(&h,strat);
1894 if(red_result == 0)
1895 {
1896 // Reduced to 0
1897 strat->sigdrop = FALSE;
1898 p_Delete(&h.sig,currRing);h.sig = NULL;
1899 return FALSE;
1900 }
1901 else
1902 {
1903 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1904 // 0 - add just the original poly causing the sigdrop, 1 - add also this
1905 #if 1
1906 strat->enterS(h,0,strat, strat->tl+1);
1907 #endif
1908 return FALSE;
1909 }
1910 }
1911 //Check for sigdrop
1912 if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1913 {
1914 strat->sigdrop = TRUE;
1915 //Enter this element to S
1916 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1917 strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1918 }
1919 #if 1
1920 h.p1 = p;h.p2 = strat->S[i];
1921 #endif
1922 if (atR >= 0)
1923 {
1924 h.i_r2 = strat->S_2_R[i];
1925 h.i_r1 = atR;
1926 }
1927 else
1928 {
1929 h.i_r1 = -1;
1930 h.i_r2 = -1;
1931 }
1932 if (strat->Ll==-1)
1933 posx =0;
1934 else
1935 posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1936 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1937 return TRUE;
1938}
1939
1940/*2
1941* put the pair (s[i],p) into the set B, ecart=ecart(p)
1942*/
1943
1944void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1945{
1946 assume(i<=strat->sl);
1947
1948 int l,j,compare;
1949 LObject Lp;
1950 Lp.i_r = -1;
1951
1952#ifdef KDEBUG
1953 Lp.ecart=0; Lp.length=0;
1954#endif
1955 /*- computes the lcm(s[i],p) -*/
1956 Lp.lcm = pInit();
1957
1958#ifndef HAVE_RATGRING
1959 pLcm(p,strat->S[i],Lp.lcm);
1960#elif defined(HAVE_RATGRING)
1961 if (rIsRatGRing(currRing))
1962 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1963 else
1964 pLcm(p,strat->S[i],Lp.lcm);
1965#endif
1966 pSetm(Lp.lcm);
1967
1968
1969 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
1970 {
1971 if (strat->fromT && (strat->ecartS[i]>ecart))
1972 {
1973 pLmFree(Lp.lcm);
1974 return;
1975 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
1976 }
1977 if((!((strat->ecartS[i]>0)&&(ecart>0)))
1978 && pHasNotCF(p,strat->S[i]))
1979 {
1980 /*
1981 *the product criterion has applied for (s,p),
1982 *i.e. lcm(s,p)=product of the leading terms of s and p.
1983 *Suppose (s,r) is in L and the leading term
1984 *of p divides lcm(s,r)
1985 *(==> the leading term of p divides the leading term of r)
1986 *but the leading term of s does not divide the leading term of r
1987 *(notice that tis condition is automatically satisfied if r is still
1988 *in S), then (s,r) can be cancelled.
1989 *This should be done here because the
1990 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1991 *
1992 *Moreover, skipping (s,r) holds also for the noncommutative case.
1993 */
1994 strat->cp++;
1995 pLmFree(Lp.lcm);
1996 return;
1997 }
1998 Lp.ecart = si_max(ecart,strat->ecartS[i]);
1999 /*
2000 *the set B collects the pairs of type (S[j],p)
2001 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2002 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2003 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2004 */
2005 {
2006 j = strat->Bl;
2007 loop
2008 {
2009 if (j < 0) break;
2010 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2011 if ((compare==1)
2012 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2013 {
2014 strat->c3++;
2015 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2016 {
2017 pLmFree(Lp.lcm);
2018 return;
2019 }
2020 break;
2021 }
2022 else
2023 if ((compare ==-1)
2024 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2025 {
2026 deleteInL(strat->B,&strat->Bl,j,strat);
2027 strat->c3++;
2028 }
2029 j--;
2030 }
2031 }
2032 }
2033 else /*sugarcrit*/
2034 {
2035 if (ALLOW_PROD_CRIT(strat))
2036 {
2037 if (strat->fromT && (strat->ecartS[i]>ecart))
2038 {
2039 pLmFree(Lp.lcm);
2040 return;
2041 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2042 }
2043 // if currRing->nc_type!=quasi (or skew)
2044 // TODO: enable productCrit for super commutative algebras...
2045 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2046 pHasNotCF(p,strat->S[i]))
2047 {
2048 /*
2049 *the product criterion has applied for (s,p),
2050 *i.e. lcm(s,p)=product of the leading terms of s and p.
2051 *Suppose (s,r) is in L and the leading term
2052 *of p divides lcm(s,r)
2053 *(==> the leading term of p divides the leading term of r)
2054 *but the leading term of s does not divide the leading term of r
2055 *(notice that tis condition is automatically satisfied if r is still
2056 *in S), then (s,r) can be canceled.
2057 *This should be done here because the
2058 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2059 */
2060 strat->cp++;
2061 pLmFree(Lp.lcm);
2062 return;
2063 }
2064 /*
2065 *the set B collects the pairs of type (S[j],p)
2066 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2067 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2068 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2069 */
2070 for(j = strat->Bl;j>=0;j--)
2071 {
2072 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2073 if (compare==1)
2074 {
2075 strat->c3++;
2076 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2077 {
2078 pLmFree(Lp.lcm);
2079 return;
2080 }
2081 break;
2082 }
2083 else
2084 if (compare ==-1)
2085 {
2086 deleteInL(strat->B,&strat->Bl,j,strat);
2087 strat->c3++;
2088 }
2089 }
2090 }
2091 }
2092 /*
2093 *the pair (S[i],p) enters B if the spoly != 0
2094 */
2095 /*- compute the short s-polynomial -*/
2096 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2097 pNorm(p);
2098
2099 if ((strat->S[i]==NULL) || (p==NULL))
2100 return;
2101
2102 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2103 Lp.p=NULL;
2104 else
2105 {
2106 #ifdef HAVE_PLURAL
2107 if ( rIsPluralRing(currRing) )
2108 {
2109 if(pHasNotCF(p, strat->S[i]))
2110 {
2111 if(ncRingType(currRing) == nc_lie)
2112 {
2113 // generalized prod-crit for lie-type
2114 strat->cp++;
2115 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2116 }
2117 else
2118 if( ALLOW_PROD_CRIT(strat) )
2119 {
2120 // product criterion for homogeneous case in SCA
2121 strat->cp++;
2122 Lp.p = NULL;
2123 }
2124 else
2125 {
2126 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2127 nc_CreateShortSpoly(strat->S[i], p, currRing);
2128 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2129 pNext(Lp.p) = strat->tail; // !!!
2130 }
2131 }
2132 else
2133 {
2134 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2135 nc_CreateShortSpoly(strat->S[i], p, currRing);
2136
2137 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2138 pNext(Lp.p) = strat->tail; // !!!
2139 }
2140 }
2141 else
2142 #endif
2143 {
2145 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2146 }
2147 }
2148 if (Lp.p == NULL)
2149 {
2150 /*- the case that the s-poly is 0 -*/
2151 if (strat->pairtest==NULL) initPairtest(strat);
2152 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2153 strat->pairtest[strat->sl+1] = TRUE;
2154 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2155 /*
2156 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2157 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2158 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2159 *term of p divides the lcm(s,r)
2160 *(this canceling should be done here because
2161 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2162 *the first case is handled in chainCrit
2163 */
2164 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2165 }
2166 else
2167 {
2168 /*- the pair (S[i],p) enters B -*/
2169 Lp.p1 = strat->S[i];
2170 Lp.p2 = p;
2171
2172 if (
2174// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2175 )
2176 {
2177 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2178 pNext(Lp.p) = strat->tail; // !!!
2179 }
2180
2181 if (atR >= 0)
2182 {
2183 Lp.i_r1 = strat->S_2_R[i];
2184 Lp.i_r2 = atR;
2185 }
2186 else
2187 {
2188 Lp.i_r1 = -1;
2189 Lp.i_r2 = -1;
2190 }
2191 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2192
2194 {
2197 && (Lp.p->coef!=NULL))
2198 nDelete(&(Lp.p->coef));
2199 }
2200
2201 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2202 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2203 }
2204}
2205
2206/// p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
2207static inline BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2208{
2209 int i = rVar(r);
2210 loop
2211 {
2212 if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2213 return FALSE;
2214 i--;
2215 if (i == 0)
2216 return TRUE;
2217 }
2218}
2219
2220/*2
2221* put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2222* (in the special case: idLift for ideals, i.e. strat->syzComp==1)
2223* (prod.crit applies)
2224*/
2225
2226static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2227{
2228 assume(ALLOW_PROD_CRIT(strat));
2230 assume(i<=strat->sl);
2231 assume(strat->syzComp==1);
2232
2233 if ((strat->S[i]==NULL) || (p==NULL))
2234 return;
2235
2236 int l,j,compare;
2237 LObject Lp;
2238 Lp.i_r = -1;
2239
2240#ifdef KDEBUG
2241 Lp.ecart=0; Lp.length=0;
2242#endif
2243 /*- computes the lcm(s[i],p) -*/
2244 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2245
2246 if (strat->sugarCrit)
2247 {
2248 if((!((strat->ecartS[i]>0)&&(ecart>0)))
2249 && p_HasNotCF_Lift(p,strat->S[i],currRing))
2250 {
2251 /*
2252 *the product criterion has applied for (s,p),
2253 *i.e. lcm(s,p)=product of the leading terms of s and p.
2254 *Suppose (s,r) is in L and the leading term
2255 *of p divides lcm(s,r)
2256 *(==> the leading term of p divides the leading term of r)
2257 *but the leading term of s does not divide the leading term of r
2258 *(notice that tis condition is automatically satisfied if r is still
2259 *in S), then (s,r) can be cancelled.
2260 *This should be done here because the
2261 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2262 *
2263 *Moreover, skipping (s,r) holds also for the noncommutative case.
2264 */
2265 strat->cp++;
2266 pLmFree(Lp.lcm);
2267 return;
2268 }
2269 else
2270 Lp.ecart = si_max(ecart,strat->ecartS[i]);
2271 if (strat->fromT && (strat->ecartS[i]>ecart))
2272 {
2273 pLmFree(Lp.lcm);
2274 return;
2275 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2276 }
2277 /*
2278 *the set B collects the pairs of type (S[j],p)
2279 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2280 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2281 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2282 */
2283 {
2284 j = strat->Bl;
2285 loop
2286 {
2287 if (j < 0) break;
2288 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2289 if ((compare==1)
2290 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2291 {
2292 strat->c3++;
2293 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2294 {
2295 pLmFree(Lp.lcm);
2296 return;
2297 }
2298 break;
2299 }
2300 else
2301 if ((compare ==-1)
2302 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2303 {
2304 deleteInL(strat->B,&strat->Bl,j,strat);
2305 strat->c3++;
2306 }
2307 j--;
2308 }
2309 }
2310 }
2311 else /*sugarcrit*/
2312 {
2313 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2314 p_HasNotCF_Lift(p,strat->S[i],currRing))
2315 {
2316 /*
2317 *the product criterion has applied for (s,p),
2318 *i.e. lcm(s,p)=product of the leading terms of s and p.
2319 *Suppose (s,r) is in L and the leading term
2320 *of p divides lcm(s,r)
2321 *(==> the leading term of p divides the leading term of r)
2322 *but the leading term of s does not divide the leading term of r
2323 *(notice that tis condition is automatically satisfied if r is still
2324 *in S), then (s,r) can be canceled.
2325 *This should be done here because the
2326 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2327 */
2328 strat->cp++;
2329 pLmFree(Lp.lcm);
2330 return;
2331 }
2332 if (strat->fromT && (strat->ecartS[i]>ecart))
2333 {
2334 pLmFree(Lp.lcm);
2335 return;
2336 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2337 }
2338 /*
2339 *the set B collects the pairs of type (S[j],p)
2340 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2341 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2342 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2343 */
2344 for(j = strat->Bl;j>=0;j--)
2345 {
2346 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2347 if (compare==1)
2348 {
2349 strat->c3++;
2350 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2351 {
2352 pLmFree(Lp.lcm);
2353 return;
2354 }
2355 break;
2356 }
2357 else
2358 if (compare ==-1)
2359 {
2360 deleteInL(strat->B,&strat->Bl,j,strat);
2361 strat->c3++;
2362 }
2363 }
2364 }
2365 /*
2366 *the pair (S[i],p) enters B if the spoly != 0
2367 */
2368 /*- compute the short s-polynomial -*/
2369 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2370 pNorm(p);
2371
2372 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2373 Lp.p=NULL;
2374 else
2375 {
2377 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2378 }
2379 if (Lp.p == NULL)
2380 {
2381 /*- the case that the s-poly is 0 -*/
2382 if (strat->pairtest==NULL) initPairtest(strat);
2383 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2384 strat->pairtest[strat->sl+1] = TRUE;
2385 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2386 /*
2387 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2388 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2389 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2390 *term of p divides the lcm(s,r)
2391 *(this canceling should be done here because
2392 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2393 *the first case is handled in chainCrit
2394 */
2395 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2396 }
2397 else
2398 {
2399 /*- the pair (S[i],p) enters B -*/
2400 Lp.p1 = strat->S[i];
2401 Lp.p2 = p;
2402
2403 pNext(Lp.p) = strat->tail; // !!!
2404
2405 if (atR >= 0)
2406 {
2407 Lp.i_r1 = strat->S_2_R[i];
2408 Lp.i_r2 = atR;
2409 }
2410 else
2411 {
2412 Lp.i_r1 = -1;
2413 Lp.i_r2 = -1;
2414 }
2415 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2416
2418 {
2421 && (Lp.p->coef!=NULL))
2422 nDelete(&(Lp.p->coef));
2423 }
2424
2425 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2426 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2427 }
2428}
2429
2430/*2
2431* put the pair (s[i],p) into the set B, ecart=ecart(p)
2432* NOTE: here we need to add the signature-based criteria
2433*/
2434
2435#ifdef DEBUGF5
2436static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2437#else
2438static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2439#endif
2440{
2441 assume(i<=strat->sl);
2442
2443 int l;
2444 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2445 // the corresponding signatures for criteria checks
2446 LObject Lp;
2447 poly pSigMult = p_Copy(pSig,currRing);
2448 poly sSigMult = p_Copy(strat->sig[i],currRing);
2449 unsigned long pSigMultNegSev,sSigMultNegSev;
2450 Lp.i_r = -1;
2451
2452#ifdef KDEBUG
2453 Lp.ecart=0; Lp.length=0;
2454#endif
2455 /*- computes the lcm(s[i],p) -*/
2456 Lp.lcm = pInit();
2457 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2458#ifndef HAVE_RATGRING
2459 pLcm(p,strat->S[i],Lp.lcm);
2460#elif defined(HAVE_RATGRING)
2461 if (rIsRatGRing(currRing))
2462 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2463 else
2464 pLcm(p,strat->S[i],Lp.lcm);
2465#endif
2466 pSetm(Lp.lcm);
2467
2468 // set coeffs of multipliers m1 and m2
2469 pSetCoeff0(m1, nInit(1));
2470 pSetCoeff0(m2, nInit(1));
2471//#if 1
2472#ifdef DEBUGF5
2473 PrintS("P1 ");
2474 pWrite(pHead(p));
2475 PrintS("P2 ");
2476 pWrite(pHead(strat->S[i]));
2477 PrintS("M1 ");
2478 pWrite(m1);
2479 PrintS("M2 ");
2480 pWrite(m2);
2481#endif
2482 // get multiplied signatures for testing
2483 pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2484 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2485 sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2486 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2487
2488//#if 1
2489#ifdef DEBUGF5
2490 PrintS("----------------\n");
2491 pWrite(pSigMult);
2492 pWrite(sSigMult);
2493 PrintS("----------------\n");
2494 Lp.checked = 0;
2495#endif
2496 int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2497//#if 1
2498#if DEBUGF5
2499 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2500 pWrite(pSigMult);
2501 pWrite(sSigMult);
2502#endif
2503 if(sigCmp==0)
2504 {
2505 // printf("!!!! EQUAL SIGS !!!!\n");
2506 // pSig = sSig, delete element due to Rewritten Criterion
2507 pDelete(&pSigMult);
2508 pDelete(&sSigMult);
2510 pLmDelete(Lp.lcm);
2511 else
2512 pLmFree(Lp.lcm);
2513 pDelete (&m1);
2514 pDelete (&m2);
2515 return;
2516 }
2517 // testing by syzCrit = F5 Criterion
2518 // testing by rewCrit1 = Rewritten Criterion
2519 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2520 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2521 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2522 || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2523 )
2524 {
2525 pDelete(&pSigMult);
2526 pDelete(&sSigMult);
2528 pLmDelete(Lp.lcm);
2529 else
2530 pLmFree(Lp.lcm);
2531 pDelete (&m1);
2532 pDelete (&m2);
2533 return;
2534 }
2535 /*
2536 *the pair (S[i],p) enters B if the spoly != 0
2537 */
2538 /*- compute the short s-polynomial -*/
2539 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2540 pNorm(p);
2541
2542 if ((strat->S[i]==NULL) || (p==NULL))
2543 return;
2544
2545 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2546 Lp.p=NULL;
2547 else
2548 {
2549 #ifdef HAVE_PLURAL
2550 if ( rIsPluralRing(currRing) )
2551 {
2552 if(pHasNotCF(p, strat->S[i]))
2553 {
2554 if(ncRingType(currRing) == nc_lie)
2555 {
2556 // generalized prod-crit for lie-type
2557 strat->cp++;
2558 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2559 }
2560 else
2561 if( ALLOW_PROD_CRIT(strat) )
2562 {
2563 // product criterion for homogeneous case in SCA
2564 strat->cp++;
2565 Lp.p = NULL;
2566 }
2567 else
2568 {
2569 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2570 nc_CreateShortSpoly(strat->S[i], p, currRing);
2571
2572 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2573 pNext(Lp.p) = strat->tail; // !!!
2574 }
2575 }
2576 else
2577 {
2578 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2579 nc_CreateShortSpoly(strat->S[i], p, currRing);
2580
2581 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2582 pNext(Lp.p) = strat->tail; // !!!
2583 }
2584 }
2585 else
2586 #endif
2587 {
2589 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2590 }
2591 }
2592 // store from which element this pair comes from for further tests
2593 //Lp.from = strat->sl+1;
2594 if(sigCmp==currRing->OrdSgn)
2595 {
2596 // pSig > sSig
2597 pDelete (&sSigMult);
2598 Lp.sig = pSigMult;
2599 Lp.sevSig = ~pSigMultNegSev;
2600 }
2601 else
2602 {
2603 // pSig < sSig
2604 pDelete (&pSigMult);
2605 Lp.sig = sSigMult;
2606 Lp.sevSig = ~sSigMultNegSev;
2607 }
2608 if (Lp.p == NULL)
2609 {
2610 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2611 int pos = posInSyz(strat, Lp.sig);
2612 enterSyz(Lp, strat, pos);
2613 }
2614 else
2615 {
2616 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2617 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2618 {
2619 pLmFree(Lp.lcm);
2620 pDelete(&Lp.sig);
2621 pDelete (&m1);
2622 pDelete (&m2);
2623 return;
2624 }
2625 // in any case Lp is checked up to the next strat->P which is added
2626 // to S right after this critical pair creation.
2627 // NOTE: this even holds if the 2nd generator gives the bigger signature
2628 // moreover, this improves rewCriterion,
2629 // i.e. strat->checked > strat->from if and only if the 2nd generator
2630 // gives the bigger signature.
2631 Lp.checked = strat->sl+1;
2632 // at this point it is clear that the pair will be added to L, since it has
2633 // passed all tests up to now
2634
2635 // adds buchberger's first criterion
2636 if (pLmCmp(m2,pHead(p)) == 0)
2637 {
2638 Lp.prod_crit = TRUE; // Product Criterion
2639#if 0
2640 int pos = posInSyz(strat, Lp.sig);
2641 enterSyz(Lp, strat, pos);
2642 pDelete (&m1);
2643 pDelete (&m2);
2644 return;
2645#endif
2646 }
2647 pDelete (&m1);
2648 pDelete (&m2);
2649#if DEBUGF5
2650 PrintS("SIGNATURE OF PAIR: ");
2651 pWrite(Lp.sig);
2652#endif
2653 /*- the pair (S[i],p) enters B -*/
2654 Lp.p1 = strat->S[i];
2655 Lp.p2 = p;
2656
2657 if (
2659// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2660 )
2661 {
2662 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2663 pNext(Lp.p) = strat->tail; // !!!
2664 }
2665
2666 if (atR >= 0)
2667 {
2668 Lp.i_r1 = strat->S_2_R[i];
2669 Lp.i_r2 = atR;
2670 }
2671 else
2672 {
2673 Lp.i_r1 = -1;
2674 Lp.i_r2 = -1;
2675 }
2676 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2677
2679 {
2682 && (Lp.p->coef!=NULL))
2683 nDelete(&(Lp.p->coef));
2684 }
2685
2686 l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2687 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2688 }
2689}
2690
2691
2692#ifdef DEBUGF5
2693static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2694#else
2695static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2696#endif
2697{
2698 #if ALL_VS_JUST
2699 //Over rings, if we construct the strong pair, do not add the spair
2701 {
2702 number s,t,d;
2703 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2704
2705 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2706 {
2707 nDelete(&d);
2708 nDelete(&s);
2709 nDelete(&t);
2710 return;
2711 }
2712 nDelete(&d);
2713 nDelete(&s);
2714 nDelete(&t);
2715 }
2716 #endif
2717 assume(i<=strat->sl);
2718 int l;
2719 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2720 // the corresponding signatures for criteria checks
2721 LObject Lp;
2722 poly pSigMult = p_Copy(pSig,currRing);
2723 poly sSigMult = p_Copy(strat->sig[i],currRing);
2724 unsigned long pSigMultNegSev,sSigMultNegSev;
2725 Lp.i_r = -1;
2726
2727#ifdef KDEBUG
2728 Lp.ecart=0; Lp.length=0;
2729#endif
2730 /*- computes the lcm(s[i],p) -*/
2731 Lp.lcm = pInit();
2732 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2733#ifndef HAVE_RATGRING
2734 pLcm(p,strat->S[i],Lp.lcm);
2735#elif defined(HAVE_RATGRING)
2736 if (rIsRatGRing(currRing))
2737 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2738 else
2739 pLcm(p,strat->S[i],Lp.lcm);
2740#endif
2741 pSetm(Lp.lcm);
2742
2743 // set coeffs of multipliers m1 and m2
2745 {
2746 number s = nCopy(pGetCoeff(strat->S[i]));
2747 number t = nCopy(pGetCoeff(p));
2748 pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2749 ksCheckCoeff(&s, &t, currRing->cf);
2750 pSetCoeff0(m1,s);
2751 pSetCoeff0(m2,t);
2752 }
2753 else
2754 {
2755 pSetCoeff0(m1, nInit(1));
2756 pSetCoeff0(m2, nInit(1));
2757 }
2758#ifdef DEBUGF5
2759 Print("P1 ");
2760 pWrite(pHead(p));
2761 Print("P2 ");
2762 pWrite(pHead(strat->S[i]));
2763 Print("M1 ");
2764 pWrite(m1);
2765 Print("M2 ");
2766 pWrite(m2);
2767#endif
2768
2769 // get multiplied signatures for testing
2770 pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2771 if(pSigMult != NULL)
2772 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2773 sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2774 if(sSigMult != NULL)
2775 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2776//#if 1
2777#ifdef DEBUGF5
2778 Print("----------------\n");
2779 pWrite(pSigMult);
2780 pWrite(sSigMult);
2781 Print("----------------\n");
2782 Lp.checked = 0;
2783#endif
2784 int sigCmp;
2785 if(pSigMult != NULL && sSigMult != NULL)
2786 {
2788 sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2789 else
2790 sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2791 }
2792 else
2793 {
2794 if(pSigMult == NULL)
2795 {
2796 if(sSigMult == NULL)
2797 sigCmp = 0;
2798 else
2799 sigCmp = -1;
2800 }
2801 else
2802 sigCmp = 1;
2803 }
2804//#if 1
2805#if DEBUGF5
2806 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2807 pWrite(pSigMult);
2808 pWrite(sSigMult);
2809#endif
2810 //In the ring case we already build the sig
2812 {
2813 if(sigCmp == 0)
2814 {
2815 //sigdrop since we loose the signature
2816 strat->sigdrop = TRUE;
2817 //Try to reduce it as far as we can via redRing
2819 {
2820 poly p1 = p_Copy(p,currRing);
2821 poly p2 = p_Copy(strat->S[i],currRing);
2822 p1 = p_Mult_mm(p1,m1,currRing);
2823 p2 = p_Mult_mm(p2,m2,currRing);
2824 Lp.p = p_Sub(p1,p2,currRing);
2825 if(Lp.p != NULL)
2826 Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2827 }
2828 int red_result = redRing(&Lp,strat);
2829 if(red_result == 0)
2830 {
2831 // Cancel the sigdrop
2832 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2833 strat->sigdrop = FALSE;
2834 return;
2835 }
2836 else
2837 {
2838 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2839 #if 1
2840 strat->enterS(Lp,0,strat,strat->tl);
2841 #endif
2842 return;
2843 }
2844 }
2845 if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2846 {
2847 //Same lm, have to subtract
2848 Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2849 }
2850 else
2851 {
2852 if(sigCmp == 1)
2853 {
2854 Lp.sig = pCopy(pSigMult);
2855 }
2856 if(sigCmp == -1)
2857 {
2858 Lp.sig = pNeg(pCopy(sSigMult));
2859 }
2860 }
2861 Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2862 }
2863
2864 #if 0
2865 if(sigCmp==0)
2866 {
2867 // printf("!!!! EQUAL SIGS !!!!\n");
2868 // pSig = sSig, delete element due to Rewritten Criterion
2869 pDelete(&pSigMult);
2870 pDelete(&sSigMult);
2872 pLmDelete(Lp.lcm);
2873 else
2874 pLmFree(Lp.lcm);
2875 pDelete (&m1);
2876 pDelete (&m2);
2877 return;
2878 }
2879 #endif
2880 // testing by syzCrit = F5 Criterion
2881 // testing by rewCrit1 = Rewritten Criterion
2882 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2883 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2884 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2885 // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2886 //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2887 )
2888 {
2889 pDelete(&pSigMult);
2890 pDelete(&sSigMult);
2892 pLmDelete(Lp.lcm);
2893 else
2894 pLmFree(Lp.lcm);
2895 pDelete (&m1);
2896 pDelete (&m2);
2897 return;
2898 }
2899 /*
2900 *the pair (S[i],p) enters B if the spoly != 0
2901 */
2902 /*- compute the short s-polynomial -*/
2903 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2904 pNorm(p);
2905
2906 if ((strat->S[i]==NULL) || (p==NULL))
2907 return;
2908
2909 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2910 Lp.p=NULL;
2911 else
2912 {
2913 //Build p
2915 {
2916 poly p1 = p_Copy(p,currRing);
2917 poly p2 = p_Copy(strat->S[i],currRing);
2918 p1 = p_Mult_mm(p1,m1,currRing);
2919 p2 = p_Mult_mm(p2,m2,currRing);
2920 Lp.p = p_Sub(p1,p2,currRing);
2921 if(Lp.p != NULL)
2922 Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2923 }
2924 else
2925 {
2926 #ifdef HAVE_PLURAL
2927 if ( rIsPluralRing(currRing) )
2928 {
2929 if(ncRingType(currRing) == nc_lie)
2930 {
2931 // generalized prod-crit for lie-type
2932 strat->cp++;
2933 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2934 }
2935 else
2936 if( ALLOW_PROD_CRIT(strat) )
2937 {
2938 // product criterion for homogeneous case in SCA
2939 strat->cp++;
2940 Lp.p = NULL;
2941 }
2942 else
2943 {
2944 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2945 nc_CreateShortSpoly(strat->S[i], p, currRing);
2946
2947 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2948 pNext(Lp.p) = strat->tail; // !!!
2949 }
2950 }
2951 else
2952 #endif
2953 {
2955 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2956 }
2957 }
2958 }
2959 // store from which element this pair comes from for further tests
2960 //Lp.from = strat->sl+1;
2962 {
2963 //Put the sig to be > 0
2964 if(!nGreaterZero(pGetCoeff(Lp.sig)))
2965 {
2966 Lp.sig = pNeg(Lp.sig);
2967 Lp.p = pNeg(Lp.p);
2968 }
2969 }
2970 else
2971 {
2972 if(sigCmp==currRing->OrdSgn)
2973 {
2974 // pSig > sSig
2975 pDelete (&sSigMult);
2976 Lp.sig = pSigMult;
2977 Lp.sevSig = ~pSigMultNegSev;
2978 }
2979 else
2980 {
2981 // pSig < sSig
2982 pDelete (&pSigMult);
2983 Lp.sig = sSigMult;
2984 Lp.sevSig = ~sSigMultNegSev;
2985 }
2986 }
2987 if (Lp.p == NULL)
2988 {
2989 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2990 int pos = posInSyz(strat, Lp.sig);
2991 enterSyz(Lp, strat, pos);
2992 }
2993 else
2994 {
2995 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2996 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2997 {
2998 pLmFree(Lp.lcm);
2999 pDelete(&Lp.sig);
3000 pDelete (&m1);
3001 pDelete (&m2);
3002 return;
3003 }
3004 // in any case Lp is checked up to the next strat->P which is added
3005 // to S right after this critical pair creation.
3006 // NOTE: this even holds if the 2nd generator gives the bigger signature
3007 // moreover, this improves rewCriterion,
3008 // i.e. strat->checked > strat->from if and only if the 2nd generator
3009 // gives the bigger signature.
3010 Lp.checked = strat->sl+1;
3011 // at this point it is clear that the pair will be added to L, since it has
3012 // passed all tests up to now
3013
3014 // adds buchberger's first criterion
3015 if (pLmCmp(m2,pHead(p)) == 0)
3016 {
3017 Lp.prod_crit = TRUE; // Product Criterion
3018#if 0
3019 int pos = posInSyz(strat, Lp.sig);
3020 enterSyz(Lp, strat, pos);
3021 pDelete (&m1);
3022 pDelete (&m2);
3023 return;
3024#endif
3025 }
3026 pDelete (&m1);
3027 pDelete (&m2);
3028#if DEBUGF5
3029 PrintS("SIGNATURE OF PAIR: ");
3030 pWrite(Lp.sig);
3031#endif
3032 /*- the pair (S[i],p) enters B -*/
3033 Lp.p1 = strat->S[i];
3034 Lp.p2 = p;
3035
3036 if (
3038// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3040 )
3041 {
3042 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3043 pNext(Lp.p) = strat->tail; // !!!
3044 }
3045
3046 if (atR >= 0)
3047 {
3048 Lp.i_r1 = strat->S_2_R[i];
3049 Lp.i_r2 = atR;
3050 }
3051 else
3052 {
3053 Lp.i_r1 = -1;
3054 Lp.i_r2 = -1;
3055 }
3056 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3057
3059 {
3062 && (Lp.p->coef!=NULL))
3063 nDelete(&(Lp.p->coef));
3064 }
3065 // Check for sigdrop
3066 if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3067 {
3068 strat->sigdrop = TRUE;
3069 // Completely reduce it
3070 int red_result = redRing(&Lp,strat);
3071 if(red_result == 0)
3072 {
3073 // Reduced to 0
3074 strat->sigdrop = FALSE;
3075 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3076 return;
3077 }
3078 else
3079 {
3080 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3081 // 0 - add just the original poly causing the sigdrop, 1 - add also this
3082 #if 1
3083 strat->enterS(Lp,0,strat, strat->tl+1);
3084 #endif
3085 return;
3086 }
3087 }
3088 l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3089 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3090 }
3091}
3092
3093/*2
3094* put the pair (s[i],p) into the set L, ecart=ecart(p)
3095* in the case that s forms a SB of (s)
3096*/
3097void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3098{
3099 //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3100 if(pHasNotCF(p,strat->S[i]))
3101 {
3102 //PrintS("prod-crit\n");
3103 if(ALLOW_PROD_CRIT(strat))
3104 {
3105 //PrintS("prod-crit\n");
3106 strat->cp++;
3107 return;
3108 }
3109 }
3110
3111 int l;
3112 LObject Lp;
3113 Lp.i_r = -1;
3114
3115 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3116 /*- compute the short s-polynomial -*/
3117
3118 #ifdef HAVE_PLURAL
3120 {
3121 Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3122 }
3123 else
3124 #endif
3125 Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3126
3127 if (Lp.p == NULL)
3128 {
3129 //PrintS("short spoly==NULL\n");
3130 pLmFree(Lp.lcm);
3131 }
3132 else
3133 {
3134 /*- the pair (S[i],p) enters L -*/
3135 Lp.p1 = strat->S[i];
3136 Lp.p2 = p;
3137 if (atR >= 0)
3138 {
3139 Lp.i_r1 = strat->S_2_R[i];
3140 Lp.i_r2 = atR;
3141 }
3142 else
3143 {
3144 Lp.i_r1 = -1;
3145 Lp.i_r2 = -1;
3146 }
3147 assume(pNext(Lp.p) == NULL);
3148 pNext(Lp.p) = strat->tail;
3149 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3151 {
3154 && (Lp.p->coef!=NULL))
3155 nDelete(&(Lp.p->coef));
3156 }
3157 l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3158 //Print("-> L[%d]\n",l);
3159 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3160 }
3161}
3162
3163/*2
3164* merge set B into L
3165*/
3167{
3168 int j=strat->Ll+strat->Bl+1;
3169 if (j>strat->Lmax)
3170 {
3171 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3172 enlargeL(&(strat->L),&(strat->Lmax),j);
3173 }
3174 j = strat->Ll;
3175 int i;
3176 for (i=strat->Bl; i>=0; i--)
3177 {
3178 j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3179 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3180 }
3181 strat->Bl = -1;
3182}
3183
3184/*2
3185* merge set B into L
3186*/
3188{
3189 int j=strat->Ll+strat->Bl+1;
3190 if (j>strat->Lmax)
3191 {
3192 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3193 enlargeL(&(strat->L),&(strat->Lmax),j);
3194 }
3195 j = strat->Ll;
3196 int i;
3197 for (i=strat->Bl; i>=0; i--)
3198 {
3199 j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3200 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3201 }
3202 strat->Bl = -1;
3203}
3204
3205/*2
3206*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3207*using the chain-criterion in B and L and enters B to L
3208*/
3209void chainCritNormal (poly p,int ecart,kStrategy strat)
3210{
3211 int i,j,l;
3212
3213 /*
3214 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3215 *In this case all elements in B such
3216 *that their lcm is divisible by the leading term of S[i] can be canceled
3217 */
3218 if (strat->pairtest!=NULL)
3219 {
3220#ifdef HAVE_SHIFTBBA
3221 // only difference is pLPDivisibleBy instead of pDivisibleBy
3222 if (rIsLPRing(currRing))
3223 {
3224 for (j=0; j<=strat->sl; j++)
3225 {
3226 if (strat->pairtest[j])
3227 {
3228 for (i=strat->Bl; i>=0; i--)
3229 {
3230 if (pLPDivisibleBy(strat->S[j],strat->B[i].lcm))
3231 {
3232 deleteInL(strat->B,&strat->Bl,i,strat);
3233 strat->c3++;
3234 }
3235 }
3236 }
3237 }
3238 }
3239 else
3240#endif
3241 {
3242 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3243 for (j=0; j<=strat->sl; j++)
3244 {
3245 if (strat->pairtest[j])
3246 {
3247 for (i=strat->Bl; i>=0; i--)
3248 {
3249 if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3250 {
3251 deleteInL(strat->B,&strat->Bl,i,strat);
3252 strat->c3++;
3253 }
3254 }
3255 }
3256 }
3257 }
3258 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3259 strat->pairtest=NULL;
3260 }
3261 if (strat->Gebauer || strat->fromT)
3262 {
3263 if (strat->sugarCrit)
3264 {
3265 /*
3266 *suppose L[j] == (s,r) and p/lcm(s,r)
3267 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3268 *and in case the sugar is o.k. then L[j] can be canceled
3269 */
3270 for (j=strat->Ll; j>=0; j--)
3271 {
3272 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3273 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3274 && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3275 {
3276 if (strat->L[j].p == strat->tail)
3277 {
3278 deleteInL(strat->L,&strat->Ll,j,strat);
3279 strat->c3++;
3280 }
3281 }
3282 }
3283 /*
3284 *this is GEBAUER-MOELLER:
3285 *in B all elements with the same lcm except the "best"
3286 *(i.e. the last one in B with this property) will be canceled
3287 */
3288 j = strat->Bl;
3289 loop /*cannot be changed into a for !!! */
3290 {
3291 if (j <= 0) break;
3292 i = j-1;
3293 loop
3294 {
3295 if (i < 0) break;
3296 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3297 {
3298 strat->c3++;
3299 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3300 {
3301 deleteInL(strat->B,&strat->Bl,i,strat);
3302 j--;
3303 }
3304 else
3305 {
3306 deleteInL(strat->B,&strat->Bl,j,strat);
3307 break;
3308 }
3309 }
3310 i--;
3311 }
3312 j--;
3313 }
3314 }
3315 else /*sugarCrit*/
3316 {
3317 /*
3318 *suppose L[j] == (s,r) and p/lcm(s,r)
3319 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3320 *and in case the sugar is o.k. then L[j] can be canceled
3321 */
3322 for (j=strat->Ll; j>=0; j--)
3323 {
3324 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3325 {
3326 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3327 {
3328 deleteInL(strat->L,&strat->Ll,j,strat);
3329 strat->c3++;
3330 }
3331 }
3332 }
3333 /*
3334 *this is GEBAUER-MOELLER:
3335 *in B all elements with the same lcm except the "best"
3336 *(i.e. the last one in B with this property) will be canceled
3337 */
3338 j = strat->Bl;
3339 loop /*cannot be changed into a for !!! */
3340 {
3341 if (j <= 0) break;
3342 for(i=j-1; i>=0; i--)
3343 {
3344 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3345 {
3346 strat->c3++;
3347 deleteInL(strat->B,&strat->Bl,i,strat);
3348 j--;
3349 }
3350 }
3351 j--;
3352 }
3353 }
3354 /*
3355 *the elements of B enter L
3356 */
3357 kMergeBintoL(strat);
3358 }
3359 else
3360 {
3361 for (j=strat->Ll; j>=0; j--)
3362 {
3363 #ifdef HAVE_SHIFTBBA
3364 if ((strat->L[j].p1!=NULL) &&
3365 pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3366 #else
3367 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3368 #endif
3369 {
3370 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3371 {
3372 deleteInL(strat->L,&strat->Ll,j,strat);
3373 strat->c3++;
3374 }
3375 }
3376 }
3377 /*
3378 *this is our MODIFICATION of GEBAUER-MOELLER:
3379 *First the elements of B enter L,
3380 *then we fix a lcm and the "best" element in L
3381 *(i.e the last in L with this lcm and of type (s,p))
3382 *and cancel all the other elements of type (r,p) with this lcm
3383 *except the case the element (s,r) has also the same lcm
3384 *and is on the worst position with respect to (s,p) and (r,p)
3385 */
3386 /*
3387 *B enters to L/their order with respect to B is permutated for elements
3388 *B[i].p with the same leading term
3389 */
3390 kMergeBintoL(strat);
3391 j = strat->Ll;
3392 loop /*cannot be changed into a for !!! */
3393 {
3394 if (j <= 0)
3395 {
3396 /*now L[0] cannot be canceled any more and the tail can be removed*/
3397 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3398 break;
3399 }
3400 if (strat->L[j].p2 == p)
3401 {
3402 i = j-1;
3403 loop
3404 {
3405 if (i < 0) break;
3406 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3407 {
3408 /*L[i] could be canceled but we search for a better one to cancel*/
3409 strat->c3++;
3410 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3411 && (pNext(strat->L[l].p) == strat->tail)
3412 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3413 && pDivisibleBy(p,strat->L[l].lcm))
3414 {
3415 /*
3416 *"NOT equal(...)" because in case of "equal" the element L[l]
3417 *is "older" and has to be from theoretical point of view behind
3418 *L[i], but we do not want to reorder L
3419 */
3420 strat->L[i].p2 = strat->tail;
3421 /*
3422 *L[l] will be canceled, we cannot cancel L[i] later on,
3423 *so we mark it with "tail"
3424 */
3425 deleteInL(strat->L,&strat->Ll,l,strat);
3426 i--;
3427 }
3428 else
3429 {
3430 deleteInL(strat->L,&strat->Ll,i,strat);
3431 }
3432 j--;
3433 }
3434 i--;
3435 }
3436 }
3437 else if (strat->L[j].p2 == strat->tail)
3438 {
3439 /*now L[j] cannot be canceled any more and the tail can be removed*/
3440 strat->L[j].p2 = p;
3441 }
3442 j--;
3443 }
3444 }
3445}
3446/*2
3447*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3448*without the chain-criterion in B and L and enters B to L
3449*/
3450void chainCritOpt_1 (poly,int,kStrategy strat)
3451{
3452 if (strat->pairtest!=NULL)
3453 {
3454 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3455 strat->pairtest=NULL;
3456 }
3457 /*
3458 *the elements of B enter L
3459 */
3460 kMergeBintoL(strat);
3461}
3462/*2
3463*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3464*using the chain-criterion in B and L and enters B to L
3465*/
3466void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3467{
3468 int i,j,l;
3469 kMergeBintoLSba(strat);
3470 j = strat->Ll;
3471 loop /*cannot be changed into a for !!! */
3472 {
3473 if (j <= 0)
3474 {
3475 /*now L[0] cannot be canceled any more and the tail can be removed*/
3476 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3477 break;
3478 }
3479 if (strat->L[j].p2 == p)
3480 {
3481 i = j-1;
3482 loop
3483 {
3484 if (i < 0) break;
3485 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3486 {
3487 /*L[i] could be canceled but we search for a better one to cancel*/
3488 strat->c3++;
3489 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3490 && (pNext(strat->L[l].p) == strat->tail)
3491 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3492 && pDivisibleBy(p,strat->L[l].lcm))
3493 {
3494 /*
3495 *"NOT equal(...)" because in case of "equal" the element L[l]
3496 *is "older" and has to be from theoretical point of view behind
3497 *L[i], but we do not want to reorder L
3498 */
3499 strat->L[i].p2 = strat->tail;
3500 /*
3501 *L[l] will be canceled, we cannot cancel L[i] later on,
3502 *so we mark it with "tail"
3503 */
3504 deleteInL(strat->L,&strat->Ll,l,strat);
3505 i--;
3506 }
3507 else
3508 {
3509 deleteInL(strat->L,&strat->Ll,i,strat);
3510 }
3511 j--;
3512 }
3513 i--;
3514 }
3515 }
3516 else if (strat->L[j].p2 == strat->tail)
3517 {
3518 /*now L[j] cannot be canceled any more and the tail can be removed*/
3519 strat->L[j].p2 = p;
3520 }
3521 j--;
3522 }
3523}
3524#ifdef HAVE_RATGRING
3525void chainCritPart (poly p,int ecart,kStrategy strat)
3526{
3527 int i,j,l;
3528
3529 /*
3530 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3531 *In this case all elements in B such
3532 *that their lcm is divisible by the leading term of S[i] can be canceled
3533 */
3534 if (strat->pairtest!=NULL)
3535 {
3536 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3537 for (j=0; j<=strat->sl; j++)
3538 {
3539 if (strat->pairtest[j])
3540 {
3541 for (i=strat->Bl; i>=0; i--)
3542 {
3543 if (_p_LmDivisibleByPart(strat->S[j],currRing,
3544 strat->B[i].lcm,currRing,
3545 currRing->real_var_start,currRing->real_var_end))
3546 {
3547 if(TEST_OPT_DEBUG)
3548 {
3549 Print("chain-crit-part: S[%d]=",j);
3550 p_wrp(strat->S[j],currRing);
3551 Print(" divide B[%d].lcm=",i);
3552 p_wrp(strat->B[i].lcm,currRing);
3553 PrintLn();
3554 }
3555 deleteInL(strat->B,&strat->Bl,i,strat);
3556 strat->c3++;
3557 }
3558 }
3559 }
3560 }
3561 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3562 strat->pairtest=NULL;
3563 }
3564 if (strat->Gebauer || strat->fromT)
3565 {
3566 if (strat->sugarCrit)
3567 {
3568 /*
3569 *suppose L[j] == (s,r) and p/lcm(s,r)
3570 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3571 *and in case the sugar is o.k. then L[j] can be canceled
3572 */
3573 for (j=strat->Ll; j>=0; j--)
3574 {
3575 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3576 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3577 && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3578 {
3579 if (strat->L[j].p == strat->tail)
3580 {
3581 if(TEST_OPT_DEBUG)
3582 {
3583 PrintS("chain-crit-part: pCompareChainPart p=");
3584 p_wrp(p,currRing);
3585 Print(" delete L[%d]",j);
3586 p_wrp(strat->L[j].lcm,currRing);
3587 PrintLn();
3588 }
3589 deleteInL(strat->L,&strat->Ll,j,strat);
3590 strat->c3++;
3591 }
3592 }
3593 }
3594 /*
3595 *this is GEBAUER-MOELLER:
3596 *in B all elements with the same lcm except the "best"
3597 *(i.e. the last one in B with this property) will be canceled
3598 */
3599 j = strat->Bl;
3600 loop /*cannot be changed into a for !!! */
3601 {
3602 if (j <= 0) break;
3603 i = j-1;
3604 loop
3605 {
3606 if (i < 0) break;
3607 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3608 {
3609 strat->c3++;
3610 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3611 {
3612 if(TEST_OPT_DEBUG)
3613 {
3614 Print("chain-crit-part: sugar B[%d].lcm=",j);
3615 p_wrp(strat->B[j].lcm,currRing);
3616 Print(" delete B[%d]",i);
3617 p_wrp(strat->B[i].lcm,currRing);
3618 PrintLn();
3619 }
3620 deleteInL(strat->B,&strat->Bl,i,strat);
3621 j--;
3622 }
3623 else
3624 {
3625 if(TEST_OPT_DEBUG)
3626 {
3627 Print("chain-crit-part: sugar B[%d].lcm=",i);
3628 p_wrp(strat->B[i].lcm,currRing);
3629 Print(" delete B[%d]",j);
3630 p_wrp(strat->B[j].lcm,currRing);
3631 PrintLn();
3632 }
3633 deleteInL(strat->B,&strat->Bl,j,strat);
3634 break;
3635 }
3636 }
3637 i--;
3638 }
3639 j--;
3640 }
3641 }
3642 else /*sugarCrit*/
3643 {
3644 /*
3645 *suppose L[j] == (s,r) and p/lcm(s,r)
3646 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3647 *and in case the sugar is o.k. then L[j] can be canceled
3648 */
3649 for (j=strat->Ll; j>=0; j--)
3650 {
3651 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3652 {
3653 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3654 {
3655 if(TEST_OPT_DEBUG)
3656 {
3657 PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3658 p_wrp(p,currRing);
3659 Print(" delete L[%d]",j);
3660 p_wrp(strat->L[j].lcm,currRing);
3661 PrintLn();
3662 }
3663 deleteInL(strat->L,&strat->Ll,j,strat);
3664 strat->c3++;
3665 }
3666 }
3667 }
3668 /*
3669 *this is GEBAUER-MOELLER:
3670 *in B all elements with the same lcm except the "best"
3671 *(i.e. the last one in B with this property) will be canceled
3672 */
3673 j = strat->Bl;
3674 loop /*cannot be changed into a for !!! */
3675 {
3676 if (j <= 0) break;
3677 for(i=j-1; i>=0; i--)
3678 {
3679 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3680 {
3681 if(TEST_OPT_DEBUG)
3682 {
3683 Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3684 p_wrp(strat->B[j].lcm,currRing);
3685 Print(" delete B[%d]\n",i);
3686 }
3687 strat->c3++;
3688 deleteInL(strat->B,&strat->Bl,i,strat);
3689 j--;
3690 }
3691 }
3692 j--;
3693 }
3694 }
3695 /*
3696 *the elements of B enter L
3697 */
3698 kMergeBintoL(strat);
3699 }
3700 else
3701 {
3702 for (j=strat->Ll; j>=0; j--)
3703 {
3704 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3705 {
3706 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3707 {
3708 if(TEST_OPT_DEBUG)
3709 {
3710 PrintS("chain-crit-part: pCompareChainPart p=");
3711 p_wrp(p,currRing);
3712 Print(" delete L[%d]",j);
3713 p_wrp(strat->L[j].lcm,currRing);
3714 PrintLn();
3715 }
3716 deleteInL(strat->L,&strat->Ll,j,strat);
3717 strat->c3++;
3718 }
3719 }
3720 }
3721 /*
3722 *this is our MODIFICATION of GEBAUER-MOELLER:
3723 *First the elements of B enter L,
3724 *then we fix a lcm and the "best" element in L
3725 *(i.e the last in L with this lcm and of type (s,p))
3726 *and cancel all the other elements of type (r,p) with this lcm
3727 *except the case the element (s,r) has also the same lcm
3728 *and is on the worst position with respect to (s,p) and (r,p)
3729 */
3730 /*
3731 *B enters to L/their order with respect to B is permutated for elements
3732 *B[i].p with the same leading term
3733 */
3734 kMergeBintoL(strat);
3735 j = strat->Ll;
3736 loop /*cannot be changed into a for !!! */
3737 {
3738 if (j <= 0)
3739 {
3740 /*now L[0] cannot be canceled any more and the tail can be removed*/
3741 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3742 break;
3743 }
3744 if (strat->L[j].p2 == p)
3745 {
3746 i = j-1;
3747 loop
3748 {
3749 if (i < 0) break;
3750 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3751 {
3752 /*L[i] could be canceled but we search for a better one to cancel*/
3753 strat->c3++;
3754 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3755 && (pNext(strat->L[l].p) == strat->tail)
3756 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3758 strat->L[l].lcm,currRing,
3759 currRing->real_var_start, currRing->real_var_end))
3760
3761 {
3762 /*
3763 *"NOT equal(...)" because in case of "equal" the element L[l]
3764 *is "older" and has to be from theoretical point of view behind
3765 *L[i], but we do not want to reorder L
3766 */
3767 strat->L[i].p2 = strat->tail;
3768 /*
3769 *L[l] will be canceled, we cannot cancel L[i] later on,
3770 *so we mark it with "tail"
3771 */
3772 if(TEST_OPT_DEBUG)
3773 {
3774 PrintS("chain-crit-part: divisible_by p=");
3775 p_wrp(p,currRing);
3776 Print(" delete L[%d]",l);
3777 p_wrp(strat->L[l].lcm,currRing);
3778 PrintLn();
3779 }
3780 deleteInL(strat->L,&strat->Ll,l,strat);
3781 i--;
3782 }
3783 else
3784 {
3785 if(TEST_OPT_DEBUG)
3786 {
3787 PrintS("chain-crit-part: divisible_by(2) p=");
3788 p_wrp(p,currRing);
3789 Print(" delete L[%d]",i);
3790 p_wrp(strat->L[i].lcm,currRing);
3791 PrintLn();
3792 }
3793 deleteInL(strat->L,&strat->Ll,i,strat);
3794 }
3795 j--;
3796 }
3797 i--;
3798 }
3799 }
3800 else if (strat->L[j].p2 == strat->tail)
3801 {
3802 /*now L[j] cannot be canceled any more and the tail can be removed*/
3803 strat->L[j].p2 = p;
3804 }
3805 j--;
3806 }
3807 }
3808}
3809#endif
3810
3811/*2
3812*(s[0],h),...,(s[k],h) will be put to the pairset L
3813*/
3814void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR/* = -1*/)
3815{
3816
3817 if ((strat->syzComp==0)
3818 || (pGetComp(h)<=strat->syzComp))
3819 {
3820 int j;
3821 BOOLEAN new_pair=FALSE;
3822
3823 if (pGetComp(h)==0)
3824 {
3825 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3826 if ((isFromQ)&&(strat->fromQ!=NULL))
3827 {
3828 for (j=0; j<=k; j++)
3829 {
3830 if (!strat->fromQ[j])
3831 {
3832 new_pair=TRUE;
3833 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3834 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3835 }
3836 }
3837 }
3838 else
3839 {
3840 new_pair=TRUE;
3841 for (j=0; j<=k; j++)
3842 {
3843 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3844 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3845 }
3846 }
3847 }
3848 else
3849 {
3850 for (j=0; j<=k; j++)
3851 {
3852 if ((pGetComp(h)==pGetComp(strat->S[j]))
3853 || (pGetComp(strat->S[j])==0))
3854 {
3855 new_pair=TRUE;
3856 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3857 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3858 }
3859 }
3860 }
3861 if (new_pair)
3862 {
3863 #ifdef HAVE_RATGRING
3864 if (currRing->real_var_start>0)
3865 chainCritPart(h,ecart,strat);
3866 else
3867 #endif
3868 strat->chainCrit(h,ecart,strat);
3869 }
3870 kMergeBintoL(strat);
3871 }
3872}
3873
3874/*2
3875*(s[0],h),...,(s[k],h) will be put to the pairset L
3876*using signatures <= only for signature-based standard basis algorithms
3877*/
3878
3879void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3880{
3881
3882 if ((strat->syzComp==0)
3883 || (pGetComp(h)<=strat->syzComp))
3884 {
3885 int j;
3886 BOOLEAN new_pair=FALSE;
3887
3888 if (pGetComp(h)==0)
3889 {
3890 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3891 if ((isFromQ)&&(strat->fromQ!=NULL))
3892 {
3893 for (j=0; j<=k; j++)
3894 {
3895 if (!strat->fromQ[j])
3896 {
3897 new_pair=TRUE;
3898 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3899 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3900 }
3901 }
3902 }
3903 else
3904 {
3905 new_pair=TRUE;
3906 for (j=0; j<=k; j++)
3907 {
3908 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3909 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3910 }
3911 }
3912 }
3913 else
3914 {
3915 for (j=0; j<=k; j++)
3916 {
3917 if ((pGetComp(h)==pGetComp(strat->S[j]))
3918 || (pGetComp(strat->S[j])==0))
3919 {
3920 new_pair=TRUE;
3921 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3922 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3923 }
3924 }
3925 }
3926
3927 if (new_pair)
3928 {
3929#ifdef HAVE_RATGRING
3930 if (currRing->real_var_start>0)
3931 chainCritPart(h,ecart,strat);
3932 else
3933#endif
3934 strat->chainCrit(h,ecart,strat);
3935 }
3936 }
3937}
3938
3939void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3940{
3941
3942 if ((strat->syzComp==0)
3943 || (pGetComp(h)<=strat->syzComp))
3944 {
3945 int j;
3946
3947 if (pGetComp(h)==0)
3948 {
3949 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3950 if ((isFromQ)&&(strat->fromQ!=NULL))
3951 {
3952 for (j=0; j<=k && !strat->sigdrop; j++)
3953 {
3954 if (!strat->fromQ[j])
3955 {
3956 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3957 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3958 }
3959 }
3960 }
3961 else
3962 {
3963 for (j=0; j<=k && !strat->sigdrop; j++)
3964 {
3965 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3966 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3967 }
3968 }
3969 }
3970 else
3971 {
3972 for (j=0; j<=k && !strat->sigdrop; j++)
3973 {
3974 if ((pGetComp(h)==pGetComp(strat->S[j]))
3975 || (pGetComp(strat->S[j])==0))
3976 {
3977 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3978 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3979 }
3980 }
3981 }
3982
3983#if 0
3984 if (new_pair)
3985 {
3986#ifdef HAVE_RATGRING
3987 if (currRing->real_var_start>0)
3988 chainCritPart(h,ecart,strat);
3989 else
3990#endif
3991 strat->chainCrit(h,ecart,strat);
3992 }
3993#endif
3994 }
3995}
3996
3997/*2
3998*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3999*using the chain-criterion in B and L and enters B to L
4000*/
4001void chainCritRing (poly p,int, kStrategy strat)
4002{
4003 int i,j,l;
4004 /*
4005 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4006 *In this case all elements in B such
4007 *that their lcm is divisible by the leading term of S[i] can be canceled
4008 */
4009 if (strat->pairtest!=NULL)
4010 {
4011 {
4012 /*- i.e. there is an i with pairtest[i]==TRUE -*/
4013 for (j=0; j<=strat->sl; j++)
4014 {
4015 if (strat->pairtest[j])
4016 {
4017 for (i=strat->Bl; i>=0; i--)
4018 {
4019 if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4020 {
4021#ifdef KDEBUG
4022 if (TEST_OPT_DEBUG)
4023 {
4024 PrintS("--- chain criterion func chainCritRing type 1\n");
4025 PrintS("strat->S[j]:");
4026 wrp(strat->S[j]);
4027 PrintS(" strat->B[i].lcm:");
4028 wrp(strat->B[i].lcm);PrintLn();
4029 pWrite(strat->B[i].p);
4030 pWrite(strat->B[i].p1);
4031 pWrite(strat->B[i].p2);
4032 wrp(strat->B[i].lcm);
4033 PrintLn();
4034 }
4035#endif
4036 deleteInL(strat->B,&strat->Bl,i,strat);
4037 strat->c3++;
4038 }
4039 }
4040 }
4041 }
4042 }
4043 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4044 strat->pairtest=NULL;
4045 }
4046 assume(!(strat->Gebauer || strat->fromT));
4047 for (j=strat->Ll; j>=0; j--)
4048 {
4049 if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4050 {
4051 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4052 {
4053 if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4054 {
4055 deleteInL(strat->L,&strat->Ll,j,strat);
4056 strat->c3++;
4057#ifdef KDEBUG
4058 if (TEST_OPT_DEBUG)
4059 {
4060 PrintS("--- chain criterion func chainCritRing type 2\n");
4061 PrintS("strat->L[j].p:");
4062 wrp(strat->L[j].p);
4063 PrintS(" p:");
4064 wrp(p);
4065 PrintLn();
4066 }
4067#endif
4068 }
4069 }
4070 }
4071 }
4072 /*
4073 *this is our MODIFICATION of GEBAUER-MOELLER:
4074 *First the elements of B enter L,
4075 *then we fix a lcm and the "best" element in L
4076 *(i.e the last in L with this lcm and of type (s,p))
4077 *and cancel all the other elements of type (r,p) with this lcm
4078 *except the case the element (s,r) has also the same lcm
4079 *and is on the worst position with respect to (s,p) and (r,p)
4080 */
4081 /*
4082 *B enters to L/their order with respect to B is permutated for elements
4083 *B[i].p with the same leading term
4084 */
4085 kMergeBintoL(strat);
4086 j = strat->Ll;
4087 loop /*cannot be changed into a for !!! */
4088 {
4089 if (j <= 0)
4090 {
4091 /*now L[0] cannot be canceled any more and the tail can be removed*/
4092 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4093 break;
4094 }
4095 if (strat->L[j].p2 == p) // Was the element added from B?
4096 {
4097 i = j-1;
4098 loop
4099 {
4100 if (i < 0) break;
4101 // Element is from B and has the same lcm as L[j]
4102 if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4103 && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4104 {
4105 /*L[i] could be canceled but we search for a better one to cancel*/
4106 strat->c3++;
4107#ifdef KDEBUG
4108 if (TEST_OPT_DEBUG)
4109 {
4110 PrintS("--- chain criterion func chainCritRing type 3\n");
4111 PrintS("strat->L[j].lcm:");
4112 wrp(strat->L[j].lcm);
4113 PrintS(" strat->L[i].lcm:");
4114 wrp(strat->L[i].lcm);
4115 PrintLn();
4116 }
4117#endif
4118 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4119 && (pNext(strat->L[l].p) == strat->tail)
4120 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4121 && pDivisibleBy(p,strat->L[l].lcm))
4122 {
4123 /*
4124 *"NOT equal(...)" because in case of "equal" the element L[l]
4125 *is "older" and has to be from theoretical point of view behind
4126 *L[i], but we do not want to reorder L
4127 */
4128 strat->L[i].p2 = strat->tail;
4129 /*
4130 *L[l] will be canceled, we cannot cancel L[i] later on,
4131 *so we mark it with "tail"
4132 */
4133 deleteInL(strat->L,&strat->Ll,l,strat);
4134 i--;
4135 }
4136 else
4137 {
4138 deleteInL(strat->L,&strat->Ll,i,strat);
4139 }
4140 j--;
4141 }
4142 i--;
4143 }
4144 }
4145 else if (strat->L[j].p2 == strat->tail)
4146 {
4147 /*now L[j] cannot be canceled any more and the tail can be removed*/
4148 strat->L[j].p2 = p;
4149 }
4150 j--;
4151 }
4152}
4153
4154/*2
4155*(s[0],h),...,(s[k],h) will be put to the pairset L
4156*/
4157void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4158{
4159 if (!nIsOne(pGetCoeff(h)))
4160 {
4161 int j;
4162 BOOLEAN new_pair=FALSE;
4163
4164 if (pGetComp(h)==0)
4165 {
4166 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4167 if ((isFromQ)&&(strat->fromQ!=NULL))
4168 {
4169 for (j=0; j<=k; j++)
4170 {
4171 if (!strat->fromQ[j])
4172 {
4173 new_pair=TRUE;
4174 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4175 }
4176 }
4177 }
4178 else
4179 {
4180 new_pair=TRUE;
4181 for (j=0; j<=k; j++)
4182 {
4183 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4184 }
4185 }
4186 }
4187 else
4188 {
4189 for (j=0; j<=k; j++)
4190 {
4191 if ((pGetComp(h)==pGetComp(strat->S[j]))
4192 || (pGetComp(strat->S[j])==0))
4193 {
4194 new_pair=TRUE;
4195 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4196 }
4197 }
4198 }
4199 if (new_pair)
4200 {
4201 #ifdef HAVE_RATGRING
4202 if (currRing->real_var_start>0)
4203 chainCritPart(h,ecart,strat);
4204 else
4205 #endif
4206 strat->chainCrit(h,ecart,strat);
4207 }
4208 kMergeBintoL(strat);
4209 }
4210}
4211
4212static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4213{
4214 const int iCompH = pGetComp(h);
4215 if (!nIsOne(pGetCoeff(h)))
4216 {
4217 int j;
4218
4219 for (j=0; j<=k && !strat->sigdrop; j++)
4220 {
4221 // Print("j:%d, Ll:%d\n",j,strat->Ll);
4222// if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4223// ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4224 if (((iCompH == pGetComp(strat->S[j]))
4225 || (0 == pGetComp(strat->S[j])))
4226 && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4227 {
4228 enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4229 }
4230 }
4231 }
4232}
4233
4234/*2
4235* Generates spoly(0, h) if applicable. Assumes ring has zero divisors
4236*/
4238{
4239 if (nIsOne(pGetCoeff(h))) return;
4240 number gcd;
4241 number zero=n_Init(0,currRing->cf);
4242 bool go = false;
4243 if (n_DivBy(zero, pGetCoeff(h), currRing->cf))
4244 {
4245 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4246 go = true;
4247 }
4248 else
4249 gcd = n_Gcd(zero, pGetCoeff(h), strat->tailRing->cf);
4250 if (go || !nIsOne(gcd))
4251 {
4252 poly p = h->next;
4253 if (!go)
4254 {
4255 number tmp = gcd;
4256 gcd = n_Ann(gcd,currRing->cf);
4257 nDelete(&tmp);
4258 }
4259 p_Test(p,strat->tailRing);
4260 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4261
4262 if (p != NULL)
4263 {
4264 if (TEST_OPT_PROT)
4265 {
4266 PrintS("Z");
4267 }
4268#ifdef KDEBUG
4269 if (TEST_OPT_DEBUG)
4270 {
4271 PrintS("--- create zero spoly: ");
4272 p_wrp(h,currRing,strat->tailRing);
4273 PrintS(" ---> ");
4274 }
4275#endif
4276 poly tmp = pInit();
4277 pSetCoeff0(tmp, pGetCoeff(p));
4278 for (int i = 1; i <= rVar(currRing); i++)
4279 {
4280 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4281 }
4283 {
4284 p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4285 }
4286 p_Setm(tmp, currRing);
4287 p = p_LmFreeAndNext(p, strat->tailRing);
4288 pNext(tmp) = p;
4289 LObject Lp;
4290 Lp.Init();
4291 Lp.p = tmp;
4292 Lp.tailRing = strat->tailRing;
4293 int posx;
4294 if (Lp.p!=NULL)
4295 {
4296 strat->initEcart(&Lp);
4297 if (strat->Ll==-1)
4298 posx =0;
4299 else
4300 posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4301 Lp.sev = pGetShortExpVector(Lp.p);
4302 if (strat->tailRing != currRing)
4303 {
4304 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4305 }
4306#ifdef KDEBUG
4307 if (TEST_OPT_DEBUG)
4308 {
4309 p_wrp(tmp,currRing,strat->tailRing);
4310 PrintLn();
4311 }
4312#endif
4313 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4314 }
4315 }
4316 }
4317 nDelete(&zero);
4318 nDelete(&gcd);
4319}
4320
4321void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
4322{
4323 if (nIsOne(pGetCoeff(h))) return;
4324 number gcd;
4325 number zero=n_Init(0,currRing->cf);
4326 bool go = false;
4327 if (n_DivBy(zero, pGetCoeff(h), currRing->cf))
4328 {
4329 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4330 go = true;
4331 }
4332 else
4333 gcd = n_Gcd(zero, pGetCoeff(h), strat->tailRing->cf);
4334 if (go || !nIsOne(gcd))
4335 {
4336 poly p = h->next;
4337 if (!go)
4338 {
4339 number tmp = gcd;
4340 gcd = n_Ann(gcd,currRing->cf);
4341 nDelete(&tmp);
4342 }
4343 p_Test(p,strat->tailRing);
4344 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4345
4346 if (p != NULL)
4347 {
4348 if (TEST_OPT_PROT)
4349 {
4350 PrintS("Z");
4351 }
4352#ifdef KDEBUG
4353 if (TEST_OPT_DEBUG)
4354 {
4355 PrintS("--- create zero spoly: ");
4356 p_wrp(h,currRing,strat->tailRing);
4357 PrintS(" ---> ");
4358 }
4359#endif
4360 poly tmp = pInit();
4361 pSetCoeff0(tmp, pGetCoeff(p));
4362 for (int i = 1; i <= rVar(currRing); i++)
4363 {
4364 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4365 }
4367 {
4368 p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4369 }
4370 p_Setm(tmp, currRing);
4371 p = p_LmFreeAndNext(p, strat->tailRing);
4372 pNext(tmp) = p;
4373 LObject Lp;
4374 Lp.Init();
4375 Lp.p = tmp;
4376 //printf("\nOld\n");pWrite(h);pWrite(hSig);
4377 #if EXT_POLY_NEW
4378 Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4379 if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4380 {
4381 strat->sigdrop = TRUE;
4382 //Try to reduce it as far as we can via redRing
4383 int red_result = redRing(&Lp,strat);
4384 if(red_result == 0)
4385 {
4386 // Cancel the sigdrop
4387 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4388 strat->sigdrop = FALSE;
4389 }
4390 else
4391 {
4392 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4393 #if 1
4394 strat->enterS(Lp,0,strat,strat->tl);
4395 #endif
4396 }
4397 nDelete(&zero);
4398 nDelete(&gcd);
4399 return;
4400 }
4401 #else
4402 Lp.sig = pOne();
4403 if(strat->Ll >= 0)
4404 p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4405 else
4406 p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4407 #endif
4408 Lp.tailRing = strat->tailRing;
4409 int posx;
4410 if (Lp.p!=NULL)
4411 {
4412 strat->initEcart(&Lp);
4413 if (strat->Ll==-1)
4414 posx =0;
4415 else
4416 posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4417 Lp.sev = pGetShortExpVector(Lp.p);
4418 if (strat->tailRing != currRing)
4419 {
4420 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4421 }
4422#ifdef KDEBUG
4423 if (TEST_OPT_DEBUG)
4424 {
4425 p_wrp(tmp,currRing,strat->tailRing);
4426 PrintLn();
4427 }
4428#endif
4429 //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4430 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4431 }
4432 }
4433 }
4434 nDelete(&gcd);
4435 nDelete(&zero);
4436}
4437
4438void clearSbatch (poly h,int k,int pos,kStrategy strat)
4439{
4440 int j = pos;
4441 if ( (!strat->fromT)
4442 && ((strat->syzComp==0)
4443 ||(pGetComp(h)<=strat->syzComp)
4444 ))
4445 {
4446 // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4447 unsigned long h_sev = pGetShortExpVector(h);
4448 loop
4449 {
4450 if (j > k) break;
4451 clearS(h,h_sev, &j,&k,strat);
4452 j++;
4453 }
4454 // Print("end clearS sl=%d\n",strat->sl);
4455 }
4456}
4457
4458/*2
4459* Generates a sufficient set of spolys (maybe just a finite generating
4460* set of the syzygys)
4461*/
4462void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4463{
4465#if HAVE_SHIFTBBA
4466 assume(!rIsLPRing(currRing)); /* LP should use enterpairsShift */
4467#endif
4468 // enter also zero divisor * poly, if this is non zero and of smaller degree
4470 initenterstrongPairs(h, k, ecart, 0, strat, atR);
4471 initenterpairs(h, k, ecart, 0, strat, atR);
4472 clearSbatch(h, k, pos, strat);
4473}
4474
4475void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4476{
4478 // enter also zero divisor * poly, if this is non zero and of smaller degree
4479 if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4480 if(strat->sigdrop) return;
4481 initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4482 if(strat->sigdrop) return;
4483 initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4484 if(strat->sigdrop) return;
4485 clearSbatch(h, k, pos, strat);
4486}
4487
4488/*2
4489*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4490*superfluous elements in S will be deleted
4491*/
4492void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4493{
4494 int j=pos;
4495
4497 initenterpairs(h,k,ecart,0,strat, atR);
4498 if ( (!strat->fromT)
4499 && ((strat->syzComp==0)
4500 ||(pGetComp(h)<=strat->syzComp)))
4501 {
4502 unsigned long h_sev = pGetShortExpVector(h);
4503 loop
4504 {
4505 if (j > k) break;
4506 clearS(h,h_sev, &j,&k,strat);
4507 j++;
4508 }
4509 }
4510}
4511
4512/*2
4513*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4514*superfluous elements in S will be deleted
4515*this is a special variant of signature-based algorithms including the
4516*signatures for criteria checks
4517*/
4518void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4519{
4520 int j=pos;
4522 initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4523 if ( (!strat->fromT)
4524 && ((strat->syzComp==0)
4525 ||(pGetComp(h)<=strat->syzComp)))
4526 {
4527 unsigned long h_sev = pGetShortExpVector(h);
4528 loop
4529 {
4530 if (j > k) break;
4531 clearS(h,h_sev, &j,&k,strat);
4532 j++;
4533 }
4534 }
4535}
4536
4537/*2
4538*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4539*superfluous elements in S will be deleted
4540*/
4541void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4542{
4543 int j;
4544 const int iCompH = pGetComp(h);
4545
4547 {
4548 for (j=0; j<=k; j++)
4549 {
4550 const int iCompSj = pGetComp(strat->S[j]);
4551 if ((iCompH==iCompSj)
4552 //|| (0==iCompH) // can only happen,if iCompSj==0
4553 || (0==iCompSj))
4554 {
4555 enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4556 }
4557 }
4558 kMergeBintoL(strat);
4559 }
4560 else
4561 {
4562 for (j=0; j<=k; j++)
4563 {
4564 const int iCompSj = pGetComp(strat->S[j]);
4565 if ((iCompH==iCompSj)
4566 //|| (0==iCompH) // can only happen,if iCompSj==0
4567 || (0==iCompSj))
4568 {
4569 enterOnePairSpecial(j,h,ecart,strat, atR);
4570 }
4571 }
4572 }
4573
4574 if (strat->noClearS) return;
4575
4576// #ifdef HAVE_PLURAL
4577/*
4578 if (rIsPluralRing(currRing))
4579 {
4580 j=pos;
4581 loop
4582 {
4583 if (j > k) break;
4584
4585 if (pLmDivisibleBy(h, strat->S[j]))
4586 {
4587 deleteInS(j, strat);
4588 j--;
4589 k--;
4590 }
4591
4592 j++;
4593 }
4594 }
4595 else
4596*/
4597// #endif // ??? Why was the following cancellation disabled for non-commutative rings?
4598 {
4599 j=pos;
4600 loop
4601 {
4602 unsigned long h_sev = pGetShortExpVector(h);
4603 if (j > k) break;
4604 clearS(h,h_sev,&j,&k,strat);
4605 j++;
4606 }
4607 }
4608}
4609
4610/*2
4611*reorders s with respect to posInS,
4612*suc is the first changed index or zero
4613*/
4614
4615void reorderS (int* suc,kStrategy strat)
4616{
4617 int i,j,at,ecart, s2r;
4618 int fq=0;
4619 unsigned long sev;
4620 poly p;
4621 int new_suc=strat->sl+1;
4622 i= *suc;
4623 if (i<0) i=0;
4624
4625 for (; i<=strat->sl; i++)
4626 {
4627 at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4628 if (at != i)
4629 {
4630 if (new_suc > at) new_suc = at;
4631 p = strat->S[i];
4632 ecart = strat->ecartS[i];
4633 sev = strat->sevS[i];
4634 s2r = strat->S_2_R[i];
4635 if (strat->fromQ!=NULL) fq=strat->fromQ[i];
4636 for (j=i; j>=at+1; j--)
4637 {
4638 strat->S[j] = strat->S[j-1];
4639 strat->ecartS[j] = strat->ecartS[j-1];
4640 strat->sevS[j] = strat->sevS[j-1];
4641 strat->S_2_R[j] = strat->S_2_R[j-1];
4642 }
4643 strat->S[at] = p;
4644 strat->ecartS[at] = ecart;
4645 strat->sevS[at] = sev;
4646 strat->S_2_R[at] = s2r;
4647 if (strat->fromQ!=NULL)
4648 {
4649 for (j=i; j>=at+1; j--)
4650 {
4651 strat->fromQ[j] = strat->fromQ[j-1];
4652 }
4653 strat->fromQ[at]=fq;
4654 }
4655 }
4656 }
4657 if (new_suc <= strat->sl) *suc=new_suc;
4658 else *suc=-1;
4659}
4660
4661
4662/*2
4663*looks up the position of p in set
4664*set[0] is the smallest with respect to the ordering-procedure deg/pComp
4665* Assumption: posInS only depends on the leading term
4666* otherwise, bba has to be changed
4667*/
4668int posInS (const kStrategy strat, const int length,const poly p,
4669 const int ecart_p)
4670{
4671 if(length==-1) return 0;
4672 polyset set=strat->S;
4673 int i;
4674 int an = 0;
4675 int en = length;
4676 int cmp_int = currRing->OrdSgn;
4678#ifdef HAVE_PLURAL
4679 && (currRing->real_var_start==0)
4680#endif
4681#if 0
4682 || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
4683#endif
4684 )
4685 {
4686 int o=p_Deg(p,currRing);
4687 int oo=p_Deg(set[length],currRing);
4688
4689 if ((oo<o)
4690 || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
4691 return length+1;
4692
4693 loop
4694 {
4695 if (an >= en-1)
4696 {
4697 if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
4698 {
4699 return an;
4700 }
4701 return en;
4702 }
4703 i=(an+en) / 2;
4704 if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
4705 else an=i;
4706 }
4707 }
4708 else
4709 {
4711 {
4712 if (pLmCmp(set[length],p)== -cmp_int)
4713 return length+1;
4714 int cmp;
4715 loop
4716 {
4717 if (an >= en-1)
4718 {
4719 cmp = pLmCmp(set[an],p);
4720 if (cmp == cmp_int) return an;
4721 if (cmp == -cmp_int) return en;
4722 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
4723 return an;
4724 }
4725 i = (an+en) / 2;
4726 cmp = pLmCmp(set[i],p);
4727 if (cmp == cmp_int) en = i;
4728 else if (cmp == -cmp_int) an = i;
4729 else
4730 {
4731 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
4732 else en = i;
4733 }
4734 }
4735 }
4736 else
4737 if (pLmCmp(set[length],p)== -cmp_int)
4738 return length+1;
4739
4740 loop
4741 {
4742 if (an >= en-1)
4743 {
4744 if (pLmCmp(set[an],p) == cmp_int) return an;
4745 if (pLmCmp(set[an],p) == -cmp_int) return en;
4746 if ((cmp_int!=1)
4747 && ((strat->ecartS[an])>ecart_p))
4748 return an;
4749 return en;
4750 }
4751 i=(an+en) / 2;
4752 if (pLmCmp(set[i],p) == cmp_int) en=i;
4753 else if (pLmCmp(set[i],p) == -cmp_int) an=i;
4754 else
4755 {
4756 if ((cmp_int!=1)
4757 &&((strat->ecartS[i])<ecart_p))
4758 en=i;
4759 else
4760 an=i;
4761 }
4762 }
4763 }
4764}
4765
4766
4767// sorts by degree and pLtCmp
4768// but puts pure monomials at the beginning
4769int posInSMonFirst (const kStrategy strat, const int length,const poly p)
4770{
4771 if (length<0) return 0;
4772 polyset set=strat->S;
4773 if(pNext(p) == NULL)
4774 {
4775 int mon = 0;
4776 for(int i = 0;i<=length;i++)
4777 {
4778 if(set[i] != NULL && pNext(set[i]) == NULL)
4779 mon++;
4780 }
4781 int o = p_Deg(p,currRing);
4782 int op = p_Deg(set[mon],currRing);
4783
4784 if ((op < o)
4785 || ((op == o) && (pLtCmp(set[mon],p) == -1)))
4786 return length+1;
4787 int i;
4788 int an = 0;
4789 int en= mon;
4790 loop
4791 {
4792 if (an >= en-1)
4793 {
4794 op = p_Deg(set[an],currRing);
4795 if ((op < o)
4796 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4797 return en;
4798 return an;
4799 }
4800 i=(an+en) / 2;
4801 op = p_Deg(set[i],currRing);
4802 if ((op < o)
4803 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4804 an=i;
4805 else
4806 en=i;
4807 }
4808 }
4809 else /*if(pNext(p) != NULL)*/
4810 {
4811 int o = p_Deg(p,currRing);
4812 int op = p_Deg(set[length],currRing);
4813
4814 if ((op < o)
4815 || ((op == o) && (pLtCmp(set[length],p) == -1)))
4816 return length+1;
4817 int i;
4818 int an = 0;
4819 for(i=0;i<=length;i++)
4820 if(set[i] != NULL && pNext(set[i]) == NULL)
4821 an++;
4822 int en= length;
4823 loop
4824 {
4825 if (an >= en-1)
4826 {
4827 op = p_Deg(set[an],currRing);
4828 if ((op < o)
4829 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4830 return en;
4831 return an;
4832 }
4833 i=(an+en) / 2;
4834 op = p_Deg(set[i],currRing);
4835 if ((op < o)
4836 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4837 an=i;
4838 else
4839 en=i;
4840 }
4841 }
4842}
4843
4844// sorts by degree and pLtCmp in the block between start,end;
4845// but puts pure monomials at the beginning
4846int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
4847{
4848 if(end < 0 || end >= IDELEMS(F))
4849 end = IDELEMS(F);
4850 if (end<0) return 0;
4851 if(pNext(p) == NULL) return start;
4852 polyset set=F->m;
4853 int o = p_Deg(p,currRing);
4854 int op;
4855 int i;
4856 int an = start;
4857 for(i=start;i<end;i++)
4858 if(set[i] != NULL && pNext(set[i]) == NULL)
4859 an++;
4860 if(an == end-1)
4861 return end;
4862 int en= end;
4863 loop
4864 {
4865 if(an>=en)
4866 return en;
4867 if (an == en-1)
4868 {
4869 op = p_Deg(set[an],currRing);
4870 if ((op < o)
4871 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4872 return en;
4873 return an;
4874 }
4875 i=(an+en) / 2;
4876 op = p_Deg(set[i],currRing);
4877 if ((op < o)
4878 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4879 an=i;
4880 else
4881 en=i;
4882 }
4883}
4884
4885
4886/*2
4887* looks up the position of p in set
4888* the position is the last one
4889*/
4890int posInT0 (const TSet,const int length,LObject &)
4891{
4892 return (length+1);
4893}
4894
4895
4896/*2
4897* looks up the position of p in T
4898* set[0] is the smallest with respect to the ordering-procedure
4899* pComp
4900*/
4901int posInT1 (const TSet set,const int length,LObject &p)
4902{
4903 if (length==-1) return 0;
4904
4905 if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
4906
4907 int i;
4908 int an = 0;
4909 int en= length;
4910 int cmp_int=currRing->OrdSgn;
4911
4912 loop
4913 {
4914 if (an >= en-1)
4915 {
4916 if (pLmCmp(set[an].p,p.p) == cmp_int) return an;
4917 return en;
4918 }
4919 i=(an+en) / 2;
4920 if (pLmCmp(set[i].p,p.p) == cmp_int) en=i;
4921 else an=i;
4922 }
4923}
4924
4925/*2
4926* looks up the position of p in T
4927* set[0] is the smallest with respect to the ordering-procedure
4928* length
4929*/
4930int posInT2 (const TSet set,const int length,LObject &p)
4931{
4932 if (length==-1) return 0;
4933 p.GetpLength();
4934 if (set[length].length<p.length) return length+1;
4935
4936 int i;
4937 int an = 0;
4938 int en= length;
4939
4940 loop
4941 {
4942 if (an >= en-1)
4943 {
4944 if (set[an].length>p.length) return an;
4945 return en;
4946 }
4947 i=(an+en) / 2;
4948 if (set[i].length>p.length) en=i;
4949 else an=i;
4950 }
4951}
4952
4953/*2
4954* looks up the position of p in T
4955* set[0] is the smallest with respect to the ordering-procedure
4956* totaldegree,pComp
4957*/
4958int posInT11 (const TSet set,const int length,LObject &p)
4959{
4960 if (length==-1) return 0;
4961
4962 int o = p.GetpFDeg();
4963 int op = set[length].GetpFDeg();
4964 int cmp_int=currRing->OrdSgn;
4965
4966 if ((op < o)
4967 || ((op == o) && (pLmCmp(set[length].p,p.p) != cmp_int)))
4968 return length+1;
4969
4970 int i;
4971 int an = 0;
4972 int en= length;
4973
4974 loop
4975 {
4976 if (an >= en-1)
4977 {
4978 op= set[an].GetpFDeg();
4979 if ((op > o)
4980 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
4981 return an;
4982 return en;
4983 }
4984 i=(an+en) / 2;
4985 op = set[i].GetpFDeg();
4986 if (( op > o)
4987 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
4988 en=i;
4989 else
4990 an=i;
4991 }
4992}
4993
4994int posInT11Ring (const TSet set,const int length,LObject &p)
4995{
4996 if (length==-1) return 0;
4997
4998 int o = p.GetpFDeg();
4999 int op = set[length].GetpFDeg();
5000
5001 if ((op < o)
5002 || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5003 return length+1;
5004
5005 int i;
5006 int an = 0;
5007 int en= length;
5008
5009 loop
5010 {
5011 if (an >= en-1)
5012 {
5013 op= set[an].GetpFDeg();
5014 if ((op > o)
5015 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5016 return an;
5017 return en;
5018 }
5019 i=(an+en) / 2;
5020 op = set[i].GetpFDeg();
5021 if (( op > o)
5022 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5023 en=i;
5024 else
5025 an=i;
5026 }
5027}
5028
5029/*2
5030* looks up the position of p in T
5031* set[0] is the smallest with respect to the ordering-procedure
5032* totaldegree,pComp
5033*/
5034int posInT110 (const TSet set,const int length,LObject &p)
5035{
5036 if (length==-1) return 0;
5037 p.GetpLength();
5038
5039 int o = p.GetpFDeg();
5040 int op = set[length].GetpFDeg();
5041 int cmp_int=currRing->OrdSgn;
5042
5043 if (( op < o)
5044 || (( op == o) && (set[length].length<p.length))
5045 || (( op == o) && (set[length].length == p.length)
5046 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5047 return length+1;
5048
5049 int i;
5050 int an = 0;
5051 int en= length;
5052 loop
5053 {
5054 if (an >= en-1)
5055 {
5056 op = set[an].GetpFDeg();
5057 if (( op > o)
5058 || (( op == o) && (set[an].length > p.length))
5059 || (( op == o) && (set[an].length == p.length)
5060 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5061 return an;
5062 return en;
5063 }
5064 i=(an+en) / 2;
5065 op = set[i].GetpFDeg();
5066 if (( op > o)
5067 || (( op == o) && (set[i].length > p.length))
5068 || (( op == o) && (set[i].length == p.length)
5069 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5070 en=i;
5071 else
5072 an=i;
5073 }
5074}
5075
5076int posInT110Ring (const TSet set,const int length,LObject &p)
5077{
5078 if (length==-1) return 0;
5079 p.GetpLength();
5080
5081 int o = p.GetpFDeg();
5082 int op = set[length].GetpFDeg();
5083
5084 if (( op < o)
5085 || (( op == o) && (set[length].length<p.length))
5086 || (( op == o) && (set[length].length == p.length)
5087 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5088 return length+1;
5089
5090 int i;
5091 int an = 0;
5092 int en= length;
5093 loop
5094 {
5095 if (an >= en-1)
5096 {
5097 op = set[an].GetpFDeg();
5098 if (( op > o)
5099 || (( op == o) && (set[an].length > p.length))
5100 || (( op == o) && (set[an].length == p.length)
5101 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5102 return an;
5103 return en;
5104 }
5105 i=(an+en) / 2;
5106 op = set[i].GetpFDeg();
5107 if (( op > o)
5108 || (( op == o) && (set[i].length > p.length))
5109 || (( op == o) && (set[i].length == p.length)
5110 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5111 en=i;
5112 else
5113 an=i;
5114 }
5115}
5116
5117/*2
5118* looks up the position of p in set
5119* set[0] is the smallest with respect to the ordering-procedure
5120* pFDeg
5121*/
5122int posInT13 (const TSet set,const int length,LObject &p)
5123{
5124 if (length==-1) return 0;
5125
5126 int o = p.GetpFDeg();
5127
5128 if (set[length].GetpFDeg() <= o)
5129 return length+1;
5130
5131 int i;
5132 int an = 0;
5133 int en= length;
5134 loop
5135 {
5136 if (an >= en-1)
5137 {
5138 if (set[an].GetpFDeg() > o)
5139 return an;
5140 return en;
5141 }
5142 i=(an+en) / 2;
5143 if (set[i].GetpFDeg() > o)
5144 en=i;
5145 else
5146 an=i;
5147 }
5148}
5149
5150// determines the position based on: 1.) Ecart 2.) pLength
5151int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5152{
5153 if (length==-1) return 0;
5154 int ol = p.GetpLength();
5155 int op=p.ecart;
5156 int oo=set[length].ecart;
5157
5158 if ((oo < op) || ((oo==op) && (set[length].length <= ol)))
5159 return length+1;
5160
5161 int i;
5162 int an = 0;
5163 int en= length;
5164 loop
5165 {
5166 if (an >= en-1)
5167 {
5168 int oo=set[an].ecart;
5169 if((oo > op)
5170 || ((oo==op) && (set[an].pLength > ol)))
5171 return an;
5172 return en;
5173 }
5174 i=(an+en) / 2;
5175 int oo=set[i].ecart;
5176 if ((oo > op)
5177 || ((oo == op) && (set[i].pLength > ol)))
5178 en=i;
5179 else
5180 an=i;
5181 }
5182}
5183
5184/*2
5185* looks up the position of p in set
5186* set[0] is the smallest with respect to the ordering-procedure
5187* maximaldegree, pComp
5188*/
5189int posInT15 (const TSet set,const int length,LObject &p)
5190/*{
5191 *int j=0;
5192 * int o;
5193 *
5194 * o = p.GetpFDeg()+p.ecart;
5195 * loop
5196 * {
5197 * if ((set[j].GetpFDeg()+set[j].ecart > o)
5198 * || ((set[j].GetpFDeg()+set[j].ecart == o)
5199 * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5200 * {
5201 * return j;
5202 * }
5203 * j++;
5204 * if (j > length) return j;
5205 * }
5206 *}
5207 */
5208{
5209 if (length==-1) return 0;
5210
5211 int o = p.GetpFDeg() + p.ecart;
5212 int op = set[length].GetpFDeg()+set[length].ecart;
5213 int cmp_int=currRing->OrdSgn;
5214
5215 if ((op < o)
5216 || ((op == o)
5217 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5218 return length+1;
5219
5220 int i;
5221 int an = 0;
5222 int en= length;
5223 loop
5224 {
5225 if (an >= en-1)
5226 {
5227 op = set[an].GetpFDeg()+set[an].ecart;
5228 if (( op > o)
5229 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
5230 return an;
5231 return en;
5232 }
5233 i=(an+en) / 2;
5234 op = set[i].GetpFDeg()+set[i].ecart;
5235 if (( op > o)
5236 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
5237 en=i;
5238 else
5239 an=i;
5240 }
5241}
5242
5243int posInT15Ring (const TSet set,const int length,LObject &p)
5244{
5245 if (length==-1) return 0;
5246
5247 int o = p.GetpFDeg() + p.ecart;
5248 int op = set[length].GetpFDeg()+set[length].ecart;
5249
5250 if ((op < o)
5251 || ((op == o)
5252 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5253 return length+1;
5254
5255 int i;
5256 int an = 0;
5257 int en= length;
5258 loop
5259 {
5260 if (an >= en-1)
5261 {
5262 op = set[an].GetpFDeg()+set[an].ecart;
5263 if (( op > o)
5264 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5265 return an;
5266 return en;
5267 }
5268 i=(an+en) / 2;
5269 op = set[i].GetpFDeg()+set[i].ecart;
5270 if (( op > o)
5271 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5272 en=i;
5273 else
5274 an=i;
5275 }
5276}
5277
5278/*2
5279* looks up the position of p in set
5280* set[0] is the smallest with respect to the ordering-procedure
5281* pFDeg+ecart, ecart, pComp
5282*/
5283int posInT17 (const TSet set,const int length,LObject &p)
5284/*
5285*{
5286* int j=0;
5287* int o;
5288*
5289* o = p.GetpFDeg()+p.ecart;
5290* loop
5291* {
5292* if ((pFDeg(set[j].p)+set[j].ecart > o)
5293* || (((pFDeg(set[j].p)+set[j].ecart == o)
5294* && (set[j].ecart < p.ecart)))
5295* || ((pFDeg(set[j].p)+set[j].ecart == o)
5296* && (set[j].ecart==p.ecart)
5297* && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5298* return j;
5299* j++;
5300* if (j > length) return j;
5301* }
5302* }
5303*/
5304{
5305 if (length==-1) return 0;
5306
5307 int o = p.GetpFDeg() + p.ecart;
5308 int op = set[length].GetpFDeg()+set[length].ecart;
5309 int cmp_int=currRing->OrdSgn;
5310
5311 if ((op < o)
5312 || (( op == o) && (set[length].ecart > p.ecart))
5313 || (( op == o) && (set[length].ecart==p.ecart)
5314 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5315 return length+1;
5316
5317 int i;
5318 int an = 0;
5319 int en= length;
5320 loop
5321 {
5322 if (an >= en-1)
5323 {
5324 op = set[an].GetpFDeg()+set[an].ecart;
5325 if (( op > o)
5326 || (( op == o) && (set[an].ecart < p.ecart))
5327 || (( op == o) && (set[an].ecart==p.ecart)
5328 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5329 return an;
5330 return en;
5331 }
5332 i=(an+en) / 2;
5333 op = set[i].GetpFDeg()+set[i].ecart;
5334 if ((op > o)
5335 || (( op == o) && (set[i].ecart < p.ecart))
5336 || (( op == o) && (set[i].ecart == p.ecart)
5337 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5338 en=i;
5339 else
5340 an=i;
5341 }
5342}
5343
5344int posInT17Ring (const TSet set,const int length,LObject &p)
5345{
5346 if (length==-1) return 0;
5347
5348 int o = p.GetpFDeg() + p.ecart;
5349 int op = set[length].GetpFDeg()+set[length].ecart;
5350
5351 if ((op < o)
5352 || (( op == o) && (set[length].ecart > p.ecart))
5353 || (( op == o) && (set[length].ecart==p.ecart)
5354 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5355 return length+1;
5356
5357 int i;
5358 int an = 0;
5359 int en= length;
5360 loop
5361 {
5362 if (an >= en-1)
5363 {
5364 op = set[an].GetpFDeg()+set[an].ecart;
5365 if (( op > o)
5366 || (( op == o) && (set[an].ecart < p.ecart))
5367 || (( op == o) && (set[an].ecart==p.ecart)
5368 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5369 return an;
5370 return en;
5371 }
5372 i=(an+en) / 2;
5373 op = set[i].GetpFDeg()+set[i].ecart;
5374 if ((op > o)
5375 || (( op == o) && (set[i].ecart < p.ecart))
5376 || (( op == o) && (set[i].ecart == p.ecart)
5377 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5378 en=i;
5379 else
5380 an=i;
5381 }
5382}
5383
5384/*2
5385* looks up the position of p in set
5386* set[0] is the smallest with respect to the ordering-procedure
5387* pGetComp, pFDeg+ecart, ecart, pComp
5388*/
5389int posInT17_c (const TSet set,const int length,LObject &p)
5390{
5391 if (length==-1) return 0;
5392
5393 int cc = (-1+2*currRing->order[0]==ringorder_c);
5394 /* cc==1 for (c,..), cc==-1 for (C,..) */
5395 int o = p.GetpFDeg() + p.ecart;
5396 int c = pGetComp(p.p)*cc;
5397 int cmp_int=currRing->OrdSgn;
5398
5399 if (pGetComp(set[length].p)*cc < c)
5400 return length+1;
5401 if (pGetComp(set[length].p)*cc == c)
5402 {
5403 int op = set[length].GetpFDeg()+set[length].ecart;
5404 if ((op < o)
5405 || ((op == o) && (set[length].ecart > p.ecart))
5406 || ((op == o) && (set[length].ecart==p.ecart)
5407 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5408 return length+1;
5409 }
5410
5411 int i;
5412 int an = 0;
5413 int en= length;
5414 loop
5415 {
5416 if (an >= en-1)
5417 {
5418 if (pGetComp(set[an].p)*cc < c)
5419 return en;
5420 if (pGetComp(set[an].p)*cc == c)
5421 {
5422 int op = set[an].GetpFDeg()+set[an].ecart;
5423 if ((op > o)
5424 || ((op == o) && (set[an].ecart < p.ecart))
5425 || ((op == o) && (set[an].ecart==p.ecart)
5426 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5427 return an;
5428 }
5429 return en;
5430 }
5431 i=(an+en) / 2;
5432 if (pGetComp(set[i].p)*cc > c)
5433 en=i;
5434 else if (pGetComp(set[i].p)*cc == c)
5435 {
5436 int op = set[i].GetpFDeg()+set[i].ecart;
5437 if ((op > o)
5438 || ((op == o) && (set[i].ecart < p.ecart))
5439 || ((op == o) && (set[i].ecart == p.ecart)
5440 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5441 en=i;
5442 else
5443 an=i;
5444 }
5445 else
5446 an=i;
5447 }
5448}
5449
5450int posInT17_cRing (const TSet set,const int length,LObject &p)
5451{
5452 if (length==-1) return 0;
5453
5454 int cc = (-1+2*currRing->order[0]==ringorder_c);
5455 /* cc==1 for (c,..), cc==-1 for (C,..) */
5456 int o = p.GetpFDeg() + p.ecart;
5457 int c = pGetComp(p.p)*cc;
5458
5459 if (pGetComp(set[length].p)*cc < c)
5460 return length+1;
5461 if (pGetComp(set[length].p)*cc == c)
5462 {
5463 int op = set[length].GetpFDeg()+set[length].ecart;
5464 if ((op < o)
5465 || ((op == o) && (set[length].ecart > p.ecart))
5466 || ((op == o) && (set[length].ecart==p.ecart)
5467 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5468 return length+1;
5469 }
5470
5471 int i;
5472 int an = 0;
5473 int en= length;
5474 loop
5475 {
5476 if (an >= en-1)
5477 {
5478 if (pGetComp(set[an].p)*cc < c)
5479 return en;
5480 if (pGetComp(set[an].p)*cc == c)
5481 {
5482 int op = set[an].GetpFDeg()+set[an].ecart;
5483 if ((op > o)
5484 || ((op == o) && (set[an].ecart < p.ecart))
5485 || ((op == o) && (set[an].ecart==p.ecart)
5486 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5487 return an;
5488 }
5489 return en;
5490 }
5491 i=(an+en) / 2;
5492 if (pGetComp(set[i].p)*cc > c)
5493 en=i;
5494 else if (pGetComp(set[i].p)*cc == c)
5495 {
5496 int op = set[i].GetpFDeg()+set[i].ecart;
5497 if ((op > o)
5498 || ((op == o) && (set[i].ecart < p.ecart))
5499 || ((op == o) && (set[i].ecart == p.ecart)
5500 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5501 en=i;
5502 else
5503 an=i;
5504 }
5505 else
5506 an=i;
5507 }
5508}
5509
5510/*2
5511* looks up the position of p in set
5512* set[0] is the smallest with respect to
5513* ecart, pFDeg, length
5514*/
5515int posInT19 (const TSet set,const int length,LObject &p)
5516{
5517 p.GetpLength();
5518 if (length==-1) return 0;
5519
5520 int o = p.ecart;
5521 int op=p.GetpFDeg();
5522
5523 if (set[length].ecart < o)
5524 return length+1;
5525 if (set[length].ecart == o)
5526 {
5527 int oo=set[length].GetpFDeg();
5528 if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5529 return length+1;
5530 }
5531
5532 int i;
5533 int an = 0;
5534 int en= length;
5535 loop
5536 {
5537 if (an >= en-1)
5538 {
5539 if (set[an].ecart > o)
5540 return an;
5541 if (set[an].ecart == o)
5542 {
5543 int oo=set[an].GetpFDeg();
5544 if((oo > op)
5545 || ((oo==op) && (set[an].length > p.length)))
5546 return an;
5547 }
5548 return en;
5549 }
5550 i=(an+en) / 2;
5551 if (set[i].ecart > o)
5552 en=i;
5553 else if (set[i].ecart == o)
5554 {
5555 int oo=set[i].GetpFDeg();
5556 if ((oo > op)
5557 || ((oo == op) && (set[i].length > p.length)))
5558 en=i;
5559 else
5560 an=i;
5561 }
5562 else
5563 an=i;
5564 }
5565}
5566
5567/*2
5568*looks up the position of polynomial p in set
5569*set[length] is the smallest element in set with respect
5570*to the ordering-procedure pComp
5571*/
5572int posInLSpecial (const LSet set, const int length,
5573 LObject *p,const kStrategy)
5574{
5575 if (length<0) return 0;
5576
5577 int d=p->GetpFDeg();
5578 int op=set[length].GetpFDeg();
5579 int cmp_int=currRing->OrdSgn;
5580
5581 if ((op > d)
5582 || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
5583 || (pLmCmp(set[length].p,p->p)== cmp_int))
5584 return length+1;
5585
5586 int i;
5587 int an = 0;
5588 int en= length;
5589 loop
5590 {
5591 if (an >= en-1)
5592 {
5593 op=set[an].GetpFDeg();
5594 if ((op > d)
5595 || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
5596 || (pLmCmp(set[an].p,p->p)== cmp_int))
5597 return en;
5598 return an;
5599 }
5600 i=(an+en) / 2;
5601 op=set[i].GetpFDeg();
5602 if ((op>d)
5603 || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
5604 || (pLmCmp(set[i].p,p->p) == cmp_int))
5605 an=i;
5606 else
5607 en=i;
5608 }
5609}
5610
5611/*2
5612*looks up the position of polynomial p in set
5613*set[length] is the smallest element in set with respect
5614*to the ordering-procedure pComp
5615*/
5616int posInL0 (const LSet set, const int length,
5617 LObject* p,const kStrategy)
5618{
5619 if (length<0) return 0;
5620
5621 int cmp_int=currRing->OrdSgn;
5622
5623 if (pLmCmp(set[length].p,p->p)== cmp_int)
5624 return length+1;
5625
5626 int i;
5627 int an = 0;
5628 int en= length;
5629 loop
5630 {
5631 if (an >= en-1)
5632 {
5633 if (pLmCmp(set[an].p,p->p) == cmp_int) return en;
5634 return an;
5635 }
5636 i=(an+en) / 2;
5637 if (pLmCmp(set[i].p,p->p) == cmp_int) an=i;
5638 else en=i;
5639 /*aend. fuer lazy == in !=- machen */
5640 }
5641}
5642
5643int posInL0Ring (const LSet set, const int length,
5644 LObject* p,const kStrategy)
5645{
5646 if (length<0) return 0;
5647
5648 if (pLtCmpOrdSgnEqP(set[length].p,p->p))
5649 return length+1;
5650
5651 int i;
5652 int an = 0;
5653 int en= length;
5654 loop
5655 {
5656 if (an >= en-1)
5657 {
5658 if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
5659 return an;
5660 }
5661 i=(an+en) / 2;
5662 if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
5663 else en=i;
5664 /*aend. fuer lazy == in !=- machen */
5665 }
5666}
5667
5668/*2
5669* looks up the position of polynomial p in set
5670* e is the ecart of p
5671* set[length] is the smallest element in set with respect
5672* to the signature order
5673*/
5674int posInLSig (const LSet set, const int length,
5675 LObject* p,const kStrategy /*strat*/)
5676{
5677 if (length<0) return 0;
5678 int cmp_int=currRing->OrdSgn;
5679 if (pLtCmp(set[length].sig,p->sig)==cmp_int)
5680 return length+1;
5681
5682 int i;
5683 int an = 0;
5684 int en= length;
5685 loop
5686 {
5687 if (an >= en-1)
5688 {
5689 if (pLtCmp(set[an].sig,p->sig) == cmp_int) return en;
5690 return an;
5691 }
5692 i=(an+en) / 2;
5693 if (pLtCmp(set[i].sig,p->sig) == cmp_int) an=i;
5694 else en=i;
5695 /*aend. fuer lazy == in !=- machen */
5696 }
5697}
5698//sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
5699int posInLSigRing (const LSet set, const int length,
5700 LObject* p,const kStrategy /*strat*/)
5701{
5702 assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
5703 if (length<0) return 0;
5704 if (pLtCmp(set[length].sig,p->sig)== 1)
5705 return length+1;
5706
5707 int an,en,i;
5708 an = 0;
5709 en = length+1;
5710 int cmp;
5711 loop
5712 {
5713 if (an >= en-1)
5714 {
5715 if(an == en)
5716 return en;
5717 cmp = pLtCmp(set[an].sig,p->sig);
5718 if (cmp == 1)
5719 return en;
5720 if (cmp == -1)
5721 return an;
5722 if (cmp == 0)
5723 {
5724 if (set[an].FDeg > p->FDeg)
5725 return en;
5726 if (set[an].FDeg < p->FDeg)
5727 return an;
5728 if (set[an].FDeg == p->FDeg)
5729 {
5730 cmp = pLtCmp(set[an].p,p->p);
5731 if(cmp == 1)
5732 return en;
5733 else
5734 return an;
5735 }
5736 }
5737 }
5738 i=(an+en) / 2;
5739 cmp = pLtCmp(set[i].sig,p->sig);
5740 if (cmp == 1)
5741 an = i;
5742 if (cmp == -1)
5743 en = i;
5744 if (cmp == 0)
5745 {
5746 if (set[i].FDeg > p->FDeg)
5747 an = i;
5748 if (set[i].FDeg < p->FDeg)
5749 en = i;
5750 if (set[i].FDeg == p->FDeg)
5751 {
5752 cmp = pLtCmp(set[i].p,p->p);
5753 if(cmp == 1)
5754 an = i;
5755 else
5756 en = i;
5757 }
5758 }
5759 }
5760}
5761
5762// for sba, sorting syzygies
5763int posInSyz (const kStrategy strat, poly sig)
5764{
5765 if (strat->syzl==0) return 0;
5766 int cmp_int=currRing->OrdSgn;
5767 if (pLtCmp(strat->syz[strat->syzl-1],sig) != cmp_int)
5768 return strat->syzl;
5769 int i;
5770 int an = 0;
5771 int en= strat->syzl-1;
5772 loop
5773 {
5774 if (an >= en-1)
5775 {
5776 if (pLtCmp(strat->syz[an],sig) != cmp_int) return en;
5777 return an;
5778 }
5779 i=(an+en) / 2;
5780 if (pLtCmp(strat->syz[i],sig) != cmp_int) an=i;
5781 else en=i;
5782 /*aend. fuer lazy == in !=- machen */
5783 }
5784}
5785
5786/*2
5787*
5788* is only used in F5C, must ensure that the interreduction process does add new
5789* critical pairs to strat->L only behind all other critical pairs which are
5790* still in strat->L!
5791*/
5792int posInLF5C (const LSet /*set*/, const int /*length*/,
5793 LObject* /*p*/,const kStrategy strat)
5794{
5795 return strat->Ll+1;
5796}
5797
5798/*2
5799* looks up the position of polynomial p in set
5800* e is the ecart of p
5801* set[length] is the smallest element in set with respect
5802* to the ordering-procedure totaldegree,pComp
5803*/
5804int posInL11 (const LSet set, const int length,
5805 LObject* p,const kStrategy)
5806{
5807 if (length<0) return 0;
5808
5809 int o = p->GetpFDeg();
5810 int op = set[length].GetpFDeg();
5811 int cmp_int= -currRing->OrdSgn;
5812
5813 if ((op > o)
5814 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
5815 return length+1;
5816 int i;
5817 int an = 0;
5818 int en= length;
5819 loop
5820 {
5821 if (an >= en-1)
5822 {
5823 op = set[an].GetpFDeg();
5824 if ((op > o)
5825 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
5826 return en;
5827 return an;
5828 }
5829 i=(an+en) / 2;
5830 op = set[i].GetpFDeg();
5831 if ((op > o)
5832 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
5833 an=i;
5834 else
5835 en=i;
5836 }
5837}
5838
5839/*2
5840* looks up the position of polynomial p in set
5841* set[length] is the smallest element in set with respect
5842* to the ordering-procedure pLmCmp,totaldegree,coefficient
5843* For the same totaldegree, original pairs (from F) will
5844* be put at the end and smallest coefficients
5845*/
5846int posInL11Ring (const LSet set, const int length,
5847 LObject* p,const kStrategy)
5848{
5849 if (length<0) return 0;
5850
5851 int o = p->GetpFDeg();
5852 int op = set[length].GetpFDeg();
5853
5854 if ((op > o)
5855 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5856 return length+1;
5857 int i;
5858 int an = 0;
5859 int en= length;
5860 loop
5861 {
5862 if (an >= en-1)
5863 {
5864 op = set[an].GetpFDeg();
5865 if ((op > o)
5866 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5867 return en;
5868 return an;
5869 }
5870 i=(an+en) / 2;
5871 op = set[i].GetpFDeg();
5872 if ((op > o)
5873 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5874 an=i;
5875 else
5876 en=i;
5877 }
5878}
5879
5880int posInLF5CRing (const LSet set, int start,const int length,
5881 LObject* p,const kStrategy)
5882{
5883 if (length<0) return 0;
5884 if(start == (length +1)) return (length+1);
5885 int o = p->GetpFDeg();
5886 int op = set[length].GetpFDeg();
5887
5888 if ((op > o)
5889 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5890 return length+1;
5891 int i;
5892 int an = start;
5893 int en= length;
5894 loop
5895 {
5896 if (an >= en-1)
5897 {
5898 op = set[an].GetpFDeg();
5899 if ((op > o)
5900 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5901 return en;
5902 return an;
5903 }
5904 i=(an+en) / 2;
5905 op = set[i].GetpFDeg();
5906 if ((op > o)
5907 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5908 an=i;
5909 else
5910 en=i;
5911 }
5912}
5913
5914int posInL11Ringls (const LSet set, const int length,
5915 LObject* p,const kStrategy)
5916{
5917 if (length < 0) return 0;
5918 int an,en,i;
5919 an = 0;
5920 en = length+1;
5921 loop
5922 {
5923 if (an >= en-1)
5924 {
5925 if(an == en)
5926 return en;
5927 if (set[an].FDeg > p->FDeg)
5928 return en;
5929 if (set[an].FDeg < p->FDeg)
5930 return an;
5931 if (set[an].FDeg == p->FDeg)
5932 {
5933 number lcset,lcp;
5934 lcset = pGetCoeff(set[an].p);
5935 lcp = pGetCoeff(p->p);
5936 if(!nGreaterZero(lcset))
5937 {
5938 set[an].p=p_Neg(set[an].p,currRing);
5939 if (set[an].t_p!=NULL)
5940 pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
5941 lcset=pGetCoeff(set[an].p);
5942 }
5943 if(!nGreaterZero(lcp))
5944 {
5945 p->p=p_Neg(p->p,currRing);
5946 if (p->t_p!=NULL)
5947 pSetCoeff0(p->t_p,pGetCoeff(p->p));
5948 lcp=pGetCoeff(p->p);
5949 }
5950 if(nGreater(lcset, lcp))
5951 {
5952 return en;
5953 }
5954 else
5955 {
5956 return an;
5957 }
5958 }
5959 }
5960 i=(an+en) / 2;
5961 if (set[i].FDeg > p->FDeg)
5962 an=i;
5963 if (set[i].FDeg < p->FDeg)
5964 en=i;
5965 if (set[i].FDeg == p->FDeg)
5966 {
5967 number lcset,lcp;
5968 lcset = pGetCoeff(set[i].p);
5969 lcp = pGetCoeff(p->p);
5970 if(!nGreaterZero(lcset))
5971 {
5972 set[i].p=p_Neg(set[i].p,currRing);
5973 if (set[i].t_p!=NULL)
5974 pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
5975 lcset=pGetCoeff(set[i].p);
5976 }
5977 if(!nGreaterZero(lcp))
5978 {
5979 p->p=p_Neg(p->p,currRing);
5980 if (p->t_p!=NULL)
5981 pSetCoeff0(p->t_p,pGetCoeff(p->p));
5982 lcp=pGetCoeff(p->p);
5983 }
5984 if(nGreater(lcset, lcp))
5985 {
5986 an = i;
5987 }
5988 else
5989 {
5990 en = i;
5991 }
5992 }
5993 }
5994}
5995
5996/*2 Position for rings L: Here I am
5997* looks up the position of polynomial p in set
5998* e is the ecart of p
5999* set[length] is the smallest element in set with respect
6000* to the ordering-procedure totaldegree,pComp
6001*/
6002inline int getIndexRng(long coeff)
6003{
6004 if (coeff == 0) return -1;
6005 long tmp = coeff;
6006 int ind = 0;
6007 while (tmp % 2 == 0)
6008 {
6009 tmp = tmp / 2;
6010 ind++;
6011 }
6012 return ind;
6013}
6014
6015/*{
6016 if (length < 0) return 0;
6017
6018 int o = p->GetpFDeg();
6019 int op = set[length].GetpFDeg();
6020
6021 int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6022 int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6023 int inda;
6024 int indi;
6025
6026 if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6027 return length + 1;
6028 int i;
6029 int an = 0;
6030 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6031 int en = length;
6032 loop
6033 {
6034 if (an >= en-1)
6035 {
6036 op = set[an].GetpFDeg();
6037 if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6038 return en;
6039 return an;
6040 }
6041 i = (an + en) / 2;
6042 indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6043 op = set[i].GetpFDeg();
6044 if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6045 // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6046 {
6047 an = i;
6048 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6049 }
6050 else
6051 en = i;
6052 }
6053} */
6054
6055/*2
6056* looks up the position of polynomial p in set
6057* set[length] is the smallest element in set with respect
6058* to the ordering-procedure totaldegree,pLength0
6059*/
6060int posInL110 (const LSet set, const int length,
6061 LObject* p,const kStrategy)
6062{
6063 if (length<0) return 0;
6064
6065 int o = p->GetpFDeg();
6066 int op = set[length].GetpFDeg();
6067 int cmp_int= -currRing->OrdSgn;
6068
6069 if ((op > o)
6070 || ((op == o) && (set[length].length >p->length))
6071 || ((op == o) && (set[length].length <= p->length)
6072 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6073 return length+1;
6074 int i;
6075 int an = 0;
6076 int en= length;
6077 loop
6078 {
6079 if (an >= en-1)
6080 {
6081 op = set[an].GetpFDeg();
6082 if ((op > o)
6083 || ((op == o) && (set[an].length >p->length))
6084 || ((op == o) && (set[an].length <=p->length)
6085 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6086 return en;
6087 return an;
6088 }
6089 i=(an+en) / 2;
6090 op = set[i].GetpFDeg();
6091 if ((op > o)
6092 || ((op == o) && (set[i].length > p->length))
6093 || ((op == o) && (set[i].length <= p->length)
6094 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6095 an=i;
6096 else
6097 en=i;
6098 }
6099}
6100
6101int posInL110Ring (const LSet set, const int length,
6102 LObject* p,const kStrategy)
6103{
6104 if (length<0) return 0;
6105
6106 int o = p->GetpFDeg();
6107 int op = set[length].GetpFDeg();
6108
6109 if ((op > o)
6110 || ((op == o) && (set[length].length >p->length))
6111 || ((op == o) && (set[length].length <= p->length)
6112 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6113 return length+1;
6114 int i;
6115 int an = 0;
6116 int en= length;
6117 loop
6118 {
6119 if (an >= en-1)
6120 {
6121 op = set[an].GetpFDeg();
6122 if ((op > o)
6123 || ((op == o) && (set[an].length >p->length))
6124 || ((op == o) && (set[an].length <=p->length)
6125 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6126 return en;
6127 return an;
6128 }
6129 i=(an+en) / 2;
6130 op = set[i].GetpFDeg();
6131 if ((op > o)
6132 || ((op == o) && (set[i].length > p->length))
6133 || ((op == o) && (set[i].length <= p->length)
6134 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6135 an=i;
6136 else
6137 en=i;
6138 }
6139}
6140
6141/*2
6142* looks up the position of polynomial p in set
6143* e is the ecart of p
6144* set[length] is the smallest element in set with respect
6145* to the ordering-procedure totaldegree
6146*/
6147int posInL13 (const LSet set, const int length,
6148 LObject* p,const kStrategy)
6149{
6150 if (length<0) return 0;
6151
6152 int o = p->GetpFDeg();
6153
6154 if (set[length].GetpFDeg() > o)
6155 return length+1;
6156
6157 int i;
6158 int an = 0;
6159 int en= length;
6160 loop
6161 {
6162 if (an >= en-1)
6163 {
6164 if (set[an].GetpFDeg() >= o)
6165 return en;
6166 return an;
6167 }
6168 i=(an+en) / 2;
6169 if (set[i].GetpFDeg() >= o)
6170 an=i;
6171 else
6172 en=i;
6173 }
6174}
6175
6176/*2
6177* looks up the position of polynomial p in set
6178* e is the ecart of p
6179* set[length] is the smallest element in set with respect
6180* to the ordering-procedure maximaldegree,pComp
6181*/
6182int posInL15 (const LSet set, const int length,
6183 LObject* p,const kStrategy)
6184{
6185 if (length<0) return 0;
6186
6187 int o = p->GetpFDeg() + p->ecart;
6188 int op = set[length].GetpFDeg() + set[length].ecart;
6189 int cmp_int= -currRing->OrdSgn;
6190
6191 if ((op > o)
6192 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
6193 return length+1;
6194 int i;
6195 int an = 0;
6196 int en= length;
6197 loop
6198 {
6199 if (an >= en-1)
6200 {
6201 op = set[an].GetpFDeg() + set[an].ecart;
6202 if ((op > o)
6203 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
6204 return en;
6205 return an;
6206 }
6207 i=(an+en) / 2;
6208 op = set[i].GetpFDeg() + set[i].ecart;
6209 if ((op > o)
6210 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
6211 an=i;
6212 else
6213 en=i;
6214 }
6215}
6216
6217int posInL15Ring (const LSet set, const int length,
6218 LObject* p,const kStrategy)
6219{
6220 if (length<0) return 0;
6221
6222 int o = p->GetpFDeg() + p->ecart;
6223 int op = set[length].GetpFDeg() + set[length].ecart;
6224
6225 if ((op > o)
6226 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
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) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
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) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6245 an=i;
6246 else
6247 en=i;
6248 }
6249}
6250
6251/*2
6252* looks up the position of polynomial p in set
6253* e is the ecart of p
6254* set[length] is the smallest element in set with respect
6255* to the ordering-procedure totaldegree
6256*/
6257int posInL17 (const LSet set, const int length,
6258 LObject* p,const kStrategy)
6259{
6260 if (length<0) return 0;
6261
6262 int o = p->GetpFDeg() + p->ecart;
6263 int cmp_int= -currRing->OrdSgn;
6264
6265 if ((set[length].GetpFDeg() + set[length].ecart > o)
6266 || ((set[length].GetpFDeg() + set[length].ecart == o)
6267 && (set[length].ecart > p->ecart))
6268 || ((set[length].GetpFDeg() + set[length].ecart == o)
6269 && (set[length].ecart == p->ecart)
6270 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6271 return length+1;
6272 int i;
6273 int an = 0;
6274 int en= length;
6275 loop
6276 {
6277 if (an >= en-1)
6278 {
6279 if ((set[an].GetpFDeg() + set[an].ecart > o)
6280 || ((set[an].GetpFDeg() + set[an].ecart == o)
6281 && (set[an].ecart > p->ecart))
6282 || ((set[an].GetpFDeg() + set[an].ecart == o)
6283 && (set[an].ecart == p->ecart)
6284 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6285 return en;
6286 return an;
6287 }
6288 i=(an+en) / 2;
6289 if ((set[i].GetpFDeg() + set[i].ecart > o)
6290 || ((set[i].GetpFDeg() + set[i].ecart == o)
6291 && (set[i].ecart > p->ecart))
6292 || ((set[i].GetpFDeg() +set[i].ecart == o)
6293 && (set[i].ecart == p->ecart)
6294 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6295 an=i;
6296 else
6297 en=i;
6298 }
6299}
6300
6301int posInL17Ring (const LSet set, const int length,
6302 LObject* p,const kStrategy)
6303{
6304 if (length<0) return 0;
6305
6306 int o = p->GetpFDeg() + p->ecart;
6307
6308 if ((set[length].GetpFDeg() + set[length].ecart > o)
6309 || ((set[length].GetpFDeg() + set[length].ecart == o)
6310 && (set[length].ecart > p->ecart))
6311 || ((set[length].GetpFDeg() + set[length].ecart == o)
6312 && (set[length].ecart == p->ecart)
6313 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6314 return length+1;
6315 int i;
6316 int an = 0;
6317 int en= length;
6318 loop
6319 {
6320 if (an >= en-1)
6321 {
6322 if ((set[an].GetpFDeg() + set[an].ecart > o)
6323 || ((set[an].GetpFDeg() + set[an].ecart == o)
6324 && (set[an].ecart > p->ecart))
6325 || ((set[an].GetpFDeg() + set[an].ecart == o)
6326 && (set[an].ecart == p->ecart)
6327 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6328 return en;
6329 return an;
6330 }
6331 i=(an+en) / 2;
6332 if ((set[i].GetpFDeg() + set[i].ecart > o)
6333 || ((set[i].GetpFDeg() + set[i].ecart == o)
6334 && (set[i].ecart > p->ecart))
6335 || ((set[i].GetpFDeg() +set[i].ecart == o)
6336 && (set[i].ecart == p->ecart)
6337 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6338 an=i;
6339 else
6340 en=i;
6341 }
6342}
6343
6344/*2
6345* looks up the position of polynomial p in set
6346* e is the ecart of p
6347* set[length] is the smallest element in set with respect
6348* to the ordering-procedure pComp
6349*/
6350int posInL17_c (const LSet set, const int length,
6351 LObject* p,const kStrategy)
6352{
6353 if (length<0) return 0;
6354
6355 int cc = (-1+2*currRing->order[0]==ringorder_c);
6356 /* cc==1 for (c,..), cc==-1 for (C,..) */
6357 long c = pGetComp(p->p)*cc;
6358 int o = p->GetpFDeg() + p->ecart;
6359 int cmp_int= -currRing->OrdSgn;
6360
6361 if (pGetComp(set[length].p)*cc > c)
6362 return length+1;
6363 if (pGetComp(set[length].p)*cc == c)
6364 {
6365 if ((set[length].GetpFDeg() + set[length].ecart > o)
6366 || ((set[length].GetpFDeg() + set[length].ecart == o)
6367 && (set[length].ecart > p->ecart))
6368 || ((set[length].GetpFDeg() + set[length].ecart == o)
6369 && (set[length].ecart == p->ecart)
6370 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6371 return length+1;
6372 }
6373 int i;
6374 int an = 0;
6375 int en= length;
6376 loop
6377 {
6378 if (an >= en-1)
6379 {
6380 if (pGetComp(set[an].p)*cc > c)
6381 return en;
6382 if (pGetComp(set[an].p)*cc == c)
6383 {
6384 if ((set[an].GetpFDeg() + set[an].ecart > o)
6385 || ((set[an].GetpFDeg() + set[an].ecart == o)
6386 && (set[an].ecart > p->ecart))
6387 || ((set[an].GetpFDeg() + set[an].ecart == o)
6388 && (set[an].ecart == p->ecart)
6389 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6390 return en;
6391 }
6392 return an;
6393 }
6394 i=(an+en) / 2;
6395 if (pGetComp(set[i].p)*cc > c)
6396 an=i;
6397 else if (pGetComp(set[i].p)*cc == c)
6398 {
6399 if ((set[i].GetpFDeg() + set[i].ecart > o)
6400 || ((set[i].GetpFDeg() + set[i].ecart == o)
6401 && (set[i].ecart > p->ecart))
6402 || ((set[i].GetpFDeg() +set[i].ecart == o)
6403 && (set[i].ecart == p->ecart)
6404 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6405 an=i;
6406 else
6407 en=i;
6408 }
6409 else
6410 en=i;
6411 }
6412}
6413
6414int posInL17_cRing (const LSet set, const int length,
6415 LObject* p,const kStrategy)
6416{
6417 if (length<0) return 0;
6418
6419 int cc = (-1+2*currRing->order[0]==ringorder_c);
6420 /* cc==1 for (c,..), cc==-1 for (C,..) */
6421 long c = pGetComp(p->p)*cc;
6422 int o = p->GetpFDeg() + p->ecart;
6423
6424 if (pGetComp(set[length].p)*cc > c)
6425 return length+1;
6426 if (pGetComp(set[length].p)*cc == c)
6427 {
6428 if ((set[length].GetpFDeg() + set[length].ecart > o)
6429 || ((set[length].GetpFDeg() + set[length].ecart == o)
6430 && (set[length].ecart > p->ecart))
6431 || ((set[length].GetpFDeg() + set[length].ecart == o)
6432 && (set[length].ecart == p->ecart)
6433 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6434 return length+1;
6435 }
6436 int i;
6437 int an = 0;
6438 int en= length;
6439 loop
6440 {
6441 if (an >= en-1)
6442 {
6443 if (pGetComp(set[an].p)*cc > c)
6444 return en;
6445 if (pGetComp(set[an].p)*cc == c)
6446 {
6447 if ((set[an].GetpFDeg() + set[an].ecart > o)
6448 || ((set[an].GetpFDeg() + set[an].ecart == o)
6449 && (set[an].ecart > p->ecart))
6450 || ((set[an].GetpFDeg() + set[an].ecart == o)
6451 && (set[an].ecart == p->ecart)
6452 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6453 return en;
6454 }
6455 return an;
6456 }
6457 i=(an+en) / 2;
6458 if (pGetComp(set[i].p)*cc > c)
6459 an=i;
6460 else if (pGetComp(set[i].p)*cc == c)
6461 {
6462 if ((set[i].GetpFDeg() + set[i].ecart > o)
6463 || ((set[i].GetpFDeg() + set[i].ecart == o)
6464 && (set[i].ecart > p->ecart))
6465 || ((set[i].GetpFDeg() +set[i].ecart == o)
6466 && (set[i].ecart == p->ecart)
6467 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6468 an=i;
6469 else
6470 en=i;
6471 }
6472 else
6473 en=i;
6474 }
6475}
6476
6477/*
6478 * SYZYGY CRITERION for signature-based standard basis algorithms
6479 */
6480BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6481{
6482//#if 1
6483#ifdef DEBUGF5
6484 PrintS("syzygy criterion checks: ");
6485 pWrite(sig);
6486#endif
6487 for (int k=0; k<strat->syzl; k++)
6488 {
6489 //printf("-%d",k);
6490//#if 1
6491#ifdef DEBUGF5
6492 Print("checking with: %d / %d -- \n",k,strat->syzl);
6493 pWrite(pHead(strat->syz[k]));
6494#endif
6495 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6496 && (!rField_is_Ring(currRing) ||
6497 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6498 {
6499//#if 1
6500#ifdef DEBUGF5
6501 PrintS("DELETE!\n");
6502#endif
6503 strat->nrsyzcrit++;
6504 //printf("- T -\n\n");
6505 return TRUE;
6506 }
6507 }
6508 //printf("- F -\n\n");
6509 return FALSE;
6510}
6511
6512/*
6513 * SYZYGY CRITERION for signature-based standard basis algorithms
6514 */
6515BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6516{
6517//#if 1
6518 if(sig == NULL)
6519 return FALSE;
6520#ifdef DEBUGF5
6521 PrintS("--- syzygy criterion checks: ");
6522 pWrite(sig);
6523#endif
6524 int comp = (int)__p_GetComp(sig, currRing);
6525 int min, max;
6526 if (comp<=1)
6527 return FALSE;
6528 else
6529 {
6530 min = strat->syzIdx[comp-2];
6531 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
6532 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
6533 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
6534 if (comp == strat->currIdx)
6535 {
6536 max = strat->syzl;
6537 }
6538 else
6539 {
6540 max = strat->syzIdx[comp-1];
6541 }
6542 for (int k=min; k<max; k++)
6543 {
6544#ifdef F5DEBUG
6545 Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
6546 Print("checking with: %d -- ",k);
6547 pWrite(pHead(strat->syz[k]));
6548#endif
6549 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6550 && (!rField_is_Ring(currRing) ||
6551 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6552 {
6553 strat->nrsyzcrit++;
6554 return TRUE;
6555 }
6556 }
6557 return FALSE;
6558 }
6559}
6560
6561/*
6562 * REWRITTEN CRITERION for signature-based standard basis algorithms
6563 */
6564BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
6565{
6566 //printf("Faugere Rewritten Criterion\n");
6568 return FALSE;
6569//#if 1
6570#ifdef DEBUGF5
6571 PrintS("rewritten criterion checks: ");
6572 pWrite(sig);
6573#endif
6574 for(int k = strat->sl; k>=start; k--)
6575 {
6576//#if 1
6577#ifdef DEBUGF5
6578 PrintS("checking with: ");
6579 pWrite(strat->sig[k]);
6580 pWrite(pHead(strat->S[k]));
6581#endif
6582 if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
6583 {
6584//#if 1
6585#ifdef DEBUGF5
6586 PrintS("DELETE!\n");
6587#endif
6588 strat->nrrewcrit++;
6589 return TRUE;
6590 }
6591 //k--;
6592 }
6593#ifdef DEBUGF5
6594 PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
6595 for(int kk = 0; kk<strat->sl+1; kk++)
6596 {
6597 pWrite(pHead(strat->S[kk]));
6598 }
6599 PrintS("------------------------------\n");
6600#endif
6601 return FALSE;
6602}
6603
6604/*
6605 * REWRITTEN CRITERION for signature-based standard basis algorithms
6606 ***************************************************************************
6607 * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
6608 ***************************************************************************
6609 */
6610
6611// real implementation of arri's rewritten criterion, only called once in
6612// kstd2.cc, right before starting reduction
6613// IDEA: Arri says that it is enough to consider 1 polynomial for each unique
6614// signature appearing during the computations. Thus we first of all go
6615// through strat->L and delete all other pairs of the same signature,
6616// keeping only the one with least possible leading monomial. After this
6617// we check if we really need to compute this critical pair at all: There
6618// can be elements already in strat->S whose signatures divide the
6619// signature of the critical pair in question and whose multiplied
6620// leading monomials are smaller than the leading monomial of the
6621// critical pair. In this situation we can discard the critical pair
6622// completely.
6623BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
6624{
6626 return FALSE;
6627 poly p1 = pOne();
6628 poly p2 = pOne();
6629 for (int ii=strat->sl; ii>start; ii--)
6630 {
6631 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
6632 {
6633 p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
6634 p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
6635 if (!(pLmCmp(p1,p2) == 1))
6636 {
6637 pDelete(&p1);
6638 pDelete(&p2);
6639 return TRUE;
6640 }
6641 }
6642 }
6643 pDelete(&p1);
6644 pDelete(&p2);
6645 return FALSE;
6646}
6647
6648BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
6649{
6650 //Over Rings, there are still some changes to do: considering coeffs
6652 return FALSE;
6653 int found = -1;
6654 for (int i=strat->Bl; i>-1; i--)
6655 {
6656 if (pLmEqual(strat->B[i].sig,sig))
6657 {
6658 found = i;
6659 break;
6660 }
6661 }
6662 if (found != -1)
6663 {
6664 if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
6665 {
6666 deleteInL(strat->B,&strat->Bl,found,strat);
6667 }
6668 else
6669 {
6670 return TRUE;
6671 }
6672 }
6673 poly p1 = pOne();
6674 poly p2 = pOne();
6675 for (int ii=strat->sl; ii>-1; ii--)
6676 {
6677 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
6678 {
6679 p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
6680 p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
6681 if (!(pLmCmp(p1,p2) == 1))
6682 {
6683 pDelete(&p1);
6684 pDelete(&p2);
6685 return TRUE;
6686 }
6687 }
6688 }
6689 pDelete(&p1);
6690 pDelete(&p2);
6691 return FALSE;
6692}
6693
6694/***************************************************************
6695 *
6696 * Tail reductions
6697 *
6698 ***************************************************************/
6699TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
6700{
6701 int j = 0;
6702 const unsigned long not_sev = ~L->sev;
6703 const unsigned long* sev = strat->sevS;
6704 poly p;
6705 ring r;
6706 L->GetLm(p, r);
6707
6708 assume(~not_sev == p_GetShortExpVector(p, r));
6709
6710 if (r == currRing)
6711 {
6712 if(!rField_is_Ring(r))
6713 {
6714 loop
6715 {
6716 if (j > end_pos) return NULL;
6717 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6718 if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
6719 (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6720 #else
6721 if (!(sev[j] & not_sev) &&
6722 (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
6723 p_LmDivisibleBy(strat->S[j], p, r))
6724 #endif
6725 {
6726 break;
6727 }
6728 j++;
6729 }
6730 }
6731 else
6732 {
6733 loop
6734 {
6735 if (j > end_pos) return NULL;
6736 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6737 if (strat->S[j]!= NULL
6738 && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r)
6739 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6740 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6741 #else
6742 if (!(sev[j] & not_sev)
6743 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6744 && p_LmDivisibleBy(strat->S[j], p, r)
6745 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6746 #endif
6747 {
6748 break; // found
6749 }
6750 j++;
6751 }
6752 }
6753 // if called from NF, T objects do not exist:
6754 if (strat->tl < 0 || strat->S_2_R[j] == -1)
6755 {
6756 T->Set(strat->S[j], r, strat->tailRing);
6757 assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
6758 return T;
6759 }
6760 else
6761 {
6762///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
6763///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
6764// assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
6765 return strat->S_2_T(j);
6766 }
6767 }
6768 else
6769 {
6770 TObject* t;
6771 if(!rField_is_Ring(r))
6772 {
6773 loop
6774 {
6775 if (j > end_pos) return NULL;
6776 assume(strat->S_2_R[j] != -1);
6777 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6778 t = strat->S_2_T(j);
6779 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6780 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6781 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6782 {
6783 t->pLength=pLength(t->t_p);
6784 return t;
6785 }
6786 #else
6787 if (! (sev[j] & not_sev)
6788 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6789 {
6790 t = strat->S_2_T(j);
6791 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6792 if (p_LmDivisibleBy(t->t_p, p, r))
6793 {
6794 t->pLength=pLength(t->t_p);
6795 return t;
6796 }
6797 }
6798 #endif
6799 j++;
6800 }
6801 }
6802 else
6803 {
6804 loop
6805 {
6806 if (j > end_pos) return NULL;
6807 assume(strat->S_2_R[j] != -1);
6808 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6809 t = strat->S_2_T(j);
6810 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6811 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6812 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6813 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6814 {
6815 t->pLength=pLength(t->t_p);
6816 return t;
6817 }
6818 #else
6819 if (! (sev[j] & not_sev)
6820 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6821 {
6822 t = strat->S_2_T(j);
6823 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6824 if (p_LmDivisibleBy(t->t_p, p, r)
6825 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6826 {
6827 t->pLength=pLength(t->t_p);
6828 return t;
6829 }
6830 }
6831 #endif
6832 j++;
6833 }
6834 }
6835 }
6836}
6837
6838poly redtail (LObject* L, int end_pos, kStrategy strat)
6839{
6840 poly h, hn;
6841 strat->redTailChange=FALSE;
6842
6843 L->GetP();
6844 poly p = L->p;
6845 if (strat->noTailReduction || pNext(p) == NULL)
6846 return p;
6847
6848 LObject Ln(strat->tailRing);
6849 TObject* With;
6850 // placeholder in case strat->tl < 0
6851 TObject With_s(strat->tailRing);
6852 h = p;
6853 hn = pNext(h);
6854 long op = strat->tailRing->pFDeg(hn, strat->tailRing);
6855 long e;
6856 int l;
6857 BOOLEAN save_HE=strat->kAllAxis;
6858 strat->kAllAxis |=
6859 ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
6860
6861 while(hn != NULL)
6862 {
6863 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6864 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6865 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6866 loop
6867 {
6868 Ln.Set(hn, strat->tailRing);
6869 Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
6870 if (strat->kAllAxis)
6871 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
6872 else
6873 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
6874 if (With == NULL) break;
6875 With->length=0;
6876 With->pLength=0;
6877 strat->redTailChange=TRUE;
6878 if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
6879 {
6880 strat->kAllAxis = save_HE;
6881 // reducing the tail would violate the exp bound
6882 if (kStratChangeTailRing(strat, L))
6883 {
6884 return redtail(L, end_pos, strat);
6885 }
6886 else
6887 return NULL;
6888 }
6889 hn = pNext(h);
6890 if (hn == NULL) goto all_done;
6891 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6892 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6893 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6894 }
6895 h = hn;
6896 hn = pNext(h);
6897 }
6898
6899 all_done:
6900 if (strat->redTailChange)
6901 {
6902 L->pLength = 0;
6903 }
6904 strat->kAllAxis = save_HE;
6905 return p;
6906}
6907
6908poly redtail (poly p, int end_pos, kStrategy strat)
6909{
6910 LObject L(p, currRing);
6911 return redtail(&L, end_pos, strat);
6912}
6913
6914poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
6915{
6916 strat->redTailChange=FALSE;
6917 if (strat->noTailReduction) return L->GetLmCurrRing();
6918 poly h, p;
6919 p = h = L->GetLmTailRing();
6920 if ((h==NULL) || (pNext(h)==NULL))
6921 return L->GetLmCurrRing();
6922
6923 TObject* With;
6924 // placeholder in case strat->tl < 0
6925 TObject With_s(strat->tailRing);
6926
6927 LObject Ln(pNext(h), strat->tailRing);
6928 Ln.GetpLength();
6929
6930 pNext(h) = NULL;
6931 if (L->p != NULL)
6932 {
6933 pNext(L->p) = NULL;
6934 if (L->t_p != NULL) pNext(L->t_p) = NULL;
6935 }
6936 L->pLength = 1;
6937
6938 Ln.PrepareRed(strat->use_buckets);
6939
6940 int cnt=REDTAIL_CANONICALIZE;
6941 while(!Ln.IsNull())
6942 {
6943 loop
6944 {
6945 if (TEST_OPT_IDLIFT)
6946 {
6947 if (Ln.p!=NULL)
6948 {
6949 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
6950 }
6951 else
6952 {
6953 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
6954 }
6955 }
6956 Ln.SetShortExpVector();
6957 if (withT)
6958 {
6959 int j;
6960 j = kFindDivisibleByInT(strat, &Ln);
6961 if (j < 0) break;
6962 With = &(strat->T[j]);
6963 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
6964 }
6965 else
6966 {
6967 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
6968 if (With == NULL) break;
6969 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
6970 }
6971 cnt--;
6972 if (cnt==0)
6973 {
6975 /*poly tmp=*/Ln.CanonicalizeP();
6976 if (normalize)
6977 {
6978 Ln.Normalize();
6979 //pNormalize(tmp);
6980 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
6981 }
6982 }
6983 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
6984 {
6985 With->pNorm();
6986 }
6987 strat->redTailChange=TRUE;
6988 if (ksReducePolyTail(L, With, &Ln))
6989 {
6990 // reducing the tail would violate the exp bound
6991 // set a flag and hope for a retry (in bba)
6993 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
6994 do
6995 {
6996 pNext(h) = Ln.LmExtractAndIter();
6997 pIter(h);
6998 L->pLength++;
6999 } while (!Ln.IsNull());
7000 goto all_done;
7001 }
7002 if (Ln.IsNull()) goto all_done;
7003 if (! withT) With_s.Init(currRing);
7004 }
7005 pNext(h) = Ln.LmExtractAndIter();
7006 pIter(h);
7007 pNormalize(h);
7008 L->pLength++;
7009 }
7010
7011 all_done:
7012 Ln.Delete();
7013 if (L->p != NULL) pNext(L->p) = pNext(p);
7014
7015 if (strat->redTailChange)
7016 {
7017 L->length = 0;
7018 L->pLength = 0;
7019 }
7020
7021 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7022 //L->Normalize(); // HANNES: should have a test
7023 kTest_L(L,strat);
7024 return L->GetLmCurrRing();
7025}
7026
7027poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7028{
7029 strat->redTailChange=FALSE;
7030 if (strat->noTailReduction) return L->GetLmCurrRing();
7031 poly h, p;
7032 p = h = L->GetLmTailRing();
7033 if ((h==NULL) || (pNext(h)==NULL))
7034 return L->GetLmCurrRing();
7035
7036 TObject* With;
7037 // placeholder in case strat->tl < 0
7038 TObject With_s(strat->tailRing);
7039
7040 LObject Ln(pNext(h), strat->tailRing);
7041 Ln.pLength = L->GetpLength() - 1;
7042
7043 pNext(h) = NULL;
7044 if (L->p != NULL) pNext(L->p) = NULL;
7045 L->pLength = 1;
7046
7047 Ln.PrepareRed(strat->use_buckets);
7048
7049 int cnt=REDTAIL_CANONICALIZE;
7050 while(!Ln.IsNull())
7051 {
7052 loop
7053 {
7054 if (TEST_OPT_IDLIFT)
7055 {
7056 if (Ln.p!=NULL)
7057 {
7058 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7059 }
7060 else
7061 {
7062 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7063 }
7064 }
7065 Ln.SetShortExpVector();
7066 if (withT)
7067 {
7068 int j;
7069 j = kFindDivisibleByInT(strat, &Ln);
7070 if (j < 0) break;
7071 With = &(strat->T[j]);
7072 }
7073 else
7074 {
7075 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7076 if (With == NULL) break;
7077 }
7078 cnt--;
7079 if (cnt==0)
7080 {
7082 /*poly tmp=*/Ln.CanonicalizeP();
7083 if (normalize)
7084 {
7085 Ln.Normalize();
7086 //pNormalize(tmp);
7087 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7088 }
7089 }
7090 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7091 {
7092 With->pNorm();
7093 }
7094 strat->redTailChange=TRUE;
7095 if (ksReducePolyTail(L, With, &Ln))
7096 {
7097 // reducing the tail would violate the exp bound
7098 // set a flag and hope for a retry (in bba)
7100 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7101 do
7102 {
7103 pNext(h) = Ln.LmExtractAndIter();
7104 pIter(h);
7105 L->pLength++;
7106 } while (!Ln.IsNull());
7107 goto all_done;
7108 }
7109 if(!Ln.IsNull())
7110 {
7111 Ln.GetP();
7112 Ln.p = pJet(Ln.p,bound);
7113 }
7114 if (Ln.IsNull())
7115 {
7116 goto all_done;
7117 }
7118 if (! withT) With_s.Init(currRing);
7119 }
7120 pNext(h) = Ln.LmExtractAndIter();
7121 pIter(h);
7122 pNormalize(h);
7123 L->pLength++;
7124 }
7125
7126 all_done:
7127 Ln.Delete();
7128 if (L->p != NULL) pNext(L->p) = pNext(p);
7129
7130 if (strat->redTailChange)
7131 {
7132 L->length = 0;
7133 L->pLength = 0;
7134 }
7135
7136 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7137 //L->Normalize(); // HANNES: should have a test
7138 kTest_L(L,strat);
7139 return L->GetLmCurrRing();
7140}
7141
7142void redtailBbaAlsoLC_Z (LObject* L, int end_pos, kStrategy strat )
7143// normalize=FALSE, withT=FALSE, coeff=Z
7144{
7145 strat->redTailChange=FALSE;
7146
7147 poly h, p;
7148 p = h = L->GetLmTailRing();
7149 if ((h==NULL) || (pNext(h)==NULL))
7150 return;
7151
7152 TObject* With;
7153 LObject Ln(pNext(h), strat->tailRing);
7154 Ln.GetpLength();
7155
7156 pNext(h) = NULL;
7157 if (L->p != NULL)
7158 {
7159 pNext(L->p) = NULL;
7160 if (L->t_p != NULL) pNext(L->t_p) = NULL;
7161 }
7162 L->pLength = 1;
7163
7164 Ln.PrepareRed(strat->use_buckets);
7165
7166 int cnt=REDTAIL_CANONICALIZE;
7167
7168 while(!Ln.IsNull())
7169 {
7170 loop
7171 {
7172 if (TEST_OPT_IDLIFT)
7173 {
7174 if (Ln.p!=NULL)
7175 {
7176 if ((int)__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7177 }
7178 else
7179 {
7180 if ((int)__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7181 }
7182 }
7183 Ln.SetShortExpVector();
7184 int j;
7185 j = kFindDivisibleByInT(strat, &Ln);
7186 if (j < 0)
7187 {
7188 j = kFindDivisibleByInT_Z(strat, &Ln);
7189 if (j < 0)
7190 {
7191 break;
7192 }
7193 else
7194 {
7195 /* reduction not cancelling a tail term, but reducing its coefficient */
7196 With = &(strat->T[j]);
7197 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7198 cnt--;
7199 if (cnt==0)
7200 {
7202 /*poly tmp=*/Ln.CanonicalizeP();
7203 }
7204 strat->redTailChange=TRUE;
7205 /* reduction cancelling a tail term */
7206 if (ksReducePolyTailLC_Z(L, With, &Ln))
7207 {
7208 // reducing the tail would violate the exp bound
7209 // set a flag and hope for a retry (in bba)
7211 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7212 do
7213 {
7214 pNext(h) = Ln.LmExtractAndIter();
7215 pIter(h);
7216 L->pLength++;
7217 } while (!Ln.IsNull());
7218 goto all_done;
7219 }
7220 /* we have to break since we did not cancel the term, but only decreased
7221 * its coefficient. */
7222 break;
7223 }
7224 } else {
7225 With = &(strat->T[j]);
7226 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7227 cnt--;
7228 if (cnt==0)
7229 {
7231 /*poly tmp=*/Ln.CanonicalizeP();
7232 }
7233 strat->redTailChange=TRUE;
7234 /* reduction cancelling a tail term */
7235 if (ksReducePolyTail_Z(L, With, &Ln))
7236 {
7237 // reducing the tail would violate the exp bound
7238 // set a flag and hope for a retry (in bba)
7240 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7241 do
7242 {
7243 pNext(h) = Ln.LmExtractAndIter();
7244 pIter(h);
7245 L->pLength++;
7246 } while (!Ln.IsNull());
7247 goto all_done;
7248 }
7249 }
7250 if (Ln.IsNull()) goto all_done;
7251 }
7252 pNext(h) = Ln.LmExtractAndIter();
7253 pIter(h);
7254 L->pLength++;
7255 }
7256
7257 all_done:
7258 Ln.Delete();
7259 if (L->p != NULL) pNext(L->p) = pNext(p);
7260
7261 if (strat->redTailChange)
7262 {
7263 L->length = 0;
7264 L->pLength = 0;
7265 }
7266
7267 kTest_L(L, strat);
7268 return;
7269}
7270
7271poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7272// normalize=FALSE, withT=FALSE, coeff=Z
7273{
7274 strat->redTailChange=FALSE;
7275 if (strat->noTailReduction) return L->GetLmCurrRing();
7276 poly h, p;
7277 p = h = L->GetLmTailRing();
7278 if ((h==NULL) || (pNext(h)==NULL))
7279 return L->GetLmCurrRing();
7280
7281 TObject* With;
7282 // placeholder in case strat->tl < 0
7283 TObject With_s(strat->tailRing);
7284
7285 LObject Ln(pNext(h), strat->tailRing);
7286 Ln.pLength = L->GetpLength() - 1;
7287
7288 pNext(h) = NULL;
7289 if (L->p != NULL) pNext(L->p) = NULL;
7290 L->pLength = 1;
7291
7292 Ln.PrepareRed(strat->use_buckets);
7293
7294 int cnt=REDTAIL_CANONICALIZE;
7295 while(!Ln.IsNull())
7296 {
7297 loop
7298 {
7299 Ln.SetShortExpVector();
7300 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7301 if (With == NULL) break;
7302 cnt--;
7303 if (cnt==0)
7304 {
7306 /*poly tmp=*/Ln.CanonicalizeP();
7307 }
7308 // we are in Z, do not call pNorm
7309 strat->redTailChange=TRUE;
7310 // test divisibility of coefs:
7311 poly p_Ln=Ln.GetLmCurrRing();
7312 poly p_With=With->GetLmCurrRing();
7313
7314 if (ksReducePolyTail_Z(L, With, &Ln))
7315 {
7316 // reducing the tail would violate the exp bound
7317 // set a flag and hope for a retry (in bba)
7319 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7320 do
7321 {
7322 pNext(h) = Ln.LmExtractAndIter();
7323 pIter(h);
7324 L->pLength++;
7325 } while (!Ln.IsNull());
7326 goto all_done;
7327 }
7328 if (Ln.IsNull()) goto all_done;
7329 With_s.Init(currRing);
7330 }
7331 pNext(h) = Ln.LmExtractAndIter();
7332 pIter(h);
7333 pNormalize(h);
7334 L->pLength++;
7335 }
7336
7337 all_done:
7338 Ln.Delete();
7339 if (L->p != NULL) pNext(L->p) = pNext(p);
7340
7341 if (strat->redTailChange)
7342 {
7343 L->length = 0;
7344 }
7345
7346 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7347 //L->Normalize(); // HANNES: should have a test
7348 kTest_L(L,strat);
7349 return L->GetLmCurrRing();
7350}
7351
7352poly redtailBba_NF (poly p, kStrategy strat )
7353{
7354 strat->redTailChange=FALSE;
7355 if (strat->noTailReduction) return p;
7356 if ((p==NULL) || (pNext(p)==NULL))
7357 return p;
7358
7359 int max_ind;
7360 poly h=p;
7361 p=pNext(p);
7362 pNext(h)=NULL;
7363 while(p!=NULL)
7364 {
7365 p=redNF(p,max_ind,1,strat);
7366 if (p!=NULL)
7367 {
7368 poly hh=p;
7369 p=pNext(p);
7370 pNext(hh)=NULL;
7371 h=p_Add_q(h,hh,currRing);
7372 }
7373 }
7374 return h;
7375}
7376
7377poly redtailBba_Ring (LObject* L, int end_pos, kStrategy strat )
7378// normalize=FALSE, withT=FALSE, coeff=Ring
7379{
7380 strat->redTailChange=FALSE;
7381 if (strat->noTailReduction) return L->GetLmCurrRing();
7382 poly h, p;
7383 p = h = L->GetLmTailRing();
7384 if ((h==NULL) || (pNext(h)==NULL))
7385 return L->GetLmCurrRing();
7386
7387 TObject* With;
7388 // placeholder in case strat->tl < 0
7389 TObject With_s(strat->tailRing);
7390
7391 LObject Ln(pNext(h), strat->tailRing);
7392 Ln.pLength = L->GetpLength() - 1;
7393
7394 pNext(h) = NULL;
7395 if (L->p != NULL) pNext(L->p) = NULL;
7396 L->pLength = 1;
7397
7398 Ln.PrepareRed(strat->use_buckets);
7399
7400 int cnt=REDTAIL_CANONICALIZE;
7401 while(!Ln.IsNull())
7402 {
7403 loop
7404 {
7405 Ln.SetShortExpVector();
7406 With_s.Init(currRing);
7407 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7408 if (With == NULL) break;
7409 cnt--;
7410 if (cnt==0)
7411 {
7413 /*poly tmp=*/Ln.CanonicalizeP();
7414 }
7415 // we are in a ring, do not call pNorm
7416 // test divisibility of coefs:
7417 poly p_Ln=Ln.GetLmCurrRing();
7418 poly p_With=With->GetLmCurrRing();
7419 if (n_DivBy(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf))
7420 {
7421 strat->redTailChange=TRUE;
7422
7423 if (ksReducePolyTail_Z(L, With, &Ln))
7424 {
7425 // reducing the tail would violate the exp bound
7426 // set a flag and hope for a retry (in bba)
7428 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7429 do
7430 {
7431 pNext(h) = Ln.LmExtractAndIter();
7432 pIter(h);
7433 L->pLength++;
7434 } while (!Ln.IsNull());
7435 goto all_done;
7436 }
7437 }
7438 else break; /*proceed to next monomial*/
7439 if (Ln.IsNull()) goto all_done;
7440 }
7441 pNext(h) = Ln.LmExtractAndIter();
7442 pIter(h);
7443 pNormalize(h);
7444 L->pLength++;
7445 }
7446
7447 all_done:
7448 Ln.Delete();
7449 if (L->p != NULL) pNext(L->p) = pNext(p);
7450
7451 if (strat->redTailChange)
7452 {
7453 L->length = 0;
7454 }
7455
7456 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7457 //L->Normalize(); // HANNES: should have a test
7458 kTest_L(L,strat);
7459 return L->GetLmCurrRing();
7460}
7461
7462/*2
7463*checks the change degree and write progress report
7464*/
7465void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7466{
7467 if (i != *olddeg)
7468 {
7469 Print("%d",i);
7470 *olddeg = i;
7471 }
7472 if (TEST_OPT_OLDSTD)
7473 {
7474 if (strat->Ll != *reduc)
7475 {
7476 if (strat->Ll != *reduc-1)
7477 Print("(%d)",strat->Ll+1);
7478 else
7479 PrintS("-");
7480 *reduc = strat->Ll;
7481 }
7482 else
7483 PrintS(".");
7484 mflush();
7485 }
7486 else
7487 {
7488 if (red_result == 0)
7489 PrintS("-");
7490 else if (red_result < 0)
7491 PrintS(".");
7492 if ((red_result > 0) || ((strat->Ll % 100)==99))
7493 {
7494 if (strat->Ll != *reduc && strat->Ll > 0)
7495 {
7496 Print("(%d)",strat->Ll+1);
7497 *reduc = strat->Ll;
7498 }
7499 }
7500 }
7501}
7502
7503/*2
7504*statistics
7505*/
7506void messageStat (int hilbcount,kStrategy strat)
7507{
7508 //PrintS("\nUsage/Allocation of temporary storage:\n");
7509 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7510 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7511 Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7512 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7513 #ifdef HAVE_SHIFTBBA
7514 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7515 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7516 #endif
7517}
7518
7519void messageStatSBA (int hilbcount,kStrategy strat)
7520{
7521 //PrintS("\nUsage/Allocation of temporary storage:\n");
7522 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7523 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7524 Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7525 //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7526 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7527 #ifdef HAVE_SHIFTBBA
7528 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7529 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7530 #endif
7531}
7532
7533#ifdef KDEBUG
7534/*2
7535*debugging output: all internal sets, if changed
7536*for testing purpuse only/has to be changed for later use
7537*/
7539{
7540 int i;
7541 if (strat->news)
7542 {
7543 PrintS("set S");
7544 for (i=0; i<=strat->sl; i++)
7545 {
7546 Print("\n %d:",i);
7547 p_wrp(strat->S[i], currRing, strat->tailRing);
7548 if (strat->fromQ!=NULL && strat->fromQ[i])
7549 Print(" (from Q)");
7550 }
7551 strat->news = FALSE;
7552 }
7553 if (strat->newt)
7554 {
7555 PrintS("\nset T");
7556 for (i=0; i<=strat->tl; i++)
7557 {
7558 Print("\n %d:",i);
7559 strat->T[i].wrp();
7560 if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7561 Print(" o:%ld e:%d l:%d",
7562 strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7563 }
7564 strat->newt = FALSE;
7565 }
7566 PrintS("\nset L");
7567 for (i=strat->Ll; i>=0; i--)
7568 {
7569 Print("\n%d:",i);
7570 p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7571 PrintS(" ");
7572 p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7573 PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7574 PrintS("\n p : ");
7575 strat->L[i].wrp();
7576 Print(" o:%ld e:%d l:%d",
7577 strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7578 }
7579 PrintLn();
7580}
7581
7582#endif
7583
7584
7585/*2
7586*construct the set s from F
7587*/
7588void initS (ideal F, ideal Q, kStrategy strat)
7589{
7590 int i,pos;
7591
7593 else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7594 if (i<setmaxTinc) i=setmaxT;
7595 strat->ecartS=initec(i);
7596 strat->sevS=initsevS(i);
7597 strat->S_2_R=initS_2_R(i);
7598 strat->fromQ=NULL;
7599 strat->Shdl=idInit(i,F->rank);
7600 strat->S=strat->Shdl->m;
7601 /*- put polys into S -*/
7602 if (Q!=NULL)
7603 {
7604 strat->fromQ=initec(i);
7605 memset(strat->fromQ,0,i*sizeof(int));
7606 for (i=0; i<IDELEMS(Q); i++)
7607 {
7608 if (Q->m[i]!=NULL)
7609 {
7610 LObject h;
7611 h.p = pCopy(Q->m[i]);
7613 {
7614 h.pCleardenom(); // also does remove Content
7615 }
7616 else
7617 {
7618 h.pNorm();
7619 }
7621 {
7622 deleteHC(&h, strat);
7623 }
7624 if (h.p!=NULL)
7625 {
7626 strat->initEcart(&h);
7627 if (strat->sl==-1)
7628 pos =0;
7629 else
7630 {
7631 pos = posInS(strat,strat->sl,h.p,h.ecart);
7632 }
7633 h.sev = pGetShortExpVector(h.p);
7634 strat->enterS(h,pos,strat,-1);
7635 strat->fromQ[pos]=1;
7636 }
7637 }
7638 }
7639 }
7640 for (i=0; i<IDELEMS(F); i++)
7641 {
7642 if (F->m[i]!=NULL)
7643 {
7644 LObject h;
7645 h.p = pCopy(F->m[i]);
7647 {
7648 cancelunit(&h); /*- tries to cancel a unit -*/
7649 deleteHC(&h, strat);
7650 }
7651 if (h.p!=NULL)
7652 // do not rely on the input being a SB!
7653 {
7655 {
7656 h.pCleardenom(); // also does remove Content
7657 }
7658 else
7659 {
7660 h.pNorm();
7661 }
7662 strat->initEcart(&h);
7663 if (strat->sl==-1)
7664 pos =0;
7665 else
7666 pos = posInS(strat,strat->sl,h.p,h.ecart);
7667 h.sev = pGetShortExpVector(h.p);
7668 strat->enterS(h,pos,strat,-1);
7669 }
7670 }
7671 }
7672 /*- test, if a unit is in F -*/
7673 if ((strat->sl>=0)
7674 && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7675 && pIsConstant(strat->S[0]))
7676 {
7677 while (strat->sl>0) deleteInS(strat->sl,strat);
7678 }
7679}
7680
7681void initSL (ideal F, ideal Q,kStrategy strat)
7682{
7683 int i,pos;
7684
7685 if (Q!=NULL)
7686 {
7688 if (i<setmaxTinc) i=setmaxT;
7689 }
7690 else i=setmaxT;
7691 strat->ecartS=initec(i);
7692 strat->sevS=initsevS(i);
7693 strat->S_2_R=initS_2_R(i);
7694 strat->fromQ=NULL;
7695 strat->Shdl=idInit(i,F->rank);
7696 strat->S=strat->Shdl->m;
7697 /*- put polys into S -*/
7698 if (Q!=NULL)
7699 {
7700 strat->fromQ=initec(i);
7701 memset(strat->fromQ,0,i*sizeof(int));
7702 for (i=0; i<IDELEMS(Q); i++)
7703 {
7704 if (Q->m[i]!=NULL)
7705 {
7706 LObject h;
7707 h.p = pCopy(Q->m[i]);
7709 {
7710 deleteHC(&h,strat);
7711 }
7713 {
7714 h.pCleardenom(); // also does remove Content
7715 }
7716 else
7717 {
7718 h.pNorm();
7719 }
7720 if (h.p!=NULL)
7721 {
7722 strat->initEcart(&h);
7723 if (strat->sl==-1)
7724 pos =0;
7725 else
7726 {
7727 pos = posInS(strat,strat->sl,h.p,h.ecart);
7728 }
7729 h.sev = pGetShortExpVector(h.p);
7730 strat->enterS(h,pos,strat,-1);
7731 strat->fromQ[pos]=1;
7732 }
7733 }
7734 }
7735 }
7736 for (i=0; i<IDELEMS(F); i++)
7737 {
7738 if (F->m[i]!=NULL)
7739 {
7740 LObject h;
7741 h.p = pCopy(F->m[i]);
7743 {
7744 cancelunit(&h); /*- tries to cancel a unit -*/
7745 deleteHC(&h, strat);
7746 }
7747 if (h.p!=NULL)
7748 {
7750 {
7751 h.pCleardenom(); // also does remove Content
7752 }
7753 else
7754 {
7755 h.pNorm();
7756 }
7757 strat->initEcart(&h);
7758 if (strat->Ll==-1)
7759 pos =0;
7760 else
7761 pos = strat->posInL(strat->L,strat->Ll,&h,strat);
7762 h.sev = pGetShortExpVector(h.p);
7763 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7764 }
7765 }
7766 }
7767 /*- test, if a unit is in F -*/
7768
7769 if ((strat->Ll>=0)
7770 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7771 && pIsConstant(strat->L[strat->Ll].p))
7772 {
7773 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7774 }
7775}
7776
7777void initSLSba (ideal F, ideal Q,kStrategy strat)
7778{
7779 int i,pos;
7780 if (Q!=NULL)
7781 {
7783 if (i<setmaxTinc) i=setmaxT;
7784 }
7785 else i=setmaxT;
7786 strat->ecartS = initec(i);
7787 strat->sevS = initsevS(i);
7788 strat->sevSig = initsevS(i);
7789 strat->S_2_R = initS_2_R(i);
7790 strat->fromQ = NULL;
7791 strat->Shdl = idInit(i,F->rank);
7792 strat->S = strat->Shdl->m;
7793 strat->sig = (poly *)omAlloc0(i*sizeof(poly));
7794 if (strat->sbaOrder != 1)
7795 {
7796 strat->syz = (poly *)omAlloc0(i*sizeof(poly));
7797 strat->sevSyz = initsevS(i);
7798 strat->syzmax = i;
7799 strat->syzl = 0;
7800 }
7801 /*- put polys into S -*/
7802 if (Q!=NULL)
7803 {
7804 strat->fromQ=initec(i);
7805 memset(strat->fromQ,0,i*sizeof(int));
7806 for (i=0; i<IDELEMS(Q); i++)
7807 {
7808 if (Q->m[i]!=NULL)
7809 {
7810 LObject h;
7811 h.p = pCopy(Q->m[i]);
7813 {
7814 deleteHC(&h,strat);
7815 }
7817 {
7818 h.pCleardenom(); // also does remove Content
7819 }
7820 else
7821 {
7822 h.pNorm();
7823 }
7824 if (h.p!=NULL)
7825 {
7826 strat->initEcart(&h);
7827 if (strat->sl==-1)
7828 pos =0;
7829 else
7830 {
7831 pos = posInS(strat,strat->sl,h.p,h.ecart);
7832 }
7833 h.sev = pGetShortExpVector(h.p);
7834 strat->enterS(h,pos,strat,-1);
7835 strat->fromQ[pos]=1;
7836 }
7837 }
7838 }
7839 }
7840 for (i=0; i<IDELEMS(F); i++)
7841 {
7842 if (F->m[i]!=NULL)
7843 {
7844 LObject h;
7845 h.p = pCopy(F->m[i]);
7846 h.sig = pOne();
7847 //h.sig = pInit();
7848 //p_SetCoeff(h.sig,nInit(1),currRing);
7849 p_SetComp(h.sig,i+1,currRing);
7850 // if we are working with the Schreyer order we generate it
7851 // by multiplying the initial signatures with the leading monomial
7852 // of the corresponding initial polynomials generating the ideal
7853 // => we can keep the underlying monomial order and get a Schreyer
7854 // order without any bigger overhead
7855 if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
7856 {
7857 p_ExpVectorAdd (h.sig,F->m[i],currRing);
7858 }
7859 h.sevSig = pGetShortExpVector(h.sig);
7860#ifdef DEBUGF5
7861 pWrite(h.p);
7862 pWrite(h.sig);
7863#endif
7864 if (h.p!=NULL)
7865 {
7867 {
7868 cancelunit(&h); /*- tries to cancel a unit -*/
7869 deleteHC(&h, strat);
7870 }
7871 if (h.p!=NULL)
7872 {
7874 {
7875 h.pCleardenom(); // also does remove Content
7876 }
7877 else
7878 {
7879 h.pNorm();
7880 }
7881 strat->initEcart(&h);
7882 if (strat->Ll==-1)
7883 pos =0;
7884 else
7885 pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
7886 h.sev = pGetShortExpVector(h.p);
7887 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7888 }
7889 }
7890 /*
7891 if (strat->sbaOrder != 1)
7892 {
7893 for(j=0;j<i;j++)
7894 {
7895 strat->syz[ctr] = pCopy(F->m[j]);
7896 p_SetCompP(strat->syz[ctr],i+1,currRing);
7897 // add LM(F->m[i]) to the signature to get a Schreyer order
7898 // without changing the underlying polynomial ring at all
7899 p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
7900 // since p_Add_q() destroys all input
7901 // data we need to recreate help
7902 // each time
7903 poly help = pCopy(F->m[i]);
7904 p_SetCompP(help,j+1,currRing);
7905 pWrite(strat->syz[ctr]);
7906 pWrite(help);
7907 printf("%d\n",pLmCmp(strat->syz[ctr],help));
7908 strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
7909 printf("%d. SYZ ",ctr);
7910 pWrite(strat->syz[ctr]);
7911 strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
7912 ctr++;
7913 }
7914 strat->syzl = ps;
7915 }
7916 */
7917 }
7918 }
7919 /*- test, if a unit is in F -*/
7920
7921 if ((strat->Ll>=0)
7922 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7923 && pIsConstant(strat->L[strat->Ll].p))
7924 {
7925 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7926 }
7927}
7928
7930{
7931 if( strat->S[0] )
7932 {
7933 if( strat->S[1] && !rField_is_Ring(currRing))
7934 {
7935 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
7936 omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
7937 omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
7938 }
7939 int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
7940 /************************************************************
7941 * computing the length of the syzygy array needed
7942 ***********************************************************/
7943 for(i=1; i<=strat->sl; i++)
7944 {
7945 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
7946 {
7947 ps += i;
7948 }
7949 }
7950 ps += strat->sl+1;
7951 //comp = pGetComp (strat->P.sig);
7952 comp = strat->currIdx;
7953 strat->syzIdx = initec(comp);
7954 strat->sevSyz = initsevS(ps);
7955 strat->syz = (poly *)omAlloc(ps*sizeof(poly));
7956 strat->syzmax = ps;
7957 strat->syzl = 0;
7958 strat->syzidxmax = comp;
7959#if defined(DEBUGF5) || defined(DEBUGF51)
7960 PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
7961#endif
7962 i = 1;
7963 j = 0;
7964 /************************************************************
7965 * generating the leading terms of the principal syzygies
7966 ***********************************************************/
7967 while (i <= strat->sl)
7968 {
7969 /**********************************************************
7970 * principal syzygies start with component index 2
7971 * the array syzIdx starts with index 0
7972 * => the rules for a signature with component comp start
7973 * at strat->syz[strat->syzIdx[comp-2]] !
7974 *********************************************************/
7975 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
7976 {
7977 comp = pGetComp(strat->sig[i]);
7978 comp_old = pGetComp(strat->sig[i-1]);
7979 diff = comp - comp_old - 1;
7980 // diff should be zero, but sometimes also the initial generating
7981 // elements of the input ideal reduce to zero. then there is an
7982 // index-gap between the signatures. for these in-between signatures we
7983 // can safely set syzIdx[j] = 0 as no such element will be ever computed
7984 // in the following.
7985 // doing this, we keep the relation "j = comp - 2" alive, which makes
7986 // jumps way easier when checking criteria
7987 while (diff>0)
7988 {
7989 strat->syzIdx[j] = 0;
7990 diff--;
7991 j++;
7992 }
7993 strat->syzIdx[j] = ctr;
7994 j++;
7995 LObject Q;
7996 int pos;
7997 for (k = 0; k<i; k++)
7998 {
7999 Q.sig = pOne();
8002 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8003 p_SetCompP (Q.sig, comp, currRing);
8004 poly q = p_One(currRing);
8007 p_ExpVectorCopy(q,strat->S[i],currRing);
8008 q = p_Neg (q, currRing);
8009 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8010 Q.sig = p_Add_q (Q.sig, q, currRing);
8011 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8012 pos = posInSyz(strat, Q.sig);
8013 enterSyz(Q, strat, pos);
8014 ctr++;
8015 }
8016 }
8017 i++;
8018 }
8019 /**************************************************************
8020 * add syzygies for upcoming first element of new iteration step
8021 **************************************************************/
8022 comp = strat->currIdx;
8023 comp_old = pGetComp(strat->sig[i-1]);
8024 diff = comp - comp_old - 1;
8025 // diff should be zero, but sometimes also the initial generating
8026 // elements of the input ideal reduce to zero. then there is an
8027 // index-gap between the signatures. for these in-between signatures we
8028 // can safely set syzIdx[j] = 0 as no such element will be ever computed
8029 // in the following.
8030 // doing this, we keep the relation "j = comp - 2" alive, which makes
8031 // jumps way easier when checking criteria
8032 while (diff>0)
8033 {
8034 strat->syzIdx[j] = 0;
8035 diff--;
8036 j++;
8037 }
8038 strat->syzIdx[j] = ctr;
8039 LObject Q;
8040 int pos;
8041 for (k = 0; k<strat->sl+1; k++)
8042 {
8043 Q.sig = pOne();
8046 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8047 p_SetCompP (Q.sig, comp, currRing);
8048 poly q = p_One(currRing);
8050 p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8051 p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8052 q = p_Neg (q, currRing);
8053 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8054 Q.sig = p_Add_q (Q.sig, q, currRing);
8055 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8056 pos = posInSyz(strat, Q.sig);
8057 enterSyz(Q, strat, pos);
8058 ctr++;
8059 }
8060//#if 1
8061#ifdef DEBUGF5
8062 PrintS("Principal syzygies:\n");
8063 Print("syzl %d\n",strat->syzl);
8064 Print("syzmax %d\n",strat->syzmax);
8065 Print("ps %d\n",ps);
8066 PrintS("--------------------------------\n");
8067 for(i=0;i<=strat->syzl-1;i++)
8068 {
8069 Print("%d - ",i);
8070 pWrite(strat->syz[i]);
8071 }
8072 for(i=0;i<strat->currIdx;i++)
8073 {
8074 Print("%d - %d\n",i,strat->syzIdx[i]);
8075 }
8076 PrintS("--------------------------------\n");
8077#endif
8078 }
8079}
8080
8081/*2
8082*construct the set s from F and {P}
8083*/
8084void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8085{
8086 int i,pos;
8087
8088 if (Q!=NULL)
8089 {
8091 if (i<setmaxTinc) i=setmaxT;
8092 }
8093 else i=setmaxT;
8094 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8095 strat->ecartS=initec(i);
8096 strat->sevS=initsevS(i);
8097 strat->S_2_R=initS_2_R(i);
8098 strat->fromQ=NULL;
8099 strat->Shdl=idInit(i,F->rank);
8100 strat->S=strat->Shdl->m;
8101
8102 /*- put polys into S -*/
8103 if (Q!=NULL)
8104 {
8105 strat->fromQ=initec(i);
8106 memset(strat->fromQ,0,i*sizeof(int));
8107 for (i=0; i<IDELEMS(Q); i++)
8108 {
8109 if (Q->m[i]!=NULL)
8110 {
8111 LObject h;
8112 h.p = pCopy(Q->m[i]);
8113 //if (TEST_OPT_INTSTRATEGY)
8114 //{
8115 // h.pCleardenom(); // also does remove Content
8116 //}
8117 //else
8118 //{
8119 // h.pNorm();
8120 //}
8122 {
8123 deleteHC(&h,strat);
8124 }
8125 if (h.p!=NULL)
8126 {
8127 strat->initEcart(&h);
8128 if (strat->sl==-1)
8129 pos =0;
8130 else
8131 {
8132 pos = posInS(strat,strat->sl,h.p,h.ecart);
8133 }
8134 h.sev = pGetShortExpVector(h.p);
8135 strat->enterS(h,pos,strat, strat->tl+1);
8136 enterT(h, strat);
8137 strat->fromQ[pos]=1;
8138 }
8139 }
8140 }
8141 }
8142 /*- put polys into S -*/
8143 for (i=0; i<IDELEMS(F); i++)
8144 {
8145 if (F->m[i]!=NULL)
8146 {
8147 LObject h;
8148 h.p = pCopy(F->m[i]);
8150 {
8151 deleteHC(&h,strat);
8152 }
8153 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8154 {
8155 h.p=redtailBba(h.p,strat->sl,strat);
8156 }
8157 if (h.p!=NULL)
8158 {
8159 strat->initEcart(&h);
8160 if (strat->sl==-1)
8161 pos =0;
8162 else
8163 pos = posInS(strat,strat->sl,h.p,h.ecart);
8164 h.sev = pGetShortExpVector(h.p);
8165 strat->enterS(h,pos,strat, strat->tl+1);
8166 enterT(h,strat);
8167 }
8168 }
8169 }
8170 for (i=0; i<IDELEMS(P); i++)
8171 {
8172 if (P->m[i]!=NULL)
8173 {
8174 LObject h;
8175 h.p=pCopy(P->m[i]);
8177 {
8178 h.pCleardenom();
8179 }
8180 else
8181 {
8182 h.pNorm();
8183 }
8184 if(strat->sl>=0)
8185 {
8187 {
8188 h.p=redBba(h.p,strat->sl,strat);
8189 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8190 {
8191 h.p=redtailBba(h.p,strat->sl,strat);
8192 }
8193 }
8194 else
8195 {
8196 h.p=redMora(h.p,strat->sl,strat);
8197 }
8198 if(h.p!=NULL)
8199 {
8200 strat->initEcart(&h);
8202 {
8203 h.pCleardenom();
8204 }
8205 else
8206 {
8207 h.is_normalized = 0;
8208 h.pNorm();
8209 }
8210 h.sev = pGetShortExpVector(h.p);
8211 h.SetpFDeg();
8212 pos = posInS(strat,strat->sl,h.p,h.ecart);
8213 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8214 strat->enterS(h,pos,strat, strat->tl+1);
8215 enterT(h,strat);
8216 }
8217 }
8218 else
8219 {
8220 h.sev = pGetShortExpVector(h.p);
8221 strat->initEcart(&h);
8222 strat->enterS(h,0,strat, strat->tl+1);
8223 enterT(h,strat);
8224 }
8225 }
8226 }
8227}
8228/*2
8229*construct the set s from F and {P}
8230*/
8231
8232void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8233{
8234 int i,pos;
8235
8236 if (Q!=NULL)
8237 {
8239 if (i<setmaxTinc) i=setmaxT;
8240 }
8241 else i=setmaxT;
8242 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8243 strat->sevS=initsevS(i);
8244 strat->sevSig=initsevS(i);
8245 strat->S_2_R=initS_2_R(i);
8246 strat->fromQ=NULL;
8247 strat->Shdl=idInit(i,F->rank);
8248 strat->S=strat->Shdl->m;
8249 strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8250 /*- put polys into S -*/
8251 if (Q!=NULL)
8252 {
8253 strat->fromQ=initec(i);
8254 memset(strat->fromQ,0,i*sizeof(int));
8255 for (i=0; i<IDELEMS(Q); i++)
8256 {
8257 if (Q->m[i]!=NULL)
8258 {
8259 LObject h;
8260 h.p = pCopy(Q->m[i]);
8261 //if (TEST_OPT_INTSTRATEGY)
8262 //{
8263 // h.pCleardenom(); // also does remove Content
8264 //}
8265 //else
8266 //{
8267 // h.pNorm();
8268 //}
8270 {
8271 deleteHC(&h,strat);
8272 }
8273 if (h.p!=NULL)
8274 {
8275 strat->initEcart(&h);
8276 if (strat->sl==-1)
8277 pos =0;
8278 else
8279 {
8280 pos = posInS(strat,strat->sl,h.p,h.ecart);
8281 }
8282 h.sev = pGetShortExpVector(h.p);
8283 strat->enterS(h,pos,strat, strat->tl+1);
8284 enterT(h, strat);
8285 strat->fromQ[pos]=1;
8286 }
8287 }
8288 }
8289 }
8290 /*- put polys into S -*/
8291 for (i=0; i<IDELEMS(F); i++)
8292 {
8293 if (F->m[i]!=NULL)
8294 {
8295 LObject h;
8296 h.p = pCopy(F->m[i]);
8298 {
8299 deleteHC(&h,strat);
8300 }
8301 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8302 {
8303 h.p=redtailBba(h.p,strat->sl,strat);
8304 }
8305 if (h.p!=NULL)
8306 {
8307 strat->initEcart(&h);
8308 if (strat->sl==-1)
8309 pos =0;
8310 else
8311 pos = posInS(strat,strat->sl,h.p,h.ecart);
8312 h.sev = pGetShortExpVector(h.p);
8313 strat->enterS(h,pos,strat, strat->tl+1);
8314 enterT(h,strat);
8315 }
8316 }
8317 }
8318 for (i=0; i<IDELEMS(P); i++)
8319 {
8320 if (P->m[i]!=NULL)
8321 {
8322 LObject h;
8323 h.p=pCopy(P->m[i]);
8325 {
8326 h.pCleardenom();
8327 }
8328 else
8329 {
8330 h.pNorm();
8331 }
8332 if(strat->sl>=0)
8333 {
8335 {
8336 h.p=redBba(h.p,strat->sl,strat);
8337 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8338 {
8339 h.p=redtailBba(h.p,strat->sl,strat);
8340 }
8341 }
8342 else
8343 {
8344 h.p=redMora(h.p,strat->sl,strat);
8345 }
8346 if(h.p!=NULL)
8347 {
8348 strat->initEcart(&h);
8350 {
8351 h.pCleardenom();
8352 }
8353 else
8354 {
8355 h.is_normalized = 0;
8356 h.pNorm();
8357 }
8358 h.sev = pGetShortExpVector(h.p);
8359 h.SetpFDeg();
8360 pos = posInS(strat,strat->sl,h.p,h.ecart);
8361 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8362 strat->enterS(h,pos,strat, strat->tl+1);
8363 enterT(h,strat);
8364 }
8365 }
8366 else
8367 {
8368 h.sev = pGetShortExpVector(h.p);
8369 strat->initEcart(&h);
8370 strat->enterS(h,0,strat, strat->tl+1);
8371 enterT(h,strat);
8372 }
8373 }
8374 }
8375}
8376
8377/*2
8378* reduces h using the set S
8379* procedure used in cancelunit1
8380*/
8381static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8382{
8383 int j = 0;
8384 unsigned long not_sev = ~ pGetShortExpVector(h);
8385
8386 while (j <= maxIndex)
8387 {
8388 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8389 return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8390 else j++;
8391 }
8392 return h;
8393}
8394
8395/*2
8396*tests if p.p=monomial*unit and cancels the unit
8397*/
8398void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8399{
8400 int k;
8401 poly r,h,h1,q;
8402
8403 if (!pIsVector((*p).p) && ((*p).ecart != 0))
8404 {
8405 // Leading coef have to be a unit: no
8406 // example 2x+4x2 should be simplified to 2x*(1+2x)
8407 // and 2 is not a unit in Z
8408 //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8409 k = 0;
8410 h1 = r = pCopy((*p).p);
8411 h =pNext(r);
8412 loop
8413 {
8414 if (h==NULL)
8415 {
8416 pDelete(&r);
8417 pDelete(&(pNext((*p).p)));
8418 (*p).ecart = 0;
8419 (*p).length = 1;
8420 (*p).pLength = 1;
8421 (*suc)=0;
8422 return;
8423 }
8424 if (!pDivisibleBy(r,h))
8425 {
8426 q=redBba1(h,index ,strat);
8427 if (q != h)
8428 {
8429 k++;
8430 pDelete(&h);
8431 pNext(h1) = h = q;
8432 }
8433 else
8434 {
8435 pDelete(&r);
8436 return;
8437 }
8438 }
8439 else
8440 {
8441 h1 = h;
8442 pIter(h);
8443 }
8444 if (k > 10)
8445 {
8446 pDelete(&r);
8447 return;
8448 }
8449 }
8450 }
8451}
8452
8453#if 0
8454/*2
8455* reduces h using the elements from Q in the set S
8456* procedure used in updateS
8457* must not be used for elements of Q or elements of an ideal !
8458*/
8459static poly redQ (poly h, int j, kStrategy strat)
8460{
8461 int start;
8462 unsigned long not_sev = ~ pGetShortExpVector(h);
8463 while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8464 start=j;
8465 while (j<=strat->sl)
8466 {
8467 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8468 {
8469 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8470 if (h==NULL) return NULL;
8471 j = start;
8472 not_sev = ~ pGetShortExpVector(h);
8473 }
8474 else j++;
8475 }
8476 return h;
8477}
8478#endif
8479
8480/*2
8481* reduces h using the set S
8482* procedure used in updateS
8483*/
8484static poly redBba (poly h,int maxIndex,kStrategy strat)
8485{
8486 int j = 0;
8487 unsigned long not_sev = ~ pGetShortExpVector(h);
8488
8489 while (j <= maxIndex)
8490 {
8491 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8492 {
8493 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8494 if (h==NULL) return NULL;
8495 j = 0;
8496 not_sev = ~ pGetShortExpVector(h);
8497 }
8498 else j++;
8499 }
8500 return h;
8501}
8502
8503/*2
8504* reduces h using the set S
8505*e is the ecart of h
8506*procedure used in updateS
8507*/
8508static poly redMora (poly h,int maxIndex,kStrategy strat)
8509{
8510 int j=0;
8511 int e,l;
8512 unsigned long not_sev = ~ pGetShortExpVector(h);
8513
8514 if (maxIndex >= 0)
8515 {
8516 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8517 do
8518 {
8519 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8520 && ((e >= strat->ecartS[j]) || (strat->kNoether!=NULL)))
8521 {
8522#ifdef KDEBUG
8523 if (TEST_OPT_DEBUG)
8524 {
8525 PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8526 }
8527#endif
8528 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8529#ifdef KDEBUG
8530 if(TEST_OPT_DEBUG)
8531 {
8532 PrintS(")\nto "); wrp(h); PrintLn();
8533 }
8534#endif
8535 // pDelete(&h);
8536 if (h == NULL) return NULL;
8537 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8538 j = 0;
8539 not_sev = ~ pGetShortExpVector(h);
8540 }
8541 else j++;
8542 }
8543 while (j <= maxIndex);
8544 }
8545 return h;
8546}
8547
8548/*2
8549*updates S:
8550*the result is a set of polynomials which are in
8551*normalform with respect to S
8552*/
8554{
8555 LObject h;
8556 int i, suc=0;
8557 poly redSi=NULL;
8558 BOOLEAN change,any_change;
8559// Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8560// for (i=0; i<=(strat->sl); i++)
8561// {
8562// Print("s%d:",i);
8563// if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8564// pWrite(strat->S[i]);
8565// }
8566// Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8567 any_change=FALSE;
8569 {
8570 while (suc != -1)
8571 {
8572 i=suc+1;
8573 while (i<=strat->sl)
8574 {
8575 change=FALSE;
8577 any_change = FALSE;
8578 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8579 {
8580 redSi = pHead(strat->S[i]);
8581 strat->S[i] = redBba(strat->S[i],i-1,strat);
8582 //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8583 // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8584 if (pCmp(redSi,strat->S[i])!=0)
8585 {
8586 change=TRUE;
8587 any_change=TRUE;
8588 #ifdef KDEBUG
8589 if (TEST_OPT_DEBUG)
8590 {
8591 PrintS("reduce:");
8592 wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8593 }
8594 #endif
8595 if (TEST_OPT_PROT)
8596 {
8597 if (strat->S[i]==NULL)
8598 PrintS("V");
8599 else
8600 PrintS("v");
8601 mflush();
8602 }
8603 }
8604 pLmDelete(&redSi);
8605 if (strat->S[i]==NULL)
8606 {
8607 deleteInS(i,strat);
8608 i--;
8609 }
8610 else if (change)
8611 {
8613 {
8615 {
8616 number n;
8617 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8618 if (!nIsOne(n))
8619 {
8621 denom->n=nInvers(n);
8622 denom->next=DENOMINATOR_LIST;
8623 DENOMINATOR_LIST=denom;
8624 }
8625 nDelete(&n);
8626 }
8627 else
8628 {
8629 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8630 }
8631 }
8632 else
8633 {
8634 pNorm(strat->S[i]);
8635 }
8636 strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8637 }
8638 }
8639 i++;
8640 }
8641 if (any_change) reorderS(&suc,strat);
8642 else break;
8643 }
8644 if (toT)
8645 {
8646 for (i=0; i<=strat->sl; i++)
8647 {
8648 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8649 {
8650 h.p = redtailBba(strat->S[i],i-1,strat);
8652 {
8653 h.pCleardenom();// also does remove Content
8654 }
8655 }
8656 else
8657 {
8658 h.p = strat->S[i];
8659 }
8660 strat->initEcart(&h);
8661 if (strat->honey)
8662 {
8663 strat->ecartS[i] = h.ecart;
8664 }
8665 if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8666 else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8667 h.sev = strat->sevS[i];
8668 /*puts the elements of S also to T*/
8669 strat->initEcart(&h);
8670 /*if (toT) - already checked*/ enterT(h,strat);
8671 strat->S_2_R[i] = strat->tl;
8672#ifdef HAVE_SHIFTBBA
8673 if (/*(toT) && */(currRing->isLPring))
8674 enterTShift(h, strat);
8675#endif
8676 }
8677 }
8678 }
8679 else
8680 {
8681 while (suc != -1)
8682 {
8683 i=suc;
8684 while (i<=strat->sl)
8685 {
8686 change=FALSE;
8687 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8688 {
8689 redSi=pHead((strat->S)[i]);
8690 (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
8691 if ((strat->S)[i]==NULL)
8692 {
8693 deleteInS(i,strat);
8694 i--;
8695 }
8696 else if (pCmp((strat->S)[i],redSi)!=0)
8697 {
8698 any_change=TRUE;
8699 h.p = strat->S[i];
8700 strat->initEcart(&h);
8701 strat->ecartS[i] = h.ecart;
8703 {
8705 {
8706 number n;
8707 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8708 if (!nIsOne(n))
8709 {
8711 denom->n=nInvers(n);
8712 denom->next=DENOMINATOR_LIST;
8713 DENOMINATOR_LIST=denom;
8714 }
8715 nDelete(&n);
8716 }
8717 else
8718 {
8719 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8720 }
8721 }
8722 else
8723 {
8724 pNorm(strat->S[i]); // == h.p
8725 }
8726 h.sev = pGetShortExpVector(h.p);
8727 strat->sevS[i] = h.sev;
8728 }
8729 pLmDelete(&redSi);
8730 kTest(strat);
8731 }
8732 i++;
8733 }
8734#ifdef KDEBUG
8735 kTest(strat);
8736#endif
8737 if (any_change) reorderS(&suc,strat);
8738 else { suc=-1; break; }
8739 if (h.p!=NULL)
8740 {
8741 if (!strat->kAllAxis)
8742 {
8743 /*strat->kAllAxis =*/ HEckeTest(h.p,strat);
8744 }
8745 if (strat->kAllAxis)
8746 newHEdge(strat);
8747 }
8748 }
8749 for (i=0; i<=strat->sl; i++)
8750 {
8751 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8752 {
8753 strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
8754 strat->initEcart(&h);
8755 strat->ecartS[i] = h.ecart;
8756 h.sev = pGetShortExpVector(h.p);
8757 strat->sevS[i] = h.sev;
8758 }
8759 else
8760 {
8761 h.p = strat->S[i];
8762 h.ecart=strat->ecartS[i];
8763 h.sev = strat->sevS[i];
8764 h.length = h.pLength = pLength(h.p);
8765 }
8766 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8767 cancelunit1(&h,&suc,strat->sl,strat);
8768 h.SetpFDeg();
8769 /*puts the elements of S also to T*/
8770 enterT(h,strat);
8771 strat->S_2_R[i] = strat->tl;
8772#ifdef HAVE_SHIFTBBA
8773 if (currRing->isLPring)
8774 enterTShift(h, strat);
8775#endif
8776 }
8777 if (suc!= -1) updateS(toT,strat);
8778 }
8779#ifdef KDEBUG
8780 kTest(strat);
8781#endif
8782}
8783
8784/*2
8785* -puts p to the standardbasis s at position at
8786* -saves the result in S
8787*/
8788void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
8789{
8790 strat->news = TRUE;
8791 /*- puts p to the standardbasis s at position at -*/
8792 if (strat->sl == IDELEMS(strat->Shdl)-1)
8793 {
8794 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8795 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8796 (IDELEMS(strat->Shdl)+setmaxTinc)
8797 *sizeof(unsigned long));
8798 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8799 IDELEMS(strat->Shdl)*sizeof(int),
8800 (IDELEMS(strat->Shdl)+setmaxTinc)
8801 *sizeof(int));
8802 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8803 IDELEMS(strat->Shdl)*sizeof(int),
8804 (IDELEMS(strat->Shdl)+setmaxTinc)
8805 *sizeof(int));
8806 if (strat->lenS!=NULL)
8807 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8808 IDELEMS(strat->Shdl)*sizeof(int),
8809 (IDELEMS(strat->Shdl)+setmaxTinc)
8810 *sizeof(int));
8811 if (strat->lenSw!=NULL)
8812 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8813 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8814 (IDELEMS(strat->Shdl)+setmaxTinc)
8815 *sizeof(wlen_type));
8816 if (strat->fromQ!=NULL)
8817 {
8818 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8819 IDELEMS(strat->Shdl)*sizeof(int),
8820 (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
8821 }
8822 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
8823 IDELEMS(strat->Shdl)+=setmaxTinc;
8824 strat->Shdl->m=strat->S;
8825 }
8826 if (atS <= strat->sl)
8827 {
8828#ifdef ENTER_USE_MEMMOVE
8829 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
8830 (strat->sl - atS + 1)*sizeof(poly));
8831 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
8832 (strat->sl - atS + 1)*sizeof(int));
8833 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
8834 (strat->sl - atS + 1)*sizeof(unsigned long));
8835 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
8836 (strat->sl - atS + 1)*sizeof(int));
8837 if (strat->lenS!=NULL)
8838 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
8839 (strat->sl - atS + 1)*sizeof(int));
8840 if (strat->lenSw!=NULL)
8841 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
8842 (strat->sl - atS + 1)*sizeof(wlen_type));
8843#else
8844 for (i=strat->sl+1; i>=atS+1; i--)
8845 {
8846 strat->S[i] = strat->S[i-1];
8847 strat->ecartS[i] = strat->ecartS[i-1];
8848 strat->sevS[i] = strat->sevS[i-1];
8849 strat->S_2_R[i] = strat->S_2_R[i-1];
8850 }
8851 if (strat->lenS!=NULL)
8852 for (i=strat->sl+1; i>=atS+1; i--)
8853 strat->lenS[i] = strat->lenS[i-1];
8854 if (strat->lenSw!=NULL)
8855 for (i=strat->sl+1; i>=atS+1; i--)
8856 strat->lenSw[i] = strat->lenSw[i-1];
8857#endif
8858 }
8859 if (strat->fromQ!=NULL)
8860 {
8861#ifdef ENTER_USE_MEMMOVE
8862 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
8863 (strat->sl - atS + 1)*sizeof(int));
8864#else
8865 for (i=strat->sl+1; i>=atS+1; i--)
8866 {
8867 strat->fromQ[i] = strat->fromQ[i-1];
8868 }
8869#endif
8870 strat->fromQ[atS]=0;
8871 }
8872
8873 /*- save result -*/
8874 poly pp=p.p;
8875 strat->S[atS] = pp;
8876 if (strat->honey) strat->ecartS[atS] = p.ecart;
8877 if (p.sev == 0)
8878 p.sev = pGetShortExpVector(pp);
8879 else
8880 assume(p.sev == pGetShortExpVector(pp));
8881 strat->sevS[atS] = p.sev;
8882 strat->ecartS[atS] = p.ecart;
8883 strat->S_2_R[atS] = atR;
8884 strat->sl++;
8885}
8886
8887#ifdef HAVE_SHIFTBBA
8888void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR)
8889{
8890 enterSBba(p, atS, strat, atR);
8891
8892 int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
8893 for (int i = maxPossibleShift; i > 0; i--)
8894 {
8895 // NOTE: don't use "shared tails" here. In rare cases it can cause problems
8896 // in `kNF2` because of lazy poly normalizations.
8897 LObject qq(p_Copy(p.p, strat->tailRing));
8898 p_mLPshift(qq.p, i, strat->tailRing);
8899 qq.shift = i;
8900 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
8901 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
8902 enterSBba(qq, atS, strat, -1);
8903 }
8904}
8905#endif
8906
8907/*2
8908* -puts p to the standardbasis s at position at
8909* -saves the result in S
8910*/
8911void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
8912{
8913 strat->news = TRUE;
8914 /*- puts p to the standardbasis s at position at -*/
8915 if (strat->sl == IDELEMS(strat->Shdl)-1)
8916 {
8917 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8918 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8919 (IDELEMS(strat->Shdl)+setmax)
8920 *sizeof(unsigned long));
8921 strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
8922 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8923 (IDELEMS(strat->Shdl)+setmax)
8924 *sizeof(unsigned long));
8925 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8926 IDELEMS(strat->Shdl)*sizeof(int),
8927 (IDELEMS(strat->Shdl)+setmax)
8928 *sizeof(int));
8929 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8930 IDELEMS(strat->Shdl)*sizeof(int),
8931 (IDELEMS(strat->Shdl)+setmax)
8932 *sizeof(int));
8933 if (strat->lenS!=NULL)
8934 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8935 IDELEMS(strat->Shdl)*sizeof(int),
8936 (IDELEMS(strat->Shdl)+setmax)
8937 *sizeof(int));
8938 if (strat->lenSw!=NULL)
8939 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8940 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8941 (IDELEMS(strat->Shdl)+setmax)
8942 *sizeof(wlen_type));
8943 if (strat->fromQ!=NULL)
8944 {
8945 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8946 IDELEMS(strat->Shdl)*sizeof(int),
8947 (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
8948 }
8949 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
8950 pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
8951 IDELEMS(strat->Shdl)+=setmax;
8952 strat->Shdl->m=strat->S;
8953 }
8954 // in a signature-based algorithm the following situation will never
8955 // appear due to the fact that the critical pairs are already sorted
8956 // by increasing signature.
8957 // True. However, in the case of integers we need to put the element
8958 // that caused the signature drop on the first position
8959 if (atS <= strat->sl)
8960 {
8961#ifdef ENTER_USE_MEMMOVE
8962 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
8963 (strat->sl - atS + 1)*sizeof(poly));
8964 memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
8965 (strat->sl - atS + 1)*sizeof(poly));
8966 memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
8967 (strat->sl - atS + 1)*sizeof(unsigned long));
8968 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
8969 (strat->sl - atS + 1)*sizeof(int));
8970 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
8971 (strat->sl - atS + 1)*sizeof(unsigned long));
8972 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
8973 (strat->sl - atS + 1)*sizeof(int));
8974 if (strat->lenS!=NULL)
8975 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
8976 (strat->sl - atS + 1)*sizeof(int));
8977 if (strat->lenSw!=NULL)
8978 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
8979 (strat->sl - atS + 1)*sizeof(wlen_type));
8980#else
8981 for (i=strat->sl+1; i>=atS+1; i--)
8982 {
8983 strat->S[i] = strat->S[i-1];
8984 strat->ecartS[i] = strat->ecartS[i-1];
8985 strat->sevS[i] = strat->sevS[i-1];
8986 strat->S_2_R[i] = strat->S_2_R[i-1];
8987 strat->sig[i] = strat->sig[i-1];
8988 strat->sevSig[i] = strat->sevSig[i-1];
8989 }
8990 if (strat->lenS!=NULL)
8991 for (i=strat->sl+1; i>=atS+1; i--)
8992 strat->lenS[i] = strat->lenS[i-1];
8993 if (strat->lenSw!=NULL)
8994 for (i=strat->sl+1; i>=atS+1; i--)
8995 strat->lenSw[i] = strat->lenSw[i-1];
8996#endif
8997 }
8998 if (strat->fromQ!=NULL)
8999 {
9000#ifdef ENTER_USE_MEMMOVE
9001 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9002 (strat->sl - atS + 1)*sizeof(int));
9003#else
9004 for (i=strat->sl+1; i>=atS+1; i--)
9005 {
9006 strat->fromQ[i] = strat->fromQ[i-1];
9007 }
9008#endif
9009 strat->fromQ[atS]=0;
9010 }
9011
9012 /*- save result -*/
9013 strat->S[atS] = p.p;
9014 strat->sig[atS] = p.sig; // TODO: get the correct signature in here!
9015 if (strat->honey) strat->ecartS[atS] = p.ecart;
9016 if (p.sev == 0)
9017 p.sev = pGetShortExpVector(p.p);
9018 else
9019 assume(p.sev == pGetShortExpVector(p.p));
9020 strat->sevS[atS] = p.sev;
9021 // during the interreduction process of a signature-based algorithm we do not
9022 // compute the signature at this point, but when the whole interreduction
9023 // process finishes, i.e. f5c terminates!
9024 if (p.sig != NULL)
9025 {
9026 if (p.sevSig == 0)
9027 p.sevSig = pGetShortExpVector(p.sig);
9028 else
9029 assume(p.sevSig == pGetShortExpVector(p.sig));
9030 strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9031 }
9032 strat->ecartS[atS] = p.ecart;
9033 strat->S_2_R[atS] = atR;
9034 strat->sl++;
9035#ifdef DEBUGF5
9036 int k;
9037 Print("--- LIST S: %d ---\n",strat->sl);
9038 for(k=0;k<=strat->sl;k++)
9039 {
9040 pWrite(strat->sig[k]);
9041 }
9042 PrintS("--- LIST S END ---\n");
9043#endif
9044}
9045
9047{
9048 p.GetP(strat->lmBin);
9049 if (strat->homog) strat->initEcart(&p);
9050 strat->redTailChange=FALSE;
9052 {
9053 p.pCleardenom();
9055 {
9056#ifdef HAVE_SHIFTBBA
9057 if (rIsLPRing(currRing))
9058 p.p = redtailBba(&p,strat->tl,strat, TRUE,!TEST_OPT_CONTENTSB);
9059 else
9060#endif
9061 {
9062 p.p = redtailBba(&p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9063 }
9064 p.pCleardenom();
9065 if (strat->redTailChange)
9066 p.t_p=NULL;
9067 if (strat->P.p!=NULL) strat->P.sev=p_GetShortExpVector(strat->P.p,currRing);
9068 else strat->P.sev=0;
9069 }
9070 }
9071
9072 assume(strat->tailRing == p.tailRing);
9073 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9074
9075 int i, j, pos;
9076 poly tp = strat->T[tj].p;
9077
9078 /* enter p to T set */
9079 enterT(p, strat);
9080
9081 for (j = 0; j <= strat->sl; ++j)
9082 {
9083 if (pLtCmp(tp, strat->S[j]) == 0)
9084 {
9085 break;
9086 }
9087 }
9088 /* it may be that the exchanged element
9089 * is until now only in T and not in S */
9090 if (j <= strat->sl)
9091 {
9092 deleteInS(j, strat);
9093 }
9094
9095 pos = posInS(strat, strat->sl, p.p, p.ecart);
9096
9097 pp_Test(p.p, currRing, p.tailRing);
9098 assume(p.FDeg == p.pFDeg());
9099
9100 /* remove useless pairs from L set */
9101 for (i = 0; i <= strat->Ll; ++i)
9102 {
9103 if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0)
9104 {
9105 deleteInL(strat->L, &(strat->Ll), i, strat);
9106 i--;
9107 continue;
9108 }
9109 if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0)
9110 {
9111 deleteInL(strat->L, &(strat->Ll), i, strat);
9112 i--;
9113 }
9114 }
9115#ifdef HAVE_SHIFTBBA
9116 if (rIsLPRing(currRing))
9117 enterpairsShift(p.p, strat->sl, p.ecart, pos, strat, strat->tl); // TODO LP
9118 else
9119#endif
9120 {
9121 /* generate new pairs with p, probably removing older, now useless pairs */
9122 superenterpairs(p.p, strat->sl, p.ecart, pos, strat, strat->tl);
9123 }
9124 /* enter p to S set */
9125 strat->enterS(p, pos, strat, strat->tl);
9126
9127#ifdef HAVE_SHIFTBBA
9128 /* do this after enterS so that the index in R (which is strat->tl) is correct */
9129 if (rIsLPRing(currRing) && !strat->rightGB)
9130 enterTShift(p,strat);
9131#endif
9132}
9133
9134/*2
9135* puts p to the set T at position atT
9136*/
9137void enterT(LObject &p, kStrategy strat, int atT)
9138{
9139 int i;
9140
9141#ifdef PDEBUG
9142#ifdef HAVE_SHIFTBBA
9143 if (currRing->isLPring && p.shift > 0)
9144 {
9145 // in this case, the order is not correct. test LM and tail separately
9146 p_LmTest(p.p, currRing);
9147 p_Test(pNext(p.p), currRing);
9148 }
9149 else
9150#endif
9151 {
9152 pp_Test(p.p, currRing, p.tailRing);
9153 }
9154#endif
9155 assume(strat->tailRing == p.tailRing);
9156 // redMoraNF complains about this -- but, we don't really
9157 // need this so far
9158 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9159 assume(!strat->homog || (p.FDeg == p.pFDeg()));
9160 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9161
9162#ifdef KDEBUG
9163 // do not put an LObject twice into T:
9164 for(i=strat->tl;i>=0;i--)
9165 {
9166 if (p.p==strat->T[i].p)
9167 {
9168 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9169 return;
9170 }
9171 }
9172#endif
9173
9174#ifdef HAVE_TAIL_RING
9175 if (currRing!=strat->tailRing)
9176 {
9177 p.t_p=p.GetLmTailRing();
9178 }
9179#endif
9180 strat->newt = TRUE;
9181 if (atT < 0)
9182 atT = strat->posInT(strat->T, strat->tl, p);
9183 if (strat->tl == strat->tmax-1)
9184 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9185 if (atT <= strat->tl)
9186 {
9187#ifdef ENTER_USE_MEMMOVE
9188 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9189 (strat->tl-atT+1)*sizeof(TObject));
9190 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9191 (strat->tl-atT+1)*sizeof(unsigned long));
9192#endif
9193 for (i=strat->tl+1; i>=atT+1; i--)
9194 {
9195#ifndef ENTER_USE_MEMMOVE
9196 strat->T[i] = strat->T[i-1];
9197 strat->sevT[i] = strat->sevT[i-1];
9198#endif
9199 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9200 }
9201 }
9202
9203 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9204 {
9205#ifdef HAVE_SHIFTBBA
9206 // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9207 if (!(currRing->isLPring && p.shift > 0))
9208#endif
9209 {
9211 (strat->tailRing != NULL ?
9212 strat->tailRing : currRing),
9213 strat->tailBin);
9214 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9215 }
9216 }
9217 strat->T[atT] = (TObject) p;
9218 //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9219
9220 if ((pNext(p.p) != NULL) && (!rIsLPRing(currRing)))
9221 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9222 else
9223 strat->T[atT].max_exp = NULL;
9224
9225 strat->tl++;
9226 strat->R[strat->tl] = &(strat->T[atT]);
9227 strat->T[atT].i_r = strat->tl;
9228 assume((p.sev == 0) || (pGetShortExpVector(p.p) == p.sev));
9229 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9230 kTest_T(&(strat->T[atT]),strat);
9231}
9232
9233/*2
9234* puts p to the set T at position atT
9235*/
9236void enterT_strong(LObject &p, kStrategy strat, int atT)
9237{
9239 int i;
9240
9241 pp_Test(p.p, currRing, p.tailRing);
9242 assume(strat->tailRing == p.tailRing);
9243 // redMoraNF complains about this -- but, we don't really
9244 // need this so far
9245 assume(p.pLength == 0 || (int)pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9246 assume(p.FDeg == p.pFDeg());
9247 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9248
9249#ifdef KDEBUG
9250 // do not put an LObject twice into T:
9251 for(i=strat->tl;i>=0;i--)
9252 {
9253 if (p.p==strat->T[i].p)
9254 {
9255 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9256 return;
9257 }
9258 }
9259#endif
9260
9261#ifdef HAVE_TAIL_RING
9262 if (currRing!=strat->tailRing)
9263 {
9264 p.t_p=p.GetLmTailRing();
9265 }
9266#endif
9267 strat->newt = TRUE;
9268 if (atT < 0)
9269 atT = strat->posInT(strat->T, strat->tl, p);
9270 if (strat->tl == strat->tmax-1)
9271 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9272 if (atT <= strat->tl)
9273 {
9274#ifdef ENTER_USE_MEMMOVE
9275 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9276 (strat->tl-atT+1)*sizeof(TObject));
9277 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9278 (strat->tl-atT+1)*sizeof(unsigned long));
9279#endif
9280 for (i=strat->tl+1; i>=atT+1; i--)
9281 {
9282#ifndef ENTER_USE_MEMMOVE
9283 strat->T[i] = strat->T[i-1];
9284 strat->sevT[i] = strat->sevT[i-1];
9285#endif
9286 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9287 }
9288 }
9289
9290 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9291 {
9293 (strat->tailRing != NULL ?
9294 strat->tailRing : currRing),
9295 strat->tailBin);
9296 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9297 }
9298 strat->T[atT] = (TObject) p;
9299 //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9300
9301 if (pNext(p.p) != NULL)
9302 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9303 else
9304 strat->T[atT].max_exp = NULL;
9305
9306 strat->tl++;
9307 strat->R[strat->tl] = &(strat->T[atT]);
9308 strat->T[atT].i_r = strat->tl;
9309 assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9310 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9311 #if 1
9313 && !n_IsUnit(p.p->coef, currRing->cf))
9314 {
9315 for(i=strat->tl;i>=0;i--)
9316 {
9317 if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9318 {
9319 enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9320 }
9321 }
9322 }
9323 /*
9324 printf("\nThis is T:\n");
9325 for(i=strat->tl;i>=0;i--)
9326 {
9327 pWrite(strat->T[i].p);
9328 }
9329 //getchar();*/
9330 #endif
9331 kTest_T(&(strat->T[atT]),strat);
9332}
9333
9334/*2
9335* puts signature p.sig to the set syz
9336*/
9337void enterSyz(LObject &p, kStrategy strat, int atT)
9338{
9339 int i;
9340 strat->newt = TRUE;
9341 if (strat->syzl == strat->syzmax-1)
9342 {
9343 pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9344 strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9345 (strat->syzmax)*sizeof(unsigned long),
9346 ((strat->syzmax)+setmax)
9347 *sizeof(unsigned long));
9348 strat->syzmax += setmax;
9349 }
9350 if (atT < strat->syzl)
9351 {
9352#ifdef ENTER_USE_MEMMOVE
9353 memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9354 (strat->syzl-atT+1)*sizeof(poly));
9355 memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9356 (strat->syzl-atT+1)*sizeof(unsigned long));
9357#endif
9358 for (i=strat->syzl; i>=atT+1; i--)
9359 {
9360#ifndef ENTER_USE_MEMMOVE
9361 strat->syz[i] = strat->syz[i-1];
9362 strat->sevSyz[i] = strat->sevSyz[i-1];
9363#endif
9364 }
9365 }
9366 //i = strat->syzl;
9367 i = atT;
9368 //Makes sure the syz saves just the signature
9370 pNext(p.sig) = NULL;
9371 strat->syz[atT] = p.sig;
9372 strat->sevSyz[atT] = p.sevSig;
9373 strat->syzl++;
9374#if F5DEBUG
9375 Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9376 pWrite(strat->syz[atT]);
9377#endif
9378 // recheck pairs in strat->L with new rule and delete correspondingly
9379 int cc = strat->Ll;
9380 while (cc>-1)
9381 {
9382 //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9383 //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);
9384 if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9385 strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9387 || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9388 )
9389 {
9390 //printf("\nYES!\n");
9391 deleteInL(strat->L,&strat->Ll,cc,strat);
9392 }
9393 cc--;
9394 }
9395//#if 1
9396#ifdef DEBUGF5
9397 PrintS("--- Syzygies ---\n");
9398 Print("syzl %d\n",strat->syzl);
9399 Print("syzmax %d\n",strat->syzmax);
9400 PrintS("--------------------------------\n");
9401 for(i=0;i<=strat->syzl-1;i++)
9402 {
9403 Print("%d - ",i);
9404 pWrite(strat->syz[i]);
9405 }
9406 PrintS("--------------------------------\n");
9407#endif
9408}
9409
9410
9411void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9412{
9413
9414 //if the ordering is local, then hilb criterion
9415 //can be used also if the ideal is not homogeneous
9417 {
9419 *hilb=NULL;
9420 else
9421 return;
9422 }
9423 if (strat->homog!=isHomog)
9424 {
9425 *hilb=NULL;
9426 }
9427}
9428
9430{
9433 if (TEST_OPT_SB_1)
9436 {
9438 strat->chainCrit=chainCritRing;
9439 }
9440#ifdef HAVE_RATGRING
9441 if (rIsRatGRing(currRing))
9442 {
9443 strat->chainCrit=chainCritPart;
9444 /* enterOnePairNormal get rational part in it */
9445 }
9446#endif
9447 if (TEST_OPT_IDLIFT
9448 && (strat->syzComp==1)
9449 && (!rIsPluralRing(currRing)))
9451
9453 strat->Gebauer = strat->homog || strat->sugarCrit;
9454 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9455 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9456 strat->pairtest = NULL;
9457 /* always use tailreduction, except:
9458 * - in local rings, - in lex order case, -in ring over extensions */
9460 //if(rHasMixedOrdering(currRing)==2)
9461 //{
9462 // strat->noTailReduction =TRUE;
9463 //}
9464
9465#ifdef HAVE_PLURAL
9466 // and r is plural_ring
9467 // hence this holds for r a rational_plural_ring
9468 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9469 { //or it has non-quasi-comm type... later
9470 strat->sugarCrit = FALSE;
9471 strat->Gebauer = FALSE;
9472 strat->honey = FALSE;
9473 }
9474#endif
9475
9476 // Coefficient ring?
9478 {
9479 strat->sugarCrit = FALSE;
9480 strat->Gebauer = FALSE;
9481 strat->honey = FALSE;
9482 }
9483 #ifdef KDEBUG
9484 if (TEST_OPT_DEBUG)
9485 {
9486 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9487 else PrintS("ideal/module is not homogeneous\n");
9488 }
9489 #endif
9490}
9491
9493{
9494 //strat->enterOnePair=enterOnePairNormal;
9496 //strat->chainCrit=chainCritNormal;
9497 strat->chainCrit = chainCritSig;
9498 /******************************************
9499 * rewCrit1 and rewCrit2 are already set in
9500 * kSba() in kstd1.cc
9501 *****************************************/
9502 //strat->rewCrit1 = faugereRewCriterion;
9503 if (strat->sbaOrder == 1)
9504 {
9505 strat->syzCrit = syzCriterionInc;
9506 }
9507 else
9508 {
9509 strat->syzCrit = syzCriterion;
9510 }
9512 {
9514 strat->chainCrit=chainCritRing;
9515 }
9516#ifdef HAVE_RATGRING
9517 if (rIsRatGRing(currRing))
9518 {
9519 strat->chainCrit=chainCritPart;
9520 /* enterOnePairNormal get rational part in it */
9521 }
9522#endif
9523
9525 strat->Gebauer = strat->homog || strat->sugarCrit;
9526 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9527 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9528 strat->pairtest = NULL;
9529 /* always use tailreduction, except:
9530 * - in local rings, - in lex order case, -in ring over extensions */
9533
9534#ifdef HAVE_PLURAL
9535 // and r is plural_ring
9536 // hence this holds for r a rational_plural_ring
9537 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9538 { //or it has non-quasi-comm type... later
9539 strat->sugarCrit = FALSE;
9540 strat->Gebauer = FALSE;
9541 strat->honey = FALSE;
9542 }
9543#endif
9544
9545 // Coefficient ring?
9547 {
9548 strat->sugarCrit = FALSE;
9549 strat->Gebauer = FALSE ;
9550 strat->honey = FALSE;
9551 }
9552 #ifdef KDEBUG
9553 if (TEST_OPT_DEBUG)
9554 {
9555 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9556 else PrintS("ideal/module is not homogeneous\n");
9557 }
9558 #endif
9559}
9560
9562 (const LSet set, const int length,
9563 LObject* L,const kStrategy strat))
9564{
9565 if (pos_in_l == posInL110
9566 || pos_in_l == posInL10
9567 || pos_in_l == posInL110Ring
9568 )
9569 return TRUE;
9570
9571 return FALSE;
9572}
9573
9575{
9577 {
9578 if (strat->honey)
9579 {
9580 strat->posInL = posInL15;
9581 // ok -- here is the deal: from my experiments for Singular-2-0
9582 // I conclude that that posInT_EcartpLength is the best of
9583 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9584 // see the table at the end of this file
9585 if (TEST_OPT_OLDSTD)
9586 strat->posInT = posInT15;
9587 else
9588 strat->posInT = posInT_EcartpLength;
9589 }
9590 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9591 {
9592 strat->posInL = posInL11;
9593 strat->posInT = posInT11;
9594 }
9595 else if (TEST_OPT_INTSTRATEGY)
9596 {
9597 strat->posInL = posInL11;
9598 strat->posInT = posInT11;
9599 }
9600 else
9601 {
9602 strat->posInL = posInL0;
9603 strat->posInT = posInT0;
9604 }
9605 //if (strat->minim>0) strat->posInL =posInLSpecial;
9606 if (strat->homog)
9607 {
9608 strat->posInL = posInL110;
9609 strat->posInT = posInT110;
9610 }
9611 }
9612 else /* local/mixed ordering */
9613 {
9614 if (strat->homog)
9615 {
9616 strat->posInL = posInL11;
9617 strat->posInT = posInT11;
9618 }
9619 else
9620 {
9621 if ((currRing->order[0]==ringorder_c)
9622 ||(currRing->order[0]==ringorder_C))
9623 {
9624 strat->posInL = posInL17_c;
9625 strat->posInT = posInT17_c;
9626 }
9627 else
9628 {
9629 strat->posInL = posInL17;
9630 strat->posInT = posInT17;
9631 }
9632 }
9633 }
9634 if (strat->minim>0) strat->posInL =posInLSpecial;
9635 // for further tests only
9636 if ((BTEST1(11)) || (BTEST1(12)))
9637 strat->posInL = posInL11;
9638 else if ((BTEST1(13)) || (BTEST1(14)))
9639 strat->posInL = posInL13;
9640 else if ((BTEST1(15)) || (BTEST1(16)))
9641 strat->posInL = posInL15;
9642 else if ((BTEST1(17)) || (BTEST1(18)))
9643 strat->posInL = posInL17;
9644 if (BTEST1(11))
9645 strat->posInT = posInT11;
9646 else if (BTEST1(13))
9647 strat->posInT = posInT13;
9648 else if (BTEST1(15))
9649 strat->posInT = posInT15;
9650 else if ((BTEST1(17)))
9651 strat->posInT = posInT17;
9652 else if ((BTEST1(19)))
9653 strat->posInT = posInT19;
9654 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9655 strat->posInT = posInT1;
9657}
9658
9660{
9662 {
9663 if (strat->honey)
9664 {
9665 strat->posInL = posInL15Ring;
9666 // ok -- here is the deal: from my experiments for Singular-2-0
9667 // I conclude that that posInT_EcartpLength is the best of
9668 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9669 // see the table at the end of this file
9670 if (TEST_OPT_OLDSTD)
9671 strat->posInT = posInT15Ring;
9672 else
9673 strat->posInT = posInT_EcartpLength;
9674 }
9675 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9676 {
9677 strat->posInL = posInL11Ring;
9678 strat->posInT = posInT11;
9679 }
9680 else if (TEST_OPT_INTSTRATEGY)
9681 {
9682 strat->posInL = posInL11Ring;
9683 strat->posInT = posInT11;
9684 }
9685 else
9686 {
9687 strat->posInL = posInL0Ring;
9688 strat->posInT = posInT0;
9689 }
9690 //if (strat->minim>0) strat->posInL =posInLSpecial;
9691 if (strat->homog)
9692 {
9693 strat->posInL = posInL110Ring;
9694 strat->posInT = posInT110Ring;
9695 }
9696 }
9697 else
9698 {
9699 if (strat->homog)
9700 {
9701 //printf("\nHere 3\n");
9702 strat->posInL = posInL11Ring;
9703 strat->posInT = posInT11Ring;
9704 }
9705 else
9706 {
9707 if ((currRing->order[0]==ringorder_c)
9708 ||(currRing->order[0]==ringorder_C))
9709 {
9710 strat->posInL = posInL17_cRing;
9711 strat->posInT = posInT17_cRing;
9712 }
9713 else
9714 {
9715 strat->posInL = posInL11Ringls;
9716 strat->posInT = posInT17Ring;
9717 }
9718 }
9719 }
9720 if (strat->minim>0) strat->posInL =posInLSpecial;
9721 // for further tests only
9722 if ((BTEST1(11)) || (BTEST1(12)))
9723 strat->posInL = posInL11Ring;
9724 else if ((BTEST1(13)) || (BTEST1(14)))
9725 strat->posInL = posInL13;
9726 else if ((BTEST1(15)) || (BTEST1(16)))
9727 strat->posInL = posInL15Ring;
9728 else if ((BTEST1(17)) || (BTEST1(18)))
9729 strat->posInL = posInL17Ring;
9730 if (BTEST1(11))
9731 strat->posInT = posInT11Ring;
9732 else if (BTEST1(13))
9733 strat->posInT = posInT13;
9734 else if (BTEST1(15))
9735 strat->posInT = posInT15Ring;
9736 else if ((BTEST1(17)))
9737 strat->posInT = posInT17Ring;
9738 else if ((BTEST1(19)))
9739 strat->posInT = posInT19;
9740 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9741 strat->posInT = posInT1;
9743}
9744
9745void initBuchMora (ideal F,ideal Q,kStrategy strat)
9746{
9747 strat->interpt = BTEST1(OPT_INTERRUPT);
9748 /*- creating temp data structures------------------- -*/
9749 //strat->cp = 0; // already by skStragy()
9750 //strat->c3 = 0; // already by skStragy()
9751#ifdef HAVE_SHIFTBBA
9752 strat->cv = 0; // already by skStragy()
9753#endif
9754 strat->tail = pInit();
9755 /*- set s -*/
9756 strat->sl = -1;
9757 /*- set L -*/
9758 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9759 strat->Ll = -1;
9760 strat->L = initL(strat->Lmax);
9761 /*- set B -*/
9762 strat->Bmax = setmaxL;
9763 strat->Bl = -1;
9764 strat->B = initL();
9765 /*- set T -*/
9766 strat->tl = -1;
9767 strat->tmax = setmaxT;
9768 strat->T = initT();
9769 strat->R = initR();
9770 strat->sevT = initsevT();
9771 /*- init local data struct.---------------------------------------- -*/
9772 //strat->P.ecart=0; // already by skStragy()
9773 //strat->P.length=0; // already by skStragy()
9774 //strat->P.pLength=0; // already by skStragy()
9776 {
9777 if (strat->kNoether!=NULL)
9778 {
9779 pSetComp(strat->kNoether, strat->ak);
9780 pSetComp(strat->kNoetherTail(), strat->ak);
9781 }
9782 }
9784 {
9785 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9786 }
9787 else
9788 {
9789 if(TEST_OPT_SB_1)
9790 {
9791 int i;
9792 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
9793 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9794 {
9795 P->m[i-strat->newIdeal] = F->m[i];
9796 F->m[i] = NULL;
9797 }
9798 initSSpecial(F,Q,P,strat);
9799 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9800 {
9801 F->m[i] = P->m[i-strat->newIdeal];
9802 P->m[i-strat->newIdeal] = NULL;
9803 }
9804 idDelete(&P);
9805 }
9806 else
9807 {
9808 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9809 // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
9810 }
9811 }
9812 strat->fromT = FALSE;
9814 if ((!TEST_OPT_SB_1)
9816 )
9817 {
9818 updateS(TRUE,strat);
9819 }
9820#ifdef HAVE_SHIFTBBA
9821 if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
9822#endif
9823 {
9824 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9825 strat->fromQ=NULL;
9826 }
9827 assume(kTest_TS(strat));
9828}
9829
9831{
9832 /*- release temp data -*/
9833 cleanT(strat);
9834 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
9835 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
9836 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
9837 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
9838 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
9839 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
9840 /*- set L: should be empty -*/
9841 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
9842 /*- set B: should be empty -*/
9843 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
9844 pLmFree(&strat->tail);
9845 strat->syzComp=0;
9846
9847#ifdef HAVE_SHIFTBBA
9848 if (rIsLPRing(currRing) && strat->rightGB)
9849 {
9850 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9851 strat->fromQ=NULL;
9852 }
9853#endif
9854}
9855
9857{
9859 {
9860 if (strat->honey)
9861 {
9862 strat->posInL = posInL15;
9863 // ok -- here is the deal: from my experiments for Singular-2-0
9864 // I conclude that that posInT_EcartpLength is the best of
9865 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9866 // see the table at the end of this file
9867 if (TEST_OPT_OLDSTD)
9868 strat->posInT = posInT15;
9869 else
9870 strat->posInT = posInT_EcartpLength;
9871 }
9872 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9873 {
9874 strat->posInL = posInL11;
9875 strat->posInT = posInT11;
9876 }
9877 else if (TEST_OPT_INTSTRATEGY)
9878 {
9879 strat->posInL = posInL11;
9880 strat->posInT = posInT11;
9881 }
9882 else
9883 {
9884 strat->posInL = posInL0;
9885 strat->posInT = posInT0;
9886 }
9887 //if (strat->minim>0) strat->posInL =posInLSpecial;
9888 if (strat->homog)
9889 {
9890 strat->posInL = posInL110;
9891 strat->posInT = posInT110;
9892 }
9893 }
9894 else
9895 {
9896 if (strat->homog)
9897 {
9898 strat->posInL = posInL11;
9899 strat->posInT = posInT11;
9900 }
9901 else
9902 {
9903 if ((currRing->order[0]==ringorder_c)
9904 ||(currRing->order[0]==ringorder_C))
9905 {
9906 strat->posInL = posInL17_c;
9907 strat->posInT = posInT17_c;
9908 }
9909 else
9910 {
9911 strat->posInL = posInL17;
9912 strat->posInT = posInT17;
9913 }
9914 }
9915 }
9916 if (strat->minim>0) strat->posInL =posInLSpecial;
9917 // for further tests only
9918 if ((BTEST1(11)) || (BTEST1(12)))
9919 strat->posInL = posInL11;
9920 else if ((BTEST1(13)) || (BTEST1(14)))
9921 strat->posInL = posInL13;
9922 else if ((BTEST1(15)) || (BTEST1(16)))
9923 strat->posInL = posInL15;
9924 else if ((BTEST1(17)) || (BTEST1(18)))
9925 strat->posInL = posInL17;
9926 if (BTEST1(11))
9927 strat->posInT = posInT11;
9928 else if (BTEST1(13))
9929 strat->posInT = posInT13;
9930 else if (BTEST1(15))
9931 strat->posInT = posInT15;
9932 else if ((BTEST1(17)))
9933 strat->posInT = posInT17;
9934 else if ((BTEST1(19)))
9935 strat->posInT = posInT19;
9936 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9937 strat->posInT = posInT1;
9939 {
9940 strat->posInL = posInL11Ring;
9941 if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
9942 strat->posInL = posInL11Ringls;
9943 strat->posInT = posInT11;
9944 }
9946 strat->posInLSba = posInLSig;
9947 //strat->posInL = posInLSig;
9948 strat->posInL = posInLF5C;
9949 /*
9950 if (rField_is_Ring(currRing))
9951 {
9952 strat->posInLSba = posInLSigRing;
9953 strat->posInL = posInL11Ring;
9954 }*/
9955 //strat->posInT = posInTSig;
9956}
9957
9958void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
9959{
9960 strat->interpt = BTEST1(OPT_INTERRUPT);
9961 //strat->kNoether=NULL; // done by skStrategy
9962 /*- creating temp data structures------------------- -*/
9963 //strat->cp = 0; // done by skStrategy
9964 //strat->c3 = 0; // done by skStrategy
9965 strat->tail = pInit();
9966 /*- set s -*/
9967 strat->sl = -1;
9968 /*- set ps -*/
9969 strat->syzl = -1;
9970 /*- set L -*/
9971 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9972 strat->Ll = -1;
9973 strat->L = initL(strat->Lmax);
9974 /*- set B -*/
9975 strat->Bmax = setmaxL;
9976 strat->Bl = -1;
9977 strat->B = initL();
9978 /*- set T -*/
9979 strat->tl = -1;
9980 strat->tmax = setmaxT;
9981 strat->T = initT();
9982 strat->R = initR();
9983 strat->sevT = initsevT();
9984 /*- init local data struct.---------------------------------------- -*/
9985 //strat->P.ecart=0; // done by skStrategy
9986 //strat->P.length=0; // done by skStrategy
9988 {
9989 if (strat->kNoether!=NULL)
9990 {
9991 pSetComp(strat->kNoether, strat->ak);
9992 pSetComp(strat->kNoetherTail(), strat->ak);
9993 }
9994 }
9996 {
9997 /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
9998 }
9999 else
10000 {
10001 if(TEST_OPT_SB_1)
10002 {
10003 int i;
10004 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10005 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10006 {
10007 P->m[i-strat->newIdeal] = F->m[i];
10008 F->m[i] = NULL;
10009 }
10010 initSSpecialSba(F,Q,P,strat);
10011 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10012 {
10013 F->m[i] = P->m[i-strat->newIdeal];
10014 P->m[i-strat->newIdeal] = NULL;
10015 }
10016 idDelete(&P);
10017 }
10018 else
10019 {
10020 initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10021 }
10022 }
10023 //strat->fromT = FALSE; // done by skStrategy
10024 if (!TEST_OPT_SB_1)
10025 {
10026 if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10027 }
10028 //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10029 //strat->fromQ=NULL;
10030 assume(kTest_TS(strat));
10031}
10032
10033void exitSba (kStrategy strat)
10034{
10035 /*- release temp data -*/
10037 cleanTSbaRing(strat);
10038 else
10039 cleanT(strat);
10040 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10041 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10042 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10043 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10044 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10045 omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10046 if(strat->syzmax>0)
10047 {
10048 omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10049 omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10050 if (strat->sbaOrder == 1)
10051 {
10052 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10053 }
10054 }
10055 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10056 /*- set L: should be empty -*/
10057 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10058 /*- set B: should be empty -*/
10059 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10060 /*- set sig: no need for the signatures anymore -*/
10061 omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10062 pLmDelete(&strat->tail);
10063 strat->syzComp=0;
10064}
10065
10066/*2
10067* in the case of a standardbase of a module over a qring:
10068* replace polynomials in i by ak vectors,
10069* (the polynomial * unit vectors gen(1)..gen(ak)
10070* in every case (also for ideals:)
10071* deletes divisible vectors/polynomials
10072*/
10073void updateResult(ideal r,ideal Q, kStrategy strat)
10074{
10075 int l;
10076 if (strat->ak>0)
10077 {
10078 for (l=IDELEMS(r)-1;l>=0;l--)
10079 {
10080 if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10081 {
10082 pDelete(&r->m[l]); // and set it to NULL
10083 }
10084 }
10085 int q;
10086 poly p;
10088 {
10089 for (l=IDELEMS(r)-1;l>=0;l--)
10090 {
10091 if ((r->m[l]!=NULL)
10092 //&& (strat->syzComp>0)
10093 //&& (pGetComp(r->m[l])<=strat->syzComp)
10094 )
10095 {
10096 for(q=IDELEMS(Q)-1; q>=0;q--)
10097 {
10098 if ((Q->m[q]!=NULL)
10099 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10100 {
10101 if (TEST_OPT_REDSB)
10102 {
10103 p=r->m[l];
10104 r->m[l]=kNF(Q,NULL,p);
10105 pDelete(&p);
10106 }
10107 else
10108 {
10109 pDelete(&r->m[l]); // and set it to NULL
10110 }
10111 break;
10112 }
10113 }
10114 }
10115 }
10116 }
10117 else
10118 {
10119 for (l=IDELEMS(r)-1;l>=0;l--)
10120 {
10121 if ((r->m[l]!=NULL)
10122 //&& (strat->syzComp>0)
10123 //&& (pGetComp(r->m[l])<=strat->syzComp)
10124 )
10125 {
10126 for(q=IDELEMS(Q)-1; q>=0;q--)
10127 {
10128 if ((Q->m[q]!=NULL)
10129 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10130 {
10131 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10132 {
10133 if (TEST_OPT_REDSB)
10134 {
10135 p=r->m[l];
10136 r->m[l]=kNF(Q,NULL,p);
10137 pDelete(&p);
10138 }
10139 else
10140 {
10141 pDelete(&r->m[l]); // and set it to NULL
10142 }
10143 break;
10144 }
10145 }
10146 }
10147 }
10148 }
10149 }
10150 }
10151 else
10152 {
10153 int q;
10154 poly p;
10155 BOOLEAN reduction_found=FALSE;
10157 {
10158 for (l=IDELEMS(r)-1;l>=0;l--)
10159 {
10160 if (r->m[l]!=NULL)
10161 {
10162 for(q=IDELEMS(Q)-1; q>=0;q--)
10163 {
10164 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10165 {
10166 if (TEST_OPT_REDSB)
10167 {
10168 p=r->m[l];
10169 r->m[l]=kNF(Q,NULL,p);
10170 pDelete(&p);
10171 reduction_found=TRUE;
10172 }
10173 else
10174 {
10175 pDelete(&r->m[l]); // and set it to NULL
10176 }
10177 break;
10178 }
10179 }
10180 }
10181 }
10182 }
10183 //Also need divisibility of the leading coefficients
10184 else
10185 {
10186 for (l=IDELEMS(r)-1;l>=0;l--)
10187 {
10188 if (r->m[l]!=NULL)
10189 {
10190 for(q=IDELEMS(Q)-1; q>=0;q--)
10191 {
10192 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10193 {
10194 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10195 {
10196 if (TEST_OPT_REDSB)
10197 {
10198 p=r->m[l];
10199 r->m[l]=kNF(Q,NULL,p);
10200 pDelete(&p);
10201 reduction_found=TRUE;
10202 }
10203 else
10204 {
10205 pDelete(&r->m[l]); // and set it to NULL
10206 }
10207 break;
10208 }
10209 }
10210 }
10211 }
10212 }
10213 }
10214 if (/*TEST_OPT_REDSB &&*/ reduction_found)
10215 {
10217 {
10218 for (l=IDELEMS(r)-1;l>=0;l--)
10219 {
10220 if (r->m[l]!=NULL)
10221 {
10222 for(q=IDELEMS(r)-1;q>=0;q--)
10223 {
10224 if ((l!=q)
10225 && (r->m[q]!=NULL)
10226 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10227 &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10228 )
10229 {
10230 //If they are equal then take the one with the smallest length
10231 if(pLmDivisibleBy(r->m[q],r->m[l])
10232 && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10233 && (pLength(r->m[q]) < pLength(r->m[l]) ||
10234 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10235 {
10236 pDelete(&r->m[l]);
10237 break;
10238 }
10239 else
10240 pDelete(&r->m[q]);
10241 }
10242 }
10243 }
10244 }
10245 }
10246 else
10247 {
10248 for (l=IDELEMS(r)-1;l>=0;l--)
10249 {
10250 if (r->m[l]!=NULL)
10251 {
10252 for(q=IDELEMS(r)-1;q>=0;q--)
10253 {
10254 if ((l!=q)
10255 && (r->m[q]!=NULL)
10256 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10257 )
10258 {
10259 //If they are equal then take the one with the smallest length
10260 if(pLmDivisibleBy(r->m[q],r->m[l])
10261 &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10262 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10263 {
10264 pDelete(&r->m[l]);
10265 break;
10266 }
10267 else
10268 pDelete(&r->m[q]);
10269 }
10270 }
10271 }
10272 }
10273 }
10274 }
10275 }
10276 idSkipZeroes(r);
10277}
10278
10280{
10281 int i;
10282 int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10283 LObject L;
10284
10285#ifdef KDEBUG
10286 // need to set this: during tailreductions of T[i], T[i].max is out of
10287 // sync
10288 sloppy_max = TRUE;
10289#endif
10290
10291 strat->noTailReduction = FALSE;
10292 //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10293 if (TEST_OPT_PROT)
10294 {
10295 PrintLn();
10296// if (timerv) writeTime("standard base computed:");
10297 }
10298 if (TEST_OPT_PROT)
10299 {
10300 Print("(S:%d)",strat->sl);mflush();
10301 }
10302 for (i=strat->sl; i>=low; i--)
10303 {
10304 int end_pos=strat->sl;
10305 if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10306 if (strat->ak==0) end_pos=i-1;
10307 TObject* T_j = strat->s_2_t(i);
10308 if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10309 {
10310 L = *T_j;
10311 #ifdef KDEBUG
10312 if (TEST_OPT_DEBUG)
10313 {
10314 Print("test S[%d]:",i);
10315 p_wrp(L.p,currRing,strat->tailRing);
10316 PrintLn();
10317 }
10318 #endif
10320 strat->S[i] = redtailBba(&L, end_pos, strat, withT,FALSE /*no normalize*/);
10321 else
10322 strat->S[i] = redtail(&L, strat->sl, strat);
10323 #ifdef KDEBUG
10324 if (TEST_OPT_DEBUG)
10325 {
10326 Print("to (tailR) S[%d]:",i);
10327 p_wrp(strat->S[i],currRing,strat->tailRing);
10328 PrintLn();
10329 }
10330 #endif
10331
10332 if (strat->redTailChange)
10333 {
10334 if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10335 if (pNext(T_j->p) != NULL)
10336 T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10337 else
10338 T_j->max_exp = NULL;
10339 }
10341 T_j->pCleardenom();
10342 }
10343 else
10344 {
10345 assume(currRing == strat->tailRing);
10346 #ifdef KDEBUG
10347 if (TEST_OPT_DEBUG)
10348 {
10349 Print("test S[%d]:",i);
10350 p_wrp(strat->S[i],currRing,strat->tailRing);
10351 PrintLn();
10352 }
10353 #endif
10355 strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10356 else
10357 strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10359 {
10361 {
10362 number n;
10363 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10364 if (!nIsOne(n))
10365 {
10367 denom->n=nInvers(n);
10368 denom->next=DENOMINATOR_LIST;
10369 DENOMINATOR_LIST=denom;
10370 }
10371 nDelete(&n);
10372 }
10373 else
10374 {
10375 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10376 }
10377 }
10378 #ifdef KDEBUG
10379 if (TEST_OPT_DEBUG)
10380 {
10381 Print("to (-tailR) S[%d]:",i);
10382 p_wrp(strat->S[i],currRing,strat->tailRing);
10383 PrintLn();
10384 }
10385 #endif
10386 }
10387 if (TEST_OPT_PROT)
10388 PrintS("-");
10389 }
10390 if (TEST_OPT_PROT) PrintLn();
10391#ifdef KDEBUG
10392 sloppy_max = FALSE;
10393#endif
10394}
10395
10396
10397/*2
10398* computes the new strat->kNoether and the new pNoether,
10399* returns TRUE, if pNoether has changed
10400*/
10402{
10403 if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10404 return FALSE;
10405 int i,newHCord;
10406 poly oldNoether=strat->kNoether; // to keep previous kNoether
10407 strat->kNoether=NULL;
10408
10409#if 0
10410 if (currRing->weight_all_1)
10411 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10412 else
10413 scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kNoether);
10414#else
10415 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10416#endif
10417 if (strat->kNoether==NULL)
10418 {
10419 strat->kNoether=oldNoether;
10420 return FALSE;
10421 }
10422 // now a new kNoether, defined by scComputeHC
10423 pSetCoeff0(strat->kNoether,NULL);
10424 newHCord = p_FDeg(strat->kNoether,currRing);
10425 for(int i=currRing->N; i>0;i--)
10426 {
10427 int j=pGetExp(strat->kNoether,i);
10428 if (j>0)
10429 {
10430 j--;
10431 pSetExp(strat->kNoether,i,j);
10432 }
10433 }
10434 pSetm(strat->kNoether);
10435 if (strat->t_kNoether != NULL)
10436 {
10437 p_LmFree(strat->t_kNoether, strat->tailRing);
10438 strat->t_kNoether=NULL;
10439 }
10440 if (strat->tailRing != currRing)
10442 /* compare old and new noether*/
10443 if (newHCord < HCord) /*- statistics -*/
10444 {
10445 if (TEST_OPT_PROT)
10446 {
10447 Print("H(%d)",newHCord);
10448 mflush();
10449 }
10450 HCord=newHCord;
10451 #ifdef KDEBUG
10452 if (TEST_OPT_DEBUG)
10453 {
10454 Print("H(%d):",newHCord);
10455 wrp(strat->kNoether);
10456 PrintLn();
10457 }
10458 #endif
10459 if (oldNoether!=NULL) pLmFree(oldNoether);
10460 return TRUE;
10461 }
10462 else // no change for HCord -> no change for kNoether
10463 {
10464 p_LmFree(strat->kNoether,currRing);
10465 strat->kNoether=oldNoether;
10466 assume(strat->t_kNoether == NULL);
10467 if (strat->tailRing != currRing)
10469
10470 }
10471 return FALSE;
10472}
10473
10474/***************************************************************
10475 *
10476 * Routines related for ring changes during std computations
10477 *
10478 ***************************************************************/
10479BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10480{
10481 if (strat->overflow) return FALSE;
10482 assume(L->p1 != NULL && L->p2 != NULL);
10483 // shift changes: from 0 to -1
10484 assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10485 assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10486
10487 if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10488 return FALSE;
10489 // shift changes: extra case inserted
10490 if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10491 {
10492 return TRUE;
10493 }
10494 poly p1_max=NULL;
10495 if ((L->i_r1>=0)&&(strat->R[L->i_r1]!=NULL)) p1_max = (strat->R[L->i_r1])->max_exp;
10496 poly p2_max=NULL;
10497 if ((L->i_r2>=0)&&(strat->R[L->i_r2]!=NULL)) p2_max = (strat->R[L->i_r2])->max_exp;
10498
10499 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10500 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10501 {
10502 p_LmFree(m1, strat->tailRing);
10503 p_LmFree(m2, strat->tailRing);
10504 m1 = NULL;
10505 m2 = NULL;
10506 return FALSE;
10507 }
10508 return TRUE;
10509}
10510
10511/***************************************************************
10512 *
10513 * Checks, if we can compute the gcd poly / strong pair
10514 * gcd-poly = m1 * R[atR] + m2 * S[atS]
10515 *
10516 ***************************************************************/
10517BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10518{
10519 assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10520 //assume(strat->tailRing != currRing);
10521
10522 poly p1_max = (strat->R[atR])->max_exp;
10523 poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10524
10525 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10526 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10527 {
10528 return FALSE;
10529 }
10530 return TRUE;
10531}
10532
10533/*!
10534 used for GB over ZZ: look for constant and monomial elements in the ideal
10535 background: any known constant element of ideal suppresses
10536 intermediate coefficient swell
10537*/
10538poly preIntegerCheck(const ideal Forig, const ideal Q)
10539{
10540 if(!nCoeff_is_Z(currRing->cf))
10541 return NULL;
10542 ideal F = idCopy(Forig);
10543 idSkipZeroes(F);
10544 poly pmon;
10545 ring origR = currRing;
10546 ideal monred = idInit(1,1);
10547 for(int i=0; i<idElem(F); i++)
10548 {
10549 if(pNext(F->m[i]) == NULL)
10550 idInsertPoly(monred, pCopy(F->m[i]));
10551 }
10552 int posconst = idPosConstant(F);
10553 if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10554 {
10555 idDelete(&F);
10556 idDelete(&monred);
10557 return NULL;
10558 }
10559 int idelemQ = 0;
10560 if(Q!=NULL)
10561 {
10562 idelemQ = IDELEMS(Q);
10563 for(int i=0; i<idelemQ; i++)
10564 {
10565 if(pNext(Q->m[i]) == NULL)
10566 idInsertPoly(monred, pCopy(Q->m[i]));
10567 }
10568 idSkipZeroes(monred);
10569 posconst = idPosConstant(monred);
10570 //the constant, if found, will be from Q
10571 if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10572 {
10573 pmon = pCopy(monred->m[posconst]);
10574 idDelete(&F);
10575 idDelete(&monred);
10576 return pmon;
10577 }
10578 }
10579 ring QQ_ring = rCopy0(currRing,FALSE);
10580 nKillChar(QQ_ring->cf);
10581 QQ_ring->cf = nInitChar(n_Q, NULL);
10582 rComplete(QQ_ring,1);
10583 QQ_ring = rAssure_c_dp(QQ_ring);
10584 rChangeCurrRing(QQ_ring);
10585 nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10586 ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10587 for(int i = 0, j = 0; i<IDELEMS(F); i++)
10588 II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10589 for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10590 II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10591 ideal one = kStd(II, NULL, isNotHomog, NULL);
10592 idSkipZeroes(one);
10593 if(idIsConstant(one))
10594 {
10595 //one should be <1>
10596 for(int i = IDELEMS(II)-1; i>=0; i--)
10597 if(II->m[i] != NULL)
10598 II->m[i+1] = II->m[i];
10599 II->m[0] = pOne();
10600 ideal syz = idSyzygies(II, isNotHomog, NULL);
10601 poly integer = NULL;
10602 for(int i = IDELEMS(syz)-1;i>=0; i--)
10603 {
10604 if(pGetComp(syz->m[i]) == 1)
10605 {
10606 pSetComp(syz->m[i],0);
10607 if(pIsConstant(pHead(syz->m[i])))
10608 {
10609 integer = pHead(syz->m[i]);
10610 break;
10611 }
10612 }
10613 }
10614 rChangeCurrRing(origR);
10615 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10616 pmon = prMapR(integer, nMap2, QQ_ring, origR);
10617 idDelete(&monred);
10618 idDelete(&F);
10619 id_Delete(&II,QQ_ring);
10620 id_Delete(&one,QQ_ring);
10621 id_Delete(&syz,QQ_ring);
10622 p_Delete(&integer,QQ_ring);
10623 rDelete(QQ_ring);
10624 return pmon;
10625 }
10626 else
10627 {
10628 if(idIs0(monred))
10629 {
10630 poly mindegmon = NULL;
10631 for(int i = 0; i<IDELEMS(one); i++)
10632 {
10633 if(pNext(one->m[i]) == NULL)
10634 {
10635 if(mindegmon == NULL)
10636 mindegmon = pCopy(one->m[i]);
10637 else
10638 {
10639 if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10640 mindegmon = pCopy(one->m[i]);
10641 }
10642 }
10643 }
10644 if(mindegmon != NULL)
10645 {
10646 for(int i = IDELEMS(II)-1; i>=0; i--)
10647 if(II->m[i] != NULL)
10648 II->m[i+1] = II->m[i];
10649 II->m[0] = pCopy(mindegmon);
10650 ideal syz = idSyzygies(II, isNotHomog, NULL);
10651 bool found = FALSE;
10652 for(int i = IDELEMS(syz)-1;i>=0; i--)
10653 {
10654 if(pGetComp(syz->m[i]) == 1)
10655 {
10656 pSetComp(syz->m[i],0);
10657 if(pIsConstant(pHead(syz->m[i])))
10658 {
10659 pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10660 found = TRUE;
10661 break;
10662 }
10663 }
10664 }
10665 id_Delete(&syz,QQ_ring);
10666 if (found == FALSE)
10667 {
10668 rChangeCurrRing(origR);
10669 idDelete(&monred);
10670 idDelete(&F);
10671 id_Delete(&II,QQ_ring);
10672 id_Delete(&one,QQ_ring);
10673 rDelete(QQ_ring);
10674 return NULL;
10675 }
10676 rChangeCurrRing(origR);
10677 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10678 pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
10679 idDelete(&monred);
10680 idDelete(&F);
10681 id_Delete(&II,QQ_ring);
10682 id_Delete(&one,QQ_ring);
10683 id_Delete(&syz,QQ_ring);
10684 rDelete(QQ_ring);
10685 return pmon;
10686 }
10687 }
10688 }
10689 rChangeCurrRing(origR);
10690 idDelete(&monred);
10691 idDelete(&F);
10692 id_Delete(&II,QQ_ring);
10693 id_Delete(&one,QQ_ring);
10694 rDelete(QQ_ring);
10695 return NULL;
10696}
10697
10698/*!
10699 used for GB over ZZ: intermediate reduction by monomial elements
10700 background: any known constant element of ideal suppresses
10701 intermediate coefficient swell
10702*/
10704{
10705 if(!nCoeff_is_Z(currRing->cf))
10706 return;
10707 poly pH = h->GetP();
10708 poly p,pp;
10709 p = pH;
10710 bool deleted = FALSE, ok = FALSE;
10711 for(int i = 0; i<=strat->sl; i++)
10712 {
10713 p = pH;
10714 if(pNext(strat->S[i]) == NULL)
10715 {
10716 //pWrite(p);
10717 //pWrite(strat->S[i]);
10718 while(ok == FALSE && p != NULL)
10719 {
10720 if(pLmDivisibleBy(strat->S[i], p)
10721#ifdef HAVE_SHIFTBBA
10722 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], p))
10723#endif
10724 )
10725 {
10726 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10727 p_SetCoeff(p,dummy,currRing);
10728 }
10729 if(nIsZero(p->coef))
10730 {
10731 pLmDelete(&p);
10732 h->p = p;
10733 deleted = TRUE;
10734 }
10735 else
10736 {
10737 ok = TRUE;
10738 }
10739 }
10740 if (p!=NULL)
10741 {
10742 pp = pNext(p);
10743 while(pp != NULL)
10744 {
10745 if(pLmDivisibleBy(strat->S[i], pp)
10746#ifdef HAVE_SHIFTBBA
10747 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], pp))
10748#endif
10749 )
10750 {
10751 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10752 p_SetCoeff(pp,dummy,currRing);
10753 if(nIsZero(pp->coef))
10754 {
10755 pLmDelete(&pNext(p));
10756 pp = pNext(p);
10757 deleted = TRUE;
10758 }
10759 else
10760 {
10761 p = pp;
10762 pp = pNext(p);
10763 }
10764 }
10765 else
10766 {
10767 p = pp;
10768 pp = pNext(p);
10769 }
10770 }
10771 }
10772 }
10773 }
10774 h->SetLmCurrRing();
10775 if((deleted)&&(h->p!=NULL))
10776 strat->initEcart(h);
10777}
10778
10780{
10781 if(!nCoeff_is_Z(currRing->cf))
10782 return;
10783 poly hSig = h->sig;
10784 poly pH = h->GetP();
10785 poly p,pp;
10786 p = pH;
10787 bool deleted = FALSE, ok = FALSE;
10788 for(int i = 0; i<=strat->sl; i++)
10789 {
10790 p = pH;
10791 if(pNext(strat->S[i]) == NULL)
10792 {
10793 while(ok == FALSE && p!=NULL)
10794 {
10795 if(pLmDivisibleBy(strat->S[i], p))
10796 {
10797 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10798 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10799 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10800 {
10801 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10802 p_SetCoeff(p,dummy,currRing);
10803 }
10804 pDelete(&sigMult);
10805 }
10806 if(nIsZero(p->coef))
10807 {
10808 pLmDelete(&p);
10809 h->p = p;
10810 deleted = TRUE;
10811 }
10812 else
10813 {
10814 ok = TRUE;
10815 }
10816 }
10817 if(p == NULL)
10818 return;
10819 pp = pNext(p);
10820 while(pp != NULL)
10821 {
10822 if(pLmDivisibleBy(strat->S[i], pp))
10823 {
10824 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10825 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10826 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10827 {
10828 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10829 p_SetCoeff(pp,dummy,currRing);
10830 if(nIsZero(pp->coef))
10831 {
10832 pLmDelete(&pNext(p));
10833 pp = pNext(p);
10834 deleted = TRUE;
10835 }
10836 else
10837 {
10838 p = pp;
10839 pp = pNext(p);
10840 }
10841 }
10842 else
10843 {
10844 p = pp;
10845 pp = pNext(p);
10846 }
10847 pDelete(&sigMult);
10848 }
10849 else
10850 {
10851 p = pp;
10852 pp = pNext(p);
10853 }
10854 }
10855 }
10856 }
10857 h->SetLmCurrRing();
10858 if(deleted)
10859 strat->initEcart(h);
10860
10861}
10862
10863/*!
10864 used for GB over ZZ: final reduction by constant elements
10865 background: any known constant element of ideal suppresses
10866 intermediate coefficient swell and beautifies output
10867*/
10869{
10870 assume(strat->tl<0); /* can only be called with no elements in T:
10871 i.e. after exitBuchMora */
10872 /* do not use strat->S, strat->sl as they may be out of sync*/
10873 if(!nCoeff_is_Z(currRing->cf))
10874 return;
10875 poly p,pp;
10876 for(int j = 0; j<IDELEMS(strat->Shdl); j++)
10877 {
10878 if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
10879 {
10880 for(int i = 0; i<IDELEMS(strat->Shdl); i++)
10881 {
10882 if((i != j) && (strat->Shdl->m[i] != NULL))
10883 {
10884 p = strat->Shdl->m[i];
10885 while((p!=NULL) && (pLmDivisibleBy(strat->Shdl->m[j], p)
10886#if HAVE_SHIFTBBA
10887 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], p))
10888#endif
10889 ))
10890 {
10891 number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
10892 if (!nEqual(dummy,p->coef))
10893 {
10894 if (nIsZero(dummy))
10895 {
10896 nDelete(&dummy);
10897 pLmDelete(&strat->Shdl->m[i]);
10898 p=strat->Shdl->m[i];
10899 }
10900 else
10901 {
10902 p_SetCoeff(p,dummy,currRing);
10903 break;
10904 }
10905 }
10906 else
10907 {
10908 nDelete(&dummy);
10909 break;
10910 }
10911 }
10912 if (p!=NULL)
10913 {
10914 pp = pNext(p);
10915 while(pp != NULL)
10916 {
10917 if(pLmDivisibleBy(strat->Shdl->m[j], pp)
10918#if HAVE_SHIFTBBA
10919 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], pp))
10920#endif
10921 )
10922 {
10923 number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
10924 if (!nEqual(dummy,pp->coef))
10925 {
10926 p_SetCoeff(pp,dummy,currRing);
10927 if(nIsZero(pp->coef))
10928 {
10929 pLmDelete(&pNext(p));
10930 pp = pNext(p);
10931 }
10932 else
10933 {
10934 p = pp;
10935 pp = pNext(p);
10936 }
10937 }
10938 else
10939 {
10940 nDelete(&dummy);
10941 p = pp;
10942 pp = pNext(p);
10943 }
10944 }
10945 else
10946 {
10947 p = pp;
10948 pp = pNext(p);
10949 }
10950 }
10951 }
10952 }
10953 }
10954 //idPrint(strat->Shdl);
10955 }
10956 }
10957 idSkipZeroes(strat->Shdl);
10958}
10959
10960BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
10961{
10962 assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
10963 /* initial setup or extending */
10964
10965 if (rIsLPRing(currRing)) return TRUE;
10966 if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
10967 if (expbound >= currRing->bitmask) return FALSE;
10968 strat->overflow=FALSE;
10969 ring new_tailRing = rModifyRing(currRing,
10970 // Hmmm .. the condition pFDeg == p_Deg
10971 // might be too strong
10972 (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
10973 (strat->ak==0), // omit_comp if the input is an ideal
10974 expbound); // exp_limit
10975
10976 if (new_tailRing == currRing) return TRUE;
10977
10978 strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
10979 strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
10980
10981 if (currRing->pFDeg != currRing->pFDegOrig)
10982 {
10983 new_tailRing->pFDeg = currRing->pFDeg;
10984 new_tailRing->pLDeg = currRing->pLDeg;
10985 }
10986
10987 if (TEST_OPT_PROT)
10988 Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
10989 kTest_TS(strat);
10990 assume(new_tailRing != strat->tailRing);
10991 pShallowCopyDeleteProc p_shallow_copy_delete
10992 = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
10993
10994 omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
10995
10996 int i;
10997 for (i=0; i<=strat->tl; i++)
10998 {
10999 strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11000 p_shallow_copy_delete);
11001 }
11002 for (i=0; i<=strat->Ll; i++)
11003 {
11004 assume(strat->L[i].p != NULL);
11005 if (pNext(strat->L[i].p) != strat->tail)
11006 strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11007 }
11008 if ((strat->P.t_p != NULL) ||
11009 ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11010 strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11011
11012 if ((L != NULL) && (L->tailRing != new_tailRing))
11013 {
11014 if (L->i_r < 0)
11015 L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11016 else
11017 {
11018 assume(L->i_r <= strat->tl);
11019 TObject* t_l = strat->R[L->i_r];
11020 assume(t_l != NULL);
11021 L->tailRing = new_tailRing;
11022 L->p = t_l->p;
11023 L->t_p = t_l->t_p;
11024 L->max_exp = t_l->max_exp;
11025 }
11026 }
11027
11028 if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11029 T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11030
11031 omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11032 if (strat->tailRing != currRing)
11034
11035 strat->tailRing = new_tailRing;
11036 strat->tailBin = new_tailBin;
11038 = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11039
11040 if (strat->kNoether != NULL)
11041 {
11042 if (strat->t_kNoether != NULL)
11043 p_LmFree(strat->t_kNoether, strat->tailRing);
11044 strat->t_kNoether=k_LmInit_currRing_2_tailRing(strat->kNoether, new_tailRing);
11045 }
11046
11047 kTest_TS(strat);
11048 if (TEST_OPT_PROT)
11049 PrintS("]");
11050 return TRUE;
11051}
11052
11054{
11055 unsigned long l = 0;
11056 int i;
11057 long e;
11058
11059 assume(strat->tailRing == currRing);
11060
11061 for (i=0; i<= strat->Ll; i++)
11062 {
11063 l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11064 }
11065 for (i=0; i<=strat->tl; i++)
11066 {
11067 // Hmm ... this we could do in one Step
11068 l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11069 }
11071 {
11072 l *= 2;
11073 }
11074 e = p_GetMaxExp(l, currRing);
11075 if (e <= 1) e = 2;
11076 if (rIsLPRing(currRing)) e = 1;
11077
11078 kStratChangeTailRing(strat, NULL, NULL, e);
11079}
11080
11081ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11082{
11083 int n = rBlocks(r); // Including trailing zero!
11084 // if sbaOrder == 1 => use (C,monomial order from r)
11085 if (strat->sbaOrder == 1)
11086 {
11087 if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11088 {
11089 return r;
11090 }
11091 ring res = rCopy0(r, TRUE, FALSE);
11092 res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11093 res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11094 res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11095 int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11096 res->wvhdl = wvhdl;
11097 for (int i=1; i<n; i++)
11098 {
11099 res->order[i] = r->order[i-1];
11100 res->block0[i] = r->block0[i-1];
11101 res->block1[i] = r->block1[i-1];
11102 res->wvhdl[i] = r->wvhdl[i-1];
11103 }
11104
11105 // new 1st block
11106 res->order[0] = ringorder_C; // Prefix
11107 // removes useless secondary component order if defined in old ring
11108 for (int i=rBlocks(res); i>0; --i)
11109 {
11110 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11111 {
11112 res->order[i] = (rRingOrder_t)0;
11113 }
11114 }
11115 rComplete(res, 1);
11116#ifdef HAVE_PLURAL
11117 if (rIsPluralRing(r))
11118 {
11119 if ( nc_rComplete(r, res, false) ) // no qideal!
11120 {
11121#ifndef SING_NDEBUG
11122 WarnS("error in nc_rComplete");
11123#endif
11124 // cleanup?
11125
11126 // rDelete(res);
11127 // return r;
11128
11129 // just go on..
11130 }
11131 }
11132#endif
11133 strat->tailRing = res;
11134 return (res);
11135 }
11136 // if sbaOrder == 3 => degree - position - ring order
11137 if (strat->sbaOrder == 3)
11138 {
11139 ring res = rCopy0(r, TRUE, FALSE);
11140 res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11141 res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11142 res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11143 int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11144 res->wvhdl = wvhdl;
11145 for (int i=2; i<n+2; i++)
11146 {
11147 res->order[i] = r->order[i-2];
11148 res->block0[i] = r->block0[i-2];
11149 res->block1[i] = r->block1[i-2];
11150 res->wvhdl[i] = r->wvhdl[i-2];
11151 }
11152
11153 // new 1st block
11154 res->order[0] = ringorder_a; // Prefix
11155 res->block0[0] = 1;
11156 res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11157 for (int i=0; i<res->N; ++i)
11158 res->wvhdl[0][i] = 1;
11159 res->block1[0] = si_min(res->N, rVar(res));
11160 // new 2nd block
11161 res->order[1] = ringorder_C; // Prefix
11162 res->wvhdl[1] = NULL;
11163 // removes useless secondary component order if defined in old ring
11164 for (int i=rBlocks(res); i>1; --i)
11165 {
11166 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11167 {
11168 res->order[i] = (rRingOrder_t)0;
11169 }
11170 }
11171 rComplete(res, 1);
11172#ifdef HAVE_PLURAL
11173 if (rIsPluralRing(r))
11174 {
11175 if ( nc_rComplete(r, res, false) ) // no qideal!
11176 {
11177#ifndef SING_NDEBUG
11178 WarnS("error in nc_rComplete");
11179#endif
11180 // cleanup?
11181
11182 // rDelete(res);
11183 // return r;
11184
11185 // just go on..
11186 }
11187 }
11188#endif
11189 strat->tailRing = res;
11190 return (res);
11191 }
11192
11193 // not sbaOrder == 1 => use Schreyer order
11194 // this is done by a trick when initializing the signatures
11195 // in initSLSba():
11196 // Instead of using the signature 1e_i for F->m[i], we start
11197 // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11198 // Schreyer order w.r.t. the underlying monomial order.
11199 // => we do not need to change the underlying polynomial ring at all!
11200
11201 // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11202
11203 /*
11204 else
11205 {
11206 ring res = rCopy0(r, FALSE, FALSE);
11207 // Create 2 more blocks for prefix/suffix:
11208 res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11209 res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11210 res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11211 int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11212
11213 // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11214 // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11215
11216 // new 1st block
11217 int j = 0;
11218 res->order[j] = ringorder_IS; // Prefix
11219 res->block0[j] = res->block1[j] = 0;
11220 // wvhdl[j] = NULL;
11221 j++;
11222
11223 for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11224 {
11225 res->order [j] = r->order [i];
11226 res->block0[j] = r->block0[i];
11227 res->block1[j] = r->block1[i];
11228
11229 if (r->wvhdl[i] != NULL)
11230 {
11231 wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11232 } // else wvhdl[j] = NULL;
11233 }
11234
11235 // new last block
11236 res->order [j] = ringorder_IS; // Suffix
11237 res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11238 // wvhdl[j] = NULL;
11239 j++;
11240
11241 // res->order [j] = 0; // The End!
11242 res->wvhdl = wvhdl;
11243
11244 // j == the last zero block now!
11245 assume(j == (n+1));
11246 assume(res->order[0]==ringorder_IS);
11247 assume(res->order[j-1]==ringorder_IS);
11248 assume(res->order[j]==0);
11249
11250 if (complete)
11251 {
11252 rComplete(res, 1);
11253
11254#ifdef HAVE_PLURAL
11255 if (rIsPluralRing(r))
11256 {
11257 if ( nc_rComplete(r, res, false) ) // no qideal!
11258 {
11259 }
11260 }
11261 assume(rIsPluralRing(r) == rIsPluralRing(res));
11262#endif
11263
11264
11265#ifdef HAVE_PLURAL
11266 ring old_ring = r;
11267
11268#endif
11269
11270 if (r->qideal!=NULL)
11271 {
11272 res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11273
11274 assume(idRankFreeModule(res->qideal, res) == 0);
11275
11276#ifdef HAVE_PLURAL
11277 if( rIsPluralRing(res) )
11278 if( nc_SetupQuotient(res, r, true) )
11279 {
11280 // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11281 }
11282
11283#endif
11284 assume(idRankFreeModule(res->qideal, res) == 0);
11285 }
11286
11287#ifdef HAVE_PLURAL
11288 assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11289 assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11290 assume(rIsSCA(res) == rIsSCA(old_ring));
11291 assume(ncRingType(res) == ncRingType(old_ring));
11292#endif
11293 }
11294 strat->tailRing = res;
11295 return res;
11296 }
11297 */
11298
11299 assume(FALSE);
11300 return(NULL);
11301}
11302
11304{
11305 memset(this, 0, sizeof(skStrategy));
11306 strat_nr++;
11307 nr=strat_nr;
11309 P.tailRing = currRing;
11310 tl = -1;
11311 sl = -1;
11312#ifdef HAVE_LM_BIN
11314#endif
11315#ifdef HAVE_TAIL_BIN
11317#endif
11318 pOrigFDeg = currRing->pFDeg;
11319 pOrigLDeg = currRing->pLDeg;
11320}
11321
11322
11324{
11326 if (lmBin != NULL)
11328 if (tailBin != NULL)// && !rField_is_Ring(currRing))
11330 ((tailRing != NULL) ? tailRing->PolyBin:
11331 currRing->PolyBin));
11332 if (t_kNoether != NULL)
11334
11335 if (currRing != tailRing)
11338}
11339
11340#if 0
11341Timings for the different possibilities of posInT:
11342 T15 EDL DL EL L 1-2-3
11343Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11344Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11345Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11346ahml 4.48 4.03 4.03 4.38 4.96 26.50
11347c7 15.02 13.98 15.16 13.24 17.31 47.89
11348c8 505.09 407.46 852.76 413.21 499.19 n/a
11349f855 12.65 9.27 14.97 8.78 14.23 33.12
11350gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11351gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11352ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11353noon8 40.68 37.02 37.99 36.82 35.59 877.16
11354rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11355rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11356schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11357test016 16.39 14.17 14.40 13.50 14.26 34.07
11358test017 34.70 36.01 33.16 35.48 32.75 71.45
11359test042 10.76 10.99 10.27 11.57 10.45 23.04
11360test058 6.78 6.75 6.51 6.95 6.22 9.47
11361test066 10.71 10.94 10.76 10.61 10.56 19.06
11362test073 10.75 11.11 10.17 10.79 8.63 58.10
11363test086 12.23 11.81 12.88 12.24 13.37 66.68
11364test103 5.05 4.80 5.47 4.64 4.89 11.90
11365test154 12.96 11.64 13.51 12.46 14.61 36.35
11366test162 65.27 64.01 67.35 59.79 67.54 196.46
11367test164 7.50 6.50 7.68 6.70 7.96 17.13
11368virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11369#endif
11370
11371
11372//#ifdef HAVE_MORE_POS_IN_T
11373#if 1
11374// determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11376{
11377
11378 if (length==-1) return 0;
11379
11380 int o = p.ecart;
11381 int op=p.GetpFDeg();
11382 int ol = p.GetpLength();
11383
11384 if (set[length].ecart < o)
11385 return length+1;
11386 if (set[length].ecart == o)
11387 {
11388 int oo=set[length].GetpFDeg();
11389 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11390 return length+1;
11391 }
11392
11393 int i;
11394 int an = 0;
11395 int en= length;
11396 loop
11397 {
11398 if (an >= en-1)
11399 {
11400 if (set[an].ecart > o)
11401 return an;
11402 if (set[an].ecart == o)
11403 {
11404 int oo=set[an].GetpFDeg();
11405 if((oo > op)
11406 || ((oo==op) && (set[an].pLength > ol)))
11407 return an;
11408 }
11409 return en;
11410 }
11411 i=(an+en) / 2;
11412 if (set[i].ecart > o)
11413 en=i;
11414 else if (set[i].ecart == o)
11415 {
11416 int oo=set[i].GetpFDeg();
11417 if ((oo > op)
11418 || ((oo == op) && (set[i].pLength > ol)))
11419 en=i;
11420 else
11421 an=i;
11422 }
11423 else
11424 an=i;
11425 }
11426}
11427
11428// determines the position based on: 1.) FDeg 2.) pLength
11429int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11430{
11431
11432 if (length==-1) return 0;
11433
11434 int op=p.GetpFDeg();
11435 int ol = p.GetpLength();
11436
11437 int oo=set[length].GetpFDeg();
11438 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11439 return length+1;
11440
11441 int i;
11442 int an = 0;
11443 int en= length;
11444 loop
11445 {
11446 if (an >= en-1)
11447 {
11448 int oo=set[an].GetpFDeg();
11449 if((oo > op)
11450 || ((oo==op) && (set[an].pLength > ol)))
11451 return an;
11452 return en;
11453 }
11454 i=(an+en) / 2;
11455 int oo=set[i].GetpFDeg();
11456 if ((oo > op)
11457 || ((oo == op) && (set[i].pLength > ol)))
11458 en=i;
11459 else
11460 an=i;
11461 }
11462}
11463
11464
11465// determines the position based on: 1.) pLength
11466int posInT_pLength(const TSet set,const int length,LObject &p)
11467{
11468 int ol = p.GetpLength();
11469 if (length==-1)
11470 return 0;
11471 if (set[length].length<p.length)
11472 return length+1;
11473
11474 int i;
11475 int an = 0;
11476 int en= length;
11477
11478 loop
11479 {
11480 if (an >= en-1)
11481 {
11482 if (set[an].pLength>ol) return an;
11483 return en;
11484 }
11485 i=(an+en) / 2;
11486 if (set[i].pLength>ol) en=i;
11487 else an=i;
11488 }
11489}
11490#endif
11491
11492// kstd1.cc:
11493int redFirst (LObject* h,kStrategy strat);
11494int redEcart (LObject* h,kStrategy strat);
11495void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11496void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11497// ../Singular/misc.cc:
11498extern char * showOption();
11499
11501{
11502 printf("red: ");
11503 if (strat->red==redFirst) printf("redFirst\n");
11504 else if (strat->red==redHoney) printf("redHoney\n");
11505 else if (strat->red==redEcart) printf("redEcart\n");
11506 else if (strat->red==redHomog) printf("redHomog\n");
11507 else if (strat->red==redLazy) printf("redLazy\n");
11508 else if (strat->red==redLiftstd) printf("redLiftstd\n");
11509 else printf("%p\n",(void*)strat->red);
11510 printf("posInT: ");
11511 if (strat->posInT==posInT0) printf("posInT0\n");
11512 else if (strat->posInT==posInT1) printf("posInT1\n");
11513 else if (strat->posInT==posInT11) printf("posInT11\n");
11514 else if (strat->posInT==posInT110) printf("posInT110\n");
11515 else if (strat->posInT==posInT13) printf("posInT13\n");
11516 else if (strat->posInT==posInT15) printf("posInT15\n");
11517 else if (strat->posInT==posInT17) printf("posInT17\n");
11518 else if (strat->posInT==posInT17_c) printf("posInT17_c\n");
11519 else if (strat->posInT==posInT19) printf("posInT19\n");
11520 else if (strat->posInT==posInT2) printf("posInT2\n");
11521 else if (strat->posInT==posInT11Ring) printf("posInT11Ring\n");
11522 else if (strat->posInT==posInT110Ring) printf("posInT110Ring\n");
11523 else if (strat->posInT==posInT15Ring) printf("posInT15Ring\n");
11524 else if (strat->posInT==posInT17Ring) printf("posInT17Ring\n");
11525 else if (strat->posInT==posInT17_cRing) printf("posInT17_cRing\n");
11526#ifdef HAVE_MORE_POS_IN_T
11527 else if (strat->posInT==posInT_EcartFDegpLength) printf("posInT_EcartFDegpLength\n");
11528 else if (strat->posInT==posInT_FDegpLength) printf("posInT_FDegpLength\n");
11529 else if (strat->posInT==posInT_pLength) printf("posInT_pLength\n");
11530#endif
11531 else if (strat->posInT==posInT_EcartpLength) printf("posInT_EcartpLength\n");
11532 else printf("%p\n",(void*)strat->posInT);
11533 printf("posInL: ");
11534 if (strat->posInL==posInL0) printf("posInL0\n");
11535 else if (strat->posInL==posInL10) printf("posInL10\n");
11536 else if (strat->posInL==posInL11) printf("posInL11\n");
11537 else if (strat->posInL==posInL110) printf("posInL110\n");
11538 else if (strat->posInL==posInL13) printf("posInL13\n");
11539 else if (strat->posInL==posInL15) printf("posInL15\n");
11540 else if (strat->posInL==posInL17) printf("posInL17\n");
11541 else if (strat->posInL==posInL17_c) printf("posInL17_c\n");
11542 else if (strat->posInL==posInL0) printf("posInL0Ring\n");
11543 else if (strat->posInL==posInL11Ring) printf("posInL11Ring\n");
11544 else if (strat->posInL==posInL11Ringls) printf("posInL11Ringls\n");
11545 else if (strat->posInL==posInL110Ring) printf("posInL110Ring\n");
11546 else if (strat->posInL==posInL15Ring) printf("posInL15Ring\n");
11547 else if (strat->posInL==posInL17Ring) printf("posInL17Ring\n");
11548 else if (strat->posInL==posInL17_cRing) printf("posInL17_cRing\n");
11549 else if (strat->posInL==posInLSpecial) printf("posInLSpecial\n");
11550 else printf("%p\n",(void*)strat->posInL);
11551 printf("enterS: ");
11552 if (strat->enterS==enterSBba) printf("enterSBba\n");
11553 else if (strat->enterS==enterSMora) printf("enterSMora\n");
11554 else if (strat->enterS==enterSMoraNF) printf("enterSMoraNF\n");
11555 else printf("%p\n",(void*)strat->enterS);
11556 printf("initEcart: ");
11557 if (strat->initEcart==initEcartBBA) printf("initEcartBBA\n");
11558 else if (strat->initEcart==initEcartNormal) printf("initEcartNormal\n");
11559 else printf("%p\n",(void*)strat->initEcart);
11560 printf("initEcartPair: ");
11561 if (strat->initEcartPair==initEcartPairBba) printf("initEcartPairBba\n");
11562 else if (strat->initEcartPair==initEcartPairMora) printf("initEcartPairMora\n");
11563 else printf("%p\n",(void*)strat->initEcartPair);
11564 printf("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11565 strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11566 printf("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11567 strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11568 printf("chainCrit: ");
11569 if (strat->chainCrit==chainCritNormal) printf("chainCritNormal\n");
11570 else if (strat->chainCrit==chainCritOpt_1) printf("chainCritOpt_1\n");
11571 else printf("%p\n",(void*)strat->chainCrit);
11572 printf("posInLDependsOnLength=%d\n",
11573 strat->posInLDependsOnLength);
11574 printf("%s\n",showOption());
11575 printf("LDeg: ");
11576 if (currRing->pLDeg==pLDeg0) printf("pLDeg0");
11577 else if (currRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11578 else if (currRing->pLDeg==pLDegb) printf("pLDegb");
11579 else if (currRing->pLDeg==pLDeg1) printf("pLDeg1");
11580 else if (currRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11581 else if (currRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11582 else if (currRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11583 else if (currRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11584 else if (currRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11585 else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11586 else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11587 else if (currRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11588 else printf("? (%lx)", (long)currRing->pLDeg);
11589 printf(" / ");
11590 if (strat->tailRing->pLDeg==pLDeg0) printf("pLDeg0");
11591 else if (strat->tailRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11592 else if (strat->tailRing->pLDeg==pLDegb) printf("pLDegb");
11593 else if (strat->tailRing->pLDeg==pLDeg1) printf("pLDeg1");
11594 else if (strat->tailRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11595 else if (strat->tailRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11596 else if (strat->tailRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11597 else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11598 else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11599 else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11600 else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11601 else if (strat->tailRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11602 else printf("? (%lx)", (long)strat->tailRing->pLDeg);
11603 printf("\n");
11604 printf("currRing->pFDeg: ");
11605 if (currRing->pFDeg==p_Totaldegree) printf("p_Totaldegree");
11606 else if (currRing->pFDeg==p_WFirstTotalDegree) printf("pWFirstTotalDegree");
11607 else if (currRing->pFDeg==p_Deg) printf("p_Deg");
11608 else if (currRing->pFDeg==kHomModDeg) printf("kHomModDeg");
11609 else if (currRing->pFDeg==totaldegreeWecart) printf("totaldegreeWecart");
11610 else if (currRing->pFDeg==p_WTotaldegree) printf("p_WTotaldegree");
11611 else printf("? (%lx)", (long)currRing->pFDeg);
11612 printf("\n");
11613 printf(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11615 printf(" degBound: %d\n", Kstd1_deg);
11616
11617 if( ecartWeights != NULL )
11618 {
11619 printf("ecartWeights: ");
11620 for (int i = rVar(currRing); i > 0; i--)
11621 printf("%hd ", ecartWeights[i]);
11622 printf("\n");
11624 }
11625
11626#ifndef SING_NDEBUG
11628#endif
11629}
11630
11631//LObject pCopyp2L(poly p, kStrategy strat)
11632//{
11633 /* creates LObject from the poly in currRing */
11634 /* actually put p into L.p and make L.t_p=NULL : does not work */
11635
11636//}
11637
11638/*2
11639* put the lcm(q,p) into the set B, q is the shift of some s[i]
11640*/
11641#ifdef HAVE_SHIFTBBA
11642static BOOLEAN enterOneStrongPolyShift (poly q, poly p, int /*ecart*/, int /*isFromQ*/, kStrategy strat, int atR, int /*ecartq*/, int /*qisFromQ*/, int shiftcount, int ifromS)
11643{
11644 number d, s, t;
11645 /* assume(atR >= 0); */
11646 assume(ifromS <= strat->sl);
11648 poly m1, m2, gcd;
11649 //printf("\n--------------------------------\n");
11650 //pWrite(p);pWrite(si);
11651 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q), &s, &t, currRing->cf);
11652
11653 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
11654 {
11655 nDelete(&d);
11656 nDelete(&s);
11657 nDelete(&t);
11658 return FALSE;
11659 }
11660
11661 assume(pIsInV(p));
11662
11663 k_GetStrongLeadTerms(p, q, currRing, m1, m2, gcd, strat->tailRing);
11664
11665 /* the V criterion */
11666 if (!pmIsInV(gcd))
11667 {
11668 strat->cv++;
11669 nDelete(&d);
11670 nDelete(&s);
11671 nDelete(&t);
11672 pLmFree(gcd);
11673 return FALSE;
11674 }
11675
11676 // disabled for Letterplace because it is not so easy to check
11677 /* if (!rHasLocalOrMixedOrdering(currRing)) { */
11678 /* unsigned long sev = pGetShortExpVector(gcd); */
11679
11680 /* for (int j = 0; j < strat->sl; j++) { */
11681 /* if (j == i) */
11682 /* continue; */
11683
11684 /* if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) && */
11685 /* !(strat->sevS[j] & ~sev) && */
11686 /* p_LmDivisibleBy(strat->S[j], gcd, currRing)) { */
11687 /* nDelete(&d); */
11688 /* nDelete(&s); */
11689 /* nDelete(&t); */
11690 /* return FALSE; */
11691 /* } */
11692 /* } */
11693 /* } */
11694
11695 poly m12, m22;
11699 // manually free the coeffs, because pSetCoeff0 is used in the next step
11700 n_Delete(&(m1->coef), currRing->cf);
11701 n_Delete(&(m2->coef), currRing->cf);
11702
11703 //p_Test(m1,strat->tailRing);
11704 //p_Test(m2,strat->tailRing);
11705 /*if(!enterTstrong)
11706 {
11707 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
11708 {
11709 memset(&(strat->P), 0, sizeof(strat->P));
11710 kStratChangeTailRing(strat);
11711 strat->P = *(strat->R[atR]);
11712 p_LmFree(m1, strat->tailRing);
11713 p_LmFree(m2, strat->tailRing);
11714 p_LmFree(gcd, currRing);
11715 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
11716 }
11717 }*/
11718 pSetCoeff0(m1, s);
11719 pSetCoeff0(m2, t);
11720 pSetCoeff0(gcd, d);
11721 p_Test(m1,strat->tailRing);
11722 p_Test(m2,strat->tailRing);
11723 p_Test(m12,strat->tailRing);
11724 p_Test(m22,strat->tailRing);
11725 assume(pmIsInV(m1));
11726 assume(pmIsInV(m2));
11727 assume(pmIsInV(m12));
11728 assume(pmIsInV(m22));
11729 //printf("\n===================================\n");
11730 //pWrite(m1);pWrite(m2);pWrite(gcd);
11731#ifdef KDEBUG
11732 if (TEST_OPT_DEBUG)
11733 {
11734 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
11735 PrintS("m1 = ");
11736 p_wrp(m1, strat->tailRing);
11737 PrintS("m12 = ");
11738 p_wrp(m12, strat->tailRing);
11739 PrintS(" ; m2 = ");
11740 p_wrp(m2, strat->tailRing);
11741 PrintS(" ; m22 = ");
11742 p_wrp(m22, strat->tailRing);
11743 PrintS(" ; gcd = ");
11744 wrp(gcd);
11745 PrintS("\n--- create strong gcd poly: ");
11746 PrintS("\n p: ");
11747 wrp(p);
11748 Print("\n q (strat->S[%d]): ", ifromS);
11749 wrp(q);
11750 PrintS(" ---> ");
11751 }
11752#endif
11753
11754 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);
11755 p_LmDelete(m1, strat->tailRing);
11756 p_LmDelete(m2, strat->tailRing);
11757 p_LmDelete(m12, strat->tailRing);
11758 p_LmDelete(m22, strat->tailRing);
11759
11760 assume(pIsInV(gcd));
11761
11762#ifdef KDEBUG
11763 if (TEST_OPT_DEBUG)
11764 {
11765 wrp(gcd);
11766 PrintLn();
11767 }
11768#endif
11769
11770 LObject h;
11771 h.p = gcd;
11772 h.tailRing = strat->tailRing;
11773 int posx;
11774 strat->initEcart(&h);
11775 h.sev = pGetShortExpVector(h.p);
11776 h.i_r1 = -1;h.i_r2 = -1;
11777 if (currRing!=strat->tailRing)
11778 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
11779#if 1
11780 h.p1 = p;
11781 h.p2 = q;
11782#endif
11783 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
11784 {
11785 h.i_r2 = kFindInT(h.p1, strat);
11786 h.i_r1 = atR;
11787 }
11788 else
11789 {
11790 h.i_r1 = -1;
11791 h.i_r2 = -1;
11792 }
11793 if (strat->Ll==-1)
11794 posx =0;
11795 else
11796 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
11797
11798 assume(pIsInV(h.p));
11799 assume(pIsInV(h.p1));
11800
11801 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
11802 return TRUE;
11803}
11804#endif
11805
11806
11807/*2
11808* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i] (ring case)
11809*/
11810#ifdef HAVE_SHIFTBBA
11811static void enterOnePairRingShift (poly q, poly p, int /*ecart*/, int isFromQ, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
11812{
11813 /* assume(atR >= 0); */
11814 /* assume(i<=strat->sl); */
11815 assume(p!=NULL);
11817 assume(pIsInV(p));
11818 #if ALL_VS_JUST
11819 //Over rings, if we construct the strong pair, do not add the spair
11821 {
11822 number s,t,d;
11823 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q, &s, &t, currRing->cf);
11824
11825 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
11826 {
11827 nDelete(&d);
11828 nDelete(&s);
11829 nDelete(&t);
11830 return;
11831 }
11832 nDelete(&d);
11833 nDelete(&s);
11834 nDelete(&t);
11835 }
11836 #endif
11837 int j,compare,compareCoeff;
11838 LObject h;
11839
11840#ifdef KDEBUG
11841 h.ecart=0; h.length=0;
11842#endif
11843 /*- computes the lcm(s[i],p) -*/
11844 if(pHasNotCFRing(p,q))
11845 {
11846 strat->cp++;
11847 return;
11848 }
11849 h.lcm = p_Lcm(p,q,currRing);
11850 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(q), currRing->cf));
11851 if (nIsZero(pGetCoeff(h.lcm)))
11852 {
11853 strat->cp++;
11854 pLmDelete(h.lcm);
11855 return;
11856 }
11857
11858 /* the V criterion */
11859 if (!pmIsInV(h.lcm))
11860 {
11861 strat->cv++;
11862 pLmDelete(h.lcm);
11863 return;
11864 }
11865 // basic chain criterion
11866 /*
11867 *the set B collects the pairs of type (S[j],p)
11868 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
11869 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
11870 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
11871 */
11872
11873 for(j = strat->Bl;j>=0;j--)
11874 {
11875 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
11876 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
11877 if(compare == pDivComp_EQUAL)
11878 {
11879 //They have the same LM
11880 if(compareCoeff == pDivComp_LESS)
11881 {
11882 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11883 {
11884 strat->c3++;
11885 pLmDelete(h.lcm);
11886 return;
11887 }
11888 break;
11889 }
11890 if(compareCoeff == pDivComp_GREATER)
11891 {
11892 deleteInL(strat->B,&strat->Bl,j,strat);
11893 strat->c3++;
11894 }
11895 if(compareCoeff == pDivComp_EQUAL)
11896 {
11897 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11898 {
11899 strat->c3++;
11900 pLmDelete(h.lcm);
11901 return;
11902 }
11903 break;
11904 }
11905 }
11906 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
11907 {
11908 if(compare == pDivComp_LESS)
11909 {
11910 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11911 {
11912 strat->c3++;
11913 pLmDelete(h.lcm);
11914 return;
11915 }
11916 break;
11917 }
11918 if(compare == pDivComp_GREATER)
11919 {
11920 deleteInL(strat->B,&strat->Bl,j,strat);
11921 strat->c3++;
11922 }
11923 }
11924 }
11925 number s, t;
11926 poly m1, m2, gcd = NULL;
11927 s = pGetCoeff(q);
11928 t = pGetCoeff(p);
11930
11931 poly m12, m22;
11935 // manually free the coeffs, because pSetCoeff0 is used in the next step
11936 n_Delete(&(m1->coef), currRing->cf);
11937 n_Delete(&(m2->coef), currRing->cf);
11938
11939 ksCheckCoeff(&s, &t, currRing->cf);
11940 pSetCoeff0(m1, s);
11941 pSetCoeff0(m2, t);
11942 m2 = pNeg(m2);
11943 p_Test(m1,strat->tailRing);
11944 p_Test(m2,strat->tailRing);
11945 p_Test(m12,strat->tailRing);
11946 p_Test(m22,strat->tailRing);
11947 assume(pmIsInV(m1));
11948 assume(pmIsInV(m2));
11949 assume(pmIsInV(m12));
11950 assume(pmIsInV(m22));
11951 poly pm1 = pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing);
11952 poly sim2 = pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing);
11953 assume(pIsInV(pm1));
11954 assume(pIsInV(sim2));
11955 p_LmDelete(m1, currRing);
11956 p_LmDelete(m2, currRing);
11957 p_LmDelete(m12, currRing);
11958 p_LmDelete(m22, currRing);
11959 if(sim2 == NULL)
11960 {
11961 if(pm1 == NULL)
11962 {
11963 if(h.lcm != NULL)
11964 {
11965 pLmDelete(h.lcm);
11966 h.lcm=NULL;
11967 }
11968 h.Clear();
11969 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
11970 /* if (strat->pairtest==NULL) initPairtest(strat); */
11971 /* strat->pairtest[i] = TRUE; */
11972 /* strat->pairtest[strat->sl+1] = TRUE; */
11973 return;
11974 }
11975 else
11976 {
11977 gcd = pm1;
11978 pm1 = NULL;
11979 }
11980 }
11981 else
11982 {
11983 if((pGetComp(q) == 0) && (0 != pGetComp(p)))
11984 {
11985 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
11986 pSetmComp(sim2);
11987 }
11988 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
11989 gcd = p_Add_q(pm1, sim2, strat->tailRing);
11990 }
11991 p_Test(gcd, strat->tailRing);
11992 assume(pIsInV(gcd));
11993#ifdef KDEBUG
11994 if (TEST_OPT_DEBUG)
11995 {
11996 wrp(gcd);
11997 PrintLn();
11998 }
11999#endif
12000 h.p = gcd;
12001 h.i_r = -1;
12002 if(h.p == NULL)
12003 {
12004 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12005 /* if (strat->pairtest==NULL) initPairtest(strat); */
12006 /* strat->pairtest[i] = TRUE; */
12007 /* strat->pairtest[strat->sl+1] = TRUE; */
12008 return;
12009 }
12010 h.tailRing = strat->tailRing;
12011 int posx;
12012 //h.pCleardenom();
12013 //pSetm(h.p);
12014 h.i_r1 = -1;h.i_r2 = -1;
12015 strat->initEcart(&h);
12016 #if 1
12017 h.p1 = p;
12018 h.p2 = q;
12019 #endif
12020 #if 1
12021 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12022 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12023 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12024 {
12025 h.i_r2 = kFindInT(h.p1, strat); //strat->S_2_R[i];
12026 h.i_r1 = atR;
12027 }
12028 else
12029 {
12030 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12031 h.i_r1 = -1;
12032 h.i_r2 = -1;
12033 }
12034 #endif
12035 if (strat->Bl==-1)
12036 posx =0;
12037 else
12038 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
12039 h.sev = pGetShortExpVector(h.p);
12040 if (currRing!=strat->tailRing)
12041 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12042
12043 assume(pIsInV(h.p));
12044 assume(pIsInV(h.p1));
12045 assume(h.lcm != NULL);
12046 assume(pIsInV(h.lcm));
12047
12048 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
12049 kTest_TS(strat);
12050}
12051#endif
12052
12053#ifdef HAVE_SHIFTBBA
12054// adds the strong pair and the normal pair for rings (aka gpoly and spoly)
12055static BOOLEAN enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12056{
12057 enterOneStrongPolyShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "gpoly"
12058 enterOnePairRingShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "spoly"
12059 return FALSE; // TODO: delete q?
12060}
12061#endif
12062
12063#ifdef HAVE_SHIFTBBA
12064// creates if possible (q,p), (shifts(q),p)
12065static 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)
12066{
12067 // note: ecart and isFromQ is for p
12068 assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12069 assume(pmFirstVblock(p) == 1);
12070 assume(pmFirstVblock(q) == 1);
12071 assume(p_lastVblock == pmLastVblock(p));
12072 assume(q_lastVblock == pmLastVblock(q));
12073
12074 // TODO: is ecartq = 0 still ok?
12075 int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12076
12077 int q_isFromQ = 0;
12078 if (strat->fromQ != NULL && q_inS >= 0)
12079 q_isFromQ = strat->fromQ[q_inS];
12080
12081 BOOLEAN (*enterPair)(poly, poly, int, int, kStrategy, int, int, int, int, int);
12084 else
12085 enterPair = enterOnePairShift;
12086
12087 int degbound = currRing->N/currRing->isLPring;
12088 int neededShift = p_lastVblock - ((pGetComp(p) > 0 || pGetComp(q) > 0) ? 0 : 1); // in the module case, product criterion does not hold
12089 int maxPossibleShift = degbound - q_lastVblock;
12090 int maxShift = si_min(neededShift, maxPossibleShift);
12091 int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12092 BOOLEAN delete_pair=TRUE;
12093 for (int j = firstShift; j <= maxShift; j++)
12094 {
12095 poly qq = pLPCopyAndShiftLM(q, j);
12096 if (enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS))
12097 {
12098 if (j>0) pLmDelete(qq);
12099 // delete qq, if not it does not enter the pair set
12100 }
12101 else
12102 delete_pair=FALSE;
12103 }
12104
12105 if (rField_is_Ring(currRing) && p_lastVblock >= firstShift && p_lastVblock <= maxPossibleShift)
12106 {
12107 // add pairs (m*shifts(q), p) where m is a monomial and the pair has no overlap
12108 for (int j = p_lastVblock; j <= maxPossibleShift; j++)
12109 {
12110 ideal fillers = id_MaxIdeal(j - p_lastVblock, currRing);
12111 for (int k = 0; k < IDELEMS(fillers); k++)
12112 {
12113 poly qq = pLPCopyAndShiftLM(pp_mm_Mult(q, fillers->m[k], currRing), p_lastVblock);
12114 enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, p_lastVblock, q_inS);
12115 }
12116 idDelete(&fillers);
12117 }
12118 }
12119 return delete_pair;
12120}
12121#endif
12122
12123#ifdef HAVE_SHIFTBBA
12124// creates (q,p), use it when q is already shifted
12125// return TRUE, if (q,p) is discarded
12126static 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)
12127{
12128 // note: ecart and isFromQ is for p
12129 assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12130 assume(pmFirstVblock(p) == 1);
12131 assume(p_lastVblock == pmLastVblock(p));
12132 assume(q_shift == pmFirstVblock(q) - 1);
12133
12134 // TODO: is ecartp = 0 still ok?
12135 int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12136
12137 int p_isFromQ = 0;
12138 if (strat->fromQ != NULL && p_inS >= 0)
12139 p_isFromQ = strat->fromQ[p_inS];
12140
12142 {
12143 assume(q_shift <= p_lastVblock); // we allow the special case where there is no overlap
12144 return enterOneStrongPolyAndEnterOnePairRingShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12145 }
12146 else
12147 {
12148 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)
12149 return enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12150 }
12151}
12152#endif
12153
12154
12155#ifdef KDEBUG
12156// enable to print which pairs are considered or discarded and why
12157/* #define CRITERION_DEBUG */
12158#endif
12159/*2
12160* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12161* return TRUE, if (q,p) does not enter B
12162*/
12163#ifdef HAVE_SHIFTBBA
12164BOOLEAN enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12165{
12166#ifdef CRITERION_DEBUG
12167 if (TEST_OPT_DEBUG)
12168 {
12169 PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12170 // also write the LMs in separate lines:
12171 poly lmq = pHead(q);
12172 poly lmp = pHead(p);
12173 pSetCoeff(lmq, n_Init(1, currRing->cf));
12174 pSetCoeff(lmp, n_Init(1, currRing->cf));
12175 Print(" %s\n", pString(lmq));
12176 Print(" %s\n", pString(lmp));
12177 pLmDelete(lmq);
12178 pLmDelete(lmp);
12179 }
12180#endif
12181
12182 /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12183
12184 /* check this Formats: */
12189
12190 /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12191
12192 int qfromQ = qisFromQ;
12193
12194 /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12195
12196 int l,j,compare;
12197 LObject Lp;
12198 Lp.i_r = -1;
12199
12200#ifdef KDEBUG
12201 Lp.ecart=0; Lp.length=0;
12202#endif
12203 /*- computes the lcm(s[i],p) -*/
12204 Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12205
12206 /* the V criterion */
12207 if (!pmIsInV(Lp.lcm))
12208 {
12209 strat->cv++; // counter for applying the V criterion
12210 pLmFree(Lp.lcm);
12211#ifdef CRITERION_DEBUG
12212 if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12213#endif
12214 return TRUE;
12215 }
12216
12217 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12218 {
12219 if((!((ecartq>0)&&(ecart>0)))
12220 && pHasNotCF(p,q))
12221 {
12222 /*
12223 *the product criterion has applied for (s,p),
12224 *i.e. lcm(s,p)=product of the leading terms of s and p.
12225 *Suppose (s,r) is in L and the leading term
12226 *of p divides lcm(s,r)
12227 *(==> the leading term of p divides the leading term of r)
12228 *but the leading term of s does not divide the leading term of r
12229 *(notice that this condition is automatically satisfied if r is still
12230 *in S), then (s,r) can be cancelled.
12231 *This should be done here because the
12232 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12233 *
12234 *Moreover, skipping (s,r) holds also for the noncommutative case.
12235 */
12236 strat->cp++;
12237 pLmFree(Lp.lcm);
12238#ifdef CRITERION_DEBUG
12239 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12240#endif
12241 return TRUE;
12242 }
12243 else
12244 Lp.ecart = si_max(ecart,ecartq);
12245 if (strat->fromT && (ecartq>ecart))
12246 {
12247 pLmFree(Lp.lcm);
12248#ifdef CRITERION_DEBUG
12249 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12250#endif
12251 return TRUE;
12252 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12253 }
12254 /*
12255 *the set B collects the pairs of type (S[j],p)
12256 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12257 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12258 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12259 */
12260 {
12261 j = strat->Bl;
12262 loop
12263 {
12264 if (j < 0) break;
12265 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12266 if ((compare==1)
12267 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12268 {
12269 strat->c3++;
12270 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12271 {
12272 pLmFree(Lp.lcm);
12273#ifdef CRITERION_DEBUG
12274 if (TEST_OPT_DEBUG)
12275 {
12276 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12277 }
12278#endif
12279 return TRUE;
12280 }
12281 break;
12282 }
12283 else
12284 if ((compare ==-1)
12285 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12286 {
12287#ifdef CRITERION_DEBUG
12288 if (TEST_OPT_DEBUG)
12289 {
12290 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12291 }
12292#endif
12293 deleteInL(strat->B,&strat->Bl,j,strat);
12294 strat->c3++;
12295 }
12296 j--;
12297 }
12298 }
12299 }
12300 else /*sugarcrit*/
12301 {
12302 if (ALLOW_PROD_CRIT(strat))
12303 {
12304 // if currRing->nc_type!=quasi (or skew)
12305 // TODO: enable productCrit for super commutative algebras...
12306 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12307 pHasNotCF(p,q))
12308 {
12309 /*
12310 *the product criterion has applied for (s,p),
12311 *i.e. lcm(s,p)=product of the leading terms of s and p.
12312 *Suppose (s,r) is in L and the leading term
12313 *of p divides lcm(s,r)
12314 *(==> the leading term of p divides the leading term of r)
12315 *but the leading term of s does not divide the leading term of r
12316 *(notice that tis condition is automatically satisfied if r is still
12317 *in S), then (s,r) can be canceled.
12318 *This should be done here because the
12319 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12320 */
12321 strat->cp++;
12322 pLmFree(Lp.lcm);
12323#ifdef CRITERION_DEBUG
12324 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12325#endif
12326 return TRUE;
12327 }
12328 if (strat->fromT && (ecartq>ecart))
12329 {
12330 pLmFree(Lp.lcm);
12331#ifdef CRITERION_DEBUG
12332 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12333#endif
12334 return TRUE;
12335 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12336 }
12337 /*
12338 *the set B collects the pairs of type (S[j],p)
12339 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12340 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12341 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12342 */
12343 for(j = strat->Bl;j>=0;j--)
12344 {
12345 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12346 if (compare==1)
12347 {
12348 strat->c3++;
12349 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12350 {
12351 pLmFree(Lp.lcm);
12352#ifdef CRITERION_DEBUG
12353 if (TEST_OPT_DEBUG)
12354 {
12355 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12356 }
12357#endif
12358 return TRUE;
12359 }
12360 break;
12361 }
12362 else
12363 if (compare ==-1)
12364 {
12365#ifdef CRITERION_DEBUG
12366 if (TEST_OPT_DEBUG)
12367 {
12368 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12369 }
12370#endif
12371 deleteInL(strat->B,&strat->Bl,j,strat);
12372 strat->c3++;
12373 }
12374 }
12375 }
12376 }
12377 /*
12378 *the pair (S[i],p) enters B if the spoly != 0
12379 */
12380 /*- compute the short s-polynomial -*/
12381 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12382 pNorm(p);
12383 if ((q==NULL) || (p==NULL))
12384 {
12385#ifdef CRITERION_DEBUG
12386 if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
12387#endif
12388 return FALSE;
12389 }
12390 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12391 {
12392 Lp.p=NULL;
12393#ifdef CRITERION_DEBUG
12394 if (TEST_OPT_DEBUG) PrintS("--- pair is from Q\n");
12395#endif
12396 }
12397 else
12398 {
12399// if ( rIsPluralRing(currRing) )
12400// {
12401// if(pHasNotCF(p, q))
12402// {
12403// if(ncRingType(currRing) == nc_lie)
12404// {
12405// // generalized prod-crit for lie-type
12406// strat->cp++;
12407// Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12408// }
12409// else
12410// if( ALLOW_PROD_CRIT(strat) )
12411// {
12412// // product criterion for homogeneous case in SCA
12413// strat->cp++;
12414// Lp.p = NULL;
12415// }
12416// else
12417// Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12418// }
12419// else Lp.p = nc_CreateSpoly(q,p,currRing);
12420// }
12421// else
12422// {
12423
12424 /* ksCreateShortSpoly needs two Lobject-kind presentations */
12425 /* p is already in this form, so convert q */
12426 Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12427 // }
12428 }
12429 if (Lp.p == NULL)
12430 {
12431 /*- the case that the s-poly is 0 -*/
12432 // TODO: currently ifromS is only > 0 if called from enterOnePairWithShifts
12433 if (ifromS > 0)
12434 {
12435 if (strat->pairtest==NULL) initPairtest(strat);
12436 strat->pairtest[ifromS] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12437 strat->pairtest[strat->sl+1] = TRUE;
12438 }
12439 //if (TEST_OPT_DEBUG){Print("!");} // option teach
12440 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12441 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12442 /*
12443 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12444 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12445 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12446 *term of p divides the lcm(s,r)
12447 *(this canceling should be done here because
12448 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12449 *the first case is handled in chainCrit
12450 */
12451 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12452#ifdef CRITERION_DEBUG
12453 if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
12454#endif
12455 return TRUE;
12456 }
12457 else
12458 {
12459 /*- the pair (S[i],p) enters B -*/
12460 /* both of them should have their LM in currRing and TAIL in tailring */
12461 Lp.p1 = q; // already in the needed form
12462 Lp.p2 = p; // already in the needed form
12463
12464 if ( !rIsPluralRing(currRing) )
12465 pNext(Lp.p) = strat->tail;
12466
12467 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12468 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12469 if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12470 {
12471 Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12472 Lp.i_r2 = atR;
12473 }
12474 else
12475 {
12476 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12477 Lp.i_r1 = -1;
12478 Lp.i_r2 = -1;
12479 }
12480 strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12481
12483 {
12486 && (Lp.p->coef!=NULL))
12487 nDelete(&(Lp.p->coef));
12488 }
12489
12490 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12491 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12492#ifdef CRITERION_DEBUG
12493 if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
12494#endif
12495 }
12496 return FALSE;
12497}
12498#endif
12499
12500/*3
12501*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12502* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12503* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12504*/
12505#ifdef HAVE_SHIFTBBA
12506void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12507{
12508 int h_lastVblock = pmLastVblock(h);
12509 assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12510 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12511 if (h_lastVblock == 0) return;
12512 assume(pmFirstVblock(h) == 1);
12513 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12514 // atR = -1;
12515 if ((strat->syzComp==0)
12516 || (pGetComp(h)<=strat->syzComp))
12517 {
12518 int i,j;
12519 BOOLEAN new_pair=FALSE;
12520
12521 int degbound = currRing->N/currRing->isLPring;
12522 int maxShift = degbound - h_lastVblock;
12523
12524 if (pGetComp(h)==0)
12525 {
12526 if (strat->rightGB)
12527 {
12528 if (isFromQ)
12529 {
12530 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12531 for (i=0; i<=maxShift; i++)
12532 {
12533 poly hh = pLPCopyAndShiftLM(h, i);
12534 BOOLEAN delete_hh=TRUE;
12535 for (j=0; j<=k; j++)
12536 {
12537 if (strat->fromQ == NULL || !strat->fromQ[j])
12538 {
12539 new_pair=TRUE;
12540 poly s = strat->S[j];
12541 if (!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12542 delete_hh=FALSE;
12543 }
12544 }
12545 if (delete_hh) pLmDelete(hh);
12546 }
12547 }
12548 else
12549 {
12550 new_pair=TRUE;
12551 for (j=0; j<=k; j++)
12552 {
12553 poly s = strat->S[j];
12554 if (strat->fromQ != NULL && strat->fromQ[j])
12555 {
12556 // pairs (shifts(s[j]),h), (s[j],h)
12557 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12558 }
12559 else
12560 {
12561 // pair (h, s[j])
12562 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12563 }
12564 }
12565 }
12566 }
12567 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12568 else if ((isFromQ)&&(strat->fromQ!=NULL))
12569 {
12570 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12571 for (j=0; j<=k; j++)
12572 {
12573 if (!strat->fromQ[j])
12574 {
12575 new_pair=TRUE;
12576 poly s = strat->S[j];
12577 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12578 }
12579 }
12580 // pairs (shifts(h),s[1..k])
12581 if (new_pair)
12582 {
12583 for (i=1; i<=maxShift; i++)
12584 {
12585 BOOLEAN delete_hh=TRUE;
12586 poly hh = pLPCopyAndShiftLM(h, i);
12587 for (j=0; j<=k; j++)
12588 {
12589 if (!strat->fromQ[j])
12590 {
12591 poly s = strat->S[j];
12592 int s_lastVblock = pmLastVblock(s);
12593 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)
12594 {
12595 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i))
12596 delete_hh=FALSE;
12597 }
12598 else if (rField_is_Ring(currRing))
12599 {
12600 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12601 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12602 for (int k = 0; k < IDELEMS(fillers); k++)
12603 {
12604 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12605 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12606 }
12607 idDelete(&fillers);
12608 }
12609 }
12610 }
12611 if (delete_hh) p_LmDelete(hh,currRing);
12612 }
12613 }
12614 }
12615 else
12616 {
12617 new_pair=TRUE;
12618 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12619 for (j=0; j<=k; j++)
12620 {
12621 poly s = strat->S[j];
12622 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12623 }
12624 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12625 for (i=1; i<=maxShift; i++)
12626 {
12627 poly hh = pLPCopyAndShiftLM(h, i);
12628 BOOLEAN delete_hh=TRUE;
12629 for (j=0; j<=k; j++)
12630 {
12631 poly s = strat->S[j];
12632 int s_lastVblock = pmLastVblock(s);
12633 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)
12634 delete_hh=enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i)
12635 && delete_hh;
12636 else if (rField_is_Ring(currRing))
12637 {
12638 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12639 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12640 for (int k = 0; k < IDELEMS(fillers); k++)
12641 {
12642 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12643 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12644 }
12645 idDelete(&fillers);
12646 }
12647 }
12648 if (i < h_lastVblock) // in the module case, product criterion does not hold (note: comp h is always zero here)
12649 delete_hh=enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i)
12650 && delete_hh;
12651 else if (rField_is_Ring(currRing))
12652 {
12653 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12654 ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
12655 for (int k = 0; k < IDELEMS(fillers); k++)
12656 {
12657 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
12658 enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock);
12659 }
12660 idDelete(&fillers);
12661 }
12662 if (delete_hh) pLmDelete(hh);
12663 }
12664 }
12665 }
12666 else
12667 {
12668 assume(isFromQ == 0); // an element from Q should always has 0 component
12669 new_pair=TRUE;
12670 if (strat->rightGB)
12671 {
12672 for (j=0; j<=k; j++)
12673 {
12674 if ((pGetComp(h)==pGetComp(strat->S[j]))
12675 || (pGetComp(strat->S[j])==0))
12676 {
12677 poly s = strat->S[j];
12678 if (strat->fromQ != NULL && strat->fromQ[j])
12679 {
12680 // pairs (shifts(s[j]),h), (s[j],h)
12681 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12682 }
12683 else
12684 {
12685 // pair (h, s[j])
12686 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12687 }
12688 }
12689 }
12690 }
12691 else
12692 {
12693 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12694 for (j=0; j<=k; j++)
12695 {
12696 if ((pGetComp(h)==pGetComp(strat->S[j]))
12697 || (pGetComp(strat->S[j])==0))
12698 {
12699 poly s = strat->S[j];
12700 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12701 }
12702 }
12703 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12704 for (i=1; i<=maxShift; i++)
12705 {
12706 poly hh = pLPCopyAndShiftLM(h, i);
12707 for (j=0; j<=k; j++)
12708 {
12709 if ((pGetComp(h)==pGetComp(strat->S[j]))
12710 || (pGetComp(strat->S[j])==0))
12711 {
12712 poly s = strat->S[j];
12713 int s_lastVblock = pmLastVblock(s);
12714 if (i <= s_lastVblock) // in the module case, product criterion does not hold
12715 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
12716 else if (rField_is_Ring(currRing))
12717 {
12718 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12719 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12720 for (int k = 0; k < IDELEMS(fillers); k++)
12721 {
12722 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12723 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12724 }
12725 idDelete(&fillers);
12726 }
12727 }
12728 }
12729 if (i <= h_lastVblock) // in the module case, product criterion does not hold
12730 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12731 else if (rField_is_Ring(currRing))
12732 {
12733 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12734 ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
12735 for (int k = 0; k < IDELEMS(fillers); k++)
12736 {
12737 BOOLEAN delete_hhh=TRUE;
12738 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
12739 if(!enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock))
12740 delete_hhh=FALSE;
12741 if (delete_hhh) p_LmDelete(hhh,currRing);
12742 }
12743 idDelete(&fillers);
12744 }
12745 }
12746 }
12747 }
12748
12749 if (new_pair)
12750 {
12751 strat->chainCrit(h,ecart,strat);
12752 }
12753 kMergeBintoL(strat);
12754 }
12755}
12756#endif
12757
12758/*3
12759*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12760* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12761* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12762*/
12763#ifdef HAVE_SHIFTBBA
12764void initenterstrongPairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12765{
12766 int h_lastVblock = pmLastVblock(h);
12767 assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12768 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12769 if (h_lastVblock == 0) return;
12770 assume(pmFirstVblock(h) == 1);
12771 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12772 // atR = -1;
12773 if ((strat->syzComp==0)
12774 || (pGetComp(h)<=strat->syzComp))
12775 {
12776 int i,j;
12777 BOOLEAN new_pair=FALSE;
12778
12779 int degbound = currRing->N/currRing->isLPring;
12780 int maxShift = degbound - h_lastVblock;
12781
12782 if (pGetComp(h)==0)
12783 {
12784 if (strat->rightGB)
12785 {
12786 if (isFromQ)
12787 {
12788 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12789 for (i=0; i<=maxShift; i++)
12790 {
12791 poly hh = pLPCopyAndShiftLM(h, i);
12792 for (j=0; j<=k; j++)
12793 {
12794 if (strat->fromQ == NULL || !strat->fromQ[j])
12795 {
12796 new_pair=TRUE;
12797 poly s = strat->S[j];
12798 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12799 }
12800 }
12801 }
12802 }
12803 else
12804 {
12805 new_pair=TRUE;
12806 for (j=0; j<=k; j++)
12807 {
12808 poly s = strat->S[j];
12809 if (strat->fromQ != NULL && strat->fromQ[j])
12810 {
12811 // pairs (shifts(s[j]),h), (s[j],h)
12812 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12813 }
12814 else
12815 {
12816 // pair (h, s[j])
12817 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12818 }
12819 }
12820 }
12821 }
12822 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12823 else if ((isFromQ)&&(strat->fromQ!=NULL))
12824 {
12825 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12826 for (j=0; j<=k; j++)
12827 {
12828 if (!strat->fromQ[j])
12829 {
12830 new_pair=TRUE;
12831 poly s = strat->S[j];
12832 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12833 }
12834 }
12835 // pairs (shifts(h),s[1..k])
12836 if (new_pair)
12837 {
12838 for (i=1; i<=maxShift; i++)
12839 {
12840 poly hh = pLPCopyAndShiftLM(h, i);
12841 for (j=0; j<=k; j++)
12842 {
12843 if (!strat->fromQ[j])
12844 {
12845 poly s = strat->S[j];
12846 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12847 }
12848 }
12849 }
12850 }
12851 }
12852 else
12853 {
12854 new_pair=TRUE;
12855 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12856 for (j=0; j<=k; j++)
12857 {
12858 poly s = strat->S[j];
12859 // TODO: cache lastVblock of s[1..k] for later use
12860 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12861 }
12862 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12863 for (i=1; i<=maxShift; i++)
12864 {
12865 poly hh = pLPCopyAndShiftLM(h, i);
12866 BOOLEAN delete_hh=TRUE;
12867 for (j=0; j<=k; j++)
12868 {
12869 poly s = strat->S[j];
12870 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12871 delete_hh=FALSE;
12872 }
12873 if(!enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i))
12874 delete_hh=FALSE;
12875 if (delete_hh) p_LmDelete(hh,currRing);
12876 }
12877 }
12878 }
12879 else
12880 {
12881 new_pair=TRUE;
12882 if (strat->rightGB)
12883 {
12884 for (j=0; j<=k; j++)
12885 {
12886 if ((pGetComp(h)==pGetComp(strat->S[j]))
12887 || (pGetComp(strat->S[j])==0))
12888 {
12889 assume(isFromQ == 0); // this case is not handled here and should also never happen
12890 poly s = strat->S[j];
12891 if (strat->fromQ != NULL && strat->fromQ[j])
12892 {
12893 // pairs (shifts(s[j]),h), (s[j],h)
12894 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12895 }
12896 else
12897 {
12898 // pair (h, s[j])
12899 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12900 }
12901 }
12902 }
12903 }
12904 else
12905 {
12906 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12907 for (j=0; j<=k; j++)
12908 {
12909 if ((pGetComp(h)==pGetComp(strat->S[j]))
12910 || (pGetComp(strat->S[j])==0))
12911 {
12912 poly s = strat->S[j];
12913 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12914 }
12915 }
12916 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12917 for (i=1; i<=maxShift; i++)
12918 {
12919 poly hh = pLPCopyAndShiftLM(h, i);
12920 for (j=0; j<=k; j++)
12921 {
12922 if ((pGetComp(h)==pGetComp(strat->S[j]))
12923 || (pGetComp(strat->S[j])==0))
12924 {
12925 poly s = strat->S[j];
12926 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12927 }
12928 }
12929 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12930 }
12931 }
12932 }
12933
12934 if (new_pair)
12935 {
12936 strat->chainCrit(h,ecart,strat);
12937 }
12938 kMergeBintoL(strat);
12939 }
12940}
12941#endif
12942
12943/*2
12944*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
12945*superfluous elements in S will be deleted
12946*/
12947#ifdef HAVE_SHIFTBBA
12948void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
12949{
12950 /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12951 /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
12952 int j=pos;
12953
12954 /* if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat); */ // TODO: enterExtendedSpoly not for LP yet
12955 initenterpairsShift(h,k,ecart,0,strat, atR);
12956 if ( (!strat->fromT)
12957 && ((strat->syzComp==0)
12958 ||(pGetComp(h)<=strat->syzComp)))
12959 {
12960 unsigned long h_sev = pGetShortExpVector(h);
12961 loop
12962 {
12963 if (j > k) break;
12964 // TODO this currently doesn't clear all possible elements because of commutative division
12965 if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
12966 clearS(h,h_sev, &j,&k,strat);
12967 j++;
12968 }
12969 }
12970}
12971#endif
12972
12973/*2
12974* enteres all admissible shifts of p into T
12975* assumes that p is already in T!
12976*/
12977#ifdef HAVE_SHIFTBBA
12978void enterTShift(LObject p, kStrategy strat, int atT)
12979{
12980 /* determine how many elements we have to insert */
12981 /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
12982 /* hence, a total number of elt's to add is: */
12983 /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
12984 pAssume(p.p != NULL);
12985
12986 int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
12987
12988 for (int i = 1; i <= maxPossibleShift; i++)
12989 {
12990 LObject qq;
12991 qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
12992 qq.shift = i;
12993 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
12994
12995 enterT(qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
12996 }
12997}
12998#endif
12999
13000#ifdef HAVE_SHIFTBBA
13002{
13003 /* for the shift case need to run it with withT = TRUE */
13004 strat->redTailChange=FALSE;
13005 if (strat->noTailReduction) return L->GetLmCurrRing();
13006 poly h, p;
13007 p = h = L->GetLmTailRing();
13008 if ((h==NULL) || (pNext(h)==NULL))
13009 return L->GetLmCurrRing();
13010
13011 TObject* With;
13012 // placeholder in case strat->tl < 0
13013 TObject With_s(strat->tailRing);
13014
13015 LObject Ln(pNext(h), strat->tailRing);
13016 Ln.pLength = L->GetpLength() - 1;
13017
13018 pNext(h) = NULL;
13019 if (L->p != NULL) pNext(L->p) = NULL;
13020 L->pLength = 1;
13021
13022 Ln.PrepareRed(strat->use_buckets);
13023
13024 while(!Ln.IsNull())
13025 {
13026 loop
13027 {
13028 Ln.SetShortExpVector();
13029 if (withT)
13030 {
13031 int j;
13032 j = kFindDivisibleByInT(strat, &Ln);
13033 if (j < 0) break;
13034 With = &(strat->T[j]);
13035 }
13036 else
13037 {
13038 With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
13039 if (With == NULL) break;
13040 }
13041 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
13042 {
13043 With->pNorm();
13044 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
13045 }
13046 strat->redTailChange=TRUE;
13047 if (ksReducePolyTail(L, With, &Ln))
13048 {
13049 // reducing the tail would violate the exp bound
13050 // set a flag and hope for a retry (in bba)
13052 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
13053 do
13054 {
13055 pNext(h) = Ln.LmExtractAndIter();
13056 pIter(h);
13057 L->pLength++;
13058 } while (!Ln.IsNull());
13059 goto all_done;
13060 }
13061 if (Ln.IsNull()) goto all_done;
13062 if (! withT) With_s.Init(currRing);
13063 }
13064 pNext(h) = Ln.LmExtractAndIter();
13065 pIter(h);
13066 L->pLength++;
13067 }
13068
13069 all_done:
13070 Ln.Delete();
13071 if (L->p != NULL) pNext(L->p) = pNext(p);
13072
13073 if (strat->redTailChange)
13074 {
13075 L->length = 0;
13076 }
13077 L->Normalize(); // HANNES: should have a test
13078 kTest_L(L,strat);
13079 return L->GetLmCurrRing();
13080}
13081#endif
static int si_max(const int a, const int b)
Definition auxiliary.h:124
int BOOLEAN
Definition auxiliary.h:87
#define TRUE
Definition auxiliary.h:100
#define FALSE
Definition auxiliary.h:96
void * ADDRESS
Definition auxiliary.h:119
static int si_min(const int a, const int b)
Definition auxiliary.h:125
CanonicalForm lc(const CanonicalForm &f)
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition cf_gcd.cc:676
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
int p
Definition cfModGcd.cc:4086
bool equal
Definition cfModGcd.cc:4134
CanonicalForm b
Definition cfModGcd.cc:4111
static CanonicalForm bound(const CFMatrix &M)
Definition cf_linsys.cc:460
poly p
Definition kutil.h:73
poly t_p
Definition kutil.h:74
ring tailRing
Definition kutil.h:76
void wrp()
Definition kutil.cc:771
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:358
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:376
int currIdx
Definition kutil.h:317
int nrsyzcrit
Definition kutil.h:359
intset lenS
Definition kutil.h:319
int nrrewcrit
Definition kutil.h:360
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:398
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:375
char rightGB
Definition kutil.h:367
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:375
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:383
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:374
int cv
Definition kutil.h:366
pShallowCopyDeleteProc p_shallow_copy_delete
Definition kutil.h:338
char Gebauer
Definition kutil.h:376
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:399
char use_buckets
Definition kutil.h:381
char interpt
Definition kutil.h:369
char redTailChange
Definition kutil.h:397
int newIdeal
Definition kutil.h:356
char fromT
Definition kutil.h:377
char completeReduce_retry
Definition kutil.h:401
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:400
int Lmax
Definition kutil.h:351
char z2homog
Definition kutil.h:372
int LazyPass
Definition kutil.h:353
char overflow
Definition kutil.h:402
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:387
unsigned long * sevS
Definition kutil.h:322
char homog
Definition kutil.h:370
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:809
@ 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:665
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:519
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:680
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:701
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:406
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:459
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:691
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:672
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:539
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:629
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:748
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition coeffs.h:525
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
void nKillChar(coeffs r)
undo all initialisations
Definition numbers.cc:556
#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
if(!FE_OPT_NO_SHELL_FLAG)
Definition fehelp.cc:1000
#define STATIC_VAR
Definition globaldefs.h:7
#define VAR
Definition globaldefs.h:5
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge)
Definition hdegree.cc:1074
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition ideals.cc: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:956
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:1057
KINLINE int ksReducePolyTailLC_Z(LObject *PR, TObject *PW, LObject *Red)
Definition kInline.h:1104
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition kInline.h:1171
KINLINE TObject ** initR()
Definition kInline.h:95
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition kInline.h:1144
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition kInline.h:1181
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition kInline.h:1232
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:1015
KINLINE int ksReducePolyTail_Z(LObject *PR, TObject *PW, LObject *Red)
Definition kInline.h:1122
KINLINE unsigned long * initsevT()
Definition kInline.h:100
int redLiftstd(LObject *h, kStrategy strat)
Definition kLiftstd.cc:167
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
Definition kbuckets.cc:197
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition kbuckets.cc:216
int ksCheckCoeff(number *a, number *b, const coeffs r)
Definition kbuckets.cc:1504
BOOLEAN pCompareChainPart(poly p, poly p1, poly p2, poly lcm, const ring R)
Definition kpolys.cc:71
BOOLEAN pCompareChain(poly p, poly p1, poly p2, poly lcm, const ring R)
Returns TRUE if.
Definition kpolys.cc:17
poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing)
Definition kspoly.cc:1446
long kHomModDeg(poly p, const ring r)
Definition kstd1.cc:2419
int redFirst(LObject *h, kStrategy strat)
Definition kstd1.cc:795
int redEcart(LObject *h, kStrategy strat)
Definition kstd1.cc:169
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition kstd1.cc:1674
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition kstd1.cc:1361
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition kstd1.cc:1621
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition kstd1.cc:3237
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:2484
EXTERN_VAR int Kstd1_deg
Definition kstd1.h:52
EXTERN_VAR int Kstd1_mu
Definition kstd1.h:52
int kFindDivisibleByInT_Z(const kStrategy strat, const LObject *L, const int start)
Definition kstd2.cc:213
int redHoney(LObject *h, kStrategy strat)
Definition kstd2.cc:2114
int redHomog(LObject *h, kStrategy strat)
Definition kstd2.cc:1154
int redLazy(LObject *h, kStrategy strat)
Definition kstd2.cc:1909
poly redNF(poly h, int &max_ind, int nonorm, kStrategy strat)
Definition kstd2.cc:2315
int redRing(LObject *h, kStrategy strat)
Definition kstd2.cc:992
int kFindDivisibleByInT(const kStrategy strat, const LObject *L, const int start)
return -1 if no divisor is found number of first divisor in T, otherwise
Definition kstd2.cc:321
void initSbaPos(kStrategy strat)
Definition kutil.cc:9856
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition kutil.cc:7465
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:6838
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6301
#define pDivComp_LESS
Definition kutil.cc:135
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6414
int getIndexRng(long coeff)
Definition kutil.cc:6002
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6060
int posInT17(const TSet set, const int length, LObject &p)
Definition kutil.cc:5283
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:9745
int redFirst(LObject *h, kStrategy strat)
Definition kstd1.cc:795
VAR int HCord
Definition kutil.cc:244
void kMergeBintoL(kStrategy strat)
Definition kutil.cc:3166
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition kutil.cc:542
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition kutil.cc:6648
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9337
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5846
int redEcart(LObject *h, kStrategy strat)
Definition kstd1.cc:169
int posInT11(const TSet set, const int length, LObject &p)
Definition kutil.cc:4958
void enterT(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9137
int posInT1(const TSet set, const int length, LObject &p)
Definition kutil.cc:4901
void enterTShift(LObject p, kStrategy strat, int atT)
Definition kutil.cc:12978
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5076
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition kutil.cc:6623
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8911
BOOLEAN kTest(kStrategy strat)
Definition kutil.cc:1010
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:3939
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition kstd1.cc:1674
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:7027
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:5151
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition kutil.cc:6699
int posInT0(const TSet, const int length, LObject &)
Definition kutil.cc:4890
BOOLEAN kTest_TS(kStrategy strat)
Definition kutil.cc:1071
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:1944
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition kutil.cc:716
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition kutil.cc:10517
void initenterstrongPairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:12764
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4518
static void enterOnePairRingShift(poly q, poly p, int, int isFromQ, kStrategy strat, int atR, int, int qisFromQ, int shiftcount, int ifromS)
Definition kutil.cc:11811
static const char * kTest_LmEqual(poly p, poly t_p, ring tailRing)
Definition kutil.cc:781
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition kutil.cc:1274
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition kutil.cc:6564
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:12055
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition kutil.cc:4438
static int pLPDivComp(poly p, poly q)
Definition kutil.cc:230
int posInT2(const TSet set, const int length, LObject &p)
Definition kutil.cc:4930
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6147
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6101
#define kFalseReturn(x)
Definition kutil.cc:778
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:12065
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11466
static intset initec(const int maxnr)
Definition kutil.cc:528
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition kutil.cc:9561
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4492
int posInT13(const TSet set, const int length, LObject &p)
Definition kutil.cc:5122
void redtailBbaAlsoLC_Z(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7142
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.cc:6515
static void deleteHCBucket(LObject *L, kStrategy strat)
Definition kutil.cc:248
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition kutil.cc:9411
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:12126
void chainCritSig(poly p, int, kStrategy strat)
Definition kutil.cc:3466
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition kutil.cc:4769
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition kutil.cc:1320
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:4157
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4475
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8508
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5643
static int pDivCompRing(poly p, poly q)
Definition kutil.cc:143
void initBuchMoraPos(kStrategy strat)
Definition kutil.cc:9574
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:3814
void initS(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7588
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition kutil.cc:10960
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:6914
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7271
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition kutil.cc:11081
void initPairtest(kStrategy strat)
Definition kutil.cc:691
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:2207
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5616
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition kutil.cc:8084
void chainCritOpt_1(poly, int, kStrategy strat)
Definition kutil.cc:3450
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:4994
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:1339
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8484
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition kutil.cc:8398
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition kutil.cc:12506
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:4212
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:3879
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6182
static void enlargeL(LSet *L, int *length, const int incr)
Definition kutil.cc:681
int posInT17_c(const TSet set, const int length, LObject &p)
Definition kutil.cc:5389
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition kutil.cc:13001
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11375
int posInT15(const TSet set, const int length, LObject &p)
Definition kutil.cc:5189
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition kutil.cc:9236
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition kutil.cc:10703
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition kutil.cc:6480
void HEckeTest(poly pp, kStrategy strat)
Definition kutil.cc:498
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5572
STATIC_VAR BOOLEAN sloppy_max
Definition kutil.cc:798
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition kutil.cc:4321
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:12948
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:2438
BOOLEAN kTest_L(LObject *L, kStrategy strat, BOOLEAN testp, int lpos, TSet T, int tlength)
Definition kutil.cc:924
void exitBuchMora(kStrategy strat)
Definition kutil.cc:9830
void messageStatSBA(int hilbcount, kStrategy strat)
Definition kutil.cc:7519
void initEcartNormal(TObject *h)
Definition kutil.cc:1298
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition kutil.cc:4668
void updateS(BOOLEAN toT, kStrategy strat)
Definition kutil.cc:8553
static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
Definition kutil.cc:1186
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7777
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5914
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition kutil.cc:3097
static int * initS_2_R(const int maxnr)
Definition kutil.cc:537
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6257
void initSyzRules(kStrategy strat)
Definition kutil.cc:7929
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5674
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:9958
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition kutil.cc:10479
void cleanT(kStrategy strat)
Definition kutil.cc:563
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition kutil.cc:2226
int posInT110(const TSet set, const int length, LObject &p)
Definition kutil.cc:5034
BOOLEAN kTest_S(kStrategy strat)
Definition kutil.cc:1053
int posInSyz(const kStrategy strat, poly sig)
Definition kutil.cc:5763
void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
Definition kutil.cc:9046
void reorderS(int *suc, kStrategy strat)
Definition kutil.cc:4615
void enterExtendedSpoly(poly h, kStrategy strat)
Definition kutil.cc:4237
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6217
#define pDivComp_INCOMP
Definition kutil.cc:137
BOOLEAN kTest_T(TObject *T, kStrategy strat, int i, char TN)
Definition kutil.cc:799
void kMergeBintoLSba(kStrategy strat)
Definition kutil.cc:3187
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition kutil.cc:291
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition kutil.cc:10073
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition kutil.cc:4462
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition kutil.cc:1331
int posInT19(const TSet set, const int length, LObject &p)
Definition kutil.cc:5515
poly redtailBba_NF(poly p, kStrategy strat)
Definition kutil.cc:7352
#define pDivComp_GREATER
Definition kutil.cc:136
void exitSba(kStrategy strat)
Definition kutil.cc:10033
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5243
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition kutil.cc:5344
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition kutil.cc:1543
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:12164
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition kutil.cc:11500
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition kutil.cc:1213
void kStratInitChangeTailRing(kStrategy strat)
Definition kutil.cc:11053
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition kutil.cc:3525
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition kstd1.cc:1621
void initBuchMoraCrit(kStrategy strat)
Definition kutil.cc:9429
void cleanTSbaRing(kStrategy strat)
Definition kutil.cc:622
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition kutil.cc:5450
static int pDivComp(poly p, poly q)
Definition kutil.cc:181
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition kutil.cc:10279
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:6350
void initBuchMoraPosRing(kStrategy strat)
Definition kutil.cc:9659
int kFindInTShift(poly p, TSet T, int tlength)
Definition kutil.cc:741
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition kutil.cc:10779
static BOOLEAN enterOneStrongPolyShift(poly q, poly p, int, int, kStrategy strat, int atR, int, int, int shiftcount, int ifromS)
Definition kutil.cc:11642
void messageSets(kStrategy strat)
Definition kutil.cc:7538
void deleteInS(int i, kStrategy strat)
Definition kutil.cc:1137
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition kutil.cc:8381
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition kutil.cc:11429
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5699
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition kutil.cc:700
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition kutil.cc:1693
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5880
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:10538
static unsigned long * initsevS(const int maxnr)
Definition kutil.cc:533
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition kutil.cc:4541
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition kutil.cc:3209
void initEcartBBA(TObject *h)
Definition kutil.cc:1306
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:2695
void enterSBbaShift(LObject &p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8888
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition kutil.cc:5804
char * showOption()
Definition misc_ip.cc:711
poly redtailBba_Ring(LObject *L, int end_pos, kStrategy strat)
Definition kutil.cc:7377
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition kutil.cc:5792
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition kutil.cc:1313
void messageStat(int hilbcount, kStrategy strat)
Definition kutil.cc:7506
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition kutil.cc:1751
void chainCritRing(poly p, int, kStrategy strat)
Definition kutil.cc:4001
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition kutil.cc:8232
void initSL(ideal F, ideal Q, kStrategy strat)
Definition kutil.cc:7681
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition kutil.cc:4846
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition kutil.cc:10868
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition kutil.cc:8788
void initSbaCrit(kStrategy strat)
Definition kutil.cc:9492
BOOLEAN newHEdge(kStrategy strat)
Definition kutil.cc:10401
#define pDivComp_EQUAL
Definition kutil.cc:134
void cancelunit(LObject *L, BOOLEAN inNF)
Definition kutil.cc:370
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:840
#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:418
LObject * LSet
Definition kutil.h:60
denominator_list next
Definition kutil.h:65
static void kDeleteLcm(LObject *P)
Definition kutil.h:869
int * intset
Definition kutil.h:53
#define ALLOW_PROD_CRIT(A)
Definition kutil.h:393
#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:387
#define r_assume(x)
Definition mod2.h:388
int dReportError(const char *fmt,...)
Definition dError.cc:44
#define p_GetComp(p, r)
Definition monomials.h:64
#define pFalseReturn(cond)
Definition monomials.h:139
#define pIter(p)
Definition monomials.h:37
#define pNext(p)
Definition monomials.h:36
#define pSetCoeff0(p, n)
Definition monomials.h:59
#define p_GetCoeff(p, r)
Definition monomials.h:50
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition monomials.h:44
#define __p_GetComp(p, r)
Definition monomials.h:63
#define rRing_has_Comp(r)
Definition monomials.h:266
#define pAssume(cond)
Definition monomials.h:90
STATIC_VAR gmp_float * diff
#define nDelete(n)
Definition numbers.h:16
#define nIsZero(n)
Definition numbers.h:19
#define nEqual(n1, n2)
Definition numbers.h:20
#define nCopy(n)
Definition numbers.h:15
#define nGreater(a, b)
Definition numbers.h:28
#define nGreaterZero(n)
Definition numbers.h:27
#define nInvers(a)
Definition numbers.h:33
#define nIsOne(n)
Definition numbers.h:25
#define nInit(i)
Definition numbers.h:24
#define nTest(a)
Definition numbers.h:35
#define omFreeSize(addr, size)
#define omCheckBinAddrSize(addr, size)
#define omAlloc(size)
#define omReallocSize(addr, o_size, size)
#define omAlloc0(size)
#define omRealloc0Size(addr, o_size, size)
#define omSizeWOfBin(bin_ptr)
#define NULL
Definition omList.c:12
omBin_t * omBin
Definition omStructs.h:12
#define REGISTER
Definition omalloc.h:27
#define TEST_OPT_WEIGHTM
Definition options.h:123
#define TEST_OPT_IDLIFT
Definition options.h:131
#define TEST_OPT_INTSTRATEGY
Definition options.h:112
#define TEST_OPT_REDTAIL
Definition options.h:118
#define TEST_OPT_INFREDTAIL
Definition options.h:120
#define TEST_OPT_SUGARCRIT
Definition options.h:109
#define TEST_OPT_OLDSTD
Definition options.h:125
#define TEST_OPT_REDSB
Definition options.h:106
#define TEST_OPT_DEGBOUND
Definition options.h:115
#define TEST_OPT_SB_1
Definition options.h:121
#define TEST_OPT_NOT_SUGAR
Definition options.h:108
#define TEST_OPT_PROT
Definition options.h:105
#define OPT_INTERRUPT
Definition options.h:80
#define TEST_OPT_CANCELUNIT
Definition options.h:130
#define BTEST1(a)
Definition options.h:34
#define TEST_OPT_DEBUG
Definition options.h:110
#define TEST_OPT_CONTENTSB
Definition options.h:129
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
static int index(p_Length length, p_Ord ord)
poly p_GetMaxExpP(poly p, const ring r)
return monomial r such that GetExp(r,i) is maximum of all monomials in p; coeff == 0,...
Definition p_polys.cc:1139
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition p_polys.cc:2958
long pLDegb(poly p, int *l, const ring r)
Definition p_polys.cc:812
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition p_polys.cc:976
long p_WFirstTotalDegree(poly p, const ring r)
Definition p_polys.cc:595
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition p_polys.cc:1039
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition p_polys.cc:3670
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition p_polys.cc:1069
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition p_polys.cc:4576
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition p_polys.cc:942
long pLDeg1(poly p, int *l, const ring r)
Definition p_polys.cc:842
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition p_polys.cc:4830
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition p_polys.cc:911
long p_WTotaldegree(poly p, const ring r)
Definition p_polys.cc:612
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition p_polys.cc:1209
poly p_Cleardenom(poly p, const ring r)
Definition p_polys.cc:2849
long pLDeg1c(poly p, int *l, const ring r)
Definition p_polys.cc:878
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition p_polys.cc:1006
long pLDeg0c(poly p, int *l, const ring r)
Definition p_polys.cc:771
unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max)
return the maximal exponent of p in form of the maximal long var
Definition p_polys.cc:1176
long pLDeg0(poly p, int *l, const ring r)
Definition p_polys.cc:740
poly p_One(const ring r)
Definition p_polys.cc:1314
poly p_Sub(poly p1, poly p2, const ring r)
Definition p_polys.cc:1994
void pEnlargeSet(poly **p, int l, int increment)
Definition p_polys.cc:3717
long p_Deg(poly a, const ring r)
Definition p_polys.cc:586
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition p_polys.cc:1659
static poly p_Neg(poly p, const ring r)
Definition p_polys.h: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:1439
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:1425
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:1870
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:1327
static int p_Cmp(poly p1, poly p2, ring r)
Definition p_polys.h:1741
#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:1661
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:1594
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition p_polys.h:1924
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:1905
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:1521
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition p_polys.h:2013
#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 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 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:3465
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition ring.cc:5772
void rKillModifiedRing(ring r)
Definition ring.cc:3076
ring rAssure_c_dp(const ring r)
Definition ring.cc:5073
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition ring.cc:2715
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition ring.cc:1424
void rDebugPrint(const ring r)
Definition ring.cc:4153
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:452
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition ring.h:405
static int rBlocks(const ring r)
Definition ring.h:573
static int rGetCurrSyzLimit(const ring r)
Definition ring.h:728
static BOOLEAN rField_is_Domain(const ring r)
Definition ring.h:492
static BOOLEAN rIsRatGRing(const ring r)
Definition ring.h:432
static BOOLEAN rIsLPRing(const ring r)
Definition ring.h:416
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:768
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition ring.h:725
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:597
BOOLEAN rHasGlobalOrdering(const ring r)
Definition ring.h:766
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition ring.h:767
#define rField_is_Ring(R)
Definition ring.h:490
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