<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %A  fpsemi.xml            GAP documentation            Isabel Araújo -->
<!-- %% -->
<!-- %% -->
<!-- %Y  (C) 1999 School Math and Comp. Sci., University of St Andrews, Scotland -->
<!-- %Y  Copyright (C) 2002 The GAP Group -->
<!-- %% -->

<Chapter Label="Finitely Presented Semigroups and Monoids">
<Heading>Finitely Presented Semigroups and Monoids</Heading>

A <E>finitely presented semigroup</E> (resp. <E>finitely presented monoid</E>)
is a quotient of a free semigroup (resp. free monoid) on a finite
number of generators over a finitely generated congruence on
the free semigroup (resp. free monoid).
<P/>
Finitely presented semigroups are obtained by factoring a free semigroup
by a set of relations (a generating set for the congruence), i.e., a set of
pairs of words in the free semigroup.
<P/>
<Example><![CDATA[
gap> f := FreeSemigroup( "a", "b" );;
gap> x := GeneratorsOfSemigroup( f );;
gap> s := f / [ [ x[1] * x[2], x[2] * x[1] ] ];
<fp semigroup on the generators [ a, b ]>
gap> GeneratorsOfSemigroup( s );
[ a, b ]
gap> RelationsOfFpSemigroup( s );
[ [ a*b, b*a ] ]
]]></Example>
<P/>
Finitely presented monoids are obtained by factoring a free monoid by
a set of relations, i.e. a set of pairs of words in the free monoid.
<P/>
<Example><![CDATA[
gap> f := FreeMonoid( "a", "b" );;
gap> x := GeneratorsOfMonoid( f );
[ a, b ]
gap> e := Identity( f );
<identity ...>
gap> m := f / [ [ x[1] * x[2], e ] ];
<fp monoid on the generators [ a, b ]>
gap> RelationsOfFpMonoid( m );
[ [ a*b, <identity ...> ] ]
]]></Example>
<P/>
Notice that for &GAP; a finitely presented monoid is not a finitely
presented semigroup.
<P/>
<Example><![CDATA[
gap> IsFpSemigroup( m );
false
]]></Example>
<P/>
However, one can build a finitely presented semigroup isomorphic
to that finitely presented monoid (see <Ref Attr="IsomorphismFpSemigroup"/>).
<P/>
Also note that is not possible to refer to the generators by their names.
These names are not variables, but just display figures.
So, if one wants to access the generators by their names, one first has to
introduce the respective variables and to assign the generators to them.
<P/>
<Example><![CDATA[
gap> Unbind( a );
gap> f := FreeSemigroup( "a", "b" );;
gap> s := f / [ [ f.1 * f.2, f.2 * f.1 ] ];;
gap> a;
Error, Variable: 'a' must have a value
gap> a := s.1;
a
gap> a in f;
false
gap> a in s;
true
]]></Example>
<P/>
The generators of the free semigroup (resp. free monoid) are different
from the generators of the finitely presented semigroup (resp. finitely
presented monoid) (even though they are displayed by the same names).
This means that words in the generators of the free semigroup (resp.
free monoid) are not elements of the finitely presented semigroup (resp.
finitely presented monoid). Conversely elements of the finitely presented
semigroup (resp. finitely presented monoid) are not words of the free
semigroup (resp. free monoid).
<P/>
Calculations comparing elements of a finitely presented semigroup
may run into problems: there are finitely presented semigroups for
which no algorithm exists (it is known that no such algorithm can exist)
that will tell for two arbitrary words in the generators whether the
corresponding elements in the finitely presented semigroup are equal.
Therefore the methods used by &GAP; to compute in finitely presented
semigroups may run into warning errors, run out of memory or run forever.
If the finitely presented semigroup is (by theory) known to be
finite the algorithms are guaranteed to terminate (if there is sufficient
memory available), but the time needed for the calculation cannot be
bounded a priori. The same can be said for monoids.
(See <Ref Sect="Rewriting Systems and the Knuth-Bendix Procedure"/>.)
<P/>
<Example><![CDATA[
gap> b := s.2;;
gap> a*b = a^5;
false
gap> a^5 * b^2 * a = a^6 * b^2;
true
]]></Example>
<P/>
Note that elements of a finitely presented semigroup (or monoid) are not
printed in a unique way:
<P/>
<Example><![CDATA[
gap> a^5 * b^2 * a;
a^5*b^2*a
gap> a^6 * b^2;
a^6*b^2
]]></Example>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="sect:IsSubsemigroupFpSemigroup">
<Heading>IsSubsemigroupFpSemigroup (Filter)</Heading>

<#Include Label="IsSubsemigroupFpSemigroup">
<#Include Label="IsFpSemigroup">
<#Include Label="IsElementOfFpSemigroup">
<#Include Label="FpGrpMonSmgOfFpGrpMonSmgElement">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Creating Finitely Presented Semigroups and Monoids">
<Heading>Creating Finitely Presented Semigroups and Monoids</Heading>

<ManSection>
<Meth Name="\/" Arg="F, rels"
 Label="for a free semigroup or monoid and a list of pairs of elements"/>

