This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Paul Clapham
• Bear Bibeault
• Junilu Lacar
Sheriffs:
• Jeanne Boyarsky
• Tim Cooke
• Henry Wong
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• salvin francis
• Frits Walraven
Bartenders:
• Scott Selikoff
• Piet Souris
• Carey Brown

# Seems to be simple, but many fail to answer correctly

Sheriff
Posts: 7734
534
I found this in my local newspaper as an exercise which tricked many and as a result answered incorrectly. According to an article, even some calculators which support expressions provide wrong answer.

Here it is:

8 / 2 (2 + 2) = ?

It is quite related with some questions we see often here on ranch. It didn't trick me for a second, did you?

Bartender
Posts: 4069
156
• 1
When I was in primary school (1962-1968) we had the sentence: Meneer Van Dam Wacht Op Antwoord, meaning powers, multiplication, division, square roots, addition, subtraction. It didn't mention parentheses, but the answer would have been 1. Like 3 - 3 + 3 would have been -3. But then came these computers, spoiling it all...

Greenhorn
Posts: 3
• 1
I think it really depends on a background of anyone answering. I see 2 possible answers: 1 and 16. When working with fractions on paper I often write something like [8/2   *   (2+2)], meaning [ (8/2)*(2+2) ], which would be 16. At the same time, I sometimes write [8/   2 (2+2)] avoiding brackets around [2*(2+2)] which results in [8/(2*(2+2))], which is 1.

And that's the story of why I prefer to put more brackets than needed when coding

Marshal
Posts: 70354
283
Assuming that the juxtaposition of the 2 and the (2 + 2) means multiplication, the * and / operators have the same precedence and the same associativity (left). The division must therefore be done before the multiplication, it evaluates toAnd welcome to the Ranch

Campbell Ritchie
Marshal
Posts: 70354
283

Piet Souris wrote:. . . 3 - 3 + 3 would have been -3. . . .

That only works if + andassociate to tthe right; they don't They associate to the left; that expression therefore evaluates to (+)3.

Saloon Keeper
Posts: 12282
259

Campbell Ritchie wrote:Assuming that the juxtaposition of the 2 and the (2 + 2) means multiplication, the * and / operators have the same precedence and the same associativity (left).

I don't agree with this. In most textbooks I read, juxtaposition was used like multiplication, except with higher precedence. If I came across

f(x,y) = 2x² / 8y

I would take that to mean

f(x,y) = (2 * x²) / (8 * y).

