Reputation: 133
I'm trying to do some work with Sage, and I can't understand how to do the following.
I've written some little code:
def ElementDr1(r):
G = SymmetricGroup(r)
E = G.list()
O = G.order()
coeff = ZeroCoeff(O)
for i in range(0,O):
if E[i] == G("(1,r)"):
coeff [i]=1
if E[i] == G("(2,3)*(1,r)"):
coeff [i]=1
if E[i] == G("(1,3)*(1,r)"):
coeff [i]=-1
return coeff
and Sage says that the permutation vector (1,r)
is invalid. I'm sure there must be a way to write permutation vectors with unknowns, but I can't find what this method is by looking at the Sage help.
Upvotes: 1
Views: 98
Reputation:
Several issues here:
G("(1,2)(3,4)")
with no * in between. Since (1,3)(1,r) is not a valid cycle decomposition, what you want to do is to multiply (1,3) by (1,r). To this end, create these elements first and then multiply them (using * operator). Since the elements are cycles, you don't even need a string: an element can be created from a tuple.
def ElementDr1(r):
G = SymmetricGroup(r)
E = G.list()
O = G.order()
coeff = [0 for i in range(0,O)] # self-contained examples are good
for i in range(0,O):
if E[i] == G((1,r)):
coeff[i] = 1
if E[i] == G((2,3))*G((1,r)):
coeff[i] = 1
if E[i] == G((1,3))*G((1,r)):
coeff[i] = -1
return coeff
Now it runs, outputting, for example, [-1, 0, 0, 1, 0, 1]
with r=3.
Upvotes: 2
Reputation: 3453
The error is likely due to calling G("...")
with strings containing r
. Replace r
by its value in these strings, for example as follows:
def ElementDr1(r):
G = SymmetricGroup(r)
E = G.list()
O = G.order()
coeff = ZeroCoeff(O)
for i in range(0,O):
if E[i] == G("(1,%s)"%r):
coeff[i] = 1
if E[i] == G("(2,3)*(1,%s)"%r):
coeff[i] = 1
if E[i] == G("(1,3)*(1,%s)"%r):
coeff[i] = -1
return coeff
Upvotes: 1