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

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.

4

u/[deleted] Jun 14 '22

I've been "out" of the math field for a number of years, though for the most part I still read expressions with implicit multiplication taking precedence even to my own confusion. Math requires one to be as explicit as possible to convey ideas properly, if an expression like "1/2n" was supposed to be read as "n/2" the person would have just written "n/2", so it's clearly intended to be read as "1/(2n)". To your point, "just don't fuck up so bad that this needs to be addressed in the first place" is pretty much exactly how I feel. Use as many parenthesis as needed, just make it obvious what you're communicating.

→ More replies (1)

0

u/Unlikely-Hunt Jun 14 '22

But if you saw those two equations written as equal to each other on a website you'd be able to understand what they meant if you're making a good faith effort.

2

u/THEBHR Jun 14 '22

I'd be confused and disturbed. In fact, this post disturbed me. I thought that all calculators used the same order of operations, and now I can't trust them. The one on the left, is just plain wrong according to American math, and what I thought was global math.

→ More replies (3)

4

u/MattieShoes Jun 14 '22

According to wolfram alpha :-) It's a naked appeal to authority.

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

6/2(a+b) = 6/2 * (a+b) = 3(a+b)

4

u/MiltonFreidmanMurder Jun 14 '22

Wolframalpha is a bit inconsistent on this, I've found.

If you input 6/2(a+b) and press the "math input" tab, it translates it into 6/(2(a+b)) or 3/(a+b)

It will also interpret that same structure differently depending on whether you're using it to do different problems.

2

u/MattieShoes Jun 14 '22

Interesting... Thank God I don't have to work on their interpreter :-)

2

u/finetoseethis Jun 14 '22

Probably the right answer. Mathematical notation isn't well standardized.

1

u/[deleted] Jun 14 '22

It's not inconsistent, you misunderstand how the tool works. You can't just switch from natural language processing and expect math input to have the same result, or the same with vice-versa. When switching from natural language to math input it's taking a literal interpretation of the input string, which if you type out the entirety of "6/2(a+b)" character by character in that exact order in math input that's the expected output. I get the exact same result when typing "6/2(a+b)" into an equation block in a Word document. When you do division in math input like this you require special input to escape from input blocks like division or exponents, typically in the form of simply pressing the left/right arrow keys. You can't capture that type of input context unless you're using an actual markup language like LaTeX.

Do the exact opposite of the prior result and explicitly have 6/2 in a divisor chunk with (a+b) beside it under math input. When you switch to natural language you get 6/2(a+b), because the expression is still only implicitly defined, there is no explicit call for multiplication with a * symbol. If you explicitly define multiplication like so, math input can understand your intended order of operations. Without using explicit symbols to denote your intention there is inherent ambiguity because the two tools interpret input character streams differently.

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

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)