<Chapter Label = "Finitely presented semigroups and Tietze transformations">
  <Heading>
    Finitely presented semigroups and Tietze transformations
  </Heading>

  In this chapter we describe the functions implemented in &SEMIGROUPS; that
  extend the features available in &GAP; for dealing with finitely presented
  semigroups and monoids.

  <P/>

  Section
  <Ref Sect="Changing representation for words and strings" Style="Number"/>
  (written by Maria Tsalakou and Murray Whyte) and Section
  <Ref Sect="Helper functions" Style="Number"/>
  (written by Luke Elliott) demonstrate a number of helper functions that allow
  the user to convert between different representations of words and relations.

  <P/>

  In the later sections, written and implemented by Ben Spiers and Tom
  Conti-Leslie, we describe how to change the relations of a finitely presented
  semigroup either manually or automatically using Tietze
    transformations (which is abbreviated to <B>Stz</B>.
  <P/>

  <Section Label="Changing representation for words and strings">
    <Heading>
      Changing representation for words and strings
    </Heading>
    This section contains various methods for dealing with words, which for
    these purposes are lists of positive integers.

    <#Include Label = "WordToString" >
    <#Include Label = "RandomWord" >
    <#Include Label = "StandardiseWord" >
    <#Include Label = "StringToWord" >
  </Section>

  <Section
   Label="Helper functions">
    <Heading>
      Helper functions
    </Heading>
    This section describes operations implemented in &SEMIGROUPS; that are
    designed to interact with standard &GAP; methods for creating finitely
    presented semigroups and monoids (see <Ref
    Chap="Finitely Presented Semigroups and Monoids"
    BookName="ref"/>).

    <#Include Label = "ParseRelations">
    <#Include Label = "ElementOfFpSemigroup">
    <#Include Label = "ElementOfFpMonoid">
    <#Include Label = "FreeMonoidAndAssignGeneratorVars">
  </Section>

  <Section Label="Creating Tietze transformation objects">
    <Heading>
      Creating Tietze transformation objects
    </Heading>
    It is possible to use &GAP; to create finitely presented semigroups without
    the &SEMIGROUPS; package, by creating a free semigroup, then
    quotienting by a list of relations. This is described in the reference
    manual
    (<Ref Chap="Finitely Presented Semigroups and Monoids" BookName="ref"/>).
    <P/>

    However, finitely presented semigroups do not allow for their relations to
    be simplified, so in the following sections, we describe how to create and
    modify the semigroup Tietze (<Ref Filt="IsStzPresentation"/>) object
    associated with an fp semigroup.  This object can be automatically
    simplified, or the user can manually apply Tietze transformations to add or
    remove relations or generators in the presentation.
    <P/>

    This object is analogous to <Ref Oper="PresentationFpGroup"
      BookName="ref"/> implemented for fp groups in the main &GAP; distribution
    (<Ref Chap="Presentations and Tietze Transformations" BookName="ref"/>),
    but its features are semigroup-specific. Most of the functions used to
    create, view and manipulate semigroup Tietze objects are prefixed with
    <B>Stz</B>.

    <#Include Label = "StzPresentation">
    <#Include Label = "IsStzPresentation">
    <#Include Label = "GeneratorsOfStzPresentation">
    <#Include Label = "RelationsOfStzPresentation">
    <#Include Label = "UnreducedFpSemigroup-stz">
    <#Include Label = "Length">
  </Section>

  <Section Label = "Printing Tietze transformation objects">
    <Heading>
      Printing Tietze transformation objects
    </Heading>
    Since the relations are stored as flat lists of numbers, there are several
    methods installed to print the presentations in more user-friendly forms.
    <P/>

    All printing methods in this section are displayed as information
    (<Ref Func="Info" BookName="ref"/>) in the class
    <C>InfoFpSemigroup</C> at level 1. Setting
    <C>SetInfoLevevl(InfoFpSemigroup, 0)</C> will suppress the messages, while
    any higher number will display them.
    <P/>

    <#Include Label="StzPrintRelations">
    <#Include Label="StzPrintRelation">
    <#Include Label="StzPrintGenerators">
    <#Include Label="StzPrintPresentation">
  </Section>

  <Section Label = "Changing Tietze transformation objects">
    <Heading>
      Changing Tietze transformation objects
    </Heading>

    Fundamentally, there are four different changes that can be made to a
    presentation without changing the algebraic structure of the fp semigroup
    that can be derived from it. These four changes are called Tietze
    transformations, and they are primarily implemented in this section
    as operations on an <C>StzPresentation</C> object that will throw
    errors if the conditions have not been met to perform the Tietze
    transformation.
    <P/>

    However, the checks required in order to ensure that a Tietze
    transformation is valid sometimes require verifying equality of two words
    in an fp semigroup (for example, to ensure that a relation we are adding
    to the list of relations can be derived from the relations already present).
    Since these checks sometimes do not terminate, a second implementation of
    Tietze transformations assumes good faith and does not perform any
    checks to see whether the requested Tietze transformation actually maintains
    the structure of the semigroup. This latter type should be used at the
    user's discretion. If only the first type are used, the presentation will
    always give a semigroup isomorphic to the one used to create the object,
    but if instead one is not
    changing the presentation with the intention of maintaining algebraic
    structure, these no-check functions are available for use.
    <P/>

    The four Tietze transformations on a presentation are adding a relation,
    removing a relation, adding a generator, and removing a generator, with
    particular conditions on what can be added/removed in order to maintain
    structure.  More details on each transformation and its arguments and
    conditions is given in each entry below.  In addition to the four
    elementary transformations, there is an additional function
    <C>StzSubstituteRelation</C> which applies multiple Tietze transformations
    in sequence.
    <P/>

    <#Include Label="StzAddRelation">
    <#Include Label="StzRemoveRelation">
    <#Include Label="StzAddGenerator">
    <#Include Label="StzRemoveGenerator">
    <#Include Label="StzSubstituteRelation">
  </Section>

  <Section Label = "Converting a Tietze transformation object into a fp semigroup">
    <Heading>
      Converting a Tietze transformation object into a fp semigroup
    </Heading>
    Semigroup Tietze transformation objects (<Ref Filt="IsStzPresentation"/>)
    are not actual fp semigroups in the sense of <Ref Filt="IsFpSemigroup"
      BookName="ref"/>.  This is because their generators and relations can be
      modified (see section <Ref Sect="Changing Tietze transformation objects"/>).  However, an
      <Ref Oper="StzPresentation"/> can be converted back into an actual
      finitely presented semigroup using the methods described in this
      section.<P/>

    The intended use of semigroup Tietze objects is as follows: given an fp
    semigroup <C>S</C>, create a modifiable presentation using
    <C>stz := StzPresentation(S)</C>, apply Tietze transformations to it
    (perhaps in order to simplify the presentation), then generate a new
    fp semigroup <C>T</C> given by <C>stz</C> which is isomorphic to <C>S</C>,
    but has a simpler presentation. Once <C>T</C> is obtained, it may be of
    interest to map elements of <C>S</C> over to <C>T</C>, where they may be
    represented by different combinations of generators. The isomorphism
    achieving this is described in this section
    (see <Ref Oper="StzIsomorphism"/>).

    <#Include Label="TietzeForwardMap">
    <#Include Label="TietzeBackwardMap">
    <#Include Label="StzIsomorphism">
  </Section>

  <Section Label = "Automatically simplifying a Tietze transformation object">
    <Heading>
      Automatically simplifying a Tietze transformation object
    </Heading>
    <P/>

    It is possible to create a presentation object from an fp semigroup object
    and attempt to manually reduce it by applying Tietze transformations.
    However, there may be many different reductions that can be applied, so
    <C>StzSimplifyOnce</C> can be used to automatically check a number of
    different possible reductions and apply the best one. Then,
    <C>StzSimplifyPresentation </C> repeatedly applies StzSimplifyOnce to the
    presentation object until it fails to reduce the presentation any further.
    The metric with respect to which the <C>IsStzPresentation</C> object is
      reduced is <Ref Oper="Length"/>.

    <#Include Label="StzSimplifyOnce">
    <#Include Label="StzSimplifyPresentation">
  </Section>

  <Section Label = "Automatically simplifying an fp semigroup">
    <Heading>
      Automatically simplifying an fp semigroup
    </Heading>
    <P/>

    It may be the case that, rather than working with a Tietze transformation
    object, we want to start with an fp semigroup object and obtain the most
    simplified version of that fp semigroup that <C>StzSimplifyPresentation</C>
    can produce. In this case, <C>SimplifyFpSemigroup</C> can be applied to
    obtain a mapping from its argument to a reduced fp semigroup. If the
    mapping is not of interest, <C>SimplifiedFpSemigroup</C> can be used to
    directly obtain a new fp semigroup isomorphic to the first with reduced
    relations and generators (the mapping is stored as an attribute of the
    output). With these functions, the user never has to consider precisely
    what Tietze transformations to perform, and never has to worry about using
    the <C>StzPresentation</C> object or its associated operations.  They can
    start with an fp semigroup and obtain a simplified fp semigroup.

    <#Include Label="SimplifyFpSemigroup">
    <#Include Label="SimplifiedFpSemigroup">
    <#Include Label="UnreducedFpSemigroup-S">
    <#Include Label="FpTietzeIsomorphism">
  </Section>
</Chapter>
