evalindets - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


evalindets

transform all subexpressions of a given type

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

evalindets( expr, atype, transformer, rest )

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

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

evalindets[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; 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 command evalindets is a particular combination of calls to eval 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 eval, with the corresponding transformed expression.

• 

If the flat option is supplied as an index to the evalindets 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.

• 

If the flat option is not supplied, then subexpressions of type atype at deeper levels of nesting are processed and replaced before subexpressions at shallower levels of nesting. This is illustrated in an example below.

• 

By default, evalindets 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 evalindets 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 evalindets on expressions containing many common subexpressions.

• 

If evalindets 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 evalindets between atype and transformer will be passed as the first N-1 arguments to transformer.

• 

A numeric index may be combined with the flat option, and they can be specified in either order.

Examples

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

evalindetsFGx,Fx,y,specfuncanything,F,fsubsop0=H,f

HGx,Hx,y

(1)

evalindetsflatF2.3+G4,1.1,float,trunc

F2+G4,1

(2)

evalindetsflatFGx,Fx,y,specfuncanything,F,fsubsop0=H,f

HGx,Fx,y

(3)

evalindetsFGx,Fx,y,specfuncsymbol,F,fsubsop0=H,f

FGx,Hx,y

(4)

Shift all symbols by a constant of π.

evalindetssinx,cosy,tanz,symbol,yy+π

sinx,cosy,tanz

(5)

Expand all products in an expression.

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

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

(6)

evalindetsexpr,`*`,expand

sinx+y+2x2+4x+2

(7)

expandexpr

sinxcosy+cosxsiny+2x2+4x+2

(8)

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

evalindetssin3+Iπ+x+y100,sinanything,expand

Isinhπ+x+y100

(9)

Optional arguments may be passed to the transformer.

exprsinx+y+xx+3+expx+1y+2

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

(10)

evalindetsexpr,`*`,expand

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

(11)

evalindetsexpr,`*`,expand,exp

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

(12)

The following example demonstrates the use of evalindets[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:

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

x12+3x1+fx1

(13)

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:

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

x12+3x2+fx3

(14)

The following example demonstrates the use of evalindets[N]

The evalindets[N] calling sequence is used when you want to pass additional arguments to the transformer function before the subexpression to be transformed:

exprfx,y2+3fx,y+3;evalindets2expr,specfuncf,1,op

exprfx,y2+3fx,y+3

x2+3x+3

(15)

This calls op(1,x) for each subexpression, x of type specfunc(f).

Without the [N] option, the alternative would be to introduce a procedure that takes a single argument x, and returns op(1,x):

evalindetsexpr,specfuncf,xop1,x

x2+3x+3

(16)

This is less efficient because of the extra level of procedure calling. The evalindets command calls your procedure which calls op, instead of just calling op directly.

This example illustrates the remark above about the order in which subexpressions at various levels of nesting depth are processed. In it, we replace each integer in the expression that occurs inside a function call with a name that indicates the name of the closest enclosing function. This is done by using a second call to evalindets as the transformer.

expr2+f4,gh6

expr2+f4,gh6

(17)

evalindetsexpr,function,fnevalindetsfn,integer,icati, in ,op0,fn

2+f4 in f,gh6 in h

(18)

This works because the outer call to evalindets processes h(6) (turning it into h(`6 in f`)) before it processes the calls to g or f; so when the transformer processes those calls, the integer 6 doesn't occur anymore.

Compatibility

• 

The evalindets command was updated in Maple 2015.

• 

The N parameter was introduced in Maple 2015.

• 

The preargs parameter was updated in Maple 2015.

• 

The nocache option was introduced in Maple 2015.

• 

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

See Also

eval

frontend

indets

subs

subsindets

type