[The title is a half-joking reference to Edsger Dijkstra’s classic paper, Go To Statement Considered Harmful; see here for more context.]
Everyone is probably familiar with the so-called “order of operations”, which is
a collection of rules that reflect conventions about which procedures to perform first in order to evaluate a given mathematical expression.
(the above quote is from the Wikipedia page on Order of Operations). If you grew up in the US, like me, you might have memorized the acronym PEMDAS; I have recently learned that people in other parts of the world use other acronyms, like BEDMAS. In any case, these mnemonics help you remember the order in which you should conventionally perform various arithmetic operations, right?
Makes sense, right? We did the stuff in parentheses first, then the exponent, then the multiplication and division (from left to right), then the addition.
OK, pop quiz: what is the value of
Of course it is , you say. Aha, but did you follow the order of operations? I thought not. Supposedly the order of operations tells you that you have to perform the exponentiation before the multiplication, but I am willing to bet that you skipped straight over the exponentiation and did the multiplication first! Really, you should be ashamed of yourself.
Another pop quiz: what is the value of
Well, let’s see:
Easy peasy. But wait, did you notice what I did there? I did one of the additions before I did the last multiplication! According to the “order of operations” this is not allowed; you are supposed to perform multiplication before addition, right??
One more quiz: solve for in the equation
Of course we can proceed by subtracting from both sides, resulting in , and then dividing both sides by , finding that is the unique solution.
How did we know not to add the and the , resulting in the bogus equation ? Because of the order of operations, of course… but wait, what does the order of operations even mean here? Did you notice that we never actually performed the multiplication or addition at all?
My point is this: casting the “order of operations” in performative terms—as in, the order we should perform the operations—is grossly misleading.
You might think all my examples can be explained away easily enough—and I agree—but if you take literally the idea of the order of operations telling us what order to perform the operations (as many students will, and do), they don’t make sense. In fact, I would argue that saying the order of operations is about the order of performing the operations is worse than misleading, it is just plain wrong.
So what is it, really?
I made the title of this post provocative on purpose, but of course I am not actually arguing against the order of operations in and of itself. We certainly do need to agree on whether should be or . But we need a better way of explaining it than saying it is the “order in which we perform the operations”.
Any mathematical expression is fundamentally a tree, where each operation is a node in the tree with the things it operates on as subtrees. For example, consider the example expression from the beginning of the post. As a tree, it looks like this:
This tells us that at the very top level, the expression consists of an addition, specifically, the addition of the number and some other expression; that other expression is a division (quick check: do you see why the division should go here, and not the multiplication?), and so on.
However, pretty much all the writing systems we humans have developed are linear, that is, they consist of a sequence of symbols one after the other. But when you go to write down a tree as a linear sequence of symbols you run into problems. For example, which tree does represent?
Without further information there’s no way to tell; the expression is ambiguous.
There are two ways to resolve such ambiguity. One is just to add parentheses around every operation. For example, when fully parenthesized, the example expression from before looks like this:
With one set of parentheses for every tree node, this is an unambiguous way to represent a tree as a linear sequence of symbols. For example, in the case of , we would be forced to write either or , fully specifying which tree we mean.
But, of course, fully parenthesized expressions are quite tedious to read and write. This leads to the second method for resolving ambiguity: come up with some conventions that specify how to resolve ambiguity when it arises. For example, if we had a convention that says has a higher precedence than (i.e. “comes before”, i.e. “binds tighter than”) , then is no longer ambiguous: it must mean the left-hand tree (with the at the top), and if we wanted the other tree we would have to use explicit parentheses, as in .
Of course, this is exactly what the “order of operations” is: a set of conventions that tells us how to interpret otherwise ambiguous linear expressions as unambiguous trees. In particular, the operations that we usually talk of being “performed first” really just have higher precedence than the other operations. Think of the operations as “magnets” trying to attract things to them; higher precedence means stronger magnets.
I wouldn’t necessarily phrase it this way to a student, though. I have never taught elementary or middle school math, or whichever level it is where this is introduced, but I think if I did I would just tell them:
The order of operations tells us where to put parentheses.
The nice thing is that if you think about adding parentheses instead of performing operations, then the order of operations really does tell you what order to do things: first, add parentheses around any exponentiations; then add parentheses around any multiplications and divisions from left to right; finally, add parentheses around any additions and subtractions from left to right. Of course, if the expression already has any parentheses to begin with, you should leave them alone. This also explains what is “different” about the parentheses/brackets at the beginning of PEMDAS/BEDMAS: you can’t “perform” parentheses like you can “perform” the other operations. But from this new point of view, you don’t even need to include them in the mnemonic: they are different because the whole point is to add more of them. Of course, as students become familiar with this process, at some point they no longer need to actually write out all the parentheses, they can just do it in their heads.
To be honest I am not sure exactly what the takeaway should be here. I do think we are doing students a disservice by teaching them the misleading idea that the “order of operations” is about the order in which to perform the operations, and sadly it seems this idea is quite widespread. But I am not exactly sure what should be done about it. If you are a mathematics educator—either one who teaches students about the order of operations, or one who has witnessed the effects of their understanding on later subjects—I’d love to hear your responses and ideas!
> To be honest I am not sure exactly what the takeaway should be here.
“Taking a rule to its logical extreme and refusing to interpret it rather as a helpful heuristic, as any actual, normal human being would, can lead to unintended results”?
I’m being facetious, of course, but that said I also think you’re splitting hairs where none need to be split.
I take your point, but of course I disagree: I do not think every “actual, normal human being” in fact interprets this in the right way. And this is mathematics we’re talking about; don’t we value precise, logically sound definitions? Why do we have to resort to just a “helpful heuristic” in this case?
The people who share viral “can you solve this” memes with me disagree with you.
Easy enough to say as a mathematically mature person. From the perspective of a kid learning math in elementary school, the ambiguity of the order of operations is a pedagogical problem
If your objection to calling it “the order of operations” is that people sometimes evaluate the expression by some means other than performing precisely those operations in that order (and are not wrong to do so), then why is that not an equally good objection to calling it “telling us where to insert parentheses”, since many people will also evaluate the expression by some means other than actually rewriting it with extra parentheses (and, again, are not wrong to do so)?
Computer language specifications have had an answer to this for decades: the “as if” rule, as seen in e.g. C99 §220.127.116.11. The correct result of the expression *can* be obtained by performing the specified operations in the order given by the precedence rule. Alternative evaluation techniques are not forbidden, but they are assessed for correctness based on whether they reliably deliver the same result as the reference technique.
I agree that if you are only worried about the precise order of evaluation, or whether or not you actually insert all possible parentheses, then you can very reasonably adopt an “as if”-type rule.
But that is NOT my main objection! My objection is that the order of operations is not really about evaluation at all. The algebra example I gave is a much better illustration than the first examples just involving arithmetic. The order of operations still tells us how we should interpret algebraic expressions, even though we are not actually going to evaluate them.
Pingback: Order of operations considered harmful - Nevin Manimala's Blog
I’ve been tutoring young people in mathematics for about 25 years, and I have definitely encountered confusion among some of them, because of the ‘order of operations’ approach, which some of them take as an imperative: you MUST do all the multiplications/divisions before you can do any additions/subtractions. The ‘parentheses’ (over here, ‘brackets’) approach sounds like a good way to overcome this problem.
Coincidentally, Dijkstra has a note on a related topic: https://www.cs.utexas.edu/~EWD/transcriptions/EWD13xx/EWD1300.html