RPN

It must be 35 years or more since I first heard on Reverse Polish Notation. It is one of those ideas that seems to have been around forever, but has never quite become mainstream. And, for me, it has always been intriguing. I suppose my interest comes from always enjoying mathematics (well, arithmetic really) and having a liking for more efficient ways to do things. That is what RPN really is: a more efficient way to do sums …

Anyone with the most basic education can do sums. For example, I am sure that there is nobody reading this who cannot perform this calculation (maybe with the aid of a calculator): 4 x 5 + 2 x 6 and arrive at the right answer (which is 32 by the way). To do this calculation, apart from knowing how to multiply and perform addition, you need to know that multiplication takes precedence over addition. In other words, we could re-write the sum like this: (4 x 5) + (2 x 6).

To perform the calculation using a pocket calculator is surprisingly complex. The result of the first multiplication must be saved (in the memory) until the second one is ready. You would need to key in something like 4 x 5 = STORE 2 x 6 = + RECALL = which is not totally intuitive in my view. Some calculators “know” about the operator precedence and others have parentheses keys, which enable much more intuitive use, but it can still be hard to follow a more complex calculation.

Enter RPN. This alternative way to do sums, which is available on quite a few calculators, does away with the need for memories, parentheses and operator precedence at a stroke. The idea is that you enter some data (a number) and it gets put on a stack. The next number is put on the stack on top of the first. Operators, like multiply, simply use the top two items on the stack and place the result back on the stack and on the display. So, to do this sum using an RPN calculator, you would key in: 4 ENTER 5 ENTER x 2 ENTER 6 ENTER x +.

Many calculators make it even simpler by eliminating some use of the ENTER key before an operator, but even in this example there are less keystrokes that a normal calculator. Once upon a time, to try out RPN, you would need to buy an expensive pocket calculator from HP. Now there are many cheap or free programs for PCs, smartphones or iPad that give you the chance to experiment with the technique. Give it a try. You might just get hooked and never be able to go back to a conventional calculator again.

Comments

0 thoughts about “RPN
  • I loved the HP28S back in the late 80s and still prefer RPN to infix.

    Droid48 is a great simulator of the HP48 for Android. You will definitely want to download the pdf manual since every key has multiple functions.

  • I studied with the HP48G and can confirm that is a great tool and RPN is an efficient way to work…
    I also downloaded the Droid48 which is a nice replica of my HP48 🙂

Leave a Reply

This article first appeared on the Siemens Digital Industries Software blog at https://blogs.sw.siemens.com/embedded-software/2010/08/26/rpn/