# Order of operations - why are they in the order they're in?

I understand the order of operations, but why are they ordered the way they're ordered? Is there a particular reason why multiplication should have a higher precedence than subtraction, other than to prevent ambiguity?

Edit: I'm a curious software developer that's relatively lousy at math. A simple explanation that your grandma could understand would be very welcome. :-)

• There's some relevant information here: mathforum.org/library/drmath/view/52582.html May 26, 2011 at 5:12
• I believe it is just convention - really one should use brackets. A similar convention exists in "real life": There is a sign on some of the toilets in my maths department which reads "For the use of female staff and postgrads only". Being a male postgrad, I am yet to work up the courage to use these loos! Aug 26, 2011 at 13:38
• Parentheses are certainly natural enough, and once you accept these, multiplication over addition makes the formula 5*(4 + 2) = 5*4 + 5*2 pretty nice.
– user2055
Jun 9, 2014 at 19:33
• Multiplication is just shorthand for addition - so 2 x 3 + 4 is actually 2 + 2 + 2 + 4 (alternatively can be written as 3 + 3 + 4). This leaves no ambiguity as to which operation is to be performed first.
– btk
Mar 21, 2016 at 16:47

The precedence rules allow efficient representation of polynomial expressions in a concise normal expanded form. If you reversed the precedence of multiplication then the notation would be more efficient for factored polynomial expressions. But, generally, polynomial operations are much less efficient in factored form (compare, e.g. equality testing and addition).

The reason that polynomial rings are ubiquitous is their universality (they are free $\rm\:R$-algebras). So, for example, any polynomial identity that you prove true in $\rm\:\mathbb Z[x]\:$ will hold true over any ring, e.g. the binomial theorem.

• I'm not a mathematician; I'm a software developer. Is there a simpler version of what you wrote? May 25, 2011 at 14:47
• @Matty: With the standard convention, $p(x)=a_0 + a_1 x + a_2 x^2 + \dots + a_n x^n$ doesn't need any parentheses. May 25, 2011 at 15:37
• @Hans, yeah, but p(x)=+a_0+*a_1x+...*a_n x^n doesn't need parentheses either, nor does a_0a_1x*+ a_2 x^2*+... a_n x^n*+ doesn't need parentheses either. In other words, basically all (if not actually all) expressions in Polish and reverse Polish notation allow for efficient representation of polynomial expressions in a concise normal expanded form. So, why even have an order of operations instead simply switching to either Polish or reverse Polish notation? May 28, 2011 at 2:51
• @Doug Yes, there is a lot that you could do if you completely abandon infix notation. There are reasons that we don't. Given that we do use infix notation, we want an order of operations so that we can drop as many parentheses as we can in the most common situations to give the most human readable expressions that convey the most important information in the fastest way. Given the ubiquity of polynomials (and the merits/demerits of their different representations), the current choice makes a lot of sense. May 28, 2011 at 3:46
• @Doug: The argument would have been more convincing if you hadn't written the powers of $x$ with infix notation. ;-) May 28, 2011 at 7:41

I am sorry that I am over a year late in reading these posts. It is a great pitty that so few people understand that order of operations is derived from the basic rules of mathematics. Let us look at a simple example: $2 + 3 \times 4$. Because multiplication is by definition repeated addition, $3 \times 4$ is the same as $4 + 4 + 4$. So I could rewrite $2 + 3 \times 4$ as $2 + 4 + 4 + 4$. Then I just add left to right and get $14$. That is the same as using the natural order of operations and performing the multiplication first. $2 + 3 \times 4 = 2 + 12 = 14$. Because exponents are simply repeated multiplication, they are performed before multiplication. Parentheses are used to form groupings that are to be performed before other operations. Thus $2(3+4)$ indicates that $3+4$ must be done before multiplying by $2$. Thus the order: parentheses first, exponents second, mutiplication and division third, and save the lowest level operations of addition and subtraction for last.

