Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/groups/matrix_gps/named_group.py
8815 views
1
"""
2
Base for Classical Matrix Groups
3
4
This module implements the base class for matrix groups that have
5
various famous names, like the general linear group.
6
7
EXAMPLES::
8
9
sage: SL(2, ZZ)
10
Special Linear Group of degree 2 over Integer Ring
11
sage: G = SL(2,GF(3)); G
12
Special Linear Group of degree 2 over Finite Field of size 3
13
sage: G.is_finite()
14
True
15
sage: G.conjugacy_class_representatives()
16
(
17
[1 0] [0 2] [0 1] [2 0] [0 2] [0 1] [0 2]
18
[0 1], [1 1], [2 1], [0 2], [1 2], [2 2], [1 0]
19
)
20
sage: G = SL(6,GF(5))
21
sage: G.gens()
22
(
23
[2 0 0 0 0 0] [4 0 0 0 0 1]
24
[0 3 0 0 0 0] [4 0 0 0 0 0]
25
[0 0 1 0 0 0] [0 4 0 0 0 0]
26
[0 0 0 1 0 0] [0 0 4 0 0 0]
27
[0 0 0 0 1 0] [0 0 0 4 0 0]
28
[0 0 0 0 0 1], [0 0 0 0 4 0]
29
)
30
"""
31
32
##############################################################################
33
# Copyright (C) 2006 David Joyner and William Stein <[email protected]>
34
# Copyright (C) 2013 Volker Braun <[email protected]>
35
#
36
# Distributed under the terms of the GNU General Public License (GPL)
37
#
38
# The full text of the GPL is available at:
39
#
40
# http://www.gnu.org/licenses/
41
##############################################################################
42
43
from sage.structure.unique_representation import UniqueRepresentation
44
from sage.groups.matrix_gps.matrix_group import (
45
MatrixGroup_generic, MatrixGroup_gap )
46
47
48
def normalize_args_vectorspace(*args, **kwds):
49
"""
50
Normalize the arguments that relate to a vector space.
51
52
INPUT:
53
54
Something that defines an affine space. For example
55
56
* An affine space itself:
57
58
- ``A`` -- affine space
59
60
* A vector space:
61
62
- ``V`` -- a vector space
63
64
* Degree and base ring:
65
66
- ``degree`` -- integer. The degree of the affine group, that
67
is, the dimension of the affine space the group is acting on.
68
69
- ``ring`` -- a ring or an integer. The base ring of the affine
70
space. If an integer is given, it must be a prime power and
71
the corresponding finite field is constructed.
72
73
- ``var='a'`` -- optional keyword argument to specify the finite
74
field generator name in the case where ``ring`` is a prime
75
power.
76
77
OUTPUT:
78
79
A pair ``(degree, ring)``.
80
81
TESTS::
82
83
sage: from sage.groups.matrix_gps.named_group import normalize_args_vectorspace
84
sage: A = AffineSpace(2, GF(4,'a')); A
85
Affine Space of dimension 2 over Finite Field in a of size 2^2
86
sage: normalize_args_vectorspace(A)
87
(2, Finite Field in a of size 2^2)
88
89
sage: normalize_args_vectorspace(2,4) # shorthand
90
(2, Finite Field in a of size 2^2)
91
92
sage: V = ZZ^3; V
93
Ambient free module of rank 3 over the principal ideal domain Integer Ring
94
sage: normalize_args_vectorspace(V)
95
(3, Integer Ring)
96
97
sage: normalize_args_vectorspace(2, QQ)
98
(2, Rational Field)
99
"""
100
from sage.rings.all import ZZ
101
if len(args) == 1:
102
V = args[0]
103
try:
104
degree = V.dimension_relative()
105
except AttributeError:
106
degree = V.dimension()
107
ring = V.base_ring()
108
if len(args) == 2:
109
degree, ring = args
110
from sage.rings.integer import is_Integer
111
try:
112
ring = ZZ(ring)
113
from sage.rings.finite_rings.constructor import FiniteField
114
var = kwds.get('var', 'a')
115
ring = FiniteField(ring, var)
116
except (ValueError, TypeError):
117
pass
118
return (ZZ(degree), ring)
119
120
121
class NamedMatrixGroup_generic(UniqueRepresentation, MatrixGroup_generic):
122
123
def __init__(self, degree, base_ring, special, sage_name, latex_string):
124
"""
125
Base class for "named" matrix groups
126
127
INPUT:
128
129
- ``degree`` -- integer. The degree (number of rows/columns of matrices).
130
131
- ``base_ring`` -- rinrg. The base ring of the matrices.
132
133
- ``special`` -- boolean. Whether the matrix group is special,
134
that is, elements have determinant one.
135
136
- ``latex_string`` -- string. The latex representation.
137
138
EXAMPLES::
139
140
sage: G = GL(2, QQ)
141
sage: from sage.groups.matrix_gps.named_group import NamedMatrixGroup_generic
142
sage: isinstance(G, NamedMatrixGroup_generic)
143
True
144
"""
145
MatrixGroup_generic.__init__(self, degree, base_ring)
146
self._special = special
147
self._name_string = sage_name
148
self._latex_string = latex_string
149
150
def _an_element_(self):
151
"""
152
Return an element.
153
154
OUTPUT:
155
156
A group element.
157
158
EXAMPLES::
159
160
sage: GL(2, QQ)._an_element_()
161
[1 0]
162
[0 1]
163
"""
164
return self(1)
165
166
def _repr_(self):
167
"""
168
Return a string representation.
169
170
OUTPUT:
171
172
String.
173
174
EXAMPLES::
175
176
sage: GL(2, QQ)._repr_()
177
'General Linear Group of degree 2 over Rational Field'
178
"""
179
return self._name_string
180
181
def _latex_(self):
182
"""
183
Return a LaTeX representation
184
185
OUTPUT:
186
187
String.
188
189
EXAMPLES::
190
191
sage: GL(2, QQ)._latex_()
192
'GL(2, \\Bold{Q})'
193
"""
194
return self._latex_string
195
196
def __eq__(self, other):
197
"""
198
Override comparison.
199
200
We need to override the comparison since the named groups
201
derive from
202
:class:`~sage.structure.unique_representation.UniqueRepresentation`,
203
which compare by identity.
204
205
EXAMPLES::
206
207
sage: G = GL(2,3)
208
sage: G == MatrixGroup(G.gens())
209
True
210
"""
211
return self.__cmp__(other) == 0
212
213
214
class NamedMatrixGroup_gap(NamedMatrixGroup_generic, MatrixGroup_gap):
215
216
def __init__(self, degree, base_ring, special, sage_name, latex_string, gap_command_string):
217
"""
218
Base class for "named" matrix groups using LibGAP
219
220
INPUT:
221
222
- ``degree`` -- integer. The degree (number of rows/columns of matrices).
223
224
- ``base_ring`` -- rinrg. The base ring of the matrices.
225
226
- ``special`` -- boolean. Whether the matrix group is special,
227
that is, elements have determinant one.
228
229
- ``latex_string`` -- string. The latex representation.
230
231
- ``gap_command_string`` -- string. The GAP command to construct the matrix group.
232
233
EXAMPLES::
234
235
sage: G = GL(2, GF(3))
236
sage: from sage.groups.matrix_gps.named_group import NamedMatrixGroup_gap
237
sage: isinstance(G, NamedMatrixGroup_gap)
238
True
239
"""
240
from sage.libs.gap.libgap import libgap
241
group = libgap.eval(gap_command_string)
242
MatrixGroup_gap.__init__(self, degree, base_ring, group)
243
self._special = special
244
self._gap_string = gap_command_string
245
self._name_string = sage_name
246
self._latex_string = latex_string
247
248
249