Order of operations considered harmful

[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?

For example:

\begin{array}{rl} & 1 + 3 \times (5 - 3)^4/2 \\ = & 1 + 3 \times 2^4 / 2 \\ = & 1 + 3 \times 16 / 2 \\ = & 1 + 48 / 2 \\ = & 1 + 24 \\ = & 25.\end{array}

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

3 + 0 \times 37^{984}?

Of course it is 3, 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

2 \times 7 + 3 \times 5 + 4 \times 6?

Well, let’s see:

\begin{array}{rl}& 2 \times 7 + 3 \times 5 + 4 \times 6 \\[0.5em] =& 14 + 3 \times 5 + 4 \times 6 \\[0.5em] =& 14 + 15 + 4 \times 6 \\[0.5em] =& 29 + 4 \times 6 \\[0.5em] =& 29 + 24 \\[0.5em] =& 53\end{array}

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 y in the equation

20 = 2 + 3y.

Of course we can proceed by subtracting 2 from both sides, resulting in 18 = 3y, and then dividing both sides by 3, finding that y = 6 is the unique solution.

How did we know not to add the 2 and the 3, resulting in the bogus equation 20 = 5y? 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 1 + 2 \times 3 should be 7 or 9. 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 1 + 3 \times (5 - 3)^4/2 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 1 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 3 \mathbin{\triangle} 5 \mathbin{\square} 2 represent?

Without further information there’s no way to tell; the expression 3 \mathbin{\triangle} 5 \mathbin{\square} 2 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:

(1 + ((3 \times ((5 - 3)^4))/2))

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 3\mathbin{\triangle} 5 \mathbin{\square} 2, we would be forced to write either (3\mathbin{\triangle} (5 \mathbin{\square} 2)) or ((3\mathbin{\triangle} 5) \mathbin{\square} 2), 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 \square has a higher precedence than (i.e. “comes before”, i.e. “binds tighter than”) \triangle, then 3 \mathbin{\triangle} 5 \mathbin{\square} 2 is no longer ambiguous: it must mean the left-hand tree (with the \triangle at the top), and if we wanted the other tree we would have to use explicit parentheses, as in (3 \mathbin{\triangle} 5) \mathbin{\square} 2.

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.

What next?

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!

About Brent

Assistant Professor of Computer Science at Hendrix College. Functional programmer, mathematician, teacher, pianist, follower of Jesus.
This entry was posted in arithmetic, teaching and tagged , , , , , , . Bookmark the permalink.

7 Responses to Order of operations considered harmful

  1. Anonymous Curmudgeon says:

    > 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.

    • Brent says:

      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?

    • Charlie Watson says:

      The people who share viral “can you solve this” memes with me disagree with you.

    • Anonymous says:

      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

  2. Simon Tatham says:

    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 §5.1.2.3. 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.

  3. Brent says:

    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.

  4. Pingback: Order of operations considered harmful - Nevin Manimala's Blog

Leave a reply. You can include LaTeX $latex like this$. Note you have to literally write 'latex' after the first dollar sign!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.