I know the proper teaching of PEMDAS/PEDMAS/BODMAS/BOMDAS.. is that multiplication and division have equal priority and are evaluated going through the arithmetic expression left to right (So, doing division first if division is left of multiplication in the arithmetic expression, and multiplication first if it is to the left of a division). Ditto for addition and subtraction.
And I know PEMDAS if taken as multiplication always before division, gives wrong answers. And addition always before subtraction, also gives wrong answers. e.g. 3-2+1 addition before subtraction would be wrong result. And 6/2*3 multiplication before division would be wrong result.
So one can break(get a wrong result from), a literal reading of PEMDAS, i.e. doing multiplication always before division, and ditto with additionan and subtraction.
But how about a literal reading of PEDMSA? so, taking it literally.. division always before multiplication. Subtraction always before addition.
Can you break it(get a wrong result from it)?
$\endgroup$ 104 Answers
$\begingroup$It is false that your PEDMSA rule (without the left-to-right rule) suffices to correctly evaluate any arithmetic expression.
$(6/3)/2 \color{red}\ne 6/(3/2)$.
$2^{(1^2)} \color{red}\ne (2^1)^{^2}$.
This shows that you still need the left-to-right rule when processing each arithmetic operation, and need the inside-out rule for exponentiation. It is true that with these rules in place, PEDMSA works. But the justification given by other existing answers is incomplete. To handle arbitrarily long arithmetic expressions, you will need induction. Also take note that exponentiation in some programming languages like Python have right-to-left associativity, so 2**1**2 is interpreted as 2**(1**2); this is obviously because there is no superscript in source code.
Here is the proof that PEDMSA+LTR+IO (namely PEDMSA with the left-to-right and inside-out rules) works for all arithmetic expressions involving $+,-,*,/$ and superscript-exponentiation and brackets, but no unary negation.
Take any expression $E$. By induction we can assume that PEDMSA+LTR+IO works for expressions that have fewer operations than $E$. Here parentheses are counted as operations. We shall analyze what happens when we apply PEDMSA+LTR+IO to $E$. We have the following cases:
$E$ has a parenthesis: The inner expression has fewer operations than $E$, and is hence evaluated correctly. After that, the resulting outer expression now has fewer operations than $E$, and hence we get the correct answer.
$E$ has no parentheses but has exponentiation: $E$ is reduced in the same way as conventionally (inside-out for chained exponentiations), so we get the correct answer.
$E$ has division and no higher-precedence operation: Let $p$ be the position of the first $/$ in $E$. By considering the $*$ operations immediately to the left of $p$, if any, it is clear that $E$ is of the form $\cdots [x * \cdots] y / z \,\cdots$, where there is no $*$ or $/$ immediately before $x$, and there is only a chain of $*$ between $x$ and $y$, and here the square-brackets in $[x * \cdots]$ denote that that subexpression is optional (it will not be there if whatever operation immediately to the left of $p$ is not $*$). Then the value of $E$ is $\cdots \Big( \big( [x * \cdots] y \big) / z \Big) \,\cdots = \cdots \Big( [x * \cdots] \big( y / z \big) \Big) \,\cdots$, and so our reduction results in an equal expression with fewer operations, and hence we get the correct answer.
$E$ has multiplication and no higher-precedence operation: $E$ is reduced in the same way as conventionally (leftmost $*$ first), so we get the correct answer.
$E$ has subtraction and no higher-precedence operation: $E$ is of the form $[x + \cdots] y - z \,\cdots$, where there is only a chain of $+$ between $x$ and $y$, or possibly $[x + \cdots]$ is empty (if the first operation is $-$). The value of $E$ is $\Big( \big( [x + \cdots] y \big) - z \Big) \,\cdots = \Big( [x + \cdots] \big( y - z \big) \Big) \,\cdots$, and so our reduction yields an equal expression with fewer operations, and hence we get the correct answer.
$E$ has only addition: Our reduction yields the correct answer because any reduction does.
I shall leave it as an exercise to extend this theorem and proof to cater for unary negation. One must think very carefully about how to amend the evaluation rules to correctly handle expressions like:
$-3/-1*--4--2*---5$
If you do not consider this valid, then you must decide and precisely specify what expressions are valid.
$\endgroup$ 9 $\begingroup$This question brings to light an excellent example of how we can introduce ambiguity into a language by removing one interpreter rule from a language/interpreter system.
A language and the corresponding interpreter go hand in hand. When we construct a language, and the corresponding interpretation rules, the onus is on the writer to phrase statements in a way that will always give the desired result by the corresponding interpreter. While there may be many speakers of one language, there is only one interpreter for languages of this sort.
Polish notation would be an example of an alternative language for arithmetic operations.
As you know, the "PEMDAS" rule is nothing more than a mnemonic device to assist in interpreting what is currently our most common language for operation order. The left to right scanner priority rule is however an integral part of this device, and PEMDAS would be best written as $P-E-(M \vee D)-(A\vee S)$ "with repeated left to right scan priority after each atomic operation execution".
We can make a new language and interpreter at will. We can also modify a language, but once you decide to modify an extant language/interpreter, like say "remove the left to right rule", then all bets are off. You now have a new language, it is not the old language, and things may need to either be written differently or interpreted differently for this new language, otherwise there will be problems, ambiguity being one such problem.
If you modify the language, you probably need to modify the interpreter. If you modify the interpreter, you probably need to modify the language.
$\endgroup$ 1 $\begingroup$To expand on Losethegame's answer
Losethegame answered "I got here by Googling the same question although I'm not sure if (m)any of the commenters have answered it specifically. I think you are right that your rule can't be broken. This can probably be proven algebraically because a*(b/c)=(a/c)*b and a+(b-c)=(a-c)+b...?"
I agree that it can probably be proven algebraically with methods like the one losethegame mentions(though losethegame's example may be flawed since, as user21280 points out, losethegame swaps operands). But elaborating on the idea of proving it algebraically (and without swapping operands!), I can think of some algebra that might prove it. (Aand granted user21280 is of the view that my examples don't account for all possibilities. His answer using logical formulae might).
Given an equation where multiplication comes textually before division, e.g. 3*4/2 it doesn't matter which you do first. So a literal PEMDAS or PEDMAS would be fine. Whereas given an equation where division comes textually before multiplication e.g. 6/2*3 then it does matter which you do first. A traditional reading of PEMDAS or PEDMAS gets it right(because they'd say do the first one first, and that's division), a literal PEDMSA gets it right. A literal reading of PEMDAS would get it wrong.
Subtraction and division share that property. So let's say we make a little equation of the part of the equation that has the operators competing with each other. If substraction is competing with addition, and subtraction occurs first(textually, in the equation), it has to be done first. If division is competing with multiplication, and division comes first, division has to be done first. Whereas if addition were competing with substraction, then regardless of whether or not it occurs first textually, it doesn't matter whether addition is done first or whether subtraction is. Similarly, if multiplication were competing with division, if multiplication comes first textually, then it doesn't matter whether the division is done first, or whether multiplication is done first. So PEDMSA literal always works(i.e. strictly doing division before multiplication, substraction before addition). As does a traditional/proper reading of PEMDAS/PEDMAS i.e. a reading that says multiplication and division are equal priority and do the first one first, similarly with addition and subtraction.
So e.g.
Taking 1*2/3 so a*b/c
Following PEDMSA literally gives 1*(2/3) so a(b/c)Following PEDMSA traditionally gives (1*2)/3 so (ab)/c
And we know algebraically that a(b/c)=(ab)/c
1*2/3 a* b/c
=
1*2/3 ab/cTaking 1/2*3 so a/b*cThat's evaluated the same whether following strictly ordered PEDMSA or traditional PEMDAS i.e. whether you do division first as a rule or whether you do the first of the multiplication and division first, that's (a/b)*c in both cases so clearly the same.
1/2*3 (a/b)*c
=
1/2*3 (a/b)*cWith 1+2-3 if we do a+ b-c which is ordered PEDMSA i.e. a+(b-c) that's the same result as if we do traditional PEMDAS (a+b)-c. We know algebraically a+(b-c)=a+b-c=(a+b)-c
I recall my math teacher pointing out that one thing you want to beware / be aware of is -(a+b) which we had drilled in was -a-b is so very different to -a+b. Subtractions always have to be done first and in order.. and if doing subtraction first, or the first of the addition and subtraction first, then we're maintaining that rule.
1+2-3 a+(b-c)
=
1+2-3 (a+b)-cAnd for this one it's the same. algebraically
1-2+3 (1-2)+3 (a-b)+c
=
1-2+3 (1-2)+3 (a-b)+cAnd I suppose finally. 1-2-3 and 1/2/3 And regardless of whether doing strictly ordered PEDMSA or traditional PEMDAS it's (1-2)-c and (1/2)/3 so same there.
I'm not sure whether those are all the possibilities.
That may then leave the question of what explains the algebra e.g. the rule that
a*(b/c) = (ab)/c
and
a+(b-c)=(a+b)-cAlso it's a parsing convention that seems to have developed late 20th century, rather than a fundamental rule of mathematics.
$\endgroup$ 7 $\begingroup$Most of this is above my head, but I take issue with the OP that 3-2+1 cannot be done with addition before subtraction.
Subtraction is just adding a negative number, so that calculation is actually (+)3+(-2)+1
No matter what order you do that on your going to get the same result.
3+(-2)+1 = 2
3+1+(-2) = 2
(-2)+3+1 = 2
(-2)+1+3 = 2
1+(-2)+3 = 2
1+3+(-2) = 2
Multiplication is just repetitive addition,
8×3 = 3+3+3+3+3+3+3+3
Division is inverse multiplication so
8÷3 = 8×⅓ = ⅓+⅓+⅓+⅓+⅓+⅓+⅓+⅓
Now division before multiplication is more difficult.
6÷2×3
This is either
(6÷2)×3 =
(6×½)×3 =
(½+½+½+½+½+½) + (½+½+½+½+½+½) + (½+½+½+½+½+½) =
3+3+3 = 9
Or it is
6÷(2×3) =
6÷6 = 6×⅙ =
⅙+⅙+⅙+⅙+⅙+⅙ = 1
In that example, the division it written first, so reading left to right it would be done first, and the answer should be 9
But what if the equation was written the other way around?
3×6÷2 ???
LTR
(3×6)÷2 =
18÷2 =
18 × ½ =
½+½+½+½+½+½+½+½+½+½+½+½+½+½+½+½+½+½ = 9
DBM
3×(6÷2) =
3×(6×½) =
(½+½+½+½+½+½) + (½+½+½+½+½+½) + (½+½+½+½+½+½) =
3+3+3 = 9
So interestingly, in the latter calculation the order made no difference, but in the former, it made a huge difference.
I can't actually say, based on above that DBM will always yield the incorrect result!
$\endgroup$ 8