1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: kstd2.cc,v 1.66 2000-12-12 08:44:46 obachman Exp $ */ |
---|
5 | /* |
---|
6 | * ABSTRACT - Kernel: alg. of Buchberger |
---|
7 | */ |
---|
8 | |
---|
9 | // #define PDEBUG 2 |
---|
10 | // define to enable tailRings |
---|
11 | #define HAVE_TAIL_RING |
---|
12 | |
---|
13 | #include "mod2.h" |
---|
14 | #include "kutil.h" |
---|
15 | #include "tok.h" |
---|
16 | #include "omalloc.h" |
---|
17 | #include "polys.h" |
---|
18 | #include "ideals.h" |
---|
19 | #include "febase.h" |
---|
20 | #include "kstd1.h" |
---|
21 | #include "khstd.h" |
---|
22 | #include "cntrlc.h" |
---|
23 | #include "weight.h" |
---|
24 | #include "ipid.h" |
---|
25 | #include "ipshell.h" |
---|
26 | #include "intvec.h" |
---|
27 | |
---|
28 | // #include "timer.h" |
---|
29 | |
---|
30 | // return -1 if no divisor is found |
---|
31 | // number of first divisor, otherwise |
---|
32 | int kFindDivisibleByInT(const TSet &T, const unsigned long* sevT, |
---|
33 | const int tl, const LObject* L, int start) |
---|
34 | { |
---|
35 | unsigned long not_sev = ~L->sev; |
---|
36 | int j = start; |
---|
37 | poly p; |
---|
38 | ring r; |
---|
39 | L->GetLm(p, r); |
---|
40 | |
---|
41 | pAssume(~not_sev == p_GetShortExpVector(p, r)); |
---|
42 | |
---|
43 | if (r == currRing) |
---|
44 | { |
---|
45 | while (1) |
---|
46 | { |
---|
47 | if (j > tl) return -1; |
---|
48 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
49 | if (p_LmShortDivisibleBy(T[j].p, sevT[j], |
---|
50 | p, not_sev, r)) |
---|
51 | return j; |
---|
52 | #else |
---|
53 | if (!(sevT[j] & not_sev) && |
---|
54 | p_LmDivisibleBy(T[j].p, p, r)) |
---|
55 | return j; |
---|
56 | #endif |
---|
57 | j++; |
---|
58 | } |
---|
59 | } |
---|
60 | else |
---|
61 | { |
---|
62 | while (1) |
---|
63 | { |
---|
64 | if (j > tl) return -1; |
---|
65 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
66 | if (p_LmShortDivisibleBy(T[j].t_p, sevT[j], |
---|
67 | p, not_sev, r)) |
---|
68 | return j; |
---|
69 | #else |
---|
70 | if (!(sevT[j] & not_sev) && |
---|
71 | p_LmDivisibleBy(T[j].t_p, p, r)) |
---|
72 | return j; |
---|
73 | #endif |
---|
74 | j++; |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | // same as above, only with set S |
---|
80 | int kFindDivisibleByInS(const polyset &S, const unsigned long* sev, const int sl, LObject* L) |
---|
81 | { |
---|
82 | unsigned long not_sev = ~L->sev; |
---|
83 | poly p = L->GetLmCurrRing(); |
---|
84 | int j = 0; |
---|
85 | |
---|
86 | pAssume(~not_sev == p_GetShortExpVector(p, currRing)); |
---|
87 | while (1) |
---|
88 | { |
---|
89 | if (j > sl) return -1; |
---|
90 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
91 | if (p_LmShortDivisibleBy(S[j], sev[j], |
---|
92 | p, not_sev, currRing)) |
---|
93 | return j; |
---|
94 | #else |
---|
95 | if ( !(sev[j] & not_sev) && |
---|
96 | p_LmDivisibleBy(S[j], p, currRing)) |
---|
97 | return j; |
---|
98 | #endif |
---|
99 | j++; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | /*2 |
---|
104 | * reduction procedure for the homogeneous case |
---|
105 | * and the case of a degree-ordering |
---|
106 | */ |
---|
107 | static int redHomog (LObject* h,kStrategy strat) |
---|
108 | { |
---|
109 | // if (strat->tl<0) return 1; |
---|
110 | #ifdef KDEBUG |
---|
111 | if (TEST_OPT_DEBUG) |
---|
112 | { |
---|
113 | PrintS("red:"); |
---|
114 | h->wrp(); |
---|
115 | PrintS(" "); |
---|
116 | } |
---|
117 | #endif |
---|
118 | int j; |
---|
119 | while (1) |
---|
120 | { |
---|
121 | // find a poly with which we can reduce |
---|
122 | h->SetShortExpVector(); |
---|
123 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h); |
---|
124 | if (j < 0) |
---|
125 | { |
---|
126 | h->SetpFDeg(); |
---|
127 | return 1; |
---|
128 | } |
---|
129 | |
---|
130 | // now we found one which is divisible -- reduce it |
---|
131 | ksReducePoly(h, &(strat->T[j]), strat->kNoether, NULL, strat); |
---|
132 | |
---|
133 | #ifdef KDEBUG |
---|
134 | if (TEST_OPT_DEBUG) |
---|
135 | { |
---|
136 | Print("\nto ", h->t_p); |
---|
137 | h->wrp(); |
---|
138 | PrintLn(); |
---|
139 | } |
---|
140 | #endif |
---|
141 | if (h->GetLmTailRing() == NULL) |
---|
142 | { |
---|
143 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
144 | #ifdef KDEBUG |
---|
145 | h->lcm=NULL; |
---|
146 | #endif |
---|
147 | return 0; |
---|
148 | } |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | /*2 |
---|
154 | * reduction procedure for the inhomogeneous case |
---|
155 | * and not a degree-ordering |
---|
156 | */ |
---|
157 | static int redLazy (LObject* h,kStrategy strat) |
---|
158 | { |
---|
159 | if (strat->tl<0) return 1; |
---|
160 | int at,d,i; |
---|
161 | int j = 0; |
---|
162 | int pass = 0; |
---|
163 | assume(h->pFDeg() == h->FDeg); |
---|
164 | long reddeg = h->GetpFDeg(); |
---|
165 | |
---|
166 | h->SetShortExpVector(); |
---|
167 | while (1) |
---|
168 | { |
---|
169 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h); |
---|
170 | if (j < 0) return 1; |
---|
171 | |
---|
172 | #ifdef KDEBUG |
---|
173 | if (TEST_OPT_DEBUG) |
---|
174 | { |
---|
175 | PrintS("red:"); |
---|
176 | h->wrp(); |
---|
177 | PrintS(" with "); |
---|
178 | strat->T[j].wrp(); |
---|
179 | } |
---|
180 | #endif |
---|
181 | |
---|
182 | ksReducePoly(h, &(strat->T[j]), strat->kNoether, NULL, strat); |
---|
183 | |
---|
184 | #ifdef KDEBUG |
---|
185 | if (TEST_OPT_DEBUG) |
---|
186 | { |
---|
187 | PrintS("\nto "); |
---|
188 | h->wrp(); |
---|
189 | PrintLn(); |
---|
190 | } |
---|
191 | #endif |
---|
192 | |
---|
193 | if (h->GetLmTailRing() == NULL) |
---|
194 | { |
---|
195 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
196 | #ifdef KDEBUG |
---|
197 | h->lcm=NULL; |
---|
198 | #endif |
---|
199 | return 0; |
---|
200 | } |
---|
201 | h->SetShortExpVector(); |
---|
202 | d = h->SetpFDeg(); |
---|
203 | /*- try to reduce the s-polynomial -*/ |
---|
204 | pass++; |
---|
205 | if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
206 | { |
---|
207 | h->SetLmCurrRing(); |
---|
208 | at = posInL11(strat->L,strat->Ll,h,strat); |
---|
209 | if (at <= strat->Ll) |
---|
210 | { |
---|
211 | if (kFindDivisibleByInS(strat->S, strat->sevS, strat->sl, h) < 0) |
---|
212 | return 1; |
---|
213 | #ifdef KDEBUG |
---|
214 | if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at); |
---|
215 | #endif |
---|
216 | h->CanonicalizeP(); |
---|
217 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
218 | h->Clear(); |
---|
219 | return -1; |
---|
220 | } |
---|
221 | } |
---|
222 | else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d != reddeg)) |
---|
223 | { |
---|
224 | Print(".%d",d);mflush(); |
---|
225 | reddeg = d; |
---|
226 | } |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | /*2 |
---|
231 | * reduction procedure for the sugar-strategy (honey) |
---|
232 | * reduces h with elements from T choosing first possible |
---|
233 | * element in T with respect to the given ecart |
---|
234 | */ |
---|
235 | static int redHoney (LObject* h, kStrategy strat) |
---|
236 | { |
---|
237 | if (strat->tl<0) return 1; |
---|
238 | assume(h->FDeg == h->pFDeg()); |
---|
239 | |
---|
240 | poly h_p; |
---|
241 | int i,j,at,pass,ei, ii, h_d; |
---|
242 | unsigned long not_sev; |
---|
243 | long reddeg,d; |
---|
244 | |
---|
245 | pass = j = 0; |
---|
246 | d = reddeg = h->GetpFDeg() + h->ecart; |
---|
247 | h->SetShortExpVector(); |
---|
248 | h_p = h->GetLmTailRing(); |
---|
249 | not_sev = ~ h->sev; |
---|
250 | loop |
---|
251 | { |
---|
252 | j = kFindDivisibleByInT(strat->T, strat->sevT, strat->tl, h); |
---|
253 | if (j < 0) return 1; |
---|
254 | |
---|
255 | ei = strat->T[j].ecart; |
---|
256 | ii = j; |
---|
257 | /* |
---|
258 | * the polynomial to reduce with (up to the moment) is; |
---|
259 | * pi with ecart ei |
---|
260 | */ |
---|
261 | i = j; |
---|
262 | loop |
---|
263 | { |
---|
264 | /*- takes the first possible with respect to ecart -*/ |
---|
265 | i++; |
---|
266 | if (i > strat->tl) |
---|
267 | break; |
---|
268 | if (ei <= h->ecart) |
---|
269 | break; |
---|
270 | if ((strat->T[i].ecart < ei) && |
---|
271 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
272 | h_p, not_sev, strat->tailRing)) |
---|
273 | { |
---|
274 | /* |
---|
275 | * the polynomial to reduce with is now; |
---|
276 | */ |
---|
277 | ei = strat->T[i].ecart; |
---|
278 | ii = i; |
---|
279 | } |
---|
280 | } |
---|
281 | |
---|
282 | /* |
---|
283 | * end of search: have to reduce with pi |
---|
284 | */ |
---|
285 | if ((pass!=0) && (ei > h->ecart)) |
---|
286 | { |
---|
287 | h->SetLmCurrRing(); |
---|
288 | /* |
---|
289 | * It is not possible to reduce h with smaller ecart; |
---|
290 | * if possible h goes to the lazy-set L,i.e |
---|
291 | * if its position in L would be not the last one |
---|
292 | */ |
---|
293 | if (strat->Ll >= 0) /* L is not empty */ |
---|
294 | { |
---|
295 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
296 | if(at <= strat->Ll) |
---|
297 | /*- h will not become the next element to reduce -*/ |
---|
298 | { |
---|
299 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
300 | #ifdef KDEBUG |
---|
301 | if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at); |
---|
302 | #endif |
---|
303 | h->Clear(); |
---|
304 | return -1; |
---|
305 | } |
---|
306 | } |
---|
307 | } |
---|
308 | #ifdef KDEBUG |
---|
309 | if (TEST_OPT_DEBUG) |
---|
310 | { |
---|
311 | PrintS("red:"); |
---|
312 | h->wrp(); |
---|
313 | PrintS(" with "); |
---|
314 | strat->T[ii].wrp(); |
---|
315 | } |
---|
316 | #endif |
---|
317 | assume(strat->fromT == FALSE); |
---|
318 | |
---|
319 | ksReducePoly(h, &(strat->T[ii]), strat->kNoether, NULL, strat); |
---|
320 | |
---|
321 | #ifdef KDEBUG |
---|
322 | if (TEST_OPT_DEBUG) |
---|
323 | { |
---|
324 | PrintS("\nto "); |
---|
325 | h->wrp(); |
---|
326 | PrintLn(); |
---|
327 | } |
---|
328 | #endif |
---|
329 | |
---|
330 | h_p = h->GetLmTailRing(); |
---|
331 | if (h_p == NULL) |
---|
332 | { |
---|
333 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
334 | #ifdef KDEBUG |
---|
335 | h->lcm=NULL; |
---|
336 | #endif |
---|
337 | return 0; |
---|
338 | } |
---|
339 | h->SetShortExpVector(); |
---|
340 | not_sev = ~ h->sev; |
---|
341 | h_d = h->SetpFDeg(); |
---|
342 | /* compute the ecart */ |
---|
343 | if (ei <= h->ecart) |
---|
344 | h->ecart = d-h_d; |
---|
345 | else |
---|
346 | h->ecart = d-h_d+ei-h->ecart; |
---|
347 | /* |
---|
348 | * try to reduce the s-polynomial h |
---|
349 | *test first whether h should go to the lazyset L |
---|
350 | *-if the degree jumps |
---|
351 | *-if the number of pre-defined reductions jumps |
---|
352 | */ |
---|
353 | pass++; |
---|
354 | d = h_d + h->ecart; |
---|
355 | if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
356 | { |
---|
357 | h->SetLmCurrRing(); |
---|
358 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
359 | if (at <= strat->Ll) |
---|
360 | { |
---|
361 | if (kFindDivisibleByInS(strat->S, strat->sevS, strat->sl, h) < 0) |
---|
362 | return 1; |
---|
363 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
364 | #ifdef KDEBUG |
---|
365 | if (TEST_OPT_DEBUG) |
---|
366 | Print(" degree jumped: -> L%d\n",at); |
---|
367 | #endif |
---|
368 | h->Clear(); |
---|
369 | return -1; |
---|
370 | } |
---|
371 | } |
---|
372 | else if (TEST_OPT_PROT && (strat->Ll < 0) && (d > reddeg)) |
---|
373 | { |
---|
374 | reddeg = d; |
---|
375 | Print(".%d",d); mflush(); |
---|
376 | } |
---|
377 | } |
---|
378 | } |
---|
379 | /*2 |
---|
380 | * reduction procedure for the normal form |
---|
381 | */ |
---|
382 | |
---|
383 | static poly redNF (poly h,kStrategy strat) |
---|
384 | { |
---|
385 | int j = 0; |
---|
386 | int z = 3; |
---|
387 | unsigned long not_sev; |
---|
388 | |
---|
389 | if (0 > strat->sl) |
---|
390 | { |
---|
391 | return h; |
---|
392 | } |
---|
393 | not_sev = ~ pGetShortExpVector(h); |
---|
394 | loop |
---|
395 | { |
---|
396 | if (pLmShortDivisibleBy(strat->S[j], strat->sevS[j], h, not_sev)) |
---|
397 | { |
---|
398 | //if (strat->interpt) test_int_std(strat->kIdeal); |
---|
399 | /*- compute the s-polynomial -*/ |
---|
400 | #ifdef KDEBUG |
---|
401 | if (TEST_OPT_DEBUG) |
---|
402 | { |
---|
403 | PrintS("red:"); |
---|
404 | wrp(h); |
---|
405 | PrintS(" with "); |
---|
406 | wrp(strat->S[j]); |
---|
407 | } |
---|
408 | #endif |
---|
409 | h = ksOldSpolyRed(strat->S[j],h,strat->kNoether); |
---|
410 | #ifdef KDEBUG |
---|
411 | if (TEST_OPT_DEBUG) |
---|
412 | { |
---|
413 | PrintS("\nto:"); |
---|
414 | wrp(h); |
---|
415 | PrintLn(); |
---|
416 | } |
---|
417 | #endif |
---|
418 | if (h == NULL) return NULL; |
---|
419 | z++; |
---|
420 | if (z>=10) |
---|
421 | { |
---|
422 | z=0; |
---|
423 | pNormalize(h); |
---|
424 | } |
---|
425 | /*- try to reduce the s-polynomial -*/ |
---|
426 | j = 0; |
---|
427 | not_sev = ~ pGetShortExpVector(h); |
---|
428 | } |
---|
429 | else |
---|
430 | { |
---|
431 | if (j >= strat->sl) return h; |
---|
432 | j++; |
---|
433 | } |
---|
434 | } |
---|
435 | } |
---|
436 | |
---|
437 | void initBba(ideal F,kStrategy strat) |
---|
438 | { |
---|
439 | int i; |
---|
440 | idhdl h; |
---|
441 | /* setting global variables ------------------- */ |
---|
442 | strat->enterS = enterSBba; |
---|
443 | if (strat->honey) |
---|
444 | strat->red = redHoney; |
---|
445 | else if (pLexOrder && !strat->homog) |
---|
446 | strat->red = redLazy; |
---|
447 | else |
---|
448 | strat->red = redHomog; |
---|
449 | if (pLexOrder && strat->honey) |
---|
450 | strat->initEcart = initEcartNormal; |
---|
451 | else |
---|
452 | strat->initEcart = initEcartBBA; |
---|
453 | if (strat->honey) |
---|
454 | strat->initEcartPair = initEcartPairMora; |
---|
455 | else |
---|
456 | strat->initEcartPair = initEcartPairBba; |
---|
457 | strat->kIdeal = NULL; |
---|
458 | //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD; |
---|
459 | //else strat->kIdeal->rtyp=MODUL_CMD; |
---|
460 | //strat->kIdeal->data=(void *)strat->Shdl; |
---|
461 | if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
462 | { |
---|
463 | //interred machen Aenderung |
---|
464 | pFDegOld=pFDeg; |
---|
465 | pLDegOld=pLDeg; |
---|
466 | h=ggetid("ecart"); |
---|
467 | if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD)) |
---|
468 | { |
---|
469 | ecartWeights=iv2array(IDINTVEC(h)); |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short)); |
---|
474 | /*uses automatic computation of the ecartWeights to set them*/ |
---|
475 | kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights); |
---|
476 | } |
---|
477 | pFDeg=totaldegreeWecart; |
---|
478 | pLDeg=maxdegreeWecart; |
---|
479 | for(i=1; i<=pVariables; i++) |
---|
480 | Print(" %d",ecartWeights[i]); |
---|
481 | PrintLn(); |
---|
482 | mflush(); |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | #ifdef KDEBUG |
---|
487 | static int bba_count = 0; |
---|
488 | #endif |
---|
489 | |
---|
490 | ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat) |
---|
491 | { |
---|
492 | #ifdef KDEBUG |
---|
493 | bba_count++; |
---|
494 | int loop_count = 0; |
---|
495 | #endif |
---|
496 | om_Opts.MinTrack = 5; |
---|
497 | int srmax,lrmax, red_result; |
---|
498 | int olddeg,reduc; |
---|
499 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
500 | #ifdef PROT_LENGTH |
---|
501 | int length; |
---|
502 | #endif |
---|
503 | |
---|
504 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
505 | initBuchMoraPos(strat); |
---|
506 | initHilbCrit(F,Q,&hilb,strat); |
---|
507 | initBba(F,strat); |
---|
508 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
509 | /*Shdl=*/initBuchMora(F, Q,strat); |
---|
510 | if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank); |
---|
511 | srmax = strat->sl; |
---|
512 | reduc = olddeg = lrmax = 0; |
---|
513 | |
---|
514 | if (!TEST_OPT_NOT_BUCKETS) |
---|
515 | strat->use_buckets = 1; |
---|
516 | |
---|
517 | kTest_TS(strat); |
---|
518 | |
---|
519 | #ifdef HAVE_TAIL_RING |
---|
520 | kStratInitChangeTailRing(strat); |
---|
521 | #endif |
---|
522 | |
---|
523 | /* compute------------------------------------------------------- */ |
---|
524 | while (strat->Ll >= 0) |
---|
525 | { |
---|
526 | if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/ |
---|
527 | #ifdef KDEBUG |
---|
528 | loop_count++; |
---|
529 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
530 | #endif |
---|
531 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
532 | if (TEST_OPT_DEGBOUND |
---|
533 | && ((strat->honey && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p)>Kstd1_deg)) |
---|
534 | || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p)>Kstd1_deg)))) |
---|
535 | { |
---|
536 | /* |
---|
537 | *stops computation if |
---|
538 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
539 | *a predefined number Kstd1_deg |
---|
540 | */ |
---|
541 | while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
542 | break; |
---|
543 | } |
---|
544 | /* picks the last element from the lazyset L */ |
---|
545 | strat->P = strat->L[strat->Ll]; |
---|
546 | strat->Ll--; |
---|
547 | |
---|
548 | if (pNext(strat->P.p) == strat->tail) |
---|
549 | { |
---|
550 | // deletes the short spoly |
---|
551 | pLmFree(strat->P.p); |
---|
552 | strat->P.p = NULL; |
---|
553 | poly m1 = NULL, m2 = NULL; |
---|
554 | |
---|
555 | // check that spoly creation is ok |
---|
556 | while (strat->tailRing != currRing && |
---|
557 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
558 | { |
---|
559 | assume(m1 == NULL && m2 == NULL); |
---|
560 | // if not, change to a ring where exponents are at least |
---|
561 | // large enough |
---|
562 | kStratChangeTailRing(strat); |
---|
563 | } |
---|
564 | // create the real one |
---|
565 | ksCreateSpoly(&(strat->P), strat->kNoether, strat->use_buckets, |
---|
566 | strat->tailRing, m1, m2, strat->R); |
---|
567 | } |
---|
568 | else if (strat->P.p1 == NULL) |
---|
569 | { |
---|
570 | if (strat->minim > 0) |
---|
571 | strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing); |
---|
572 | // for input polys, prepare reduction |
---|
573 | strat->P.PrepareRed(strat->use_buckets); |
---|
574 | } |
---|
575 | |
---|
576 | if (TEST_OPT_PROT) |
---|
577 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
578 | &olddeg,&reduc,strat); |
---|
579 | |
---|
580 | /* reduction of the element choosen from L */ |
---|
581 | red_result = strat->red(&strat->P,strat); |
---|
582 | |
---|
583 | // reduction to non-zero new poly |
---|
584 | if (red_result == 1) |
---|
585 | { |
---|
586 | /* statistic */ |
---|
587 | if (TEST_OPT_PROT) PrintS("s"); |
---|
588 | |
---|
589 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
590 | strat->P.GetP(strat->lmBin); |
---|
591 | |
---|
592 | int pos=posInS(strat->S,strat->sl,strat->P.p); |
---|
593 | |
---|
594 | // reduce the tail and normailze poly |
---|
595 | if (TEST_OPT_INTSTRATEGY) |
---|
596 | { |
---|
597 | strat->P.pCleardenom(); |
---|
598 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
599 | { |
---|
600 | strat->P.p = redtailBba(&(strat->P),pos-1,strat); |
---|
601 | strat->P.pCleardenom(); |
---|
602 | } |
---|
603 | } |
---|
604 | else |
---|
605 | { |
---|
606 | strat->P.pNorm(); |
---|
607 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
608 | strat->P.p = redtailBba(&(strat->P),pos-1,strat); |
---|
609 | } |
---|
610 | |
---|
611 | #ifdef KDEBUG |
---|
612 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
613 | #endif |
---|
614 | |
---|
615 | // min_std stuff |
---|
616 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
617 | { |
---|
618 | if (strat->minim==1) |
---|
619 | { |
---|
620 | strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing); |
---|
621 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
622 | } |
---|
623 | else |
---|
624 | { |
---|
625 | strat->M->m[minimcnt]=strat->P.p2; |
---|
626 | strat->P.p2=NULL; |
---|
627 | } |
---|
628 | if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL) |
---|
629 | pNext(strat->M->m[minimcnt]) |
---|
630 | = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]), |
---|
631 | strat->tailRing, currRing, |
---|
632 | currRing->PolyBin); |
---|
633 | minimcnt++; |
---|
634 | } |
---|
635 | |
---|
636 | // enter into S, L, and T |
---|
637 | #ifdef PROT_LENGTH |
---|
638 | if (TEST_OPT_PROT) |
---|
639 | { |
---|
640 | length += strat->P.GetpLength(); |
---|
641 | Print("[%d:%d]", strat->P.GetpLength(), length); |
---|
642 | } |
---|
643 | #endif |
---|
644 | enterT(strat->P, strat); |
---|
645 | enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
646 | // posInS only depends on the leading term |
---|
647 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
648 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
649 | // Print("[%d]",hilbeledeg); |
---|
650 | if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm); |
---|
651 | if (strat->sl>srmax) srmax = strat->sl; |
---|
652 | } |
---|
653 | else if (strat->P.p1 == NULL && strat->minim > 0) |
---|
654 | { |
---|
655 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
656 | } |
---|
657 | #ifdef KDEBUG |
---|
658 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
659 | #endif |
---|
660 | kTest_TS(strat); |
---|
661 | } |
---|
662 | #ifdef KDEBUG |
---|
663 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
664 | #endif |
---|
665 | /* complete reduction of the standard basis--------- */ |
---|
666 | if (TEST_OPT_REDSB) completeReduce(strat); |
---|
667 | /* release temp data-------------------------------- */ |
---|
668 | exitBuchMora(strat); |
---|
669 | if (TEST_OPT_WEIGHTM) |
---|
670 | { |
---|
671 | pFDeg=pFDegOld; |
---|
672 | pLDeg=pLDegOld; |
---|
673 | if (ecartWeights) |
---|
674 | { |
---|
675 | omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short)); |
---|
676 | ecartWeights=NULL; |
---|
677 | } |
---|
678 | } |
---|
679 | if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat); |
---|
680 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
681 | return (strat->Shdl); |
---|
682 | } |
---|
683 | |
---|
684 | poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce) |
---|
685 | { |
---|
686 | poly p; |
---|
687 | int i; |
---|
688 | |
---|
689 | if ((idIs0(F))&&(Q==NULL)) |
---|
690 | return pCopy(q); /*F=0*/ |
---|
691 | strat->ak = idRankFreeModule(F); |
---|
692 | /*- creating temp data structures------------------- -*/ |
---|
693 | BITSET save_test=test; |
---|
694 | test|=Sy_bit(OPT_REDTAIL); |
---|
695 | initBuchMoraCrit(strat); |
---|
696 | strat->initEcart = initEcartBBA; |
---|
697 | strat->enterS = enterSBba; |
---|
698 | /*- set S -*/ |
---|
699 | strat->sl = -1; |
---|
700 | /*- init local data struct.---------------------------------------- -*/ |
---|
701 | /*Shdl=*/initS(F,Q,strat); |
---|
702 | /*- compute------------------------------------------------------- -*/ |
---|
703 | if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0)) |
---|
704 | { |
---|
705 | for (i=strat->sl;i>=0;i--) |
---|
706 | pNorm(strat->S[i]); |
---|
707 | } |
---|
708 | kTest(strat); |
---|
709 | if (TEST_OPT_PROT) { PrintS("r"); mflush(); } |
---|
710 | p = redNF(pCopy(q),strat); |
---|
711 | if ((p!=NULL)&&(lazyReduce==0)) |
---|
712 | { |
---|
713 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
714 | p = redtailBba(p,strat->sl,strat); |
---|
715 | } |
---|
716 | /*- release temp data------------------------------- -*/ |
---|
717 | omfree(strat->sevS); |
---|
718 | omfree(strat->ecartS); |
---|
719 | omfree(strat->T); |
---|
720 | omfree(strat->sevT); |
---|
721 | omfree(strat->R); |
---|
722 | omfree(strat->S_2_R); |
---|
723 | omfree(strat->L); |
---|
724 | omfree(strat->B); |
---|
725 | omfree(strat->fromQ); |
---|
726 | idDelete(&strat->Shdl); |
---|
727 | test=save_test; |
---|
728 | if (TEST_OPT_PROT) PrintLn(); |
---|
729 | return p; |
---|
730 | } |
---|
731 | |
---|
732 | ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce) |
---|
733 | { |
---|
734 | poly p; |
---|
735 | int i; |
---|
736 | ideal res; |
---|
737 | |
---|
738 | if (idIs0(q)) |
---|
739 | return idInit(1,q->rank); |
---|
740 | if ((idIs0(F))&&(Q==NULL)) |
---|
741 | return idCopy(q); /*F=0*/ |
---|
742 | strat->ak = idRankFreeModule(F); |
---|
743 | /*- creating temp data structures------------------- -*/ |
---|
744 | BITSET save_test=test; |
---|
745 | test|=Sy_bit(OPT_REDTAIL); |
---|
746 | initBuchMoraCrit(strat); |
---|
747 | strat->initEcart = initEcartBBA; |
---|
748 | strat->enterS = enterSBba; |
---|
749 | /*- set S -*/ |
---|
750 | strat->sl = -1; |
---|
751 | /*- init local data struct.---------------------------------------- -*/ |
---|
752 | /*Shdl=*/initS(F,Q,strat); |
---|
753 | /*- compute------------------------------------------------------- -*/ |
---|
754 | res=idInit(IDELEMS(q),q->rank); |
---|
755 | if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0)) |
---|
756 | { |
---|
757 | for (i=strat->sl;i>=0;i--) |
---|
758 | pNorm(strat->S[i]); |
---|
759 | } |
---|
760 | for (i=IDELEMS(q)-1; i>=0; i--) |
---|
761 | { |
---|
762 | if (q->m[i]!=NULL) |
---|
763 | { |
---|
764 | if (TEST_OPT_PROT) { PrintS("r");mflush(); } |
---|
765 | p = redNF(pCopy(q->m[i]),strat); |
---|
766 | if ((p!=NULL)&&(lazyReduce==0)) |
---|
767 | { |
---|
768 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
769 | p = redtailBba(p,strat->sl,strat); |
---|
770 | } |
---|
771 | res->m[i]=p; |
---|
772 | } |
---|
773 | //else |
---|
774 | // res->m[i]=NULL; |
---|
775 | } |
---|
776 | /*- release temp data------------------------------- -*/ |
---|
777 | omfree(strat->sevS); |
---|
778 | omfree(strat->ecartS); |
---|
779 | omfree(strat->T); |
---|
780 | omfree(strat->sevT); |
---|
781 | omfree(strat->R); |
---|
782 | omfree(strat->S_2_R); |
---|
783 | omfree(strat->L); |
---|
784 | omfree(strat->B); |
---|
785 | omfree(strat->fromQ); |
---|
786 | idDelete(&strat->Shdl); |
---|
787 | test=save_test; |
---|
788 | if (TEST_OPT_PROT) PrintLn(); |
---|
789 | return res; |
---|
790 | } |
---|
791 | |
---|
792 | static ideal bbared (ideal F, ideal Q,kStrategy strat) |
---|
793 | { |
---|
794 | |
---|
795 | /* complete reduction of the standard basis--------- */ |
---|
796 | completeReduce(strat); |
---|
797 | /* release temp data-------------------------------- */ |
---|
798 | exitBuchMora(strat); |
---|
799 | if (TEST_OPT_WEIGHTM) |
---|
800 | { |
---|
801 | pFDeg=pFDegOld; |
---|
802 | pLDeg=pLDegOld; |
---|
803 | if (ecartWeights) |
---|
804 | { |
---|
805 | omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short)); |
---|
806 | ecartWeights=NULL; |
---|
807 | } |
---|
808 | } |
---|
809 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
810 | return (strat->Shdl); |
---|
811 | } |
---|
812 | |
---|
813 | ideal stdred(ideal F, ideal Q, tHomog h,intvec ** w) |
---|
814 | { |
---|
815 | ideal r; |
---|
816 | BOOLEAN b=pLexOrder,toReset=FALSE; |
---|
817 | BOOLEAN delete_w=(w==NULL); |
---|
818 | kStrategy strat=new skStrategy; |
---|
819 | |
---|
820 | if (rField_has_simple_inverse()) |
---|
821 | strat->LazyPass=20; |
---|
822 | else |
---|
823 | strat->LazyPass=2; |
---|
824 | strat->LazyDegree = 1; |
---|
825 | strat->ak = idRankFreeModule(F); |
---|
826 | if ((h==testHomog)) |
---|
827 | { |
---|
828 | if (strat->ak==0) |
---|
829 | { |
---|
830 | h = (tHomog)idHomIdeal(F,Q); |
---|
831 | w=NULL; |
---|
832 | } |
---|
833 | else |
---|
834 | h = (tHomog)idHomModule(F,Q,w); |
---|
835 | } |
---|
836 | if (h==isHomog) |
---|
837 | { |
---|
838 | if ((w!=NULL) && (*w!=NULL)) |
---|
839 | { |
---|
840 | kModW = *w; |
---|
841 | strat->kModW = *w; |
---|
842 | pOldFDeg = pFDeg; |
---|
843 | pFDeg = kModDeg; |
---|
844 | toReset = TRUE; |
---|
845 | } |
---|
846 | pLexOrder = TRUE; |
---|
847 | strat->LazyPass*=2; |
---|
848 | } |
---|
849 | strat->homog=h; |
---|
850 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
851 | initBuchMoraPos(strat); |
---|
852 | if (pOrdSgn==1) |
---|
853 | initBba(F,strat); |
---|
854 | else |
---|
855 | initMora(F,strat); |
---|
856 | initBuchMora(F, Q,strat); |
---|
857 | //initS(F,Q,strat); |
---|
858 | // Ende der Initalisierung |
---|
859 | r=bbared(F,Q,strat); |
---|
860 | #ifdef KDEBUG |
---|
861 | int i; |
---|
862 | for (i=0; i<IDELEMS(r); i++) pTest(r->m[i]); |
---|
863 | #endif |
---|
864 | // Ende: aufraeumen |
---|
865 | if (toReset) |
---|
866 | { |
---|
867 | kModW = NULL; |
---|
868 | pFDeg = pOldFDeg; |
---|
869 | } |
---|
870 | pLexOrder = b; |
---|
871 | delete(strat); |
---|
872 | if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w; |
---|
873 | idSkipZeroes(r); |
---|
874 | return r; |
---|
875 | } |
---|