Reverse Polish Notation

RPN has been far my favorite notation since the late 70s when I got my first HP. I had an SR-50 before that, but the logic that is happening in an “algebraic” calculator is really complicated compared to what happens in an RPN calculator.

Which isn’t trivial, by the way. If the stack is full of zeros and you type “6 Enter +” what will you get? Most HP calculators use a semihidden feature called a “stack lift flag” that controls whether the “X” register will push its result into “Y” when something else tries to go into X, and they will give you 12 as a result, because the Enter duplicates X into Y and the + eats them both and sums them and writes the result into X. But the more Forth-like 28S (the most wonderful calculator ever devised IMHO) would give you 6 because Enter only terminates digit entry (if I am remembering this right). Forth, of course, doesn’t use Enter, it only requires numbers be separated by whitespace, which causes them to be separate tokens. And the 28S would behave the same way if you typed the Space key between numbers. Fans will remember it also had DUP, SWAP, DROP and other Forth names for what other HPs called Enter (sort of) and X<>Y and ClrX.

And Forth seemed like the cleverest thing I had ever been able to follow, 20 years ago, and still hasn’t really been replaced (though OOP certainly has a unique zing all its own).

Lots of systems use stacks. I think probably a fair number of “algebraic” calculators have been implemented internally as RPN or other stack systems, though some like the SR-50 had separate registers for addition/subtraction, multiplication/division, exponentiation, and monadic operators.

Usually you use one stack, at least consciously. In RPN there is a number stack that you think of as THE stack. In Forth there is a number stack and a return stack. The number stack is practically the same as in RPN. The return stack has processor addresses on it. You enter a subroutine by putting the address where you left off onto the return stack, then going off elsewhere to run the subroutine, then pulling the address off the return stack and resuming execution there. After a little thought you won’t be surprised to learn this is a very common way of managing subroutines. In Forth there’s an outer interpreter and an inner interpreter that parse the tokens in each word definition in the dictionary, and you reach Forth Nirvana when you learn that the inner interpreter is actually just a “return” instruction in Assembly. Just to keep things lively, Forth provides functions that move a value from the return stack to the number stack, and vice versa, and you use these to move things out of your way for a moment. When the square root of your velocity can become an interrupt handling vector, you can get things mighty crashed mighty fast, which gave Forth a scary reputation, but as C. H. Ting once said, it’s the user’s computer, if he wants to crash it, he should be able to. Ting once entertained a concert hall full of people by wiring resistors sized in factor-of-two succession to the pins of a parallel port of an IBM PC, and programming it to play Bach like a synthesizer. In Forth, of course.

And loads of programming is done with stacks, though programmers are often not conscious of it. You know you can manipulate values with a computer without giving them names. Of course, you can name a value, but you can also for example pass it as an argument into a function, or have it implicitly in there as an intermediate result. A simple view is that things that are named get put in the “heap”, which associates information with names, and things that are not named are often sitting in a stack. Of which, by the way, there are often many. I don’t mean locations in the stack, “registers” as HP called them. I mean stacks that are separate and isolated and don’t know about each other.

It’s all wonderful. God knows how many of us first got thinking about stacks and about how to organize stuff so you can use it, just by reading HP manuals with the little Charlie Chaplin figure rolling things into and out of the stack with his cane…

Starting from an empty stack:

“0 Enter 6 Enter +” gives you 6.

“6 Enter +” gives you a “+ Error: Too Few Arguments” message.

Well, of course. That’s why I started with a stack full of zeros.

You might have heard of these, but there are newer languages like Joy, Factor, and Cat (and others), which are stack-based, RPN languages in the spirit of Forth. And then of course there’s Postscript, a personal favorite — the page description language that many printers use.

For anyone still curious, there’s a decent Wikipedia page on the subject here.

In my HP15C, both give you 12. The enter doesn’t move what’s in the lowest register to the next one and leave the lowest register empty: it copies over.

So, if you’re a clean person and remember to use your Clear
you start with an empty stack (0 0 0 0)
0 (0 0 0 0) ← ok…
enter (0 0 0 0) <— so far you’ve used 2 keystrokes for a lot of nothing
6 (6 0 0 0) <— we did something now
enter (6 6 0 0) <— copies over

  • (12 0 0 0)

The second version is the same minus the two initial useless keystrokes.

Thanks for clearing my vocabulary issue.

Well, I’m committed.

I had about three quarts of change lying about, and I’ve had my eye on The Complete Calvin And Hobbes boxed set. So I ambled on down to the nearest CoinStar machine hoping I’d have at least $100 so I could buy it. Turns out that three quarts of change was enough for The Complete Calvin And Hobbes, The Complete Far Side 1980-1994 boxed set, and…

An HP 35s calculator with RPN.

Plus tax.

Now what do I spend the other $75 on? :smiley:

Anyway, as I said, I’m now committed to learning RPN even though I have no use for it.

Aw shoot, I thought this was going to be a humorous thread about some kind of slangy doublespeak along the lines of Pig Latin. :smack:

Hookers n’ blow. (although 75 wont get you very far in either dept.)

“In Joy, the meaning function is a homomorphism from the syntactic monoid onto the semantic monoid. That is, the syntactic relation of concatenation of symbols maps directly onto the semantic relation of composition of functions.”

  • from the Wikipedia article on the Joy programming language

