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