Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1911 > unrolled thread

Output Precision Exploration

Started byRafael Dunn <worthless.trash.junk@gmail.com>
First post2011-04-27 09:39 +0000
Last post2011-04-28 10:36 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Output Precision Exploration Rafael Dunn <worthless.trash.junk@gmail.com> - 2011-04-27 09:39 +0000
    Re: Output Precision Exploration Barak Shoshany <baraksh@gmail.com> - 2011-04-28 10:33 +0000
    Re: Output Precision Exploration Joseph Gwinn <joegwinn@comcast.net> - 2011-04-28 10:36 +0000

#1911 — Output Precision Exploration

FromRafael Dunn <worthless.trash.junk@gmail.com>
Date2011-04-27 09:39 +0000
SubjectOutput Precision Exploration
Message-ID<ip8o8c$piq$1@smc.vnet.net>
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. 

[toc] | [next] | [standalone]


#1938

FromBarak Shoshany <baraksh@gmail.com>
Date2011-04-28 10:33 +0000
Message-ID<ipbfou$aac$1@smc.vnet.net>
In reply to#1911
On Apr 27, 12:39 pm, Rafael Dunn <worthless.trash.j...@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.

173.5 is a machine precision number, not an exact number. So it's only
know up to a certain precision. Try this:

InputForm[173.5/173.5]

0.9999999999999999

So it's only *approximately* 1. Of course, you could specify the
numbers to be of arbitrary precision, for example 100 digits:

Log[173.5`100/173.5`100]

0.*10^-100

However, the answer will never be *exactly* 0 because it is only known
to a certain precision. This is what Chop was made for:

Chop@Log[173.5/173.5]

0

See tutorial/NumericalPrecision in the Mathematica documentation.

[toc] | [prev] | [next] | [standalone]


#1959

FromJoseph Gwinn <joegwinn@comcast.net>
Date2011-04-28 10:36 +0000
Message-ID<ipbfvs$ag8$1@smc.vnet.net>
In reply to#1911
In article <ip8o8c$piq$1@smc.vnet.net>,
 Rafael Dunn <worthless.trash.junk@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. 

The computations are performed using 64-bit double precision floating 
point numbers, as defined in IEEE Std 754.  This is by definition a 
finite-precision computation, and errors of order 10^-16 are to be 
expected, and cannot be removed unless one goes to Mathematica's 
arbitrary precision arithmetic, which is orders of magnitude slower to 
compute.

You may wish to reformulate your problem.  With an explanation of what 
you are trying to solve and why, people will be able to suggest 
alternatives.

Joe Gwinn

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web