Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/groups/matrix_gps/matrix_group_morphism.py
4057 views
1
"""
2
Homomorphisms Between Matrix Groups
3
4
AUTHORS:
5
6
- David Joyner and William Stein (2006-03): initial version
7
8
- David Joyner (2006-05): examples
9
10
- Simon King (2011-01): cleaning and improving code
11
"""
12
13
#*****************************************************************************
14
# Copyright (C) 2006 David Joyner and William Stein <[email protected]>
15
#
16
# Distributed under the terms of the GNU General Public License (GPL)
17
# as published by the Free Software Foundation; either version 2 of
18
# the License, or (at your option) any later version.
19
# http://www.gnu.org/licenses/
20
#*****************************************************************************
21
22
from sage.interfaces.gap import gap
23
from sage.categories.morphism import *
24
from sage.misc.latex import latex
25
26
class MatrixGroupMap(Morphism):
27
"""
28
A set-theoretic map between matrix groups.
29
"""
30
def __init__(self, parent):
31
Morphism.__init__(self, parent)
32
33
def _repr_type(self):
34
return "MatrixGroup"
35
36
class MatrixGroupMorphism(MatrixGroupMap):
37
pass
38
39
class MatrixGroupMorphism_im_gens(MatrixGroupMorphism):
40
"""
41
Some python code for wrapping GAP's GroupHomomorphismByImages
42
function but only for matrix groups. Can be expensive if G is
43
large.
44
45
EXAMPLES::
46
47
sage: F = GF(5); MS = MatrixSpace(F,2,2)
48
sage: G = MatrixGroup([MS([1,1,0,1])])
49
sage: H = MatrixGroup([MS([1,0,1,1])])
50
sage: phi = G.hom(H.gens())
51
sage: phi
52
Homomorphism : Matrix group over Finite Field of size 5 with 1 generators:
53
[[[1, 1], [0, 1]]] --> Matrix group over Finite Field of size 5 with 1 generators:
54
[[[1, 0], [1, 1]]]
55
sage: phi(MS([1,1,0,1]))
56
[1 0]
57
[1 1]
58
sage: F = GF(7); MS = MatrixSpace(F,2,2)
59
sage: F.multiplicative_generator()
60
3
61
sage: G = MatrixGroup([MS([3,0,0,1])])
62
sage: a = G.gens()[0]^2
63
sage: phi = G.hom([a])
64
"""
65
def __init__(self, homset, imgsH, check=True):
66
MatrixGroupMorphism.__init__(self, homset) # sets the parent
67
G = homset.domain()
68
H = homset.codomain()
69
gaplist_gens = [gap(x) for x in G.gens()]
70
gaplist_imgs = [gap(x) for x in imgsH]
71
genss = '[%s]'%(','.join(str(v) for v in gaplist_gens))
72
imgss = '[%s]'%(','.join(str(v) for v in gaplist_imgs))
73
args = '%s, %s, %s, %s'%(G._gap_init_(), H._gap_init_(), genss, imgss)
74
self._gap_str = 'GroupHomomorphismByImages(%s)'%args
75
phi0 = gap(self)
76
if gap.eval("IsGroupHomomorphism(%s)"%phi0.name())!="true":
77
raise ValueError,"The map "+str(gensG)+"-->"+str(imgsH)+" isn't a homomorphism."
78
79
def _repr_(self):
80
"""
81
EXAMPLES::
82
83
sage: F = GF(5); MS = MatrixSpace(F,2,2)
84
sage: G = MatrixGroup([MS([1,1,0,1])])
85
sage: H = MatrixGroup([MS([1,0,1,1])])
86
sage: phi = G.hom(H.gens())
87
sage: phi
88
Homomorphism : Matrix group over Finite Field of size 5 with 1 generators:
89
[[[1, 1], [0, 1]]] --> Matrix group over Finite Field of size 5 with 1 generators:
90
[[[1, 0], [1, 1]]]
91
sage: phi(MS([1,1,0,1]))
92
[1 0]
93
[1 1]
94
"""
95
return "Homomorphism : %s --> %s"%(self.domain(),self.codomain())
96
97
def _latex_(self):
98
r"""
99
EXAMPLES::
100
101
sage: F = GF(5); MS = MatrixSpace(F,2,2)
102
sage: G = MatrixGroup([MS([1,1,0,1])])
103
sage: phi = G.hom(G.gens())
104
sage: print latex(phi)
105
\left\langle \left(\begin{array}{rr}
106
1 & 1 \\
107
0 & 1
108
\end{array}\right) \right\rangle \rightarrow{} \left\langle \left(\begin{array}{rr}
109
1 & 1 \\
110
0 & 1
111
\end{array}\right) \right\rangle
112
"""
113
return "%s \\rightarrow{} %s"%(latex(self.domain()), latex(self.codomain()))
114
115
def _gap_init_(self):
116
return self._gap_str
117
118
def kernel(self):
119
"""
120
Return the kernel of ``self``, i.e., a matrix group.
121
122
EXAMPLES::
123
124
sage: F = GF(7); MS = MatrixSpace(F,2,2)
125
sage: F.multiplicative_generator()
126
3
127
sage: G = MatrixGroup([MS([3,0,0,1])])
128
sage: a = G.gens()[0]^2
129
sage: phi = G.hom([a])
130
sage: phi.kernel()
131
Matrix group over Finite Field of size 7 with 1 generators:
132
[[[6, 0], [0, 1]]]
133
134
"""
135
gap_ker = gap(self).Kernel()
136
from sage.all import MatrixGroup
137
F = self.domain().base_ring()
138
return MatrixGroup([x._matrix_(F) for x in gap_ker.GeneratorsOfGroup()])
139
140
def pushforward(self, J, *args,**kwds):
141
"""
142
The image of an element or a subgroup.
143
144
INPUT:
145
146
``J`` -- a subgroup or an element of the domain of ``self``.
147
148
OUTPUT:
149
150
The image of ``J`` under ``self``
151
152
NOTE:
153
154
``pushforward`` is the method that is used when a map is called on
155
anything that is not an element of its domain. For historical reasons,
156
we keep the alias ``image()`` for this method.
157
158
EXAMPLES::
159
160
sage: F = GF(7); MS = MatrixSpace(F,2,2)
161
sage: F.multiplicative_generator()
162
3
163
sage: G = MatrixGroup([MS([3,0,0,1])])
164
sage: a = G.gens()[0]^2
165
sage: phi = G.hom([a])
166
sage: phi.image(G.gens()[0]) # indirect doctest
167
[2 0]
168
[0 1]
169
sage: H = MatrixGroup([MS(a.list())])
170
sage: H
171
Matrix group over Finite Field of size 7 with 1 generators:
172
[[[2, 0], [0, 1]]]
173
174
The following tests against trac ticket #10659::
175
176
sage: phi(H) # indirect doctestest
177
Matrix group over Finite Field of size 7 with 1 generators:
178
[[[4, 0], [0, 1]]]
179
"""
180
phi = gap(self)
181
F = self.codomain().base_ring()
182
from sage.all import MatrixGroup
183
gapJ = gap(J)
184
if gap.eval("IsGroup(%s)"%gapJ.name()) == "true":
185
return MatrixGroup([x._matrix_(F) for x in phi.Image(gapJ).GeneratorsOfGroup()])
186
return phi.Image(gapJ)._matrix_(F)
187
188
image = pushforward
189
190
def _call_( self, g ):
191
"""
192
Some python code for wrapping GAP's Images function for a matrix
193
group G. Returns an error if g is not in G.
194
195
EXAMPLES::
196
197
sage: F = GF(5); MS = MatrixSpace(F,2,2)
198
sage: g = MS([1,1,0,1])
199
sage: G = MatrixGroup([g])
200
sage: phi = G.hom(G.gens())
201
sage: phi(G.0)
202
[1 1]
203
[0 1]
204
sage: phi(G(g^2))
205
[1 2]
206
[0 1]
207
208
::
209
210
sage: F = GF(5); MS = MatrixSpace(F,2,2)
211
sage: gens = [MS([1,2, -1,1]),MS([1,1, 0,1])]
212
sage: G = MatrixGroup(gens)
213
sage: phi = G.hom(G.gens())
214
sage: phi(G.0)
215
[1 2]
216
[4 1]
217
sage: phi(G.1)
218
[1 1]
219
[0 1]
220
221
TEST:
222
223
The following tests that the call method was successfully
224
improved in trac ticket #10659::
225
226
sage: O = WeylGroup(['D',6])
227
sage: r = prod(O.gens())
228
sage: r_ = r^-1
229
sage: f = O.hom([r*x*r_ for x in O.gens()]) # long time (19s on sage.math, 2011)
230
sage: [f(x) for x in O.gens()] # long time
231
[
232
[1 0 0 0 0 0] [1 0 0 0 0 0] [1 0 0 0 0 0] [ 0 0 0 0 -1 0]
233
[0 0 1 0 0 0] [0 1 0 0 0 0] [0 1 0 0 0 0] [ 0 1 0 0 0 0]
234
[0 1 0 0 0 0] [0 0 0 1 0 0] [0 0 1 0 0 0] [ 0 0 1 0 0 0]
235
[0 0 0 1 0 0] [0 0 1 0 0 0] [0 0 0 0 1 0] [ 0 0 0 1 0 0]
236
[0 0 0 0 1 0] [0 0 0 0 1 0] [0 0 0 1 0 0] [-1 0 0 0 0 0]
237
[0 0 0 0 0 1], [0 0 0 0 0 1], [0 0 0 0 0 1], [ 0 0 0 0 0 1],
238
<BLANKLINE>
239
[0 0 0 0 0 1] [ 0 0 0 0 0 -1]
240
[0 1 0 0 0 0] [ 0 1 0 0 0 0]
241
[0 0 1 0 0 0] [ 0 0 1 0 0 0]
242
[0 0 0 1 0 0] [ 0 0 0 1 0 0]
243
[0 0 0 0 1 0] [ 0 0 0 0 1 0]
244
[1 0 0 0 0 0], [-1 0 0 0 0 0]
245
]
246
sage: f(O) # long time
247
Matrix group over Rational Field with 6 generators:
248
[[[1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1]], [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1]], [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1]], [[0, 0, 0, 0, -1, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [-1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1]], [[0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0], [1, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, -1], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0], [-1, 0, 0, 0, 0, 0]]]
249
250
"""
251
phi = gap(self)
252
G = self.domain()
253
F = G.base_ring()
254
h = gap(g)
255
return phi.Image(h)._matrix_(F)
256
257