A perfect power, and then?

Niels Möller nisse at lysator.liu.se
Wed Oct 24 20:47:47 CEST 2012


bodrato at mail.dm.unipi.it writes:

> I propose
>  mp_bitcnt_t mpz_perfect_root (mpz_t root, const mpz_t x, mp_bitcnt_t nth);
>
> If nth != 0, check if x is a perfect nth-root (generalize perfect_square).
> If nth == 0, search for a non-trivial relation root^e = x, and return e.

Both variants make sense, but I'm not sure they should be the same
function.

> To be coherent, the return value e should always be the exponent, such
> that root^e = x. I.e. when only the trivial equation x^1 = x exists,
> return 1 and set root=x.
>
> I'm not sure I'd vote for coherence in this particular case.

I think it's desirable that mpz_perfect_power_p can be re-implemented by
a call to new new function followed by a very simple check on the return
value. Then we need distinct return values for the case |x| <= 1 (which
are considered perfect powers) and non-powers. Using 1 for the former
and 0 for the latter seems like a reasonable choice to me.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list