substitute subexpressions into an expression - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Operations : Substitution : subs

subs - substitute subexpressions into an expression

Calling Sequence

subs(x=a,expr)

subs(s1,...,sn,expr)

subs[eval](x=a,expr)

subs[eval](s1,...,sn,expr)

subs[inplace](x=a,expr)

subs[inplace](s1,...,sn,expr)

Parameters

x

-

expression

a

-

expression

expr

-

expression

s1, ..., sn

-

equations, or sets or lists of equations

Description

• 

The first form of the subs command substitutes a for x in the expression expr. Note that this command is similar to the eval command. Simple applications of replacing a symbol by a value in a formula should normally be done with the eval command. Differences between the two commands are highlighted in the examples later.

• 

The second general form of the subs command makes the substitutions specified by first arguments in the last argument expr. Each of s1, ..., sn must be an equation or a list or set of equations. The substitutions are performed sequentially starting with s1. The substitutions within a set or list are performed simultaneously; if there are multiple substitutions on the same name, the first one is used.

• 

Every occurrence of the left-hand side of a substitution equation that appears in expr is replaced by the right-hand side of the equation. Note that only subexpressions in expr that correspond to operands (ops) of a Maple object are matched.  This is termed "syntactic substitution".  A more powerful substitution is available using the algsubs command.

• 

The inplace option only applies when substituting into an rtable (such as Array, Matrix, or Vector) with no indexing function. When inplace is specified, the input rtable is updated in-place.  The result is the updated original expr rtable, rather than a copy.

• 

The action of substitution is not followed by evaluation by default. There are two ways of achieving a full evaluation:

– 

The eval command also performs a full evaluation but takes care to delay substitutions which are not mathematically safe, as shown in the examples later.

– 

The eval option to subs performs a full evaluation while keeping the semantics the same as for subs. This option should be used with care.

• 

The options eval and inplace can be given together in the index as an expression sequence, and they can be specified in either order.

Thread Safety

• 

The subs command is thread-safe as of Maple 15.

• 

For more information on thread safety, see index/threadsafe.

Examples

subsx=2,x2+x+1

7

(1)

subsx=r13,3xlnx3

3r1/3lnr

(2)

subssinx=y,sinx1sinx

y1y

(3)

subsa+b=y,a+b+c2

a+b+c2

(4)

algsubsa+b=y,a+b+c2

y+c2

(5)

subsa2=y,a3

a3

(6)

algsubsa2=y,a3

ya

(7)

subsx=y,y=x,x,y

x,x

(8)

The substitutions within a set or list are performed simultaneously,

subsx=y,y=x,x,y

y,x

(9)

subsx=y,y=x,x,y

y,x

(10)

If there are multiple substitutions on the same name, the first one is used.

subsx=0,x=2,ⅇx

ⅇ0

(11)

simplify

1

(12)

subsy=0,siny

sin0

(13)

subsevaly=0,siny

0

(14)

sinyy=0|sinyy=0

0

(15)

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.)

p:=piecewisex=0,1,sinxx

p:={1x=0sinxxotherwise

(16)

subsx=0,p

Error, numeric exception: division by zero

subsevalx=0,p

Error, numeric exception: division by zero

px=0|px=0

1

(17)

Here is an example where subs[eval] is more effective than eval (since eval sometimes delays substitutions which involve dummy variables):

∫sfxⅆxs=signumfx|∫sfxⅆxs=signumfx

∫sfxⅆxs=signumfx|∫sfxⅆxs=signumfx

(18)

subsevals=signumfx,∫sfxⅆx

∫signumfxfxⅆx

(19)

See Also

algsubs, applyrule, eval, limit, op, subsop


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam