Define
With the define command, evaluation and simplification properties for functions and operators can be defined. Properties are specified by both keywords and by equations that use the syntax of the pattern matcher (patmatch command). The define command then creates a procedure that implements the function and its properties.
Note that properties are used in the order that they are given; therefore, if one pattern is more general than the other, it has to be specified first: for example, f(x)=x should be defined before
>
|
|
|
First Examples
|
|
In the first example, we use the keyword linear:
>
|
|
>
|
|
| (1.1) |
>
|
|
>
|
|
| (1.2) |
>
|
|
| (1.3) |
To define commutative and associative operations, use the keywords orderless and flat. orderless means that the arguments of a function have no order, and flat means that f(a,f(b,c)) is equal to f(a,b,c).
>
|
|
>
|
|
| (1.4) |
>
|
|
| (1.5) |
One can use define for functional programming:
>
|
|
>
|
|
| (1.6) |
>
|
|
>
|
|
| (1.7) |
>
|
|
| (1.8) |
A nice way to define the greatest common divisor of integers:
>
|
|
>
|
|
| (1.9) |
>
|
|
| (1.10) |
>
|
|
| (1.11) |
The keyword multilinear can be used to define multilinear functions:
>
|
|
>
|
|
| (1.12) |
Now we use the definemore command to add to the existing definition of H the rule of commutativity (keyword orderless), and a simplification rule for some special arguments:
>
|
|
>
|
|
| (1.13) |
>
|
|
| (1.14) |
|
|
Further Examples
|
|
Define an integration procedure: integration is linear, equals when a does not depend on .
>
|
|
>
|
|
| (2.1) |
>
|
|
| (2.2) |
We now define the integral of :
>
|
|
>
|
|
| (2.3) |
>
|
|
| (2.4) |
And now the integral for powers of :
>
|
|
>
|
|
| (2.5) |
>
|
|
| (2.6) |
An example with the keyword diff and the command diff :
We define the derivative of to be :
>
|
|
>
|
|
| (2.7) |
>
|
|
| (2.8) |
>
|
|
| (2.9) |
Define properties of a function which is linear, has a derivative of , and for which .
>
|
|
>
|
|
Check the derivative of :
>
|
|
| (2.10) |
Given that is linear:
>
|
|
| (2.11) |
Now Maple can compute the following integral using the fact that is linear and has derivative :
>
|
|
| (2.12) |
Even nested functions with can be integrated:
>
|
|
| (2.13) |
>
|
|
| (2.14) |
Since the derivative is given, we can compute limit and series:
>
|
|
| (2.15) |
>
|
|
| (2.16) |
|
|
An Example with an Infix Operator
|
|
Using the neutral operator &m, we define:
>
|
|
| (3.1) |
>
|
|
| (3.2) |
We can add more properties:
>
|
|
| (3.3) |
>
|
|
| (3.4) |
>
|
|
|
The syntax for define is described in the help page of define, while the syntax for patterns is described in the help page of patmatch.
Return to Example Worksheets Index
|
Download Help Document
Was this information helpful?