Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/modular/modsym/element.py
4045 views
1
"""
2
A single element of an ambient space of modular symbols
3
"""
4
5
#*****************************************************************************
6
# Sage: System for Algebra and Geometry Experimentation
7
#
8
# Copyright (C) 2005 William Stein <[email protected]>
9
#
10
# Distributed under the terms of the GNU General Public License (GPL)
11
#
12
# This code is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
16
#
17
# The full text of the GPL is available at:
18
#
19
# http://www.gnu.org/licenses/
20
#*****************************************************************************
21
22
23
import sage.modules.free_module_element
24
import sage.misc.misc as misc
25
import sage.structure.formal_sum as formal_sum
26
import ambient
27
import sage.modular.hecke.all as hecke
28
import sage.misc.latex as latex
29
30
_print_mode = "manin"
31
32
def is_ModularSymbolsElement(x):
33
r"""
34
Return True if x is an element of a modular symbols space.
35
36
EXAMPLES::
37
38
sage: sage.modular.modsym.element.is_ModularSymbolsElement(ModularSymbols(11, 2).0)
39
True
40
sage: sage.modular.modsym.element.is_ModularSymbolsElement(13)
41
False
42
"""
43
return isinstance(x, ModularSymbolsElement)
44
45
def set_modsym_print_mode(mode="manin"):
46
"""
47
Set the mode for printing of elements of modular symbols spaces.
48
49
INPUT:
50
51
- ``mode`` - a string. The possibilities are as
52
follows:
53
54
- ``'manin'`` - (the default) formal sums of Manin
55
symbols [P(X,Y),(u,v)]
56
57
- ``'modular'`` - formal sums of Modular symbols
58
P(X,Y)\*alpha,beta, where alpha and beta are cusps
59
60
- ``'vector'`` - as vectors on the basis for the
61
ambient space
62
63
OUTPUT: none
64
65
EXAMPLE::
66
67
sage: M = ModularSymbols(13, 8)
68
sage: x = M.0 + M.1 + M.14
69
sage: set_modsym_print_mode('manin'); x
70
[X^5*Y,(1,11)] + [X^5*Y,(1,12)] + [X^6,(1,11)]
71
sage: set_modsym_print_mode('modular'); x
72
1610510*X^6*{-1/11, 0} - 248832*X^6*{-1/12, 0} + 893101*X^5*Y*{-1/11, 0} - 103680*X^5*Y*{-1/12, 0} + 206305*X^4*Y^2*{-1/11, 0} - 17280*X^4*Y^2*{-1/12, 0} + 25410*X^3*Y^3*{-1/11, 0} - 1440*X^3*Y^3*{-1/12, 0} + 1760*X^2*Y^4*{-1/11, 0} - 60*X^2*Y^4*{-1/12, 0} + 65*X*Y^5*{-1/11, 0} - X*Y^5*{-1/12, 0} + Y^6*{-1/11, 0}
73
sage: set_modsym_print_mode('vector'); x
74
(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0)
75
sage: set_modsym_print_mode()
76
"""
77
mode = str(mode).lower()
78
if not (mode in ['manin', 'modular', 'vector']):
79
raise ValueError, "mode must be one of 'manin', 'modular', or 'vector'"
80
global _print_mode
81
_print_mode = mode
82
83
class ModularSymbolsElement(hecke.HeckeModuleElement):
84
"""
85
An element of a space of modular symbols.
86
87
TESTS::
88
89
sage: x = ModularSymbols(3, 12).cuspidal_submodule().gen(0)
90
sage: x == loads(dumps(x))
91
True
92
"""
93
def __init__(self, parent, x, check=True):
94
"""
95
INPUT:
96
97
98
- ``parent`` - a space of modular symbols
99
100
- ``x`` - a free module element that represents the
101
modular symbol in terms of a basis for the ambient space (not in
102
terms of a basis for parent!)
103
104
EXAMPLE::
105
106
sage: S = ModularSymbols(11, sign=1).cuspidal_submodule()
107
sage: S(vector([0,1]))
108
(1,9)
109
sage: S(vector([1,0]))
110
Traceback (most recent call last):
111
...
112
TypeError: x does not coerce to an element of this Hecke module
113
"""
114
if check:
115
if not isinstance(parent, ambient.ModularSymbolsAmbient):
116
raise TypeError, "parent must be an ambient space of modular symbols."
117
if not isinstance(x, sage.modules.free_module_element.FreeModuleElement):
118
raise TypeError, "x must be a free module element."
119
if x.degree() != parent.degree():
120
raise TypeError, "x (of degree %s) must be of degree the same as the degree of the parent (of degree %s)."%(x.degree(), parent.degree())
121
hecke.HeckeModuleElement.__init__(self, parent, x)
122
123
def __cmp__(self, other):
124
r""" Standard comparison function.
125
126
EXAMPLE::
127
128
sage: M = ModularSymbols(11, 2)
129
sage: M.0 == M.1 # indirect doctest
130
False
131
sage: M.0 == (M.1 + M.0 - M.1)
132
True
133
sage: M.0 == ModularSymbols(13, 2).0
134
False
135
sage: M.0 == 4
136
False
137
"""
138
return self.element().__cmp__(other.element())
139
140
def _repr_(self):
141
r"""
142
String representation of self. The output will depend on the global
143
modular symbols print mode setting controlled by the function
144
``set_modsym_print_mode``.
145
146
EXAMPLE::
147
148
sage: M = ModularSymbols(13, 4)
149
sage: set_modsym_print_mode('manin'); M.0._repr_()
150
'[X^2,(0,1)]'
151
sage: set_modsym_print_mode('modular'); M.0._repr_()
152
'X^2*{0, Infinity}'
153
sage: set_modsym_print_mode('vector'); M.0._repr_()
154
'(1, 0, 0, 0, 0, 0, 0, 0)'
155
sage: set_modsym_print_mode()
156
"""
157
if _print_mode == "vector":
158
return str(self.element())
159
elif _print_mode == "manin":
160
m = self.manin_symbol_rep()
161
elif _print_mode == "modular":
162
m = self.modular_symbol_rep()
163
return misc.repr_lincomb([(t,c) for c,t in m])
164
165
def _latex_(self):
166
r"""
167
LaTeX representation of self. The output will be determined by the print mode setting set using ``set_modsym_print_mode``.
168
169
EXAMPLE::
170
171
sage: M = ModularSymbols(11, 2)
172
sage: x = M.0 + M.2; x
173
(1,0) + (1,9)
174
sage: set_modsym_print_mode('manin'); latex(x) # indirect doctest
175
(1,0) + (1,9)
176
sage: set_modsym_print_mode('modular'); latex(x) # indirect doctest
177
\left\{\frac{-1}{9}, 0\right\} + \left\{\infty, 0\right\}
178
sage: set_modsym_print_mode('vector'); latex(x) # indirect doctest
179
\left(1,\,0,\,1\right)
180
sage: set_modsym_print_mode()
181
"""
182
183
if _print_mode == "vector":
184
return self.element()._latex_()
185
elif _print_mode == "manin":
186
m = self.manin_symbol_rep()
187
elif _print_mode == "modular":
188
m = self.modular_symbol_rep()
189
c = [x[0] for x in m]
190
v = [x[1] for x in m]
191
# TODO: use repr_lincomb with is_latex=True
192
return latex.repr_lincomb(v, c)
193
194
def _add_(self, right):
195
r"""
196
Sum of self and other.
197
198
EXAMPLE::
199
200
sage: M = ModularSymbols(3, 12)
201
sage: x = M.0; y = M.1; z = x + y; z # indirect doctest
202
[X^8*Y^2,(1,2)] + [X^9*Y,(1,0)]
203
sage: z.parent() is M
204
True
205
"""
206
return ModularSymbolsElement(self.parent(), self.element() + right.element(), check=False)
207
208
def _rmul_(self, other):
209
r"""
210
Right-multiply self by other.
211
212
EXAMPLE::
213
214
sage: M = ModularSymbols(3, 12)
215
sage: x = M.0; z = x*3; z # indirect doctest
216
3*[X^8*Y^2,(1,2)]
217
sage: z.parent() is M
218
True
219
sage: z*Mod(1, 17)
220
Traceback (most recent call last):
221
...
222
TypeError: unsupported operand parent(s) for '*': 'Modular Symbols space of dimension 8 for Gamma_0(3) of weight 12 with sign 0 over Rational Field' and 'Ring of integers modulo 17'
223
"""
224
return ModularSymbolsElement(self.parent(), self.element()*other, check=False)
225
226
def _lmul_(self, left):
227
r"""
228
Left-multiply self by other.
229
230
EXAMPLE::
231
232
sage: M = ModularSymbols(3, 12)
233
sage: x = M.0; z = 3*x; z # indirect doctest
234
3*[X^8*Y^2,(1,2)]
235
sage: z.parent() is M
236
True
237
sage: Mod(1, 17)*z
238
Traceback (most recent call last):
239
...
240
TypeError: unsupported operand parent(s) for '*': 'Ring of integers modulo 17' and 'Modular Symbols space of dimension 8 for Gamma_0(3) of weight 12 with sign 0 over Rational Field'
241
"""
242
return ModularSymbolsElement(self.parent(), left*self.element(), check=False)
243
244
def _neg_(self):
245
r"""
246
Multiply by -1.
247
248
EXAMPLE::
249
250
sage: M = ModularSymbols(3, 12)
251
sage: x = M.0; z = -x; z # indirect doctest
252
-[X^8*Y^2,(1,2)]
253
sage: z.parent() is M
254
True
255
"""
256
return ModularSymbolsElement(self.parent(), -self.element(), check=False)
257
258
def _sub_(self, other):
259
r"""
260
Subtract other from self.
261
262
EXAMPLE::
263
264
sage: M = ModularSymbols(3, 12)
265
sage: x = M.0; y = M.1; z = y-x; z # indirect doctest
266
-[X^8*Y^2,(1,2)] + [X^9*Y,(1,0)]
267
sage: z.parent() is M
268
True
269
"""
270
return ModularSymbolsElement(self.parent(), self.element() - other.element(), check=False)
271
272
# this clearly hasn't worked for some time -- the method embedded_vector_space doesn't exist -- DL 2009-05-18
273
# def coordinate_vector(self):
274
# if self.parent().is_ambient():
275
# return self.element()
276
# return self.parent().embedded_vector_space().coordinate_vector(self.element())
277
278
def list(self):
279
r"""
280
Return a list of the coordinates of self in terms of a basis for the ambient space.
281
282
EXAMPLE::
283
284
sage: ModularSymbols(37, 2).0.list()
285
[1, 0, 0, 0, 0]
286
"""
287
return self.element().list()
288
289
def manin_symbol_rep(self):
290
"""
291
Returns a representation of self as a formal sum of Manin symbols.
292
293
EXAMPLE::
294
295
sage: x = ModularSymbols(37, 4).0
296
sage: x.manin_symbol_rep()
297
[X^2,(0,1)]
298
299
The result is cached::
300
301
sage: x.manin_symbol_rep() is x.manin_symbol_rep()
302
True
303
"""
304
try:
305
return self.__manin_symbols
306
except AttributeError:
307
A = self.parent()
308
v = self.element()
309
manin_symbols = A.ambient_hecke_module().manin_symbols_basis()
310
F = formal_sum.FormalSums(A.base_ring())
311
ms = F([(v[i], manin_symbols[i]) for i in \
312
range(v.degree()) if v[i] != 0], check=False, reduce=False)
313
self.__manin_symbols = ms
314
return self.__manin_symbols
315
316
def modular_symbol_rep(self):
317
"""
318
Returns a representation of self as a formal sum of modular
319
symbols.
320
321
EXAMPLE::
322
323
sage: x = ModularSymbols(37, 4).0
324
sage: x.modular_symbol_rep()
325
X^2*{0, Infinity}
326
327
The result is cached::
328
329
sage: x.modular_symbol_rep() is x.modular_symbol_rep()
330
True
331
"""
332
try:
333
return self.__modular_symbols
334
except AttributeError:
335
A = self.parent()
336
v = self.manin_symbol_rep()
337
if v == 0:
338
return v
339
w = [c * x.modular_symbol_rep() for c, x in v]
340
self.__modular_symbols = sum(w)
341
return self.__modular_symbols
342
343
344
345