  
  [1XC Inverse automata and subgroups of the free group[0X
  
  Inverse  automata  with a single initial/accepting state are in a one to one
  correspondence  with finitely generated subgroups of the free group over the
  alphabet  of  the automaton. See [MSW01], [KM02] for details, as well as for
  concepts such as [13Xflower automaton[0m and [13XStallings foldings[0m.
  
  
  [1XC.1 From subgroups to inverse automata[0X
  
  A  finitely  generated  subgroup of a finitely generated free group is given
  through  a  list whose first element is the number of generators of the free
  group and the remaining elements are the generators of the subgroup. The set
  of generators of the free group of rank n consists on the n first letters of
  the  set  {a,b,c,d,e,f,g}. In particular, free groups of rank greater than 8
  must  not  be  considered. A formal inverse of a generator is represented by
  the corresponding capital letter.
  
  A  generator  of  the  subgroup  may be given through a string of letters or
  through a list of positive integers as should be clear from the example that
  follows.
  
  For example, [10X[2,"abA","bbabAB"][0m stands for the subgroup of the free group of
  rank  2  on the generators aba^-1 and bbaba^-1b^-1. The same subgroup may be
  given  as  [10X[2,[1,2,3],[2,2,1,2,3,4]][0m.  The  number n+j represents the formal
  inverse   of   the   generator  represented  by  j.  One  can  go  from  one
  representation to another, using the following functions.
  
  [1XC.1-1 GeneratorsToListRepresentation[0m
  
  [2X> GeneratorsToListRepresentation( [0X[3XL[0X[2X ) ______________________________[0Xfunction
  
  [4X---------------------------  Example  ----------------------------[0X
    [4Xgap> L:=[2,"abA","bbabAB"];;[0X
    [4Xgap> GeneratorsToListRepresentation(L);[0X
    [4X[ 2, [ 1, 2, 3 ], [ 2, 2, 1, 2, 3, 4 ] ][0X
  [4X------------------------------------------------------------------[0X
  
  [1XC.1-2 ListToGeneratorsRepresentation[0m
  
  [2X> ListToGeneratorsRepresentation( [0X[3XK[0X[2X ) ______________________________[0Xfunction
  
  [4X---------------------------  Example  ----------------------------[0X
    [4Xgap> K:=[2,[1,2,3],[2,2,1,2,3,4]];;[0X
    [4Xgap> ListToGeneratorsRepresentation(K);[0X
    [4X[ 2, "abA", "bbabAB" ][0X
  [4X------------------------------------------------------------------[0X
  
  [1XC.1-3 FlowerAutomaton[0m
  
  [2X> FlowerAutomaton( [0X[3XL[0X[2X ) _____________________________________________[0Xfunction
  
  The  argument  [10XL[0m  is  a  subgroup of the free group given through any of the
  representations described above. Returns the flower automaton.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4Xgap> W:=[2,"bbbAB","abAbA"];;[0X
    [4Xgap> A:=FlowerAutomaton(W);[0X
    [4X< non deterministic automaton on 2 letters with 9 states >[0X
    [4Xgap> Display(A);[0X
    [4X   |  1          2       3       4    5       6       7    8       9[0X
    [4X---------------------------------------------------------------------[0X
    [4X a | [ 6, 9 ]                        [ 4 ]                [ 7 ][0X
    [4X b | [ 2, 5 ]   [ 3 ]   [ 4 ]                [ 7 ]        [ 9 ][0X
    [4XInitial state:   [ 1 ][0X
    [4XAccepting state: [ 1 ][0X
  [4X------------------------------------------------------------------[0X
  
  [1XC.1-4 FoldFlowerAutomaton[0m
  
  [2X> FoldFlowerAutomaton( [0X[3XA[0X[2X ) _________________________________________[0Xfunction
  
  Makes  identifications  on  the flower automaton [10XA[0m. In the literature, these
  identifications are called Stallings foldings.
  
  (This  function  may  have  [10Xtrue[0m  as  a second argument. WARNING: the second
  argument should only be used when facilities to draw automata are available.
  In that case, one may visualize the identifications that are taking place.)
  
  [4X---------------------------  Example  ----------------------------[0X
    [4Xgap> B := FoldFlowerAutomaton(A);[0X
    [4X< deterministic automaton on 2 letters with 7 states >[0X
    [4Xgap> Display(B);[0X
    [4X   |  1  2  3  4  5  6  7[0X
    [4X--------------------------[0X
    [4X a |  5  4              6[0X
    [4X b |  2  3  4     6     5[0X
    [4XInitial state:   [ 1 ][0X
    [4XAccepting state: [ 1 ][0X
  [4X------------------------------------------------------------------[0X
  
  [1XC.1-5 SubgroupGenToInvAut[0m
  
  [2X> SubgroupGenToInvAut( [0X[3XL[0X[2X ) _________________________________________[0Xfunction
  
  Returns the inverse automaton corresponding to the subgroup given by [3XL[0m.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4Xgap> L:=[2,"bbbAB","AbAbA"];;[0X
    [4Xgap> SubgroupGenToInvAut(L);[0X
    [4X< deterministic automaton on 2 letters with 8 states >[0X
    [4Xgap> Display(last);[0X
    [4X   |  1  2  3  4  5  6  7  8[0X
    [4X-----------------------------[0X
    [4X a |  8  4        1     6[0X
    [4X b |  2  3  4     6     8[0X
    [4XInitial state:   [ 1 ][0X
    [4XAccepting state: [ 1 ][0X
    [4X[0X
  [4X------------------------------------------------------------------[0X
  
  
  [1XC.2 From inverse automata to subgroups[0X
  
  Given  an  inverse  automaton with a single initial/accepting state, one can
  find  a  set  of  generators  for the subgroup represented by the automaton.
  Moreover,  using  a  geodesic  tree,  one  can find a Nielsen reduced set of
  generators [KM02].
  
  [1XC.2-1 GeodesicTreeOfInverseAutomaton[0m
  
  [2X> GeodesicTreeOfInverseAutomaton( [0X[3XA[0X[2X ) ______________________________[0Xfunction
  
  Returns  a subautomaton of [3XA[0mwhose underlying graph is a geodesic tree of the
  underlying graph of the inverse automaton [10XA[0m.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4Xgap> A:=Automaton("det",4,2,[ [ 3, 4, 0, 0 ], [ 2, 3, 4, 0 ] ],[ 1 ],[ 1 ]);;[0X
    [4Xgap> G := GeodesicTreeOfInverseAutomaton(A);[0X
    [4X< deterministic automaton on 2 letters with 4 states >[0X
    [4Xgap> Display(G);[0X
    [4X   |  1  2  3  4[0X
    [4X-----------------[0X
    [4X a |  3[0X
    [4X b |  2     4[0X
    [4XInitial state:   [ 1 ][0X
    [4XAccepting state: [ 1 ][0X
  [4X------------------------------------------------------------------[0X
  
  [1XC.2-2 InverseAutomatonToGenerators[0m
  
  [2X> InverseAutomatonToGenerators( [0X[3XA[0X[2X ) ________________________________[0Xfunction
  
  Returns  a  set of generators (given trough the representation above) of the
  subgroup of the free group corresponding to the automaton [10XA[0m given.
  
  [4X---------------------------  Example  ----------------------------[0X
    [4Xgap> NW := InverseAutomatonToGenerators(A);[0X
    [4X[ 2, "baBA", "bbA" ][0X
  [4X------------------------------------------------------------------[0X
  
