I saw a question on Facebook $8\div2 (2 + 2)=?$

Consider these inputs.

Divide[8, 2 (2 + 2)]


$8\div2 (2 + 2)$ using esc+div+esc


Why the results are different.

I also tried these entries.

8/2 (2 + 2)


8/(2 (2 + 2))


Precedence /@ {Plus, Subtract, Times, Divide}

{310., 310., 400., 470.}


closed as off-topic by Thies Heidecke, chuy, Daniel Lichtblau, Roman, m_goldberg Aug 1 at 23:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Thies Heidecke, chuy, Daniel Lichtblau, Roman, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Try using Trace[] to see how the evaluation is performed. $\endgroup$ – Anjan Kumar Aug 1 at 14:58
  • $\begingroup$ Is Mathematica just following the usual order of operations: en.m.wikipedia.org/wiki/Order_of_operations ? $\endgroup$ – JimB Aug 1 at 15:02
  • $\begingroup$ @OkkesDulgerci The arguments to Divide are treated as if you had parenthesis around each one. There is no spilling from denominator to numerator because of operator precedence like you can have when you are writing / as infix operator. $\endgroup$ – Thies Heidecke Aug 1 at 15:08
  • 1
    $\begingroup$ The answer to the question should be "It is X if I follow these rules, and Y if I follow these rules." It would be nice if that is what the Facebook poster is after. But my bias is that it is not an attempt at enlightenment. $\endgroup$ – JimB Aug 1 at 15:20
  • 1
    $\begingroup$ "There is no Supreme Court for mathematical notation; there were no commandments handed down on Sinai concerning operational precedence; all there is, is convention, and different people are free to adhere to different conventions. Wise people will stick in enough parentheses to make it impossible for anyone to mistake the meaning. If they mean, (48÷2)(9+3), they'll write it that way; if they mean 48÷(2(9+3)), they'll write it that way." - from here. $\endgroup$ – J. M. will be back soon Aug 2 at 8:02

First, since the precedence of Divide is higher than Times, you should expect to parse 8 ÷ 2(2+2) as:

Divide[8, 2] (2+2)

You can also verify this by entering the input into a cell and using Cell | Show Expression to see what the boxes look like. The rendered version:

8 ÷ 2 (2 + 2)

and the version after using Cell | Show Expression:

Cell[BoxData[ RowBox[{ RowBox[{"8", "\[Divide]", "2"}], RowBox[{"(", RowBox[{"2", "+", "2"}], ")"}]}]], "Input", CellLabel->"In[353]:="]

The boxes show that 8 ÷ 2 (with the boxes RowBox[{"8" "\[Divide]", "2"}]) is being multiplied by 2 + 2 (with the boxes RowBox[{"2", "+", "2"}]).

  • 1
    $\begingroup$ Also FullForm[Hold[8/2 (2 + 2)]] might be easier to understand than "show expression" $\endgroup$ – Gustavo Delfino Aug 1 at 18:36
  • $\begingroup$ Thanks. This clears things a bit. But my main concern was, on help page for Divide it says you can use esc+div+esc for shorthand $\div$ and I expected to get the same result as Divide[8, 2 (2 + 2)]=1 but it didn't. $\endgroup$ – OkkesDulgerci Aug 1 at 22:58

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