[Python-Dev] re: division

Tim Peters tim_one@email.msn.com
Wed, 5 Apr 2000 23:10:35 -0400


[Moshe]
> FWIW, I think Python should support Rationals, and have integer division
> return a rational. I'm still working on the details of my great Python
> numeric tower change.

[Guido]
> Forget it.  ABC did this, and the problem is that where you *think*
> you are doing something simple like calculating interest rates, you
> are actually manipulating rational numbers with 1000s of digits in
> their numerator and denumerator.

Let's not be too hasty about this, cuz I doubt we'll get to change it twice
<wink>.  You (Guido) & I agreed that ABC's rationals didn't work out well
way back when, but

a) That has not been my experience in other languages -- ABC was unique.
b) Presumably ABC did usability studies that concluded rationals were
   least surprising.
c) TeachScheme! seems delighted with their use of rationals (indeed,
   one of TeachScheme!'s primary authors beat up on me in email for Python
   not doing this).
d) I'd much rather saddle newbies with time & space surprises than
   correctness surprises.

Last week I took some time to stare at the ABC manual again, & suspect I hit
on the cause:  ABC was *aggressively* rational.  That is, ABC had no
notation for floating point (ABC "approximate") literals; even 6.02e23 was
taken to mean "exact rational".  In my experience ABC was unique this way,
and uniquely surprising for it:  it's hard to be surprised by 2/3 returning
a rational, but hard not to be surprised by 6.02e23/1.0001e-18 doing so.

Give it some thought.

> If you want to change it, consider emulating what kids currently use
> in school: a decimal floating point calculator with N digits of
> precision.

This is what REXX does, and is very powerful even for experts (assuming the
user can, as in REXX, specify N; but that means writing a whole slew of
arbitrary-precision math libraries too -- btw, that is doable! e.g., I
worked w/ Dave Gillespie on some of the algorithms for his amazing Emacs
calc).  It will run at best 10x slower than native fp of comparable
precision, though, so experts will hate it in the cases they don't love it
<0.5 wink>.

one-case-where-one-size-doesn't-fit-anyone-ly y'rs  - tim