# Ambiguity in Reverse Polish notation

Given the infix form:

1 * 2 * 3

What is the Reverse Polish notation?

As I see things, two valid answers are:

A. 1 2 3 * *
B. 1 2 * 3 *

I believe there is a subtle difference between these two forms, as, mathematically, they both yield the same result.

Also, I think the ambiguity comes from the decision of whether to evaluate the expression as (1 * 2) * 3 or 1 * (2 * 3).

How does multiplication work in this case by definition? (if it's any relevance I'm asking this in the realm of computer science).

• Typically, multiplication is left-associative, $(1*2)*3$. – Daniel Fischer Jan 24 '14 at 12:16
• The polish notation is suitable for a mechanized manipulation because a computer program does not have the typical limitations and strenghts of human mind : e.g. a trained human "mathematician" can read a compelx formula with parentheses quite easily. A machine does not "see" the complex formula, but works step by step. But the polish notation does not change the rules : e.g those regarding precedence between operators. Human "computrers" use parentheses to facilitate reading, but the strict application of rules does not allow for ambiguities. – Mauro ALLEGRANZA Jan 24 '14 at 12:26

Technically, there is ambiguity in the infix form $a*b*c$, since it is not a matter of notational definition that this means $(a*b)*c$. In practice, of course, the ambiguity doesn't matter, since the two interpretations evaluate to the same result (unlike the case with octonions, for example). Arguably, there is no ambiguity if we accept the convention that operations of the same type are performed from left to right. However, this convention (unlike the case with subtraction) might be considered as lapsed in the case of multiplication, since it is never exercised.
Reverse polish notation is unambiguous, with the operations applying left to right as soon as they make sense. Your example using numerals is perhaps a little unfortunate, because the prior convention is that $12$ means twelve, not $1\times 2.$
• The convention for infix operations is not "as soon as it makes sense". In evaluating $a+b*c$, the expression makes sense as soon as we reach $a+b.$ While $a+b$ makes sense, it is a wrong interpretation, because there is an overriding convention that multiplication is evaluated before addition. Thus (omitting $*$, also by convention) $a+bc$ means $a+(bc).$ If we intend $(a+b)c,$ then we must put those parentheses in to override the "times before plus" convention. In contrast, reverse Polish is always "as soon as it makes sense": $abc*+$ means $a+bc$ and $ab+c*$ means $(a+b)c.$ – John Bentin Jan 24 '14 at 15:08
The term $1\cdot2\cdot3$ only makes sense for an associative multiplication, which allows the "reader" to chose one of the following meanings, which yield the same result: $$1\cdot2\cdot3 = \begin{cases}(1\cdot2)\cdot3\\1\cdot(2\cdot3)\end{cases} = \begin{cases}1\ 2*3*\\1\ 2\ 3**\end{cases}=\begin{cases}2\ 3*\\1\ 6*\end{cases} = 6$$ You could view the reverse polish notation as a FORTH program to visualize