mpz_invert inconsistency

Max Horn Max.Horn at
Thu Sep 18 10:36:26 UTC 2014


in GMP 6.0.0, the behavior of mpz_invert was changed (see also Now it treats any number in Z/1Z as invertible. Makes sense from a mathematical point of view, too.

Unfortunately, this clashes with the documentation of mpz_invert (taken from [1]) which states:

— Function: int mpz_invert (mpz_t rop, const mpz_t op1, const mpz_t op2)

Compute the inverse of op1 modulo op2 and put the result in rop. If the
inverse exists, the return value is non-zero and rop will satisfy 0 < rop <
abs(op2). If an inverse doesn't exist the return value is zero and rop is
undefined. The behaviour of this function is undefined when op2 is zero.

So according to the GMP 6.0 news item, for op2 = 1, every input op1 is
treated as invertible, hence mpz_invert returns 0. But in that case the
output specification 0 < rop < abs(op2) = 1 cannot be satisfied. Indeed, rop
seems to be set to 0 (which indeed is the "correct" thing to do), which is
of course not larger than 0...

This should be clarified in the documentation. Perhaps something like this:

"[...] the return value is non-zero and rop will satisfy 0 <= rop <
abs(op2). Note that rop = 0 occurs if and only if op2 is 1 or -1 (in this case,
every element op1 is invertible with inverse 0). [...]"


Prof. Dr. Max Horn
AG Algebra
Mathematisches Institut
Justus-Liebig-Universität Gießen
Arndtstraße 2
D-35392 Gießen
Tel: (+49) 641 99-32044
Fax: (+49) 641 99-32049
Email: max.horn at

More information about the gmp-bugs mailing list