1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | static char rcsid[] = "$Header: /exports/cvsroot-2/cvsroot/Singular/gr_kstd2.cc,v 1.1 2001-02-28 11:39:17 levandov Exp $"; |
---|
5 | /* $Log: not supported by cvs2svn $ |
---|
6 | /* Revision 1.1 2000/07/20 16:11:45 obachman |
---|
7 | /* * added stuff |
---|
8 | /* |
---|
9 | */ |
---|
10 | /* |
---|
11 | * ABSTRACT - Kernel: alg. of Buchberger |
---|
12 | */ |
---|
13 | |
---|
14 | #include "mod2.h" |
---|
15 | #ifdef HAVE_PLURAL |
---|
16 | #include "omalloc.h" |
---|
17 | #include "polys.h" |
---|
18 | #include "ideals.h" |
---|
19 | #include "febase.h" |
---|
20 | #include "kutil.h" |
---|
21 | #include "kstd1.h" |
---|
22 | #include "khstd.h" |
---|
23 | //#include "spolys.h" |
---|
24 | #include "cntrlc.h" |
---|
25 | #include "weight.h" |
---|
26 | #include "ipid.h" |
---|
27 | #include "ipshell.h" |
---|
28 | #include "intvec.h" |
---|
29 | #include "tok.h" |
---|
30 | |
---|
31 | /*2 |
---|
32 | * consider the part above syzComp: |
---|
33 | * (assume the polynomial comes from a syz computation) |
---|
34 | * - it is a constant term: return a copy of it |
---|
35 | * - else: return NULL |
---|
36 | */ |
---|
37 | static poly kFromInput(poly p,kStrategy strat) |
---|
38 | { |
---|
39 | poly q=p; |
---|
40 | |
---|
41 | if (pGetComp(q)>strat->syzComp) return NULL; |
---|
42 | while ((q!=NULL) && (pGetComp(q)<=strat->syzComp)) pIter(q); |
---|
43 | if (pIsConstantComp(q)) |
---|
44 | return pHead(q); |
---|
45 | return NULL; |
---|
46 | } |
---|
47 | |
---|
48 | /*2 |
---|
49 | * reduction procedure for the homogeneous case |
---|
50 | * and the case of a degree-ordering |
---|
51 | */ |
---|
52 | static int redHomog (LObject* h,kStrategy strat) |
---|
53 | { |
---|
54 | if (strat->tl<0) |
---|
55 | { |
---|
56 | enterTBba((*h),0,strat); |
---|
57 | return 1; |
---|
58 | } |
---|
59 | |
---|
60 | int j = 0; |
---|
61 | |
---|
62 | if (TEST_OPT_DEBUG) |
---|
63 | { |
---|
64 | PrintS("red:"); |
---|
65 | wrp(h->p); |
---|
66 | PrintS(" "); |
---|
67 | } |
---|
68 | loop |
---|
69 | { |
---|
70 | if (TEST_OPT_DEBUG) Print("%d",j); |
---|
71 | if (pDivisibleBy(strat->S[j],(*h).p)) |
---|
72 | { |
---|
73 | if (TEST_OPT_DEBUG) |
---|
74 | { |
---|
75 | PrintS("+\nwith "); |
---|
76 | wrp(strat->S[j]); |
---|
77 | } |
---|
78 | if (strat->interpt) test_int_std(strat->kIdeal); |
---|
79 | /*- compute the s-polynomial -*/ |
---|
80 | (*h).p = spSpolyRed(strat->S[j],(*h).p,strat->kNoether); |
---|
81 | if ((*h).p == NULL) |
---|
82 | { |
---|
83 | if (TEST_OPT_DEBUG) PrintS(" to 0\n"); |
---|
84 | if (h->lcm!=NULL) pLmFree((*h).lcm); |
---|
85 | (*h).lcm=NULL; |
---|
86 | return 0; |
---|
87 | } |
---|
88 | /* |
---|
89 | * else if (strat->syzComp) |
---|
90 | * { |
---|
91 | * if (pMinComp((*h).p) > strat->syzComp) |
---|
92 | * { |
---|
93 | * enterTBba((*h),strat->tl+1,strat); |
---|
94 | * return; |
---|
95 | * } |
---|
96 | * } |
---|
97 | */ |
---|
98 | /*- try to reduce the s-polynomial -*/ |
---|
99 | j = 0; |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | if (j >= strat->sl) |
---|
104 | { |
---|
105 | enterTBba((*h),strat->tl+1,strat); |
---|
106 | return 1; |
---|
107 | } |
---|
108 | j++; |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | /*2 |
---|
114 | * reduction procedure for the homogeneous case |
---|
115 | * and the case of a degree-ordering |
---|
116 | */ |
---|
117 | static int redHomog0 (LObject* h,kStrategy strat) |
---|
118 | { |
---|
119 | if (strat->tl<0) |
---|
120 | { |
---|
121 | enterTBba((*h),0,strat); |
---|
122 | return 0; |
---|
123 | } |
---|
124 | |
---|
125 | int j = 0; |
---|
126 | int k = 0; |
---|
127 | |
---|
128 | if (TEST_OPT_DEBUG) |
---|
129 | { |
---|
130 | PrintS("red:"); |
---|
131 | wrp(h->p); |
---|
132 | PrintS(" "); |
---|
133 | } |
---|
134 | loop |
---|
135 | { |
---|
136 | if (TEST_OPT_DEBUG) Print("%d",j); |
---|
137 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
138 | { |
---|
139 | if (strat->interpt) test_int_std(strat->kIdeal); |
---|
140 | if (TEST_OPT_DEBUG) |
---|
141 | { |
---|
142 | PrintS("+\nwith "); |
---|
143 | wrp(strat->S[j]); |
---|
144 | } |
---|
145 | /*- compute the s-polynomial -*/ |
---|
146 | (*h).p = spSpolyRed(strat->T[j].p,(*h).p,strat->kNoether); |
---|
147 | if ((*h).p == NULL) |
---|
148 | { |
---|
149 | if (TEST_OPT_DEBUG) PrintS(" to 0\n"); |
---|
150 | if (h->lcm!=NULL) pLmFree((*h).lcm); |
---|
151 | (*h).lcm=NULL; |
---|
152 | return 0; |
---|
153 | } |
---|
154 | else if (strat->syzComp!=0) |
---|
155 | { |
---|
156 | if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
157 | { |
---|
158 | //pContent((*h).p); |
---|
159 | pCleardenom((*h).p);// also does a pContent |
---|
160 | /* |
---|
161 | * (*h).length=pLength0((*h).p); |
---|
162 | */ |
---|
163 | k=strat->posInT(strat->T,strat->tl,(*h)); |
---|
164 | enterTBba((*h),k,strat); |
---|
165 | return 0; |
---|
166 | } |
---|
167 | } |
---|
168 | /*- try to reduce the s-polynomial -*/ |
---|
169 | j = 0; |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | if (j >= strat->tl) |
---|
174 | { |
---|
175 | //pContent((*h).p); |
---|
176 | pCleardenom((*h).p);// also does a pContent |
---|
177 | /* |
---|
178 | * (*h).length=pLength0((*h).p); |
---|
179 | */ |
---|
180 | k=strat->posInT(strat->T,strat->tl,(*h)); |
---|
181 | enterTBba((*h),k,strat); |
---|
182 | return 0; |
---|
183 | } |
---|
184 | j++; |
---|
185 | } |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | /*2 |
---|
190 | * reduction procedure for the inhomogeneous case |
---|
191 | * and not a degree-ordering |
---|
192 | */ |
---|
193 | static int redLazy (LObject* h,kStrategy strat) |
---|
194 | { |
---|
195 | if (strat->tl<0) |
---|
196 | { |
---|
197 | enterTBba((*h),0,strat); |
---|
198 | return 0; |
---|
199 | } |
---|
200 | |
---|
201 | int at,d,i; |
---|
202 | int j = 0; |
---|
203 | int pass = 0; |
---|
204 | int reddeg = pFDeg((*h).p); |
---|
205 | |
---|
206 | if (TEST_OPT_DEBUG) |
---|
207 | { |
---|
208 | PrintS("red:"); |
---|
209 | wrp(h->p); |
---|
210 | PrintS(" "); |
---|
211 | } |
---|
212 | loop |
---|
213 | { |
---|
214 | if (TEST_OPT_DEBUG) Print("%d",j); |
---|
215 | if (pDivisibleBy(strat->S[j],(*h).p)) |
---|
216 | { |
---|
217 | if (strat->interpt) test_int_std(strat->kIdeal); |
---|
218 | if (TEST_OPT_DEBUG) |
---|
219 | { |
---|
220 | PrintS("+\nwith "); |
---|
221 | wrp(strat->S[j]); |
---|
222 | } |
---|
223 | /*- compute the s-polynomial -*/ |
---|
224 | (*h).p = spSpolyRed(strat->S[j],(*h).p,strat->kNoether); |
---|
225 | if ((*h).p == NULL) |
---|
226 | { |
---|
227 | if (TEST_OPT_DEBUG) PrintS(" to 0\n"); |
---|
228 | if (h->lcm!=NULL) pLmFree((*h).lcm); |
---|
229 | (*h).lcm=NULL; |
---|
230 | return 0; |
---|
231 | } |
---|
232 | // else if (strat->syzComp) |
---|
233 | // { |
---|
234 | // if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
235 | // { |
---|
236 | // if (TEST_OPT_DEBUG) PrintS(" > syzComp\n"); |
---|
237 | // if (TEST_OPT_INTSTRATEGY) pContent(h->p); |
---|
238 | // enterTBba((*h),strat->tl+1,strat); |
---|
239 | // return; |
---|
240 | // } |
---|
241 | // } |
---|
242 | else if (TEST_OPT_DEBUG) |
---|
243 | { |
---|
244 | PrintS("to:"); |
---|
245 | wrp((*h).p); |
---|
246 | PrintLn(); |
---|
247 | } |
---|
248 | /*- try to reduce the s-polynomial -*/ |
---|
249 | pass++; |
---|
250 | d = pFDeg((*h).p); |
---|
251 | if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
252 | { |
---|
253 | at = posInL11(strat->L,strat->Ll,h,strat); |
---|
254 | if (at <= strat->Ll) |
---|
255 | { |
---|
256 | i=strat->sl+1; |
---|
257 | do |
---|
258 | { |
---|
259 | i--; |
---|
260 | if (i<0) |
---|
261 | { |
---|
262 | enterTBba((*h),strat->tl+1,strat); |
---|
263 | return 0; |
---|
264 | } |
---|
265 | } |
---|
266 | while (!pDivisibleBy(strat->S[i],(*h).p)); |
---|
267 | if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at); |
---|
268 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
269 | (*h).p = NULL; |
---|
270 | return 0; |
---|
271 | } |
---|
272 | } |
---|
273 | else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d != reddeg)) |
---|
274 | { |
---|
275 | Print(".%d",d);mflush(); |
---|
276 | reddeg = d; |
---|
277 | } |
---|
278 | j = 0; |
---|
279 | } |
---|
280 | else |
---|
281 | { |
---|
282 | if (TEST_OPT_DEBUG) PrintS("-"); |
---|
283 | if (j >= strat->sl) |
---|
284 | { |
---|
285 | if (TEST_OPT_DEBUG) PrintLn(); |
---|
286 | if (TEST_OPT_INTSTRATEGY) |
---|
287 | { |
---|
288 | //pContent(h->p); |
---|
289 | pCleardenom(h->p);// also does a pContent |
---|
290 | } |
---|
291 | enterTBba((*h),strat->tl+1,strat); |
---|
292 | return 0; |
---|
293 | } |
---|
294 | j++; |
---|
295 | } |
---|
296 | } |
---|
297 | } |
---|
298 | |
---|
299 | /*2 |
---|
300 | * reduction procedure for the sugar-strategy (honey) |
---|
301 | * reduces h with elements from T choosing first possible |
---|
302 | * element in T with respect to the given ecart |
---|
303 | */ |
---|
304 | static int redHoney (LObject* h,kStrategy strat) |
---|
305 | { |
---|
306 | if (strat->tl<0) |
---|
307 | { |
---|
308 | enterTBba((*h),0,strat); |
---|
309 | return 0; |
---|
310 | } |
---|
311 | |
---|
312 | poly pi; |
---|
313 | int i,j,at,reddeg,d,pass,ei; |
---|
314 | |
---|
315 | pass = j = 0; |
---|
316 | d = reddeg = pFDeg((*h).p)+(*h).ecart; |
---|
317 | if (TEST_OPT_DEBUG) |
---|
318 | { |
---|
319 | PrintS("red:"); |
---|
320 | wrp((*h).p); |
---|
321 | } |
---|
322 | loop |
---|
323 | { |
---|
324 | if (TEST_OPT_DEBUG) Print("%d",j); |
---|
325 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
326 | { |
---|
327 | if (TEST_OPT_DEBUG) PrintS("+"); |
---|
328 | pi = strat->T[j].p; |
---|
329 | ei = strat->T[j].ecart; |
---|
330 | /* |
---|
331 | * the polynomial to reduce with (up to the moment) is; |
---|
332 | * pi with ecart ei |
---|
333 | */ |
---|
334 | i = j; |
---|
335 | loop |
---|
336 | { |
---|
337 | /*- takes the first possible with respect to ecart -*/ |
---|
338 | i++; |
---|
339 | if (i > strat->tl) |
---|
340 | break; |
---|
341 | if ((!BTEST1(20)) && (ei <= (*h).ecart)) |
---|
342 | break; |
---|
343 | if (TEST_OPT_DEBUG) Print("%d",i); |
---|
344 | if ((strat->T[i].ecart < ei) && pDivisibleBy(strat->T[i].p,(*h).p)) |
---|
345 | { |
---|
346 | if (TEST_OPT_DEBUG) PrintS("+"); |
---|
347 | /* |
---|
348 | * the polynomial to reduce with is now; |
---|
349 | */ |
---|
350 | pi = strat->T[i].p; |
---|
351 | ei = strat->T[i].ecart; |
---|
352 | } |
---|
353 | else if (TEST_OPT_DEBUG) PrintS("-"); |
---|
354 | } |
---|
355 | |
---|
356 | /* |
---|
357 | * end of search: have to reduce with pi |
---|
358 | */ |
---|
359 | if (ei > (*h).ecart) |
---|
360 | { |
---|
361 | /* |
---|
362 | * It is not possible to reduce h with smaller ecart; |
---|
363 | * if possible h goes to the lazy-set L,i.e |
---|
364 | * if its position in L would be not the last one |
---|
365 | */ |
---|
366 | if (strat->Ll >= 0) /* L is not empty */ |
---|
367 | { |
---|
368 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
369 | if(at <= strat->Ll) |
---|
370 | /*- h will not become the next element to reduce -*/ |
---|
371 | { |
---|
372 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
373 | if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at); |
---|
374 | (*h).p = NULL; |
---|
375 | return 0; |
---|
376 | } |
---|
377 | } |
---|
378 | } |
---|
379 | if (TEST_OPT_DEBUG) |
---|
380 | { |
---|
381 | PrintS("\nwith "); |
---|
382 | wrp(pi); |
---|
383 | } |
---|
384 | if (strat->fromT) |
---|
385 | { |
---|
386 | strat->fromT=FALSE; |
---|
387 | (*h).p = spSpolyRedNew(pi,(*h).p,strat->kNoether); |
---|
388 | } |
---|
389 | else |
---|
390 | (*h).p = spSpolyRed(pi,(*h).p,strat->kNoether); |
---|
391 | if (TEST_OPT_DEBUG) |
---|
392 | { |
---|
393 | PrintS(" to "); |
---|
394 | wrp((*h).p); |
---|
395 | PrintLn(); |
---|
396 | } |
---|
397 | if ((*h).p == NULL) |
---|
398 | { |
---|
399 | if (h->lcm!=NULL) pLmFree((*h).lcm); |
---|
400 | (*h).lcm=NULL; |
---|
401 | return 0; |
---|
402 | } |
---|
403 | /* compute the ecart */ |
---|
404 | if (ei <= (*h).ecart) |
---|
405 | (*h).ecart = d-pFDeg((*h).p); |
---|
406 | else |
---|
407 | (*h).ecart = d-pFDeg((*h).p)+ei-(*h).ecart; |
---|
408 | // if (strat->syzComp) |
---|
409 | // { |
---|
410 | // if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
411 | // { |
---|
412 | // if (TEST_OPT_DEBUG) |
---|
413 | // PrintS(" >syzComp\n"); |
---|
414 | // if (TEST_OPT_INTSTRATEGY) pContent(h->p); |
---|
415 | // at=strat->posInT(strat->T,strat->tl,(*h)); |
---|
416 | // enterTBba((*h),at,strat); |
---|
417 | // return; |
---|
418 | // } |
---|
419 | // } |
---|
420 | /* |
---|
421 | * try to reduce the s-polynomial h |
---|
422 | *test first whether h should go to the lazyset L |
---|
423 | *-if the degree jumps |
---|
424 | *-if the number of pre-defined reductions jumps |
---|
425 | */ |
---|
426 | pass++; |
---|
427 | d = pFDeg((*h).p)+(*h).ecart; |
---|
428 | if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
429 | { |
---|
430 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
431 | if (at <= strat->Ll) |
---|
432 | { |
---|
433 | /*test if h is already standardbasis element*/ |
---|
434 | i=strat->sl+1; |
---|
435 | do |
---|
436 | { |
---|
437 | i--; |
---|
438 | if (i<0) |
---|
439 | { |
---|
440 | at=strat->posInT(strat->T,strat->tl,(*h)); |
---|
441 | enterTBba((*h),at,strat); |
---|
442 | return 0; |
---|
443 | } |
---|
444 | } while (!pDivisibleBy(strat->S[i],(*h).p)); |
---|
445 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
446 | if (TEST_OPT_DEBUG) |
---|
447 | Print(" degree jumped: -> L%d\n",at); |
---|
448 | (*h).p = NULL; |
---|
449 | return 0; |
---|
450 | } |
---|
451 | } |
---|
452 | else if (TEST_OPT_PROT && (strat->Ll < 0) && (d > reddeg)) |
---|
453 | { |
---|
454 | reddeg = d; |
---|
455 | Print(".%d",d); mflush(); |
---|
456 | } |
---|
457 | j = 0; |
---|
458 | } |
---|
459 | else |
---|
460 | { |
---|
461 | if (TEST_OPT_DEBUG) PrintS("-"); |
---|
462 | if (j >= strat->tl) |
---|
463 | { |
---|
464 | if (TEST_OPT_DEBUG) PrintLn(); |
---|
465 | if (TEST_OPT_INTSTRATEGY) |
---|
466 | { |
---|
467 | //pContent(h->p); |
---|
468 | pCleardenom(h->p);// also does a pContent |
---|
469 | } |
---|
470 | at=strat->posInT(strat->T,strat->tl,(*h)); |
---|
471 | enterTBba((*h),at,strat); |
---|
472 | return 0; |
---|
473 | } |
---|
474 | j++; |
---|
475 | } |
---|
476 | } |
---|
477 | } |
---|
478 | |
---|
479 | /*2 |
---|
480 | * reduction procedure for tests only |
---|
481 | * reduces with elements from T and chooses the best possible |
---|
482 | */ |
---|
483 | static int redBest (LObject* h,kStrategy strat) |
---|
484 | { |
---|
485 | if (strat->tl<0) |
---|
486 | { |
---|
487 | enterTBba((*h),0,strat); |
---|
488 | return 0; |
---|
489 | } |
---|
490 | |
---|
491 | int j,jbest,at,reddeg,d,pass; |
---|
492 | poly p,ph; |
---|
493 | pass = j = 0; |
---|
494 | |
---|
495 | if (strat->honey) |
---|
496 | reddeg = pFDeg((*h).p)+(*h).ecart; |
---|
497 | else |
---|
498 | reddeg = pFDeg((*h).p); |
---|
499 | loop |
---|
500 | { |
---|
501 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
502 | { |
---|
503 | if (strat->interpt) test_int_std(strat->kIdeal); |
---|
504 | /* compute the s-polynomial */ |
---|
505 | if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p); |
---|
506 | #ifdef SDRING |
---|
507 | // spSpolyShortBba will not work in the SRING case |
---|
508 | if (pSDRING) |
---|
509 | { |
---|
510 | p=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether); |
---|
511 | if (p!=NULL) pDelete(&pNext(p)); |
---|
512 | } |
---|
513 | else |
---|
514 | #endif |
---|
515 | p = spSpolyShortBba(strat->T[j].p,(*h).p); |
---|
516 | /* computes only the first monomial of the spoly */ |
---|
517 | if (p) |
---|
518 | { |
---|
519 | jbest = j; |
---|
520 | /* looking for the best possible reduction */ |
---|
521 | if ((strat->syzComp==0) || (pMinComp(p) <= strat->syzComp)) |
---|
522 | { |
---|
523 | loop |
---|
524 | { |
---|
525 | j++; |
---|
526 | if (j > strat->tl) |
---|
527 | break; |
---|
528 | if (pDivisibleBy(strat->T[j].p,(*h).p)) |
---|
529 | { |
---|
530 | #ifdef SDRING |
---|
531 | // spSpolyShortBba will not work in the SRING case |
---|
532 | if (pSDRING) |
---|
533 | { |
---|
534 | ph=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether); |
---|
535 | if (ph!=NULL) pDelete(&pNext(ph)); |
---|
536 | } |
---|
537 | else |
---|
538 | #endif |
---|
539 | ph = spSpolyShortBba(strat->T[j].p,(*h).p); |
---|
540 | if (ph==NULL) |
---|
541 | { |
---|
542 | pLmFree(p); |
---|
543 | pDelete(&((*h).p)); |
---|
544 | if (h->lcm!=NULL) |
---|
545 | { |
---|
546 | pLmFree((*h).lcm); |
---|
547 | (*h).lcm=NULL; |
---|
548 | } |
---|
549 | return 0; |
---|
550 | } |
---|
551 | else if (pComp0(ph,p) == -1) |
---|
552 | { |
---|
553 | pLmFree(p); |
---|
554 | p = ph; |
---|
555 | jbest = j; |
---|
556 | } |
---|
557 | else |
---|
558 | { |
---|
559 | pLmFree(ph); |
---|
560 | } |
---|
561 | } |
---|
562 | } |
---|
563 | } |
---|
564 | pLmFree(p); |
---|
565 | (*h).p = spSpolyRed(strat->T[jbest].p,(*h).p,strat->kNoether); |
---|
566 | } |
---|
567 | else |
---|
568 | { |
---|
569 | if (h->lcm!=NULL) |
---|
570 | { |
---|
571 | pLmFree((*h).lcm); |
---|
572 | (*h).lcm=NULL; |
---|
573 | } |
---|
574 | (*h).p = NULL; |
---|
575 | return 0; |
---|
576 | } |
---|
577 | if (strat->honey && pLexOrder) |
---|
578 | strat->initEcart(h); |
---|
579 | /* h.length:=l; */ |
---|
580 | /* try to reduce the s-polynomial */ |
---|
581 | // if (strat->syzComp) |
---|
582 | // { |
---|
583 | // if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp)) |
---|
584 | // { |
---|
585 | // if (TEST_OPT_DEBUG) |
---|
586 | // PrintS(" >syzComp\n"); |
---|
587 | // if (TEST_OPT_INTSTRATEGY) pContent(h->p); |
---|
588 | // at=strat->posInT(strat->T,strat->tl,(*h)); |
---|
589 | // enterTBba((*h),at,strat); |
---|
590 | // return; |
---|
591 | // } |
---|
592 | // } |
---|
593 | if (strat->honey || pLexOrder) |
---|
594 | { |
---|
595 | pass++; |
---|
596 | d = pFDeg((*h).p); |
---|
597 | if (strat->honey) |
---|
598 | d += (*h).ecart; |
---|
599 | if ((strat->Ll >= 0) && ((pass > strat->LazyPass) || (d > reddeg))) |
---|
600 | { |
---|
601 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
602 | if (at <= strat->Ll) |
---|
603 | { |
---|
604 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
605 | (*h).p = NULL; |
---|
606 | return 0; |
---|
607 | } |
---|
608 | } |
---|
609 | else if (TEST_OPT_PROT && (strat->Ll < 0) && (d != reddeg)) |
---|
610 | { |
---|
611 | reddeg = d; |
---|
612 | Print("%d."); |
---|
613 | mflush(); |
---|
614 | } |
---|
615 | } |
---|
616 | j = 0; |
---|
617 | } |
---|
618 | else |
---|
619 | { |
---|
620 | if (j >= strat->tl) |
---|
621 | { |
---|
622 | if (TEST_OPT_INTSTRATEGY) |
---|
623 | { |
---|
624 | //pContent(h->p); |
---|
625 | pCleardenom(h->p);// also does a pContent |
---|
626 | } |
---|
627 | at=strat->posInT(strat->T,strat->tl,(*h)); |
---|
628 | enterTBba((*h),at,strat); |
---|
629 | return 0; |
---|
630 | } |
---|
631 | j++; |
---|
632 | } |
---|
633 | } |
---|
634 | } |
---|
635 | |
---|
636 | static void gr_initBba(ideal F,kStrategy strat) |
---|
637 | { |
---|
638 | int i; |
---|
639 | idhdl h; |
---|
640 | /* setting global variables ------------------- */ |
---|
641 | strat->enterS = enterSBba; |
---|
642 | if ((BTEST1(20)) && (!strat->honey)) |
---|
643 | strat->red = redBest; |
---|
644 | else if (strat->honey) |
---|
645 | strat->red = redHoney; |
---|
646 | else if (pLexOrder && !strat->homog) |
---|
647 | strat->red = redLazy; |
---|
648 | else if (TEST_OPT_INTSTRATEGY && strat->homog) |
---|
649 | strat->red = redHomog0; |
---|
650 | else |
---|
651 | strat->red = redHomog; |
---|
652 | |
---|
653 | if (pLexOrder && strat->honey) |
---|
654 | strat->initEcart = initEcartNormal; |
---|
655 | else |
---|
656 | strat->initEcart = initEcartBBA; |
---|
657 | if (strat->honey) |
---|
658 | strat->initEcartPair = initEcartPairMora; |
---|
659 | else |
---|
660 | strat->initEcartPair = initEcartPairBba; |
---|
661 | strat->kIdeal = NULL; |
---|
662 | //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD; |
---|
663 | //else strat->kIdeal->rtyp=MODUL_CMD; |
---|
664 | //strat->kIdeal->data=(void *)strat->Shdl; |
---|
665 | if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
666 | { |
---|
667 | //interred machen Aenderung |
---|
668 | pFDegOld=pFDeg; |
---|
669 | pLDegOld=pLDeg; |
---|
670 | h=ggetid("ecart"); |
---|
671 | if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD)) |
---|
672 | { |
---|
673 | ecartWeights=iv2array(IDINTVEC(h)); |
---|
674 | } |
---|
675 | else |
---|
676 | { |
---|
677 | ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short)); |
---|
678 | /*uses automatic computation of the ecartWeights to set them*/ |
---|
679 | kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights); |
---|
680 | } |
---|
681 | pFDeg=totaldegreeWecart; |
---|
682 | pLDeg=maxdegreeWecart; |
---|
683 | for(i=1; i<=pVariables; i++) |
---|
684 | Print(" %d",ecartWeights[i]); |
---|
685 | PrintLn(); |
---|
686 | mflush(); |
---|
687 | } |
---|
688 | } |
---|
689 | |
---|
690 | ideal gr_bba (ideal F, ideal Q,kStrategy strat) |
---|
691 | { |
---|
692 | intvec *w=NULL; |
---|
693 | intvec *hilb=NULL; |
---|
694 | int srmax,lrmax; |
---|
695 | int olddeg,reduc; |
---|
696 | int red_result=1; |
---|
697 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
698 | |
---|
699 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
700 | initHilbCrit(F,Q,&hilb,strat); |
---|
701 | gr_initBba(F,strat); |
---|
702 | initBuchMoraPos(strat); |
---|
703 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
704 | /*Shdl=*/initBuchMora(F, Q,strat); |
---|
705 | srmax = strat->sl; |
---|
706 | reduc = olddeg = lrmax = 0; |
---|
707 | /* compute------------------------------------------------------- */ |
---|
708 | while (strat->Ll >= 0) |
---|
709 | { |
---|
710 | if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/ |
---|
711 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
712 | test_int_std(strat->kIdeal); |
---|
713 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
714 | if (TEST_OPT_DEGBOUND |
---|
715 | && ((strat->honey && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p)>Kstd1_deg)) |
---|
716 | || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p)>Kstd1_deg)))) |
---|
717 | { |
---|
718 | /* |
---|
719 | *stops computation if |
---|
720 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
721 | *a predefined number Kstd1_deg |
---|
722 | */ |
---|
723 | while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
724 | break; |
---|
725 | } |
---|
726 | /* picks the last element from the lazyset L */ |
---|
727 | strat->P = strat->L[strat->Ll]; |
---|
728 | strat->Ll--; |
---|
729 | kTest(strat); |
---|
730 | if (pNext(strat->P.p) == strat->tail) |
---|
731 | { |
---|
732 | /* deletes the short spoly and computes */ |
---|
733 | pLmFree(strat->P.p); |
---|
734 | /* the real one */ |
---|
735 | strat->P.p = spSpolyCreate(strat->P.p1,strat->P.p2,strat->kNoether); |
---|
736 | } |
---|
737 | #ifdef SDRING |
---|
738 | if (strat->P.p != NULL) |
---|
739 | #endif |
---|
740 | { |
---|
741 | if (TEST_OPT_PROT) |
---|
742 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
743 | &olddeg,&reduc,strat, red_result); |
---|
744 | /* reduction of the element choosen from L */ |
---|
745 | strat->red(&strat->P,strat); |
---|
746 | } |
---|
747 | if (strat->P.p != NULL) |
---|
748 | { |
---|
749 | /* statistic */ |
---|
750 | if (TEST_OPT_PROT) PrintS("s"); |
---|
751 | /* enter P.p into s and L */ |
---|
752 | { |
---|
753 | int pos=posInS(strat,strat->sl,strat->P.p); |
---|
754 | { |
---|
755 | if (TEST_OPT_INTSTRATEGY) |
---|
756 | { |
---|
757 | if ((strat->syzComp==0)||(!strat->homog)) |
---|
758 | { |
---|
759 | strat->P.p = redtailBba(strat->P.p,pos-1,strat); |
---|
760 | pCleardenom(strat->P.p); |
---|
761 | } |
---|
762 | } |
---|
763 | else |
---|
764 | { |
---|
765 | pNorm(strat->P.p); |
---|
766 | if ((strat->syzComp==0)||(!strat->homog)) |
---|
767 | { |
---|
768 | strat->P.p = redtailBba(strat->P.p,pos-1,strat); |
---|
769 | } |
---|
770 | } |
---|
771 | if (TEST_OPT_DEBUG) |
---|
772 | { |
---|
773 | PrintS("new s:"); |
---|
774 | wrp(strat->P.p); |
---|
775 | PrintLn(); |
---|
776 | } |
---|
777 | enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat); |
---|
778 | if (strat->sl==-1) pos=0; |
---|
779 | else pos=posInS(strat,strat->sl,strat->P.p); |
---|
780 | strat->enterS(strat->P,pos,strat); |
---|
781 | } |
---|
782 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
783 | } |
---|
784 | if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm); |
---|
785 | if (strat->sl>srmax) srmax = strat->sl; |
---|
786 | } |
---|
787 | #ifdef KDEBUG |
---|
788 | strat->P.lcm=NULL; |
---|
789 | #endif |
---|
790 | kTest(strat); |
---|
791 | } |
---|
792 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
793 | /* complete reduction of the standard basis--------- */ |
---|
794 | if (TEST_OPT_REDSB) completeReduce(strat); |
---|
795 | /* release temp data-------------------------------- */ |
---|
796 | exitBuchMora(strat); |
---|
797 | if (TEST_OPT_WEIGHTM) |
---|
798 | { |
---|
799 | pFDeg=pFDegOld; |
---|
800 | pLDeg=pLDegOld; |
---|
801 | if (ecartWeights) |
---|
802 | { |
---|
803 | omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short)); |
---|
804 | ecartWeights=NULL; |
---|
805 | } |
---|
806 | } |
---|
807 | if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat); |
---|
808 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
809 | return (strat->Shdl); |
---|
810 | } |
---|
811 | #endif |
---|