<Description>
<Index Subkey="of free semigroup">quotient</Index>
<Index Subkey="of free monoid">quotient</Index>
creates a finitely presented semigroup or monoid given by the presentation
<M>\langle <A>gens</A> \mid <A>rels</A> \rangle</M> where
<A>gens</A> are the generators of the free semigroup or free monoid <A>F</A>,
and the relations <A>rels</A> are entered as pairs of
words in the generators of the free semigroup or free monoid.
<P/>
The same result is obtained with the infix operator <C>/</C>,
i.e. as <A>F</A> <C>/</C> <A>rels</A>.
<P/>
<Example><![CDATA[
gap> fs := FreeSemigroup( 3 );;
gap> x := GeneratorsOfSemigroup( fs );;
gap> s := fs / [ [ x[1] * x[2] * x[1], x[1] ], [ x[2]^4, x[1] ] ];
<fp semigroup on the generators [ s1, s2, s3 ]>
]]></Example>
</Description>
</ManSection>

<#Include Label="FactorFreeSemigroupByRelations">
<#Include Label="IsomorphismFpSemigroup">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Comparison of Elements of Finitely Presented Semigroups">
<Heading>Comparison of Elements of Finitely Presented Semigroups</Heading>

<ManSection>
<Meth Name="\=" Arg="a, b" Label="for two elements in a f.p. semigroup"/>

<Description>
<Index Subkey="fp semigroup elements">comparison</Index>
Two elements <A>a</A>, <A>b</A> of a finitely presented semigroup are equal
if they are equal in the semigroup.
Nevertheless they may be represented as different words in the generators.
Because of the fundamental problems mentioned in the
introduction to this chapter such a test may take a very long time
and cannot be guaranteed to finish
(see <Ref Sect="Rewriting Systems and the Knuth-Bendix Procedure"/>).
</Description>
</ManSection>

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Preimages in the Free Semigroup or Monoid">
<Heading>Preimages in the Free Semigroup or Monoid</Heading>

Elements of a finitely presented semigroup or monoid are not words,
but are represented using a word from the free semigroup or free monoid
as representative.
<P/>

<ManSection>
<Oper Name="UnderlyingElement" Arg='elm'
Label="of an element in a fp semigroup or monoid"/>

<Description>
for an element <A>elm</A> of a finitely presented semigroup or monoid.
Returns the word from the free semigroup or free monoid that is used as a
representative for <A>elm</A>.
<P/>
<Example><![CDATA[
gap> genm := GeneratorsOfMonoid( m );;
gap> e := genm[2]^4;
m2^4
gap> IsWord( e );
false
gap> ue := UnderlyingElement( e );
m2^4
gap> IsWord( ue );
true
]]></Example>
</Description>
</ManSection>

<#Include Label="ElementOfFpSemigroup">
<#Include Label="FreeSemigroupOfFpSemigroup">
<#Include Label="FreeGeneratorsOfFpSemigroup">
<#Include Label="RelationsOfFpSemigroup">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Rewriting Systems and the Knuth-Bendix Procedure">
<Heading>Rewriting Systems and the Knuth-Bendix Procedure</Heading>

If a finitely presented semigroup (or monoid) has a confluent rewriting system
then it has a solvable word problem, that is, there is an algorithm to decide
when two words in the free underlying semigroup represent the same element
of the finitely presented semigroup.
Indeed, once we have a confluent rewriting system, it is possible to
successfully test that two words represent the same element in the
semigroup, by reducing both words using the rewriting system rules.
This is, at the moment, the method that &GAP; uses to check equality
in finitely presented semigroups and monoids.
<P/>

<#Include Label="ReducedConfluentRewritingSystem">
<#Include Label="KB_REW">

<ManSection>
<Heading>KnuthBendixRewritingSystem</Heading>
<Oper Name="KnuthBendixRewritingSystem" Arg='s, wordord'
 Label="for a semigroup and a reduction ordering"/>
<Oper Name="KnuthBendixRewritingSystem" Arg='m, wordord'
 Label="for a monoid and a reduction ordering"/>

<Description>
in the first form, for a semigroup <A>s</A> and a reduction ordering
for the underlying free semigroup, it returns the Knuth-Bendix
rewriting system of the finitely presented semigroup <A>s</A> using the
reduction ordering <A>wordord</A>.
In the second form, for a monoid <A>m</A> and a reduction ordering
for the underlying free monoid, it returns the Knuth-Bendix
rewriting system of the finitely presented monoid <A>m</A> using the
reduction ordering <A>wordord</A>.
</Description>
</ManSection>

<#Include Label="SemigroupOfRewritingSystem">
<#Include Label="FreeSemigroupOfRewritingSystem">

</Section>


<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Todd-Coxeter Procedure">
<Heading>Todd-Coxeter Procedure</Heading>

This procedure gives a standard way of finding a transformation
representation of a finitely presented semigroup. Usually
one does not explicitly call this procedure but uses
<Ref Attr="IsomorphismTransformationSemigroup"/>.
<!--or <Ref Func="HomomorphismTransformationSemigroup"/>-->

<#Include Label="CosetTableOfFpSemigroup">

</Section>
</Chapter>

<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %E -->
