Path: blob/master/sage/groups/matrix_gps/general_linear.py
4056 views
r"""1General Linear Groups23EXAMPLES::45sage: GL(4,QQ)6General Linear Group of degree 4 over Rational Field7sage: GL(1,ZZ)8General Linear Group of degree 1 over Integer Ring9sage: GL(100,RR)10General Linear Group of degree 100 over Real Field with 53 bits of precision11sage: GL(3,GF(49,'a'))12General Linear Group of degree 3 over Finite Field in a of size 7^21314AUTHORS:1516- David Joyner (2006-01)1718- William Stein (2006-01)1920- David Joyner (2006-05): added _latex_, __str__, examples2122- William Stein (2006-12-09): rewrite23"""2425##TODO: Rework this and \code{special_linear} into MatrixGroup class for any26##field, wrapping all of GAP's matrix group commands in chapter 4127##Matrix Groups of the GAP reference manual.282930#*****************************************************************************31# Copyright (C) 2005 William Stein <[email protected]>32#33# Distributed under the terms of the GNU General Public License (GPL)34#35# This code is distributed in the hope that it will be useful,36# but WITHOUT ANY WARRANTY; without even the implied warranty of37# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU38# General Public License for more details.39#40# The full text of the GPL is available at:41#42# http://www.gnu.org/licenses/43#*****************************************************************************4445from sage.structure.unique_representation import UniqueRepresentation46from sage.rings.all import is_FiniteField, Integer, FiniteField47from matrix_group import MatrixGroup_gap, MatrixGroup_gap_finite_field4849def GL(n, R, var='a'):50"""51Return the general linear group of degree `n` over the ring52`R`.5354EXAMPLES::5556sage: G = GL(6,GF(5))57sage: G.order()581106447542200000000000000059sage: G.base_ring()60Finite Field of size 561sage: G.category()62Category of finite groups63sage: TestSuite(G).run()6465sage: G = GL(6, QQ)66sage: G.category()67Category of groups68sage: TestSuite(G).run()6970Here is the Cayley graph of (relatively small) finite General Linear Group::7172sage: g = GL(2,3)73sage: d = g.cayley_graph(); d74Digraph on 48 vertices75sage: d.show(color_by_label=True, vertex_size=0.03, vertex_labels=False)76sage: d.show3d(color_by_label=True)7778::7980sage: F = GF(3); MS = MatrixSpace(F,2,2)81sage: gens = [MS([[0,1],[1,0]]),MS([[1,1],[0,1]])]82sage: G = MatrixGroup(gens)83sage: G.order()844885sage: G.cardinality()864887sage: H = GL(2,F)88sage: H.order()894890sage: H == G # Do we really want this equality?91False92sage: H.as_matrix_group() == G93True94sage: H.gens()95[96[2 0]97[0 1],98[2 1]99[2 0]100]101"""102if isinstance(R, (int, long, Integer)):103R = FiniteField(R, var)104if is_FiniteField(R):105return GeneralLinearGroup_finite_field(n, R)106return GeneralLinearGroup_generic(n, R)107108class GeneralLinearGroup_generic(UniqueRepresentation, MatrixGroup_gap):109"""110TESTS::111112sage: G6 = GL(6, QQ)113sage: G6 == G6114True115sage: G6 != G6 # check that #8695 is fixed.116False117"""118def _gap_init_(self):119"""120EXAMPLES::121122sage: G = GL(6,GF(5))123sage: G._gap_init_()124'GL(6, GF(5))'125"""126return "GL(%s, %s)"%(self.degree(), self.base_ring()._gap_init_())127128def _latex_(self):129"""130EXAMPLES::131132sage: G = GL(6,GF(5))133sage: latex(G)134\text{GL}_{6}(\Bold{F}_{5})135"""136return "\\text{GL}_{%s}(%s)"%(self.degree(), self.base_ring()._latex_())137138def _repr_(self):139"""140String representation of this linear group.141142EXAMPLES::143144sage: GL(6,GF(5))145General Linear Group of degree 6 over Finite Field of size 5146"""147return "General Linear Group of degree %s over %s"%(self.degree(), self.base_ring())148149def __call__(self, x):150"""151Construct a new element in this group, i.e. try to coerce x into152self if at all possible.153154EXAMPLES: This indicates that the issue from trac #1834 is155resolved::156157sage: G = GL(3, ZZ)158sage: x = [[1,0,1], [0,1,0], [0,0,1]]159sage: G(x)160[1 0 1]161[0 1 0]162[0 0 1]163"""164if isinstance(x, self.element_class) and x.parent() is self:165return x166try:167m = self.matrix_space()(x)168except TypeError:169raise TypeError, "Cannot coerce %s to a %s-by-%s matrix over %s"%(x,self.degree(),self.degree(),self.base_ring())170if m.is_invertible():171return self.element_class(m, self)172else:173raise TypeError, "%s is not an invertible matrix"%(x)174175def __contains__(self, x):176"""177Return True if x is an element of self, False otherwise.178179EXAMPLES::180181sage: G = GL(2, GF(101))182sage: x = [[0,1], [1,0]]183sage: x in G184True185186::187188sage: G = GL(3, ZZ)189sage: x = [[1,0,1], [0,2,0], [0,0,1]]190sage: x in G191False192"""193try:194x = self(x)195except TypeError:196return False197return True198199class GeneralLinearGroup_finite_field(GeneralLinearGroup_generic, MatrixGroup_gap_finite_field):200pass201202203