Changeset e5d267 in git
- Timestamp:
- Jul 4, 2011, 4:22:10 PM (12 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
- Children:
- da49bc5ede2940b54c1e9f92022763151efa76e6
- Parents:
- df43d9eede47de2604d4c0ff334af81427c1ec57
- git-author:
- Frank Seelisch <seelisch@mathematik.uni-kl.de>2011-07-04 16:22:10+02:00
- git-committer:
- Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:39:11+01:00
- Location:
- libpolys
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/coeffs/longrat.cc
rdf43d9 re5d267 2603 2603 r->cfDBTest=nlDBTest; 2604 2604 #endif 2605 #ifdef HAVE_FACTORY 2606 r->convSingNFactoryN=nlConvSingNFactoryN; 2607 r->convFactoryNSingN=nlConvFactoryNSingN; 2608 #endif 2605 2609 2606 2610 // the variables: general stuff (required) -
libpolys/polys/ext_fields/transext.cc
rdf43d9 re5d267 25 25 #include <polys/monomials/p_polys.h> 26 26 #include <polys/simpleideals.h> 27 28 #ifdef HAVE_FACTORY 29 #include <polys/clapsing.h> 30 #endif 27 31 28 32 #include <polys/ext_fields/transext.h> … … 74 78 assume(getCoeffType(cf) == ntID); 75 79 fraction t = (fraction)a; 76 if ( is0(t)) return TRUE;77 assume( num(t) != NULL); /**< t != 0 ==> numerator(t) != 0 */78 p_Test( num(t), ntRing);79 if (! denIs1(t)) p_Test(den(t), ntRing);80 if (IS0(t)) return TRUE; 81 assume(NUM(t) != NULL); /**< t != 0 ==> numerator(t) != 0 */ 82 p_Test(NUM(t), ntRing); 83 if (!DENIS1(t)) p_Test(DEN(t), ntRing); 80 84 return TRUE; 81 85 } … … 103 107 { 104 108 ntTest(a); 105 return ( is0(a));109 return (IS0(a)); 106 110 } 107 111 … … 109 113 { 110 114 fraction f = (fraction)(*a); 111 if ( is0(f)) return;112 p_Delete(& num(f), ntRing);113 if (! denIs1(f)) p_Delete(&den(f), ntRing);115 if (IS0(f)) return; 116 p_Delete(&NUM(f), ntRing); 117 if (!DENIS1(f)) p_Delete(&DEN(f), ntRing); 114 118 omFreeBin((ADDRESS)f, fractionObjectBin); 115 119 *a = NULL; … … 122 126 /// simple tests 123 127 if (a == b) return TRUE; 124 if (( is0(a)) && (!is0(b))) return FALSE;125 if (( is0(b)) && (!is0(a))) return FALSE;128 if ((IS0(a)) && (!IS0(b))) return FALSE; 129 if ((IS0(b)) && (!IS0(a))) return FALSE; 126 130 127 131 /// cheap test if gcd's have been cancelled in both numbers 128 132 fraction fa = (fraction)a; 129 133 fraction fb = (fraction)b; 130 if (( c(fa) == 1) && (c(fb) == 1))131 { 132 poly f = p_Add_q(p_Copy( num(fa), ntRing),133 p_Neg(p_Copy( num(fb), ntRing), ntRing),134 if ((COM(fa) == 1) && (COM(fb) == 1)) 135 { 136 poly f = p_Add_q(p_Copy(NUM(fa), ntRing), 137 p_Neg(p_Copy(NUM(fb), ntRing), ntRing), 134 138 ntRing); 135 139 if (f != NULL) { p_Delete(&f, ntRing); return FALSE; } 136 if ( denIs1(fa) && denIs1(fb)) return TRUE;137 if ( denIs1(fa) && !denIs1(fb)) return FALSE;138 if (! denIs1(fa) && denIs1(fb)) return FALSE;139 f = p_Add_q(p_Copy( den(fa), ntRing),140 p_Neg(p_Copy( den(fb), ntRing), ntRing),140 if (DENIS1(fa) && DENIS1(fb)) return TRUE; 141 if (DENIS1(fa) && !DENIS1(fb)) return FALSE; 142 if (!DENIS1(fa) && DENIS1(fb)) return FALSE; 143 f = p_Add_q(p_Copy(DEN(fa), ntRing), 144 p_Neg(p_Copy(DEN(fb), ntRing), ntRing), 141 145 ntRing); 142 146 if (f != NULL) { p_Delete(&f, ntRing); return FALSE; } … … 146 150 /* default: the more expensive multiplication test 147 151 a/b = c/d <==> a*d = b*c */ 148 poly f = p_Copy( num(fa), ntRing);149 if (! denIs1(fb)) f = p_Mult_q(f, p_Copy(den(fb), ntRing), ntRing);150 poly g = p_Copy( num(fb), ntRing);151 if (! denIs1(fa)) g = p_Mult_q(g, p_Copy(den(fa), ntRing), ntRing);152 poly f = p_Copy(NUM(fa), ntRing); 153 if (!DENIS1(fb)) f = p_Mult_q(f, p_Copy(DEN(fb), ntRing), ntRing); 154 poly g = p_Copy(NUM(fb), ntRing); 155 if (!DENIS1(fa)) g = p_Mult_q(g, p_Copy(DEN(fa), ntRing), ntRing); 152 156 poly h = p_Add_q(f, p_Neg(g, ntRing), ntRing); 153 157 if (h == NULL) return TRUE; … … 162 166 { 163 167 ntTest(a); 164 if ( is0(a)) return NULL;165 fraction f = (fraction)a; 166 poly g = p_Copy( num(f), ntRing);167 poly h = NULL; if (! denIs1(f)) h = p_Copy(den(f), ntRing);168 if (IS0(a)) return NULL; 169 fraction f = (fraction)a; 170 poly g = p_Copy(NUM(f), ntRing); 171 poly h = NULL; if (!DENIS1(f)) h = p_Copy(DEN(f), ntRing); 168 172 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 169 num(result) = g;170 den(result) = h;171 c(result) = c(f);173 NUM(result) = g; 174 DEN(result) = h; 175 COM(result) = COM(f); 172 176 return (number)result; 173 177 } … … 177 181 ntTest(a); 178 182 definiteGcdCancellation(a, cf, FALSE); 179 if ( is0(a)) return NULL;180 fraction f = (fraction)a; 181 poly g = p_Copy( num(f), ntRing);183 if (IS0(a)) return NULL; 184 fraction f = (fraction)a; 185 poly g = p_Copy(NUM(f), ntRing); 182 186 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 183 num(result) = g;184 den(result) = NULL;185 c(result) = 0;187 NUM(result) = g; 188 DEN(result) = NULL; 189 COM(result) = 0; 186 190 return (number)result; 187 191 } … … 193 197 fraction f = (fraction)a; 194 198 poly g; 195 if ( is0(f) || denIs1(f)) g = p_One(ntRing);196 else g = p_Copy( den(f), ntRing);199 if (IS0(f) || DENIS1(f)) g = p_One(ntRing); 200 else g = p_Copy(DEN(f), ntRing); 197 201 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 198 num(result) = g;199 den(result) = NULL;200 c(result) = 0;202 NUM(result) = g; 203 DEN(result) = NULL; 204 COM(result) = 0; 201 205 return (number)result; 202 206 } … … 207 211 definiteGcdCancellation(a, cf, FALSE); 208 212 fraction f = (fraction)a; 209 return denIs1(f) && numIs1(f);213 return DENIS1(f) && NUMIS1(f); 210 214 } 211 215 … … 215 219 definiteGcdCancellation(a, cf, FALSE); 216 220 fraction f = (fraction)a; 217 if (! denIs1(f)) return FALSE;218 poly g = num(f);221 if (!DENIS1(f)) return FALSE; 222 poly g = NUM(f); 219 223 if (!p_IsConstant(g, ntRing)) return FALSE; 220 224 return n_IsMOne(p_GetCoeff(g, ntRing), ntCoeffs); … … 225 229 { 226 230 ntTest(a); 227 if (! is0(a))231 if (!IS0(a)) 228 232 { 229 233 fraction f = (fraction)a; 230 num(f) = p_Neg(num(f), ntRing);234 NUM(f) = p_Neg(NUM(f), ntRing); 231 235 } 232 236 return a; … … 245 249 { 246 250 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 247 num(result) = p_ISet(i, ntRing);248 den(result) = NULL;249 c(result) = 0;251 NUM(result) = p_ISet(i, ntRing); 252 DEN(result) = NULL; 253 COM(result) = 0; 250 254 return (number)result; 251 255 } … … 255 259 { 256 260 ntTest(a); 257 if ( is0(a)) return 0;261 if (IS0(a)) return 0; 258 262 definiteGcdCancellation(a, cf, FALSE); 259 263 fraction f = (fraction)a; 260 if (! denIs1(f)) return 0;261 if (!p_IsConstant( num(f), ntRing)) return 0;262 return n_Int(p_GetCoeff( num(f), ntRing), ntCoeffs);264 if (!DENIS1(f)) return 0; 265 if (!p_IsConstant(NUM(f), ntRing)) return 0; 266 return n_Int(p_GetCoeff(NUM(f), ntRing), ntCoeffs); 263 267 } 264 268 … … 274 278 number aNumCoeff = NULL; int aNumDeg = 0; 275 279 number bNumCoeff = NULL; int bNumDeg = 0; 276 if (! is0(a))280 if (!IS0(a)) 277 281 { 278 282 fraction fa = (fraction)a; 279 aNumDeg = p_Totaldegree( num(fa), ntRing);280 aNumCoeff = p_GetCoeff( num(fa), ntRing);281 } 282 if (! is0(b))283 aNumDeg = p_Totaldegree(NUM(fa), ntRing); 284 aNumCoeff = p_GetCoeff(NUM(fa), ntRing); 285 } 286 if (!IS0(b)) 283 287 { 284 288 fraction fb = (fraction)b; 285 bNumDeg = p_Totaldegree( num(fb), ntRing);286 bNumCoeff = p_GetCoeff( num(fb), ntRing);289 bNumDeg = p_Totaldegree(NUM(fb), ntRing); 290 bNumCoeff = p_GetCoeff(NUM(fb), ntRing); 287 291 } 288 292 if (aNumDeg != bNumDeg) return FALSE; … … 298 302 { 299 303 ntTest(a); 300 if ( is0(a)) return FALSE;301 fraction f = (fraction)a; 302 poly g = num(f);304 if (IS0(a)) return FALSE; 305 fraction f = (fraction)a; 306 poly g = NUM(f); 303 307 return (n_GreaterZero(p_GetCoeff(g, ntRing), ntCoeffs) || 304 308 (!p_LmIsConstant(g, ntRing))); … … 326 330 p_Setm(p, ntRing); 327 331 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 328 num(result) = p;329 den(result) = NULL;330 c(result) = 0;332 NUM(result) = p; 333 DEN(result) = NULL; 334 COM(result) = 0; 331 335 return (number)result; 332 336 } … … 335 339 { 336 340 ntTest(a); ntTest(b); 337 if ( is0(a)) return ntCopy(b, cf);338 if ( is0(b)) return ntCopy(a, cf);341 if (IS0(a)) return ntCopy(b, cf); 342 if (IS0(b)) return ntCopy(a, cf); 339 343 340 344 fraction fa = (fraction)a; 341 345 fraction fb = (fraction)b; 342 346 343 poly g = p_Copy( num(fa), ntRing);344 if (! denIs1(fb)) g = p_Mult_q(g, p_Copy(den(fb), ntRing), ntRing);345 poly h = p_Copy( num(fb), ntRing);346 if (! denIs1(fa)) h = p_Mult_q(h, p_Copy(den(fa), ntRing), ntRing);347 poly g = p_Copy(NUM(fa), ntRing); 348 if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing); 349 poly h = p_Copy(NUM(fb), ntRing); 350 if (!DENIS1(fa)) h = p_Mult_q(h, p_Copy(DEN(fa), ntRing), ntRing); 347 351 g = p_Add_q(g, h, ntRing); 348 352 … … 350 354 351 355 poly f; 352 if ( denIs1(fa) && denIs1(fb)) f = NULL;353 else if (! denIs1(fa) && denIs1(fb)) f = p_Copy(den(fa), ntRing);354 else if ( denIs1(fa) && !denIs1(fb)) f = p_Copy(den(fb), ntRing);355 else /* both denom's are != 1 */ f = p_Mult_q(p_Copy( den(fa), ntRing),356 p_Copy( den(fb), ntRing),356 if (DENIS1(fa) && DENIS1(fb)) f = NULL; 357 else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing); 358 else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing); 359 else /* both denom's are != 1 */ f = p_Mult_q(p_Copy(DEN(fa), ntRing), 360 p_Copy(DEN(fb), ntRing), 357 361 ntRing); 358 362 359 363 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 360 num(result) = g;361 den(result) = f;362 c(result) = c(fa) + c(fb) + ADD_COMPLEXITY;364 NUM(result) = g; 365 DEN(result) = f; 366 COM(result) = COM(fa) + COM(fb) + ADD_COMPLEXITY; 363 367 heuristicGcdCancellation((number)result, cf); 364 368 return (number)result; … … 368 372 { 369 373 ntTest(a); ntTest(b); 370 if ( is0(a)) return ntNeg(ntCopy(b, cf), cf);371 if ( is0(b)) return ntCopy(a, cf);374 if (IS0(a)) return ntNeg(ntCopy(b, cf), cf); 375 if (IS0(b)) return ntCopy(a, cf); 372 376 373 377 fraction fa = (fraction)a; 374 378 fraction fb = (fraction)b; 375 379 376 poly g = p_Copy( num(fa), ntRing);377 if (! denIs1(fb)) g = p_Mult_q(g, p_Copy(den(fb), ntRing), ntRing);378 poly h = p_Copy( num(fb), ntRing);379 if (! denIs1(fa)) h = p_Mult_q(h, p_Copy(den(fa), ntRing), ntRing);380 poly g = p_Copy(NUM(fa), ntRing); 381 if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing); 382 poly h = p_Copy(NUM(fb), ntRing); 383 if (!DENIS1(fa)) h = p_Mult_q(h, p_Copy(DEN(fa), ntRing), ntRing); 380 384 g = p_Add_q(g, p_Neg(h, ntRing), ntRing); 381 385 … … 383 387 384 388 poly f; 385 if ( denIs1(fa) && denIs1(fb)) f = NULL;386 else if (! denIs1(fa) && denIs1(fb)) f = p_Copy(den(fa), ntRing);387 else if ( denIs1(fa) && !denIs1(fb)) f = p_Copy(den(fb), ntRing);388 else /* both den's are != 1 */ f = p_Mult_q(p_Copy( den(fa), ntRing),389 p_Copy( den(fb), ntRing),389 if (DENIS1(fa) && DENIS1(fb)) f = NULL; 390 else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing); 391 else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing); 392 else /* both den's are != 1 */ f = p_Mult_q(p_Copy(DEN(fa), ntRing), 393 p_Copy(DEN(fb), ntRing), 390 394 ntRing); 391 395 392 396 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 393 num(result) = g;394 den(result) = f;395 c(result) = c(fa) + c(fb) + ADD_COMPLEXITY;397 NUM(result) = g; 398 DEN(result) = f; 399 COM(result) = COM(fa) + COM(fb) + ADD_COMPLEXITY; 396 400 heuristicGcdCancellation((number)result, cf); 397 401 return (number)result; … … 401 405 { 402 406 ntTest(a); ntTest(b); 403 if ( is0(a) || is0(b)) return NULL;407 if (IS0(a) || IS0(b)) return NULL; 404 408 405 409 fraction fa = (fraction)a; 406 410 fraction fb = (fraction)b; 407 411 408 poly g = p_Copy( num(fa), ntRing);409 poly h = p_Copy( num(fb), ntRing);412 poly g = p_Copy(NUM(fa), ntRing); 413 poly h = p_Copy(NUM(fb), ntRing); 410 414 g = p_Mult_q(g, h, ntRing); 411 415 … … 413 417 414 418 poly f; 415 if ( denIs1(fa) && denIs1(fb)) f = NULL;416 else if (! denIs1(fa) && denIs1(fb)) f = p_Copy(den(fa), ntRing);417 else if ( denIs1(fa) && !denIs1(fb)) f = p_Copy(den(fb), ntRing);418 else /* both den's are != 1 */ f = p_Mult_q(p_Copy( den(fa), ntRing),419 p_Copy( den(fb), ntRing),419 if (DENIS1(fa) && DENIS1(fb)) f = NULL; 420 else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing); 421 else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing); 422 else /* both den's are != 1 */ f = p_Mult_q(p_Copy(DEN(fa), ntRing), 423 p_Copy(DEN(fb), ntRing), 420 424 ntRing); 421 425 422 426 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 423 num(result) = g;424 den(result) = f;425 c(result) = c(fa) + c(fb) + MULT_COMPLEXITY;427 NUM(result) = g; 428 DEN(result) = f; 429 COM(result) = COM(fa) + COM(fb) + MULT_COMPLEXITY; 426 430 heuristicGcdCancellation((number)result, cf); 427 431 return (number)result; … … 431 435 { 432 436 ntTest(a); ntTest(b); 433 if ( is0(a)) return NULL;434 if ( is0(b)) WerrorS(nDivBy0);437 if (IS0(a)) return NULL; 438 if (IS0(b)) WerrorS(nDivBy0); 435 439 436 440 fraction fa = (fraction)a; 437 441 fraction fb = (fraction)b; 438 442 439 poly g = p_Copy( num(fa), ntRing);440 if (! denIs1(fb)) g = p_Mult_q(g, p_Copy(den(fb), ntRing), ntRing);443 poly g = p_Copy(NUM(fa), ntRing); 444 if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing); 441 445 442 446 if (g == NULL) return NULL; /* may happen due to zero divisors */ 443 447 444 poly f = p_Copy( num(fb), ntRing);445 if (! denIs1(fa)) f = p_Mult_q(f, p_Copy(den(fa), ntRing), ntRing);448 poly f = p_Copy(NUM(fb), ntRing); 449 if (!DENIS1(fa)) f = p_Mult_q(f, p_Copy(DEN(fa), ntRing), ntRing); 446 450 447 451 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 448 num(result) = g;449 den(result) = f;450 c(result) = c(fa) + c(fb) + MULT_COMPLEXITY;452 NUM(result) = g; 453 DEN(result) = f; 454 COM(result) = COM(fa) + COM(fb) + MULT_COMPLEXITY; 451 455 heuristicGcdCancellation((number)result, cf); 452 456 return (number)result; … … 466 470 467 471 /* special cases first */ 468 if ( is0(a))472 if (IS0(a)) 469 473 { 470 474 if (exp >= 0) *b = NULL; … … 529 533 { 530 534 ntTest(a); 531 if (is0(a)) return; 532 533 fraction f = (fraction)a; 534 if (denIs1(f) || numIs1(f)) { c(f) = 0; return; } 535 536 /* check whether num(f) = den(f), and - if so - replace 'a' by 1 */ 537 poly difference = p_Add_q(p_Copy(num(f), ntRing), 538 p_Neg(p_Copy(den(f), ntRing), ntRing), 539 ntRing); 540 if (difference == NULL) 541 { /* we also know that numerator and denominator are both != 1 */ 542 p_Delete(&num(f), ntRing); num(f) = p_ISet(1, ntRing); 543 p_Delete(&den(f), ntRing); den(f) = NULL; 544 c(f) = 0; 535 if (IS0(a)) return; 536 537 fraction f = (fraction)a; 538 if (DENIS1(f) || NUMIS1(f)) { COM(f) = 0; return; } 539 540 /* check whether NUM(f) = DEN(f), and - if so - replace 'a' by 1 */ 541 if (p_EqualPolys(NUM(f), DEN(f), ntRing)) 542 { /* numerator and denominator are both != 1 */ 543 p_Delete(&NUM(f), ntRing); NUM(f) = p_ISet(1, ntRing); 544 p_Delete(&DEN(f), ntRing); DEN(f) = NULL; 545 COM(f) = 0; 545 546 return; 546 547 } 547 else p_Delete(&difference, ntRing); 548 549 if (c(f) <= BOUND_COMPLEXITY) return; 548 549 if (COM(f) <= BOUND_COMPLEXITY) return; 550 550 else definiteGcdCancellation(a, cf, TRUE); 551 551 } … … 561 561 if (!skipSimpleTests) 562 562 { 563 if (is0(a)) return; 564 if (denIs1(f) || numIs1(f)) { c(f) = 0; return; } 565 566 /* check whether num(f) = den(f), and - if so - replace 'a' by 1 */ 567 poly difference = p_Add_q(p_Copy(num(f), ntRing), 568 p_Neg(p_Copy(den(f), ntRing), ntRing), 569 ntRing); 570 if (difference == NULL) 571 { /* we also know that numerator and denominator are both != 1 */ 572 p_Delete(&num(f), ntRing); num(f) = p_ISet(1, ntRing); 573 p_Delete(&den(f), ntRing); den(f) = NULL; 574 c(f) = 0; 563 if (IS0(a)) return; 564 if (DENIS1(f) || NUMIS1(f)) { COM(f) = 0; return; } 565 566 /* check whether NUM(f) = DEN(f), and - if so - replace 'a' by 1 */ 567 if (p_EqualPolys(NUM(f), DEN(f), ntRing)) 568 { /* numerator and denominator are both != 1 */ 569 p_Delete(&NUM(f), ntRing); NUM(f) = p_ISet(1, ntRing); 570 p_Delete(&DEN(f), ntRing); DEN(f) = NULL; 571 COM(f) = 0; 575 572 return; 576 573 } 577 else p_Delete(&difference, ntRing); 578 } 579 580 /* TO BE IMPLEMENTED! 581 for the time being, cancellation of gcd's does not take place */ 582 Print("// TO BE IMPLEMENTED: transext.cc:definiteGcdCancellation\n"); 583 Print("// (complexity of number = %d, bound = %d)\n", 584 c(f), BOUND_COMPLEXITY); 585 } 586 574 } 575 576 #ifdef HAVE_FACTORY 577 /* singclap_gcd destroys its arguments. We hence need copies: */ 578 poly pNum = p_Copy(NUM(f), ntRing); 579 poly pDen = p_Copy(DEN(f), ntRing); 580 poly pGcd = singclap_gcd(pNum, pDen, cf->extRing); 581 if (p_IsConstant(pGcd, ntRing) && 582 n_IsOne(p_GetCoeff(pGcd, ntRing), ntCoeffs)) 583 { 584 /* gcd = 1; nothing to cancel */ 585 } 586 else 587 { 588 poly newNum = singclap_pdivide(NUM(f), pGcd, ntRing); 589 p_Delete(&NUM(f), ntRing); 590 NUM(f) = newNum; 591 poly newDen = singclap_pdivide(DEN(f), pGcd, ntRing); 592 p_Delete(&DEN(f), ntRing); 593 if (p_IsConstant(newDen, ntRing) && 594 n_IsOne(p_GetCoeff(newDen, ntRing), ntCoeffs)) 595 { 596 /* newDen = 1 needs to be represented by NULL */ 597 p_Delete(&newDen, ntRing); 598 newDen = NULL; 599 } 600 DEN(f) = newDen; 601 } 602 COM(f) = 0; 603 p_Delete(&pGcd, ntRing); 604 #endif /* HAVE_FACTORY */ 605 } 606 607 /* modifies a */ 587 608 void ntWrite(number &a, const coeffs cf) 588 609 { 589 610 ntTest(a); 590 611 definiteGcdCancellation(a, cf, FALSE); 591 if ( is0(a))612 if (IS0(a)) 592 613 StringAppendS("0"); 593 614 else 594 615 { 595 616 fraction f = (fraction)a; 596 BOOLEAN useBrackets = !(p_IsConstant(num(f), ntRing)) && (!denIs1(f));617 BOOLEAN useBrackets = (!p_IsConstant(NUM(f), ntRing)) && (!DENIS1(f)); 597 618 if (useBrackets) StringAppendS("("); 598 p_String0( num(f), ntRing, ntRing);619 p_String0(NUM(f), ntRing, ntRing); 599 620 if (useBrackets) StringAppendS(")"); 600 if (! denIs1(f))621 if (!DENIS1(f)) 601 622 { 602 623 StringAppendS("/"); 603 useBrackets = !p_IsConstant( den(f), ntRing);624 useBrackets = !p_IsConstant(DEN(f), ntRing); 604 625 if (useBrackets) StringAppendS("("); 605 p_String0( den(f), ntRing, ntRing);626 p_String0(DEN(f), ntRing, ntRing); 606 627 if (useBrackets) StringAppendS(")"); 607 628 } … … 617 638 { 618 639 fraction f = (fraction)omAlloc0Bin(fractionObjectBin); 619 num(f) = p;620 den(f) = NULL;621 c(f) = 0;640 NUM(f) = p; 641 DEN(f) = NULL; 642 COM(f) = 0; 622 643 *a = (number)f; 623 644 return result; … … 659 680 { 660 681 ntTest(a); 661 if ( is0(a)) return -1;682 if (IS0(a)) return -1; 662 683 /* this has been taken from the old implementation of field extensions, 663 684 where we computed the sum of the degrees and the numbers of terms in … … 665 686 time being */ 666 687 fraction f = (fraction)a; 667 poly p = num(f);688 poly p = NUM(f); 668 689 int noOfTerms = 0; 669 690 int numDegree = 0; … … 678 699 } 679 700 int denDegree = 0; 680 if (! denIs1(f))681 { 682 p = den(f);701 if (!DENIS1(f)) 702 { 703 p = DEN(f); 683 704 while (p != NULL) 684 705 { … … 697 718 { 698 719 ntTest(a); 699 if ( is0(a)) WerrorS(nDivBy0);720 if (IS0(a)) WerrorS(nDivBy0); 700 721 fraction f = (fraction)a; 701 722 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 702 723 poly g; 703 if ( denIs1(f)) g = p_One(ntRing);704 else g = p_Copy( den(f), ntRing);705 num(result) = g;706 den(result) = p_Copy(num(f), ntRing);707 c(result) = c(f);724 if (DENIS1(f)) g = p_One(ntRing); 725 else g = p_Copy(DEN(f), ntRing); 726 NUM(result) = g; 727 DEN(result) = p_Copy(NUM(f), ntRing); 728 COM(result) = COM(f); 708 729 return (number)result; 709 730 } … … 717 738 p_SetCoeff(p, ntCopy(a, src), dst->extRing); 718 739 fraction f = (fraction)omAlloc0Bin(fractionObjectBin); 719 num(f) = p; den(f) = NULL; c(f) = 0;740 NUM(f) = p; DEN(f) = NULL; COM(f) = 0; 720 741 return (number)f; 721 742 } … … 737 758 p_SetCoeff(p, q, dst->extRing); 738 759 fraction f = (fraction)omAlloc0Bin(fractionObjectBin); 739 num(f) = p; den(f) = NULL; c(f) = 0;760 NUM(f) = p; DEN(f) = NULL; COM(f) = 0; 740 761 return (number)f; 741 762 } … … 764 785 p_SetCoeff(g, q, dst->extRing); 765 786 fraction f = (fraction)omAlloc0Bin(fractionObjectBin); 766 num(f) = g; den(f) = NULL; c(f) = 0;787 NUM(f) = g; DEN(f) = NULL; COM(f) = 0; 767 788 return (number)f; 768 789 } … … 776 797 p_SetCoeff(p, ntCopy(a, src), dst->extRing); 777 798 fraction f = (fraction)omAlloc0Bin(fractionObjectBin); 778 num(f) = p; den(f) = NULL; c(f) = 0;799 NUM(f) = p; DEN(f) = NULL; COM(f) = 0; 779 800 return (number)f; 780 801 } … … 796 817 p_SetCoeff(p, q, dst->extRing); 797 818 fraction f = (fraction)omAlloc0Bin(fractionObjectBin); 798 num(f) = p; den(f) = NULL; c(f) = 0;819 NUM(f) = p; DEN(f) = NULL; COM(f) = 0; 799 820 return (number)f; 800 821 } … … 907 928 cf->cfIntDiv = ntDiv; 908 929 930 #ifndef HAVE_FACTORY 931 PrintS("// Warning: The 'factory' module is not available.\n"); 932 PrintS("// Hence gcd's cannot be cancelled in any\n"); 933 PrintS("// computed fraction!\n"); 934 #endif 935 909 936 return FALSE; 910 937 } -
libpolys/polys/ext_fields/transext.h
rdf43d9 re5d267 59 59 60 60 /* some useful accessors for fractions: */ 61 #define is0(f) (f == NULL) /**< TRUE iff n represents 0 in K(t_1, .., t_s) */ 62 #define num(f) f->numerator 63 #define den(f) f->denominator 64 #define denIs1(f) (f->denominator == NULL) /**< TRUE iff den. represents 1 */ 65 #define numIs1(f) (p_IsConstant(f->numerator, cf->extRing) && \ 66 n_IsOne(p_GetCoeff(num(f), cf->extRing), cf->extRing->cf)) 61 #define IS0(f) (f == NULL) /**< TRUE iff n represents 0 in K(t_1, .., t_s) */ 62 #define NUM(f) f->numerator 63 #define DEN(f) f->denominator 64 #define DENIS1(f) (f->denominator == NULL) /**< TRUE iff den. represents 1 */ 65 #define NUMIS1(f) (p_IsConstant(f->numerator, cf->extRing) && \ 66 n_IsOne(p_GetCoeff(f->numerator, cf->extRing), \ 67 cf->extRing->cf)) 67 68 /**< TRUE iff num. represents 1 */ 68 #define c(f) f->complexity69 #define COM(f) f->complexity 69 70 70 71 /// Get a mapping function from src into the domain of this type (n_transExt) -
libpolys/polys/monomials/p_polys.cc
rdf43d9 re5d267 1310 1310 } 1311 1311 /*2 1312 * assumes that the head term of b is a multiple of the head term of a 1313 * and return the multiplicant *m 1314 * Frank's observation: If LM(b) = LM(a)*m, then we may actually set 1315 * negative(!) exponents in the below loop. I suspect that the correct 1316 * comment should be "assumes that LM(a) = LM(b)*m, for some monomial m..." 1312 * assumes that LM(a) = LM(b)*m, for some monomial m, 1313 * returns the multiplicant m, 1314 * leaves a and b unmodified 1317 1315 */ 1318 1316 poly p_Divide(poly a, poly b, const ring r) -
libpolys/tests/polys_test.h
rdf43d9 re5d267 233 233 } 234 234 /* assumes that cf represents a rational function field; 235 does NOT copy p, i.e. uses p directlyinside the resulting number */235 uses a copy of p inside the resulting number */ 236 236 number toFractionNumber(poly p, const coeffs cf) 237 237 { … … 239 239 fraction f = (fraction)n; 240 240 p_Delete(&(f->numerator), cf->extRing); 241 f->numerator = p ;241 f->numerator = p_Copy(p, cf->extRing); 242 242 return n; 243 243 } … … 953 953 number v_n = toFractionNumber(v, cf); 954 954 PrintSized(v_n, cf); 955 poly w = NULL; 956 plusTerm(w, 1, 1, 1, cf->extRing); // s 957 plusTerm(w, 1, 1, 0, cf->extRing); // s + 1 955 poly w1 = NULL; 956 plusTerm(w1, 1, 1, 1, cf->extRing); // s 957 plusTerm(w1, 1, 1, 0, cf->extRing); // s + 1 958 poly w2 = NULL; 959 plusTerm(w2, 3, 1, 1, cf->extRing); // 3s 960 plusTerm(w2, -7, 2, 1, cf->extRing); // 3s - 7t 961 poly w = p_Mult_q(w1, w2, cf->extRing); // (s + 1) * (3s - 7t) 958 962 number w_n = toFractionNumber(w, cf); 959 963 PrintSized(w_n, cf); … … 972 976 clog << i << ". "; PrintSized(nn, cf); 973 977 } 978 974 979 n_Delete(&prod, cf); n_Delete(&nn, cf); 975 980 n_Delete(&v_n, cf); n_Delete(&w_n, cf);
Note: See TracChangeset
for help on using the changeset viewer.