bool fdivides ( const CanonicalForm & f, const CanonicalForm & g ) * * * fdivides() - check whether `f' divides `g'. * * Returns true iff `f' divides `g'. Uses some extra heuristic * to avoid polynomial division. Without the heuristic, the test * essentialy looks like `divremt(g, f, q, r) && r.isZero()'. * * Type info: * ---------- * f, g: Current * * Elements from prime power domai
| 337 | * |
| 338 | **/ |
| 339 | bool |
| 340 | fdivides ( const CanonicalForm & f, const CanonicalForm & g ) |
| 341 | { |
| 342 | // trivial cases |
| 343 | if ( g.isZero() ) |
| 344 | return true; |
| 345 | else if ( f.isZero() ) |
| 346 | return false; |
| 347 | |
| 348 | if ( (f.inCoeffDomain() || g.inCoeffDomain()) |
| 349 | && ((getCharacteristic() == 0 && isOn( SW_RATIONAL )) |
| 350 | || (getCharacteristic() > 0) )) |
| 351 | { |
| 352 | // if we are in a field all elements not equal to zero are units |
| 353 | if ( f.inCoeffDomain() ) |
| 354 | return true; |
| 355 | else |
| 356 | // g.inCoeffDomain() |
| 357 | return false; |
| 358 | } |
| 359 | |
| 360 | // we may assume now that both levels either equal LEVELBASE |
| 361 | // or are greater zero |
| 362 | int fLevel = f.level(); |
| 363 | int gLevel = g.level(); |
| 364 | if ( (gLevel > 0) && (fLevel == gLevel) ) |
| 365 | // f and g are polynomials in the same main variable |
| 366 | if ( degree( f ) <= degree( g ) |
| 367 | && fdivides( f.tailcoeff(), g.tailcoeff() ) |
| 368 | && fdivides( f.LC(), g.LC() ) ) |
| 369 | { |
| 370 | CanonicalForm q, r; |
| 371 | return divremt( g, f, q, r ) && r.isZero(); |
| 372 | } |
| 373 | else |
| 374 | return false; |
| 375 | else if ( gLevel < fLevel ) |
| 376 | // g is a coefficient w.r.t. f |
| 377 | return false; |
| 378 | else |
| 379 | { |
| 380 | // either f is a coefficient w.r.t. polynomial g or both |
| 381 | // f and g are from a base domain (should be Z or Z/p^n, |
| 382 | // then) |
| 383 | CanonicalForm q, r; |
| 384 | return divremt( g, f, q, r ) && r.isZero(); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | /// same as fdivides if true returns quotient quot of g by f otherwise quot == 0 |
| 389 | bool |
no test coverage detected