def init_dynamic_properties(self, embeddings=False): if self.number is not None: emf_logger.debug('number: {0}'.format(self.number)) self.character = DirichletCharacter_conrey( DirichletGroup_conrey(self.modulus), self.number) if not self.number == 1: self.sage_character = self.character.sage_character() else: self.sage_character = trivial_character(self.modulus) self.name = "Character nr. {0} of modulus {1}".format( self.number, self.modulus) if embeddings: from lmfdb.modular_forms.elliptic_modular_forms.backend.emf_utils import dirichlet_character_conrey_galois_orbit_embeddings emb = dirichlet_character_conrey_galois_orbit_embeddings( self.modulus, self.number) self.set_embeddings(emb) c = self.character if self.conductor == 0: self.conductor = c.conductor() if self.order == 0: self.order = c.multiplicative_order() if self.modulus_euler_phi == 0: self.modulus_euler_phi = euler_phi(self.modulus) if self.latex_name == '': self.latex_name = "\chi_{" + str(self.modulus) + "}(" + str( self.number) + ", \cdot)"
def DirichletCharacterGaloisReps(N): global DCGR_cache if not N in DCGR_cache: Chars = [ch[0] for ch in DG(N).galois_orbits()] vv = [[[DC.multiplicative_order(chi)] + character_traces(DC.sage_character(chi)), i] for i, chi in enumerate(Chars)] vv.sort() DCGR_cache[N] = [Chars[v[1]] for v in vv] return DCGR_cache[N]
def doline(inputs, line, lfun_dir, check_for_lpdata = True, check_for_lfunction = True): linesplit = line.rstrip('\n').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 = None G = DirichletGroup_conrey(level, CCC) char = DirichletCharacter_conrey(G, conrey_label) if not os.path.exists(lpfilename) or not check_for_lpdata: ap_list = read_aps(ap_txt) euler_factors = [[elt[0], euler_factor(level, weight, char, elt[0], elt[1])] for elt in ap_list] 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] = [] sd = self_dual_by_char(char) if sd is None: if ap_list is None: ap_list = read_aps(ap_txt) sd = self_dual(char, ap_list) inputs[weight].append("%d %d %d %s %s" % (weight, sd, level, label, lpfilename))
def DC_char_to_gp_char(chi, G=None): """ If this function is to be called repeatedly with the same modulus it is better to precompute G and pass it, so save recomputation: """ if G is None: G = pari(chi.modulus()).znstar(1) return G.znconreylog(DC.number(chi))
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 char_orbit_index_to_DC_number(N, o): """Returns the index in the Dirichlet-Conrey numbering of one character in orbit number o""" if o == 1: return 1 global char_table_dict if not char_table_dict: char_table_dict = {} try: chartab = open("chartab.txt") for L in chartab.readlines(): NN, oo, nn = [int(x) for x in L.split()] if not NN in char_table_dict: char_table_dict[NN] = {} char_table_dict[NN][oo] = nn chartab.close() except IOError: Chars = DirichletCharacterGaloisReps(N) return DC.number(Chars[o - 1]) try: return char_table_dict[N][o] except KeyError: # N too big for precomputed table Chars = DirichletCharacterGaloisReps(N) return DC.number(Chars[o - 1])
def init_dynamic_properties(self, embeddings=False): if self.number is not None: emf_logger.debug('number: {0}'.format(self.number)) self.character = DirichletCharacter_conrey(DirichletGroup_conrey(self.modulus),self.number) if not self.number == 1: self.sage_character = self.character.sage_character() else: self.sage_character = trivial_character(self.modulus) self.name = "Character nr. {0} of modulus {1}".format(self.number,self.modulus) if embeddings: from lmfdb.modular_forms.elliptic_modular_forms.backend.emf_utils import dirichlet_character_conrey_galois_orbit_embeddings emb = dirichlet_character_conrey_galois_orbit_embeddings(self.modulus,self.number) self.set_embeddings(emb) c = self.character if self.conductor == 0: self.conductor = c.conductor() if self.order == 0: self.order = c.multiplicative_order() if self.modulus_euler_phi == 0: self.modulus_euler_phi = euler_phi(self.modulus) if self.latex_name == '': self.latex_name = "\chi_{" + str(self.modulus) + "}(" + str(self.number) + ", \cdot)"
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 conrey_character_from_number(N, c): D = DirichletGroup_conrey(N) return DirichletCharacter_conrey(D, c)
def setup_cc_data(self, info): """ INPUT: - ``info`` -- a dictionary with keys - ``m`` -- a string describing the embedding indexes desired - ``n`` -- a string describing the a_n desired - ``CC_m`` -- a list of embedding indexes - ``CC_n`` -- a list of desired a_n - ``format`` -- one of 'embed', 'analytic_embed', 'satake', or 'satake_angle' """ an_formats = ['embed','analytic_embed',None] angles_formats = ['satake','satake_angle',None] m = info.get('m','1-%s'%(min(self.dim,20))) n = info.get('n','1-10') CC_m = info.get('CC_m', integer_options(m)) CC_n = info.get('CC_n', integer_options(n)) # convert CC_n to an interval in [1,an_storage_bound] CC_n = ( max(1, min(CC_n)), min(an_storage_bound, max(CC_n)) ) an_keys = (CC_n[0]-1, CC_n[1]) # extra 5 primes in case we hit too many bad primes angles_keys = (bisect.bisect_left(primes_for_angles, CC_n[0]), bisect.bisect_right(primes_for_angles, CC_n[1]) + 5) format = info.get('format') cc_proj = ['conrey_label','embedding_index','embedding_m','embedding_root_real','embedding_root_imag'] an_projection = 'an[%d:%d]' % an_keys angles_projection = 'angles[%d:%d]' % angles_keys if format in an_formats: cc_proj.append(an_projection) if format in angles_formats: cc_proj.append(angles_projection) query = {'hecke_orbit_code':self.hecke_orbit_code} range_match = INTEGER_RANGE_RE.match(m) if range_match: low, high = int(range_match.group(1)), int(range_match.group(2)) query['embedding_m'] = {'$gte':low, '$lte':high} else: query['embedding_m'] = {'$in': CC_m} cc_data= list(db.mf_hecke_cc.search(query, projection = cc_proj)) if not cc_data: self.has_complex_qexp = False self.cqexp_prec = 0 else: self.has_complex_qexp = True self.cqexp_prec = an_keys[1] + 1 self.cc_data = {} for embedded_mf in cc_data: #as they are stored as a jsonb, large enough elements might be recognized as an integer if format in an_formats: # we don't store a_0, thus the +1 embedded_mf['an'] = {i: [float(x), float(y)] for i, (x, y) in enumerate(embedded_mf.pop(an_projection), an_keys[0] + 1)} if format in angles_formats: embedded_mf['angles'] = {primes_for_angles[i]: theta for i, theta in enumerate(embedded_mf.pop(angles_projection), angles_keys[0])} self.cc_data[embedded_mf.pop('embedding_m')] = embedded_mf if format in ['analytic_embed',None]: self.analytic_shift = {i : float(i)**((1-ZZ(self.weight))/2) for i in self.cc_data.values()[0]['an'].keys()} if format in angles_formats: self.character_values = defaultdict(list) G = DirichletGroup_conrey(self.level) chars = [DirichletCharacter_conrey(G, char) for char in self.char_labels] for p in self.cc_data.values()[0]['angles'].keys(): if p.divides(self.level): continue for chi in chars: c = chi.logvalue(p) * self.char_order angle = float(c / self.char_order) value = CDF(0,2*CDF.pi()*angle).exp() self.character_values[p].append((angle, value))
class WebChar(WebObject, CachedRepresentation): r""" Class which should/might be replaced with WebDirichletCharcter once this is ok. """ _key = ['modulus', 'number','version'] _file_key = ['modulus', 'number','version'] _collection_name = 'webchar' def __init__(self, modulus=1, number=1, update_from_db=True, compute_values=False, init_dynamic_properties=True): r""" Init self. """ emf_logger.debug("In WebChar {0}".format((modulus,number,update_from_db,compute_values))) if isinstance(modulus,basestring): try: m,n=modulus.split('.') modulus = int(m); number=int(n) except: raise ValueError,"{0} does not correspond to the label of a WebChar".format(modulus) if not gcd(number,modulus)==1: raise ValueError,"Character number {0} of modulus {1} does not exist!".format(number,modulus) if number > modulus: number = number % modulus self._properties = WebProperties( WebInt('conductor'), WebInt('modulus', value=modulus), WebInt('number', value=number), WebInt('modulus_euler_phi'), WebInt('order'), WebStr('latex_name'), WebStr('label',value="{0}.{1}".format(modulus,number)), WebNoStoreObject('sage_character', type(trivial_character(1))), WebDict('_values_algebraic'), WebDict('_values_float'), WebDict('_embeddings'), WebFloat('version', value=float(emf_version)) ) emf_logger.debug('Set properties in WebChar!') super(WebChar, self).__init__( update_from_db=update_from_db, init_dynamic_properties=init_dynamic_properties ) #if not self.has_updated_from_db(): # self.init_dynamic_properties() # this was not done if we exited early # compute = True if compute_values: self.compute_values() #emf_logger.debug('In WebChar, self.__dict__ = {0}'.format(self.__dict__)) emf_logger.debug('In WebChar, self.number = {0}'.format(self.number)) def compute_values(self, save=False): emf_logger.debug('in compute_values for WebChar number {0} of modulus {1}'.format(self.number, self.modulus)) if self._values_algebraic == {} or self._values_float == {}: changed = True for i in range(self.modulus): self.value(i,value_format='float') self.value(i,value_format='algebraic') if changed and save: self.save_to_db() else: emf_logger.debug('Not saving.') def init_dynamic_properties(self, embeddings=False): if self.number is not None: emf_logger.debug('number: {0}'.format(self.number)) self.character = DirichletCharacter_conrey(DirichletGroup_conrey(self.modulus),self.number) if not self.number == 1: self.sage_character = self.character.sage_character() else: self.sage_character = trivial_character(self.modulus) self.name = "Character nr. {0} of modulus {1}".format(self.number,self.modulus) if embeddings: from lmfdb.modular_forms.elliptic_modular_forms.backend.emf_utils import dirichlet_character_conrey_galois_orbit_embeddings emb = dirichlet_character_conrey_galois_orbit_embeddings(self.modulus,self.number) self.set_embeddings(emb) c = self.character if self.conductor == 0: self.conductor = c.conductor() if self.order == 0: self.order = c.multiplicative_order() if self.modulus_euler_phi == 0: self.modulus_euler_phi = euler_phi(self.modulus) if self.latex_name == '': self.latex_name = "\chi_{" + str(self.modulus) + "}(" + str(self.number) + ", \cdot)" def is_trivial(self): r""" Check if self is trivial. """ return self.character.is_trivial() def embeddings(self): r""" Returns a dictionary that maps the Conrey numbers of the Dirichlet characters in the Galois orbit of ```self``` to the powers of $\zeta_{\phi(N)}$ so that the corresponding embeddings map the labels. Let $\zeta_{\phi(N)}$ be the generator of the cyclotomic field of $N$-th roots of unity which is the base field for the coefficients of a modular form contained in the database. Considering the space $S_k(N,\chi)$, where $\chi = \chi_N(m, \cdot)$, if embeddings()[m] = n, then $\zeta_{\phi(N)}$ is mapped to $\mathrm{exp}(2\pi i n /\phi(N))$. """ return self._embeddings def set_embeddings(self, d): self._embeddings = d def embedding(self): r""" Let $\zeta_{\phi(N)}$ be the generator of the cyclotomic field of $N$-th roots of unity which is the base field for the coefficients of a modular form contained in the database. If ```self``` is given as $\chi = \chi_N(m, \cdot)$ in the Conrey naming scheme, then we have to apply the map \[ \zeta_{\phi(N)} \mapsto \mathrm{exp}(2\pi i n /\phi(N)) \] to the coefficients of normalized newforms in $S_k(N,\chi)$ as in the database in order to obtain the coefficients corresponding to ```self``` (that is to elements in $S_k(N,\chi)$). """ return self._embeddings[self.number] def __repr__(self): r""" Return the string representation of the character of self. """ return self.name def value(self, x, value_format='algebraic'): r""" Return the value of self as an algebraic integer or float. """ x = int(x) if value_format =='algebraic': if self._values_algebraic is None: self._values_algebraic = {} y = self._values_algebraic.get(x) if y is None: y = self._values_algebraic[x]=self.sage_character(x) else: self._values_algebraic[x]=y return self._values_algebraic[x] elif value_format=='float': ## floating point if self._values_float is None: self._values_float = {} y = self._values_float.get(x) if y is None: y = self._values_float[x]=self.character(x) else: self._values_float[x]=y return self._values_float[x] else: raise ValueError,"Format {0} is not known!".format(value_format) def url(self): r""" Return the url of self. """ if not hasattr(self, '_url') or self._url is None: self._url = url_for('characters.render_Dirichletwebpage',modulus=self.modulus, number=self.number) return self._url
def GP_DirichletCharacterGaloisReps(N): G = pari(N).znstar(1) return [ G.znconreylog(DC.number(chi)) for chi in DirichletCharacterGaloisReps(N) ]
def DC_char_to_gp_char(chi, G=None): if G == None: G = pari(chi.modulus()).znstar(1) return G.znconreylog(DC.number(chi))
def OrderedConreyLabels(N): return [DC.number(chi) for chi in DirichletCharacterGaloisReps(N)]
def angles_euler_factors(coeffs, level, weight, chi): """ - ``coeffs`` -- a list of Dirichlet coefficients, as elements of CCC - ``level`` -- the level N - ``weight`` -- the weight k - ``chi`` -- the index of the Dirichlet character in the Conrey labeling returns a triple: (angles, euler_factos, bad_euler_factors) """ G = DirichletGroup_conrey(level, CCC) char = DirichletCharacter_conrey(G, chi) euler = [] bad_euler = [] angles = [] for p in prime_range(to_store): b = -coeffs[p] c = 1 if p.divides(level): bad_euler.append([p, [c, b]]) euler.append([c, b]) a = 0 angles.append(None) else: charval = CCC(2 * char.logvalue(int(p))).exppii() if charval.contains_exact(ZZ(1)): charval = 1 elif charval.contains_exact(ZZ(-1)): charval = -1 a = (p**QQ(weight - 1)) * charval euler.append([c, b, a]) # alpha solves T^2 - a_p T + chi(p)*p^(k-1) sqrt_disc = sqrt_hack(b**2 - 4 * a * c) thetas = [] for sign in [1, -1]: alpha = (-b + sign * sqrt_disc) / (2 * c) theta = (arg_hack(alpha) / (2 * CCC.pi().real())).mid() if theta > 0.5: theta -= 1 elif theta <= -0.5: theta += 1 assert theta <= 0.5 and theta > -0.5, "%s %s %s" % ( theta, arg_hack(alpha), alpha) thetas.append(theta) angles.append(float(min(thetas))) if len(coeffs) > p**2: if coeffs[p**2].abs().contains_zero(): match = (coeffs[p**2] - (b**2 - a)).abs().mid() < 1e-5 else: match = ((coeffs[p**2] - (b**2 - a)).abs() / coeffs[p**2].abs()).mid() < 1e-5 if not match: print "coeffs[p**2] doesn't match euler recursion" print zip(range(len(coeffs)), map(CDF, coeffs)) print "(level, weight, chi, p) = %s\n%s != %s\na_p2**2 - (b**2 - a)= %s\n b**2 - a = %s\na_p2 = %s\na=%s\nb = %s\nap = %s" % ( (level, weight, chi, p), CDF(coeffs[p**2]), CDF(b**2 - a), coeffs[p**2] - (b**2 - a), b**2 - a, coeffs[p**2], CDF(a), CDF(b), CDF(coeffs[p])) assert False an_f = [ CBF_to_pair(RRR(n)**(QQ(-(weight - 1)) / 2) * c) for n, c in enumerate(coeffs[:to_store + 1]) ] return an_f, angles, euler, bad_euler
def primitivize(label): m, n = [ZZ(a) for a in label.split(".")] char = DirichletCharacter_conrey(DirGroup(m), n).primitive_character() return "%d.%d" % (char.modulus(), char.number())
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, )
class WebChar(WebObject, CachedRepresentation): r""" Class which should/might be replaced with WebDirichletCharcter once this is ok. """ _key = ['modulus', 'number', 'version'] _file_key = ['modulus', 'number', 'version'] _collection_name = 'webchar' def __init__(self, modulus=1, number=1, update_from_db=True, compute_values=False, init_dynamic_properties=True): r""" Init self. """ emf_logger.debug("In WebChar {0}".format( (modulus, number, update_from_db, compute_values))) if isinstance(modulus, basestring): try: m, n = modulus.split('.') modulus = int(m) number = int(n) except: raise ValueError, "{0} does not correspond to the label of a WebChar".format( modulus) if not gcd(number, modulus) == 1: raise ValueError, "Character number {0} of modulus {1} does not exist!".format( number, modulus) if number > modulus: number = number % modulus self._properties = WebProperties( WebInt('conductor'), WebInt('modulus', value=modulus), WebInt('number', value=number), WebInt('modulus_euler_phi'), WebInt('order'), WebStr('latex_name'), WebStr('label', value="{0}.{1}".format(modulus, number)), WebNoStoreObject('sage_character', type(trivial_character(1))), WebDict('_values_algebraic'), WebDict('_values_float'), WebDict('_embeddings'), WebFloat('version', value=float(emf_version))) emf_logger.debug('Set properties in WebChar!') super(WebChar, self).__init__(update_from_db=update_from_db, init_dynamic_properties=init_dynamic_properties) #if not self.has_updated_from_db(): # self.init_dynamic_properties() # this was not done if we exited early # compute = True if compute_values: self.compute_values() #emf_logger.debug('In WebChar, self.__dict__ = {0}'.format(self.__dict__)) emf_logger.debug('In WebChar, self.number = {0}'.format(self.number)) def compute_values(self, save=False): emf_logger.debug( 'in compute_values for WebChar number {0} of modulus {1}'.format( self.number, self.modulus)) if self._values_algebraic == {} or self._values_float == {}: changed = True for i in range(self.modulus): self.value(i, value_format='float') self.value(i, value_format='algebraic') if changed and save: self.save_to_db() else: emf_logger.debug('Not saving.') def init_dynamic_properties(self, embeddings=False): if self.number is not None: emf_logger.debug('number: {0}'.format(self.number)) self.character = DirichletCharacter_conrey( DirichletGroup_conrey(self.modulus), self.number) if not self.number == 1: self.sage_character = self.character.sage_character() else: self.sage_character = trivial_character(self.modulus) self.name = "Character nr. {0} of modulus {1}".format( self.number, self.modulus) if embeddings: from lmfdb.modular_forms.elliptic_modular_forms.backend.emf_utils import dirichlet_character_conrey_galois_orbit_embeddings emb = dirichlet_character_conrey_galois_orbit_embeddings( self.modulus, self.number) self.set_embeddings(emb) c = self.character if self.conductor == 0: self.conductor = c.conductor() if self.order == 0: self.order = c.multiplicative_order() if self.modulus_euler_phi == 0: self.modulus_euler_phi = euler_phi(self.modulus) if self.latex_name == '': self.latex_name = "\chi_{" + str(self.modulus) + "}(" + str( self.number) + ", \cdot)" def is_trivial(self): r""" Check if self is trivial. """ return self.character.is_trivial() def embeddings(self): r""" Returns a dictionary that maps the Conrey numbers of the Dirichlet characters in the Galois orbit of ```self``` to the powers of $\zeta_{\phi(N)}$ so that the corresponding embeddings map the labels. Let $\zeta_{\phi(N)}$ be the generator of the cyclotomic field of $N$-th roots of unity which is the base field for the coefficients of a modular form contained in the database. Considering the space $S_k(N,\chi)$, where $\chi = \chi_N(m, \cdot)$, if embeddings()[m] = n, then $\zeta_{\phi(N)}$ is mapped to $\mathrm{exp}(2\pi i n /\phi(N))$. """ return self._embeddings def set_embeddings(self, d): self._embeddings = d def embedding(self): r""" Let $\zeta_{\phi(N)}$ be the generator of the cyclotomic field of $N$-th roots of unity which is the base field for the coefficients of a modular form contained in the database. If ```self``` is given as $\chi = \chi_N(m, \cdot)$ in the Conrey naming scheme, then we have to apply the map \[ \zeta_{\phi(N)} \mapsto \mathrm{exp}(2\pi i n /\phi(N)) \] to the coefficients of normalized newforms in $S_k(N,\chi)$ as in the database in order to obtain the coefficients corresponding to ```self``` (that is to elements in $S_k(N,\chi)$). """ return self._embeddings[self.number] def __repr__(self): r""" Return the string representation of the character of self. """ return self.name def value(self, x, value_format='algebraic'): r""" Return the value of self as an algebraic integer or float. """ x = int(x) if value_format == 'algebraic': if self._values_algebraic is None: self._values_algebraic = {} y = self._values_algebraic.get(x) if y is None: y = self._values_algebraic[x] = self.sage_character(x) else: self._values_algebraic[x] = y return self._values_algebraic[x] elif value_format == 'float': ## floating point if self._values_float is None: self._values_float = {} y = self._values_float.get(x) if y is None: y = self._values_float[x] = self.character(x) else: self._values_float[x] = y return self._values_float[x] else: raise ValueError, "Format {0} is not known!".format(value_format) def url(self): r""" Return the url of self. """ if not hasattr(self, '_url') or self._url is None: self._url = url_for('characters.render_Dirichletwebpage', modulus=self.modulus, number=self.number) return self._url
def dirichlet_character_from_lmfdb_mf(data): G = DirichletGroup_conrey(data[u'level']) return DirichletCharacter_conrey(G, data[u'conrey_indexes'][0])