I am not sure why RPN is necessary?

For something like this, where we know that X is:

(2(4*x-8)+3*x)-(11*x+1-9) (2*(4*x-8)+3*x)-(11*x+1-9)
In converting an algebraic representation to RPN, the order of the operands will be unchanged. You wind up either pushing an operand to the stack or applying an operator the previous 2 things on the stack. (well there is the case of an unary operator, 4+ (-8), etc.)

(2*(4*x-8)): push 2 push 4 push x op *; (4*x) is now last on stack push 8 op -; now 4*x-8 is last on stack op * ; now result is last thing on stack
In Perl, you can compile and execute an expression "on the fly" using "eval". No conversion by you to RPN is necessary. Any legal Perl statement can be executed via eval. There are ways to intercept and report errors in the eval'ed expression (divide by zero), etc.

An expression like this:

2(4x-8)+3x=11x+1-9
where you want "x", is not so easy. I am flummoxed as to why you think that RPN could help here?

In reply to Re: Reverse Polish Notation Question by Marshall
in thread RPN Question by nat47

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.