[Python-Dev] PEP239 (Rational Numbers) Reference Implementation and new issues
Andrew Koenig
ark@research.att.com
Wed, 2 Oct 2002 21:10:52 -0400 (EDT)
Guido> [Andrew Koenig]
>> Much as I like APL, I'd rather use Scheme's numeric model.
Guido> I've heard that before, but I've also heard criticism of
Guido> Scheme's numeric model. "It works in Scheme" doesn't give me
Guido> the warm fuzzy feeling that it's been tried in real life.
...and "It works in APL" does?
More seriously, there aren't that many languages with
infinite-precision rationals, which means there aren't
all that many precedents.
I find the partial ordering among Python's types interesting.
If we use "<" to mean "is a strict subset of", then
int < long < rational (except perhaps on machines with 64-bit int,
which opens a different can of worms entirely)
int < float < rational
float < complex
Excluding complex, then, adding rational to the numeric types makes
the numeric types a lattice. We could make all of the numeric types
a lattice by adding a "complex rational" type:
complex rational
| \___
| \
rational complex
/ \ ____/
/ \ /
long float
\ __/
\ /
\ /
int
What's nice about a lattice is that for any two types T1 and T2, there
is a unique minimum type T of which T1 and T2 are both subsets (not
necessarily proper subsets, because T1 could be a subset of T2 or vice
versa).