Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/modular/modsym/tests.py
4045 views
1
"""
2
Testing modular symbols spaces.
3
4
TESTS:
5
sage: m = ModularSymbols(389)
6
sage: [(g.degree(), e) for g, e in m.T(2).fcp()]
7
[(1, 1), (1, 2), (2, 2), (3, 2), (6, 2), (20, 2)]
8
"""
9
10
#*****************************************************************************
11
# Sage: System for Algebra and Geometry Experimentation
12
#
13
# Copyright (C) 2005 William Stein <[email protected]>
14
#
15
# Distributed under the terms of the GNU General Public License (GPL)
16
#
17
# This code is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
# General Public License for more details.
21
#
22
# The full text of the GPL is available at:
23
#
24
# http://www.gnu.org/licenses/
25
#*****************************************************************************
26
27
28
import random
29
30
import modsym
31
import sage.modular.dirichlet as dirichlet
32
import sage.modular.arithgroup.all as arithgroup
33
from sage.misc.misc import cputime
34
35
class Test:
36
"""
37
Modular symbol testing class.
38
"""
39
def __init__(self, levels=20, weights=4, onlyg0=False, onlyg1=False, onlychar=False):
40
"""
41
Create a modular symbol testing object.
42
43
INPUT:
44
levels -- list or int
45
weights -- list or int
46
onlyg0 -- bool, if True only select Gamma0 spaces for testing
47
onlyg1 -- bool, if True only select Gamma1 spaces for testing
48
onlychar -- bool, if True only selects spaces with character for testing
49
50
EXAMPLES:
51
sage: sage.modular.modsym.tests.Test()
52
Modular symbols testing class
53
sage: T = sage.modular.modsym.tests.Test(weights=[3,5,7])
54
sage: T.weights
55
[3, 5, 7]
56
sage: T = sage.modular.modsym.tests.Test(levels=5) ; T.levels
57
[1, 2, 3, 4, 5]
58
"""
59
if not isinstance(levels, list):
60
levels = range(1,int(levels)+1)
61
if not isinstance(weights, list):
62
weights = range(2,int(weights)+1)
63
self.levels = levels
64
self.weights = weights
65
if len(levels) < 1:
66
raise RuntimeError, "levels must have positive length"
67
if len(weights) < 1:
68
raise RuntimeError, "weights must have positive length"
69
self.current_space = None
70
self.onlyg0 = onlyg0
71
self.onlyg1 = onlyg1
72
self.onlychar = onlychar
73
74
def __repr__(self):
75
"""
76
Return the string representation of self.
77
78
EXAMPLES:
79
sage: sage.modular.modsym.tests.Test().__repr__()
80
'Modular symbols testing class'
81
"""
82
return "Modular symbols testing class"
83
84
def _modular_symbols_space(self):
85
"""
86
Generate a random space of modular symbols subject to
87
the conditions of self.
88
89
EXAMPLES:
90
sage: T = sage.modular.modsym.tests.Test(levels=[5],weights=[2], onlychar=True)
91
92
Note that the sign of the generated space is always arbitrary.
93
sage: T._modular_symbols_space()
94
character
95
level = 5, weight = 2, sign = ...
96
...
97
"""
98
if self.onlyg0:
99
which = 0
100
elif self.onlyg1:
101
which = 1
102
elif self.onlychar:
103
which = 2
104
else:
105
which = random.randrange(0,3)
106
if which == 0:
107
print "gamma0"
108
M = self._modular_symbols_space_gamma0()
109
elif which == 1:
110
print "gamma1"
111
M = self._modular_symbols_space_gamma1()
112
else:
113
print "character"
114
M = self._modular_symbols_space_character()
115
print "\t",M
116
return M
117
118
def _level_weight_sign(self):
119
"""
120
Return a triple containing a random choice of level from from
121
self.levels, weights from self.weights, and sign chosen
122
randomly from [1, 0, -1].
123
124
EXAMPLES:
125
sage: sage.modular.modsym.tests.Test()._level_weight_sign() # random
126
level = 4, weight = 3, sign = 1
127
(4, 3, 1)
128
"""
129
level = random.choice(self.levels)
130
weight = random.choice(self.weights)
131
sign = random.choice([-1,0,1])
132
print "level = %s, weight = %s, sign = %s"%(level,weight,sign)
133
return level, weight, sign
134
135
def _modular_symbols_space_gamma0(self):
136
"""
137
Return a space of modular symbols for Gamma0, with level a
138
random choice from self.levels, weight from self.weights, and
139
sign chosen randomly from [1, 0, -1].
140
141
EXAMPLES:
142
sage: sage.modular.modsym.tests.Test()._modular_symbols_space_gamma0() # random
143
level = 1, weight = 3, sign = 0
144
Modular Symbols space of dimension 0 for Gamma_0(1) of weight 3 with sign 0 over Rational Field
145
"""
146
level, weight, sign = self._level_weight_sign()
147
M = modsym.ModularSymbols(arithgroup.Gamma0(level), weight, sign)
148
self.current_space = M
149
return M
150
151
def _modular_symbols_space_gamma1(self):
152
"""
153
Return a space of modular symbols for Gamma1, with level a
154
random choice from self.levels, weight from self.weights, and
155
sign chosen randomly from [1, 0, -1].
156
157
EXAMPLES:
158
sage: sage.modular.modsym.tests.Test()._modular_symbols_space_gamma1() # random
159
level = 3, weight = 4, sign = 0
160
Modular Symbols space of dimension 2 for Gamma_1(3) of weight 4 with sign 0 and over Rational Field
161
"""
162
level, weight, sign = self._level_weight_sign()
163
M = modsym.ModularSymbols(arithgroup.Gamma1(level), weight, sign)
164
self.current_space = M
165
return M
166
167
def _modular_symbols_space_character(self):
168
"""
169
Return a random space of modular symbols for Gamma1, with
170
(possibly trivial) character, random sign, and weight a
171
random choice from self.weights.
172
173
EXAMPLES:
174
sage: sage.modular.modsym.tests.Test()._modular_symbols_space_character() # random
175
level = 18, weight = 3, sign = 0
176
Modular Symbols space of dimension 0 and level 18, weight 3, character [1, zeta6 - 1], sign 0, over Cyclotomic Field of order 6 and degree 2
177
"""
178
level, weight, sign = self._level_weight_sign()
179
G = dirichlet.DirichletGroup(level)
180
eps = G.random_element()
181
M = modsym.ModularSymbols(eps, weight, sign)
182
self.current_space = M
183
return M
184
185
def _do(self, name):
186
"""
187
Perform the test 'test_name', where name is specified as an
188
argument. This function exists to avoid a call to eval.
189
190
EXAMPLES:
191
sage: sage.modular.modsym.tests.Test()._do("random")
192
test_random
193
...
194
"""
195
print "test_%s"%name
196
Test.__dict__["test_%s"%name](self)
197
198
#################################################################
199
# The tests
200
#################################################################
201
def random(self, seconds=0):
202
"""
203
Perform random tests for a given number of seconds, or
204
indefinitely if seconds is not specified.
205
206
EXAMPLES:
207
sage: sage.modular.modsym.tests.Test().random(1)
208
test_random
209
...
210
"""
211
self.test("random", seconds)
212
213
def test(self, name, seconds=0):
214
"""
215
Repeatedly run 'test_name', where name is passed as an
216
argument. If seconds is nonzero, run for that many seconds. If
217
seconds is 0, run indefinitely.
218
219
EXAMPLES:
220
sage: sage.modular.modsym.tests.Test().test('cs_dimension',seconds=1)
221
test_cs_dimension
222
...
223
sage: sage.modular.modsym.tests.Test().test('csnew_dimension',seconds=1)
224
test_csnew_dimension
225
...
226
"""
227
seconds = float(seconds)
228
total = cputime()
229
n = 1
230
while seconds == 0 or cputime(total) < seconds:
231
s = "** test_dimension: number %s"%n
232
if seconds > 0:
233
s += " (will stop after about %s seconds)"%seconds
234
t = cputime()
235
self._do(name)
236
print "\ttime=%s\telapsed=%s"%(cputime(t),cputime(total))
237
n += 1
238
239
def test_cs_dimension(self):
240
"""
241
Compute the cuspidal subspace (this implicitly checks that the
242
dimension is correct using formulas).
243
244
EXAMPLES:
245
sage: sage.modular.modsym.tests.Test().test_cs_dimension() # random
246
gamma0
247
level = 16, weight = 3, sign = -1
248
Modular Symbols space of dimension 0 for Gamma_0(16) of weight 3 with sign -1 over Rational Field
249
"""
250
self._modular_symbols_space().cuspidal_submodule()
251
252
def test_csnew_dimension(self):
253
"""
254
Compute the new cuspidal subspace and verify that the
255
dimension is correct using a dimension formula.
256
257
EXAMPLES:
258
sage: sage.modular.modsym.tests.Test().test_csnew_dimension() # random
259
gamma0
260
level = 3, weight = 3, sign = 1
261
Modular Symbols space of dimension 0 for Gamma_0(3) of weight 3 with sign 1 over Rational Field
262
"""
263
M = self._modular_symbols_space()
264
V = M.cuspidal_submodule().new_submodule()
265
d = V.dimension()
266
d2 = M._cuspidal_new_submodule_dimension_formula()
267
if d != d2:
268
assert False, "Test failed for M=\"%s\", where computed dimension is %s but formula dimension is %s."%(M, d, d2)
269
270
def test_csns_nscs(self):
271
"""
272
Compute new cuspidal subspace in two ways and verify that the
273
results are the same.
274
275
EXAMPLES:
276
sage: sage.modular.modsym.tests.Test().test_csns_nscs() # random
277
gamma0
278
level = 5, weight = 4, sign = 1
279
Modular Symbols space of dimension 3 for Gamma_0(5) of weight 4 with sign 1 over Rational Field
280
"""
281
M = self._modular_symbols_space()
282
V1 = M.cuspidal_submodule().new_submodule()
283
V2 = M.new_submodule().cuspidal_submodule()
284
assert V1 == V2, "Test failed for M=\"%s\", where the new cuspidal and cuspidal new spaces are computed differently."%M
285
d = M._cuspidal_new_submodule_dimension_formula()
286
if d != V1.dimension():
287
assert False, "Test failed for M=\"%s\", where computed dimension is %s but formula dimension is %s."%(
288
M, V1.dimension(), d)
289
290
291
def test_decomposition(self):
292
"""
293
Compute the decomposition of a modular symbols space, and
294
verify that the sum of the dimensions of its components equals
295
the dimension of the original space.
296
297
EXAMPLES:
298
sage: sage.modular.modsym.tests.Test().test_decomposition() # random
299
gamma1
300
level = 10, weight = 4, sign = 0
301
Modular Symbols space of dimension 18 for Gamma_1(10) of weight 4 with sign 0 and over Rational Field
302
"""
303
M = self._modular_symbols_space()
304
D = M.decomposition()
305
assert M.dimension() == sum([A.dimension() for A in D])
306
307
def test_dimension(self):
308
"""
309
Compute the dimension of a modular symbols space.
310
311
EXAMPLES:
312
sage: sage.modular.modsym.tests.Test().test_dimension() # random
313
gamma1
314
level = 14, weight = 2, sign = -1
315
Modular Symbols space of dimension 1 for Gamma_1(14) of weight 2 with sign -1 and over Rational Field
316
"""
317
self._modular_symbols_space().dimension()
318
319
def test_random(self):
320
"""
321
Do a random test from all the possible tests.
322
323
EXAMPLES:
324
sage: sage.modular.modsym.tests.Test().test_random() # random
325
Doing random test test_csnew_dimension
326
character
327
level = 18, weight = 4, sign = -1
328
Modular Symbols space of dimension 0 and level 18, weight 4, character [1, -1], sign -1, over Rational Field
329
"""
330
tests = [a for a in Test.__dict__.keys() if a[:5] == "test_" and a != "test_random"]
331
name = random.choice(tests)
332
print "Doing random test %s"%name
333
Test.__dict__[name](self)
334
335
336