Finitely presented groups in Sage
===================================================
#Most of the following computations are actually performed by Gap (see https://www.gap-system.org/)
#Gap has a different syntax, but comes with sage. To start it from the terminal prompt, enter "sage-gap".
====== Free groups
#Multiple ways of defining them
F. = FreeGroup(); F
FreeGroup(3)
FreeGroup('a,b,c')
FreeGroup(3,'t')
#words can also be written down in multiple ways
a*b*c*a
F([1,2,3,1])
x = a^2 * b^(-3) * a^(-2)
x.Tietze
#We can also replace the generators by arbitrary ring elements
g = a * b / c * b^2
M1 = identity_matrix(2)
M2 = matrix([[1,1],[0,1]])
M3 = matrix([[0,1],[1,0]])
g([M1, M2, M3])
g(1,2,3)
====== Finitely presented groups
G = F / [a^2, b^2, c^2, a*b*c*a*b*c]
#Referencing the elements of G
G.gen(0) * G.gen(1)
G([1,2,-1])
#Up until now, a, b and c still reference elements of F
a.parent()
#We can change this though.
G.inject_variables()
a.parent()
#Elements of G and F are not the same!
F([1])
G([1])
F([1]) is G([1])
#We can convert them from one parent to the other, though.
G(a*b/c)
F(G(a*b/c))
#Finitely presented groups are implemented via GAP. If you know what you are doing, you can access the underlying LibGap object.
G.gap()
#This can be used to call GAP functions which are not yet wrapped in Sage. However, it can also cause you some trouble.
#As for free abelian groups, we can call syntax to replace the generators with a set of arbitrary ring elements, which satisfy the relations of the group.
G = FreeGroup(2)
G_ab = G / [G([1, 2, -1, -2])];
a,b = G_ab.gens()
g = a * b
M1 = matrix([[1,0],[0,2]])
M2 = matrix([[0,1],[1,0]])
g(3, 5)
g(M1, M1)
g(M1, M2)
M1*M2 == M2*M1
##Character tables and Cayley graph
#I
G.character_table()
F. = FreeGroup();
G = F / [a^2*b^(-2), a*b*a*b^(-1)]
G.character_table()
G.cayley_table()
G.cayley_graph()
show(G.cayley_graph())
#A3
G=AlternatingGroup(3)
G.cayley_table()
show(G.cayley_graph())
#A4
G=AlternatingGroup(4)
G.cayley_table()
show(G.cayley_graph())
#A5
G=AlternatingGroup(5)
G.cayley_table()
show(G.cayley_graph())
Finitely presented groups in GAP
=============================
f := FreeGroup( "a", "b" );;
g:=f/[f.1^2*f.2^(-2),f.1*f.2*f.1*f.2^(-1)];
CharacterTable( g );;
PrintCharacterTable( CharacterTable( g ), "tbl" );