My Project
Loading...
Searching...
No Matches
kutil.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT: kernel: utils for kStd
6*/
7
8// #define PDEBUG 2
9// #define PDIV_DEBUG
10#define KUTIL_CC
11
12#define MYTEST 0
13
14//All vs Just strategy over rings:
15// 1 - Just
16// 0 - All
17#define ALL_VS_JUST 0
18//Extended Spoly Strategy:
19// 0 - new gen sig
20// 1 - ann*old sig
21#define EXT_POLY_NEW 0
22
23#include "kernel/mod2.h"
24
25#include "misc/mylimits.h"
26#include "misc/options.h"
27#include "polys/nc/nc.h"
28#include "polys/nc/sca.h"
29#include "polys/weight.h" /* for kDebugPrint: maxdegreeWecart*/
30
31#include <stdlib.h>
32#include <string.h>
33
34#ifdef KDEBUG
35#undef KDEBUG
36#define KDEBUG 2
37#endif
38
39#ifdef DEBUGF5
40#undef DEBUGF5
41//#define DEBUGF5 1
42#endif
43
44// define if enterL, enterT should use memmove instead of doing it manually
45// on topgun, this is slightly faster (see monodromy_l.tst, homog_gonnet.sing)
46#ifndef SunOS_4
47#define ENTER_USE_MEMMOVE
48#endif
49
50// define, if the my_memmove inlines should be used instead of
51// system memmove -- it does not seem to pay off, though
52// #define ENTER_USE_MYMEMMOVE
53
55#include "polys/kbuckets.h"
56#include "coeffs/numbers.h"
57#include "kernel/polys.h"
59#include "kernel/ideals.h"
63
64#ifdef HAVE_SHIFTBBA
65#include "polys/shiftop.h"
66#endif
67
68#include "polys/prCopy.h"
69
70#ifdef HAVE_RATGRING
72#endif
73
74#ifdef KDEBUG
75#undef KDEBUG
76#define KDEBUG 2
77#endif
78
79#ifdef DEBUGF5
80#undef DEBUGF5
81#define DEBUGF5 2
82#endif
83
85
86
87#ifdef ENTER_USE_MYMEMMOVE
88inline void _my_memmove_d_gt_s(unsigned long* d, unsigned long* s, long l)
89{
90 REGISTER unsigned long* _dl = (unsigned long*) d;
91 REGISTER unsigned long* _sl = (unsigned long*) s;
92 REGISTER long _i = l - 1;
93
94 do
95 {
96 _dl[_i] = _sl[_i];
97 _i--;
98 }
99 while (_i >= 0);
100}
101
102inline void _my_memmove_d_lt_s(unsigned long* d, unsigned long* s, long l)
103{
104 REGISTER long _ll = l;
105 REGISTER unsigned long* _dl = (unsigned long*) d;
106 REGISTER unsigned long* _sl = (unsigned long*) s;
107 REGISTER long _i = 0;
108
109 do
110 {
111 _dl[_i] = _sl[_i];
112 _i++;
113 }
114 while (_i < _ll);
115}
116
117inline void _my_memmove(void* d, void* s, long l)
118{
119 unsigned long _d = (unsigned long) d;
120 unsigned long _s = (unsigned long) s;
121 unsigned long _l = ((l) + SIZEOF_LONG - 1) >> LOG_SIZEOF_LONG;
122
123 if (_d > _s) _my_memmove_d_gt_s(_d, _s, _l);
124 else _my_memmove_d_lt_s(_d, _s, _l);
125}
126
127#undef memmove
128#define memmove(d,s,l) _my_memmove(d, s, l)
129#endif
130
131static poly redMora (poly h,int maxIndex,kStrategy strat);
132static poly redBba (poly h,int maxIndex,kStrategy strat);
133
134#ifdef HAVE_RINGS
135#define pDivComp_EQUAL 2
136#define pDivComp_LESS 1
137#define pDivComp_GREATER -1
138#define pDivComp_INCOMP 0
139/* Checks the relation of LM(p) and LM(q)
140 LM(p) = LM(q) => return pDivComp_EQUAL
141 LM(p) | LM(q) => return pDivComp_LESS
142 LM(q) | LM(p) => return pDivComp_GREATER
143 else return pDivComp_INCOMP */
144static inline int pDivCompRing(poly p, poly q)
145{
146 if ((currRing->pCompIndex < 0)
148 {
149 BOOLEAN a=FALSE, b=FALSE;
150 int i;
151 unsigned long la, lb;
152 unsigned long divmask = currRing->divmask;
153 for (i=0; i<currRing->VarL_Size; i++)
154 {
155 la = p->exp[currRing->VarL_Offset[i]];
156 lb = q->exp[currRing->VarL_Offset[i]];
157 if (la != lb)
158 {
159 if (la < lb)
160 {
161 if (b) return pDivComp_INCOMP;
162 if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
163 return pDivComp_INCOMP;
164 a = TRUE;
165 }
166 else
167 {
168 if (a) return pDivComp_INCOMP;
169 if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
170 return pDivComp_INCOMP;
171 b = TRUE;
172 }
173 }
174 }
175 if (a) return pDivComp_LESS;
176 if (b) return pDivComp_GREATER;
177 if (!a & !b) return pDivComp_EQUAL;
178 }
179 return pDivComp_INCOMP;
180}
181#endif
182
183static inline int pDivComp(poly p, poly q)
184{
185 if ((currRing->pCompIndex < 0)
187 {
188#ifdef HAVE_RATGRING
190 {
192 q,currRing,
193 currRing->real_var_start, currRing->real_var_end))
194 return 0;
195 return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
196 }
197#endif
198 BOOLEAN a=FALSE, b=FALSE;
199 int i;
200 unsigned long la, lb;
201 unsigned long divmask = currRing->divmask;
202 for (i=0; i<currRing->VarL_Size; i++)
203 {
204 la = p->exp[currRing->VarL_Offset[i]];
205 lb = q->exp[currRing->VarL_Offset[i]];
206 if (la != lb)
207 {
208 if (la < lb)
209 {
210 if (b) return 0;
211 if (((la & divmask) ^ (lb & divmask)) != ((lb - la) & divmask))
212 return 0;
213 a = TRUE;
214 }
215 else
216 {
217 if (a) return 0;
218 if (((la & divmask) ^ (lb & divmask)) != ((la - lb) & divmask))
219 return 0;
220 b = TRUE;
221 }
222 }
223 }
224 if (a) { /*assume(pLmCmp(q,p)==1);*/ return 1; }
225 if (b) { /*assume(pLmCmp(q,p)==-1);*/return -1; }
226 /*assume(pLmCmp(q,p)==0);*/
227 }
228 return 0;
229}
230
231#ifdef HAVE_SHIFTBBA
232static inline int pLPDivComp(poly p, poly q)
233{
234 if ((currRing->pCompIndex < 0) || (__p_GetComp(p,currRing) == __p_GetComp(q,currRing)))
235 {
236 // maybe there is a more performant way to do this? This will get called quite often in bba.
237 if (_p_LPLmDivisibleByNoComp(p, q, currRing)) return 1;
238 if (_p_LPLmDivisibleByNoComp(q, p, currRing)) return -1;
239 }
240
241 return 0;
242}
243#endif
244
245
248VAR int Kstd1_mu=INT_MAX;
249
250static void deleteHCBucket(LObject *L, kStrategy strat)
251{
252 if ((strat->kNoether!=NULL)
253 && (L->bucket != NULL))
254 {
255 poly p1;
256 for (int i=1; i<= (int) L->bucket->buckets_used; i++)
257 {
258 poly p=L->bucket->buckets[i];
259 if(p!=NULL)
260 {
261 if (p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
262 {
263 L->bucket->buckets[i]=NULL;
264 L->bucket->buckets_length[i]=0;
265 }
266 else
267 {
268 do
269 {
270 if (p_Cmp(pNext(p),strat->kNoetherTail(), L->tailRing) == -1)
271 {
272 p_Delete(&pNext(p), L->tailRing);
273 L->bucket->buckets_length[i]=pLength(L->bucket->buckets[i]);
274 break;
275 }
276 pIter(p);
277 } while(p!=NULL);
278 }
279 }
280 }
281 int i=L->bucket->buckets_used;
282 while ((i>0)&&(L->bucket->buckets[i]==NULL))
283 {
284 i--;
285 L->bucket->buckets_used=i;
286 }
287 }
288}
289
290/*2
291*deletes higher monomial of p, re-compute ecart and length
292*works only for orderings with ecart =pFDeg(end)-pFDeg(start)
293*/
294void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
295{
296 if (strat->kNoether!=NULL)
297 {
298 kTest_L(L,strat);
299 poly p1;
300 poly p = L->GetLmTailRing();
301 int l = 1;
302
303 if (!fromNext && p_Cmp(p,strat->kNoetherTail(), L->tailRing) == -1)
304 {
305 if (L->bucket != NULL) kBucketDestroy(&L->bucket);
306 L->Delete();
307 L->Clear();
308 L->ecart = -1;
309 return;
310 }
311 if (L->bucket != NULL)
312 {
313 deleteHCBucket(L,strat);
314 return;
315 }
316 BOOLEAN cut=FALSE;
317 p1 = p;
318 while (pNext(p1)!=NULL)
319 {
320 if (p_LmCmp(pNext(p1), strat->kNoetherTail(), L->tailRing) == -1)
321 {
322 cut=(pNext(p1)!=NULL);
323 if (cut)
324 {
325 p_Delete(&pNext(p1), L->tailRing);
326
327 if (p1 == p)
328 {
329 if (L->t_p != NULL)
330 {
331 assume(L->p != NULL && p == L->t_p);
332 pNext(L->p) = NULL;
333 }
334 L->max_exp = NULL;
335 }
336 else if (fromNext)
337 L->max_exp = p_GetMaxExpP(pNext(L->p), L->tailRing ); // p1;
338 //if (L->pLength != 0)
339 L->pLength = l;
340 // Hmmm when called from updateT, then only
341 // reset ecart when cut
342 if (fromNext)
343 L->ecart = L->pLDeg() - L->GetpFDeg();
344 }
345 break;
346 }
347 l++;
348 pIter(p1);
349 }
350 if ((!fromNext) && cut)
351 {
352 L->SetpFDeg();
353 L->ecart = L->pLDeg(strat->LDegLast) - L->GetpFDeg();
354 }
355 kTest_L(L,strat);
356 }
357}
358
359void deleteHC(poly* p, int* e, int* l,kStrategy strat)
360{
361 LObject L(*p, currRing, strat->tailRing);
362
363 deleteHC(&L, strat);
364 *p = L.p;
365 *e = L.ecart;
366 *l = L.length;
367 if (L.t_p != NULL) p_LmFree(L.t_p, strat->tailRing);
368}
369
370/*2
371*tests if p.p=monomial*unit and cancels the unit
372*/
374{
375 if(rHasGlobalOrdering (currRing)) return;
376 if(TEST_OPT_CANCELUNIT) return;
377
378 ring r = L->tailRing;
379 poly p = L->GetLmTailRing();
380 if(p_GetComp(p, r) != 0 && !p_OneComp(p, r)) return;
381
382 number lc=NULL; /*dummy, is always set if rField_is_Ring(r) */
383 if (rField_is_Ring(r) /*&& (rHasLocalOrMixedOrdering(r))*/)
384 lc = pGetCoeff(p);
385
386 // Leading coef have to be a unit
387 // example 2x+4x2 should be simplified to 2x*(1+2x)
388 // and 2 is not a unit in Z
389 //if ( !(n_IsUnit(pGetCoeff(p), r->cf)) ) return;
390
391 poly h = pNext(p);
392 int i;
393
395 {
396 loop
397 {
398 if (h==NULL)
399 {
400 p_Delete(&pNext(p), r);
401 if (!inNF)
402 {
403 number eins= nCopy(lc);
404 if (L->p != NULL)
405 {
406 pSetCoeff(L->p,eins);
407 if (L->t_p != NULL)
408 pSetCoeff0(L->t_p,eins);
409 }
410 else
411 pSetCoeff(L->t_p,eins);
412 /* p and t_p share the same coeff, if both are !=NULL */
413 /* p==NULL==t_p cannot happen here */
414 }
415 L->ecart = 0;
416 L->length = 1;
417 //if (L->pLength > 0)
418 L->pLength = 1;
419 L->max_exp = NULL;
420
421 if (L->t_p != NULL && pNext(L->t_p) != NULL)
422 p_Delete(&pNext(L->t_p),r);
423 if (L->p != NULL && pNext(L->p) != NULL)
424 pNext(L->p) = NULL;
425 return;
426 }
427 i = rVar(r);
428 loop
429 {
430 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
431 i--;
432 if (i == 0) break; // does divide, try next monom
433 }
434 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
435 // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
436 // domains), no zerodivisor test needed CAUTION
437 if (!n_DivBy(pGetCoeff(h),lc,r->cf))
438 {
439 return;
440 }
441 pIter(h);
442 }
443 }
444 else
445 {
446 loop
447 {
448 if (h==NULL)
449 {
450 p_Delete(&pNext(p), r);
451 if (!inNF)
452 {
453 number eins=nInit(1);
454 if (L->p != NULL)
455 {
456 pSetCoeff(L->p,eins);
457 if (L->t_p != NULL)
458 pSetCoeff0(L->t_p,eins);
459 }
460 else
461 pSetCoeff(L->t_p,eins);
462 /* p and t_p share the same coeff, if both are !=NULL */
463 /* p==NULL==t_p cannot happen here */
464 }
465 L->ecart = 0;
466 L->length = 1;
467 //if (L->pLength > 0)
468 L->pLength = 1;
469 L->max_exp = NULL;
470
471 if (L->t_p != NULL && pNext(L->t_p) != NULL)
472 p_Delete(&pNext(L->t_p),r);
473 if (L->p != NULL && pNext(L->p) != NULL)
474 pNext(L->p) = NULL;
475
476 return;
477 }
478 i = rVar(r);
479 loop
480 {
481 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
482 i--;
483 if (i == 0) break; // does divide, try next monom
484 }
485 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
486 pIter(h);
487 }
488 }
489}
490
491/*2
492*pp is the new element in s
493*returns TRUE (in strat->kAllAxis) if
494*-HEcke is allowed
495*-we are in the last componente of the vector
496*-on all axis are monomials (all elements in NotUsedAxis are FALSE)
497*returns FALSE for pLexOrderings,
498*assumes in module case an ordering of type c* !!
499* HEckeTest is only called with strat->kAllAxis==FALSE !
500*/
501void HEckeTest (poly pp,kStrategy strat)
502{
503 int j,/*k,*/p;
504
505 if (currRing->pLexOrder
507 || (strat->ak >1)
509 {
510 return;
511 }
513 if (p!=0)
514 strat->NotUsedAxis[p] = FALSE;
515 /*- the leading term of pp is a power of the p-th variable -*/
516 for (j=(currRing->N);j>0; j--)
517 {
518 if (strat->NotUsedAxis[j])
519 {
520 strat->kAllAxis=FALSE;
521 return;
522 }
523 }
524 strat->kAllAxis=TRUE;
525}
526
527/*2
528*utilities for TSet, LSet
529*/
530inline static intset initec (const int maxnr)
531{
532 return (intset)omAlloc(maxnr*sizeof(int));
533}
534
535inline static unsigned long* initsevS (const int maxnr)
536{
537 return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
538}
539inline static int* initS_2_R (const int maxnr)
540{
541 return (int*)omAlloc0(maxnr*sizeof(int));
542}
543
544static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
545 int &length, const int incr)
546{
547 assume(T!=NULL);
548 assume(sevT!=NULL);
549 assume(R!=NULL);
550 assume((length+incr) > 0);
551
552 int i;
553 T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
554 (length+incr)*sizeof(TObject));
555
556 sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
557 (length+incr)*sizeof(long*));
558
559 R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
560 (length+incr)*sizeof(TObject*));
561 for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
562 length += incr;
563}
564
565void cleanT (kStrategy strat)
566{
567 int i,j;
568 poly p;
569 assume(currRing == strat->tailRing || strat->tailRing != NULL);
570
571 pShallowCopyDeleteProc p_shallow_copy_delete =
572 (strat->tailRing != currRing ?
574 NULL);
575 for (j=0; j<=strat->tl; j++)
576 {
577 p = strat->T[j].p;
578 strat->T[j].p=NULL;
579 if (strat->T[j].max_exp != NULL)
580 {
581 p_LmFree(strat->T[j].max_exp, strat->tailRing);
582 }
583 i = -1;
584 loop
585 {
586 i++;
587 if (i>strat->sl)
588 {
589 if (strat->T[j].t_p != NULL)
590 {
591 p_Delete(&(strat->T[j].t_p), strat->tailRing);
593 }
594 else
595 {
596#ifdef HAVE_SHIFTBBA
597 if (currRing->isLPring && strat->T[j].shift > 0)
598 {
599 pNext(p) = NULL; // pNext(p) points to the unshifted tail, don't try to delete it here
600 }
601#endif
602 pDelete(&p);
603 }
604 break;
605 }
606 if (p == strat->S[i])
607 {
608 if (strat->T[j].t_p != NULL)
609 {
610 if (p_shallow_copy_delete!=NULL)
611 {
612 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
613 currRing->PolyBin);
614 }
615 p_LmFree(strat->T[j].t_p, strat->tailRing);
616 }
617 break;
618 }
619 }
620 }
621 strat->tl=-1;
622}
623
625{
626 int i,j;
627 poly p;
628 assume(currRing == strat->tailRing || strat->tailRing != NULL);
629
630 pShallowCopyDeleteProc p_shallow_copy_delete =
631 (strat->tailRing != currRing ?
633 NULL);
634 for (j=0; j<=strat->tl; j++)
635 {
636 p = strat->T[j].p;
637 strat->T[j].p=NULL;
638 if (strat->T[j].max_exp != NULL)
639 {
640 p_LmFree(strat->T[j].max_exp, strat->tailRing);
641 }
642 i = -1;
643 loop
644 {
645 i++;
646 if (i>strat->sl)
647 {
648 if (strat->T[j].t_p != NULL)
649 {
650 p_Delete(&(strat->T[j].t_p), strat->tailRing);
652 }
653 else
654 {
655 //pDelete(&p);
656 p = NULL;
657 }
658 break;
659 }
660 if (p == strat->S[i])
661 {
662 if (strat->T[j].t_p != NULL)
663 {
664 assume(p_shallow_copy_delete != NULL);
665 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
666 currRing->PolyBin);
667 p_LmFree(strat->T[j].t_p, strat->tailRing);
668 }
669 break;
670 }
671 }
672 }
673 strat->tl=-1;
674}
675
676//LSet initL ()
677//{
678// int i;
679// LSet l = (LSet)omAlloc(setmaxL*sizeof(LObject));
680// return l;
681//}
682
683static inline void enlargeL (LSet* L,int* length,const int incr)
684{
685 assume((*L)!=NULL);
686 assume(((*length)+incr)>0);
687
688 *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
689 ((*length)+incr)*sizeof(LObject));
690 (*length) += incr;
691}
692
694{
695 strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
696}
697
698/*2
699*test whether (p1,p2) or (p2,p1) is in L up position length
700*it returns TRUE if yes and the position k
701*/
702BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
703{
704 LObject *p=&(strat->L[length]);
705
706 *k = length;
707 loop
708 {
709 if ((*k) < 0) return FALSE;
710 if (((p1 == (*p).p1) && (p2 == (*p).p2))
711 || ((p1 == (*p).p2) && (p2 == (*p).p1)))
712 return TRUE;
713 (*k)--;
714 p--;
715 }
716}
717
718int kFindInT(poly p, TSet T, int tlength)
719{
720 int i;
721
722 for (i=0; i<=tlength; i++)
723 {
724 if (T[i].p == p) return i;
725 }
726 return -1;
727}
728
729int kFindInT(poly p, kStrategy strat)
730{
731 int i;
732 do
733 {
734 i = kFindInT(p, strat->T, strat->tl);
735 if (i >= 0) return i;
736 strat = strat->next;
737 }
738 while (strat != NULL);
739 return -1;
740}
741
742#ifdef HAVE_SHIFTBBA
743int kFindInTShift(poly p, TSet T, int tlength)
744{
745 int i;
746
747 for (i=0; i<=tlength; i++)
748 {
749 // in the Letterplace ring the LMs in T and L are copies thus we have to use pEqualPolys() instead of ==
750 if (pEqualPolys(T[i].p, p)) return i;
751 }
752 return -1;
753}
754#endif
755
756#ifdef HAVE_SHIFTBBA
757int kFindInTShift(poly p, kStrategy strat)
758{
759 int i;
760 do
761 {
762 i = kFindInTShift(p, strat->T, strat->tl);
763 if (i >= 0) return i;
764 strat = strat->next;
765 }
766 while (strat != NULL);
767 return -1;
768}
769#endif
770
771#ifdef KDEBUG
772
774{
775 if (t_p != NULL) p_wrp(t_p, tailRing);
776 else if (p != NULL) p_wrp(p, currRing, tailRing);
777 else ::wrp(NULL);
778}
779
780#define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
781
782// check that Lm's of a poly from T are "equal"
783static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
784{
785 int i;
786 for (i=1; i<=tailRing->N; i++)
787 {
788 if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
789 return "Lm[i] different";
790 }
791 if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
792 return "Lm[0] different";
793 if (pNext(p) != pNext(t_p))
794 return "Lm.next different";
795 if (pGetCoeff(p) != pGetCoeff(t_p))
796 return "Lm.coeff different";
797 return NULL;
798}
799
801BOOLEAN kTest_T(TObject * T, kStrategy strat, int i, char TN)
802{
803 ring tailRing = T->tailRing;
804 ring strat_tailRing = strat->tailRing;
805 if (strat_tailRing == NULL) strat_tailRing = tailRing;
806 r_assume(strat_tailRing == tailRing);
807
808 poly p = T->p;
809 // ring r = currRing;
810
811 if (T->p == NULL && T->t_p == NULL && i >= 0)
812 return dReportError("%c[%d].poly is NULL", TN, i);
813
814 if (T->p!=NULL)
815 {
816 nTest(pGetCoeff(T->p));
817 if ((T->t_p==NULL)&&(pNext(T->p)!=NULL)) p_Test(pNext(T->p),currRing);
818 }
819 if (T->t_p!=NULL)
820 {
821 nTest(pGetCoeff(T->t_p));
822 if (pNext(T->t_p)!=NULL) p_Test(pNext(T->t_p),strat_tailRing);
823 }
824 if ((T->p!=NULL)&&(T->t_p!=NULL)) assume(pGetCoeff(T->p)==pGetCoeff(T->t_p));
825
826 if (T->tailRing != currRing)
827 {
828 if (T->t_p == NULL && i > 0)
829 return dReportError("%c[%d].t_p is NULL", TN, i);
830 pFalseReturn(p_Test(T->t_p, T->tailRing));
831 if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
832 if ((T->p != NULL) && (T->t_p != NULL))
833 {
834 const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
835 if (msg != NULL)
836 return dReportError("%c[%d] %s", TN, i, msg);
837 // r = T->tailRing;
838 p = T->t_p;
839 }
840 if (T->p == NULL)
841 {
842 p = T->t_p;
843 // r = T->tailRing;
844 }
845 if (T->t_p != NULL && i >= 0 && TN == 'T')
846 {
847 if (pNext(T->t_p) == NULL)
848 {
849 if (T->max_exp != NULL)
850 return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
851 }
852 else
853 {
854 if (T->max_exp == NULL)
855 return dReportError("%c[%d].max_exp is NULL", TN, i);
856 if (pNext(T->max_exp) != NULL)
857 return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
858
859 pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
860 omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
861#if KDEBUG > 0
862 if (! sloppy_max)
863 {
864 poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
865 p_Setm(T->max_exp, tailRing);
866 p_Setm(test_max, tailRing);
867 BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
868 if (! equal)
869 return dReportError("%c[%d].max out of sync", TN, i);
870 p_LmFree(test_max, tailRing);
871 }
872#endif
873 }
874 }
875 }
876 else
877 {
878 if (T->p == NULL && i > 0)
879 return dReportError("%c[%d].p is NULL", TN, i);
880#ifdef HAVE_SHIFTBBA
881 if (currRing->isLPring && T->shift > 0)
882 {
883 // in this case, the order is not correct. test LM and tail separately
886 }
887 else
888#endif
889 {
891 }
892 }
893
894 if ((i >= 0) && (T->pLength != 0)
895 && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
896 {
897 int l=T->pLength;
898 T->pLength=pLength(p);
899 return dReportError("%c[%d] pLength error: has %d, specified to have %d",
900 TN, i , pLength(p), l);
901 }
902
903 // check FDeg, for elements in L and T
904 if (i >= 0 && (TN == 'T' || TN == 'L'))
905 {
906 // FDeg has ir element from T of L set
907 if (strat->homog && (T->FDeg != T->pFDeg()))
908 {
909 int d=T->FDeg;
910 T->FDeg=T->pFDeg();
911 return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
912 TN, i , T->pFDeg(), d);
913 }
914 }
915
916 // check is_normalized for elements in T
917 if (i >= 0 && TN == 'T')
918 {
919 if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
920 return dReportError("T[%d] is_normalized error", i);
921
922 }
923 return TRUE;
924}
925
927 BOOLEAN testp, int lpos, TSet T, int tlength)
928{
929 ring strat_tailRing=strat->tailRing;
930 if (L->p!=NULL)
931 {
932 if ((L->t_p==NULL)
933 &&(pNext(L->p)!=NULL)
934 &&(pGetCoeff(pNext(L->p))!=NULL)) /* !=strat->tail*/
935 {
936 p_Test(pNext(L->p),currRing);
937 nTest(pGetCoeff(L->p));
938 }
939 }
940 if (L->t_p!=NULL)
941 {
942 if ((pNext(L->t_p)!=NULL)
943 &&(pGetCoeff(pNext(L->t_p))!=NULL)) /* !=strat->tail*/
944 {
945 p_Test(pNext(L->t_p),strat_tailRing);
946 nTest(pGetCoeff(L->t_p));
947 }
948 }
949 if ((L->p!=NULL)&&(L->t_p!=NULL)) assume(pGetCoeff(L->p)==pGetCoeff(L->t_p));
950
951 if (testp)
952 {
953 poly pn = NULL;
954 if (L->bucket != NULL)
955 {
956 kFalseReturn(kbTest(L->bucket));
957 r_assume(L->bucket->bucket_ring == L->tailRing);
958 if (L->p != NULL && pNext(L->p) != NULL)
959 {
960 pn = pNext(L->p);
961 pNext(L->p) = NULL;
962 }
963 }
964 kFalseReturn(kTest_T(L, strat, lpos, 'L'));
965 if (pn != NULL)
966 pNext(L->p) = pn;
967
968 ring r;
969 poly p;
970 L->GetLm(p, r);
971 if (L->sev != 0L)
972 {
973 if (p_GetShortExpVector(p, r) != L->sev)
974 {
975 return dReportError("L[%d] wrong sev: has %lo, specified to have %lo",
976 lpos, p_GetShortExpVector(p, r), L->sev);
977 }
978 }
979 }
980 if (L->p1 == NULL)
981 {
982 // L->p2 either NULL or "normal" poly
983 pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
984 }
985 else if (tlength > 0 && T != NULL && (lpos >=0))
986 {
987 // now p1 and p2 must be != NULL and must be contained in T
988 int i;
989#ifdef HAVE_SHIFTBBA
990 if (rIsLPRing(currRing))
991 i = kFindInTShift(L->p1, T, tlength);
992 else
993#endif
994 i = kFindInT(L->p1, T, tlength);
995 if (i < 0)
996 return dReportError("L[%d].p1 not in T",lpos);
997#ifdef HAVE_SHIFTBBA
998 if (rIsLPRing(currRing))
999 {
1000 if (rField_is_Ring(currRing)) return TRUE; // m*shift(q) is not in T
1001 i = kFindInTShift(L->p2, T, tlength);
1002 }
1003 else
1004#endif
1005 i = kFindInT(L->p2, T, tlength);
1006 if (i < 0)
1007 return dReportError("L[%d].p2 not in T",lpos);
1008 }
1009 return TRUE;
1010}
1011
1013{
1014 int i;
1015 // test P
1016 kFalseReturn(kTest_L(&(strat->P), strat,
1017 (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
1018 -1, strat->T, strat->tl));
1019
1020 // test T
1021 if (strat->T != NULL)
1022 {
1023 for (i=0; i<=strat->tl; i++)
1024 {
1025 kFalseReturn(kTest_T(&(strat->T[i]), strat, i, 'T'));
1026 if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
1027 return dReportError("strat->sevT[%d] out of sync", i);
1028 }
1029 }
1030
1031 // test L
1032 if (strat->L != NULL)
1033 {
1034 for (i=0; i<=strat->Ll; i++)
1035 {
1036 kFalseReturn(kTest_L(&(strat->L[i]), strat,
1037 strat->L[i].Next() != strat->tail, i,
1038 strat->T, strat->tl));
1039 // may be unused
1040 //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
1041 // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
1042 //{
1043 // assume(strat->L[i].bucket != NULL);
1044 //}
1045 }
1046 }
1047
1048 // test S
1049 if (strat->S != NULL)
1050 kFalseReturn(kTest_S(strat));
1051
1052 return TRUE;
1053}
1054
1056{
1057 int i;
1058 BOOLEAN ret = TRUE;
1059 for (i=0; i<=strat->sl; i++)
1060 {
1061 if (strat->S[i] != NULL &&
1062 strat->sevS[i] != pGetShortExpVector(strat->S[i]))
1063 {
1064 return dReportError("S[%d] wrong sev: has %o, specified to have %o",
1065 i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
1066 }
1067 }
1068 return ret;
1069}
1070
1071
1072
1074{
1075 int i, j;
1076 // BOOLEAN ret = TRUE;
1077 kFalseReturn(kTest(strat));
1078
1079 // test strat->R, strat->T[i].i_r
1080 for (i=0; i<=strat->tl; i++)
1081 {
1082 if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1083 return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1084 strat->T[i].i_r);
1085 if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1086 return dReportError("T[%d].i_r with R out of sync", i);
1087 }
1088 // test containment of S inT
1089 if ((strat->S != NULL)&&(strat->tl>=0))
1090 {
1091 for (i=0; i<=strat->sl; i++)
1092 {
1093 j = kFindInT(strat->S[i], strat->T, strat->tl);
1094 if (j < 0)
1095 return dReportError("S[%d] not in T", i);
1096 if (strat->S_2_R[i] != strat->T[j].i_r)
1097 return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1098 i, strat->S_2_R[i], j, strat->T[j].i_r);
1099 }
1100 }
1101 // test strat->L[i].i_r1
1102 #ifdef HAVE_SHIFTBBA
1103 if (!rIsLPRing(currRing)) // in the Letterplace ring we currently don't set/use i_r1 and i_r2
1104 #endif
1105 if (strat->L!=NULL)
1106 {
1107 for (i=0; i<=strat->Ll; i++)
1108 {
1109 if (strat->L[i].p1 != NULL && strat->L[i].p2)
1110 {
1111 if (strat->L[i].i_r1 < 0 ||
1112 strat->L[i].i_r1 > strat->tl ||
1113 strat->L[i].T_1(strat)->p != strat->L[i].p1)
1114 return dReportError("L[%d].i_r1 out of sync", i);
1115 if (strat->L[i].i_r2 < 0 ||
1116 strat->L[i].i_r2 > strat->tl ||
1117 strat->L[i].T_2(strat)->p != strat->L[i].p2)
1118 return dReportError("L[%d].i_r2 out of sync", i);
1119 }
1120 else
1121 {
1122 if (strat->L[i].i_r1 != -1)
1123 return dReportError("L[%d].i_r1 out of sync", i);
1124 if (strat->L[i].i_r2 != -1)
1125 return dReportError("L[%d].i_r2 out of sync", i);
1126 }
1127 if (strat->L[i].i_r != -1)
1128 return dReportError("L[%d].i_r out of sync", i);
1129 }
1130 }
1131 return TRUE;
1132}
1133
1134#endif // KDEBUG
1135
1136/*2
1137*cancels the i-th polynomial in the standardbase s
1138*/
1139void deleteInS (int i,kStrategy strat)
1140{
1141#ifdef ENTER_USE_MEMMOVE
1142 memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1143 memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1144 memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1145 memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1146#else
1147 int j;
1148 for (j=i; j<strat->sl; j++)
1149 {
1150 strat->S[j] = strat->S[j+1];
1151 strat->ecartS[j] = strat->ecartS[j+1];
1152 strat->sevS[j] = strat->sevS[j+1];
1153 strat->S_2_R[j] = strat->S_2_R[j+1];
1154 }
1155#endif
1156 if (strat->lenS!=NULL)
1157 {
1158#ifdef ENTER_USE_MEMMOVE
1159 memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1160#else
1161 for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1162#endif
1163 }
1164 if (strat->lenSw!=NULL)
1165 {
1166#ifdef ENTER_USE_MEMMOVE
1167 memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1168#else
1169 for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1170#endif
1171 }
1172 if (strat->fromQ!=NULL)
1173 {
1174#ifdef ENTER_USE_MEMMOVE
1175 memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1176#else
1177 for (j=i; j<strat->sl; j++)
1178 {
1179 strat->fromQ[j] = strat->fromQ[j+1];
1180 }
1181#endif
1182 }
1183 strat->S[strat->sl] = NULL;
1184 strat->sl--;
1185}
1186
1187#ifdef HAVE_SHIFTBBA
1188static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
1189{
1190 if (rIsLPRing(currRing)
1191 && (strat->P.p1!=NULL))
1192 {
1193 // clean up strat->P.p1: may be shifted
1194 poly p=strat->P.p1;
1195 int lv=currRing->isLPring;
1196 BOOLEAN is_shifted=TRUE;
1197 for (int i=lv;i>0;i--)
1198 {
1199 if (pGetExp(p,i)!=0) { is_shifted=FALSE; break;}
1200 }
1201 if (is_shifted
1202 && (kFindInL1(p, strat)<0)
1203 && (kFindInT(p, strat->T, strat->tl) < 0)
1204 )
1205 {
1206 return TRUE;
1207 }
1208 }
1209 return FALSE;
1210}
1211#endif
1212/*2
1213*cancels the j-th polynomial in the set
1214*/
1215void deleteInL (LSet set, int *length, int j,kStrategy strat)
1216{
1217 if (set[j].lcm!=NULL)
1218 {
1219 kDeleteLcm(&set[j]);
1220 }
1221 if (set[j].sig!=NULL)
1222 {
1223#ifdef HAVE_RINGS
1224 if (pGetCoeff(set[j].sig) != NULL)
1225 pLmDelete(set[j].sig);
1226 else
1227#endif
1228 pLmFree(set[j].sig);
1229 }
1230 if (set[j].p!=NULL)
1231 {
1232 if (pNext(set[j].p) == strat->tail)
1233 {
1234#ifdef HAVE_RINGS
1235 if (pGetCoeff(set[j].p) != NULL)
1236 pLmDelete(set[j].p);
1237 else
1238#endif
1239 pLmFree(set[j].p);
1240 /*- tail belongs to several int spolys -*/
1241 }
1242 else
1243 {
1244 // search p in T, if it is there, do not delete it
1245 if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1246 {
1247 // assure that for global orderings kFindInT fails
1248 //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1249 set[j].Delete();
1250 }
1251 }
1252 }
1253 #ifdef HAVE_SHIFTBBA
1254 if (is_shifted_p1(strat->P.p1,strat))
1255 {
1256 // clean up strat->P.p1: may be shifted
1257 pLmDelete(strat->P.p1);
1258 strat->P.p1=NULL;
1259 }
1260 #endif
1261 if (*length > 0 && j < *length)
1262 {
1263#ifdef ENTER_USE_MEMMOVE
1264 memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1265#else
1266 int i;
1267 for (i=j; i < (*length); i++)
1268 set[i] = set[i+1];
1269#endif
1270 }
1271#ifdef KDEBUG
1272 memset(&(set[*length]),0,sizeof(LObject));
1273#endif
1274 (*length)--;
1275}
1276
1277/*2
1278*enters p at position at in L
1279*/
1280void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1281{
1282 // this should be corrected
1283 assume(p.FDeg == p.pFDeg());
1284
1285 if ((*length)>=0)
1286 {
1287 if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1288 if (at <= (*length))
1289#ifdef ENTER_USE_MEMMOVE
1290 memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1291#else
1292 for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1293#endif
1294 }
1295 else at = 0;
1296 (*set)[at] = p;
1297 (*length)++;
1298}
1299
1300/*2
1301* computes the normal ecart;
1302* used in mora case and if pLexOrder & sugar in bba case
1303*/
1305{
1306 h->FDeg = h->pFDeg();
1307 h->ecart = h->pLDeg() - h->FDeg;
1308 // h->length is set by h->pLDeg
1309 h->length=h->pLength=pLength(h->p);
1310}
1311
1313{
1314 h->FDeg = h->pFDeg();
1315 (*h).ecart = 0;
1316 h->length=h->pLength=pLength(h->p);
1317}
1318
1319void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1320{
1321 Lp->FDeg = Lp->pFDeg();
1322 (*Lp).ecart = 0;
1323 (*Lp).length = 0;
1324}
1325
1326void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1327{
1328 Lp->FDeg = Lp->pFDeg();
1329 (*Lp).ecart = si_max(ecartF,ecartG);
1330 (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1331 (*Lp).length = 0;
1332}
1333
1334/*2
1335*if ecart1<=ecart2 it returns TRUE
1336*/
1337static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1338{
1339 return (ecart1 <= ecart2);
1340}
1341
1342#ifdef HAVE_RINGS
1343/*2
1344* put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1345*/
1346static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1347{
1348 assume(atR >= 0);
1349 assume(i<=strat->sl);
1350 assume(p!=NULL);
1352 #if ALL_VS_JUST
1353 //Over rings, if we construct the strong pair, do not add the spair
1355 {
1356 number s,t,d;
1357 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1358
1359 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1360 {
1361 nDelete(&d);
1362 nDelete(&s);
1363 nDelete(&t);
1364 return;
1365 }
1366 nDelete(&d);
1367 nDelete(&s);
1368 nDelete(&t);
1369 }
1370 #endif
1371 int j,compare,compareCoeff;
1372 LObject h;
1373
1374#ifdef KDEBUG
1375 h.ecart=0; h.length=0;
1376#endif
1377 /*- computes the lcm(s[i],p) -*/
1378 if(pHasNotCFRing(p,strat->S[i]))
1379 {
1380 strat->cp++;
1381 return;
1382 }
1383 h.lcm = p_Lcm(p,strat->S[i],currRing);
1384 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1385 if (nIsZero(pGetCoeff(h.lcm)))
1386 {
1387 strat->cp++;
1388 pLmDelete(h.lcm);
1389 return;
1390 }
1391 // basic chain criterion
1392 /*
1393 *the set B collects the pairs of type (S[j],p)
1394 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1395 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
1396 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
1397 */
1398
1399 for(j = strat->Bl;j>=0;j--)
1400 {
1401 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1402 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1403 if(compare == pDivComp_EQUAL)
1404 {
1405 //They have the same LM
1406 if(compareCoeff == pDivComp_LESS)
1407 {
1408 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1409 {
1410 strat->c3++;
1411 pLmDelete(h.lcm);
1412 return;
1413 }
1414 break;
1415 }
1416 if(compareCoeff == pDivComp_GREATER)
1417 {
1418 deleteInL(strat->B,&strat->Bl,j,strat);
1419 strat->c3++;
1420 }
1421 if(compareCoeff == pDivComp_EQUAL)
1422 {
1423 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1424 {
1425 strat->c3++;
1426 pLmDelete(h.lcm);
1427 return;
1428 }
1429 break;
1430 }
1431 }
1432 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1433 {
1434 if(compare == pDivComp_LESS)
1435 {
1436 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1437 {
1438 strat->c3++;
1439 pLmDelete(h.lcm);
1440 return;
1441 }
1442 break;
1443 }
1444 if(compare == pDivComp_GREATER)
1445 {
1446 deleteInL(strat->B,&strat->Bl,j,strat);
1447 strat->c3++;
1448 }
1449 }
1450 }
1451 number s, t;
1452 poly m1, m2, gcd = NULL;
1453 s = pGetCoeff(strat->S[i]);
1454 t = pGetCoeff(p);
1455 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1456 ksCheckCoeff(&s, &t, currRing->cf);
1457 pSetCoeff0(m1, s);
1458 pSetCoeff0(m2, t);
1459 m2 = pNeg(m2);
1460 p_Test(m1,strat->tailRing);
1461 p_Test(m2,strat->tailRing);
1462 poly si = pCopy(strat->S[i]);
1463 poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1464 poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1465 pDelete(&si);
1466 p_LmDelete(m1, currRing);
1467 p_LmDelete(m2, currRing);
1468 if(sim2 == NULL)
1469 {
1470 if(pm1 == NULL)
1471 {
1472 if(h.lcm != NULL)
1473 {
1474 pLmDelete(h.lcm);
1475 h.lcm=NULL;
1476 }
1477 h.Clear();
1478 if (strat->pairtest==NULL) initPairtest(strat);
1479 strat->pairtest[i] = TRUE;
1480 strat->pairtest[strat->sl+1] = TRUE;
1481 return;
1482 }
1483 else
1484 {
1485 gcd = pm1;
1486 pm1 = NULL;
1487 }
1488 }
1489 else
1490 {
1491 if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1492 {
1493 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1494 pSetmComp(sim2);
1495 }
1496 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1497 gcd = p_Add_q(pm1, sim2, strat->tailRing);
1498 }
1499 p_Test(gcd, strat->tailRing);
1500#ifdef KDEBUG
1501 if (TEST_OPT_DEBUG)
1502 {
1503 wrp(gcd);
1504 PrintLn();
1505 }
1506#endif
1507 h.p = gcd;
1508 h.i_r = -1;
1509 if(h.p == NULL)
1510 {
1511 if (strat->pairtest==NULL) initPairtest(strat);
1512 strat->pairtest[i] = TRUE;
1513 strat->pairtest[strat->sl+1] = TRUE;
1514 return;
1515 }
1516 h.tailRing = strat->tailRing;
1517 int posx;
1518 //h.pCleardenom();
1519 //pSetm(h.p);
1520 h.i_r1 = -1;h.i_r2 = -1;
1521 strat->initEcart(&h);
1522 #if 1
1523 h.p2 = strat->S[i];
1524 h.p1 = p;
1525 #endif
1526 #if 1
1527 if (atR >= 0)
1528 {
1529 h.i_r1 = atR;
1530 h.i_r2 = strat->S_2_R[i];
1531 }
1532 #endif
1533 if (strat->Bl==-1)
1534 posx =0;
1535 else
1536 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1537 h.sev = pGetShortExpVector(h.p);
1538 if (currRing!=strat->tailRing)
1539 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1540 if (strat->P.p!=NULL) strat->P.sev = pGetShortExpVector(strat->P.p);
1541 else strat->P.sev=0L;
1542 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1543 kTest_TS(strat);
1544}
1545
1546/*2
1547* put the lcm(s[i],p) into the set B
1548*/
1549
1550static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1551{
1552 number d, s, t;
1553 assume(atR >= 0);
1555 poly m1, m2, gcd,si;
1556 if(!enterTstrong)
1557 {
1558 assume(i<=strat->sl);
1559 si = strat->S[i];
1560 }
1561 else
1562 {
1563 assume(i<=strat->tl);
1564 si = strat->T[i].p;
1565 }
1566 //printf("\n--------------------------------\n");
1567 //pWrite(p);pWrite(si);
1568 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1569
1570 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1571 {
1572 nDelete(&d);
1573 nDelete(&s);
1574 nDelete(&t);
1575 return FALSE;
1576 }
1577
1578 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1579
1581 {
1582 unsigned long sev = pGetShortExpVector(gcd);
1583
1584 for (int j = 0; j < strat->sl; j++)
1585 {
1586 if (j == i)
1587 continue;
1588
1589 if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf)
1590 && !(strat->sevS[j] & ~sev)
1591 && p_LmDivisibleBy(strat->S[j], gcd, currRing))
1592 {
1593 nDelete(&d);
1594 nDelete(&s);
1595 nDelete(&t);
1596 return FALSE;
1597 }
1598 }
1599 }
1600
1601 //p_Test(m1,strat->tailRing);
1602 //p_Test(m2,strat->tailRing);
1603 /*if(!enterTstrong)
1604 {
1605 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1606 {
1607 memset(&(strat->P), 0, sizeof(strat->P));
1608 kStratChangeTailRing(strat);
1609 strat->P = *(strat->R[atR]);
1610 p_LmFree(m1, strat->tailRing);
1611 p_LmFree(m2, strat->tailRing);
1612 p_LmFree(gcd, currRing);
1613 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1614 }
1615 }*/
1616 pSetCoeff0(m1, s);
1617 pSetCoeff0(m2, t);
1618 pSetCoeff0(gcd, d);
1619 p_Test(m1,strat->tailRing);
1620 p_Test(m2,strat->tailRing);
1621 //printf("\n===================================\n");
1622 //pWrite(m1);pWrite(m2);pWrite(gcd);
1623#ifdef KDEBUG
1624 if (TEST_OPT_DEBUG)
1625 {
1626 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1627 PrintS("m1 = ");
1628 p_wrp(m1, strat->tailRing);
1629 PrintS(" ; m2 = ");
1630 p_wrp(m2, strat->tailRing);
1631 PrintS(" ; gcd = ");
1632 wrp(gcd);
1633 PrintS("\n--- create strong gcd poly: ");
1634 Print("\n p: %d", i);
1635 wrp(p);
1636 Print("\n strat->S[%d]: ", i);
1637 wrp(si);
1638 PrintS(" ---> ");
1639 }
1640#endif
1641
1642 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1643 p_LmDelete(m1, strat->tailRing);
1644 p_LmDelete(m2, strat->tailRing);
1645#ifdef KDEBUG
1646 if (TEST_OPT_DEBUG)
1647 {
1648 wrp(gcd);
1649 PrintLn();
1650 }
1651#endif
1652
1653 LObject h;
1654 h.p = gcd;
1655 h.tailRing = strat->tailRing;
1656 int posx;
1657 strat->initEcart(&h);
1658 h.sev = pGetShortExpVector(h.p);
1659 h.i_r1 = -1;h.i_r2 = -1;
1660 if (currRing!=strat->tailRing)
1661 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1662 if(!enterTstrong)
1663 {
1664 #if 1
1665 h.p1 = p;h.p2 = strat->S[i];
1666 #endif
1667 if (atR >= 0)
1668 {
1669 h.i_r2 = strat->S_2_R[i];
1670 h.i_r1 = atR;
1671 }
1672 else
1673 {
1674 h.i_r1 = -1;
1675 h.i_r2 = -1;
1676 }
1677 if (strat->Ll==-1)
1678 posx =0;
1679 else
1680 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1681 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1682 }
1683 else
1684 {
1685 if(h.IsNull()) return FALSE;
1686 //int red_result;
1687 //reduzieren ist teur!!!
1688 //if(strat->L != NULL)
1689 //red_result = strat->red(&h,strat);
1690 if(!h.IsNull())
1691 {
1692 enterT(h, strat,-1);
1693 //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1694 //strat->enterS(h,pos,strat,-1);
1695 }
1696 }
1697 return TRUE;
1698}
1699
1701{
1702 if(strat->sl < 0) return FALSE;
1703 int i;
1704 for(i=0;i<strat->sl;i++)
1705 {
1706 //Construct the gcd pair between h and S[i]
1707 number d, s, t;
1708 poly m1, m2, gcd;
1709 d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1710 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1711 {
1712 nDelete(&d);
1713 nDelete(&s);
1714 nDelete(&t);
1715 }
1716 else
1717 {
1718 k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1719 pSetCoeff0(m1, s);
1720 pSetCoeff0(m2, t);
1721 pSetCoeff0(gcd, d);
1722 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);
1723 poly pSigMult = p_Copy(h->sig,currRing);
1724 poly sSigMult = p_Copy(strat->sig[i],currRing);
1725 pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1726 sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1727 p_LmDelete(m1, strat->tailRing);
1728 p_LmDelete(m2, strat->tailRing);
1729 poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1730 if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1731 {
1732 pDelete(&h->p);
1733 h->p = gcd;
1734 pDelete(&h->sig);
1735 h->sig = pairsig;
1736 pNext(h->sig) = NULL;
1737 strat->initEcart(h);
1738 h->sev = pGetShortExpVector(h->p);
1739 h->sevSig = pGetShortExpVector(h->sig);
1740 h->i_r1 = -1;h->i_r2 = -1;
1741 if(h->lcm != NULL)
1742 {
1743 pLmDelete(h->lcm);
1744 h->lcm = NULL;
1745 }
1746 if (currRing!=strat->tailRing)
1747 h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1748 return TRUE;
1749 }
1750 //Delete what you didn't use
1751 pDelete(&gcd);
1752 pDelete(&pairsig);
1753 }
1754 }
1755 return FALSE;
1756}
1757
1758static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1759{
1760 number d, s, t;
1761 assume(atR >= 0);
1762 poly m1, m2, gcd,si;
1763 assume(i<=strat->sl);
1764 si = strat->S[i];
1765 //printf("\n--------------------------------\n");
1766 //pWrite(p);pWrite(si);
1767 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1768
1769 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1770 {
1771 nDelete(&d);
1772 nDelete(&s);
1773 nDelete(&t);
1774 return FALSE;
1775 }
1776
1777 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1778 //p_Test(m1,strat->tailRing);
1779 //p_Test(m2,strat->tailRing);
1780 /*if(!enterTstrong)
1781 {
1782 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1783 {
1784 memset(&(strat->P), 0, sizeof(strat->P));
1785 kStratChangeTailRing(strat);
1786 strat->P = *(strat->R[atR]);
1787 p_LmFree(m1, strat->tailRing);
1788 p_LmFree(m2, strat->tailRing);
1789 p_LmFree(gcd, currRing);
1790 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1791 }
1792 }*/
1793 pSetCoeff0(m1, s);
1794 pSetCoeff0(m2, t);
1795 pSetCoeff0(gcd, d);
1796 p_Test(m1,strat->tailRing);
1797 p_Test(m2,strat->tailRing);
1798 //printf("\n===================================\n");
1799 //pWrite(m1);pWrite(m2);pWrite(gcd);
1800#ifdef KDEBUG
1801 if (TEST_OPT_DEBUG)
1802 {
1803 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1804 PrintS("m1 = ");
1805 p_wrp(m1, strat->tailRing);
1806 PrintS(" ; m2 = ");
1807 p_wrp(m2, strat->tailRing);
1808 PrintS(" ; gcd = ");
1809 wrp(gcd);
1810 PrintS("\n--- create strong gcd poly: ");
1811 Print("\n p: %d", i);
1812 wrp(p);
1813 Print("\n strat->S[%d]: ", i);
1814 wrp(si);
1815 PrintS(" ---> ");
1816 }
1817#endif
1818
1819 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1820
1821#ifdef KDEBUG
1822 if (TEST_OPT_DEBUG)
1823 {
1824 wrp(gcd);
1825 PrintLn();
1826 }
1827#endif
1828
1829 //Check and set the signatures
1830 poly pSigMult = p_Copy(sig,currRing);
1831 poly sSigMult = p_Copy(strat->sig[i],currRing);
1832 pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1833 sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1834 p_LmDelete(m1, strat->tailRing);
1835 p_LmDelete(m2, strat->tailRing);
1836 poly pairsig;
1837 if(pLmCmp(pSigMult,sSigMult) == 0)
1838 {
1839 //Same lm, have to add them
1840 pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1841 //This might be zero
1842 }
1843 else
1844 {
1845 //Set the sig to either pSigMult or sSigMult
1846 if(pLtCmp(pSigMult,sSigMult)==1)
1847 {
1848 pairsig = pSigMult;
1849 pDelete(&sSigMult);
1850 }
1851 else
1852 {
1853 pairsig = sSigMult;
1854 pDelete(&pSigMult);
1855 }
1856 }
1857
1858 LObject h;
1859 h.p = gcd;
1860 h.tailRing = strat->tailRing;
1861 h.sig = pairsig;
1862 int posx;
1863 strat->initEcart(&h);
1864 h.sev = pGetShortExpVector(h.p);
1865 h.i_r1 = -1;h.i_r2 = -1;
1866 if (currRing!=strat->tailRing)
1867 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1868 if(h.sig == NULL)
1869 {
1870 //sigdrop since we loose the signature
1871 strat->sigdrop = TRUE;
1872 //Try to reduce it as far as we can via redRing
1873 int red_result = redRing(&h,strat);
1874 if(red_result == 0)
1875 {
1876 // Cancel the sigdrop
1877 p_Delete(&h.sig,currRing);h.sig = NULL;
1878 strat->sigdrop = FALSE;
1879 return FALSE;
1880 }
1881 else
1882 {
1883 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1884 #if 1
1885 strat->enterS(h,0,strat,strat->tl);
1886 #endif
1887 return FALSE;
1888 }
1889 }
1890 if(!nGreaterZero(pGetCoeff(h.sig)))
1891 {
1892 h.sig = pNeg(h.sig);
1893 h.p = pNeg(h.p);
1894 }
1895
1896 if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1897 {
1898 strat->sigdrop = TRUE;
1899 // Completely reduce it
1900 int red_result = redRing(&h,strat);
1901 if(red_result == 0)
1902 {
1903 // Reduced to 0
1904 strat->sigdrop = FALSE;
1905 p_Delete(&h.sig,currRing);h.sig = NULL;
1906 return FALSE;
1907 }
1908 else
1909 {
1910 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1911 // 0 - add just the original poly causing the sigdrop, 1 - add also this
1912 #if 1
1913 strat->enterS(h,0,strat, strat->tl+1);
1914 #endif
1915 return FALSE;
1916 }
1917 }
1918 //Check for sigdrop
1919 if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
1920 {
1921 strat->sigdrop = TRUE;
1922 //Enter this element to S
1923 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1924 strat->enterS(h,strat->sl+1,strat,strat->tl+1);
1925 }
1926 #if 1
1927 h.p1 = p;h.p2 = strat->S[i];
1928 #endif
1929 if (atR >= 0)
1930 {
1931 h.i_r2 = strat->S_2_R[i];
1932 h.i_r1 = atR;
1933 }
1934 else
1935 {
1936 h.i_r1 = -1;
1937 h.i_r2 = -1;
1938 }
1939 if (strat->Ll==-1)
1940 posx =0;
1941 else
1942 posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
1943 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1944 return TRUE;
1945}
1946#endif
1947
1948/*2
1949* put the pair (s[i],p) into the set B, ecart=ecart(p)
1950*/
1951
1952void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
1953{
1954 assume(i<=strat->sl);
1955
1956 int l,j,compare;
1957 LObject Lp;
1958 Lp.i_r = -1;
1959
1960#ifdef KDEBUG
1961 Lp.ecart=0; Lp.length=0;
1962#endif
1963 /*- computes the lcm(s[i],p) -*/
1964 Lp.lcm = pInit();
1965
1966#ifndef HAVE_RATGRING
1967 pLcm(p,strat->S[i],Lp.lcm);
1968#elif defined(HAVE_RATGRING)
1969 if (rIsRatGRing(currRing))
1970 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
1971 else
1972 pLcm(p,strat->S[i],Lp.lcm);
1973#endif
1974 pSetm(Lp.lcm);
1975
1976
1977 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
1978 {
1979 if (strat->fromT && (strat->ecartS[i]>ecart))
1980 {
1981 pLmFree(Lp.lcm);
1982 return;
1983 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
1984 }
1985 if((!((strat->ecartS[i]>0)&&(ecart>0)))
1986 && pHasNotCF(p,strat->S[i]))
1987 {
1988 /*
1989 *the product criterion has applied for (s,p),
1990 *i.e. lcm(s,p)=product of the leading terms of s and p.
1991 *Suppose (s,r) is in L and the leading term
1992 *of p divides lcm(s,r)
1993 *(==> the leading term of p divides the leading term of r)
1994 *but the leading term of s does not divide the leading term of r
1995 *(notice that tis condition is automatically satisfied if r is still
1996 *in S), then (s,r) can be cancelled.
1997 *This should be done here because the
1998 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
1999 *
2000 *Moreover, skipping (s,r) holds also for the noncommutative case.
2001 */
2002 strat->cp++;
2003 pLmFree(Lp.lcm);
2004 return;
2005 }
2006 Lp.ecart = si_max(ecart,strat->ecartS[i]);
2007 /*
2008 *the set B collects the pairs of type (S[j],p)
2009 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2010 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2011 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2012 */
2013 {
2014 j = strat->Bl;
2015 loop
2016 {
2017 if (j < 0) break;
2018 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2019 if ((compare==1)
2020 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2021 {
2022 strat->c3++;
2023 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2024 {
2025 pLmFree(Lp.lcm);
2026 return;
2027 }
2028 break;
2029 }
2030 else
2031 if ((compare ==-1)
2032 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2033 {
2034 deleteInL(strat->B,&strat->Bl,j,strat);
2035 strat->c3++;
2036 }
2037 j--;
2038 }
2039 }
2040 }
2041 else /*sugarcrit*/
2042 {
2043 if (ALLOW_PROD_CRIT(strat))
2044 {
2045 if (strat->fromT && (strat->ecartS[i]>ecart))
2046 {
2047 pLmFree(Lp.lcm);
2048 return;
2049 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2050 }
2051 // if currRing->nc_type!=quasi (or skew)
2052 // TODO: enable productCrit for super commutative algebras...
2053 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2054 pHasNotCF(p,strat->S[i]))
2055 {
2056 /*
2057 *the product criterion has applied for (s,p),
2058 *i.e. lcm(s,p)=product of the leading terms of s and p.
2059 *Suppose (s,r) is in L and the leading term
2060 *of p divides lcm(s,r)
2061 *(==> the leading term of p divides the leading term of r)
2062 *but the leading term of s does not divide the leading term of r
2063 *(notice that tis condition is automatically satisfied if r is still
2064 *in S), then (s,r) can be canceled.
2065 *This should be done here because the
2066 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2067 */
2068 strat->cp++;
2069 pLmFree(Lp.lcm);
2070 return;
2071 }
2072 /*
2073 *the set B collects the pairs of type (S[j],p)
2074 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2075 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2076 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2077 */
2078 for(j = strat->Bl;j>=0;j--)
2079 {
2080 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2081 if (compare==1)
2082 {
2083 strat->c3++;
2084 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2085 {
2086 pLmFree(Lp.lcm);
2087 return;
2088 }
2089 break;
2090 }
2091 else
2092 if (compare ==-1)
2093 {
2094 deleteInL(strat->B,&strat->Bl,j,strat);
2095 strat->c3++;
2096 }
2097 }
2098 }
2099 }
2100 /*
2101 *the pair (S[i],p) enters B if the spoly != 0
2102 */
2103 /*- compute the short s-polynomial -*/
2104 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2105 pNorm(p);
2106
2107 if ((strat->S[i]==NULL) || (p==NULL))
2108 return;
2109
2110 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2111 Lp.p=NULL;
2112 else
2113 {
2114 #ifdef HAVE_PLURAL
2115 if ( rIsPluralRing(currRing) )
2116 {
2117 if(pHasNotCF(p, strat->S[i]))
2118 {
2119 if(ncRingType(currRing) == nc_lie)
2120 {
2121 // generalized prod-crit for lie-type
2122 strat->cp++;
2123 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2124 }
2125 else
2126 if( ALLOW_PROD_CRIT(strat) )
2127 {
2128 // product criterion for homogeneous case in SCA
2129 strat->cp++;
2130 Lp.p = NULL;
2131 }
2132 else
2133 {
2134 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2135 nc_CreateShortSpoly(strat->S[i], p, currRing);
2136 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2137 pNext(Lp.p) = strat->tail; // !!!
2138 }
2139 }
2140 else
2141 {
2142 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2143 nc_CreateShortSpoly(strat->S[i], p, currRing);
2144
2145 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2146 pNext(Lp.p) = strat->tail; // !!!
2147 }
2148 }
2149 else
2150 #endif
2151 {
2153 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2154 }
2155 }
2156 if (Lp.p == NULL)
2157 {
2158 /*- the case that the s-poly is 0 -*/
2159 if (strat->pairtest==NULL) initPairtest(strat);
2160 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2161 strat->pairtest[strat->sl+1] = TRUE;
2162 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2163 /*
2164 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2165 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2166 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2167 *term of p divides the lcm(s,r)
2168 *(this canceling should be done here because
2169 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2170 *the first case is handled in chainCrit
2171 */
2172 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2173 }
2174 else
2175 {
2176 /*- the pair (S[i],p) enters B -*/
2177 Lp.p1 = strat->S[i];
2178 Lp.p2 = p;
2179
2180 if (
2182// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2183 )
2184 {
2185 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2186 pNext(Lp.p) = strat->tail; // !!!
2187 }
2188
2189 if (atR >= 0)
2190 {
2191 Lp.i_r1 = strat->S_2_R[i];
2192 Lp.i_r2 = atR;
2193 }
2194 else
2195 {
2196 Lp.i_r1 = -1;
2197 Lp.i_r2 = -1;
2198 }
2199 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2200
2202 {
2205 && (Lp.p->coef!=NULL))
2206 nDelete(&(Lp.p->coef));
2207 }
2208
2209 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2210 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2211 }
2212}
2213
2214/// p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
2215static inline BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2216{
2217 int i = rVar(r);
2218 loop
2219 {
2220 if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2221 return FALSE;
2222 i--;
2223 if (i == 0)
2224 return TRUE;
2225 }
2226}
2227
2228/*2
2229* put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2230* (in the special case: idLift for ideals, i.e. strat->syzComp==1)
2231* (prod.crit applies)
2232*/
2233
2234static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2235{
2236 assume(ALLOW_PROD_CRIT(strat));
2238 assume(i<=strat->sl);
2239 assume(strat->syzComp==1);
2240
2241 if ((strat->S[i]==NULL) || (p==NULL))
2242 return;
2243
2244 int l,j,compare;
2245 LObject Lp;
2246 Lp.i_r = -1;
2247
2248#ifdef KDEBUG
2249 Lp.ecart=0; Lp.length=0;
2250#endif
2251 /*- computes the lcm(s[i],p) -*/
2252 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2253
2254 if (strat->sugarCrit)
2255 {
2256 if((!((strat->ecartS[i]>0)&&(ecart>0)))
2257 && p_HasNotCF_Lift(p,strat->S[i],currRing))
2258 {
2259 /*
2260 *the product criterion has applied for (s,p),
2261 *i.e. lcm(s,p)=product of the leading terms of s and p.
2262 *Suppose (s,r) is in L and the leading term
2263 *of p divides lcm(s,r)
2264 *(==> the leading term of p divides the leading term of r)
2265 *but the leading term of s does not divide the leading term of r
2266 *(notice that tis condition is automatically satisfied if r is still
2267 *in S), then (s,r) can be cancelled.
2268 *This should be done here because the
2269 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2270 *
2271 *Moreover, skipping (s,r) holds also for the noncommutative case.
2272 */
2273 strat->cp++;
2274 pLmFree(Lp.lcm);
2275 return;
2276 }
2277 else
2278 Lp.ecart = si_max(ecart,strat->ecartS[i]);
2279 if (strat->fromT && (strat->ecartS[i]>ecart))
2280 {
2281 pLmFree(Lp.lcm);
2282 return;
2283 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2284 }
2285 /*
2286 *the set B collects the pairs of type (S[j],p)
2287 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2288 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2289 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2290 */
2291 {
2292 j = strat->Bl;
2293 loop
2294 {
2295 if (j < 0) break;
2296 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2297 if ((compare==1)
2298 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2299 {
2300 strat->c3++;
2301 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2302 {
2303 pLmFree(Lp.lcm);
2304 return;
2305 }
2306 break;
2307 }
2308 else
2309 if ((compare ==-1)
2310 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2311 {
2312 deleteInL(strat->B,&strat->Bl,j,strat);
2313 strat->c3++;
2314 }
2315 j--;
2316 }
2317 }
2318 }
2319 else /*sugarcrit*/
2320 {
2321 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2322 p_HasNotCF_Lift(p,strat->S[i],currRing))
2323 {
2324 /*
2325 *the product criterion has applied for (s,p),
2326 *i.e. lcm(s,p)=product of the leading terms of s and p.
2327 *Suppose (s,r) is in L and the leading term
2328 *of p divides lcm(s,r)
2329 *(==> the leading term of p divides the leading term of r)
2330 *but the leading term of s does not divide the leading term of r
2331 *(notice that tis condition is automatically satisfied if r is still
2332 *in S), then (s,r) can be canceled.
2333 *This should be done here because the
2334 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2335 */
2336 strat->cp++;
2337 pLmFree(Lp.lcm);
2338 return;
2339 }
2340 if (strat->fromT && (strat->ecartS[i]>ecart))
2341 {
2342 pLmFree(Lp.lcm);
2343 return;
2344 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2345 }
2346 /*
2347 *the set B collects the pairs of type (S[j],p)
2348 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2349 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2350 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2351 */
2352 for(j = strat->Bl;j>=0;j--)
2353 {
2354 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2355 if (compare==1)
2356 {
2357 strat->c3++;
2358 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2359 {
2360 pLmFree(Lp.lcm);
2361 return;
2362 }
2363 break;
2364 }
2365 else
2366 if (compare ==-1)
2367 {
2368 deleteInL(strat->B,&strat->Bl,j,strat);
2369 strat->c3++;
2370 }
2371 }
2372 }
2373 /*
2374 *the pair (S[i],p) enters B if the spoly != 0
2375 */
2376 /*- compute the short s-polynomial -*/
2377 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2378 pNorm(p);
2379
2380 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2381 Lp.p=NULL;
2382 else
2383 {
2385 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2386 }
2387 if (Lp.p == NULL)
2388 {
2389 /*- the case that the s-poly is 0 -*/
2390 if (strat->pairtest==NULL) initPairtest(strat);
2391 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2392 strat->pairtest[strat->sl+1] = TRUE;
2393 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2394 /*
2395 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2396 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2397 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2398 *term of p divides the lcm(s,r)
2399 *(this canceling should be done here because
2400 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2401 *the first case is handled in chainCrit
2402 */
2403 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2404 }
2405 else
2406 {
2407 /*- the pair (S[i],p) enters B -*/
2408 Lp.p1 = strat->S[i];
2409 Lp.p2 = p;
2410
2411 pNext(Lp.p) = strat->tail; // !!!
2412
2413 if (atR >= 0)
2414 {
2415 Lp.i_r1 = strat->S_2_R[i];
2416 Lp.i_r2 = atR;
2417 }
2418 else
2419 {
2420 Lp.i_r1 = -1;
2421 Lp.i_r2 = -1;
2422 }
2423 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2424
2426 {
2429 && (Lp.p->coef!=NULL))
2430 nDelete(&(Lp.p->coef));
2431 }
2432
2433 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2434 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2435 }
2436}
2437
2438/*2
2439* put the pair (s[i],p) into the set B, ecart=ecart(p)
2440* NOTE: here we need to add the signature-based criteria
2441*/
2442
2443#ifdef DEBUGF5
2444static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2445#else
2446static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2447#endif
2448{
2449 assume(i<=strat->sl);
2450
2451 int l;
2452 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2453 // the corresponding signatures for criteria checks
2454 LObject Lp;
2455 poly pSigMult = p_Copy(pSig,currRing);
2456 poly sSigMult = p_Copy(strat->sig[i],currRing);
2457 unsigned long pSigMultNegSev,sSigMultNegSev;
2458 Lp.i_r = -1;
2459
2460#ifdef KDEBUG
2461 Lp.ecart=0; Lp.length=0;
2462#endif
2463 /*- computes the lcm(s[i],p) -*/
2464 Lp.lcm = pInit();
2465 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2466#ifndef HAVE_RATGRING
2467 pLcm(p,strat->S[i],Lp.lcm);
2468#elif defined(HAVE_RATGRING)
2469 if (rIsRatGRing(currRing))
2470 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2471 else
2472 pLcm(p,strat->S[i],Lp.lcm);
2473#endif
2474 pSetm(Lp.lcm);
2475
2476 // set coeffs of multipliers m1 and m2
2477 pSetCoeff0(m1, nInit(1));
2478 pSetCoeff0(m2, nInit(1));
2479//#if 1
2480#ifdef DEBUGF5
2481 PrintS("P1 ");
2482 pWrite(pHead(p));
2483 PrintS("P2 ");
2484 pWrite(pHead(strat->S[i]));
2485 PrintS("M1 ");
2486 pWrite(m1);
2487 PrintS("M2 ");
2488 pWrite(m2);
2489#endif
2490 // get multiplied signatures for testing
2491 pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2492 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2493 sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2494 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2495
2496//#if 1
2497#ifdef DEBUGF5
2498 PrintS("----------------\n");
2499 pWrite(pSigMult);
2500 pWrite(sSigMult);
2501 PrintS("----------------\n");
2502 Lp.checked = 0;
2503#endif
2504 int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2505//#if 1
2506#if DEBUGF5
2507 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2508 pWrite(pSigMult);
2509 pWrite(sSigMult);
2510#endif
2511 if(sigCmp==0)
2512 {
2513 // printf("!!!! EQUAL SIGS !!!!\n");
2514 // pSig = sSig, delete element due to Rewritten Criterion
2515 pDelete(&pSigMult);
2516 pDelete(&sSigMult);
2518 pLmDelete(Lp.lcm);
2519 else
2520 pLmFree(Lp.lcm);
2521 pDelete (&m1);
2522 pDelete (&m2);
2523 return;
2524 }
2525 // testing by syzCrit = F5 Criterion
2526 // testing by rewCrit1 = Rewritten Criterion
2527 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2528 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2529 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2530 || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2531 )
2532 {
2533 pDelete(&pSigMult);
2534 pDelete(&sSigMult);
2536 pLmDelete(Lp.lcm);
2537 else
2538 pLmFree(Lp.lcm);
2539 pDelete (&m1);
2540 pDelete (&m2);
2541 return;
2542 }
2543 /*
2544 *the pair (S[i],p) enters B if the spoly != 0
2545 */
2546 /*- compute the short s-polynomial -*/
2547 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2548 pNorm(p);
2549
2550 if ((strat->S[i]==NULL) || (p==NULL))
2551 return;
2552
2553 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2554 Lp.p=NULL;
2555 else
2556 {
2557 #ifdef HAVE_PLURAL
2558 if ( rIsPluralRing(currRing) )
2559 {
2560 if(pHasNotCF(p, strat->S[i]))
2561 {
2562 if(ncRingType(currRing) == nc_lie)
2563 {
2564 // generalized prod-crit for lie-type
2565 strat->cp++;
2566 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2567 }
2568 else
2569 if( ALLOW_PROD_CRIT(strat) )
2570 {
2571 // product criterion for homogeneous case in SCA
2572 strat->cp++;
2573 Lp.p = NULL;
2574 }
2575 else
2576 {
2577 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2578 nc_CreateShortSpoly(strat->S[i], p, currRing);
2579
2580 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2581 pNext(Lp.p) = strat->tail; // !!!
2582 }
2583 }
2584 else
2585 {
2586 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2587 nc_CreateShortSpoly(strat->S[i], p, currRing);
2588
2589 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2590 pNext(Lp.p) = strat->tail; // !!!
2591 }
2592 }
2593 else
2594 #endif
2595 {
2597 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2598 }
2599 }
2600 // store from which element this pair comes from for further tests
2601 //Lp.from = strat->sl+1;
2602 if(sigCmp==currRing->OrdSgn)
2603 {
2604 // pSig > sSig
2605 pDelete (&sSigMult);
2606 Lp.sig = pSigMult;
2607 Lp.sevSig = ~pSigMultNegSev;
2608 }
2609 else
2610 {
2611 // pSig < sSig
2612 pDelete (&pSigMult);
2613 Lp.sig = sSigMult;
2614 Lp.sevSig = ~sSigMultNegSev;
2615 }
2616 if (Lp.p == NULL)
2617 {
2618 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2619 int pos = posInSyz(strat, Lp.sig);
2620 enterSyz(Lp, strat, pos);
2621 }
2622 else
2623 {
2624 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2625 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2626 {
2627 pLmFree(Lp.lcm);
2628 pDelete(&Lp.sig);
2629 pDelete (&m1);
2630 pDelete (&m2);
2631 return;
2632 }
2633 // in any case Lp is checked up to the next strat->P which is added
2634 // to S right after this critical pair creation.
2635 // NOTE: this even holds if the 2nd generator gives the bigger signature
2636 // moreover, this improves rewCriterion,
2637 // i.e. strat->checked > strat->from if and only if the 2nd generator
2638 // gives the bigger signature.
2639 Lp.checked = strat->sl+1;
2640 // at this point it is clear that the pair will be added to L, since it has
2641 // passed all tests up to now
2642
2643 // adds buchberger's first criterion
2644 if (pLmCmp(m2,pHead(p)) == 0)
2645 {
2646 Lp.prod_crit = TRUE; // Product Criterion
2647#if 0
2648 int pos = posInSyz(strat, Lp.sig);
2649 enterSyz(Lp, strat, pos);
2650 pDelete (&m1);
2651 pDelete (&m2);
2652 return;
2653#endif
2654 }
2655 pDelete (&m1);
2656 pDelete (&m2);
2657#if DEBUGF5
2658 PrintS("SIGNATURE OF PAIR: ");
2659 pWrite(Lp.sig);
2660#endif
2661 /*- the pair (S[i],p) enters B -*/
2662 Lp.p1 = strat->S[i];
2663 Lp.p2 = p;
2664
2665 if (
2667// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2668 )
2669 {
2670 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2671 pNext(Lp.p) = strat->tail; // !!!
2672 }
2673
2674 if (atR >= 0)
2675 {
2676 Lp.i_r1 = strat->S_2_R[i];
2677 Lp.i_r2 = atR;
2678 }
2679 else
2680 {
2681 Lp.i_r1 = -1;
2682 Lp.i_r2 = -1;
2683 }
2684 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2685
2687 {
2690 && (Lp.p->coef!=NULL))
2691 nDelete(&(Lp.p->coef));
2692 }
2693
2694 l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2695 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2696 }
2697}
2698
2699
2700#ifdef DEBUGF5
2701static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2702#else
2703static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2704#endif
2705{
2706 #if ALL_VS_JUST
2707 //Over rings, if we construct the strong pair, do not add the spair
2709 {
2710 number s,t,d;
2711 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2712
2713 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2714 {
2715 nDelete(&d);
2716 nDelete(&s);
2717 nDelete(&t);
2718 return;
2719 }
2720 nDelete(&d);
2721 nDelete(&s);
2722 nDelete(&t);
2723 }
2724 #endif
2725 assume(i<=strat->sl);
2726 int l;
2727 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2728 // the corresponding signatures for criteria checks
2729 LObject Lp;
2730 poly pSigMult = p_Copy(pSig,currRing);
2731 poly sSigMult = p_Copy(strat->sig[i],currRing);
2732 unsigned long pSigMultNegSev,sSigMultNegSev;
2733 Lp.i_r = -1;
2734
2735#ifdef KDEBUG
2736 Lp.ecart=0; Lp.length=0;
2737#endif
2738 /*- computes the lcm(s[i],p) -*/
2739 Lp.lcm = pInit();
2740 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2741#ifndef HAVE_RATGRING
2742 pLcm(p,strat->S[i],Lp.lcm);
2743#elif defined(HAVE_RATGRING)
2744 if (rIsRatGRing(currRing))
2745 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2746 else
2747 pLcm(p,strat->S[i],Lp.lcm);
2748#endif
2749 pSetm(Lp.lcm);
2750
2751 // set coeffs of multipliers m1 and m2
2753 {
2754 number s = nCopy(pGetCoeff(strat->S[i]));
2755 number t = nCopy(pGetCoeff(p));
2756 pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2757 ksCheckCoeff(&s, &t, currRing->cf);
2758 pSetCoeff0(m1,s);
2759 pSetCoeff0(m2,t);
2760 }
2761 else
2762 {
2763 pSetCoeff0(m1, nInit(1));
2764 pSetCoeff0(m2, nInit(1));
2765 }
2766#ifdef DEBUGF5
2767 Print("P1 ");
2768 pWrite(pHead(p));
2769 Print("P2 ");
2770 pWrite(pHead(strat->S[i]));
2771 Print("M1 ");
2772 pWrite(m1);
2773 Print("M2 ");
2774 pWrite(m2);
2775#endif
2776
2777 // get multiplied signatures for testing
2778 pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2779 if(pSigMult != NULL)
2780 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2781 sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2782 if(sSigMult != NULL)
2783 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2784//#if 1
2785#ifdef DEBUGF5
2786 Print("----------------\n");
2787 pWrite(pSigMult);
2788 pWrite(sSigMult);
2789 Print("----------------\n");
2790 Lp.checked = 0;
2791#endif
2792 int sigCmp;
2793 if(pSigMult != NULL && sSigMult != NULL)
2794 {
2796 sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2797 else
2798 sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2799 }
2800 else
2801 {
2802 if(pSigMult == NULL)
2803 {
2804 if(sSigMult == NULL)
2805 sigCmp = 0;
2806 else
2807 sigCmp = -1;
2808 }
2809 else
2810 sigCmp = 1;
2811 }
2812//#if 1
2813#if DEBUGF5
2814 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2815 pWrite(pSigMult);
2816 pWrite(sSigMult);
2817#endif
2818 //In the ring case we already build the sig
2820 {
2821 if(sigCmp == 0)
2822 {
2823 //sigdrop since we loose the signature
2824 strat->sigdrop = TRUE;
2825 //Try to reduce it as far as we can via redRing
2827 {
2828 poly p1 = p_Copy(p,currRing);
2829 poly p2 = p_Copy(strat->S[i],currRing);
2830 p1 = p_Mult_mm(p1,m1,currRing);
2831 p2 = p_Mult_mm(p2,m2,currRing);
2832 Lp.p = p_Sub(p1,p2,currRing);
2833 if(Lp.p != NULL)
2834 Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2835 }
2836 int red_result = redRing(&Lp,strat);
2837 if(red_result == 0)
2838 {
2839 // Cancel the sigdrop
2840 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2841 strat->sigdrop = FALSE;
2842 return;
2843 }
2844 else
2845 {
2846 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2847 #if 1
2848 strat->enterS(Lp,0,strat,strat->tl);
2849 #endif
2850 return;
2851 }
2852 }
2853 if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2854 {
2855 //Same lm, have to subtract
2856 Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2857 }
2858 else
2859 {
2860 if(sigCmp == 1)
2861 {
2862 Lp.sig = pCopy(pSigMult);
2863 }
2864 if(sigCmp == -1)
2865 {
2866 Lp.sig = pNeg(pCopy(sSigMult));
2867 }
2868 }
2869 Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2870 }
2871
2872 #if 0
2873 if(sigCmp==0)
2874 {
2875 // printf("!!!! EQUAL SIGS !!!!\n");
2876 // pSig = sSig, delete element due to Rewritten Criterion
2877 pDelete(&pSigMult);
2878 pDelete(&sSigMult);
2880 pLmDelete(Lp.lcm);
2881 else
2882 pLmFree(Lp.lcm);
2883 pDelete (&m1);
2884 pDelete (&m2);
2885 return;
2886 }
2887 #endif
2888 // testing by syzCrit = F5 Criterion
2889 // testing by rewCrit1 = Rewritten Criterion
2890 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2891 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2892 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2893 // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2894 //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2895 )
2896 {
2897 pDelete(&pSigMult);
2898 pDelete(&sSigMult);
2900 pLmDelete(Lp.lcm);
2901 else
2902 pLmFree(Lp.lcm);
2903 pDelete (&m1);
2904 pDelete (&m2);
2905 return;
2906 }
2907 /*
2908 *the pair (S[i],p) enters B if the spoly != 0
2909 */
2910 /*- compute the short s-polynomial -*/
2911 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2912 pNorm(p);
2913
2914 if ((strat->S[i]==NULL) || (p==NULL))
2915 return;
2916
2917 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2918 Lp.p=NULL;
2919 else
2920 {
2921 //Build p
2923 {
2924 poly p1 = p_Copy(p,currRing);
2925 poly p2 = p_Copy(strat->S[i],currRing);
2926 p1 = p_Mult_mm(p1,m1,currRing);
2927 p2 = p_Mult_mm(p2,m2,currRing);
2928 Lp.p = p_Sub(p1,p2,currRing);
2929 if(Lp.p != NULL)
2930 Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2931 }
2932 else
2933 {
2934 #ifdef HAVE_PLURAL
2935 if ( rIsPluralRing(currRing) )
2936 {
2937 if(ncRingType(currRing) == nc_lie)
2938 {
2939 // generalized prod-crit for lie-type
2940 strat->cp++;
2941 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2942 }
2943 else
2944 if( ALLOW_PROD_CRIT(strat) )
2945 {
2946 // product criterion for homogeneous case in SCA
2947 strat->cp++;
2948 Lp.p = NULL;
2949 }
2950 else
2951 {
2952 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2953 nc_CreateShortSpoly(strat->S[i], p, currRing);
2954
2955 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2956 pNext(Lp.p) = strat->tail; // !!!
2957 }
2958 }
2959 else
2960 #endif
2961 {
2963 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2964 }
2965 }
2966 }
2967 // store from which element this pair comes from for further tests
2968 //Lp.from = strat->sl+1;
2970 {
2971 //Put the sig to be > 0
2972 if(!nGreaterZero(pGetCoeff(Lp.sig)))
2973 {
2974 Lp.sig = pNeg(Lp.sig);
2975 Lp.p = pNeg(Lp.p);
2976 }
2977 }
2978 else
2979 {
2980 if(sigCmp==currRing->OrdSgn)
2981 {
2982 // pSig > sSig
2983 pDelete (&sSigMult);
2984 Lp.sig = pSigMult;
2985 Lp.sevSig = ~pSigMultNegSev;
2986 }
2987 else
2988 {
2989 // pSig < sSig
2990 pDelete (&pSigMult);
2991 Lp.sig = sSigMult;
2992 Lp.sevSig = ~sSigMultNegSev;
2993 }
2994 }
2995 if (Lp.p == NULL)
2996 {
2997 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2998 int pos = posInSyz(strat, Lp.sig);
2999 enterSyz(Lp, strat, pos);
3000 }
3001 else
3002 {
3003 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
3004 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
3005 {
3006 pLmFree(Lp.lcm);
3007 pDelete(&Lp.sig);
3008 pDelete (&m1);
3009 pDelete (&m2);
3010 return;
3011 }
3012 // in any case Lp is checked up to the next strat->P which is added
3013 // to S right after this critical pair creation.
3014 // NOTE: this even holds if the 2nd generator gives the bigger signature
3015 // moreover, this improves rewCriterion,
3016 // i.e. strat->checked > strat->from if and only if the 2nd generator
3017 // gives the bigger signature.
3018 Lp.checked = strat->sl+1;
3019 // at this point it is clear that the pair will be added to L, since it has
3020 // passed all tests up to now
3021
3022 // adds buchberger's first criterion
3023 if (pLmCmp(m2,pHead(p)) == 0)
3024 {
3025 Lp.prod_crit = TRUE; // Product Criterion
3026#if 0
3027 int pos = posInSyz(strat, Lp.sig);
3028 enterSyz(Lp, strat, pos);
3029 pDelete (&m1);
3030 pDelete (&m2);
3031 return;
3032#endif
3033 }
3034 pDelete (&m1);
3035 pDelete (&m2);
3036#if DEBUGF5
3037 PrintS("SIGNATURE OF PAIR: ");
3038 pWrite(Lp.sig);
3039#endif
3040 /*- the pair (S[i],p) enters B -*/
3041 Lp.p1 = strat->S[i];
3042 Lp.p2 = p;
3043
3044 if (
3046// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3048 )
3049 {
3050 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3051 pNext(Lp.p) = strat->tail; // !!!
3052 }
3053
3054 if (atR >= 0)
3055 {
3056 Lp.i_r1 = strat->S_2_R[i];
3057 Lp.i_r2 = atR;
3058 }
3059 else
3060 {
3061 Lp.i_r1 = -1;
3062 Lp.i_r2 = -1;
3063 }
3064 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3065
3067 {
3070 && (Lp.p->coef!=NULL))
3071 nDelete(&(Lp.p->coef));
3072 }
3073 // Check for sigdrop
3074 if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3075 {
3076 strat->sigdrop = TRUE;
3077 // Completely reduce it
3078 int red_result = redRing(&Lp,strat);
3079 if(red_result == 0)
3080 {
3081 // Reduced to 0
3082 strat->sigdrop = FALSE;
3083 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3084 return;
3085 }
3086 else
3087 {
3088 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3089 // 0 - add just the original poly causing the sigdrop, 1 - add also this
3090 #if 1
3091 strat->enterS(Lp,0,strat, strat->tl+1);
3092 #endif
3093 return;
3094 }
3095 }
3096 l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3097 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3098 }
3099}
3100
3101/*2
3102* put the pair (s[i],p) into the set L, ecart=ecart(p)
3103* in the case that s forms a SB of (s)
3104*/
3105void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3106{
3107 //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3108 if(pHasNotCF(p,strat->S[i]))
3109 {
3110 //PrintS("prod-crit\n");
3111 if(ALLOW_PROD_CRIT(strat))
3112 {
3113 //PrintS("prod-crit\n");
3114 strat->cp++;
3115 return;
3116 }
3117 }
3118
3119 int l;
3120 LObject Lp;
3121 Lp.i_r = -1;
3122
3123 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3124 /*- compute the short s-polynomial -*/
3125
3126 #ifdef HAVE_PLURAL
3128 {
3129 Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3130 }
3131 else
3132 #endif
3133 Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3134
3135 if (Lp.p == NULL)
3136 {
3137 //PrintS("short spoly==NULL\n");
3138 pLmFree(Lp.lcm);
3139 }
3140 else
3141 {
3142 /*- the pair (S[i],p) enters L -*/
3143 Lp.p1 = strat->S[i];
3144 Lp.p2 = p;
3145 if (atR >= 0)
3146 {
3147 Lp.i_r1 = strat->S_2_R[i];
3148 Lp.i_r2 = atR;
3149 }
3150 else
3151 {
3152 Lp.i_r1 = -1;
3153 Lp.i_r2 = -1;
3154 }
3155 assume(pNext(Lp.p) == NULL);
3156 pNext(Lp.p) = strat->tail;
3157 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3159 {
3162 && (Lp.p->coef!=NULL))
3163 nDelete(&(Lp.p->coef));
3164 }
3165 l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3166 //Print("-> L[%d]\n",l);
3167 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3168 }
3169}
3170
3171/*2
3172* merge set B into L
3173*/
3175{
3176 int j=strat->Ll+strat->Bl+1;
3177 if (j>strat->Lmax)
3178 {
3179 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3180 enlargeL(&(strat->L),&(strat->Lmax),j);
3181 }
3182 j = strat->Ll;
3183 int i;
3184 for (i=strat->Bl; i>=0; i--)
3185 {
3186 j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3187 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3188 }
3189 strat->Bl = -1;
3190}
3191
3192/*2
3193* merge set B into L
3194*/
3196{
3197 int j=strat->Ll+strat->Bl+1;
3198 if (j>strat->Lmax)
3199 {
3200 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3201 enlargeL(&(strat->L),&(strat->Lmax),j);
3202 }
3203 j = strat->Ll;
3204 int i;
3205 for (i=strat->Bl; i>=0; i--)
3206 {
3207 j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3208 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3209 }
3210 strat->Bl = -1;
3211}
3212
3213/*2
3214*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3215*using the chain-criterion in B and L and enters B to L
3216*/
3217void chainCritNormal (poly p,int ecart,kStrategy strat)
3218{
3219 int i,j,l;
3220
3221 /*
3222 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3223 *In this case all elements in B such
3224 *that their lcm is divisible by the leading term of S[i] can be canceled
3225 */
3226 if (strat->pairtest!=NULL)
3227 {
3228#ifdef HAVE_SHIFTBBA
3229 // only difference is pLPDivisibleBy instead of pDivisibleBy
3230 if (rIsLPRing(currRing))
3231 {
3232 for (j=0; j<=strat->sl; j++)
3233 {
3234 if (strat->pairtest[j])
3235 {
3236 for (i=strat->Bl; i>=0; i--)
3237 {
3238 if (pLPDivisibleBy(strat->S[j],strat->B[i].lcm))
3239 {
3240 deleteInL(strat->B,&strat->Bl,i,strat);
3241 strat->c3++;
3242 }
3243 }
3244 }
3245 }
3246 }
3247 else
3248#endif
3249 {
3250 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3251 for (j=0; j<=strat->sl; j++)
3252 {
3253 if (strat->pairtest[j])
3254 {
3255 for (i=strat->Bl; i>=0; i--)
3256 {
3257 if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3258 {
3259 deleteInL(strat->B,&strat->Bl,i,strat);
3260 strat->c3++;
3261 }
3262 }
3263 }
3264 }
3265 }
3266 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3267 strat->pairtest=NULL;
3268 }
3269 if (strat->Gebauer || strat->fromT)
3270 {
3271 if (strat->sugarCrit)
3272 {
3273 /*
3274 *suppose L[j] == (s,r) and p/lcm(s,r)
3275 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3276 *and in case the sugar is o.k. then L[j] can be canceled
3277 */
3278 for (j=strat->Ll; j>=0; j--)
3279 {
3280 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3281 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3282 && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3283 {
3284 if (strat->L[j].p == strat->tail)
3285 {
3286 deleteInL(strat->L,&strat->Ll,j,strat);
3287 strat->c3++;
3288 }
3289 }
3290 }
3291 /*
3292 *this is GEBAUER-MOELLER:
3293 *in B all elements with the same lcm except the "best"
3294 *(i.e. the last one in B with this property) will be canceled
3295 */
3296 j = strat->Bl;
3297 loop /*cannot be changed into a for !!! */
3298 {
3299 if (j <= 0) break;
3300 i = j-1;
3301 loop
3302 {
3303 if (i < 0) break;
3304 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3305 {
3306 strat->c3++;
3307 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3308 {
3309 deleteInL(strat->B,&strat->Bl,i,strat);
3310 j--;
3311 }
3312 else
3313 {
3314 deleteInL(strat->B,&strat->Bl,j,strat);
3315 break;
3316 }
3317 }
3318 i--;
3319 }
3320 j--;
3321 }
3322 }
3323 else /*sugarCrit*/
3324 {
3325 /*
3326 *suppose L[j] == (s,r) and p/lcm(s,r)
3327 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3328 *and in case the sugar is o.k. then L[j] can be canceled
3329 */
3330 for (j=strat->Ll; j>=0; j--)
3331 {
3332 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3333 {
3334 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3335 {
3336 deleteInL(strat->L,&strat->Ll,j,strat);
3337 strat->c3++;
3338 }
3339 }
3340 }
3341 /*
3342 *this is GEBAUER-MOELLER:
3343 *in B all elements with the same lcm except the "best"
3344 *(i.e. the last one in B with this property) will be canceled
3345 */
3346 j = strat->Bl;
3347 loop /*cannot be changed into a for !!! */
3348 {
3349 if (j <= 0) break;
3350 for(i=j-1; i>=0; i--)
3351 {
3352 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3353 {
3354 strat->c3++;
3355 deleteInL(strat->B,&strat->Bl,i,strat);
3356 j--;
3357 }
3358 }
3359 j--;
3360 }
3361 }
3362 /*
3363 *the elements of B enter L
3364 */
3365 kMergeBintoL(strat);
3366 }
3367 else
3368 {
3369 for (j=strat->Ll; j>=0; j--)
3370 {
3371 #ifdef HAVE_SHIFTBBA
3372 if ((strat->L[j].p1!=NULL) &&
3373 pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3374 #else
3375 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3376 #endif
3377 {
3378 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3379 {
3380 deleteInL(strat->L,&strat->Ll,j,strat);
3381 strat->c3++;
3382 }
3383 }
3384 }
3385 /*
3386 *this is our MODIFICATION of GEBAUER-MOELLER:
3387 *First the elements of B enter L,
3388 *then we fix a lcm and the "best" element in L
3389 *(i.e the last in L with this lcm and of type (s,p))
3390 *and cancel all the other elements of type (r,p) with this lcm
3391 *except the case the element (s,r) has also the same lcm
3392 *and is on the worst position with respect to (s,p) and (r,p)
3393 */
3394 /*
3395 *B enters to L/their order with respect to B is permutated for elements
3396 *B[i].p with the same leading term
3397 */
3398 kMergeBintoL(strat);
3399 j = strat->Ll;
3400 loop /*cannot be changed into a for !!! */
3401 {
3402 if (j <= 0)
3403 {
3404 /*now L[0] cannot be canceled any more and the tail can be removed*/
3405 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3406 break;
3407 }
3408 if (strat->L[j].p2 == p)
3409 {
3410 i = j-1;
3411 loop
3412 {
3413 if (i < 0) break;
3414 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3415 {
3416 /*L[i] could be canceled but we search for a better one to cancel*/
3417 strat->c3++;
3418 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3419 && (pNext(strat->L[l].p) == strat->tail)
3420 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3421 && pDivisibleBy(p,strat->L[l].lcm))
3422 {
3423 /*
3424 *"NOT equal(...)" because in case of "equal" the element L[l]
3425 *is "older" and has to be from theoretical point of view behind
3426 *L[i], but we do not want to reorder L
3427 */
3428 strat->L[i].p2 = strat->tail;
3429 /*
3430 *L[l] will be canceled, we cannot cancel L[i] later on,
3431 *so we mark it with "tail"
3432 */
3433 deleteInL(strat->L,&strat->Ll,l,strat);
3434 i--;
3435 }
3436 else
3437 {
3438 deleteInL(strat->L,&strat->Ll,i,strat);
3439 }
3440 j--;
3441 }
3442 i--;
3443 }
3444 }
3445 else if (strat->L[j].p2 == strat->tail)
3446 {
3447 /*now L[j] cannot be canceled any more and the tail can be removed*/
3448 strat->L[j].p2 = p;
3449 }
3450 j--;
3451 }
3452 }
3453}
3454/*2
3455*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3456*without the chain-criterion in B and L and enters B to L
3457*/
3458void chainCritOpt_1 (poly,int,kStrategy strat)
3459{
3460 if (strat->pairtest!=NULL)
3461 {
3462 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3463 strat->pairtest=NULL;
3464 }
3465 /*
3466 *the elements of B enter L
3467 */
3468 kMergeBintoL(strat);
3469}
3470/*2
3471*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3472*using the chain-criterion in B and L and enters B to L
3473*/
3474void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3475{
3476 int i,j,l;
3477 kMergeBintoLSba(strat);
3478 j = strat->Ll;
3479 loop /*cannot be changed into a for !!! */
3480 {
3481 if (j <= 0)
3482 {
3483 /*now L[0] cannot be canceled any more and the tail can be removed*/
3484 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3485 break;
3486 }
3487 if (strat->L[j].p2 == p)
3488 {
3489 i = j-1;
3490 loop
3491 {
3492 if (i < 0) break;
3493 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3494 {
3495 /*L[i] could be canceled but we search for a better one to cancel*/
3496 strat->c3++;
3497 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3498 && (pNext(strat->L[l].p) == strat->tail)
3499 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3500 && pDivisibleBy(p,strat->L[l].lcm))
3501 {
3502 /*
3503 *"NOT equal(...)" because in case of "equal" the element L[l]
3504 *is "older" and has to be from theoretical point of view behind
3505 *L[i], but we do not want to reorder L
3506 */
3507 strat->L[i].p2 = strat->tail;
3508 /*
3509 *L[l] will be canceled, we cannot cancel L[i] later on,
3510 *so we mark it with "tail"
3511 */
3512 deleteInL(strat->L,&strat->Ll,l,strat);
3513 i--;
3514 }
3515 else
3516 {
3517 deleteInL(strat->L,&strat->Ll,i,strat);
3518 }
3519 j--;
3520 }
3521 i--;
3522 }
3523 }
3524 else if (strat->L[j].p2 == strat->tail)
3525 {
3526 /*now L[j] cannot be canceled any more and the tail can be removed*/
3527 strat->L[j].p2 = p;
3528 }
3529 j--;
3530 }
3531}
3532#ifdef HAVE_RATGRING
3533void chainCritPart (poly p,int ecart,kStrategy strat)
3534{
3535 int i,j,l;
3536
3537 /*
3538 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3539 *In this case all elements in B such
3540 *that their lcm is divisible by the leading term of S[i] can be canceled
3541 */
3542 if (strat->pairtest!=NULL)
3543 {
3544 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3545 for (j=0; j<=strat->sl; j++)
3546 {
3547 if (strat->pairtest[j])
3548 {
3549 for (i=strat->Bl; i>=0; i--)
3550 {
3551 if (_p_LmDivisibleByPart(strat->S[j],currRing,
3552 strat->B[i].lcm,currRing,
3553 currRing->real_var_start,currRing->real_var_end))
3554 {
3555 if(TEST_OPT_DEBUG)
3556 {
3557 Print("chain-crit-part: S[%d]=",j);
3558 p_wrp(strat->S[j],currRing);
3559 Print(" divide B[%d].lcm=",i);
3560 p_wrp(strat->B[i].lcm,currRing);
3561 PrintLn();
3562 }
3563 deleteInL(strat->B,&strat->Bl,i,strat);
3564 strat->c3++;
3565 }
3566 }
3567 }
3568 }
3569 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3570 strat->pairtest=NULL;
3571 }
3572 if (strat->Gebauer || strat->fromT)
3573 {
3574 if (strat->sugarCrit)
3575 {
3576 /*
3577 *suppose L[j] == (s,r) and p/lcm(s,r)
3578 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3579 *and in case the sugar is o.k. then L[j] can be canceled
3580 */
3581 for (j=strat->Ll; j>=0; j--)
3582 {
3583 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3584 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3585 && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3586 {
3587 if (strat->L[j].p == strat->tail)
3588 {
3589 if(TEST_OPT_DEBUG)
3590 {
3591 PrintS("chain-crit-part: pCompareChainPart p=");
3592 p_wrp(p,currRing);
3593 Print(" delete L[%d]",j);
3594 p_wrp(strat->L[j].lcm,currRing);
3595 PrintLn();
3596 }
3597 deleteInL(strat->L,&strat->Ll,j,strat);
3598 strat->c3++;
3599 }
3600 }
3601 }
3602 /*
3603 *this is GEBAUER-MOELLER:
3604 *in B all elements with the same lcm except the "best"
3605 *(i.e. the last one in B with this property) will be canceled
3606 */
3607 j = strat->Bl;
3608 loop /*cannot be changed into a for !!! */
3609 {
3610 if (j <= 0) break;
3611 i = j-1;
3612 loop
3613 {
3614 if (i < 0) break;
3615 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3616 {
3617 strat->c3++;
3618 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3619 {
3620 if(TEST_OPT_DEBUG)
3621 {
3622 Print("chain-crit-part: sugar B[%d].lcm=",j);
3623 p_wrp(strat->B[j].lcm,currRing);
3624 Print(" delete B[%d]",i);
3625 p_wrp(strat->B[i].lcm,currRing);
3626 PrintLn();
3627 }
3628 deleteInL(strat->B,&strat->Bl,i,strat);
3629 j--;
3630 }
3631 else
3632 {
3633 if(TEST_OPT_DEBUG)
3634 {
3635 Print("chain-crit-part: sugar B[%d].lcm=",i);
3636 p_wrp(strat->B[i].lcm,currRing);
3637 Print(" delete B[%d]",j);
3638 p_wrp(strat->B[j].lcm,currRing);
3639 PrintLn();
3640 }
3641 deleteInL(strat->B,&strat->Bl,j,strat);
3642 break;
3643 }
3644 }
3645 i--;
3646 }
3647 j--;
3648 }
3649 }
3650 else /*sugarCrit*/
3651 {
3652 /*
3653 *suppose L[j] == (s,r) and p/lcm(s,r)
3654 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3655 *and in case the sugar is o.k. then L[j] can be canceled
3656 */
3657 for (j=strat->Ll; j>=0; j--)
3658 {
3659 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3660 {
3661 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3662 {
3663 if(TEST_OPT_DEBUG)
3664 {
3665 PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3666 p_wrp(p,currRing);
3667 Print(" delete L[%d]",j);
3668 p_wrp(strat->L[j].lcm,currRing);
3669 PrintLn();
3670 }
3671 deleteInL(strat->L,&strat->Ll,j,strat);
3672 strat->c3++;
3673 }
3674 }
3675 }
3676 /*
3677 *this is GEBAUER-MOELLER:
3678 *in B all elements with the same lcm except the "best"
3679 *(i.e. the last one in B with this property) will be canceled
3680 */
3681 j = strat->Bl;
3682 loop /*cannot be changed into a for !!! */
3683 {
3684 if (j <= 0) break;
3685 for(i=j-1; i>=0; i--)
3686 {
3687 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3688 {
3689 if(TEST_OPT_DEBUG)
3690 {
3691 Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3692 p_wrp(strat->B[j].lcm,currRing);
3693 Print(" delete B[%d]\n",i);
3694 }
3695 strat->c3++;
3696 deleteInL(strat->B,&strat->Bl,i,strat);
3697 j--;
3698 }
3699 }
3700 j--;
3701 }
3702 }
3703 /*
3704 *the elements of B enter L
3705 */
3706 kMergeBintoL(strat);
3707 }
3708 else
3709 {
3710 for (j=strat->Ll; j>=0; j--)
3711 {
3712 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3713 {
3714 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3715 {
3716 if(TEST_OPT_DEBUG)
3717 {
3718 PrintS("chain-crit-part: pCompareChainPart p=");
3719 p_wrp(p,currRing);
3720 Print(" delete L[%d]",j);
3721 p_wrp(strat->L[j].lcm,currRing);
3722 PrintLn();
3723 }
3724 deleteInL(strat->L,&strat->Ll,j,strat);
3725 strat->c3++;
3726 }
3727 }
3728 }
3729 /*
3730 *this is our MODIFICATION of GEBAUER-MOELLER:
3731 *First the elements of B enter L,
3732 *then we fix a lcm and the "best" element in L
3733 *(i.e the last in L with this lcm and of type (s,p))
3734 *and cancel all the other elements of type (r,p) with this lcm
3735 *except the case the element (s,r) has also the same lcm
3736 *and is on the worst position with respect to (s,p) and (r,p)
3737 */
3738 /*
3739 *B enters to L/their order with respect to B is permutated for elements
3740 *B[i].p with the same leading term
3741 */
3742 kMergeBintoL(strat);
3743 j = strat->Ll;
3744 loop /*cannot be changed into a for !!! */
3745 {
3746 if (j <= 0)
3747 {
3748 /*now L[0] cannot be canceled any more and the tail can be removed*/
3749 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3750 break;
3751 }
3752 if (strat->L[j].p2 == p)
3753 {
3754 i = j-1;
3755 loop
3756 {
3757 if (i < 0) break;
3758 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3759 {
3760 /*L[i] could be canceled but we search for a better one to cancel*/
3761 strat->c3++;
3762 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3763 && (pNext(strat->L[l].p) == strat->tail)
3764 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3766 strat->L[l].lcm,currRing,
3767 currRing->real_var_start, currRing->real_var_end))
3768
3769 {
3770 /*
3771 *"NOT equal(...)" because in case of "equal" the element L[l]
3772 *is "older" and has to be from theoretical point of view behind
3773 *L[i], but we do not want to reorder L
3774 */
3775 strat->L[i].p2 = strat->tail;
3776 /*
3777 *L[l] will be canceled, we cannot cancel L[i] later on,
3778 *so we mark it with "tail"
3779 */
3780 if(TEST_OPT_DEBUG)
3781 {
3782 PrintS("chain-crit-part: divisible_by p=");
3783 p_wrp(p,currRing);
3784 Print(" delete L[%d]",l);
3785 p_wrp(strat->L[l].lcm,currRing);
3786 PrintLn();
3787 }
3788 deleteInL(strat->L,&strat->Ll,l,strat);
3789 i--;
3790 }
3791 else
3792 {
3793 if(TEST_OPT_DEBUG)
3794 {
3795 PrintS("chain-crit-part: divisible_by(2) p=");
3796 p_wrp(p,currRing);
3797 Print(" delete L[%d]",i);
3798 p_wrp(strat->L[i].lcm,currRing);
3799 PrintLn();
3800 }
3801 deleteInL(strat->L,&strat->Ll,i,strat);
3802 }
3803 j--;
3804 }
3805 i--;
3806 }
3807 }
3808 else if (strat->L[j].p2 == strat->tail)
3809 {
3810 /*now L[j] cannot be canceled any more and the tail can be removed*/
3811 strat->L[j].p2 = p;
3812 }
3813 j--;
3814 }
3815 }
3816}
3817#endif
3818
3819/*2
3820*(s[0],h),...,(s[k],h) will be put to the pairset L
3821*/
3822void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR/* = -1*/)
3823{
3824
3825 if ((strat->syzComp==0)
3826 || (pGetComp(h)<=strat->syzComp))
3827 {
3828 int j;
3829 BOOLEAN new_pair=FALSE;
3830
3831 if (pGetComp(h)==0)
3832 {
3833 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3834 if ((isFromQ)&&(strat->fromQ!=NULL))
3835 {
3836 for (j=0; j<=k; j++)
3837 {
3838 if (!strat->fromQ[j])
3839 {
3840 new_pair=TRUE;
3841 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3842 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3843 }
3844 }
3845 }
3846 else
3847 {
3848 new_pair=TRUE;
3849 for (j=0; j<=k; j++)
3850 {
3851 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3852 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3853 }
3854 }
3855 }
3856 else
3857 {
3858 for (j=0; j<=k; j++)
3859 {
3860 if ((pGetComp(h)==pGetComp(strat->S[j]))
3861 || (pGetComp(strat->S[j])==0))
3862 {
3863 new_pair=TRUE;
3864 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3865 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3866 }
3867 }
3868 }
3869 if (new_pair)
3870 {
3871 #ifdef HAVE_RATGRING
3872 if (currRing->real_var_start>0)
3873 chainCritPart(h,ecart,strat);
3874 else
3875 #endif
3876 strat->chainCrit(h,ecart,strat);
3877 }
3878 kMergeBintoL(strat);
3879 }
3880}
3881
3882/*2
3883*(s[0],h),...,(s[k],h) will be put to the pairset L
3884*using signatures <= only for signature-based standard basis algorithms
3885*/
3886
3887void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3888{
3889
3890 if ((strat->syzComp==0)
3891 || (pGetComp(h)<=strat->syzComp))
3892 {
3893 int j;
3894 BOOLEAN new_pair=FALSE;
3895
3896 if (pGetComp(h)==0)
3897 {
3898 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3899 if ((isFromQ)&&(strat->fromQ!=NULL))
3900 {
3901 for (j=0; j<=k; j++)
3902 {
3903 if (!strat->fromQ[j])
3904 {
3905 new_pair=TRUE;
3906 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3907 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3908 }
3909 }
3910 }
3911 else
3912 {
3913 new_pair=TRUE;
3914 for (j=0; j<=k; j++)
3915 {
3916 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3917 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3918 }
3919 }
3920 }
3921 else
3922 {
3923 for (j=0; j<=k; j++)
3924 {
3925 if ((pGetComp(h)==pGetComp(strat->S[j]))
3926 || (pGetComp(strat->S[j])==0))
3927 {
3928 new_pair=TRUE;
3929 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3930 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3931 }
3932 }
3933 }
3934
3935 if (new_pair)
3936 {
3937#ifdef HAVE_RATGRING
3938 if (currRing->real_var_start>0)
3939 chainCritPart(h,ecart,strat);
3940 else
3941#endif
3942 strat->chainCrit(h,ecart,strat);
3943 }
3944 }
3945}
3946
3947void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3948{
3949
3950 if ((strat->syzComp==0)
3951 || (pGetComp(h)<=strat->syzComp))
3952 {
3953 int j;
3954
3955 if (pGetComp(h)==0)
3956 {
3957 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3958 if ((isFromQ)&&(strat->fromQ!=NULL))
3959 {
3960 for (j=0; j<=k && !strat->sigdrop; j++)
3961 {
3962 if (!strat->fromQ[j])
3963 {
3964 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3965 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3966 }
3967 }
3968 }
3969 else
3970 {
3971 for (j=0; j<=k && !strat->sigdrop; j++)
3972 {
3973 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3974 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3975 }
3976 }
3977 }
3978 else
3979 {
3980 for (j=0; j<=k && !strat->sigdrop; j++)
3981 {
3982 if ((pGetComp(h)==pGetComp(strat->S[j]))
3983 || (pGetComp(strat->S[j])==0))
3984 {
3985 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3986 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3987 }
3988 }
3989 }
3990
3991#if 0
3992 if (new_pair)
3993 {
3994#ifdef HAVE_RATGRING
3995 if (currRing->real_var_start>0)
3996 chainCritPart(h,ecart,strat);
3997 else
3998#endif
3999 strat->chainCrit(h,ecart,strat);
4000 }
4001#endif
4002 }
4003}
4004#ifdef HAVE_RINGS
4005/*2
4006*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
4007*using the chain-criterion in B and L and enters B to L
4008*/
4009void chainCritRing (poly p,int, kStrategy strat)
4010{
4011 int i,j,l;
4012 /*
4013 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4014 *In this case all elements in B such
4015 *that their lcm is divisible by the leading term of S[i] can be canceled
4016 */
4017 if (strat->pairtest!=NULL)
4018 {
4019 {
4020 /*- i.e. there is an i with pairtest[i]==TRUE -*/
4021 for (j=0; j<=strat->sl; j++)
4022 {
4023 if (strat->pairtest[j])
4024 {
4025 for (i=strat->Bl; i>=0; i--)
4026 {
4027 if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4028 {
4029#ifdef KDEBUG
4030 if (TEST_OPT_DEBUG)
4031 {
4032 PrintS("--- chain criterion func chainCritRing type 1\n");
4033 PrintS("strat->S[j]:");
4034 wrp(strat->S[j]);
4035 PrintS(" strat->B[i].lcm:");
4036 wrp(strat->B[i].lcm);PrintLn();
4037 pWrite(strat->B[i].p);
4038 pWrite(strat->B[i].p1);
4039 pWrite(strat->B[i].p2);
4040 wrp(strat->B[i].lcm);
4041 PrintLn();
4042 }
4043#endif
4044 deleteInL(strat->B,&strat->Bl,i,strat);
4045 strat->c3++;
4046 }
4047 }
4048 }
4049 }
4050 }
4051 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4052 strat->pairtest=NULL;
4053 }
4054 assume(!(strat->Gebauer || strat->fromT));
4055 for (j=strat->Ll; j>=0; j--)
4056 {
4057 if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4058 {
4059 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4060 {
4061 if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4062 {
4063 deleteInL(strat->L,&strat->Ll,j,strat);
4064 strat->c3++;
4065#ifdef KDEBUG
4066 if (TEST_OPT_DEBUG)
4067 {
4068 PrintS("--- chain criterion func chainCritRing type 2\n");
4069 PrintS("strat->L[j].p:");
4070 wrp(strat->L[j].p);
4071 PrintS(" p:");
4072 wrp(p);
4073 PrintLn();
4074 }
4075#endif
4076 }
4077 }
4078 }
4079 }
4080 /*
4081 *this is our MODIFICATION of GEBAUER-MOELLER:
4082 *First the elements of B enter L,
4083 *then we fix a lcm and the "best" element in L
4084 *(i.e the last in L with this lcm and of type (s,p))
4085 *and cancel all the other elements of type (r,p) with this lcm
4086 *except the case the element (s,r) has also the same lcm
4087 *and is on the worst position with respect to (s,p) and (r,p)
4088 */
4089 /*
4090 *B enters to L/their order with respect to B is permutated for elements
4091 *B[i].p with the same leading term
4092 */
4093 kMergeBintoL(strat);
4094 j = strat->Ll;
4095 loop /*cannot be changed into a for !!! */
4096 {
4097 if (j <= 0)
4098 {
4099 /*now L[0] cannot be canceled any more and the tail can be removed*/
4100 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4101 break;
4102 }
4103 if (strat->L[j].p2 == p) // Was the element added from B?
4104 {
4105 i = j-1;
4106 loop
4107 {
4108 if (i < 0) break;
4109 // Element is from B and has the same lcm as L[j]
4110 if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4111 && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4112 {
4113 /*L[i] could be canceled but we search for a better one to cancel*/
4114 strat->c3++;
4115#ifdef KDEBUG
4116 if (TEST_OPT_DEBUG)
4117 {
4118 PrintS("--- chain criterion func chainCritRing type 3\n");
4119 PrintS("strat->L[j].lcm:");
4120 wrp(strat->L[j].lcm);
4121 PrintS(" strat->L[i].lcm:");
4122 wrp(strat->L[i].lcm);
4123 PrintLn();
4124 }
4125#endif
4126 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4127 && (pNext(strat->L[l].p) == strat->tail)
4128 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4129 && pDivisibleBy(p,strat->L[l].lcm))
4130 {
4131 /*
4132 *"NOT equal(...)" because in case of "equal" the element L[l]
4133 *is "older" and has to be from theoretical point of view behind
4134 *L[i], but we do not want to reorder L
4135 */
4136 strat->L[i].p2 = strat->tail;
4137 /*
4138 *L[l] will be canceled, we cannot cancel L[i] later on,
4139 *so we mark it with "tail"
4140 */
4141 deleteInL(strat->L,&strat->Ll,l,strat);
4142 i--;
4143 }
4144 else
4145 {
4146 deleteInL(strat->L,&strat->Ll,i,strat);
4147 }
4148 j--;
4149 }
4150 i--;
4151 }
4152 }
4153 else if (strat->L[j].p2 == strat->tail)
4154 {
4155 /*now L[j] cannot be canceled any more and the tail can be removed*/
4156 strat->L[j].p2 = p;
4157 }
4158 j--;
4159 }
4160}
4161#endif
4162
4163#ifdef HAVE_RINGS
4164/*2
4165*(s[0],h),...,(s[k],h) will be put to the pairset L
4166*/
4167void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4168{
4169 if (!nIsOne(pGetCoeff(h)))
4170 {
4171 int j;
4172 BOOLEAN new_pair=FALSE;
4173
4174 if (pGetComp(h)==0)
4175 {
4176 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4177 if ((isFromQ)&&(strat->fromQ!=NULL))
4178 {
4179 for (j=0; j<=k; j++)
4180 {
4181 if (!strat->fromQ[j])
4182 {
4183 new_pair=TRUE;
4184 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4185 }
4186 }
4187 }
4188 else
4189 {
4190 new_pair=TRUE;
4191 for (j=0; j<=k; j++)
4192 {
4193 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4194 }
4195 }
4196 }
4197 else
4198 {
4199 for (j=0; j<=k; j++)
4200 {
4201 if ((pGetComp(h)==pGetComp(strat->S[j]))
4202 || (pGetComp(strat->S[j])==0))
4203 {
4204 new_pair=TRUE;
4205 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4206 }
4207 }
4208 }
4209 if (new_pair)
4210 {
4211 #ifdef HAVE_RATGRING
4212 if (currRing->real_var_start>0)
4213 chainCritPart(h,ecart,strat);
4214 else
4215 #endif
4216 strat->chainCrit(h,ecart,strat);
4217 }
4218 kMergeBintoL(strat);
4219 }
4220}
4221
4222static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4223{
4224 const int iCompH = pGetComp(h);
4225 if (!nIsOne(pGetCoeff(h)))
4226 {
4227 int j;
4228
4229 for (j=0; j<=k && !strat->sigdrop; j++)
4230 {
4231 // Print("j:%d, Ll:%d\n",j,strat->Ll);
4232// if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4233// ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4234 if (((iCompH == pGetComp(strat->S[j]))
4235 || (0 == pGetComp(strat->S[j])))
4236 && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4237 {
4238 enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4239 }
4240 }
4241 }
4242}
4243#endif
4244
4245#ifdef HAVE_RINGS
4246/*2
4247* Generates spoly(0, h) if applicable. Assumes ring has zero divisors
4248*/
4250{
4251 if (nIsOne(pGetCoeff(h))) return;
4252 number gcd;
4253 number zero=n_Init(0,currRing->cf);
4254 bool go = false;
4255 if (n_DivBy(zero, pGetCoeff(h), currRing->cf))
4256 {
4257 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4258 go = true;
4259 }
4260 else
4261 gcd = n_Gcd(zero, pGetCoeff(h), strat->tailRing->cf);
4262 if (go || !nIsOne(gcd))
4263 {
4264 poly p = h->next;
4265 if (!go)
4266 {
4267 number tmp = gcd;
4268 gcd = n_Ann(gcd,currRing->cf);
4269 nDelete(&tmp);
4270 }
4271 p_Test(p,strat->tailRing);
4272 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4273
4274 if (p != NULL)
4275 {
4276 if (TEST_OPT_PROT)
4277 {
4278 PrintS("Z");
4279 }
4280#ifdef KDEBUG
4281 if (TEST_OPT_DEBUG)
4282 {
4283 PrintS("--- create zero spoly: ");
4284 p_wrp(h,currRing,strat->tailRing);
4285 PrintS(" ---> ");
4286 }
4287#endif
4288 poly tmp = pInit();
4289 pSetCoeff0(tmp, pGetCoeff(p));
4290 for (int i = 1; i <= rVar(currRing); i++)
4291 {
4292 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4293 }
4295 {
4296 p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4297 }
4298 p_Setm(tmp, currRing);
4299 p = p_LmFreeAndNext(p, strat->tailRing);
4300 pNext(tmp) = p;
4301 LObject Lp;
4302 Lp.Init();
4303 Lp.p = tmp;
4304 Lp.tailRing = strat->tailRing;
4305 int posx;
4306 if (Lp.p!=NULL)
4307 {
4308 strat->initEcart(&Lp);
4309 if (strat->Ll==-1)
4310 posx =0;
4311 else
4312 posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4313 Lp.sev = pGetShortExpVector(Lp.p);
4314 if (strat->tailRing != currRing)
4315 {
4316 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4317 }
4318#ifdef KDEBUG
4319 if (TEST_OPT_DEBUG)
4320 {
4321 p_wrp(tmp,currRing,strat->tailRing);
4322 PrintLn();
4323 }
4324#endif
4325 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4326 }
4327 }
4328 }
4329 nDelete(&zero);
4330 nDelete(&gcd);
4331}
4332
4333void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
4334{
4335 if (nIsOne(pGetCoeff(h))) return;
4336 number gcd;
4337 number zero=n_Init(0,currRing->cf);
4338 bool go = false;
4339 if (n_DivBy(zero, pGetCoeff(h), currRing->cf))
4340 {
4341 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4342 go = true;
4343 }
4344 else
4345 gcd = n_Gcd(zero, pGetCoeff(h), strat->tailRing->cf);
4346 if (go || !nIsOne(gcd))
4347 {
4348 poly p = h->next;
4349 if (!go)
4350 {
4351 number tmp = gcd;
4352 gcd = n_Ann(gcd,currRing->cf);
4353 nDelete(&tmp);
4354 }
4355 p_Test(p,strat->tailRing);
4356 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4357
4358 if (p != NULL)
4359 {
4360 if (TEST_OPT_PROT)
4361 {
4362 PrintS("Z");
4363 }
4364#ifdef KDEBUG
4365 if (TEST_OPT_DEBUG)
4366 {
4367 PrintS("--- create zero spoly: ");
4368 p_wrp(h,currRing,strat->tailRing);
4369 PrintS(" ---> ");
4370 }
4371#endif
4372 poly tmp = pInit();
4373 pSetCoeff0(tmp, pGetCoeff(p));
4374 for (int i = 1; i <= rVar(currRing); i++)
4375 {
4376 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4377 }
4379 {
4380 p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4381 }
4382 p_Setm(tmp, currRing);
4383 p = p_LmFreeAndNext(p, strat->tailRing);
4384 pNext(tmp) = p;
4385 LObject Lp;
4386 Lp.Init();
4387 Lp.p = tmp;
4388 //printf("\nOld\n");pWrite(h);pWrite(hSig);
4389 #if EXT_POLY_NEW
4390 Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4391 if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4392 {
4393 strat->sigdrop = TRUE;
4394 //Try to reduce it as far as we can via redRing
4395 int red_result = redRing(&Lp,strat);
4396 if(red_result == 0)
4397 {
4398 // Cancel the sigdrop
4399 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4400 strat->sigdrop = FALSE;
4401 }
4402 else
4403 {
4404 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4405 #if 1
4406 strat->enterS(Lp,0,strat,strat->tl);
4407 #endif
4408 }
4409 nDelete(&zero);
4410 nDelete(&gcd);
4411 return;
4412 }
4413 #else
4414 Lp.sig = pOne();
4415 if(strat->Ll >= 0)
4416 p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4417 else
4418 p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4419 #endif
4420 Lp.tailRing = strat->tailRing;
4421 int posx;
4422 if (Lp.p!=NULL)
4423 {
4424 strat->initEcart(&Lp);
4425 if (strat->Ll==-1)
4426 posx =0;
4427 else
4428 posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4429 Lp.sev = pGetShortExpVector(Lp.p);
4430 if (strat->tailRing != currRing)
4431 {
4432 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4433 }
4434#ifdef KDEBUG
4435 if (TEST_OPT_DEBUG)
4436 {
4437 p_wrp(tmp,currRing,strat->tailRing);
4438 PrintLn();
4439 }
4440#endif
4441 //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4442 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4443 }
4444 }
4445 }
4446 nDelete(&gcd);
4447 nDelete(&zero);
4448}
4449#endif
4450
4451#ifdef HAVE_RINGS
4452void clearSbatch (poly h,int k,int pos,kStrategy strat)
4453{
4454 int j = pos;
4455 if ( (!strat->fromT)
4456 && ((strat->syzComp==0)
4457 ||(pGetComp(h)<=strat->syzComp)
4458 ))
4459 {
4460 // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4461 unsigned long h_sev = pGetShortExpVector(h);
4462 loop
4463 {
4464 if (j > k) break;
4465 clearS(h,h_sev, &j,&k,strat);
4466 j++;
4467 }
4468 // Print("end clearS sl=%d\n",strat->sl);
4469 }
4470}
4471#endif
4472
4473#ifdef HAVE_RINGS
4474/*2
4475* Generates a sufficient set of spolys (maybe just a finite generating
4476* set of the syzygys)
4477*/
4478void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4479{
4481#if HAVE_SHIFTBBA
4482 assume(!rIsLPRing(currRing)); /* LP should use enterpairsShift */
4483#endif
4484 // enter also zero divisor * poly, if this is non zero and of smaller degree
4486 initenterstrongPairs(h, k, ecart, 0, strat, atR);
4487 initenterpairs(h, k, ecart, 0, strat, atR);
4488 clearSbatch(h, k, pos, strat);
4489}
4490
4491void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4492{
4494 // enter also zero divisor * poly, if this is non zero and of smaller degree
4495 if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4496 if(strat->sigdrop) return;
4497 initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4498 if(strat->sigdrop) return;
4499 initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4500 if(strat->sigdrop) return;
4501 clearSbatch(h, k, pos, strat);
4502}
4503#endif
4504
4505/*2
4506*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4507*superfluous elements in S will be deleted
4508*/
4509void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4510{
4511 int j=pos;
4512
4514 initenterpairs(h,k,ecart,0,strat, atR);
4515 if ( (!strat->fromT)
4516 && ((strat->syzComp==0)
4517 ||(pGetComp(h)<=strat->syzComp)))
4518 {
4519 unsigned long h_sev = pGetShortExpVector(h);
4520 loop
4521 {
4522 if (j > k) break;
4523 clearS(h,h_sev, &j,&k,strat);
4524 j++;
4525 }
4526 }
4527}
4528
4529/*2
4530*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4531*superfluous elements in S will be deleted
4532*this is a special variant of signature-based algorithms including the
4533*signatures for criteria checks
4534*/
4535void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4536{
4537 int j=pos;
4539 initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4540 if ( (!strat->fromT)
4541 && ((strat->syzComp==0)
4542 ||(pGetComp(h)<=strat->syzComp)))
4543 {
4544 unsigned long h_sev = pGetShortExpVector(h);
4545 loop
4546 {
4547 if (j > k) break;
4548 clearS(h,h_sev, &j,&k,strat);
4549 j++;
4550 }
4551 }
4552}
4553
4554/*2
4555*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4556*superfluous elements in S will be deleted
4557*/
4558void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4559{
4560 int j;
4561 const int iCompH = pGetComp(h);
4562
4564 {
4565 for (j=0; j<=k; j++)
4566 {
4567 const int iCompSj = pGetComp(strat->S[j]);
4568 if ((iCompH==iCompSj)
4569 //|| (0==iCompH) // can only happen,if iCompSj==0
4570 || (0==iCompSj))
4571 {
4572 enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4573 }
4574 }
4575 kMergeBintoL(strat);
4576 }
4577 else
4578 {
4579 for (j=0; j<=k; j++)
4580 {
4581 const int iCompSj = pGetComp(strat->S[j]);
4582 if ((iCompH==iCompSj)
4583 //|| (0==iCompH) // can only happen,if iCompSj==0
4584 || (0==iCompSj))
4585 {
4586 enterOnePairSpecial(j,h,ecart,strat, atR);
4587 }
4588 }
4589 }
4590
4591 if (strat->noClearS) return;
4592
4593// #ifdef HAVE_PLURAL
4594/*
4595 if (rIsPluralRing(currRing))
4596 {
4597 j=pos;
4598 loop
4599 {
4600 if (j > k) break;
4601
4602 if (pLmDivisibleBy(h, strat->S[j]))
4603 {
4604 deleteInS(j, strat);
4605 j--;
4606 k--;
4607 }
4608
4609 j++;
4610 }
4611 }
4612 else
4613*/
4614// #endif // ??? Why was the following cancellation disabled for non-commutative rings?
4615 {
4616 j=pos;
4617 loop
4618 {
4619 unsigned long h_sev = pGetShortExpVector(h);
4620 if (j > k) break;
4621 clearS(h,h_sev,&j,&k,strat);
4622 j++;
4623 }
4624 }
4625}
4626
4627/*2
4628*reorders s with respect to posInS,
4629*suc is the first changed index or zero
4630*/
4631
4632void reorderS (int* suc,kStrategy strat)
4633{
4634 int i,j,at,ecart, s2r;
4635 int fq=0;
4636 unsigned long sev;
4637 poly p;
4638 int new_suc=strat->sl+1;
4639 i= *suc;
4640 if (i<0) i=0;
4641
4642 for (; i<=strat->sl; i++)
4643 {
4644 at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4645 if (at != i)
4646 {
4647 if (new_suc > at) new_suc = at;
4648 p = strat->S[i];
4649 ecart = strat->ecartS[i];
4650 sev = strat->sevS[i];
4651 s2r = strat->S_2_R[i];
4652 if (strat->fromQ!=NULL) fq=strat->fromQ[i];
4653 for (j=i; j>=at+1; j--)
4654 {
4655 strat->S[j] = strat->S[j-1];
4656 strat->ecartS[j] = strat->ecartS[j-1];
4657 strat->sevS[j] = strat->sevS[j-1];
4658 strat->S_2_R[j] = strat->S_2_R[j-1];
4659 }
4660 strat->S[at] = p;
4661 strat->ecartS[at] = ecart;
4662 strat->sevS[at] = sev;
4663 strat->S_2_R[at] = s2r;
4664 if (strat->fromQ!=NULL)
4665 {
4666 for (j=i; j>=at+1; j--)
4667 {
4668 strat->fromQ[j] = strat->fromQ[j-1];
4669 }
4670 strat->fromQ[at]=fq;
4671 }
4672 }
4673 }
4674 if (new_suc <= strat->sl) *suc=new_suc;
4675 else *suc=-1;
4676}
4677
4678
4679/*2
4680*looks up the position of p in set
4681*set[0] is the smallest with respect to the ordering-procedure deg/pComp
4682* Assumption: posInS only depends on the leading term
4683* otherwise, bba has to be changed
4684*/
4685int posInS (const kStrategy strat, const int length,const poly p,
4686 const int ecart_p)
4687{
4688 if(length==-1) return 0;
4689 polyset set=strat->S;
4690 int i;
4691 int an = 0;
4692 int en = length;
4693 int cmp_int = currRing->OrdSgn;
4695#ifdef HAVE_PLURAL
4696 && (currRing->real_var_start==0)
4697#endif
4698#if 0
4699 || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
4700#endif
4701 )
4702 {
4703 int o=p_Deg(p,currRing);
4704 int oo=p_Deg(set[length],currRing);
4705
4706 if ((oo<o)
4707 || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
4708 return length+1;
4709
4710 loop
4711 {
4712 if (an >= en-1)
4713 {
4714 if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
4715 {
4716 return an;
4717 }
4718 return en;
4719 }
4720 i=(an+en) / 2;
4721 if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
4722 else an=i;
4723 }
4724 }
4725 else
4726 {
4728 {
4729 if (pLmCmp(set[length],p)== -cmp_int)
4730 return length+1;
4731 int cmp;
4732 loop
4733 {
4734 if (an >= en-1)
4735 {
4736 cmp = pLmCmp(set[an],p);
4737 if (cmp == cmp_int) return an;
4738 if (cmp == -cmp_int) return en;
4739 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
4740 return an;
4741 }
4742 i = (an+en) / 2;
4743 cmp = pLmCmp(set[i],p);
4744 if (cmp == cmp_int) en = i;
4745 else if (cmp == -cmp_int) an = i;
4746 else
4747 {
4748 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
4749 else en = i;
4750 }
4751 }
4752 }
4753 else
4754 if (pLmCmp(set[length],p)== -cmp_int)
4755 return length+1;
4756
4757 loop
4758 {
4759 if (an >= en-1)
4760 {
4761 if (pLmCmp(set[an],p) == cmp_int) return an;
4762 if (pLmCmp(set[an],p) == -cmp_int) return en;
4763 if ((cmp_int!=1)
4764 && ((strat->ecartS[an])>ecart_p))
4765 return an;
4766 return en;
4767 }
4768 i=(an+en) / 2;
4769 if (pLmCmp(set[i],p) == cmp_int) en=i;
4770 else if (pLmCmp(set[i],p) == -cmp_int) an=i;
4771 else
4772 {
4773 if ((cmp_int!=1)
4774 &&((strat->ecartS[i])<ecart_p))
4775 en=i;
4776 else
4777 an=i;
4778 }
4779 }
4780 }
4781}
4782
4783
4784// sorts by degree and pLtCmp
4785// but puts pure monomials at the beginning
4786int posInSMonFirst (const kStrategy strat, const int length,const poly p)
4787{
4788 if (length<0) return 0;
4789 polyset set=strat->S;
4790 if(pNext(p) == NULL)
4791 {
4792 int mon = 0;
4793 for(int i = 0;i<=length;i++)
4794 {
4795 if(set[i] != NULL && pNext(set[i]) == NULL)
4796 mon++;
4797 }
4798 int o = p_Deg(p,currRing);
4799 int op = p_Deg(set[mon],currRing);
4800
4801 if ((op < o)
4802 || ((op == o) && (pLtCmp(set[mon],p) == -1)))
4803 return length+1;
4804 int i;
4805 int an = 0;
4806 int en= mon;
4807 loop
4808 {
4809 if (an >= en-1)
4810 {
4811 op = p_Deg(set[an],currRing);
4812 if ((op < o)
4813 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4814 return en;
4815 return an;
4816 }
4817 i=(an+en) / 2;
4818 op = p_Deg(set[i],currRing);
4819 if ((op < o)
4820 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4821 an=i;
4822 else
4823 en=i;
4824 }
4825 }
4826 else /*if(pNext(p) != NULL)*/
4827 {
4828 int o = p_Deg(p,currRing);
4829 int op = p_Deg(set[length],currRing);
4830
4831 if ((op < o)
4832 || ((op == o) && (pLtCmp(set[length],p) == -1)))
4833 return length+1;
4834 int i;
4835 int an = 0;
4836 for(i=0;i<=length;i++)
4837 if(set[i] != NULL && pNext(set[i]) == NULL)
4838 an++;
4839 int en= length;
4840 loop
4841 {
4842 if (an >= en-1)
4843 {
4844 op = p_Deg(set[an],currRing);
4845 if ((op < o)
4846 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4847 return en;
4848 return an;
4849 }
4850 i=(an+en) / 2;
4851 op = p_Deg(set[i],currRing);
4852 if ((op < o)
4853 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4854 an=i;
4855 else
4856 en=i;
4857 }
4858 }
4859}
4860
4861// sorts by degree and pLtCmp in the block between start,end;
4862// but puts pure monomials at the beginning
4863int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
4864{
4865 if(end < 0 || end >= IDELEMS(F))
4866 end = IDELEMS(F);
4867 if (end<0) return 0;
4868 if(pNext(p) == NULL) return start;
4869 polyset set=F->m;
4870 int o = p_Deg(p,currRing);
4871 int op;
4872 int i;
4873 int an = start;
4874 for(i=start;i<end;i++)
4875 if(set[i] != NULL && pNext(set[i]) == NULL)
4876 an++;
4877 if(an == end-1)
4878 return end;
4879 int en= end;
4880 loop
4881 {
4882 if(an>=en)
4883 return en;
4884 if (an == en-1)
4885 {
4886 op = p_Deg(set[an],currRing);
4887 if ((op < o)
4888 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4889 return en;
4890 return an;
4891 }
4892 i=(an+en) / 2;
4893 op = p_Deg(set[i],currRing);
4894 if ((op < o)
4895 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4896 an=i;
4897 else
4898 en=i;
4899 }
4900}
4901
4902
4903/*2
4904* looks up the position of p in set
4905* the position is the last one
4906*/
4907int posInT0 (const TSet,const int length,LObject &)
4908{
4909 return (length+1);
4910}
4911
4912
4913/*2
4914* looks up the position of p in T
4915* set[0] is the smallest with respect to the ordering-procedure
4916* pComp
4917*/
4918int posInT1 (const TSet set,const int length,LObject &p)
4919{
4920 if (length==-1) return 0;
4921
4922 if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
4923
4924 int i;
4925 int an = 0;
4926 int en= length;
4927 int cmp_int=currRing->OrdSgn;
4928
4929 loop
4930 {
4931 if (an >= en-1)
4932 {
4933 if (pLmCmp(set[an].p,p.p) == cmp_int) return an;
4934 return en;
4935 }
4936 i=(an+en) / 2;
4937 if (pLmCmp(set[i].p,p.p) == cmp_int) en=i;
4938 else an=i;
4939 }
4940}
4941
4942/*2
4943* looks up the position of p in T
4944* set[0] is the smallest with respect to the ordering-procedure
4945* length
4946*/
4947int posInT2 (const TSet set,const int length,LObject &p)
4948{
4949 if (length==-1) return 0;
4950 p.GetpLength();
4951 if (set[length].length<p.length) return length+1;
4952
4953 int i;
4954 int an = 0;
4955 int en= length;
4956
4957 loop
4958 {
4959 if (an >= en-1)
4960 {
4961 if (set[an].length>p.length) return an;
4962 return en;
4963 }
4964 i=(an+en) / 2;
4965 if (set[i].length>p.length) en=i;
4966 else an=i;
4967 }
4968}
4969
4970/*2
4971* looks up the position of p in T
4972* set[0] is the smallest with respect to the ordering-procedure
4973* totaldegree,pComp
4974*/
4975int posInT11 (const TSet set,const int length,LObject &p)
4976{
4977 if (length==-1) return 0;
4978
4979 int o = p.GetpFDeg();
4980 int op = set[length].GetpFDeg();
4981 int cmp_int=currRing->OrdSgn;
4982
4983 if ((op < o)
4984 || ((op == o) && (pLmCmp(set[length].p,p.p) != cmp_int)))
4985 return length+1;
4986
4987 int i;
4988 int an = 0;
4989 int en= length;
4990
4991 loop
4992 {
4993 if (an >= en-1)
4994 {
4995 op= set[an].GetpFDeg();
4996 if ((op > o)
4997 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
4998 return an;
4999 return en;
5000 }
5001 i=(an+en) / 2;
5002 op = set[i].GetpFDeg();
5003 if (( op > o)
5004 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
5005 en=i;
5006 else
5007 an=i;
5008 }
5009}
5010
5011#ifdef HAVE_RINGS
5012int posInT11Ring (const TSet set,const int length,LObject &p)
5013{
5014 if (length==-1) return 0;
5015
5016 int o = p.GetpFDeg();
5017 int op = set[length].GetpFDeg();
5018
5019 if ((op < o)
5020 || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5021 return length+1;
5022
5023 int i;
5024 int an = 0;
5025 int en= length;
5026
5027 loop
5028 {
5029 if (an >= en-1)
5030 {
5031 op= set[an].GetpFDeg();
5032 if ((op > o)
5033 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5034 return an;
5035 return en;
5036 }
5037 i=(an+en) / 2;
5038 op = set[i].GetpFDeg();
5039 if (( op > o)
5040 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5041 en=i;
5042 else
5043 an=i;
5044 }
5045}
5046#endif
5047
5048/*2
5049* looks up the position of p in T
5050* set[0] is the smallest with respect to the ordering-procedure
5051* totaldegree,pComp
5052*/
5053int posInT110 (const TSet set,const int length,LObject &p)
5054{
5055 if (length==-1) return 0;
5056 p.GetpLength();
5057
5058 int o = p.GetpFDeg();
5059 int op = set[length].GetpFDeg();
5060 int cmp_int=currRing->OrdSgn;
5061
5062 if (( op < o)
5063 || (( op == o) && (set[length].length<p.length))
5064 || (( op == o) && (set[length].length == p.length)
5065 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5066 return length+1;
5067
5068 int i;
5069 int an = 0;
5070 int en= length;
5071 loop
5072 {
5073 if (an >= en-1)
5074 {
5075 op = set[an].GetpFDeg();
5076 if (( op > o)
5077 || (( op == o) && (set[an].length > p.length))
5078 || (( op == o) && (set[an].length == p.length)
5079 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5080 return an;
5081 return en;
5082 }
5083 i=(an+en) / 2;
5084 op = set[i].GetpFDeg();
5085 if (( op > o)
5086 || (( op == o) && (set[i].length > p.length))
5087 || (( op == o) && (set[i].length == p.length)
5088 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5089 en=i;
5090 else
5091 an=i;
5092 }
5093}
5094
5095#ifdef HAVE_RINGS
5096int posInT110Ring (const TSet set,const int length,LObject &p)
5097{
5098 if (length==-1) return 0;
5099 p.GetpLength();
5100
5101 int o = p.GetpFDeg();
5102 int op = set[length].GetpFDeg();
5103
5104 if (( op < o)
5105 || (( op == o) && (set[length].length<p.length))
5106 || (( op == o) && (set[length].length == p.length)
5107 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5108 return length+1;
5109
5110 int i;
5111 int an = 0;
5112 int en= length;
5113 loop
5114 {
5115 if (an >= en-1)
5116 {
5117 op = set[an].GetpFDeg();
5118 if (( op > o)
5119 || (( op == o) && (set[an].length > p.length))
5120 || (( op == o) && (set[an].length == p.length)
5121 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5122 return an;
5123 return en;
5124 }
5125 i=(an+en) / 2;
5126 op = set[i].GetpFDeg();
5127 if (( op > o)
5128 || (( op == o) && (set[i].length > p.length))
5129 || (( op == o) && (set[i].length == p.length)
5130 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5131 en=i;
5132 else
5133 an=i;
5134 }
5135}
5136#endif
5137
5138/*2
5139* looks up the position of p in set
5140* set[0] is the smallest with respect to the ordering-procedure
5141* pFDeg
5142*/
5143int posInT13 (const TSet set,const int length,LObject &p)
5144{
5145 if (length==-1) return 0;
5146
5147 int o = p.GetpFDeg();
5148
5149 if (set[length].GetpFDeg() <= o)
5150 return length+1;
5151
5152 int i;
5153 int an = 0;
5154 int en= length;
5155 loop
5156 {
5157 if (an >= en-1)
5158 {
5159 if (set[an].GetpFDeg() > o)
5160 return an;
5161 return en;
5162 }
5163 i=(an+en) / 2;
5164 if (set[i].GetpFDeg() > o)
5165 en=i;
5166 else
5167 an=i;
5168 }
5169}
5170
5171// determines the position based on: 1.) Ecart 2.) pLength
5172int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5173{
5174 if (length==-1) return 0;
5175 int ol = p.GetpLength();
5176 int op=p.ecart;
5177 int oo=set[length].ecart;
5178
5179 if ((oo < op) || ((oo==op) && (set[length].length <= ol)))
5180 return length+1;
5181
5182 int i;
5183 int an = 0;
5184 int en= length;
5185 loop
5186 {
5187 if (an >= en-1)
5188 {
5189 int oo=set[an].ecart;
5190 if((oo > op)
5191 || ((oo==op) && (set[an].pLength > ol)))
5192 return an;
5193 return en;
5194 }
5195 i=(an+en) / 2;
5196 int oo=set[i].ecart;
5197 if ((oo > op)
5198 || ((oo == op) && (set[i].pLength > ol)))
5199 en=i;
5200 else
5201 an=i;
5202 }
5203}
5204
5205/*2
5206* looks up the position of p in set
5207* set[0] is the smallest with respect to the ordering-procedure
5208* maximaldegree, pComp
5209*/
5210int posInT15 (const TSet set,const int length,LObject &p)
5211/*{
5212 *int j=0;
5213 * int o;
5214 *
5215 * o = p.GetpFDeg()+p.ecart;
5216 * loop
5217 * {
5218 * if ((set[j].GetpFDeg()+set[j].ecart > o)
5219 * || ((set[j].GetpFDeg()+set[j].ecart == o)
5220 * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5221 * {
5222 * return j;
5223 * }
5224 * j++;
5225 * if (j > length) return j;
5226 * }
5227 *}
5228 */
5229{
5230 if (length==-1) return 0;
5231
5232 int o = p.GetpFDeg() + p.ecart;
5233 int op = set[length].GetpFDeg()+set[length].ecart;
5234 int cmp_int=currRing->OrdSgn;
5235
5236 if ((op < o)
5237 || ((op == o)
5238 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5239 return length+1;
5240
5241 int i;
5242 int an = 0;
5243 int en= length;
5244 loop
5245 {
5246 if (an >= en-1)
5247 {
5248 op = set[an].GetpFDeg()+set[an].ecart;
5249 if (( op > o)
5250 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
5251 return an;
5252 return en;
5253 }
5254 i=(an+en) / 2;
5255 op = set[i].GetpFDeg()+set[i].ecart;
5256 if (( op > o)
5257 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
5258 en=i;
5259 else
5260 an=i;
5261 }
5262}
5263
5264#ifdef HAVE_RINGS
5265int posInT15Ring (const TSet set,const int length,LObject &p)
5266{
5267 if (length==-1) return 0;
5268
5269 int o = p.GetpFDeg() + p.ecart;
5270 int op = set[length].GetpFDeg()+set[length].ecart;
5271
5272 if ((op < o)
5273 || ((op == o)
5274 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5275 return length+1;
5276
5277 int i;
5278 int an = 0;
5279 int en= length;
5280 loop
5281 {
5282 if (an >= en-1)
5283 {
5284 op = set[an].GetpFDeg()+set[an].ecart;
5285 if (( op > o)
5286 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5287 return an;
5288 return en;
5289 }
5290 i=(an+en) / 2;
5291 op = set[i].GetpFDeg()+set[i].ecart;
5292 if (( op > o)
5293 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5294 en=i;
5295 else
5296 an=i;
5297 }
5298}
5299#endif
5300
5301/*2
5302* looks up the position of p in set
5303* set[0] is the smallest with respect to the ordering-procedure
5304* pFDeg+ecart, ecart, pComp
5305*/
5306int posInT17 (const TSet set,const int length,LObject &p)
5307/*
5308*{
5309* int j=0;
5310* int o;
5311*
5312* o = p.GetpFDeg()+p.ecart;
5313* loop
5314* {
5315* if ((pFDeg(set[j].p)+set[j].ecart > o)
5316* || (((pFDeg(set[j].p)+set[j].ecart == o)
5317* && (set[j].ecart < p.ecart)))
5318* || ((pFDeg(set[j].p)+set[j].ecart == o)
5319* && (set[j].ecart==p.ecart)
5320* && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5321* return j;
5322* j++;
5323* if (j > length) return j;
5324* }
5325* }
5326*/
5327{
5328 if (length==-1) return 0;
5329
5330 int o = p.GetpFDeg() + p.ecart;
5331 int op = set[length].GetpFDeg()+set[length].ecart;
5332 int cmp_int=currRing->OrdSgn;
5333
5334 if ((op < o)
5335 || (( op == o) && (set[length].ecart > p.ecart))
5336 || (( op == o) && (set[length].ecart==p.ecart)
5337 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5338 return length+1;
5339
5340 int i;
5341 int an = 0;
5342 int en= length;
5343 loop
5344 {
5345 if (an >= en-1)
5346 {
5347 op = set[an].GetpFDeg()+set[an].ecart;
5348 if (( op > o)
5349 || (( op == o) && (set[an].ecart < p.ecart))
5350 || (( op == o) && (set[an].ecart==p.ecart)
5351 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5352 return an;
5353 return en;
5354 }
5355 i=(an+en) / 2;
5356 op = set[i].GetpFDeg()+set[i].ecart;
5357 if ((op > o)
5358 || (( op == o) && (set[i].ecart < p.ecart))
5359 || (( op == o) && (set[i].ecart == p.ecart)
5360 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5361 en=i;
5362 else
5363 an=i;
5364 }
5365}
5366
5367#ifdef HAVE_RINGS
5368int posInT17Ring (const TSet set,const int length,LObject &p)
5369{
5370 if (length==-1) return 0;
5371
5372 int o = p.GetpFDeg() + p.ecart;
5373 int op = set[length].GetpFDeg()+set[length].ecart;
5374
5375 if ((op < o)
5376 || (( op == o) && (set[length].ecart > p.ecart))
5377 || (( op == o) && (set[length].ecart==p.ecart)
5378 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5379 return length+1;
5380
5381 int i;
5382 int an = 0;
5383 int en= length;
5384 loop
5385 {
5386 if (an >= en-1)
5387 {
5388 op = set[an].GetpFDeg()+set[an].ecart;
5389 if (( op > o)
5390 || (( op == o) && (set[an].ecart < p.ecart))
5391 || (( op == o) && (set[an].ecart==p.ecart)
5392 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5393 return an;
5394 return en;
5395 }
5396 i=(an+en) / 2;
5397 op = set[i].GetpFDeg()+set[i].ecart;
5398 if ((op > o)
5399 || (( op == o) && (set[i].ecart < p.ecart))
5400 || (( op == o) && (set[i].ecart == p.ecart)
5401 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5402 en=i;
5403 else
5404 an=i;
5405 }
5406}
5407#endif
5408
5409/*2
5410* looks up the position of p in set
5411* set[0] is the smallest with respect to the ordering-procedure
5412* pGetComp, pFDeg+ecart, ecart, pComp
5413*/
5414int posInT17_c (const TSet set,const int length,LObject &p)
5415{
5416 if (length==-1) return 0;
5417
5418 int cc = (-1+2*currRing->order[0]==ringorder_c);
5419 /* cc==1 for (c,..), cc==-1 for (C,..) */
5420 int o = p.GetpFDeg() + p.ecart;
5421 int c = pGetComp(p.p)*cc;
5422 int cmp_int=currRing->OrdSgn;
5423
5424 if (pGetComp(set[length].p)*cc < c)
5425 return length+1;
5426 if (pGetComp(set[length].p)*cc == c)
5427 {
5428 int op = set[length].GetpFDeg()+set[length].ecart;
5429 if ((op < o)
5430 || ((op == o) && (set[length].ecart > p.ecart))
5431 || ((op == o) && (set[length].ecart==p.ecart)
5432 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5433 return length+1;
5434 }
5435
5436 int i;
5437 int an = 0;
5438 int en= length;
5439 loop
5440 {
5441 if (an >= en-1)
5442 {
5443 if (pGetComp(set[an].p)*cc < c)
5444 return en;
5445 if (pGetComp(set[an].p)*cc == c)
5446 {
5447 int op = set[an].GetpFDeg()+set[an].ecart;
5448 if ((op > o)
5449 || ((op == o) && (set[an].ecart < p.ecart))
5450 || ((op == o) && (set[an].ecart==p.ecart)
5451 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5452 return an;
5453 }
5454 return en;
5455 }
5456 i=(an+en) / 2;
5457 if (pGetComp(set[i].p)*cc > c)
5458 en=i;
5459 else if (pGetComp(set[i].p)*cc == c)
5460 {
5461 int op = set[i].GetpFDeg()+set[i].ecart;
5462 if ((op > o)
5463 || ((op == o) && (set[i].ecart < p.ecart))
5464 || ((op == o) && (set[i].ecart == p.ecart)
5465 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5466 en=i;
5467 else
5468 an=i;
5469 }
5470 else
5471 an=i;
5472 }
5473}
5474
5475#ifdef HAVE_RINGS
5476int posInT17_cRing (const TSet set,const int length,LObject &p)
5477{
5478 if (length==-1) return 0;
5479
5480 int cc = (-1+2*currRing->order[0]==ringorder_c);
5481 /* cc==1 for (c,..), cc==-1 for (C,..) */
5482 int o = p.GetpFDeg() + p.ecart;
5483 int c = pGetComp(p.p)*cc;
5484
5485 if (pGetComp(set[length].p)*cc < c)
5486 return length+1;
5487 if (pGetComp(set[length].p)*cc == c)
5488 {
5489 int op = set[length].GetpFDeg()+set[length].ecart;
5490 if ((op < o)
5491 || ((op == o) && (set[length].ecart > p.ecart))
5492 || ((op == o) && (set[length].ecart==p.ecart)
5493 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5494 return length+1;
5495 }
5496
5497 int i;
5498 int an = 0;
5499 int en= length;
5500 loop
5501 {
5502 if (an >= en-1)
5503 {
5504 if (pGetComp(set[an].p)*cc < c)
5505 return en;
5506 if (pGetComp(set[an].p)*cc == c)
5507 {
5508 int op = set[an].GetpFDeg()+set[an].ecart;
5509 if ((op > o)
5510 || ((op == o) && (set[an].ecart < p.ecart))
5511 || ((op == o) && (set[an].ecart==p.ecart)
5512 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5513 return an;
5514 }
5515 return en;
5516 }
5517 i=(an+en) / 2;
5518 if (pGetComp(set[i].p)*cc > c)
5519 en=i;
5520 else if (pGetComp(set[i].p)*cc == c)
5521 {
5522 int op = set[i].GetpFDeg()+set[i].ecart;
5523 if ((op > o)
5524 || ((op == o) && (set[i].ecart < p.ecart))
5525 || ((op == o) && (set[i].ecart == p.ecart)
5526 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5527 en=i;
5528 else
5529 an=i;
5530 }
5531 else
5532 an=i;
5533 }
5534}
5535#endif
5536
5537/*2
5538* looks up the position of p in set
5539* set[0] is the smallest with respect to
5540* ecart, pFDeg, length
5541*/
5542int posInT19 (const TSet set,const int length,LObject &p)
5543{
5544 p.GetpLength();
5545 if (length==-1) return 0;
5546
5547 int o = p.ecart;
5548 int op=p.GetpFDeg();
5549
5550 if (set[length].ecart < o)
5551 return length+1;
5552 if (set[length].ecart == o)
5553 {
5554 int oo=set[length].GetpFDeg();
5555 if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5556 return length+1;
5557 }
5558
5559 int i;
5560 int an = 0;
5561 int en= length;
5562 loop
5563 {
5564 if (an >= en-1)
5565 {
5566 if (set[an].ecart > o)
5567 return an;
5568 if (set[an].ecart == o)
5569 {
5570 int oo=set[an].GetpFDeg();
5571 if((oo > op)
5572 || ((oo==op) && (set[an].length > p.length)))
5573 return an;
5574 }
5575 return en;
5576 }
5577 i=(an+en) / 2;
5578 if (set[i].ecart > o)
5579 en=i;
5580 else if (set[i].ecart == o)
5581 {
5582 int oo=set[i].GetpFDeg();
5583 if ((oo > op)
5584 || ((oo == op) && (set[i].length > p.length)))
5585 en=i;
5586 else
5587 an=i;
5588 }
5589 else
5590 an=i;
5591 }
5592}
5593
5594/*2
5595*looks up the position of polynomial p in set
5596*set[length] is the smallest element in set with respect
5597*to the ordering-procedure pComp
5598*/
5599int posInLSpecial (const LSet set, const int length,
5600 LObject *p,const kStrategy)
5601{
5602 if (length<0) return 0;
5603
5604 int d=p->GetpFDeg();
5605 int op=set[length].GetpFDeg();
5606 int cmp_int=currRing->OrdSgn;
5607
5608 if ((op > d)
5609 || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
5610 || (pLmCmp(set[length].p,p->p)== cmp_int))
5611 return length+1;
5612
5613 int i;
5614 int an = 0;
5615 int en= length;
5616 loop
5617 {
5618 if (an >= en-1)
5619 {
5620 op=set[an].GetpFDeg();
5621 if ((op > d)
5622 || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
5623 || (pLmCmp(set[an].p,p->p)== cmp_int))
5624 return en;
5625 return an;
5626 }
5627 i=(an+en) / 2;
5628 op=set[i].GetpFDeg();
5629 if ((op>d)
5630 || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
5631 || (pLmCmp(set[i].p,p->p) == cmp_int))
5632 an=i;
5633 else
5634 en=i;
5635 }
5636}
5637
5638/*2
5639*looks up the position of polynomial p in set
5640*set[length] is the smallest element in set with respect
5641*to the ordering-procedure pComp
5642*/
5643int posInL0 (const LSet set, const int length,
5644 LObject* p,const kStrategy)
5645{
5646 if (length<0) return 0;
5647
5648 int cmp_int=currRing->OrdSgn;
5649
5650 if (pLmCmp(set[length].p,p->p)== cmp_int)
5651 return length+1;
5652
5653 int i;
5654 int an = 0;
5655 int en= length;
5656 loop
5657 {
5658 if (an >= en-1)
5659 {
5660 if (pLmCmp(set[an].p,p->p) == cmp_int) return en;
5661 return an;
5662 }
5663 i=(an+en) / 2;
5664 if (pLmCmp(set[i].p,p->p) == cmp_int) an=i;
5665 else en=i;
5666 /*aend. fuer lazy == in !=- machen */
5667 }
5668}
5669
5670#ifdef HAVE_RINGS
5671int posInL0Ring (const LSet set, const int length,
5672 LObject* p,const kStrategy)
5673{
5674 if (length<0) return 0;
5675
5676 if (pLtCmpOrdSgnEqP(set[length].p,p->p))
5677 return length+1;
5678
5679 int i;
5680 int an = 0;
5681 int en= length;
5682 loop
5683 {
5684 if (an >= en-1)
5685 {
5686 if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
5687 return an;
5688 }
5689 i=(an+en) / 2;
5690 if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
5691 else en=i;
5692 /*aend. fuer lazy == in !=- machen */
5693 }
5694}
5695#endif
5696
5697/*2
5698* looks up the position of polynomial p in set
5699* e is the ecart of p
5700* set[length] is the smallest element in set with respect
5701* to the signature order
5702*/
5703int posInLSig (const LSet set, const int length,
5704 LObject* p,const kStrategy /*strat*/)
5705{
5706 if (length<0) return 0;
5707 int cmp_int=currRing->OrdSgn;
5708 if (pLtCmp(set[length].sig,p->sig)==cmp_int)
5709 return length+1;
5710
5711 int i;
5712 int an = 0;
5713 int en= length;
5714 loop
5715 {
5716 if (an >= en-1)
5717 {
5718 if (pLtCmp(set[an].sig,p->sig) == cmp_int) return en;
5719 return an;
5720 }
5721 i=(an+en) / 2;
5722 if (pLtCmp(set[i].sig,p->sig) == cmp_int) an=i;
5723 else en=i;
5724 /*aend. fuer lazy == in !=- machen */
5725 }
5726}
5727//sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
5728int posInLSigRing (const LSet set, const int length,
5729 LObject* p,const kStrategy /*strat*/)
5730{
5731 assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
5732 if (length<0) return 0;
5733 if (pLtCmp(set[length].sig,p->sig)== 1)
5734 return length+1;
5735
5736 int an,en,i;
5737 an = 0;
5738 en = length+1;
5739 int cmp;
5740 loop
5741 {
5742 if (an >= en-1)
5743 {
5744 if(an == en)
5745 return en;
5746 cmp = pLtCmp(set[an].sig,p->sig);
5747 if (cmp == 1)
5748 return en;
5749 if (cmp == -1)
5750 return an;
5751 if (cmp == 0)
5752 {
5753 if (set[an].FDeg > p->FDeg)
5754 return en;
5755 if (set[an].FDeg < p->FDeg)
5756 return an;
5757 if (set[an].FDeg == p->FDeg)
5758 {
5759 cmp = pLtCmp(set[an].p,p->p);
5760 if(cmp == 1)
5761 return en;
5762 else
5763 return an;
5764 }
5765 }
5766 }
5767 i=(an+en) / 2;
5768 cmp = pLtCmp(set[i].sig,p->sig);
5769 if (cmp == 1)
5770 an = i;
5771 if (cmp == -1)
5772 en = i;
5773 if (cmp == 0)
5774 {
5775 if (set[i].FDeg > p->FDeg)
5776 an = i;
5777 if (set[i].FDeg < p->FDeg)
5778 en = i;
5779 if (set[i].FDeg == p->FDeg)
5780 {
5781 cmp = pLtCmp(set[i].p,p->p);
5782 if(cmp == 1)
5783 an = i;
5784 else
5785 en = i;
5786 }
5787 }
5788 }
5789}
5790
5791// for sba, sorting syzygies
5792int posInSyz (const kStrategy strat, poly sig)
5793{
5794 if (strat->syzl==0) return 0;
5795 int cmp_int=currRing->OrdSgn;
5796 if (pLtCmp(strat->syz[strat->syzl-1],sig) != cmp_int)
5797 return strat->syzl;
5798 int i;
5799 int an = 0;
5800 int en= strat->syzl-1;
5801 loop
5802 {
5803 if (an >= en-1)
5804 {
5805 if (pLtCmp(strat->syz[an],sig) != cmp_int) return en;
5806 return an;
5807 }
5808 i=(an+en) / 2;
5809 if (pLtCmp(strat->syz[i],sig) != cmp_int) an=i;
5810 else en=i;
5811 /*aend. fuer lazy == in !=- machen */
5812 }
5813}
5814
5815/*2
5816*
5817* is only used in F5C, must ensure that the interreduction process does add new
5818* critical pairs to strat->L only behind all other critical pairs which are
5819* still in strat->L!
5820*/
5821int posInLF5C (const LSet /*set*/, const int /*length*/,
5822 LObject* /*p*/,const kStrategy strat)
5823{
5824 return strat->Ll+1;
5825}
5826
5827/*2
5828* looks up the position of polynomial p in set
5829* e is the ecart of p
5830* set[length] is the smallest element in set with respect
5831* to the ordering-procedure totaldegree,pComp
5832*/
5833int posInL11 (const LSet set, const int length,
5834 LObject* p,const kStrategy)
5835{
5836 if (length<0) return 0;
5837
5838 int o = p->GetpFDeg();
5839 int op = set[length].GetpFDeg();
5840 int cmp_int= -currRing->OrdSgn;
5841
5842 if ((op > o)
5843 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
5844 return length+1;
5845 int i;
5846 int an = 0;
5847 int en= length;
5848 loop
5849 {
5850 if (an >= en-1)
5851 {
5852 op = set[an].GetpFDeg();
5853 if ((op > o)
5854 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
5855 return en;
5856 return an;
5857 }
5858 i=(an+en) / 2;
5859 op = set[i].GetpFDeg();
5860 if ((op > o)
5861 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
5862 an=i;
5863 else
5864 en=i;
5865 }
5866}
5867
5868#ifdef HAVE_RINGS
5869/*2
5870* looks up the position of polynomial p in set
5871* set[length] is the smallest element in set with respect
5872* to the ordering-procedure pLmCmp,totaldegree,coefficient
5873* For the same totaldegree, original pairs (from F) will
5874* be put at the end and smallest coefficients
5875*/
5876int posInL11Ring (const LSet set, const int length,
5877 LObject* p,const kStrategy)
5878{
5879 if (length<0) return 0;
5880
5881 int o = p->GetpFDeg();
5882 int op = set[length].GetpFDeg();
5883
5884 if ((op > o)
5885 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5886 return length+1;
5887 int i;
5888 int an = 0;
5889 int en= length;
5890 loop
5891 {
5892 if (an >= en-1)
5893 {
5894 op = set[an].GetpFDeg();
5895 if ((op > o)
5896 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5897 return en;
5898 return an;
5899 }
5900 i=(an+en) / 2;
5901 op = set[i].GetpFDeg();
5902 if ((op > o)
5903 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5904 an=i;
5905 else
5906 en=i;
5907 }
5908}
5909
5910int posInLF5CRing (const LSet set, int start,const int length,
5911 LObject* p,const kStrategy)
5912{
5913 if (length<0) return 0;
5914 if(start == (length +1)) return (length+1);
5915 int o = p->GetpFDeg();
5916 int op = set[length].GetpFDeg();
5917
5918 if ((op > o)
5919 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
5920 return length+1;
5921 int i;
5922 int an = start;
5923 int en= length;
5924 loop
5925 {
5926 if (an >= en-1)
5927 {
5928 op = set[an].GetpFDeg();
5929 if ((op > o)
5930 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
5931 return en;
5932 return an;
5933 }
5934 i=(an+en) / 2;
5935 op = set[i].GetpFDeg();
5936 if ((op > o)
5937 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
5938 an=i;
5939 else
5940 en=i;
5941 }
5942}
5943#endif
5944
5945#ifdef HAVE_RINGS
5946int posInL11Ringls (const LSet set, const int length,
5947 LObject* p,const kStrategy)
5948{
5949 if (length < 0) return 0;
5950 int an,en,i;
5951 an = 0;
5952 en = length+1;
5953 loop
5954 {
5955 if (an >= en-1)
5956 {
5957 if(an == en)
5958 return en;
5959 if (set[an].FDeg > p->FDeg)
5960 return en;
5961 if (set[an].FDeg < p->FDeg)
5962 return an;
5963 if (set[an].FDeg == p->FDeg)
5964 {
5965 number lcset,lcp;
5966 lcset = pGetCoeff(set[an].p);
5967 lcp = pGetCoeff(p->p);
5968 if(!nGreaterZero(lcset))
5969 {
5970 set[an].p=p_Neg(set[an].p,currRing);
5971 if (set[an].t_p!=NULL)
5972 pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
5973 lcset=pGetCoeff(set[an].p);
5974 }
5975 if(!nGreaterZero(lcp))
5976 {
5977 p->p=p_Neg(p->p,currRing);
5978 if (p->t_p!=NULL)
5979 pSetCoeff0(p->t_p,pGetCoeff(p->p));
5980 lcp=pGetCoeff(p->p);
5981 }
5982 if(nGreater(lcset, lcp))
5983 {
5984 return en;
5985 }
5986 else
5987 {
5988 return an;
5989 }
5990 }
5991 }
5992 i=(an+en) / 2;
5993 if (set[i].FDeg > p->FDeg)
5994 an=i;
5995 if (set[i].FDeg < p->FDeg)
5996 en=i;
5997 if (set[i].FDeg == p->FDeg)
5998 {
5999 number lcset,lcp;
6000 lcset = pGetCoeff(set[i].p);
6001 lcp = pGetCoeff(p->p);
6002 if(!nGreaterZero(lcset))
6003 {
6004 set[i].p=p_Neg(set[i].p,currRing);
6005 if (set[i].t_p!=NULL)
6006 pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6007 lcset=pGetCoeff(set[i].p);
6008 }
6009 if(!nGreaterZero(lcp))
6010 {
6011 p->p=p_Neg(p->p,currRing);
6012 if (p->t_p!=NULL)
6013 pSetCoeff0(p->t_p,pGetCoeff(p->p));
6014 lcp=pGetCoeff(p->p);
6015 }
6016 if(nGreater(lcset, lcp))
6017 {
6018 an = i;
6019 }
6020 else
6021 {
6022 en = i;
6023 }
6024 }
6025 }
6026}
6027#endif
6028
6029/*2 Position for rings L: Here I am
6030* looks up the position of polynomial p in set
6031* e is the ecart of p
6032* set[length] is the smallest element in set with respect
6033* to the ordering-procedure totaldegree,pComp
6034*/
6035inline int getIndexRng(long coeff)
6036{
6037 if (coeff == 0) return -1;
6038 long tmp = coeff;
6039 int ind = 0;
6040 while (tmp % 2 == 0)
6041 {
6042 tmp = tmp / 2;
6043 ind++;
6044 }
6045 return ind;
6046}
6047
6048/*{
6049 if (length < 0) return 0;
6050
6051 int o = p->GetpFDeg();
6052 int op = set[length].GetpFDeg();
6053
6054 int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6055 int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6056 int inda;
6057 int indi;
6058
6059 if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6060 return length + 1;
6061 int i;
6062 int an = 0;
6063 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6064 int en = length;
6065 loop
6066 {
6067 if (an >= en-1)
6068 {
6069 op = set[an].GetpFDeg();
6070 if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6071 return en;
6072 return an;
6073 }
6074 i = (an + en) / 2;
6075 indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6076 op = set[i].GetpFDeg();
6077 if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6078 // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6079 {
6080 an = i;
6081 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6082 }
6083 else
6084 en = i;
6085 }
6086} */
6087
6088/*2
6089* looks up the position of polynomial p in set
6090* set[length] is the smallest element in set with respect
6091* to the ordering-procedure totaldegree,pLength0
6092*/
6093int posInL110 (const LSet set, const int length,
6094 LObject* p,const kStrategy)
6095{
6096 if (length<0) return 0;
6097
6098 int o = p->GetpFDeg();
6099 int op = set[length].GetpFDeg();
6100 int cmp_int= -currRing->OrdSgn;
6101
6102 if ((op > o)
6103 || ((op == o) && (set[length].length >p->length))
6104 || ((op == o) && (set[length].length <= p->length)
6105 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6106 return length+1;
6107 int i;
6108 int an = 0;
6109 int en= length;
6110 loop
6111 {
6112 if (an >= en-1)
6113 {
6114 op = set[an].GetpFDeg();
6115 if ((op > o)
6116 || ((op == o) && (set[an].length >p->length))
6117 || ((op == o) && (set[an].length <=p->length)
6118 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6119 return en;
6120 return an;
6121 }
6122 i=(an+en) / 2;
6123 op = set[i].GetpFDeg();
6124 if ((op > o)
6125 || ((op == o) && (set[i].length > p->length))
6126 || ((op == o) && (set[i].length <= p->length)
6127 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6128 an=i;
6129 else
6130 en=i;
6131 }
6132}
6133
6134#ifdef HAVE_RINGS
6135int posInL110Ring (const LSet set, const int length,
6136 LObject* p,const kStrategy)
6137{
6138 if (length<0) return 0;
6139
6140 int o = p->GetpFDeg();
6141 int op = set[length].GetpFDeg();
6142
6143 if ((op > o)
6144 || ((op == o) && (set[length].length >p->length))
6145 || ((op == o) && (set[length].length <= p->length)
6146 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6147 return length+1;
6148 int i;
6149 int an = 0;
6150 int en= length;
6151 loop
6152 {
6153 if (an >= en-1)
6154 {
6155 op = set[an].GetpFDeg();
6156 if ((op > o)
6157 || ((op == o) && (set[an].length >p->length))
6158 || ((op == o) && (set[an].length <=p->length)
6159 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6160 return en;
6161 return an;
6162 }
6163 i=(an+en) / 2;
6164 op = set[i].GetpFDeg();
6165 if ((op > o)
6166 || ((op == o) && (set[i].length > p->length))
6167 || ((op == o) && (set[i].length <= p->length)
6168 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6169 an=i;
6170 else
6171 en=i;
6172 }
6173}
6174#endif
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 totaldegree
6181*/
6182int posInL13 (const LSet set, const int length,
6183 LObject* p,const kStrategy)
6184{
6185 if (length<0) return 0;
6186
6187 int o = p->GetpFDeg();
6188
6189 if (set[length].GetpFDeg() > o)
6190 return length+1;
6191
6192 int i;
6193 int an = 0;
6194 int en= length;
6195 loop
6196 {
6197 if (an >= en-1)
6198 {
6199 if (set[an].GetpFDeg() >= o)
6200 return en;
6201 return an;
6202 }
6203 i=(an+en) / 2;
6204 if (set[i].GetpFDeg() >= o)
6205 an=i;
6206 else
6207 en=i;
6208 }
6209}
6210
6211/*2
6212* looks up the position of polynomial p in set
6213* e is the ecart of p
6214* set[length] is the smallest element in set with respect
6215* to the ordering-procedure maximaldegree,pComp
6216*/
6217int posInL15 (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 int cmp_int= -currRing->OrdSgn;
6225
6226 if ((op > o)
6227 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
6228 return length+1;
6229 int i;
6230 int an = 0;
6231 int en= length;
6232 loop
6233 {
6234 if (an >= en-1)
6235 {
6236 op = set[an].GetpFDeg() + set[an].ecart;
6237 if ((op > o)
6238 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
6239 return en;
6240 return an;
6241 }
6242 i=(an+en) / 2;
6243 op = set[i].GetpFDeg() + set[i].ecart;
6244 if ((op > o)
6245 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
6246 an=i;
6247 else
6248 en=i;
6249 }
6250}
6251
6252#ifdef HAVE_RINGS
6253int posInL15Ring (const LSet set, const int length,
6254 LObject* p,const kStrategy)
6255{
6256 if (length<0) return 0;
6257
6258 int o = p->GetpFDeg() + p->ecart;
6259 int op = set[length].GetpFDeg() + set[length].ecart;
6260
6261 if ((op > o)
6262 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6263 return length+1;
6264 int i;
6265 int an = 0;
6266 int en= length;
6267 loop
6268 {
6269 if (an >= en-1)
6270 {
6271 op = set[an].GetpFDeg() + set[an].ecart;
6272 if ((op > o)
6273 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6274 return en;
6275 return an;
6276 }
6277 i=(an+en) / 2;
6278 op = set[i].GetpFDeg() + set[i].ecart;
6279 if ((op > o)
6280 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6281 an=i;
6282 else
6283 en=i;
6284 }
6285}
6286#endif
6287
6288/*2
6289* looks up the position of polynomial p in set
6290* e is the ecart of p
6291* set[length] is the smallest element in set with respect
6292* to the ordering-procedure totaldegree
6293*/
6294int posInL17 (const LSet set, const int length,
6295 LObject* p,const kStrategy)
6296{
6297 if (length<0) return 0;
6298
6299 int o = p->GetpFDeg() + p->ecart;
6300 int cmp_int= -currRing->OrdSgn;
6301
6302 if ((set[length].GetpFDeg() + set[length].ecart > o)
6303 || ((set[length].GetpFDeg() + set[length].ecart == o)
6304 && (set[length].ecart > p->ecart))
6305 || ((set[length].GetpFDeg() + set[length].ecart == o)
6306 && (set[length].ecart == p->ecart)
6307 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6308 return length+1;
6309 int i;
6310 int an = 0;
6311 int en= length;
6312 loop
6313 {
6314 if (an >= en-1)
6315 {
6316 if ((set[an].GetpFDeg() + set[an].ecart > o)
6317 || ((set[an].GetpFDeg() + set[an].ecart == o)
6318 && (set[an].ecart > p->ecart))
6319 || ((set[an].GetpFDeg() + set[an].ecart == o)
6320 && (set[an].ecart == p->ecart)
6321 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6322 return en;
6323 return an;
6324 }
6325 i=(an+en) / 2;
6326 if ((set[i].GetpFDeg() + set[i].ecart > o)
6327 || ((set[i].GetpFDeg() + set[i].ecart == o)
6328 && (set[i].ecart > p->ecart))
6329 || ((set[i].GetpFDeg() +set[i].ecart == o)
6330 && (set[i].ecart == p->ecart)
6331 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6332 an=i;
6333 else
6334 en=i;
6335 }
6336}
6337
6338#ifdef HAVE_RINGS
6339int posInL17Ring (const LSet set, const int length,
6340 LObject* p,const kStrategy)
6341{
6342 if (length<0) return 0;
6343
6344 int o = p->GetpFDeg() + p->ecart;
6345
6346 if ((set[length].GetpFDeg() + set[length].ecart > o)
6347 || ((set[length].GetpFDeg() + set[length].ecart == o)
6348 && (set[length].ecart > p->ecart))
6349 || ((set[length].GetpFDeg() + set[length].ecart == o)
6350 && (set[length].ecart == p->ecart)
6351 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6352 return length+1;
6353 int i;
6354 int an = 0;
6355 int en= length;
6356 loop
6357 {
6358 if (an >= en-1)
6359 {
6360 if ((set[an].GetpFDeg() + set[an].ecart > o)
6361 || ((set[an].GetpFDeg() + set[an].ecart == o)
6362 && (set[an].ecart > p->ecart))
6363 || ((set[an].GetpFDeg() + set[an].ecart == o)
6364 && (set[an].ecart == p->ecart)
6365 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6366 return en;
6367 return an;
6368 }
6369 i=(an+en) / 2;
6370 if ((set[i].GetpFDeg() + set[i].ecart > o)
6371 || ((set[i].GetpFDeg() + set[i].ecart == o)
6372 && (set[i].ecart > p->ecart))
6373 || ((set[i].GetpFDeg() +set[i].ecart == o)
6374 && (set[i].ecart == p->ecart)
6375 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6376 an=i;
6377 else
6378 en=i;
6379 }
6380}
6381#endif
6382
6383/*2
6384* looks up the position of polynomial p in set
6385* e is the ecart of p
6386* set[length] is the smallest element in set with respect
6387* to the ordering-procedure pComp
6388*/
6389int posInL17_c (const LSet set, const int length,
6390 LObject* p,const kStrategy)
6391{
6392 if (length<0) return 0;
6393
6394 int cc = (-1+2*currRing->order[0]==ringorder_c);
6395 /* cc==1 for (c,..), cc==-1 for (C,..) */
6396 long c = pGetComp(p->p)*cc;
6397 int o = p->GetpFDeg() + p->ecart;
6398 int cmp_int= -currRing->OrdSgn;
6399
6400 if (pGetComp(set[length].p)*cc > c)
6401 return length+1;
6402 if (pGetComp(set[length].p)*cc == c)
6403 {
6404 if ((set[length].GetpFDeg() + set[length].ecart > o)
6405 || ((set[length].GetpFDeg() + set[length].ecart == o)
6406 && (set[length].ecart > p->ecart))
6407 || ((set[length].GetpFDeg() + set[length].ecart == o)
6408 && (set[length].ecart == p->ecart)
6409 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6410 return length+1;
6411 }
6412 int i;
6413 int an = 0;
6414 int en= length;
6415 loop
6416 {
6417 if (an >= en-1)
6418 {
6419 if (pGetComp(set[an].p)*cc > c)
6420 return en;
6421 if (pGetComp(set[an].p)*cc == c)
6422 {
6423 if ((set[an].GetpFDeg() + set[an].ecart > o)
6424 || ((set[an].GetpFDeg() + set[an].ecart == o)
6425 && (set[an].ecart > p->ecart))
6426 || ((set[an].GetpFDeg() + set[an].ecart == o)
6427 && (set[an].ecart == p->ecart)
6428 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6429 return en;
6430 }
6431 return an;
6432 }
6433 i=(an+en) / 2;
6434 if (pGetComp(set[i].p)*cc > c)
6435 an=i;
6436 else if (pGetComp(set[i].p)*cc == c)
6437 {
6438 if ((set[i].GetpFDeg() + set[i].ecart > o)
6439 || ((set[i].GetpFDeg() + set[i].ecart == o)
6440 && (set[i].ecart > p->ecart))
6441 || ((set[i].GetpFDeg() +set[i].ecart == o)
6442 && (set[i].ecart == p->ecart)
6443 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6444 an=i;
6445 else
6446 en=i;
6447 }
6448 else
6449 en=i;
6450 }
6451}
6452
6453#ifdef HAVE_RINGS
6454int posInL17_cRing (const LSet set, const int length,
6455 LObject* p,const kStrategy)
6456{
6457 if (length<0) return 0;
6458
6459 int cc = (-1+2*currRing->order[0]==ringorder_c);
6460 /* cc==1 for (c,..), cc==-1 for (C,..) */
6461 unsigned long c = pGetComp(p->p)*cc;
6462 int o = p->GetpFDeg() + p->ecart;
6463
6464 if (pGetComp(set[length].p)*cc > c)
6465 return length+1;
6466 if (pGetComp(set[length].p)*cc == c)
6467 {
6468 if ((set[length].GetpFDeg() + set[length].ecart > o)
6469 || ((set[length].GetpFDeg() + set[length].ecart == o)
6470 && (set[length].ecart > p->ecart))
6471 || ((set[length].GetpFDeg() + set[length].ecart == o)
6472 && (set[length].ecart == p->ecart)
6473 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6474 return length+1;
6475 }
6476 int i;
6477 int an = 0;
6478 int en= length;
6479 loop
6480 {
6481 if (an >= en-1)
6482 {
6483 if (pGetComp(set[an].p)*cc > c)
6484 return en;
6485 if (pGetComp(set[an].p)*cc == c)
6486 {
6487 if ((set[an].GetpFDeg() + set[an].ecart > o)
6488 || ((set[an].GetpFDeg() + set[an].ecart == o)
6489 && (set[an].ecart > p->ecart))
6490 || ((set[an].GetpFDeg() + set[an].ecart == o)
6491 && (set[an].ecart == p->ecart)
6492 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6493 return en;
6494 }
6495 return an;
6496 }
6497 i=(an+en) / 2;
6498 if (pGetComp(set[i].p)*cc > c)
6499 an=i;
6500 else if (pGetComp(set[i].p)*cc == c)
6501 {
6502 if ((set[i].GetpFDeg() + set[i].ecart > o)
6503 || ((set[i].GetpFDeg() + set[i].ecart == o)
6504 && (set[i].ecart > p->ecart))
6505 || ((set[i].GetpFDeg() +set[i].ecart == o)
6506 && (set[i].ecart == p->ecart)
6507 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6508 an=i;
6509 else
6510 en=i;
6511 }
6512 else
6513 en=i;
6514 }
6515}
6516#endif
6517
6518/*
6519 * SYZYGY CRITERION for signature-based standard basis algorithms
6520 */
6521BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6522{
6523//#if 1
6524#ifdef DEBUGF5
6525 PrintS("syzygy criterion checks: ");
6526 pWrite(sig);
6527#endif
6528 for (int k=0; k<strat->syzl; k++)
6529 {
6530 //printf("-%d",k);
6531//#if 1
6532#ifdef DEBUGF5
6533 Print("checking with: %d / %d -- \n",k,strat->syzl);
6534 pWrite(pHead(strat->syz[k]));
6535#endif
6536 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6537 && (!rField_is_Ring(currRing) ||
6538 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6539 {
6540//#if 1
6541#ifdef DEBUGF5
6542 PrintS("DELETE!\n");
6543#endif
6544 strat->nrsyzcrit++;
6545 //printf("- T -\n\n");
6546 return TRUE;
6547 }
6548 }
6549 //printf("- F -\n\n");
6550 return FALSE;
6551}
6552
6553/*
6554 * SYZYGY CRITERION for signature-based standard basis algorithms
6555 */
6556BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6557{
6558//#if 1
6559 if(sig == NULL)
6560 return FALSE;
6561#ifdef DEBUGF5
6562 PrintS("--- syzygy criterion checks: ");
6563 pWrite(sig);
6564#endif
6565 int comp = __p_GetComp(sig, currRing);
6566 int min, max;
6567 if (comp<=1)
6568 return FALSE;
6569 else
6570 {
6571 min = strat->syzIdx[comp-2];
6572 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
6573 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
6574 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
6575 if (comp == strat->currIdx)
6576 {
6577 max = strat->syzl;
6578 }
6579 else
6580 {
6581 max = strat->syzIdx[comp-1];
6582 }
6583 for (int k=min; k<max; k++)
6584 {
6585#ifdef F5DEBUG
6586 Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
6587 Print("checking with: %d -- ",k);
6588 pWrite(pHead(strat->syz[k]));
6589#endif
6590 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6591 && (!rField_is_Ring(currRing) ||
6592 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6593 {
6594 strat->nrsyzcrit++;
6595 return TRUE;
6596 }
6597 }
6598 return FALSE;
6599 }
6600}
6601
6602/*
6603 * REWRITTEN CRITERION for signature-based standard basis algorithms
6604 */
6605BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
6606{
6607 //printf("Faugere Rewritten Criterion\n");
6609 return FALSE;
6610//#if 1
6611#ifdef DEBUGF5
6612 PrintS("rewritten criterion checks: ");
6613 pWrite(sig);
6614#endif
6615 for(int k = strat->sl; k>=start; k--)
6616 {
6617//#if 1
6618#ifdef DEBUGF5
6619 PrintS("checking with: ");
6620 pWrite(strat->sig[k]);
6621 pWrite(pHead(strat->S[k]));
6622#endif
6623 if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
6624 {
6625//#if 1
6626#ifdef DEBUGF5
6627 PrintS("DELETE!\n");
6628#endif
6629 strat->nrrewcrit++;
6630 return TRUE;
6631 }
6632 //k--;
6633 }
6634#ifdef DEBUGF5
6635 PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
6636 for(int kk = 0; kk<strat->sl+1; kk++)
6637 {
6638 pWrite(pHead(strat->S[kk]));
6639 }
6640 PrintS("------------------------------\n");
6641#endif
6642 return FALSE;
6643}
6644
6645/*
6646 * REWRITTEN CRITERION for signature-based standard basis algorithms
6647 ***************************************************************************
6648 * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
6649 ***************************************************************************
6650 */
6651
6652// real implementation of arri's rewritten criterion, only called once in
6653// kstd2.cc, right before starting reduction
6654// IDEA: Arri says that it is enough to consider 1 polynomial for each unique
6655// signature appearing during the computations. Thus we first of all go
6656// through strat->L and delete all other pairs of the same signature,
6657// keeping only the one with least possible leading monomial. After this
6658// we check if we really need to compute this critical pair at all: There
6659// can be elements already in strat->S whose signatures divide the
6660// signature of the critical pair in question and whose multiplied
6661// leading monomials are smaller than the leading monomial of the
6662// critical pair. In this situation we can discard the critical pair
6663// completely.
6664BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
6665{
6667 return FALSE;
6668 poly p1 = pOne();
6669 poly p2 = pOne();
6670 for (int ii=strat->sl; ii>start; ii--)
6671 {
6672 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
6673 {
6674 p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
6675 p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
6676 if (!(pLmCmp(p1,p2) == 1))
6677 {
6678 pDelete(&p1);
6679 pDelete(&p2);
6680 return TRUE;
6681 }
6682 }
6683 }
6684 pDelete(&p1);
6685 pDelete(&p2);
6686 return FALSE;
6687}
6688
6689BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
6690{
6691 //Over Rings, there are still some changes to do: considering coeffs
6693 return FALSE;
6694 int found = -1;
6695 for (int i=strat->Bl; i>-1; i--)
6696 {
6697 if (pLmEqual(strat->B[i].sig,sig))
6698 {
6699 found = i;
6700 break;
6701 }
6702 }
6703 if (found != -1)
6704 {
6705 if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
6706 {
6707 deleteInL(strat->B,&strat->Bl,found,strat);
6708 }
6709 else
6710 {
6711 return TRUE;
6712 }
6713 }
6714 poly p1 = pOne();
6715 poly p2 = pOne();
6716 for (int ii=strat->sl; ii>-1; ii--)
6717 {
6718 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
6719 {
6720 p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
6721 p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
6722 if (!(pLmCmp(p1,p2) == 1))
6723 {
6724 pDelete(&p1);
6725 pDelete(&p2);
6726 return TRUE;
6727 }
6728 }
6729 }
6730 pDelete(&p1);
6731 pDelete(&p2);
6732 return FALSE;
6733}
6734
6735/***************************************************************
6736 *
6737 * Tail reductions
6738 *
6739 ***************************************************************/
6740TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
6741{
6742 int j = 0;
6743 const unsigned long not_sev = ~L->sev;
6744 const unsigned long* sev = strat->sevS;
6745 poly p;
6746 ring r;
6747 L->GetLm(p, r);
6748
6749 assume(~not_sev == p_GetShortExpVector(p, r));
6750
6751 if (r == currRing)
6752 {
6753 if(!rField_is_Ring(r))
6754 {
6755 loop
6756 {
6757 if (j > end_pos) return NULL;
6758 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6759 if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
6760 (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6761 #else
6762 if (!(sev[j] & not_sev) &&
6763 (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
6764 p_LmDivisibleBy(strat->S[j], p, r))
6765 #endif
6766 {
6767 break;
6768 }
6769 j++;
6770 }
6771 }
6772 #ifdef HAVE_RINGS
6773 else
6774 {
6775 loop
6776 {
6777 if (j > end_pos) return NULL;
6778 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6779 if (strat->S[j]!= NULL
6780 && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r)
6781 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6782 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6783 #else
6784 if (!(sev[j] & not_sev)
6785 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6786 && p_LmDivisibleBy(strat->S[j], p, r)
6787 && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
6788 #endif
6789 {
6790 break; // found
6791 }
6792 j++;
6793 }
6794 }
6795 #endif
6796 // if called from NF, T objects do not exist:
6797 if (strat->tl < 0 || strat->S_2_R[j] == -1)
6798 {
6799 T->Set(strat->S[j], r, strat->tailRing);
6800 assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
6801 return T;
6802 }
6803 else
6804 {
6805///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
6806///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
6807// assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
6808 return strat->S_2_T(j);
6809 }
6810 }
6811 else
6812 {
6813 TObject* t;
6814 if(!rField_is_Ring(r))
6815 {
6816 loop
6817 {
6818 if (j > end_pos) return NULL;
6819 assume(strat->S_2_R[j] != -1);
6820 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6821 t = strat->S_2_T(j);
6822 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6823 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6824 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6825 {
6826 t->pLength=pLength(t->t_p);
6827 return t;
6828 }
6829 #else
6830 if (! (sev[j] & not_sev)
6831 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6832 {
6833 t = strat->S_2_T(j);
6834 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6835 if (p_LmDivisibleBy(t->t_p, p, r))
6836 {
6837 t->pLength=pLength(t->t_p);
6838 return t;
6839 }
6840 }
6841 #endif
6842 j++;
6843 }
6844 }
6845 #ifdef HAVE_RINGS
6846 else
6847 {
6848 loop
6849 {
6850 if (j > end_pos) return NULL;
6851 assume(strat->S_2_R[j] != -1);
6852 #if defined(PDEBUG) || defined(PDIV_DEBUG)
6853 t = strat->S_2_T(j);
6854 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
6855 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r)
6856 && (ecart== LONG_MAX || ecart>= strat->ecartS[j])
6857 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6858 {
6859 t->pLength=pLength(t->t_p);
6860 return t;
6861 }
6862 #else
6863 if (! (sev[j] & not_sev)
6864 && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
6865 {
6866 t = strat->S_2_T(j);
6867 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
6868 if (p_LmDivisibleBy(t->t_p, p, r)
6869 && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
6870 {
6871 t->pLength=pLength(t->t_p);
6872 return t;
6873 }
6874 }
6875 #endif
6876 j++;
6877 }
6878 }
6879 #endif
6880 }
6881}
6882
6883poly redtail (LObject* L, int end_pos, kStrategy strat)
6884{
6885 poly h, hn;
6886 strat->redTailChange=FALSE;
6887
6888 L->GetP();
6889 poly p = L->p;
6890 if (strat->noTailReduction || pNext(p) == NULL)
6891 return p;
6892
6893 LObject Ln(strat->tailRing);
6894 TObject* With;
6895 // placeholder in case strat->tl < 0
6896 TObject With_s(strat->tailRing);
6897 h = p;
6898 hn = pNext(h);
6899 long op = strat->tailRing->pFDeg(hn, strat->tailRing);
6900 long e;
6901 int l;
6902 BOOLEAN save_HE=strat->kAllAxis;
6903 strat->kAllAxis |=
6904 ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
6905
6906 while(hn != NULL)
6907 {
6908 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6909 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6910 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6911 loop
6912 {
6913 Ln.Set(hn, strat->tailRing);
6914 Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
6915 if (strat->kAllAxis)
6916 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
6917 else
6918 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
6919 if (With == NULL) break;
6920 With->length=0;
6921 With->pLength=0;
6922 strat->redTailChange=TRUE;
6923 if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
6924 {
6925 // reducing the tail would violate the exp bound
6926 if (kStratChangeTailRing(strat, L))
6927 {
6928 strat->kAllAxis = save_HE;
6929 return redtail(L, end_pos, strat);
6930 }
6931 else
6932 return NULL;
6933 }
6934 hn = pNext(h);
6935 if (hn == NULL) goto all_done;
6936 op = strat->tailRing->pFDeg(hn, strat->tailRing);
6937 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
6938 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
6939 }
6940 h = hn;
6941 hn = pNext(h);
6942 }
6943
6944 all_done:
6945 if (strat->redTailChange)
6946 {
6947 L->pLength = 0;
6948 }
6949 strat->kAllAxis = save_HE;
6950 return p;
6951}
6952
6953poly redtail (poly p, int end_pos, kStrategy strat)
6954{
6955 LObject L(p, currRing);
6956 return redtail(&L, end_pos, strat);
6957}
6958
6959poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
6960{
6961 strat->redTailChange=FALSE;
6962 if (strat->noTailReduction) return L->GetLmCurrRing();
6963 poly h, p;
6964 p = h = L->GetLmTailRing();
6965 if ((h==NULL) || (pNext(h)==NULL))
6966 return L->GetLmCurrRing();
6967
6968 TObject* With;
6969 // placeholder in case strat->tl < 0
6970 TObject With_s(strat->tailRing);
6971
6972 LObject Ln(pNext(h), strat->tailRing);
6973 Ln.GetpLength();
6974
6975 pNext(h) = NULL;
6976 if (L->p != NULL)
6977 {
6978 pNext(L->p) = NULL;
6979 if (L->t_p != NULL) pNext(L->t_p) = NULL;
6980 }
6981 L->pLength = 1;
6982
6983 Ln.PrepareRed(strat->use_buckets);
6984
6985 int cnt=REDTAIL_CANONICALIZE;
6986 while(!Ln.IsNull())
6987 {
6988 loop
6989 {
6990 if (TEST_OPT_IDLIFT)
6991 {
6992 if (Ln.p!=NULL)
6993 {
6994 if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
6995 }
6996 else
6997 {
6998 if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
6999 }
7000 }
7001 Ln.SetShortExpVector();
7002 if (withT)
7003 {
7004 int j;
7005 j = kFindDivisibleByInT(strat, &Ln);
7006 if (j < 0) break;
7007 With = &(strat->T[j]);
7008 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7009 }
7010 else
7011 {
7012 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7013 if (With == NULL) break;
7014 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7015 }
7016 cnt--;
7017 if (cnt==0)
7018 {
7020 /*poly tmp=*/Ln.CanonicalizeP();
7021 if (normalize)
7022 {
7023 Ln.Normalize();
7024 //pNormalize(tmp);
7025 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7026 }
7027 }
7028 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7029 {
7030 With->pNorm();
7031 }
7032 strat->redTailChange=TRUE;
7033 if (ksReducePolyTail(L, With, &Ln))
7034 {
7035 // reducing the tail would violate the exp bound
7036 // set a flag and hope for a retry (in bba)
7038 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7039 do
7040 {
7041 pNext(h) = Ln.LmExtractAndIter();
7042 pIter(h);
7043 L->pLength++;
7044 } while (!Ln.IsNull());
7045 goto all_done;
7046 }
7047 if (Ln.IsNull()) goto all_done;
7048 if (! withT) With_s.Init(currRing);
7049 }
7050 pNext(h) = Ln.LmExtractAndIter();
7051 pIter(h);
7052 pNormalize(h);
7053 L->pLength++;
7054 }
7055
7056 all_done:
7057 Ln.Delete();
7058 if (L->p != NULL) pNext(L->p) = pNext(p);
7059
7060 if (strat->redTailChange)
7061 {
7062 L->length = 0;
7063 L->pLength = 0;
7064 }
7065
7066 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7067 //L->Normalize(); // HANNES: should have a test
7068 kTest_L(L,strat);
7069 return L->GetLmCurrRing();
7070}
7071
7072poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7073{
7074 strat->redTailChange=FALSE;
7075 if (strat->noTailReduction) return L->GetLmCurrRing();
7076 poly h, p;
7077 p = h = L->GetLmTailRing();
7078 if ((h==NULL) || (pNext(h)==NULL))
7079 return L->GetLmCurrRing();
7080
7081 TObject* With;
7082 // placeholder in case strat->tl < 0
7083 TObject With_s(strat->tailRing);
7084
7085 LObject Ln(pNext(h), strat->tailRing);
7086 Ln.pLength = L->GetpLength() - 1;
7087
7088 pNext(h) = NULL;
7089 if (L->p != NULL) pNext(L->p) = NULL;
7090 L->pLength = 1;
7091
7092 Ln.PrepareRed(strat->use_buckets);
7093
7094 int cnt=REDTAIL_CANONICALIZE;
7095 while(!Ln.IsNull())
7096 {
7097 loop
7098 {
7099 if (TEST_OPT_IDLIFT)
7100 {
7101 if (Ln.p!=NULL)
7102 {
7103 if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7104 }
7105 else
7106 {
7107 if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7108 }
7109 }
7110 Ln.SetShortExpVector();
7111 if (withT)
7112 {
7113 int j;
7114 j = kFindDivisibleByInT(strat, &Ln);
7115 if (j < 0) break;
7116 With = &(strat->T[j]);
7117 }
7118 else
7119 {
7120 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7121 if (With == NULL) break;
7122 }
7123 cnt--;
7124 if (cnt==0)
7125 {
7127 /*poly tmp=*/Ln.CanonicalizeP();
7128 if (normalize)
7129 {
7130 Ln.Normalize();
7131 //pNormalize(tmp);
7132 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7133 }
7134 }
7135 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7136 {
7137 With->pNorm();
7138 }
7139 strat->redTailChange=TRUE;
7140 if (ksReducePolyTail(L, With, &Ln))
7141 {
7142 // reducing the tail would violate the exp bound
7143 // set a flag and hope for a retry (in bba)
7145 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7146 do
7147 {
7148 pNext(h) = Ln.LmExtractAndIter();
7149 pIter(h);
7150 L->pLength++;
7151 } while (!Ln.IsNull());
7152 goto all_done;
7153 }
7154 if(!Ln.IsNull())
7155 {
7156 Ln.GetP();
7157 Ln.p = pJet(Ln.p,bound);
7158 }
7159 if (Ln.IsNull())
7160 {
7161 goto all_done;
7162 }
7163 if (! withT) With_s.Init(currRing);
7164 }
7165 pNext(h) = Ln.LmExtractAndIter();
7166 pIter(h);
7167 pNormalize(h);
7168 L->pLength++;
7169 }
7170
7171 all_done:
7172 Ln.Delete();
7173 if (L->p != NULL) pNext(L->p) = pNext(p);
7174
7175 if (strat->redTailChange)
7176 {
7177 L->length = 0;
7178 L->pLength = 0;
7179 }
7180
7181 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7182 //L->Normalize(); // HANNES: should have a test
7183 kTest_L(L,strat);
7184 return L->GetLmCurrRing();
7185}
7186
7187#ifdef HAVE_RINGS
7188void redtailBbaAlsoLC_Z (LObject* L, int end_pos, kStrategy strat )
7189// normalize=FALSE, withT=FALSE, coeff=Z
7190{
7191 strat->redTailChange=FALSE;
7192
7193 poly h, p;
7194 p = h = L->GetLmTailRing();
7195 if ((h==NULL) || (pNext(h)==NULL))
7196 return;
7197
7198 TObject* With;
7199 LObject Ln(pNext(h), strat->tailRing);
7200 Ln.GetpLength();
7201
7202 pNext(h) = NULL;
7203 if (L->p != NULL)
7204 {
7205 pNext(L->p) = NULL;
7206 if (L->t_p != NULL) pNext(L->t_p) = NULL;
7207 }
7208 L->pLength = 1;
7209
7210 Ln.PrepareRed(strat->use_buckets);
7211
7212 int cnt=REDTAIL_CANONICALIZE;
7213
7214 while(!Ln.IsNull())
7215 {
7216 loop
7217 {
7218 if (TEST_OPT_IDLIFT)
7219 {
7220 if (Ln.p!=NULL)
7221 {
7222 if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7223 }
7224 else
7225 {
7226 if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7227 }
7228 }
7229 Ln.SetShortExpVector();
7230 int j;
7231 j = kFindDivisibleByInT(strat, &Ln);
7232 if (j < 0)
7233 {
7234 j = kFindDivisibleByInT_Z(strat, &Ln);
7235 if (j < 0)
7236 {
7237 break;
7238 }
7239 else
7240 {
7241 /* reduction not cancelling a tail term, but reducing its coefficient */
7242 With = &(strat->T[j]);
7243 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7244 cnt--;
7245 if (cnt==0)
7246 {
7248 /*poly tmp=*/Ln.CanonicalizeP();
7249 }
7250 strat->redTailChange=TRUE;
7251 /* reduction cancelling a tail term */
7252 if (ksReducePolyTailLC_Z(L, With, &Ln))
7253 {
7254 // reducing the tail would violate the exp bound
7255 // set a flag and hope for a retry (in bba)
7257 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7258 do
7259 {
7260 pNext(h) = Ln.LmExtractAndIter();
7261 pIter(h);
7262 L->pLength++;
7263 } while (!Ln.IsNull());
7264 goto all_done;
7265 }
7266 /* we have to break since we did not cancel the term, but only decreased
7267 * its coefficient. */
7268 break;
7269 }
7270 } else {
7271 With = &(strat->T[j]);
7272 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7273 cnt--;
7274 if (cnt==0)
7275 {
7277 /*poly tmp=*/Ln.CanonicalizeP();
7278 }
7279 strat->redTailChange=TRUE;
7280 /* reduction cancelling a tail term */
7281 if (ksReducePolyTail_Z(L, With, &Ln))
7282 {
7283 // reducing the tail would violate the exp bound
7284 // set a flag and hope for a retry (in bba)
7286 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7287 do
7288 {
7289 pNext(h) = Ln.LmExtractAndIter();
7290 pIter(h);
7291 L->pLength++;
7292 } while (!Ln.IsNull());
7293 goto all_done;
7294 }
7295 }
7296 if (Ln.IsNull()) goto all_done;
7297 }
7298 pNext(h) = Ln.LmExtractAndIter();
7299 pIter(h);
7300 L->pLength++;
7301 }
7302
7303 all_done:
7304 Ln.Delete();
7305 if (L->p != NULL) pNext(L->p) = pNext(p);
7306
7307 if (strat->redTailChange)
7308 {
7309 L->length = 0;
7310 L->pLength = 0;
7311 }
7312
7313 kTest_L(L, strat);
7314 return;
7315}
7316
7317poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7318// normalize=FALSE, withT=FALSE, coeff=Z
7319{
7320 strat->redTailChange=FALSE;
7321 if (strat->noTailReduction) return L->GetLmCurrRing();
7322 poly h, p;
7323 p = h = L->GetLmTailRing();
7324 if ((h==NULL) || (pNext(h)==NULL))
7325 return L->GetLmCurrRing();
7326
7327 TObject* With;
7328 // placeholder in case strat->tl < 0
7329 TObject With_s(strat->tailRing);
7330
7331 LObject Ln(pNext(h), strat->tailRing);
7332 Ln.pLength = L->GetpLength() - 1;
7333
7334 pNext(h) = NULL;
7335 if (L->p != NULL) pNext(L->p) = NULL;
7336 L->pLength = 1;
7337
7338 Ln.PrepareRed(strat->use_buckets);
7339
7340 int cnt=REDTAIL_CANONICALIZE;
7341 while(!Ln.IsNull())
7342 {
7343 loop
7344 {
7345 Ln.SetShortExpVector();
7346 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7347 if (With == NULL) break;
7348 cnt--;
7349 if (cnt==0)
7350 {
7352 /*poly tmp=*/Ln.CanonicalizeP();
7353 }
7354 // we are in Z, do not call pNorm
7355 strat->redTailChange=TRUE;
7356 // test divisibility of coefs:
7357 poly p_Ln=Ln.GetLmCurrRing();
7358 poly p_With=With->GetLmCurrRing();
7359
7360 if (ksReducePolyTail_Z(L, With, &Ln))
7361 {
7362 // reducing the tail would violate the exp bound
7363 // set a flag and hope for a retry (in bba)
7365 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7366 do
7367 {
7368 pNext(h) = Ln.LmExtractAndIter();
7369 pIter(h);
7370 L->pLength++;
7371 } while (!Ln.IsNull());
7372 goto all_done;
7373 }
7374 if (Ln.IsNull()) goto all_done;
7375 With_s.Init(currRing);
7376 }
7377 pNext(h) = Ln.LmExtractAndIter();
7378 pIter(h);
7379 pNormalize(h);
7380 L->pLength++;
7381 }
7382
7383 all_done:
7384 Ln.Delete();
7385 if (L->p != NULL) pNext(L->p) = pNext(p);
7386
7387 if (strat->redTailChange)
7388 {
7389 L->length = 0;
7390 }
7391
7392 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7393 //L->Normalize(); // HANNES: should have a test
7394 kTest_L(L,strat);
7395 return L->GetLmCurrRing();
7396}
7397
7398poly redtailBba_NF (poly p, kStrategy strat )
7399{
7400 strat->redTailChange=FALSE;
7401 if (strat->noTailReduction) return p;
7402 if ((p==NULL) || (pNext(p)==NULL))
7403 return p;
7404
7405 int max_ind;
7406 poly h=p;
7407 p=pNext(p);
7408 pNext(h)=NULL;
7409 while(p!=NULL)
7410 {
7411 p=redNF(p,max_ind,1,strat);
7412 if (p!=NULL)
7413 {
7414 poly hh=p;
7415 p=pNext(p);
7416 pNext(hh)=NULL;
7417 h=p_Add_q(h,hh,currRing);
7418 }
7419 }
7420 return h;
7421}
7422
7423poly redtailBba_Ring (LObject* L, int end_pos, kStrategy strat )
7424// normalize=FALSE, withT=FALSE, coeff=Ring
7425{
7426 strat->redTailChange=FALSE;
7427 if (strat->noTailReduction) return L->GetLmCurrRing();
7428 poly h, p;
7429 p = h = L->GetLmTailRing();
7430 if ((h==NULL) || (pNext(h)==NULL))
7431 return L->GetLmCurrRing();
7432
7433 TObject* With;
7434 // placeholder in case strat->tl < 0
7435 TObject With_s(strat->tailRing);
7436
7437 LObject Ln(pNext(h), strat->tailRing);
7438 Ln.pLength = L->GetpLength() - 1;
7439
7440 pNext(h) = NULL;
7441 if (L->p != NULL) pNext(L->p) = NULL;
7442 L->pLength = 1;
7443
7444 Ln.PrepareRed(strat->use_buckets);
7445
7446 int cnt=REDTAIL_CANONICALIZE;
7447 while(!Ln.IsNull())
7448 {
7449 loop
7450 {
7451 Ln.SetShortExpVector();
7452 With_s.Init(currRing);
7453 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7454 if (With == NULL) break;
7455 cnt--;
7456 if (cnt==0)
7457 {
7459 /*poly tmp=*/Ln.CanonicalizeP();
7460 }
7461 // we are in a ring, do not call pNorm
7462 // test divisibility of coefs:
7463 poly p_Ln=Ln.GetLmCurrRing();
7464 poly p_With=With->GetLmCurrRing();
7465 if (n_DivBy(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf))
7466 {
7467 strat->redTailChange=TRUE;
7468
7469 if (ksReducePolyTail_Z(L, With, &Ln))
7470 {
7471 // reducing the tail would violate the exp bound
7472 // set a flag and hope for a retry (in bba)
7474 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7475 do
7476 {
7477 pNext(h) = Ln.LmExtractAndIter();
7478 pIter(h);
7479 L->pLength++;
7480 } while (!Ln.IsNull());
7481 goto all_done;
7482 }
7483 }
7484 else break; /*proceed to next monomial*/
7485 if (Ln.IsNull()) goto all_done;
7486 }
7487 pNext(h) = Ln.LmExtractAndIter();
7488 pIter(h);
7489 pNormalize(h);
7490 L->pLength++;
7491 }
7492
7493 all_done:
7494 Ln.Delete();
7495 if (L->p != NULL) pNext(L->p) = pNext(p);
7496
7497 if (strat->redTailChange)
7498 {
7499 L->length = 0;
7500 }
7501
7502 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7503 //L->Normalize(); // HANNES: should have a test
7504 kTest_L(L,strat);
7505 return L->GetLmCurrRing();
7506}
7507#endif
7508
7509/*2
7510*checks the change degree and write progress report
7511*/
7512void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7513{
7514 if (i != *olddeg)
7515 {
7516 Print("%d",i);
7517 *olddeg = i;
7518 }
7519 if (TEST_OPT_OLDSTD)
7520 {
7521 if (strat->Ll != *reduc)
7522 {
7523 if (strat->Ll != *reduc-1)
7524 Print("(%d)",strat->Ll+1);
7525 else
7526 PrintS("-");
7527 *reduc = strat->Ll;
7528 }
7529 else
7530 PrintS(".");
7531 mflush();
7532 }
7533 else
7534 {
7535 if (red_result == 0)
7536 PrintS("-");
7537 else if (red_result < 0)
7538 PrintS(".");
7539 if ((red_result > 0) || ((strat->Ll % 100)==99))
7540 {
7541 if (strat->Ll != *reduc && strat->Ll > 0)
7542 {
7543 Print("(%d)",strat->Ll+1);
7544 *reduc = strat->Ll;
7545 }
7546 }
7547 }
7548}
7549
7550/*2
7551*statistics
7552*/
7553void messageStat (int hilbcount,kStrategy strat)
7554{
7555 //PrintS("\nUsage/Allocation of temporary storage:\n");
7556 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7557 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7558 Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7559 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7560 #ifdef HAVE_SHIFTBBA
7561 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7562 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7563 #endif
7564}
7565
7566void messageStatSBA (int hilbcount,kStrategy strat)
7567{
7568 //PrintS("\nUsage/Allocation of temporary storage:\n");
7569 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7570 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7571 Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7572 //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7573 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7574 #ifdef HAVE_SHIFTBBA
7575 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7576 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7577 #endif
7578}
7579
7580#ifdef KDEBUG
7581/*2
7582*debugging output: all internal sets, if changed
7583*for testing purpuse only/has to be changed for later use
7584*/
7586{
7587 int i;
7588 if (strat->news)
7589 {
7590 PrintS("set S");
7591 for (i=0; i<=strat->sl; i++)
7592 {
7593 Print("\n %d:",i);
7594 p_wrp(strat->S[i], currRing, strat->tailRing);
7595 if (strat->fromQ!=NULL && strat->fromQ[i])
7596 Print(" (from Q)");
7597 }
7598 strat->news = FALSE;
7599 }
7600 if (strat->newt)
7601 {
7602 PrintS("\nset T");
7603 for (i=0; i<=strat->tl; i++)
7604 {
7605 Print("\n %d:",i);
7606 strat->T[i].wrp();
7607 if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7608 Print(" o:%ld e:%d l:%d",
7609 strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7610 }
7611 strat->newt = FALSE;
7612 }
7613 PrintS("\nset L");
7614 for (i=strat->Ll; i>=0; i--)
7615 {
7616 Print("\n%d:",i);
7617 p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7618 PrintS(" ");
7619 p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7620 PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7621 PrintS("\n p : ");
7622 strat->L[i].wrp();
7623 Print(" o:%ld e:%d l:%d",
7624 strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7625 }
7626 PrintLn();
7627}
7628
7629#endif
7630
7631
7632/*2
7633*construct the set s from F
7634*/
7635void initS (ideal F, ideal Q, kStrategy strat)
7636{
7637 int i,pos;
7638
7640 else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7641 strat->ecartS=initec(i);
7642 strat->sevS=initsevS(i);
7643 strat->S_2_R=initS_2_R(i);
7644 strat->fromQ=NULL;
7645 strat->Shdl=idInit(i,F->rank);
7646 strat->S=strat->Shdl->m;
7647 /*- put polys into S -*/
7648 if (Q!=NULL)
7649 {
7650 strat->fromQ=initec(i);
7651 memset(strat->fromQ,0,i*sizeof(int));
7652 for (i=0; i<IDELEMS(Q); i++)
7653 {
7654 if (Q->m[i]!=NULL)
7655 {
7656 LObject h;
7657 h.p = pCopy(Q->m[i]);
7659 {
7660 h.pCleardenom(); // also does remove Content
7661 }
7662 else
7663 {
7664 h.pNorm();
7665 }
7667 {
7668 deleteHC(&h, strat);
7669 }
7670 if (h.p!=NULL)
7671 {
7672 strat->initEcart(&h);
7673 if (strat->sl==-1)
7674 pos =0;
7675 else
7676 {
7677 pos = posInS(strat,strat->sl,h.p,h.ecart);
7678 }
7679 h.sev = pGetShortExpVector(h.p);
7680 strat->enterS(h,pos,strat,-1);
7681 strat->fromQ[pos]=1;
7682 }
7683 }
7684 }
7685 }
7686 for (i=0; i<IDELEMS(F); i++)
7687 {
7688 if (F->m[i]!=NULL)
7689 {
7690 LObject h;
7691 h.p = pCopy(F->m[i]);
7693 {
7694 cancelunit(&h); /*- tries to cancel a unit -*/
7695 deleteHC(&h, strat);
7696 }
7697 if (h.p!=NULL)
7698 // do not rely on the input being a SB!
7699 {
7701 {
7702 h.pCleardenom(); // also does remove Content
7703 }
7704 else
7705 {
7706 h.pNorm();
7707 }
7708 strat->initEcart(&h);
7709 if (strat->sl==-1)
7710 pos =0;
7711 else
7712 pos = posInS(strat,strat->sl,h.p,h.ecart);
7713 h.sev = pGetShortExpVector(h.p);
7714 strat->enterS(h,pos,strat,-1);
7715 }
7716 }
7717 }
7718 /*- test, if a unit is in F -*/
7719 if ((strat->sl>=0)
7720#ifdef HAVE_RINGS
7721 && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7722#endif
7723 && pIsConstant(strat->S[0]))
7724 {
7725 while (strat->sl>0) deleteInS(strat->sl,strat);
7726 }
7727}
7728
7729void initSL (ideal F, ideal Q,kStrategy strat)
7730{
7731 int i,pos;
7732
7734 else i=setmaxT;
7735 strat->ecartS=initec(i);
7736 strat->sevS=initsevS(i);
7737 strat->S_2_R=initS_2_R(i);
7738 strat->fromQ=NULL;
7739 strat->Shdl=idInit(i,F->rank);
7740 strat->S=strat->Shdl->m;
7741 /*- put polys into S -*/
7742 if (Q!=NULL)
7743 {
7744 strat->fromQ=initec(i);
7745 memset(strat->fromQ,0,i*sizeof(int));
7746 for (i=0; i<IDELEMS(Q); i++)
7747 {
7748 if (Q->m[i]!=NULL)
7749 {
7750 LObject h;
7751 h.p = pCopy(Q->m[i]);
7753 {
7754 deleteHC(&h,strat);
7755 }
7757 {
7758 h.pCleardenom(); // also does remove Content
7759 }
7760 else
7761 {
7762 h.pNorm();
7763 }
7764 if (h.p!=NULL)
7765 {
7766 strat->initEcart(&h);
7767 if (strat->sl==-1)
7768 pos =0;
7769 else
7770 {
7771 pos = posInS(strat,strat->sl,h.p,h.ecart);
7772 }
7773 h.sev = pGetShortExpVector(h.p);
7774 strat->enterS(h,pos,strat,-1);
7775 strat->fromQ[pos]=1;
7776 }
7777 }
7778 }
7779 }
7780 for (i=0; i<IDELEMS(F); i++)
7781 {
7782 if (F->m[i]!=NULL)
7783 {
7784 LObject h;
7785 h.p = pCopy(F->m[i]);
7786 if (h.p!=NULL)
7787 {
7789 {
7790 cancelunit(&h); /*- tries to cancel a unit -*/
7791 deleteHC(&h, strat);
7792 }
7793 if (h.p!=NULL)
7794 {
7796 {
7797 h.pCleardenom(); // also does remove Content
7798 }
7799 else
7800 {
7801 h.pNorm();
7802 }
7803 strat->initEcart(&h);
7804 if (strat->Ll==-1)
7805 pos =0;
7806 else
7807 pos = strat->posInL(strat->L,strat->Ll,&h,strat);
7808 h.sev = pGetShortExpVector(h.p);
7809 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7810 }
7811 }
7812 }
7813 }
7814 /*- test, if a unit is in F -*/
7815
7816 if ((strat->Ll>=0)
7817#ifdef HAVE_RINGS
7818 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7819#endif
7820 && pIsConstant(strat->L[strat->Ll].p))
7821 {
7822 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7823 }
7824}
7825
7826void initSLSba (ideal F, ideal Q,kStrategy strat)
7827{
7828 int i,pos;
7830 else i=setmaxT;
7831 strat->ecartS = initec(i);
7832 strat->sevS = initsevS(i);
7833 strat->sevSig = initsevS(i);
7834 strat->S_2_R = initS_2_R(i);
7835 strat->fromQ = NULL;
7836 strat->Shdl = idInit(i,F->rank);
7837 strat->S = strat->Shdl->m;
7838 strat->sig = (poly *)omAlloc0(i*sizeof(poly));
7839 if (strat->sbaOrder != 1)
7840 {
7841 strat->syz = (poly *)omAlloc0(i*sizeof(poly));
7842 strat->sevSyz = initsevS(i);
7843 strat->syzmax = i;
7844 strat->syzl = 0;
7845 }
7846 /*- put polys into S -*/
7847 if (Q!=NULL)
7848 {
7849 strat->fromQ=initec(i);
7850 memset(strat->fromQ,0,i*sizeof(int));
7851 for (i=0; i<IDELEMS(Q); i++)
7852 {
7853 if (Q->m[i]!=NULL)
7854 {
7855 LObject h;
7856 h.p = pCopy(Q->m[i]);
7858 {
7859 deleteHC(&h,strat);
7860 }
7862 {
7863 h.pCleardenom(); // also does remove Content
7864 }
7865 else
7866 {
7867 h.pNorm();
7868 }
7869 if (h.p!=NULL)
7870 {
7871 strat->initEcart(&h);
7872 if (strat->sl==-1)
7873 pos =0;
7874 else
7875 {
7876 pos = posInS(strat,strat->sl,h.p,h.ecart);
7877 }
7878 h.sev = pGetShortExpVector(h.p);
7879 strat->enterS(h,pos,strat,-1);
7880 strat->fromQ[pos]=1;
7881 }
7882 }
7883 }
7884 }
7885 for (i=0; i<IDELEMS(F); i++)
7886 {
7887 if (F->m[i]!=NULL)
7888 {
7889 LObject h;
7890 h.p = pCopy(F->m[i]);
7891 h.sig = pOne();
7892 //h.sig = pInit();
7893 //p_SetCoeff(h.sig,nInit(1),currRing);
7894 p_SetComp(h.sig,i+1,currRing);
7895 // if we are working with the Schreyer order we generate it
7896 // by multiplying the initial signatures with the leading monomial
7897 // of the corresponding initial polynomials generating the ideal
7898 // => we can keep the underlying monomial order and get a Schreyer
7899 // order without any bigger overhead
7900 if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
7901 {
7902 p_ExpVectorAdd (h.sig,F->m[i],currRing);
7903 }
7904 h.sevSig = pGetShortExpVector(h.sig);
7905#ifdef DEBUGF5
7906 pWrite(h.p);
7907 pWrite(h.sig);
7908#endif
7909 if (h.p!=NULL)
7910 {
7912 {
7913 cancelunit(&h); /*- tries to cancel a unit -*/
7914 deleteHC(&h, strat);
7915 }
7916 if (h.p!=NULL)
7917 {
7919 {
7920 h.pCleardenom(); // also does remove Content
7921 }
7922 else
7923 {
7924 h.pNorm();
7925 }
7926 strat->initEcart(&h);
7927 if (strat->Ll==-1)
7928 pos =0;
7929 else
7930 pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
7931 h.sev = pGetShortExpVector(h.p);
7932 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
7933 }
7934 }
7935 /*
7936 if (strat->sbaOrder != 1)
7937 {
7938 for(j=0;j<i;j++)
7939 {
7940 strat->syz[ctr] = pCopy(F->m[j]);
7941 p_SetCompP(strat->syz[ctr],i+1,currRing);
7942 // add LM(F->m[i]) to the signature to get a Schreyer order
7943 // without changing the underlying polynomial ring at all
7944 p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
7945 // since p_Add_q() destroys all input
7946 // data we need to recreate help
7947 // each time
7948 poly help = pCopy(F->m[i]);
7949 p_SetCompP(help,j+1,currRing);
7950 pWrite(strat->syz[ctr]);
7951 pWrite(help);
7952 printf("%d\n",pLmCmp(strat->syz[ctr],help));
7953 strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
7954 printf("%d. SYZ ",ctr);
7955 pWrite(strat->syz[ctr]);
7956 strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
7957 ctr++;
7958 }
7959 strat->syzl = ps;
7960 }
7961 */
7962 }
7963 }
7964 /*- test, if a unit is in F -*/
7965
7966 if ((strat->Ll>=0)
7967#ifdef HAVE_RINGS
7968 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
7969#endif
7970 && pIsConstant(strat->L[strat->Ll].p))
7971 {
7972 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
7973 }
7974}
7975
7977{
7978 if( strat->S[0] )
7979 {
7980 if( strat->S[1] && !rField_is_Ring(currRing))
7981 {
7982 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
7983 omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
7984 omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
7985 }
7986 int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
7987 /************************************************************
7988 * computing the length of the syzygy array needed
7989 ***********************************************************/
7990 for(i=1; i<=strat->sl; i++)
7991 {
7992 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
7993 {
7994 ps += i;
7995 }
7996 }
7997 ps += strat->sl+1;
7998 //comp = pGetComp (strat->P.sig);
7999 comp = strat->currIdx;
8000 strat->syzIdx = initec(comp);
8001 strat->sevSyz = initsevS(ps);
8002 strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8003 strat->syzmax = ps;
8004 strat->syzl = 0;
8005 strat->syzidxmax = comp;
8006#if defined(DEBUGF5) || defined(DEBUGF51)
8007 PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8008#endif
8009 i = 1;
8010 j = 0;
8011 /************************************************************
8012 * generating the leading terms of the principal syzygies
8013 ***********************************************************/
8014 while (i <= strat->sl)
8015 {
8016 /**********************************************************
8017 * principal syzygies start with component index 2
8018 * the array syzIdx starts with index 0
8019 * => the rules for a signature with component comp start
8020 * at strat->syz[strat->syzIdx[comp-2]] !
8021 *********************************************************/
8022 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8023 {
8024 comp = pGetComp(strat->sig[i]);
8025 comp_old = pGetComp(strat->sig[i-1]);
8026 diff = comp - comp_old - 1;
8027 // diff should be zero, but sometimes also the initial generating
8028 // elements of the input ideal reduce to zero. then there is an
8029 // index-gap between the signatures. for these in-between signatures we
8030 // can safely set syzIdx[j] = 0 as no such element will be ever computed
8031 // in the following.
8032 // doing this, we keep the relation "j = comp - 2" alive, which makes
8033 // jumps way easier when checking criteria
8034 while (diff>0)
8035 {
8036 strat->syzIdx[j] = 0;
8037 diff--;
8038 j++;
8039 }
8040 strat->syzIdx[j] = ctr;
8041 j++;
8042 LObject Q;
8043 int pos;
8044 for (k = 0; k<i; k++)
8045 {
8046 Q.sig = pOne();
8049 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8050 p_SetCompP (Q.sig, comp, currRing);
8051 poly q = p_One(currRing);
8054 p_ExpVectorCopy(q,strat->S[i],currRing);
8055 q = p_Neg (q, currRing);
8056 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8057 Q.sig = p_Add_q (Q.sig, q, currRing);
8058 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8059 pos = posInSyz(strat, Q.sig);
8060 enterSyz(Q, strat, pos);
8061 ctr++;
8062 }
8063 }
8064 i++;
8065 }
8066 /**************************************************************
8067 * add syzygies for upcoming first element of new iteration step
8068 **************************************************************/
8069 comp = strat->currIdx;
8070 comp_old = pGetComp(strat->sig[i-1]);
8071 diff = comp - comp_old - 1;
8072 // diff should be zero, but sometimes also the initial generating
8073 // elements of the input ideal reduce to zero. then there is an
8074 // index-gap between the signatures. for these in-between signatures we
8075 // can safely set syzIdx[j] = 0 as no such element will be ever computed
8076 // in the following.
8077 // doing this, we keep the relation "j = comp - 2" alive, which makes
8078 // jumps way easier when checking criteria
8079 while (diff>0)
8080 {
8081 strat->syzIdx[j] = 0;
8082 diff--;
8083 j++;
8084 }
8085 strat->syzIdx[j] = ctr;
8086 LObject Q;
8087 int pos;
8088 for (k = 0; k<strat->sl+1; k++)
8089 {
8090 Q.sig = pOne();
8093 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8094 p_SetCompP (Q.sig, comp, currRing);
8095 poly q = p_One(currRing);
8097 p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8098 p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8099 q = p_Neg (q, currRing);
8100 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8101 Q.sig = p_Add_q (Q.sig, q, currRing);
8102 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8103 pos = posInSyz(strat, Q.sig);
8104 enterSyz(Q, strat, pos);
8105 ctr++;
8106 }
8107//#if 1
8108#ifdef DEBUGF5
8109 PrintS("Principal syzygies:\n");
8110 Print("syzl %d\n",strat->syzl);
8111 Print("syzmax %d\n",strat->syzmax);
8112 Print("ps %d\n",ps);
8113 PrintS("--------------------------------\n");
8114 for(i=0;i<=strat->syzl-1;i++)
8115 {
8116 Print("%d - ",i);
8117 pWrite(strat->syz[i]);
8118 }
8119 for(i=0;i<strat->currIdx;i++)
8120 {
8121 Print("%d - %d\n",i,strat->syzIdx[i]);
8122 }
8123 PrintS("--------------------------------\n");
8124#endif
8125 }
8126}
8127
8128/*2
8129*construct the set s from F and {P}
8130*/
8131void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8132{
8133 int i,pos;
8134
8136 else i=setmaxT;
8137 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8138 strat->ecartS=initec(i);
8139 strat->sevS=initsevS(i);
8140 strat->S_2_R=initS_2_R(i);
8141 strat->fromQ=NULL;
8142 strat->Shdl=idInit(i,F->rank);
8143 strat->S=strat->Shdl->m;
8144
8145 /*- put polys into S -*/
8146 if (Q!=NULL)
8147 {
8148 strat->fromQ=initec(i);
8149 memset(strat->fromQ,0,i*sizeof(int));
8150 for (i=0; i<IDELEMS(Q); i++)
8151 {
8152 if (Q->m[i]!=NULL)
8153 {
8154 LObject h;
8155 h.p = pCopy(Q->m[i]);
8156 //if (TEST_OPT_INTSTRATEGY)
8157 //{
8158 // h.pCleardenom(); // also does remove Content
8159 //}
8160 //else
8161 //{
8162 // h.pNorm();
8163 //}
8165 {
8166 deleteHC(&h,strat);
8167 }
8168 if (h.p!=NULL)
8169 {
8170 strat->initEcart(&h);
8171 if (strat->sl==-1)
8172 pos =0;
8173 else
8174 {
8175 pos = posInS(strat,strat->sl,h.p,h.ecart);
8176 }
8177 h.sev = pGetShortExpVector(h.p);
8178 strat->enterS(h,pos,strat, strat->tl+1);
8179 enterT(h, strat);
8180 strat->fromQ[pos]=1;
8181 }
8182 }
8183 }
8184 }
8185 /*- put polys into S -*/
8186 for (i=0; i<IDELEMS(F); i++)
8187 {
8188 if (F->m[i]!=NULL)
8189 {
8190 LObject h;
8191 h.p = pCopy(F->m[i]);
8193 {
8194 deleteHC(&h,strat);
8195 }
8196 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8197 {
8198 h.p=redtailBba(h.p,strat->sl,strat);
8199 }
8200 if (h.p!=NULL)
8201 {
8202 strat->initEcart(&h);
8203 if (strat->sl==-1)
8204 pos =0;
8205 else
8206 pos = posInS(strat,strat->sl,h.p,h.ecart);
8207 h.sev = pGetShortExpVector(h.p);
8208 strat->enterS(h,pos,strat, strat->tl+1);
8209 enterT(h,strat);
8210 }
8211 }
8212 }
8213 for (i=0; i<IDELEMS(P); i++)
8214 {
8215 if (P->m[i]!=NULL)
8216 {
8217 LObject h;
8218 h.p=pCopy(P->m[i]);
8220 {
8221 h.pCleardenom();
8222 }
8223 else
8224 {
8225 h.pNorm();
8226 }
8227 if(strat->sl>=0)
8228 {
8230 {
8231 h.p=redBba(h.p,strat->sl,strat);
8232 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8233 {
8234 h.p=redtailBba(h.p,strat->sl,strat);
8235 }
8236 }
8237 else
8238 {
8239 h.p=redMora(h.p,strat->sl,strat);
8240 }
8241 if(h.p!=NULL)
8242 {
8243 strat->initEcart(&h);
8245 {
8246 h.pCleardenom();
8247 }
8248 else
8249 {
8250 h.is_normalized = 0;
8251 h.pNorm();
8252 }
8253 h.sev = pGetShortExpVector(h.p);
8254 h.SetpFDeg();
8255 pos = posInS(strat,strat->sl,h.p,h.ecart);
8256 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8257 strat->enterS(h,pos,strat, strat->tl+1);
8258 enterT(h,strat);
8259 }
8260 }
8261 else
8262 {
8263 h.sev = pGetShortExpVector(h.p);
8264 strat->initEcart(&h);
8265 strat->enterS(h,0,strat, strat->tl+1);
8266 enterT(h,strat);
8267 }
8268 }
8269 }
8270}
8271/*2
8272*construct the set s from F and {P}
8273*/
8274
8275void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8276{
8277 int i,pos;
8278
8280 else i=setmaxT;
8281 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8282 strat->sevS=initsevS(i);
8283 strat->sevSig=initsevS(i);
8284 strat->S_2_R=initS_2_R(i);
8285 strat->fromQ=NULL;
8286 strat->Shdl=idInit(i,F->rank);
8287 strat->S=strat->Shdl->m;
8288 strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8289 /*- put polys into S -*/
8290 if (Q!=NULL)
8291 {
8292 strat->fromQ=initec(i);
8293 memset(strat->fromQ,0,i*sizeof(int));
8294 for (i=0; i<IDELEMS(Q); i++)
8295 {
8296 if (Q->m[i]!=NULL)
8297 {
8298 LObject h;
8299 h.p = pCopy(Q->m[i]);
8300 //if (TEST_OPT_INTSTRATEGY)
8301 //{
8302 // h.pCleardenom(); // also does remove Content
8303 //}
8304 //else
8305 //{
8306 // h.pNorm();
8307 //}
8309 {
8310 deleteHC(&h,strat);
8311 }
8312 if (h.p!=NULL)
8313 {
8314 strat->initEcart(&h);
8315 if (strat->sl==-1)
8316 pos =0;
8317 else
8318 {
8319 pos = posInS(strat,strat->sl,h.p,h.ecart);
8320 }
8321 h.sev = pGetShortExpVector(h.p);
8322 strat->enterS(h,pos,strat, strat->tl+1);
8323 enterT(h, strat);
8324 strat->fromQ[pos]=1;
8325 }
8326 }
8327 }
8328 }
8329 /*- put polys into S -*/
8330 for (i=0; i<IDELEMS(F); i++)
8331 {
8332 if (F->m[i]!=NULL)
8333 {
8334 LObject h;
8335 h.p = pCopy(F->m[i]);
8337 {
8338 deleteHC(&h,strat);
8339 }
8340 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8341 {
8342 h.p=redtailBba(h.p,strat->sl,strat);
8343 }
8344 if (h.p!=NULL)
8345 {
8346 strat->initEcart(&h);
8347 if (strat->sl==-1)
8348 pos =0;
8349 else
8350 pos = posInS(strat,strat->sl,h.p,h.ecart);
8351 h.sev = pGetShortExpVector(h.p);
8352 strat->enterS(h,pos,strat, strat->tl+1);
8353 enterT(h,strat);
8354 }
8355 }
8356 }
8357 for (i=0; i<IDELEMS(P); i++)
8358 {
8359 if (P->m[i]!=NULL)
8360 {
8361 LObject h;
8362 h.p=pCopy(P->m[i]);
8364 {
8365 h.pCleardenom();
8366 }
8367 else
8368 {
8369 h.pNorm();
8370 }
8371 if(strat->sl>=0)
8372 {
8374 {
8375 h.p=redBba(h.p,strat->sl,strat);
8376 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8377 {
8378 h.p=redtailBba(h.p,strat->sl,strat);
8379 }
8380 }
8381 else
8382 {
8383 h.p=redMora(h.p,strat->sl,strat);
8384 }
8385 if(h.p!=NULL)
8386 {
8387 strat->initEcart(&h);
8389 {
8390 h.pCleardenom();
8391 }
8392 else
8393 {
8394 h.is_normalized = 0;
8395 h.pNorm();
8396 }
8397 h.sev = pGetShortExpVector(h.p);
8398 h.SetpFDeg();
8399 pos = posInS(strat,strat->sl,h.p,h.ecart);
8400 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8401 strat->enterS(h,pos,strat, strat->tl+1);
8402 enterT(h,strat);
8403 }
8404 }
8405 else
8406 {
8407 h.sev = pGetShortExpVector(h.p);
8408 strat->initEcart(&h);
8409 strat->enterS(h,0,strat, strat->tl+1);
8410 enterT(h,strat);
8411 }
8412 }
8413 }
8414}
8415
8416/*2
8417* reduces h using the set S
8418* procedure used in cancelunit1
8419*/
8420static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8421{
8422 int j = 0;
8423 unsigned long not_sev = ~ pGetShortExpVector(h);
8424
8425 while (j <= maxIndex)
8426 {
8427 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8428 return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8429 else j++;
8430 }
8431 return h;
8432}
8433
8434/*2
8435*tests if p.p=monomial*unit and cancels the unit
8436*/
8437void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8438{
8439 int k;
8440 poly r,h,h1,q;
8441
8442 if (!pIsVector((*p).p) && ((*p).ecart != 0))
8443 {
8444#ifdef HAVE_RINGS
8445 // Leading coef have to be a unit: no
8446 // example 2x+4x2 should be simplified to 2x*(1+2x)
8447 // and 2 is not a unit in Z
8448 //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8449#endif
8450 k = 0;
8451 h1 = r = pCopy((*p).p);
8452 h =pNext(r);
8453 loop
8454 {
8455 if (h==NULL)
8456 {
8457 pDelete(&r);
8458 pDelete(&(pNext((*p).p)));
8459 (*p).ecart = 0;
8460 (*p).length = 1;
8461 (*p).pLength = 1;
8462 (*suc)=0;
8463 return;
8464 }
8465 if (!pDivisibleBy(r,h))
8466 {
8467 q=redBba1(h,index ,strat);
8468 if (q != h)
8469 {
8470 k++;
8471 pDelete(&h);
8472 pNext(h1) = h = q;
8473 }
8474 else
8475 {
8476 pDelete(&r);
8477 return;
8478 }
8479 }
8480 else
8481 {
8482 h1 = h;
8483 pIter(h);
8484 }
8485 if (k > 10)
8486 {
8487 pDelete(&r);
8488 return;
8489 }
8490 }
8491 }
8492}
8493
8494#if 0
8495/*2
8496* reduces h using the elements from Q in the set S
8497* procedure used in updateS
8498* must not be used for elements of Q or elements of an ideal !
8499*/
8500static poly redQ (poly h, int j, kStrategy strat)
8501{
8502 int start;
8503 unsigned long not_sev = ~ pGetShortExpVector(h);
8504 while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8505 start=j;
8506 while (j<=strat->sl)
8507 {
8508 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8509 {
8510 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8511 if (h==NULL) return NULL;
8512 j = start;
8513 not_sev = ~ pGetShortExpVector(h);
8514 }
8515 else j++;
8516 }
8517 return h;
8518}
8519#endif
8520
8521/*2
8522* reduces h using the set S
8523* procedure used in updateS
8524*/
8525static poly redBba (poly h,int maxIndex,kStrategy strat)
8526{
8527 int j = 0;
8528 unsigned long not_sev = ~ pGetShortExpVector(h);
8529
8530 while (j <= maxIndex)
8531 {
8532 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8533 {
8534 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8535 if (h==NULL) return NULL;
8536 j = 0;
8537 not_sev = ~ pGetShortExpVector(h);
8538 }
8539 else j++;
8540 }
8541 return h;
8542}
8543
8544/*2
8545* reduces h using the set S
8546*e is the ecart of h
8547*procedure used in updateS
8548*/
8549static poly redMora (poly h,int maxIndex,kStrategy strat)
8550{
8551 int j=0;
8552 int e,l;
8553 unsigned long not_sev = ~ pGetShortExpVector(h);
8554
8555 if (maxIndex >= 0)
8556 {
8557 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8558 do
8559 {
8560 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8561 && ((e >= strat->ecartS[j]) || (strat->kNoether!=NULL)))
8562 {
8563#ifdef KDEBUG
8564 if (TEST_OPT_DEBUG)
8565 {
8566 PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8567 }
8568#endif
8569 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8570#ifdef KDEBUG
8571 if(TEST_OPT_DEBUG)
8572 {
8573 PrintS(")\nto "); wrp(h); PrintLn();
8574 }
8575#endif
8576 // pDelete(&h);
8577 if (h == NULL) return NULL;
8578 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8579 j = 0;
8580 not_sev = ~ pGetShortExpVector(h);
8581 }
8582 else j++;
8583 }
8584 while (j <= maxIndex);
8585 }
8586 return h;
8587}
8588
8589/*2
8590*updates S:
8591*the result is a set of polynomials which are in
8592*normalform with respect to S
8593*/
8595{
8596 LObject h;
8597 int i, suc=0;
8598 poly redSi=NULL;
8599 BOOLEAN change,any_change;
8600// Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8601// for (i=0; i<=(strat->sl); i++)
8602// {
8603// Print("s%d:",i);
8604// if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8605// pWrite(strat->S[i]);
8606// }
8607// Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8608 any_change=FALSE;
8610 {
8611 while (suc != -1)
8612 {
8613 i=suc+1;
8614 while (i<=strat->sl)
8615 {
8616 change=FALSE;
8618 any_change = FALSE;
8619 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8620 {
8621 redSi = pHead(strat->S[i]);
8622 strat->S[i] = redBba(strat->S[i],i-1,strat);
8623 //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8624 // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8625 if (pCmp(redSi,strat->S[i])!=0)
8626 {
8627 change=TRUE;
8628 any_change=TRUE;
8629 #ifdef KDEBUG
8630 if (TEST_OPT_DEBUG)
8631 {
8632 PrintS("reduce:");
8633 wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8634 }
8635 #endif
8636 if (TEST_OPT_PROT)
8637 {
8638 if (strat->S[i]==NULL)
8639 PrintS("V");
8640 else
8641 PrintS("v");
8642 mflush();
8643 }
8644 }
8645 pLmDelete(&redSi);
8646 if (strat->S[i]==NULL)
8647 {
8648 deleteInS(i,strat);
8649 i--;
8650 }
8651 else if (change)
8652 {
8654 {
8656 {
8657 number n;
8658 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8659 if (!nIsOne(n))
8660 {
8662 denom->n=nInvers(n);
8663 denom->next=DENOMINATOR_LIST;
8664 DENOMINATOR_LIST=denom;
8665 }
8666 nDelete(&n);
8667 }
8668 else
8669 {
8670 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8671 }
8672 }
8673 else
8674 {
8675 pNorm(strat->S[i]);
8676 }
8677 strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8678 }
8679 }
8680 i++;
8681 }
8682 if (any_change) reorderS(&suc,strat);
8683 else break;
8684 }
8685 if (toT)
8686 {
8687 for (i=0; i<=strat->sl; i++)
8688 {
8689 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8690 {
8691 h.p = redtailBba(strat->S[i],i-1,strat);
8693 {
8694 h.pCleardenom();// also does remove Content
8695 }
8696 }
8697 else
8698 {
8699 h.p = strat->S[i];
8700 }
8701 strat->initEcart(&h);
8702 if (strat->honey)
8703 {
8704 strat->ecartS[i] = h.ecart;
8705 }
8706 if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8707 else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8708 h.sev = strat->sevS[i];
8709 /*puts the elements of S also to T*/
8710 strat->initEcart(&h);
8711 /*if (toT) - already checked*/ enterT(h,strat);
8712 strat->S_2_R[i] = strat->tl;
8713#ifdef HAVE_SHIFTBBA
8714 if (/*(toT) && */(currRing->isLPring))
8715 enterTShift(h, strat);
8716#endif
8717 }
8718 }
8719 }
8720 else
8721 {
8722 while (suc != -1)
8723 {
8724 i=suc;
8725 while (i<=strat->sl)
8726 {
8727 change=FALSE;
8728 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8729 {
8730 redSi=pHead((strat->S)[i]);
8731 (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
8732 if ((strat->S)[i]==NULL)
8733 {
8734 deleteInS(i,strat);
8735 i--;
8736 }
8737 else if (pCmp((strat->S)[i],redSi)!=0)
8738 {
8739 any_change=TRUE;
8740 h.p = strat->S[i];
8741 strat->initEcart(&h);
8742 strat->ecartS[i] = h.ecart;
8744 {
8746 {
8747 number n;
8748 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8749 if (!nIsOne(n))
8750 {
8752 denom->n=nInvers(n);
8753 denom->next=DENOMINATOR_LIST;
8754 DENOMINATOR_LIST=denom;
8755 }
8756 nDelete(&n);
8757 }
8758 else
8759 {
8760 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8761 }
8762 }
8763 else
8764 {
8765 pNorm(strat->S[i]); // == h.p
8766 }
8767 h.sev = pGetShortExpVector(h.p);
8768 strat->sevS[i] = h.sev;
8769 }
8770 pLmDelete(&redSi);
8771 kTest(strat);
8772 }
8773 i++;
8774 }
8775#ifdef KDEBUG
8776 kTest(strat);
8777#endif
8778 if (any_change) reorderS(&suc,strat);
8779 else { suc=-1; break; }
8780 if (h.p!=NULL)
8781 {
8782 if (!strat->kAllAxis)
8783 {
8784 /*strat->kAllAxis =*/ HEckeTest(h.p,strat);
8785 }
8786 if (strat->kAllAxis)
8787 newHEdge(strat);
8788 }
8789 }
8790 for (i=0; i<=strat->sl; i++)
8791 {
8792 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8793 {
8794 strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
8795 strat->initEcart(&h);
8796 strat->ecartS[i] = h.ecart;
8797 h.sev = pGetShortExpVector(h.p);
8798 strat->sevS[i] = h.sev;
8799 }
8800 else
8801 {
8802 h.p = strat->S[i];
8803 h.ecart=strat->ecartS[i];
8804 h.sev = strat->sevS[i];
8805 h.length = h.pLength = pLength(h.p);
8806 }
8807 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8808 cancelunit1(&h,&suc,strat->sl,strat);
8809 h.SetpFDeg();
8810 /*puts the elements of S also to T*/
8811 enterT(h,strat);
8812 strat->S_2_R[i] = strat->tl;
8813#ifdef HAVE_SHIFTBBA
8814 if (currRing->isLPring)
8815 enterTShift(h, strat);
8816#endif
8817 }
8818 if (suc!= -1) updateS(toT,strat);
8819 }
8820#ifdef KDEBUG
8821 kTest(strat);
8822#endif
8823}
8824
8825/*2
8826* -puts p to the standardbasis s at position at
8827* -saves the result in S
8828*/
8829void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
8830{
8831 strat->news = TRUE;
8832 /*- puts p to the standardbasis s at position at -*/
8833 if (strat->sl == IDELEMS(strat->Shdl)-1)
8834 {
8835 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8836 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8837 (IDELEMS(strat->Shdl)+setmaxTinc)
8838 *sizeof(unsigned long));
8839 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8840 IDELEMS(strat->Shdl)*sizeof(int),
8841 (IDELEMS(strat->Shdl)+setmaxTinc)
8842 *sizeof(int));
8843 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8844 IDELEMS(strat->Shdl)*sizeof(int),
8845 (IDELEMS(strat->Shdl)+setmaxTinc)
8846 *sizeof(int));
8847 if (strat->lenS!=NULL)
8848 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8849 IDELEMS(strat->Shdl)*sizeof(int),
8850 (IDELEMS(strat->Shdl)+setmaxTinc)
8851 *sizeof(int));
8852 if (strat->lenSw!=NULL)
8853 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8854 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8855 (IDELEMS(strat->Shdl)+setmaxTinc)
8856 *sizeof(wlen_type));
8857 if (strat->fromQ!=NULL)
8858 {
8859 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8860 IDELEMS(strat->Shdl)*sizeof(int),
8861 (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
8862 }
8863 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
8864 IDELEMS(strat->Shdl)+=setmaxTinc;
8865 strat->Shdl->m=strat->S;
8866 }
8867 if (atS <= strat->sl)
8868 {
8869#ifdef ENTER_USE_MEMMOVE
8870 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
8871 (strat->sl - atS + 1)*sizeof(poly));
8872 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
8873 (strat->sl - atS + 1)*sizeof(int));
8874 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
8875 (strat->sl - atS + 1)*sizeof(unsigned long));
8876 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
8877 (strat->sl - atS + 1)*sizeof(int));
8878 if (strat->lenS!=NULL)
8879 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
8880 (strat->sl - atS + 1)*sizeof(int));
8881 if (strat->lenSw!=NULL)
8882 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
8883 (strat->sl - atS + 1)*sizeof(wlen_type));
8884#else
8885 for (i=strat->sl+1; i>=atS+1; i--)
8886 {
8887 strat->S[i] = strat->S[i-1];
8888 strat->ecartS[i] = strat->ecartS[i-1];
8889 strat->sevS[i] = strat->sevS[i-1];
8890 strat->S_2_R[i] = strat->S_2_R[i-1];
8891 }
8892 if (strat->lenS!=NULL)
8893 for (i=strat->sl+1; i>=atS+1; i--)
8894 strat->lenS[i] = strat->lenS[i-1];
8895 if (strat->lenSw!=NULL)
8896 for (i=strat->sl+1; i>=atS+1; i--)
8897 strat->lenSw[i] = strat->lenSw[i-1];
8898#endif
8899 }
8900 if (strat->fromQ!=NULL)
8901 {
8902#ifdef ENTER_USE_MEMMOVE
8903 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
8904 (strat->sl - atS + 1)*sizeof(int));
8905#else
8906 for (i=strat->sl+1; i>=atS+1; i--)
8907 {
8908 strat->fromQ[i] = strat->fromQ[i-1];
8909 }
8910#endif
8911 strat->fromQ[atS]=0;
8912 }
8913
8914 /*- save result -*/
8915 poly pp=p.p;
8916 strat->S[atS] = pp;
8917 if (strat->honey) strat->ecartS[atS] = p.ecart;
8918 if (p.sev == 0)
8919 p.sev = pGetShortExpVector(pp);
8920 else
8921 assume(p.sev == pGetShortExpVector(pp));
8922 strat->sevS[atS] = p.sev;
8923 strat->ecartS[atS] = p.ecart;
8924 strat->S_2_R[atS] = atR;
8925 strat->sl++;
8926}
8927
8928#ifdef HAVE_SHIFTBBA
8929void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR)
8930{
8931 enterSBba(p, atS, strat, atR);
8932
8933 int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
8934 for (int i = maxPossibleShift; i > 0; i--)
8935 {
8936 // NOTE: don't use "shared tails" here. In rare cases it can cause problems
8937 // in `kNF2` because of lazy poly normalizations.
8938 LObject qq(p_Copy(p.p, strat->tailRing));
8939 p_mLPshift(qq.p, i, strat->tailRing);
8940 qq.shift = i;
8941 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
8942 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
8943 enterSBba(qq, atS, strat, -1);
8944 }
8945}
8946#endif
8947
8948/*2
8949* -puts p to the standardbasis s at position at
8950* -saves the result in S
8951*/
8952void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
8953{
8954 strat->news = TRUE;
8955 /*- puts p to the standardbasis s at position at -*/
8956 if (strat->sl == IDELEMS(strat->Shdl)-1)
8957 {
8958 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
8959 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8960 (IDELEMS(strat->Shdl)+setmax)
8961 *sizeof(unsigned long));
8962 strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
8963 IDELEMS(strat->Shdl)*sizeof(unsigned long),
8964 (IDELEMS(strat->Shdl)+setmax)
8965 *sizeof(unsigned long));
8966 strat->ecartS = (intset)omReallocSize(strat->ecartS,
8967 IDELEMS(strat->Shdl)*sizeof(int),
8968 (IDELEMS(strat->Shdl)+setmax)
8969 *sizeof(int));
8970 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
8971 IDELEMS(strat->Shdl)*sizeof(int),
8972 (IDELEMS(strat->Shdl)+setmax)
8973 *sizeof(int));
8974 if (strat->lenS!=NULL)
8975 strat->lenS=(int*)omRealloc0Size(strat->lenS,
8976 IDELEMS(strat->Shdl)*sizeof(int),
8977 (IDELEMS(strat->Shdl)+setmax)
8978 *sizeof(int));
8979 if (strat->lenSw!=NULL)
8980 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
8981 IDELEMS(strat->Shdl)*sizeof(wlen_type),
8982 (IDELEMS(strat->Shdl)+setmax)
8983 *sizeof(wlen_type));
8984 if (strat->fromQ!=NULL)
8985 {
8986 strat->fromQ = (intset)omReallocSize(strat->fromQ,
8987 IDELEMS(strat->Shdl)*sizeof(int),
8988 (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
8989 }
8990 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
8991 pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
8992 IDELEMS(strat->Shdl)+=setmax;
8993 strat->Shdl->m=strat->S;
8994 }
8995 // in a signature-based algorithm the following situation will never
8996 // appear due to the fact that the critical pairs are already sorted
8997 // by increasing signature.
8998 // True. However, in the case of integers we need to put the element
8999 // that caused the signature drop on the first position
9000 if (atS <= strat->sl)
9001 {
9002#ifdef ENTER_USE_MEMMOVE
9003 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9004 (strat->sl - atS + 1)*sizeof(poly));
9005 memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9006 (strat->sl - atS + 1)*sizeof(poly));
9007 memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9008 (strat->sl - atS + 1)*sizeof(unsigned long));
9009 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9010 (strat->sl - atS + 1)*sizeof(int));
9011 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9012 (strat->sl - atS + 1)*sizeof(unsigned long));
9013 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9014 (strat->sl - atS + 1)*sizeof(int));
9015 if (strat->lenS!=NULL)
9016 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9017 (strat->sl - atS + 1)*sizeof(int));
9018 if (strat->lenSw!=NULL)
9019 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9020 (strat->sl - atS + 1)*sizeof(wlen_type));
9021#else
9022 for (i=strat->sl+1; i>=atS+1; i--)
9023 {
9024 strat->S[i] = strat->S[i-1];
9025 strat->ecartS[i] = strat->ecartS[i-1];
9026 strat->sevS[i] = strat->sevS[i-1];
9027 strat->S_2_R[i] = strat->S_2_R[i-1];
9028 strat->sig[i] = strat->sig[i-1];
9029 strat->sevSig[i] = strat->sevSig[i-1];
9030 }
9031 if (strat->lenS!=NULL)
9032 for (i=strat->sl+1; i>=atS+1; i--)
9033 strat->lenS[i] = strat->lenS[i-1];
9034 if (strat->lenSw!=NULL)
9035 for (i=strat->sl+1; i>=atS+1; i--)
9036 strat->lenSw[i] = strat->lenSw[i-1];
9037#endif
9038 }
9039 if (strat->fromQ!=NULL)
9040 {
9041#ifdef ENTER_USE_MEMMOVE
9042 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9043 (strat->sl - atS + 1)*sizeof(int));
9044#else
9045 for (i=strat->sl+1; i>=atS+1; i--)
9046 {
9047 strat->fromQ[i] = strat->fromQ[i-1];
9048 }
9049#endif
9050 strat->fromQ[atS]=0;
9051 }
9052
9053 /*- save result -*/
9054 strat->S[atS] = p.p;
9055 strat->sig[atS] = p.sig; // TODO: get the correct signature in here!
9056 if (strat->honey) strat->ecartS[atS] = p.ecart;
9057 if (p.sev == 0)
9058 p.sev = pGetShortExpVector(p.p);
9059 else
9060 assume(p.sev == pGetShortExpVector(p.p));
9061 strat->sevS[atS] = p.sev;
9062 // during the interreduction process of a signature-based algorithm we do not
9063 // compute the signature at this point, but when the whole interreduction
9064 // process finishes, i.e. f5c terminates!
9065 if (p.sig != NULL)
9066 {
9067 if (p.sevSig == 0)
9068 p.sevSig = pGetShortExpVector(p.sig);
9069 else
9070 assume(p.sevSig == pGetShortExpVector(p.sig));
9071 strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9072 }
9073 strat->ecartS[atS] = p.ecart;
9074 strat->S_2_R[atS] = atR;
9075 strat->sl++;
9076#ifdef DEBUGF5
9077 int k;
9078 Print("--- LIST S: %d ---\n",strat->sl);
9079 for(k=0;k<=strat->sl;k++)
9080 {
9081 pWrite(strat->sig[k]);
9082 }
9083 PrintS("--- LIST S END ---\n");
9084#endif
9085}
9086
9088{
9089 p.GetP(strat->lmBin);
9090 if (strat->homog) strat->initEcart(&p);
9091 strat->redTailChange=FALSE;
9093 {
9094 p.pCleardenom();
9096 {
9097#ifdef HAVE_SHIFTBBA
9098 if (rIsLPRing(currRing))
9099 p.p = redtailBba(&p,strat->tl,strat, TRUE,!TEST_OPT_CONTENTSB);
9100 else
9101#endif
9102 {
9103 p.p = redtailBba(&p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9104 }
9105 p.pCleardenom();
9106 if (strat->redTailChange)
9107 p.t_p=NULL;
9108 if (strat->P.p!=NULL) strat->P.sev=p_GetShortExpVector(strat->P.p,currRing);
9109 else strat->P.sev=0;
9110 }
9111 }
9112
9113 assume(strat->tailRing == p.tailRing);
9114 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9115
9116 int i, j, pos;
9117 poly tp = strat->T[tj].p;
9118
9119 /* enter p to T set */
9120 enterT(p, strat);
9121
9122 for (j = 0; j <= strat->sl; ++j)
9123 {
9124 if (pLtCmp(tp, strat->S[j]) == 0)
9125 {
9126 break;
9127 }
9128 }
9129 /* it may be that the exchanged element
9130 * is until now only in T and not in S */
9131 if (j <= strat->sl)
9132 {
9133 deleteInS(j, strat);
9134 }
9135
9136 pos = posInS(strat, strat->sl, p.p, p.ecart);
9137
9138 pp_Test(p.p, currRing, p.tailRing);
9139 assume(p.FDeg == p.pFDeg());
9140
9141 /* remove useless pairs from L set */
9142 for (i = 0; i <= strat->Ll; ++i)
9143 {
9144 if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0)
9145 {
9146 deleteInL(strat->L, &(strat->Ll), i, strat);
9147 i--;
9148 continue;
9149 }
9150 if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0)
9151 {
9152 deleteInL(strat->L, &(strat->Ll), i, strat);
9153 i--;
9154 }
9155 }
9156#ifdef HAVE_SHIFTBBA
9157 if (rIsLPRing(currRing))
9158 enterpairsShift(p.p, strat->sl, p.ecart, pos, strat, strat->tl); // TODO LP
9159 else
9160#endif
9161 {
9162 /* generate new pairs with p, probably removing older, now useless pairs */
9163 superenterpairs(p.p, strat->sl, p.ecart, pos, strat, strat->tl);
9164 }
9165 /* enter p to S set */
9166 strat->enterS(p, pos, strat, strat->tl);
9167
9168#ifdef HAVE_SHIFTBBA
9169 /* do this after enterS so that the index in R (which is strat->tl) is correct */
9170 if (rIsLPRing(currRing) && !strat->rightGB)
9171 enterTShift(p,strat);
9172#endif
9173}
9174
9175/*2
9176* puts p to the set T at position atT
9177*/
9178void enterT(LObject &p, kStrategy strat, int atT)
9179{
9180 int i;
9181
9182#ifdef PDEBUG
9183#ifdef HAVE_SHIFTBBA
9184 if (currRing->isLPring && p.shift > 0)
9185 {
9186 // in this case, the order is not correct. test LM and tail separately
9187 p_LmTest(p.p, currRing);
9188 p_Test(pNext(p.p), currRing);
9189 }
9190 else
9191#endif
9192 {
9193 pp_Test(p.p, currRing, p.tailRing);
9194 }
9195#endif
9196 assume(strat->tailRing == p.tailRing);
9197 // redMoraNF complains about this -- but, we don't really
9198 // need this so far
9199 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9200 assume(!strat->homog || (p.FDeg == p.pFDeg()));
9201 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9202
9203#ifdef KDEBUG
9204 // do not put an LObject twice into T:
9205 for(i=strat->tl;i>=0;i--)
9206 {
9207 if (p.p==strat->T[i].p)
9208 {
9209 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9210 return;
9211 }
9212 }
9213#endif
9214
9215#ifdef HAVE_TAIL_RING
9216 if (currRing!=strat->tailRing)
9217 {
9218 p.t_p=p.GetLmTailRing();
9219 }
9220#endif
9221 strat->newt = TRUE;
9222 if (atT < 0)
9223 atT = strat->posInT(strat->T, strat->tl, p);
9224 if (strat->tl == strat->tmax-1)
9225 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9226 if (atT <= strat->tl)
9227 {
9228#ifdef ENTER_USE_MEMMOVE
9229 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9230 (strat->tl-atT+1)*sizeof(TObject));
9231 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9232 (strat->tl-atT+1)*sizeof(unsigned long));
9233#endif
9234 for (i=strat->tl+1; i>=atT+1; i--)
9235 {
9236#ifndef ENTER_USE_MEMMOVE
9237 strat->T[i] = strat->T[i-1];
9238 strat->sevT[i] = strat->sevT[i-1];
9239#endif
9240 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9241 }
9242 }
9243
9244 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9245 {
9246#ifdef HAVE_SHIFTBBA
9247 // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9248 if (!(currRing->isLPring && p.shift > 0))
9249#endif
9250 {
9252 (strat->tailRing != NULL ?
9253 strat->tailRing : currRing),
9254 strat->tailBin);
9255 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9256 }
9257 }
9258 strat->T[atT] = (TObject) p;
9259 //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9260
9261 if ((pNext(p.p) != NULL) && (!rIsLPRing(currRing)))
9262 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9263 else
9264 strat->T[atT].max_exp = NULL;
9265
9266 strat->tl++;
9267 strat->R[strat->tl] = &(strat->T[atT]);
9268 strat->T[atT].i_r = strat->tl;
9269 assume((p.sev == 0) || (pGetShortExpVector(p.p) == p.sev));
9270 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9271 kTest_T(&(strat->T[atT]),strat);
9272}
9273
9274/*2
9275* puts p to the set T at position atT
9276*/
9277#ifdef HAVE_RINGS
9278void enterT_strong(LObject &p, kStrategy strat, int atT)
9279{
9281 int i;
9282
9283 pp_Test(p.p, currRing, p.tailRing);
9284 assume(strat->tailRing == p.tailRing);
9285 // redMoraNF complains about this -- but, we don't really
9286 // need this so far
9287 assume(p.pLength == 0 || (int)pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9288 assume(p.FDeg == p.pFDeg());
9289 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9290
9291#ifdef KDEBUG
9292 // do not put an LObject twice into T:
9293 for(i=strat->tl;i>=0;i--)
9294 {
9295 if (p.p==strat->T[i].p)
9296 {
9297 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9298 return;
9299 }
9300 }
9301#endif
9302
9303#ifdef HAVE_TAIL_RING
9304 if (currRing!=strat->tailRing)
9305 {
9306 p.t_p=p.GetLmTailRing();
9307 }
9308#endif
9309 strat->newt = TRUE;
9310 if (atT < 0)
9311 atT = strat->posInT(strat->T, strat->tl, p);
9312 if (strat->tl == strat->tmax-1)
9313 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9314 if (atT <= strat->tl)
9315 {
9316#ifdef ENTER_USE_MEMMOVE
9317 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9318 (strat->tl-atT+1)*sizeof(TObject));
9319 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9320 (strat->tl-atT+1)*sizeof(unsigned long));
9321#endif
9322 for (i=strat->tl+1; i>=atT+1; i--)
9323 {
9324#ifndef ENTER_USE_MEMMOVE
9325 strat->T[i] = strat->T[i-1];
9326 strat->sevT[i] = strat->sevT[i-1];
9327#endif
9328 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9329 }
9330 }
9331
9332 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9333 {
9335 (strat->tailRing != NULL ?
9336 strat->tailRing : currRing),
9337 strat->tailBin);
9338 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9339 }
9340 strat->T[atT] = (TObject) p;
9341 //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9342
9343 if (pNext(p.p) != NULL)
9344 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9345 else
9346 strat->T[atT].max_exp = NULL;
9347
9348 strat->tl++;
9349 strat->R[strat->tl] = &(strat->T[atT]);
9350 strat->T[atT].i_r = strat->tl;
9351 assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9352 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9353 #if 1
9355 && !n_IsUnit(p.p->coef, currRing->cf))
9356 {
9357 for(i=strat->tl;i>=0;i--)
9358 {
9359 if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9360 {
9361 enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9362 }
9363 }
9364 }
9365 /*
9366 printf("\nThis is T:\n");
9367 for(i=strat->tl;i>=0;i--)
9368 {
9369 pWrite(strat->T[i].p);
9370 }
9371 //getchar();*/
9372 #endif
9373 kTest_T(&(strat->T[atT]),strat);
9374}
9375#endif
9376
9377/*2
9378* puts signature p.sig to the set syz
9379*/
9380void enterSyz(LObject &p, kStrategy strat, int atT)
9381{
9382 int i;
9383 strat->newt = TRUE;
9384 if (strat->syzl == strat->syzmax-1)
9385 {
9386 pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9387 strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9388 (strat->syzmax)*sizeof(unsigned long),
9389 ((strat->syzmax)+setmax)
9390 *sizeof(unsigned long));
9391 strat->syzmax += setmax;
9392 }
9393 if (atT < strat->syzl)
9394 {
9395#ifdef ENTER_USE_MEMMOVE
9396 memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9397 (strat->syzl-atT+1)*sizeof(poly));
9398 memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9399 (strat->syzl-atT+1)*sizeof(unsigned long));
9400#endif
9401 for (i=strat->syzl; i>=atT+1; i--)
9402 {
9403#ifndef ENTER_USE_MEMMOVE
9404 strat->syz[i] = strat->syz[i-1];
9405 strat->sevSyz[i] = strat->sevSyz[i-1];
9406#endif
9407 }
9408 }
9409 //i = strat->syzl;
9410 i = atT;
9411 //Makes sure the syz saves just the signature
9412 #ifdef HAVE_RINGS
9414 pNext(p.sig) = NULL;
9415 #endif
9416 strat->syz[atT] = p.sig;
9417 strat->sevSyz[atT] = p.sevSig;
9418 strat->syzl++;
9419#if F5DEBUG
9420 Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9421 pWrite(strat->syz[atT]);
9422#endif
9423 // recheck pairs in strat->L with new rule and delete correspondingly
9424 int cc = strat->Ll;
9425 while (cc>-1)
9426 {
9427 //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9428 //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);
9429 if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9430 strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9431 #ifdef HAVE_RINGS
9433 || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9434 #endif
9435 )
9436 {
9437 //printf("\nYES!\n");
9438 deleteInL(strat->L,&strat->Ll,cc,strat);
9439 }
9440 cc--;
9441 }
9442//#if 1
9443#ifdef DEBUGF5
9444 PrintS("--- Syzygies ---\n");
9445 Print("syzl %d\n",strat->syzl);
9446 Print("syzmax %d\n",strat->syzmax);
9447 PrintS("--------------------------------\n");
9448 for(i=0;i<=strat->syzl-1;i++)
9449 {
9450 Print("%d - ",i);
9451 pWrite(strat->syz[i]);
9452 }
9453 PrintS("--------------------------------\n");
9454#endif
9455}
9456
9457
9458void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9459{
9460
9461 //if the ordering is local, then hilb criterion
9462 //can be used also if the ideal is not homogeneous
9464 {
9466 *hilb=NULL;
9467 else
9468 return;
9469 }
9470 if (strat->homog!=isHomog)
9471 {
9472 *hilb=NULL;
9473 }
9474}
9475
9477{
9480 if (TEST_OPT_SB_1)
9482#ifdef HAVE_RINGS
9484 {
9486 strat->chainCrit=chainCritRing;
9487 }
9488#endif
9489#ifdef HAVE_RATGRING
9490 if (rIsRatGRing(currRing))
9491 {
9492 strat->chainCrit=chainCritPart;
9493 /* enterOnePairNormal get rational part in it */
9494 }
9495#endif
9496 if (TEST_OPT_IDLIFT
9497 && (strat->syzComp==1)
9498 && (!rIsPluralRing(currRing)))
9500
9502 strat->Gebauer = strat->homog || strat->sugarCrit;
9503 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9504 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9505 strat->pairtest = NULL;
9506 /* always use tailreduction, except:
9507 * - in local rings, - in lex order case, -in ring over extensions */
9509 //if(rHasMixedOrdering(currRing)==2)
9510 //{
9511 // strat->noTailReduction =TRUE;
9512 //}
9513
9514#ifdef HAVE_PLURAL
9515 // and r is plural_ring
9516 // hence this holds for r a rational_plural_ring
9517 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9518 { //or it has non-quasi-comm type... later
9519 strat->sugarCrit = FALSE;
9520 strat->Gebauer = FALSE;
9521 strat->honey = FALSE;
9522 }
9523#endif
9524
9525 // Coefficient ring?
9527 {
9528 strat->sugarCrit = FALSE;
9529 strat->Gebauer = FALSE;
9530 strat->honey = FALSE;
9531 }
9532 #ifdef KDEBUG
9533 if (TEST_OPT_DEBUG)
9534 {
9535 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9536 else PrintS("ideal/module is not homogeneous\n");
9537 }
9538 #endif
9539}
9540
9542{
9543 //strat->enterOnePair=enterOnePairNormal;
9545 //strat->chainCrit=chainCritNormal;
9546 strat->chainCrit = chainCritSig;
9547 /******************************************
9548 * rewCrit1 and rewCrit2 are already set in
9549 * kSba() in kstd1.cc
9550 *****************************************/
9551 //strat->rewCrit1 = faugereRewCriterion;
9552 if (strat->sbaOrder == 1)
9553 {
9554 strat->syzCrit = syzCriterionInc;
9555 }
9556 else
9557 {
9558 strat->syzCrit = syzCriterion;
9559 }
9560#ifdef HAVE_RINGS
9562 {
9564 strat->chainCrit=chainCritRing;
9565 }
9566#endif
9567#ifdef HAVE_RATGRING
9568 if (rIsRatGRing(currRing))
9569 {
9570 strat->chainCrit=chainCritPart;
9571 /* enterOnePairNormal get rational part in it */
9572 }
9573#endif
9574
9576 strat->Gebauer = strat->homog || strat->sugarCrit;
9577 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9578 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9579 strat->pairtest = NULL;
9580 /* always use tailreduction, except:
9581 * - in local rings, - in lex order case, -in ring over extensions */
9584
9585#ifdef HAVE_PLURAL
9586 // and r is plural_ring
9587 // hence this holds for r a rational_plural_ring
9588 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9589 { //or it has non-quasi-comm type... later
9590 strat->sugarCrit = FALSE;
9591 strat->Gebauer = FALSE;
9592 strat->honey = FALSE;
9593 }
9594#endif
9595
9596 // Coefficient ring?
9598 {
9599 strat->sugarCrit = FALSE;
9600 strat->Gebauer = FALSE ;
9601 strat->honey = FALSE;
9602 }
9603 #ifdef KDEBUG
9604 if (TEST_OPT_DEBUG)
9605 {
9606 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9607 else PrintS("ideal/module is not homogeneous\n");
9608 }
9609 #endif
9610}
9611
9613 (const LSet set, const int length,
9614 LObject* L,const kStrategy strat))
9615{
9616 if (pos_in_l == posInL110
9617 || pos_in_l == posInL10
9618 #ifdef HAVE_RINGS
9619 || pos_in_l == posInL110Ring
9620 #endif
9621 )
9622 return TRUE;
9623
9624 return FALSE;
9625}
9626
9628{
9630 {
9631 if (strat->honey)
9632 {
9633 strat->posInL = posInL15;
9634 // ok -- here is the deal: from my experiments for Singular-2-0
9635 // I conclude that that posInT_EcartpLength is the best of
9636 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9637 // see the table at the end of this file
9638 if (TEST_OPT_OLDSTD)
9639 strat->posInT = posInT15;
9640 else
9641 strat->posInT = posInT_EcartpLength;
9642 }
9643 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9644 {
9645 strat->posInL = posInL11;
9646 strat->posInT = posInT11;
9647 }
9648 else if (TEST_OPT_INTSTRATEGY)
9649 {
9650 strat->posInL = posInL11;
9651 strat->posInT = posInT11;
9652 }
9653 else
9654 {
9655 strat->posInL = posInL0;
9656 strat->posInT = posInT0;
9657 }
9658 //if (strat->minim>0) strat->posInL =posInLSpecial;
9659 if (strat->homog)
9660 {
9661 strat->posInL = posInL110;
9662 strat->posInT = posInT110;
9663 }
9664 }
9665 else /* local/mixed ordering */
9666 {
9667 if (strat->homog)
9668 {
9669 strat->posInL = posInL11;
9670 strat->posInT = posInT11;
9671 }
9672 else
9673 {
9674 if ((currRing->order[0]==ringorder_c)
9675 ||(currRing->order[0]==ringorder_C))
9676 {
9677 strat->posInL = posInL17_c;
9678 strat->posInT = posInT17_c;
9679 }
9680 else
9681 {
9682 strat->posInL = posInL17;
9683 strat->posInT = posInT17;
9684 }
9685 }
9686 }
9687 if (strat->minim>0) strat->posInL =posInLSpecial;
9688 // for further tests only
9689 if ((BTEST1(11)) || (BTEST1(12)))
9690 strat->posInL = posInL11;
9691 else if ((BTEST1(13)) || (BTEST1(14)))
9692 strat->posInL = posInL13;
9693 else if ((BTEST1(15)) || (BTEST1(16)))
9694 strat->posInL = posInL15;
9695 else if ((BTEST1(17)) || (BTEST1(18)))
9696 strat->posInL = posInL17;
9697 if (BTEST1(11))
9698 strat->posInT = posInT11;
9699 else if (BTEST1(13))
9700 strat->posInT = posInT13;
9701 else if (BTEST1(15))
9702 strat->posInT = posInT15;
9703 else if ((BTEST1(17)))
9704 strat->posInT = posInT17;
9705 else if ((BTEST1(19)))
9706 strat->posInT = posInT19;
9707 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9708 strat->posInT = posInT1;
9710}
9711
9712#ifdef HAVE_RINGS
9714{
9716 {
9717 if (strat->honey)
9718 {
9719 strat->posInL = posInL15Ring;
9720 // ok -- here is the deal: from my experiments for Singular-2-0
9721 // I conclude that that posInT_EcartpLength is the best of
9722 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9723 // see the table at the end of this file
9724 if (TEST_OPT_OLDSTD)
9725 strat->posInT = posInT15Ring;
9726 else
9727 strat->posInT = posInT_EcartpLength;
9728 }
9729 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9730 {
9731 strat->posInL = posInL11Ring;
9732 strat->posInT = posInT11;
9733 }
9734 else if (TEST_OPT_INTSTRATEGY)
9735 {
9736 strat->posInL = posInL11Ring;
9737 strat->posInT = posInT11;
9738 }
9739 else
9740 {
9741 strat->posInL = posInL0Ring;
9742 strat->posInT = posInT0;
9743 }
9744 //if (strat->minim>0) strat->posInL =posInLSpecial;
9745 if (strat->homog)
9746 {
9747 strat->posInL = posInL110Ring;
9748 strat->posInT = posInT110Ring;
9749 }
9750 }
9751 else
9752 {
9753 if (strat->homog)
9754 {
9755 //printf("\nHere 3\n");
9756 strat->posInL = posInL11Ring;
9757 strat->posInT = posInT11Ring;
9758 }
9759 else
9760 {
9761 if ((currRing->order[0]==ringorder_c)
9762 ||(currRing->order[0]==ringorder_C))
9763 {
9764 strat->posInL = posInL17_cRing;
9765 strat->posInT = posInT17_cRing;
9766 }
9767 else
9768 {
9769 strat->posInL = posInL11Ringls;
9770 strat->posInT = posInT17Ring;
9771 }
9772 }
9773 }
9774 if (strat->minim>0) strat->posInL =posInLSpecial;
9775 // for further tests only
9776 if ((BTEST1(11)) || (BTEST1(12)))
9777 strat->posInL = posInL11Ring;
9778 else if ((BTEST1(13)) || (BTEST1(14)))
9779 strat->posInL = posInL13;
9780 else if ((BTEST1(15)) || (BTEST1(16)))
9781 strat->posInL = posInL15Ring;
9782 else if ((BTEST1(17)) || (BTEST1(18)))
9783 strat->posInL = posInL17Ring;
9784 if (BTEST1(11))
9785 strat->posInT = posInT11Ring;
9786 else if (BTEST1(13))
9787 strat->posInT = posInT13;
9788 else if (BTEST1(15))
9789 strat->posInT = posInT15Ring;
9790 else if ((BTEST1(17)))
9791 strat->posInT = posInT17Ring;
9792 else if ((BTEST1(19)))
9793 strat->posInT = posInT19;
9794 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9795 strat->posInT = posInT1;
9797}
9798#endif
9799
9800void initBuchMora (ideal F,ideal Q,kStrategy strat)
9801{
9802 strat->interpt = BTEST1(OPT_INTERRUPT);
9803 /*- creating temp data structures------------------- -*/
9804 //strat->cp = 0; // already by skStragy()
9805 //strat->c3 = 0; // already by skStragy()
9806#ifdef HAVE_SHIFTBBA
9807 strat->cv = 0; // already by skStragy()
9808#endif
9809 strat->tail = pInit();
9810 /*- set s -*/
9811 strat->sl = -1;
9812 /*- set L -*/
9813 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
9814 strat->Ll = -1;
9815 strat->L = initL(strat->Lmax);
9816 /*- set B -*/
9817 strat->Bmax = setmaxL;
9818 strat->Bl = -1;
9819 strat->B = initL();
9820 /*- set T -*/
9821 strat->tl = -1;
9822 strat->tmax = setmaxT;
9823 strat->T = initT();
9824 strat->R = initR();
9825 strat->sevT = initsevT();
9826 /*- init local data struct.---------------------------------------- -*/
9827 //strat->P.ecart=0; // already by skStragy()
9828 //strat->P.length=0; // already by skStragy()
9829 //strat->P.pLength=0; // already by skStragy()
9831 {
9832 if (strat->kNoether!=NULL)
9833 {
9834 pSetComp(strat->kNoether, strat->ak);
9835 pSetComp(strat->kNoetherTail(), strat->ak);
9836 }
9837 }
9839 {
9840 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9841 }
9842 else
9843 {
9844 if(TEST_OPT_SB_1)
9845 {
9846 int i;
9847 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
9848 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9849 {
9850 P->m[i-strat->newIdeal] = F->m[i];
9851 F->m[i] = NULL;
9852 }
9853 initSSpecial(F,Q,P,strat);
9854 for (i=strat->newIdeal;i<IDELEMS(F);i++)
9855 {
9856 F->m[i] = P->m[i-strat->newIdeal];
9857 P->m[i-strat->newIdeal] = NULL;
9858 }
9859 idDelete(&P);
9860 }
9861 else
9862 {
9863 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
9864 // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
9865 }
9866 }
9867 strat->fromT = FALSE;
9869 if ((!TEST_OPT_SB_1)
9871 )
9872 {
9873 updateS(TRUE,strat);
9874 }
9875#ifdef HAVE_SHIFTBBA
9876 if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
9877#endif
9878 {
9879 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9880 strat->fromQ=NULL;
9881 }
9882 assume(kTest_TS(strat));
9883}
9884
9886{
9887 /*- release temp data -*/
9888 cleanT(strat);
9889 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
9890 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
9891 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
9892 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
9893 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
9894 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
9895 /*- set L: should be empty -*/
9896 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
9897 /*- set B: should be empty -*/
9898 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
9899 pLmFree(&strat->tail);
9900 strat->syzComp=0;
9901
9902#ifdef HAVE_SHIFTBBA
9903 if (rIsLPRing(currRing) && strat->rightGB)
9904 {
9905 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
9906 strat->fromQ=NULL;
9907 }
9908#endif
9909}
9910
9912{
9914 {
9915 if (strat->honey)
9916 {
9917 strat->posInL = posInL15;
9918 // ok -- here is the deal: from my experiments for Singular-2-0
9919 // I conclude that that posInT_EcartpLength is the best of
9920 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9921 // see the table at the end of this file
9922 if (TEST_OPT_OLDSTD)
9923 strat->posInT = posInT15;
9924 else
9925 strat->posInT = posInT_EcartpLength;
9926 }
9927 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9928 {
9929 strat->posInL = posInL11;
9930 strat->posInT = posInT11;
9931 }
9932 else if (TEST_OPT_INTSTRATEGY)
9933 {
9934 strat->posInL = posInL11;
9935 strat->posInT = posInT11;
9936 }
9937 else
9938 {
9939 strat->posInL = posInL0;
9940 strat->posInT = posInT0;
9941 }
9942 //if (strat->minim>0) strat->posInL =posInLSpecial;
9943 if (strat->homog)
9944 {
9945 strat->posInL = posInL110;
9946 strat->posInT = posInT110;
9947 }
9948 }
9949 else
9950 {
9951 if (strat->homog)
9952 {
9953 strat->posInL = posInL11;
9954 strat->posInT = posInT11;
9955 }
9956 else
9957 {
9958 if ((currRing->order[0]==ringorder_c)
9959 ||(currRing->order[0]==ringorder_C))
9960 {
9961 strat->posInL = posInL17_c;
9962 strat->posInT = posInT17_c;
9963 }
9964 else
9965 {
9966 strat->posInL = posInL17;
9967 strat->posInT = posInT17;
9968 }
9969 }
9970 }
9971 if (strat->minim>0) strat->posInL =posInLSpecial;
9972 // for further tests only
9973 if ((BTEST1(11)) || (BTEST1(12)))
9974 strat->posInL = posInL11;
9975 else if ((BTEST1(13)) || (BTEST1(14)))
9976 strat->posInL = posInL13;
9977 else if ((BTEST1(15)) || (BTEST1(16)))
9978 strat->posInL = posInL15;
9979 else if ((BTEST1(17)) || (BTEST1(18)))
9980 strat->posInL = posInL17;
9981 if (BTEST1(11))
9982 strat->posInT = posInT11;
9983 else if (BTEST1(13))
9984 strat->posInT = posInT13;
9985 else if (BTEST1(15))
9986 strat->posInT = posInT15;
9987 else if ((BTEST1(17)))
9988 strat->posInT = posInT17;
9989 else if ((BTEST1(19)))
9990 strat->posInT = posInT19;
9991 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9992 strat->posInT = posInT1;
9994 {
9995 strat->posInL = posInL11Ring;
9996 if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
9997 strat->posInL = posInL11Ringls;
9998 strat->posInT = posInT11;
9999 }
10001 strat->posInLSba = posInLSig;
10002 //strat->posInL = posInLSig;
10003 strat->posInL = posInLF5C;
10004 /*
10005 if (rField_is_Ring(currRing))
10006 {
10007 strat->posInLSba = posInLSigRing;
10008 strat->posInL = posInL11Ring;
10009 }*/
10010 //strat->posInT = posInTSig;
10011}
10012
10013void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10014{
10015 strat->interpt = BTEST1(OPT_INTERRUPT);
10016 //strat->kNoether=NULL; // done by skStrategy
10017 /*- creating temp data structures------------------- -*/
10018 //strat->cp = 0; // done by skStrategy
10019 //strat->c3 = 0; // done by skStrategy
10020 strat->tail = pInit();
10021 /*- set s -*/
10022 strat->sl = -1;
10023 /*- set ps -*/
10024 strat->syzl = -1;
10025 /*- set L -*/
10026 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10027 strat->Ll = -1;
10028 strat->L = initL(strat->Lmax);
10029 /*- set B -*/
10030 strat->Bmax = setmaxL;
10031 strat->Bl = -1;
10032 strat->B = initL();
10033 /*- set T -*/
10034 strat->tl = -1;
10035 strat->tmax = setmaxT;
10036 strat->T = initT();
10037 strat->R = initR();
10038 strat->sevT = initsevT();
10039 /*- init local data struct.---------------------------------------- -*/
10040 //strat->P.ecart=0; // done by skStrategy
10041 //strat->P.length=0; // done by skStrategy
10043 {
10044 if (strat->kNoether!=NULL)
10045 {
10046 pSetComp(strat->kNoether, strat->ak);
10047 pSetComp(strat->kNoetherTail(), strat->ak);
10048 }
10049 }
10051 {
10052 /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10053 }
10054 else
10055 {
10056 if(TEST_OPT_SB_1)
10057 {
10058 int i;
10059 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10060 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10061 {
10062 P->m[i-strat->newIdeal] = F->m[i];
10063 F->m[i] = NULL;
10064 }
10065 initSSpecialSba(F,Q,P,strat);
10066 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10067 {
10068 F->m[i] = P->m[i-strat->newIdeal];
10069 P->m[i-strat->newIdeal] = NULL;
10070 }
10071 idDelete(&P);
10072 }
10073 else
10074 {
10075 initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10076 }
10077 }
10078 //strat->fromT = FALSE; // done by skStrategy
10079 if (!TEST_OPT_SB_1)
10080 {
10081 if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10082 }
10083 //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10084 //strat->fromQ=NULL;
10085 assume(kTest_TS(strat));
10086}
10087
10088void exitSba (kStrategy strat)
10089{
10090 /*- release temp data -*/
10092 cleanTSbaRing(strat);
10093 else
10094 cleanT(strat);
10095 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10096 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10097 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10098 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10099 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10100 omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10101 if(strat->syzmax>0)
10102 {
10103 omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10104 omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10105 if (strat->sbaOrder == 1)
10106 {
10107 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10108 }
10109 }
10110 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10111 /*- set L: should be empty -*/
10112 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10113 /*- set B: should be empty -*/
10114 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10115 /*- set sig: no need for the signatures anymore -*/
10116 omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10117 pLmDelete(&strat->tail);
10118 strat->syzComp=0;
10119}
10120
10121/*2
10122* in the case of a standardbase of a module over a qring:
10123* replace polynomials in i by ak vectors,
10124* (the polynomial * unit vectors gen(1)..gen(ak)
10125* in every case (also for ideals:)
10126* deletes divisible vectors/polynomials
10127*/
10128void updateResult(ideal r,ideal Q, kStrategy strat)
10129{
10130 int l;
10131 if (strat->ak>0)
10132 {
10133 for (l=IDELEMS(r)-1;l>=0;l--)
10134 {
10135 if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10136 {
10137 pDelete(&r->m[l]); // and set it to NULL
10138 }
10139 }
10140 int q;
10141 poly p;
10143 {
10144 for (l=IDELEMS(r)-1;l>=0;l--)
10145 {
10146 if ((r->m[l]!=NULL)
10147 //&& (strat->syzComp>0)
10148 //&& (pGetComp(r->m[l])<=strat->syzComp)
10149 )
10150 {
10151 for(q=IDELEMS(Q)-1; q>=0;q--)
10152 {
10153 if ((Q->m[q]!=NULL)
10154 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10155 {
10156 if (TEST_OPT_REDSB)
10157 {
10158 p=r->m[l];
10159 r->m[l]=kNF(Q,NULL,p);
10160 pDelete(&p);
10161 }
10162 else
10163 {
10164 pDelete(&r->m[l]); // and set it to NULL
10165 }
10166 break;
10167 }
10168 }
10169 }
10170 }
10171 }
10172 #ifdef HAVE_RINGS
10173 else
10174 {
10175 for (l=IDELEMS(r)-1;l>=0;l--)
10176 {
10177 if ((r->m[l]!=NULL)
10178 //&& (strat->syzComp>0)
10179 //&& (pGetComp(r->m[l])<=strat->syzComp)
10180 )
10181 {
10182 for(q=IDELEMS(Q)-1; q>=0;q--)
10183 {
10184 if ((Q->m[q]!=NULL)
10185 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10186 {
10187 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10188 {
10189 if (TEST_OPT_REDSB)
10190 {
10191 p=r->m[l];
10192 r->m[l]=kNF(Q,NULL,p);
10193 pDelete(&p);
10194 }
10195 else
10196 {
10197 pDelete(&r->m[l]); // and set it to NULL
10198 }
10199 break;
10200 }
10201 }
10202 }
10203 }
10204 }
10205 }
10206 #endif
10207 }
10208 else
10209 {
10210 int q;
10211 poly p;
10212 BOOLEAN reduction_found=FALSE;
10214 {
10215 for (l=IDELEMS(r)-1;l>=0;l--)
10216 {
10217 if (r->m[l]!=NULL)
10218 {
10219 for(q=IDELEMS(Q)-1; q>=0;q--)
10220 {
10221 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10222 {
10223 if (TEST_OPT_REDSB)
10224 {
10225 p=r->m[l];
10226 r->m[l]=kNF(Q,NULL,p);
10227 pDelete(&p);
10228 reduction_found=TRUE;
10229 }
10230 else
10231 {
10232 pDelete(&r->m[l]); // and set it to NULL
10233 }
10234 break;
10235 }
10236 }
10237 }
10238 }
10239 }
10240 #ifdef HAVE_RINGS
10241 //Also need divisibility of the leading coefficients
10242 else
10243 {
10244 for (l=IDELEMS(r)-1;l>=0;l--)
10245 {
10246 if (r->m[l]!=NULL)
10247 {
10248 for(q=IDELEMS(Q)-1; q>=0;q--)
10249 {
10250 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10251 {
10252 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10253 {
10254 if (TEST_OPT_REDSB)
10255 {
10256 p=r->m[l];
10257 r->m[l]=kNF(Q,NULL,p);
10258 pDelete(&p);
10259 reduction_found=TRUE;
10260 }
10261 else
10262 {
10263 pDelete(&r->m[l]); // and set it to NULL
10264 }
10265 break;
10266 }
10267 }
10268 }
10269 }
10270 }
10271 }
10272 #endif
10273 if (/*TEST_OPT_REDSB &&*/ reduction_found)
10274 {
10275 #ifdef HAVE_RINGS
10277 {
10278 for (l=IDELEMS(r)-1;l>=0;l--)
10279 {
10280 if (r->m[l]!=NULL)
10281 {
10282 for(q=IDELEMS(r)-1;q>=0;q--)
10283 {
10284 if ((l!=q)
10285 && (r->m[q]!=NULL)
10286 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10287 &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10288 )
10289 {
10290 //If they are equal then take the one with the smallest length
10291 if(pLmDivisibleBy(r->m[q],r->m[l])
10292 && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10293 && (pLength(r->m[q]) < pLength(r->m[l]) ||
10294 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10295 {
10296 pDelete(&r->m[l]);
10297 break;
10298 }
10299 else
10300 pDelete(&r->m[q]);
10301 }
10302 }
10303 }
10304 }
10305 }
10306 else
10307 #endif
10308 {
10309 for (l=IDELEMS(r)-1;l>=0;l--)
10310 {
10311 if (r->m[l]!=NULL)
10312 {
10313 for(q=IDELEMS(r)-1;q>=0;q--)
10314 {
10315 if ((l!=q)
10316 && (r->m[q]!=NULL)
10317 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10318 )
10319 {
10320 //If they are equal then take the one with the smallest length
10321 if(pLmDivisibleBy(r->m[q],r->m[l])
10322 &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10323 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10324 {
10325 pDelete(&r->m[l]);
10326 break;
10327 }
10328 else
10329 pDelete(&r->m[q]);
10330 }
10331 }
10332 }
10333 }
10334 }
10335 }
10336 }
10337 idSkipZeroes(r);
10338}
10339
10341{
10342 int i;
10343 int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10344 LObject L;
10345
10346#ifdef KDEBUG
10347 // need to set this: during tailreductions of T[i], T[i].max is out of
10348 // sync
10349 sloppy_max = TRUE;
10350#endif
10351
10352 strat->noTailReduction = FALSE;
10353 //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10354 if (TEST_OPT_PROT)
10355 {
10356 PrintLn();
10357// if (timerv) writeTime("standard base computed:");
10358 }
10359 if (TEST_OPT_PROT)
10360 {
10361 Print("(S:%d)",strat->sl);mflush();
10362 }
10363 for (i=strat->sl; i>=low; i--)
10364 {
10365 int end_pos=strat->sl;
10366 if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10367 if (strat->ak==0) end_pos=i-1;
10368 TObject* T_j = strat->s_2_t(i);
10369 if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10370 {
10371 L = *T_j;
10372 #ifdef KDEBUG
10373 if (TEST_OPT_DEBUG)
10374 {
10375 Print("test S[%d]:",i);
10376 p_wrp(L.p,currRing,strat->tailRing);
10377 PrintLn();
10378 }
10379 #endif
10381 strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10382 else
10383 strat->S[i] = redtail(&L, strat->sl, strat);
10384 #ifdef KDEBUG
10385 if (TEST_OPT_DEBUG)
10386 {
10387 Print("to (tailR) S[%d]:",i);
10388 p_wrp(strat->S[i],currRing,strat->tailRing);
10389 PrintLn();
10390 }
10391 #endif
10392
10393 if (strat->redTailChange)
10394 {
10395 if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10396 if (pNext(T_j->p) != NULL)
10397 T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10398 else
10399 T_j->max_exp = NULL;
10400 }
10402 T_j->pCleardenom();
10403 }
10404 else
10405 {
10406 assume(currRing == strat->tailRing);
10407 #ifdef KDEBUG
10408 if (TEST_OPT_DEBUG)
10409 {
10410 Print("test S[%d]:",i);
10411 p_wrp(strat->S[i],currRing,strat->tailRing);
10412 PrintLn();
10413 }
10414 #endif
10416 strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10417 else
10418 strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10420 {
10422 {
10423 number n;
10424 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10425 if (!nIsOne(n))
10426 {
10428 denom->n=nInvers(n);
10429 denom->next=DENOMINATOR_LIST;
10430 DENOMINATOR_LIST=denom;
10431 }
10432 nDelete(&n);
10433 }
10434 else
10435 {
10436 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10437 }
10438 }
10439 #ifdef KDEBUG
10440 if (TEST_OPT_DEBUG)
10441 {
10442 Print("to (-tailR) S[%d]:",i);
10443 p_wrp(strat->S[i],currRing,strat->tailRing);
10444 PrintLn();
10445 }
10446 #endif
10447 }
10448 if (TEST_OPT_PROT)
10449 PrintS("-");
10450 }
10451 if (TEST_OPT_PROT) PrintLn();
10452#ifdef KDEBUG
10453 sloppy_max = FALSE;
10454#endif
10455}
10456
10457
10458/*2
10459* computes the new strat->kNoether and the new pNoether,
10460* returns TRUE, if pNoether has changed
10461*/
10463{
10464 if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10465 return FALSE;
10466 int i,j;
10467 poly newNoether;
10468
10469#if 0
10470 if (currRing->weight_all_1)
10471 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10472 else
10473 scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kNoether);
10474#else
10475 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10476#endif
10477 if (strat->kNoether==NULL) return FALSE;
10478 if (strat->t_kNoether != NULL)
10479 {
10480 p_LmFree(strat->t_kNoether, strat->tailRing);
10481 strat->t_kNoether=NULL;
10482 }
10483 if (strat->tailRing != currRing)
10485 /* compare old and new noether*/
10486 newNoether = pLmInit(strat->kNoether);
10487 pSetCoeff0(newNoether,nInit(1));
10488 j = p_FDeg(newNoether,currRing);
10489 for (i=1; i<=(currRing->N); i++)
10490 {
10491 if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
10492 }
10493 pSetm(newNoether);
10494 if (j < HCord) /*- statistics -*/
10495 {
10496 if (TEST_OPT_PROT)
10497 {
10498 Print("H(%d)",j);
10499 mflush();
10500 }
10501 HCord=j;
10502 #ifdef KDEBUG
10503 if (TEST_OPT_DEBUG)
10504 {
10505 Print("H(%d):",j);
10506 wrp(strat->kNoether);
10507 PrintLn();
10508 }
10509 #endif
10510 }
10511 if (pCmp(strat->kNoether,newNoether)!=1)
10512 {
10513 if (strat->kNoether!=NULL) p_LmDelete0(strat->kNoether,currRing);
10514 strat->kNoether=newNoether;
10515 if (strat->t_kNoether != NULL)
10516 {
10517 p_LmFree(strat->t_kNoether, strat->tailRing);
10518 strat->t_kNoether=NULL;
10519 }
10520 if (strat->tailRing != currRing)
10522
10523 return TRUE;
10524 }
10525 pLmDelete(newNoether);
10526 return FALSE;
10527}
10528
10529/***************************************************************
10530 *
10531 * Routines related for ring changes during std computations
10532 *
10533 ***************************************************************/
10534BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10535{
10536 if (strat->overflow) return FALSE;
10537 assume(L->p1 != NULL && L->p2 != NULL);
10538 // shift changes: from 0 to -1
10539 assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10540 assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10541
10542 if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10543 return FALSE;
10544 // shift changes: extra case inserted
10545 if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10546 {
10547 return TRUE;
10548 }
10549 poly p1_max=NULL;
10550 if ((L->i_r1>=0)&&(strat->R[L->i_r1]!=NULL)) p1_max = (strat->R[L->i_r1])->max_exp;
10551 poly p2_max=NULL;
10552 if ((L->i_r2>=0)&&(strat->R[L->i_r2]!=NULL)) p2_max = (strat->R[L->i_r2])->max_exp;
10553
10554 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10555 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10556 {
10557 p_LmFree(m1, strat->tailRing);
10558 p_LmFree(m2, strat->tailRing);
10559 m1 = NULL;
10560 m2 = NULL;
10561 return FALSE;
10562 }
10563 return TRUE;
10564}
10565
10566#ifdef HAVE_RINGS
10567/***************************************************************
10568 *
10569 * Checks, if we can compute the gcd poly / strong pair
10570 * gcd-poly = m1 * R[atR] + m2 * S[atS]
10571 *
10572 ***************************************************************/
10573BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10574{
10575 assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10576 //assume(strat->tailRing != currRing);
10577
10578 poly p1_max = (strat->R[atR])->max_exp;
10579 poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10580
10581 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10582 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10583 {
10584 return FALSE;
10585 }
10586 return TRUE;
10587}
10588#endif
10589
10590#ifdef HAVE_RINGS
10591/*!
10592 used for GB over ZZ: look for constant and monomial elements in the ideal
10593 background: any known constant element of ideal suppresses
10594 intermediate coefficient swell
10595*/
10596poly preIntegerCheck(const ideal Forig, const ideal Q)
10597{
10598 if(!nCoeff_is_Z(currRing->cf))
10599 return NULL;
10600 ideal F = idCopy(Forig);
10601 idSkipZeroes(F);
10602 poly pmon;
10603 ring origR = currRing;
10604 ideal monred = idInit(1,1);
10605 for(int i=0; i<idElem(F); i++)
10606 {
10607 if(pNext(F->m[i]) == NULL)
10608 idInsertPoly(monred, pCopy(F->m[i]));
10609 }
10610 int posconst = idPosConstant(F);
10611 if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10612 {
10613 idDelete(&F);
10614 idDelete(&monred);
10615 return NULL;
10616 }
10617 int idelemQ = 0;
10618 if(Q!=NULL)
10619 {
10620 idelemQ = IDELEMS(Q);
10621 for(int i=0; i<idelemQ; i++)
10622 {
10623 if(pNext(Q->m[i]) == NULL)
10624 idInsertPoly(monred, pCopy(Q->m[i]));
10625 }
10626 idSkipZeroes(monred);
10627 posconst = idPosConstant(monred);
10628 //the constant, if found, will be from Q
10629 if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10630 {
10631 pmon = pCopy(monred->m[posconst]);
10632 idDelete(&F);
10633 idDelete(&monred);
10634 return pmon;
10635 }
10636 }
10637 ring QQ_ring = rCopy0(currRing,FALSE);
10638 nKillChar(QQ_ring->cf);
10639 QQ_ring->cf = nInitChar(n_Q, NULL);
10640 rComplete(QQ_ring,1);
10641 QQ_ring = rAssure_c_dp(QQ_ring);
10642 rChangeCurrRing(QQ_ring);
10643 nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10644 ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10645 for(int i = 0, j = 0; i<IDELEMS(F); i++)
10646 II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10647 for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10648 II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10649 ideal one = kStd(II, NULL, isNotHomog, NULL);
10650 idSkipZeroes(one);
10651 if(idIsConstant(one))
10652 {
10653 //one should be <1>
10654 for(int i = IDELEMS(II)-1; i>=0; i--)
10655 if(II->m[i] != NULL)
10656 II->m[i+1] = II->m[i];
10657 II->m[0] = pOne();
10658 ideal syz = idSyzygies(II, isNotHomog, NULL);
10659 poly integer = NULL;
10660 for(int i = IDELEMS(syz)-1;i>=0; i--)
10661 {
10662 if(pGetComp(syz->m[i]) == 1)
10663 {
10664 pSetComp(syz->m[i],0);
10665 if(pIsConstant(pHead(syz->m[i])))
10666 {
10667 integer = pHead(syz->m[i]);
10668 break;
10669 }
10670 }
10671 }
10672 rChangeCurrRing(origR);
10673 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10674 pmon = prMapR(integer, nMap2, QQ_ring, origR);
10675 idDelete(&monred);
10676 idDelete(&F);
10677 id_Delete(&II,QQ_ring);
10678 id_Delete(&one,QQ_ring);
10679 id_Delete(&syz,QQ_ring);
10680 p_Delete(&integer,QQ_ring);
10681 rDelete(QQ_ring);
10682 return pmon;
10683 }
10684 else
10685 {
10686 if(idIs0(monred))
10687 {
10688 poly mindegmon = NULL;
10689 for(int i = 0; i<IDELEMS(one); i++)
10690 {
10691 if(pNext(one->m[i]) == NULL)
10692 {
10693 if(mindegmon == NULL)
10694 mindegmon = pCopy(one->m[i]);
10695 else
10696 {
10697 if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10698 mindegmon = pCopy(one->m[i]);
10699 }
10700 }
10701 }
10702 if(mindegmon != NULL)
10703 {
10704 for(int i = IDELEMS(II)-1; i>=0; i--)
10705 if(II->m[i] != NULL)
10706 II->m[i+1] = II->m[i];
10707 II->m[0] = pCopy(mindegmon);
10708 ideal syz = idSyzygies(II, isNotHomog, NULL);
10709 bool found = FALSE;
10710 for(int i = IDELEMS(syz)-1;i>=0; i--)
10711 {
10712 if(pGetComp(syz->m[i]) == 1)
10713 {
10714 pSetComp(syz->m[i],0);
10715 if(pIsConstant(pHead(syz->m[i])))
10716 {
10717 pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10718 found = TRUE;
10719 break;
10720 }
10721 }
10722 }
10723 id_Delete(&syz,QQ_ring);
10724 if (found == FALSE)
10725 {
10726 rChangeCurrRing(origR);
10727 idDelete(&monred);
10728 idDelete(&F);
10729 id_Delete(&II,QQ_ring);
10730 id_Delete(&one,QQ_ring);
10731 rDelete(QQ_ring);
10732 return NULL;
10733 }
10734 rChangeCurrRing(origR);
10735 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10736 pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
10737 idDelete(&monred);
10738 idDelete(&F);
10739 id_Delete(&II,QQ_ring);
10740 id_Delete(&one,QQ_ring);
10741 id_Delete(&syz,QQ_ring);
10742 rDelete(QQ_ring);
10743 return pmon;
10744 }
10745 }
10746 }
10747 rChangeCurrRing(origR);
10748 idDelete(&monred);
10749 idDelete(&F);
10750 id_Delete(&II,QQ_ring);
10751 id_Delete(&one,QQ_ring);
10752 rDelete(QQ_ring);
10753 return NULL;
10754}
10755#endif
10756
10757#ifdef HAVE_RINGS
10758/*!
10759 used for GB over ZZ: intermediate reduction by monomial elements
10760 background: any known constant element of ideal suppresses
10761 intermediate coefficient swell
10762*/
10764{
10765 if(!nCoeff_is_Z(currRing->cf))
10766 return;
10767 poly pH = h->GetP();
10768 poly p,pp;
10769 p = pH;
10770 bool deleted = FALSE, ok = FALSE;
10771 for(int i = 0; i<=strat->sl; i++)
10772 {
10773 p = pH;
10774 if(pNext(strat->S[i]) == NULL)
10775 {
10776 //pWrite(p);
10777 //pWrite(strat->S[i]);
10778 while(ok == FALSE && p != NULL)
10779 {
10780 if(pLmDivisibleBy(strat->S[i], p)
10781#ifdef HAVE_SHIFTBBA
10782 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], p))
10783#endif
10784 )
10785 {
10786 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10787 p_SetCoeff(p,dummy,currRing);
10788 }
10789 if(nIsZero(p->coef))
10790 {
10791 pLmDelete(&p);
10792 h->p = p;
10793 deleted = TRUE;
10794 }
10795 else
10796 {
10797 ok = TRUE;
10798 }
10799 }
10800 if (p!=NULL)
10801 {
10802 pp = pNext(p);
10803 while(pp != NULL)
10804 {
10805 if(pLmDivisibleBy(strat->S[i], pp)
10806#ifdef HAVE_SHIFTBBA
10807 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], pp))
10808#endif
10809 )
10810 {
10811 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10812 p_SetCoeff(pp,dummy,currRing);
10813 if(nIsZero(pp->coef))
10814 {
10815 pLmDelete(&pNext(p));
10816 pp = pNext(p);
10817 deleted = TRUE;
10818 }
10819 else
10820 {
10821 p = pp;
10822 pp = pNext(p);
10823 }
10824 }
10825 else
10826 {
10827 p = pp;
10828 pp = pNext(p);
10829 }
10830 }
10831 }
10832 }
10833 }
10834 h->SetLmCurrRing();
10835 if((deleted)&&(h->p!=NULL))
10836 strat->initEcart(h);
10837}
10838
10840{
10841 if(!nCoeff_is_Z(currRing->cf))
10842 return;
10843 poly hSig = h->sig;
10844 poly pH = h->GetP();
10845 poly p,pp;
10846 p = pH;
10847 bool deleted = FALSE, ok = FALSE;
10848 for(int i = 0; i<=strat->sl; i++)
10849 {
10850 p = pH;
10851 if(pNext(strat->S[i]) == NULL)
10852 {
10853 while(ok == FALSE && p!=NULL)
10854 {
10855 if(pLmDivisibleBy(strat->S[i], p))
10856 {
10857 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10858 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10859 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10860 {
10861 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
10862 p_SetCoeff(p,dummy,currRing);
10863 }
10864 pDelete(&sigMult);
10865 }
10866 if(nIsZero(p->coef))
10867 {
10868 pLmDelete(&p);
10869 h->p = p;
10870 deleted = TRUE;
10871 }
10872 else
10873 {
10874 ok = TRUE;
10875 }
10876 }
10877 if(p == NULL)
10878 return;
10879 pp = pNext(p);
10880 while(pp != NULL)
10881 {
10882 if(pLmDivisibleBy(strat->S[i], pp))
10883 {
10884 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
10885 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
10886 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
10887 {
10888 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
10889 p_SetCoeff(pp,dummy,currRing);
10890 if(nIsZero(pp->coef))
10891 {
10892 pLmDelete(&pNext(p));
10893 pp = pNext(p);
10894 deleted = TRUE;
10895 }
10896 else
10897 {
10898 p = pp;
10899 pp = pNext(p);
10900 }
10901 }
10902 else
10903 {
10904 p = pp;
10905 pp = pNext(p);
10906 }
10907 pDelete(&sigMult);
10908 }
10909 else
10910 {
10911 p = pp;
10912 pp = pNext(p);
10913 }
10914 }
10915 }
10916 }
10917 h->SetLmCurrRing();
10918 if(deleted)
10919 strat->initEcart(h);
10920
10921}
10922
10923/*!
10924 used for GB over ZZ: final reduction by constant elements
10925 background: any known constant element of ideal suppresses
10926 intermediate coefficient swell and beautifies output
10927*/
10929{
10930 assume(strat->tl<0); /* can only be called with no elements in T:
10931 i.e. after exitBuchMora */
10932 /* do not use strat->S, strat->sl as they may be out of sync*/
10933 if(!nCoeff_is_Z(currRing->cf))
10934 return;
10935 poly p,pp;
10936 for(int j = 0; j<IDELEMS(strat->Shdl); j++)
10937 {
10938 if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
10939 {
10940 for(int i = 0; i<IDELEMS(strat->Shdl); i++)
10941 {
10942 if((i != j) && (strat->Shdl->m[i] != NULL))
10943 {
10944 p = strat->Shdl->m[i];
10945 while((p!=NULL) && (pLmDivisibleBy(strat->Shdl->m[j], p)
10946#if HAVE_SHIFTBBA
10947 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], p))
10948#endif
10949 ))
10950 {
10951 number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
10952 if (!nEqual(dummy,p->coef))
10953 {
10954 if (nIsZero(dummy))
10955 {
10956 nDelete(&dummy);
10957 pLmDelete(&strat->Shdl->m[i]);
10958 p=strat->Shdl->m[i];
10959 }
10960 else
10961 {
10962 p_SetCoeff(p,dummy,currRing);
10963 break;
10964 }
10965 }
10966 else
10967 {
10968 nDelete(&dummy);
10969 break;
10970 }
10971 }
10972 if (p!=NULL)
10973 {
10974 pp = pNext(p);
10975 while(pp != NULL)
10976 {
10977 if(pLmDivisibleBy(strat->Shdl->m[j], pp)
10978#if HAVE_SHIFTBBA
10979 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], pp))
10980#endif
10981 )
10982 {
10983 number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
10984 if (!nEqual(dummy,pp->coef))
10985 {
10986 p_SetCoeff(pp,dummy,currRing);
10987 if(nIsZero(pp->coef))
10988 {
10989 pLmDelete(&pNext(p));
10990 pp = pNext(p);
10991 }
10992 else
10993 {
10994 p = pp;
10995 pp = pNext(p);
10996 }
10997 }
10998 else
10999 {
11000 nDelete(&dummy);
11001 p = pp;
11002 pp = pNext(p);
11003 }
11004 }
11005 else
11006 {
11007 p = pp;
11008 pp = pNext(p);
11009 }
11010 }
11011 }
11012 }
11013 }
11014 //idPrint(strat->Shdl);
11015 }
11016 }
11017 idSkipZeroes(strat->Shdl);
11018}
11019#endif
11020
11021BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
11022{
11023 assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11024 /* initial setup or extending */
11025
11026 if (rIsLPRing(currRing)) return TRUE;
11027 if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11028 if (expbound >= currRing->bitmask) return FALSE;
11029 strat->overflow=FALSE;
11030 ring new_tailRing = rModifyRing(currRing,
11031 // Hmmm .. the condition pFDeg == p_Deg
11032 // might be too strong
11033 (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11034 (strat->ak==0), // omit_comp if the input is an ideal
11035 expbound); // exp_limit
11036
11037 if (new_tailRing == currRing) return TRUE;
11038
11039 strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11040 strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11041
11042 if (currRing->pFDeg != currRing->pFDegOrig)
11043 {
11044 new_tailRing->pFDeg = currRing->pFDeg;
11045 new_tailRing->pLDeg = currRing->pLDeg;
11046 }
11047
11048 if (TEST_OPT_PROT)
11049 Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11050 kTest_TS(strat);
11051 assume(new_tailRing != strat->tailRing);
11052 pShallowCopyDeleteProc p_shallow_copy_delete
11053 = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11054
11055 omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11056
11057 int i;
11058 for (i=0; i<=strat->tl; i++)
11059 {
11060 strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11061 p_shallow_copy_delete);
11062 }
11063 for (i=0; i<=strat->Ll; i++)
11064 {
11065 assume(strat->L[i].p != NULL);
11066 if (pNext(strat->L[i].p) != strat->tail)
11067 strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11068 }
11069 if ((strat->P.t_p != NULL) ||
11070 ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11071 strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11072
11073 if ((L != NULL) && (L->tailRing != new_tailRing))
11074 {
11075 if (L->i_r < 0)
11076 L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11077 else
11078 {
11079 assume(L->i_r <= strat->tl);
11080 TObject* t_l = strat->R[L->i_r];
11081 assume(t_l != NULL);
11082 L->tailRing = new_tailRing;
11083 L->p = t_l->p;
11084 L->t_p = t_l->t_p;
11085 L->max_exp = t_l->max_exp;
11086 }
11087 }
11088
11089 if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11090 T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11091
11092 omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11093 if (strat->tailRing != currRing)
11095
11096 strat->tailRing = new_tailRing;
11097 strat->tailBin = new_tailBin;
11099 = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11100
11101 if (strat->kNoether != NULL)
11102 {
11103 if (strat->t_kNoether != NULL)
11104 p_LmFree(strat->t_kNoether, strat->tailRing);
11105 strat->t_kNoether=k_LmInit_currRing_2_tailRing(strat->kNoether, new_tailRing);
11106 }
11107
11108 kTest_TS(strat);
11109 if (TEST_OPT_PROT)
11110 PrintS("]");
11111 return TRUE;
11112}
11113
11115{
11116 unsigned long l = 0;
11117 int i;
11118 long e;
11119
11120 assume(strat->tailRing == currRing);
11121
11122 for (i=0; i<= strat->Ll; i++)
11123 {
11124 l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11125 }
11126 for (i=0; i<=strat->tl; i++)
11127 {
11128 // Hmm ... this we could do in one Step
11129 l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11130 }
11132 {
11133 l *= 2;
11134 }
11135 e = p_GetMaxExp(l, currRing);
11136 if (e <= 1) e = 2;
11137 if (rIsLPRing(currRing)) e = 1;
11138
11139 kStratChangeTailRing(strat, NULL, NULL, e);
11140}
11141
11142ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11143{
11144 int n = rBlocks(r); // Including trailing zero!
11145 // if sbaOrder == 1 => use (C,monomial order from r)
11146 if (strat->sbaOrder == 1)
11147 {
11148 if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11149 {
11150 return r;
11151 }
11152 ring res = rCopy0(r, TRUE, FALSE);
11153 res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11154 res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11155 res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11156 int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11157 res->wvhdl = wvhdl;
11158 for (int i=1; i<n; i++)
11159 {
11160 res->order[i] = r->order[i-1];
11161 res->block0[i] = r->block0[i-1];
11162 res->block1[i] = r->block1[i-1];
11163 res->wvhdl[i] = r->wvhdl[i-1];
11164 }
11165
11166 // new 1st block
11167 res->order[0] = ringorder_C; // Prefix
11168 // removes useless secondary component order if defined in old ring
11169 for (int i=rBlocks(res); i>0; --i)
11170 {
11171 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11172 {
11173 res->order[i] = (rRingOrder_t)0;
11174 }
11175 }
11176 rComplete(res, 1);
11177#ifdef HAVE_PLURAL
11178 if (rIsPluralRing(r))
11179 {
11180 if ( nc_rComplete(r, res, false) ) // no qideal!
11181 {
11182#ifndef SING_NDEBUG
11183 WarnS("error in nc_rComplete");
11184#endif
11185 // cleanup?
11186
11187 // rDelete(res);
11188 // return r;
11189
11190 // just go on..
11191 }
11192 }
11193#endif
11194 strat->tailRing = res;
11195 return (res);
11196 }
11197 // if sbaOrder == 3 => degree - position - ring order
11198 if (strat->sbaOrder == 3)
11199 {
11200 ring res = rCopy0(r, TRUE, FALSE);
11201 res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11202 res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11203 res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11204 int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11205 res->wvhdl = wvhdl;
11206 for (int i=2; i<n+2; i++)
11207 {
11208 res->order[i] = r->order[i-2];
11209 res->block0[i] = r->block0[i-2];
11210 res->block1[i] = r->block1[i-2];
11211 res->wvhdl[i] = r->wvhdl[i-2];
11212 }
11213
11214 // new 1st block
11215 res->order[0] = ringorder_a; // Prefix
11216 res->block0[0] = 1;
11217 res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11218 for (int i=0; i<res->N; ++i)
11219 res->wvhdl[0][i] = 1;
11220 res->block1[0] = si_min(res->N, rVar(res));
11221 // new 2nd block
11222 res->order[1] = ringorder_C; // Prefix
11223 res->wvhdl[1] = NULL;
11224 // removes useless secondary component order if defined in old ring
11225 for (int i=rBlocks(res); i>1; --i)
11226 {
11227 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11228 {
11229 res->order[i] = (rRingOrder_t)0;
11230 }
11231 }
11232 rComplete(res, 1);
11233#ifdef HAVE_PLURAL
11234 if (rIsPluralRing(r))
11235 {
11236 if ( nc_rComplete(r, res, false) ) // no qideal!
11237 {
11238#ifndef SING_NDEBUG
11239 WarnS("error in nc_rComplete");
11240#endif
11241 // cleanup?
11242
11243 // rDelete(res);
11244 // return r;
11245
11246 // just go on..
11247 }
11248 }
11249#endif
11250 strat->tailRing = res;
11251 return (res);
11252 }
11253
11254 // not sbaOrder == 1 => use Schreyer order
11255 // this is done by a trick when initializing the signatures
11256 // in initSLSba():
11257 // Instead of using the signature 1e_i for F->m[i], we start
11258 // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11259 // Schreyer order w.r.t. the underlying monomial order.
11260 // => we do not need to change the underlying polynomial ring at all!
11261
11262 // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11263
11264 /*
11265 else
11266 {
11267 ring res = rCopy0(r, FALSE, FALSE);
11268 // Create 2 more blocks for prefix/suffix:
11269 res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11270 res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11271 res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11272 int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11273
11274 // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11275 // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11276
11277 // new 1st block
11278 int j = 0;
11279 res->order[j] = ringorder_IS; // Prefix
11280 res->block0[j] = res->block1[j] = 0;
11281 // wvhdl[j] = NULL;
11282 j++;
11283
11284 for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11285 {
11286 res->order [j] = r->order [i];
11287 res->block0[j] = r->block0[i];
11288 res->block1[j] = r->block1[i];
11289
11290 if (r->wvhdl[i] != NULL)
11291 {
11292 wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11293 } // else wvhdl[j] = NULL;
11294 }
11295
11296 // new last block
11297 res->order [j] = ringorder_IS; // Suffix
11298 res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11299 // wvhdl[j] = NULL;
11300 j++;
11301
11302 // res->order [j] = 0; // The End!
11303 res->wvhdl = wvhdl;
11304
11305 // j == the last zero block now!
11306 assume(j == (n+1));
11307 assume(res->order[0]==ringorder_IS);
11308 assume(res->order[j-1]==ringorder_IS);
11309 assume(res->order[j]==0);
11310
11311 if (complete)
11312 {
11313 rComplete(res, 1);
11314
11315#ifdef HAVE_PLURAL
11316 if (rIsPluralRing(r))
11317 {
11318 if ( nc_rComplete(r, res, false) ) // no qideal!
11319 {
11320 }
11321 }
11322 assume(rIsPluralRing(r) == rIsPluralRing(res));
11323#endif
11324
11325
11326#ifdef HAVE_PLURAL
11327 ring old_ring = r;
11328
11329#endif
11330
11331 if (r->qideal!=NULL)
11332 {
11333 res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11334
11335 assume(idRankFreeModule(res->qideal, res) == 0);
11336
11337#ifdef HAVE_PLURAL
11338 if( rIsPluralRing(res) )
11339 if( nc_SetupQuotient(res, r, true) )
11340 {
11341 // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11342 }
11343
11344#endif
11345 assume(idRankFreeModule(res->qideal, res) == 0);
11346 }
11347
11348#ifdef HAVE_PLURAL
11349 assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11350 assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11351 assume(rIsSCA(res) == rIsSCA(old_ring));
11352 assume(ncRingType(res) == ncRingType(old_ring));
11353#endif
11354 }
11355 strat->tailRing = res;
11356 return res;
11357 }
11358 */
11359
11360 assume(FALSE);
11361 return(NULL);
11362}
11363
11365{
11366 memset(this, 0, sizeof(skStrategy));
11367 strat_nr++;
11368 nr=strat_nr;
11370 P.tailRing = currRing;
11371 tl = -1;
11372 sl = -1;
11373#ifdef HAVE_LM_BIN
11375#endif
11376#ifdef HAVE_TAIL_BIN
11378#endif
11379 pOrigFDeg = currRing->pFDeg;
11380 pOrigLDeg = currRing->pLDeg;
11381}
11382
11383
11385{
11386 if (lmBin != NULL)
11388 if (tailBin != NULL)// && !rField_is_Ring(currRing))
11390 ((tailRing != NULL) ? tailRing->PolyBin:
11391 currRing->PolyBin));
11392 if (t_kNoether != NULL)
11394
11395 if (currRing != tailRing)
11398}
11399
11400#if 0
11401Timings for the different possibilities of posInT:
11402 T15 EDL DL EL L 1-2-3
11403Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11404Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11405Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11406ahml 4.48 4.03 4.03 4.38 4.96 26.50
11407c7 15.02 13.98 15.16 13.24 17.31 47.89
11408c8 505.09 407.46 852.76 413.21 499.19 n/a
11409f855 12.65 9.27 14.97 8.78 14.23 33.12
11410gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11411gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11412ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11413noon8 40.68 37.02 37.99 36.82 35.59 877.16
11414rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11415rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11416schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11417test016 16.39 14.17 14.40 13.50 14.26 34.07
11418test017 34.70 36.01 33.16 35.48 32.75 71.45
11419test042 10.76 10.99 10.27 11.57 10.45 23.04
11420test058 6.78 6.75 6.51 6.95 6.22 9.47
11421test066 10.71 10.94 10.76 10.61 10.56 19.06
11422test073 10.75 11.11 10.17 10.79 8.63 58.10
11423test086 12.23 11.81 12.88 12.24 13.37 66.68
11424test103 5.05 4.80 5.47 4.64 4.89 11.90
11425test154 12.96 11.64 13.51 12.46 14.61 36.35
11426test162 65.27 64.01 67.35 59.79 67.54 196.46
11427test164 7.50 6.50 7.68 6.70 7.96 17.13
11428virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11429#endif
11430
11431
11432//#ifdef HAVE_MORE_POS_IN_T
11433#if 1
11434// determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11436{
11437
11438 if (length==-1) return 0;
11439
11440 int o = p.ecart;
11441 int op=p.GetpFDeg();
11442 int ol = p.GetpLength();
11443
11444 if (set[length].ecart < o)
11445 return length+1;
11446 if (set[length].ecart == o)
11447 {
11448 int oo=set[length].GetpFDeg();
11449 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11450 return length+1;
11451 }
11452
11453 int i;
11454 int an = 0;
11455 int en= length;
11456 loop
11457 {
11458 if (an >= en-1)
11459 {
11460 if (set[an].ecart > o)
11461 return an;
11462 if (set[an].ecart == o)
11463 {
11464 int oo=set[an].GetpFDeg();
11465 if((oo > op)
11466 || ((oo==op) && (set[an].pLength > ol)))
11467 return an;
11468 }
11469 return en;
11470 }
11471 i=(an+en) / 2;
11472 if (set[i].ecart > o)
11473 en=i;
11474 else if (set[i].ecart == o)
11475 {
11476 int oo=set[i].GetpFDeg();
11477 if ((oo > op)
11478 || ((oo == op) && (set[i].pLength > ol)))
11479 en=i;
11480 else
11481 an=i;
11482 }
11483 else
11484 an=i;
11485 }
11486}
11487
11488// determines the position based on: 1.) FDeg 2.) pLength
11489int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11490{
11491
11492 if (length==-1) return 0;
11493
11494 int op=p.GetpFDeg();
11495 int ol = p.GetpLength();
11496
11497 int oo=set[length].GetpFDeg();
11498 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11499 return length+1;
11500
11501 int i;
11502 int an = 0;
11503 int en= length;
11504 loop
11505 {
11506 if (an >= en-1)
11507 {
11508 int oo=set[an].GetpFDeg();
11509 if((oo > op)
11510 || ((oo==op) && (set[an].pLength > ol)))
11511 return an;
11512 return en;
11513 }
11514 i=(an+en) / 2;
11515 int oo=set[i].GetpFDeg();
11516 if ((oo > op)
11517 || ((oo == op) && (set[i].pLength > ol)))
11518 en=i;
11519 else
11520 an=i;
11521 }
11522}
11523
11524
11525// determines the position based on: 1.) pLength
11526int posInT_pLength(const TSet set,const int length,LObject &p)
11527{
11528 int ol = p.GetpLength();
11529 if (length==-1)
11530 return 0;
11531 if (set[length].length<p.length)
11532 return length+1;
11533
11534 int i;
11535 int an = 0;
11536 int en= length;
11537
11538 loop
11539 {
11540 if (an >= en-1)
11541 {
11542 if (set[an].pLength>ol) return an;
11543 return en;
11544 }
11545 i=(an+en) / 2;
11546 if (set[i].pLength>ol) en=i;
11547 else an=i;
11548 }
11549}
11550#endif
11551
11552// kstd1.cc:
11553int redFirst (LObject* h,kStrategy strat);
11554int redEcart (LObject* h,kStrategy strat);
11555void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11556void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11557// ../Singular/misc.cc:
11558extern char * showOption();
11559
11561{
11562 printf("red: ");
11563 if (strat->red==redFirst) printf("redFirst\n");
11564 else if (strat->red==redHoney) printf("redHoney\n");
11565 else if (strat->red==redEcart) printf("redEcart\n");
11566 else if (strat->red==redHomog) printf("redHomog\n");
11567 else if (strat->red==redLazy) printf("redLazy\n");
11568 else if (strat->red==redLiftstd) printf("redLiftstd\n");
11569 else printf("%p\n",(void*)strat->red);
11570 printf("posInT: ");
11571 if (strat->posInT==posInT0) printf("posInT0\n");
11572 else if (strat->posInT==posInT1) printf("posInT1\n");
11573 else if (strat->posInT==posInT11) printf("posInT11\n");
11574 else if (strat->posInT==posInT110) printf("posInT110\n");
11575 else if (strat->posInT==posInT13) printf("posInT13\n");
11576 else if (strat->posInT==posInT15) printf("posInT15\n");
11577 else if (strat->posInT==posInT17) printf("posInT17\n");
11578 else if (strat->posInT==posInT17_c) printf("posInT17_c\n");
11579 else if (strat->posInT==posInT19) printf("posInT19\n");
11580 else if (strat->posInT==posInT2) printf("posInT2\n");
11581 #ifdef HAVE_RINGS
11582 else if (strat->posInT==posInT11Ring) printf("posInT11Ring\n");
11583 else if (strat->posInT==posInT110Ring) printf("posInT110Ring\n");
11584 else if (strat->posInT==posInT15Ring) printf("posInT15Ring\n");
11585 else if (strat->posInT==posInT17Ring) printf("posInT17Ring\n");
11586 else if (strat->posInT==posInT17_cRing) printf("posInT17_cRing\n");
11587 #endif
11588#ifdef HAVE_MORE_POS_IN_T
11589 else if (strat->posInT==posInT_EcartFDegpLength) printf("posInT_EcartFDegpLength\n");
11590 else if (strat->posInT==posInT_FDegpLength) printf("posInT_FDegpLength\n");
11591 else if (strat->posInT==posInT_pLength) printf("posInT_pLength\n");
11592#endif
11593 else if (strat->posInT==posInT_EcartpLength) printf("posInT_EcartpLength\n");
11594 else printf("%p\n",(void*)strat->posInT);
11595 printf("posInL: ");
11596 if (strat->posInL==posInL0) printf("posInL0\n");
11597 else if (strat->posInL==posInL10) printf("posInL10\n");
11598 else if (strat->posInL==posInL11) printf("posInL11\n");
11599 else if (strat->posInL==posInL110) printf("posInL110\n");
11600 else if (strat->posInL==posInL13) printf("posInL13\n");
11601 else if (strat->posInL==posInL15) printf("posInL15\n");
11602 else if (strat->posInL==posInL17) printf("posInL17\n");
11603 else if (strat->posInL==posInL17_c) printf("posInL17_c\n");
11604 #ifdef HAVE_RINGS
11605 else if (strat->posInL==posInL0) printf("posInL0Ring\n");
11606 else if (strat->posInL==posInL11Ring) printf("posInL11Ring\n");
11607 else if (strat->posInL==posInL11Ringls) printf("posInL11Ringls\n");
11608 else if (strat->posInL==posInL110Ring) printf("posInL110Ring\n");
11609 else if (strat->posInL==posInL15Ring) printf("posInL15Ring\n");
11610 else if (strat->posInL==posInL17Ring) printf("posInL17Ring\n");
11611 else if (strat->posInL==posInL17_cRing) printf("posInL17_cRing\n");
11612 #endif
11613 else if (strat->posInL==posInLSpecial) printf("posInLSpecial\n");
11614 else printf("%p\n",(void*)strat->posInL);
11615 printf("enterS: ");
11616 if (strat->enterS==enterSBba) printf("enterSBba\n");
11617 else if (strat->enterS==enterSMora) printf("enterSMora\n");
11618 else if (strat->enterS==enterSMoraNF) printf("enterSMoraNF\n");
11619 else printf("%p\n",(void*)strat->enterS);
11620 printf("initEcart: ");
11621 if (strat->initEcart==initEcartBBA) printf("initEcartBBA\n");
11622 else if (strat->initEcart==initEcartNormal) printf("initEcartNormal\n");
11623 else printf("%p\n",(void*)strat->initEcart);
11624 printf("initEcartPair: ");
11625 if (strat->initEcartPair==initEcartPairBba) printf("initEcartPairBba\n");
11626 else if (strat->initEcartPair==initEcartPairMora) printf("initEcartPairMora\n");
11627 else printf("%p\n",(void*)strat->initEcartPair);
11628 printf("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11629 strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11630 printf("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11631 strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11632 printf("chainCrit: ");
11633 if (strat->chainCrit==chainCritNormal) printf("chainCritNormal\n");
11634 else if (strat->chainCrit==chainCritOpt_1) printf("chainCritOpt_1\n");
11635 else printf("%p\n",(void*)strat->chainCrit);
11636 printf("posInLDependsOnLength=%d\n",
11637 strat->posInLDependsOnLength);
11638 printf("%s\n",showOption());
11639 printf("LDeg: ");
11640 if (currRing->pLDeg==pLDeg0) printf("pLDeg0");
11641 else if (currRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11642 else if (currRing->pLDeg==pLDegb) printf("pLDegb");
11643 else if (currRing->pLDeg==pLDeg1) printf("pLDeg1");
11644 else if (currRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11645 else if (currRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11646 else if (currRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11647 else if (currRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11648 else if (currRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11649 else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11650 else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11651 else if (currRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11652 else printf("? (%lx)", (long)currRing->pLDeg);
11653 printf(" / ");
11654 if (strat->tailRing->pLDeg==pLDeg0) printf("pLDeg0");
11655 else if (strat->tailRing->pLDeg==pLDeg0c) printf("pLDeg0c");
11656 else if (strat->tailRing->pLDeg==pLDegb) printf("pLDegb");
11657 else if (strat->tailRing->pLDeg==pLDeg1) printf("pLDeg1");
11658 else if (strat->tailRing->pLDeg==pLDeg1c) printf("pLDeg1c");
11659 else if (strat->tailRing->pLDeg==pLDeg1_Deg) printf("pLDeg1_Deg");
11660 else if (strat->tailRing->pLDeg==pLDeg1c_Deg) printf("pLDeg1c_Deg");
11661 else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) printf("pLDeg1_Totaldegree");
11662 else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) printf("pLDeg1c_Totaldegree");
11663 else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) printf("pLDeg1_WFirstTotalDegree");
11664 else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) printf("pLDeg1c_WFirstTotalDegree");
11665 else if (strat->tailRing->pLDeg==maxdegreeWecart) printf("maxdegreeWecart");
11666 else printf("? (%lx)", (long)strat->tailRing->pLDeg);
11667 printf("\n");
11668 printf("currRing->pFDeg: ");
11669 if (currRing->pFDeg==p_Totaldegree) printf("p_Totaldegree");
11670 else if (currRing->pFDeg==p_WFirstTotalDegree) printf("pWFirstTotalDegree");
11671 else if (currRing->pFDeg==p_Deg) printf("p_Deg");
11672 else if (currRing->pFDeg==kHomModDeg) printf("kHomModDeg");
11673 else if (currRing->pFDeg==totaldegreeWecart) printf("totaldegreeWecart");
11674 else if (currRing->pFDeg==p_WTotaldegree) printf("p_WTotaldegree");
11675 else printf("? (%lx)", (long)currRing->pFDeg);
11676 printf("\n");
11677 printf(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11679 printf(" degBound: %d\n", Kstd1_deg);
11680
11681 if( ecartWeights != NULL )
11682 {
11683 printf("ecartWeights: ");
11684 for (int i = rVar(currRing); i > 0; i--)
11685 printf("%hd ", ecartWeights[i]);
11686 printf("\n");
11688 }
11689
11690#ifndef SING_NDEBUG
11692#endif
11693}
11694
11695//LObject pCopyp2L(poly p, kStrategy strat)
11696//{
11697 /* creates LObject from the poly in currRing */
11698 /* actually put p into L.p and make L.t_p=NULL : does not work */
11699
11700//}
11701
11702/*2
11703* put the lcm(q,p) into the set B, q is the shift of some s[i]
11704*/
11705#ifdef HAVE_SHIFTBBA
11706static BOOLEAN enterOneStrongPolyShift (poly q, poly p, int /*ecart*/, int /*isFromQ*/, kStrategy strat, int atR, int /*ecartq*/, int /*qisFromQ*/, int shiftcount, int ifromS)
11707{
11708 number d, s, t;
11709 /* assume(atR >= 0); */
11710 assume(ifromS <= strat->sl);
11712 poly m1, m2, gcd;
11713 //printf("\n--------------------------------\n");
11714 //pWrite(p);pWrite(si);
11715 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q), &s, &t, currRing->cf);
11716
11717 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
11718 {
11719 nDelete(&d);
11720 nDelete(&s);
11721 nDelete(&t);
11722 return FALSE;
11723 }
11724
11725 assume(pIsInV(p));
11726
11727 k_GetStrongLeadTerms(p, q, currRing, m1, m2, gcd, strat->tailRing);
11728
11729 /* the V criterion */
11730 if (!pmIsInV(gcd))
11731 {
11732 strat->cv++;
11733 nDelete(&d);
11734 nDelete(&s);
11735 nDelete(&t);
11736 pLmFree(gcd);
11737 return FALSE;
11738 }
11739
11740 // disabled for Letterplace because it is not so easy to check
11741 /* if (!rHasLocalOrMixedOrdering(currRing)) { */
11742 /* unsigned long sev = pGetShortExpVector(gcd); */
11743
11744 /* for (int j = 0; j < strat->sl; j++) { */
11745 /* if (j == i) */
11746 /* continue; */
11747
11748 /* if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) && */
11749 /* !(strat->sevS[j] & ~sev) && */
11750 /* p_LmDivisibleBy(strat->S[j], gcd, currRing)) { */
11751 /* nDelete(&d); */
11752 /* nDelete(&s); */
11753 /* nDelete(&t); */
11754 /* return FALSE; */
11755 /* } */
11756 /* } */
11757 /* } */
11758
11759 poly m12, m22;
11763 // manually free the coeffs, because pSetCoeff0 is used in the next step
11764 n_Delete(&(m1->coef), currRing->cf);
11765 n_Delete(&(m2->coef), currRing->cf);
11766
11767 //p_Test(m1,strat->tailRing);
11768 //p_Test(m2,strat->tailRing);
11769 /*if(!enterTstrong)
11770 {
11771 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
11772 {
11773 memset(&(strat->P), 0, sizeof(strat->P));
11774 kStratChangeTailRing(strat);
11775 strat->P = *(strat->R[atR]);
11776 p_LmFree(m1, strat->tailRing);
11777 p_LmFree(m2, strat->tailRing);
11778 p_LmFree(gcd, currRing);
11779 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
11780 }
11781 }*/
11782 pSetCoeff0(m1, s);
11783 pSetCoeff0(m2, t);
11784 pSetCoeff0(gcd, d);
11785 p_Test(m1,strat->tailRing);
11786 p_Test(m2,strat->tailRing);
11787 p_Test(m12,strat->tailRing);
11788 p_Test(m22,strat->tailRing);
11789 assume(pmIsInV(m1));
11790 assume(pmIsInV(m2));
11791 assume(pmIsInV(m12));
11792 assume(pmIsInV(m22));
11793 //printf("\n===================================\n");
11794 //pWrite(m1);pWrite(m2);pWrite(gcd);
11795#ifdef KDEBUG
11796 if (TEST_OPT_DEBUG)
11797 {
11798 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
11799 PrintS("m1 = ");
11800 p_wrp(m1, strat->tailRing);
11801 PrintS("m12 = ");
11802 p_wrp(m12, strat->tailRing);
11803 PrintS(" ; m2 = ");
11804 p_wrp(m2, strat->tailRing);
11805 PrintS(" ; m22 = ");
11806 p_wrp(m22, strat->tailRing);
11807 PrintS(" ; gcd = ");
11808 wrp(gcd);
11809 PrintS("\n--- create strong gcd poly: ");
11810 PrintS("\n p: ");
11811 wrp(p);
11812 Print("\n q (strat->S[%d]): ", ifromS);
11813 wrp(q);
11814 PrintS(" ---> ");
11815 }
11816#endif
11817
11818 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);
11819 p_LmDelete(m1, strat->tailRing);
11820 p_LmDelete(m2, strat->tailRing);
11821 p_LmDelete(m12, strat->tailRing);
11822 p_LmDelete(m22, strat->tailRing);
11823
11824 assume(pIsInV(gcd));
11825
11826#ifdef KDEBUG
11827 if (TEST_OPT_DEBUG)
11828 {
11829 wrp(gcd);
11830 PrintLn();
11831 }
11832#endif
11833
11834 LObject h;
11835 h.p = gcd;
11836 h.tailRing = strat->tailRing;
11837 int posx;
11838 strat->initEcart(&h);
11839 h.sev = pGetShortExpVector(h.p);
11840 h.i_r1 = -1;h.i_r2 = -1;
11841 if (currRing!=strat->tailRing)
11842 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
11843#if 1
11844 h.p1 = p;
11845 h.p2 = q;
11846#endif
11847 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
11848 {
11849 h.i_r2 = kFindInT(h.p1, strat);
11850 h.i_r1 = atR;
11851 }
11852 else
11853 {
11854 h.i_r1 = -1;
11855 h.i_r2 = -1;
11856 }
11857 if (strat->Ll==-1)
11858 posx =0;
11859 else
11860 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
11861
11862 assume(pIsInV(h.p));
11863 assume(pIsInV(h.p1));
11864
11865 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
11866 return TRUE;
11867}
11868#endif
11869
11870
11871/*2
11872* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i] (ring case)
11873*/
11874#ifdef HAVE_SHIFTBBA
11875static void enterOnePairRingShift (poly q, poly p, int /*ecart*/, int isFromQ, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
11876{
11877 /* assume(atR >= 0); */
11878 /* assume(i<=strat->sl); */
11879 assume(p!=NULL);
11881 assume(pIsInV(p));
11882 #if ALL_VS_JUST
11883 //Over rings, if we construct the strong pair, do not add the spair
11885 {
11886 number s,t,d;
11887 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q, &s, &t, currRing->cf);
11888
11889 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
11890 {
11891 nDelete(&d);
11892 nDelete(&s);
11893 nDelete(&t);
11894 return;
11895 }
11896 nDelete(&d);
11897 nDelete(&s);
11898 nDelete(&t);
11899 }
11900 #endif
11901 int j,compare,compareCoeff;
11902 LObject h;
11903
11904#ifdef KDEBUG
11905 h.ecart=0; h.length=0;
11906#endif
11907 /*- computes the lcm(s[i],p) -*/
11908 if(pHasNotCFRing(p,q))
11909 {
11910 strat->cp++;
11911 return;
11912 }
11913 h.lcm = p_Lcm(p,q,currRing);
11914 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(q), currRing->cf));
11915 if (nIsZero(pGetCoeff(h.lcm)))
11916 {
11917 strat->cp++;
11918 pLmDelete(h.lcm);
11919 return;
11920 }
11921
11922 /* the V criterion */
11923 if (!pmIsInV(h.lcm))
11924 {
11925 strat->cv++;
11926 pLmDelete(h.lcm);
11927 return;
11928 }
11929 // basic chain criterion
11930 /*
11931 *the set B collects the pairs of type (S[j],p)
11932 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
11933 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
11934 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
11935 */
11936
11937 for(j = strat->Bl;j>=0;j--)
11938 {
11939 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
11940 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
11941 if(compare == pDivComp_EQUAL)
11942 {
11943 //They have the same LM
11944 if(compareCoeff == pDivComp_LESS)
11945 {
11946 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11947 {
11948 strat->c3++;
11949 pLmDelete(h.lcm);
11950 return;
11951 }
11952 break;
11953 }
11954 if(compareCoeff == pDivComp_GREATER)
11955 {
11956 deleteInL(strat->B,&strat->Bl,j,strat);
11957 strat->c3++;
11958 }
11959 if(compareCoeff == pDivComp_EQUAL)
11960 {
11961 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11962 {
11963 strat->c3++;
11964 pLmDelete(h.lcm);
11965 return;
11966 }
11967 break;
11968 }
11969 }
11970 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
11971 {
11972 if(compare == pDivComp_LESS)
11973 {
11974 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
11975 {
11976 strat->c3++;
11977 pLmDelete(h.lcm);
11978 return;
11979 }
11980 break;
11981 }
11982 if(compare == pDivComp_GREATER)
11983 {
11984 deleteInL(strat->B,&strat->Bl,j,strat);
11985 strat->c3++;
11986 }
11987 }
11988 }
11989 number s, t;
11990 poly m1, m2, gcd = NULL;
11991 s = pGetCoeff(q);
11992 t = pGetCoeff(p);
11994
11995 poly m12, m22;
11999 // manually free the coeffs, because pSetCoeff0 is used in the next step
12000 n_Delete(&(m1->coef), currRing->cf);
12001 n_Delete(&(m2->coef), currRing->cf);
12002
12003 ksCheckCoeff(&s, &t, currRing->cf);
12004 pSetCoeff0(m1, s);
12005 pSetCoeff0(m2, t);
12006 m2 = pNeg(m2);
12007 p_Test(m1,strat->tailRing);
12008 p_Test(m2,strat->tailRing);
12009 p_Test(m12,strat->tailRing);
12010 p_Test(m22,strat->tailRing);
12011 assume(pmIsInV(m1));
12012 assume(pmIsInV(m2));
12013 assume(pmIsInV(m12));
12014 assume(pmIsInV(m22));
12015 poly pm1 = pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing);
12016 poly sim2 = pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing);
12017 assume(pIsInV(pm1));
12018 assume(pIsInV(sim2));
12019 p_LmDelete(m1, currRing);
12020 p_LmDelete(m2, currRing);
12021 p_LmDelete(m12, currRing);
12022 p_LmDelete(m22, currRing);
12023 if(sim2 == NULL)
12024 {
12025 if(pm1 == NULL)
12026 {
12027 if(h.lcm != NULL)
12028 {
12029 pLmDelete(h.lcm);
12030 h.lcm=NULL;
12031 }
12032 h.Clear();
12033 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12034 /* if (strat->pairtest==NULL) initPairtest(strat); */
12035 /* strat->pairtest[i] = TRUE; */
12036 /* strat->pairtest[strat->sl+1] = TRUE; */
12037 return;
12038 }
12039 else
12040 {
12041 gcd = pm1;
12042 pm1 = NULL;
12043 }
12044 }
12045 else
12046 {
12047 if((pGetComp(q) == 0) && (0 != pGetComp(p)))
12048 {
12049 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
12050 pSetmComp(sim2);
12051 }
12052 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
12053 gcd = p_Add_q(pm1, sim2, strat->tailRing);
12054 }
12055 p_Test(gcd, strat->tailRing);
12056 assume(pIsInV(gcd));
12057#ifdef KDEBUG
12058 if (TEST_OPT_DEBUG)
12059 {
12060 wrp(gcd);
12061 PrintLn();
12062 }
12063#endif
12064 h.p = gcd;
12065 h.i_r = -1;
12066 if(h.p == NULL)
12067 {
12068 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12069 /* if (strat->pairtest==NULL) initPairtest(strat); */
12070 /* strat->pairtest[i] = TRUE; */
12071 /* strat->pairtest[strat->sl+1] = TRUE; */
12072 return;
12073 }
12074 h.tailRing = strat->tailRing;
12075 int posx;
12076 //h.pCleardenom();
12077 //pSetm(h.p);
12078 h.i_r1 = -1;h.i_r2 = -1;
12079 strat->initEcart(&h);
12080 #if 1
12081 h.p1 = p;
12082 h.p2 = q;
12083 #endif
12084 #if 1
12085 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12086 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12087 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12088 {
12089 h.i_r2 = kFindInT(h.p1, strat); //strat->S_2_R[i];
12090 h.i_r1 = atR;
12091 }
12092 else
12093 {
12094 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12095 h.i_r1 = -1;
12096 h.i_r2 = -1;
12097 }
12098 #endif
12099 if (strat->Bl==-1)
12100 posx =0;
12101 else
12102 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
12103 h.sev = pGetShortExpVector(h.p);
12104 if (currRing!=strat->tailRing)
12105 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12106
12107 assume(pIsInV(h.p));
12108 assume(pIsInV(h.p1));
12109 assume(h.lcm != NULL);
12110 assume(pIsInV(h.lcm));
12111
12112 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
12113 kTest_TS(strat);
12114}
12115#endif
12116
12117#ifdef HAVE_SHIFTBBA
12118// adds the strong pair and the normal pair for rings (aka gpoly and spoly)
12119static BOOLEAN enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12120{
12121 enterOneStrongPolyShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "gpoly"
12122 enterOnePairRingShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "spoly"
12123 return FALSE; // TODO: delete q?
12124}
12125#endif
12126
12127#ifdef HAVE_SHIFTBBA
12128// creates if possible (q,p), (shifts(q),p)
12129static 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)
12130{
12131 // note: ecart and isFromQ is for p
12132 assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12133 assume(pmFirstVblock(p) == 1);
12134 assume(pmFirstVblock(q) == 1);
12135 assume(p_lastVblock == pmLastVblock(p));
12136 assume(q_lastVblock == pmLastVblock(q));
12137
12138 // TODO: is ecartq = 0 still ok?
12139 int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12140
12141 int q_isFromQ = 0;
12142 if (strat->fromQ != NULL && q_inS >= 0)
12143 q_isFromQ = strat->fromQ[q_inS];
12144
12145 BOOLEAN (*enterPair)(poly, poly, int, int, kStrategy, int, int, int, int, int);
12146#ifdef HAVE_RINGS
12149 else
12150#endif
12151 enterPair = enterOnePairShift;
12152
12153 int degbound = currRing->N/currRing->isLPring;
12154 int neededShift = p_lastVblock - ((pGetComp(p) > 0 || pGetComp(q) > 0) ? 0 : 1); // in the module case, product criterion does not hold
12155 int maxPossibleShift = degbound - q_lastVblock;
12156 int maxShift = si_min(neededShift, maxPossibleShift);
12157 int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12158 BOOLEAN delete_pair=TRUE;
12159 for (int j = firstShift; j <= maxShift; j++)
12160 {
12161 poly qq = pLPCopyAndShiftLM(q, j);
12162 if (enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS))
12163 {
12164 if (j>0) pLmDelete(qq);
12165 // delete qq, if not it does not enter the pair set
12166 }
12167 else
12168 delete_pair=FALSE;
12169 }
12170
12171#ifdef HAVE_RINGS
12172 if (rField_is_Ring(currRing) && p_lastVblock >= firstShift && p_lastVblock <= maxPossibleShift)
12173 {
12174 // add pairs (m*shifts(q), p) where m is a monomial and the pair has no overlap
12175 for (int j = p_lastVblock; j <= maxPossibleShift; j++)
12176 {
12177 ideal fillers = id_MaxIdeal(j - p_lastVblock, currRing);
12178 for (int k = 0; k < IDELEMS(fillers); k++)
12179 {
12180 poly qq = pLPCopyAndShiftLM(pp_mm_Mult(q, fillers->m[k], currRing), p_lastVblock);
12181 enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, p_lastVblock, q_inS);
12182 }
12183 idDelete(&fillers);
12184 }
12185 }
12186#endif
12187 return delete_pair;
12188}
12189#endif
12190
12191#ifdef HAVE_SHIFTBBA
12192// creates (q,p), use it when q is already shifted
12193// return TRUE, if (q,p) is discarded
12194static 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)
12195{
12196 // note: ecart and isFromQ is for p
12197 assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12198 assume(pmFirstVblock(p) == 1);
12199 assume(p_lastVblock == pmLastVblock(p));
12200 assume(q_shift == pmFirstVblock(q) - 1);
12201
12202 // TODO: is ecartp = 0 still ok?
12203 int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12204
12205 int p_isFromQ = 0;
12206 if (strat->fromQ != NULL && p_inS >= 0)
12207 p_isFromQ = strat->fromQ[p_inS];
12208
12209#ifdef HAVE_RINGS
12211 {
12212 assume(q_shift <= p_lastVblock); // we allow the special case where there is no overlap
12213 return enterOneStrongPolyAndEnterOnePairRingShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12214 }
12215 else
12216#endif
12217 {
12218 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)
12219 return enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12220 }
12221}
12222#endif
12223
12224
12225#ifdef KDEBUG
12226// enable to print which pairs are considered or discarded and why
12227/* #define CRITERION_DEBUG */
12228#endif
12229/*2
12230* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12231* return TRUE, if (q,p) does not enter B
12232*/
12233#ifdef HAVE_SHIFTBBA
12234BOOLEAN enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12235{
12236#ifdef CRITERION_DEBUG
12237 if (TEST_OPT_DEBUG)
12238 {
12239 PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12240 // also write the LMs in separate lines:
12241 poly lmq = pHead(q);
12242 poly lmp = pHead(p);
12243 pSetCoeff(lmq, n_Init(1, currRing->cf));
12244 pSetCoeff(lmp, n_Init(1, currRing->cf));
12245 Print(" %s\n", pString(lmq));
12246 Print(" %s\n", pString(lmp));
12247 pLmDelete(lmq);
12248 pLmDelete(lmp);
12249 }
12250#endif
12251
12252 /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12253
12254 /* check this Formats: */
12259
12260 /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12261
12262 int qfromQ = qisFromQ;
12263
12264 /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12265
12266 int l,j,compare;
12267 LObject Lp;
12268 Lp.i_r = -1;
12269
12270#ifdef KDEBUG
12271 Lp.ecart=0; Lp.length=0;
12272#endif
12273 /*- computes the lcm(s[i],p) -*/
12274 Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12275
12276 /* the V criterion */
12277 if (!pmIsInV(Lp.lcm))
12278 {
12279 strat->cv++; // counter for applying the V criterion
12280 pLmFree(Lp.lcm);
12281#ifdef CRITERION_DEBUG
12282 if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12283#endif
12284 return TRUE;
12285 }
12286
12287 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12288 {
12289 if((!((ecartq>0)&&(ecart>0)))
12290 && pHasNotCF(p,q))
12291 {
12292 /*
12293 *the product criterion has applied for (s,p),
12294 *i.e. lcm(s,p)=product of the leading terms of s and p.
12295 *Suppose (s,r) is in L and the leading term
12296 *of p divides lcm(s,r)
12297 *(==> the leading term of p divides the leading term of r)
12298 *but the leading term of s does not divide the leading term of r
12299 *(notice that this condition is automatically satisfied if r is still
12300 *in S), then (s,r) can be cancelled.
12301 *This should be done here because the
12302 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12303 *
12304 *Moreover, skipping (s,r) holds also for the noncommutative case.
12305 */
12306 strat->cp++;
12307 pLmFree(Lp.lcm);
12308#ifdef CRITERION_DEBUG
12309 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12310#endif
12311 return TRUE;
12312 }
12313 else
12314 Lp.ecart = si_max(ecart,ecartq);
12315 if (strat->fromT && (ecartq>ecart))
12316 {
12317 pLmFree(Lp.lcm);
12318#ifdef CRITERION_DEBUG
12319 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12320#endif
12321 return TRUE;
12322 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12323 }
12324 /*
12325 *the set B collects the pairs of type (S[j],p)
12326 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12327 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12328 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12329 */
12330 {
12331 j = strat->Bl;
12332 loop
12333 {
12334 if (j < 0) break;
12335 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12336 if ((compare==1)
12337 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12338 {
12339 strat->c3++;
12340 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12341 {
12342 pLmFree(Lp.lcm);
12343#ifdef CRITERION_DEBUG
12344 if (TEST_OPT_DEBUG)
12345 {
12346 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12347 }
12348#endif
12349 return TRUE;
12350 }
12351 break;
12352 }
12353 else
12354 if ((compare ==-1)
12355 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12356 {
12357#ifdef CRITERION_DEBUG
12358 if (TEST_OPT_DEBUG)
12359 {
12360 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12361 }
12362#endif
12363 deleteInL(strat->B,&strat->Bl,j,strat);
12364 strat->c3++;
12365 }
12366 j--;
12367 }
12368 }
12369 }
12370 else /*sugarcrit*/
12371 {
12372 if (ALLOW_PROD_CRIT(strat))
12373 {
12374 // if currRing->nc_type!=quasi (or skew)
12375 // TODO: enable productCrit for super commutative algebras...
12376 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12377 pHasNotCF(p,q))
12378 {
12379 /*
12380 *the product criterion has applied for (s,p),
12381 *i.e. lcm(s,p)=product of the leading terms of s and p.
12382 *Suppose (s,r) is in L and the leading term
12383 *of p divides lcm(s,r)
12384 *(==> the leading term of p divides the leading term of r)
12385 *but the leading term of s does not divide the leading term of r
12386 *(notice that tis condition is automatically satisfied if r is still
12387 *in S), then (s,r) can be canceled.
12388 *This should be done here because the
12389 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12390 */
12391 strat->cp++;
12392 pLmFree(Lp.lcm);
12393#ifdef CRITERION_DEBUG
12394 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12395#endif
12396 return TRUE;
12397 }
12398 if (strat->fromT && (ecartq>ecart))
12399 {
12400 pLmFree(Lp.lcm);
12401#ifdef CRITERION_DEBUG
12402 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12403#endif
12404 return TRUE;
12405 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12406 }
12407 /*
12408 *the set B collects the pairs of type (S[j],p)
12409 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12410 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12411 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12412 */
12413 for(j = strat->Bl;j>=0;j--)
12414 {
12415 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12416 if (compare==1)
12417 {
12418 strat->c3++;
12419 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12420 {
12421 pLmFree(Lp.lcm);
12422#ifdef CRITERION_DEBUG
12423 if (TEST_OPT_DEBUG)
12424 {
12425 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12426 }
12427#endif
12428 return TRUE;
12429 }
12430 break;
12431 }
12432 else
12433 if (compare ==-1)
12434 {
12435#ifdef CRITERION_DEBUG
12436 if (TEST_OPT_DEBUG)
12437 {
12438 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12439 }
12440#endif
12441 deleteInL(strat->B,&strat->Bl,j,strat);
12442 strat->c3++;
12443 }
12444 }
12445 }
12446 }
12447 /*
12448 *the pair (S[i],p) enters B if the spoly != 0
12449 */
12450 /*- compute the short s-polynomial -*/
12451 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12452 pNorm(p);
12453 if ((q==NULL) || (p==NULL))
12454 {
12455#ifdef CRITERION_DEBUG
12456 if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
12457#endif
12458 return FALSE;
12459 }
12460 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12461 {
12462 Lp.p=NULL;
12463#ifdef CRITERION_DEBUG
12464 if (TEST_OPT_DEBUG) PrintS("--- pair is from Q\n");
12465#endif
12466 }
12467 else
12468 {
12469// if ( rIsPluralRing(currRing) )
12470// {
12471// if(pHasNotCF(p, q))
12472// {
12473// if(ncRingType(currRing) == nc_lie)
12474// {
12475// // generalized prod-crit for lie-type
12476// strat->cp++;
12477// Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12478// }
12479// else
12480// if( ALLOW_PROD_CRIT(strat) )
12481// {
12482// // product criterion for homogeneous case in SCA
12483// strat->cp++;
12484// Lp.p = NULL;
12485// }
12486// else
12487// Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12488// }
12489// else Lp.p = nc_CreateSpoly(q,p,currRing);
12490// }
12491// else
12492// {
12493
12494 /* ksCreateShortSpoly needs two Lobject-kind presentations */
12495 /* p is already in this form, so convert q */
12496 Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12497 // }
12498 }
12499 if (Lp.p == NULL)
12500 {
12501 /*- the case that the s-poly is 0 -*/
12502 // TODO: currently ifromS is only > 0 if called from enterOnePairWithShifts
12503 if (ifromS > 0)
12504 {
12505 if (strat->pairtest==NULL) initPairtest(strat);
12506 strat->pairtest[ifromS] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12507 strat->pairtest[strat->sl+1] = TRUE;
12508 }
12509 //if (TEST_OPT_DEBUG){Print("!");} // option teach
12510 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12511 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12512 /*
12513 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12514 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12515 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12516 *term of p divides the lcm(s,r)
12517 *(this canceling should be done here because
12518 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12519 *the first case is handled in chainCrit
12520 */
12521 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12522#ifdef CRITERION_DEBUG
12523 if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
12524#endif
12525 return TRUE;
12526 }
12527 else
12528 {
12529 /*- the pair (S[i],p) enters B -*/
12530 /* both of them should have their LM in currRing and TAIL in tailring */
12531 Lp.p1 = q; // already in the needed form
12532 Lp.p2 = p; // already in the needed form
12533
12534 if ( !rIsPluralRing(currRing) )
12535 pNext(Lp.p) = strat->tail;
12536
12537 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12538 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12539 if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12540 {
12541 Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12542 Lp.i_r2 = atR;
12543 }
12544 else
12545 {
12546 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12547 Lp.i_r1 = -1;
12548 Lp.i_r2 = -1;
12549 }
12550 strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12551
12553 {
12556 && (Lp.p->coef!=NULL))
12557 nDelete(&(Lp.p->coef));
12558 }
12559
12560 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12561 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12562#ifdef CRITERION_DEBUG
12563 if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
12564#endif
12565 }
12566 return FALSE;
12567}
12568#endif
12569
12570/*3
12571*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12572* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12573* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12574*/
12575#ifdef HAVE_SHIFTBBA
12576void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12577{
12578 int h_lastVblock = pmLastVblock(h);
12579 assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12580 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12581 if (h_lastVblock == 0) return;
12582 assume(pmFirstVblock(h) == 1);
12583 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12584 // atR = -1;
12585 if ((strat->syzComp==0)
12586 || (pGetComp(h)<=strat->syzComp))
12587 {
12588 int i,j;
12589 BOOLEAN new_pair=FALSE;
12590
12591 int degbound = currRing->N/currRing->isLPring;
12592 int maxShift = degbound - h_lastVblock;
12593
12594 if (pGetComp(h)==0)
12595 {
12596 if (strat->rightGB)
12597 {
12598 if (isFromQ)
12599 {
12600 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12601 for (i=0; i<=maxShift; i++)
12602 {
12603 poly hh = pLPCopyAndShiftLM(h, i);
12604 BOOLEAN delete_hh=TRUE;
12605 for (j=0; j<=k; j++)
12606 {
12607 if (strat->fromQ == NULL || !strat->fromQ[j])
12608 {
12609 new_pair=TRUE;
12610 poly s = strat->S[j];
12611 if (!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12612 delete_hh=FALSE;
12613 }
12614 }
12615 if (delete_hh) pLmDelete(hh);
12616 }
12617 }
12618 else
12619 {
12620 new_pair=TRUE;
12621 for (j=0; j<=k; j++)
12622 {
12623 poly s = strat->S[j];
12624 if (strat->fromQ != NULL && strat->fromQ[j])
12625 {
12626 // pairs (shifts(s[j]),h), (s[j],h)
12627 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12628 }
12629 else
12630 {
12631 // pair (h, s[j])
12632 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12633 }
12634 }
12635 }
12636 }
12637 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12638 else if ((isFromQ)&&(strat->fromQ!=NULL))
12639 {
12640 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12641 for (j=0; j<=k; j++)
12642 {
12643 if (!strat->fromQ[j])
12644 {
12645 new_pair=TRUE;
12646 poly s = strat->S[j];
12647 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12648 }
12649 }
12650 // pairs (shifts(h),s[1..k])
12651 if (new_pair)
12652 {
12653 for (i=1; i<=maxShift; i++)
12654 {
12655 BOOLEAN delete_hh=TRUE;
12656 poly hh = pLPCopyAndShiftLM(h, i);
12657 for (j=0; j<=k; j++)
12658 {
12659 if (!strat->fromQ[j])
12660 {
12661 poly s = strat->S[j];
12662 int s_lastVblock = pmLastVblock(s);
12663 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)
12664 {
12665 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i))
12666 delete_hh=FALSE;
12667 }
12668#ifdef HAVE_RINGS
12669 else if (rField_is_Ring(currRing))
12670 {
12671 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12672 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12673 for (int k = 0; k < IDELEMS(fillers); k++)
12674 {
12675 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12676 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12677 }
12678 idDelete(&fillers);
12679 }
12680#endif
12681 }
12682 }
12683 if (delete_hh) p_LmDelete(hh,currRing);
12684 }
12685 }
12686 }
12687 else
12688 {
12689 new_pair=TRUE;
12690 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12691 for (j=0; j<=k; j++)
12692 {
12693 poly s = strat->S[j];
12694 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12695 }
12696 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12697 for (i=1; i<=maxShift; i++)
12698 {
12699 poly hh = pLPCopyAndShiftLM(h, i);
12700 BOOLEAN delete_hh=TRUE;
12701 for (j=0; j<=k; j++)
12702 {
12703 poly s = strat->S[j];
12704 int s_lastVblock = pmLastVblock(s);
12705 if (i < s_lastVblock || (pGetComp(s) > 0 && i == s_lastVblock)) // in the module case, product criterion does not hold (note: comp h is always zero here)
12706 delete_hh=enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i)
12707 && delete_hh;
12708#ifdef HAVE_RINGS
12709 else if (rField_is_Ring(currRing))
12710 {
12711 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12712 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12713 for (int k = 0; k < IDELEMS(fillers); k++)
12714 {
12715 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12716 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12717 }
12718 idDelete(&fillers);
12719 }
12720#endif
12721 }
12722 if (i < h_lastVblock) // in the module case, product criterion does not hold (note: comp h is always zero here)
12723 delete_hh=enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i)
12724 && delete_hh;
12725#ifdef HAVE_RINGS
12726 else if (rField_is_Ring(currRing))
12727 {
12728 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12729 ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
12730 for (int k = 0; k < IDELEMS(fillers); k++)
12731 {
12732 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
12733 enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock);
12734 }
12735 idDelete(&fillers);
12736 }
12737#endif
12738 if (delete_hh) pLmDelete(hh);
12739 }
12740 }
12741 }
12742 else
12743 {
12744 assume(isFromQ == 0); // an element from Q should always has 0 component
12745 new_pair=TRUE;
12746 if (strat->rightGB)
12747 {
12748 for (j=0; j<=k; j++)
12749 {
12750 if ((pGetComp(h)==pGetComp(strat->S[j]))
12751 || (pGetComp(strat->S[j])==0))
12752 {
12753 poly s = strat->S[j];
12754 if (strat->fromQ != NULL && strat->fromQ[j])
12755 {
12756 // pairs (shifts(s[j]),h), (s[j],h)
12757 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12758 }
12759 else
12760 {
12761 // pair (h, s[j])
12762 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12763 }
12764 }
12765 }
12766 }
12767 else
12768 {
12769 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12770 for (j=0; j<=k; j++)
12771 {
12772 if ((pGetComp(h)==pGetComp(strat->S[j]))
12773 || (pGetComp(strat->S[j])==0))
12774 {
12775 poly s = strat->S[j];
12776 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12777 }
12778 }
12779 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12780 for (i=1; i<=maxShift; i++)
12781 {
12782 poly hh = pLPCopyAndShiftLM(h, i);
12783 for (j=0; j<=k; j++)
12784 {
12785 if ((pGetComp(h)==pGetComp(strat->S[j]))
12786 || (pGetComp(strat->S[j])==0))
12787 {
12788 poly s = strat->S[j];
12789 int s_lastVblock = pmLastVblock(s);
12790 if (i <= s_lastVblock) // in the module case, product criterion does not hold
12791 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
12792#ifdef HAVE_RINGS
12793 else if (rField_is_Ring(currRing))
12794 {
12795 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
12796 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
12797 for (int k = 0; k < IDELEMS(fillers); k++)
12798 {
12799 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
12800 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
12801 }
12802 idDelete(&fillers);
12803 }
12804#endif
12805 }
12806 }
12807 if (i <= h_lastVblock) // in the module case, product criterion does not hold
12808 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
12809#ifdef HAVE_RINGS
12810 else if (rField_is_Ring(currRing))
12811 {
12812 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
12813 ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
12814 for (int k = 0; k < IDELEMS(fillers); k++)
12815 {
12816 BOOLEAN delete_hhh=TRUE;
12817 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
12818 if(!enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock))
12819 delete_hhh=FALSE;
12820 if (delete_hhh) p_LmDelete(hhh,currRing);
12821 }
12822 idDelete(&fillers);
12823 }
12824#endif
12825 }
12826 }
12827 }
12828
12829 if (new_pair)
12830 {
12831 strat->chainCrit(h,ecart,strat);
12832 }
12833 kMergeBintoL(strat);
12834 }
12835}
12836#endif
12837
12838/*3
12839*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12840* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12841* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12842*/
12843#ifdef HAVE_SHIFTBBA
12844void initenterstrongPairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12845{
12846 int h_lastVblock = pmLastVblock(h);
12847 assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12848 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12849 if (h_lastVblock == 0) return;
12850 assume(pmFirstVblock(h) == 1);
12851 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12852 // atR = -1;
12853 if ((strat->syzComp==0)
12854 || (pGetComp(h)<=strat->syzComp))
12855 {
12856 int i,j;
12857 BOOLEAN new_pair=FALSE;
12858
12859 int degbound = currRing->N/currRing->isLPring;
12860 int maxShift = degbound - h_lastVblock;
12861
12862 if (pGetComp(h)==0)
12863 {
12864 if (strat->rightGB)
12865 {
12866 if (isFromQ)
12867 {
12868 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12869 for (i=0; i<=maxShift; i++)
12870 {
12871 poly hh = pLPCopyAndShiftLM(h, i);
12872 for (j=0; j<=k; j++)
12873 {
12874 if (strat->fromQ == NULL || !strat->fromQ[j])
12875 {
12876 new_pair=TRUE;
12877 poly s = strat->S[j];
12878 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12879 }
12880 }
12881 }
12882 }
12883 else
12884 {
12885 new_pair=TRUE;
12886 for (j=0; j<=k; j++)
12887 {
12888 poly s = strat->S[j];
12889 if (strat->fromQ != NULL && strat->fromQ[j])
12890 {
12891 // pairs (shifts(s[j]),h), (s[j],h)
12892 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12893 }
12894 else
12895 {
12896 // pair (h, s[j])
12897 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12898 }
12899 }
12900 }
12901 }
12902 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
12903 else if ((isFromQ)&&(strat->fromQ!=NULL))
12904 {
12905 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12906 for (j=0; j<=k; j++)
12907 {
12908 if (!strat->fromQ[j])
12909 {
12910 new_pair=TRUE;
12911 poly s = strat->S[j];
12912 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12913 }
12914 }
12915 // pairs (shifts(h),s[1..k])
12916 if (new_pair)
12917 {
12918 for (i=1; i<=maxShift; i++)
12919 {
12920 poly hh = pLPCopyAndShiftLM(h, i);
12921 for (j=0; j<=k; j++)
12922 {
12923 if (!strat->fromQ[j])
12924 {
12925 poly s = strat->S[j];
12926 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
12927 }
12928 }
12929 }
12930 }
12931 }
12932 else
12933 {
12934 new_pair=TRUE;
12935 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12936 for (j=0; j<=k; j++)
12937 {
12938 poly s = strat->S[j];
12939 // TODO: cache lastVblock of s[1..k] for later use
12940 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12941 }
12942 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12943 for (i=1; i<=maxShift; i++)
12944 {
12945 poly hh = pLPCopyAndShiftLM(h, i);
12946 BOOLEAN delete_hh=TRUE;
12947 for (j=0; j<=k; j++)
12948 {
12949 poly s = strat->S[j];
12950 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
12951 delete_hh=FALSE;
12952 }
12953 if(!enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i))
12954 delete_hh=FALSE;
12955 if (delete_hh) p_LmDelete(hh,currRing);
12956 }
12957 }
12958 }
12959 else
12960 {
12961 new_pair=TRUE;
12962 if (strat->rightGB)
12963 {
12964 for (j=0; j<=k; j++)
12965 {
12966 if ((pGetComp(h)==pGetComp(strat->S[j]))
12967 || (pGetComp(strat->S[j])==0))
12968 {
12969 assume(isFromQ == 0); // this case is not handled here and should also never happen
12970 poly s = strat->S[j];
12971 if (strat->fromQ != NULL && strat->fromQ[j])
12972 {
12973 // pairs (shifts(s[j]),h), (s[j],h)
12974 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12975 }
12976 else
12977 {
12978 // pair (h, s[j])
12979 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
12980 }
12981 }
12982 }
12983 }
12984 else
12985 {
12986 // pairs (shifts(s[1..k]),h), (s[1..k],h)
12987 for (j=0; j<=k; j++)
12988 {
12989 if ((pGetComp(h)==pGetComp(strat->S[j]))
12990 || (pGetComp(strat->S[j])==0))
12991 {
12992 poly s = strat->S[j];
12993 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
12994 }
12995 }
12996 // pairs (shifts(h),s[1..k]), (shifts(h), h)
12997 for (i=1; i<=maxShift; i++)
12998 {
12999 poly hh = pLPCopyAndShiftLM(h, i);
13000 for (j=0; j<=k; j++)
13001 {
13002 if ((pGetComp(h)==pGetComp(strat->S[j]))
13003 || (pGetComp(strat->S[j])==0))
13004 {
13005 poly s = strat->S[j];
13006 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13007 }
13008 }
13009 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13010 }
13011 }
13012 }
13013
13014 if (new_pair)
13015 {
13016 strat->chainCrit(h,ecart,strat);
13017 }
13018 kMergeBintoL(strat);
13019 }
13020}
13021#endif
13022
13023/*2
13024*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
13025*superfluous elements in S will be deleted
13026*/
13027#ifdef HAVE_SHIFTBBA
13028void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
13029{
13030 /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13031 /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
13032 int j=pos;
13033
13034 /* if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat); */ // TODO: enterExtendedSpoly not for LP yet
13035 initenterpairsShift(h,k,ecart,0,strat, atR);
13036 if ( (!strat->fromT)
13037 && ((strat->syzComp==0)
13038 ||(pGetComp(h)<=strat->syzComp)))
13039 {
13040 unsigned long h_sev = pGetShortExpVector(h);
13041 loop
13042 {
13043 if (j > k) break;
13044 // TODO this currently doesn't clear all possible elements because of commutative division
13045 if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
13046 clearS(h,h_sev, &j,&k,strat);
13047 j++;
13048 }
13049 }
13050}
13051#endif
13052
13053/*2
13054* enteres all admissible shifts of p into T
13055* assumes that p is already in T!
13056*/
13057#ifdef HAVE_SHIFTBBA
13058void enterTShift(LObject p, kStrategy strat, int atT)
13059{
13060 /* determine how many elements we have to insert */
13061 /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
13062 /* hence, a total number of elt's to add is: */
13063 /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
13064 pAssume(p.p != NULL);
13065
13066 int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
13067
13068 for (int i = 1; i <= maxPossibleShift; i++)
13069 {
13070 LObject qq;
13071 qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
13072 qq.shift = i;
13073 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
13074
13075 enterT(qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
13076 }
13077}
13078#endif
13079
13080#ifdef HAVE_SHIFTBBA
13082{
13083 /* for the shift case need to run it with withT = TRUE */
13084 strat->redTailChange=FALSE;
13085 if (strat->noTailReduction) return L->GetLmCurrRing();
13086 poly h, p;
13087 p = h = L->GetLmTailRing();
13088 if ((h==NULL) || (pNext(h)==NULL))
13089 return L->GetLmCurrRing();
13090
13091 TObject* With;
13092 // placeholder in case strat->tl < 0
13093 TObject With_s(strat->tailRing);
13094
13095 LObject Ln(pNext(h), strat->tailRing);
13096 Ln.pLength = L->GetpLength() - 1;
13097
13098 pNext(h) = NULL;
13099 if (L->p != NULL) pNext(L->p) = NULL;
13100 L->pLength = 1;
13101
13102 Ln.PrepareRed(strat->use_buckets);
13103
13104 while(!Ln.IsNull())
13105 {
13106 loop
13107 {
13108 Ln.SetShortExpVector();
13109 if (withT)
13110 {
13111 int j;
13112 j = kFindDivisibleByInT(strat, &Ln);
13113 if (j < 0) break;
13114 With = &(strat->T[j]);
13115 }
13116 else
13117 {
13118 With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
13119 if (With == NULL) break;
13120 }
13121 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
13122 {
13123 With->pNorm();
13124 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
13125 }
13126 strat->redTailChange=TRUE;
13127 if (ksReducePolyTail(L, With, &Ln))
13128 {
13129 // reducing the tail would violate the exp bound
13130 // set a flag and hope for a retry (in bba)
13132 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
13133 do
13134 {
13135 pNext(h) = Ln.LmExtractAndIter();
13136 pIter(h);
13137 L->pLength++;
13138 } while (!Ln.IsNull());
13139 goto all_done;
13140 }
13141 if (Ln.IsNull()) goto all_done;
13142 if (! withT) With_s.Init(currRing);
13143 }
13144 pNext(h) = Ln.LmExtractAndIter();
13145 pIter(h);
13146 L->pLength++;
13147 }
13148
13149 all_done:
13150 Ln.Delete();
13151 if (L->p != NULL) pNext(L->p) = pNext(p);
13152
13153 if (strat->redTailChange)
13154 {
13155 L->length = 0;
13156 }
13157 L->Normalize(); // HANNES: should have a test
13158 kTest_L(L,strat);
13159 return L->GetLmCurrRing();
13160}
13161#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:4078
bool equal
Definition: cfModGcd.cc:4126
CanonicalForm b
Definition: cfModGcd.cc:4103
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
Definition: intvec.h:23
poly p
Definition: kutil.h:73
poly t_p
Definition: kutil.h:74
ring tailRing
Definition: kutil.h:76
void wrp()
Definition: kutil.cc:773
KINLINE poly kNoetherTail()
Definition: kInline.h:66
unsigned long * sevSyz
Definition: kutil.h:323
kStrategy next
Definition: kutil.h:277
bool sigdrop
Definition: kutil.h:359
poly t_kNoether
Definition: kutil.h:330
int * S_2_R
Definition: kutil.h:342
ring tailRing
Definition: kutil.h:343
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:291
char noTailReduction
Definition: kutil.h:378
int currIdx
Definition: kutil.h:317
~skStrategy()
Definition: kutil.cc:11384
skStrategy()
Definition: kutil.cc:11364
int nrsyzcrit
Definition: kutil.h:360
intset lenS
Definition: kutil.h:319
int nrrewcrit
Definition: kutil.h:361
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:298
int Ll
Definition: kutil.h:351
TSet T
Definition: kutil.h:326
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:293
char news
Definition: kutil.h:400
omBin lmBin
Definition: kutil.h:344
int syzmax
Definition: kutil.h:349
int Bl
Definition: kutil.h:352
intset ecartS
Definition: kutil.h:309
int syzidxmax
Definition: kutil.h:349
char honey
Definition: kutil.h:377
unsigned syzComp
Definition: kutil.h:354
char rightGB
Definition: kutil.h:369
polyset S
Definition: kutil.h:306
int minim
Definition: kutil.h:357
poly kNoether
Definition: kutil.h:329
BOOLEAN * NotUsedAxis
Definition: kutil.h:332
LSet B
Definition: kutil.h:328
BOOLEAN * pairtest
Definition: kutil.h:333
int cp
Definition: kutil.h:347
int ak
Definition: kutil.h:353
TObject ** R
Definition: kutil.h:340
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:295
int tl
Definition: kutil.h:350
unsigned long * sevT
Definition: kutil.h:325
unsigned long * sevSig
Definition: kutil.h:324
int nr
Definition: kutil.h:346
poly tail
Definition: kutil.h:334
char sugarCrit
Definition: kutil.h:377
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:284
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:47
intset syzIdx
Definition: kutil.h:313
ideal Shdl
Definition: kutil.h:303
int syzl
Definition: kutil.h:349
unsigned sbaOrder
Definition: kutil.h:316
pFDegProc pOrigFDeg
Definition: kutil.h:296
int tmax
Definition: kutil.h:350
polyset sig
Definition: kutil.h:308
polyset syz
Definition: kutil.h:307
char LDegLast
Definition: kutil.h:385
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:287
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.h:292
wlen_set lenSw
Definition: kutil.h:320
char kAllAxis
Definition: kutil.h:376
int cv
Definition: kutil.h:368
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:338
char Gebauer
Definition: kutil.h:378
intset fromQ
Definition: kutil.h:321
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:286
char newt
Definition: kutil.h:401
char use_buckets
Definition: kutil.h:383
char interpt
Definition: kutil.h:371
char redTailChange
Definition: kutil.h:399
int newIdeal
Definition: kutil.h:356
char fromT
Definition: kutil.h:379
char completeReduce_retry
Definition: kutil.h:403
void(* initEcart)(TObject *L)
Definition: kutil.h:280
omBin tailBin
Definition: kutil.h:345
LObject P
Definition: kutil.h:302
KINLINE TObject * S_2_T(int i)
Definition: kInline.h:38
char noClearS
Definition: kutil.h:402
int Lmax
Definition: kutil.h:351
char z2homog
Definition: kutil.h:374
int LazyPass
Definition: kutil.h:353
char overflow
Definition: kutil.h:404
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.h:290
LSet L
Definition: kutil.h:327
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:281
int(* red)(LObject *L, kStrategy strat)
Definition: kutil.h:278
int sl
Definition: kutil.h:348
int LazyDegree
Definition: kutil.h:353
char posInLDependsOnLength
Definition: kutil.h:389
unsigned long * sevS
Definition: kutil.h:322
char homog
Definition: kutil.h:372
pLDegProc pOrigLDeg
Definition: kutil.h:297
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:282
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:299
int Bmax
Definition: kutil.h:352
int c3
Definition: kutil.h:347
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:813
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:30
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition: coeffs.h:661
static FORCE_INLINE BOOLEAN n_IsUnit(number n, const coeffs r)
TRUE iff n has a multiplicative inverse in the given coeff field/ring r.
Definition: coeffs.h:512
static FORCE_INLINE number n_Ann(number a, const coeffs r)
if r is a ring with zero divisors, return an annihilator!=0 of b otherwise return NULL
Definition: coeffs.h:676
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition: coeffs.h:697
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:413
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:452
static FORCE_INLINE number n_Lcm(number a, number b, const coeffs r)
in Z: return the lcm of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition: coeffs.h:687
static FORCE_INLINE number n_ExtGcd(number a, number b, number *s, number *t, const coeffs r)
beware that ExtGCD is only relevant for a few chosen coeff. domains and may perform something unexpec...
Definition: coeffs.h:668
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:535
static FORCE_INLINE number n_IntMod(number a, number b, const coeffs r)
for r a field, return n_Init(0,r) always: n_Div(a,b,r)*b+n_IntMod(a,b,r)==a n_IntMod(a,...
Definition: coeffs.h:625
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether 'a' is divisible 'b'; for r encoding a field: TRUE iff 'b' does not represent zero in Z:...
Definition: coeffs.h:750
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition: coeffs.h:519
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition: coeffs.h:73
void nKillChar(coeffs r)
undo all initialisations
Definition: numbers.cc:568
#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
Definition: facFactorize.cc:55
int j
Definition: facHensel.cc:110
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
static int min(int a, int b)
Definition: fast_mult.cc:268
static int max(int a, int b)
Definition: fast_mult.cc:264
if(!FE_OPT_NO_SHELL_FLAG)(void) system(sys)
#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:1101
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:959
KINLINE TSet initT()
Definition: kInline.h:84
KINLINE void k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing, poly &m1, poly &m2, poly &lcm, const ring tailRing)
Definition: kInline.h:1061
KINLINE int ksReducePolyTailLC_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1109
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1176
KINLINE TObject ** initR()
Definition: kInline.h:95
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1149
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1186
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1239
KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r, poly &m1, poly &m2, const ring m_r)
Definition: kInline.h:1018
KINLINE int ksReducePolyTail_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1127
KINLINE unsigned long * initsevT()
Definition: kInline.h:100
int redLiftstd(LObject *h, kStrategy strat)
Definition: kLiftstd.cc:167
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
Definition: kbuckets.cc:197
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:216
int ksCheckCoeff(number *a, number *b, const coeffs r)
Definition: kbuckets.cc:1504
BOOLEAN pCompareChainPart(poly p, poly p1, poly p2, poly lcm, const ring R)
Definition: kpolys.cc:71
BOOLEAN pCompareChain(poly p, poly p1, poly p2, poly lcm, const ring R)
Returns TRUE if.
Definition: kpolys.cc:17
poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing)
Definition: kspoly.cc:1453
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition: kstd1.cc:1365
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2434
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:3182
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:2447
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:2088
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:1121
int redLazy(LObject *h, kStrategy strat)
Definition: kstd2.cc:1881
poly redNF(poly h, int &max_ind, int nonorm, kStrategy strat)
Definition: kstd2.cc:2325
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:954
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:9911
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7512
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:6883
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6339
#define pDivComp_LESS
Definition: kutil.cc:136
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6454
int getIndexRng(long coeff)
Definition: kutil.cc:6035
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6093
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5306
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:9800
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:797
VAR int HCord
Definition: kutil.cc:246
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3174
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition: kutil.cc:544
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition: kutil.cc:6689
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9380
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5876
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:169
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:4975
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9178
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:4918
void enterTShift(LObject p, kStrategy strat, int atT)
Definition: kutil.cc:13058
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5096
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:6664
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:8952
BOOLEAN kTest(kStrategy strat)
Definition: kutil.cc:1012
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3947
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1681
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7072
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5172
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition: kutil.cc:6740
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:4907
BOOLEAN kTest_TS(kStrategy strat)
Definition: kutil.cc:1073
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:1952
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:718
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition: kutil.cc:10573
VAR int Kstd1_mu
Definition: kutil.cc:248
void initenterstrongPairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:12844
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4535
static void enterOnePairRingShift(poly q, poly p, int, int isFromQ, kStrategy strat, int atR, int, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:11875
static const char * kTest_LmEqual(poly p, poly t_p, ring tailRing)
Definition: kutil.cc:783
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1280
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:6605
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:12119
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4452
static int pLPDivComp(poly p, poly q)
Definition: kutil.cc:232
int posInT2(const TSet set, const int length, LObject &p)
Definition: kutil.cc:4947
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6182
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6135
#define kFalseReturn(x)
Definition: kutil.cc:780
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:12129
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11526
static intset initec(const int maxnr)
Definition: kutil.cc:530
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition: kutil.cc:9612
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4509
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5143
void redtailBbaAlsoLC_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7188
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6556
static void deleteHCBucket(LObject *L, kStrategy strat)
Definition: kutil.cc:250
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9458
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:12194
void chainCritSig(poly p, int, kStrategy strat)
Definition: kutil.cc:3474
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition: kutil.cc:4786
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1326
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4167
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4491
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8549
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5671
static int pDivCompRing(poly p, poly q)
Definition: kutil.cc:144
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:9627
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:3822
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7635
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11021
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:6959
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7317
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11142
void initPairtest(kStrategy strat)
Definition: kutil.cc:693
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:2215
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5643
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8131
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3458
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5012
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:1346
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8525
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition: kutil.cc:8437
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:12576
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4222
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3887
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6217
static void enlargeL(LSet *L, int *length, const int incr)
Definition: kutil.cc:683
int posInT17_c(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5414
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:13081
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11435
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5210
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9278
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:10763
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6521
void HEckeTest(poly pp, kStrategy strat)
Definition: kutil.cc:501
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5599
STATIC_VAR BOOLEAN sloppy_max
Definition: kutil.cc:800
VAR int Kstd1_deg
Definition: kutil.cc:247
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition: kutil.cc:4333
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:13028
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2446
BOOLEAN kTest_L(LObject *L, kStrategy strat, BOOLEAN testp, int lpos, TSet T, int tlength)
Definition: kutil.cc:926
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:9885
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:7566
void initEcartNormal(TObject *h)
Definition: kutil.cc:1304
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:4685
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:8594
static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
Definition: kutil.cc:1188
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7826
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5946
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3105
static int * initS_2_R(const int maxnr)
Definition: kutil.cc:539
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6294
void initSyzRules(kStrategy strat)
Definition: kutil.cc:7976
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5703
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10013
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10534
void cleanT(kStrategy strat)
Definition: kutil.cc:565
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2234
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5053
BOOLEAN kTest_S(kStrategy strat)
Definition: kutil.cc:1055
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:5792
void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
Definition: kutil.cc:9087
void reorderS(int *suc, kStrategy strat)
Definition: kutil.cc:4632
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4249
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6253
#define pDivComp_INCOMP
Definition: kutil.cc:138
BOOLEAN kTest_T(TObject *T, kStrategy strat, int i, char TN)
Definition: kutil.cc:801
void kMergeBintoLSba(kStrategy strat)
Definition: kutil.cc:3195
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:294
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10128
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4478
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition: kutil.cc:1337
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5542
poly redtailBba_NF(poly p, kStrategy strat)
Definition: kutil.cc:7398
#define pDivComp_GREATER
Definition: kutil.cc:137
void exitSba(kStrategy strat)
Definition: kutil.cc:10088
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5265
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5368
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition: kutil.cc:1550
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:12234
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition: kutil.cc:11560
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1215
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11114
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3533
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1628
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9476
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:624
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5476
static int pDivComp(poly p, poly q)
Definition: kutil.cc:183
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:10340
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6389
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:9713
int kFindInTShift(poly p, TSet T, int tlength)
Definition: kutil.cc:743
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:10839
static BOOLEAN enterOneStrongPolyShift(poly q, poly p, int, int, kStrategy strat, int atR, int, int, int shiftcount, int ifromS)
Definition: kutil.cc:11706
void messageSets(kStrategy strat)
Definition: kutil.cc:7585
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1139
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8420
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11489
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5728
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition: kutil.cc:702
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition: kutil.cc:1700
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5910
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:10596
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:535
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:4558
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3217
void initEcartBBA(TObject *h)
Definition: kutil.cc:1312
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:2703
void enterSBbaShift(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:8929
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5833
char * showOption()
Definition: misc_ip.cc:709
poly redtailBba_Ring(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7423
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:5821
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1319
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7553
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1758
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:4009
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8275
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7729
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:4863
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:10928
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:8829
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:9541
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10462
#define pDivComp_EQUAL
Definition: kutil.cc:135
void cancelunit(LObject *L, BOOLEAN inNF)
Definition: kutil.cc:373
denominator_list_s * denominator_list
Definition: kutil.h:63
TObject * TSet
Definition: kutil.h:59
#define setmaxL
Definition: kutil.h:30
#define setmaxTinc
Definition: kutil.h:34
static int kFindInL1(const poly p, const kStrategy strat)
Definition: kutil.h:851
#define setmax
Definition: kutil.h:29
EXTERN_VAR int strat_nr
Definition: kutil.h:181
int64 wlen_type
Definition: kutil.h:54
static LSet initL(int nr=setmaxL)
Definition: kutil.h:420
LObject * LSet
Definition: kutil.h:60
denominator_list next
Definition: kutil.h:65
static void kDeleteLcm(LObject *P)
Definition: kutil.h:880
int * intset
Definition: kutil.h:53
#define ALLOW_PROD_CRIT(A)
Definition: kutil.h:395
#define setmaxT
Definition: kutil.h:33
#define setmaxLinc
Definition: kutil.h:31
class sTObject TObject
Definition: kutil.h:57
#define REDTAIL_CANONICALIZE
Definition: kutil.h:38
class sLObject LObject
Definition: kutil.h:58
static bool rIsSCA(const ring r)
Definition: nc.h:190
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
Definition: old.gring.cc:1879
@ 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
Definition: old.gring.cc:2251
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:709
#define assume(x)
Definition: mod2.h:389
#define r_assume(x)
Definition: mod2.h:390
int dReportError(const char *fmt,...)
Definition: dError.cc:44
#define p_GetComp(p, r)
Definition: monomials.h:64
#define pFalseReturn(cond)
Definition: monomials.h:139
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
#define pSetCoeff0(p, n)
Definition: monomials.h:59
#define p_GetCoeff(p, r)
Definition: monomials.h:50
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44
#define __p_GetComp(p, r)
Definition: monomials.h:63
#define rRing_has_Comp(r)
Definition: monomials.h:266
#define pAssume(cond)
Definition: monomials.h:90
STATIC_VAR gmp_float * diff
Definition: mpr_complex.cc:45
#define nDelete(n)
Definition: numbers.h:16
#define nIsZero(n)
Definition: numbers.h:19
#define nEqual(n1, n2)
Definition: numbers.h:20
#define nCopy(n)
Definition: numbers.h:15
#define nGreater(a, b)
Definition: numbers.h:28
#define nGreaterZero(n)
Definition: numbers.h:27
#define nInvers(a)
Definition: numbers.h:33
#define nIsOne(n)
Definition: numbers.h:25
#define nInit(i)
Definition: numbers.h:24
#define nTest(a)
Definition: numbers.h:35
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omCheckBinAddrSize(addr, size)
Definition: omAllocDecl.h:326
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omReallocSize(addr, o_size, size)
Definition: omAllocDecl.h:220
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define omRealloc0Size(addr, o_size, size)
Definition: omAllocDecl.h:221
#define omSizeWOfBin(bin_ptr)
#define NULL
Definition: omList.c:12
omBin_t * omBin
Definition: omStructs.h:12
#define REGISTER
Definition: omalloc.h:27
#define TEST_OPT_WEIGHTM
Definition: options.h:122
#define TEST_OPT_IDLIFT
Definition: options.h:130
#define TEST_OPT_INTSTRATEGY
Definition: options.h:111
#define TEST_OPT_REDTAIL
Definition: options.h:117
#define TEST_OPT_INFREDTAIL
Definition: options.h:119
#define TEST_OPT_SUGARCRIT
Definition: options.h:108
#define TEST_OPT_OLDSTD
Definition: options.h:124
#define TEST_OPT_REDSB
Definition: options.h:105
#define TEST_OPT_DEGBOUND
Definition: options.h:114
#define TEST_OPT_SB_1
Definition: options.h:120
#define TEST_OPT_NOT_SUGAR
Definition: options.h:107
#define TEST_OPT_PROT
Definition: options.h:104
#define OPT_INTERRUPT
Definition: options.h:80
#define TEST_OPT_CANCELUNIT
Definition: options.h:129
#define BTEST1(a)
Definition: options.h:34
#define TEST_OPT_DEBUG
Definition: options.h:109
#define TEST_OPT_CONTENTSB
Definition: options.h:128
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
poly p_GetMaxExpP(poly p, const ring r)
return monomial r such that GetExp(r,i) is maximum of all monomials in p; coeff == 0,...
Definition: p_polys.cc:1138
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2954
long pLDegb(poly p, int *l, const ring r)
Definition: p_polys.cc:811
long pLDeg1_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:975
long p_WFirstTotalDegree(poly p, const ring r)
Definition: p_polys.cc:596
long pLDeg1_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1038
void pRestoreDegProcs(ring r, pFDegProc old_FDeg, pLDegProc old_lDeg)
Definition: p_polys.cc:3649
long pLDeg1c_WFirstTotalDegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1068
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition: p_polys.cc:4526
long pLDeg1c_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:941
long pLDeg1(poly p, int *l, const ring r)
Definition: p_polys.cc:841
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4780
long pLDeg1_Deg(poly p, int *l, const ring r)
Definition: p_polys.cc:910
long p_WTotaldegree(poly p, const ring r)
Definition: p_polys.cc:613
BOOLEAN p_OneComp(poly p, const ring r)
return TRUE if all monoms have the same component
Definition: p_polys.cc:1208
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2845
long pLDeg1c(poly p, int *l, const ring r)
Definition: p_polys.cc:877
long pLDeg1c_Totaldegree(poly p, int *l, const ring r)
Definition: p_polys.cc:1005
long pLDeg0c(poly p, int *l, const ring r)
Definition: p_polys.cc:770
unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max)
return the maximal exponent of p in form of the maximal long var
Definition: p_polys.cc:1175
long pLDeg0(poly p, int *l, const ring r)
Definition: p_polys.cc:739
poly p_One(const ring r)
Definition: p_polys.cc:1313
poly p_Sub(poly p1, poly p2, const ring r)
Definition: p_polys.cc:1990
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3696
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:587
void p_Lcm(const poly a, const poly b, poly m, const ring r)
Definition: p_polys.cc:1655
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1105
static int pLength(poly a)
Definition: p_polys.h:188
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1423
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:934
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:721
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1409
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:1854
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:378
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition: p_polys.h:779
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition: p_polys.h:1311
static void p_LmDelete0(poly p, const ring r)
Definition: p_polys.h:731
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1725
#define __pp_Mult_nn(p, n, r)
Definition: p_polys.h:1000
static poly pp_mm_Mult(poly p, poly m, const ring r)
Definition: p_polys.h:1039
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1029
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition: p_polys.h:1645
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:252
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:161
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:245
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:231
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:410
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1578
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1908
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:467
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:1889
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:926
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:899
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:115
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:709
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1049
static void p_LmFree(poly p, ring)
Definition: p_polys.h:681
#define p_LmTest(p, r)
Definition: p_polys.h:160
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:844
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1505
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition: p_polys.h:1997
#define p_Test(p, r)
Definition: p_polys.h:159
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:373
void rChangeCurrRing(ring r)
Definition: polys.cc:15
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
Compatibility layer for legacy polynomial operations (over currRing)
#define pLtCmp(p, q)
Definition: polys.h:123
#define pLtCmpOrdSgnDiffM(p, q)
Definition: polys.h:125
#define pDelete(p_ptr)
Definition: polys.h:186
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL
Definition: polys.h:67
#define pLmIsConstantComp(p)
like above, except that p must be != NULL
Definition: polys.h:242
#define pSetm(p)
Definition: polys.h:271
#define pIsConstant(p)
like above, except that Comp must be 0
Definition: polys.h:238
#define pHasNotCF(p1, p2)
Definition: polys.h:263
#define pLtCmpOrdSgnDiffP(p, q)
Definition: polys.h:126
#define pNeg(p)
Definition: polys.h:198
#define pLmEqual(p1, p2)
Definition: polys.h:111
#define ppMult_mm(p, m)
Definition: polys.h:201
#define pGetComp(p)
Component.
Definition: polys.h:37
#define pIsVector(p)
Definition: polys.h:250
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
void pNorm(poly p)
Definition: polys.h:362
#define pJet(p, m)
Definition: polys.h:367
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition: polys.h:146
#define pCmp(p1, p2)
pCmp: args may be NULL returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
Definition: polys.h:115
#define pDivideM(a, b)
Definition: polys.h:294
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
#define pSetComp(p, v)
Definition: polys.h:38
#define pLmDelete(p)
assume p != NULL, deletes Lm(p)->coef and Lm(p)
Definition: polys.h:76
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl....
Definition: polys.h:152
void wrp(poly p)
Definition: polys.h:310
#define pLmDivisibleBy(a, b)
like pDivisibleBy, except that it is assumed that a!=NULL, b!=NULL
Definition: polys.h:140
static void pLmFree(poly p)
frees the space of the monomial m, assumes m != NULL coef is not freed, m is not advanced
Definition: polys.h:70
void pWrite(poly p)
Definition: polys.h:308
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
#define pSetmComp(p)
TODO:
Definition: polys.h:273
#define pHasNotCFRing(p1, p2)
Definition: polys.h:262
#define pNormalize(p)
Definition: polys.h:317
#define pIsPurePower(p)
Definition: polys.h:248
#define pInit()
allocates a new monomial and initializes everything to 0
Definition: polys.h:61
#define pEqualPolys(p1, p2)
Definition: polys.h:399
#define pDivisibleBy(a, b)
returns TRUE, if leading monom of a divides leading monom of b i.e., if there exists a expvector c > ...
Definition: polys.h:138
#define pSetExp(p, i, v)
Definition: polys.h:42
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:105
#define pLtCmpOrdSgnEqP(p, q)
Definition: polys.h:128
char * pString(poly p)
Definition: polys.h:306
#define pCopy(p)
return a copy of the poly
Definition: polys.h:185
#define pOne()
Definition: polys.h:315
poly * polyset
Definition: polys.h:259
#define pDecrExp(p, i)
Definition: polys.h:44
#define pLcm(a, b, m)
Definition: polys.h:295
poly prMapR(poly src, nMapFunc nMap, ring src_r, ring dest_r)
Definition: prCopy.cc:45
void pLcmRat(poly a, poly b, poly m, int rat_shift)
Definition: ratgring.cc:30
void PrintS(const char *s)
Definition: reporter.cc:284
void PrintLn()
Definition: reporter.cc:310
#define mflush()
Definition: reporter.h:58
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition: ring.cc:3450
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5685
void rKillModifiedRing(ring r)
Definition: ring.cc:3059
ring rAssure_c_dp(const ring r)
Definition: ring.cc:4990
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2698
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1421
void rDebugPrint(const ring r)
Definition: ring.cc:4122
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:450
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:400
static int rBlocks(const ring r)
Definition: ring.h:568
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:723
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:487
static BOOLEAN rIsRatGRing(const ring r)
Definition: ring.h:427
static BOOLEAN rIsLPRing(const ring r)
Definition: ring.h:411
rRingOrder_t
order stuff
Definition: ring.h:68
@ ringorder_a
Definition: ring.h:70
@ ringorder_C
Definition: ring.h:73
@ ringorder_c
Definition: ring.h:72
BOOLEAN rHasMixedOrdering(const ring r)
Definition: ring.h:761
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:720
poly(* pShallowCopyDeleteProc)(poly s_p, ring source_r, ring dest_r, omBin dest_bin)
returns a poly from dest_r which is a ShallowCopy of s_p from source_r assumes that source_r->N == de...
Definition: ring.h:44
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:592
BOOLEAN rHasGlobalOrdering(const ring r)
Definition: ring.h:759
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:760
#define rField_is_Ring(R)
Definition: ring.h:485
int p_mLPmaxPossibleShift(poly p, const ring r)
Definition: shiftgb.cc:45
#define pLPCopyAndShiftLM(p, sh)
Definition: shiftgb.h:15
BOOLEAN _p_LPLmDivisibleByNoComp(poly a, poly b, const ring r)
Definition: shiftop.cc:796
int p_mFirstVblock(poly p, const ring ri)
Definition: shiftop.cc:478
void k_SplitFrame(poly &m1, poly &m2, int at, const ring r)
Definition: shiftop.cc:600
void p_mLPshift(poly m, int sh, const ring ri)
Definition: shiftop.cc:362
#define pmFirstVblock(p)
Definition: shiftop.h:35
#define pLPDivisibleBy(a, b)
Definition: shiftop.h:57
#define pIsInV(p)
Definition: shiftop.h:50
#define pmIsInV(p)
Definition: shiftop.h:51
#define pmLastVblock(p)
Definition: shiftop.h:33
#define pLPLmDivisibleBy(a, b)
Definition: shiftop.h:58
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35
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)
Definition: simpleideals.cc:98
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
#define IDELEMS(i)
Definition: simpleideals.h:23
static int idElem(const ideal F)
number of non-zero polys in F
Definition: simpleideals.h:67
#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)
Definition: walkSupport.cc:836
long totaldegreeWecart(poly p, ring r)
Definition: weight.cc:217
long maxdegreeWecart(poly p, int *l, ring r)
Definition: weight.cc:247
EXTERN_VAR short * ecartWeights
Definition: weight.h:12
#define omGetStickyBinOfBin(B)
Definition: xalloc.h:247
#define omMergeStickyBinIntoBin(A, B)
Definition: xalloc.h:275