% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\SquareMatrixXmpTitle}{SquareMatrix}
\newcommand{\SquareMatrixXmpNumber}{9.79}
%
% =====================================================================
\begin{page}{SquareMatrixXmpPage}{9.79 SquareMatrix}
% =====================================================================
\beginscroll

%
%
%
%
%



The top level matrix type in \Language{} is \spadtype{Matrix}
(see \downlink{`Matrix'}{MatrixXmpPage}\ignore{Matrix}), which
provides basic arithmetic and linear algebra functions.
However, since the matrices can be of any size it is not true that any pair
can be added or multiplied.
Thus \spadtype{Matrix} has little algebraic structure.

Sometimes you want to use matrices as coefficients for polynomials
or in other algebraic contexts.  In this case, \spadtype{SquareMatrix}
%-% \HDindex{matrix!square}{SquareMatrixXmpPage}{9.79}{SquareMatrix}
should be used.  The domain \spadtype{SquareMatrix(n,R)} gives the ring of
\spad{n} by \spad{n} square matrices over \spad{R}.

\xtc{
Since \spadtype{SquareMatrix} is not normally exposed at the top level,
you must expose it before it can be used.
}{
\spadpaste{)set expose add constructor SquareMatrix \bound{SQ}}
}
\xtc{
Once \spad{SQMATRIX} has been exposed,
values can be created using the \spadfunFrom{squareMatrix}{SquareMatrix}
function.
}{
\spadpaste{m := squareMatrix [[1,-\%i],[\%i,4]] \bound{m}\free{SQ}}
}
\xtc{
The usual arithmetic operations are available.
}{
\spadpaste{m*m - m \free{m}}
}
\xtc{
Square matrices can be used where ring elements are required.
For example, here is a matrix with matrix entries.
}{
\spadpaste{mm := squareMatrix [[m, 1], [1-m, m^2]] \free{m}\bound{mm}}
}
\xtc{
Or you can construct a polynomial with  square matrix coefficients.
}{
\spadpaste{p := (x + m)^2 \free{m}\bound{p}}
}
\xtc{
This value can be converted to a square matrix with polynomial coefficients.
}{
\spadpaste{p::SquareMatrix(2, ?) \free{p}}
}

For more information on related topics, see
\downlink{``\ugTypesWritingModesTitle''}{ugTypesWritingModesPage} in Section \ugTypesWritingModesNumber\ignore{ugTypesWritingModes},
\downlink{``\ugTypesExposeTitle''}{ugTypesExposePage} in Section \ugTypesExposeNumber\ignore{ugTypesExpose}, and
\downlink{`Matrix'}{MatrixXmpPage}\ignore{Matrix}.
\showBlurb{SquareMatrix}
\endscroll
\autobuttons
\end{page}
%
