Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

RE: Accuracy and Precision

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36922] RE: Accuracy and Precision
  • From: "DrBob" <drbob at bigfoot.com>
  • Date: Wed, 2 Oct 2002 03:32:00 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Andrzej, observe:

a = 77617; b = 33096;
f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 +
a/(2*b)
f
Accuracy[f]
Precision[f]
Accuracy[10.^21]
Precision[10.^21]

1.1805916207174113*^21
-5
16
-5
16

The two numbers supposedly have the same accuracy and precision, yet the
first is in doubt by about 22 ORDERS OF MAGNITUDE -- never mind the
digits!  Mathematica computed this beast without giving any indication
it was just noise -- without REALIZING it was noise.

>>What more do you demand?

I'm not demanding, objecting, or criticizing.  I'm pointing out the
problem.  On the one hand, the poster is computing something that's
simply not well-behaved.  Unless he knows the coefficients with VERY
high precision, he can't know even the magnitude of the result -- and
that's not Mathematica's fault at all.  On the other hand, Mathematica
doesn't notice that precision is lost in the computation, and perhaps it
should.  You thought it DID notice, after all -- but it didn't.

Bobby

-----Original Message-----
From: Andrzej Kozlowski [mailto:andrzej at platon.c.u-tokyo.ac.jp] 
To: mathgroup at smc.vnet.net
Subject: [mg36922] Re: Accuracy and Precision

It seems clear to me that what Allan and what you mean by "succeeds"  
here refer to quite different things and your objection is therefore  
beside the point. There are obviously two ways in which one can  
interpret the original posting. The first interpretation, which Allan  
and myself adopted, was that the question concerned purely the  
computational mechanism of Mathematica. Or, to put it in other words,  
it was "why are the results of these two computations not the same?".  
In this sense "success" means no more than making Mathematica return  
the same answer using the two different routes the original poster used.
You on the other hand choose to assume that the posting shows that its  
author does not understand not just the mechanism of significance  
arithmetic used by Mathematica  but also computations with inexact  
numbers in general. I do not think this is necessarily the correct  
assumption. I also don't see that Mathematica is doing anything wrong.  
After all, one can always check the accuracy of your answer:

In[1]:=
a = 77617.; b = 33096.;

In[2]:=
f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) +
    5.5*b^8 + a/(2*b)

In[3]:=
f

Out[3]=
-1.1805916207174113*^21

In[4]:=
Accuracy[%]

Out[4]=
-5

which tells you that it can't be very reliable. What more do you demand?

Andrzej


Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/

On Tuesday, October 1, 2002, at 02:59 AM, DrBob wrote:

