Examples showing simple substitution of the form x=a for an expression expr.
>
|
|
>
|
|
The following examples show the difference between subs and algsubs, where the algsubs command substitutes subexpressions into an expression.
>
|
|
>
|
|
The substitutions within a set or a list are performed simultaneously.
>
|
|
>
|
|
Substitutions can be specified using a table.
>
|
|
When the substitutions are in a sequence, they are applied one at a time, akin to the following:
>
|
|
>
|
|
If there are multiple substitutions on the same expression, the first one is used.
>
|
|
If there are substitutions on both an expression and subexpressions thereof, the former is used.
>
|
|
As shown in the following example, evaluation does not follow substitution by default.
The option eval for subs can be used to perform a full evaluation while not altering the semantics for subs.
>
|
|
Alternatively, you can use the eval command:
The following calls to subs and subs[eval] will return an error since Maple does simultaneous substitution in all parameters. (However, eval will work correctly.)
>
|
|
| (20) |
Here is an example where subs[eval] is more effective than eval (since eval sometimes delays substitutions which involve dummy variables):
>
|
|
| (22) |
>
|
|
| (23) |
This example performs a substitution in-place. Notice that myVec is changed after calling subs[inplace].
>
|
|
>
|
|
Using the member option limits substitutions to the immediate entries of a container expresssion:
>
|
|
subs will descend into procedures, whereas eval will not.
>
|
subs(a=b,[a, proc(x) x+a end]);
|
| (28) |
>
|
eval([a, proc(x) x+a end],a=b);
|
| (29) |