Sponsored links: Algebra eBooks ### The Maxima on-line user's manual

Algebra Calculator

#### Search: #### Define

Function: define (<f>(<x_1>, ..., <x_n>), <expr>) Function: define (<f>[<x_1>, ..., <x_n>], <expr>)

Function: define (funmake (<f>, [<x_1>, ..., <x_n>]), <expr>)

Function: define (arraymake (<f>, [<x_1>, ..., <x_n>]), <expr>)

Function: define (ev (<expr_1>), <expr_2>) Defines a function named <f> with arguments <x_1>, ..., <x_n> and function body <expr>. `define` always evaluates its second argument (unless explicitly quoted). The function so defined may be an ordinary Maxima function (with arguments enclosed in parentheses) or an array function (with arguments enclosed in square brackets).

When the last or only function argument <x_n> is a list of one element, the function defined by `define` accepts a variable number of arguments. Actual arguments are assigned one-to-one to formal arguments <x_1>, ..., <x_(n - 1)>, and any further actual arguments, if present, are assigned to <x_n> as a list.

When the first argument of `define` is an expression of the form `<f>(<x_1>, ..., <x_n>)` or `<f>[<x_1>, ..., <x_n>]`, the function arguments are evaluated but <f> is not evaluated, even if there is already a function or variable by that name.

When the first argument is an expression with operator `funmake`, `arraymake`, or `ev`, the first argument is evaluated; this allows for the function name to be computed, as well as the body.

All function definitions appear in the same namespace; defining a function `f` within another function `g` does not automatically limit the scope of `f` to `g`. However, `local(f)` makes the definition of function `f` effective only within the block or other compound expression in which `local` appears.

If some formal argument <x_k> is a quoted symbol (after evaluation), the function defined by `define` does not evaluate the corresponding actual argument. Otherwise all actual arguments are evaluated.

See also `:=` and `::=`.

Examples:

`define` always evaluates its second argument (unless explicitly quoted).

```          (%i1) expr : cos(y) - sin(x);
(%o1)                    cos(y) - sin(x)
(%i2) define (F1 (x, y), expr);
(%o2)              F1(x, y) := cos(y) - sin(x)
(%i3) F1 (a, b);
(%o3)                    cos(b) - sin(a)
(%i4) F2 (x, y) := expr;
(%o4)                   F2(x, y) := expr
(%i5) F2 (a, b);
(%o5)                    cos(y) - sin(x)```

The function defined by `define` may be an ordinary Maxima function or an array function.

```          (%i1) define (G1 (x, y), x.y - y.x);
(%o1)               G1(x, y) := x . y - y . x
(%i2) define (G2 [x, y], x.y - y.x);
(%o2)                G2     := x . y - y . x
x, y```

When the last or only function argument <x_n> is a list of one element, the function defined by `define` accepts a variable number of arguments.

```          (%i1) define (H ([L]), (apply ("+", L)));
(%o1)                H([L]) := apply("+", L)
(%i2) H (a, b, c);
(%o2)                       c + b + a```

When the first argument is an expression with operator `funmake`, `arraymake`, or `ev`, the first argument is evaluated.

```          (%i1) [F : I, u : x];
(%o1)                        [I, x]
(%i2) funmake (F, [u]);
(%o2)                         I(x)
(%i3) define (funmake (F, [u]), cos(u) + 1);
(%o3)                  I(x) := cos(x) + 1
(%i4) define (arraymake (F, [u]), cos(u) + 1);
(%o4)                   I  := cos(x) + 1
x
(%i5) define (foo (x, y), bar (y, x));
(%o5)                foo(x, y) := bar(y, x)
(%i6) define (ev (foo (x, y)), sin(x) - cos(y));
(%o6)             bar(y, x) := sin(x) - cos(y)```

There are also some inexact matches for `define`. Try `?? define` to see them.

```(%o1)                                true
(%i2) ```

### Related Examples

kill(all);

a:0;

b:8;

Calculate

##### define-log-sqrt

define(blackCall(S0,T...

Calculate

##### define-diff-plot2d h: 5.2981 ;

f(x) := (-6*5.2981+8*...

define(d(x), diff(f(x...

Calculate

##### define-realroots

define (p(x), 3*x^4 +...

p(-3);

realroots (p(x));

Calculate

##### define-diff-log-sin

define (f(x), log(x^2...

define (fp(x), diff(f...

Calculate

##### define-sin

define(f(x),x*sin(3*x...

f(1);

Calculate

a: -1;

b: 5;

h: b-a;

Calculate

##### define-diff

f(x):=x^3;

define(g(x),diff(f(x)...

g(3);

Calculate

##### define-expand

define (T13(t1), (1-t...

define (T12(t1), 3*t1...

define (T11(t1), 3*t1...

Calculate

##### define-diff

f(x,y):=x^2-y^2;

define(f1(x,y),diff(f...

define(f2(x,y),diff(f...

Calculate 