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// for(i=r->N;i>0;i--)
392// {
393// if ((p_GetExp(p,i,r)>0) && (rIsPolyVar(i, r)==TRUE)) return;
394// }
395 poly h = pNext(p);
396 int i;
397
399 {
400 loop
401 {
402 if (h==NULL)
403 {
404 p_Delete(&pNext(p), r);
405 if (!inNF)
406 {
407 number eins= nCopy(lc);
408 if (L->p != NULL)
409 {
410 pSetCoeff(L->p,eins);
411 if (L->t_p != NULL)
412 pSetCoeff0(L->t_p,eins);
413 }
414 else
415 pSetCoeff(L->t_p,eins);
416 /* p and t_p share the same coeff, if both are !=NULL */
417 /* p==NULL==t_p cannot happen here */
418 }
419 L->ecart = 0;
420 L->length = 1;
421 //if (L->pLength > 0)
422 L->pLength = 1;
423 L->max_exp = NULL;
424
425 if (L->t_p != NULL && pNext(L->t_p) != NULL)
426 p_Delete(&pNext(L->t_p),r);
427 if (L->p != NULL && pNext(L->p) != NULL)
428 pNext(L->p) = NULL;
429 return;
430 }
431 i = rVar(r);
432 loop
433 {
434 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
435 i--;
436 if (i == 0) break; // does divide, try next monom
437 }
438 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
439 // Note: As long as qring j forbidden if j contains integer (i.e. ground rings are
440 // domains), no zerodivisor test needed CAUTION
441 if (!n_DivBy(pGetCoeff(h),lc,r->cf))
442 {
443 return;
444 }
445 pIter(h);
446 }
447 }
448 else
449 {
450 loop
451 {
452 if (h==NULL)
453 {
454 p_Delete(&pNext(p), r);
455 if (!inNF)
456 {
457 number eins=nInit(1);
458 if (L->p != NULL)
459 {
460 pSetCoeff(L->p,eins);
461 if (L->t_p != NULL)
462 pSetCoeff0(L->t_p,eins);
463 }
464 else
465 pSetCoeff(L->t_p,eins);
466 /* p and t_p share the same coeff, if both are !=NULL */
467 /* p==NULL==t_p cannot happen here */
468 }
469 L->ecart = 0;
470 L->length = 1;
471 //if (L->pLength > 0)
472 L->pLength = 1;
473 L->max_exp = NULL;
474
475 if (L->t_p != NULL && pNext(L->t_p) != NULL)
476 p_Delete(&pNext(L->t_p),r);
477 if (L->p != NULL && pNext(L->p) != NULL)
478 pNext(L->p) = NULL;
479
480 return;
481 }
482 i = rVar(r);
483 loop
484 {
485 if (p_GetExp(p,i,r) > p_GetExp(h,i,r)) return; // does not divide
486 i--;
487 if (i == 0) break; // does divide, try next monom
488 }
489 //wrp(p); PrintS(" divide ");wrp(h); PrintLn();
490 pIter(h);
491 }
492 }
493}
494
495/*2
496*pp is the new element in s
497*returns TRUE (in strat->kAllAxis) if
498*-HEcke is allowed
499*-we are in the last componente of the vector
500*-on all axis are monomials (all elements in NotUsedAxis are FALSE)
501*returns FALSE for pLexOrderings,
502*assumes in module case an ordering of type c* !!
503* HEckeTest is only called with strat->kAllAxis==FALSE !
504*/
505void HEckeTest (poly pp,kStrategy strat)
506{
507 int j,/*k,*/p;
508
509 if (currRing->pLexOrder
511 || (strat->ak >1)
513 {
514 return;
515 }
517 if (p!=0)
518 strat->NotUsedAxis[p] = FALSE;
519 /*- the leading term of pp is a power of the p-th variable -*/
520 for (j=(currRing->N);j>0; j--)
521 {
522 if (strat->NotUsedAxis[j])
523 {
524 strat->kAllAxis=FALSE;
525 return;
526 }
527 }
528 strat->kAllAxis=TRUE;
529}
530
531/*2
532*utilities for TSet, LSet
533*/
534inline static intset initec (const int maxnr)
535{
536 return (intset)omAlloc(maxnr*sizeof(int));
537}
538
539inline static unsigned long* initsevS (const int maxnr)
540{
541 return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
542}
543inline static int* initS_2_R (const int maxnr)
544{
545 return (int*)omAlloc0(maxnr*sizeof(int));
546}
547
548static inline void enlargeT (TSet &T, TObject** &R, unsigned long* &sevT,
549 int &length, const int incr)
550{
551 assume(T!=NULL);
552 assume(sevT!=NULL);
553 assume(R!=NULL);
554 assume((length+incr) > 0);
555
556 int i;
557 T = (TSet)omRealloc0Size(T, length*sizeof(TObject),
558 (length+incr)*sizeof(TObject));
559
560 sevT = (unsigned long*) omReallocSize(sevT, length*sizeof(long*),
561 (length+incr)*sizeof(long*));
562
563 R = (TObject**)omRealloc0Size(R,length*sizeof(TObject*),
564 (length+incr)*sizeof(TObject*));
565 for (i=length-1;i>=0;i--) R[T[i].i_r] = &(T[i]);
566 length += incr;
567}
568
569void cleanT (kStrategy strat)
570{
571 int i,j;
572 poly p;
573 assume(currRing == strat->tailRing || strat->tailRing != NULL);
574
575 pShallowCopyDeleteProc p_shallow_copy_delete =
576 (strat->tailRing != currRing ?
578 NULL);
579 for (j=0; j<=strat->tl; j++)
580 {
581 p = strat->T[j].p;
582 strat->T[j].p=NULL;
583 if (strat->T[j].max_exp != NULL)
584 {
585 p_LmFree(strat->T[j].max_exp, strat->tailRing);
586 }
587 i = -1;
588 loop
589 {
590 i++;
591 if (i>strat->sl)
592 {
593 if (strat->T[j].t_p != NULL)
594 {
595 p_Delete(&(strat->T[j].t_p), strat->tailRing);
597 }
598 else
599 {
600#ifdef HAVE_SHIFTBBA
601 if (currRing->isLPring && strat->T[j].shift > 0)
602 {
603 pNext(p) = NULL; // pNext(p) points to the unshifted tail, don't try to delete it here
604 }
605#endif
606 pDelete(&p);
607 }
608 break;
609 }
610 if (p == strat->S[i])
611 {
612 if (strat->T[j].t_p != NULL)
613 {
614 if (p_shallow_copy_delete!=NULL)
615 {
616 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
617 currRing->PolyBin);
618 }
619 p_LmFree(strat->T[j].t_p, strat->tailRing);
620 }
621 break;
622 }
623 }
624 }
625 strat->tl=-1;
626}
627
629{
630 int i,j;
631 poly p;
632 assume(currRing == strat->tailRing || strat->tailRing != NULL);
633
634 pShallowCopyDeleteProc p_shallow_copy_delete =
635 (strat->tailRing != currRing ?
637 NULL);
638 for (j=0; j<=strat->tl; j++)
639 {
640 p = strat->T[j].p;
641 strat->T[j].p=NULL;
642 if (strat->T[j].max_exp != NULL)
643 {
644 p_LmFree(strat->T[j].max_exp, strat->tailRing);
645 }
646 i = -1;
647 loop
648 {
649 i++;
650 if (i>strat->sl)
651 {
652 if (strat->T[j].t_p != NULL)
653 {
654 p_Delete(&(strat->T[j].t_p), strat->tailRing);
656 }
657 else
658 {
659 //pDelete(&p);
660 p = NULL;
661 }
662 break;
663 }
664 if (p == strat->S[i])
665 {
666 if (strat->T[j].t_p != NULL)
667 {
668 assume(p_shallow_copy_delete != NULL);
669 pNext(p) = p_shallow_copy_delete(pNext(p),strat->tailRing,currRing,
670 currRing->PolyBin);
671 p_LmFree(strat->T[j].t_p, strat->tailRing);
672 }
673 break;
674 }
675 }
676 }
677 strat->tl=-1;
678}
679
680//LSet initL ()
681//{
682// int i;
683// LSet l = (LSet)omAlloc(setmaxL*sizeof(LObject));
684// return l;
685//}
686
687static inline void enlargeL (LSet* L,int* length,const int incr)
688{
689 assume((*L)!=NULL);
690 assume(((*length)+incr)>0);
691
692 *L = (LSet)omReallocSize((*L),(*length)*sizeof(LObject),
693 ((*length)+incr)*sizeof(LObject));
694 (*length) += incr;
695}
696
698{
699 strat->pairtest = (BOOLEAN *)omAlloc0((strat->sl+2)*sizeof(BOOLEAN));
700}
701
702/*2
703*test whether (p1,p2) or (p2,p1) is in L up position length
704*it returns TRUE if yes and the position k
705*/
706BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat)
707{
708 LObject *p=&(strat->L[length]);
709
710 *k = length;
711 loop
712 {
713 if ((*k) < 0) return FALSE;
714 if (((p1 == (*p).p1) && (p2 == (*p).p2))
715 || ((p1 == (*p).p2) && (p2 == (*p).p1)))
716 return TRUE;
717 (*k)--;
718 p--;
719 }
720}
721
722/*2
723*in B all pairs have the same element p on the right
724*it tests whether (q,p) is in B and returns TRUE if yes
725*and the position k
726*/
727BOOLEAN isInPairsetB(poly q,int* k,kStrategy strat)
728{
729 LObject *p=&(strat->B[strat->Bl]);
730
731 *k = strat->Bl;
732 loop
733 {
734 if ((*k) < 0) return FALSE;
735 if (q == (*p).p1)
736 return TRUE;
737 (*k)--;
738 p--;
739 }
740}
741
742int kFindInT(poly p, TSet T, int tlength)
743{
744 int i;
745
746 for (i=0; i<=tlength; i++)
747 {
748 if (T[i].p == p) return i;
749 }
750 return -1;
751}
752
753int kFindInT(poly p, kStrategy strat)
754{
755 int i;
756 do
757 {
758 i = kFindInT(p, strat->T, strat->tl);
759 if (i >= 0) return i;
760 strat = strat->next;
761 }
762 while (strat != NULL);
763 return -1;
764}
765
766#ifdef HAVE_SHIFTBBA
767int kFindInTShift(poly p, TSet T, int tlength)
768{
769 int i;
770
771 for (i=0; i<=tlength; i++)
772 {
773 // in the Letterplace ring the LMs in T and L are copies thus we have to use pEqualPolys() instead of ==
774 if (pEqualPolys(T[i].p, p)) return i;
775 }
776 return -1;
777}
778#endif
779
780#ifdef HAVE_SHIFTBBA
781int kFindInTShift(poly p, kStrategy strat)
782{
783 int i;
784 do
785 {
786 i = kFindInTShift(p, strat->T, strat->tl);
787 if (i >= 0) return i;
788 strat = strat->next;
789 }
790 while (strat != NULL);
791 return -1;
792}
793#endif
794
795#ifdef KDEBUG
796
798{
799 if (t_p != NULL) p_wrp(t_p, tailRing);
800 else if (p != NULL) p_wrp(p, currRing, tailRing);
801 else ::wrp(NULL);
802}
803
804#define kFalseReturn(x) do { if (!x) return FALSE;} while (0)
805
806// check that Lm's of a poly from T are "equal"
807static const char* kTest_LmEqual(poly p, poly t_p, ring tailRing)
808{
809 int i;
810 for (i=1; i<=tailRing->N; i++)
811 {
812 if (p_GetExp(p, i, currRing) != p_GetExp(t_p, i, tailRing))
813 return "Lm[i] different";
814 }
815 if (p_GetComp(p, currRing) != p_GetComp(t_p, tailRing))
816 return "Lm[0] different";
817 if (pNext(p) != pNext(t_p))
818 return "Lm.next different";
819 if (pGetCoeff(p) != pGetCoeff(t_p))
820 return "Lm.coeff different";
821 return NULL;
822}
823
825BOOLEAN kTest_T(TObject * T, kStrategy strat, int i, char TN)
826{
827 ring tailRing = T->tailRing;
828 ring strat_tailRing = strat->tailRing;
829 if (strat_tailRing == NULL) strat_tailRing = tailRing;
830 r_assume(strat_tailRing == tailRing);
831
832 poly p = T->p;
833 // ring r = currRing;
834
835 if (T->p == NULL && T->t_p == NULL && i >= 0)
836 return dReportError("%c[%d].poly is NULL", TN, i);
837
838 if (T->p!=NULL)
839 {
840 nTest(pGetCoeff(T->p));
841 if ((T->t_p==NULL)&&(pNext(T->p)!=NULL)) p_Test(pNext(T->p),currRing);
842 }
843 if (T->t_p!=NULL)
844 {
845 nTest(pGetCoeff(T->t_p));
846 if (pNext(T->t_p)!=NULL) p_Test(pNext(T->t_p),strat_tailRing);
847 }
848 if ((T->p!=NULL)&&(T->t_p!=NULL)) assume(pGetCoeff(T->p)==pGetCoeff(T->t_p));
849
850 if (T->tailRing != currRing)
851 {
852 if (T->t_p == NULL && i > 0)
853 return dReportError("%c[%d].t_p is NULL", TN, i);
854 pFalseReturn(p_Test(T->t_p, T->tailRing));
855 if (T->p != NULL) pFalseReturn(p_LmTest(T->p, currRing));
856 if ((T->p != NULL) && (T->t_p != NULL))
857 {
858 const char* msg = kTest_LmEqual(T->p, T->t_p, T->tailRing);
859 if (msg != NULL)
860 return dReportError("%c[%d] %s", TN, i, msg);
861 // r = T->tailRing;
862 p = T->t_p;
863 }
864 if (T->p == NULL)
865 {
866 p = T->t_p;
867 // r = T->tailRing;
868 }
869 if (T->t_p != NULL && i >= 0 && TN == 'T')
870 {
871 if (pNext(T->t_p) == NULL)
872 {
873 if (T->max_exp != NULL)
874 return dReportError("%c[%d].max_exp is not NULL as it should be", TN, i);
875 }
876 else
877 {
878 if (T->max_exp == NULL)
879 return dReportError("%c[%d].max_exp is NULL", TN, i);
880 if (pNext(T->max_exp) != NULL)
881 return dReportError("pNext(%c[%d].max_exp) != NULL", TN, i);
882
883 pFalseReturn(p_CheckPolyRing(T->max_exp, tailRing));
884 omCheckBinAddrSize(T->max_exp, (omSizeWOfBin(tailRing->PolyBin))*SIZEOF_LONG);
885#if KDEBUG > 0
886 if (! sloppy_max)
887 {
888 poly test_max = p_GetMaxExpP(pNext(T->t_p), tailRing);
889 p_Setm(T->max_exp, tailRing);
890 p_Setm(test_max, tailRing);
891 BOOLEAN equal = p_ExpVectorEqual(T->max_exp, test_max, tailRing);
892 if (! equal)
893 return dReportError("%c[%d].max out of sync", TN, i);
894 p_LmFree(test_max, tailRing);
895 }
896#endif
897 }
898 }
899 }
900 else
901 {
902 if (T->p == NULL && i > 0)
903 return dReportError("%c[%d].p is NULL", TN, i);
904#ifdef HAVE_SHIFTBBA
905 if (currRing->isLPring && T->shift > 0)
906 {
907 // in this case, the order is not correct. test LM and tail separately
910 }
911 else
912#endif
913 {
915 }
916 }
917
918 if ((i >= 0) && (T->pLength != 0)
919 && (! rIsSyzIndexRing(currRing)) && (T->pLength != pLength(p)))
920 {
921 int l=T->pLength;
922 T->pLength=pLength(p);
923 return dReportError("%c[%d] pLength error: has %d, specified to have %d",
924 TN, i , pLength(p), l);
925 }
926
927 // check FDeg, for elements in L and T
928 if (i >= 0 && (TN == 'T' || TN == 'L'))
929 {
930 // FDeg has ir element from T of L set
931 if (strat->homog && (T->FDeg != T->pFDeg()))
932 {
933 int d=T->FDeg;
934 T->FDeg=T->pFDeg();
935 return dReportError("%c[%d] FDeg error: has %d, specified to have %d",
936 TN, i , T->pFDeg(), d);
937 }
938 }
939
940 // check is_normalized for elements in T
941 if (i >= 0 && TN == 'T')
942 {
943 if (T->is_normalized && ! nIsOne(pGetCoeff(p)))
944 return dReportError("T[%d] is_normalized error", i);
945
946 }
947 return TRUE;
948}
949
951 BOOLEAN testp, int lpos, TSet T, int tlength)
952{
953 ring strat_tailRing=strat->tailRing;
954 if (L->p!=NULL)
955 {
956 if ((L->t_p==NULL)
957 &&(pNext(L->p)!=NULL)
958 &&(pGetCoeff(pNext(L->p))!=NULL)) /* !=strat->tail*/
959 {
960 p_Test(pNext(L->p),currRing);
961 nTest(pGetCoeff(L->p));
962 }
963 }
964 if (L->t_p!=NULL)
965 {
966 if ((pNext(L->t_p)!=NULL)
967 &&(pGetCoeff(pNext(L->t_p))!=NULL)) /* !=strat->tail*/
968 {
969 p_Test(pNext(L->t_p),strat_tailRing);
970 nTest(pGetCoeff(L->t_p));
971 }
972 }
973 if ((L->p!=NULL)&&(L->t_p!=NULL)) assume(pGetCoeff(L->p)==pGetCoeff(L->t_p));
974
975 if (testp)
976 {
977 poly pn = NULL;
978 if (L->bucket != NULL)
979 {
980 kFalseReturn(kbTest(L->bucket));
981 r_assume(L->bucket->bucket_ring == L->tailRing);
982 if (L->p != NULL && pNext(L->p) != NULL)
983 {
984 pn = pNext(L->p);
985 pNext(L->p) = NULL;
986 }
987 }
988 kFalseReturn(kTest_T(L, strat, lpos, 'L'));
989 if (pn != NULL)
990 pNext(L->p) = pn;
991
992 ring r;
993 poly p;
994 L->GetLm(p, r);
995 if (L->sev != 0L)
996 {
997 if (p_GetShortExpVector(p, r) != L->sev)
998 {
999 return dReportError("L[%d] wrong sev: has %lo, specified to have %lo",
1000 lpos, p_GetShortExpVector(p, r), L->sev);
1001 }
1002 }
1003 }
1004 if (L->p1 == NULL)
1005 {
1006 // L->p2 either NULL or "normal" poly
1007 pFalseReturn(pp_Test(L->p2, currRing, L->tailRing));
1008 }
1009 else if (tlength > 0 && T != NULL && (lpos >=0))
1010 {
1011 // now p1 and p2 must be != NULL and must be contained in T
1012 int i;
1013#ifdef HAVE_SHIFTBBA
1014 if (rIsLPRing(currRing))
1015 i = kFindInTShift(L->p1, T, tlength);
1016 else
1017#endif
1018 i = kFindInT(L->p1, T, tlength);
1019 if (i < 0)
1020 return dReportError("L[%d].p1 not in T",lpos);
1021#ifdef HAVE_SHIFTBBA
1022 if (rIsLPRing(currRing))
1023 {
1024 if (rField_is_Ring(currRing)) return TRUE; // m*shift(q) is not in T
1025 i = kFindInTShift(L->p2, T, tlength);
1026 }
1027 else
1028#endif
1029 i = kFindInT(L->p2, T, tlength);
1030 if (i < 0)
1031 return dReportError("L[%d].p2 not in T",lpos);
1032 }
1033 return TRUE;
1034}
1035
1037{
1038 int i;
1039 // test P
1040 kFalseReturn(kTest_L(&(strat->P), strat,
1041 (strat->P.p != NULL && pNext(strat->P.p)!=strat->tail),
1042 -1, strat->T, strat->tl));
1043
1044 // test T
1045 if (strat->T != NULL)
1046 {
1047 for (i=0; i<=strat->tl; i++)
1048 {
1049 kFalseReturn(kTest_T(&(strat->T[i]), strat, i, 'T'));
1050 if (strat->sevT[i] != pGetShortExpVector(strat->T[i].p))
1051 return dReportError("strat->sevT[%d] out of sync", i);
1052 }
1053 }
1054
1055 // test L
1056 if (strat->L != NULL)
1057 {
1058 for (i=0; i<=strat->Ll; i++)
1059 {
1060 kFalseReturn(kTest_L(&(strat->L[i]), strat,
1061 strat->L[i].Next() != strat->tail, i,
1062 strat->T, strat->tl));
1063 // may be unused
1064 //if (strat->use_buckets && strat->L[i].Next() != strat->tail &&
1065 // strat->L[i].Next() != NULL && strat->L[i].p1 != NULL)
1066 //{
1067 // assume(strat->L[i].bucket != NULL);
1068 //}
1069 }
1070 }
1071
1072 // test S
1073 if (strat->S != NULL)
1074 kFalseReturn(kTest_S(strat));
1075
1076 return TRUE;
1077}
1078
1080{
1081 int i;
1082 BOOLEAN ret = TRUE;
1083 for (i=0; i<=strat->sl; i++)
1084 {
1085 if (strat->S[i] != NULL &&
1086 strat->sevS[i] != pGetShortExpVector(strat->S[i]))
1087 {
1088 return dReportError("S[%d] wrong sev: has %o, specified to have %o",
1089 i , pGetShortExpVector(strat->S[i]), strat->sevS[i]);
1090 }
1091 }
1092 return ret;
1093}
1094
1095
1096
1098{
1099 int i, j;
1100 // BOOLEAN ret = TRUE;
1101 kFalseReturn(kTest(strat));
1102
1103 // test strat->R, strat->T[i].i_r
1104 for (i=0; i<=strat->tl; i++)
1105 {
1106 if (strat->T[i].i_r < 0 || strat->T[i].i_r > strat->tl)
1107 return dReportError("strat->T[%d].i_r == %d out of bounds", i,
1108 strat->T[i].i_r);
1109 if (strat->R[strat->T[i].i_r] != &(strat->T[i]))
1110 return dReportError("T[%d].i_r with R out of sync", i);
1111 }
1112 // test containment of S inT
1113 if ((strat->S != NULL)&&(strat->tl>=0))
1114 {
1115 for (i=0; i<=strat->sl; i++)
1116 {
1117 j = kFindInT(strat->S[i], strat->T, strat->tl);
1118 if (j < 0)
1119 return dReportError("S[%d] not in T", i);
1120 if (strat->S_2_R[i] != strat->T[j].i_r)
1121 return dReportError("S_2_R[%d]=%d != T[%d].i_r=%d\n",
1122 i, strat->S_2_R[i], j, strat->T[j].i_r);
1123 }
1124 }
1125 // test strat->L[i].i_r1
1126 #ifdef HAVE_SHIFTBBA
1127 if (!rIsLPRing(currRing)) // in the Letterplace ring we currently don't set/use i_r1 and i_r2
1128 #endif
1129 if (strat->L!=NULL)
1130 {
1131 for (i=0; i<=strat->Ll; i++)
1132 {
1133 if (strat->L[i].p1 != NULL && strat->L[i].p2)
1134 {
1135 if (strat->L[i].i_r1 < 0 ||
1136 strat->L[i].i_r1 > strat->tl ||
1137 strat->L[i].T_1(strat)->p != strat->L[i].p1)
1138 return dReportError("L[%d].i_r1 out of sync", i);
1139 if (strat->L[i].i_r2 < 0 ||
1140 strat->L[i].i_r2 > strat->tl ||
1141 strat->L[i].T_2(strat)->p != strat->L[i].p2)
1142 return dReportError("L[%d].i_r2 out of sync", i);
1143 }
1144 else
1145 {
1146 if (strat->L[i].i_r1 != -1)
1147 return dReportError("L[%d].i_r1 out of sync", i);
1148 if (strat->L[i].i_r2 != -1)
1149 return dReportError("L[%d].i_r2 out of sync", i);
1150 }
1151 if (strat->L[i].i_r != -1)
1152 return dReportError("L[%d].i_r out of sync", i);
1153 }
1154 }
1155 return TRUE;
1156}
1157
1158#endif // KDEBUG
1159
1160/*2
1161*cancels the i-th polynomial in the standardbase s
1162*/
1163void deleteInS (int i,kStrategy strat)
1164{
1165#ifdef ENTER_USE_MEMMOVE
1166 memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1167 memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1168 memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1169 memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1170#else
1171 int j;
1172 for (j=i; j<strat->sl; j++)
1173 {
1174 strat->S[j] = strat->S[j+1];
1175 strat->ecartS[j] = strat->ecartS[j+1];
1176 strat->sevS[j] = strat->sevS[j+1];
1177 strat->S_2_R[j] = strat->S_2_R[j+1];
1178 }
1179#endif
1180 if (strat->lenS!=NULL)
1181 {
1182#ifdef ENTER_USE_MEMMOVE
1183 memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1184#else
1185 for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1186#endif
1187 }
1188 if (strat->lenSw!=NULL)
1189 {
1190#ifdef ENTER_USE_MEMMOVE
1191 memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1192#else
1193 for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1194#endif
1195 }
1196 if (strat->fromQ!=NULL)
1197 {
1198#ifdef ENTER_USE_MEMMOVE
1199 memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1200#else
1201 for (j=i; j<strat->sl; j++)
1202 {
1203 strat->fromQ[j] = strat->fromQ[j+1];
1204 }
1205#endif
1206 }
1207 strat->S[strat->sl] = NULL;
1208 strat->sl--;
1209}
1210
1211
1212/*2
1213*cancels the i-th polynomial in the standardbase s
1214*/
1215void deleteInSSba (int i,kStrategy strat)
1216{
1217#ifdef ENTER_USE_MEMMOVE
1218 memmove(&(strat->S[i]), &(strat->S[i+1]), (strat->sl - i)*sizeof(poly));
1219 memmove(&(strat->sig[i]), &(strat->sig[i+1]), (strat->sl - i)*sizeof(poly));
1220 memmove(&(strat->ecartS[i]),&(strat->ecartS[i+1]),(strat->sl - i)*sizeof(int));
1221 memmove(&(strat->sevS[i]),&(strat->sevS[i+1]),(strat->sl - i)*sizeof(unsigned long));
1222 memmove(&(strat->sevSig[i]),&(strat->sevSig[i+1]),(strat->sl - i)*sizeof(unsigned long));
1223 memmove(&(strat->S_2_R[i]),&(strat->S_2_R[i+1]),(strat->sl - i)*sizeof(int));
1224#else
1225 int j;
1226 for (j=i; j<strat->sl; j++)
1227 {
1228 strat->S[j] = strat->S[j+1];
1229 strat->sig[j] = strat->sig[j+1];
1230 strat->ecartS[j] = strat->ecartS[j+1];
1231 strat->sevS[j] = strat->sevS[j+1];
1232 strat->sevSig[j] = strat->sevSig[j+1];
1233 strat->S_2_R[j] = strat->S_2_R[j+1];
1234 }
1235#endif
1236 if (strat->lenS!=NULL)
1237 {
1238#ifdef ENTER_USE_MEMMOVE
1239 memmove(&(strat->lenS[i]),&(strat->lenS[i+1]),(strat->sl - i)*sizeof(int));
1240#else
1241 for (j=i; j<strat->sl; j++) strat->lenS[j] = strat->lenS[j+1];
1242#endif
1243 }
1244 if (strat->lenSw!=NULL)
1245 {
1246#ifdef ENTER_USE_MEMMOVE
1247 memmove(&(strat->lenSw[i]),&(strat->lenSw[i+1]),(strat->sl - i)*sizeof(wlen_type));
1248#else
1249 for (j=i; j<strat->sl; j++) strat->lenSw[j] = strat->lenSw[j+1];
1250#endif
1251 }
1252 if (strat->fromQ!=NULL)
1253 {
1254#ifdef ENTER_USE_MEMMOVE
1255 memmove(&(strat->fromQ[i]),&(strat->fromQ[i+1]),(strat->sl - i)*sizeof(int));
1256#else
1257 for (j=i; j<strat->sl; j++)
1258 {
1259 strat->fromQ[j] = strat->fromQ[j+1];
1260 }
1261#endif
1262 }
1263 strat->S[strat->sl] = NULL;
1264 strat->sl--;
1265}
1266
1267#ifdef HAVE_SHIFTBBA
1268static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
1269{
1270 if (rIsLPRing(currRing)
1271 && (strat->P.p1!=NULL))
1272 {
1273 // clean up strat->P.p1: may be shifted
1274 poly p=strat->P.p1;
1275 int lv=currRing->isLPring;
1276 BOOLEAN is_shifted=TRUE;
1277 for (int i=lv;i>0;i--)
1278 {
1279 if (pGetExp(p,i)!=0) { is_shifted=FALSE; break;}
1280 }
1281 if (is_shifted
1282 && (kFindInL1(p, strat)<0)
1283 && (kFindInT(p, strat->T, strat->tl) < 0)
1284 )
1285 {
1286 return TRUE;
1287 }
1288 }
1289 return FALSE;
1290}
1291#endif
1292/*2
1293*cancels the j-th polynomial in the set
1294*/
1295void deleteInL (LSet set, int *length, int j,kStrategy strat)
1296{
1297 if (set[j].lcm!=NULL)
1298 {
1299 kDeleteLcm(&set[j]);
1300 }
1301 if (set[j].sig!=NULL)
1302 {
1303#ifdef HAVE_RINGS
1304 if (pGetCoeff(set[j].sig) != NULL)
1305 pLmDelete(set[j].sig);
1306 else
1307#endif
1308 pLmFree(set[j].sig);
1309 }
1310 if (set[j].p!=NULL)
1311 {
1312 if (pNext(set[j].p) == strat->tail)
1313 {
1314#ifdef HAVE_RINGS
1315 if (pGetCoeff(set[j].p) != NULL)
1316 pLmDelete(set[j].p);
1317 else
1318#endif
1319 pLmFree(set[j].p);
1320 /*- tail belongs to several int spolys -*/
1321 }
1322 else
1323 {
1324 // search p in T, if it is there, do not delete it
1325 if (rHasGlobalOrdering(currRing) || (kFindInT(set[j].p, strat) < 0))
1326 {
1327 // assure that for global orderings kFindInT fails
1328 //assume((rHasLocalOrMixedOrdering(currRing)) && (kFindInT(set[j].p, strat) >= 0));
1329 set[j].Delete();
1330 }
1331 }
1332 }
1333 #ifdef HAVE_SHIFTBBA
1334 if (is_shifted_p1(strat->P.p1,strat))
1335 {
1336 // clean up strat->P.p1: may be shifted
1337 pLmDelete(strat->P.p1);
1338 strat->P.p1=NULL;
1339 }
1340 #endif
1341 if (*length > 0 && j < *length)
1342 {
1343#ifdef ENTER_USE_MEMMOVE
1344 memmove(&(set[j]), &(set[j+1]), (*length - j)*sizeof(LObject));
1345#else
1346 int i;
1347 for (i=j; i < (*length); i++)
1348 set[i] = set[i+1];
1349#endif
1350 }
1351#ifdef KDEBUG
1352 memset(&(set[*length]),0,sizeof(LObject));
1353#endif
1354 (*length)--;
1355}
1356
1357/*2
1358*enters p at position at in L
1359*/
1360void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at)
1361{
1362 // this should be corrected
1363 assume(p.FDeg == p.pFDeg());
1364
1365 if ((*length)>=0)
1366 {
1367 if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmaxLinc);
1368 if (at <= (*length))
1369#ifdef ENTER_USE_MEMMOVE
1370 memmove(&((*set)[at+1]), &((*set)[at]), ((*length)-at+1)*sizeof(LObject));
1371#else
1372 for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1];
1373#endif
1374 }
1375 else at = 0;
1376 (*set)[at] = p;
1377 (*length)++;
1378}
1379
1380/*2
1381* computes the normal ecart;
1382* used in mora case and if pLexOrder & sugar in bba case
1383*/
1385{
1386 h->FDeg = h->pFDeg();
1387 h->ecart = h->pLDeg() - h->FDeg;
1388 // h->length is set by h->pLDeg
1389 h->length=h->pLength=pLength(h->p);
1390}
1391
1393{
1394 h->FDeg = h->pFDeg();
1395 (*h).ecart = 0;
1396 h->length=h->pLength=pLength(h->p);
1397}
1398
1399void initEcartPairBba (LObject* Lp,poly /*f*/,poly /*g*/,int /*ecartF*/,int /*ecartG*/)
1400{
1401 Lp->FDeg = Lp->pFDeg();
1402 (*Lp).ecart = 0;
1403 (*Lp).length = 0;
1404}
1405
1406void initEcartPairMora (LObject* Lp,poly /*f*/,poly /*g*/,int ecartF,int ecartG)
1407{
1408 Lp->FDeg = Lp->pFDeg();
1409 (*Lp).ecart = si_max(ecartF,ecartG);
1410 (*Lp).ecart = (*Lp).ecart- (Lp->FDeg -p_FDeg((*Lp).lcm,currRing));
1411 (*Lp).length = 0;
1412}
1413
1414/*2
1415*if ecart1<=ecart2 it returns TRUE
1416*/
1417static inline BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
1418{
1419 return (ecart1 <= ecart2);
1420}
1421
1422#ifdef HAVE_RINGS
1423/*2
1424* put the pair (s[i],p) into the set B, ecart=ecart(p) (ring case)
1425*/
1426static void enterOnePairRing (int i,poly p,int /*ecart*/, int isFromQ,kStrategy strat, int atR)
1427{
1428 assume(atR >= 0);
1429 assume(i<=strat->sl);
1430 assume(p!=NULL);
1432 #if ALL_VS_JUST
1433 //Over rings, if we construct the strong pair, do not add the spair
1435 {
1436 number s,t,d;
1437 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1438
1439 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
1440 {
1441 nDelete(&d);
1442 nDelete(&s);
1443 nDelete(&t);
1444 return;
1445 }
1446 nDelete(&d);
1447 nDelete(&s);
1448 nDelete(&t);
1449 }
1450 #endif
1451 int j,compare,compareCoeff;
1452 LObject h;
1453
1454#ifdef KDEBUG
1455 h.ecart=0; h.length=0;
1456#endif
1457 /*- computes the lcm(s[i],p) -*/
1458 if(pHasNotCFRing(p,strat->S[i]))
1459 {
1460 strat->cp++;
1461 return;
1462 }
1463 h.lcm = p_Lcm(p,strat->S[i],currRing);
1464 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(strat->S[i]), currRing->cf));
1465 if (nIsZero(pGetCoeff(h.lcm)))
1466 {
1467 strat->cp++;
1468 pLmDelete(h.lcm);
1469 return;
1470 }
1471 // basic chain criterion
1472 /*
1473 *the set B collects the pairs of type (S[j],p)
1474 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
1475 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
1476 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
1477 */
1478
1479 for(j = strat->Bl;j>=0;j--)
1480 {
1481 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
1482 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
1483 if(compare == pDivComp_EQUAL)
1484 {
1485 //They have the same LM
1486 if(compareCoeff == pDivComp_LESS)
1487 {
1488 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1489 {
1490 strat->c3++;
1491 pLmDelete(h.lcm);
1492 return;
1493 }
1494 break;
1495 }
1496 if(compareCoeff == pDivComp_GREATER)
1497 {
1498 deleteInL(strat->B,&strat->Bl,j,strat);
1499 strat->c3++;
1500 }
1501 if(compareCoeff == pDivComp_EQUAL)
1502 {
1503 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1504 {
1505 strat->c3++;
1506 pLmDelete(h.lcm);
1507 return;
1508 }
1509 break;
1510 }
1511 }
1512 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
1513 {
1514 if(compare == pDivComp_LESS)
1515 {
1516 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
1517 {
1518 strat->c3++;
1519 pLmDelete(h.lcm);
1520 return;
1521 }
1522 break;
1523 }
1524 if(compare == pDivComp_GREATER)
1525 {
1526 deleteInL(strat->B,&strat->Bl,j,strat);
1527 strat->c3++;
1528 }
1529 }
1530 }
1531 number s, t;
1532 poly m1, m2, gcd = NULL;
1533 s = pGetCoeff(strat->S[i]);
1534 t = pGetCoeff(p);
1535 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
1536 ksCheckCoeff(&s, &t, currRing->cf);
1537 pSetCoeff0(m1, s);
1538 pSetCoeff0(m2, t);
1539 m2 = pNeg(m2);
1540 p_Test(m1,strat->tailRing);
1541 p_Test(m2,strat->tailRing);
1542 poly si = pCopy(strat->S[i]);
1543 poly pm1 = pp_Mult_mm(pNext(p), m1, strat->tailRing);
1544 poly sim2 = pp_Mult_mm(pNext(si), m2, strat->tailRing);
1545 pDelete(&si);
1546 p_LmDelete(m1, currRing);
1547 p_LmDelete(m2, currRing);
1548 if(sim2 == NULL)
1549 {
1550 if(pm1 == NULL)
1551 {
1552 if(h.lcm != NULL)
1553 {
1554 pLmDelete(h.lcm);
1555 h.lcm=NULL;
1556 }
1557 h.Clear();
1558 if (strat->pairtest==NULL) initPairtest(strat);
1559 strat->pairtest[i] = TRUE;
1560 strat->pairtest[strat->sl+1] = TRUE;
1561 return;
1562 }
1563 else
1564 {
1565 gcd = pm1;
1566 pm1 = NULL;
1567 }
1568 }
1569 else
1570 {
1571 if((pGetComp(strat->S[i]) == 0) && (0 != pGetComp(p)))
1572 {
1573 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
1574 pSetmComp(sim2);
1575 }
1576 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
1577 gcd = p_Add_q(pm1, sim2, strat->tailRing);
1578 }
1579 p_Test(gcd, strat->tailRing);
1580#ifdef KDEBUG
1581 if (TEST_OPT_DEBUG)
1582 {
1583 wrp(gcd);
1584 PrintLn();
1585 }
1586#endif
1587 h.p = gcd;
1588 h.i_r = -1;
1589 if(h.p == NULL)
1590 {
1591 if (strat->pairtest==NULL) initPairtest(strat);
1592 strat->pairtest[i] = TRUE;
1593 strat->pairtest[strat->sl+1] = TRUE;
1594 return;
1595 }
1596 h.tailRing = strat->tailRing;
1597 int posx;
1598 //h.pCleardenom();
1599 //pSetm(h.p);
1600 h.i_r1 = -1;h.i_r2 = -1;
1601 strat->initEcart(&h);
1602 #if 1
1603 h.p2 = strat->S[i];
1604 h.p1 = p;
1605 #endif
1606 #if 1
1607 if (atR >= 0)
1608 {
1609 h.i_r1 = atR;
1610 h.i_r2 = strat->S_2_R[i];
1611 }
1612 #endif
1613 if (strat->Bl==-1)
1614 posx =0;
1615 else
1616 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
1617 h.sev = pGetShortExpVector(h.p);
1618 if (currRing!=strat->tailRing)
1619 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1620 if (strat->P.p!=NULL) strat->P.sev = pGetShortExpVector(strat->P.p);
1621 else strat->P.sev=0L;
1622 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
1623 kTest_TS(strat);
1624}
1625
1626/*2
1627* put the lcm(s[i],p) into the set B
1628*/
1629
1630static BOOLEAN enterOneStrongPoly (int i,poly p,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR, bool enterTstrong)
1631{
1632 number d, s, t;
1633 assume(atR >= 0);
1635 poly m1, m2, gcd,si;
1636 if(!enterTstrong)
1637 {
1638 assume(i<=strat->sl);
1639 si = strat->S[i];
1640 }
1641 else
1642 {
1643 assume(i<=strat->tl);
1644 si = strat->T[i].p;
1645 }
1646 //printf("\n--------------------------------\n");
1647 //pWrite(p);pWrite(si);
1648 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1649
1650 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1651 {
1652 nDelete(&d);
1653 nDelete(&s);
1654 nDelete(&t);
1655 return FALSE;
1656 }
1657
1658 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1659
1661 {
1662 unsigned long sev = pGetShortExpVector(gcd);
1663
1664 for (int j = 0; j < strat->sl; j++)
1665 {
1666 if (j == i)
1667 continue;
1668
1669 if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf)
1670 && !(strat->sevS[j] & ~sev)
1671 && p_LmDivisibleBy(strat->S[j], gcd, currRing))
1672 {
1673 nDelete(&d);
1674 nDelete(&s);
1675 nDelete(&t);
1676 return FALSE;
1677 }
1678 }
1679 }
1680
1681 //p_Test(m1,strat->tailRing);
1682 //p_Test(m2,strat->tailRing);
1683 /*if(!enterTstrong)
1684 {
1685 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1686 {
1687 memset(&(strat->P), 0, sizeof(strat->P));
1688 kStratChangeTailRing(strat);
1689 strat->P = *(strat->R[atR]);
1690 p_LmFree(m1, strat->tailRing);
1691 p_LmFree(m2, strat->tailRing);
1692 p_LmFree(gcd, currRing);
1693 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1694 }
1695 }*/
1696 pSetCoeff0(m1, s);
1697 pSetCoeff0(m2, t);
1698 pSetCoeff0(gcd, d);
1699 p_Test(m1,strat->tailRing);
1700 p_Test(m2,strat->tailRing);
1701 //printf("\n===================================\n");
1702 //pWrite(m1);pWrite(m2);pWrite(gcd);
1703#ifdef KDEBUG
1704 if (TEST_OPT_DEBUG)
1705 {
1706 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1707 PrintS("m1 = ");
1708 p_wrp(m1, strat->tailRing);
1709 PrintS(" ; m2 = ");
1710 p_wrp(m2, strat->tailRing);
1711 PrintS(" ; gcd = ");
1712 wrp(gcd);
1713 PrintS("\n--- create strong gcd poly: ");
1714 Print("\n p: %d", i);
1715 wrp(p);
1716 Print("\n strat->S[%d]: ", i);
1717 wrp(si);
1718 PrintS(" ---> ");
1719 }
1720#endif
1721
1722 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1723 p_LmDelete(m1, strat->tailRing);
1724 p_LmDelete(m2, strat->tailRing);
1725#ifdef KDEBUG
1726 if (TEST_OPT_DEBUG)
1727 {
1728 wrp(gcd);
1729 PrintLn();
1730 }
1731#endif
1732
1733 LObject h;
1734 h.p = gcd;
1735 h.tailRing = strat->tailRing;
1736 int posx;
1737 strat->initEcart(&h);
1738 h.sev = pGetShortExpVector(h.p);
1739 h.i_r1 = -1;h.i_r2 = -1;
1740 if (currRing!=strat->tailRing)
1741 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1742 if(!enterTstrong)
1743 {
1744 #if 1
1745 h.p1 = p;h.p2 = strat->S[i];
1746 #endif
1747 if (atR >= 0)
1748 {
1749 h.i_r2 = strat->S_2_R[i];
1750 h.i_r1 = atR;
1751 }
1752 else
1753 {
1754 h.i_r1 = -1;
1755 h.i_r2 = -1;
1756 }
1757 if (strat->Ll==-1)
1758 posx =0;
1759 else
1760 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
1761 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
1762 }
1763 else
1764 {
1765 if(h.IsNull()) return FALSE;
1766 //int red_result;
1767 //reduzieren ist teur!!!
1768 //if(strat->L != NULL)
1769 //red_result = strat->red(&h,strat);
1770 if(!h.IsNull())
1771 {
1772 enterT(h, strat,-1);
1773 //int pos = posInS(strat,strat->sl,h.p,h.ecart);
1774 //strat->enterS(h,pos,strat,-1);
1775 }
1776 }
1777 return TRUE;
1778}
1779
1781{
1782 if(strat->sl < 0) return FALSE;
1783 int i;
1784 for(i=0;i<strat->sl;i++)
1785 {
1786 //Construct the gcd pair between h and S[i]
1787 number d, s, t;
1788 poly m1, m2, gcd;
1789 d = n_ExtGcd(pGetCoeff(h->p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
1790 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1791 {
1792 nDelete(&d);
1793 nDelete(&s);
1794 nDelete(&t);
1795 }
1796 else
1797 {
1798 k_GetStrongLeadTerms(h->p, strat->S[i], currRing, m1, m2, gcd, strat->tailRing);
1799 pSetCoeff0(m1, s);
1800 pSetCoeff0(m2, t);
1801 pSetCoeff0(gcd, d);
1802 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);
1803 poly pSigMult = p_Copy(h->sig,currRing);
1804 poly sSigMult = p_Copy(strat->sig[i],currRing);
1805 pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1806 sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1807 p_LmDelete(m1, strat->tailRing);
1808 p_LmDelete(m2, strat->tailRing);
1809 poly pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1810 if(pairsig!= NULL && pLtCmp(pairsig,h->sig) == 0)
1811 {
1812 pDelete(&h->p);
1813 h->p = gcd;
1814 pDelete(&h->sig);
1815 h->sig = pairsig;
1816 pNext(h->sig) = NULL;
1817 strat->initEcart(h);
1818 h->sev = pGetShortExpVector(h->p);
1819 h->sevSig = pGetShortExpVector(h->sig);
1820 h->i_r1 = -1;h->i_r2 = -1;
1821 if(h->lcm != NULL)
1822 {
1823 pLmDelete(h->lcm);
1824 h->lcm = NULL;
1825 }
1826 if (currRing!=strat->tailRing)
1827 h->t_p = k_LmInit_currRing_2_tailRing(h->p, strat->tailRing);
1828 return TRUE;
1829 }
1830 //Delete what you didn't use
1831 pDelete(&gcd);
1832 pDelete(&pairsig);
1833 }
1834 }
1835 return FALSE;
1836}
1837
1838static BOOLEAN enterOneStrongPolySig (int i,poly p,poly sig,int /*ecart*/, int /*isFromQ*/,kStrategy strat, int atR)
1839{
1840 number d, s, t;
1841 assume(atR >= 0);
1842 poly m1, m2, gcd,si;
1843 assume(i<=strat->sl);
1844 si = strat->S[i];
1845 //printf("\n--------------------------------\n");
1846 //pWrite(p);pWrite(si);
1847 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(si), &s, &t, currRing->cf);
1848
1849 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
1850 {
1851 nDelete(&d);
1852 nDelete(&s);
1853 nDelete(&t);
1854 return FALSE;
1855 }
1856
1857 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1858 //p_Test(m1,strat->tailRing);
1859 //p_Test(m2,strat->tailRing);
1860 /*if(!enterTstrong)
1861 {
1862 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
1863 {
1864 memset(&(strat->P), 0, sizeof(strat->P));
1865 kStratChangeTailRing(strat);
1866 strat->P = *(strat->R[atR]);
1867 p_LmFree(m1, strat->tailRing);
1868 p_LmFree(m2, strat->tailRing);
1869 p_LmFree(gcd, currRing);
1870 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
1871 }
1872 }*/
1873 pSetCoeff0(m1, s);
1874 pSetCoeff0(m2, t);
1875 pSetCoeff0(gcd, d);
1876 p_Test(m1,strat->tailRing);
1877 p_Test(m2,strat->tailRing);
1878 //printf("\n===================================\n");
1879 //pWrite(m1);pWrite(m2);pWrite(gcd);
1880#ifdef KDEBUG
1881 if (TEST_OPT_DEBUG)
1882 {
1883 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
1884 PrintS("m1 = ");
1885 p_wrp(m1, strat->tailRing);
1886 PrintS(" ; m2 = ");
1887 p_wrp(m2, strat->tailRing);
1888 PrintS(" ; gcd = ");
1889 wrp(gcd);
1890 PrintS("\n--- create strong gcd poly: ");
1891 Print("\n p: %d", i);
1892 wrp(p);
1893 Print("\n strat->S[%d]: ", i);
1894 wrp(si);
1895 PrintS(" ---> ");
1896 }
1897#endif
1898
1899 pNext(gcd) = p_Add_q(pp_Mult_mm(pNext(p), m1, strat->tailRing), pp_Mult_mm(pNext(si), m2, strat->tailRing), strat->tailRing);
1900
1901#ifdef KDEBUG
1902 if (TEST_OPT_DEBUG)
1903 {
1904 wrp(gcd);
1905 PrintLn();
1906 }
1907#endif
1908
1909 //Check and set the signatures
1910 poly pSigMult = p_Copy(sig,currRing);
1911 poly sSigMult = p_Copy(strat->sig[i],currRing);
1912 pSigMult = p_Mult_mm(pSigMult,m1,currRing);
1913 sSigMult = p_Mult_mm(sSigMult,m2,currRing);
1914 p_LmDelete(m1, strat->tailRing);
1915 p_LmDelete(m2, strat->tailRing);
1916 poly pairsig;
1917 if(pLmCmp(pSigMult,sSigMult) == 0)
1918 {
1919 //Same lm, have to add them
1920 pairsig = p_Add_q(pSigMult,sSigMult,currRing);
1921 //This might be zero
1922 }
1923 else
1924 {
1925 //Set the sig to either pSigMult or sSigMult
1926 if(pLtCmp(pSigMult,sSigMult)==1)
1927 {
1928 pairsig = pSigMult;
1929 pDelete(&sSigMult);
1930 }
1931 else
1932 {
1933 pairsig = sSigMult;
1934 pDelete(&pSigMult);
1935 }
1936 }
1937
1938 LObject h;
1939 h.p = gcd;
1940 h.tailRing = strat->tailRing;
1941 h.sig = pairsig;
1942 int posx;
1943 strat->initEcart(&h);
1944 h.sev = pGetShortExpVector(h.p);
1945 h.i_r1 = -1;h.i_r2 = -1;
1946 if (currRing!=strat->tailRing)
1947 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
1948 if(h.sig == NULL)
1949 {
1950 //sigdrop since we loose the signature
1951 strat->sigdrop = TRUE;
1952 //Try to reduce it as far as we can via redRing
1953 int red_result = redRing(&h,strat);
1954 if(red_result == 0)
1955 {
1956 // Cancel the sigdrop
1957 p_Delete(&h.sig,currRing);h.sig = NULL;
1958 strat->sigdrop = FALSE;
1959 return FALSE;
1960 }
1961 else
1962 {
1963 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1964 #if 1
1965 strat->enterS(h,0,strat,strat->tl);
1966 #endif
1967 return FALSE;
1968 }
1969 }
1970 if(!nGreaterZero(pGetCoeff(h.sig)))
1971 {
1972 h.sig = pNeg(h.sig);
1973 h.p = pNeg(h.p);
1974 }
1975
1976 if(rField_is_Ring(currRing) && pLtCmp(h.sig,sig) == -1)
1977 {
1978 strat->sigdrop = TRUE;
1979 // Completely reduce it
1980 int red_result = redRing(&h,strat);
1981 if(red_result == 0)
1982 {
1983 // Reduced to 0
1984 strat->sigdrop = FALSE;
1985 p_Delete(&h.sig,currRing);h.sig = NULL;
1986 return FALSE;
1987 }
1988 else
1989 {
1990 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
1991 // 0 - add just the original poly causing the sigdrop, 1 - add also this
1992 #if 1
1993 strat->enterS(h,0,strat, strat->tl+1);
1994 #endif
1995 return FALSE;
1996 }
1997 }
1998 //Check for sigdrop
1999 if(gcd != NULL && pLtCmp(sig,pairsig) > 0 && pLtCmp(strat->sig[i],pairsig) > 0)
2000 {
2001 strat->sigdrop = TRUE;
2002 //Enter this element to S
2003 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2004 strat->enterS(h,strat->sl+1,strat,strat->tl+1);
2005 }
2006 #if 1
2007 h.p1 = p;h.p2 = strat->S[i];
2008 #endif
2009 if (atR >= 0)
2010 {
2011 h.i_r2 = strat->S_2_R[i];
2012 h.i_r1 = atR;
2013 }
2014 else
2015 {
2016 h.i_r1 = -1;
2017 h.i_r2 = -1;
2018 }
2019 if (strat->Ll==-1)
2020 posx =0;
2021 else
2022 posx = strat->posInLSba(strat->L,strat->Ll,&h,strat);
2023 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
2024 return TRUE;
2025}
2026#endif
2027
2028/*2
2029* put the pair (s[i],p) into the set B, ecart=ecart(p)
2030*/
2031
2032void enterOnePairNormal (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2033{
2034 assume(i<=strat->sl);
2035
2036 int l,j,compare;
2037 LObject Lp;
2038 Lp.i_r = -1;
2039
2040#ifdef KDEBUG
2041 Lp.ecart=0; Lp.length=0;
2042#endif
2043 /*- computes the lcm(s[i],p) -*/
2044 Lp.lcm = pInit();
2045
2046#ifndef HAVE_RATGRING
2047 pLcm(p,strat->S[i],Lp.lcm);
2048#elif defined(HAVE_RATGRING)
2049 if (rIsRatGRing(currRing))
2050 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2051 else
2052 pLcm(p,strat->S[i],Lp.lcm);
2053#endif
2054 pSetm(Lp.lcm);
2055
2056
2057 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
2058 {
2059 if (strat->fromT && (strat->ecartS[i]>ecart))
2060 {
2061 pLmFree(Lp.lcm);
2062 return;
2063 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2064 }
2065 if((!((strat->ecartS[i]>0)&&(ecart>0)))
2066 && pHasNotCF(p,strat->S[i]))
2067 {
2068 /*
2069 *the product criterion has applied for (s,p),
2070 *i.e. lcm(s,p)=product of the leading terms of s and p.
2071 *Suppose (s,r) is in L and the leading term
2072 *of p divides lcm(s,r)
2073 *(==> the leading term of p divides the leading term of r)
2074 *but the leading term of s does not divide the leading term of r
2075 *(notice that tis condition is automatically satisfied if r is still
2076 *in S), then (s,r) can be cancelled.
2077 *This should be done here because the
2078 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2079 *
2080 *Moreover, skipping (s,r) holds also for the noncommutative case.
2081 */
2082 strat->cp++;
2083 pLmFree(Lp.lcm);
2084 return;
2085 }
2086 Lp.ecart = si_max(ecart,strat->ecartS[i]);
2087 /*
2088 *the set B collects the pairs of type (S[j],p)
2089 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2090 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2091 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2092 */
2093 {
2094 j = strat->Bl;
2095 loop
2096 {
2097 if (j < 0) break;
2098 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2099 if ((compare==1)
2100 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2101 {
2102 strat->c3++;
2103 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2104 {
2105 pLmFree(Lp.lcm);
2106 return;
2107 }
2108 break;
2109 }
2110 else
2111 if ((compare ==-1)
2112 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2113 {
2114 deleteInL(strat->B,&strat->Bl,j,strat);
2115 strat->c3++;
2116 }
2117 j--;
2118 }
2119 }
2120 }
2121 else /*sugarcrit*/
2122 {
2123 if (ALLOW_PROD_CRIT(strat))
2124 {
2125 if (strat->fromT && (strat->ecartS[i]>ecart))
2126 {
2127 pLmFree(Lp.lcm);
2128 return;
2129 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2130 }
2131 // if currRing->nc_type!=quasi (or skew)
2132 // TODO: enable productCrit for super commutative algebras...
2133 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2134 pHasNotCF(p,strat->S[i]))
2135 {
2136 /*
2137 *the product criterion has applied for (s,p),
2138 *i.e. lcm(s,p)=product of the leading terms of s and p.
2139 *Suppose (s,r) is in L and the leading term
2140 *of p divides lcm(s,r)
2141 *(==> the leading term of p divides the leading term of r)
2142 *but the leading term of s does not divide the leading term of r
2143 *(notice that tis condition is automatically satisfied if r is still
2144 *in S), then (s,r) can be canceled.
2145 *This should be done here because the
2146 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2147 */
2148 strat->cp++;
2149 pLmFree(Lp.lcm);
2150 return;
2151 }
2152 /*
2153 *the set B collects the pairs of type (S[j],p)
2154 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2155 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2156 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2157 */
2158 for(j = strat->Bl;j>=0;j--)
2159 {
2160 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2161 if (compare==1)
2162 {
2163 strat->c3++;
2164 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2165 {
2166 pLmFree(Lp.lcm);
2167 return;
2168 }
2169 break;
2170 }
2171 else
2172 if (compare ==-1)
2173 {
2174 deleteInL(strat->B,&strat->Bl,j,strat);
2175 strat->c3++;
2176 }
2177 }
2178 }
2179 }
2180 /*
2181 *the pair (S[i],p) enters B if the spoly != 0
2182 */
2183 /*- compute the short s-polynomial -*/
2184 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2185 pNorm(p);
2186
2187 if ((strat->S[i]==NULL) || (p==NULL))
2188 return;
2189
2190 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2191 Lp.p=NULL;
2192 else
2193 {
2194 #ifdef HAVE_PLURAL
2195 if ( rIsPluralRing(currRing) )
2196 {
2197 if(pHasNotCF(p, strat->S[i]))
2198 {
2199 if(ncRingType(currRing) == nc_lie)
2200 {
2201 // generalized prod-crit for lie-type
2202 strat->cp++;
2203 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2204 }
2205 else
2206 if( ALLOW_PROD_CRIT(strat) )
2207 {
2208 // product criterion for homogeneous case in SCA
2209 strat->cp++;
2210 Lp.p = NULL;
2211 }
2212 else
2213 {
2214 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2215 nc_CreateShortSpoly(strat->S[i], p, currRing);
2216 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2217 pNext(Lp.p) = strat->tail; // !!!
2218 }
2219 }
2220 else
2221 {
2222 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2223 nc_CreateShortSpoly(strat->S[i], p, currRing);
2224
2225 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2226 pNext(Lp.p) = strat->tail; // !!!
2227 }
2228 }
2229 else
2230 #endif
2231 {
2233 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2234 }
2235 }
2236 if (Lp.p == NULL)
2237 {
2238 /*- the case that the s-poly is 0 -*/
2239 if (strat->pairtest==NULL) initPairtest(strat);
2240 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2241 strat->pairtest[strat->sl+1] = TRUE;
2242 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2243 /*
2244 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2245 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2246 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2247 *term of p divides the lcm(s,r)
2248 *(this canceling should be done here because
2249 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2250 *the first case is handeled in chainCrit
2251 */
2252 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2253 }
2254 else
2255 {
2256 /*- the pair (S[i],p) enters B -*/
2257 Lp.p1 = strat->S[i];
2258 Lp.p2 = p;
2259
2260 if (
2262// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2263 )
2264 {
2265 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2266 pNext(Lp.p) = strat->tail; // !!!
2267 }
2268
2269 if (atR >= 0)
2270 {
2271 Lp.i_r1 = strat->S_2_R[i];
2272 Lp.i_r2 = atR;
2273 }
2274 else
2275 {
2276 Lp.i_r1 = -1;
2277 Lp.i_r2 = -1;
2278 }
2279 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2280
2282 {
2285 && (Lp.p->coef!=NULL))
2286 nDelete(&(Lp.p->coef));
2287 }
2288
2289 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2290 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2291 }
2292}
2293
2294/// p_HasNotCF for the IDLIFT case and syzComp==1: ignore component
2295static inline BOOLEAN p_HasNotCF_Lift(poly p1, poly p2, const ring r)
2296{
2297 int i = rVar(r);
2298 loop
2299 {
2300 if ((p_GetExp(p1, i, r) > 0) && (p_GetExp(p2, i, r) > 0))
2301 return FALSE;
2302 i--;
2303 if (i == 0)
2304 return TRUE;
2305 }
2306}
2307
2308/*2
2309* put the pair (s[i],p) into the set B, ecart=ecart(p) for idLift(I,T)
2310* (in the special case: idLift for ideals, i.e. strat->syzComp==1)
2311* (prod.crit applies)
2312*/
2313
2314static void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR = -1)
2315{
2316 assume(ALLOW_PROD_CRIT(strat));
2318 assume(i<=strat->sl);
2319 assume(strat->syzComp==1);
2320
2321 if ((strat->S[i]==NULL) || (p==NULL))
2322 return;
2323
2324 int l,j,compare;
2325 LObject Lp;
2326 Lp.i_r = -1;
2327
2328#ifdef KDEBUG
2329 Lp.ecart=0; Lp.length=0;
2330#endif
2331 /*- computes the lcm(s[i],p) -*/
2332 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
2333
2334 if (strat->sugarCrit)
2335 {
2336 if((!((strat->ecartS[i]>0)&&(ecart>0)))
2337 && p_HasNotCF_Lift(p,strat->S[i],currRing))
2338 {
2339 /*
2340 *the product criterion has applied for (s,p),
2341 *i.e. lcm(s,p)=product of the leading terms of s and p.
2342 *Suppose (s,r) is in L and the leading term
2343 *of p divides lcm(s,r)
2344 *(==> the leading term of p divides the leading term of r)
2345 *but the leading term of s does not divide the leading term of r
2346 *(notice that tis condition is automatically satisfied if r is still
2347 *in S), then (s,r) can be cancelled.
2348 *This should be done here because the
2349 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2350 *
2351 *Moreover, skipping (s,r) holds also for the noncommutative case.
2352 */
2353 strat->cp++;
2354 pLmFree(Lp.lcm);
2355 return;
2356 }
2357 else
2358 Lp.ecart = si_max(ecart,strat->ecartS[i]);
2359 if (strat->fromT && (strat->ecartS[i]>ecart))
2360 {
2361 pLmFree(Lp.lcm);
2362 return;
2363 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2364 }
2365 /*
2366 *the set B collects the pairs of type (S[j],p)
2367 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2368 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2369 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2370 */
2371 {
2372 j = strat->Bl;
2373 loop
2374 {
2375 if (j < 0) break;
2376 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2377 if ((compare==1)
2378 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
2379 {
2380 strat->c3++;
2381 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2382 {
2383 pLmFree(Lp.lcm);
2384 return;
2385 }
2386 break;
2387 }
2388 else
2389 if ((compare ==-1)
2390 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
2391 {
2392 deleteInL(strat->B,&strat->Bl,j,strat);
2393 strat->c3++;
2394 }
2395 j--;
2396 }
2397 }
2398 }
2399 else /*sugarcrit*/
2400 {
2401 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
2402 p_HasNotCF_Lift(p,strat->S[i],currRing))
2403 {
2404 /*
2405 *the product criterion has applied for (s,p),
2406 *i.e. lcm(s,p)=product of the leading terms of s and p.
2407 *Suppose (s,r) is in L and the leading term
2408 *of p divides lcm(s,r)
2409 *(==> the leading term of p divides the leading term of r)
2410 *but the leading term of s does not divide the leading term of r
2411 *(notice that tis condition is automatically satisfied if r is still
2412 *in S), then (s,r) can be canceled.
2413 *This should be done here because the
2414 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
2415 */
2416 strat->cp++;
2417 pLmFree(Lp.lcm);
2418 return;
2419 }
2420 if (strat->fromT && (strat->ecartS[i]>ecart))
2421 {
2422 pLmFree(Lp.lcm);
2423 return;
2424 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
2425 }
2426 /*
2427 *the set B collects the pairs of type (S[j],p)
2428 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
2429 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
2430 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
2431 */
2432 for(j = strat->Bl;j>=0;j--)
2433 {
2434 compare=pDivComp(strat->B[j].lcm,Lp.lcm);
2435 if (compare==1)
2436 {
2437 strat->c3++;
2438 if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0))
2439 {
2440 pLmFree(Lp.lcm);
2441 return;
2442 }
2443 break;
2444 }
2445 else
2446 if (compare ==-1)
2447 {
2448 deleteInL(strat->B,&strat->Bl,j,strat);
2449 strat->c3++;
2450 }
2451 }
2452 }
2453 /*
2454 *the pair (S[i],p) enters B if the spoly != 0
2455 */
2456 /*- compute the short s-polynomial -*/
2457 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2458 pNorm(p);
2459
2460 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2461 Lp.p=NULL;
2462 else
2463 {
2465 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2466 }
2467 if (Lp.p == NULL)
2468 {
2469 /*- the case that the s-poly is 0 -*/
2470 if (strat->pairtest==NULL) initPairtest(strat);
2471 strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
2472 strat->pairtest[strat->sl+1] = TRUE;
2473 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
2474 /*
2475 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
2476 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
2477 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
2478 *term of p divides the lcm(s,r)
2479 *(this canceling should be done here because
2480 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
2481 *the first case is handeled in chainCrit
2482 */
2483 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2484 }
2485 else
2486 {
2487 /*- the pair (S[i],p) enters B -*/
2488 Lp.p1 = strat->S[i];
2489 Lp.p2 = p;
2490
2491 pNext(Lp.p) = strat->tail; // !!!
2492
2493 if (atR >= 0)
2494 {
2495 Lp.i_r1 = strat->S_2_R[i];
2496 Lp.i_r2 = atR;
2497 }
2498 else
2499 {
2500 Lp.i_r1 = -1;
2501 Lp.i_r2 = -1;
2502 }
2503 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2504
2506 {
2509 && (Lp.p->coef!=NULL))
2510 nDelete(&(Lp.p->coef));
2511 }
2512
2513 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
2514 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2515 }
2516}
2517
2518/*2
2519* put the pair (s[i],p) into the set B, ecart=ecart(p)
2520* NOTE: here we need to add the signature-based criteria
2521*/
2522
2523#ifdef DEBUGF5
2524static void enterOnePairSig (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2525#else
2526static void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2527#endif
2528{
2529 assume(i<=strat->sl);
2530
2531 int l;
2532 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2533 // the corresponding signatures for criteria checks
2534 LObject Lp;
2535 poly pSigMult = p_Copy(pSig,currRing);
2536 poly sSigMult = p_Copy(strat->sig[i],currRing);
2537 unsigned long pSigMultNegSev,sSigMultNegSev;
2538 Lp.i_r = -1;
2539
2540#ifdef KDEBUG
2541 Lp.ecart=0; Lp.length=0;
2542#endif
2543 /*- computes the lcm(s[i],p) -*/
2544 Lp.lcm = pInit();
2545 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2546#ifndef HAVE_RATGRING
2547 pLcm(p,strat->S[i],Lp.lcm);
2548#elif defined(HAVE_RATGRING)
2549 if (rIsRatGRing(currRing))
2550 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2551 else
2552 pLcm(p,strat->S[i],Lp.lcm);
2553#endif
2554 pSetm(Lp.lcm);
2555
2556 // set coeffs of multipliers m1 and m2
2557 pSetCoeff0(m1, nInit(1));
2558 pSetCoeff0(m2, nInit(1));
2559//#if 1
2560#ifdef DEBUGF5
2561 PrintS("P1 ");
2562 pWrite(pHead(p));
2563 PrintS("P2 ");
2564 pWrite(pHead(strat->S[i]));
2565 PrintS("M1 ");
2566 pWrite(m1);
2567 PrintS("M2 ");
2568 pWrite(m2);
2569#endif
2570 // get multiplied signatures for testing
2571 pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
2572 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2573 sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
2574 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2575
2576//#if 1
2577#ifdef DEBUGF5
2578 PrintS("----------------\n");
2579 pWrite(pSigMult);
2580 pWrite(sSigMult);
2581 PrintS("----------------\n");
2582 Lp.checked = 0;
2583#endif
2584 int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2585//#if 1
2586#if DEBUGF5
2587 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2588 pWrite(pSigMult);
2589 pWrite(sSigMult);
2590#endif
2591 if(sigCmp==0)
2592 {
2593 // printf("!!!! EQUAL SIGS !!!!\n");
2594 // pSig = sSig, delete element due to Rewritten Criterion
2595 pDelete(&pSigMult);
2596 pDelete(&sSigMult);
2598 pLmDelete(Lp.lcm);
2599 else
2600 pLmFree(Lp.lcm);
2601 pDelete (&m1);
2602 pDelete (&m2);
2603 return;
2604 }
2605 // testing by syzCrit = F5 Criterion
2606 // testing by rewCrit1 = Rewritten Criterion
2607 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2608 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2609 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2610 || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2611 )
2612 {
2613 pDelete(&pSigMult);
2614 pDelete(&sSigMult);
2616 pLmDelete(Lp.lcm);
2617 else
2618 pLmFree(Lp.lcm);
2619 pDelete (&m1);
2620 pDelete (&m2);
2621 return;
2622 }
2623 /*
2624 *the pair (S[i],p) enters B if the spoly != 0
2625 */
2626 /*- compute the short s-polynomial -*/
2627 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2628 pNorm(p);
2629
2630 if ((strat->S[i]==NULL) || (p==NULL))
2631 return;
2632
2633 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2634 Lp.p=NULL;
2635 else
2636 {
2637 #ifdef HAVE_PLURAL
2638 if ( rIsPluralRing(currRing) )
2639 {
2640 if(pHasNotCF(p, strat->S[i]))
2641 {
2642 if(ncRingType(currRing) == nc_lie)
2643 {
2644 // generalized prod-crit for lie-type
2645 strat->cp++;
2646 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
2647 }
2648 else
2649 if( ALLOW_PROD_CRIT(strat) )
2650 {
2651 // product criterion for homogeneous case in SCA
2652 strat->cp++;
2653 Lp.p = NULL;
2654 }
2655 else
2656 {
2657 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2658 nc_CreateShortSpoly(strat->S[i], p, currRing);
2659
2660 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2661 pNext(Lp.p) = strat->tail; // !!!
2662 }
2663 }
2664 else
2665 {
2666 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
2667 nc_CreateShortSpoly(strat->S[i], p, currRing);
2668
2669 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2670 pNext(Lp.p) = strat->tail; // !!!
2671 }
2672 }
2673 else
2674 #endif
2675 {
2677 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
2678 }
2679 }
2680 // store from which element this pair comes from for further tests
2681 //Lp.from = strat->sl+1;
2682 if(sigCmp==currRing->OrdSgn)
2683 {
2684 // pSig > sSig
2685 pDelete (&sSigMult);
2686 Lp.sig = pSigMult;
2687 Lp.sevSig = ~pSigMultNegSev;
2688 }
2689 else
2690 {
2691 // pSig < sSig
2692 pDelete (&pSigMult);
2693 Lp.sig = sSigMult;
2694 Lp.sevSig = ~sSigMultNegSev;
2695 }
2696 if (Lp.p == NULL)
2697 {
2698 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
2699 int pos = posInSyz(strat, Lp.sig);
2700 enterSyz(Lp, strat, pos);
2701 }
2702 else
2703 {
2704 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
2705 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
2706 {
2707 pLmFree(Lp.lcm);
2708 pDelete(&Lp.sig);
2709 pDelete (&m1);
2710 pDelete (&m2);
2711 return;
2712 }
2713 // in any case Lp is checked up to the next strat->P which is added
2714 // to S right after this critical pair creation.
2715 // NOTE: this even holds if the 2nd generator gives the bigger signature
2716 // moreover, this improves rewCriterion,
2717 // i.e. strat->checked > strat->from if and only if the 2nd generator
2718 // gives the bigger signature.
2719 Lp.checked = strat->sl+1;
2720 // at this point it is clear that the pair will be added to L, since it has
2721 // passed all tests up to now
2722
2723 // adds buchberger's first criterion
2724 if (pLmCmp(m2,pHead(p)) == 0)
2725 {
2726 Lp.prod_crit = TRUE; // Product Criterion
2727#if 0
2728 int pos = posInSyz(strat, Lp.sig);
2729 enterSyz(Lp, strat, pos);
2730 pDelete (&m1);
2731 pDelete (&m2);
2732 return;
2733#endif
2734 }
2735 pDelete (&m1);
2736 pDelete (&m2);
2737#if DEBUGF5
2738 PrintS("SIGNATURE OF PAIR: ");
2739 pWrite(Lp.sig);
2740#endif
2741 /*- the pair (S[i],p) enters B -*/
2742 Lp.p1 = strat->S[i];
2743 Lp.p2 = p;
2744
2745 if (
2747// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
2748 )
2749 {
2750 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
2751 pNext(Lp.p) = strat->tail; // !!!
2752 }
2753
2754 if (atR >= 0)
2755 {
2756 Lp.i_r1 = strat->S_2_R[i];
2757 Lp.i_r2 = atR;
2758 }
2759 else
2760 {
2761 Lp.i_r1 = -1;
2762 Lp.i_r2 = -1;
2763 }
2764 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
2765
2767 {
2770 && (Lp.p->coef!=NULL))
2771 nDelete(&(Lp.p->coef));
2772 }
2773
2774 l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
2775 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
2776 }
2777}
2778
2779
2780#ifdef DEBUGF5
2781static void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2782#else
2783static void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
2784#endif
2785{
2786 #if ALL_VS_JUST
2787 //Over rings, if we construct the strong pair, do not add the spair
2789 {
2790 number s,t,d;
2791 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(strat->S[i]), &s, &t, currRing->cf);
2792
2793 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
2794 {
2795 nDelete(&d);
2796 nDelete(&s);
2797 nDelete(&t);
2798 return;
2799 }
2800 nDelete(&d);
2801 nDelete(&s);
2802 nDelete(&t);
2803 }
2804 #endif
2805 assume(i<=strat->sl);
2806 int l;
2807 poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
2808 // the corresponding signatures for criteria checks
2809 LObject Lp;
2810 poly pSigMult = p_Copy(pSig,currRing);
2811 poly sSigMult = p_Copy(strat->sig[i],currRing);
2812 unsigned long pSigMultNegSev,sSigMultNegSev;
2813 Lp.i_r = -1;
2814
2815#ifdef KDEBUG
2816 Lp.ecart=0; Lp.length=0;
2817#endif
2818 /*- computes the lcm(s[i],p) -*/
2819 Lp.lcm = pInit();
2820 k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
2821#ifndef HAVE_RATGRING
2822 pLcm(p,strat->S[i],Lp.lcm);
2823#elif defined(HAVE_RATGRING)
2824 if (rIsRatGRing(currRing))
2825 pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
2826 else
2827 pLcm(p,strat->S[i],Lp.lcm);
2828#endif
2829 pSetm(Lp.lcm);
2830
2831 // set coeffs of multipliers m1 and m2
2833 {
2834 number s = nCopy(pGetCoeff(strat->S[i]));
2835 number t = nCopy(pGetCoeff(p));
2836 pSetCoeff0(Lp.lcm, n_Lcm(s, t, currRing->cf));
2837 ksCheckCoeff(&s, &t, currRing->cf);
2838 pSetCoeff0(m1,s);
2839 pSetCoeff0(m2,t);
2840 }
2841 else
2842 {
2843 pSetCoeff0(m1, nInit(1));
2844 pSetCoeff0(m2, nInit(1));
2845 }
2846#ifdef DEBUGF5
2847 Print("P1 ");
2848 pWrite(pHead(p));
2849 Print("P2 ");
2850 pWrite(pHead(strat->S[i]));
2851 Print("M1 ");
2852 pWrite(m1);
2853 Print("M2 ");
2854 pWrite(m2);
2855#endif
2856
2857 // get multiplied signatures for testing
2858 pSigMult = pp_Mult_mm(pSigMult,m1,currRing);
2859 if(pSigMult != NULL)
2860 pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
2861 sSigMult = pp_Mult_mm(sSigMult,m2,currRing);
2862 if(sSigMult != NULL)
2863 sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
2864//#if 1
2865#ifdef DEBUGF5
2866 Print("----------------\n");
2867 pWrite(pSigMult);
2868 pWrite(sSigMult);
2869 Print("----------------\n");
2870 Lp.checked = 0;
2871#endif
2872 int sigCmp;
2873 if(pSigMult != NULL && sSigMult != NULL)
2874 {
2876 sigCmp = p_LtCmpNoAbs(pSigMult,sSigMult,currRing);
2877 else
2878 sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
2879 }
2880 else
2881 {
2882 if(pSigMult == NULL)
2883 {
2884 if(sSigMult == NULL)
2885 sigCmp = 0;
2886 else
2887 sigCmp = -1;
2888 }
2889 else
2890 sigCmp = 1;
2891 }
2892//#if 1
2893#if DEBUGF5
2894 Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
2895 pWrite(pSigMult);
2896 pWrite(sSigMult);
2897#endif
2898 //In the ring case we already build the sig
2900 {
2901 if(sigCmp == 0)
2902 {
2903 //sigdrop since we loose the signature
2904 strat->sigdrop = TRUE;
2905 //Try to reduce it as far as we can via redRing
2907 {
2908 poly p1 = p_Copy(p,currRing);
2909 poly p2 = p_Copy(strat->S[i],currRing);
2910 p1 = p_Mult_mm(p1,m1,currRing);
2911 p2 = p_Mult_mm(p2,m2,currRing);
2912 Lp.p = p_Sub(p1,p2,currRing);
2913 if(Lp.p != NULL)
2914 Lp.sev = p_GetShortExpVector(Lp.p,currRing);
2915 }
2916 int red_result = redRing(&Lp,strat);
2917 if(red_result == 0)
2918 {
2919 // Cancel the sigdrop
2920 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
2921 strat->sigdrop = FALSE;
2922 return;
2923 }
2924 else
2925 {
2926 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
2927 #if 1
2928 strat->enterS(Lp,0,strat,strat->tl);
2929 #endif
2930 return;
2931 }
2932 }
2933 if(pSigMult != NULL && sSigMult != NULL && p_LmCmp(pSigMult,sSigMult,currRing) == 0)
2934 {
2935 //Same lm, have to substract
2936 Lp.sig = p_Sub(pCopy(pSigMult),pCopy(sSigMult),currRing);
2937 }
2938 else
2939 {
2940 if(sigCmp == 1)
2941 {
2942 Lp.sig = pCopy(pSigMult);
2943 }
2944 if(sigCmp == -1)
2945 {
2946 Lp.sig = pNeg(pCopy(sSigMult));
2947 }
2948 }
2949 Lp.sevSig = p_GetShortExpVector(Lp.sig,currRing);
2950 }
2951
2952 #if 0
2953 if(sigCmp==0)
2954 {
2955 // printf("!!!! EQUAL SIGS !!!!\n");
2956 // pSig = sSig, delete element due to Rewritten Criterion
2957 pDelete(&pSigMult);
2958 pDelete(&sSigMult);
2960 pLmDelete(Lp.lcm);
2961 else
2962 pLmFree(Lp.lcm);
2963 pDelete (&m1);
2964 pDelete (&m2);
2965 return;
2966 }
2967 #endif
2968 // testing by syzCrit = F5 Criterion
2969 // testing by rewCrit1 = Rewritten Criterion
2970 // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
2971 if ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
2972 strat->syzCrit(sSigMult,sSigMultNegSev,strat)
2973 // With this rewCrit activated i get a wrong deletion in sba_int_56.tst
2974 //|| strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
2975 )
2976 {
2977 pDelete(&pSigMult);
2978 pDelete(&sSigMult);
2980 pLmDelete(Lp.lcm);
2981 else
2982 pLmFree(Lp.lcm);
2983 pDelete (&m1);
2984 pDelete (&m2);
2985 return;
2986 }
2987 /*
2988 *the pair (S[i],p) enters B if the spoly != 0
2989 */
2990 /*- compute the short s-polynomial -*/
2991 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
2992 pNorm(p);
2993
2994 if ((strat->S[i]==NULL) || (p==NULL))
2995 return;
2996
2997 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
2998 Lp.p=NULL;
2999 else
3000 {
3001 //Build p
3003 {
3004 poly p1 = p_Copy(p,currRing);
3005 poly p2 = p_Copy(strat->S[i],currRing);
3006 p1 = p_Mult_mm(p1,m1,currRing);
3007 p2 = p_Mult_mm(p2,m2,currRing);
3008 Lp.p = p_Sub(p1,p2,currRing);
3009 if(Lp.p != NULL)
3010 Lp.sev = p_GetShortExpVector(Lp.p,currRing);
3011 }
3012 else
3013 {
3014 #ifdef HAVE_PLURAL
3015 if ( rIsPluralRing(currRing) )
3016 {
3017 if(ncRingType(currRing) == nc_lie)
3018 {
3019 // generalized prod-crit for lie-type
3020 strat->cp++;
3021 Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
3022 }
3023 else
3024 if( ALLOW_PROD_CRIT(strat) )
3025 {
3026 // product criterion for homogeneous case in SCA
3027 strat->cp++;
3028 Lp.p = NULL;
3029 }
3030 else
3031 {
3032 Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
3033 nc_CreateShortSpoly(strat->S[i], p, currRing);
3034
3035 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3036 pNext(Lp.p) = strat->tail; // !!!
3037 }
3038 }
3039 else
3040 #endif
3041 {
3043 Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
3044 }
3045 }
3046 }
3047 // store from which element this pair comes from for further tests
3048 //Lp.from = strat->sl+1;
3050 {
3051 //Put the sig to be > 0
3052 if(!nGreaterZero(pGetCoeff(Lp.sig)))
3053 {
3054 Lp.sig = pNeg(Lp.sig);
3055 Lp.p = pNeg(Lp.p);
3056 }
3057 }
3058 else
3059 {
3060 if(sigCmp==currRing->OrdSgn)
3061 {
3062 // pSig > sSig
3063 pDelete (&sSigMult);
3064 Lp.sig = pSigMult;
3065 Lp.sevSig = ~pSigMultNegSev;
3066 }
3067 else
3068 {
3069 // pSig < sSig
3070 pDelete (&pSigMult);
3071 Lp.sig = sSigMult;
3072 Lp.sevSig = ~sSigMultNegSev;
3073 }
3074 }
3075 if (Lp.p == NULL)
3076 {
3077 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
3078 int pos = posInSyz(strat, Lp.sig);
3079 enterSyz(Lp, strat, pos);
3080 }
3081 else
3082 {
3083 // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
3084 if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
3085 {
3086 pLmFree(Lp.lcm);
3087 pDelete(&Lp.sig);
3088 pDelete (&m1);
3089 pDelete (&m2);
3090 return;
3091 }
3092 // in any case Lp is checked up to the next strat->P which is added
3093 // to S right after this critical pair creation.
3094 // NOTE: this even holds if the 2nd generator gives the bigger signature
3095 // moreover, this improves rewCriterion,
3096 // i.e. strat->checked > strat->from if and only if the 2nd generator
3097 // gives the bigger signature.
3098 Lp.checked = strat->sl+1;
3099 // at this point it is clear that the pair will be added to L, since it has
3100 // passed all tests up to now
3101
3102 // adds buchberger's first criterion
3103 if (pLmCmp(m2,pHead(p)) == 0)
3104 {
3105 Lp.prod_crit = TRUE; // Product Criterion
3106#if 0
3107 int pos = posInSyz(strat, Lp.sig);
3108 enterSyz(Lp, strat, pos);
3109 pDelete (&m1);
3110 pDelete (&m2);
3111 return;
3112#endif
3113 }
3114 pDelete (&m1);
3115 pDelete (&m2);
3116#if DEBUGF5
3117 PrintS("SIGNATURE OF PAIR: ");
3118 pWrite(Lp.sig);
3119#endif
3120 /*- the pair (S[i],p) enters B -*/
3121 Lp.p1 = strat->S[i];
3122 Lp.p2 = p;
3123
3124 if (
3126// || (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
3128 )
3129 {
3130 assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
3131 pNext(Lp.p) = strat->tail; // !!!
3132 }
3133
3134 if (atR >= 0)
3135 {
3136 Lp.i_r1 = strat->S_2_R[i];
3137 Lp.i_r2 = atR;
3138 }
3139 else
3140 {
3141 Lp.i_r1 = -1;
3142 Lp.i_r2 = -1;
3143 }
3144 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3145
3147 {
3150 && (Lp.p->coef!=NULL))
3151 nDelete(&(Lp.p->coef));
3152 }
3153 // Check for sigdrop
3154 if(rField_is_Ring(currRing) && pLtCmp(Lp.sig,pSig) == -1)
3155 {
3156 strat->sigdrop = TRUE;
3157 // Completely reduce it
3158 int red_result = redRing(&Lp,strat);
3159 if(red_result == 0)
3160 {
3161 // Reduced to 0
3162 strat->sigdrop = FALSE;
3163 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
3164 return;
3165 }
3166 else
3167 {
3168 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
3169 // 0 - add just the original poly causing the sigdrop, 1 - add also this
3170 #if 1
3171 strat->enterS(Lp,0,strat, strat->tl+1);
3172 #endif
3173 return;
3174 }
3175 }
3176 l = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
3177 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3178 }
3179}
3180
3181/*2
3182* put the pair (s[i],p) into the set L, ecart=ecart(p)
3183* in the case that s forms a SB of (s)
3184*/
3185void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat, int atR = -1)
3186{
3187 //PrintS("try ");wrp(strat->S[i]);PrintS(" and ");wrp(p);PrintLn();
3188 if(pHasNotCF(p,strat->S[i]))
3189 {
3190 //PrintS("prod-crit\n");
3191 if(ALLOW_PROD_CRIT(strat))
3192 {
3193 //PrintS("prod-crit\n");
3194 strat->cp++;
3195 return;
3196 }
3197 }
3198
3199 int l;
3200 LObject Lp;
3201 Lp.i_r = -1;
3202
3203 Lp.lcm = p_Lcm(p,strat->S[i],currRing);
3204 /*- compute the short s-polynomial -*/
3205
3206 #ifdef HAVE_PLURAL
3208 {
3209 Lp.p = nc_CreateShortSpoly(strat->S[i],p, currRing); // ??? strat->tailRing?
3210 }
3211 else
3212 #endif
3213 Lp.p = ksCreateShortSpoly(strat->S[i],p,strat->tailRing);
3214
3215 if (Lp.p == NULL)
3216 {
3217 //PrintS("short spoly==NULL\n");
3218 pLmFree(Lp.lcm);
3219 }
3220 else
3221 {
3222 /*- the pair (S[i],p) enters L -*/
3223 Lp.p1 = strat->S[i];
3224 Lp.p2 = p;
3225 if (atR >= 0)
3226 {
3227 Lp.i_r1 = strat->S_2_R[i];
3228 Lp.i_r2 = atR;
3229 }
3230 else
3231 {
3232 Lp.i_r1 = -1;
3233 Lp.i_r2 = -1;
3234 }
3235 assume(pNext(Lp.p) == NULL);
3236 pNext(Lp.p) = strat->tail;
3237 strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
3239 {
3242 && (Lp.p->coef!=NULL))
3243 nDelete(&(Lp.p->coef));
3244 }
3245 l = strat->posInL(strat->L,strat->Ll,&Lp,strat);
3246 //Print("-> L[%d]\n",l);
3247 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l);
3248 }
3249}
3250
3251/*2
3252* merge set B into L
3253*/
3255{
3256 int j=strat->Ll+strat->Bl+1;
3257 if (j>strat->Lmax)
3258 {
3259 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3260 enlargeL(&(strat->L),&(strat->Lmax),j);
3261 }
3262 j = strat->Ll;
3263 int i;
3264 for (i=strat->Bl; i>=0; i--)
3265 {
3266 j = strat->posInL(strat->L,j,&(strat->B[i]),strat);
3267 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3268 }
3269 strat->Bl = -1;
3270}
3271
3272/*2
3273* merge set B into L
3274*/
3276{
3277 int j=strat->Ll+strat->Bl+1;
3278 if (j>strat->Lmax)
3279 {
3280 j=((j+setmaxLinc-1)/setmaxLinc)*setmaxLinc-strat->Lmax;
3281 enlargeL(&(strat->L),&(strat->Lmax),j);
3282 }
3283 j = strat->Ll;
3284 int i;
3285 for (i=strat->Bl; i>=0; i--)
3286 {
3287 j = strat->posInLSba(strat->L,j,&(strat->B[i]),strat);
3288 enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j);
3289 }
3290 strat->Bl = -1;
3291}
3292
3293/*2
3294*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3295*using the chain-criterion in B and L and enters B to L
3296*/
3297void chainCritNormal (poly p,int ecart,kStrategy strat)
3298{
3299 int i,j,l;
3300
3301 /*
3302 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3303 *In this case all elements in B such
3304 *that their lcm is divisible by the leading term of S[i] can be canceled
3305 */
3306 if (strat->pairtest!=NULL)
3307 {
3308#ifdef HAVE_SHIFTBBA
3309 // only difference is pLPDivisibleBy instead of pDivisibleBy
3310 if (rIsLPRing(currRing))
3311 {
3312 for (j=0; j<=strat->sl; j++)
3313 {
3314 if (strat->pairtest[j])
3315 {
3316 for (i=strat->Bl; i>=0; i--)
3317 {
3318 if (pLPDivisibleBy(strat->S[j],strat->B[i].lcm))
3319 {
3320 deleteInL(strat->B,&strat->Bl,i,strat);
3321 strat->c3++;
3322 }
3323 }
3324 }
3325 }
3326 }
3327 else
3328#endif
3329 {
3330 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3331 for (j=0; j<=strat->sl; j++)
3332 {
3333 if (strat->pairtest[j])
3334 {
3335 for (i=strat->Bl; i>=0; i--)
3336 {
3337 if (pDivisibleBy(strat->S[j],strat->B[i].lcm))
3338 {
3339 deleteInL(strat->B,&strat->Bl,i,strat);
3340 strat->c3++;
3341 }
3342 }
3343 }
3344 }
3345 }
3346 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3347 strat->pairtest=NULL;
3348 }
3349 if (strat->Gebauer || strat->fromT)
3350 {
3351 if (strat->sugarCrit)
3352 {
3353 /*
3354 *suppose L[j] == (s,r) and p/lcm(s,r)
3355 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3356 *and in case the sugar is o.k. then L[j] can be canceled
3357 */
3358 for (j=strat->Ll; j>=0; j--)
3359 {
3360 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3361 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3362 && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3363 {
3364 if (strat->L[j].p == strat->tail)
3365 {
3366 deleteInL(strat->L,&strat->Ll,j,strat);
3367 strat->c3++;
3368 }
3369 }
3370 }
3371 /*
3372 *this is GEBAUER-MOELLER:
3373 *in B all elements with the same lcm except the "best"
3374 *(i.e. the last one in B with this property) will be canceled
3375 */
3376 j = strat->Bl;
3377 loop /*cannot be changed into a for !!! */
3378 {
3379 if (j <= 0) break;
3380 i = j-1;
3381 loop
3382 {
3383 if (i < 0) break;
3384 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3385 {
3386 strat->c3++;
3387 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3388 {
3389 deleteInL(strat->B,&strat->Bl,i,strat);
3390 j--;
3391 }
3392 else
3393 {
3394 deleteInL(strat->B,&strat->Bl,j,strat);
3395 break;
3396 }
3397 }
3398 i--;
3399 }
3400 j--;
3401 }
3402 }
3403 else /*sugarCrit*/
3404 {
3405 /*
3406 *suppose L[j] == (s,r) and p/lcm(s,r)
3407 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3408 *and in case the sugar is o.k. then L[j] can be canceled
3409 */
3410 for (j=strat->Ll; j>=0; j--)
3411 {
3412 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3413 {
3414 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3415 {
3416 deleteInL(strat->L,&strat->Ll,j,strat);
3417 strat->c3++;
3418 }
3419 }
3420 }
3421 /*
3422 *this is GEBAUER-MOELLER:
3423 *in B all elements with the same lcm except the "best"
3424 *(i.e. the last one in B with this property) will be canceled
3425 */
3426 j = strat->Bl;
3427 loop /*cannot be changed into a for !!! */
3428 {
3429 if (j <= 0) break;
3430 for(i=j-1; i>=0; i--)
3431 {
3432 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3433 {
3434 strat->c3++;
3435 deleteInL(strat->B,&strat->Bl,i,strat);
3436 j--;
3437 }
3438 }
3439 j--;
3440 }
3441 }
3442 /*
3443 *the elements of B enter L
3444 */
3445 kMergeBintoL(strat);
3446 }
3447 else
3448 {
3449 for (j=strat->Ll; j>=0; j--)
3450 {
3451 #ifdef HAVE_SHIFTBBA
3452 if ((strat->L[j].p1!=NULL) &&
3453 pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3454 #else
3455 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3456 #endif
3457 {
3458 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3459 {
3460 deleteInL(strat->L,&strat->Ll,j,strat);
3461 strat->c3++;
3462 }
3463 }
3464 }
3465 /*
3466 *this is our MODIFICATION of GEBAUER-MOELLER:
3467 *First the elements of B enter L,
3468 *then we fix a lcm and the "best" element in L
3469 *(i.e the last in L with this lcm and of type (s,p))
3470 *and cancel all the other elements of type (r,p) with this lcm
3471 *except the case the element (s,r) has also the same lcm
3472 *and is on the worst position with respect to (s,p) and (r,p)
3473 */
3474 /*
3475 *B enters to L/their order with respect to B is permutated for elements
3476 *B[i].p with the same leading term
3477 */
3478 kMergeBintoL(strat);
3479 j = strat->Ll;
3480 loop /*cannot be changed into a for !!! */
3481 {
3482 if (j <= 0)
3483 {
3484 /*now L[0] cannot be canceled any more and the tail can be removed*/
3485 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3486 break;
3487 }
3488 if (strat->L[j].p2 == p)
3489 {
3490 i = j-1;
3491 loop
3492 {
3493 if (i < 0) break;
3494 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3495 {
3496 /*L[i] could be canceled but we search for a better one to cancel*/
3497 strat->c3++;
3498 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3499 && (pNext(strat->L[l].p) == strat->tail)
3500 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3501 && pDivisibleBy(p,strat->L[l].lcm))
3502 {
3503 /*
3504 *"NOT equal(...)" because in case of "equal" the element L[l]
3505 *is "older" and has to be from theoretical point of view behind
3506 *L[i], but we do not want to reorder L
3507 */
3508 strat->L[i].p2 = strat->tail;
3509 /*
3510 *L[l] will be canceled, we cannot cancel L[i] later on,
3511 *so we mark it with "tail"
3512 */
3513 deleteInL(strat->L,&strat->Ll,l,strat);
3514 i--;
3515 }
3516 else
3517 {
3518 deleteInL(strat->L,&strat->Ll,i,strat);
3519 }
3520 j--;
3521 }
3522 i--;
3523 }
3524 }
3525 else if (strat->L[j].p2 == strat->tail)
3526 {
3527 /*now L[j] cannot be canceled any more and the tail can be removed*/
3528 strat->L[j].p2 = p;
3529 }
3530 j--;
3531 }
3532 }
3533}
3534/*2
3535*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3536*without the chain-criterion in B and L and enters B to L
3537*/
3538void chainCritOpt_1 (poly,int,kStrategy strat)
3539{
3540 if (strat->pairtest!=NULL)
3541 {
3542 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3543 strat->pairtest=NULL;
3544 }
3545 /*
3546 *the elements of B enter L
3547 */
3548 kMergeBintoL(strat);
3549}
3550/*2
3551*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
3552*using the chain-criterion in B and L and enters B to L
3553*/
3554void chainCritSig (poly p,int /*ecart*/,kStrategy strat)
3555{
3556 int i,j,l;
3557 kMergeBintoLSba(strat);
3558 j = strat->Ll;
3559 loop /*cannot be changed into a for !!! */
3560 {
3561 if (j <= 0)
3562 {
3563 /*now L[0] cannot be canceled any more and the tail can be removed*/
3564 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3565 break;
3566 }
3567 if (strat->L[j].p2 == p)
3568 {
3569 i = j-1;
3570 loop
3571 {
3572 if (i < 0) break;
3573 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3574 {
3575 /*L[i] could be canceled but we search for a better one to cancel*/
3576 strat->c3++;
3577 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3578 && (pNext(strat->L[l].p) == strat->tail)
3579 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3580 && pDivisibleBy(p,strat->L[l].lcm))
3581 {
3582 /*
3583 *"NOT equal(...)" because in case of "equal" the element L[l]
3584 *is "older" and has to be from theoretical point of view behind
3585 *L[i], but we do not want to reorder L
3586 */
3587 strat->L[i].p2 = strat->tail;
3588 /*
3589 *L[l] will be canceled, we cannot cancel L[i] later on,
3590 *so we mark it with "tail"
3591 */
3592 deleteInL(strat->L,&strat->Ll,l,strat);
3593 i--;
3594 }
3595 else
3596 {
3597 deleteInL(strat->L,&strat->Ll,i,strat);
3598 }
3599 j--;
3600 }
3601 i--;
3602 }
3603 }
3604 else if (strat->L[j].p2 == strat->tail)
3605 {
3606 /*now L[j] cannot be canceled any more and the tail can be removed*/
3607 strat->L[j].p2 = p;
3608 }
3609 j--;
3610 }
3611}
3612#ifdef HAVE_RATGRING
3613void chainCritPart (poly p,int ecart,kStrategy strat)
3614{
3615 int i,j,l;
3616
3617 /*
3618 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
3619 *In this case all elements in B such
3620 *that their lcm is divisible by the leading term of S[i] can be canceled
3621 */
3622 if (strat->pairtest!=NULL)
3623 {
3624 /*- i.e. there is an i with pairtest[i]==TRUE -*/
3625 for (j=0; j<=strat->sl; j++)
3626 {
3627 if (strat->pairtest[j])
3628 {
3629 for (i=strat->Bl; i>=0; i--)
3630 {
3631 if (_p_LmDivisibleByPart(strat->S[j],currRing,
3632 strat->B[i].lcm,currRing,
3633 currRing->real_var_start,currRing->real_var_end))
3634 {
3635 if(TEST_OPT_DEBUG)
3636 {
3637 Print("chain-crit-part: S[%d]=",j);
3638 p_wrp(strat->S[j],currRing);
3639 Print(" divide B[%d].lcm=",i);
3640 p_wrp(strat->B[i].lcm,currRing);
3641 PrintLn();
3642 }
3643 deleteInL(strat->B,&strat->Bl,i,strat);
3644 strat->c3++;
3645 }
3646 }
3647 }
3648 }
3649 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
3650 strat->pairtest=NULL;
3651 }
3652 if (strat->Gebauer || strat->fromT)
3653 {
3654 if (strat->sugarCrit)
3655 {
3656 /*
3657 *suppose L[j] == (s,r) and p/lcm(s,r)
3658 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3659 *and in case the sugar is o.k. then L[j] can be canceled
3660 */
3661 for (j=strat->Ll; j>=0; j--)
3662 {
3663 if (sugarDivisibleBy(ecart,strat->L[j].ecart)
3664 && ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
3665 && pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3666 {
3667 if (strat->L[j].p == strat->tail)
3668 {
3669 if(TEST_OPT_DEBUG)
3670 {
3671 PrintS("chain-crit-part: pCompareChainPart p=");
3672 p_wrp(p,currRing);
3673 Print(" delete L[%d]",j);
3674 p_wrp(strat->L[j].lcm,currRing);
3675 PrintLn();
3676 }
3677 deleteInL(strat->L,&strat->Ll,j,strat);
3678 strat->c3++;
3679 }
3680 }
3681 }
3682 /*
3683 *this is GEBAUER-MOELLER:
3684 *in B all elements with the same lcm except the "best"
3685 *(i.e. the last one in B with this property) will be canceled
3686 */
3687 j = strat->Bl;
3688 loop /*cannot be changed into a for !!! */
3689 {
3690 if (j <= 0) break;
3691 i = j-1;
3692 loop
3693 {
3694 if (i < 0) break;
3695 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3696 {
3697 strat->c3++;
3698 if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart))
3699 {
3700 if(TEST_OPT_DEBUG)
3701 {
3702 Print("chain-crit-part: sugar B[%d].lcm=",j);
3703 p_wrp(strat->B[j].lcm,currRing);
3704 Print(" delete B[%d]",i);
3705 p_wrp(strat->B[i].lcm,currRing);
3706 PrintLn();
3707 }
3708 deleteInL(strat->B,&strat->Bl,i,strat);
3709 j--;
3710 }
3711 else
3712 {
3713 if(TEST_OPT_DEBUG)
3714 {
3715 Print("chain-crit-part: sugar B[%d].lcm=",i);
3716 p_wrp(strat->B[i].lcm,currRing);
3717 Print(" delete B[%d]",j);
3718 p_wrp(strat->B[j].lcm,currRing);
3719 PrintLn();
3720 }
3721 deleteInL(strat->B,&strat->Bl,j,strat);
3722 break;
3723 }
3724 }
3725 i--;
3726 }
3727 j--;
3728 }
3729 }
3730 else /*sugarCrit*/
3731 {
3732 /*
3733 *suppose L[j] == (s,r) and p/lcm(s,r)
3734 *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p)
3735 *and in case the sugar is o.k. then L[j] can be canceled
3736 */
3737 for (j=strat->Ll; j>=0; j--)
3738 {
3739 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3740 {
3741 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3742 {
3743 if(TEST_OPT_DEBUG)
3744 {
3745 PrintS("chain-crit-part: sugar:pCompareChainPart p=");
3746 p_wrp(p,currRing);
3747 Print(" delete L[%d]",j);
3748 p_wrp(strat->L[j].lcm,currRing);
3749 PrintLn();
3750 }
3751 deleteInL(strat->L,&strat->Ll,j,strat);
3752 strat->c3++;
3753 }
3754 }
3755 }
3756 /*
3757 *this is GEBAUER-MOELLER:
3758 *in B all elements with the same lcm except the "best"
3759 *(i.e. the last one in B with this property) will be canceled
3760 */
3761 j = strat->Bl;
3762 loop /*cannot be changed into a for !!! */
3763 {
3764 if (j <= 0) break;
3765 for(i=j-1; i>=0; i--)
3766 {
3767 if (pLmEqual(strat->B[j].lcm,strat->B[i].lcm))
3768 {
3769 if(TEST_OPT_DEBUG)
3770 {
3771 Print("chain-crit-part: equal lcm B[%d].lcm=",j);
3772 p_wrp(strat->B[j].lcm,currRing);
3773 Print(" delete B[%d]\n",i);
3774 }
3775 strat->c3++;
3776 deleteInL(strat->B,&strat->Bl,i,strat);
3777 j--;
3778 }
3779 }
3780 j--;
3781 }
3782 }
3783 /*
3784 *the elements of B enter L
3785 */
3786 kMergeBintoL(strat);
3787 }
3788 else
3789 {
3790 for (j=strat->Ll; j>=0; j--)
3791 {
3792 if (pCompareChainPart(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
3793 {
3794 if ((pNext(strat->L[j].p) == strat->tail)||(rHasGlobalOrdering(currRing)))
3795 {
3796 if(TEST_OPT_DEBUG)
3797 {
3798 PrintS("chain-crit-part: pCompareChainPart p=");
3799 p_wrp(p,currRing);
3800 Print(" delete L[%d]",j);
3801 p_wrp(strat->L[j].lcm,currRing);
3802 PrintLn();
3803 }
3804 deleteInL(strat->L,&strat->Ll,j,strat);
3805 strat->c3++;
3806 }
3807 }
3808 }
3809 /*
3810 *this is our MODIFICATION of GEBAUER-MOELLER:
3811 *First the elements of B enter L,
3812 *then we fix a lcm and the "best" element in L
3813 *(i.e the last in L with this lcm and of type (s,p))
3814 *and cancel all the other elements of type (r,p) with this lcm
3815 *except the case the element (s,r) has also the same lcm
3816 *and is on the worst position with respect to (s,p) and (r,p)
3817 */
3818 /*
3819 *B enters to L/their order with respect to B is permutated for elements
3820 *B[i].p with the same leading term
3821 */
3822 kMergeBintoL(strat);
3823 j = strat->Ll;
3824 loop /*cannot be changed into a for !!! */
3825 {
3826 if (j <= 0)
3827 {
3828 /*now L[0] cannot be canceled any more and the tail can be removed*/
3829 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
3830 break;
3831 }
3832 if (strat->L[j].p2 == p)
3833 {
3834 i = j-1;
3835 loop
3836 {
3837 if (i < 0) break;
3838 if ((strat->L[i].p2 == p) && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
3839 {
3840 /*L[i] could be canceled but we search for a better one to cancel*/
3841 strat->c3++;
3842 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
3843 && (pNext(strat->L[l].p) == strat->tail)
3844 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
3846 strat->L[l].lcm,currRing,
3847 currRing->real_var_start, currRing->real_var_end))
3848
3849 {
3850 /*
3851 *"NOT equal(...)" because in case of "equal" the element L[l]
3852 *is "older" and has to be from theoretical point of view behind
3853 *L[i], but we do not want to reorder L
3854 */
3855 strat->L[i].p2 = strat->tail;
3856 /*
3857 *L[l] will be canceled, we cannot cancel L[i] later on,
3858 *so we mark it with "tail"
3859 */
3860 if(TEST_OPT_DEBUG)
3861 {
3862 PrintS("chain-crit-part: divisible_by p=");
3863 p_wrp(p,currRing);
3864 Print(" delete L[%d]",l);
3865 p_wrp(strat->L[l].lcm,currRing);
3866 PrintLn();
3867 }
3868 deleteInL(strat->L,&strat->Ll,l,strat);
3869 i--;
3870 }
3871 else
3872 {
3873 if(TEST_OPT_DEBUG)
3874 {
3875 PrintS("chain-crit-part: divisible_by(2) p=");
3876 p_wrp(p,currRing);
3877 Print(" delete L[%d]",i);
3878 p_wrp(strat->L[i].lcm,currRing);
3879 PrintLn();
3880 }
3881 deleteInL(strat->L,&strat->Ll,i,strat);
3882 }
3883 j--;
3884 }
3885 i--;
3886 }
3887 }
3888 else if (strat->L[j].p2 == strat->tail)
3889 {
3890 /*now L[j] cannot be canceled any more and the tail can be removed*/
3891 strat->L[j].p2 = p;
3892 }
3893 j--;
3894 }
3895 }
3896}
3897#endif
3898
3899/*2
3900*(s[0],h),...,(s[k],h) will be put to the pairset L
3901*/
3902void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR/* = -1*/)
3903{
3904
3905 if ((strat->syzComp==0)
3906 || (pGetComp(h)<=strat->syzComp))
3907 {
3908 int j;
3909 BOOLEAN new_pair=FALSE;
3910
3911 if (pGetComp(h)==0)
3912 {
3913 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3914 if ((isFromQ)&&(strat->fromQ!=NULL))
3915 {
3916 for (j=0; j<=k; j++)
3917 {
3918 if (!strat->fromQ[j])
3919 {
3920 new_pair=TRUE;
3921 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3922 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3923 }
3924 }
3925 }
3926 else
3927 {
3928 new_pair=TRUE;
3929 for (j=0; j<=k; j++)
3930 {
3931 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3932 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3933 }
3934 }
3935 }
3936 else
3937 {
3938 for (j=0; j<=k; j++)
3939 {
3940 if ((pGetComp(h)==pGetComp(strat->S[j]))
3941 || (pGetComp(strat->S[j])==0))
3942 {
3943 new_pair=TRUE;
3944 strat->enterOnePair(j,h,ecart,isFromQ,strat, atR);
3945 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3946 }
3947 }
3948 }
3949 if (new_pair)
3950 {
3951 #ifdef HAVE_RATGRING
3952 if (currRing->real_var_start>0)
3953 chainCritPart(h,ecart,strat);
3954 else
3955 #endif
3956 strat->chainCrit(h,ecart,strat);
3957 }
3958 kMergeBintoL(strat);
3959 }
3960}
3961
3962/*2
3963*(s[0],h),...,(s[k],h) will be put to the pairset L
3964*using signatures <= only for signature-based standard basis algorithms
3965*/
3966
3967void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
3968{
3969
3970 if ((strat->syzComp==0)
3971 || (pGetComp(h)<=strat->syzComp))
3972 {
3973 int j;
3974 BOOLEAN new_pair=FALSE;
3975
3976 if (pGetComp(h)==0)
3977 {
3978 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
3979 if ((isFromQ)&&(strat->fromQ!=NULL))
3980 {
3981 for (j=0; j<=k; j++)
3982 {
3983 if (!strat->fromQ[j])
3984 {
3985 new_pair=TRUE;
3986 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3987 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3988 }
3989 }
3990 }
3991 else
3992 {
3993 new_pair=TRUE;
3994 for (j=0; j<=k; j++)
3995 {
3996 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
3997 //Print("j:%d, Ll:%d\n",j,strat->Ll);
3998 }
3999 }
4000 }
4001 else
4002 {
4003 for (j=0; j<=k; j++)
4004 {
4005 if ((pGetComp(h)==pGetComp(strat->S[j]))
4006 || (pGetComp(strat->S[j])==0))
4007 {
4008 new_pair=TRUE;
4009 enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4010 //Print("j:%d, Ll:%d\n",j,strat->Ll);
4011 }
4012 }
4013 }
4014
4015 if (new_pair)
4016 {
4017#ifdef HAVE_RATGRING
4018 if (currRing->real_var_start>0)
4019 chainCritPart(h,ecart,strat);
4020 else
4021#endif
4022 strat->chainCrit(h,ecart,strat);
4023 }
4024 }
4025}
4026
4027void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4028{
4029
4030 if ((strat->syzComp==0)
4031 || (pGetComp(h)<=strat->syzComp))
4032 {
4033 int j;
4034
4035 if (pGetComp(h)==0)
4036 {
4037 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4038 if ((isFromQ)&&(strat->fromQ!=NULL))
4039 {
4040 for (j=0; j<=k && !strat->sigdrop; j++)
4041 {
4042 if (!strat->fromQ[j])
4043 {
4044 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4045 //Print("j:%d, Ll:%d\n",j,strat->Ll);
4046 }
4047 }
4048 }
4049 else
4050 {
4051 for (j=0; j<=k && !strat->sigdrop; j++)
4052 {
4053 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4054 //Print("j:%d, Ll:%d\n",j,strat->Ll);
4055 }
4056 }
4057 }
4058 else
4059 {
4060 for (j=0; j<=k && !strat->sigdrop; j++)
4061 {
4062 if ((pGetComp(h)==pGetComp(strat->S[j]))
4063 || (pGetComp(strat->S[j])==0))
4064 {
4065 enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
4066 //Print("j:%d, Ll:%d\n",j,strat->Ll);
4067 }
4068 }
4069 }
4070
4071#if 0
4072 if (new_pair)
4073 {
4074#ifdef HAVE_RATGRING
4075 if (currRing->real_var_start>0)
4076 chainCritPart(h,ecart,strat);
4077 else
4078#endif
4079 strat->chainCrit(h,ecart,strat);
4080 }
4081#endif
4082 }
4083}
4084#ifdef HAVE_RINGS
4085/*2
4086*the pairset B of pairs of type (s[i],p) is complete now. It will be updated
4087*using the chain-criterion in B and L and enters B to L
4088*/
4089void chainCritRing (poly p,int, kStrategy strat)
4090{
4091 int i,j,l;
4092 /*
4093 *pairtest[i] is TRUE if spoly(S[i],p) == 0.
4094 *In this case all elements in B such
4095 *that their lcm is divisible by the leading term of S[i] can be canceled
4096 */
4097 if (strat->pairtest!=NULL)
4098 {
4099 {
4100 /*- i.e. there is an i with pairtest[i]==TRUE -*/
4101 for (j=0; j<=strat->sl; j++)
4102 {
4103 if (strat->pairtest[j])
4104 {
4105 for (i=strat->Bl; i>=0; i--)
4106 {
4107 if (pDivisibleBy(strat->S[j],strat->B[i].lcm) && n_DivBy(pGetCoeff(strat->B[i].lcm), pGetCoeff(strat->S[j]),currRing->cf))
4108 {
4109#ifdef KDEBUG
4110 if (TEST_OPT_DEBUG)
4111 {
4112 PrintS("--- chain criterion func chainCritRing type 1\n");
4113 PrintS("strat->S[j]:");
4114 wrp(strat->S[j]);
4115 PrintS(" strat->B[i].lcm:");
4116 wrp(strat->B[i].lcm);PrintLn();
4117 pWrite(strat->B[i].p);
4118 pWrite(strat->B[i].p1);
4119 pWrite(strat->B[i].p2);
4120 wrp(strat->B[i].lcm);
4121 PrintLn();
4122 }
4123#endif
4124 deleteInL(strat->B,&strat->Bl,i,strat);
4125 strat->c3++;
4126 }
4127 }
4128 }
4129 }
4130 }
4131 omFreeSize(strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN));
4132 strat->pairtest=NULL;
4133 }
4134 assume(!(strat->Gebauer || strat->fromT));
4135 for (j=strat->Ll; j>=0; j--)
4136 {
4137 if ((strat->L[j].lcm != NULL) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(p), currRing->cf))
4138 {
4139 if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm))
4140 {
4141 if ((pNext(strat->L[j].p) == strat->tail) || (rHasGlobalOrdering(currRing)))
4142 {
4143 deleteInL(strat->L,&strat->Ll,j,strat);
4144 strat->c3++;
4145#ifdef KDEBUG
4146 if (TEST_OPT_DEBUG)
4147 {
4148 PrintS("--- chain criterion func chainCritRing type 2\n");
4149 PrintS("strat->L[j].p:");
4150 wrp(strat->L[j].p);
4151 PrintS(" p:");
4152 wrp(p);
4153 PrintLn();
4154 }
4155#endif
4156 }
4157 }
4158 }
4159 }
4160 /*
4161 *this is our MODIFICATION of GEBAUER-MOELLER:
4162 *First the elements of B enter L,
4163 *then we fix a lcm and the "best" element in L
4164 *(i.e the last in L with this lcm and of type (s,p))
4165 *and cancel all the other elements of type (r,p) with this lcm
4166 *except the case the element (s,r) has also the same lcm
4167 *and is on the worst position with respect to (s,p) and (r,p)
4168 */
4169 /*
4170 *B enters to L/their order with respect to B is permutated for elements
4171 *B[i].p with the same leading term
4172 */
4173 kMergeBintoL(strat);
4174 j = strat->Ll;
4175 loop /*cannot be changed into a for !!! */
4176 {
4177 if (j <= 0)
4178 {
4179 /*now L[0] cannot be canceled any more and the tail can be removed*/
4180 if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p;
4181 break;
4182 }
4183 if (strat->L[j].p2 == p) // Was the element added from B?
4184 {
4185 i = j-1;
4186 loop
4187 {
4188 if (i < 0) break;
4189 // Element is from B and has the same lcm as L[j]
4190 if ((strat->L[i].p2 == p) && n_DivBy(pGetCoeff(strat->L[j].lcm), pGetCoeff(strat->L[i].lcm), currRing->cf)
4191 && pLmEqual(strat->L[j].lcm,strat->L[i].lcm))
4192 {
4193 /*L[i] could be canceled but we search for a better one to cancel*/
4194 strat->c3++;
4195#ifdef KDEBUG
4196 if (TEST_OPT_DEBUG)
4197 {
4198 PrintS("--- chain criterion func chainCritRing type 3\n");
4199 PrintS("strat->L[j].lcm:");
4200 wrp(strat->L[j].lcm);
4201 PrintS(" strat->L[i].lcm:");
4202 wrp(strat->L[i].lcm);
4203 PrintLn();
4204 }
4205#endif
4206 if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat)
4207 && (pNext(strat->L[l].p) == strat->tail)
4208 && (!pLmEqual(strat->L[i].p,strat->L[l].p))
4209 && pDivisibleBy(p,strat->L[l].lcm))
4210 {
4211 /*
4212 *"NOT equal(...)" because in case of "equal" the element L[l]
4213 *is "older" and has to be from theoretical point of view behind
4214 *L[i], but we do not want to reorder L
4215 */
4216 strat->L[i].p2 = strat->tail;
4217 /*
4218 *L[l] will be canceled, we cannot cancel L[i] later on,
4219 *so we mark it with "tail"
4220 */
4221 deleteInL(strat->L,&strat->Ll,l,strat);
4222 i--;
4223 }
4224 else
4225 {
4226 deleteInL(strat->L,&strat->Ll,i,strat);
4227 }
4228 j--;
4229 }
4230 i--;
4231 }
4232 }
4233 else if (strat->L[j].p2 == strat->tail)
4234 {
4235 /*now L[j] cannot be canceled any more and the tail can be removed*/
4236 strat->L[j].p2 = p;
4237 }
4238 j--;
4239 }
4240}
4241#endif
4242
4243#ifdef HAVE_RINGS
4244/*2
4245*(s[0],h),...,(s[k],h) will be put to the pairset L
4246*/
4247void initenterstrongPairs (poly h,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4248{
4249 if (!nIsOne(pGetCoeff(h)))
4250 {
4251 int j;
4252 BOOLEAN new_pair=FALSE;
4253
4254 if (pGetComp(h)==0)
4255 {
4256 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
4257 if ((isFromQ)&&(strat->fromQ!=NULL))
4258 {
4259 for (j=0; j<=k; j++)
4260 {
4261 if (!strat->fromQ[j])
4262 {
4263 new_pair=TRUE;
4264 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4265 }
4266 }
4267 }
4268 else
4269 {
4270 new_pair=TRUE;
4271 for (j=0; j<=k; j++)
4272 {
4273 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4274 }
4275 }
4276 }
4277 else
4278 {
4279 for (j=0; j<=k; j++)
4280 {
4281 if ((pGetComp(h)==pGetComp(strat->S[j]))
4282 || (pGetComp(strat->S[j])==0))
4283 {
4284 new_pair=TRUE;
4285 enterOneStrongPoly(j,h,ecart,isFromQ,strat, atR, FALSE);
4286 }
4287 }
4288 }
4289 if (new_pair)
4290 {
4291 #ifdef HAVE_RATGRING
4292 if (currRing->real_var_start>0)
4293 chainCritPart(h,ecart,strat);
4294 else
4295 #endif
4296 strat->chainCrit(h,ecart,strat);
4297 }
4298 kMergeBintoL(strat);
4299 }
4300}
4301
4302static void initenterstrongPairsSig (poly h,poly hSig, int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
4303{
4304 const int iCompH = pGetComp(h);
4305 if (!nIsOne(pGetCoeff(h)))
4306 {
4307 int j;
4308
4309 for (j=0; j<=k && !strat->sigdrop; j++)
4310 {
4311 // Print("j:%d, Ll:%d\n",j,strat->Ll);
4312// if (((unsigned long) pGetCoeff(h) % (unsigned long) pGetCoeff(strat->S[j]) != 0) &&
4313// ((unsigned long) pGetCoeff(strat->S[j]) % (unsigned long) pGetCoeff(h) != 0))
4314 if (((iCompH == pGetComp(strat->S[j]))
4315 || (0 == pGetComp(strat->S[j])))
4316 && ((iCompH<=strat->syzComp)||(strat->syzComp==0)))
4317 {
4318 enterOneStrongPolySig(j,h,hSig,ecart,isFromQ,strat, atR);
4319 }
4320 }
4321 }
4322}
4323#endif
4324
4325#ifdef HAVE_RINGS
4326/*2
4327* Generates spoly(0, h) if applicable. Assumes ring in Z/2^n.
4328*/
4330{
4331 if (nIsOne(pGetCoeff(h))) return;
4332 number gcd;
4333 bool go = false;
4334 if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4335 {
4336 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4337 go = true;
4338 }
4339 else
4340 gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4341 if (go || !nIsOne(gcd))
4342 {
4343 poly p = h->next;
4344 if (!go)
4345 {
4346 number tmp = gcd;
4347 gcd = n_Ann(gcd,currRing->cf);
4348 nDelete(&tmp);
4349 }
4350 p_Test(p,strat->tailRing);
4351 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4352 nDelete(&gcd);
4353
4354 if (p != NULL)
4355 {
4356 if (TEST_OPT_PROT)
4357 {
4358 PrintS("Z");
4359 }
4360#ifdef KDEBUG
4361 if (TEST_OPT_DEBUG)
4362 {
4363 PrintS("--- create zero spoly: ");
4364 p_wrp(h,currRing,strat->tailRing);
4365 PrintS(" ---> ");
4366 }
4367#endif
4368 poly tmp = pInit();
4369 pSetCoeff0(tmp, pGetCoeff(p));
4370 for (int i = 1; i <= rVar(currRing); i++)
4371 {
4372 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4373 }
4375 {
4376 p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4377 }
4378 p_Setm(tmp, currRing);
4379 p = p_LmFreeAndNext(p, strat->tailRing);
4380 pNext(tmp) = p;
4381 LObject Lp;
4382 Lp.Init();
4383 Lp.p = tmp;
4384 Lp.tailRing = strat->tailRing;
4385 int posx;
4386 if (Lp.p!=NULL)
4387 {
4388 strat->initEcart(&Lp);
4389 if (strat->Ll==-1)
4390 posx =0;
4391 else
4392 posx = strat->posInL(strat->L,strat->Ll,&Lp,strat);
4393 Lp.sev = pGetShortExpVector(Lp.p);
4394 if (strat->tailRing != currRing)
4395 {
4396 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4397 }
4398#ifdef KDEBUG
4399 if (TEST_OPT_DEBUG)
4400 {
4401 p_wrp(tmp,currRing,strat->tailRing);
4402 PrintLn();
4403 }
4404#endif
4405 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4406 }
4407 }
4408 }
4409 nDelete(&gcd);
4410}
4411
4412void enterExtendedSpolySig(poly h,poly hSig,kStrategy strat)
4413{
4414 if (nIsOne(pGetCoeff(h))) return;
4415 number gcd;
4416 bool go = false;
4417 if (n_DivBy((number) 0, pGetCoeff(h), currRing->cf))
4418 {
4419 gcd = n_Ann(pGetCoeff(h),currRing->cf);
4420 go = true;
4421 }
4422 else
4423 gcd = n_Gcd((number) 0, pGetCoeff(h), strat->tailRing->cf);
4424 if (go || !nIsOne(gcd))
4425 {
4426 poly p = h->next;
4427 if (!go)
4428 {
4429 number tmp = gcd;
4430 gcd = n_Ann(gcd,currRing->cf);
4431 nDelete(&tmp);
4432 }
4433 p_Test(p,strat->tailRing);
4434 p = __pp_Mult_nn(p, gcd, strat->tailRing);
4435
4436 if (p != NULL)
4437 {
4438 if (TEST_OPT_PROT)
4439 {
4440 PrintS("Z");
4441 }
4442#ifdef KDEBUG
4443 if (TEST_OPT_DEBUG)
4444 {
4445 PrintS("--- create zero spoly: ");
4446 p_wrp(h,currRing,strat->tailRing);
4447 PrintS(" ---> ");
4448 }
4449#endif
4450 poly tmp = pInit();
4451 pSetCoeff0(tmp, pGetCoeff(p));
4452 for (int i = 1; i <= rVar(currRing); i++)
4453 {
4454 pSetExp(tmp, i, p_GetExp(p, i, strat->tailRing));
4455 }
4457 {
4458 p_SetComp(tmp, __p_GetComp(p, strat->tailRing), currRing);
4459 }
4460 p_Setm(tmp, currRing);
4461 p = p_LmFreeAndNext(p, strat->tailRing);
4462 pNext(tmp) = p;
4463 LObject Lp;
4464 Lp.Init();
4465 Lp.p = tmp;
4466 //printf("\nOld\n");pWrite(h);pWrite(hSig);
4467 #if EXT_POLY_NEW
4468 Lp.sig = __pp_Mult_nn(hSig, gcd, currRing);
4469 if(Lp.sig == NULL || nIsZero(pGetCoeff(Lp.sig)))
4470 {
4471 strat->sigdrop = TRUE;
4472 //Try to reduce it as far as we can via redRing
4473 int red_result = redRing(&Lp,strat);
4474 if(red_result == 0)
4475 {
4476 // Cancel the sigdrop
4477 p_Delete(&Lp.sig,currRing);Lp.sig = NULL;
4478 strat->sigdrop = FALSE;
4479 return;
4480 }
4481 else
4482 {
4483 strat->enterS(strat->P,strat->sl+1,strat, strat->tl+1);
4484 #if 1
4485 strat->enterS(Lp,0,strat,strat->tl);
4486 #endif
4487 return;
4488 }
4489
4490 }
4491 #else
4492 Lp.sig = pOne();
4493 if(strat->Ll >= 0)
4494 p_SetComp(Lp.sig,pGetComp(strat->L[0].sig)+1,currRing);
4495 else
4496 p_SetComp(Lp.sig,pGetComp(hSig)+1,currRing);
4497 #endif
4498 Lp.tailRing = strat->tailRing;
4499 int posx;
4500 if (Lp.p!=NULL)
4501 {
4502 strat->initEcart(&Lp);
4503 if (strat->Ll==-1)
4504 posx =0;
4505 else
4506 posx = strat->posInLSba(strat->L,strat->Ll,&Lp,strat);
4507 Lp.sev = pGetShortExpVector(Lp.p);
4508 if (strat->tailRing != currRing)
4509 {
4510 Lp.t_p = k_LmInit_currRing_2_tailRing(Lp.p, strat->tailRing);
4511 }
4512#ifdef KDEBUG
4513 if (TEST_OPT_DEBUG)
4514 {
4515 p_wrp(tmp,currRing,strat->tailRing);
4516 PrintLn();
4517 }
4518#endif
4519 //pWrite(h);pWrite(hSig);pWrite(Lp.p);pWrite(Lp.sig);printf("\n------------------\n");getchar();
4520 enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,posx);
4521 }
4522 }
4523 nDelete(&gcd);
4524 }
4525 nDelete(&gcd);
4526}
4527#endif
4528
4529#ifdef HAVE_RINGS
4530void clearSbatch (poly h,int k,int pos,kStrategy strat)
4531{
4532 int j = pos;
4533 if ( (!strat->fromT)
4534 && ((strat->syzComp==0)
4535 ||(pGetComp(h)<=strat->syzComp)
4536 ))
4537 {
4538 // Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl);
4539 unsigned long h_sev = pGetShortExpVector(h);
4540 loop
4541 {
4542 if (j > k) break;
4543 clearS(h,h_sev, &j,&k,strat);
4544 j++;
4545 }
4546 // Print("end clearS sl=%d\n",strat->sl);
4547 }
4548}
4549#endif
4550
4551#ifdef HAVE_RINGS
4552/*2
4553* Generates a sufficient set of spolys (maybe just a finite generating
4554* set of the syzygys)
4555*/
4556void superenterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4557{
4559#if HAVE_SHIFTBBA
4560 assume(!rIsLPRing(currRing)); /* LP should use enterpairsShift */
4561#endif
4562 // enter also zero divisor * poly, if this is non zero and of smaller degree
4564 initenterstrongPairs(h, k, ecart, 0, strat, atR);
4565 initenterpairs(h, k, ecart, 0, strat, atR);
4566 clearSbatch(h, k, pos, strat);
4567}
4568
4569void superenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4570{
4572 // enter also zero divisor * poly, if this is non zero and of smaller degree
4573 if (!(rField_is_Domain(currRing))) enterExtendedSpolySig(h, hSig, strat);
4574 if(strat->sigdrop) return;
4575 initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
4576 if(strat->sigdrop) return;
4577 initenterstrongPairsSig(h, hSig, k, ecart, 0, strat, atR);
4578 if(strat->sigdrop) return;
4579 clearSbatch(h, k, pos, strat);
4580}
4581#endif
4582
4583/*2
4584*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4585*superfluous elements in S will be deleted
4586*/
4587void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
4588{
4589 int j=pos;
4590
4592 initenterpairs(h,k,ecart,0,strat, atR);
4593 if ( (!strat->fromT)
4594 && ((strat->syzComp==0)
4595 ||(pGetComp(h)<=strat->syzComp)))
4596 {
4597 unsigned long h_sev = pGetShortExpVector(h);
4598 loop
4599 {
4600 if (j > k) break;
4601 clearS(h,h_sev, &j,&k,strat);
4602 j++;
4603 }
4604 }
4605}
4606
4607/*2
4608*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4609*superfluous elements in S will be deleted
4610*this is a special variant of signature-based algorithms including the
4611*signatures for criteria checks
4612*/
4613void enterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int pos,kStrategy strat, int atR)
4614{
4615 int j=pos;
4617 initenterpairsSig(h,hSig,hFrom,k,ecart,0,strat, atR);
4618 if ( (!strat->fromT)
4619 && ((strat->syzComp==0)
4620 ||(pGetComp(h)<=strat->syzComp)))
4621 {
4622 unsigned long h_sev = pGetShortExpVector(h);
4623 loop
4624 {
4625 if (j > k) break;
4626 clearS(h,h_sev, &j,&k,strat);
4627 j++;
4628 }
4629 }
4630}
4631
4632/*2
4633*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
4634*superfluous elements in S will be deleted
4635*/
4636void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat, int atR = -1)
4637{
4638 int j;
4639 const int iCompH = pGetComp(h);
4640
4642 {
4643 for (j=0; j<=k; j++)
4644 {
4645 const int iCompSj = pGetComp(strat->S[j]);
4646 if ((iCompH==iCompSj)
4647 //|| (0==iCompH) // can only happen,if iCompSj==0
4648 || (0==iCompSj))
4649 {
4650 enterOnePairRing(j,h,ecart,FALSE,strat, atR);
4651 }
4652 }
4653 kMergeBintoL(strat);
4654 }
4655 else
4656 {
4657 for (j=0; j<=k; j++)
4658 {
4659 const int iCompSj = pGetComp(strat->S[j]);
4660 if ((iCompH==iCompSj)
4661 //|| (0==iCompH) // can only happen,if iCompSj==0
4662 || (0==iCompSj))
4663 {
4664 enterOnePairSpecial(j,h,ecart,strat, atR);
4665 }
4666 }
4667 }
4668
4669 if (strat->noClearS) return;
4670
4671// #ifdef HAVE_PLURAL
4672/*
4673 if (rIsPluralRing(currRing))
4674 {
4675 j=pos;
4676 loop
4677 {
4678 if (j > k) break;
4679
4680 if (pLmDivisibleBy(h, strat->S[j]))
4681 {
4682 deleteInS(j, strat);
4683 j--;
4684 k--;
4685 }
4686
4687 j++;
4688 }
4689 }
4690 else
4691*/
4692// #endif // ??? Why was the following cancelation disabled for non-commutative rings?
4693 {
4694 j=pos;
4695 loop
4696 {
4697 unsigned long h_sev = pGetShortExpVector(h);
4698 if (j > k) break;
4699 clearS(h,h_sev,&j,&k,strat);
4700 j++;
4701 }
4702 }
4703}
4704
4705/*2
4706*reorders s with respect to posInS,
4707*suc is the first changed index or zero
4708*/
4709
4710void reorderS (int* suc,kStrategy strat)
4711{
4712 int i,j,at,ecart, s2r;
4713 int fq=0;
4714 unsigned long sev;
4715 poly p;
4716 int new_suc=strat->sl+1;
4717 i= *suc;
4718 if (i<0) i=0;
4719
4720 for (; i<=strat->sl; i++)
4721 {
4722 at = posInS(strat,i-1,strat->S[i],strat->ecartS[i]);
4723 if (at != i)
4724 {
4725 if (new_suc > at) new_suc = at;
4726 p = strat->S[i];
4727 ecart = strat->ecartS[i];
4728 sev = strat->sevS[i];
4729 s2r = strat->S_2_R[i];
4730 if (strat->fromQ!=NULL) fq=strat->fromQ[i];
4731 for (j=i; j>=at+1; j--)
4732 {
4733 strat->S[j] = strat->S[j-1];
4734 strat->ecartS[j] = strat->ecartS[j-1];
4735 strat->sevS[j] = strat->sevS[j-1];
4736 strat->S_2_R[j] = strat->S_2_R[j-1];
4737 }
4738 strat->S[at] = p;
4739 strat->ecartS[at] = ecart;
4740 strat->sevS[at] = sev;
4741 strat->S_2_R[at] = s2r;
4742 if (strat->fromQ!=NULL)
4743 {
4744 for (j=i; j>=at+1; j--)
4745 {
4746 strat->fromQ[j] = strat->fromQ[j-1];
4747 }
4748 strat->fromQ[at]=fq;
4749 }
4750 }
4751 }
4752 if (new_suc <= strat->sl) *suc=new_suc;
4753 else *suc=-1;
4754}
4755
4756
4757/*2
4758*looks up the position of p in set
4759*set[0] is the smallest with respect to the ordering-procedure deg/pComp
4760* Assumption: posInS only depends on the leading term
4761* otherwise, bba has to be changed
4762*/
4763int posInS (const kStrategy strat, const int length,const poly p,
4764 const int ecart_p)
4765{
4766 if(length==-1) return 0;
4767 polyset set=strat->S;
4768 int i;
4769 int an = 0;
4770 int en = length;
4771 int cmp_int = currRing->OrdSgn;
4773#ifdef HAVE_PLURAL
4774 && (currRing->real_var_start==0)
4775#endif
4776#if 0
4777 || ((strat->ak>0) && ((currRing->order[0]==ringorder_c)||((currRing->order[0]==ringorder_C))))
4778#endif
4779 )
4780 {
4781 int o=p_Deg(p,currRing);
4782 int oo=p_Deg(set[length],currRing);
4783
4784 if ((oo<o)
4785 || ((o==oo) && (pLmCmp(set[length],p)!= cmp_int)))
4786 return length+1;
4787
4788 loop
4789 {
4790 if (an >= en-1)
4791 {
4792 if ((p_Deg(set[an],currRing)>=o) && (pLmCmp(set[an],p) == cmp_int))
4793 {
4794 return an;
4795 }
4796 return en;
4797 }
4798 i=(an+en) / 2;
4799 if ((p_Deg(set[i],currRing)>=o) && (pLmCmp(set[i],p) == cmp_int)) en=i;
4800 else an=i;
4801 }
4802 }
4803 else
4804 {
4806 {
4807 if (pLmCmp(set[length],p)== -cmp_int)
4808 return length+1;
4809 int cmp;
4810 loop
4811 {
4812 if (an >= en-1)
4813 {
4814 cmp = pLmCmp(set[an],p);
4815 if (cmp == cmp_int) return an;
4816 if (cmp == -cmp_int) return en;
4817 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[an]), currRing->cf)) return en;
4818 return an;
4819 }
4820 i = (an+en) / 2;
4821 cmp = pLmCmp(set[i],p);
4822 if (cmp == cmp_int) en = i;
4823 else if (cmp == -cmp_int) an = i;
4824 else
4825 {
4826 if (n_DivBy(pGetCoeff(p), pGetCoeff(set[i]), currRing->cf)) an = i;
4827 else en = i;
4828 }
4829 }
4830 }
4831 else
4832 if (pLmCmp(set[length],p)== -cmp_int)
4833 return length+1;
4834
4835 loop
4836 {
4837 if (an >= en-1)
4838 {
4839 if (pLmCmp(set[an],p) == cmp_int) return an;
4840 if (pLmCmp(set[an],p) == -cmp_int) return en;
4841 if ((cmp_int!=1)
4842 && ((strat->ecartS[an])>ecart_p))
4843 return an;
4844 return en;
4845 }
4846 i=(an+en) / 2;
4847 if (pLmCmp(set[i],p) == cmp_int) en=i;
4848 else if (pLmCmp(set[i],p) == -cmp_int) an=i;
4849 else
4850 {
4851 if ((cmp_int!=1)
4852 &&((strat->ecartS[i])<ecart_p))
4853 en=i;
4854 else
4855 an=i;
4856 }
4857 }
4858 }
4859}
4860
4861
4862// sorts by degree and pLtCmp
4863// but puts pure monomials at the beginning
4864int posInSMonFirst (const kStrategy strat, const int length,const poly p)
4865{
4866 if (length<0) return 0;
4867 polyset set=strat->S;
4868 if(pNext(p) == NULL)
4869 {
4870 int mon = 0;
4871 for(int i = 0;i<=length;i++)
4872 {
4873 if(set[i] != NULL && pNext(set[i]) == NULL)
4874 mon++;
4875 }
4876 int o = p_Deg(p,currRing);
4877 int op = p_Deg(set[mon],currRing);
4878
4879 if ((op < o)
4880 || ((op == o) && (pLtCmp(set[mon],p) == -1)))
4881 return length+1;
4882 int i;
4883 int an = 0;
4884 int en= mon;
4885 loop
4886 {
4887 if (an >= en-1)
4888 {
4889 op = p_Deg(set[an],currRing);
4890 if ((op < o)
4891 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4892 return en;
4893 return an;
4894 }
4895 i=(an+en) / 2;
4896 op = p_Deg(set[i],currRing);
4897 if ((op < o)
4898 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4899 an=i;
4900 else
4901 en=i;
4902 }
4903 }
4904 else /*if(pNext(p) != NULL)*/
4905 {
4906 int o = p_Deg(p,currRing);
4907 int op = p_Deg(set[length],currRing);
4908
4909 if ((op < o)
4910 || ((op == o) && (pLtCmp(set[length],p) == -1)))
4911 return length+1;
4912 int i;
4913 int an = 0;
4914 for(i=0;i<=length;i++)
4915 if(set[i] != NULL && pNext(set[i]) == NULL)
4916 an++;
4917 int en= length;
4918 loop
4919 {
4920 if (an >= en-1)
4921 {
4922 op = p_Deg(set[an],currRing);
4923 if ((op < o)
4924 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4925 return en;
4926 return an;
4927 }
4928 i=(an+en) / 2;
4929 op = p_Deg(set[i],currRing);
4930 if ((op < o)
4931 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4932 an=i;
4933 else
4934 en=i;
4935 }
4936 }
4937}
4938
4939// sorts by degree and pLtCmp in the block between start,end;
4940// but puts pure monomials at the beginning
4941int posInIdealMonFirst (const ideal F, const poly p,int start,int end)
4942{
4943 if(end < 0 || end >= IDELEMS(F))
4944 end = IDELEMS(F);
4945 if (end<0) return 0;
4946 if(pNext(p) == NULL) return start;
4947 polyset set=F->m;
4948 int o = p_Deg(p,currRing);
4949 int op;
4950 int i;
4951 int an = start;
4952 for(i=start;i<end;i++)
4953 if(set[i] != NULL && pNext(set[i]) == NULL)
4954 an++;
4955 if(an == end-1)
4956 return end;
4957 int en= end;
4958 loop
4959 {
4960 if(an>=en)
4961 return en;
4962 if (an == en-1)
4963 {
4964 op = p_Deg(set[an],currRing);
4965 if ((op < o)
4966 || ((op == o) && (pLtCmp(set[an],p) == -1)))
4967 return en;
4968 return an;
4969 }
4970 i=(an+en) / 2;
4971 op = p_Deg(set[i],currRing);
4972 if ((op < o)
4973 || ((op == o) && (pLtCmp(set[i],p) == -1)))
4974 an=i;
4975 else
4976 en=i;
4977 }
4978}
4979
4980
4981/*2
4982* looks up the position of p in set
4983* the position is the last one
4984*/
4985int posInT0 (const TSet,const int length,LObject &)
4986{
4987 return (length+1);
4988}
4989
4990
4991/*2
4992* looks up the position of p in T
4993* set[0] is the smallest with respect to the ordering-procedure
4994* pComp
4995*/
4996int posInT1 (const TSet set,const int length,LObject &p)
4997{
4998 if (length==-1) return 0;
4999
5000 if (pLmCmp(set[length].p,p.p)!= currRing->OrdSgn) return length+1;
5001
5002 int i;
5003 int an = 0;
5004 int en= length;
5005 int cmp_int=currRing->OrdSgn;
5006
5007 loop
5008 {
5009 if (an >= en-1)
5010 {
5011 if (pLmCmp(set[an].p,p.p) == cmp_int) return an;
5012 return en;
5013 }
5014 i=(an+en) / 2;
5015 if (pLmCmp(set[i].p,p.p) == cmp_int) en=i;
5016 else an=i;
5017 }
5018}
5019
5020/*2
5021* looks up the position of p in T
5022* set[0] is the smallest with respect to the ordering-procedure
5023* length
5024*/
5025int posInT2 (const TSet set,const int length,LObject &p)
5026{
5027 if (length==-1) return 0;
5028 p.GetpLength();
5029 if (set[length].length<p.length) return length+1;
5030
5031 int i;
5032 int an = 0;
5033 int en= length;
5034
5035 loop
5036 {
5037 if (an >= en-1)
5038 {
5039 if (set[an].length>p.length) return an;
5040 return en;
5041 }
5042 i=(an+en) / 2;
5043 if (set[i].length>p.length) en=i;
5044 else an=i;
5045 }
5046}
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 posInT11 (const TSet set,const int length,LObject &p)
5054{
5055 if (length==-1) return 0;
5056
5057 int o = p.GetpFDeg();
5058 int op = set[length].GetpFDeg();
5059 int cmp_int=currRing->OrdSgn;
5060
5061 if ((op < o)
5062 || ((op == o) && (pLmCmp(set[length].p,p.p) != cmp_int)))
5063 return length+1;
5064
5065 int i;
5066 int an = 0;
5067 int en= length;
5068
5069 loop
5070 {
5071 if (an >= en-1)
5072 {
5073 op= set[an].GetpFDeg();
5074 if ((op > o)
5075 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
5076 return an;
5077 return en;
5078 }
5079 i=(an+en) / 2;
5080 op = set[i].GetpFDeg();
5081 if (( op > o)
5082 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
5083 en=i;
5084 else
5085 an=i;
5086 }
5087}
5088
5089#ifdef HAVE_RINGS
5090int posInT11Ring (const TSet set,const int length,LObject &p)
5091{
5092 if (length==-1) return 0;
5093
5094 int o = p.GetpFDeg();
5095 int op = set[length].GetpFDeg();
5096
5097 if ((op < o)
5098 || ((op == o) && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5099 return length+1;
5100
5101 int i;
5102 int an = 0;
5103 int en= length;
5104
5105 loop
5106 {
5107 if (an >= en-1)
5108 {
5109 op= set[an].GetpFDeg();
5110 if ((op > o)
5111 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5112 return an;
5113 return en;
5114 }
5115 i=(an+en) / 2;
5116 op = set[i].GetpFDeg();
5117 if (( op > o)
5118 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5119 en=i;
5120 else
5121 an=i;
5122 }
5123}
5124#endif
5125
5126/*2 Pos for rings T: Here I am
5127* looks up the position of p in T
5128* set[0] is the smallest with respect to the ordering-procedure
5129* totaldegree,pComp
5130*/
5131int posInTrg0 (const TSet set,const int length,LObject &p)
5132{
5133 if (length==-1) return 0;
5134 int o = p.GetpFDeg();
5135 int op = set[length].GetpFDeg();
5136 int i;
5137 int an = 0;
5138 int en = length;
5139 int cmp_int = currRing->OrdSgn;
5140 if ((op < o) || (pLmCmp(set[length].p,p.p)== -cmp_int))
5141 return length+1;
5142 int cmp;
5143 loop
5144 {
5145 if (an >= en-1)
5146 {
5147 op = set[an].GetpFDeg();
5148 if (op > o) return an;
5149 if (op < 0) return en;
5150 cmp = pLmCmp(set[an].p,p.p);
5151 if (cmp == cmp_int) return an;
5152 if (cmp == -cmp_int) return en;
5153 if (nGreater(pGetCoeff(p.p), pGetCoeff(set[an].p))) return en;
5154 return an;
5155 }
5156 i = (an + en) / 2;
5157 op = set[i].GetpFDeg();
5158 if (op > o) en = i;
5159 else if (op < o) an = i;
5160 else
5161 {
5162 cmp = pLmCmp(set[i].p,p.p);
5163 if (cmp == cmp_int) en = i;
5164 else if (cmp == -cmp_int) an = i;
5165 else if (nGreater(pGetCoeff(p.p), pGetCoeff(set[i].p))) an = i;
5166 else en = i;
5167 }
5168 }
5169}
5170/*
5171 int o = p.GetpFDeg();
5172 int op = set[length].GetpFDeg();
5173
5174 if ((op < o)
5175 || ((op == o) && (pLmCmp(set[length].p,p.p) != currRing->OrdSgn)))
5176 return length+1;
5177
5178 int i;
5179 int an = 0;
5180 int en= length;
5181
5182 loop
5183 {
5184 if (an >= en-1)
5185 {
5186 op= set[an].GetpFDeg();
5187 if ((op > o)
5188 || (( op == o) && (pLmCmp(set[an].p,p.p) == currRing->OrdSgn)))
5189 return an;
5190 return en;
5191 }
5192 i=(an+en) / 2;
5193 op = set[i].GetpFDeg();
5194 if (( op > o)
5195 || (( op == o) && (pLmCmp(set[i].p,p.p) == currRing->OrdSgn)))
5196 en=i;
5197 else
5198 an=i;
5199 }
5200}
5201 */
5202/*2
5203* looks up the position of p in T
5204* set[0] is the smallest with respect to the ordering-procedure
5205* totaldegree,pComp
5206*/
5207int posInT110 (const TSet set,const int length,LObject &p)
5208{
5209 if (length==-1) return 0;
5210 p.GetpLength();
5211
5212 int o = p.GetpFDeg();
5213 int op = set[length].GetpFDeg();
5214 int cmp_int=currRing->OrdSgn;
5215
5216 if (( op < o)
5217 || (( op == o) && (set[length].length<p.length))
5218 || (( op == o) && (set[length].length == p.length)
5219 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5220 return length+1;
5221
5222 int i;
5223 int an = 0;
5224 int en= length;
5225 loop
5226 {
5227 if (an >= en-1)
5228 {
5229 op = set[an].GetpFDeg();
5230 if (( op > o)
5231 || (( op == o) && (set[an].length > p.length))
5232 || (( op == o) && (set[an].length == p.length)
5233 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5234 return an;
5235 return en;
5236 }
5237 i=(an+en) / 2;
5238 op = set[i].GetpFDeg();
5239 if (( op > o)
5240 || (( op == o) && (set[i].length > p.length))
5241 || (( op == o) && (set[i].length == p.length)
5242 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5243 en=i;
5244 else
5245 an=i;
5246 }
5247}
5248
5249#ifdef HAVE_RINGS
5250int posInT110Ring (const TSet set,const int length,LObject &p)
5251{
5252 if (length==-1) return 0;
5253 p.GetpLength();
5254
5255 int o = p.GetpFDeg();
5256 int op = set[length].GetpFDeg();
5257
5258 if (( op < o)
5259 || (( op == o) && (set[length].length<p.length))
5260 || (( op == o) && (set[length].length == p.length)
5261 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5262 return length+1;
5263
5264 int i;
5265 int an = 0;
5266 int en= length;
5267 loop
5268 {
5269 if (an >= en-1)
5270 {
5271 op = set[an].GetpFDeg();
5272 if (( op > o)
5273 || (( op == o) && (set[an].length > p.length))
5274 || (( op == o) && (set[an].length == p.length)
5275 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5276 return an;
5277 return en;
5278 }
5279 i=(an+en) / 2;
5280 op = set[i].GetpFDeg();
5281 if (( op > o)
5282 || (( op == o) && (set[i].length > p.length))
5283 || (( op == o) && (set[i].length == p.length)
5284 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5285 en=i;
5286 else
5287 an=i;
5288 }
5289}
5290#endif
5291
5292/*2
5293* looks up the position of p in set
5294* set[0] is the smallest with respect to the ordering-procedure
5295* pFDeg
5296*/
5297int posInT13 (const TSet set,const int length,LObject &p)
5298{
5299 if (length==-1) return 0;
5300
5301 int o = p.GetpFDeg();
5302
5303 if (set[length].GetpFDeg() <= o)
5304 return length+1;
5305
5306 int i;
5307 int an = 0;
5308 int en= length;
5309 loop
5310 {
5311 if (an >= en-1)
5312 {
5313 if (set[an].GetpFDeg() > o)
5314 return an;
5315 return en;
5316 }
5317 i=(an+en) / 2;
5318 if (set[i].GetpFDeg() > o)
5319 en=i;
5320 else
5321 an=i;
5322 }
5323}
5324
5325// determines the position based on: 1.) Ecart 2.) pLength
5326int posInT_EcartpLength(const TSet set,const int length,LObject &p)
5327{
5328 if (length==-1) return 0;
5329 int ol = p.GetpLength();
5330 int op=p.ecart;
5331 int oo=set[length].ecart;
5332
5333 if ((oo < op) || ((oo==op) && (set[length].length <= ol)))
5334 return length+1;
5335
5336 int i;
5337 int an = 0;
5338 int en= length;
5339 loop
5340 {
5341 if (an >= en-1)
5342 {
5343 int oo=set[an].ecart;
5344 if((oo > op)
5345 || ((oo==op) && (set[an].pLength > ol)))
5346 return an;
5347 return en;
5348 }
5349 i=(an+en) / 2;
5350 int oo=set[i].ecart;
5351 if ((oo > op)
5352 || ((oo == op) && (set[i].pLength > ol)))
5353 en=i;
5354 else
5355 an=i;
5356 }
5357}
5358
5359/*2
5360* looks up the position of p in set
5361* set[0] is the smallest with respect to the ordering-procedure
5362* maximaldegree, pComp
5363*/
5364int posInT15 (const TSet set,const int length,LObject &p)
5365/*{
5366 *int j=0;
5367 * int o;
5368 *
5369 * o = p.GetpFDeg()+p.ecart;
5370 * loop
5371 * {
5372 * if ((set[j].GetpFDeg()+set[j].ecart > o)
5373 * || ((set[j].GetpFDeg()+set[j].ecart == o)
5374 * && (pLmCmp(set[j].p,p.p) == currRing->OrdSgn)))
5375 * {
5376 * return j;
5377 * }
5378 * j++;
5379 * if (j > length) return j;
5380 * }
5381 *}
5382 */
5383{
5384 if (length==-1) return 0;
5385
5386 int o = p.GetpFDeg() + p.ecart;
5387 int op = set[length].GetpFDeg()+set[length].ecart;
5388 int cmp_int=currRing->OrdSgn;
5389
5390 if ((op < o)
5391 || ((op == o)
5392 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5393 return length+1;
5394
5395 int i;
5396 int an = 0;
5397 int en= length;
5398 loop
5399 {
5400 if (an >= en-1)
5401 {
5402 op = set[an].GetpFDeg()+set[an].ecart;
5403 if (( op > o)
5404 || (( op == o) && (pLmCmp(set[an].p,p.p) == cmp_int)))
5405 return an;
5406 return en;
5407 }
5408 i=(an+en) / 2;
5409 op = set[i].GetpFDeg()+set[i].ecart;
5410 if (( op > o)
5411 || (( op == o) && (pLmCmp(set[i].p,p.p) == cmp_int)))
5412 en=i;
5413 else
5414 an=i;
5415 }
5416}
5417
5418#ifdef HAVE_RINGS
5419int posInT15Ring (const TSet set,const int length,LObject &p)
5420{
5421 if (length==-1) return 0;
5422
5423 int o = p.GetpFDeg() + p.ecart;
5424 int op = set[length].GetpFDeg()+set[length].ecart;
5425
5426 if ((op < o)
5427 || ((op == o)
5428 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5429 return length+1;
5430
5431 int i;
5432 int an = 0;
5433 int en= length;
5434 loop
5435 {
5436 if (an >= en-1)
5437 {
5438 op = set[an].GetpFDeg()+set[an].ecart;
5439 if (( op > o)
5440 || (( op == o) && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5441 return an;
5442 return en;
5443 }
5444 i=(an+en) / 2;
5445 op = set[i].GetpFDeg()+set[i].ecart;
5446 if (( op > o)
5447 || (( op == o) && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5448 en=i;
5449 else
5450 an=i;
5451 }
5452}
5453#endif
5454
5455/*2
5456* looks up the position of p in set
5457* set[0] is the smallest with respect to the ordering-procedure
5458* pFDeg+ecart, ecart, pComp
5459*/
5460int posInT17 (const TSet set,const int length,LObject &p)
5461/*
5462*{
5463* int j=0;
5464* int o;
5465*
5466* o = p.GetpFDeg()+p.ecart;
5467* loop
5468* {
5469* if ((pFDeg(set[j].p)+set[j].ecart > o)
5470* || (((pFDeg(set[j].p)+set[j].ecart == o)
5471* && (set[j].ecart < p.ecart)))
5472* || ((pFDeg(set[j].p)+set[j].ecart == o)
5473* && (set[j].ecart==p.ecart)
5474* && (pLmCmp(set[j].p,p.p)==currRing->OrdSgn)))
5475* return j;
5476* j++;
5477* if (j > length) return j;
5478* }
5479* }
5480*/
5481{
5482 if (length==-1) return 0;
5483
5484 int o = p.GetpFDeg() + p.ecart;
5485 int op = set[length].GetpFDeg()+set[length].ecart;
5486 int cmp_int=currRing->OrdSgn;
5487
5488 if ((op < o)
5489 || (( op == o) && (set[length].ecart > p.ecart))
5490 || (( op == o) && (set[length].ecart==p.ecart)
5491 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5492 return length+1;
5493
5494 int i;
5495 int an = 0;
5496 int en= length;
5497 loop
5498 {
5499 if (an >= en-1)
5500 {
5501 op = set[an].GetpFDeg()+set[an].ecart;
5502 if (( op > o)
5503 || (( op == o) && (set[an].ecart < p.ecart))
5504 || (( op == o) && (set[an].ecart==p.ecart)
5505 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5506 return an;
5507 return en;
5508 }
5509 i=(an+en) / 2;
5510 op = set[i].GetpFDeg()+set[i].ecart;
5511 if ((op > o)
5512 || (( op == o) && (set[i].ecart < p.ecart))
5513 || (( op == o) && (set[i].ecart == p.ecart)
5514 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5515 en=i;
5516 else
5517 an=i;
5518 }
5519}
5520
5521#ifdef HAVE_RINGS
5522int posInT17Ring (const TSet set,const int length,LObject &p)
5523{
5524 if (length==-1) return 0;
5525
5526 int o = p.GetpFDeg() + p.ecart;
5527 int op = set[length].GetpFDeg()+set[length].ecart;
5528
5529 if ((op < o)
5530 || (( op == o) && (set[length].ecart > p.ecart))
5531 || (( op == o) && (set[length].ecart==p.ecart)
5532 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5533 return length+1;
5534
5535 int i;
5536 int an = 0;
5537 int en= length;
5538 loop
5539 {
5540 if (an >= en-1)
5541 {
5542 op = set[an].GetpFDeg()+set[an].ecart;
5543 if (( op > o)
5544 || (( op == o) && (set[an].ecart < p.ecart))
5545 || (( op == o) && (set[an].ecart==p.ecart)
5546 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5547 return an;
5548 return en;
5549 }
5550 i=(an+en) / 2;
5551 op = set[i].GetpFDeg()+set[i].ecart;
5552 if ((op > o)
5553 || (( op == o) && (set[i].ecart < p.ecart))
5554 || (( op == o) && (set[i].ecart == p.ecart)
5555 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5556 en=i;
5557 else
5558 an=i;
5559 }
5560}
5561#endif
5562
5563/*2
5564* looks up the position of p in set
5565* set[0] is the smallest with respect to the ordering-procedure
5566* pGetComp, pFDeg+ecart, ecart, pComp
5567*/
5568int posInT17_c (const TSet set,const int length,LObject &p)
5569{
5570 if (length==-1) return 0;
5571
5572 int cc = (-1+2*currRing->order[0]==ringorder_c);
5573 /* cc==1 for (c,..), cc==-1 for (C,..) */
5574 int o = p.GetpFDeg() + p.ecart;
5575 int c = pGetComp(p.p)*cc;
5576 int cmp_int=currRing->OrdSgn;
5577
5578 if (pGetComp(set[length].p)*cc < c)
5579 return length+1;
5580 if (pGetComp(set[length].p)*cc == c)
5581 {
5582 int op = set[length].GetpFDeg()+set[length].ecart;
5583 if ((op < o)
5584 || ((op == o) && (set[length].ecart > p.ecart))
5585 || ((op == o) && (set[length].ecart==p.ecart)
5586 && (pLmCmp(set[length].p,p.p) != cmp_int)))
5587 return length+1;
5588 }
5589
5590 int i;
5591 int an = 0;
5592 int en= length;
5593 loop
5594 {
5595 if (an >= en-1)
5596 {
5597 if (pGetComp(set[an].p)*cc < c)
5598 return en;
5599 if (pGetComp(set[an].p)*cc == c)
5600 {
5601 int op = set[an].GetpFDeg()+set[an].ecart;
5602 if ((op > o)
5603 || ((op == o) && (set[an].ecart < p.ecart))
5604 || ((op == o) && (set[an].ecart==p.ecart)
5605 && (pLmCmp(set[an].p,p.p) == cmp_int)))
5606 return an;
5607 }
5608 return en;
5609 }
5610 i=(an+en) / 2;
5611 if (pGetComp(set[i].p)*cc > c)
5612 en=i;
5613 else if (pGetComp(set[i].p)*cc == c)
5614 {
5615 int op = set[i].GetpFDeg()+set[i].ecart;
5616 if ((op > o)
5617 || ((op == o) && (set[i].ecart < p.ecart))
5618 || ((op == o) && (set[i].ecart == p.ecart)
5619 && (pLmCmp(set[i].p,p.p) == cmp_int)))
5620 en=i;
5621 else
5622 an=i;
5623 }
5624 else
5625 an=i;
5626 }
5627}
5628
5629#ifdef HAVE_RINGS
5630int posInT17_cRing (const TSet set,const int length,LObject &p)
5631{
5632 if (length==-1) return 0;
5633
5634 int cc = (-1+2*currRing->order[0]==ringorder_c);
5635 /* cc==1 for (c,..), cc==-1 for (C,..) */
5636 int o = p.GetpFDeg() + p.ecart;
5637 int c = pGetComp(p.p)*cc;
5638
5639 if (pGetComp(set[length].p)*cc < c)
5640 return length+1;
5641 if (pGetComp(set[length].p)*cc == c)
5642 {
5643 int op = set[length].GetpFDeg()+set[length].ecart;
5644 if ((op < o)
5645 || ((op == o) && (set[length].ecart > p.ecart))
5646 || ((op == o) && (set[length].ecart==p.ecart)
5647 && (pLtCmpOrdSgnDiffP(set[length].p,p.p))))
5648 return length+1;
5649 }
5650
5651 int i;
5652 int an = 0;
5653 int en= length;
5654 loop
5655 {
5656 if (an >= en-1)
5657 {
5658 if (pGetComp(set[an].p)*cc < c)
5659 return en;
5660 if (pGetComp(set[an].p)*cc == c)
5661 {
5662 int op = set[an].GetpFDeg()+set[an].ecart;
5663 if ((op > o)
5664 || ((op == o) && (set[an].ecart < p.ecart))
5665 || ((op == o) && (set[an].ecart==p.ecart)
5666 && (pLtCmpOrdSgnEqP(set[an].p,p.p))))
5667 return an;
5668 }
5669 return en;
5670 }
5671 i=(an+en) / 2;
5672 if (pGetComp(set[i].p)*cc > c)
5673 en=i;
5674 else if (pGetComp(set[i].p)*cc == c)
5675 {
5676 int op = set[i].GetpFDeg()+set[i].ecart;
5677 if ((op > o)
5678 || ((op == o) && (set[i].ecart < p.ecart))
5679 || ((op == o) && (set[i].ecart == p.ecart)
5680 && (pLtCmpOrdSgnEqP(set[i].p,p.p))))
5681 en=i;
5682 else
5683 an=i;
5684 }
5685 else
5686 an=i;
5687 }
5688}
5689#endif
5690
5691/*2
5692* looks up the position of p in set
5693* set[0] is the smallest with respect to
5694* ecart, pFDeg, length
5695*/
5696int posInT19 (const TSet set,const int length,LObject &p)
5697{
5698 p.GetpLength();
5699 if (length==-1) return 0;
5700
5701 int o = p.ecart;
5702 int op=p.GetpFDeg();
5703
5704 if (set[length].ecart < o)
5705 return length+1;
5706 if (set[length].ecart == o)
5707 {
5708 int oo=set[length].GetpFDeg();
5709 if ((oo < op) || ((oo==op) && (set[length].length < p.length)))
5710 return length+1;
5711 }
5712
5713 int i;
5714 int an = 0;
5715 int en= length;
5716 loop
5717 {
5718 if (an >= en-1)
5719 {
5720 if (set[an].ecart > o)
5721 return an;
5722 if (set[an].ecart == o)
5723 {
5724 int oo=set[an].GetpFDeg();
5725 if((oo > op)
5726 || ((oo==op) && (set[an].length > p.length)))
5727 return an;
5728 }
5729 return en;
5730 }
5731 i=(an+en) / 2;
5732 if (set[i].ecart > o)
5733 en=i;
5734 else if (set[i].ecart == o)
5735 {
5736 int oo=set[i].GetpFDeg();
5737 if ((oo > op)
5738 || ((oo == op) && (set[i].length > p.length)))
5739 en=i;
5740 else
5741 an=i;
5742 }
5743 else
5744 an=i;
5745 }
5746}
5747
5748/*2
5749*looks up the position of polynomial p in set
5750*set[length] is the smallest element in set with respect
5751*to the ordering-procedure pComp
5752*/
5753int posInLSpecial (const LSet set, const int length,
5754 LObject *p,const kStrategy)
5755{
5756 if (length<0) return 0;
5757
5758 int d=p->GetpFDeg();
5759 int op=set[length].GetpFDeg();
5760 int cmp_int=currRing->OrdSgn;
5761
5762 if ((op > d)
5763 || ((op == d) && (p->p1!=NULL)&&(set[length].p1==NULL))
5764 || (pLmCmp(set[length].p,p->p)== cmp_int))
5765 return length+1;
5766
5767 int i;
5768 int an = 0;
5769 int en= length;
5770 loop
5771 {
5772 if (an >= en-1)
5773 {
5774 op=set[an].GetpFDeg();
5775 if ((op > d)
5776 || ((op == d) && (p->p1!=NULL) && (set[an].p1==NULL))
5777 || (pLmCmp(set[an].p,p->p)== cmp_int))
5778 return en;
5779 return an;
5780 }
5781 i=(an+en) / 2;
5782 op=set[i].GetpFDeg();
5783 if ((op>d)
5784 || ((op==d) && (p->p1!=NULL) && (set[i].p1==NULL))
5785 || (pLmCmp(set[i].p,p->p) == cmp_int))
5786 an=i;
5787 else
5788 en=i;
5789 }
5790}
5791
5792/*2
5793*looks up the position of polynomial p in set
5794*set[length] is the smallest element in set with respect
5795*to the ordering-procedure pComp
5796*/
5797int posInL0 (const LSet set, const int length,
5798 LObject* p,const kStrategy)
5799{
5800 if (length<0) return 0;
5801
5802 int cmp_int=currRing->OrdSgn;
5803
5804 if (pLmCmp(set[length].p,p->p)== cmp_int)
5805 return length+1;
5806
5807 int i;
5808 int an = 0;
5809 int en= length;
5810 loop
5811 {
5812 if (an >= en-1)
5813 {
5814 if (pLmCmp(set[an].p,p->p) == cmp_int) return en;
5815 return an;
5816 }
5817 i=(an+en) / 2;
5818 if (pLmCmp(set[i].p,p->p) == cmp_int) an=i;
5819 else en=i;
5820 /*aend. fuer lazy == in !=- machen */
5821 }
5822}
5823
5824#ifdef HAVE_RINGS
5825int posInL0Ring (const LSet set, const int length,
5826 LObject* p,const kStrategy)
5827{
5828 if (length<0) return 0;
5829
5830 if (pLtCmpOrdSgnEqP(set[length].p,p->p))
5831 return length+1;
5832
5833 int i;
5834 int an = 0;
5835 int en= length;
5836 loop
5837 {
5838 if (an >= en-1)
5839 {
5840 if (pLtCmpOrdSgnEqP(set[an].p,p->p)) return en;
5841 return an;
5842 }
5843 i=(an+en) / 2;
5844 if (pLtCmpOrdSgnEqP(set[i].p,p->p)) an=i;
5845 else en=i;
5846 /*aend. fuer lazy == in !=- machen */
5847 }
5848}
5849#endif
5850
5851/*2
5852* looks up the position of polynomial p in set
5853* e is the ecart of p
5854* set[length] is the smallest element in set with respect
5855* to the signature order
5856*/
5857int posInLSig (const LSet set, const int length,
5858 LObject* p,const kStrategy /*strat*/)
5859{
5860 if (length<0) return 0;
5861 int cmp_int=currRing->OrdSgn;
5862 if (pLtCmp(set[length].sig,p->sig)==cmp_int)
5863 return length+1;
5864
5865 int i;
5866 int an = 0;
5867 int en= length;
5868 loop
5869 {
5870 if (an >= en-1)
5871 {
5872 if (pLtCmp(set[an].sig,p->sig) == cmp_int) return en;
5873 return an;
5874 }
5875 i=(an+en) / 2;
5876 if (pLtCmp(set[i].sig,p->sig) == cmp_int) an=i;
5877 else en=i;
5878 /*aend. fuer lazy == in !=- machen */
5879 }
5880}
5881//sorts the pair list in this order: pLtCmp on the sigs, FDeg, pLtCmp on the polys
5882int posInLSigRing (const LSet set, const int length,
5883 LObject* p,const kStrategy /*strat*/)
5884{
5885 assume(currRing->OrdSgn == 1 && rField_is_Ring(currRing));
5886 if (length<0) return 0;
5887 if (pLtCmp(set[length].sig,p->sig)== 1)
5888 return length+1;
5889
5890 int an,en,i;
5891 an = 0;
5892 en = length+1;
5893 int cmp;
5894 loop
5895 {
5896 if (an >= en-1)
5897 {
5898 if(an == en)
5899 return en;
5900 cmp = pLtCmp(set[an].sig,p->sig);
5901 if (cmp == 1)
5902 return en;
5903 if (cmp == -1)
5904 return an;
5905 if (cmp == 0)
5906 {
5907 if (set[an].FDeg > p->FDeg)
5908 return en;
5909 if (set[an].FDeg < p->FDeg)
5910 return an;
5911 if (set[an].FDeg == p->FDeg)
5912 {
5913 cmp = pLtCmp(set[an].p,p->p);
5914 if(cmp == 1)
5915 return en;
5916 else
5917 return an;
5918 }
5919 }
5920 }
5921 i=(an+en) / 2;
5922 cmp = pLtCmp(set[i].sig,p->sig);
5923 if (cmp == 1)
5924 an = i;
5925 if (cmp == -1)
5926 en = i;
5927 if (cmp == 0)
5928 {
5929 if (set[i].FDeg > p->FDeg)
5930 an = i;
5931 if (set[i].FDeg < p->FDeg)
5932 en = i;
5933 if (set[i].FDeg == p->FDeg)
5934 {
5935 cmp = pLtCmp(set[i].p,p->p);
5936 if(cmp == 1)
5937 an = i;
5938 else
5939 en = i;
5940 }
5941 }
5942 }
5943}
5944
5945int posInLRing (const LSet set, const int length,
5946 LObject* p,const kStrategy /*strat*/)
5947{
5948 if (length < 0) return 0;
5949 if (set[length].FDeg > p->FDeg)
5950 return length+1;
5951 if (set[length].FDeg == p->FDeg)
5952 if(set[length].GetpLength() > p->GetpLength())
5953 return length+1;
5954 int i;
5955 int an = 0;
5956 int en= length+1;
5957 loop
5958 {
5959 if (an >= en-1)
5960 {
5961 if(an == en)
5962 return en;
5963 if (set[an].FDeg > p->FDeg)
5964 return en;
5965 if(set[an].FDeg == p->FDeg)
5966 {
5967 if(set[an].GetpLength() > p->GetpLength())
5968 return en;
5969 else
5970 {
5971 if(set[an].GetpLength() == p->GetpLength())
5972 {
5973 if(nGreater(set[an].p->coef, p->p->coef))
5974 return en;
5975 else
5976 return an;
5977 }
5978 else
5979 {
5980 return an;
5981 }
5982 }
5983 }
5984 else
5985 return an;
5986 }
5987 i=(an+en) / 2;
5988 if (set[i].FDeg > p->FDeg)
5989 an=i;
5990 else
5991 {
5992 if(set[i].FDeg == p->FDeg)
5993 {
5994 if(set[i].GetpLength() > p->GetpLength())
5995 an=i;
5996 else
5997 {
5998 if(set[i].GetpLength() == p->GetpLength())
5999 {
6000 if(nGreater(set[i].p->coef, p->p->coef))
6001 an = i;
6002 else
6003 en = i;
6004 }
6005 else
6006 {
6007 en=i;
6008 }
6009 }
6010 }
6011 else
6012 en=i;
6013 }
6014 }
6015}
6016
6017// for sba, sorting syzygies
6018int posInSyz (const kStrategy strat, poly sig)
6019{
6020 if (strat->syzl==0) return 0;
6021 int cmp_int=currRing->OrdSgn;
6022 if (pLtCmp(strat->syz[strat->syzl-1],sig) != cmp_int)
6023 return strat->syzl;
6024 int i;
6025 int an = 0;
6026 int en= strat->syzl-1;
6027 loop
6028 {
6029 if (an >= en-1)
6030 {
6031 if (pLtCmp(strat->syz[an],sig) != cmp_int) return en;
6032 return an;
6033 }
6034 i=(an+en) / 2;
6035 if (pLtCmp(strat->syz[i],sig) != cmp_int) an=i;
6036 else en=i;
6037 /*aend. fuer lazy == in !=- machen */
6038 }
6039}
6040
6041/*2
6042*
6043* is only used in F5C, must ensure that the interreduction process does add new
6044* critical pairs to strat->L only behind all other critical pairs which are
6045* still in strat->L!
6046*/
6047int posInLF5C (const LSet /*set*/, const int /*length*/,
6048 LObject* /*p*/,const kStrategy strat)
6049{
6050 return strat->Ll+1;
6051}
6052
6053/*2
6054* looks up the position of polynomial p in set
6055* e is the ecart of p
6056* set[length] is the smallest element in set with respect
6057* to the ordering-procedure totaldegree,pComp
6058*/
6059int posInL11 (const LSet set, const int length,
6060 LObject* p,const kStrategy)
6061{
6062 if (length<0) return 0;
6063
6064 int o = p->GetpFDeg();
6065 int op = set[length].GetpFDeg();
6066 int cmp_int= -currRing->OrdSgn;
6067
6068 if ((op > o)
6069 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
6070 return length+1;
6071 int i;
6072 int an = 0;
6073 int en= length;
6074 loop
6075 {
6076 if (an >= en-1)
6077 {
6078 op = set[an].GetpFDeg();
6079 if ((op > o)
6080 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
6081 return en;
6082 return an;
6083 }
6084 i=(an+en) / 2;
6085 op = set[i].GetpFDeg();
6086 if ((op > o)
6087 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
6088 an=i;
6089 else
6090 en=i;
6091 }
6092}
6093
6094#ifdef HAVE_RINGS
6095/*2
6096* looks up the position of polynomial p in set
6097* set[length] is the smallest element in set with respect
6098* to the ordering-procedure pLmCmp,totaldegree,coefficient
6099* For the same totaldegree, original pairs (from F) will
6100* be put at the end and smalles coefficents
6101*/
6102int posInL11Ring (const LSet set, const int length,
6103 LObject* p,const kStrategy)
6104{
6105 if (length<0) return 0;
6106
6107 int o = p->GetpFDeg();
6108 int op = set[length].GetpFDeg();
6109
6110 if ((op > o)
6111 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6112 return length+1;
6113 int i;
6114 int an = 0;
6115 int en= length;
6116 loop
6117 {
6118 if (an >= en-1)
6119 {
6120 op = set[an].GetpFDeg();
6121 if ((op > o)
6122 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6123 return en;
6124 return an;
6125 }
6126 i=(an+en) / 2;
6127 op = set[i].GetpFDeg();
6128 if ((op > o)
6129 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6130 an=i;
6131 else
6132 en=i;
6133 }
6134}
6135
6136int posInLF5CRing (const LSet set, int start,const int length,
6137 LObject* p,const kStrategy)
6138{
6139 if (length<0) return 0;
6140 if(start == (length +1)) return (length+1);
6141 int o = p->GetpFDeg();
6142 int op = set[length].GetpFDeg();
6143
6144 if ((op > o)
6145 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6146 return length+1;
6147 int i;
6148 int an = start;
6149 int en= length;
6150 loop
6151 {
6152 if (an >= en-1)
6153 {
6154 op = set[an].GetpFDeg();
6155 if ((op > o)
6156 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6157 return en;
6158 return an;
6159 }
6160 i=(an+en) / 2;
6161 op = set[i].GetpFDeg();
6162 if ((op > o)
6163 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6164 an=i;
6165 else
6166 en=i;
6167 }
6168}
6169#endif
6170
6171#ifdef HAVE_RINGS
6172int posInL11Ringls (const LSet set, const int length,
6173 LObject* p,const kStrategy)
6174{
6175 if (length < 0) return 0;
6176 int an,en,i;
6177 an = 0;
6178 en = length+1;
6179 loop
6180 {
6181 if (an >= en-1)
6182 {
6183 if(an == en)
6184 return en;
6185 if (set[an].FDeg > p->FDeg)
6186 return en;
6187 if (set[an].FDeg < p->FDeg)
6188 return an;
6189 if (set[an].FDeg == p->FDeg)
6190 {
6191 number lcset,lcp;
6192 lcset = pGetCoeff(set[an].p);
6193 lcp = pGetCoeff(p->p);
6194 if(!nGreaterZero(lcset))
6195 {
6196 set[an].p=p_Neg(set[an].p,currRing);
6197 if (set[an].t_p!=NULL)
6198 pSetCoeff0(set[an].t_p,pGetCoeff(set[an].p));
6199 lcset=pGetCoeff(set[an].p);
6200 }
6201 if(!nGreaterZero(lcp))
6202 {
6203 p->p=p_Neg(p->p,currRing);
6204 if (p->t_p!=NULL)
6205 pSetCoeff0(p->t_p,pGetCoeff(p->p));
6206 lcp=pGetCoeff(p->p);
6207 }
6208 if(nGreater(lcset, lcp))
6209 {
6210 return en;
6211 }
6212 else
6213 {
6214 return an;
6215 }
6216 }
6217 }
6218 i=(an+en) / 2;
6219 if (set[i].FDeg > p->FDeg)
6220 an=i;
6221 if (set[i].FDeg < p->FDeg)
6222 en=i;
6223 if (set[i].FDeg == p->FDeg)
6224 {
6225 number lcset,lcp;
6226 lcset = pGetCoeff(set[i].p);
6227 lcp = pGetCoeff(p->p);
6228 if(!nGreaterZero(lcset))
6229 {
6230 set[i].p=p_Neg(set[i].p,currRing);
6231 if (set[i].t_p!=NULL)
6232 pSetCoeff0(set[i].t_p,pGetCoeff(set[i].p));
6233 lcset=pGetCoeff(set[i].p);
6234 }
6235 if(!nGreaterZero(lcp))
6236 {
6237 p->p=p_Neg(p->p,currRing);
6238 if (p->t_p!=NULL)
6239 pSetCoeff0(p->t_p,pGetCoeff(p->p));
6240 lcp=pGetCoeff(p->p);
6241 }
6242 if(nGreater(lcset, lcp))
6243 {
6244 an = i;
6245 }
6246 else
6247 {
6248 en = i;
6249 }
6250 }
6251 }
6252}
6253#endif
6254
6255/*2 Position for rings L: Here I am
6256* looks up the position of polynomial p in set
6257* e is the ecart of p
6258* set[length] is the smallest element in set with respect
6259* to the ordering-procedure totaldegree,pComp
6260*/
6261inline int getIndexRng(long coeff)
6262{
6263 if (coeff == 0) return -1;
6264 long tmp = coeff;
6265 int ind = 0;
6266 while (tmp % 2 == 0)
6267 {
6268 tmp = tmp / 2;
6269 ind++;
6270 }
6271 return ind;
6272}
6273
6274int posInLrg0 (const LSet set, const int length,
6275 LObject* p,const kStrategy)
6276/* if (nGreater(pGetCoeff(p), pGetCoeff(set[an]))) return en;
6277 if (pLmCmp(set[i],p) == cmp_int) en = i;
6278 else if (pLmCmp(set[i],p) == -cmp_int) an = i;
6279 else
6280 {
6281 if (nGreater(pGetCoeff(p), pGetCoeff(set[i]))) an = i;
6282 else en = i;
6283 }*/
6284{
6285 if (length < 0) return 0;
6286
6287 int o = p->GetpFDeg();
6288 int op = set[length].GetpFDeg();
6289
6290 if ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))
6291 return length + 1;
6292 int i;
6293 int an = 0;
6294 int en = length;
6295 loop
6296 {
6297 if (an >= en - 1)
6298 {
6299 op = set[an].GetpFDeg();
6300 if ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))
6301 return en;
6302 return an;
6303 }
6304 i = (an+en) / 2;
6305 op = set[i].GetpFDeg();
6306 if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6307 an = i;
6308 else
6309 en = i;
6310 }
6311}
6312
6313/*{
6314 if (length < 0) return 0;
6315
6316 int o = p->GetpFDeg();
6317 int op = set[length].GetpFDeg();
6318
6319 int inde = getIndexRng((unsigned long) pGetCoeff(set[length].p));
6320 int indp = getIndexRng((unsigned long) pGetCoeff(p->p));
6321 int inda;
6322 int indi;
6323
6324 if ((inda > indp) || ((inda == inde) && ((op > o) || ((op == o) && (pLmCmp(set[length].p,p->p) != -currRing->OrdSgn)))))
6325 return length + 1;
6326 int i;
6327 int an = 0;
6328 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6329 int en = length;
6330 loop
6331 {
6332 if (an >= en-1)
6333 {
6334 op = set[an].GetpFDeg();
6335 if ((indp > inda) || ((indp == inda) && ((op > o) || ((op == o) && (pLmCmp(set[an].p,p->p) != -currRing->OrdSgn)))))
6336 return en;
6337 return an;
6338 }
6339 i = (an + en) / 2;
6340 indi = getIndexRng((unsigned long) pGetCoeff(set[i].p));
6341 op = set[i].GetpFDeg();
6342 if ((indi > indp) || ((indi == indp) && ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))))
6343 // if ((op > o) || ((op == o) && (pLmCmp(set[i].p,p->p) != -currRing->OrdSgn)))
6344 {
6345 an = i;
6346 inda = getIndexRng((unsigned long) pGetCoeff(set[an].p));
6347 }
6348 else
6349 en = i;
6350 }
6351} */
6352
6353/*2
6354* looks up the position of polynomial p in set
6355* set[length] is the smallest element in set with respect
6356* to the ordering-procedure totaldegree,pLength0
6357*/
6358int posInL110 (const LSet set, const int length,
6359 LObject* p,const kStrategy)
6360{
6361 if (length<0) return 0;
6362
6363 int o = p->GetpFDeg();
6364 int op = set[length].GetpFDeg();
6365 int cmp_int= -currRing->OrdSgn;
6366
6367 if ((op > o)
6368 || ((op == o) && (set[length].length >p->length))
6369 || ((op == o) && (set[length].length <= p->length)
6370 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6371 return length+1;
6372 int i;
6373 int an = 0;
6374 int en= length;
6375 loop
6376 {
6377 if (an >= en-1)
6378 {
6379 op = set[an].GetpFDeg();
6380 if ((op > o)
6381 || ((op == o) && (set[an].length >p->length))
6382 || ((op == o) && (set[an].length <=p->length)
6383 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6384 return en;
6385 return an;
6386 }
6387 i=(an+en) / 2;
6388 op = set[i].GetpFDeg();
6389 if ((op > o)
6390 || ((op == o) && (set[i].length > p->length))
6391 || ((op == o) && (set[i].length <= p->length)
6392 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6393 an=i;
6394 else
6395 en=i;
6396 }
6397}
6398
6399#ifdef HAVE_RINGS
6400int posInL110Ring (const LSet set, const int length,
6401 LObject* p,const kStrategy)
6402{
6403 if (length<0) return 0;
6404
6405 int o = p->GetpFDeg();
6406 int op = set[length].GetpFDeg();
6407
6408 if ((op > o)
6409 || ((op == o) && (set[length].length >p->length))
6410 || ((op == o) && (set[length].length <= p->length)
6411 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6412 return length+1;
6413 int i;
6414 int an = 0;
6415 int en= length;
6416 loop
6417 {
6418 if (an >= en-1)
6419 {
6420 op = set[an].GetpFDeg();
6421 if ((op > o)
6422 || ((op == o) && (set[an].length >p->length))
6423 || ((op == o) && (set[an].length <=p->length)
6424 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6425 return en;
6426 return an;
6427 }
6428 i=(an+en) / 2;
6429 op = set[i].GetpFDeg();
6430 if ((op > o)
6431 || ((op == o) && (set[i].length > p->length))
6432 || ((op == o) && (set[i].length <= p->length)
6433 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6434 an=i;
6435 else
6436 en=i;
6437 }
6438}
6439#endif
6440
6441/*2
6442* looks up the position of polynomial p in set
6443* e is the ecart of p
6444* set[length] is the smallest element in set with respect
6445* to the ordering-procedure totaldegree
6446*/
6447int posInL13 (const LSet set, const int length,
6448 LObject* p,const kStrategy)
6449{
6450 if (length<0) return 0;
6451
6452 int o = p->GetpFDeg();
6453
6454 if (set[length].GetpFDeg() > o)
6455 return length+1;
6456
6457 int i;
6458 int an = 0;
6459 int en= length;
6460 loop
6461 {
6462 if (an >= en-1)
6463 {
6464 if (set[an].GetpFDeg() >= o)
6465 return en;
6466 return an;
6467 }
6468 i=(an+en) / 2;
6469 if (set[i].GetpFDeg() >= o)
6470 an=i;
6471 else
6472 en=i;
6473 }
6474}
6475
6476/*2
6477* looks up the position of polynomial p in set
6478* e is the ecart of p
6479* set[length] is the smallest element in set with respect
6480* to the ordering-procedure maximaldegree,pComp
6481*/
6482int posInL15 (const LSet set, const int length,
6483 LObject* p,const kStrategy)
6484{
6485 if (length<0) return 0;
6486
6487 int o = p->GetpFDeg() + p->ecart;
6488 int op = set[length].GetpFDeg() + set[length].ecart;
6489 int cmp_int= -currRing->OrdSgn;
6490
6491 if ((op > o)
6492 || ((op == o) && (pLmCmp(set[length].p,p->p) != cmp_int)))
6493 return length+1;
6494 int i;
6495 int an = 0;
6496 int en= length;
6497 loop
6498 {
6499 if (an >= en-1)
6500 {
6501 op = set[an].GetpFDeg() + set[an].ecart;
6502 if ((op > o)
6503 || ((op == o) && (pLmCmp(set[an].p,p->p) != cmp_int)))
6504 return en;
6505 return an;
6506 }
6507 i=(an+en) / 2;
6508 op = set[i].GetpFDeg() + set[i].ecart;
6509 if ((op > o)
6510 || ((op == o) && (pLmCmp(set[i].p,p->p) != cmp_int)))
6511 an=i;
6512 else
6513 en=i;
6514 }
6515}
6516
6517#ifdef HAVE_RINGS
6518int posInL15Ring (const LSet set, const int length,
6519 LObject* p,const kStrategy)
6520{
6521 if (length<0) return 0;
6522
6523 int o = p->GetpFDeg() + p->ecart;
6524 int op = set[length].GetpFDeg() + set[length].ecart;
6525
6526 if ((op > o)
6527 || ((op == o) && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6528 return length+1;
6529 int i;
6530 int an = 0;
6531 int en= length;
6532 loop
6533 {
6534 if (an >= en-1)
6535 {
6536 op = set[an].GetpFDeg() + set[an].ecart;
6537 if ((op > o)
6538 || ((op == o) && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6539 return en;
6540 return an;
6541 }
6542 i=(an+en) / 2;
6543 op = set[i].GetpFDeg() + set[i].ecart;
6544 if ((op > o)
6545 || ((op == o) && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6546 an=i;
6547 else
6548 en=i;
6549 }
6550}
6551#endif
6552
6553/*2
6554* looks up the position of polynomial p in set
6555* e is the ecart of p
6556* set[length] is the smallest element in set with respect
6557* to the ordering-procedure totaldegree
6558*/
6559int posInL17 (const LSet set, const int length,
6560 LObject* p,const kStrategy)
6561{
6562 if (length<0) return 0;
6563
6564 int o = p->GetpFDeg() + p->ecart;
6565 int cmp_int= -currRing->OrdSgn;
6566
6567 if ((set[length].GetpFDeg() + set[length].ecart > o)
6568 || ((set[length].GetpFDeg() + set[length].ecart == o)
6569 && (set[length].ecart > p->ecart))
6570 || ((set[length].GetpFDeg() + set[length].ecart == o)
6571 && (set[length].ecart == p->ecart)
6572 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6573 return length+1;
6574 int i;
6575 int an = 0;
6576 int en= length;
6577 loop
6578 {
6579 if (an >= en-1)
6580 {
6581 if ((set[an].GetpFDeg() + set[an].ecart > o)
6582 || ((set[an].GetpFDeg() + set[an].ecart == o)
6583 && (set[an].ecart > p->ecart))
6584 || ((set[an].GetpFDeg() + set[an].ecart == o)
6585 && (set[an].ecart == p->ecart)
6586 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6587 return en;
6588 return an;
6589 }
6590 i=(an+en) / 2;
6591 if ((set[i].GetpFDeg() + set[i].ecart > o)
6592 || ((set[i].GetpFDeg() + set[i].ecart == o)
6593 && (set[i].ecart > p->ecart))
6594 || ((set[i].GetpFDeg() +set[i].ecart == o)
6595 && (set[i].ecart == p->ecart)
6596 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6597 an=i;
6598 else
6599 en=i;
6600 }
6601}
6602
6603#ifdef HAVE_RINGS
6604int posInL17Ring (const LSet set, const int length,
6605 LObject* p,const kStrategy)
6606{
6607 if (length<0) return 0;
6608
6609 int o = p->GetpFDeg() + p->ecart;
6610
6611 if ((set[length].GetpFDeg() + set[length].ecart > o)
6612 || ((set[length].GetpFDeg() + set[length].ecart == o)
6613 && (set[length].ecart > p->ecart))
6614 || ((set[length].GetpFDeg() + set[length].ecart == o)
6615 && (set[length].ecart == p->ecart)
6616 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6617 return length+1;
6618 int i;
6619 int an = 0;
6620 int en= length;
6621 loop
6622 {
6623 if (an >= en-1)
6624 {
6625 if ((set[an].GetpFDeg() + set[an].ecart > o)
6626 || ((set[an].GetpFDeg() + set[an].ecart == o)
6627 && (set[an].ecart > p->ecart))
6628 || ((set[an].GetpFDeg() + set[an].ecart == o)
6629 && (set[an].ecart == p->ecart)
6630 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6631 return en;
6632 return an;
6633 }
6634 i=(an+en) / 2;
6635 if ((set[i].GetpFDeg() + set[i].ecart > o)
6636 || ((set[i].GetpFDeg() + set[i].ecart == o)
6637 && (set[i].ecart > p->ecart))
6638 || ((set[i].GetpFDeg() +set[i].ecart == o)
6639 && (set[i].ecart == p->ecart)
6640 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6641 an=i;
6642 else
6643 en=i;
6644 }
6645}
6646#endif
6647
6648/*2
6649* looks up the position of polynomial p in set
6650* e is the ecart of p
6651* set[length] is the smallest element in set with respect
6652* to the ordering-procedure pComp
6653*/
6654int posInL17_c (const LSet set, const int length,
6655 LObject* p,const kStrategy)
6656{
6657 if (length<0) return 0;
6658
6659 int cc = (-1+2*currRing->order[0]==ringorder_c);
6660 /* cc==1 for (c,..), cc==-1 for (C,..) */
6661 long c = pGetComp(p->p)*cc;
6662 int o = p->GetpFDeg() + p->ecart;
6663 int cmp_int= -currRing->OrdSgn;
6664
6665 if (pGetComp(set[length].p)*cc > c)
6666 return length+1;
6667 if (pGetComp(set[length].p)*cc == c)
6668 {
6669 if ((set[length].GetpFDeg() + set[length].ecart > o)
6670 || ((set[length].GetpFDeg() + set[length].ecart == o)
6671 && (set[length].ecart > p->ecart))
6672 || ((set[length].GetpFDeg() + set[length].ecart == o)
6673 && (set[length].ecart == p->ecart)
6674 && (pLmCmp(set[length].p,p->p) != cmp_int)))
6675 return length+1;
6676 }
6677 int i;
6678 int an = 0;
6679 int en= length;
6680 loop
6681 {
6682 if (an >= en-1)
6683 {
6684 if (pGetComp(set[an].p)*cc > c)
6685 return en;
6686 if (pGetComp(set[an].p)*cc == c)
6687 {
6688 if ((set[an].GetpFDeg() + set[an].ecart > o)
6689 || ((set[an].GetpFDeg() + set[an].ecart == o)
6690 && (set[an].ecart > p->ecart))
6691 || ((set[an].GetpFDeg() + set[an].ecart == o)
6692 && (set[an].ecart == p->ecart)
6693 && (pLmCmp(set[an].p,p->p) != cmp_int)))
6694 return en;
6695 }
6696 return an;
6697 }
6698 i=(an+en) / 2;
6699 if (pGetComp(set[i].p)*cc > c)
6700 an=i;
6701 else if (pGetComp(set[i].p)*cc == c)
6702 {
6703 if ((set[i].GetpFDeg() + set[i].ecart > o)
6704 || ((set[i].GetpFDeg() + set[i].ecart == o)
6705 && (set[i].ecart > p->ecart))
6706 || ((set[i].GetpFDeg() +set[i].ecart == o)
6707 && (set[i].ecart == p->ecart)
6708 && (pLmCmp(set[i].p,p->p) != cmp_int)))
6709 an=i;
6710 else
6711 en=i;
6712 }
6713 else
6714 en=i;
6715 }
6716}
6717
6718#ifdef HAVE_RINGS
6719int posInL17_cRing (const LSet set, const int length,
6720 LObject* p,const kStrategy)
6721{
6722 if (length<0) return 0;
6723
6724 int cc = (-1+2*currRing->order[0]==ringorder_c);
6725 /* cc==1 for (c,..), cc==-1 for (C,..) */
6726 unsigned long c = pGetComp(p->p)*cc;
6727 int o = p->GetpFDeg() + p->ecart;
6728
6729 if (pGetComp(set[length].p)*cc > c)
6730 return length+1;
6731 if (pGetComp(set[length].p)*cc == c)
6732 {
6733 if ((set[length].GetpFDeg() + set[length].ecart > o)
6734 || ((set[length].GetpFDeg() + set[length].ecart == o)
6735 && (set[length].ecart > p->ecart))
6736 || ((set[length].GetpFDeg() + set[length].ecart == o)
6737 && (set[length].ecart == p->ecart)
6738 && (pLtCmpOrdSgnDiffM(set[length].p,p->p))))
6739 return length+1;
6740 }
6741 int i;
6742 int an = 0;
6743 int en= length;
6744 loop
6745 {
6746 if (an >= en-1)
6747 {
6748 if (pGetComp(set[an].p)*cc > c)
6749 return en;
6750 if (pGetComp(set[an].p)*cc == c)
6751 {
6752 if ((set[an].GetpFDeg() + set[an].ecart > o)
6753 || ((set[an].GetpFDeg() + set[an].ecart == o)
6754 && (set[an].ecart > p->ecart))
6755 || ((set[an].GetpFDeg() + set[an].ecart == o)
6756 && (set[an].ecart == p->ecart)
6757 && (pLtCmpOrdSgnDiffM(set[an].p,p->p))))
6758 return en;
6759 }
6760 return an;
6761 }
6762 i=(an+en) / 2;
6763 if (pGetComp(set[i].p)*cc > c)
6764 an=i;
6765 else if (pGetComp(set[i].p)*cc == c)
6766 {
6767 if ((set[i].GetpFDeg() + set[i].ecart > o)
6768 || ((set[i].GetpFDeg() + set[i].ecart == o)
6769 && (set[i].ecart > p->ecart))
6770 || ((set[i].GetpFDeg() +set[i].ecart == o)
6771 && (set[i].ecart == p->ecart)
6772 && (pLtCmpOrdSgnDiffM(set[i].p,p->p))))
6773 an=i;
6774 else
6775 en=i;
6776 }
6777 else
6778 en=i;
6779 }
6780}
6781#endif
6782
6783/*
6784 * SYZYGY CRITERION for signature-based standard basis algorithms
6785 */
6786BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
6787{
6788//#if 1
6789#ifdef DEBUGF5
6790 PrintS("syzygy criterion checks: ");
6791 pWrite(sig);
6792#endif
6793 for (int k=0; k<strat->syzl; k++)
6794 {
6795 //printf("-%d",k);
6796//#if 1
6797#ifdef DEBUGF5
6798 Print("checking with: %d / %d -- \n",k,strat->syzl);
6799 pWrite(pHead(strat->syz[k]));
6800#endif
6801 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6802 && (!rField_is_Ring(currRing) ||
6803 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6804 {
6805//#if 1
6806#ifdef DEBUGF5
6807 PrintS("DELETE!\n");
6808#endif
6809 strat->nrsyzcrit++;
6810 //printf("- T -\n\n");
6811 return TRUE;
6812 }
6813 }
6814 //printf("- F -\n\n");
6815 return FALSE;
6816}
6817
6818/*
6819 * SYZYGY CRITERION for signature-based standard basis algorithms
6820 */
6821BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
6822{
6823//#if 1
6824 if(sig == NULL)
6825 return FALSE;
6826#ifdef DEBUGF5
6827 PrintS("--- syzygy criterion checks: ");
6828 pWrite(sig);
6829#endif
6830 int comp = __p_GetComp(sig, currRing);
6831 int min, max;
6832 if (comp<=1)
6833 return FALSE;
6834 else
6835 {
6836 min = strat->syzIdx[comp-2];
6837 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-2],comp-2);
6838 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp-1],comp-1);
6839 //printf("SYZIDX %d/%d\n",strat->syzIdx[comp],comp);
6840 if (comp == strat->currIdx)
6841 {
6842 max = strat->syzl;
6843 }
6844 else
6845 {
6846 max = strat->syzIdx[comp-1];
6847 }
6848 for (int k=min; k<max; k++)
6849 {
6850#ifdef F5DEBUG
6851 Print("COMP %d/%d - MIN %d - MAX %d - SYZL %ld\n",comp,strat->currIdx,min,max,strat->syzl);
6852 Print("checking with: %d -- ",k);
6853 pWrite(pHead(strat->syz[k]));
6854#endif
6855 if (p_LmShortDivisibleBy(strat->syz[k], strat->sevSyz[k], sig, not_sevSig, currRing)
6856 && (!rField_is_Ring(currRing) ||
6857 (n_DivBy(pGetCoeff(sig), pGetCoeff(strat->syz[k]),currRing->cf) && pLtCmp(sig,strat->syz[k]) == 1)))
6858 {
6859 strat->nrsyzcrit++;
6860 return TRUE;
6861 }
6862 }
6863 return FALSE;
6864 }
6865}
6866
6867/*
6868 * REWRITTEN CRITERION for signature-based standard basis algorithms
6869 */
6870BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly /*lm*/, kStrategy strat, int start=0)
6871{
6872 //printf("Faugere Rewritten Criterion\n");
6874 return FALSE;
6875//#if 1
6876#ifdef DEBUGF5
6877 PrintS("rewritten criterion checks: ");
6878 pWrite(sig);
6879#endif
6880 for(int k = strat->sl; k>=start; k--)
6881 {
6882//#if 1
6883#ifdef DEBUGF5
6884 PrintS("checking with: ");
6885 pWrite(strat->sig[k]);
6886 pWrite(pHead(strat->S[k]));
6887#endif
6888 if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
6889 {
6890//#if 1
6891#ifdef DEBUGF5
6892 PrintS("DELETE!\n");
6893#endif
6894 strat->nrrewcrit++;
6895 return TRUE;
6896 }
6897 //k--;
6898 }
6899#ifdef DEBUGF5
6900 PrintS("ALL ELEMENTS OF S\n----------------------------------------\n");
6901 for(int kk = 0; kk<strat->sl+1; kk++)
6902 {
6903 pWrite(pHead(strat->S[kk]));
6904 }
6905 PrintS("------------------------------\n");
6906#endif
6907 return FALSE;
6908}
6909
6910/*
6911 * REWRITTEN CRITERION for signature-based standard basis algorithms
6912 ***************************************************************************
6913 * TODO:This should become the version of Arri/Perry resp. Bjarke/Stillman *
6914 ***************************************************************************
6915 */
6916
6917// real implementation of arri's rewritten criterion, only called once in
6918// kstd2.cc, right before starting reduction
6919// IDEA: Arri says that it is enough to consider 1 polynomial for each unique
6920// signature appearing during the computations. Thus we first of all go
6921// through strat->L and delete all other pairs of the same signature,
6922// keeping only the one with least possible leading monomial. After this
6923// we check if we really need to compute this critical pair at all: There
6924// can be elements already in strat->S whose signatures divide the
6925// signature of the critical pair in question and whose multiplied
6926// leading monomials are smaller than the leading monomial of the
6927// critical pair. In this situation we can discard the critical pair
6928// completely.
6929BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
6930{
6932 return FALSE;
6933 poly p1 = pOne();
6934 poly p2 = pOne();
6935 for (int ii=strat->sl; ii>start; ii--)
6936 {
6937 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], strat->P.sig, ~strat->P.sevSig, currRing))
6938 {
6939 p_ExpVectorSum(p1,strat->P.sig,strat->S[ii],currRing);
6940 p_ExpVectorSum(p2,strat->sig[ii],strat->P.p,currRing);
6941 if (!(pLmCmp(p1,p2) == 1))
6942 {
6943 pDelete(&p1);
6944 pDelete(&p2);
6945 return TRUE;
6946 }
6947 }
6948 }
6949 pDelete(&p1);
6950 pDelete(&p2);
6951 return FALSE;
6952}
6953
6954BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
6955{
6956 //Over Rings, there are still some changes to do: considering coeffs
6958 return FALSE;
6959 int found = -1;
6960 for (int i=strat->Bl; i>-1; i--)
6961 {
6962 if (pLmEqual(strat->B[i].sig,sig))
6963 {
6964 found = i;
6965 break;
6966 }
6967 }
6968 if (found != -1)
6969 {
6970 if (pLmCmp(lm,strat->B[found].GetLmCurrRing()) == -1)
6971 {
6972 deleteInL(strat->B,&strat->Bl,found,strat);
6973 }
6974 else
6975 {
6976 return TRUE;
6977 }
6978 }
6979 poly p1 = pOne();
6980 poly p2 = pOne();
6981 for (int ii=strat->sl; ii>-1; ii--)
6982 {
6983 if (p_LmShortDivisibleBy(strat->sig[ii], strat->sevSig[ii], sig, not_sevSig, currRing))
6984 {
6985 p_ExpVectorSum(p1,sig,strat->S[ii],currRing);
6986 p_ExpVectorSum(p2,strat->sig[ii],lm,currRing);
6987 if (!(pLmCmp(p1,p2) == 1))
6988 {
6989 pDelete(&p1);
6990 pDelete(&p2);
6991 return TRUE;
6992 }
6993 }
6994 }
6995 pDelete(&p1);
6996 pDelete(&p2);
6997 return FALSE;
6998}
6999
7000/***************************************************************
7001 *
7002 * Tail reductions
7003 *
7004 ***************************************************************/
7005TObject* kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject* L, TObject *T, long ecart)
7006{
7007 int j = 0;
7008 const unsigned long not_sev = ~L->sev;
7009 const unsigned long* sev = strat->sevS;
7010 poly p;
7011 ring r;
7012 L->GetLm(p, r);
7013
7014 assume(~not_sev == p_GetShortExpVector(p, r));
7015
7016 if (r == currRing)
7017 {
7018 if(!rField_is_Ring(r))
7019 {
7020 loop
7021 {
7022 if (j > end_pos) return NULL;
7023 #if defined(PDEBUG) || defined(PDIV_DEBUG)
7024 if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7025 (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7026 {
7027 break;
7028 }
7029 #else
7030 if (!(sev[j] & not_sev) &&
7031 (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7032 p_LmDivisibleBy(strat->S[j], p, r))
7033 {
7034 break;
7035 }
7036 #endif
7037 j++;
7038 }
7039 }
7040 #ifdef HAVE_RINGS
7041 else
7042 {
7043 loop
7044 {
7045 if (j > end_pos) return NULL;
7046 #if defined(PDEBUG) || defined(PDIV_DEBUG)
7047 if (strat->S[j]!= NULL && p_LmShortDivisibleBy(strat->S[j], sev[j], p, not_sev, r) &&
7048 (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7049 {
7050 break;
7051 }
7052 #else
7053 if (!(sev[j] & not_sev) &&
7054 (ecart== LONG_MAX || ecart>= strat->ecartS[j]) &&
7055 p_LmDivisibleBy(strat->S[j], p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), r->cf))
7056 {
7057 break;
7058 }
7059 #endif
7060 j++;
7061 }
7062 }
7063 #endif
7064 // if called from NF, T objects do not exist:
7065 if (strat->tl < 0 || strat->S_2_R[j] == -1)
7066 {
7067 T->Set(strat->S[j], r, strat->tailRing);
7068 assume(T->GetpLength()==pLength(T->p != __null ? T->p : T->t_p));
7069 return T;
7070 }
7071 else
7072 {
7073///// assume (j >= 0 && j <= strat->tl && strat->S_2_T(j) != NULL
7074///// && strat->S_2_T(j)->p == strat->S[j]); // wrong?
7075// assume (j >= 0 && j <= strat->sl && strat->S_2_T(j) != NULL && strat->S_2_T(j)->p == strat->S[j]);
7076 return strat->S_2_T(j);
7077 }
7078 }
7079 else
7080 {
7081 TObject* t;
7082 if(!rField_is_Ring(r))
7083 {
7084 loop
7085 {
7086 if (j > end_pos) return NULL;
7087 assume(strat->S_2_R[j] != -1);
7088 #if defined(PDEBUG) || defined(PDIV_DEBUG)
7089 t = strat->S_2_T(j);
7090 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7091 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7092 (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7093 {
7094 t->pLength=pLength(t->t_p);
7095 return t;
7096 }
7097 #else
7098 if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7099 {
7100 t = strat->S_2_T(j);
7101 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7102 if (p_LmDivisibleBy(t->t_p, p, r))
7103 {
7104 t->pLength=pLength(t->t_p);
7105 return t;
7106 }
7107 }
7108 #endif
7109 j++;
7110 }
7111 }
7112 #ifdef HAVE_RINGS
7113 else
7114 {
7115 loop
7116 {
7117 if (j > end_pos) return NULL;
7118 assume(strat->S_2_R[j] != -1);
7119 #if defined(PDEBUG) || defined(PDIV_DEBUG)
7120 t = strat->S_2_T(j);
7121 assume(t != NULL && t->t_p != NULL && t->tailRing == r);
7122 if (p_LmShortDivisibleBy(t->t_p, sev[j], p, not_sev, r) &&
7123 (ecart== LONG_MAX || ecart>= strat->ecartS[j]) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7124 {
7125 t->pLength=pLength(t->t_p);
7126 return t;
7127 }
7128 #else
7129 if (! (sev[j] & not_sev) && (ecart== LONG_MAX || ecart>= strat->ecartS[j]))
7130 {
7131 t = strat->S_2_T(j);
7132 assume(t != NULL && t->t_p != NULL && t->tailRing == r && t->p == strat->S[j]);
7133 if (p_LmDivisibleBy(t->t_p, p, r) && n_DivBy(pGetCoeff(p), pGetCoeff(t->t_p), r->cf))
7134 {
7135 t->pLength=pLength(t->t_p);
7136 return t;
7137 }
7138 }
7139 #endif
7140 j++;
7141 }
7142 }
7143 #endif
7144 }
7145}
7146
7147poly redtail (LObject* L, int end_pos, kStrategy strat)
7148{
7149 poly h, hn;
7150 strat->redTailChange=FALSE;
7151
7152 L->GetP();
7153 poly p = L->p;
7154 if (strat->noTailReduction || pNext(p) == NULL)
7155 return p;
7156
7157 LObject Ln(strat->tailRing);
7158 TObject* With;
7159 // placeholder in case strat->tl < 0
7160 TObject With_s(strat->tailRing);
7161 h = p;
7162 hn = pNext(h);
7163 long op = strat->tailRing->pFDeg(hn, strat->tailRing);
7164 long e;
7165 int l;
7166 BOOLEAN save_HE=strat->kAllAxis;
7167 strat->kAllAxis |=
7168 ((Kstd1_deg>0) && (op<=Kstd1_deg)) || TEST_OPT_INFREDTAIL;
7169
7170 while(hn != NULL)
7171 {
7172 op = strat->tailRing->pFDeg(hn, strat->tailRing);
7173 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7174 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7175 loop
7176 {
7177 Ln.Set(hn, strat->tailRing);
7178 Ln.sev = p_GetShortExpVector(hn, strat->tailRing);
7179 if (strat->kAllAxis)
7180 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7181 else
7182 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s, e);
7183 if (With == NULL) break;
7184 With->length=0;
7185 With->pLength=0;
7186 strat->redTailChange=TRUE;
7187 if (ksReducePolyTail(L, With, h, strat->kNoetherTail()))
7188 {
7189 // reducing the tail would violate the exp bound
7190 if (kStratChangeTailRing(strat, L))
7191 {
7192 strat->kAllAxis = save_HE;
7193 return redtail(L, end_pos, strat);
7194 }
7195 else
7196 return NULL;
7197 }
7198 hn = pNext(h);
7199 if (hn == NULL) goto all_done;
7200 op = strat->tailRing->pFDeg(hn, strat->tailRing);
7201 if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done;
7202 e = strat->tailRing->pLDeg(hn, &l, strat->tailRing) - op;
7203 }
7204 h = hn;
7205 hn = pNext(h);
7206 }
7207
7208 all_done:
7209 if (strat->redTailChange)
7210 {
7211 L->pLength = 0;
7212 }
7213 strat->kAllAxis = save_HE;
7214 return p;
7215}
7216
7217poly redtail (poly p, int end_pos, kStrategy strat)
7218{
7219 LObject L(p, currRing);
7220 return redtail(&L, end_pos, strat);
7221}
7222
7223poly redtailBba (LObject* L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
7224{
7225 strat->redTailChange=FALSE;
7226 if (strat->noTailReduction) return L->GetLmCurrRing();
7227 poly h, p;
7228 p = h = L->GetLmTailRing();
7229 if ((h==NULL) || (pNext(h)==NULL))
7230 return L->GetLmCurrRing();
7231
7232 TObject* With;
7233 // placeholder in case strat->tl < 0
7234 TObject With_s(strat->tailRing);
7235
7236 LObject Ln(pNext(h), strat->tailRing);
7237 Ln.GetpLength();
7238
7239 pNext(h) = NULL;
7240 if (L->p != NULL)
7241 {
7242 pNext(L->p) = NULL;
7243 if (L->t_p != NULL) pNext(L->t_p) = NULL;
7244 }
7245 L->pLength = 1;
7246
7247 Ln.PrepareRed(strat->use_buckets);
7248
7249 int cnt=REDTAIL_CANONICALIZE;
7250 while(!Ln.IsNull())
7251 {
7252 loop
7253 {
7254 if (TEST_OPT_IDLIFT)
7255 {
7256 if (Ln.p!=NULL)
7257 {
7258 if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7259 }
7260 else
7261 {
7262 if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7263 }
7264 }
7265 Ln.SetShortExpVector();
7266 if (withT)
7267 {
7268 int j;
7269 j = kFindDivisibleByInT(strat, &Ln);
7270 if (j < 0) break;
7271 With = &(strat->T[j]);
7272 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7273 }
7274 else
7275 {
7276 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7277 if (With == NULL) break;
7278 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7279 }
7280 cnt--;
7281 if (cnt==0)
7282 {
7284 /*poly tmp=*/Ln.CanonicalizeP();
7285 if (normalize)
7286 {
7287 Ln.Normalize();
7288 //pNormalize(tmp);
7289 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7290 }
7291 }
7292 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7293 {
7294 With->pNorm();
7295 }
7296 strat->redTailChange=TRUE;
7297 if (ksReducePolyTail(L, With, &Ln))
7298 {
7299 // reducing the tail would violate the exp bound
7300 // set a flag and hope for a retry (in bba)
7302 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7303 do
7304 {
7305 pNext(h) = Ln.LmExtractAndIter();
7306 pIter(h);
7307 L->pLength++;
7308 } while (!Ln.IsNull());
7309 goto all_done;
7310 }
7311 if (Ln.IsNull()) goto all_done;
7312 if (! withT) With_s.Init(currRing);
7313 }
7314 pNext(h) = Ln.LmExtractAndIter();
7315 pIter(h);
7316 pNormalize(h);
7317 L->pLength++;
7318 }
7319
7320 all_done:
7321 Ln.Delete();
7322 if (L->p != NULL) pNext(L->p) = pNext(p);
7323
7324 if (strat->redTailChange)
7325 {
7326 L->length = 0;
7327 L->pLength = 0;
7328 }
7329
7330 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7331 //L->Normalize(); // HANNES: should have a test
7332 kTest_L(L,strat);
7333 return L->GetLmCurrRing();
7334}
7335
7336poly redtailBbaBound (LObject* L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
7337{
7338 strat->redTailChange=FALSE;
7339 if (strat->noTailReduction) return L->GetLmCurrRing();
7340 poly h, p;
7341 p = h = L->GetLmTailRing();
7342 if ((h==NULL) || (pNext(h)==NULL))
7343 return L->GetLmCurrRing();
7344
7345 TObject* With;
7346 // placeholder in case strat->tl < 0
7347 TObject With_s(strat->tailRing);
7348
7349 LObject Ln(pNext(h), strat->tailRing);
7350 Ln.pLength = L->GetpLength() - 1;
7351
7352 pNext(h) = NULL;
7353 if (L->p != NULL) pNext(L->p) = NULL;
7354 L->pLength = 1;
7355
7356 Ln.PrepareRed(strat->use_buckets);
7357
7358 int cnt=REDTAIL_CANONICALIZE;
7359 while(!Ln.IsNull())
7360 {
7361 loop
7362 {
7363 if (TEST_OPT_IDLIFT)
7364 {
7365 if (Ln.p!=NULL)
7366 {
7367 if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7368 }
7369 else
7370 {
7371 if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7372 }
7373 }
7374 Ln.SetShortExpVector();
7375 if (withT)
7376 {
7377 int j;
7378 j = kFindDivisibleByInT(strat, &Ln);
7379 if (j < 0) break;
7380 With = &(strat->T[j]);
7381 }
7382 else
7383 {
7384 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7385 if (With == NULL) break;
7386 }
7387 cnt--;
7388 if (cnt==0)
7389 {
7391 /*poly tmp=*/Ln.CanonicalizeP();
7392 if (normalize)
7393 {
7394 Ln.Normalize();
7395 //pNormalize(tmp);
7396 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
7397 }
7398 }
7399 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
7400 {
7401 With->pNorm();
7402 }
7403 strat->redTailChange=TRUE;
7404 if (ksReducePolyTail(L, With, &Ln))
7405 {
7406 // reducing the tail would violate the exp bound
7407 // set a flag and hope for a retry (in bba)
7409 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7410 do
7411 {
7412 pNext(h) = Ln.LmExtractAndIter();
7413 pIter(h);
7414 L->pLength++;
7415 } while (!Ln.IsNull());
7416 goto all_done;
7417 }
7418 if(!Ln.IsNull())
7419 {
7420 Ln.GetP();
7421 Ln.p = pJet(Ln.p,bound);
7422 }
7423 if (Ln.IsNull())
7424 {
7425 goto all_done;
7426 }
7427 if (! withT) With_s.Init(currRing);
7428 }
7429 pNext(h) = Ln.LmExtractAndIter();
7430 pIter(h);
7431 pNormalize(h);
7432 L->pLength++;
7433 }
7434
7435 all_done:
7436 Ln.Delete();
7437 if (L->p != NULL) pNext(L->p) = pNext(p);
7438
7439 if (strat->redTailChange)
7440 {
7441 L->length = 0;
7442 L->pLength = 0;
7443 }
7444
7445 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7446 //L->Normalize(); // HANNES: should have a test
7447 kTest_L(L,strat);
7448 return L->GetLmCurrRing();
7449}
7450
7451#ifdef HAVE_RINGS
7452void redtailBbaAlsoLC_Z (LObject* L, int end_pos, kStrategy strat )
7453// normalize=FALSE, withT=FALSE, coeff=Z
7454{
7455 strat->redTailChange=FALSE;
7456
7457 poly h, p;
7458 p = h = L->GetLmTailRing();
7459 if ((h==NULL) || (pNext(h)==NULL))
7460 return;
7461
7462 TObject* With;
7463 LObject Ln(pNext(h), strat->tailRing);
7464 Ln.GetpLength();
7465
7466 pNext(h) = NULL;
7467 if (L->p != NULL)
7468 {
7469 pNext(L->p) = NULL;
7470 if (L->t_p != NULL) pNext(L->t_p) = NULL;
7471 }
7472 L->pLength = 1;
7473
7474 Ln.PrepareRed(strat->use_buckets);
7475
7476 int cnt=REDTAIL_CANONICALIZE;
7477
7478 while(!Ln.IsNull())
7479 {
7480 loop
7481 {
7482 if (TEST_OPT_IDLIFT)
7483 {
7484 if (Ln.p!=NULL)
7485 {
7486 if (__p_GetComp(Ln.p,currRing)> strat->syzComp) break;
7487 }
7488 else
7489 {
7490 if (__p_GetComp(Ln.t_p,strat->tailRing)> strat->syzComp) break;
7491 }
7492 }
7493 Ln.SetShortExpVector();
7494 int j;
7495 j = kFindDivisibleByInT(strat, &Ln);
7496 if (j < 0)
7497 {
7498 j = kFindDivisibleByInT_Z(strat, &Ln);
7499 if (j < 0)
7500 {
7501 break;
7502 }
7503 else
7504 {
7505 /* reduction not cancelling a tail term, but reducing its coefficient */
7506 With = &(strat->T[j]);
7507 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7508 cnt--;
7509 if (cnt==0)
7510 {
7512 /*poly tmp=*/Ln.CanonicalizeP();
7513 }
7514 strat->redTailChange=TRUE;
7515 /* reduction cancelling a tail term */
7516 if (ksReducePolyTailLC_Z(L, With, &Ln))
7517 {
7518 // reducing the tail would violate the exp bound
7519 // set a flag and hope for a retry (in bba)
7521 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7522 do
7523 {
7524 pNext(h) = Ln.LmExtractAndIter();
7525 pIter(h);
7526 L->pLength++;
7527 } while (!Ln.IsNull());
7528 goto all_done;
7529 }
7530 /* we have to break since we did not cancel the term, but only decreased
7531 * its coefficient. */
7532 break;
7533 }
7534 } else {
7535 With = &(strat->T[j]);
7536 assume(With->GetpLength()==pLength(With->p != __null ? With->p : With->t_p));
7537 cnt--;
7538 if (cnt==0)
7539 {
7541 /*poly tmp=*/Ln.CanonicalizeP();
7542 }
7543 strat->redTailChange=TRUE;
7544 /* reduction cancelling a tail term */
7545 if (ksReducePolyTail_Z(L, With, &Ln))
7546 {
7547 // reducing the tail would violate the exp bound
7548 // set a flag and hope for a retry (in bba)
7550 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7551 do
7552 {
7553 pNext(h) = Ln.LmExtractAndIter();
7554 pIter(h);
7555 L->pLength++;
7556 } while (!Ln.IsNull());
7557 goto all_done;
7558 }
7559 }
7560 if (Ln.IsNull()) goto all_done;
7561 }
7562 pNext(h) = Ln.LmExtractAndIter();
7563 pIter(h);
7564 L->pLength++;
7565 }
7566
7567 all_done:
7568 Ln.Delete();
7569 if (L->p != NULL) pNext(L->p) = pNext(p);
7570
7571 if (strat->redTailChange)
7572 {
7573 L->length = 0;
7574 L->pLength = 0;
7575 }
7576
7577 kTest_L(L, strat);
7578 return;
7579}
7580
7581poly redtailBba_Z (LObject* L, int end_pos, kStrategy strat )
7582// normalize=FALSE, withT=FALSE, coeff=Z
7583{
7584 strat->redTailChange=FALSE;
7585 if (strat->noTailReduction) return L->GetLmCurrRing();
7586 poly h, p;
7587 p = h = L->GetLmTailRing();
7588 if ((h==NULL) || (pNext(h)==NULL))
7589 return L->GetLmCurrRing();
7590
7591 TObject* With;
7592 // placeholder in case strat->tl < 0
7593 TObject With_s(strat->tailRing);
7594
7595 LObject Ln(pNext(h), strat->tailRing);
7596 Ln.pLength = L->GetpLength() - 1;
7597
7598 pNext(h) = NULL;
7599 if (L->p != NULL) pNext(L->p) = NULL;
7600 L->pLength = 1;
7601
7602 Ln.PrepareRed(strat->use_buckets);
7603
7604 int cnt=REDTAIL_CANONICALIZE;
7605 while(!Ln.IsNull())
7606 {
7607 loop
7608 {
7609 Ln.SetShortExpVector();
7610 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7611 if (With == NULL) break;
7612 cnt--;
7613 if (cnt==0)
7614 {
7616 /*poly tmp=*/Ln.CanonicalizeP();
7617 }
7618 // we are in Z, do not call pNorm
7619 strat->redTailChange=TRUE;
7620 // test divisibility of coefs:
7621 poly p_Ln=Ln.GetLmCurrRing();
7622 poly p_With=With->GetLmCurrRing();
7623 number z=n_IntMod(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf);
7624 if (!nIsZero(z))
7625 {
7626 // subtract z*Ln, add z.Ln to L
7627 poly m=pHead(p_Ln);
7628 pSetCoeff(m,z);
7629 poly mm=pHead(m);
7630 pNext(h) = m;
7631 pIter(h);
7632 L->pLength++;
7633 mm=pNeg(mm);
7634 if (Ln.bucket!=NULL)
7635 {
7636 int dummy=1;
7637 kBucket_Add_q(Ln.bucket,mm,&dummy);
7638 }
7639 else
7640 {
7641 if ((Ln.t_p!=NULL)&&(Ln.p==NULL))
7642 Ln.GetP();
7643 if (Ln.p!=NULL)
7644 {
7645 Ln.p=pAdd(Ln.p,mm);
7646 if (Ln.t_p!=NULL)
7647 {
7648 pNext(Ln.t_p)=NULL;
7649 p_LmDelete(Ln.t_p,strat->tailRing);
7650 }
7651 }
7652 }
7653 }
7654 else
7655 nDelete(&z);
7656
7657 if (ksReducePolyTail_Z(L, With, &Ln))
7658 {
7659 // reducing the tail would violate the exp bound
7660 // set a flag and hope for a retry (in bba)
7662 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7663 do
7664 {
7665 pNext(h) = Ln.LmExtractAndIter();
7666 pIter(h);
7667 L->pLength++;
7668 } while (!Ln.IsNull());
7669 goto all_done;
7670 }
7671 if (Ln.IsNull()) goto all_done;
7672 With_s.Init(currRing);
7673 }
7674 pNext(h) = Ln.LmExtractAndIter();
7675 pIter(h);
7676 pNormalize(h);
7677 L->pLength++;
7678 }
7679
7680 all_done:
7681 Ln.Delete();
7682 if (L->p != NULL) pNext(L->p) = pNext(p);
7683
7684 if (strat->redTailChange)
7685 {
7686 L->length = 0;
7687 }
7688
7689 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7690 //L->Normalize(); // HANNES: should have a test
7691 kTest_L(L,strat);
7692 return L->GetLmCurrRing();
7693}
7694
7695poly redtailBba_Ring (LObject* L, int end_pos, kStrategy strat )
7696// normalize=FALSE, withT=FALSE, coeff=Z
7697{
7698 strat->redTailChange=FALSE;
7699 if (strat->noTailReduction) return L->GetLmCurrRing();
7700 poly h, p;
7701 p = h = L->GetLmTailRing();
7702 if ((h==NULL) || (pNext(h)==NULL))
7703 return L->GetLmCurrRing();
7704
7705 TObject* With;
7706 // placeholder in case strat->tl < 0
7707 TObject With_s(strat->tailRing);
7708
7709 LObject Ln(pNext(h), strat->tailRing);
7710 Ln.pLength = L->GetpLength() - 1;
7711
7712 pNext(h) = NULL;
7713 if (L->p != NULL) pNext(L->p) = NULL;
7714 L->pLength = 1;
7715
7716 Ln.PrepareRed(strat->use_buckets);
7717
7718 int cnt=REDTAIL_CANONICALIZE;
7719 while(!Ln.IsNull())
7720 {
7721 loop
7722 {
7723 Ln.SetShortExpVector();
7724 With_s.Init(currRing);
7725 With = kFindDivisibleByInS_T(strat, end_pos, &Ln, &With_s);
7726 if (With == NULL) break;
7727 cnt--;
7728 if (cnt==0)
7729 {
7731 /*poly tmp=*/Ln.CanonicalizeP();
7732 }
7733 // we are in a ring, do not call pNorm
7734 // test divisibility of coefs:
7735 poly p_Ln=Ln.GetLmCurrRing();
7736 poly p_With=With->GetLmCurrRing();
7737 if (n_DivBy(pGetCoeff(p_Ln),pGetCoeff(p_With), currRing->cf))
7738 {
7739 strat->redTailChange=TRUE;
7740
7741 if (ksReducePolyTail_Z(L, With, &Ln))
7742 {
7743 // reducing the tail would violate the exp bound
7744 // set a flag and hope for a retry (in bba)
7746 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
7747 do
7748 {
7749 pNext(h) = Ln.LmExtractAndIter();
7750 pIter(h);
7751 L->pLength++;
7752 } while (!Ln.IsNull());
7753 goto all_done;
7754 }
7755 }
7756 else break; /*proceed to next monomial*/
7757 if (Ln.IsNull()) goto all_done;
7758 }
7759 pNext(h) = Ln.LmExtractAndIter();
7760 pIter(h);
7761 pNormalize(h);
7762 L->pLength++;
7763 }
7764
7765 all_done:
7766 Ln.Delete();
7767 if (L->p != NULL) pNext(L->p) = pNext(p);
7768
7769 if (strat->redTailChange)
7770 {
7771 L->length = 0;
7772 }
7773
7774 //if (TEST_OPT_PROT) { PrintS("N"); mflush(); }
7775 //L->Normalize(); // HANNES: should have a test
7776 kTest_L(L,strat);
7777 return L->GetLmCurrRing();
7778}
7779#endif
7780
7781/*2
7782*checks the change degree and write progress report
7783*/
7784void message (int i,int* reduc,int* olddeg,kStrategy strat, int red_result)
7785{
7786 if (i != *olddeg)
7787 {
7788 Print("%d",i);
7789 *olddeg = i;
7790 }
7791 if (TEST_OPT_OLDSTD)
7792 {
7793 if (strat->Ll != *reduc)
7794 {
7795 if (strat->Ll != *reduc-1)
7796 Print("(%d)",strat->Ll+1);
7797 else
7798 PrintS("-");
7799 *reduc = strat->Ll;
7800 }
7801 else
7802 PrintS(".");
7803 mflush();
7804 }
7805 else
7806 {
7807 if (red_result == 0)
7808 PrintS("-");
7809 else if (red_result < 0)
7810 PrintS(".");
7811 if ((red_result > 0) || ((strat->Ll % 100)==99))
7812 {
7813 if (strat->Ll != *reduc && strat->Ll > 0)
7814 {
7815 Print("(%d)",strat->Ll+1);
7816 *reduc = strat->Ll;
7817 }
7818 }
7819 }
7820}
7821
7822/*2
7823*statistics
7824*/
7825void messageStat (int hilbcount,kStrategy strat)
7826{
7827 //PrintS("\nUsage/Allocation of temporary storage:\n");
7828 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7829 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7830 Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7831 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7832 #ifdef HAVE_SHIFTBBA
7833 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7834 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7835 #endif
7836}
7837
7838void messageStatSBA (int hilbcount,kStrategy strat)
7839{
7840 //PrintS("\nUsage/Allocation of temporary storage:\n");
7841 //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl));
7842 //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax);
7843 Print("syz criterion:%d rew criterion:%d\n",strat->nrsyzcrit,strat->nrrewcrit);
7844 //Print("product criterion:%d chain criterion:%d\n",strat->cp,strat->c3);
7845 if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount);
7846 #ifdef HAVE_SHIFTBBA
7847 /* in usual case strat->cv is 0, it gets changed only in shift routines */
7848 if (strat->cv!=0) Print("shift V criterion:%d\n",strat->cv);
7849 #endif
7850}
7851
7852#ifdef KDEBUG
7853/*2
7854*debugging output: all internal sets, if changed
7855*for testing purpuse only/has to be changed for later use
7856*/
7858{
7859 int i;
7860 if (strat->news)
7861 {
7862 PrintS("set S");
7863 for (i=0; i<=strat->sl; i++)
7864 {
7865 Print("\n %d:",i);
7866 p_wrp(strat->S[i], currRing, strat->tailRing);
7867 if (strat->fromQ!=NULL && strat->fromQ[i])
7868 Print(" (from Q)");
7869 }
7870 strat->news = FALSE;
7871 }
7872 if (strat->newt)
7873 {
7874 PrintS("\nset T");
7875 for (i=0; i<=strat->tl; i++)
7876 {
7877 Print("\n %d:",i);
7878 strat->T[i].wrp();
7879 if (strat->T[i].length==0) strat->T[i].length=pLength(strat->T[i].p);
7880 Print(" o:%ld e:%d l:%d",
7881 strat->T[i].pFDeg(),strat->T[i].ecart,strat->T[i].length);
7882 }
7883 strat->newt = FALSE;
7884 }
7885 PrintS("\nset L");
7886 for (i=strat->Ll; i>=0; i--)
7887 {
7888 Print("\n%d:",i);
7889 p_wrp(strat->L[i].p1, currRing, strat->tailRing);
7890 PrintS(" ");
7891 p_wrp(strat->L[i].p2, currRing, strat->tailRing);
7892 PrintS(" lcm: ");p_wrp(strat->L[i].lcm, currRing);
7893 PrintS("\n p : ");
7894 strat->L[i].wrp();
7895 Print(" o:%ld e:%d l:%d",
7896 strat->L[i].pFDeg(),strat->L[i].ecart,strat->L[i].length);
7897 }
7898 PrintLn();
7899}
7900
7901#endif
7902
7903
7904/*2
7905*construct the set s from F
7906*/
7907void initS (ideal F, ideal Q, kStrategy strat)
7908{
7909 int i,pos;
7910
7912 else i=((IDELEMS(F)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
7913 strat->ecartS=initec(i);
7914 strat->sevS=initsevS(i);
7915 strat->S_2_R=initS_2_R(i);
7916 strat->fromQ=NULL;
7917 strat->Shdl=idInit(i,F->rank);
7918 strat->S=strat->Shdl->m;
7919 /*- put polys into S -*/
7920 if (Q!=NULL)
7921 {
7922 strat->fromQ=initec(i);
7923 memset(strat->fromQ,0,i*sizeof(int));
7924 for (i=0; i<IDELEMS(Q); i++)
7925 {
7926 if (Q->m[i]!=NULL)
7927 {
7928 LObject h;
7929 h.p = pCopy(Q->m[i]);
7931 {
7932 h.pCleardenom(); // also does remove Content
7933 }
7934 else
7935 {
7936 h.pNorm();
7937 }
7939 {
7940 deleteHC(&h, strat);
7941 }
7942 if (h.p!=NULL)
7943 {
7944 strat->initEcart(&h);
7945 if (strat->sl==-1)
7946 pos =0;
7947 else
7948 {
7949 pos = posInS(strat,strat->sl,h.p,h.ecart);
7950 }
7951 h.sev = pGetShortExpVector(h.p);
7952 strat->enterS(h,pos,strat,-1);
7953 strat->fromQ[pos]=1;
7954 }
7955 }
7956 }
7957 }
7958 for (i=0; i<IDELEMS(F); i++)
7959 {
7960 if (F->m[i]!=NULL)
7961 {
7962 LObject h;
7963 h.p = pCopy(F->m[i]);
7965 {
7966 cancelunit(&h); /*- tries to cancel a unit -*/
7967 deleteHC(&h, strat);
7968 }
7969 if (h.p!=NULL)
7970 // do not rely on the input being a SB!
7971 {
7973 {
7974 h.pCleardenom(); // also does remove Content
7975 }
7976 else
7977 {
7978 h.pNorm();
7979 }
7980 strat->initEcart(&h);
7981 if (strat->sl==-1)
7982 pos =0;
7983 else
7984 pos = posInS(strat,strat->sl,h.p,h.ecart);
7985 h.sev = pGetShortExpVector(h.p);
7986 strat->enterS(h,pos,strat,-1);
7987 }
7988 }
7989 }
7990 /*- test, if a unit is in F -*/
7991 if ((strat->sl>=0)
7992#ifdef HAVE_RINGS
7993 && n_IsUnit(pGetCoeff(strat->S[0]),currRing->cf)
7994#endif
7995 && pIsConstant(strat->S[0]))
7996 {
7997 while (strat->sl>0) deleteInS(strat->sl,strat);
7998 }
7999}
8000
8001void initSL (ideal F, ideal Q,kStrategy strat)
8002{
8003 int i,pos;
8004
8006 else i=setmaxT;
8007 strat->ecartS=initec(i);
8008 strat->sevS=initsevS(i);
8009 strat->S_2_R=initS_2_R(i);
8010 strat->fromQ=NULL;
8011 strat->Shdl=idInit(i,F->rank);
8012 strat->S=strat->Shdl->m;
8013 /*- put polys into S -*/
8014 if (Q!=NULL)
8015 {
8016 strat->fromQ=initec(i);
8017 memset(strat->fromQ,0,i*sizeof(int));
8018 for (i=0; i<IDELEMS(Q); i++)
8019 {
8020 if (Q->m[i]!=NULL)
8021 {
8022 LObject h;
8023 h.p = pCopy(Q->m[i]);
8025 {
8026 deleteHC(&h,strat);
8027 }
8029 {
8030 h.pCleardenom(); // also does remove Content
8031 }
8032 else
8033 {
8034 h.pNorm();
8035 }
8036 if (h.p!=NULL)
8037 {
8038 strat->initEcart(&h);
8039 if (strat->sl==-1)
8040 pos =0;
8041 else
8042 {
8043 pos = posInS(strat,strat->sl,h.p,h.ecart);
8044 }
8045 h.sev = pGetShortExpVector(h.p);
8046 strat->enterS(h,pos,strat,-1);
8047 strat->fromQ[pos]=1;
8048 }
8049 }
8050 }
8051 }
8052 for (i=0; i<IDELEMS(F); i++)
8053 {
8054 if (F->m[i]!=NULL)
8055 {
8056 LObject h;
8057 h.p = pCopy(F->m[i]);
8058 if (h.p!=NULL)
8059 {
8061 {
8062 cancelunit(&h); /*- tries to cancel a unit -*/
8063 deleteHC(&h, strat);
8064 }
8065 if (h.p!=NULL)
8066 {
8068 {
8069 h.pCleardenom(); // also does remove Content
8070 }
8071 else
8072 {
8073 h.pNorm();
8074 }
8075 strat->initEcart(&h);
8076 if (strat->Ll==-1)
8077 pos =0;
8078 else
8079 pos = strat->posInL(strat->L,strat->Ll,&h,strat);
8080 h.sev = pGetShortExpVector(h.p);
8081 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8082 }
8083 }
8084 }
8085 }
8086 /*- test, if a unit is in F -*/
8087
8088 if ((strat->Ll>=0)
8089#ifdef HAVE_RINGS
8090 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8091#endif
8092 && pIsConstant(strat->L[strat->Ll].p))
8093 {
8094 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8095 }
8096}
8097
8098void initSLSba (ideal F, ideal Q,kStrategy strat)
8099{
8100 int i,pos;
8102 else i=setmaxT;
8103 strat->ecartS = initec(i);
8104 strat->sevS = initsevS(i);
8105 strat->sevSig = initsevS(i);
8106 strat->S_2_R = initS_2_R(i);
8107 strat->fromQ = NULL;
8108 strat->Shdl = idInit(i,F->rank);
8109 strat->S = strat->Shdl->m;
8110 strat->sig = (poly *)omAlloc0(i*sizeof(poly));
8111 if (strat->sbaOrder != 1)
8112 {
8113 strat->syz = (poly *)omAlloc0(i*sizeof(poly));
8114 strat->sevSyz = initsevS(i);
8115 strat->syzmax = i;
8116 strat->syzl = 0;
8117 }
8118 /*- put polys into S -*/
8119 if (Q!=NULL)
8120 {
8121 strat->fromQ=initec(i);
8122 memset(strat->fromQ,0,i*sizeof(int));
8123 for (i=0; i<IDELEMS(Q); i++)
8124 {
8125 if (Q->m[i]!=NULL)
8126 {
8127 LObject h;
8128 h.p = pCopy(Q->m[i]);
8130 {
8131 deleteHC(&h,strat);
8132 }
8134 {
8135 h.pCleardenom(); // also does remove Content
8136 }
8137 else
8138 {
8139 h.pNorm();
8140 }
8141 if (h.p!=NULL)
8142 {
8143 strat->initEcart(&h);
8144 if (strat->sl==-1)
8145 pos =0;
8146 else
8147 {
8148 pos = posInS(strat,strat->sl,h.p,h.ecart);
8149 }
8150 h.sev = pGetShortExpVector(h.p);
8151 strat->enterS(h,pos,strat,-1);
8152 strat->fromQ[pos]=1;
8153 }
8154 }
8155 }
8156 }
8157 for (i=0; i<IDELEMS(F); i++)
8158 {
8159 if (F->m[i]!=NULL)
8160 {
8161 LObject h;
8162 h.p = pCopy(F->m[i]);
8163 h.sig = pOne();
8164 //h.sig = pInit();
8165 //p_SetCoeff(h.sig,nInit(1),currRing);
8166 p_SetComp(h.sig,i+1,currRing);
8167 // if we are working with the Schreyer order we generate it
8168 // by multiplying the initial signatures with the leading monomial
8169 // of the corresponding initial polynomials generating the ideal
8170 // => we can keep the underlying monomial order and get a Schreyer
8171 // order without any bigger overhead
8172 if (strat->sbaOrder == 0 || strat->sbaOrder == 3)
8173 {
8174 p_ExpVectorAdd (h.sig,F->m[i],currRing);
8175 }
8176 h.sevSig = pGetShortExpVector(h.sig);
8177#ifdef DEBUGF5
8178 pWrite(h.p);
8179 pWrite(h.sig);
8180#endif
8181 if (h.p!=NULL)
8182 {
8184 {
8185 cancelunit(&h); /*- tries to cancel a unit -*/
8186 deleteHC(&h, strat);
8187 }
8188 if (h.p!=NULL)
8189 {
8191 {
8192 h.pCleardenom(); // also does remove Content
8193 }
8194 else
8195 {
8196 h.pNorm();
8197 }
8198 strat->initEcart(&h);
8199 if (strat->Ll==-1)
8200 pos =0;
8201 else
8202 pos = strat->posInLSba(strat->L,strat->Ll,&h,strat);
8203 h.sev = pGetShortExpVector(h.p);
8204 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos);
8205 }
8206 }
8207 /*
8208 if (strat->sbaOrder != 1)
8209 {
8210 for(j=0;j<i;j++)
8211 {
8212 strat->syz[ctr] = pCopy(F->m[j]);
8213 p_SetCompP(strat->syz[ctr],i+1,currRing);
8214 // add LM(F->m[i]) to the signature to get a Schreyer order
8215 // without changing the underlying polynomial ring at all
8216 p_ExpVectorAdd (strat->syz[ctr],F->m[i],currRing);
8217 // since p_Add_q() destroys all input
8218 // data we need to recreate help
8219 // each time
8220 poly help = pCopy(F->m[i]);
8221 p_SetCompP(help,j+1,currRing);
8222 pWrite(strat->syz[ctr]);
8223 pWrite(help);
8224 printf("%d\n",pLmCmp(strat->syz[ctr],help));
8225 strat->syz[ctr] = p_Add_q(strat->syz[ctr],help,currRing);
8226 printf("%d. SYZ ",ctr);
8227 pWrite(strat->syz[ctr]);
8228 strat->sevSyz[ctr] = p_GetShortExpVector(strat->syz[ctr],currRing);
8229 ctr++;
8230 }
8231 strat->syzl = ps;
8232 }
8233 */
8234 }
8235 }
8236 /*- test, if a unit is in F -*/
8237
8238 if ((strat->Ll>=0)
8239#ifdef HAVE_RINGS
8240 && n_IsUnit(pGetCoeff(strat->L[strat->Ll].p), currRing->cf)
8241#endif
8242 && pIsConstant(strat->L[strat->Ll].p))
8243 {
8244 while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat);
8245 }
8246}
8247
8249{
8250 if( strat->S[0] )
8251 {
8252 if( strat->S[1] && !rField_is_Ring(currRing))
8253 {
8254 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
8255 omFreeSize(strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
8256 omFreeSize(strat->syz,(strat->syzmax)*sizeof(poly));
8257 }
8258 int i, j, k, diff, comp, comp_old, ps=0, ctr=0;
8259 /************************************************************
8260 * computing the length of the syzygy array needed
8261 ***********************************************************/
8262 for(i=1; i<=strat->sl; i++)
8263 {
8264 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8265 {
8266 ps += i;
8267 }
8268 }
8269 ps += strat->sl+1;
8270 //comp = pGetComp (strat->P.sig);
8271 comp = strat->currIdx;
8272 strat->syzIdx = initec(comp);
8273 strat->sevSyz = initsevS(ps);
8274 strat->syz = (poly *)omAlloc(ps*sizeof(poly));
8275 strat->syzmax = ps;
8276 strat->syzl = 0;
8277 strat->syzidxmax = comp;
8278#if defined(DEBUGF5) || defined(DEBUGF51)
8279 PrintS("------------- GENERATING SYZ RULES NEW ---------------\n");
8280#endif
8281 i = 1;
8282 j = 0;
8283 /************************************************************
8284 * generating the leading terms of the principal syzygies
8285 ***********************************************************/
8286 while (i <= strat->sl)
8287 {
8288 /**********************************************************
8289 * principal syzygies start with component index 2
8290 * the array syzIdx starts with index 0
8291 * => the rules for a signature with component comp start
8292 * at strat->syz[strat->syzIdx[comp-2]] !
8293 *********************************************************/
8294 if (pGetComp(strat->sig[i-1]) != pGetComp(strat->sig[i]))
8295 {
8296 comp = pGetComp(strat->sig[i]);
8297 comp_old = pGetComp(strat->sig[i-1]);
8298 diff = comp - comp_old - 1;
8299 // diff should be zero, but sometimes also the initial generating
8300 // elements of the input ideal reduce to zero. then there is an
8301 // index-gap between the signatures. for these inbetween signatures we
8302 // can safely set syzIdx[j] = 0 as no such element will be ever computed
8303 // in the following.
8304 // doing this, we keep the relation "j = comp - 2" alive, which makes
8305 // jumps way easier when checking criteria
8306 while (diff>0)
8307 {
8308 strat->syzIdx[j] = 0;
8309 diff--;
8310 j++;
8311 }
8312 strat->syzIdx[j] = ctr;
8313 j++;
8314 LObject Q;
8315 int pos;
8316 for (k = 0; k<i; k++)
8317 {
8318 Q.sig = pOne();
8321 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8322 p_SetCompP (Q.sig, comp, currRing);
8323 poly q = p_One(currRing);
8326 p_ExpVectorCopy(q,strat->S[i],currRing);
8327 q = p_Neg (q, currRing);
8328 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8329 Q.sig = p_Add_q (Q.sig, q, currRing);
8330 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8331 pos = posInSyz(strat, Q.sig);
8332 enterSyz(Q, strat, pos);
8333 ctr++;
8334 }
8335 }
8336 i++;
8337 }
8338 /**************************************************************
8339 * add syzygies for upcoming first element of new iteration step
8340 **************************************************************/
8341 comp = strat->currIdx;
8342 comp_old = pGetComp(strat->sig[i-1]);
8343 diff = comp - comp_old - 1;
8344 // diff should be zero, but sometimes also the initial generating
8345 // elements of the input ideal reduce to zero. then there is an
8346 // index-gap between the signatures. for these inbetween signatures we
8347 // can safely set syzIdx[j] = 0 as no such element will be ever computed
8348 // in the following.
8349 // doing this, we keep the relation "j = comp - 2" alive, which makes
8350 // jumps way easier when checking criteria
8351 while (diff>0)
8352 {
8353 strat->syzIdx[j] = 0;
8354 diff--;
8355 j++;
8356 }
8357 strat->syzIdx[j] = ctr;
8358 LObject Q;
8359 int pos;
8360 for (k = 0; k<strat->sl+1; k++)
8361 {
8362 Q.sig = pOne();
8365 p_ExpVectorCopy(Q.sig,strat->S[k],currRing);
8366 p_SetCompP (Q.sig, comp, currRing);
8367 poly q = p_One(currRing);
8369 p_SetCoeff(q,nCopy(p_GetCoeff(strat->L[strat->Ll].p,currRing)),currRing);
8370 p_ExpVectorCopy(q,strat->L[strat->Ll].p,currRing);
8371 q = p_Neg (q, currRing);
8372 p_SetCompP (q, __p_GetComp(strat->sig[k], currRing), currRing);
8373 Q.sig = p_Add_q (Q.sig, q, currRing);
8374 Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
8375 pos = posInSyz(strat, Q.sig);
8376 enterSyz(Q, strat, pos);
8377 ctr++;
8378 }
8379//#if 1
8380#ifdef DEBUGF5
8381 PrintS("Principal syzygies:\n");
8382 Print("syzl %d\n",strat->syzl);
8383 Print("syzmax %d\n",strat->syzmax);
8384 Print("ps %d\n",ps);
8385 PrintS("--------------------------------\n");
8386 for(i=0;i<=strat->syzl-1;i++)
8387 {
8388 Print("%d - ",i);
8389 pWrite(strat->syz[i]);
8390 }
8391 for(i=0;i<strat->currIdx;i++)
8392 {
8393 Print("%d - %d\n",i,strat->syzIdx[i]);
8394 }
8395 PrintS("--------------------------------\n");
8396#endif
8397 }
8398}
8399
8400/*2
8401*construct the set s from F and {P}
8402*/
8403void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat)
8404{
8405 int i,pos;
8406
8408 else i=setmaxT;
8409 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8410 strat->ecartS=initec(i);
8411 strat->sevS=initsevS(i);
8412 strat->S_2_R=initS_2_R(i);
8413 strat->fromQ=NULL;
8414 strat->Shdl=idInit(i,F->rank);
8415 strat->S=strat->Shdl->m;
8416
8417 /*- put polys into S -*/
8418 if (Q!=NULL)
8419 {
8420 strat->fromQ=initec(i);
8421 memset(strat->fromQ,0,i*sizeof(int));
8422 for (i=0; i<IDELEMS(Q); i++)
8423 {
8424 if (Q->m[i]!=NULL)
8425 {
8426 LObject h;
8427 h.p = pCopy(Q->m[i]);
8428 //if (TEST_OPT_INTSTRATEGY)
8429 //{
8430 // h.pCleardenom(); // also does remove Content
8431 //}
8432 //else
8433 //{
8434 // h.pNorm();
8435 //}
8437 {
8438 deleteHC(&h,strat);
8439 }
8440 if (h.p!=NULL)
8441 {
8442 strat->initEcart(&h);
8443 if (strat->sl==-1)
8444 pos =0;
8445 else
8446 {
8447 pos = posInS(strat,strat->sl,h.p,h.ecart);
8448 }
8449 h.sev = pGetShortExpVector(h.p);
8450 strat->enterS(h,pos,strat, strat->tl+1);
8451 enterT(h, strat);
8452 strat->fromQ[pos]=1;
8453 }
8454 }
8455 }
8456 }
8457 /*- put polys into S -*/
8458 for (i=0; i<IDELEMS(F); i++)
8459 {
8460 if (F->m[i]!=NULL)
8461 {
8462 LObject h;
8463 h.p = pCopy(F->m[i]);
8465 {
8466 deleteHC(&h,strat);
8467 }
8468 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8469 {
8470 h.p=redtailBba(h.p,strat->sl,strat);
8471 }
8472 if (h.p!=NULL)
8473 {
8474 strat->initEcart(&h);
8475 if (strat->sl==-1)
8476 pos =0;
8477 else
8478 pos = posInS(strat,strat->sl,h.p,h.ecart);
8479 h.sev = pGetShortExpVector(h.p);
8480 strat->enterS(h,pos,strat, strat->tl+1);
8481 enterT(h,strat);
8482 }
8483 }
8484 }
8485 for (i=0; i<IDELEMS(P); i++)
8486 {
8487 if (P->m[i]!=NULL)
8488 {
8489 LObject h;
8490 h.p=pCopy(P->m[i]);
8492 {
8493 h.pCleardenom();
8494 }
8495 else
8496 {
8497 h.pNorm();
8498 }
8499 if(strat->sl>=0)
8500 {
8502 {
8503 h.p=redBba(h.p,strat->sl,strat);
8504 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8505 {
8506 h.p=redtailBba(h.p,strat->sl,strat);
8507 }
8508 }
8509 else
8510 {
8511 h.p=redMora(h.p,strat->sl,strat);
8512 }
8513 if(h.p!=NULL)
8514 {
8515 strat->initEcart(&h);
8517 {
8518 h.pCleardenom();
8519 }
8520 else
8521 {
8522 h.is_normalized = 0;
8523 h.pNorm();
8524 }
8525 h.sev = pGetShortExpVector(h.p);
8526 h.SetpFDeg();
8527 pos = posInS(strat,strat->sl,h.p,h.ecart);
8528 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8529 strat->enterS(h,pos,strat, strat->tl+1);
8530 enterT(h,strat);
8531 }
8532 }
8533 else
8534 {
8535 h.sev = pGetShortExpVector(h.p);
8536 strat->initEcart(&h);
8537 strat->enterS(h,0,strat, strat->tl+1);
8538 enterT(h,strat);
8539 }
8540 }
8541 }
8542}
8543/*2
8544*construct the set s from F and {P}
8545*/
8546
8547void initSSpecialSba (ideal F, ideal Q, ideal P,kStrategy strat)
8548{
8549 int i,pos;
8550
8552 else i=setmaxT;
8553 i=((i+IDELEMS(F)+IDELEMS(P)+setmax-1)/setmax)*setmax;
8554 strat->sevS=initsevS(i);
8555 strat->sevSig=initsevS(i);
8556 strat->S_2_R=initS_2_R(i);
8557 strat->fromQ=NULL;
8558 strat->Shdl=idInit(i,F->rank);
8559 strat->S=strat->Shdl->m;
8560 strat->sig=(poly *)omAlloc0(i*sizeof(poly));
8561 /*- put polys into S -*/
8562 if (Q!=NULL)
8563 {
8564 strat->fromQ=initec(i);
8565 memset(strat->fromQ,0,i*sizeof(int));
8566 for (i=0; i<IDELEMS(Q); i++)
8567 {
8568 if (Q->m[i]!=NULL)
8569 {
8570 LObject h;
8571 h.p = pCopy(Q->m[i]);
8572 //if (TEST_OPT_INTSTRATEGY)
8573 //{
8574 // h.pCleardenom(); // also does remove Content
8575 //}
8576 //else
8577 //{
8578 // h.pNorm();
8579 //}
8581 {
8582 deleteHC(&h,strat);
8583 }
8584 if (h.p!=NULL)
8585 {
8586 strat->initEcart(&h);
8587 if (strat->sl==-1)
8588 pos =0;
8589 else
8590 {
8591 pos = posInS(strat,strat->sl,h.p,h.ecart);
8592 }
8593 h.sev = pGetShortExpVector(h.p);
8594 strat->enterS(h,pos,strat, strat->tl+1);
8595 enterT(h, strat);
8596 strat->fromQ[pos]=1;
8597 }
8598 }
8599 }
8600 }
8601 /*- put polys into S -*/
8602 for (i=0; i<IDELEMS(F); i++)
8603 {
8604 if (F->m[i]!=NULL)
8605 {
8606 LObject h;
8607 h.p = pCopy(F->m[i]);
8609 {
8610 deleteHC(&h,strat);
8611 }
8612 else if (TEST_OPT_REDTAIL || TEST_OPT_REDSB)
8613 {
8614 h.p=redtailBba(h.p,strat->sl,strat);
8615 }
8616 if (h.p!=NULL)
8617 {
8618 strat->initEcart(&h);
8619 if (strat->sl==-1)
8620 pos =0;
8621 else
8622 pos = posInS(strat,strat->sl,h.p,h.ecart);
8623 h.sev = pGetShortExpVector(h.p);
8624 strat->enterS(h,pos,strat, strat->tl+1);
8625 enterT(h,strat);
8626 }
8627 }
8628 }
8629 for (i=0; i<IDELEMS(P); i++)
8630 {
8631 if (P->m[i]!=NULL)
8632 {
8633 LObject h;
8634 h.p=pCopy(P->m[i]);
8636 {
8637 h.pCleardenom();
8638 }
8639 else
8640 {
8641 h.pNorm();
8642 }
8643 if(strat->sl>=0)
8644 {
8646 {
8647 h.p=redBba(h.p,strat->sl,strat);
8648 if ((h.p!=NULL)&&(TEST_OPT_REDTAIL || TEST_OPT_REDSB))
8649 {
8650 h.p=redtailBba(h.p,strat->sl,strat);
8651 }
8652 }
8653 else
8654 {
8655 h.p=redMora(h.p,strat->sl,strat);
8656 }
8657 if(h.p!=NULL)
8658 {
8659 strat->initEcart(&h);
8661 {
8662 h.pCleardenom();
8663 }
8664 else
8665 {
8666 h.is_normalized = 0;
8667 h.pNorm();
8668 }
8669 h.sev = pGetShortExpVector(h.p);
8670 h.SetpFDeg();
8671 pos = posInS(strat,strat->sl,h.p,h.ecart);
8672 enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
8673 strat->enterS(h,pos,strat, strat->tl+1);
8674 enterT(h,strat);
8675 }
8676 }
8677 else
8678 {
8679 h.sev = pGetShortExpVector(h.p);
8680 strat->initEcart(&h);
8681 strat->enterS(h,0,strat, strat->tl+1);
8682 enterT(h,strat);
8683 }
8684 }
8685 }
8686}
8687
8688/*2
8689* reduces h using the set S
8690* procedure used in cancelunit1
8691*/
8692static poly redBba1 (poly h,int maxIndex,kStrategy strat)
8693{
8694 int j = 0;
8695 unsigned long not_sev = ~ pGetShortExpVector(h);
8696
8697 while (j <= maxIndex)
8698 {
8699 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev))
8700 return ksOldSpolyRedNew(strat->S[j],h,strat->kNoetherTail());
8701 else j++;
8702 }
8703 return h;
8704}
8705
8706/*2
8707*tests if p.p=monomial*unit and cancels the unit
8708*/
8709void cancelunit1 (LObject* p,int *suc, int index,kStrategy strat )
8710{
8711 int k;
8712 poly r,h,h1,q;
8713
8714 if (!pIsVector((*p).p) && ((*p).ecart != 0))
8715 {
8716#ifdef HAVE_RINGS
8717 // Leading coef have to be a unit: no
8718 // example 2x+4x2 should be simplified to 2x*(1+2x)
8719 // and 2 is not a unit in Z
8720 //if ( !(n_IsUnit(pGetCoeff((*p).p), currRing->cf)) ) return;
8721#endif
8722 k = 0;
8723 h1 = r = pCopy((*p).p);
8724 h =pNext(r);
8725 loop
8726 {
8727 if (h==NULL)
8728 {
8729 pDelete(&r);
8730 pDelete(&(pNext((*p).p)));
8731 (*p).ecart = 0;
8732 (*p).length = 1;
8733 (*p).pLength = 1;
8734 (*suc)=0;
8735 return;
8736 }
8737 if (!pDivisibleBy(r,h))
8738 {
8739 q=redBba1(h,index ,strat);
8740 if (q != h)
8741 {
8742 k++;
8743 pDelete(&h);
8744 pNext(h1) = h = q;
8745 }
8746 else
8747 {
8748 pDelete(&r);
8749 return;
8750 }
8751 }
8752 else
8753 {
8754 h1 = h;
8755 pIter(h);
8756 }
8757 if (k > 10)
8758 {
8759 pDelete(&r);
8760 return;
8761 }
8762 }
8763 }
8764}
8765
8766#if 0
8767/*2
8768* reduces h using the elements from Q in the set S
8769* procedure used in updateS
8770* must not be used for elements of Q or elements of an ideal !
8771*/
8772static poly redQ (poly h, int j, kStrategy strat)
8773{
8774 int start;
8775 unsigned long not_sev = ~ pGetShortExpVector(h);
8776 while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++;
8777 start=j;
8778 while (j<=strat->sl)
8779 {
8780 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8781 {
8782 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8783 if (h==NULL) return NULL;
8784 j = start;
8785 not_sev = ~ pGetShortExpVector(h);
8786 }
8787 else j++;
8788 }
8789 return h;
8790}
8791#endif
8792
8793/*2
8794* reduces h using the set S
8795* procedure used in updateS
8796*/
8797static poly redBba (poly h,int maxIndex,kStrategy strat)
8798{
8799 int j = 0;
8800 unsigned long not_sev = ~ pGetShortExpVector(h);
8801
8802 while (j <= maxIndex)
8803 {
8804 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev))
8805 {
8806 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8807 if (h==NULL) return NULL;
8808 j = 0;
8809 not_sev = ~ pGetShortExpVector(h);
8810 }
8811 else j++;
8812 }
8813 return h;
8814}
8815
8816/*2
8817* reduces h using the set S
8818*e is the ecart of h
8819*procedure used in updateS
8820*/
8821static poly redMora (poly h,int maxIndex,kStrategy strat)
8822{
8823 int j=0;
8824 int e,l;
8825 unsigned long not_sev = ~ pGetShortExpVector(h);
8826
8827 if (maxIndex >= 0)
8828 {
8829 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8830 do
8831 {
8832 if (pLmShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)
8833 && ((e >= strat->ecartS[j]) || (strat->kNoether!=NULL)))
8834 {
8835#ifdef KDEBUG
8836 if (TEST_OPT_DEBUG)
8837 {
8838 PrintS("reduce ");wrp(h);Print(" with S[%d] (",j);wrp(strat->S[j]);
8839 }
8840#endif
8841 h = ksOldSpolyRed(strat->S[j],h,strat->kNoetherTail());
8842#ifdef KDEBUG
8843 if(TEST_OPT_DEBUG)
8844 {
8845 PrintS(")\nto "); wrp(h); PrintLn();
8846 }
8847#endif
8848 // pDelete(&h);
8849 if (h == NULL) return NULL;
8850 e = currRing->pLDeg(h,&l,currRing)-p_FDeg(h,currRing);
8851 j = 0;
8852 not_sev = ~ pGetShortExpVector(h);
8853 }
8854 else j++;
8855 }
8856 while (j <= maxIndex);
8857 }
8858 return h;
8859}
8860
8861/*2
8862*updates S:
8863*the result is a set of polynomials which are in
8864*normalform with respect to S
8865*/
8867{
8868 LObject h;
8869 int i, suc=0;
8870 poly redSi=NULL;
8871 BOOLEAN change,any_change;
8872// Print("nach initS: updateS start mit sl=%d\n",(strat->sl));
8873// for (i=0; i<=(strat->sl); i++)
8874// {
8875// Print("s%d:",i);
8876// if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]);
8877// pWrite(strat->S[i]);
8878// }
8879// Print("currRing->OrdSgn=%d\n", currRing->OrdSgn);
8880 any_change=FALSE;
8882 {
8883 while (suc != -1)
8884 {
8885 i=suc+1;
8886 while (i<=strat->sl)
8887 {
8888 change=FALSE;
8890 any_change = FALSE;
8891 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
8892 {
8893 redSi = pHead(strat->S[i]);
8894 strat->S[i] = redBba(strat->S[i],i-1,strat);
8895 //if ((strat->ak!=0)&&(strat->S[i]!=NULL))
8896 // strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/
8897 if (pCmp(redSi,strat->S[i])!=0)
8898 {
8899 change=TRUE;
8900 any_change=TRUE;
8901 #ifdef KDEBUG
8902 if (TEST_OPT_DEBUG)
8903 {
8904 PrintS("reduce:");
8905 wrp(redSi);PrintS(" to ");p_wrp(strat->S[i], currRing, strat->tailRing);PrintLn();
8906 }
8907 #endif
8908 if (TEST_OPT_PROT)
8909 {
8910 if (strat->S[i]==NULL)
8911 PrintS("V");
8912 else
8913 PrintS("v");
8914 mflush();
8915 }
8916 }
8917 pLmDelete(&redSi);
8918 if (strat->S[i]==NULL)
8919 {
8920 deleteInS(i,strat);
8921 i--;
8922 }
8923 else if (change)
8924 {
8926 {
8928 {
8929 number n;
8930 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
8931 if (!nIsOne(n))
8932 {
8934 denom->n=nInvers(n);
8935 denom->next=DENOMINATOR_LIST;
8936 DENOMINATOR_LIST=denom;
8937 }
8938 nDelete(&n);
8939 }
8940 else
8941 {
8942 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
8943 }
8944 }
8945 else
8946 {
8947 pNorm(strat->S[i]);
8948 }
8949 strat->sevS[i] = pGetShortExpVector(strat->S[i]);
8950 }
8951 }
8952 i++;
8953 }
8954 if (any_change) reorderS(&suc,strat);
8955 else break;
8956 }
8957 if (toT)
8958 {
8959 for (i=0; i<=strat->sl; i++)
8960 {
8961 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
8962 {
8963 h.p = redtailBba(strat->S[i],i-1,strat);
8965 {
8966 h.pCleardenom();// also does remove Content
8967 }
8968 }
8969 else
8970 {
8971 h.p = strat->S[i];
8972 }
8973 strat->initEcart(&h);
8974 if (strat->honey)
8975 {
8976 strat->ecartS[i] = h.ecart;
8977 }
8978 if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);}
8979 else assume(strat->sevS[i] == pGetShortExpVector(h.p));
8980 h.sev = strat->sevS[i];
8981 /*puts the elements of S also to T*/
8982 strat->initEcart(&h);
8983 /*if (toT) - already checked*/ enterT(h,strat);
8984 strat->S_2_R[i] = strat->tl;
8985#ifdef HAVE_SHIFTBBA
8986 if (/*(toT) && */(currRing->isLPring))
8987 enterTShift(h, strat);
8988#endif
8989 }
8990 }
8991 }
8992 else
8993 {
8994 while (suc != -1)
8995 {
8996 i=suc;
8997 while (i<=strat->sl)
8998 {
8999 change=FALSE;
9000 if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) && (i>0))
9001 {
9002 redSi=pHead((strat->S)[i]);
9003 (strat->S)[i] = redMora((strat->S)[i],i-1,strat);
9004 if ((strat->S)[i]==NULL)
9005 {
9006 deleteInS(i,strat);
9007 i--;
9008 }
9009 else if (pCmp((strat->S)[i],redSi)!=0)
9010 {
9011 any_change=TRUE;
9012 h.p = strat->S[i];
9013 strat->initEcart(&h);
9014 strat->ecartS[i] = h.ecart;
9016 {
9018 {
9019 number n;
9020 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
9021 if (!nIsOne(n))
9022 {
9024 denom->n=nInvers(n);
9025 denom->next=DENOMINATOR_LIST;
9026 DENOMINATOR_LIST=denom;
9027 }
9028 nDelete(&n);
9029 }
9030 else
9031 {
9032 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
9033 }
9034 }
9035 else
9036 {
9037 pNorm(strat->S[i]); // == h.p
9038 }
9039 h.sev = pGetShortExpVector(h.p);
9040 strat->sevS[i] = h.sev;
9041 }
9042 pLmDelete(&redSi);
9043 kTest(strat);
9044 }
9045 i++;
9046 }
9047#ifdef KDEBUG
9048 kTest(strat);
9049#endif
9050 if (any_change) reorderS(&suc,strat);
9051 else { suc=-1; break; }
9052 if (h.p!=NULL)
9053 {
9054 if (!strat->kAllAxis)
9055 {
9056 /*strat->kAllAxis =*/ HEckeTest(h.p,strat);
9057 }
9058 if (strat->kAllAxis)
9059 newHEdge(strat);
9060 }
9061 }
9062 for (i=0; i<=strat->sl; i++)
9063 {
9064 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9065 {
9066 strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat);
9067 strat->initEcart(&h);
9068 strat->ecartS[i] = h.ecart;
9069 h.sev = pGetShortExpVector(h.p);
9070 strat->sevS[i] = h.sev;
9071 }
9072 else
9073 {
9074 h.p = strat->S[i];
9075 h.ecart=strat->ecartS[i];
9076 h.sev = strat->sevS[i];
9077 h.length = h.pLength = pLength(h.p);
9078 }
9079 if ((strat->fromQ==NULL) || (strat->fromQ[i]==0))
9080 cancelunit1(&h,&suc,strat->sl,strat);
9081 h.SetpFDeg();
9082 /*puts the elements of S also to T*/
9083 enterT(h,strat);
9084 strat->S_2_R[i] = strat->tl;
9085#ifdef HAVE_SHIFTBBA
9086 if (currRing->isLPring)
9087 enterTShift(h, strat);
9088#endif
9089 }
9090 if (suc!= -1) updateS(toT,strat);
9091 }
9092#ifdef KDEBUG
9093 kTest(strat);
9094#endif
9095}
9096
9097/*2
9098* -puts p to the standardbasis s at position at
9099* -saves the result in S
9100*/
9101void enterSBba (LObject &p,int atS,kStrategy strat, int atR)
9102{
9103 strat->news = TRUE;
9104 /*- puts p to the standardbasis s at position at -*/
9105 if (strat->sl == IDELEMS(strat->Shdl)-1)
9106 {
9107 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9108 IDELEMS(strat->Shdl)*sizeof(unsigned long),
9109 (IDELEMS(strat->Shdl)+setmaxTinc)
9110 *sizeof(unsigned long));
9111 strat->ecartS = (intset)omReallocSize(strat->ecartS,
9112 IDELEMS(strat->Shdl)*sizeof(int),
9113 (IDELEMS(strat->Shdl)+setmaxTinc)
9114 *sizeof(int));
9115 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9116 IDELEMS(strat->Shdl)*sizeof(int),
9117 (IDELEMS(strat->Shdl)+setmaxTinc)
9118 *sizeof(int));
9119 if (strat->lenS!=NULL)
9120 strat->lenS=(int*)omRealloc0Size(strat->lenS,
9121 IDELEMS(strat->Shdl)*sizeof(int),
9122 (IDELEMS(strat->Shdl)+setmaxTinc)
9123 *sizeof(int));
9124 if (strat->lenSw!=NULL)
9125 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9126 IDELEMS(strat->Shdl)*sizeof(wlen_type),
9127 (IDELEMS(strat->Shdl)+setmaxTinc)
9128 *sizeof(wlen_type));
9129 if (strat->fromQ!=NULL)
9130 {
9131 strat->fromQ = (intset)omReallocSize(strat->fromQ,
9132 IDELEMS(strat->Shdl)*sizeof(int),
9133 (IDELEMS(strat->Shdl)+setmaxTinc)*sizeof(int));
9134 }
9135 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmaxTinc);
9136 IDELEMS(strat->Shdl)+=setmaxTinc;
9137 strat->Shdl->m=strat->S;
9138 }
9139 if (atS <= strat->sl)
9140 {
9141#ifdef ENTER_USE_MEMMOVE
9142 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9143 (strat->sl - atS + 1)*sizeof(poly));
9144 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9145 (strat->sl - atS + 1)*sizeof(int));
9146 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9147 (strat->sl - atS + 1)*sizeof(unsigned long));
9148 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9149 (strat->sl - atS + 1)*sizeof(int));
9150 if (strat->lenS!=NULL)
9151 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9152 (strat->sl - atS + 1)*sizeof(int));
9153 if (strat->lenSw!=NULL)
9154 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9155 (strat->sl - atS + 1)*sizeof(wlen_type));
9156#else
9157 for (i=strat->sl+1; i>=atS+1; i--)
9158 {
9159 strat->S[i] = strat->S[i-1];
9160 strat->ecartS[i] = strat->ecartS[i-1];
9161 strat->sevS[i] = strat->sevS[i-1];
9162 strat->S_2_R[i] = strat->S_2_R[i-1];
9163 }
9164 if (strat->lenS!=NULL)
9165 for (i=strat->sl+1; i>=atS+1; i--)
9166 strat->lenS[i] = strat->lenS[i-1];
9167 if (strat->lenSw!=NULL)
9168 for (i=strat->sl+1; i>=atS+1; i--)
9169 strat->lenSw[i] = strat->lenSw[i-1];
9170#endif
9171 }
9172 if (strat->fromQ!=NULL)
9173 {
9174#ifdef ENTER_USE_MEMMOVE
9175 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9176 (strat->sl - atS + 1)*sizeof(int));
9177#else
9178 for (i=strat->sl+1; i>=atS+1; i--)
9179 {
9180 strat->fromQ[i] = strat->fromQ[i-1];
9181 }
9182#endif
9183 strat->fromQ[atS]=0;
9184 }
9185
9186 /*- save result -*/
9187 poly pp=p.p;
9188 strat->S[atS] = pp;
9189 if (strat->honey) strat->ecartS[atS] = p.ecart;
9190 if (p.sev == 0)
9191 p.sev = pGetShortExpVector(pp);
9192 else
9193 assume(p.sev == pGetShortExpVector(pp));
9194 strat->sevS[atS] = p.sev;
9195 strat->ecartS[atS] = p.ecart;
9196 strat->S_2_R[atS] = atR;
9197 strat->sl++;
9198}
9199
9200#ifdef HAVE_SHIFTBBA
9201void enterSBbaShift (LObject &p,int atS,kStrategy strat, int atR)
9202{
9203 enterSBba(p, atS, strat, atR);
9204
9205 int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
9206 for (int i = maxPossibleShift; i > 0; i--)
9207 {
9208 // NOTE: don't use "shared tails" here. In rare cases it can cause problems
9209 // in `kNF2` because of lazy poly normalizations.
9210 LObject qq(p_Copy(p.p, strat->tailRing));
9211 p_mLPshift(qq.p, i, strat->tailRing);
9212 qq.shift = i;
9213 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
9214 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
9215 enterSBba(qq, atS, strat, -1);
9216 }
9217}
9218#endif
9219
9220/*2
9221* -puts p to the standardbasis s at position at
9222* -saves the result in S
9223*/
9224void enterSSba (LObject &p,int atS,kStrategy strat, int atR)
9225{
9226 strat->news = TRUE;
9227 /*- puts p to the standardbasis s at position at -*/
9228 if (strat->sl == IDELEMS(strat->Shdl)-1)
9229 {
9230 strat->sevS = (unsigned long*) omRealloc0Size(strat->sevS,
9231 IDELEMS(strat->Shdl)*sizeof(unsigned long),
9232 (IDELEMS(strat->Shdl)+setmax)
9233 *sizeof(unsigned long));
9234 strat->sevSig = (unsigned long*) omRealloc0Size(strat->sevSig,
9235 IDELEMS(strat->Shdl)*sizeof(unsigned long),
9236 (IDELEMS(strat->Shdl)+setmax)
9237 *sizeof(unsigned long));
9238 strat->ecartS = (intset)omReallocSize(strat->ecartS,
9239 IDELEMS(strat->Shdl)*sizeof(int),
9240 (IDELEMS(strat->Shdl)+setmax)
9241 *sizeof(int));
9242 strat->S_2_R = (int*) omRealloc0Size(strat->S_2_R,
9243 IDELEMS(strat->Shdl)*sizeof(int),
9244 (IDELEMS(strat->Shdl)+setmax)
9245 *sizeof(int));
9246 if (strat->lenS!=NULL)
9247 strat->lenS=(int*)omRealloc0Size(strat->lenS,
9248 IDELEMS(strat->Shdl)*sizeof(int),
9249 (IDELEMS(strat->Shdl)+setmax)
9250 *sizeof(int));
9251 if (strat->lenSw!=NULL)
9252 strat->lenSw=(wlen_type*)omRealloc0Size(strat->lenSw,
9253 IDELEMS(strat->Shdl)*sizeof(wlen_type),
9254 (IDELEMS(strat->Shdl)+setmax)
9255 *sizeof(wlen_type));
9256 if (strat->fromQ!=NULL)
9257 {
9258 strat->fromQ = (intset)omReallocSize(strat->fromQ,
9259 IDELEMS(strat->Shdl)*sizeof(int),
9260 (IDELEMS(strat->Shdl)+setmax)*sizeof(int));
9261 }
9262 pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax);
9263 pEnlargeSet(&strat->sig,IDELEMS(strat->Shdl),setmax);
9264 IDELEMS(strat->Shdl)+=setmax;
9265 strat->Shdl->m=strat->S;
9266 }
9267 // in a signature-based algorithm the following situation will never
9268 // appear due to the fact that the critical pairs are already sorted
9269 // by increasing signature.
9270 // True. However, in the case of integers we need to put the element
9271 // that caused the signature drop on the first position
9272 if (atS <= strat->sl)
9273 {
9274#ifdef ENTER_USE_MEMMOVE
9275 memmove(&(strat->S[atS+1]), &(strat->S[atS]),
9276 (strat->sl - atS + 1)*sizeof(poly));
9277 memmove(&(strat->sig[atS+1]), &(strat->sig[atS]),
9278 (strat->sl - atS + 1)*sizeof(poly));
9279 memmove(&(strat->sevSig[atS+1]), &(strat->sevSig[atS]),
9280 (strat->sl - atS + 1)*sizeof(unsigned long));
9281 memmove(&(strat->ecartS[atS+1]), &(strat->ecartS[atS]),
9282 (strat->sl - atS + 1)*sizeof(int));
9283 memmove(&(strat->sevS[atS+1]), &(strat->sevS[atS]),
9284 (strat->sl - atS + 1)*sizeof(unsigned long));
9285 memmove(&(strat->S_2_R[atS+1]), &(strat->S_2_R[atS]),
9286 (strat->sl - atS + 1)*sizeof(int));
9287 if (strat->lenS!=NULL)
9288 memmove(&(strat->lenS[atS+1]), &(strat->lenS[atS]),
9289 (strat->sl - atS + 1)*sizeof(int));
9290 if (strat->lenSw!=NULL)
9291 memmove(&(strat->lenSw[atS+1]), &(strat->lenSw[atS]),
9292 (strat->sl - atS + 1)*sizeof(wlen_type));
9293#else
9294 for (i=strat->sl+1; i>=atS+1; i--)
9295 {
9296 strat->S[i] = strat->S[i-1];
9297 strat->ecartS[i] = strat->ecartS[i-1];
9298 strat->sevS[i] = strat->sevS[i-1];
9299 strat->S_2_R[i] = strat->S_2_R[i-1];
9300 strat->sig[i] = strat->sig[i-1];
9301 strat->sevSig[i] = strat->sevSig[i-1];
9302 }
9303 if (strat->lenS!=NULL)
9304 for (i=strat->sl+1; i>=atS+1; i--)
9305 strat->lenS[i] = strat->lenS[i-1];
9306 if (strat->lenSw!=NULL)
9307 for (i=strat->sl+1; i>=atS+1; i--)
9308 strat->lenSw[i] = strat->lenSw[i-1];
9309#endif
9310 }
9311 if (strat->fromQ!=NULL)
9312 {
9313#ifdef ENTER_USE_MEMMOVE
9314 memmove(&(strat->fromQ[atS+1]), &(strat->fromQ[atS]),
9315 (strat->sl - atS + 1)*sizeof(int));
9316#else
9317 for (i=strat->sl+1; i>=atS+1; i--)
9318 {
9319 strat->fromQ[i] = strat->fromQ[i-1];
9320 }
9321#endif
9322 strat->fromQ[atS]=0;
9323 }
9324
9325 /*- save result -*/
9326 strat->S[atS] = p.p;
9327 strat->sig[atS] = p.sig; // TODO: get ths correct signature in here!
9328 if (strat->honey) strat->ecartS[atS] = p.ecart;
9329 if (p.sev == 0)
9330 p.sev = pGetShortExpVector(p.p);
9331 else
9332 assume(p.sev == pGetShortExpVector(p.p));
9333 strat->sevS[atS] = p.sev;
9334 // during the interreduction process of a signature-based algorithm we do not
9335 // compute the signature at this point, but when the whole interreduction
9336 // process finishes, i.e. f5c terminates!
9337 if (p.sig != NULL)
9338 {
9339 if (p.sevSig == 0)
9340 p.sevSig = pGetShortExpVector(p.sig);
9341 else
9342 assume(p.sevSig == pGetShortExpVector(p.sig));
9343 strat->sevSig[atS] = p.sevSig; // TODO: get the correct signature in here!
9344 }
9345 strat->ecartS[atS] = p.ecart;
9346 strat->S_2_R[atS] = atR;
9347 strat->sl++;
9348#ifdef DEBUGF5
9349 int k;
9350 Print("--- LIST S: %d ---\n",strat->sl);
9351 for(k=0;k<=strat->sl;k++)
9352 {
9353 pWrite(strat->sig[k]);
9354 }
9355 PrintS("--- LIST S END ---\n");
9356#endif
9357}
9358
9360{
9361 p.GetP(strat->lmBin);
9362 if (strat->homog) strat->initEcart(&p);
9363 strat->redTailChange=FALSE;
9365 {
9366 p.pCleardenom();
9368 {
9369#ifdef HAVE_SHIFTBBA
9370 if (rIsLPRing(currRing))
9371 p.p = redtailBba(&p,strat->tl,strat, TRUE,!TEST_OPT_CONTENTSB);
9372 else
9373#endif
9374 {
9375 p.p = redtailBba(&p,strat->sl,strat, FALSE,!TEST_OPT_CONTENTSB);
9376 }
9377 p.pCleardenom();
9378 if (strat->redTailChange)
9379 p.t_p=NULL;
9380 if (strat->P.p!=NULL) strat->P.sev=p_GetShortExpVector(strat->P.p,currRing);
9381 else strat->P.sev=0;
9382 }
9383 }
9384
9385 assume(strat->tailRing == p.tailRing);
9386 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9387
9388 int i, j, pos;
9389 poly tp = strat->T[tj].p;
9390
9391 /* enter p to T set */
9392 enterT(p, strat);
9393
9394 for (j = 0; j <= strat->sl; ++j)
9395 {
9396 if (pLtCmp(tp, strat->S[j]) == 0)
9397 {
9398 break;
9399 }
9400 }
9401 /* it may be that the exchanged element
9402 * is until now only in T and not in S */
9403 if (j <= strat->sl)
9404 {
9405 deleteInS(j, strat);
9406 }
9407
9408 pos = posInS(strat, strat->sl, p.p, p.ecart);
9409
9410 pp_Test(p.p, currRing, p.tailRing);
9411 assume(p.FDeg == p.pFDeg());
9412
9413 /* remove useless pairs from L set */
9414 for (i = 0; i <= strat->Ll; ++i)
9415 {
9416 if (strat->L[i].p1 != NULL && pLtCmp(tp, strat->L[i].p1) == 0)
9417 {
9418 deleteInL(strat->L, &(strat->Ll), i, strat);
9419 i--;
9420 continue;
9421 }
9422 if (strat->L[i].p2 != NULL && pLtCmp(tp, strat->L[i].p2) == 0)
9423 {
9424 deleteInL(strat->L, &(strat->Ll), i, strat);
9425 i--;
9426 }
9427 }
9428#ifdef HAVE_SHIFTBBA
9429 if (rIsLPRing(currRing))
9430 enterpairsShift(p.p, strat->sl, p.ecart, pos, strat, strat->tl); // TODO LP
9431 else
9432#endif
9433 {
9434 /* generate new pairs with p, probably removing older, now useless pairs */
9435 superenterpairs(p.p, strat->sl, p.ecart, pos, strat, strat->tl);
9436 }
9437 /* enter p to S set */
9438 strat->enterS(p, pos, strat, strat->tl);
9439
9440#ifdef HAVE_SHIFTBBA
9441 /* do this after enterS so that the index in R (which is strat->tl) is correct */
9442 if (rIsLPRing(currRing) && !strat->rightGB)
9443 enterTShift(p,strat);
9444#endif
9445}
9446
9447/*2
9448* puts p to the set T at position atT
9449*/
9450void enterT(LObject &p, kStrategy strat, int atT)
9451{
9452 int i;
9453
9454#ifdef PDEBUG
9455#ifdef HAVE_SHIFTBBA
9456 if (currRing->isLPring && p.shift > 0)
9457 {
9458 // in this case, the order is not correct. test LM and tail separately
9459 p_LmTest(p.p, currRing);
9460 p_Test(pNext(p.p), currRing);
9461 }
9462 else
9463#endif
9464 {
9465 pp_Test(p.p, currRing, p.tailRing);
9466 }
9467#endif
9468 assume(strat->tailRing == p.tailRing);
9469 // redMoraNF complains about this -- but, we don't really
9470 // neeed this so far
9471 assume(p.pLength == 0 || pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9472 assume(!strat->homog || (p.FDeg == p.pFDeg()));
9473 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9474
9475#ifdef KDEBUG
9476 // do not put an LObject twice into T:
9477 for(i=strat->tl;i>=0;i--)
9478 {
9479 if (p.p==strat->T[i].p)
9480 {
9481 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9482 return;
9483 }
9484 }
9485#endif
9486
9487#ifdef HAVE_TAIL_RING
9488 if (currRing!=strat->tailRing)
9489 {
9490 p.t_p=p.GetLmTailRing();
9491 }
9492#endif
9493 strat->newt = TRUE;
9494 if (atT < 0)
9495 atT = strat->posInT(strat->T, strat->tl, p);
9496 if (strat->tl == strat->tmax-1)
9497 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9498 if (atT <= strat->tl)
9499 {
9500#ifdef ENTER_USE_MEMMOVE
9501 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9502 (strat->tl-atT+1)*sizeof(TObject));
9503 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9504 (strat->tl-atT+1)*sizeof(unsigned long));
9505#endif
9506 for (i=strat->tl+1; i>=atT+1; i--)
9507 {
9508#ifndef ENTER_USE_MEMMOVE
9509 strat->T[i] = strat->T[i-1];
9510 strat->sevT[i] = strat->sevT[i-1];
9511#endif
9512 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9513 }
9514 }
9515
9516 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9517 {
9518#ifdef HAVE_SHIFTBBA
9519 // letterplace: if p.shift > 0 then pNext(p.p) is already in the tailBin
9520 if (!(currRing->isLPring && p.shift > 0))
9521#endif
9522 {
9524 (strat->tailRing != NULL ?
9525 strat->tailRing : currRing),
9526 strat->tailBin);
9527 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9528 }
9529 }
9530 strat->T[atT] = (TObject) p;
9531 //printf("\nenterT: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9532
9533 if ((pNext(p.p) != NULL) && (!rIsLPRing(currRing)))
9534 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9535 else
9536 strat->T[atT].max_exp = NULL;
9537
9538 strat->tl++;
9539 strat->R[strat->tl] = &(strat->T[atT]);
9540 strat->T[atT].i_r = strat->tl;
9541 assume((p.sev == 0) || (pGetShortExpVector(p.p) == p.sev));
9542 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9543 kTest_T(&(strat->T[atT]),strat);
9544}
9545
9546/*2
9547* puts p to the set T at position atT
9548*/
9549#ifdef HAVE_RINGS
9550void enterT_strong(LObject &p, kStrategy strat, int atT)
9551{
9553 int i;
9554
9555 pp_Test(p.p, currRing, p.tailRing);
9556 assume(strat->tailRing == p.tailRing);
9557 // redMoraNF complains about this -- but, we don't really
9558 // neeed this so far
9559 assume(p.pLength == 0 || (int)pLength(p.p) == p.pLength || rIsSyzIndexRing(currRing)); // modulo syzring
9560 assume(p.FDeg == p.pFDeg());
9561 assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
9562
9563#ifdef KDEBUG
9564 // do not put an LObject twice into T:
9565 for(i=strat->tl;i>=0;i--)
9566 {
9567 if (p.p==strat->T[i].p)
9568 {
9569 printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
9570 return;
9571 }
9572 }
9573#endif
9574
9575#ifdef HAVE_TAIL_RING
9576 if (currRing!=strat->tailRing)
9577 {
9578 p.t_p=p.GetLmTailRing();
9579 }
9580#endif
9581 strat->newt = TRUE;
9582 if (atT < 0)
9583 atT = strat->posInT(strat->T, strat->tl, p);
9584 if (strat->tl == strat->tmax-1)
9585 enlargeT(strat->T,strat->R,strat->sevT,strat->tmax,setmaxTinc);
9586 if (atT <= strat->tl)
9587 {
9588#ifdef ENTER_USE_MEMMOVE
9589 memmove(&(strat->T[atT+1]), &(strat->T[atT]),
9590 (strat->tl-atT+1)*sizeof(TObject));
9591 memmove(&(strat->sevT[atT+1]), &(strat->sevT[atT]),
9592 (strat->tl-atT+1)*sizeof(unsigned long));
9593#endif
9594 for (i=strat->tl+1; i>=atT+1; i--)
9595 {
9596#ifndef ENTER_USE_MEMMOVE
9597 strat->T[i] = strat->T[i-1];
9598 strat->sevT[i] = strat->sevT[i-1];
9599#endif
9600 strat->R[strat->T[i].i_r] = &(strat->T[i]);
9601 }
9602 }
9603
9604 if ((strat->tailBin != NULL) && (pNext(p.p) != NULL))
9605 {
9607 (strat->tailRing != NULL ?
9608 strat->tailRing : currRing),
9609 strat->tailBin);
9610 if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
9611 }
9612 strat->T[atT] = (TObject) p;
9613 //printf("\nenterT_strong: add new: length = %i, ecart = %i\n",p.length,p.ecart);
9614
9615 if (pNext(p.p) != NULL)
9616 strat->T[atT].max_exp = p_GetMaxExpP(pNext(p.p), strat->tailRing);
9617 else
9618 strat->T[atT].max_exp = NULL;
9619
9620 strat->tl++;
9621 strat->R[strat->tl] = &(strat->T[atT]);
9622 strat->T[atT].i_r = strat->tl;
9623 assume(p.sev == 0 || pGetShortExpVector(p.p) == p.sev);
9624 strat->sevT[atT] = (p.sev == 0 ? pGetShortExpVector(p.p) : p.sev);
9625 #if 1
9627 && !n_IsUnit(p.p->coef, currRing->cf))
9628 {
9629 for(i=strat->tl;i>=0;i--)
9630 {
9631 if(strat->T[i].ecart <= p.ecart && pLmDivisibleBy(strat->T[i].p,p.p))
9632 {
9633 enterOneStrongPoly(i,p.p,p.ecart,0,strat,0 , TRUE);
9634 }
9635 }
9636 }
9637 /*
9638 printf("\nThis is T:\n");
9639 for(i=strat->tl;i>=0;i--)
9640 {
9641 pWrite(strat->T[i].p);
9642 }
9643 //getchar();*/
9644 #endif
9645 kTest_T(&(strat->T[atT]),strat);
9646}
9647#endif
9648
9649/*2
9650* puts signature p.sig to the set syz
9651*/
9652void enterSyz(LObject &p, kStrategy strat, int atT)
9653{
9654 int i;
9655 strat->newt = TRUE;
9656 if (strat->syzl == strat->syzmax-1)
9657 {
9658 pEnlargeSet(&strat->syz,strat->syzmax,setmax);
9659 strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
9660 (strat->syzmax)*sizeof(unsigned long),
9661 ((strat->syzmax)+setmax)
9662 *sizeof(unsigned long));
9663 strat->syzmax += setmax;
9664 }
9665 if (atT < strat->syzl)
9666 {
9667#ifdef ENTER_USE_MEMMOVE
9668 memmove(&(strat->syz[atT+1]), &(strat->syz[atT]),
9669 (strat->syzl-atT+1)*sizeof(poly));
9670 memmove(&(strat->sevSyz[atT+1]), &(strat->sevSyz[atT]),
9671 (strat->syzl-atT+1)*sizeof(unsigned long));
9672#endif
9673 for (i=strat->syzl; i>=atT+1; i--)
9674 {
9675#ifndef ENTER_USE_MEMMOVE
9676 strat->syz[i] = strat->syz[i-1];
9677 strat->sevSyz[i] = strat->sevSyz[i-1];
9678#endif
9679 }
9680 }
9681 //i = strat->syzl;
9682 i = atT;
9683 //Makes sure the syz saves just the signature
9684 #ifdef HAVE_RINGS
9686 pNext(p.sig) = NULL;
9687 #endif
9688 strat->syz[atT] = p.sig;
9689 strat->sevSyz[atT] = p.sevSig;
9690 strat->syzl++;
9691#if F5DEBUG
9692 Print("element in strat->syz: %d--%d ",atT+1,strat->syzmax);
9693 pWrite(strat->syz[atT]);
9694#endif
9695 // recheck pairs in strat->L with new rule and delete correspondingly
9696 int cc = strat->Ll;
9697 while (cc>-1)
9698 {
9699 //printf("\nCheck if syz is div by L\n");pWrite(strat->syz[atT]);pWrite(strat->L[cc].sig);
9700 //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);
9701 if (p_LmShortDivisibleBy( strat->syz[atT], strat->sevSyz[atT],
9702 strat->L[cc].sig, ~strat->L[cc].sevSig, currRing)
9703 #ifdef HAVE_RINGS
9705 || (n_DivBy(pGetCoeff(strat->L[cc].sig),pGetCoeff(strat->syz[atT]),currRing->cf) && (pLtCmp(strat->L[cc].sig,strat->syz[atT])==1)))
9706 #endif
9707 )
9708 {
9709 //printf("\nYES!\n");
9710 deleteInL(strat->L,&strat->Ll,cc,strat);
9711 }
9712 cc--;
9713 }
9714//#if 1
9715#ifdef DEBUGF5
9716 PrintS("--- Syzygies ---\n");
9717 Print("syzl %d\n",strat->syzl);
9718 Print("syzmax %d\n",strat->syzmax);
9719 PrintS("--------------------------------\n");
9720 for(i=0;i<=strat->syzl-1;i++)
9721 {
9722 Print("%d - ",i);
9723 pWrite(strat->syz[i]);
9724 }
9725 PrintS("--------------------------------\n");
9726#endif
9727}
9728
9729
9730void initHilbCrit(ideal/*F*/, ideal /*Q*/, intvec **hilb,kStrategy strat)
9731{
9732
9733 //if the ordering is local, then hilb criterion
9734 //can be used also if the ideal is not homogenous
9736 {
9738 *hilb=NULL;
9739 else
9740 return;
9741 }
9742 if (strat->homog!=isHomog)
9743 {
9744 *hilb=NULL;
9745 }
9746}
9747
9749{
9752 if (TEST_OPT_SB_1)
9754#ifdef HAVE_RINGS
9756 {
9758 strat->chainCrit=chainCritRing;
9759 }
9760#endif
9761#ifdef HAVE_RATGRING
9762 if (rIsRatGRing(currRing))
9763 {
9764 strat->chainCrit=chainCritPart;
9765 /* enterOnePairNormal get rational part in it */
9766 }
9767#endif
9768 if (TEST_OPT_IDLIFT
9769 && (strat->syzComp==1)
9770 && (!rIsPluralRing(currRing)))
9772
9774 strat->Gebauer = strat->homog || strat->sugarCrit;
9775 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9776 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9777 strat->pairtest = NULL;
9778 /* alway use tailreduction, except:
9779 * - in local rings, - in lex order case, -in ring over extensions */
9781 //if(rHasMixedOrdering(currRing)==2)
9782 //{
9783 // strat->noTailReduction =TRUE;
9784 //}
9785
9786#ifdef HAVE_PLURAL
9787 // and r is plural_ring
9788 // hence this holds for r a rational_plural_ring
9789 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9790 { //or it has non-quasi-comm type... later
9791 strat->sugarCrit = FALSE;
9792 strat->Gebauer = FALSE;
9793 strat->honey = FALSE;
9794 }
9795#endif
9796
9797 // Coefficient ring?
9799 {
9800 strat->sugarCrit = FALSE;
9801 strat->Gebauer = FALSE;
9802 strat->honey = FALSE;
9803 }
9804 #ifdef KDEBUG
9805 if (TEST_OPT_DEBUG)
9806 {
9807 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9808 else PrintS("ideal/module is not homogeneous\n");
9809 }
9810 #endif
9811}
9812
9814{
9815 //strat->enterOnePair=enterOnePairNormal;
9817 //strat->chainCrit=chainCritNormal;
9818 strat->chainCrit = chainCritSig;
9819 /******************************************
9820 * rewCrit1 and rewCrit2 are already set in
9821 * kSba() in kstd1.cc
9822 *****************************************/
9823 //strat->rewCrit1 = faugereRewCriterion;
9824 if (strat->sbaOrder == 1)
9825 {
9826 strat->syzCrit = syzCriterionInc;
9827 }
9828 else
9829 {
9830 strat->syzCrit = syzCriterion;
9831 }
9832#ifdef HAVE_RINGS
9834 {
9836 strat->chainCrit=chainCritRing;
9837 }
9838#endif
9839#ifdef HAVE_RATGRING
9840 if (rIsRatGRing(currRing))
9841 {
9842 strat->chainCrit=chainCritPart;
9843 /* enterOnePairNormal get rational part in it */
9844 }
9845#endif
9846
9848 strat->Gebauer = strat->homog || strat->sugarCrit;
9849 strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM;
9850 if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE;
9851 strat->pairtest = NULL;
9852 /* alway use tailreduction, except:
9853 * - in local rings, - in lex order case, -in ring over extensions */
9856
9857#ifdef HAVE_PLURAL
9858 // and r is plural_ring
9859 // hence this holds for r a rational_plural_ring
9860 if( rIsPluralRing(currRing) || (rIsSCA(currRing) && !strat->z2homog) )
9861 { //or it has non-quasi-comm type... later
9862 strat->sugarCrit = FALSE;
9863 strat->Gebauer = FALSE;
9864 strat->honey = FALSE;
9865 }
9866#endif
9867
9868 // Coefficient ring?
9870 {
9871 strat->sugarCrit = FALSE;
9872 strat->Gebauer = FALSE ;
9873 strat->honey = FALSE;
9874 }
9875 #ifdef KDEBUG
9876 if (TEST_OPT_DEBUG)
9877 {
9878 if (strat->homog) PrintS("ideal/module is homogeneous\n");
9879 else PrintS("ideal/module is not homogeneous\n");
9880 }
9881 #endif
9882}
9883
9885 (const LSet set, const int length,
9886 LObject* L,const kStrategy strat))
9887{
9888 if (pos_in_l == posInL110
9889 || pos_in_l == posInL10
9890 #ifdef HAVE_RINGS
9891 || pos_in_l == posInL110Ring
9892 || pos_in_l == posInLRing
9893 #endif
9894 )
9895 return TRUE;
9896
9897 return FALSE;
9898}
9899
9901{
9903 {
9904 if (strat->honey)
9905 {
9906 strat->posInL = posInL15;
9907 // ok -- here is the deal: from my experiments for Singular-2-0
9908 // I conclude that that posInT_EcartpLength is the best of
9909 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9910 // see the table at the end of this file
9911 if (TEST_OPT_OLDSTD)
9912 strat->posInT = posInT15;
9913 else
9914 strat->posInT = posInT_EcartpLength;
9915 }
9916 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
9917 {
9918 strat->posInL = posInL11;
9919 strat->posInT = posInT11;
9920 }
9921 else if (TEST_OPT_INTSTRATEGY)
9922 {
9923 strat->posInL = posInL11;
9924 strat->posInT = posInT11;
9925 }
9926 else
9927 {
9928 strat->posInL = posInL0;
9929 strat->posInT = posInT0;
9930 }
9931 //if (strat->minim>0) strat->posInL =posInLSpecial;
9932 if (strat->homog)
9933 {
9934 strat->posInL = posInL110;
9935 strat->posInT = posInT110;
9936 }
9937 }
9938 else /* local/mixed ordering */
9939 {
9940 if (strat->homog)
9941 {
9942 strat->posInL = posInL11;
9943 strat->posInT = posInT11;
9944 }
9945 else
9946 {
9947 if ((currRing->order[0]==ringorder_c)
9948 ||(currRing->order[0]==ringorder_C))
9949 {
9950 strat->posInL = posInL17_c;
9951 strat->posInT = posInT17_c;
9952 }
9953 else
9954 {
9955 strat->posInL = posInL17;
9956 strat->posInT = posInT17;
9957 }
9958 }
9959 }
9960 if (strat->minim>0) strat->posInL =posInLSpecial;
9961 // for further tests only
9962 if ((BTEST1(11)) || (BTEST1(12)))
9963 strat->posInL = posInL11;
9964 else if ((BTEST1(13)) || (BTEST1(14)))
9965 strat->posInL = posInL13;
9966 else if ((BTEST1(15)) || (BTEST1(16)))
9967 strat->posInL = posInL15;
9968 else if ((BTEST1(17)) || (BTEST1(18)))
9969 strat->posInL = posInL17;
9970 if (BTEST1(11))
9971 strat->posInT = posInT11;
9972 else if (BTEST1(13))
9973 strat->posInT = posInT13;
9974 else if (BTEST1(15))
9975 strat->posInT = posInT15;
9976 else if ((BTEST1(17)))
9977 strat->posInT = posInT17;
9978 else if ((BTEST1(19)))
9979 strat->posInT = posInT19;
9980 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
9981 strat->posInT = posInT1;
9983}
9984
9985#ifdef HAVE_RINGS
9987{
9989 {
9990 if (strat->honey)
9991 {
9992 strat->posInL = posInL15Ring;
9993 // ok -- here is the deal: from my experiments for Singular-2-0
9994 // I conclude that that posInT_EcartpLength is the best of
9995 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
9996 // see the table at the end of this file
9997 if (TEST_OPT_OLDSTD)
9998 strat->posInT = posInT15Ring;
9999 else
10000 strat->posInT = posInT_EcartpLength;
10001 }
10002 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10003 {
10004 strat->posInL = posInL11Ring;
10005 strat->posInT = posInT11;
10006 }
10007 else if (TEST_OPT_INTSTRATEGY)
10008 {
10009 strat->posInL = posInL11Ring;
10010 strat->posInT = posInT11;
10011 }
10012 else
10013 {
10014 strat->posInL = posInL0Ring;
10015 strat->posInT = posInT0;
10016 }
10017 //if (strat->minim>0) strat->posInL =posInLSpecial;
10018 if (strat->homog)
10019 {
10020 strat->posInL = posInL110Ring;
10021 strat->posInT = posInT110Ring;
10022 }
10023 }
10024 else
10025 {
10026 if (strat->homog)
10027 {
10028 //printf("\nHere 3\n");
10029 strat->posInL = posInL11Ring;
10030 strat->posInT = posInT11Ring;
10031 }
10032 else
10033 {
10034 if ((currRing->order[0]==ringorder_c)
10035 ||(currRing->order[0]==ringorder_C))
10036 {
10037 strat->posInL = posInL17_cRing;
10038 strat->posInT = posInT17_cRing;
10039 }
10040 else
10041 {
10042 strat->posInL = posInL11Ringls;
10043 strat->posInT = posInT17Ring;
10044 }
10045 }
10046 }
10047 if (strat->minim>0) strat->posInL =posInLSpecial;
10048 // for further tests only
10049 if ((BTEST1(11)) || (BTEST1(12)))
10050 strat->posInL = posInL11Ring;
10051 else if ((BTEST1(13)) || (BTEST1(14)))
10052 strat->posInL = posInL13;
10053 else if ((BTEST1(15)) || (BTEST1(16)))
10054 strat->posInL = posInL15Ring;
10055 else if ((BTEST1(17)) || (BTEST1(18)))
10056 strat->posInL = posInL17Ring;
10057 if (BTEST1(11))
10058 strat->posInT = posInT11Ring;
10059 else if (BTEST1(13))
10060 strat->posInT = posInT13;
10061 else if (BTEST1(15))
10062 strat->posInT = posInT15Ring;
10063 else if ((BTEST1(17)))
10064 strat->posInT = posInT17Ring;
10065 else if ((BTEST1(19)))
10066 strat->posInT = posInT19;
10067 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10068 strat->posInT = posInT1;
10070}
10071#endif
10072
10073void initBuchMora (ideal F,ideal Q,kStrategy strat)
10074{
10075 strat->interpt = BTEST1(OPT_INTERRUPT);
10076 /*- creating temp data structures------------------- -*/
10077 //strat->cp = 0; // already by skStragy()
10078 //strat->c3 = 0; // already by skStragy()
10079#ifdef HAVE_SHIFTBBA
10080 strat->cv = 0; // already by skStragy()
10081#endif
10082 strat->tail = pInit();
10083 /*- set s -*/
10084 strat->sl = -1;
10085 /*- set L -*/
10086 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10087 strat->Ll = -1;
10088 strat->L = initL(strat->Lmax);
10089 /*- set B -*/
10090 strat->Bmax = setmaxL;
10091 strat->Bl = -1;
10092 strat->B = initL();
10093 /*- set T -*/
10094 strat->tl = -1;
10095 strat->tmax = setmaxT;
10096 strat->T = initT();
10097 strat->R = initR();
10098 strat->sevT = initsevT();
10099 /*- init local data struct.---------------------------------------- -*/
10100 //strat->P.ecart=0; // already by skStragy()
10101 //strat->P.length=0; // already by skStragy()
10102 //strat->P.pLength=0; // already by skStragy()
10104 {
10105 if (strat->kNoether!=NULL)
10106 {
10107 pSetComp(strat->kNoether, strat->ak);
10108 pSetComp(strat->kNoetherTail(), strat->ak);
10109 }
10110 }
10112 {
10113 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10114 }
10115 else
10116 {
10117 if(TEST_OPT_SB_1)
10118 {
10119 int i;
10120 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10121 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10122 {
10123 P->m[i-strat->newIdeal] = F->m[i];
10124 F->m[i] = NULL;
10125 }
10126 initSSpecial(F,Q,P,strat);
10127 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10128 {
10129 F->m[i] = P->m[i-strat->newIdeal];
10130 P->m[i-strat->newIdeal] = NULL;
10131 }
10132 idDelete(&P);
10133 }
10134 else
10135 {
10136 /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */
10137 // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */
10138 }
10139 }
10140 strat->fromT = FALSE;
10142 if ((!TEST_OPT_SB_1)
10144 )
10145 {
10146 updateS(TRUE,strat);
10147 }
10148#ifdef HAVE_SHIFTBBA
10149 if (!(rIsLPRing(currRing) && strat->rightGB)) // for right GB, we need to check later whether a poly is from Q
10150#endif
10151 {
10152 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10153 strat->fromQ=NULL;
10154 }
10155 assume(kTest_TS(strat));
10156}
10157
10159{
10160 /*- release temp data -*/
10161 cleanT(strat);
10162 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10163 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10164 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10165 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10166 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10167 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10168 /*- set L: should be empty -*/
10169 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10170 /*- set B: should be empty -*/
10171 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10172 pLmFree(&strat->tail);
10173 strat->syzComp=0;
10174
10175#ifdef HAVE_SHIFTBBA
10176 if (rIsLPRing(currRing) && strat->rightGB)
10177 {
10178 if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10179 strat->fromQ=NULL;
10180 }
10181#endif
10182}
10183
10185{
10187 {
10188 if (strat->honey)
10189 {
10190 strat->posInL = posInL15;
10191 // ok -- here is the deal: from my experiments for Singular-2-0
10192 // I conclude that that posInT_EcartpLength is the best of
10193 // posInT15, posInT_EcartFDegpLength, posInT_FDegLength, posInT_pLength
10194 // see the table at the end of this file
10195 if (TEST_OPT_OLDSTD)
10196 strat->posInT = posInT15;
10197 else
10198 strat->posInT = posInT_EcartpLength;
10199 }
10200 else if (currRing->pLexOrder && !TEST_OPT_INTSTRATEGY)
10201 {
10202 strat->posInL = posInL11;
10203 strat->posInT = posInT11;
10204 }
10205 else if (TEST_OPT_INTSTRATEGY)
10206 {
10207 strat->posInL = posInL11;
10208 strat->posInT = posInT11;
10209 }
10210 else
10211 {
10212 strat->posInL = posInL0;
10213 strat->posInT = posInT0;
10214 }
10215 //if (strat->minim>0) strat->posInL =posInLSpecial;
10216 if (strat->homog)
10217 {
10218 strat->posInL = posInL110;
10219 strat->posInT = posInT110;
10220 }
10221 }
10222 else
10223 {
10224 if (strat->homog)
10225 {
10226 strat->posInL = posInL11;
10227 strat->posInT = posInT11;
10228 }
10229 else
10230 {
10231 if ((currRing->order[0]==ringorder_c)
10232 ||(currRing->order[0]==ringorder_C))
10233 {
10234 strat->posInL = posInL17_c;
10235 strat->posInT = posInT17_c;
10236 }
10237 else
10238 {
10239 strat->posInL = posInL17;
10240 strat->posInT = posInT17;
10241 }
10242 }
10243 }
10244 if (strat->minim>0) strat->posInL =posInLSpecial;
10245 // for further tests only
10246 if ((BTEST1(11)) || (BTEST1(12)))
10247 strat->posInL = posInL11;
10248 else if ((BTEST1(13)) || (BTEST1(14)))
10249 strat->posInL = posInL13;
10250 else if ((BTEST1(15)) || (BTEST1(16)))
10251 strat->posInL = posInL15;
10252 else if ((BTEST1(17)) || (BTEST1(18)))
10253 strat->posInL = posInL17;
10254 if (BTEST1(11))
10255 strat->posInT = posInT11;
10256 else if (BTEST1(13))
10257 strat->posInT = posInT13;
10258 else if (BTEST1(15))
10259 strat->posInT = posInT15;
10260 else if ((BTEST1(17)))
10261 strat->posInT = posInT17;
10262 else if ((BTEST1(19)))
10263 strat->posInT = posInT19;
10264 else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18))
10265 strat->posInT = posInT1;
10267 {
10268 strat->posInL = posInL11Ring;
10269 if(rHasLocalOrMixedOrdering(currRing) && currRing->pLexOrder == TRUE)
10270 strat->posInL = posInL11Ringls;
10271 strat->posInT = posInT11;
10272 }
10274 strat->posInLSba = posInLSig;
10275 //strat->posInL = posInLSig;
10276 strat->posInL = posInLF5C;
10277 /*
10278 if (rField_is_Ring(currRing))
10279 {
10280 strat->posInLSba = posInLSigRing;
10281 strat->posInL = posInL11Ring;
10282 }*/
10283 //strat->posInT = posInTSig;
10284}
10285
10286void initSbaBuchMora (ideal F,ideal Q,kStrategy strat)
10287{
10288 strat->interpt = BTEST1(OPT_INTERRUPT);
10289 //strat->kNoether=NULL; // done by skStrategy
10290 /*- creating temp data structures------------------- -*/
10291 //strat->cp = 0; // done by skStrategy
10292 //strat->c3 = 0; // done by skStrategy
10293 strat->tail = pInit();
10294 /*- set s -*/
10295 strat->sl = -1;
10296 /*- set ps -*/
10297 strat->syzl = -1;
10298 /*- set L -*/
10299 strat->Lmax = ((IDELEMS(F)+setmaxLinc-1)/setmaxLinc)*setmaxLinc;
10300 strat->Ll = -1;
10301 strat->L = initL(strat->Lmax);
10302 /*- set B -*/
10303 strat->Bmax = setmaxL;
10304 strat->Bl = -1;
10305 strat->B = initL();
10306 /*- set T -*/
10307 strat->tl = -1;
10308 strat->tmax = setmaxT;
10309 strat->T = initT();
10310 strat->R = initR();
10311 strat->sevT = initsevT();
10312 /*- init local data struct.---------------------------------------- -*/
10313 //strat->P.ecart=0; // done by skStrategy
10314 //strat->P.length=0; // done by skStrategy
10316 {
10317 if (strat->kNoether!=NULL)
10318 {
10319 pSetComp(strat->kNoether, strat->ak);
10320 pSetComp(strat->kNoetherTail(), strat->ak);
10321 }
10322 }
10324 {
10325 /*Shdl=*/initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10326 }
10327 else
10328 {
10329 if(TEST_OPT_SB_1)
10330 {
10331 int i;
10332 ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank);
10333 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10334 {
10335 P->m[i-strat->newIdeal] = F->m[i];
10336 F->m[i] = NULL;
10337 }
10338 initSSpecialSba(F,Q,P,strat);
10339 for (i=strat->newIdeal;i<IDELEMS(F);i++)
10340 {
10341 F->m[i] = P->m[i-strat->newIdeal];
10342 P->m[i-strat->newIdeal] = NULL;
10343 }
10344 idDelete(&P);
10345 }
10346 else
10347 {
10348 initSLSba(F, Q,strat); /*sets also S, ecartS, fromQ */
10349 }
10350 }
10351 //strat->fromT = FALSE; // done by skStrategy
10352 if (!TEST_OPT_SB_1)
10353 {
10354 if(!rField_is_Ring(currRing)) updateS(TRUE,strat);
10355 }
10356 //if (strat->fromQ!=NULL) omFreeSize(strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
10357 //strat->fromQ=NULL;
10358 assume(kTest_TS(strat));
10359}
10360
10361void exitSba (kStrategy strat)
10362{
10363 /*- release temp data -*/
10365 cleanTSbaRing(strat);
10366 else
10367 cleanT(strat);
10368 omFreeSize(strat->T,(strat->tmax)*sizeof(TObject));
10369 omFreeSize(strat->R,(strat->tmax)*sizeof(TObject*));
10370 omFreeSize(strat->sevT, (strat->tmax)*sizeof(unsigned long));
10371 omFreeSize(strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
10372 omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10373 omFreeSize((ADDRESS)strat->sevSig,IDELEMS(strat->Shdl)*sizeof(unsigned long));
10374 if(strat->syzmax>0)
10375 {
10376 omFreeSize((ADDRESS)strat->syz,(strat->syzmax)*sizeof(poly));
10377 omFreeSize((ADDRESS)strat->sevSyz,(strat->syzmax)*sizeof(unsigned long));
10378 if (strat->sbaOrder == 1)
10379 {
10380 omFreeSize(strat->syzIdx,(strat->syzidxmax)*sizeof(int));
10381 }
10382 }
10383 omFreeSize(strat->S_2_R,IDELEMS(strat->Shdl)*sizeof(int));
10384 /*- set L: should be empty -*/
10385 omFreeSize(strat->L,(strat->Lmax)*sizeof(LObject));
10386 /*- set B: should be empty -*/
10387 omFreeSize(strat->B,(strat->Bmax)*sizeof(LObject));
10388 /*- set sig: no need for the signatures anymore -*/
10389 omFreeSize(strat->sig,IDELEMS(strat->Shdl)*sizeof(poly));
10390 pLmDelete(&strat->tail);
10391 strat->syzComp=0;
10392}
10393
10394/*2
10395* in the case of a standardbase of a module over a qring:
10396* replace polynomials in i by ak vectors,
10397* (the polynomial * unit vectors gen(1)..gen(ak)
10398* in every case (also for ideals:)
10399* deletes divisible vectors/polynomials
10400*/
10401void updateResult(ideal r,ideal Q, kStrategy strat)
10402{
10403 int l;
10404 if (strat->ak>0)
10405 {
10406 for (l=IDELEMS(r)-1;l>=0;l--)
10407 {
10408 if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0))
10409 {
10410 pDelete(&r->m[l]); // and set it to NULL
10411 }
10412 }
10413 int q;
10414 poly p;
10416 {
10417 for (l=IDELEMS(r)-1;l>=0;l--)
10418 {
10419 if ((r->m[l]!=NULL)
10420 //&& (strat->syzComp>0)
10421 //&& (pGetComp(r->m[l])<=strat->syzComp)
10422 )
10423 {
10424 for(q=IDELEMS(Q)-1; q>=0;q--)
10425 {
10426 if ((Q->m[q]!=NULL)
10427 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10428 {
10429 if (TEST_OPT_REDSB)
10430 {
10431 p=r->m[l];
10432 r->m[l]=kNF(Q,NULL,p);
10433 pDelete(&p);
10434 }
10435 else
10436 {
10437 pDelete(&r->m[l]); // and set it to NULL
10438 }
10439 break;
10440 }
10441 }
10442 }
10443 }
10444 }
10445 #ifdef HAVE_RINGS
10446 else
10447 {
10448 for (l=IDELEMS(r)-1;l>=0;l--)
10449 {
10450 if ((r->m[l]!=NULL)
10451 //&& (strat->syzComp>0)
10452 //&& (pGetComp(r->m[l])<=strat->syzComp)
10453 )
10454 {
10455 for(q=IDELEMS(Q)-1; q>=0;q--)
10456 {
10457 if ((Q->m[q]!=NULL)
10458 &&(pLmDivisibleBy(Q->m[q],r->m[l])))
10459 {
10460 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10461 {
10462 if (TEST_OPT_REDSB)
10463 {
10464 p=r->m[l];
10465 r->m[l]=kNF(Q,NULL,p);
10466 pDelete(&p);
10467 }
10468 else
10469 {
10470 pDelete(&r->m[l]); // and set it to NULL
10471 }
10472 break;
10473 }
10474 }
10475 }
10476 }
10477 }
10478 }
10479 #endif
10480 }
10481 else
10482 {
10483 int q;
10484 poly p;
10485 BOOLEAN reduction_found=FALSE;
10487 {
10488 for (l=IDELEMS(r)-1;l>=0;l--)
10489 {
10490 if (r->m[l]!=NULL)
10491 {
10492 for(q=IDELEMS(Q)-1; q>=0;q--)
10493 {
10494 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])))
10495 {
10496 if (TEST_OPT_REDSB)
10497 {
10498 p=r->m[l];
10499 r->m[l]=kNF(Q,NULL,p);
10500 pDelete(&p);
10501 reduction_found=TRUE;
10502 }
10503 else
10504 {
10505 pDelete(&r->m[l]); // and set it to NULL
10506 }
10507 break;
10508 }
10509 }
10510 }
10511 }
10512 }
10513 #ifdef HAVE_RINGS
10514 //Also need divisibility of the leading coefficients
10515 else
10516 {
10517 for (l=IDELEMS(r)-1;l>=0;l--)
10518 {
10519 if (r->m[l]!=NULL)
10520 {
10521 for(q=IDELEMS(Q)-1; q>=0;q--)
10522 {
10523 if(n_DivBy(r->m[l]->coef, Q->m[q]->coef, currRing->cf))
10524 {
10525 if ((Q->m[q]!=NULL)&&(pLmEqual(Q->m[q],r->m[l])) && pDivisibleBy(Q->m[q],r->m[l]))
10526 {
10527 if (TEST_OPT_REDSB)
10528 {
10529 p=r->m[l];
10530 r->m[l]=kNF(Q,NULL,p);
10531 pDelete(&p);
10532 reduction_found=TRUE;
10533 }
10534 else
10535 {
10536 pDelete(&r->m[l]); // and set it to NULL
10537 }
10538 break;
10539 }
10540 }
10541 }
10542 }
10543 }
10544 }
10545 #endif
10546 if (/*TEST_OPT_REDSB &&*/ reduction_found)
10547 {
10548 #ifdef HAVE_RINGS
10550 {
10551 for (l=IDELEMS(r)-1;l>=0;l--)
10552 {
10553 if (r->m[l]!=NULL)
10554 {
10555 for(q=IDELEMS(r)-1;q>=0;q--)
10556 {
10557 if ((l!=q)
10558 && (r->m[q]!=NULL)
10559 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10560 &&(n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf))
10561 )
10562 {
10563 //If they are equal then take the one with the smallest length
10564 if(pLmDivisibleBy(r->m[q],r->m[l])
10565 && n_DivBy(r->m[q]->coef, r->m[l]->coef, currRing->cf)
10566 && (pLength(r->m[q]) < pLength(r->m[l]) ||
10567 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10568 {
10569 pDelete(&r->m[l]);
10570 break;
10571 }
10572 else
10573 pDelete(&r->m[q]);
10574 }
10575 }
10576 }
10577 }
10578 }
10579 else
10580 #endif
10581 {
10582 for (l=IDELEMS(r)-1;l>=0;l--)
10583 {
10584 if (r->m[l]!=NULL)
10585 {
10586 for(q=IDELEMS(r)-1;q>=0;q--)
10587 {
10588 if ((l!=q)
10589 && (r->m[q]!=NULL)
10590 &&(pLmDivisibleBy(r->m[l],r->m[q]))
10591 )
10592 {
10593 //If they are equal then take the one with the smallest length
10594 if(pLmDivisibleBy(r->m[q],r->m[l])
10595 &&(pLength(r->m[q]) < pLength(r->m[l]) ||
10596 (pLength(r->m[q]) == pLength(r->m[l]) && nGreaterZero(r->m[q]->coef))))
10597 {
10598 pDelete(&r->m[l]);
10599 break;
10600 }
10601 else
10602 pDelete(&r->m[q]);
10603 }
10604 }
10605 }
10606 }
10607 }
10608 }
10609 }
10610 idSkipZeroes(r);
10611}
10612
10614{
10615 int i;
10616 int low = (((rHasGlobalOrdering(currRing)) && (strat->ak==0)) ? 1 : 0);
10617 LObject L;
10618
10619#ifdef KDEBUG
10620 // need to set this: during tailreductions of T[i], T[i].max is out of
10621 // sync
10622 sloppy_max = TRUE;
10623#endif
10624
10625 strat->noTailReduction = FALSE;
10626 //if(rHasMixedOrdering(currRing)) strat->noTailReduction = TRUE;
10627 if (TEST_OPT_PROT)
10628 {
10629 PrintLn();
10630// if (timerv) writeTime("standard base computed:");
10631 }
10632 if (TEST_OPT_PROT)
10633 {
10634 Print("(S:%d)",strat->sl);mflush();
10635 }
10636 for (i=strat->sl; i>=low; i--)
10637 {
10638 int end_pos=strat->sl;
10639 if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
10640 if (strat->ak==0) end_pos=i-1;
10641 TObject* T_j = strat->s_2_t(i);
10642 if ((T_j != NULL)&&(T_j->p==strat->S[i]))
10643 {
10644 L = *T_j;
10645 #ifdef KDEBUG
10646 if (TEST_OPT_DEBUG)
10647 {
10648 Print("test S[%d]:",i);
10649 p_wrp(L.p,currRing,strat->tailRing);
10650 PrintLn();
10651 }
10652 #endif
10654 strat->S[i] = redtailBba(&L, end_pos, strat, withT);
10655 else
10656 strat->S[i] = redtail(&L, strat->sl, strat);
10657 #ifdef KDEBUG
10658 if (TEST_OPT_DEBUG)
10659 {
10660 Print("to (tailR) S[%d]:",i);
10661 p_wrp(strat->S[i],currRing,strat->tailRing);
10662 PrintLn();
10663 }
10664 #endif
10665
10666 if (strat->redTailChange)
10667 {
10668 if (T_j->max_exp != NULL) p_LmFree(T_j->max_exp, strat->tailRing);
10669 if (pNext(T_j->p) != NULL)
10670 T_j->max_exp = p_GetMaxExpP(pNext(T_j->p), strat->tailRing);
10671 else
10672 T_j->max_exp = NULL;
10673 }
10675 T_j->pCleardenom();
10676 }
10677 else
10678 {
10679 assume(currRing == strat->tailRing);
10680 #ifdef KDEBUG
10681 if (TEST_OPT_DEBUG)
10682 {
10683 Print("test S[%d]:",i);
10684 p_wrp(strat->S[i],currRing,strat->tailRing);
10685 PrintLn();
10686 }
10687 #endif
10689 strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
10690 else
10691 strat->S[i] = redtail(strat->S[i], strat->sl, strat);
10693 {
10695 {
10696 number n;
10697 p_Cleardenom_n(strat->S[i], currRing, n);// also does remove Content
10698 if (!nIsOne(n))
10699 {
10701 denom->n=nInvers(n);
10702 denom->next=DENOMINATOR_LIST;
10703 DENOMINATOR_LIST=denom;
10704 }
10705 nDelete(&n);
10706 }
10707 else
10708 {
10709 strat->S[i]=p_Cleardenom(strat->S[i], currRing);// also does remove Content
10710 }
10711 }
10712 #ifdef KDEBUG
10713 if (TEST_OPT_DEBUG)
10714 {
10715 Print("to (-tailR) S[%d]:",i);
10716 p_wrp(strat->S[i],currRing,strat->tailRing);
10717 PrintLn();
10718 }
10719 #endif
10720 }
10721 if (TEST_OPT_PROT)
10722 PrintS("-");
10723 }
10724 if (TEST_OPT_PROT) PrintLn();
10725#ifdef KDEBUG
10726 sloppy_max = FALSE;
10727#endif
10728}
10729
10730
10731/*2
10732* computes the new strat->kNoether and the new pNoether,
10733* returns TRUE, if pNoether has changed
10734*/
10736{
10737 if (currRing->pLexOrder || rHasMixedOrdering(currRing))
10738 return FALSE;
10739 int i,j;
10740 poly newNoether;
10741
10742#if 0
10743 if (currRing->weight_all_1)
10744 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10745 else
10746 scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kNoether);
10747#else
10748 scComputeHC(strat->Shdl,NULL,strat->ak,strat->kNoether);
10749#endif
10750 if (strat->kNoether==NULL) return FALSE;
10751 if (strat->t_kNoether != NULL)
10752 {
10753 p_LmFree(strat->t_kNoether, strat->tailRing);
10754 strat->t_kNoether=NULL;
10755 }
10756 if (strat->tailRing != currRing)
10758 /* compare old and new noether*/
10759 newNoether = pLmInit(strat->kNoether);
10760 pSetCoeff0(newNoether,nInit(1));
10761 j = p_FDeg(newNoether,currRing);
10762 for (i=1; i<=(currRing->N); i++)
10763 {
10764 if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i);
10765 }
10766 pSetm(newNoether);
10767 if (j < HCord) /*- statistics -*/
10768 {
10769 if (TEST_OPT_PROT)
10770 {
10771 Print("H(%d)",j);
10772 mflush();
10773 }
10774 HCord=j;
10775 #ifdef KDEBUG
10776 if (TEST_OPT_DEBUG)
10777 {
10778 Print("H(%d):",j);
10779 wrp(strat->kNoether);
10780 PrintLn();
10781 }
10782 #endif
10783 }
10784 if (pCmp(strat->kNoether,newNoether)!=1)
10785 {
10786 if (strat->kNoether!=NULL) p_LmDelete0(strat->kNoether,currRing);
10787 strat->kNoether=newNoether;
10788 if (strat->t_kNoether != NULL)
10789 {
10790 p_LmFree(strat->t_kNoether, strat->tailRing);
10791 strat->t_kNoether=NULL;
10792 }
10793 if (strat->tailRing != currRing)
10795
10796 return TRUE;
10797 }
10798 pLmDelete(newNoether);
10799 return FALSE;
10800}
10801
10802/***************************************************************
10803 *
10804 * Routines related for ring changes during std computations
10805 *
10806 ***************************************************************/
10807BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
10808{
10809 if (strat->overflow) return FALSE;
10810 assume(L->p1 != NULL && L->p2 != NULL);
10811 // shift changes: from 0 to -1
10812 assume(L->i_r1 >= -1 && L->i_r1 <= strat->tl);
10813 assume(L->i_r2 >= -1 && L->i_r2 <= strat->tl);
10814
10815 if (! k_GetLeadTerms(L->p1, L->p2, currRing, m1, m2, strat->tailRing))
10816 return FALSE;
10817 // shift changes: extra case inserted
10818 if ((L->i_r1 == -1) || (L->i_r2 == -1) )
10819 {
10820 return TRUE;
10821 }
10822 poly p1_max=NULL;
10823 if ((L->i_r1>=0)&&(strat->R[L->i_r1]!=NULL)) p1_max = (strat->R[L->i_r1])->max_exp;
10824 poly p2_max=NULL;
10825 if ((L->i_r2>=0)&&(strat->R[L->i_r2]!=NULL)) p2_max = (strat->R[L->i_r2])->max_exp;
10826
10827 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10828 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10829 {
10830 p_LmFree(m1, strat->tailRing);
10831 p_LmFree(m2, strat->tailRing);
10832 m1 = NULL;
10833 m2 = NULL;
10834 return FALSE;
10835 }
10836 return TRUE;
10837}
10838
10839#ifdef HAVE_RINGS
10840/***************************************************************
10841 *
10842 * Checks, if we can compute the gcd poly / strong pair
10843 * gcd-poly = m1 * R[atR] + m2 * S[atS]
10844 *
10845 ***************************************************************/
10846BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
10847{
10848 assume(strat->S_2_R[atS] >= -1 && strat->S_2_R[atS] <= strat->tl);
10849 //assume(strat->tailRing != currRing);
10850
10851 poly p1_max = (strat->R[atR])->max_exp;
10852 poly p2_max = (strat->R[strat->S_2_R[atS]])->max_exp;
10853
10854 if (((p1_max != NULL) && !p_LmExpVectorAddIsOk(m1, p1_max, strat->tailRing)) ||
10855 ((p2_max != NULL) && !p_LmExpVectorAddIsOk(m2, p2_max, strat->tailRing)))
10856 {
10857 return FALSE;
10858 }
10859 return TRUE;
10860}
10861#endif
10862
10863#ifdef HAVE_RINGS
10864/*!
10865 used for GB over ZZ: look for constant and monomial elements in the ideal
10866 background: any known constant element of ideal suppresses
10867 intermediate coefficient swell
10868*/
10869poly preIntegerCheck(const ideal Forig, const ideal Q)
10870{
10871 if(!nCoeff_is_Z(currRing->cf))
10872 return NULL;
10873 ideal F = idCopy(Forig);
10874 idSkipZeroes(F);
10875 poly pmon;
10876 ring origR = currRing;
10877 ideal monred = idInit(1,1);
10878 for(int i=0; i<idElem(F); i++)
10879 {
10880 if(pNext(F->m[i]) == NULL)
10881 idInsertPoly(monred, pCopy(F->m[i]));
10882 }
10883 int posconst = idPosConstant(F);
10884 if((posconst != -1) && (!nIsZero(F->m[posconst]->coef)))
10885 {
10886 idDelete(&F);
10887 idDelete(&monred);
10888 return NULL;
10889 }
10890 int idelemQ = 0;
10891 if(Q!=NULL)
10892 {
10893 idelemQ = IDELEMS(Q);
10894 for(int i=0; i<idelemQ; i++)
10895 {
10896 if(pNext(Q->m[i]) == NULL)
10897 idInsertPoly(monred, pCopy(Q->m[i]));
10898 }
10899 idSkipZeroes(monred);
10900 posconst = idPosConstant(monred);
10901 //the constant, if found, will be from Q
10902 if((posconst != -1) && (!nIsZero(monred->m[posconst]->coef)))
10903 {
10904 pmon = pCopy(monred->m[posconst]);
10905 idDelete(&F);
10906 idDelete(&monred);
10907 return pmon;
10908 }
10909 }
10910 ring QQ_ring = rCopy0(currRing,FALSE);
10911 nKillChar(QQ_ring->cf);
10912 QQ_ring->cf = nInitChar(n_Q, NULL);
10913 rComplete(QQ_ring,1);
10914 QQ_ring = rAssure_c_dp(QQ_ring);
10915 rChangeCurrRing(QQ_ring);
10916 nMapFunc nMap = n_SetMap(origR->cf, QQ_ring->cf);
10917 ideal II = idInit(IDELEMS(F)+idelemQ+2,id_RankFreeModule(F, origR));
10918 for(int i = 0, j = 0; i<IDELEMS(F); i++)
10919 II->m[j++] = prMapR(F->m[i], nMap, origR, QQ_ring);
10920 for(int i = 0, j = IDELEMS(F); i<idelemQ; i++)
10921 II->m[j++] = prMapR(Q->m[i], nMap, origR, QQ_ring);
10922 ideal one = kStd(II, NULL, isNotHomog, NULL);
10923 idSkipZeroes(one);
10924 if(idIsConstant(one))
10925 {
10926 //one should be <1>
10927 for(int i = IDELEMS(II)-1; i>=0; i--)
10928 if(II->m[i] != NULL)
10929 II->m[i+1] = II->m[i];
10930 II->m[0] = pOne();
10931 ideal syz = idSyzygies(II, isNotHomog, NULL);
10932 poly integer = NULL;
10933 for(int i = IDELEMS(syz)-1;i>=0; i--)
10934 {
10935 if(pGetComp(syz->m[i]) == 1)
10936 {
10937 pSetComp(syz->m[i],0);
10938 if(pIsConstant(pHead(syz->m[i])))
10939 {
10940 integer = pHead(syz->m[i]);
10941 break;
10942 }
10943 }
10944 }
10945 rChangeCurrRing(origR);
10946 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
10947 pmon = prMapR(integer, nMap2, QQ_ring, origR);
10948 idDelete(&monred);
10949 idDelete(&F);
10950 id_Delete(&II,QQ_ring);
10951 id_Delete(&one,QQ_ring);
10952 id_Delete(&syz,QQ_ring);
10953 p_Delete(&integer,QQ_ring);
10954 rDelete(QQ_ring);
10955 return pmon;
10956 }
10957 else
10958 {
10959 if(idIs0(monred))
10960 {
10961 poly mindegmon = NULL;
10962 for(int i = 0; i<IDELEMS(one); i++)
10963 {
10964 if(pNext(one->m[i]) == NULL)
10965 {
10966 if(mindegmon == NULL)
10967 mindegmon = pCopy(one->m[i]);
10968 else
10969 {
10970 if(p_Deg(one->m[i], QQ_ring) < p_Deg(mindegmon, QQ_ring))
10971 mindegmon = pCopy(one->m[i]);
10972 }
10973 }
10974 }
10975 if(mindegmon != NULL)
10976 {
10977 for(int i = IDELEMS(II)-1; i>=0; i--)
10978 if(II->m[i] != NULL)
10979 II->m[i+1] = II->m[i];
10980 II->m[0] = pCopy(mindegmon);
10981 ideal syz = idSyzygies(II, isNotHomog, NULL);
10982 bool found = FALSE;
10983 for(int i = IDELEMS(syz)-1;i>=0; i--)
10984 {
10985 if(pGetComp(syz->m[i]) == 1)
10986 {
10987 pSetComp(syz->m[i],0);
10988 if(pIsConstant(pHead(syz->m[i])))
10989 {
10990 pSetCoeff(mindegmon, nCopy(syz->m[i]->coef));
10991 found = TRUE;
10992 break;
10993 }
10994 }
10995 }
10996 id_Delete(&syz,QQ_ring);
10997 if (found == FALSE)
10998 {
10999 rChangeCurrRing(origR);
11000 idDelete(&monred);
11001 idDelete(&F);
11002 id_Delete(&II,QQ_ring);
11003 id_Delete(&one,QQ_ring);
11004 rDelete(QQ_ring);
11005 return NULL;
11006 }
11007 rChangeCurrRing(origR);
11008 nMapFunc nMap2 = n_SetMap(QQ_ring->cf, origR->cf);
11009 pmon = prMapR(mindegmon, nMap2, QQ_ring, origR);
11010 idDelete(&monred);
11011 idDelete(&F);
11012 id_Delete(&II,QQ_ring);
11013 id_Delete(&one,QQ_ring);
11014 id_Delete(&syz,QQ_ring);
11015 rDelete(QQ_ring);
11016 return pmon;
11017 }
11018 }
11019 }
11020 rChangeCurrRing(origR);
11021 idDelete(&monred);
11022 idDelete(&F);
11023 id_Delete(&II,QQ_ring);
11024 id_Delete(&one,QQ_ring);
11025 rDelete(QQ_ring);
11026 return NULL;
11027}
11028#endif
11029
11030#ifdef HAVE_RINGS
11031/*!
11032 used for GB over ZZ: intermediate reduction by monomial elements
11033 background: any known constant element of ideal suppresses
11034 intermediate coefficient swell
11035*/
11037{
11038 if(!nCoeff_is_Z(currRing->cf))
11039 return;
11040 poly pH = h->GetP();
11041 poly p,pp;
11042 p = pH;
11043 bool deleted = FALSE, ok = FALSE;
11044 for(int i = 0; i<=strat->sl; i++)
11045 {
11046 p = pH;
11047 if(pNext(strat->S[i]) == NULL)
11048 {
11049 //pWrite(p);
11050 //pWrite(strat->S[i]);
11051 while(ok == FALSE && p != NULL)
11052 {
11053 if(pLmDivisibleBy(strat->S[i], p)
11054#ifdef HAVE_SHIFTBBA
11055 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], p))
11056#endif
11057 )
11058 {
11059 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11060 p_SetCoeff(p,dummy,currRing);
11061 }
11062 if(nIsZero(p->coef))
11063 {
11064 pLmDelete(&p);
11065 h->p = p;
11066 deleted = TRUE;
11067 }
11068 else
11069 {
11070 ok = TRUE;
11071 }
11072 }
11073 if (p!=NULL)
11074 {
11075 pp = pNext(p);
11076 while(pp != NULL)
11077 {
11078 if(pLmDivisibleBy(strat->S[i], pp)
11079#ifdef HAVE_SHIFTBBA
11080 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->S[i], pp))
11081#endif
11082 )
11083 {
11084 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11085 p_SetCoeff(pp,dummy,currRing);
11086 if(nIsZero(pp->coef))
11087 {
11088 pLmDelete(&pNext(p));
11089 pp = pNext(p);
11090 deleted = TRUE;
11091 }
11092 else
11093 {
11094 p = pp;
11095 pp = pNext(p);
11096 }
11097 }
11098 else
11099 {
11100 p = pp;
11101 pp = pNext(p);
11102 }
11103 }
11104 }
11105 }
11106 }
11107 h->SetLmCurrRing();
11108 if((deleted)&&(h->p!=NULL))
11109 strat->initEcart(h);
11110}
11111
11113{
11114 if(!nCoeff_is_Z(currRing->cf))
11115 return;
11116 poly hSig = h->sig;
11117 poly pH = h->GetP();
11118 poly p,pp;
11119 p = pH;
11120 bool deleted = FALSE, ok = FALSE;
11121 for(int i = 0; i<=strat->sl; i++)
11122 {
11123 p = pH;
11124 if(pNext(strat->S[i]) == NULL)
11125 {
11126 while(ok == FALSE && p!=NULL)
11127 {
11128 if(pLmDivisibleBy(strat->S[i], p))
11129 {
11130 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11131 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11132 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11133 {
11134 number dummy = n_IntMod(p->coef, strat->S[i]->coef, currRing->cf);
11135 p_SetCoeff(p,dummy,currRing);
11136 }
11137 pDelete(&sigMult);
11138 }
11139 if(nIsZero(p->coef))
11140 {
11141 pLmDelete(&p);
11142 h->p = p;
11143 deleted = TRUE;
11144 }
11145 else
11146 {
11147 ok = TRUE;
11148 }
11149 }
11150 if(p == NULL)
11151 return;
11152 pp = pNext(p);
11153 while(pp != NULL)
11154 {
11155 if(pLmDivisibleBy(strat->S[i], pp))
11156 {
11157 poly sigMult = pDivideM(pHead(p),pHead(strat->S[i]));
11158 sigMult = ppMult_mm(sigMult,pCopy(strat->sig[i]));
11159 if(sigMult!= NULL && pLtCmp(hSig,sigMult) == 1)
11160 {
11161 number dummy = n_IntMod(pp->coef, strat->S[i]->coef, currRing->cf);
11162 p_SetCoeff(pp,dummy,currRing);
11163 if(nIsZero(pp->coef))
11164 {
11165 pLmDelete(&pNext(p));
11166 pp = pNext(p);
11167 deleted = TRUE;
11168 }
11169 else
11170 {
11171 p = pp;
11172 pp = pNext(p);
11173 }
11174 }
11175 else
11176 {
11177 p = pp;
11178 pp = pNext(p);
11179 }
11180 pDelete(&sigMult);
11181 }
11182 else
11183 {
11184 p = pp;
11185 pp = pNext(p);
11186 }
11187 }
11188 }
11189 }
11190 h->SetLmCurrRing();
11191 if(deleted)
11192 strat->initEcart(h);
11193
11194}
11195
11196/*!
11197 used for GB over ZZ: final reduction by constant elements
11198 background: any known constant element of ideal suppresses
11199 intermediate coefficient swell and beautifies output
11200*/
11202{
11203 assume(strat->tl<0); /* can only be called with no elements in T:
11204 i.e. after exitBuchMora */
11205 /* do not use strat->S, strat->sl as they may be out of sync*/
11206 if(!nCoeff_is_Z(currRing->cf))
11207 return;
11208 poly p,pp;
11209 for(int j = 0; j<IDELEMS(strat->Shdl); j++)
11210 {
11211 if((strat->Shdl->m[j]!=NULL)&&(pNext(strat->Shdl->m[j]) == NULL))
11212 {
11213 for(int i = 0; i<IDELEMS(strat->Shdl); i++)
11214 {
11215 if((i != j) && (strat->Shdl->m[i] != NULL))
11216 {
11217 p = strat->Shdl->m[i];
11218 while((p!=NULL) && (pLmDivisibleBy(strat->Shdl->m[j], p)
11219#if HAVE_SHIFTBBA
11220 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], p))
11221#endif
11222 ))
11223 {
11224 number dummy = n_IntMod(p->coef, strat->Shdl->m[j]->coef, currRing->cf);
11225 if (!nEqual(dummy,p->coef))
11226 {
11227 if (nIsZero(dummy))
11228 {
11229 nDelete(&dummy);
11230 pLmDelete(&strat->Shdl->m[i]);
11231 p=strat->Shdl->m[i];
11232 }
11233 else
11234 {
11235 p_SetCoeff(p,dummy,currRing);
11236 break;
11237 }
11238 }
11239 else
11240 {
11241 nDelete(&dummy);
11242 break;
11243 }
11244 }
11245 if (p!=NULL)
11246 {
11247 pp = pNext(p);
11248 while(pp != NULL)
11249 {
11250 if(pLmDivisibleBy(strat->Shdl->m[j], pp)
11251#if HAVE_SHIFTBBA
11252 || (rIsLPRing(currRing) && pLPLmDivisibleBy(strat->Shdl->m[j], pp))
11253#endif
11254 )
11255 {
11256 number dummy = n_IntMod(pp->coef, strat->Shdl->m[j]->coef, currRing->cf);
11257 if (!nEqual(dummy,pp->coef))
11258 {
11259 p_SetCoeff(pp,dummy,currRing);
11260 if(nIsZero(pp->coef))
11261 {
11262 pLmDelete(&pNext(p));
11263 pp = pNext(p);
11264 }
11265 else
11266 {
11267 p = pp;
11268 pp = pNext(p);
11269 }
11270 }
11271 else
11272 {
11273 nDelete(&dummy);
11274 p = pp;
11275 pp = pNext(p);
11276 }
11277 }
11278 else
11279 {
11280 p = pp;
11281 pp = pNext(p);
11282 }
11283 }
11284 }
11285 }
11286 }
11287 //idPrint(strat->Shdl);
11288 }
11289 }
11290 idSkipZeroes(strat->Shdl);
11291}
11292#endif
11293
11294BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject* T, unsigned long expbound)
11295{
11296 assume((strat->tailRing == currRing) || (strat->tailRing->bitmask <= currRing->bitmask));
11297 /* initial setup or extending */
11298
11299 if (rIsLPRing(currRing)) return TRUE;
11300 if (expbound == 0) expbound = strat->tailRing->bitmask << 1;
11301 if (expbound >= currRing->bitmask) return FALSE;
11302 strat->overflow=FALSE;
11303 ring new_tailRing = rModifyRing(currRing,
11304 // Hmmm .. the condition pFDeg == p_Deg
11305 // might be too strong
11306 (strat->homog && currRing->pFDeg == p_Deg && !(rField_is_Ring(currRing))), // omit degree
11307 (strat->ak==0), // omit_comp if the input is an ideal
11308 expbound); // exp_limit
11309
11310 if (new_tailRing == currRing) return TRUE;
11311
11312 strat->pOrigFDeg_TailRing = new_tailRing->pFDeg;
11313 strat->pOrigLDeg_TailRing = new_tailRing->pLDeg;
11314
11315 if (currRing->pFDeg != currRing->pFDegOrig)
11316 {
11317 new_tailRing->pFDeg = currRing->pFDeg;
11318 new_tailRing->pLDeg = currRing->pLDeg;
11319 }
11320
11321 if (TEST_OPT_PROT)
11322 Print("[%lu:%d", (unsigned long) new_tailRing->bitmask, new_tailRing->ExpL_Size);
11323 kTest_TS(strat);
11324 assume(new_tailRing != strat->tailRing);
11325 pShallowCopyDeleteProc p_shallow_copy_delete
11326 = pGetShallowCopyDeleteProc(strat->tailRing, new_tailRing);
11327
11328 omBin new_tailBin = omGetStickyBinOfBin(new_tailRing->PolyBin);
11329
11330 int i;
11331 for (i=0; i<=strat->tl; i++)
11332 {
11333 strat->T[i].ShallowCopyDelete(new_tailRing, new_tailBin,
11334 p_shallow_copy_delete);
11335 }
11336 for (i=0; i<=strat->Ll; i++)
11337 {
11338 assume(strat->L[i].p != NULL);
11339 if (pNext(strat->L[i].p) != strat->tail)
11340 strat->L[i].ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11341 }
11342 if ((strat->P.t_p != NULL) ||
11343 ((strat->P.p != NULL) && pNext(strat->P.p) != strat->tail))
11344 strat->P.ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11345
11346 if ((L != NULL) && (L->tailRing != new_tailRing))
11347 {
11348 if (L->i_r < 0)
11349 L->ShallowCopyDelete(new_tailRing, p_shallow_copy_delete);
11350 else
11351 {
11352 assume(L->i_r <= strat->tl);
11353 TObject* t_l = strat->R[L->i_r];
11354 assume(t_l != NULL);
11355 L->tailRing = new_tailRing;
11356 L->p = t_l->p;
11357 L->t_p = t_l->t_p;
11358 L->max_exp = t_l->max_exp;
11359 }
11360 }
11361
11362 if ((T != NULL) && (T->tailRing != new_tailRing && T->i_r < 0))
11363 T->ShallowCopyDelete(new_tailRing, new_tailBin, p_shallow_copy_delete);
11364
11365 omMergeStickyBinIntoBin(strat->tailBin, strat->tailRing->PolyBin);
11366 if (strat->tailRing != currRing)
11368
11369 strat->tailRing = new_tailRing;
11370 strat->tailBin = new_tailBin;
11372 = pGetShallowCopyDeleteProc(currRing, new_tailRing);
11373
11374 if (strat->kNoether != NULL)
11375 {
11376 if (strat->t_kNoether != NULL)
11377 p_LmFree(strat->t_kNoether, strat->tailRing);
11378 strat->t_kNoether=k_LmInit_currRing_2_tailRing(strat->kNoether, new_tailRing);
11379 }
11380
11381 kTest_TS(strat);
11382 if (TEST_OPT_PROT)
11383 PrintS("]");
11384 return TRUE;
11385}
11386
11388{
11389 unsigned long l = 0;
11390 int i;
11391 long e;
11392
11393 assume(strat->tailRing == currRing);
11394
11395 for (i=0; i<= strat->Ll; i++)
11396 {
11397 l = p_GetMaxExpL(strat->L[i].p, currRing, l);
11398 }
11399 for (i=0; i<=strat->tl; i++)
11400 {
11401 // Hmm ... this we could do in one Step
11402 l = p_GetMaxExpL(strat->T[i].p, currRing, l);
11403 }
11405 {
11406 l *= 2;
11407 }
11408 e = p_GetMaxExp(l, currRing);
11409 if (e <= 1) e = 2;
11410 if (rIsLPRing(currRing)) e = 1;
11411
11412 kStratChangeTailRing(strat, NULL, NULL, e);
11413}
11414
11415ring sbaRing (kStrategy strat, const ring r, BOOLEAN /*complete*/, int /*sgn*/)
11416{
11417 int n = rBlocks(r); // Including trailing zero!
11418 // if sbaOrder == 1 => use (C,monomial order from r)
11419 if (strat->sbaOrder == 1)
11420 {
11421 if (r->order[0] == ringorder_C || r->order[0] == ringorder_c)
11422 {
11423 return r;
11424 }
11425 ring res = rCopy0(r, TRUE, FALSE);
11426 res->order = (rRingOrder_t *)omAlloc0((n+1)*sizeof(rRingOrder_t));
11427 res->block0 = (int *)omAlloc0((n+1)*sizeof(int));
11428 res->block1 = (int *)omAlloc0((n+1)*sizeof(int));
11429 int **wvhdl = (int **)omAlloc0((n+1)*sizeof(int*));
11430 res->wvhdl = wvhdl;
11431 for (int i=1; i<n; i++)
11432 {
11433 res->order[i] = r->order[i-1];
11434 res->block0[i] = r->block0[i-1];
11435 res->block1[i] = r->block1[i-1];
11436 res->wvhdl[i] = r->wvhdl[i-1];
11437 }
11438
11439 // new 1st block
11440 res->order[0] = ringorder_C; // Prefix
11441 // removes useless secondary component order if defined in old ring
11442 for (int i=rBlocks(res); i>0; --i)
11443 {
11444 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11445 {
11446 res->order[i] = (rRingOrder_t)0;
11447 }
11448 }
11449 rComplete(res, 1);
11450#ifdef HAVE_PLURAL
11451 if (rIsPluralRing(r))
11452 {
11453 if ( nc_rComplete(r, res, false) ) // no qideal!
11454 {
11455#ifndef SING_NDEBUG
11456 WarnS("error in nc_rComplete");
11457#endif
11458 // cleanup?
11459
11460 // rDelete(res);
11461 // return r;
11462
11463 // just go on..
11464 }
11465 }
11466#endif
11467 strat->tailRing = res;
11468 return (res);
11469 }
11470 // if sbaOrder == 3 => degree - position - ring order
11471 if (strat->sbaOrder == 3)
11472 {
11473 ring res = rCopy0(r, TRUE, FALSE);
11474 res->order = (rRingOrder_t*)omAlloc0((n+2)*sizeof(rRingOrder_t));
11475 res->block0 = (int *)omAlloc0((n+2)*sizeof(int));
11476 res->block1 = (int *)omAlloc0((n+2)*sizeof(int));
11477 int **wvhdl = (int **)omAlloc0((n+2)*sizeof(int*));
11478 res->wvhdl = wvhdl;
11479 for (int i=2; i<n+2; i++)
11480 {
11481 res->order[i] = r->order[i-2];
11482 res->block0[i] = r->block0[i-2];
11483 res->block1[i] = r->block1[i-2];
11484 res->wvhdl[i] = r->wvhdl[i-2];
11485 }
11486
11487 // new 1st block
11488 res->order[0] = ringorder_a; // Prefix
11489 res->block0[0] = 1;
11490 res->wvhdl[0] = (int *)omAlloc(res->N*sizeof(int));
11491 for (int i=0; i<res->N; ++i)
11492 res->wvhdl[0][i] = 1;
11493 res->block1[0] = si_min(res->N, rVar(res));
11494 // new 2nd block
11495 res->order[1] = ringorder_C; // Prefix
11496 res->wvhdl[1] = NULL;
11497 // removes useless secondary component order if defined in old ring
11498 for (int i=rBlocks(res); i>1; --i)
11499 {
11500 if (res->order[i] == ringorder_C || res->order[i] == ringorder_c)
11501 {
11502 res->order[i] = (rRingOrder_t)0;
11503 }
11504 }
11505 rComplete(res, 1);
11506#ifdef HAVE_PLURAL
11507 if (rIsPluralRing(r))
11508 {
11509 if ( nc_rComplete(r, res, false) ) // no qideal!
11510 {
11511#ifndef SING_NDEBUG
11512 WarnS("error in nc_rComplete");
11513#endif
11514 // cleanup?
11515
11516 // rDelete(res);
11517 // return r;
11518
11519 // just go on..
11520 }
11521 }
11522#endif
11523 strat->tailRing = res;
11524 return (res);
11525 }
11526
11527 // not sbaOrder == 1 => use Schreyer order
11528 // this is done by a trick when initializing the signatures
11529 // in initSLSba():
11530 // Instead of using the signature 1e_i for F->m[i], we start
11531 // with the signature LM(F->m[i])e_i for F->m[i]. Doing this we get a
11532 // Schreyer order w.r.t. the underlying monomial order.
11533 // => we do not need to change the underlying polynomial ring at all!
11534
11535 // UPDATE/NOTE/TODO: use induced Schreyer ordering 'IS'!!!!????
11536
11537 /*
11538 else
11539 {
11540 ring res = rCopy0(r, FALSE, FALSE);
11541 // Create 2 more blocks for prefix/suffix:
11542 res->order=(int *)omAlloc0((n+2)*sizeof(int)); // 0 .. n+1
11543 res->block0=(int *)omAlloc0((n+2)*sizeof(int));
11544 res->block1=(int *)omAlloc0((n+2)*sizeof(int));
11545 int ** wvhdl =(int **)omAlloc0((n+2)*sizeof(int**));
11546
11547 // Encapsulate all existing blocks between induced Schreyer ordering markers: prefix and suffix!
11548 // Note that prefix and suffix have the same ringorder marker and only differ in block[] parameters!
11549
11550 // new 1st block
11551 int j = 0;
11552 res->order[j] = ringorder_IS; // Prefix
11553 res->block0[j] = res->block1[j] = 0;
11554 // wvhdl[j] = NULL;
11555 j++;
11556
11557 for(int i = 0; (i < n) && (r->order[i] != 0); i++, j++) // i = [0 .. n-1] <- non-zero old blocks
11558 {
11559 res->order [j] = r->order [i];
11560 res->block0[j] = r->block0[i];
11561 res->block1[j] = r->block1[i];
11562
11563 if (r->wvhdl[i] != NULL)
11564 {
11565 wvhdl[j] = (int*) omMemDup(r->wvhdl[i]);
11566 } // else wvhdl[j] = NULL;
11567 }
11568
11569 // new last block
11570 res->order [j] = ringorder_IS; // Suffix
11571 res->block0[j] = res->block1[j] = sgn; // Sign of v[o]: 1 for C, -1 for c
11572 // wvhdl[j] = NULL;
11573 j++;
11574
11575 // res->order [j] = 0; // The End!
11576 res->wvhdl = wvhdl;
11577
11578 // j == the last zero block now!
11579 assume(j == (n+1));
11580 assume(res->order[0]==ringorder_IS);
11581 assume(res->order[j-1]==ringorder_IS);
11582 assume(res->order[j]==0);
11583
11584 if (complete)
11585 {
11586 rComplete(res, 1);
11587
11588#ifdef HAVE_PLURAL
11589 if (rIsPluralRing(r))
11590 {
11591 if ( nc_rComplete(r, res, false) ) // no qideal!
11592 {
11593 }
11594 }
11595 assume(rIsPluralRing(r) == rIsPluralRing(res));
11596#endif
11597
11598
11599#ifdef HAVE_PLURAL
11600 ring old_ring = r;
11601
11602#endif
11603
11604 if (r->qideal!=NULL)
11605 {
11606 res->qideal= idrCopyR_NoSort(r->qideal, r, res);
11607
11608 assume(idRankFreeModule(res->qideal, res) == 0);
11609
11610#ifdef HAVE_PLURAL
11611 if( rIsPluralRing(res) )
11612 if( nc_SetupQuotient(res, r, true) )
11613 {
11614 // WarnS("error in nc_SetupQuotient"); // cleanup? rDelete(res); return r; // just go on...?
11615 }
11616
11617#endif
11618 assume(idRankFreeModule(res->qideal, res) == 0);
11619 }
11620
11621#ifdef HAVE_PLURAL
11622 assume((res->qideal==NULL) == (old_ring->qideal==NULL));
11623 assume(rIsPluralRing(res) == rIsPluralRing(old_ring));
11624 assume(rIsSCA(res) == rIsSCA(old_ring));
11625 assume(ncRingType(res) == ncRingType(old_ring));
11626#endif
11627 }
11628 strat->tailRing = res;
11629 return res;
11630 }
11631 */
11632
11633 assume(FALSE);
11634 return(NULL);
11635}
11636
11638{
11639 memset(this, 0, sizeof(skStrategy));
11640 strat_nr++;
11641 nr=strat_nr;
11643 P.tailRing = currRing;
11644 tl = -1;
11645 sl = -1;
11646#ifdef HAVE_LM_BIN
11648#endif
11649#ifdef HAVE_TAIL_BIN
11651#endif
11652 pOrigFDeg = currRing->pFDeg;
11653 pOrigLDeg = currRing->pLDeg;
11654}
11655
11656
11658{
11659 if (lmBin != NULL)
11661 if (tailBin != NULL)// && !rField_is_Ring(currRing))
11663 ((tailRing != NULL) ? tailRing->PolyBin:
11664 currRing->PolyBin));
11665 if (t_kNoether != NULL)
11667
11668 if (currRing != tailRing)
11671}
11672
11673#if 0
11674Timings for the different possibilities of posInT:
11675 T15 EDL DL EL L 1-2-3
11676Gonnet 43.26 42.30 38.34 41.98 38.40 100.04
11677Hairer_2_1 1.11 1.15 1.04 1.22 1.08 4.7
11678Twomat3 1.62 1.69 1.70 1.65 1.54 11.32
11679ahml 4.48 4.03 4.03 4.38 4.96 26.50
11680c7 15.02 13.98 15.16 13.24 17.31 47.89
11681c8 505.09 407.46 852.76 413.21 499.19 n/a
11682f855 12.65 9.27 14.97 8.78 14.23 33.12
11683gametwo6 11.47 11.35 14.57 11.20 12.02 35.07
11684gerhard_3 2.73 2.83 2.93 2.64 3.12 6.24
11685ilias13 22.89 22.46 24.62 20.60 23.34 53.86
11686noon8 40.68 37.02 37.99 36.82 35.59 877.16
11687rcyclic_19 48.22 42.29 43.99 45.35 51.51 204.29
11688rkat9 82.37 79.46 77.20 77.63 82.54 267.92
11689schwarz_11 16.46 16.81 16.76 16.81 16.72 35.56
11690test016 16.39 14.17 14.40 13.50 14.26 34.07
11691test017 34.70 36.01 33.16 35.48 32.75 71.45
11692test042 10.76 10.99 10.27 11.57 10.45 23.04
11693test058 6.78 6.75 6.51 6.95 6.22 9.47
11694test066 10.71 10.94 10.76 10.61 10.56 19.06
11695test073 10.75 11.11 10.17 10.79 8.63 58.10
11696test086 12.23 11.81 12.88 12.24 13.37 66.68
11697test103 5.05 4.80 5.47 4.64 4.89 11.90
11698test154 12.96 11.64 13.51 12.46 14.61 36.35
11699test162 65.27 64.01 67.35 59.79 67.54 196.46
11700test164 7.50 6.50 7.68 6.70 7.96 17.13
11701virasoro 3.39 3.50 3.35 3.47 3.70 7.66
11702#endif
11703
11704
11705//#ifdef HAVE_MORE_POS_IN_T
11706#if 1
11707// determines the position based on: 1.) Ecart 2.) FDeg 3.) pLength
11709{
11710
11711 if (length==-1) return 0;
11712
11713 int o = p.ecart;
11714 int op=p.GetpFDeg();
11715 int ol = p.GetpLength();
11716
11717 if (set[length].ecart < o)
11718 return length+1;
11719 if (set[length].ecart == o)
11720 {
11721 int oo=set[length].GetpFDeg();
11722 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11723 return length+1;
11724 }
11725
11726 int i;
11727 int an = 0;
11728 int en= length;
11729 loop
11730 {
11731 if (an >= en-1)
11732 {
11733 if (set[an].ecart > o)
11734 return an;
11735 if (set[an].ecart == o)
11736 {
11737 int oo=set[an].GetpFDeg();
11738 if((oo > op)
11739 || ((oo==op) && (set[an].pLength > ol)))
11740 return an;
11741 }
11742 return en;
11743 }
11744 i=(an+en) / 2;
11745 if (set[i].ecart > o)
11746 en=i;
11747 else if (set[i].ecart == o)
11748 {
11749 int oo=set[i].GetpFDeg();
11750 if ((oo > op)
11751 || ((oo == op) && (set[i].pLength > ol)))
11752 en=i;
11753 else
11754 an=i;
11755 }
11756 else
11757 an=i;
11758 }
11759}
11760
11761// determines the position based on: 1.) FDeg 2.) pLength
11762int posInT_FDegpLength(const TSet set,const int length,LObject &p)
11763{
11764
11765 if (length==-1) return 0;
11766
11767 int op=p.GetpFDeg();
11768 int ol = p.GetpLength();
11769
11770 int oo=set[length].GetpFDeg();
11771 if ((oo < op) || ((oo==op) && (set[length].length < ol)))
11772 return length+1;
11773
11774 int i;
11775 int an = 0;
11776 int en= length;
11777 loop
11778 {
11779 if (an >= en-1)
11780 {
11781 int oo=set[an].GetpFDeg();
11782 if((oo > op)
11783 || ((oo==op) && (set[an].pLength > ol)))
11784 return an;
11785 return en;
11786 }
11787 i=(an+en) / 2;
11788 int oo=set[i].GetpFDeg();
11789 if ((oo > op)
11790 || ((oo == op) && (set[i].pLength > ol)))
11791 en=i;
11792 else
11793 an=i;
11794 }
11795}
11796
11797
11798// determines the position based on: 1.) pLength
11799int posInT_pLength(const TSet set,const int length,LObject &p)
11800{
11801 int ol = p.GetpLength();
11802 if (length==-1)
11803 return 0;
11804 if (set[length].length<p.length)
11805 return length+1;
11806
11807 int i;
11808 int an = 0;
11809 int en= length;
11810
11811 loop
11812 {
11813 if (an >= en-1)
11814 {
11815 if (set[an].pLength>ol) return an;
11816 return en;
11817 }
11818 i=(an+en) / 2;
11819 if (set[i].pLength>ol) en=i;
11820 else an=i;
11821 }
11822}
11823#endif
11824
11825// kstd1.cc:
11826int redFirst (LObject* h,kStrategy strat);
11827int redEcart (LObject* h,kStrategy strat);
11828void enterSMora (LObject &p,int atS,kStrategy strat, int atR=-1);
11829void enterSMoraNF (LObject &p,int atS,kStrategy strat, int atR=-1);
11830// ../Singular/misc.cc:
11831extern char * showOption();
11832
11834{
11835 PrintS("red: ");
11836 if (strat->red==redFirst) PrintS("redFirst\n");
11837 else if (strat->red==redHoney) PrintS("redHoney\n");
11838 else if (strat->red==redEcart) PrintS("redEcart\n");
11839 else if (strat->red==redHomog) PrintS("redHomog\n");
11840 else if (strat->red==redLazy) PrintS("redLazy\n");
11841 else if (strat->red==redLiftstd) PrintS("redLiftstd\n");
11842 else Print("%p\n",(void*)strat->red);
11843 PrintS("posInT: ");
11844 if (strat->posInT==posInT0) PrintS("posInT0\n");
11845 else if (strat->posInT==posInT1) PrintS("posInT1\n");
11846 else if (strat->posInT==posInT11) PrintS("posInT11\n");
11847 else if (strat->posInT==posInT110) PrintS("posInT110\n");
11848 else if (strat->posInT==posInT13) PrintS("posInT13\n");
11849 else if (strat->posInT==posInT15) PrintS("posInT15\n");
11850 else if (strat->posInT==posInT17) PrintS("posInT17\n");
11851 else if (strat->posInT==posInT17_c) PrintS("posInT17_c\n");
11852 else if (strat->posInT==posInT19) PrintS("posInT19\n");
11853 else if (strat->posInT==posInT2) PrintS("posInT2\n");
11854 #ifdef HAVE_RINGS
11855 else if (strat->posInT==posInT11Ring) PrintS("posInT11Ring\n");
11856 else if (strat->posInT==posInT110Ring) PrintS("posInT110Ring\n");
11857 else if (strat->posInT==posInT15Ring) PrintS("posInT15Ring\n");
11858 else if (strat->posInT==posInT17Ring) PrintS("posInT17Ring\n");
11859 else if (strat->posInT==posInT17_cRing) PrintS("posInT17_cRing\n");
11860 #endif
11861#ifdef HAVE_MORE_POS_IN_T
11862 else if (strat->posInT==posInT_EcartFDegpLength) PrintS("posInT_EcartFDegpLength\n");
11863 else if (strat->posInT==posInT_FDegpLength) PrintS("posInT_FDegpLength\n");
11864 else if (strat->posInT==posInT_pLength) PrintS("posInT_pLength\n");
11865#endif
11866 else if (strat->posInT==posInT_EcartpLength) PrintS("posInT_EcartpLength\n");
11867 else if (strat->posInT==posInTrg0) PrintS("posInTrg0\n");
11868 else Print("%p\n",(void*)strat->posInT);
11869 PrintS("posInL: ");
11870 if (strat->posInL==posInL0) PrintS("posInL0\n");
11871 else if (strat->posInL==posInL10) PrintS("posInL10\n");
11872 else if (strat->posInL==posInL11) PrintS("posInL11\n");
11873 else if (strat->posInL==posInL110) PrintS("posInL110\n");
11874 else if (strat->posInL==posInL13) PrintS("posInL13\n");
11875 else if (strat->posInL==posInL15) PrintS("posInL15\n");
11876 else if (strat->posInL==posInL17) PrintS("posInL17\n");
11877 else if (strat->posInL==posInL17_c) PrintS("posInL17_c\n");
11878 #ifdef HAVE_RINGS
11879 else if (strat->posInL==posInL0) PrintS("posInL0Ring\n");
11880 else if (strat->posInL==posInL11Ring) PrintS("posInL11Ring\n");
11881 else if (strat->posInL==posInL11Ringls) PrintS("posInL11Ringls\n");
11882 else if (strat->posInL==posInL110Ring) PrintS("posInL110Ring\n");
11883 else if (strat->posInL==posInL15Ring) PrintS("posInL15Ring\n");
11884 else if (strat->posInL==posInL17Ring) PrintS("posInL17Ring\n");
11885 else if (strat->posInL==posInL17_cRing) PrintS("posInL17_cRing\n");
11886 #endif
11887 else if (strat->posInL==posInLSpecial) PrintS("posInLSpecial\n");
11888 else if (strat->posInL==posInLrg0) PrintS("posInLrg0\n");
11889 else Print("%p\n",(void*)strat->posInL);
11890 PrintS("enterS: ");
11891 if (strat->enterS==enterSBba) PrintS("enterSBba\n");
11892 else if (strat->enterS==enterSMora) PrintS("enterSMora\n");
11893 else if (strat->enterS==enterSMoraNF) PrintS("enterSMoraNF\n");
11894 else Print("%p\n",(void*)strat->enterS);
11895 PrintS("initEcart: ");
11896 if (strat->initEcart==initEcartBBA) PrintS("initEcartBBA\n");
11897 else if (strat->initEcart==initEcartNormal) PrintS("initEcartNormal\n");
11898 else Print("%p\n",(void*)strat->initEcart);
11899 PrintS("initEcartPair: ");
11900 if (strat->initEcartPair==initEcartPairBba) PrintS("initEcartPairBba\n");
11901 else if (strat->initEcartPair==initEcartPairMora) PrintS("initEcartPairMora\n");
11902 else Print("%p\n",(void*)strat->initEcartPair);
11903 Print("homog=%d, LazyDegree=%d, LazyPass=%d, ak=%d,\n",
11904 strat->homog, strat->LazyDegree,strat->LazyPass, strat->ak);
11905 Print("honey=%d, sugarCrit=%d, Gebauer=%d, noTailReduction=%d, use_buckets=%d\n",
11906 strat->honey,strat->sugarCrit,strat->Gebauer,strat->noTailReduction,strat->use_buckets);
11907 PrintS("chainCrit: ");
11908 if (strat->chainCrit==chainCritNormal) PrintS("chainCritNormal\n");
11909 else if (strat->chainCrit==chainCritOpt_1) PrintS("chainCritOpt_1\n");
11910 else Print("%p\n",(void*)strat->chainCrit);
11911 Print("posInLDependsOnLength=%d\n",
11912 strat->posInLDependsOnLength);
11914 PrintS("LDeg: ");
11915 if (currRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11916 else if (currRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11917 else if (currRing->pLDeg==pLDegb) PrintS("pLDegb");
11918 else if (currRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11919 else if (currRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11920 else if (currRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11921 else if (currRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11922 else if (currRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11923 else if (currRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11924 else if (currRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11925 else if (currRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11926 else if (currRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11927 else Print("? (%lx)", (long)currRing->pLDeg);
11928 PrintS(" / ");
11929 if (strat->tailRing->pLDeg==pLDeg0) PrintS("pLDeg0");
11930 else if (strat->tailRing->pLDeg==pLDeg0c) PrintS("pLDeg0c");
11931 else if (strat->tailRing->pLDeg==pLDegb) PrintS("pLDegb");
11932 else if (strat->tailRing->pLDeg==pLDeg1) PrintS("pLDeg1");
11933 else if (strat->tailRing->pLDeg==pLDeg1c) PrintS("pLDeg1c");
11934 else if (strat->tailRing->pLDeg==pLDeg1_Deg) PrintS("pLDeg1_Deg");
11935 else if (strat->tailRing->pLDeg==pLDeg1c_Deg) PrintS("pLDeg1c_Deg");
11936 else if (strat->tailRing->pLDeg==pLDeg1_Totaldegree) PrintS("pLDeg1_Totaldegree");
11937 else if (strat->tailRing->pLDeg==pLDeg1c_Totaldegree) PrintS("pLDeg1c_Totaldegree");
11938 else if (strat->tailRing->pLDeg==pLDeg1_WFirstTotalDegree) PrintS("pLDeg1_WFirstTotalDegree");
11939 else if (strat->tailRing->pLDeg==pLDeg1c_WFirstTotalDegree) PrintS("pLDeg1c_WFirstTotalDegree");
11940 else if (strat->tailRing->pLDeg==maxdegreeWecart) PrintS("maxdegreeWecart");
11941 else Print("? (%lx)", (long)strat->tailRing->pLDeg);
11942 PrintLn();
11943 PrintS("currRing->pFDeg: ");
11944 if (currRing->pFDeg==p_Totaldegree) PrintS("p_Totaldegree");
11945 else if (currRing->pFDeg==p_WFirstTotalDegree) PrintS("pWFirstTotalDegree");
11946 else if (currRing->pFDeg==p_Deg) PrintS("p_Deg");
11947 else if (currRing->pFDeg==kHomModDeg) PrintS("kHomModDeg");
11948 else if (currRing->pFDeg==totaldegreeWecart) PrintS("totaldegreeWecart");
11949 else if (currRing->pFDeg==p_WTotaldegree) PrintS("p_WTotaldegree");
11950 else Print("? (%lx)", (long)currRing->pFDeg);
11951 PrintLn();
11952 Print(" syzring:%d, syzComp(strat):%d limit:%d\n",rIsSyzIndexRing(currRing),strat->syzComp,rGetCurrSyzLimit(currRing));
11954 Print(" degBound: %d\n", Kstd1_deg);
11955
11956 if( ecartWeights != NULL )
11957 {
11958 PrintS("ecartWeights: ");
11959 for (int i = rVar(currRing); i > 0; i--)
11960 Print("%hd ", ecartWeights[i]);
11961 PrintLn();
11963 }
11964
11965#ifndef SING_NDEBUG
11967#endif
11968}
11969
11970#ifdef HAVE_SHIFTBBA
11971poly pMove2CurrTail(poly p, kStrategy strat)
11972{
11973 /* assume: p is completely in currRing */
11974 /* produces an object with LM in curring
11975 and TAIL in tailring */
11976 if (pNext(p)!=NULL)
11977 {
11978 pNext(p) = prMoveR(pNext(p), /* src */ currRing, /* dest */ strat->tailRing);
11979 }
11980 return(p);
11981}
11982#endif
11983
11984#ifdef HAVE_SHIFTBBA
11986{
11987 /* assume: p has LM in curring and TAIL in tailring */
11988 /* convert it to complete currRing */
11989
11990 /* check that LM is in currRing */
11992
11993 if (pNext(p)!=NULL)
11994 {
11995 pNext(p) = prMoveR(pNext(p), /* src */ strat->tailRing, /* dest */currRing);
11996 }
11997 return(p);
11998}
11999#endif
12000
12001#ifdef HAVE_SHIFTBBA
12003{
12004 /* restores a poly in currRing from LObject */
12005 LObject h = H;
12006 h.Copy();
12007 poly p;
12008 if (h.p == NULL)
12009 {
12010 if (h.t_p != NULL)
12011 {
12012 p = prMoveR(h.t_p, /* source ring: */ strat->tailRing, /* dest. ring: */ currRing);
12013 return(p);
12014 }
12015 else
12016 {
12017 /* h.tp == NULL -> the object is NULL */
12018 return(NULL);
12019 }
12020 }
12021 /* we're here if h.p != NULL */
12022 if (h.t_p == NULL)
12023 {
12024 /* then h.p is the whole poly in currRing */
12025 p = h.p;
12026 return(p);
12027 }
12028 /* we're here if h.p != NULL and h.t_p != NULL */
12029 // clean h.p, get poly from t_p
12030 pNext(h.p)=NULL;
12031 pLmDelete(&h.p);
12032 p = prMoveR(h.t_p, /* source ring: */ strat->tailRing,
12033 /* dest. ring: */ currRing);
12034 // no need to clean h: we re-used the polys
12035 return(p);
12036}
12037#endif
12038
12039//LObject pCopyp2L(poly p, kStrategy strat)
12040//{
12041 /* creates LObject from the poly in currRing */
12042 /* actually put p into L.p and make L.t_p=NULL : does not work */
12043
12044//}
12045
12046// poly pCopyL2p(LObject H, kStrategy strat)
12047// {
12048// /* restores a poly in currRing from LObject */
12049// LObject h = H;
12050// h.Copy();
12051// poly p;
12052// if (h.p == NULL)
12053// {
12054// if (h.t_p != NULL)
12055// {
12056// p = p_ShallowCopyDelete(h.t_p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12057// return(p);
12058// }
12059// else
12060// {
12061// /* h.tp == NULL -> the object is NULL */
12062// return(NULL);
12063// }
12064// }
12065// /* we're here if h.p != NULL */
12066
12067// if (h.t_p == NULL)
12068// {
12069// /* then h.p is the whole poly in tailRing */
12070// if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12071// {
12072// p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12073// }
12074// return(p);
12075// }
12076// /* we're here if h.p != NULL and h.t_p != NULL */
12077// p = pCopy(pHead(h.p)); // in currRing
12078// if (strat->tailBin != NULL && (pNext(h.p) != NULL))
12079// {
12080// // pNext(p) = p_ShallowCopyDelete(pNext(h.t_p), (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
12081// poly pp = p_Copy(pNext(h.p), strat->tailRing);
12082// // poly p3 = p_Copy(pNext(h.p), currRing); // error
12083// // p_ShallowCopyDelete(pNext(h.p), currRing, strat->tailBin); // the same as pp
12084// poly p5 = p_ShallowCopyDelete(pNext(h.p), strat->tailRing, strat->tailBin);
12085// pNext(p) = p_ShallowCopyDelete(h.t_p, strat->tailRing, strat->tailBin);
12086// poly p4 = p_Copy(h.t_p, strat->tailRing);
12087// // if (p.t_p != NULL) pNext(p.t_p) = pNext(p.p);
12088// }
12089// // pTest(p);
12090// return(p);
12091// }
12092
12093/*2
12094* put the lcm(q,p) into the set B, q is the shift of some s[i]
12095*/
12096#ifdef HAVE_SHIFTBBA
12097static BOOLEAN enterOneStrongPolyShift (poly q, poly p, int /*ecart*/, int /*isFromQ*/, kStrategy strat, int atR, int /*ecartq*/, int /*qisFromQ*/, int shiftcount, int ifromS)
12098{
12099 number d, s, t;
12100 /* assume(atR >= 0); */
12101 assume(ifromS <= strat->sl);
12103 poly m1, m2, gcd;
12104 //printf("\n--------------------------------\n");
12105 //pWrite(p);pWrite(si);
12106 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q), &s, &t, currRing->cf);
12107
12108 if (nIsZero(s) || nIsZero(t)) // evtl. durch divBy tests ersetzen
12109 {
12110 nDelete(&d);
12111 nDelete(&s);
12112 nDelete(&t);
12113 return FALSE;
12114 }
12115
12116 assume(pIsInV(p));
12117
12118 k_GetStrongLeadTerms(p, q, currRing, m1, m2, gcd, strat->tailRing);
12119
12120 /* the V criterion */
12121 if (!pmIsInV(gcd))
12122 {
12123 strat->cv++;
12124 nDelete(&d);
12125 nDelete(&s);
12126 nDelete(&t);
12127 pLmFree(gcd);
12128 return FALSE;
12129 }
12130
12131 // disabled for Letterplace because it is not so easy to check
12132 /* if (!rHasLocalOrMixedOrdering(currRing)) { */
12133 /* unsigned long sev = pGetShortExpVector(gcd); */
12134
12135 /* for (int j = 0; j < strat->sl; j++) { */
12136 /* if (j == i) */
12137 /* continue; */
12138
12139 /* if (n_DivBy(d, pGetCoeff(strat->S[j]), currRing->cf) && */
12140 /* !(strat->sevS[j] & ~sev) && */
12141 /* p_LmDivisibleBy(strat->S[j], gcd, currRing)) { */
12142 /* nDelete(&d); */
12143 /* nDelete(&s); */
12144 /* nDelete(&t); */
12145 /* return FALSE; */
12146 /* } */
12147 /* } */
12148 /* } */
12149
12150 poly m12, m22;
12154 // manually free the coeffs, because pSetCoeff0 is used in the next step
12155 n_Delete(&(m1->coef), currRing->cf);
12156 n_Delete(&(m2->coef), currRing->cf);
12157
12158 //p_Test(m1,strat->tailRing);
12159 //p_Test(m2,strat->tailRing);
12160 /*if(!enterTstrong)
12161 {
12162 while (! kCheckStrongCreation(atR, m1, i, m2, strat) )
12163 {
12164 memset(&(strat->P), 0, sizeof(strat->P));
12165 kStratChangeTailRing(strat);
12166 strat->P = *(strat->R[atR]);
12167 p_LmFree(m1, strat->tailRing);
12168 p_LmFree(m2, strat->tailRing);
12169 p_LmFree(gcd, currRing);
12170 k_GetStrongLeadTerms(p, si, currRing, m1, m2, gcd, strat->tailRing);
12171 }
12172 }*/
12173 pSetCoeff0(m1, s);
12174 pSetCoeff0(m2, t);
12175 pSetCoeff0(gcd, d);
12176 p_Test(m1,strat->tailRing);
12177 p_Test(m2,strat->tailRing);
12178 p_Test(m12,strat->tailRing);
12179 p_Test(m22,strat->tailRing);
12180 assume(pmIsInV(m1));
12181 assume(pmIsInV(m2));
12182 assume(pmIsInV(m12));
12183 assume(pmIsInV(m22));
12184 //printf("\n===================================\n");
12185 //pWrite(m1);pWrite(m2);pWrite(gcd);
12186#ifdef KDEBUG
12187 if (TEST_OPT_DEBUG)
12188 {
12189 // Print("t = %d; s = %d; d = %d\n", nInt(t), nInt(s), nInt(d));
12190 PrintS("m1 = ");
12191 p_wrp(m1, strat->tailRing);
12192 PrintS("m12 = ");
12193 p_wrp(m12, strat->tailRing);
12194 PrintS(" ; m2 = ");
12195 p_wrp(m2, strat->tailRing);
12196 PrintS(" ; m22 = ");
12197 p_wrp(m22, strat->tailRing);
12198 PrintS(" ; gcd = ");
12199 wrp(gcd);
12200 PrintS("\n--- create strong gcd poly: ");
12201 PrintS("\n p: ");
12202 wrp(p);
12203 Print("\n q (strat->S[%d]): ", ifromS);
12204 wrp(q);
12205 PrintS(" ---> ");
12206 }
12207#endif
12208
12209 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);
12210 p_LmDelete(m1, strat->tailRing);
12211 p_LmDelete(m2, strat->tailRing);
12212 p_LmDelete(m12, strat->tailRing);
12213 p_LmDelete(m22, strat->tailRing);
12214
12215 assume(pIsInV(gcd));
12216
12217#ifdef KDEBUG
12218 if (TEST_OPT_DEBUG)
12219 {
12220 wrp(gcd);
12221 PrintLn();
12222 }
12223#endif
12224
12225 LObject h;
12226 h.p = gcd;
12227 h.tailRing = strat->tailRing;
12228 int posx;
12229 strat->initEcart(&h);
12230 h.sev = pGetShortExpVector(h.p);
12231 h.i_r1 = -1;h.i_r2 = -1;
12232 if (currRing!=strat->tailRing)
12233 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12234#if 1
12235 h.p1 = p;
12236 h.p2 = q;
12237#endif
12238 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12239 {
12240 h.i_r2 = kFindInT(h.p1, strat);
12241 h.i_r1 = atR;
12242 }
12243 else
12244 {
12245 h.i_r1 = -1;
12246 h.i_r2 = -1;
12247 }
12248 if (strat->Ll==-1)
12249 posx =0;
12250 else
12251 posx = strat->posInL(strat->L,strat->Ll,&h,strat);
12252
12253 assume(pIsInV(h.p));
12254 assume(pIsInV(h.p1));
12255
12256 enterL(&strat->L,&strat->Ll,&strat->Lmax,h,posx);
12257 return TRUE;
12258}
12259#endif
12260
12261
12262/*2
12263* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i] (ring case)
12264*/
12265#ifdef HAVE_SHIFTBBA
12266static void enterOnePairRingShift (poly q, poly p, int /*ecart*/, int isFromQ, kStrategy strat, int atR, int /*ecartq*/, int qisFromQ, int shiftcount, int ifromS)
12267{
12268 /* assume(atR >= 0); */
12269 /* assume(i<=strat->sl); */
12270 assume(p!=NULL);
12272 assume(pIsInV(p));
12273 #if ALL_VS_JUST
12274 //Over rings, if we construct the strong pair, do not add the spair
12276 {
12277 number s,t,d;
12278 d = n_ExtGcd(pGetCoeff(p), pGetCoeff(q, &s, &t, currRing->cf);
12279
12280 if (!nIsZero(s) && !nIsZero(t)) // evtl. durch divBy tests ersetzen
12281 {
12282 nDelete(&d);
12283 nDelete(&s);
12284 nDelete(&t);
12285 return;
12286 }
12287 nDelete(&d);
12288 nDelete(&s);
12289 nDelete(&t);
12290 }
12291 #endif
12292 int j,compare,compareCoeff;
12293 LObject h;
12294
12295#ifdef KDEBUG
12296 h.ecart=0; h.length=0;
12297#endif
12298 /*- computes the lcm(s[i],p) -*/
12299 if(pHasNotCFRing(p,q))
12300 {
12301 strat->cp++;
12302 return;
12303 }
12304 h.lcm = p_Lcm(p,q,currRing);
12305 pSetCoeff0(h.lcm, n_Lcm(pGetCoeff(p), pGetCoeff(q), currRing->cf));
12306 if (nIsZero(pGetCoeff(h.lcm)))
12307 {
12308 strat->cp++;
12309 pLmDelete(h.lcm);
12310 return;
12311 }
12312
12313 /* the V criterion */
12314 if (!pmIsInV(h.lcm))
12315 {
12316 strat->cv++;
12317 pLmDelete(h.lcm);
12318 return;
12319 }
12320 // basic chain criterion
12321 /*
12322 *the set B collects the pairs of type (S[j],p)
12323 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p) != lcm(r,p)
12324 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12325 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12326 */
12327
12328 for(j = strat->Bl;j>=0;j--)
12329 {
12330 compare=pDivCompRing(strat->B[j].lcm,h.lcm);
12331 compareCoeff = n_DivComp(pGetCoeff(strat->B[j].lcm), pGetCoeff(h.lcm), currRing->cf);
12332 if(compare == pDivComp_EQUAL)
12333 {
12334 //They have the same LM
12335 if(compareCoeff == pDivComp_LESS)
12336 {
12337 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12338 {
12339 strat->c3++;
12340 pLmDelete(h.lcm);
12341 return;
12342 }
12343 break;
12344 }
12345 if(compareCoeff == pDivComp_GREATER)
12346 {
12347 deleteInL(strat->B,&strat->Bl,j,strat);
12348 strat->c3++;
12349 }
12350 if(compareCoeff == pDivComp_EQUAL)
12351 {
12352 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12353 {
12354 strat->c3++;
12355 pLmDelete(h.lcm);
12356 return;
12357 }
12358 break;
12359 }
12360 }
12361 if(compareCoeff == compare || compareCoeff == pDivComp_EQUAL)
12362 {
12363 if(compare == pDivComp_LESS)
12364 {
12365 if ((strat->fromQ==NULL) || (isFromQ==0) || (qisFromQ==0))
12366 {
12367 strat->c3++;
12368 pLmDelete(h.lcm);
12369 return;
12370 }
12371 break;
12372 }
12373 if(compare == pDivComp_GREATER)
12374 {
12375 deleteInL(strat->B,&strat->Bl,j,strat);
12376 strat->c3++;
12377 }
12378 }
12379 }
12380 number s, t;
12381 poly m1, m2, gcd = NULL;
12382 s = pGetCoeff(q);
12383 t = pGetCoeff(p);
12385
12386 poly m12, m22;
12390 // manually free the coeffs, because pSetCoeff0 is used in the next step
12391 n_Delete(&(m1->coef), currRing->cf);
12392 n_Delete(&(m2->coef), currRing->cf);
12393
12394 ksCheckCoeff(&s, &t, currRing->cf);
12395 pSetCoeff0(m1, s);
12396 pSetCoeff0(m2, t);
12397 m2 = pNeg(m2);
12398 p_Test(m1,strat->tailRing);
12399 p_Test(m2,strat->tailRing);
12400 p_Test(m12,strat->tailRing);
12401 p_Test(m22,strat->tailRing);
12402 assume(pmIsInV(m1));
12403 assume(pmIsInV(m2));
12404 assume(pmIsInV(m12));
12405 assume(pmIsInV(m22));
12406 poly pm1 = pp_Mult_mm(pp_mm_Mult(pNext(p), m1, strat->tailRing), m12, strat->tailRing);
12407 poly sim2 = pp_Mult_mm(pp_mm_Mult(pNext(q), m2, strat->tailRing), m22, strat->tailRing);
12408 assume(pIsInV(pm1));
12409 assume(pIsInV(sim2));
12410 p_LmDelete(m1, currRing);
12411 p_LmDelete(m2, currRing);
12412 p_LmDelete(m12, currRing);
12413 p_LmDelete(m22, currRing);
12414 if(sim2 == NULL)
12415 {
12416 if(pm1 == NULL)
12417 {
12418 if(h.lcm != NULL)
12419 {
12420 pLmDelete(h.lcm);
12421 h.lcm=NULL;
12422 }
12423 h.Clear();
12424 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12425 /* if (strat->pairtest==NULL) initPairtest(strat); */
12426 /* strat->pairtest[i] = TRUE; */
12427 /* strat->pairtest[strat->sl+1] = TRUE; */
12428 return;
12429 }
12430 else
12431 {
12432 gcd = pm1;
12433 pm1 = NULL;
12434 }
12435 }
12436 else
12437 {
12438 if((pGetComp(q) == 0) && (0 != pGetComp(p)))
12439 {
12440 p_SetCompP(sim2, pGetComp(p), strat->tailRing);
12441 pSetmComp(sim2);
12442 }
12443 //p_Write(pm1,strat->tailRing);p_Write(sim2,strat->tailRing);
12444 gcd = p_Add_q(pm1, sim2, strat->tailRing);
12445 }
12446 p_Test(gcd, strat->tailRing);
12447 assume(pIsInV(gcd));
12448#ifdef KDEBUG
12449 if (TEST_OPT_DEBUG)
12450 {
12451 wrp(gcd);
12452 PrintLn();
12453 }
12454#endif
12455 h.p = gcd;
12456 h.i_r = -1;
12457 if(h.p == NULL)
12458 {
12459 /* TEMPORARILY DISABLED FOR SHIFTS because there is no i*/
12460 /* if (strat->pairtest==NULL) initPairtest(strat); */
12461 /* strat->pairtest[i] = TRUE; */
12462 /* strat->pairtest[strat->sl+1] = TRUE; */
12463 return;
12464 }
12465 h.tailRing = strat->tailRing;
12466 int posx;
12467 //h.pCleardenom();
12468 //pSetm(h.p);
12469 h.i_r1 = -1;h.i_r2 = -1;
12470 strat->initEcart(&h);
12471 #if 1
12472 h.p1 = p;
12473 h.p2 = q;
12474 #endif
12475 #if 1
12476 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12477 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12478 if (atR >= 0 && shiftcount == 0 && ifromS >= 0)
12479 {
12480 h.i_r2 = kFindInT(h.p1, strat); //strat->S_2_R[i];
12481 h.i_r1 = atR;
12482 }
12483 else
12484 {
12485 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12486 h.i_r1 = -1;
12487 h.i_r2 = -1;
12488 }
12489 #endif
12490 if (strat->Bl==-1)
12491 posx =0;
12492 else
12493 posx = strat->posInL(strat->B,strat->Bl,&h,strat);
12494 h.sev = pGetShortExpVector(h.p);
12495 if (currRing!=strat->tailRing)
12496 h.t_p = k_LmInit_currRing_2_tailRing(h.p, strat->tailRing);
12497
12498 assume(pIsInV(h.p));
12499 assume(pIsInV(h.p1));
12500 assume(h.lcm != NULL);
12501 assume(pIsInV(h.lcm));
12502
12503 enterL(&strat->B,&strat->Bl,&strat->Bmax,h,posx);
12504 kTest_TS(strat);
12505}
12506#endif
12507
12508#ifdef HAVE_SHIFTBBA
12509// adds the strong pair and the normal pair for rings (aka gpoly and spoly)
12510static BOOLEAN enterOneStrongPolyAndEnterOnePairRingShift(poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12511{
12512 enterOneStrongPolyShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "gpoly"
12513 enterOnePairRingShift(q, p, ecart, isFromQ, strat, atR, ecartq, qisFromQ, shiftcount, ifromS); // "spoly"
12514 return FALSE; // TODO: delete q?
12515}
12516#endif
12517
12518#ifdef HAVE_SHIFTBBA
12519// creates if possible (q,p), (shifts(q),p)
12520static 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)
12521{
12522 // note: ecart and isFromQ is for p
12523 assume(q_inS < 0 || strat->S[q_inS] == q); // if q is from S, q_inS should be the index of q in S
12524 assume(pmFirstVblock(p) == 1);
12525 assume(pmFirstVblock(q) == 1);
12526 assume(p_lastVblock == pmLastVblock(p));
12527 assume(q_lastVblock == pmLastVblock(q));
12528
12529 // TODO: is ecartq = 0 still ok?
12530 int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
12531
12532 int q_isFromQ = 0;
12533 if (strat->fromQ != NULL && q_inS >= 0)
12534 q_isFromQ = strat->fromQ[q_inS];
12535
12536 BOOLEAN (*enterPair)(poly, poly, int, int, kStrategy, int, int, int, int, int);
12537#ifdef HAVE_RINGS
12540 else
12541#endif
12542 enterPair = enterOnePairShift;
12543
12544 int degbound = currRing->N/currRing->isLPring;
12545 int neededShift = p_lastVblock - ((pGetComp(p) > 0 || pGetComp(q) > 0) ? 0 : 1); // in the module case, product criterion does not hold
12546 int maxPossibleShift = degbound - q_lastVblock;
12547 int maxShift = si_min(neededShift, maxPossibleShift);
12548 int firstShift = (q == p ? 1 : 0); // do not add (q,p) if q=p
12549 BOOLEAN delete_pair=TRUE;
12550 for (int j = firstShift; j <= maxShift; j++)
12551 {
12552 poly qq = pLPCopyAndShiftLM(q, j);
12553 if (enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, j, q_inS))
12554 {
12555 if (j>0) pLmDelete(qq);
12556 // delete qq, if not it does not enter the pair set
12557 }
12558 else
12559 delete_pair=FALSE;
12560 }
12561
12562#ifdef HAVE_RINGS
12563 if (rField_is_Ring(currRing) && p_lastVblock >= firstShift && p_lastVblock <= maxPossibleShift)
12564 {
12565 // add pairs (m*shifts(q), p) where m is a monomial and the pair has no overlap
12566 for (int j = p_lastVblock; j <= maxPossibleShift; j++)
12567 {
12568 ideal fillers = id_MaxIdeal(j - p_lastVblock, currRing);
12569 for (int k = 0; k < IDELEMS(fillers); k++)
12570 {
12571 poly qq = pLPCopyAndShiftLM(pp_mm_Mult(q, fillers->m[k], currRing), p_lastVblock);
12572 enterPair(qq, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, p_lastVblock, q_inS);
12573 }
12574 idDelete(&fillers);
12575 }
12576 }
12577#endif
12578 return delete_pair;
12579}
12580#endif
12581
12582#ifdef HAVE_SHIFTBBA
12583// creates (q,p), use it when q is already shifted
12584// return TRUE, if (q,p) is discarded
12585static 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)
12586{
12587 // note: ecart and isFromQ is for p
12588 assume(p_inS < 0 || strat->S[p_inS] == p); // if p is from S, p_inS should be the index of p in S
12589 assume(pmFirstVblock(p) == 1);
12590 assume(p_lastVblock == pmLastVblock(p));
12591 assume(q_shift == pmFirstVblock(q) - 1);
12592
12593 // TODO: is ecartp = 0 still ok?
12594 int ecartp = 0; //Hans says it's ok; we're in the homog e:, no ecart
12595
12596 int p_isFromQ = 0;
12597 if (strat->fromQ != NULL && p_inS >= 0)
12598 p_isFromQ = strat->fromQ[p_inS];
12599
12600#ifdef HAVE_RINGS
12602 {
12603 assume(q_shift <= p_lastVblock); // we allow the special case where there is no overlap
12604 return enterOneStrongPolyAndEnterOnePairRingShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12605 }
12606 else
12607#endif
12608 {
12609 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)
12610 return enterOnePairShift(q, p, ecartp, p_isFromQ, strat, -1, ecartq, q_isFromQ, q_shift, -1);
12611 }
12612}
12613#endif
12614
12615
12616#ifdef KDEBUG
12617// enable to print which pairs are considered or discarded and why
12618/* #define CRITERION_DEBUG */
12619#endif
12620/*2
12621* put the pair (q,p) into the set B, ecart=ecart(p), q is the shift of some s[i]
12622* return TRUE, if (q,p) does not enter B
12623*/
12624#ifdef HAVE_SHIFTBBA
12625BOOLEAN enterOnePairShift (poly q, poly p, int ecart, int isFromQ, kStrategy strat, int atR, int ecartq, int qisFromQ, int shiftcount, int ifromS)
12626{
12627#ifdef CRITERION_DEBUG
12628 if (TEST_OPT_DEBUG)
12629 {
12630 PrintS("Consider pair ("); wrp(q); PrintS(", "); wrp(p); PrintS(")"); PrintLn();
12631 // also write the LMs in separate lines:
12632 poly lmq = pHead(q);
12633 poly lmp = pHead(p);
12634 pSetCoeff(lmq, n_Init(1, currRing->cf));
12635 pSetCoeff(lmp, n_Init(1, currRing->cf));
12636 Print(" %s\n", pString(lmq));
12637 Print(" %s\n", pString(lmp));
12638 pLmDelete(lmq);
12639 pLmDelete(lmp);
12640 }
12641#endif
12642
12643 /* Format: q and p are like strat->P.p, so lm in CR, tail in TR */
12644
12645 /* check this Formats: */
12650
12651 /* poly q stays for s[i], ecartq = ecart(q), qisFromQ = applies to q */
12652
12653 int qfromQ = qisFromQ;
12654
12655 /* need additionally: int up_to_degree, poly V0 with the variables in (0) or just the number lV = the length of the first block */
12656
12657 int l,j,compare;
12658 LObject Lp;
12659 Lp.i_r = -1;
12660
12661#ifdef KDEBUG
12662 Lp.ecart=0; Lp.length=0;
12663#endif
12664 /*- computes the lcm(s[i],p) -*/
12665 Lp.lcm = p_Lcm(p,q, currRing); // q is what was strat->S[i], so a poly in LM/TR presentation
12666
12667 /* the V criterion */
12668 if (!pmIsInV(Lp.lcm))
12669 {
12670 strat->cv++; // counter for applying the V criterion
12671 pLmFree(Lp.lcm);
12672#ifdef CRITERION_DEBUG
12673 if (TEST_OPT_DEBUG) PrintS("--- V crit\n");
12674#endif
12675 return TRUE;
12676 }
12677
12678 if (strat->sugarCrit && ALLOW_PROD_CRIT(strat))
12679 {
12680 if((!((ecartq>0)&&(ecart>0)))
12681 && pHasNotCF(p,q))
12682 {
12683 /*
12684 *the product criterion has applied for (s,p),
12685 *i.e. lcm(s,p)=product of the leading terms of s and p.
12686 *Suppose (s,r) is in L and the leading term
12687 *of p divides lcm(s,r)
12688 *(==> the leading term of p divides the leading term of r)
12689 *but the leading term of s does not divide the leading term of r
12690 *(notice that this condition is automatically satisfied if r is still
12691 *in S), then (s,r) can be cancelled.
12692 *This should be done here because the
12693 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12694 *
12695 *Moreover, skipping (s,r) holds also for the noncommutative case.
12696 */
12697 strat->cp++;
12698 pLmFree(Lp.lcm);
12699#ifdef CRITERION_DEBUG
12700 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12701#endif
12702 return TRUE;
12703 }
12704 else
12705 Lp.ecart = si_max(ecart,ecartq);
12706 if (strat->fromT && (ecartq>ecart))
12707 {
12708 pLmFree(Lp.lcm);
12709#ifdef CRITERION_DEBUG
12710 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12711#endif
12712 return TRUE;
12713 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12714 }
12715 /*
12716 *the set B collects the pairs of type (S[j],p)
12717 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12718 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12719 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12720 */
12721 {
12722 j = strat->Bl;
12723 loop
12724 {
12725 if (j < 0) break;
12726 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12727 if ((compare==1)
12728 &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart)))
12729 {
12730 strat->c3++;
12731 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12732 {
12733 pLmFree(Lp.lcm);
12734#ifdef CRITERION_DEBUG
12735 if (TEST_OPT_DEBUG)
12736 {
12737 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12738 }
12739#endif
12740 return TRUE;
12741 }
12742 break;
12743 }
12744 else
12745 if ((compare ==-1)
12746 && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart))
12747 {
12748#ifdef CRITERION_DEBUG
12749 if (TEST_OPT_DEBUG)
12750 {
12751 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12752 }
12753#endif
12754 deleteInL(strat->B,&strat->Bl,j,strat);
12755 strat->c3++;
12756 }
12757 j--;
12758 }
12759 }
12760 }
12761 else /*sugarcrit*/
12762 {
12763 if (ALLOW_PROD_CRIT(strat))
12764 {
12765 // if currRing->nc_type!=quasi (or skew)
12766 // TODO: enable productCrit for super commutative algebras...
12767 if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/
12768 pHasNotCF(p,q))
12769 {
12770 /*
12771 *the product criterion has applied for (s,p),
12772 *i.e. lcm(s,p)=product of the leading terms of s and p.
12773 *Suppose (s,r) is in L and the leading term
12774 *of p divides lcm(s,r)
12775 *(==> the leading term of p divides the leading term of r)
12776 *but the leading term of s does not divide the leading term of r
12777 *(notice that tis condition is automatically satisfied if r is still
12778 *in S), then (s,r) can be canceled.
12779 *This should be done here because the
12780 *case lcm(s,r)=lcm(s,p) is not covered by chainCrit.
12781 */
12782 strat->cp++;
12783 pLmFree(Lp.lcm);
12784#ifdef CRITERION_DEBUG
12785 if (TEST_OPT_DEBUG) PrintS("--- prod crit\n");
12786#endif
12787 return TRUE;
12788 }
12789 if (strat->fromT && (ecartq>ecart))
12790 {
12791 pLmFree(Lp.lcm);
12792#ifdef CRITERION_DEBUG
12793 if (TEST_OPT_DEBUG) PrintS("--- ecartq > ecart\n");
12794#endif
12795 return TRUE;
12796 /*the pair is (s[i],t[.]), discard it if the ecart is too big*/
12797 }
12798 /*
12799 *the set B collects the pairs of type (S[j],p)
12800 *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p)
12801 *if the leading term of s divides lcm(r,p) then (r,p) will be canceled
12802 *if the leading term of r divides lcm(s,p) then (s,p) will not enter B
12803 */
12804 for(j = strat->Bl;j>=0;j--)
12805 {
12806 compare=pLPDivComp(strat->B[j].lcm,Lp.lcm);
12807 if (compare==1)
12808 {
12809 strat->c3++;
12810 if ((strat->fromQ==NULL) || (isFromQ==0) || (qfromQ==0))
12811 {
12812 pLmFree(Lp.lcm);
12813#ifdef CRITERION_DEBUG
12814 if (TEST_OPT_DEBUG)
12815 {
12816 Print("--- chain crit using B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12817 }
12818#endif
12819 return TRUE;
12820 }
12821 break;
12822 }
12823 else
12824 if (compare ==-1)
12825 {
12826#ifdef CRITERION_DEBUG
12827 if (TEST_OPT_DEBUG)
12828 {
12829 Print("--- chain crit using pair to remove B[%d].lcm=%s\n", j, pString(strat->B[j].lcm));
12830 }
12831#endif
12832 deleteInL(strat->B,&strat->Bl,j,strat);
12833 strat->c3++;
12834 }
12835 }
12836 }
12837 }
12838 /*
12839 *the pair (S[i],p) enters B if the spoly != 0
12840 */
12841 /*- compute the short s-polynomial -*/
12842 if (strat->fromT && !TEST_OPT_INTSTRATEGY)
12843 pNorm(p);
12844 if ((q==NULL) || (p==NULL))
12845 {
12846#ifdef CRITERION_DEBUG
12847 if (TEST_OPT_DEBUG) PrintS("--- q == NULL || p == NULL\n");
12848#endif
12849 return FALSE;
12850 }
12851 if ((strat->fromQ!=NULL) && (isFromQ!=0) && (qfromQ!=0))
12852 {
12853 Lp.p=NULL;
12854#ifdef CRITERION_DEBUG
12855 if (TEST_OPT_DEBUG) PrintS("--- pair is from Q\n");
12856#endif
12857 }
12858 else
12859 {
12860// if ( rIsPluralRing(currRing) )
12861// {
12862// if(pHasNotCF(p, q))
12863// {
12864// if(ncRingType(currRing) == nc_lie)
12865// {
12866// // generalized prod-crit for lie-type
12867// strat->cp++;
12868// Lp.p = nc_p_Bracket_qq(pCopy(p),q, currRing);
12869// }
12870// else
12871// if( ALLOW_PROD_CRIT(strat) )
12872// {
12873// // product criterion for homogeneous case in SCA
12874// strat->cp++;
12875// Lp.p = NULL;
12876// }
12877// else
12878// Lp.p = nc_CreateSpoly(q,p,currRing); // ?
12879// }
12880// else Lp.p = nc_CreateSpoly(q,p,currRing);
12881// }
12882// else
12883// {
12884
12885 /* ksCreateShortSpoly needs two Lobject-kind presentations */
12886 /* p is already in this form, so convert q */
12887 // q = pMove2CurrTail(q, strat);
12888 Lp.p = ksCreateShortSpoly(q, p, strat->tailRing);
12889 // }
12890 }
12891 if (Lp.p == NULL)
12892 {
12893 /*- the case that the s-poly is 0 -*/
12894 // TODO: currently ifromS is only > 0 if called from enterOnePairWithShifts
12895 if (ifromS > 0)
12896 {
12897 if (strat->pairtest==NULL) initPairtest(strat);
12898 strat->pairtest[ifromS] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/
12899 strat->pairtest[strat->sl+1] = TRUE;
12900 }
12901 //if (TEST_OPT_DEBUG){Print("!");} // option teach
12902 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12903 /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/
12904 /*
12905 *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is
12906 *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not
12907 *divide lcm(r,p)). In the last case (s,r) can be canceled if the leading
12908 *term of p divides the lcm(s,r)
12909 *(this canceling should be done here because
12910 *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit)
12911 *the first case is handeled in chainCrit
12912 */
12913 if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
12914#ifdef CRITERION_DEBUG
12915 if (TEST_OPT_DEBUG) PrintS("--- S-poly = 0\n");
12916#endif
12917 return TRUE;
12918 }
12919 else
12920 {
12921 /*- the pair (S[i],p) enters B -*/
12922 /* both of them should have their LM in currRing and TAIL in tailring */
12923 Lp.p1 = q; // already in the needed form
12924 Lp.p2 = p; // already in the needed form
12925
12926 if ( !rIsPluralRing(currRing) )
12927 pNext(Lp.p) = strat->tail;
12928
12929 /* TEMPORARILY DISABLED FOR SHIFTS because there's no i*/
12930 /* at the beginning we DO NOT set atR = -1 ANYMORE*/
12931 if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
12932 {
12933 Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
12934 Lp.i_r2 = atR;
12935 }
12936 else
12937 {
12938 /* END _ TEMPORARILY DISABLED FOR SHIFTS */
12939 Lp.i_r1 = -1;
12940 Lp.i_r2 = -1;
12941 }
12942 strat->initEcartPair(&Lp,q,p,ecartq,ecart);
12943
12945 {
12948 && (Lp.p->coef!=NULL))
12949 nDelete(&(Lp.p->coef));
12950 }
12951
12952 l = strat->posInL(strat->B,strat->Bl,&Lp,strat);
12953 enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
12954#ifdef CRITERION_DEBUG
12955 if (TEST_OPT_DEBUG) PrintS("+++ Entered pair\n");
12956#endif
12957 }
12958 return FALSE;
12959}
12960#endif
12961
12962/*3
12963*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
12964* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
12965* additionally we put the pairs (h, s \sdot h) for s>=1 to L
12966*/
12967#ifdef HAVE_SHIFTBBA
12968void initenterpairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
12969{
12970 int h_lastVblock = pmLastVblock(h);
12971 assume(h_lastVblock != 0 || pLmIsConstantComp(h));
12972 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
12973 if (h_lastVblock == 0) return;
12974 assume(pmFirstVblock(h) == 1);
12975 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
12976 // atR = -1;
12977 if ((strat->syzComp==0)
12978 || (pGetComp(h)<=strat->syzComp))
12979 {
12980 int i,j;
12981 BOOLEAN new_pair=FALSE;
12982
12983 int degbound = currRing->N/currRing->isLPring;
12984 int maxShift = degbound - h_lastVblock;
12985
12986 if (pGetComp(h)==0)
12987 {
12988 if (strat->rightGB)
12989 {
12990 if (isFromQ)
12991 {
12992 // pairs (shifts(h),s[1..k]), (h, s[1..k])
12993 for (i=0; i<=maxShift; i++)
12994 {
12995 poly hh = pLPCopyAndShiftLM(h, i);
12996 BOOLEAN delete_hh=TRUE;
12997 for (j=0; j<=k; j++)
12998 {
12999 if (strat->fromQ == NULL || !strat->fromQ[j])
13000 {
13001 new_pair=TRUE;
13002 poly s = strat->S[j];
13003 if (!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
13004 delete_hh=FALSE;
13005 }
13006 }
13007 if (delete_hh) pLmDelete(hh);
13008 }
13009 }
13010 else
13011 {
13012 new_pair=TRUE;
13013 for (j=0; j<=k; j++)
13014 {
13015 poly s = strat->S[j];
13016 if (strat->fromQ != NULL && strat->fromQ[j])
13017 {
13018 // pairs (shifts(s[j]),h), (s[j],h)
13019 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13020 }
13021 else
13022 {
13023 // pair (h, s[j])
13024 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13025 }
13026 }
13027 }
13028 }
13029 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
13030 else if ((isFromQ)&&(strat->fromQ!=NULL))
13031 {
13032 // pairs (shifts(s[1..k]),h), (s[1..k],h)
13033 for (j=0; j<=k; j++)
13034 {
13035 if (!strat->fromQ[j])
13036 {
13037 new_pair=TRUE;
13038 poly s = strat->S[j];
13039 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13040 }
13041 }
13042 // pairs (shifts(h),s[1..k])
13043 if (new_pair)
13044 {
13045 for (i=1; i<=maxShift; i++)
13046 {
13047 BOOLEAN delete_hh=TRUE;
13048 poly hh = pLPCopyAndShiftLM(h, i);
13049 for (j=0; j<=k; j++)
13050 {
13051 if (!strat->fromQ[j])
13052 {
13053 poly s = strat->S[j];
13054 int s_lastVblock = pmLastVblock(s);
13055 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)
13056 {
13057 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i))
13058 delete_hh=FALSE;
13059 }
13060#ifdef HAVE_RINGS
13061 else if (rField_is_Ring(currRing))
13062 {
13063 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13064 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13065 for (int k = 0; k < IDELEMS(fillers); k++)
13066 {
13067 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13068 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13069 }
13070 idDelete(&fillers);
13071 }
13072#endif
13073 }
13074 }
13075 if (delete_hh) p_LmDelete(hh,currRing);
13076 }
13077 }
13078 }
13079 else
13080 {
13081 new_pair=TRUE;
13082 // pairs (shifts(s[1..k]),h), (s[1..k],h)
13083 for (j=0; j<=k; j++)
13084 {
13085 poly s = strat->S[j];
13086 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13087 }
13088 // pairs (shifts(h),s[1..k]), (shifts(h), h)
13089 for (i=1; i<=maxShift; i++)
13090 {
13091 poly hh = pLPCopyAndShiftLM(h, i);
13092 BOOLEAN delete_hh=TRUE;
13093 for (j=0; j<=k; j++)
13094 {
13095 poly s = strat->S[j];
13096 int s_lastVblock = pmLastVblock(s);
13097 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)
13098 delete_hh=enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i)
13099 && delete_hh;
13100#ifdef HAVE_RINGS
13101 else if (rField_is_Ring(currRing))
13102 {
13103 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13104 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13105 for (int k = 0; k < IDELEMS(fillers); k++)
13106 {
13107 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13108 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13109 }
13110 idDelete(&fillers);
13111 }
13112#endif
13113 }
13114 if (i < h_lastVblock) // in the module case, product criterion does not hold (note: comp h is always zero here)
13115 delete_hh=enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i)
13116 && delete_hh;
13117#ifdef HAVE_RINGS
13118 else if (rField_is_Ring(currRing))
13119 {
13120 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
13121 ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
13122 for (int k = 0; k < IDELEMS(fillers); k++)
13123 {
13124 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
13125 enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock);
13126 }
13127 idDelete(&fillers);
13128 }
13129#endif
13130 if (delete_hh) pLmDelete(hh);
13131 }
13132 }
13133 }
13134 else
13135 {
13136 assume(isFromQ == 0); // an element from Q should always has 0 component
13137 new_pair=TRUE;
13138 if (strat->rightGB)
13139 {
13140 for (j=0; j<=k; j++)
13141 {
13142 if ((pGetComp(h)==pGetComp(strat->S[j]))
13143 || (pGetComp(strat->S[j])==0))
13144 {
13145 poly s = strat->S[j];
13146 if (strat->fromQ != NULL && strat->fromQ[j])
13147 {
13148 // pairs (shifts(s[j]),h), (s[j],h)
13149 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13150 }
13151 else
13152 {
13153 // pair (h, s[j])
13154 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13155 }
13156 }
13157 }
13158 }
13159 else
13160 {
13161 // pairs (shifts(s[1..k]),h), (s[1..k],h)
13162 for (j=0; j<=k; j++)
13163 {
13164 if ((pGetComp(h)==pGetComp(strat->S[j]))
13165 || (pGetComp(strat->S[j])==0))
13166 {
13167 poly s = strat->S[j];
13168 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13169 }
13170 }
13171 // pairs (shifts(h),s[1..k]), (shifts(h), h)
13172 for (i=1; i<=maxShift; i++)
13173 {
13174 poly hh = pLPCopyAndShiftLM(h, i);
13175 for (j=0; j<=k; j++)
13176 {
13177 if ((pGetComp(h)==pGetComp(strat->S[j]))
13178 || (pGetComp(strat->S[j])==0))
13179 {
13180 poly s = strat->S[j];
13181 int s_lastVblock = pmLastVblock(s);
13182 if (i <= s_lastVblock) // in the module case, product criterion does not hold
13183 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, s_lastVblock, i);
13184#ifdef HAVE_RINGS
13185 else if (rField_is_Ring(currRing))
13186 {
13187 assume(i >= s_lastVblock); // this is always the case, but just to be very sure
13188 ideal fillers = id_MaxIdeal(i - s_lastVblock, currRing);
13189 for (int k = 0; k < IDELEMS(fillers); k++)
13190 {
13191 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), s_lastVblock);
13192 enterOnePairWithoutShifts(j, hhh, s, ecart, isFromQ, strat, atR, s_lastVblock, s_lastVblock);
13193 }
13194 idDelete(&fillers);
13195 }
13196#endif
13197 }
13198 }
13199 if (i <= h_lastVblock) // in the module case, product criterion does not hold
13200 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13201#ifdef HAVE_RINGS
13202 else if (rField_is_Ring(currRing))
13203 {
13204 assume(i >= h_lastVblock); // this is always the case, but just to be very sure
13205 ideal fillers = id_MaxIdeal(i - h_lastVblock, currRing);
13206 for (int k = 0; k < IDELEMS(fillers); k++)
13207 {
13208 BOOLEAN delete_hhh=TRUE;
13209 poly hhh = pLPCopyAndShiftLM(pp_mm_Mult(h, fillers->m[k], currRing), h_lastVblock);
13210 if(!enterOnePairWithoutShifts(-1, hhh, h, ecart, isFromQ, strat, atR, h_lastVblock, h_lastVblock))
13211 delete_hhh=FALSE;
13212 if (delete_hhh) p_LmDelete(hhh,currRing);
13213 }
13214 idDelete(&fillers);
13215 }
13216#endif
13217 }
13218 }
13219 }
13220
13221 if (new_pair)
13222 {
13223 strat->chainCrit(h,ecart,strat);
13224 }
13225 kMergeBintoL(strat);
13226 }
13227}
13228#endif
13229
13230/*3
13231*(s[0], s \dot h),...,(s[k],s \dot h) will be put to the pairset L
13232* also the pairs (h, s\dot s[0]), ..., (h, s\dot s[k]) enter L
13233* additionally we put the pairs (h, s \sdot h) for s>=1 to L
13234*/
13235#ifdef HAVE_SHIFTBBA
13236void initenterstrongPairsShift (poly h,int k,int ecart,int isFromQ, kStrategy strat, int atR)
13237{
13238 int h_lastVblock = pmLastVblock(h);
13239 assume(h_lastVblock != 0 || pLmIsConstantComp(h));
13240 // TODO: is it allowed to skip pairs with constants? also with constants from other components?
13241 if (h_lastVblock == 0) return;
13242 assume(pmFirstVblock(h) == 1);
13243 /* h comes from strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13244 // atR = -1;
13245 if ((strat->syzComp==0)
13246 || (pGetComp(h)<=strat->syzComp))
13247 {
13248 int i,j;
13249 BOOLEAN new_pair=FALSE;
13250
13251 int degbound = currRing->N/currRing->isLPring;
13252 int maxShift = degbound - h_lastVblock;
13253
13254 if (pGetComp(h)==0)
13255 {
13256 if (strat->rightGB)
13257 {
13258 if (isFromQ)
13259 {
13260 // pairs (shifts(h),s[1..k]), (h, s[1..k])
13261 for (i=0; i<=maxShift; i++)
13262 {
13263 poly hh = pLPCopyAndShiftLM(h, i);
13264 for (j=0; j<=k; j++)
13265 {
13266 if (strat->fromQ == NULL || !strat->fromQ[j])
13267 {
13268 new_pair=TRUE;
13269 poly s = strat->S[j];
13270 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13271 }
13272 }
13273 }
13274 }
13275 else
13276 {
13277 new_pair=TRUE;
13278 for (j=0; j<=k; j++)
13279 {
13280 poly s = strat->S[j];
13281 if (strat->fromQ != NULL && strat->fromQ[j])
13282 {
13283 // pairs (shifts(s[j]),h), (s[j],h)
13284 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13285 }
13286 else
13287 {
13288 // pair (h, s[j])
13289 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13290 }
13291 }
13292 }
13293 }
13294 /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
13295 else if ((isFromQ)&&(strat->fromQ!=NULL))
13296 {
13297 // pairs (shifts(s[1..k]),h), (s[1..k],h)
13298 for (j=0; j<=k; j++)
13299 {
13300 if (!strat->fromQ[j])
13301 {
13302 new_pair=TRUE;
13303 poly s = strat->S[j];
13304 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13305 }
13306 }
13307 // pairs (shifts(h),s[1..k])
13308 if (new_pair)
13309 {
13310 for (i=1; i<=maxShift; i++)
13311 {
13312 poly hh = pLPCopyAndShiftLM(h, i);
13313 for (j=0; j<=k; j++)
13314 {
13315 if (!strat->fromQ[j])
13316 {
13317 poly s = strat->S[j];
13318 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13319 }
13320 }
13321 }
13322 }
13323 }
13324 else
13325 {
13326 new_pair=TRUE;
13327 // pairs (shifts(s[1..k]),h), (s[1..k],h)
13328 for (j=0; j<=k; j++)
13329 {
13330 poly s = strat->S[j];
13331 // TODO: cache lastVblock of s[1..k] for later use
13332 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13333 }
13334 // pairs (shifts(h),s[1..k]), (shifts(h), h)
13335 for (i=1; i<=maxShift; i++)
13336 {
13337 poly hh = pLPCopyAndShiftLM(h, i);
13338 BOOLEAN delete_hh=TRUE;
13339 for (j=0; j<=k; j++)
13340 {
13341 poly s = strat->S[j];
13342 if(!enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i))
13343 delete_hh=FALSE;
13344 }
13345 if(!enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i))
13346 delete_hh=FALSE;
13347 if (delete_hh) p_LmDelete(hh,currRing);
13348 }
13349 }
13350 }
13351 else
13352 {
13353 new_pair=TRUE;
13354 if (strat->rightGB)
13355 {
13356 for (j=0; j<=k; j++)
13357 {
13358 if ((pGetComp(h)==pGetComp(strat->S[j]))
13359 || (pGetComp(strat->S[j])==0))
13360 {
13361 assume(isFromQ == 0); // this case is not handeled here and should also never happen
13362 poly s = strat->S[j];
13363 if (strat->fromQ != NULL && strat->fromQ[j])
13364 {
13365 // pairs (shifts(s[j]),h), (s[j],h)
13366 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13367 }
13368 else
13369 {
13370 // pair (h, s[j])
13371 enterOnePairWithoutShifts(j, h, s, ecart, isFromQ, strat, atR, pmLastVblock(s), 0);
13372 }
13373 }
13374 }
13375 }
13376 else
13377 {
13378 // pairs (shifts(s[1..k]),h), (s[1..k],h)
13379 for (j=0; j<=k; j++)
13380 {
13381 if ((pGetComp(h)==pGetComp(strat->S[j]))
13382 || (pGetComp(strat->S[j])==0))
13383 {
13384 poly s = strat->S[j];
13385 enterOnePairWithShifts(j, s, h, ecart, isFromQ, strat, atR, h_lastVblock, pmLastVblock(s));
13386 }
13387 }
13388 // pairs (shifts(h),s[1..k]), (shifts(h), h)
13389 for (i=1; i<=maxShift; i++)
13390 {
13391 poly hh = pLPCopyAndShiftLM(h, i);
13392 for (j=0; j<=k; j++)
13393 {
13394 if ((pGetComp(h)==pGetComp(strat->S[j]))
13395 || (pGetComp(strat->S[j])==0))
13396 {
13397 poly s = strat->S[j];
13398 enterOnePairWithoutShifts(j, hh, s, ecart, isFromQ, strat, atR, pmLastVblock(s), i);
13399 }
13400 }
13401 enterOnePairWithoutShifts(-1, hh, h, ecart, isFromQ, strat, atR, h_lastVblock, i);
13402 }
13403 }
13404 }
13405
13406 if (new_pair)
13407 {
13408 strat->chainCrit(h,ecart,strat);
13409 }
13410 kMergeBintoL(strat);
13411 }
13412}
13413#endif
13414
13415/*2
13416*(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs)
13417*superfluous elements in S will be deleted
13418*/
13419#ifdef HAVE_SHIFTBBA
13420void enterpairsShift (poly h,int k,int ecart,int pos,kStrategy strat, int atR)
13421{
13422 /* h is strat->P.p, that is LObject with LM in currRing and Tail in tailRing */
13423 /* Q: what is exactly the strat->fromT ? A: a local case trick; don't need it yet*/
13424 int j=pos;
13425
13426 /* if (!(rField_is_Domain(currRing))) enterExtendedSpoly(h, strat); */ // TODO: enterExtendedSpoly not for LP yet
13427 initenterpairsShift(h,k,ecart,0,strat, atR);
13428 if ( (!strat->fromT)
13429 && ((strat->syzComp==0)
13430 ||(pGetComp(h)<=strat->syzComp)))
13431 {
13432 unsigned long h_sev = pGetShortExpVector(h);
13433 loop
13434 {
13435 if (j > k) break;
13436 // TODO this currently doesn't clear all possible elements because of commutative division
13437 if (!(strat->rightGB && strat->fromQ != NULL && strat->fromQ[j]))
13438 clearS(h,h_sev, &j,&k,strat);
13439 j++;
13440 }
13441 }
13442}
13443#endif
13444
13445/*2
13446* enteres all admissible shifts of p into T
13447* assumes that p is already in T!
13448*/
13449#ifdef HAVE_SHIFTBBA
13450void enterTShift(LObject p, kStrategy strat, int atT)
13451{
13452 /* determine how many elements we have to insert */
13453 /* x(0)y(1)z(2) : lastVblock-1=2, to add until lastVblock=uptodeg-1 */
13454 /* hence, a total number of elt's to add is: */
13455 /* int toInsert = 1 + (uptodeg-1) - (pLastVblock(p.p, lV) -1); */
13456 pAssume(p.p != NULL);
13457
13458 int maxPossibleShift = p_mLPmaxPossibleShift(p.p, strat->tailRing);
13459
13460 for (int i = 1; i <= maxPossibleShift; i++)
13461 {
13462 LObject qq;
13463 qq.p = pLPCopyAndShiftLM(p.p, i); // don't use Set() because it'll test the poly order
13464 qq.shift = i;
13465 strat->initEcart(&qq); // initEcartBBA sets length, pLength, FDeg and ecart
13466
13467 enterT(qq, strat, atT); // enterT is modified, so it doesn't copy and delete the tail of shifted polys
13468 }
13469}
13470#endif
13471
13472#ifdef HAVE_SHIFTBBA
13474{
13475 /* for the shift case need to run it with withT = TRUE */
13476 strat->redTailChange=FALSE;
13477 if (strat->noTailReduction) return L->GetLmCurrRing();
13478 poly h, p;
13479 p = h = L->GetLmTailRing();
13480 if ((h==NULL) || (pNext(h)==NULL))
13481 return L->GetLmCurrRing();
13482
13483 TObject* With;
13484 // placeholder in case strat->tl < 0
13485 TObject With_s(strat->tailRing);
13486
13487 LObject Ln(pNext(h), strat->tailRing);
13488 Ln.pLength = L->GetpLength() - 1;
13489
13490 pNext(h) = NULL;
13491 if (L->p != NULL) pNext(L->p) = NULL;
13492 L->pLength = 1;
13493
13494 Ln.PrepareRed(strat->use_buckets);
13495
13496 while(!Ln.IsNull())
13497 {
13498 loop
13499 {
13500 Ln.SetShortExpVector();
13501 if (withT)
13502 {
13503 int j;
13504 j = kFindDivisibleByInT(strat, &Ln);
13505 if (j < 0) break;
13506 With = &(strat->T[j]);
13507 }
13508 else
13509 {
13510 With = kFindDivisibleByInS_T(strat, pos, &Ln, &With_s);
13511 if (With == NULL) break;
13512 }
13513 if (normalize && (!TEST_OPT_INTSTRATEGY) && (!nIsOne(pGetCoeff(With->p))))
13514 {
13515 With->pNorm();
13516 //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
13517 }
13518 strat->redTailChange=TRUE;
13519 if (ksReducePolyTail(L, With, &Ln))
13520 {
13521 // reducing the tail would violate the exp bound
13522 // set a flag and hope for a retry (in bba)
13524 if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL;
13525 do
13526 {
13527 pNext(h) = Ln.LmExtractAndIter();
13528 pIter(h);
13529 L->pLength++;
13530 } while (!Ln.IsNull());
13531 goto all_done;
13532 }
13533 if (Ln.IsNull()) goto all_done;
13534 if (! withT) With_s.Init(currRing);
13535 }
13536 pNext(h) = Ln.LmExtractAndIter();
13537 pIter(h);
13538 L->pLength++;
13539 }
13540
13541 all_done:
13542 Ln.Delete();
13543 if (L->p != NULL) pNext(L->p) = pNext(p);
13544
13545 if (strat->redTailChange)
13546 {
13547 L->length = 0;
13548 }
13549 L->Normalize(); // HANNES: should have a test
13550 kTest_L(L,strat);
13551 return L->GetLmCurrRing();
13552}
13553#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 m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
int p
Definition: cfModGcd.cc:4077
bool equal
Definition: cfModGcd.cc:4125
CanonicalForm b
Definition: cfModGcd.cc:4102
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:797
KINLINE poly kNoetherTail()
Definition: kInline.h:66
unsigned long * sevSyz
Definition: kutil.h:323
kStrategy next
Definition: kutil.h:277
bool sigdrop
Definition: kutil.h:359
poly t_kNoether
Definition: kutil.h:330
int syzComp
Definition: kutil.h:354
int * S_2_R
Definition: kutil.h:342
ring tailRing
Definition: kutil.h:343
void(* chainCrit)(poly p, int ecart, kStrategy strat)
Definition: kutil.h:291
char noTailReduction
Definition: kutil.h:378
int currIdx
Definition: kutil.h:317
~skStrategy()
Definition: kutil.cc:11657
skStrategy()
Definition: kutil.cc:11637
int nrsyzcrit
Definition: kutil.h:360
intset lenS
Definition: kutil.h:319
int nrrewcrit
Definition: kutil.h:361
pFDegProc pOrigFDeg_TailRing
Definition: kutil.h:298
int Ll
Definition: kutil.h:351
TSet T
Definition: kutil.h:326
BOOLEAN(* rewCrit1)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:293
char news
Definition: kutil.h:400
omBin lmBin
Definition: kutil.h:344
int syzmax
Definition: kutil.h:349
int Bl
Definition: kutil.h:352
intset ecartS
Definition: kutil.h:309
int syzidxmax
Definition: kutil.h:349
char honey
Definition: kutil.h:377
char rightGB
Definition: kutil.h:369
polyset S
Definition: kutil.h:306
int minim
Definition: kutil.h:357
poly kNoether
Definition: kutil.h:329
BOOLEAN * NotUsedAxis
Definition: kutil.h:332
LSet B
Definition: kutil.h:328
BOOLEAN * pairtest
Definition: kutil.h:333
int cp
Definition: kutil.h:347
int ak
Definition: kutil.h:353
TObject ** R
Definition: kutil.h:340
BOOLEAN(* rewCrit3)(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int start)
Definition: kutil.h:295
int tl
Definition: kutil.h:350
unsigned long * sevT
Definition: kutil.h:325
unsigned long * sevSig
Definition: kutil.h:324
int nr
Definition: kutil.h:346
poly tail
Definition: kutil.h:334
char sugarCrit
Definition: kutil.h:377
int(* posInL)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:284
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:47
intset syzIdx
Definition: kutil.h:313
ideal Shdl
Definition: kutil.h:303
int syzl
Definition: kutil.h:349
unsigned sbaOrder
Definition: kutil.h:316
pFDegProc pOrigFDeg
Definition: kutil.h:296
int tmax
Definition: kutil.h:350
polyset sig
Definition: kutil.h:308
polyset syz
Definition: kutil.h:307
char LDegLast
Definition: kutil.h:385
void(* initEcartPair)(LObject *h, poly f, poly g, int ecartF, int ecartG)
Definition: kutil.h:287
BOOLEAN(* syzCrit)(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.h:292
wlen_set lenSw
Definition: kutil.h:320
char kAllAxis
Definition: kutil.h:376
int cv
Definition: kutil.h:368
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:338
char Gebauer
Definition: kutil.h:378
intset fromQ
Definition: kutil.h:321
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:286
char newt
Definition: kutil.h:401
char use_buckets
Definition: kutil.h:383
char interpt
Definition: kutil.h:371
char redTailChange
Definition: kutil.h:399
int newIdeal
Definition: kutil.h:356
char fromT
Definition: kutil.h:379
char completeReduce_retry
Definition: kutil.h:403
void(* initEcart)(TObject *L)
Definition: kutil.h:280
omBin tailBin
Definition: kutil.h:345
LObject P
Definition: kutil.h:302
KINLINE TObject * S_2_T(int i)
Definition: kInline.h:38
char noClearS
Definition: kutil.h:402
int Lmax
Definition: kutil.h:351
char z2homog
Definition: kutil.h:374
int LazyPass
Definition: kutil.h:353
char overflow
Definition: kutil.h:404
void(* enterOnePair)(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.h:290
LSet L
Definition: kutil.h:327
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:281
int(* red)(LObject *L, kStrategy strat)
Definition: kutil.h:278
int sl
Definition: kutil.h:348
int LazyDegree
Definition: kutil.h:353
char posInLDependsOnLength
Definition: kutil.h:389
unsigned long * sevS
Definition: kutil.h:322
char homog
Definition: kutil.h:372
pLDegProc pOrigLDeg
Definition: kutil.h:297
int(* posInLSba)(const LSet set, const int length, LObject *L, const kStrategy strat)
Definition: kutil.h:282
pLDegProc pOrigLDeg_TailRing
Definition: kutil.h:299
int Bmax
Definition: kutil.h:352
int c3
Definition: kutil.h:347
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:816
@ 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:664
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:515
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:679
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:700
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:392
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
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:690
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:671
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:538
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:628
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:753
static FORCE_INLINE int n_DivComp(number a, number b, const coeffs r)
Definition: coeffs.h:522
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:547
#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
CanonicalForm H
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:970
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:1072
KINLINE int ksReducePolyTailLC_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1120
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1185
KINLINE TObject ** initR()
Definition: kInline.h:95
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1158
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1195
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1248
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:1029
KINLINE int ksReducePolyTail_Z(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1138
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
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
Definition: kbuckets.cc:660
int ksCheckCoeff(number *a, number *b)
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:1430
int posInL10(const LSet set, const int length, LObject *p, const kStrategy strat)
Definition: kstd1.cc:1352
long kHomModDeg(poly p, ring r)
Definition: kstd1.cc:2420
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition: kstd1.cc:3167
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:2433
int kFindDivisibleByInT_Z(const kStrategy strat, const LObject *L, const int start)
Definition: kstd2.cc:209
int redHoney(LObject *h, kStrategy strat)
Definition: kstd2.cc:1905
int redHomog(LObject *h, kStrategy strat)
Definition: kstd2.cc:938
int redLazy(LObject *h, kStrategy strat)
Definition: kstd2.cc:1698
int redRing(LObject *h, kStrategy strat)
Definition: kstd2.cc:831
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:290
void initSbaPos(kStrategy strat)
Definition: kutil.cc:10184
void message(int i, int *reduc, int *olddeg, kStrategy strat, int red_result)
Definition: kutil.cc:7784
poly redtail(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7147
int posInL17Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6604
#define pDivComp_LESS
Definition: kutil.cc:136
int posInL17_cRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6719
int getIndexRng(long coeff)
Definition: kutil.cc:6261
int posInL110(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6358
int posInT17(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5460
void initBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10073
poly pMove2CurrTail(poly p, kStrategy strat)
Definition: kutil.cc:11971
int posInTrg0(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5131
int redFirst(LObject *h, kStrategy strat)
Definition: kstd1.cc:797
VAR int HCord
Definition: kutil.cc:246
void kMergeBintoL(kStrategy strat)
Definition: kutil.cc:3254
static void enlargeT(TSet &T, TObject **&R, unsigned long *&sevT, int &length, const int incr)
Definition: kutil.cc:548
BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int)
Definition: kutil.cc:6954
void enterSyz(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9652
int posInL11Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6102
int redEcart(LObject *h, kStrategy strat)
Definition: kstd1.cc:169
int posInT11(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5053
void enterT(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9450
int posInT1(const TSet set, const int length, LObject &p)
Definition: kutil.cc:4996
void enterTShift(LObject p, kStrategy strat, int atT)
Definition: kutil.cc:13450
int posInT110Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5250
BOOLEAN arriRewCriterion(poly, unsigned long, poly, kStrategy strat, int start=0)
Definition: kutil.cc:6929
void enterSSba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9224
BOOLEAN kTest(kStrategy strat)
Definition: kutil.cc:1036
void initenterpairsSigRing(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4027
void enterSMoraNF(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1668
poly redtailBbaBound(LObject *L, int end_pos, kStrategy strat, int bound, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7336
int posInT_EcartpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5326
TObject * kFindDivisibleByInS_T(kStrategy strat, int end_pos, LObject *L, TObject *T, long ecart)
Definition: kutil.cc:7005
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:4985
poly pMoveCurrTail2poly(poly p, kStrategy strat)
Definition: kutil.cc:11985
BOOLEAN kTest_TS(kStrategy strat)
Definition: kutil.cc:1097
void enterOnePairNormal(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2032
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:742
BOOLEAN kCheckStrongCreation(int atR, poly m1, int atS, poly m2, kStrategy strat)
Definition: kutil.cc:10846
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:13236
void enterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4613
static void enterOnePairRingShift(poly q, poly p, int, int isFromQ, kStrategy strat, int atR, int, int qisFromQ, int shiftcount, int ifromS)
Definition: kutil.cc:12266
static const char * kTest_LmEqual(poly p, poly t_p, ring tailRing)
Definition: kutil.cc:807
void enterL(LSet *set, int *length, int *LSetmax, LObject p, int at)
Definition: kutil.cc:1360
BOOLEAN faugereRewCriterion(poly sig, unsigned long not_sevSig, poly, kStrategy strat, int start=0)
Definition: kutil.cc:6870
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:12510
void clearSbatch(poly h, int k, int pos, kStrategy strat)
Definition: kutil.cc:4530
static int pLPDivComp(poly p, poly q)
Definition: kutil.cc:232
int posInT2(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5025
int posInL13(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6447
int posInL110Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6400
#define kFalseReturn(x)
Definition: kutil.cc:804
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:12520
int posInT_pLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11799
static intset initec(const int maxnr)
Definition: kutil.cc:534
BOOLEAN kPosInLDependsOnLength(int(*pos_in_l)(const LSet set, const int length, LObject *L, const kStrategy strat))
Definition: kutil.cc:9884
void enterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4587
int posInT13(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5297
void redtailBbaAlsoLC_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7452
BOOLEAN syzCriterionInc(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6821
static void deleteHCBucket(LObject *L, kStrategy strat)
Definition: kutil.cc:250
void initHilbCrit(ideal, ideal, intvec **hilb, kStrategy strat)
Definition: kutil.cc:9730
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:12585
void chainCritSig(poly p, int, kStrategy strat)
Definition: kutil.cc:3554
int posInSMonFirst(const kStrategy strat, const int length, const poly p)
Definition: kutil.cc:4864
void initEcartPairMora(LObject *Lp, poly, poly, int ecartF, int ecartG)
Definition: kutil.cc:1406
void initenterstrongPairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4247
void superenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4569
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8821
int posInL0Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5825
static int pDivCompRing(poly p, poly q)
Definition: kutil.cc:144
BOOLEAN isInPairsetB(poly q, int *k, kStrategy strat)
Definition: kutil.cc:727
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:9900
void initenterpairs(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:3902
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:7907
BOOLEAN kStratChangeTailRing(kStrategy strat, LObject *L, TObject *T, unsigned long expbound)
Definition: kutil.cc:11294
poly redtailBba(LObject *L, int end_pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:7223
poly redtailBba_Z(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7581
ring sbaRing(kStrategy strat, const ring r, BOOLEAN, int)
Definition: kutil.cc:11415
void initPairtest(kStrategy strat)
Definition: kutil.cc:697
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:2295
int posInL0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5797
void initSSpecial(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8403
void chainCritOpt_1(poly, int, kStrategy strat)
Definition: kutil.cc:3538
int posInT11Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5090
static void enterOnePairRing(int i, poly p, int, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:1426
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8797
void cancelunit1(LObject *p, int *suc, int index, kStrategy strat)
Definition: kutil.cc:8709
poly pCopyL2p(LObject H, kStrategy strat)
Definition: kutil.cc:12002
void initenterpairsShift(poly h, int k, int ecart, int isFromQ, kStrategy strat, int atR)
Definition: kutil.cc:12968
static void initenterstrongPairsSig(poly h, poly hSig, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:4302
void initenterpairsSig(poly h, poly hSig, int hFrom, int k, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:3967
int posInL15(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6482
static void enlargeL(LSet *L, int *length, const int incr)
Definition: kutil.cc:687
int posInT17_c(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5568
poly redtailBbaShift(LObject *L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize)
Definition: kutil.cc:13473
int posInT_EcartFDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11708
int posInT15(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5364
void enterT_strong(LObject &p, kStrategy strat, int atT)
Definition: kutil.cc:9550
void postReduceByMon(LObject *h, kStrategy strat)
used for GB over ZZ: intermediate reduction by monomial elements background: any known constant eleme...
Definition: kutil.cc:11036
BOOLEAN syzCriterion(poly sig, unsigned long not_sevSig, kStrategy strat)
Definition: kutil.cc:6786
void HEckeTest(poly pp, kStrategy strat)
Definition: kutil.cc:505
int posInLSpecial(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5753
STATIC_VAR BOOLEAN sloppy_max
Definition: kutil.cc:824
VAR int Kstd1_deg
Definition: kutil.cc:247
void enterExtendedSpolySig(poly h, poly hSig, kStrategy strat)
Definition: kutil.cc:4412
void enterpairsShift(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:13420
static void enterOnePairSig(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2526
BOOLEAN kTest_L(LObject *L, kStrategy strat, BOOLEAN testp, int lpos, TSet T, int tlength)
Definition: kutil.cc:950
void exitBuchMora(kStrategy strat)
Definition: kutil.cc:10158
void messageStatSBA(int hilbcount, kStrategy strat)
Definition: kutil.cc:7838
void initEcartNormal(TObject *h)
Definition: kutil.cc:1384
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:4763
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:8866
static BOOLEAN is_shifted_p1(const poly p, const kStrategy strat)
Definition: kutil.cc:1268
void initSLSba(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8098
int posInL11Ringls(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6172
void enterOnePairSpecial(int i, poly p, int ecart, kStrategy strat, int atR=-1)
Definition: kutil.cc:3185
static int * initS_2_R(const int maxnr)
Definition: kutil.cc:543
int posInL17(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6559
void initSyzRules(kStrategy strat)
Definition: kutil.cc:8248
int posInLSig(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5857
void initSbaBuchMora(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:10286
BOOLEAN kCheckSpolyCreation(LObject *L, kStrategy strat, poly &m1, poly &m2)
Definition: kutil.cc:10807
void cleanT(kStrategy strat)
Definition: kutil.cc:569
static void enterOnePairLift(int i, poly p, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2314
int posInT110(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5207
BOOLEAN kTest_S(kStrategy strat)
Definition: kutil.cc:1079
int posInSyz(const kStrategy strat, poly sig)
Definition: kutil.cc:6018
void replaceInLAndSAndT(LObject &p, int tj, kStrategy strat)
Definition: kutil.cc:9359
void reorderS(int *suc, kStrategy strat)
Definition: kutil.cc:4710
void enterExtendedSpoly(poly h, kStrategy strat)
Definition: kutil.cc:4329
int posInL15Ring(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6518
#define pDivComp_INCOMP
Definition: kutil.cc:138
BOOLEAN kTest_T(TObject *T, kStrategy strat, int i, char TN)
Definition: kutil.cc:825
void kMergeBintoLSba(kStrategy strat)
Definition: kutil.cc:3275
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:294
void updateResult(ideal r, ideal Q, kStrategy strat)
Definition: kutil.cc:10401
void superenterpairs(poly h, int k, int ecart, int pos, kStrategy strat, int atR)
Definition: kutil.cc:4556
static BOOLEAN sugarDivisibleBy(int ecart1, int ecart2)
Definition: kutil.cc:1417
int posInT19(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5696
#define pDivComp_GREATER
Definition: kutil.cc:137
void exitSba(kStrategy strat)
Definition: kutil.cc:10361
int posInT15Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5419
int posInT17Ring(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5522
static BOOLEAN enterOneStrongPoly(int i, poly p, int, int, kStrategy strat, int atR, bool enterTstrong)
Definition: kutil.cc:1630
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:12625
void kDebugPrint(kStrategy strat)
Output some debug info about a given strategy.
Definition: kutil.cc:11833
int posInLrg0(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6274
void deleteInL(LSet set, int *length, int j, kStrategy strat)
Definition: kutil.cc:1295
void kStratInitChangeTailRing(kStrategy strat)
Definition: kutil.cc:11387
void chainCritPart(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3613
void enterSMora(LObject &p, int atS, kStrategy strat, int atR=-1)
Definition: kstd1.cc:1615
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9748
void cleanTSbaRing(kStrategy strat)
Definition: kutil.cc:628
int posInT17_cRing(const TSet set, const int length, LObject &p)
Definition: kutil.cc:5630
void deleteInSSba(int i, kStrategy strat)
Definition: kutil.cc:1215
static int pDivComp(poly p, poly q)
Definition: kutil.cc:183
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:10613
int posInL17_c(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6654
void initBuchMoraPosRing(kStrategy strat)
Definition: kutil.cc:9986
int kFindInTShift(poly p, TSet T, int tlength)
Definition: kutil.cc:767
void postReduceByMonSig(LObject *h, kStrategy strat)
Definition: kutil.cc:11112
static BOOLEAN enterOneStrongPolyShift(poly q, poly p, int, int, kStrategy strat, int atR, int, int, int shiftcount, int ifromS)
Definition: kutil.cc:12097
void messageSets(kStrategy strat)
Definition: kutil.cc:7857
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1163
static poly redBba1(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:8692
int posInT_FDegpLength(const TSet set, const int length, LObject &p)
Definition: kutil.cc:11762
int posInLSigRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5882
BOOLEAN isInPairsetL(int length, poly p1, poly p2, int *k, kStrategy strat)
Definition: kutil.cc:706
BOOLEAN sbaCheckGcdPair(LObject *h, kStrategy strat)
Definition: kutil.cc:1780
int posInLF5CRing(const LSet set, int start, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6136
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:10869
static unsigned long * initsevS(const int maxnr)
Definition: kutil.cc:539
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:4636
void chainCritNormal(poly p, int ecart, kStrategy strat)
Definition: kutil.cc:3297
void initEcartBBA(TObject *h)
Definition: kutil.cc:1392
VAR denominator_list DENOMINATOR_LIST
Definition: kutil.cc:84
int posInLRing(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:5945
static void enterOnePairSigRing(int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR=-1)
Definition: kutil.cc:2783
void enterSBbaShift(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9201
int posInL11(const LSet set, const int length, LObject *p, const kStrategy)
Definition: kutil.cc:6059
char * showOption()
Definition: misc_ip.cc:709
poly redtailBba_Ring(LObject *L, int end_pos, kStrategy strat)
Definition: kutil.cc:7695
int posInLF5C(const LSet, const int, LObject *, const kStrategy strat)
Definition: kutil.cc:6047
void initEcartPairBba(LObject *Lp, poly, poly, int, int)
Definition: kutil.cc:1399
void messageStat(int hilbcount, kStrategy strat)
Definition: kutil.cc:7825
static BOOLEAN enterOneStrongPolySig(int i, poly p, poly sig, int, int, kStrategy strat, int atR)
Definition: kutil.cc:1838
void chainCritRing(poly p, int, kStrategy strat)
Definition: kutil.cc:4089
void initSSpecialSba(ideal F, ideal Q, ideal P, kStrategy strat)
Definition: kutil.cc:8547
void initSL(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8001
int posInIdealMonFirst(const ideal F, const poly p, int start, int end)
Definition: kutil.cc:4941
void finalReduceByMon(kStrategy strat)
used for GB over ZZ: final reduction by constant elements background: any known constant element of i...
Definition: kutil.cc:11201
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9101
void initSbaCrit(kStrategy strat)
Definition: kutil.cc:9813
BOOLEAN newHEdge(kStrategy strat)
Definition: kutil.cc:10735
#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:421
LObject * LSet
Definition: kutil.h:60
denominator_list next
Definition: kutil.h:65
static void kDeleteLcm(LObject *P)
Definition: kutil.h:886
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:2243
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:43
#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:121
#define TEST_OPT_IDLIFT
Definition: options.h:129
#define TEST_OPT_INTSTRATEGY
Definition: options.h:110
#define TEST_OPT_REDTAIL
Definition: options.h:116
#define TEST_OPT_INFREDTAIL
Definition: options.h:118
#define TEST_OPT_SUGARCRIT
Definition: options.h:107
#define TEST_OPT_OLDSTD
Definition: options.h:123
#define TEST_OPT_REDSB
Definition: options.h:104
#define TEST_OPT_DEGBOUND
Definition: options.h:113
#define TEST_OPT_SB_1
Definition: options.h:119
#define TEST_OPT_NOT_SUGAR
Definition: options.h:106
#define TEST_OPT_PROT
Definition: options.h:103
#define OPT_INTERRUPT
Definition: options.h:79
#define TEST_OPT_CANCELUNIT
Definition: options.h:128
#define BTEST1(a)
Definition: options.h:33
#define TEST_OPT_DEBUG
Definition: options.h:108
#define TEST_OPT_CONTENTSB
Definition: options.h:127
pShallowCopyDeleteProc pGetShallowCopyDeleteProc(ring, ring)
static int index(p_Length length, p_Ord ord)
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:3019
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:3765
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:4642
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:4897
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:2910
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:1986
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3812
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:1651
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1109
static void p_ExpVectorSum(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1427
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:938
static void p_LmDelete(poly p, const ring r)
Definition: p_polys.h:725
static void p_ExpVectorAdd(poly p1, poly p2, const ring r)
Definition: p_polys.h:1413
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:102
static BOOLEAN _p_LmDivisibleByPart(poly a, const ring r_a, poly b, const ring r_b, const int start, const int end)
Definition: p_polys.h:1856
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:382
static unsigned long p_GetMaxExp(const unsigned long l, const ring r)
Definition: p_polys.h:783
static void p_ExpVectorCopy(poly d_p, poly s_p, const ring r)
Definition: p_polys.h:1315
static void p_LmDelete0(poly p, const ring r)
Definition: p_polys.h:735
static int p_Cmp(poly p1, poly p2, ring r)
Definition: p_polys.h:1729
#define __pp_Mult_nn(p, n, r)
Definition: p_polys.h:1004
static poly pp_mm_Mult(poly p, poly m, const ring r)
Definition: p_polys.h:1043
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1033
static int p_LtCmpNoAbs(poly p, poly q, const ring r)
Definition: p_polys.h:1649
static void p_SetCompP(poly p, int i, ring r)
Definition: p_polys.h:256
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:164
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:249
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:235
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:414
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1582
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1931
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:471
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:71
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1897
static poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
Definition: p_polys.h:930
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:903
static unsigned pLength(poly a)
Definition: p_polys.h:191
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:112
static poly p_LmFreeAndNext(poly p, ring)
Definition: p_polys.h:713
static poly p_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:1053
static void p_LmFree(poly p, ring)
Definition: p_polys.h:685
#define p_LmTest(p, r)
Definition: p_polys.h:163
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:848
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1509
static BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, const ring r)
Definition: p_polys.h:2040
#define p_Test(p, r)
Definition: p_polys.h:162
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
Compatiblity layer for legacy polynomial operations (over currRing)
#define pAdd(p, q)
Definition: polys.h:203
#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:363
#define pJet(p, m)
Definition: polys.h:368
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition: polys.h: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:400
#define pDivisibleBy(a, b)
returns TRUE, if leading monom of a divides leading monom of b i.e., if there exists a expvector c > ...
Definition: polys.h: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 prMoveR(poly &p, ring src_r, ring dest_r)
Definition: prCopy.cc:90
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:3492
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition: ring.cc:5786
void rKillModifiedRing(ring r)
Definition: ring.cc:3101
ring rAssure_c_dp(const ring r)
Definition: ring.cc:5070
ring rModifyRing(ring r, BOOLEAN omit_degree, BOOLEAN try_omit_comp, unsigned long exp_limit)
Definition: ring.cc:2740
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition: ring.cc:1421
void rDebugPrint(const ring r)
Definition: ring.cc:4164
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:569
static int rGetCurrSyzLimit(const ring r)
Definition: ring.h:724
static BOOLEAN rField_is_Domain(const ring r)
Definition: ring.h:488
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:762
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:721
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:593
BOOLEAN rHasGlobalOrdering(const ring r)
Definition: ring.h:760
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:761
#define rField_is_Ring(R)
Definition: ring.h:486
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
int idElem(const ideal F)
count non-zero elements
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
#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:1026
#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