RPN is not as unnatural as you may think. In fact, you have probably been using RPN for a Very long time. How's that, you ask? Let me show you:
Lets start out with a simple RPN problem:
3 4 +
Now, add a line to the end:
|
3 4 +|
And then move the + a bit:
+|
3 4 |
Finally, flip this puppy on its side*:
3
4 +
---
So, are you groking this now? The only thing
I changed was the appearance of the problem,
not the logic. Does it hold up with more complex problems? lets find out:
3 4 / 12 * 6 -
First, we have to add variables as place holders for results of operations:
3 4 / X 12 * Y 6 - Z
Then add the lines again, wherever there is an operator:
| | |
3 4|X 12|Y 6|Z
Next, distribute the Operators:
/| *| -|
3 4|X 12|Y 6|Z
And, finally, Flip it:
3
4/
--
X
12*
--
Y
6-
--
Z
However, things get a little
hairy when you write
RPN like this:
6 12 4 3 / * -
This is,
in fact, the
same as the problem
above.
You use a similar
process to make
sense of it. However, you must
reverse the number line first.
3 4 12 6
| | |
3 4|X 12|Y 6|Z
/| *| -|
3 4|x 12|y 6|Z
3
4/
--
X
12*
--
Y
6-
--
Z
*:OK, so most people would put the + on the left. Sue me.