PEP239 (Rational Numbers) Reference Implementation and new issues

James J. Besemer jb at cascade-sys.com
Thu Oct 3 09:35:55 EDT 2002


François Pinard wrote:

>On the other hand, [...]
>On average, most programs will not use matrices of rational numbers,
>nor play with series.  Moreover, most programs do not use so many different
>numeric variables anyway, nor perform long computations involving them.
>Many programs do not go beyond adding or subtracting one, once in a while!
>
I think this is an excellent point.  The prospective active user base 
for rationals, at least initially, is a small subset of the user base.  

Most people who propose to do much numerical computation often encounter 
performance issues and in any case are quickly referred to Numerics 
rather than Python intrinsics.  Most courses in "Numerical Analysis" 
assume floating point arithmetic and include chapters on minimizing loss 
of precision.

However more "accurate" Rationals may be in a mathematical sense they 
really are a novelty to the majority of computer users and programming 
environments.   While I support their addition to the language I don't 
see that they'd be something I or the majority of users would use on a 
routine basis.  Like Complex numbers, rationals just don't apply to a 
large portion of programming applications.

I certainly think it would be much more confusing for Newbies to find 
rational objects showing up and possibly slowing their computation when 
they least expect it.

Guido is right that rationals should be off to the side a bit and not 
show up in any computations unless expressly introduced by the user.  

I think complex numbers are a good model -- naive users can pretty much 
ignore their presence altogether and not get into trouble.

>So it might be more
>worth accepting as a community to warn programmers who are more prone to
>numerical algorithms of the intrinsic dangers of integer division in Python.
>

I personally think the "dangers" of integer division have been vastly 
exaggerated.  Integer division is older than computers and it's really a 
trivial concept.  The answer cannot be represented accurately so instead 
you get an approximation.  Furthermore, integer division and integer 
modulo together DO produce a complete and exact answer -- a whole number 
quotient and a remainder.  In my experience, when dealing with integers, 
the original integer division result (and the modulo) is more useful in 
practice than the "more accurate" floating point result.  

That decision is water over the bridge.  But substituting a rational for 
the present floating point result would only be more confusing.

Regards

--jb

-- 
James J. Besemer		503-280-0838 voice
2727 NE Skidmore St.		503-280-0375 fax
Portland, Oregon 97211-6557	mailto:jb at cascade-sys.com
				http://cascade-sys.com	








More information about the Python-list mailing list