Operations in Reverse Polish Notation

Click For Summary

Discussion Overview

The discussion revolves around the application of Reverse Polish Notation (RPN) for expressing mathematical operations, particularly limits and integrals, which are not straightforwardly represented in RPN. Participants explore how RPN can accommodate various functions, including those with multiple arguments, and the challenges associated with defining a universal order of operations for such functions.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant questions how to express limits in RPN, noting that limits and integrals are complex functions requiring multiple values.
  • Another participant suggests that limits can be treated as operations taking two arguments: a function and a point of evaluation.
  • Some participants argue that RPN can handle n-ary operations, countering the claim that it only supports unary and binary functions.
  • Concerns are raised about the lack of a universal order for entering arguments in RPN, especially for functions with more than two variables.
  • One participant mentions that while there is no universal standard, specific calculators have developed their own conventions for handling multiple arguments in RPN.
  • Another participant points out that without standardization, confusion can arise regarding the order of arguments in operations like integrals.
  • Discussion includes references to HP's RPL language, which standardizes certain functions and allows for complex operations.

Areas of Agreement / Disagreement

Participants express differing views on the capabilities of RPN regarding multi-argument functions and the existence of a universal order of operations. There is no consensus on whether a standardized approach exists for expressing complex functions in RPN.

Contextual Notes

Limitations include the absence of universally accepted definitions for the order of operations in RPN, particularly for functions with multiple arguments, and the potential for confusion in interpreting expressions without standardization.

The Javaman
Messages
3
Reaction score
0
Recently I was doing various equations in RPN to teach myself the notation. Everything went fine until I wanted to do a limit. How would one go about expressing limits (and any other operation that isn't addition, subtraction, division, or multiplication) in RPN?
 
Mathematics news on Phys.org
Limits and integrals are complex functions that require several values and/or variables to be entered at one time. They don't really have a specific, defined "order of operations" (i.e., how would you enter a limit in a calculator; standard or RPN?)

RPN only really lends itself to 1- or 2-value functions:
X [enter]
Y [enter]
[function]

or

X [enter]
[function]

where [function] might be addition, subtraction, multiplication, x^y, e^x, 10^x, SIN, COS, TAN, 1/x, etc.
 
In the usual way. We write addition "a b +" where a and b are numbers because + is an operation that takes two arguments. If you have a function f(x) and you want to evaluate
[tex]\lim_{x \to a} f(x)[/tex]
then you can consider a limit as an operation that takes two arguments: first a function, then a number that specifies where you want to evaluate the limit so it might look something like,
f(x) a lim
If we call the operation lim. Or for a more concrete example where x is a built-in variable and sin is a one-argument operation returning the sine.
x sin x / 0 lim
which would evaluate
[tex]\lim_{x \to 0} \frac{\sin(x)}{x}[/tex]
Of course if you have some specific RPN system in mind, then there might be a specific way to evaluate limits, but RPN in general is just a way to write evaluation of functions so there are many options as to how it's designed.
 
zgozvrm said:
RPN only really lends itself to 1- or 2-value functions:
X [enter]
Y [enter]
[function]

This is false. RPN lends itself perfectly fine to n-ary operations. For instance for a 3-ary function:
X [enter]
Y [enter]
Z [enter]
[function]
For a 4-ary function:
X [enter]
Y [enter]
Z [enter]
W [enter]
[function]
It's the ordinary infix notation that doesn't work well with more than 2 arguments.
 
Interesting. I never thought about using multiple arguments, but it does make a great deal of sense. I actually have no system in mind, I was just curious.
 
It DOES make some sense, but I haven't seen it done.

When I think about it, I'm not really sure you can still call it RPN; any definition I've seen refers to unary and binary functions.

I think the problem with ternary (and larger functions) is that there is no standard defined order of entering the values. Clearly, the order would be important though.
 
So there is no universal order of operations in RPN? That's disappointing, but I suppose one could define their own system. It is safe to say that any operation in RPN can be represented as a stack of it's arguments followed by the symbol itself though, isn't it?
 
Last edited:
It's not that there's no "universal order" in RPN, it's more that complicated functions with many variables, don't have a universal order in which the values should be entered. Therefore, it would be difficult to implement in RPN (or any other system) with universal agreement.

You are correct in that it can be done though.
 
The Javaman said:
So there is no universal order of operations in RPN?

Even some binary functions require specific order of arguments - so some basic ordering of arguments already is there. But it is not generalized to functions with more variables.
 
  • #10
zgozvrm said:
Therefore, it would be difficult to implement in RPN (or any other system) with universal agreement.
Luckily you don't need universal agreement, just a specification. For instance on HP's calculator's they usually use x to represent the top-most argument on the stack, and y the next so.
5 3 [itex]y^x[/itex]
would evaluate [itex]5^3[/itex], but there is nothing wrong in extending this notation to include z for the next argument. Actually while most users doing simple computation won't need functions taking 3 arguments they do exist on modern HP calculators. For instance there is a command called IFTE which is short for "If-then-else". The first argument is a truth-value (1 or 0), the second is what to return if the first argument is 1 and the last is what to return if the first argument is 0. Using this we could for instance evaluate the sign of the top-most value on the stack as follows :
DUP 0 == 0 DUP ABS / IFTE
which basically works as follows:
if(x == 0) then: 0
else: x/|x|
There is nothing confusing about this as long as we standardize the order of the arguments just as we have with -. In normal infix notation there is no danger of confusing x-y and y-x or
[tex]\int_a^b f(x) \,\textrm{d}x \quad \int_b^a f(x) \,\textrm{d}x \quad \int_a^{f(x)} b \,\textrm{d}x[/tex]
They are clearly different. If you standardize INTEGRATE, then there is no way you would confuse
A B F INTEGRATE
with
A F B INTEGRATE
 
  • #11
Agreed, but to my knowledge there hasn't been any standardization for such expressions.

Besides, you could just as easily say "take the integral of function F from a to b" as "take the integral from a to b of function F"
To us, they mean the same thing, but a calculator, needs to have strict rules. Once there is standardization in the order in which the variables are entered, then no, there is no confusion, but unless and until that happens, it is not necessarily clear.

In addition, your example shows a very simple function F, what if it was more complicated?
 
  • #12
zgozvrm said:
Agreed, but to my knowledge there hasn't been any standardization for such expressions.
HP developed the RPL (Reverse-Polish LISP) programming language for their calculators which standardize the functions I mentioned earlier. It also includes syntax for actually working with complex functions and even defining your own. You're right that there is no universal standard though, just as 5 3 ^ could mean both 5^3 or 3^5 since there is no universally agreed upon way of ordering it.

Besides, you could just as easily say "take the integral of function F from a to b" as "take the integral from a to b of function F"
To us, they mean the same thing, but a calculator, needs to have strict rules. Once there is standardization in the order in which the variables are entered, then no, there is no confusion, but unless and until that happens, it is not necessarily clear.
I completely agree, but keep in mind that many calculator producers have taken the trouble to standardize the order. Due to the fact that when writing definite integrals ([itex]\int_a^b f(x)dx[/itex]) we write the arguments in the order a b f so the natural candidate is A B F INTEGRATE, but F A B INTEGRATE is also imaginable even though I have never seen that order. Keep in mind however that this problem is in no way exclusive to RPN calculators/languages. Most calculators and programming languages don't have an integral sign as such either so you end up writing INTEGRATE(a,b,f) which also relies on some ordering.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K