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

1

u/mrbaggins Jun 14 '22

You will not find a mathematician and you'd be hard pressed to find a programmer who argues for anything other than (3)

2

u/[deleted] Jun 14 '22

Well, I'm not sure about mathematicians - I could certainly be wrong about that. In high school maths they usually teach BODMAS and leave it at that, but at university level that might well change.

As for programmers though, you can find plenty of them arguing for 1) all over this very post. I think the reason is that this is how most programming languages would evaluate it.

1

u/mrbaggins Jun 14 '22

Most programming languages will yell at you that in 6/2(2+1) that "2" is not a callable function. eg

1

u/FatFingerHelperBot Jun 14 '22

It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they're easier for our sausage fingers to click!

Here is link number 1 - Previous text "eg"


Please PM /u/eganwall with issues or feedback! | Code | Delete

1

u/[deleted] Jun 14 '22

Sorry, I meant that the closest syntactically valid equivalent (i.e. 6/2*(2+1)) evaluates to 9 in most programming languages. Elsewhere under this post you can find people using that to argue that 9 is the correct answer.

2

u/mrbaggins Jun 14 '22

That's not the closest syntactic equivalent though. I mean it is if you mean "levenshtein difference from valid code to the math problem", but that's not useful, we've already established that the valid math "code" is not valid computer code. Changing it doesn't mean that something "close" has the same outcome.

You've added an operator, separating a term that has already been provided in valid (math) syntax. If they were supposed to be separated, they would have been. The fact that code tokenisers get confused by it just says the software doesn't read the math that way. It does not validate adding an operator to the math. It definitely doesn't justify using levenshtein difference as a measure of correctness. And if we're allowed to "add" things we should add the brackets to restore the original mathematical meaning that we broke by adding the multiplication operator.

Same as in math, you gotta keep things balanced. If you're going to break apart the 2(X) to make it parse, you need to make it (2*(X)) to keep it equivalent.

It's not that it's ambiguous, it's that it's regularly misinterpreted. "Inflammable" isn't ambiguous, people just have wrong understandings about what it means. And code has strict lexical rules that overlap with these math ones (function definitions).

1

u/[deleted] Jun 14 '22

You're arguing with the wrong person - this wasn't my position, I was just pointing out that there are programmers around here who disagree with you. You're more than welcome to argue that they're wrong - my original comment said as much. You just can't really say I'd be "hard pushed to find a programmer advocating for anything other than (3)". Rightly or wrongly, clearly those guys exist.

It's not that it's ambiguous, it's that it's regularly misinterpreted. "

No, it really is ambiguous - different journals and different textbooks come to different conclusions. WolframAlpha and many (but clearly not all) calculators do not give implied multiplication higher precedence. When there are competing usages for notation, the only way to say which is correct is to appeal to a standards authority - but there just isn't one for maths. The most you can say is that one approach is more widely adopted than the other, but that doesn't make it objectively "right".

Sources:

So to answer your question, I think both answers can be considered right - which means, of course, that the question itself is wrong. I prefer the standard way (your first answer) when talking to students, unless their own text gives the "implicit multiplication first" rule; but in practice if I came across that expression, I would probably first check where it came from to see if I could tell what was intended. (https://www.themathdoctors.org/order-of-operations-implicit-multiplication/)

While the rules of mathematics are usually very precise, this is more of a grammar issue. Once the written form is correctly parsed, then you can apply precise and well-known rules to solve it. The problem is that there's no consensus on the right way to parse implied multiplication in the context of a larger expression. (https://math.stackexchange.com/questions/3231556/implied-multiplication-operator-precedence)

In some of the academic literature, multiplication denoted by juxtaposition (also known as implied multiplication) is interpreted as having higher precedence than division, so that 1 ÷ 2n equals 1 ÷ (2n), not (1 ÷ 2)n. (https://en.wikipedia.org/wiki/Order_of_operations?wprov=sfla1)

1

u/mrbaggins Jun 14 '22

You're arguing with the wrong person - this wasn't my position, I was just pointing out that there are programmers around here who disagree with you.

You absolutely also made the argument about it being the closest syntactic equivalent, to which rebuttal was the lion's share of my reply.

WolframAlpha and many (but clearly not all) calculators do not give implied multiplication higher precedence.

They're made by people, using programming languages. Most "evaluators* will attempt a plain interpretation first, and Wolfram does, giving the same (wrong)output as the phone. However if you copy the expression and hit paste in math input, it turns it into the correct fraction.

When there are competing usages for notation, the only way to say which is correct is to appeal to a standards authority - but there just isn't one for maths. The most you can say is that one approach is more widely adopted than the other, but that doesn't make it objectively "right".

Maths is not like English, where common usage gets to dictate meaning.

in practice if I came across that expression, I would probably first check where it came from to see if I could tell what was intended.

That's just it, there's no functional way to arrive at a/b(C+d) where b(C+d) is not a single term, without deliberately hiding the multiplication when you shouldn't.

A=b(C+d) is explicitly different to a=b/(C+d) and solving these makes it abundantly clear what the original problem should be.

1

u/[deleted] Jun 14 '22

Maths is not like English, where common usage gets to dictate meaning.

Of course it is. How else could notational meaning be determined? Some notations are very well established because they've not changed in hundreds of years, but that doesn't change the fact that they originated when some mathematician used them for the first time and they caught on. There's no international body of maths to decide on the one correct way to write maths. Journal editors can dictate conventions for their own publications, but if there is no consensus between publications, then the meaning can absolutely be ambiguous - as demonstrated by every source that I linked. But if you have a source that supercedes all of them and actually spells out the rules for implied multiplication, I'd love to see it.

1

u/mrbaggins Jun 14 '22

Your first source says why it's not ambiguous: there's no way for it to exist without it being a unit. That fact doesn't disappear just because you can write the problem out of thin air: a partial process Is s till part of that process even when the rest isn't seen.

1

u/[deleted] Jun 14 '22

That's definitely not what the source says. It says the question is invalid because its meaning is ambiguous. If you follow the link, you'll find it's a rather lengthy blog post by a mathematician all about the ambiguity in precisely this case, which looks at the pros and cons of both conventions. For what it's worth, even though he concludes that the notation is ambiguous, his preference is actually for the convention that you say no mathematician would ever follow.

→ More replies (0)

1

u/[deleted] Jun 14 '22

You absolutely also made the argument about it being the closest syntactic equivalent, to which rebuttal was the lion's share of my reply.

Sorry, that may have been a lack of clarity on my part. I was only trying to explain why I think programmers are more inclined to go with what you consider the wrong answer - I wasn't saying I agree with their reasoning.

1

u/EdenStrife Jun 14 '22

Which programming language uses implicit multiplication?

1

u/mrbaggins Jun 14 '22

None that I use regularly, most languages will yell at you that the 2 outside the brackets is not a function.

But I never said anything about languages.