0
$\begingroup$

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.

| cite | improve this question | | | | |
$\endgroup$
  • $\begingroup$ This seems like it is better suited for the Mathematica.se forum; it does not come across as a math question per se. $\endgroup$ – Daniel Lichtblau Dec 26 '19 at 19:23
1
$\begingroup$

$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).

| cite | improve this answer | | | | |
$\endgroup$
  • $\begingroup$ Thank Ruslan, this helped me a lot! It is impossible to evaluate a MachineNumber with N[] and a Precision greater than $\texttt{\$MachinePrecision}$? $\endgroup$ – FRANCESCO Dec 20 '19 at 16:57
  • $\begingroup$ I'm not sure what you mean. A machine number is already the result of truncation of precision. You can convert it to an arbitrary-precision number using SetPrecision, but this won't improve its precision with respect to the value that it already approximates – just let further computations consider and store more of its significant digits. $\endgroup$ – Ruslan Dec 20 '19 at 17:24
  • $\begingroup$ 30 digit version needs work... $$\pi=3.1415926535897932384$$$$62643383279502884197$$$$1693993751058$$$$\boldsymbol{2097494459230...}$$ Also it is north of 60 digits shown ... $\endgroup$ – user645636 Dec 20 '19 at 17:33
  • $\begingroup$ @RoddyMacPhee it's FullForm. If you omit this call and simply output the result of N, you'll get 3.14159265358979323846264338328 $\endgroup$ – Ruslan Dec 20 '19 at 17:34
  • $\begingroup$ @RoddyMacPhee I've edited the post to note this. $\endgroup$ – Ruslan Dec 20 '19 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.