Python math is off by .000000000000045

Devin Jeanpierre jeanpierreda at
Sat Feb 25 21:49:59 EST 2012

On Sat, Feb 25, 2012 at 2:08 PM, Tim Wintle <tim.wintle at> wrote:
> > It seems to me that there  are a great many real numbers that can be
> > represented exactly by floating point numbers.  The number 1 is an
> > example.
> >
> > I suppose that if you divide that count by the infinite count of all
> > real numbers, you could argue that the result is 0%.
> It's not just an argument - it's mathematically correct.

^ this

The floating point numbers are a finite set. Any infinite set, even
the rationals, is too big to have "many" floats relative to the whole,
as in the percentage sense.


In fact, any number we can reasonably deal with must have some finite
representation, even if the decimal expansion has an infinite number
of digits. We can work with pi, for example, because there are
algorithms that can enumerate all the digits up to some precision. But
we can't really work with a number for which no algorithm can
enumerate the digits, and for which there are infinitely many digits.
Most (in some sense involving infinities, which is to say, one that is
not really intuitive) of the real numbers cannot in any way or form be
represented in a finite amount of space, so most of them can't be
worked on by computers. They only exist in any sense because it's
convenient to pretend they exist for mathematical purposes, not for
computational purposes.

What this boils down to is to say that, basically by definition, the
set of numbers representable in some finite number of binary digits is
countable (just count up in binary value). But the whole of the real
numbers are uncountable. The hard part is then accepting that some
countable thing is 0% of an uncountable superset. I don't really know
of any "proof" of that latter thing, it's something I've accepted
axiomatically and then worked out backwards from there. But surely
it's obvious, somehow, that the set of finite strings is tiny compared
to the set of infinite strings? If we look at binary strings,
representing numbers, the reals could be encoded as the union of the
two, and by far most of them would be infinite.

Anyway, all that aside, the real numbers are kind of dumb.

-- Devin

More information about the Python-list mailing list