From: Emre Sevinc
Subject: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <8764purxyg.fsf@ileriseviye.org>
Probably you've already heard Google's failure to calculate:

1 - 0.9 - 0.1

http://www.google.com/search?q=1+-+0.9+-+0.1

When I ask the question to SBCL (on Debian GNU/Linux):

CL-USER> (- (- 1 0.9) 0.1)
2.2351742e-8

CL-USER> (- (- 1 9/10) 1/10)
0

Not very surprising I guess.

The same question, this time MIT Scheme running on
Debian GNU/Linux:

1 ]=> (- (- 1 0.9) 0.1)

;Value: -2.7755575615628914e-17

1 ]=> (- (- 1 9/10) 1/10)

;Value: 0


Similar answers. Finally I have tried Dr.Scheme on an
MS Windows 2000 system:


> (- (- 1 0.9) 0.1)
0

> (- (- 1 9/10) 1/10)
0

Now, that surprised me! Any explanations?

-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr

From: ·········@gmail.com
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <1134411819.607240.80310@g49g2000cwa.googlegroups.com>
google for floating point and rounding error, while you are at it
From: Mert YILMAZ
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <1134415702.433680.294720@g44g2000cwa.googlegroups.com>
            Actually I tried to do this in my Scheme run in Debian, and
the result is "zero".. I guess that this may be about the teachpacks or
versions we are using, I am using MrED Pretty Big (maybe it's not about
that but I use draw.ss teachpack). But it's surprising anyway that
Scheme doesn't calculate it in all versions..
From: Emre Sevinc
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <87slsyqez6.fsf@ileriseviye.org>
>>>>> "MY" == Mert YILMAZ <··············@gmail.com> writes:

    MY>             Actually I tried to do this in my Scheme run in
    MY> Debian, and the result is "zero".. I guess that this may be
    MY> about the teachpacks or versions we are using, I am using MrED
    MY> Pretty Big (maybe it's not about that but I use draw.ss
    MY> teachpack). But it's surprising anyway that Scheme doesn't
    MY> calculate it in all versions..

Talking about Debian GNU/Linux, I just wondered and tried
some other programs (e.g. dc and Octave produced the same error)
and bc produced this:

 ··@debian:~$ echo "1 - 0.9 - 0.1" | bc
 0

I didn't examine in detail how bc handled this, but
I was surprised again (today is my surprise day I guess).


-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr
From: matteo d'addio 81
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <1134417568.554984.20540@f14g2000cwb.googlegroups.com>
Emre Sevinc ha scritto:

> >>>>> "MY" == Mert YILMAZ <··············@gmail.com> writes:
>
>     MY>             Actually I tried to do this in my Scheme run in
>     MY> Debian, and the result is "zero".. I guess that this may be
>     MY> about the teachpacks or versions we are using, I am using MrED
>     MY> Pretty Big (maybe it's not about that but I use draw.ss
>     MY> teachpack). But it's surprising anyway that Scheme doesn't
>     MY> calculate it in all versions..
>
> Talking about Debian GNU/Linux, I just wondered and tried
> some other programs (e.g. dc and Octave produced the same error)
> and bc produced this:
>
>  ··@debian:~$ echo "1 - 0.9 - 0.1" | bc
>  0
>
> I didn't examine in detail how bc handled this, but
> I was surprised again (today is my surprise day I guess).
>

SISC handles it correctly. It handles precision in a special way.

matteo

>
> --
> Emre Sevinc
>
> eMBA Software Developer         Actively engaged in:
> http:www.bilgi.edu.tr           http://ileriseviye.org
> http://www.bilgi.edu.tr         http://fazlamesai.net
> Cognitive Science Student       http://cazci.com
> http://www.cogsci.boun.edu.tr
From: Ivan Boldyrev
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <0r8273-d07.ln1@ibhome.cgitftp.uiggm.nsc.ru>
On 9322 day of my life Emre Sevinc wrote:
> Talking about Debian GNU/Linux, I just wondered and tried
> some other programs (e.g. dc and Octave produced the same error)
> and bc produced this:
>
>  ··@debian:~$ echo "1 - 0.9 - 0.1" | bc
>  0

bc is "an arbitrary precision calculator language".  So, it uses exact
(ratio-like) arithmetics.

-- 
Ivan Boldyrev

                                                  Is 'morning' a gerund?
