Reverse Polish notation (RPN) is a method for representing expressions in which the operator symbol is placed after the operands being operated on. An expression written this way is a reverse Polish expression. It differs from Polish notation, also called prefix notation, in which each operator precedes its operands. Polish notation was introduced by the Polish logician Jan Łukasiewicz (Simons 2021). Charles L. Hamblin developed the use of reverse Polish notation in computer instruction languages in the late 1950s (Hamblin 1962).
For example, the following RPN expression will produce the sum of 2 and 3, namely 5: 2 3 +.
Reverse Polish notation, also known as postfix notation, contrasts with infix notation of standard arithmetic expressions in which the operator symbol appears between the operands.
When each operator has a fixed, known number of operands, RPN has the property that parentheses are not required
to represent the order of evaluation or grouping of the terms. RPN
expressions are simply evaluated from left to right and this greatly simplifies
the computation of the expression within computer programs. As an example, the arithmetic expression can be expressed in RPN as
.
In practice RPN can be conveniently evaluated using a stack structure. Reading the expression from left to right, the following operations are performed:
1. If a value appears next in the expression, push this value on to the stack.
2. If an operator appears next, pop as many items from the top of the stack as it has operands, preserving their order, and push the result of the operation on to the stack.
An arithmetic expression written in infix notation can be converted to an RPN expression using a parsing algorithm, such as a recursive descent parser.
RPN is used in Hewlett Packard and some Texas Instruments calculators and internally in some computer languages.