Tag: Reverse Polish Notation

Reverse Polish Notation Calculator – RPN Vs Algebraic Calculator

Reverse Polish Notation Calculator – RPN Vs Algebraic Calculator

| July 22, 2013 | 1 Comments

Reverse Polish Notation is also known as “postfix notation”. It is named so because in this notation all the operands are placed before the operator. This notation is also of interest because no parenthesis is used in RPN notation. A Polish logician and philosopher Jan Lukasiewicz invented prefix notation in 1920s; that’s why the word “Polish” has been placed in the title of this notation. Burks, Warren and Wright were the people who were involved in introducing Reverse Polish Notation scheme in 1954. There was further development in the algorithms of RPN in the mid of 1950s by Charles Hamblin. RPN scheme was known to many calculator users during 1970s and 1980s. Hewlett Packard used Reverse Polish Notation first time in the scientific calculator named 9100A in 1968.

While using the calculators with algebraic notations, the use of parenthesis is quite a big problem. The parenthesis does not matter a lot in simple calculations but they create much confusion while dealing with complex calculations. The BODMAS rule is applied while dealing with the mathematical calculations using algebraic notation but the BODMAS rule becomes very confusing when there are brackets in the mathematical expression and it becomes even more confusing when there are brackets inside the brackets. This mess can be solved by using calculators using Reverse Polish Notation in which the operators appear in the order which is required for the computation. In the calculators using RPN, complex calculations can be done quite easily by using a minimum number of special symbols.

One simple example can serve this purpose of showing that the calculators using RPN are better than the calculators using algebraic notation. Suppose we want to calculator “4+5×2” in such a way that we want that the operator “+” operates before “×” giving the result equal to “18” neglecting the BODMAS rule. This thing can only be done in the regular calculators using Algebraic notation by using a bracket across “4+5” so that the above expression takes the form as “(4+5)×2”. Now this will give the right answer as we want.

There are many reasons for using a RPN calculator rather than a calculator using algebraic notation. An RPN calculator saves time because the same calculation can be performed in less time as compared to a regular calculator. For example, we want to compute “(13+3)÷(4×2)” using a calculator of algebraic notation (not a scientific one) then we have to do many steps to reach the answer. Firstly, we have to compute “(13+3)” and then we will save the answer to the memory of the calculator. Then we have to compute the calculation in the denominator i.e. “(4×2)” and we have to save this answer too to the memory of the calculator. In the end, we will bring both the answers and will perform the last operation of division. This procedure has taken a reasonable amount of time. This thing can be avoided by using RPN calculator. In RPN calculator, we have to insert just a single line expression as “13 Enter 3 + 4 Enter 2 × ÷” and the answer will be computed instantly.

Reverse Polish Notation has stack which is absent in case of algebraic notation calculators. RPN operates in a way that if an operand appears next in the expression then the operand value is pushed on to the stack and if an operator appears next in the expression then two operand values from the top of the stack are popped and the answer of these values is pushed on to the stack. For example, if the expression “4+6+7” has to be computed then in RPN, it is inserted as “4 Enter 6 Enter 7 + +”. The value “4” is pushed on to the stack followed by the value “6” and then followed by “7” but after appearing the operator “+”, two values from top of the stack i.e. “7” and “6” are popped up and their result i.e. “13” is pushed on to the stack. After appearing the operator “+” in the expression again, two top values from the stack i.e. “13” and “4” are popped up and their result i.e. “17” is pushed to the stack. The other important feature of RPN is that we can go back to any place in the stack by using they key “R↓”.

The other reason of using RPN rather than algebraic notation is that RPN is less complicated. While doing the calculation like “12+8”, the answer of the calculation is not displayed on the screen until we press “=” or any other operator symbol. This thing is very confusing for the users because on pressing “+”, “-“, “×” or “÷” symbol, the respective operation must take place rather than giving the result of the previous calculation. RPN in more intelligent in this case. When “+” key is pressed in case of RPN then addition is performed always; that’s the case with subtraction, multiplication and division.

