Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/groups/perm_gps/permgroup_morphism.py
8815 views
1
r"""
2
Permutation group homomorphisms
3
4
AUTHORS:
5
6
- David Joyner (2006-03-21): first version
7
8
- David Joyner (2008-06): fixed kernel and image to return a group,
9
instead of a string.
10
11
EXAMPLES::
12
13
sage: G = CyclicPermutationGroup(4)
14
sage: H = DihedralGroup(4)
15
sage: g = G([(1,2,3,4)])
16
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
17
sage: phi.image(G)
18
Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,2,3,4)]
19
sage: phi.kernel()
20
Subgroup of (Cyclic group of order 4 as a permutation group) generated by [()]
21
sage: phi.image(g)
22
(1,2,3,4)
23
sage: phi(g)
24
(1,2,3,4)
25
sage: phi.codomain()
26
Dihedral group of order 8 as a permutation group
27
sage: phi.codomain()
28
Dihedral group of order 8 as a permutation group
29
sage: phi.domain()
30
Cyclic group of order 4 as a permutation group
31
"""
32
33
#*****************************************************************************
34
# Copyright (C) 2006 David Joyner and William Stein <[email protected]>
35
#
36
# Distributed under the terms of the GNU General Public License (GPL)
37
# http://www.gnu.org/licenses/
38
#*****************************************************************************
39
40
from sage.misc.superseded import deprecation
41
from sage.categories.morphism import Morphism
42
from sage.groups.perm_gps.permgroup import PermutationGroup, PermutationGroup_generic
43
44
class PermutationGroupMorphism(Morphism):
45
"""
46
A set-theoretic map between PermutationGroups.
47
"""
48
def _repr_type(self):
49
"""
50
Returns the type of this morphism. This is used for printing
51
the morphism.
52
53
EXAMPLES::
54
55
sage: G = PSL(2,7)
56
sage: D, iota1, iota2, pr1, pr2 = G.direct_product(G)
57
sage: pr1._repr_type()
58
'Permutation group'
59
"""
60
return "Permutation group"
61
62
def range(self):
63
"""
64
Returns the codomain of this morphism. This method is
65
deprecated. Please use :meth:`codomain` instead.
66
67
EXAMPLES::
68
69
sage: G = PSL(2,7)
70
sage: D, iota1, iota2, pr1, pr2 = G.direct_product(G)
71
sage: pr1.range()
72
doctest:...: DeprecationWarning: range is deprecated. Please use codomain instead.
73
See http://trac.sagemath.org/10334 for details.
74
Permutation Group with generators [(3,7,5)(4,8,6), (1,2,6)(3,4,8)]
75
"""
76
deprecation(10334, 'range is deprecated. Please use codomain instead.')
77
return self.codomain()
78
79
def kernel(self):
80
"""
81
Returns the kernel of this homomorphism as a permutation group.
82
83
EXAMPLES::
84
85
sage: G = CyclicPermutationGroup(4)
86
sage: H = DihedralGroup(4)
87
sage: g = G([(1,2,3,4)])
88
sage: phi = PermutationGroupMorphism_im_gens(G, H, [1])
89
sage: phi.kernel()
90
Subgroup of (Cyclic group of order 4 as a permutation group) generated by [(1,2,3,4)]
91
92
::
93
94
sage: G = PSL(2,7)
95
sage: D = G.direct_product(G)
96
sage: H = D[0]
97
sage: pr1 = D[3]
98
sage: G.is_isomorphic(pr1.kernel())
99
True
100
"""
101
return self.domain().subgroup(gap_group=self._gap_().Kernel())
102
103
def image(self, J):
104
"""
105
J must be a subgroup of G. Computes the subgroup of H which is the
106
image of J.
107
108
EXAMPLES::
109
110
sage: G = CyclicPermutationGroup(4)
111
sage: H = DihedralGroup(4)
112
sage: g = G([(1,2,3,4)])
113
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
114
sage: phi.image(G)
115
Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,2,3,4)]
116
sage: phi.image(g)
117
(1,2,3,4)
118
119
::
120
121
sage: G = PSL(2,7)
122
sage: D = G.direct_product(G)
123
sage: H = D[0]
124
sage: pr1 = D[3]
125
sage: pr1.image(G)
126
Subgroup of (The projective special linear group of degree 2 over Finite Field of size 7) generated by [(3,7,5)(4,8,6), (1,2,6)(3,4,8)]
127
sage: G.is_isomorphic(pr1.image(G))
128
True
129
"""
130
H = self.codomain()
131
if J in self.domain():
132
J = PermutationGroup([J])
133
G = self._gap_().Image(J)
134
return H.subgroup(gap_group=G).gens()[0]
135
else:
136
G = self._gap_().Image(J)
137
return H.subgroup(gap_group=G)
138
139
def __call__(self, g):
140
"""
141
Some python code for wrapping GAP's Images function but only for
142
permutation groups. Returns an error if g is not in G.
143
144
EXAMPLES::
145
146
sage: G = CyclicPermutationGroup(4)
147
sage: H = DihedralGroup(4)
148
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
149
sage: g = G([(1,3),(2,4)]); g
150
(1,3)(2,4)
151
sage: phi(g)
152
(1,3)(2,4)
153
"""
154
return self.image(g)
155
156
class PermutationGroupMorphism_id(PermutationGroupMorphism):
157
pass
158
159
class PermutationGroupMorphism_from_gap(PermutationGroupMorphism):
160
def __init__(self, G, H, gap_hom):
161
"""
162
This is a Python trick to allow Sage programmers to create a group
163
homomorphism using GAP using very general constructions. An example
164
of its usage is in the direct_product instance method of the
165
PermutationGroup_generic class in permgroup.py.
166
167
Basic syntax:
168
169
PermutationGroupMorphism_from_gap(domain_group,
170
range_group,'phi:=gap_hom_command;','phi') And don't forget the
171
line: from sage.groups.perm_gps.permgroup_morphism import
172
PermutationGroupMorphism_from_gap in your program.
173
174
EXAMPLES::
175
176
sage: from sage.groups.perm_gps.permgroup_morphism import PermutationGroupMorphism_from_gap
177
sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])
178
sage: H = G.subgroup([G([(1,2,3,4)])])
179
sage: PermutationGroupMorphism_from_gap(H, G, gap.Identity)
180
Permutation group morphism:
181
From: Subgroup of (Permutation Group with generators [(1,2)(3,4), (1,2,3,4)]) generated by [(1,2,3,4)]
182
To: Permutation Group with generators [(1,2)(3,4), (1,2,3,4)]
183
Defn: Identity
184
"""
185
if not all(isinstance(X, PermutationGroup_generic) for X in [G, H]):
186
raise TypeError, "Sorry, the groups must be permutation groups."
187
PermutationGroupMorphism.__init__(self, G, H)
188
self._gap_hom = gap_hom
189
190
def _repr_defn(self):
191
"""
192
Returns the definition of this morphism. This is used when
193
printing the morphism.
194
195
EXAMPLES::
196
197
sage: from sage.groups.perm_gps.permgroup_morphism import PermutationGroupMorphism_from_gap
198
sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])
199
sage: H = G.subgroup([G([(1,2,3,4)])])
200
sage: phi = PermutationGroupMorphism_from_gap(H, G, gap.Identity)
201
sage: phi._repr_defn()
202
'Identity'
203
"""
204
return str(self._gap_hom).replace('\n', '')
205
206
def _gap_(self, gap=None):
207
"""
208
Returns a GAP version of this morphism.
209
210
EXAMPLES::
211
212
sage: from sage.groups.perm_gps.permgroup_morphism import PermutationGroupMorphism_from_gap
213
sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])
214
sage: H = G.subgroup([G([(1,2,3,4)])])
215
sage: phi = PermutationGroupMorphism_from_gap(H, G, gap.Identity)
216
sage: phi._gap_()
217
Identity
218
"""
219
return self._gap_hom
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: G = PSL(2,7)
229
sage: D = G.direct_product(G)
230
sage: H = D[0]
231
sage: pr1 = D[3]
232
sage: [pr1(g) for g in G.gens()]
233
[(3,7,5)(4,8,6), (1,2,6)(3,4,8)]
234
"""
235
return self.codomain()(self._gap_().Image(g))
236
237
238
class PermutationGroupMorphism_im_gens(PermutationGroupMorphism):
239
def __init__(self, G, H, gens=None, images=None):
240
"""
241
Some python code for wrapping GAP's GroupHomomorphismByImages
242
function but only for permutation groups. Can be expensive if G is
243
large. Returns "fail" if gens does not generate self or if the map
244
does not extend to a group homomorphism, self - other.
245
246
EXAMPLES::
247
248
sage: G = CyclicPermutationGroup(4)
249
sage: H = DihedralGroup(4)
250
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens())); phi
251
Permutation group morphism:
252
From: Cyclic group of order 4 as a permutation group
253
To: Dihedral group of order 8 as a permutation group
254
Defn: [(1,2,3,4)] -> [(1,2,3,4)]
255
sage: g = G([(1,3),(2,4)]); g
256
(1,3)(2,4)
257
sage: phi(g)
258
(1,3)(2,4)
259
sage: images = ((4,3,2,1),)
260
sage: phi = PermutationGroupMorphism_im_gens(G, G, images)
261
sage: g = G([(1,2,3,4)]); g
262
(1,2,3,4)
263
sage: phi(g)
264
(1,4,3,2)
265
266
AUTHORS:
267
268
- David Joyner (2006-02)
269
"""
270
if not all([isinstance(X, PermutationGroup_generic) for X in [G, H]]):
271
raise TypeError, "Sorry, the groups must be permutation groups."
272
if images is not None:
273
deprecation(10334, 'only the images need to be specified')
274
else:
275
images = gens
276
PermutationGroupMorphism.__init__(self, G, H)
277
self._images = [H(img) for img in images]
278
279
def _repr_defn(self):
280
"""
281
Returns the definition of this morphism. This is used when
282
printing the morphism.
283
284
EXAMPLES::
285
286
sage: G = CyclicPermutationGroup(4)
287
sage: H = DihedralGroup(4)
288
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
289
sage: phi._repr_defn()
290
'[(1,2,3,4)] -> [(1,2,3,4)]'
291
"""
292
return "%s -> %s"%(self.domain().gens(), self._images)
293
294
def _gap_(self):
295
"""
296
Returns a GAP representation of this morphism.
297
298
EXAMPLES::
299
300
sage: G = CyclicPermutationGroup(4)
301
sage: H = DihedralGroup(4)
302
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
303
sage: phi._gap_()
304
GroupHomomorphismByImages( Group( [ (1,2,3,4) ] ), Group(
305
[ (1,2,3,4), (1,4)(2,3) ] ), [ (1,2,3,4) ], [ (1,2,3,4) ] )
306
"""
307
return self.domain()._gap_().GroupHomomorphismByImages(self.codomain(), self.domain().gens(), self._images)
308
309
def is_PermutationGroupMorphism(f):
310
"""
311
Returns True if the argument ``f`` is a PermutationGroupMorphism.
312
313
EXAMPLES::
314
315
sage: from sage.groups.perm_gps.permgroup_morphism import is_PermutationGroupMorphism
316
sage: G = CyclicPermutationGroup(4)
317
sage: H = DihedralGroup(4)
318
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
319
sage: is_PermutationGroupMorphism(phi)
320
True
321
"""
322
return isinstance(f, PermutationGroupMorphism)
323
324