# [Python-Dev] Revamping Python's Numeric Model

M.-A. Lemburg mal@lemburg.com
Sat, 04 Nov 2000 11:31:01 +0100

```Moshe Zadka wrote:
>
> > While I like the idea of having the numeric model in Python
> > based on a solid class hierarchy, I don't think that this model
> > is implementable in Python 2.x without giving away performance.
>
> I think they are, using a similar trick to Fred's automorphing dictionaries.

You mean numbers "morph" to become floats, complex numbers, etc.
on demand ? E.g. math.sqrt(-1) would return 1j ?!

> > +1.
> >
> > I would like to see methods on Python numbers too (after having
> > made some really good experiences with methods on strings ;-).
> > There's one problem though: how would you call these on
> > numeric literals ? ... 1.2.isreal() ?!
>
> Ummmm....how would you say you want to add 3 and 4, and multiply the result
> by 5? 3+4*5?
>
> No, you use parens:
>
> (3+4)*5
> (1.2).isreal()

Ah. Of course :-) Cool !

> > >     a. isexact()
> > >
> > >     Obviously, a number which answers m as true, also answers m+k as true.
> > >     If "isexact()" is not true, then any answer might be wrong. (But not
> > >     horribly wrong: it's close the truth).
> >
> > Not sure what you mean here: perhaps .isexact() <=> can be
> > represented in IEEE ?
>
> No, I meant "not represented exactly". The real meaning for that (one
> that we might or might not promise) is that it's a float. It's a place
> where the numeric model takes the easy way out <wink>.

Uhm, that's what I meant. I don't see much use for this though:
the whole meaning of "exact" is void w/r to floats. It should
be replaced by "accurate to n digits".

Note that there is a whole mathematical theory that tries to
deal with this problem: interval calculus. A package to support
this would probably make sense... a nice side-effect of
interval calculus is that it allows "automatic" optimization
of functions within certain bounds. Numbers are replaced with
intervals and calculus is then done on the interval bounds.

This is just about as close as you can get to floating point
values with computer machinery ;-)

--
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/

```