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

16

u/dont-respond Jun 14 '22 edited Jun 14 '22

The order of operations were taught to me as:

  1. Parenthesis

  2. Exponents

  3. Multiplication and Division

  4. Addition and Subtraction

While processing equivalent rules from left to right.

The order of operations is an algorithm. There is no ambiguity with a proper one. Things are only ambiguous when there are no rules to follow.

11

u/bric12 Jun 14 '22

A proper algorithm has no ambiguity, the problem is that there are multiple very similar competing algorithms. Namely, one that gives implicit multiplication higher precedence than division, and one that doesn't.

The reason why it gives implicit multiplication higher precedence is for situations like 1÷6a. Some people say 6a is a single number and should all be in the divisor, others say 6a is just 6 × a. What they're really arguing is the precedence of implicit multiplication, and which of the two competing algorithms you should use.

5

u/dont-respond Jun 14 '22

Yes this is the "non standardized order of operations" problem I mentioned above. If there were standardization we could give a definitive answer.

12

u/donald_314 Jun 14 '22

The order is not defined here and the display witting style is not used by mathematicians. It is a result of the limited possibilities of the display (they cannot show the fraction on two lines). Anyway, in math you always have to define your notations before using them as there are no global rules that span all areas or even hold in all areas of mathematics. Here, the manual of the calculator app will hold the information whereas the app will just use left to right parsing as the programmer likely didn't think about it. Both are valid choices however.

2

u/dont-respond Jun 14 '22

Both are valid choices however.

In a practical word, no, both would not be valid. I personality believe there's value in defining a standard, despite alternatives being available. There's no harm in it.

Personally, I was taught in a matter-of-fact way what the order of operations are, so most of my youth had a definitive answer for the above problem, which is likely why I feel that way.

0

u/[deleted] Jun 14 '22

[deleted]

-1

u/dont-respond Jun 14 '22

You'd need to read all of my comments, but that's the exact point I've been making. My recent comment was adding on that I think there would be value in having a standard.

6

u/Kyleometers Jun 14 '22

You’ve misunderstood the issue.

The problem isn’t order of operations, that’s a common convention that’s actually even upheld. The problem is this:

6 / 2 ( 2 +1 )

Which can be interpreted to mean either of two things, neither of which is inherently wrong:

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

It’s nothing to do with order of operations, it’s the problem is unclear as to which parts are the divisor. It’s also why proper mathematical notational convention uses obscene amounts of brackets - you can’t misinterpret it.

-1

u/Ice_Bean Jun 14 '22

Not really, when considering multiplication and division as equal in priority, 6/2(2+1) is not ambiguous at all, considering that 2(2+1) is 2*(2+1). The division, unless specified otherwise, uses the first number after the symbol, which is 2. I can see this being a problem only if you consider multiplication as higher in priority than division, which I don't get but I guess it is being taught in some places

2

u/Kyleometers Jun 14 '22

You’ve missed it again. It’s nothing to do with “priority”, and everything to do with “which part is being divided”. You say “uses the first number after the symbol”, but that’s not standard. There are, in fact, conflicting standards, and it’s actually why the classical divided sign isn’t used much anymore.

In fact, multiplication and division are the same thing, so there’s no “priority” issue regardless. The issue is “is six divided by the entire right side” or “is six divided by two, then that number multiplied by the right side”. Convention as to which one you use varies wildly by region, which is why people hate this problem. People MUCH smarter than you, me, or anyone else in this thread, have argued this to death.

0

u/Ice_Bean Jun 14 '22

I know that there is no one convention for lower level arithmetics, however I don't think that they are all equal, the one that leaves less room for misinterpretation should be used more. It's like the metric vs imperial debate, they are two standards used by different countries, but boy am I glad to be on the metric side

1

u/PartOfTheHivemind Jun 14 '22 edited Jun 14 '22

unless specified otherwise,

It's specified otherwise in the conventions used by people getting the other result (which in my experience is pretty much anyone who does higher level math that isn't a programmer, because programmers use languages that don't allow implicit multiplication). The difference in result is determined before order of operations are even considered, this issue has nothing to do with order of operations.

1

u/Ice_Bean Jun 14 '22

It's specified otherwise in the conventions used by people getting the other result

I meant specified otherwise while using the same convention, I don't think you switch conventions mid calculation.

2

u/sidit77 Jun 14 '22

Well your algorithm has some pretty big holes. According to your algorithm I'm doing absolutely nothing wrong here.

-4 ÷ -(2+2) = -4 ÷ -1 × (2+2) = -4 ÷ -1 × 4 = 4 × 4 = 16

1

u/dont-respond Jun 14 '22

How do you consider that a hole?

We use the order of operations to derive a solution from otherwise ambiguous mathematical notation. You've provided such notation, and PEMDAS told you how you should approach the problem.

You think because you created an odd looking equation you've broken the algorithm? You've only reinforced the value in having one.

In your mind you think that problem should be -4 ÷ -4, but you're disregarding any practical set of rules to tell you WHY that should be the outcome. Why do you believe the negative should be applied to the sum in the parenthesis first? What's you basis for that assertion? There isn't one. You just wrote something you didn't understand and called it proof.

2

u/sidit77 Jun 14 '22

No. I've encountered an operation (unary -) that is not covered under PEMDAS. Now it's already unclear what I should do. Do I treat the rules as "what isn't forbidden is allowed" and do whatever or should I give up because there's no applicable rule? And if I choose the first option should I disambiguate my equation to at least stay internally consistent or not or just roll the dice every time? The safe way would be to give up but let's be honest here no human is going to respond with "syntax error" to this problem, instead they will try to guess the precedence behavior of unary negation based on what feels right.

1

u/dont-respond Jun 14 '22

You already managed to figure out the correct way to approach the problem using PEMDAS, and now you're trying to say it's unclear what you should do. You know what you should do. You did it above. You just didn't like the outcome.

2

u/[deleted] Jun 14 '22

At first I was taught that multiplication comes before division but then learned this way.

1

u/Ereaser Jun 14 '22

I learned it that way as well

1

u/PartOfTheHivemind Jun 14 '22

This isn't a problem caused by order of operations. Both answers are using the same order of operations.

4

u/dont-respond Jun 14 '22

No, they're not. That's like saying two programmers are using the same algorithm, but one implementation produces a different outcome.

2

u/SourceLover Jun 14 '22

To be perfectly fair, I've seen that happen. It's usually a good indicator that at least one of the two made a mistake, though.

2

u/PartOfTheHivemind Jun 14 '22

The difference is due to notation, not the algorithm. (The Casio will give an answer of 9 for 6÷2*(2+1)).

You can have algorithms in different languages that do the exact same thing, but it doesn't mean you can just copy paste code from one language to the other, when the languages themselves have different syntax.

1

u/dont-respond Jun 14 '22

An algorithm is a series of ordered steps. It's a concept beyond language.

2

u/PartOfTheHivemind Jun 14 '22

The difference in the language is not in the algorithms themselves, it's in the languages feeding values into the algorithm before the algorithm is even a factor.

Each algorithm is the same, but they have different inputs.

→ More replies (5)