Math errors in python

Alex Martelli aleaxit at yahoo.com
Sun Sep 19 18:33:17 EDT 2004


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

> aleaxit at yahoo.com (Alex Martelli) writes:
> > Yes, but applying rational arithmetic by default might slow some
> > computations far too much for beginners' liking!
> 
> I dunno, lots of Lisp dialects do rational arithmetic by default.

And...?  What fractions of beginners get exposed to Lisp as their first
language just love the resulting precision/speed tradeoff...?  I think
Paul Graham's "Worse is Better" article applies quite well here...


> > Well, you can pretty easily use constructive reals with Python, see for
> > example <http://more.btexact.com/people/briggsk2/XR.html> -- that's a
> > vastly vaster set than just algebraic numbers.  If we DO want precision,
> > after all, why should sqrt(5) be more important than log(3)?
> 
> I don't know that it's generally tractable to do exact computation on
> constructive reals.  How do you implement comparison (<, >, ==)?

Well, if you can generate decimal representations on demand (and you'd
better, as the user might ask for such output at any time with any
a-priori unpredictable number of digits), worst case you can compare
them lexicographically, one digit at a time, until you find a different
digit (assuming identical signs and integer parts) -- except that equal
numbers would not terminate by this procedure.  Briggs' implementation
finesses the issue by comparing no more than k significant digits, 1000
by default;-)


Alex



More information about the Python-list mailing list