HP Forums

Full Version: 50G RPL Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I thought, at one point, I ran across a 50G RPL command to convert an algebraic equation to an RPL program. I spend some time looking through the AUR, and couldn't find the command. Does this command exist, or was I dreaming?
Hello David,

you aren't dreaming, have a look to AUR: RPL Programming Examples 2-27; Headline:
"Converting Procedures from Algebraic to RPN". There you get what you want! TYGWYW.

Sincerely peacecalc
Great, that was exactly what I was looking for. Thanks!
There is also a built-in command which converts algebraic objects into RPN form as a list, and another which converts them into RPN form as a program. They are in Library 256, so unless you keep that library attached, you'll have to do 256 ATTACH before using these commands, or type 256 MENU and access these functions via their softkeys. Examples:

'1+2*3' →LST --> { 1 2 3 * + }
'1+2*3' →PRG --> 1 2 3 * + (the program delimiters are invisible)

The function →ALG turns both of the above outputs back into an algebraic object. Warning: The →ALG command does not check to see if its input produces a valid algebraic object. Use with caution, and if the result looks like 'Invalid Expression' then beware that executing it can crash or cause memory corruption.
For those looking for a solution on the HP48G series, if you type in TEACH it loads some sample programs (among other things). In the EXAMPLES PRGS subdirectory is a program called →RPN which does exactly what the name suggests. (You enter an algebraic object and it converts it to an RPN list)

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
»
This is really great, thanks for this information! And thanks to OP for making the thread. I wanted to do this for a while but never managed to make my way through the AUR.
Joe-I think that's the solution that I had in mind, it was a single command. The ->RPN program will also work, without those libraries attached.
Thanks!
If you wish to have the program delimiters included, the following adds those to the beginning and end of the program:
Code:
\<<
   \->LST
   \<< \>> \->LST LIST\-> DROP
   ROT SWAP
   + +
   \->PRG
\>>

Likewise, the following converts a program object with the program delimiters back into an algebraic:
Code:
\<<
   \->LST
   DUP SIZE 1. -
   2. SWAP SUB
   \->ALG
\>>

Joe's warning still applies -- watch out for 'Invalid Expression'.
Reference URL's