-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsiegel.sage
382 lines (325 loc) · 11.5 KB
/
siegel.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
import json
import re
from collections import defaultdict
from tqdm import tqdm
from functools import partial
from collections.abc import Iterable
import numpy as np
import multiprocessing as mp
from itertools import product
from scipy.interpolate import approximate_taylor_polynomial
load("boxes.sage")
load("legendre_reduction.sage")
def read_coefficients(file):
with open(file) as json_file:
data = json.load(json_file)
coefficients = defaultdict(list)
for determinant, values in data["Fourier_coefficients"].items():
determinant = int(determinant)
for matrix_str, coefficient in values.items():
parsed = re.search(r'\((-?\d+), (-?\d+), (-?\d+)\)', matrix_str)
n, r, Nm = int(parsed.group(3)), int(parsed.group(2)), int(parsed.group(1))
coefficients[determinant].append([
tuple2matrix((Nm, r, n)), QQ(coefficient)
])
return coefficients
def specialization_q_expansion(f, N, s, t=matrix.zero(2), m=0, max_n=20, boxes=None, warnings=True):
q_expansion = defaultdict(int)
try:
den = max(1, t.denominator())
except:
den = 1
if m == 0:
FF = CyclotomicField(den) if den > 1 else QQ
else:
F = CyclotomicField(den) if den > 1 else QQ
FF = F.residue_field(m) if F == QQ else F.residue_field(F.prime_above(m))
S.<q> = PuiseuxSeriesRing(FF, sparse=True)
q_expansion = S(0)
if boxes is None:
boxes = list(S_box(N,s,max_n,0))
# print(boxes)
for detT, T in boxes:
e = (s * T).trace()
T_legendre, _, v = legendre_reduce(T, N)
if e <= max_n:
found_flag = False
for U, aT in f[detT]:
U_legendre, _, w = legendre_reduce(U, N)
"""if U_legendre == T_legendre:
print(U_legendre)
print(U)
print(T)
print(v,w)"""
if U_legendre == T_legendre and aut_T_equivalent(U_legendre, v, w):
found_flag = True
Tt = (T * t).trace()
if aT.parent().characteristic() != 0:
q_expansion += FF(exp(2*pi*I*Tt) * aT.lift()) * q^e
else:
q_expansion += FF(exp(2*pi*I*Tt) * aT) * q^e
break
if not found_flag:
print(f"Warning - might be missing for trace {e}: T = {(T[1][1],2*T[1][0],T[0][0])}, det(T) = {detT}")
# if e.is_integer():
# raise
return q_expansion.add_bigoh(max_n+1)
def Hecke_Tp_q(f, s, p, N=277, max_n=20, warnings=None):
a, b, c = s[0][0], s[0][1], s[1][1]*N
try:
G = p*s
Tpf = p * specialization_q_expansion(f, N, G, max_n=max_n)
G = Matrix([[a/p, b], [b,p*c/N]])
if a % p != 0:
f_i = specialization_q_expansion(f, N,
G,
max_n=max_n, warnings=warnings)
Tpf += f_i
else:
G_box = list(S_box(N, G, max_n, 0))
for i in range(p):
f_i = specialization_q_expansion(f, N,
G,
t=Matrix([[i/p,0],[0,0]]),
max_n=max_n,
boxes=G_box)
Tpf += f_i / p
##########################
for i in range(p):
G = Matrix([[p*a, b+i*a], [b+i*a, (c/N + 2*i*b + i^2*a)/p]])
G_box = list(S_box(N, G, max_n, 0))
if (c + 2*i*b*N + i^2*a*N) % p != 0:
f_i = specialization_q_expansion(f, N,
G,
max_n=max_n,
boxes=G_box)
Tpf += f_i
else:
for j in range(p):
f_ij = specialization_q_expansion(f, N,
G,
t=Matrix([[0,0],[0,j/p]]),
max_n=max_n,
boxes=G_box)
Tpf += f_ij / p
###########################
G = s/p
G_box = list(S_box(N, G, max_n, 0))
if a % p != 0:
for j in range(p):
for k in range(p):
f_jk = specialization_q_expansion(f, N,
G,
t=Matrix([[0,j/p],[j/p,k/p]]),
max_n=max_n,
boxes=G_box)
Tpf += f_jk / p^2
elif b % p != 0:
for i in range(p):
for k in range(p):
f_ik = specialization_q_expansion(f, N,
G,
t=Matrix([[i/p,0],[0,k/p]]),
max_n=max_n,
boxes=G_box)
Tpf += f_ik / p^2
elif c % p != 0:
for i in range(p):
for j in range(p):
f_ij = specialization_q_expansion(f, N,
G,
t=Matrix([[i/p,j/p],[j/p,0]]),
max_n=max_n,
boxes=G_box)
Tpf += f_ij / p^2
else:
print(f"Worst. case. ever. ({p})")
for i in range(p):
for j in range(p):
for k in range(p):
f_ijk = specialization_q_expansion(f, N,
G,
Matrix([[i/p,j/p],[j/p,k/p]]),
max_n=max_n,
boxes=G_box)
Tpf += f_ijk / p^3
return Tpf
except:
print(f"Error: some Fourier coefficient is missing for T({p}). Try computing some more.")
return specialization_q_expansion(f, N, s, max_n=max_n)
def Hecke_Tp_q_GritQ(Grits, f_G, s, p, m=0, N=277, max_n=20, warnings=None):
a, b, c = s[0][0], s[0][1], s[1][1]*N
G = p*s
Grit_ps = [
specialization_q_expansion(f, N,
G, m=m,
max_n=max_n, warnings=warnings)
for f in Grits
]
Tpf = p * f_G(Grit_ps)
G = matrix(QQ, [[a/p, b], [b,p*c/N]])
if a % p != 0:
Grit_i = [
specialization_q_expansion(f, N,
G, m=m,
max_n=max_n, warnings=warnings)
for f in Grits
]
Tpf += f_G(Grit_i)
else:
G_box = list(S_box(N, G, max_n, 0))
for i in range(p):
Grit_i = [
specialization_q_expansion(f, N,
G, m=m,
t=matrix(QQ, [[i/p,0],[0,0]]),
max_n=max_n,
boxes=G_box)
for f in Grits
]
Tpf += f_G(Grit_i) / p
##########################
for i in range(p):
G = matrix(QQ, [[p*a, b+i*a], [b+i*a, (c/N + 2*i*b + i^2*a)/p]])
G_box = list(S_box(N, G, max_n, 0))
if (c + 2*i*b*N + i^2*a*N) % p != 0:
Grit_i = [
specialization_q_expansion(f, N,
G, m=m,
max_n=max_n,
boxes=G_box)
for f in Grits
]
Tpf += f_G(Grit_i)
else:
for j in range(p):
Grit_ij = [
specialization_q_expansion(f, N,
G, m=m,
t=matrix(QQ, [[0,0],[0,j/p]]),
max_n=max_n,
boxes=G_box)
for f in Grits
]
Tpf += f_G(Grit_ij) / p
###########################
G = s/p
G_box = list(S_box(N, G, max_n, 0))
if a % p != 0:
for j in range(p):
for k in range(p):
Grit_jk = [
specialization_q_expansion(f, N,
G, m=m,
t=matrix(QQ, [[0,j/p],[j/p,k/p]]),
max_n=max_n,
boxes=G_box)
for f in Grits
]
Tpf += f_G(Grit_jk) / p^2
elif b % p != 0:
for i in range(p):
for k in range(p):
Grit_ik = [
specialization_q_expansion(f, N,
G, m=m,
t=matrix(QQ, [[i/p,0],[0,k/p]]),
max_n=max_n,
boxes=G_box)
for f in Grits
]
Tpf += f_G(Grit_ik) / p^2
elif c % p != 0:
for i in range(p):
for j in range(p):
Grit_ij = [
specialization_q_expansion(f, N,
G, m=m,
t=matrix(QQ, [[i/p,j/p],[j/p,0]]),
max_n=max_n,
boxes=G_box)
for f in Grits
]
Tpf += f_G(Grit_ij) / p^2
else:
print(f"Worst. case. ever. ({p})")
for i in range(p):
for j in range(p):
for k in range(p):
Grit_ijk = [
specialization_q_expansion(f, N,
G, m=m,
t=matrix(QQ, [[i/p,j/p],[j/p,k/p]]),
max_n=max_n,
boxes=G_box)
for f in Grits
]
Tpf += f_G(Grit_ijk) / p^3
return Tpf
def Hecke_Tp_box(s, p, N=277, max_n=3):
a, b, c = s[0][0], s[0][1], s[1][1]*N
box = list()
G = p*s
box += (list(S_box(N, G, max_n, 0)))
G = Matrix([[a/p, b], [b,p*c/N]])
box += (list(S_box(N, G, max_n, 0)))
for i in range(p):
G = Matrix([[p*a, b+i*a], [b+i*a, (c/N + 2*i*b + i^2*a)/p]])
box += (list(S_box(N, G, max_n, 0)))
G = s/p
box += (list(S_box(N, G, max_n, 0)))
reduced_box = []
R = Matrix([[0,1],[1,0]])
for detT, T in box:
reduced_T, _, v = legendre_reduce(T, N=N)
if v[0] != 0:
u = v * mod(1/v[0], N)
u = vector([Integer(u[0]),Integer(u[1])])
U = Matrix([[u[0],0],[u[1],1]])
else:
u = v * mod(1/v[1], N)
u = Integer(u)
U = Matrix([[u[0],-1],[u[1],1]])
reduced_box.append(
[detT, R.T * U.T * reduced_T * U * R]
)
return reduced_box
def Hecke_Tp(f, p):
Tpf = defaultdict(list)
for determinant in f.keys():
for T, _ in f[determinant]:
a_T = 0
if p^2 * determinant in f:
for M, coefficient in f[p^2 * determinant]:
if M == p*T:
a_T += coefficient
break
if determinant / p^2 in f:
for M, coefficient in f[determinant / p^2]:
if M == (1/p) * T:
# p^{2k - 3} = p (k=2)
a_T += p * coefficient
break
for j in range(p):
u = Matrix([[1,0], [j, p]])
uTu = u.T * T * u / p
for M, coefficient in f[determinant]:
if M == uTu:
a_T += coefficient
break
u = Matrix([[p,0], [0, 1]])
uTu = u * T * u / p
for M, coefficient in f[determinant]:
if M == uTu:
a_T += coefficient
break
if a_T != 0:
Tpf[determinant].append([T, a_T])
return Tpf
def tuple2matrix(T):
return Matrix([
[T[2], T[1]/2],
[T[1]/2, T[0]]
])
def matrix2tuple(T):
return (T[1][1], 2*T[0][1], T[0][0])