Google seems to agree with me (for whatever that's worth); when I use juxtaposition rather than the asterisk, Google gives juxtaposition precedence over division.

2x^2 / 8y   : conic
2*x^2 / 8*y : hyperbolic paraboloid

Campbell Ritchie
Marshal
Posts: 70354
283
If juxtaposition has a higher precedence than division, then the answer is 1. But we aren't working out 2x but 2•4. Does that precedence still apply? If you write
2x²
8y

then the full‑length division line acts as a kind of (). And remind me, doesn't the square have a higher precedence than the doubing in the top of that expression.

I shall ask around, but it might be a couple of weeks before I can catch any proper mathematicians.

Stephan van Hulst
Saloon Keeper
Posts: 12282
259

Campbell Ritchie wrote:If juxtaposition has a higher precedence than division, then the answer is 1. But we aren't working out 2x but 2•4. Does that precedence still apply?

It depends on what convention you follow. There is no single truth. That's also why different calculators give different results, and why different teachers teach differently. Usually the formatting would make it clear, putting more space around operators that have lower precedence. And any real mathematician would never juxtapose two numerals.

Any time you find this kind of question in newspapers or in social media, you will see that the expression is intentionally formatted to make it ambiguous. The correct answer depends entirely on what the editor in question decides is the correct answer.

Having said all that, I'm still firmly of the opinion that anybody who doesn't assign the same precedence level to inverse operators is just part of a lesser form of life.

And remind me, doesn't the square have a higher precedence than the doubing in the top of that expression.

Yes, exponentiation always has precedence over multiplication, even when the multiplication is indicated by juxtaposition.

Campbell Ritchie
Marshal
Posts: 70354
283

Stephan van Hulst wrote:. . . Any time you find this kind of question in newspapers or in social media, you will see that the expression is intentionally formatted to make it ambiguous. The correct answer depends entirely on what the editor in question decides is the correct answer. . . .

Thank you. I think we shall have to be conventional and agree to disagree. If the editor decides, well that depends on whether they have printed riddles like the one about saving fuel on an aeroplane with a cargo of birds by rattling their cages and making all the birds fly.

Piet Souris
Bartender
Posts: 4069
156

Campbell Ritchie wrote:

Piet Souris wrote:. . . 3 - 3 + 3 would have been -3. . . .

That only works if + andassociate to tthe right; they don't They associate to the left; that expression therefore evaluates to (+)3.

Please read my reply again and you 'll see it has nothing to do with association to the right. For that matter, 12 - 2 * 5 + 2 was 0 in those years, for the same reason.

Campbell Ritchie
Marshal
Posts: 70354
283
That will only evaluate to 0 if
• 1: + has a precedence higher than −
• or, 2: + and − associate to the right
• Does Meneer Van Dam Wacht Op Bier mean that all the precedences are different? You aren't going to notice the difference with +, which is associative and commutative, but − isn't commutative; x − y = y − x ⇔ x = y

lowercase baba
Posts: 12893
63

Piet Souris wrote:When I was in primary school (1962-1968) we had the sentence: Meneer Van Dam Wacht Op Antwoord, meaning powers, multiplication, division, square roots, addition, subtraction. It didn't mention parentheses, but the answer would have been 1. Like 3 - 3 + 3 would have been -3. But then came these computers, spoiling it all...

We used "Please Excuse My Dear Aunt Sally" - Parentesis, Exponents, Multiplication, Division, Addition, Subtraction.  However the problem there is this implies all multiplication comes before all addition.  I was taught multiplication and division go in order, left to right, and you do them all before you do the addition/subtraction in order, left to right.

that makes sense, since multiplication and division are really the same operation, as are addition/subtraction.

but your phrase really confuses me.  You did square roots AFTER multiplication?  what about cube roots, or fractional roots?  and roots are again the same thing as powers, so why do they come so late?  if you has a power of 3/2, do you do it as a power or as a root?  PLEASE don't tell me you'd cube it, then multiply/divide, and THEN do the root.  that would break my brain.

Piet Souris
Bartender
Posts: 4069
156

Campbell Ritchie wrote:That will only evaluate to 0 if

• 1: + has a precedence higher than −
• or, 2: + and − associate to the right
• Does Meneer Van Dam Wacht Op Bier mean that all the precedences are different? (...)

Piet Souris
Bartender
Posts: 4069
156

fred rosenberger wrote:(...)
but your phrase really confuses me.  You did square roots AFTER multiplication?  what about cube roots, or fractional roots?  and roots are again the same thing as powers, so why do they come so late?  if you has a power of 3/2, do you do it as a power or as a root?  PLEASE don't tell me you'd cube it, then multiply/divide, and THEN do the root.  that would break my brain.

Well, for once it meant that if you had sqr 3 * 5, then you must calculate sqr(3 * 5).

But that was at primary school! I can't even remember being taught about roots in primary school, let alone qubes and fractional roots.

Campbell Ritchie
Marshal
Posts: 70354
283
I would assume that sqr 3 * 5 is the same as 5√3; as Fred suggests √ has a higher precedence than multiplication.

Rancher
Posts: 3635
40
• 1
Well, root symbols carry implicit parenthesis based on the length of the horizontal line at the top.  That is, the difference between sqrt(x) + y and sqrt(x + y) is shown by whether the line after the √ covers only the x, or covers x + y.  The precedence relative to other operations is defined explicitly by such implied parentheses.  Much like using a long horizontal line to denote division.

For the original question, when I originally saw it being shared everywhere, it usually used the symbol ÷ to denote division:

8 ÷ 2 (2 + 2) = ?

In my opinion, this made things more ambiguous, because by the time my teachers were talking about the precedence of multiplication and division over addition and subtraction, they stopped using ÷  entirely, in favor of / or a horizontal line.  So for me, the precedence of ÷ is essentially undefined, though / is well defined.  (Much like some programming languages use both "&&" and " AND ", meaning the same thing, but with different precedence relative to other operators.)  Different people may have a different take on it, but as far as I know, there is no standard for this symbol.  As Stephan says, "There is no single truth."

Also, if you use /, it's really incumbent on the writer to format it more clearly.  For example, if you write

8 / 2 (2 + 2)

on a whiteboard, it could easily be seen as

if you make the / a little bigger.  Conversely, if you wrote it more like

8/2 * (2 + 2)

Then that would also be clearer for everyone, with the opposite meaning.

So really, the problem is that the original author of the expression was being intentionally ambiguous.  It's ultimately their fault, not that of the readers.

Campbell Ritchie
Marshal
Posts: 70354
283

Mike Simmons wrote:. . . implicit parenthesis based on the length of the horizontal line at the top. . . .

I was taught the same: long lines imply () too. But that doesn't only apply to √. I know the HTML escape &radic; for √ but I don't think there is an overscore symbol.

Saloon Keeper
Posts: 2671
130
When I am in doubt, I ask the java compiler for all my life's queries
See my conversation below.

Yes, that's right... It's not a statement ! it needs a rounded bracket
The Gods have spoken! (ﾉ""_ _)ﾉ""

Mike Simmons
Rancher
Posts: 3635
40
Yeah... but your gods would also tell you that 3/2 is 1.  Try justifying that to any non-programmer...

salvin francis
Saloon Keeper
Posts: 2671
130
• 2

Mike Simmons wrote:Try justifying that to any non-programmer...

It's easy... Try dividing 3 toys between two siblings and you'll realize that the answer is correct !!!

Campbell Ritchie
Marshal
Posts: 70354
283
• 1

salvin francis wrote:. . . Try dividing 3 toys between two siblings . . .

That division has two possible solutions: 0 and 3

 All of the following truths are shameless lies. But what about this tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton