Trident Help

RPN Financial 12 manual · Chapter 2 of 16

How RPN and the stack work

What reverse Polish notation is, the four stack registers X, Y, Z and T, ENTER, stack lift, rolling, swapping and LSTx, with step-by-step stack diagrams.

2.1What RPN is and why accountants like it#

In RPN you give the numbers first and the operation last. To add 3 and 4 you do not write 3 + 4. You write 3 4 + , which reads "3 and 4: add them". That is where "reverse Polish" comes from.

3  4  +  ⟶  73\;4\;+\;\longrightarrow\;7
RPN writes the numbers first and the operation last.

This pays off in longer work. You never need brackets, because the order in which you press the operations decides the order of the maths. You never need an equals key, because every operation shows its answer at once. And you can see every in-between answer, so a slip is easy to spot.

Think of a stack of plates. You put numbers on the top of the pile. An operation takes the top plate (or the top two), works on them, and puts the answer back on top.

2.2The four stack registers: X, Y, Z and T#

The stack has four places, called registers. They are named X, Y, Z and T, from the bottom of the pile to the top.

RegisterWhat it isWhere you see it
XThe number you are typing, or the latest answer. It is the one shown in the main display, and the one one-number functions work on.Bottom line
YThe second level. Two-number operations use Y and X.Line above X
ZThe third level.Third line
TThe top level.Top line

A calculation with two numbers always reads "Y operation X". In Y ÷ X, Y is the number being divided and X is the divisor. So 10 ÷ 4 means 10 in Y and 4 in X: key in 10, press ENTER, key in 4, press ÷.

Filling the stack: each ENTER copies X up one level.

In every stack figure the registers are listed X first, then Y, Z and T.

Example 2.1

See all four registers

  1. Key in 1, ENTER, 2, ENTER, 3, ENTER, 4.

    1ENTER2ENTER3ENTER4
Result of the example "See all four registers" The display shows:  1.00 /  2.00 /  3.00 /  4.00 /  4.
You should seeT = 1, Z = 2, Y = 3, X = 4.

2.3What ENTER does#

ENTER has one job: it separates two numbers. It copies the number in X up into Y (and moves what was in Y up to Z, and so on), and leaves X holding the same number. The next number you type then replaces that copy in X, so nothing is wasted.

That is why 3 ENTER 4 + works. After 3 ENTER, X and Y both hold 3. When you type 4, it replaces the copy in X. The stack now has 3 in Y and 4 in X, and + adds them.

Example 2.2

3 ENTER 4 +

  1. Key in 3, ENTER, 4, then +.

    3ENTER4+
Result of the example "3 ENTER 4 +" The display shows:  0.00 /  0.00 /  0.00 /  7.00.
You should see7.00

You do not press ENTER after the last number, and you do not press it before an operation key. If you press an operation straight after typing a number, the calculator finishes the number for you.

2.4One-number functions and two-number operations#

There are two kinds of key. A one-number function (√x, 1/x, LN, n! and so on) works on X only and replaces X with the answer. Y, Z and T stay put.

A two-number operation (+, −, ×, ÷, yˣ) uses Y and X. The answer goes into X, and the stack drops: Z moves down to Y, and T moves down to Z. T keeps its value, so a copy of it also appears in Z.

X←Y  op  XX \leftarrow Y \;\mathrm{op}\; X
A two-number operation computes Y op X and leaves the result in X.
Example 2.3

Square root leaves the rest alone

  1. Key in 5, ENTER, then 9 and press g, √x.

    5ENTER9g√xyˣ
Result of the example "Square root leaves the rest alone" The display shows:  0.00 /  0.00 /  5.00 /  3.00.
You should seeX shows 3.00 and Y still holds 5.00.
Example 2.4

The stack drops after an operation

  1. Fill the stack with 1, 2, 3 and 4 as before, then press +.

    1ENTER2ENTER3ENTER4+
Result of the example "The stack drops after an operation" The display shows:  1.00 /  1.00 /  2.00 /  7.00.
You should seeX = 7 (3 + 4), Y = 2, Z = 1 and T = 1: the old T value is copied downwards.
A two-number operation drops the stack: Z falls into Y and T is copied down into Z.

2.5Chain calculations without brackets#

To work out (3 + 4) × (5 + 6), do the brackets first, one at a time, and let the answers wait on the stack. First 3 ENTER 4 + gives 7. That 7 stays in X. Key in 5: because 7 was an answer, it moves up to Y by itself. Press ENTER, key in 6, press + to get 11. The 7 is in Y again. Press × to finish.

(3+4)×(5+6)=77(3+4)\times(5+6)=77
The brackets are worked out first and the answers wait on the stack.
Keys for (3 + 4) × (5 + 6).
Example 2.5

(3 + 4) × (5 + 6)

  1. Add 3 and 4.

    3ENTER4+
  2. Add 5 and 6. The 7 moves up by itself.

    5ENTER6+
  3. Multiply the two answers.

    ×
Result of the example "(3 + 4) × (5 + 6)" The display shows:  0.00 /  0.00 /  0.00 /  77.00.
You should see77.00
Example 2.6

(12 + 8) ÷ (2 × 5)

  1. Add 12 and 8.

    12ENTER8+
  2. Multiply 2 and 5.

    2ENTER5×
  3. Divide Y by X.

    ÷
