5
$\begingroup$

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$
  • $\begingroup$ I would like to see an example of multiplication before division giving wrong answers. Not being snide here, I just just need to one good example where the $\times$ before $\div$ gives the wrong answer. Likewise with $+$ before $-$. $\endgroup$ – J. W. Perry Nov 4 '13 at 1:10
  • $\begingroup$ @J.W.Perry $6/2\cdot 3$ should yield $9$, but if you do multiplication before division, you get $6/(2\cdot 3) = 1$. $\endgroup$ – Daniel Fischer Nov 4 '13 at 1:13
  • $\begingroup$ @J.W.Perry 8/2*4 If you it right then (8/2)*4=16. that's different to doing multiplication before division where you get 8/(2*4)=1. google does it right=16. $\endgroup$ – barlop Nov 4 '13 at 1:14
  • 1
    $\begingroup$ @J.W.Perry well when doing the left to right rule - as you should, then you don't do M before D or D before M. My question is regarding actually doing D before M. i.e. one before another, i.e. without the left to right rule. $\endgroup$ – barlop Nov 4 '13 at 1:16
  • 1
    $\begingroup$ Ahh I see what you mean on $8 \div 2 \cdot 4$. The algorithm, with the repeated left right scanner might be better stated as P - E - MD - AS (MD = M or D). I have trouble thinking outside of the "program it" perspective sometimes. You have posed a decent question. $\endgroup$ – J. W. Perry Nov 4 '13 at 1:32
4
$\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$
  • $\begingroup$ (sticking to any or what I think is ur,definition of language) I'm not modifying the language or creating a new language,it's possible if one breaks the interpretation I "suggest"(could call it strict PEDMSA),that one would have to modify the language, but that has yet to be done in my case.U say "once you decide to modify an extant language/interpreter....all bets are off" Well to put it in terms of bets, the bets are on,i'm saying I bet you that u can't show it giving the wrong result.U say "If you modify the interpreter,u probably need to modify the language." <-- Seems not in this case. $\endgroup$ – barlop Nov 4 '13 at 10:50
3
$\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$
  • $\begingroup$ Looking right at the beginning of your answer I see it misinterprets me. I am saying to do Parentheses first. The left to right rule that i'm referring to doing or not doing, is the one regarding MD and SA, and whether or not one does them in the order they occur in the PEDMSA formula vs (the normal left to right rule with MD and SA) to do them in the order they occur in the mathematical expression. I'm saying that with PEDMSA you can do them in the order they occur in the PEDMSA formula i.e. paren first, then exponent then division then multipilication then subtraction then addition. $\endgroup$ – barlop Sep 1 '17 at 18:33
  • $\begingroup$ whereas with PEMDAS if you do it paren then exponent then multiplication then division then addition then subtraction, you're not getting the right answer. 'cos MD and AS have to be evaluated left to right in the order they occur in teh arithmetic expression which can sometimes be DM or SA. So PEMDAS is never literally P,E,M,D,A,S Whereas PEDMSA can be literally P,E,D,M,S,A $\endgroup$ – barlop Sep 1 '17 at 18:34
  • $\begingroup$ Your first sentence and your following two examples misinterpret me. $\endgroup$ – barlop Sep 1 '17 at 18:35
  • 1
    $\begingroup$ @barlop: I'm afraid you are the one who does not know what you're talking about. You cannot evaluate "$6/3/2$" correctly without a left-to-right rule. You didn't specify that anywhere in your question or answer. And as I stated clearly your proof is very incomplete. If you do not understand it, ask to clarify. But don't assume that I did not grasp your question. Furthermore, you said that LoseTheGame's answer was essentially correct, but that's nonsense (and 4 other people agree with me and it's now deleted); he/she swapped operands. That makes your answer's first paragraph wrong too. $\endgroup$ – user21820 Sep 2 '17 at 10:17
  • $\begingroup$ I didn't say you can evaluate 6/3/2 "without a left to right rule" at least not in the sense that you mean. I am not talking about evaluating 6/3/2 by doing anything other than the first division operator first, and the second division operator second. Please quote exactly what I said(that also enables me to see the context of it), and also please make sure you understand what i've said. If you think that I am saying you can evaluate 6/3/2 by going through the expression right to left, then you have not understood what I said. $\endgroup$ – barlop Sep 2 '17 at 16:21
0
$\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/c

Taking 1/2*3 so a/b*c That'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)*c

With 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)-c

And 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)+c

And 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)-c

