| 340 | } |
| 341 | |
| 342 | CanonicalForm |
| 343 | primitiveElement (const Variable& alpha, Variable& beta, bool& fail) |
| 344 | { |
| 345 | bool primitive= false; |
| 346 | fail= false; |
| 347 | primitive= isPrimitive (alpha, fail); |
| 348 | if (fail) |
| 349 | return 0; |
| 350 | if (primitive) |
| 351 | { |
| 352 | beta= alpha; |
| 353 | return alpha; |
| 354 | } |
| 355 | CanonicalForm mipo= getMipo (alpha); |
| 356 | int d= degree (mipo); |
| 357 | int p= getCharacteristic (); |
| 358 | #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20503) |
| 359 | nmod_poly_t FLINT_mipo; |
| 360 | nmod_poly_init(FLINT_mipo,p); |
| 361 | #elif defined(HAVE_NTL) |
| 362 | if (fac_NTL_char != p) |
| 363 | { |
| 364 | fac_NTL_char= p; |
| 365 | zz_p::init (p); |
| 366 | } |
| 367 | zz_pX NTL_mipo; |
| 368 | #else |
| 369 | factoryError("NTL/FLINT missing: primitiveElement"); |
| 370 | return CanonicalForm(0); |
| 371 | #endif |
| 372 | CanonicalForm mipo2; |
| 373 | primitive= false; |
| 374 | fail= false; |
| 375 | bool initialized= false; |
| 376 | do |
| 377 | { |
| 378 | #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20503) |
| 379 | nmod_poly_randtest_monic_irreducible(FLINT_mipo, FLINTrandom, d+1); |
| 380 | mipo2=convertnmod_poly_t2FacCF(FLINT_mipo,Variable(1)); |
| 381 | #elif defined(HAVE_NTL) |
| 382 | BuildIrred (NTL_mipo, d); |
| 383 | mipo2= convertNTLzzpX2CF (NTL_mipo, Variable (1)); |
| 384 | #endif |
| 385 | if (!initialized) |
| 386 | beta= rootOf (mipo2); |
| 387 | else |
| 388 | setMipo (beta, mipo2); |
| 389 | primitive= isPrimitive (beta, fail); |
| 390 | if (primitive) |
| 391 | break; |
| 392 | if (fail) |
| 393 | return 0; |
| 394 | } while (1); |
| 395 | #if defined(HAVE_FLINT) && (__FLINT_RELEASE >= 20503) |
| 396 | nmod_poly_clear(FLINT_mipo); |
| 397 | // convert alpha_mipo |
| 398 | nmod_poly_t alpha_mipo; |
| 399 | convertFacCF2nmod_poly_t(alpha_mipo,mipo); |
no test coverage detected