Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/classical_modular_forms/compare_hecke_cc_data.py
1448 views
1
2
import sys, os
3
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),"../.."))
4
from lmfdb.db_backend import db
5
from sage.all import RR, prime_range
6
7
filename = '/scratch/importing/mf_dim20_hecke_cc_3000.txt'
8
filename = '/scratch/importing/mf_dim20_hecke_cc_3001_4000.txt'
9
num_lines = sum(1 for line in open(filename))
10
cols_header = 'hecke_orbit_code:lfunction_label:conrey_label:embedding_index:embedding_m:embedding_root_real:embedding_root_imag:an:first_an:angles:first_angles'
11
cols = cols_header.split(':')
12
del cols[10]
13
del cols[8]
14
maxNk2 = db.mf_newforms.max('Nk2')
15
# we store a_n with n \in [1, an_storage_bound]
16
an_storage_bound = 1000
17
# we store alpha_p with p <= an_storage_bound
18
primes_for_angles = prime_range(an_storage_bound)
19
20
if len(sys.argv) == 3:
21
M = int(sys.argv[1])
22
C = int(sys.argv[2])
23
assert M > C
24
else:
25
print(r"""Usage:
26
You should run this on legendre as: (this will use 40 cores):
27
# parallel -u -j 40 --halt 2 --progress sage -python %s 40 ::: {0..39}""" % sys.argv[0])
28
29
30
def compare_floats(a, b, prec = 52):
31
if a == b:
32
return True
33
if None in [a,b]:
34
return False
35
if b == 0:
36
b, a = a, b
37
if a == 0:
38
return b == 0 or abs(b) < 1e-60
39
else:
40
return RR(abs((a - b)/a)).log(2) < -prec
41
def compare_row(a, b, verbose = True):
42
for i,c in enumerate(cols):
43
if c in ['hecke_orbit_code', 'conrey_label','embedding_index','embedding_m']:
44
if a[i] != b[i]:
45
print(c, a[i], b[i])
46
return False
47
elif c in ['embedding_root_real', 'embedding_root_imag']:
48
if not compare_floats(a[i], b[i]):
49
print(c, a[i], b[i], a[i] - b[i])
50
return False
51
elif c == 'an':
52
for j, ((ax, ay), (bx, by)) in enumerate(zip(a[i],b[i])):
53
if not compare_floats(ax, bx):
54
print(c, j, ax, bx, ax-bx)
55
if ax != 0:
56
print(RR(abs((ax - bx)/ax)).log(2))
57
return False
58
if not compare_floats(ay, by):
59
print(c, j, ay, by, ay-by)
60
if ay != 0:
61
print(RR(abs((ay - by)/ay)).log(2))
62
return False
63
elif c == 'angles':
64
for j, (at, bt) in enumerate(zip(a[i],b[i])):
65
if not compare_floats(at, bt):
66
print(c, j, at, bt)
67
if None not in [at,bt]:
68
print(at - bt)
69
if at !=0:
70
print(RR(abs((at - bt)/at)).log(2))
71
return False
72
return True
73
74
75
with open(filename, 'r') as F:
76
linenumber = -1
77
for line in F:
78
linenumber += 1
79
if linenumber < 3:
80
if linenumber == 0:
81
assert line[:-1] == cols_header
82
elif linenumber % M == C:
83
linesplit = line[:-1].split(':')
84
del linesplit[10]
85
del linesplit[8]
86
N, k = map(int, linesplit[1].split('.')[:2])
87
#if N*k**2 > maxNk2:
88
# continue
89
for i, c in enumerate(cols):
90
if c in ['hecke_orbit_code', 'conrey_label','embedding_index','embedding_m']:
91
linesplit[i] = int(linesplit[i])
92
elif c in ['embedding_root_real', 'embedding_root_imag']:
93
linesplit[i] =float(linesplit[i])
94
elif c == 'an':
95
linesplit[i] = [[float(x), float(y)] for x, y in eval(linesplit[i])]
96
elif c == 'angles':
97
angles_dict = dict([(int(x), float(y)) for x, y in eval(linesplit[i])])
98
linesplit[i] = [ angles_dict.get(p) for p in primes_for_angles ]
99
# fix trivial character
100
if linesplit[2] == 0:
101
linesplit[2] = 1
102
lfun_label = linesplit[1].split('.')
103
lfun_label[-2] = str(1)
104
linesplit[1] = '.'.join(lfun_label)
105
hc = db.mf_hecke_cc.lucky({'hecke_orbit_code': linesplit[0], 'lfunction_label' : linesplit[1]})
106
if hc is None:
107
print({'hecke_orbit_code': linesplit[0], 'lfunction_label' : linesplit[1]})
108
assert False
109
for c in ['an']:
110
hc[c] = [[float(x), float(y)] for x, y in hc[c]]
111
112
if 'embedding_root_real' not in hc.keys(): #FIXME
113
hc['embedding_root_imag'] = 0
114
hc['embedding_root_real'] = 0
115
if sorted(hc.keys()) != sorted(cols):
116
print({'hecke_orbit_code': linesplit[0], 'lfunction_label' : linesplit[1]})
117
print(sorted(hc.keys()))
118
print(sorted(cols))
119
assert False
120
hc_list = [ hc[c] for c in cols]
121
if not compare_row(hc_list, linesplit):
122
print({'hecke_orbit_code': linesplit[0], 'lfunction_label' : linesplit[1]})
123
print(hc_list[-1][:10])
124
print(linesplit[-1][:10])
125
assert False
126
127
if (linenumber - C)/M % int(float(num_lines)/(10*M)) == 0:
128
print('%.2f %%' % (100*linenumber/float(num_lines)))
129
130
131
132
133