Wow. Jesus. Wow. OK, now I think this might be the cleverest thing I will have been unable to follow. Or not. Turns out, you can’t identify that. So, ordering in Joy is like nesting functions in most languages (though not languages like Scheme that implement pure functions)?

Although I’ve never programmed in joy, it looks like that is the case, also that you cant redefine symbols? That sounds like a headache that only a professor of programming methodologies would ever inflict on anyone.

In searching for an RPN calculator, I’ve noticed that lots of people like the HP 11C. What makes it ‘better’ than any of the others? Is it just nostalgia? Or is it the size? (It seems from photos to be smaller than most.) Or does it do something or some things better than newer calculators?

I noticed that the HP-12C financial version is still being made. Wiki says:

Weird.

There were the HP 10, 11, 12, and maybe 15 and 16? -C calculators that were pretty well constructed and had a landscape-orientation that was nice. The display could have large characters and display a long line of them this way. But, the size and layout is very convenient. It fits in a pocket well. Its thickness is small relative to the other dimensions and its feet are close to the corners, so it sits very stably and does not rock or flip over if you push harder or more obliquely on keys near the edge. I have a 15C in front of me now that is the first thing I grab to calculate when I am in my office downstairs at home. I think it’s 21 years old. The key for ln(x) and exp(x) sticks but that’s all I know is wrong with it. It has a large unbroken flat area on the back that has a very useful and detailed label listing various things like the meanings of the statistics registers and 4 conversions between English and SI units.

The 16C, which I never see sitting around anyplace, was pretty neat - it had alternative number bases and logic and a few other things that are computeresque - I think it was targeted as useful to computer science and/or programming. I always wanted one, even though I am not so sure any of those things are useful to a computer programmer, especially if they are in something separate from the computer that doesn’t talk to it.

Overall I think the 10 series is one of the best designed calculators I have used.

In fact I daydream about starting a calculator company that would make something that looked much like the 10 series, but with a very strong titanium case, and lots of time invested in weeding out extra complications that are more burdensome than useful in a calculator. The idea would be that it would be worth learning it completely and even taking a course in it or entering calculating contests with it, so it became that much better integrated as second nature, because nothing would ever replace it. It would last for years and would remain available as the same model even years from now when yours finally broke (I hope only because a truck ran over it, twice).

I had an 11C. It stood up to being wacked with a hoe when it fell out of my pocket as I was weeding potatoes but touching a cooker fried it :frowning: The 10 was basic I think, the 11 scientific, the 15 engineering, the 12 financial and the 16 programming. There don’t seem to have been a 13 and 14. I had a 16 emulator on the computer at one time. Either I’ve lost it or it’s under Windows. Calcoo is a nice precompiled emulator that can be set to do RPN or Algebraic and Stepulator is another.

Sticky keys? You must really like that calculator! :smiley:

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?

As I said, I’ve ordered an HP 35s so I can learn RPN. It’s not landscape, but it seems a reasonable size and has a large display. One reviewer said, ‘A definite improvement on the 32sII’, another OOP HP calculator that seems to have a strong following. I assume it’s faster than an HP 11C, and has more memory. And it has algebraic data entry in case I decide I hate RPN.

Another question: Wiki sez ‘In the HP calculator community, the 42S is infamous for its inflated prices in online auctions.’ Why is demand for the 42s such that prices are ‘infamously inflated’.

I’m getting the sense that long-time HP users are a bunch of curmudgeons! :stuck_out_tongue:

The 11C for me has just been an incredibly durable, reliable RPN scientific calculator. Mine is something like 22 years old, and works as well now as when it was new. The 12C is for business, and the 11C (among scientific calculators) did everything I needed, so I never bought one of the more advanced ones.

I did get a new one. I got a 12C when I got my MBA, for its useful PV, FV, NPV, IRR, etc. functions.

I still use it at home. But the blasted thing doesn’t have SIN, COS, TAN, Log, Ln, square root, etc., which I use all the time as an engineer. So it’s the 11C at work.

And switching calculators once you’ve learned one very well is sorta like switching once you’re good at a QWERTY keyboard.

Let me give the link to CoCalc a free RPN calculator:http://www.cohort.com/CoCalc.html. It can also be downloaded. It appears to have all sorts of features I have not delved into.

That looks pretty sweet. I’ll have to download it onto the ol’ MacBook when I get home.

I got an email from Amazon yesterday saying my HP 35s has been shipped. I should have it in a couple/few days. :slight_smile:

A new what? There aren’t any new 11C’s as far as I know. I have newer HP’s including a 28S and probably 3 of a newer one, 33E or something like that, and a few older including a 41CX (with a PPC rom!) for which I did a bunch of “synthetic programming”.

There are present day HP’s that still have RPN. I’ve contemplated getting a new one of those. They look too big and seem to have too much complicated stuff in them, so I think they miss the mark that is right for a technical calculator.

And I have a few PC software RPN calculator emulators. In fact I even wrote one. These are somewhat useful, but if it’s on a PC, you have to put up with all the baggage of PCs to use it, namely: I’m not going to keep one in my toolbox or this drawer here, it takes minutes to turn on and off, and every few months somebody figures out how to make it stop working unless I give them more money and then fix the things they broke.

Besides, on PCs I already program in C, C#, FlexPDE, Forth, Fortran, LabView, Mathematica, SAS, VisualBasic, and a few other things. The PC is a very complicated place. If I want to do a multiplication and a division, I don’t need authentications and crashes.