Reverse Polish notation (RPN) is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position. It is also known as Postfix notation and is parenthesisfree as long as operator arities are fixed. The description "Polish" refers to the nationality of logician Jan ukasiewicz, who invented (prefix) Polish notation in the 1920s.
The Reverse Polish scheme was proposed in 1954 by Burks, Warren, and Wright^{[1]} and was independently reinvented by F. L. Bauer and E. W. Dijkstra in the early 1960s to reduce computer memory access and utilize the stack to evaluate expressions. The algorithms and notation for this scheme were extended by Australian philosopher and computer scientist Charles Hamblin in the mid1950s.^{[2]}^{[3]}
During the 1970s and 1980s, RPN was even known to the general public, as it was widely used in handheld calculators of the time for example, the HP10C series and Sinclair Scientific calculators.
In computer science, postfix notation is often used in stackbased and concatenative programming languages. It is also common in dataflow and pipelinebased systems, including Unix pipelines.
Most of what follows is about binary operators. A unary operator for which the Reverse Polish notation is the general convention is the factorial.
Explanation
In Reverse Polish notation the operators follow their operands; for instance, to add 3 and 4, one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediately after its second operand; so the expression written "3 4 + 5" in conventional infix notation would be written "3 4 5 +" in RPN: first subtract 4 from 3, then add 5 to that. An advantage of RPN is that it obviates the need for parentheses that are required by infix. While "3 4 * 5" can also be written "3 (4 * 5)", that means something quite different from "(3 4) * 5". In postfix, the former could be written "3 4 5 * ", which unambiguously means "3 (4 5 *) " which reduces to "3 20 "; the latter could be written "3 4  5 *" (or 5 3 4  *, if you wish to keep similar formatting), which unambiguously means "(3 4 ) 5 *".
Despite the name, reverse Polish notation is not exactly the reverse of Polish notation, for the operands of noncommutative operations are still written in the conventional order (e.g. "/ 6 3" in Polish notation and "6 3 /" in reverse Polish both evaluating to 2, whereas "3 6 /" in reverse Polish notation would evaluate to ).
Practical implications
 Calculations occur as soon as an operator is specified. Thus, expressions are not entered wholesale from right to left but calculated one piece at a time, most efficiently from the center outwards.
 The automatic stack permits the automatic storage of intermediate results for use later: this key feature is what permits RPN calculators to easily evaluate expressions of arbitrary complexity: they do not have limits on the complexity of expression they can evaluate.
 Brackets and parentheses are unnecessary: the user simply performs calculations in the order that is required, letting the automatic stack store intermediate results on the fly for later use. Likewise, there is no requirement for the precedence rules required in infix notation.
 In RPN calculators, no equals key is required to force computation to occur.
 RPN calculators do, however, require an enter key to separate two adjacent numeric operands.
 Users must know the size of the stack, because practical implementations of RPN use different sizes for the stack. For example, the algebraic expression 11.001^{(6.2  2^{3 \pi})}, if performed with a stack size of 4 and executed from left to right, would exhaust the stack. The answer might be given as an erroneous imaginary number instead of approximately 0.5 as a real number.
 When writing RPN on paper (something that some users of RPN may not do) adjacent numbers need a separator between them. Using a space requires clear handwriting to prevent confusion. For example, could look like while something like is straightforward.
Converting from infix notation
Edsger Dijkstra invented the Shuntingyard algorithm to convert infix expressions to postfix (RPN), so named because its operation resembles that of a railroad shunting yard.
There are other ways of producing postfix expressions from infix notation. Most operatorprecedence parsers can be modified to produce postfix expressions; in particular, once an abstract syntax tree has been constructed, the corresponding postfix expression is given by a simple postorder traversal of that tree.
Implementations
History of implementations
The first computers to implement architectures enabling RPN were the English Electric Company's KDF9 machine, which was announced in 1960 and delivered (i.e. made available commercially) in 1963, and the American Burroughs B5000, announced in 1961 and also delivered in 1963. One of the designers of the B5000, Robert S. Barton, later wrote that he developed RPN independently of Hamblin sometime in 1958 while reading a textbook by Kopi on symbolic logic^{[4]}^{[5]} and before he was aware of Hamblin's work.
HewlettPackard
Friden introduced RPN to the desktop calculator market with the EC130 in June 1963. HewlettPackard engineers designed the 9100A Desktop Calculator in 1968 with RPN. This calculator popularized RPN among the scientific and engineering communities, even though early advertisements for the 9100A failed to mention RPN. The HP35, the world's first handheld scientific calculator, used RPN in 1972. HP used RPN on every handheld calculator it sold, whether scientific, financial, or programmable, until it introduced the HP10 adding machine calculator in 1977. By this time HP was the leading manufacturer of calculators for professionals, including engineers and accountants.
HP introduced an LCDbased line of calculators in the early 1980s that used RPN, such as the HP10C, HP11C, HP15C, HP16C, and the famous financial calculator, the HP12C. When HewlettPackard introduced a later business calculator, the HP19B, without RPN, feedback from financiers and others used to the 12C compelled them to release the HP19BII, which gave users the option of using algebraic notation or RPN. From 1990 to 2003 HP manufactured the HP48 series of graphing RPN calculators and in 2006 introduced the HP50g with a 131x80 LCD and a 75 MHz ARM CPU that emulates the Saturn CPU of the HP48 series.
As of 2011, HewlettPackard is producing the calculator models 12C, 12C Platinum, 17BII, 20B (financial), 30B (business), 33S, 35S, 48GII and 50G (scientific) which support RPN notation.^{[6]}
Soviet Union
Soviet programmable calculators (MK52, MK61, B334 and earlier B321^{[7]} models) used RPN for both automatic mode and programming. Modern Russian calculators MK161^{[8]} and MK152,^{[9]} designed and manufactured in Novosibirsk since 2007 and offered by Semico, are backward compatible with them. Their extended architecture is also based on Reverse Polish notation.
Current implementations
Existing implementations using Reverse Polish notation include:
See also
References
External links
ca:Notaci polonesa inversa cs:Postfixov notace da:Omvendt polsk notation de:Umgekehrte Polnische Notation es:Notaci n polaca inversa eo:Inversa pola notacio eu:Alderantzizko poloniar notazio fr:Notation polonaise inverse ko: hr:Obrnuta poljska notacija it:Notazione polacca inversa hu:Ford tott lengyel jel l s ja: no:Omvendt polsk notasjon pl:Odwrotna notacja polska pt:Nota o polonesa inversa ru: simple:Postfix notation sl:Obrnjeni poljski zapis sr: sh:Obrnuta poljska notacija fi:K nteinen puolalainen notaatio sv:Omv nd polsk notation uk: zh:
