Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/modular/modsym/modsym.py
4045 views
1
# -*- coding: utf-8 -*-
2
r"""
3
Creation of modular symbols spaces
4
5
EXAMPLES: We create a space and output its category.
6
7
::
8
9
sage: C = HeckeModules(RationalField()); C
10
Category of Hecke modules over Rational Field
11
sage: M = ModularSymbols(11)
12
sage: M.category()
13
Category of Hecke modules over Rational Field
14
sage: M in C
15
True
16
17
We create a space compute the charpoly, then compute the same but
18
over a bigger field. In each case we also decompose the space using
19
`T_2`.
20
21
::
22
23
sage: M = ModularSymbols(23,2,base_ring=QQ)
24
sage: print M.T(2).charpoly('x').factor()
25
(x - 3) * (x^2 + x - 1)^2
26
sage: print M.decomposition(2)
27
[
28
Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Rational Field,
29
Modular Symbols subspace of dimension 4 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Rational Field
30
]
31
32
::
33
34
sage: M = ModularSymbols(23,2,base_ring=QuadraticField(5, 'sqrt5'))
35
sage: print M.T(2).charpoly('x').factor()
36
(x - 3) * (x - 1/2*sqrt5 + 1/2)^2 * (x + 1/2*sqrt5 + 1/2)^2
37
sage: print M.decomposition(2)
38
[
39
Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Number Field in sqrt5 with defining polynomial x^2 - 5,
40
Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Number Field in sqrt5 with defining polynomial x^2 - 5,
41
Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Number Field in sqrt5 with defining polynomial x^2 - 5
42
]
43
44
We compute some Hecke operators and do a consistency check::
45
46
sage: m = ModularSymbols(39, 2)
47
sage: t2 = m.T(2); t5 = m.T(5)
48
sage: t2*t5 - t5*t2 == 0
49
True
50
51
This tests the bug reported in trac #1220::
52
53
sage: G = GammaH(36, [13, 19])
54
sage: G.modular_symbols()
55
Modular Symbols space of dimension 13 for Congruence Subgroup Gamma_H(36) with H generated by [13, 19] of weight 2 with sign 0 and over Rational Field
56
sage: G.modular_symbols().cuspidal_subspace()
57
Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 13 for Congruence Subgroup Gamma_H(36) with H generated by [13, 19] of weight 2 with sign 0 and over Rational Field
58
59
This test catches a tricky corner case for spaces with character::
60
61
sage: ModularSymbols(DirichletGroup(20).1**3, weight=3, sign=1).cuspidal_subspace()
62
Modular Symbols subspace of dimension 3 of Modular Symbols space of dimension 6 and level 20, weight 3, character [1, -zeta4], sign 1, over Cyclotomic Field of order 4 and degree 2
63
"""
64
65
#*****************************************************************************
66
# Sage: System for Algebra and Geometry Experimentation
67
#
68
# Copyright (C) 2005 William Stein <[email protected]>
69
#
70
# Distributed under the terms of the GNU General Public License (GPL)
71
#
72
# This code is distributed in the hope that it will be useful,
73
# but WITHOUT ANY WARRANTY; without even the implied warranty of
74
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
75
# General Public License for more details.
76
#
77
# The full text of the GPL is available at:
78
#
79
# http://www.gnu.org/licenses/
80
#*****************************************************************************
81
82
import weakref
83
84
import ambient
85
import sage.modular.arithgroup.all as arithgroup
86
import sage.modular.dirichlet as dirichlet
87
import sage.rings.rational_field as rational_field
88
import sage.rings.all as rings
89
90
91
def canonical_parameters(group, weight, sign, base_ring):
92
"""
93
Return the canonically normalized parameters associated to a choice
94
of group, weight, sign, and base_ring. That is, normalize each of
95
these to be of the correct type, perform all appropriate type
96
checking, etc.
97
98
EXAMPLES::
99
100
sage: p1 = sage.modular.modsym.modsym.canonical_parameters(5,int(2),1,QQ) ; p1
101
(Congruence Subgroup Gamma0(5), 2, 1, Rational Field)
102
sage: p2 = sage.modular.modsym.modsym.canonical_parameters(Gamma0(5),2,1,QQ) ; p2
103
(Congruence Subgroup Gamma0(5), 2, 1, Rational Field)
104
sage: p1 == p2
105
True
106
sage: type(p1[1])
107
<type 'sage.rings.integer.Integer'>
108
"""
109
sign = rings.Integer(sign)
110
if not (sign in [-1,0,1]):
111
raise ValueError, "sign must be -1, 0, or 1"
112
113
weight = rings.Integer(weight)
114
if weight <= 1:
115
raise ValueError, "the weight must be at least 2"
116
117
if isinstance(group, (int, rings.Integer)):
118
group = arithgroup.Gamma0(group)
119
120
elif isinstance(group, dirichlet.DirichletCharacter):
121
try:
122
eps = group.minimize_base_ring()
123
except NotImplementedError:
124
# TODO -- implement minimize_base_ring over finite fields
125
eps = group
126
G = eps.parent()
127
if eps.is_trivial():
128
group = arithgroup.Gamma0(eps.modulus())
129
else:
130
group = (eps, G)
131
if base_ring is None: base_ring = eps.base_ring()
132
133
if base_ring is None: base_ring = rational_field.RationalField()
134
135
if not rings.is_CommutativeRing(base_ring):
136
raise TypeError, "base_ring (=%s) must be a commutative ring"%base_ring
137
138
if not base_ring.is_field():
139
raise TypeError, "(currently) base_ring (=%s) must be a field"%base_ring
140
141
return group, weight, sign, base_ring
142
143
_cache = {}
144
145
def ModularSymbols_clear_cache():
146
"""
147
Clear the global cache of modular symbols spaces.
148
149
EXAMPLES::
150
151
sage: sage.modular.modsym.modsym.ModularSymbols_clear_cache()
152
sage: sage.modular.modsym.modsym._cache.keys()
153
[]
154
sage: M = ModularSymbols(6,2)
155
sage: sage.modular.modsym.modsym._cache.keys()
156
[(Congruence Subgroup Gamma0(6), 2, 0, Rational Field)]
157
sage: sage.modular.modsym.modsym.ModularSymbols_clear_cache()
158
sage: sage.modular.modsym.modsym._cache.keys()
159
[]
160
161
TESTS:
162
163
Make sure #10548 is fixed
164
sage: import gc
165
sage: m=ModularSymbols(Gamma1(29))
166
sage: m=[]
167
sage: ModularSymbols_clear_cache()
168
sage: gc.collect() # random
169
3422
170
sage: a=[x for x in gc.get_objects() if isinstance(x,sage.modular.modsym.ambient.ModularSymbolsAmbient_wtk_g1)]
171
sage: a
172
[]
173
174
"""
175
global _cache
176
_cache = {}
177
178
def ModularSymbols(group = 1,
179
weight = 2,
180
sign = 0,
181
base_ring = None,
182
use_cache = True,
183
custom_init=None):
184
r"""
185
Create an ambient space of modular symbols.
186
187
INPUT:
188
189
- ``group`` - A congruence subgroup or a Dirichlet character eps.
190
- ``weight`` - int, the weight, which must be = 2.
191
- ``sign`` - int, The sign of the involution on modular symbols
192
induced by complex conjugation. The default is 0, which means
193
"no sign", i.e., take the whole space.
194
- ``base_ring`` - the base ring. Defaults to `\QQ` if no character
195
is given, or to the minimal extension of `\QQ` containing the
196
values of the character.
197
- ``custom_init`` - a function that is called with self as input
198
before any computations are done using self; this could be used
199
to set a custom modular symbols presentation. If self is
200
already in the cache and use_cache=True, then this function is
201
not called.
202
203
EXAMPLES: First we create some spaces with trivial character::
204
205
sage: ModularSymbols(Gamma0(11),2).dimension()
206
3
207
sage: ModularSymbols(Gamma0(1),12).dimension()
208
3
209
210
If we give an integer N for the congruence subgroup, it defaults to
211
`\Gamma_0(N)`::
212
213
sage: ModularSymbols(1,12,-1).dimension()
214
1
215
sage: ModularSymbols(11,4, sign=1)
216
Modular Symbols space of dimension 4 for Gamma_0(11) of weight 4 with sign 1 over Rational Field
217
218
We create some spaces for `\Gamma_1(N)`.
219
220
::
221
222
sage: ModularSymbols(Gamma1(13),2)
223
Modular Symbols space of dimension 15 for Gamma_1(13) of weight 2 with sign 0 and over Rational Field
224
sage: ModularSymbols(Gamma1(13),2, sign=1).dimension()
225
13
226
sage: ModularSymbols(Gamma1(13),2, sign=-1).dimension()
227
2
228
sage: [ModularSymbols(Gamma1(7),k).dimension() for k in [2,3,4,5]]
229
[5, 8, 12, 16]
230
sage: ModularSymbols(Gamma1(5),11).dimension()
231
20
232
233
We create a space for `\Gamma_H(N)`::
234
235
sage: G = GammaH(15,[4,13])
236
sage: M = ModularSymbols(G,2)
237
sage: M.decomposition()
238
[
239
Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 for Congruence Subgroup Gamma_H(15) with H generated by [4, 13] of weight 2 with sign 0 and over Rational Field,
240
Modular Symbols subspace of dimension 3 of Modular Symbols space of dimension 5 for Congruence Subgroup Gamma_H(15) with H generated by [4, 13] of weight 2 with sign 0 and over Rational Field
241
]
242
243
We create a space with character::
244
245
sage: e = (DirichletGroup(13).0)^2
246
sage: e.order()
247
6
248
sage: M = ModularSymbols(e, 2); M
249
Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2
250
sage: f = M.T(2).charpoly('x'); f
251
x^4 + (-zeta6 - 1)*x^3 - 8*zeta6*x^2 + (10*zeta6 - 5)*x + 21*zeta6 - 21
252
sage: f.factor()
253
(x - 2*zeta6 - 1) * (x - zeta6 - 2) * (x + zeta6 + 1)^2
254
255
We create a space with character over a larger base ring than the values of the character::
256
257
sage: ModularSymbols(e, 2, base_ring = CyclotomicField(24))
258
Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta24^4], sign 0, over Cyclotomic Field of order 24 and degree 8
259
260
More examples of spaces with character::
261
262
sage: e = DirichletGroup(5, RationalField()).gen(); e
263
Dirichlet character modulo 5 of conductor 5 mapping 2 |--> -1
264
265
sage: m = ModularSymbols(e, 2); m
266
Modular Symbols space of dimension 2 and level 5, weight 2, character [-1], sign 0, over Rational Field
267
268
::
269
270
sage: m.T(2).charpoly('x')
271
x^2 - 1
272
sage: m = ModularSymbols(e, 6); m.dimension()
273
6
274
sage: m.T(2).charpoly('x')
275
x^6 - 873*x^4 - 82632*x^2 - 1860496
276
277
We create a space of modular symbols with nontrivial character in
278
characteristic 2.
279
280
::
281
282
sage: G = DirichletGroup(13,GF(4,'a')); G
283
Group of Dirichlet characters of modulus 13 over Finite Field in a of size 2^2
284
sage: e = G.list()[2]; e
285
Dirichlet character modulo 13 of conductor 13 mapping 2 |--> a + 1
286
sage: M = ModularSymbols(e,4); M
287
Modular Symbols space of dimension 8 and level 13, weight 4, character [a + 1], sign 0, over Finite Field in a of size 2^2
288
sage: M.basis()
289
([X*Y,(1,0)], [X*Y,(1,5)], [X*Y,(1,10)], [X*Y,(1,11)], [X^2,(0,1)], [X^2,(1,10)], [X^2,(1,11)], [X^2,(1,12)])
290
sage: M.T(2).matrix()
291
[ 0 0 0 0 0 0 1 1]
292
[ 0 0 0 0 0 0 0 0]
293
[ 0 0 0 0 0 a + 1 1 a]
294
[ 0 0 0 0 0 1 a + 1 a]
295
[ 0 0 0 0 a + 1 0 1 1]
296
[ 0 0 0 0 0 a 1 a]
297
[ 0 0 0 0 0 0 a + 1 a]
298
[ 0 0 0 0 0 0 1 0]
299
300
We illustrate the custom_init function, which can be used to make
301
arbitrary changes to the modular symbols object before its
302
presentation is computed::
303
304
sage: ModularSymbols_clear_cache()
305
sage: def custom_init(M):
306
... M.customize='hi'
307
sage: M = ModularSymbols(1,12, custom_init=custom_init)
308
sage: M.customize
309
'hi'
310
311
We illustrate the relation between custom_init and use_cache::
312
313
sage: def custom_init(M):
314
... M.customize='hi2'
315
sage: M = ModularSymbols(1,12, custom_init=custom_init)
316
sage: M.customize
317
'hi'
318
sage: M = ModularSymbols(1,12, custom_init=custom_init, use_cache=False)
319
sage: M.customize
320
'hi2'
321
322
TESTS: We test use_cache::
323
324
sage: ModularSymbols_clear_cache()
325
sage: M = ModularSymbols(11,use_cache=False)
326
sage: sage.modular.modsym.modsym._cache
327
{}
328
sage: M = ModularSymbols(11,use_cache=True)
329
sage: sage.modular.modsym.modsym._cache
330
{(Congruence Subgroup Gamma0(11), 2, 0, Rational Field): <weakref at ...; to 'ModularSymbolsAmbient_wt2_g0_with_category' at ...>}
331
sage: M is ModularSymbols(11,use_cache=True)
332
True
333
sage: M is ModularSymbols(11,use_cache=False)
334
False
335
"""
336
key = canonical_parameters(group, weight, sign, base_ring)
337
338
if use_cache and _cache.has_key(key):
339
M = _cache[key]()
340
if not (M is None): return M
341
342
(group, weight, sign, base_ring) = key
343
344
M = None
345
if arithgroup.is_Gamma0(group):
346
if weight == 2:
347
M = ambient.ModularSymbolsAmbient_wt2_g0(
348
group.level(),sign, base_ring, custom_init=custom_init)
349
else:
350
M = ambient.ModularSymbolsAmbient_wtk_g0(
351
group.level(), weight, sign, base_ring, custom_init=custom_init)
352
353
elif arithgroup.is_Gamma1(group):
354
355
M = ambient.ModularSymbolsAmbient_wtk_g1(group.level(),
356
weight, sign, base_ring, custom_init=custom_init)
357
358
elif arithgroup.is_GammaH(group):
359
360
M = ambient.ModularSymbolsAmbient_wtk_gamma_h(group,
361
weight, sign, base_ring, custom_init=custom_init)
362
363
elif isinstance(group, tuple):
364
eps = group[0]
365
M = ambient.ModularSymbolsAmbient_wtk_eps(eps,
366
weight, sign, base_ring, custom_init=custom_init)
367
368
if M is None:
369
raise NotImplementedError, "computation of requested space of modular symbols not defined or implemented"
370
371
if use_cache:
372
_cache[key] = weakref.ref(M)
373
return M
374
375
376