% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved.
% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\XPolynomialRingXmpTitle}{XPolynomialRing}
\newcommand{\XPolynomialRingXmpNumber}{9.94}
%
% =====================================================================
\begin{page}{XPolynomialRingXmpPage}{9.94 XPolynomialRing}
% =====================================================================
\beginscroll

%
%
%
%
%


The \spadtype{XPolynomialRing} domain constructor implements
generalized polynomials with coefficients from an arbitrary \spadtype{Ring}
(not necessarily commutative) and whose exponents are
words from an arbitrary \spadtype{OrderedMonoid}
(not necessarily commutative too).
Thus these polynomials are (finite) linear combinations of words.

This constructor takes two arguments.
The first one is a \spadtype{Ring}
and the second is an \spadtype{OrderedMonoid}.
The abbreviation for \spadtype{XPolynomialRing} is \spadtype{XPR}.

Other constructors like \spadtype{XPolynomial},
\spadtype{XRecursivePolynomial},
\spadtype{XDistributedPolynomial},
\spadtype{LiePolynomial} and
\spadtype{XPBWPolynomial}
implement multivariate polynomials
in non-commutative variables.

We illustrate now some of the facilities of the \spadtype{XPR} domain constructor.

\xtc{
Define the free ordered monoid generated by the symbols.
}{
\spadpaste{Word := FreeMonoid(Symbol) \bound{Word}}
}

\xtc{
Define the linear combinations of these words with integer coefficients.
}{
\spadpaste{poly:= XPR(Integer,Word) \free{Word} \bound{poly}}
}


\xtc{
Then we define a first element from {\bf poly}.
}{
\spadpaste{p:poly := 2 * x - 3 * y + 1 \free{poly} \bound{p}}
}

\xtc{
And a second one.
}{
\spadpaste{q:poly := 2 * x + 1 \free{poly} \bound{q}}
}


\xtc{
We compute their sum,
}{
\spadpaste{p + q  \free{p}\free{q} }
}

\xtc{
their product,
}{
\spadpaste{p * q  \free{p}\free{q} }
}

\xtc{
and see that variables do not commute.
}{
\spadpaste{(p +q)^2 -p^2 -q^2 - 2*p*q  \free{p}\free{q} }
}



\xtc{
Now we define a ring of square matrices,
}{
\spadpaste{M := SquareMatrix(2,Fraction Integer)  \bound{M}}
}

\xtc{
and the linear combinations of words with these  matrices as coefficients.
}{
\spadpaste{poly1:= XPR(M,Word) \free{Word} \free{M} \bound{poly1}}
}


\xtc{
Define a first matrix,
}{
\spadpaste{m1:M := matrix [[i*j^2 for i in 1..2] for j in 1..2] \free{M} \bound{m1}}
}

\xtc{
a second one,
}{
\spadpaste{m2:M := m1 - 5/4 \free{M} \free{m1} \bound{m2}}
}

\xtc{
and a third one.
}{
\spadpaste{m3: M := m2^2 \free{M} \free{m2} \bound{m3}}
}

\xtc{
Define a polynomial,
}{
\spadpaste{pm:poly1   := m1*x + m2*y + m3*z - 2/3 \free{poly1} \free{m1} \free{m2} \free{m3} \bound{pm}}
}


\xtc{
a second one,
}{
\spadpaste{qm:poly1 := pm - m1*x \free{m1} \free{pm} \bound{qm}}
}

\xtc{
and the following power.
}{
\spadpaste{qm^3 \bound{qm}}
}
\endscroll
\autobuttons
\end{page}
%
