56 comments

[ 3.2 ms ] story [ 113 ms ] thread
Is it 1+3 or 1+2? Title does not match content.
I blogged about this nearly two years ago:

http://www.solipsys.co.uk/new/AMatterOfConvention.html?HN

Nice, i would have said 9 just because that's how C interprets it.

float x = 6 / 2 * (2 + 1); // x == 9

Right, but you also had to explicitly add the asterisk for multiplication. I thought the same thing, but the remarks on juxtaposition do have a point. For example, if an integer were callable, you'd do the function call--2(2+1)--independantly of the division.
Yeah, tale as old as time, right? It's making the rounds on social media currently, so I thought it was relevant.

I agree with your interpretation FTA:

> DON'T DO THIS!

> It's ambiguous, and should not be written like this because it leads to problems.

That "divide-by" symbol can suck my left nut.
Obviously, the author is right that there is no universal objective definition of the order of operations. Still, I find it surprising that anyone with a high school level mathematics education would perform the division via the obelus (÷) before the multiplication via juxtaposition.
In high school (and college) I've always been taught that multiplication and division have equal precedence and should be evaluated in the order in which they are encountered.
Was multiplication by juxtaposition ever mentioned explicitly? I was taught to give them equal precedence, but that was explicitly for the division symbol and the multiplication symbol (* or x). Juxtaposition, like 2x or 2(2+1), was always considered to have greater precedence than the division and multiplication symbols.
Nope, never heard that in my 13 years of school in Germany.
also note that the author skips the multiplication operator. Especially odd (to me) since he is using parenthesis to imply multiplication and the values are not variables but values.
If the expression were 6÷2x(1+2)=?, then my intuition would be to evaluate from left to right (division before multiplication). But removing the x symbol makes me want to perform the multiplication via juxtaposition first, just like if it were 6÷2x. Would anyone really interpret 6÷2x as 3x?

note: I had to use an x instead of the asterisk to represent multiplication, since I don't know how to escape the asterisk in Markdown.

Psst... the programmers at google might have a bone to pick with you.
I strongly suspect that to be an oversight.
Wouldn't it have been easier to just express this question as 6/2*3? The addition part doesn't seem to add anything to the point of the article (no pun intended).
The question is taken from a Facebook post making the rounds. The parentheses are important however, as they introduce a new ambiguity: does the implied multiplication from the open parenthesis trump the division symbol on the left?

Put another way, does it fall into the Parentheses section or the Multiplication section of the PEMDAS order of operations? (Or whatever mnemonic your country uses.)

Why would the multiplication fall in the parenthesis section when it clearly isn't in a set of parenthesis? 6÷2(1+2) expands to 6÷2*(1+2). The items inside the parenthesis first and there should be no ambiguity about that.
I was taught to handle parenthesis first before multiplication or division so the answer is clear to me to be 1.
You handle the contents of the parenthesis first. 2(3) is just shorthand for 2*3 so you would handle the division and multiplication in the order given.
Well, is the implied multiplication technically part of the parenthesis, though? I've always been taught the stuff inside the parenthesis takes precedence, but outside is irrelevant because it's not technically "part" of the parenthesis statement.

It's like how programming works:

6 / 2 * add(1, 2)

This would obviously evaluate to 9, because the "add" function would simply return a value and the rest of the statement would be evaluated from left to right. In this case, the first 2 is not related to the "add" function in any way.

I have never understood why you would process multiplication and division as separate reduction steps, besides for simplification in elementary-school learning materials. It seems completely arbitrary. Division is just multiplying by an inverse, and subtraction is just adding negative numbers. PEMDAS seems like something that is taught to you, and then never correctly explained.
BEDMAS (what I was taught in school) really throws some confusion in there concerning PEMDAS. Heh. We've started using PEMA in NZ to lessen confusion. I assume they go on to explain where division / subtraction went.

  6/2(1+2)=6/2*(1+2)=6/2*3=(6/2)*3=(3)*3=9
This is pretty well defined, I feel:

- Expand implicit multiplication to explicit multiplication (e.g. 2(1+2) becomes 2*(1+2))

- Left-to-right precedence for operators of equal-precedence (divide and multiply)

The 2 is no more bound to the parenthesis than it is to the division operator.

Am I missing something?

When you have 6/2(3), it is not well define if the correct expansion is 6/(23) or (6/2)3. In my experience with math, the intuitive answer is that implicit multiplication takes precedence. For example, say instead of 6/2(3), you had 6/2x. Following your convention, that would expand to (6/2)x, not 6/(2x). You might say that the () around the last number make a difference. However that would imply that 6/2x!=6/2(x). Which I find deeply unsettling if true.

