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

Online Help

All Products    Maple    MapleSim


define

define characteristics of an operator name

 

Calling Sequence

Parameters

Description

Rules

Examples

Calling Sequence

define(oper, rule1, rule2, ...)

definemore(oper, rule1, rule2, ...)

undefine(oper)

redefine(oper, rulelist)

Parameters

oper

-

name of the operator being defined

rule1, rule2, ...

-

one or more key names of a property, or an equation that defines a rule

rulelist

-

list; a list of equational rules, or property keywords

Description

• 

The define command defines procedures by means of rules. To define a procedure by using the define command, you specify the name of the procedure and rules that it must obey using the syntax of patmatch. The left-hand side of each defining equation must contain the name of the defined procedure. In addition, there are several property names that can be used as abbreviations for common constructions.

• 

The name passed as the first argument to define must not be assigned. Therefore, to change the definition of a procedure defined using define use instead the redefine command, described below.

• 

A procedure defined using define can be specialized further, adding more rules and properties to its definition, by using the definemore command. Its syntax is the same as for the define command, but the rules or properties are added to the definition of the defined procedure rather than replacing them.

• 

The define command is not able in all cases to detect if some rules are contradictory, or may result in a non-terminating program.

• 

A procedure defined using define does not automatically respect assumptions. However, you can use assumptions within a conditional pattern.

Rules

• 

A rule can be an equational rule specified using the syntax of patmatch, or one of the reserved words linear, multilinear, orderless, flat, identity, zero, and diff, which name a property. The meanings of these reserved words are as follows.

• 

The linear property causes the defined procedure to be linear in its first argument.

• 

The multilinear property causes the defined procedure to be a multilinear function, that is, it is linear in each argument, independently.

• 

The orderless property causes the defined procedure to be constant on permutations of its arguments. For two-argument procedures, this corresponds to commutativity.

• 

The flat property causes the defined procedure to be associative.

• 

The identity property is used to name an identity element for a two-argument procedure (or binary operation). It is used by specifying an equation of the form identity=EXPR, where EXPR is the expression that is to serve as an identity element.

• 

The zero option is used to specify a zero of the defined procedure. It is used by specifying an equation of the form zero=EXPR, where EXPR is the expression that is to be a zero of the defined procedure.

• 

The rules defining a procedure may include the specification of the derivative of the defined procedure. If the procedure name being defined is F, then its derivative must be specified in the form ⅆⅆxFx=EXPR, where EXPR is an expression (which may depend on x) for the derivative of F.

• 

If a function F has been created with define, you can remove its definition by calling undefineF. (In many cases, simply unassign F will suffice, but in general, undefine must be used.)

• 

A function name can be changed by using the redefine command. It takes exactly two arguments: the name of the function to be redefined, and a list of the defining properties that would be passed as subsequent arguments to define in a fresh definition.

Examples

definef,linear,f1=tt

f2x+4

2fx+4tt

(1)

defineg,ga::nonunitalgebraicn::nonunitinteger=nga,ga::realcons=a

gx2

2gx

(2)

gx21

gx2

(3)

gπsqrt2

π2

(4)

Define a commutative and associative operation.

defineh,orderless,flat

ha,bhb,a

0

(5)

ha,hb,chha,b,c

0

(6)

You can use define to program recursive procedures.

definefac,fac0=1,facn::posint=nfacn1

fac5

120

(7)

definefib,fib0=1,fib1=1,fibn::posint=fibn1+fibn2

fib7

21

(8)

defineH,multilinear

H2x,x+3

2Hx,x+6Hx,1

(9)

definemoreH,orderless,Ha::realcons,b::algebraic=aHb

H2x,x+3

2Hx,x+6Hx

(10)

An example of programming a one-line GCD.

defineGCD,GCDa::integer,0=a,GCDa::integer,b::integer=GCDb,amodb

GCD6,3

3

(11)

GCD120,12120

120

(12)

GCD13,11

1

(13)

The identity property can be used to define a monoid operation.

define`&x`,flat,identity=1

a&xb&xc

&xa,b,c

(14)

a&x1

a

(15)

1&xb

b

(16)

A simple integrator can be defined as follows.

defineINT,linear,conditionalINTa::algebraic,X::name=aX,_typea,freeofX,INTX::name,X::name=X22

This definition works for any variable.

INT2x+4,x

x2+4x

(17)

INT3zπ,z

32z2πz

(18)

Use definemore to improve the integrator.

definemoreINT,conditionalINT1a::algebraicX::name+b::algebraic,X::name=lnaX+b,_typea,freeofX&and_typeb,freeofX

INT1x,x

lnx

(19)

INT12x+3,x

ln2x+3

(20)

definemoreINT,INTx::namen::nonunitinteger,x::name=1n+1xn+1

INT2x2,x

2x33

(21)

INT1x,x

lnx

(22)

definemoreINT,conditionalINTsina::algebraicX::name+b::algebraic,X::name=1acosax+b,_typea,freeofX&and_typeb,freeofX

Note: If INT does not recognize the pattern, it returns unevaluated.

INTsinx+cosx,x

cosx+INTcosx,x

(23)

The following example defined the procedure P by specifying its derivative.

defineP,diffPx,x=1Px

diffPx,x

1Px

(24)

diffPexpz,z

ⅇzPⅇz

(25)

diff1Px2,x

2xPx23

(26)

If the derivative is specified for a procedure defined using the linear property, then Maple can take advantage of this.

redefinef,linear,difffx,x=a

difffx,x

a

(27)

f0

0

(28)

intfx,x

xfxx2a2

(29)

intexpfx,x

ⅇfxa

(30)

intfsinx,x

xfsinxacosx+xsinx

(31)

limitfx,x=0

0

(32)

seriesfx,x=0

ax+Ox6

(33)

Use undefine to completely remove the definition of a procedure defined using the define command.

undefinef

difffx,x

ⅆⅆxfx

(34)

limitfx,x=0

limx0fx

(35)

See Also

examples/define

neutral

operator

patmatch

procedure

unassign

undefined