Reverse Polish Activity

Infix to Reverse Polish

Tool to convert a standard mathematical expression (infix) to RPN (postfix)

Infix:

Postfix:

Reverse Polish Stack


















Add data to the stack by entering a value and then selecting "Push".

Remove data from the stack by entering a value and then selecting "Pop".

Perform an operation on the top two values in the stack by selecting an operation. The values are removed from the stack and then the result is placed at the top of the stack.



Reverse Polish Calcuations

Reverse Polish Notation

Infix notation is the standard way of expressing a calculation. It uses brackets and BIDMAS to define the order that each part of the expression is calculated.

RPN does not need to use brackets or define the presidence that different operations take. The position of the operators in a RPN expression define the presidence with which they are performed

Use of a Stack

A Reverse Polish calculator uses a stack.

  • Numerical values are pushed onto the top of the stack
  • When an operation is specific, the top two values on the stack are popped off
  • The operation is performed between these two values and the result is pusshed onto the top of the stack
Example

Infix Expression: (1 + 2 × 3) × (4 + 5)

Steps used to convert an infix expression into an expression using Reverse Polish Notation

ActionStackExpression
Push 1 onto the stack11
Push 2 onto the stack1 21 2
Push 3 onto the stack1 2 31 2 3
Use the × operator to multiply 2 by 3 and give the result 611 2 3 ×
Push 6 onto the stack1 51 2 3 ×
Use the +; operator to add 1 to 6 and give the result 771 2 3 × +
Push 7 onto the stack71 2 3 × +
Push 4 onto the stack7 41 2 3 × + 4
Push 5 onto the stack7 4 41 2 3 × + 4 5
Use the + operator to add 4 to 5 and give the result 971 2 3 × + 4 5 +
Use the × operator to multiply 7 by 9 and give the result 631 2 3 × + 4 5 + ×

Reverse Polish expression: 1 2 3 × + 4 5 + ×