def eisenstein_series_qexp(k, prec = 10, K=QQ, var='q', normalization='linear'): r""" Return the `q`-expansion of the normalized weight `k` Eisenstein series on `{\rm SL}_2(\ZZ)` to precision prec in the ring `K`. Three normalizations are available, depending on the parameter ``normalization``; the default normalization is the one for which the linear coefficient is 1. INPUT: - ``k`` - an even positive integer - ``prec`` - (default: 10) a nonnegative integer - ``K`` - (default: `\QQ`) a ring - ``var`` - (default: ``'q'``) variable name to use for q-expansion - ``normalization`` - (default: ``'linear'``) normalization to use. If this is ``'linear'``, then the series will be normalized so that the linear term is 1. If it is ``'constant'``, the series will be normalized to have constant term 1. If it is ``'integral'``, then the series will be normalized to have integer coefficients and no common factor, and linear term that is positive. Note that ``'integral'`` will work over arbitrary base rings, while ``'linear'`` or ``'constant'`` will fail if the denominator (resp. numerator) of `B_k / 2k` is invertible. ALGORITHM: We know `E_k = \text{constant} + \sum_n \sigma_{k-1}(n) q^n`. So we compute all the `\sigma_{k-1}(n)` simultaneously, using the fact that `\sigma` is multiplicative. EXAMPLES:: sage: eisenstein_series_qexp(2,5) -1/24 + q + 3*q^2 + 4*q^3 + 7*q^4 + O(q^5) sage: eisenstein_series_qexp(2,0) O(q^0) sage: eisenstein_series_qexp(2,5,GF(7)) 2 + q + 3*q^2 + 4*q^3 + O(q^5) sage: eisenstein_series_qexp(2,5,GF(7),var='T') 2 + T + 3*T^2 + 4*T^3 + O(T^5) We illustrate the use of the ``normalization`` parameter:: sage: eisenstein_series_qexp(12, 5, normalization='integral') 691 + 65520*q + 134250480*q^2 + 11606736960*q^3 + 274945048560*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 5, normalization='constant') 1 + 65520/691*q + 134250480/691*q^2 + 11606736960/691*q^3 + 274945048560/691*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 5, normalization='linear') 691/65520 + q + 2049*q^2 + 177148*q^3 + 4196353*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 50, K=GF(13), normalization="constant") 1 + O(q^50) TESTS: Test that :trac:`5102` is fixed:: sage: eisenstein_series_qexp(10, 30, GF(17)) 15 + 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) This shows that the bug reported at :trac:`8291` is fixed:: sage: eisenstein_series_qexp(26, 10, GF(13)) 7 + 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) We check that the function behaves properly over finite-characteristic base rings:: sage: eisenstein_series_qexp(12, 5, K = Zmod(691), normalization="integral") 566*q + 236*q^2 + 286*q^3 + 194*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 5, K = Zmod(691), normalization="constant") Traceback (most recent call last): ... ValueError: The numerator of -B_k/(2*k) (=691) must be invertible in the ring Ring of integers modulo 691 sage: eisenstein_series_qexp(12, 5, K = Zmod(691), normalization="linear") q + 667*q^2 + 252*q^3 + 601*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 5, K = Zmod(2), normalization="integral") 1 + O(q^5) sage: eisenstein_series_qexp(12, 5, K = Zmod(2), normalization="constant") 1 + O(q^5) sage: eisenstein_series_qexp(12, 5, K = Zmod(2), normalization="linear") Traceback (most recent call last): ... ValueError: The denominator of -B_k/(2*k) (=65520) must be invertible in the ring Ring of integers modulo 2 AUTHORS: - William Stein: original implementation - Craig Citro (2007-06-01): rewrote for massive speedup - Martin Raum (2009-08-02): port to cython for speedup - David Loeffler (2010-04-07): work around an integer overflow when `k` is large - David Loeffler (2012-03-15): add options for alternative normalizations (motivated by :trac:`12043`) """ ## we use this to prevent computation if it would fail anyway. if k <= 0 or k % 2 == 1 : raise ValueError("k must be positive and even") a0 = - bernoulli(k) / (2*k) if normalization == 'linear': a0den = a0.denominator() try: a0fac = K(1/a0den) except ZeroDivisionError: raise ValueError("The denominator of -B_k/(2*k) (=%s) must be invertible in the ring %s"%(a0den, K)) elif normalization == 'constant': a0num = a0.numerator() try: a0fac = K(1/a0num) except ZeroDivisionError: raise ValueError("The numerator of -B_k/(2*k) (=%s) must be invertible in the ring %s"%(a0num, K)) elif normalization == 'integral': a0fac = None else: raise ValueError("Normalization (=%s) must be one of 'linear', 'constant', 'integral'" % normalization) R = PowerSeriesRing(K, var) if K == QQ and normalization == 'linear': ls = Ek_ZZ(k, prec) # The following is *dramatically* faster than doing the more natural # "R(ls)" would be: E = ZZ[var](ls, prec=prec, check=False).change_ring(QQ) if len(ls)>0: E._unsafe_mutate(0, a0) return R(E, prec) # The following is an older slower alternative to the above three lines: #return a0fac*R(eisenstein_series_poly(k, prec).list(), prec=prec, check=False) else: # This used to work with check=False, but that can only be regarded as # an improbable lucky miracle. Enabling checking is a noticeable speed # regression; the morally right fix would be to expose FLINT's # fmpz_poly_to_nmod_poly command (at least for word-sized N). if a0fac is not None: return a0fac*R(eisenstein_series_poly(k, prec).list(), prec=prec, check=True) else: return R(eisenstein_series_poly(k, prec).list(), prec=prec, check=True)
def victor_miller_basis(k, prec=10, cusp_only=False, var='q'): r""" Compute and return the Victor Miller basis for modular forms of weight `k` and level 1 to precision `O(q^{prec})`. If ``cusp_only`` is True, return only a basis for the cuspidal subspace. INPUT: - ``k`` -- an integer - ``prec`` -- (default: 10) a positive integer - ``cusp_only`` -- bool (default: False) - ``var`` -- string (default: 'q') OUTPUT: A sequence whose entries are power series in ``ZZ[[var]]``. EXAMPLES:: sage: victor_miller_basis(1, 6) [] sage: victor_miller_basis(0, 6) [ 1 + O(q^6) ] sage: victor_miller_basis(2, 6) [] sage: victor_miller_basis(4, 6) [ 1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + O(q^6) ] sage: victor_miller_basis(6, 6, var='w') [ 1 - 504*w - 16632*w^2 - 122976*w^3 - 532728*w^4 - 1575504*w^5 + O(w^6) ] sage: victor_miller_basis(6, 6) [ 1 - 504*q - 16632*q^2 - 122976*q^3 - 532728*q^4 - 1575504*q^5 + O(q^6) ] sage: victor_miller_basis(12, 6) [ 1 + 196560*q^2 + 16773120*q^3 + 398034000*q^4 + 4629381120*q^5 + O(q^6), q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 + O(q^6) ] sage: victor_miller_basis(12, 6, cusp_only=True) [ q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 + O(q^6) ] sage: victor_miller_basis(24, 6, cusp_only=True) [ q + 195660*q^3 + 12080128*q^4 + 44656110*q^5 + O(q^6), q^2 - 48*q^3 + 1080*q^4 - 15040*q^5 + O(q^6) ] sage: victor_miller_basis(24, 6) [ 1 + 52416000*q^3 + 39007332000*q^4 + 6609020221440*q^5 + O(q^6), q + 195660*q^3 + 12080128*q^4 + 44656110*q^5 + O(q^6), q^2 - 48*q^3 + 1080*q^4 - 15040*q^5 + O(q^6) ] sage: victor_miller_basis(32, 6) [ 1 + 2611200*q^3 + 19524758400*q^4 + 19715347537920*q^5 + O(q^6), q + 50220*q^3 + 87866368*q^4 + 18647219790*q^5 + O(q^6), q^2 + 432*q^3 + 39960*q^4 - 1418560*q^5 + O(q^6) ] sage: victor_miller_basis(40,200)[1:] == victor_miller_basis(40,200,cusp_only=True) True sage: victor_miller_basis(200,40)[1:] == victor_miller_basis(200,40,cusp_only=True) True AUTHORS: - William Stein, Craig Citro: original code - Martin Raum (2009-08-02): use FLINT for polynomial arithmetic (instead of NTL) """ k = Integer(k) if k%2 == 1 or k==2: return Sequence([]) elif k < 0: raise ValueError("k must be non-negative") elif k == 0: return Sequence([PowerSeriesRing(ZZ,var)(1).add_bigoh(prec)], cr=True) e = k.mod(12) if e == 2: e += 12 n = (k-e) // 12 if n == 0 and cusp_only: return Sequence([]) # If prec is less than or equal to the dimension of the space of # cusp forms, which is just n, then we know the answer, and we # simply return it. if prec <= n: q = PowerSeriesRing(ZZ,var).gen(0) err = bigO(q**prec) ls = [0] * (n+1) if not cusp_only: ls[0] = 1 + err for i in range(1,prec): ls[i] = q**i + err for i in range(prec,n+1): ls[i] = err return Sequence(ls, cr=True) F6 = eisenstein_series_poly(6,prec) if e == 0: A = Fmpz_poly(1) elif e == 4: A = eisenstein_series_poly(4,prec) elif e == 6: A = F6 elif e == 8: A = eisenstein_series_poly(8,prec) elif e == 10: A = eisenstein_series_poly(10,prec) else: # e == 14 A = eisenstein_series_poly(14,prec) if A[0] == -1 : A = -A if n == 0: return Sequence([PowerSeriesRing(ZZ,var)(A.list()).add_bigoh(prec)],cr=True) F6_squared = F6**2 F6_squared._unsafe_mutate_truncate(prec) D = _delta_poly(prec) Fprod = F6_squared Dprod = D if cusp_only: ls = [Fmpz_poly(0)] + [A] * n else: ls = [A] * (n+1) for i in xrange(1,n+1): ls[n-i] *= Fprod ls[i] *= Dprod ls[n-i]._unsafe_mutate_truncate(prec) ls[i]._unsafe_mutate_truncate(prec) Fprod *= F6_squared Dprod *= D Fprod._unsafe_mutate_truncate(prec) Dprod._unsafe_mutate_truncate(prec) P = PowerSeriesRing(ZZ,var) if cusp_only : for i in xrange(1,n+1) : for j in xrange(1, i) : ls[j] = ls[j] - ls[j][i]*ls[i] return Sequence(map(lambda l: P(l.list()).add_bigoh(prec), ls[1:]),cr=True) else : for i in xrange(1,n+1) : for j in xrange(i) : ls[j] = ls[j] - ls[j][i]*ls[i] return Sequence(map(lambda l: P(l.list()).add_bigoh(prec), ls), cr=True)
def eisenstein_series_qexp(k, prec = 10, K=QQ, var='q') : r""" Return the `q`-expansion of the normalized weight `k` Eisenstein series on `{\rm SL}_2(\ZZ)` to precision prec in the ring `K`. (The normalization chosen here is the one that forces the coefficient of `q` to be 1.) INPUT: - ``k`` - an even positive integer - ``prec`` - (default: 10) a nonnegative integer - ``K`` - (default: `\QQ`) a ring in which the denominator of `B_k / 2k` is invertible - ``var`` - (default: 'q') variable name to use for q-expansion ALGORITHM: We know `E_k = \text{constant} + \sum_n \sigma_{k-1}(n) q^n`. So we compute all the `\sigma_{k-1}(n)` simultaneously, using the fact that `\sigma` is multiplicative. EXAMPLES:: sage: eisenstein_series_qexp(2,5) -1/24 + q + 3*q^2 + 4*q^3 + 7*q^4 + O(q^5) sage: eisenstein_series_qexp(2,0) O(q^0) sage: eisenstein_series_qexp(2,5,GF(7)) 2 + q + 3*q^2 + 4*q^3 + O(q^5) sage: eisenstein_series_qexp(2,5,GF(7),var='T') 2 + T + 3*T^2 + 4*T^3 + O(T^5) sage: eisenstein_series_qexp(10, 30, GF(17)) 15 + 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) TESTS: This shows that the bug reported at trac 8291 is fixed:: sage: eisenstein_series_qexp(26, 10, GF(13)) 7 + 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) AUTHORS: - William Stein: original implementation - Craig Citro (2007-06-01): rewrote for massive speedup - Martin Raum (2009-08-02): port to cython for speedup - David Loeffler (2010-04-07): work around an integer overflow when k is large """ ## we use this to prevent computation if it would fail anyway. if k <= 0 or k % 2 == 1 : raise ValueError, "k must be positive and even" a0 = - bernoulli(k) / (2*k) a0den = a0.denominator() try: a0fac = K(1/a0den) except ZeroDivisionError: raise ValueError, "The denominator of -B_k/(2*k) (=%s) must be invertible in the ring %s"%(a0den, K) R = PowerSeriesRing(K, var) if K == QQ: ls = Ek_ZZ(k, prec) # The following is *dramatically* faster than doing the more natural # "R(ls)" would be: E = ZZ[var](ls, prec=prec, check=False).change_ring(QQ) if len(ls)>0: E._unsafe_mutate(0, a0) return R(E, prec) # The following is an older slower alternative to the above three lines: #return a0fac*R(eisenstein_series_poly(k, prec).list(), prec=prec, check=False) else: # this is a temporary fix due to a change in the # polynomial constructor over finite fields; this # is a notable speed regression, to be fixed soon. return a0fac*R(eisenstein_series_poly(k, prec).list(), prec=prec, check=True)
def eisenstein_series_qexp(k, prec=10, K=QQ, var='q', normalization='linear'): r""" Return the `q`-expansion of the normalized weight `k` Eisenstein series on `{\rm SL}_2(\ZZ)` to precision prec in the ring `K`. Three normalizations are available, depending on the parameter ``normalization``; the default normalization is the one for which the linear coefficient is 1. INPUT: - ``k`` - an even positive integer - ``prec`` - (default: 10) a nonnegative integer - ``K`` - (default: `\QQ`) a ring - ``var`` - (default: ``'q'``) variable name to use for q-expansion - ``normalization`` - (default: ``'linear'``) normalization to use. If this is ``'linear'``, then the series will be normalized so that the linear term is 1. If it is ``'constant'``, the series will be normalized to have constant term 1. If it is ``'integral'``, then the series will be normalized to have integer coefficients and no common factor, and linear term that is positive. Note that ``'integral'`` will work over arbitrary base rings, while ``'linear'`` or ``'constant'`` will fail if the denominator (resp. numerator) of `B_k / 2k` is invertible. ALGORITHM: We know `E_k = \text{constant} + \sum_n \sigma_{k-1}(n) q^n`. So we compute all the `\sigma_{k-1}(n)` simultaneously, using the fact that `\sigma` is multiplicative. EXAMPLES:: sage: eisenstein_series_qexp(2,5) -1/24 + q + 3*q^2 + 4*q^3 + 7*q^4 + O(q^5) sage: eisenstein_series_qexp(2,0) O(q^0) sage: eisenstein_series_qexp(2,5,GF(7)) 2 + q + 3*q^2 + 4*q^3 + O(q^5) sage: eisenstein_series_qexp(2,5,GF(7),var='T') 2 + T + 3*T^2 + 4*T^3 + O(T^5) We illustrate the use of the ``normalization`` parameter:: sage: eisenstein_series_qexp(12, 5, normalization='integral') 691 + 65520*q + 134250480*q^2 + 11606736960*q^3 + 274945048560*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 5, normalization='constant') 1 + 65520/691*q + 134250480/691*q^2 + 11606736960/691*q^3 + 274945048560/691*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 5, normalization='linear') 691/65520 + q + 2049*q^2 + 177148*q^3 + 4196353*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 50, K=GF(13), normalization="constant") 1 + O(q^50) TESTS: Test that :trac:`5102` is fixed:: sage: eisenstein_series_qexp(10, 30, GF(17)) 15 + 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) This shows that the bug reported at :trac:`8291` is fixed:: sage: eisenstein_series_qexp(26, 10, GF(13)) 7 + 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) We check that the function behaves properly over finite-characteristic base rings:: sage: eisenstein_series_qexp(12, 5, K = Zmod(691), normalization="integral") 566*q + 236*q^2 + 286*q^3 + 194*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 5, K = Zmod(691), normalization="constant") Traceback (most recent call last): ... ValueError: The numerator of -B_k/(2*k) (=691) must be invertible in the ring Ring of integers modulo 691 sage: eisenstein_series_qexp(12, 5, K = Zmod(691), normalization="linear") q + 667*q^2 + 252*q^3 + 601*q^4 + O(q^5) sage: eisenstein_series_qexp(12, 5, K = Zmod(2), normalization="integral") 1 + O(q^5) sage: eisenstein_series_qexp(12, 5, K = Zmod(2), normalization="constant") 1 + O(q^5) sage: eisenstein_series_qexp(12, 5, K = Zmod(2), normalization="linear") Traceback (most recent call last): ... ValueError: The denominator of -B_k/(2*k) (=65520) must be invertible in the ring Ring of integers modulo 2 AUTHORS: - William Stein: original implementation - Craig Citro (2007-06-01): rewrote for massive speedup - Martin Raum (2009-08-02): port to cython for speedup - David Loeffler (2010-04-07): work around an integer overflow when `k` is large - David Loeffler (2012-03-15): add options for alternative normalizations (motivated by :trac:`12043`) """ ## we use this to prevent computation if it would fail anyway. if k <= 0 or k % 2 == 1: raise ValueError, "k must be positive and even" a0 = -bernoulli(k) / (2 * k) if normalization == 'linear': a0den = a0.denominator() try: a0fac = K(1 / a0den) except ZeroDivisionError: raise ValueError, "The denominator of -B_k/(2*k) (=%s) must be invertible in the ring %s" % ( a0den, K) elif normalization == 'constant': a0num = a0.numerator() try: a0fac = K(1 / a0num) except ZeroDivisionError: raise ValueError, "The numerator of -B_k/(2*k) (=%s) must be invertible in the ring %s" % ( a0num, K) elif normalization == 'integral': a0fac = None else: raise ValueError, "Normalization (=%s) must be one of 'linear', 'constant', 'integral'" % normalization R = PowerSeriesRing(K, var) if K == QQ and normalization == 'linear': ls = Ek_ZZ(k, prec) # The following is *dramatically* faster than doing the more natural # "R(ls)" would be: E = ZZ[var](ls, prec=prec, check=False).change_ring(QQ) if len(ls) > 0: E._unsafe_mutate(0, a0) return R(E, prec) # The following is an older slower alternative to the above three lines: #return a0fac*R(eisenstein_series_poly(k, prec).list(), prec=prec, check=False) else: # This used to work with check=False, but that can only be regarded as # an improbable lucky miracle. Enabling checking is a noticeable speed # regression; the morally right fix would be to expose FLINT's # fmpz_poly_to_nmod_poly command (at least for word-sized N). if a0fac is not None: return a0fac * R( eisenstein_series_poly(k, prec).list(), prec=prec, check=True) else: return R(eisenstein_series_poly(k, prec).list(), prec=prec, check=True)
def victor_miller_basis(k, prec=10, cusp_only=False, var='q'): r""" Compute and return the Victor Miller basis for modular forms of weight `k` and level 1 to precision `O(q^{prec})`. If ``cusp_only`` is True, return only a basis for the cuspidal subspace. INPUT: - ``k`` -- an integer - ``prec`` -- (default: 10) a positive integer - ``cusp_only`` -- bool (default: False) - ``var`` -- string (default: 'q') OUTPUT: A sequence whose entries are power series in ``ZZ[[var]]``. EXAMPLES:: sage: victor_miller_basis(1, 6) [] sage: victor_miller_basis(0, 6) [ 1 + O(q^6) ] sage: victor_miller_basis(2, 6) [] sage: victor_miller_basis(4, 6) [ 1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + O(q^6) ] sage: victor_miller_basis(6, 6, var='w') [ 1 - 504*w - 16632*w^2 - 122976*w^3 - 532728*w^4 - 1575504*w^5 + O(w^6) ] sage: victor_miller_basis(6, 6) [ 1 - 504*q - 16632*q^2 - 122976*q^3 - 532728*q^4 - 1575504*q^5 + O(q^6) ] sage: victor_miller_basis(12, 6) [ 1 + 196560*q^2 + 16773120*q^3 + 398034000*q^4 + 4629381120*q^5 + O(q^6), q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 + O(q^6) ] sage: victor_miller_basis(12, 6, cusp_only=True) [ q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 + O(q^6) ] sage: victor_miller_basis(24, 6, cusp_only=True) [ q + 195660*q^3 + 12080128*q^4 + 44656110*q^5 + O(q^6), q^2 - 48*q^3 + 1080*q^4 - 15040*q^5 + O(q^6) ] sage: victor_miller_basis(24, 6) [ 1 + 52416000*q^3 + 39007332000*q^4 + 6609020221440*q^5 + O(q^6), q + 195660*q^3 + 12080128*q^4 + 44656110*q^5 + O(q^6), q^2 - 48*q^3 + 1080*q^4 - 15040*q^5 + O(q^6) ] sage: victor_miller_basis(32, 6) [ 1 + 2611200*q^3 + 19524758400*q^4 + 19715347537920*q^5 + O(q^6), q + 50220*q^3 + 87866368*q^4 + 18647219790*q^5 + O(q^6), q^2 + 432*q^3 + 39960*q^4 - 1418560*q^5 + O(q^6) ] sage: victor_miller_basis(40,200)[1:] == victor_miller_basis(40,200,cusp_only=True) True sage: victor_miller_basis(200,40)[1:] == victor_miller_basis(200,40,cusp_only=True) True AUTHORS: - William Stein, Craig Citro: original code - Martin Raum (2009-08-02): use FLINT for polynomial arithmetic (instead of NTL) """ k = Integer(k) if k % 2 == 1 or k == 2: return Sequence([]) elif k < 0: raise ValueError, "k must be non-negative" elif k == 0: return Sequence([PowerSeriesRing(ZZ, var)(1).add_bigoh(prec)], cr=True) e = k.mod(12) if e == 2: e += 12 n = (k - e) // 12 if n == 0 and cusp_only: return Sequence([]) # If prec is less than or equal to the dimension of the space of # cusp forms, which is just n, then we know the answer, and we # simply return it. if prec <= n: q = PowerSeriesRing(ZZ, var).gen(0) err = bigO(q**prec) ls = [0] * (n + 1) if not cusp_only: ls[0] = 1 + err for i in range(1, prec): ls[i] = q**i + err for i in range(prec, n + 1): ls[i] = err return Sequence(ls, cr=True) F6 = eisenstein_series_poly(6, prec) if e == 0: A = Fmpz_poly(1) elif e == 4: A = eisenstein_series_poly(4, prec) elif e == 6: A = F6 elif e == 8: A = eisenstein_series_poly(8, prec) elif e == 10: A = eisenstein_series_poly(10, prec) else: # e == 14 A = eisenstein_series_poly(14, prec) if A[0] == -1: A = -A if n == 0: return Sequence([PowerSeriesRing(ZZ, var)(A.list()).add_bigoh(prec)], cr=True) F6_squared = F6**2 F6_squared._unsafe_mutate_truncate(prec) D = _delta_poly(prec) Fprod = F6_squared Dprod = D if cusp_only: ls = [Fmpz_poly(0)] + [A] * n else: ls = [A] * (n + 1) for i in xrange(1, n + 1): ls[n - i] *= Fprod ls[i] *= Dprod ls[n - i]._unsafe_mutate_truncate(prec) ls[i]._unsafe_mutate_truncate(prec) Fprod *= F6_squared Dprod *= D Fprod._unsafe_mutate_truncate(prec) Dprod._unsafe_mutate_truncate(prec) P = PowerSeriesRing(ZZ, var) if cusp_only: for i in xrange(1, n + 1): for j in xrange(1, i): ls[j] = ls[j] - ls[j][i] * ls[i] return Sequence(map(lambda l: P(l.list()).add_bigoh(prec), ls[1:]), cr=True) else: for i in xrange(1, n + 1): for j in xrange(i): ls[j] = ls[j] - ls[j][i] * ls[i] return Sequence(map(lambda l: P(l.list()).add_bigoh(prec), ls), cr=True)