Mathematica numerical "error" for simple multiplication In:= 0.6*0.8048780487804877

Out= 0.482927

In:= 0.3*0.8414634146341463

Out= 0.252439

In:= (0.6*0.8048780487804877) + 0.3*0.8414634146341463

Out= 0.735366

In:= 0.6*0.8048780487804877+0.3*0.8414634146341463

Out= 0.406365

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

• 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. Mar 27 '20 at 19:38

Because the In is completely different than you think.

0.6*0.8048780487804877+0.3*0.8414634146341463
(* 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.2+30
(* 1.20000000000000000000000000000 *)

(* in this case it's 1.2 with $MachinePrecision, plus 30 *) 1.2 + 30 (* 31.2 *) • "arbitrary-precision" It's$MachinePrecision when a precision isn't specified after the tick. Mar 27 '20 at 19:33
• @RobertJacobson Nope, it's MachinePrecision. Indeed, there is a difference! Compare N[1, MachinePrecision] and N[1, $MachinePrecision]. Mar 27 '20 at 20:04 • You are right! Now I need to go edit my other comment! Mar 27 '20 at 20:08 • 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. 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 • Note that 3.0 will be a$MachinePrecision number. Mar 27 '20 at 19:31
• @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? Mar 27 '20 at 19:38 • The value of MachinePrecision is$MachinePrecision. Real numbers with fewer than $MachinePrecision digits have precision$MachinePrecision. Mar 27 '20 at 19:42
• (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.) Mar 27 '20 at 19:56 • Just to clarify: Arbitrary precision numbers (aka "bignums") can have precision less than$MachinePrecision. 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

0.*10^-1

and

0.8048780487804877 +0.3

1.10488

We have

0.8048780487804877+0.3 == 0.80487804878048770.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.650 0.804878048780487750 + 0.350*0.8414634146341463`50
(*0.7353658536585365100000000000000000000000000000000*)