define - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Operations : Operators : Defining : define

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π2

π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 &x b &x c

&xa,b,c

(14)

a &x 1

a

(15)

1 &x b

b

(16)

A simple integrator can be defined as follows.

defineINT,'linear','conditional'INTa::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,'conditional'INT1a::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=1xn+1n+1

INT2x2,x

23x3

(21)

INT1x,x

lnx

(22)

definemoreINT,'conditional'INTsina::algebraicX::name+b::algebraic,X::name=1cosax+ba,_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,ⅆⅆxPx=1Px

ⅆⅆxPx

1Px

(24)

ⅆⅆzPⅇz

ⅇzPⅇz

(25)

ⅆⅆx1Px2

2xPx23

(26)

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

redefinef,linear,ⅆⅆxfx=a

ⅆⅆxfx

a

(27)

f0

0

(28)

∫fxⅆx

xfx12x2a

(29)

∫ⅇfxⅆx

ⅇfxa

(30)

∫fsinxⅆx

xfsinxacosx+xsinx

(31)

limx→0fx

0

(32)

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

undefinef

ⅆⅆxfx

ⅆⅆxfx

(33)

limx→0fx

limx→0fx

(34)

See Also

neutral

operator

patmatch

procedure

unassign

undefined