In REDUCE, global algebraic relations can be formulated with rules. A rule links an algebraic search pattern to a replacement pattern, sometimes controlled by additional conditions. Rules can be activated (and deactivated) globally, or they can be invoked with a limited scope for single evaluations. So the user has an arbitrary precise control over the algebraic simplification.
Example: Expanding trigonometric functions for combined arguments; the
symbol represents an implicit
.
Sin_Cos_rules:=
{sin(~x+~y)=>sin(x)*cos(y) + cos(x)*sin(y),
cos(~x+~y)=>cos(x)*cos(y) - sin(x)*sin(y)};
Global activation is achieved by
let Sin_Cos_rules;
Note: REDUCE has no predefined ``knowledge'' about these relations for trigonometric functions, as they can be used as production rules in either form depending on whether expansion or collection is required; only the user can define which mode is adequate for his problem.
Using rules, a complete calculus can be implemented; the rule syntax here is very close to the mathematical notation for multistep cases.
Example: Definition of Hermite polynomials:
operator Hermite;
Hermite_rules:=
{Hermite(0,~x) => 1,
Hermite(1,~x) => 2*x,
Hermite(~n,~x) => 2*x*Hermite(n-1,x)
-2*(n-1)*Hermite(n-2,x)
when n>1};
let Hermite_rules;
Generation of a Hermite polynomial:
Hermite(4,z);
4 2
16*Z - 48*Z + 12
see also: REDUCE Home Page