% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk.
\newcommand{\FreeMagmaXmpTitle}{FreeMagma}
\newcommand{\FreeMagmaXmpNumber}{9.29}
%
% =====================================================================
\begin{page}{FreeMagmaXmpPage}{9.29 FreeMagma}
% =====================================================================
\beginscroll

%
%
%
%
%


Initialisations
\xtc{
}{
\spadpaste{x:Symbol :='x \bound{x}}
}
\xtc{
}{
\spadpaste{y:Symbol :='y \bound{y}}
}
\xtc{
}{
\spadpaste{z:Symbol :='z \bound{z}}
}
\xtc{
}{
\spadpaste{word := FreeMonoid(Symbol) \bound{word}}
}
\xtc{
}{
\spadpaste{tree := FreeMagma(Symbol) \bound{tree}}
}

Let's make some trees
\xtc{
}{
\spadpaste{a:tree := x*x \free{x tree} \bound{a}}
}
\xtc{
}{
\spadpaste{b:tree := y*y \free{y tree} \bound{b}}
}
\xtc{
}{
\spadpaste{c:tree := a*b \free{a b tree} \bound{c}}
}

Query the trees
\xtc{
}{
\spadpaste{left c \free{c}}
}
\xtc{
}{
\spadpaste{right c \free{c}}
}
\xtc{
}{
\spadpaste{length c \free{c}}
}
\xtc{
Coerce to the monoid
}{
\spadpaste{c::word \free{c word}}
}

Check ordering
\xtc{
}{
\spadpaste{a < b \free{a b}}
}
\xtc{
}{
\spadpaste{a < c \free{a c}}
}
\xtc{
}{
\spadpaste{b < c \free{b c}}
}

Navigate the tree
\xtc{
}{
\spadpaste{first c \free{c}}
}
\xtc{
}{
\spadpaste{rest c \free{c}}
}
\xtc{
}{
\spadpaste{rest rest c  \free{c}}
}

Check ordering
\xtc{
}{
\spadpaste{ax:tree := a*x \free{a x tree} \bound{ax}}
}
\xtc{
}{
\spadpaste{xa:tree := x*a \free{a x tree} \bound{xa}}
}
\xtc{
}{
\spadpaste{xa < ax \free{ax xa}}
}
\xtc{
}{
\spadpaste{lexico(xa,ax) \free{ax xa}}
}
\endscroll
\autobuttons
\end{page}
%
