MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Odd behavior?

  • To: mathgroup at
  • Subject: [mg101853] Re: Odd behavior?
  • From: Bill Rowe <readnews at>
  • Date: Mon, 20 Jul 2009 05:58:34 -0400 (EDT)

On 7/19/09 at 7:15 AM, esadlon at (elliot) wrote:

>The expression 5.1 - 4.5 - 0.6 gives different answers depending on
>the version of Mathematica. Version 6 says 0. (which is obviously
>what we expect) with an accuracy of about 307. Version 7 says
>-3.33067x10^-16 with an accuracy of about 31. Also, in version 7, if
>the expression is changed to 5.1 - (4.5 + 0.6) the answer it gives
>is 0. with an accuracy of about 307. Both versions were run on three
>different computers.

>Anybody know what changed or what I can do to prevent such poor
>solutions (besides forcing a specific order of evaluation)? Thanks.

By "poor solution" I assume you are referring to

In[1]:= 5.1 - 4.5 - 0.6

Out[1]= -3.33067*10^-16

In[2]:= $Version

Out[2]= 7.0 for Mac OS X x86 (64-bit) (February 19, 2009)

This is inherent to using machine precision numbers. The only
way to prevent this type of problem is to use exact arithmetic.
The problem is the numbers 5.1, 4.5, and 0.6 cannot be expressed
exactly in binary with a finite number of digits. So, the
problem being solved by Mathematica isn't exactly what you expect.

The other work around is to use Chop, i.e.,

In[3]:= Chop[5.1 - 4.5 - 0.6]

Out[3]= 0

  • Prev by Date: Re: Invisible - misleading documentation
  • Next by Date: Thoughts on a Wolfram|Alpha package for
  • Previous by thread: Re: Odd behavior?
  • Next by thread: Re: Odd behavior?