[Tutor] math question

Tim Peters tim.one at comcast.net
Fri Apr 23 12:55:00 EDT 2004


[Chris Lott]
> I understand and I don't understand. I've read that section in the
> tutorial. I understand that the sqrt(2) can't be written as an exact
> value. But the sqrt(2)^2 certainly can be written in an exact value.

Suppose you had a decimal hand calculator, with 3 digits of precision.  If
you computed sqrt(2) on that, you would get

   1.41

This is an approximation to the square root of 2, but is the best
approximation the calculator is capable of giving you.  If you go on to
square 1.41, the exact result is 1.9881.  But, again, since your calculator
has only 3 digits of precision, the best possible approximation it can give
you to 1.9881 is 1.99.

So, in all, on that calculator the result of sqrt(2)**2 will be 1.99 -- and
all assuming it's giving the best possible approximation at every step.  You
lose information at each step, and the more steps there are the more that
information loss can compound.

Exactly the same kinds of things happen in binary floating-point arithmetic,
but they're harder to picture at first because people aren't accustomed to
using base 2.

Note that when you see "sqrt(2)**2" and think "ah, that must be 2!", you're
not doing arithmetic at all in your head:  you're doing symbolic algebra,
building on your knowledge about how the square root and square functions
relate to each other (as inverses).  If you were doing arithmetic on paper
instead, one operation at a time, you'd have exactly the same problem with
losing information at each step (unless you had enough spare time to write
down an infinite number of digits at each step <wink>).




More information about the Tutor mailing list