[issue39657] Bezout and Chinese Remainder Theorem in the Standard Library?

Tim Peters report at bugs.python.org
Sun Feb 23 14:44:10 EST 2020


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

Ya, I'll close this, channeling that Raymond would also reject it for now (although he's certainly free to reopen it).

There's nothing wrong with adding such functions, but the `math` module is already straying too far from its original intent as a home for floating-point functions, nearly all of which had counterparts in `cmath`.  _If_ we had a, say, `imath` module, it would be a much easier sell.

These are just "too specialized".  I'd put them in the same class as, say, a new function to compute the Jacobi symbol.  Very handy but only for a vanishingly small percentage of Python users.

Probably _the_ most common use for xgcd (or egcd, either of which I suggest are better names than `bezout` - "extended gcd" is descriptive and commonly used) is for finding modular inverses, but `pow()` does that now directly.

For Chinese remainder, I'd suggest two changes:

1. Generalize to any number of bases.  The 2-base case is common in toy RSA implementations, but in that context a more efficient way is generally used, based on precomputing "helper constants" specific to the modulus's 2 factors.

2. Since the same bases are generally used over & over while only the remainders change, the function signature would be more usable if it accepted a sequence of remainders, and a sequence of corresponding bases, as two distinct arguments.

----------
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list