Ultimitly, this is why we tend to use notation which uses placement to resolve these issues unambiguasly, without alot of parentheses.

I find it interesting you feel this way.

In my experience, it is pretty well defined:

0. Evaluate (the inside of!) parenthesis, then

1. Evaluate exponentials, then

2. Evaluate division and multiplication operators, left to right

  e.g. 1 / 2 * 3 / 4 = (1/2) * 3/4 = ((1/2)*3)/4
3. Evaluate addition and subtraction operators, left to right

Your issue seems to stem from the left-to-right concept (in order in which operators are encountered as you read, left-to-right).

Your example of 6/2x to me is clearly (6/2)x. What is 1/2x ? In my experience, textbook authors/professors/math teachers tend to be disambiguous and either use the horizontal line for clarity or use parenthesis.

I attended public schools in Ontario, Canada if it makes any difference.

Edit: Oh yeah, also I have never felt that implicit operators would take precedence. Interesting!

It's funny because in other interpretations the "%" symbol evaluates to the modulus operator and this brings up another possible result. 6 mod 2(1+2) = 6 mod 6 ~= 0 mod 6
The way you know this question is dumb? It was written by someone who either doesn't understand how to write math to be readable, or was written by a troll. The use of that division sign, ironically, doesn't make it any easier to determine, although there's surely a subset of FB idiots (the same that would waste time on this in the first place) that wouldn't understand it written as 6/2(1+2).
You wasted time on this by writing this comment.. not sure why you're discriminating others as idiots.
I'm 96% sure you missed the point of my post.
I don't understand his idea of comparing the independence of the Continuum Hypothesis from the other axioms of set theory, which is a very deep and important result about (in essence) one of the limits of mathematical reasoning, with this little notational difficulty, which frankly is of very little interest, especially to mathematicians (you do run into this when writing parsers, sometimes...) He actually manages to say that this is "as stupid as" asking for a proof of the Continuum Hypothesis. Reminds me of people who get hung up on whether 1 is a prime number. Yes, no, maybe - people have defined it this way and that, it's a convention you can make without changing anything fundamental about mathematical reasoning.

Different systems of axioms lead to very different mathematical objects (compare Euclidean and non-Euclidean geometries). Different conventions lead to the exact same thing written slightly differently - if we say that clockwise rotation corresponds to positive change in angle (the opposite of current convention), we'll exchange plus and minus signs in a bunch of formulas, and nothing else.

My (intended) implication was that answering the question

> What is 6÷2(1+2)?

without establishing the axioms of arithmetic is as impossible as answering

> Does CH hold in ZF?

without establishing some axioms of set theory.

Put another way, asking 6÷2(1+2) on the SAT is as ill-advised as asking an Introduction to Proofs course to tackle the Continuum Hypothesis with just some naive set theory.

Again, I think that's a very bad comparison - resolving this difficulty is not "impossible". You can choose whatever convention you like, and all that changes is the notation. Of course it's a bad test question, but it is not "impossible" or even remotely difficult for mathematics - it's just a matter of choosing a notation.

You seem to think that this question has something to do with the "axioms of arithmetic" - no, it doesn't, it's a matter of how you write things by convention. Operator precedence is not and has never been an "axiom". We can define plus to have the highest precedence, and get the exact same arithmetic we have now, written differently.

On the other hand, deciding the Continuum Hypothesis is "impossible" in a very fundamental way - Kurt Godel and Paul Cohen, two of the greatest mathematical logicians in history, proved that the Continuum Hypothesis is undecidable by mathematical reasoning as we can best formulate it, i.e. it is independent of the ZFC axioms. That's not a matter of choosing a notation for it.

Whether you consider the properties of arithmetic to be axioms or some other word which describes a fact assumed without proof is a matter of semantics.

The point was that without a precise foundation for mathematics we cannot proceed - anything further is overanalysis for an article I wrote mainly for folks without our mathematical background. :-)