• Nice explanation ! Jan 25, 2013 at 18:13
• I don't understand why your argument precludes someone from using the convention that $2 + 3 \times 4 = 5 \times 4 = 4 + 4 + 4 + 4 + 4$. Jan 25, 2013 at 18:34
• @MichaelJoyce is right. The order of operations is not derived from the basic rules of mathematics. It is merely a convention which makes sure everyone arrives at the same result. The reason we landed on the convention that multiplication should precede addition, probably has to do with the intuition that one should solve grouped terms before more primitive terms, such as Mark Monroe proposes. Although doing it the other way around would have worked just as well. It's just a matter of notation and how we interpret it. See my answer for a more lengthy explanation. Jun 9, 2014 at 17:12
• @MichaelJoyce - because multiplication is shorthand for addition, and using this shorthand implies that it must be evaluated first.
– btk
Mar 21, 2016 at 16:51
• This was the answer I believe is most relevant... Multiplication comes before additions because multiplication is a shorthand notation for a bunch of additions. Dec 1, 2018 at 11:01

I don't think there is any mathematical reason. The order of operations is only a matter of notation to save some brackets.

Careful: a typical calculator does not have a different order of operations but none at all instead. So

5 - 4*3 on a calculator is actually (5-4)*3 while with our convention for algebra it is 5-(4*3).

Both assumptions are valid, the latter one is just the more common form.

• There's got to be a logical reason. I find it hard to believe that it was just thrown together randomly! May 25, 2011 at 12:58
• It depends on the calculator whether you get 3 or -7. Microsoft's calc.exe will give different answers depending on whether you are using the standard or scientific view. May 25, 2011 at 16:39

I would say depending on which one is distributive with respect to which other one.

Without parenthesis, you just assume that the expression is expanded as much as possible.

Some Background: Why have an order of operations at all?

The order of operations exists:

1. To be able to write down the same expression in different ways.
2. So that everyone will (still) arrive at the same answer.

The same calculation can be written in different ways: 1+2*2, or 2*2+1, but it should always give the same answer. The problem is that the answer will depend on how you interpret it, and that will influence how you solve it. If you just go left-to-right and joining two and two numbers, you will get (1+2)*2 = 3*2 = 6 in the first case and (2*2)+1 = 4+1 = 5 in the second case.

So mathematicians have agreed on a standard way of interpreting the expression (what parts belong together and not), independently of how it is written down. This standard way is called "The order of operations", which says you should solve an equation in this order:

1. Parenthesis
2. Exponentials
3. Multiplication and division
4. Addition and subtraction

But why are the operations in the order they are in?

The order of operations is ordered the way it is simply by convention (agreement). An author could have used parenthesis for every term of an expression, to specify precisely how he intended the expression to be calculated. Instead, a default order was agreed upon, so that one may remove parentheses, and still have people interpret the expressions in the same manner. The default order of operations is arbitrary. The order could have been different, and worked quite as well.

History: "I would say that the rules actually fall into two categories: the natural rules (such as precedence of exponential over multiplicative over additive operations, and the meaning of parentheses), and the artificial rules (left-to-right evaluation, equal precedence for multiplication and division, and so on). The former were present from the beginning of the notation, and probably existed already, though in a somewhat different form, in the geometric and verbal modes of expression that preceded algebraic symbolism. The latter, not having any absolute reason for their acceptance, have had to be gradually agreed upon through usage, and continue to evolve." - http://mathforum.org/library/drmath/view/52582.html

The natural rules arose naturally, and people used it in the same way. Probably because it is intuitive to solve the most grouped terms of the expression first, so you get a bunch of more primitive terms which can then be added together later.

Exponentials are just grouped multiplication: 5^3 = 5*5*5

Multiplication is just grouped addition: 5*3 = 5+5+5

So, exponentials are grouped multiplication which is grouped addition. When you solve exponential terms out all the way, you are just left with a bunch of numbers which are added together.

 The important thing is that the author and the reader of an expression has the same interpretation. If you calculated addition before multiplication, then an expression like 5*5+1 would suddenly mean something entirely different, if the author had presupposed multiplication before addition. If the author knew that the reader would interpret and calculate addition before multiplication (if there were no parentheses to explicitly state the order), he would have to write it as (5*5)+1, to force the reader to multiply before adding. And vice versa.

If you punch $5-4\times3$ into a (typical) calculator, you'll get $3$, not $-7$, so evidently there are situations where subtraction takes precedence over multiplication. This suggests it's just a convention, and that it could have gone the other way.