From: Pascal Bourguignon
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <87u0dc1v2l.fsf@thalassa.informatimago.com>
Ivan Boldyrev <···············@cgitftp.uiggm.nsc.ru> writes:

> On 9322 day of my life Emre Sevinc wrote:
>> Talking about Debian GNU/Linux, I just wondered and tried
>> some other programs (e.g. dc and Octave produced the same error)
>> and bc produced this:
>>
>>  ··@debian:~$ echo "1 - 0.9 - 0.1" | bc
>>  0
>
> bc is "an arbitrary precision calculator language".  So, it uses exact
> (ratio-like) arithmetics.

The important point of bc is that:

   All numbers are represented internally  in  decimal and all
   computation is done in decimal.


While with normal floating point, the internal representation is
binary, with binary exponents, therefore 0.1 CANNOT be represented
exactly.

And conversely, if the internal representation of floating point
numbers used base 10, then 1-0.9-0.1 would give the exact 0 result,
but  #3r1.0 - #3r0.2 - #3r0.1 wouldn't (if such a notation for base 3
decimal number existed in CL).



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
You're always typing.
Well, let's see you ignore my
sitting on your hands.
From: George Neuner
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <45vrp19d9soicrl8lh5kjhd9v14tehujtc@4ax.com>
On Mon, 12 Dec 2005 20:07:19 +0200, Emre Sevinc <·····@bilgi.edu.tr>
wrote:

>
>Probably you've already heard Google's failure to calculate:
>
>1 - 0.9 - 0.1
>
>http://www.google.com/search?q=1+-+0.9+-+0.1
>
>When I ask the question to SBCL (on Debian GNU/Linux):
>
>CL-USER> (- (- 1 0.9) 0.1)
>2.2351742e-8
>
>CL-USER> (- (- 1 9/10) 1/10)
>0
>
>Not very surprising I guess.
>
>The same question, this time MIT Scheme running on
>Debian GNU/Linux:
>
>1 ]=> (- (- 1 0.9) 0.1)
>
>;Value: -2.7755575615628914e-17
>
>1 ]=> (- (- 1 9/10) 1/10)
>
>;Value: 0
>
>Similar answers. Finally I have tried Dr.Scheme on an
>MS Windows 2000 system:
>
>> (- (- 1 0.9) 0.1)
>0
>
>> (- (- 1 9/10) 1/10)
>0
>
>Now, that surprised me! Any explanations?


Have you perhaps heard of floating point arithmetic?

David Goldberg wrote a good paper on the subject.
http://docs.sun.com/source/806-3568/ncg_goldberg.html

George
--
for email reply remove "/" from address
From: Jens Axel Søgaard
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <439dce86$0$38694$edfadb0f@dread12.news.tele.dk>
Emre Sevinc wrote:

> Similar answers. Finally I have tried Dr.Scheme on an
> MS Windows 2000 system:

>>(- (- 1 0.9) 0.1)
> 0

> Now, that surprised me! Any explanations?

You forgot to state which language, you used. From the
result, I assume yuo tried one of the teaching languages?


In the "Pretty Big Scheme" one gets:

   > (- (- 1 0.9) 0.1)
   -2.7755575615628914e-017

The explanation hinges on the paramter read-decimal-as-inexact:

   7.9.1.3  Parsing
   ...
   * (read-decimal-as-inexact [on?]) gets or sets a boolean value that
     controls parsing input numbers with a decimal point or exponent (but
     no explicit exactness tag). See section 11.2.5.1 for more
     information.

