Archive

Tags

**iCalcula: Reverse Polish Notation**

*November 6, 2017*

iCALCULA is based on Reverse Polish Notation (RPN) and the use of a four registers stack. Automatic storage of intermediate results is the reason that a RPN calculator easily processes complex calculations without the need of using parenthesis. The key to automatic storage is the RPN memory stack.

RPN works with unary (√, sin(), ... )and binary operators (+, ÷, ...). Algebraic notation places operators between operands. An addition of two numbers can be expressed:

2 + 3 = 5

Then, in an algebraic calculator you type:

|2| |+| |3| |=|

RPN notation places operators after the numbers or variables they operate:

2 3 +

So, in a RPN calculator like iCALCULA you type:

|2| |ENTER| |3| |+|

One of the most visible difference between both notations is that RPN doesn't use parenthesis or |=| key at all. This can be an advantage in more complex calculations:

ALG: |(| |2| |+| |3| |)| |/| |√| |(| |5| |-| |4| |)| |=|

RPN: |2| |ENTER| |3| |+| |5| |ENTER| |4| |-| |√| |÷|

The contents of the stack move up and down automatically as new numbers enter the x-register (lifting the stack) and as operators combine two numbers in the x and y-register to produce one new number in the x-register (dropping the stack).

Suppose the stack is filled with the numbers 2,5,6 and 4. See how the stacks drops and lifts its contents while calculating 6-4+8:

t 2 2 2 2

z 5 2 5 2

y 6 5 2 5

x 4 |-| 2 |8| 8 |+| 10

1 2 3

1. The stack drops its content. The t-register replicates its content.

2. The stack lifts its content. The t-register's content is lost.

3. The stack drops

Most functions and operators prepare the stack to lift its content when the next number enters the x-register. But there are some exceptions, for example |ENTER|.

THE |ENTER| KEY

|ENTER| key separates two numbers keyed in one after the other. It lifts the stack and replicates x-register. It also prepares the stack so that x-register will be overwritten with next input. Suppose the stack is again filled with 2,5,6 and 4. Now enter and add two new numbers:

t 2 5 6 6 6

z 5 6 4 4 6

y 6 4 5 5 4

x 4 |5| 5 |ENTER| 5 |6| 6 |+| 11

1 2 3 4

1. Lifts the stack

2. Lifts the stack and replicates the x-register

3. Does not lift the stack

4. Drops the stack and replicates the t-register

The replicating feature of |ENTER| can be interesting if you want to enter a number and apply an operator to itself.

|3| |ENTER| |×|

gives you the square of 3.

The replicating effect of |ENTER| together with the replicating effect of stack drop (from t into z-register) allows you to fill the stack with a numeric constant for calculations.

|3| |ENTER| |ENTER| |ENTER| |×| |×| |×| |×| ...

gives you successive powers of 3.

THE |LAST x| REGISTER

The |Last x| register is a companion to the stack: it holds the number that was in the x-register before the last operation was executed. This ability to retrieve the "last x" has two main uses: correcting errors and reusing a number in a calculation.

Recent Posts

*December 3, 2017*

*November 28, 2017*

*November 25, 2017*