Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241852 views
1
#################################################################################
2
#
3
# (c) Copyright 2010 William Stein
4
#
5
# This file is part of PSAGE
6
#
7
# PSAGE is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# PSAGE 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
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#
20
#################################################################################
21
22
_multiprocess_can_split_ = True
23
24
import random
25
from sage.all import set_random_seed, primes
26
from sqrt5 import *
27
from sqrt5_fast import *
28
29
def prime_powers(B=100, emax=5):
30
for p in primes(B+1):
31
for P in F.primes_above(p):
32
for e in range(1,emax+1):
33
yield p, P, e
34
35
################################################################
36
# Tests of Residue Rings
37
################################################################
38
39
def residue_rings(B=100, emax=5):
40
for p, P, e in prime_powers(B, emax):
41
yield ResidueRing(P, e)
42
43
def residue_ring_creation(B=100, emax=5):
44
alpha = -F.gen() - 3
45
for R in residue_rings(B, emax):
46
R.residue_field()
47
R._moduli()
48
zero = R(0); one = R(1)
49
assert R(alpha) - R(alpha) == zero
50
assert one - one == zero
51
str(R)
52
assert R[0] == zero
53
assert R[1] == one
54
55
def test_residue_ring_1():
56
residue_ring_creation(B=100, emax=4)
57
58
def test_residue_ring_2():
59
residue_ring_creation(B=35, emax=6)
60
61
def test_residue_ring_3():
62
residue_ring_creation(B=200, emax=2)
63
64
def residue_ring_arith(P, e, n=None):
65
"""
66
Test that arithmetic in the residue field is correct.
67
"""
68
set_random_seed(0)
69
R = ResidueRing(P, e)
70
n0, n1 = R._moduli()
71
alpha = F.gen()
72
reps = [i+j*alpha for i in range(n0) for j in range(n1)]
73
if n is not None:
74
reps = [reps[random.randrange(len(reps))] for i in range(n)]
75
reps_mod = [R(a) for a in reps]
76
for i in range(len(reps)):
77
for j in range(len(reps)):
78
assert reps_mod[i] * reps_mod[j] == R(reps[i] * reps[j])
79
assert reps_mod[i] + reps_mod[j] == R(reps[i] + reps[j])
80
assert reps_mod[i] - reps_mod[j] == R(reps[i] - reps[j])
81
82
def test_residue_ring_arith2():
83
for i in range(1,4):
84
residue_ring_arith(F.primes_above(2)[0], i)
85
86
def test_residue_ring_arith3():
87
for i in range(1,4):
88
residue_ring_arith(F.primes_above(2)[0], i, 50)
89
90
def test_residue_ring_arith5():
91
for i in range(1,4):
92
residue_ring_arith(F.primes_above(5)[0], i, 50)
93
94
def test_residue_ring_arith11():
95
for i in range(1,4):
96
residue_ring_arith(F.primes_above(11)[0], i, 50)
97
residue_ring_arith(F.primes_above(11)[1], i, 50)
98
99
################################################################
100
# Testing pow function on elements
101
################################################################
102
def test_pow():
103
def f(B,e):
104
for R in residue_rings(B,e):
105
for a in R:
106
b = a*a
107
for i in range(4):
108
assert b == a**(i+2)
109
if a.is_unit():
110
assert ~b == a**(-(i+2))
111
b *= a
112
f(100,1)
113
f(11,3)
114
115
################################################################
116
# Testing is_square in case of degree 1
117
################################################################
118
def is_square_0(B=11, emax=2):
119
for R in residue_rings(B, emax):
120
assert set([x*x for x in R]) == set([x for x in R if x.is_square()])
121
122
def test_is_square_0():
123
is_square_0(20,2)
124
is_square_0(12,3)
125
126
def test_is_square_2(emax=6):
127
for R in residue_rings(2, emax):
128
assert set([x*x for x in R]) == set([x for x in R if x.is_square()])
129
130
def test_is_square_5(emax=5):
131
P = F.primes_above(5)[0]
132
for e in range(1,emax+1):
133
R = ResidueRing(P, e)
134
assert set([x*x for x in R]) == set([x for x in R if x.is_square()])
135
136
################################################################
137
# Testing sqrt function on elements
138
################################################################
139
def test_sqrt1(B=11,emax=2):
140
for R in residue_rings(B,emax):
141
for a in R:
142
b = a*a
143
assert b.is_square()
144
assert b.sqrt()**2 == b
145
146
def test_sqrt2(B=11,emax=2):
147
for R in residue_rings(B,emax):
148
for a in R:
149
if a.is_square():
150
assert a.sqrt()**2 == a
151
152
def test_sqrt5(emax=4):
153
P = F.primes_above(5)[0]
154
for e in range(1,emax+1):
155
for a in ResidueRing(P, e):
156
if a.is_square():
157
assert a.sqrt()**2 == a
158
159
def test_sqrt5b(emax=4):
160
P = F.primes_above(5)[0]
161
for e in range(1,emax+1):
162
if e % 2: continue
163
for a in ResidueRing(P,e):
164
b = a*a
165
assert b.is_square()
166
assert b.sqrt()**2 == b
167
168
169
################################################################
170
# Test computing local splitting map
171
################################################################
172
173
174
def test_local_splitting_maps(B=11,e=3, verbose=True):
175
ans = []
176
for p, P, e in prime_powers(B,e):
177
print p, P, e
178
r = ModN_Reduction(P**e)
179
180
def test_local_splitting_maps_1():
181
test_local_splitting_maps(100,2)
182
183
def test_local_splitting_maps_2():
184
test_local_splitting_maps(11,5)
185
186
################################################################
187
# Test computing R^* \ P^1
188
################################################################
189
190
191
def test_icosians_mod_p1(B=11, e=3):
192
for p, P, e in prime_powers(B,e):
193
H = IcosiansModP1ModN(P**e)
194
195
196
################################################################
197
# Testing mod_long functions
198
################################################################
199
200
def test_sqrtmod_long_2(e_max=15):
201
for e in range(1, e_max+1):
202
R = Integers(2**e)
203
X = set([a*a for a in R])
204
for b in X:
205
c = sqrtmod_long(int(b), 2, e)
206
assert c*c == b
207
208
209
210
################################################################
211
# Test Hecke operators commute
212
################################################################
213
214
def test_hecke_commutes(Bmin=2, Bmax=50):
215
from tables import ideals_of_bounded_norm
216
from hmf import HilbertModularForms, next_prime_of_characteristic_coprime_to
217
for N in ideals_of_bounded_norm(Bmax):
218
if N.norm() < Bmin: continue
219
print N.norm()
220
H = HilbertModularForms(N)
221
p = next_prime_of_characteristic_coprime_to(F.ideal(1), N)
222
q = next_prime_of_characteristic_coprime_to(p, N)
223
print p, q
224
T_p = H.T(p)
225
T_q = H.T(q)
226
assert T_p*T_q == T_q*T_p, "Hecke operators T_{%s} and T_{%s} at level %s (of norm %s) don't commute"%(p, q, N, N.norm())
227
228
229
230
231
################################################################
232
# New subspaces
233
################################################################
234
235
## def test_compute_new_subspace(Bmin=2, Bmax=200, try_hecke=False):
236
## from tables import ideals_of_bounded_norm
237
## from hmf import HilbertModularForms, next_prime_of_characteristic_coprime_to
238
## for N in ideals_of_bounded_norm(Bmax):
239
## if N.norm() < Bmin: continue
240
## print N.norm()
241
## H = HilbertModularForms(N)
242
## NS = H.new_subspace()
243
## if try_hecke:
244
## p = next_prime_of_characteristic_coprime_to(F.ideal(1), N)
245
## NS.hecke_matrix(p)
246
247
248
def test_hecke_invariance_of_new_subspace(Bmin=2, Bmax=300):
249
from tables import ideals_of_bounded_norm
250
from hmf import HilbertModularForms, next_prime_of_characteristic_coprime_to
251
for N in ideals_of_bounded_norm(Bmax):
252
if N.norm() < Bmin: continue
253
print N.norm()
254
H = HilbertModularForms(N)
255
NS = H.new_subspace()
256
p = next_prime_of_characteristic_coprime_to(F.ideal(1), N)
257
q = next_prime_of_characteristic_coprime_to(p, N)
258
print p, q
259
T_p = NS.T(p)
260
T_q = NS.T(q)
261
assert T_p*T_q == T_q*T_p, "Hecke operators T_{%s} and T_{%s} at level %s (of norm %s) don't commute"%(p, q, N, N.norm())
262
263
264