Result of the example "(12 + 8) ÷ (2 × 5)" The display shows:  0.00 /  0.00 /  0.00 /  2.00.
You should see20 ÷ 10 = 2.00.

Work from the inside out: do the innermost brackets first, then the next level. Four stack levels are enough for most expressions of this kind.

2.6When a new number replaces X and when it lifts the stack#

When you key in a new number, the calculator decides: should the new number go on top of what is in X (lifting the stack), or replace X? It follows one rule, called stack lift.

  • After most operations (+, −, ×, ÷, functions, RCL, and results of any kind), stack lift is on. The next number you key in lifts the stack: the old X moves up to Y.
  • After ENTER, stack lift is off. The next number replaces X. This is what makes 3 ENTER 4 work.
  • After CLx (CLx), stack lift is off too. The next number replaces the cleared X.
  • After Σ+ or gΣ−Σ+ (Σ+ or Σ−) stack lift is off. The count n shown in X is replaced by the next data point.
  • STO, the display format keys and the BEG, END, D.MY and M.DY keys do not change the lift state.
Stack lift: after a result the new number lifts the stack. After ENTER it replaces X.
Example 2.7

A result lifts the stack when you type a new number

  1. Add 2 and 3, then key in 4 and multiply.

    2ENTER3+4×
Result of the example "A result lifts the stack when you type a new number" The display shows:  0.00 /  0.00 /  0.00 /  20.00.
You should see5 × 4 = 20.00. The 5 moved up to Y when you typed 4.
Example 2.8

ENTER turns lift off

  1. Key in 7, ENTER, then key in 8. The 8 replaces the copy in X.

    7ENTER8
Result of the example "ENTER turns lift off" The display shows:  0.00 /  0.00 /  7.00 /  8.00 /  8.
You should seeY = 7 and X = 8. There is no extra 7.

2.7Use a number twice: ENTER ENTER#

Pressing ENTER twice puts two copies of X on the stack. That helps when a number appears more than once. 3 ENTER ENTER × squares 3 and leaves a 3 in Y. Press × again and you get 3 × 3 × 3 = 27.

Example 2.9

Cube a number

  1. Key in 3, press ENTER twice, then × twice.

    3ENTERENTER××
Result of the example "Cube a number" The display shows:  0.00 /  0.00 /  0.00 /  27.00.
You should see27.00

You can also use gx²× (x²) to square X, or yˣ for any power.

2.8Roll the stack and swap X and Y#

x⇄y (x⇄y) swaps X and Y. It cures numbers keyed in the wrong order. Keyed as 10 ENTER 4 ÷ you get 2.5. If you wanted 4 ÷ 10, press x⇄y first.

Example 2.10

Swap to divide the other way

  1. Key in 10, ENTER, 4, swap, then divide.

    10ENTER4x⇄y÷
Result of the example "Swap to divide the other way" The display shows:  0.00 /  0.00 /  0.00 /  0.40.
You should see4 ÷ 10 = 0.40.

R↓ (R↓, roll down) moves every number down one level. X goes to the top (T), and Y, Z and T each move down. Nothing is lost, because the numbers go round in a circle. Four presses bring the stack back to where it started. This model has only a roll-down key.

Swap and roll down (starting from X = 4, Y = 3, Z = 2, T = 1).
Example 2.11

Roll down

  1. Fill the stack with 1, 2, 3 and 4, then press R↓.

    1ENTER2ENTER3ENTER4R↓
Result of the example "Roll down" The display shows:  4.00 /  1.00 /  2.00 /  3.00.
You should seeX = 3, Y = 2, Z = 1 and T = 4 (the 4 went round to the top).

2.9Bring back the last number with LSTx#

Every time you press a function or operation, the calculator saves the number that was in X just before. gLSTxENTER (LSTx, "last X") pushes that number back. It is useful to correct a slip, or to use the same number again.

LSTx after 6 ENTER 2 ×: the 2 comes back, so ÷ undoes the multiplication.
Example 2.12

Undo a multiplication with LSTx

  1. Key in 6, ENTER, 2 and press × (you meant to add). Press g, LSTx to bring back the 2, then ÷.

    6ENTER2×gLSTxENTER÷
Result of the example "Undo a multiplication with LSTx" The display shows:  0.00 /  0.00 /  0.00 /  6.00.
You should see12 ÷ 2 returns to 6.00, ready to try again.
Example 2.13

Reuse a number: 5 + 3, then 3 more

  1. Key in 5, ENTER, 3, then +. Press g, LSTx to recall the 3, then + again.

    5ENTER3+gLSTxENTER+
Result of the example "Reuse a number: 5 + 3, then 3 more" The display shows:  0.00 /  0.00 /  0.00 /  11.00.
You should see8 + 3 = 11.00.

2.10Stack habits that save time#

  • Do not press ENTER after the last number or before an operation.
  • Work from the inside out for brackets.
  • If a result seems wrong, press R↓ a few times to look at Y, Z and T. The numbers you need are still there.
  • The stack holds only four numbers. If you have more waiting to be used, store some in registers (see Memory).
  • For a − b, key in a, ENTER, b and press −. For a ÷ b it is the same: a goes in first.

See also How the RPN stack worksEveryday calculations

HP 12C is a trademark of HP Inc.. Trident Calculator is an independent product by South View Studios and is not affiliated with, sponsored by or endorsed by HP. The name is used only to describe the kind of calculator this model resembles; Trident's names, keys, display, fonts and software are its own clean-room design.