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).

  • $\begingroup$ Typically, multiplication is left-associative, $(1*2)*3$. $\endgroup$ – Daniel Fischer Jan 24 '14 at 12:16
  • $\begingroup$ 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. $\endgroup$ – 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.$

  • $\begingroup$ Your answer makes sense, but can you please define in technical terms what "as soon as they make sense" means? Why would applying the operations make sense for a * b * c and wouldn't make sense for a + b * c? In the second example when you arrive to the "b" you cannot apply the + operation. So, the 2nd example becomes a b c * + in RPN, whereas a * b * c becomes (as you suggested) a b * c * - so why wouldn't we apply the same logic here (in order to get a b c * *)? How can you foresee that an operation is going to make sense or not? $\endgroup$ – Razvan Jan 24 '14 at 13:36
  • $\begingroup$ 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.$ $\endgroup$ – 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

  • $\begingroup$ I'm aware we get the same result using either form, but my question was whether or not - by definition - we should get to only one of them (with no ambiguities). $\endgroup$ – Razvan Jan 24 '14 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.