Why Some Calculators Change the Placement of
Operators in Algebraic Expressions
Albert Lilly, Ph.D.
Alabama School of Mathematics and Science
1255 Dauphin St.,
Mobile, AL 36604
E-mail: lilly@asms.net
Voice: (334) 441-2168
Fax: (334) 441-3290
The reason some calculators change the placement of operators
in algebraic expressions is to maintain a way
of changing the order
of operations without having to use parentheses.
For example, compare the following two expressions:
1 + 2 * 3
and
(1 + 2) * 3
The first expression evaluates to 7 and the second expression
evaluates to 9. The effect of the parentheses in the second
expression is to perform the addition before the multiplication.
Changing the Notation
The way some calculators avoid parentheses is to change the
notation to postfix (or Polish) notation from infix notation.
With infix notation, the operator is placed in the middle
of the operands. For example, in the infix expression
1 + 2
1 and 2 are operands and + is the operator in the middle.
The postfix version of the expression places the + after
both operands as in
1 2 +
Using a Calculator that Expects Posfix Expressions
Enter the numbers in the exact order in
which they appear. Enter the operators in their
order
of operation as soon as
the appropriate operands have been entered.
For example, for the expression
1 + 2 * 3 - 4
The order of the numbers is 1 2 3 4
The order of the operations is * + -
The * should be entered after 3
The + should be entered after 2 but
not before *
The - should be entered after 4
The correct sequence is:
1 Enter {1 is the current value}
2 Enter {The calculator pushes
2 on top of 1--1 is no
longer shown }
3 Enter {The calculator pushes 3
on top of 1 and 2--Note
that * is the first
operation and 3 is the
second operand for *}
* {The calculator multiplies
2 * 3 to get 6 and pushes
the 6 on top of the 1}
+ {The calculator adds the
1 and 6 to get 7}
4 Enter {The calculator pushes
4 on top of 7}
- {The calculator subtracts
4 from 7 to get 3}
The postfix version of the expression
is the same as the entered order:
1 2 3 * + 4 -
A second expression
(1 + 2) * (3 - 4)
would be entered as follows:
The order of the numbers is 1 2 3 4
The order of the operations is + - *
The + should be entered after 2
The - should be entered after 4
The * should be entered after
3 but not before -
1 Enter {1 is the current value}
2 Enter {The calculator pushes
2 on top of 1--1 is no
longer shown}
+ {Note that + is the first
operation--The calculator
adds 1 and 2 to get 3 and
returns the result}
3 Enter {The calculator pushes
3 on top of 3}
4 Enter {The calculator pushes
4 on top of 3 and 3}
- {The calculator subtracts
4 from 3 to get -1 and
pushes -1 on top of 3}
* {The calculator multiplies
3 * -1 to get -3}
The postfix version of the expression
is the same as the entered order:
1 2 + 3 4 - *
Exercises
For the following expressions, show the order of operations
for a calculator that expects postfix notation:
1. 5 + 9 / 3
2. (5 + 9) / 2
3. 4 * 3 / 6 + 8
4. 4 * 3 / (4 + 8)
5. 4 * (3 / (1 + 2))
6. 4 * 3 + 6 / 3
7. 4 * (3 + 6) / 3
8. 4 * 3 + (6 / 3)
9. 4 * ((3 + 6) / 3)
10. 4 * (3 + (6 / 3))