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