The result seems weird for simple multiplication, I have no idea why this happens.

In[71]:= 0.6*0.8048780487804877`

Out[71]= 0.482927

In[72]:= 0.3*0.8414634146341463`

Out[72]= 0.252439

In[74]:= (0.6*0.8048780487804877`) + 0.3*0.8414634146341463`

Out[74]= 0.735366

In[75]:= 0.6*0.8048780487804877`+0.3*0.8414634146341463`

Out[75]= 0.406365

Why the brackets In[74] and In[75] have effect? I think it should have no difference. I use mathematica 12.1. Thank you for your help.

  • 7
    $\begingroup$ This is definitely one of Mathematica's "gotchas." This lexical quirk is a consequence of Wolfram Language allowing both a plus and a minus in the number in a precision annotation. Since the precision annotation is infix instead of matchfix, there is no good way of avoiding some version of this lexical trap, unfortunately. $\endgroup$ Mar 27 '20 at 19:38

Because the In[75] is completely different than you think.

(* 0.406365 *)

0.6*0.8048780487804877` + 0.3*0.8414634146341463`
(* 0.735366 *)

Notice the space in the second example: in your case +0.3 is a specification for precision for tick `

Easier example:

(* in this case it's specification of precision *)
(* 1.20000000000000000000000000000 *)

(* in this case it's 1.2 with $MachinePrecision, plus 30 *)
1.2` + 30
(* 31.2 *)
  • 1
    $\begingroup$ "arbitrary-precision" It's $MachinePrecision when a precision isn't specified after the tick. $\endgroup$ Mar 27 '20 at 19:33
  • 2
    $\begingroup$ @RobertJacobson Nope, it's MachinePrecision. Indeed, there is a difference! Compare N[1, MachinePrecision] and N[1, $MachinePrecision]. $\endgroup$ Mar 27 '20 at 20:04
  • $\begingroup$ You are right! Now I need to go edit my other comment! $\endgroup$ Mar 27 '20 at 20:08
  • 5
    $\begingroup$ N.B. Once upon a time, N[1, $MachinePrecision] was used to get a machine precision result. Version 5 introduced MachinePrecision, so that N[1, MachinePrecision] was what you now had to do to get a machine precision result, and N[1, $MachinePrecision] now produced an arbitrary precision result. Perhaps this is what @Robert was (mis)remembering. $\endgroup$ Mar 27 '20 at 20:17

0.8048780487804877`+0.3 is an arbitrary-precision number with precision 0.3.

With the parentheses, the 0.3 does not specify the precision, but stands as a number. The second line is equivalent to

0.6 * (0.8048780487804877`+0.3) * 0.8414634146341463`
  • $\begingroup$ Note that 3.0 will be a $MachinePrecision number. $\endgroup$ Mar 27 '20 at 19:31
  • 1
    $\begingroup$ @RobertJacobson I suppose you meant 0.3, not 3.0. Do you mean $MachinePrecision (i.e., arbitrary precision) or MachinePrecision number? Do you just mean that the precision of an arbitrary-precision number is specified by a MachinePrecision number? $\endgroup$
    – Michael E2
    Mar 27 '20 at 19:38
  • $\begingroup$ The value of MachinePrecision is $MachinePrecision. Real numbers with fewer than $MachinePrecision digits have precision $MachinePrecision. $\endgroup$ Mar 27 '20 at 19:42
  • $\begingroup$ (Technically, MachinePrecision is n*Log[10, 2] where n is the IEEE mantissa on the host system, and $MachinePrecision is the MachinePrecision approximation to MachinePrecision.) $\endgroup$ Mar 27 '20 at 19:56
  • 2
    $\begingroup$ Just to clarify: Arbitrary precision numbers (aka "bignums") can have precision less than $MachinePrecision. $\endgroup$ Mar 27 '20 at 21:38

It's not hte parentheses; it's the missing whitespace!

There is a tiny difference between the meanings of




 0.8048780487804877` +0.3


We have

 0.8048780487804877`+0.3 == 0.8048780487804877`0.3

and the number behind the backtick denotes the number of significant digits. In particular, no addition is performed during evaluation of in case of 0.8048780487804877`+0.3


Of course you can raise all the numbers to a higher precision:

0.6`50 0.8048780487804877`50 + 0.3`50*0.8414634146341463`50

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.