  
  [1m[4m[31m2. Rewriting Systems[0m
  
  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 [22m[32mq8[0m with generators a,b and relators
  [a^4, b^4, abab^-1, a^2b^2].
  
  
  [1m[4m[31m2.1 Identity Y-sequences[0m
  
  A  typical input for [1mIdRel[0m is an fp-group presentation. This requires a free
  group  [22m[32mF[0m  on  a set of generators and a set of relators [22m[32mR[0m (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   [22m[32mF[0m.   A   Y-sequence   is   evaluated  in  [22m[32mF[0m  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  [22m[32mF[0m.  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 [1mIdRel[0m. 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 [22m[32ms3[0m with generators a,b and relators [a^3 , b^2, (ab)^2].
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35m[0m
    [22m[35mgap> F := FreeGroup( 2 );[0m
    [22m[35m<free group on the generators [ fl, f2]>[0m
    [22m[35mgap> a := F.l;; b:= F.2;;[0m
    [22m[35mgap> rels := [ a^3 , b^2, a*b*a*b];[0m
    [22m[35m[ fl^3 , f2^2, fl*f2*fl*f2] [0m
    [22m[35mgap> s3 := F/rels;[0m
    [22m[35m<fp group on the generators [ fl, f2 ]> [0m
    [22m[35mgap> idrels3 := IdentitiesAmongRelators( s3 );;[0m
    [22m[35mgap> Display( idrels3 );[0m
    [22m[35m[ [ ( FY4*( <identity ...>, FR1*( mon1 - <identity ...> ), [0m
    [22m[35m    ( FY8*( <identity ...>, FR2*( mon2 - <identity ...> ), [0m
    [22m[35m    ( FY7*( mon2*mon1), FR3*( mon2 - mon1) ), [0m
    [22m[35m    ( FY6*( -<identity ...>, FR1*( -mon2*mon1 - mon1) + FR2*( -mon1*mon2 - mo\ [0m
    [22m[35mnl - <identity ...> + FR3 *( mon3 + mon2 + <identity ...> ) ],[0m
    [22m[35m  [ ( FY4*( <identity ...>, FR1*( mon1 - <identity ...> ), [0m
    [22m[35m    ( FY8*( <identity ...>, FR2*( mon2 - <identity ...> ), [0m
    [22m[35m    ( FY7*( mon2*mon1), FR3 *( mon2 - mon1) ), [0m
    [22m[35m    ( FY4*( -mon2*mon1 + <identity ...> + FY6*( -<identity ...> + FY7*( -mon\ [0m
    [22m[35m2*mon1) + FY8*( mon3 ) , FR1*( -mon2 - <identity ...> + FR2*( -mon3 - mon1 - <i[0m
    [22m[35mdentity ...> + FR3*( mon3 + mon1 + <identity ...>) ) ] ][0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m2.2 Monoid Presentations of FpGroups[0m
  
  [1m[4m[31m2.2-1 FreeRelatorGroup[0m
  
  [1m[34m> FreeRelatorGroup( [0m[22m[34mgrp[0m[1m[34m ) _________________________________________[0mattribute
  [1m[34m> FreeRelatorHomomorphism( [0m[22m[34mgrp[0m[1m[34m ) __________________________________[0mattribute
  
  The function [22m[32mFreeRelatorGroup[0m returns a free group on the set of relators of
  the  given  fp-group  [22m[32mG[0m.  If [22m[32mHasName(G)[0m is [22m[32mtrue[0m then a name is automatically
  assigned to the free group.
  
  The function [22m[32mFreeRelatorHomomorphism[0m returns the group homomorphism from the
  free group on the relators to the free group on the generators of [22m[32mG[0m, mapping
  each generator to the corresponding word.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35m[0m
    [22m[35mgap> F := FreeGroup( 2 );;[0m
    [22m[35mgap> a := F.1;; b:= F.2;;[0m
    [22m[35mgap> rels := [ a^4, b^4, a*b*a*b^-1, a^2*b^2];[0m
    [22m[35m[ f1^4, f2^4, f1*f2*f1*f2^-1, f1^2*f2^2] [0m
    [22m[35mgap> q8 := F/rels;;[0m
    [22m[35mgap> SetName( q8, "q8" );[0m
    [22m[35mgap> frq8 := FreeRelatorGroup( q8 );[0m
    [22m[35mq8_R [0m
    [22m[35mgap> GeneratorsOfGroup( frq8 );[0m
    [22m[35m[ q8_R1, q8_R2, q8_R3, q8_R4][0m
    [22m[35mgap> frhomq8 := FreeRelatorHomomorphism( q8 );[0m
    [22m[35m[ q8_R1, q8_R2, q8_R3, q8_R4] -> [ f1^4, f2^4, f1*f2*f1*f2^-1, f1^2*f2^2][0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m2.2-2 MonoidPresentationFpGroup[0m
  
  [1m[34m> MonoidPresentationFpGroup( [0m[22m[34mgrp[0m[1m[34m ) ________________________________[0mattribute
  [1m[34m> FreeGroupOfPresentation( [0m[22m[34mmon[0m[1m[34m ) __________________________________[0mattribute
  [1m[34m> GroupRelatorsOfPresentation( [0m[22m[34mmon[0m[1m[34m ) ______________________________[0mattribute
  [1m[34m> InverseRelatorsOfPresentation( [0m[22m[34mmon[0m[1m[34m ) ____________________________[0mattribute
  [1m[34m> HomomorphismOfPresentation( [0m[22m[34mmon[0m[1m[34m ) _______________________________[0mattribute
  
  A  monoid  presentation  for  a  finitely  presented  group [22m[32mG[0m 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   [22m[32mMonoidPresentationFpGroup[0m  returns  the  monoid
  presentation  derived  in  this  way  from  an  fp-presentation. (Note: this
  function   should   always   be   followed   by   a   double   semicolon  --
  [22m[32mMonoidPresentationFpGroup(G);;[0m  --  because an error occurs in attempting to
  display the results on the screen: the [22m[32mElementsFamily[0m needs to be fixed.)
  
  The  function  [22m[32mFreeGroupOfPresentation[0m  returns the free group on the monoid
  generators.
  
  The  function  [22m[32mGroupRelatorsOfPresentation[0m  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  [22m[32mInverseRelatorsOfPresentation[0m  returns relators which specify
  the inverse pairs of the monoid generators.
  
  The  function  [22m[32mHomomorphismOfPresentation[0m  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 [22m[32mq8\_M1, q8\_M2, q8\_M3, q8\_M4[0m.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35m[0m
    [22m[35mgap> mon := MonoidPresentationFpgroup( q8 );; [0m
    [22m[35mgap> fgmon := FreeGroupOfPresentation( mon);[0m
    [22m[35m<free group on the generators [ q8_Ml, q8_M2, q8_M3, q8_M4]> [0m
    [22m[35mgap> genfgmon := GeneratorsOfGroup( fgmon);[0m
    [22m[35m[ q8_Ml, q8_M2, q8_M3, q8_M4] [0m
    [22m[35mgap> gprels := GroupRelatorsOfPresentation( mon );[0m
    [22m[35m[ q8_Ml^4, q8_M2^4, q8_Ml*q8_M2*q8_Ml*q8_M4, q8_Ml^2*q8_M2^2] [0m
    [22m[35mgap> invrels := InverseRelatorsOfPresentation( mon);[0m
    [22m[35m[ q8_Ml*q8_M3, q8_M2*q8_M4, q8_M3*q8_Ml, q8_M4*q8_M2] [0m
    [22m[35mgap> hompres := HomomorphismOfPresentation( mon );[0m
    [22m[35m[ q8_Ml, q8_M2, q8_M3, q8_M4] -> [ fl, f2, fl^-l, f2^-1 ][0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m2.3 Rewriting systems for FpGroups[0m
  
  These  functions  duplicate  the  standard  Knuth Bendix functions which are
  available  in  the  [1mGAP[0m  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.
  
  [1m[4m[31m2.3-1 RewritingSystemFpGroup[0m
  
  [1m[34m> RewritingSystemFpGroup( [0m[22m[34mgrp[0m[1m[34m ) ___________________________________[0mattribute
  
  This  function  attempts to return a complete rewrite system for the group [22m[32mG[0m
  obtained  from  the  monoid  presentation [22m[32mmon[0m, with a length-lexicographical
  ordering  on the words in [22m[32mfgmon[0m, 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 [22m[32mq8[0m example there are 16 rewrite rules.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35m[0m
    [22m[35mgap> rws := RewritingSystemFpGroup( q8 );[0m
    [22m[35m[ [q8_Ml*q8_M3, <identity ...>], [ q8_M2*q8_M4, <identity ...> ], [0m
    [22m[35m  [q8_M3*q8_Ml, <identity ...>], [ q8_M4*q8_M2, <identity ...> ], [0m
    [22m[35m  [q8_M1^2*q8_M4, q8_M2], [q8_Ml^2*q8_M2, q8_M4], [ q8_Ml^3, q8_M3 ], [0m
    [22m[35m  [ q8_M4^2, q8_Ml^2], [ q8_M4*q8_M3, q8_Ml*q8_M4], [0m
    [22m[35m  [ q8_M4*q8_Ml, q8_Ml*q8_M2], [q8_M3*q8_M4, q8_Ml*q8_M2], [0m
    [22m[35m  [ q8_M3^2, q8_Ml^2], [q8_M3*q8_M2, q8_Ml*q8_M4], [0m
    [22m[35m  [ q8_M2*q8_M3, q8_Ml*q8_M2], [q8_M2^2, q8_Ml^2], [0m
    [22m[35m  [ q8_M2*q8_Ml, q8_Ml*q8_M4] ][0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  The functions called by [22m[32mRewritingSystemFpGroup[0m are as follows.
  
  [1m[4m[31m2.3-2 OnePassReduceWord[0m
  
  [1m[34m> OnePassReduceWord( [0m[22m[34mword, rules[0m[1m[34m ) ________________________________[0moperation
  [1m[34m> ReduceWordKB( [0m[22m[34mword, rules[0m[1m[34m ) _____________________________________[0moperation
  
  Assuming  that  [22m[32mword[0m  is  an element of a free monoid and [22m[32mrules[0m is a list of
  ordered  pairs  of  such  words, the function [22m[32mOnePassReduceWord[0m searches the
  list  of rules until it finds that the left-hand side of a [22m[32mrule[0m is a [22m[32msubword[0m
  of  [22m[32mword[0m, whereupon it replaces that [22m[32msubword[0m with the right-hand side of the
  matching  rule.  The  search  is  continued from the next [22m[32mrule[0m in [22m[32mrules[0m, but
  using the new [22m[32mword[0m. When the end of [22m[32mrules[0m is reached, one pass is considered
  to  have been made and the reduced [22m[32mword[0m is returned. If no matches are found
  then the original [22m[32mword[0m is returned.
  
  The  function [22m[32mReduceWordKB[0m repeatedly applies the function [22m[32mOnePassReduceWord[0m
  until  the [22m[32mword[0m remaining contains no left-hand side of a [22m[32mrule[0m as a [22m[32msubword[0m.
  If  [22m[32mrules[0m  is  a  complete rewrite system, then the irreducible [22m[32mword[0m that is
  returned is unique, otherwise the order of the rules in [22m[32mrules[0m will determine
  which irreducible word is returned.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35m[0m
    [22m[35mgap> monrels := Concatenation( gprels, invrels );[0m
    [22m[35m[ q8_Ml^4, q8_M2^4, q8_Ml*q8_M2*q8_Ml*q8_M4, q8_Ml^2*q8_M2^2, q8_Ml*q8_M3, [0m
    [22m[35m  q8_M2*q8_M4, q8_M3*q8_Ml, q8_M4*q8_M2] [0m
    [22m[35mgap> id := One( monrels[l] );;[0m
    [22m[35mgap> r0 := List( monrels, r -> [ r, id ] );[0m
    [22m[35m[ [ q8_Ml^4, <identity ...> ], [ q8_M2^4, <identity. ..> ], [0m
    [22m[35m  [ q8_Ml*q8_M2*q8_Ml*q8_M4, <identity ...> ], [0m
    [22m[35m  [ q8_Ml^2*q8_M2^2, <identity. ..>], [ q8_Ml*q8_M3, <identity ...> ], [0m
    [22m[35m  [ q8_M2*q8_M4, <identity ...> ], [ q8_M3*q8_Ml, <identity. ..>], [0m
    [22m[35m  [ q8_M4*q8_M2, <identity ...> ] ] [0m
    [22m[35mgap> ap := genfgmon[l];; bp := genfgmon[2];;   ## p for plus[0m
    [22m[35mgap> am := genfgmon[3];; bm := genfgmon[4];;   ## m for minus[0m
    [22m[35mgap> w0 := (ap^3 * bp^3)^3;[0m
    [22m[35mq8_Ml^3*q8_M2^3*q8_Ml^3*q8_M2^3*q8_Ml^3*q8_M2^3 [0m
    [22m[35mgap> w1 := OnePassReduceWord( w0, r0 );[0m
    [22m[35mq8_Ml*q8_M2*q8_Ml^3*q8_M2^3*q8_Ml^3*q8_M2^3 [0m
    [22m[35mgap> w2 := ReduceWordKB( w0, r0 );[0m
    [22m[35mq8_Ml*q8_M2*q8_Ml*q8_M2*q8_Ml*q8_M2[0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  [1m[4m[31m2.3-3 OnePassKB[0m
  
  [1m[34m> OnePassKB( [0m[22m[34mrules[0m[1m[34m ) ______________________________________________[0moperation
  [1m[34m> RewriteReduce( [0m[22m[34mrules[0m[1m[34m ) __________________________________________[0moperation
  [1m[34m> KnuthBendix( [0m[22m[34mrules[0m[1m[34m ) ____________________________________________[0moperation
  [1m[34m> ShorterRule( [0m[22m[34mrule1, rule2[0m[1m[34m ) _____________________________________[0moperation
  
  The  function  [22m[32mOnePassKB[0m  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  [22m[32mRewriteReduce[0m  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  [22m[32mKnuthBendix[0m implements the Knuth-Bendix algorithm, attempting
  to  complete  a  rewrite  system  with  respect  to  a  length-lexicographic
  ordering.  It  calls  first  [22m[32mOnePassKB[0m,  which  adds  rules,  and  then (for
  efficiency) [22m[32mRewriteReduce[0m which removes any unnecessary ones. This procedure
  is  repeated  until  [22m[32mOnePassKB[0m  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 [22m[32mShorterRule[0m 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  [22m[32mq8[0m 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.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35m[0m
    [22m[35mgap> r1 := OnePassKB( r0 );[0m
    [22m[35m[ [ q8_Ml^4, <identity ...> ], [ q8_M2^4, <identity ...> ], [0m
    [22m[35m  [ q8_Ml*q8_M2*q8_Ml*q8_M4, <identity ...> ], [0m
    [22m[35m  [ q8_Ml^2*q8_M2^2, <identity. ..> ], [ q8_Ml*q8_M3, <identity ...> ], [0m
    [22m[35m  [ q8_M2*q8_M4, <identity ...> ], [ q8_M3*q8_Ml, <identity ...> ], [0m
    [22m[35m  [ q8_M4*q8_M2, <identity ...> ], [ q8_M2*q8_Ml*q8_M4, q8_Ml^3], [0m
    [22m[35m  [ q8_Ml*q8_M2^2, q8_Ml^3 ], [ q8_M2^2, q8_Ml^2 ], [q8_Ml^3, q8_M3 ], [0m
    [22m[35m  [ q8_M2^3, q8_M4 ], [ q8_Ml*q8_M2*q8_Ml, q8_M2], [0m
    [22m[35m  [ q8_M2^3, q8_Ml^2*q8_M2], [ q8_M2^2, q8_Ml^2 ], [q8_Ml^2*q8_M2, q8_M4 ], [0m
    [22m[35m  [ q8_Ml^3, q8_M3 ], [ q8_M2*q8_Ml*q8_M4, q8_M3 ], [q8_Ml*q8_M2^2, q8_M3 ], [0m
    [22m[35m  [ q8_M2^3, q8_M4 ] ] [0m
    [22m[35mgap> r1 := RewriteReduce( r1 );[0m
    [22m[35m[ [ q8_Ml*q8_M3, <identity ...> ], [ q8_M2^2, q8_Ml^2 ], [0m
    [22m[35m  [ q8_M2*q8_M4, <identity ...> ], [ q8_M3*q8_Ml, <identity ...> ], [0m
    [22m[35m  [ q8_M4*q8_M2, <identity ...> ], [ q8_Ml^3, q8_M3 ], [0m
    [22m[35m  [ q8_Ml^2*q8_M2, q8_M4 ], [ q8_Ml*q8_M2*q8_Ml, q8_M2 ], [0m
    [22m[35m  [ q8_M2*q8_Ml*q8_M4, q8_M3 ] ] [0m
    [22m[35mgap> Length( r1 );[0m
    [22m[35m9 [0m
    [22m[35mgap> r2 := KnuthBendix( r1 );[0m
    [22m[35m[ [ q8_Ml*q8_M3, <identity ...> ], [ q8_M2*q8_Ml, q8_Ml*q8_M4 ], [0m
    [22m[35m  [ q8_M2^2, q8_Ml^2], [ q8_M2*q8_M3, q8_Ml*q8_M2 ], [0m
    [22m[35m  [ q8_M2*q8_M4, <identity ...> ], [ q8_M3*q8_Ml, <identity ...> ], [0m
    [22m[35m  [ q8_M3*q8_M2, q8_Ml*q8_M4 ], [ q8_M3^2, q8_Ml^2 ], [0m
    [22m[35m  [ q8_M3*q8_M4, q8_Ml*q8_M2 ], [ q8_M4*q8_Ml, q8_Ml*q8_M2 ], [0m
    [22m[35m  [ q8_M4*q8_M2, <identity ...> ], [ q8_M4*q8_M3, q8_Ml*q8_M4 ], [0m
    [22m[35m  [ q8_M4^2, q8_Ml^2], [ q8_Ml^3, q8_M3 ], [q8_Ml^2*q8_M2, q8_M4 ], [0m
    [22m[35m  [ q8_Ml^2*q8_M4, q8_M2 ] ][0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
  
  [1m[4m[31m2.4 Enumerating elements[0m
  
  [1m[4m[31m2.4-1 ElementsOfMonoidPresentation[0m
  
  [1m[34m> ElementsOfMonoidPresentation( [0m[22m[34mmon[0m[1m[34m ) _____________________________[0mattribute
  
  The function [22m[32mElementsOfMonoidPresentation[0m returns a list of normal forms for
  the  elements  of the group given by the monoid presentation [22m[32mmon[0m. The normal
  forms are in fact the least elements in each equivalence class (with respect
  to  the length-lex order). The function [22m[32mEnumerateKB[0m builds up a catalogue of
  irreducible  words  in  the  generators of a monoid with respect to a set of
  rules.  When [22m[32mrules[0m is a complete rewrite system for [22m[32mG[0m the list returned is a
  set of normal forms for the group elements.
  
  [22m[35m---------------------------  Example  ----------------------------[0m
    [22m[35m[0m
    [22m[35mgap> elq8 := Elements( q8 );[0m
    [22m[35m[ <identity .. .>, fl, f2, fl^2, fl*f2, fl^3*f2, fl^3, fl^2*f2 ] [0m
    [22m[35mgap> elmonq8 := ElementsOfMonoidPresentation( monq8 );[0m
    [22m[35m[ <identity. ..>, q8_Ml, q8_M2, q8_M3, q8_M4, q8_Ml^2, q8_Ml*q8_M2, [0m
    [22m[35m  q8_Ml*q8_M4 ][0m
    [22m[35m[0m
  [22m[35m------------------------------------------------------------------[0m
  
