Randy Wink
Randy Wink

Reputation: 71

Mathematica precision differs from other calculators

If I evaluate the following input in Mathematica 12:

SetPrecision[DecimalForm[123.432654/54.1122356, 130], 130]

The result is:

2.2810488724291406725797060062177479267120361328125000000000000000000000000000000000000000000000000000000000000000000000000000000000

When I run the same calculation in other calculators, the results are equal until the 15th digit of the Mathematica result: 2,281048872429140. However, as of the 16th digit, the other calculators show an equal result whereas Mathematica is showing a different result:

Windows Calculator: 2,281048872429140591633586101550

https://keisan.casio.com/calculator: 2.281048872429140591633586101550[.....]

https://www.mathsisfun.com/calculator-precision.html: 2.281048872429140591633586101550[.....]

Mathematica: 2.281048872429140672579706006217[.....].

Why is (only) Mathematica ending up with a different result?

Can Mathematica somehow end up with the same result as the other calculators (supposing that these unanimous results are the correct ones)?

Upvotes: 3

Views: 235

Answers (2)

Bill
Bill

Reputation: 3957

Mathematica's model of approximate decimal numbers is different from almost everyone else's model of approximate decimal numbers.

Because of the number of digits you supplied for each of 123.432654 and 54.1122356 these are assumed to be and treated as MachinePrecision numbers. That means they have the usual "about 16 digits of precision as supplied by the CPU floating point hardware in your computer, but it is a little more complicated than that.

Because of precedence rules Mathematica first evaluated each of those numbers and converted them to the internal floating point form, with the limited accuracy and all the problems that brings and all the speed of being able to perform calculations in hardware instead of software.

Then it did the division using the internal floating point hardware which resulted in another MachinePrecision number with only about 16 digits of precision.

Then with DecimalForm you asked Mathematica to extrapolate that result with only about 16 good digits into a 130 digit display.

All, or almost all with some very subtle things in dark corners, of the *Form functions are intended to and only used to produce something that can be displayed and not used for further calculations. For example, new users routinely do m=MatrixForm[mymatrix] to see a pretty formatting of the matrix and then proceed to try to do calculations with m, which fails.

Then you asked Mathematica to perform the SetPrecision function on that display to try to turn that into a 130 bit precision number. I can't even guess what that really did internally.

Upvotes: 2

Rohit Namjoshi
Rohit Namjoshi

Reputation: 679

It seems those other calculators assume that the precision of the entered numbers is infinite. WL does not. You can specify what precision the entered numbers have e.g.

123.432654`30/54.1122356`30

2.28104887242914059163358610155

Upvotes: 1

Related Questions