Ticket #1834: 1834-gl_z_call.patch

File 1834-gl_z_call.patch, 4.9 kB (added by AlexGhitza, 4 months ago)
  • a/sage/groups/matrix_gps/general_linear.py

    old new  
    4040 
    4141from sage.rings.all import is_FiniteField, Integer, FiniteField 
    4242from matrix_group import MatrixGroup_gap, MatrixGroup_gap_finite_field 
     43from matrix_group_element import MatrixGroupElement 
    4344 
    4445def GL(n, R, var='a'): 
    4546    """ 
     
    107108        """ 
    108109        return "General Linear Group of degree %s over %s"%(self.degree(), self.base_ring()) 
    109110 
     111    def __call__(self, x): 
     112        """ 
     113        Construct a new element in this group, i.e. try to coerce x 
     114        into self if at all possible. 
     115 
     116        EXAMPLES: 
     117        This indicates that the issue from trac \#1834 is resolved: 
     118            sage: G = GL(3, ZZ) 
     119            sage: x = [[1,0,1], [0,1,0], [0,0,1]] 
     120            sage: G(x) 
     121            [1 0 1] 
     122            [0 1 0] 
     123            [0 0 1] 
     124        """ 
     125        if isinstance(x, MatrixGroupElement) and x.parent() is self: 
     126            return x 
     127        try: 
     128            m = self.matrix_space()(x) 
     129        except TypeError: 
     130            raise TypeError, "Cannot coerce %s to a %s-by-%s matrix over %s"%(x,self.degree(),self.degree(),self.base_ring()) 
     131        if m.is_invertible(): 
     132            return MatrixGroupElement(m, self) 
     133        else: 
     134            raise TypeError, "%s is not an invertible matrix"%(x) 
     135         
     136    def __contains__(self, x): 
     137        """ 
     138        Return True if x is an element of self, False otherwise. 
     139 
     140        EXAMPLES: 
     141            sage: G = GL(2, GF(101)) 
     142            sage: x = [[0,1], [1,0]] 
     143            sage: x in G 
     144            True 
     145         
     146            sage: G = GL(3, ZZ) 
     147            sage: x = [[1,0,1], [0,2,0], [0,0,1]] 
     148            sage: x in G 
     149            False 
     150        """ 
     151        try: 
     152            x = self(x) 
     153        except TypeError: 
     154            return False 
     155        return True 
     156 
    110157class GeneralLinearGroup_finite_field(GeneralLinearGroup_generic, MatrixGroup_gap_finite_field): 
    111158    pass 
  • a/sage/groups/matrix_gps/matrix_group.py

    old new  
    99   DJ (2007-12) -- Added invariant_generators (with M Albrecht, S King) 
    1010 
    1111This class is designed for computing with matrix groups defined by a 
    12 relatively (small) finite set of generating matrices. 
     12(relatively small) finite set of generating matrices. 
    1313 
    1414EXAMPLES: 
    1515    sage: F = GF(3) 
  • a/sage/groups/matrix_gps/special_linear.py

    old new  
    5858 
    5959from sage.rings.all import is_FiniteField, Integer, FiniteField 
    6060from matrix_group import MatrixGroup_gap, MatrixGroup_gap_finite_field 
     61from matrix_group_element import MatrixGroupElement 
    6162 
    6263def SL(n, R, var='a'): 
    6364    r""" 
     
    137138        """ 
    138139        return "Special Linear Group of degree %s over %s"%(self.degree(), self.base_ring()) 
    139140 
     141    def __call__(self, x): 
     142        """ 
     143        Construct a new element in this group, i.e. try to coerce x 
     144        into self if at all possible. 
     145 
     146        EXAMPLES: 
     147            sage: G = SL(3, ZZ) 
     148            sage: x = [[1,0,1], [0,1,0], [0,0,1]] 
     149            sage: G(x) 
     150            [1 0 1] 
     151            [0 1 0] 
     152            [0 0 1] 
     153        """ 
     154        if isinstance(x, MatrixGroupElement) and x.parent() is self: 
     155            return x 
     156        try: 
     157            m = self.matrix_space()(x) 
     158        except TypeError: 
     159            raise TypeError, "Cannot coerce %s to a %s-by-%s matrix over %s"%(x,self.degree(),self.degree(),self.base_ring()) 
     160        if m.determinant() == self.base_ring()(1): 
     161            return MatrixGroupElement(m, self) 
     162        else: 
     163            raise TypeError, "%s does not have determinant 1"%(x) 
     164 
     165    def __contains__(self, x): 
     166        """ 
     167        Return True if x is an element of self, False otherwise. 
     168 
     169        EXAMPLES: 
     170            sage: G = SL(2, GF(101)) 
     171            sage: x = [[1,1], [0,1]] 
     172            sage: x in G 
     173            True 
     174         
     175            sage: G = SL(3, ZZ) 
     176            sage: x = [[1,0,1], [0,-1,0], [0,0,1]] 
     177            sage: x in G 
     178            False 
     179        """ 
     180        try: 
     181            x = self(x) 
     182        except TypeError: 
     183            return False 
     184        return True 
     185 
    140186 
    141187     
    142188class SpecialLinearGroup_finite_field(SpecialLinearGroup_generic, MatrixGroup_gap_finite_field):