Path: blob/master/sage/modular/modsym/hecke_operator.py
4056 views
##########################################################################1#2# Copyright (C) 2008 William Stein <[email protected]>3#4# Distributed under the terms of the GNU General Public License (GPL)5#6# http://www.gnu.org/licenses/7#8##########################################################################91011import sage.modular.hecke.hecke_operator12from sage.rings.arith import is_prime13import heilbronn1415class HeckeOperator(sage.modular.hecke.hecke_operator.HeckeOperator):16def apply_sparse(self, x):17"""18Return the image of x under self. If x is not in self.domain(),19raise a TypeError.2021EXAMPLES:22sage: M = ModularSymbols(17,4,-1)23sage: T = M.hecke_operator(4)24sage: T.apply_sparse(M.0)2564*[X^2,(1,8)] + 24*[X^2,(1,10)] - 9*[X^2,(1,13)] + 37*[X^2,(1,16)]26sage: [ T.apply_sparse(x) == T.hecke_module_morphism()(x) for x in M.basis() ]27[True, True, True, True]28sage: N = ModularSymbols(17,4,1)29sage: T.apply_sparse(N.0)30Traceback (most recent call last):31...32TypeError: x (=[X^2,(0,1)]) must be in Modular Symbols space of dimension 4 for Gamma_0(17) of weight 4 with sign -1 over Rational Field33"""34if x not in self.domain():35raise TypeError, "x (=%s) must be in %s"%(x, self.domain())3637# old version just to check for correctness38#return self.hecke_module_morphism()(x)3940p = self.index()41if is_prime(p):42H = heilbronn.HeilbronnCremona(p)43else:44H = heilbronn.HeilbronnMerel(p)4546M = self.parent().module()47mod2term = M._mod2term48syms = M.manin_symbols()49K = M.base_ring()50R = M.manin_gens_to_basis()5152W = R.new_matrix(nrows=1, ncols = R.nrows())5354B = M.manin_basis()5556#from sage.all import cputime57#t = cputime()58v = x.element()59for i in v.nonzero_positions():60for h in H:61entries = syms.apply(B[i], h)62for k, w in entries:63f, s = mod2term[k]64if s:65W[0,f] += s*K(w)*v[i]6667#print 'sym', cputime(t)68#t = cputime()69ans = M( v.parent()((W * R).row(0)) )70#print 'mul', cputime(t)71#print 'density: ', len(W.nonzero_positions())/(W.nrows()*float(W.ncols()))7273return ans74757677