Post Reply 
why is RPN always reversed (not PN)
05-25-2015, 11:44 AM
Post: #9
RE: why is RPN always reversed (not PN)
(05-25-2015 06:14 AM)StephenG1CMZ Wrote:  Can anyone explain why RPN is always reversed.

What are the advantages of reversing the sequence?

Another answer is that with a prefix notation it would be very hard to use the result of a previous calculation in a subsequent calculation.

Say you've completed some calculation 1 and the result is on Level 1 of the stack. Now you want to do calculation 2 using the result. You now need to get the operator for calculation 2 into Level 2 of the stack somehow. You can't just enter it and use SWAP because SWAP is now a prefix operator too and you would need to have entered it before you did calculation 1. (Indeed, if you are doing multiple calculations in a row you will need to have the foresight to put as many SWAPs on the stack as you will have operators in your calculations, before you begin.)

You might think of storing the result of calculation 1 in a variable and then recalling it again once you have your operator on the stack. But STO is now a prefix operator so you would need to have entered it before its arguments.

So you delete the result from calculation 1 from the stack, enter your operator for calculation 2 and then retype the result from calculation 1! But even that is problematical since DROP is now a prefix operator and would need to have been on the stack already!

So it seems that using prefix operators with a stack doesn't make sense unless you have a special set of postfix operators for working on the stack itself, like DROP and SWAP. (The subset of operators that had best be postfix will tend towards the entire set and you're back at RPN.) Otherwise you must have inhuman forethought.

Alternatively you're stuck using a lisp-like syntax (as pointed out by Gerald H), which is fine for programming or for interactive use when you can enter complete forms, but not so useful for entry element by element from a calculator keyboard.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: why is RPN always reversed (not PN) - nlj - 05-25-2015 11:44 AM



User(s) browsing this thread: 8 Guest(s)