def add_narrow_classno_data(): # Adds narrow class number data to all fields for F in hmf_fields.find(): Fcoeff = fields.find_one({'label' : F['label']})['coeffs'] magma.eval('F<w> := NumberField(Polynomial([' + str(Fcoeff) + ']));') hplus = magma.eval('NarrowClassNumber(F);') hmf_fields.update({ '_id': F['_id'] }, { "$set": {'narrow_class_no': int(hplus)} }) print Fcoeff, hplus
def find_Galois_squarefull_forms(): forms_labels = [] for F in hmf_fields.find(): Fcoeff = fields.find_one({'label' : F['label']})['coeffs'] magma.eval('F<w> := NumberField(Polynomial([' + str(Fcoeff) + ']));') if magma('IsNormal(F) and Degree(F) mod 2 eq 1;'): magma.eval('ZF := Integers(F);') for f in hmf_forms.find({'field_label' : F['label']}): magma.eval('NN := ideal<ZF | SequenceToSet(' + f['level_ideal'] + ')>;'); if magma('Min([2] cat [ff[2] : ff in Factorization(NN)]) ge 2;'): forms_labels.append(f['label']) print(f['label']) return forms_labels
def find_Galois_squarefull_forms(): forms_labels = [] for F in hmf_fields.find(): Fcoeff = fields.find_one({'label' : F['label']})['coeffs'] magma.eval('F<w> := NumberField(Polynomial([' + str(Fcoeff) + ']));') if magma('IsNormal(F) and Degree(F) mod 2 eq 1;'): magma.eval('ZF := Integers(F);') for f in hmf_forms.find({'field_label' : F['label']}): magma.eval('NN := ideal<ZF | SequenceToSet(' + f['level_ideal'] + ')>;'); if magma('Min([2] cat [ff[2] : ff in Factorization(NN)]) ge 2;'): forms_labels.append(f['label']) print f['label'] return forms_labels
def compare(log2N, t, use_c=False, vssage=True, vsmagma=True, **kwds): r""" e.g: compare(15, 1337, vssage=False, cyclotomic=([4,4,2,2], [3,3,3])) """ import resource def get_utime(): return resource.getrusage(resource.RUSAGE_SELF).ru_utime for i in range(10, log2N + 1): print("2^%s" % i) H = AmortizingHypergeometricData(2**i, **kwds) start = get_utime() foo = H.amortized_padic_H_values(t, use_c=use_c) print("Amortized: %.2f s" % (get_utime() - start)) #print_maxrss() if vssage: start = get_utime() bar = {p: H.padic_H_value(p=p, f=1, t=t, prec=1) % p for p in foo} print("Sage: %.2f s" % (get_utime() - start)) H._gauss_table = {} H.padic_H_value.clear_cache() #print_maxrss() assert foo == bar if vsmagma: magma.quit() magma.eval('ps := %s;' % sorted(foo)) magma.eval('H := HypergeometricData(%s, %s);' % H.alpha_beta()) z = 1 / t start_magma = magma.Cputime() magma.eval('foo := [HypergeometricTrace(H, %s, p) : p in ps];' % z) print("Magma: %.2f s" % (magma.Cputime(start_magma))) bar = dict((p, k % p) for p, k in zip(sorted(foo), eval(magma.eval('foo;')))) assert foo == bar print("")
def import_data(hmf_filename): hmff = file(hmf_filename) ferrors = file('/home/jvoight/lmfdb/backups/import_data.err', 'a') # Parse field data v = hmff.readline() assert v[:9] == 'COEFFS :=' coeffs = eval(v[10:][:-2]) v = hmff.readline() assert v[:4] == 'n :=' n = int(v[4:][:-2]) v = hmff.readline() assert v[:4] == 'd :=' d = int(v[4:][:-2]) magma.eval('F<w> := NumberField(Polynomial(' + str(coeffs) + '));') magma.eval('ZF := Integers(F);') # Find the corresponding field in the database of number fields print "Finding field..." fields_matching = fields.find({ "signature": [n, int(0)], "discriminant": d }) cnt = fields_matching.count() assert cnt >= 1 field_label = None for i in range(cnt): nf = fields_matching.next() if nf['coefficients'] == coeffs: field_label = nf['label'] assert field_label is not None print "...found!" # Find the field in the HMF database print "Finding field in HMF..." F_hmf = hmf_fields.find_one({"label": field_label}) if F_hmf is None: # Create list of ideals print "...adding!" ideals = eval(preparse(magma.eval('nice_idealstr(F);'))) ideals_str = [str(c) for c in ideals] hmf_fields.insert({ "label": field_label, "degree": n, "discriminant": d, "ideals": ideals_str }) F_hmf = hmf_fields.find_one({"label": field_label}) else: print "...found!" print "Computing ideals..." ideals_str = F_hmf['ideals'] ideals = [eval(preparse(c)) for c in ideals_str] ideals_norms = [c[0] for c in ideals] magma.eval('ideals_str := [' + ''.join(F_hmf['ideals']).replace('][', '], [') + ']') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') # Add the list of primes print "Computing primes..." v = hmff.readline() # Skip line v = hmff.readline() assert v[:9] == 'PRIMES :=' primes_str = v[10:][:-2] primes_array = [str(t) for t in eval(preparse(primes_str))] magma.eval('primes_array := ' + primes_str) magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_array];') magma.eval('primes_indices := [Index(ideals, pp) : pp in primes];') try: assert magma( '&and[primes_indices[j] gt primes_indices[j-1] : j in [2..#primes_indices]]' ) resort = False except AssertionError: print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Primes reordered!" resort = True magma.eval('_, sigma := Sort(primes_indices, func<x,y | x-y>);') magma.eval( 'perm := [[xx : xx in x] : x in CycleDecomposition(sigma) | #x gt 1]' ) # Check at least they have the same norm magma.eval( 'for tau in perm do assert #{Norm(ideals[primes_indices[t]]) : t in tau} eq 1; end for;' ) primes_resort = eval(magma.eval('Eltseq(sigma)')) primes_resort = [c - 1 for c in primes_resort] primes_indices = eval(magma.eval('primes_indices')) primes_str = [ideals_str[j - 1] for j in primes_indices] assert len(primes_array) == len(primes_str) print "...comparing..." for i in range(len(primes_array)): assert magma('ideal<ZF | {F!x : x in ' + primes_array[i] + '}> eq ' + 'ideal<ZF | {F!x : x in ' + primes_str[i] + '}>;') if 'primes' in F_hmf: # Nothing smart: make sure it is the same assert F_hmf['primes'] == primes_str else: F_hmf['primes'] = primes_str hmf_fields.save(F_hmf) print "...saved!" # Collect levels v = hmff.readline() if v[:9] == 'LEVELS :=': # skip this line, we do not use the list of levels v = hmff.readline() for i in range(3): if v[:11] != 'NEWFORMS :=': v = hmff.readline() else: break # Finally, newforms! print "Starting newforms!" while v != '': v = hmff.readline()[1:-3] if len(v) == 0: break data = eval(preparse(v)) level_ideal = data[0] level_norm = data[0][0] label_suffix = data[1] weight = [2 for i in range(n)] level_ind = int( magma('Index(ideals, ideal<ZF | {F!x : x in ' + str(level_ideal) + '}>)')) - 1 # Magma counts starting at 1 level_ideal = ideals_str[level_ind] assert magma('ideal<ZF | {F!x : x in ' + str(level_ideal) + '}> eq ' + 'ideal<ZF | {F!x : x in ' + str(data[0]) + '}>;') level_dotlabel = level_ind - ideals_norms.index( level_norm) + 1 # Start counting at 1 assert level_dotlabel > 0 level_label = str(level_norm) + '.' + str(level_dotlabel) label = parse_label(field_label, weight, level_label, label_suffix) short_label = level_label + '-' + label_suffix if len(data) == 3: hecke_polynomial = x hecke_eigenvalues = data[2] else: hecke_polynomial = data[2] hecke_eigenvalues = data[3] if resort: hecke_eigenvalues = [hecke_eigenvalues[i] for i in primes_resort] # Sort out Atkin-Lehner involutions magma.eval('NN := ideal<ZF | {F!x : x in ' + str(level_ideal) + '}>;') magma.eval('NNfact := Factorization(NN);') ALind = eval( preparse( magma.eval( '[Index(primes, pp[1])-1 : pp in NNfact | Index(primes,pp[1]) gt 0];' ))) AL_eigsin = [hecke_eigenvalues[c] for c in ALind] try: assert all([abs(int(c)) <= 1 for c in AL_eigsin]) except: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') AL_eigenvalues = [] ees = eval(preparse(magma.eval('[pp[2] : pp in NNfact]'))) for i in range(len(AL_eigsin)): if ees[i] >= 2: if hecke_eigenvalues[ALind[i]] != 0: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') else: try: if abs(int(AL_eigsin[i])) != 1: ferrors.write( str(n) + '/' + str(d) + ' ' + label + '\n') else: AL_eigenvalues.append( [primes_str[ALind[i]], -AL_eigsin[i]]) except TypeError: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') assert magma( '[Valuation(NN, ideal<ZF | {F!x : x in a}>) gt 0 : a in [' + str(''.join([a[0] for a in AL_eigenvalues])).replace('][', '], [') + ']];') # Constrain eigenvalues to size 2MB hecke_eigenvalues = [str(c) for c in hecke_eigenvalues] leftout = 0 while sum([len(s) for s in hecke_eigenvalues]) > 2000000: leftout += 1 hecke_eigenvalues = hecke_eigenvalues[:-1] if leftout > 0: print "Left out", leftout info = { "label": label, "short_label": short_label, "field_label": field_label, "level_norm": int(level_norm), "level_ideal": str(level_ideal), "level_label": level_label, "weight": str(weight), "label_suffix": label_suffix, "dimension": hecke_polynomial.degree(), "hecke_polynomial": str(hecke_polynomial), "hecke_eigenvalues": hecke_eigenvalues, "AL_eigenvalues": [[str(a[0]), str(a[1])] for a in AL_eigenvalues] } print info['label'] existing_forms = hmf_forms.find({"label": label}) assert existing_forms.count() <= 1 if existing_forms.count() == 0: hmf_forms.insert(info) else: existing_form = existing_forms.next() assert info['hecke_eigenvalues'] == existing_form[ 'hecke_eigenvalues'] print "...duplicate"
def recompute_AL(): field_label = None S = hmf_forms.find({}) S = S.sort("label") while True: v = S.next() NN_label = v["level_label"] v_label = v["label"] try: if v["AL_eigenvalues_fixed"] == 'done' or v[ "AL_eigenvalues_fixed"] == 'working': continue except KeyError: print(v_label) print("...new, computing!") v["AL_eigenvalues_fixed"] = 'working' hmf_forms.save(v) if field_label is None or not field_label == v["field_label"]: field_label = v["field_label"] print("...new field " + field_label) F = fields.find_one({"label": field_label}) F_hmf = hmf_fields.find_one({"label": field_label}) magma.eval('P<x> := PolynomialRing(Rationals());') magma.eval('F<w> := NumberField(Polynomial(' + str(F["coefficients"]) + '));') magma.eval('ZF := Integers(F);') magma.eval('ideals_str := [' + ','.join([st for st in F_hmf["ideals"]]) + '];') magma.eval( 'ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') magma.eval('primes_str := [' + ','.join([st for st in F_hmf["primes"]]) + '];') magma.eval( 'primes := [ideal<ZF | {F!x : x in I}> : I in primes_str];') NN_index = NN_label[NN_label.index('.') + 1:] magma.eval('NN := [I : I in ideals | Norm(I) eq ' + str(v["level_norm"]) + '][' + str(NN_index) + '];') magma.eval('M := HilbertCuspForms(F, NN);') if v["hecke_polynomial"] != 'x': magma.eval('K<e> := NumberField(' + v["hecke_polynomial"] + ');') else: magma.eval('K := Rationals(); e := 1;') magma.eval('hecke_eigenvalues := [' + ','.join([st for st in v["hecke_eigenvalues"]]) + '];') print("...Hecke eigenvalues loaded...") magma.eval( 's := 0; KT := []; ' 'while KT cmpeq [] or Dimension(KT) gt 1 do ' ' s +:= 1; ' ' pp := primes[s]; ' ' if Valuation(NN, pp) eq 0 then ' ' T_pp := HeckeOperator(M, pp); ' ' a_pp := hecke_eigenvalues[s]; ' ' if KT cmpeq [] then ' ' KT := Kernel(ChangeRing(Matrix(T_pp),K)-a_pp); ' ' else ' ' KT := KT meet Kernel(ChangeRing(Matrix(T_pp),K)-a_pp); ' ' end if; ' ' end if; ' 'end while;') magma.eval('assert Dimension(KT) eq 1;') print("...dimension 1 subspace found...") magma.eval('NNfact := Factorization(NN);') magma.eval('f := Vector(Basis(KT)[1]); ' 'AL_eigenvalues := []; ' 'for pp in NNfact do ' ' U_ppf := f*ChangeRing(AtkinLehnerOperator(M, pp[1]),K); ' ' assert U_ppf eq f or U_ppf eq -f; ' ' if U_ppf eq f then ' ' Append(~AL_eigenvalues, 1); ' ' else ' ' Append(~AL_eigenvalues, -1); ' ' end if; ' 'end for;') # ' T_ppf := f*ChangeRing(HeckeOperator(M, pp[1]),K); '\ # ' if pp[2] ge 2 then assert T_ppf eq 0*f; else assert T_ppf eq -U_ppf; end if; '\ print("...AL eigenvalues computed!") AL_ind = eval( preparse(magma.eval('[Index(primes,pp[1])-1 : pp in NNfact]'))) AL_eigenvalues_jv = eval(preparse(magma.eval('AL_eigenvalues'))) AL_eigenvalues = [[F_hmf["primes"][AL_ind[i]], AL_eigenvalues_jv[i]] for i in range(len(AL_ind))] pps_exps = eval(preparse(magma.eval('[pp[2] : pp in NNfact]'))) hecke_eigenvalues = v["hecke_eigenvalues"] for j in range(len(AL_ind)): s = AL_ind[j] if pps_exps[j] >= 2: hecke_eigenvalues[s] = '0' else: hecke_eigenvalues[s] = str(-AL_eigenvalues[j][1]) AL_eigenvalues = [[a[0], str(a[1])] for a in AL_eigenvalues] v["hecke_eigenvalues"] = hecke_eigenvalues v["AL_eigenvalues"] = AL_eigenvalues v["AL_eigenvalues_fixed"] = 'done' hmf_forms.save(v)
def qexpansion(field_label=None): if field_label is None: query = {} else: query = {"field_label": field_label} S = db.hmf_forms.search(query, sort=["label"]) field_label = None v = S.next() while True: # NN_label = v["level_label"] # never used v_label = v["label"] print v_label if v.get('q_expansion') is not None: v = S.next() continue if field_label is None or not field_label != v["field_label"]: field_label = v["field_label"] print "...new field " + field_label coeffs = db.nf_fields.lookup(field_label, projection="coefficients") F_hmf = db.hmf_fields.lookup( field_label, projection=["ideals", "primes", "narrow_class_number"]) magma.eval('P<x> := PolynomialRing(Rationals());') magma.eval('F<w> := NumberField(Polynomial(' + str(coeffs) + '));') magma.eval('ZF := Integers(F);') magma.eval('ideals_str := [' + ','.join([st for st in F_hmf["ideals"]]) + '];') magma.eval( 'ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') magma.eval('primes_str := [' + ','.join([st for st in F_hmf["primes"]]) + '];') magma.eval( 'primes := [ideal<ZF | {F!x : x in I}> : I in primes_str];') if F_hmf.get("narrow_class_number") is None: F_hmf['narrow_class_number'] = eval( preparse(magma.eval('NarrowClassNumber(F);'))) if v["hecke_polynomial"] != 'x': magma.eval('fpol := ' + v["hecke_polynomial"] + ';') magma.eval('K<e> := NumberField(fpol);') else: magma.eval('fpol := x;') magma.eval('K := Rationals(); e := 1;') magma.eval('hecke_eigenvalues := [' + ','.join([st for st in v["hecke_eigenvalues"]]) + '];') magma.eval( 'mCl := ClassGroupPrimeRepresentatives(ZF, 1*ZF, RealPlaces(F)); ' 'Cl := [mCl(x) : x in Domain(mCl)]; ' 'dd := Different(ZF); ' 'ddinv := dd^(-1); ' 'Nd := Norm(dd); ' 'q_expansions := [* *]; ' 'for pp in Cl do ' ' L0 := MinkowskiLattice(ZF!!(Nd*pp*ddinv)); ' ' L := LatticeWithGram( GramMatrix(L0)/Nd^2 ); ' ' ppdd_basis := Basis(pp*ddinv); ' ' ' ' det := Norm(pp)/Nd; ' ' s := 1; ' ' V := []; ' ' while #V lt 10 do ' ' S := ShortVectors(L, s*det); ' ' S := [&+[Round(Eltseq(v[1])[i])*ppdd_basis[i] : i in [1..#ppdd_basis]] : v in S]; ' ' S := [x : x in S | IsTotallyPositive(x)]; ' ' V := S; ' ' s +:= 1; ' ' end while; ' ' ' ' Append(~q_expansions, [* [F!x : x in V[1..10]], [Index(ideals, x*dd) : x in V] *]); ' 'end for;') q_expansions_str = magma.eval( 'hecke_eigenvalues_forideals := [1]; ' 'm := Max(&cat[t[2] : t in q_expansions]); ' 'for i := 2 to m do ' ' nn := ideals[i]; ' ' nnfact := Factorization(nn); ' ' if #nnfact eq 1 then ' ' pp := nnfact[1][1]; ' ' e := nnfact[1][2]; ' ' if e eq 1 then ' ' ann := hecke_eigenvalues[Index(primes,pp)]; ' ' else ' ' ann := hecke_eigenvalues_forideals[Index(ideals,pp)]* ' ' hecke_eigenvalues_forideals[Index(ideals,pp^(e-1))] - ' ' Norm(pp)*hecke_eigenvalues_forideals[Index(ideals,pp^(e-2))]; ' ' end if; ' ' else ' ' ann := &*[ hecke_eigenvalues_forideals[Index(ideals,qq[1]^qq[2])] : qq in nnfact ]; ' ' end if; ' ' Append(~hecke_eigenvalues_forideals, ann); ' 'end for; ' ' ' 'print [* [* [* q[1][i], hecke_eigenvalues_forideals[q[2][i]] *] : i in [1..#q[1]] *] : q in q_expansions *];' ) q_expansions = eval( preparse(q_expansions_str.replace('[*', '[').replace('*]', ']'))) q_expansions = [[[str(c) for c in q[0]], [str(c) for c in q[1]]] for q in q_expansions] v["q_expansions"] = q_expansions # UPDATES DON'T WORK #db.hmf_forms.save(v) v = S.next()
def qexpansion(field_label=None): if field_label is None: S = hmf_forms.find({}) else: S = hmf_forms.find({"field_label": field_label}) S = S.sort("label") field_label = None v = S.next() while True: # NN_label = v["level_label"] # never used v_label = v["label"] print v_label if v.has_key('q_expansion'): v = S.next() continue if field_label is None or not field_label == v["field_label"]: field_label = v["field_label"] print "...new field " + field_label F = fields.find_one({"label": field_label}) F_hmf = hmf_fields.find_one({"label": field_label}) magma.eval('P<x> := PolynomialRing(Rationals());') magma.eval('F<w> := NumberField(Polynomial(' + str(F["coefficients"]) + '));') magma.eval('ZF := Integers(F);') magma.eval('ideals_str := [' + ','.join([st for st in F_hmf["ideals"]]) + '];') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') magma.eval('primes_str := [' + ','.join([st for st in F_hmf["primes"]]) + '];') magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_str];') if not F_hmf.has_key('narrow_class_number'): F_hmf['narrow_class_number'] = eval(preparse(magma.eval('NarrowClassNumber(F);'))) if v["hecke_polynomial"] != 'x': magma.eval('fpol := ' + v["hecke_polynomial"] + ';') magma.eval('K<e> := NumberField(fpol);') else: magma.eval('fpol := x;') magma.eval('K := Rationals(); e := 1;') magma.eval('hecke_eigenvalues := [' + ','.join([st for st in v["hecke_eigenvalues"]]) + '];') magma.eval('mCl := ClassGroupPrimeRepresentatives(ZF, 1*ZF, RealPlaces(F)); ' 'Cl := [mCl(x) : x in Domain(mCl)]; ' 'dd := Different(ZF); ' 'ddinv := dd^(-1); ' 'Nd := Norm(dd); ' 'q_expansions := [* *]; ' 'for pp in Cl do ' ' L0 := MinkowskiLattice(ZF!!(Nd*pp*ddinv)); ' ' L := LatticeWithGram( GramMatrix(L0)/Nd^2 ); ' ' ppdd_basis := Basis(pp*ddinv); ' ' ' ' det := Norm(pp)/Nd; ' ' s := 1; ' ' V := []; ' ' while #V lt 10 do ' ' S := ShortVectors(L, s*det); ' ' S := [&+[Round(Eltseq(v[1])[i])*ppdd_basis[i] : i in [1..#ppdd_basis]] : v in S]; ' ' S := [x : x in S | IsTotallyPositive(x)]; ' ' V := S; ' ' s +:= 1; ' ' end while; ' ' ' ' Append(~q_expansions, [* [F!x : x in V[1..10]], [Index(ideals, x*dd) : x in V] *]); ' 'end for;') q_expansions_str = magma.eval('hecke_eigenvalues_forideals := [1]; ' 'm := Max(&cat[t[2] : t in q_expansions]); ' 'for i := 2 to m do ' ' nn := ideals[i]; ' ' nnfact := Factorization(nn); ' ' if #nnfact eq 1 then ' ' pp := nnfact[1][1]; ' ' e := nnfact[1][2]; ' ' if e eq 1 then ' ' ann := hecke_eigenvalues[Index(primes,pp)]; ' ' else ' ' ann := hecke_eigenvalues_forideals[Index(ideals,pp)]* ' ' hecke_eigenvalues_forideals[Index(ideals,pp^(e-1))] - ' ' Norm(pp)*hecke_eigenvalues_forideals[Index(ideals,pp^(e-2))]; ' ' end if; ' ' else ' ' ann := &*[ hecke_eigenvalues_forideals[Index(ideals,qq[1]^qq[2])] : qq in nnfact ]; ' ' end if; ' ' Append(~hecke_eigenvalues_forideals, ann); ' 'end for; ' ' ' 'print [* [* [* q[1][i], hecke_eigenvalues_forideals[q[2][i]] *] : i in [1..#q[1]] *] : q in q_expansions *];') q_expansions = eval(preparse(q_expansions_str.replace('[*', '[').replace('*]', ']'))) q_expansions = [[[str(c) for c in q[0]], [str(c) for c in q[1]]] for q in q_expansions] v["q_expansions"] = q_expansions hmf_forms.save(v) v = S.next()
def import_data(hmf_filename, fileprefix=None, ferrors=None, test=True): if fileprefix==None: fileprefix="." hmff = file(os.path.join(fileprefix,hmf_filename)) if ferrors==None: ferrors = file('/home/jvoight/lmfdb/backups/import_data.err', 'a') # Parse field data v = hmff.readline() assert v[:9] == 'COEFFS :=' coeffs = eval(v[10:][:-2]) v = hmff.readline() assert v[:4] == 'n :=' n = int(v[4:][:-2]) v = hmff.readline() assert v[:4] == 'd :=' d = int(v[4:][:-2]) magma.eval('F<w> := NumberField(Polynomial(' + str(coeffs) + '));') magma.eval('ZF := Integers(F);') # Find the corresponding field in the database of number fields dkey = make_disc_key(ZZ(d))[1] sig = "%s,%s" % (n,0) print("Finding field with signature %s and disc_key %s ..." % (sig,dkey)) fields_matching = fields.find({"disc_abs_key": dkey, "signature": sig}) cnt = fields_matching.count() print("Found %s fields" % cnt) assert cnt >= 1 field_label = None co = str(coeffs)[1:-1].replace(" ","") for i in range(cnt): nf = fields_matching.next() print("Comparing coeffs %s with %s" % (nf['coeffs'], co)) if nf['coeffs'] == co: field_label = nf['label'] assert field_label is not None print "...found!" # Find the field in the HMF database print("Finding field %s in HMF..." % field_label) F_hmf = hmf_fields.find_one({"label": field_label}) if F_hmf is None: # Create list of ideals print "...adding!" ideals = eval(preparse(magma.eval('nice_idealstr(F);'))) ideals_str = [str(c) for c in ideals] if test: print("Would now insert data for %s into hmf_fields" % field_label) else: hmf_fields.insert({"label": field_label, "degree": n, "discriminant": d, "ideals": ideals_str}) F_hmf = hmf_fields.find_one({"label": field_label}) else: print "...found!" print "Computing ideals..." ideals_str = F_hmf['ideals'] ideals = [eval(preparse(c)) for c in ideals_str] ideals_norms = [c[0] for c in ideals] magma.eval('ideals_str := [' + ''.join(F_hmf['ideals']).replace('][', '], [') + ']') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') # Add the list of primes print "Computing primes..." v = hmff.readline() # Skip line v = hmff.readline() assert v[:9] == 'PRIMES :=' primes_str = v[10:][:-2] primes_array = [str(t) for t in eval(preparse(primes_str))] magma.eval('primes_array := ' + primes_str) magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_array];') magma.eval('primes_indices := [Index(ideals, pp) : pp in primes];') try: assert magma('&and[primes_indices[j] gt primes_indices[j-1] : j in [2..#primes_indices]]') resort = False except AssertionError: print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Primes reordered!" resort = True magma.eval('_, sigma := Sort(primes_indices, func<x,y | x-y>);') magma.eval('perm := [[xx : xx in x] : x in CycleDecomposition(sigma) | #x gt 1]') # Check at least they have the same norm magma.eval('for tau in perm do assert #{Norm(ideals[primes_indices[t]]) : t in tau} eq 1; end for;') primes_resort = eval(magma.eval('Eltseq(sigma)')) primes_resort = [c - 1 for c in primes_resort] primes_indices = eval(magma.eval('primes_indices')) primes_str = [ideals_str[j - 1] for j in primes_indices] assert len(primes_array) == len(primes_str) print "...comparing..." for i in range(len(primes_array)): assert magma('ideal<ZF | {F!x : x in ' + primes_array[i] + '}> eq ' + 'ideal<ZF | {F!x : x in ' + primes_str[i] + '}>;') if resort: # Important also to resort the list of primes themselves! # not just the a_pp's primes_str = [primes_str[i] for i in primes_resort] if 'primes' in F_hmf: # Nothing smart: make sure it is the same assert F_hmf['primes'] == primes_str else: F_hmf['primes'] = primes_str if test: print("Would now save primes string %s... into hmf_fields" % primes_str[:100]) else: hmf_fields.save(F_hmf) print "...saved!" # Collect levels v = hmff.readline() if v[:9] == 'LEVELS :=': # Skip this line since we do not use the list of levels v = hmff.readline() for i in range(3): if v[:11] != 'NEWFORMS :=': v = hmff.readline() else: break # Finally, newforms! print "Starting newforms!" while v != '': v = hmff.readline()[1:-3] if len(v) == 0: break data = eval(preparse(v)) level_ideal = data[0] level_norm = data[0][0] label_suffix = data[1] weight = [2 for i in range(n)] level_ind = int(magma('Index(ideals, ideal<ZF | {F!x : x in ' + str(level_ideal) + '}>)') ) - 1 # Magma counts starting at 1 level_ideal = ideals_str[level_ind] assert magma('ideal<ZF | {F!x : x in ' + str(level_ideal) + '}> eq ' + 'ideal<ZF | {F!x : x in ' + str(data[0]) + '}>;') level_dotlabel = level_ind - ideals_norms.index(level_norm) + 1 # Start counting at 1 assert level_dotlabel > 0 level_label = str(level_norm) + '.' + str(level_dotlabel) label = construct_full_label(field_label, weight, level_label, label_suffix) short_label = level_label + '-' + label_suffix if len(data) == 3: hecke_polynomial = x hecke_eigenvalues = data[2] else: hecke_polynomial = data[2] hecke_eigenvalues = data[3] if resort: hecke_eigenvalues = [hecke_eigenvalues[i] for i in primes_resort] # Sort out Atkin-Lehner involutions magma.eval('NN := ideal<ZF | {F!x : x in ' + str(level_ideal) + '}>;') magma.eval('NNfact := Factorization(NN);') ALind = eval( preparse(magma.eval('[Index(primes, pp[1])-1 : pp in NNfact | Index(primes,pp[1]) gt 0];'))) AL_eigsin = [hecke_eigenvalues[c] for c in ALind] try: assert all([abs(int(c)) <= 1 for c in AL_eigsin]) except: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') AL_eigenvalues = [] ees = eval(preparse(magma.eval('[pp[2] : pp in NNfact]'))) for i in range(len(AL_eigsin)): if ees[i] >= 2: if hecke_eigenvalues[ALind[i]] != 0: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') else: try: if abs(int(AL_eigsin[i])) != 1: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') else: AL_eigenvalues.append([primes_str[ALind[i]], -AL_eigsin[i]]) except TypeError: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') assert magma('[Valuation(NN, ideal<ZF | {F!x : x in a}>) gt 0 : a in [' + str(''.join([a[0] for a in AL_eigenvalues])).replace('][', '], [') + ']];') # Constrain eigenvalues to size 2MB hecke_eigenvalues = [str(c) for c in hecke_eigenvalues] leftout = 0 while sum([len(s) for s in hecke_eigenvalues]) > 2000000: leftout += 1 hecke_eigenvalues = hecke_eigenvalues[:-1] if leftout > 0: print "Left out", leftout info = {"label": label, "short_label": short_label, "field_label": field_label, "level_norm": int(level_norm), "level_ideal": str(level_ideal), "level_label": level_label, "weight": str(weight), "label_suffix": label_suffix, "dimension": hecke_polynomial.degree(), "hecke_polynomial": str(hecke_polynomial), "hecke_eigenvalues": hecke_eigenvalues, "AL_eigenvalues": [[str(a[0]), str(a[1])] for a in AL_eigenvalues]} print info['label'] existing_forms = hmf_forms.find({"label": label}) assert existing_forms.count() <= 1 if existing_forms.count() == 0: if test: print("Would now insert form data %s into hmf_forms" % info) else: hmf_forms.insert(info) else: existing_form = existing_forms.next() assert info['hecke_polynomial'] == existing_form['hecke_polynomial'] try: assert info['hecke_eigenvalues'] == existing_form['hecke_eigenvalues'] print "...duplicate" except AssertionError: print "...Hecke eigenvalues do not match! Checking for permutation" assert set(info['hecke_eigenvalues'] + ['0','1','-1']) == set(existing_form['hecke_eigenvalues'] + [u'0',u'1',u'-1']) # Add 0,1,-1 to allow for Atkin-Lehner eigenvalues, if not computed print "As sets, ignoring 0,1,-1, the eigenvalues match!" if test: print("Would now replace permuted form data %s with %s" % (existing_form, info)) else: existing_form['hecke_eigenvalues'] = info['hecke_eigenvalues'] hmf_forms.save(existing_form)
def recompute_AL(field_label=None, skip_odd=False): if field_label is None: S = hmf_forms.find({"AL_eigenvalues_fixed": None}) else: S = hmf_forms.find({"field_label": field_label, "AL_eigenvalues_fixed": None}) S = S.sort("label") field_label = None magma.eval('SetVerbose("ModFrmHil", 1);') v = S.next() while True: NN_label = v["level_label"] v_label = v["label"] print(v_label) if field_label is None or not field_label == v["field_label"]: field_label = v["field_label"] print("...new field " + field_label) F = fields.find_one({"label": field_label}) F_hmf = hmf_fields.find_one({"label": field_label}) magma.eval('P<x> := PolynomialRing(Rationals());') magma.eval('F<w> := NumberField(Polynomial(' + str(F["coefficients"]) + '));') magma.eval('ZF := Integers(F);') magma.eval('ideals_str := [' + ','.join([st for st in F_hmf["ideals"]]) + '];') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') magma.eval('primes_str := [' + ','.join([st for st in F_hmf["primes"]]) + '];') magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_str];') magma.eval('classno := NarrowClassNumber(F);') if skip_odd and F["degree"] % 2 == 1 and v["level_norm"] > 300: print("...level norm > 300, skipping!") try: v = S.next() continue except StopIteration: break NN_index = NN_label[NN_label.index('.') + 1:] magma.eval( 'NN := [I : I in ideals | Norm(I) eq ' + str(v["level_norm"]) + '][' + str(NN_index) + '];') magma.eval('Mfull := HilbertCuspForms(F, NN);') magma.eval('M := NewSubspace(Mfull);') magma.eval('O := QuaternionOrder(M); B := Algebra(O); DD := Discriminant(B);') if v["hecke_polynomial"] != 'x': magma.eval('fpol := ' + v["hecke_polynomial"] + ';') magma.eval('K<e> := NumberField(fpol);') else: magma.eval('fpol := x;') magma.eval('K := Rationals(); e := 1;') magma.eval('hecke_eigenvalues := [' + ','.join([st for st in v["hecke_eigenvalues"]]) + '];') print("...Hecke eigenvalues loaded...") magma.eval('denom := Lcm([Denominator(a) : a in hecke_eigenvalues]); q := NextPrime(200);') magma.eval( 'while #Roots(fpol, GF(q)) eq 0 or Valuation(denom,q) gt 0 do q := NextPrime(q); end while;') magma.eval('if K cmpeq Rationals() then mk := hom<K -> GF(q) | >; else mk := hom<K -> GF(q) | Roots(fpol,GF(q))[1][1]>; end if;') magma.eval( '_<xQ> := PolynomialRing(Rationals()); rootsofunity := [r[1] : r in Roots(xQ^(2*classno)-1,K)];') magma.eval('s := 0; KT := []; ' 'while KT cmpeq [] or Dimension(KT) gt 1 do ' ' s +:= 1; ' ' if s gt Min(50,#hecke_eigenvalues) then ' ' q := NextPrime(q); while #Roots(fpol, GF(q)) eq 0 or Valuation(denom,q) gt 0 do q := NextPrime(q); end while; ' ' if K cmpeq Rationals() then mk := hom<K -> GF(q) | >; else mk := hom<K -> GF(q) | Roots(fpol,GF(q))[1][1]>; end if; ' ' s := 1; ' ' KT := []; ' ' end if; ' ' pp := primes[s]; ' ' if Valuation(NN, pp) eq 0 then ' ' T_pp := HeckeOperator(M, pp); ' ' T_pp := Matrix(Nrows(T_pp),Ncols(T_pp),[mk(c) : c in Eltseq(T_pp)]); ' ' a_pp := hecke_eigenvalues[s]; ' ' if KT cmpeq [] then ' ' KT := Kernel(T_pp-mk(a_pp)); ' ' else ' ' KT := KT meet Kernel(T_pp-mk(a_pp)); ' ' end if; ' ' end if; ' 'end while;') magma.eval('assert Dimension(KT) eq 1;') print("...dimension 1 subspace found...") magma.eval('NNfact := [pp : pp in Factorization(NN) | pp[1] in primes];') magma.eval('f := Vector(Basis(KT)[1]); ' 'AL_eigenvalues := []; ' 'for pp in NNfact do ' ' if Valuation(DD,pp[1]) gt 0 then U_pp := -HeckeOperator(M, pp[1]); ' ' else U_pp := AtkinLehnerOperator(M, pp[1]); end if; ' ' U_pp := Matrix(Nrows(U_pp),Ncols(U_pp),[mk(c) : c in Eltseq(U_pp)]); ' ' U_ppf := f*U_pp; found := false; ' ' for mu in rootsofunity do ' ' if U_ppf eq mk(mu)*f then Append(~AL_eigenvalues, mu); found := true; end if; ' ' end for; ' ' assert found; ' 'end for;') print("...AL eigenvalues computed!") AL_ind = eval(preparse(magma.eval('[Index(primes,pp[1])-1 : pp in NNfact]'))) AL_eigenvalues_jv = eval(preparse(magma.eval('AL_eigenvalues'))) AL_eigenvalues = [[F_hmf["primes"][AL_ind[i]], AL_eigenvalues_jv[i]] for i in range(len(AL_ind))] pps_exps = eval(preparse(magma.eval('[pp[2] : pp in NNfact]'))) hecke_eigenvalues = v["hecke_eigenvalues"] for j in range(len(AL_ind)): s = AL_ind[j] try: if pps_exps[j] >= 2: hecke_eigenvalues[s] = '0' else: hecke_eigenvalues[s] = str(-AL_eigenvalues[j][1]) except IndexError: pass AL_eigenvalues = [[a[0], str(a[1])] for a in AL_eigenvalues] v["hecke_eigenvalues"] = hecke_eigenvalues v["AL_eigenvalues"] = AL_eigenvalues v["AL_eigenvalues_fixed"] = 'done' hmf_forms.save(v) v = S.next()
from scripts.hmf.check_conjugates import fix_one_label from sage.databases.cremona import class_to_int import yaml # Assumes running from lmfdb root directory pw_dict = yaml.load(open(os.path.join(os.getcwd(), "passwords.yaml"))) username = pw_dict['data']['username'] password = pw_dict['data']['password'] C['hmfs'].authenticate(username, password) hmf_forms = C.hmfs.forms_dan hmf_fields = C.hmfs.fields fields = C.numberfields.fields magma.eval( 'nice_idealstr := function(F : Bound := 10000); idealsstr := []; ideals := IdealsUpTo(Bound, F); for I in ideals do bl, g := IsPrincipal(I); if bl then s := Sprintf("[%o, %o, %o]", Norm(I), Minimum(I), F!g); else zs := Generators(I); z := zs[#zs]; m := Minimum(I); z := F![(Integers()!c) mod m : c in Eltseq(F!z)]; assert ideal<Integers(F) | [m, z]> eq I; s := Sprintf("[%o, %o, %o]", Norm(I), m, z); end if; Append(~idealsstr, s); end for; return idealsstr; end function;' ) from lmfdb.number_fields.number_field import make_disc_key from lmfdb.hilbert_modular_forms.web_HMF import construct_full_label P = PolynomialRing(QQ, 3, ['w', 'e', 'x']) w, e, x = P.gens() def import_all_data(n, fileprefix=None, ferrors=None, test=True): nstr = str(n) if fileprefix == None: fileprefix = "/home/jvoight/Elements/ModFrmHilDatav1.1/Data/" + nstr + "/dir.tmp" ff = open(fileprefix, 'r')
def import_data_fix_perm_primes(hmf_filename, fileprefix=None, ferrors=None, test=True): if fileprefix == None: fileprefix = "." hmff = file(os.path.join(fileprefix, hmf_filename)) if ferrors == None: ferrors = file('/home/jvoight/lmfdb/backups/import_data.err', 'a') # Parse field data v = hmff.readline() assert v[:9] == 'COEFFS :=' coeffs = eval(v[10:].split(';')[0]) v = hmff.readline() assert v[:4] == 'n :=' n = int(v[4:][:-2]) v = hmff.readline() assert v[:4] == 'd :=' d = int(v[4:][:-2]) magma.eval('F<w> := NumberField(Polynomial(' + str(coeffs) + '));') magma.eval('ZF := Integers(F);') # Find the corresponding field in the database of number fields dkey = make_disc_key(ZZ(d))[1] sig = "%s,%s" % (n, 0) print("Finding field with signature %s and disc_key %s ..." % (sig, dkey)) fields_matching = fields.find({"disc_abs_key": dkey, "signature": sig}) cnt = fields_matching.count() print("Found %s fields" % cnt) assert cnt >= 1 field_label = None co = str(coeffs)[1:-1].replace(" ", "") for i in range(cnt): nf = fields_matching.next() print("Comparing coeffs %s with %s" % (nf['coeffs'], co)) if nf['coeffs'] == co: field_label = nf['label'] assert field_label is not None print "...found!" # Find the field in the HMF database print("Finding field %s in HMF..." % field_label) F_hmf = hmf_fields.find_one({"label": field_label}) assert F_hmf is not None # only proceed if field already in database print "...found!" print "Computing ideals..." ideals_str = F_hmf['ideals'] # ideals = [eval(preparse(c)) for c in ideals_str] # doesn't appear to be used # ideals_norms = [c[0] for c in ideals] # doesn't appear to be used magma.eval('ideals_str := [' + ''.join(F_hmf['ideals']).replace('][', '], [') + ']') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') # Add the list of primes print "Computing primes..." v = hmff.readline() # Skip line v = hmff.readline() assert v[:9] == 'PRIMES :=' primes_str = v[10:][:-2] primes_array = [str(t) for t in eval(preparse(primes_str))] magma.eval('primes_array := ' + primes_str) magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_array];') magma.eval('primes_indices := [Index(ideals, pp) : pp in primes];') try: assert magma( '&and[primes_indices[j] gt primes_indices[j-1] : j in [2..#primes_indices]]' ) resort = False except AssertionError: print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Primes reordered!" resort = True magma.eval('_, sigma := Sort(primes_indices, func<x,y | x-y>);') magma.eval( 'perm := [[xx : xx in x] : x in CycleDecomposition(sigma) | #x gt 1]' ) # Check at least they have the same norm magma.eval( 'for tau in perm do assert #{Norm(ideals[primes_indices[t]]) : t in tau} eq 1; end for;' ) primes_resort = eval(magma.eval('Eltseq(sigma)')) primes_resort = [c - 1 for c in primes_resort] if resort: primes_indices = eval(magma.eval('primes_indices')) primes_str = [ideals_str[j - 1] for j in primes_indices] assert len(primes_array) == len(primes_str) print "...comparing..." for i in range(len(primes_array)): assert magma('ideal<ZF | {F!x : x in ' + primes_array[i] + '}> eq ' + 'ideal<ZF | {F!x : x in ' + primes_str[i] + '}>;') # Important also to resort the list of primes themselves! # not just the a_pp's primes_str = [primes_str[i] for i in primes_resort] print("Compare primes in hmf.fields\n %s\n with NEW primes\n %s" % (F_hmf['primes'], primes_str)) if test: print("...Didn't do anything! Just a test") else: F_hmf['primes'] = primes_str hmf_fields.save(F_hmf) print "...saved!"
def recompute_AL(field_label=None, skip_odd=False): if field_label is None: S = hmf_forms.find({"AL_eigenvalues_fixed": None}) else: S = hmf_forms.find({"field_label": field_label, "AL_eigenvalues_fixed": None}) S = S.sort("label") field_label = None magma.eval('SetVerbose("ModFrmHil", 1);') v = S.next() while True: NN_label = v["level_label"] v_label = v["label"] print v_label if field_label is None or not field_label == v["field_label"]: field_label = v["field_label"] print "...new field " + field_label F = fields.find_one({"label": field_label}) F_hmf = hmf_fields.find_one({"label": field_label}) magma.eval('P<x> := PolynomialRing(Rationals());') magma.eval('F<w> := NumberField(Polynomial(' + str(F["coefficients"]) + '));') magma.eval('ZF := Integers(F);') magma.eval('ideals_str := [' + ','.join([st for st in F_hmf["ideals"]]) + '];') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') magma.eval('primes_str := [' + ','.join([st for st in F_hmf["primes"]]) + '];') magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_str];') magma.eval('classno := NarrowClassNumber(F);') if skip_odd and F["degree"] % 2 == 1 and v["level_norm"] > 300: print "...level norm > 300, skipping!" try: v = S.next() continue except StopIteration: break NN_index = NN_label[NN_label.index('.') + 1:] magma.eval( 'NN := [I : I in ideals | Norm(I) eq ' + str(v["level_norm"]) + '][' + str(NN_index) + '];') magma.eval('Mfull := HilbertCuspForms(F, NN);') magma.eval('M := NewSubspace(Mfull);') magma.eval('O := QuaternionOrder(M); B := Algebra(O); DD := Discriminant(B);') if v["hecke_polynomial"] != 'x': magma.eval('fpol := ' + v["hecke_polynomial"] + ';') magma.eval('K<e> := NumberField(fpol);') else: magma.eval('fpol := x;') magma.eval('K := Rationals(); e := 1;') magma.eval('hecke_eigenvalues := [' + ','.join([st for st in v["hecke_eigenvalues"]]) + '];') print "...Hecke eigenvalues loaded..." magma.eval('denom := Lcm([Denominator(a) : a in hecke_eigenvalues]); q := NextPrime(200);') magma.eval( 'while #Roots(fpol, GF(q)) eq 0 or Valuation(denom,q) gt 0 do q := NextPrime(q); end while;') magma.eval('if K cmpeq Rationals() then mk := hom<K -> GF(q) | >; else mk := hom<K -> GF(q) | Roots(fpol,GF(q))[1][1]>; end if;') magma.eval( '_<xQ> := PolynomialRing(Rationals()); rootsofunity := [r[1] : r in Roots(xQ^(2*classno)-1,K)];') magma.eval('s := 0; KT := []; ' 'while KT cmpeq [] or Dimension(KT) gt 1 do ' ' s +:= 1; ' ' if s gt Min(50,#hecke_eigenvalues) then ' ' q := NextPrime(q); while #Roots(fpol, GF(q)) eq 0 or Valuation(denom,q) gt 0 do q := NextPrime(q); end while; ' ' if K cmpeq Rationals() then mk := hom<K -> GF(q) | >; else mk := hom<K -> GF(q) | Roots(fpol,GF(q))[1][1]>; end if; ' ' s := 1; ' ' KT := []; ' ' end if; ' ' pp := primes[s]; ' ' if Valuation(NN, pp) eq 0 then ' ' T_pp := HeckeOperator(M, pp); ' ' T_pp := Matrix(Nrows(T_pp),Ncols(T_pp),[mk(c) : c in Eltseq(T_pp)]); ' ' a_pp := hecke_eigenvalues[s]; ' ' if KT cmpeq [] then ' ' KT := Kernel(T_pp-mk(a_pp)); ' ' else ' ' KT := KT meet Kernel(T_pp-mk(a_pp)); ' ' end if; ' ' end if; ' 'end while;') magma.eval('assert Dimension(KT) eq 1;') print "...dimension 1 subspace found..." magma.eval('NNfact := [pp : pp in Factorization(NN) | pp[1] in primes];') magma.eval('f := Vector(Basis(KT)[1]); ' 'AL_eigenvalues := []; ' 'for pp in NNfact do ' ' if Valuation(DD,pp[1]) gt 0 then U_pp := -HeckeOperator(M, pp[1]); ' ' else U_pp := AtkinLehnerOperator(M, pp[1]); end if; ' ' U_pp := Matrix(Nrows(U_pp),Ncols(U_pp),[mk(c) : c in Eltseq(U_pp)]); ' ' U_ppf := f*U_pp; found := false; ' ' for mu in rootsofunity do ' ' if U_ppf eq mk(mu)*f then Append(~AL_eigenvalues, mu); found := true; end if; ' ' end for; ' ' assert found; ' 'end for;') print "...AL eigenvalues computed!" AL_ind = eval(preparse(magma.eval('[Index(primes,pp[1])-1 : pp in NNfact]'))) AL_eigenvalues_jv = eval(preparse(magma.eval('AL_eigenvalues'))) AL_eigenvalues = [[F_hmf["primes"][AL_ind[i]], AL_eigenvalues_jv[i]] for i in range(len(AL_ind))] pps_exps = eval(preparse(magma.eval('[pp[2] : pp in NNfact]'))) hecke_eigenvalues = v["hecke_eigenvalues"] for j in range(len(AL_ind)): s = AL_ind[j] try: if pps_exps[j] >= 2: hecke_eigenvalues[s] = '0' else: hecke_eigenvalues[s] = str(-AL_eigenvalues[j][1]) except IndexError: pass AL_eigenvalues = [[a[0], str(a[1])] for a in AL_eigenvalues] v["hecke_eigenvalues"] = hecke_eigenvalues v["AL_eigenvalues"] = AL_eigenvalues v["AL_eigenvalues_fixed"] = 'done' hmf_forms.save(v) v = S.next()
def Lpvalue(f, g, h, p, prec, N=None, modformsring=False, weightbound=6, eps=None, orthogonal_form=None, magma_args=None, force_computation=False, algorithm='twostage'): if magma_args is None: magma_args = {} if algorithm not in ['twostage', 'threestage']: raise ValueError( 'Algorithm should be one of "twostage" (default) or "threestage"') from sage.interfaces.magma import Magma magma = Magma(**magma_args) ll, mm = g.weight(), h.weight() t = 0 # Assume t = 0 here kk = ll + mm - 2 * (1 + t) # Is this correct? p = ZZ(p) if N is None: N = LCM([ZZ(f.level()), ZZ(g.level()), ZZ(h.level())]) N = N.prime_to_m_part(p) print("Tame level N = %s, prime p = %s" % (N, p)) prec = ZZ(prec) print("Step 1: Compute the Up matrix") computation_name = '%s_%s_%s_%s_%s_%s' % ( p, N, kk, prec, 'triv' if eps is None else 'char', algorithm) tmp_filename = '/tmp/magma_mtx_%s.tmp' % computation_name import os.path from sage.misc.persist import db, db_save try: if force_computation: raise IOError V = db('Lpvalue_Apow_ordbasis_eimat_%s' % computation_name) ord_basis, eimat, zetapm, elldash, mdash = V[:5] Apow_data = V[5:] except IOError: if force_computation or not os.path.exists(tmp_filename): if eps is not None: eps_magma = sage_character_to_magma(eps, magma=magma) Am, zetapm, eimatm, elldash, mdash = magma.UpOperatorData( p, eps_magma, kk, prec, nvals=5) else: Am, zetapm, eimatm, elldash, mdash = magma.UpOperatorData( p, N, kk, prec, nvals=5) print(" ..Converting to Sage...") Amodulus = Am[1, 1].Parent().Modulus().sage() Arows = Am.NumberOfRows().sage() Acols = Am.NumberOfColumns().sage() Emodulus = eimatm[1, 1].Parent().Modulus().sage() Erows = eimatm.NumberOfRows().sage() Ecols = eimatm.NumberOfColumns().sage() magma.eval('F := Open("%s", "w");' % tmp_filename) magma.eval('fprintf F, "Matrix(Zmod(%s),%s, %s, "' % (Amodulus, Arows, Acols)) magma.eval('fprintf F, "%%o", ElementToSequence(%s)' % Am.name()) magma.eval('fprintf F, ") \\n"') magma.eval('fprintf F, "Matrix(Zmod(%s),%s, %s, "' % (Emodulus, Erows, Ecols)) magma.eval('fprintf F, "%%o", ElementToSequence(%s)' % eimatm.name()) magma.eval('fprintf F, ") \\n"') magma.eval('fprintf F, "%%o\\n", %s' % zetapm.name()) magma.eval('fprintf F, "%%o\\n", %s' % elldash.name()) magma.eval('fprintf F, "%%o\\n", %s' % mdash.name()) magma.eval('delete F;') magma.quit() # Read A and eimat from file from sage.structure.sage_object import load from sage.misc.sage_eval import sage_eval with open(tmp_filename, 'r') as fmagma: A = sage_eval(fmagma.readline(), preparse=False) eimat = sage_eval(fmagma.readline(), preparse=False) zetapm = sage_eval(fmagma.readline()) elldash = sage_eval(fmagma.readline()) mdash = sage_eval(fmagma.readline()) print("Step 3b: Apply Up^(r-1) to H") if algorithm == 'twostage': V0 = list(find_Apow_and_ord(A, eimat, p, prec)) else: V0 = list(find_Apow_and_ord_three_stage(A, eimat, p, prec)) ord_basis = V0[0] Apow_data = V0[1:] V = [ord_basis] V.extend([eimat, zetapm, elldash, mdash]) V.extend(Apow_data) db_save(V, 'Lpvalue_Apow_ordbasis_eimat_%s' % computation_name) from posix import remove remove(tmp_filename) print("Step 2: p-depletion, Coleman primitive, and multiply") H = depletion_coleman_multiply(g, h, p, p * elldash, t=0) print("Step 3a: Compute Up(H)") UpH = vector([H(p * n) for n in range(elldash)]) if len(Apow_data) == 1: Hord = compute_ordinary_projection_two_stage(UpH, Apow_data, eimat, elldash) else: Hord = compute_ordinary_projection_three_stage(UpH, [ord_basis] + Apow_data, eimat, elldash) Hord = Hord.change_ring(Apow_data[0].parent().base_ring()) print("Step 4: Project onto f-component") R = Qp(p, prec) if orthogonal_form is None: ell, piHord = project_onto_eigenspace(f, ord_basis, Hord.change_ring(R), kk, N * p, eps) n = 1 while f[n] == 0: n += 1 Lpa = R(piHord[n]) / R(f[n]) else: ell, piHord = project_onto_eigenspace(f, ord_basis, Hord.change_ring(R), kk, N * p, eps, derivative_order=2) gplus, gminus = f, orthogonal_form l1 = 2 while N * p * ell % l1 == 0 or gplus[l1] == 0: l1 = next_prime(l1) proj_mat = matrix([[gplus[l1], gplus[p]], [gminus[l1], gminus[p]]]) Lpalist = (matrix([piHord[l1], piHord[p]]) * proj_mat**-1).list() Lpa = Lpalist[0] if Lpa.valuation() > prec / 2: # this is quite arbitrary! Lpa = Lpalist[1] n = 1 while f[n] == 0: n += 1 Lpa = Lpa / f[n] return Lpa, ell
def import_data_fix_perm_primes(hmf_filename, fileprefix=None, ferrors=None, test=True): if fileprefix==None: fileprefix="." hmff = file(os.path.join(fileprefix,hmf_filename)) if ferrors==None: ferrors = file('/home/jvoight/lmfdb/backups/import_data.err', 'a') # Parse field data v = hmff.readline() assert v[:9] == 'COEFFS :=' coeffs = eval(v[10:].split(';')[0]) v = hmff.readline() assert v[:4] == 'n :=' n = int(v[4:][:-2]) v = hmff.readline() assert v[:4] == 'd :=' d = int(v[4:][:-2]) magma.eval('F<w> := NumberField(Polynomial(' + str(coeffs) + '));') magma.eval('ZF := Integers(F);') # Find the corresponding field in the database of number fields dkey = make_disc_key(ZZ(d))[1] sig = "%s,%s" % (n,0) print("Finding field with signature %s and disc_key %s ..." % (sig,dkey)) fields_matching = fields.find({"disc_abs_key": dkey, "signature": sig}) cnt = fields_matching.count() print("Found %s fields" % cnt) assert cnt >= 1 field_label = None co = str(coeffs)[1:-1].replace(" ","") for i in range(cnt): nf = fields_matching.next() print("Comparing coeffs %s with %s" % (nf['coeffs'], co)) if nf['coeffs'] == co: field_label = nf['label'] assert field_label is not None print "...found!" # Find the field in the HMF database print("Finding field %s in HMF..." % field_label) F_hmf = hmf_fields.find_one({"label": field_label}) assert F_hmf is not None # only proceed if field already in database print "...found!" print "Computing ideals..." ideals_str = F_hmf['ideals'] # ideals = [eval(preparse(c)) for c in ideals_str] # doesn't appear to be used # ideals_norms = [c[0] for c in ideals] # doesn't appear to be used magma.eval('ideals_str := [' + ''.join(F_hmf['ideals']).replace('][', '], [') + ']') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') # Add the list of primes print "Computing primes..." v = hmff.readline() # Skip line v = hmff.readline() assert v[:9] == 'PRIMES :=' primes_str = v[10:][:-2] primes_array = [str(t) for t in eval(preparse(primes_str))] magma.eval('primes_array := ' + primes_str) magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_array];') magma.eval('primes_indices := [Index(ideals, pp) : pp in primes];') try: assert magma('&and[primes_indices[j] gt primes_indices[j-1] : j in [2..#primes_indices]]') resort = False except AssertionError: print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Primes reordered!" resort = True magma.eval('_, sigma := Sort(primes_indices, func<x,y | x-y>);') magma.eval('perm := [[xx : xx in x] : x in CycleDecomposition(sigma) | #x gt 1]') # Check at least they have the same norm magma.eval('for tau in perm do assert #{Norm(ideals[primes_indices[t]]) : t in tau} eq 1; end for;') primes_resort = eval(magma.eval('Eltseq(sigma)')) primes_resort = [c - 1 for c in primes_resort] if resort: primes_indices = eval(magma.eval('primes_indices')) primes_str = [ideals_str[j - 1] for j in primes_indices] assert len(primes_array) == len(primes_str) print "...comparing..." for i in range(len(primes_array)): assert magma('ideal<ZF | {F!x : x in ' + primes_array[i] + '}> eq ' + 'ideal<ZF | {F!x : x in ' + primes_str[i] + '}>;') # Important also to resort the list of primes themselves! # not just the a_pp's primes_str = [primes_str[i] for i in primes_resort] print("Compare primes in hmf.fields\n %s\n with NEW primes\n %s" % (F_hmf['primes'], primes_str)) if test: print("...Didn't do anything! Just a test") else: F_hmf['primes'] = primes_str hmf_fields.save(F_hmf) print "...saved!"
def compute_data(genera, groups='all', g0_gt0_compute=True, top_braid_compute=True, top_braid_g0_gt0=False): ''' Compute hgcwa data for the specified genera (list of integers) and output the data in files that can be uploaded to the hgcwa db via the copy_from function, called gxx_allgrps_data.txt, gxx_abelgrps_data.txt, or gxx_nonabelgrps_data.txt depending on the value of groups, where gxx refers to the specific genus. If groups='all', then data for all groups will be computed for each genus. If groups='abel', then only data for abelian groups will be computed for each genus. If groups='nonabel', then only data for nonabelian groups will be computed for each genus. The g0_gt0_compute parameter determines whether to compute g0>0 data for each genus. The top_braid_compute parameter determines whether to compute topological, braid equivalences for g0=0 and each genus. The top_braid_g0_gt0 parameter determines whether to compute topological, braid equivalences for g0>0 and each genus. The file gL_complete.txt, where L is the sequence of genera, will contain the completeness values, which can be uploaded to the hgcwa_per_genus_stats db. If db.gps_groups or db.gps_transitive have been updated recently, the scripts gps_decode.py and gps_transitive.py should be rerun to create new gps_decode.mag and gps_transitive.mag files before running this procedure. The file log.txt will contain errors that occurred during computation and instances where a group not from db.gps_transitive is passed into RepEpi. ''' # Check if arguments are valid try: for genus in genera: if genus < 2 or int(genus) != genus: raise ValueError if not(groups == 'all' or groups == 'abel' or groups == 'nonabel'): raise ValueError if not(type(g0_gt0_compute) == bool and type(top_braid_compute) == bool and type(top_braid_g0_gt0) == bool): raise ValueError if top_braid_g0_gt0 and not g0_gt0_compute: raise ValueError if top_braid_g0_gt0: print('top,braid for g0>0 not implemented') raise ValueError except: print('Invalid arguments') return # Create a file that contains the completeness columns of the # hgcwa_per_genus_stats db but is missing the stats columns create_comp_file(genera, groups, g0_gt0_compute, top_braid_compute, top_braid_g0_gt0) # Empty contents of log.txt and TBLDATA magma.eval('SetOutputFile("%s" : Overwrite:=true)' % 'log.txt') magma.eval('SetOutputFile("%s" : Overwrite:=true)' % 'OutputFiles/TBLDATA') magma.eval('UnsetOutputFile()') magma.set('logfile', '"%s"' % 'log.txt') # Iterate over each genus for genus in genera: print('Computing data for genus %d...' % genus) genus_str = str(genus) if genus < 10: genus_str = '0' + genus_str # Names of temporary files for each genus supp_gxx = 'SupplementaryFiles/g%s' % genus_str possible_full = 'OutputFiles/g%spossible_full' % genus_str full = 'OutputFiles/g%sfull' % genus_str notfull = 'OutputFiles/g%snotfull' % genus_str gxxfinaldata = 'g%sfinaldata' % genus_str # Make sure the temporary files are empty before beginning magma.eval('SetOutputFile("%s" : Overwrite:=true)' % supp_gxx) magma.eval('SetOutputFile("%s" : Overwrite:=true)' % possible_full) magma.eval('SetOutputFile("%s" : Overwrite:=true)' % full) magma.eval('SetOutputFile("%s" : Overwrite:=true)' % notfull) magma.eval('SetOutputFile("%s" : Overwrite:=true)' % gxxfinaldata) magma.eval('UnsetOutputFile()') # Code adapted from main.mag magma.load('genvectors.mag') magma.load('ries_helper_fn.mag') magma.set('g', genus) magma.set('group_restriction', '"%s"' % groups) magma.set('g0_gt0_compute', '%s' % str(g0_gt0_compute).lower()) magma.set('top_braid_compute', '%s' % str(top_braid_compute).lower()) magma.set('top_braid_g0_gt0', '%s' % str(top_braid_g0_gt0).lower()) magma.set('NotFullList', []) magma.set('prtfile', '"%s"' % supp_gxx) magma.eval('SetColumns(0)') magma.load('SupplementaryFiles/BreuerRaw/g%s' % genus_str) magma.load('generate_ccnums.mag') magma.load(supp_gxx) magma.load(possible_full) magma.load('addl_data.mag') magma.load(full) magma.load(notfull) print('Done computing data for genus %d' % genus) print('Making upload file for genus %d...' % genus) # Read the temporary file containing the computed data so that we can # create the upload file rf = open('g%sfinaldata' % genus_str, 'r') lines = rf.read().splitlines() rf.close() # Separate lines by the delimiter '@' grouped_lines = itertools.groupby(lines, lambda line : line == '@') entries = [list(entry) for is_delim, entry in grouped_lines if not is_delim] # Write column names and types to the upload file cols = [['genus','smallint'], ['total_label','text'], ['passport_label','text'], ['label','text'], ['group','text'], ['group_order','integer'], ['signature','integer[]'], ['g0','smallint'], ['r','smallint'], ['dim','smallint'], ['con','text[]'], ['cc','integer[]'], ['braid','integer[]'], ['topological','integer[]'], ['jacobian_decomp','jsonb'], ['genvec','numeric[]'], ['connected_genvec','text[]'], ['trans_group','text'], ['min_deg','integer'], ['hyperelliptic','boolean'], ['hyp_involution','numeric'], ['eqn','text[]'], ['cyclic_trigonal','boolean'], ['cinv','numeric'], ['full_label','text'], ['full_auto','text'], ['signH','integer[]']] col_names = '|'.join([col[0] for col in cols]) + '\n' col_types = '|'.join([col[1] for col in cols]) + '\n' if groups == 'abel': wf = open('g%s_abelgrps_data.txt' % genus_str, 'w') elif groups == 'nonabel': wf = open('g%s_nonabelgrps_data.txt' % genus_str, 'w') else: # groups == 'all' wf = open('g%s_allgrps_data.txt' % genus_str, 'w') wf.write(col_names) wf.write(col_types) wf.write('\n') # Iterate over each entry of the computed data for entry in entries: f_or_nf = entry[0] group = json.loads(entry[1]) order = group[0] counter = group[1] group_str = '%d.%d' % (order, counter) signature = json.loads(entry[2]) g0 = signature[0] r = len(signature[1:]) dim = 3*g0 + r - 3 con = put_curly_brackets(entry[4]) cc = json.loads(entry[5]) braid = json.loads(entry[6]) if braid == [0,0]: braid = 'NULL' topological = json.loads(entry[7]) if topological == [0,0]: topological = 'NULL' jacobian_decomp = entry[8] genvec = put_curly_brackets(entry[9]) # as a list of integers connected_genvec = entry[11] if connected_genvec == 'Nonsolvable': connected_genvec = 'NULL' else: connected_genvec = put_curly_brackets(connected_genvec) trans_group = entry[12] if trans_group == 'N/A': trans_group = 'NULL' min_deg = entry[13] if min_deg == 'N/A': min_deg = 'NULL' perm_orders = '0' if signature[1:] != []: # cover is ramified perm_orders = '-'.join([str(perm_order) for perm_order in signature[1:]]) label = '%d.%d-%d.%d.%s' % (genus, order, counter, g0, perm_orders) passport_label = '%s.%d' % (label, cc[0]) total_label = '%s.%d' % (passport_label, cc[1]) # Line of data so far line = [genus, total_label, passport_label, label, group_str, order, signature, g0, r, dim, con, cc, braid, topological, jacobian_decomp, genvec, connected_genvec, trans_group, min_deg] line = list(map(convert_to_str, line)) # The format of the entry is different depending on whether or not it # represents a full automorphism group if f_or_nf == 'F': # full automorphism group hy_or_hn = entry[14] hyperelliptic = hy_or_hn == 'HY' if hyperelliptic: hyp_involution = entry[16] # as an integer eqn = put_curly_brackets(entry[17]) line.extend([str(hyperelliptic), hyp_involution, eqn]) else: line.extend([str(hyperelliptic), 'NULL', 'NULL']) cy_or_cn = entry[18] cyclic_trigonal = cy_or_cn == "CY" if cyclic_trigonal: cinv = entry[20] # as an integer line.extend([str(cyclic_trigonal), cinv]) else: line.extend([str(cyclic_trigonal), 'NULL']) # put NULL for full_label, full_auto, signH line.extend(['NULL', 'NULL', 'NULL']) else: # not a full automorphism group # put NULL for hyperelliptic, hyp_involution, eqn, cyclic_trigonal, cinv line.extend(['NULL', 'NULL', 'NULL', 'NULL', 'NULL']) full_auto = json.loads(entry[14]) full_auto_str = '%d.%d' % (full_auto[0], full_auto[1]) signH = json.loads(entry[15]) perm_ordersH = '0' if signH[1:] != []: # cover is ramified perm_ordersH = '-'.join([str(perm_order) for perm_order in signH[1:]]) full_label = '%d.%d-%d.%d.%s' % (genus, full_auto[0], full_auto[1], signH[0], perm_ordersH) line.extend([full_label, full_auto_str, convert_to_str(signH)]) # Finally write the line output = '|'.join(line) + '\n' wf.write(output) # Finished iterating over the entries for the current genus wf.close() print('Done making upload file for genus %d' % genus) # Finished creating upload files for all the specified genera print('Done making all upload files')
def import_data(hmf_filename, fileprefix=None, ferrors=None, test=True): if fileprefix is None: fileprefix = "." hmff = open(os.path.join(fileprefix, hmf_filename)) if ferrors is None: ferrors = open('/home/jvoight/lmfdb/backups/import_data.err', 'a') # Parse field data v = hmff.readline() assert v[:9] == 'COEFFS :=' coeffs = eval(v[10:][:-2]) v = hmff.readline() assert v[:4] == 'n :=' n = int(v[4:][:-2]) v = hmff.readline() assert v[:4] == 'd :=' d = int(v[4:][:-2]) magma.eval('F<w> := NumberField(Polynomial(' + str(coeffs) + '));') magma.eval('ZF := Integers(F);') # Find the corresponding field in the database of number fields dkey = make_disc_key(ZZ(d))[1] sig = "%s,%s" % (n, 0) print("Finding field with signature %s and disc_key %s ..." % (sig, dkey)) fields_matching = fields.find({"disc_abs_key": dkey, "signature": sig}) cnt = fields_matching.count() print("Found %s fields" % cnt) assert cnt >= 1 field_label = None co = str(coeffs)[1:-1].replace(" ", "") for i in range(cnt): nf = next(fields_matching) print("Comparing coeffs %s with %s" % (nf['coeffs'], co)) if nf['coeffs'] == co: field_label = nf['label'] assert field_label is not None print("...found!") # Find the field in the HMF database print("Finding field %s in HMF..." % field_label) F_hmf = hmf_fields.find_one({"label": field_label}) if F_hmf is None: # Create list of ideals print("...adding!") ideals = eval(preparse(magma.eval('nice_idealstr(F);'))) ideals_str = [str(c) for c in ideals] if test: print("Would now insert data for %s into hmf_fields" % field_label) else: hmf_fields.insert({ "label": field_label, "degree": n, "discriminant": d, "ideals": ideals_str }) F_hmf = hmf_fields.find_one({"label": field_label}) else: print("...found!") print("Computing ideals...") ideals_str = F_hmf['ideals'] ideals = [eval(preparse(c)) for c in ideals_str] ideals_norms = [c[0] for c in ideals] magma.eval('ideals_str := [' + ''.join(F_hmf['ideals']).replace('][', '], [') + ']') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') # Add the list of primes print("Computing primes...") v = hmff.readline() # Skip line v = hmff.readline() assert v[:9] == 'PRIMES :=' primes_str = v[10:][:-2] primes_array = [str(t) for t in eval(preparse(primes_str))] magma.eval('primes_array := ' + primes_str) magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_array];') magma.eval('primes_indices := [Index(ideals, pp) : pp in primes];') try: assert magma( '&and[primes_indices[j] gt primes_indices[j-1] : j in [2..#primes_indices]]' ) resort = False except AssertionError: print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Primes reordered!") resort = True magma.eval('_, sigma := Sort(primes_indices, func<x,y | x-y>);') magma.eval( 'perm := [[xx : xx in x] : x in CycleDecomposition(sigma) | #x gt 1]' ) # Check at least they have the same norm magma.eval( 'for tau in perm do assert #{Norm(ideals[primes_indices[t]]) : t in tau} eq 1; end for;' ) primes_resort = eval(magma.eval('Eltseq(sigma)')) primes_resort = [c - 1 for c in primes_resort] primes_indices = eval(magma.eval('primes_indices')) primes_str = [ideals_str[j - 1] for j in primes_indices] assert len(primes_array) == len(primes_str) print("...comparing...") for i in range(len(primes_array)): assert magma('ideal<ZF | {F!x : x in ' + primes_array[i] + '}> eq ' + 'ideal<ZF | {F!x : x in ' + primes_str[i] + '}>;') if resort: # Important also to resort the list of primes themselves! # not just the a_pp's primes_str = [primes_str[i] for i in primes_resort] if 'primes' in F_hmf: # Nothing smart: make sure it is the same assert F_hmf['primes'] == primes_str else: F_hmf['primes'] = primes_str if test: print("Would now save primes string %s... into hmf_fields" % primes_str[:100]) else: hmf_fields.save(F_hmf) print("...saved!") # Collect levels v = hmff.readline() if v[:9] == 'LEVELS :=': # Skip this line since we do not use the list of levels v = hmff.readline() for i in range(3): if v[:11] != 'NEWFORMS :=': v = hmff.readline() else: break # Finally, newforms! print("Starting newforms!") while v != '': v = hmff.readline()[1:-3] if len(v) == 0: break data = eval(preparse(v)) level_ideal = data[0] level_norm = data[0][0] label_suffix = data[1] weight = [2 for i in range(n)] level_ind = int( magma('Index(ideals, ideal<ZF | {F!x : x in ' + str(level_ideal) + '}>)')) - 1 # Magma counts starting at 1 level_ideal = ideals_str[level_ind] assert magma('ideal<ZF | {F!x : x in ' + str(level_ideal) + '}> eq ' + 'ideal<ZF | {F!x : x in ' + str(data[0]) + '}>;') level_dotlabel = level_ind - ideals_norms.index( level_norm) + 1 # Start counting at 1 assert level_dotlabel > 0 level_label = str(level_norm) + '.' + str(level_dotlabel) label = construct_full_label(field_label, weight, level_label, label_suffix) short_label = level_label + '-' + label_suffix if len(data) == 3: hecke_polynomial = x hecke_eigenvalues = data[2] else: hecke_polynomial = data[2] hecke_eigenvalues = data[3] if resort: hecke_eigenvalues = [hecke_eigenvalues[i] for i in primes_resort] # Sort out Atkin-Lehner involutions magma.eval('NN := ideal<ZF | {F!x : x in ' + str(level_ideal) + '}>;') magma.eval('NNfact := Factorization(NN);') ALind = eval( preparse( magma.eval( '[Index(primes, pp[1])-1 : pp in NNfact | Index(primes,pp[1]) gt 0];' ))) AL_eigsin = [hecke_eigenvalues[c] for c in ALind] try: assert all([abs(int(c)) <= 1 for c in AL_eigsin]) except Exception: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') AL_eigenvalues = [] ees = eval(preparse(magma.eval('[pp[2] : pp in NNfact]'))) for i in range(len(AL_eigsin)): if ees[i] >= 2: if hecke_eigenvalues[ALind[i]] != 0: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') else: try: if abs(int(AL_eigsin[i])) != 1: ferrors.write( str(n) + '/' + str(d) + ' ' + label + '\n') else: AL_eigenvalues.append( [primes_str[ALind[i]], -AL_eigsin[i]]) except TypeError: ferrors.write(str(n) + '/' + str(d) + ' ' + label + '\n') assert magma( '[Valuation(NN, ideal<ZF | {F!x : x in a}>) gt 0 : a in [' + str(''.join([a[0] for a in AL_eigenvalues])).replace('][', '], [') + ']];') # Constrain eigenvalues to size 2MB hecke_eigenvalues = [str(c) for c in hecke_eigenvalues] leftout = 0 while sum([len(s) for s in hecke_eigenvalues]) > 2000000: leftout += 1 hecke_eigenvalues = hecke_eigenvalues[:-1] if leftout > 0: print("Left out", leftout) info = { "label": label, "short_label": short_label, "field_label": field_label, "level_norm": int(level_norm), "level_ideal": str(level_ideal), "level_label": level_label, "weight": str(weight), "label_suffix": label_suffix, "dimension": hecke_polynomial.degree(), "hecke_polynomial": str(hecke_polynomial), "hecke_eigenvalues": hecke_eigenvalues, "AL_eigenvalues": [[str(a[0]), str(a[1])] for a in AL_eigenvalues] } print(info['label']) existing_forms = hmf_forms.find({"label": label}) assert existing_forms.count() <= 1 if existing_forms.count() == 0: if test: print("Would now insert form data %s into hmf_forms" % info) else: hmf_forms.insert(info) else: existing_form = next(existing_forms) assert info['hecke_polynomial'] == existing_form[ 'hecke_polynomial'] try: assert info['hecke_eigenvalues'] == existing_form[ 'hecke_eigenvalues'] print("...duplicate") except AssertionError: print( "...Hecke eigenvalues do not match! Checking for permutation" ) assert set(info['hecke_eigenvalues'] + ['0', '1', '-1']) == set( existing_form['hecke_eigenvalues'] + [u'0', u'1', u'-1']) # Add 0,1,-1 to allow for Atkin-Lehner eigenvalues, if not computed print("As sets, ignoring 0,1,-1, the eigenvalues match!") if test: print("Would now replace permuted form data %s with %s" % (existing_form, info)) else: existing_form['hecke_eigenvalues'] = info[ 'hecke_eigenvalues'] hmf_forms.save(existing_form)
from lmfdb.base import getDBConnection print "getting connection" C= getDBConnection() C['admin'].authenticate('lmfdb', 'lmfdb') # read-only import yaml pw_dict = yaml.load(open(os.path.join(os.getcwd(), os.extsep, os.extsep, os.extsep, "passwords.yaml"))) username = pw_dict['data']['username'] password = pw_dict['data']['password'] C['hmfs'].authenticate(username, password) hmf_forms = C.hmfs.forms hmf_fields = C.hmfs.fields fields = C.numberfields.fields magma.eval('nice_idealstr := function(F : Bound := 10000); idealsstr := []; ideals := IdealsUpTo(Bound, F); for I in ideals do bl, g := IsPrincipal(I); if bl then s := Sprintf("[%o, %o, %o]", Norm(I), Minimum(I), F!g); else zs := Generators(I); z := zs[#zs]; m := Minimum(I); z := F![(Integers()!c) mod m : c in Eltseq(F!z)]; assert ideal<Integers(F) | [m, z]> eq I; s := Sprintf("[%o, %o, %o]", Norm(I), m, z); end if; Append(~idealsstr, s); end for; return idealsstr; end function;') from lmfdb.number_fields.number_field import make_disc_key from lmfdb.hilbert_modular_forms.web_HMF import construct_full_label P = sage.rings.polynomial.polynomial_ring_constructor.PolynomialRing(sage.rings.rational_field.RationalField(), 3, ['w', 'e', 'x']) w, e, x = P.gens() def import_all_data(n, fileprefix=None, ferrors=None, test=True): nstr = str(n) if fileprefix == None: fileprefix = "/home/jvoight/Elements/ModFrmHilDatav1/Data/" + nstr + "/dir.tmp" ff = open(fileprefix, 'r') files = ff.readlines() files = [f[:-1] for f in files]
def import_data(hmf_filename, fileprefix=None, ferrors=None, test=True): if fileprefix == None: fileprefix = "." hmff = file(os.path.join(fileprefix, hmf_filename)) if ferrors == None: if Dan_test: ferrors = file( '/Users/d_yasaki/repos/lmfdb/lmfdb/scripts/hmf/fixing-permuted-primes/import_data.err', 'a') else: ferrors = file('/home/jvoight/lmfdb/backups/import_data.err', 'a') # Parse field data v = hmff.readline() assert v[:9] == 'COEFFS :=' coeffs = eval(v[10:][:-2]) v = hmff.readline() assert v[:4] == 'n :=' n = int(v[4:][:-2]) v = hmff.readline() assert v[:4] == 'd :=' d = int(v[4:][:-2]) magma.eval('F<w> := NumberField(Polynomial(' + str(coeffs) + '));') magma.eval('ZF := Integers(F);') # Find the corresponding field in the database of number fields dkey = make_disc_key(ZZ(d))[1] sig = "%s,%s" % (n, 0) print("Finding field with signature %s and disc_key %s ..." % (sig, dkey)) fields_matching = fields.find({"disc_abs_key": dkey, "signature": sig}) cnt = fields_matching.count() print("Found %s fields" % cnt) assert cnt >= 1 field_label = None co = str(coeffs)[1:-1].replace(" ", "") for i in range(cnt): nf = fields_matching.next() print("Comparing coeffs %s with %s" % (nf['coeffs'], co)) if nf['coeffs'] == co: field_label = nf['label'] assert field_label is not None print "...found!" # Find the field in the HMF database print("Finding field %s in HMF..." % field_label) F_hmf = hmf_fields.find_one({"label": field_label}) if Dan_test: assert F_hmf is not None # Assuming the hmf field is already there! if F_hmf is None: # Create list of ideals print "...adding!" ideals = eval(preparse(magma.eval('nice_idealstr(F);'))) ideals_str = [str(c) for c in ideals] if test: print("Would now insert data for %s into hmf_fields" % field_label) else: hmf_fields.insert_one({ "label": field_label, "degree": n, "discriminant": d, "ideals": ideals_str }) F_hmf = hmf_fields.find_one({"label": field_label}) else: print "...found!" print "Computing ideals..." ideals_str = F_hmf['ideals'] ideals = [eval(preparse(c)) for c in ideals_str] ideals_norms = [c[0] for c in ideals] magma.eval('ideals_str := [' + ''.join(F_hmf['ideals']).replace('][', '], [') + ']') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') # Add the list of primes print "Computing primes..." v = hmff.readline() # Skip line v = hmff.readline() assert v[:9] == 'PRIMES :=' primes_str = v[10:][:-2] primes_array = [str(t) for t in eval(preparse(primes_str))] magma.eval('primes_array := ' + primes_str) magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_array];') magma.eval('primes_indices := [Index(ideals, pp) : pp in primes];') try: assert magma( '&and[primes_indices[j] gt primes_indices[j-1] : j in [2..#primes_indices]]' ) resort = False except AssertionError: print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Primes reordered!" resort = True magma.eval('_, sigma := Sort(primes_indices, func<x,y | x-y>);') magma.eval( 'perm := [[xx : xx in x] : x in CycleDecomposition(sigma) | #x gt 1]' ) # Check at least they have the same norm magma.eval( 'for tau in perm do assert #{Norm(ideals[primes_indices[t]]) : t in tau} eq 1; end for;' ) primes_resort = eval(magma.eval('Eltseq(sigma)')) primes_resort = [c - 1 for c in primes_resort] primes_indices = eval(magma.eval('primes_indices')) primes_str = [ideals_str[j - 1] for j in primes_indices] assert len(primes_array) == len(primes_str) print "...comparing..." for i in range(len(primes_array)): assert magma('ideal<ZF | {F!x : x in ' + primes_array[i] + '}> eq ' + 'ideal<ZF | {F!x : x in ' + primes_str[i] + '}>;') if resort: # Important also to resort the list of primes themselves! # not just the a_pp's primes_str = [primes_str[i] for i in primes_resort] if Dan_test: assert 'primes' in F_hmf # DY: want to make sure the fields are not touched! if 'primes' in F_hmf: # Nothing smart: make sure it is the same assert F_hmf['primes'] == primes_str else: F_hmf['primes'] = primes_str if test: print("Would now save primes string %s... into hmf_fields" % primes_str[:100]) else: hmf_fields.replace_one(F_hmf) print "...saved!" # Collect levels v = hmff.readline() if v[:9] == 'LEVELS :=': # Skip this line since we do not use the list of levels v = hmff.readline() for i in range(3): if v[:11] != 'NEWFORMS :=': v = hmff.readline() else: break # Finally, newforms! print "Starting newforms!" while v != '': v = hmff.readline()[1:-3] if len(v) == 0: break data = eval(preparse(v)) level_ideal = data[0] level_norm = data[0][0] label_suffix = fix_one_label(data[1]) weight = [2 for i in range(n)] label_nsuffix = class_to_int(label_suffix) level_ind = int( magma('Index(ideals, ideal<ZF | {F!x : x in ' + str(level_ideal) + '}>)')) - 1 # Magma counts starting at 1 level_ideal = ideals_str[level_ind] assert magma('ideal<ZF | {F!x : x in ' + str(level_ideal) + '}> eq ' + 'ideal<ZF | {F!x : x in ' + str(data[0]) + '}>;') level_dotlabel = level_ind - ideals_norms.index( level_norm) + 1 # Start counting at 1 assert level_dotlabel > 0 level_label = str(level_norm) + '.' + str(level_dotlabel) label = construct_full_label(field_label, weight, level_label, label_suffix) short_label = level_label + '-' + label_suffix if len(data) == 3: hecke_polynomial = x hecke_eigenvalues = data[2] else: hecke_polynomial = data[2] hecke_eigenvalues = data[3] if resort: hecke_eigenvalues = [hecke_eigenvalues[i] for i in primes_resort] # Constrain eigenvalues to size 2MB hecke_eigenvalues = [str(c) for c in hecke_eigenvalues] leftout = 0 while sum([len(s) for s in hecke_eigenvalues]) > 2000000: hecke_eigenvalues = hecke_eigenvalues[:-1] leftout += 1 # commented code below throws an error. use above. # just be safe and remove one eigenvalue at a time. # Aurel's code will adjust and remove extra when needed. #q = primes_resort[len(hecke_eigenvalues)] #while primes_resort[len(hecke_eigenvalues)] == q: # # Remove all with same norm # leftout += 1 # hecke_eigenvalues = hecke_eigenvalues[:-1] if leftout > 0: print "Left out", leftout info = { "label": label, "short_label": short_label, "field_label": field_label, "level_norm": int(level_norm), "level_ideal": str(level_ideal), "level_label": level_label, "weight": str(weight), "label_suffix": label_suffix, "label_nsuffix": label_nsuffix, "dimension": hecke_polynomial.degree(), "hecke_polynomial": str(hecke_polynomial), "hecke_eigenvalues": hecke_eigenvalues } # DY: don't deal with AL right now. #, #"AL_eigenvalues": [[str(a[0]), str(a[1])] for a in AL_eigenvalues]} print info['label'] existing_forms = hmf_forms.find({"label": label}) assert existing_forms.count() <= 1 if existing_forms.count() == 0: if test: print("Would now insert form data %s into hmf_forms" % info) else: hmf_forms.insert_one(info) else: existing_form = existing_forms.next() assert info['hecke_polynomial'] == existing_form[ 'hecke_polynomial'] try: assert info['hecke_eigenvalues'] == existing_form[ 'hecke_eigenvalues'] print "...duplicate" except AssertionError: print "...Hecke eigenvalues do not match! Checking for permutation" assert set(info['hecke_eigenvalues'] + ['0', '1', '-1']) == set( existing_form['hecke_eigenvalues'] + [u'0', u'1', u'-1']) # Add 0,1,-1 to allow for Atkin-Lehner eigenvalues, if not computed print "As sets, ignoring 0,1,-1, the eigenvalues match!" if test: print("Would now replace permuted form data %s with %s" % (existing_form, info)) else: existing_form['hecke_eigenvalues'] = info[ 'hecke_eigenvalues'] hmf_forms.save(existing_form)
def recompute_AL(): field_label = None S = hmf_forms.find({}) S = S.sort("label") while True: v = S.next() NN_label = v["level_label"] v_label = v["label"] try: if v["AL_eigenvalues_fixed"] == 'done' or v["AL_eigenvalues_fixed"] == 'working': continue except KeyError: print v_label print "...new, computing!" v["AL_eigenvalues_fixed"] = 'working' hmf_forms.save(v) if field_label is None or not field_label == v["field_label"]: field_label = v["field_label"] print "...new field " + field_label F = fields.find_one({"label": field_label}) F_hmf = hmf_fields.find_one({"label": field_label}) magma.eval('P<x> := PolynomialRing(Rationals());') magma.eval('F<w> := NumberField(Polynomial(' + str(F["coefficients"]) + '));') magma.eval('ZF := Integers(F);') magma.eval('ideals_str := [' + ','.join([st for st in F_hmf["ideals"]]) + '];') magma.eval('ideals := [ideal<ZF | {F!x : x in I}> : I in ideals_str];') magma.eval('primes_str := [' + ','.join([st for st in F_hmf["primes"]]) + '];') magma.eval('primes := [ideal<ZF | {F!x : x in I}> : I in primes_str];') NN_index = NN_label[NN_label.index('.') + 1:] magma.eval( 'NN := [I : I in ideals | Norm(I) eq ' + str(v["level_norm"]) + '][' + str(NN_index) + '];') magma.eval('M := HilbertCuspForms(F, NN);') if v["hecke_polynomial"] != 'x': magma.eval('K<e> := NumberField(' + v["hecke_polynomial"] + ');') else: magma.eval('K := Rationals(); e := 1;') magma.eval('hecke_eigenvalues := [' + ','.join([st for st in v["hecke_eigenvalues"]]) + '];') print "...Hecke eigenvalues loaded..." magma.eval('s := 0; KT := []; ' 'while KT cmpeq [] or Dimension(KT) gt 1 do ' ' s +:= 1; ' ' pp := primes[s]; ' ' if Valuation(NN, pp) eq 0 then ' ' T_pp := HeckeOperator(M, pp); ' ' a_pp := hecke_eigenvalues[s]; ' ' if KT cmpeq [] then ' ' KT := Kernel(ChangeRing(Matrix(T_pp),K)-a_pp); ' ' else ' ' KT := KT meet Kernel(ChangeRing(Matrix(T_pp),K)-a_pp); ' ' end if; ' ' end if; ' 'end while;') magma.eval('assert Dimension(KT) eq 1;') print "...dimension 1 subspace found..." magma.eval('NNfact := Factorization(NN);') magma.eval('f := Vector(Basis(KT)[1]); ' 'AL_eigenvalues := []; ' 'for pp in NNfact do ' ' U_ppf := f*ChangeRing(AtkinLehnerOperator(M, pp[1]),K); ' ' assert U_ppf eq f or U_ppf eq -f; ' ' if U_ppf eq f then ' ' Append(~AL_eigenvalues, 1); ' ' else ' ' Append(~AL_eigenvalues, -1); ' ' end if; ' 'end for;') # ' T_ppf := f*ChangeRing(HeckeOperator(M, pp[1]),K); '\ # ' if pp[2] ge 2 then assert T_ppf eq 0*f; else assert T_ppf eq -U_ppf; end if; '\ print "...AL eigenvalues computed!" AL_ind = eval(preparse(magma.eval('[Index(primes,pp[1])-1 : pp in NNfact]'))) AL_eigenvalues_jv = eval(preparse(magma.eval('AL_eigenvalues'))) AL_eigenvalues = [[F_hmf["primes"][AL_ind[i]], AL_eigenvalues_jv[i]] for i in range(len(AL_ind))] pps_exps = eval(preparse(magma.eval('[pp[2] : pp in NNfact]'))) hecke_eigenvalues = v["hecke_eigenvalues"] for j in range(len(AL_ind)): s = AL_ind[j] if pps_exps[j] >= 2: hecke_eigenvalues[s] = '0' else: hecke_eigenvalues[s] = str(-AL_eigenvalues[j][1]) AL_eigenvalues = [[a[0], str(a[1])] for a in AL_eigenvalues] v["hecke_eigenvalues"] = hecke_eigenvalues v["AL_eigenvalues"] = AL_eigenvalues v["AL_eigenvalues_fixed"] = 'done' hmf_forms.save(v)