• I know the rule exists to prevent ambiguity, but I'm curious as to the logical reasoning behind the order of the order of operations. Is there a reason addition shouldn't have a higher precedence than division? May 25, 2011 at 13:04
• If you get 3 then the precedence is left-to-right rather than depending on the operation. May 25, 2011 at 16:40
• I can only speak for myself regarding what's typical in this case, but I don't think I've ever encountered a calculator which would answer 3 if you punch "5, minus, 4, times, 3, equals". May 26, 2011 at 7:06
• @Hans: I haven't ever encountered a physical calculator which wouldn't answer 3. (Except possibly scientific calculators which have keys for parentheses etc… certainly no "normal" calculators.) May 26, 2011 at 13:06
• @ShreevatsaR: Well, I guess that means that I've mostly dealt with scientific calculators then... May 26, 2011 at 13:25

There's a clear reason for why there must be some order of operations (to avoid ambiguity), but which order of operations is agreed upon is a mere convention.

I think that expression syntax directly comes from the language syntax. In natural language multiplication is often represented without conjunctions as in "three dogs". I think that an explicit operator for multiplication (as the $\times$ sign) is only used for didactic reason to make it clear that an operation is involved. The operator $\times$ becomes $\cdot$ and then disappears when you progress into mathematics. On the other hand addition is represented by conjuctions as in "one apple and two bananas": $a + 2 b$. It is clear that adjectives have higher precedence than conjunction.

This is confirmed by the fact that the order of operations is much less clear when we mix addition and subtraction or multiplication and division. The language, in such cases, becomes ambiguous. So mathematicians need to agree upon a convention.

I would also point out that even mathematicians don't follow a strict rule in operators precedence, there are many cases where common sense comes before any rule. For example anyone would agree with these interpretations: $$\sin xy = \sin(xy)$$ while $$\sin x \sin y = (\sin x)(\sin y).$$

When browsing the posts flaired Mathematics at r/askscience, I lighted upon the same question!

u/KyleG substantiates this comment:

It's arbitrary because all of written math is arbitrary symbolic notation invented by humans. There are plenty of programming languages and other types of notation systems that don't follow PEMDAS. For example, Reverse Polish Notation (which was favored by early computer scientists) is written "operand operand operator." So, for example 3 4 + 7 / evaluates to 1 because, from left to right, 3 4 + evaluates to 3+4=7. Then you have 7 /, so the 7 that came from 3 4 + you divide by 7.

http://en.wikipedia.org/wiki/Reverse_polish_notation

For what it's worth, both exponents and parentheses are relatively recent additions to math notation, so it makes sense that our arbitrarily defined writing system would adapt to new symbols by saying "everything works exactly the same as before, but before doing that, we have to do the new stuff and get it out of the way."

Never the less, u/paolog ventures a reason for PEDMAS:

Essentially we use PEDMAS because we've found it to be useful in arithmetic and algebra (although there are areas of mathematics where this isn't necessarily the case). There's nothing to stop us from using, say, ~~SAMDEP~~ PSAMDE if we wanted to, but things would get very messy if we did.

Let's just consider the DMAS bit. Why do multiplication and division come before addition and subtraction? Because it makes sense to do it that way. I might send you out to buy me three half-dozen boxes of eggs and two boxes containing a dozen. The total number of eggs is 3 x 6 + 2 x 12. The real-life situation this describes requires us to interpret this as (3 x 6) + (2 x 12), or 42 in total, rather than 3 x (6 + 2) x 12. Multiplication before addition occurs naturally all the time, so it makes sense to do the operations in that order.

Furthermore, PEDMAS allows us to simplify algebra. We can write an expression like:

$$c = 4a^2 + 5b + 1$$

and we know this means we have compute $$a \times a \times 4$$ and $$5 \times b$$, add these together and add 1. If the order were SAMDEP, this would have to be written as:

$$c = [4(a^2)] + (5b) + 1$$

which is less easy to read.

Why do things work out this way? Well, multiplication is really repeated addition, and exponentiation is just repeated multiplication. Suppose a = 3 in the above expression, and we expand it out:

$$c = 4 \times 3^2 + 5b + 1$$

  = 4 x (3 x 3) + b + b + b + b + b + 1

= 3 x 3 + 3 x 3 + 3 x 3 + 3 x 3 + b + b + b + b + b + 1

= 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + b + b + b + b + b + 1


Now we have only one operation so we can do the additions in any order, but you can see that if we go backwards to the original expression, each time we collect up addends into a multiplication, we get a single product that needs to be added to another result. So we end up adding together products, meaning multiplication must come before addition. Exponentiation bundles together multiplicands ready for multiplication by other terms, hence the exponentiation needs to be done before the multiplication.

If we consider integers only, division can be viewed as just repeated subtraction, and subtraction is just addition of negative terms, hence division comes at the same level as multiplication and subtraction at the same level as addition.

