[0e1846] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[0ae5116] | 4 | /* $Id: spolys.cc,v 1.20 1999-05-10 15:10:56 Singular Exp $ */ |
---|
[32df82] | 5 | |
---|
[0e1846] | 6 | /* |
---|
| 7 | * ABSTRACT - s-polynomials and reduction for char p |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include <string.h> |
---|
| 11 | #include "mod2.h" |
---|
| 12 | #include "tok.h" |
---|
| 13 | #include "mmemory.h" |
---|
| 14 | #include "kstd1.h" |
---|
| 15 | #include "numbers.h" |
---|
| 16 | #include "modulop.h" |
---|
| 17 | #include "polys.h" |
---|
| 18 | #include "ipid.h" |
---|
| 19 | #include "febase.h" |
---|
| 20 | #include "spolys0.h" |
---|
| 21 | #include "spolys.h" |
---|
[51c163] | 22 | #include "spSpolyLoop.h" |
---|
| 23 | |
---|
[f92fa13] | 24 | |
---|
[0e1846] | 25 | /*0 implementation*/ |
---|
| 26 | |
---|
| 27 | #ifdef SDRING |
---|
[311499] | 28 | poly spDSpolyRed(poly p1,poly p2,poly spNoether, spSpolyLoopProc dummy); |
---|
| 29 | poly spDSpolyCreate(poly p1,poly p2,poly spNoether, spSpolyLoopProc dummy); |
---|
[0e1846] | 30 | #endif |
---|
| 31 | |
---|
[51c163] | 32 | poly (*spSpolyRed)(poly p1, poly p2,poly spNoether, |
---|
| 33 | spSpolyLoopProc spSpolyLoop); |
---|
| 34 | void (*spSpolyTail)(poly p1, poly q, poly q2, poly spNoether, |
---|
| 35 | spSpolyLoopProc spSpolyLoop); |
---|
| 36 | poly (*spSpolyRedNew)(poly p1, poly p2,poly spNoether, |
---|
| 37 | spSpolyLoopProc spSpolyLoop); |
---|
[7a5e7c] | 38 | poly (*spSpolyCreate)(poly p1, poly p2,poly spNoether, |
---|
| 39 | spSpolyLoopProc SpolyLoop); |
---|
[0e1846] | 40 | poly (*spSpolyShortBba)(poly p1, poly p2); |
---|
| 41 | |
---|
| 42 | /*2 |
---|
| 43 | * assume m = L(m) and Lc(m) = 1 |
---|
| 44 | * pNext(m) = result = p*m |
---|
| 45 | * do not destroy p |
---|
| 46 | */ |
---|
| 47 | static void spMultCopy0(poly p, poly m, poly spNoether) |
---|
| 48 | { |
---|
| 49 | poly a, b; |
---|
| 50 | |
---|
| 51 | a = m; |
---|
| 52 | if (spNoether==NULL) |
---|
| 53 | { |
---|
| 54 | do |
---|
| 55 | { |
---|
| 56 | a = pNext(a) = pNew(); |
---|
[f92fa13] | 57 | pCopyAddFast(a,p,m); |
---|
[0e1846] | 58 | pIter(p); |
---|
| 59 | } |
---|
| 60 | while (p!=NULL); |
---|
| 61 | pNext(a) = NULL; |
---|
| 62 | return; |
---|
| 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
| 66 | do |
---|
| 67 | { |
---|
| 68 | b = pNext(a) = pNew(); |
---|
[f92fa13] | 69 | pCopyAddFast(b,p,m); |
---|
[0e1846] | 70 | if (pComp0(b, spNoether) == -1) |
---|
| 71 | { |
---|
| 72 | pFree1(b); |
---|
| 73 | pNext(a) = NULL; |
---|
| 74 | return; |
---|
| 75 | } |
---|
| 76 | a = b; |
---|
| 77 | pIter(p); |
---|
| 78 | } |
---|
| 79 | while (p!=NULL); |
---|
| 80 | pNext(a) = NULL; |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | /*2 |
---|
| 85 | * assume m = L(m) and Lc(m) = -1 |
---|
| 86 | * pNext(n) = result = p*m |
---|
| 87 | * do not destroy p |
---|
| 88 | */ |
---|
| 89 | static void spMultCopy1(poly p, poly m, poly n, poly spNoether) |
---|
| 90 | { |
---|
| 91 | poly a, b; |
---|
| 92 | |
---|
| 93 | a = n; |
---|
| 94 | if (spNoether==NULL) |
---|
| 95 | { |
---|
| 96 | do |
---|
| 97 | { |
---|
| 98 | a = pNext(a) = pNew(); |
---|
[f92fa13] | 99 | pCopyAddFast(a,p,m); |
---|
[0e1846] | 100 | pSetCoeff0(a,npNegM(pGetCoeff(a))); |
---|
| 101 | pIter(p); |
---|
| 102 | } |
---|
| 103 | while (p!=NULL); |
---|
| 104 | pNext(a) = NULL; |
---|
| 105 | return; |
---|
| 106 | } |
---|
| 107 | else |
---|
| 108 | { |
---|
| 109 | do |
---|
| 110 | { |
---|
| 111 | b = pNext(a) = pNew(); |
---|
[f92fa13] | 112 | pCopyAddFast(b,p,m); |
---|
[0e1846] | 113 | spMemcpy(b,p); |
---|
| 114 | spMonAdd(b,m); |
---|
| 115 | if (pComp0(b, spNoether) == -1) |
---|
| 116 | { |
---|
| 117 | pFree1(b); |
---|
| 118 | pNext(a) = NULL; |
---|
| 119 | return; |
---|
| 120 | } |
---|
| 121 | a = b; |
---|
| 122 | pSetCoeff0(a,npNegM(pGetCoeff(a))); |
---|
| 123 | pIter(p); |
---|
| 124 | } |
---|
| 125 | while (p!=NULL); |
---|
| 126 | pNext(a) = NULL; |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /*2 |
---|
| 131 | * assume m = L(m) and Lc(m) = 1 |
---|
| 132 | * pNext(m) = result = a2-a1*m |
---|
| 133 | * do not destroy a1, but a2 |
---|
| 134 | */ |
---|
| 135 | static void spSpolyLoop1(poly a1, poly a2, poly m, poly spNoether) |
---|
| 136 | { |
---|
| 137 | poly a, b, s; |
---|
| 138 | int c; |
---|
| 139 | |
---|
| 140 | if (a2==NULL) |
---|
| 141 | { |
---|
| 142 | spMultCopy1(a1, m, m, spNoether); |
---|
| 143 | return; |
---|
| 144 | } |
---|
| 145 | a = m; |
---|
| 146 | b = pNew(); |
---|
[f92fa13] | 147 | pCopyAddFast(b,a1,m); |
---|
[0e1846] | 148 | loop |
---|
| 149 | { |
---|
| 150 | c = pComp0(b, a2); |
---|
| 151 | if (c == 1) |
---|
| 152 | { |
---|
| 153 | pSetCoeff0(b,npNegM(pGetCoeff(b))); |
---|
| 154 | a = pNext(a) = b; |
---|
| 155 | pIter(a1); |
---|
| 156 | if (a1!=NULL) |
---|
| 157 | { |
---|
| 158 | b = pNew(); |
---|
[f92fa13] | 159 | pCopyAddFast(b,a1,m); |
---|
[0e1846] | 160 | } |
---|
| 161 | else |
---|
| 162 | { |
---|
| 163 | pNext(a) = a2; |
---|
| 164 | return; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | else if (c == -1) |
---|
| 168 | { |
---|
| 169 | a = pNext(a) = a2; |
---|
| 170 | pIter(a2); |
---|
| 171 | if (a2==NULL) |
---|
| 172 | { |
---|
| 173 | pFree1(b); |
---|
| 174 | spMultCopy1(a1, m, a,spNoether); |
---|
| 175 | return; |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | else |
---|
| 179 | { |
---|
| 180 | if (!npEqualM(pGetCoeff(a2),pGetCoeff(a1))) |
---|
| 181 | { |
---|
| 182 | pSetCoeff0(a2,npSubM(pGetCoeff(a2),pGetCoeff(a1))); |
---|
| 183 | a = pNext(a) = a2; |
---|
| 184 | pIter(a2); |
---|
| 185 | } |
---|
| 186 | else |
---|
| 187 | { |
---|
| 188 | s = a2; |
---|
| 189 | pIter(a2); |
---|
| 190 | pFree1(s); |
---|
| 191 | } |
---|
| 192 | pIter(a1); |
---|
| 193 | if (a1==NULL) |
---|
| 194 | { |
---|
| 195 | pFree1(b); |
---|
| 196 | pNext(a) = a2; |
---|
| 197 | return; |
---|
| 198 | } |
---|
| 199 | if (a2==NULL) |
---|
| 200 | { |
---|
| 201 | pFree1(b); |
---|
| 202 | spMultCopy1(a1, m, a,spNoether); |
---|
| 203 | return; |
---|
| 204 | } |
---|
| 205 | spMemcpy(b,a1); |
---|
| 206 | spMonAdd(b,m); |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | /*2 |
---|
| 212 | * assume m = L(m) and Lc(m) = exp |
---|
| 213 | * pNext(n) = result = p*m |
---|
| 214 | * do not destroy p |
---|
| 215 | */ |
---|
[51c163] | 216 | void spMultCopyX(poly p, poly m, poly n, number exp, poly spNoether) |
---|
[0e1846] | 217 | { |
---|
| 218 | poly a, b; |
---|
| 219 | |
---|
| 220 | a = n; |
---|
| 221 | if (spNoether==NULL) |
---|
| 222 | { |
---|
| 223 | do |
---|
| 224 | { |
---|
| 225 | a = pNext(a) = pNew(); |
---|
[f92fa13] | 226 | pCopyAddFast(a,p,m); |
---|
[0e1846] | 227 | pSetCoeff0(a,npMultM(pGetCoeff(p),exp)); |
---|
| 228 | pIter(p); |
---|
| 229 | } |
---|
| 230 | while (p!=NULL); |
---|
| 231 | pNext(a) = NULL; |
---|
| 232 | return; |
---|
| 233 | } |
---|
| 234 | else |
---|
| 235 | { |
---|
| 236 | do |
---|
| 237 | { |
---|
| 238 | b = pNext(a) = pNew(); |
---|
[f92fa13] | 239 | pCopyAddFast(b,p,m); |
---|
[0e1846] | 240 | if (pComp0(b, spNoether) == -1) |
---|
| 241 | { |
---|
| 242 | pFree1(b); |
---|
| 243 | pNext(a) = NULL; |
---|
| 244 | return; |
---|
| 245 | } |
---|
| 246 | a = b; |
---|
| 247 | pSetCoeff0(a,npMultM(pGetCoeff(p),exp)); |
---|
| 248 | pIter(p); |
---|
| 249 | } |
---|
| 250 | while (p!=NULL); |
---|
| 251 | pNext(a) = NULL; |
---|
| 252 | } |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | /*2 |
---|
| 256 | * reduction of p2 with p1 |
---|
| 257 | * do not destroy p1, but p2 |
---|
| 258 | */ |
---|
[7a5e7c] | 259 | static poly spPSpolyRed(poly p1, poly p2,poly spNoether, |
---|
| 260 | spSpolyLoopProc SpolyLoop) |
---|
[0e1846] | 261 | { |
---|
| 262 | poly a1 = pNext(p1), a2 = pNext(p2); |
---|
| 263 | if(a1==NULL) |
---|
| 264 | { |
---|
| 265 | pFree1(p2); |
---|
| 266 | return a2; |
---|
| 267 | } |
---|
| 268 | BOOLEAN reset_vec=FALSE; |
---|
| 269 | if (pGetComp(p1) != pGetComp(p2)) |
---|
| 270 | { |
---|
| 271 | pSetCompP(a1,pGetComp(p2)); |
---|
| 272 | reset_vec=TRUE; |
---|
| 273 | } |
---|
| 274 | spMonSub(p2,p1); |
---|
[3d3ba58] | 275 | if (1!=(int)pGetCoeff(p2)) |
---|
[7a5e7c] | 276 | { |
---|
| 277 | if (SpolyLoop != NULL) |
---|
| 278 | SpolyLoop(a1, a2, p2,spNoether); |
---|
| 279 | else |
---|
| 280 | spSpolyLoop_General(a1, a2, p2,spNoether); |
---|
| 281 | } |
---|
[0e1846] | 282 | else |
---|
| 283 | spSpolyLoop1(a1, a2, p2,spNoether); |
---|
| 284 | a2 = pNext(p2); |
---|
| 285 | if (reset_vec) |
---|
| 286 | spModuleToPoly(a1); |
---|
| 287 | pFree1(p2); |
---|
| 288 | return a2; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | /* |
---|
| 292 | * reduction of tail(q) with p1 |
---|
| 293 | * lead(p1) divides lead(pNext(q2)) and pNext(q2) is reduced |
---|
| 294 | * do not destroy p1, but tail(q) |
---|
| 295 | */ |
---|
[51c163] | 296 | static void spPSpolyTail(poly p1, poly q, poly q2, poly spNoether, |
---|
| 297 | spSpolyLoopProc spSpolyLoop) |
---|
[0e1846] | 298 | { |
---|
| 299 | poly h = pNext(q2); |
---|
| 300 | if (p1 != q) |
---|
| 301 | { |
---|
[51c163] | 302 | pNext(q2) = spSpolyRed(p1, h, spNoether, spSpolyLoop); |
---|
[0e1846] | 303 | } |
---|
| 304 | else |
---|
| 305 | { |
---|
[51c163] | 306 | pNext(q2) = spSpolyRedNew(p1, h, spNoether, spSpolyLoop); |
---|
[0e1846] | 307 | pDelete(&h); |
---|
| 308 | } |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | /*2 |
---|
| 312 | * reduction of p2 with p1 |
---|
| 313 | * do not destroy p1 and p2 |
---|
| 314 | */ |
---|
[51c163] | 315 | static poly spPSpolyRedNew(poly p1, poly p2,poly spNoether, |
---|
| 316 | spSpolyLoopProc SpolyLoop) |
---|
[0e1846] | 317 | { |
---|
| 318 | poly a1 = pNext(p1), a2 = pNext(p2); |
---|
| 319 | poly m; |
---|
| 320 | if (a2!=NULL) |
---|
| 321 | a2 = pCopy(a2); |
---|
| 322 | if (a1==NULL) |
---|
| 323 | return a2; |
---|
| 324 | BOOLEAN reset_vec=FALSE; |
---|
| 325 | if (pGetComp(p1) != pGetComp(p2)) |
---|
| 326 | { |
---|
| 327 | pSetCompP(a1,pGetComp(p2)); |
---|
| 328 | reset_vec=TRUE; |
---|
| 329 | } |
---|
| 330 | m = pNew(); |
---|
| 331 | spMemcpy(m,p2); |
---|
| 332 | spMonSub(m,p1); |
---|
[3d3ba58] | 333 | if (1!=(int)pGetCoeff(m)) |
---|
[7a5e7c] | 334 | { |
---|
| 335 | if (SpolyLoop != NULL) |
---|
| 336 | SpolyLoop(a1, a2, m,spNoether); |
---|
| 337 | else |
---|
| 338 | spSpolyLoop_General(a1, a2, m,spNoether); |
---|
| 339 | } |
---|
[0e1846] | 340 | else |
---|
| 341 | spSpolyLoop1(a1, a2, m,spNoether); |
---|
| 342 | a2 = pNext(m); |
---|
| 343 | if (reset_vec) |
---|
| 344 | spModuleToPoly(a1); |
---|
| 345 | pFree1(m); |
---|
| 346 | return a2; |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | /*2 |
---|
| 350 | * creates the S-polynomial of p1 and p2 |
---|
| 351 | * do not destroy p1 and p2 |
---|
| 352 | */ |
---|
[7a5e7c] | 353 | static poly spPSpolyCreate(poly p1, poly p2,poly spNoether, |
---|
| 354 | spSpolyLoopProc SpolyLoop) |
---|
[0e1846] | 355 | { |
---|
| 356 | poly a1 = pNext(p1), a2 = pNext(p2); |
---|
| 357 | poly m, b; |
---|
| 358 | int co=0; |
---|
[51c163] | 359 | Exponent_t c; |
---|
[0e1846] | 360 | if (pGetComp(p1)!=pGetComp(p2)) |
---|
| 361 | { |
---|
| 362 | if (pGetComp(p1)==0) |
---|
| 363 | { |
---|
| 364 | co=1; |
---|
| 365 | pSetCompP(p1,pGetComp(p2)); |
---|
| 366 | } |
---|
| 367 | else |
---|
| 368 | { |
---|
| 369 | co=2; |
---|
| 370 | pSetCompP(p2,pGetComp(p1)); |
---|
| 371 | } |
---|
| 372 | } |
---|
[f92fa13] | 373 | b = pInit(); |
---|
| 374 | m = pInit(); |
---|
[0e1846] | 375 | for (int i = pVariables; i; i--) |
---|
| 376 | { |
---|
[51c163] | 377 | c = pGetExpDiff(p1, p2,i); |
---|
[0e1846] | 378 | if (c > 0) |
---|
| 379 | { |
---|
| 380 | pSetExp(b,i,c); |
---|
| 381 | pSetExp(m,i,0); |
---|
| 382 | } |
---|
| 383 | else |
---|
| 384 | { |
---|
| 385 | pSetExp(m,i,-c); |
---|
| 386 | pSetExp(b,i,0); |
---|
| 387 | } |
---|
| 388 | } |
---|
| 389 | pSetm(m); |
---|
| 390 | pSetm(b); |
---|
| 391 | if (a2!=NULL) |
---|
| 392 | { |
---|
| 393 | spMultCopy0(a2, b,spNoether); |
---|
| 394 | a2 = pNext(b); |
---|
| 395 | } |
---|
| 396 | pFree1(b); |
---|
| 397 | if (a1!=NULL) |
---|
| 398 | { |
---|
| 399 | spSpolyLoop1(a1, a2, m,spNoether); |
---|
| 400 | a2 = pNext(m); |
---|
| 401 | } |
---|
| 402 | pFree1(m); |
---|
| 403 | if (co==1) spModuleToPoly(p1); |
---|
| 404 | else if (co==2) spModuleToPoly(p2); |
---|
| 405 | return a2; |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | /*2 |
---|
| 409 | * creates the leading term of the S-polynomial of p1 and p2 |
---|
| 410 | * do not destroy p1 and p2 |
---|
| 411 | * remarks: |
---|
| 412 | * 1. the coefficient is undefined |
---|
[99c178] | 413 | * 2. pNext is undefined |
---|
[0e1846] | 414 | */ |
---|
[954622] | 415 | //#ifndef TEST_MAC_ORDER |
---|
| 416 | #if 1 |
---|
[0e1846] | 417 | static poly spPSpolyShortBba(poly p1, poly p2) |
---|
| 418 | { |
---|
| 419 | poly a1 = pNext(p1), a2 = pNext(p2); |
---|
[99c178] | 420 | Exponent_t c1=pGetComp(p1),c2=pGetComp(p2); |
---|
| 421 | Exponent_t c; |
---|
| 422 | poly m1,m2; |
---|
| 423 | int cm,i; |
---|
| 424 | |
---|
| 425 | if (a1==NULL) |
---|
[0e1846] | 426 | { |
---|
[99c178] | 427 | if(a2!=NULL) |
---|
[0e1846] | 428 | { |
---|
[f92fa13] | 429 | m2=pInit(); |
---|
[99c178] | 430 | x2: |
---|
| 431 | for (i = pVariables; i; i--) |
---|
| 432 | { |
---|
| 433 | c = pGetExpDiff(p1, p2,i); |
---|
| 434 | if (c>0) |
---|
| 435 | { |
---|
| 436 | pSetExp(m2,i,(c+pGetExp(a2,i))); |
---|
| 437 | } |
---|
| 438 | else |
---|
| 439 | { |
---|
| 440 | pSetExp(m2,i,pGetExp(a2,i)); |
---|
| 441 | } |
---|
| 442 | } |
---|
| 443 | if ((c1==c2)||(c2!=0)) |
---|
| 444 | { |
---|
| 445 | pSetComp(m2,pGetComp(a2)); |
---|
| 446 | } |
---|
| 447 | else |
---|
| 448 | { |
---|
| 449 | pSetComp(m2,c1); |
---|
| 450 | } |
---|
| 451 | pSetm(m2); |
---|
| 452 | return m2; |
---|
[0e1846] | 453 | } |
---|
| 454 | else |
---|
[99c178] | 455 | return NULL; |
---|
| 456 | } |
---|
| 457 | else if (a2==NULL) |
---|
| 458 | { |
---|
[f92fa13] | 459 | m1=pInit(); |
---|
[99c178] | 460 | x1: |
---|
| 461 | for (i = pVariables; i; i--) |
---|
[0e1846] | 462 | { |
---|
[99c178] | 463 | c = pGetExpDiff(p2, p1,i); |
---|
| 464 | if (c>0) |
---|
| 465 | { |
---|
| 466 | pSetExp(m1,i,(c+pGetExp(a1,i))); |
---|
| 467 | } |
---|
| 468 | else |
---|
| 469 | { |
---|
| 470 | pSetExp(m1,i,pGetExp(a1,i)); |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | if ((c1==c2)||(c1!=0)) |
---|
| 474 | { |
---|
| 475 | pSetComp(m1,pGetComp(a1)); |
---|
| 476 | } |
---|
| 477 | else |
---|
| 478 | { |
---|
| 479 | pSetComp(m1,c2); |
---|
[0e1846] | 480 | } |
---|
[99c178] | 481 | pSetm(m1); |
---|
| 482 | return m1; |
---|
[0e1846] | 483 | } |
---|
[f92fa13] | 484 | m1 = pInit(); |
---|
| 485 | m2 = pInit(); |
---|
[99c178] | 486 | loop |
---|
[0e1846] | 487 | { |
---|
[99c178] | 488 | for (i = pVariables; i; i--) |
---|
[0e1846] | 489 | { |
---|
[99c178] | 490 | c = pGetExpDiff(p1, p2,i); |
---|
| 491 | if (c > 0) |
---|
| 492 | { |
---|
| 493 | pSetExp(m2,i,(c+pGetExp(a2,i))); |
---|
| 494 | pSetExp(m1,i,pGetExp(a1,i)); |
---|
| 495 | } |
---|
| 496 | else |
---|
| 497 | { |
---|
| 498 | pSetExp(m1,i,(pGetExp(a1,i)-c)); |
---|
| 499 | pSetExp(m2,i,pGetExp(a2,i)); |
---|
| 500 | } |
---|
| 501 | } |
---|
| 502 | if(c1==c2) |
---|
| 503 | { |
---|
| 504 | pSetComp(m1,pGetComp(a1)); |
---|
| 505 | pSetComp(m2,pGetComp(a2)); |
---|
[0e1846] | 506 | } |
---|
| 507 | else |
---|
| 508 | { |
---|
[99c178] | 509 | if(c1!=0) |
---|
[0e1846] | 510 | { |
---|
[99c178] | 511 | pSetComp(m1,pGetComp(a1)); |
---|
| 512 | pSetComp(m2,c1); |
---|
[0e1846] | 513 | } |
---|
[99c178] | 514 | else |
---|
[0e1846] | 515 | { |
---|
[99c178] | 516 | pSetComp(m2,pGetComp(a2)); |
---|
| 517 | pSetComp(m1,c2); |
---|
| 518 | } |
---|
| 519 | } |
---|
| 520 | pSetm(m1); |
---|
| 521 | pSetm(m2); |
---|
[c5f63ab] | 522 | cm = pComp0(m1, m2); |
---|
[99c178] | 523 | if (cm!=0) |
---|
| 524 | { |
---|
| 525 | if(cm==1) |
---|
| 526 | { |
---|
| 527 | pFree1(m2); |
---|
| 528 | return m1; |
---|
[0e1846] | 529 | } |
---|
| 530 | else |
---|
| 531 | { |
---|
[99c178] | 532 | pFree1(m1); |
---|
| 533 | return m2; |
---|
[0e1846] | 534 | } |
---|
| 535 | } |
---|
[99c178] | 536 | if (!npEqualM(pGetCoeff(a2),pGetCoeff(a1))) |
---|
[0e1846] | 537 | { |
---|
[99c178] | 538 | pFree1(m2); |
---|
| 539 | return m1; |
---|
[0e1846] | 540 | } |
---|
[99c178] | 541 | pIter(a1); |
---|
| 542 | pIter(a2); |
---|
| 543 | if (a2==NULL) |
---|
[0e1846] | 544 | { |
---|
[99c178] | 545 | pFree1(m2); |
---|
| 546 | if (a1==NULL) |
---|
| 547 | { |
---|
| 548 | pFree1(m1); |
---|
| 549 | return NULL; |
---|
| 550 | } |
---|
| 551 | goto x1; |
---|
| 552 | } |
---|
| 553 | if (a1==NULL) |
---|
| 554 | { |
---|
| 555 | pFree1(m1); |
---|
| 556 | goto x2; |
---|
[0e1846] | 557 | } |
---|
| 558 | } |
---|
| 559 | } |
---|
| 560 | #else |
---|
| 561 | static poly spPSpolyShortBba(poly p1, poly p2) |
---|
| 562 | { |
---|
| 563 | poly a1 = pNext(p1), a2 = pNext(p2); |
---|
| 564 | int co=0; |
---|
| 565 | // adjust components, store change poly-nr in co |
---|
| 566 | if (pGetComp(p1)!=pGetComp(p2)) |
---|
| 567 | { |
---|
| 568 | if (pGetComp(p1)==0) |
---|
| 569 | { |
---|
| 570 | co=1; |
---|
| 571 | pSetCompP(p1,pGetComp(p2)); |
---|
| 572 | } |
---|
| 573 | else |
---|
| 574 | { |
---|
| 575 | co=2; |
---|
| 576 | pSetCompP(p2,pGetComp(p1)); |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | //------------------------------------------------------------ |
---|
[f92fa13] | 580 | poly b = pInit(); /* the result */ |
---|
| 581 | poly lcm=pInit(); |
---|
[0e1846] | 582 | pLcm(p1,p2,lcm); |
---|
| 583 | pSetComp(b,pGetComp(p1)); |
---|
| 584 | loop |
---|
| 585 | { |
---|
| 586 | if(a1==NULL) |
---|
| 587 | { |
---|
| 588 | if(a2==NULL) |
---|
| 589 | { |
---|
| 590 | pFree1(b); |
---|
| 591 | b=NULL; |
---|
| 592 | break; |
---|
| 593 | } |
---|
| 594 | else |
---|
| 595 | { |
---|
| 596 | spMemcpy(b,a2); |
---|
[51c163] | 597 | MyspMonAdd0(b,lcm); |
---|
[0e1846] | 598 | spMonSub(b,p2); |
---|
| 599 | break; |
---|
| 600 | } |
---|
| 601 | } |
---|
| 602 | else /*a1!=NULL*/ |
---|
| 603 | { |
---|
| 604 | if(a2==NULL) |
---|
| 605 | { |
---|
| 606 | spMemcpy(b,a1); |
---|
[51c163] | 607 | MyspMonAdd0(b,lcm); |
---|
[0e1846] | 608 | spMonSub(b,p1); |
---|
| 609 | break; |
---|
| 610 | } |
---|
| 611 | } |
---|
| 612 | /* now a1!=NULL and a2!=NULL */ |
---|
| 613 | { |
---|
| 614 | poly n1=pNew(); |
---|
| 615 | poly n2=pNew(); |
---|
| 616 | spMemcpy(n1,a1); |
---|
| 617 | spMemcpy(n2,a2); |
---|
| 618 | spMonAdd(n1,p2); |
---|
| 619 | spMonAdd(n2,p1); |
---|
| 620 | int c=pComp0(n1,n2); |
---|
| 621 | pFree1(n2); |
---|
| 622 | pFree1(n1); |
---|
| 623 | if(c==1) |
---|
| 624 | { |
---|
| 625 | spMemcpy(b,a1); |
---|
[51c163] | 626 | MyspMonAdd0(b,lcm); |
---|
[0e1846] | 627 | spMonSub(b,p1); |
---|
| 628 | break; |
---|
| 629 | } |
---|
| 630 | else if(c==-1) |
---|
| 631 | { |
---|
| 632 | spMemcpy(b,a2); |
---|
[51c163] | 633 | MyspMonAdd0(b,lcm); |
---|
[0e1846] | 634 | spMonSub(b,p2); |
---|
| 635 | break; |
---|
| 636 | } |
---|
| 637 | else |
---|
| 638 | { |
---|
| 639 | if (!npEqualM(pGetCoeff(a2),pGetCoeff(a1))) |
---|
| 640 | { |
---|
| 641 | spMemcpy(b,a1); |
---|
[51c163] | 642 | MyspMonAdd0(b,lcm); |
---|
[0e1846] | 643 | spMonSub(b,p1); |
---|
| 644 | break; |
---|
| 645 | } |
---|
| 646 | pIter(a1); |
---|
| 647 | pIter(a2); |
---|
| 648 | } |
---|
| 649 | } |
---|
| 650 | } |
---|
| 651 | if (co==1) spModuleToPoly(p1); |
---|
| 652 | else if (co==2) spModuleToPoly(p2); |
---|
| 653 | pFree1(lcm); |
---|
| 654 | return b; |
---|
| 655 | } |
---|
| 656 | #endif |
---|
| 657 | |
---|
| 658 | #ifdef SDRING |
---|
[311499] | 659 | poly spDSpolyRed(poly p1,poly p2,poly spNoether, spSpolyLoopProc dummy) |
---|
[0e1846] | 660 | { |
---|
| 661 | poly m=pOne(); |
---|
| 662 | poly tp1; |
---|
| 663 | number n1,n2; |
---|
| 664 | |
---|
| 665 | int i; |
---|
| 666 | |
---|
[ce231a] | 667 | pTest(p1); |
---|
[0e1846] | 668 | for (i=1;i<=pVariables;i++) |
---|
| 669 | { |
---|
| 670 | pSetExp(m,i,pGetExp(p2,i)-pGetExp(p1,i)); |
---|
| 671 | } |
---|
| 672 | #ifdef DRING |
---|
| 673 | if (pDRING) |
---|
| 674 | { |
---|
| 675 | if (pdDFlag(p1)==0) /* && (pdDFlag(p2==0) */ |
---|
| 676 | { |
---|
| 677 | for (i=pdN+1;i<=2*pdN;i++) |
---|
| 678 | { |
---|
| 679 | if (pGetExp(m,i)!=0) |
---|
| 680 | { |
---|
| 681 | pDelete1(&m); |
---|
| 682 | pTest(p2); |
---|
| 683 | return p2; |
---|
| 684 | } |
---|
| 685 | } |
---|
| 686 | } |
---|
[311499] | 687 | pdSetDFlag(m,1); |
---|
[0e1846] | 688 | } |
---|
| 689 | #endif |
---|
| 690 | pSetm(m); |
---|
[ce231a] | 691 | pTest(p1); |
---|
[0e1846] | 692 | tp1=pMult(m,pCopy(p1)); |
---|
[ce231a] | 693 | pTest(tp1); |
---|
[0e1846] | 694 | if (tp1!=NULL) |
---|
| 695 | { |
---|
| 696 | n2=nCopy(pGetCoeff(p2)); |
---|
| 697 | n2=nNeg(n2); |
---|
| 698 | n1=pGetCoeff(tp1); |
---|
| 699 | pMultN(tp1,n2); |
---|
| 700 | pMultN(p2,n1); |
---|
| 701 | nDelete(&n2); |
---|
| 702 | //pDelete1(&p2); |
---|
| 703 | //pDelete1(&tp1); |
---|
| 704 | p2=pAdd(tp1,p2); |
---|
| 705 | } |
---|
| 706 | pTest(p2); |
---|
| 707 | return p2; |
---|
| 708 | } |
---|
| 709 | |
---|
[311499] | 710 | poly spDSpolyRedNew(poly p1,poly p2,poly spNoether, spSpolyLoopProc dummy) |
---|
[0e1846] | 711 | { |
---|
[311499] | 712 | return spDSpolyRed(p1,pCopy(p2),spNoether, dummy); |
---|
[0e1846] | 713 | } |
---|
| 714 | |
---|
[12310e] | 715 | poly spDSpolyCreate(poly p1,poly p2,poly spNoether, spSpolyLoopProc dummy) |
---|
[0e1846] | 716 | { |
---|
| 717 | poly m1=pOne(); |
---|
| 718 | poly m2=pOne(); |
---|
| 719 | poly pp1=p1,pp2=p2; |
---|
| 720 | number n1,n2; |
---|
| 721 | int i,j; |
---|
| 722 | int co=0; |
---|
| 723 | if (pGetComp(p1)!=pGetComp(p2)) |
---|
| 724 | { |
---|
| 725 | if (pGetComp(p1)==0) |
---|
| 726 | { |
---|
| 727 | co=1; |
---|
| 728 | pSetCompP(p1,pGetComp(p2)); |
---|
| 729 | } |
---|
| 730 | else |
---|
| 731 | { |
---|
| 732 | co=2; |
---|
| 733 | pSetCompP(p2,pGetComp(p1)); |
---|
| 734 | } |
---|
| 735 | } |
---|
| 736 | |
---|
| 737 | for (i=1;i<=pVariables;i++) |
---|
| 738 | { |
---|
| 739 | j=pGetExp(p2,i)-pGetExp(p1,i); |
---|
| 740 | if (j>0) |
---|
| 741 | { |
---|
| 742 | pSetExp(m1,i,j); |
---|
| 743 | } |
---|
| 744 | else |
---|
| 745 | { |
---|
| 746 | pSetExp(m2,i,-j); |
---|
| 747 | } |
---|
| 748 | } |
---|
| 749 | #ifdef DRING |
---|
| 750 | if (pDRING) |
---|
| 751 | { |
---|
| 752 | if (pdDFlag(p1)==0) /* && (pdDFlag(p2==0) */ |
---|
| 753 | { |
---|
| 754 | for (i=pdN+1;i<=2*pdN;i++) |
---|
| 755 | { |
---|
| 756 | if ((pGetExp(m1,i)!=0) || (pGetExp(m2,i)!=0)) |
---|
| 757 | { |
---|
| 758 | pDelete1(&m1); |
---|
| 759 | pDelete1(&m2); |
---|
| 760 | return NULL; |
---|
| 761 | } |
---|
| 762 | } |
---|
| 763 | } |
---|
[311499] | 764 | pdSetDFlag(m1,1); |
---|
| 765 | pdSetDFlag(m2,1); |
---|
[0e1846] | 766 | } |
---|
| 767 | #endif |
---|
| 768 | pSetm(m1); |
---|
| 769 | pSetm(m2); |
---|
| 770 | p1=pMult(m1,pCopy(p1)); |
---|
| 771 | p2=pMult(m2,pCopy(p2)); |
---|
| 772 | |
---|
| 773 | n1=nCopy(pGetCoeff(p1)); |
---|
| 774 | n2=nCopy(pGetCoeff(p2)); |
---|
| 775 | |
---|
| 776 | pDelete1(&p1); |
---|
| 777 | pDelete1(&p2); |
---|
| 778 | |
---|
| 779 | n1=nNeg(n1); |
---|
| 780 | pMultN(p1,n2); |
---|
| 781 | nDelete(&n2); |
---|
| 782 | pMultN(p2,n1); |
---|
| 783 | nDelete(&n1); |
---|
| 784 | |
---|
| 785 | m1=pAdd(p1,p2); |
---|
| 786 | if (co==1) spModuleToPoly(pp1); |
---|
| 787 | else if (co==2) spModuleToPoly(pp2); |
---|
| 788 | pTest(m1); |
---|
| 789 | return m1; |
---|
| 790 | } |
---|
| 791 | |
---|
| 792 | #endif |
---|
| 793 | |
---|
| 794 | void spSet(ring r) |
---|
| 795 | { |
---|
[8a150b] | 796 | if ((TEST_OPT_INTSTRATEGY /* Q, Q(a), Fp(a) */ |
---|
[0ae5116] | 797 | || (rField_is_R()) || (rField_is_long_R()) || (rField_is_long_C())) |
---|
[0e1846] | 798 | #ifdef SRING |
---|
| 799 | && (pSRING==0) |
---|
| 800 | #endif |
---|
| 801 | #ifdef DRING |
---|
| 802 | && (pDRING==0) |
---|
| 803 | #endif |
---|
| 804 | ) |
---|
| 805 | { |
---|
| 806 | spSpolyRed=spGSpolyRed; |
---|
| 807 | spSpolyTail=spGSpolyTail; |
---|
| 808 | spSpolyRedNew=spGSpolyRedNew; |
---|
| 809 | spSpolyCreate=spGSpolyCreate; |
---|
| 810 | spSpolyShortBba=spGSpolyShortBba; |
---|
| 811 | return; |
---|
| 812 | } |
---|
[be0d84] | 813 | if (rField_is_GF(r) /* finite fields GF(p,n) */ |
---|
[0e1846] | 814 | #ifdef SRING |
---|
| 815 | && (pSRING==0) |
---|
| 816 | #endif |
---|
| 817 | #ifdef DRING |
---|
| 818 | && (pDRING==0) |
---|
| 819 | #endif |
---|
| 820 | ) |
---|
| 821 | { |
---|
| 822 | spSpolyRed=spGSpolyRed; |
---|
| 823 | spSpolyTail=spGSpolyTail; |
---|
| 824 | spSpolyRedNew=spGSpolyRedNew; |
---|
| 825 | spSpolyCreate=spGSpolyCreate; |
---|
| 826 | spSpolyShortBba=spGSpolyShortBba; |
---|
| 827 | return; |
---|
| 828 | } |
---|
[be0d84] | 829 | if (rField_is_Zp(r) /* Fp */ |
---|
[0e1846] | 830 | #ifdef SRING |
---|
| 831 | && (pSRING==0) |
---|
| 832 | #endif |
---|
| 833 | #ifdef DRING |
---|
| 834 | && (pDRING==0) |
---|
| 835 | #endif |
---|
| 836 | ) |
---|
| 837 | { |
---|
| 838 | spSpolyRed=spPSpolyRed; |
---|
| 839 | spSpolyTail=spPSpolyTail; |
---|
| 840 | spSpolyRedNew=spPSpolyRedNew; |
---|
| 841 | spSpolyCreate=spPSpolyCreate; |
---|
| 842 | spSpolyShortBba=spPSpolyShortBba; |
---|
| 843 | return; |
---|
| 844 | } |
---|
| 845 | #ifdef SRING |
---|
| 846 | if (pSRING!=0) |
---|
| 847 | { |
---|
| 848 | spSpolyRed=spDSpolyRed; |
---|
| 849 | spSpolyRedNew=spDSpolyRedNew; |
---|
| 850 | spSpolyCreate=spDSpolyCreate; |
---|
| 851 | spSpolyShortBba=NULL;/*spGSpolyShortBba;*/ |
---|
| 852 | test&=~Sy_bit(OPT_REDTAIL); // no redtail |
---|
| 853 | return; |
---|
| 854 | } |
---|
| 855 | #endif |
---|
| 856 | #ifdef DRING |
---|
| 857 | if (pDRING!=0) |
---|
| 858 | { |
---|
| 859 | spSpolyRed=spDSpolyRed; |
---|
| 860 | spSpolyRedNew=spDSpolyRedNew; |
---|
| 861 | spSpolyCreate=spDSpolyCreate; |
---|
| 862 | spSpolyShortBba=NULL;/*spGSpolyShortBba;*/ |
---|
| 863 | test&=~Sy_bit(OPT_REDTAIL); // no redtail |
---|
| 864 | return; |
---|
| 865 | } |
---|
| 866 | #endif |
---|
| 867 | WarnS("spoly init err"); |
---|
| 868 | } |
---|