[Python-3000] Math in Python 3.0
Fredrik Johansson
fredrik.johansson at gmail.com
Thu May 11 22:07:46 CEST 2006
Hi all,
Some assorted thoughts:
Python's current numeric model has serious problems. It's fine for
calculating with nothing but floats, or nothing but ints, but writing
code that works for ints, floats, complexes *and* Decimals - let alone
for custom types such as mpfs or numeric arrays - is nearly
impossible. Duck typing doesn't work because these types all have
different interfaces, despite being functionally (or conceptually)
equivalent for many purposes.
Generic functions would solve most of the problem. I don't see this
example being brought up often (perhaps I've just missed those posts),
but I do think improved support for custom numeric types is a very
strong motivation for implementing generic functions in Python 3.0. If
operators could be overloaded as well (to define mpf()+Decimal(), say)
without creating wrapper classes, it'd be even better.
Are people still positive regarding the idea of merging decimal and
binary floats into the same type? (Or at least ensuring that they can
be mixed seamlessly, which should be no problem with decimal literals
added to the language.) Is someone currently working on a faster
implementation of Decimal? I'm occupied, but might be able to lend a
hand soon.
The issue of generally extending Python's default math library was
also brought up quite recently. I don't think incorporating half of
SciPy or nzmath would be a good idea at all, but there's certainly
room for more small utility functions. For example, isodd()/iseven()
would be extremely nice (how many times have you typed/read the
mind-numbing expression "n%2 == 0"?).
Anyone for PEP-writing? I can think of numerous small changes (and
ideas too insane to suggest publicly on this list); perhaps a wiki
page first?
Fredrik Johansson
More information about the Python-3000
mailing list