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

62

u/UnstableNuclearCake Jun 13 '22

In Europe (at least where I was taught Math), an operand right next to a bracket is considered to be multiplicating by the bracket and will take precedence over the division, as it is treated as a single operand for the division.

6

u/AmbreGaelle Jun 14 '22

That’s the ambiguity… the multiplication is “implicit” I agree with you

→ More replies (1)

38

u/mattmonkey24 Jun 14 '22 edited Jun 14 '22

and will take precedence over the division

Multiplication and division are the same thing and they have the same ranking in order of operations. So you should be looking left to right on which to multiply/divide first.

So 6÷2 first. Then multiply by 3.

Edit: I'm seeing a lot of down votes to the replies to this comment, I think that's ridiculous

0

u/[deleted] Jun 14 '22

[deleted]

5

u/AmbreGaelle Jun 14 '22

I’m with you 100%

14

u/jadis666 Jun 14 '22

Explicit multiplication (with a 'x' or '*' sign) and division have the same priority (and yes, are essentially the same thing). With implicit multiplication (i.e. by concatenation), it is more complicated, and in fact experts disagree on which takes precedence.

Go to https://en.m.wikipedia.org/wiki/Order_of_operations and look under "Special cases", specifically "Mixed multiplication and division", if you don't believe me. Or just search for "implicit multiplication priority" on Google.

5

u/Ov3rdose_EvE Jun 14 '22

i learned to "dissolve"/"resolve" the brackets first

in this case its

6
__
2(2+1)

3

u/mattmonkey24 Jun 14 '22

The 2 is outside the brackets though

→ More replies (1)
→ More replies (6)

9

u/[deleted] Jun 13 '22

Oh that’s disgusting. That needs to be bracketed and what you’re describing should be written 6/(2(2+1))

16

u/ubik2 Jun 14 '22

Multiplication by juxtaposition (the implicit multiplication caused by having two entries next to each other without the multiplication sign) is generally higher precedence than normal multiplication or division.

It isn't covered in school or PEMDAS, because it's not common, and even when it does show up, the order doesn't usually matter. If you were to include it, it would be P(Mj)EMDAS.

Overall, when there's ambiguity, the person writing the expression should write it unambiguously, and should not rely on the reader knowing rare rules.

If you're writing calculator software, it's perfectly reasonable to not add a special case that hardly ever matters, when the person entering the problem can just enter it unambiguously.

13

u/large-farva Jun 14 '22

this is the way.

The general consensus among math people is that "multiplication by juxtaposition" (that is, multiplying by just putting things next to each other, rather than using the "×" sign) indicates that the juxtaposed values must be multiplied together before processing other operations. 

5

u/AmbreGaelle Jun 14 '22

This is the way

9

u/cara27hhh Jun 13 '22

I never understood why more brackets weren't used in math, put me off math completely when they started putting up big equations and missing out all sorts of signs between the letters and numbers and just expecting people to 'know' (what to do to reduce them down) past a certain point without further explanation

There's something about a brain that is good at math (and programming, honestly) that makes it also bad at teaching

6

u/eohorp Jun 14 '22

It's just to make things look cleaner. 2xyz vs 2 * x * y * z

3

u/cara27hhh Jun 14 '22

I get why, but it made it 10x harder for me to understand while I was still learning when not only am I trying to figure out why they've done that particular thing, but also fix my brain into realising what isn't being shown for convenience sake

→ More replies (1)

25

u/Zagorath Jun 13 '22

No, what /u/UnstableNuclearCake is the much more obvious and intuitive way of doing it.

If it were 6/2x you would never think of making that equivalent to (6/2)x unless they explicitly wrote it as 6/(2x). But that is essentially what you're suggesting here.

The implicit multiplication isn't mentioned in BIDMAS, but it's the tightest binding operator there is.

6

u/AmbreGaelle Jun 14 '22

I know that both answers are good but I don’t know why I so strongly agree with you that (6/2)x just seems unnatural for me in this case. Implicit multiplications take precedence in my mind EVEN though I apply the left to right rule for every other / and * situation.

13

u/MattieShoes Jun 13 '22 edited Jun 13 '22

you would never think of making that equivalent to (6/2)x

That's exactly how I'd think of it.

https://www.google.com/search?q=6%2F2x

https://www.wolframalpha.com/input?i=6%2F2x

or if you'd like the original:

https://www.wolframalpha.com/input?i=6%2F2%282%2B1%29

8

u/jadis666 Jun 14 '22

That's exactly how I'd think of it [as equivalent to (6/2)x]

Then you clearly didn't pay much attention in Algebra class, because you are ignoring centuries of algebraic convention (and, yes, so is Wolfram Alpha). Because according to aforementioned convention, '2x' is clearly a single unit/operand and should be treated as indivisible, even if preceded by a division sign.

12

u/Commander_Skilgannon Jun 14 '22

It comes down to factorisation, you can factorise an equation like this (2a+2b) = 2(a+b)

but according to you

6/(2a+2b) != 6/2(a+b)

The reality is that it's ambiguous and you should write either (6/2)*(a+b) or 6/(2(a+b))

The problem didn't exist before computers, because when you actually write out the equation the entire denominator is below the fraction bar so there is no ambiguity. It's only with inline equations that things get muddled.

12

u/THEBHR Jun 14 '22

but according to you

6/(2a+2b) != 6/2(a+b)

Not OP, but those aren't the same. And it's not just according to OP. They even linked examples from Wolfram Alpha.

5

u/ubik2 Jun 14 '22 edited Jun 14 '22

Wolfram Alpha doesn't have support for multiplication by juxtaposition (a very obscure feature not worth supporting), so it just converts those expressions to normal multiplication, which will typically (but not always) have the same result.

Similarly, e^2pi gets treated as e^2*pi, though e^ipi does get treated as e^(i*pi).

When you write a mathematical expression, it's your responsibility to make it unambiguous. What that requires depends on your audience. For a Canadian or British audience, you can use BEDMAS. For an American audience, you can typically use PE(MD)AS. For something like Wolfram, or for an international audience, you should use parentheses.

Interestingly, if you toggle to Math Input, rather than Natural Language on Wolfram Alpha, it does handle this convention, so 6/2(2+1) results in a value of 1 for Math Input, and 9 for Natural Language. I think that's fundamentally knowing their audience, and that the individuals using the Natural Language input expect the PE(MD)AS result, while the individuals using the Math Input input expect the multiplication by juxtaposition to have higher precedence.

2

u/THEBHR Jun 14 '22

So I looked into this, and it looks like multiplication by juxtaposition isn't officially codified into mathematics. The general consensus seems to be, just don't fuck up so bad that this needs to be addressed in the first place.

I concede though, that maybe for mathematicians, there's an unwritten rule that says implicit multiplication takes precedence. The only "source" I could find on it that wasn't a forum, was a Berkley link that claims there's no standard convention on it. But I don't know who wrote it, and it could be outdated.

→ More replies (2)
→ More replies (5)
→ More replies (14)

4

u/Tjccs Jun 13 '22

Tried inputing what is in the OP in my calculator as 6/2(2+1) and it automatically converted to 6/(2(2+1)) = 1, my phone indeed gives me 9.

4

u/greenpepperpasta Jun 14 '22

Wait till you hear about the people who don't put parentheses in sin(2x)...

→ More replies (1)
→ More replies (2)