> Actually, we don't know whether SetAccuracy "succeeds", because we  
> don't
> know how inexact those numbers really are.  If they are known to more
> digits than shown in the original post, they should be entered with as
> much precision as they deserve.  If not, there's no trick or algorithm
> that will give the result precision, because the value of f really is
> "in the noise".  That is, we have no idea what the value of f should  
> be.
>
> Mathematica's failing is in returning a value without pointing out
that
> it has no precision.
>
> Bobby
>
> -----Original Message-----
> From: Allan Hayes [mailto:hay at haystack.demon.co.uk]
To: mathgroup at smc.vnet.net
> Sent: Monday, September 30, 2002 11:59 AM
> Subject: [mg36922] Re: Accuracy and Precision
>
> Andrzej, Bobby, Peter
>
> It looks as if using SetAccuracy succeeds here because the inexact
> numbers
> that occur have finite binary representations. If we change them
> slightly to
> avoid this then we have to use Rationalize:
>
> 1) Using SetAccuracy
>
>     Clear[a,b,f]
>
>
> f=SetAccuracy[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ 
> (2*b),
>       Infinity];
>
>     a=77617.1;
>     b=33096.1;
>
>     a=SetAccuracy[a,Infinity];b=SetAccuracy[b,Infinity];
>
>     f
>
>
> -1564032114908486835197494923989618867972540153873951942813115514949
> 3891236234\
>
>
52500771916869370459119776018798804630436149786919912931962574301029236 
> 3
> 1246
> 75\
>
> / 
>
10867106143970760551000357827554793888198143135975649579607989867743572
> 8240
> 16\
>         0653953612982932181371232436367739737604096
>
> 2) Rewriting as fractions
>
>     a=776171/10;
>     b=330961/10;
>
>     f=33374/100*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+54/10*b^8+a/(2*b)
>
>         -(5954133808997234115690303589909929091649391296257/
>            41370125000000)
>
> 3) Using Rationalize
>
>     Clear[a,b,f]
>
>
> f=Rationalize[333.74*b^6+a^2*(11*a^2*b^2-b^6-121*b^4-2)+5.4*b^8+a/ 
> (2*b),
> 0];
>
>     a=77617.1;
>     b=33096.1;
>
>     a=Rationalize[a,0];b=Rationalize[b,0];
>
>     f
>
>         -(5954133808997234115690303589909929091649391296257/
>            41370125000000)
>
>
> I use Rationalize[. , 0] besause of results like
>
>     Rationalize[3.1415959]
>
>         3.1416
>
>     Rationalize[3.1415959,0]
>
>         31415959/10000000
> --
> Allan
>
> ---------------------
> Allan Hayes
> Mathematica Training and Consulting
> Leicester UK
> www.haystack.demon.co.uk
> hay at haystack.demon.co.uk
> Voice: +44 (0)116 271 4198
> Fax: +44 (0)870 164 0565
>
>
> "Andrzej Kozlowski" <andrzej at tuins.ac.jp> wrote in message
> news:an8s8i$6pk$1 at smc.vnet.net...
>> Well, first of of all, your using SetAccuracy and SetPrecision does
>> nothing at all here, since they do not change the value of a or b.
You
>> should use a = SetAccuracy[a, Infinity] etc. But even then you won't
>> get the same answer as  when you use exact numbers because of the way
>> you evaluate f. Here is the order of evaluation that will give you
the
>> same answer, and should explain what is going on:
>>
>> f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*
>>          b^4 - 2) + 5.5*b^8 + a/(2*b), Infinity];
>>
>> a = 77617.;
>>
>>
>>   b = 33096.;
>>
>> a = SetAccuracy[a, Infinity]; b = SetAccuracy[b, Infinity];
>>
>> f
>>
>>    54767
>> -(-----)
>>    66192
>>
>> Andrzej Kozlowski
>> Toyama International University
>> JAPAN
>>
>>
>>
>> On Sunday, September 29, 2002, at 03:55 PM, Peter Kosta wrote:
>>
>>> Could someone explain what is going on here, please?
>>>
>>> In[1]:=
>>> a = 77617.; b = 33096.;
>>>
>>> In[2]:=
>>> SetAccuracy[a, Infinity]; SetAccuracy[b, Infinity];
>>> SetPrecision[a, Infinity]; SetPrecision[b, Infinity];
>>>
>>> In[4]:=
>>> f := 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 +
>>> a/(2*b)
>>>
>>> In[5]:=
>>> SetAccuracy[f, Infinity]; SetPrecision[f, Infinity];
>>>
>>> In[6]:=
>>> f
>>>
>>> Out[6]=
>>> -1.1805916207174113*^21
>>>
>>> In[7]:=
>>> a = 77617; b = 33096;
>>>
>>> In[8]:=
>>> g := (33375/100)*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) +
>>> (55/10)*b^8 + a/(2*b)
>>>
>>> In[9]:=
>>> g
>>>
>>> Out[9]=
>>> -(54767/66192)
>>>
>>> In[10]:=
>>> N[%]
>>>
>>> Out[10]=
>>> -0.8273960599468214
>>>
>>> Thanks,
>>>
>>> PK
>>>
>>>
>>>
>>
>>
>
>
>
>
>
>
>
>






  • Prev by Date: Loss of precision when using Simplify
  • Next by Date: Re: Request for Mathematica Programming help.
  • Previous by thread: Re: Accuracy and Precision
  • Next by thread: Re: Accuracy and Precision