Also it's a parsing convention that seems to have developed late 20th century, rather than a fundamental rule of mathematics. https://www.quora.com/Is-the-order-of-operations-unclear-for-expressions-like-20-2-5+5

$\endgroup$
  • $\begingroup$ This is a great answer, but let me add a more thorough argument to show why PEDMSA (or rather DMSA, since that's the part at issue) will always work. On the one hand, addition and multiplication are associative; so if we were only dealing with MA, then we wouldn't even have to specify left to right. On the other hand, subtraction and division are just addition and multiplication by opposites and reciprocals, respectively. For them, the left-to-right rule makes this operation of taking the opposite/reciprocal always apply directly to the following number. ... $\endgroup$ – Toby Bartels Jul 26 '16 at 19:57
  • $\begingroup$ … So what does this mean when the operations are mixed? It means that any sequence of multiplications and divisions or of additions and subtractions can be interpreted as a sequence of just multiplications or just additions, whose order doesn't matter. You can rearrange those however you like, so the only thing that the rule has to guarantee is that taking opposites/reciprocals applies to directly to the following number. That means that no multiplication or division can come first to the right of a division, and no addition or subtraction can come first to the right of a subtraction. … $\endgroup$ – Toby Bartels Jul 26 '16 at 20:01
  • $\begingroup$ … Whether you say division before multiplication or multiplication and division together, as long as it's left to right, then nothing to the right of a division will come before it. But if you say multiplication before division, then a multiplication to the right of a division can come before it, which is wrong. And that's the only thing that matters, so DMSA and (M=D)(A=S) are both fine, while MDAS is wrong. Now we just need a mnemonic for PEDMSA! $\endgroup$ – Toby Bartels Jul 26 '16 at 20:04
  • $\begingroup$ @TobyBartels I see what you mean.. If you have a division to the right e.g. expression 1*2/3 and you do division first, but convert it into the identical reciprocal so 2/3 becomes 2*(1/3), so that expression becomes 1*2*(1/3) then that's the same as if you had done the multiplication first in that expression (1*2)/3. So division first when it's to the right is the same as multiplication first when it's to the left, becaues of the reciprocal rule.. ... $\endgroup$ – barlop Jul 26 '16 at 22:46
  • $\begingroup$ @TobyBartels Similarly if subtraction is to the right but done first , so expression of 4+3-2 is 4+(3-2) and it's done by converting the subtraction into an addition so 3-2 = 3+(-2). Then the expression is 4+3+(-2) then since addition is associative, we see that 4+(3+(-2)) is the same as doing the addition first when it's to the left of that subtraction (4+3)+(-2) Whereas if we have this expression 5-4+2 then no doubt if we did the addition of 4+2 first, it doesn't work, it looks wrong too since one would be snatching the 4 away from the minus, and subtraction isn't associative. $\endgroup$ – barlop Jul 26 '16 at 22:56
-1
$\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$
  • $\begingroup$ you skipped 3-(2+1) , that gives you not 4.. $\endgroup$ – barlop Feb 24 at 12:41
  • $\begingroup$ And your missing the point. Without any parenthesis in the base equation, and as there is no multiplication, -2 can only be -2. $\endgroup$ – Escribblings Feb 24 at 18:55
  • $\begingroup$ As such, the 3 numbers in this equation are +1 +3 and -2, it matters not in which order you put them, it will always sum to 2 (not 4 as I originally posted above - my bad). By putting the 2 inside the parenthesis as you have shown, you have changed it from -2 to +2 and that changes the entire equation $\endgroup$ – Escribblings Feb 24 at 18:58
  • $\begingroup$ I am not suggesting that you should calculate it like 3-(2+1)! Also, your answer changes the entire thing to addition, i'm aware you can do that, and then indeed, the equation becomes commutative i.e. a+b+c can be done in any order. You are adding to the number of operators in the expression when you do that e.g. 3-2+1 has 2 operators , but 3+(-2)+1 has 3 operators. $\endgroup$ – barlop Feb 24 at 21:50
  • $\begingroup$ Also, you say that if you do 3-(2+1) then i'm changing -2 to +2, well, you're interpreting the - as a unary operator, but it isn't really, 'cos then it'd be 3(-2)-1 so you then have no operator between the 3 and the (-2). unless you convert it into an addition which is what you did. 3-2+1 or 3-(2+1) are both different, but they have 2 binary operators. (and maybe some implicit unary operators) $\endgroup$ – barlop Feb 24 at 21:58

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.