Solutions to the homework problems |
sage: def list_all_monomials( n, deg ):Exercise 2:
....: return [subset_to_monomial( SS, deg ) for SS in Subsets(n+deg-1, n-1)]
sage: n = 4 # as an example take n=4There are several ways of working with a root of unity in sage. Two are CyclotomicField(n).zeta() and exp(2*pi*I/n). You may need to experiment to see which works better.
sage: (x,y) = DihedralGroup(n).gens() # this group is generated by two elements
sage: D4 = [ (a, b) for a in range(n) for b in range(2) ] # this is a list of exponents
sage: D4
[(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1), (3, 0), (3, 1)]
sage: [ x^a*y^b for (a,b) in D4 ]
[(), (1,4)(2,3), (1,2,3,4), (1,3), (1,3)(2,4), (1,2)(3,4), (1,4,3,2), (2,4)]
sage: DihedralGroup(n).list() # not in the same order but the same elements
[(), (2,4), (1,2)(3,4), (1,2,3,4), (1,3), (1,3)(2,4), (1,4,3,2), (1,4)(2,3)]
def group_element_to_pair( g ):If you want to see how this works try the following commands
"""
Converts a group element g of DihedralGroup(n) into a pair (a,b)
with a in range(n) and b in range(2)
EXAMPLES::
sage: [group_element_to_pair(g) for g in DihedralGroup(4)]
[(0, 0), (3, 1), (2, 1), (1, 0), (1, 1), (2, 0), (3, 0), (0, 1)]
"""
G = g.parent() # this is the dihedral group
(x,y) = G.gens() # these are the generators
# the following construction is a 'dictionary' which maps group elements
# to pairs over all possible group elements (not efficient, but it works)
M = { x^a*y^b : (a,b) for a in range(G.order()/2) for b in range(2) }
return M[g]
def pair_to_group_element(p, n):
"""
Converts a pair p = (a,b) into a group element of the DihedralGroup(n)
Given n, this function is the inverse of group_element_to_pair
EXAMPLES::
sage: all(pair_to_group_element(group_element_to_pair( g ), 4)==g for g in DihedralGroup(4))
True
sage: all(group_element_to_pair(pair_to_group_element((a,b),4))==(a,b) for a in range(4) for b in range(2))
True
"""
G = DihedralGroup(n)
(x,y) = G.gens()
return x^p[0]*y^p[1]
sage: pair_to_group_element((3,1), 5)
(1,2)(3,5)
sage: group_element_to_pair(_) # underline means the result of the last calculation
(3, 1)
sage: group_element_to_pair(DihedralGroup(5).list()[4])
(2, 1)
sage: [group_element_to_pair(g) for g in DihedralGroup(5)]
[(0, 0), (4, 1), (3, 1), (1, 0), (2, 1), (2, 0), (1, 1), (3, 0), (4, 0), (0, 1)]