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 40 40 41 41 from sage.rings.all import is_FiniteField, Integer, FiniteField 42 42 from matrix_group import MatrixGroup_gap, MatrixGroup_gap_finite_field 43 from matrix_group_element import MatrixGroupElement 43 44 44 45 def GL(n, R, var='a'): 45 46 """ … … 107 108 """ 108 109 return "General Linear Group of degree %s over %s"%(self.degree(), self.base_ring()) 109 110 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 110 157 class GeneralLinearGroup_finite_field(GeneralLinearGroup_generic, MatrixGroup_gap_finite_field): 111 158 pass -
a/sage/groups/matrix_gps/matrix_group.py
old new 9 9 DJ (2007-12) -- Added invariant_generators (with M Albrecht, S King) 10 10 11 11 This 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. 13 13 14 14 EXAMPLES: 15 15 sage: F = GF(3) -
a/sage/groups/matrix_gps/special_linear.py
old new 58 58 59 59 from sage.rings.all import is_FiniteField, Integer, FiniteField 60 60 from matrix_group import MatrixGroup_gap, MatrixGroup_gap_finite_field 61 from matrix_group_element import MatrixGroupElement 61 62 62 63 def SL(n, R, var='a'): 63 64 r""" … … 137 138 """ 138 139 return "Special Linear Group of degree %s over %s"%(self.degree(), self.base_ring()) 139 140 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 140 186 141 187 142 188 class SpecialLinearGroup_finite_field(SpecialLinearGroup_generic, MatrixGroup_gap_finite_field):