subsindets - Maple Programming Help

Online Help

All Products    Maple    MapleSim


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

subsindets

transform all subexpressions of a given type

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

subsindets( expr, atype, transformer, rest )

subsindets[eval]( expr, atype, transformer, rest )

subsindets[flat]( expr, atype, transformer, rest )

subsindets[nocache]( expr, atype, transformer, rest )

subsindets[N]( expr, atype, preargs, transformer, rest )

Parameters

expr

-

anything; any Maple expression

atype

-

type; any Maple type expression

transformer

-

anything; an expression (typically, a procedure) to be called on each subexpression processed

rest

-

anything; (optional) expression sequence of extra arguments to be passed to transformer

N

-

integer; one more than the number of arguments passed to the transformer before the subexpression

preargs

-

anything; expression sequence of N-1 arguments to be passed to the transformer before the subexpression

Description

• 

The procedure subsindets is a particular combination of calls to subs and indets that allows you to efficiently transform all subexpressions of a given type by some algorithm. It encapsulates a common "pattern" used in expression manipulation and transformation.

• 

Each subexpression of type atype is transformed by the supplied transformer procedure. Then, each subexpression is replaced in the original expression, using subs (or subs[eval], if the eval option is given), with the corresponding transformed expression.

• 

If the flat option is supplied as an index to the subsindets command, then Maple will not recursively look inside any subexpressions of the given atype for further (nested) subexpressions of that type. This provides a hint to Maple that it can use a somewhat faster algorithm in this special case.

• 

By default, subsindets uses a cache to avoid repetitive type checking and repeated calls to transformer for multiple instances of the same subexpression (this cache is limited in size, so repeated calls may occur, but there is no guarantee that they will). The nocache option, specified as an index to the subsindets command, prevents the use of this cache and guarantees that transformer will be called once for each instance of any common subexpression matching atype. Note that using the nocache option can dramatically lower the performance of subsindets on expressions containing many common subexpressions.

• 

If subsindets is called with an integer index, N, then each subexpression to be processed by transformer will be passed as the N-th argument to transformer. The sequence of N-1 arguments of subsindets between atype and transformer will be passed as the first N-1 arguments to transformer.

• 

Any number of the options eval, flat, nocache, and N can be given in the index as an expression sequence, and they can be specified in any order.

Examples

This example changes every call to F to a call to H.

subsindetsFGx,Fx,y,'specfuncanything,F',f→subsop0=H,f

HGx,Hx,y

(1)

subsindets[flat]F2.3+G4,1.1,'float',trunc

F2+G4,1

(2)

subsindets[flat]FGx,Fx,y,'specfuncanything,F',f→subsop0=H,f

HGx,Fx,y

(3)

subsindetsFGx,Fx,y,'specfuncsymbol,F',f→subsop0=H,f

FGx,Hx,y

(4)

Shift all symbols by a constant of π.

subsindetssinx,cosy,tanz,'symbol',y→y+π

sinx+π,cosy+π,tanz+π

(5)

Expand all products in an expression.

exprsinx+y+xx+1+x+1x+2

expr:=sinx+y+xx+1+x+1x+2

(6)

subsindetsexpr,'`*`',expand

sinx+y+2x2+4x+2

(7)

expandexpr

sinxcosy+cosxsiny+2x2+4x+2

(8)

Using subsindets, you can avoid expanding things you might not want expanded.

subsindetssin3+Iπ+x+y100,'sinanything',expand

Isinhπ+x+y100

(9)

Optional arguments may be passed to the transformer.

exprsinx+y+xx+3+ⅇx+1y+2

expr:=sinx+y+xx+3+ⅇx+1y+2

(10)

subsindetsexpr,'`*`',expand

sinx+y+x2+3x+ⅇxⅇy+2ⅇxⅇ

(11)

subsindetsexpr,'`*`',expand,exp

sinx+y+x2+3x+ⅇx+1y+2ⅇx+1

(12)

expra,b,3,4,c

expr:=a,b,3,4,c

(13)

subsindetsexpr,symbol,`^`,x

ax,bx,3,4,cx

(14)

subsindets[2]expr,symbol,x,`^`

xa,xb,3,4,xc

(15)

The following example demonstrates the use of subsindets[nocache]

In this first case, without nocache, the transformer function will be called at least once, and most likely only once, though this is not guaranteed, for each matching subexpression:

exprx2+3x+fx:

count0:

subsindets(expr,symbol,proc(s) global count; count:=count+1; cat(s,count) end);

x12+3x1+fx1

(16)

In this next case, with the nocache option, the transformer function is guaranteed to be called once for every instance of each matching subexpression:

count0:

subsindents['nocache'](expr,symbol,proc(s) global count; count:=count+1; cat(s,count) end);

subsindentsnocachex2+3x+fx,symbol,procsglobalcount;count:=count+1;cats,countend proc

(17)

Compatibility

• 

The subsindets command was updated in Maple 2015.

• 

The N parameter was introduced in Maple 2015.

• 

The eval and nocache options were introduced in Maple 2015.

• 

For more information on Maple 2015 changes, see Updates in Maple 2015.

See Also

eval

evalindets

frontend

indets

subs

type

 


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