       Arbitrary Precision Arithmetic

• To: mathgroup at smc.vnet.net
• Subject: [mg18834] Arbitrary Precision Arithmetic
• From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
• Date: Thu, 22 Jul 1999 08:19:43 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```I agree with the result below.  If we multiply a number with 50 digits of
precision by a machine precision number, all the extra digits are garbage.
I get back a number with 16 digits of precision and this is good.

In:=
pie=SetPrecision[Pi,50];
area=pie (1.25)^2;
{Precision[pie], Precision[area]}

Out=
{50, 16}
------------------------------

Next I multiply a number with only 4 digits of precision by a machine
precision number and Mathematica doesn't know that the result should have 4
digits of precision.  I don't like this.

In:=
mass=SetPrecision[4.2,4];
density=mass / 1.25;
{Precision[mass], Precision[density]}

Out=
{4, 16}

To do the calculation above correctly we can do something like the line
below.

In:=
density=mass / SetPrecision[1.25,6];
{Precision[mass], Precision[density]}

Out=
{4, 4}

--------------------------------------------
At first you might guess that if a numeric function gets a machine precision
number it returns a machine precision number whenever possible.  This isn't
always true, and it can be hard to predict what you will get.  Consider the
line below, and look at the ByteCount of the results.  If memory is a
concern you might want to use N[Erf[x2]] to make sure the result is a
machine number.

In:=
x1=Erf[26.0];
x2=Erf[27.0];
{Precision[x1], Precision[x2]}

Out=
{16, 331}

In:=
{ByteCount[x1], ByteCount[x2]}

Out=
{16, 192}

----------------------------------
In the line below (b1 = a1 + Pi - 1) and the kernel thinks (b1) has better
precision than (a1).  Wrong!

In:=
a1 = Exp[1000.0] / Exp;
b1 = a1 + Pi - 1;
{Precision[a1], Precision[b1]}

Out=
{13, 24}

---------------------------------------
I learned from WRI tech support that the calculation above can be
done correctly by using (\$MinPrecision = -Infinity).

In:=
\$MinPrecision=-Infinity;

In:=
b1 = a1 + Pi - 1;
{Precision[a1], Precision[b1]}

Out=
{13, 13}

--------------------------------------

Sometimes the kernel leaves machine precision arithmetic unfinished.  See
the example below.

In:=
x =15.0 / 0.125 +Log[1-Erf]

Out=
120. +Log[1-Erf]

Below we see simply using N on the result above returns Indeterminate.
That's why it was returned unfinished.  We have to use arbitrary precision
to get an ordinary number.  However, we get back a machine number because of
the machine number in the original calculation.  In this case I am impressed
with how careful the kernel is.

In[19:=
{ N[x], N[x, 17] }

Out=
{Indeterminate, 68.4718}

In:=
Precision[ N[x, 17]  ]

Out=
16

-------------------------------------

Regards,
Ted Ersek
ersektr at navair.navy.mil

```

• Prev by Date: RE: TableAlignments
• Next by Date: Re: Re: Slow Version 4 Front End
• Previous by thread: Re: implcit plot with undefined expression
• Next by thread: Exporting PRINT results from Mathematica to other applications