The basis of RPN - Chapter 2

the Stack

The stack is very important when you work in RPN,
That's the place where is stored objects which are :
- computed
- typed by you.

If you compute 2 enter 3 +, you will have 5 in stack, exactly as you were typed 5 enter. you can now use this 5 for further computation...
Do you want to compute a sine for this 5 ? just use the sin function.

You have to understand the powerfull the stack provide to you.
You can store all your results in your stack, if you need one of them, you don't need to type it again, you just have to PICK it from the stack.
(we will see later the function PICK).
Please note that virtualy there are no limit to the stack depth. (the memory of you PC maybe :) )

How to works with negative value ?

You may expect to enter number -2 by typing - 2 ?
It cannot be filled like this, because when you will hit -, any RPN calculator will try to compute a substraction between two numbers.
depending on which RPN calculator you are working, you have functions such as NEG, +/ - or CHS (change sign).
In MiniRPN and in RPN-Enh, you have NEG (hit the N key of your keyboard).

It works like this : 2 NEG, on your keyboard, press the key "2", and press the key "N".
you don't need to press enter, because NEG to it himself.

Negative values with matrix : See important note about RPN-Enh

What kind of Object a RPN calculator usualy handle ?

in MiniRPN it just handle numeric values.
a lot of RPN calculator can handle serveral kind of objects, RPN-Enh can handle Lists, complex number, matrix, strings...
Other well known hp calculator can handler more complex objects like librairies, Programs... hp48 is wonderfull. (hp, hp48 are trademarks of hewlett packard company)

Each of these object use only one position into the stack.
a matrix is ONE object. like a number or else, there are no differences
You can treat any object type exactly as they were number : this is important, it open a lot of possibilities, you can compute a DET of a matrix, for example.
That mean you can make operation with these, exactly as they were numbers. If you have a matrix on the stack, you can multiply it by 2 simply like this : 2 *.


DUP2 function is an important stack manipulation function.
It dupplicate the two last item of the stack.
Before :
After :
You see, the two items (147 and 6) have been dupplicated, you can now use the two last one and keep the one from 3: and 4: for later use.
DUP2 can be quickly found on MiniRPN and RPN-Enh by hitting the "D" key of your keyboard.


Please follow this example :
We have a box, the width is 14.51 cm and the lenght is 9.72 cm,
we would like to compute the area and the perimeter for this box.
How can we take profit of the powerfull of the stack to works efficiently with a RPN calulator ?

answer :
enter 14.51, and 9.72, use DUP2, press *, you got area (141.0372 cm²),
you can now use DROP or AROT,
you have 14.51 and 9.72 on top of stack, now press +, enter 2 and press *, you have here the perimeter : 48.46 cm

Note : what is AROT ?
AROT is the function that move the Top Of Stack item to the 3rd line, in this example it have moved 141.0372 to the 3rd line.
If you use DROP, it just remove the area value.
If you use AROT, you have on the stack the both results : area and perimeter, isn't efficient ?

See enxt chapter : The Stack Operations