Next: Differentiating a Function Up: Functions Previous: Functions

### Defining a Function

The following mathematical expression:

is implemented in Maxima as

There is a system call functions, which can be used to list all user defined functions:

Function F(x) can be now used like any other function, e.g, , or :

In Maple, symbol := is used for an assignment. In order to define a function Maple uses notation that is somewhat closer to the mathematical original with a arrow:

Maxima's := notation is a shorthand for calling a function define whose purpose is to define functions:

Maple, similarly, has a special form, unapply, which has the same effect as the combination of := and ->:

In Mathematica functions  are defined more like in Maxima. Here is an example:

Observe the underscore that follows x in F[x_]. The underscore tells Mathematica that x in the expression on the right is to be understood as a formal parameter, as in .

We can also use the delayed  Set, denoted by :=, while defining a function, although, in this case, it wouldn't make much difference, because the expression x^2 + 1/2 cannot be evaluated any further.

As in Maxima and in Maple, there is a system utility in Mathematica too, called Function, which can be used to define a function. Here is an example of how it works.

Observe the ?g trick. By placing the question mark in front of a symbol, you can always ask Mathematica how it understands the symbol. We have used it already before when we asked Mathematica about delayed expressions. In this case function g is not stored in the same way as function f, even though they have the same effect on their arguments. It is stored as a lambda-expression instead. If you are familiar with Lisp or lambda calculus, you will find it quite natural to think about functions this way.

The definitions of a function in Maxima, Maple and Mathematica suffer from imprecision. In real mathematics we would usually specify precisely a set that x belongs to, as well as a set that the values of F belong to, e.g.,

Not being able to convey this to symbol manipulation environments discussed in this tutorial may sometimes lead to incorrect results. Having a slave that does all the algebra for you does not release you from having to think about what you do.

We will see later on that there are ways to restrict x to certain ranges in this context.

Next: Differentiating a Function Up: Functions Previous: Functions
Zdzislaw Meglicki
2001-02-26