Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/groups/abelian_gps/abelian_group_morphism.py
4100 views
1
"""
2
Homomorphisms of abelian groups
3
4
TODO:
5
6
- there must be a homspace first
7
8
- there should be hom and Hom methods in abelian group
9
10
AUTHORS:
11
12
- David Joyner (2006-03-03): initial version
13
"""
14
15
#*****************************************************************************
16
# Copyright (C) 2006 David Joyner and William Stein <[email protected]>
17
#
18
# Distributed under the terms of the GNU General Public License (GPL)
19
#
20
# http://www.gnu.org/licenses/
21
#*****************************************************************************
22
23
from sage.groups.perm_gps.permgroup import *
24
from sage.interfaces.gap import *
25
from sage.categories.morphism import *
26
from sage.categories.homset import *
27
28
from sage.misc.misc import prod
29
30
def is_AbelianGroupMorphism(f):
31
return isinstance(f, AbelianGroupMorphism);
32
33
class AbelianGroupMap(Morphism):
34
"""
35
A set-theoretic map between AbelianGroups.
36
"""
37
def __init__(self, parent):
38
Morphism.__init__(self, parent)
39
40
def _repr_type(self):
41
return "AbelianGroup"
42
43
class AbelianGroupMorphism_id(AbelianGroupMap):
44
"""
45
Return the identity homomorphism from X to itself.
46
47
EXAMPLES:
48
"""
49
def __init__(self, X):
50
AbelianGroupMorphism.__init__(self, X.Hom(X))
51
52
def _repr_defn(self):
53
return "Identity map of "+str(X)
54
55
class AbelianGroupMorphism:
56
"""
57
Some python code for wrapping GAP's GroupHomomorphismByImages
58
function for abelian groups. Returns "fail" if gens does not
59
generate self or if the map does not extend to a group
60
homomorphism, self - other.
61
62
EXAMPLES::
63
64
sage: G = AbelianGroup(3,[2,3,4],names="abc"); G
65
Multiplicative Abelian Group isomorphic to C2 x C3 x C4
66
sage: a,b,c = G.gens()
67
sage: H = AbelianGroup(2,[2,3],names="xy"); H
68
Multiplicative Abelian Group isomorphic to C2 x C3
69
sage: x,y = H.gens()
70
71
::
72
73
sage: from sage.groups.abelian_gps.abelian_group_morphism import AbelianGroupMorphism
74
sage: phi = AbelianGroupMorphism(H,G,[x,y],[a,b])
75
76
AUTHORS:
77
78
- David Joyner (2006-02)
79
"""
80
81
# There is a homomorphism from H to G but not from G to H:
82
#
83
# sage: phi = AbelianGroupMorphism_im_gens(G,H,[a*b,a*c],[x,y])
84
#------------------------------------------------------------
85
#Traceback (most recent call last):
86
# File "<ipython console>", line 1, in ?
87
# File ".abeliangp_hom.sage.py", line 737, in __init__
88
# raise TypeError, "Sorry, the orders of the corresponding elements in %s, %s must be equal."%(genss,imgss)
89
#TypeError: Sorry, the orders of the corresponding elements in [a*b, a*c], [x, y] must be equal.
90
#
91
# sage: phi = AbelianGroupMorphism_im_gens(G,H,[a*b,(a*c)^2],[x*y,y])
92
#------------------------------------------------------------
93
#Traceback (most recent call last):
94
# File "<ipython console>", line 1, in ?
95
# File ".abeliangp_hom.sage.py", line 730, in __init__
96
# raise TypeError, "Sorry, the list %s must generate G."%genss
97
#TypeError: Sorry, the list [a*b, c^2] must generate G.
98
99
def __init__(self, G, H, genss, imgss ):
100
if len(genss) != len(imgss):
101
raise TypeError, "Sorry, the lengths of %s, %s must be equal."%(genss,imgss)
102
self._domain = G
103
self._codomain = H
104
if not(G.is_abelian()):
105
raise TypeError, "Sorry, the groups must be abelian groups."
106
if not(H.is_abelian()):
107
raise TypeError, "Sorry, the groups must be abelian groups."
108
G_domain = G.subgroup(genss)
109
if G_domain.order() != G.order():
110
raise TypeError, "Sorry, the list %s must generate G."%genss
111
self.domain_invs = G.invariants()
112
self.codomaininvs = H.invariants()
113
self.domaingens = genss
114
self.codomaingens = imgss
115
#print genss, imgss
116
for i in range(len(self.domaingens)):
117
if (self.domaingens[i]).order() != (self.codomaingens[i]).order():
118
raise TypeError, "Sorry, the orders of the corresponding elements in %s, %s must be equal."%(genss,imgss)
119
120
def _gap_init_(self):
121
"""
122
Only works for finite groups.
123
124
EXAMPLES::
125
126
sage: G = AbelianGroup(3,[2,3,4],names="abc"); G
127
Multiplicative Abelian Group isomorphic to C2 x C3 x C4
128
sage: a,b,c = G.gens()
129
sage: H = AbelianGroup(2,[2,3],names="xy"); H
130
Multiplicative Abelian Group isomorphic to C2 x C3
131
sage: x,y = H.gens()
132
sage: phi = AbelianGroupMorphism(H,G,[x,y],[a,b])
133
sage: phi._gap_init_()
134
'phi := GroupHomomorphismByImages(G,H,[x, y],[a, b])'
135
"""
136
G = (self.domain())._gap_init_()
137
H = (self.range())._gap_init_()
138
# print G,H
139
s3 = 'G:=%s; H:=%s'%(G,H)
140
#print s3,"\n"
141
gap.eval(s3)
142
gensG = self.domain().variable_names() ## the Sage group generators
143
gensH = self.range().variable_names()
144
#print gensG, gensH
145
s1 = "gensG := GeneratorsOfGroup(G)" ## the GAP group generators
146
gap.eval(s1)
147
s2 = "gensH := GeneratorsOfGroup(H)"
148
gap.eval(s2)
149
for i in range(len(gensG)): ## making the Sage group gens
150
cmd = ("%s := gensG["+str(i+1)+"]")%gensG[i] ## correspond to the Sage group gens
151
#print i," \n",cmd
152
gap.eval(cmd)
153
for i in range(len(gensH)):
154
cmd = ("%s := gensH["+str(i+1)+"]")%gensH[i]
155
#print i," \n",cmd
156
gap.eval(cmd)
157
args = str(self.domaingens)+","+ str(self.codomaingens)
158
#print args,"\n"
159
gap.eval("phi := GroupHomomorphismByImages(G,H,"+args+")")
160
self.gap_hom_string = "phi := GroupHomomorphismByImages(G,H,"+args+")"
161
return self.gap_hom_string
162
163
def _repr_type(self):
164
return "AbelianGroup"
165
166
def domain(self):
167
return self._domain
168
169
def range(self):
170
return self._codomain
171
172
def codomain(self):
173
return self._codomain
174
175
def kernel(self):
176
"""
177
Only works for finite groups.
178
179
TODO: not done yet; returns a gap object but should return a Sage
180
group.
181
182
EXAMPLES::
183
184
sage: H = AbelianGroup(3,[2,3,4],names="abc"); H
185
Multiplicative Abelian Group isomorphic to C2 x C3 x C4
186
sage: a,b,c = H.gens()
187
sage: G = AbelianGroup(2,[2,3],names="xy"); G
188
Multiplicative Abelian Group isomorphic to C2 x C3
189
sage: x,y = G.gens()
190
sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])
191
sage: phi.kernel()
192
'Group([ ])'
193
"""
194
cmd = self._gap_init_()
195
gap.eval(cmd)
196
return gap.eval("Kernel(phi)")
197
198
def image(self, J):
199
"""
200
Only works for finite groups.
201
202
J must be a subgroup of G. Computes the subgroup of H which is the
203
image of J.
204
205
EXAMPLES::
206
207
sage: G = AbelianGroup(2,[2,3],names="xy")
208
sage: x,y = G.gens()
209
sage: H = AbelianGroup(3,[2,3,4],names="abc")
210
sage: a,b,c = H.gens()
211
sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])
212
"""
213
G = self.domain()
214
gensJ = J.gens()
215
for g in gensJ:
216
print g
217
print self(g),"\n"
218
L = [self(g) for g in gensJ]
219
return G.subgroup(L)
220
221
def __call__( self, g ):
222
"""
223
Some python code for wrapping GAP's Images function but only for
224
permutation groups. Returns an error if g is not in G.
225
226
EXAMPLES::
227
228
sage: H = AbelianGroup(3, [2,3,4], names="abc")
229
sage: a,b,c = H.gens()
230
sage: G = AbelianGroup(2, [2,3], names="xy")
231
sage: x,y = G.gens()
232
sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b])
233
sage: phi(y*x)
234
a*b
235
sage: phi(y^2)
236
b^2
237
"""
238
G = g.parent()
239
w = g.word_problem(self.domaingens)
240
n = len(w)
241
#print w,g.word_problem(self.domaingens)
242
# g.word_problem is faster in general than word_problem(g)
243
gens = self.codomaingens
244
h = prod([gens[(self.domaingens).index(w[i][0])]**(w[i][1]) for i in range(n)])
245
return h
246
247
248
249
250
251
252