[Tutor] Simple RPN calculator
Brian van den Broek
bvande at po-box.mcgill.ca
Sun Dec 5 17:40:38 CET 2004
Kent Johnson said unto the world upon 2004-12-05 06:55:
> RPN reverses the order of operator and operand, it doesn't reverse the
> whole string. So in Polish Notation 2 + 3 is +23 and (2 + 3) - 1 is
> -+231; in RPN they become 23+ and 23+1-
>
> Kent
Hi all,
Thanks Kent, that is what I had assumed it would be by analogy to Polish
notation in logic. Somewhere on the thread, I though it had been
asserted that all opps and operands were separated. For a bit there, I
thought I'd gone all goofy :-) So, thanks for clearing that up.
Thanks also for the other interesting posts on the thread.
Largely off-topic things follow:
One other advantage, at least from the logicians perspective is that
standard "infix" notation is only able to comfortably deal with binary
and unary operations (operations that have 2 or 1 arguments). For
arithmetic, where you can do everything with zero, successor,
multiplication, and addition, that isn't so important. But notice that
general function notation, in Python and in math, is also Polish -- to
write a 4 placed function that takes, say, the greatest common divisor
of two numbers, and the least common multiple of two others, and tells
you if the first divides the second, you've got to write:
f(a,b,c,d).
So, Polish notation makes manifest the conceptual similarity between the
addition -- ADD(a,b) -- 2-placed function and arbitrary n-placed functions.
This also helps out a lot in some of the areas where formal logic and
formal semantics for natural languages bleed into each other. At a cost
of patience, all truth functions can be expressed in terms of the "not
both" truth function, so polyadic truth-functions past binary don't
really need Polish notation.
But, when you consider the quantifiers ('for everything . . .' and
'there is at least on thing . . . '), standard ones are one-placed (with
a given universe of discourse set assumed). In the 1950's and 1960's
mathematicians began exploring generalizations of the quantifier notion.
There have, since the 1980's, been a sizable group of linguists who
argue that natural language quantification is almost always 2 or higher
placed. After two places, this too needs Polish notation (or heroic and
ugly conventions).
Brian vdB
More information about the Tutor
mailing list