| 287 | } |
| 288 | |
| 289 | void tryEuclid( const CanonicalForm & A, const CanonicalForm & B, const CanonicalForm & M, CanonicalForm & result, bool & fail ) |
| 290 | { |
| 291 | CanonicalForm P; |
| 292 | if(A.inCoeffDomain()) |
| 293 | { |
| 294 | tryInvert( A, M, P, fail ); |
| 295 | if(fail) |
| 296 | return; |
| 297 | result = 1; |
| 298 | return; |
| 299 | } |
| 300 | if(B.inCoeffDomain()) |
| 301 | { |
| 302 | tryInvert( B, M, P, fail ); |
| 303 | if(fail) |
| 304 | return; |
| 305 | result = 1; |
| 306 | return; |
| 307 | } |
| 308 | // here: both not inCoeffDomain |
| 309 | if( A.degree() > B.degree() ) |
| 310 | { |
| 311 | P = A; result = B; |
| 312 | } |
| 313 | else |
| 314 | { |
| 315 | P = B; result = A; |
| 316 | } |
| 317 | CanonicalForm inv; |
| 318 | if( result.isZero() ) |
| 319 | { |
| 320 | tryInvert( Lc(P), M, inv, fail ); |
| 321 | if(fail) |
| 322 | return; |
| 323 | result = inv*P; // monify result (not reduced, yet) |
| 324 | result= reduce (result, M); |
| 325 | return; |
| 326 | } |
| 327 | Variable x = P.mvar(); |
| 328 | CanonicalForm rem, Q; |
| 329 | // here: degree(P) >= degree(result) |
| 330 | while(true) |
| 331 | { |
| 332 | tryDivrem (P, result, Q, rem, inv, M, fail); |
| 333 | if (fail) |
| 334 | return; |
| 335 | if( rem.isZero() ) |
| 336 | { |
| 337 | result *= inv; |
| 338 | result= reduce (result, M); |
| 339 | return; |
| 340 | } |
| 341 | if(result.degree(x) >= rem.degree(x)) |
| 342 | { |
| 343 | P = result; |
| 344 | result = rem; |
| 345 | } |
| 346 | else |
no test coverage detected