Next: Storing Objects Up: How to Use the Previous: The Key Board

# Reverse Polish Notation

Many people are confused when they first use hand held calculators made by Hewlett-Packard. This confusion arises because of the Reverse Polish Notation (RPN) which these calculators use. As a matter of fact, at one time I thought that algebraic notation would be easier to use. However, once you realize that RPN is exactly what is used when calculations are done with paper and pencil, the syntax is much clearer. For example, to add the numbers 21 and 37 together, using paper and pencil, we write

Well that's exactly what is entered in the HP48G/GX. 21 37

To compute , compute x+y first, and then the sine of their sum. To further demonstrate that the way numbers and functional evaluations are entered into the HP48G/GX mimics what is done with pencil and paper, let's compute . To solve this on the HP48G/GX enter: 2

This puts the number 20 on stack level 1. Be sure to always use the symbol * for multiplication. To enter * push . The HP48G/GX does not recognize implied multiplication. To appreciate the correlation between RPN and hand calculations, compute by hand the above expression. To compute the natural log of this number, push the keys: 2pt .

If a calculator, with algebraic notation, is used, the following keystrokes are entered:

At first sight both methods seem reasonable. However, for more complicated expressions we are soon lost in a sea of parentheses. Moreover, algebraic notation requires that we understand the syntax of the entire expression, while RPN only requires an understanding of the small pieces from which our expression is built.

Negative numbers are entered with the aid of the key. For example, to calculate, , place the numbers -3 and -5 on the stack with the following keystrokes:

Now press . It is worth pointing out that the HP48G/GX does allow for algebraic notation. If a formula like needs to be placed on the stack, enter tick marks first, and then place the expression between the tick marks. For example:

Notice that the HP48G/GX places both tick marks in the command line with the cursor positioned between them. Missing closing delimiters are no longer a problem. An alternate way to place this expression on the stack is:

To compute using algebraic notation, use tick marks as above and enter the given expression. Now push enter. You should have on the command line. Push .

Another aspect of the HP48G/GX calculator that merits discussion is the stack. Since all input, and the results of every computation appear on the stack, any output from an intermediate calculation can be used as the input of another calculation. I may be stretching the point a bit, but this feature alone is worth the price of admission. For example, suppose we wanted to compute , where 1.5 is radians, not degrees.

Notice we now have on stack level 2 and on stack level 1. The ENTER key stroke immediately following the second 1.5 pushes the object on level 1 up to level 2 and then places 1.5 on level 1. The next command computes the cosine of 1.5 and places that value on level 1. Be sure that your calculator is set to radian mode. To finish the computations: 2pt

The number 7.89322756581 should now appear in level one. Note: we did not have to place the number 2 on the stack in order to exponentiate it.

A second way to compute the above is as follows:
2pt

The point of the second example is to note that hitting the key with the command line empty moves all stack objects up one level, and leaves a copy of the object in level one in level one.

The key moves the stack objects down one level, and deletes the object on level one. The key clears the entire stack.

Some items worth remembering:

• Reverse Polish Notation mimics hand calculations.
• Every result can be used as the input of another computation.
• Algebraic notation is used between tick marks.

%

Next: Storing Objects Up: How to Use the Previous: The Key Board

Mike Stecher
Thu Mar 21 09:53:31 CST 1996