Yes, thanks to all for the answers. Very interesting.
Once you get used to RPN, you realize that that’s what you always do when doing math yourself; it’s just usually not notated that way.
Of note, you need an “ENTER” key, or the like, to use between numbers, so you can distinguish “Four Three Two” from “Four Hundred Thirty-Two”. So @Hari_Seldon 's example should read
4[Enter]2[Enter]3+*
RPN needs some kind of symbol or key entry to let it know that 423 is not one number. On an HP calculator, you’d type:
4 {enter} 2 {enter} 3 + *
In RPN the operator (or equivalent) is not just a separator, it is an instruction to push the current value onto the stack. Other operators pop a value off the stack and perform an operation between that value and the current value, with the result becoming the new current value.
Very simple to implement in hardware and easy to key into a calculator, but not IMHO very readable.
By far my favourite
What does, say, a polynomial look like in RPN?
Would you use it for expressions involving, say, matrices or vectors?
Isn’t a space the usual delimiter for writing out RPN? The example given was confusing as heck to me as 432 was written out as a single number.
ax2 + bx + c turns into
x^2a*xb*c++ or equivalently
x^2a*xb*+c+ depending on your taste.
It’s essentially just rattle off the inputs and operators in the sequence you’d perform the calculation by hand.
Which works well for actual calculation with numbers resulting in a number, but is less than convenient for symbolic manipulations, like factoring that same polynomial into (x+d)(x-f) format.
You could. Given suitable mechanisms for denoting or storing vectors and matrices. Again it’s simply a matter of writing
[operand][operator] or
[operand1][operand2][operator]
in preference to some other way of indicating what is to be done to who. It’s particularly suited to denoting scalar values and unary/monadic and binary/dyadic operators. But it doesn’t have to be limited to just that.
The fact its popularity is almost entirely down to one brand of long-obsolete hand calculators sorta suggests its real strengths lie near that use case, not in general mathematical or computer programming discourse.
Yes, that kind of gets to the heart of it.
The easiest way for human beings to read mathematical expressions or at least with the most clarity is not necessarily optimal from the sense of disambiguation or for mechanical calculation
Except that’s what students do rather than OoPs. 3 + 7 x 2 becomes in their head reading left to right Three plus Seven times Two.
Maybe we should rewrite expressions to be read left to right as our new order of operations so that if I want multiplication first I would have to do 7 x 2 + 3
The problem with that approach is it can only be sufficient for very, very simple expressions when using “infix” (= operator between operands) notation.
Try rearranging this expression using your idea:
3 x 4 + 7 x 2
You can’t.
RPN as discussed above is a solution that does reorder things to be left-to-right with no built-in precedence for e.g. multiplication over addition. At the expense of creating an implicit or explicit stack of intermediate partial solutions, and sacrificing infix operators for post-fix operators.
Further, all this comes back to the difference between teaching kids to calculate versus teaching (older?) kids to understand and manipulate formulas as formulas, not just plugging in input values to arrive at a result value.
Understanding very basic algebra concepts like the commutability, associativity, and distributivity would be hampered if our notation drove how we expressed those ideas.
In the future the graphic representation of expressions will be adjustable to the display device and your choice of operator precedence and order of operations will be selectable to your preference along with the representation of all the other elements of the expression. It is rather easy to convert expression format between defined systems. Discussions like this about the limitations and limited choices of hard text based expressions will seem rather quaint. Many coding studios already have the feature of adding parentheses to expressions for clarity and offering optimizer hints and tips for expression syntax alternatives.
Exactly what I meant
An expression like 3 + 7 x 2 is very easy for us to read. But it requires disambiguation to determine if the multiplication should be done first or not, which is what an Order of Operations is intended to do.
RPN resolves this issue from a mechanical calculation standpoint but it’s not intuitive for us to read and parse.
An “Order of Operations” is more of a bridge between natural human language and mathematical calculation than something that is inherently necessary for mathematical expression.
It’s very easy to say “well, everybody should just follow ‘the’ order of operations” but that misses the point. The purpose of an order of operations is to make it easier for people to communicate mathematical expressions unambiguously, not to provide arbitrary rules for people to follow thoughtlessly.
Just thought of something. You know how people can’t agree how 60 ÷ 2(3 + 2) should be calculated via order of operations? RPN makes it unambiguous.
It’s no more or less ambiguous in RPN. Any expression is ambiguous if the rules aren’t known. RPN is a name for some simple rules, PEMDAS is a name for slightly more complex rules.
Exactly the point I made about readability. I couldn’t fathom doing algebra in RPN.
Agree 100%.
But it is also true that the more complex the rules the greater the odds there will be unnoticed corner cases. Witness the Federal tax code.
Or, more realistically for something as time-worn and well-tested as PEMDAS, the greater the likelihood that the more complex rules will be misunderstood or misremembered in a simplified form which causes mistakes and exposes what looks like corner cases that aren’t really per the no-kidding actual rule, but are per the simplified caricature rule that most non-experts think they accurately learned or remember.
Viewed in isolation the upside to RPN is its comparative simplicity over PEMDAS. After that, much like Dvorak keyboards, it’s mostly esoterica for esoterica’s sake.
…and to be able to work with and manipulate them in a way that is as convenient, flexible, and intuitive as possible.
I loooove RPN for calculator work, but I don’t like it for written notation. With written RPN notation, I have to do the full calculation from left to right to understand what’s happening. But with PEDMAS, I can visually see the big jumps and small changes that lead to the answer. It’s easier for me to read “10x4+4” than “10,4x4+”. But it’s easier for me to compute “10,4x4+” with my beloved, decades old HP calculator than to compute “10x4+4” on a traditional calculator.
It’s basically the exact same process for English grammar, except math is supposedly a universal language, so there aren’t thousands of different versions, like there are different grammars for different languages.
Grammar evolved naturally over time. Much later, people started writing down the rules of grammar as they understood them, and then teachers started treating them like indisputable, set-in-stone rules, and smacking students’ fingers with rulers whenever they got it wrong.
But nevertheless, it is not set in stone, different people will express the same ideas in different ways, and some care and communication needs to happen in order to avoid ambiguity and confusion. Even in a supposedly universal, standardized, rule-based language like mathematics.