It is usually thought that algebraic calculations are taught in schools because they are easy to understand. The algebraic calculations are easy to be inserted in the calculator as we have just to read the mathematical expression from left to right and then inserting the expression in the calculator. But this thinking is absolutely wrong because algebraic calculations are easy to be done only in the case when we are inserting the mathematical expression into the calculator by reading from some source. But if we have to deal with the expressions which are made on the spot by mind then RPN is the best method because we don’t have to remember the calculation results in the intermediate steps to move ahead as in the case of algebraic calculations.

This thing can easily be done using RPN. In all the calculators using RPN, there is a key named “Enter”. This key is pressed every time when an operand is inserted in the expression to separate one operand from the other. While solving the mathematical expression “(4+5)×2” using RPN calculators, the expression is inserted as “2 Enter 4 Enter 5 + ×”. This will give the correct answer as “18”. Likewise if we want to calculate “4+(5×2)” then this expression is inserted in RPN calculator as “4 Enter 5 Enter 2 × +” and this will give the answer as “14”. This thing happens in the stack in the following way:


For Mathematical expression “(4+5)×2”

      First Step (Initial State)T: 0Z: 0Y: 0

X: 0

Second Step (Press “2” then “ENTER”)T: 0Z: 0Y: 0

X: 2

  Third Step (Press “4” then “Enter”)T: 0Z: 0Y: 2

X: 4

 Fourth Step (Press “5” then “ENTER”)T: 0Z: 2Y: 4

X: 5

 Fifth Step (Press “+” then ENTER)T: 0Z: 0Y: 2

X: 9

 Sixth Step (Press”×” then ENTER)T: 0Z: 0Y: 0

X: 18





For Mathematical Expression “4+(5×2)”

      First Step (Initial State)T: 0Z: 0Y: 0

X: 0

Second Step (Press “4” then “ENTER”)T: 0Z: 0Y: 0

X: 4

  Third Step (Press “5” then “Enter”)T: 0Z: 0Y: 4

X: 5

 Fourth Step (Press “2” then “ENTER”)T: 0Z: 4Y: 5

X: 2

 Fifth Step (Press “×” then ENTER)T: 0Z: 0Y: 4

X: 10

 Sixth Step (Press”+” then ENTER)T: 0Z: 0Y: 0

X: 14


HP 15C Scientific Calculator
is shown in the figure below. Hp-15c uses five registers in complex mode. There is an easy method to enter a complex number in Hp-15c. The real part of the complex number is entered by pressing “ENTER” and then the imaginary part of the complex number is entered by pressing “f1” key. By doing so, the real part of the complex number is displayed on screen and the imaginary part is saved to the stack. The user can see the imaginary part on the display of the calculator by pressing “f(i)”.  In this way, the user can see both the imaginary and real parts of the complex number.

HP 15C Scientific Calculator
was the first model with Matric calculation. The calculations on this calculator can be done with 5 matrices which are named as A, B, C, D and E. There is a very easy way to set the dimensions of the matrix on this calculator. The user has to enter the expression “2 Enter 2 fDIM A” for defining matrix A as 2 by 2 matrix. The user can insert the elements of the matrix explicitly by adjusting the rows and the columns. The size of the matrix as defined by the user can be shown by the expression “RCL MATRIX A” and the result will be displayed on screen as “2 2”. This calculator has the capacity for storing 64 matrix elements. Many of the matrix functions can be performed on this calculator like determinants, LU Decomposition, Inverse of the matrix, multiplication, addition, subtraction etc.

By looking at all the factors discussed so far, it is proved that RPN is much better than the regular algebraic calculation because RPN saves time; the calculations can be done with less number of keystrokes; RPN has stack; there is no need of parentheses in case of RPN; RPN is more intelligent; RPN is elegant and RPN does the computation which matches the thinking of the user.

Interested in reading more about reverse polish notation? Check out Algorithms for Reverse Polish Notation Calculators

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather
facebookrssby feather