~ Office Supplies ~~ Buy Posters ~~ A-Z Products ~~ Website Advertising


Reverse Polish Notation - Wikipedia

<<Up     Contents

Reverse Polish Notation

Reverse Polish Notation (RPN, or postfix notation) is an arithmetic formula notation, introduced in 1920 by the Polish mathematician Jan Łukasiewicz[?]. In this notation, the operands precede the operator, thus dispensing with the need for parentheses. For example, the expression 3 * ( 4 + 7) would be written as 3 4 7 + *.

Implementations that use RPN are stack-based; that is, operands are popped from a stack, and calculation results are pushed back onto it. Although this concept may seem obscure at first, RPN has the advantage of being extremely easy for a computer to analyze due to it being a regular grammar. RPN has been used in Hewlett-Packard calculators as well as in some programming languages such as Forth and PostScript. Most Unix systems also comes with a calculator program that uses RPN: dc.

Practical implications

From the practical point of view, in RPN:

Example

For instance, the calculation: ((1 + 2) * 4) + 3 can be written down like this in RPN:
 1 2 + 4 * 3 +
The expression is evaluated in the following way (the Stack is displayed after Operation has taken place):
Input Stack Operation
1 1 Push operand
2 1, 2 Push operand
+ 3 Addition
4 3, 4 Push operand
* 12 Multiplication
3 12, 3 Push operand
+ 15 Addition
The final result, 15, lies on the top of the stack in the end of the calculation.

Examples of RPN Use

Compare to Polish notation.

wikipedia.org dumped 2003-03-17 with terodump




 
 
WHITE Clear Quartz jewel Loose natural faceted cut polished jewelry gemstone 7x5 mm ov rutile single
 WHITE Clear Quartz jewel Loose ed cut polished jewelry 7x5 mm ov rutile single 
 
100 carats Green PERIDOTS gem stones included rough tumbled polished jewelry gemstones lot 20 grams
 100 carats Green PERIDOTS included tumbled polished jewelry lot 20 grams 
 
6 carat Golden canary yellow SCAPOLITE gem stone Facet rough gemstone Faceting gems jewel crystal 3
 6 carat Golden canary yellow SCAPOLITE ing jewel crystal 3 
 
25 carats Green PERIDOTS gem stones rough tumbled polished designer jewelry gemstones 5 grams PRETTY
 25 carats Green PERIDOTS tumbled polished designer jewelry 5 grams PRETTY 
 
39 gram turquoise green blue CHRYSOCOLLA gem stone Cab cabbing rough tumbled gemstone 196 carat ct
 39 gram turquoise green blue CHRYSOCOLLA Cab cabbing tumbled 196 carat ct