[issue37893] pow() should disallow inverse when modulus is +-1

Tim Peters report at bugs.python.org
Tue Aug 20 20:16:22 EDT 2019


Tim Peters <tim at python.org> added the comment:

I don't have a problem with the trivial ring - I wasn't being that high-minded ;-)  I was testing a different inverse algorithm, and in the absence of errors checked that

    minv(a, m) * a % m == 1

for various a and m >= 0.  Of course that failed using pow(a, -1, m) instead when m=1.  Offhand, I couldn't imagine a plausible use case for finding an inverse mod 1 - and still can't ;-)  In abstract algebra, sure - but for concrete numerical computation?  Oh well.

In any case, testing

    (minv(a, m) * a - 1) % m == 0

instead appears to work for all non-error cases.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37893>
_______________________________________


More information about the Python-bugs-list mailing list