Python3k extended grammar

Moshe Zadka moshez at
Sat May 20 21:57:42 CEST 2000

On 20 May 2000, Tres Seaver wrote:

> >Seems sane to you? Where were you when they taught about fractions in math
> >class? The only thing which looks sane to me is 1/2 is 1/2. And 1/3. And
> >367/573. 
> This change will break *huge* volumes of code, in the name of the "E" in
> CP4E.

Well, this specific change has more merit, IMHO: it would give Python an
*honest* numerical model, rather then C's CPU-tied numerical model.

> Again, it seems primarily motivated by the Alice project's creator,
> and would be better addressed in tools than the language.

The horrid 1/2 == 0.5 is by Randy, and I'm firmly against it: I'm afraid
Randy's studies didn't take into account people actually *doing* things
with floats.

> After all, elementary maths *don't* teach that "1/3" is 0.33333333 (or
> whatever 754 gives as the roundoff) -- floating point representations of
> rational numbers are subject to as many (or more!) gotchas as integer
> math, which is at least comprehensible to anybody who knows the terms
> "quotient" and "remainder").

Did you see me *anywhere* preaching that 1/2 == 0.5? I said that 1/2
should be 1/2, and 1/3 is 1/3. Here's a sketch of a numerical tower,
with a bit more work to bring complex numbers here:

exact integers -- internally represented by Python integers and Python
exact rationals -- internally represented by numerator denominator pairs, 
                   which are exact integers
inexact rationals -- internally represented by Python floats

Any operation can only go "down" the tower, and *should* only go down as
much as it needs to: 1/2 should go only one step down the tower, while
sqrt(2) would go down two levels.

Complex numbers: any number is complex. The two parts are real number,
each is one of the earlier classes. It is permissible that they always be
of the same level, so that 

(1+2j) + (0.1) ==> 1.1 + 2.0j

Special rule:
The are some functions which go "up" the tower: numerator/denominator
climb from rationals to integers, and round() climbs from floats to
integers. The function real() and imag() go from complexes to reals.

More information about the Python-list mailing list