[Python-Dev] PEP239 (Rational Numbers) Reference Implementation and new issues

Ken Starks straton at lampsacos.demon.co.uk
Sun Oct 6 18:26:33 EDT 2002


In article <anibpv$bjr$1 at peabody.colorado.edu>, Fernando Pérez
<fperez528 at yahoo.com> quotes and writes
>
>> And what about rational 0/0?  Is that 1, or NaN (or Inf :-) )?
>
>NaN. This one isn't defined even as a limit. 

Forget the divide sign in 0/0 for a moment, and avoid the use of
the label `rational' which 0/0 certainly is not.

Consider the set of pairs of integers with an `equality'
defined by the relation:
(a,b)  '=' (c,d)
if and only if a*d == b*c

You can define addition and multiplication as for rationals
and you can define 'negative of' and 'reciprocal of' a value,
and start to build up an arithmetic.

You can also do this in Python, and I once did, using long
integers. It was an enjoyable exercise in overloading
some of the standard Python Operators. By the way, I found
it useful to cancel them to their lowest terms, with a
non-negative 'denominator'.

Whether you are a Mathematician or not, you may enjoy
finding out where this system fails to obey the demands
of a 'proper' system of numbers.

-- 
Ken Starks



More information about the Python-list mailing list