Explanation of the precision and the accuracy used by Wolfram Mathematica when performing arithmetic operations on floating point numbers

270 Views Asked by At

The numerical value for the precision in mathematica is given out by $MachinePrecision, and this is also the number of relevant digits showed in the output console when performing a computation with floating points.

Howewer, by executing for example RealDigits[Pi, 10, 300] I can see 3 hundrends decimals, each of them correct. Moreover even the multiplication RealDigits[Pi*3, 10, 300] is perfectly correct on any of the decimal, and it is not just approximated on the first $MachinePrecision ones.

I am wondering why this is possible, what is actually the real grade of precision when doing arithmetic operation on Mathematical. My vision is not clear right now. Thank you.

1

There are 1 best solutions below

8
On BEST ANSWER

$MachinePrecision is the precision of machine numbers. You get a machine number when you e.g. enter it as 3.5234 instead of e.g. 35234/10000. Also, default precision for N is $MachinePrecision, so e.g. N[3] will give you a machine representation of 3.

When you enter Pi or 3Pi, you get an exact number. It's a symbolic representation of a number, which can be evaluated to arbitrary precision using N. Similarly, you get Sqrt[5] if you evaluate e.g. 25^(1/4), while evaluation of 25.0^(1/4) will give you machine-precision approximation 2.23606797749979. So you'll get:

(* Exact number *)
Pi // FullForm
(* Machine number *)
N[Pi] // FullForm
(* Arbitrary-precision number (this one with 30 decimal digits) *)
N[Pi, 30] // FullForm

$\pi$

3.141592653589793`

3.1415926535897932384626433832795028841971693993751058151208`30.

To avoid confusion, note that FullForm shows more digits than the number precision actually is. They are the internal detail of implementation of the number storage and are printed for user to be able to save and then restore the exact same value as current session has. To see the numbers in their actual precision, omit the call to FullForm:

(* Exact number *)
Pi
(* Machine number *)
N[Pi]
(* Arbitrary-precision number (this one with 30 decimal digits) *)
N[Pi, 30]

$\pi$

3.14159265358979

3.14159265358979323846264338328

To see your example in the context of machine precision, try evaluating RealDigits[Pi*3., 10, 300] instead of RealDigits[Pi*3, 10, 300] (note the difference: 3. vs 3). Also try the arbitrary-precision version: RealDigits[Pi*3.0`11, 10, 300] (or replace 11 with your desired precision of the input number).