There is a fundamental difference between conventions of notation, and properties of the thing being notated, in this case arithmetic. I'm frankly surprised that someone with a mathematical background keeps mixing up the two. There are a dozen people in this thread of comments posting different notations - prefix, postfix, what have you. Do you think these define a different arithmetic? Now of course it's stupid to ask people a question without defining what you mean by your notation - you might as well mumble something and expect them to decipher it. But that is in no way equivalent to asking a question which is undecidable in mathematical logic (which is not necessarily a stupid thing to do). And features of some particular notation do not in any way, shape, or form, or by any stretch of semantics, constitute axioms, or properties, or anything else which belongs to arithmetic itself. Do you really disagree with that?
When converting it from infix to postfix, it returns 6 2 / 1 2 + * which returns 9. I prefer this point of view.
It's one. He himself said parenthesis takes precedence. So:

6 / 2(3) <== Parenthesis still there

6 / 6

1

wooosh

--

It's 9, you've added some invisible brackets in there.

6 / 2 * (1 + 2)

6 / 2 * 3

3 * 3

9

(/ 6 (* 2 (+ 1 2)))

The answer is 1.

(* (/ 6 2) (+ 1 2)) would give nine but c'mon...that multiplication way over on the left came outta nowhere.

I prefer 6 2 1 2 + * / and 6 2 / 1 2 + * notation.
> In the real world of mathematics, this is as stupid a question as me asking “Is there a mathematical size bigger than the amount of integers but less than the amount of real numbers?” [1] because you can’t answer it without going through a lot of trouble to specify the “axioms” (basic assumed rules for doing mathematics) you want used on the problem.

I don't think this analogy holds very well--a curious student could reasonably and earnestly ask about the continuum hypothesis, since it's not at all obvious from first principles that the answer depends so heavily on obscure set axioms. On the other hand, the order of operations question seems to have been designed to confuse people and stir up meaningless, unresolvable arguments over PEMDAS.

>> The issue stems from the incorrect (but often subconscious) belief that there exists a Bible of Mathematics somewhere

Well, yes, I thought so. Most mathematical expressions are pretty standard and I'm surprising that there is no a definitive answer to this question.

The way I see it is:

  6/2(1+2)
  6/2(3)
  6/2*3
  3*3
  9
If I wanted to apply 23 first, I'd write: 6/(23). Maybe I thought like that because that's how all calculators I've used work.
I am very surprised that people would evaluate the multiplication via juxtaposition after the division symbol. According to that method, 6 ÷ 2x would be evaluated as 3x, which I find extremely unlikely to be the intention of that expression.
Well, 6 ÷ 2x is similar to:

  6
  __
  2x
You've explicitly put spaces around it.

However, if you look at it like:

  6/2*x  
Does 3x seems that unlikely?
Again, my point is that my interpretation depends on whether it's multiplication via the multiplication symbol, like 6/2*x, or multiplication via juxtaposition, like 6/2x.
(comment deleted)
The title (on his website) contains the wrong formula. I've skimmed the post a few times, wondering why the correct answer wasn't twelve... Then I saw it :/
Computers will conclude the answer is 1 as they will prioritise the multiply.

Now us humans will get 9 as they will do the 6/2 and then multiply the result with the (1+2) for 3x3.

Now given the multiply is implied and computers like to have that symbol in many languages and the divide sign as again a form not overly used in programming languages, then it is clearly expressed in a form for human consumption. With that we imply the 6 divided by 2 is in its own bracket and will think it is 9, then we will think again if we know computers and then think 1.

Moral being whilst lots of brackets and braces can look untidy, they do clarify beyond doubt.

No, they won't. Computers will compute it as nine because they evaluate the parenthesis, then go left to right.

6 / 2 (1 + 2)

6 / 2 * 3

3 * 3

9

This is not mathematics, this is symbol manipulation. The author is correct, the answer here is that it is a badly expressed problem - with multiple possible solutions depending on the assumptions the audience makes.

In mathematics allowing your audience to make assumptions is very very bad...people are terrible at making and applying assumptions - just look at any studies into eye witness testimony.

Machines are just as bad, as they are loaded with assumptions of their programmers.

As a Computer Scientist, I absolutely hate coming across badly expressed formulas. Abstraction is key - why are there parentheses around the 1+2, what makes those separate...why not just write 3?? - In fact there are no variables in this problem, it is constant, just give me the constant...or tell me why you have defined it this way.

Implicit operations and ordering may save you a couple of characters but generate essays worth of confusion.

just as a data point:

as google, wolfram alpha (a mathematica "frontend") interprets it as (6/2)*(1+2).

https://www.wolframalpha.com/input/?i=6÷2(1+2)&dataset=

(and even with a variable juxtapositioned it's interpreted like that.)

but right, that's no real metric for mathematical use. (i still think the result is 1.)