  
  [1X2. Rewriting Systems[0X
  
  This chapter describes functions to construct rewriting systems for finitely
  presented  groups  which  store rewriting information. The example used is a
  presentation  of  the  quaternion  group [10Xq8[0X with generators a,b and relators
  [a^4, b^4, abab^-1, a^2b^2].
  
  
  [1X2.1 Identity Y-sequences[0X
  
  A  typical input for [5XIdRel[0X is an fp-group presentation. This requires a free
  group  [10XF[0X  on  a set of generators and a set of relators [10XR[0X (words in the free
  group).  The  module of identities among relations for this presentation has
  as  its  elements  the  Peiffer  equivalence  classes  of  all  products  of
  conjugates of relators which represent the identity in the free group.
  
  In   this   package  the  identities  among  relations  are  represented  by
  Y-sequences,  which  are  lists [[r_1, u_1],...,[r_k,u_k]] where r_1,...,r_k
  are  the  group relators or their inverses, and u_1,...,u_k are words in the
  free   group   [10XF[0X.   A   Y-sequence   is   evaluated  in  [10XF[0X  as  the  product
  (u_1^-1r_1u_1)...(u_k^-1r_ku_k)   and   is  an  identity  Y-sequence  if  it
  evaluates  to  the  identity  in  [10XF[0X.  An  identity  Y-sequence represents an
  identity  among the relators of the group presentation. The main function of
  the package is to produce a set of Y-sequences which generated the module of
  identites  among  relations,  and  further,  that this set be minimal in the
  sense that every element in it is needed to generate the module.
  
  We  now  give  a  simple  example  to  illustrate  the use of [5XIdRel[0X. All the
  functions  used are described in detail in this manual. We compute a reduced
  set  of  identities  among  relations  for the presentation of the symmetric
  group [10Xs3[0X with generators a,b and relators [a^3 , b^2, (ab)^2].
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> F := FreeGroup( 2 );[0X
    [4X<free group on the generators [ fl, f2]>[0X
    [4Xgap> a := F.l;; b:= F.2;;[0X
    [4Xgap> rels := [ a^3 , b^2, a*b*a*b];[0X
    [4X[ fl^3 , f2^2, fl*f2*fl*f2] [0X
    [4Xgap> s3 := F/rels;[0X
    [4X<fp group on the generators [ fl, f2 ]> [0X
    [4Xgap> idrels3 := IdentitiesAmongRelators( s3 );;[0X
    [4Xgap> Display( idrels3 );[0X
    [4X[ [ ( FY4*( <identity ...>, FR1*( mon1 - <identity ...> ), [0X
    [4X    ( FY8*( <identity ...>, FR2*( mon2 - <identity ...> ), [0X
    [4X    ( FY7*( mon2*mon1), FR3*( mon2 - mon1) ), [0X
    [4X    ( FY6*( -<identity ...>, FR1*( -mon2*mon1 - mon1) + FR2*( -mon1*mon2 - mo\ [0X
    [4Xnl - <identity ...> + FR3 *( mon3 + mon2 + <identity ...> ) ],[0X
    [4X  [ ( FY4*( <identity ...>, FR1*( mon1 - <identity ...> ), [0X
    [4X    ( FY8*( <identity ...>, FR2*( mon2 - <identity ...> ), [0X
    [4X    ( FY7*( mon2*mon1), FR3 *( mon2 - mon1) ), [0X
    [4X    ( FY4*( -mon2*mon1 + <identity ...> + FY6*( -<identity ...> + FY7*( -mon\ [0X
    [4X2*mon1) + FY8*( mon3 ) , FR1*( -mon2 - <identity ...> + FR2*( -mon3 - mon1 - <i[0X
    [4Xdentity ...> + FR3*( mon3 + mon1 + <identity ...>) ) ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X2.2 Monoid Presentations of FpGroups[0X
  
  [1X2.2-1 FreeRelatorGroup[0X
  
  [2X> FreeRelatorGroup( [0X[3Xgrp[0X[2X ) _________________________________________[0Xattribute
  [2X> FreeRelatorHomomorphism( [0X[3Xgrp[0X[2X ) __________________________________[0Xattribute
  
  The function [10XFreeRelatorGroup[0X returns a free group on the set of relators of
  the  given  fp-group  [10XG[0X.  If [10XHasName(G)[0X is [10Xtrue[0X then a name is automatically
  assigned to the free group.
  
  The function [10XFreeRelatorHomomorphism[0X returns the group homomorphism from the
  free group on the relators to the free group on the generators of [10XG[0X, mapping
  each generator to the corresponding word.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> F := FreeGroup( 2 );;[0X
    [4Xgap> a := F.1;; b:= F.2;;[0X
    [4Xgap> rels := [ a^4, b^4, a*b*a*b^-1, a^2*b^2];[0X
    [4X[ f1^4, f2^4, f1*f2*f1*f2^-1, f1^2*f2^2] [0X
    [4Xgap> q8 := F/rels;;[0X
    [4Xgap> SetName( q8, "q8" );[0X
    [4Xgap> frq8 := FreeRelatorGroup( q8 );[0X
    [4Xq8_R [0X
    [4Xgap> GeneratorsOfGroup( frq8 );[0X
    [4X[ q8_R1, q8_R2, q8_R3, q8_R4][0X
    [4Xgap> frhomq8 := FreeRelatorHomomorphism( q8 );[0X
    [4X[ q8_R1, q8_R2, q8_R3, q8_R4] -> [ f1^4, f2^4, f1*f2*f1*f2^-1, f1^2*f2^2][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [1X2.2-2 MonoidPresentationFpGroup[0X
  
  [2X> MonoidPresentationFpGroup( [0X[3Xgrp[0X[2X ) ________________________________[0Xattribute
  [2X> FreeGroupOfPresentation( [0X[3Xmon[0X[2X ) __________________________________[0Xattribute
  [2X> GroupRelatorsOfPresentation( [0X[3Xmon[0X[2X ) ______________________________[0Xattribute
  [2X> InverseRelatorsOfPresentation( [0X[3Xmon[0X[2X ) ____________________________[0Xattribute
  [2X> HomomorphismOfPresentation( [0X[3Xmon[0X[2X ) _______________________________[0Xattribute
  
  A  monoid  presentation  for  a  finitely  presented  group [10XG[0X has two monoid
  generators  g^+,g^-  for  each group generator g. The relators of the monoid
  presentation comprise the group relators, and relators g^+g^- specifying the
  inverses.   The   function   [10XMonoidPresentationFpGroup[0X  returns  the  monoid
  presentation  derived  in  this  way  from  an  fp-presentation. (Note: this
  function   should   always   be   followed   by   a   double   semicolon  --
  [10XMonoidPresentationFpGroup(G);;[0X  --  because an error occurs in attempting to
  display the results on the screen: the [10XElementsFamily[0X needs to be fixed.)
  
  The  function  [10XFreeGroupOfPresentation[0X  returns the free group on the monoid
  generators.
  
  The  function  [10XGroupRelatorsOfPresentation[0X  returns  those  relators  of the
  monoid which correspond to the relators of the group. All negative powers in
  the group relators are converted to positive powers of the g^-.
  
  The  function  [10XInverseRelatorsOfPresentation[0X  returns relators which specify
  the inverse pairs of the monoid generators.
  
  The  function  [10XHomomorphismOfPresentation[0X  returns the homomorphism from the
  free  group  of  the  monoid  presentation  to  the  free group of the group
  presentation.
  
  In  the  example  below,  the  four monoid generators a^+, b^+, a^-, b^- are
  named [10Xq8\_M1, q8\_M2, q8\_M3, q8\_M4[0X.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> mon := MonoidPresentationFpgroup( q8 );; [0X
    [4Xgap> fgmon := FreeGroupOfPresentation( mon);[0X
    [4X<free group on the generators [ q8_Ml, q8_M2, q8_M3, q8_M4]> [0X
    [4Xgap> genfgmon := GeneratorsOfGroup( fgmon);[0X
    [4X[ q8_Ml, q8_M2, q8_M3, q8_M4] [0X
    [4Xgap> gprels := GroupRelatorsOfPresentation( mon );[0X
    [4X[ q8_Ml^4, q8_M2^4, q8_Ml*q8_M2*q8_Ml*q8_M4, q8_Ml^2*q8_M2^2] [0X
    [4Xgap> invrels := InverseRelatorsOfPresentation( mon);[0X
    [4X[ q8_Ml*q8_M3, q8_M2*q8_M4, q8_M3*q8_Ml, q8_M4*q8_M2] [0X
    [4Xgap> hompres := HomomorphismOfPresentation( mon );[0X
    [4X[ q8_Ml, q8_M2, q8_M3, q8_M4] -> [ fl, f2, fl^-l, f2^-1 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X2.3 Rewriting systems for FpGroups[0X
  
  These  functions  duplicate  the  standard  Knuth Bendix functions which are
  available  in  the  [5XGAP[0X  library.  There are two reasons for this: (1) these
  functions  were  first written before the standard functions were available;
  (2)  we  require  logged  versions  of  the  functions,  and  these are most
  conveniently extended versions of the non-logged code.
  
  [1X2.3-1 RewritingSystemFpGroup[0X
  
  [2X> RewritingSystemFpGroup( [0X[3Xgrp[0X[2X ) ___________________________________[0Xattribute
  
  This  function  attempts to return a complete rewrite system for the group [10XG[0X
  obtained  from  the  monoid  presentation [10Xmon[0X, with a length-lexicographical
  ordering  on the words in [10Xfgmon[0X, by applying Knuth-Bendix completion. Such a
  rewrite  system can be obtained for all finite groups. The rewrite rules are
  (partially)  ordered,  starting  with  the inverse relators, followed by the
  rules which reduce the word length the most.
  
  In our [10Xq8[0X example there are 16 rewrite rules.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> rws := RewritingSystemFpGroup( q8 );[0X
    [4X[ [q8_Ml*q8_M3, <identity ...>], [ q8_M2*q8_M4, <identity ...> ], [0X
    [4X  [q8_M3*q8_Ml, <identity ...>], [ q8_M4*q8_M2, <identity ...> ], [0X
    [4X  [q8_M1^2*q8_M4, q8_M2], [q8_Ml^2*q8_M2, q8_M4], [ q8_Ml^3, q8_M3 ], [0X
    [4X  [ q8_M4^2, q8_Ml^2], [ q8_M4*q8_M3, q8_Ml*q8_M4], [0X
    [4X  [ q8_M4*q8_Ml, q8_Ml*q8_M2], [q8_M3*q8_M4, q8_Ml*q8_M2], [0X
    [4X  [ q8_M3^2, q8_Ml^2], [q8_M3*q8_M2, q8_Ml*q8_M4], [0X
    [4X  [ q8_M2*q8_M3, q8_Ml*q8_M2], [q8_M2^2, q8_Ml^2], [0X
    [4X  [ q8_M2*q8_Ml, q8_Ml*q8_M4] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  The functions called by [10XRewritingSystemFpGroup[0X are as follows.
  
  [1X2.3-2 OnePassReduceWord[0X
  
  [2X> OnePassReduceWord( [0X[3Xword, rules[0X[2X ) ________________________________[0Xoperation
  [2X> ReduceWordKB( [0X[3Xword, rules[0X[2X ) _____________________________________[0Xoperation
  
  Assuming  that  [10Xword[0X  is  an element of a free monoid and [10Xrules[0X is a list of
  ordered  pairs  of  such  words, the function [10XOnePassReduceWord[0X searches the
  list  of rules until it finds that the left-hand side of a [10Xrule[0X is a [10Xsubword[0X
  of  [10Xword[0X, whereupon it replaces that [10Xsubword[0X with the right-hand side of the
  matching  rule.  The  search  is  continued from the next [10Xrule[0X in [10Xrules[0X, but
  using the new [10Xword[0X. When the end of [10Xrules[0X is reached, one pass is considered
  to  have been made and the reduced [10Xword[0X is returned. If no matches are found
  then the original [10Xword[0X is returned.
  
  The  function [10XReduceWordKB[0X repeatedly applies the function [10XOnePassReduceWord[0X
  until  the [10Xword[0X remaining contains no left-hand side of a [10Xrule[0X as a [10Xsubword[0X.
  If  [10Xrules[0X  is  a  complete rewrite system, then the irreducible [10Xword[0X that is
  returned is unique, otherwise the order of the rules in [10Xrules[0X will determine
  which irreducible word is returned.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> monrels := Concatenation( gprels, invrels );[0X
    [4X[ q8_Ml^4, q8_M2^4, q8_Ml*q8_M2*q8_Ml*q8_M4, q8_Ml^2*q8_M2^2, q8_Ml*q8_M3, [0X
    [4X  q8_M2*q8_M4, q8_M3*q8_Ml, q8_M4*q8_M2] [0X
    [4Xgap> id := One( monrels[l] );;[0X
    [4Xgap> r0 := List( monrels, r -> [ r, id ] );[0X
    [4X[ [ q8_Ml^4, <identity ...> ], [ q8_M2^4, <identity. ..> ], [0X
    [4X  [ q8_Ml*q8_M2*q8_Ml*q8_M4, <identity ...> ], [0X
    [4X  [ q8_Ml^2*q8_M2^2, <identity. ..>], [ q8_Ml*q8_M3, <identity ...> ], [0X
    [4X  [ q8_M2*q8_M4, <identity ...> ], [ q8_M3*q8_Ml, <identity. ..>], [0X
    [4X  [ q8_M4*q8_M2, <identity ...> ] ] [0X
    [4Xgap> ap := genfgmon[l];; bp := genfgmon[2];;   ## p for plus[0X
    [4Xgap> am := genfgmon[3];; bm := genfgmon[4];;   ## m for minus[0X
    [4Xgap> w0 := (ap^3 * bp^3)^3;[0X
    [4Xq8_Ml^3*q8_M2^3*q8_Ml^3*q8_M2^3*q8_Ml^3*q8_M2^3 [0X
    [4Xgap> w1 := OnePassReduceWord( w0, r0 );[0X
    [4Xq8_Ml*q8_M2*q8_Ml^3*q8_M2^3*q8_Ml^3*q8_M2^3 [0X
    [4Xgap> w2 := ReduceWordKB( w0, r0 );[0X
    [4Xq8_Ml*q8_M2*q8_Ml*q8_M2*q8_Ml*q8_M2[0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  [1X2.3-3 OnePassKB[0X
  
  [2X> OnePassKB( [0X[3Xrules[0X[2X ) ______________________________________________[0Xoperation
  [2X> RewriteReduce( [0X[3Xrules[0X[2X ) __________________________________________[0Xoperation
  [2X> KnuthBendix( [0X[3Xrules[0X[2X ) ____________________________________________[0Xoperation
  [2X> ShorterRule( [0X[3Xrule1, rule2[0X[2X ) _____________________________________[0Xoperation
  
  The  function  [10XOnePassKB[0X  implements  the  main  loop  of  the  Knuth-Bendix
  completion algorithm. Rules are compared with each other; all critical pairs
  are  calculated;  and  the  irreducible  critical  pairs are orientated with
  respect  to  the  length-lexicographical  ordering  and added to the rewrite
  system.
  
  The  function  [10XRewriteReduce[0X  will  remove  unnecessary rules from a rewrite
  system.  A  rule  is  deemed to be unnecessary if it is implied by the other
  rules,  i.e. if both sides can be reduced to the same thing by the remaining
  rules.
  
  The  function  [10XKnuthBendix[0X implements the Knuth-Bendix algorithm, attempting
  to  complete  a  rewrite  system  with  respect  to  a  length-lexicographic
  ordering.  It  calls  first  [10XOnePassKB[0X,  which  adds  rules,  and  then (for
  efficiency) [10XRewriteReduce[0X which removes any unnecessary ones. This procedure
  is  repeated  until  [10XOnePassKB[0X  adds  no  more  rules.  It  will  not always
  terminate,  but for many examples (all finite groups) it will be successful.
  The  rewrite system returned is complete, that is: it will rewrite any given
  word  in  the  free monoid to a unique irreducible; there is one irreducible
  for  each  element  of the quotient monoid; and any two elements of the free
  monoid which are in the same class will rewrite to the same irreducible.
  
  The  function [10XShorterRule[0X gives an ordering on rules. Rules (g_lg_2,id) that
  identify  two  generators (or one generator with the inverse of another) are
  considered  to  be  the  best. Otherwise one rule is considered to be better
  than another if it reduces the length of a word by a greater amount.
  
  One  pass  of  this  procedure  for  our  [10Xq8[0X example adds 13 relators to the
  original  8, and these 21 are then reduced to 9. A second pass and reduction
  gives  a  list  of  16  rules  which forms a complete rewrite system for the
  group.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> r1 := OnePassKB( r0 );[0X
    [4X[ [ q8_Ml^4, <identity ...> ], [ q8_M2^4, <identity ...> ], [0X
    [4X  [ q8_Ml*q8_M2*q8_Ml*q8_M4, <identity ...> ], [0X
    [4X  [ q8_Ml^2*q8_M2^2, <identity. ..> ], [ q8_Ml*q8_M3, <identity ...> ], [0X
    [4X  [ q8_M2*q8_M4, <identity ...> ], [ q8_M3*q8_Ml, <identity ...> ], [0X
    [4X  [ q8_M4*q8_M2, <identity ...> ], [ q8_M2*q8_Ml*q8_M4, q8_Ml^3], [0X
    [4X  [ q8_Ml*q8_M2^2, q8_Ml^3 ], [ q8_M2^2, q8_Ml^2 ], [q8_Ml^3, q8_M3 ], [0X
    [4X  [ q8_M2^3, q8_M4 ], [ q8_Ml*q8_M2*q8_Ml, q8_M2], [0X
    [4X  [ q8_M2^3, q8_Ml^2*q8_M2], [ q8_M2^2, q8_Ml^2 ], [q8_Ml^2*q8_M2, q8_M4 ], [0X
    [4X  [ q8_Ml^3, q8_M3 ], [ q8_M2*q8_Ml*q8_M4, q8_M3 ], [q8_Ml*q8_M2^2, q8_M3 ], [0X
    [4X  [ q8_M2^3, q8_M4 ] ] [0X
    [4Xgap> r1 := RewriteReduce( r1 );[0X
    [4X[ [ q8_Ml*q8_M3, <identity ...> ], [ q8_M2^2, q8_Ml^2 ], [0X
    [4X  [ q8_M2*q8_M4, <identity ...> ], [ q8_M3*q8_Ml, <identity ...> ], [0X
    [4X  [ q8_M4*q8_M2, <identity ...> ], [ q8_Ml^3, q8_M3 ], [0X
    [4X  [ q8_Ml^2*q8_M2, q8_M4 ], [ q8_Ml*q8_M2*q8_Ml, q8_M2 ], [0X
    [4X  [ q8_M2*q8_Ml*q8_M4, q8_M3 ] ] [0X
    [4Xgap> Length( r1 );[0X
    [4X9 [0X
    [4Xgap> r2 := KnuthBendix( r1 );[0X
    [4X[ [ q8_Ml*q8_M3, <identity ...> ], [ q8_M2*q8_Ml, q8_Ml*q8_M4 ], [0X
    [4X  [ q8_M2^2, q8_Ml^2], [ q8_M2*q8_M3, q8_Ml*q8_M2 ], [0X
    [4X  [ q8_M2*q8_M4, <identity ...> ], [ q8_M3*q8_Ml, <identity ...> ], [0X
    [4X  [ q8_M3*q8_M2, q8_Ml*q8_M4 ], [ q8_M3^2, q8_Ml^2 ], [0X
    [4X  [ q8_M3*q8_M4, q8_Ml*q8_M2 ], [ q8_M4*q8_Ml, q8_Ml*q8_M2 ], [0X
    [4X  [ q8_M4*q8_M2, <identity ...> ], [ q8_M4*q8_M3, q8_Ml*q8_M4 ], [0X
    [4X  [ q8_M4^2, q8_Ml^2], [ q8_Ml^3, q8_M3 ], [q8_Ml^2*q8_M2, q8_M4 ], [0X
    [4X  [ q8_Ml^2*q8_M4, q8_M2 ] ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1X2.4 Enumerating elements[0X
  
  [1X2.4-1 ElementsOfMonoidPresentation[0X
  
  [2X> ElementsOfMonoidPresentation( [0X[3Xmon[0X[2X ) _____________________________[0Xattribute
  
  The function [10XElementsOfMonoidPresentation[0X returns a list of normal forms for
  the  elements  of the group given by the monoid presentation [10Xmon[0X. The normal
  forms are in fact the least elements in each equivalence class (with respect
  to  the length-lex order). The function [10XEnumerateKB[0X builds up a catalogue of
  irreducible  words  in  the  generators of a monoid with respect to a set of
  rules.  When [10Xrules[0X is a complete rewrite system for [10XG[0X the list returned is a
  set of normal forms for the group elements.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4X[0X
    [4Xgap> elq8 := Elements( q8 );[0X
    [4X[ <identity .. .>, fl, f2, fl^2, fl*f2, fl^3*f2, fl^3, fl^2*f2 ] [0X
    [4Xgap> elmonq8 := ElementsOfMonoidPresentation( monq8 );[0X
    [4X[ <identity. ..>, q8_Ml, q8_M2, q8_M3, q8_M4, q8_Ml^2, q8_Ml*q8_M2, [0X
    [4X  q8_Ml*q8_M4 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
