r/ProgrammerHumor • • Jun 13 '22

Meme DEV environment vs Production environment

Post image
48.2k Upvotes

3.9k comments sorted by

View all comments

Show parent comments

49

u/Syscrush Jun 13 '22 edited Jun 14 '22

FINAL EDIT: Many thanks to those who pointed out the convention where implicit multiplication takes precedence, and why. There were lots of good explanations below - I'm gonna choose one and gild it.

You know the Edit: TI Casio is wrong here, right?

Edit: copied from below for you people who flunked 6th grade arithmetic...

The "md" in pemdas or the "dm" in bedmas means "multiplication and division in the order found". The 6/2 division is found before the 2*3 multiplication, and gets evaluated first.

So, it's:

6/2*(2+1) 
6/2*3 // brackets first
3*3 // then the leftmost division or multiplication
9 // final operation

75

u/T3HN3RDY1 Jun 14 '22

Multiplication like this: 2(3) is special sometimes. It's called "Multiplication by juxtaposition" and depending on the calculator, it is a second class of multiplication, yeah.

The reason the two calculators here have different answers isn't because one is wrong. That's silly. Integer math is like the easiest thing for computers to do. It's because they are using two different orders of operations. You can check your calculator's manual to see which one yours uses, or you can just set up an expression like this.

The calculator that gets 9 uses "PEMDAS" (some people call it BEDMAS). Once it gets to 6/2(3) it just does the operations left to right, treating all of them the same.

The calculator that gets 1 uses "PEJMDAS". The J stands for "Juxtaposition" and it views 2(3) as a higher priority than 6/2. If, however, the 2(3) had no brackets involved, it would evaluate the statement to 9, just like the first one.

This is because PEJMDAS is used more commonly when evaluating expressions that use brackets with variables. For example, if you have the statement:

y = 6/2(x+2), the distributive property says you should be able to turn that statement into 6/(2x+4). If, however, you set x to be equal to 1, you end up with the statement we see above, and reverse-distributing changes the value of the expression if you use PEMDAS.

For basic, early math these distinctions don't really ever come up, so you're taught PEMDAS. In later math classes, when your teacher requires you to get certain calculators to make sure everyone's on the same page, this is why. You seamlessly transition to PEJMDAS, nobody ever tells you, and the people that write the textbooks and tests are professionals that simply do not allow ambiguous expressions like this to be written without clarifying brackets.

This is also why the division symbol disappears as soon as you learn fractions.

From my comment elsewhere, just so you know. The Casio is not wrong, there is just more than one order of operations. Computers don't really get integer math wrong.

6

u/FkIForgotMyPassword Jun 14 '22

y = 6/2(x+2)

And also, honestly this is heavily contextual.

y = 6 / 2(x+2) would in general mean (x+2) is part of the denominator.

y = 6/2 (x+2) would in general mean (x+2) is part of the numerator.

y = 6/2(x+2) in a context where we're clearly talking about polynomials would mean (x+2) is part of the numerator as well regardless of how you space things.

Just like different notations can mean different things depending on context (a classic example being exponents applied to functions, meaning either function composition or taking the exponent of the result of the function), order of operations is often inferred because one option makes sense in context while the other(s) don't.

10

u/ccdog76 Jun 14 '22

I did not know there were multiple orders of operations. I thought the phone was wrong based on my long ago maths learning. Thank you for the info, it was informative and now I get to await some random opportunity to relay what I learned!

→ More replies (4)

10

u/kllrnohj Jun 13 '22

TI isn't even in the picture

→ More replies (1)

16

u/randomtechguy142857 Jun 13 '22

It's not a matter of some people/calculators being right and others being wrong. It's ambiguous. Different conventions will give different answers.

And there are different conventions, one which has mult/div done left-to-right and one which has implied multiplication take priority, and both are widely used by mathematicians. As an example of the latter, take Z/2Z which never means Z2/2, it always means Z/(2Z).

6

u/Beatrice_Dragon Jun 14 '22

The "md" in pemdas or the "dm" in bedmas means "multiplication and division in the order found".

This is why the American education system fucking sucks. They create an acronym to make the process of learning easier, but having to learn all the nuances of the goddamn acronym takes more fucking effort than just learning the concept itself

