Ambiguous PEMDAS
Oliver Knill
April/9/2014
Abstract: even in mathematics, ambiguities can
be hard to spot. The phenomenon seen here in arithmetic goes beyond the usual
PEMDAS rule and illustrates an ambiguity which can lead to heated arguments and discussions.

What is 2x/3y1 if x=9 and y=2 ?
Try to answer this question before continuing to read.
Did you get 11 or 2?
If you got 11, then you are in the BEMDAS camp,
if you got 2, you are in the BEDMAS camp.
In either case you can relax because you have passed the
test. If you got something different you are in trouble although!
There are arguments for both sides. But first a story.
A true story
I got today following lovely story from the director of
curriculum of some some school district:
"The problem 2x/3y1 with x=9 and y=2 was actually posed for a 5th
grade homework question and it is interesting how much debate has
occurred between our parents. The students who had help from parents
had the answer of 2. The teacher explained that the correct answer
was 11."

Who is right?
I wrote back:
"It depends on how the brackets are understood. There are two
interpretations:
x=9; y=2;
(2x/3)y1 gives 11
2x/(3y)1 gives 2
It is not clear what the textbook had intended with the 3y.
As written, it can be interpreted both ways. Yes, one could argue that
without brackets the given order matters. One can however also argue that
"3y" is a unit which belongs together.
So, everybody is right and that the textbook problem has just been unclear."
This is actually a really fun topic. Lets expand a bit on it and explain
why we can argue both ways. I bet most humans get the answer 2.
[Update April 16, 2014: I made an experiment with my calculus class, in which
60 students submitted answers on paper: all except two got the answer 2.
Interestingly, the
two other answers were 18/5. This is what you get if read it as 2x/(3y1). Nobody got 11].
The interesting thing is that if you want to use technology then the answer is 11:
javascript gives 11, or
wolfram alpha gives 11 or
mathics (based on python) gives 11 too.
What is x/3x?
It depends again on whether one has 3x bundled together or not.
Both answers x^{2}/3 or 1/3
should be counted correct because the parenthesis
had been missing. One should write either x/(3x) or (x/3)x
in order to make the problem clear. Here is what the computer
algebra system Mathematica does:
x/3x
2
x
Out[1]= 
3
x/(3x)
1
Out[2]= 
3
The computer has chosen to do the division first.
This is natural if one looks as division and multiplication as operations
on the same level. To play the devils advocate, note however that the famous PEMDAS (parenthesis, exponents, multiplication, division,
addition and subtraction) has the M before the D so that we would have to accept the second one ...
Its funny that in Excel, there is a rule BEDMAS
(Brackets, Exponents, Division, Multiplication, Addition, Subtraction), which reverses Multiplication and division.
One could therefore call the original question the BEMDASMEDMAS conflict.
Different programming languages might do things differently. Your browser computes in Javascript
with the BEDMAS rule:
gives both 10/3. Try it out.
Funny by the way (and totally unrelated to the topic discussed here) that the results are different
3.333333333333333
3.3333333333333335
illustrating that computers do not honor basic laws of arithmetic. The mathematics
of rounding error arithmetic is subtle. My PhD advisor
Oscar Lanford knew much about this.
By the way, also Mathematica adhers to BEDMAS and does division before multiplication. It is in line with Excel and
javascript as probably most programming languages like Perl.
What is the source of the problem?
We know that addition and subtraction orders can be interchanged:
3+43 = (3+4)3 = 3+(43)
This is called associativity. Since the logarithm gives an isomorphism
between the group (R,+) and (R {0}, *), where * is multiplication,
one could think that we also have the same associativity in the
multiplicative case. This is true because the multiplicative group
(R{0},*) is by definition associative.
But it is the role of the division which must be made clear:
12/(3*2) = 2
(12/3)*2 = 8
gives different answers. This can not be discovered well in
algebra situations like
12/3x
which is ambiguous. Both of the following expressions are
clear, but give different results:
12/(3*x) = 4/x
(12/3)*x = 4x
This is also often a source of error in addition, as
the minus sign has to be carried through:
34+3
(34)+3 = 2
3(4+3) = 5
It is this case which makes the argument that the bracket should be placed to the
left. The additive case is also a reason which seduces not to write the brackets
in the multiplicative case. It always leads to trouble.
An other example
What is
x/x/x ?
We again have two interpretations
(x/x)/x = 1/x
x/(x/x) = x
But since now, we have only divisions and no multiplication, it is even less clear
what comes first. When dealing with fractions, we often make this clear by the size
of the division lines
x

x = x

x
It has become clear that we first do the division with the smaller
division line and
x

x = 1/x

x
What does Mathematica do? Lets look and enter
2/100/2
2/(100/2) = 1/25
(2/100)/2 = 1/100
Mathematica choses the second choice (as does javascript).
It makes the first division first.
An ambiguous example with exponents
So, Mathematica does things from the left. Lets
look now at exponents. What is
3^3^3 ?
Again we have an ambiguity with two cases:
(3^3)^3 = 19683
3^(3^3) = 7625597484987
Leaving out the brackets invites trouble. Yes, one could argue that the first
example is more natural, but then, a printed version of a textbook
might have the third 3 smaller so that the reader is seduced
to first compute 3^3 and put that into the exponent, producing
a much larger number. In the following example, this is even
less clear what the writer intends because expressions like 10^{2}
are often treated together as we write 10^{6} for a million.
The 10^{6} has become a unit: so, if we write
2^10^2
which of the two answers
(2^10)^2 = 1048576
2^(10^2) = 1267650600228229401496703205376
is correct? Maybe we should ask our professional computer algebra
system again. Mathematica 9.0 gives the second choice, if 2^10^2
is entered!
Now we see that even professionals have difficulty to decide.
For (a/b/c) the algebra system starts evaluating
from the left, while for (a^b^c) it starts evaluating from the
right.

How come, Mathematica does that? The reason is that a^x is a short hand
for Exp[x Log[a]]. Now, if you write expressions like Exp[Exp[Exp[x]]],
then by nature, we start evaluating from the right.
If we write f(g(x)), we first compute g(x) and then f(g(x))
even so f is written first.
Lets go back to division. If we write f(x)=1/x
then f(f(x))=x but (1/1)/x) = 1/x and 1/(1/x) = x.
We see that the argument of starting to evaluate the division from the
right when writing 1/1/x has some merit too because it even
gives in the division case the result we would get if we wrote
the expressions as operators.
This is why the parents and the teacher have disagreed. And both were right.
Because both way to write things make sense in some way.
There is only one solution: write the parenthesis.

P.S. This reminds me: when I was in school, there had
been a war about whether to use Reverse Polish Notation (RPN) or not for
calculators. There was the "HP camp" using calculators from HewlettPackard
which used RPN and there was the "TI camp" using calculators from Texas Instruments which did not.
I had been in the TI camp (even hardware
hacking them) and as a student found the RPN strange.
Of course, after having studied mathematics and working with
computer algebra systems for a long time, RPN has become natural too.
In Mathematica, one often makes computations by adding commands from the
right like in
256 // Sqrt // Exp // Floor // PrimeQ
which takes the square root of 256, then exponentiates it, take the
integer part and then answers the question whether this is prime.
It is equivalent to
PrimeQ[Floor[Exp[Sqrt[256]]]]
but avoids the brackets. I use the first way often when computing
interactively, while the second one when writing code like the
following which looks for the statistics of primes in a subexponential
sequence of integers:
F[n_]:=Floor[Exp[Sqrt[n]]];
s=Table[If[PrimeQ[F[n]],1,0],{n,1000}];
G[n_]:=Sum[s[[k]],{k,n}]*Log[n]/n;
ListPlot[Table[G[n],{n,Length[s]}],PlotRange>{0,1}]
If you are curious: here is the Plot.
P.S. An other interesting (a bit unrelated) story is the ambiguity introduced
by decimal marks and dividing numbers into groups. Especially in journalism,
one writes things like 121.123 or 121,123 meaning 121123 and not 121 + 123/1000.
Even so it is now well established that
"the symbol for the decimal marker shall be either the point on the line or the comma on the line"
the comma or decimal point is still used frequently to divide numbers into groups, despite the fact
that it clearly violates the ISO 310 standard. But habits are hard to change.
Document history:
 4/9/2014
 4/13/2014 change title, found BEDMAS Excel page and put question first
 4/14/2014: add picture, motivated from here
using background drop from here.
 4/14/2014: references
 A formum example
 Physics forum: 48/2(9+3)
 advocates Divide and multiply rank equally and go left to right.
and has other memnonics like "Please Eat Mom's Delicious Apple Strudels".
 Science blog mentions the article
