Post Reply 
Conversion: Algebraic - Polish - Reverse Polish - LISP ?
11-01-2024, 12:34 PM
Post: #2
RE: Conversion: Algebraic - Polish - Reverse Polish - LISP ?
(11-01-2024 09:52 AM)Martin Hepperle Wrote:  Something written in RPL for the HP 4x family of calculators would be an option

On the HP-48 you can run the TEACH command, which creates an EXAMPLES directory.
In the PRGS subdirectory you will find the following program →RPN:
Code:
« OBJ→
  IF OVER
  THEN → n f
    « 1 n
      FOR i
        IF DUP TYPE 9 SAME
        THEN →RPN
        END n ROLLD
      NEXT
      IF DUP TYPE 5 ≠
      THEN 1 →LIST
      END
      IF n 1 >
      THEN 2 n
        START +
        NEXT
      END f +
    »
  ELSE 1 →LIST SWAP DROP
  END
»

The algebraic expression 'x*(1+x*(1-x))*SIN(x)' is converted into an RPN program:

{ x 1 x 1 x - * + * x SIN * }

Using REVLIST we can reverse the list:

{ * SIN x * + * - x 1 x 1 x }

Now we need to insert the missing parentheses:

{ * {SIN x} {* {+ {* {- x 1} x} 1} x} }

Let's swap the arguments of the binary operators:

{* {* x {+ 1 {* x {- 1 x}}}} {SIN x}}

Compare it with:

(* (* x (+ 1 (* x (- 1 x)))) (SIN x))

Maybe you can modify the program to do that automatically for you.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Conversion: Algebraic - Polish - Reverse Polish - LISP ? - Thomas Klemm - 11-01-2024 12:34 PM



User(s) browsing this thread: 4 Guest(s)