passagemath-eclib 10.6.40__cp314-cp314t-macosx_13_0_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of passagemath-eclib might be problematic. Click here for more details.

@@ -0,0 +1,8 @@
1
+ # sage_setup: distribution = sagemath-eclib
2
+ from sage.libs.eclib cimport mat
3
+
4
+ cdef class Matrix:
5
+ cdef mat* M
6
+
7
+ cdef class MatrixFactory:
8
+ cdef new_matrix(self, mat M)
@@ -0,0 +1,247 @@
1
+ # sage_setup: distribution = sagemath-eclib
2
+ """
3
+ Cremona matrices
4
+ """
5
+
6
+ from sage.libs.eclib cimport scalar, addscalar
7
+
8
+ from sage.matrix.matrix_space import MatrixSpace
9
+ from sage.rings.integer_ring import ZZ
10
+
11
+ from sage.matrix.matrix_integer_sparse cimport Matrix_integer_sparse
12
+ from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense
13
+ from sage.rings.integer cimport Integer
14
+
15
+ cdef class Matrix:
16
+ """
17
+ A Cremona Matrix.
18
+
19
+ EXAMPLES::
20
+
21
+ sage: M = CremonaModularSymbols(225)
22
+ sage: t = M.hecke_matrix(2)
23
+ sage: type(t)
24
+ <class 'sage.libs.eclib.mat.Matrix'>
25
+ sage: t
26
+ 61 x 61 Cremona matrix over Rational Field
27
+
28
+ TESTS::
29
+
30
+ sage: t = CremonaModularSymbols(11).hecke_matrix(2); t
31
+ 3 x 3 Cremona matrix over Rational Field
32
+ sage: type(t)
33
+ <class 'sage.libs.eclib.mat.Matrix'>
34
+ """
35
+ def __repr__(self):
36
+ """
37
+ String representation of this matrix. Use print(self.str()) to
38
+ print out the matrix entries on the screen.
39
+
40
+ EXAMPLES::
41
+
42
+ sage: M = CremonaModularSymbols(23)
43
+ sage: t = M.hecke_matrix(2); t
44
+ 5 x 5 Cremona matrix over Rational Field
45
+ sage: print(t.str())
46
+ [ 3 0 0 0 0]
47
+ [-1 -1 0 0 -1]
48
+ [ 1 1 0 1 1]
49
+ [-1 1 1 -1 0]
50
+ [ 0 -1 0 0 0]
51
+ """
52
+ return "%s x %s Cremona matrix over Rational Field" % (self.nrows(), self.ncols())
53
+
54
+ def str(self):
55
+ r"""
56
+ Return full string representation of this matrix, never in compact form.
57
+
58
+ EXAMPLES::
59
+
60
+ sage: M = CremonaModularSymbols(22, sign=1)
61
+ sage: t = M.hecke_matrix(13)
62
+ sage: t.str()
63
+ '[14 0 0 0 0]\n[-4 12 0 8 4]\n[ 0 -6 4 -6 0]\n[ 4 2 0 6 -4]\n[ 0 0 0 0 14]'
64
+ """
65
+ return self.sage_matrix_over_ZZ(sparse=False).str()
66
+
67
+ def __dealloc__(self):
68
+ del self.M
69
+
70
+ def __getitem__(self, ij):
71
+ """
72
+ Return the (i,j) entry of this matrix.
73
+
74
+ Here, ij is a 2-tuple (i,j) and the row and column indices start
75
+ at 1 and not 0.
76
+
77
+ EXAMPLES::
78
+
79
+ sage: M = CremonaModularSymbols(19, sign=1)
80
+ sage: t = M.hecke_matrix(13); t
81
+ 2 x 2 Cremona matrix over Rational Field
82
+ sage: t.sage_matrix_over_ZZ()
83
+ [ 28 0]
84
+ [-12 -8]
85
+ sage: [[t.__getitem__((i,j)) for j in [1,2]] for i in [1,2]]
86
+ [[28, 0], [-12, -8]]
87
+ sage: t.__getitem__((0,0))
88
+ Traceback (most recent call last):
89
+ ...
90
+ IndexError: matrix indices out of range
91
+ """
92
+ cdef long i, j
93
+ if self.M:
94
+ i, j = ij
95
+ if 0<i and i<=self.M[0].nrows() and 0<j and j<=self.M[0].ncols():
96
+ return self.M.sub(i,j)
97
+ raise IndexError("matrix indices out of range")
98
+ raise IndexError("cannot index into an undefined matrix")
99
+
100
+ def nrows(self):
101
+ """
102
+ Return the number of rows of this matrix.
103
+
104
+ EXAMPLES::
105
+
106
+ sage: M = CremonaModularSymbols(19, sign=1)
107
+ sage: t = M.hecke_matrix(13); t
108
+ 2 x 2 Cremona matrix over Rational Field
109
+ sage: t.nrows()
110
+ 2
111
+ """
112
+ return self.M[0].nrows()
113
+
114
+ def ncols(self):
115
+ """
116
+ Return the number of columns of this matrix.
117
+
118
+ EXAMPLES::
119
+
120
+ sage: M = CremonaModularSymbols(1234, sign=1)
121
+ sage: t = M.hecke_matrix(3); t.ncols()
122
+ 156
123
+ sage: M.dimension()
124
+ 156
125
+ """
126
+ return self.M[0].ncols()
127
+
128
+ # Commented out since it gives very weird
129
+ # results when sign != 0.
130
+ ## def rank(self):
131
+ ## """
132
+ ## Return the rank of this matrix.
133
+
134
+ ## EXAMPLES::
135
+ ##
136
+ ## sage: M = CremonaModularSymbols(389)
137
+ ## sage: t = M.hecke_matrix(2)
138
+ ## sage: t.rank()
139
+ ## 65
140
+ ## sage: M = CremonaModularSymbols(389, cuspidal=True)
141
+ ## sage: t = M.hecke_matrix(2)
142
+ ## sage: t.rank()
143
+ ## 64
144
+
145
+ ## sage: M = CremonaModularSymbols(389,sign=1)
146
+ ## sage: t = M.hecke_matrix(2)
147
+ ## sage: t.rank() # known bug.
148
+ ## 16
149
+ ## """
150
+ ## return rank(self.M[0])
151
+
152
+ def add_scalar(self, scalar s):
153
+ """
154
+ Return new matrix obtained by adding `s` to each diagonal entry of ``self``.
155
+
156
+ EXAMPLES::
157
+
158
+ sage: M = CremonaModularSymbols(23, cuspidal=True, sign=1)
159
+ sage: t = M.hecke_matrix(2); print(t.str())
160
+ [ 0 1]
161
+ [ 1 -1]
162
+ sage: w = t.add_scalar(3); print(w.str())
163
+ [3 1]
164
+ [1 2]
165
+ """
166
+ return new_Matrix(addscalar(self.M[0], s))
167
+
168
+ def charpoly(self, var='x'):
169
+ """
170
+ Return the characteristic polynomial of this matrix, viewed as
171
+ as a matrix over the integers.
172
+
173
+ ALGORITHM:
174
+
175
+ Note that currently, this function converts this matrix into a
176
+ dense matrix over the integers, then calls the charpoly
177
+ algorithm on that, which I think is LinBox's.
178
+
179
+ EXAMPLES::
180
+
181
+ sage: M = CremonaModularSymbols(33, cuspidal=True, sign=1)
182
+ sage: t = M.hecke_matrix(2)
183
+ sage: t.charpoly()
184
+ x^3 + 3*x^2 - 4
185
+ sage: t.charpoly().factor()
186
+ (x - 1) * (x + 2)^2
187
+ """
188
+ return self.sage_matrix_over_ZZ(sparse=False).charpoly(var)
189
+
190
+ def sage_matrix_over_ZZ(self, sparse=True):
191
+ """
192
+ Return corresponding Sage matrix over the integers.
193
+
194
+ INPUT:
195
+
196
+ - ``sparse`` -- boolean (default: ``True``); whether the return matrix has
197
+ a sparse representation
198
+
199
+ EXAMPLES::
200
+
201
+ sage: M = CremonaModularSymbols(23, cuspidal=True, sign=1)
202
+ sage: t = M.hecke_matrix(2)
203
+ sage: s = t.sage_matrix_over_ZZ(); s
204
+ [ 0 1]
205
+ [ 1 -1]
206
+ sage: type(s)
207
+ <class 'sage.matrix.matrix_integer_sparse.Matrix_integer_sparse'>
208
+ sage: s = t.sage_matrix_over_ZZ(sparse=False); s
209
+ [ 0 1]
210
+ [ 1 -1]
211
+ sage: type(s)
212
+ <class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
213
+ """
214
+ cdef long n = self.nrows()
215
+ cdef long i, j
216
+
217
+ cdef Matrix_integer_dense Td
218
+ cdef Matrix_integer_sparse Ts
219
+
220
+ # Ugly code...
221
+ if sparse:
222
+ Ts = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix().__copy__()
223
+ for i from 0 <= i < n:
224
+ for j from 0 <= j < n:
225
+ Mij = Integer(self.M.sub(i+1,j+1))
226
+ if Mij:
227
+ Ts.set_unsafe(i, j, Mij)
228
+ return Ts
229
+ else:
230
+ Td = MatrixSpace(ZZ, n, sparse=sparse).zero_matrix().__copy__()
231
+ for i from 0 <= i < n:
232
+ for j from 0 <= j < n:
233
+ Mij = Integer(self.M.sub(i+1,j+1))
234
+ if Mij:
235
+ Td.set_unsafe(i, j, Mij)
236
+ return Td
237
+
238
+
239
+ cdef class MatrixFactory:
240
+ cdef new_matrix(self, mat M):
241
+ return new_Matrix(M)
242
+
243
+
244
+ cdef Matrix new_Matrix(mat M):
245
+ cdef Matrix A = Matrix()
246
+ A.M = new mat(M)
247
+ return A