Using references to break long functions
Suppose you want to define a function like this:
z(x,y) = exp(1-cos(x)) / (y + exp(1-cos(x))
Soon you see that the function definition is long and inefficient. The
exp(1-cos(x))
part appeared twice and it is more efficient to
make a reference to exp(1-cos(x))
, says a
, and
defines the overall function as: z(x,y) = a / (y + a)
.
Since version 1.30b1, Surface Plotter provides a way to do this. The syntax
of references is:
reference name 1: definition 1; reference name 2
: defintion 2; ...
The reference name is theoritically can be any characters long, but it must not
be the same with any of defined variables or constants (x, y, e, pi), function
names (sin, cos, tan, ...), reserved words or operators (if, |, =, ...).
In short, the reference must not make the original definition ambiguous.
The reference name may not start with a number. (e.q: 1st, 2nd, ...) This
restriction also apply in most (all ?) of computer language.
A function definition may contain many references, and a reference definition
may contain other references, but it must not start with a reference.
Surface Plotter evaluates references from back, so you
must define a reference after you used it.
This makes circular
references impossible.
Examples:
z(x,y) = a: sin(x); b: cos(y); a + b
- Incorrect, must not start with a reference.
z(x,y) = a + b + c; a: cos(b); c: 2 * a
- Incorrect (in
c = 2 * a
), must define a reference after used it.
z(x,y) = a / (1 + b + c); a: cos(b); b: 2 * x; c: x * cos(y)
Send comments, suggestions, bug reports to
Yanto Suryono