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


Declaration of domains
\xtc{
}{
\spadcommand{RN    := Fraction Integer \bound{RN}}
}
\xtc{
}{
\spadcommand{Lpoly := LiePolynomial(Symbol,RN) \bound{Lpoly} \free{RN}}
}
\xtc{
}{
\spadcommand{Dpoly := XDPOLY(Symbol,RN) \bound{Dpoly} \free{RN}}
}
\xtc{
}{
\spadcommand{Lword := LyndonWord Symbol \bound{Lword}}
}

Initialisation
\xtc{
}{
\spadcommand{a:Symbol := 'a \bound{a}}
}
\xtc{
}{
\spadcommand{b:Symbol := 'b \bound{b}}
}
\xtc{
}{
\spadcommand{c:Symbol := 'c \bound{c}}
}
\xtc{
}{
\spadcommand{aa: Lpoly := a \bound{aa} \free{Lpoly} \free{a}}
}
\xtc{
}{
\spadcommand{bb: Lpoly := b \bound{bb} \free{Lpoly} \free{b}}
}
\xtc{
}{
\spadcommand{cc: Lpoly := c \bound{cc} \free{Lpoly} \free{c}}
}
\xtc{
}{
\spadcommand{p : Lpoly := [aa,bb] \bound{p} \free{aa} \free{bb} \free{Lpoly}}
}
\xtc{
}{
\spadcommand{q : Lpoly := [p,bb] \bound{q} \free{p} \free{bb} \free{Lpoly}}
}
\xtc{
All the Lyndon words of order 4
}{
\spadcommand{liste : List Lword := LyndonWordsList([a,b], 4) \free{a} \free{b} \free{Lword} \bound{liste}}
}
\xtc{
}{
\spadcommand{r: Lpoly := p + q + 3*LiePoly(liste.4)\$Lpoly \bound{r} \free{Lpoly} \free{p} \free{q} \free{liste}}
}
\xtc{
}{
\spadcommand{s:Lpoly := [p,r] \bound{s} \free{Lpoly} \free{p} \free{r}}
}
\xtc{
}{
\spadcommand{t:Lpoly  := s  + 2*LiePoly(liste.3) - 5*LiePoly(liste.5) \bound{t} \free{Lpoly} \free{s} \free{liste} }
}
\xtc{
}{
\spadcommand{degree t \free{t}}
}
\xtc{
}{
\spadcommand{mirror t \free{t}}
}

Jacobi Relation
\xtc{
}{
\spadcommand{Jacobi(p: Lpoly, q: Lpoly, r: Lpoly): Lpoly == [[p,q]\$Lpoly, r] + [[q,r]\$Lpoly, p] + [[r,p]\$Lpoly, q] \free{Lpoly} \bound{J}}
}

Tests
\xtc{
}{
\spadcommand{test: Lpoly := Jacobi(a,b,b) \free{J Lpoly a b} \bound{test1}}
}
\xtc{
}{
\spadcommand{test: Lpoly := Jacobi(p,q,r) \free{J p q r Lpoly} \bound{test2}}
}
\xtc{
}{
\spadcommand{test: Lpoly := Jacobi(r,s,t) \free{J r s t Lpoly} \bound{test3}}
}

Evaluation
\xtc{
}{
\spadcommand{eval(p, a, p)\$Lpoly}
}
\xtc{
}{
\spadcommand{eval(p, [a,b], [2*bb, 3*aa])\$Lpoly \free{p a b bb aa Lpoly}}
}
\xtc{
}{
\spadcommand{r: Lpoly := [p,c] \free{p c Lpoly} \bound{rr}}
}
\xtc{
}{
\spadcommand{r1: Lpoly := eval(r, [a,b,c], [bb, cc, aa])\$Lpoly \free{rr a b c aa bb cc Lpoly} \bound{r1}}
}
\xtc{
}{
\spadcommand{r2: Lpoly := eval(r, [a,b,c], [cc, aa, bb])\$Lpoly \free{rr a b c cc bb aa Lpoly} \bound{r2}}
}
\xtc{
}{
\spadcommand{r + r1 + r2 \free{rr r1 r2}}
}
