EXEC
programs checks the object type at stack level 1
and performs the corresponding action:
'objA=objB'
), replace objA
by objB
in stack2.
The syntax is 'old_name=expression' EXEC
. oldname
may
be a global name, an expression (in this case, the first global name
in this expression will be isolated) or a user-defined function.
'X^2+2*X+5' 'X=1' EXEC
: evaluate an expression at x=1.
'X=Y^2' EXEC
: change of variables, works in integrals too
'2*Z(X)-X*d1Z(X)' 'Z(X)=X^2 EXEC
:
in a differential equation, replace the function z(x) by x2.
'Z(X)+d1Z(X)' 'Z(X)=EXP(-X)*Y(X)' EXEC
: 'X^2+X*COS(X)' 'X^2=1-Y' EXEC
:
replace x2 by 1-y and replace
x by
.
{ old_name_1 ... old_name_n } { expr_1 ... expr_n } EXEC
EXEC
does only substitutions.
'SIN(X)^2+SIN(X)*COS(X)' { 'SIN(X)^2' } { '1-COS(X)^2' } EXEC
:
replace
by
but does not replace
by
.
'COS(X)+i*SIN(X)' { SIN COS } { << i * EXP DUP INV - i 2 * / >> << i * EXP DUP INV + 2 / >> } EXECreplace and by complex exponentials. If you call
EXPA
after you get eix.
EXEC
tries to isolate stack level 1 in stack level 2.
Example:
'X^2-5' X EXECreturns
'X='
.
EXEC
executes program at stack level 1 recursively on the components
of a list object at stack level 2. Example:
{ 1 2 3 } << NEG >> EXEC
{ 1 2 3 } CHS