Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/groups/perm_gps/permgroup_morphism.py
4057 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.misc 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: (Since Sage Version 5.0) range is deprecated. Please use codomain instead.
73
Permutation Group with generators [(3,7,5)(4,8,6), (1,2,6)(3,4,8)]
74
"""
75
deprecation('range is deprecated. Please use codomain instead.', 'Sage Version 5.0')
76
return self.codomain()
77
78
def kernel(self):
79
"""
80
Returns the kernel of this homomorphism as a permutation group.
81
82
EXAMPLES::
83
84
sage: G = CyclicPermutationGroup(4)
85
sage: H = DihedralGroup(4)
86
sage: g = G([(1,2,3,4)])
87
sage: phi = PermutationGroupMorphism_im_gens(G, H, [1])
88
sage: phi.kernel()
89
Subgroup of (Cyclic group of order 4 as a permutation group) generated by [(1,2,3,4)]
90
91
::
92
93
sage: G = PSL(2,7)
94
sage: D = G.direct_product(G)
95
sage: H = D[0]
96
sage: pr1 = D[3]
97
sage: G.is_isomorphic(pr1.kernel())
98
True
99
"""
100
return self.domain().subgroup(gap_group=self._gap_().Kernel())
101
102
def image(self, J):
103
"""
104
J must be a subgroup of G. Computes the subgroup of H which is the
105
image of J.
106
107
EXAMPLES::
108
109
sage: G = CyclicPermutationGroup(4)
110
sage: H = DihedralGroup(4)
111
sage: g = G([(1,2,3,4)])
112
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
113
sage: phi.image(G)
114
Subgroup of (Dihedral group of order 8 as a permutation group) generated by [(1,2,3,4)]
115
sage: phi.image(g)
116
(1,2,3,4)
117
118
::
119
120
sage: G = PSL(2,7)
121
sage: D = G.direct_product(G)
122
sage: H = D[0]
123
sage: pr1 = D[3]
124
sage: pr1.image(G)
125
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)]
126
sage: G.is_isomorphic(pr1.image(G))
127
True
128
"""
129
H = self.codomain()
130
if J in self.domain():
131
J = PermutationGroup([J])
132
G = self._gap_().Image(J)
133
return H.subgroup(gap_group=G).gens()[0]
134
else:
135
G = self._gap_().Image(J)
136
return H.subgroup(gap_group=G)
137
138
def __call__(self, g):
139
"""
140
Some python code for wrapping GAP's Images function but only for
141
permutation groups. Returns an error if g is not in G.
142
143
EXAMPLES::
144
145
sage: G = CyclicPermutationGroup(4)
146
sage: H = DihedralGroup(4)
147
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
148
sage: g = G([(1,3),(2,4)]); g
149
(1,3)(2,4)
150
sage: phi(g)
151
(1,3)(2,4)
152
"""
153
return self.image(g)
154
155
class PermutationGroupMorphism_id(PermutationGroupMorphism):
156
pass
157
158
class PermutationGroupMorphism_from_gap(PermutationGroupMorphism):
159
def __init__(self, G, H, gap_hom):
160
"""
161
This is a Python trick to allow Sage programmers to create a group
162
homomorphism using GAP using very general constructions. An example
163
of its usage is in the direct_product instance method of the
164
PermutationGroup_generic class in permgroup.py.
165
166
Basic syntax:
167
168
PermutationGroupMorphism_from_gap(domain_group,
169
range_group,'phi:=gap_hom_command;','phi') And don't forget the
170
line: from sage.groups.perm_gps.permgroup_morphism import
171
PermutationGroupMorphism_from_gap in your program.
172
173
EXAMPLES::
174
175
sage: from sage.groups.perm_gps.permgroup_morphism import PermutationGroupMorphism_from_gap
176
sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])
177
sage: H = G.subgroup([G([(1,2,3,4)])])
178
sage: PermutationGroupMorphism_from_gap(H, G, gap.Identity)
179
Permutation group morphism:
180
From: Subgroup of (Permutation Group with generators [(1,2)(3,4), (1,2,3,4)]) generated by [(1,2,3,4)]
181
To: Permutation Group with generators [(1,2)(3,4), (1,2,3,4)]
182
Defn: Identity
183
"""
184
if not all(isinstance(X, PermutationGroup_generic) for X in [G, H]):
185
raise TypeError, "Sorry, the groups must be permutation groups."
186
PermutationGroupMorphism.__init__(self, G, H)
187
self._gap_hom = gap_hom
188
189
def _repr_defn(self):
190
"""
191
Returns the definition of this morphism. This is used when
192
printing the morphism.
193
194
EXAMPLES::
195
196
sage: from sage.groups.perm_gps.permgroup_morphism import PermutationGroupMorphism_from_gap
197
sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])
198
sage: H = G.subgroup([G([(1,2,3,4)])])
199
sage: phi = PermutationGroupMorphism_from_gap(H, G, gap.Identity)
200
sage: phi._repr_defn()
201
'Identity'
202
"""
203
return str(self._gap_hom).replace('\n', '')
204
205
def _gap_(self, gap=None):
206
"""
207
Returns a GAP version of this morphism.
208
209
EXAMPLES::
210
211
sage: from sage.groups.perm_gps.permgroup_morphism import PermutationGroupMorphism_from_gap
212
sage: G = PermutationGroup([[(1,2),(3,4)], [(1,2,3,4)]])
213
sage: H = G.subgroup([G([(1,2,3,4)])])
214
sage: phi = PermutationGroupMorphism_from_gap(H, G, gap.Identity)
215
sage: phi._gap_()
216
Identity
217
"""
218
return self._gap_hom
219
220
def __call__(self, g):
221
"""
222
Some python code for wrapping GAP's Images function but only for
223
permutation groups. Returns an error if g is not in G.
224
225
EXAMPLES::
226
227
sage: G = PSL(2,7)
228
sage: D = G.direct_product(G)
229
sage: H = D[0]
230
sage: pr1 = D[3]
231
sage: [pr1(g) for g in G.gens()]
232
[(3,7,5)(4,8,6), (1,2,6)(3,4,8)]
233
"""
234
return self.codomain()(self._gap_().Image(g))
235
236
237
class PermutationGroupMorphism_im_gens(PermutationGroupMorphism):
238
def __init__(self, G, H, gens=None, images=None):
239
"""
240
Some python code for wrapping GAP's GroupHomomorphismByImages
241
function but only for permutation groups. Can be expensive if G is
242
large. Returns "fail" if gens does not generate self or if the map
243
does not extend to a group homomorphism, self - other.
244
245
EXAMPLES::
246
247
sage: G = CyclicPermutationGroup(4)
248
sage: H = DihedralGroup(4)
249
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens())); phi
250
Permutation group morphism:
251
From: Cyclic group of order 4 as a permutation group
252
To: Dihedral group of order 8 as a permutation group
253
Defn: [(1,2,3,4)] -> [(1,2,3,4)]
254
sage: g = G([(1,3),(2,4)]); g
255
(1,3)(2,4)
256
sage: phi(g)
257
(1,3)(2,4)
258
sage: images = ((4,3,2,1),)
259
sage: phi = PermutationGroupMorphism_im_gens(G, G, images)
260
sage: g = G([(1,2,3,4)]); g
261
(1,2,3,4)
262
sage: phi(g)
263
(1,4,3,2)
264
265
AUTHORS:
266
267
- David Joyner (2006-02)
268
"""
269
if not all([isinstance(X, PermutationGroup_generic) for X in [G, H]]):
270
raise TypeError, "Sorry, the groups must be permutation groups."
271
if images is not None:
272
deprecation('only the images need to be specified')
273
else:
274
images = gens
275
PermutationGroupMorphism.__init__(self, G, H)
276
self._images = [H(img) for img in images]
277
278
def _repr_defn(self):
279
"""
280
Returns the definition of this morphism. This is used when
281
printing the morphism.
282
283
EXAMPLES::
284
285
sage: G = CyclicPermutationGroup(4)
286
sage: H = DihedralGroup(4)
287
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
288
sage: phi._repr_defn()
289
'[(1,2,3,4)] -> [(1,2,3,4)]'
290
"""
291
return "%s -> %s"%(self.domain().gens(), self._images)
292
293
def _gap_(self):
294
"""
295
Returns a GAP representation of this morphism.
296
297
EXAMPLES::
298
299
sage: G = CyclicPermutationGroup(4)
300
sage: H = DihedralGroup(4)
301
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
302
sage: phi._gap_()
303
GroupHomomorphismByImages( Group( [ (1,2,3,4) ] ), Group(
304
[ (1,2,3,4), (1,4)(2,3) ] ), [ (1,2,3,4) ], [ (1,2,3,4) ] )
305
"""
306
return self.domain()._gap_().GroupHomomorphismByImages(self.codomain(), self.domain().gens(), self._images)
307
308
def is_PermutationGroupMorphism(f):
309
"""
310
Returns True if the argument ``f`` is a PermutationGroupMorphism.
311
312
EXAMPLES::
313
314
sage: from sage.groups.perm_gps.permgroup_morphism import is_PermutationGroupMorphism
315
sage: G = CyclicPermutationGroup(4)
316
sage: H = DihedralGroup(4)
317
sage: phi = PermutationGroupMorphism_im_gens(G, H, map(H, G.gens()))
318
sage: is_PermutationGroupMorphism(phi)
319
True
320
"""
321
return isinstance(f, PermutationGroupMorphism)
322
323