def cached_eisenstein_series_qexp(k, prec, verbose=False): """ Return q-expansion of the weight k level 1 Eisenstein series to the requested precision. The result is cached, so that subsequent calls are quick. INPUT: - k -- even positive integer - prec -- positive integer - verbose -- bool (default: False); if True, print timing information OUTPUT: - power series over the rational numbers EXAMPLES:: sage: from psage.modform.rational.special import cached_eisenstein_series_qexp sage: cached_eisenstein_series_qexp(4, 10) 1/240 + q + 9*q^2 + 28*q^3 + 73*q^4 + 126*q^5 + 252*q^6 + 344*q^7 + 585*q^8 + 757*q^9 + O(q^10) sage: cached_eisenstein_series_qexp(4, 5, verbose=True) Computing E_4(q) + O(q^5)... (time = ... seconds) 1/240 + q + 9*q^2 + 28*q^3 + 73*q^4 + O(q^5) sage: cached_eisenstein_series_qexp(4, 5, verbose=True) # cache used, so no timing printed 1/240 + q + 9*q^2 + 28*q^3 + 73*q^4 + O(q^5) """ if verbose: print("Computing E_{0}(q) + O(q^{1})...".format(k, prec)) sys.stdout.flush() t = cputime() e = eisenstein_series_qexp(k, prec) if verbose: print("(time = {0:.2f} seconds)".format(cputime(t))) return e
def qexp(self, prec, verbose=False): """ The q-expansion of a monomial in Eisenstein series. INPUT: - prec -- positive integer - verbose -- bool (default: False) EXAMPLES:: sage: from psage.modform.rational.special import EisensteinMonomial sage: e = EisensteinMonomial([(5,4,2), (5,6,3)]) sage: e.qexp(11) -1/7374186086400 + 43/307257753600*q^5 - 671/102419251200*q^10 + O(q^11) sage: E4 = eisenstein_series_qexp(4,11); q = E4.parent().gen() sage: E6 = eisenstein_series_qexp(6,11) sage: (E4(q^5)^2 * E6(q^5)^3).add_bigoh(11) -1/7374186086400 + 43/307257753600*q^5 - 671/102419251200*q^10 + O(q^11) """ z = [eis_qexp(k, t, prec, verbose=verbose)**e for t, k, e in self._v] if verbose: print("Arithmetic to compute {0} +O(q^{1})".format(self, prec)) sys.stdout.flush() t = cputime() p = prod(z) if verbose: print("(time = {0:.2f} seconds)".format(cputime(t))) return p
def cached_eisenstein_series_qexp(k, prec, verbose=False): """ Return q-expansion of the weight k level 1 Eisenstein series to the requested precision. The result is cached, so that subsequent calls are quick. INPUT: - k -- even positive integer - prec -- positive integer - verbose -- bool (default: False); if True, print timing information OUTPUT: - power series over the rational numbers EXAMPLES:: sage: from psage.modform.rational.special import cached_eisenstein_series_qexp sage: cached_eisenstein_series_qexp(4, 10) 1/240 + q + 9*q^2 + 28*q^3 + 73*q^4 + 126*q^5 + 252*q^6 + 344*q^7 + 585*q^8 + 757*q^9 + O(q^10) sage: cached_eisenstein_series_qexp(4, 5, verbose=True) Computing E_4(q) + O(q^5)... (time = ... seconds) 1/240 + q + 9*q^2 + 28*q^3 + 73*q^4 + O(q^5) sage: cached_eisenstein_series_qexp(4, 5, verbose=True) # cache used, so no timing printed 1/240 + q + 9*q^2 + 28*q^3 + 73*q^4 + O(q^5) """ if verbose: print "Computing E_%s(q) + O(q^%s)..."%(k,prec),; sys.stdout.flush(); t = cputime() e = eisenstein_series_qexp(k, prec) if verbose: print "(time = %.2f seconds)"%cputime(t) return e
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 """ F = open(filename,'a') if filename else None for N in ideals_of_norm(v): t = cputime() H = sqrt5_fast.IcosiansModP1ModN(N) tm = cputime(t) s = '{0} {1} {2} {3}'.format(N.norm(), H.cardinality(), no_space(canonical_gen(N)), tm) print(s) if F: F.write(s+'\n') F.flush()
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 """ F = open(filename,'a') if filename else None for N in ideals_of_norm(v): t = cputime() H = sqrt5_fast.IcosiansModP1ModN(N) tm = cputime(t) s = '%s %s %s %s'%(N.norm(), H.cardinality(), no_space(canonical_gen(N)), tm) print s if F: F.write(s+'\n') F.flush()
def charpolys(v, B, filename=None): """ Compute characteristic polynomials of T_P for primes P with norm <= B for spaces of Hilbert modular forms for all the levels in v. """ 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 = sqrt5_fast.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 = cputime(t) s = '%s %s %s %s'%(N.norm(), no_space(canonical_gen(N)), tm, no_space(T)) print s if F: F.write(s+'\n') F.flush()
def charpolys(v, B, filename=None): """ Compute characteristic polynomials of T_P for primes P with norm <= B for spaces of Hilbert modular forms for all the levels in v. """ 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 = sqrt5_fast.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 = cputime(t) s = '{0} {1} {2} {3}'.format(N.norm(), no_space(canonical_gen(N)), tm, no_space(T)) print(s) if F: F.write(s+'\n') F.flush()
def one_charpoly(v, filename=None): """ Compute and factor one characteristic polynomials for all the levels in v. Always compute the charpoly of T_P where P is the smallest prime not dividing the level. """ F = open(filename,'a') if filename else None P = [p for p in ideals_of_bounded_norm(100) if p.is_prime()] for N in ideals_of_norm(v): NN = Integer(N.norm()) t = cputime() H = sqrt5_fast.IcosiansModP1ModN(N) t0 = cputime(t) for p in P: if Integer(p.norm()).gcd(NN) == 1: break t = cputime() T = H.hecke_matrix(p) t1 = cputime(t) t = cputime() f = T.fcp() t2 = cputime(t) s = '{0}\t{1}\t{2}\t{3}\t{4}\t({5:.1f},{6:.1f},{7:.1f})'.format(N.norm(), no_space(canonical_gen(N)), p.smallest_integer(), no_space(canonical_gen(p)), no_space(f), t0, t1, t2) print(s) if F: F.write(s+'\n') F.flush()
def one_charpoly(v, filename=None): """ Compute and factor one characteristic polynomials for all the levels in v. Always compute the charpoly of T_P where P is the smallest prime not dividing the level. """ F = open(filename,'a') if filename else None P = [p for p in ideals_of_bounded_norm(100) if p.is_prime()] for N in ideals_of_norm(v): NN = Integer(N.norm()) t = cputime() H = sqrt5_fast.IcosiansModP1ModN(N) t0 = cputime(t) for p in P: if Integer(p.norm()).gcd(NN) == 1: break t = cputime() T = H.hecke_matrix(p) t1 = cputime(t) t = cputime() f = T.fcp() t2 = cputime(t) s = '%s\t%s\t%s\t%s\t%s\t(%.1f,%.1f,%.1f)'%(N.norm(), no_space(canonical_gen(N)), p.smallest_integer(), no_space(canonical_gen(p)), no_space(f), t0, t1, t2,) print s if F: F.write(s+'\n') F.flush()
def qexp(self, prec, verbose=False): """ The q-expansion of a monomial in Eisenstein series. INPUT: - prec -- positive integer - verbose -- bool (default: False) EXAMPLES:: sage: from psage.modform.rational.special import EisensteinMonomial sage: e = EisensteinMonomial([(5,4,2), (5,6,3)]) sage: e.qexp(11) -1/7374186086400 + 43/307257753600*q^5 - 671/102419251200*q^10 + O(q^11) sage: E4 = eisenstein_series_qexp(4,11); q = E4.parent().gen() sage: E6 = eisenstein_series_qexp(6,11) sage: (E4(q^5)^2 * E6(q^5)^3).add_bigoh(11) -1/7374186086400 + 43/307257753600*q^5 - 671/102419251200*q^10 + O(q^11) """ z = [eis_qexp(k, t, prec, verbose=verbose)**e for t,k,e in self._v] if verbose: print "Arithmetic to compute %s +O(q^%s)"%(self, prec); sys.stdout.flush(); t=cputime() p = prod(z) if verbose: print "(time = %.2f seconds)"%cputime(t) return p
def __find_eisen_chars(character, k): """ Find all triples `(\psi_1, \psi_2, t)` that give rise to an Eisenstein series of the given weight and character. EXAMPLES:: sage: sage.modular.modform.eis_series.__find_eisen_chars(DirichletGroup(36).0, 4) [] sage: pars = sage.modular.modform.eis_series.__find_eisen_chars(DirichletGroup(36).0, 5) sage: [(x[0].values_on_gens(), x[1].values_on_gens(), x[2]) for x in pars] [((1, 1), (-1, 1), 1), ((1, 1), (-1, 1), 3), ((1, 1), (-1, 1), 9), ((1, -1), (-1, -1), 1), ((-1, 1), (1, 1), 1), ((-1, 1), (1, 1), 3), ((-1, 1), (1, 1), 9), ((-1, -1), (1, -1), 1)] """ N = character.modulus() if character.is_trivial(): if k%2 != 0: return [] char_inv = ~character V = [(character, char_inv, t) for t in divisors(N) if t>1] if k != 2: V.insert(0,(character, char_inv, 1)) if is_squarefree(N): return V # Now include all pairs (chi,chi^(-1)) such that cond(chi)^2 divides N: # TODO: Optimize -- this is presumably way too hard work below. G = dirichlet.DirichletGroup(N) for chi in G: if not chi.is_trivial(): f = chi.conductor() if N % (f**2) == 0: chi = chi.minimize_base_ring() chi_inv = ~chi for t in divisors(N//(f**2)): V.insert(0, (chi, chi_inv, t)) return V eps = character if eps(-1) != (-1)**k: return [] eps = eps.maximize_base_ring() G = eps.parent() # Find all pairs chi, psi such that: # # (1) cond(chi)*cond(psi) divides the level, and # # (2) chi*psi == eps, where eps is the nebentypus character of self. # # See [Miyake, Modular Forms] Lemma 7.1.1. K = G.base_ring() C = {} t0 = misc.cputime() for e in G: m = Integer(e.conductor()) if m in C: C[m].append(e) else: C[m] = [e] misc.verbose("Enumeration with conductors.",t0) params = [] for L in divisors(N): misc.verbose("divisor %s"%L) if L not in C: continue GL = C[L] for R in divisors(N/L): if R not in C: continue GR = C[R] for chi in GL: for psi in GR: if chi*psi == eps: chi0, psi0 = __common_minimal_basering(chi, psi) for t in divisors(N//(R*L)): if k != 1 or ((psi0, chi0, t) not in params): params.append( (chi0,psi0,t) ) return params
def splitting_field(poly, name, map=False, degree_multiple=None, abort_degree=None, simplify=True, simplify_all=False): r""" Compute the splitting field of a given polynomial, defined over a number field. INPUT: - ``poly`` -- a monic polynomial over a number field - ``name`` -- a variable name for the number field - ``map`` -- (default: ``False``) also return an embedding of ``poly`` into the resulting field. Note that computing this embedding might be expensive. - ``degree_multiple`` -- a multiple of the absolute degree of the splitting field. If ``degree_multiple`` equals the actual degree, this can enormously speed up the computation. - ``abort_degree`` -- abort by raising a :class:`SplittingFieldAbort` if it can be determined that the absolute degree of the splitting field is strictly larger than ``abort_degree``. - ``simplify`` -- (default: ``True``) during the algorithm, try to find a simpler defining polynomial for the intermediate number fields using PARI's ``polred()``. This usually speeds up the computation but can also considerably slow it down. Try and see what works best in the given situation. - ``simplify_all`` -- (default: ``False``) If ``True``, simplify intermediate fields and also the resulting number field. OUTPUT: If ``map`` is ``False``, the splitting field as an absolute number field. If ``map`` is ``True``, a tuple ``(K, phi)`` where ``phi`` is an embedding of the base field in ``K``. EXAMPLES:: sage: R.<x> = PolynomialRing(QQ) sage: K.<a> = (x^3 + 2).splitting_field(); K Number Field in a with defining polynomial x^6 + 3*x^5 + 6*x^4 + 11*x^3 + 12*x^2 - 3*x + 1 sage: K.<a> = (x^3 - 3*x + 1).splitting_field(); K Number Field in a with defining polynomial x^3 - 3*x + 1 The ``simplify`` and ``simplify_all`` flags usually yield fields defined by polynomials with smaller coefficients. By default, ``simplify`` is True and ``simplify_all`` is False. :: sage: (x^4 - x + 1).splitting_field('a', simplify=False) Number Field in a with defining polynomial x^24 - 2780*x^22 + 2*x^21 + 3527512*x^20 - 2876*x^19 - 2701391985*x^18 + 945948*x^17 + 1390511639677*x^16 + 736757420*x^15 - 506816498313560*x^14 - 822702898220*x^13 + 134120588299548463*x^12 + 362240696528256*x^11 - 25964582366880639486*x^10 - 91743672243419990*x^9 + 3649429473447308439427*x^8 + 14310332927134072336*x^7 - 363192569823568746892571*x^6 - 1353403793640477725898*x^5 + 24293393281774560140427565*x^4 + 70673814899934142357628*x^3 - 980621447508959243128437933*x^2 - 1539841440617805445432660*x + 18065914012013502602456565991 sage: (x^4 - x + 1).splitting_field('a', simplify=True) Number Field in a with defining polynomial x^24 + 8*x^23 - 32*x^22 - 310*x^21 + 540*x^20 + 4688*x^19 - 6813*x^18 - 32380*x^17 + 49525*x^16 + 102460*x^15 - 129944*x^14 - 287884*x^13 + 372727*x^12 + 150624*x^11 - 110530*x^10 - 566926*x^9 + 1062759*x^8 - 779940*x^7 + 863493*x^6 - 1623578*x^5 + 1759513*x^4 - 955624*x^3 + 459975*x^2 - 141948*x + 53919 sage: (x^4 - x + 1).splitting_field('a', simplify_all=True) Number Field in a with defining polynomial x^24 - 3*x^23 + 2*x^22 - x^20 + 4*x^19 + 32*x^18 - 35*x^17 - 92*x^16 + 49*x^15 + 163*x^14 - 15*x^13 - 194*x^12 - 15*x^11 + 163*x^10 + 49*x^9 - 92*x^8 - 35*x^7 + 32*x^6 + 4*x^5 - x^4 + 2*x^2 - 3*x + 1 Reducible polynomials also work:: sage: pol = (x^4 - 1)*(x^2 + 1/2)*(x^2 + 1/3) sage: pol.splitting_field('a', simplify_all=True) Number Field in a with defining polynomial x^8 - x^4 + 1 Relative situation:: sage: R.<x> = PolynomialRing(QQ) sage: K.<a> = NumberField(x^3 + 2) sage: S.<t> = PolynomialRing(K) sage: L.<b> = (t^2 - a).splitting_field() sage: L Number Field in b with defining polynomial t^6 + 2 With ``map=True``, we also get the embedding of the base field into the splitting field:: sage: L.<b>, phi = (t^2 - a).splitting_field(map=True) sage: phi Ring morphism: From: Number Field in a with defining polynomial x^3 + 2 To: Number Field in b with defining polynomial t^6 + 2 Defn: a |--> b^2 sage: (x^4 - x + 1).splitting_field('a', simplify_all=True, map=True)[1] Ring morphism: From: Rational Field To: Number Field in a with defining polynomial x^24 - 3*x^23 + 2*x^22 - x^20 + 4*x^19 + 32*x^18 - 35*x^17 - 92*x^16 + 49*x^15 + 163*x^14 - 15*x^13 - 194*x^12 - 15*x^11 + 163*x^10 + 49*x^9 - 92*x^8 - 35*x^7 + 32*x^6 + 4*x^5 - x^4 + 2*x^2 - 3*x + 1 Defn: 1 |--> 1 We can enable verbose messages:: sage: from sage.misc.verbose import set_verbose sage: set_verbose(2) sage: K.<a> = (x^3 - x + 1).splitting_field() verbose 1 (...: splitting_field.py, splitting_field) Starting field: y verbose 1 (...: splitting_field.py, splitting_field) SplittingData to factor: [(3, 0)] verbose 2 (...: splitting_field.py, splitting_field) Done factoring (time = ...) verbose 1 (...: splitting_field.py, splitting_field) SplittingData to handle: [(2, 2), (3, 3)] verbose 1 (...: splitting_field.py, splitting_field) Bounds for absolute degree: [6, 6] verbose 2 (...: splitting_field.py, splitting_field) Handling polynomial x^2 + 23 verbose 1 (...: splitting_field.py, splitting_field) New field before simplifying: x^2 + 23 (time = ...) verbose 1 (...: splitting_field.py, splitting_field) New field: y^2 - y + 6 (time = ...) verbose 2 (...: splitting_field.py, splitting_field) Converted polynomials to new field (time = ...) verbose 1 (...: splitting_field.py, splitting_field) SplittingData to factor: [] verbose 2 (...: splitting_field.py, splitting_field) Done factoring (time = ...) verbose 1 (...: splitting_field.py, splitting_field) SplittingData to handle: [(3, 3)] verbose 1 (...: splitting_field.py, splitting_field) Bounds for absolute degree: [6, 6] verbose 2 (...: splitting_field.py, splitting_field) Handling polynomial x^3 - x + 1 verbose 1 (...: splitting_field.py, splitting_field) New field: y^6 + 3*y^5 + 19*y^4 + 35*y^3 + 127*y^2 + 73*y + 271 (time = ...) sage: set_verbose(0) Try all Galois groups in degree 4. We use a quadratic base field such that ``polgalois()`` cannot be used:: sage: R.<x> = PolynomialRing(QuadraticField(-11)) sage: C2C2pol = x^4 - 10*x^2 + 1 sage: C2C2pol.splitting_field('x') Number Field in x with defining polynomial x^8 + 24*x^6 + 608*x^4 + 9792*x^2 + 53824 sage: C4pol = x^4 + x^3 + x^2 + x + 1 sage: C4pol.splitting_field('x') Number Field in x with defining polynomial x^8 - x^7 - 2*x^6 + 5*x^5 + x^4 + 15*x^3 - 18*x^2 - 27*x + 81 sage: D8pol = x^4 - 2 sage: D8pol.splitting_field('x') Number Field in x with defining polynomial x^16 + 8*x^15 + 68*x^14 + 336*x^13 + 1514*x^12 + 5080*x^11 + 14912*x^10 + 35048*x^9 + 64959*x^8 + 93416*x^7 + 88216*x^6 + 41608*x^5 - 25586*x^4 - 60048*x^3 - 16628*x^2 + 12008*x + 34961 sage: A4pol = x^4 - 4*x^3 + 14*x^2 - 28*x + 21 sage: A4pol.splitting_field('x') Number Field in x with defining polynomial x^24 - 20*x^23 + 290*x^22 - 3048*x^21 + 26147*x^20 - 186132*x^19 + 1130626*x^18 - 5913784*x^17 + 26899345*x^16 - 106792132*x^15 + 371066538*x^14 - 1127792656*x^13 + 2991524876*x^12 - 6888328132*x^11 + 13655960064*x^10 - 23000783036*x^9 + 32244796382*x^8 - 36347834476*x^7 + 30850889884*x^6 - 16707053128*x^5 + 1896946429*x^4 + 4832907884*x^3 - 3038258802*x^2 - 200383596*x + 593179173 sage: S4pol = x^4 + x + 1 sage: S4pol.splitting_field('x') Number Field in x with defining polynomial x^48 ... Some bigger examples:: sage: R.<x> = PolynomialRing(QQ) sage: pol15 = chebyshev_T(31, x) - 1 # 2^30*(x-1)*minpoly(cos(2*pi/31))^2 sage: pol15.splitting_field('a') Number Field in a with defining polynomial x^15 - x^14 - 14*x^13 + 13*x^12 + 78*x^11 - 66*x^10 - 220*x^9 + 165*x^8 + 330*x^7 - 210*x^6 - 252*x^5 + 126*x^4 + 84*x^3 - 28*x^2 - 8*x + 1 sage: pol48 = x^6 - 4*x^4 + 12*x^2 - 12 sage: pol48.splitting_field('a') Number Field in a with defining polynomial x^48 ... If you somehow know the degree of the field in advance, you should add a ``degree_multiple`` argument. This can speed up the computation, in particular for polynomials of degree >= 12 or for relative extensions:: sage: pol15.splitting_field('a', degree_multiple=15) Number Field in a with defining polynomial x^15 + x^14 - 14*x^13 - 13*x^12 + 78*x^11 + 66*x^10 - 220*x^9 - 165*x^8 + 330*x^7 + 210*x^6 - 252*x^5 - 126*x^4 + 84*x^3 + 28*x^2 - 8*x - 1 A value for ``degree_multiple`` which isn't actually a multiple of the absolute degree of the splitting field can either result in a wrong answer or the following exception:: sage: pol48.splitting_field('a', degree_multiple=20) Traceback (most recent call last): ... ValueError: inconsistent degree_multiple in splitting_field() Compute the Galois closure as the splitting field of the defining polynomial:: sage: R.<x> = PolynomialRing(QQ) sage: pol48 = x^6 - 4*x^4 + 12*x^2 - 12 sage: K.<a> = NumberField(pol48) sage: L.<b> = pol48.change_ring(K).splitting_field() sage: L Number Field in b with defining polynomial x^48 ... Try all Galois groups over `\QQ` in degree 5 except for `S_5` (the latter is infeasible with the current implementation):: sage: C5pol = x^5 + x^4 - 4*x^3 - 3*x^2 + 3*x + 1 sage: C5pol.splitting_field('x') Number Field in x with defining polynomial x^5 + x^4 - 4*x^3 - 3*x^2 + 3*x + 1 sage: D10pol = x^5 - x^4 - 5*x^3 + 4*x^2 + 3*x - 1 sage: D10pol.splitting_field('x') Number Field in x with defining polynomial x^10 - 28*x^8 + 216*x^6 - 681*x^4 + 902*x^2 - 401 sage: AGL_1_5pol = x^5 - 2 sage: AGL_1_5pol.splitting_field('x') Number Field in x with defining polynomial x^20 + 10*x^19 + 55*x^18 + 210*x^17 + 595*x^16 + 1300*x^15 + 2250*x^14 + 3130*x^13 + 3585*x^12 + 3500*x^11 + 2965*x^10 + 2250*x^9 + 1625*x^8 + 1150*x^7 + 750*x^6 + 400*x^5 + 275*x^4 + 100*x^3 + 75*x^2 + 25 sage: A5pol = x^5 - x^4 + 2*x^2 - 2*x + 2 sage: A5pol.splitting_field('x') Number Field in x with defining polynomial x^60 ... We can use the ``abort_degree`` option if we don't want to compute fields of too large degree (this can be used to check whether the splitting field has small degree):: sage: (x^5+x+3).splitting_field('b', abort_degree=119) Traceback (most recent call last): ... SplittingFieldAbort: degree of splitting field equals 120 sage: (x^10+x+3).splitting_field('b', abort_degree=60) # long time (10s on sage.math, 2014) Traceback (most recent call last): ... SplittingFieldAbort: degree of splitting field is a multiple of 180 Use the ``degree_divisor`` attribute to recover the divisor of the degree of the splitting field or ``degree_multiple`` to recover a multiple:: sage: from sage.rings.number_field.splitting_field import SplittingFieldAbort sage: try: # long time (4s on sage.math, 2014) ....: (x^8+x+1).splitting_field('b', abort_degree=60, simplify=False) ....: except SplittingFieldAbort as e: ....: print(e.degree_divisor) ....: print(e.degree_multiple) 120 1440 TESTS:: sage: from sage.rings.number_field.splitting_field import splitting_field sage: splitting_field(polygen(QQ), name='x', map=True, simplify_all=True) (Number Field in x with defining polynomial x, Ring morphism: From: Rational Field To: Number Field in x with defining polynomial x Defn: 1 |--> 1) """ from sage.misc.all import cputime from sage.misc.verbose import verbose degree_multiple = Integer(degree_multiple or 0) abort_degree = Integer(abort_degree or 0) # Kpol = PARI polynomial in y defining the extension found so far F = poly.base_ring() if is_RationalField(F): Kpol = pari("'y") else: Kpol = F.pari_polynomial("y") # Fgen = the generator of F as element of Q[y]/Kpol # (only needed if map=True) if map: Fgen = F.gen().__pari__() verbose("Starting field: %s" % Kpol) # L and Lred are lists of SplittingData. # L contains polynomials which are irreducible over K, # Lred contains polynomials which need to be factored. L = [] Lred = [SplittingData(poly._pari_with_name(), degree_multiple)] # Main loop, handle polynomials one by one while True: # Absolute degree of current field K absolute_degree = Integer(Kpol.poldegree()) # Compute minimum relative degree of splitting field rel_degree_divisor = Integer(1) for splitting in L: rel_degree_divisor = rel_degree_divisor.lcm(splitting.poldegree()) # Check for early aborts abort_rel_degree = abort_degree // absolute_degree if abort_rel_degree and rel_degree_divisor > abort_rel_degree: raise SplittingFieldAbort(absolute_degree * rel_degree_divisor, degree_multiple) # First, factor polynomials in Lred and store the result in L verbose("SplittingData to factor: %s" % [s._repr_tuple() for s in Lred]) t = cputime() for splitting in Lred: m = splitting.dm.gcd(degree_multiple).gcd( factorial(splitting.poldegree())) if m == 1: continue factors = Kpol.nffactor(splitting.pol)[0] for q in factors: d = q.poldegree() fac = factorial(d) # Multiple of the degree of the splitting field of q, # note that the degree equals fac iff the Galois group is S_n. mq = m.gcd(fac) if mq == 1: continue # Multiple of the degree of the splitting field of q # over the field defined by adding square root of the # discriminant. # If the Galois group is contained in A_n, then mq_alt is # also the degree multiple over the current field K. # Here, we have equality if the Galois group is A_n. mq_alt = mq.gcd(fac // 2) # If we are over Q, then use PARI's polgalois() to compute # these degrees exactly. if absolute_degree == 1: try: G = q.polgalois() except PariError: pass else: mq = Integer(G[0]) mq_alt = mq // 2 if (G[1] == -1) else mq # In degree 4, use the cubic resolvent to refine the # degree bounds. if d == 4 and mq >= 12: # mq equals 12 or 24 # Compute cubic resolvent a0, a1, a2, a3, a4 = (q / q.pollead()).Vecrev() assert a4 == 1 cubicpol = pari([ 4 * a0 * a2 - a1 * a1 - a0 * a3 * a3, a1 * a3 - 4 * a0, -a2, 1 ]).Polrev() cubicfactors = Kpol.nffactor(cubicpol)[0] if len(cubicfactors) == 1: # A4 or S4 # After adding a root of the cubic resolvent, # the degree of the extension defined by q # is a factor 3 smaller. L.append(SplittingData(cubicpol, 3)) rel_degree_divisor = rel_degree_divisor.lcm(3) mq = mq // 3 # 4 or 8 mq_alt = 4 elif len(cubicfactors) == 2: # C4 or D8 # The irreducible degree 2 factor is # equivalent to x^2 - q.poldisc(). discpol = cubicfactors[1] L.append(SplittingData(discpol, 2)) mq = mq_alt = 4 else: # C2 x C2 mq = mq_alt = 4 if mq > mq_alt >= 3: # Add quadratic resolvent x^2 - D to decrease # the degree multiple by a factor 2. discpol = pari([-q.poldisc(), 0, 1]).Polrev() discfactors = Kpol.nffactor(discpol)[0] if len(discfactors) == 1: # Discriminant is not a square L.append(SplittingData(discpol, 2)) rel_degree_divisor = rel_degree_divisor.lcm(2) mq = mq_alt L.append(SplittingData(q, mq)) rel_degree_divisor = rel_degree_divisor.lcm(q.poldegree()) if abort_rel_degree and rel_degree_divisor > abort_rel_degree: raise SplittingFieldAbort( absolute_degree * rel_degree_divisor, degree_multiple) verbose("Done factoring", t, level=2) if len(L) == 0: # Nothing left to do break # Recompute absolute degree multiple new_degree_multiple = absolute_degree for splitting in L: new_degree_multiple *= splitting.dm degree_multiple = new_degree_multiple.gcd(degree_multiple) # Absolute degree divisor degree_divisor = rel_degree_divisor * absolute_degree # Sort according to degree to handle low degrees first L.sort(key=lambda x: x.key()) verbose("SplittingData to handle: %s" % [s._repr_tuple() for s in L]) verbose("Bounds for absolute degree: [%s, %s]" % (degree_divisor, degree_multiple)) # Check consistency if degree_multiple % degree_divisor != 0: raise ValueError( "inconsistent degree_multiple in splitting_field()") for splitting in L: # The degree of the splitting field must be a multiple of # the degree of the polynomial. Only do this check for # SplittingData with minimal dm, because the higher dm are # defined as relative degree over the splitting field of # the polynomials with lesser dm. if splitting.dm > L[0].dm: break if splitting.dm % splitting.poldegree() != 0: raise ValueError( "inconsistent degree_multiple in splitting_field()") # Add a root of f = L[0] to construct the field N = K[x]/f(x) splitting = L[0] f = splitting.pol verbose("Handling polynomial %s" % (f.lift()), level=2) t = cputime() Npol, KtoN, k = Kpol.rnfequation(f, flag=1) # Make Npol monic integral primitive, store in Mpol # (after this, we don't need Npol anymore, only Mpol) Mdiv = pari(1) Mpol = Npol while True: denom = Integer(Mpol.pollead()) if denom == 1: break denom = pari(denom.factor().radical_value()) Mpol = (Mpol * (denom**Mpol.poldegree())).subst( "x", pari([0, 1 / denom]).Polrev("x")) Mpol /= Mpol.content() Mdiv *= denom # We are finished for sure if we hit the degree bound finished = (Mpol.poldegree() >= degree_multiple) if simplify_all or (simplify and not finished): # Find a simpler defining polynomial Lpol for Mpol verbose("New field before simplifying: %s" % Mpol, t) t = cputime() M = Mpol.polred(flag=3) n = len(M[0]) - 1 Lpol = M[1][n].change_variable_name("y") LtoM = M[0][n].change_variable_name("y").Mod( Mpol.change_variable_name("y")) MtoL = LtoM.modreverse() else: # Lpol = Mpol Lpol = Mpol.change_variable_name("y") MtoL = pari("'y") NtoL = MtoL / Mdiv KtoL = KtoN.lift().subst("x", NtoL).Mod(Lpol) Kpol = Lpol # New Kpol (for next iteration) verbose("New field: %s" % Kpol, t) if map: t = cputime() Fgen = Fgen.lift().subst("y", KtoL) verbose("Computed generator of F in K", t, level=2) if finished: break t = cputime() # Convert f and elements of L from K to L and store in L # (if the polynomial is certain to remain irreducible) or Lred. Lold = L[1:] L = [] Lred = [] # First add f divided by the linear factor we obtained, # mg is the new degree multiple. mg = splitting.dm // f.poldegree() if mg > 1: g = [c.subst("y", KtoL).Mod(Lpol) for c in f.Vecrev().lift()] g = pari(g).Polrev() g /= pari([k * KtoL - NtoL, 1]).Polrev() # divide linear factor Lred.append(SplittingData(g, mg)) for splitting in Lold: g = [c.subst("y", KtoL) for c in splitting.pol.Vecrev().lift()] g = pari(g).Polrev() mg = splitting.dm if Integer(g.poldegree()).gcd( f.poldegree()) == 1: # linearly disjoint fields L.append(SplittingData(g, mg)) else: Lred.append(SplittingData(g, mg)) verbose("Converted polynomials to new field", t, level=2) # Convert Kpol to Sage and construct the absolute number field Kpol = PolynomialRing(RationalField(), name=poly.variable_name())(Kpol / Kpol.pollead()) K = NumberField(Kpol, name) if map: return K, F.hom(Fgen, K) else: return K
def __find_eisen_chars(character, k): """ Find all triples `(\psi_1, \psi_2, t)` that give rise to an Eisenstein series of the given weight and character. EXAMPLES:: sage: sage.modular.modform.eis_series.__find_eisen_chars(DirichletGroup(36).0, 4) [] sage: pars = sage.modular.modform.eis_series.__find_eisen_chars(DirichletGroup(36).0, 5) sage: [(x[0].values_on_gens(), x[1].values_on_gens(), x[2]) for x in pars] [((1, 1), (-1, 1), 1), ((1, 1), (-1, 1), 3), ((1, 1), (-1, 1), 9), ((1, -1), (-1, -1), 1), ((-1, 1), (1, 1), 1), ((-1, 1), (1, 1), 3), ((-1, 1), (1, 1), 9), ((-1, -1), (1, -1), 1)] """ N = character.modulus() if character.is_trivial(): if k%2 != 0: return [] char_inv = ~character V = [(character, char_inv, t) for t in divisors(N) if t>1] if k != 2: V.insert(0,(character, char_inv, 1)) if is_squarefree(N): return V # Now include all pairs (chi,chi^(-1)) such that cond(chi)^2 divides N: # TODO: Optimize -- this is presumably way too hard work below. G = dirichlet.DirichletGroup(N) for chi in G: if not chi.is_trivial(): f = chi.conductor() if N % (f**2) == 0: chi = chi.minimize_base_ring() chi_inv = ~chi for t in divisors(N//(f**2)): V.insert(0, (chi, chi_inv, t)) return V eps = character if eps(-1) != (-1)**k: return [] eps = eps.maximize_base_ring() G = eps.parent() # Find all pairs chi, psi such that: # # (1) cond(chi)*cond(psi) divides the level, and # # (2) chi*psi == eps, where eps is the nebentypus character of self. # # See [Miyake, Modular Forms] Lemma 7.1.1. K = G.base_ring() C = {} t0 = cputime() for e in G: m = Integer(e.conductor()) if m in C: C[m].append(e) else: C[m] = [e] verbose("Enumeration with conductors.", t0) params = [] for L in divisors(N): verbose("divisor %s" % L) if L not in C: continue GL = C[L] for R in divisors(N/L): if R not in C: continue GR = C[R] for chi in GL: for psi in GR: if chi*psi == eps: chi0, psi0 = __common_minimal_basering(chi, psi) for t in divisors(N//(R*L)): if k != 1 or ((psi0, chi0, t) not in params): params.append( (chi0,psi0,t) ) return params
def splitting_field(poly, name, map=False, degree_multiple=None, abort_degree=None, simplify=True, simplify_all=False): """ Compute the splitting field of a given polynomial, defined over a number field. INPUT: - ``poly`` -- a monic polynomial over a number field - ``name`` -- a variable name for the number field - ``map`` -- (default: ``False``) also return an embedding of ``poly`` into the resulting field. Note that computing this embedding might be expensive. - ``degree_multiple`` -- a multiple of the absolute degree of the splitting field. If ``degree_multiple`` equals the actual degree, this can enormously speed up the computation. - ``abort_degree`` -- abort by raising a :class:`SplittingFieldAbort` if it can be determined that the absolute degree of the splitting field is strictly larger than ``abort_degree``. - ``simplify`` -- (default: ``True``) during the algorithm, try to find a simpler defining polynomial for the intermediate number fields using PARI's ``polred()``. This usually speeds up the computation but can also considerably slow it down. Try and see what works best in the given situation. - ``simplify_all`` -- (default: ``False``) If ``True``, simplify intermediate fields and also the resulting number field. OUTPUT: If ``map`` is ``False``, the splitting field as an absolute number field. If ``map`` is ``True``, a tuple ``(K, phi)`` where ``phi`` is an embedding of the base field in ``K``. EXAMPLES:: sage: R.<x> = PolynomialRing(QQ) sage: K.<a> = (x^3 + 2).splitting_field(); K Number Field in a with defining polynomial x^6 + 3*x^5 + 6*x^4 + 11*x^3 + 12*x^2 - 3*x + 1 sage: K.<a> = (x^3 - 3*x + 1).splitting_field(); K Number Field in a with defining polynomial x^3 - 3*x + 1 The ``simplify`` and ``simplify_all`` flags usually yield fields defined by polynomials with smaller coefficients. By default, ``simplify`` is True and ``simplify_all`` is False. :: sage: (x^4 - x + 1).splitting_field('a', simplify=False) Number Field in a with defining polynomial x^24 - 2780*x^22 + 2*x^21 + 3527512*x^20 - 2876*x^19 - 2701391985*x^18 + 945948*x^17 + 1390511639677*x^16 + 736757420*x^15 - 506816498313560*x^14 - 822702898220*x^13 + 134120588299548463*x^12 + 362240696528256*x^11 - 25964582366880639486*x^10 - 91743672243419990*x^9 + 3649429473447308439427*x^8 + 14310332927134072336*x^7 - 363192569823568746892571*x^6 - 1353403793640477725898*x^5 + 24293393281774560140427565*x^4 + 70673814899934142357628*x^3 - 980621447508959243128437933*x^2 - 1539841440617805445432660*x + 18065914012013502602456565991 sage: (x^4 - x + 1).splitting_field('a', simplify=True) Number Field in a with defining polynomial x^24 + 8*x^23 - 32*x^22 - 310*x^21 + 540*x^20 + 4688*x^19 - 6813*x^18 - 32380*x^17 + 49525*x^16 + 102460*x^15 - 129944*x^14 - 287884*x^13 + 372727*x^12 + 150624*x^11 - 110530*x^10 - 566926*x^9 + 1062759*x^8 - 779940*x^7 + 863493*x^6 - 1623578*x^5 + 1759513*x^4 - 955624*x^3 + 459975*x^2 - 141948*x + 53919 sage: (x^4 - x + 1).splitting_field('a', simplify_all=True) Number Field in a with defining polynomial x^24 - 3*x^23 + 2*x^22 - x^20 + 4*x^19 + 32*x^18 - 35*x^17 - 92*x^16 + 49*x^15 + 163*x^14 - 15*x^13 - 194*x^12 - 15*x^11 + 163*x^10 + 49*x^9 - 92*x^8 - 35*x^7 + 32*x^6 + 4*x^5 - x^4 + 2*x^2 - 3*x + 1 Reducible polynomials also work:: sage: pol = (x^4 - 1)*(x^2 + 1/2)*(x^2 + 1/3) sage: pol.splitting_field('a', simplify_all=True) Number Field in a with defining polynomial x^8 - x^4 + 1 Relative situation:: sage: R.<x> = PolynomialRing(QQ) sage: K.<a> = NumberField(x^3 + 2) sage: S.<t> = PolynomialRing(K) sage: L.<b> = (t^2 - a).splitting_field() sage: L Number Field in b with defining polynomial t^6 + 2 With ``map=True``, we also get the embedding of the base field into the splitting field:: sage: L.<b>, phi = (t^2 - a).splitting_field(map=True) sage: phi Ring morphism: From: Number Field in a with defining polynomial x^3 + 2 To: Number Field in b with defining polynomial t^6 + 2 Defn: a |--> b^2 sage: (x^4 - x + 1).splitting_field('a', simplify_all=True, map=True)[1] Ring morphism: From: Rational Field To: Number Field in a with defining polynomial x^24 - 3*x^23 + 2*x^22 - x^20 + 4*x^19 + 32*x^18 - 35*x^17 - 92*x^16 + 49*x^15 + 163*x^14 - 15*x^13 - 194*x^12 - 15*x^11 + 163*x^10 + 49*x^9 - 92*x^8 - 35*x^7 + 32*x^6 + 4*x^5 - x^4 + 2*x^2 - 3*x + 1 Defn: 1 |--> 1 We can enable verbose messages:: sage: set_verbose(2) sage: K.<a> = (x^3 - x + 1).splitting_field() verbose 1 (...: splitting_field.py, splitting_field) Starting field: y verbose 1 (...: splitting_field.py, splitting_field) SplittingData to factor: [(3, 0)] verbose 2 (...: splitting_field.py, splitting_field) Done factoring (time = ...) verbose 1 (...: splitting_field.py, splitting_field) SplittingData to handle: [(2, 2), (3, 3)] verbose 1 (...: splitting_field.py, splitting_field) Bounds for absolute degree: [6, 6] verbose 2 (...: splitting_field.py, splitting_field) Handling polynomial x^2 + 23 verbose 1 (...: splitting_field.py, splitting_field) New field before simplifying: x^2 + 23 (time = ...) verbose 1 (...: splitting_field.py, splitting_field) New field: y^2 - y + 6 (time = ...) verbose 2 (...: splitting_field.py, splitting_field) Converted polynomials to new field (time = ...) verbose 1 (...: splitting_field.py, splitting_field) SplittingData to factor: [] verbose 2 (...: splitting_field.py, splitting_field) Done factoring (time = ...) verbose 1 (...: splitting_field.py, splitting_field) SplittingData to handle: [(3, 3)] verbose 1 (...: splitting_field.py, splitting_field) Bounds for absolute degree: [6, 6] verbose 2 (...: splitting_field.py, splitting_field) Handling polynomial x^3 - x + 1 verbose 1 (...: splitting_field.py, splitting_field) New field: y^6 + 3*y^5 + 19*y^4 + 35*y^3 + 127*y^2 + 73*y + 271 (time = ...) sage: set_verbose(0) Try all Galois groups in degree 4. We use a quadratic base field such that ``polgalois()`` cannot be used:: sage: R.<x> = PolynomialRing(QuadraticField(-11)) sage: C2C2pol = x^4 - 10*x^2 + 1 sage: C2C2pol.splitting_field('x') Number Field in x with defining polynomial x^8 + 24*x^6 + 608*x^4 + 9792*x^2 + 53824 sage: C4pol = x^4 + x^3 + x^2 + x + 1 sage: C4pol.splitting_field('x') Number Field in x with defining polynomial x^8 - x^7 - 2*x^6 + 5*x^5 + x^4 + 15*x^3 - 18*x^2 - 27*x + 81 sage: D8pol = x^4 - 2 sage: D8pol.splitting_field('x') Number Field in x with defining polynomial x^16 + 8*x^15 + 68*x^14 + 336*x^13 + 1514*x^12 + 5080*x^11 + 14912*x^10 + 35048*x^9 + 64959*x^8 + 93416*x^7 + 88216*x^6 + 41608*x^5 - 25586*x^4 - 60048*x^3 - 16628*x^2 + 12008*x + 34961 sage: A4pol = x^4 - 4*x^3 + 14*x^2 - 28*x + 21 sage: A4pol.splitting_field('x') Number Field in x with defining polynomial x^24 - 20*x^23 + 290*x^22 - 3048*x^21 + 26147*x^20 - 186132*x^19 + 1130626*x^18 - 5913784*x^17 + 26899345*x^16 - 106792132*x^15 + 371066538*x^14 - 1127792656*x^13 + 2991524876*x^12 - 6888328132*x^11 + 13655960064*x^10 - 23000783036*x^9 + 32244796382*x^8 - 36347834476*x^7 + 30850889884*x^6 - 16707053128*x^5 + 1896946429*x^4 + 4832907884*x^3 - 3038258802*x^2 - 200383596*x + 593179173 sage: S4pol = x^4 + x + 1 sage: S4pol.splitting_field('x') Number Field in x with defining polynomial x^48 ... Some bigger examples:: sage: R.<x> = PolynomialRing(QQ) sage: pol15 = chebyshev_T(31, x) - 1 # 2^30*(x-1)*minpoly(cos(2*pi/31))^2 sage: pol15.splitting_field('a') Number Field in a with defining polynomial x^15 - x^14 - 14*x^13 + 13*x^12 + 78*x^11 - 66*x^10 - 220*x^9 + 165*x^8 + 330*x^7 - 210*x^6 - 252*x^5 + 126*x^4 + 84*x^3 - 28*x^2 - 8*x + 1 sage: pol48 = x^6 - 4*x^4 + 12*x^2 - 12 sage: pol48.splitting_field('a') Number Field in a with defining polynomial x^48 ... If you somehow know the degree of the field in advance, you should add a ``degree_multiple`` argument. This can speed up the computation, in particular for polynomials of degree >= 12 or for relative extensions:: sage: pol15.splitting_field('a', degree_multiple=15) Number Field in a with defining polynomial x^15 + x^14 - 14*x^13 - 13*x^12 + 78*x^11 + 66*x^10 - 220*x^9 - 165*x^8 + 330*x^7 + 210*x^6 - 252*x^5 - 126*x^4 + 84*x^3 + 28*x^2 - 8*x - 1 A value for ``degree_multiple`` which isn't actually a multiple of the absolute degree of the splitting field can either result in a wrong answer or the following exception:: sage: pol48.splitting_field('a', degree_multiple=20) Traceback (most recent call last): ... ValueError: inconsistent degree_multiple in splitting_field() Compute the Galois closure as the splitting field of the defining polynomial:: sage: R.<x> = PolynomialRing(QQ) sage: pol48 = x^6 - 4*x^4 + 12*x^2 - 12 sage: K.<a> = NumberField(pol48) sage: L.<b> = pol48.change_ring(K).splitting_field() sage: L Number Field in b with defining polynomial x^48 ... Try all Galois groups over `\QQ` in degree 5 except for `S_5` (the latter is infeasible with the current implementation):: sage: C5pol = x^5 + x^4 - 4*x^3 - 3*x^2 + 3*x + 1 sage: C5pol.splitting_field('x') Number Field in x with defining polynomial x^5 + x^4 - 4*x^3 - 3*x^2 + 3*x + 1 sage: D10pol = x^5 - x^4 - 5*x^3 + 4*x^2 + 3*x - 1 sage: D10pol.splitting_field('x') Number Field in x with defining polynomial x^10 - 28*x^8 + 216*x^6 - 681*x^4 + 902*x^2 - 401 sage: AGL_1_5pol = x^5 - 2 sage: AGL_1_5pol.splitting_field('x') Number Field in x with defining polynomial x^20 + 10*x^19 + 55*x^18 + 210*x^17 + 595*x^16 + 1300*x^15 + 2250*x^14 + 3130*x^13 + 3585*x^12 + 3500*x^11 + 2965*x^10 + 2250*x^9 + 1625*x^8 + 1150*x^7 + 750*x^6 + 400*x^5 + 275*x^4 + 100*x^3 + 75*x^2 + 25 sage: A5pol = x^5 - x^4 + 2*x^2 - 2*x + 2 sage: A5pol.splitting_field('x') Number Field in x with defining polynomial x^60 ... We can use the ``abort_degree`` option if we don't want to compute fields of too large degree (this can be used to check whether the splitting field has small degree):: sage: (x^5+x+3).splitting_field('b', abort_degree=119) Traceback (most recent call last): ... SplittingFieldAbort: degree of splitting field equals 120 sage: (x^10+x+3).splitting_field('b', abort_degree=60) # long time (10s on sage.math, 2014) Traceback (most recent call last): ... SplittingFieldAbort: degree of splitting field is a multiple of 180 Use the ``degree_divisor`` attribute to recover the divisor of the degree of the splitting field or ``degree_multiple`` to recover a multiple:: sage: from sage.rings.number_field.splitting_field import SplittingFieldAbort sage: try: # long time (4s on sage.math, 2014) ....: (x^8+x+1).splitting_field('b', abort_degree=60, simplify=False) ....: except SplittingFieldAbort as e: ....: print(e.degree_divisor) ....: print(e.degree_multiple) 120 1440 TESTS:: sage: from sage.rings.number_field.splitting_field import splitting_field sage: splitting_field(polygen(QQ), name='x', map=True, simplify_all=True) (Number Field in x with defining polynomial x, Ring morphism: From: Rational Field To: Number Field in x with defining polynomial x Defn: 1 |--> 1) """ from sage.misc.all import verbose, cputime degree_multiple = Integer(degree_multiple or 0) abort_degree = Integer(abort_degree or 0) # Kpol = PARI polynomial in y defining the extension found so far F = poly.base_ring() if is_RationalField(F): Kpol = pari("'y") else: Kpol = F.pari_polynomial("y") # Fgen = the generator of F as element of Q[y]/Kpol # (only needed if map=True) if map: Fgen = F.gen().__pari__() verbose("Starting field: %s"%Kpol) # L and Lred are lists of SplittingData. # L contains polynomials which are irreducible over K, # Lred contains polynomials which need to be factored. L = [] Lred = [SplittingData(poly._pari_with_name(), degree_multiple)] # Main loop, handle polynomials one by one while True: # Absolute degree of current field K absolute_degree = Integer(Kpol.poldegree()) # Compute minimum relative degree of splitting field rel_degree_divisor = Integer(1) for splitting in L: rel_degree_divisor = rel_degree_divisor.lcm(splitting.poldegree()) # Check for early aborts abort_rel_degree = abort_degree//absolute_degree if abort_rel_degree and rel_degree_divisor > abort_rel_degree: raise SplittingFieldAbort(absolute_degree * rel_degree_divisor, degree_multiple) # First, factor polynomials in Lred and store the result in L verbose("SplittingData to factor: %s"%[s._repr_tuple() for s in Lred]) t = cputime() for splitting in Lred: m = splitting.dm.gcd(degree_multiple).gcd(factorial(splitting.poldegree())) if m == 1: continue factors = Kpol.nffactor(splitting.pol)[0] for q in factors: d = q.poldegree() fac = factorial(d) # Multiple of the degree of the splitting field of q, # note that the degree equals fac iff the Galois group is S_n. mq = m.gcd(fac) if mq == 1: continue # Multiple of the degree of the splitting field of q # over the field defined by adding square root of the # discriminant. # If the Galois group is contained in A_n, then mq_alt is # also the degree multiple over the current field K. # Here, we have equality if the Galois group is A_n. mq_alt = mq.gcd(fac//2) # If we are over Q, then use PARI's polgalois() to compute # these degrees exactly. if absolute_degree == 1: try: G = q.polgalois() except PariError: pass else: mq = Integer(G[0]) mq_alt = mq//2 if (G[1] == -1) else mq # In degree 4, use the cubic resolvent to refine the # degree bounds. if d == 4 and mq >= 12: # mq equals 12 or 24 # Compute cubic resolvent a0, a1, a2, a3, a4 = (q/q.pollead()).Vecrev() assert a4 == 1 cubicpol = pari([4*a0*a2 - a1*a1 -a0*a3*a3, a1*a3 - 4*a0, -a2, 1]).Polrev() cubicfactors = Kpol.nffactor(cubicpol)[0] if len(cubicfactors) == 1: # A4 or S4 # After adding a root of the cubic resolvent, # the degree of the extension defined by q # is a factor 3 smaller. L.append(SplittingData(cubicpol, 3)) rel_degree_divisor = rel_degree_divisor.lcm(3) mq = mq//3 # 4 or 8 mq_alt = 4 elif len(cubicfactors) == 2: # C4 or D8 # The irreducible degree 2 factor is # equivalent to x^2 - q.poldisc(). discpol = cubicfactors[1] L.append(SplittingData(discpol, 2)) mq = mq_alt = 4 else: # C2 x C2 mq = mq_alt = 4 if mq > mq_alt >= 3: # Add quadratic resolvent x^2 - D to decrease # the degree multiple by a factor 2. discpol = pari([-q.poldisc(), 0, 1]).Polrev() discfactors = Kpol.nffactor(discpol)[0] if len(discfactors) == 1: # Discriminant is not a square L.append(SplittingData(discpol, 2)) rel_degree_divisor = rel_degree_divisor.lcm(2) mq = mq_alt L.append(SplittingData(q, mq)) rel_degree_divisor = rel_degree_divisor.lcm(q.poldegree()) if abort_rel_degree and rel_degree_divisor > abort_rel_degree: raise SplittingFieldAbort(absolute_degree * rel_degree_divisor, degree_multiple) verbose("Done factoring", t, level=2) if len(L) == 0: # Nothing left to do break # Recompute absolute degree multiple new_degree_multiple = absolute_degree for splitting in L: new_degree_multiple *= splitting.dm degree_multiple = new_degree_multiple.gcd(degree_multiple) # Absolute degree divisor degree_divisor = rel_degree_divisor * absolute_degree # Sort according to degree to handle low degrees first L.sort(key=lambda x: x.key()) verbose("SplittingData to handle: %s"%[s._repr_tuple() for s in L]) verbose("Bounds for absolute degree: [%s, %s]"%(degree_divisor,degree_multiple)) # Check consistency if degree_multiple % degree_divisor != 0: raise ValueError("inconsistent degree_multiple in splitting_field()") for splitting in L: # The degree of the splitting field must be a multiple of # the degree of the polynomial. Only do this check for # SplittingData with minimal dm, because the higher dm are # defined as relative degree over the splitting field of # the polynomials with lesser dm. if splitting.dm > L[0].dm: break if splitting.dm % splitting.poldegree() != 0: raise ValueError("inconsistent degree_multiple in splitting_field()") # Add a root of f = L[0] to construct the field N = K[x]/f(x) splitting = L[0] f = splitting.pol verbose("Handling polynomial %s"%(f.lift()), level=2) t = cputime() Npol, KtoN, k = Kpol.rnfequation(f, flag=1) # Make Npol monic integral primitive, store in Mpol # (after this, we don't need Npol anymore, only Mpol) Mdiv = pari(1) Mpol = Npol while True: denom = Integer(Mpol.pollead()) if denom == 1: break denom = pari(denom.factor().radical_value()) Mpol = (Mpol*(denom**Mpol.poldegree())).subst("x", pari([0,1/denom]).Polrev("x")) Mpol /= Mpol.content() Mdiv *= denom # We are finished for sure if we hit the degree bound finished = (Mpol.poldegree() >= degree_multiple) if simplify_all or (simplify and not finished): # Find a simpler defining polynomial Lpol for Mpol verbose("New field before simplifying: %s"%Mpol, t) t = cputime() M = Mpol.polred(flag=3) n = len(M[0])-1 Lpol = M[1][n].change_variable_name("y") LtoM = M[0][n].change_variable_name("y").Mod(Mpol.change_variable_name("y")) MtoL = LtoM.modreverse() else: # Lpol = Mpol Lpol = Mpol.change_variable_name("y") MtoL = pari("'y") NtoL = MtoL/Mdiv KtoL = KtoN.lift().subst("x", NtoL).Mod(Lpol) Kpol = Lpol # New Kpol (for next iteration) verbose("New field: %s"%Kpol, t) if map: t = cputime() Fgen = Fgen.lift().subst("y", KtoL) verbose("Computed generator of F in K", t, level=2) if finished: break t = cputime() # Convert f and elements of L from K to L and store in L # (if the polynomial is certain to remain irreducible) or Lred. Lold = L[1:] L = [] Lred = [] # First add f divided by the linear factor we obtained, # mg is the new degree multiple. mg = splitting.dm//f.poldegree() if mg > 1: g = [c.subst("y", KtoL).Mod(Lpol) for c in f.Vecrev().lift()] g = pari(g).Polrev() g /= pari([k*KtoL - NtoL, 1]).Polrev() # divide linear factor Lred.append(SplittingData(g, mg)) for splitting in Lold: g = [c.subst("y", KtoL) for c in splitting.pol.Vecrev().lift()] g = pari(g).Polrev() mg = splitting.dm if Integer(g.poldegree()).gcd(f.poldegree()) == 1: # linearly disjoint fields L.append(SplittingData(g, mg)) else: Lred.append(SplittingData(g, mg)) verbose("Converted polynomials to new field", t, level=2) # Convert Kpol to Sage and construct the absolute number field Kpol = PolynomialRing(RationalField(), name=poly.variable_name())(Kpol/Kpol.pollead()) K = NumberField(Kpol, name) if map: return K, F.hom(Fgen, K) else: return K
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 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 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