Re:2^3^4 - a comparison of math packages
by baddox on Monday February 06, 2012 @03:41AM
(#3556692)
It's interesting to think that the whole notion of associativity and order of operations only exists because for some reason humans seem to find infix notation more "natural" for binary (or fixed arity) operators than more easily parseable and less ambiguous alternatives like prefix.
[ Parent
| on HN ]
^ ^ 2 3 4
Prefix notation doesn't automatically solve the problem, you need to assume an evaluation order. More specifically, you need to not assume associativity.
Isn't the lack of associativity explicit in prefix notation? Prefix notation doesn't even contain the notion of order of operations. You would convert the infix "2^3^4" to prefix in different ways depending on the associativity of exponentiation:
For left associativity (uncommon):
^ ^ 2 3 4
For right associativity (common): ^ 2 ^ 3 4
Of course, all this is assuming all operators are fixed arity, otherwise you need parentheses no matter what.