# Reverse Polish Notation

**URL:** <https://boards.straightdope.com/t/reverse-polish-notation/504991>\
**Category:** In My Humble Opinion\
**Created:** [August 1, 2009, 7:08pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991 "2009-08-01T19:08:17Z")\
**Posts on this page:** 14\
**Page:** 4

<div class="post-metadata">

**Author:** ![Johnny\_L.A](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/johnny_l.a/32/1084_2.png) [@Johnny\_L.A](https://boards.straightdope.com/u/Johnny_L.A)\
**Post date:** [August 10, 2009, 9:24pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/61 "2009-08-10T21:24:58Z")

</div>

> [@Napier](#):
>
> A new what? There aren’t any new 11C’s as far as I know.

Why not use a new model? From what I’ve read, HP went to hell for a few years. But the reviews of the HP 35s are generally very good.

> [@Napier](#):
>
> The PC is a very complicated place. If I want to do a multiplication and a division, I don’t need authentications and crashes.

I love my Mac! 😛

I have a certificate lying around somewhere that says I learned SAS. I keep stumbling across the books. But I haven’t used it in years, and have forgotten all of it. I don’t remember my COBOL either. I use an archaic language called Easytrieve.

---

<div class="post-metadata">

**Author:** ![Nava](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@Nava](https://boards.straightdope.com/u/Nava)\
**Post date:** [August 10, 2009, 9:43pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/62 "2009-08-10T21:43:37Z")

</div>

> [@Johnny\_L.A](#):
>
> So let me get this straight: The HP 11C is stable, it fits in a pocket well, people like the landscape layout, the display is large for the size of the unit, and it’s durable. Right? These are certainly things that I can see would generate a following. But why not use a new one?

Same reason I drag out my HP15C when I need a Real Calculator: because it still works!

---

<div class="post-metadata">

**Author:** ![Johnny\_L.A](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/johnny_l.a/32/1084_2.png) [@Johnny\_L.A](https://boards.straightdope.com/u/Johnny_L.A)\
**Post date:** [August 14, 2009, 4:22am UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/63 "2009-08-14T04:22:03Z")

</div>

The HP 35s arrived Tuesday. I’ve been very busy, so I haven’t had much of a chance to really play with it. But I did have it at work yesterday and needed a calculator, so I used it. RPN doesn’t seem that hard! I also tried an exercise in the book:

Square root of (8.33 x (4 - 5.2) + [(8.33 - 7.46) x 0.32]) / [4.3 x (3.15 - 2.75) - (1.71 x 2.01)]

(I wish I knew how to post the symbols.) I came up with 4.5728, which is what the book says.

I don’t know when I’ll be able to delve into the scientific functions, other than using the examples in the book. The manual comes on CD, BTW. I called HP minutes after the calculator came, and I had a hardcopy at my door early this morning.

The HP 35s looks more ‘retro’ IRL than it did in Amazon’s photo. Looks like it came out of the '80s. The other HPs I was reading about (42s, 32sii) ‘look right’, if that makes any sense. I could do without the chrome stripes, and I think it would look better if the sides were straight; but it’s still attractive. And function is what counts anyway. I think it will be a good calc to learn RPN on.

---

<div class="post-metadata">

**Author:** ![snailboy](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@snailboy](https://boards.straightdope.com/u/snailboy)\
**Post date:** [August 14, 2009, 1:44pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/64 "2009-08-14T13:44:39Z")

</div>

I’ve had an HP 32SII since high school. Just a couple of weeks ago, I bought a 49G. The 49 is a graphing calculator with a very extensive list of capabilities. It can do integrals and derivatives, for instance. But when it comes to simpler problems, the 32SII is the best calculator I’ve ever used.

What I like most about RPN is that you can start at any part of a problem and never have to use parentheses. That may not be so special when you’re calculating something that’s already written down, but when you’re doing a real life problem and figuring it out as you go, it can be very frustrating to do on an algebraic notation calculator. Here’s an example:

5 + 7 / 3 ^ (4 + 6)

This expression has to be done pretty much backwards. On an algebraic calculator, you don’t have much room to work with as far as rearranging the problem goes. You can swap it around so that the 5 is at the end of the problem, since 5 + x = x + 5, but that’s it. x / y != y / x and x ^ y != y ^ x. If you really wanted to, you could figure out the denominator first, divide it by 7, and use the 1/x key. Nothing can be done to allow you to do the exponent backwards though.

On my 32SII, I could do it like this:

4 enter 6 + 3 x\<\>y ^ 7 x\<\>y / 5 +

I could also use the 1/x key to do the division backwards just like on an algebraic calculator, but exchanging the registers is the only way to do the exponentiation backwards. Other ways I could do it are:

3 enter 4 enter 6 + ^ 7 / 1/x 5 +  
7 enter 3 enter 4 enter 6 + ^ / 5 +

Note that I couldn’t start with the 5 since that would overflow the stack and give the wrong results. Once the stack gets full, it simply discards the last register when you execute another push. When you pop it, whatever is in the last register stays in the last register. So if you tried to do this:

5 enter 7 enter 3 enter 4 enter 6 + ^ / +

That last addition operator would actually add 7, not 5. Note also that the second to last method (where we started with 7), while giving the correct answer, would leave the rest of the registers filled with sevens. So when the problems get pretty complex, you might actually _have_ to start somewhere other than the beginning of the problem. I’m sure I could come up with a problem that couldn’t be done at all on one of these four-register calculators, but it would be terribly complex.

This isn’t so easy to do on a calculator that has a larger stack, such as the modern graphing calculators. Not only would you have to do a lot of pushes to fill the stack, but I bet it would warn you when you overflow it too.

---

<div class="post-metadata">

**Author:** ![Kevbo](https://avatars.discourse-cdn.com/v4/letter/k/e47774/32.png) [@Kevbo](https://boards.straightdope.com/u/Kevbo)\
**Post date:** [August 14, 2009, 6:05pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/65 "2009-08-14T18:05:45Z")

</div>

I always found RPN nice for solving for something other than the equation in the book was written for…trivial example:

The book gives Ohms law as V=I\*R. I and V are given, solve for R.

Now that is simple algebra, but with an HP in hand, I wouldn’t even bother, just V enter I /

Yes, that is a trivial example, but I routinely do such with much more complex equations. Just punch in the term, and if it came from the “wrong” side of the equation, then use the reciprical operator instead of the one written.

The other day I had to do an excel spreadsheet where I needed to take bits from 16 cells and convert them to one 4 digit hexidecimal value. What a mass of parenthesis that needed. Took me 4-5 tries to get them right..though the color coding scheme in current excel version is helpful, this could have been done RPN style with zero parens. 4 bit example:

dectohex(bit0+2\*(bit1+2\*(bit2+2\*bit3)))

vs

Bit3 ^ 2 \* bit2 + 2 \* bit1 + 2 \* bit3 + dectohex

(^=push, enter, whatever)

The above nicely illustrates the source for “reverse” in the name.

> [@\_xiao\_wenti](#):
>
> The hard point for me is finding RPN calc programs for my computer.

Google “Excaliber”. There is also a freeware virtual HP-41 out there.

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [August 14, 2009, 10:33pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/66 "2009-08-14T22:33:39Z")

</div>

Since we’re sharing stack oriented code, here’s a sample of some FORTH. This is part of a system for studying PID control algorithms. These lines operate P and I and D regulation mechanisms for a MIMO (multiple input multiple output) system in which all the inputs influence all the outputs.

BTW this is an example of not very well written code; the definitions are too long. There should be more functinal nesting. I’ve grown since. Nevertheless, you can see some of what is happening. In this system, integers and floating point numbers are managed differently, and the backslashes start comments, and the colons start definitions of words (functions or subroutines).

\ CALCULATE P, I AND D ERRORS FOR SENSE0-SENSEn IN uV

variable first.time 1 first.time !  
create error.array 3 16 \* floats allot \ § error then I error then D error, nested within SENSEn  
error.array 3 16 \* floats erase \ Fill array with zeroes because it includes running sums  
: update.errors ( – ) \ Read sense.array and update error.array  
n.senses @ 0 do \ For each SENSEn used in regulation (SENSE0 - SENSEn-1)  
sense.array i cells + @ setpoint @ - \ Calculate the nth error in uV  
s\>d d\>f fdup fdup \ Convert to float, 3 copies  
error.array i 3 \* 0 + floats + f! \ Store nth error  
measured.timeinc f@ f\* \ Calculate nth addend for integral error  
error.array i 3 \* 1 + floats + f@ f+ \ Add it to running sum  
error.array i 3 \* 1 + floats + f! \ Store new running sum  
first.time @ 1 = \ Is this the first use of running sum?  
if 0 s\>d d\>f \ If so, prepare a zero…  
error.array i 3 \* 1 + floats + f! then \ …and reset running sum with it  
measured.timeinc f@ f/ \ Calculate nth derivative error  
error.array i 3 \* 2 + floats + f! \ Store it  
loop \ Go on to next sense  
0 first.time ! \ Now it can’t be first time any longer  
;

\ CHOOSE DRIVE VALUES BASED ON SENSE VALUES  
fvariable p\_correction fvariable i\_correction fvariable d\_correction  
: regulate ( – )  
offset.array drive.array 4 cells cmove \ Load drive.array with offset values  
m.drives @ 0 do \ For DRIVE0-DRIVEm-1  
n.senses @ 0 do \ For SENSE0-SENSEn-1 (now i is SENSE channel and j is DRIVE channel  
error.array i 3 \* 0 + floats + f@ \ Fetch proportional error  
gain.array i 3 \* j 9 \* + 0 + floats + f@ \ Fetch proportional gain  
f\* fnegate \ Calculate correction by multiplying error and gain, negate due to sign convention for gains  
f\>s \ Convert correction to integer  
drive.array j cells + +! \ Add proportional correction  
error.array i 3 \* 1 + floats + f@ \ Fetch integral error  
gain.array i 3 \* j 9 \* + 1 + floats + f@ \ Fetch integral gain  
f\* fnegate \ Calculate correction by multiplying error and gain, negate due to sign convention for gains  
f\>s \ Convert correction to integer  
drive.array j cells + +! \ Add integal correction  
error.array i 3 \* 2 + floats + f@ \ Fetch derivative error  
gain.array i 3 \* j 9 \* + 2 + floats + f@ \ Fetch derivative gain  
f\* fnegate \ Calculate correction by multiplying error and gain, negate due to sign convention for gains  
f\>s \ Convert correction to integer  
drive.array j cells + +! \ Add derivative correction  
loop loop \ Close loops  
;

---

<div class="post-metadata">

**Author:** ![Johnny\_L.A](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/johnny_l.a/32/1084_2.png) [@Johnny\_L.A](https://boards.straightdope.com/u/Johnny_L.A)\
**Post date:** [August 17, 2009, 4:32pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/67 "2009-08-17T16:32:26Z")

</div>

> [@yoyodyne](#):
>
> The HP app skin looks like crap. If you don’t mind the layout change check out [Free42](http://thomasokken.com/free42/).

I just saw this. There are many times I’ve wanted a calculator whilst driving on a long trip. And now I have an iPod Touch. I might have to download this.

---

<div class="post-metadata">

**Author:** ![Wednesday\_Evening](https://avatars.discourse-cdn.com/v4/letter/w/b2d939/32.png) [@Wednesday\_Evening](https://boards.straightdope.com/u/Wednesday_Evening)\
**Post date:** [August 18, 2009, 12:46am UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/68 "2009-08-18T00:46:38Z")

</div>

To answer the OP, I find RPN much more efficient since I don’t have to type in any parentheses. When I’m doing calcs I just have to make sure to start with the inner operations and work my way out. The values stored in the stack are useful too, although I must admit I don’t make as much use of them as I could.

I teach engineering (occasionally) and every exam at least one student will say, “My calculator died - can I borrow yours?” And I say, “Sure, but it’s RPN.” And they look at me funny and say, “Uh…nevermind.”

---

<div class="post-metadata">

**Author:** ![Johnny\_L.A](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/johnny_l.a/32/1084_2.png) [@Johnny\_L.A](https://boards.straightdope.com/u/Johnny_L.A)\
**Post date:** [August 18, 2009, 3:11am UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/69 "2009-08-18T03:11:04Z")

</div>

> [@Wednesday\_Evening](#):
>
> To answer the OP, I find RPN much more efficient since I don’t have to type in any parentheses. When I’m doing calcs I just have to make sure to start with the inner operations and work my way out.

See this is where I feel I’m missing something. I’ve done some exercises in the manual, and I’m like, ‘All I’m doing is working out from the parentheses.’ It feels there should be more than that.

---

<div class="post-metadata">

**Author:** ![RadicalPi](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/radicalpi/32/9806_2.png) [@RadicalPi](https://boards.straightdope.com/u/RadicalPi)\
**Post date:** [August 18, 2009, 8:12am UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/70 "2009-08-18T08:12:14Z")

</div>

If RPN is reverse Polish notation, then obviously there should be a normal Polish notation. So, my question is, why didn’t that, presumably the original, catch on?

---

<div class="post-metadata">

**Author:** ![snailboy](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@snailboy](https://boards.straightdope.com/u/snailboy)\
**Post date:** [August 18, 2009, 11:01am UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/71 "2009-08-18T11:01:49Z")

</div>

[Polish notation](http://en.wikipedia.org/wiki/Polish_notation). Apparently it has survived in some programming languages. Would you want a calculator that uses it though?

---

<div class="post-metadata">

**Author:** ![yoyodyne](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yoyodyne](https://boards.straightdope.com/u/yoyodyne)\
**Post date:** [August 18, 2009, 3:25pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/72 "2009-08-18T15:25:46Z")

</div>

> [@Johnny\_L.A](#):
>
> See this is where I feel I’m missing something. I’ve done some exercises in the manual, and I’m like, ‘All I’m doing is working out from the parentheses.’ It feels there should be more than that.

Once you get used to it it’s noticeably faster and more efficient. You won’t see that by following contrived examples, or by doing simple calculations, but if you need to routinely solve long/complicated equations you will learn to love it.

---

<div class="post-metadata">

**Author:** ![Johnny\_L.A](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/johnny_l.a/32/1084_2.png) [@Johnny\_L.A](https://boards.straightdope.com/u/Johnny_L.A)\
**Post date:** [August 18, 2009, 3:32pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/73 "2009-08-18T15:32:12Z")

</div>

What I meant was that (following the ‘contrived examples’) it just seemed too easy. It seems it should be harder.

I don’t need to routinely solve complicated equations, as at work I use an ancient sequential language and parentheses are used. Learning RPN is just for my Inner Geek.

---

<div class="post-metadata">

**Author:** ![yoyodyne](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yoyodyne](https://boards.straightdope.com/u/yoyodyne)\
**Post date:** [August 18, 2009, 3:56pm UTC](https://boards.straightdope.com/t/reverse-polish-notation/504991/74 "2009-08-18T15:56:20Z")

</div>

It’s not hard, just different. And it takes a little work to understand how to use it.

If you hand an RPN calc to an average person they’re like “OMG! I can’t do 2+2!” therefore it must be really weird and hard to use.

[Previous page](https://boards.straightdope.com/t/reverse-polish-notation/504991.md?page=3)
