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: [mg36932] Re: Accuracy and Precision
  • From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
  • Date: Wed, 2 Oct 2002 03:32:42 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

You are of course right, I forgot that Mathematica does not try to keep  
precision or accuracy of machine arithmetic computations. But I think  
the actual precision you set need not be higher than machine precision,  
it just has to be set explicitely (is that right?). For example:

In[1]:=
Clear[f,a,b,k]

In[2]:=
k = $MachinePrecision;

In[3]:=
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),k];

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

In[5]:=
a=SetAccuracy[a,k];

In[6]:=
b=SetAccuracy[b,k];


In[7]:=
f

Out[7]=
\!\(\(-5.51716400890319`-2.8311*^19\)\)

In[8]:=
Accuracy[f]

 From In[8]:=
Accuracy::mnprec: Value -23 would be inconsistent with $MinPrecision; \
bounding by $MinPrecision instead.

Out[8]=
-20


Andrzej


On Wednesday, October 2, 2002, at 01:45 AM, Allan Hayes wrote:

> Andrzej
>
> Yes, like you I took the original question to be about how to get the  
> result
> of using the naive rational versions in place of the inexact numbers.
> Bobby raises the question of how we might know accuracy of the result.
>
> You answer this with
>> 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
>
> However this computation is done in machine arithmetic, which means  
> that
> Mathematica keeps no check on the accuracy and precision of the  
> computation,
> and Mathematica gives the default accuracy value without any real
> signifcance:
>
>     $MachinePrecision - Log[10,Abs[f]]//Round
>
>         -5
>
> To get meaningful accuracy and precision values we need to force the
> computation to be in bignums (bigfloat, arbitrary precision)  
> arithmetic.
> Mathematica then keeps track of the accuracy and precision that it can
> guarantee.
>
>     Clear[f,a,b,k]
>     k=50;
>
> 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),k];
>     a=77617.;b=33096.;
>     a=SetAccuracy[a,k];
>     b=SetAccuracy[b,k];
>     f
>
>         -0.82739605995
>
>     Accuracy[f]
>
>         11
>
>     Precision[f]
>
>         11
>
> Which tells  us that the error in the computed value of f is not more  
> than
>
>         10^-11
>
>
> The above results are rounded. More accurately we get
>
>     Accuracy[f, Round->False]
>
>         11.4956
>
>     Precision[f, Round->False]
>
>         11.4133
>
> There are several related issues here:
> - is the precision (accuracy) of rhe input known?
> - how does Mathematica interpret what one gives it?
> - how does Mathematica go about the calculation?
>
> --
> 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 platon.c.u-tokyo.ac.jp> wrote in message
> news:anbofj$e7u$1 at smc.vnet.net...
>> 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: [mg36932] 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\
>>>
>>> 525007719168693704591197760187988046304361497869199129319625743010292 
>>> 36
>>> 3
>>> 1246
>>> 75\
>>>
>>> /
>>> 108671061439707605510003578275547938881981431359756495796079898677435 
>>> 72
>>> 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
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
>
>
>
>
>
>
>
>
Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/



  • Prev by Date: Re: Accuracy and Precision
  • Next by Date: RE: final results: creating adjacency matrices
  • Previous by thread: Re: Accuracy and Precision
  • Next by thread: RE: Accuracy and Precision