MathGroup Archive 2009

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

Search the Archive

Re: Odd behavior?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101858] Re: [mg101850] Odd behavior?
  • From: Andrzej Kozlowski <akozlowski at gmail.com>
  • Date: Mon, 20 Jul 2009 05:59:28 -0400 (EDT)
  • References: <200907191115.HAA20885@smc.vnet.net>

First and above all you have to understand that the results you are  
getting have (essentially) nothing to do with Mathematica. You are  
doing computations with MachinePrecision which means that they area  
all performed entirely by your processor and Mathematica is only  
reporting the results. So if you want to blame someone for these "poor  
solutions" your choice is:

1. Processor makers for making binary (rather then decimal) processors  
which cannot represent these decimal fractions with perfect accuracy
2. The laws of numerical analysis, which cause the order of  
computations to matter in doing this sort of inexact arithmetic

If you are not looking for someone to blame you could follow the  
common advice in such situations and read the manual (as well as  
looking into to an introductory text on basic numerical analysis,  
particularly the section on binary representation of numbers with  
finite precision).

As for Mathematica: there are only a few bits of information relevant  
to this. One is that it is Precision rather than Accuracy that gives  
you relevant information, and your case the Precision is always the  
same: $MachinePrecision. If the precision is $MachinePrecision then  
Accuracy is defined purely formally as $MachinePrecision- 
Log[10,Abs[x]] and carries no useful information beside what is  
already included in the value Abs[x]. (In other words, reporting the  
value of your computation and its Accuracy you were simply reporting  
the same thing twice).

The second useful piece of information is that:

Chop[5.1 - 4.5 - 0.6]
0

Andrzej Kozlowski


On 19 Jul 2009, at 04:15, 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.
>



  • Prev by Date: Re: How to make variables local to a particular notebook?
  • Next by Date: Re: Naming Operators in Pure Function form
  • Previous by thread: Re: Odd behavior?
  • Next by thread: Re: Odd behavior?