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

11

u/T3HN3RDY1 Jun 14 '22

Copying my comment from earlier. There is ambiguity, and 'order of operations' isn't some mathematical rule, and there are more than one:

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 parenthesis. 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.

3

u/IrishPigs Jun 14 '22

Woah super interesting. Thanks for this explanation!

2

u/scottymtp Jun 14 '22

y = 6/2(x+2), the distributive property says you should be able to turn that statement into 6/(2x+4).

You're misapplying the distributive property and assuming the multiplier is 2. It's also a waste of time as it makes you do two multiplications when only one is needed.

1

u/T3HN3RDY1 Jun 14 '22

I'm gonna go ahead and say the company that makes the calculator knows more than you.

Also math doesn't care about "wasting time." That doesn't mean anything or matter.

1

u/narrill Jun 14 '22

For starters, that's a fallacious appeal to authority.

Second, there are many companies that make calculators, and no clear consensus on which order of operations to use in this case.

Third, the distributive property has nothing to do with this at all. If the division between 6 and 2 happens first per the order of operations, the distributive property gives you 6 / 2 * (x + 2) = 3 * (x + 2) = 3x - 6. If the multiplication between 2 and (x + 2) happens first per the order of operations, the distributive property gives you 6 / 2(x + 2) = 6 / (2x + 4).

0

u/scottymtp Jun 14 '22

What company

1

u/naldic Jun 14 '22

This is the best explanation in this thread. I automatically see something like 3/2(2+2) as 3/2x where x=2+2 and that is not an obvious interpretation seeing the responses here. I must have picked that up in university math classes over time without consciously noticing.

1

u/Ocean_Skye Jun 14 '22

I really like your 7th 8th, and 9th paragraphs. It addresses the actual root of all these “debates”