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