1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: kutil.cc,v 1.48 1999-11-02 17:15:31 Singular Exp $ */ |
---|
5 | /* |
---|
6 | * ABSTRACT: kernel: utils for kStd |
---|
7 | */ |
---|
8 | |
---|
9 | #include <stdlib.h> |
---|
10 | #include <string.h> |
---|
11 | #include "mod2.h" |
---|
12 | #include "tok.h" |
---|
13 | #include "febase.h" |
---|
14 | #include "mmemory.h" |
---|
15 | #include "numbers.h" |
---|
16 | #include "polys.h" |
---|
17 | #include "ring.h" |
---|
18 | #include "ideals.h" |
---|
19 | #include "timer.h" |
---|
20 | #include "cntrlc.h" |
---|
21 | #include "stairc.h" |
---|
22 | #include "subexpr.h" |
---|
23 | #include "kstd1.h" |
---|
24 | #include "kutil.h" |
---|
25 | |
---|
26 | static poly redMora (poly h,int maxIndex,kStrategy strat); |
---|
27 | static poly redBba (poly h,int maxIndex,kStrategy strat); |
---|
28 | |
---|
29 | BITSET test=(BITSET)0; |
---|
30 | int HCord; |
---|
31 | int Kstd1_deg; |
---|
32 | int mu=32000; |
---|
33 | |
---|
34 | /*2 |
---|
35 | *deletes higher monomial of p, re-compute ecart and length |
---|
36 | *works only for orderings with ecart =pFDeg(end)-pFDeg(start) |
---|
37 | */ |
---|
38 | void deleteHC(poly* p, int* e, int* l,kStrategy strat) |
---|
39 | { |
---|
40 | poly p1; |
---|
41 | |
---|
42 | if (strat->kHEdgeFound) |
---|
43 | { |
---|
44 | if (pComp(*p,strat->kNoether) == -1) |
---|
45 | { |
---|
46 | pDelete(p); |
---|
47 | *l = 0; |
---|
48 | *e = -1; |
---|
49 | return; |
---|
50 | } |
---|
51 | p1 = *p; |
---|
52 | while (pNext(p1)!=NULL) |
---|
53 | { |
---|
54 | if (pComp0(pNext(p1), strat->kNoether) == -1) |
---|
55 | pDelete(&pNext(p1)); |
---|
56 | else |
---|
57 | pIter(p1); |
---|
58 | } |
---|
59 | *e = pLDeg(*p,l)-pFDeg(*p); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | /*2 |
---|
64 | *tests if p.p=monomial*unit and cancels the unit |
---|
65 | */ |
---|
66 | void cancelunit (LObject* p) |
---|
67 | { |
---|
68 | int i; |
---|
69 | poly h; |
---|
70 | |
---|
71 | if(pIsVector((*p).p)) |
---|
72 | { |
---|
73 | if(!pOneComp((*p).p)) return; |
---|
74 | } |
---|
75 | if ((*p).ecart != 0) |
---|
76 | { |
---|
77 | for(i=1;i<=pVariables;i++) |
---|
78 | { |
---|
79 | if ((pGetExp((*p).p,1)>0) && (rIsPolyVar(i)==TRUE)) return; |
---|
80 | } |
---|
81 | h = pNext(((*p).p)); |
---|
82 | loop |
---|
83 | { |
---|
84 | if (h==NULL) |
---|
85 | { |
---|
86 | pDelete(&(pNext((*p).p))); |
---|
87 | (*p).ecart = 0; |
---|
88 | (*p).length = 1; |
---|
89 | return; |
---|
90 | } |
---|
91 | i = 0; |
---|
92 | loop |
---|
93 | { |
---|
94 | i++; |
---|
95 | if (pGetExp((*p).p,i) > pGetExp(h,i)) return ; |
---|
96 | if (i == pVariables) break; |
---|
97 | } |
---|
98 | pIter(h); |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | /*2 |
---|
104 | *pp is the new element in s |
---|
105 | *returns TRUE (in strat->kHEdgeFound) if |
---|
106 | *-HEcke is allowed |
---|
107 | *-we are in the last componente of the vector |
---|
108 | *-on all axis are monomials (all elements in NotUsedAxis are FALSE) |
---|
109 | *returns FALSE for pLexOrderings, |
---|
110 | *assumes in module case an ordering of type c* !! |
---|
111 | * HEckeTest is only called with strat->kHEdgeFound==FALSE ! |
---|
112 | */ |
---|
113 | void HEckeTest (poly pp,kStrategy strat) |
---|
114 | { |
---|
115 | int j,k,p; |
---|
116 | |
---|
117 | strat->kHEdgeFound=FALSE; |
---|
118 | if (pLexOrder) |
---|
119 | { |
---|
120 | return; |
---|
121 | } |
---|
122 | if (strat->ak > 1) /*we are in the module case*/ |
---|
123 | { |
---|
124 | return; // until .... |
---|
125 | //if (!pVectorOut) /*pVectorOut <=> order = c,* */ |
---|
126 | // return FALSE; |
---|
127 | //if (pGetComp(pp) < strat->ak) /* ak is the number of the last component */ |
---|
128 | // return FALSE; |
---|
129 | } |
---|
130 | k = 0; |
---|
131 | p=pIsPurePower(pp); |
---|
132 | if (p!=0) strat->NotUsedAxis[p] = FALSE; |
---|
133 | /*- the leading term of pp is a power of the p-th variable -*/ |
---|
134 | for (j=pVariables;j>0; j--) |
---|
135 | { |
---|
136 | if (strat->NotUsedAxis[j]) |
---|
137 | { |
---|
138 | return; |
---|
139 | } |
---|
140 | } |
---|
141 | strat->kHEdgeFound=TRUE; |
---|
142 | } |
---|
143 | |
---|
144 | /*2 |
---|
145 | *utilities for TSet, LSet |
---|
146 | */ |
---|
147 | inline static intset initec (int maxnr) |
---|
148 | { |
---|
149 | return (intset)Alloc(maxnr*sizeof(int)); |
---|
150 | } |
---|
151 | |
---|
152 | inline static unsigned long* initsevS (int maxnr) |
---|
153 | { |
---|
154 | return (unsigned long*)Alloc0(maxnr*sizeof(unsigned long)); |
---|
155 | } |
---|
156 | |
---|
157 | static inline void enlargeT (TSet* T,int* length,int incr) |
---|
158 | { |
---|
159 | *T = (TSet)ReAlloc0((ADDRESS)(*T),(*length)*sizeof(TObject), |
---|
160 | ((*length)+incr)*sizeof(TObject)); |
---|
161 | (*length) += incr; |
---|
162 | } |
---|
163 | |
---|
164 | void cleanT (kStrategy strat) |
---|
165 | { |
---|
166 | int i,j; |
---|
167 | poly p; |
---|
168 | |
---|
169 | for (j=0; j<=strat->tl; j++) |
---|
170 | { |
---|
171 | p = strat->T[j].p; |
---|
172 | strat->T[j].p=NULL; |
---|
173 | i = -1; |
---|
174 | loop |
---|
175 | { |
---|
176 | i++; |
---|
177 | if (i>strat->sl) |
---|
178 | { |
---|
179 | if (strat->T[j].heap != NULL) |
---|
180 | pHeapDelete(&p, strat->T[j].heap); |
---|
181 | else |
---|
182 | pDelete(&p); |
---|
183 | break; |
---|
184 | } |
---|
185 | if (p == strat->S[i]) |
---|
186 | { |
---|
187 | #if 0 |
---|
188 | if (strat->T[j].heap != NULL) |
---|
189 | strat->S[i] |
---|
190 | = pShallowCopyDelete(mm_specHeap, &p, strat->T[j].heap); |
---|
191 | #endif |
---|
192 | break; |
---|
193 | } |
---|
194 | } |
---|
195 | } |
---|
196 | strat->tl=-1; |
---|
197 | } |
---|
198 | |
---|
199 | LSet initL () |
---|
200 | { |
---|
201 | return (LSet)Alloc(setmax*sizeof(LObject)); |
---|
202 | } |
---|
203 | |
---|
204 | static inline void enlargeL (LSet* L,int* length,int incr) |
---|
205 | { |
---|
206 | LSet h; |
---|
207 | |
---|
208 | *L = (LSet)ReAlloc((ADDRESS)(*L),(*length)*sizeof(LObject), |
---|
209 | ((*length)+incr)*sizeof(LObject)); |
---|
210 | (*length) += incr; |
---|
211 | } |
---|
212 | |
---|
213 | void initPairtest(kStrategy strat) |
---|
214 | { |
---|
215 | strat->pairtest = (BOOLEAN *)Alloc0((strat->sl+2)*sizeof(BOOLEAN)); |
---|
216 | } |
---|
217 | |
---|
218 | /*2 |
---|
219 | *test whether (p1,p2) or (p2,p1) is in L up position length |
---|
220 | *it returns TRUE if yes and the position k |
---|
221 | */ |
---|
222 | BOOLEAN isInPairsetL(int length,poly p1,poly p2,int* k,kStrategy strat) |
---|
223 | { |
---|
224 | LObject *p=&(strat->L[length]); |
---|
225 | |
---|
226 | *k = length; |
---|
227 | loop |
---|
228 | { |
---|
229 | if ((*k) < 0) return FALSE; |
---|
230 | if (((p1 == (*p).p1) && (p2 == (*p).p2)) |
---|
231 | || ((p1 == (*p).p2) && (p2 == (*p).p1))) |
---|
232 | return TRUE; |
---|
233 | (*k)--; |
---|
234 | p--; |
---|
235 | } |
---|
236 | } |
---|
237 | |
---|
238 | /*2 |
---|
239 | *in B all pairs have the same element p on the right |
---|
240 | *it tests whether (q,p) is in B and returns TRUE if yes |
---|
241 | *and the position k |
---|
242 | */ |
---|
243 | BOOLEAN isInPairsetB(poly q,int* k,kStrategy strat) |
---|
244 | { |
---|
245 | LObject *p=&(strat->B[strat->Bl]); |
---|
246 | |
---|
247 | *k = strat->Bl; |
---|
248 | loop |
---|
249 | { |
---|
250 | if ((*k) < 0) return FALSE; |
---|
251 | if (q == (*p).p1) |
---|
252 | return TRUE; |
---|
253 | (*k)--; |
---|
254 | p--; |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | #ifdef KDEBUG |
---|
259 | BOOLEAN K_Test_L(char *f , int l, LObject *L, |
---|
260 | BOOLEAN testp, int lpos, TSet T, int tlength) |
---|
261 | { |
---|
262 | BOOLEAN ret = TRUE; |
---|
263 | |
---|
264 | if (testp) |
---|
265 | { |
---|
266 | if (! pDBTest(L->p, L->heap, f, l)) |
---|
267 | { |
---|
268 | Warn("for L->p"); |
---|
269 | ret = FALSE; |
---|
270 | } |
---|
271 | } |
---|
272 | |
---|
273 | if (L->pLength != 0 && L->pLength != pLength(L->p)) |
---|
274 | { |
---|
275 | Warn("L[%d] length error: has %d, specified to have %d", |
---|
276 | lpos, pLength(L->p), L->pLength); |
---|
277 | ret = FALSE; |
---|
278 | } |
---|
279 | if (L->p1 == NULL) |
---|
280 | { |
---|
281 | // L->p2 either NULL or poly from global heap |
---|
282 | ret &= pDBTest(L->p2, f, l); |
---|
283 | } |
---|
284 | else if (tlength > 0 && T != NULL) |
---|
285 | { |
---|
286 | // now p1 and p2 must be != NULL and must be contained in T |
---|
287 | int i; |
---|
288 | for (i=0; i<tlength; i++) |
---|
289 | if (L->p1 == T[i].p) break; |
---|
290 | if (i>=tlength) |
---|
291 | { |
---|
292 | Warn("L[%d].p1 not in T",lpos); |
---|
293 | ret = FALSE; |
---|
294 | } |
---|
295 | for (i=0; i<tlength; i++) |
---|
296 | if (L->p2 == T[i].p) break; |
---|
297 | if (i>=tlength) |
---|
298 | { |
---|
299 | Warn("L[%d].p2 not in T",lpos); |
---|
300 | ret &= FALSE; |
---|
301 | } |
---|
302 | } |
---|
303 | return ret; |
---|
304 | } |
---|
305 | |
---|
306 | BOOLEAN K_Test (char *f, int l, kStrategy strat, int pref) |
---|
307 | { |
---|
308 | int i; |
---|
309 | BOOLEAN ret = TRUE; |
---|
310 | // test P |
---|
311 | #ifdef MDEBUG |
---|
312 | if (pref >= 2) mmStartReferenceWatch(); |
---|
313 | #endif |
---|
314 | ret = K_Test_L(f, l, &(strat->P), |
---|
315 | (strat->P.p != NULL && pNext(strat->P.p) != strat->tail), |
---|
316 | -1, strat->T, strat->tl+1); |
---|
317 | |
---|
318 | if (ret == FALSE) |
---|
319 | { |
---|
320 | Warn("for strat->P"); |
---|
321 | } |
---|
322 | |
---|
323 | // test T |
---|
324 | if (strat->T != NULL) |
---|
325 | { |
---|
326 | #ifdef MDEBUG |
---|
327 | if (pref && pref <= 1) mmStartReferenceWatch(); |
---|
328 | #endif |
---|
329 | for (i=0; i<=strat->tl; i++) |
---|
330 | { |
---|
331 | if (K_Test_T(f, l, &(strat->T[i]), i) == FALSE) |
---|
332 | { |
---|
333 | ret = FALSE; |
---|
334 | } |
---|
335 | } |
---|
336 | } |
---|
337 | #ifdef MDEBUG |
---|
338 | if (pref) mmStopReferenceWatch(); |
---|
339 | #endif |
---|
340 | // test L |
---|
341 | if (strat->L != NULL) |
---|
342 | { |
---|
343 | for (i=0; i<=strat->Ll; i++) |
---|
344 | { |
---|
345 | if (strat->L[i].p == NULL) |
---|
346 | { |
---|
347 | Warn("L[%d].p is NULL", i); |
---|
348 | ret = FALSE; |
---|
349 | } |
---|
350 | if (K_Test_L(f, l, &(strat->L[i]), |
---|
351 | (pNext(strat->L[i].p) != strat->tail), i, |
---|
352 | strat->T, strat->tl + 1) == FALSE) |
---|
353 | { |
---|
354 | Warn("for strat->L[%d]", i); |
---|
355 | ret = FALSE; |
---|
356 | } |
---|
357 | } |
---|
358 | } |
---|
359 | // test S |
---|
360 | if (strat->S != NULL) |
---|
361 | ret = ret && K_Test_S(f, l, strat); |
---|
362 | |
---|
363 | return ret; |
---|
364 | } |
---|
365 | |
---|
366 | BOOLEAN K_Test_S(char* f, int l, kStrategy strat) |
---|
367 | { |
---|
368 | int i; |
---|
369 | BOOLEAN ret = TRUE; |
---|
370 | for (i=0; i<=strat->sl; i++) |
---|
371 | { |
---|
372 | if (strat->S[i] != NULL && strat->sevS[i] != 0 && strat->sevS[i] != |
---|
373 | pGetShortExpVector(strat->S[i])) |
---|
374 | { |
---|
375 | Warn("S[%d] wrong sev: has %o, specified to have %o in %s:%d", |
---|
376 | i , pGetShortExpVector(strat->S[i]), strat->sevS[i],f, l); |
---|
377 | ret = FALSE; |
---|
378 | } |
---|
379 | } |
---|
380 | return ret; |
---|
381 | } |
---|
382 | |
---|
383 | |
---|
384 | BOOLEAN K_Test_T(char* f, int l, TObject * T, int i) |
---|
385 | { |
---|
386 | BOOLEAN ret = pDBTest(T->p, T->heap, f, l); |
---|
387 | if (ret == FALSE) Warn("for T[%d]", i); |
---|
388 | if (T->pLength != 0 && |
---|
389 | T->pLength != pLength(T->p)) |
---|
390 | { |
---|
391 | Warn("T[%d] length error: has %d, specified to have %d in %s:%d", |
---|
392 | i , pLength(T->p), T->pLength,f, l); |
---|
393 | ret = FALSE; |
---|
394 | } |
---|
395 | if (T->sev != 0 && pGetShortExpVector(T->p) != T->sev) |
---|
396 | { |
---|
397 | Warn("T[%d] wrong sev: has %o, specified to have %o in %s:%d", |
---|
398 | i , pGetShortExpVector(T->p), T->sev,f, l); |
---|
399 | ret = FALSE; |
---|
400 | } |
---|
401 | return ret; |
---|
402 | } |
---|
403 | |
---|
404 | |
---|
405 | |
---|
406 | BOOLEAN K_Test_TS(char *f, int l, kStrategy strat) |
---|
407 | { |
---|
408 | int i, j; |
---|
409 | BOOLEAN ret = TRUE; |
---|
410 | K_Test(f, l, strat); |
---|
411 | |
---|
412 | // test S |
---|
413 | if (strat->S != NULL) |
---|
414 | { |
---|
415 | for (i=0; i<=strat->sl; i++) |
---|
416 | { |
---|
417 | for (j=0; j<=strat->tl; j++) |
---|
418 | if (strat->S[i] == strat->T[j].p) break; |
---|
419 | if (j > strat->tl) |
---|
420 | { |
---|
421 | Warn("S[%d] not in T", i); |
---|
422 | ret = FALSE; |
---|
423 | } |
---|
424 | } |
---|
425 | } |
---|
426 | return ret; |
---|
427 | } |
---|
428 | |
---|
429 | #endif |
---|
430 | |
---|
431 | /*2 |
---|
432 | *cancels the i-th polynomial in the standardbase s |
---|
433 | */ |
---|
434 | void deleteInS (int i,kStrategy strat) |
---|
435 | { |
---|
436 | int j; |
---|
437 | |
---|
438 | for (j=i; j<strat->sl; j++) |
---|
439 | { |
---|
440 | strat->S[j] = strat->S[j+1]; |
---|
441 | strat->ecartS[j] = strat->ecartS[j+1]; |
---|
442 | strat->sevS[j] = strat->sevS[j+1]; |
---|
443 | } |
---|
444 | if (strat->fromQ!=NULL) |
---|
445 | { |
---|
446 | for (j=i; j<strat->sl; j++) |
---|
447 | { |
---|
448 | strat->fromQ[j] = strat->fromQ[j+1]; |
---|
449 | } |
---|
450 | } |
---|
451 | strat->S[strat->sl] = NULL; |
---|
452 | strat->sl--; |
---|
453 | } |
---|
454 | |
---|
455 | /*2 |
---|
456 | *cancels the j-th polynomial in the set |
---|
457 | */ |
---|
458 | void deleteInL (LSet set, int *length, int j,kStrategy strat) |
---|
459 | { |
---|
460 | int i; |
---|
461 | |
---|
462 | if (set[j].lcm!=NULL) |
---|
463 | pFree1(set[j].lcm); |
---|
464 | if (set[j].p!=NULL) |
---|
465 | { |
---|
466 | if (pNext(set[j].p) == strat->tail) |
---|
467 | { |
---|
468 | pFree1(set[j].p); |
---|
469 | /*- tail belongs to several int spolys -*/ |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | // search p in T, if it is there, do not delete it |
---|
474 | int i=strat->tl; |
---|
475 | poly p=set[j].p; |
---|
476 | if (p!=NULL) |
---|
477 | loop |
---|
478 | { |
---|
479 | if (i < 0) |
---|
480 | { |
---|
481 | if (strat->next!=NULL) |
---|
482 | { |
---|
483 | strat=strat->next; |
---|
484 | i=strat->tl; |
---|
485 | } |
---|
486 | else |
---|
487 | { |
---|
488 | /* not found : */ |
---|
489 | pDelete(&p); |
---|
490 | break; |
---|
491 | } |
---|
492 | } |
---|
493 | else |
---|
494 | { |
---|
495 | if (strat->T[i].p==p) |
---|
496 | { |
---|
497 | /* found : */ |
---|
498 | p=NULL; |
---|
499 | break; |
---|
500 | } |
---|
501 | i--; |
---|
502 | } |
---|
503 | } |
---|
504 | } |
---|
505 | set[j].p=NULL; |
---|
506 | } |
---|
507 | if ((*length)>0) |
---|
508 | { |
---|
509 | for (i=j; i < (*length); i++) |
---|
510 | set[i] = set[i+1]; |
---|
511 | } |
---|
512 | #ifdef KDEBUG |
---|
513 | memset(&(set[*length]),0,sizeof(LObject)); |
---|
514 | #endif |
---|
515 | (*length)--; |
---|
516 | } |
---|
517 | |
---|
518 | /*2 |
---|
519 | *is used after updating the pairset,if the leading term of p |
---|
520 | *devides the leading term of some S[i] it will be canceled |
---|
521 | */ |
---|
522 | void clearS (poly p, int* at, int* k,kStrategy strat) |
---|
523 | { |
---|
524 | unsigned long sev = pGetShortExpVector(p); |
---|
525 | if (!pShortDivisibleBy(p,sev, strat->S[*at], ~ strat->sevS[*at])) return; |
---|
526 | deleteInS((*at),strat); |
---|
527 | (*at)--; |
---|
528 | (*k)--; |
---|
529 | } |
---|
530 | |
---|
531 | /*2 |
---|
532 | *enters p at position at in L |
---|
533 | */ |
---|
534 | void enterL (LSet *set,int *length, int *LSetmax, LObject p,int at) |
---|
535 | { |
---|
536 | int i; |
---|
537 | |
---|
538 | if ((*length)>=0) |
---|
539 | { |
---|
540 | if ((*length) == (*LSetmax)-1) enlargeL(set,LSetmax,setmax); |
---|
541 | for (i=(*length)+1; i>=at+1; i--) (*set)[i] = (*set)[i-1]; |
---|
542 | } |
---|
543 | else at = 0; |
---|
544 | (*set)[at] = p; |
---|
545 | (*length)++; |
---|
546 | } |
---|
547 | |
---|
548 | /*2 |
---|
549 | * computes the normal ecart; |
---|
550 | * used in mora case and if pLexOrder & sugar in bba case |
---|
551 | */ |
---|
552 | void initEcartNormal (LObject* h) |
---|
553 | { |
---|
554 | h->ecart = pLDeg(h->p,&(h->length))-pFDeg(h->p); |
---|
555 | } |
---|
556 | |
---|
557 | void initEcartBBA (LObject* h) |
---|
558 | { |
---|
559 | (*h).ecart = 0; |
---|
560 | //#ifdef KDEBUG |
---|
561 | (*h).length = 0; |
---|
562 | //#endif |
---|
563 | } |
---|
564 | |
---|
565 | void initEcartPairBba (LObject* Lp,poly f,poly g,int ecartF,int ecartG) |
---|
566 | { |
---|
567 | //#ifdef KDEBUG |
---|
568 | (*Lp).ecart = 0; |
---|
569 | (*Lp).length = 0; |
---|
570 | //#endif |
---|
571 | } |
---|
572 | |
---|
573 | void initEcartPairMora (LObject* Lp,poly f,poly g,int ecartF,int ecartG) |
---|
574 | { |
---|
575 | (*Lp).ecart = max(ecartF,ecartG); |
---|
576 | (*Lp).ecart = (*Lp).ecart-(pFDeg((*Lp).p)-pFDeg((*Lp).lcm)); |
---|
577 | //#ifdef KDEBUG |
---|
578 | (*Lp).length = 0; |
---|
579 | //#endif |
---|
580 | } |
---|
581 | |
---|
582 | /*2 |
---|
583 | *if ecart1<=ecart2 it returns TRUE |
---|
584 | */ |
---|
585 | BOOLEAN sugarDivisibleBy(int ecart1, int ecart2) |
---|
586 | { |
---|
587 | return (ecart1 <= ecart2); |
---|
588 | } |
---|
589 | |
---|
590 | /*2 |
---|
591 | * put the pair (s[i],p) into the set B, ecart=ecart(p) |
---|
592 | */ |
---|
593 | void enterOnePair (int i,poly p,int ecart, int isFromQ,kStrategy strat) |
---|
594 | { |
---|
595 | int l,j,compare; |
---|
596 | LObject Lp; |
---|
597 | |
---|
598 | #ifdef KDEBUG |
---|
599 | Lp.ecart=0; Lp.length=0; |
---|
600 | #endif |
---|
601 | /*- computes the lcm(s[i],p) -*/ |
---|
602 | Lp.lcm = pInit(); |
---|
603 | pLcm(p,strat->S[i],Lp.lcm); |
---|
604 | pSetm(Lp.lcm); |
---|
605 | if (strat->sugarCrit) |
---|
606 | { |
---|
607 | if( |
---|
608 | (!((strat->ecartS[i]>0)&&(ecart>0))) |
---|
609 | && pHasNotCF(p,strat->S[i])) |
---|
610 | { |
---|
611 | /* |
---|
612 | *the product criterion has applied for (s,p), |
---|
613 | *i.e. lcm(s,p)=product of the leading terms of s and p. |
---|
614 | *Suppose (s,r) is in L and the leading term |
---|
615 | *of p devides lcm(s,r) |
---|
616 | *(==> the leading term of p devides the leading term of r) |
---|
617 | *but the leading term of s does not devide the leading term of r |
---|
618 | *(notice that tis condition is automatically satisfied if r is still |
---|
619 | *in S), then (s,r) can be canceled. |
---|
620 | *This should be done here because the |
---|
621 | *case lcm(s,r)=lcm(s,p) is not covered by chainCrit. |
---|
622 | */ |
---|
623 | strat->cp++; |
---|
624 | pFree1(Lp.lcm); |
---|
625 | Lp.lcm=NULL; |
---|
626 | return; |
---|
627 | } |
---|
628 | else |
---|
629 | Lp.ecart = max(ecart,strat->ecartS[i]); |
---|
630 | if (strat->fromT && (strat->ecartS[i]>ecart)) |
---|
631 | { |
---|
632 | pFree1(Lp.lcm); |
---|
633 | Lp.lcm=NULL; |
---|
634 | return; |
---|
635 | /*the pair is (s[i],t[.]), discard it if the ecart is too big*/ |
---|
636 | } |
---|
637 | /* |
---|
638 | *the set B collects the pairs of type (S[j],p) |
---|
639 | *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p) |
---|
640 | *if the leading term of s devides lcm(r,p) then (r,p) will be canceled |
---|
641 | *if the leading term of r devides lcm(s,p) then (s,p) will not enter B |
---|
642 | */ |
---|
643 | { |
---|
644 | j = strat->Bl; |
---|
645 | loop |
---|
646 | { |
---|
647 | if (j < 0) break; |
---|
648 | compare=pDivComp(strat->B[j].lcm,Lp.lcm); |
---|
649 | if ((compare==1) |
---|
650 | &&(sugarDivisibleBy(strat->B[j].ecart,Lp.ecart))) |
---|
651 | { |
---|
652 | strat->c3++; |
---|
653 | if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0)) |
---|
654 | { |
---|
655 | pFree1(Lp.lcm); |
---|
656 | return; |
---|
657 | } |
---|
658 | break; |
---|
659 | } |
---|
660 | else |
---|
661 | if ((compare ==-1) |
---|
662 | && sugarDivisibleBy(Lp.ecart,strat->B[j].ecart)) |
---|
663 | { |
---|
664 | deleteInL(strat->B,&strat->Bl,j,strat); |
---|
665 | strat->c3++; |
---|
666 | } |
---|
667 | j--; |
---|
668 | } |
---|
669 | } |
---|
670 | } |
---|
671 | else /*sugarcrit*/ |
---|
672 | { |
---|
673 | if(/*(strat->ak==0) && productCrit(p,strat->S[i])*/ |
---|
674 | pHasNotCF(p,strat->S[i])) |
---|
675 | { |
---|
676 | /* |
---|
677 | *the product criterion has applied for (s,p), |
---|
678 | *i.e. lcm(s,p)=product of the leading terms of s and p. |
---|
679 | *Suppose (s,r) is in L and the leading term |
---|
680 | *of p devides lcm(s,r) |
---|
681 | *(==> the leading term of p devides the leading term of r) |
---|
682 | *but the leading term of s does not devide the leading term of r |
---|
683 | *(notice that tis condition is automatically satisfied if r is still |
---|
684 | *in S), then (s,r) can be canceled. |
---|
685 | *This should be done here because the |
---|
686 | *case lcm(s,r)=lcm(s,p) is not covered by chainCrit. |
---|
687 | */ |
---|
688 | strat->cp++; |
---|
689 | pFree1(Lp.lcm); |
---|
690 | Lp.lcm=NULL; |
---|
691 | return; |
---|
692 | } |
---|
693 | if (strat->fromT && (strat->ecartS[i]>ecart)) |
---|
694 | { |
---|
695 | pFree1(Lp.lcm); |
---|
696 | Lp.lcm=NULL; |
---|
697 | return; |
---|
698 | /*the pair is (s[i],t[.]), discard it if the ecart is too big*/ |
---|
699 | } |
---|
700 | /* |
---|
701 | *the set B collects the pairs of type (S[j],p) |
---|
702 | *suppose (r,p) is in B and (s,p) is the new pair and lcm(s,p)#lcm(r,p) |
---|
703 | *if the leading term of s devides lcm(r,p) then (r,p) will be canceled |
---|
704 | *if the leading term of r devides lcm(s,p) then (s,p) will not enter B |
---|
705 | */ |
---|
706 | for(j = strat->Bl;j>=0;j--) |
---|
707 | { |
---|
708 | compare=pDivComp(strat->B[j].lcm,Lp.lcm); |
---|
709 | if (compare==1) |
---|
710 | { |
---|
711 | strat->c3++; |
---|
712 | if ((strat->fromQ==NULL) || (isFromQ==0) || (strat->fromQ[i]==0)) |
---|
713 | { |
---|
714 | pFree1(Lp.lcm); |
---|
715 | return; |
---|
716 | } |
---|
717 | break; |
---|
718 | } |
---|
719 | else |
---|
720 | if (compare ==-1) |
---|
721 | { |
---|
722 | deleteInL(strat->B,&strat->Bl,j,strat); |
---|
723 | strat->c3++; |
---|
724 | } |
---|
725 | } |
---|
726 | } |
---|
727 | /* |
---|
728 | *the pair (S[i],p) enters B if the spoly != 0 |
---|
729 | */ |
---|
730 | /*- compute the short s-polynomial -*/ |
---|
731 | if (strat->fromT && !TEST_OPT_INTSTRATEGY) |
---|
732 | pNorm(p); |
---|
733 | if ((strat->S[i]==NULL) || (p==NULL)) |
---|
734 | return; |
---|
735 | if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0)) |
---|
736 | Lp.p=NULL; |
---|
737 | else |
---|
738 | { |
---|
739 | Lp.p = ksCreateShortSpoly(strat->S[i],p); |
---|
740 | } |
---|
741 | if (Lp.p == NULL) |
---|
742 | { |
---|
743 | /*- the case that the s-poly is 0 -*/ |
---|
744 | if (strat->pairtest==NULL) initPairtest(strat); |
---|
745 | strat->pairtest[i] = TRUE;/*- hint for spoly(S^[i],p)=0 -*/ |
---|
746 | strat->pairtest[strat->sl+1] = TRUE; |
---|
747 | /*hint for spoly(S[i],p) == 0 for some i,0 <= i <= sl*/ |
---|
748 | /* |
---|
749 | *suppose we have (s,r),(r,p),(s,p) and spoly(s,p) == 0 and (r,p) is |
---|
750 | *still in B (i.e. lcm(r,p) == lcm(s,p) or the leading term of s does not |
---|
751 | *devide lcm(r,p)). In the last case (s,r) can be canceled if the leading |
---|
752 | *term of p devides the lcm(s,r) |
---|
753 | *(this canceling should be done here because |
---|
754 | *the case lcm(s,p) == lcm(s,r) is not covered in chainCrit) |
---|
755 | *the first case is handeled in chainCrit |
---|
756 | */ |
---|
757 | if (Lp.lcm!=NULL) pFree1(Lp.lcm); |
---|
758 | } |
---|
759 | else |
---|
760 | { |
---|
761 | /*- the pair (S[i],p) enters B -*/ |
---|
762 | Lp.p1 = strat->S[i]; |
---|
763 | Lp.p2 = p; |
---|
764 | pNext(Lp.p) = strat->tail; |
---|
765 | strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart); |
---|
766 | if (TEST_OPT_INTSTRATEGY) |
---|
767 | { |
---|
768 | nDelete(&(Lp.p->coef)); |
---|
769 | } |
---|
770 | l = strat->posInL(strat->B,strat->Bl,Lp,strat); |
---|
771 | enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l); |
---|
772 | } |
---|
773 | } |
---|
774 | |
---|
775 | /*2 |
---|
776 | * put the pair (s[i],p) into the set L, ecart=ecart(p) |
---|
777 | * in the case that s forms a SB of (s) |
---|
778 | */ |
---|
779 | void enterOnePairSpecial (int i,poly p,int ecart,kStrategy strat) |
---|
780 | { |
---|
781 | int l,j,compare; |
---|
782 | LObject Lp; |
---|
783 | |
---|
784 | Lp.lcm = pInit(); |
---|
785 | pLcm(p,strat->S[i],Lp.lcm); |
---|
786 | pSetm(Lp.lcm); |
---|
787 | if(pHasNotCF(p,strat->S[i])) |
---|
788 | { |
---|
789 | strat->cp++; |
---|
790 | pFree1(Lp.lcm); |
---|
791 | Lp.lcm=NULL; |
---|
792 | return; |
---|
793 | } |
---|
794 | for(j = strat->Ll;j>=0;j--) |
---|
795 | { |
---|
796 | compare=pDivComp(strat->L[j].lcm,Lp.lcm); |
---|
797 | if ((compare==1) || (pEqual(strat->L[j].lcm,Lp.lcm))) |
---|
798 | { |
---|
799 | strat->c3++; |
---|
800 | pFree1(Lp.lcm); |
---|
801 | return; |
---|
802 | } |
---|
803 | else if (compare ==-1) |
---|
804 | { |
---|
805 | deleteInL(strat->L,&strat->Ll,j,strat); |
---|
806 | strat->c3++; |
---|
807 | } |
---|
808 | } |
---|
809 | /*- compute the short s-polynomial -*/ |
---|
810 | |
---|
811 | Lp.p = ksCreateShortSpoly(strat->S[i],p); |
---|
812 | if (Lp.p == NULL) |
---|
813 | { |
---|
814 | pFree1(Lp.lcm); |
---|
815 | } |
---|
816 | else |
---|
817 | { |
---|
818 | /*- the pair (S[i],p) enters B -*/ |
---|
819 | Lp.p1 = strat->S[i]; |
---|
820 | Lp.p2 = p; |
---|
821 | pNext(Lp.p) = strat->tail; |
---|
822 | strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart); |
---|
823 | if (TEST_OPT_INTSTRATEGY) |
---|
824 | { |
---|
825 | nDelete(&(Lp.p->coef)); |
---|
826 | } |
---|
827 | l = strat->posInL(strat->L,strat->Ll,Lp,strat); |
---|
828 | enterL(&strat->L,&strat->Ll,&strat->Lmax,Lp,l); |
---|
829 | } |
---|
830 | } |
---|
831 | |
---|
832 | /*2 |
---|
833 | *the pairset B of pairs of type (s[i],p) is complete now. It will be updated |
---|
834 | *using the chain-criterion in B and L and enters B to L |
---|
835 | */ |
---|
836 | void chainCrit (poly p,int ecart,kStrategy strat) |
---|
837 | { |
---|
838 | int i,j,l; |
---|
839 | |
---|
840 | /* |
---|
841 | *pairtest[i] is TRUE if spoly(S[i],p) == 0. |
---|
842 | *In this case all elements in B such |
---|
843 | *that their lcm is divisible by the leading term of S[i] can be canceled |
---|
844 | */ |
---|
845 | if (strat->pairtest!=NULL) |
---|
846 | { |
---|
847 | { |
---|
848 | /*- i.e. there is an i with pairtest[i]==TRUE -*/ |
---|
849 | for (j=0; j<=strat->sl; j++) |
---|
850 | { |
---|
851 | if (strat->pairtest[j]) |
---|
852 | { |
---|
853 | for (i=strat->Bl; i>=0; i--) |
---|
854 | { |
---|
855 | if (pDivisibleBy(strat->S[j],strat->B[i].lcm)) |
---|
856 | { |
---|
857 | deleteInL(strat->B,&strat->Bl,i,strat); |
---|
858 | strat->c3++; |
---|
859 | } |
---|
860 | } |
---|
861 | } |
---|
862 | } |
---|
863 | } |
---|
864 | Free((ADDRESS)strat->pairtest,(strat->sl+2)*sizeof(BOOLEAN)); |
---|
865 | strat->pairtest=NULL; |
---|
866 | } |
---|
867 | if (strat->Gebauer || strat->fromT) |
---|
868 | { |
---|
869 | if (strat->sugarCrit) |
---|
870 | { |
---|
871 | /* |
---|
872 | *suppose L[j] == (s,r) and p/lcm(s,r) |
---|
873 | *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p) |
---|
874 | *and in case the sugar is o.k. then L[j] can be canceled |
---|
875 | */ |
---|
876 | for (j=strat->Ll; j>=0; j--) |
---|
877 | { |
---|
878 | if (sugarDivisibleBy(ecart,strat->L[j].ecart) |
---|
879 | && ((pNext(strat->L[j].p) == strat->tail) || (pOrdSgn==1)) |
---|
880 | && pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm)) |
---|
881 | { |
---|
882 | if (strat->L[j].p == strat->tail) |
---|
883 | { |
---|
884 | deleteInL(strat->L,&strat->Ll,j,strat); |
---|
885 | strat->c3++; |
---|
886 | } |
---|
887 | } |
---|
888 | } |
---|
889 | /* |
---|
890 | *this is GEBAUER-MOELLER: |
---|
891 | *in B all elements with the same lcm except the "best" |
---|
892 | *(i.e. the last one in B with this property) will be canceled |
---|
893 | */ |
---|
894 | j = strat->Bl; |
---|
895 | loop /*cannot be changed into a for !!! */ |
---|
896 | { |
---|
897 | if (j <= 0) break; |
---|
898 | i = j-1; |
---|
899 | loop |
---|
900 | { |
---|
901 | if (i < 0) break; |
---|
902 | if (pEqual(strat->B[j].lcm,strat->B[i].lcm)) |
---|
903 | { |
---|
904 | strat->c3++; |
---|
905 | if (sugarDivisibleBy(strat->B[j].ecart,strat->B[i].ecart)) |
---|
906 | { |
---|
907 | deleteInL(strat->B,&strat->Bl,i,strat); |
---|
908 | j--; |
---|
909 | } |
---|
910 | else |
---|
911 | { |
---|
912 | deleteInL(strat->B,&strat->Bl,j,strat); |
---|
913 | break; |
---|
914 | } |
---|
915 | } |
---|
916 | i--; |
---|
917 | } |
---|
918 | j--; |
---|
919 | } |
---|
920 | } |
---|
921 | else /*sugarCrit*/ |
---|
922 | { |
---|
923 | /* |
---|
924 | *suppose L[j] == (s,r) and p/lcm(s,r) |
---|
925 | *and lcm(s,r)#lcm(s,p) and lcm(s,r)#lcm(r,p) |
---|
926 | *and in case the sugar is o.k. then L[j] can be canceled |
---|
927 | */ |
---|
928 | for (j=strat->Ll; j>=0; j--) |
---|
929 | { |
---|
930 | if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm)) |
---|
931 | { |
---|
932 | if ((pNext(strat->L[j].p) == strat->tail)||(pOrdSgn==1)) |
---|
933 | { |
---|
934 | deleteInL(strat->L,&strat->Ll,j,strat); |
---|
935 | strat->c3++; |
---|
936 | } |
---|
937 | } |
---|
938 | } |
---|
939 | /* |
---|
940 | *this is GEBAUER-MOELLER: |
---|
941 | *in B all elements with the same lcm except the "best" |
---|
942 | *(i.e. the last one in B with this property) will be canceled |
---|
943 | */ |
---|
944 | j = strat->Bl; |
---|
945 | loop /*cannot be changed into a for !!! */ |
---|
946 | { |
---|
947 | if (j <= 0) break; |
---|
948 | for(i=j-1; i>=0; i--) |
---|
949 | { |
---|
950 | if (pEqual(strat->B[j].lcm,strat->B[i].lcm)) |
---|
951 | { |
---|
952 | strat->c3++; |
---|
953 | deleteInL(strat->B,&strat->Bl,i,strat); |
---|
954 | j--; |
---|
955 | } |
---|
956 | } |
---|
957 | j--; |
---|
958 | } |
---|
959 | } |
---|
960 | /* |
---|
961 | *the elements of B enter L/their order with respect to B is kept |
---|
962 | *j = posInL(L,j,B[i]) would permutate the order |
---|
963 | *if once B is ordered different from L |
---|
964 | *then one should use j = posInL(L,Ll,B[i]) |
---|
965 | */ |
---|
966 | j = strat->Ll+1; |
---|
967 | for (i=strat->Bl; i>=0; i--) |
---|
968 | { |
---|
969 | j = strat->posInL(strat->L,j-1,strat->B[i],strat); |
---|
970 | enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j); |
---|
971 | } |
---|
972 | strat->Bl = -1; |
---|
973 | } |
---|
974 | else |
---|
975 | { |
---|
976 | for (j=strat->Ll; j>=0; j--) |
---|
977 | { |
---|
978 | if (pCompareChain(p,strat->L[j].p1,strat->L[j].p2,strat->L[j].lcm)) |
---|
979 | { |
---|
980 | if ((pNext(strat->L[j].p) == strat->tail)||(pOrdSgn==1)) |
---|
981 | { |
---|
982 | deleteInL(strat->L,&strat->Ll,j,strat); |
---|
983 | strat->c3++; |
---|
984 | } |
---|
985 | } |
---|
986 | } |
---|
987 | /* |
---|
988 | *this is our MODIFICATION of GEBAUER-MOELLER: |
---|
989 | *First the elements of B enter L, |
---|
990 | *then we fix a lcm and the "best" element in L |
---|
991 | *(i.e the last in L with this lcm and of type (s,p)) |
---|
992 | *and cancel all the other elements of type (r,p) with this lcm |
---|
993 | *except the case the element (s,r) has also the same lcm |
---|
994 | *and is on the worst position with respect to (s,p) and (r,p) |
---|
995 | */ |
---|
996 | /* |
---|
997 | *B enters to L/their order with respect to B is permutated for elements |
---|
998 | *B[i].p with the same leading term |
---|
999 | */ |
---|
1000 | j = strat->Ll; |
---|
1001 | for (i=strat->Bl; i>=0; i--) |
---|
1002 | { |
---|
1003 | j = strat->posInL(strat->L,j,strat->B[i],strat); |
---|
1004 | enterL(&strat->L,&strat->Ll,&strat->Lmax,strat->B[i],j); |
---|
1005 | } |
---|
1006 | strat->Bl = -1; |
---|
1007 | j = strat->Ll; |
---|
1008 | loop /*cannot be changed into a for !!! */ |
---|
1009 | { |
---|
1010 | if (j <= 0) |
---|
1011 | { |
---|
1012 | /*now L[0] cannot be canceled any more and the tail can be removed*/ |
---|
1013 | if (strat->L[0].p2 == strat->tail) strat->L[0].p2 = p; |
---|
1014 | break; |
---|
1015 | } |
---|
1016 | if (strat->L[j].p2 == p) |
---|
1017 | { |
---|
1018 | i = j-1; |
---|
1019 | loop |
---|
1020 | { |
---|
1021 | if (i < 0) break; |
---|
1022 | if ((strat->L[i].p2 == p) && pEqual(strat->L[j].lcm,strat->L[i].lcm)) |
---|
1023 | { |
---|
1024 | /*L[i] could be canceled but we search for a better one to cancel*/ |
---|
1025 | strat->c3++; |
---|
1026 | if (isInPairsetL(i-1,strat->L[j].p1,strat->L[i].p1,&l,strat) |
---|
1027 | && (pNext(strat->L[l].p) == strat->tail) |
---|
1028 | && (!pEqual(strat->L[i].p,strat->L[l].p)) |
---|
1029 | && pDivisibleBy(p,strat->L[l].lcm)) |
---|
1030 | { |
---|
1031 | /* |
---|
1032 | *"NOT equal(...)" because in case of "equal" the element L[l] |
---|
1033 | *is "older" and has to be from theoretical point of view behind |
---|
1034 | *L[i], but we do not want to reorder L |
---|
1035 | */ |
---|
1036 | strat->L[i].p2 = strat->tail; |
---|
1037 | /* |
---|
1038 | *L[l] will be canceled, we cannot cancel L[i] later on, |
---|
1039 | *so we mark it with "tail" |
---|
1040 | */ |
---|
1041 | deleteInL(strat->L,&strat->Ll,l,strat); |
---|
1042 | i--; |
---|
1043 | } |
---|
1044 | else |
---|
1045 | { |
---|
1046 | deleteInL(strat->L,&strat->Ll,i,strat); |
---|
1047 | } |
---|
1048 | j--; |
---|
1049 | } |
---|
1050 | i--; |
---|
1051 | } |
---|
1052 | } |
---|
1053 | else if (strat->L[j].p2 == strat->tail) |
---|
1054 | { |
---|
1055 | /*now L[j] cannot be canceled any more and the tail can be removed*/ |
---|
1056 | strat->L[j].p2 = p; |
---|
1057 | } |
---|
1058 | j--; |
---|
1059 | } |
---|
1060 | } |
---|
1061 | } |
---|
1062 | |
---|
1063 | /*2 |
---|
1064 | *(s[0],h),...,(s[k],h) will be put to the pairset L |
---|
1065 | */ |
---|
1066 | void initenterpairs (poly h,int k,int ecart,int isFromQ,kStrategy strat) |
---|
1067 | { |
---|
1068 | |
---|
1069 | if ((strat->syzComp==0) |
---|
1070 | || (pGetComp(h)<=strat->syzComp)) |
---|
1071 | { |
---|
1072 | int j; |
---|
1073 | BOOLEAN new_pair=FALSE; |
---|
1074 | |
---|
1075 | if (pGetComp(h)==0) |
---|
1076 | { |
---|
1077 | /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/ |
---|
1078 | if ((isFromQ)&&(strat->fromQ!=NULL)) |
---|
1079 | { |
---|
1080 | for (j=0; j<=k; j++) |
---|
1081 | { |
---|
1082 | if (!strat->fromQ[j]) |
---|
1083 | { |
---|
1084 | new_pair=TRUE; |
---|
1085 | enterOnePair(j,h,ecart,isFromQ,strat); |
---|
1086 | //Print("j:%d, Ll:%d\n",j,strat->Ll); |
---|
1087 | } |
---|
1088 | } |
---|
1089 | } |
---|
1090 | else |
---|
1091 | { |
---|
1092 | new_pair=TRUE; |
---|
1093 | for (j=0; j<=k; j++) |
---|
1094 | { |
---|
1095 | enterOnePair(j,h,ecart,isFromQ,strat); |
---|
1096 | //Print("j:%d, Ll:%d\n",j,strat->Ll); |
---|
1097 | } |
---|
1098 | } |
---|
1099 | } |
---|
1100 | else |
---|
1101 | { |
---|
1102 | for (j=0; j<=k; j++) |
---|
1103 | { |
---|
1104 | if ((pGetComp(h)==pGetComp(strat->S[j])) |
---|
1105 | || (pGetComp(strat->S[j])==0)) |
---|
1106 | { |
---|
1107 | new_pair=TRUE; |
---|
1108 | enterOnePair(j,h,ecart,isFromQ,strat); |
---|
1109 | //Print("j:%d, Ll:%d\n",j,strat->Ll); |
---|
1110 | } |
---|
1111 | } |
---|
1112 | } |
---|
1113 | if (new_pair) chainCrit(h,ecart,strat); |
---|
1114 | } |
---|
1115 | } |
---|
1116 | |
---|
1117 | /*2 |
---|
1118 | *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs) |
---|
1119 | *superfluous elements in S will be deleted |
---|
1120 | */ |
---|
1121 | void enterpairs (poly h,int k,int ecart,int pos,kStrategy strat) |
---|
1122 | { |
---|
1123 | int j=pos; |
---|
1124 | |
---|
1125 | initenterpairs(h,k,ecart,0,strat); |
---|
1126 | if ((!strat->fromT) |
---|
1127 | && ((strat->syzComp==0) |
---|
1128 | ||(pGetComp(h)<=strat->syzComp))) |
---|
1129 | { |
---|
1130 | //Print("start clearS k=%d, pos=%d, sl=%d\n",k,pos,strat->sl); |
---|
1131 | loop |
---|
1132 | { |
---|
1133 | if (j > k) break; |
---|
1134 | clearS(h,&j,&k,strat); |
---|
1135 | j++; |
---|
1136 | } |
---|
1137 | //Print("end clearS sl=%d\n",strat->sl); |
---|
1138 | } |
---|
1139 | // PrintS("end enterpairs\n"); |
---|
1140 | } |
---|
1141 | |
---|
1142 | /*2 |
---|
1143 | *(s[0],h),...,(s[k],h) will be put to the pairset L(via initenterpairs) |
---|
1144 | *superfluous elements in S will be deleted |
---|
1145 | */ |
---|
1146 | void enterpairsSpecial (poly h,int k,int ecart,int pos,kStrategy strat) |
---|
1147 | { |
---|
1148 | int j; |
---|
1149 | |
---|
1150 | for (j=0; j<=k; j++) |
---|
1151 | { |
---|
1152 | if ((pGetComp(h)==pGetComp(strat->S[j])) |
---|
1153 | || (0==pGetComp(strat->S[j]))) |
---|
1154 | { |
---|
1155 | enterOnePairSpecial(j,h,ecart,strat); |
---|
1156 | } |
---|
1157 | } |
---|
1158 | j=pos; |
---|
1159 | loop |
---|
1160 | { |
---|
1161 | if (j > k) break; |
---|
1162 | clearS(h,&j,&k,strat); |
---|
1163 | j++; |
---|
1164 | } |
---|
1165 | } |
---|
1166 | |
---|
1167 | /*2 |
---|
1168 | *constructs the pairset at the beginning |
---|
1169 | *of the buchberger/mora algorithm |
---|
1170 | */ |
---|
1171 | void pairs (kStrategy strat) |
---|
1172 | { |
---|
1173 | int j,i; |
---|
1174 | // Print("pairs:sl=%d\n",strat->sl); |
---|
1175 | // for (i=0; i<=strat->sl; i++) |
---|
1176 | // { |
---|
1177 | // Print("s%d:",i);pWrite(strat->S[i]); |
---|
1178 | // } |
---|
1179 | if (strat->fromQ!=NULL) |
---|
1180 | { |
---|
1181 | for (i=1; i<=strat->sl; i++) |
---|
1182 | { |
---|
1183 | initenterpairs(strat->S[i],i-1,strat->ecartS[i],strat->fromQ[i],strat); |
---|
1184 | } |
---|
1185 | } |
---|
1186 | else |
---|
1187 | { |
---|
1188 | for (i=1; i<=strat->sl; i++) |
---|
1189 | { |
---|
1190 | initenterpairs(strat->S[i],i-1,strat->ecartS[i],0,strat); |
---|
1191 | } |
---|
1192 | } |
---|
1193 | /*deletes superfluous elements in S*/ |
---|
1194 | i = -1; |
---|
1195 | loop |
---|
1196 | { |
---|
1197 | i++; |
---|
1198 | if (i >= strat->sl) break; |
---|
1199 | if ((strat->syzComp==0) || (pGetComp(strat->S[i])<=strat->syzComp)) |
---|
1200 | { |
---|
1201 | j=i; |
---|
1202 | loop |
---|
1203 | { |
---|
1204 | j++; |
---|
1205 | if (j > strat->sl) break; |
---|
1206 | if (pShortDivisibleBy(strat->S[i], strat->sevS[i], |
---|
1207 | strat->S[j], ~ strat->sevS[j])) |
---|
1208 | { |
---|
1209 | // Print("delete %d=",j); |
---|
1210 | // wrp(strat->S[j]); |
---|
1211 | // Print(" wegen %d=",i); |
---|
1212 | // wrp(strat->S[i]); |
---|
1213 | // Print("( fromQ=%d)\n", (strat->fromQ) ? strat->fromQ[j]:0); |
---|
1214 | if ((strat->fromQ==NULL) || (strat->fromQ[j]==0)) |
---|
1215 | { |
---|
1216 | deleteInS(j,strat); |
---|
1217 | j--; |
---|
1218 | } |
---|
1219 | } |
---|
1220 | } |
---|
1221 | } |
---|
1222 | } |
---|
1223 | } |
---|
1224 | |
---|
1225 | /*2 |
---|
1226 | *reorders s with respect to posInS, |
---|
1227 | *suc is the first changed index or zero |
---|
1228 | */ |
---|
1229 | void reorderS (int* suc,kStrategy strat) |
---|
1230 | { |
---|
1231 | int i,j,at,ecart; |
---|
1232 | int fq=0; |
---|
1233 | unsigned long sev; |
---|
1234 | poly p; |
---|
1235 | |
---|
1236 | *suc = -1; |
---|
1237 | for (i=1; i<=strat->sl; i++) |
---|
1238 | { |
---|
1239 | at = posInS(strat->S,i-1,strat->S[i]); |
---|
1240 | if (at != i) |
---|
1241 | { |
---|
1242 | if ((*suc > at) || (*suc == -1)) *suc = at; |
---|
1243 | p = strat->S[i]; |
---|
1244 | ecart = strat->ecartS[i]; |
---|
1245 | sev = strat->sevS[i]; |
---|
1246 | if (strat->fromQ!=NULL) fq=strat->fromQ[i]; |
---|
1247 | for (j=i; j>=at+1; j--) |
---|
1248 | { |
---|
1249 | strat->S[j] = strat->S[j-1]; |
---|
1250 | strat->ecartS[j] = strat->ecartS[j-1]; |
---|
1251 | strat->sevS[j] = strat->sevS[j-1]; |
---|
1252 | } |
---|
1253 | strat->S[at] = p; |
---|
1254 | strat->ecartS[at] = ecart; |
---|
1255 | strat->sevS[at] = sev; |
---|
1256 | if (strat->fromQ!=NULL) |
---|
1257 | { |
---|
1258 | for (j=i; j>=at+1; j--) |
---|
1259 | { |
---|
1260 | strat->fromQ[j] = strat->fromQ[j-1]; |
---|
1261 | } |
---|
1262 | strat->fromQ[at]=fq; |
---|
1263 | } |
---|
1264 | } |
---|
1265 | } |
---|
1266 | } |
---|
1267 | |
---|
1268 | |
---|
1269 | /*2 |
---|
1270 | *looks up the position of p in set |
---|
1271 | *set[0] is the smallest with respect to the ordering-procedure |
---|
1272 | *pComp |
---|
1273 | * Assumption: posInS only depends on the leading term |
---|
1274 | * otherwise, bba has to be changed |
---|
1275 | */ |
---|
1276 | int posInS (polyset set,int length,poly p) |
---|
1277 | { |
---|
1278 | if(length==-1) return 0; |
---|
1279 | int i; |
---|
1280 | int an = 0; |
---|
1281 | int en= length; |
---|
1282 | if (pMixedOrder) |
---|
1283 | { |
---|
1284 | int o=pWTotaldegree(p); |
---|
1285 | int oo=pWTotaldegree(set[length]); |
---|
1286 | |
---|
1287 | if ((oo<o) |
---|
1288 | || ((o==oo) && (pComp0(set[length],p)!= pOrdSgn))) |
---|
1289 | return length+1; |
---|
1290 | |
---|
1291 | loop |
---|
1292 | { |
---|
1293 | if (an >= en-1) |
---|
1294 | { |
---|
1295 | if ((pWTotaldegree(set[an])>=o) && (pComp0(set[an],p) == pOrdSgn)) |
---|
1296 | { |
---|
1297 | return an; |
---|
1298 | } |
---|
1299 | return en; |
---|
1300 | } |
---|
1301 | i=(an+en) / 2; |
---|
1302 | if ((pWTotaldegree(set[an])>=o) |
---|
1303 | && (pComp0(set[i],p) == pOrdSgn)) en=i; |
---|
1304 | else an=i; |
---|
1305 | } |
---|
1306 | } |
---|
1307 | else |
---|
1308 | { |
---|
1309 | if (pComp0(set[length],p)!= pOrdSgn) |
---|
1310 | return length+1; |
---|
1311 | |
---|
1312 | loop |
---|
1313 | { |
---|
1314 | if (an >= en-1) |
---|
1315 | { |
---|
1316 | if (pComp0(set[an],p) == pOrdSgn) return an; |
---|
1317 | return en; |
---|
1318 | } |
---|
1319 | i=(an+en) / 2; |
---|
1320 | if (pComp0(set[i],p) == pOrdSgn) en=i; |
---|
1321 | else an=i; |
---|
1322 | } |
---|
1323 | } |
---|
1324 | } |
---|
1325 | |
---|
1326 | |
---|
1327 | /*2 |
---|
1328 | * looks up the position of p in set |
---|
1329 | * the position is the last one |
---|
1330 | */ |
---|
1331 | int posInT0 (const TSet set,const int length,const LObject &p) |
---|
1332 | { |
---|
1333 | return (length+1); |
---|
1334 | } |
---|
1335 | |
---|
1336 | |
---|
1337 | /*2 |
---|
1338 | * looks up the position of p in T |
---|
1339 | * set[0] is the smallest with respect to the ordering-procedure |
---|
1340 | * pComp |
---|
1341 | */ |
---|
1342 | int posInT1 (const TSet set,const int length,const LObject &p) |
---|
1343 | { |
---|
1344 | if (length==-1) return 0; |
---|
1345 | |
---|
1346 | if (pComp0(set[length].p,p.p)!= pOrdSgn) return length+1; |
---|
1347 | |
---|
1348 | int i; |
---|
1349 | int an = 0; |
---|
1350 | int en= length; |
---|
1351 | |
---|
1352 | loop |
---|
1353 | { |
---|
1354 | if (an >= en-1) |
---|
1355 | { |
---|
1356 | if (pComp0(set[an].p,p.p) == pOrdSgn) return an; |
---|
1357 | return en; |
---|
1358 | } |
---|
1359 | i=(an+en) / 2; |
---|
1360 | if (pComp0(set[i].p,p.p) == pOrdSgn) en=i; |
---|
1361 | else an=i; |
---|
1362 | } |
---|
1363 | } |
---|
1364 | |
---|
1365 | /*2 |
---|
1366 | * looks up the position of p in T |
---|
1367 | * set[0] is the smallest with respect to the ordering-procedure |
---|
1368 | * length |
---|
1369 | */ |
---|
1370 | int posInT2 (const TSet set,const int length,const LObject &p) |
---|
1371 | { |
---|
1372 | if (length==-1) |
---|
1373 | return 0; |
---|
1374 | if (set[length].length<p.length) |
---|
1375 | return length+1; |
---|
1376 | |
---|
1377 | int i; |
---|
1378 | int an = 0; |
---|
1379 | int en= length; |
---|
1380 | |
---|
1381 | loop |
---|
1382 | { |
---|
1383 | if (an >= en-1) |
---|
1384 | { |
---|
1385 | if (set[an].length>p.length) return an; |
---|
1386 | return en; |
---|
1387 | } |
---|
1388 | i=(an+en) / 2; |
---|
1389 | if (set[i].length>p.length) en=i; |
---|
1390 | else an=i; |
---|
1391 | } |
---|
1392 | } |
---|
1393 | |
---|
1394 | /*2 |
---|
1395 | * looks up the position of p in T |
---|
1396 | * set[0] is the smallest with respect to the ordering-procedure |
---|
1397 | * totaldegree,pComp |
---|
1398 | */ |
---|
1399 | int posInT11 (const TSet set,const int length,const LObject &p) |
---|
1400 | /*{ |
---|
1401 | * int j=0; |
---|
1402 | * int o; |
---|
1403 | * |
---|
1404 | * o = pFDeg(p.p); |
---|
1405 | * loop |
---|
1406 | * { |
---|
1407 | * if ((pFDeg(set[j].p) > o) |
---|
1408 | * || ((pFDeg(set[j].p) == o) && (pComp0(set[j].p,p.p) == pOrdSgn))) |
---|
1409 | * { |
---|
1410 | * return j; |
---|
1411 | * } |
---|
1412 | * j++; |
---|
1413 | * if (j > length) return j; |
---|
1414 | * } |
---|
1415 | *} |
---|
1416 | */ |
---|
1417 | { |
---|
1418 | if (length==-1) return 0; |
---|
1419 | |
---|
1420 | int o = pFDeg(p.p); |
---|
1421 | int op = pFDeg(set[length].p); |
---|
1422 | |
---|
1423 | if ((op < o) |
---|
1424 | || ((op == o) && (pComp0(set[length].p,p.p) != pOrdSgn))) |
---|
1425 | return length+1; |
---|
1426 | |
---|
1427 | int i; |
---|
1428 | int an = 0; |
---|
1429 | int en= length; |
---|
1430 | |
---|
1431 | loop |
---|
1432 | { |
---|
1433 | if (an >= en-1) |
---|
1434 | { |
---|
1435 | op= pFDeg(set[an].p); |
---|
1436 | if ((op > o) |
---|
1437 | || (( op == o) && (pComp0(set[an].p,p.p) == pOrdSgn))) |
---|
1438 | return an; |
---|
1439 | return en; |
---|
1440 | } |
---|
1441 | i=(an+en) / 2; |
---|
1442 | op = pFDeg(set[i].p); |
---|
1443 | if (( op > o) |
---|
1444 | || (( op == o) && (pComp0(set[i].p,p.p) == pOrdSgn))) |
---|
1445 | en=i; |
---|
1446 | else |
---|
1447 | an=i; |
---|
1448 | } |
---|
1449 | } |
---|
1450 | |
---|
1451 | /*2 |
---|
1452 | * looks up the position of p in T |
---|
1453 | * set[0] is the smallest with respect to the ordering-procedure |
---|
1454 | * totaldegree,pComp |
---|
1455 | */ |
---|
1456 | int posInT110 (const TSet set,const int length,const LObject &p) |
---|
1457 | { |
---|
1458 | if (length==-1) return 0; |
---|
1459 | |
---|
1460 | int o = pFDeg(p.p); |
---|
1461 | int op = pFDeg(set[length].p); |
---|
1462 | |
---|
1463 | if (( op < o) |
---|
1464 | || (( op == o) && (set[length].length<p.length)) |
---|
1465 | || (( op == o) && (set[length].length == p.length) |
---|
1466 | && (pComp0(set[length].p,p.p) != pOrdSgn))) |
---|
1467 | return length+1; |
---|
1468 | |
---|
1469 | int i; |
---|
1470 | int an = 0; |
---|
1471 | int en= length; |
---|
1472 | loop |
---|
1473 | { |
---|
1474 | if (an >= en-1) |
---|
1475 | { |
---|
1476 | op = pFDeg(set[an].p); |
---|
1477 | if (( op > o) |
---|
1478 | || (( op == o) && (set[an].length > p.length)) |
---|
1479 | || (( op == o) && (set[an].length == p.length) |
---|
1480 | && (pComp0(set[an].p,p.p) == pOrdSgn))) |
---|
1481 | return an; |
---|
1482 | return en; |
---|
1483 | } |
---|
1484 | i=(an+en) / 2; |
---|
1485 | op = pFDeg(set[i].p); |
---|
1486 | if (( op > o) |
---|
1487 | || (( op == o) && (set[i].length > p.length)) |
---|
1488 | || (( op == o) && (set[i].length == p.length) |
---|
1489 | && (pComp0(set[i].p,p.p) == pOrdSgn))) |
---|
1490 | en=i; |
---|
1491 | else |
---|
1492 | an=i; |
---|
1493 | } |
---|
1494 | } |
---|
1495 | |
---|
1496 | /*2 |
---|
1497 | * looks up the position of p in set |
---|
1498 | * set[0] is the smallest with respect to the ordering-procedure |
---|
1499 | * pFDeg |
---|
1500 | */ |
---|
1501 | int posInT13 (const TSet set,const int length,const LObject &p) |
---|
1502 | { |
---|
1503 | if (length==-1) return 0; |
---|
1504 | |
---|
1505 | int o = pFDeg(p.p); |
---|
1506 | |
---|
1507 | if (pFDeg(set[length].p) <= o) |
---|
1508 | return length+1; |
---|
1509 | |
---|
1510 | int i; |
---|
1511 | int an = 0; |
---|
1512 | int en= length; |
---|
1513 | loop |
---|
1514 | { |
---|
1515 | if (an >= en-1) |
---|
1516 | { |
---|
1517 | if (pFDeg(set[an].p) > o) |
---|
1518 | return an; |
---|
1519 | return en; |
---|
1520 | } |
---|
1521 | i=(an+en) / 2; |
---|
1522 | if (pFDeg(set[i].p) > o) |
---|
1523 | en=i; |
---|
1524 | else |
---|
1525 | an=i; |
---|
1526 | } |
---|
1527 | } |
---|
1528 | |
---|
1529 | /*2 |
---|
1530 | * looks up the position of p in set |
---|
1531 | * set[0] is the smallest with respect to the ordering-procedure |
---|
1532 | * maximaldegree, pComp |
---|
1533 | */ |
---|
1534 | int posInT15 (const TSet set,const int length,const LObject &p) |
---|
1535 | /*{ |
---|
1536 | *int j=0; |
---|
1537 | * int o; |
---|
1538 | * |
---|
1539 | * o = pFDeg(p.p)+p.ecart; |
---|
1540 | * loop |
---|
1541 | * { |
---|
1542 | * if ((pFDeg(set[j].p)+set[j].ecart > o) |
---|
1543 | * || ((pFDeg(set[j].p)+set[j].ecart == o) |
---|
1544 | * && (pComp0(set[j].p,p.p) == pOrdSgn))) |
---|
1545 | * { |
---|
1546 | * return j; |
---|
1547 | * } |
---|
1548 | * j++; |
---|
1549 | * if (j > length) return j; |
---|
1550 | * } |
---|
1551 | *} |
---|
1552 | */ |
---|
1553 | { |
---|
1554 | if (length==-1) return 0; |
---|
1555 | |
---|
1556 | int o = pFDeg(p.p) + p.ecart; |
---|
1557 | int op = pFDeg(set[length].p)+set[length].ecart; |
---|
1558 | |
---|
1559 | if ((op < o) |
---|
1560 | || ((op == o) |
---|
1561 | && (pComp0(set[length].p,p.p) != pOrdSgn))) |
---|
1562 | return length+1; |
---|
1563 | |
---|
1564 | int i; |
---|
1565 | int an = 0; |
---|
1566 | int en= length; |
---|
1567 | loop |
---|
1568 | { |
---|
1569 | if (an >= en-1) |
---|
1570 | { |
---|
1571 | op = pFDeg(set[an].p)+set[an].ecart; |
---|
1572 | if (( op > o) |
---|
1573 | || (( op == o) && (pComp0(set[an].p,p.p) == pOrdSgn))) |
---|
1574 | return an; |
---|
1575 | return en; |
---|
1576 | } |
---|
1577 | i=(an+en) / 2; |
---|
1578 | op = pFDeg(set[i].p)+set[i].ecart; |
---|
1579 | if (( op > o) |
---|
1580 | || (( op == o) && (pComp0(set[i].p,p.p) == pOrdSgn))) |
---|
1581 | en=i; |
---|
1582 | else |
---|
1583 | an=i; |
---|
1584 | } |
---|
1585 | } |
---|
1586 | |
---|
1587 | /*2 |
---|
1588 | * looks up the position of p in set |
---|
1589 | * set[0] is the smallest with respect to the ordering-procedure |
---|
1590 | * pFDeg+ecart, ecart, pComp |
---|
1591 | */ |
---|
1592 | int posInT17 (const TSet set,const int length,const LObject &p) |
---|
1593 | /* |
---|
1594 | *{ |
---|
1595 | * int j=0; |
---|
1596 | * int o; |
---|
1597 | * |
---|
1598 | * o = pFDeg(p.p)+p.ecart; |
---|
1599 | * loop |
---|
1600 | * { |
---|
1601 | * if ((pFDeg(set[j].p)+set[j].ecart > o) |
---|
1602 | * || (((pFDeg(set[j].p)+set[j].ecart == o) |
---|
1603 | * && (set[j].ecart < p.ecart))) |
---|
1604 | * || ((pFDeg(set[j].p)+set[j].ecart == o) |
---|
1605 | * && (set[j].ecart==p.ecart) |
---|
1606 | * && (pComp0(set[j].p,p.p)==pOrdSgn))) |
---|
1607 | * return j; |
---|
1608 | * j++; |
---|
1609 | * if (j > length) return j; |
---|
1610 | * } |
---|
1611 | * } |
---|
1612 | */ |
---|
1613 | { |
---|
1614 | if (length==-1) return 0; |
---|
1615 | |
---|
1616 | int o = pFDeg(p.p) + p.ecart; |
---|
1617 | int op = pFDeg(set[length].p)+set[length].ecart; |
---|
1618 | |
---|
1619 | if ((op < o) |
---|
1620 | || (( op == o) && (set[length].ecart > p.ecart)) |
---|
1621 | || (( op == o) && (set[length].ecart==p.ecart) |
---|
1622 | && (pComp0(set[length].p,p.p) != pOrdSgn))) |
---|
1623 | return length+1; |
---|
1624 | |
---|
1625 | int i; |
---|
1626 | int an = 0; |
---|
1627 | int en= length; |
---|
1628 | loop |
---|
1629 | { |
---|
1630 | if (an >= en-1) |
---|
1631 | { |
---|
1632 | op = pFDeg(set[an].p)+set[an].ecart; |
---|
1633 | if (( op > o) |
---|
1634 | || (( op == o) && (set[an].ecart < p.ecart)) |
---|
1635 | || (( op == o) && (set[an].ecart==p.ecart) |
---|
1636 | && (pComp0(set[an].p,p.p) == pOrdSgn))) |
---|
1637 | return an; |
---|
1638 | return en; |
---|
1639 | } |
---|
1640 | i=(an+en) / 2; |
---|
1641 | op = pFDeg(set[i].p)+set[i].ecart; |
---|
1642 | if ((op > o) |
---|
1643 | || (( op == o) && (set[i].ecart < p.ecart)) |
---|
1644 | || (( op == o) && (set[i].ecart == p.ecart) |
---|
1645 | && (pComp0(set[i].p,p.p) == pOrdSgn))) |
---|
1646 | en=i; |
---|
1647 | else |
---|
1648 | an=i; |
---|
1649 | } |
---|
1650 | } |
---|
1651 | /*2 |
---|
1652 | * looks up the position of p in set |
---|
1653 | * set[0] is the smallest with respect to the ordering-procedure |
---|
1654 | * pGetComp, pFDeg+ecart, ecart, pComp |
---|
1655 | */ |
---|
1656 | int posInT17_c (const TSet set,const int length,const LObject &p) |
---|
1657 | { |
---|
1658 | if (length==-1) return 0; |
---|
1659 | |
---|
1660 | int cc = (-1+2*currRing->order[0]==ringorder_c); |
---|
1661 | /* cc==1 for (c,..), cc==-1 for (C,..) */ |
---|
1662 | int o = pFDeg(p.p) + p.ecart; |
---|
1663 | int c = pGetComp(p.p)*cc; |
---|
1664 | |
---|
1665 | if (pGetComp(set[length].p)*cc < c) |
---|
1666 | return length+1; |
---|
1667 | if (pGetComp(set[length].p)*cc == c) |
---|
1668 | { |
---|
1669 | int op = pFDeg(set[length].p)+set[length].ecart; |
---|
1670 | if ((op < o) |
---|
1671 | || ((op == o) && (set[length].ecart > p.ecart)) |
---|
1672 | || ((op == o) && (set[length].ecart==p.ecart) |
---|
1673 | && (pComp0(set[length].p,p.p) != pOrdSgn))) |
---|
1674 | return length+1; |
---|
1675 | } |
---|
1676 | |
---|
1677 | int i; |
---|
1678 | int an = 0; |
---|
1679 | int en= length; |
---|
1680 | loop |
---|
1681 | { |
---|
1682 | if (an >= en-1) |
---|
1683 | { |
---|
1684 | if (pGetComp(set[an].p)*cc < c) |
---|
1685 | return en; |
---|
1686 | if (pGetComp(set[an].p)*cc == c) |
---|
1687 | { |
---|
1688 | int op = pFDeg(set[an].p)+set[an].ecart; |
---|
1689 | if ((op > o) |
---|
1690 | || ((op == o) && (set[an].ecart < p.ecart)) |
---|
1691 | || ((op == o) && (set[an].ecart==p.ecart) |
---|
1692 | && (pComp0(set[an].p,p.p) == pOrdSgn))) |
---|
1693 | return an; |
---|
1694 | } |
---|
1695 | return en; |
---|
1696 | } |
---|
1697 | i=(an+en) / 2; |
---|
1698 | if (pGetComp(set[i].p)*cc > c) |
---|
1699 | en=i; |
---|
1700 | else if (pGetComp(set[i].p)*cc == c) |
---|
1701 | { |
---|
1702 | int op = pFDeg(set[i].p)+set[i].ecart; |
---|
1703 | if ((op > o) |
---|
1704 | || ((op == o) && (set[i].ecart < p.ecart)) |
---|
1705 | || ((op == o) && (set[i].ecart == p.ecart) |
---|
1706 | && (pComp0(set[i].p,p.p) == pOrdSgn))) |
---|
1707 | en=i; |
---|
1708 | else |
---|
1709 | an=i; |
---|
1710 | } |
---|
1711 | else |
---|
1712 | an=i; |
---|
1713 | } |
---|
1714 | } |
---|
1715 | |
---|
1716 | /*2 |
---|
1717 | * looks up the position of p in set |
---|
1718 | * set[0] is the smallest with respect to |
---|
1719 | * ecart, pFDeg, length |
---|
1720 | */ |
---|
1721 | int posInT19 (const TSet set,const int length,const LObject &p) |
---|
1722 | { |
---|
1723 | if (length==-1) return 0; |
---|
1724 | |
---|
1725 | int o = p.ecart; |
---|
1726 | |
---|
1727 | if (set[length].ecart < o) |
---|
1728 | return length+1; |
---|
1729 | if (set[length].ecart == o) |
---|
1730 | { |
---|
1731 | int oo=pFDeg(set[length].p); |
---|
1732 | int op=pFDeg(p.p); |
---|
1733 | if ((oo < op) || ((oo==op) && (set[length].length < p.length))) |
---|
1734 | return length+1; |
---|
1735 | } |
---|
1736 | |
---|
1737 | int i; |
---|
1738 | int an = 0; |
---|
1739 | int en= length; |
---|
1740 | loop |
---|
1741 | { |
---|
1742 | if (an >= en-1) |
---|
1743 | { |
---|
1744 | if (set[an].ecart > o) |
---|
1745 | return an; |
---|
1746 | if (set[an].ecart == o) |
---|
1747 | { |
---|
1748 | int oo=pFDeg(set[an].p); |
---|
1749 | int op=pFDeg(p.p); |
---|
1750 | if((oo > op) |
---|
1751 | || ((oo==op) && (set[an].length > p.length))) |
---|
1752 | return an; |
---|
1753 | } |
---|
1754 | return en; |
---|
1755 | } |
---|
1756 | i=(an+en) / 2; |
---|
1757 | if (set[i].ecart > o) |
---|
1758 | en=i; |
---|
1759 | else if (set[i].ecart == o) |
---|
1760 | { |
---|
1761 | int oo=pFDeg(set[i].p); |
---|
1762 | int op=pFDeg(p.p); |
---|
1763 | if ((oo > op) |
---|
1764 | || ((oo == op) && (set[i].length > p.length))) |
---|
1765 | en=i; |
---|
1766 | else |
---|
1767 | an=i; |
---|
1768 | } |
---|
1769 | else |
---|
1770 | an=i; |
---|
1771 | } |
---|
1772 | } |
---|
1773 | |
---|
1774 | /*2 |
---|
1775 | *looks up the position of polynomial p in set |
---|
1776 | *set[length] is the smallest element in set with respect |
---|
1777 | *to the ordering-procedure pComp |
---|
1778 | */ |
---|
1779 | int posInLSpecial (const LSet set, const int length, |
---|
1780 | const LObject &p,const kStrategy strat) |
---|
1781 | { |
---|
1782 | if (length<0) return 0; |
---|
1783 | |
---|
1784 | int d=pFDeg(p.p); |
---|
1785 | int op=pFDeg(set[length].p); |
---|
1786 | |
---|
1787 | if ((op > d) |
---|
1788 | || ((op == d) && (p.p1!=NULL)&&(set[length].p1==NULL)) |
---|
1789 | || (pComp0(set[length].p,p.p)== pOrdSgn)) |
---|
1790 | return length+1; |
---|
1791 | |
---|
1792 | int i; |
---|
1793 | int an = 0; |
---|
1794 | int en= length; |
---|
1795 | loop |
---|
1796 | { |
---|
1797 | if (an >= en-1) |
---|
1798 | { |
---|
1799 | op=pFDeg(set[an].p); |
---|
1800 | if ((op > d) |
---|
1801 | || ((op == d) && (p.p1!=NULL) && (set[an].p1==NULL)) |
---|
1802 | || (pComp0(set[an].p,p.p)== pOrdSgn)) |
---|
1803 | return en; |
---|
1804 | return an; |
---|
1805 | } |
---|
1806 | i=(an+en) / 2; |
---|
1807 | op=pFDeg(set[i].p); |
---|
1808 | if ((op>d) |
---|
1809 | || ((op==d) && (p.p1!=NULL) && (set[i].p1==NULL)) |
---|
1810 | || (pComp0(set[i].p,p.p) == pOrdSgn)) |
---|
1811 | an=i; |
---|
1812 | else |
---|
1813 | en=i; |
---|
1814 | } |
---|
1815 | } |
---|
1816 | |
---|
1817 | /*2 |
---|
1818 | *looks up the position of polynomial p in set |
---|
1819 | *set[length] is the smallest element in set with respect |
---|
1820 | *to the ordering-procedure pComp |
---|
1821 | */ |
---|
1822 | int posInL0 (const LSet set, const int length, |
---|
1823 | const LObject &p,const kStrategy strat) |
---|
1824 | { |
---|
1825 | if (length<0) return 0; |
---|
1826 | |
---|
1827 | if (pComp0(set[length].p,p.p)== pOrdSgn) |
---|
1828 | return length+1; |
---|
1829 | |
---|
1830 | int i; |
---|
1831 | int an = 0; |
---|
1832 | int en= length; |
---|
1833 | loop |
---|
1834 | { |
---|
1835 | if (an >= en-1) |
---|
1836 | { |
---|
1837 | if (pComp0(set[an].p,p.p) == pOrdSgn) return en; |
---|
1838 | return an; |
---|
1839 | } |
---|
1840 | i=(an+en) / 2; |
---|
1841 | if (pComp0(set[i].p,p.p) == pOrdSgn) an=i; |
---|
1842 | else en=i; |
---|
1843 | /*aend. fuer lazy == in !=- machen */ |
---|
1844 | } |
---|
1845 | } |
---|
1846 | |
---|
1847 | /*2 |
---|
1848 | * looks up the position of polynomial p in set |
---|
1849 | * e is the ecart of p |
---|
1850 | * set[length] is the smallest element in set with respect |
---|
1851 | * to the ordering-procedure totaldegree,pComp |
---|
1852 | */ |
---|
1853 | int posInL11 (const LSet set, const int length, |
---|
1854 | const LObject &p,const kStrategy strat) |
---|
1855 | /*{ |
---|
1856 | * int j=0; |
---|
1857 | * int o; |
---|
1858 | * |
---|
1859 | * o = pFDeg(p.p); |
---|
1860 | * loop |
---|
1861 | * { |
---|
1862 | * if (j > length) return j; |
---|
1863 | * if ((pFDeg(set[j].p) < o)) return j; |
---|
1864 | * if ((pFDeg(set[j].p) == o) && (pComp0(set[j].p,p.p) == -pOrdSgn)) |
---|
1865 | * { |
---|
1866 | * return j; |
---|
1867 | * } |
---|
1868 | * j++; |
---|
1869 | * } |
---|
1870 | *} |
---|
1871 | */ |
---|
1872 | { |
---|
1873 | if (length<0) return 0; |
---|
1874 | |
---|
1875 | int o = pFDeg(p.p); |
---|
1876 | int op = pFDeg(set[length].p); |
---|
1877 | |
---|
1878 | if ((op > o) |
---|
1879 | || ((op == o) && (pComp0(set[length].p,p.p) != -pOrdSgn))) |
---|
1880 | return length+1; |
---|
1881 | int i; |
---|
1882 | int an = 0; |
---|
1883 | int en= length; |
---|
1884 | loop |
---|
1885 | { |
---|
1886 | if (an >= en-1) |
---|
1887 | { |
---|
1888 | op = pFDeg(set[an].p); |
---|
1889 | if ((op > o) |
---|
1890 | || ((op == o) && (pComp0(set[an].p,p.p) != -pOrdSgn))) |
---|
1891 | return en; |
---|
1892 | return an; |
---|
1893 | } |
---|
1894 | i=(an+en) / 2; |
---|
1895 | op = pFDeg(set[i].p); |
---|
1896 | if ((op > o) |
---|
1897 | || ((op == o) && (pComp0(set[i].p,p.p) != -pOrdSgn))) |
---|
1898 | an=i; |
---|
1899 | else |
---|
1900 | en=i; |
---|
1901 | } |
---|
1902 | } |
---|
1903 | |
---|
1904 | /*2 |
---|
1905 | * looks up the position of polynomial p in set |
---|
1906 | * set[length] is the smallest element in set with respect |
---|
1907 | * to the ordering-procedure totaldegree,pLength0 |
---|
1908 | */ |
---|
1909 | int posInL110 (const LSet set, const int length, |
---|
1910 | const LObject &p,const kStrategy strat) |
---|
1911 | { |
---|
1912 | if (length<0) return 0; |
---|
1913 | |
---|
1914 | int o = pFDeg(p.p); |
---|
1915 | int op = pFDeg(set[length].p); |
---|
1916 | |
---|
1917 | if ((op > o) |
---|
1918 | || ((op == o) && (set[length].length >2*p.length)) |
---|
1919 | || ((op == o) && (set[length].length <= 2*p.length) |
---|
1920 | && (pComp0(set[length].p,p.p) != -pOrdSgn))) |
---|
1921 | return length+1; |
---|
1922 | int i; |
---|
1923 | int an = 0; |
---|
1924 | int en= length; |
---|
1925 | loop |
---|
1926 | { |
---|
1927 | if (an >= en-1) |
---|
1928 | { |
---|
1929 | op = pFDeg(set[an].p); |
---|
1930 | if ((op > o) |
---|
1931 | || ((op == o) && (set[an].length >2*p.length)) |
---|
1932 | || ((op == o) && (set[an].length <=2*p.length) |
---|
1933 | && (pComp0(set[an].p,p.p) != -pOrdSgn))) |
---|
1934 | return en; |
---|
1935 | return an; |
---|
1936 | } |
---|
1937 | i=(an+en) / 2; |
---|
1938 | op = pFDeg(set[i].p); |
---|
1939 | if ((op > o) |
---|
1940 | || ((op == o) && (set[i].length > 2*p.length)) |
---|
1941 | || ((op == o) && (set[i].length <= 2*p.length) |
---|
1942 | && (pComp0(set[i].p,p.p) != -pOrdSgn))) |
---|
1943 | an=i; |
---|
1944 | else |
---|
1945 | en=i; |
---|
1946 | } |
---|
1947 | } |
---|
1948 | |
---|
1949 | /*2 |
---|
1950 | * looks up the position of polynomial p in set |
---|
1951 | * e is the ecart of p |
---|
1952 | * set[length] is the smallest element in set with respect |
---|
1953 | * to the ordering-procedure totaldegree |
---|
1954 | */ |
---|
1955 | int posInL13 (const LSet set, const int length, |
---|
1956 | const LObject &p,const kStrategy strat) |
---|
1957 | { |
---|
1958 | if (length<0) return 0; |
---|
1959 | |
---|
1960 | int o = pFDeg(p.p); |
---|
1961 | |
---|
1962 | if (pFDeg(set[length].p) > o) |
---|
1963 | return length+1; |
---|
1964 | |
---|
1965 | int i; |
---|
1966 | int an = 0; |
---|
1967 | int en= length; |
---|
1968 | loop |
---|
1969 | { |
---|
1970 | if (an >= en-1) |
---|
1971 | { |
---|
1972 | if (pFDeg(set[an].p) >= o) |
---|
1973 | return en; |
---|
1974 | return an; |
---|
1975 | } |
---|
1976 | i=(an+en) / 2; |
---|
1977 | if (pFDeg(set[i].p) >= o) |
---|
1978 | an=i; |
---|
1979 | else |
---|
1980 | en=i; |
---|
1981 | } |
---|
1982 | } |
---|
1983 | |
---|
1984 | /*2 |
---|
1985 | * looks up the position of polynomial p in set |
---|
1986 | * e is the ecart of p |
---|
1987 | * set[length] is the smallest element in set with respect |
---|
1988 | * to the ordering-procedure maximaldegree,pComp |
---|
1989 | */ |
---|
1990 | int posInL15 (const LSet set, const int length, |
---|
1991 | const LObject &p,const kStrategy strat) |
---|
1992 | /*{ |
---|
1993 | * int j=0; |
---|
1994 | * int o; |
---|
1995 | * |
---|
1996 | * o = p.ecart+pFDeg(p.p); |
---|
1997 | * loop |
---|
1998 | * { |
---|
1999 | * if (j > length) return j; |
---|
2000 | * if (pFDeg(set[j].p)+set[j].ecart < o) return j; |
---|
2001 | * if ((pFDeg(set[j].p)+set[j].ecart == o) |
---|
2002 | * && (pComp0(set[j].p,p.p) == -pOrdSgn)) |
---|
2003 | * { |
---|
2004 | * return j; |
---|
2005 | * } |
---|
2006 | * j++; |
---|
2007 | * } |
---|
2008 | *} |
---|
2009 | */ |
---|
2010 | { |
---|
2011 | if (length<0) return 0; |
---|
2012 | |
---|
2013 | int o = pFDeg(p.p) + p.ecart; |
---|
2014 | int op = pFDeg(set[length].p) + set[length].ecart; |
---|
2015 | |
---|
2016 | if ((op > o) |
---|
2017 | || ((op == o) && (pComp0(set[length].p,p.p) != -pOrdSgn))) |
---|
2018 | return length+1; |
---|
2019 | int i; |
---|
2020 | int an = 0; |
---|
2021 | int en= length; |
---|
2022 | loop |
---|
2023 | { |
---|
2024 | if (an >= en-1) |
---|
2025 | { |
---|
2026 | op = pFDeg(set[an].p) + set[an].ecart; |
---|
2027 | if ((op > o) |
---|
2028 | || ((op == o) && (pComp0(set[an].p,p.p) != -pOrdSgn))) |
---|
2029 | return en; |
---|
2030 | return an; |
---|
2031 | } |
---|
2032 | i=(an+en) / 2; |
---|
2033 | op = pFDeg(set[i].p) + set[i].ecart; |
---|
2034 | if ((op > o) |
---|
2035 | || ((op == o) && (pComp0(set[i].p,p.p) != -pOrdSgn))) |
---|
2036 | an=i; |
---|
2037 | else |
---|
2038 | en=i; |
---|
2039 | } |
---|
2040 | } |
---|
2041 | |
---|
2042 | /*2 |
---|
2043 | * looks up the position of polynomial p in set |
---|
2044 | * e is the ecart of p |
---|
2045 | * set[length] is the smallest element in set with respect |
---|
2046 | * to the ordering-procedure totaldegree |
---|
2047 | */ |
---|
2048 | int posInL17 (const LSet set, const int length, |
---|
2049 | const LObject &p,const kStrategy strat) |
---|
2050 | { |
---|
2051 | if (length<0) return 0; |
---|
2052 | |
---|
2053 | int o = pFDeg(p.p) + p.ecart; |
---|
2054 | |
---|
2055 | if ((pFDeg(set[length].p) + set[length].ecart > o) |
---|
2056 | || ((pFDeg(set[length].p) + set[length].ecart == o) |
---|
2057 | && (set[length].ecart > p.ecart)) |
---|
2058 | || ((pFDeg(set[length].p) + set[length].ecart == o) |
---|
2059 | && (set[length].ecart == p.ecart) |
---|
2060 | && (pComp0(set[length].p,p.p) != -pOrdSgn))) |
---|
2061 | return length+1; |
---|
2062 | int i; |
---|
2063 | int an = 0; |
---|
2064 | int en= length; |
---|
2065 | loop |
---|
2066 | { |
---|
2067 | if (an >= en-1) |
---|
2068 | { |
---|
2069 | if ((pFDeg(set[an].p) + set[an].ecart > o) |
---|
2070 | || ((pFDeg(set[an].p) + set[an].ecart == o) |
---|
2071 | && (set[an].ecart > p.ecart)) |
---|
2072 | || ((pFDeg(set[an].p) + set[an].ecart == o) |
---|
2073 | && (set[an].ecart == p.ecart) |
---|
2074 | && (pComp0(set[an].p,p.p) != -pOrdSgn))) |
---|
2075 | return en; |
---|
2076 | return an; |
---|
2077 | } |
---|
2078 | i=(an+en) / 2; |
---|
2079 | if ((pFDeg(set[i].p) + set[i].ecart > o) |
---|
2080 | || ((pFDeg(set[i].p) + set[i].ecart == o) |
---|
2081 | && (set[i].ecart > p.ecart)) |
---|
2082 | || ((pFDeg(set[i].p) +set[i].ecart == o) |
---|
2083 | && (set[i].ecart == p.ecart) |
---|
2084 | && (pComp0(set[i].p,p.p) != -pOrdSgn))) |
---|
2085 | an=i; |
---|
2086 | else |
---|
2087 | en=i; |
---|
2088 | } |
---|
2089 | } |
---|
2090 | #if 0 |
---|
2091 | { |
---|
2092 | if (length<0) return 0; |
---|
2093 | |
---|
2094 | int o = pFDeg(p.p) + p.ecart; |
---|
2095 | int ol = pFDeg(set[length].p) + set[length].ecart; |
---|
2096 | |
---|
2097 | if ((ol > o) |
---|
2098 | || ((ol == o) |
---|
2099 | && (set[length].ecart > p.ecart)) |
---|
2100 | || ((ol == o) |
---|
2101 | && (set[length].ecart == p.ecart) |
---|
2102 | //&& (set[length].lp+set[length].length > p.lp+p.length)) |
---|
2103 | && (set[length].length > p.length)) |
---|
2104 | || ((ol == o) |
---|
2105 | && (set[length].ecart == p.ecart) |
---|
2106 | //&& (set[length].lp+set[length].length == p.lp+p.length) |
---|
2107 | && (set[length].length == p.length) |
---|
2108 | && (pComp0(set[length].p,p.p) != -pOrdSgn))) |
---|
2109 | return length+1; |
---|
2110 | int i; |
---|
2111 | int an = 0; |
---|
2112 | int en= length; |
---|
2113 | loop |
---|
2114 | { |
---|
2115 | if (an >= en-1) |
---|
2116 | { |
---|
2117 | ol = pFDeg(set[an].p) + set[an].ecart; |
---|
2118 | if ((ol > o) |
---|
2119 | || ((ol == o) |
---|
2120 | && (set[an].ecart > p.ecart)) |
---|
2121 | || ((ol == o) |
---|
2122 | && (set[an].ecart == p.ecart) |
---|
2123 | //&& (set[length].lp+set[length].length > p.lp+p.length)) |
---|
2124 | && (set[length].length > p.length)) |
---|
2125 | || ((ol == o) |
---|
2126 | && (set[an].ecart == p.ecart) |
---|
2127 | //&& (set[length].lp+set[length].length == p.lp+p.length) |
---|
2128 | && (set[length].length == p.length) |
---|
2129 | && (pComp0(set[an].p,p.p) != -pOrdSgn))) |
---|
2130 | return en; |
---|
2131 | return an; |
---|
2132 | } |
---|
2133 | i=(an+en) / 2; |
---|
2134 | ol = pFDeg(set[i].p) + set[i].ecart; |
---|
2135 | if ((ol > o) |
---|
2136 | || ((ol == o) |
---|
2137 | && (set[i].ecart > p.ecart)) |
---|
2138 | || ((ol == o) |
---|
2139 | && (set[i].ecart == p.ecart) |
---|
2140 | //&& (set[i].lp+set[i].length > p.lp+p.length)) |
---|
2141 | && (set[i].length > p.length)) |
---|
2142 | || ((ol == o) |
---|
2143 | && (set[i].ecart == p.ecart) |
---|
2144 | //&& (set[i].lp+set[i].length == p.lp+p.length) |
---|
2145 | && (set[i].length == p.length) |
---|
2146 | && (pComp0(set[i].p,p.p) != -pOrdSgn))) |
---|
2147 | an=i; |
---|
2148 | else |
---|
2149 | en=i; |
---|
2150 | } |
---|
2151 | } |
---|
2152 | #endif |
---|
2153 | /*2 |
---|
2154 | * looks up the position of polynomial p in set |
---|
2155 | * e is the ecart of p |
---|
2156 | * set[length] is the smallest element in set with respect |
---|
2157 | * to the ordering-procedure pComp |
---|
2158 | */ |
---|
2159 | int posInL17_c (const LSet set, const int length, |
---|
2160 | const LObject &p,const kStrategy strat) |
---|
2161 | { |
---|
2162 | if (length<0) return 0; |
---|
2163 | |
---|
2164 | int cc = (-1+2*currRing->order[0]==ringorder_c); |
---|
2165 | /* cc==1 for (c,..), cc==-1 for (C,..) */ |
---|
2166 | int c = pGetComp(p.p)*cc; |
---|
2167 | int o = pFDeg(p.p) + p.ecart; |
---|
2168 | |
---|
2169 | if (pGetComp(set[length].p)*cc > c) |
---|
2170 | return length+1; |
---|
2171 | if (pGetComp(set[length].p)*cc == c) |
---|
2172 | { |
---|
2173 | if ((pFDeg(set[length].p) + set[length].ecart > o) |
---|
2174 | || ((pFDeg(set[length].p) + set[length].ecart == o) |
---|
2175 | && (set[length].ecart > p.ecart)) |
---|
2176 | || ((pFDeg(set[length].p) + set[length].ecart == o) |
---|
2177 | && (set[length].ecart == p.ecart) |
---|
2178 | && (pComp0(set[length].p,p.p) != -pOrdSgn))) |
---|
2179 | return length+1; |
---|
2180 | } |
---|
2181 | int i; |
---|
2182 | int an = 0; |
---|
2183 | int en= length; |
---|
2184 | loop |
---|
2185 | { |
---|
2186 | if (an >= en-1) |
---|
2187 | { |
---|
2188 | if (pGetComp(set[an].p)*cc > c) |
---|
2189 | return en; |
---|
2190 | if (pGetComp(set[an].p)*cc == c) |
---|
2191 | { |
---|
2192 | if ((pFDeg(set[an].p) + set[an].ecart > o) |
---|
2193 | || ((pFDeg(set[an].p) + set[an].ecart == o) |
---|
2194 | && (set[an].ecart > p.ecart)) |
---|
2195 | || ((pFDeg(set[an].p) + set[an].ecart == o) |
---|
2196 | && (set[an].ecart == p.ecart) |
---|
2197 | && (pComp0(set[an].p,p.p) != -pOrdSgn))) |
---|
2198 | return en; |
---|
2199 | } |
---|
2200 | return an; |
---|
2201 | } |
---|
2202 | i=(an+en) / 2; |
---|
2203 | if (pGetComp(set[i].p)*cc > c) |
---|
2204 | an=i; |
---|
2205 | else if (pGetComp(set[i].p)*cc == c) |
---|
2206 | { |
---|
2207 | if ((pFDeg(set[i].p) + set[i].ecart > o) |
---|
2208 | || ((pFDeg(set[i].p) + set[i].ecart == o) |
---|
2209 | && (set[i].ecart > p.ecart)) |
---|
2210 | || ((pFDeg(set[i].p) +set[i].ecart == o) |
---|
2211 | && (set[i].ecart == p.ecart) |
---|
2212 | && (pComp0(set[i].p,p.p) != -pOrdSgn))) |
---|
2213 | an=i; |
---|
2214 | else |
---|
2215 | en=i; |
---|
2216 | } |
---|
2217 | else |
---|
2218 | en=i; |
---|
2219 | } |
---|
2220 | } |
---|
2221 | /*2 |
---|
2222 | * reduces h using the set S |
---|
2223 | * procedure used in redtail |
---|
2224 | */ |
---|
2225 | /*2 |
---|
2226 | *compute the normalform of the tail p->next of p |
---|
2227 | *with respect to S |
---|
2228 | */ |
---|
2229 | poly redtail (poly p, int pos, kStrategy strat) |
---|
2230 | { |
---|
2231 | if ((!strat->noTailReduction) |
---|
2232 | && (pNext(p)!=NULL)) |
---|
2233 | { |
---|
2234 | int j, e, l; |
---|
2235 | unsigned long not_sev; |
---|
2236 | |
---|
2237 | poly h = p; |
---|
2238 | poly hn = pNext(h); // !=NULL |
---|
2239 | int op = pFDeg(hn); |
---|
2240 | BOOLEAN save_HE=strat->kHEdgeFound; |
---|
2241 | strat->kHEdgeFound |= ((Kstd1_deg>0) && (op<=Kstd1_deg)); |
---|
2242 | loop |
---|
2243 | { |
---|
2244 | not_sev = ~ pGetShortExpVector(hn); |
---|
2245 | e = pLDeg(hn,&l)-op; |
---|
2246 | j = 0; |
---|
2247 | while (j <= pos) |
---|
2248 | { |
---|
2249 | if (pShortDivisibleBy(strat->S[j], strat->sevS[j], hn, not_sev) |
---|
2250 | && ((e >= strat->ecartS[j]) |
---|
2251 | || strat->kHEdgeFound) |
---|
2252 | ) |
---|
2253 | { |
---|
2254 | ksOldSpolyTail(strat->S[j], p, h, strat->kNoether); |
---|
2255 | hn = pNext(h); |
---|
2256 | if (hn == NULL) goto all_done; |
---|
2257 | not_sev = ~ pGetShortExpVector(hn); |
---|
2258 | op = pFDeg(hn); |
---|
2259 | if ((Kstd1_deg>0)&&(op>Kstd1_deg)) goto all_done; |
---|
2260 | e = pLDeg(hn,&l)-op; |
---|
2261 | j = 0; |
---|
2262 | } |
---|
2263 | else |
---|
2264 | { |
---|
2265 | j++; |
---|
2266 | } |
---|
2267 | } /* while (j <= pos) */ |
---|
2268 | h = hn; /* better for: pIter(h); */ |
---|
2269 | hn = pNext(h); |
---|
2270 | if (hn==NULL) break; |
---|
2271 | op = pFDeg(hn); |
---|
2272 | if ((Kstd1_deg>0)&&(op>Kstd1_deg)) break; |
---|
2273 | } |
---|
2274 | all_done: |
---|
2275 | strat->kHEdgeFound = save_HE; |
---|
2276 | } |
---|
2277 | return p; |
---|
2278 | } |
---|
2279 | |
---|
2280 | /*2 |
---|
2281 | *compute the normalform of the tail p->next of p |
---|
2282 | *with respect to S |
---|
2283 | */ |
---|
2284 | poly redtailBba (poly p, int pos, kStrategy strat) |
---|
2285 | { |
---|
2286 | poly h, hn; |
---|
2287 | int j; |
---|
2288 | unsigned long not_sev; |
---|
2289 | strat->redTailChange=FALSE; |
---|
2290 | |
---|
2291 | if (strat->noTailReduction) |
---|
2292 | { |
---|
2293 | return p; |
---|
2294 | } |
---|
2295 | h = p; |
---|
2296 | hn = pNext(h); |
---|
2297 | while(hn != NULL) |
---|
2298 | { |
---|
2299 | j = 0; |
---|
2300 | not_sev = ~ pGetShortExpVector(hn); |
---|
2301 | while (j <= pos) |
---|
2302 | { |
---|
2303 | if (pShortDivisibleBy(strat->S[j], strat->sevS[j], hn, not_sev)) |
---|
2304 | { |
---|
2305 | strat->redTailChange=TRUE; |
---|
2306 | assume(p != strat->S[j]); |
---|
2307 | ksOldSpolyTail(strat->S[j], p, h, strat->kNoether); |
---|
2308 | hn = pNext(h); |
---|
2309 | if (hn == NULL) |
---|
2310 | { |
---|
2311 | return p; |
---|
2312 | } |
---|
2313 | not_sev = ~ pGetShortExpVector(hn); |
---|
2314 | j = 0; |
---|
2315 | } |
---|
2316 | else |
---|
2317 | { |
---|
2318 | j++; |
---|
2319 | } |
---|
2320 | } |
---|
2321 | h = hn; |
---|
2322 | hn = pNext(h); |
---|
2323 | } |
---|
2324 | return p; |
---|
2325 | } |
---|
2326 | |
---|
2327 | /*2 |
---|
2328 | *compute the "normalform" of the tail p->next of p |
---|
2329 | *with respect to S for syzygies |
---|
2330 | */ |
---|
2331 | poly redtailSyz (poly p, int pos, kStrategy strat) |
---|
2332 | { |
---|
2333 | poly h, hn; |
---|
2334 | int j; |
---|
2335 | unsigned long not_sev; |
---|
2336 | |
---|
2337 | if (strat->noTailReduction) |
---|
2338 | { |
---|
2339 | return p; |
---|
2340 | } |
---|
2341 | h = p; |
---|
2342 | hn = pNext(h); |
---|
2343 | while(hn != NULL) |
---|
2344 | { |
---|
2345 | j = 0; |
---|
2346 | not_sev = ~ pGetShortExpVector(hn); |
---|
2347 | while (j <= pos) |
---|
2348 | { |
---|
2349 | if (pShortDivisibleBy(strat->S[j], strat->sevS[j], hn, not_sev) |
---|
2350 | && (!pEqual(strat->S[j],h))) |
---|
2351 | { |
---|
2352 | ksOldSpolyTail(strat->S[j], p, h, strat->kNoether); |
---|
2353 | hn = pNext(h); |
---|
2354 | if (hn == NULL) |
---|
2355 | { |
---|
2356 | return p; |
---|
2357 | } |
---|
2358 | not_sev = ~ pGetShortExpVector(hn); |
---|
2359 | j = 0; |
---|
2360 | } |
---|
2361 | else |
---|
2362 | { |
---|
2363 | j++; |
---|
2364 | } |
---|
2365 | } |
---|
2366 | h = hn; |
---|
2367 | hn = pNext(h); |
---|
2368 | } |
---|
2369 | return p; |
---|
2370 | } |
---|
2371 | |
---|
2372 | /*2 |
---|
2373 | *checks the change degree and write progress report |
---|
2374 | */ |
---|
2375 | void message (int i,int* reduc,int* olddeg,kStrategy strat) |
---|
2376 | { |
---|
2377 | if (i != *olddeg) |
---|
2378 | { |
---|
2379 | Print("%d",i); |
---|
2380 | *olddeg = i; |
---|
2381 | } |
---|
2382 | if (strat->Ll != *reduc) |
---|
2383 | { |
---|
2384 | if (strat->Ll != *reduc-1) |
---|
2385 | Print("(%d)",strat->Ll+1); |
---|
2386 | else |
---|
2387 | PrintS("-"); |
---|
2388 | *reduc = strat->Ll; |
---|
2389 | } |
---|
2390 | else |
---|
2391 | PrintS("."); |
---|
2392 | mflush(); |
---|
2393 | } |
---|
2394 | |
---|
2395 | /*2 |
---|
2396 | *statistics |
---|
2397 | */ |
---|
2398 | void messageStat (int srmax,int lrmax,int hilbcount,kStrategy strat) |
---|
2399 | { |
---|
2400 | //PrintS("\nUsage/Allocation of temporary storage:\n"); |
---|
2401 | //Print("%d/%d polynomials in standard base\n",srmax,IDELEMS(Shdl)); |
---|
2402 | //Print("%d/%d polynomials in set L (for lazy alg.)",lrmax+1,strat->Lmax); |
---|
2403 | Print("\nproduct criterion:%d chain criterion:%d\n",strat->cp,strat->c3); |
---|
2404 | if (hilbcount!=0) Print("hilbert series criterion:%d\n",hilbcount); |
---|
2405 | /*mflush();*/ |
---|
2406 | } |
---|
2407 | |
---|
2408 | /*2 |
---|
2409 | *debugging output: all internal sets, if changed |
---|
2410 | *for testing purpuse only/has to be changed for later use |
---|
2411 | */ |
---|
2412 | void messageSets (kStrategy strat) |
---|
2413 | { |
---|
2414 | int i; |
---|
2415 | if (strat->news) |
---|
2416 | { |
---|
2417 | PrintS("set S"); |
---|
2418 | for (i=0; i<=strat->sl; i++) |
---|
2419 | { |
---|
2420 | Print("\n %d:",i); |
---|
2421 | wrp(strat->S[i]); |
---|
2422 | } |
---|
2423 | strat->news = FALSE; |
---|
2424 | } |
---|
2425 | if (strat->newt) |
---|
2426 | { |
---|
2427 | PrintS("\nset T"); |
---|
2428 | for (i=0; i<=strat->tl; i++) |
---|
2429 | { |
---|
2430 | Print("\n %d:",i); |
---|
2431 | wrp(strat->T[i].p); |
---|
2432 | Print(" o:%d e:%d l:%d", |
---|
2433 | pFDeg(strat->T[i].p),strat->T[i].ecart,strat->T[i].length); |
---|
2434 | } |
---|
2435 | strat->newt = FALSE; |
---|
2436 | } |
---|
2437 | PrintS("\nset L"); |
---|
2438 | for (i=strat->Ll; i>=0; i--) |
---|
2439 | { |
---|
2440 | Print("\n%d:",i); |
---|
2441 | wrp(strat->L[i].p1); |
---|
2442 | PrintS(" "); |
---|
2443 | wrp(strat->L[i].p2); |
---|
2444 | PrintS(" lcm: ");wrp(strat->L[i].lcm); |
---|
2445 | PrintS("\n p : "); |
---|
2446 | wrp(strat->L[i].p); |
---|
2447 | Print(" o:%d e:%d l:%d", |
---|
2448 | pGetOrder(strat->L[i].p),strat->L[i].ecart,strat->L[i].length); |
---|
2449 | } |
---|
2450 | PrintLn(); |
---|
2451 | } |
---|
2452 | |
---|
2453 | /*2 |
---|
2454 | *construct the set s from F |
---|
2455 | */ |
---|
2456 | void initS (ideal F, ideal Q,kStrategy strat) |
---|
2457 | { |
---|
2458 | LObject h; |
---|
2459 | int i,pos; |
---|
2460 | |
---|
2461 | h.ecart=0; h.length=0; |
---|
2462 | if (Q!=NULL) i=IDELEMS(Q); |
---|
2463 | else i=0; |
---|
2464 | i=((i+IDELEMS(F)+15)/16)*16; |
---|
2465 | strat->ecartS=initec(i); |
---|
2466 | strat->sevS=initsevS(i); |
---|
2467 | strat->fromQ=NULL; |
---|
2468 | strat->Shdl=idInit(i,F->rank); |
---|
2469 | strat->S=strat->Shdl->m; |
---|
2470 | /*- put polys into S -*/ |
---|
2471 | if (Q!=NULL) |
---|
2472 | { |
---|
2473 | strat->fromQ=initec(i); |
---|
2474 | memset(strat->fromQ,0,i*sizeof(int)); |
---|
2475 | for (i=0; i<IDELEMS(Q); i++) |
---|
2476 | { |
---|
2477 | if (Q->m[i]!=NULL) |
---|
2478 | { |
---|
2479 | h.p = pCopy(Q->m[i]); |
---|
2480 | if (TEST_OPT_INTSTRATEGY) |
---|
2481 | { |
---|
2482 | //pContent(h.p); |
---|
2483 | pCleardenom(h.p); // also does a pContent |
---|
2484 | } |
---|
2485 | else |
---|
2486 | { |
---|
2487 | pNorm(h.p); |
---|
2488 | } |
---|
2489 | strat->initEcart(&h); |
---|
2490 | if (pOrdSgn==-1) |
---|
2491 | { |
---|
2492 | deleteHC(&h.p, &h.ecart, &h.length,strat); |
---|
2493 | } |
---|
2494 | if (h.p!=NULL) |
---|
2495 | { |
---|
2496 | if (strat->sl==-1) |
---|
2497 | pos =0; |
---|
2498 | else |
---|
2499 | { |
---|
2500 | pos = posInS(strat->S,strat->sl,h.p); |
---|
2501 | } |
---|
2502 | h.sev = pGetShortExpVector(h.p); |
---|
2503 | strat->enterS(h,pos,strat); |
---|
2504 | strat->fromQ[pos]=1; |
---|
2505 | } |
---|
2506 | } |
---|
2507 | } |
---|
2508 | } |
---|
2509 | for (i=0; i<IDELEMS(F); i++) |
---|
2510 | { |
---|
2511 | if (F->m[i]!=NULL) |
---|
2512 | { |
---|
2513 | h.p = pCopy(F->m[i]); |
---|
2514 | if (TEST_OPT_INTSTRATEGY) |
---|
2515 | { |
---|
2516 | //pContent(h.p); |
---|
2517 | pCleardenom(h.p); // also does a pContent |
---|
2518 | } |
---|
2519 | else |
---|
2520 | { |
---|
2521 | pNorm(h.p); |
---|
2522 | } |
---|
2523 | strat->initEcart(&h); |
---|
2524 | if (pOrdSgn==-1) |
---|
2525 | { |
---|
2526 | cancelunit(&h); /*- tries to cancel a unit -*/ |
---|
2527 | deleteHC(&h.p, &h.ecart, &h.length,strat); |
---|
2528 | } |
---|
2529 | if (TEST_OPT_DEGBOUND |
---|
2530 | && (((strat->honey) && (h.ecart+pFDeg(h.p)>Kstd1_deg)) |
---|
2531 | || ((!(strat->honey)) && (pFDeg(h.p)>Kstd1_deg)))) |
---|
2532 | pDelete(&h.p); |
---|
2533 | else |
---|
2534 | if (h.p!=NULL) |
---|
2535 | { |
---|
2536 | if (strat->sl==-1) |
---|
2537 | pos =0; |
---|
2538 | else |
---|
2539 | { |
---|
2540 | pos = posInS(strat->S,strat->sl,h.p); |
---|
2541 | } |
---|
2542 | h.sev = pGetShortExpVector(h.p); |
---|
2543 | strat->enterS(h,pos,strat); |
---|
2544 | } |
---|
2545 | } |
---|
2546 | } |
---|
2547 | /*- test, if a unit is in F -*/ |
---|
2548 | if ((strat->sl>=0) && pIsConstant(strat->S[0])) |
---|
2549 | { |
---|
2550 | while (strat->sl>0) deleteInS(strat->sl,strat); |
---|
2551 | } |
---|
2552 | } |
---|
2553 | |
---|
2554 | void initSL (ideal F, ideal Q,kStrategy strat) |
---|
2555 | { |
---|
2556 | LObject h; |
---|
2557 | int i,pos; |
---|
2558 | |
---|
2559 | h.ecart=0; h.length=0; |
---|
2560 | if (Q!=NULL) i=IDELEMS(Q); |
---|
2561 | else i=0; |
---|
2562 | i=((i+16)/16)*16; |
---|
2563 | strat->ecartS=initec(i); |
---|
2564 | strat->sevS=initsevS(i); |
---|
2565 | strat->fromQ=NULL; |
---|
2566 | strat->Shdl=idInit(i,F->rank); |
---|
2567 | strat->S=strat->Shdl->m; |
---|
2568 | /*- put polys into S -*/ |
---|
2569 | if (Q!=NULL) |
---|
2570 | { |
---|
2571 | strat->fromQ=initec(i); |
---|
2572 | memset(strat->fromQ,0,i*sizeof(int)); |
---|
2573 | for (i=0; i<IDELEMS(Q); i++) |
---|
2574 | { |
---|
2575 | if (Q->m[i]!=NULL) |
---|
2576 | { |
---|
2577 | h.p = pCopy(Q->m[i]); |
---|
2578 | if (TEST_OPT_INTSTRATEGY) |
---|
2579 | { |
---|
2580 | //pContent(h.p); |
---|
2581 | pCleardenom(h.p); // also does a pContent |
---|
2582 | } |
---|
2583 | else |
---|
2584 | { |
---|
2585 | pNorm(h.p); |
---|
2586 | } |
---|
2587 | strat->initEcart(&h); |
---|
2588 | if (pOrdSgn==-1) |
---|
2589 | { |
---|
2590 | deleteHC(&h.p, &h.ecart, &h.length,strat); |
---|
2591 | } |
---|
2592 | if (h.p!=NULL) |
---|
2593 | { |
---|
2594 | if (strat->sl==-1) |
---|
2595 | pos =0; |
---|
2596 | else |
---|
2597 | { |
---|
2598 | pos = posInS(strat->S,strat->sl,h.p); |
---|
2599 | } |
---|
2600 | h.sev = pGetShortExpVector(h.p); |
---|
2601 | strat->enterS(h,pos,strat); |
---|
2602 | strat->fromQ[pos]=1; |
---|
2603 | } |
---|
2604 | } |
---|
2605 | } |
---|
2606 | } |
---|
2607 | for (i=0; i<IDELEMS(F); i++) |
---|
2608 | { |
---|
2609 | if (F->m[i]!=NULL) |
---|
2610 | { |
---|
2611 | h.p = pCopy(F->m[i]); |
---|
2612 | h.p1=NULL; |
---|
2613 | h.p2=NULL; |
---|
2614 | h.lcm=NULL; |
---|
2615 | if (TEST_OPT_INTSTRATEGY) |
---|
2616 | { |
---|
2617 | //pContent(h.p); |
---|
2618 | pCleardenom(h.p); // also does a pContent |
---|
2619 | } |
---|
2620 | else |
---|
2621 | { |
---|
2622 | pNorm(h.p); |
---|
2623 | } |
---|
2624 | strat->initEcart(&h); |
---|
2625 | if (pOrdSgn==-1) |
---|
2626 | { |
---|
2627 | cancelunit(&h); /*- tries to cancel a unit -*/ |
---|
2628 | deleteHC(&h.p, &h.ecart, &h.length,strat); |
---|
2629 | } |
---|
2630 | if (TEST_OPT_DEGBOUND |
---|
2631 | && (((strat->honey) && (h.ecart+pFDeg(h.p)>Kstd1_deg)) |
---|
2632 | || ((!(strat->honey)) && (pFDeg(h.p)>Kstd1_deg)))) |
---|
2633 | pDelete(&h.p); |
---|
2634 | else |
---|
2635 | if (h.p!=NULL) |
---|
2636 | { |
---|
2637 | if (strat->Ll==-1) |
---|
2638 | pos =0; |
---|
2639 | else |
---|
2640 | { |
---|
2641 | pos = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
2642 | } |
---|
2643 | h.sev = pGetShortExpVector(h.p); |
---|
2644 | enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos); |
---|
2645 | } |
---|
2646 | } |
---|
2647 | } |
---|
2648 | /*- test, if a unit is in F -*/ |
---|
2649 | if ((strat->Ll>=0) && pIsConstant(strat->L[strat->Ll].p)) |
---|
2650 | { |
---|
2651 | while (strat->Ll>0) deleteInL(strat->L,&strat->Ll,strat->Ll-1,strat); |
---|
2652 | } |
---|
2653 | } |
---|
2654 | |
---|
2655 | |
---|
2656 | /*2 |
---|
2657 | *construct the set s from F u {P} |
---|
2658 | */ |
---|
2659 | void initSSpecial (ideal F, ideal Q, ideal P,kStrategy strat) |
---|
2660 | { |
---|
2661 | LObject h; |
---|
2662 | int i,pos; |
---|
2663 | |
---|
2664 | h.ecart=0; h.length=0; |
---|
2665 | if (Q!=NULL) i=IDELEMS(Q); |
---|
2666 | else i=0; |
---|
2667 | i=((i+IDELEMS(F)+15)/16)*16; |
---|
2668 | strat->ecartS=initec(i); |
---|
2669 | strat->sevS=initsevS(i); |
---|
2670 | strat->fromQ=NULL; |
---|
2671 | strat->Shdl=idInit(i,F->rank); |
---|
2672 | strat->S=strat->Shdl->m; |
---|
2673 | |
---|
2674 | /*- put polys into S -*/ |
---|
2675 | if (Q!=NULL) |
---|
2676 | { |
---|
2677 | strat->fromQ=initec(i); |
---|
2678 | memset(strat->fromQ,0,i*sizeof(int)); |
---|
2679 | for (i=0; i<IDELEMS(Q); i++) |
---|
2680 | { |
---|
2681 | if (Q->m[i]!=NULL) |
---|
2682 | { |
---|
2683 | h.p = pCopy(Q->m[i]); |
---|
2684 | //if (TEST_OPT_INTSTRATEGY) |
---|
2685 | //{ |
---|
2686 | // //pContent(h.p); |
---|
2687 | // pCleardenom(h.p); // also does a pContent |
---|
2688 | //} |
---|
2689 | //else |
---|
2690 | //{ |
---|
2691 | // pNorm(h.p); |
---|
2692 | //} |
---|
2693 | strat->initEcart(&h); |
---|
2694 | if (pOrdSgn==-1) |
---|
2695 | { |
---|
2696 | deleteHC(&h.p, &h.ecart, &h.length,strat); |
---|
2697 | } |
---|
2698 | if (h.p!=NULL) |
---|
2699 | { |
---|
2700 | if (strat->sl==-1) |
---|
2701 | pos =0; |
---|
2702 | else |
---|
2703 | { |
---|
2704 | pos = posInS(strat->S,strat->sl,h.p); |
---|
2705 | } |
---|
2706 | h.sev = pGetShortExpVector(h.p); |
---|
2707 | strat->enterS(h,pos,strat); |
---|
2708 | strat->fromQ[pos]=1; |
---|
2709 | } |
---|
2710 | } |
---|
2711 | } |
---|
2712 | } |
---|
2713 | /*- put polys into S -*/ |
---|
2714 | for (i=0; i<IDELEMS(F); i++) |
---|
2715 | { |
---|
2716 | if (F->m[i]!=NULL) |
---|
2717 | { |
---|
2718 | h.p = pCopy(F->m[i]); |
---|
2719 | if (pOrdSgn==1) |
---|
2720 | { |
---|
2721 | h.p=redtailBba(h.p,strat->sl,strat); |
---|
2722 | } |
---|
2723 | strat->initEcart(&h); |
---|
2724 | if (pOrdSgn==-1) |
---|
2725 | { |
---|
2726 | deleteHC(&h.p, &h.ecart, &h.length,strat); |
---|
2727 | } |
---|
2728 | if (TEST_OPT_DEGBOUND |
---|
2729 | && (((strat->honey) && (h.ecart+pFDeg(h.p)>Kstd1_deg)) |
---|
2730 | || ((!(strat->honey)) && (pFDeg(h.p)>Kstd1_deg)))) |
---|
2731 | pDelete(&h.p); |
---|
2732 | else |
---|
2733 | if (h.p!=NULL) |
---|
2734 | { |
---|
2735 | if (strat->sl==-1) |
---|
2736 | pos =0; |
---|
2737 | else |
---|
2738 | { |
---|
2739 | pos = posInS(strat->S,strat->sl,h.p); |
---|
2740 | } |
---|
2741 | h.sev = pGetShortExpVector(h.p); |
---|
2742 | strat->enterS(h,pos,strat); |
---|
2743 | h.length = pLength(h.p); |
---|
2744 | enterT(h,strat); |
---|
2745 | } |
---|
2746 | } |
---|
2747 | } |
---|
2748 | for (i=0; i<IDELEMS(P); i++) |
---|
2749 | { |
---|
2750 | if (P->m[i]!=NULL) |
---|
2751 | { |
---|
2752 | h.p=pCopy(P->m[i]); |
---|
2753 | strat->initEcart(&h); |
---|
2754 | h.length = pLength(h.p); |
---|
2755 | if (TEST_OPT_INTSTRATEGY) |
---|
2756 | { |
---|
2757 | pCleardenom(h.p); |
---|
2758 | } |
---|
2759 | else |
---|
2760 | { |
---|
2761 | pNorm(h.p); |
---|
2762 | } |
---|
2763 | if(strat->sl>=0) |
---|
2764 | { |
---|
2765 | if (pOrdSgn==1) |
---|
2766 | { |
---|
2767 | h.p=redBba(h.p,strat->sl,strat); |
---|
2768 | if (h.p!=NULL) |
---|
2769 | h.p=redtailBba(h.p,strat->sl,strat); |
---|
2770 | } |
---|
2771 | else |
---|
2772 | { |
---|
2773 | h.p=redMora(h.p,strat->sl,strat); |
---|
2774 | strat->initEcart(&h); |
---|
2775 | } |
---|
2776 | if(h.p!=NULL) |
---|
2777 | { |
---|
2778 | if (TEST_OPT_INTSTRATEGY) |
---|
2779 | { |
---|
2780 | pCleardenom(h.p); |
---|
2781 | } |
---|
2782 | else |
---|
2783 | { |
---|
2784 | pNorm(h.p); |
---|
2785 | } |
---|
2786 | h.sev = pGetShortExpVector(h.p); |
---|
2787 | pos = posInS(strat->S,strat->sl,h.p); |
---|
2788 | enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat); |
---|
2789 | strat->enterS(h,pos,strat); |
---|
2790 | enterT(h,strat); |
---|
2791 | } |
---|
2792 | } |
---|
2793 | else |
---|
2794 | { |
---|
2795 | h.sev = pGetShortExpVector(h.p); |
---|
2796 | strat->enterS(h,0,strat); |
---|
2797 | enterT(h,strat); |
---|
2798 | } |
---|
2799 | } |
---|
2800 | } |
---|
2801 | } |
---|
2802 | /*2 |
---|
2803 | * reduces h using the set S |
---|
2804 | * procedure used in cancelunit1 |
---|
2805 | */ |
---|
2806 | static poly redBba1 (poly h,int maxIndex,kStrategy strat) |
---|
2807 | { |
---|
2808 | int j = 0; |
---|
2809 | unsigned long not_sev = ~ pGetShortExpVector(h); |
---|
2810 | |
---|
2811 | while (j <= maxIndex) |
---|
2812 | { |
---|
2813 | if (pShortDivisibleBy(strat->S[j],strat->sevS[j],h, not_sev)) |
---|
2814 | return ksOldSpolyRedNew(strat->S[j],h,strat->kNoether); |
---|
2815 | else j++; |
---|
2816 | } |
---|
2817 | return h; |
---|
2818 | } |
---|
2819 | |
---|
2820 | /*2 |
---|
2821 | *tests if p.p=monomial*unit and cancels the unit |
---|
2822 | */ |
---|
2823 | void cancelunit1 (LObject* p,int index,kStrategy strat ) |
---|
2824 | { |
---|
2825 | int k; |
---|
2826 | poly r,h,h1,q; |
---|
2827 | |
---|
2828 | if (!pIsVector((*p).p) && ((*p).ecart != 0)) |
---|
2829 | { |
---|
2830 | k = 0; |
---|
2831 | h1 = r = pCopy((*p).p); |
---|
2832 | h =pNext(r); |
---|
2833 | loop |
---|
2834 | { |
---|
2835 | if (h==NULL) |
---|
2836 | { |
---|
2837 | pDelete(&r); |
---|
2838 | pDelete(&(pNext((*p).p))); |
---|
2839 | (*p).ecart = 0; |
---|
2840 | (*p).length = 1; |
---|
2841 | return; |
---|
2842 | } |
---|
2843 | if (!pDivisibleBy(r,h)) |
---|
2844 | { |
---|
2845 | q=redBba1(h,index ,strat); |
---|
2846 | if (q != h) |
---|
2847 | { |
---|
2848 | k++; |
---|
2849 | pDelete(&h); |
---|
2850 | pNext(h1) = h = q; |
---|
2851 | } |
---|
2852 | else |
---|
2853 | { |
---|
2854 | pDelete(&r); |
---|
2855 | return; |
---|
2856 | } |
---|
2857 | } |
---|
2858 | else |
---|
2859 | { |
---|
2860 | h1 = h; |
---|
2861 | pIter(h); |
---|
2862 | } |
---|
2863 | if (k > 10) |
---|
2864 | { |
---|
2865 | pDelete(&r); |
---|
2866 | return; |
---|
2867 | } |
---|
2868 | } |
---|
2869 | } |
---|
2870 | } |
---|
2871 | |
---|
2872 | /*2 |
---|
2873 | * reduces h using the elements from Q in the set S |
---|
2874 | * procedure used in updateS |
---|
2875 | * must not be used for elements of Q or elements of an ideal ! |
---|
2876 | */ |
---|
2877 | static poly redQ (poly h, int j, kStrategy strat) |
---|
2878 | { |
---|
2879 | int start; |
---|
2880 | unsigned long not_sev = ~ pGetShortExpVector(h); |
---|
2881 | while ((j <= strat->sl) && (pGetComp(strat->S[j])!=0)) j++; |
---|
2882 | start=j; |
---|
2883 | while (j<=strat->sl) |
---|
2884 | { |
---|
2885 | if (pShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)) |
---|
2886 | { |
---|
2887 | h = ksOldSpolyRed(strat->S[j],h,strat->kNoether); |
---|
2888 | if (h==NULL) return NULL; |
---|
2889 | j = start; |
---|
2890 | not_sev = ~ pGetShortExpVector(h); |
---|
2891 | } |
---|
2892 | else j++; |
---|
2893 | } |
---|
2894 | return h; |
---|
2895 | } |
---|
2896 | |
---|
2897 | /*2 |
---|
2898 | * reduces h using the set S |
---|
2899 | * procedure used in updateS |
---|
2900 | */ |
---|
2901 | static poly redBba (poly h,int maxIndex,kStrategy strat) |
---|
2902 | { |
---|
2903 | int j = 0; |
---|
2904 | unsigned long not_sev = ~ pGetShortExpVector(h); |
---|
2905 | |
---|
2906 | while (j <= maxIndex) |
---|
2907 | { |
---|
2908 | if (pShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev)) |
---|
2909 | { |
---|
2910 | h = ksOldSpolyRed(strat->S[j],h,strat->kNoether); |
---|
2911 | if (h==NULL) return NULL; |
---|
2912 | j = 0; |
---|
2913 | not_sev = ~ pGetShortExpVector(h); } |
---|
2914 | else j++; |
---|
2915 | } |
---|
2916 | return h; |
---|
2917 | } |
---|
2918 | |
---|
2919 | /*2 |
---|
2920 | * reduces h using the set S |
---|
2921 | *e is the ecart of h |
---|
2922 | *procedure used in updateS |
---|
2923 | */ |
---|
2924 | static poly redMora (poly h,int maxIndex,kStrategy strat) |
---|
2925 | { |
---|
2926 | int j=0; |
---|
2927 | int e,l; |
---|
2928 | poly h1; |
---|
2929 | unsigned long not_sev = ~ pGetShortExpVector(h); |
---|
2930 | |
---|
2931 | if (maxIndex >= 0) |
---|
2932 | { |
---|
2933 | e = pLDeg(h,&l)-pFDeg(h); |
---|
2934 | do |
---|
2935 | { |
---|
2936 | if (pShortDivisibleBy(strat->S[j],strat->sevS[j], h, not_sev) |
---|
2937 | && ((e >= strat->ecartS[j]) || strat->kHEdgeFound)) |
---|
2938 | { |
---|
2939 | h1 = ksOldSpolyRedNew(strat->S[j],h,strat->kNoether); |
---|
2940 | if(TEST_OPT_DEBUG) |
---|
2941 | { |
---|
2942 | PrintS("reduce "); wrp(h); Print(" with S[%d] (",j);wrp(strat->S[j]); |
---|
2943 | PrintS(")\nto "); wrp(h1); PrintLn(); |
---|
2944 | } |
---|
2945 | pDelete(&h); |
---|
2946 | if (h1 == NULL) return NULL; |
---|
2947 | h = h1; |
---|
2948 | e = pLDeg(h,&l)-pFDeg(h); |
---|
2949 | j = 0; |
---|
2950 | not_sev = ~ pGetShortExpVector(h); |
---|
2951 | } |
---|
2952 | else j++; |
---|
2953 | } |
---|
2954 | while (j <= maxIndex); |
---|
2955 | } |
---|
2956 | return h; |
---|
2957 | } |
---|
2958 | |
---|
2959 | /*2 |
---|
2960 | *updates S: |
---|
2961 | *the result is a set of polynomials which are in |
---|
2962 | *normalform with respect to S |
---|
2963 | */ |
---|
2964 | void updateS(BOOLEAN toT,kStrategy strat) |
---|
2965 | { |
---|
2966 | LObject h; |
---|
2967 | int i, suc=0; |
---|
2968 | poly redSi=NULL; |
---|
2969 | //Print("nach initS: updateS start mit sl=%d\n",(strat->sl)); |
---|
2970 | // for (i=0; i<=(strat->sl); i++) |
---|
2971 | // { |
---|
2972 | // Print("s%d:",i); |
---|
2973 | // if (strat->fromQ!=NULL) Print("(Q:%d) ",strat->fromQ[i]); |
---|
2974 | // pWrite(strat->S[i]); |
---|
2975 | // } |
---|
2976 | memset(&h,0,sizeof(h)); |
---|
2977 | if (pOrdSgn==1) |
---|
2978 | { |
---|
2979 | while (suc != -1) |
---|
2980 | { |
---|
2981 | i=suc+1; |
---|
2982 | while (i<=strat->sl) |
---|
2983 | { |
---|
2984 | if (((strat->syzComp==0) || (pGetComp(strat->S[i])<=strat->syzComp)) |
---|
2985 | && ((strat->fromQ==NULL) || (strat->fromQ[i]==0))) |
---|
2986 | { |
---|
2987 | pDelete(&redSi); |
---|
2988 | redSi = pHead(strat->S[i]); |
---|
2989 | strat->S[i] = redBba(strat->S[i],i-1,strat); |
---|
2990 | if ((strat->ak!=0)&&(strat->S[i]!=NULL)) |
---|
2991 | strat->S[i]=redQ(strat->S[i],i+1,strat); /*reduce S[i] mod Q*/ |
---|
2992 | if (TEST_OPT_DEBUG && (pComp(redSi,strat->S[i])!=0)) |
---|
2993 | { |
---|
2994 | PrintS("reduce:"); |
---|
2995 | wrp(redSi);PrintS(" to ");wrp(strat->S[i]);PrintLn(); |
---|
2996 | } |
---|
2997 | if (TEST_OPT_PROT && (pComp(redSi,strat->S[i])!=0)) |
---|
2998 | { |
---|
2999 | if (strat->S[i]==NULL) |
---|
3000 | PrintS("V"); |
---|
3001 | else |
---|
3002 | PrintS("v"); |
---|
3003 | mflush(); |
---|
3004 | } |
---|
3005 | if (strat->S[i]==NULL) |
---|
3006 | { |
---|
3007 | pDelete(&redSi); |
---|
3008 | deleteInS(i,strat); |
---|
3009 | i--; |
---|
3010 | } |
---|
3011 | else |
---|
3012 | { |
---|
3013 | pDelete(&redSi); |
---|
3014 | if (TEST_OPT_INTSTRATEGY) |
---|
3015 | { |
---|
3016 | //pContent(strat->S[i]); |
---|
3017 | pCleardenom(strat->S[i]);// also does a pContent |
---|
3018 | } |
---|
3019 | else |
---|
3020 | { |
---|
3021 | pNorm(strat->S[i]); |
---|
3022 | } |
---|
3023 | strat->sevS[i] = pGetShortExpVector(strat->S[i]); |
---|
3024 | } |
---|
3025 | } |
---|
3026 | i++; |
---|
3027 | } |
---|
3028 | reorderS(&suc,strat); |
---|
3029 | } |
---|
3030 | if (toT) |
---|
3031 | { |
---|
3032 | for (i=0; i<=strat->sl; i++) |
---|
3033 | { |
---|
3034 | if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) |
---|
3035 | ) |
---|
3036 | h.p = redtailBba(strat->S[i],i-1,strat); |
---|
3037 | else |
---|
3038 | { |
---|
3039 | h.p = strat->S[i]; |
---|
3040 | } |
---|
3041 | if (strat->honey) |
---|
3042 | { |
---|
3043 | strat->initEcart(&h); |
---|
3044 | strat->ecartS[i] = h.ecart; |
---|
3045 | } |
---|
3046 | if (strat->sevS[i] == 0) {strat->sevS[i] = pGetShortExpVector(h.p);} |
---|
3047 | else assume(strat->sevS[i] == pGetShortExpVector(h.p)); |
---|
3048 | h.sev = strat->sevS[i]; |
---|
3049 | /*puts the elements of S also to T*/ |
---|
3050 | enterT(h,strat); |
---|
3051 | } |
---|
3052 | } |
---|
3053 | } |
---|
3054 | else |
---|
3055 | { |
---|
3056 | while (suc != -1) |
---|
3057 | { |
---|
3058 | i=suc+1; |
---|
3059 | while (i<=strat->sl) |
---|
3060 | { |
---|
3061 | if (((strat->syzComp==0) || (pGetComp(strat->S[i])<=strat->syzComp)) |
---|
3062 | && ((strat->fromQ==NULL) || (strat->fromQ[i]==0))) |
---|
3063 | { |
---|
3064 | pDelete(&redSi); |
---|
3065 | redSi=pHead((strat->S)[i]); |
---|
3066 | (strat->S)[i] = redMora((strat->S)[i],i-1,strat); |
---|
3067 | if ((strat->S)[i]==NULL) |
---|
3068 | { |
---|
3069 | deleteInS(i,strat); |
---|
3070 | i--; |
---|
3071 | } |
---|
3072 | else |
---|
3073 | { |
---|
3074 | if (TEST_OPT_INTSTRATEGY) |
---|
3075 | { |
---|
3076 | pDelete(&redSi); |
---|
3077 | pCleardenom(strat->S[i]);// also does a pContent |
---|
3078 | h.p = strat->S[i]; |
---|
3079 | strat->initEcart(&h); |
---|
3080 | strat->ecartS[i] = h.ecart; |
---|
3081 | } |
---|
3082 | else |
---|
3083 | { |
---|
3084 | pDelete(&redSi); |
---|
3085 | pNorm(strat->S[i]); |
---|
3086 | h.p = strat->S[i]; |
---|
3087 | strat->initEcart(&h); |
---|
3088 | strat->ecartS[i] = h.ecart; |
---|
3089 | } |
---|
3090 | h.sev = pGetShortExpVector(h.p); |
---|
3091 | strat->sevS[i] = h.sev; |
---|
3092 | } |
---|
3093 | kTest(strat); |
---|
3094 | } |
---|
3095 | i++; |
---|
3096 | } |
---|
3097 | #ifdef KDEBUG |
---|
3098 | kTest(strat); |
---|
3099 | #endif |
---|
3100 | reorderS(&suc,strat); |
---|
3101 | if (h.p!=NULL) |
---|
3102 | { |
---|
3103 | if (!strat->kHEdgeFound) |
---|
3104 | { |
---|
3105 | /*strat->kHEdgeFound =*/ HEckeTest(h.p,strat); |
---|
3106 | } |
---|
3107 | if (strat->kHEdgeFound) |
---|
3108 | newHEdge(strat->S,strat->ak,strat); |
---|
3109 | } |
---|
3110 | } |
---|
3111 | for (i=0; i<=strat->sl; i++) |
---|
3112 | { |
---|
3113 | if (((strat->fromQ==NULL) || (strat->fromQ[i]==0)) |
---|
3114 | ) |
---|
3115 | { |
---|
3116 | strat->S[i] = h.p = redtail(strat->S[i],strat->sl,strat); |
---|
3117 | strat->initEcart(&h); |
---|
3118 | strat->ecartS[i] = h.ecart; |
---|
3119 | h.sev = pGetShortExpVector(h.p); |
---|
3120 | strat->sevS[i] = h.sev; |
---|
3121 | } |
---|
3122 | else |
---|
3123 | { |
---|
3124 | h.p = strat->S[i]; |
---|
3125 | h.ecart=strat->ecartS[i]; |
---|
3126 | h.sev = strat->sevS[i]; |
---|
3127 | } |
---|
3128 | if ((strat->fromQ==NULL) || (strat->fromQ[i]==0)) |
---|
3129 | cancelunit1(&h,strat->sl,strat); |
---|
3130 | h.length = pLength(h.p); |
---|
3131 | /*puts the elements of S also to T*/ |
---|
3132 | enterT(h,strat); |
---|
3133 | } |
---|
3134 | } |
---|
3135 | if (redSi!=NULL) pDelete1(&redSi); |
---|
3136 | #ifdef KDEBUG |
---|
3137 | kTest(strat); |
---|
3138 | #endif |
---|
3139 | } |
---|
3140 | |
---|
3141 | /*2 |
---|
3142 | * -puts p to the standardbasis s at position at |
---|
3143 | * -saves the result in S |
---|
3144 | */ |
---|
3145 | void enterSBba (LObject p,int atS,kStrategy strat) |
---|
3146 | { |
---|
3147 | int i; |
---|
3148 | |
---|
3149 | strat->news = TRUE; |
---|
3150 | /*- puts p to the standardbasis s at position at -*/ |
---|
3151 | if (strat->sl == IDELEMS(strat->Shdl)-1) |
---|
3152 | { |
---|
3153 | strat->sevS = (unsigned long*) ReAlloc0(strat->sevS, |
---|
3154 | IDELEMS(strat->Shdl)*sizeof(unsigned long), |
---|
3155 | (IDELEMS(strat->Shdl)+setmax) |
---|
3156 | *sizeof(unsigned long)); |
---|
3157 | strat->ecartS = (intset)ReAlloc(strat->ecartS, |
---|
3158 | IDELEMS(strat->Shdl)*sizeof(int), |
---|
3159 | (IDELEMS(strat->Shdl)+setmax)*sizeof(int)); |
---|
3160 | if (strat->fromQ!=NULL) |
---|
3161 | { |
---|
3162 | strat->fromQ = (intset)ReAlloc(strat->fromQ, |
---|
3163 | IDELEMS(strat->Shdl)*sizeof(int), |
---|
3164 | (IDELEMS(strat->Shdl)+setmax)*sizeof(int)); |
---|
3165 | } |
---|
3166 | pEnlargeSet(&strat->S,IDELEMS(strat->Shdl),setmax); |
---|
3167 | IDELEMS(strat->Shdl)+=setmax; |
---|
3168 | strat->Shdl->m=strat->S; |
---|
3169 | } |
---|
3170 | for (i=strat->sl+1; i>=atS+1; i--) |
---|
3171 | { |
---|
3172 | strat->S[i] = strat->S[i-1]; |
---|
3173 | if (strat->honey) strat->ecartS[i] = strat->ecartS[i-1]; |
---|
3174 | strat->sevS[i] = strat->sevS[i-1]; |
---|
3175 | } |
---|
3176 | if (strat->fromQ!=NULL) |
---|
3177 | { |
---|
3178 | for (i=strat->sl+1; i>=atS+1; i--) |
---|
3179 | { |
---|
3180 | strat->fromQ[i] = strat->fromQ[i-1]; |
---|
3181 | } |
---|
3182 | strat->fromQ[atS]=0; |
---|
3183 | } |
---|
3184 | /*- save result -*/ |
---|
3185 | strat->S[atS] = p.p; |
---|
3186 | if (strat->honey) strat->ecartS[atS] = p.ecart; |
---|
3187 | if (p.sev == 0) |
---|
3188 | { |
---|
3189 | p.sev = pGetShortExpVector(p.p); |
---|
3190 | } |
---|
3191 | else |
---|
3192 | { |
---|
3193 | assume(p.sev == pGetShortExpVector(p.p)); |
---|
3194 | } |
---|
3195 | strat->sevS[atS] = p.sev; |
---|
3196 | strat->sl++; |
---|
3197 | } |
---|
3198 | |
---|
3199 | /*2 |
---|
3200 | * puts p to the set T at position atT |
---|
3201 | */ |
---|
3202 | void enterT (LObject p,kStrategy strat) |
---|
3203 | { |
---|
3204 | int i,atT; |
---|
3205 | |
---|
3206 | pHeapTest(p.p, (p.heap == NULL ? mm_specHeap : p.heap)); |
---|
3207 | assume(p.pLength == 0 || pLength(p.p) == p.pLength); |
---|
3208 | |
---|
3209 | strat->newt = TRUE; |
---|
3210 | if (strat->tl >= 0) |
---|
3211 | { |
---|
3212 | /*- puts p to the standardbasis s at position atT -*/ |
---|
3213 | atT = strat->posInT(strat->T,strat->tl,p); |
---|
3214 | if (strat->tl == strat->tmax-1) enlargeT(&strat->T,&strat->tmax,setmax); |
---|
3215 | for (i=strat->tl+1; i>=atT+1; i--) strat->T[i] = strat->T[i-1]; |
---|
3216 | } |
---|
3217 | else atT = 0; |
---|
3218 | strat->T[atT].p = p.p; |
---|
3219 | strat->T[atT].ecart = p.ecart; |
---|
3220 | strat->T[atT].length = p.length; |
---|
3221 | strat->T[atT].pLength = p.pLength; |
---|
3222 | strat->T[atT].heap = p.heap; |
---|
3223 | if (p.sev == 0) |
---|
3224 | { |
---|
3225 | p.sev = pGetShortExpVector(p.p); |
---|
3226 | } |
---|
3227 | else |
---|
3228 | { |
---|
3229 | assume(p.sev == pGetShortExpVector(p.p)); |
---|
3230 | } |
---|
3231 | strat->T[atT].sev = p.sev; |
---|
3232 | strat->tl++; |
---|
3233 | } |
---|
3234 | |
---|
3235 | /*2 |
---|
3236 | * puts p to the set T at position atT |
---|
3237 | */ |
---|
3238 | void enterTBba (LObject p, int atT,kStrategy strat) |
---|
3239 | { |
---|
3240 | int i; |
---|
3241 | |
---|
3242 | pHeapTest(p.p, (p.heap == NULL ? mm_specHeap : p.heap)); |
---|
3243 | assume(p.pLength == 0 || pLength(p.p) == p.pLength); |
---|
3244 | |
---|
3245 | strat->newt = TRUE; |
---|
3246 | if (strat->tl == strat->tmax-1) enlargeT(&strat->T,&strat->tmax,setmax); |
---|
3247 | for (i=strat->tl+1; i>=atT+1; i--) |
---|
3248 | strat->T[i] = strat->T[i-1]; |
---|
3249 | strat->T[atT].p = p.p; |
---|
3250 | if (strat->honey) |
---|
3251 | strat->T[atT].ecart = p.ecart; |
---|
3252 | if (TEST_OPT_INTSTRATEGY) |
---|
3253 | strat->T[atT].length = p.length; |
---|
3254 | |
---|
3255 | strat->T[atT].heap = p.heap; |
---|
3256 | strat->T[atT].pLength = p.pLength; |
---|
3257 | if (p.sev == 0) |
---|
3258 | { |
---|
3259 | p.sev = pGetShortExpVector(p.p); |
---|
3260 | } |
---|
3261 | else |
---|
3262 | { |
---|
3263 | assume(p.sev == pGetShortExpVector(p.p)); |
---|
3264 | } |
---|
3265 | strat->T[atT].sev = p.sev; |
---|
3266 | |
---|
3267 | strat->tl++; |
---|
3268 | } |
---|
3269 | |
---|
3270 | void initHilbCrit(ideal F, ideal Q, intvec **hilb,kStrategy strat) |
---|
3271 | { |
---|
3272 | if (strat->homog!=isHomog) |
---|
3273 | { |
---|
3274 | *hilb=NULL; |
---|
3275 | } |
---|
3276 | } |
---|
3277 | |
---|
3278 | void initBuchMoraCrit(kStrategy strat) |
---|
3279 | { |
---|
3280 | strat->sugarCrit = TEST_OPT_SUGARCRIT; |
---|
3281 | strat->Gebauer = BTEST1(2) || strat->homog || strat->sugarCrit; |
---|
3282 | strat->honey = !strat->homog || strat->sugarCrit || TEST_OPT_WEIGHTM; |
---|
3283 | if (TEST_OPT_NOT_SUGAR) strat->honey = FALSE; |
---|
3284 | strat->pairtest = NULL; |
---|
3285 | /* alway use tailreduction, except: |
---|
3286 | * - in local rings, - in lex order case, -in ring over extensions */ |
---|
3287 | strat->noTailReduction = !TEST_OPT_REDTAIL; |
---|
3288 | if (TEST_OPT_DEBUG) |
---|
3289 | { |
---|
3290 | if (strat->homog) PrintS("ideal/module is homogeneous\n"); |
---|
3291 | else PrintS("ideal/module is not homogeneous\n"); |
---|
3292 | } |
---|
3293 | } |
---|
3294 | |
---|
3295 | void initBuchMoraPos (kStrategy strat) |
---|
3296 | { |
---|
3297 | if (pOrdSgn==1) |
---|
3298 | { |
---|
3299 | if (strat->honey) |
---|
3300 | { |
---|
3301 | strat->posInL = posInL15; |
---|
3302 | strat->posInT = posInT15; |
---|
3303 | } |
---|
3304 | else if (pLexOrder && !TEST_OPT_INTSTRATEGY) |
---|
3305 | { |
---|
3306 | strat->posInL = posInL11; |
---|
3307 | strat->posInT = posInT11; |
---|
3308 | } |
---|
3309 | else if (TEST_OPT_INTSTRATEGY) |
---|
3310 | { |
---|
3311 | strat->posInL = posInL11; |
---|
3312 | strat->posInT = posInT11; |
---|
3313 | } |
---|
3314 | else |
---|
3315 | { |
---|
3316 | strat->posInL = posInL0; |
---|
3317 | strat->posInT = posInT0; |
---|
3318 | } |
---|
3319 | //if (strat->minim>0) strat->posInL =posInLSpecial; |
---|
3320 | } |
---|
3321 | else |
---|
3322 | { |
---|
3323 | if (strat->homog) |
---|
3324 | { |
---|
3325 | strat->posInL = posInL11; |
---|
3326 | strat->posInT = posInT11; |
---|
3327 | } |
---|
3328 | else |
---|
3329 | { |
---|
3330 | if ((currRing->order[0]==ringorder_c) |
---|
3331 | ||(currRing->order[0]==ringorder_C)) |
---|
3332 | { |
---|
3333 | strat->posInL = posInL17_c; |
---|
3334 | strat->posInT = posInT17_c; |
---|
3335 | } |
---|
3336 | else |
---|
3337 | { |
---|
3338 | strat->posInL = posInL17; |
---|
3339 | strat->posInT = posInT17; |
---|
3340 | } |
---|
3341 | } |
---|
3342 | } |
---|
3343 | if (strat->minim>0) strat->posInL =posInLSpecial; |
---|
3344 | // for further tests only |
---|
3345 | if ((BTEST1(11)) || (BTEST1(12))) |
---|
3346 | strat->posInL = posInL11; |
---|
3347 | else if ((BTEST1(13)) || (BTEST1(14))) |
---|
3348 | strat->posInL = posInL13; |
---|
3349 | else if ((BTEST1(15)) || (BTEST1(16))) |
---|
3350 | strat->posInL = posInL15; |
---|
3351 | else if ((BTEST1(17)) || (BTEST1(18))) |
---|
3352 | strat->posInL = posInL17; |
---|
3353 | if (BTEST1(11)) |
---|
3354 | strat->posInT = posInT11; |
---|
3355 | else if (BTEST1(13)) |
---|
3356 | strat->posInT = posInT13; |
---|
3357 | else if (BTEST1(15)) |
---|
3358 | strat->posInT = posInT15; |
---|
3359 | else if ((BTEST1(17))) |
---|
3360 | strat->posInT = posInT17; |
---|
3361 | else if ((BTEST1(19))) |
---|
3362 | strat->posInT = posInT19; |
---|
3363 | else if (BTEST1(12) || BTEST1(14) || BTEST1(16) || BTEST1(18)) |
---|
3364 | strat->posInT = posInT1; |
---|
3365 | } |
---|
3366 | |
---|
3367 | void initBuchMora (ideal F,ideal Q,kStrategy strat) |
---|
3368 | { |
---|
3369 | strat->interpt = BTEST1(OPT_INTERRUPT); |
---|
3370 | strat->kHEdge=NULL; |
---|
3371 | if (pOrdSgn==1) strat->kHEdgeFound=FALSE; |
---|
3372 | /*- creating temp data structures------------------- -*/ |
---|
3373 | strat->cp = 0; |
---|
3374 | strat->c3 = 0; |
---|
3375 | strat->tail = pInit(); |
---|
3376 | /*- set s -*/ |
---|
3377 | strat->sl = -1; |
---|
3378 | /*- set L -*/ |
---|
3379 | strat->Lmax = setmax; |
---|
3380 | strat->Ll = -1; |
---|
3381 | strat->L = initL(); |
---|
3382 | /*- set B -*/ |
---|
3383 | strat->Bmax = setmax; |
---|
3384 | strat->Bl = -1; |
---|
3385 | strat->B = initL(); |
---|
3386 | /*- set T -*/ |
---|
3387 | strat->tl = -1; |
---|
3388 | strat->tmax = setmax; |
---|
3389 | strat->T = initT(); |
---|
3390 | /*- init local data struct.---------------------------------------- -*/ |
---|
3391 | strat->P.ecart=0; |
---|
3392 | strat->P.length=0; |
---|
3393 | if (pOrdSgn==-1) |
---|
3394 | { |
---|
3395 | if (strat->kHEdge!=NULL) pSetComp(strat->kHEdge, strat->ak); |
---|
3396 | if (strat->kNoether!=NULL) pSetComp(strat->kNoether, strat->ak); |
---|
3397 | } |
---|
3398 | if(TEST_OPT_SB_1) |
---|
3399 | { |
---|
3400 | int i; |
---|
3401 | ideal P=idInit(IDELEMS(F)-strat->newIdeal,F->rank); |
---|
3402 | for (i=strat->newIdeal;i<IDELEMS(F);i++) |
---|
3403 | { |
---|
3404 | P->m[i-strat->newIdeal] = F->m[i]; |
---|
3405 | F->m[i] = NULL; |
---|
3406 | } |
---|
3407 | initSSpecial(F,Q,P,strat); |
---|
3408 | for (i=strat->newIdeal;i<IDELEMS(F);i++) |
---|
3409 | { |
---|
3410 | F->m[i] = P->m[i-strat->newIdeal]; |
---|
3411 | P->m[i-strat->newIdeal] = NULL; |
---|
3412 | } |
---|
3413 | idDelete(&P); |
---|
3414 | } |
---|
3415 | else |
---|
3416 | { |
---|
3417 | /*Shdl=*/initSL(F, Q,strat); /*sets also S, ecartS, fromQ */ |
---|
3418 | // /*Shdl=*/initS(F, Q,strat); /*sets also S, ecartS, fromQ */ |
---|
3419 | } |
---|
3420 | strat->kIdeal = NULL; |
---|
3421 | strat->fromT = FALSE; |
---|
3422 | strat->noTailReduction = !TEST_OPT_REDTAIL; |
---|
3423 | if(!TEST_OPT_SB_1) |
---|
3424 | { |
---|
3425 | updateS(TRUE,strat); |
---|
3426 | pairs(strat); |
---|
3427 | } |
---|
3428 | if (strat->fromQ!=NULL) Free((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int)); |
---|
3429 | strat->fromQ=NULL; |
---|
3430 | } |
---|
3431 | |
---|
3432 | void exitBuchMora (kStrategy strat) |
---|
3433 | { |
---|
3434 | /*- release temp data -*/ |
---|
3435 | cleanT(strat); |
---|
3436 | Free((ADDRESS)strat->T,(strat->tmax)*sizeof(TObject)); |
---|
3437 | Free((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int)); |
---|
3438 | Free((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(int)); |
---|
3439 | /*- set L: should be empty -*/ |
---|
3440 | Free((ADDRESS)strat->L,(strat->Lmax)*sizeof(LObject)); |
---|
3441 | /*- set B: should be empty -*/ |
---|
3442 | Free((ADDRESS)strat->B,(strat->Bmax)*sizeof(LObject)); |
---|
3443 | pDelete1(&strat->tail); |
---|
3444 | strat->syzComp=0; |
---|
3445 | if (strat->kIdeal!=NULL) |
---|
3446 | { |
---|
3447 | FreeSizeOf((ADDRESS)strat->kIdeal,sleftv); |
---|
3448 | strat->kIdeal=NULL; |
---|
3449 | } |
---|
3450 | } |
---|
3451 | |
---|
3452 | /*2 |
---|
3453 | * in the case of a standardbase of a module over a qring: |
---|
3454 | * replace polynomials in i by ak vectors, |
---|
3455 | * (the polynomial * unit vectors gen(1)..gen(ak) |
---|
3456 | * in every case (also for ideals:) |
---|
3457 | * deletes divisible vectors/polynomials |
---|
3458 | */ |
---|
3459 | void updateResult(ideal r,ideal Q,kStrategy strat) |
---|
3460 | { |
---|
3461 | int l; |
---|
3462 | if (strat->ak>0) |
---|
3463 | { |
---|
3464 | for (l=IDELEMS(r)-1;l>=0;l--) |
---|
3465 | { |
---|
3466 | if ((r->m[l]!=NULL) && (pGetComp(r->m[l])==0)) |
---|
3467 | { |
---|
3468 | pDelete(&r->m[l]); // and set it to NULL |
---|
3469 | } |
---|
3470 | } |
---|
3471 | } |
---|
3472 | else |
---|
3473 | { |
---|
3474 | int q; |
---|
3475 | poly p; |
---|
3476 | for (l=IDELEMS(r)-1;l>=0;l--) |
---|
3477 | { |
---|
3478 | if (r->m[l]!=NULL) |
---|
3479 | { |
---|
3480 | for(q=IDELEMS(Q)-1; q>=0;q--) |
---|
3481 | { |
---|
3482 | if ((Q->m[q]!=NULL) |
---|
3483 | &&(pEqual(r->m[l],Q->m[q]))) |
---|
3484 | { |
---|
3485 | if (TEST_OPT_REDSB) |
---|
3486 | { |
---|
3487 | p=r->m[l]; |
---|
3488 | r->m[l]=kNF(Q,NULL,p); |
---|
3489 | pDelete(&p); |
---|
3490 | } |
---|
3491 | else |
---|
3492 | { |
---|
3493 | pDelete(&r->m[l]); // and set it to NULL |
---|
3494 | } |
---|
3495 | break; |
---|
3496 | } |
---|
3497 | } |
---|
3498 | } |
---|
3499 | } |
---|
3500 | } |
---|
3501 | idSkipZeroes(r); |
---|
3502 | } |
---|
3503 | |
---|
3504 | void completeReduce (kStrategy strat) |
---|
3505 | { |
---|
3506 | int i; |
---|
3507 | |
---|
3508 | strat->noTailReduction = FALSE; |
---|
3509 | if (TEST_OPT_PROT) |
---|
3510 | { |
---|
3511 | PrintLn(); |
---|
3512 | if (timerv) writeTime("standard base computed:"); |
---|
3513 | } |
---|
3514 | if (TEST_OPT_PROT) |
---|
3515 | { |
---|
3516 | Print("(S:%d)",strat->sl);mflush(); |
---|
3517 | } |
---|
3518 | if(pOrdSgn==1) |
---|
3519 | { |
---|
3520 | for (i=strat->sl; i>0; i--) |
---|
3521 | { |
---|
3522 | //if (strat->interpt) test_int_std(strat->kIdeal); |
---|
3523 | strat->S[i] = redtailBba(strat->S[i],i-1,strat); |
---|
3524 | if (TEST_OPT_INTSTRATEGY) |
---|
3525 | { |
---|
3526 | //if (strat->redTailChange) |
---|
3527 | pCleardenom(strat->S[i]); |
---|
3528 | } |
---|
3529 | if (TEST_OPT_PROT) |
---|
3530 | { |
---|
3531 | PrintS("-");mflush(); |
---|
3532 | } |
---|
3533 | } |
---|
3534 | } |
---|
3535 | else |
---|
3536 | { |
---|
3537 | for (i=strat->sl; i>=0; i--) |
---|
3538 | { |
---|
3539 | //if (strat->interpt) test_int_std(strat->kIdeal); |
---|
3540 | strat->S[i] = redtail(strat->S[i],strat->sl,strat); |
---|
3541 | if (TEST_OPT_INTSTRATEGY) |
---|
3542 | { |
---|
3543 | pCleardenom(strat->S[i]); |
---|
3544 | } |
---|
3545 | if (TEST_OPT_PROT) |
---|
3546 | { |
---|
3547 | PrintS("-");mflush(); |
---|
3548 | } |
---|
3549 | } |
---|
3550 | } |
---|
3551 | } |
---|
3552 | |
---|
3553 | /*2 |
---|
3554 | * computes the new strat->kHEdge and the new pNoether, |
---|
3555 | * returns TRUE, if pNoether has changed |
---|
3556 | */ |
---|
3557 | BOOLEAN newHEdge(polyset S, int ak,kStrategy strat) |
---|
3558 | { |
---|
3559 | int i,j; |
---|
3560 | poly newNoether; |
---|
3561 | |
---|
3562 | scComputeHC(strat->Shdl,ak,strat->kHEdge); |
---|
3563 | /* compare old and new noether*/ |
---|
3564 | newNoether = pHead0(strat->kHEdge); |
---|
3565 | j = pFDeg(newNoether); |
---|
3566 | for (i=1; i<=pVariables; i++) |
---|
3567 | { |
---|
3568 | if (pGetExp(newNoether, i) > 0) pDecrExp(newNoether,i); |
---|
3569 | } |
---|
3570 | pSetm(newNoether); |
---|
3571 | if (j < strat->HCord) /*- statistics -*/ |
---|
3572 | { |
---|
3573 | if (TEST_OPT_PROT) |
---|
3574 | { |
---|
3575 | Print("H(%d)",j); |
---|
3576 | mflush(); |
---|
3577 | } |
---|
3578 | strat->HCord=j; |
---|
3579 | if (TEST_OPT_DEBUG) |
---|
3580 | { |
---|
3581 | Print("H(%d):",j); |
---|
3582 | wrp(strat->kHEdge); |
---|
3583 | PrintLn(); |
---|
3584 | } |
---|
3585 | } |
---|
3586 | if (pComp(strat->kNoether,newNoether)!=1) |
---|
3587 | { |
---|
3588 | pDelete(&strat->kNoether); |
---|
3589 | strat->kNoether=newNoether; |
---|
3590 | return TRUE; |
---|
3591 | } |
---|
3592 | pFree1(newNoether); |
---|
3593 | return FALSE; |
---|
3594 | } |
---|
3595 | |
---|
3596 | void kFreeStrat(kStrategy strat) |
---|
3597 | { |
---|
3598 | #if 0 |
---|
3599 | if (strat->THeap != NULL) |
---|
3600 | { |
---|
3601 | mmMergeHeap(mm_specHeap, strat->THeap); |
---|
3602 | mmUnGetTempHeap(&(strat->THeap)); |
---|
3603 | } |
---|
3604 | #endif |
---|
3605 | FreeSizeOf(strat, skStrategy); |
---|
3606 | } |
---|
3607 | |
---|
3608 | rOrderType_t spGetOrderType(ring r, int modrank, int syzcomp) |
---|
3609 | { |
---|
3610 | if (syzcomp > 0) |
---|
3611 | return rOrderType_Syz; |
---|
3612 | else |
---|
3613 | { |
---|
3614 | rOrderType_t rot = rGetOrderType(r); |
---|
3615 | |
---|
3616 | if ((rot == rOrderType_CompExp || rot == rOrderType_ExpComp) && |
---|
3617 | (modrank == 0)) |
---|
3618 | return rOrderType_Exp; |
---|
3619 | else |
---|
3620 | return rot; |
---|
3621 | } |
---|
3622 | } |
---|
3623 | |
---|
3624 | |
---|