Indeed continuing in the same REPL as before:

   > (read-decimal-as-inexact #f)
   > (- (- 1 0.9) 0.1)
   0

-- 
Jens Axel S�gaard
From: Emre Sevinc
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <871x0irtv2.fsf@ileriseviye.org>
>>>>> "JAS" == Jens Axel S�gaard <······@soegaard.net> writes:

    JAS> Emre Sevinc wrote:
    >> Similar answers. Finally I have tried Dr.Scheme on an MS
    >> Windows 2000 system:

    >>> (- (- 1 0.9) 0.1)
    >> 0

    >> Now, that surprised me! Any explanations?

    JAS> You forgot to state which language, you used. From the
    JAS> result, I assume yuo tried one of the teaching languages?

Probably so (not the basic language, I think something advanced
but not the Pretty Big one), I don't remember exactly now, but I see your
point.



-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr
From: Paolo Amoroso
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <87zmn6glsp.fsf@plato.moon.paoloamoroso.it>
Emre Sevinc <·····@bilgi.edu.tr> writes:

> Probably you've already heard Google's failure to calculate:
>
> 1 - 0.9 - 0.1
>
> http://www.google.com/search?q=1+-+0.9+-+0.1
>
> When I ask the question to SBCL (on Debian GNU/Linux):
>
> CL-USER> (- (- 1 0.9) 0.1)
> 2.2351742e-8

You ask the wrong question :)

  CMU Common Lisp Snapshot 2005-11 (19C), running on plato
  With core: /usr/local/cmucl-2005-11/lib/cmucl/lib/lisp.core
  Dumped on: Fri, 2005-11-25 17:08:08+01:00 on plato
  See <http://www.cons.org/cmucl/> for support information.
  Loaded subsystems:
      Python 1.1, target Intel x86
      CLOS based on Gerd's PCL 2004/04/14 03:32:47
      Gray Streams Protocol Support
  * (- 1 9/10 1/10)

  0
  *


Paolo
-- 
Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
Recommended Common Lisp libraries/tools:
- ASDF/ASDF-INSTALL: system building/installation
- CL-PPCRE: regular expressions
- CFFI: Foreign Function Interface
From: Emre Sevinc
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <87oe3mqehl.fsf@ileriseviye.org>
>>>>> "PA" == Paolo Amoroso <·······@mclink.it> writes:

    PA> Emre Sevinc <·····@bilgi.edu.tr> writes:
    >> Probably you've already heard Google's failure to calculate:
    >> 
    >> 1 - 0.9 - 0.1
    >> 
    >> http://www.google.com/search?q=1+-+0.9+-+0.1
    >> 
    >> When I ask the question to SBCL (on Debian GNU/Linux):
    >> 
    CL-USER> (- (- 1 0.9) 0.1)
    >> 2.2351742e-8

    PA> You ask the wrong question :)

    PA>   CMU Common Lisp Snapshot 2005-11 (19C), running on plato
    PA> With core: /usr/local/cmucl-2005-11/lib/cmucl/lib/lisp.core
    PA> Dumped on: Fri, 2005-11-25 17:08:08+01:00 on plato See
    PA> <http://www.cons.org/cmucl/> for support information.  Loaded
    PA> subsystems: Python 1.1, target Intel x86 CLOS based on Gerd's
    PA> PCL 2004/04/14 03:32:47 Gray Streams Protocol Support * (- 1
    PA> 9/10 1/10)

    PA>   0 *

No NII please ;-)


NII: Natural Intelligence Intervention


-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr
From: Pascal Bourguignon
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <877jaa3ylw.fsf@thalassa.informatimago.com>
Emre Sevinc <·····@bilgi.edu.tr> writes:

> Probably you've already heard Google's failure to calculate:
>
> 1 - 0.9 - 0.1
>
> http://www.google.com/search?q=1+-+0.9+-+0.1
>
> When I ask the question to SBCL (on Debian GNU/Linux):
>
> CL-USER> (- (- 1 0.9) 0.1)
> 2.2351742e-8

You are not asking the right question!
The way to ask these kind of questions is:

(format t "~,1F" (- (- 1 0.9) 0.1))
0.0


> CL-USER> (- (- 1 9/10) 1/10)
> 0
>
> Not very surprising I guess.
> [...]
> Similar answers. Finally I have tried Dr.Scheme on an
> MS Windows 2000 system:
>
>
>> (- (- 1 0.9) 0.1)
> 0
>
>> (- (- 1 9/10) 1/10)
> 0
>
> Now, that surprised me! Any explanations?

DrScheme translates specifically your question as above.

This is unfortunate, since it prevents students to learn about
floating-point arithmetic.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
You're always typing.
Well, let's see you ignore my
sitting on your hands.
From: Emre Sevinc
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <87wtiaqf43.fsf@ileriseviye.org>
>>>>> "PB" == Pascal Bourguignon <····@mouse-potato.com> writes:

    PB> Emre Sevinc <·····@bilgi.edu.tr> writes:
    >> Probably you've already heard Google's failure to calculate:
    >> 
    >> 1 - 0.9 - 0.1
    >> 
    >> http://www.google.com/search?q=1+-+0.9+-+0.1
    >> 
    >> When I ask the question to SBCL (on Debian GNU/Linux):
    PB> You are not asking the right question!  The way to ask these
    PB> kind of questions is:

    PB> (format t "~,1F" (- (- 1 0.9) 0.1)) 0.0
    [..]

    PB> DrScheme translates specifically your question as above.
    PB> This is unfortunate, since it prevents students to learn about
    PB> floating-point arithmetic.

