A perfect power, and then?

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Wed Oct 24 16:39:18 CEST 2012


Ciao,

Il Mer, 24 Ottobre 2012 9:20 am, Niels ha scritto:
> I see. What do you think of the interface
>
>      mp_bitcnt_t mpz_perfect_root (mpz_t root, const mpz_t x);

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.

> We can allow root == NULL, for callers who don't care about the root.

I agree.

> Return value can then be defined as:

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.

Regards,
m

-- 
http://bodrato.it/papers/



More information about the gmp-devel mailing list