id	summary	reporter	owner	description	type	status	priority	milestone	component	resolution	keywords	cc	work_issues	upstream	reviewer	author	merged	dependencies	stopgaps
10510	ModularSymbols(Gamma1(29), 2).cuspidal_subspace().hecke_algebra().basis() doesn't terminate	mderickx	craigcitro	"It also doesn't terminate for other primes then 29, but here is a more detailed example of the case 29 which should illustrate everything

The sourcecode which determines the basis is currently:

{{{
def basis(self):
    try:
        return self.__basis_cache
    except AttributeError:
        pass
    level = self.level()
    bound = self.__M.hecke_bound()
    dim = self.__M.rank()
    if dim == 0:
        basis = []
    elif dim == 1:
        basis = [self.hecke_operator(1)]
    else:
        span = [self.hecke_operator(n) for n in range(1, bound+1) if not self.is_anemic() or gcd(n, level) == 1]
        rand_max = 5
        while True:
            # Project the full Hecke module to a random submodule to ease the HNF reduction.
            v = (ZZ**dim).random_element(x=rand_max)
            proj_span = matrix([T.matrix()*v for T in span])._clear_denom()[0]
            proj_basis = proj_span.hermite_form()
            if proj_basis[dim-1] == 0:
                # We got unlucky, choose another projection.
                rand_max *= 2
                continue
            # Lift the projected basis to a basis in the Hecke algebra.
            trans = proj_span.solve_left(proj_basis)
            basis = [sum(c*T for c,T in zip(row,span) if c != 0) for row in trans[:dim]]
            break

    self.__basis_cache = tuple(basis)
    return basis
}}}

Now dim equals 44 and the hecke bound 140 in this example:
{{{
sage: G29=Gamma1(29)
sage: M=ModularSymbols(G29,2)
sage: m=M.cuspidal_subspace()
sage: m.rank()
44
sage: m.hecke_bound()
140
}}}

Now we see that the hecke algebra has rank 22 over ZZ
{{{
sage: HA=m.hecke_algebra()
sage: span = [HA.hecke_operator(n) for n in range(1, 140+1) if not HA.is_anemic() or gcd(n, 29) == 1]
sage: (ZZ^(44^2)).span([i.matrix().list() for i in span])
Free module of degree 1936 and rank 22 over Integer Ring
Echelon basis matrix:
22 x 1936 dense matrix over Rational Field
}}}
So as the comment say's we are unlucky since proj_basis[43] will always be zero since the hecke algebra has only rank 22
{{{
            if proj_basis[dim-1] == 0:
                # We got unlucky, choose another projection.
                rand_max *= 2
                continue
}}}
I suspect there is a problem in that the rank of m is 44 over QQ. But that the rank of the hecke algebra will be the dimension of m as a complex vector space so dim should actually be half of what it is now.

I don't know enough of modular symbols yet to know how it should be done in other weights and other modular groups but I suspect there will be problems there also."	defect	new	major		modular forms					N/A		mderickx			
