MathGroup Archive 2011

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

Search the Archive

Re: Output Precision Exploration

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118427] Re: Output Precision Exploration
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 28 Apr 2011 06:32:57 -0400 (EDT)

I agree that this is annoying (but deceptive):

173.5/173.5 == 1
Log[1] == 0
Log[173.5/173.5] == 0

True

True

False

(I've replaced "==" where you had "=", since you could NOT get those  
results with the code you posted.)

Notice that the fraction is REAL, not INTEGER:

173.5/173.5
% // RealDigits
Log@%%

1.

{{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9}, 0}

-1.11022*10^-16

And that's as it should be. Dividing reals gives a real number -- not a  
rational or integer.

Now, having admitted that the example is disconcerting...

First alternative: When your chemical calculations reached the point of  
computing Log[173.5/173.5], perhaps it was really a case of Log[x/x],  
where the numerator and denominator were SUPPOSED to be or KNOWN to be  
precisely the same. If so, you could have coded 0, not Log[x/x], and you'd  
be fine.

Second alternative: You could have used exact calculations throughout, so  
that x would be exact when the time came, as in:

Log[(347/2)/(173 + 1/2)]

0

or

Log[2 ArcSin[1]/Pi]

0

Third alternative: Perhaps the calculation reached was Log[x/y], where x  
and y were Real outputs of separate calculations, and they merely HAPPENED  
to be equal, to the precision used. (Probably machine precision.)

In that case, there's no reason the result should be zero; there's not  
enough precision to justify it. If other terms are dominated by this one,  
your final result has no precision, and pretending that it does is futile.

Fourth alternative: Try using arbitrary precision, such as

Block[{$MaxPrecision=50,$MinPrecision=50},(* your calculations *)]

and examine the value and precision of the result.

You may find that all meaningful precision has been lost in the  
calculations... or you may get something useful.

Good luck!

Bobby

On Wed, 27 Apr 2011 04:39:14 -0500, Rafael Dunn  
<worthless.trash.junk at gmail.com> wrote:

> Mathematica 8.0.1.0, Mac OSX x86
>
> In:=
> Log[173.5/173.5]
>
> Out:=
> -1.11022*10^-16
>
> I expect an output of exactly 0.  Although 10^-16 is small, it turned
> out to be the largest factor in a chemical equation I was attempting to
> compute.
>
> I discovered this is because Mathematica does not actually evaluate
> 173.5/173.5 = 1.  The output is actually some number 0.9999999999...
>
> However, for most decimal constants x/x produces an exact output of 1.
> By entering a few decimals off the top of my head I also found 1733.5,
> 26.44, and 27.44 do not produce an output of 1 when divided by
> themselves.
>
> Why?  I understand Mathematica's algorithms for working with decimals
> must make approximations, but why is there so much variance among
> decimal calculations?  173.49/173.49 = 1, while 173.5/173.5 != 1.
> Furthermore, I find:
> x=173.49999999999999
> x/x = 173.5/173.5, with infinite precision.  If you add or remove a
> single 9 to the end of x, this ceases to be true.
>
> Furthermore, this looks like a contradiction to me:
>
> In:=
> 173.5/173.5 = 1
> Log[1] = 0
> Log[173.5/173.5] = 0
>
> Out:=
> True
> True
> False
>
> I have learned a lot about Mathematica's precision and approximation  
> through the help documentation, but I still can not explain this or see  
> how I can expect Log[x/x] = 0 for the sake of calculations on the 10^-16  
> scale.


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Bug in ListContourPlot?
  • Next by Date: Re: Same Programming Problem Implemented in Multiple Paradigms
  • Previous by thread: Output Precision Exploration
  • Next by thread: Re: Output Precision Exploration