GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
1[1m[4m[31m9. Stallings foldings[0m234[1m[4m[31m9.1 Some theory[0m567[1m[4m[31m9.2 Foldings[0m89A finitely generated subgroup of a finitely generated free group is given10through a list whose first element is the number of generators of the free11group and the remaining elements are the generators of the subgroup.1213A generator of the subgroup may be given through a string of letters or14through a list of positive integers as decribed in what follows.1516When the free group has n generators, the n+j^th letter of the alphabet17should be used to represent the formal inverse of the j^th generator which18is represented by the j^th letter. The number of generators of the free19group must not exceed 7.2021For example, [22m[32m[2,"abc","bbabcd"][0m means the subgroup of the free group on 222generators generated by aba^-1 and bbaba^-1b^-1. The same subgroup may be23given as [22m[32m[2,[1,2,3],[2,2,1,2,3,4]][0m2425[1m[4m[31m9.2-1 FlowerAutomaton[0m2627[1m[34m> FlowerAutomaton( [0m[22m[34mL[0m[1m[34m ) _____________________________________________[0mfunction2829The argument [22m[32mL[0m is a subgroup of the free group given through any of the30representations described above.3132[1m[4m[31m9.2-2 FoldFlowerAutomaton[0m3334[1m[34m> FoldFlowerAutomaton( [0m[22m[34mA[0m[1m[34m ) _________________________________________[0mfunction3536Makes identifications on the flower automaton [22m[32mA[0m37383940