This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
/
free_module_linear_group.py
569 lines (451 loc) · 19.4 KB
/
free_module_linear_group.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
r"""
General linear group of a free module
The set `\mathrm{GL}(M)` of automorphisms (i.e. invertible endomorphims) of a
free module of finite rank `M` is a group under composition of automorphisms,
named the *general linear group* of `M`. In other words, `\mathrm{GL}(M)` is
the group of units (i.e. invertible elements) of `\mathrm{End}(M)`, the
endomorphism ring of `M`.
The group `\mathrm{GL}(M)` is implemented via the class
:class:`FreeModuleLinearGroup`.
AUTHORS:
- Eric Gourgoulhon (2015): initial version
REFERENCES:
- Chap. 15 of R. Godement: *Algebra*, Hermann (Paris) / Houghton Mifflin
(Boston) (1968)
"""
#******************************************************************************
# Copyright (C) 2015 Eric Gourgoulhon <eric.gourgoulhon@obspm.fr>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#******************************************************************************
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent
from sage.categories.groups import Groups
from sage.tensor.modules.finite_rank_free_module import FiniteRankFreeModule
from sage.tensor.modules.free_module_automorphism import FreeModuleAutomorphism
import six
class FreeModuleLinearGroup(UniqueRepresentation, Parent):
r"""
General linear group of a free module of finite rank over a commutative
ring.
Given a free module of finite rank `M` over a commutative ring `R`, the
*general linear group* of `M` is the group `\mathrm{GL}(M)` of
automorphisms (i.e. invertible endomorphims) of `M`. It is the group of
units (i.e. invertible elements) of `\mathrm{End}(M)`, the endomorphism
ring of `M`.
This is a Sage *parent* class, whose *element* class is
:class:`~sage.tensor.modules.free_module_automorphism.FreeModuleAutomorphism`.
INPUT:
- ``fmodule`` -- free module `M` of finite rank over a commutative ring
`R`, as an instance of
:class:`~sage.tensor.modules.finite_rank_free_module.FiniteRankFreeModule`
EXAMPLES:
General linear group of a free `\ZZ`-module of rank 3::
sage: M = FiniteRankFreeModule(ZZ, 3, name='M')
sage: e = M.basis('e')
sage: from sage.tensor.modules.free_module_linear_group import FreeModuleLinearGroup
sage: GL = FreeModuleLinearGroup(M) ; GL
General linear group of the Rank-3 free module M over the Integer Ring
Instead of importing FreeModuleLinearGroup in the global name space, it is
recommended to use the module's method
:meth:`~sage.tensor.modules.finite_rank_free_module.FiniteRankFreeModule.general_linear_group`::
sage: GL = M.general_linear_group() ; GL
General linear group of the Rank-3 free module M over the Integer Ring
sage: latex(GL)
\mathrm{GL}\left( M \right)
As most parents, the general linear group has a unique instance::
sage: GL is M.general_linear_group()
True
`\mathrm{GL}(M)` is in the category of groups::
sage: GL.category()
Category of groups
sage: GL in Groups()
True
``GL`` is a *parent* object, whose elements are automorphisms of `M`,
represented by instances of the class
:class:`~sage.tensor.modules.free_module_automorphism.FreeModuleAutomorphism`::
sage: GL.Element
<class 'sage.tensor.modules.free_module_automorphism.FreeModuleAutomorphism'>
sage: a = GL.an_element() ; a
Automorphism of the Rank-3 free module M over the Integer Ring
sage: a.matrix(e)
[ 1 0 0]
[ 0 -1 0]
[ 0 0 1]
sage: a in GL
True
sage: GL.is_parent_of(a)
True
As an endomorphism, ``a`` maps elements of `M` to elements of `M`::
sage: v = M.an_element() ; v
Element of the Rank-3 free module M over the Integer Ring
sage: v.display()
e_0 + e_1 + e_2
sage: a(v)
Element of the Rank-3 free module M over the Integer Ring
sage: a(v).display()
e_0 - e_1 + e_2
An automorphism can also be viewed as a tensor of type (1,1) on `M`::
sage: a.tensor_type()
(1, 1)
sage: a.display(e)
e_0*e^0 - e_1*e^1 + e_2*e^2
sage: type(a)
<class 'sage.tensor.modules.free_module_automorphism.FreeModuleLinearGroup_with_category.element_class'>
As for any group, the identity element is obtained by the method
:meth:`one`::
sage: id = GL.one() ; id
Identity map of the Rank-3 free module M over the Integer Ring
sage: id*a == a
True
sage: a*id == a
True
sage: a*a^(-1) == id
True
sage: a^(-1)*a == id
True
The identity element is of course the identity map of the module `M`::
sage: id(v) == v
True
sage: id.matrix(e)
[1 0 0]
[0 1 0]
[0 0 1]
The module's changes of basis are stored as elements of the general linear
group::
sage: f = M.basis('f', from_family=(-e[1], 4*e[0]+3*e[2], 7*e[0]+5*e[2]))
sage: f
Basis (f_0,f_1,f_2) on the Rank-3 free module M over the Integer Ring
sage: M.change_of_basis(e,f)
Automorphism of the Rank-3 free module M over the Integer Ring
sage: M.change_of_basis(e,f) in GL
True
sage: M.change_of_basis(e,f).parent()
General linear group of the Rank-3 free module M over the Integer Ring
sage: M.change_of_basis(e,f).matrix(e)
[ 0 4 7]
[-1 0 0]
[ 0 3 5]
sage: M.change_of_basis(e,f) == M.change_of_basis(f,e).inverse()
True
Since every automorphism is an endomorphism, there is a coercion
`\mathrm{GL}(M) \rightarrow \mathrm{End}(M)` (the endomorphism ring of
module `M`)::
sage: End(M).has_coerce_map_from(GL)
True
(see :class:`~sage.tensor.modules.free_module_homset.FreeModuleHomset` for
details), but not in the reverse direction, since only bijective
endomorphisms are automorphisms::
sage: GL.has_coerce_map_from(End(M))
False
A bijective endomorphism can be converted to an element of
`\mathrm{GL}(M)`::
sage: h = M.endomorphism([[1,0,0], [0,-1,2], [0,1,-3]]) ; h
Generic endomorphism of Rank-3 free module M over the Integer Ring
sage: h.parent() is End(M)
True
sage: ah = GL(h) ; ah
Automorphism of the Rank-3 free module M over the Integer Ring
sage: ah.parent() is GL
True
As maps `M\rightarrow M`, ``ah`` and ``h`` are identical::
sage: v # recall
Element of the Rank-3 free module M over the Integer Ring
sage: ah(v) == h(v)
True
sage: ah.matrix(e) == h.matrix(e)
True
Of course, non-invertible endomorphisms cannot be converted to elements of
`\mathrm{GL}(M)`::
sage: GL(M.endomorphism([[0,0,0], [0,-1,2], [0,1,-3]]))
Traceback (most recent call last):
...
TypeError: the Generic endomorphism of Rank-3 free module M over the
Integer Ring is not invertible
Similarly, there is a coercion `\mathrm{GL}(M)\rightarrow T^{(1,1)}(M)`
(module of type-(1,1) tensors)::
sage: M.tensor_module(1,1).has_coerce_map_from(GL)
True
(see :class:`~sage.tensor.modules.tensor_free_module.TensorFreeModule` for
details), but not in the reverse direction, since not every type-(1,1)
tensor can be considered as an automorphism::
sage: GL.has_coerce_map_from(M.tensor_module(1,1))
False
Invertible type-(1,1) tensors can be converted to automorphisms::
sage: t = M.tensor((1,1), name='t')
sage: t[e,:] = [[-1,0,0], [0,1,2], [0,1,3]]
sage: at = GL(t) ; at
Automorphism t of the Rank-3 free module M over the Integer Ring
sage: at.matrix(e)
[-1 0 0]
[ 0 1 2]
[ 0 1 3]
sage: at.matrix(e) == t[e,:]
True
Non-invertible ones cannot::
sage: t0 = M.tensor((1,1), name='t_0')
sage: t0[e,0,0] = 1
sage: t0[e,:] # the matrix is clearly not invertible
[1 0 0]
[0 0 0]
[0 0 0]
sage: GL(t0)
Traceback (most recent call last):
...
TypeError: the Type-(1,1) tensor t_0 on the Rank-3 free module M over
the Integer Ring is not invertible
sage: t0[e,1,1], t0[e,2,2] = 2, 3
sage: t0[e,:] # the matrix is not invertible in Mat_3(ZZ)
[1 0 0]
[0 2 0]
[0 0 3]
sage: GL(t0)
Traceback (most recent call last):
...
TypeError: the Type-(1,1) tensor t_0 on the Rank-3 free module M over
the Integer Ring is not invertible
"""
Element = FreeModuleAutomorphism
def __init__(self, fmodule):
r"""
See :class:`FreeModuleLinearGroup` for documentation and examples.
TESTS::
sage: M = FiniteRankFreeModule(ZZ, 3, name='M')
sage: e = M.basis('e')
sage: from sage.tensor.modules.free_module_linear_group import FreeModuleLinearGroup
sage: GL = FreeModuleLinearGroup(M) ; GL
General linear group of the Rank-3 free module M over the Integer Ring
sage: GL.category()
Category of groups
sage: TestSuite(GL).run()
"""
if not isinstance(fmodule, FiniteRankFreeModule):
raise TypeError("{} is not a free module of finite rank".format(
fmodule))
Parent.__init__(self, category=Groups())
self._fmodule = fmodule
self._one = None # to be set by self.one()
#### Parent methods ####
def _element_constructor_(self, comp=[], basis=None, name=None,
latex_name=None):
r"""
Construct a free module automorphism.
INPUT:
- ``comp`` -- (default: ``[]``) components representing the
automorphism with respect to ``basis``; this entry can actually be
any array of size rank(M)*rank(M) from which a matrix of elements
of ``self`` base ring can be constructed; the *columns* of ``comp``
must be the components w.r.t. ``basis`` of the images of the elements
of ``basis``. If ``comp`` is ``[]``, the automorphism has to be
initialized afterwards by method
:meth:`~sage.tensor.modules.free_module_tensor.FreeModuleTensor.set_comp`
or via the operator [].
- ``basis`` -- (default: ``None``) basis of ``self`` defining the
matrix representation; if ``None`` the default basis of ``self`` is
assumed.
- ``name`` -- (default: ``None``) name given to the automorphism
- ``latex_name`` -- (default: ``None``) LaTeX symbol to denote the
automorphism; if none is provided, the LaTeX symbol is set to ``name``
OUTPUT:
- instance of
:class:`~sage.tensor.modules.free_module_automorphism.FreeModuleAutomorphism`
EXAMPLES:
Generic construction::
sage: M = FiniteRankFreeModule(ZZ, 2, name='M')
sage: e = M.basis('e')
sage: GL = M.general_linear_group()
sage: a = GL._element_constructor_(comp=[[1,2],[1,3]], basis=e,
....: name='a')
sage: a
Automorphism a of the Rank-2 free module M over the Integer Ring
sage: a.matrix(e)
[1 2]
[1 3]
Identity map constructed from integer 1::
sage: GL._element_constructor_(1)
Identity map of the Rank-2 free module M over the Integer Ring
sage: GL._element_constructor_(1).matrix(e)
[1 0]
[0 1]
Construction from an invertible endomorphism::
sage: phi = M.endomorphism([[1,1], [2,3]])
sage: a = GL._element_constructor_(phi) ; a
Automorphism of the Rank-2 free module M over the Integer Ring
sage: a.matrix(e)
[1 1]
[2 3]
sage: a.matrix(e) == phi.matrix(e)
True
Construction from an invertible tensor of type (1,1)::
sage: t = M.tensor((1,1), name='t')
sage: t[e,:] = [[1,1], [2,3]]
sage: a = GL._element_constructor_(t) ; a
Automorphism t of the Rank-2 free module M over the Integer Ring
sage: a.matrix(e) == t[e,:]
True
"""
from sage.tensor.modules.free_module_tensor import FreeModuleTensor
from sage.tensor.modules.free_module_morphism import \
FiniteRankFreeModuleMorphism
if comp == 1:
return self.one()
if isinstance(comp, FreeModuleTensor):
tens = comp # for readability
# Conversion of a type-(1,1) tensor to an automorphism
if tens.tensor_type() == (1,1):
resu = self.element_class(self._fmodule, name=tens._name,
latex_name=tens._latex_name)
for basis, comp in six.iteritems(tens._components):
resu._components[basis] = comp.copy()
# Check whether the tensor is invertible:
try:
resu.inverse()
except (ZeroDivisionError, TypeError):
raise TypeError("the {} is not invertible ".format(tens))
return resu
else:
raise TypeError("the {} cannot be converted ".format(tens)
+ "to an automorphism.")
if isinstance(comp, FiniteRankFreeModuleMorphism):
# Conversion of an endomorphism to an automorphism
endo = comp # for readability
if endo.is_endomorphism() and self._fmodule is endo.domain():
resu = self.element_class(self._fmodule, name=endo._name,
latex_name=endo._latex_name)
for basis, mat in six.iteritems(endo._matrices):
resu.add_comp(basis[0])[:] = mat
# Check whether the endomorphism is invertible:
try:
resu.inverse()
except (ZeroDivisionError, TypeError):
raise TypeError("the {} is not invertible ".format(endo))
return resu
else:
raise TypeError("cannot coerce the {}".format(endo) +
" to an element of {}".format(self))
# standard construction
resu = self.element_class(self._fmodule, name=name,
latex_name=latex_name)
if comp:
resu.set_comp(basis)[:] = comp
return resu
def _an_element_(self):
r"""
Construct some specific free module automorphism.
OUTPUT:
- instance of
:class:`~sage.tensor.modules.free_module_automorphism.FreeModuleAutomorphism`
EXAMPLES::
sage: M = FiniteRankFreeModule(ZZ, 2, name='M')
sage: e = M.basis('e')
sage: GL = M.general_linear_group()
sage: a = GL._an_element_() ; a
Automorphism of the Rank-2 free module M over the Integer Ring
sage: a.matrix(e)
[ 1 0]
[ 0 -1]
"""
resu = self.element_class(self._fmodule)
if self._fmodule._def_basis is not None:
comp = resu.set_comp()
for i in self._fmodule.irange():
if i%2 == 0:
comp[[i,i]] = self._fmodule._ring.one()
else:
comp[[i,i]] = -(self._fmodule._ring.one())
return resu
#### End of parent methods ####
#### Monoid methods ####
def one(self):
r"""
Return the group identity element of ``self``.
The group identity element is nothing but the module identity map.
OUTPUT:
- instance of
:class:`~sage.tensor.modules.free_module_automorphism.FreeModuleAutomorphism`
representing the identity element.
EXAMPLES:
Identity element of the general linear group of a rank-2 free module::
sage: M = FiniteRankFreeModule(ZZ, 2, name='M', start_index=1)
sage: GL = M.general_linear_group()
sage: GL.one()
Identity map of the Rank-2 free module M over the Integer Ring
The identity element is cached::
sage: GL.one() is GL.one()
True
Check that the element returned is indeed the neutral element for
the group law::
sage: e = M.basis('e')
sage: a = GL([[3,4],[5,7]], basis=e) ; a
Automorphism of the Rank-2 free module M over the Integer Ring
sage: a.matrix(e)
[3 4]
[5 7]
sage: GL.one() * a == a
True
sage: a * GL.one() == a
True
sage: a * a^(-1) == GL.one()
True
sage: a^(-1) * a == GL.one()
True
The unit element of `\mathrm{GL}(M)` is the identity map of `M`::
sage: GL.one()(e[1])
Element e_1 of the Rank-2 free module M over the Integer Ring
sage: GL.one()(e[2])
Element e_2 of the Rank-2 free module M over the Integer Ring
Its matrix is the identity matrix in any basis::
sage: GL.one().matrix(e)
[1 0]
[0 1]
sage: f = M.basis('f', from_family=(e[1]+2*e[2], e[1]+3*e[2]))
sage: GL.one().matrix(f)
[1 0]
[0 1]
"""
if self._one is None:
self._one = self.element_class(self._fmodule, is_identity=True)
# Initialization of the components (Kronecker delta) in some basis:
if self._fmodule.bases():
self._one.components(self._fmodule.bases()[0])
return self._one
#### End of monoid methods ####
def _repr_(self):
r"""
Return a string representation of ``self``.
EXAMPLE::
sage: M = FiniteRankFreeModule(ZZ, 2, name='M')
sage: GL = M.general_linear_group()
sage: GL._repr_()
'General linear group of the Rank-2 free module M over the Integer Ring'
"""
return "General linear group of the {}".format(self._fmodule)
def _latex_(self):
r"""
Return a string representation of ``self``.
EXAMPLE::
sage: M = FiniteRankFreeModule(ZZ, 2, name='M')
sage: GL = M.general_linear_group()
sage: GL._latex_()
\mathrm{GL}\left( M \right)
"""
from sage.misc.latex import latex
return r"\mathrm{GL}\left("+ latex(self._fmodule)+ r"\right)"
def base_module(self):
r"""
Return the free module of which ``self`` is the general linear group.
OUTPUT:
- instance of :class:`FiniteRankFreeModule` representing the free
module of which ``self`` is the general linear group
EXAMPLE::
sage: M = FiniteRankFreeModule(ZZ, 2, name='M')
sage: GL = M.general_linear_group()
sage: GL.base_module()
Rank-2 free module M over the Integer Ring
sage: GL.base_module() is M
True
"""
return self._fmodule