define
define characteristics of an operator name
Calling Sequence
Parameters
Description
Rules
Examples
define(oper, rule1, rule2, ...)
definemore(oper, rule1, rule2, ...)
undefine(oper)
redefine(oper, rulelist)
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
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.
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 ⅆⅆxF⁡x=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 undefine⁡F. (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.
define⁡f,linear,f⁡1=tt
f⁡2⁢x+4
2⁢f⁡x+4⁢tt
define⁡g,g⁡a::nonunit⁡algebraicn::nonunit⁡integer=n⁢g⁡a,g⁡a::realcons=a
g⁡x2
2⁢g⁡x
g⁡x−2−1
−g⁡x−2
g⁡π⁢sqrt⁡2
π⁢2
Define a commutative and associative operation.
define⁡h,orderless,flat
h⁡a,b−h⁡b,a
0
h⁡a,h⁡b,c−h⁡h⁡a,b,c
You can use define to program recursive procedures.
define⁡fac,fac⁡0=1,fac⁡n::posint=n⁢fac⁡n−1
fac⁡5
120
define⁡fib,fib⁡0=1,fib⁡1=1,fib⁡n::posint=fib⁡n−1+fib⁡n−2
fib⁡7
21
define⁡H,multilinear
H⁡2⁢x,x+3
2⁢H⁡x,x+6⁢H⁡x,1
definemore⁡H,orderless,H⁡a::realcons,b::algebraic=a⁢H⁡b
2⁢H⁡x,x+6⁢H⁡x
An example of programming a one-line GCD.
define⁡GCD,GCD⁡a::integer,0=a,GCD⁡a::integer,b::integer=GCD⁡b,amodb
GCD⁡6,3
3
GCD⁡120,12⋅120
GCD⁡13,11
1
The identity property can be used to define a monoid operation.
define⁡`&x`,flat,identity=1
a&xb&xc
&x⁡a,b,c
a&x1
a
1&xb
b
A simple integrator can be defined as follows.
define⁡INT,linear,conditional⁡INT⁡a::algebraic,X::name=a⁢X,_type⁡a,freeof⁡X,INT⁡X::name,X::name=X22
This definition works for any variable.
INT⁡2⁢x+4,x
x2+4⁢x
INT⁡3⁢z−π,z
32⁢z2−π⁢z
Use definemore to improve the integrator.
definemore⁡INT,conditional⁡INT⁡1a::algebraic⁢X::name+b::algebraic,X::name=ln⁡a⁢X+b,_type⁡a,freeof⁡X&and_type⁡b,freeof⁡X
INT⁡1x,x
ln⁡x
INT⁡12⁢x+3,x
ln⁡2⁢x+3
definemore⁡INT,INT⁡x::namen::nonunit⁡integer,x::name=1n+1⁢xn+1
INT⁡2⁢x2,x
2⁢x33
definemore⁡INT,conditional⁡INT⁡sin⁡a::algebraic⁢X::name+b::algebraic,X::name=−1a⁢cos⁡a⁢x+b,_type⁡a,freeof⁡X&and_type⁡b,freeof⁡X
Note: If INT does not recognize the pattern, it returns unevaluated.
INT⁡sin⁡x+cos⁡x,x
−cos⁡x+INT⁡cos⁡x,x
The following example defined the procedure P by specifying its derivative.
define⁡P,diff⁡P⁡x,x=1P⁡x
diff⁡P⁡x,x
1P⁡x
diff⁡P⁡exp⁡z,z
ⅇzP⁡ⅇz
diff⁡1P⁡x2,x
−2⁢xP⁡x23
If the derivative is specified for a procedure defined using the linear property, then Maple can take advantage of this.
redefine⁡f,linear,diff⁡f⁡x,x=a
diff⁡f⁡x,x
f⁡0
int⁡f⁡x,x
x⁢f⁡x−x2⁢a2
int⁡exp⁡f⁡x,x
ⅇf⁡xa
int⁡f⁡sin⁡x,x
x⁢f⁡sin⁡x−a⁢cos⁡x+x⁢sin⁡x
limit⁡f⁡x,x=0
series⁡f⁡x,x=0
a⁢x+O⁡x6
Use undefine to completely remove the definition of a procedure defined using the define command.
undefine⁡f
ⅆⅆxf⁡x
limx→0⁡f⁡x
See Also
examples/define
neutral
operator
patmatch
procedure
unassign
undefined
Download Help Document