1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT - Routines for Spoly creation and reductions |
---|
6 | */ |
---|
7 | |
---|
8 | // #define PDEBUG 2 |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | #include <kernel/mod2.h> |
---|
13 | #include <misc/options.h> |
---|
14 | #include <kernel/GBEngine/kutil.h> |
---|
15 | #include <coeffs/numbers.h> |
---|
16 | #include <polys/monomials/p_polys.h> |
---|
17 | #include <polys/templates/p_Procs.h> |
---|
18 | #include <polys/nc/nc.h> |
---|
19 | #ifdef KDEBUG |
---|
20 | #endif |
---|
21 | #ifdef HAVE_RINGS |
---|
22 | #include <kernel/polys.h> |
---|
23 | #endif |
---|
24 | |
---|
25 | #ifdef KDEBUG |
---|
26 | int red_count = 0; |
---|
27 | int create_count = 0; |
---|
28 | // define this if reductions are reported on TEST_OPT_DEBUG |
---|
29 | #define TEST_OPT_DEBUG_RED |
---|
30 | #endif |
---|
31 | |
---|
32 | /*************************************************************** |
---|
33 | * |
---|
34 | * Reduces PR with PW |
---|
35 | * Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR) |
---|
36 | * |
---|
37 | ***************************************************************/ |
---|
38 | int ksReducePoly(LObject* PR, |
---|
39 | TObject* PW, |
---|
40 | poly spNoether, |
---|
41 | number *coef, |
---|
42 | kStrategy strat) |
---|
43 | { |
---|
44 | #ifdef KDEBUG |
---|
45 | red_count++; |
---|
46 | #ifdef TEST_OPT_DEBUG_RED |
---|
47 | if (TEST_OPT_DEBUG) |
---|
48 | { |
---|
49 | Print("Red %d:", red_count); PR->wrp(); Print(" with:"); |
---|
50 | PW->wrp(); |
---|
51 | } |
---|
52 | #endif |
---|
53 | #endif |
---|
54 | int ret = 0; |
---|
55 | ring tailRing = PR->tailRing; |
---|
56 | kTest_L(PR); |
---|
57 | kTest_T(PW); |
---|
58 | |
---|
59 | poly p1 = PR->GetLmTailRing(); // p2 | p1 |
---|
60 | poly p2 = PW->GetLmTailRing(); // i.e. will reduce p1 with p2; lm = LT(p1) / LM(p2) |
---|
61 | poly t2 = pNext(p2), lm = p1; // t2 = p2 - LT(p2); really compute P = LC(p2)*p1 - LT(p1)/LM(p2)*p2 |
---|
62 | assume(p1 != NULL && p2 != NULL);// Attention, we have rings and there LC(p2) and LC(p1) are special |
---|
63 | p_CheckPolyRing(p1, tailRing); |
---|
64 | p_CheckPolyRing(p2, tailRing); |
---|
65 | |
---|
66 | pAssume1(p2 != NULL && p1 != NULL && |
---|
67 | p_DivisibleBy(p2, p1, tailRing)); |
---|
68 | |
---|
69 | pAssume1(p_GetComp(p1, tailRing) == p_GetComp(p2, tailRing) || |
---|
70 | (p_GetComp(p2, tailRing) == 0 && |
---|
71 | p_MaxComp(pNext(p2),tailRing) == 0)); |
---|
72 | |
---|
73 | #ifdef HAVE_PLURAL |
---|
74 | if (rIsPluralRing(currRing)) |
---|
75 | { |
---|
76 | // for the time being: we know currRing==strat->tailRing |
---|
77 | // no exp-bound checking needed |
---|
78 | // (only needed if exp-bound(tailring)<exp-b(currRing)) |
---|
79 | if (PR->bucket!=NULL) nc_kBucketPolyRed(PR->bucket, p2,coef); |
---|
80 | else |
---|
81 | { |
---|
82 | poly _p = (PR->t_p != NULL ? PR->t_p : PR->p); |
---|
83 | assume(_p != NULL); |
---|
84 | nc_PolyPolyRed(_p, p2,coef, currRing); |
---|
85 | if (PR->t_p!=NULL) PR->t_p=_p; else PR->p=_p; |
---|
86 | PR->pLength=0; // usually not used, GetpLength re-computes it if needed |
---|
87 | } |
---|
88 | return 0; |
---|
89 | } |
---|
90 | #endif |
---|
91 | |
---|
92 | if (t2==NULL) // Divisor is just one term, therefore it will |
---|
93 | { // just cancel the leading term |
---|
94 | PR->LmDeleteAndIter(); |
---|
95 | if (coef != NULL) *coef = n_Init(1, tailRing); |
---|
96 | return 0; |
---|
97 | } |
---|
98 | |
---|
99 | p_ExpVectorSub(lm, p2, tailRing); // Calculate the Monomial we must multiply to p2 |
---|
100 | |
---|
101 | if (tailRing != currRing) |
---|
102 | { |
---|
103 | // check that reduction does not violate exp bound |
---|
104 | while (PW->max != NULL && !p_LmExpVectorAddIsOk(lm, PW->max, tailRing)) |
---|
105 | { |
---|
106 | // undo changes of lm |
---|
107 | p_ExpVectorAdd(lm, p2, tailRing); |
---|
108 | if (strat == NULL) return 2; |
---|
109 | if (! kStratChangeTailRing(strat, PR, PW)) return -1; |
---|
110 | tailRing = strat->tailRing; |
---|
111 | p1 = PR->GetLmTailRing(); |
---|
112 | p2 = PW->GetLmTailRing(); |
---|
113 | t2 = pNext(p2); |
---|
114 | lm = p1; |
---|
115 | p_ExpVectorSub(lm, p2, tailRing); |
---|
116 | ret = 1; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | // take care of coef buisness |
---|
121 | if (! n_IsOne(pGetCoeff(p2), tailRing)) |
---|
122 | { |
---|
123 | number bn = pGetCoeff(lm); |
---|
124 | number an = pGetCoeff(p2); |
---|
125 | int ct = ksCheckCoeff(&an, &bn, tailRing->cf); // Calculate special LC |
---|
126 | p_SetCoeff(lm, bn, tailRing); |
---|
127 | if ((ct == 0) || (ct == 2)) |
---|
128 | PR->Tail_Mult_nn(an); |
---|
129 | if (coef != NULL) *coef = an; |
---|
130 | else n_Delete(&an, tailRing); |
---|
131 | } |
---|
132 | else |
---|
133 | { |
---|
134 | if (coef != NULL) *coef = n_Init(1, tailRing); |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | // and finally, |
---|
139 | PR->Tail_Minus_mm_Mult_qq(lm, t2, PW->GetpLength() - 1, spNoether); |
---|
140 | assume(PW->GetpLength() == pLength(PW->p != NULL ? PW->p : PW->t_p)); |
---|
141 | PR->LmDeleteAndIter(); |
---|
142 | |
---|
143 | // the following is commented out: shrinking |
---|
144 | #ifdef HAVE_SHIFTBBA_NONEXISTENT |
---|
145 | if ( (currRing->isLPring) && (!strat->homog) ) |
---|
146 | { |
---|
147 | // assume? h->p in currRing |
---|
148 | PR->GetP(); |
---|
149 | poly qq = p_Shrink(PR->p, currRing->isLPring, currRing); |
---|
150 | PR->Clear(); // does the right things |
---|
151 | PR->p = qq; |
---|
152 | PR->t_p = NULL; |
---|
153 | PR->SetShortExpVector(); |
---|
154 | } |
---|
155 | #endif |
---|
156 | |
---|
157 | #if defined(KDEBUG) && defined(TEST_OPT_DEBUG_RED) |
---|
158 | if (TEST_OPT_DEBUG) |
---|
159 | { |
---|
160 | Print(" to: "); PR->wrp(); Print("\n"); |
---|
161 | } |
---|
162 | #endif |
---|
163 | return ret; |
---|
164 | } |
---|
165 | |
---|
166 | /*************************************************************** |
---|
167 | * |
---|
168 | * Reduces PR with PW |
---|
169 | * Assumes PR != NULL, PW != NULL, Lm(PW) divides Lm(PR) |
---|
170 | * |
---|
171 | ***************************************************************/ |
---|
172 | int ksReducePolySig(LObject* PR, |
---|
173 | TObject* PW, |
---|
174 | long /*idx*/, |
---|
175 | poly spNoether, |
---|
176 | number *coef, |
---|
177 | kStrategy strat) |
---|
178 | { |
---|
179 | #ifdef KDEBUG |
---|
180 | red_count++; |
---|
181 | #ifdef TEST_OPT_DEBUG_RED |
---|
182 | if (TEST_OPT_DEBUG) |
---|
183 | { |
---|
184 | Print("Red %d:", red_count); PR->wrp(); Print(" with:"); |
---|
185 | PW->wrp(); |
---|
186 | } |
---|
187 | #endif |
---|
188 | #endif |
---|
189 | int ret = 0; |
---|
190 | ring tailRing = PR->tailRing; |
---|
191 | kTest_L(PR); |
---|
192 | kTest_T(PW); |
---|
193 | |
---|
194 | // signature-based stuff: |
---|
195 | // checking for sig-safeness first |
---|
196 | // NOTE: This has to be done in the current ring |
---|
197 | // |
---|
198 | /********************************************** |
---|
199 | * |
---|
200 | * TODO: |
---|
201 | * -------------------------------------------- |
---|
202 | * if strat->sbaOrder == 1 |
---|
203 | * Since we are subdividing lower index and |
---|
204 | * current index reductions it is enough to |
---|
205 | * look at the polynomial part of the signature |
---|
206 | * for a check. This should speed-up checking |
---|
207 | * a lot! |
---|
208 | * if !strat->sbaOrder == 0 |
---|
209 | * We are not subdividing lower and current index |
---|
210 | * due to the fact that we are using the induced |
---|
211 | * Schreyer order |
---|
212 | * |
---|
213 | * nevertheless, this different behaviour is |
---|
214 | * taken care of by is_sigsafe |
---|
215 | * => one reduction procedure can be used for |
---|
216 | * both, the incremental and the non-incremental |
---|
217 | * attempt! |
---|
218 | * -------------------------------------------- |
---|
219 | * |
---|
220 | *********************************************/ |
---|
221 | //printf("COMPARE IDX: %ld -- %ld\n",idx,strat->currIdx); |
---|
222 | if (!PW->is_sigsafe) |
---|
223 | { |
---|
224 | poly sigMult = pCopy(PW->sig); // copy signature of reducer |
---|
225 | //#if 1 |
---|
226 | #ifdef DEBUGF5 |
---|
227 | printf("IN KSREDUCEPOLYSIG: \n"); |
---|
228 | pWrite(pHead(f1)); |
---|
229 | pWrite(pHead(f2)); |
---|
230 | pWrite(sigMult); |
---|
231 | printf("--------------\n"); |
---|
232 | #endif |
---|
233 | p_ExpVectorAddSub(sigMult,PR->GetLmCurrRing(),PW->GetLmCurrRing(),currRing); |
---|
234 | //#if 1 |
---|
235 | #ifdef DEBUGF5 |
---|
236 | printf("------------------- IN KSREDUCEPOLYSIG: --------------------\n"); |
---|
237 | pWrite(pHead(f1)); |
---|
238 | pWrite(pHead(f2)); |
---|
239 | pWrite(sigMult); |
---|
240 | pWrite(PR->sig); |
---|
241 | printf("--------------\n"); |
---|
242 | #endif |
---|
243 | int sigSafe = p_LmCmp(PR->sig,sigMult,currRing); |
---|
244 | // now we can delete the copied polynomial data used for checking for |
---|
245 | // sig-safeness of the reduction step |
---|
246 | //#if 1 |
---|
247 | #ifdef DEBUGF5 |
---|
248 | printf("%d -- %d sig\n",sigSafe,PW->is_sigsafe); |
---|
249 | |
---|
250 | #endif |
---|
251 | //pDelete(&f1); |
---|
252 | pDelete(&sigMult); |
---|
253 | // go on with the computations only if the signature of p2 is greater than the |
---|
254 | // signature of fm*p1 |
---|
255 | if(sigSafe != 1) |
---|
256 | { |
---|
257 | PR->is_redundant = TRUE; |
---|
258 | return 3; |
---|
259 | } |
---|
260 | //PW->is_sigsafe = TRUE; |
---|
261 | } |
---|
262 | PR->is_redundant = FALSE; |
---|
263 | poly p1 = PR->GetLmTailRing(); // p2 | p1 |
---|
264 | poly p2 = PW->GetLmTailRing(); // i.e. will reduce p1 with p2; lm = LT(p1) / LM(p2) |
---|
265 | poly t2 = pNext(p2), lm = p1; // t2 = p2 - LT(p2); really compute P = LC(p2)*p1 - LT(p1)/LM(p2)*p2 |
---|
266 | assume(p1 != NULL && p2 != NULL);// Attention, we have rings and there LC(p2) and LC(p1) are special |
---|
267 | p_CheckPolyRing(p1, tailRing); |
---|
268 | p_CheckPolyRing(p2, tailRing); |
---|
269 | |
---|
270 | pAssume1(p2 != NULL && p1 != NULL && |
---|
271 | p_DivisibleBy(p2, p1, tailRing)); |
---|
272 | |
---|
273 | pAssume1(p_GetComp(p1, tailRing) == p_GetComp(p2, tailRing) || |
---|
274 | (p_GetComp(p2, tailRing) == 0 && |
---|
275 | p_MaxComp(pNext(p2),tailRing) == 0)); |
---|
276 | |
---|
277 | #ifdef HAVE_PLURAL |
---|
278 | if (rIsPluralRing(currRing)) |
---|
279 | { |
---|
280 | // for the time being: we know currRing==strat->tailRing |
---|
281 | // no exp-bound checking needed |
---|
282 | // (only needed if exp-bound(tailring)<exp-b(currRing)) |
---|
283 | if (PR->bucket!=NULL) nc_kBucketPolyRed(PR->bucket, p2,coef); |
---|
284 | else |
---|
285 | { |
---|
286 | poly _p = (PR->t_p != NULL ? PR->t_p : PR->p); |
---|
287 | assume(_p != NULL); |
---|
288 | nc_PolyPolyRed(_p, p2, coef, currRing); |
---|
289 | if (PR->t_p!=NULL) PR->t_p=_p; else PR->p=_p; |
---|
290 | PR->pLength=0; // usaully not used, GetpLength re-comoutes it if needed |
---|
291 | } |
---|
292 | return 0; |
---|
293 | } |
---|
294 | #endif |
---|
295 | |
---|
296 | if (t2==NULL) // Divisor is just one term, therefore it will |
---|
297 | { // just cancel the leading term |
---|
298 | PR->LmDeleteAndIter(); |
---|
299 | if (coef != NULL) *coef = n_Init(1, tailRing); |
---|
300 | return 0; |
---|
301 | } |
---|
302 | |
---|
303 | p_ExpVectorSub(lm, p2, tailRing); // Calculate the Monomial we must multiply to p2 |
---|
304 | |
---|
305 | if (tailRing != currRing) |
---|
306 | { |
---|
307 | // check that reduction does not violate exp bound |
---|
308 | while (PW->max != NULL && !p_LmExpVectorAddIsOk(lm, PW->max, tailRing)) |
---|
309 | { |
---|
310 | // undo changes of lm |
---|
311 | p_ExpVectorAdd(lm, p2, tailRing); |
---|
312 | if (strat == NULL) return 2; |
---|
313 | if (! kStratChangeTailRing(strat, PR, PW)) return -1; |
---|
314 | tailRing = strat->tailRing; |
---|
315 | p1 = PR->GetLmTailRing(); |
---|
316 | p2 = PW->GetLmTailRing(); |
---|
317 | t2 = pNext(p2); |
---|
318 | lm = p1; |
---|
319 | p_ExpVectorSub(lm, p2, tailRing); |
---|
320 | ret = 1; |
---|
321 | } |
---|
322 | } |
---|
323 | |
---|
324 | // take care of coef buisness |
---|
325 | if (! n_IsOne(pGetCoeff(p2), tailRing)) |
---|
326 | { |
---|
327 | number bn = pGetCoeff(lm); |
---|
328 | number an = pGetCoeff(p2); |
---|
329 | int ct = ksCheckCoeff(&an, &bn, tailRing->cf); // Calculate special LC |
---|
330 | p_SetCoeff(lm, bn, tailRing); |
---|
331 | if ((ct == 0) || (ct == 2)) |
---|
332 | PR->Tail_Mult_nn(an); |
---|
333 | if (coef != NULL) *coef = an; |
---|
334 | else n_Delete(&an, tailRing); |
---|
335 | } |
---|
336 | else |
---|
337 | { |
---|
338 | if (coef != NULL) *coef = n_Init(1, tailRing); |
---|
339 | } |
---|
340 | |
---|
341 | |
---|
342 | // and finally, |
---|
343 | PR->Tail_Minus_mm_Mult_qq(lm, t2, PW->GetpLength() - 1, spNoether); |
---|
344 | assume(PW->GetpLength() == pLength(PW->p != NULL ? PW->p : PW->t_p)); |
---|
345 | PR->LmDeleteAndIter(); |
---|
346 | |
---|
347 | // the following is commented out: shrinking |
---|
348 | #ifdef HAVE_SHIFTBBA_NONEXISTENT |
---|
349 | if ( (currRing->isLPring) && (!strat->homog) ) |
---|
350 | { |
---|
351 | // assume? h->p in currRing |
---|
352 | PR->GetP(); |
---|
353 | poly qq = p_Shrink(PR->p, currRing->isLPring, currRing); |
---|
354 | PR->Clear(); // does the right things |
---|
355 | PR->p = qq; |
---|
356 | PR->t_p = NULL; |
---|
357 | PR->SetShortExpVector(); |
---|
358 | } |
---|
359 | #endif |
---|
360 | |
---|
361 | #if defined(KDEBUG) && defined(TEST_OPT_DEBUG_RED) |
---|
362 | if (TEST_OPT_DEBUG) |
---|
363 | { |
---|
364 | Print(" to: "); PR->wrp(); Print("\n"); |
---|
365 | } |
---|
366 | #endif |
---|
367 | return ret; |
---|
368 | } |
---|
369 | |
---|
370 | /*************************************************************** |
---|
371 | * |
---|
372 | * Creates S-Poly of p1 and p2 |
---|
373 | * |
---|
374 | * |
---|
375 | ***************************************************************/ |
---|
376 | void ksCreateSpoly(LObject* Pair, poly spNoether, |
---|
377 | int use_buckets, ring tailRing, |
---|
378 | poly m1, poly m2, TObject** R) |
---|
379 | { |
---|
380 | #ifdef KDEBUG |
---|
381 | create_count++; |
---|
382 | #endif |
---|
383 | kTest_L(Pair); |
---|
384 | poly p1 = Pair->p1; |
---|
385 | poly p2 = Pair->p2; |
---|
386 | Pair->tailRing = tailRing; |
---|
387 | |
---|
388 | assume(p1 != NULL); |
---|
389 | assume(p2 != NULL); |
---|
390 | assume(tailRing != NULL); |
---|
391 | |
---|
392 | poly a1 = pNext(p1), a2 = pNext(p2); |
---|
393 | number lc1 = pGetCoeff(p1), lc2 = pGetCoeff(p2); |
---|
394 | int co=0/*, ct = ksCheckCoeff(&lc1, &lc2, currRing->cf)*/; // gcd and zero divisors |
---|
395 | (void) ksCheckCoeff(&lc1, &lc2, currRing->cf); |
---|
396 | |
---|
397 | int l1=0, l2=0; |
---|
398 | |
---|
399 | if (p_GetComp(p1, currRing)!=p_GetComp(p2, currRing)) |
---|
400 | { |
---|
401 | if (p_GetComp(p1, currRing)==0) |
---|
402 | { |
---|
403 | co=1; |
---|
404 | p_SetCompP(p1,p_GetComp(p2, currRing), currRing, tailRing); |
---|
405 | } |
---|
406 | else |
---|
407 | { |
---|
408 | co=2; |
---|
409 | p_SetCompP(p2, p_GetComp(p1, currRing), currRing, tailRing); |
---|
410 | } |
---|
411 | } |
---|
412 | |
---|
413 | // get m1 = LCM(LM(p1), LM(p2))/LM(p1) |
---|
414 | // m2 = LCM(LM(p1), LM(p2))/LM(p2) |
---|
415 | if (m1 == NULL) |
---|
416 | k_GetLeadTerms(p1, p2, currRing, m1, m2, tailRing); |
---|
417 | |
---|
418 | pSetCoeff0(m1, lc2); |
---|
419 | pSetCoeff0(m2, lc1); // and now, m1 * LT(p1) == m2 * LT(p2) |
---|
420 | |
---|
421 | if (R != NULL) |
---|
422 | { |
---|
423 | if (Pair->i_r1 == -1) |
---|
424 | { |
---|
425 | l1 = pLength(p1) - 1; |
---|
426 | } |
---|
427 | else |
---|
428 | { |
---|
429 | l1 = (R[Pair->i_r1])->GetpLength() - 1; |
---|
430 | } |
---|
431 | if ((Pair->i_r2 == -1)||(R[Pair->i_r2]==NULL)) |
---|
432 | { |
---|
433 | l2 = pLength(p2) - 1; |
---|
434 | } |
---|
435 | else |
---|
436 | { |
---|
437 | l2 = (R[Pair->i_r2])->GetpLength() - 1; |
---|
438 | } |
---|
439 | } |
---|
440 | |
---|
441 | // get m2 * a2 |
---|
442 | if (spNoether != NULL) |
---|
443 | { |
---|
444 | l2 = -1; |
---|
445 | a2 = tailRing->p_Procs->pp_Mult_mm_Noether(a2, m2, spNoether, l2, tailRing); |
---|
446 | assume(l2 == pLength(a2)); |
---|
447 | } |
---|
448 | else |
---|
449 | a2 = tailRing->p_Procs->pp_Mult_mm(a2, m2, tailRing); |
---|
450 | #ifdef HAVE_RINGS |
---|
451 | if (!(rField_is_Domain(currRing))) l2 = pLength(a2); |
---|
452 | #endif |
---|
453 | |
---|
454 | Pair->SetLmTail(m2, a2, l2, use_buckets, tailRing); |
---|
455 | |
---|
456 | // get m2*a2 - m1*a1 |
---|
457 | Pair->Tail_Minus_mm_Mult_qq(m1, a1, l1, spNoether); |
---|
458 | |
---|
459 | // Clean-up time |
---|
460 | Pair->LmDeleteAndIter(); |
---|
461 | p_LmDelete(m1, tailRing); |
---|
462 | |
---|
463 | if (co != 0) |
---|
464 | { |
---|
465 | if (co==1) |
---|
466 | { |
---|
467 | p_SetCompP(p1,0, currRing, tailRing); |
---|
468 | } |
---|
469 | else |
---|
470 | { |
---|
471 | p_SetCompP(p2,0, currRing, tailRing); |
---|
472 | } |
---|
473 | } |
---|
474 | |
---|
475 | // the following is commented out: shrinking |
---|
476 | #ifdef HAVE_SHIFTBBA_NONEXISTENT |
---|
477 | if (currRing->isLPring) |
---|
478 | { |
---|
479 | // assume? h->p in currRing |
---|
480 | Pair->GetP(); |
---|
481 | poly qq = p_Shrink(Pair->p, currRing->isLPring, currRing); |
---|
482 | Pair->Clear(); // does the right things |
---|
483 | Pair->p = qq; |
---|
484 | Pair->t_p = NULL; |
---|
485 | Pair->SetShortExpVector(); |
---|
486 | } |
---|
487 | #endif |
---|
488 | |
---|
489 | } |
---|
490 | |
---|
491 | int ksReducePolyTail(LObject* PR, TObject* PW, poly Current, poly spNoether) |
---|
492 | { |
---|
493 | BOOLEAN ret; |
---|
494 | number coef; |
---|
495 | poly Lp = PR->GetLmCurrRing(); |
---|
496 | poly Save = PW->GetLmCurrRing(); |
---|
497 | |
---|
498 | kTest_L(PR); |
---|
499 | kTest_T(PW); |
---|
500 | pAssume(pIsMonomOf(Lp, Current)); |
---|
501 | |
---|
502 | assume(Lp != NULL && Current != NULL && pNext(Current) != NULL); |
---|
503 | assume(PR->bucket == NULL); |
---|
504 | |
---|
505 | LObject Red(pNext(Current), PR->tailRing); |
---|
506 | TObject With(PW, Lp == Save); |
---|
507 | |
---|
508 | pAssume(!pHaveCommonMonoms(Red.p, With.p)); |
---|
509 | ret = ksReducePoly(&Red, &With, spNoether, &coef); |
---|
510 | |
---|
511 | if (!ret) |
---|
512 | { |
---|
513 | if (! n_IsOne(coef, currRing)) |
---|
514 | { |
---|
515 | pNext(Current) = NULL; |
---|
516 | if (Current == PR->p && PR->t_p != NULL) |
---|
517 | pNext(PR->t_p) = NULL; |
---|
518 | PR->Mult_nn(coef); |
---|
519 | } |
---|
520 | |
---|
521 | n_Delete(&coef, currRing); |
---|
522 | pNext(Current) = Red.GetLmTailRing(); |
---|
523 | if (Current == PR->p && PR->t_p != NULL) |
---|
524 | pNext(PR->t_p) = pNext(Current); |
---|
525 | } |
---|
526 | |
---|
527 | if (Lp == Save) |
---|
528 | With.Delete(); |
---|
529 | |
---|
530 | // the following is commented out: shrinking |
---|
531 | #ifdef HAVE_SHIFTBBA_NONEXISTENT |
---|
532 | if (currRing->isLPring) |
---|
533 | { |
---|
534 | // assume? h->p in currRing |
---|
535 | PR->GetP(); |
---|
536 | poly qq = p_Shrink(PR->p, currRing->isLPring, currRing); |
---|
537 | PR->Clear(); // does the right things |
---|
538 | PR->p = qq; |
---|
539 | PR->t_p = NULL; |
---|
540 | PR->SetShortExpVector(); |
---|
541 | } |
---|
542 | #endif |
---|
543 | |
---|
544 | return ret; |
---|
545 | } |
---|
546 | |
---|
547 | /*************************************************************** |
---|
548 | * |
---|
549 | * Auxillary Routines |
---|
550 | * |
---|
551 | * |
---|
552 | ***************************************************************/ |
---|
553 | |
---|
554 | /*2 |
---|
555 | * creates the leading term of the S-polynomial of p1 and p2 |
---|
556 | * do not destroy p1 and p2 |
---|
557 | * remarks: |
---|
558 | * 1. the coefficient is 0 (nNew) |
---|
559 | * 1. a) in the case of coefficient ring, the coefficient is calculated |
---|
560 | * 2. pNext is undefined |
---|
561 | */ |
---|
562 | //static void bbb() { int i=0; } |
---|
563 | poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing) |
---|
564 | { |
---|
565 | poly a1 = pNext(p1), a2 = pNext(p2); |
---|
566 | long c1=p_GetComp(p1, currRing),c2=p_GetComp(p2, currRing); |
---|
567 | long c; |
---|
568 | poly m1,m2; |
---|
569 | number t1 = NULL,t2 = NULL; |
---|
570 | int cm,i; |
---|
571 | BOOLEAN equal; |
---|
572 | |
---|
573 | #ifdef HAVE_RINGS |
---|
574 | BOOLEAN is_Ring=rField_is_Ring(currRing); |
---|
575 | number lc1 = pGetCoeff(p1), lc2 = pGetCoeff(p2); |
---|
576 | if (is_Ring) |
---|
577 | { |
---|
578 | ksCheckCoeff(&lc1, &lc2, currRing->cf); // gcd and zero divisors |
---|
579 | if (a1 != NULL) t2 = nMult(pGetCoeff(a1),lc2); |
---|
580 | if (a2 != NULL) t1 = nMult(pGetCoeff(a2),lc1); |
---|
581 | while (a1 != NULL && nIsZero(t2)) |
---|
582 | { |
---|
583 | pIter(a1); |
---|
584 | nDelete(&t2); |
---|
585 | if (a1 != NULL) t2 = nMult(pGetCoeff(a1),lc2); |
---|
586 | } |
---|
587 | while (a2 != NULL && nIsZero(t1)) |
---|
588 | { |
---|
589 | pIter(a2); |
---|
590 | nDelete(&t1); |
---|
591 | if (a2 != NULL) t1 = nMult(pGetCoeff(a2),lc1); |
---|
592 | } |
---|
593 | } |
---|
594 | #endif |
---|
595 | |
---|
596 | if (a1==NULL) |
---|
597 | { |
---|
598 | if(a2!=NULL) |
---|
599 | { |
---|
600 | m2=p_Init(currRing); |
---|
601 | x2: |
---|
602 | for (i = (currRing->N); i; i--) |
---|
603 | { |
---|
604 | c = p_GetExpDiff(p1, p2,i, currRing); |
---|
605 | if (c>0) |
---|
606 | { |
---|
607 | p_SetExp(m2,i,(c+p_GetExp(a2,i,tailRing)),currRing); |
---|
608 | } |
---|
609 | else |
---|
610 | { |
---|
611 | p_SetExp(m2,i,p_GetExp(a2,i,tailRing),currRing); |
---|
612 | } |
---|
613 | } |
---|
614 | if ((c1==c2)||(c2!=0)) |
---|
615 | { |
---|
616 | p_SetComp(m2,p_GetComp(a2,tailRing), currRing); |
---|
617 | } |
---|
618 | else |
---|
619 | { |
---|
620 | p_SetComp(m2,c1,currRing); |
---|
621 | } |
---|
622 | p_Setm(m2, currRing); |
---|
623 | #ifdef HAVE_RINGS |
---|
624 | if (is_Ring) |
---|
625 | { |
---|
626 | nDelete(&lc1); |
---|
627 | nDelete(&lc2); |
---|
628 | nDelete(&t2); |
---|
629 | pSetCoeff0(m2, t1); |
---|
630 | } |
---|
631 | else |
---|
632 | #endif |
---|
633 | nNew(&(pGetCoeff(m2))); |
---|
634 | return m2; |
---|
635 | } |
---|
636 | else |
---|
637 | { |
---|
638 | #ifdef HAVE_RINGS |
---|
639 | if (is_Ring) |
---|
640 | { |
---|
641 | nDelete(&lc1); |
---|
642 | nDelete(&lc2); |
---|
643 | nDelete(&t1); |
---|
644 | nDelete(&t2); |
---|
645 | } |
---|
646 | #endif |
---|
647 | return NULL; |
---|
648 | } |
---|
649 | } |
---|
650 | if (a2==NULL) |
---|
651 | { |
---|
652 | m1=p_Init(currRing); |
---|
653 | x1: |
---|
654 | for (i = (currRing->N); i; i--) |
---|
655 | { |
---|
656 | c = p_GetExpDiff(p2, p1,i,currRing); |
---|
657 | if (c>0) |
---|
658 | { |
---|
659 | p_SetExp(m1,i,(c+p_GetExp(a1,i, tailRing)),currRing); |
---|
660 | } |
---|
661 | else |
---|
662 | { |
---|
663 | p_SetExp(m1,i,p_GetExp(a1,i, tailRing), currRing); |
---|
664 | } |
---|
665 | } |
---|
666 | if ((c1==c2)||(c1!=0)) |
---|
667 | { |
---|
668 | p_SetComp(m1,p_GetComp(a1,tailRing),currRing); |
---|
669 | } |
---|
670 | else |
---|
671 | { |
---|
672 | p_SetComp(m1,c2,currRing); |
---|
673 | } |
---|
674 | p_Setm(m1, currRing); |
---|
675 | #ifdef HAVE_RINGS |
---|
676 | if (is_Ring) |
---|
677 | { |
---|
678 | pSetCoeff0(m1, t2); |
---|
679 | nDelete(&lc1); |
---|
680 | nDelete(&lc2); |
---|
681 | nDelete(&t1); |
---|
682 | } |
---|
683 | else |
---|
684 | #endif |
---|
685 | nNew(&(pGetCoeff(m1))); |
---|
686 | return m1; |
---|
687 | } |
---|
688 | m1 = p_Init(currRing); |
---|
689 | m2 = p_Init(currRing); |
---|
690 | loop |
---|
691 | { |
---|
692 | for (i = (currRing->N); i; i--) |
---|
693 | { |
---|
694 | c = p_GetExpDiff(p1, p2,i,currRing); |
---|
695 | if (c > 0) |
---|
696 | { |
---|
697 | p_SetExp(m2,i,(c+p_GetExp(a2,i,tailRing)), currRing); |
---|
698 | p_SetExp(m1,i,p_GetExp(a1,i, tailRing), currRing); |
---|
699 | } |
---|
700 | else |
---|
701 | { |
---|
702 | p_SetExp(m1,i,(p_GetExp(a1,i,tailRing)-c), currRing); |
---|
703 | p_SetExp(m2,i,p_GetExp(a2,i, tailRing), currRing); |
---|
704 | } |
---|
705 | } |
---|
706 | if(c1==c2) |
---|
707 | { |
---|
708 | p_SetComp(m1,p_GetComp(a1, tailRing), currRing); |
---|
709 | p_SetComp(m2,p_GetComp(a2, tailRing), currRing); |
---|
710 | } |
---|
711 | else |
---|
712 | { |
---|
713 | if(c1!=0) |
---|
714 | { |
---|
715 | p_SetComp(m1,p_GetComp(a1, tailRing), currRing); |
---|
716 | p_SetComp(m2,c1, currRing); |
---|
717 | } |
---|
718 | else |
---|
719 | { |
---|
720 | p_SetComp(m2,p_GetComp(a2, tailRing), currRing); |
---|
721 | p_SetComp(m1,c2, currRing); |
---|
722 | } |
---|
723 | } |
---|
724 | p_Setm(m1,currRing); |
---|
725 | p_Setm(m2,currRing); |
---|
726 | cm = p_LmCmp(m1, m2,currRing); |
---|
727 | if (cm!=0) |
---|
728 | { |
---|
729 | if(cm==1) |
---|
730 | { |
---|
731 | p_LmFree(m2,currRing); |
---|
732 | #ifdef HAVE_RINGS |
---|
733 | if (is_Ring) |
---|
734 | { |
---|
735 | pSetCoeff0(m1, t2); |
---|
736 | nDelete(&lc1); |
---|
737 | nDelete(&lc2); |
---|
738 | nDelete(&t1); |
---|
739 | } |
---|
740 | else |
---|
741 | #endif |
---|
742 | nNew(&(pGetCoeff(m1))); |
---|
743 | return m1; |
---|
744 | } |
---|
745 | else |
---|
746 | { |
---|
747 | p_LmFree(m1,currRing); |
---|
748 | #ifdef HAVE_RINGS |
---|
749 | if (is_Ring) |
---|
750 | { |
---|
751 | pSetCoeff0(m2, t1); |
---|
752 | nDelete(&lc1); |
---|
753 | nDelete(&lc2); |
---|
754 | nDelete(&t2); |
---|
755 | } |
---|
756 | else |
---|
757 | #endif |
---|
758 | nNew(&(pGetCoeff(m2))); |
---|
759 | return m2; |
---|
760 | } |
---|
761 | } |
---|
762 | #ifdef HAVE_RINGS |
---|
763 | if (is_Ring) |
---|
764 | { |
---|
765 | equal = nEqual(t1,t2); |
---|
766 | } |
---|
767 | else |
---|
768 | #endif |
---|
769 | { |
---|
770 | t1 = nMult(pGetCoeff(a2),pGetCoeff(p1)); |
---|
771 | t2 = nMult(pGetCoeff(a1),pGetCoeff(p2)); |
---|
772 | equal = nEqual(t1,t2); |
---|
773 | nDelete(&t2); |
---|
774 | nDelete(&t1); |
---|
775 | } |
---|
776 | if (!equal) |
---|
777 | { |
---|
778 | p_LmFree(m2,currRing); |
---|
779 | #ifdef HAVE_RINGS |
---|
780 | if (is_Ring) |
---|
781 | { |
---|
782 | pSetCoeff0(m1, nSub(t1, t2)); |
---|
783 | nDelete(&lc1); |
---|
784 | nDelete(&lc2); |
---|
785 | nDelete(&t1); |
---|
786 | nDelete(&t2); |
---|
787 | } |
---|
788 | else |
---|
789 | #endif |
---|
790 | nNew(&(pGetCoeff(m1))); |
---|
791 | return m1; |
---|
792 | } |
---|
793 | pIter(a1); |
---|
794 | pIter(a2); |
---|
795 | #ifdef HAVE_RINGS |
---|
796 | if (is_Ring) |
---|
797 | { |
---|
798 | if (a2 != NULL) |
---|
799 | { |
---|
800 | nDelete(&t1); |
---|
801 | t1 = nMult(pGetCoeff(a2),lc1); |
---|
802 | } |
---|
803 | if (a1 != NULL) |
---|
804 | { |
---|
805 | nDelete(&t2); |
---|
806 | t2 = nMult(pGetCoeff(a1),lc2); |
---|
807 | } |
---|
808 | while ((a1 != NULL) && nIsZero(t2)) |
---|
809 | { |
---|
810 | pIter(a1); |
---|
811 | if (a1 != NULL) |
---|
812 | { |
---|
813 | nDelete(&t2); |
---|
814 | t2 = nMult(pGetCoeff(a1),lc2); |
---|
815 | } |
---|
816 | } |
---|
817 | while ((a2 != NULL) && nIsZero(t1)) |
---|
818 | { |
---|
819 | pIter(a2); |
---|
820 | if (a2 != NULL) |
---|
821 | { |
---|
822 | nDelete(&t1); |
---|
823 | t1 = nMult(pGetCoeff(a2),lc1); |
---|
824 | } |
---|
825 | } |
---|
826 | } |
---|
827 | #endif |
---|
828 | if (a2==NULL) |
---|
829 | { |
---|
830 | p_LmFree(m2,currRing); |
---|
831 | if (a1==NULL) |
---|
832 | { |
---|
833 | #ifdef HAVE_RINGS |
---|
834 | if (is_Ring) |
---|
835 | { |
---|
836 | nDelete(&lc1); |
---|
837 | nDelete(&lc2); |
---|
838 | nDelete(&t1); |
---|
839 | nDelete(&t2); |
---|
840 | } |
---|
841 | #endif |
---|
842 | p_LmFree(m1,currRing); |
---|
843 | return NULL; |
---|
844 | } |
---|
845 | goto x1; |
---|
846 | } |
---|
847 | if (a1==NULL) |
---|
848 | { |
---|
849 | p_LmFree(m1,currRing); |
---|
850 | goto x2; |
---|
851 | } |
---|
852 | } |
---|
853 | } |
---|