Tree Notation for Arithmetic

Alternate Notations for Arithmetic

There are other ways to write down math. The style which we are used to is known as infix notation. Two better known alternatives are Reverse Polish Notation ( RPN , or postfix notation, and Polish Notation ( PN ), or prefix notation. The main difference is that infix notation places operators, like +, −, ×, ÷, are placed between the arguments, and parentheses are used for grouping. Postfix notation ( RPN ) puts the operators after the arguments, and prefix ( PN ) puts the operators before the arguments. One interesting difference is that these other two notations don’t require the use of any parentheses. Below is a table of a few examples written in all three notations.

Infix Postfix Prefix
1 + 1 1 1 + + 1 1
1 + 2 × 3 1 2 3 × + + × 2 3 1
(1 + 2) × 3 1 2 + 3 × × 3 + 1 2
√(3^2 + 4^2) 3 2 ^ 4 2 ^ + √ √ + ^ 3 2 ^ 4 2

There are programming advantages of using these alternate notations, most deal with entering in expressions and parsing expressions. Many HP calculators use RPN input which allows them to forgo buttons for (, ), and =. The end of an postfix expression is signaled by a entering an operation. This can be seen in the postfix examples above in that each ends with an operation. Parsing postfix and prefix expressions can be accomplished with simpler programs than those required to parse infix expressions.

With the supremacy of TI calculators, which employ infix expression input, it is difficult to test any benefit from students knowing these alternate notations due to the cost of teaching either prefix or postfix. And there are benefits to students who can think in these alternate notations. One is a better understanding of order of operations. Neither prefix nor postfix notation require an ordering on operation evaluation. This is because the ordering is already encoded in the notation. A student who can consistently convert expressions from a textbook or assignment into one of these alternate notations will be able to correctly determine the order of evaluation in the exercise. Second, often the last operation performed in the evaluation is important to identify. In exercises like expanding logarithmic expressions, computing derivatives, or even solving equations, the last operation performed needs to be identified to determine which rule should be the first to employ. With postfix, the last operation is the last symbol in the expression, and likewise with prefix, it is the first symbol. Third, distinguishing between horizontal and vertical transformations requires an ability akin to identiyfing which operations happen before the function is applied and which happen after. All these benefits amount deeper understanding of order of operations for not just numeric expression, but algebraic as well. For those that would like a new phrase, perhaps we should call this deeper concept the “order of evaluation”.

Arithmetic on Trees

I think that there might be a notation which is easier to read and understand which provides all the benefits of prefix or postfix. This notation may be correctly referred to as the abstract syntax tree of the arithmetic expression. Learning this tree notation makes prefix and postfix easier to understand, and vesa-versa. Below is an example of using the tree notation to represent 1+1.

Tree Notation for 1 + 1

Tree Notation for 1 + 1

Subtracting Fractions

Next is an example of the computations to show that 3 / 4 - 2 / 3 = 1 / 12.

Quadratic Example

Another learning example is the quadratic formula.

Tree notation for quadratic formula

Tree notation for quadratic formula

And the following are the steps in the computation of the quadratic formula for the quadratic \(x^{2} - 4 x + 3\).

One may notice the use of boxes for operators like − and ÷ versus the use of ovals for + and ×. This is due to the fact that − and ÷ are noncommutative binary operators, whereas + and × are commutative. So for − and ÷, it must be made explicit which is the first argument and which is the second. But for + and ×, it does not matter which argument is first and which is second. Also, note in the quadratic formula, the part of the tree corresponding to \(4 a c\) is just an oval for × with three leaves coming off it, one leave for each 4, \(a\), and \(c\). This might seem odd because × is not defined to take three arguments but only two. The associative property is what allows us to multiply together any number of arguments.

× Instead of ÷, + Instead of −

Already, we have used the properties of associativity and commutativity to explain the features of this tree notation. The convenience of these two properties in our notation push us to use + instead of − and × instead of ÷.

FOIL

In the next example, distributing two binomials is done step by step. The second and third steps make no progress in the computation, but only allow for two applications of distributing × over + to be clearly delineated. A similar need for clarity of the notation splits the last step up into the fourth and fifth steps. Notice how, in the last step, each variable is used in two different multiplications. Yet there is only one node for each variable. This demonstrates how tree notation can reuse common subexpressions and cut down on redundancy. Another example of this reuse of common subexpressions can be found in the second and third steps, where \(c+d\) is the common term.

Log of a Product

Tree notation of the product rule for logarithms

Tree notation of the product rule for logarithms

Notice how almost all of the laws, rules, and properties illustrated here with tree notation are about moving one operation past, or perhaps through, another. This a deep fact about the nature of algebra: the study of algebra is the study of how these operators can be rearranged and done so in a correct way.

Thoughts

I would love to hear your thoughts, comments, questions, and criticisms on this tree notation. Allow to address some obvious questions first though. First, I don’t think this new notation will take the world by storm. It's big draw back is that it takes up a lot of room and is far more difficult to get a computer to render. Second, I don’t know if this notation should even be introduced to students in general. While I do believe there are benefits to this notation, the costs of teaching the notation alone should not be underestimated. With struggling students, it may not be worth the time. But with brighter students, it might be worthwhile to spend a day or two on this notation, and come back to it now and again. Still, all of this is merely conjecture, and not backed by evidence. Rather the purpose of this post was to introduce people to an unfamiliar idea in the hopes that any value in the idea, if any exists in it, will be spread to others.