It made me think about which one is more pedagogical: creating
a false belief that the underlying system handles decimal fractions
perfectly, and then introducing the lesson of "welcome the wonderful world
of floating point arithmetic - be careful not to mess up badly"
or vice versa?

-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr
From: Eli Barzilay
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <m3ek4iytm2.fsf@winooski.ccs.neu.edu>
Emre Sevinc <·····@bilgi.edu.tr> writes:

> >>>>> "PB" == Pascal Bourguignon <····@mouse-potato.com> writes:
> 
>     PB> DrScheme translates specifically your question as above.
>     PB> This is unfortunate, since it prevents students to learn
>     PB> about floating-point arithmetic.

The target crowd of the teaching languages in DrScheme is people who
learn how to program.  Throwing in a concept like rounding errors is
not going to help much...


> It made me think about which one is more pedagogical: creating a
> false belief that the underlying system handles decimal fractions
> perfectly, and then introducing the lesson of "welcome the wonderful
> world of floating point arithmetic - be careful not to mess up
> badly" or vice versa?

It all depends on your expectations.  Digging back to the time I
learned how to program, I don't think that I expected an answer of
-2.7755575615628914e-17.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!
From: Pascal Bourguignon
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <873bky3uio.fsf@thalassa.informatimago.com>
Eli Barzilay <···@barzilay.org> writes:

> Emre Sevinc <·····@bilgi.edu.tr> writes:
>
>> >>>>> "PB" == Pascal Bourguignon <····@mouse-potato.com> writes:
>> 
>>     PB> DrScheme translates specifically your question as above.
>>     PB> This is unfortunate, since it prevents students to learn
>>     PB> about floating-point arithmetic.
>
> The target crowd of the teaching languages in DrScheme is people who
> learn how to program.  Throwing in a concept like rounding errors is
> not going to help much...

Actually, this should be taught in pre-scholar. 

People still believe blisslessly that all that comes out of the
computer is the Truth, and shutdown their own brains too often.


>> It made me think about which one is more pedagogical: creating a
>> false belief that the underlying system handles decimal fractions
>> perfectly, and then introducing the lesson of "welcome the wonderful
>> world of floating point arithmetic - be careful not to mess up
>> badly" or vice versa?
>
> It all depends on your expectations.  Digging back to the time I
> learned how to program, I don't think that I expected an answer of
> -2.7755575615628914e-17.
>
> -- 
>           ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                   http://www.barzilay.org/                 Maze is Life!

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Small brave carnivores
Kill pine cones and mosquitoes
Fear vacuum cleaner
From: Eli Barzilay
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <m364puyqi3.fsf@winooski.ccs.neu.edu>
Pascal Bourguignon <····@mouse-potato.com> writes:

> Eli Barzilay <···@barzilay.org> writes:
> 
> > Emre Sevinc <·····@bilgi.edu.tr> writes:
> >
> >> >>>>> "PB" == Pascal Bourguignon <····@mouse-potato.com> writes:
> >> 
> >>     PB> DrScheme translates specifically your question as above.
> >>     PB> This is unfortunate, since it prevents students to learn
> >>     PB> about floating-point arithmetic.
> >
> > The target crowd of the teaching languages in DrScheme is people
> > who learn how to program.  Throwing in a concept like rounding
> > errors is not going to help much...
> 
> Actually, this should be taught in pre-scholar. 
> 
> People still believe blisslessly that all that comes out of the
> computer is the Truth, and shutdown their own brains too often.

You're right -- it should be taught, but in a different context.

In the context of teaching people how to program, my experience is
that you can talk all you want about problems with floating point
representations -- you can also talk about infinite precision
representations, non-algebraic numbers, lazy streams, lambda calculus,
the Y combinator, life, and everything.  IME, they will look at you
and nod, but they will get nothing.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!
From: Pascal Bourguignon
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <87pso22ew4.fsf@thalassa.informatimago.com>
Eli Barzilay <···@barzilay.org> writes:

