# [Tutor] math question

orbitz at ezabel.com orbitz at ezabel.com
Fri Apr 23 12:26:02 EDT 2004

```Python does what you tell it.  sqrt(2)^2, take the square root of 2, which is am
aproximation, then multiply it by itself, which is still an aproximation.
Python isn't a symbolic computer, it isn't meant to guess that "oh, you want to
square what i just took the square root of, that is itself then".  but since
python is a programming language, you can certinaly do that on your own.

On Fri, 23 Apr 2004 07:53:03 -0800
Chris Lott <chris at chrislott.org> wrote:

> Karl Pflästerer wrote:
>
> > Here are several problems:
> > (a) sqrt(2) can't be written as exact value (neither base 10 nor base
> >     2).  So Python uses a floating point approximation
> > (b) you see the internal representation of the numbers (repr())
> > (c) most floating point numbers can't be represented exactly in the way
> >     Python stores them
> >
> > A very good explanation of the problems with floating point numbers can
> > be found in the Python tutorial in the official documentation.  You
> >
> > A simple example from it which shows the problem:
>
> 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. It
> seems strange to me (I'm no mathematician and I suspect this is a
> philosophy question rather than a Python question) that the language
> can't figure this out-- similarly, if I add up 1/3 + 1/3 + 1/3 there is
> no reason (to my layperson's mind) that it doesn't come out to 1,
> regardless of the individual values. I guess it seems like something
> should see the code and know a difference between adding .33 + .33 +
> .333 and 1/3 + 1/3 + 1/3
>
> I can't conceive of why it would *matter* in anything I do, but I had a
> hard time explaining to my daughter when I was helping her with a
> math/geometry problem and showed her how to use the Python shell as a
> kind of calculator and was demonstrating to her and got 2.000000004 here :)
>
> c
> --
> Chris Lott
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

```