
% 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.


Initialisations
\xtc{
}{
\spadcommand{a:Symbol := 'a \bound{a}}
}
\xtc{
}{
\spadcommand{b:Symbol := 'b \bound{b}}
}
\xtc{
}{
\spadcommand{RN    := Fraction(Integer) \bound{RN}}
}
\xtc{
}{
\spadcommand{word   := FreeMonoid Symbol \bound{word}}
}
\xtc{
}{
\spadcommand{lword := LyndonWord(Symbol) \bound{lword}}
}
\xtc{
}{
\spadcommand{base  := PoincareBirkhoffWittLyndonBasis Symbol \bound{base}}
}
\xtc{
}{
\spadcommand{dpoly := XDistributedPolynomial(Symbol, RN) \bound{dpoly} \free{RN}}
}
\xtc{
}{
\spadcommand{rpoly := XRecursivePolynomial(Symbol, RN) \bound{rpoly} \free{RN}}
}
\xtc{
}{
\spadcommand{lpoly := LiePolynomial(Symbol, RN) \bound{lpoly} \free{RN}}
}
\xtc{
}{
\spadcommand{poly  := XPBWPolynomial(Symbol, RN) \bound{poly} \free{RN}}
}
\xtc{
}{
\spadcommand{liste : List lword := LyndonWordsList([a,b], 6) \bound{liste} \free{lword a b }}
}

Let's make some polynomials
\xtc{
}{
\spadcommand{0\$poly \free{poly}}
}
\xtc{
}{
\spadcommand{1\$poly \free{poly}}
}
\xtc{
}{
\spadcommand{p : poly := a \free{a poly} \bound{p}}
}
\xtc{
}{
\spadcommand{q : poly := b \free{b poly} \bound{q}}
}
\xtc{
}{
\spadcommand{pq: poly := p*q \free{p q poly} \bound{pq}}
}
\xtc{
Coerce to distributed polynomial
}{
\spadcommand{pq :: dpoly \free{pq dpoly}}
}

Check some polynomial operations
\xtc{
}{
\spadcommand{mirror pq \free{pq}}
}
\xtc{
}{
\spadcommand{listOfTerms pq \free{pq}}
}
\xtc{
}{
\spadcommand{reductum pq \free{pq}}
}
\xtc{
}{
\spadcommand{leadingMonomial pq \free{pq}}
}
\xtc{
}{
\spadcommand{coefficients pq \free{pq}}
}
\xtc{
}{
\spadcommand{leadingTerm pq \free{pq}}
}
\xtc{
}{
\spadcommand{degree pq \free{pq}}
}
\xtc{
}{
\spadcommand{pq4:=exp(pq,4) \bound{pq4} \free{pq}}
}
\xtc{
}{
\spadcommand{log(pq4,4) - pq \free{pq4 pq} }
}

Calculations with verification in \spadtype{XDistributedPolynomial}.
\xtc{
}{
\spadcommand{lp1 :lpoly := LiePoly liste.10 \free{liste lpoly} \bound{lp1}}
}
\xtc{
}{
\spadcommand{lp2 :lpoly := LiePoly liste.11 \free{liste lpoly} \bound{lp2}}
}
\xtc{
}{
\spadcommand{lp  :lpoly := [lp1, lp2] \free{lp1 lp2 lpoly} \bound{lp}}
}
\xtc{
}{
\spadcommand{lpd1: dpoly := lp1 \free{lp1 dpoly} \bound{lpd1}}
}
\xtc{
}{
\spadcommand{lpd2: dpoly := lp2 \free{lp2 dpoly} \bound{lpd2}}
}
\xtc{
}{
\spadcommand{lpd : dpoly := lpd1 * lpd2 - lpd2 * lpd1 \free{dpoly lpd1 lpd2} \bound{lpd}}
}
\xtc{
}{
\spadcommand{lp :: dpoly - lpd \free{lpd dpoly lp}}
}

Calculations with verification in \spadtype{XRecursivePolynomial}.
\xtc{
}{
\spadcommand{p := 3 * lp \free{lp} \bound{pp}}
}
\xtc{
}{
\spadcommand{q := lp1 \free{lp1} \bound{qq}}
}
\xtc{
}{
\spadcommand{pq:= p * q \free{pp qq} \bound{pqpq}}
}
\xtc{
}{
\spadcommand{pr:rpoly := p :: rpoly \free{rpoly pp} \bound{pr}}
}
\xtc{
}{
\spadcommand{qr:rpoly := q :: rpoly \free{rpoly qq} \bound{qr}}
}
\xtc{
}{
\spadcommand{pq :: rpoly - pr*qr \free{pr qr rpoly pqpq} }
}