> Pascal Bourguignon <····@mouse-potato.com> writes:
>
>> Eli Barzilay <···@barzilay.org> writes:
>> 
>> > Emre Sevinc <·····@bilgi.edu.tr> writes:
>> >
>> >> >>>>> "PB" == Pascal Bourguignon <····@mouse-potato.com> writes:
>> >> 
>> >>     PB> DrScheme translates specifically your question as above.
>> >>     PB> This is unfortunate, since it prevents students to learn
>> >>     PB> about floating-point arithmetic.
>> >
>> > The target crowd of the teaching languages in DrScheme is people
>> > who learn how to program.  Throwing in a concept like rounding
>> > errors is not going to help much...
>> 
>> Actually, this should be taught in pre-scholar. 
>> 
>> People still believe blisslessly that all that comes out of the
>> computer is the Truth, and shutdown their own brains too often.
>
> You're right -- it should be taught, but in a different context.
>
> In the context of teaching people how to program, my experience is
> that you can talk all you want about problems with floating point
> representations -- you can also talk about infinite precision
> representations, non-algebraic numbers, lazy streams, lambda calculus,
> the Y combinator, life, and everything.  IME, they will look at you
> and nod, but they will get nothing.

Depends if you are dealing with packers who put everything in little
boxes, or mappers who can see the bigger picture.  And you want to
make little mappers, we need more mappers!


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

The world will now reboot.  don't bother saving your artefacts.
From: Eli Barzilay
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <m31x0iyodt.fsf@winooski.ccs.neu.edu>
Pascal Bourguignon <····@mouse-potato.com> writes:

> Eli Barzilay <···@barzilay.org> writes:
> 
> > In the context of teaching people how to program, my experience is
> > that you can talk all you want about problems with floating point
> > representations -- you can also talk about infinite precision
> > representations, non-algebraic numbers, lazy streams, lambda
> > calculus, the Y combinator, life, and everything.  IME, they will
> > look at you and nod, but they will get nothing.
> 
> Depends if you are dealing with packers who put everything in little
> boxes, or mappers who can see the bigger picture.  And you want to
> make little mappers, we need more mappers!

