-1
$\begingroup$

According to order of operations the answer should be $\mathbf{2}$ But Google and Wolfram calculates as 8

This is last proccess: $5-0+3$

This is how I think: $5-(0+3)$

This is how Google answers: $(5-0)+3$

So, question is which operation is first $+$ or $-$?

  • 0
    Verily, this is a real question about expression parsing, which can be delicate matter of interest.2012-08-16

5 Answers 5

9

You proceed from left to right down the hierarchy. $5- 0\cdot3 + 9/3 = 5 - 0 + 3 = 5 + 3 = 8.$ You make the mistake of distributing the $-$ to two terms in the absence of parentheses.

  • 0
    That would be an error in the code for their parser. We know $-0 = 0$.2012-08-07
4

The operations + and - have the same priority, therefore google is right: $a - b + c$ is read as $(a-b) + c$.

2

$\times$ and $\div$ are higher precedence than $+$ and $-$, but each are associated left-to-right. First, the multiplication and division. Next, the leftmost addition/subtraction. Finally, the last addition. $ \begin{array}{c} 5-\color{#C00000}{0\times3}+\color{#C00000}{9/3}\\ \color{#C00000}{5-0}+3\\ \color{#C00000}{5+3}\\ 8 \end{array} $

1

The $0$ is meant to "confuse" but if you write things in a very explicit $+,\times$ only notation it gets clearer:

$\begin{align} &5-0\times 3+9/3 =\\ &5 + (-1)\times 0\times 3 + 9/3 =\\ & 5 + 0 + 3 = 8 \end{align}$

Remember that $a-b$ is actually $a+(-1)b$, and multiplication takes precedence over addition, so $(-1)\times 0 + 3$ is not the same as $(-1)\times(0+3)$.

0

$5-(0+3)=5-0-3=2$ but $(5-0)+3=5-0+3=8$ There's no priority between $+$ and $-$, but most people prefer to start from right to do the calculation.

  • 2
    As far as I always knew (and I haven't taught this stuff since my last kid was in junior high), the order between product/division and sum-substraction gets determined from left to right.2012-08-19