def charpolys(v, B, filename=None): """ Compute characteristic polynomials of T_P for primes P with norm <= B coprime to the level, for all spaces of Hilbert modular forms for all the levels in v. INPUT: - `v` -- list of positive integers - `B` -- positive integer - ``filename`` -- optional string; if given, output is also written to that file (in addition to stdout). OUTPUT: - outputs a table with rows corresponding to the ideals of Q(sqrt(5)) with norm in v, and optionally creates a file EXAMPLES:: sage: from sage.modular.hilbert.sqrt5_tables import charpolys sage: out = charpolys([1..20], 10) 4 2 ... [(5,x-6),(3,x-10)] 5 -2*a+1 ... [(2,x-5),(3,x-10)] 9 3 ... [(2,x-5),(5,x-6)] 11 -3*a+1 ... [(2,x-5),(5,x-6),(3,x-10)] 11 -3*a+2 ... [(2,x-5),(5,x-6),(3,x-10)] 16 4 ... [(5,x-6),(3,x-10)] 19 -4*a+1 ... [(2,x-5),(5,x-6),(3,x-10)] 19 -4*a+3 ... [(2,x-5),(5,x-6),(3,x-10)] 20 -4*a+2 ... [(3,x-10)] sage: out = charpolys([20, 11], 10) 20 -4*a+2 ... [(3,x-10)] 11 -3*a+1 ... [(2,x-5),(5,x-6),(3,x-10)] 11 -3*a+2 ... [(2,x-5),(5,x-6),(3,x-10)] Test writing to a file:: sage: if os.path.exists('tmp_table.txt'): os.unlink('tmp_table.txt') sage: out = charpolys([20, 11], 10, 'tmp_table.txt') 20 -4*a+2 ... [(3,x-10)] 11 -3*a+1 ... [(2,x-5),(5,x-6),(3,x-10)] 11 -3*a+2 ... [(2,x-5),(5,x-6),(3,x-10)] sage: r = open('tmp_table.txt').read() sage: 'x-10' in r True sage: r.count('\n') 3 sage: os.unlink('tmp_table.txt') """ if len(v) == 0: return "" out = "" F = open(filename, "a") if filename else None P = [p for p in ideals_of_bounded_norm(B) if p.is_prime()] for N in ideals_of_norm(v): t = cputime() H = IcosiansModP1ModN(N) T = [ (p.smallest_integer(), H.hecke_matrix(p).fcp()) for p in P if gcd(Integer(p.norm()), Integer(N.norm())) == 1 ] tm = "%.2f" % cputime(t) s = "%s %s %s %s" % (N.norm(), no_space(reduced_gen(N)), tm, no_space(T)) print s out += s + "\n" if F: F.write(s + "\n") F.flush() return out
def rational_newforms(v, B=100, filename=None, ncpu=1): """ Return system of Hecke eigenvalues corresponding to rational newforms of level whose norm is in v. Compute the Hecke eigenvalues a_P for all good primes P with norm < B. INPUT: - `v` -- list of integers - `B` -- positive integer - ``filename`` -- optional filename - ``ncpu`` -- positive integer (default: 1); if > 1 then use ncpu simultaneous processes. Note that that displayed output during the computation and to the file may be out of order. OUTPUT: - outputs a table with rows corresponding to the ideals of Q(sqrt(5)) with norm in v, and optionally creates a file Table columns: norm_of_level generator_of_level number time_for_level a_P a_P ... EXAMPLES:: sage: from sage.modular.hilbert.sqrt5_tables import rational_newforms sage: out = rational_newforms([1..76], B=20) 31 5*a-3 0 ... -3 -2 2 4 -4 -4 4 31 5*a-2 0 ... -3 -2 2 -4 4 4 -4 36 6 0 ... ? -4 ? 2 2 0 0 41 a-7 0 ... -2 -1 -4 -2 5 -1 6 41 a+6 0 ... -2 -1 -4 5 -2 6 -1 45 -6*a+3 0 ... -3 ? ? -4 -4 4 4 49 7 0 ... 0 -4 5 -3 -3 0 0 55 a+7 0 ... -1 ? -2 ? 0 8 -4 55 -a+8 0 ... -1 ? -2 0 ? -4 8 64 8 0 ... 0 -2 2 -4 -4 4 4 71 a-9 0 ... -1 0 -2 0 0 -4 2 71 a+8 0 ... -1 0 -2 0 0 2 -4 76 -8*a+2 0 ... ? -3 1 3 -6 ? -7 76 -8*a+2 1 ... ? 1 -5 -3 2 ? 5 76 -8*a+6 0 ... ? -3 1 -6 3 -7 ? 76 -8*a+6 1 ... ? 1 -5 2 -3 5 ? Test writing to a file:: sage: if os.path.exists('tmp_table.txt'): os.unlink('tmp_table.txt') sage: out = rational_newforms([1..36], 20,'tmp_table.txt') 31 5*a-3 0 ... -3 -2 2 4 -4 -4 4 31 5*a-2 0 ... -3 -2 2 -4 4 4 -4 36 6 0 ... ? -4 ? 2 2 0 0 sage: r = open('tmp_table.txt').read() sage: r.count('\n') 3 sage: os.unlink('tmp_table.txt') """ if len(v) == 0: return "" if ncpu < 1: raise ValueError, "ncpu must be >= 1" F = open(filename, "a") if filename else None if ncpu > 1: from sage.all import parallel @parallel(ncpu) def f(N): return rational_newforms([N], B, filename=None, ncpu=1) d = {} for X in f(v): N = X[0][0] ans = X[1].strip() if ans: d[N] = ans if F: F.write(ans + "\n") return "\n".join(d[N] for N in sorted(d.keys())) out = "" from sqrt5_hmf import QuaternionicModule for N in ideals_of_norm(v): t = cputime() H = QuaternionicModule(N) EC = H.rational_newforms() tm = "%.2f" % cputime(t) for i, E in enumerate(EC): v = E.aplist(B) data = [N.norm(), no_space(reduced_gen(N)), i, tm, " ".join([no_space(x) for x in v])] s = " ".join([str(x) for x in data]) print s out += s + "\n" if F: F.write(s + "\n") F.flush() return out
def dimensions(v, filename=None): """ Compute dimensions of spaces of Hilbert modular forms for all the levels in v. The format is: Norm dimension generator time INPUT: - `v` -- list of positive integers - ``filename`` -- optional string; if given, output is also written to that file (in addition to stdout). OUTPUT: - appends to table with above format and rows corresponding to the ideals of Q(sqrt(5)) with norm in v, and optionally creates a file EXAMPLES:: sage: from sage.modular.hilbert.sqrt5_tables import dimensions sage: out = dimensions([1..40]) 4 1 2 ... 5 1 -2*a+1 ... 9 1 3 ... 11 1 -3*a+1 ... 11 1 -3*a+2 ... 16 1 4 ... 19 1 -4*a+1 ... 19 1 -4*a+3 ... 20 1 -4*a+2 ... 25 1 5 ... 29 1 a-6 ... 29 1 -a-5 ... 31 2 5*a-3 ... 31 2 5*a-2 ... 36 2 6 ... sage: out = dimensions([36, 4]) 36 2 6 ... 4 1 2 ... Test writing to a file:: sage: if os.path.exists('tmp_table.txt'): os.unlink('tmp_table.txt') sage: out = dimensions([36, 4], 'tmp_table.txt') 36 2 6 ... 4 1 2 ... sage: '36 2 6' in open('tmp_table.txt').read() True sage: open('tmp_table.txt').read().count('\n') 2 sage: os.unlink('tmp_table.txt') """ if len(v) == 0: return "" F = open(filename, "a") if filename else None out = "" for N in ideals_of_norm(v): t = cputime() H = IcosiansModP1ModN(N) tm = "%.2f" % cputime(t) s = "%s %s %s %s" % (N.norm(), H.cardinality(), no_space(reduced_gen(N)), tm) print s out += s + "\n" if F: F.write(s + "\n") F.flush() return out