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