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