Advice: Defining functions

Here is a correct way of defining a function:

> f:= x -> x^2 + 1;

[Maple Math]

You can then evaluate such a function with a constant or variable argument:

> f(u);

[Maple Math]

> f(3);

[Maple Math]

On the other hand, the following defines an expression rather than a function:

> g:= x^2 + 1;

[Maple Math]

This is no problem if that's what you wanted, but functions and expressions are used in different ways. In particular, you get a strange-looking result if you try to evaluate g as you would a function:

> g(u);

[Maple Math]

In order to evaluate g for some value of x , you must use subs .

> subs(x=u, g);

[Maple Math]

Since in ordinary mathematics we often speak of "the function [Maple Math] ", a common beginner's mistake is to define f(x) instead of defining f .

> h(x):= x^2 + 1;

[Maple Math]

Beware! Everything seems fine, as long as you use only h(x) . But when you try to use h with some other argument, it appears to be undefined:

> h(u);

[Maple Math]

This is not surprising, since in fact it is only h(x) , and not h of anything else, that you have defined.

There is a legitimate use of such a construction (it places a value in the remember table of h ).

See also: function , remember , subs

Maple Advisor Database R. Israel, 1997