How to convert summation into reverse polish notation

415 Views Asked by At

I'm struggling to find a proper answer to the following question. How to convert a equation (including complex operators like summation) into RPN?

Example power series:

P(x)=$\sum^\infty_{n=0}a_n(x-x_0)^n$

I know how to write the equation within the summation, but the summation take 3 operants (plus variable assignment).

$x$ $x_0$ $-$ $n$ $pow$ $a_n$ $*$

2

There are 2 best solutions below

0
On BEST ANSWER

In RPN, you affectively have a "stack" of operands. Each new entry removes however many operands it needs from the stack, and places its result back on the stack.

  • Constants and variables require no operands, so they simply add their value to the stack.
  • Unary operators require one operand, so they remove one item from the stack and then add their result to the stack.
  • Binary operators remove two operands from the stack and add one.
  • Trinary operators remove three operands from the stack and add one.
  • Etc.

Every operator has to have a known number of operands, but as long as that is true, the RPN is straight forward to interpret.

Understanding $\sum$ to be a quadrary operator, whose first operand is the expression to be summed (which must be a function of an indexing variable), the second is the index variable, the third is the lower limit and the fourth is the upper limit.

In this scheme, it is not the summation that gives trouble. Instead, "$a_n$" is the questionable term, as it must somehow express different values for each $n$. But passing over that, the RPN would be

$x\,\,x_0\,\,−\,\,n\,\,\text{pow}\,\,a_n\,\,*\,\,n\,\,1\,\,\infty\,\,\sum$

2
On

This question doesn't make much sense as the RPN is working with numbers and not expressions involving variables.

If you insist having an RPN-like notation, you could write

$x$ $x_0$ $-$ $n$ $pow$ $a_n$ $*$ $0$ $\infty$ $+_n$

with the conventional interpretation

$x$ $x_0$ $-$ $0$ $pow$ $a_0$ $*$ $x$ $x_0$ $-$ $1$ $pow$ $a_1$ $*$ $+$ $x$ $x_0$ $-$ $2$ $pow$ $a_2$ $*$ $+$ $\cdots$

IMO, ugly and useless.