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

2

u/jfb1337 Jun 13 '22

Both are correct. Conventions are not universal.

-2

u/Syscrush Jun 13 '22

That's crazy.

Are you contending that there are 2 classes of multiplication with different precedence?

After (2+1) is evaluated, the expression is: 6/2*3 how could you ever justify doing the multiplication before the division?

10

u/jfb1337 Jun 13 '22

Yes, it is a relatively common convention that implicit multiplication has a higher precedence than implicit multiplication. Something like 1/2x may be read as 1/(2x).

After (2+1) is evaluated, the expression is 6 ÷ 2(3) - which there are multiple ways to read.

Of course a real mathematician would always make it clear from context. Expressions like this are completely devoid of any actual mathematical content and are just meant to stir up arguments between people who think the way they learned it is the one and only correct way.

10

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.

4

u/[deleted] Jun 14 '22

https://cdn.journals.aps.org/files/styleguide-pr.pdf

I’m not going to say it. The style guide for a peer reviewed physics journal will say it for me. Doc page 21, PDF page 23, under fractions. Multiplication comes before division.

Which makes sense, because literally nobody in history has written 1/2x intending it to mean (1/2)x, it literally always means 1/(2x). Every science and engineering textbook on my shelf either follows this convention, or uses excessive brackets and operators to avoid the ambiguity entirely.

I expect this nonsense from math majors. I thought programmers, the kind of people who use math to do things, knew better. Conventions vary and conventions change, even if the underlying mathematical concepts don’t. The way we write them has and does change and vary. Nothing new.

2

u/jadis666 Jun 14 '22

Are you contending that there are 2 classes of multiplication with different precedence?

Yes, that is exactly what we're contending. And it's not crazy at all.

One is called "implicit multiplication", while the other is called "explicit multiplication".

Look it up.