From: Bob Hanlon on
The input expression must have higher precision

N[173746*Sin[10^22] +
94228*Log[171/10] -
78487*Exp[42/100], 10]

-1.341818958*10^-12

N[Release[Rationalize[Hold[
173746*Sin[10^22] +
94228*Log[17.1] -
78487*Exp[0.42]]]], 10]

-1.341818958*10^-12


Bob Hanlon

---- Damien Wyart <damien.wyart(a)free.fr> wrote:

=============
Hello,

I am using Mathematica 7.0.2 and playing a bit with an expression
analyzed in the following paper:
http://www.loria.fr/~zimmerma/papers/cise.pdf

I tried many constructions with N and SetPrecision and can't get
Mathematica to output the correct result (I am not very experienced with
Mathematica). Here is the expression :

173746*Sin[10^22]+94228*Log[17.1]-78487*Exp[0.42]

The correct result should be -1.341818958*10^-12 but even forcing each
term with N and a very large number, I am still not getting this value
at all.


Any help will be appreciated. Thanks in advance ; best regards,

--
Damien Wyart



From: Toni Ivas on
Dear Bill and Damien

Still something is strange with Mathematica 7.0 as my output shows:

In[50]:== $Version

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

In[54]:== 173746*Sin[10^22] + 94228*Log[17.1] - 78487*Exp[0.42]

Out[54]== 2.91038*10^-11

In[55]:== N[173746*Sin[10^22] + 94228*Log[17.1] - 78487*Exp[0.42], 20]

Out[55]== 2.91038*10^-11

In[56]:== N[
173746*Sin[10^22] + 94228*Log[171/10] - 78487*Exp[42/100], 16]

Out[56]== -1.341818957829620*10^-12

In[57]:== N[
173746*Sin[10^22] + 94228*Log[171/10] - 78487*Exp[42/100], 20]

Out[57]== -1.3418189578296195497*10^-12

After first evaluating without forcing with N[*,prec] Mathematica
gives wrong answer
but then on trying to evaluate expression with precision 20 it gives
same answer,
and finally trying with 16 (maybe MachinePrecision) it gives correct
answer, all subsequent
evaluation with higher precision give correct answer :)

Best,
Toni

On Thu, Aug 5, 2010 at 12:59 PM, Bill Rowe <readnews(a)sbcglobal.net> wrote:
> On 8/4/10 at 5:51 AM, damien.wyart(a)free.fr (Damien Wyart) wrote:
>
>>I am using Mathematica 7.0.2 and playing a bit with an expression
>>analyzed in the following paper:
>>http://www.loria.fr/~zimmerma/papers/cise.pdf
>
>>I tried many constructions with N and SetPrecision and can't get
>>Mathematica to output the correct result (I am not very experienced
>>with Mathematica). Here is the expression :
>
>>173746*Sin[10^22]+94228*Log[17.1]-78487*Exp[0.42]
>
>>The correct result should be -1.341818958*10^-12 but even forcing
>>each term with N and a very large number, I am still not getting
>>this value at all.
>
> Actually, the "correct" result for this expression will vary
> with different CPUs, different platforms etc. Without being very
> specific about hardware and operating system, there is no
> assurance whatever you will get the specific value you are expecting.
>
> The problem is due to round off and loss of precision when using
> machine precision numbers.
>
> with
>
> In[1]:== $Version
>
> Out[1]== 7.0 for Mac OS X x86 (64-bit) (February 19, 2009)
>
> I get
>
> In[2]:== 173746*Sin[10^22] + 94228*Log[17.1] - 78487*Exp[0.42]
>
> Out[2]== 2.91038*10^-11
>
> I can get the result you are expecting by telling Mathematica to
> use exact arithmetic until the final result is converted to a
> floating point number. The following result should be repeatable
> on all platforms running Mathematica version 7.0.1.
>
> In[3]:== N[
> 173746*Sin[10^22] + 94228*Log[171/10] - 78487*Exp[42/100], 16]
>
> Out[3]== -1.341818957829620*10^-12
>
>
>

From: Bill Rowe on
On 8/6/10 at 6:56 AM, toniivas(a)gmail.com (Toni Ivas) wrote:

>Still something is strange with Mathematica 7.0 as my output shows:

<results/code snipped>

>After first evaluating without forcing with N[*,prec] Mathematica
>gives wrong answer

You are missing the point. The fact you get a result like

In[13]:= 173746*Sin[10^22] + 94228*Log[17.1] - 78487*Exp[0.42]

Out[13]= 2.91038*10^-11

has essentially nothing to do with Mathematica. This type of
result will occur in *any* software capable of doing the same
computation. The result is a direct consequence of using
floating point arithmetic. The exact value you get depends on
details of the FPU hardware you are using.

This is a wrong answer with respect to the true mathematical
answer using infinite precision numbers. But it is not wrong
answer with respect to floating point arithmetic. It is inherent
to the way floating point arithmetic works on any computer.

All three of the terms in the sum have values on the order of
10^5. You are looking for an answer on the order of 10^-12. You
simply cannot achieve the accuracy you are asking for in any
valid computation when you start with numbers with only 16 digit
precision. And in Mathematica, whenever you explicitly type a
decimal point in a number without explicitly specifying the
precision of that number you will be using machine precision
numbers that have approximately 16 digit precision. The
advantage of machine precision arithmetic is it is all done in
hardware and is the fastest possible computation

A result like:

In[14]:= N[
173746*Sin[10^22] + 94228*Log[171/10] - 78487*Exp[42/100], 16]

Out[14]= -1.341818957829620*10^-12

has a lot to do with Mathematica. This result takes advantage of
Mathematica's ability to do arbitrary precision arithmetic
something many other computational software packages cannot
easily do.

Mathematica gives you a choice. You can choose speed an accept
whatever accuracy is possible using your hardware. Or you can
sacrifice speed and choose whatever accuracy you want. It is up
to you to choose wisely.