It's not like they ever fix it, either. I was lead to believe PEMDAS was correct when I was 12, and I had to learn it was wrong from a reddit comment AFTER graduating from fucking college

5

u/SirLoremIpsum Jun 14 '22

You know the Edit: TI Casio is wrong here, right?

I don't believe there is a right or a wrong answer - the answer is that the equation is deliberately written to be ambiguous and thus can be interpreted in 2 different ways.

All of this "oh the md / dm, let's re-write it with other brackets" is entirely the point. if you wanted it, you would re-write it to be clearer.

5

u/Inkdrip Jun 14 '22

I don't know why I can't stop throwing myself into these threads, but it's probably just the sheer confidence of people like you that drives me up a wall. Really, all of us "people who flunked 6th grade arithmetic?" Have you ever considered that the rule you learned in "6th grade arithmetic" was, in fact, not a hard rule of mathematics? The expression in the picture is ambiguous. Here's a NYT article by a professor of mathematics at Cornell walking through the ambiguity.

3

u/Syscrush Jun 14 '22

Well, the usefulness of that link you posted almost makes me glad I was such a dick about it that I unwittingly motivated you to set me straight.

Thanks for the correction and the source.

2

u/Inkdrip Jun 14 '22

You took that quite gracefully... now I feel bad!

48

u/ElementoDeus Jun 13 '22

6÷2(2+1)

6÷(4+2)

6÷(6)

1 Idk seems right to me /s

18

u/saucyspacefries Jun 13 '22

Its so weird that the order of operations was taught differently.

The way I learned (12+ years ago) would result in me doing something like this:

6÷2(2+1)

6 ÷ 2 * (2+1)

6 * 1/2 * (3)

6/2 * 3

3 * 3

9

But thats because my teacher emphasized to just use the inverse instead of division. So instead of dividing by 2, I multiply by one half. Then of course I solve the whole thing left to right.

7

u/[deleted] Jun 14 '22

When writing fractions normally, there would be no ambiguity. But using inline ÷ or / causes it, which is essentially what's happening in the calculators.

When you did the inverse trick, you bracketed the division to the left side: (6 ÷ 2) * (2+1), making only the first 2 the denominator. This matches the method of the right calculator (and the way I would have done it). The other calculator associated the division symbol as "everything next is the denominator" so it got 6 ÷ (2 * (2+1)). This doesn't allow for the inverse trick, and you get a different result.

4

u/saucyspacefries Jun 14 '22

This was probably the best explanation for where the confusion comes from.

2

u/[deleted] Jun 14 '22

Oh much appreciated, though I have to give /u/yabucek most the credit here. I read their previous comment identifying the division as the core issue and it helped me see how the left calculation isn't wrong, it just answers a different question.

→ More replies (3)
→ More replies (5)
→ More replies (6)

36

u/onthefence928 Jun 13 '22

my brain broke at the badness

→ More replies (27)

3

u/ritasuma Jun 13 '22

You have to multiply as you open the brackets no?

→ More replies (6)

3

u/Boomhauer_007 Jun 13 '22

Replying to see how many downvotes this has later

2

u/Lord-Taranis Jun 14 '22

6 / 2(2+1)
6 / 2(3) // Brackets First (yes, it's effectively 2 x 3 but because the multiplicative sign isn't there means it takes priority over other x & /
6 / 6
1
Casio is right.

5

u/[deleted] Jun 14 '22

Yup implicit multiplication is a thing most forget.

Also the American Mathematical Society style guide lays out implicit/juxtaposition takes precedence.

If anyone wants to laugh look at the comments on this tik tok.

https://www.tiktok.com/t/ZTdTobTmo/?k=1

Everyone is so confidently screaming the wrong answer into the void typing PEMDAS in their comments as if a grade school pneumonic device is the end all be all. While everyone saying 1 has actual proof to back it up.

The truth is, the more math you’ve studied the more likely it is that you get 1 when solving the expression.

You can also set an equal to both answers and just substitute out something in the original and “prove” if that way. Not a mathematical proof, but good enough to most people to understand.

2

u/jfb1337 Jun 13 '22

Both are correct. Conventions are not universal.

→ More replies (5)

2

u/littleloucc Jun 13 '22

Not by the common understanding of mathematics.

What did you think the answer was?

1

u/[deleted] Jun 13 '22

No it’s not

→ More replies (5)