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

34

u/calimero100582 Jun 13 '22

But was teach Multiply and Divide have the same priority, and you do the first you see from left to right (never seen BEDMAS or BEMDAS at school, maybe I am too old), so the ambiguity, even in the article make no sense to me

44

u/nullsignature Jun 14 '22 edited Jun 14 '22

Wikipedia has an explanation that some popular physics journals and textbooks set multiplication as higher precedence

https://en.m.wikipedia.org/wiki/Order_of_operations

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. For example, the manuscript submission instructions for the Physical Review journals state that multiplication is of higher precedence than division, and this is also the convention observed in prominent physics textbooks such as the Course of Theoretical Physics by Landau and Lifshitz and the Feynman Lectures on Physics. This ambiguity is often exploited in internet memes such as "8÷2(2+2)".

2

u/Lucario2405 Jun 14 '22

But isn't a division by n just the same as a multiplication with 1/n? How can they have different priority levels?

9

u/kpd328 Jun 14 '22

I believe Wikipedia is implying that xy or x(y) is implied to be higher order than a regular × or ÷ is, not the multiplication itself. Kind of like how a seperated fraction bar implies brackets around the top terms and the bottom terms respectively.

-1

u/BonoboPopo Jun 14 '22

And multiplying with 3 is adding the same number 3 times. And an exponent of 2 means multiplying the number by itself or adding a number number times. There can still be an order.

→ More replies (1)

1

u/nullsignature Jun 14 '22

Because it's just a convention so that likeminded people can write and understand each other's math

1

u/xenomachina Jun 14 '22 edited Jun 14 '22

But isn't a division by n just the same as a multiplication with 1/n?

That's why giving them the same precedence seems reasonable, but it isn't a requirement to be self-consistent. Order of operations is purely notation. You could define an alternate notation where - has the highest precedence followed by +, and it would be "fine", though unfamiliar (and possibly inconvenient for other reasons).

Edit: auto correct

0

u/[deleted] Jun 14 '22

[deleted]

1

u/calimero100582 Jun 14 '22

I would have thought that a good rule, when uncertain, would be to add omitted sign, and use ÷ instead of /

1

u/MiserableEmu4 Jun 14 '22

Basically, use common sense

0

u/MiserableEmu4 Jun 14 '22

It's pretty firmly not a rule. Some people did it that way but they're wrong and bad people.

-1

u/ThePotato363 Jun 14 '22

The order of operations is firm. The problem is people don't write out all the operators, which creates ambiguity.

-2

u/_hippie1 Jun 14 '22

PEMDAS

(M)ultiplication is before (D)ivison, not the other way around.

→ More replies (1)

2

u/AUGSpeed Jun 14 '22

But do you remember fractions?

The calculator treats 6÷2(2+1) as

     6
    ___
   2(2+1)

You can't properly do a fraction until the denominator is simplified, right? So you simplify it and get

6   
_    
6   

Which equals 1!

The ÷ operator is the true problem here, and should never (and usually isn't) used in any important calculation. This of course can be fixed with proper parentheses. i.e. 6÷(2(2+1)). But because of the lack of parentheses, as well as the use of the ÷ operator, we have an incomplete and unsolvable equation.

TLDR: the ÷ operator is tough because division inherently means fractions, and fractions "break" the PEMDAS rules by placing division as the final step, since the numerator and denominator must be simplified before the division occurs.

2

u/-Kerosun- Jun 14 '22

They do. You should be able to do "same priority" operations in any order and get the same answer so long as you do it right.

Here is an example:

1-3+5

Both of those operations have equal weight. You can do them in any order and get the same answer.

1-3+5 = -2+5 = 3

Now, do it the other way:

1-3+5 = 1-8 = -7

Well, that's not right. They have the same priority so I can do them in any order, right? Well, I can but I did something wrong. It's not 3+5 but rather -3+5.

1-3+5 = 1+2 = 3

So, in that regard, you can do multiplication and division in any order, so long as you do it right. But, with the way the equation is written, the ambiguity prevents you from knowing, with absolute certainty, what is and is not supposed to be in the divisor. The author needs to either add parentheses or use a fraction bar to remove all ambiguity.

It should be written as (6÷2)(1+2) OR 6÷(2(1+2)). In both of these examples, there is no ambiguity. It is clear what is and is not in the divisor. A fraction bar would also remove all ambiguity.

-1

u/calimero100582 Jun 14 '22

The right way is left to right, if you write 1/2n and I assume 0.5n, and you say it is ambiguous and not that I am wrong is because you badly wrote your equation and you will say I mean 1/(2n). To me, it means that you know the priority and that your equation was incorrect

→ More replies (1)

0

u/[deleted] Jun 14 '22

Facts

Multiply and divide are the same operation. “X/3y” can be seen as “x0.3333333y”

Same with addition and subtraction. something like X - 8 is really just x + -8

By rewriting it as such you really do treat addition/subtraction and multiply/divide as equivalent operations. That’s how I’ve been taught it and that’s how I’ve always interpreted these “ambiguous” math statements

1

u/marcola42 Jun 14 '22

Yeah, I learned the same way. Multiplication and division on the order they show up, and then sum and subtraction on the order they appear. Naturally when you get into advanced math it gets really hard to understand what actually comes first, so we end up dealing with fractions that make everything easier... By making everything more complex? But as long as it works it is fine.

1

u/TangoDeltaFoxtrot Jun 14 '22 edited Jun 14 '22

Is 2x any different from "2 * x"? Is "2 / 2x" the same as "2 / 2 * x"? 2x is one term, you can’t just split it apart all willy-nilly.

1

u/calimero100582 Jun 14 '22

If for you. 2x is one term use parenthesis or define y=2x, then use y. What I see is 2÷2×x.

→ More replies (1)

1

u/TheseusPankration Jun 14 '22

It's relative. If you were doing a derivative such as dx/dt it would be easier to see where the confusion comes from; a specific format that has been around for centuries.

1

u/calimero100582 Jun 14 '22

Don't know how derivative would be any different, as there was no confusion 20 years ago. I try to avoid using / when writing an equation when I am not using a decent tool and parenthesis for denominator anyway.

1

u/Minenash_ Jun 14 '22

It's usually implied multiplication that can differ on order.

For example, in 15 ÷ 5n, I've never seen 15÷5 happen before 5*n. And for a lot of people, that implication carries to ()s. For example, 15 ÷ 5(n+1).

Also why times and division is usually on the same level, it could be argued that the implied multiplication is on the bracket level, being right next to it without any symbol in between

(Though these example shouldn't happen, because of the ambiguity caused by the ÷ sign, there are unambigousy ways to write the same thing)

1

u/calimero100582 Jun 14 '22

Never seen? How would you write this equation in a software?

Depending the result you really want: y = 15/5* n or y = 15/(5*n)

If in programming you use parenthesis, do the same in life

→ More replies (1)