Meta Calculator > Learning Labs > How to Build Scientific Calculator > Reverse Polish Notation
Meta Calculator

What is Reverse Polish Notation ?

Reverse polish notation (rpn), sometimes referred to as postfix notation, is a way of writing mathematical expressions where each operand is preceded by the two operators it applies to and looks something like 2 5 3 + * instead of (5 + 3 ) * 2
What does this have to do with scientific calculators ?
Well, it turns out that it is easier/more efficient for computers to parse an RPN expression than an infix one. In fact, if you look at the code underlying most calculators you'd find that most of them take the infix expressions that we write and first convert them to postfix before evaluating them. Meta calculator's graphing and scientific calculators both do exactly this. If you'd like some insight into how a calculator typically would evaluate a reverse polish notation expression, try our interactive rpn calculator .

What are some examples of RPN?

Below are some examples of rpn right next to their 'normal' ie 'infix' notation.
Infix Version RPN Version
3 - 2 3 2 -
3 * 2+5 5 3 2 * +
(12 - 3 ) /3 12 3 - 3 /
As the last example illustrates, RPN or postfix notation removes the need for parentheses! To give any operation greater precedence in RPN, just place the associated operand (- in our example) immediately to the right of the two operators (12 and 3)!

You can practice converting infix to rpn (postfix) all you want with our infix to postfix convertor.

Practice Evaluating Postfix Expressions

Postfix Value
3 11 + qmark 3 11 +
3 + 11
= 14
3 11 5 + - qmark 11 5 + -
3 11 5 + -
3 16 -
3 16 -
-13
3 11 + 5 - qmark 3 11 + 5 -
14 5 -
9
2 3 11 + 5 -* qmark 2 3 11 + 5 -*
2 14 5 - *
2 14 5 - *
2 9 *
18
9 5 3 + 2 4 ^ - + qmark 9 5 3 + 2 4 ^ - +
9 8 2 4 ^ - +
9 8 2 4 ^ - +
9 8 16 - +
9 -8 +
= 1

Practice Converting from Infix to Postfix

Ok, now that you've seen some examples, try these practice problems out!
Infix Version RPN Version Value
5 + 2 ^3 qmark 5 2 3 ^ +
5 8 +
= 13
13
3 * 2 -11 qmark 3 2 * 11 -
Evaluated as:
6 11 - = 5
-5
2 + 1 - 12 /3 qmark 2 1 12 3 / - +
Evaluated as:
2 1 4 - +
2 -3 +
= -1
-1
( 6 - 3) ^2 - 11 qmark 6 3 - 2 ^ 11 -
Evaluated as:
3 2 ^ 11 -
9 11 - = - 2
-2
6 - 3 ^2 - 11 qmark 6 3 2 ^ - 11 -
Evaluated as:
6 9 - 11 -
-2 11 -
= -14
-14
162 / (2 + 1 ) ^4 qmark 162 2 1 + 4 ^ /
Evaluated as:
162 3 4 ^ /
162 81 /
= 2
2