Path: blob/main/scripts/classical_modular_forms/compare_hecke_cc_data.py
1448 views
1import sys, os2sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),"../.."))3from lmfdb.db_backend import db4from sage.all import RR, prime_range56filename = '/scratch/importing/mf_dim20_hecke_cc_3000.txt'7filename = '/scratch/importing/mf_dim20_hecke_cc_3001_4000.txt'8num_lines = sum(1 for line in open(filename))9cols_header = 'hecke_orbit_code:lfunction_label:conrey_label:embedding_index:embedding_m:embedding_root_real:embedding_root_imag:an:first_an:angles:first_angles'10cols = cols_header.split(':')11del cols[10]12del cols[8]13maxNk2 = db.mf_newforms.max('Nk2')14# we store a_n with n \in [1, an_storage_bound]15an_storage_bound = 100016# we store alpha_p with p <= an_storage_bound17primes_for_angles = prime_range(an_storage_bound)1819if len(sys.argv) == 3:20M = int(sys.argv[1])21C = int(sys.argv[2])22assert M > C23else:24print(r"""Usage:25You should run this on legendre as: (this will use 40 cores):26# parallel -u -j 40 --halt 2 --progress sage -python %s 40 ::: {0..39}""" % sys.argv[0])272829def compare_floats(a, b, prec = 52):30if a == b:31return True32if None in [a,b]:33return False34if b == 0:35b, a = a, b36if a == 0:37return b == 0 or abs(b) < 1e-6038else:39return RR(abs((a - b)/a)).log(2) < -prec40def compare_row(a, b, verbose = True):41for i,c in enumerate(cols):42if c in ['hecke_orbit_code', 'conrey_label','embedding_index','embedding_m']:43if a[i] != b[i]:44print(c, a[i], b[i])45return False46elif c in ['embedding_root_real', 'embedding_root_imag']:47if not compare_floats(a[i], b[i]):48print(c, a[i], b[i], a[i] - b[i])49return False50elif c == 'an':51for j, ((ax, ay), (bx, by)) in enumerate(zip(a[i],b[i])):52if not compare_floats(ax, bx):53print(c, j, ax, bx, ax-bx)54if ax != 0:55print(RR(abs((ax - bx)/ax)).log(2))56return False57if not compare_floats(ay, by):58print(c, j, ay, by, ay-by)59if ay != 0:60print(RR(abs((ay - by)/ay)).log(2))61return False62elif c == 'angles':63for j, (at, bt) in enumerate(zip(a[i],b[i])):64if not compare_floats(at, bt):65print(c, j, at, bt)66if None not in [at,bt]:67print(at - bt)68if at !=0:69print(RR(abs((at - bt)/at)).log(2))70return False71return True727374with open(filename, 'r') as F:75linenumber = -176for line in F:77linenumber += 178if linenumber < 3:79if linenumber == 0:80assert line[:-1] == cols_header81elif linenumber % M == C:82linesplit = line[:-1].split(':')83del linesplit[10]84del linesplit[8]85N, k = map(int, linesplit[1].split('.')[:2])86#if N*k**2 > maxNk2:87# continue88for i, c in enumerate(cols):89if c in ['hecke_orbit_code', 'conrey_label','embedding_index','embedding_m']:90linesplit[i] = int(linesplit[i])91elif c in ['embedding_root_real', 'embedding_root_imag']:92linesplit[i] =float(linesplit[i])93elif c == 'an':94linesplit[i] = [[float(x), float(y)] for x, y in eval(linesplit[i])]95elif c == 'angles':96angles_dict = dict([(int(x), float(y)) for x, y in eval(linesplit[i])])97linesplit[i] = [ angles_dict.get(p) for p in primes_for_angles ]98# fix trivial character99if linesplit[2] == 0:100linesplit[2] = 1101lfun_label = linesplit[1].split('.')102lfun_label[-2] = str(1)103linesplit[1] = '.'.join(lfun_label)104hc = db.mf_hecke_cc.lucky({'hecke_orbit_code': linesplit[0], 'lfunction_label' : linesplit[1]})105if hc is None:106print({'hecke_orbit_code': linesplit[0], 'lfunction_label' : linesplit[1]})107assert False108for c in ['an']:109hc[c] = [[float(x), float(y)] for x, y in hc[c]]110111if 'embedding_root_real' not in hc.keys(): #FIXME112hc['embedding_root_imag'] = 0113hc['embedding_root_real'] = 0114if sorted(hc.keys()) != sorted(cols):115print({'hecke_orbit_code': linesplit[0], 'lfunction_label' : linesplit[1]})116print(sorted(hc.keys()))117print(sorted(cols))118assert False119hc_list = [ hc[c] for c in cols]120if not compare_row(hc_list, linesplit):121print({'hecke_orbit_code': linesplit[0], 'lfunction_label' : linesplit[1]})122print(hc_list[-1][:10])123print(linesplit[-1][:10])124assert False125126if (linenumber - C)/M % int(float(num_lines)/(10*M)) == 0:127print('%.2f %%' % (100*linenumber/float(num_lines)))128129130131132133