% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\EquationXmpTitle}{Equation}
\newcommand{\EquationXmpNumber}{9.19}
%
% =====================================================================
\begin{page}{EquationXmpPage}{9.19 Equation}
% =====================================================================
\beginscroll

The \spadtype{Equation} domain provides equations as mathematical objects.
These are used, for example, as the input to various
\spadfunFrom{solve}{TransSolvePackage} operations.

\xtc{
Equations are created using the equals symbol, \spadopFrom{=}{Equation}.
}{
\spadpaste{eq1 := 3*x + 4*y = 5 \bound{eq1}}
}
\xtc{
}{
\spadpaste{eq2 := 2*x + 2*y = 3 \bound{eq2}}
}
\xtc{
The left- and right-hand sides of an equation are accessible using
the operations \spadfunFrom{lhs}{Equation} and \spadfunFrom{rhs}{Equation}.
}{
\spadpaste{lhs eq1 \free{eq1}}
}
\xtc{
}{
\spadpaste{rhs eq1 \free{eq1}}
}

\xtc{
Arithmetic operations are supported
and operate on both sides of the equation.
}{
\spadpaste{eq1 + eq2   \free{eq1 eq2}}
}
\xtc{
}{
\spadpaste{eq1 * eq2   \free{eq1 eq2}}
}
\xtc{
}{
\spadpaste{2*eq2 - eq1 \free{eq1 eq2}}
}
\xtc{
Equations may be created for any type so the arithmetic operations
will be defined only when they make sense.  For example,
exponentiation is not defined for equations involving non-square matrices.
}{
\spadpaste{eq1^2 \free{eq1}}
}

\xtc{
Note that an equals symbol is also used to {\it test}
for equality of values in certain contexts.
For example, \spad{x+1} and \spad{y} are unequal as polynomials.
}{
\spadpaste{if x+1 = y then "equal" else "unequal"}
}
\xtc{
}{
\spadpaste{eqpol := x+1 = y \bound{eqpol}}
}
\xtc{
If an equation is used where a \spadtype{Boolean} value
is required, then it is evaluated using the equality
test from the operand type.
}{
\spadpaste{if eqpol then "equal" else "unequal" \free{eqpol}}
}
\xtc{
If one wants a \spadtype{Boolean} value rather than an equation,
all one has to do is ask!
}{
\spadpaste{eqpol::Boolean \free{eqpol}}
}
\endscroll
\autobuttons
\end{page}
%
