Syntax
where F is the name of the function, and E is any valid
equation.
We define functions by using the F: command, which is used in
parallel to the C: command. A function is the same as a constant
except (i) that it is not evaluated until required; and (ii) may contain
unknown indices. In contrast, a constant has a unique value which is
unchanging. The value of a function changes according to its definition.
If a function is defined solely in terms of numbers, it is equivalent to
a constant.
Functions have names, generally alphanumeric strings which begin with a
letter, and are referenced by prefixing the name with a # symbol.
Function names typically terminate with one or more indices representing
unknowns that will be revealed whenever the function is to be evaluated.
The first form of the syntax has the definition part following
immediately after the name part. As an alternative, for interactive
prompting of function inputs, the second form of the syntax prompts for
the definition part from the keyboard.
The definition part, E, is any valid equation. Thus, for example,
E might consist of a simple real number, or some more complicated
formula. The equation may include unknowns, which must relate to the indices
present in the function name. The value of these unknowns must be known
at the time of evaluation of the function.
Functions can be deleted by using the XF: command, and they may
also be redefined.
It is an error if an unrecognised function is found in an equation.
Consider, for example, the definition and usage of a typical function
shown in the code in Figure 7.2.
This command line defines a function with unknowns represented by
the indices .i, .j, and .k. Thus, for example, the intention will be to
regard #X.1.2.3 as equivalent to the value of ,
where %sum is a constant (not necessarily already defined). The remarks
made earlier about a function not being evaluated until required means
that the value of the constant %sum will only be referenced at that
time. Hence the first value output by this segment of code will be
, and the second will be
.
With regard to the attachment of indices to the function name to
represent unknowns, the index is a period followed by an alphabetic
character. This character must be replaced by an integer whenever the
function is evaluated. When the formula part is evaluated to give the
function its value, any character representing an unknown in the formula
is replaced by its appropriate value;
the context determines whether the period is
also removed. Generally, the period is removed when the whole is
intended to represent a number, and not removed when the whole is part
of a name. For example, a definition of
BD>f : #X.i.j= .i + .j + var (1,y.j.i) + %fred.i.j + z.i.j
would result in #X.3.4 being defined as
,
so that %fred.i.j is replaced by %fred.3.4, and not %fred34; whereas
z.i(.j) is replaced by z.3(4). See section §6.3 for
further information about functional forms.