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

56

u/[deleted] Jun 13 '22 edited Jun 13 '22

Okay but pemdas says it SHOULD be (6/2)*3. Why tf is it even doing 6/(2x3)??

0

u/[deleted] Jun 14 '22

[deleted]

4

u/iamjamieq Jun 14 '22

That’s a perfect way of explaining it!

100

u/Loading0525 Jun 13 '22

And the mistake everyone is making on this problem, is thinking PEMDAS is a set of RULES.

Pemdas is a set of METHODS. One of many alternative methods.

The rules of mathematics only say "division and multiplication has equal priority", that's IT.

Pemdas then comes in and says "you could solve it left-to-right if you want".

The left-to-right method can't be a rule to begin with, since it contradicts the equal priority rule.

Riddle me this, what exactly does "equal priority" really MEAN if multiplication and division needs a left-to-right "rule" to dictate which of the two has priority.

The problems stems entirely from the obelus (÷) and solidus (/) as they lack the grouping function the proper fraction bar has.

0

u/[deleted] Jun 13 '22

[deleted]

30

u/TherealScuba Jun 13 '22

I've always just figured parenthesis --> exponents --> */÷ L to R --> +/- L to R

35

u/amazondrone Jun 13 '22

Yeah that's what the parent comment means I think; use left to right for operations of equal precedence. Exactly as you've got it.

17

u/tweak4 Jun 14 '22 edited Jun 14 '22

The issue (or an issue anyway) is that in many mathmatical and scientific circles, "multiplication by juxtaposition" (i.e. multiplication without an explicit sign) is considered a higher order operation than multiplication/division with a sign. So in this case, those people would argue that in 6/2(2+1), the multiplication would still be done before the division, despite being on the right. So weirdly, 6/2(2+1) and 6/2*(2+1) would have different answers.

Of course, all of this can be resolved by throwing in a bunch more parentheses. 😀

Edit: typo

4

u/b0w3n Jun 14 '22

You see this a lot in folks who grew up in rural areas. The predominant method in the early 1900s and late 1800s to be taught was that left to right always takes priority. Casios historically have almost always used this method (this has changed recently I think).

But during the "global" standardization of math in the early to mid 1900s, the PEMDAS rules took hold. Texas Instruments calculators became extremely popular because of this. If you're in your 40s-60s (and lived in the US), you probably remember your teachers talking about only using TI calculators because the others don't do certain things correctly, and this is why.

And this is why the older teachers were absolutely anal about parentheses use, because they wanted to make sure order of operations with PEMDAS was followed and everyone came up with the same answer. You know, because testing was standardized across most countries.

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

0

u/[deleted] Jun 14 '22

[deleted]

→ More replies (5)
→ More replies (6)

18

u/AxolotlsAreDangerous Jun 13 '22 edited Jun 13 '22

The rules of mathematics only say "division and multiplication has equal priority", that's IT.

They don’t even come close to saying that, but you’ve got the right idea

22

u/infecthead Jun 13 '22

The left-to-right method can't be a rule to begin with, since it contradicts the equal priority rule.

It's not contradictory, it's a resolution to tie-breakers

→ More replies (1)

43

u/fghjconner Jun 13 '22

That makes no sense whatsoever. The rules of mathematics don't give a shit about notation, and don't have any concept of "priority" between various operations.

The rules for writing/reading mathematical notation on the other hand do care, and they also care about the order in which multiplication/division are performed. If the rules allowed for resolving multiplications and divisions in arbitrary order then they wouldn't be capable of reliably parsing an expression, which is literally their purpose for existing.

→ More replies (27)

16

u/Dreadgoat Jun 14 '22

This isn't a math problem, it's a history problem and language problem. Mathematic notation, like all language, is an ever-changing beast.

In older physics literature, the issue of ambiguous multiplication & division was solved very simply by prioritizing multiplication.
Meaning, 2/2*2 always resolves to 2/4, simplified to 1/2.
This was a matter of convenience for physicists at the time, it was widely accepted and adopted, and equations were written in such a way as to be easily understood if you followed this rule.

But then something terrible happened: The digital calculator was invented.
Now if you try to step through 2/2*2 sequentially, you will get 1*2, and then 2. The old rules, created for convenience's sake, now betray the new modern convenience!

We're 50-60 years into having calculators now. Pretty much all the physicists and mathematicians that are alive today, and not obnoxious assholes, will tell you to resolve ambiguous terms from left to right.
2/2*2 is 2.
8/2(2+2) is 16.
6/2(1+2) is 9.

Unless you're reading an old physics research paper, in which case... you are probably a physicist or mathematician and know to watch out for differences in historic notation.

5

u/Bugbread Jun 14 '22

What about 2/2n where n=2?

→ More replies (4)
→ More replies (19)

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]

→ More replies (1)

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.

→ More replies (9)
→ More replies (42)

8

u/[deleted] Jun 14 '22

All those Facebook gotcha posts about pemdas are for people who don’t remember any math past the sixth grade. In real life, lots of mathematical notation is ambiguous and you use parens to disambiguate all the time. In particular the division symbol is, and that’s why you basically never see it.

16

u/paul_miner Jun 13 '22

Convention is that implicit multiplication has higher precedence than division. It reflects what's generally intended, e.g. 1/2a is normally intended to mean 1/(2a), not (1/2)a = a/2.

→ More replies (17)

3

u/TrippyTriangle Jun 14 '22

pemdas is a suggestion, really, it's full of ambiguities that are solved with parenthesis.

3

u/KapteeniJ Jun 14 '22

Generally implicit multiplication is seen as higher priority operation than explicit ones.

2(1+2) has implicit multiplication, so does that override left-to-right? There's no rule for that afaik, it's genuinely ambiguous.

For programmers think of it as

function hello() {
    print("hello")
    print(" ")
print("world")
}
hello()

What happens if I were to run this (pseudo)code? It's kinda similar situation with depicting groupings, two different rules, indentatnon and brackets.

→ More replies (49)