mpz_invert returns wrong result
Benjamin Eltzner
b.eltzner at gmx.de
Sat Apr 12 23:12:29 UTC 2014
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
>> * The return value of mpz_invert is wrongly different from 0,
>> when the inverse cannot be calculated (cf. documentation, section
>> 5.9). In the example, the modulus by 1 yields 0, which cannot be
>> inverted. Thus, the result should be 0 but is 1.
>
> https://gmplib.org/gmp6.0.html
>
> First item of the changes in 6.0.0:
>
> * The function mpz_invert now considers any number invertible in
> Z/1Z.
>
> (because 0 * x == 1 modulo 1 whatever x)
Sorry for not parsing that. Still the current behavior contradicts the
documentation
(https://gmplib.org/manual/Number-Theoretic-Functions.html#Number-Theoretic-Functions):
"If the inverse exists, the return value is non-zero and rop will
satisfy 0 < rop < abs(op2)."
In the example code I sent, rop = 0 but if I understand your reasoning
correctly, it should be 1.
Also I would like to add, that "taking mod 1" constitutes a mapping to
the zero ring, the only ring with only one element, such that 0=1. In
a case where "everything is 0" AND "everything is 1" it seems very
strange to me to prefer 1. Not only to me: the generally accepted
convention is "n mod 1 = 0" and I do not think it is a good idea to go
differently on this.
Best regards, Benjamin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Icedove - http://www.enigmail.net/
iQIcBAEBAgAGBQJTSchMAAoJEK27BRz67lmpJmMP/iQtcPmsKcwlhj3Nf4IAuyRg
ZAwB95ornYNe/fgUCLMgmLZtXvYjrd75+Z76Feh4Qlr8etpeYIqYKrGW7Q3axAXh
uPLRKogB1eQqi+OSerDN5Aeo4dRIBzhZN9v9gN4T+euEVzc4+dQ42hBvqRZfuMxe
plbzH+YeyZO6feRpdpxfmArf7tXScACnsbnx4XbYiiTrAEML/kSaOK3JFtz9218m
uFj3lUXZwMAMMlh1xz6fEH2X1zE8cl041rnlmANUAGEFP8nacqaopvR8a4vaKJlo
4svJAX60QumtBeBo3jpjolo4f6J1JZNWaRBPevKKsS0C9AKDgdH1m/TETFY7yC+e
OAQID2tXBEakCbMBdz+lUhvVhoJylfIRpFg5dfFbScL7GFgQHLOF65VL1PJWJT/n
yXC/o4UC7VZPi6Rn+MZF4iAN2264Fup8IDx8xxIjy4NIyla8bxmo5QOPibph9H4h
ryelLvKEuYlk9bq9+MaPxSfAdkewLhMSdmTFGHBfwEYGfjbgLnduR957L0zqpLcd
9lDfhaHkcan0WiVrHF5fR4DHAXW3GicJrnOogINFIa8YdExH7juvygJHZaeOSHJ3
C+7BW9gI/riQCfQ+4C3fXSVqP/eJLqn/7LqbkMW/8ELF0U6fR2GJ44itMlQsLyWT
YbtBehrVMlCjRYKKGau4
=Iei4
-----END PGP SIGNATURE-----
More information about the gmp-bugs
mailing list