# SageMath code for working with modular form 297.2.g.a # Compute space of new eigenforms: from sage.modular.dirichlet import DirichletCharacter H = DirichletGroup(297, base_ring=CyclotomicField(6)) chi = DirichletCharacter(H, H._module([5, 3])) N = Newforms(chi, 2, names="a") # select newform: traces = [4] f = next(g for g in N if [g.coefficient(i+1).trace() for i in range(1)] == traces) # q-expansion: f.q_expansion() # note that sage often uses an isomorphic number field