Path: blob/master/src/sage/modular/modform/eis_series.py
8820 views
# -*- coding: utf-8 -*-1"""2Eisenstein Series3"""45#########################################################################6# Copyright (C) 2004--2006 William Stein <[email protected]>7#8# Distributed under the terms of the GNU General Public License (GPL)9#10# http://www.gnu.org/licenses/11#########################################################################1213import sage.misc.all as misc1415import sage.modular.dirichlet as dirichlet1617from sage.modular.arithgroup.congroup_gammaH import GammaH_class1819from sage.rings.all import Integer2021from sage.rings.all import (bernoulli, CyclotomicField,22is_FiniteField, ZZ, QQ, Integer, divisors,23LCM, is_squarefree)24from sage.rings.power_series_ring import PowerSeriesRing25from eis_series_cython import eisenstein_series_poly, Ek_ZZ2627def eisenstein_series_qexp(k, prec = 10, K=QQ, var='q', normalization='linear'):28r"""29Return the `q`-expansion of the normalized weight `k` Eisenstein series on30`{\rm SL}_2(\ZZ)` to precision prec in the ring `K`. Three normalizations31are available, depending on the parameter ``normalization``; the default32normalization is the one for which the linear coefficient is 1.3334INPUT:3536- ``k`` - an even positive integer3738- ``prec`` - (default: 10) a nonnegative integer3940- ``K`` - (default: `\QQ`) a ring4142- ``var`` - (default: ``'q'``) variable name to use for q-expansion4344- ``normalization`` - (default: ``'linear'``) normalization to use. If this45is ``'linear'``, then the series will be normalized so that the linear46term is 1. If it is ``'constant'``, the series will be normalized to have47constant term 1. If it is ``'integral'``, then the series will be48normalized to have integer coefficients and no common factor, and linear49term that is positive. Note that ``'integral'`` will work over arbitrary50base rings, while ``'linear'`` or ``'constant'`` will fail if the51denominator (resp. numerator) of `B_k / 2k` is invertible.5253ALGORITHM:5455We know `E_k = \text{constant} + \sum_n \sigma_{k-1}(n) q^n`. So we56compute all the `\sigma_{k-1}(n)` simultaneously, using the fact that57`\sigma` is multiplicative.5859EXAMPLES::6061sage: eisenstein_series_qexp(2,5)62-1/24 + q + 3*q^2 + 4*q^3 + 7*q^4 + O(q^5)63sage: eisenstein_series_qexp(2,0)64O(q^0)65sage: eisenstein_series_qexp(2,5,GF(7))662 + q + 3*q^2 + 4*q^3 + O(q^5)67sage: eisenstein_series_qexp(2,5,GF(7),var='T')682 + T + 3*T^2 + 4*T^3 + O(T^5)6970We illustrate the use of the ``normalization`` parameter::7172sage: eisenstein_series_qexp(12, 5, normalization='integral')73691 + 65520*q + 134250480*q^2 + 11606736960*q^3 + 274945048560*q^4 + O(q^5)74sage: eisenstein_series_qexp(12, 5, normalization='constant')751 + 65520/691*q + 134250480/691*q^2 + 11606736960/691*q^3 + 274945048560/691*q^4 + O(q^5)76sage: eisenstein_series_qexp(12, 5, normalization='linear')77691/65520 + q + 2049*q^2 + 177148*q^3 + 4196353*q^4 + O(q^5)78sage: eisenstein_series_qexp(12, 50, K=GF(13), normalization="constant")791 + O(q^50)8081TESTS:8283Test that :trac:`5102` is fixed::8485sage: eisenstein_series_qexp(10, 30, GF(17))8615 + q + 3*q^2 + 15*q^3 + 7*q^4 + 13*q^5 + 11*q^6 + 11*q^7 + 15*q^8 + 7*q^9 + 5*q^10 + 7*q^11 + 3*q^12 + 14*q^13 + 16*q^14 + 8*q^15 + 14*q^16 + q^17 + 4*q^18 + 3*q^19 + 6*q^20 + 12*q^21 + 4*q^22 + 12*q^23 + 4*q^24 + 4*q^25 + 8*q^26 + 14*q^27 + 9*q^28 + 6*q^29 + O(q^30)8788This shows that the bug reported at :trac:`8291` is fixed::8990sage: eisenstein_series_qexp(26, 10, GF(13))917 + q + 3*q^2 + 4*q^3 + 7*q^4 + 6*q^5 + 12*q^6 + 8*q^7 + 2*q^8 + O(q^10)9293We check that the function behaves properly over finite-characteristic base rings::9495sage: eisenstein_series_qexp(12, 5, K = Zmod(691), normalization="integral")96566*q + 236*q^2 + 286*q^3 + 194*q^4 + O(q^5)97sage: eisenstein_series_qexp(12, 5, K = Zmod(691), normalization="constant")98Traceback (most recent call last):99...100ValueError: The numerator of -B_k/(2*k) (=691) must be invertible in the ring Ring of integers modulo 691101sage: eisenstein_series_qexp(12, 5, K = Zmod(691), normalization="linear")102q + 667*q^2 + 252*q^3 + 601*q^4 + O(q^5)103104sage: eisenstein_series_qexp(12, 5, K = Zmod(2), normalization="integral")1051 + O(q^5)106sage: eisenstein_series_qexp(12, 5, K = Zmod(2), normalization="constant")1071 + O(q^5)108sage: eisenstein_series_qexp(12, 5, K = Zmod(2), normalization="linear")109Traceback (most recent call last):110...111ValueError: The denominator of -B_k/(2*k) (=65520) must be invertible in the ring Ring of integers modulo 2112113AUTHORS:114115- William Stein: original implementation116117- Craig Citro (2007-06-01): rewrote for massive speedup118119- Martin Raum (2009-08-02): port to cython for speedup120121- David Loeffler (2010-04-07): work around an integer overflow when `k` is large122123- David Loeffler (2012-03-15): add options for alternative normalizations124(motivated by :trac:`12043`)125"""126## we use this to prevent computation if it would fail anyway.127if k <= 0 or k % 2 == 1 :128raise ValueError, "k must be positive and even"129130a0 = - bernoulli(k) / (2*k)131132if normalization == 'linear':133a0den = a0.denominator()134try:135a0fac = K(1/a0den)136except ZeroDivisionError:137raise ValueError, "The denominator of -B_k/(2*k) (=%s) must be invertible in the ring %s"%(a0den, K)138elif normalization == 'constant':139a0num = a0.numerator()140try:141a0fac = K(1/a0num)142except ZeroDivisionError:143raise ValueError, "The numerator of -B_k/(2*k) (=%s) must be invertible in the ring %s"%(a0num, K)144elif normalization == 'integral':145a0fac = None146else:147raise ValueError, "Normalization (=%s) must be one of 'linear', 'constant', 'integral'" % normalization148149R = PowerSeriesRing(K, var)150if K == QQ and normalization == 'linear':151ls = Ek_ZZ(k, prec)152# The following is *dramatically* faster than doing the more natural153# "R(ls)" would be:154E = ZZ[var](ls, prec=prec, check=False).change_ring(QQ)155if len(ls)>0:156E._unsafe_mutate(0, a0)157return R(E, prec)158# The following is an older slower alternative to the above three lines:159#return a0fac*R(eisenstein_series_poly(k, prec).list(), prec=prec, check=False)160else:161# This used to work with check=False, but that can only be regarded as162# an improbable lucky miracle. Enabling checking is a noticeable speed163# regression; the morally right fix would be to expose FLINT's164# fmpz_poly_to_nmod_poly command (at least for word-sized N).165if a0fac is not None:166return a0fac*R(eisenstein_series_poly(k, prec).list(), prec=prec, check=True)167else:168return R(eisenstein_series_poly(k, prec).list(), prec=prec, check=True)169170def __common_minimal_basering(chi, psi):171"""172Find the smallest basering over which chi and psi are valued, and173return new chi and psi valued in that ring.174175EXAMPLES::176177sage: sage.modular.modform.eis_series.__common_minimal_basering(DirichletGroup(1).0, DirichletGroup(1).0)178(Dirichlet character modulo 1 of conductor 1 mapping 0 |--> 1, Dirichlet character modulo 1 of conductor 1 mapping 0 |--> 1)179180sage: sage.modular.modform.eis_series.__common_minimal_basering(DirichletGroup(3).0, DirichletGroup(5).0)181(Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1, Dirichlet character modulo 5 of conductor 5 mapping 2 |--> zeta4)182183sage: sage.modular.modform.eis_series.__common_minimal_basering(DirichletGroup(12).0, DirichletGroup(36).0)184(Dirichlet character modulo 12 of conductor 4 mapping 7 |--> -1, 5 |--> 1, Dirichlet character modulo 36 of conductor 4 mapping 19 |--> -1, 29 |--> 1)185"""186chi = chi.minimize_base_ring()187psi = psi.minimize_base_ring()188n = LCM(chi.base_ring().zeta().multiplicative_order(),\189psi.base_ring().zeta().multiplicative_order())190if n <= 2:191K = QQ192else:193K = CyclotomicField(n)194chi = chi.change_ring(K)195psi = psi.change_ring(K)196return chi, psi197198#def prim(eps):199# print "making eps with modulus %s primitive"%eps.modulus()200# return eps.primitive_character()201202def __find_eisen_chars(character, k):203"""204Find all triples `(\psi_1, \psi_2, t)` that give rise to an Eisenstein series of the given weight and character.205206EXAMPLES::207208sage: sage.modular.modform.eis_series.__find_eisen_chars(DirichletGroup(36).0, 4)209[]210211sage: pars = sage.modular.modform.eis_series.__find_eisen_chars(DirichletGroup(36).0, 5)212sage: [(x[0].values_on_gens(), x[1].values_on_gens(), x[2]) for x in pars]213[((1, 1), (-1, 1), 1),214((1, 1), (-1, 1), 3),215((1, 1), (-1, 1), 9),216((1, -1), (-1, -1), 1),217((-1, 1), (1, 1), 1),218((-1, 1), (1, 1), 3),219((-1, 1), (1, 1), 9),220((-1, -1), (1, -1), 1)]221"""222N = character.modulus()223if character.is_trivial():224if k%2 != 0:225return []226char_inv = ~character227V = [(character, char_inv, t) for t in divisors(N) if t>1]228if k != 2:229V.insert(0,(character, char_inv, 1))230if is_squarefree(N):231return V232# Now include all pairs (chi,chi^(-1)) such that cond(chi)^2 divides N:233# TODO: Optimize -- this is presumably way too hard work below.234G = dirichlet.DirichletGroup(N)235for chi in G:236if not chi.is_trivial():237f = chi.conductor()238if N % (f**2) == 0:239chi = chi.minimize_base_ring()240chi_inv = ~chi241for t in divisors(N//(f**2)):242V.insert(0, (chi, chi_inv, t))243return V244245246eps = character247if eps(-1) != (-1)**k:248return []249eps = eps.maximize_base_ring()250G = eps.parent()251252# Find all pairs chi, psi such that:253#254# (1) cond(chi)*cond(psi) divides the level, and255#256# (2) chi*psi == eps, where eps is the nebentypus character of self.257#258# See [Miyake, Modular Forms] Lemma 7.1.1.259260K = G.base_ring()261C = {}262263t0 = misc.cputime()264265for e in G:266m = Integer(e.conductor())267if C.has_key(m):268C[m].append(e)269else:270C[m] = [e]271272misc.verbose("Enumeration with conductors.",t0)273274params = []275for L in divisors(N):276misc.verbose("divisor %s"%L)277if not C.has_key(L):278continue279GL = C[L]280for R in divisors(N/L):281if not C.has_key(R):282continue283GR = C[R]284for chi in GL:285for psi in GR:286if chi*psi == eps:287chi0, psi0 = __common_minimal_basering(chi, psi)288for t in divisors(N//(R*L)):289if k != 1 or ((psi0, chi0, t) not in params):290params.append( (chi0,psi0,t) )291return params292293def __find_eisen_chars_gammaH(N, H, k):294"""295Find all triples `(\psi_1, \psi_2, t)` that give rise to an Eisenstein series of weight `k` on296`\Gamma_H(N)`.297298EXAMPLE::299300sage: pars = sage.modular.modform.eis_series.__find_eisen_chars_gammaH(15, [2], 5)301sage: [(x[0].values_on_gens(), x[1].values_on_gens(), x[2]) for x in pars]302[((1, 1), (-1, -1), 1), ((-1, 1), (1, -1), 1), ((1, -1), (-1, 1), 1), ((-1, -1), (1, 1), 1)]303"""304params = []305for chi in dirichlet.DirichletGroup(N):306if all([chi(h) == 1 for h in H]):307params += __find_eisen_chars(chi, k)308return params309310def __find_eisen_chars_gamma1(N, k):311"""312Find all triples `(\psi_1, \psi_2, t)` that give rise to an Eisenstein series of weight `k` on313`\Gamma_1(N)`.314315EXAMPLES::316317sage: pars = sage.modular.modform.eis_series.__find_eisen_chars_gamma1(12, 4)318sage: [(x[0].values_on_gens(), x[1].values_on_gens(), x[2]) for x in pars]319[((1, 1), (1, 1), 1),320((1, 1), (1, 1), 2),321((1, 1), (1, 1), 3),322((1, 1), (1, 1), 4),323((1, 1), (1, 1), 6),324((1, 1), (1, 1), 12),325((1, 1), (-1, -1), 1),326((-1, -1), (1, 1), 1),327((-1, 1), (1, -1), 1),328((1, -1), (-1, 1), 1)]329330sage: pars = sage.modular.modform.eis_series.__find_eisen_chars_gamma1(12, 5)331sage: [(x[0].values_on_gens(), x[1].values_on_gens(), x[2]) for x in pars]332[((1, 1), (-1, 1), 1),333((1, 1), (-1, 1), 3),334((-1, 1), (1, 1), 1),335((-1, 1), (1, 1), 3),336((1, 1), (1, -1), 1),337((1, 1), (1, -1), 2),338((1, 1), (1, -1), 4),339((1, -1), (1, 1), 1),340((1, -1), (1, 1), 2),341((1, -1), (1, 1), 4)]342"""343pairs = []344s = (-1)**k345G = dirichlet.DirichletGroup(N)346E = list(G)347parity = [c(-1) for c in E]348for i in range(len(E)):349for j in range(i,len(E)):350if parity[i]*parity[j] == s and N % (E[i].conductor()*E[j].conductor()) == 0:351chi, psi = __common_minimal_basering(E[i], E[j])352if k != 1:353pairs.append((chi, psi))354if i!=j: pairs.append((psi,chi))355else:356# if weight is 1 then (chi, psi) and (chi, psi) are the357# same form358if psi.is_trivial() and not chi.is_trivial():359# need to put the trivial character first to get the L-value right360pairs.append((psi, chi))361else:362pairs.append((chi, psi))363#end fors364#end if365366triples = []367D = divisors(N)368for chi, psi in pairs:369c_chi = chi.conductor()370c_psi = psi.conductor()371D = divisors(N/(c_chi * c_psi))372if (k==2 and chi.is_trivial() and psi.is_trivial()):373D.remove(1)374chi, psi = __common_minimal_basering(chi, psi)375for t in D:376triples.append((chi, psi, t))377return triples378379def eisenstein_series_lseries(weight, prec=53,380max_imaginary_part=0,381max_asymp_coeffs=40):382r"""383Return the L-series of the weight `2k` Eisenstein series384on `\mathrm{SL}_2(\ZZ)`.385386This actually returns an interface to Tim Dokchitser's program387for computing with the L-series of the Eisenstein series388389INPUT:390391- ``weight`` - even integer392393- ``prec`` - integer (bits precision)394395- ``max_imaginary_part`` - real number396397- ``max_asymp_coeffs`` - integer398399OUTPUT:400401The L-series of the Eisenstein series.402403EXAMPLES:404405We compute with the L-series of `E_{16}` and then `E_{20}`::406407sage: L = eisenstein_series_lseries(16)408sage: L(1)409-0.291657724743874410sage: L = eisenstein_series_lseries(20)411sage: L(2)412-5.02355351645998413414Now with higher precision::415416sage: L = eisenstein_series_lseries(20, prec=200)417sage: L(2)418-5.0235535164599797471968418348135050804419155747868718371029419"""420f = eisenstein_series_qexp(weight,prec)421from sage.lfunctions.all import Dokchitser422from sage.symbolic.constants import pi423key = (prec, max_imaginary_part, max_asymp_coeffs)424j = weight425L = Dokchitser(conductor = 1,426gammaV = [0,1],427weight = j,428eps = (-1)**Integer(j/2),429poles = [j],430# Using a string for residues is a hack but it works well431# since this will make PARI/GP compute sqrt(pi) with the432# right precision.433residues = '[sqrt(Pi)*(%s)]'%((-1)**Integer(j/2)*bernoulli(j)/j),434prec = prec)435436s = 'coeff = %s;'%f.list()437L.init_coeffs('coeff[k+1]',pari_precode = s,438max_imaginary_part=max_imaginary_part,439max_asymp_coeffs=max_asymp_coeffs)440L.check_functional_equation()441L.rename('L-series associated to the weight %s Eisenstein series %s on SL_2(Z)'%(j,f))442return L443444def compute_eisenstein_params(character, k):445r"""446Compute and return a list of all parameters `(\chi,\psi,t)` that447define the Eisenstein series with given character and weight `k`.448449Only the parity of `k` is relevant (unless k = 1, which is a slightly different case).450451If ``character`` is an integer `N`, then the parameters for452`\Gamma_1(N)` are computed instead. Then the condition is that453`\chi(-1)*\psi(-1) =(-1)^k`.454455If ``character`` is a list of integers, the parameters for `\Gamma_H(N)` are456computed, where `H` is the subgroup of `(\ZZ/N\ZZ)^\times` generated by the457integers in the given list.458459EXAMPLES::460461sage: sage.modular.modform.eis_series.compute_eisenstein_params(DirichletGroup(30)(1), 3)462[]463464sage: pars = sage.modular.modform.eis_series.compute_eisenstein_params(DirichletGroup(30)(1), 4)465sage: [(x[0].values_on_gens(), x[1].values_on_gens(), x[2]) for x in pars]466[((1, 1), (1, 1), 1),467((1, 1), (1, 1), 2),468((1, 1), (1, 1), 3),469((1, 1), (1, 1), 5),470((1, 1), (1, 1), 6),471((1, 1), (1, 1), 10),472((1, 1), (1, 1), 15),473((1, 1), (1, 1), 30)]474475sage: pars = sage.modular.modform.eis_series.compute_eisenstein_params(15, 1)476sage: [(x[0].values_on_gens(), x[1].values_on_gens(), x[2]) for x in pars]477[((1, 1), (-1, 1), 1),478((1, 1), (-1, 1), 5),479((1, 1), (1, zeta4), 1),480((1, 1), (1, zeta4), 3),481((1, 1), (-1, -1), 1),482((1, 1), (1, -zeta4), 1),483((1, 1), (1, -zeta4), 3),484((-1, 1), (1, -1), 1)]485486sage: sage.modular.modform.eis_series.compute_eisenstein_params(DirichletGroup(15).0, 1)487[(Dirichlet character modulo 15 of conductor 1 mapping 11 |--> 1, 7 |--> 1, Dirichlet character modulo 15 of conductor 3 mapping 11 |--> -1, 7 |--> 1, 1),488(Dirichlet character modulo 15 of conductor 1 mapping 11 |--> 1, 7 |--> 1, Dirichlet character modulo 15 of conductor 3 mapping 11 |--> -1, 7 |--> 1, 5)]489490sage: len(sage.modular.modform.eis_series.compute_eisenstein_params(GammaH(15, [4]), 3))4918492"""493if isinstance(character, (int,long,Integer)):494return __find_eisen_chars_gamma1(character, k)495elif isinstance(character, GammaH_class):496return __find_eisen_chars_gammaH(character.level(), character._generators_for_H(), k)497else:498return __find_eisen_chars(character, k)499500501502