(People still believe blisslessly that dumping piles of information on
kids is the same as teaching.  I hear exactly the same thing when
people argue for C ("if everyting is a pointer, why not show them that
instead of hiding things?").

Good luck trying to get mappers this way -- but this is off topic so
I'll shut up now.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!
From: Barry Margolin
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <barmar-2F54C2.23595412122005@comcast.dca.giganews.com>
In article <··············@winooski.ccs.neu.edu>,
 Eli Barzilay <···@barzilay.org> wrote:

> Pascal Bourguignon <····@mouse-potato.com> writes:
> 
> > Eli Barzilay <···@barzilay.org> writes:
> > 
> > > Emre Sevinc <·····@bilgi.edu.tr> writes:
> > >
> > >> >>>>> "PB" == Pascal Bourguignon <····@mouse-potato.com> writes:
> > >> 
> > >>     PB> DrScheme translates specifically your question as above.
> > >>     PB> This is unfortunate, since it prevents students to learn
> > >>     PB> about floating-point arithmetic.
> > >
> > > The target crowd of the teaching languages in DrScheme is people
> > > who learn how to program.  Throwing in a concept like rounding
> > > errors is not going to help much...
> > 
> > Actually, this should be taught in pre-scholar. 
> > 
> > People still believe blisslessly that all that comes out of the
> > computer is the Truth, and shutdown their own brains too often.
> 
> You're right -- it should be taught, but in a different context.
> 
> In the context of teaching people how to program, my experience is
> that you can talk all you want about problems with floating point
> representations -- you can also talk about infinite precision
> representations, non-algebraic numbers, lazy streams, lambda calculus,
> the Y combinator, life, and everything.  IME, they will look at you
> and nod, but they will get nothing.

You don't have to get into all that detail, you just have to show a few 
examples that floating point is not exact.

I remember some beginning Fortran and BASIC textbooks that taught not to 
write loops like:

for i = 0 to 1 by .1

because of the round-off error.  They demonstrated this by putting a 
"print i" statement in the loop so you could see the errors accumulate.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Eli Barzilay
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <m3u0ddd0ze.fsf@winooski.ccs.neu.edu>
Barry Margolin <······@alum.mit.edu> writes:

> In article <··············@winooski.ccs.neu.edu>,
>  Eli Barzilay <···@barzilay.org> wrote:
> 
> > Pascal Bourguignon <····@mouse-potato.com> writes:
> > 
> > > Actually, this should be taught in pre-scholar. 
> > > 
> > > People still believe blisslessly that all that comes out of the
> > > computer is the Truth, and shutdown their own brains too often.
> > 
> > You're right -- it should be taught, but in a different context.
> > 
> > In the context of teaching people how to program, my experience is
> > that you can talk all you want about problems with floating point
> > representations -- you can also talk about infinite precision
> > representations, non-algebraic numbers, lazy streams, lambda calculus,
> > the Y combinator, life, and everything.  IME, they will look at you
> > and nod, but they will get nothing.
> 
> You don't have to get into all that detail, you just have to show a few 
> examples that floating point is not exact.
> 
> I remember some beginning Fortran and BASIC textbooks that taught not to 
> write loops like:
> 
> for i = 0 to 1 by .1
> 
> because of the round-off error.  They demonstrated this by putting a 
> "print i" statement in the loop so you could see the errors accumulate.

As Jens pointed out earlier, it *is* possible to deal with floating
point numbers in DrScheme's teaching languages.  It's not the default
because the emphasis is on learning how to program first.  (And sure,
floating point arithmetics is something programmers need to know,
among many other technical details.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!
From: Jens Kilian
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <87r78fcs6c.fsf@gondolin.bb.bawue.de>
Eli Barzilay <···@barzilay.org> writes:
> It all depends on your expectations.  Digging back to the time I
> learned how to program, I don't think that I expected an answer of
> -2.7755575615628914e-17.

What accuracy!  If I had tried that, I would have got 1.1641532E-10.
(I just checked that with an emulator :-)

-- 
··········@acm.org                 As the air to a bird, or the sea to a fish,
  http://www.bawue.de/~jjk/        so is contempt to the contemptible. [Blake]
  http://del.icio.us/jjk
From: Eli Barzilay
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <m3oe3jmlgj.fsf@winooski.ccs.neu.edu>
Jens Kilian <···@acm.org> writes:

> Eli Barzilay <···@barzilay.org> writes:
> > It all depends on your expectations.  Digging back to the time I
> > learned how to program, I don't think that I expected an answer of
> > -2.7755575615628914e-17.
> 
> What accuracy!  If I had tried that, I would have got 1.1641532E-10.
> (I just checked that with an emulator :-)

I just used a default mzscheme, which uses double floats by default.
Actually, I get the same answer from several other Schemes, and from
Emacs.  ACL and CLISP seem to be using single floats by default
though.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!
From: rydis (Martin Rydstr|m) @CD.Chalmers.SE
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <w4cfyov9kax.fsf@boris.cd.chalmers.se>
Eli Barzilay <···@barzilay.org> writes:
> I just used a default mzscheme, which uses double floats by default.
> Actually, I get the same answer from several other Schemes, and from
> Emacs.  ACL and CLISP seem to be using single floats by default
> though.

That's mandated by the CL standard. See *read-default-float-format*.

',mr

-- 
[Emacs] is written in Lisp, which is the only computer language that is
beautiful.  -- Neal Stephenson, _In the Beginning was the Command Line_
From: Jens Axel Søgaard
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <439deac1$0$38666$edfadb0f@dread12.news.tele.dk>
Pascal Bourguignon wrote:

> DrScheme translates specifically your question as above.

Only in the teaching languages.

> This is unfortunate, since it prevents students to learn about
> floating-point arithmetic.

One idea behind the language levels of the teaching languages, is
that you focus on one type of language constructs at a time.
Anything that distracts from the focus is therefore kept to a
minimum - which is why decimal numbers is read as exact numbers.

However, for those that wish to teach the students about floating
point operations, one just use the #i (inexact) prefix:

   [Beginner Language]
     > (- #i1.0 #i0.9 #i0.1)
     #i-2.7755575615628914e-017

The discussion on exact vs inexact numbers comes natural when
discussing these outputs:

   > (sqrt 2)
   #i1.4142135623730951

   > (sqrt 4)
   2

-- 
Jens Axel S�gaard
From: Bradd W. Szonye
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <slrndprvia.kno.bradd+news@szonye.com>
[Followups reset, since the main question asks about a specific Scheme
implementation.]

Emre Sevinc wrote:
> Probably you've already heard Google's failure to calculate:
>
> 1 - 0.9 - 0.1
>
> http://www.google.com/search?q=1+-+0.9+-+0.1

This is news to me, but not really surprising. It's a natural
consequence of a round-trip conversion of inexact numbers from decimal
to binary arithmetic and back again. It's counterintuitive (for non-
programmers, anyway), but it's not a failure of calculation so much as
mismatched assumptions.

> Finally I have tried Dr.Scheme on an
> MS Windows 2000 system:

>> (- (- 1 0.9) 0.1)
> 0
>
>> (- (- 1 9/10) 1/10)
> 0

> Now, that surprised me! Any explanations?

The two most likely explanations:

1. When printing values, MzScheme's REPL rounds values to some multiple
   of the floating-point system's epsilon value, to conceal small
   rounding errors like this.

2. Your MzScheme system is set up so that decimal numbers are exact by
   default, thus making the two lines of sample code identical. (The
   Scheme spec leaves it up to the implementation to decide whether the
   decimal point implies inexactness.)

You could determine which is true by altering your first test
expression. If the REPL is rounding printed results, you should be able
to provoke weirdness by replacing (- 1 0.9) with something like
(- 1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1). If it's defaulting to
exact numbers, you should be able to provoke weirdness with
(- (- 1 #i0.9) #i0.1) to force inexact arithmetic.
-- 
Bradd W. Szonye
http://www.szonye.com/bradd
From: Max Hailperin
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <m21x0hkgr2.fsf@max-1.res-hall.gac.edu>
"Bradd W. Szonye" <··········@szonye.com> writes:
...
> 2. Your MzScheme system is set up so that decimal numbers are exact by
>    default, thus making the two lines of sample code identical. (The
>    Scheme spec leaves it up to the implementation to decide whether the
>    decimal point implies inexactness.)

Not true.  Section 7.2.4 of the R5RS says "If the written
representation of a number has no exactness prefix ... It is inexact
if it contains a decimal point ...."

However, as it happens, DrScheme deviates from the R5RS spec in this
regard by default.  (You can set an option to make it obey the spec.)

> You could determine which is true by altering your first test
> expression. If the REPL is rounding printed results, you should be able
> to provoke weirdness by replacing (- 1 0.9) with something like
> (- 1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1). If it's defaulting to
> exact numbers, you should be able to provoke weirdness with
> (- (- 1 #i0.9) #i0.1) to force inexact arithmetic.

A simpler approach would be to just evaluate

 (exact? 0.9)

Of course, by default DrScheme won't let you use a lot of standard
R5RS procedures -- perhaps exact? is one of them.  (I didn't check).

 -Max Hailperin
  Professor of Computer Science
  Gustavus Adolphus College
  http://www.gustavus.edu/+max/
From: Timofei Shatrov
Subject: Re: Google's arithmetic failure, Python, floating point arithmetic, Lisp, Scheme...
Date: 
Message-ID: <439e75e4.3165333@news.readfreenews.net>
On 12 Dec 2005 22:48:42 GMT, "Bradd W. Szonye" <··········@szonye.com>
tried to confuse everyone with this message:

>[Followups reset, since the main question asks about a specific Scheme
>implementation.]
>
>Emre Sevinc wrote:
>> Probably you've already heard Google's failure to calculate:
>>
>> 1 - 0.9 - 0.1
>>
>> http://www.google.com/search?q=1+-+0.9+-+0.1
>
>This is news to me, but not really surprising. It's a natural
>consequence of a round-trip conversion of inexact numbers from decimal
>to binary arithmetic and back again. It's counterintuitive (for non-
>programmers, anyway), but it's not a failure of calculation so much as
>mismatched assumptions.

I'd call it a bug. There are enough smart people working in Google to
make it round off the result based on the numbers being input.

-- 
|a\o/r|,-------------.,---------- Timofei Shatrov aka Grue ------------.
| m"a ||FC AMKAR PERM|| mail: grue at mail.ru  http://grue3.tripod.com |
|  k  ||  PWNZ J00   || Kingdom of Loathing: Grue3 lvl 18 Seal Clubber |
`-----'`-------------'`-------------------------------------------[4*72]