RE:Working Precision
- To: mathgroup at smc.vnet.net
- Subject: [mg23928] RE:Working Precision
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Fri, 16 Jun 2000 00:57:07 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Richard Fateman showed how arbitrary precision arithmetic can produce
strange results. I have some more strange behavior.
Richard demonstrated that (x == x+1) returns True after evaluating the Do
loop below. Well you can also get f[x] defined for lots of values you don't
expect!
In[1]:=
x=1.11111111111111111111;
Do[x=2*x-x, {100}];
Clear[f];
f[x]=29;
{f[-5.2],f[-2.1],f[4.3],f[8.2]}
Out[5]=
{f[-5.2],29,29,f[8.2]}
-------------------------------
The way to fix this problem is to change the value of $MinPrecision as I do
below. Then my definition for (f) doesn't apply to f[-2.1], f[4.3]. This
will also ensure (x==x+1) returns False. I haven't checked but a positive
value for $MinPrecision might solve the problem Bernd Brandt had with
NIntegrate.
In[6]:=
$MinPrecision=1.0;
x=1.11111111111111111111;
Do[x=2*x-x, {100}];
Clear[f];
f[x]=29;
{f[-5.2],f[-2.1],f[4.3],f[8.2]}
Out[11]=
{f[-5.2],f[-2.1],f[4.3],f[8.2]}
---------------------------
Now consider another example. Below Mathematica thinks (b1) has much better
precision than (a1). This doesn't make sense, and Mathematica doesn't do
much better using the default setting ($MinPrecision=0.0).
In[12]:=
a1=Exp[800.0]/Exp[800];
b1=a1+p-1;
SetOptions[Precision,Round->False];
(* Precision only has an option in Version 4. *);
{Precision[a1],Precision[b1]}
Out[15]=
{13.0515,25.2788}
The result above comes out much better if $MinPrecision is much less than
zero. However, I can't understand why (b1) below still has slightly better
precision than (a1).
In[16]:=
$MinPrecision=-Infinity;
a1=Exp[800.0]/Exp[800];
b1=a1+p-1;
{Precision[a1],Precision[b1]}
Out[19]=
{13.0502,13.5473}
----------------------------------
Well, ($MinPrecision=-Infinity) allows a better result from the last
example, but now the definitions for (f) that I considered earlier are even
more strange.
In[20]:=
x=1.11111111111111111111;
Do[x=2*x-x, {100}] ;
Clear[f];
f[x]=29;
{f[-534.2],f[-2.1],f[4.3],f[815.2]}
Out[25]=
{29,29,29,29}
----------------------
A very good discussion of arbitrary precision arithmetic can be found in the
Help Browser under:
Getting Started/Demos
Demos
Numerics Report (near the bottom)
--------------------
Regards,
Ted Ersek
Download Mathematica tips from
http://www.verbeia.com/mathematica/tips/Tricks.html