
% Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
%     - Redistributions of source code must retain the above copyright
%       notice, this list of conditions and the following disclaimer.
%
%     - Redistributions in binary form must reproduce the above copyright
%       notice, this list of conditions and the following disclaimer in
%       the documentation and/or other materials provided with the
%       distribution.
%
%     - Neither the name of The Numerical ALgorithms Group Ltd. nor the
%       names of its contributors may be used to endorse or promote products
%       derived from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
% IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
% TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
% OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES-- LOSS OF USE, DATA, OR
% PROFITS-- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
% LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


The \spadtype{XPolynomial} domain constructor implements multivariate polynomials
whose set of variables is \spadtype{Symbol}.
These variables do not commute.
The only parameter of this constructor is
the coefficient ring which may be non-commutative.
However, coefficients and variables commute.
The representation of the polynomials is recursive.
The abbreviation for \spadtype{XPolynomial} is \spadtype{XPOLY}.

Other constructors like \spadtype{XPolynomialRing},
\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{XPOLY} domain constructor.


\xtc{
Define a polynomial ring over the integers.
}{
\spadcommand{poly := XPolynomial(Integer) \bound{poly}}
}

\xtc{
Define a first polynomial,
}{
\spadcommand{pr: poly := 2*x + 3*y-5  \free{poly} \bound{pr}}
}


\xtc{
and a second one.
}{
\spadcommand{pr2: poly := pr*pr  \free{poly} \bound{pr2}}
}

\xtc{
Rewrite {\bf pr} in a distributive way,
}{
\spadcommand{pd  := expand pr   \free{pr} \bound{pd}}
}

\xtc{
compute its square,
}{
\spadcommand{pd2 := pd*pd   \free{pd} \bound{pd2}}
}

\xtc{
and checks that:
}{
\spadcommand{expand(pr2) - pd2 \free{pr2} \free{pd2}}
}


\xtc{
We define:
}{
\spadcommand{qr :=  pr^3 \free{pr} \bound{qr}}
}

\xtc{
and:
}{
\spadcommand{qd :=  pd^3 \free{pd} \bound{qd}}
}

\xtc{
We truncate {\bf qd} at degree {\bf 3}:
}{
\spadcommand{trunc(qd,2) \free{qd}}
}

\xtc{
The same for {\bf qr}:
}{
\spadcommand{trunc(qr,2) \free{qr}}
}

\xtc{
We define:
}{
\spadcommand{Word := FreeMonoid Symbol \bound{Word}}
}

\xtc{
and:
}{
\spadcommand{w: Word := x*y^2 \free{Word} \bound{w}}
}

\xtc{
The we can compute the right-quotient of {\bf qr} by {\bf r}:
}{
\spadcommand{rquo(qr,w) \free{qr} \free{w}}
}

\xtc{
and the shuffle-product of {\bf pr} by {\bf r}:
}{
\spadcommand{sh(pr,w::poly) \free{pr} \free{w}}
}
