Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can of course first generate the words, but if the group generated by your generators is far from free on those generators, you will be generating a lot of extraneous entries. In addition M in <List> is much slower than M in <Set>, and sets would take care of repetitions automatically.

Matrices and sets are a little inconvenient together, because matrices are by default "mutable" and it's a bad idea to put mutable objects in a set (if an element were to mutate into one that is equal to another one, it would need to be taken out!), but with a little helper function we can fix that.

def immutable(a):
  a.set_immutable()
  return a

m1=immutable(matrix(ZZ,2,2,[1,1,0,1]))
m2=immutable(matrix(ZZ,2,2,[0,1,-1,0]))
V={m1,m2,immutable(m1^(-1)),immutable(m2^(-1))}

G=[V]
for i in [1..5]:
    G.append( {immutable(m*g) for m in G[0] for g in G[-1]})

Note that for every i, a new Gi is computed. Furthermore, in python, negative indices mean from the end, so G[-1] is the last element in the list G, i.e., the last computed list G[i-1]. List indexing in python is 0-based, so G[0] is the first entry, i.e., V.