Parentheses give us a way of overriding the existing order, so P has to come before everything else so we can more easily solve word problems like the following: "How many ounces of vegetables are there in three bags of mixed vegetables each containing four ounces of carrots and six ounces of peas?" (Answer: $$3 \times (4 + 6)$$ oz = 3 x 10 oz = 30 oz.) Without parentheses, we would have to write $$3 \times 4 + 3 \times 6$$, essentially expanding the parentheses. Imagine if the parentheses contained some much more complicated expression - we would need to write it out in full several times over if parentheses weren't available.

TL;DR: For integers, exponentiation is repeated multiplication and collects up multiplicands ready for multiplication by or addition to other terms, while multiplication is repeated addition and collects up addends for addition to other terms. Hence it is useful to do exponentiation before multiplication (and division), and multiplication before addition (and subtraction). Parentheses give a way of overriding the order.

u/DirichletIndicator ventures another reason - polynomials.

It's because of polynomials.

Polynomials used to be one of the most studied objects back when this sort of notation was being formalized. Originally you'd have to write them like

$$(2(x^2 )) + (3x) - 5$$

which is just ridiculous. People are lazy, so they eventually dropped the parentheses and experienced mathematicians knew what they meant. But for new students, they had to explain how to read these nonsensical shorthands like

$$2x^2 + 3x - 5.$$

Well, the exponent is applied to x before you multiply it by 2. Then you multiply 2 by $$x^2$$ and 3 by x. Then you add everything together.

It's really nothing more than a typesetting rule, like "always put the period before the quotation mark." It was, at one point, the most convenient way to do things, and at some point it got formalized.

1. To illustrate your example with substraction and multiplication, denote them as two variable functions: $S(a,b)=a-b,\ P(a,b)=a\cdot b$. Then to calculate $a-b\cdot c$(without any brackets), we would have $S(a,P(b,c))$. In order to calculate the result, we need to find $P(b,c)$ first.

2. There are many operations defined with the aid of the simpler ones: multiplication is defined using addition; powers are defined using multiplications. It is then natural to give priority to the elevated operations, since they depend on the simpler ones.

3. Think practical. In a warehouse there are 2000 bottles of Coca cola, in boxes of 20 pcs. Someone takes out 30 boxes. How many bottles are left? Answer: $2000-30\times 20$. If we calculate $2000-600=1400$ we get the practical result right(we go and count the remaining bottles to see that... ) . If we calculate substraction first we get $1970\times 30>2000$, and we see that something is wrong.

I think the third aspect is the most important, since mathematics is made to help modelling different things we encounter in real life. Not all maths is abstract. If you take the operations and change their priorities, you will get results which do not correspond with reality.

• Point 1, unless I'm misunderstanding it, is circular. We need to find $P(b,c)$ first simply because by convention $a-b\cdot c$ means $S(a,P(b,c))$ and not $P(S(a,b),c)$. Point 2 doesn't sound terribly convincing to me. And point 3 is completely arbitrary: In a warehouse, there are $100$ boxes of coke, in boxes of 20 bottles each. Someone takes out $30$ boxes. How many bottles are left? Answer: $(100-30)\times20$. If we calculate $100-30\times20$ instead, we get $100-600<0$, and we see that something is wrong. May 25, 2011 at 13:29
• I wanted to underline that math should be in connection with the things that surround us. That was just an example. May 25, 2011 at 14:22
• The point is that it's only the existing convention that lets us write $2000-30\times 20$ for $2000-(30\times 20)$, and you're arguing for it in terms of itself. That's a circular argument. (BTW: the word is subtraction, not substraction.) May 25, 2011 at 15:43
• I'm so out of my depth with all of the answers to this question. Disregarding points 1 and 3, is point #2 in Beni's answer correct? May 25, 2011 at 16:09
• @Matty: I think #2 has some merit, but take it with a grain of salt. Exponentiation has high precedence with respect to the base but not with respect to the exponent; that is, $a\cdot b^c$ means $a\cdot(b^c)$, but $a^{b\cdot c}$ means $a^{(b\cdot c)}$. Also, juxtaposition can stand for many things other than ordinary multiplication (for instance, composition of functions), and yet it always takes precedence over addition. In Boolean algebra, mutliplication is used to denote $\land$ and addition for $\lor$, which are symmetric to each other, yet the same precedence convention applies. May 26, 2011 at 5:06