by Tara Haelle
which pretty well tells already what is going on (if I had seen this article written on March 12, 2013 before,
I would not have bothered to write this down, because that article makes very clear that the initial assessment that there is no
agreement on the order of multiplication or division is correct). Still, the topic had prompted me to say something new
about the order of operations of the same type, like the D or E in PEMDAS which goes beyond the BEDMAS controversy.
Here is an interesting quote from that article
"Internet rumors claim the American Mathematical Society has written "multiplication indicated by juxtaposition is carried
out before division," but no original AMS source exists online anymore (if it ever did). Still, some early math textbooks
also taught students to do all multiplications and then all divisions, but most, such as this 1907 highschool algebra
textbook, this 1910 textbook, and this 1912 textbook, recommended performing all multiplications and divisions in the
order they appear first, followed by additions and subtractions. (This convention makes sense as well with the Canadian
and British versions of PEMDAS, such as BEDMAS, BIDMAS, and BODMAS, which all list division before multiplication in
the acronym.) The most sensible advice, in a 1917 edition of Mathematical Gazette, recommended using parentheses to
avoid ambiguity. (Duh!) But even noted math historian Florian Cajori wrote in A History of Mathematical Notations
in 192829, "If an arithmetical or algebraical term contains / and x, there is at present no agreement as to which
sign shall be used first."
The article has links to sources of textbooks.
Here is entry 242 in Florian Cajoris book "A history of mathematical notation" (page 274), which is mentioned in that quote
I don't see any indications of an advise given in the cited Highschool textbooks like
here,
here,
but the mentioned entry
this book of Webster Wells is clear about it on page 18:
Update of May 18, 2017: As of recently, riddles like this
where one easily overlooks that the number of fries has changed. Or this:
(where one can miss that only one cherry is used) or this:
have surfaced. These type of puzzles became viral maybe
not because of the PEMDAS thing but because
people don't look at the variations (3 instead of
4 bananas, 2 o clock rather than 3 o clock).
Almost everybody gets it wrong at first.
But there is also the PEMDAS challenge. Some get 88.
But for getting 88, one would have to write
parenthesis (2+3+3)*11.
(thanks to Abitha Sukumaran for sharing this).
Update of August 2, 2017: Presh Talwalkar writes
"I make math videos on YouTube on the channel "MindYourDecisions."
Some of the most popular videos are ambiguous expressions involving the order of operations.
In doing research, I came across your website and the problem:
What is 2x/3y  1 if x = 9 and y = 2?
I would answer 11, which was what the 5th grade teacher said.
I was stunned that none of the 60 students your Harvard calculus class
answered 11 (you explained 58 got the answer 2; and then 2 got the answer 18/5).
My answer:
"yes, it is an interesting thing. None of the answers is of course "correct"
as we know that both the BEDMAS and PEMDAS interpretations can
be used without violating any authority. As indicated on the page, the answer
11 is what most computer languages get. You were obviously taught that. It would be interesting
to know what percentage of humans say 11. My experiments say that it is very
rare. Most do the multiplication before division as PEMDAS seems to be more
popular and is what is usually taught in schools. BEDMAS appears to be taught
much less. The only thing we know is that the claim that one of the answer is the
only right answer, is wrong."
Update of August 5, 2017: Jacob Poscholann Koefoed Christensen
sends an other exasmple and a remark on the obelus.
"The problem is a picture of a mobile phone gets 9 from the equation : 6÷2(2+1)
which according to them says it would be 1.
In your argue you define obelus and division slash to have to whole different meanings.
Well yes they actually do have two different meanings and that's why you normally
never use obelus. Only American may still use it, but this sign has been removed
in use of equations of scientific papers due to its historical problematic.
First of obelus in Northern Europe means subtraction.
Second of all, obelus is recommended removed in the use of science due to that we already have a sign for either of these (division slash ("/") and subtraction ("")). Even though according to your argue that obelus and division slash should imply two
different meanings you often only have one option on a calculator to make a divisionsign."
My Answer:
"thanks for the example 6÷2(2+1). It illustrates the ambiguity too.
Yes, depending on whether one is in the PEMDAS or PEDMAS team,
one gets 1 or 9. Its also a beautiful example, where one can
see heated debates. Like pointed out and previously by others in the
literature list, there is no right answer.
It depends on which rule is applied. Both 1 and 9 are correct. I
always see the obelus as a synonym for / but it can be even more
confusing and so, yes, should be avoided. "