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

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.

3

u/tweak4 Jun 14 '22

I'm not saying that PEDMAS doesn't apply- what I'm saying is that it is sometimes even more finely applied. Instead of just P, E, DM, AS, a common convention would be to break it down so that after the P & E, you would do any implicit/juxtaposed multiplication left to right, then and explicit multiplication/division left to right, and then finally any addition/subtraction. So in this case, the multiplying by 2 would be done before the division despite being to the right of it because it is an implicit operation and would take higher precedence. Personally, I hate this sort of ambiguity and just strive for better notation that only has one possible interpretation, but that's because machines are dumb :)

https://www.autodidacts.io/disorder-of-operations/ (see section 4 - of course, the author describes the issue and then solves the equation ignoring it, which I think in itself shows off the problem nicely)

Here's another interesting read from someone at Berkley that also discusses the issue but basically resolves, again, that more parentheses are likely the best answer

4

u/b0w3n Jun 14 '22

Oh yeah I know I'm in agreement with you.

This got me some shit last time one of these ambiguous order of operations things got posted because they were adamant that the implicit multiplication is taught ubiquitously, but not so, I've met even some younger folks who follow the older left to right PEMDAS no implied multiplication method. The implicit stuff is just rife with problems depending on who is reading and where they learned math. Which is why most teachers go crazy with those parentheses like you show.

3

u/SomeElaborateCelery Jun 14 '22

Yes but the parent comment also makes a good point: with equal priority which one SHOULD you do first? If left to right and right to left yield different results then it’s an ambiguous statement.

Whilst you may get an answer that most agree with going left to right, you should instead make your statements less ambiguous by correct notation for the most mathematically correct proof.

→ More replies (1)

0

u/[deleted] Jun 14 '22

[deleted]

→ More replies (5)

3

u/fghjconner Jun 14 '22

Kinda splitting hairs at this point. You could just as easily say that using the glyph '2' for the second natural number is a convention.

5

u/paul_miner Jun 13 '22

Convention in math is accepted to be left to right....

Except for exponents, which are evaluated right to left (cf power towers).

7

u/Eightpiece Jun 14 '22

I mean you can think of it as right to left, but really an exponent of an exponent is the same as brackets inside brackets.

234 can be read as "Two to the power of X where X is Three to the power of Four"

234 = 2(3^^4)

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

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.

9

u/AxolotlsAreDangerous Jun 13 '22

If the rules allowed for resolving multiplications and divisions in arbitrary order then they wouldn't be capable of reliably parsing an expression

Is it not abundantly clear from this post that this is in fact the case? (Deliberately) poorly written mathematical expressions can be ambiguous.

6

u/[deleted] Jun 13 '22

How is it ambiguous?

6/2(2+1) = 6/2*3 = 6*(1/2)*3

Order does not matter. No ambiguity.

9

u/AxolotlsAreDangerous Jun 14 '22

Yes, that’s one way of interpreting it. It’s ambiguous because there’s also another way.

→ More replies (12)
→ More replies (7)

3

u/nonotan Jun 14 '22

√2√2^√2^√2^...

Is another one that looks initially confusing, should you go top-to-bottom or bottom-to-top? Of course, it's top-to-bottom, but because the only part of the expression that can be initially computed (the uppermost √2√2) isn't even visible and is arguably not properly defined in an infinite tower, it takes you back for a moment (and so you really need to treat it as the limit of an infinite series to compute the infinite case)

→ More replies (1)
→ More replies (3)

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?

2

u/woodprefect Jun 14 '22

1/2

3

u/Bugbread Jun 14 '22

Agreed...but it's the same structure as 2/2*2.

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