Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Evaluating symbolics

22 views
Skip to first unread message

Luis Baptista

unread,
Jan 14, 2001, 8:57:14 PM1/14/01
to
Hello,

Sometimes we need to evaluate a symbolic using data entered by the user
in a SysRPL program. One of the ways to do this is store the entered
objects in global names and then CRUNCH the symbolic. Although there is
a command called REPLACE that is fast , the process of creating the
global vars is relatively slow, specially if the number of vars is big.
There is a more efficient way to acomplish this. The trick consists in
replacing all the ID's with nulllam's and convert the symbolic into a
secondary. Assuming that level 1 of the stack contains a symbolic
( 'X+2*Y' used in this example ), the program looks like this:


::
{ 1GETLAM 2GETLAM ... 22GETLAM } ( symb lamlist )
SWAP ( lamlist symb )
DUPLENCOMP ( lamlist symb symb_lenght )
SWAPDUP ( lamlist symb_lenght symb symb )
FINDVARS ( lamlist symb_lenght symb symb_vars )
SWAP ( lamlist symb_lenght symb_vars symb )
>R ( lamlist symb_lenght symb_vars )
ticR
DROP
BEGIN
DUPTYPEIDNT?
IT
::
OVERSWAP
EQUALPOSCOMP
4PICKSWAP
NTHCOMPDROP
;
4UNROLL
RSWAP
ticR
WHILE
RSWAP
REPEAT
ROT2DROP
::N
;

So, for the 'X+2*Y' symb, the result is:

::
1GETLAM
%2
2GETLAM
x*
x+
;

The stack diagram is indicated for the first part of the program, in
order to understand the rest of the prog.

The symbolic process routine was taken from a post by Werner Huysegoms,
I think he don't mind that i use it! :-) ( see his post for a remark
regarding the compilation of the program )

The "important" part of the algorithm is very simple: check if the
object is an ID and, if it is, get it's position in the var list and
pick the respective nulllam from the lam list.

All you have to do now is store the values in the nulllam's and
EVALuate the secondary.

If you need some nulllams to use in your program, just begin the
lamlist with "higher" lams. ( example : { 3GETLAM ... } if you need to
use two nulllam's for something ) And don't forget that nulllam BINDing
reverses the stack order.

The only problem is that we are limitated to 22 nulllam's, but i think
this is enough! :-) ( using this program, of course... For more than 22
nulllam's, the program would look different )

I hope this can be useful to someone...

Thanks,

Luis Baptista


Sent via Deja.com
http://www.deja.com/

Jean-Yves Avenard

unread,
Jan 14, 2001, 11:24:33 PM1/14/01
to
Hello

And there is even easier way to do it as the CAS provide such entry points.
PLus the entry point will also simplify the equation and will go inside
embedded algebraic and will include it inside the main algebraic.

Easy syntax:

3: Algebraic
2: { list of variables to be replaced }
1: { list of what will be replaced with }

SimplifyExpression

SimplifyExpression is making use of FLASHPTR CASNUMEVAL which takes eaxctly
the same arguments.
SimplifyExpression will also save the flags and restore them at the end of
the process (so the CAS won't have any effect on the settings) and will also
tell the system not to evaluate UserFonction.

In your example, you would do:
3: 'X+2*Y'
2: { ID X ID Y }
1: { 1GETLAM 2GETLAM }

SimplifyExpression -> ' 1GETLAM %2 2GETLAM x* x+ '

Then simply run COMPEVAL on it...
Jean-Yves

Jean-Yves

"Luis Baptista" <luisba...@net.sapo.pt> wrote in message
news:93tldn$cin$1...@nnrp1.deja.com...


> Hello,
>
> Sometimes we need to evaluate a symbolic using data entered by the user
> in a SysRPL program. One of the ways to do this is store the entered
> objects in global names and then CRUNCH the symbolic. Although there is
> a command called REPLACE that is fast , the process of creating the
> global vars is relatively slow, specially if the number of vars is big.
> There is a more efficient way to acomplish this. The trick consists in
> replacing all the ID's with nulllam's and convert the symbolic into a
> secondary. Assuming that level 1 of the stack contains a symbolic
> ( 'X+2*Y' used in this example ), the program looks like this:
>
>

[...] source deleted

Luis Baptista

unread,
Jan 14, 2001, 11:54:42 PM1/14/01
to
What a mess!!!!
No comments, looks better...

::
{ 1GETLAM 2GETLAM ... 22GETLAM }
SWAP
DUPLENCOMP
SWAPDUP
FINDVARS
SWAP
>R


ticR
DROP
BEGIN
DUPTYPEIDNT?
IT
::
OVERSWAP
EQUALPOSCOMP
4PICKSWAP
NTHCOMPDROP
;
4UNROLL
RSWAP
ticR
WHILE
RSWAP
REPEAT
ROT2DROP
::N
;

LB

Luis Baptista

unread,
Jan 15, 2001, 12:00:13 AM1/15/01
to
"Jean-Yves Avenard" <aven...@epita.fr> wrote:
> Hello
>
> And there is even easier way to do it as the CAS provide such entry
points.

I forgot to tell that my program was intended to use in HP48.

LB

Luis Baptista

unread,
Jan 15, 2001, 12:06:26 AM1/15/01
to
"Jean-Yves Avenard" <aven...@epita.fr> wrote:

> In your example, you would do:
> 3: 'X+2*Y'
> 2: { ID X ID Y }
> 1: { 1GETLAM 2GETLAM }
>
> SimplifyExpression -> ' 1GETLAM %2 2GETLAM x* x+ '

And what happens if the symbolic contains 30 ID's? ( unrealistic!?!? )
In that situation how would the nulllam list look like?

LB

Jean-Yves Avenard

unread,
Jan 15, 2001, 6:09:34 AM1/15/01
to
Hello

You specify what you want to replace with what. So there's no such issue as
you're describing. It's up to the programmer to decide what he wants to
replace

Jean-Yves

"Luis Baptista" <luisba...@net.sapo.pt> wrote in message

news:93u0gg$l5a$1...@nnrp1.deja.com...

0 new messages