[issue35606] Add prod() function to the math module

Tim Peters report at bugs.python.org
Sun Jan 6 01:26:58 EST 2019


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

I'd like to divorce `prod()` from floating-point complications.  The `sum()` builtin has proved extremely handy, even for floats, in large part because it's type-agnostic and straightforward.  While I'd usually use `prod()` on ints and Fractions, in almost all cases I have for multiplying floats a dirt simple implementation would work fine too (e.g., I don't multiply NaNs or infinities to begin with, overflow and underflow can't occur in context, and I usually couldn't care less about the accuracy of the trailing bits).

Not that floats should suffer benign neglect forever, but heroically complex - and expensive - float implementations should get their own function, like `fprod()` (like they got their own `fsum()` function).  Likewise if, e.g., someone wants an `iprod()` that makes heroic efforts to reorder partial products to speed multiplying sequences of giant integers, or `matprod()` to re-associate matrix multiplications in an optimal way, or ...

----------

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


More information about the Python-bugs-list mailing list