Reverse Polish Notation

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.

I love my Mac! :stuck_out_tongue:

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.

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

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.

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.

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.

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

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
;

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.

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.”

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.

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?

Polish notation. Apparently it has survived in some programming languages. Would you want a calculator that uses it though?

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.

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.

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.