Path: blob/master/src/sage/modular/overconvergent/hecke_series.py
8821 views
r"""1Atkin/Hecke series for overconvergent modular forms.23This file contains a function :func:`~hecke_series` to compute the4characteristic series `P(t)` modulo `p^m` of the Atkin/Hecke operator `U_p`5upon the space of p-adic overconvergent modular forms of level `\Gamma_0(N)`.6The input weight ``k`` can also be a list ``klist`` of weights which must all7be congruent modulo `(p-1)`.89Two optional parameters ``modformsring`` and ``weightbound`` can be specified,10and in most cases for levels `N > 1` they can be used to obtain the output more11quickly. When `m \le k-1` the output `P(t)` is also equal modulo `p^m` to the12reverse characteristic polynomial of the Atkin operator `U_p` on the space of13classical modular forms of weight k and level `\Gamma_0(Np)`. In addition,14provided `m \le (k-2)/2` the output `P(t)` is equal modulo `p^m` to the reverse15characteristic polynomial of the Hecke operator `T_p` on the space of classical16modular forms of weight k and level `\Gamma_0(N)`. The function is based upon17the main algorithm in [AGBL]_, and has linear running time in the logarithm of18the weight k.1920AUTHORS:2122- Alan G.B. Lauder (2011-11-10): original implementation.23- David Loeffler (2011-12): minor optimizations in review stage.2425EXAMPLES:2627The characteristic series of the U_11 operator modulo 11^10 on the space of 11-adic overconvergent28modular forms of level 1 and weight 10000::2930sage: hecke_series(11,1,10000,10)3110009319650*x^4 + 25618839103*x^3 + 6126165716*x^2 + 10120524732*x + 13233The characteristic series of the U_5 operator modulo 5^5 on the space of 5-adic overconvergent34modular forms of level 3 and weight 1000::3536sage: hecke_series(5,3,1000,5)371875*x^6 + 1250*x^5 + 1200*x^4 + 1385*x^3 + 1131*x^2 + 2533*x + 13839The characteristic series of the U_7 operator modulo 7^5 on the space of 7-adic overconvergent40modular forms of level 5 and weight 1000. Here the optional parameter ``modformsring`` is set to true::4142sage: hecke_series(7,5,1000,5,modformsring = True) # long time (21s on sage.math, 2012)4312005*x^7 + 10633*x^6 + 6321*x^5 + 6216*x^4 + 5412*x^3 + 4927*x^2 + 4906*x + 14445The characteristic series of the U_13 operator modulo 13^5 on the space of 13-adic overconvergent46modular forms of level 2 and weight 10000. Here the optional parameter ``weightbound`` is set to 4::4748sage: hecke_series(13,2,10000,5,weightbound = 4) # long time (17s on sage.math, 2012)49325156*x^5 + 109681*x^4 + 188617*x^3 + 220858*x^2 + 269566*x + 15051A list containing the characteristic series of the U_23 operator modulo 23^10 on the spaces of5223-adic overconvergent modular forms of level 1 and weights 1000 and 1022, respectively.5354::5556sage: hecke_series(23,1,[1000,1022],10)57[7204610645852*x^6 + 2117949463923*x^5 + 24152587827773*x^4 + 31270783576528*x^3 + 30336366679797*x^258+ 29197235447073*x + 1, 32737396672905*x^4 + 36141830902187*x^3 + 16514246534976*x^2 + 38886059530878*x + 1]5960REFERENCES:6162.. [AGBL] Alan G.B. Lauder, "Computations with classical and p-adic modular63forms", LMS J. of Comput. Math. 14 (2011), 214-231.6465"""66#########################################################################67# Copyright (C) 2011 Alan Lauder <[email protected]>68#69# Distributed under the terms of the GNU General Public License (GPL)70#71# http://www.gnu.org/licenses/72#########################################################################7374from sage.functions.all import floor, ceil75from sage.rings.all import ZZ,Zmod,valuation,Infinity,Integer76from sage.rings.finite_rings.constructor import GF77from sage.modular.modform.all import ModularForms, ModularFormsRing, delta_qexp, eisenstein_series_qexp78from sage.modular.dims import dimension_modular_forms79from sage.misc.functional import dimension,transpose,charpoly80from sage.matrix.constructor import matrix, random_matrix81from sage.matrix.matrix_space import MatrixSpace82from sage.misc.misc import cputime, verbose8384# AUXILIARY CODE: SPACES OF MODULAR FORMS AND LINEAR ALGEBRA8586def compute_G(p, F):87r"""88Given a power series `F \in R[[q]]^\times`, for some ring `R`, and an89integer `p`, compute the quotient9091.. math::9293\frac{F(q)}{F(q^p)}.9495Used by :func:`level1_UpGj` and by :func:`higher_level_UpGj`, with `F` equal96to the Eisenstein series `E_{p-1}`.9798INPUT:99100- ``p`` -- integer101- ``F`` -- power series (with invertible constant term)102103OUTPUT:104105the power series `F(q) / F(q^p)`, to the same precision as `F`106107EXAMPLE::108109sage: E = sage.modular.overconvergent.hecke_series.eisenstein_series_qexp(2, 12, Zmod(9),normalization="constant")110sage: sage.modular.overconvergent.hecke_series.compute_G(3, E)1111 + 3*q + 3*q^4 + 6*q^7 + O(q^12)112"""113Fp = (F.truncate_powerseries(ceil(F.prec() / ZZ(p)))).V(p)114return F / Fp115116def low_weight_bases(N,p,m,NN,weightbound):117r"""118Returns a list of integral bases of modular forms of level N and (even)119weight at most ``weightbound``, as `q`-expansions modulo `(p^m,q^{NN})`.120121These forms are obtained by reduction mod `p^m` from an integral basis in122Hermite normal form (so they are not necessarily in reduced row echelon123form mod `p^m`, but they are not far off).124125INPUT:126127- ``N`` -- positive integer (level).128- ``p`` -- prime.129- ``m``, ``NN`` -- positive integers.130- ``weightbound`` -- (even) positive integer.131132OUTPUT:133134- list of lists of `q`-expansions modulo `(p^m,q^{NN})`.135136EXAMPLES::137138sage: from sage.modular.overconvergent.hecke_series import low_weight_bases139sage: low_weight_bases(2,5,3,5,6)140[[1 + 24*q + 24*q^2 + 96*q^3 + 24*q^4 + O(q^5)],141[1 + 115*q^2 + 35*q^4 + O(q^5), q + 8*q^2 + 28*q^3 + 64*q^4 + O(q^5)],142[1 + 121*q^2 + 118*q^4 + O(q^5), q + 32*q^2 + 119*q^3 + 24*q^4 + O(q^5)]]143144"""145generators = []146147for k in xrange(2,weightbound + 2,2):148b = ModularForms(N,k,base_ring=Zmod(p**m)).q_expansion_basis(prec=NN)149generators.append(list(b))150return generators151152def random_low_weight_bases(N,p,m,NN,weightbound):153r"""154Returns list of random integral bases of modular forms of level `N` and155(even) weight at most weightbound with coefficients reduced modulo156`(p^m,q^{NN})`.157158INPUT:159160- ``N`` -- positive integer (level).161- ``p`` -- prime.162- ``m``, ``NN`` -- positive integers.163- ``weightbound`` -- (even) positive integer.164165OUTPUT:166167- list of lists of `q`-expansions modulo `(p^m,q^{NN})`.168169EXAMPLES::170171sage: from sage.modular.overconvergent.hecke_series import random_low_weight_bases172sage: S = random_low_weight_bases(3,7,2,5,6); S # random173[[4 + 48*q + 46*q^2 + 48*q^3 + 42*q^4 + O(q^5)],174[3 + 5*q + 45*q^2 + 22*q^3 + 22*q^4 + O(q^5),1751 + 3*q + 27*q^2 + 27*q^3 + 23*q^4 + O(q^5)],176[2*q + 4*q^2 + 16*q^3 + 48*q^4 + O(q^5),1772 + 6*q + q^2 + 3*q^3 + 43*q^4 + O(q^5),1781 + 2*q + 6*q^2 + 14*q^3 + 4*q^4 + O(q^5)]]179sage: S[0][0].parent()180Power Series Ring in q over Ring of integers modulo 49181sage: S[0][0].prec()1825183184"""185LWB = low_weight_bases(N,p,m,NN,weightbound)186# this is "approximately" row reduced (it's the mod p^n reduction of a187# matrix over ZZ in Hermite form)188RandomLWB = []189for i in xrange(len(LWB)):190n = len(LWB[i])191c = random_matrix(Zmod(p**m), n)192while c.det() % p == 0:193c = random_matrix(Zmod(p**m), n)194RandomLWB.append([ sum([c[j, k] * LWB[i][k] for k in xrange(n)]) for j in xrange(n) ])195196return RandomLWB197198def low_weight_generators(N,p,m,NN):199r"""200Returns a list of lists of modular forms, and an even natural number. The201first output is a list of lists of modular forms reduced modulo202`(p^m,q^{NN})` which generate the `(\ZZ / p^m \ZZ)`-algebra of mod `p^m`203modular forms of weight at most 8, and the second output is the largest204weight among the forms in the generating set.205206We (Alan Lauder and David Loeffler, the author and reviewer of this patch)207conjecture that forms of weight at most 8 are always sufficient to generate208the algebra of mod `p^m` modular forms of all weights. (We believe 6 to be209sufficient, and we can prove that 4 is sufficient when there are no210elliptic points, but using weights up to 8 acts as a consistency check.)211212INPUT:213214- ``N`` -- positive integer (level).215- ``p`` -- prime.216- ``m``, ``NN`` -- positive integers.217218OUTPUT:219220a tuple consisting of:221222- a list of lists of `q`-expansions modulo `(p^m,q^{NN})`,223- an even natural number (twice the length of the list).224225EXAMPLES::226227sage: from sage.modular.overconvergent.hecke_series import low_weight_generators228sage: low_weight_generators(3,7,3,10)229([[1 + 12*q + 36*q^2 + 12*q^3 + 84*q^4 + 72*q^5 + 36*q^6 + 96*q^7 + 180*q^8 + 12*q^9 + O(q^10)],230[1 + 240*q^3 + 102*q^6 + 203*q^9 + O(q^10)],231[1 + 182*q^3 + 175*q^6 + 161*q^9 + O(q^10)]], 6)232sage: low_weight_generators(11,5,3,10)233([[1 + 12*q^2 + 12*q^3 + 12*q^4 + 12*q^5 + 24*q^6 + 24*q^7 + 36*q^8 + 36*q^9 + O(q^10),234q + 123*q^2 + 124*q^3 + 2*q^4 + q^5 + 2*q^6 + 123*q^7 + 123*q^9 + O(q^10)],235[q + 116*q^4 + 115*q^5 + 102*q^6 + 121*q^7 + 96*q^8 + 106*q^9 + O(q^10)]], 4)236"""237M = ModularFormsRing(N,base_ring=Zmod(p))238239b = M.gen_forms(maxweight = 8)240241weightbound = max([f.weight() for f in b])242generators = []243244for k in xrange(2,weightbound + 2,2):245generators.append([f.qexp(NN).change_ring(Zmod(p**m)) for f in b if f.weight() == k])246247return generators,weightbound248249def random_solution(B,K):250r"""251Returns a random solution in non-negative integers to the equation `a_1 + 2252a_2 + 3 a_3 + ... + B a_B = K`, using a greedy algorithm.253254Note that this is *much* faster than using255``WeightedIntegerVectors.random_element()``.256257INPUT:258259- ``B``, ``K`` -- non-negative integers.260261OUTPUT:262263- list.264265EXAMPLES::266267sage: from sage.modular.overconvergent.hecke_series import random_solution268sage: random_solution(5,10)269[1, 1, 1, 1, 0]270"""271a = []272for i in xrange(B,1,-1):273ai = ZZ.random_element((K // i) + 1)274a.append(ai)275K = K - ai*i276a.append(K)277a.reverse()278279return a280281# AUXILIARY CODE: ECHELON FORM282283def ech_form(A,p):284r"""285Returns echelon form of matrix ``A`` over the ring of integers modulo286`p^m`, for some prime `p` and `m \ge 1`.287288.. todo::289290This should be moved to :mod:`sage.matrix.matrix_modn_dense` at some291point.292293INPUT:294295- ``A`` -- matrix over ``Zmod(p^m)`` for some m.296- ``p`` - prime p.297298OUTPUT:299300- matrix over ``Zmod(p^m)``.301302EXAMPLES::303304sage: from sage.modular.overconvergent.hecke_series import ech_form305sage: A = MatrixSpace(Zmod(5**3),3)([1,2,3,4,5,6,7,8,9])306sage: ech_form(A,5)307[1 2 3]308[0 1 2]309[0 0 0]310"""311312S = A[0,0].parent()313a = A.nrows()314b = A.ncols()315316k = 0 # position pivoting row will be swapped to317for j in xrange(b):318if k < a:319pivj = k # find new pivot320for i in xrange(k+1,a):321if valuation(A[i,j],p) < valuation(A[pivj,j],p):322pivj = i323if valuation(A[pivj,j],p) < +Infinity: # else column already reduced324A.swap_rows(pivj, k)325A.set_row_to_multiple_of_row(k, k, S(ZZ(A[k,j])/(p**valuation(A[k,j],p)))**(-1))326for i in xrange(k+1,a):327A.add_multiple_of_row(i, k, S(-ZZ(A[i,j])/ZZ(A[k,j])))328k = k + 1329330return A331332333# *** COMPLEMENTARY SPACES FOR LEVEL N > 1 ***334335def random_new_basis_modp(N,p,k,LWBModp,TotalBasisModp,elldash,bound):336r"""337Returns ``NewBasisCode``. Here `NewBasisCode` is a list of lists of lists338``[j,a]``. This encodes a choice of basis for the ith complementary space339`W_i`, as explained in the documentation for the function340:func:`complementary_spaces_modp`.341342INPUT:343344- ``N`` -- positive integer at least 2 and not divisible by p (level).345- ``p`` -- prime at least 5.346- ``k`` -- non-negative integer.347- ``LWBModp`` -- list of list of q-expansions modulo348`(p,q^\text{elldash})`.349- ``TotalBasisModp`` -- matrix over GF(p).350- ``elldash`` - positive integer.351- ``bound`` -- positive even integer (twice the length of the list352``LWBModp``).353354OUTPUT:355356- A list of lists of lists ``[j,a]``.357358.. note::359360As well as having a non-trivial return value, this function also361modifies the input matrix ``TotalBasisModp``.362363EXAMPLES::364365sage: from sage.modular.overconvergent.hecke_series import random_low_weight_bases, complementary_spaces_modp366sage: LWB = random_low_weight_bases(2,5,2,4,6)367sage: LWBModp = [ [f.change_ring(GF(5)) for f in x] for x in LWB]368sage: complementary_spaces_modp(2,5,2,3,4,LWBModp,4) # random, indirect doctest369[[[[0, 0]]], [[[0, 0], [1, 1]]], [[[0, 0], [1, 0], [1, 1]]], [[[0, 0], [1, 0], [1, 1], [1, 1]]]]370371"""372373R = LWBModp[0][0].parent()374375# Case k0 + i(p-1) = 0 + 0(p-1) = 0376377if k == 0:378TotalBasisModp[0,0] = 1379return [[]]380381# Case k = k0 + i(p-1) > 0382383di = dimension_modular_forms(N, k)384diminus1 = dimension_modular_forms(N, k-(p-1))385mi = di - diminus1386387NewBasisCode = []388rk = diminus1389for i in xrange(1,mi+1):390while (rk < diminus1 + i):391# take random product of basis elements392exps = random_solution(bound // 2, k // 2)393TotalBasisi = R(1)394TotalBasisiCode = []395for j in xrange(len(exps)):396for l in xrange(exps[j]):397a = ZZ.random_element(len(LWBModp[j]))398TotalBasisi = TotalBasisi*LWBModp[j][a]399TotalBasisiCode.append([j,a])400TotalBasisModp[rk] = [TotalBasisi[j] for j in range(elldash)]401TotalBasisModp.echelonize()402rk = TotalBasisModp.rank()403NewBasisCode.append(TotalBasisiCode) # this choice increased the rank404405return NewBasisCode406407def complementary_spaces_modp(N,p,k0,n,elldash,LWBModp,bound):408r"""409Returns a list of lists of lists of lists ``[j,a]``. The pairs ``[j,a]``410encode the choice of the `a`-th element in the `j`-th list of the input411``LWBModp``, i.e., the `a`-th element in a particular basis modulo412`(p,q^\text{elldash})` for the space of modular forms of level413`\Gamma_0(N)` and weight `2(j+1)`. The list ``[[j_1,a_1],...,[j_r,a_r]]``414then encodes the product of the r modular forms associated to each415``[j_i,a_i]``; this has weight `k + (p-1)i` for some `0 \le i \le n`; here416the i is such that this *list of lists* occurs in the ith list of the417output. The ith list of the output thus encodes a choice of basis for the418complementary space `W_i` which occurs in Step 2 of Algorithm 2 in [AGBL]_.419The idea is that one searches for this space `W_i` first modulo420`(p,q^\text{elldash})` and then, having found the correct products of421generating forms, one can reconstruct these spaces modulo422`(p^\text{mdash},q^\text{elldashp})` using the output of this function.423(This idea is based upon a suggestion of John Voight.)424425INPUT:426427- ``N`` -- positive integer at least 2 and not divisible by p (level).428- ``p`` -- prime at least 5.429- ``k0`` -- integer in range 0 to `p-1`.430- ``n,elldash`` -- positive integers.431- ``LWBModp`` -- list of lists of `q`-expansions over `GF(p)`.432- ``bound`` -- positive even integer (twice the length of the list ``LWBModp``).433434OUTPUT:435436- list of list of list of lists.437438EXAMPLES::439440sage: from sage.modular.overconvergent.hecke_series import random_low_weight_bases, complementary_spaces_modp441sage: LWB = random_low_weight_bases(2,5,2,4,6)442sage: LWBModp = [[f.change_ring(Zmod(5)) for f in x] for x in LWB]443sage: complementary_spaces_modp(2,5,0,3,4,LWBModp,6) # random, indirect doctest444[[[]], [[[0, 0], [0, 0]]], [[[0, 0], [2, 1]]], [[[0, 0], [0, 0], [0, 0], [2, 1]]]]445"""446CompSpacesCode = []447ell = dimension_modular_forms(N,k0 + n*(p-1))448TotalBasisModp = matrix(GF(p),ell,elldash); # zero matrix449450for i in xrange(n+1):451NewBasisCodemi = random_new_basis_modp(N,p,k0 + i*(p-1),LWBModp,TotalBasisModp,elldash,bound)452# TotalBasisModp is passed by reference and updated in function453CompSpacesCode.append(NewBasisCodemi)454455return CompSpacesCode456457def complementary_spaces(N,p,k0,n,mdash,elldashp,elldash,modformsring,bound):458r"""459Returns a list ``Ws``, each element in which is a list ``Wi`` of460q-expansions modulo `(p^\text{mdash},q^\text{elldashp})`. The list ``Wi`` is461a basis for a choice of complementary space in level `\Gamma_0(N)` and462weight `k` to the image of weight `k - (p-1)` forms under multiplication by463the Eisenstein series `E_{p-1}`.464465The lists ``Wi`` play the same role as `W_i` in Step 2 of Algorithm 2 in466[AGBL]_. (The parameters ``k0,n,mdash,elldash,elldashp = elldash*p`` are467defined as in Step 1 of that algorithm when this function is used in468:func:`hecke_series`.) However, the complementary spaces are computed in a469different manner, combining a suggestion of David Loeffler with one of John470Voight. That is, one builds these spaces recursively using random products471of forms in low weight, first searching for suitable products modulo472`(p,q^\text{elldash})`, and then later reconstructing only the required473products to the full precision modulo `(p^\text{mdash},q^{elldashp})`. The474forms in low weight are chosen from either bases of all forms up to weight475``bound`` or from a (tentative) generating set for the ring of all modular476forms, according to whether ``modformsring`` is ``False`` or ``True``.477478INPUT:479480- ``N`` -- positive integer at least 2 and not divisible by p (level).481- ``p`` -- prime at least 5.482- ``k0`` -- integer in range 0 to ``p-1``.483- ``n,mdash,elldashp,elldash`` -- positive integers.484- ``modformsring`` -- True or False.485- ``bound`` -- positive (even) integer (ignored if ``modformsring`` is True).486487OUTPUT:488489- list of lists of q-expansions modulo490``(p^\text{mdash},q^\text{elldashp})``.491492EXAMPLES::493494sage: from sage.modular.overconvergent.hecke_series import complementary_spaces495sage: complementary_spaces(2,5,0,3,2,5,4,true,6) # random496[[1],497[1 + 23*q + 24*q^2 + 19*q^3 + 7*q^4 + O(q^5)],498[1 + 21*q + 2*q^2 + 17*q^3 + 14*q^4 + O(q^5)],499[1 + 19*q + 9*q^2 + 11*q^3 + 9*q^4 + O(q^5)]]500sage: complementary_spaces(2,5,0,3,2,5,4,false,6) # random501[[1],502[3 + 4*q + 2*q^2 + 12*q^3 + 11*q^4 + O(q^5)],503[2 + 2*q + 14*q^2 + 19*q^3 + 18*q^4 + O(q^5)],504[6 + 8*q + 10*q^2 + 23*q^3 + 4*q^4 + O(q^5)]]505"""506if modformsring == False:507LWB = random_low_weight_bases(N,p,mdash,elldashp,bound)508else:509LWB,bound = low_weight_generators(N,p,mdash,elldashp)510511LWBModp = [ [ f.change_ring(GF(p)).truncate_powerseries(elldash) for f in x] for x in LWB]512513CompSpacesCode = complementary_spaces_modp(N,p,k0,n,elldash,LWBModp,bound)514515Ws = []516Epm1 = eisenstein_series_qexp(p-1, prec=elldashp, K = Zmod(p**mdash), normalization="constant")517for i in xrange(n+1):518CompSpacesCodemi = CompSpacesCode[i]519Wi = []520for k in xrange(len(CompSpacesCodemi)):521CompSpacesCodemik = CompSpacesCodemi[k]522Wik = Epm1.parent()(1)523for j in xrange(len(CompSpacesCodemik)):524l = CompSpacesCodemik[j][0]525index = CompSpacesCodemik[j][1]526Wik = Wik*LWB[l][index]527Wi.append(Wik)528Ws.append(Wi)529530return Ws531532# AUXILIARY CODE: KATZ EXPANSIONS533534def higher_level_katz_exp(p,N,k0,m,mdash,elldash,elldashp,modformsring,bound):535r"""536Returns a matrix `e` of size ``ell x elldashp`` over the integers modulo537`p^\text{mdash}`, and the Eisenstein series `E_{p-1} = 1 + .\dots \bmod538(p^\text{mdash},q^\text{elldashp})`. The matrix e contains the coefficients539of the elements `e_{i,s}` in the Katz expansions basis in Step 3 of540Algorithm 2 in [AGBL]_ when one takes as input to that algorithm541`p`,`N`,`m` and `k` and define ``k0``, ``mdash``, ``n``, ``elldash``,542``elldashp = ell*dashp`` as in Step 1.543544INPUT:545546- ``p`` -- prime at least 5.547- ``N`` -- positive integer at least 2 and not divisible by p (level).548- ``k0`` -- integer in xrange 0 to p-1.549- ``m,mdash,elldash,elldashp`` -- positive integers.550- ``modformsring`` -- True or False.551- ``bound`` -- positive (even) integer.552553OUTPUT:554555- matrix and q-expansion.556557EXAMPLES::558559sage: from sage.modular.overconvergent.hecke_series import higher_level_katz_exp560sage: e,Ep1 = higher_level_katz_exp(5,2,0,1,2,4,20,true,6)561sage: e562[ 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]563[ 0 1 18 23 19 6 9 9 17 7 3 17 12 8 22 8 11 19 1 5]564[ 0 0 1 11 20 16 0 8 4 0 18 15 24 6 15 23 5 18 7 15]565[ 0 0 0 1 4 16 23 13 6 5 23 5 2 16 4 18 10 23 5 15]566sage: Ep15671 + 15*q + 10*q^2 + 20*q^3 + 20*q^4 + 15*q^5 + 5*q^6 + 10*q^7 +5685*q^9 + 10*q^10 + 5*q^11 + 10*q^12 + 20*q^13 + 15*q^14 + 20*q^15 + 15*q^16 +56910*q^17 + 20*q^18 + O(q^20)570"""571ordr = 1/(p+1)572S = Zmod(p**mdash)573Ep1 = eisenstein_series_qexp(p-1,prec=elldashp,K=S, normalization="constant")574575n = floor(((p+1)/(p-1))*(m+1))576Wjs = complementary_spaces(N,p,k0,n,mdash,elldashp,elldash,modformsring,bound)577578Basis = []579for j in xrange(n+1):580Wj = Wjs[j]581dimj = len(Wj)582Ep1minusj = Ep1**(-j)583for i in xrange(dimj):584wji = Wj[i]585b = p**floor(ordr*j) * wji * Ep1minusj586Basis.append(b)587588# extract basis as a matrix589590ell = len(Basis)591M = matrix(S,ell,elldashp)592for i in xrange(ell):593for j in xrange(elldashp):594M[i,j] = Basis[i][j]595596ech_form(M,p) # put it into echelon form597598return M,Ep1599600def compute_elldash(p,N,k0,n):601r"""602Returns the "Sturm bound" for the space of modular forms of level603`\Gamma_0(N)` and weight `k_0 + n(p-1)`.604605.. seealso::606607:meth:`~sage.modular.modform.space.ModularFormsSpace.sturm_bound`608609INPUT:610611- ``p`` -- prime.612- ``N`` -- positive integer (level).613- ``k0``, ``n`` - non-negative integers not both zero.614615OUTPUT:616617- positive integer.618619EXAMPLES::620621sage: from sage.modular.overconvergent.hecke_series import compute_elldash622sage: compute_elldash(11,5,4,10)62353624"""625626return ModularForms(N,k0 + n*(p-1)).sturm_bound()627628# *** DEGREE BOUND ON HECKE SERIES ***629630def hecke_series_degree_bound(p,N,k,m):631r"""632Returns the ``Wan bound`` on the degree of the characteristic series of the633Atkin operator on p-adic overconvergent modular forms of level634`\Gamma_0(N)` and weight k when reduced modulo `p^m`. This bound depends635only upon p, `k \pmod{p-1}`, and N. It uses Lemma 3.1 in [DW]_.636637INPUT:638639- ``p`` -- prime at least 5.640- ``N`` -- positive integer not divisible by p.641- ``k`` -- even integer.642- ``m`` -- positive integer.643644OUTPUT:645646A non-negative integer.647648EXAMPLES::649650sage: from sage.modular.overconvergent.hecke_series import hecke_series_degree_bound651sage: hecke_series_degree_bound(13,11,100,5)65239653654REFERENCES:655656.. [DW] Daqing Wan, "Dimension variation of classical and p-adic modular657forms", Invent. Math. 133, (1998) 449-463.658"""659k0 = k % (p-1)660ds = [dimension_modular_forms(N, k0)]661ms = [ds[0]]662sum = 0663u = 1664665ord = 0666while ord < m:667ds.append(dimension_modular_forms(N,k0 + u*(p-1)))668ms.append(ds[u] - ds[u-1])669sum = sum + u*ms[u]670ord = floor(((p-1)/(p+1))*sum - ds[u])671u = u + 1672673return (ds[u-1] - 1)674675# *** MAIN FUNCTION FOR LEVEL > 1 ***676677# Returns matrix A modulo p^m from Step 6 of Algorithm 2.678679def higher_level_UpGj(p,N,klist,m,modformsring,bound):680r"""681Returns a list ``[A_k]`` of square matrices over ``IntegerRing(p^m)``682parameterised by the weights k in ``klist``. The matrix `A_k` is the finite683square matrix which occurs on input p,k,N and m in Step 6 of Algorithm 2 in684[AGBL]_. Notational change from paper: In Step 1 following Wan we defined685j by `k = k_0 + j(p-1)` with `0 \le k_0 < p-1`. Here we replace j by686``kdiv`` so that we may use j as a column index for matrices.)687688INPUT:689690- ``p`` -- prime at least 5.691- ``N`` -- integer at least 2 and not divisible by p (level).692- ``klist`` -- list of integers all congruent modulo (p-1) (the weights).693- ``m`` -- positive integer.694- ``modformsring`` -- True or False.695- ``bound`` -- (even) positive integer.696697OUTPUT:698699- list of square matrices.700701EXAMPLES::702703sage: from sage.modular.overconvergent.hecke_series import higher_level_UpGj704sage: higher_level_UpGj(5,3,[4],2,true,6)705[706[ 1 0 0 0 0 0]707[ 0 1 0 0 0 0]708[ 0 7 0 0 0 0]709[ 0 5 10 20 0 0]710[ 0 7 20 0 20 0]711[ 0 1 24 0 20 0]712]713714"""715t = cputime()716# Step 1717718k0 = klist[0] % (p-1)719n = floor(((p+1)/(p-1)) * (m+1))720elldash = compute_elldash(p,N,k0,n)721elldashp = elldash*p722mdash = m + ceil(n/(p+1))723724verbose("done step 1",t)725t = cputime()726# Steps 2 and 3727728e,Ep1 = higher_level_katz_exp(p,N,k0,m,mdash,elldash,elldashp,modformsring,bound)729ell = dimension(transpose(e)[0].parent())730S = e[0,0].parent()731732verbose("done steps 2+3", t)733t = cputime()734# Step 4735736R = Ep1.parent()737G = compute_G(p, Ep1)738Alist = []739740verbose("done step 4a", t)741t = cputime()742for k in klist:743k = ZZ(k) # convert to sage integer744kdiv = k // (p-1)745Gkdiv = G**kdiv746747T = matrix(S,ell,elldash)748for i in xrange(ell):749ei = R(e[i].list())750Gkdivei = Gkdiv*ei; # act by G^kdiv751for j in xrange(0, elldash):752T[i,j] = Gkdivei[p*j]753754verbose("done steps 4b and 5", t)755t = cputime()756757# Step 6: solve T = AE using fact E is upper triangular.758# Warning: assumes that T = AE (rather than pT = AE) has759# a solution over Z/(p^mdash). This has always been the case in760# examples computed by the author, see Note 3.1.761762A = matrix(S,ell,ell)763verbose("solving a square matrix problem of dimension %s" % ell)764verbose("elldash is %s" % elldash)765766for i in xrange(0,ell):767Ti = T[i]768for j in xrange(0,ell):769ej = Ti.parent()([e[j][l] for l in xrange(0,elldash)])770ejleadpos = ej.nonzero_positions()[0]771lj = ZZ(ej[ejleadpos])772A[i,j] = S(ZZ(Ti[j])/lj)773Ti = Ti - A[i,j]*ej774775Alist.append(MatrixSpace(Zmod(p**m),ell,ell)(A))776verbose("done step 6", t)777778return Alist779780781# *** LEVEL 1 CODE ***782783def compute_Wi(k,p,h,hj,E4,E6):784r"""785This function computes a list `W_i` of q-expansions, together with an786auxilliary quantity `h^j` (see below) which is to be used on the next787call of this function. (The precision is that of input q-expansions.)788789The list `W_i` is a certain subset of a basis of the modular forms of790weight `k` and level 1. Suppose `(a, b)` is the pair of non-negative791integers with `4a + 6b = k` and `a` minimal among such pairs. Then this792space has a basis given by793794.. math::795796\{ \Delta^j E_6^{b - 2j} E_4^a : 0 \le j < d\}797798where `d` is the dimension.799800What this function returns is the subset of the above basis corresponding801to `e \le j < d` where `e` is the dimension of the space of modular forms802of weight `k - (p-1)`. This set is a basis for the complement of the image803of the weight `k - (p-1)` forms under multiplication by `E_{p-1}`.804805This function is used repeatedly in the construction of the Katz expansion806basis. Hence considerable care is taken to reuse steps in the computation807wherever possible: we keep track of powers of the form `h = \Delta /808E_6^2`.809810INPUT:811812- ``k`` -- non-negative integer.813- ``p`` -- prime at least 5.814- ``h`` -- q-expansion of `h` (to some finite precision).815- ``hj`` -- q-expansion of h^j where j is the dimension of the space of816modular forms of level 1 and weight `k - (p-1)` (to same finite817precision).818- ``E4`` -- q-expansion of ``E_4`` (to same finite precision).819- ``E6`` -- q-expansion of ``E_6`` (to same finite precision).820821The Eisenstein series q-expansions should be normalized to have constant822term 1.823824OUTPUT:825826- list of q-expansions (to same finite precision), and q-expansion.827828EXAMPLES::829830sage: from sage.modular.overconvergent.hecke_series import compute_Wi831sage: p = 17832sage: prec = 10833sage: k = 24834sage: S = Zmod(17^3)835sage: E4 = eisenstein_series_qexp(4, prec, K=S, normalization="constant")836sage: E6 = eisenstein_series_qexp(6, prec, K=S, normalization="constant")837sage: h = delta_qexp(prec, K=S) / E6^2838sage: j = dimension_modular_forms(1, k - (p-1))839sage: hj = h**j840sage: c = compute_Wi(k,p,h,hj,E4,E6); c841([q + 3881*q^2 + 4459*q^3 + 4665*q^4 + 2966*q^5 + 1902*q^6 + 1350*q^7 + 3836*q^8 + 1752*q^9 + O(q^10), q^2 + 4865*q^3 + 1080*q^4 + 4612*q^5 + 1343*q^6 + 1689*q^7 + 3876*q^8 + 1381*q^9 + O(q^10)], q^3 + 2952*q^4 + 1278*q^5 + 3225*q^6 + 1286*q^7 + 589*q^8 + 122*q^9 + O(q^10))842sage: c == ([delta_qexp(10) * E6^2, delta_qexp(10)^2], h**3)843True844"""845846# Define a and b847a = k % 3848b = (k // 2) % 2849850# Compute dimensions required for Miller basis851d = dimension_modular_forms(1, k) - 1852e = dimension_modular_forms(1, k-(p-1)) - 1853854# This next line is a bit of a bottleneck, particularly when m is large but855# p is small. It would be good to reuse values calculated on the previous856# call here somehow.857r = E6**(2*d + b) * E4**a858859prec = E4.prec() # everything gets trucated to this precision860861# Construct basis for Wi862Wi = []863for j in xrange(e+1,d+1):864# compute aj = delta^j*E6^(2*(d-j) + b)*E4^a865verbose("k = %s, computing Delta^%s E6^%s E4^%s" % (k, j, 2*(d-j) + b, a), level=2)866aj = (hj * r).truncate_powerseries(prec)867hj = (hj * h).truncate_powerseries(prec)868Wi.append(aj)869870return Wi,hj871872def katz_expansions(k0,p,ellp,mdash,n):873r"""874Returns a list e of q-expansions, and the Eisenstein series `E_{p-1} = 1 +875\dots`, all modulo `(p^\text{mdash},q^\text{ellp})`. The list e contains876the elements `e_{i,s}` in the Katz expansions basis in Step 3 of Algorithm8771 in [AGBL]_ when one takes as input to that algorithm p,m and k and define878``k0``, ``mdash``, n, ``ellp = ell*p`` as in Step 1.879880INPUT:881882- ``k0`` -- integer in range 0 to p-1.883- ``p`` -- prime at least 5.884- ``ellp,mdash,n`` -- positive integers.885886OUTPUT:887888- list of q-expansions and the Eisenstein series E_{p-1} modulo889`(p^\text{mdash},q^\text{ellp})`.890891EXAMPLES::892893sage: from sage.modular.overconvergent.hecke_series import katz_expansions894sage: katz_expansions(0,5,10,3,4)895([1 + O(q^10), q + 6*q^2 + 27*q^3 + 98*q^4 + 65*q^5 + 37*q^6 + 81*q^7 + 85*q^8 + 62*q^9 + O(q^10)],8961 + 115*q + 35*q^2 + 95*q^3 + 20*q^4 + 115*q^5 + 105*q^6 + 60*q^7 + 25*q^8 + 55*q^9 + O(q^10))897"""898S = Zmod(p**mdash)899900Ep1 = eisenstein_series_qexp(p-1, ellp, K=S, normalization="constant")901E4 = eisenstein_series_qexp(4, ellp, K=S, normalization="constant")902E6 = eisenstein_series_qexp(6, ellp, K=S, normalization="constant")903904delta = delta_qexp(ellp, K=S)905h = delta / E6**2906hj = delta.parent()(1)907e = []908909# We compute negative powers of E_(p-1) successively (this saves a great910# deal of time). The effect is that Ep1mi = Ep1 ** (-i).911Ep1m1 = ~Ep1912Ep1mi = 1913for i in xrange(0,n+1):914Wi,hj = compute_Wi(k0 + i*(p-1),p,h,hj,E4,E6)915for bis in Wi:916eis = p**floor(i/(p+1)) * Ep1mi * bis917e.append(eis)918Ep1mi = Ep1mi * Ep1m1919920return e,Ep1921922# *** MAIN FUNCTION FOR LEVEL 1 ***923924def level1_UpGj(p,klist,m):925r"""926Returns a list `[A_k]` of square matrices over ``IntegerRing(p^m)``927parameterised by the weights k in ``klist``. The matrix `A_k` is the finite928square matrix which occurs on input p,k and m in Step 6 of Algorithm 1 in929[AGBL]_. Notational change from paper: In Step 1 following Wan we defined930j by `k = k_0 + j(p-1)` with `0 \le k_0 < p-1`. Here we replace j by931``kdiv`` so that we may use j as a column index for matrices.932933INPUT:934935- ``p`` -- prime at least 5.936- ``klist`` -- list of integers congruent modulo `(p-1)` (the weights).937- ``m`` -- positive integer.938939OUTPUT:940941- list of square matrices.942943EXAMPLES::944945sage: from sage.modular.overconvergent.hecke_series import level1_UpGj946sage: level1_UpGj(7,[100],5)947[948[ 1 980 4802 0 0]949[ 0 13727 14406 0 0]950[ 0 13440 7203 0 0]951[ 0 1995 4802 0 0]952[ 0 9212 14406 0 0]953]954"""955# Step 1956t = cputime()957958k0 = klist[0] % (p-1)959n = floor(((p+1)/(p-1)) * (m+1))960ell = dimension_modular_forms(1, k0 + n*(p-1))961ellp = ell*p962mdash = m + ceil(n/(p+1))963964verbose("done step 1", t)965t = cputime()966# Steps 2 and 3967968e,Ep1 = katz_expansions(k0,p,ellp,mdash,n)969970verbose("done steps 2+3", t)971t=cputime()972# Step 4973974G = compute_G(p, Ep1)975Alist = []976977verbose("done step 4a", t)978t=cputime()979for k in klist:980k = ZZ(k) # convert to sage integer981kdiv = k // (p-1)982Gkdiv = G**kdiv983u = []984for i in xrange(0,ell):985ei = e[i]986ui = Gkdiv*ei987u.append(ui)988989verbose("done step 4b", t)990t = cputime()991# Step 5 and computation of T in Step 6992993S = e[0][0].parent()994T = matrix(S,ell,ell)995996for i in xrange(0,ell):997for j in xrange(0,ell):998T[i,j] = u[i][p*j]9991000verbose("done step 5", t)1001t = cputime()1002# Step 6: solve T = AE using fact E is upper triangular.1003# Warning: assumes that T = AE (rather than pT = AE) has1004# a solution over Z/(p^mdash). This has always been the case in1005# examples computed by the author, see Note 3.1.10061007A = matrix(S,ell,ell)1008verbose("solving a square matrix problem of dimension %s" % ell, t)10091010for i in xrange(0,ell):1011Ti = T[i]1012for j in xrange(0,ell):1013ej = Ti.parent()([e[j][l] for l in xrange(0,ell)])1014lj = ZZ(ej[j])1015A[i,j] = S(ZZ(Ti[j])/lj)1016Ti = Ti - A[i,j]*ej10171018Alist.append(MatrixSpace(Zmod(p**m),ell,ell)(A))1019verbose("done step 6", t)10201021return Alist10221023# *** CODE FOR GENERAL LEVEL ***10241025def is_valid_weight_list(klist,p):1026r"""1027This function checks that ``klist`` is a nonempty list of integers all of1028which are congruent modulo `(p-1)`. Otherwise, it will raise a ValueError.10291030INPUT:10311032- ``klist`` -- list of integers.1033- ``p`` -- prime.10341035EXAMPLES::10361037sage: from sage.modular.overconvergent.hecke_series import is_valid_weight_list1038sage: is_valid_weight_list([10,20,30],11)1039sage: is_valid_weight_list([-3, 1], 5)1040sage: is_valid_weight_list([], 3)1041Traceback (most recent call last):1042...1043ValueError: List of weights must be non-empty1044sage: is_valid_weight_list([-3, 2], 5)1045Traceback (most recent call last):1046...1047ValueError: List of weights must be all congruent modulo p-1 = 4, but given list contains -3 and 2 which are not congruent1048"""1049if len(klist) == 0:1050raise ValueError, "List of weights must be non-empty"1051k0 = klist[0] % (p-1)1052for i in xrange(1,len(klist)):1053if (klist[i] % (p-1)) != k0:1054raise ValueError, "List of weights must be all congruent modulo p-1 = %s, but given list contains %s and %s which are not congruent" % (p-1, klist[0], klist[i])10551056def hecke_series(p,N,klist,m, modformsring = False, weightbound = 6):1057r"""1058Returns the characteristic series modulo `p^m` of the Atkin operator `U_p`1059acting upon the space of p-adic overconvergent modular forms of level1060`\Gamma_0(N)` and weight ``klist``. The input ``klist`` may also be a list1061of weights congruent modulo `(p-1)`, in which case the output is the1062corresponding list of characteristic series for each `k` in ``klist``; this1063is faster than performing the computation separately for each `k`, since1064intermediate steps in the computation may be reused.10651066If ``modformsring`` is True, then for `N > 1` the algorithm computes at one1067step ``ModularFormsRing(N).generators()``. This will often be faster but1068the algorithm will default to ``modformsring = False`` if the generators1069found are not p-adically integral. Note that ``modformsring`` is ignored1070for `N = 1` and the ring structure of modular forms is *always* used in1071this case.10721073When ``modformsring`` is False and `N > 1`, `weightbound` is a bound set on1074the weight of generators for a certain subspace of modular forms. The1075algorithm will often be faster if ``weightbound = 4``, but it may fail to1076terminate for certain exceptional small values of `N`, when this bound is1077too small.10781079The algorithm is based upon that described in [AGBL]_.10801081INPUT:10821083- ``p`` -- a prime greater than or equal to 5.1084- ``N`` -- a positive integer not divisible by `p`.1085- ``klist`` -- either a list of integers congruent modulo `(p-1)`, or a single integer.1086- ``m`` -- a positive integer.1087- ``modformsring`` -- ``True`` or ``False`` (optional, default ``False``).1088Ignored if `N = 1`.1089- ``weightbound`` -- a positive even integer (optional, default 6). Ignored1090if `N = 1` or ``modformsring`` is True.10911092OUTPUT:10931094Either a list of polynomials or a single polynomial over the integers modulo `p^m`.10951096EXAMPLES::10971098sage: hecke_series(5,7,10000,5, modformsring = True) # long time (3.4s)1099250*x^6 + 1825*x^5 + 2500*x^4 + 2184*x^3 + 1458*x^2 + 1157*x + 11100sage: hecke_series(7,3,10000,3, weightbound = 4)1101196*x^4 + 294*x^3 + 197*x^2 + 341*x + 11102sage: hecke_series(19,1,[10000,10018],5)1103[1694173*x^4 + 2442526*x^3 + 1367943*x^2 + 1923654*x + 1,1104130321*x^4 + 958816*x^3 + 2278233*x^2 + 1584827*x + 1]11051106Check that silly weights are handled correctly::11071108sage: hecke_series(5, 7, [2, 3], 5)1109Traceback (most recent call last):1110...1111ValueError: List of weights must be all congruent modulo p-1 = 4, but given list contains 2 and 3 which are not congruent1112sage: hecke_series(5, 7, [3], 5)1113[1]1114sage: hecke_series(5, 7, 3, 5)111511116"""1117# convert to sage integers1118p = ZZ(p)1119N = ZZ(N)1120m = ZZ(m)1121weightbound = ZZ(weightbound)11221123oneweight = False1124# convert single weight to list1125if ((type(klist) == int) or (type(klist) == Integer)):1126klist = [klist]1127oneweight = True # input is single weight11281129# algorithm may finish with false output unless:1130is_valid_weight_list(klist,p)1131if not p.is_prime():1132raise ValueError, "p (=%s) is not prime" % p1133if p < 5:1134raise ValueError, "p = 2 and p = 3 not supported"1135if not N%p:1136raise ValueError, "Level (=%s) should be prime to p (=%s)" % (N, p)11371138# return all 1 list for odd weights1139if klist[0] % 2 == 1:1140if oneweight:1141return 11142else:1143return [1 for i in xrange(len(klist))]11441145if N == 1:1146Alist = level1_UpGj(p,klist,m)1147else:1148Alist = higher_level_UpGj(p,N,klist,m,modformsring,weightbound)11491150Plist = []1151for A in Alist:1152P = charpoly(A).reverse()1153Plist.append(P)11541155if oneweight == True:1156return Plist[0]1157else:1158return Plist115911601161