This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lschoe
Recipients josh.r, lschoe, rhettinger
Date 2019-02-15.08:26:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1550219172.47.0.204498578791.issue35996@roundup.psfhosted.org>
In-reply-to
Content
I had the same reservations but after rethinking it several times concluded that the modulus argument would fit really well.

Indeed, Mathematica doesn't support the Modulus option for the Product[] function. But they don't even support it for the Power[] function, one needs to use PowerMod[] for that. 

Python has the extra option for its built-in pow(), and sensibly restricts this to the case of integer arguments only. 

To do modular arithmetic, even with big numbers, in Python is really nice and easy using the % operator. And it's all pretty efficient as well. The only exception where efficiency becomes an issue is the pow() function.

To maintain that balance with the new prod() function around, the modulus argument would do the job. We can continue to do all modular arithmetic in a natural way, yielding programs that are perfectly readable and with very decent performance, now with prod() in the language as well.

Taking larger modular products is a common thing to do in modern crypto, and Python is a popular platform for this. Next to the example of prod_i g[i]**s[i] mod z, which is like a Pedersen multi-commitment, it also arises when computing Lagrange coefficients (used in Shamir secret sharing) and related determinants for Vandermonde matrices.

One would also be able to things like prod(range(1, n), n) == n - 1 for Wilson's primality test. (Extending the factorial() function with a modulus argument would be taking things too far, probably, but the modular version would now be available anyway via prod().)

So, my feeling is that there are sufficiently many use cases around. And, I'm kind of assuming that it's not too much effort to add a modulus argument to prod(), but maybe that's not really the case.
History
Date User Action Args
2019-02-15 08:26:12lschoesetrecipients: + lschoe, rhettinger, josh.r
2019-02-15 08:26:12lschoesetmessageid: <1550219172.47.0.204498578791.issue35996@roundup.psfhosted.org>
2019-02-15 08:26:12lschoelinkissue35996 messages
2019-02-15 08:26:12lschoecreate