We realize there are other venus that you have posted to that store your brilliance.
Take the opportunity to share it with the FM Forums Community.

Thanks.

# RPN ( expression )

• Formulae:

```// RPN( expression )  or Reverse Polish Notation
// by Stephen Dolenski

Let ([
exp = Substitute( expression ; " " ; ¶) ; // pivot expression into a return sep list.
exp_len = ValueCount ( exp ) // count entries.
];

//============================

If(  \$i   >   exp_len ;

Let( \$i = 1 ; \$stack)
;

If(  Filter( GetValue(exp ; \$i) ; "*+-/")  ≠ \$null ;   // value is operator

Let ([
\$result =  Evaluate(GetValue (\$stack ; 1 )  &  GetValue(exp ; \$i)  & GetValue (\$stack ; 2 ))  ;
\$stack =  Substitute( \$stack ; [GetValue ( \$stack; 1 )  & "¶" & GetValue ( \$stack; 2 )  & "¶"  ; \$result &¶] ; [GetValue ( \$stack; 1 )  & "¶" & GetValue ( \$stack; 2 ) ; \$result]);
\$i = \$i+1
];
RPN( exp )
) // end let

; // else append stack

Let ([
\$stack = Case( \$i = 1; GetValue (exp ; 1 ) ; GetValue(exp ; \$i) & ¶& \$stack );
\$i = \$i+1
]; RPN( exp )
) // end let
) // end if

) // end if

//============================

) // close let
```

This CF will allow you to evaluate an expression with Rerverse Polish Notation. Where entry detrmines order of operation, using a stack to push and pull from.

RPN input would be written : 10 25 2 * + 40 +
Infix input would be written : ((25 * 2) + 10) + 40

Edited by Ocean West

• 1
Report Function

## User Feedback

Posted · Report

reminds me of when I used to 'program' my HP48GX. Started with RPL.

## Create an account

Register a new account