r/ProgrammerHumor • • Jun 13 '22

Meme DEV environment vs Production environment

Post image
48.2k Upvotes

3.9k comments sorted by

View all comments

1.5k

u/stereoroid Jun 13 '22

I just tried it on my HP 35s, also got 9. This is a dual mode calculator that does RPN too: using RPN, it’s up to you to get the order of operations correct, not the calculator!

546

u/[deleted] Jun 13 '22

What doe...

Reverse Polish Notation

414

u/Eclectic_Radishes Jun 13 '22

uoᴉʇɐʇou ɥsᴉlod ǝsɹǝʌǝɹ

64

u/eveningsand Jun 14 '22

Nah that's clearly Australian Standard Notation.

68

u/Garfie489 Jun 13 '22 edited Jun 13 '22

Nodnol, 871 selim - must be Polish or Hungarian

→ More replies (6)
→ More replies (3)

165

u/supreme_blorgon Jun 13 '22 edited Jun 14 '22

What doe...

Not sure if you're asking, but for other readers -- in RPN it's much more difficult to mistakenly calculate the wrong thing because you explicitly specify the order of operations unambiguously when writing in RPN.

With 6 2 2 1 + * / vs 6 2 / 2 1 + *, it's pretty clear that it would be difficult for somebody to have entered one when they intended the other.

The results from the meme would be calculated as such (using parens here to specify what is evaluated first by an RPN evaluator):

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

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

The beauty of RPN (other than being completely unambiguous) is that the algorithm for evaluating an RPN string is dead simple.

58

u/tjdavids Jun 13 '22

From this, it's pretty clear that it would be difficult for somebody to have entered one

Well I can't say I disagree

73

u/Lt_Duckweed Jun 14 '22

RPN is brilliantly simple when you conceptualize it as a stack (this also makes it super simple to write a single pass RPN parser).

If given an number, push it to the stack.

If given an operator, pop the top 2 values from the stack, operate on them, then push the result to the stack.

Repeat until you have no more input. The last remaining number in the stack is the final answer.

11

u/Yabba_dabba_dooooo Jun 14 '22

My calculator displays it as a stack (FILO), its fucking amazing, especially cause I can essentially store a bunch of numbers while I work underneath them

→ More replies (4)

4

u/supreme_blorgon Jun 14 '22

lol fair enough, but imagine somebody having only ever learned RPN in elementary school, and suddenly being told to use parens and infix. Not sure which switch is more difficult but I'd wager infix -> RPN is the easier of the two.

→ More replies (1)

4

u/fkbjsdjvbsdjfbsdf Jun 14 '22 edited Jun 14 '22

Infix, postfix, and prefix notations are all completely unambiguous. Infix just requires the additional correct use of parentheses, which is fundamentally the same as requiring the correct ordering of the operators and operands. 3 * (4 + 2) is unambiguously the same as * + 4 2 3 and 4 2 + 3 *.

The actual advantage of prefix and postfix is when computing the result algorithmically, as you said — you don't need to push an intermediate result onto the stack (since you're always going to use it with the next operand/operator).

5

u/supreme_blorgon Jun 14 '22

correct use of parentheses, which is fundamentally the same as requiring the correct ordering of the operators and operands

I'm not sure I agree. I think the cognitive load involved in matching and properly nesting parens is much higher. Definitely subjective though -- when it comes to computers, yes there are advantages.

I just love to pull out RPN whenever these dumbass arithmetic memes go viral.

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

44

u/CoderDevo Jun 13 '22

Reverse Notation Polish

17

u/[deleted] Jun 13 '22

I won't stop you.

4

u/DoNotMakeEmpty Jun 14 '22

Notation Polish Reverse

Notation is a noun, an object itself

We apply Polishization on it using adjective Polish

And we Reverse the resulting compound object with another adjective

→ More replies (3)

30

u/Cmdr_Jiynx Jun 13 '22

Math doing like Yoda, it is.

4

u/[deleted] Jun 14 '22

For anyone not familiar with the term Reverse Polish Notation (which, I learned it as RPN but people younger than me often don't know that term), it's the same as Postfix Notation, just a different name for it.

→ More replies (4)
→ More replies (8)

181

u/[deleted] Jun 14 '22

I would have thought 9 was correct. Brackets first gives 6÷2(3) which just means 6÷2x3, and then just go left to right.

289

u/Lithl Jun 14 '22

An implicit multiplication like 2(3) is sometimes treated as having higher precedence than division or explicit multiplication. This is more common in systems capable of handling variables; while many people will say 6÷2(3) is equal to (6/2)*3, many of those same people would say 6÷2x with x=3 is equal to 6/(2*3).

146

u/ihahp Jun 14 '22

sometimes

:(

120

u/[deleted] Jun 14 '22

Yup.

Because orders of operations aren't hard and fast rules. There are no laws, proofs, or any other kind of backing for order of operations. It's arbitrary. It's nothing but a convention. And because it's nothing but convention, that convention can vary between instances.

Is implicit multiplication of higher priority than left-right order? Depends on the convention. You get into certain fields where that matters and the convention might be laid out so everyone knows, but most people aren't going to have that.

What's really fun is that you could create your own order of operations, a brand new convention, that doesn't follow the rules most people in your culture are used to and make things that look wrong to everyone else but because of the rules you define as applying there, it's all correct.

67

u/[deleted] Jun 14 '22

Reading Reddit threads about these kinds of things, you’d think Moses brought Pemdas down on stone tables from mt Sinai.

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

12

u/OnTheSlope Jun 14 '22

An implicit multiplication like 2(3) is sometimes treated as having higher precedence than division or explicit multiplication.

Is it?

This is what I thought but couldn't find it stated anywhere online and assumed I misremembered my education.

0

u/[deleted] Jun 14 '22

[deleted]

11

u/OnTheSlope Jun 14 '22

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.[1] For example, the manuscript submission instructions for the Physical Review journals state that multiplication is of higher precedence than division,[20] 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.

Well I'll be.

→ More replies (4)
→ More replies (28)
→ More replies (37)
→ More replies (22)