def reduce_ap_mod_ell(nf, red, verbose=False): """Input: a newform and one reduction map to GF(ell) for some ell Output: a list of pairs (p,a_p mod ell) for the prime index q-expansion coefficients a_p of the newform. """ if verbose: print("Reducing {} mod ell via {}".format(nf.label, red)) for i,p in enumerate(primes_first_n(10)): ap = nf.ap[i] print("p={}, ap={}, ap mod ell = {}".format(p, ap, apply_red(ap, red))) return dict([(p,apply_red(nf.ap[i], red)) for i,p in enumerate(primes_first_n(len(nf.ap)))])
def check_all_files(filename, linecount, chunk = 100): k = 0 base_dir = os.path.dirname(os.path.abspath(filename)) lfun_dir = os.path.join(base_dir, 'lfun') inputs_dir = os.path.join(base_dir, 'inputs') inputs = {} with open(filename, 'r') as F: for line in F: linesplit = line[:-1].split(':') hoc, label, conrey_label_tmp, embedding_index_tmp, embedding_m, ap_txt = linesplit lpdatafilename = os.path.join(lfun_dir, label + ".lpdata") lfunfilename = os.path.join(lfun_dir, label + ".lpdata.lfunction") if not os.path.exists(lpdatafilename): print "%s\tMissing lpdata file: %s" % (label, lpdatafilename) print "Use generate_lpdata_and_inputs.py to generate those files" sys.exit(1) if not os.path.exists(lfunfilename): print "%s\tMissing lfunction file: for %s" % (label, lfunfilename) # reading the line level, weight, char_orbit, hecke_orbit, conrey_label, embedding_index = label.split(".") level, weight, conrey_label, embedding_index = map(int, [level, weight, conrey_label, embedding_index]) ap_list = [ toCCC(*elt.split(',')) for elt in ap_txt[2:-2].split('],[')] ap_list = zip(primes_first_n(len(ap_list)),ap_list) G = DirichletGroup_conrey(level, CCC) char = DirichletCharacter_conrey(G, conrey_label) if weight not in inputs: inputs[weight] = [] inputs[weight].append("%d %d %d %s %s" % (weight, self_dual(char, ap_list) , level, label, lpdatafilename)) k += 1 if linecount > 10: if (k % (linecount//10)) == 0: print "check_all_files %.2f%% done" % (k*100./linecount) if len(inputs) > 0: real_filename = os.path.abspath(filename).split('/')[-1] parallel_inputs = os.path.join(base_dir, real_filename + '.tsv.missing') with open(parallel_inputs, 'w') as I: for weight, lines in inputs.iteritems(): if chunk is None: chunked_lines = [lines] else: chunked_lines = [ lines[i:i+chunk] for i in range(0, len(lines), chunk)] assert sum(map(len, chunked_lines)) == len(lines), "%d != %d" % (sum(map(len, chunked_lines)), len(lines)) for i, line_block in enumerate(chunked_lines): inputsfilename = os.path.join(inputs_dir, real_filename + '_wt%d_%d.missing.input' % (weight, i)) with open(inputsfilename , 'w') as W: W.write('\n'.join(line_block) + '\n') #print "wrote %d lines to %s" % (len(line_block), inputsfilename) I.write("%d\t%s\n" % (weight, inputsfilename)) print "There were some missing lfunction files!" print "please set LFUNCTIONS and run:" print r"""parallel -a %s --colsep '\t' --progress ${LFUNCTIONS}/euler_factors 11 200 ${LFUNCTIONS}/gamma_files/mf.{1} {2} 100""" % (parallel_inputs,) sys.exit(1) print "check_all_files done" return None
def init_dynamic_properties(self): emf_logger.debug("E = {0}".format(self.E)) if not self.E is None and not self.v is None: c = multiply_mat_vec(self.E,self.v) lc = len(c) primes_to_lc = primes_first_n(lc) self._ap = {} for i in range(len(c)): p = primes_to_lc[i] self._ap[p] = c[i] else: self._ap = {}
def dirichlet(R, euler_factors): PS = PowerSeriesRing(R) pef = zip(primes_first_n(len(euler_factors)), euler_factors) an_list_bound = next_prime(pef[-1][0]) res = [1]*an_list_bound for p, ef in pef: k = RR(an_list_bound).log(p).floor()+1 foo = (1/PS(ef)).padded_list(k) for i in range(1, k): res[p**i] = foo[i] extend_multiplicatively(res) return res
def init_dynamic_properties(self): emf_logger.debug("E = {0}".format(self.E)) if not self.E is None and not self.v is None: c = multiply_mat_vec(self.E, self.v) lc = len(c) primes_to_lc = primes_first_n(lc) self._ap = {} for i in range(len(c)): p = primes_to_lc[i] self._ap[p] = c[i] self.prec = self._ap.keys()[len(self._ap) - 1] else: self._ap = {}
def lfuncEPhtml(L,fmt, prec = None): """ Euler product as a formula and a table of local factors. """ # Formula texform_gen = "\[L(s) = " # "\[L(A,s) = " texform_gen += "\prod_{p \\text{ prime}} F_p(p^{-s})^{-1} \]\n" pfactors = prime_divisors(L.level) if len(pfactors) == 0: pgoodset = None pbadset = None elif len(pfactors) == 1: #i.e., the conductor is prime pgoodset = "$p \\neq " + str(pfactors[0]) + "$" pbadset = "$p = " + str(pfactors[0]) + "$" else: badset = "\\{" + str(pfactors[0]) for j in range(1,len(pfactors)): badset += ",\\;" badset += str(pfactors[j]) badset += "\\}" pgoodset = "$p \\notin " + badset + "$" pbadset = "$p \\in " + badset + "$" ans = "" ans += texform_gen + "where" if pgoodset is not None: ans += ", for " + pgoodset ans += ",\n" if L.motivic_weight == 1 and L.characternumber == 1 and L.degree in [2,4]: if L.degree == 4: ans += "\[F_p(T) = 1 - a_p T + b_p T^2 - a_p p T^3 + p^2 T^4 \]" ans += "with $b_p = a_p^2 - a_{p^2}$. " elif L.degree == 2: ans += "\[F_p(T) = 1 - a_p T + p T^2 .\]" else: ans += "\(F_p\) is a polynomial of degree " + str(L.degree) + ". " if pbadset is not None: ans += "If " + pbadset + ", then $F_p$ is a polynomial of degree at most " ans += str(L.degree - 1) + ". " # Figuring out good and bad primes bad_primes = [] for lf in L.bad_lfactors: bad_primes.append(lf[0]) eulerlim = 25 good_primes = [] for p in primes_first_n(eulerlim): if p not in bad_primes: good_primes.append(p) #decide if we display galois display_galois = True if L.degree <= 2 or L.degree >= 12: display_galois = False if L.coefficient_field == "CDF": display_galois = False def pretty_poly(poly, prec = None): out = "1" for i,elt in enumerate(poly): if elt is None or (i == prec and prec != len(poly) - 1): out += "O(%s)" % (seriesvar(i, "polynomial"),) break; elif i > 0: out += seriescoeff(elt, i, "series", "polynomial", 3) return out eptable = r"""<div style="max-width: 100%; overflow-x: auto;">""" eptable += "<table class='ntdata euler'>\n" eptable += "<thead>" eptable += "<tr class='space'><th class='weight'></th><th class='weight'>$p$</th>" if L.degree > 2 and L.degree < 12: display_galois = True eptable += "<th class='weight galois'>$\Gal(F_p)$</th>" else: display_galois = False eptable += r"""<th class='weight' style="text-align: left;">$F_p$</th>""" eptable += "</tr>\n" eptable += "</thead>" def row(trclass, goodorbad, p, poly): out = "" try: if L.coefficient_field == "CDF" or None in poly: factors = str(pretty_poly(poly, prec = prec)) elif not display_galois: factors = list_to_factored_poly_otherorder(poly, galois=display_galois, prec = prec, p = p) else: factors, gal_groups = list_to_factored_poly_otherorder(poly, galois=display_galois, p = p) out += "<tr" + trclass + "><td>" + goodorbad + "</td><td>" + str(p) + "</td>"; if display_galois: out += "<td class='galois'>" if gal_groups[0]==[0,0]: pass # do nothing, because the local faco is 1 elif gal_groups[0]==[1,1]: out += group_display_knowl(gal_groups[0][0], gal_groups[0][1],'$C_1$') else: out += group_display_knowl(gal_groups[0][0], gal_groups[0][1]) for n, k in gal_groups[1:]: out += "$\\times$" out += group_display_knowl(n, k) out += "</td>" out += "<td>" +"$" + factors + "$" + "</td>" out += "</tr>\n" except IndexError: out += "<tr><td></td><td>" + str(j) + "</td><td>" + "not available" + "</td></tr>\n" return out goodorbad = "bad" trclass = "" for lf in L.bad_lfactors: eptable += row(trclass, goodorbad, lf[0], lf[1]) goodorbad = "" trclass = "" goodorbad = "good" trclass = " class='first'" good_primes1 = good_primes[:9] good_primes2 = good_primes[9:] for j in good_primes1: this_prime_index = prime_pi(j) - 1 eptable += row(trclass, goodorbad, j, L.localfactors[this_prime_index]) goodorbad = "" trclass = "" trclass = " id='moreep' class='more nodisplay'" for j in good_primes2: this_prime_index = prime_pi(j) - 1 eptable += row(trclass, goodorbad, j, L.localfactors[this_prime_index]) trclass = " class='more nodisplay'" eptable += r"""<tr class="less toggle"><td colspan="2"> <a onclick="show_moreless("more"); return true" href="#moreep">show more</a></td>""" last_entry = "" if display_galois: last_entry +="<td></td>" last_entry += "<td></td>" eptable += last_entry eptable += "</tr>" eptable += r"""<tr class="more toggle nodisplay"><td colspan="2"><a onclick="show_moreless("less"); return true" href="#eptable">show less</a></td>""" eptable += last_entry eptable += "</tr>\n</table>\n</div>\n" ans += "\n" + eptable return(ans)
def read_all(filename): # label -> [p, Lp] euler_factors_cc = {} # label -> labels orbits = {} # label -> postgres row as list rows = {} instances = {} base_dir = os.path.dirname(os.path.abspath(filename)) lfun_dir = os.path.join(base_dir, 'lfun') linecount = line_count(filename) check_all_files(filename, linecount) k = 0 with open(filename, 'r') as F: for line in F: linesplit = line[:-1].split(':') hoc, label, conrey_label_tmp, embedding_index_tmp, embedding_m, ap_txt = linesplit level, weight, char_orbit, hecke_orbit, conrey_label, embedding_index = label.split(".") assert conrey_label_tmp == conrey_label assert embedding_index_tmp == embedding_index mf_orbit_label = ".".join([level, weight, char_orbit, hecke_orbit]) if mf_orbit_label not in orbits: orbits[mf_orbit_label] = [] orbits[mf_orbit_label].append(label) ap_list = [ toCCC(*elt.split(',')) for elt in ap_txt[2:-2].split('],[')] ap_list = zip(primes_first_n(len(ap_list)),ap_list) lpfilename = os.path.join(lfun_dir, label + ".lpdata") lffilename = os.path.join(lfun_dir, label + ".lpdata.lfunction") if not all(map(os.path.exists, [lpfilename, lffilename])): continue level, weight, conrey_label, embedding_index = map(int, [level, weight, conrey_label, embedding_index]) G = DirichletGroup_conrey(level, CCC) char = DirichletCharacter_conrey(G, conrey_label) # the basis row = constant_lf(level, weight, 2) row['origin'] = "ModularForm/GL2/Q/holomorphic/%d/%d/%s/%s/%d/%d" % (level, weight, char_orbit, hecke_orbit, conrey_label, embedding_index) row['self_dual'] = self_dual(char, ap_list) row['central_character'] = "%s.%s" % (level, conrey_label) # sets accuracy, root_number, sign_arg, leading_term, order_of_vanishing, positive_zeros, plot_delta, plot_values for key, val in read_lfunction_file(lffilename).iteritems(): row[key] = val if row['self_dual']: row['conjugate'] = '\N' else: lfconjfilename= os.path.join(lfun_dir, label + ".lpdata.conj.lfunction") assert os.path.exists(lfconjfilename) row['conjugate'] = read_lfunction_file(lfconjfilename)['Lhash'] def euler_factor(p, ap): if p.divides(level): return [1, -ap] charval = CCC(2*char.logvalue(p)).exppii() if charval.contains_exact(ZZ(1)): charval = 1 elif charval.contains_exact(ZZ(-1)): charval = -1 return [1, -ap, (p**(weight-1))*charval] cut = 30 if level == 1 else max(30, prime_pi(max(prime_divisors(level)))) euler_factors = [ euler_factor(*elt) for elt in ap_list[:cut] ] bad_euler_factors = [ [elt[0], euler_factor(*elt)] for elt in ap_list if elt[0].divides(level)] euler_factors_cc[label] = euler_factors row['euler_factors'] = map( lambda x : map(CBF_to_pair, x), euler_factors) row['bad_lfactors'] = map( lambda x: [int(x[0]), map(CBF_to_pair, x[1])], bad_euler_factors) row['coefficient_field'] = 'CDF' for i, ai in enumerate(dirichlet(CCC, euler_factors[:11])[2:12]): if i + 2 <= 10: row['a' + str(i+2)] = CBF_to_pair(ai) for key in schema_lf: assert key in row, "%s not in row = %s" % (key, row) assert len(row) == len(schema_lf), "%s != %s" % (len(row) , len(schema_lf)) rows[label] = [row[key] for key in schema_lf] instances[label] = (row['origin'], row['Lhash'], 'CMF') k += 1 if linecount > 10: if (k % (linecount//10)) == 0: print "read_all %.2f%% done" % (k*100./linecount) print "read_all Done" rational_rows = populate_rational_rows(orbits, euler_factors_cc, rows, instances) positive_zeros = schema_lf_dict['positive_zeros'] for elt, val in rows.iteritems(): assert isinstance(val[positive_zeros], str), "%s, %s, %s" % (elt, type(val[positive_zeros]), val[positive_zeros]) lfun_filename = filename + ".lfunctions" instances_filename = filename + ".instances" export_lfunctions(rows, rational_rows, instances, lfun_filename, instances_filename) return 0
def rational_euler_factors(euler_factors_cc, level, weight, an_list_bound = 11): dirichlet = [1]*an_list_bound dirichlet[0] = 0 euler_factors = [] bad_lfactors = [] halfdegree = len(euler_factors_cc) PS = PowerSeriesRing(ZZ, "X") CCCx = PolynomialRing(CCC, "x") todo = list(enumerate(primes_first_n(30))) for p in sorted(ZZ(level).prime_divisors()): p_index = prime_pi(p) - 1 if p_index >= 30: todo.append((p_index, p)) for p_index, p in todo: if p_index >= len(euler_factors_cc[0]): assert level % p == 0, "%s, %s, %s" % (level, weight, len(euler_factors_cc)) bad_lfactors.append([int(p), [int(1)] + [None]*halfdegree]) continue #try to guess the rest by multiplying them roots = [] for lf in euler_factors_cc: roots += reciprocal_roots(lf[p_index]) root_powers = [None] * (halfdegree + 1) for j in range(1,halfdegree + 1): try: root_powers[j] = RRR(sum( map(lambda z: (z**j).real(), roots) )).unique_integer() except ValueError: root_powers = root_powers[:j] break partial_efzz = from_power_sums(root_powers) efzz = map(int, partial_efzz) + [None]*(halfdegree +1 - len(partial_efzz)) # to check that from_power_sums is correct ef = prod([CCCx(lf[p_index]) for lf in euler_factors_cc]) for j, elt in enumerate(ef.list()[:len(partial_efzz)]): try: efj = int(RRR(elt.real()).unique_integer()) except ValueError: #print j #print RRR(elt.real()) #print p #print "[%s]" % (", ".join(["[%s]" % (", ".join(map(print_CCC, lf[p_index]))) for ef in euler_factors_cc])) #assert False break; assert efj == efzz[j], "%s, %s, %s, %s != %s" % (level, weight, len(euler_factors_cc), efj, efzz[j]) if (level % p) != 0: sign = RRR(ef.list()[-1].real()/p**((halfdegree)*(weight - 1))).unique_integer() assert sign in [1,-1], "%s\n%s" % (RRR(prod( lf[p_index][2] for lf in euler_factors_cc).real()).unique_integer(),p**((halfdegree)*(weight - 1))) efzz2 = [None] * halfdegree for i, elt in enumerate(reversed(efzz[:-1])): if elt is None: efzz2[i] = None else: efzz2[i] = int(sign*p**((i+1)*(weight - 1)) * elt) efzz += efzz2 euler_factors.append(efzz) else: if None not in efzz: k = len(efzz) while efzz[k - 1] == 0 and k >= 1: k -= 1 efzz = efzz[:k] bad_lfactors.append([int(p), efzz]) if p_index < 30: euler_factors.append(efzz) if p < an_list_bound: k = RR(an_list_bound).log(p).floor()+1 foo = (1/PS(efzz)).padded_list(k) for i in range(1, k): dirichlet[p**i] = foo[i] extend_multiplicatively(dirichlet) assert len(euler_factors) == 30, "%s, %s, %s, %s != 30" % (level, weight, len(euler_factors_cc), len(euler_factors)) return euler_factors, bad_lfactors, dirichlet
def read_aps(ap_txt): ap_list = [ toCCC(*elt.split(',')) for elt in ap_txt[2:-2].split('],[')] return zip(primes_first_n(len(ap_list)),ap_list)
def lfuncEPhtml(L, fmt, prec=None): """ Euler product as a formula and a table of local factors. """ # Formula texform_gen = "\[L(s) = " # "\[L(A,s) = " texform_gen += "\prod_{p \\text{ prime}} F_p(p^{-s})^{-1} \]\n" pfactors = prime_divisors(L.level) if len(pfactors) == 0: pgoodset = None pbadset = None elif len(pfactors) == 1: #i.e., the conductor is prime pgoodset = "$p \\neq " + str(pfactors[0]) + "$" pbadset = "$p = " + str(pfactors[0]) + "$" else: badset = "\\{" + str(pfactors[0]) for j in range(1, len(pfactors)): badset += ",\\;" badset += str(pfactors[j]) badset += "\\}" pgoodset = "$p \\notin " + badset + "$" pbadset = "$p \\in " + badset + "$" ans = "" ans += texform_gen + "where" if pgoodset is not None: ans += ", for " + pgoodset ans += ",\n" if L.motivic_weight == 1 and L.characternumber == 1 and L.degree in [2, 4]: if L.degree == 4: ans += "\[F_p(T) = 1 - a_p T + b_p T^2 - a_p p T^3 + p^2 T^4 \]" ans += "with $b_p = a_p^2 - a_{p^2}$. " elif L.degree == 2: ans += "\[F_p(T) = 1 - a_p T + p T^2 .\]" else: ans += "\(F_p\) is a polynomial of degree " + str(L.degree) + ". " if pbadset is not None: ans += "If " + pbadset + ", then $F_p$ is a polynomial of degree at most " ans += str(L.degree - 1) + ". " # Figuring out good and bad primes bad_primes = [] for lf in L.bad_lfactors: bad_primes.append(lf[0]) eulerlim = 25 good_primes = [] for p in primes_first_n(eulerlim): if p not in bad_primes: good_primes.append(p) #decide if we display galois display_galois = True if L.degree <= 2 or L.degree >= 12: display_galois = False if L.coefficient_field == "CDF": display_galois = False def pretty_poly(poly, prec=None): out = "1" for i, elt in enumerate(poly): if elt is None or (i == prec and prec != len(poly) - 1): out += "O(%s)" % (seriesvar(i, "polynomial"), ) break elif i > 0: out += seriescoeff(elt, i, "series", "polynomial", 3) return out eptable = r"""<div style="max-width: 100%; overflow-x: auto;">""" eptable += "<table class='ntdata euler'>\n" eptable += "<thead>" eptable += "<tr class='space'><th class='weight'></th><th class='weight'>$p$</th>" if L.degree > 2 and L.degree < 12: display_galois = True eptable += "<th class='weight galois'>$\Gal(F_p)$</th>" else: display_galois = False eptable += r"""<th class='weight' style="text-align: left;">$F_p$</th>""" eptable += "</tr>\n" eptable += "</thead>" def row(trclass, goodorbad, p, poly): out = "" try: if L.coefficient_field == "CDF" or None in poly: factors = str(pretty_poly(poly, prec=prec)) elif not display_galois: factors = list_to_factored_poly_otherorder( poly, galois=display_galois, prec=prec, p=p) else: factors, gal_groups = list_to_factored_poly_otherorder( poly, galois=display_galois, p=p) out += "<tr" + trclass + "><td>" + goodorbad + "</td><td>" + str( p) + "</td>" if display_galois: out += "<td class='galois'>" if gal_groups[0] == [0, 0]: pass # do nothing, because the local faco is 1 elif gal_groups[0] == [1, 1]: out += group_display_knowl(gal_groups[0][0], gal_groups[0][1], '$C_1$') else: out += group_display_knowl(gal_groups[0][0], gal_groups[0][1]) for n, k in gal_groups[1:]: out += "$\\times$" out += group_display_knowl(n, k) out += "</td>" out += "<td>" + "$" + factors + "$" + "</td>" out += "</tr>\n" except IndexError: out += "<tr><td></td><td>" + str( j) + "</td><td>" + "not available" + "</td></tr>\n" return out goodorbad = "bad" trclass = "" for lf in L.bad_lfactors: eptable += row(trclass, goodorbad, lf[0], lf[1]) goodorbad = "" trclass = "" goodorbad = "good" trclass = " class='first'" good_primes1 = good_primes[:9] good_primes2 = good_primes[9:] for j in good_primes1: this_prime_index = prime_pi(j) - 1 eptable += row(trclass, goodorbad, j, L.localfactors[this_prime_index]) goodorbad = "" trclass = "" trclass = " id='moreep' class='more nodisplay'" for j in good_primes2: this_prime_index = prime_pi(j) - 1 eptable += row(trclass, goodorbad, j, L.localfactors[this_prime_index]) trclass = " class='more nodisplay'" eptable += r"""<tr class="less toggle"><td colspan="2"> <a onclick="show_moreless("more"); return true" href="#moreep">show more</a></td>""" last_entry = "" if display_galois: last_entry += "<td></td>" last_entry += "<td></td>" eptable += last_entry eptable += "</tr>" eptable += r"""<tr class="more toggle nodisplay"><td colspan="2"><a onclick="show_moreless("less"); return true" href="#eptable">show less</a></td>""" eptable += last_entry eptable += "</tr>\n</table>\n</div>\n" ans += "\n" + eptable return (ans)
def set_twist_info(self, prec=10,insert_in_db=True): r""" Try to find forms of lower level which get twisted into self. OUTPUT: -''[t,l]'' -- tuple of a Bool t and a list l. The list l contains all tuples of forms which twists to the given form. The actual minimal one is the first element of this list. t is set to True if self is minimal and False otherwise EXAMPLES:: """ if(len(self._twist_info) > 0): return self._twist_info N = self.level() k = self.weight() if(is_squarefree(ZZ(N))): self._twist_info = [True, None ] return [True, None] # We need to check all square factors of N twist_candidates = list() KF = self.base_ring() # check how many Hecke eigenvalues we need to check max_nump = self._number_of_hecke_eigenvalues_to_check() maxp = max(primes_first_n(max_nump)) for d in divisors(N): if(d == 1): continue # we look at all d such that d^2 divdes N if(not ZZ(d ** 2).divides(ZZ(N))): continue D = DirichletGroup(d) # check possible candidates to twist into f # g in S_k(M,chi) wit M=N/d^2 M = ZZ(N / d ** 2) if(self._verbose > 0): wmf_logger.debug("Checking level {0}".format(M)) for xig in range(euler_phi(M)): (t, glist) = _get_newform(M,k, xig) if(not t): return glist for g in glist: if(self._verbose > 1): wmf_logger.debug("Comparing to function {0}".format(g)) KG = g.base_ring() # we now see if twisting of g by xi in D gives us f for xi in D: try: for p in primes_first_n(max_nump): if(ZZ(p).divides(ZZ(N))): continue bf = self.as_factor().q_eigenform(maxp + 1, names='x')[p] bg = g.q_expansion(maxp + 1)[p] if(bf == 0 and bg == 0): continue elif(bf == 0 and bg != 0 or bg == 0 and bf != 0): raise StopIteration() if(ZZ(p).divides(xi.conductor())): raise ArithmeticError("") xip = xi(p) # make a preliminary check that the base rings match with respect to being # real or not try: QQ(xip) XF = QQ if(KF != QQ or KG != QQ): raise StopIteration except TypeError: # we have a non-rational (i.e. complex) value of the character XF = xip.parent() if((KF.absolute_degree() == 1 or KF.is_totally_real()) and (KG.absolute_degre() == 1 or KG.is_totally_real())): raise StopIteration ## it is diffcult to compare elements from diferent rings in general but we make some checcks # is it possible to see if there is a larger ring which everything can be # coerced into? ok = False try: a = KF(bg / xip) b = KF(bf) ok = True if(a != b): raise StopIteration() except TypeError: pass try: a = KG(bg) b = KG(xip * bf) ok = True if(a != b): raise StopIteration() except TypeError: pass if(not ok): # we could coerce and the coefficients were equal return "Could not compare against possible candidates!" # otherwise if we are here we are ok and found a candidate twist_candidates.append([M, g.q_expansion(prec), xi]) except StopIteration: # they are not equal pass wmf_logger.debug("Candidates=v{0}".format(twist_candidates)) self._twist_info = (False, twist_candidates) if(len(twist_candidates) == 0): self._twist_info = [True, None] else: self._twist_info = [False, twist_candidates] return self._twist_info
def generate_lpdata_and_inputs(filename, check_for_lpdata=True, check_for_lfunction=True, chunk=100): linecount = line_count(filename) def print_RRR(elt): if elt.contains_integer(): try: return "%d" % ZZ(elt) except ValueError: pass return RRR(elt).str(style="question").replace('?', '') def print_CCC(elt): elt = CCC(elt) return "[ %s, %s]" % tuple(map(print_RRR, [elt.real(), elt.imag()])) def self_dual(char, aps): if char.is_trivial(): return True if (char * char).is_trivial(): for _, z in aps: if not z.imag().contains_zero(): return False return True else: return False base_dir = os.path.dirname(os.path.abspath(filename)) real_filename = os.path.abspath(filename).split('/')[-1] lfun_dir = os.path.join(base_dir, 'lfun') inputs_dir = os.path.join(base_dir, 'inputs') for d in [inputs_dir, lfun_dir]: if not os.path.exists(d): os.mkdir(d) inputs = {} k = 0 with open(filename, 'r') as F: for line in F: linesplit = line[:-1].split(':') hoc, label, conrey_label, embedding_index, embedding_m, ap_txt = linesplit lpfilename = os.path.join(lfun_dir, label + ".lpdata") lfunctionfilename = os.path.join(lfun_dir, label + ".lpdata.lfunction") level, weight, char_orbit, hecke_orbit, conrey_label_again, embedding = label.split( '.') assert conrey_label_again == conrey_label level = int(level) weight = int(weight) conrey_label = int(conrey_label) ap_list = [ toCCC(*elt.split(',')) for elt in ap_txt[2:-2].split('],[') ] ap_list = zip(primes_first_n(len(ap_list)), ap_list) G = DirichletGroup_conrey(level, CCC) char = DirichletCharacter_conrey(G, conrey_label) def euler_factor(p, ap): if p.divides(level): return [1, -ap] charval = CCC(2 * char.logvalue(p)).exppii() if charval.contains_exact(ZZ(1)): charval = 1 elif charval.contains_exact(ZZ(-1)): charval = -1 return [1, -ap, (p**(weight - 1)) * charval] euler_factors = [[elt[0], euler_factor(*elt)] for elt in ap_list] if not os.path.exists(lpfilename) or not check_for_lpdata: with open(lpfilename, 'w') as LPDATA: for p, ep in euler_factors: LPDATA.write("%d, [ %s ]\n" % (p, ", ".join(map(print_CCC, ep)))) if not os.path.exists( lfunctionfilename) or not check_for_lfunction: if weight not in inputs: inputs[weight] = [] inputs[weight].append( "%d %d %d %s %s" % (weight, self_dual( char, ap_list), level, label, lpfilename)) k += 1 if (k % (linecount // 10)) == 0: print "generate_lpdata_and_inputs %.2f%% done" % (k * 100. / linecount) parallel_inputs = os.path.join(base_dir, real_filename + '.tsv') with open(parallel_inputs, 'w') as I: for weight, lines in inputs.iteritems(): if chunk is None: chunked_lines = [lines] else: chunked_lines = [ lines[i:i + chunk] for i in range(0, len(lines), chunk) ] assert sum(map(len, chunked_lines)) == len(lines), "%d != %d" % (sum( map(len, chunked_lines)), len(lines)) for i, line_block in enumerate(chunked_lines): inputsfilename = os.path.join( inputs_dir, real_filename + '_wt%d_%d.input' % (weight, i)) with open(inputsfilename, 'w') as W: W.write('\n'.join(line_block) + '\n') #print "wrote %d lines to %s" % (len(line_block), inputsfilename) I.write("%d\t%s\n" % (weight, inputsfilename)) print "now set LFUNCTIONS and run:" print r"""parallel -a %s --colsep '\t' --progress ${LFUNCTIONS}/euler_factors 11 200 ${LFUNCTIONS}/gamma_files/mf.{1} {2} 100""" % ( parallel_inputs, )