1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT - Kernel: alg. of Buchberger |
---|
6 | */ |
---|
7 | |
---|
8 | // #define PDEBUG 2 |
---|
9 | |
---|
10 | #include "kernel/mod2.h" |
---|
11 | |
---|
12 | //#define ADIDEBUG 1 |
---|
13 | #define GCD_SBA 1 |
---|
14 | |
---|
15 | // define if no buckets should be used |
---|
16 | // #define NO_BUCKETS |
---|
17 | |
---|
18 | #ifdef HAVE_PLURAL |
---|
19 | #define PLURAL_INTERNAL_DECLARATIONS 1 |
---|
20 | #endif |
---|
21 | |
---|
22 | /*********************************************** |
---|
23 | * SBA stuff -- start |
---|
24 | ***********************************************/ |
---|
25 | #define DEBUGF50 0 |
---|
26 | #define DEBUGF51 0 |
---|
27 | |
---|
28 | #ifdef DEBUGF5 |
---|
29 | #undef DEBUGF5 |
---|
30 | //#define DEBUGF5 1 |
---|
31 | #endif |
---|
32 | |
---|
33 | #define F5C 1 |
---|
34 | #if F5C |
---|
35 | #define F5CTAILRED 1 |
---|
36 | #endif |
---|
37 | |
---|
38 | #define SBA_INTERRED_START 0 |
---|
39 | #define SBA_TAIL_RED 1 |
---|
40 | #define SBA_PRODUCT_CRITERION 0 |
---|
41 | #define SBA_PRINT_ZERO_REDUCTIONS 0 |
---|
42 | #define SBA_PRINT_REDUCTION_STEPS 0 |
---|
43 | #define SBA_PRINT_OPERATIONS 0 |
---|
44 | #define SBA_PRINT_SIZE_G 0 |
---|
45 | #define SBA_PRINT_SIZE_SYZ 0 |
---|
46 | #define SBA_PRINT_PRODUCT_CRITERION 0 |
---|
47 | |
---|
48 | // counts sba's reduction steps |
---|
49 | #if SBA_PRINT_REDUCTION_STEPS |
---|
50 | long sba_reduction_steps; |
---|
51 | long sba_interreduction_steps; |
---|
52 | #endif |
---|
53 | #if SBA_PRINT_OPERATIONS |
---|
54 | long sba_operations; |
---|
55 | long sba_interreduction_operations; |
---|
56 | #endif |
---|
57 | |
---|
58 | /*********************************************** |
---|
59 | * SBA stuff -- done |
---|
60 | ***********************************************/ |
---|
61 | |
---|
62 | #include "kernel/GBEngine/kutil.h" |
---|
63 | #include "misc/options.h" |
---|
64 | #include "omalloc/omalloc.h" |
---|
65 | #include "kernel/polys.h" |
---|
66 | #include "kernel/ideals.h" |
---|
67 | #include "kernel/GBEngine/kstd1.h" |
---|
68 | #include "kernel/GBEngine/khstd.h" |
---|
69 | #include "polys/kbuckets.h" |
---|
70 | #include "polys/prCopy.h" |
---|
71 | #include "polys/weight.h" |
---|
72 | #include "misc/intvec.h" |
---|
73 | #ifdef HAVE_PLURAL |
---|
74 | #include "polys/nc/nc.h" |
---|
75 | #endif |
---|
76 | // #include "timer.h" |
---|
77 | |
---|
78 | /* shiftgb stuff */ |
---|
79 | #include "kernel/GBEngine/shiftgb.h" |
---|
80 | |
---|
81 | int (*test_PosInT)(const TSet T,const int tl,LObject &h); |
---|
82 | int (*test_PosInL)(const LSet set, const int length, |
---|
83 | LObject* L,const kStrategy strat); |
---|
84 | |
---|
85 | // return -1 if no divisor is found |
---|
86 | // number of first divisor, otherwise |
---|
87 | int kFindDivisibleByInT(const kStrategy strat, const LObject* L, const int start) |
---|
88 | { |
---|
89 | unsigned long not_sev = ~L->sev; |
---|
90 | int j = start; |
---|
91 | |
---|
92 | const TSet T=strat->T; |
---|
93 | const unsigned long* sevT=strat->sevT; |
---|
94 | if (L->p!=NULL) |
---|
95 | { |
---|
96 | const ring r=currRing; |
---|
97 | const poly p=L->p; |
---|
98 | |
---|
99 | pAssume(~not_sev == p_GetShortExpVector(p, r)); |
---|
100 | |
---|
101 | if(rField_is_Ring(r)) |
---|
102 | { |
---|
103 | loop |
---|
104 | { |
---|
105 | if (j > strat->tl) return -1; |
---|
106 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
107 | if (p_LmShortDivisibleBy(T[j].p, sevT[j],p, not_sev, r)) |
---|
108 | { |
---|
109 | if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].p), r->cf)) |
---|
110 | return j; |
---|
111 | } |
---|
112 | #else |
---|
113 | if (!(sevT[j] & not_sev) && |
---|
114 | p_LmDivisibleBy(T[j].p, p, r)) |
---|
115 | { |
---|
116 | if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].p), r->cf)) |
---|
117 | return j; |
---|
118 | } |
---|
119 | #endif |
---|
120 | j++; |
---|
121 | } |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | loop |
---|
126 | { |
---|
127 | if (j > strat->tl) return -1; |
---|
128 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
129 | if (p_LmShortDivisibleBy(T[j].p, sevT[j],p, not_sev, r)) |
---|
130 | { |
---|
131 | return j; |
---|
132 | } |
---|
133 | #else |
---|
134 | if (!(sevT[j] & not_sev) && |
---|
135 | p_LmDivisibleBy(T[j].p, p, r)) |
---|
136 | { |
---|
137 | return j; |
---|
138 | } |
---|
139 | #endif |
---|
140 | j++; |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | else |
---|
145 | { |
---|
146 | const poly p=L->t_p; |
---|
147 | const ring r=strat->tailRing; |
---|
148 | if(rField_is_Ring(r)) |
---|
149 | { |
---|
150 | loop |
---|
151 | { |
---|
152 | if (j > strat->tl) return -1; |
---|
153 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
154 | if (p_LmShortDivisibleBy(T[j].t_p, sevT[j], |
---|
155 | p, not_sev, r)) |
---|
156 | { |
---|
157 | if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].t_p), r->cf)) |
---|
158 | return j; |
---|
159 | } |
---|
160 | #else |
---|
161 | if (!(sevT[j] & not_sev) && |
---|
162 | p_LmDivisibleBy(T[j].t_p, p, r)) |
---|
163 | { |
---|
164 | if(n_DivBy(pGetCoeff(p), pGetCoeff(T[j].t_p), r->cf)) |
---|
165 | return j; |
---|
166 | } |
---|
167 | #endif |
---|
168 | j++; |
---|
169 | } |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | loop |
---|
174 | { |
---|
175 | if (j > strat->tl) return -1; |
---|
176 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
177 | if (p_LmShortDivisibleBy(T[j].t_p, sevT[j], |
---|
178 | p, not_sev, r)) |
---|
179 | { |
---|
180 | return j; |
---|
181 | } |
---|
182 | #else |
---|
183 | if (!(sevT[j] & not_sev) && |
---|
184 | p_LmDivisibleBy(T[j].t_p, p, r)) |
---|
185 | { |
---|
186 | return j; |
---|
187 | } |
---|
188 | #endif |
---|
189 | j++; |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | // same as above, only with set S |
---|
196 | int kFindDivisibleByInS(const kStrategy strat, int* max_ind, LObject* L) |
---|
197 | { |
---|
198 | unsigned long not_sev = ~L->sev; |
---|
199 | poly p = L->GetLmCurrRing(); |
---|
200 | int j = 0; |
---|
201 | |
---|
202 | pAssume(~not_sev == p_GetShortExpVector(p, currRing)); |
---|
203 | #if 1 |
---|
204 | int ende; |
---|
205 | if ((strat->ak>0) || currRing->pLexOrder || rField_is_Ring(currRing)) ende=strat->sl; |
---|
206 | else ende=posInS(strat,*max_ind,p,0)+1; |
---|
207 | if (ende>(*max_ind)) ende=(*max_ind); |
---|
208 | #else |
---|
209 | int ende=strat->sl; |
---|
210 | #endif |
---|
211 | (*max_ind)=ende; |
---|
212 | if(rField_is_Ring(currRing)) |
---|
213 | { |
---|
214 | loop |
---|
215 | { |
---|
216 | if (j > ende) return -1; |
---|
217 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
218 | if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j], |
---|
219 | p, not_sev, currRing)) |
---|
220 | { |
---|
221 | if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing->cf)) |
---|
222 | return j; |
---|
223 | } |
---|
224 | #else |
---|
225 | if ( !(strat->sevS[j] & not_sev) && |
---|
226 | p_LmDivisibleBy(strat->S[j], p, currRing)) |
---|
227 | { |
---|
228 | if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing->cf)) |
---|
229 | return j; |
---|
230 | } |
---|
231 | #endif |
---|
232 | j++; |
---|
233 | } |
---|
234 | } |
---|
235 | else |
---|
236 | { |
---|
237 | loop |
---|
238 | { |
---|
239 | if (j > ende) return -1; |
---|
240 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
241 | if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j], |
---|
242 | p, not_sev, currRing)) |
---|
243 | { |
---|
244 | return j; |
---|
245 | } |
---|
246 | #else |
---|
247 | if ( !(strat->sevS[j] & not_sev) && |
---|
248 | p_LmDivisibleBy(strat->S[j], p, currRing)) |
---|
249 | { |
---|
250 | return j; |
---|
251 | } |
---|
252 | #endif |
---|
253 | j++; |
---|
254 | } |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | int kFindNextDivisibleByInS(const kStrategy strat, int start,int max_ind, LObject* L) |
---|
259 | { |
---|
260 | unsigned long not_sev = ~L->sev; |
---|
261 | poly p = L->GetLmCurrRing(); |
---|
262 | int j = start; |
---|
263 | |
---|
264 | pAssume(~not_sev == p_GetShortExpVector(p, currRing)); |
---|
265 | #if 1 |
---|
266 | int ende=max_ind; |
---|
267 | #else |
---|
268 | int ende=strat->sl; |
---|
269 | #endif |
---|
270 | if(rField_is_Ring(currRing)) |
---|
271 | { |
---|
272 | loop |
---|
273 | { |
---|
274 | if (j > ende) return -1; |
---|
275 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
276 | if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j], |
---|
277 | p, not_sev, currRing)) |
---|
278 | { |
---|
279 | if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing->cf)) |
---|
280 | return j; |
---|
281 | } |
---|
282 | #else |
---|
283 | if ( !(strat->sevS[j] & not_sev) && |
---|
284 | p_LmDivisibleBy(strat->S[j], p, currRing)) |
---|
285 | { |
---|
286 | if(n_DivBy(pGetCoeff(p), pGetCoeff(strat->S[j]), currRing->cf)) |
---|
287 | return j; |
---|
288 | } |
---|
289 | #endif |
---|
290 | j++; |
---|
291 | } |
---|
292 | } |
---|
293 | else |
---|
294 | { |
---|
295 | loop |
---|
296 | { |
---|
297 | if (j > ende) return -1; |
---|
298 | #if defined(PDEBUG) || defined(PDIV_DEBUG) |
---|
299 | if (p_LmShortDivisibleBy(strat->S[j], strat->sevS[j], |
---|
300 | p, not_sev, currRing)) |
---|
301 | { |
---|
302 | return j; |
---|
303 | } |
---|
304 | #else |
---|
305 | if ( !(strat->sevS[j] & not_sev) && |
---|
306 | p_LmDivisibleBy(strat->S[j], p, currRing)) |
---|
307 | { |
---|
308 | return j; |
---|
309 | } |
---|
310 | #endif |
---|
311 | j++; |
---|
312 | } |
---|
313 | } |
---|
314 | } |
---|
315 | |
---|
316 | #ifdef HAVE_RINGS |
---|
317 | poly kFindZeroPoly(poly input_p, ring leadRing, ring tailRing) |
---|
318 | { |
---|
319 | // m = currRing->ch |
---|
320 | |
---|
321 | if (input_p == NULL) return NULL; |
---|
322 | |
---|
323 | poly p = input_p; |
---|
324 | poly zeroPoly = NULL; |
---|
325 | unsigned long a = (unsigned long) pGetCoeff(p); |
---|
326 | |
---|
327 | int k_ind2 = 0; |
---|
328 | int a_ind2 = ind2(a); |
---|
329 | |
---|
330 | // unsigned long k = 1; |
---|
331 | // of interest is only k_ind2, special routine for improvement ... TODO OLIVER |
---|
332 | for (int i = 1; i <= leadRing->N; i++) |
---|
333 | { |
---|
334 | k_ind2 = k_ind2 + ind_fact_2(p_GetExp(p, i, leadRing)); |
---|
335 | } |
---|
336 | |
---|
337 | a = (unsigned long) pGetCoeff(p); |
---|
338 | |
---|
339 | number tmp1; |
---|
340 | poly tmp2, tmp3; |
---|
341 | poly lead_mult = p_ISet(1, tailRing); |
---|
342 | if (n_GetChar(leadRing->cf) <= k_ind2 + a_ind2) |
---|
343 | { |
---|
344 | int too_much = k_ind2 + a_ind2 - n_GetChar(leadRing->cf); |
---|
345 | int s_exp; |
---|
346 | zeroPoly = p_ISet(a, tailRing); |
---|
347 | for (int i = 1; i <= leadRing->N; i++) |
---|
348 | { |
---|
349 | s_exp = p_GetExp(p, i,leadRing); |
---|
350 | if (s_exp % 2 != 0) |
---|
351 | { |
---|
352 | s_exp = s_exp - 1; |
---|
353 | } |
---|
354 | while ( (0 < ind2(s_exp)) && (ind2(s_exp) <= too_much) ) |
---|
355 | { |
---|
356 | too_much = too_much - ind2(s_exp); |
---|
357 | s_exp = s_exp - 2; |
---|
358 | } |
---|
359 | p_SetExp(lead_mult, i, p_GetExp(p, i,leadRing) - s_exp, tailRing); |
---|
360 | for (int j = 1; j <= s_exp; j++) |
---|
361 | { |
---|
362 | tmp1 = nInit(j); |
---|
363 | tmp2 = p_ISet(1, tailRing); |
---|
364 | p_SetExp(tmp2, i, 1, tailRing); |
---|
365 | p_Setm(tmp2, tailRing); |
---|
366 | if (nIsZero(tmp1)) |
---|
367 | { // should nowbe obsolet, test ! TODO OLIVER |
---|
368 | zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing); |
---|
369 | } |
---|
370 | else |
---|
371 | { |
---|
372 | tmp3 = p_NSet(nCopy(tmp1), tailRing); |
---|
373 | zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp3, tmp2, tailRing), tailRing); |
---|
374 | } |
---|
375 | } |
---|
376 | } |
---|
377 | p_Setm(lead_mult, tailRing); |
---|
378 | zeroPoly = p_Mult_mm(zeroPoly, lead_mult, tailRing); |
---|
379 | tmp2 = p_NSet(nCopy(pGetCoeff(zeroPoly)), leadRing); |
---|
380 | for (int i = 1; i <= leadRing->N; i++) |
---|
381 | { |
---|
382 | pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing)); |
---|
383 | } |
---|
384 | p_Setm(tmp2, leadRing); |
---|
385 | zeroPoly = p_LmDeleteAndNext(zeroPoly, tailRing); |
---|
386 | pNext(tmp2) = zeroPoly; |
---|
387 | return tmp2; |
---|
388 | } |
---|
389 | /* unsigned long alpha_k = twoPow(leadRing->ch - k_ind2); |
---|
390 | if (1 == 0 && alpha_k <= a) |
---|
391 | { // Temporarly disabled, reducing coefficients not compatible with std TODO Oliver |
---|
392 | zeroPoly = p_ISet((a / alpha_k)*alpha_k, tailRing); |
---|
393 | for (int i = 1; i <= leadRing->N; i++) |
---|
394 | { |
---|
395 | for (unsigned long j = 1; j <= p_GetExp(p, i, leadRing); j++) |
---|
396 | { |
---|
397 | tmp1 = nInit(j); |
---|
398 | tmp2 = p_ISet(1, tailRing); |
---|
399 | p_SetExp(tmp2, i, 1, tailRing); |
---|
400 | p_Setm(tmp2, tailRing); |
---|
401 | if (nIsZero(tmp1)) |
---|
402 | { |
---|
403 | zeroPoly = p_Mult_q(zeroPoly, tmp2, tailRing); |
---|
404 | } |
---|
405 | else |
---|
406 | { |
---|
407 | tmp3 = p_ISet((unsigned long) tmp1, tailRing); |
---|
408 | zeroPoly = p_Mult_q(zeroPoly, p_Add_q(tmp2, tmp3, tailRing), tailRing); |
---|
409 | } |
---|
410 | } |
---|
411 | } |
---|
412 | tmp2 = p_ISet((unsigned long) pGetCoeff(zeroPoly), leadRing); |
---|
413 | for (int i = 1; i <= leadRing->N; i++) |
---|
414 | { |
---|
415 | pSetExp(tmp2, i, p_GetExp(zeroPoly, i, tailRing)); |
---|
416 | } |
---|
417 | p_Setm(tmp2, leadRing); |
---|
418 | zeroPoly = p_LmDeleteAndNext(zeroPoly, tailRing); |
---|
419 | pNext(tmp2) = zeroPoly; |
---|
420 | return tmp2; |
---|
421 | } */ |
---|
422 | return NULL; |
---|
423 | } |
---|
424 | #endif |
---|
425 | |
---|
426 | |
---|
427 | #ifdef HAVE_RINGS |
---|
428 | /*2 |
---|
429 | * reduction procedure for the ring Z/2^m |
---|
430 | */ |
---|
431 | int redRing (LObject* h,kStrategy strat) |
---|
432 | { |
---|
433 | if (h->IsNull()) return 0; // spoly is zero (can only occure with zero divisors) |
---|
434 | if (strat->tl<0) return 1; |
---|
435 | |
---|
436 | int at/*,i*/; |
---|
437 | long d; |
---|
438 | int j = 0; |
---|
439 | int pass = 0; |
---|
440 | // poly zeroPoly = NULL; |
---|
441 | |
---|
442 | // TODO warum SetpFDeg notwendig? |
---|
443 | h->SetpFDeg(); |
---|
444 | assume(h->pFDeg() == h->FDeg); |
---|
445 | long reddeg = h->GetpFDeg(); |
---|
446 | |
---|
447 | h->SetShortExpVector(); |
---|
448 | loop |
---|
449 | { |
---|
450 | j = kFindDivisibleByInT(strat, h); |
---|
451 | if (j < 0) |
---|
452 | { |
---|
453 | // over ZZ: cleanup coefficients by complete reduction with monomials |
---|
454 | postReduceByMon(h, strat); |
---|
455 | if(h->p == NULL) |
---|
456 | { |
---|
457 | if (h->lcm!=NULL) pLmDelete(h->lcm); |
---|
458 | h->Clear(); |
---|
459 | return 0; |
---|
460 | } |
---|
461 | if(nIsZero(pGetCoeff(h->p))) return 2; |
---|
462 | j = kFindDivisibleByInT(strat, h); |
---|
463 | if(j < 0) |
---|
464 | { |
---|
465 | if(strat->tl >= 0) |
---|
466 | h->i_r1 = strat->tl; |
---|
467 | else |
---|
468 | h->i_r1 = -1; |
---|
469 | if (h->GetLmTailRing() == NULL) |
---|
470 | { |
---|
471 | if (h->lcm!=NULL) pLmDelete(h->lcm); |
---|
472 | h->Clear(); |
---|
473 | return 0; |
---|
474 | } |
---|
475 | return 1; |
---|
476 | } |
---|
477 | } |
---|
478 | //printf("\nFound one: ");pWrite(strat->T[j].p); |
---|
479 | //enterT(*h, strat); |
---|
480 | ksReducePoly(h, &(strat->T[j]), NULL, NULL, strat); // with debug output |
---|
481 | //printf("\nAfter small red: ");pWrite(h->p); |
---|
482 | if (h->GetLmTailRing() == NULL) |
---|
483 | { |
---|
484 | if (h->lcm!=NULL) pLmDelete(h->lcm); |
---|
485 | #ifdef KDEBUG |
---|
486 | h->lcm=NULL; |
---|
487 | #endif |
---|
488 | h->Clear(); |
---|
489 | return 0; |
---|
490 | } |
---|
491 | h->SetShortExpVector(); |
---|
492 | d = h->SetpFDeg(); |
---|
493 | /*- try to reduce the s-polynomial -*/ |
---|
494 | pass++; |
---|
495 | if (!TEST_OPT_REDTHROUGH && |
---|
496 | (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
497 | { |
---|
498 | h->SetLmCurrRing(); |
---|
499 | if (strat->posInLDependsOnLength) |
---|
500 | h->SetLength(strat->length_pLength); |
---|
501 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
502 | if (at <= strat->Ll) |
---|
503 | { |
---|
504 | #ifdef KDEBUG |
---|
505 | if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at); |
---|
506 | #endif |
---|
507 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); // NOT RING CHECKED OLIVER |
---|
508 | h->Clear(); |
---|
509 | return -1; |
---|
510 | } |
---|
511 | } |
---|
512 | if (d != reddeg) |
---|
513 | { |
---|
514 | if (d >= (long)strat->tailRing->bitmask) |
---|
515 | { |
---|
516 | if (h->pTotalDeg() >= (long)strat->tailRing->bitmask) |
---|
517 | { |
---|
518 | strat->overflow=TRUE; |
---|
519 | //Print("OVERFLOW in redRing d=%ld, max=%ld\n",d,strat->tailRing->bitmask); |
---|
520 | h->GetP(); |
---|
521 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
522 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
523 | h->Clear(); |
---|
524 | return -1; |
---|
525 | } |
---|
526 | } |
---|
527 | else if ((TEST_OPT_PROT) && (strat->Ll < 0)) |
---|
528 | { |
---|
529 | Print(".%ld",d);mflush(); |
---|
530 | reddeg = d; |
---|
531 | } |
---|
532 | } |
---|
533 | } |
---|
534 | } |
---|
535 | #endif |
---|
536 | |
---|
537 | /*2 |
---|
538 | * reduction procedure for the homogeneous case |
---|
539 | * and the case of a degree-ordering |
---|
540 | */ |
---|
541 | int redHomog (LObject* h,kStrategy strat) |
---|
542 | { |
---|
543 | if (strat->tl<0) return 1; |
---|
544 | //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED! |
---|
545 | assume(h->FDeg == h->pFDeg()); |
---|
546 | |
---|
547 | poly h_p; |
---|
548 | int i,j,at,pass, ii; |
---|
549 | unsigned long not_sev; |
---|
550 | // long reddeg,d; |
---|
551 | |
---|
552 | pass = j = 0; |
---|
553 | // d = reddeg = h->GetpFDeg(); |
---|
554 | h->SetShortExpVector(); |
---|
555 | int li; |
---|
556 | h_p = h->GetLmTailRing(); |
---|
557 | not_sev = ~ h->sev; |
---|
558 | loop |
---|
559 | { |
---|
560 | j = kFindDivisibleByInT(strat, h); |
---|
561 | if (j < 0) return 1; |
---|
562 | |
---|
563 | li = strat->T[j].pLength; |
---|
564 | ii = j; |
---|
565 | /* |
---|
566 | * the polynomial to reduce with (up to the moment) is; |
---|
567 | * pi with length li |
---|
568 | */ |
---|
569 | i = j; |
---|
570 | #if 1 |
---|
571 | if (TEST_OPT_LENGTH) |
---|
572 | loop |
---|
573 | { |
---|
574 | /*- search the shortest possible with respect to length -*/ |
---|
575 | i++; |
---|
576 | if (i > strat->tl) |
---|
577 | break; |
---|
578 | if (li<=1) |
---|
579 | break; |
---|
580 | if ((strat->T[i].pLength < li) |
---|
581 | && |
---|
582 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
583 | h_p, not_sev, strat->tailRing)) |
---|
584 | { |
---|
585 | /* |
---|
586 | * the polynomial to reduce with is now; |
---|
587 | */ |
---|
588 | li = strat->T[i].pLength; |
---|
589 | ii = i; |
---|
590 | } |
---|
591 | } |
---|
592 | #endif |
---|
593 | |
---|
594 | /* |
---|
595 | * end of search: have to reduce with pi |
---|
596 | */ |
---|
597 | #ifdef KDEBUG |
---|
598 | if (TEST_OPT_DEBUG) |
---|
599 | { |
---|
600 | PrintS("red:"); |
---|
601 | h->wrp(); |
---|
602 | PrintS(" with "); |
---|
603 | strat->T[ii].wrp(); |
---|
604 | } |
---|
605 | #endif |
---|
606 | assume(strat->fromT == FALSE); |
---|
607 | |
---|
608 | ksReducePoly(h, &(strat->T[ii]), NULL, NULL, strat); |
---|
609 | #if SBA_PRINT_REDUCTION_STEPS |
---|
610 | sba_interreduction_steps++; |
---|
611 | #endif |
---|
612 | #if SBA_PRINT_OPERATIONS |
---|
613 | sba_interreduction_operations += pLength(strat->T[ii].p); |
---|
614 | #endif |
---|
615 | |
---|
616 | #ifdef KDEBUG |
---|
617 | if (TEST_OPT_DEBUG) |
---|
618 | { |
---|
619 | PrintS("\nto "); |
---|
620 | h->wrp(); |
---|
621 | PrintLn(); |
---|
622 | } |
---|
623 | #endif |
---|
624 | |
---|
625 | h_p = h->GetLmTailRing(); |
---|
626 | if (h_p == NULL) |
---|
627 | { |
---|
628 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
629 | #ifdef KDEBUG |
---|
630 | h->lcm=NULL; |
---|
631 | #endif |
---|
632 | return 0; |
---|
633 | } |
---|
634 | h->SetShortExpVector(); |
---|
635 | not_sev = ~ h->sev; |
---|
636 | /* |
---|
637 | * try to reduce the s-polynomial h |
---|
638 | *test first whether h should go to the lazyset L |
---|
639 | *-if the degree jumps |
---|
640 | *-if the number of pre-defined reductions jumps |
---|
641 | */ |
---|
642 | pass++; |
---|
643 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass)) |
---|
644 | { |
---|
645 | h->SetLmCurrRing(); |
---|
646 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
647 | if (at <= strat->Ll) |
---|
648 | { |
---|
649 | int dummy=strat->sl; |
---|
650 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
651 | return 1; |
---|
652 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
653 | #ifdef KDEBUG |
---|
654 | if (TEST_OPT_DEBUG) |
---|
655 | Print(" lazy: -> L%d\n",at); |
---|
656 | #endif |
---|
657 | h->Clear(); |
---|
658 | return -1; |
---|
659 | } |
---|
660 | } |
---|
661 | } |
---|
662 | } |
---|
663 | |
---|
664 | KINLINE int ksReducePolyTailSig(LObject* PR, TObject* PW, LObject* Red, kStrategy strat) |
---|
665 | { |
---|
666 | BOOLEAN ret; |
---|
667 | number coef; |
---|
668 | assume(PR->GetLmCurrRing() != PW->GetLmCurrRing()); |
---|
669 | if(!rField_is_Ring(currRing)) |
---|
670 | Red->HeadNormalize(); |
---|
671 | /* |
---|
672 | printf("------------------------\n"); |
---|
673 | pWrite(Red->GetLmCurrRing()); |
---|
674 | */ |
---|
675 | if(rField_is_Ring(currRing)) |
---|
676 | ret = ksReducePolySigRing(Red, PW, 1, NULL, &coef, strat); |
---|
677 | else |
---|
678 | ret = ksReducePolySig(Red, PW, 1, NULL, &coef, strat); |
---|
679 | if (!ret) |
---|
680 | { |
---|
681 | if (! n_IsOne(coef, currRing->cf) && !rField_is_Ring(currRing)) |
---|
682 | { |
---|
683 | PR->Mult_nn(coef); |
---|
684 | // HANNES: mark for Normalize |
---|
685 | } |
---|
686 | n_Delete(&coef, currRing->cf); |
---|
687 | } |
---|
688 | return ret; |
---|
689 | } |
---|
690 | |
---|
691 | /*2 |
---|
692 | * reduction procedure for signature-based standard |
---|
693 | * basis algorithms: |
---|
694 | * all reductions have to be sig-safe! |
---|
695 | * |
---|
696 | * 2 is returned if and only if the pair is rejected by the rewritten criterion |
---|
697 | * at exactly this point of the computations. This is the last possible point |
---|
698 | * such a check can be done => checks with the biggest set of available |
---|
699 | * signatures |
---|
700 | */ |
---|
701 | |
---|
702 | int redSig (LObject* h,kStrategy strat) |
---|
703 | { |
---|
704 | if (strat->tl<0) return 1; |
---|
705 | //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED! |
---|
706 | //printf("FDEGS: %ld -- %ld\n",h->FDeg, h->pFDeg()); |
---|
707 | assume(h->FDeg == h->pFDeg()); |
---|
708 | //#if 1 |
---|
709 | #ifdef DEBUGF5 |
---|
710 | PrintS("------- IN REDSIG -------\n"); |
---|
711 | Print("p: "); |
---|
712 | pWrite(pHead(h->p)); |
---|
713 | PrintS("p1: "); |
---|
714 | pWrite(pHead(h->p1)); |
---|
715 | PrintS("p2: "); |
---|
716 | pWrite(pHead(h->p2)); |
---|
717 | PrintS("---------------------------\n"); |
---|
718 | #endif |
---|
719 | poly h_p; |
---|
720 | int i,j,at,pass, ii; |
---|
721 | int start=0; |
---|
722 | int sigSafe; |
---|
723 | unsigned long not_sev; |
---|
724 | // long reddeg,d; |
---|
725 | |
---|
726 | pass = j = 0; |
---|
727 | // d = reddeg = h->GetpFDeg(); |
---|
728 | h->SetShortExpVector(); |
---|
729 | int li; |
---|
730 | h_p = h->GetLmTailRing(); |
---|
731 | not_sev = ~ h->sev; |
---|
732 | loop |
---|
733 | { |
---|
734 | j = kFindDivisibleByInT(strat, h, start); |
---|
735 | if (j < 0) |
---|
736 | { |
---|
737 | return 1; |
---|
738 | } |
---|
739 | |
---|
740 | li = strat->T[j].pLength; |
---|
741 | ii = j; |
---|
742 | /* |
---|
743 | * the polynomial to reduce with (up to the moment) is; |
---|
744 | * pi with length li |
---|
745 | */ |
---|
746 | i = j; |
---|
747 | #if 1 |
---|
748 | if (TEST_OPT_LENGTH) |
---|
749 | loop |
---|
750 | { |
---|
751 | /*- search the shortest possible with respect to length -*/ |
---|
752 | i++; |
---|
753 | if (i > strat->tl) |
---|
754 | break; |
---|
755 | if (li<=1) |
---|
756 | break; |
---|
757 | if ((strat->T[i].pLength < li) |
---|
758 | && |
---|
759 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
760 | h_p, not_sev, strat->tailRing)) |
---|
761 | { |
---|
762 | /* |
---|
763 | * the polynomial to reduce with is now; |
---|
764 | */ |
---|
765 | li = strat->T[i].pLength; |
---|
766 | ii = i; |
---|
767 | } |
---|
768 | } |
---|
769 | start = ii+1; |
---|
770 | #endif |
---|
771 | |
---|
772 | /* |
---|
773 | * end of search: have to reduce with pi |
---|
774 | */ |
---|
775 | #ifdef KDEBUG |
---|
776 | if (TEST_OPT_DEBUG) |
---|
777 | { |
---|
778 | PrintS("red:"); |
---|
779 | h->wrp(); |
---|
780 | PrintS(" with "); |
---|
781 | strat->T[ii].wrp(); |
---|
782 | } |
---|
783 | #endif |
---|
784 | assume(strat->fromT == FALSE); |
---|
785 | //#if 1 |
---|
786 | #ifdef DEBUGF5 |
---|
787 | Print("BEFORE REDUCTION WITH %d:\n",ii); |
---|
788 | PrintS("--------------------------------\n"); |
---|
789 | pWrite(h->sig); |
---|
790 | pWrite(strat->T[ii].sig); |
---|
791 | pWrite(h->GetLmCurrRing()); |
---|
792 | pWrite(pHead(h->p1)); |
---|
793 | pWrite(pHead(h->p2)); |
---|
794 | pWrite(pHead(strat->T[ii].p)); |
---|
795 | PrintS("--------------------------------\n"); |
---|
796 | printf("INDEX OF REDUCER T: %d\n",ii); |
---|
797 | #endif |
---|
798 | sigSafe = ksReducePolySig(h, &(strat->T[ii]), strat->S_2_R[ii], NULL, NULL, strat); |
---|
799 | #if SBA_PRINT_REDUCTION_STEPS |
---|
800 | if (sigSafe != 3) |
---|
801 | sba_reduction_steps++; |
---|
802 | #endif |
---|
803 | #if SBA_PRINT_OPERATIONS |
---|
804 | if (sigSafe != 3) |
---|
805 | sba_operations += pLength(strat->T[ii].p); |
---|
806 | #endif |
---|
807 | // if reduction has taken place, i.e. the reduction was sig-safe |
---|
808 | // otherwise start is already at the next position and the loop |
---|
809 | // searching reducers in T goes on from index start |
---|
810 | //#if 1 |
---|
811 | #ifdef DEBUGF5 |
---|
812 | Print("SigSAFE: %d\n",sigSafe); |
---|
813 | #endif |
---|
814 | if (sigSafe != 3) |
---|
815 | { |
---|
816 | // start the next search for reducers in T from the beginning |
---|
817 | start = 0; |
---|
818 | #ifdef KDEBUG |
---|
819 | if (TEST_OPT_DEBUG) |
---|
820 | { |
---|
821 | PrintS("\nto "); |
---|
822 | h->wrp(); |
---|
823 | PrintLn(); |
---|
824 | } |
---|
825 | #endif |
---|
826 | |
---|
827 | h_p = h->GetLmTailRing(); |
---|
828 | if (h_p == NULL) |
---|
829 | { |
---|
830 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
831 | #ifdef KDEBUG |
---|
832 | h->lcm=NULL; |
---|
833 | #endif |
---|
834 | return 0; |
---|
835 | } |
---|
836 | h->SetShortExpVector(); |
---|
837 | not_sev = ~ h->sev; |
---|
838 | /* |
---|
839 | * try to reduce the s-polynomial h |
---|
840 | *test first whether h should go to the lazyset L |
---|
841 | *-if the degree jumps |
---|
842 | *-if the number of pre-defined reductions jumps |
---|
843 | */ |
---|
844 | pass++; |
---|
845 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass)) |
---|
846 | { |
---|
847 | h->SetLmCurrRing(); |
---|
848 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
849 | if (at <= strat->Ll) |
---|
850 | { |
---|
851 | int dummy=strat->sl; |
---|
852 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
853 | { |
---|
854 | return 1; |
---|
855 | } |
---|
856 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
857 | #ifdef KDEBUG |
---|
858 | if (TEST_OPT_DEBUG) |
---|
859 | Print(" lazy: -> L%d\n",at); |
---|
860 | #endif |
---|
861 | h->Clear(); |
---|
862 | return -1; |
---|
863 | } |
---|
864 | } |
---|
865 | } |
---|
866 | } |
---|
867 | } |
---|
868 | |
---|
869 | |
---|
870 | int redSigRing (LObject* h,kStrategy strat) |
---|
871 | { |
---|
872 | //Since reduce is really bad for SBA we use the following idea: |
---|
873 | // We first check if we can build a gcd pair between h and S |
---|
874 | //where the sig remains the same and replace h by this gcd poly |
---|
875 | assume(rField_is_Ring(currRing)); |
---|
876 | #if GCD_SBA |
---|
877 | #ifdef ADIDEBUG |
---|
878 | printf("\nBefore sbaCheckGcdPair ");pWrite(h->p); |
---|
879 | #endif |
---|
880 | while(sbaCheckGcdPair(h,strat)) |
---|
881 | { |
---|
882 | #ifdef ADIDEBUG |
---|
883 | printf("\nIntermidiate sbaCheckGcdPair ");pWrite(h->p); |
---|
884 | #endif |
---|
885 | h->sev = pGetShortExpVector(h->p); |
---|
886 | } |
---|
887 | #ifdef ADIDEBUG |
---|
888 | printf("\nAfter sbaCheckGcdPair ");pWrite(h->p); |
---|
889 | #endif |
---|
890 | #endif |
---|
891 | poly beforeredsig; |
---|
892 | beforeredsig = pCopy(h->sig); |
---|
893 | |
---|
894 | if (strat->tl<0) return 1; |
---|
895 | //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED! |
---|
896 | //printf("FDEGS: %ld -- %ld\n",h->FDeg, h->pFDeg()); |
---|
897 | assume(h->FDeg == h->pFDeg()); |
---|
898 | #ifdef ADIDEBUG |
---|
899 | printf("\n--------------------------redSig-------------------------------------\n"); |
---|
900 | printf("\nBefore redSig:\n"); |
---|
901 | p_Write(h->p,strat->tailRing);pWrite(h->sig); |
---|
902 | #endif |
---|
903 | //#if 1 |
---|
904 | #ifdef DEBUGF5 |
---|
905 | Print("------- IN REDSIG -------\n"); |
---|
906 | Print("p: "); |
---|
907 | pWrite(pHead(h->p)); |
---|
908 | Print("p1: "); |
---|
909 | pWrite(pHead(h->p1)); |
---|
910 | Print("p2: "); |
---|
911 | pWrite(pHead(h->p2)); |
---|
912 | Print("---------------------------\n"); |
---|
913 | #endif |
---|
914 | poly h_p; |
---|
915 | int i,j,at,pass, ii; |
---|
916 | int start=0; |
---|
917 | int sigSafe; |
---|
918 | unsigned long not_sev; |
---|
919 | // long reddeg,d; |
---|
920 | |
---|
921 | pass = j = 0; |
---|
922 | // d = reddeg = h->GetpFDeg(); |
---|
923 | h->SetShortExpVector(); |
---|
924 | int li; |
---|
925 | h_p = h->GetLmTailRing(); |
---|
926 | not_sev = ~ h->sev; |
---|
927 | loop |
---|
928 | { |
---|
929 | j = kFindDivisibleByInT(strat, h, start); |
---|
930 | if (j < 0) |
---|
931 | { |
---|
932 | #if GCD_SBA |
---|
933 | #ifdef ADIDEBUG |
---|
934 | printf("\nBefore sbaCheckGcdPair ");pWrite(h->p); |
---|
935 | #endif |
---|
936 | while(sbaCheckGcdPair(h,strat)) |
---|
937 | { |
---|
938 | #ifdef ADIDEBUG |
---|
939 | printf("\nIntermidiate sbaCheckGcdPair ");pWrite(h->p); |
---|
940 | #endif |
---|
941 | h->sev = pGetShortExpVector(h->p); |
---|
942 | h->is_redundant = FALSE; |
---|
943 | start = 0; |
---|
944 | } |
---|
945 | #ifdef ADIDEBUG |
---|
946 | printf("\nAfter sbaCheckGcdPair ");pWrite(h->p); |
---|
947 | #endif |
---|
948 | #endif |
---|
949 | // over ZZ: cleanup coefficients by complete reduction with monomials |
---|
950 | postReduceByMonSig(h, strat); |
---|
951 | if(h->p == NULL || nIsZero(pGetCoeff(h->p))) return 2; |
---|
952 | j = kFindDivisibleByInT(strat, h,start); |
---|
953 | if(j < 0) |
---|
954 | { |
---|
955 | if(strat->tl >= 0) |
---|
956 | h->i_r1 = strat->tl; |
---|
957 | else |
---|
958 | h->i_r1 = -1; |
---|
959 | if (h->GetLmTailRing() == NULL) |
---|
960 | { |
---|
961 | if (h->lcm!=NULL) pLmDelete(h->lcm); |
---|
962 | h->Clear(); |
---|
963 | return 0; |
---|
964 | } |
---|
965 | //Check for sigdrop after reduction |
---|
966 | if(pLtCmp(beforeredsig,h->sig) == 1) |
---|
967 | { |
---|
968 | #ifdef ADIDEBUG |
---|
969 | printf("\nSigDrop after reduce\n");pWrite(beforeredsig);pWrite(h->sig); |
---|
970 | #endif |
---|
971 | strat->sigdrop = TRUE; |
---|
972 | //Reduce it as much as you can |
---|
973 | int red_result = redRing(h,strat); |
---|
974 | if(red_result == 0) |
---|
975 | { |
---|
976 | //It reduced to 0, cancel the sigdrop |
---|
977 | #ifdef ADIDEBUG |
---|
978 | printf("\nReduced to 0 via redRing. Cancel sigdrop\n"); |
---|
979 | #endif |
---|
980 | strat->sigdrop = FALSE; |
---|
981 | p_Delete(&h->sig,currRing);h->sig = NULL; |
---|
982 | return 0; |
---|
983 | } |
---|
984 | else |
---|
985 | { |
---|
986 | #ifdef ADIDEBUG |
---|
987 | printf("\nReduced to this via redRing.SIGDROP\n");pWrite(h->p); |
---|
988 | #endif |
---|
989 | //strat->enterS(*h, strat->sl+1, strat, strat->tl); |
---|
990 | return 0; |
---|
991 | } |
---|
992 | } |
---|
993 | p_Delete(&beforeredsig,currRing); |
---|
994 | return 1; |
---|
995 | } |
---|
996 | } |
---|
997 | |
---|
998 | li = strat->T[j].pLength; |
---|
999 | ii = j; |
---|
1000 | /* |
---|
1001 | * the polynomial to reduce with (up to the moment) is; |
---|
1002 | * pi with length li |
---|
1003 | */ |
---|
1004 | i = j; |
---|
1005 | if (TEST_OPT_LENGTH) |
---|
1006 | loop |
---|
1007 | { |
---|
1008 | /*- search the shortest possible with respect to length -*/ |
---|
1009 | i++; |
---|
1010 | if (i > strat->tl) |
---|
1011 | break; |
---|
1012 | if (li<=1) |
---|
1013 | break; |
---|
1014 | if ((strat->T[i].pLength < li) |
---|
1015 | && n_DivBy(pGetCoeff(h_p),pGetCoeff(strat->T[i].p),currRing->cf) |
---|
1016 | && p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
1017 | h_p, not_sev, strat->tailRing)) |
---|
1018 | { |
---|
1019 | /* |
---|
1020 | * the polynomial to reduce with is now; |
---|
1021 | */ |
---|
1022 | li = strat->T[i].pLength; |
---|
1023 | ii = i; |
---|
1024 | } |
---|
1025 | } |
---|
1026 | |
---|
1027 | start = ii+1; |
---|
1028 | |
---|
1029 | /* |
---|
1030 | * end of search: have to reduce with pi |
---|
1031 | */ |
---|
1032 | #ifdef KDEBUG |
---|
1033 | if (TEST_OPT_DEBUG) |
---|
1034 | { |
---|
1035 | PrintS("red:"); |
---|
1036 | h->wrp(); |
---|
1037 | PrintS(" with "); |
---|
1038 | strat->T[ii].wrp(); |
---|
1039 | } |
---|
1040 | #endif |
---|
1041 | assume(strat->fromT == FALSE); |
---|
1042 | //#if 1 |
---|
1043 | #ifdef DEBUGF5 |
---|
1044 | Print("BEFORE REDUCTION WITH %d:\n",ii); |
---|
1045 | Print("--------------------------------\n"); |
---|
1046 | pWrite(h->sig); |
---|
1047 | pWrite(strat->T[ii].sig); |
---|
1048 | pWrite(h->GetLmCurrRing()); |
---|
1049 | pWrite(pHead(h->p1)); |
---|
1050 | pWrite(pHead(h->p2)); |
---|
1051 | pWrite(pHead(strat->T[ii].p)); |
---|
1052 | Print("--------------------------------\n"); |
---|
1053 | printf("INDEX OF REDUCER T: %d\n",ii); |
---|
1054 | #endif |
---|
1055 | #ifdef ADIDEBUG |
---|
1056 | printf("\nWe reduce it with:\n");p_Write(strat->T[ii].p,strat->tailRing);pWrite(strat->T[ii].sig); |
---|
1057 | #endif |
---|
1058 | sigSafe = ksReducePolySigRing(h, &(strat->T[ii]), strat->S_2_R[ii], NULL, NULL, strat); |
---|
1059 | #ifdef ADIDEBUG |
---|
1060 | printf("\nAfter small reduction:\n");pWrite(h->p);pWrite(h->sig); |
---|
1061 | #endif |
---|
1062 | if(h->p == NULL && h->sig == NULL) |
---|
1063 | { |
---|
1064 | //Trivial case catch |
---|
1065 | strat->sigdrop = FALSE; |
---|
1066 | } |
---|
1067 | #if 0 |
---|
1068 | //If the reducer has the same lt (+ or -) as the other one, reduce it via redRing |
---|
1069 | //In some cases this proves to be very bad |
---|
1070 | if(rField_is_Ring(currRing) && h->p != NULL && pLmCmp(h->p,strat->T[ii].p)==0) |
---|
1071 | { |
---|
1072 | #ifdef ADIDEBUG |
---|
1073 | printf("\nReducer and Original have same LT. Force it with redRing!\n"); |
---|
1074 | #endif |
---|
1075 | int red_result = redRing(h,strat); |
---|
1076 | if(red_result == 0) |
---|
1077 | { |
---|
1078 | #ifdef ADIDEBUG |
---|
1079 | printf("\nRedRing reduced it to 0. Perfect\n"); |
---|
1080 | #endif |
---|
1081 | pDelete(&h->sig);h->sig = NULL; |
---|
1082 | return 0; |
---|
1083 | } |
---|
1084 | else |
---|
1085 | { |
---|
1086 | #ifdef ADIDEBUG |
---|
1087 | printf("\nRedRing reduced it to *.\nHave to sigdrop now\n");pWrite(h->p); |
---|
1088 | #endif |
---|
1089 | strat->sigdrop = TRUE; |
---|
1090 | return 1; |
---|
1091 | } |
---|
1092 | } |
---|
1093 | #endif |
---|
1094 | if(strat->sigdrop) |
---|
1095 | return 1; |
---|
1096 | #if SBA_PRINT_REDUCTION_STEPS |
---|
1097 | if (sigSafe != 3) |
---|
1098 | sba_reduction_steps++; |
---|
1099 | #endif |
---|
1100 | #if SBA_PRINT_OPERATIONS |
---|
1101 | if (sigSafe != 3) |
---|
1102 | sba_operations += pLength(strat->T[ii].p); |
---|
1103 | #endif |
---|
1104 | // if reduction has taken place, i.e. the reduction was sig-safe |
---|
1105 | // otherwise start is already at the next position and the loop |
---|
1106 | // searching reducers in T goes on from index start |
---|
1107 | //#if 1 |
---|
1108 | #ifdef DEBUGF5 |
---|
1109 | Print("SigSAFE: %d\n",sigSafe); |
---|
1110 | #endif |
---|
1111 | if (sigSafe != 3) |
---|
1112 | { |
---|
1113 | // start the next search for reducers in T from the beginning |
---|
1114 | start = 0; |
---|
1115 | #ifdef KDEBUG |
---|
1116 | if (TEST_OPT_DEBUG) |
---|
1117 | { |
---|
1118 | PrintS("\nto "); |
---|
1119 | h->wrp(); |
---|
1120 | PrintLn(); |
---|
1121 | } |
---|
1122 | #endif |
---|
1123 | |
---|
1124 | h_p = h->GetLmTailRing(); |
---|
1125 | if (h_p == NULL) |
---|
1126 | { |
---|
1127 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
1128 | #ifdef KDEBUG |
---|
1129 | h->lcm=NULL; |
---|
1130 | #endif |
---|
1131 | return 0; |
---|
1132 | } |
---|
1133 | h->SetShortExpVector(); |
---|
1134 | not_sev = ~ h->sev; |
---|
1135 | /* |
---|
1136 | * try to reduce the s-polynomial h |
---|
1137 | *test first whether h should go to the lazyset L |
---|
1138 | *-if the degree jumps |
---|
1139 | *-if the number of pre-defined reductions jumps |
---|
1140 | */ |
---|
1141 | pass++; |
---|
1142 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass)) |
---|
1143 | { |
---|
1144 | h->SetLmCurrRing(); |
---|
1145 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
1146 | if (at <= strat->Ll) |
---|
1147 | { |
---|
1148 | int dummy=strat->sl; |
---|
1149 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
1150 | { |
---|
1151 | return 1; |
---|
1152 | } |
---|
1153 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
1154 | #ifdef KDEBUG |
---|
1155 | if (TEST_OPT_DEBUG) |
---|
1156 | Print(" lazy: -> L%d\n",at); |
---|
1157 | #endif |
---|
1158 | h->Clear(); |
---|
1159 | return -1; |
---|
1160 | } |
---|
1161 | } |
---|
1162 | } |
---|
1163 | } |
---|
1164 | } |
---|
1165 | |
---|
1166 | // tail reduction for SBA |
---|
1167 | poly redtailSba (LObject* L, int pos, kStrategy strat, BOOLEAN withT, BOOLEAN normalize) |
---|
1168 | { |
---|
1169 | #define REDTAIL_CANONICALIZE 100 |
---|
1170 | strat->redTailChange=FALSE; |
---|
1171 | if (strat->noTailReduction) return L->GetLmCurrRing(); |
---|
1172 | poly h, p; |
---|
1173 | p = h = L->GetLmTailRing(); |
---|
1174 | if ((h==NULL) || (pNext(h)==NULL)) |
---|
1175 | return L->GetLmCurrRing(); |
---|
1176 | |
---|
1177 | TObject* With; |
---|
1178 | // placeholder in case strat->tl < 0 |
---|
1179 | TObject With_s(strat->tailRing); |
---|
1180 | |
---|
1181 | LObject Ln(pNext(h), strat->tailRing); |
---|
1182 | Ln.sig = L->sig; |
---|
1183 | Ln.sevSig = L->sevSig; |
---|
1184 | Ln.pLength = L->GetpLength() - 1; |
---|
1185 | |
---|
1186 | pNext(h) = NULL; |
---|
1187 | if (L->p != NULL) pNext(L->p) = NULL; |
---|
1188 | L->pLength = 1; |
---|
1189 | |
---|
1190 | Ln.PrepareRed(strat->use_buckets); |
---|
1191 | |
---|
1192 | int cnt=REDTAIL_CANONICALIZE; |
---|
1193 | while(!Ln.IsNull()) |
---|
1194 | { |
---|
1195 | loop |
---|
1196 | { |
---|
1197 | if(rField_is_Ring(currRing) && strat->sigdrop) |
---|
1198 | break; |
---|
1199 | Ln.SetShortExpVector(); |
---|
1200 | if (withT) |
---|
1201 | { |
---|
1202 | int j; |
---|
1203 | j = kFindDivisibleByInT(strat, &Ln); |
---|
1204 | if (j < 0) break; |
---|
1205 | With = &(strat->T[j]); |
---|
1206 | } |
---|
1207 | else |
---|
1208 | { |
---|
1209 | With = kFindDivisibleByInS(strat, pos, &Ln, &With_s); |
---|
1210 | if (With == NULL) break; |
---|
1211 | } |
---|
1212 | cnt--; |
---|
1213 | if (cnt==0) |
---|
1214 | { |
---|
1215 | cnt=REDTAIL_CANONICALIZE; |
---|
1216 | /*poly tmp=*/Ln.CanonicalizeP(); |
---|
1217 | if (normalize && !rField_is_Ring(currRing)) |
---|
1218 | { |
---|
1219 | Ln.Normalize(); |
---|
1220 | //pNormalize(tmp); |
---|
1221 | //if (TEST_OPT_PROT) { PrintS("n"); mflush(); } |
---|
1222 | } |
---|
1223 | } |
---|
1224 | if (normalize && (!TEST_OPT_INTSTRATEGY) && !rField_is_Ring(currRing) && (!nIsOne(pGetCoeff(With->p)))) |
---|
1225 | { |
---|
1226 | With->pNorm(); |
---|
1227 | } |
---|
1228 | strat->redTailChange=TRUE; |
---|
1229 | #ifdef ADIDEBUG |
---|
1230 | printf("\nWill TAILreduce * with *:\n");p_Write(Ln.p,strat->tailRing);pWrite(Ln.sig); |
---|
1231 | p_Write(With->p,strat->tailRing);pWrite(With->sig);pWrite(L->sig); |
---|
1232 | #endif |
---|
1233 | int ret = ksReducePolyTailSig(L, With, &Ln, strat); |
---|
1234 | if(rField_is_Ring(currRing)) |
---|
1235 | L->sig = Ln.sig; |
---|
1236 | //Because Ln.sig is set to L->sig, but in ksReducePolyTailSig -> ksReducePolySig |
---|
1237 | // I delete it an then set Ln.sig. Hence L->sig is lost |
---|
1238 | #ifdef ADIDEBUG |
---|
1239 | printf("\nAfter small TAILreduce:\n");pWrite(Ln.p);pWrite(Ln.sig);pWrite(L->sig); |
---|
1240 | #endif |
---|
1241 | #if SBA_PRINT_REDUCTION_STEPS |
---|
1242 | if (ret != 3) |
---|
1243 | sba_reduction_steps++; |
---|
1244 | #endif |
---|
1245 | #if SBA_PRINT_OPERATIONS |
---|
1246 | if (ret != 3) |
---|
1247 | sba_operations += pLength(With->p); |
---|
1248 | #endif |
---|
1249 | if (ret) |
---|
1250 | { |
---|
1251 | // reducing the tail would violate the exp bound |
---|
1252 | // set a flag and hope for a retry (in bba) |
---|
1253 | strat->completeReduce_retry=TRUE; |
---|
1254 | if ((Ln.p != NULL) && (Ln.t_p != NULL)) Ln.p=NULL; |
---|
1255 | do |
---|
1256 | { |
---|
1257 | pNext(h) = Ln.LmExtractAndIter(); |
---|
1258 | pIter(h); |
---|
1259 | L->pLength++; |
---|
1260 | } while (!Ln.IsNull()); |
---|
1261 | goto all_done; |
---|
1262 | } |
---|
1263 | if (Ln.IsNull()) goto all_done; |
---|
1264 | if (! withT) With_s.Init(currRing); |
---|
1265 | if(rField_is_Ring(currRing) && strat->sigdrop) |
---|
1266 | { |
---|
1267 | //Cannot break the loop here so easily |
---|
1268 | break; |
---|
1269 | } |
---|
1270 | } |
---|
1271 | pNext(h) = Ln.LmExtractAndIter(); |
---|
1272 | pIter(h); |
---|
1273 | if(!rField_is_Ring(currRing)) |
---|
1274 | pNormalize(h); |
---|
1275 | L->pLength++; |
---|
1276 | } |
---|
1277 | all_done: |
---|
1278 | Ln.Delete(); |
---|
1279 | if (L->p != NULL) pNext(L->p) = pNext(p); |
---|
1280 | |
---|
1281 | if (strat->redTailChange) |
---|
1282 | { |
---|
1283 | L->length = 0; |
---|
1284 | } |
---|
1285 | //if (TEST_OPT_PROT) { PrintS("N"); mflush(); } |
---|
1286 | //L->Normalize(); // HANNES: should have a test |
---|
1287 | kTest_L(L); |
---|
1288 | return L->GetLmCurrRing(); |
---|
1289 | } |
---|
1290 | |
---|
1291 | /*2 |
---|
1292 | * reduction procedure for the inhomogeneous case |
---|
1293 | * and not a degree-ordering |
---|
1294 | */ |
---|
1295 | int redLazy (LObject* h,kStrategy strat) |
---|
1296 | { |
---|
1297 | if (strat->tl<0) return 1; |
---|
1298 | int at,i,ii,li; |
---|
1299 | int j = 0; |
---|
1300 | int pass = 0; |
---|
1301 | assume(h->pFDeg() == h->FDeg); |
---|
1302 | long reddeg = h->GetpFDeg(); |
---|
1303 | long d; |
---|
1304 | unsigned long not_sev; |
---|
1305 | |
---|
1306 | h->SetShortExpVector(); |
---|
1307 | poly h_p = h->GetLmTailRing(); |
---|
1308 | not_sev = ~ h->sev; |
---|
1309 | loop |
---|
1310 | { |
---|
1311 | j = kFindDivisibleByInT(strat, h); |
---|
1312 | if (j < 0) return 1; |
---|
1313 | |
---|
1314 | li = strat->T[j].pLength; |
---|
1315 | #if 0 |
---|
1316 | if (li==0) |
---|
1317 | { |
---|
1318 | li=strat->T[j].pLength=pLength(strat->T[j].p); |
---|
1319 | } |
---|
1320 | #endif |
---|
1321 | ii = j; |
---|
1322 | /* |
---|
1323 | * the polynomial to reduce with (up to the moment) is; |
---|
1324 | * pi with length li |
---|
1325 | */ |
---|
1326 | |
---|
1327 | i = j; |
---|
1328 | #if 1 |
---|
1329 | if (TEST_OPT_LENGTH) |
---|
1330 | loop |
---|
1331 | { |
---|
1332 | /*- search the shortest possible with respect to length -*/ |
---|
1333 | i++; |
---|
1334 | if (i > strat->tl) |
---|
1335 | break; |
---|
1336 | if (li<=1) |
---|
1337 | break; |
---|
1338 | #if 0 |
---|
1339 | if (strat->T[i].pLength==0) |
---|
1340 | { |
---|
1341 | PrintS("!"); |
---|
1342 | strat->T[i].pLength=pLength(strat->T[i].p); |
---|
1343 | } |
---|
1344 | #endif |
---|
1345 | if ((strat->T[i].pLength < li) |
---|
1346 | && |
---|
1347 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
1348 | h_p, not_sev, strat->tailRing)) |
---|
1349 | { |
---|
1350 | /* |
---|
1351 | * the polynomial to reduce with is now; |
---|
1352 | */ |
---|
1353 | PrintS("+"); |
---|
1354 | li = strat->T[i].pLength; |
---|
1355 | ii = i; |
---|
1356 | } |
---|
1357 | } |
---|
1358 | #endif |
---|
1359 | |
---|
1360 | /* |
---|
1361 | * end of search: have to reduce with pi |
---|
1362 | */ |
---|
1363 | |
---|
1364 | |
---|
1365 | #ifdef KDEBUG |
---|
1366 | if (TEST_OPT_DEBUG) |
---|
1367 | { |
---|
1368 | PrintS("red:"); |
---|
1369 | h->wrp(); |
---|
1370 | PrintS(" with "); |
---|
1371 | strat->T[ii].wrp(); |
---|
1372 | } |
---|
1373 | #endif |
---|
1374 | |
---|
1375 | ksReducePoly(h, &(strat->T[ii]), NULL, NULL, strat); |
---|
1376 | #if SBA_PRINT_REDUCTION_STEPS |
---|
1377 | sba_interreduction_steps++; |
---|
1378 | #endif |
---|
1379 | #if SBA_PRINT_OPERATIONS |
---|
1380 | sba_interreduction_operations += pLength(strat->T[ii].p); |
---|
1381 | #endif |
---|
1382 | |
---|
1383 | #ifdef KDEBUG |
---|
1384 | if (TEST_OPT_DEBUG) |
---|
1385 | { |
---|
1386 | PrintS("\nto "); |
---|
1387 | h->wrp(); |
---|
1388 | PrintLn(); |
---|
1389 | } |
---|
1390 | #endif |
---|
1391 | |
---|
1392 | h_p=h->GetLmTailRing(); |
---|
1393 | |
---|
1394 | if (h_p == NULL) |
---|
1395 | { |
---|
1396 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
1397 | #ifdef KDEBUG |
---|
1398 | h->lcm=NULL; |
---|
1399 | #endif |
---|
1400 | return 0; |
---|
1401 | } |
---|
1402 | h->SetShortExpVector(); |
---|
1403 | not_sev = ~ h->sev; |
---|
1404 | d = h->SetpFDeg(); |
---|
1405 | /*- try to reduce the s-polynomial -*/ |
---|
1406 | pass++; |
---|
1407 | if (//!TEST_OPT_REDTHROUGH && |
---|
1408 | (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
1409 | { |
---|
1410 | h->SetLmCurrRing(); |
---|
1411 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
1412 | if (at <= strat->Ll) |
---|
1413 | { |
---|
1414 | #if 1 |
---|
1415 | int dummy=strat->sl; |
---|
1416 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
1417 | return 1; |
---|
1418 | #endif |
---|
1419 | #ifdef KDEBUG |
---|
1420 | if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at); |
---|
1421 | #endif |
---|
1422 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
1423 | h->Clear(); |
---|
1424 | return -1; |
---|
1425 | } |
---|
1426 | } |
---|
1427 | else if (d != reddeg) |
---|
1428 | { |
---|
1429 | if (d>=(long)strat->tailRing->bitmask) |
---|
1430 | { |
---|
1431 | if (h->pTotalDeg() >= (long)strat->tailRing->bitmask) |
---|
1432 | { |
---|
1433 | strat->overflow=TRUE; |
---|
1434 | //Print("OVERFLOW in redLazy d=%ld, max=%ld\n",d,strat->tailRing->bitmask); |
---|
1435 | h->GetP(); |
---|
1436 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
1437 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
1438 | h->Clear(); |
---|
1439 | return -1; |
---|
1440 | } |
---|
1441 | } |
---|
1442 | else if ((TEST_OPT_PROT) && (strat->Ll < 0)) |
---|
1443 | { |
---|
1444 | Print(".%ld",d);mflush(); |
---|
1445 | reddeg = d; |
---|
1446 | } |
---|
1447 | } |
---|
1448 | } |
---|
1449 | } |
---|
1450 | /*2 |
---|
1451 | * reduction procedure for the sugar-strategy (honey) |
---|
1452 | * reduces h with elements from T choosing first possible |
---|
1453 | * element in T with respect to the given ecart |
---|
1454 | */ |
---|
1455 | int redHoney (LObject* h, kStrategy strat) |
---|
1456 | { |
---|
1457 | if (strat->tl<0) return 1; |
---|
1458 | //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED! |
---|
1459 | assume(h->FDeg == h->pFDeg()); |
---|
1460 | poly h_p; |
---|
1461 | int i,j,at,pass,ei, ii, h_d; |
---|
1462 | unsigned long not_sev; |
---|
1463 | long reddeg,d; |
---|
1464 | |
---|
1465 | pass = j = 0; |
---|
1466 | d = reddeg = h->GetpFDeg() + h->ecart; |
---|
1467 | h->SetShortExpVector(); |
---|
1468 | int li; |
---|
1469 | h_p = h->GetLmTailRing(); |
---|
1470 | not_sev = ~ h->sev; |
---|
1471 | |
---|
1472 | h->PrepareRed(strat->use_buckets); |
---|
1473 | loop |
---|
1474 | { |
---|
1475 | j=kFindDivisibleByInT(strat, h); |
---|
1476 | if (j < 0) return 1; |
---|
1477 | |
---|
1478 | ei = strat->T[j].ecart; |
---|
1479 | li = strat->T[j].pLength; |
---|
1480 | ii = j; |
---|
1481 | /* |
---|
1482 | * the polynomial to reduce with (up to the moment) is; |
---|
1483 | * pi with ecart ei (T[ii]) |
---|
1484 | */ |
---|
1485 | i = j; |
---|
1486 | if (TEST_OPT_LENGTH) |
---|
1487 | loop |
---|
1488 | { |
---|
1489 | /*- takes the first possible with respect to ecart -*/ |
---|
1490 | i++; |
---|
1491 | if (i > strat->tl) |
---|
1492 | break; |
---|
1493 | //if (ei < h->ecart) |
---|
1494 | // break; |
---|
1495 | if (li<=1) |
---|
1496 | break; |
---|
1497 | if ((((strat->T[i].ecart < ei) && (ei> h->ecart)) |
---|
1498 | || ((strat->T[i].ecart <= h->ecart) && (strat->T[i].pLength < li))) |
---|
1499 | && |
---|
1500 | p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i], |
---|
1501 | h_p, not_sev, strat->tailRing)) |
---|
1502 | { |
---|
1503 | /* |
---|
1504 | * the polynomial to reduce with is now; |
---|
1505 | */ |
---|
1506 | ei = strat->T[i].ecart; |
---|
1507 | li = strat->T[i].pLength; |
---|
1508 | ii = i; |
---|
1509 | } |
---|
1510 | } |
---|
1511 | |
---|
1512 | /* |
---|
1513 | * end of search: have to reduce with pi |
---|
1514 | */ |
---|
1515 | if (!TEST_OPT_REDTHROUGH && (pass!=0) && (ei > h->ecart)) |
---|
1516 | { |
---|
1517 | h->GetTP(); // clears bucket |
---|
1518 | h->SetLmCurrRing(); |
---|
1519 | /* |
---|
1520 | * It is not possible to reduce h with smaller ecart; |
---|
1521 | * if possible h goes to the lazy-set L,i.e |
---|
1522 | * if its position in L would be not the last one |
---|
1523 | */ |
---|
1524 | if (strat->Ll >= 0) /* L is not empty */ |
---|
1525 | { |
---|
1526 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
1527 | if(at <= strat->Ll) |
---|
1528 | /*- h will not become the next element to reduce -*/ |
---|
1529 | { |
---|
1530 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
1531 | #ifdef KDEBUG |
---|
1532 | if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at); |
---|
1533 | #endif |
---|
1534 | h->Clear(); |
---|
1535 | return -1; |
---|
1536 | } |
---|
1537 | } |
---|
1538 | } |
---|
1539 | #ifdef KDEBUG |
---|
1540 | if (TEST_OPT_DEBUG) |
---|
1541 | { |
---|
1542 | PrintS("red:"); |
---|
1543 | h->wrp(); |
---|
1544 | Print("\nwith T[%d]:",ii); |
---|
1545 | strat->T[ii].wrp(); |
---|
1546 | } |
---|
1547 | #endif |
---|
1548 | assume(strat->fromT == FALSE); |
---|
1549 | |
---|
1550 | number coef; |
---|
1551 | ksReducePoly(h,&(strat->T[ii]),strat->kNoetherTail(),&coef,strat); |
---|
1552 | #if SBA_PRINT_REDUCTION_STEPS |
---|
1553 | sba_interreduction_steps++; |
---|
1554 | #endif |
---|
1555 | #if SBA_PRINT_OPERATIONS |
---|
1556 | sba_interreduction_operations += pLength(strat->T[ii].p); |
---|
1557 | #endif |
---|
1558 | #ifdef KDEBUG |
---|
1559 | if (TEST_OPT_DEBUG) |
---|
1560 | { |
---|
1561 | PrintS("\nto:"); |
---|
1562 | h->wrp(); |
---|
1563 | PrintLn(); |
---|
1564 | } |
---|
1565 | #endif |
---|
1566 | if(h->IsNull()) |
---|
1567 | { |
---|
1568 | h->Clear(); |
---|
1569 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
1570 | #ifdef KDEBUG |
---|
1571 | h->lcm=NULL; |
---|
1572 | #endif |
---|
1573 | return 0; |
---|
1574 | } |
---|
1575 | if (TEST_OPT_IDLIFT) |
---|
1576 | { |
---|
1577 | if (h->p!=NULL) |
---|
1578 | { |
---|
1579 | if(p_GetComp(h->p,currRing)>strat->syzComp) |
---|
1580 | { |
---|
1581 | h->Delete(); |
---|
1582 | return 0; |
---|
1583 | } |
---|
1584 | } |
---|
1585 | else if (h->t_p!=NULL) |
---|
1586 | { |
---|
1587 | if(p_GetComp(h->t_p,strat->tailRing)>strat->syzComp) |
---|
1588 | { |
---|
1589 | h->Delete(); |
---|
1590 | return 0; |
---|
1591 | } |
---|
1592 | } |
---|
1593 | } |
---|
1594 | h->SetShortExpVector(); |
---|
1595 | not_sev = ~ h->sev; |
---|
1596 | h_d = h->SetpFDeg(); |
---|
1597 | /* compute the ecart */ |
---|
1598 | if (ei <= h->ecart) |
---|
1599 | h->ecart = d-h_d; |
---|
1600 | else |
---|
1601 | h->ecart = d-h_d+ei-h->ecart; |
---|
1602 | |
---|
1603 | /* |
---|
1604 | * try to reduce the s-polynomial h |
---|
1605 | *test first whether h should go to the lazyset L |
---|
1606 | *-if the degree jumps |
---|
1607 | *-if the number of pre-defined reductions jumps |
---|
1608 | */ |
---|
1609 | pass++; |
---|
1610 | d = h_d + h->ecart; |
---|
1611 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass))) |
---|
1612 | { |
---|
1613 | h->GetTP(); // clear bucket |
---|
1614 | h->SetLmCurrRing(); |
---|
1615 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
1616 | if (at <= strat->Ll) |
---|
1617 | { |
---|
1618 | int dummy=strat->sl; |
---|
1619 | if (kFindDivisibleByInS(strat, &dummy, h) < 0) |
---|
1620 | return 1; |
---|
1621 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
1622 | #ifdef KDEBUG |
---|
1623 | if (TEST_OPT_DEBUG) |
---|
1624 | Print(" degree jumped: -> L%d\n",at); |
---|
1625 | #endif |
---|
1626 | h->Clear(); |
---|
1627 | return -1; |
---|
1628 | } |
---|
1629 | } |
---|
1630 | else if (d > reddeg) |
---|
1631 | { |
---|
1632 | if (d>=(long)strat->tailRing->bitmask) |
---|
1633 | { |
---|
1634 | if (h->pTotalDeg()+h->ecart >= (long)strat->tailRing->bitmask) |
---|
1635 | { |
---|
1636 | strat->overflow=TRUE; |
---|
1637 | //Print("OVERFLOW in redHoney d=%ld, max=%ld\n",d,strat->tailRing->bitmask); |
---|
1638 | h->GetP(); |
---|
1639 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
1640 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
1641 | h->Clear(); |
---|
1642 | return -1; |
---|
1643 | } |
---|
1644 | } |
---|
1645 | else if (TEST_OPT_PROT && (strat->Ll < 0) ) |
---|
1646 | { |
---|
1647 | //h->wrp(); Print("<%d>\n",h->GetpLength()); |
---|
1648 | reddeg = d; |
---|
1649 | Print(".%ld",d); mflush(); |
---|
1650 | } |
---|
1651 | } |
---|
1652 | } |
---|
1653 | } |
---|
1654 | |
---|
1655 | /*2 |
---|
1656 | * reduction procedure for the normal form |
---|
1657 | */ |
---|
1658 | |
---|
1659 | poly redNF (poly h,int &max_ind,int nonorm,kStrategy strat) |
---|
1660 | { |
---|
1661 | #define REDNF_CANONICALIZE 60 |
---|
1662 | if (h==NULL) return NULL; |
---|
1663 | int j; |
---|
1664 | int cnt=REDNF_CANONICALIZE; |
---|
1665 | max_ind=strat->sl; |
---|
1666 | |
---|
1667 | if (0 > strat->sl) |
---|
1668 | { |
---|
1669 | return h; |
---|
1670 | } |
---|
1671 | LObject P(h); |
---|
1672 | P.SetShortExpVector(); |
---|
1673 | P.bucket = kBucketCreate(currRing); |
---|
1674 | kBucketInit(P.bucket,P.p,pLength(P.p)); |
---|
1675 | kbTest(P.bucket); |
---|
1676 | #ifdef HAVE_RINGS |
---|
1677 | BOOLEAN is_ring = rField_is_Ring(currRing); |
---|
1678 | #endif |
---|
1679 | #ifdef KDEBUG |
---|
1680 | // if (TEST_OPT_DEBUG) |
---|
1681 | // { |
---|
1682 | // PrintS("redNF: starting S:\n"); |
---|
1683 | // for( j = 0; j <= max_ind; j++ ) |
---|
1684 | // { |
---|
1685 | // Print("S[%d] (of size: %d): ", j, pSize(strat->S[j])); |
---|
1686 | // pWrite(strat->S[j]); |
---|
1687 | // } |
---|
1688 | // }; |
---|
1689 | #endif |
---|
1690 | |
---|
1691 | loop |
---|
1692 | { |
---|
1693 | j=kFindDivisibleByInS(strat,&max_ind,&P); |
---|
1694 | if (j>=0) |
---|
1695 | { |
---|
1696 | #ifdef HAVE_RINGS |
---|
1697 | if (!is_ring) |
---|
1698 | { |
---|
1699 | #endif |
---|
1700 | int sl=pSize(strat->S[j]); |
---|
1701 | int jj=j; |
---|
1702 | loop |
---|
1703 | { |
---|
1704 | int sll; |
---|
1705 | jj=kFindNextDivisibleByInS(strat,jj+1,max_ind,&P); |
---|
1706 | if (jj<0) break; |
---|
1707 | sll=pSize(strat->S[jj]); |
---|
1708 | if (sll<sl) |
---|
1709 | { |
---|
1710 | #ifdef KDEBUG |
---|
1711 | if (TEST_OPT_DEBUG) Print("better(S%d:%d -> S%d:%d)\n",j,sl,jj,sll); |
---|
1712 | #endif |
---|
1713 | //else if (TEST_OPT_PROT) { PrintS("b"); mflush(); } |
---|
1714 | j=jj; |
---|
1715 | sl=sll; |
---|
1716 | } |
---|
1717 | } |
---|
1718 | if ((nonorm==0) && (!nIsOne(pGetCoeff(strat->S[j])))) |
---|
1719 | { |
---|
1720 | pNorm(strat->S[j]); |
---|
1721 | //if (TEST_OPT_PROT) { PrintS("n"); mflush(); } |
---|
1722 | } |
---|
1723 | #ifdef HAVE_RINGS |
---|
1724 | } |
---|
1725 | #endif |
---|
1726 | nNormalize(pGetCoeff(P.p)); |
---|
1727 | #ifdef KDEBUG |
---|
1728 | if (TEST_OPT_DEBUG) |
---|
1729 | { |
---|
1730 | PrintS("red:"); |
---|
1731 | wrp(h); |
---|
1732 | PrintS(" with "); |
---|
1733 | wrp(strat->S[j]); |
---|
1734 | } |
---|
1735 | #endif |
---|
1736 | #ifdef HAVE_PLURAL |
---|
1737 | if (rIsPluralRing(currRing)) |
---|
1738 | { |
---|
1739 | number coef; |
---|
1740 | nc_kBucketPolyRed(P.bucket,strat->S[j],&coef); |
---|
1741 | nDelete(&coef); |
---|
1742 | } |
---|
1743 | else |
---|
1744 | #endif |
---|
1745 | { |
---|
1746 | number coef; |
---|
1747 | coef=kBucketPolyRed(P.bucket,strat->S[j],pLength(strat->S[j]),strat->kNoether); |
---|
1748 | nDelete(&coef); |
---|
1749 | } |
---|
1750 | cnt--; |
---|
1751 | if (cnt==0) |
---|
1752 | { |
---|
1753 | kBucketCanonicalize(P.bucket); |
---|
1754 | cnt=REDNF_CANONICALIZE; |
---|
1755 | } |
---|
1756 | h = kBucketGetLm(P.bucket); // FRAGE OLIVER |
---|
1757 | if (h==NULL) |
---|
1758 | { |
---|
1759 | kBucketDestroy(&P.bucket); |
---|
1760 | |
---|
1761 | #ifdef KDEBUG |
---|
1762 | // if (TEST_OPT_DEBUG) |
---|
1763 | // { |
---|
1764 | // PrintS("redNF: starting S:\n"); |
---|
1765 | // for( j = 0; j <= max_ind; j++ ) |
---|
1766 | // { |
---|
1767 | // Print("S[%d] (of size: %d): ", j, pSize(strat->S[j])); |
---|
1768 | // pWrite(strat->S[j]); |
---|
1769 | // } |
---|
1770 | // }; |
---|
1771 | #endif |
---|
1772 | |
---|
1773 | return NULL; |
---|
1774 | } |
---|
1775 | kbTest(P.bucket); |
---|
1776 | P.p=h; |
---|
1777 | P.t_p=NULL; |
---|
1778 | P.SetShortExpVector(); |
---|
1779 | #ifdef KDEBUG |
---|
1780 | if (TEST_OPT_DEBUG) |
---|
1781 | { |
---|
1782 | PrintS("\nto:"); |
---|
1783 | wrp(h); |
---|
1784 | PrintLn(); |
---|
1785 | } |
---|
1786 | #endif |
---|
1787 | } |
---|
1788 | else |
---|
1789 | { |
---|
1790 | P.p=kBucketClear(P.bucket); |
---|
1791 | kBucketDestroy(&P.bucket); |
---|
1792 | pNormalize(P.p); |
---|
1793 | |
---|
1794 | #ifdef KDEBUG |
---|
1795 | // if (TEST_OPT_DEBUG) |
---|
1796 | // { |
---|
1797 | // PrintS("redNF: starting S:\n"); |
---|
1798 | // for( j = 0; j <= max_ind; j++ ) |
---|
1799 | // { |
---|
1800 | // Print("S[%d] (of size: %d): ", j, pSize(strat->S[j])); |
---|
1801 | // pWrite(strat->S[j]); |
---|
1802 | // } |
---|
1803 | // }; |
---|
1804 | #endif |
---|
1805 | |
---|
1806 | return P.p; |
---|
1807 | } |
---|
1808 | } |
---|
1809 | } |
---|
1810 | |
---|
1811 | /*2 |
---|
1812 | * reduction procedure from global case but with jet bound |
---|
1813 | */ |
---|
1814 | |
---|
1815 | poly redNFBound (poly h,int &max_ind,int nonorm,kStrategy strat,int bound) |
---|
1816 | { |
---|
1817 | h = pJet(h,bound); |
---|
1818 | if (h==NULL) return NULL; |
---|
1819 | int j; |
---|
1820 | max_ind=strat->sl; |
---|
1821 | |
---|
1822 | if (0 > strat->sl) |
---|
1823 | { |
---|
1824 | return h; |
---|
1825 | } |
---|
1826 | LObject P(h); |
---|
1827 | P.SetShortExpVector(); |
---|
1828 | P.bucket = kBucketCreate(currRing); |
---|
1829 | kBucketInit(P.bucket,P.p,pLength(P.p)); |
---|
1830 | kbTest(P.bucket); |
---|
1831 | #ifdef HAVE_RINGS |
---|
1832 | BOOLEAN is_ring = rField_is_Ring(currRing); |
---|
1833 | #endif |
---|
1834 | #ifdef KDEBUG |
---|
1835 | // if (TEST_OPT_DEBUG) |
---|
1836 | // { |
---|
1837 | // PrintS("redNF: starting S:\n"); |
---|
1838 | // for( j = 0; j <= max_ind; j++ ) |
---|
1839 | // { |
---|
1840 | // Print("S[%d] (of size: %d): ", j, pSize(strat->S[j])); |
---|
1841 | // pWrite(strat->S[j]); |
---|
1842 | // } |
---|
1843 | // }; |
---|
1844 | #endif |
---|
1845 | |
---|
1846 | loop |
---|
1847 | { |
---|
1848 | j=kFindDivisibleByInS(strat,&max_ind,&P); |
---|
1849 | if (j>=0) |
---|
1850 | { |
---|
1851 | #ifdef HAVE_RINGS |
---|
1852 | if (!is_ring) |
---|
1853 | { |
---|
1854 | #endif |
---|
1855 | int sl=pSize(strat->S[j]); |
---|
1856 | int jj=j; |
---|
1857 | loop |
---|
1858 | { |
---|
1859 | int sll; |
---|
1860 | jj=kFindNextDivisibleByInS(strat,jj+1,max_ind,&P); |
---|
1861 | if (jj<0) break; |
---|
1862 | sll=pSize(strat->S[jj]); |
---|
1863 | if (sll<sl) |
---|
1864 | { |
---|
1865 | #ifdef KDEBUG |
---|
1866 | if (TEST_OPT_DEBUG) Print("better(S%d:%d -> S%d:%d)\n",j,sl,jj,sll); |
---|
1867 | #endif |
---|
1868 | //else if (TEST_OPT_PROT) { PrintS("b"); mflush(); } |
---|
1869 | j=jj; |
---|
1870 | sl=sll; |
---|
1871 | } |
---|
1872 | } |
---|
1873 | if ((nonorm==0) && (!nIsOne(pGetCoeff(strat->S[j])))) |
---|
1874 | { |
---|
1875 | pNorm(strat->S[j]); |
---|
1876 | //if (TEST_OPT_PROT) { PrintS("n"); mflush(); } |
---|
1877 | } |
---|
1878 | #ifdef HAVE_RINGS |
---|
1879 | } |
---|
1880 | #endif |
---|
1881 | nNormalize(pGetCoeff(P.p)); |
---|
1882 | #ifdef KDEBUG |
---|
1883 | if (TEST_OPT_DEBUG) |
---|
1884 | { |
---|
1885 | PrintS("red:"); |
---|
1886 | wrp(h); |
---|
1887 | PrintS(" with "); |
---|
1888 | wrp(strat->S[j]); |
---|
1889 | } |
---|
1890 | #endif |
---|
1891 | #ifdef HAVE_PLURAL |
---|
1892 | if (rIsPluralRing(currRing)) |
---|
1893 | { |
---|
1894 | number coef; |
---|
1895 | nc_kBucketPolyRed(P.bucket,strat->S[j],&coef); |
---|
1896 | nDelete(&coef); |
---|
1897 | } |
---|
1898 | else |
---|
1899 | #endif |
---|
1900 | { |
---|
1901 | number coef; |
---|
1902 | coef=kBucketPolyRed(P.bucket,strat->S[j],pLength(strat->S[j]),strat->kNoether); |
---|
1903 | P.p = kBucketClear(P.bucket); |
---|
1904 | P.p = pJet(P.p,bound); |
---|
1905 | if(!P.IsNull()) |
---|
1906 | { |
---|
1907 | kBucketDestroy(&P.bucket); |
---|
1908 | P.SetShortExpVector(); |
---|
1909 | P.bucket = kBucketCreate(currRing); |
---|
1910 | kBucketInit(P.bucket,P.p,pLength(P.p)); |
---|
1911 | } |
---|
1912 | nDelete(&coef); |
---|
1913 | } |
---|
1914 | h = kBucketGetLm(P.bucket); // FRAGE OLIVER |
---|
1915 | if (h==NULL) |
---|
1916 | { |
---|
1917 | kBucketDestroy(&P.bucket); |
---|
1918 | |
---|
1919 | #ifdef KDEBUG |
---|
1920 | // if (TEST_OPT_DEBUG) |
---|
1921 | // { |
---|
1922 | // PrintS("redNF: starting S:\n"); |
---|
1923 | // for( j = 0; j <= max_ind; j++ ) |
---|
1924 | // { |
---|
1925 | // Print("S[%d] (of size: %d): ", j, pSize(strat->S[j])); |
---|
1926 | // pWrite(strat->S[j]); |
---|
1927 | // } |
---|
1928 | // }; |
---|
1929 | #endif |
---|
1930 | |
---|
1931 | return NULL; |
---|
1932 | } |
---|
1933 | kbTest(P.bucket); |
---|
1934 | P.p=h; |
---|
1935 | P.t_p=NULL; |
---|
1936 | P.SetShortExpVector(); |
---|
1937 | #ifdef KDEBUG |
---|
1938 | if (TEST_OPT_DEBUG) |
---|
1939 | { |
---|
1940 | PrintS("\nto:"); |
---|
1941 | wrp(h); |
---|
1942 | PrintLn(); |
---|
1943 | } |
---|
1944 | #endif |
---|
1945 | } |
---|
1946 | else |
---|
1947 | { |
---|
1948 | P.p=kBucketClear(P.bucket); |
---|
1949 | kBucketDestroy(&P.bucket); |
---|
1950 | pNormalize(P.p); |
---|
1951 | |
---|
1952 | #ifdef KDEBUG |
---|
1953 | // if (TEST_OPT_DEBUG) |
---|
1954 | // { |
---|
1955 | // PrintS("redNF: starting S:\n"); |
---|
1956 | // for( j = 0; j <= max_ind; j++ ) |
---|
1957 | // { |
---|
1958 | // Print("S[%d] (of size: %d): ", j, pSize(strat->S[j])); |
---|
1959 | // pWrite(strat->S[j]); |
---|
1960 | // } |
---|
1961 | // }; |
---|
1962 | #endif |
---|
1963 | |
---|
1964 | return P.p; |
---|
1965 | } |
---|
1966 | } |
---|
1967 | } |
---|
1968 | |
---|
1969 | void kDebugPrint(kStrategy strat); |
---|
1970 | |
---|
1971 | ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat) |
---|
1972 | { |
---|
1973 | int red_result = 1; |
---|
1974 | int olddeg,reduc; |
---|
1975 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
1976 | BOOLEAN withT = FALSE; |
---|
1977 | BITSET save; |
---|
1978 | SI_SAVE_OPT1(save); |
---|
1979 | |
---|
1980 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
1981 | if(rField_is_Ring(currRing)) |
---|
1982 | initBuchMoraPosRing(strat); |
---|
1983 | else |
---|
1984 | initBuchMoraPos(strat); |
---|
1985 | initHilbCrit(F,Q,&hilb,strat); |
---|
1986 | initBba(strat); |
---|
1987 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
1988 | /*Shdl=*/initBuchMora(F, Q,strat); |
---|
1989 | if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank); |
---|
1990 | reduc = olddeg = 0; |
---|
1991 | |
---|
1992 | #ifndef NO_BUCKETS |
---|
1993 | if (!TEST_OPT_NOT_BUCKETS) |
---|
1994 | strat->use_buckets = 1; |
---|
1995 | #endif |
---|
1996 | // redtailBBa against T for inhomogenous input |
---|
1997 | if (!TEST_OPT_OLDSTD) |
---|
1998 | withT = ! strat->homog; |
---|
1999 | |
---|
2000 | // strat->posInT = posInT_pLength; |
---|
2001 | kTest_TS(strat); |
---|
2002 | |
---|
2003 | #ifdef HAVE_TAIL_RING |
---|
2004 | if(!idIs0(F) &&(!rField_is_Ring(currRing))) // create strong gcd poly computes with tailring and S[i] ->to be fixed |
---|
2005 | kStratInitChangeTailRing(strat); |
---|
2006 | #endif |
---|
2007 | if (BVERBOSE(23)) |
---|
2008 | { |
---|
2009 | if (test_PosInT!=NULL) strat->posInT=test_PosInT; |
---|
2010 | if (test_PosInL!=NULL) strat->posInL=test_PosInL; |
---|
2011 | kDebugPrint(strat); |
---|
2012 | } |
---|
2013 | |
---|
2014 | |
---|
2015 | #ifdef KDEBUG |
---|
2016 | //kDebugPrint(strat); |
---|
2017 | #endif |
---|
2018 | /* compute------------------------------------------------------- */ |
---|
2019 | while (strat->Ll >= 0) |
---|
2020 | { |
---|
2021 | #ifdef ADIDEBUG |
---|
2022 | printf("\n ------------------------NEW LOOP\n"); |
---|
2023 | printf("\nShdl = \n"); |
---|
2024 | #if 0 |
---|
2025 | idPrint(strat->Shdl); |
---|
2026 | #else |
---|
2027 | for(int ii = 0; ii<=strat->sl;ii++) |
---|
2028 | p_Write(strat->S[ii],strat->tailRing); |
---|
2029 | #endif |
---|
2030 | printf("\n list L\n"); |
---|
2031 | int iii; |
---|
2032 | #if 1 |
---|
2033 | for(iii = 0; iii<= strat->Ll; iii++) |
---|
2034 | { |
---|
2035 | printf("L[%i]:",iii); |
---|
2036 | p_Write(strat->L[iii].p, currRing); |
---|
2037 | p_Write(strat->L[iii].p1, currRing); |
---|
2038 | p_Write(strat->L[iii].p2, currRing); |
---|
2039 | } |
---|
2040 | #else |
---|
2041 | { |
---|
2042 | printf("L[%i]:",strat->Ll); |
---|
2043 | p_Write(strat->L[strat->Ll].p, strat->tailRing); |
---|
2044 | p_Write(strat->L[strat->Ll].p1, strat->tailRing); |
---|
2045 | p_Write(strat->L[strat->Ll].p2, strat->tailRing); |
---|
2046 | } |
---|
2047 | #endif |
---|
2048 | #if 0 |
---|
2049 | for(iii = 0; iii<= strat->Bl; iii++) |
---|
2050 | { |
---|
2051 | printf("B[%i]:",iii); |
---|
2052 | p_Write(strat->B[iii].p, /*strat->tailRing*/currRing); |
---|
2053 | p_Write(strat->B[iii].p1, /*strat->tailRing*/currRing); |
---|
2054 | p_Write(strat->B[iii].p2, strat->tailRing); |
---|
2055 | } |
---|
2056 | #endif |
---|
2057 | //getchar(); |
---|
2058 | #endif |
---|
2059 | #ifdef KDEBUG |
---|
2060 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
2061 | #endif |
---|
2062 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
2063 | if (TEST_OPT_DEGBOUND |
---|
2064 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
2065 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))) |
---|
2066 | { |
---|
2067 | /* |
---|
2068 | *stops computation if |
---|
2069 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
2070 | *a predefined number Kstd1_deg |
---|
2071 | */ |
---|
2072 | while ((strat->Ll >= 0) |
---|
2073 | && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL) |
---|
2074 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
2075 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))) |
---|
2076 | ) |
---|
2077 | deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
2078 | if (strat->Ll<0) break; |
---|
2079 | else strat->noClearS=TRUE; |
---|
2080 | } |
---|
2081 | /* picks the last element from the lazyset L */ |
---|
2082 | strat->P = strat->L[strat->Ll]; |
---|
2083 | strat->Ll--; |
---|
2084 | |
---|
2085 | if (pNext(strat->P.p) == strat->tail) |
---|
2086 | { |
---|
2087 | // deletes the short spoly |
---|
2088 | if (rField_is_Ring(currRing)) |
---|
2089 | pLmDelete(strat->P.p); |
---|
2090 | else |
---|
2091 | pLmFree(strat->P.p); |
---|
2092 | strat->P.p = NULL; |
---|
2093 | poly m1 = NULL, m2 = NULL; |
---|
2094 | |
---|
2095 | // check that spoly creation is ok |
---|
2096 | while (strat->tailRing != currRing && |
---|
2097 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
2098 | { |
---|
2099 | assume(m1 == NULL && m2 == NULL); |
---|
2100 | // if not, change to a ring where exponents are at least |
---|
2101 | // large enough |
---|
2102 | if (!kStratChangeTailRing(strat)) |
---|
2103 | { |
---|
2104 | WerrorS("OVERFLOW..."); |
---|
2105 | break; |
---|
2106 | } |
---|
2107 | } |
---|
2108 | // create the real one |
---|
2109 | ksCreateSpoly(&(strat->P), NULL, strat->use_buckets, |
---|
2110 | strat->tailRing, m1, m2, strat->R); |
---|
2111 | } |
---|
2112 | else if (strat->P.p1 == NULL) |
---|
2113 | { |
---|
2114 | if (strat->minim > 0) |
---|
2115 | strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing); |
---|
2116 | // for input polys, prepare reduction |
---|
2117 | strat->P.PrepareRed(strat->use_buckets); |
---|
2118 | } |
---|
2119 | |
---|
2120 | if (strat->P.p == NULL && strat->P.t_p == NULL) |
---|
2121 | { |
---|
2122 | red_result = 0; |
---|
2123 | } |
---|
2124 | else |
---|
2125 | { |
---|
2126 | if (TEST_OPT_PROT) |
---|
2127 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
2128 | &olddeg,&reduc,strat, red_result); |
---|
2129 | |
---|
2130 | /* reduction of the element chosen from L */ |
---|
2131 | red_result = strat->red(&strat->P,strat); |
---|
2132 | if (errorreported) break; |
---|
2133 | } |
---|
2134 | |
---|
2135 | if (strat->overflow) |
---|
2136 | { |
---|
2137 | if (!kStratChangeTailRing(strat)) { WerrorS("OVERFLOW.."); break;} |
---|
2138 | } |
---|
2139 | |
---|
2140 | // reduction to non-zero new poly |
---|
2141 | if (red_result == 1) |
---|
2142 | { |
---|
2143 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
2144 | strat->P.GetP(strat->lmBin); |
---|
2145 | // in the homogeneous case FDeg >= pFDeg (sugar/honey) |
---|
2146 | // but now, for entering S, T, we reset it |
---|
2147 | // in the inhomogeneous case: FDeg == pFDeg |
---|
2148 | if (strat->homog) strat->initEcart(&(strat->P)); |
---|
2149 | |
---|
2150 | /* statistic */ |
---|
2151 | if (TEST_OPT_PROT) PrintS("s"); |
---|
2152 | |
---|
2153 | int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
2154 | |
---|
2155 | // reduce the tail and normalize poly |
---|
2156 | // in the ring case we cannot expect LC(f) = 1, |
---|
2157 | // therefore we call pContent instead of pNorm |
---|
2158 | strat->redTailChange=FALSE; |
---|
2159 | if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing))) |
---|
2160 | { |
---|
2161 | strat->P.pCleardenom(); |
---|
2162 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
2163 | { |
---|
2164 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT,!TEST_OPT_CONTENTSB); |
---|
2165 | strat->P.pCleardenom(); |
---|
2166 | if (strat->redTailChange) { strat->P.t_p=NULL; } |
---|
2167 | } |
---|
2168 | } |
---|
2169 | else |
---|
2170 | { |
---|
2171 | strat->P.pNorm(); |
---|
2172 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
2173 | { |
---|
2174 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
2175 | if (strat->redTailChange) { strat->P.t_p=NULL; } |
---|
2176 | } |
---|
2177 | } |
---|
2178 | |
---|
2179 | #ifdef KDEBUG |
---|
2180 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
2181 | #endif /* KDEBUG */ |
---|
2182 | |
---|
2183 | // min_std stuff |
---|
2184 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
2185 | { |
---|
2186 | if (strat->minim==1) |
---|
2187 | { |
---|
2188 | strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing); |
---|
2189 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
2190 | } |
---|
2191 | else |
---|
2192 | { |
---|
2193 | strat->M->m[minimcnt]=strat->P.p2; |
---|
2194 | strat->P.p2=NULL; |
---|
2195 | } |
---|
2196 | if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL) |
---|
2197 | pNext(strat->M->m[minimcnt]) |
---|
2198 | = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]), |
---|
2199 | strat->tailRing, currRing, |
---|
2200 | currRing->PolyBin); |
---|
2201 | minimcnt++; |
---|
2202 | } |
---|
2203 | |
---|
2204 | // enter into S, L, and T |
---|
2205 | if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp)) |
---|
2206 | { |
---|
2207 | enterT(strat->P, strat); |
---|
2208 | if (rField_is_Ring(currRing)) |
---|
2209 | superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
2210 | else |
---|
2211 | enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
2212 | // posInS only depends on the leading term |
---|
2213 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
2214 | #ifdef ADIDEBUG |
---|
2215 | printf("\nThis element has been added to S:\n");pWrite(strat->P.p);pWrite(strat->P.p1);pWrite(strat->P.p2); |
---|
2216 | #endif |
---|
2217 | #if 0 |
---|
2218 | int pl=pLength(strat->P.p); |
---|
2219 | if (pl==1) |
---|
2220 | { |
---|
2221 | //if (TEST_OPT_PROT) |
---|
2222 | //PrintS("<1>"); |
---|
2223 | } |
---|
2224 | else if (pl==2) |
---|
2225 | { |
---|
2226 | //if (TEST_OPT_PROT) |
---|
2227 | //PrintS("<2>"); |
---|
2228 | } |
---|
2229 | #endif |
---|
2230 | } |
---|
2231 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
2232 | // Print("[%d]",hilbeledeg); |
---|
2233 | if (strat->P.lcm!=NULL) |
---|
2234 | { |
---|
2235 | if (rField_is_Ring(currRing)) pLmDelete(strat->P.lcm); |
---|
2236 | else pLmFree(strat->P.lcm); |
---|
2237 | strat->P.lcm=NULL; |
---|
2238 | } |
---|
2239 | if (strat->s_poly!=NULL) |
---|
2240 | { |
---|
2241 | // the only valid entries are: strat->P.p, |
---|
2242 | // strat->tailRing (read-only, keep it) |
---|
2243 | // (and P->p1, P->p2 (read-only, must set to NULL if P.p is changed) |
---|
2244 | if (strat->s_poly(strat)) |
---|
2245 | { |
---|
2246 | // we are called AFTER enterS, i.e. if we change P |
---|
2247 | // we have to add it also to S/T |
---|
2248 | // and add pairs |
---|
2249 | int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
2250 | enterT(strat->P, strat); |
---|
2251 | if (rField_is_Ring(currRing)) |
---|
2252 | superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
2253 | else |
---|
2254 | enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
2255 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
2256 | } |
---|
2257 | } |
---|
2258 | } |
---|
2259 | else if (strat->P.p1 == NULL && strat->minim > 0) |
---|
2260 | { |
---|
2261 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
2262 | } |
---|
2263 | |
---|
2264 | #ifdef KDEBUG |
---|
2265 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
2266 | #endif /* KDEBUG */ |
---|
2267 | kTest_TS(strat); |
---|
2268 | } |
---|
2269 | #ifdef KDEBUG |
---|
2270 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
2271 | #endif /* KDEBUG */ |
---|
2272 | |
---|
2273 | if (TEST_OPT_SB_1) |
---|
2274 | { |
---|
2275 | if(!rField_is_Ring(currRing)) |
---|
2276 | { |
---|
2277 | int k=1; |
---|
2278 | int j; |
---|
2279 | while(k<=strat->sl) |
---|
2280 | { |
---|
2281 | j=0; |
---|
2282 | loop |
---|
2283 | { |
---|
2284 | if (j>=k) break; |
---|
2285 | clearS(strat->S[j],strat->sevS[j],&k,&j,strat); |
---|
2286 | j++; |
---|
2287 | } |
---|
2288 | k++; |
---|
2289 | } |
---|
2290 | } |
---|
2291 | } |
---|
2292 | /* complete reduction of the standard basis--------- */ |
---|
2293 | if (TEST_OPT_REDSB) |
---|
2294 | { |
---|
2295 | completeReduce(strat); |
---|
2296 | if (strat->completeReduce_retry) |
---|
2297 | { |
---|
2298 | // completeReduce needed larger exponents, retry |
---|
2299 | // to reduce with S (instead of T) |
---|
2300 | // and in currRing (instead of strat->tailRing) |
---|
2301 | #ifdef HAVE_TAIL_RING |
---|
2302 | if(currRing->bitmask>strat->tailRing->bitmask) |
---|
2303 | { |
---|
2304 | strat->completeReduce_retry=FALSE; |
---|
2305 | cleanT(strat);strat->tailRing=currRing; |
---|
2306 | int i; |
---|
2307 | for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1; |
---|
2308 | completeReduce(strat); |
---|
2309 | } |
---|
2310 | if (strat->completeReduce_retry) |
---|
2311 | #endif |
---|
2312 | Werror("exponent bound is %ld",currRing->bitmask); |
---|
2313 | } |
---|
2314 | } |
---|
2315 | else if (TEST_OPT_PROT) PrintLn(); |
---|
2316 | if (!errorreported) |
---|
2317 | { |
---|
2318 | if(rField_is_Ring_Z(currRing)) |
---|
2319 | { |
---|
2320 | for(int i = 0;i<=strat->sl;i++) |
---|
2321 | { |
---|
2322 | if(!nGreaterZero(pGetCoeff(strat->S[i]))) |
---|
2323 | { |
---|
2324 | strat->S[i] = pNeg(strat->S[i]); |
---|
2325 | } |
---|
2326 | } |
---|
2327 | finalReduceByMon(strat); |
---|
2328 | for(int i = 0;i<=strat->sl;i++) |
---|
2329 | { |
---|
2330 | if(!nGreaterZero(pGetCoeff(strat->S[i]))) |
---|
2331 | { |
---|
2332 | strat->S[i] = pNeg(strat->S[i]); |
---|
2333 | } |
---|
2334 | } |
---|
2335 | } |
---|
2336 | else if (rField_is_Ring(currRing)) |
---|
2337 | finalReduceByMon(strat); |
---|
2338 | } |
---|
2339 | /* release temp data-------------------------------- */ |
---|
2340 | exitBuchMora(strat); |
---|
2341 | // if (TEST_OPT_WEIGHTM) |
---|
2342 | // { |
---|
2343 | // pRestoreDegProcs(currRing,pFDegOld, pLDegOld); |
---|
2344 | // if (ecartWeights) |
---|
2345 | // { |
---|
2346 | // omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short)); |
---|
2347 | // ecartWeights=NULL; |
---|
2348 | // } |
---|
2349 | // } |
---|
2350 | if ((TEST_OPT_PROT) || (TEST_OPT_DEBUG)) messageStat(hilbcount,strat); |
---|
2351 | SI_RESTORE_OPT1(save); |
---|
2352 | if ((Q!=NULL)&&(!errorreported)) updateResult(strat->Shdl,Q,strat); |
---|
2353 | |
---|
2354 | idTest(strat->Shdl); |
---|
2355 | |
---|
2356 | return (strat->Shdl); |
---|
2357 | } |
---|
2358 | |
---|
2359 | ideal sba (ideal F0, ideal Q,intvec *w,intvec *hilb,kStrategy strat) |
---|
2360 | { |
---|
2361 | // ring order stuff: |
---|
2362 | // in sba we have (until now) two possibilities: |
---|
2363 | // 1. an incremental computation w.r.t. (C,monomial order) |
---|
2364 | // 2. a (possibly non-incremental) computation w.r.t. the |
---|
2365 | // induced Schreyer order. |
---|
2366 | // The corresponding orders are computed in sbaRing(), depending |
---|
2367 | // on the flag strat->sbaOrder |
---|
2368 | #if SBA_PRINT_ZERO_REDUCTIONS |
---|
2369 | long zeroreductions = 0; |
---|
2370 | #endif |
---|
2371 | #if SBA_PRINT_PRODUCT_CRITERION |
---|
2372 | long product_criterion = 0; |
---|
2373 | #endif |
---|
2374 | #if SBA_PRINT_SIZE_G |
---|
2375 | int size_g = 0; |
---|
2376 | int size_g_non_red = 0; |
---|
2377 | #endif |
---|
2378 | #if SBA_PRINT_SIZE_SYZ |
---|
2379 | long size_syz = 0; |
---|
2380 | #endif |
---|
2381 | // global variable |
---|
2382 | #if SBA_PRINT_REDUCTION_STEPS |
---|
2383 | sba_reduction_steps = 0; |
---|
2384 | sba_interreduction_steps = 0; |
---|
2385 | #endif |
---|
2386 | #if SBA_PRINT_OPERATIONS |
---|
2387 | sba_operations = 0; |
---|
2388 | sba_interreduction_operations = 0; |
---|
2389 | #endif |
---|
2390 | |
---|
2391 | ideal F1 = F0; |
---|
2392 | ring sRing, currRingOld; |
---|
2393 | currRingOld = currRing; |
---|
2394 | if (strat->sbaOrder == 1 || strat->sbaOrder == 3) |
---|
2395 | { |
---|
2396 | sRing = sbaRing(strat); |
---|
2397 | if (sRing!=currRingOld) |
---|
2398 | { |
---|
2399 | rChangeCurrRing (sRing); |
---|
2400 | F1 = idrMoveR (F0, currRingOld, currRing); |
---|
2401 | } |
---|
2402 | } |
---|
2403 | ideal F; |
---|
2404 | // sort ideal F |
---|
2405 | //Put the SigDrop element on the correct position (think of sbaEnterS) |
---|
2406 | //We also sort them |
---|
2407 | if(rField_is_Ring(currRing) && strat->sigdrop) |
---|
2408 | { |
---|
2409 | #if 1 |
---|
2410 | F = idInit(IDELEMS(F1),F1->rank); |
---|
2411 | for (int i=0; i<IDELEMS(F1);++i) |
---|
2412 | F->m[i] = F1->m[i]; |
---|
2413 | if(strat->sbaEnterS >= 0) |
---|
2414 | { |
---|
2415 | poly dummy; |
---|
2416 | dummy = pCopy(F->m[0]); //the sigdrop element |
---|
2417 | for(int i = 0;i<strat->sbaEnterS;i++) |
---|
2418 | F->m[i] = F->m[i+1]; |
---|
2419 | F->m[strat->sbaEnterS] = dummy; |
---|
2420 | } |
---|
2421 | #else |
---|
2422 | F = idInit(1,F1->rank); |
---|
2423 | //printf("\nBefore the initial block sorting:\n");idPrint(F1); |
---|
2424 | F->m[0] = F1->m[0]; |
---|
2425 | int pos; |
---|
2426 | if(strat->sbaEnterS >= 0) |
---|
2427 | { |
---|
2428 | for(int i=1;i<=strat->sbaEnterS;i++) |
---|
2429 | { |
---|
2430 | pos = posInIdealMonFirst(F,F1->m[i],1,strat->sbaEnterS); |
---|
2431 | idInsertPolyOnPos(F,F1->m[i],pos); |
---|
2432 | } |
---|
2433 | for(int i=strat->sbaEnterS+1;i<IDELEMS(F1);i++) |
---|
2434 | { |
---|
2435 | pos = posInIdealMonFirst(F,F1->m[i],strat->sbaEnterS+1,IDELEMS(F)); |
---|
2436 | idInsertPolyOnPos(F,F1->m[i],pos); |
---|
2437 | } |
---|
2438 | poly dummy; |
---|
2439 | dummy = pCopy(F->m[0]); //the sigdrop element |
---|
2440 | for(int i = 0;i<strat->sbaEnterS;i++) |
---|
2441 | F->m[i] = F->m[i+1]; |
---|
2442 | F->m[strat->sbaEnterS] = dummy; |
---|
2443 | } |
---|
2444 | else |
---|
2445 | { |
---|
2446 | for(int i=1;i<IDELEMS(F1);i++) |
---|
2447 | { |
---|
2448 | pos = posInIdealMonFirst(F,F1->m[i],1,IDELEMS(F)); |
---|
2449 | idInsertPolyOnPos(F,F1->m[i],pos); |
---|
2450 | } |
---|
2451 | } |
---|
2452 | #endif |
---|
2453 | //printf("\nAfter the initial block sorting:\n");idPrint(F);getchar(); |
---|
2454 | } |
---|
2455 | else |
---|
2456 | { |
---|
2457 | F = idInit(IDELEMS(F1),F1->rank); |
---|
2458 | intvec *sort = idSort(F1); |
---|
2459 | for (int i=0; i<sort->length();++i) |
---|
2460 | F->m[i] = F1->m[(*sort)[i]-1]; |
---|
2461 | if(rField_is_Ring(currRing)) |
---|
2462 | { |
---|
2463 | // put the monomials after the sbaEnterS polynomials |
---|
2464 | //printf("\nThis is the ideal before sorting (sbaEnterS = %i)\n",strat->sbaEnterS);idPrint(F); |
---|
2465 | int nrmon = 0; |
---|
2466 | for(int i = IDELEMS(F)-1,j;i>strat->sbaEnterS+nrmon+1 ;i--) |
---|
2467 | { |
---|
2468 | //pWrite(F->m[i]); |
---|
2469 | if(F->m[i] != NULL && pNext(F->m[i]) == NULL) |
---|
2470 | { |
---|
2471 | poly mon = F->m[i]; |
---|
2472 | for(j = i;j>strat->sbaEnterS+nrmon+1;j--) |
---|
2473 | { |
---|
2474 | F->m[j] = F->m[j-1]; |
---|
2475 | } |
---|
2476 | F->m[j] = mon; |
---|
2477 | nrmon++; |
---|
2478 | } |
---|
2479 | //idPrint(F); |
---|
2480 | } |
---|
2481 | } |
---|
2482 | } |
---|
2483 | //printf("\nThis is the ideal after sorting\n");idPrint(F);getchar(); |
---|
2484 | if(rField_is_Ring(currRing)) |
---|
2485 | strat->sigdrop = FALSE; |
---|
2486 | strat->nrsyzcrit = 0; |
---|
2487 | strat->nrrewcrit = 0; |
---|
2488 | #if SBA_INTERRED_START |
---|
2489 | F = kInterRed(F,NULL); |
---|
2490 | #endif |
---|
2491 | #if F5DEBUG |
---|
2492 | printf("SBA COMPUTATIONS DONE IN THE FOLLOWING RING:\n"); |
---|
2493 | rWrite (currRing); |
---|
2494 | printf("ordSgn = %d\n",currRing->OrdSgn); |
---|
2495 | printf("\n"); |
---|
2496 | #endif |
---|
2497 | int srmax,lrmax, red_result = 1; |
---|
2498 | int olddeg,reduc; |
---|
2499 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
2500 | LObject L; |
---|
2501 | BOOLEAN withT = TRUE; |
---|
2502 | strat->max_lower_index = 0; |
---|
2503 | //initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
2504 | initSbaCrit(strat); /*set Gebauer, honey, sugarCrit*/ |
---|
2505 | initSbaPos(strat); |
---|
2506 | initHilbCrit(F,Q,&hilb,strat); |
---|
2507 | initSba(F,strat); |
---|
2508 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
2509 | /*Shdl=*/initSbaBuchMora(F, Q,strat); |
---|
2510 | idTest(strat->Shdl); |
---|
2511 | if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank); |
---|
2512 | srmax = strat->sl; |
---|
2513 | reduc = olddeg = lrmax = 0; |
---|
2514 | #ifndef NO_BUCKETS |
---|
2515 | if (!TEST_OPT_NOT_BUCKETS) |
---|
2516 | strat->use_buckets = 1; |
---|
2517 | #endif |
---|
2518 | |
---|
2519 | // redtailBBa against T for inhomogenous input |
---|
2520 | // if (!TEST_OPT_OLDSTD) |
---|
2521 | // withT = ! strat->homog; |
---|
2522 | |
---|
2523 | // strat->posInT = posInT_pLength; |
---|
2524 | kTest_TS(strat); |
---|
2525 | |
---|
2526 | #ifdef HAVE_TAIL_RING |
---|
2527 | if(!idIs0(F) &&(!rField_is_Ring(currRing))) // create strong gcd poly computes with tailring and S[i] ->to be fixed |
---|
2528 | kStratInitChangeTailRing(strat); |
---|
2529 | #endif |
---|
2530 | if (BVERBOSE(23)) |
---|
2531 | { |
---|
2532 | if (test_PosInT!=NULL) strat->posInT=test_PosInT; |
---|
2533 | if (test_PosInL!=NULL) strat->posInL=test_PosInL; |
---|
2534 | kDebugPrint(strat); |
---|
2535 | } |
---|
2536 | // We add the elements directly in S from the previous loop |
---|
2537 | if(rField_is_Ring(currRing) && strat->sbaEnterS >= 0) |
---|
2538 | { |
---|
2539 | for(int i = 0;i<strat->sbaEnterS;i++) |
---|
2540 | { |
---|
2541 | //Update: now the element is at the corect place |
---|
2542 | //i+1 because on the 0 position is the sigdrop element |
---|
2543 | enterT(strat->L[strat->Ll-(i)],strat); |
---|
2544 | strat->enterS(strat->L[strat->Ll-(i)], strat->sl+1, strat, strat->tl); |
---|
2545 | } |
---|
2546 | strat->Ll = strat->Ll - strat->sbaEnterS; |
---|
2547 | strat->sbaEnterS = -1; |
---|
2548 | } |
---|
2549 | kTest_TS(strat); |
---|
2550 | #ifdef KDEBUG |
---|
2551 | //kDebugPrint(strat); |
---|
2552 | #endif |
---|
2553 | /* compute------------------------------------------------------- */ |
---|
2554 | while (strat->Ll >= 0) |
---|
2555 | { |
---|
2556 | #ifdef ADIDEBUG |
---|
2557 | printf("\n ------------------------NEW LOOP\n"); |
---|
2558 | printf("\nShdl = \n"); |
---|
2559 | #if 0 |
---|
2560 | idPrint(strat->Shdl); |
---|
2561 | #else |
---|
2562 | for(int ii = 0; ii<=strat->sl;ii++) |
---|
2563 | { |
---|
2564 | printf("\nS[%i]: ",ii);p_Write(strat->S[ii],strat->tailRing); |
---|
2565 | printf("sig: ");pWrite(strat->sig[ii]); |
---|
2566 | } |
---|
2567 | #endif |
---|
2568 | #if 0 |
---|
2569 | for(int iii = 0; iii< strat->syzl; iii++) |
---|
2570 | { |
---|
2571 | printf("\nsyz[%i]:\n",iii); |
---|
2572 | p_Write(strat->syz[iii], currRing); |
---|
2573 | } |
---|
2574 | #endif |
---|
2575 | #if 0 |
---|
2576 | for(int iii = 0; iii<= strat->tl; iii++) |
---|
2577 | { |
---|
2578 | printf("\nT[%i]:\n",iii); |
---|
2579 | p_Write(strat->T[iii].p, currRing); |
---|
2580 | } |
---|
2581 | #endif |
---|
2582 | printf("\n list L\n"); |
---|
2583 | int iii; |
---|
2584 | #if 0 |
---|
2585 | for(iii = 0; iii<= strat->Ll; iii++) |
---|
2586 | { |
---|
2587 | printf("\nL[%i]:\n",iii); |
---|
2588 | p_Write(strat->L[iii].p, currRing); |
---|
2589 | p_Write(strat->L[iii].p1, currRing); |
---|
2590 | p_Write(strat->L[iii].p2, currRing); |
---|
2591 | p_Write(strat->L[iii].sig, currRing); |
---|
2592 | } |
---|
2593 | #else |
---|
2594 | { |
---|
2595 | printf("L[%i]:",strat->Ll); |
---|
2596 | p_Write(strat->L[strat->Ll].p, strat->tailRing); |
---|
2597 | p_Write(strat->L[strat->Ll].p1, strat->tailRing); |
---|
2598 | p_Write(strat->L[strat->Ll].p2, strat->tailRing); |
---|
2599 | p_Write(strat->L[strat->Ll].sig, currRing); |
---|
2600 | } |
---|
2601 | #endif |
---|
2602 | //getchar(); |
---|
2603 | #endif |
---|
2604 | if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/ |
---|
2605 | #ifdef KDEBUG |
---|
2606 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
2607 | #endif |
---|
2608 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
2609 | /* |
---|
2610 | if (TEST_OPT_DEGBOUND |
---|
2611 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
2612 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))) |
---|
2613 | { |
---|
2614 | |
---|
2615 | //stops computation if |
---|
2616 | // 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
2617 | //a predefined number Kstd1_deg |
---|
2618 | while ((strat->Ll >= 0) |
---|
2619 | && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL) |
---|
2620 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
2621 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))) |
---|
2622 | ) |
---|
2623 | deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
2624 | if (strat->Ll<0) break; |
---|
2625 | else strat->noClearS=TRUE; |
---|
2626 | } |
---|
2627 | */ |
---|
2628 | if (strat->sbaOrder == 1 && pGetComp(strat->L[strat->Ll].sig) != strat->currIdx) |
---|
2629 | { |
---|
2630 | strat->currIdx = pGetComp(strat->L[strat->Ll].sig); |
---|
2631 | #if F5C |
---|
2632 | // 1. interreduction of the current standard basis |
---|
2633 | // 2. generation of new principal syzygy rules for syzCriterion |
---|
2634 | f5c ( strat, olddeg, minimcnt, hilbeledeg, hilbcount, srmax, |
---|
2635 | lrmax, reduc, Q, w, hilb ); |
---|
2636 | #endif |
---|
2637 | // initialize new syzygy rules for the next iteration step |
---|
2638 | initSyzRules(strat); |
---|
2639 | } |
---|
2640 | /********************************************************************* |
---|
2641 | * interrreduction step is done, we can go on with the next iteration |
---|
2642 | * step of the signature-based algorithm |
---|
2643 | ********************************************************************/ |
---|
2644 | /* picks the last element from the lazyset L */ |
---|
2645 | strat->P = strat->L[strat->Ll]; |
---|
2646 | strat->Ll--; |
---|
2647 | |
---|
2648 | if(rField_is_Ring(currRing)) |
---|
2649 | strat->sbaEnterS = pGetComp(strat->P.sig) - 1; |
---|
2650 | |
---|
2651 | #ifdef ADIDEBUG |
---|
2652 | printf("\n-------------------------\nThis is the current element P\n"); |
---|
2653 | p_Write(strat->P.p,strat->tailRing); |
---|
2654 | p_Write(strat->P.p1,strat->tailRing); |
---|
2655 | p_Write(strat->P.p2,strat->tailRing); |
---|
2656 | p_Write(strat->P.sig,currRing); |
---|
2657 | #endif |
---|
2658 | /* reduction of the element chosen from L */ |
---|
2659 | if (!strat->rewCrit2(strat->P.sig, ~strat->P.sevSig, strat->P.GetLmCurrRing(), strat, strat->P.checked+1)) |
---|
2660 | { |
---|
2661 | //#if 1 |
---|
2662 | #ifdef DEBUGF5 |
---|
2663 | PrintS("SIG OF NEXT PAIR TO HANDLE IN SIG-BASED ALGORITHM\n"); |
---|
2664 | PrintS("-------------------------------------------------\n"); |
---|
2665 | pWrite(strat->P.sig); |
---|
2666 | pWrite(pHead(strat->P.p)); |
---|
2667 | pWrite(pHead(strat->P.p1)); |
---|
2668 | pWrite(pHead(strat->P.p2)); |
---|
2669 | PrintS("-------------------------------------------------\n"); |
---|
2670 | #endif |
---|
2671 | if (pNext(strat->P.p) == strat->tail) |
---|
2672 | { |
---|
2673 | // deletes the short spoly |
---|
2674 | /* |
---|
2675 | if (rField_is_Ring(currRing)) |
---|
2676 | pLmDelete(strat->P.p); |
---|
2677 | else |
---|
2678 | pLmFree(strat->P.p); |
---|
2679 | */ |
---|
2680 | // TODO: needs some masking |
---|
2681 | // TODO: masking needs to vanish once the signature |
---|
2682 | // sutff is completely implemented |
---|
2683 | strat->P.p = NULL; |
---|
2684 | poly m1 = NULL, m2 = NULL; |
---|
2685 | |
---|
2686 | // check that spoly creation is ok |
---|
2687 | while (strat->tailRing != currRing && |
---|
2688 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
2689 | { |
---|
2690 | assume(m1 == NULL && m2 == NULL); |
---|
2691 | // if not, change to a ring where exponents are at least |
---|
2692 | // large enough |
---|
2693 | if (!kStratChangeTailRing(strat)) |
---|
2694 | { |
---|
2695 | WerrorS("OVERFLOW..."); |
---|
2696 | break; |
---|
2697 | } |
---|
2698 | } |
---|
2699 | // create the real one |
---|
2700 | ksCreateSpoly(&(strat->P), NULL, strat->use_buckets, |
---|
2701 | strat->tailRing, m1, m2, strat->R); |
---|
2702 | |
---|
2703 | } |
---|
2704 | else if (strat->P.p1 == NULL) |
---|
2705 | { |
---|
2706 | if (strat->minim > 0) |
---|
2707 | strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing); |
---|
2708 | // for input polys, prepare reduction |
---|
2709 | if(!rField_is_Ring(currRing)) |
---|
2710 | strat->P.PrepareRed(strat->use_buckets); |
---|
2711 | } |
---|
2712 | if (strat->P.p == NULL && strat->P.t_p == NULL) |
---|
2713 | { |
---|
2714 | red_result = 0; |
---|
2715 | } |
---|
2716 | else |
---|
2717 | { |
---|
2718 | //#if 1 |
---|
2719 | #ifdef DEBUGF5 |
---|
2720 | PrintS("Poly before red: "); |
---|
2721 | pWrite(pHead(strat->P.p)); |
---|
2722 | pWrite(strat->P.sig); |
---|
2723 | #endif |
---|
2724 | #if SBA_PRODUCT_CRITERION |
---|
2725 | if (strat->P.prod_crit) |
---|
2726 | { |
---|
2727 | #if SBA_PRINT_PRODUCT_CRITERION |
---|
2728 | product_criterion++; |
---|
2729 | #endif |
---|
2730 | int pos = posInSyz(strat, strat->P.sig); |
---|
2731 | enterSyz(strat->P, strat, pos); |
---|
2732 | if (strat->P.lcm!=NULL) |
---|
2733 | pLmFree(strat->P.lcm); |
---|
2734 | red_result = 2; |
---|
2735 | } |
---|
2736 | else |
---|
2737 | { |
---|
2738 | red_result = strat->red(&strat->P,strat); |
---|
2739 | } |
---|
2740 | #else |
---|
2741 | red_result = strat->red(&strat->P,strat); |
---|
2742 | #endif |
---|
2743 | } |
---|
2744 | } |
---|
2745 | else |
---|
2746 | { |
---|
2747 | /* |
---|
2748 | if (strat->P.lcm != NULL) |
---|
2749 | pLmFree(strat->P.lcm); |
---|
2750 | */ |
---|
2751 | red_result = 2; |
---|
2752 | } |
---|
2753 | if(rField_is_Ring(currRing)) |
---|
2754 | { |
---|
2755 | if(strat->P.sig!= NULL && !nGreaterZero(pGetCoeff(strat->P.sig))) |
---|
2756 | { |
---|
2757 | strat->P.p = pNeg(strat->P.p); |
---|
2758 | strat->P.sig = pNeg(strat->P.sig); |
---|
2759 | } |
---|
2760 | strat->P.pLength = pLength(strat->P.p); |
---|
2761 | if(strat->P.sig != NULL) |
---|
2762 | strat->P.sevSig = pGetShortExpVector(strat->P.sig); |
---|
2763 | if(strat->P.p != NULL) |
---|
2764 | strat->P.sev = pGetShortExpVector(strat->P.p); |
---|
2765 | } |
---|
2766 | #ifdef ADIDEBUG |
---|
2767 | printf("\nAfter reduce (redresult=%i): \n",red_result);pWrite(strat->P.p);pWrite(strat->P.sig); |
---|
2768 | #endif |
---|
2769 | //sigdrop case |
---|
2770 | if(rField_is_Ring(currRing) && strat->sigdrop) |
---|
2771 | { |
---|
2772 | //First reduce it as much as one can |
---|
2773 | #ifdef ADIDEBUG |
---|
2774 | printf("\nSigdrop in the reduce. Trying redring\n"); |
---|
2775 | #endif |
---|
2776 | red_result = redRing(&strat->P,strat); |
---|
2777 | if(red_result == 0) |
---|
2778 | { |
---|
2779 | #ifdef ADIDEBUG |
---|
2780 | printf("\nSigdrop cancelled since redRing reduced to 0\n"); |
---|
2781 | #endif |
---|
2782 | strat->sigdrop = FALSE; |
---|
2783 | pDelete(&strat->P.sig); |
---|
2784 | strat->P.sig = NULL; |
---|
2785 | } |
---|
2786 | else |
---|
2787 | { |
---|
2788 | #ifdef ADIDEBUG |
---|
2789 | printf("\nStill Sigdrop - redRing reduced to:\n");pWrite(strat->P.p); |
---|
2790 | #endif |
---|
2791 | strat->enterS(strat->P, 0, strat, strat->tl); |
---|
2792 | if (TEST_OPT_PROT) |
---|
2793 | PrintS("-"); |
---|
2794 | break; |
---|
2795 | } |
---|
2796 | } |
---|
2797 | if(rField_is_Ring(currRing) && strat->blockred > strat->blockredmax) |
---|
2798 | { |
---|
2799 | #ifdef ADIDEBUG |
---|
2800 | printf("\nToo many blocked reductions\n"); |
---|
2801 | #endif |
---|
2802 | strat->sigdrop = TRUE; |
---|
2803 | break; |
---|
2804 | } |
---|
2805 | |
---|
2806 | if (errorreported) break; |
---|
2807 | |
---|
2808 | //#if 1 |
---|
2809 | #ifdef DEBUGF5 |
---|
2810 | if (red_result != 0) |
---|
2811 | { |
---|
2812 | PrintS("Poly after red: "); |
---|
2813 | pWrite(pHead(strat->P.p)); |
---|
2814 | pWrite(strat->P.GetLmCurrRing()); |
---|
2815 | pWrite(strat->P.sig); |
---|
2816 | printf("%d\n",red_result); |
---|
2817 | } |
---|
2818 | #endif |
---|
2819 | if (TEST_OPT_PROT) |
---|
2820 | { |
---|
2821 | if(strat->P.p != NULL) |
---|
2822 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
2823 | &olddeg,&reduc,strat, red_result); |
---|
2824 | else |
---|
2825 | message((strat->honey ? strat->P.ecart : 0), |
---|
2826 | &olddeg,&reduc,strat, red_result); |
---|
2827 | } |
---|
2828 | |
---|
2829 | if (strat->overflow) |
---|
2830 | { |
---|
2831 | if (!kStratChangeTailRing(strat)) { WerrorS("OVERFLOW.."); break;} |
---|
2832 | } |
---|
2833 | // reduction to non-zero new poly |
---|
2834 | if (red_result == 1) |
---|
2835 | { |
---|
2836 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
2837 | strat->P.GetP(strat->lmBin); |
---|
2838 | |
---|
2839 | // sig-safe computations may lead to wrong FDeg computation, thus we need |
---|
2840 | // to recompute it to make sure everything is alright |
---|
2841 | (strat->P).FDeg = (strat->P).pFDeg(); |
---|
2842 | // in the homogeneous case FDeg >= pFDeg (sugar/honey) |
---|
2843 | // but now, for entering S, T, we reset it |
---|
2844 | // in the inhomogeneous case: FDeg == pFDeg |
---|
2845 | if (strat->homog) strat->initEcart(&(strat->P)); |
---|
2846 | |
---|
2847 | /* statistic */ |
---|
2848 | if (TEST_OPT_PROT) PrintS("s"); |
---|
2849 | |
---|
2850 | //int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
2851 | // in F5E we know that the last reduced element is already the |
---|
2852 | // the one with highest signature |
---|
2853 | int pos = strat->sl+1; |
---|
2854 | |
---|
2855 | // reduce the tail and normalize poly |
---|
2856 | // in the ring case we cannot expect LC(f) = 1, |
---|
2857 | // therefore we call pContent instead of pNorm |
---|
2858 | #ifdef HAVE_RINGS |
---|
2859 | poly beforetailred; |
---|
2860 | if(rField_is_Ring(currRing)) |
---|
2861 | beforetailred = pCopy(strat->P.sig); |
---|
2862 | #endif |
---|
2863 | #if SBA_TAIL_RED |
---|
2864 | if(rField_is_Ring(currRing)) |
---|
2865 | { |
---|
2866 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
2867 | strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT); |
---|
2868 | } |
---|
2869 | else |
---|
2870 | { |
---|
2871 | if (strat->sbaOrder != 2) |
---|
2872 | { |
---|
2873 | if (TEST_OPT_INTSTRATEGY) |
---|
2874 | { |
---|
2875 | strat->P.pCleardenom(); |
---|
2876 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
2877 | { |
---|
2878 | strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT); |
---|
2879 | strat->P.pCleardenom(); |
---|
2880 | } |
---|
2881 | } |
---|
2882 | else |
---|
2883 | { |
---|
2884 | strat->P.pNorm(); |
---|
2885 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
2886 | strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT); |
---|
2887 | } |
---|
2888 | } |
---|
2889 | } |
---|
2890 | // It may happen that we have lost the sig in redtailsba |
---|
2891 | // It cannot reduce to 0 since here we are doing just tail reduction. |
---|
2892 | // Best case scenerio: remains the leading term |
---|
2893 | if(rField_is_Ring(currRing) && strat->sigdrop) |
---|
2894 | { |
---|
2895 | #ifdef ADIDEBUG |
---|
2896 | printf("\n Still sigdrop after redtailSba - it reduced to \n");pWrite(strat->P.p); |
---|
2897 | #endif |
---|
2898 | strat->enterS(strat->P, 0, strat, strat->tl); |
---|
2899 | break; |
---|
2900 | } |
---|
2901 | #endif |
---|
2902 | if(rField_is_Ring(currRing)) |
---|
2903 | { |
---|
2904 | if(strat->P.sig == NULL || pLtCmp(beforetailred,strat->P.sig) == 1) |
---|
2905 | { |
---|
2906 | #ifdef ADIDEBUG |
---|
2907 | printf("\nSigDrop after TAILred\n");pWrite(beforetailred);pWrite(strat->P.sig); |
---|
2908 | #endif |
---|
2909 | strat->sigdrop = TRUE; |
---|
2910 | //Reduce it as much as you can |
---|
2911 | red_result = redRing(&strat->P,strat); |
---|
2912 | if(red_result == 0) |
---|
2913 | { |
---|
2914 | //It reduced to 0, cancel the sigdrop |
---|
2915 | #ifdef ADIDEBUG |
---|
2916 | printf("\nReduced to 0 via redRing. Cancel sigdrop\n"); |
---|
2917 | #endif |
---|
2918 | strat->sigdrop = FALSE; |
---|
2919 | p_Delete(&strat->P.sig,currRing);strat->P.sig = NULL; |
---|
2920 | } |
---|
2921 | else |
---|
2922 | { |
---|
2923 | #ifdef ADIDEBUG |
---|
2924 | printf("\nReduced to this via redRing.SIGDROP\n");pWrite(strat->P.p); |
---|
2925 | #endif |
---|
2926 | strat->enterS(strat->P, 0, strat, strat->tl); |
---|
2927 | break; |
---|
2928 | } |
---|
2929 | } |
---|
2930 | p_Delete(&beforetailred,currRing); |
---|
2931 | // strat->P.p = NULL may appear if we had a sigdrop above and reduced to 0 via redRing |
---|
2932 | if(strat->P.p == NULL) |
---|
2933 | goto case_when_red_result_changed; |
---|
2934 | } |
---|
2935 | #ifdef ADIDEBUG |
---|
2936 | printf("\nNach redTailSba: \n"); |
---|
2937 | p_Write(strat->P.p,strat->tailRing);p_Write(strat->P.sig,currRing); |
---|
2938 | #endif |
---|
2939 | // remove sigsafe label since it is no longer valid for the next element to |
---|
2940 | // be reduced |
---|
2941 | if (strat->sbaOrder == 1) |
---|
2942 | { |
---|
2943 | for (int jj = 0; jj<strat->tl+1; jj++) |
---|
2944 | { |
---|
2945 | if (pGetComp(strat->T[jj].sig) == strat->currIdx) |
---|
2946 | { |
---|
2947 | strat->T[jj].is_sigsafe = FALSE; |
---|
2948 | } |
---|
2949 | } |
---|
2950 | } |
---|
2951 | else |
---|
2952 | { |
---|
2953 | for (int jj = 0; jj<strat->tl+1; jj++) |
---|
2954 | { |
---|
2955 | strat->T[jj].is_sigsafe = FALSE; |
---|
2956 | } |
---|
2957 | } |
---|
2958 | #ifdef KDEBUG |
---|
2959 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
2960 | #endif /* KDEBUG */ |
---|
2961 | |
---|
2962 | // min_std stuff |
---|
2963 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
2964 | { |
---|
2965 | if (strat->minim==1) |
---|
2966 | { |
---|
2967 | strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing); |
---|
2968 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
2969 | } |
---|
2970 | else |
---|
2971 | { |
---|
2972 | strat->M->m[minimcnt]=strat->P.p2; |
---|
2973 | strat->P.p2=NULL; |
---|
2974 | } |
---|
2975 | if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL) |
---|
2976 | pNext(strat->M->m[minimcnt]) |
---|
2977 | = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]), |
---|
2978 | strat->tailRing, currRing, |
---|
2979 | currRing->PolyBin); |
---|
2980 | minimcnt++; |
---|
2981 | } |
---|
2982 | |
---|
2983 | // enter into S, L, and T |
---|
2984 | //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp)) |
---|
2985 | enterT(strat->P, strat); |
---|
2986 | strat->T[strat->tl].is_sigsafe = FALSE; |
---|
2987 | /* |
---|
2988 | printf("hier\n"); |
---|
2989 | pWrite(strat->P.GetLmCurrRing()); |
---|
2990 | pWrite(strat->P.sig); |
---|
2991 | */ |
---|
2992 | if (rField_is_Ring(currRing)) |
---|
2993 | superenterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
2994 | else |
---|
2995 | enterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl); |
---|
2996 | #ifdef ADIDEBUG |
---|
2997 | printf("\nThis element is added to S\n"); |
---|
2998 | p_Write(strat->P.p, strat->tailRing);p_Write(strat->P.p1, strat->tailRing);p_Write(strat->P.p2, strat->tailRing);pWrite(strat->P.sig); |
---|
2999 | //getchar(); |
---|
3000 | #endif |
---|
3001 | if(rField_is_Ring(currRing) && strat->sigdrop) |
---|
3002 | break; |
---|
3003 | if(rField_is_Ring(currRing)) |
---|
3004 | strat->P.sevSig = p_GetShortExpVector(strat->P.sig,currRing); |
---|
3005 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
3006 | if(strat->sbaOrder != 1) |
---|
3007 | { |
---|
3008 | BOOLEAN overwrite = FALSE; |
---|
3009 | for (int tk=0; tk<strat->sl+1; tk++) |
---|
3010 | { |
---|
3011 | if (pGetComp(strat->sig[tk]) == pGetComp(strat->P.sig)) |
---|
3012 | { |
---|
3013 | //printf("TK %d / %d\n",tk,strat->sl); |
---|
3014 | overwrite = FALSE; |
---|
3015 | break; |
---|
3016 | } |
---|
3017 | } |
---|
3018 | //printf("OVERWRITE %d\n",overwrite); |
---|
3019 | if (overwrite) |
---|
3020 | { |
---|
3021 | int cmp = pGetComp(strat->P.sig); |
---|
3022 | int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int)); |
---|
3023 | pGetExpV (strat->P.p,vv); |
---|
3024 | pSetExpV (strat->P.sig, vv); |
---|
3025 | pSetComp (strat->P.sig,cmp); |
---|
3026 | |
---|
3027 | strat->P.sevSig = pGetShortExpVector (strat->P.sig); |
---|
3028 | int i; |
---|
3029 | LObject Q; |
---|
3030 | for(int ps=0;ps<strat->sl+1;ps++) |
---|
3031 | { |
---|
3032 | |
---|
3033 | strat->newt = TRUE; |
---|
3034 | if (strat->syzl == strat->syzmax) |
---|
3035 | { |
---|
3036 | pEnlargeSet(&strat->syz,strat->syzmax,setmaxTinc); |
---|
3037 | strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz, |
---|
3038 | (strat->syzmax)*sizeof(unsigned long), |
---|
3039 | ((strat->syzmax)+setmaxTinc) |
---|
3040 | *sizeof(unsigned long)); |
---|
3041 | strat->syzmax += setmaxTinc; |
---|
3042 | } |
---|
3043 | Q.sig = pCopy(strat->P.sig); |
---|
3044 | // add LM(F->m[i]) to the signature to get a Schreyer order |
---|
3045 | // without changing the underlying polynomial ring at all |
---|
3046 | if (strat->sbaOrder == 0) |
---|
3047 | p_ExpVectorAdd (Q.sig,strat->S[ps],currRing); |
---|
3048 | // since p_Add_q() destroys all input |
---|
3049 | // data we need to recreate help |
---|
3050 | // each time |
---|
3051 | // ---------------------------------------------------------- |
---|
3052 | // in the Schreyer order we always know that the multiplied |
---|
3053 | // module monomial strat->P.sig gives the leading monomial of |
---|
3054 | // the corresponding principal syzygy |
---|
3055 | // => we do not need to compute the "real" syzygy completely |
---|
3056 | poly help = p_Copy(strat->sig[ps],currRing); |
---|
3057 | p_ExpVectorAdd (help,strat->P.p,currRing); |
---|
3058 | Q.sig = p_Add_q(Q.sig,help,currRing); |
---|
3059 | //printf("%d. SYZ ",i+1); |
---|
3060 | //pWrite(strat->syz[i]); |
---|
3061 | Q.sevSig = p_GetShortExpVector(Q.sig,currRing); |
---|
3062 | i = posInSyz(strat, Q.sig); |
---|
3063 | enterSyz(Q, strat, i); |
---|
3064 | } |
---|
3065 | } |
---|
3066 | } |
---|
3067 | // deg - idx - lp/rp |
---|
3068 | // => we need to add syzygies with indices > pGetComp(strat->P.sig) |
---|
3069 | if(strat->sbaOrder == 0 || strat->sbaOrder == 3) |
---|
3070 | { |
---|
3071 | int cmp = pGetComp(strat->P.sig); |
---|
3072 | int max_cmp = IDELEMS(F); |
---|
3073 | int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int)); |
---|
3074 | pGetExpV (strat->P.p,vv); |
---|
3075 | LObject Q; |
---|
3076 | int pos; |
---|
3077 | int idx = __p_GetComp(strat->P.sig,currRing); |
---|
3078 | //printf("++ -- adding syzygies -- ++\n"); |
---|
3079 | // if new element is the first one in this index |
---|
3080 | if (strat->currIdx < idx) |
---|
3081 | { |
---|
3082 | for (int i=0; i<strat->sl; ++i) |
---|
3083 | { |
---|
3084 | Q.sig = p_Copy(strat->P.sig,currRing); |
---|
3085 | p_ExpVectorAdd(Q.sig,strat->S[i],currRing); |
---|
3086 | poly help = p_Copy(strat->sig[i],currRing); |
---|
3087 | p_ExpVectorAdd(help,strat->P.p,currRing); |
---|
3088 | Q.sig = p_Add_q(Q.sig,help,currRing); |
---|
3089 | //pWrite(Q.sig); |
---|
3090 | pos = posInSyz(strat, Q.sig); |
---|
3091 | enterSyz(Q, strat, pos); |
---|
3092 | } |
---|
3093 | strat->currIdx = idx; |
---|
3094 | } |
---|
3095 | else |
---|
3096 | { |
---|
3097 | // if the element is not the first one in the given index we build all |
---|
3098 | // possible syzygies with elements of higher index |
---|
3099 | for (int i=cmp+1; i<=max_cmp; ++i) |
---|
3100 | { |
---|
3101 | pos = -1; |
---|
3102 | for (int j=0; j<strat->sl; ++j) |
---|
3103 | { |
---|
3104 | if (__p_GetComp(strat->sig[j],currRing) == i) |
---|
3105 | { |
---|
3106 | pos = j; |
---|
3107 | break; |
---|
3108 | } |
---|
3109 | } |
---|
3110 | if (pos != -1) |
---|
3111 | { |
---|
3112 | Q.sig = p_One(currRing); |
---|
3113 | p_SetExpV(Q.sig, vv, currRing); |
---|
3114 | // F->m[i-1] corresponds to index i |
---|
3115 | p_ExpVectorAdd(Q.sig,F->m[i-1],currRing); |
---|
3116 | p_SetComp(Q.sig, i, currRing); |
---|
3117 | poly help = p_Copy(strat->P.sig,currRing); |
---|
3118 | p_ExpVectorAdd(help,strat->S[pos],currRing); |
---|
3119 | Q.sig = p_Add_q(Q.sig,help,currRing); |
---|
3120 | if (strat->sbaOrder == 0) |
---|
3121 | { |
---|
3122 | if (p_LmCmp(Q.sig,strat->syz[strat->syzl-1],currRing) == -currRing->OrdSgn) |
---|
3123 | { |
---|
3124 | pos = posInSyz(strat, Q.sig); |
---|
3125 | enterSyz(Q, strat, pos); |
---|
3126 | } |
---|
3127 | } |
---|
3128 | else |
---|
3129 | { |
---|
3130 | pos = posInSyz(strat, Q.sig); |
---|
3131 | enterSyz(Q, strat, pos); |
---|
3132 | } |
---|
3133 | } |
---|
3134 | } |
---|
3135 | //printf("++ -- done adding syzygies -- ++\n"); |
---|
3136 | } |
---|
3137 | } |
---|
3138 | //#if 1 |
---|
3139 | #if DEBUGF50 |
---|
3140 | printf("---------------------------\n"); |
---|
3141 | Print(" %d. ELEMENT ADDED TO GCURR:\n",strat->sl+1); |
---|
3142 | PrintS("LEAD POLY: "); pWrite(pHead(strat->S[strat->sl])); |
---|
3143 | PrintS("SIGNATURE: "); pWrite(strat->sig[strat->sl]); |
---|
3144 | #endif |
---|
3145 | /* |
---|
3146 | if (newrules) |
---|
3147 | { |
---|
3148 | newrules = FALSE; |
---|
3149 | } |
---|
3150 | */ |
---|
3151 | #if 0 |
---|
3152 | int pl=pLength(strat->P.p); |
---|
3153 | if (pl==1) |
---|
3154 | { |
---|
3155 | //if (TEST_OPT_PROT) |
---|
3156 | //PrintS("<1>"); |
---|
3157 | } |
---|
3158 | else if (pl==2) |
---|
3159 | { |
---|
3160 | //if (TEST_OPT_PROT) |
---|
3161 | //PrintS("<2>"); |
---|
3162 | } |
---|
3163 | #endif |
---|
3164 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
3165 | // Print("[%d]",hilbeledeg); |
---|
3166 | if (strat->P.lcm!=NULL) |
---|
3167 | #ifdef HAVE_RINGS |
---|
3168 | pLmDelete(strat->P.lcm); |
---|
3169 | #else |
---|
3170 | pLmFree(strat->P.lcm); |
---|
3171 | #endif |
---|
3172 | if (strat->sl>srmax) srmax = strat->sl; |
---|
3173 | } |
---|
3174 | else |
---|
3175 | { |
---|
3176 | case_when_red_result_changed: |
---|
3177 | // adds signature of the zero reduction to |
---|
3178 | // strat->syz. This is the leading term of |
---|
3179 | // syzygy and can be used in syzCriterion() |
---|
3180 | // the signature is added if and only if the |
---|
3181 | // pair was not detected by the rewritten criterion in strat->red = redSig |
---|
3182 | if (red_result!=2) |
---|
3183 | { |
---|
3184 | #if SBA_PRINT_ZERO_REDUCTIONS |
---|
3185 | zeroreductions++; |
---|
3186 | #endif |
---|
3187 | if(rField_is_Ring(currRing) && strat->P.p == NULL && strat->P.sig == NULL) |
---|
3188 | { |
---|
3189 | //Catch the case when p = 0, sig = 0 |
---|
3190 | } |
---|
3191 | else |
---|
3192 | { |
---|
3193 | int pos = posInSyz(strat, strat->P.sig); |
---|
3194 | enterSyz(strat->P, strat, pos); |
---|
3195 | //#if 1 |
---|
3196 | #ifdef DEBUGF5 |
---|
3197 | Print("ADDING STUFF TO SYZ : "); |
---|
3198 | //pWrite(strat->P.p); |
---|
3199 | pWrite(strat->P.sig); |
---|
3200 | #endif |
---|
3201 | } |
---|
3202 | } |
---|
3203 | if (strat->P.p1 == NULL && strat->minim > 0) |
---|
3204 | { |
---|
3205 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
3206 | } |
---|
3207 | } |
---|
3208 | |
---|
3209 | #ifdef KDEBUG |
---|
3210 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
3211 | #endif /* KDEBUG */ |
---|
3212 | kTest_TS(strat); |
---|
3213 | } |
---|
3214 | #if 0 |
---|
3215 | if(strat->sigdrop) |
---|
3216 | printf("\nSigDrop!\n"); |
---|
3217 | else |
---|
3218 | printf("\nEnded with no SigDrop\n"); |
---|
3219 | #endif |
---|
3220 | // Clean strat->P for the next sba call |
---|
3221 | if(rField_is_Ring(currRing) && strat->sigdrop) |
---|
3222 | { |
---|
3223 | //This is used to know how many elements can we directly add to S in the next run |
---|
3224 | if(strat->P.sig != NULL) |
---|
3225 | strat->sbaEnterS = pGetComp(strat->P.sig)-1; |
---|
3226 | //else we already set it at the beggining of the loop |
---|
3227 | #ifdef KDEBUG |
---|
3228 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
3229 | #endif /* KDEBUG */ |
---|
3230 | } |
---|
3231 | #ifdef KDEBUG |
---|
3232 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
3233 | #endif /* KDEBUG */ |
---|
3234 | |
---|
3235 | if (TEST_OPT_SB_1) |
---|
3236 | { |
---|
3237 | if(!rField_is_Ring(currRing)) |
---|
3238 | { |
---|
3239 | int k=1; |
---|
3240 | int j; |
---|
3241 | while(k<=strat->sl) |
---|
3242 | { |
---|
3243 | j=0; |
---|
3244 | loop |
---|
3245 | { |
---|
3246 | if (j>=k) break; |
---|
3247 | clearS(strat->S[j],strat->sevS[j],&k,&j,strat); |
---|
3248 | j++; |
---|
3249 | } |
---|
3250 | k++; |
---|
3251 | } |
---|
3252 | } |
---|
3253 | } |
---|
3254 | /* complete reduction of the standard basis--------- */ |
---|
3255 | if (TEST_OPT_REDSB) |
---|
3256 | { |
---|
3257 | completeReduce(strat); |
---|
3258 | if (strat->completeReduce_retry) |
---|
3259 | { |
---|
3260 | // completeReduce needed larger exponents, retry |
---|
3261 | // to reduce with S (instead of T) |
---|
3262 | // and in currRing (instead of strat->tailRing) |
---|
3263 | #ifdef HAVE_TAIL_RING |
---|
3264 | if(currRing->bitmask>strat->tailRing->bitmask) |
---|
3265 | { |
---|
3266 | strat->completeReduce_retry=FALSE; |
---|
3267 | cleanT(strat);strat->tailRing=currRing; |
---|
3268 | int i; |
---|
3269 | for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1; |
---|
3270 | completeReduce(strat); |
---|
3271 | } |
---|
3272 | if (strat->completeReduce_retry) |
---|
3273 | #endif |
---|
3274 | Werror("exponent bound is %ld",currRing->bitmask); |
---|
3275 | } |
---|
3276 | } |
---|
3277 | else if (TEST_OPT_PROT) PrintLn(); |
---|
3278 | |
---|
3279 | #if SBA_PRINT_SIZE_SYZ |
---|
3280 | // that is correct, syzl is counting one too far |
---|
3281 | size_syz = strat->syzl; |
---|
3282 | #endif |
---|
3283 | // if (TEST_OPT_WEIGHTM) |
---|
3284 | // { |
---|
3285 | // pRestoreDegProcs(pFDegOld, pLDegOld); |
---|
3286 | // if (ecartWeights) |
---|
3287 | // { |
---|
3288 | // omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short)); |
---|
3289 | // ecartWeights=NULL; |
---|
3290 | // } |
---|
3291 | // } |
---|
3292 | if (TEST_OPT_PROT) messageStatSBA(hilbcount,strat); |
---|
3293 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
3294 | #if SBA_PRINT_SIZE_G |
---|
3295 | size_g_non_red = IDELEMS(strat->Shdl); |
---|
3296 | #endif |
---|
3297 | if(!rField_is_Ring(currRing)) |
---|
3298 | exitSba(strat); |
---|
3299 | // I have to add the initial input polynomials which where not used (p1 and p2 = NULL) |
---|
3300 | #ifdef HAVE_RINGS |
---|
3301 | int k; |
---|
3302 | if(rField_is_Ring(currRing)) |
---|
3303 | { |
---|
3304 | //for(k = strat->sl;k>=0;k--) |
---|
3305 | // {printf("\nS[%i] = %p\n",k,strat->Shdl->m[k]);pWrite(strat->Shdl->m[k]);} |
---|
3306 | k = strat->Ll; |
---|
3307 | #if 1 |
---|
3308 | // 1 - adds just the unused ones, 0 - adds everthing |
---|
3309 | for(;k>=0 && (strat->L[k].p1 != NULL || strat->L[k].p2 != NULL);k--) |
---|
3310 | { |
---|
3311 | //printf("\nDeleted k = %i, %p\n",k,strat->L[k].p);pWrite(strat->L[k].p);pWrite(strat->L[k].p1);pWrite(strat->L[k].p2); |
---|
3312 | deleteInL(strat->L,&strat->Ll,k,strat); |
---|
3313 | } |
---|
3314 | #endif |
---|
3315 | //for(int kk = strat->sl;kk>=0;kk--) |
---|
3316 | // {printf("\nS[%i] = %p\n",kk,strat->Shdl->m[kk]);pWrite(strat->Shdl->m[kk]);} |
---|
3317 | //idPrint(strat->Shdl); |
---|
3318 | //printf("\nk = %i\n",k); |
---|
3319 | for(;k>=0 && strat->L[k].p1 == NULL && strat->L[k].p2 == NULL;k--) |
---|
3320 | { |
---|
3321 | //printf("\nAdded k = %i\n",k); |
---|
3322 | strat->enterS(strat->L[k], strat->sl+1, strat, strat->tl); |
---|
3323 | //printf("\nThis elements was added from L on pos %i\n",strat->sl);pWrite(strat->S[strat->sl]);pWrite(strat->sig[strat->sl]); |
---|
3324 | } |
---|
3325 | } |
---|
3326 | // Find the "sigdrop element" and put the same signature as the previous one - do we really need this?? - now i put it on the 0 position - no more comparing needed |
---|
3327 | #if 0 |
---|
3328 | if(strat->sigdrop && rField_is_Ring(currRing)) |
---|
3329 | { |
---|
3330 | for(k=strat->sl;k>=0;k--) |
---|
3331 | { |
---|
3332 | printf("\nsig[%i] = ",i);pWrite(strat->sig[k]); |
---|
3333 | if(strat->sig[k] == NULL) |
---|
3334 | strat->sig[k] = pCopy(strat->sig[k-1]); |
---|
3335 | } |
---|
3336 | } |
---|
3337 | #endif |
---|
3338 | #endif |
---|
3339 | //Never do this - you will damage S |
---|
3340 | //idSkipZeroes(strat->Shdl); |
---|
3341 | //idPrint(strat->Shdl); |
---|
3342 | |
---|
3343 | if ((strat->sbaOrder == 1 || strat->sbaOrder == 3) && sRing!=currRingOld) |
---|
3344 | { |
---|
3345 | rChangeCurrRing (currRingOld); |
---|
3346 | F0 = idrMoveR (F1, sRing, currRing); |
---|
3347 | strat->Shdl = idrMoveR_NoSort (strat->Shdl, sRing, currRing); |
---|
3348 | rChangeCurrRing (sRing); |
---|
3349 | if(rField_is_Ring(currRing)) |
---|
3350 | exitSba(strat); |
---|
3351 | rChangeCurrRing (currRingOld); |
---|
3352 | if(strat->tailRing == sRing) |
---|
3353 | strat->tailRing = currRing; |
---|
3354 | rDelete (sRing); |
---|
3355 | } |
---|
3356 | if(rField_is_Ring(currRing) && !strat->sigdrop) |
---|
3357 | id_DelDiv(strat->Shdl, currRing); |
---|
3358 | if(!rField_is_Ring(currRing)) |
---|
3359 | id_DelDiv(strat->Shdl, currRing); |
---|
3360 | idSkipZeroes(strat->Shdl); |
---|
3361 | idTest(strat->Shdl); |
---|
3362 | |
---|
3363 | #if SBA_PRINT_SIZE_G |
---|
3364 | size_g = IDELEMS(strat->Shdl); |
---|
3365 | #endif |
---|
3366 | #ifdef DEBUGF5 |
---|
3367 | printf("SIZE OF SHDL: %d\n",IDELEMS(strat->Shdl)); |
---|
3368 | int oo = 0; |
---|
3369 | while (oo<IDELEMS(strat->Shdl)) |
---|
3370 | { |
---|
3371 | printf(" %d. ",oo+1); |
---|
3372 | pWrite(pHead(strat->Shdl->m[oo])); |
---|
3373 | oo++; |
---|
3374 | } |
---|
3375 | #endif |
---|
3376 | #if SBA_PRINT_ZERO_REDUCTIONS |
---|
3377 | printf("----------------------------------------------------------\n"); |
---|
3378 | printf("ZERO REDUCTIONS: %ld\n",zeroreductions); |
---|
3379 | zeroreductions = 0; |
---|
3380 | #endif |
---|
3381 | #if SBA_PRINT_REDUCTION_STEPS |
---|
3382 | printf("----------------------------------------------------------\n"); |
---|
3383 | printf("S-REDUCTIONS: %ld\n",sba_reduction_steps); |
---|
3384 | #endif |
---|
3385 | #if SBA_PRINT_OPERATIONS |
---|
3386 | printf("OPERATIONS: %ld\n",sba_operations); |
---|
3387 | #endif |
---|
3388 | #if SBA_PRINT_REDUCTION_STEPS |
---|
3389 | printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n"); |
---|
3390 | printf("INTERREDUCTIONS: %ld\n",sba_interreduction_steps); |
---|
3391 | #endif |
---|
3392 | #if SBA_PRINT_OPERATIONS |
---|
3393 | printf("INTERREDUCTION OPERATIONS: %ld\n",sba_interreduction_operations); |
---|
3394 | #endif |
---|
3395 | #if SBA_PRINT_REDUCTION_STEPS |
---|
3396 | printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n"); |
---|
3397 | printf("ALL REDUCTIONS: %ld\n",sba_reduction_steps+sba_interreduction_steps); |
---|
3398 | sba_interreduction_steps = 0; |
---|
3399 | sba_reduction_steps = 0; |
---|
3400 | #endif |
---|
3401 | #if SBA_PRINT_OPERATIONS |
---|
3402 | printf("ALL OPERATIONS: %ld\n",sba_operations+sba_interreduction_operations); |
---|
3403 | sba_interreduction_operations = 0; |
---|
3404 | sba_operations = 0; |
---|
3405 | #endif |
---|
3406 | #if SBA_PRINT_SIZE_G |
---|
3407 | printf("----------------------------------------------------------\n"); |
---|
3408 | printf("SIZE OF G: %d / %d\n",size_g,size_g_non_red); |
---|
3409 | size_g = 0; |
---|
3410 | size_g_non_red = 0; |
---|
3411 | #endif |
---|
3412 | #if SBA_PRINT_SIZE_SYZ |
---|
3413 | printf("SIZE OF SYZ: %ld\n",size_syz); |
---|
3414 | printf("----------------------------------------------------------\n"); |
---|
3415 | size_syz = 0; |
---|
3416 | #endif |
---|
3417 | #if SBA_PRINT_PRODUCT_CRITERION |
---|
3418 | printf("PRODUCT CRITERIA: %ld\n",product_criterion); |
---|
3419 | product_criterion = 0; |
---|
3420 | #endif |
---|
3421 | return (strat->Shdl); |
---|
3422 | } |
---|
3423 | |
---|
3424 | poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce) |
---|
3425 | { |
---|
3426 | assume(q!=NULL); |
---|
3427 | assume(!(idIs0(F)&&(Q==NULL))); // NF(q, std(0) in polynomial ring? |
---|
3428 | |
---|
3429 | // lazy_reduce flags: can be combined by | |
---|
3430 | //#define KSTD_NF_LAZY 1 |
---|
3431 | // do only a reduction of the leading term |
---|
3432 | //#define KSTD_NF_NONORM 4 |
---|
3433 | // only global: avoid normalization, return a multiply of NF |
---|
3434 | poly p; |
---|
3435 | |
---|
3436 | //if ((idIs0(F))&&(Q==NULL)) |
---|
3437 | // return pCopy(q); /*F=0*/ |
---|
3438 | //strat->ak = idRankFreeModule(F); |
---|
3439 | /*- creating temp data structures------------------- -*/ |
---|
3440 | BITSET save1; |
---|
3441 | SI_SAVE_OPT1(save1); |
---|
3442 | si_opt_1|=Sy_bit(OPT_REDTAIL); |
---|
3443 | initBuchMoraCrit(strat); |
---|
3444 | strat->initEcart = initEcartBBA; |
---|
3445 | strat->enterS = enterSBba; |
---|
3446 | #ifndef NO_BUCKETS |
---|
3447 | strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing)); |
---|
3448 | #endif |
---|
3449 | /*- set S -*/ |
---|
3450 | strat->sl = -1; |
---|
3451 | /*- init local data struct.---------------------------------------- -*/ |
---|
3452 | /*Shdl=*/initS(F,Q,strat); |
---|
3453 | /*- compute------------------------------------------------------- -*/ |
---|
3454 | //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0)) |
---|
3455 | //{ |
---|
3456 | // for (i=strat->sl;i>=0;i--) |
---|
3457 | // pNorm(strat->S[i]); |
---|
3458 | //} |
---|
3459 | kTest(strat); |
---|
3460 | if (TEST_OPT_PROT) { PrintS("r"); mflush(); } |
---|
3461 | if (BVERBOSE(23)) kDebugPrint(strat); |
---|
3462 | int max_ind; |
---|
3463 | p = redNF(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat); |
---|
3464 | if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
3465 | { |
---|
3466 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
3467 | if (rField_is_Ring(currRing)) |
---|
3468 | { |
---|
3469 | p = redtailBba_Z(p,max_ind,strat); |
---|
3470 | } |
---|
3471 | else |
---|
3472 | { |
---|
3473 | si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY); |
---|
3474 | p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0); |
---|
3475 | } |
---|
3476 | } |
---|
3477 | /*- release temp data------------------------------- -*/ |
---|
3478 | assume(strat->L==NULL); /* strat->L unused */ |
---|
3479 | assume(strat->B==NULL); /* strat->B unused */ |
---|
3480 | omFree(strat->sevS); |
---|
3481 | omFree(strat->ecartS); |
---|
3482 | assume(strat->T==NULL);//omfree(strat->T); |
---|
3483 | assume(strat->sevT==NULL);//omfree(strat->sevT); |
---|
3484 | assume(strat->R==NULL);//omfree(strat->R); |
---|
3485 | omfree(strat->S_2_R); |
---|
3486 | omfree(strat->fromQ); |
---|
3487 | idDelete(&strat->Shdl); |
---|
3488 | SI_RESTORE_OPT1(save1); |
---|
3489 | if (TEST_OPT_PROT) PrintLn(); |
---|
3490 | return p; |
---|
3491 | } |
---|
3492 | |
---|
3493 | poly kNF2Bound (ideal F,ideal Q,poly q,int bound,kStrategy strat, int lazyReduce) |
---|
3494 | { |
---|
3495 | assume(q!=NULL); |
---|
3496 | assume(!(idIs0(F)&&(Q==NULL))); // NF(q, std(0) in polynomial ring? |
---|
3497 | |
---|
3498 | // lazy_reduce flags: can be combined by | |
---|
3499 | //#define KSTD_NF_LAZY 1 |
---|
3500 | // do only a reduction of the leading term |
---|
3501 | //#define KSTD_NF_NONORM 4 |
---|
3502 | // only global: avoid normalization, return a multiply of NF |
---|
3503 | poly p; |
---|
3504 | |
---|
3505 | //if ((idIs0(F))&&(Q==NULL)) |
---|
3506 | // return pCopy(q); /*F=0*/ |
---|
3507 | //strat->ak = idRankFreeModule(F); |
---|
3508 | /*- creating temp data structures------------------- -*/ |
---|
3509 | BITSET save1; |
---|
3510 | SI_SAVE_OPT1(save1); |
---|
3511 | si_opt_1|=Sy_bit(OPT_REDTAIL); |
---|
3512 | initBuchMoraCrit(strat); |
---|
3513 | strat->initEcart = initEcartBBA; |
---|
3514 | strat->enterS = enterSBba; |
---|
3515 | #ifndef NO_BUCKETS |
---|
3516 | strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing)); |
---|
3517 | #endif |
---|
3518 | /*- set S -*/ |
---|
3519 | strat->sl = -1; |
---|
3520 | /*- init local data struct.---------------------------------------- -*/ |
---|
3521 | /*Shdl=*/initS(F,Q,strat); |
---|
3522 | /*- compute------------------------------------------------------- -*/ |
---|
3523 | //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0)) |
---|
3524 | //{ |
---|
3525 | // for (i=strat->sl;i>=0;i--) |
---|
3526 | // pNorm(strat->S[i]); |
---|
3527 | //} |
---|
3528 | kTest(strat); |
---|
3529 | if (TEST_OPT_PROT) { PrintS("r"); mflush(); } |
---|
3530 | if (BVERBOSE(23)) kDebugPrint(strat); |
---|
3531 | int max_ind; |
---|
3532 | p = redNFBound(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat,bound); |
---|
3533 | if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
3534 | { |
---|
3535 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
3536 | if (rField_is_Ring(currRing)) |
---|
3537 | { |
---|
3538 | p = redtailBba_Z(p,max_ind,strat); |
---|
3539 | } |
---|
3540 | else |
---|
3541 | { |
---|
3542 | si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY); |
---|
3543 | p = redtailBbaBound(p,max_ind,strat,bound,(lazyReduce & KSTD_NF_NONORM)==0); |
---|
3544 | //p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0); |
---|
3545 | } |
---|
3546 | } |
---|
3547 | /*- release temp data------------------------------- -*/ |
---|
3548 | assume(strat->L==NULL); /* strat->L unused */ |
---|
3549 | assume(strat->B==NULL); /* strat->B unused */ |
---|
3550 | omFree(strat->sevS); |
---|
3551 | omFree(strat->ecartS); |
---|
3552 | assume(strat->T==NULL);//omfree(strat->T); |
---|
3553 | assume(strat->sevT==NULL);//omfree(strat->sevT); |
---|
3554 | assume(strat->R==NULL);//omfree(strat->R); |
---|
3555 | omfree(strat->S_2_R); |
---|
3556 | omfree(strat->fromQ); |
---|
3557 | idDelete(&strat->Shdl); |
---|
3558 | SI_RESTORE_OPT1(save1); |
---|
3559 | if (TEST_OPT_PROT) PrintLn(); |
---|
3560 | return p; |
---|
3561 | } |
---|
3562 | |
---|
3563 | ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce) |
---|
3564 | { |
---|
3565 | assume(!idIs0(q)); |
---|
3566 | assume(!(idIs0(F)&&(Q==NULL))); |
---|
3567 | // lazy_reduce flags: can be combined by | |
---|
3568 | //#define KSTD_NF_LAZY 1 |
---|
3569 | // do only a reduction of the leading term |
---|
3570 | //#define KSTD_NF_NONORM 4 |
---|
3571 | // only global: avoid normalization, return a multiply of NF |
---|
3572 | poly p; |
---|
3573 | int i; |
---|
3574 | ideal res; |
---|
3575 | int max_ind; |
---|
3576 | |
---|
3577 | //if (idIs0(q)) |
---|
3578 | // return idInit(IDELEMS(q),si_max(q->rank,F->rank)); |
---|
3579 | //if ((idIs0(F))&&(Q==NULL)) |
---|
3580 | // return idCopy(q); /*F=0*/ |
---|
3581 | //strat->ak = idRankFreeModule(F); |
---|
3582 | /*- creating temp data structures------------------- -*/ |
---|
3583 | BITSET save1; |
---|
3584 | SI_SAVE_OPT1(save1); |
---|
3585 | si_opt_1|=Sy_bit(OPT_REDTAIL); |
---|
3586 | initBuchMoraCrit(strat); |
---|
3587 | strat->initEcart = initEcartBBA; |
---|
3588 | strat->enterS = enterSBba; |
---|
3589 | /*- set S -*/ |
---|
3590 | strat->sl = -1; |
---|
3591 | #ifndef NO_BUCKETS |
---|
3592 | strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing)); |
---|
3593 | #endif |
---|
3594 | /*- init local data struct.---------------------------------------- -*/ |
---|
3595 | /*Shdl=*/initS(F,Q,strat); |
---|
3596 | /*- compute------------------------------------------------------- -*/ |
---|
3597 | res=idInit(IDELEMS(q),si_max(q->rank,F->rank)); |
---|
3598 | si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY); |
---|
3599 | for (i=IDELEMS(q)-1; i>=0; i--) |
---|
3600 | { |
---|
3601 | if (q->m[i]!=NULL) |
---|
3602 | { |
---|
3603 | if (TEST_OPT_PROT) { PrintS("r");mflush(); } |
---|
3604 | p = redNF(pCopy(q->m[i]),max_ind,lazyReduce & KSTD_NF_NONORM,strat); |
---|
3605 | if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
3606 | { |
---|
3607 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
3608 | if (rField_is_Ring(currRing)) |
---|
3609 | { |
---|
3610 | p = redtailBba_Z(p,max_ind,strat); |
---|
3611 | } |
---|
3612 | else |
---|
3613 | { |
---|
3614 | p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0); |
---|
3615 | } |
---|
3616 | } |
---|
3617 | res->m[i]=p; |
---|
3618 | } |
---|
3619 | //else |
---|
3620 | // res->m[i]=NULL; |
---|
3621 | } |
---|
3622 | /*- release temp data------------------------------- -*/ |
---|
3623 | assume(strat->L==NULL); /* strat->L unused */ |
---|
3624 | assume(strat->B==NULL); /* strat->B unused */ |
---|
3625 | omFree(strat->sevS); |
---|
3626 | omFree(strat->ecartS); |
---|
3627 | assume(strat->T==NULL);//omfree(strat->T); |
---|
3628 | assume(strat->sevT==NULL);//omfree(strat->sevT); |
---|
3629 | assume(strat->R==NULL);//omfree(strat->R); |
---|
3630 | omfree(strat->S_2_R); |
---|
3631 | omfree(strat->fromQ); |
---|
3632 | idDelete(&strat->Shdl); |
---|
3633 | SI_RESTORE_OPT1(save1); |
---|
3634 | if (TEST_OPT_PROT) PrintLn(); |
---|
3635 | return res; |
---|
3636 | } |
---|
3637 | |
---|
3638 | ideal kNF2Bound (ideal F,ideal Q,ideal q,int bound,kStrategy strat, int lazyReduce) |
---|
3639 | { |
---|
3640 | assume(!idIs0(q)); |
---|
3641 | assume(!(idIs0(F)&&(Q==NULL))); |
---|
3642 | // lazy_reduce flags: can be combined by | |
---|
3643 | //#define KSTD_NF_LAZY 1 |
---|
3644 | // do only a reduction of the leading term |
---|
3645 | //#define KSTD_NF_NONORM 4 |
---|
3646 | // only global: avoid normalization, return a multiply of NF |
---|
3647 | poly p; |
---|
3648 | int i; |
---|
3649 | ideal res; |
---|
3650 | int max_ind; |
---|
3651 | |
---|
3652 | //if (idIs0(q)) |
---|
3653 | // return idInit(IDELEMS(q),si_max(q->rank,F->rank)); |
---|
3654 | //if ((idIs0(F))&&(Q==NULL)) |
---|
3655 | // return idCopy(q); /*F=0*/ |
---|
3656 | //strat->ak = idRankFreeModule(F); |
---|
3657 | /*- creating temp data structures------------------- -*/ |
---|
3658 | BITSET save1; |
---|
3659 | SI_SAVE_OPT1(save1); |
---|
3660 | si_opt_1|=Sy_bit(OPT_REDTAIL); |
---|
3661 | initBuchMoraCrit(strat); |
---|
3662 | strat->initEcart = initEcartBBA; |
---|
3663 | strat->enterS = enterSBba; |
---|
3664 | /*- set S -*/ |
---|
3665 | strat->sl = -1; |
---|
3666 | #ifndef NO_BUCKETS |
---|
3667 | strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing)); |
---|
3668 | #endif |
---|
3669 | /*- init local data struct.---------------------------------------- -*/ |
---|
3670 | /*Shdl=*/initS(F,Q,strat); |
---|
3671 | /*- compute------------------------------------------------------- -*/ |
---|
3672 | res=idInit(IDELEMS(q),si_max(q->rank,F->rank)); |
---|
3673 | si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY); |
---|
3674 | for (i=IDELEMS(q)-1; i>=0; i--) |
---|
3675 | { |
---|
3676 | if (q->m[i]!=NULL) |
---|
3677 | { |
---|
3678 | if (TEST_OPT_PROT) { PrintS("r");mflush(); } |
---|
3679 | p = redNFBound(pCopy(q->m[i]),max_ind,lazyReduce & KSTD_NF_NONORM,strat,bound); |
---|
3680 | if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
3681 | { |
---|
3682 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
3683 | if (rField_is_Ring(currRing)) |
---|
3684 | { |
---|
3685 | p = redtailBba_Z(p,max_ind,strat); |
---|
3686 | } |
---|
3687 | else |
---|
3688 | { |
---|
3689 | p = redtailBbaBound(p,max_ind,strat,bound,(lazyReduce & KSTD_NF_NONORM)==0); |
---|
3690 | } |
---|
3691 | } |
---|
3692 | res->m[i]=p; |
---|
3693 | } |
---|
3694 | //else |
---|
3695 | // res->m[i]=NULL; |
---|
3696 | } |
---|
3697 | /*- release temp data------------------------------- -*/ |
---|
3698 | assume(strat->L==NULL); /* strat->L unused */ |
---|
3699 | assume(strat->B==NULL); /* strat->B unused */ |
---|
3700 | omFree(strat->sevS); |
---|
3701 | omFree(strat->ecartS); |
---|
3702 | assume(strat->T==NULL);//omfree(strat->T); |
---|
3703 | assume(strat->sevT==NULL);//omfree(strat->sevT); |
---|
3704 | assume(strat->R==NULL);//omfree(strat->R); |
---|
3705 | omfree(strat->S_2_R); |
---|
3706 | omfree(strat->fromQ); |
---|
3707 | idDelete(&strat->Shdl); |
---|
3708 | SI_RESTORE_OPT1(save1); |
---|
3709 | if (TEST_OPT_PROT) PrintLn(); |
---|
3710 | return res; |
---|
3711 | } |
---|
3712 | |
---|
3713 | #if F5C |
---|
3714 | /********************************************************************* |
---|
3715 | * interrreduction step of the signature-based algorithm: |
---|
3716 | * 1. all strat->S are interpreted as new critical pairs |
---|
3717 | * 2. those pairs need to be completely reduced by the usual (non sig- |
---|
3718 | * safe) reduction process (including tail reductions) |
---|
3719 | * 3. strat->S and strat->T are completely new computed in these steps |
---|
3720 | ********************************************************************/ |
---|
3721 | void f5c (kStrategy strat, int& olddeg, int& minimcnt, int& hilbeledeg, |
---|
3722 | int& hilbcount, int& srmax, int& lrmax, int& reduc, ideal Q, |
---|
3723 | intvec *w,intvec *hilb ) |
---|
3724 | { |
---|
3725 | int Ll_old, red_result = 1; |
---|
3726 | int pos = 0; |
---|
3727 | hilbeledeg=1; |
---|
3728 | hilbcount=0; |
---|
3729 | minimcnt=0; |
---|
3730 | srmax = 0; // strat->sl is 0 at this point |
---|
3731 | reduc = olddeg = lrmax = 0; |
---|
3732 | // we cannot use strat->T anymore |
---|
3733 | //cleanT(strat); |
---|
3734 | //strat->tl = -1; |
---|
3735 | Ll_old = strat->Ll; |
---|
3736 | while (strat->tl >= 0) |
---|
3737 | { |
---|
3738 | if(!strat->T[strat->tl].is_redundant) |
---|
3739 | { |
---|
3740 | LObject h; |
---|
3741 | h.p = strat->T[strat->tl].p; |
---|
3742 | h.tailRing = strat->T[strat->tl].tailRing; |
---|
3743 | h.t_p = strat->T[strat->tl].t_p; |
---|
3744 | if (h.p!=NULL) |
---|
3745 | { |
---|
3746 | if (currRing->OrdSgn==-1) |
---|
3747 | { |
---|
3748 | cancelunit(&h); |
---|
3749 | deleteHC(&h, strat); |
---|
3750 | } |
---|
3751 | if (h.p!=NULL) |
---|
3752 | { |
---|
3753 | if (TEST_OPT_INTSTRATEGY) |
---|
3754 | { |
---|
3755 | //pContent(h.p); |
---|
3756 | h.pCleardenom(); // also does a pContent |
---|
3757 | } |
---|
3758 | else |
---|
3759 | { |
---|
3760 | h.pNorm(); |
---|
3761 | } |
---|
3762 | strat->initEcart(&h); |
---|
3763 | if(rField_is_Ring(currRing)) |
---|
3764 | pos = posInLF5CRing(strat->L, Ll_old+1,strat->Ll,&h,strat); |
---|
3765 | else |
---|
3766 | pos = strat->Ll+1; |
---|
3767 | h.sev = pGetShortExpVector(h.p); |
---|
3768 | enterL(&strat->L,&strat->Ll,&strat->Lmax,h,pos); |
---|
3769 | } |
---|
3770 | } |
---|
3771 | } |
---|
3772 | strat->tl--; |
---|
3773 | } |
---|
3774 | strat->sl = -1; |
---|
3775 | #if 0 |
---|
3776 | //#ifdef HAVE_TAIL_RING |
---|
3777 | if(!rField_is_Ring()) // create strong gcd poly computes with tailring and S[i] ->to be fixed |
---|
3778 | kStratInitChangeTailRing(strat); |
---|
3779 | #endif |
---|
3780 | //enterpairs(pOne(),0,0,-1,strat,strat->tl); |
---|
3781 | //strat->sl = -1; |
---|
3782 | /* picks the last element from the lazyset L */ |
---|
3783 | while (strat->Ll>Ll_old) |
---|
3784 | { |
---|
3785 | strat->P = strat->L[strat->Ll]; |
---|
3786 | strat->Ll--; |
---|
3787 | //#if 1 |
---|
3788 | #ifdef DEBUGF5 |
---|
3789 | PrintS("NEXT PAIR TO HANDLE IN INTERRED ALGORITHM\n"); |
---|
3790 | PrintS("-------------------------------------------------\n"); |
---|
3791 | pWrite(pHead(strat->P.p)); |
---|
3792 | pWrite(pHead(strat->P.p1)); |
---|
3793 | pWrite(pHead(strat->P.p2)); |
---|
3794 | printf("%d\n",strat->tl); |
---|
3795 | PrintS("-------------------------------------------------\n"); |
---|
3796 | #endif |
---|
3797 | if (pNext(strat->P.p) == strat->tail) |
---|
3798 | { |
---|
3799 | // deletes the short spoly |
---|
3800 | if (rField_is_Ring(currRing)) |
---|
3801 | pLmDelete(strat->P.p); |
---|
3802 | else |
---|
3803 | pLmFree(strat->P.p); |
---|
3804 | |
---|
3805 | // TODO: needs some masking |
---|
3806 | // TODO: masking needs to vanish once the signature |
---|
3807 | // sutff is completely implemented |
---|
3808 | strat->P.p = NULL; |
---|
3809 | poly m1 = NULL, m2 = NULL; |
---|
3810 | |
---|
3811 | // check that spoly creation is ok |
---|
3812 | while (strat->tailRing != currRing && |
---|
3813 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
3814 | { |
---|
3815 | assume(m1 == NULL && m2 == NULL); |
---|
3816 | // if not, change to a ring where exponents are at least |
---|
3817 | // large enough |
---|
3818 | if (!kStratChangeTailRing(strat)) |
---|
3819 | { |
---|
3820 | WerrorS("OVERFLOW..."); |
---|
3821 | break; |
---|
3822 | } |
---|
3823 | } |
---|
3824 | // create the real one |
---|
3825 | ksCreateSpoly(&(strat->P), NULL, strat->use_buckets, |
---|
3826 | strat->tailRing, m1, m2, strat->R); |
---|
3827 | } |
---|
3828 | else if (strat->P.p1 == NULL) |
---|
3829 | { |
---|
3830 | if (strat->minim > 0) |
---|
3831 | strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing); |
---|
3832 | // for input polys, prepare reduction |
---|
3833 | if(!rField_is_Ring(currRing)) |
---|
3834 | strat->P.PrepareRed(strat->use_buckets); |
---|
3835 | } |
---|
3836 | |
---|
3837 | if (strat->P.p == NULL && strat->P.t_p == NULL) |
---|
3838 | { |
---|
3839 | red_result = 0; |
---|
3840 | } |
---|
3841 | else |
---|
3842 | { |
---|
3843 | if (TEST_OPT_PROT) |
---|
3844 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
3845 | &olddeg,&reduc,strat, red_result); |
---|
3846 | |
---|
3847 | #ifdef DEBUGF5 |
---|
3848 | PrintS("Poly before red: "); |
---|
3849 | pWrite(strat->P.p); |
---|
3850 | #endif |
---|
3851 | /* complete reduction of the element chosen from L */ |
---|
3852 | red_result = strat->red2(&strat->P,strat); |
---|
3853 | if (errorreported) break; |
---|
3854 | } |
---|
3855 | |
---|
3856 | if (strat->overflow) |
---|
3857 | { |
---|
3858 | if (!kStratChangeTailRing(strat)) { WerrorS("OVERFLOW.."); break;} |
---|
3859 | } |
---|
3860 | |
---|
3861 | // reduction to non-zero new poly |
---|
3862 | if (red_result == 1) |
---|
3863 | { |
---|
3864 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
3865 | strat->P.GetP(strat->lmBin); |
---|
3866 | // in the homogeneous case FDeg >= pFDeg (sugar/honey) |
---|
3867 | // but now, for entering S, T, we reset it |
---|
3868 | // in the inhomogeneous case: FDeg == pFDeg |
---|
3869 | if (strat->homog) strat->initEcart(&(strat->P)); |
---|
3870 | |
---|
3871 | /* statistic */ |
---|
3872 | if (TEST_OPT_PROT) PrintS("s"); |
---|
3873 | int pos; |
---|
3874 | #if 1 |
---|
3875 | if(!rField_is_Ring(currRing)) |
---|
3876 | pos = posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
3877 | else |
---|
3878 | pos = posInSMonFirst(strat,strat->sl,strat->P.p); |
---|
3879 | #else |
---|
3880 | pos = posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
3881 | #endif |
---|
3882 | // reduce the tail and normalize poly |
---|
3883 | // in the ring case we cannot expect LC(f) = 1, |
---|
3884 | // therefore we call pContent instead of pNorm |
---|
3885 | #if F5CTAILRED |
---|
3886 | BOOLEAN withT = TRUE; |
---|
3887 | if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing))) |
---|
3888 | { |
---|
3889 | strat->P.pCleardenom(); |
---|
3890 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
3891 | { |
---|
3892 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
3893 | strat->P.pCleardenom(); |
---|
3894 | } |
---|
3895 | } |
---|
3896 | else |
---|
3897 | { |
---|
3898 | strat->P.pNorm(); |
---|
3899 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
3900 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
3901 | } |
---|
3902 | #endif |
---|
3903 | #ifdef KDEBUG |
---|
3904 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
3905 | #endif /* KDEBUG */ |
---|
3906 | |
---|
3907 | // min_std stuff |
---|
3908 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
3909 | { |
---|
3910 | if (strat->minim==1) |
---|
3911 | { |
---|
3912 | strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing); |
---|
3913 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
3914 | } |
---|
3915 | else |
---|
3916 | { |
---|
3917 | strat->M->m[minimcnt]=strat->P.p2; |
---|
3918 | strat->P.p2=NULL; |
---|
3919 | } |
---|
3920 | if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL) |
---|
3921 | pNext(strat->M->m[minimcnt]) |
---|
3922 | = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]), |
---|
3923 | strat->tailRing, currRing, |
---|
3924 | currRing->PolyBin); |
---|
3925 | minimcnt++; |
---|
3926 | } |
---|
3927 | |
---|
3928 | // enter into S, L, and T |
---|
3929 | // here we need to recompute new signatures, but those are trivial ones |
---|
3930 | if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp)) |
---|
3931 | { |
---|
3932 | enterT(strat->P, strat); |
---|
3933 | // posInS only depends on the leading term |
---|
3934 | strat->enterS(strat->P, pos, strat, strat->tl); |
---|
3935 | //#if 1 |
---|
3936 | #ifdef DEBUGF5 |
---|
3937 | PrintS("ELEMENT ADDED TO GCURR DURING INTERRED: "); |
---|
3938 | pWrite(pHead(strat->S[strat->sl])); |
---|
3939 | pWrite(strat->sig[strat->sl]); |
---|
3940 | #endif |
---|
3941 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
3942 | } |
---|
3943 | // Print("[%d]",hilbeledeg); |
---|
3944 | if (strat->P.lcm!=NULL) |
---|
3945 | #ifdef HAVE_RINGS |
---|
3946 | pLmDelete(strat->P.lcm); |
---|
3947 | #else |
---|
3948 | pLmFree(strat->P.lcm); |
---|
3949 | #endif |
---|
3950 | if (strat->sl>srmax) srmax = strat->sl; |
---|
3951 | } |
---|
3952 | else |
---|
3953 | { |
---|
3954 | // adds signature of the zero reduction to |
---|
3955 | // strat->syz. This is the leading term of |
---|
3956 | // syzygy and can be used in syzCriterion() |
---|
3957 | // the signature is added if and only if the |
---|
3958 | // pair was not detected by the rewritten criterion in strat->red = redSig |
---|
3959 | if (strat->P.p1 == NULL && strat->minim > 0) |
---|
3960 | { |
---|
3961 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
3962 | } |
---|
3963 | } |
---|
3964 | |
---|
3965 | #ifdef KDEBUG |
---|
3966 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
3967 | #endif /* KDEBUG */ |
---|
3968 | } |
---|
3969 | int cc = 0; |
---|
3970 | while (cc<strat->tl+1) |
---|
3971 | { |
---|
3972 | strat->T[cc].sig = pOne(); |
---|
3973 | p_SetComp(strat->T[cc].sig,cc+1,currRing); |
---|
3974 | strat->T[cc].sevSig = pGetShortExpVector(strat->T[cc].sig); |
---|
3975 | strat->sig[cc] = strat->T[cc].sig; |
---|
3976 | strat->sevSig[cc] = strat->T[cc].sevSig; |
---|
3977 | strat->T[cc].is_sigsafe = TRUE; |
---|
3978 | cc++; |
---|
3979 | } |
---|
3980 | strat->max_lower_index = strat->tl; |
---|
3981 | // set current signature index of upcoming iteration step |
---|
3982 | // NOTE: this needs to be set here, as otherwise initSyzRules cannot compute |
---|
3983 | // the corresponding syzygy rules correctly |
---|
3984 | strat->currIdx = cc+1; |
---|
3985 | for (int cd=strat->Ll; cd>=0; cd--) |
---|
3986 | { |
---|
3987 | p_SetComp(strat->L[cd].sig,cc+1,currRing); |
---|
3988 | cc++; |
---|
3989 | } |
---|
3990 | for (cc=strat->sl+1; cc<IDELEMS(strat->Shdl); ++cc) |
---|
3991 | strat->Shdl->m[cc] = NULL; |
---|
3992 | #if 0 |
---|
3993 | printf("\nAfter f5c sorting\n"); |
---|
3994 | for(int i=0;i<=strat->sl;i++) |
---|
3995 | pWrite(pHead(strat->S[i])); |
---|
3996 | getchar(); |
---|
3997 | #endif |
---|
3998 | //#if 1 |
---|
3999 | #if DEBUGF5 |
---|
4000 | PrintS("------------------- STRAT S ---------------------\n"); |
---|
4001 | cc = 0; |
---|
4002 | while (cc<strat->tl+1) |
---|
4003 | { |
---|
4004 | pWrite(pHead(strat->S[cc])); |
---|
4005 | pWrite(strat->sig[cc]); |
---|
4006 | printf("- - - - - -\n"); |
---|
4007 | cc++; |
---|
4008 | } |
---|
4009 | PrintS("-------------------------------------------------\n"); |
---|
4010 | PrintS("------------------- STRAT T ---------------------\n"); |
---|
4011 | cc = 0; |
---|
4012 | while (cc<strat->tl+1) |
---|
4013 | { |
---|
4014 | pWrite(pHead(strat->T[cc].p)); |
---|
4015 | pWrite(strat->T[cc].sig); |
---|
4016 | printf("- - - - - -\n"); |
---|
4017 | cc++; |
---|
4018 | } |
---|
4019 | PrintS("-------------------------------------------------\n"); |
---|
4020 | PrintS("------------------- STRAT L ---------------------\n"); |
---|
4021 | cc = 0; |
---|
4022 | while (cc<strat->Ll+1) |
---|
4023 | { |
---|
4024 | pWrite(pHead(strat->L[cc].p)); |
---|
4025 | pWrite(pHead(strat->L[cc].p1)); |
---|
4026 | pWrite(pHead(strat->L[cc].p2)); |
---|
4027 | pWrite(strat->L[cc].sig); |
---|
4028 | printf("- - - - - -\n"); |
---|
4029 | cc++; |
---|
4030 | } |
---|
4031 | PrintS("-------------------------------------------------\n"); |
---|
4032 | printf("F5C DONE\nSTRAT SL: %d -- %d\n",strat->sl, strat->currIdx); |
---|
4033 | #endif |
---|
4034 | |
---|
4035 | } |
---|
4036 | #endif |
---|
4037 | |
---|
4038 | /* shiftgb stuff */ |
---|
4039 | #ifdef HAVE_SHIFTBBA |
---|
4040 | |
---|
4041 | |
---|
4042 | ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, int uptodeg, int lV) |
---|
4043 | { |
---|
4044 | int red_result = 1; |
---|
4045 | int olddeg,reduc; |
---|
4046 | int hilbeledeg=1,hilbcount=0,minimcnt=0; |
---|
4047 | BOOLEAN withT = TRUE; // very important for shifts |
---|
4048 | |
---|
4049 | initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit, NO CHANGES */ |
---|
4050 | if(rField_is_Ring(currRing)) |
---|
4051 | initBuchMoraPosRing(strat); |
---|
4052 | else |
---|
4053 | initBuchMoraPos(strat); /*NO CHANGES YET: perhaps later*/ |
---|
4054 | initHilbCrit(F,Q,&hilb,strat); /*NO CHANGES*/ |
---|
4055 | initBbaShift(strat); /* DONE */ |
---|
4056 | /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/ |
---|
4057 | /*Shdl=*/initBuchMoraShift(F, Q,strat); /* updateS with no toT, i.e. no init for T */ |
---|
4058 | updateSShift(strat,uptodeg,lV); /* initializes T */ |
---|
4059 | |
---|
4060 | if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank); |
---|
4061 | reduc = olddeg = 0; |
---|
4062 | strat->lV=lV; |
---|
4063 | |
---|
4064 | #ifndef NO_BUCKETS |
---|
4065 | if (!TEST_OPT_NOT_BUCKETS) |
---|
4066 | strat->use_buckets = 1; |
---|
4067 | #endif |
---|
4068 | |
---|
4069 | // redtailBBa against T for inhomogenous input |
---|
4070 | // if (!TEST_OPT_OLDSTD) |
---|
4071 | // withT = ! strat->homog; |
---|
4072 | |
---|
4073 | // strat->posInT = posInT_pLength; |
---|
4074 | kTest_TS(strat); |
---|
4075 | |
---|
4076 | #ifdef HAVE_TAIL_RING |
---|
4077 | kStratInitChangeTailRing(strat); |
---|
4078 | #endif |
---|
4079 | |
---|
4080 | /* compute------------------------------------------------------- */ |
---|
4081 | while (strat->Ll >= 0) |
---|
4082 | { |
---|
4083 | #ifdef KDEBUG |
---|
4084 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
4085 | #endif |
---|
4086 | if (strat->Ll== 0) strat->interpt=TRUE; |
---|
4087 | if (TEST_OPT_DEGBOUND |
---|
4088 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
4089 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))) |
---|
4090 | { |
---|
4091 | /* |
---|
4092 | *stops computation if |
---|
4093 | * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then |
---|
4094 | *a predefined number Kstd1_deg |
---|
4095 | */ |
---|
4096 | while ((strat->Ll >= 0) |
---|
4097 | && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL) |
---|
4098 | && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)) |
---|
4099 | || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))) |
---|
4100 | ) |
---|
4101 | deleteInL(strat->L,&strat->Ll,strat->Ll,strat); |
---|
4102 | if (strat->Ll<0) break; |
---|
4103 | else strat->noClearS=TRUE; |
---|
4104 | } |
---|
4105 | /* picks the last element from the lazyset L */ |
---|
4106 | strat->P = strat->L[strat->Ll]; |
---|
4107 | strat->Ll--; |
---|
4108 | |
---|
4109 | if (pNext(strat->P.p) == strat->tail) |
---|
4110 | { |
---|
4111 | // deletes the short spoly |
---|
4112 | pLmFree(strat->P.p); |
---|
4113 | strat->P.p = NULL; |
---|
4114 | poly m1 = NULL, m2 = NULL; |
---|
4115 | |
---|
4116 | // check that spoly creation is ok |
---|
4117 | while (strat->tailRing != currRing && |
---|
4118 | !kCheckSpolyCreation(&(strat->P), strat, m1, m2)) |
---|
4119 | { |
---|
4120 | assume(m1 == NULL && m2 == NULL); |
---|
4121 | // if not, change to a ring where exponents are at least |
---|
4122 | // large enough |
---|
4123 | kStratChangeTailRing(strat); |
---|
4124 | } |
---|
4125 | // create the real one |
---|
4126 | ksCreateSpoly(&(strat->P), NULL, strat->use_buckets, |
---|
4127 | strat->tailRing, m1, m2, strat->R); |
---|
4128 | } |
---|
4129 | else if (strat->P.p1 == NULL) |
---|
4130 | { |
---|
4131 | if (strat->minim > 0) |
---|
4132 | strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing); |
---|
4133 | // for input polys, prepare reduction |
---|
4134 | strat->P.PrepareRed(strat->use_buckets); |
---|
4135 | } |
---|
4136 | |
---|
4137 | poly qq; |
---|
4138 | |
---|
4139 | /* here in the nonhomog case we shrink the new spoly */ |
---|
4140 | |
---|
4141 | if ( ! strat->homog) |
---|
4142 | { |
---|
4143 | strat->P.GetP(strat->lmBin); // because shifts are counted with .p structure |
---|
4144 | /* in the nonhomog case we have to shrink the polynomial */ |
---|
4145 | assume(strat->P.t_p!=NULL); |
---|
4146 | qq = p_Shrink(strat->P.t_p, lV, strat->tailRing); // direct shrink |
---|
4147 | if (qq != NULL) |
---|
4148 | { |
---|
4149 | /* we're here if Shrink is nonzero */ |
---|
4150 | // strat->P.p = NULL; |
---|
4151 | // strat->P.Delete(); /* deletes P.p and P.t_p */ //error |
---|
4152 | strat->P.p = NULL; // is not set by Delete |
---|
4153 | strat->P.t_p = qq; |
---|
4154 | strat->P.GetP(strat->lmBin); |
---|
4155 | // update sev and length |
---|
4156 | strat->initEcart(&(strat->P)); |
---|
4157 | strat->P.sev = pGetShortExpVector(strat->P.p); |
---|
4158 | // strat->P.FDeg = strat->P.pFDeg(); |
---|
4159 | // strat->P.length = strat->P.pLDeg(); |
---|
4160 | // strat->P.pLength =strat->P.GetpLength(); //pLength(strat->P.p); |
---|
4161 | } |
---|
4162 | else |
---|
4163 | { |
---|
4164 | /* Shrink is zero, like y(1)*y(2) - y(1)*y(3)*/ |
---|
4165 | #ifdef KDEBUG |
---|
4166 | if (TEST_OPT_DEBUG){PrintS("nonzero s shrinks to 0");PrintLn();} |
---|
4167 | #endif |
---|
4168 | // strat->P.Delete(); // cause error |
---|
4169 | strat->P.p = NULL; |
---|
4170 | strat->P.t_p = NULL; |
---|
4171 | // strat->P.p = NULL; // or delete strat->P.p ? |
---|
4172 | } |
---|
4173 | } |
---|
4174 | /* end shrinking poly in the nonhomog case */ |
---|
4175 | |
---|
4176 | if (strat->P.p == NULL && strat->P.t_p == NULL) |
---|
4177 | { |
---|
4178 | red_result = 0; |
---|
4179 | } |
---|
4180 | else |
---|
4181 | { |
---|
4182 | if (TEST_OPT_PROT) |
---|
4183 | message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(), |
---|
4184 | &olddeg,&reduc,strat, red_result); |
---|
4185 | |
---|
4186 | /* reduction of the element chosen from L */ |
---|
4187 | red_result = strat->red(&strat->P,strat); |
---|
4188 | } |
---|
4189 | |
---|
4190 | // reduction to non-zero new poly |
---|
4191 | if (red_result == 1) |
---|
4192 | { |
---|
4193 | /* statistic */ |
---|
4194 | if (TEST_OPT_PROT) PrintS("s"); |
---|
4195 | |
---|
4196 | // get the polynomial (canonicalize bucket, make sure P.p is set) |
---|
4197 | strat->P.GetP(strat->lmBin); |
---|
4198 | |
---|
4199 | int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart); |
---|
4200 | |
---|
4201 | // reduce the tail and normalize poly |
---|
4202 | if (TEST_OPT_INTSTRATEGY) |
---|
4203 | { |
---|
4204 | strat->P.pCleardenom(); |
---|
4205 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
4206 | { |
---|
4207 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
4208 | strat->P.pCleardenom(); |
---|
4209 | } |
---|
4210 | } |
---|
4211 | else |
---|
4212 | { |
---|
4213 | strat->P.pNorm(); |
---|
4214 | if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL)) |
---|
4215 | strat->P.p = redtailBba(&(strat->P),pos-1,strat, withT); |
---|
4216 | } |
---|
4217 | |
---|
4218 | // here we must shrink again! and optionally reduce again |
---|
4219 | // or build shrink into redtailBba! |
---|
4220 | |
---|
4221 | #ifdef KDEBUG |
---|
4222 | if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();} |
---|
4223 | #endif |
---|
4224 | |
---|
4225 | // min_std stuff |
---|
4226 | if ((strat->P.p1==NULL) && (strat->minim>0)) |
---|
4227 | { |
---|
4228 | if (strat->minim==1) |
---|
4229 | { |
---|
4230 | strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing); |
---|
4231 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
4232 | } |
---|
4233 | else |
---|
4234 | { |
---|
4235 | strat->M->m[minimcnt]=strat->P.p2; |
---|
4236 | strat->P.p2=NULL; |
---|
4237 | } |
---|
4238 | if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL) |
---|
4239 | pNext(strat->M->m[minimcnt]) |
---|
4240 | = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]), |
---|
4241 | strat->tailRing, currRing, |
---|
4242 | currRing->PolyBin); |
---|
4243 | minimcnt++; |
---|
4244 | } |
---|
4245 | |
---|
4246 | /* here in the nonhomog case we shrink the reduced poly AGAIN */ |
---|
4247 | |
---|
4248 | if ( ! strat->homog) |
---|
4249 | { |
---|
4250 | strat->P.GetP(strat->lmBin); // because shifts are counted with .p structure |
---|
4251 | /* assume strat->P.t_p != NULL */ |
---|
4252 | /* in the nonhomog case we have to shrink the polynomial */ |
---|
4253 | assume(strat->P.t_p!=NULL); // poly qq defined above |
---|
4254 | qq = p_Shrink(strat->P.t_p, lV, strat->tailRing); // direct shrink |
---|
4255 | if (qq != NULL) |
---|
4256 | { |
---|
4257 | /* we're here if Shrink is nonzero */ |
---|
4258 | // strat->P.p = NULL; |
---|
4259 | // strat->P.Delete(); /* deletes P.p and P.t_p */ //error |
---|
4260 | strat->P.p = NULL; // is not set by Delete |
---|
4261 | strat->P.t_p = qq; |
---|
4262 | strat->P.GetP(strat->lmBin); |
---|
4263 | // update sev and length |
---|
4264 | strat->initEcart(&(strat->P)); |
---|
4265 | strat->P.sev = pGetShortExpVector(strat->P.p); |
---|
4266 | } |
---|
4267 | else |
---|
4268 | { |
---|
4269 | /* Shrink is zero, like y(1)*y(2) - y(1)*y(3)*/ |
---|
4270 | #ifdef PDEBUG |
---|
4271 | if (TEST_OPT_DEBUG){PrintS("nonzero s shrinks to 0");PrintLn();} |
---|
4272 | #endif |
---|
4273 | // strat->P.Delete(); // cause error |
---|
4274 | strat->P.p = NULL; |
---|
4275 | strat->P.t_p = NULL; |
---|
4276 | // strat->P.p = NULL; // or delete strat->P.p ? |
---|
4277 | goto red_shrink2zero; |
---|
4278 | } |
---|
4279 | } |
---|
4280 | /* end shrinking poly AGAIN in the nonhomog case */ |
---|
4281 | |
---|
4282 | |
---|
4283 | // enter into S, L, and T |
---|
4284 | //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp)) |
---|
4285 | // enterT(strat->P, strat); // this was here before Shift stuff |
---|
4286 | //enterTShift(LObject p, kStrategy strat, int atT, int uptodeg, int lV); // syntax |
---|
4287 | // the default value for atT = -1 as in bba |
---|
4288 | /* strat->P.GetP(); */ |
---|
4289 | // because shifts are counted with .p structure // done before, but ? |
---|
4290 | int atR=strat->tl+1; // enterTShift introduces T[tl+1], T[tl+2]... |
---|
4291 | // with T[tl+1]=P.p |
---|
4292 | enterTShift(strat->P,strat,-1,uptodeg, lV); |
---|
4293 | enterpairsShift(strat->P.p,strat->sl,strat->P.ecart,pos,strat, atR,uptodeg,lV); |
---|
4294 | // enterpairsShift(vw,strat->sl,strat->P.ecart,pos,strat, strat->tl,uptodeg,lV); |
---|
4295 | // posInS only depends on the leading term |
---|
4296 | strat->enterS(strat->P, pos, strat, atR); |
---|
4297 | |
---|
4298 | if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat); |
---|
4299 | // Print("[%d]",hilbeledeg); |
---|
4300 | if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm); |
---|
4301 | } |
---|
4302 | else |
---|
4303 | { |
---|
4304 | red_shrink2zero: |
---|
4305 | if (strat->P.p1 == NULL && strat->minim > 0) |
---|
4306 | { |
---|
4307 | p_Delete(&strat->P.p2, currRing, strat->tailRing); |
---|
4308 | } |
---|
4309 | } |
---|
4310 | #ifdef KDEBUG |
---|
4311 | memset(&(strat->P), 0, sizeof(strat->P)); |
---|
4312 | #endif |
---|
4313 | kTest_TS(strat); |
---|
4314 | } |
---|
4315 | #ifdef KDEBUG |
---|
4316 | if (TEST_OPT_DEBUG) messageSets(strat); |
---|
4317 | #endif |
---|
4318 | /* complete reduction of the standard basis--------- */ |
---|
4319 | /* shift case: look for elt's in S such that they are divisible by elt in T */ |
---|
4320 | // if (TEST_OPT_SB_1) |
---|
4321 | if (TEST_OPT_REDSB) |
---|
4322 | { |
---|
4323 | int k=0; |
---|
4324 | int j=-1; |
---|
4325 | while(k<=strat->sl) |
---|
4326 | { |
---|
4327 | // loop |
---|
4328 | // { |
---|
4329 | // if (j>=k) break; |
---|
4330 | // clearS(strat->S[j],strat->sevS[j],&k,&j,strat); |
---|
4331 | // j++; |
---|
4332 | // } |
---|
4333 | LObject Ln (strat->S[k],currRing, strat->tailRing); |
---|
4334 | Ln.SetShortExpVector(); |
---|
4335 | j = kFindDivisibleByInT(strat, &Ln, j+1); |
---|
4336 | if (j<0) { k++; j=-1;} |
---|
4337 | else |
---|
4338 | { |
---|
4339 | if ( pLmCmp(strat->S[k],strat->T[j].p) == 0) |
---|
4340 | { |
---|
4341 | j = kFindDivisibleByInT(strat, &Ln, j+1); |
---|
4342 | if (j<0) { k++; j=-1;} |
---|
4343 | else |
---|
4344 | { |
---|
4345 | deleteInS(k,strat); |
---|
4346 | } |
---|
4347 | } |
---|
4348 | else |
---|
4349 | { |
---|
4350 | deleteInS(k,strat); |
---|
4351 | } |
---|
4352 | } |
---|
4353 | } |
---|
4354 | } |
---|
4355 | |
---|
4356 | if (TEST_OPT_REDSB) |
---|
4357 | { completeReduce(strat, TRUE); //shift: withT = TRUE |
---|
4358 | if (strat->completeReduce_retry) |
---|
4359 | { |
---|
4360 | // completeReduce needed larger exponents, retry |
---|
4361 | // to reduce with S (instead of T) |
---|
4362 | // and in currRing (instead of strat->tailRing) |
---|
4363 | #ifdef HAVE_TAIL_RING |
---|
4364 | if(currRing->bitmask>strat->tailRing->bitmask) |
---|
4365 | { |
---|
4366 | strat->completeReduce_retry=FALSE; |
---|
4367 | cleanT(strat);strat->tailRing=currRing; |
---|
4368 | int i; |
---|
4369 | for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1; |
---|
4370 | completeReduce(strat); |
---|
4371 | } |
---|
4372 | if (strat->completeReduce_retry) |
---|
4373 | #endif |
---|
4374 | Werror("exponent bound is %ld",currRing->bitmask); |
---|
4375 | } |
---|
4376 | } |
---|
4377 | else if (TEST_OPT_PROT) PrintLn(); |
---|
4378 | |
---|
4379 | /* release temp data-------------------------------- */ |
---|
4380 | exitBuchMora(strat); |
---|
4381 | // if (TEST_OPT_WEIGHTM) |
---|
4382 | // { |
---|
4383 | // pRestoreDegProcs(currRing,pFDegOld, pLDegOld); |
---|
4384 | // if (ecartWeights) |
---|
4385 | // { |
---|
4386 | // omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short)); |
---|
4387 | // ecartWeights=NULL; |
---|
4388 | // } |
---|
4389 | // } |
---|
4390 | if (TEST_OPT_PROT) messageStat(hilbcount,strat); |
---|
4391 | if (Q!=NULL) updateResult(strat->Shdl,Q,strat); |
---|
4392 | return (strat->Shdl); |
---|
4393 | } |
---|
4394 | |
---|
4395 | |
---|
4396 | ideal freegb(ideal I, int uptodeg, int lVblock) |
---|
4397 | { |
---|
4398 | /* todo main call */ |
---|
4399 | |
---|
4400 | /* assume: ring is prepared, ideal is copied into shifted ring */ |
---|
4401 | /* uptodeg and lVblock are correct - test them! */ |
---|
4402 | |
---|
4403 | /* check whether the ideal is in V */ |
---|
4404 | |
---|
4405 | // if (0) |
---|
4406 | if (! ideal_isInV(I,lVblock) ) |
---|
4407 | { |
---|
4408 | WerrorS("The input ideal contains incorrectly encoded elements! "); |
---|
4409 | return(NULL); |
---|
4410 | } |
---|
4411 | |
---|
4412 | // kStrategy strat = new skStrategy; |
---|
4413 | /* ideal bbaShift(ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, int uptodeg, int lV) */ |
---|
4414 | /* at the moment: |
---|
4415 | - no quotient (check) |
---|
4416 | - no *w, no *hilb |
---|
4417 | */ |
---|
4418 | /* ideal F, ideal Q, tHomog h,intvec ** w, intvec *hilb,int syzComp, |
---|
4419 | int newIdeal, intvec *vw) */ |
---|
4420 | ideal RS = kStdShift(I,NULL, testHomog, NULL,NULL,0,0,NULL, uptodeg, lVblock); |
---|
4421 | //bbaShift(I,NULL, NULL, NULL, strat, uptodeg, lVblock); |
---|
4422 | idSkipZeroes(RS); |
---|
4423 | return(RS); |
---|
4424 | } |
---|
4425 | |
---|
4426 | /*2 |
---|
4427 | *reduces h with elements from T choosing the first possible |
---|
4428 | * element in t with respect to the given pDivisibleBy |
---|
4429 | */ |
---|
4430 | int redFirstShift (LObject* h,kStrategy strat) |
---|
4431 | { |
---|
4432 | if (h->IsNull()) return 0; |
---|
4433 | |
---|
4434 | int at, reddeg,d; |
---|
4435 | int pass = 0; |
---|
4436 | int j = 0; |
---|
4437 | |
---|
4438 | if (! strat->homog) |
---|
4439 | { |
---|
4440 | d = h->GetpFDeg() + h->ecart; |
---|
4441 | reddeg = strat->LazyDegree+d; |
---|
4442 | } |
---|
4443 | h->SetShortExpVector(); |
---|
4444 | loop |
---|
4445 | { |
---|
4446 | j = kFindDivisibleByInT(strat, h); |
---|
4447 | if (j < 0) |
---|
4448 | { |
---|
4449 | h->SetDegStuffReturnLDeg(strat->LDegLast); |
---|
4450 | return 1; |
---|
4451 | } |
---|
4452 | |
---|
4453 | if (!TEST_OPT_INTSTRATEGY) |
---|
4454 | strat->T[j].pNorm(); |
---|
4455 | #ifdef KDEBUG |
---|
4456 | if (TEST_OPT_DEBUG) |
---|
4457 | { |
---|
4458 | PrintS("reduce "); |
---|
4459 | h->wrp(); |
---|
4460 | PrintS(" with "); |
---|
4461 | strat->T[j].wrp(); |
---|
4462 | } |
---|
4463 | #endif |
---|
4464 | ksReducePoly(h, &(strat->T[j]), strat->kNoetherTail(), NULL, strat); |
---|
4465 | if (!h->IsNull()) |
---|
4466 | { |
---|
4467 | poly qq=p_Shrink(h->GetTP(),strat->lV,strat->tailRing); |
---|
4468 | h->p=NULL; |
---|
4469 | h->t_p=qq; |
---|
4470 | if (qq!=NULL) h->GetP(strat->lmBin); |
---|
4471 | } |
---|
4472 | |
---|
4473 | #ifdef KDEBUG |
---|
4474 | if (TEST_OPT_DEBUG) |
---|
4475 | { |
---|
4476 | PrintS("\nto "); |
---|
4477 | wrp(h->p); |
---|
4478 | PrintLn(); |
---|
4479 | } |
---|
4480 | #endif |
---|
4481 | if (h->IsNull()) |
---|
4482 | { |
---|
4483 | if (h->lcm!=NULL) pLmFree(h->lcm); |
---|
4484 | h->Clear(); |
---|
4485 | return 0; |
---|
4486 | } |
---|
4487 | h->SetShortExpVector(); |
---|
4488 | |
---|
4489 | #if 0 |
---|
4490 | if ((strat->syzComp!=0) && !strat->honey) |
---|
4491 | { |
---|
4492 | if ((strat->syzComp>0) && |
---|
4493 | (h->Comp() > strat->syzComp)) |
---|
4494 | { |
---|
4495 | assume(h->MinComp() > strat->syzComp); |
---|
4496 | #ifdef KDEBUG |
---|
4497 | if (TEST_OPT_DEBUG) PrintS(" > syzComp\n"); |
---|
4498 | #endif |
---|
4499 | if (strat->homog) |
---|
4500 | h->SetDegStuffReturnLDeg(strat->LDegLast); |
---|
4501 | return -2; |
---|
4502 | } |
---|
4503 | } |
---|
4504 | #endif |
---|
4505 | if (!strat->homog) |
---|
4506 | { |
---|
4507 | if (!TEST_OPT_OLDSTD && strat->honey) |
---|
4508 | { |
---|
4509 | h->SetpFDeg(); |
---|
4510 | if (strat->T[j].ecart <= h->ecart) |
---|
4511 | h->ecart = d - h->GetpFDeg(); |
---|
4512 | else |
---|
4513 | h->ecart = d - h->GetpFDeg() + strat->T[j].ecart - h->ecart; |
---|
4514 | |
---|
4515 | d = h->GetpFDeg() + h->ecart; |
---|
4516 | } |
---|
4517 | else |
---|
4518 | d = h->SetDegStuffReturnLDeg(strat->LDegLast); |
---|
4519 | /*- try to reduce the s-polynomial -*/ |
---|
4520 | pass++; |
---|
4521 | /* |
---|
4522 | *test whether the polynomial should go to the lazyset L |
---|
4523 | *-if the degree jumps |
---|
4524 | *-if the number of pre-defined reductions jumps |
---|
4525 | */ |
---|
4526 | if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) |
---|
4527 | && ((d >= reddeg) || (pass > strat->LazyPass))) |
---|
4528 | { |
---|
4529 | h->SetLmCurrRing(); |
---|
4530 | if (strat->posInLDependsOnLength) |
---|
4531 | h->SetLength(strat->length_pLength); |
---|
4532 | at = strat->posInL(strat->L,strat->Ll,h,strat); |
---|
4533 | if (at <= strat->Ll) |
---|
4534 | { |
---|
4535 | //int dummy=strat->sl; |
---|
4536 | /* if (kFindDivisibleByInS(strat,&dummy, h) < 0) */ |
---|
4537 | //if (kFindDivisibleByInT(strat->T,strat->sevT, dummy, h) < 0) |
---|
4538 | if (kFindDivisibleByInT(strat, h) < 0) |
---|
4539 | return 1; |
---|
4540 | enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at); |
---|
4541 | #ifdef KDEBUG |
---|
4542 | if (TEST_OPT_DEBUG) Print(" degree jumped; ->L%d\n",at); |
---|
4543 | #endif |
---|
4544 | h->Clear(); |
---|
4545 | return -1; |
---|
4546 | } |
---|
4547 | } |
---|
4548 | if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d >= reddeg)) |
---|
4549 | { |
---|
4550 | reddeg = d+1; |
---|
4551 | Print(".%d",d);mflush(); |
---|
4552 | } |
---|
4553 | } |
---|
4554 | } |
---|
4555 | } |
---|
4556 | |
---|
4557 | void initBbaShift(kStrategy strat) |
---|
4558 | { |
---|
4559 | /* setting global variables ------------------- */ |
---|
4560 | strat->enterS = enterSBba; /* remains as is, we change enterT! */ |
---|
4561 | |
---|
4562 | strat->red = redFirstShift; /* no redHomog ! */ |
---|
4563 | |
---|
4564 | if (currRing->pLexOrder && strat->honey) |
---|
4565 | strat->initEcart = initEcartNormal; |
---|
4566 | else |
---|
4567 | strat->initEcart = initEcartBBA; |
---|
4568 | if (strat->honey) |
---|
4569 | strat->initEcartPair = initEcartPairMora; |
---|
4570 | else |
---|
4571 | strat->initEcartPair = initEcartPairBba; |
---|
4572 | // if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
4573 | // { |
---|
4574 | // //interred machen Aenderung |
---|
4575 | // pFDegOld=currRing->pFDeg; |
---|
4576 | // pLDegOld=pLDeg; |
---|
4577 | // //h=ggetid("ecart"); |
---|
4578 | // //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/) |
---|
4579 | // //{ |
---|
4580 | // // ecartWeights=iv2array(IDINTVEC(h)); |
---|
4581 | // //} |
---|
4582 | // //else |
---|
4583 | // { |
---|
4584 | // ecartWeights=(short *)omAlloc(((currRing->N)+1)*sizeof(short)); |
---|
4585 | // /*uses automatic computation of the ecartWeights to set them*/ |
---|
4586 | // kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights,currRing); |
---|
4587 | // } |
---|
4588 | // pRestoreDegProcs(currRing,totaldegreeWecart, maxdegreeWecart); |
---|
4589 | // if (TEST_OPT_PROT) |
---|
4590 | // { |
---|
4591 | // for(int i=1; i<=rVar(currRing); i++) |
---|
4592 | // Print(" %d",ecartWeights[i]); |
---|
4593 | // PrintLn(); |
---|
4594 | // mflush(); |
---|
4595 | // } |
---|
4596 | // } |
---|
4597 | } |
---|
4598 | #endif |
---|