Path: blob/master/src/sage/groups/matrix_gps/named_group.py
8815 views
"""1Base for Classical Matrix Groups23This module implements the base class for matrix groups that have4various famous names, like the general linear group.56EXAMPLES::78sage: SL(2, ZZ)9Special Linear Group of degree 2 over Integer Ring10sage: G = SL(2,GF(3)); G11Special Linear Group of degree 2 over Finite Field of size 312sage: G.is_finite()13True14sage: G.conjugacy_class_representatives()15(16[1 0] [0 2] [0 1] [2 0] [0 2] [0 1] [0 2]17[0 1], [1 1], [2 1], [0 2], [1 2], [2 2], [1 0]18)19sage: G = SL(6,GF(5))20sage: G.gens()21(22[2 0 0 0 0 0] [4 0 0 0 0 1]23[0 3 0 0 0 0] [4 0 0 0 0 0]24[0 0 1 0 0 0] [0 4 0 0 0 0]25[0 0 0 1 0 0] [0 0 4 0 0 0]26[0 0 0 0 1 0] [0 0 0 4 0 0]27[0 0 0 0 0 1], [0 0 0 0 4 0]28)29"""3031##############################################################################32# Copyright (C) 2006 David Joyner and William Stein <[email protected]>33# Copyright (C) 2013 Volker Braun <[email protected]>34#35# Distributed under the terms of the GNU General Public License (GPL)36#37# The full text of the GPL is available at:38#39# http://www.gnu.org/licenses/40##############################################################################4142from sage.structure.unique_representation import UniqueRepresentation43from sage.groups.matrix_gps.matrix_group import (44MatrixGroup_generic, MatrixGroup_gap )454647def normalize_args_vectorspace(*args, **kwds):48"""49Normalize the arguments that relate to a vector space.5051INPUT:5253Something that defines an affine space. For example5455* An affine space itself:5657- ``A`` -- affine space5859* A vector space:6061- ``V`` -- a vector space6263* Degree and base ring:6465- ``degree`` -- integer. The degree of the affine group, that66is, the dimension of the affine space the group is acting on.6768- ``ring`` -- a ring or an integer. The base ring of the affine69space. If an integer is given, it must be a prime power and70the corresponding finite field is constructed.7172- ``var='a'`` -- optional keyword argument to specify the finite73field generator name in the case where ``ring`` is a prime74power.7576OUTPUT:7778A pair ``(degree, ring)``.7980TESTS::8182sage: from sage.groups.matrix_gps.named_group import normalize_args_vectorspace83sage: A = AffineSpace(2, GF(4,'a')); A84Affine Space of dimension 2 over Finite Field in a of size 2^285sage: normalize_args_vectorspace(A)86(2, Finite Field in a of size 2^2)8788sage: normalize_args_vectorspace(2,4) # shorthand89(2, Finite Field in a of size 2^2)9091sage: V = ZZ^3; V92Ambient free module of rank 3 over the principal ideal domain Integer Ring93sage: normalize_args_vectorspace(V)94(3, Integer Ring)9596sage: normalize_args_vectorspace(2, QQ)97(2, Rational Field)98"""99from sage.rings.all import ZZ100if len(args) == 1:101V = args[0]102try:103degree = V.dimension_relative()104except AttributeError:105degree = V.dimension()106ring = V.base_ring()107if len(args) == 2:108degree, ring = args109from sage.rings.integer import is_Integer110try:111ring = ZZ(ring)112from sage.rings.finite_rings.constructor import FiniteField113var = kwds.get('var', 'a')114ring = FiniteField(ring, var)115except (ValueError, TypeError):116pass117return (ZZ(degree), ring)118119120class NamedMatrixGroup_generic(UniqueRepresentation, MatrixGroup_generic):121122def __init__(self, degree, base_ring, special, sage_name, latex_string):123"""124Base class for "named" matrix groups125126INPUT:127128- ``degree`` -- integer. The degree (number of rows/columns of matrices).129130- ``base_ring`` -- rinrg. The base ring of the matrices.131132- ``special`` -- boolean. Whether the matrix group is special,133that is, elements have determinant one.134135- ``latex_string`` -- string. The latex representation.136137EXAMPLES::138139sage: G = GL(2, QQ)140sage: from sage.groups.matrix_gps.named_group import NamedMatrixGroup_generic141sage: isinstance(G, NamedMatrixGroup_generic)142True143"""144MatrixGroup_generic.__init__(self, degree, base_ring)145self._special = special146self._name_string = sage_name147self._latex_string = latex_string148149def _an_element_(self):150"""151Return an element.152153OUTPUT:154155A group element.156157EXAMPLES::158159sage: GL(2, QQ)._an_element_()160[1 0]161[0 1]162"""163return self(1)164165def _repr_(self):166"""167Return a string representation.168169OUTPUT:170171String.172173EXAMPLES::174175sage: GL(2, QQ)._repr_()176'General Linear Group of degree 2 over Rational Field'177"""178return self._name_string179180def _latex_(self):181"""182Return a LaTeX representation183184OUTPUT:185186String.187188EXAMPLES::189190sage: GL(2, QQ)._latex_()191'GL(2, \\Bold{Q})'192"""193return self._latex_string194195def __eq__(self, other):196"""197Override comparison.198199We need to override the comparison since the named groups200derive from201:class:`~sage.structure.unique_representation.UniqueRepresentation`,202which compare by identity.203204EXAMPLES::205206sage: G = GL(2,3)207sage: G == MatrixGroup(G.gens())208True209"""210return self.__cmp__(other) == 0211212213class NamedMatrixGroup_gap(NamedMatrixGroup_generic, MatrixGroup_gap):214215def __init__(self, degree, base_ring, special, sage_name, latex_string, gap_command_string):216"""217Base class for "named" matrix groups using LibGAP218219INPUT:220221- ``degree`` -- integer. The degree (number of rows/columns of matrices).222223- ``base_ring`` -- rinrg. The base ring of the matrices.224225- ``special`` -- boolean. Whether the matrix group is special,226that is, elements have determinant one.227228- ``latex_string`` -- string. The latex representation.229230- ``gap_command_string`` -- string. The GAP command to construct the matrix group.231232EXAMPLES::233234sage: G = GL(2, GF(3))235sage: from sage.groups.matrix_gps.named_group import NamedMatrixGroup_gap236sage: isinstance(G, NamedMatrixGroup_gap)237True238"""239from sage.libs.gap.libgap import libgap240group = libgap.eval(gap_command_string)241MatrixGroup_gap.__init__(self, degree, base_ring, group)242self._special = special243self._gap_string = gap_command_string244self._name_string = sage_name245self._latex_string = latex_string246247248249