Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/groups/matrix_gps/general_linear.py
4056 views
1
r"""
2
General Linear Groups
3
4
EXAMPLES::
5
6
sage: GL(4,QQ)
7
General Linear Group of degree 4 over Rational Field
8
sage: GL(1,ZZ)
9
General Linear Group of degree 1 over Integer Ring
10
sage: GL(100,RR)
11
General Linear Group of degree 100 over Real Field with 53 bits of precision
12
sage: GL(3,GF(49,'a'))
13
General Linear Group of degree 3 over Finite Field in a of size 7^2
14
15
AUTHORS:
16
17
- David Joyner (2006-01)
18
19
- William Stein (2006-01)
20
21
- David Joyner (2006-05): added _latex_, __str__, examples
22
23
- William Stein (2006-12-09): rewrite
24
"""
25
26
##TODO: Rework this and \code{special_linear} into MatrixGroup class for any
27
##field, wrapping all of GAP's matrix group commands in chapter 41
28
##Matrix Groups of the GAP reference manual.
29
30
31
#*****************************************************************************
32
# Copyright (C) 2005 William Stein <[email protected]>
33
#
34
# Distributed under the terms of the GNU General Public License (GPL)
35
#
36
# This code is distributed in the hope that it will be useful,
37
# but WITHOUT ANY WARRANTY; without even the implied warranty of
38
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39
# General Public License for more details.
40
#
41
# The full text of the GPL is available at:
42
#
43
# http://www.gnu.org/licenses/
44
#*****************************************************************************
45
46
from sage.structure.unique_representation import UniqueRepresentation
47
from sage.rings.all import is_FiniteField, Integer, FiniteField
48
from matrix_group import MatrixGroup_gap, MatrixGroup_gap_finite_field
49
50
def GL(n, R, var='a'):
51
"""
52
Return the general linear group of degree `n` over the ring
53
`R`.
54
55
EXAMPLES::
56
57
sage: G = GL(6,GF(5))
58
sage: G.order()
59
11064475422000000000000000
60
sage: G.base_ring()
61
Finite Field of size 5
62
sage: G.category()
63
Category of finite groups
64
sage: TestSuite(G).run()
65
66
sage: G = GL(6, QQ)
67
sage: G.category()
68
Category of groups
69
sage: TestSuite(G).run()
70
71
Here is the Cayley graph of (relatively small) finite General Linear Group::
72
73
sage: g = GL(2,3)
74
sage: d = g.cayley_graph(); d
75
Digraph on 48 vertices
76
sage: d.show(color_by_label=True, vertex_size=0.03, vertex_labels=False)
77
sage: d.show3d(color_by_label=True)
78
79
::
80
81
sage: F = GF(3); MS = MatrixSpace(F,2,2)
82
sage: gens = [MS([[0,1],[1,0]]),MS([[1,1],[0,1]])]
83
sage: G = MatrixGroup(gens)
84
sage: G.order()
85
48
86
sage: G.cardinality()
87
48
88
sage: H = GL(2,F)
89
sage: H.order()
90
48
91
sage: H == G # Do we really want this equality?
92
False
93
sage: H.as_matrix_group() == G
94
True
95
sage: H.gens()
96
[
97
[2 0]
98
[0 1],
99
[2 1]
100
[2 0]
101
]
102
"""
103
if isinstance(R, (int, long, Integer)):
104
R = FiniteField(R, var)
105
if is_FiniteField(R):
106
return GeneralLinearGroup_finite_field(n, R)
107
return GeneralLinearGroup_generic(n, R)
108
109
class GeneralLinearGroup_generic(UniqueRepresentation, MatrixGroup_gap):
110
"""
111
TESTS::
112
113
sage: G6 = GL(6, QQ)
114
sage: G6 == G6
115
True
116
sage: G6 != G6 # check that #8695 is fixed.
117
False
118
"""
119
def _gap_init_(self):
120
"""
121
EXAMPLES::
122
123
sage: G = GL(6,GF(5))
124
sage: G._gap_init_()
125
'GL(6, GF(5))'
126
"""
127
return "GL(%s, %s)"%(self.degree(), self.base_ring()._gap_init_())
128
129
def _latex_(self):
130
"""
131
EXAMPLES::
132
133
sage: G = GL(6,GF(5))
134
sage: latex(G)
135
\text{GL}_{6}(\Bold{F}_{5})
136
"""
137
return "\\text{GL}_{%s}(%s)"%(self.degree(), self.base_ring()._latex_())
138
139
def _repr_(self):
140
"""
141
String representation of this linear group.
142
143
EXAMPLES::
144
145
sage: GL(6,GF(5))
146
General Linear Group of degree 6 over Finite Field of size 5
147
"""
148
return "General Linear Group of degree %s over %s"%(self.degree(), self.base_ring())
149
150
def __call__(self, x):
151
"""
152
Construct a new element in this group, i.e. try to coerce x into
153
self if at all possible.
154
155
EXAMPLES: This indicates that the issue from trac #1834 is
156
resolved::
157
158
sage: G = GL(3, ZZ)
159
sage: x = [[1,0,1], [0,1,0], [0,0,1]]
160
sage: G(x)
161
[1 0 1]
162
[0 1 0]
163
[0 0 1]
164
"""
165
if isinstance(x, self.element_class) and x.parent() is self:
166
return x
167
try:
168
m = self.matrix_space()(x)
169
except TypeError:
170
raise TypeError, "Cannot coerce %s to a %s-by-%s matrix over %s"%(x,self.degree(),self.degree(),self.base_ring())
171
if m.is_invertible():
172
return self.element_class(m, self)
173
else:
174
raise TypeError, "%s is not an invertible matrix"%(x)
175
176
def __contains__(self, x):
177
"""
178
Return True if x is an element of self, False otherwise.
179
180
EXAMPLES::
181
182
sage: G = GL(2, GF(101))
183
sage: x = [[0,1], [1,0]]
184
sage: x in G
185
True
186
187
::
188
189
sage: G = GL(3, ZZ)
190
sage: x = [[1,0,1], [0,2,0], [0,0,1]]
191
sage: x in G
192
False
193
"""
194
try:
195
x = self(x)
196
except TypeError:
197
return False
198
return True
199
200
class GeneralLinearGroup_finite_field(GeneralLinearGroup_generic, MatrixGroup_gap_finite_field):
201
pass
202
203