defcon SciMax Toolbox define_variable

SciMax Toolbox >> define

define

Maxima Function

Calling Sequence

define (f(x_1, ..., x_n), expr)
define(f[x_1,...,x_n],expr)
define(funmake(f,[x_1,...,x_n]),expr)
define(arraymake(f,[x_1,...,x_n]),expr)
define(ev(expr_1),expr_2)

Description

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 limit the scope of f to g.

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)
defcon SciMax Toolbox define_variable