1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT: |
---|
6 | */ |
---|
7 | |
---|
8 | // TODO: why the following is here instead of mod2.h??? |
---|
9 | |
---|
10 | |
---|
11 | // define if buckets should be used |
---|
12 | #define MORA_USE_BUCKETS |
---|
13 | |
---|
14 | #define MYTEST 0 |
---|
15 | |
---|
16 | #define ADIDEBUG 0 |
---|
17 | #define ADIDEBUG_NF 0 |
---|
18 | |
---|
19 | #include <kernel/mod2.h> |
---|
20 | |
---|
21 | #include <omalloc/omalloc.h> |
---|
22 | |
---|
23 | #include <misc/options.h> |
---|
24 | #include <misc/intvec.h> |
---|
25 | |
---|
26 | #if MYTEST |
---|
27 | #ifdef HAVE_TAIL_RING |
---|
28 | #undef HAVE_TAIL_RING |
---|
29 | #endif /* ifdef HAVE_TAIL_RING */ |
---|
30 | #endif /* if MYTEST */ |
---|
31 | |
---|
32 | #include <polys/weight.h> |
---|
33 | #include <kernel/polys.h> |
---|
34 | |
---|
35 | #include <kernel/GBEngine/kutil.h> |
---|
36 | #include <kernel/GBEngine/kstd1.h> |
---|
37 | #include <kernel/GBEngine/khstd.h> |
---|
38 | #include <kernel/combinatorics/stairc.h> |
---|
39 | //#include "cntrlc.h" |
---|
40 | #include <kernel/ideals.h> |
---|
41 | //#include "../Singular/ipid.h" |
---|
42 | |
---|
43 | //#include "ipprint.h" |
---|
44 | |
---|
45 | #ifdef HAVE_PLURAL |
---|
46 | #include <polys/nc/nc.h> |
---|
47 | #include <polys/nc/sca.h> |
---|
48 | #include <kernel/GBEngine/nc.h> |
---|
49 | #endif |
---|
50 | |
---|
51 | #include <kernel/GBEngine/kInline.h> |
---|
52 | |
---|
53 | |
---|
54 | /* the list of all options which give a warning by test */ |
---|
55 | BITSET kOptions=Sy_bit(OPT_PROT) /* 0 */ |
---|
56 | |Sy_bit(OPT_REDSB) /* 1 */ |
---|
57 | |Sy_bit(OPT_NOT_SUGAR) /* 3 */ |
---|
58 | |Sy_bit(OPT_INTERRUPT) /* 4 */ |
---|
59 | |Sy_bit(OPT_SUGARCRIT) /* 5 */ |
---|
60 | |Sy_bit(OPT_REDTHROUGH) |
---|
61 | |Sy_bit(OPT_OLDSTD) |
---|
62 | |Sy_bit(OPT_FASTHC) /* 10 */ |
---|
63 | |Sy_bit(OPT_INTSTRATEGY) /* 26 */ |
---|
64 | |Sy_bit(OPT_INFREDTAIL) /* 28 */ |
---|
65 | |Sy_bit(OPT_NOTREGULARITY) /* 30 */ |
---|
66 | |Sy_bit(OPT_WEIGHTM); /* 31 */ |
---|
67 | |
---|
68 | /* the list of all options which may be used by option and test */ |
---|
69 | /* defintion of ALL options: libpolys/misc/options.h */ |
---|
70 | BITSET validOpts=Sy_bit(0) |
---|
71 | |Sy_bit(1) |
---|
72 | |Sy_bit(2) // obachman 10/00: replaced by notBucket |
---|
73 | |Sy_bit(3) |
---|
74 | |Sy_bit(4) |
---|
75 | |Sy_bit(5) |
---|
76 | |Sy_bit(6) |
---|
77 | // |Sy_bit(7) obachman 11/00 tossed: 12/00 used for redThrough |
---|
78 | |Sy_bit(7) // OPT_REDTHROUGH |
---|
79 | |Sy_bit(8) // obachman 11/00 tossed -> motsak 2011 experimental: OPT_NO_SYZ_MINIM |
---|
80 | |Sy_bit(9) |
---|
81 | |Sy_bit(10) |
---|
82 | |Sy_bit(11) |
---|
83 | |Sy_bit(12) |
---|
84 | |Sy_bit(13) |
---|
85 | |Sy_bit(14) |
---|
86 | |Sy_bit(15) |
---|
87 | |Sy_bit(16) |
---|
88 | |Sy_bit(17) |
---|
89 | |Sy_bit(18) |
---|
90 | |Sy_bit(19) |
---|
91 | // |Sy_bit(20) obachman 11/00 tossed: 12/00 used for redOldStd |
---|
92 | |Sy_bit(OPT_OLDSTD) |
---|
93 | |Sy_bit(21) |
---|
94 | |Sy_bit(22) |
---|
95 | /*|Sy_bit(23)*/ |
---|
96 | /*|Sy_bit(24)*/ |
---|
97 | |Sy_bit(OPT_REDTAIL) |
---|
98 | |Sy_bit(OPT_INTSTRATEGY) |
---|
99 | |Sy_bit(27) |
---|
100 | |Sy_bit(28) |
---|
101 | |Sy_bit(29) |
---|
102 | |Sy_bit(30) |
---|
103 | |Sy_bit(31); |
---|
104 | |
---|
105 | //static BOOLEAN posInLOldFlag; |
---|
106 | /*FALSE, if posInL == posInL10*/ |
---|
107 | // returns TRUE if mora should use buckets, false otherwise |
---|
108 | static BOOLEAN kMoraUseBucket(kStrategy strat); |
---|
109 | |
---|
110 | static void kOptimizeLDeg(pLDegProc ldeg, kStrategy strat) |
---|
111 | { |
---|
112 | // if (strat->ak == 0 && !rIsSyzIndexRing(currRing)) |
---|
113 | strat->length_pLength = TRUE; |
---|
114 | // else |
---|
115 | // strat->length_pLength = FALSE; |
---|
116 | |
---|
117 | if ((ldeg == pLDeg0c /*&& !rIsSyzIndexRing(currRing)*/) || |
---|
118 | (ldeg == pLDeg0 && strat->ak == 0)) |
---|
119 | { |
---|
120 | strat->LDegLast = TRUE; |
---|
121 | } |
---|
122 | else |
---|
123 | { |
---|
124 | strat->LDegLast = FALSE; |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | |
---|
129 | static int doRed (LObject* h, TObject* with,BOOLEAN intoT,kStrategy strat) |
---|
130 | { |
---|
131 | int ret; |
---|
132 | #if KDEBUG > 0 |
---|
133 | kTest_L(h); |
---|
134 | kTest_T(with); |
---|
135 | #endif |
---|
136 | // Hmmm ... why do we do this -- polys from T should already be normalized |
---|
137 | if (!TEST_OPT_INTSTRATEGY) |
---|
138 | with->pNorm(); |
---|
139 | #ifdef KDEBUG |
---|
140 | if (TEST_OPT_DEBUG) |
---|
141 | { |
---|
142 | PrintS("reduce ");h->wrp();PrintS(" with ");with->wrp();PrintLn(); |
---|
143 | } |
---|
144 | #endif |
---|
145 | if (intoT) |
---|
146 | { |
---|
147 | // need to do it exacly like this: otherwise |
---|
148 | // we might get errors |
---|
149 | LObject L= *h; |
---|
150 | L.Copy(); |
---|
151 | h->GetP(); |
---|
152 | h->length=h->pLength=pLength(h->p); |
---|
153 | ret = ksReducePoly(&L, with, strat->kNoetherTail(), NULL, strat); |
---|
154 | if (ret) |
---|
155 | { |
---|
156 | if (ret < 0) return ret; |
---|
157 | if (h->tailRing != strat->tailRing) |
---|
158 | h->ShallowCopyDelete(strat->tailRing, |
---|
159 | pGetShallowCopyDeleteProc(h->tailRing, |
---|
160 | strat->tailRing)); |
---|
161 | } |
---|
162 | enterT(*h,strat); |
---|
163 | *h = L; |
---|
164 | } |
---|
165 | else |
---|
166 | ret = ksReducePoly(h, with, strat->kNoetherTail(), NULL, strat); |
---|
167 | #ifdef KDEBUG |
---|
168 | if (TEST_OPT_DEBUG) |
---|
169 | { |
---|
170 | PrintS("to ");h->wrp();PrintLn(); |
---|
171 | } |
---|
172 | #endif |
---|
173 | return ret; |
---|
174 | } |
---|
175 | |
---|
176 | int redEcart (LObject* h,kStrategy strat) |
---|
177 | { |
---|
178 | int i,at,ei,li,ii; |
---|
179 | int j = 0; |
---|
180 | int pass = 0; |
---|
181 | long d,reddeg; |
---|
182 | |
---|
183 | d = h->GetpFDeg()+ h->ecart; |
---|
184 | reddeg = strat->LazyDegree+d; |
---|
185 | h->SetShortExpVector(); |
---|
186 | loop |
---|
187 | { |
---|
188 | j = kFindDivisibleByInT(strat, h); |
---|
189 | if (j < 0) |
---|
190 | { |
---|
191 | if (strat->honey) h->SetLength(strat->length_pLength); |
---|
192 | return 1; |
---|
193 | } |
---|
194 | |
---|
195 | ei = strat->T[j].ecart; |
---|
196 | ii = j; |
---|
197 | |
---|
198 | if (ei > h->ecart && ii < strat->tl) |
---|
199 | { |
---|
200 | li = strat->T[j].length; |
---|
201 | // the polynomial to reduce with (up to the moment) is; |
---|
202 | // pi with ecart ei and length li |
---|
203 | // look for one with smaller ecart |
---|
204 | i = j; |
---|
205 | loop |
---|
206 | { |
---|
207 | /*- takes the first possible with respect to ecart -*/ |
---|
208 | i++; |
---|
209 | #if 1 |
---|
210 | if (i > strat->tl) break; |
---|
211 | if ((strat->T[i].ecart < ei || (strat->T[i].ecart == ei && |
---|
212 | strat->T[i].length < li)) |
---|
213 | && |
---|
214 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], h->GetLmTailRing(), ~h->sev, strat->tailRing)) |
---|
215 | #else |
---|
216 | j = kFindDivisibleByInT(strat, h, i); |
---|
217 | if (j < 0) break; |
---|
218 | i = j; |
---|
219 | if (strat->T[i].ecart < ei || (strat->T[i].ecart == ei && |
---|
220 | strat->T[i].length < li)) |
---|
221 | #endif |
---|
222 | { |
---|
223 | // the polynomial to reduce with is now |
---|
224 | ii = i; |
---|
225 | ei = strat->T[i].ecart; |
---|
226 | if (ei <= h->ecart) break; |
---|
227 | li = strat->T[i].length; |
---|
228 | } |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | // end of search: have to reduce with pi |
---|
233 | if (ei > h->ecart) |
---|
234 | { |
---|
235 | // It is not possible to reduce h with smaller ecart; |
---|
236 | // if possible h goes to the lazy-set L,i.e |
---|
237 | // if its position in L would be not the last one |
---|
238 | strat->fromT = TRUE; |
---|
239 | if (!TEST_OPT_REDTHROUGH && strat->Ll >= 0) /*- L is not empty -*/ |
---|
240 | { |
---|
241 | h->SetLmCurrRing(); |
---|
242 | if (strat->honey && strat->posInLDependsOnLength) |
---|
243 | h->SetLength(strat->length_pLength); |
---|
244 | assume(h->FDeg == h->pFDeg()); |
---|
245 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
246 | if (at <= strat->Ll) |
---|
247 | { |
---|
248 | /*- h will not become the next element to reduce -*/ |
---|
249 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
250 | #ifdef KDEBUG |
---|
251 | if (TEST_OPT_DEBUG) Print(" ecart too big; -> L%d\n",at); |
---|
252 | #endif |
---|
253 | h->Clear(); |
---|
254 | strat->fromT = FALSE; |
---|
255 | return -1; |
---|
256 | } |
---|
257 | } |
---|
258 | } |
---|
259 | |
---|
260 | // now we finally can reduce |
---|
261 | doRed(h,&(strat->T[ii]),strat->fromT,strat); |
---|
262 | strat->fromT=FALSE; |
---|
263 | |
---|
264 | // are we done ??? |
---|
265 | if (h->IsNull()) |
---|
266 | { |
---|
267 | assume(!rField_is_Ring(currRing)); |
---|
268 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
269 | h->Clear(); |
---|
270 | return 0; |
---|
271 | } |
---|
272 | |
---|
273 | // NO! |
---|
274 | h->SetShortExpVector(); |
---|
275 | h->SetpFDeg(); |
---|
276 | if (strat->honey) |
---|
277 | { |
---|
278 | if (ei <= h->ecart) |
---|
279 | h->ecart = d-h->GetpFDeg(); |
---|
280 | else |
---|
281 | h->ecart = d-h->GetpFDeg()+ei-h->ecart; |
---|
282 | } |
---|
283 | else |
---|
284 | // this has the side effect of setting h->length |
---|
285 | h->ecart = h->pLDeg(strat->LDegLast) - h->GetpFDeg(); |
---|
286 | #if 0 |
---|
287 | if (strat->syzComp!=0) |
---|
288 | { |
---|
289 | if ((strat->syzComp>0) && (h->Comp() > strat->syzComp)) |
---|
290 | { |
---|
291 | assume(h->MinComp() > strat->syzComp); |
---|
292 | if (strat->honey) h->SetLength(); |
---|
293 | #ifdef KDEBUG |
---|
294 | if (TEST_OPT_DEBUG) PrintS(" > syzComp\n"); |
---|
295 | #endif |
---|
296 | return -2; |
---|
297 | } |
---|
298 | } |
---|
299 | #endif |
---|
300 | /*- try to reduce the s-polynomial -*/ |
---|
301 | pass++; |
---|
302 | d = h->GetpFDeg()+h->ecart; |
---|
303 | /* |
---|
304 | *test whether the polynomial should go to the lazyset L |
---|
305 | *-if the degree jumps |
---|
306 | *-if the number of pre-defined reductions jumps |
---|
307 | */ |
---|
308 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) |
---|
309 | && ((d >= reddeg) || (pass > strat->LazyPass))) |
---|
310 | { |
---|
311 | h->SetLmCurrRing(); |
---|
312 | if (strat->honey && strat->posInLDependsOnLength) |
---|
313 | h->SetLength(strat->length_pLength); |
---|
314 | assume(h->FDeg == h->pFDeg()); |
---|
315 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
316 | if (at <= strat->Ll) |
---|
317 | { |
---|
318 | int dummy=strat->sl; |
---|
319 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
320 | { |
---|
321 | if (strat->honey && !strat->posInLDependsOnLength) |
---|
322 | h->SetLength(strat->length_pLength); |
---|
323 | return 1; |
---|
324 | } |
---|
325 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
326 | #ifdef KDEBUG |
---|
327 | if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at); |
---|
328 | #endif |
---|
329 | h->Clear(); |
---|
330 | return -1; |
---|
331 | } |
---|
332 | } |
---|
333 | else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg)) |
---|
334 | { |
---|
335 | Print(".%ld",d);mflush(); |
---|
336 | reddeg = d+1; |
---|
337 | if (h->pTotalDeg()+h->ecart >= (int)strat->tailRing->bitmask) |
---|
338 | { |
---|
339 | strat->overflow=TRUE; |
---|
340 | //Print("OVERFLOW in redEcart d=%ld, max=%ld",d,strat->tailRing->bitmask); |
---|
341 | h->GetP(); |
---|
342 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
343 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
344 | h->Clear(); |
---|
345 | return -1; |
---|
346 | } |
---|
347 | } |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | int redRiloc (LObject* h,kStrategy strat) |
---|
352 | { |
---|
353 | int i,at,ei,li,ii; |
---|
354 | int j = 0; |
---|
355 | int pass = 0; |
---|
356 | long d,reddeg; |
---|
357 | |
---|
358 | |
---|
359 | #if ADIDEBUG_NF |
---|
360 | int iii; |
---|
361 | PrintLn(); |
---|
362 | PrintS("---------------------------- NEW REDRILOC COMPUTATION ----------------------------"); |
---|
363 | PrintLn(); |
---|
364 | PrintS(" The pair h : "); PrintLn(); PrintLn(); |
---|
365 | PrintS(" p1 = "); p_Write(h->p1,strat->tailRing); PrintLn(); |
---|
366 | PrintS(" p2 = "); p_Write(h->p2,strat->tailRing); PrintLn(); |
---|
367 | PrintS(" p = "); p_Write(h->p,strat->tailRing); PrintLn(); |
---|
368 | PrintLn(); |
---|
369 | PrintS(" The actual reducer T is: "); |
---|
370 | if(strat->tl<0) |
---|
371 | {PrintS(" Empty.\n");} |
---|
372 | else |
---|
373 | { |
---|
374 | for (iii=0;iii<=strat->tl;iii++) |
---|
375 | { |
---|
376 | PrintLn(); |
---|
377 | Print(" T[%i] = ",iii);p_Write(strat->T[iii].p,strat->tailRing); |
---|
378 | PrintLn(); |
---|
379 | } |
---|
380 | } |
---|
381 | #endif /* ADIDEBUG_NF */ |
---|
382 | |
---|
383 | d = h->GetpFDeg()+ h->ecart; |
---|
384 | reddeg = strat->LazyDegree+d; |
---|
385 | h->SetShortExpVector(); |
---|
386 | #if ADIDEBUG_NF |
---|
387 | Print("\n Searching for a poly in T that divides h (of ecart %i) ...\n",h->ecart); |
---|
388 | #endif |
---|
389 | loop |
---|
390 | { |
---|
391 | j = kFindDivisibleByInT(strat, h); |
---|
392 | #if ADIDEBUG_NF |
---|
393 | if(j != -1) |
---|
394 | { |
---|
395 | ei = strat->T[j].ecart; |
---|
396 | Print("\n Found one: T[%i] of ecart %i: ",j,ei); |
---|
397 | p_Write(strat->T[j].p,strat->tailRing); |
---|
398 | PrintS("\n Try to find another with smaller ecart:\n"); |
---|
399 | } |
---|
400 | else |
---|
401 | { |
---|
402 | PrintS("\n No poly in T divides h.\n"); |
---|
403 | } |
---|
404 | #endif |
---|
405 | if (j < 0) |
---|
406 | { |
---|
407 | if (strat->honey) h->SetLength(strat->length_pLength); |
---|
408 | // over ZZ: cleanup coefficients by complete reduction with monomials |
---|
409 | postReduceByMon(h, strat); |
---|
410 | if(nIsZero(pGetCoeff(h->p)) || h->p == NULL) return 2; |
---|
411 | if(strat->tl >= 0) |
---|
412 | h->i_r1 = strat->tl; |
---|
413 | else |
---|
414 | h->i_r1 = -1; |
---|
415 | if (h->GetLmTailRing() == NULL) |
---|
416 | { |
---|
417 | if (h->lcm!=NULL) pLmDelete(h->lcm); |
---|
418 | h->Clear(); |
---|
419 | return 0; |
---|
420 | } |
---|
421 | return 1; |
---|
422 | } |
---|
423 | |
---|
424 | ei = strat->T[j].ecart; |
---|
425 | ii = j; |
---|
426 | #if ADIDEBUG_NF |
---|
427 | iii=ii; |
---|
428 | #endif |
---|
429 | if (ei > h->ecart && ii < strat->tl) |
---|
430 | { |
---|
431 | li = strat->T[j].length; |
---|
432 | // the polynomial to reduce with (up to the moment) is; |
---|
433 | // pi with ecart ei and length li |
---|
434 | // look for one with smaller ecart |
---|
435 | i = j; |
---|
436 | loop |
---|
437 | { |
---|
438 | /*- takes the first possible with respect to ecart -*/ |
---|
439 | i++; |
---|
440 | #if 1 |
---|
441 | if (i > strat->tl) break; |
---|
442 | if ((strat->T[i].ecart < ei || (strat->T[i].ecart == ei && |
---|
443 | strat->T[i].length < li)) |
---|
444 | && |
---|
445 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], h->GetLmTailRing(), ~h->sev, strat->tailRing) && n_DivBy(h->p->coef,strat->T[i].p->coef,strat->tailRing)) |
---|
446 | #else |
---|
447 | j = kFindDivisibleByInT(strat, h, i); |
---|
448 | if (j < 0) break; |
---|
449 | i = j; |
---|
450 | if (strat->T[i].ecart < ei || (strat->T[i].ecart == ei && |
---|
451 | strat->T[i].length < li)) |
---|
452 | #endif |
---|
453 | { |
---|
454 | // the polynomial to reduce with is now |
---|
455 | ii = i; |
---|
456 | ei = strat->T[i].ecart; |
---|
457 | if (ei <= h->ecart) break; |
---|
458 | li = strat->T[i].length; |
---|
459 | } |
---|
460 | } |
---|
461 | |
---|
462 | #if ADIDEBUG_NF |
---|
463 | if(iii == ii) |
---|
464 | { |
---|
465 | PrintS("\n None was found.\n"); |
---|
466 | } |
---|
467 | else |
---|
468 | { |
---|
469 | Print("\n A better one (ecart = %i): T[%i] = ",ei,ii); |
---|
470 | p_Write(strat->T[ii].p,strat->tailRing); |
---|
471 | PrintLn(); |
---|
472 | } |
---|
473 | #endif |
---|
474 | } |
---|
475 | |
---|
476 | // end of search: have to reduce with pi |
---|
477 | if (ei > h->ecart) |
---|
478 | { |
---|
479 | // It is not possible to reduce h with smaller ecart; |
---|
480 | // if possible h goes to the lazy-set L,i.e |
---|
481 | // if its position in L would be not the last one |
---|
482 | strat->fromT = TRUE; |
---|
483 | if (!TEST_OPT_REDTHROUGH && strat->Ll >= 0) /*- L is not empty -*/ |
---|
484 | { |
---|
485 | h->SetLmCurrRing(); |
---|
486 | if (strat->honey && strat->posInLDependsOnLength) |
---|
487 | h->SetLength(strat->length_pLength); |
---|
488 | assume(h->FDeg == h->pFDeg()); |
---|
489 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
490 | if (at <= strat->Ll && pLmCmp(h->p, strat->L[strat->Ll].p) != 0 && !nEqual(h->p->coef, strat->L[strat->Ll].p->coef)) |
---|
491 | { |
---|
492 | /*- h will not become the next element to reduce -*/ |
---|
493 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
494 | #ifdef KDEBUG |
---|
495 | if (TEST_OPT_DEBUG) Print(" ecart too big; -> L%d\n",at); |
---|
496 | #endif |
---|
497 | h->Clear(); |
---|
498 | strat->fromT = FALSE; |
---|
499 | return -1; |
---|
500 | } |
---|
501 | } |
---|
502 | } |
---|
503 | |
---|
504 | // now we finally can reduce |
---|
505 | doRed(h,&(strat->T[ii]),strat->fromT,strat); |
---|
506 | #if ADIDEBUG_NF |
---|
507 | PrintS("\n Partial Reduced h = ");p_Write(h->p,strat->tailRing); |
---|
508 | PrintLn(); |
---|
509 | #endif |
---|
510 | strat->fromT=FALSE; |
---|
511 | |
---|
512 | // are we done ??? |
---|
513 | if (h->IsNull()) |
---|
514 | { |
---|
515 | if (h->lcm!=NULL) pLmDelete(h->lcm); |
---|
516 | h->Clear(); |
---|
517 | return 0; |
---|
518 | } |
---|
519 | |
---|
520 | // NO! |
---|
521 | h->SetShortExpVector(); |
---|
522 | h->SetpFDeg(); |
---|
523 | if (strat->honey) |
---|
524 | { |
---|
525 | if (ei <= h->ecart) |
---|
526 | h->ecart = d-h->GetpFDeg(); |
---|
527 | else |
---|
528 | h->ecart = d-h->GetpFDeg()+ei-h->ecart; |
---|
529 | } |
---|
530 | else |
---|
531 | // this has the side effect of setting h->length |
---|
532 | h->ecart = h->pLDeg(strat->LDegLast) - h->GetpFDeg(); |
---|
533 | |
---|
534 | /*- try to reduce the s-polynomial -*/ |
---|
535 | pass++; |
---|
536 | d = h->GetpFDeg()+h->ecart; |
---|
537 | /* |
---|
538 | *test whether the polynomial should go to the lazyset L |
---|
539 | *-if the degree jumps |
---|
540 | *-if the number of pre-defined reductions jumps |
---|
541 | */ |
---|
542 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) |
---|
543 | && ((d >= reddeg) || (pass > strat->LazyPass))) |
---|
544 | { |
---|
545 | h->SetLmCurrRing(); |
---|
546 | if (strat->honey && strat->posInLDependsOnLength) |
---|
547 | h->SetLength(strat->length_pLength); |
---|
548 | assume(h->FDeg == h->pFDeg()); |
---|
549 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
550 | if (at <= strat->Ll) |
---|
551 | { |
---|
552 | int dummy=strat->sl; |
---|
553 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
554 | { |
---|
555 | if (strat->honey && !strat->posInLDependsOnLength) |
---|
556 | h->SetLength(strat->length_pLength); |
---|
557 | return 1; |
---|
558 | } |
---|
559 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
560 | #ifdef KDEBUG |
---|
561 | if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at); |
---|
562 | #endif |
---|
563 | h->Clear(); |
---|
564 | return -1; |
---|
565 | } |
---|
566 | } |
---|
567 | else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg)) |
---|
568 | { |
---|
569 | Print(".%ld",d);mflush(); |
---|
570 | reddeg = d+1; |
---|
571 | if (h->pTotalDeg()+h->ecart >= (int)strat->tailRing->bitmask) |
---|
572 | { |
---|
573 | strat->overflow=TRUE; |
---|
574 | //Print("OVERFLOW in redEcart d=%ld, max=%ld",d,strat->tailRing->bitmask); |
---|
575 | h->GetP(); |
---|
576 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
577 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
578 | h->Clear(); |
---|
579 | return -1; |
---|
580 | } |
---|
581 | } |
---|
582 | } |
---|
583 | } |
---|
584 | |
---|
585 | /*2 |
---|
586 | *reduces h with elements from T choosing the first possible |
---|
587 | * element in t with respect to the given pDivisibleBy |
---|
588 | */ |
---|
589 | int redFirst (LObject* h,kStrategy strat) |
---|
590 | { |
---|
591 | if (h->IsNull()) return 0; |
---|
592 | |
---|
593 | int at; |
---|
594 | long reddeg,d; |
---|
595 | int pass = 0; |
---|
596 | int j = 0; |
---|
597 | |
---|
598 | if (! strat->homog) |
---|
599 | { |
---|
600 | d = h->GetpFDeg() + h->ecart; |
---|
601 | reddeg = strat->LazyDegree+d; |
---|
602 | } |
---|
603 | h->SetShortExpVector(); |
---|
604 | loop |
---|
605 | { |
---|
606 | j = kFindDivisibleByInT(strat, h); |
---|
607 | if (j < 0) |
---|
608 | { |
---|
609 | h->SetDegStuffReturnLDeg(strat->LDegLast); |
---|
610 | return 1; |
---|
611 | } |
---|
612 | |
---|
613 | if (!TEST_OPT_INTSTRATEGY) |
---|
614 | strat->T[j].pNorm(); |
---|
615 | #ifdef KDEBUG |
---|
616 | if (TEST_OPT_DEBUG) |
---|
617 | { |
---|
618 | PrintS("reduce "); |
---|
619 | h->wrp(); |
---|
620 | PrintS(" with "); |
---|
621 | strat->T[j].wrp(); |
---|
622 | } |
---|
623 | #endif |
---|
624 | ksReducePoly(h, &(strat->T[j]), strat->kNoetherTail(), NULL, strat); |
---|
625 | #ifdef KDEBUG |
---|
626 | if (TEST_OPT_DEBUG) |
---|
627 | { |
---|
628 | PrintS(" to "); |
---|
629 | wrp(h->p); |
---|
630 | PrintLn(); |
---|
631 | } |
---|
632 | #endif |
---|
633 | if (h->IsNull()) |
---|
634 | { |
---|
635 | assume(!rField_is_Ring(currRing)); |
---|
636 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
637 | h->Clear(); |
---|
638 | return 0; |
---|
639 | } |
---|
640 | h->SetShortExpVector(); |
---|
641 | |
---|
642 | #if 0 |
---|
643 | if ((strat->syzComp!=0) && !strat->honey) |
---|
644 | { |
---|
645 | if ((strat->syzComp>0) && |
---|
646 | (h->Comp() > strat->syzComp)) |
---|
647 | { |
---|
648 | assume(h->MinComp() > strat->syzComp); |
---|
649 | #ifdef KDEBUG |
---|
650 | if (TEST_OPT_DEBUG) PrintS(" > syzComp\n"); |
---|
651 | #endif |
---|
652 | if (strat->homog) |
---|
653 | h->SetDegStuffReturnLDeg(strat->LDegLast); |
---|
654 | return -2; |
---|
655 | } |
---|
656 | } |
---|
657 | #endif |
---|
658 | if (!strat->homog) |
---|
659 | { |
---|
660 | if (!TEST_OPT_OLDSTD && strat->honey) |
---|
661 | { |
---|
662 | h->SetpFDeg(); |
---|
663 | if (strat->T[j].ecart <= h->ecart) |
---|
664 | h->ecart = d - h->GetpFDeg(); |
---|
665 | else |
---|
666 | h->ecart = d - h->GetpFDeg() + strat->T[j].ecart - h->ecart; |
---|
667 | |
---|
668 | d = h->GetpFDeg() + h->ecart; |
---|
669 | } |
---|
670 | else |
---|
671 | d = h->SetDegStuffReturnLDeg(strat->LDegLast); |
---|
672 | /*- try to reduce the s-polynomial -*/ |
---|
673 | pass++; |
---|
674 | /* |
---|
675 | *test whether the polynomial should go to the lazyset L |
---|
676 | *-if the degree jumps |
---|
677 | *-if the number of pre-defined reductions jumps |
---|
678 | */ |
---|
679 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) |
---|
680 | && ((d >= reddeg) || (pass > strat->LazyPass))) |
---|
681 | { |
---|
682 | h->SetLmCurrRing(); |
---|
683 | if (strat->posInLDependsOnLength) |
---|
684 | h->SetLength(strat->length_pLength); |
---|
685 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
686 | if (at <= strat->Ll) |
---|
687 | { |
---|
688 | int dummy=strat->sl; |
---|
689 | if (kFindDivisibleByInS(strat,&dummy, h) < 0) |
---|
690 | return 1; |
---|
691 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
692 | #ifdef KDEBUG |
---|
693 | if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at); |
---|
694 | #endif |
---|
695 | h->Clear(); |
---|
696 | return -1; |
---|
697 | } |
---|
698 | } |
---|
699 | if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg)) |
---|
700 | { |
---|
701 | reddeg = d+1; |
---|
702 | Print(".%ld",d);mflush(); |
---|
703 | if (h->pTotalDeg()+h->ecart >= (int)strat->tailRing->bitmask) |
---|
704 | { |
---|
705 | strat->overflow=TRUE; |
---|
706 | //Print("OVERFLOW in redFirst d=%ld, max=%ld",d,strat->tailRing->bitmask); |
---|
707 | h->GetP(); |
---|
708 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
709 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
710 | h->Clear(); |
---|
711 | return -1; |
---|
712 | } |
---|
713 | } |
---|
714 | } |
---|
715 | } |
---|
716 | } |
---|
717 | |
---|
718 | /*2 |
---|
719 | * reduces h with elements from T choosing first possible |
---|
720 | * element in T with respect to the given ecart |
---|
721 | * used for computing normal forms outside kStd |
---|
722 | */ |
---|
723 | static poly redMoraNF (poly h,kStrategy strat, int flag) |
---|
724 | { |
---|
725 | LObject H; |
---|
726 | H.p = h; |
---|
727 | int j = 0; |
---|
728 | int z = 10; |
---|
729 | int o = H.SetpFDeg(); |
---|
730 | H.ecart = currRing->pLDeg(H.p,&H.length,currRing)-o; |
---|
731 | if ((flag & 2) == 0) cancelunit(&H,TRUE); |
---|
732 | H.sev = pGetShortExpVector(H.p); |
---|
733 | unsigned long not_sev = ~ H.sev; |
---|
734 | loop |
---|
735 | { |
---|
736 | if (j > strat->tl) |
---|
737 | { |
---|
738 | return H.p; |
---|
739 | } |
---|
740 | if (TEST_V_DEG_STOP) |
---|
741 | { |
---|
742 | if (kModDeg(H.p)>Kstd1_deg) pLmDelete(&H.p); |
---|
743 | if (H.p==NULL) return NULL; |
---|
744 | } |
---|
745 | #if ADIDEBUG_NF |
---|
746 | printf("\nSearching for a reducer...\n"); |
---|
747 | #endif |
---|
748 | if (p_LmShortDivisibleBy(strat->T[j].GetLmTailRing(), strat->sevT[j], H.GetLmTailRing(), not_sev, strat->tailRing) |
---|
749 | #ifdef HAVE_RINGS |
---|
750 | && (!rField_is_Ring(strat->tailRing) || |
---|
751 | n_DivBy(H.p->coef, strat->T[j].p->coef,strat->tailRing)) |
---|
752 | #endif |
---|
753 | ) |
---|
754 | { |
---|
755 | /*- remember the found T-poly -*/ |
---|
756 | // poly pi = strat->T[j].p; |
---|
757 | int ei = strat->T[j].ecart; |
---|
758 | int li = strat->T[j].length; |
---|
759 | int ii = j; |
---|
760 | #if ADIDEBUG_NF |
---|
761 | printf("\nFound: j = %i, ecart = %i\nTrying to find a better one...\n",j,ei);pWrite(strat->T[j].p); |
---|
762 | #endif |
---|
763 | /* |
---|
764 | * the polynomial to reduce with (up to the moment) is; |
---|
765 | * pi with ecart ei and length li |
---|
766 | */ |
---|
767 | loop |
---|
768 | { |
---|
769 | /*- look for a better one with respect to ecart -*/ |
---|
770 | /*- stop, if the ecart is small enough (<=ecart(H)) -*/ |
---|
771 | j++; |
---|
772 | if (j > strat->tl) break; |
---|
773 | if (ei <= H.ecart) break; |
---|
774 | if (((strat->T[j].ecart < ei) |
---|
775 | || ((strat->T[j].ecart == ei) |
---|
776 | && (strat->T[j].length < li))) |
---|
777 | && pLmShortDivisibleBy(strat->T[j].p,strat->sevT[j], H.p, not_sev) |
---|
778 | #ifdef HAVE_RINGS |
---|
779 | && (!rField_is_Ring(strat->tailRing) || |
---|
780 | n_DivBy(H.p->coef, strat->T[j].p->coef,strat->tailRing)) |
---|
781 | #endif |
---|
782 | ) |
---|
783 | { |
---|
784 | /* |
---|
785 | * the polynomial to reduce with is now; |
---|
786 | */ |
---|
787 | // pi = strat->T[j].p; |
---|
788 | ei = strat->T[j].ecart; |
---|
789 | li = strat->T[j].length; |
---|
790 | ii = j; |
---|
791 | #if ADIDEBUG_NF |
---|
792 | printf("\nFound a better one: j = %i, ecart = %i\nTrying to find a better one...\n",j,ei); |
---|
793 | pWrite(strat->T[j].p); |
---|
794 | #endif |
---|
795 | } |
---|
796 | } |
---|
797 | /* |
---|
798 | * end of search: have to reduce with pi |
---|
799 | */ |
---|
800 | z++; |
---|
801 | if (z>10) |
---|
802 | { |
---|
803 | pNormalize(H.p); |
---|
804 | z=0; |
---|
805 | } |
---|
806 | if ((ei > H.ecart) && (!strat->kHEdgeFound)) |
---|
807 | { |
---|
808 | /* |
---|
809 | * It is not possible to reduce h with smaller ecart; |
---|
810 | * we have to reduce with bad ecart: H has to enter in T |
---|
811 | */ |
---|
812 | doRed(&H,&(strat->T[ii]),TRUE,strat); |
---|
813 | if (H.p == NULL) |
---|
814 | return NULL; |
---|
815 | } |
---|
816 | else |
---|
817 | { |
---|
818 | /* |
---|
819 | * we reduce with good ecart, h need not to be put to T |
---|
820 | */ |
---|
821 | doRed(&H,&(strat->T[ii]),FALSE,strat); |
---|
822 | if (H.p == NULL) |
---|
823 | return NULL; |
---|
824 | } |
---|
825 | #if ADIDEBUG_NF |
---|
826 | printf("\nAfter the small reduction it looks like this:\n");pWrite(H.p); |
---|
827 | getchar(); |
---|
828 | #endif |
---|
829 | /*- try to reduce the s-polynomial -*/ |
---|
830 | o = H.SetpFDeg(); |
---|
831 | if ((flag &2 ) == 0) cancelunit(&H,TRUE); |
---|
832 | H.ecart = currRing->pLDeg(H.p,&(H.length),currRing)-o; |
---|
833 | j = 0; |
---|
834 | H.sev = pGetShortExpVector(H.p); |
---|
835 | not_sev = ~ H.sev; |
---|
836 | } |
---|
837 | else |
---|
838 | { |
---|
839 | j++; |
---|
840 | } |
---|
841 | } |
---|
842 | } |
---|
843 | |
---|
844 | /*2 |
---|
845 | *reorders L with respect to posInL |
---|
846 | */ |
---|
847 | void reorderL(kStrategy strat) |
---|
848 | { |
---|
849 | int i,j,at; |
---|
850 | LObject p; |
---|
851 | |
---|
852 | for (i=1; i<=strat->Ll; i++) |
---|
853 | { |
---|
854 | at = strat->posInL(strat->L,i-1,&(strat->L[i]),strat); |
---|
855 | if (at != i) |
---|
856 | { |
---|
857 | p = strat->L[i]; |
---|
858 | for (j=i-1; j>=at; j--) strat->L[j+1] = strat->L[j]; |
---|
859 | strat->L[at] = p; |
---|
860 | } |
---|
861 | } |
---|
862 | } |
---|
863 | |
---|
864 | /*2 |
---|
865 | *reorders T with respect to length |
---|
866 | */ |
---|
867 | void reorderT(kStrategy strat) |
---|
868 | { |
---|
869 | int i,j,at; |
---|
870 | TObject p; |
---|
871 | unsigned long sev; |
---|
872 | |
---|
873 | |
---|
874 | for (i=1; i<=strat->tl; i++) |
---|
875 | { |
---|
876 | if (strat->T[i-1].length > strat->T[i].length) |
---|
877 | { |
---|
878 | p = strat->T[i]; |
---|
879 | sev = strat->sevT[i]; |
---|
880 | at = i-1; |
---|
881 | loop |
---|
882 | { |
---|
883 | at--; |
---|
884 | if (at < 0) break; |
---|
885 | if (strat->T[i].length > strat->T[at].length) break; |
---|
886 | } |
---|
887 | for (j = i-1; j>at; j--) |
---|
888 | { |
---|
889 | strat->T[j+1]=strat->T[j]; |
---|
890 | strat->sevT[j+1]=strat->sevT[j]; |
---|
891 | strat->R[strat->T[j+1].i_r] = &(strat->T[j+1]); |
---|
892 | } |
---|
893 | strat->T[at+1]=p; |
---|
894 | strat->sevT[at+1] = sev; |
---|
895 | strat->R[p.i_r] = &(strat->T[at+1]); |
---|
896 | } |
---|
897 | } |
---|
898 | } |
---|
899 | |
---|
900 | /*2 |
---|
901 | *looks whether exactly (currRing->N)-1 axis are used |
---|
902 | *returns last != 0 in this case |
---|
903 | *last is the (first) unused axis |
---|
904 | */ |
---|
905 | void missingAxis (int* last,kStrategy strat) |
---|
906 | { |
---|
907 | int i = 0; |
---|
908 | int k = 0; |
---|
909 | |
---|
910 | *last = 0; |
---|
911 | if (!currRing->MixedOrder) |
---|
912 | { |
---|
913 | loop |
---|
914 | { |
---|
915 | i++; |
---|
916 | if (i > (currRing->N)) break; |
---|
917 | if (strat->NotUsedAxis[i]) |
---|
918 | { |
---|
919 | *last = i; |
---|
920 | k++; |
---|
921 | } |
---|
922 | if (k>1) |
---|
923 | { |
---|
924 | *last = 0; |
---|
925 | break; |
---|
926 | } |
---|
927 | } |
---|
928 | } |
---|
929 | } |
---|
930 | |
---|
931 | /*2 |
---|
932 | *last is the only non used axis, it looks |
---|
933 | *for a monomial in p being a pure power of this |
---|
934 | *variable and returns TRUE in this case |
---|
935 | *(*length) gives the length between the pure power and the leading term |
---|
936 | *(should be minimal) |
---|
937 | */ |
---|
938 | BOOLEAN hasPurePower (const poly p,int last, int *length,kStrategy strat) |
---|
939 | { |
---|
940 | poly h; |
---|
941 | int i; |
---|
942 | |
---|
943 | if (pNext(p) == strat->tail) |
---|
944 | return FALSE; |
---|
945 | pp_Test(p, currRing, strat->tailRing); |
---|
946 | if (strat->ak <= 0 || p_MinComp(p, currRing, strat->tailRing) == strat->ak) |
---|
947 | { |
---|
948 | i = p_IsPurePower(p, currRing); |
---|
949 | if (i == last) |
---|
950 | { |
---|
951 | *length = 0; |
---|
952 | return TRUE; |
---|
953 | } |
---|
954 | *length = 1; |
---|
955 | h = pNext(p); |
---|
956 | while (h != NULL) |
---|
957 | { |
---|
958 | i = p_IsPurePower(h, strat->tailRing); |
---|
959 | if (i==last) return TRUE; |
---|
960 | (*length)++; |
---|
961 | pIter(h); |
---|
962 | } |
---|
963 | } |
---|
964 | return FALSE; |
---|
965 | } |
---|
966 | |
---|
967 | BOOLEAN hasPurePower (LObject *L,int last, int *length,kStrategy strat) |
---|
968 | { |
---|
969 | if (L->bucket != NULL) |
---|
970 | { |
---|
971 | poly p = L->CanonicalizeP(); |
---|
972 | BOOLEAN ret = hasPurePower(p, last, length, strat); |
---|
973 | pNext(p) = NULL; |
---|
974 | return ret; |
---|
975 | } |
---|
976 | else |
---|
977 | { |
---|
978 | return hasPurePower(L->p, last, length, strat); |
---|
979 | } |
---|
980 | } |
---|
981 | |
---|
982 | /*2 |
---|
983 | * looks up the position of polynomial p in L |
---|
984 | * in the case of looking for the pure powers |
---|
985 | */ |
---|
986 | int posInL10 (const LSet set,const int length, LObject* p,const kStrategy strat) |
---|
987 | { |
---|
988 | int j,dp,dL; |
---|
989 | |
---|
990 | if (length<0) return 0; |
---|
991 | if (hasPurePower(p,strat->lastAxis,&dp,strat)) |
---|
992 | { |
---|
993 | int op= p->GetpFDeg() +p->ecart; |
---|
994 | for (j=length; j>=0; j--) |
---|
995 | { |
---|
996 | if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat)) |
---|
997 | return j+1; |
---|
998 | if (dp < dL) |
---|
999 | return j+1; |
---|
1000 | if ((dp == dL) |
---|
1001 | && (set[j].GetpFDeg()+set[j].ecart >= op)) |
---|
1002 | return j+1; |
---|
1003 | } |
---|
1004 | } |
---|
1005 | j=length; |
---|
1006 | loop |
---|
1007 | { |
---|
1008 | if (j<0) break; |
---|
1009 | if (!hasPurePower(&(set[j]),strat->lastAxis,&dL,strat)) break; |
---|
1010 | j--; |
---|
1011 | } |
---|
1012 | return strat->posInLOld(set,j,p,strat); |
---|
1013 | } |
---|
1014 | |
---|
1015 | |
---|
1016 | /*2 |
---|
1017 | * computes the s-polynomials L[ ].p in L |
---|
1018 | */ |
---|
1019 | void updateL(kStrategy strat) |
---|
1020 | { |
---|
1021 | LObject p; |
---|
1022 | int dL; |
---|
1023 | int j=strat->Ll; |
---|
1024 | loop |
---|
1025 | { |
---|
1026 | if (j<0) break; |
---|
1027 | if (hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat)) |
---|
1028 | { |
---|
1029 | p=strat->L[strat->Ll]; |
---|
1030 | strat->L[strat->Ll]=strat->L[j]; |
---|
1031 | strat->L[j]=p; |
---|
1032 | break; |
---|
1033 | } |
---|
1034 | j--; |
---|
1035 | } |
---|
1036 | if (j<0) |
---|
1037 | { |
---|
1038 | j=strat->Ll; |
---|
1039 | loop |
---|
1040 | { |
---|
1041 | if (j<0) break; |
---|
1042 | if (pNext(strat->L[j].p) == strat->tail) |
---|
1043 | { |
---|
1044 | #ifdef HAVE_RINGS |
---|
1045 | if (rField_is_Ring(currRing)) |
---|
1046 | pLmDelete(strat->L[j].p); /*deletes the short spoly and computes*/ |
---|
1047 | else |
---|
1048 | #else |
---|
1049 | pLmFree(strat->L[j].p); /*deletes the short spoly and computes*/ |
---|
1050 | #endif |
---|
1051 | strat->L[j].p = NULL; |
---|
1052 | poly m1 = NULL, m2 = NULL; |
---|
1053 | // check that spoly creation is ok |
---|
1054 | while (strat->tailRing != currRing && |
---|
1055 | !kCheckSpolyCreation(&(strat->L[j]), strat, m1, m2)) |
---|
1056 | { |
---|
1057 | assume(m1 == NULL && m2 == NULL); |
---|
1058 | // if not, change to a ring where exponents are at least |
---|
1059 | // large enough |
---|
1060 | kStratChangeTailRing(strat); |
---|
1061 | } |
---|
1062 | /* create the real one */ |
---|
1063 | ksCreateSpoly(&(strat->L[j]), strat->kNoetherTail(), FALSE, |
---|
1064 | strat->tailRing, m1, m2, strat->R); |
---|
1065 | |
---|
1066 | strat->L[j].SetLmCurrRing(); |
---|
1067 | if (!strat->honey) |
---|
1068 | strat->initEcart(&strat->L[j]); |
---|
1069 | else |
---|
1070 | strat->L[j].SetLength(strat->length_pLength); |
---|
1071 | |
---|
1072 | BOOLEAN pp = hasPurePower(&(strat->L[j]),strat->lastAxis,&dL,strat); |
---|
1073 | |
---|
1074 | if (strat->use_buckets) strat->L[j].PrepareRed(TRUE); |
---|
1075 | |
---|
1076 | if (pp) |
---|
1077 | { |
---|
1078 | p=strat->L[strat->Ll]; |
---|
1079 | strat->L[strat->Ll]=strat->L[j]; |
---|
1080 | strat->L[j]=p; |
---|
1081 | break; |
---|
1082 | } |
---|
1083 | } |
---|
1084 | j--; |
---|
1085 | } |
---|
1086 | } |
---|
1087 | } |
---|
1088 | |
---|
1089 | /*2 |
---|
1090 | * computes the s-polynomials L[ ].p in L and |
---|
1091 | * cuts elements in L above noether |
---|
1092 | */ |
---|
1093 | void updateLHC(kStrategy strat) |
---|
1094 | { |
---|
1095 | |
---|
1096 | int i = 0; |
---|
1097 | kTest_TS(strat); |
---|
1098 | while (i <= strat->Ll) |
---|
1099 | { |
---|
1100 | if (pNext(strat->L[i].p) == strat->tail) |
---|
1101 | { |
---|
1102 | /*- deletes the int spoly and computes -*/ |
---|
1103 | if (pLmCmp(strat->L[i].p,strat->kNoether) == -1) |
---|
1104 | { |
---|
1105 | pLmFree(strat->L[i].p); |
---|
1106 | strat->L[i].p = NULL; |
---|
1107 | } |
---|
1108 | else |
---|
1109 | { |
---|
1110 | pLmFree(strat->L[i].p); |
---|
1111 | strat->L[i].p = NULL; |
---|
1112 | poly m1 = NULL, m2 = NULL; |
---|
1113 | // check that spoly creation is ok |
---|
1114 | while (strat->tailRing != currRing && |
---|
1115 | !kCheckSpolyCreation(&(strat->L[i]), strat, m1, m2)) |
---|
1116 | { |
---|
1117 | assume(m1 == NULL && m2 == NULL); |
---|
1118 | // if not, change to a ring where exponents are at least |
---|
1119 | // large enough |
---|
1120 | kStratChangeTailRing(strat); |
---|
1121 | } |
---|
1122 | /* create the real one */ |
---|
1123 | ksCreateSpoly(&(strat->L[i]), strat->kNoetherTail(), FALSE, |
---|
1124 | strat->tailRing, m1, m2, strat->R); |
---|
1125 | if (! strat->L[i].IsNull()) |
---|
1126 | { |
---|
1127 | strat->L[i].SetLmCurrRing(); |
---|
1128 | strat->L[i].SetpFDeg(); |
---|
1129 | strat->L[i].ecart |
---|
1130 | = strat->L[i].pLDeg(strat->LDegLast) - strat->L[i].GetpFDeg(); |
---|
1131 | if (strat->use_buckets) strat->L[i].PrepareRed(TRUE); |
---|
1132 | } |
---|
1133 | } |
---|
1134 | } |
---|
1135 | else |
---|
1136 | deleteHC(&(strat->L[i]), strat); |
---|
1137 | if (strat->L[i].IsNull()) |
---|
1138 | deleteInL(strat->L,&strat->Ll,i,strat); |
---|
1139 | else |
---|
1140 | { |
---|
1141 | #ifdef KDEBUG |
---|
1142 | kTest_L(&(strat->L[i]), strat->tailRing, TRUE, i, strat->T, strat->tl); |
---|
1143 | #endif |
---|
1144 | i++; |
---|
1145 | } |
---|
1146 | } |
---|
1147 | kTest_TS(strat); |
---|
1148 | } |
---|
1149 | |
---|
1150 | /*2 |
---|
1151 | * cuts in T above strat->kNoether and tries to cancel a unit |
---|
1152 | */ |
---|
1153 | void updateT(kStrategy strat) |
---|
1154 | { |
---|
1155 | int i = 0; |
---|
1156 | LObject p; |
---|
1157 | |
---|
1158 | while (i <= strat->tl) |
---|
1159 | { |
---|
1160 | p = strat->T[i]; |
---|
1161 | deleteHC(&p,strat, TRUE); |
---|
1162 | /*- tries to cancel a unit: -*/ |
---|
1163 | cancelunit(&p); |
---|
1164 | if (p.p != strat->T[i].p) |
---|
1165 | { |
---|
1166 | strat->sevT[i] = pGetShortExpVector(p.p); |
---|
1167 | p.SetpFDeg(); |
---|
1168 | } |
---|
1169 | strat->T[i] = p; |
---|
1170 | i++; |
---|
1171 | } |
---|
1172 | } |
---|
1173 | |
---|
1174 | /*2 |
---|
1175 | * arranges red, pos and T if strat->kHEdgeFound (first time) |
---|
1176 | */ |
---|
1177 | void firstUpdate(kStrategy strat) |
---|
1178 | { |
---|
1179 | if (strat->update) |
---|
1180 | { |
---|
1181 | kTest_TS(strat); |
---|
1182 | strat->update = (strat->tl == -1); |
---|
1183 | if (TEST_OPT_WEIGHTM) |
---|
1184 | { |
---|
1185 | pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
1186 | if (strat->tailRing != currRing) |
---|
1187 | { |
---|
1188 | strat->tailRing->pFDeg = strat->pOrigFDeg_TailRing; |
---|
1189 | strat->tailRing->pLDeg = strat->pOrigLDeg_TailRing; |
---|
1190 | } |
---|
1191 | int i; |
---|
1192 | for (i=strat->Ll; i>=0; i--) |
---|
1193 | { |
---|
1194 | strat->L[i].SetpFDeg(); |
---|
1195 | } |
---|
1196 | for (i=strat->tl; i>=0; i--) |
---|
1197 | { |
---|
1198 | strat->T[i].SetpFDeg(); |
---|
1199 | } |
---|
1200 | if (ecartWeights) |
---|
1201 | { |
---|
1202 | omFreeSize((ADDRESS)ecartWeights,(rVar(currRing)+1)*sizeof(short)); |
---|
1203 | ecartWeights=NULL; |
---|
1204 | } |
---|
1205 | } |
---|
1206 | if (TEST_OPT_FASTHC) |
---|
1207 | { |
---|
1208 | strat->posInL = strat->posInLOld; |
---|
1209 | strat->lastAxis = 0; |
---|
1210 | } |
---|
1211 | if (TEST_OPT_FINDET) |
---|
1212 | return; |
---|
1213 | |
---|
1214 | #ifndef HAVE_RINGS |
---|
1215 | strat->red = redFirst; |
---|
1216 | strat->use_buckets = kMoraUseBucket(strat); |
---|
1217 | #else |
---|
1218 | if ( (!rField_is_Ring(currRing)) || (rHasGlobalOrdering(currRing))) |
---|
1219 | { |
---|
1220 | strat->red = redFirst; |
---|
1221 | strat->use_buckets = kMoraUseBucket(strat); |
---|
1222 | } |
---|
1223 | #endif |
---|
1224 | updateT(strat); |
---|
1225 | |
---|
1226 | #ifndef HAVE_RINGS |
---|
1227 | strat->posInT = posInT2; |
---|
1228 | reorderT(strat); |
---|
1229 | #else |
---|
1230 | if ( (!rField_is_Ring(currRing)) || (rHasGlobalOrdering(currRing))) |
---|
1231 | { |
---|
1232 | strat->posInT = posInT2; |
---|
1233 | reorderT(strat); |
---|
1234 | } |
---|
1235 | #endif |
---|
1236 | } |
---|
1237 | kTest_TS(strat); |
---|
1238 | } |
---|
1239 | |
---|
1240 | /*2 |
---|
1241 | *-puts p to the standardbasis s at position at |
---|
1242 | *-reduces the tail of p if TEST_OPT_REDTAIL |
---|
1243 | *-tries to cancel a unit |
---|
1244 | *-HEckeTest |
---|
1245 | * if TRUE |
---|
1246 | * - decides about reduction-strategies |
---|
1247 | * - computes noether |
---|
1248 | * - stops computation if TEST_OPT_FINDET |
---|
1249 | * - cuts the tails of the polynomials |
---|
1250 | * in s,t and the elements in L above noether |
---|
1251 | * and cancels units if possible |
---|
1252 | * - reorders s,L |
---|
1253 | */ |
---|
1254 | void enterSMora (LObject &p,int atS,kStrategy strat, int atR = -1) |
---|
1255 | { |
---|
1256 | enterSBba(p, atS, strat, atR); |
---|
1257 | #ifdef KDEBUG |
---|
1258 | if (TEST_OPT_DEBUG) |
---|
1259 | { |
---|
1260 | Print("new s%d:",atS); |
---|
1261 | p_wrp(p.p,currRing,strat->tailRing); |
---|
1262 | PrintLn(); |
---|
1263 | } |
---|
1264 | #endif |
---|
1265 | if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat); |
---|
1266 | if (strat->kHEdgeFound) |
---|
1267 | { |
---|
1268 | if (newHEdge(strat)) |
---|
1269 | { |
---|
1270 | firstUpdate(strat); |
---|
1271 | if (TEST_OPT_FINDET) |
---|
1272 | return; |
---|
1273 | |
---|
1274 | /*- cuts elements in L above noether and reorders L -*/ |
---|
1275 | updateLHC(strat); |
---|
1276 | /*- reorders L with respect to posInL -*/ |
---|
1277 | reorderL(strat); |
---|
1278 | } |
---|
1279 | } |
---|
1280 | else if (strat->kNoether!=NULL) |
---|
1281 | strat->kHEdgeFound = TRUE; |
---|
1282 | else if (TEST_OPT_FASTHC) |
---|
1283 | { |
---|
1284 | if (strat->posInLOldFlag) |
---|
1285 | { |
---|
1286 | missingAxis(&strat->lastAxis,strat); |
---|
1287 | if (strat->lastAxis) |
---|
1288 | { |
---|
1289 | strat->posInLOld = strat->posInL; |
---|
1290 | strat->posInLOldFlag = FALSE; |
---|
1291 | strat->posInL = posInL10; |
---|
1292 | strat->posInLDependsOnLength = TRUE; |
---|
1293 | updateL(strat); |
---|
1294 | reorderL(strat); |
---|
1295 | } |
---|
1296 | } |
---|
1297 | else if (strat->lastAxis) |
---|
1298 | updateL(strat); |
---|
1299 | } |
---|
1300 | } |
---|
1301 | |
---|
1302 | /*2 |
---|
1303 | *-puts p to the standardbasis s at position at |
---|
1304 | *-HEckeTest |
---|
1305 | * if TRUE |
---|
1306 | * - computes noether |
---|
1307 | */ |
---|
1308 | void enterSMoraNF (LObject &p, int atS,kStrategy strat, int atR = -1) |
---|
1309 | { |
---|
1310 | enterSBba(p, atS, strat, atR); |
---|
1311 | if ((!strat->kHEdgeFound) || (strat->kNoether!=NULL)) HEckeTest(p.p,strat); |
---|
1312 | if (strat->kHEdgeFound) |
---|
1313 | newHEdge(strat); |
---|
1314 | else if (strat->kNoether!=NULL) |
---|
1315 | strat->kHEdgeFound = TRUE; |
---|
1316 | } |
---|
1317 | |
---|
1318 | void initBba(ideal /*F*/,kStrategy strat) |
---|
1319 | { |
---|
1320 | /* setting global variables ------------------- */ |
---|
1321 | strat->enterS = enterSBba; |
---|
1322 | strat->red = redHoney; |
---|
1323 | if (strat->honey) |
---|
1324 | strat->red = redHoney; |
---|
1325 | else if (currRing->pLexOrder && !strat->homog) |
---|
1326 | strat->red = redLazy; |
---|
1327 | else |
---|
1328 | { |
---|
1329 | strat->LazyPass *=4; |
---|
1330 | strat->red = redHomog; |
---|
1331 | } |
---|
1332 | #ifdef HAVE_RINGS //TODO Oliver |
---|
1333 | if (rField_is_Ring(currRing)) |
---|
1334 | { |
---|
1335 | strat->red = redRing; |
---|
1336 | } |
---|
1337 | #endif |
---|
1338 | if (currRing->pLexOrder && strat->honey) |
---|
1339 | strat->initEcart = initEcartNormal; |
---|
1340 | else |
---|
1341 | strat->initEcart = initEcartBBA; |
---|
1342 | if (strat->honey) |
---|
1343 | strat->initEcartPair = initEcartPairMora; |
---|
1344 | else |
---|
1345 | strat->initEcartPair = initEcartPairBba; |
---|
1346 | // if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
1347 | // { |
---|
1348 | // //interred machen Aenderung |
---|
1349 | // strat->pOrigFDeg=pFDeg; |
---|
1350 | // strat->pOrigLDeg=pLDeg; |
---|
1351 | // //h=ggetid("ecart"); |
---|
1352 | // //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/) |
---|
1353 | // //{ |
---|
1354 | // // ecartWeights=iv2array(IDINTVEC(h)); |
---|
1355 | // //} |
---|
1356 | // //else |
---|
1357 | // { |
---|
1358 | // ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short)); |
---|
1359 | // /*uses automatic computation of the ecartWeights to set them*/ |
---|
1360 | // kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights); |
---|
1361 | // } |
---|
1362 | // pRestoreDegProcs(currRing,totaldegreeWecart, maxdegreeWecart); |
---|
1363 | // if (TEST_OPT_PROT) |
---|
1364 | // { |
---|
1365 | // for(i=1; i<=(currRing->N); i++) |
---|
1366 | // Print(" %d",ecartWeights[i]); |
---|
1367 | // PrintLn(); |
---|
1368 | // mflush(); |
---|
1369 | // } |
---|
1370 | // } |
---|
1371 | } |
---|
1372 | |
---|
1373 | void initSba(ideal F,kStrategy strat) |
---|
1374 | { |
---|
1375 | int i; |
---|
1376 | //idhdl h; |
---|
1377 | /* setting global variables ------------------- */ |
---|
1378 | strat->enterS = enterSSba; |
---|
1379 | strat->red2 = redHoney; |
---|
1380 | if (strat->honey) |
---|
1381 | strat->red2 = redHoney; |
---|
1382 | else if (currRing->pLexOrder && !strat->homog) |
---|
1383 | strat->red2 = redLazy; |
---|
1384 | else |
---|
1385 | { |
---|
1386 | strat->LazyPass *=4; |
---|
1387 | strat->red2 = redHomog; |
---|
1388 | } |
---|
1389 | #if defined(HAVE_RINGS) |
---|
1390 | if (rField_is_Ring(currRing)) |
---|
1391 | { |
---|
1392 | if(rHasLocalOrMixedOrdering(currRing)) |
---|
1393 | {strat->red = redRiloc;} |
---|
1394 | else |
---|
1395 | {strat->red2 = redRing;} |
---|
1396 | } |
---|
1397 | #endif |
---|
1398 | if (currRing->pLexOrder && strat->honey) |
---|
1399 | strat->initEcart = initEcartNormal; |
---|
1400 | else |
---|
1401 | strat->initEcart = initEcartBBA; |
---|
1402 | if (strat->honey) |
---|
1403 | strat->initEcartPair = initEcartPairMora; |
---|
1404 | else |
---|
1405 | strat->initEcartPair = initEcartPairBba; |
---|
1406 | //strat->kIdeal = NULL; |
---|
1407 | //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD; |
---|
1408 | //else strat->kIdeal->rtyp=MODUL_CMD; |
---|
1409 | //strat->kIdeal->data=(void *)strat->Shdl; |
---|
1410 | if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
1411 | { |
---|
1412 | //interred machen Aenderung |
---|
1413 | strat->pOrigFDeg = currRing->pFDeg; |
---|
1414 | strat->pOrigLDeg = currRing->pLDeg; |
---|
1415 | //h=ggetid("ecart"); |
---|
1416 | //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/) |
---|
1417 | //{ |
---|
1418 | // ecartWeights=iv2array(IDINTVEC(h)); |
---|
1419 | //} |
---|
1420 | //else |
---|
1421 | { |
---|
1422 | ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short)); |
---|
1423 | /*uses automatic computation of the ecartWeights to set them*/ |
---|
1424 | kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights, currRing); |
---|
1425 | } |
---|
1426 | pRestoreDegProcs(currRing, totaldegreeWecart, maxdegreeWecart); |
---|
1427 | if (TEST_OPT_PROT) |
---|
1428 | { |
---|
1429 | for(i=1; i<=(currRing->N); i++) |
---|
1430 | Print(" %d",ecartWeights[i]); |
---|
1431 | PrintLn(); |
---|
1432 | mflush(); |
---|
1433 | } |
---|
1434 | } |
---|
1435 | // for sig-safe reductions in signature-based |
---|
1436 | // standard basis computations |
---|
1437 | strat->red = redSig; |
---|
1438 | //strat->sbaOrder = 1; |
---|
1439 | strat->currIdx = 1; |
---|
1440 | } |
---|
1441 | |
---|
1442 | void initMora(ideal F,kStrategy strat) |
---|
1443 | { |
---|
1444 | int i,j; |
---|
1445 | |
---|
1446 | strat->NotUsedAxis = (BOOLEAN *)omAlloc(((currRing->N)+1)*sizeof(BOOLEAN)); |
---|
1447 | for (j=(currRing->N); j>0; j--) strat->NotUsedAxis[j] = TRUE; |
---|
1448 | strat->enterS = enterSMora; |
---|
1449 | strat->initEcartPair = initEcartPairMora; /*- ecart approximation -*/ |
---|
1450 | strat->posInLOld = strat->posInL; |
---|
1451 | strat->posInLOldFlag = TRUE; |
---|
1452 | strat->initEcart = initEcartNormal; |
---|
1453 | strat->kHEdgeFound = (currRing->ppNoether) != NULL; |
---|
1454 | if ( strat->kHEdgeFound ) |
---|
1455 | strat->kNoether = pCopy((currRing->ppNoether)); |
---|
1456 | else if (strat->kHEdgeFound || strat->homog) |
---|
1457 | strat->red = redFirst; /*take the first possible in T*/ |
---|
1458 | else |
---|
1459 | strat->red = redEcart;/*take the first possible in under ecart-restriction*/ |
---|
1460 | if (strat->kHEdgeFound) |
---|
1461 | { |
---|
1462 | strat->HCord = currRing->pFDeg((currRing->ppNoether),currRing)+1; |
---|
1463 | strat->posInT = posInT2; |
---|
1464 | } |
---|
1465 | else |
---|
1466 | { |
---|
1467 | strat->HCord = 32000;/*- very large -*/ |
---|
1468 | } |
---|
1469 | |
---|
1470 | #ifdef HAVE_RINGS |
---|
1471 | if (rField_is_Ring(currRing)) |
---|
1472 | strat->red = redRiloc; |
---|
1473 | #endif |
---|
1474 | |
---|
1475 | /*reads the ecartWeights used for Graebes method from the |
---|
1476 | *intvec ecart and set ecartWeights |
---|
1477 | */ |
---|
1478 | if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
1479 | { |
---|
1480 | //interred machen Aenderung |
---|
1481 | strat->pOrigFDeg=currRing->pFDeg; |
---|
1482 | strat->pOrigLDeg=currRing->pLDeg; |
---|
1483 | ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short)); |
---|
1484 | /*uses automatic computation of the ecartWeights to set them*/ |
---|
1485 | kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights,currRing); |
---|
1486 | |
---|
1487 | pSetDegProcs(currRing,totaldegreeWecart, maxdegreeWecart); |
---|
1488 | if (TEST_OPT_PROT) |
---|
1489 | { |
---|
1490 | for(i=1; i<=(currRing->N); i++) |
---|
1491 | Print(" %d",ecartWeights[i]); |
---|
1492 | PrintLn(); |
---|
1493 | mflush(); |
---|
1494 | } |
---|
1495 | } |
---|
1496 | kOptimizeLDeg(currRing->pLDeg, strat); |
---|
1497 | } |
---|
1498 | |
---|
1499 | void kDebugPrint(kStrategy strat); |
---|
1500 | |
---|
1501 | ideal mora (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat) |
---|
1502 | { |
---|
1503 | #ifdef HAVE_RINGS |
---|
1504 | #if ADIDEBUG |
---|
1505 | int loop_count; |
---|
1506 | loop_count = 1; |
---|
1507 | #endif |
---|
1508 | #endif |
---|
1509 | int olddeg = 0; |
---|
1510 | int reduc = 0; |
---|
1511 | int red_result = 1; |
---|
1512 | int hilbeledeg=1,hilbcount=0; |
---|
1513 | BITSET save1; |
---|
1514 | SI_SAVE_OPT1(save1); |
---|
1515 | if (currRing->MixedOrder) |
---|
1516 | { |
---|
1517 | si_opt_1 &= ~Sy_bit(OPT_REDSB); |
---|
1518 | si_opt_1 &= ~Sy_bit(OPT_REDTAIL); |
---|
1519 | } |
---|
1520 | |
---|
1521 | strat->update = TRUE; |
---|
1522 | /*- setting global variables ------------------- -*/ |
---|
1523 | initBuchMoraCrit(strat); |
---|
1524 | initHilbCrit(F,Q,&hilb,strat); |
---|
1525 | initMora(F,strat); |
---|
1526 | initBuchMoraPos(strat); |
---|
1527 | /*Shdl=*/initBuchMora(F,Q,strat); |
---|
1528 | if (TEST_OPT_FASTHC) missingAxis(&strat->lastAxis,strat); |
---|
1529 | /*updateS in initBuchMora has Hecketest |
---|
1530 | * and could have put strat->kHEdgdeFound FALSE*/ |
---|
1531 | if ((currRing->ppNoether)!=NULL) |
---|
1532 | { |
---|
1533 | strat->kHEdgeFound = TRUE; |
---|
1534 | } |
---|
1535 | if (strat->kHEdgeFound && strat->update) |
---|
1536 | { |
---|
1537 | firstUpdate(strat); |
---|
1538 | updateLHC(strat); |
---|
1539 | reorderL(strat); |
---|
1540 | } |
---|
1541 | if (TEST_OPT_FASTHC && (strat->lastAxis) && strat->posInLOldFlag) |
---|
1542 | { |
---|
1543 | strat->posInLOld = strat->posInL; |
---|
1544 | strat->posInLOldFlag = FALSE; |
---|
1545 | strat->posInL = posInL10; |
---|
1546 | updateL(strat); |
---|
1547 | reorderL(strat); |
---|
1548 | } |
---|
1549 | kTest_TS(strat); |
---|
1550 | strat->use_buckets = kMoraUseBucket(strat); |
---|
1551 | /*- compute-------------------------------------------*/ |
---|
1552 | |
---|
1553 | #ifdef HAVE_TAIL_RING |
---|
1554 | // if (strat->homog && strat->red == redFirst) |
---|
1555 | kStratInitChangeTailRing(strat); |
---|
1556 | #endif |
---|
1557 | |
---|
1558 | if (BVERBOSE(23)) |
---|
1559 | { |
---|
1560 | kDebugPrint(strat); |
---|
1561 | } |
---|
1562 | |
---|
1563 | while (strat->Ll >= 0) |
---|
1564 | { |
---|
1565 | #ifdef KDEBUG |
---|
1566 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
1567 | #endif |
---|
1568 | if (TEST_OPT_DEGBOUND |
---|
1569 | && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg)) |
---|
1570 | { |
---|
1571 | /* |
---|
1572 | * stops computation if |
---|
1573 | * - 24 (degBound) |
---|
1574 | * && upper degree is bigger than Kstd1_deg |
---|
1575 | */ |
---|
1576 | while ((strat->Ll >= 0) |
---|
1577 | && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL) |
---|
1578 | && (strat->L[strat->Ll].ecart+strat->L[strat->Ll].GetpFDeg()> Kstd1_deg) |
---|
1579 | ) |
---|
1580 | { |
---|
1581 | deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
1582 | //if (TEST_OPT_PROT) |
---|
1583 | //{ |
---|
1584 | // PrintS("D"); mflush(); |
---|
1585 | //} |
---|
1586 | } |
---|
1587 | if (strat->Ll<0) break; |
---|
1588 | else strat->noClearS=TRUE; |
---|
1589 | } |
---|
1590 | |
---|
1591 | #if ADIDEBUG |
---|
1592 | #ifdef KDEBUG |
---|
1593 | Print("\n-------------------------------- LOOP %d ---------------------------------------\n",loop_count); |
---|
1594 | //print the list L: (p1,p2,p) |
---|
1595 | Print("\n The pair list L -- in loop %d -- is:\n",loop_count); |
---|
1596 | for(int iii=0;iii<=strat->Ll;iii++) |
---|
1597 | { |
---|
1598 | Print("\n L[%d]:\n",iii); |
---|
1599 | PrintS(" ");p_Write(strat->L[iii].p1,strat->tailRing); |
---|
1600 | PrintS(" ");p_Write(strat->L[iii].p2,strat->tailRing); |
---|
1601 | PrintS(" ");p_Write(strat->L[iii].p,strat->tailRing); |
---|
1602 | } |
---|
1603 | PrintLn(); |
---|
1604 | #endif |
---|
1605 | #endif |
---|
1606 | |
---|
1607 | strat->P = strat->L[strat->Ll];/*- picks the last element from the lazyset L -*/ |
---|
1608 | if (strat->Ll==0) strat->interpt=TRUE; |
---|
1609 | strat->Ll--; |
---|
1610 | |
---|
1611 | #if ADIDEBUG |
---|
1612 | #ifdef KDEBUG |
---|
1613 | PrintS(" My new pair P = (p1,p2,p) is:\n"); |
---|
1614 | PrintS(" p1 = "); p_Write(strat->P.p1,strat->tailRing);PrintLn(); |
---|
1615 | PrintS(" p2 = "); p_Write(strat->P.p2,strat->tailRing);PrintLn(); |
---|
1616 | PrintS(" p = "); p_Write(strat->P.p,strat->tailRing); PrintLn(); |
---|
1617 | Print("\n The old reducer list T -- at the beg of loop %d -- is :",loop_count); |
---|
1618 | if(strat->tl<0) |
---|
1619 | {PrintS(" Empty.\n");} |
---|
1620 | else |
---|
1621 | for(int iii=0;iii<=strat->tl;iii++) |
---|
1622 | { |
---|
1623 | Print("\n T[%d]:",iii); |
---|
1624 | p_Write(strat->T[iii].p,strat->T->tailRing); |
---|
1625 | } |
---|
1626 | PrintLn(); |
---|
1627 | #endif /* ADIDEBUG */ |
---|
1628 | #endif |
---|
1629 | |
---|
1630 | // create the real Spoly |
---|
1631 | if (pNext(strat->P.p) == strat->tail) |
---|
1632 | { |
---|
1633 | /*- deletes the short spoly and computes -*/ |
---|
1634 | #ifdef HAVE_RINGS |
---|
1635 | if (rField_is_Ring(currRing)) |
---|
1636 | pLmDelete(strat->P.p); |
---|
1637 | else |
---|
1638 | #endif |
---|
1639 | pLmFree(strat->P.p); |
---|
1640 | strat->P.p = NULL; |
---|
1641 | poly m1 = NULL, m2 = NULL; |
---|
1642 | // check that spoly creation is ok |
---|
1643 | while (strat->tailRing != currRing && |
---|
1644 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
1645 | { |
---|
1646 | assume(m1 == NULL && m2 == NULL); |
---|
1647 | // if not, change to a ring where exponents are large enough |
---|
1648 | kStratChangeTailRing(strat); |
---|
1649 | } |
---|
1650 | /* create the real one */ |
---|
1651 | ksCreateSpoly(&(strat->P), strat->kNoetherTail(), strat->use_buckets, |
---|
1652 | strat->tailRing, m1, m2, strat->R); |
---|
1653 | if (!strat->use_buckets) |
---|
1654 | strat->P.SetLength(strat->length_pLength); |
---|
1655 | } |
---|
1656 | else if (strat->P.p1 == NULL) |
---|
1657 | { |
---|
1658 | // for input polys, prepare reduction (buckets !) |
---|
1659 | strat->P.SetLength(strat->length_pLength); |
---|
1660 | strat->P.PrepareRed(strat->use_buckets); |
---|
1661 | } |
---|
1662 | |
---|
1663 | if (!strat->P.IsNull()) |
---|
1664 | { |
---|
1665 | // might be NULL from noether !!! |
---|
1666 | if (TEST_OPT_PROT) |
---|
1667 | message(strat->P.ecart+strat->P.GetpFDeg(),&olddeg,&reduc,strat, red_result); |
---|
1668 | // reduce |
---|
1669 | #if ADIDEBUG |
---|
1670 | printf("\nThis is P vor red:\n");p_Write(strat->P.p,strat->tailRing);p_Write(strat->P.p1,strat->tailRing);p_Write(strat->P.p2,strat->tailRing); |
---|
1671 | printf("\nBefore Ll = %i\n", strat->Ll); |
---|
1672 | #endif |
---|
1673 | red_result = strat->red(&strat->P,strat); |
---|
1674 | #if ADIDEBUG |
---|
1675 | printf("\nThis is P nach red:\n");p_Write(strat->P.p,strat->tailRing);p_Write(strat->P.p1,strat->tailRing);p_Write(strat->P.p2,strat->tailRing); |
---|
1676 | printf("\nBefore Ll = %i\n", strat->Ll); |
---|
1677 | #endif |
---|
1678 | } |
---|
1679 | |
---|
1680 | if (! strat->P.IsNull()) |
---|
1681 | { |
---|
1682 | strat->P.GetP(); |
---|
1683 | // statistics |
---|
1684 | if (TEST_OPT_PROT) PrintS("s"); |
---|
1685 | // normalization |
---|
1686 | if (!TEST_OPT_INTSTRATEGY) |
---|
1687 | strat->P.pNorm(); |
---|
1688 | // tailreduction |
---|
1689 | strat->P.p = redtail(&(strat->P),strat->sl,strat); |
---|
1690 | if (strat->P.p==NULL) |
---|
1691 | { |
---|
1692 | WerrorS("expoent overflow - wrong ordering"); |
---|
1693 | return(idInit(1,1)); |
---|
1694 | } |
---|
1695 | // set ecart -- might have changed because of tail reductions |
---|
1696 | if ((!strat->noTailReduction) && (!strat->honey)) |
---|
1697 | strat->initEcart(&strat->P); |
---|
1698 | // cancel unit |
---|
1699 | cancelunit(&strat->P); |
---|
1700 | // for char 0, clear denominators |
---|
1701 | if (TEST_OPT_INTSTRATEGY) |
---|
1702 | strat->P.pCleardenom(); |
---|
1703 | |
---|
1704 | // put in T |
---|
1705 | enterT(strat->P,strat); |
---|
1706 | // build new pairs |
---|
1707 | #ifdef HAVE_RINGS |
---|
1708 | if (rField_is_Ring(currRing)) |
---|
1709 | { |
---|
1710 | superenterpairs(strat->P.p,strat->sl,strat->P.ecart,0,strat, strat->tl); |
---|
1711 | |
---|
1712 | #if ADIDEBUG |
---|
1713 | Print("\n The new pair list L -- after superenterpairs in loop %d -- is:\n",loop_count); |
---|
1714 | for(int iii=0;iii<=strat->Ll;iii++) |
---|
1715 | { |
---|
1716 | PrintS("\n L[%d]:\n",iii); |
---|
1717 | PrintS(" ");p_Write(strat->L[iii].p1,strat->tailRing); |
---|
1718 | PrintS(" ");p_Write(strat->L[iii].p2,strat->tailRing); |
---|
1719 | PrintS(" ");p_Write(strat->L[iii].p,strat->tailRing); |
---|
1720 | } |
---|
1721 | #endif |
---|
1722 | } |
---|
1723 | else |
---|
1724 | #endif |
---|
1725 | enterpairs(strat->P.p,strat->sl,strat->P.ecart,0,strat, strat->tl); |
---|
1726 | // put in S |
---|
1727 | |
---|
1728 | #if ADIDEBUG |
---|
1729 | Print("\n The new pair list L -- after superenterpairs in loop %d -- is:\n",loop_count); |
---|
1730 | for(int iii=0;iii<=strat->Ll;iii++) |
---|
1731 | { |
---|
1732 | printf("\n L[%d]:\n",iii); |
---|
1733 | PrintS(" ");p_Write(strat->L[iii].p,strat->tailRing); |
---|
1734 | PrintS(" ");p_Write(strat->L[iii].p1,strat->tailRing); |
---|
1735 | PrintS(" ");p_Write(strat->L[iii].p2,strat->tailRing); |
---|
1736 | } |
---|
1737 | #endif |
---|
1738 | strat->enterS(strat->P, |
---|
1739 | posInS(strat,strat->sl,strat->P.p, strat->P.ecart), |
---|
1740 | strat, strat->tl); |
---|
1741 | #if ADIDEBUG |
---|
1742 | printf("\nThis pair has been added to S:\n"); |
---|
1743 | pWrite(strat->P.p); |
---|
1744 | pWrite(strat->P.p1); |
---|
1745 | pWrite(strat->P.p2); |
---|
1746 | #endif |
---|
1747 | |
---|
1748 | // apply hilbert criterion |
---|
1749 | if (hilb!=NULL) |
---|
1750 | { |
---|
1751 | if (strat->homog==isHomog) |
---|
1752 | khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
1753 | else |
---|
1754 | khCheckLocInhom(Q,w,hilb,hilbcount,strat); |
---|
1755 | } |
---|
1756 | |
---|
1757 | // clear strat->P |
---|
1758 | if (strat->P.lcm!=NULL) |
---|
1759 | #if defined(HAVE_RINGS) |
---|
1760 | pLmDelete(strat->P.lcm); |
---|
1761 | #else |
---|
1762 | pLmFree(strat->P.lcm); |
---|
1763 | #endif |
---|
1764 | strat->P.lcm=NULL; |
---|
1765 | #ifdef KDEBUG |
---|
1766 | // make sure kTest_TS does not complain about strat->P |
---|
1767 | memset(&strat->P,0,sizeof(strat->P)); |
---|
1768 | #endif |
---|
1769 | } |
---|
1770 | if (strat->kHEdgeFound) |
---|
1771 | { |
---|
1772 | if ((TEST_OPT_FINDET) |
---|
1773 | || ((TEST_OPT_MULTBOUND) && (scMult0Int(strat->Shdl,NULL,strat->tailRing) < Kstd1_mu))) |
---|
1774 | { |
---|
1775 | // obachman: is this still used ??? |
---|
1776 | /* |
---|
1777 | * stops computation if strat->kHEdgeFound and |
---|
1778 | * - 27 (finiteDeterminacyTest) |
---|
1779 | * or |
---|
1780 | * - 23 |
---|
1781 | * (multBound) |
---|
1782 | * && multiplicity of the ideal is smaller then a predefined number mu |
---|
1783 | */ |
---|
1784 | while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
1785 | } |
---|
1786 | } |
---|
1787 | kTest_TS(strat); |
---|
1788 | |
---|
1789 | #if ADIDEBUG |
---|
1790 | Print("\n The new reducer list T -- at the end of loop %d -- is\n",loop_count); |
---|
1791 | for(int iii=0;iii<=strat->tl;iii++) |
---|
1792 | { |
---|
1793 | printf("\n T[%d]:",iii); |
---|
1794 | p_Write(strat->T[iii].p,strat->tailRing); |
---|
1795 | } |
---|
1796 | PrintLn(); |
---|
1797 | |
---|
1798 | loop_count++; |
---|
1799 | #endif /* ADIDEBUG */ |
---|
1800 | } |
---|
1801 | /*- complete reduction of the standard basis------------------------ -*/ |
---|
1802 | if (TEST_OPT_REDSB) completeReduce(strat); |
---|
1803 | else if (TEST_OPT_PROT) PrintLn(); |
---|
1804 | /*- release temp data------------------------------- -*/ |
---|
1805 | exitBuchMora(strat); |
---|
1806 | /*- polynomials used for HECKE: HC, noether -*/ |
---|
1807 | if (TEST_OPT_FINDET) |
---|
1808 | { |
---|
1809 | if (strat->kHEdge!=NULL) |
---|
1810 | Kstd1_mu=currRing->pFDeg(strat->kHEdge,currRing); |
---|
1811 | else |
---|
1812 | Kstd1_mu=-1; |
---|
1813 | } |
---|
1814 | pDelete(&strat->kHEdge); |
---|
1815 | strat->update = TRUE; //??? |
---|
1816 | strat->lastAxis = 0; //??? |
---|
1817 | pDelete(&strat->kNoether); |
---|
1818 | omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN)); |
---|
1819 | if (TEST_OPT_PROT) messageStat(hilbcount,strat); |
---|
1820 | // if (TEST_OPT_WEIGHTM) |
---|
1821 | // { |
---|
1822 | // pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
1823 | // if (ecartWeights) |
---|
1824 | // { |
---|
1825 | // omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short)); |
---|
1826 | // ecartWeights=NULL; |
---|
1827 | // } |
---|
1828 | // } |
---|
1829 | #ifdef HAVE_RINGS |
---|
1830 | if(nCoeff_is_Ring_Z(currRing->cf)) |
---|
1831 | finalReduceByMon(strat); |
---|
1832 | #endif |
---|
1833 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
1834 | SI_RESTORE_OPT1(save1); |
---|
1835 | idTest(strat->Shdl); |
---|
1836 | return (strat->Shdl); |
---|
1837 | } |
---|
1838 | |
---|
1839 | poly kNF1 (ideal F,ideal Q,poly q, kStrategy strat, int lazyReduce) |
---|
1840 | { |
---|
1841 | assume(q!=NULL); |
---|
1842 | assume(!(idIs0(F)&&(Q==NULL))); |
---|
1843 | |
---|
1844 | // lazy_reduce flags: can be combined by | |
---|
1845 | //#define KSTD_NF_LAZY 1 |
---|
1846 | // do only a reduction of the leading term |
---|
1847 | //#define KSTD_NF_ECART 2 |
---|
1848 | // only local: recude even with bad ecart |
---|
1849 | poly p; |
---|
1850 | int i; |
---|
1851 | int j; |
---|
1852 | int o; |
---|
1853 | LObject h; |
---|
1854 | BITSET save1; |
---|
1855 | SI_SAVE_OPT1(save1); |
---|
1856 | |
---|
1857 | //if ((idIs0(F))&&(Q==NULL)) |
---|
1858 | // return pCopy(q); /*F=0*/ |
---|
1859 | //strat->ak = si_max(idRankFreeModule(F),pMaxComp(q)); |
---|
1860 | /*- creating temp data structures------------------- -*/ |
---|
1861 | strat->kHEdgeFound = (currRing->ppNoether) != NULL; |
---|
1862 | strat->kNoether = pCopy((currRing->ppNoether)); |
---|
1863 | si_opt_1|=Sy_bit(OPT_REDTAIL); |
---|
1864 | si_opt_1&=~Sy_bit(OPT_INTSTRATEGY); |
---|
1865 | if (TEST_OPT_STAIRCASEBOUND |
---|
1866 | && (! TEST_V_DEG_STOP) |
---|
1867 | && (0<Kstd1_deg) |
---|
1868 | && ((!strat->kHEdgeFound) |
---|
1869 | ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg)))) |
---|
1870 | { |
---|
1871 | pDelete(&strat->kNoether); |
---|
1872 | strat->kNoether=pOne(); |
---|
1873 | pSetExp(strat->kNoether,1, Kstd1_deg+1); |
---|
1874 | pSetm(strat->kNoether); |
---|
1875 | strat->kHEdgeFound=TRUE; |
---|
1876 | } |
---|
1877 | initBuchMoraCrit(strat); |
---|
1878 | initBuchMoraPos(strat); |
---|
1879 | initMora(F,strat); |
---|
1880 | strat->enterS = enterSMoraNF; |
---|
1881 | /*- set T -*/ |
---|
1882 | strat->tl = -1; |
---|
1883 | strat->tmax = setmaxT; |
---|
1884 | strat->T = initT(); |
---|
1885 | strat->R = initR(); |
---|
1886 | strat->sevT = initsevT(); |
---|
1887 | /*- set S -*/ |
---|
1888 | strat->sl = -1; |
---|
1889 | /*- init local data struct.-------------------------- -*/ |
---|
1890 | /*Shdl=*/initS(F,Q,strat); |
---|
1891 | if ((strat->ak!=0) |
---|
1892 | && (strat->kHEdgeFound)) |
---|
1893 | { |
---|
1894 | if (strat->ak!=1) |
---|
1895 | { |
---|
1896 | pSetComp(strat->kNoether,1); |
---|
1897 | pSetmComp(strat->kNoether); |
---|
1898 | poly p=pHead(strat->kNoether); |
---|
1899 | pSetComp(p,strat->ak); |
---|
1900 | pSetmComp(p); |
---|
1901 | p=pAdd(strat->kNoether,p); |
---|
1902 | strat->kNoether=pNext(p); |
---|
1903 | p_LmFree(p,currRing); |
---|
1904 | } |
---|
1905 | } |
---|
1906 | if ((lazyReduce & KSTD_NF_LAZY)==0) |
---|
1907 | { |
---|
1908 | for (i=strat->sl; i>=0; i--) |
---|
1909 | pNorm(strat->S[i]); |
---|
1910 | } |
---|
1911 | /*- puts the elements of S also to T -*/ |
---|
1912 | for (i=0; i<=strat->sl; i++) |
---|
1913 | { |
---|
1914 | h.p = strat->S[i]; |
---|
1915 | h.ecart = strat->ecartS[i]; |
---|
1916 | if (strat->sevS[i] == 0) strat->sevS[i] = pGetShortExpVector(h.p); |
---|
1917 | else assume(strat->sevS[i] == pGetShortExpVector(h.p)); |
---|
1918 | h.length = pLength(h.p); |
---|
1919 | h.sev = strat->sevS[i]; |
---|
1920 | h.SetpFDeg(); |
---|
1921 | enterT(h,strat); |
---|
1922 | } |
---|
1923 | #ifdef KDEBUG |
---|
1924 | // kDebugPrint(strat); |
---|
1925 | #endif |
---|
1926 | /*- compute------------------------------------------- -*/ |
---|
1927 | p = pCopy(q); |
---|
1928 | deleteHC(&p,&o,&j,strat); |
---|
1929 | kTest(strat); |
---|
1930 | if (TEST_OPT_PROT) { PrintS("r"); mflush(); } |
---|
1931 | if (BVERBOSE(23)) kDebugPrint(strat); |
---|
1932 | if (p!=NULL) p = redMoraNF(p,strat, lazyReduce & KSTD_NF_ECART); |
---|
1933 | if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
1934 | { |
---|
1935 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
1936 | p = redtail(p,strat->sl,strat); |
---|
1937 | } |
---|
1938 | /*- release temp data------------------------------- -*/ |
---|
1939 | cleanT(strat); |
---|
1940 | assume(strat->L==NULL); /*strat->L unsed */ |
---|
1941 | assume(strat->B==NULL); /*strat->B unused */ |
---|
1942 | omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject)); |
---|
1943 | omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int)); |
---|
1944 | omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long)); |
---|
1945 | omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN)); |
---|
1946 | omFree(strat->sevT); |
---|
1947 | omFree(strat->S_2_R); |
---|
1948 | omFree(strat->R); |
---|
1949 | |
---|
1950 | if ((Q!=NULL)&&(strat->fromQ!=NULL)) |
---|
1951 | { |
---|
1952 | i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16; |
---|
1953 | omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int)); |
---|
1954 | strat->fromQ=NULL; |
---|
1955 | } |
---|
1956 | pDelete(&strat->kHEdge); |
---|
1957 | pDelete(&strat->kNoether); |
---|
1958 | // if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
1959 | // { |
---|
1960 | // pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
1961 | // if (ecartWeights) |
---|
1962 | // { |
---|
1963 | // omFreeSize((ADDRESS *)&ecartWeights,((currRing->N)+1)*sizeof(short)); |
---|
1964 | // ecartWeights=NULL; |
---|
1965 | // } |
---|
1966 | // } |
---|
1967 | idDelete(&strat->Shdl); |
---|
1968 | SI_RESTORE_OPT1(save1); |
---|
1969 | if (TEST_OPT_PROT) PrintLn(); |
---|
1970 | return p; |
---|
1971 | } |
---|
1972 | |
---|
1973 | ideal kNF1 (ideal F,ideal Q,ideal q, kStrategy strat, int lazyReduce) |
---|
1974 | { |
---|
1975 | assume(!idIs0(q)); |
---|
1976 | assume(!(idIs0(F)&&(Q==NULL))); |
---|
1977 | |
---|
1978 | // lazy_reduce flags: can be combined by | |
---|
1979 | //#define KSTD_NF_LAZY 1 |
---|
1980 | // do only a reduction of the leading term |
---|
1981 | //#define KSTD_NF_ECART 2 |
---|
1982 | // only local: recude even with bad ecart |
---|
1983 | poly p; |
---|
1984 | int i; |
---|
1985 | int j; |
---|
1986 | int o; |
---|
1987 | LObject h; |
---|
1988 | ideal res; |
---|
1989 | BITSET save1; |
---|
1990 | SI_SAVE_OPT1(save1); |
---|
1991 | |
---|
1992 | //if (idIs0(q)) return idInit(IDELEMS(q),si_max(q->rank,F->rank)); |
---|
1993 | //if ((idIs0(F))&&(Q==NULL)) |
---|
1994 | // return idCopy(q); /*F=0*/ |
---|
1995 | //strat->ak = si_max(idRankFreeModule(F),idRankFreeModule(q)); |
---|
1996 | /*- creating temp data structures------------------- -*/ |
---|
1997 | strat->kHEdgeFound = (currRing->ppNoether) != NULL; |
---|
1998 | strat->kNoether=pCopy((currRing->ppNoether)); |
---|
1999 | si_opt_1|=Sy_bit(OPT_REDTAIL); |
---|
2000 | if (TEST_OPT_STAIRCASEBOUND |
---|
2001 | && (0<Kstd1_deg) |
---|
2002 | && ((!strat->kHEdgeFound) |
---|
2003 | ||(TEST_OPT_DEGBOUND && (pWTotaldegree(strat->kNoether)<Kstd1_deg)))) |
---|
2004 | { |
---|
2005 | pDelete(&strat->kNoether); |
---|
2006 | strat->kNoether=pOne(); |
---|
2007 | pSetExp(strat->kNoether,1, Kstd1_deg+1); |
---|
2008 | pSetm(strat->kNoether); |
---|
2009 | strat->kHEdgeFound=TRUE; |
---|
2010 | } |
---|
2011 | initBuchMoraCrit(strat); |
---|
2012 | initBuchMoraPos(strat); |
---|
2013 | initMora(F,strat); |
---|
2014 | strat->enterS = enterSMoraNF; |
---|
2015 | /*- set T -*/ |
---|
2016 | strat->tl = -1; |
---|
2017 | strat->tmax = setmaxT; |
---|
2018 | strat->T = initT(); |
---|
2019 | strat->R = initR(); |
---|
2020 | strat->sevT = initsevT(); |
---|
2021 | /*- set S -*/ |
---|
2022 | strat->sl = -1; |
---|
2023 | /*- init local data struct.-------------------------- -*/ |
---|
2024 | /*Shdl=*/initS(F,Q,strat); |
---|
2025 | if ((strat->ak!=0) |
---|
2026 | && (strat->kHEdgeFound)) |
---|
2027 | { |
---|
2028 | if (strat->ak!=1) |
---|
2029 | { |
---|
2030 | pSetComp(strat->kNoether,1); |
---|
2031 | pSetmComp(strat->kNoether); |
---|
2032 | poly p=pHead(strat->kNoether); |
---|
2033 | pSetComp(p,strat->ak); |
---|
2034 | pSetmComp(p); |
---|
2035 | p=pAdd(strat->kNoether,p); |
---|
2036 | strat->kNoether=pNext(p); |
---|
2037 | p_LmFree(p,currRing); |
---|
2038 | } |
---|
2039 | } |
---|
2040 | if (TEST_OPT_INTSTRATEGY && ((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
2041 | { |
---|
2042 | for (i=strat->sl; i>=0; i--) |
---|
2043 | pNorm(strat->S[i]); |
---|
2044 | } |
---|
2045 | /*- compute------------------------------------------- -*/ |
---|
2046 | res=idInit(IDELEMS(q),strat->ak); |
---|
2047 | for (i=0; i<IDELEMS(q); i++) |
---|
2048 | { |
---|
2049 | if (q->m[i]!=NULL) |
---|
2050 | { |
---|
2051 | p = pCopy(q->m[i]); |
---|
2052 | deleteHC(&p,&o,&j,strat); |
---|
2053 | if (p!=NULL) |
---|
2054 | { |
---|
2055 | /*- puts the elements of S also to T -*/ |
---|
2056 | for (j=0; j<=strat->sl; j++) |
---|
2057 | { |
---|
2058 | h.p = strat->S[j]; |
---|
2059 | h.ecart = strat->ecartS[j]; |
---|
2060 | h.pLength = h.length = pLength(h.p); |
---|
2061 | if (strat->sevS[j] == 0) strat->sevS[j] = pGetShortExpVector(h.p); |
---|
2062 | else assume(strat->sevS[j] == pGetShortExpVector(h.p)); |
---|
2063 | h.sev = strat->sevS[j]; |
---|
2064 | h.SetpFDeg(); |
---|
2065 | enterT(h,strat); |
---|
2066 | } |
---|
2067 | if (TEST_OPT_PROT) { PrintS("r"); mflush(); } |
---|
2068 | p = redMoraNF(p,strat, lazyReduce & KSTD_NF_ECART); |
---|
2069 | if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
2070 | { |
---|
2071 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
2072 | p = redtail(p,strat->sl,strat); |
---|
2073 | } |
---|
2074 | cleanT(strat); |
---|
2075 | } |
---|
2076 | res->m[i]=p; |
---|
2077 | } |
---|
2078 | //else |
---|
2079 | // res->m[i]=NULL; |
---|
2080 | } |
---|
2081 | /*- release temp data------------------------------- -*/ |
---|
2082 | assume(strat->L==NULL); /*strat->L unsed */ |
---|
2083 | assume(strat->B==NULL); /*strat->B unused */ |
---|
2084 | omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject)); |
---|
2085 | omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int)); |
---|
2086 | omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long)); |
---|
2087 | omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN)); |
---|
2088 | omFree(strat->sevT); |
---|
2089 | omFree(strat->S_2_R); |
---|
2090 | omFree(strat->R); |
---|
2091 | if ((Q!=NULL)&&(strat->fromQ!=NULL)) |
---|
2092 | { |
---|
2093 | i=((IDELEMS(Q)+IDELEMS(F)+15)/16)*16; |
---|
2094 | omFreeSize((ADDRESS)strat->fromQ,i*sizeof(int)); |
---|
2095 | strat->fromQ=NULL; |
---|
2096 | } |
---|
2097 | pDelete(&strat->kHEdge); |
---|
2098 | pDelete(&strat->kNoether); |
---|
2099 | // if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
2100 | // { |
---|
2101 | // pFDeg=strat->pOrigFDeg; |
---|
2102 | // pLDeg=strat->pOrigLDeg; |
---|
2103 | // if (ecartWeights) |
---|
2104 | // { |
---|
2105 | // omFreeSize((ADDRESS *)&ecartWeights,((currRing->N)+1)*sizeof(short)); |
---|
2106 | // ecartWeights=NULL; |
---|
2107 | // } |
---|
2108 | // } |
---|
2109 | idDelete(&strat->Shdl); |
---|
2110 | SI_RESTORE_OPT1(save1); |
---|
2111 | if (TEST_OPT_PROT) PrintLn(); |
---|
2112 | return res; |
---|
2113 | } |
---|
2114 | |
---|
2115 | intvec * kModW, * kHomW; |
---|
2116 | |
---|
2117 | long kModDeg(poly p, ring r) |
---|
2118 | { |
---|
2119 | long o=p_WDegree(p, r); |
---|
2120 | long i=p_GetComp(p, r); |
---|
2121 | if (i==0) return o; |
---|
2122 | //assume((i>0) && (i<=kModW->length())); |
---|
2123 | if (i<=kModW->length()) |
---|
2124 | return o+(*kModW)[i-1]; |
---|
2125 | return o; |
---|
2126 | } |
---|
2127 | long kHomModDeg(poly p, ring r) |
---|
2128 | { |
---|
2129 | int i; |
---|
2130 | long j=0; |
---|
2131 | |
---|
2132 | for (i=r->N;i>0;i--) |
---|
2133 | j+=p_GetExp(p,i,r)*(*kHomW)[i-1]; |
---|
2134 | if (kModW == NULL) return j; |
---|
2135 | i = p_GetComp(p,r); |
---|
2136 | if (i==0) return j; |
---|
2137 | return j+(*kModW)[i-1]; |
---|
2138 | } |
---|
2139 | |
---|
2140 | ideal kStd(ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp, |
---|
2141 | int newIdeal, intvec *vw, s_poly_proc_t sp) |
---|
2142 | { |
---|
2143 | if(idIs0(F)) |
---|
2144 | return idInit(1,F->rank); |
---|
2145 | |
---|
2146 | ideal r; |
---|
2147 | BOOLEAN b=currRing->pLexOrder,toReset=FALSE; |
---|
2148 | BOOLEAN delete_w=(w==NULL); |
---|
2149 | kStrategy strat=new skStrategy; |
---|
2150 | |
---|
2151 | strat->s_poly=sp; |
---|
2152 | if(!TEST_OPT_RETURN_SB) |
---|
2153 | strat->syzComp = syzComp; |
---|
2154 | if (TEST_OPT_SB_1 |
---|
2155 | #ifdef HAVE_RINGS |
---|
2156 | &&(!rField_is_Ring(currRing)) |
---|
2157 | #endif |
---|
2158 | ) |
---|
2159 | strat->newIdeal = newIdeal; |
---|
2160 | if (rField_has_simple_inverse(currRing)) |
---|
2161 | strat->LazyPass=20; |
---|
2162 | else |
---|
2163 | strat->LazyPass=2; |
---|
2164 | strat->LazyDegree = 1; |
---|
2165 | strat->ak = id_RankFreeModule(F,currRing); |
---|
2166 | strat->kModW=kModW=NULL; |
---|
2167 | strat->kHomW=kHomW=NULL; |
---|
2168 | if (vw != NULL) |
---|
2169 | { |
---|
2170 | currRing->pLexOrder=FALSE; |
---|
2171 | strat->kHomW=kHomW=vw; |
---|
2172 | strat->pOrigFDeg = currRing->pFDeg; |
---|
2173 | strat->pOrigLDeg = currRing->pLDeg; |
---|
2174 | pSetDegProcs(currRing,kHomModDeg); |
---|
2175 | toReset = TRUE; |
---|
2176 | } |
---|
2177 | if (h==testHomog) |
---|
2178 | { |
---|
2179 | if (strat->ak == 0) |
---|
2180 | { |
---|
2181 | h = (tHomog)idHomIdeal(F,Q); |
---|
2182 | w=NULL; |
---|
2183 | } |
---|
2184 | else if (!TEST_OPT_DEGBOUND) |
---|
2185 | { |
---|
2186 | h = (tHomog)idHomModule(F,Q,w); |
---|
2187 | } |
---|
2188 | } |
---|
2189 | currRing->pLexOrder=b; |
---|
2190 | if (h==isHomog) |
---|
2191 | { |
---|
2192 | if (strat->ak > 0 && (w!=NULL) && (*w!=NULL)) |
---|
2193 | { |
---|
2194 | strat->kModW = kModW = *w; |
---|
2195 | if (vw == NULL) |
---|
2196 | { |
---|
2197 | strat->pOrigFDeg = currRing->pFDeg; |
---|
2198 | strat->pOrigLDeg = currRing->pLDeg; |
---|
2199 | pSetDegProcs(currRing,kModDeg); |
---|
2200 | toReset = TRUE; |
---|
2201 | } |
---|
2202 | } |
---|
2203 | currRing->pLexOrder = TRUE; |
---|
2204 | if (hilb==NULL) strat->LazyPass*=2; |
---|
2205 | } |
---|
2206 | strat->homog=h; |
---|
2207 | #ifdef KDEBUG |
---|
2208 | idTest(F); |
---|
2209 | if (Q!=NULL) idTest(Q); |
---|
2210 | |
---|
2211 | #if MYTEST |
---|
2212 | if (TEST_OPT_DEBUG) |
---|
2213 | { |
---|
2214 | PrintS("// kSTD: currRing: "); |
---|
2215 | rWrite(currRing); |
---|
2216 | } |
---|
2217 | #endif |
---|
2218 | |
---|
2219 | #endif |
---|
2220 | #ifdef HAVE_PLURAL |
---|
2221 | if (rIsPluralRing(currRing)) |
---|
2222 | { |
---|
2223 | const BOOLEAN bIsSCA = rIsSCA(currRing) && strat->z2homog; // for Z_2 prod-crit |
---|
2224 | strat->no_prod_crit = ! bIsSCA; |
---|
2225 | if (w!=NULL) |
---|
2226 | r = nc_GB(F, Q, *w, hilb, strat, currRing); |
---|
2227 | else |
---|
2228 | r = nc_GB(F, Q, NULL, hilb, strat, currRing); |
---|
2229 | } |
---|
2230 | else |
---|
2231 | #endif |
---|
2232 | #ifdef HAVE_RINGS |
---|
2233 | if (rField_is_Ring(currRing)) |
---|
2234 | { |
---|
2235 | if(rHasLocalOrMixedOrdering(currRing)) |
---|
2236 | r=mora(F,Q,NULL,hilb,strat); |
---|
2237 | else |
---|
2238 | r=bba(F,Q,NULL,hilb,strat); |
---|
2239 | } |
---|
2240 | else |
---|
2241 | #endif |
---|
2242 | { |
---|
2243 | if (rHasLocalOrMixedOrdering(currRing)) |
---|
2244 | { |
---|
2245 | if (w!=NULL) |
---|
2246 | r=mora(F,Q,*w,hilb,strat); |
---|
2247 | else |
---|
2248 | r=mora(F,Q,NULL,hilb,strat); |
---|
2249 | } |
---|
2250 | else |
---|
2251 | { |
---|
2252 | if (w!=NULL) |
---|
2253 | r=bba(F,Q,*w,hilb,strat); |
---|
2254 | else |
---|
2255 | r=bba(F,Q,NULL,hilb,strat); |
---|
2256 | } |
---|
2257 | } |
---|
2258 | #ifdef KDEBUG |
---|
2259 | idTest(r); |
---|
2260 | #endif |
---|
2261 | if (toReset) |
---|
2262 | { |
---|
2263 | kModW = NULL; |
---|
2264 | pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
2265 | } |
---|
2266 | currRing->pLexOrder = b; |
---|
2267 | //Print("%d reductions canceled \n",strat->cel); |
---|
2268 | HCord=strat->HCord; |
---|
2269 | delete(strat); |
---|
2270 | if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w; |
---|
2271 | return r; |
---|
2272 | } |
---|
2273 | |
---|
2274 | ideal kSba(ideal F, ideal Q, tHomog h,intvec ** w, int sbaOrder, int arri, intvec *hilb,int syzComp, |
---|
2275 | int newIdeal, intvec *vw) |
---|
2276 | { |
---|
2277 | if(idIs0(F)) |
---|
2278 | return idInit(1,F->rank); |
---|
2279 | |
---|
2280 | ideal r; |
---|
2281 | BOOLEAN b=currRing->pLexOrder,toReset=FALSE; |
---|
2282 | BOOLEAN delete_w=(w==NULL); |
---|
2283 | kStrategy strat=new skStrategy; |
---|
2284 | strat->sbaOrder = sbaOrder; |
---|
2285 | if (arri!=0) |
---|
2286 | { |
---|
2287 | strat->rewCrit1 = arriRewDummy; |
---|
2288 | strat->rewCrit2 = arriRewCriterion; |
---|
2289 | strat->rewCrit3 = arriRewCriterionPre; |
---|
2290 | } |
---|
2291 | else |
---|
2292 | { |
---|
2293 | strat->rewCrit1 = faugereRewCriterion; |
---|
2294 | strat->rewCrit2 = faugereRewCriterion; |
---|
2295 | strat->rewCrit3 = faugereRewCriterion; |
---|
2296 | } |
---|
2297 | |
---|
2298 | if(!TEST_OPT_RETURN_SB) |
---|
2299 | strat->syzComp = syzComp; |
---|
2300 | if (TEST_OPT_SB_1) |
---|
2301 | #ifdef HAVE_RINGS |
---|
2302 | if(!rField_is_Ring(currRing)) |
---|
2303 | #endif |
---|
2304 | strat->newIdeal = newIdeal; |
---|
2305 | if (rField_has_simple_inverse(currRing)) |
---|
2306 | strat->LazyPass=20; |
---|
2307 | else |
---|
2308 | strat->LazyPass=2; |
---|
2309 | strat->LazyDegree = 1; |
---|
2310 | strat->enterOnePair=enterOnePairNormal; |
---|
2311 | strat->chainCrit=chainCritNormal; |
---|
2312 | strat->ak = id_RankFreeModule(F,currRing); |
---|
2313 | strat->kModW=kModW=NULL; |
---|
2314 | strat->kHomW=kHomW=NULL; |
---|
2315 | if (vw != NULL) |
---|
2316 | { |
---|
2317 | currRing->pLexOrder=FALSE; |
---|
2318 | strat->kHomW=kHomW=vw; |
---|
2319 | strat->pOrigFDeg = currRing->pFDeg; |
---|
2320 | strat->pOrigLDeg = currRing->pLDeg; |
---|
2321 | pSetDegProcs(currRing,kHomModDeg); |
---|
2322 | toReset = TRUE; |
---|
2323 | } |
---|
2324 | if (h==testHomog) |
---|
2325 | { |
---|
2326 | if (strat->ak == 0) |
---|
2327 | { |
---|
2328 | h = (tHomog)idHomIdeal(F,Q); |
---|
2329 | w=NULL; |
---|
2330 | } |
---|
2331 | else if (!TEST_OPT_DEGBOUND) |
---|
2332 | { |
---|
2333 | h = (tHomog)idHomModule(F,Q,w); |
---|
2334 | } |
---|
2335 | } |
---|
2336 | currRing->pLexOrder=b; |
---|
2337 | if (h==isHomog) |
---|
2338 | { |
---|
2339 | if (strat->ak > 0 && (w!=NULL) && (*w!=NULL)) |
---|
2340 | { |
---|
2341 | strat->kModW = kModW = *w; |
---|
2342 | if (vw == NULL) |
---|
2343 | { |
---|
2344 | strat->pOrigFDeg = currRing->pFDeg; |
---|
2345 | strat->pOrigLDeg = currRing->pLDeg; |
---|
2346 | pSetDegProcs(currRing,kModDeg); |
---|
2347 | toReset = TRUE; |
---|
2348 | } |
---|
2349 | } |
---|
2350 | currRing->pLexOrder = TRUE; |
---|
2351 | if (hilb==NULL) strat->LazyPass*=2; |
---|
2352 | } |
---|
2353 | strat->homog=h; |
---|
2354 | #ifdef KDEBUG |
---|
2355 | idTest(F); |
---|
2356 | idTest(Q); |
---|
2357 | |
---|
2358 | #if MYTEST |
---|
2359 | if (TEST_OPT_DEBUG) |
---|
2360 | { |
---|
2361 | PrintS("// kSTD: currRing: "); |
---|
2362 | rWrite(currRing); |
---|
2363 | } |
---|
2364 | #endif |
---|
2365 | |
---|
2366 | #endif |
---|
2367 | #ifdef HAVE_PLURAL |
---|
2368 | if (rIsPluralRing(currRing)) |
---|
2369 | { |
---|
2370 | const BOOLEAN bIsSCA = rIsSCA(currRing) && strat->z2homog; // for Z_2 prod-crit |
---|
2371 | strat->no_prod_crit = ! bIsSCA; |
---|
2372 | if (w!=NULL) |
---|
2373 | r = nc_GB(F, Q, *w, hilb, strat, currRing); |
---|
2374 | else |
---|
2375 | r = nc_GB(F, Q, NULL, hilb, strat, currRing); |
---|
2376 | } |
---|
2377 | else |
---|
2378 | #endif |
---|
2379 | #ifdef HAVE_RINGS |
---|
2380 | if (rField_is_Ring(currRing)) |
---|
2381 | r=bba(F,Q,NULL,hilb,strat); |
---|
2382 | else |
---|
2383 | #endif |
---|
2384 | { |
---|
2385 | if (rHasLocalOrMixedOrdering(currRing)) |
---|
2386 | { |
---|
2387 | if (w!=NULL) |
---|
2388 | r=mora(F,Q,*w,hilb,strat); |
---|
2389 | else |
---|
2390 | r=mora(F,Q,NULL,hilb,strat); |
---|
2391 | } |
---|
2392 | else |
---|
2393 | { |
---|
2394 | if (w!=NULL) |
---|
2395 | r=sba(F,Q,*w,hilb,strat); |
---|
2396 | else |
---|
2397 | r=sba(F,Q,NULL,hilb,strat); |
---|
2398 | } |
---|
2399 | } |
---|
2400 | #ifdef KDEBUG |
---|
2401 | idTest(r); |
---|
2402 | #endif |
---|
2403 | if (toReset) |
---|
2404 | { |
---|
2405 | kModW = NULL; |
---|
2406 | pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
2407 | } |
---|
2408 | currRing->pLexOrder = b; |
---|
2409 | //Print("%d reductions canceled \n",strat->cel); |
---|
2410 | HCord=strat->HCord; |
---|
2411 | delete(strat); |
---|
2412 | if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w; |
---|
2413 | return r; |
---|
2414 | } |
---|
2415 | |
---|
2416 | #ifdef HAVE_SHIFTBBA |
---|
2417 | ideal kStdShift(ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp, |
---|
2418 | int newIdeal, intvec *vw, int uptodeg, int lV) |
---|
2419 | { |
---|
2420 | ideal r; |
---|
2421 | BOOLEAN b=currRing->pLexOrder,toReset=FALSE; |
---|
2422 | BOOLEAN delete_w=(w==NULL); |
---|
2423 | kStrategy strat=new skStrategy; |
---|
2424 | |
---|
2425 | if(!TEST_OPT_RETURN_SB) |
---|
2426 | strat->syzComp = syzComp; |
---|
2427 | if (TEST_OPT_SB_1) |
---|
2428 | #ifdef HAVE_RINGS |
---|
2429 | if(!rField_is_Ring(currRing)) |
---|
2430 | #endif |
---|
2431 | strat->newIdeal = newIdeal; |
---|
2432 | if (rField_has_simple_inverse(currRing)) |
---|
2433 | strat->LazyPass=20; |
---|
2434 | else |
---|
2435 | strat->LazyPass=2; |
---|
2436 | strat->LazyDegree = 1; |
---|
2437 | strat->ak = id_RankFreeModule(F,currRing); |
---|
2438 | strat->kModW=kModW=NULL; |
---|
2439 | strat->kHomW=kHomW=NULL; |
---|
2440 | if (vw != NULL) |
---|
2441 | { |
---|
2442 | currRing->pLexOrder=FALSE; |
---|
2443 | strat->kHomW=kHomW=vw; |
---|
2444 | strat->pOrigFDeg = currRing->pFDeg; |
---|
2445 | strat->pOrigLDeg = currRing->pLDeg; |
---|
2446 | pSetDegProcs(currRing,kHomModDeg); |
---|
2447 | toReset = TRUE; |
---|
2448 | } |
---|
2449 | if (h==testHomog) |
---|
2450 | { |
---|
2451 | if (strat->ak == 0) |
---|
2452 | { |
---|
2453 | h = (tHomog)idHomIdeal(F,Q); |
---|
2454 | w=NULL; |
---|
2455 | } |
---|
2456 | else if (!TEST_OPT_DEGBOUND) |
---|
2457 | { |
---|
2458 | h = (tHomog)idHomModule(F,Q,w); |
---|
2459 | } |
---|
2460 | } |
---|
2461 | currRing->pLexOrder=b; |
---|
2462 | if (h==isHomog) |
---|
2463 | { |
---|
2464 | if (strat->ak > 0 && (w!=NULL) && (*w!=NULL)) |
---|
2465 | { |
---|
2466 | strat->kModW = kModW = *w; |
---|
2467 | if (vw == NULL) |
---|
2468 | { |
---|
2469 | strat->pOrigFDeg = currRing->pFDeg; |
---|
2470 | strat->pOrigLDeg = currRing->pLDeg; |
---|
2471 | pSetDegProcs(currRing,kModDeg); |
---|
2472 | toReset = TRUE; |
---|
2473 | } |
---|
2474 | } |
---|
2475 | currRing->pLexOrder = TRUE; |
---|
2476 | if (hilb==NULL) strat->LazyPass*=2; |
---|
2477 | } |
---|
2478 | strat->homog=h; |
---|
2479 | #ifdef KDEBUG |
---|
2480 | idTest(F); |
---|
2481 | #endif |
---|
2482 | if (rHasLocalOrMixedOrdering(currRing)) |
---|
2483 | { |
---|
2484 | /* error: no local ord yet with shifts */ |
---|
2485 | Print("No local ordering possible for shifts"); |
---|
2486 | return(NULL); |
---|
2487 | } |
---|
2488 | else |
---|
2489 | { |
---|
2490 | /* global ordering */ |
---|
2491 | if (w!=NULL) |
---|
2492 | r=bbaShift(F,Q,*w,hilb,strat,uptodeg,lV); |
---|
2493 | else |
---|
2494 | r=bbaShift(F,Q,NULL,hilb,strat,uptodeg,lV); |
---|
2495 | } |
---|
2496 | #ifdef KDEBUG |
---|
2497 | idTest(r); |
---|
2498 | #endif |
---|
2499 | if (toReset) |
---|
2500 | { |
---|
2501 | kModW = NULL; |
---|
2502 | pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
2503 | } |
---|
2504 | currRing->pLexOrder = b; |
---|
2505 | //Print("%d reductions canceled \n",strat->cel); |
---|
2506 | HCord=strat->HCord; |
---|
2507 | delete(strat); |
---|
2508 | if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w; |
---|
2509 | return r; |
---|
2510 | } |
---|
2511 | #endif |
---|
2512 | |
---|
2513 | //############################################################## |
---|
2514 | //############################################################## |
---|
2515 | //############################################################## |
---|
2516 | //############################################################## |
---|
2517 | //############################################################## |
---|
2518 | |
---|
2519 | ideal kMin_std(ideal F, ideal Q, tHomog h,intvec ** w, ideal &M, intvec *hilb, |
---|
2520 | int syzComp, int reduced) |
---|
2521 | { |
---|
2522 | if(idIs0(F)) |
---|
2523 | { |
---|
2524 | M=idInit(1,F->rank); |
---|
2525 | return idInit(1,F->rank); |
---|
2526 | } |
---|
2527 | #ifdef HAVE_RINGS |
---|
2528 | if(rField_is_Ring(currRing)) |
---|
2529 | { |
---|
2530 | ideal sb; |
---|
2531 | sb = kStd(F, Q, h, w, hilb); |
---|
2532 | idSkipZeroes(sb); |
---|
2533 | if(IDELEMS(sb) <= IDELEMS(F)) |
---|
2534 | { |
---|
2535 | M = idCopy(sb); |
---|
2536 | idSkipZeroes(M); |
---|
2537 | return(sb); |
---|
2538 | } |
---|
2539 | else |
---|
2540 | { |
---|
2541 | M = idCopy(F); |
---|
2542 | idSkipZeroes(M); |
---|
2543 | return(sb); |
---|
2544 | } |
---|
2545 | } |
---|
2546 | #endif |
---|
2547 | ideal r=NULL; |
---|
2548 | int Kstd1_OldDeg = Kstd1_deg,i; |
---|
2549 | intvec* temp_w=NULL; |
---|
2550 | BOOLEAN b=currRing->pLexOrder,toReset=FALSE; |
---|
2551 | BOOLEAN delete_w=(w==NULL); |
---|
2552 | BOOLEAN oldDegBound=TEST_OPT_DEGBOUND; |
---|
2553 | kStrategy strat=new skStrategy; |
---|
2554 | |
---|
2555 | if(!TEST_OPT_RETURN_SB) |
---|
2556 | strat->syzComp = syzComp; |
---|
2557 | if (rField_has_simple_inverse(currRing)) |
---|
2558 | strat->LazyPass=20; |
---|
2559 | else |
---|
2560 | strat->LazyPass=2; |
---|
2561 | strat->LazyDegree = 1; |
---|
2562 | strat->minim=(reduced % 2)+1; |
---|
2563 | strat->ak = id_RankFreeModule(F,currRing); |
---|
2564 | if (delete_w) |
---|
2565 | { |
---|
2566 | temp_w=new intvec((strat->ak)+1); |
---|
2567 | w = &temp_w; |
---|
2568 | } |
---|
2569 | if (h==testHomog) |
---|
2570 | { |
---|
2571 | if (strat->ak == 0) |
---|
2572 | { |
---|
2573 | h = (tHomog)idHomIdeal(F,Q); |
---|
2574 | w=NULL; |
---|
2575 | } |
---|
2576 | else |
---|
2577 | { |
---|
2578 | h = (tHomog)idHomModule(F,Q,w); |
---|
2579 | } |
---|
2580 | } |
---|
2581 | if (h==isHomog) |
---|
2582 | { |
---|
2583 | if (strat->ak > 0 && (w!=NULL) && (*w!=NULL)) |
---|
2584 | { |
---|
2585 | kModW = *w; |
---|
2586 | strat->kModW = *w; |
---|
2587 | assume(currRing->pFDeg != NULL && currRing->pLDeg != NULL); |
---|
2588 | strat->pOrigFDeg = currRing->pFDeg; |
---|
2589 | strat->pOrigLDeg = currRing->pLDeg; |
---|
2590 | pSetDegProcs(currRing,kModDeg); |
---|
2591 | |
---|
2592 | toReset = TRUE; |
---|
2593 | if (reduced>1) |
---|
2594 | { |
---|
2595 | Kstd1_OldDeg=Kstd1_deg; |
---|
2596 | Kstd1_deg = -1; |
---|
2597 | for (i=IDELEMS(F)-1;i>=0;i--) |
---|
2598 | { |
---|
2599 | if ((F->m[i]!=NULL) && (currRing->pFDeg(F->m[i],currRing)>=Kstd1_deg)) |
---|
2600 | Kstd1_deg = currRing->pFDeg(F->m[i],currRing)+1; |
---|
2601 | } |
---|
2602 | } |
---|
2603 | } |
---|
2604 | currRing->pLexOrder = TRUE; |
---|
2605 | strat->LazyPass*=2; |
---|
2606 | } |
---|
2607 | strat->homog=h; |
---|
2608 | if (rHasLocalOrMixedOrdering(currRing)) |
---|
2609 | { |
---|
2610 | if (w!=NULL) |
---|
2611 | r=mora(F,Q,*w,hilb,strat); |
---|
2612 | else |
---|
2613 | r=mora(F,Q,NULL,hilb,strat); |
---|
2614 | } |
---|
2615 | else |
---|
2616 | { |
---|
2617 | if (w!=NULL) |
---|
2618 | r=bba(F,Q,*w,hilb,strat); |
---|
2619 | else |
---|
2620 | r=bba(F,Q,NULL,hilb,strat); |
---|
2621 | } |
---|
2622 | #ifdef KDEBUG |
---|
2623 | { |
---|
2624 | int i; |
---|
2625 | for (i=IDELEMS(r)-1; i>=0; i--) pTest(r->m[i]); |
---|
2626 | } |
---|
2627 | #endif |
---|
2628 | idSkipZeroes(r); |
---|
2629 | if (toReset) |
---|
2630 | { |
---|
2631 | pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
2632 | kModW = NULL; |
---|
2633 | } |
---|
2634 | currRing->pLexOrder = b; |
---|
2635 | HCord=strat->HCord; |
---|
2636 | if ((delete_w)&&(temp_w!=NULL)) delete temp_w; |
---|
2637 | if ((IDELEMS(r)==1) && (r->m[0]!=NULL) && pIsConstant(r->m[0]) && (strat->ak==0)) |
---|
2638 | { |
---|
2639 | M=idInit(1,F->rank); |
---|
2640 | M->m[0]=pOne(); |
---|
2641 | //if (strat->ak!=0) { pSetComp(M->m[0],strat->ak); pSetmComp(M->m[0]); } |
---|
2642 | if (strat->M!=NULL) idDelete(&strat->M); |
---|
2643 | } |
---|
2644 | else if (strat->M==NULL) |
---|
2645 | { |
---|
2646 | M=idInit(1,F->rank); |
---|
2647 | Warn("no minimal generating set computed"); |
---|
2648 | } |
---|
2649 | else |
---|
2650 | { |
---|
2651 | idSkipZeroes(strat->M); |
---|
2652 | M=strat->M; |
---|
2653 | } |
---|
2654 | delete(strat); |
---|
2655 | if (reduced>2) |
---|
2656 | { |
---|
2657 | Kstd1_deg=Kstd1_OldDeg; |
---|
2658 | if (!oldDegBound) |
---|
2659 | si_opt_1 &= ~Sy_bit(OPT_DEGBOUND); |
---|
2660 | } |
---|
2661 | else |
---|
2662 | { |
---|
2663 | if (IDELEMS(M)>IDELEMS(r)) { |
---|
2664 | idDelete(&M); |
---|
2665 | M=idCopy(r); } |
---|
2666 | } |
---|
2667 | return r; |
---|
2668 | } |
---|
2669 | |
---|
2670 | poly kNF(ideal F, ideal Q, poly p,int syzComp, int lazyReduce) |
---|
2671 | { |
---|
2672 | if (p==NULL) |
---|
2673 | return NULL; |
---|
2674 | |
---|
2675 | poly pp = p; |
---|
2676 | |
---|
2677 | #ifdef HAVE_PLURAL |
---|
2678 | if(rIsSCA(currRing)) |
---|
2679 | { |
---|
2680 | const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing); |
---|
2681 | const unsigned int m_iLastAltVar = scaLastAltVar(currRing); |
---|
2682 | pp = p_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing); |
---|
2683 | |
---|
2684 | if(Q == currRing->qideal) |
---|
2685 | Q = SCAQuotient(currRing); |
---|
2686 | } |
---|
2687 | #endif |
---|
2688 | |
---|
2689 | if ((idIs0(F))&&(Q==NULL)) |
---|
2690 | { |
---|
2691 | #ifdef HAVE_PLURAL |
---|
2692 | if(p != pp) |
---|
2693 | return pp; |
---|
2694 | #endif |
---|
2695 | return pCopy(p); /*F+Q=0*/ |
---|
2696 | } |
---|
2697 | |
---|
2698 | kStrategy strat=new skStrategy; |
---|
2699 | strat->syzComp = syzComp; |
---|
2700 | strat->ak = si_max(id_RankFreeModule(F,currRing),pMaxComp(p)); |
---|
2701 | poly res; |
---|
2702 | |
---|
2703 | if (rHasLocalOrMixedOrdering(currRing)) |
---|
2704 | res=kNF1(F,Q,pp,strat,lazyReduce); |
---|
2705 | else |
---|
2706 | res=kNF2(F,Q,pp,strat,lazyReduce); |
---|
2707 | delete(strat); |
---|
2708 | |
---|
2709 | #ifdef HAVE_PLURAL |
---|
2710 | if(pp != p) |
---|
2711 | p_Delete(&pp, currRing); |
---|
2712 | #endif |
---|
2713 | return res; |
---|
2714 | } |
---|
2715 | |
---|
2716 | ideal kNF(ideal F, ideal Q, ideal p,int syzComp,int lazyReduce) |
---|
2717 | { |
---|
2718 | ideal res; |
---|
2719 | if (TEST_OPT_PROT) |
---|
2720 | { |
---|
2721 | Print("(S:%d)",IDELEMS(p));mflush(); |
---|
2722 | } |
---|
2723 | if (idIs0(p)) |
---|
2724 | return idInit(IDELEMS(p),si_max(p->rank,F->rank)); |
---|
2725 | |
---|
2726 | ideal pp = p; |
---|
2727 | #ifdef HAVE_PLURAL |
---|
2728 | if(rIsSCA(currRing)) |
---|
2729 | { |
---|
2730 | const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing); |
---|
2731 | const unsigned int m_iLastAltVar = scaLastAltVar(currRing); |
---|
2732 | pp = id_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing, false); |
---|
2733 | |
---|
2734 | if(Q == currRing->qideal) |
---|
2735 | Q = SCAQuotient(currRing); |
---|
2736 | } |
---|
2737 | #endif |
---|
2738 | |
---|
2739 | if ((idIs0(F))&&(Q==NULL)) |
---|
2740 | { |
---|
2741 | #ifdef HAVE_PLURAL |
---|
2742 | if(p != pp) |
---|
2743 | return pp; |
---|
2744 | #endif |
---|
2745 | return idCopy(p); /*F+Q=0*/ |
---|
2746 | } |
---|
2747 | |
---|
2748 | kStrategy strat=new skStrategy; |
---|
2749 | strat->syzComp = syzComp; |
---|
2750 | strat->ak = si_max(id_RankFreeModule(F,currRing),id_RankFreeModule(p,currRing)); |
---|
2751 | if (strat->ak>0) // only for module case, see Tst/Short/bug_reduce.tst |
---|
2752 | { |
---|
2753 | strat->ak = si_max(strat->ak,(int)F->rank); |
---|
2754 | } |
---|
2755 | |
---|
2756 | if (rHasLocalOrMixedOrdering(currRing)) |
---|
2757 | res=kNF1(F,Q,pp,strat,lazyReduce); |
---|
2758 | else |
---|
2759 | res=kNF2(F,Q,pp,strat,lazyReduce); |
---|
2760 | delete(strat); |
---|
2761 | |
---|
2762 | #ifdef HAVE_PLURAL |
---|
2763 | if(pp != p) |
---|
2764 | id_Delete(&pp, currRing); |
---|
2765 | #endif |
---|
2766 | |
---|
2767 | return res; |
---|
2768 | } |
---|
2769 | |
---|
2770 | poly k_NF (ideal F, ideal Q, poly p,int syzComp, int lazyReduce, const ring _currRing) |
---|
2771 | { |
---|
2772 | const ring save = currRing; |
---|
2773 | if( currRing != _currRing ) rChangeCurrRing(_currRing); |
---|
2774 | poly ret = kNF(F, Q, p, syzComp, lazyReduce); |
---|
2775 | if( currRing != save ) rChangeCurrRing(save); |
---|
2776 | return ret; |
---|
2777 | } |
---|
2778 | |
---|
2779 | /*2 |
---|
2780 | *interreduces F |
---|
2781 | */ |
---|
2782 | // old version |
---|
2783 | ideal kInterRedOld (ideal F, ideal Q) |
---|
2784 | { |
---|
2785 | int j; |
---|
2786 | kStrategy strat = new skStrategy; |
---|
2787 | |
---|
2788 | ideal tempF = F; |
---|
2789 | ideal tempQ = Q; |
---|
2790 | |
---|
2791 | #ifdef HAVE_PLURAL |
---|
2792 | if(rIsSCA(currRing)) |
---|
2793 | { |
---|
2794 | const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing); |
---|
2795 | const unsigned int m_iLastAltVar = scaLastAltVar(currRing); |
---|
2796 | tempF = id_KillSquares(F, m_iFirstAltVar, m_iLastAltVar, currRing); |
---|
2797 | |
---|
2798 | // this should be done on the upper level!!! : |
---|
2799 | // tempQ = SCAQuotient(currRing); |
---|
2800 | |
---|
2801 | if(Q == currRing->qideal) |
---|
2802 | tempQ = SCAQuotient(currRing); |
---|
2803 | } |
---|
2804 | #endif |
---|
2805 | |
---|
2806 | // if (TEST_OPT_PROT) |
---|
2807 | // { |
---|
2808 | // writeTime("start InterRed:"); |
---|
2809 | // mflush(); |
---|
2810 | // } |
---|
2811 | //strat->syzComp = 0; |
---|
2812 | strat->kHEdgeFound = (currRing->ppNoether) != NULL; |
---|
2813 | strat->kNoether=pCopy((currRing->ppNoether)); |
---|
2814 | strat->ak = id_RankFreeModule(tempF,currRing); |
---|
2815 | initBuchMoraCrit(strat); |
---|
2816 | strat->NotUsedAxis = (BOOLEAN *)omAlloc(((currRing->N)+1)*sizeof(BOOLEAN)); |
---|
2817 | for (j=(currRing->N); j>0; j--) strat->NotUsedAxis[j] = TRUE; |
---|
2818 | strat->enterS = enterSBba; |
---|
2819 | strat->posInT = posInT17; |
---|
2820 | strat->initEcart = initEcartNormal; |
---|
2821 | strat->sl = -1; |
---|
2822 | strat->tl = -1; |
---|
2823 | strat->tmax = setmaxT; |
---|
2824 | strat->T = initT(); |
---|
2825 | strat->R = initR(); |
---|
2826 | strat->sevT = initsevT(); |
---|
2827 | if (rHasLocalOrMixedOrdering(currRing)) strat->honey = TRUE; |
---|
2828 | initS(tempF, tempQ, strat); |
---|
2829 | if (TEST_OPT_REDSB) |
---|
2830 | strat->noTailReduction=FALSE; |
---|
2831 | updateS(TRUE,strat); |
---|
2832 | if (TEST_OPT_REDSB && TEST_OPT_INTSTRATEGY) |
---|
2833 | completeReduce(strat); |
---|
2834 | //else if (TEST_OPT_PROT) PrintLn(); |
---|
2835 | pDelete(&strat->kHEdge); |
---|
2836 | omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject)); |
---|
2837 | omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int)); |
---|
2838 | omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long)); |
---|
2839 | omFreeSize((ADDRESS)strat->NotUsedAxis,((currRing->N)+1)*sizeof(BOOLEAN)); |
---|
2840 | omfree(strat->sevT); |
---|
2841 | omfree(strat->S_2_R); |
---|
2842 | omfree(strat->R); |
---|
2843 | |
---|
2844 | if (strat->fromQ) |
---|
2845 | { |
---|
2846 | for (j=IDELEMS(strat->Shdl)-1;j>=0;j--) |
---|
2847 | { |
---|
2848 | if(strat->fromQ[j]) pDelete(&strat->Shdl->m[j]); |
---|
2849 | } |
---|
2850 | omFreeSize((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int)); |
---|
2851 | } |
---|
2852 | // if (TEST_OPT_PROT) |
---|
2853 | // { |
---|
2854 | // writeTime("end Interred:"); |
---|
2855 | // mflush(); |
---|
2856 | // } |
---|
2857 | ideal shdl=strat->Shdl; |
---|
2858 | idSkipZeroes(shdl); |
---|
2859 | if (strat->fromQ) |
---|
2860 | { |
---|
2861 | strat->fromQ=NULL; |
---|
2862 | ideal res=kInterRed(shdl,NULL); |
---|
2863 | idDelete(&shdl); |
---|
2864 | shdl=res; |
---|
2865 | } |
---|
2866 | delete(strat); |
---|
2867 | #ifdef HAVE_PLURAL |
---|
2868 | if( tempF != F ) |
---|
2869 | id_Delete( &tempF, currRing); |
---|
2870 | #endif |
---|
2871 | return shdl; |
---|
2872 | } |
---|
2873 | // new version |
---|
2874 | ideal kInterRedBba (ideal F, ideal Q, int &need_retry) |
---|
2875 | { |
---|
2876 | need_retry=0; |
---|
2877 | int red_result = 1; |
---|
2878 | int olddeg,reduc; |
---|
2879 | BOOLEAN withT = FALSE; |
---|
2880 | // BOOLEAN toReset=FALSE; |
---|
2881 | kStrategy strat=new skStrategy; |
---|
2882 | tHomog h; |
---|
2883 | intvec * w=NULL; |
---|
2884 | |
---|
2885 | if (rField_has_simple_inverse(currRing)) |
---|
2886 | strat->LazyPass=20; |
---|
2887 | else |
---|
2888 | strat->LazyPass=2; |
---|
2889 | strat->LazyDegree = 1; |
---|
2890 | strat->ak = id_RankFreeModule(F,currRing); |
---|
2891 | strat->syzComp = strat->ak; |
---|
2892 | strat->kModW=kModW=NULL; |
---|
2893 | strat->kHomW=kHomW=NULL; |
---|
2894 | if (strat->ak == 0) |
---|
2895 | { |
---|
2896 | h = (tHomog)idHomIdeal(F,Q); |
---|
2897 | w=NULL; |
---|
2898 | } |
---|
2899 | else if (!TEST_OPT_DEGBOUND) |
---|
2900 | { |
---|
2901 | h = (tHomog)idHomModule(F,Q,&w); |
---|
2902 | } |
---|
2903 | if (h==isHomog) |
---|
2904 | { |
---|
2905 | if (strat->ak > 0 && (w!=NULL) && (w!=NULL)) |
---|
2906 | { |
---|
2907 | strat->kModW = kModW = w; |
---|
2908 | strat->pOrigFDeg = currRing->pFDeg; |
---|
2909 | strat->pOrigLDeg = currRing->pLDeg; |
---|
2910 | pSetDegProcs(currRing,kModDeg); |
---|
2911 | // toReset = TRUE; |
---|
2912 | } |
---|
2913 | strat->LazyPass*=2; |
---|
2914 | } |
---|
2915 | strat->homog=h; |
---|
2916 | #ifdef KDEBUG |
---|
2917 | idTest(F); |
---|
2918 | #endif |
---|
2919 | |
---|
2920 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
2921 | initBuchMoraPos(strat); |
---|
2922 | initBba(F,strat); |
---|
2923 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
2924 | strat->posInL=posInL0; /* ord according pComp */ |
---|
2925 | |
---|
2926 | /*Shdl=*/initBuchMora(F, Q, strat); |
---|
2927 | reduc = olddeg = 0; |
---|
2928 | |
---|
2929 | #ifndef NO_BUCKETS |
---|
2930 | if (!TEST_OPT_NOT_BUCKETS) |
---|
2931 | strat->use_buckets = 1; |
---|
2932 | #endif |
---|
2933 | |
---|
2934 | // redtailBBa against T for inhomogenous input |
---|
2935 | if (!TEST_OPT_OLDSTD) |
---|
2936 | withT = ! strat->homog; |
---|
2937 | |
---|
2938 | // strat->posInT = posInT_pLength; |
---|
2939 | kTest_TS(strat); |
---|
2940 | |
---|
2941 | #ifdef HAVE_TAIL_RING |
---|
2942 | kStratInitChangeTailRing(strat); |
---|
2943 | #endif |
---|
2944 | |
---|
2945 | /* compute------------------------------------------------------- */ |
---|
2946 | while (strat->Ll >= 0) |
---|
2947 | { |
---|
2948 | #ifdef KDEBUG |
---|
2949 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
2950 | #endif |
---|
2951 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
2952 | /* picks the last element from the lazyset L */ |
---|
2953 | strat->P = strat->L[strat->Ll]; |
---|
2954 | strat->Ll--; |
---|
2955 | |
---|
2956 | if (strat->P.p1 == NULL) |
---|
2957 | { |
---|
2958 | // for input polys, prepare reduction |
---|
2959 | strat->P.PrepareRed(strat->use_buckets); |
---|
2960 | } |
---|
2961 | |
---|
2962 | if (strat->P.p == NULL && strat->P.t_p == NULL) |
---|
2963 | { |
---|
2964 | red_result = 0; |
---|
2965 | } |
---|
2966 | else |
---|
2967 | { |
---|
2968 | if (TEST_OPT_PROT) |
---|
2969 | message(strat->P.pFDeg(), |
---|
2970 | &olddeg,&reduc,strat, red_result); |
---|
2971 | |
---|
2972 | /* reduction of the element chosen from L */ |
---|
2973 | red_result = strat->red(&strat->P,strat); |
---|
2974 | } |
---|
2975 | |
---|
2976 | // reduction to non-zero new poly |
---|
2977 | if (red_result == 1) |
---|
2978 | { |
---|
2979 | /* statistic */ |
---|
2980 | if (TEST_OPT_PROT) PrintS("s"); |
---|
2981 | |
---|
2982 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
2983 | strat->P.GetP(strat->lmBin); |
---|
2984 | |
---|
2985 | int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
2986 | |
---|
2987 | // reduce the tail and normalize poly |
---|
2988 | // in the ring case we cannot expect LC(f) = 1, |
---|
2989 | // therefore we call pContent instead of pNorm |
---|
2990 | if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing))) |
---|
2991 | { |
---|
2992 | strat->P.pCleardenom(); |
---|
2993 | if (0) |
---|
2994 | //if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
2995 | { |
---|
2996 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
2997 | strat->P.pCleardenom(); |
---|
2998 | } |
---|
2999 | } |
---|
3000 | else |
---|
3001 | { |
---|
3002 | strat->P.pNorm(); |
---|
3003 | if (0) |
---|
3004 | //if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
3005 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
3006 | } |
---|
3007 | |
---|
3008 | #ifdef KDEBUG |
---|
3009 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
3010 | #endif |
---|
3011 | |
---|
3012 | // enter into S, L, and T |
---|
3013 | if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp)) |
---|
3014 | { |
---|
3015 | enterT(strat->P, strat); |
---|
3016 | // posInS only depends on the leading term |
---|
3017 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
3018 | |
---|
3019 | if (pos<strat->sl) |
---|
3020 | { |
---|
3021 | need_retry++; |
---|
3022 | // move all "larger" elements fromS to L |
---|
3023 | // remove them from T |
---|
3024 | int ii=pos+1; |
---|
3025 | for(;ii<=strat->sl;ii++) |
---|
3026 | { |
---|
3027 | LObject h; |
---|
3028 | memset(&h,0,sizeof(h)); |
---|
3029 | h.tailRing=strat->tailRing; |
---|
3030 | h.p=strat->S[ii]; strat->S[ii]=NULL; |
---|
3031 | strat->initEcart(&h); |
---|
3032 | h.sev=strat->sevS[ii]; |
---|
3033 | int jj=strat->tl; |
---|
3034 | while (jj>=0) |
---|
3035 | { |
---|
3036 | if (strat->T[jj].p==h.p) |
---|
3037 | { |
---|
3038 | strat->T[jj].p=NULL; |
---|
3039 | if (jj<strat->tl) |
---|
3040 | { |
---|
3041 | memmove(&(strat->T[jj]),&(strat->T[jj+1]), |
---|
3042 | (strat->tl-jj)*sizeof(strat->T[jj])); |
---|
3043 | memmove(&(strat->sevT[jj]),&(strat->sevT[jj+1]), |
---|
3044 | (strat->tl-jj)*sizeof(strat->sevT[jj])); |
---|
3045 | } |
---|
3046 | strat->tl--; |
---|
3047 | break; |
---|
3048 | } |
---|
3049 | jj--; |
---|
3050 | } |
---|
3051 | int lpos=strat->posInL(strat->L,strat->Ll,&h,strat); |
---|
3052 | enterL(&strat->L,&strat->Ll,&strat->Lmax,h,lpos); |
---|
3053 | #ifdef KDEBUG |
---|
3054 | if (TEST_OPT_DEBUG) |
---|
3055 | { |
---|
3056 | Print("move S[%d] -> L[%d]: ",ii,pos); |
---|
3057 | p_wrp(h.p,currRing, strat->tailRing); |
---|
3058 | PrintLn(); |
---|
3059 | } |
---|
3060 | #endif |
---|
3061 | } |
---|
3062 | if (strat->fromQ!=NULL) |
---|
3063 | { |
---|
3064 | for(ii=pos+1;ii<=strat->sl;ii++) strat->fromQ[ii]=0; |
---|
3065 | } |
---|
3066 | strat->sl=pos; |
---|
3067 | } |
---|
3068 | } |
---|
3069 | else |
---|
3070 | { |
---|
3071 | // clean P |
---|
3072 | } |
---|
3073 | if (strat->P.lcm!=NULL) |
---|
3074 | #ifdef HAVE_RINGS |
---|
3075 | pLmDelete(strat->P.lcm); |
---|
3076 | #else |
---|
3077 | pLmFree(strat->P.lcm); |
---|
3078 | #endif |
---|
3079 | } |
---|
3080 | |
---|
3081 | #ifdef KDEBUG |
---|
3082 | if (TEST_OPT_DEBUG) |
---|
3083 | { |
---|
3084 | messageSets(strat); |
---|
3085 | } |
---|
3086 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
3087 | #endif |
---|
3088 | //kTest_TS(strat);: i_r out of sync in kInterRedBba, but not used! |
---|
3089 | } |
---|
3090 | #ifdef KDEBUG |
---|
3091 | //if (TEST_OPT_DEBUG) messageSets(strat); |
---|
3092 | #endif |
---|
3093 | /* complete reduction of the standard basis--------- */ |
---|
3094 | |
---|
3095 | if((need_retry<=0) && (TEST_OPT_REDSB)) |
---|
3096 | { |
---|
3097 | completeReduce(strat); |
---|
3098 | #ifdef HAVE_TAIL_RING |
---|
3099 | if (strat->completeReduce_retry) |
---|
3100 | { |
---|
3101 | // completeReduce needed larger exponents, retry |
---|
3102 | // to reduce with S (instead of T) |
---|
3103 | // and in currRing (instead of strat->tailRing) |
---|
3104 | cleanT(strat);strat->tailRing=currRing; |
---|
3105 | int i; |
---|
3106 | for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1; |
---|
3107 | completeReduce(strat); |
---|
3108 | } |
---|
3109 | #endif |
---|
3110 | } |
---|
3111 | else if (TEST_OPT_PROT) PrintLn(); |
---|
3112 | |
---|
3113 | /* release temp data-------------------------------- */ |
---|
3114 | exitBuchMora(strat); |
---|
3115 | // if (TEST_OPT_WEIGHTM) |
---|
3116 | // { |
---|
3117 | // pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg); |
---|
3118 | // if (ecartWeights) |
---|
3119 | // { |
---|
3120 | // omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short)); |
---|
3121 | // ecartWeights=NULL; |
---|
3122 | // } |
---|
3123 | // } |
---|
3124 | //if (TEST_OPT_PROT) messageStat(0/*hilbcount*/,strat); |
---|
3125 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
3126 | ideal res=strat->Shdl; |
---|
3127 | strat->Shdl=NULL; |
---|
3128 | delete strat; |
---|
3129 | if (w!=NULL) delete w; |
---|
3130 | return res; |
---|
3131 | } |
---|
3132 | ideal kInterRed (ideal F, ideal Q) |
---|
3133 | { |
---|
3134 | #ifdef HAVE_PLURAL |
---|
3135 | if(rIsPluralRing(currRing)) return kInterRedOld(F,Q); |
---|
3136 | #endif |
---|
3137 | if ((rHasLocalOrMixedOrdering(currRing))|| (rField_is_numeric(currRing)) |
---|
3138 | #ifdef HAVE_RINGS |
---|
3139 | ||(rField_is_Ring(currRing)) |
---|
3140 | #endif |
---|
3141 | ) |
---|
3142 | return kInterRedOld(F,Q); |
---|
3143 | |
---|
3144 | //return kInterRedOld(F,Q); |
---|
3145 | |
---|
3146 | BITSET save1; |
---|
3147 | SI_SAVE_OPT1(save1); |
---|
3148 | //si_opt_1|=Sy_bit(OPT_NOT_SUGAR); |
---|
3149 | si_opt_1|=Sy_bit(OPT_REDTHROUGH); |
---|
3150 | //si_opt_1&= ~Sy_bit(OPT_REDTAIL); |
---|
3151 | //si_opt_1&= ~Sy_bit(OPT_REDSB); |
---|
3152 | //extern char * showOption() ; |
---|
3153 | //Print("%s\n",showOption()); |
---|
3154 | |
---|
3155 | int need_retry; |
---|
3156 | int counter=3; |
---|
3157 | ideal res, res1; |
---|
3158 | int elems; |
---|
3159 | ideal null=NULL; |
---|
3160 | if ((Q==NULL) || (!TEST_OPT_REDSB)) |
---|
3161 | { |
---|
3162 | elems=idElem(F); |
---|
3163 | res=kInterRedBba(F,Q,need_retry); |
---|
3164 | } |
---|
3165 | else |
---|
3166 | { |
---|
3167 | ideal FF=idSimpleAdd(F,Q); |
---|
3168 | res=kInterRedBba(FF,NULL,need_retry); |
---|
3169 | idDelete(&FF); |
---|
3170 | null=idInit(1,1); |
---|
3171 | if (need_retry) |
---|
3172 | res1=kNF(null,Q,res,0,KSTD_NF_LAZY); |
---|
3173 | else |
---|
3174 | res1=kNF(null,Q,res); |
---|
3175 | idDelete(&res); |
---|
3176 | res=res1; |
---|
3177 | need_retry=1; |
---|
3178 | } |
---|
3179 | if (idElem(res)<=1) need_retry=0; |
---|
3180 | while (need_retry && (counter>0)) |
---|
3181 | { |
---|
3182 | #ifdef KDEBUG |
---|
3183 | if (TEST_OPT_DEBUG) { Print("retry counter %d\n",counter); } |
---|
3184 | #endif |
---|
3185 | res1=kInterRedBba(res,Q,need_retry); |
---|
3186 | int new_elems=idElem(res1); |
---|
3187 | counter -= (new_elems >= elems); |
---|
3188 | elems = new_elems; |
---|
3189 | idDelete(&res); |
---|
3190 | if (idElem(res1)<=1) need_retry=0; |
---|
3191 | if ((Q!=NULL) && (TEST_OPT_REDSB)) |
---|
3192 | { |
---|
3193 | if (need_retry) |
---|
3194 | res=kNF(null,Q,res1,0,KSTD_NF_LAZY); |
---|
3195 | else |
---|
3196 | res=kNF(null,Q,res1); |
---|
3197 | idDelete(&res1); |
---|
3198 | } |
---|
3199 | else |
---|
3200 | res = res1; |
---|
3201 | if (idElem(res)<=1) need_retry=0; |
---|
3202 | } |
---|
3203 | if (null!=NULL) idDelete(&null); |
---|
3204 | SI_RESTORE_OPT1(save1); |
---|
3205 | idSkipZeroes(res); |
---|
3206 | return res; |
---|
3207 | } |
---|
3208 | |
---|
3209 | // returns TRUE if mora should use buckets, false otherwise |
---|
3210 | static BOOLEAN kMoraUseBucket(kStrategy strat) |
---|
3211 | { |
---|
3212 | #ifdef MORA_USE_BUCKETS |
---|
3213 | if (TEST_OPT_NOT_BUCKETS) |
---|
3214 | return FALSE; |
---|
3215 | if (strat->red == redFirst) |
---|
3216 | { |
---|
3217 | #ifdef NO_LDEG |
---|
3218 | if (strat->syzComp==0) |
---|
3219 | return TRUE; |
---|
3220 | #else |
---|
3221 | if ((strat->homog || strat->honey) && (strat->syzComp==0)) |
---|
3222 | return TRUE; |
---|
3223 | #endif |
---|
3224 | } |
---|
3225 | else |
---|
3226 | { |
---|
3227 | assume(strat->red == redEcart || strat->red == redRiloc); |
---|
3228 | if (strat->honey && (strat->syzComp==0)) |
---|
3229 | return TRUE; |
---|
3230 | } |
---|
3231 | #endif |
---|
3232 | return FALSE; |
---|
3233 | } |
---|