Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is some example. Things are depending on the way the modular form is declared / constructed. Here i use the modular forms space constructor, ask for a basis, use its first element, get its $q$-series, then ask for the list of its coefficients.

sage: ModularForms?
sage: MF53_2 = ModularForms(Gamma0(53), 2 )
sage: f = MF53_2.basis()[0]
sage: f
q - 2/3*q^5 + O(q^6)
sage: f.q_expansion(20)
q - 2/3*q^5 - 1/3*q^6 + 1/3*q^7 - 2/3*q^8 + q^9 - q^10 - 1/3*q^11 - 2/3*q^12 + 1/3*q^13 - 5/3*q^15 - 5/3*q^16 - q^17 - 2*q^18 + 8/3*q^19 + O(q^20)
sage: list(f.q_expansion(20))
[0,
 1,
 0,
 0,
 0,
 -2/3,
 -1/3,
 1/3,
 -2/3,
 1,
 -1,
 -1/3,
 -2/3,
 1/3,
 0,
 -5/3,
 -5/3,
 -1,
 -2,
 8/3]

Note there is a "well-known" trap with this:

sage: fq = f.q_expansion(20)
sage: fq.coefficients()
[1, -2/3, -1/3, 1/3, -2/3, 1, -1, -1/3, -2/3, 1/3, -5/3, -5/3, -1, -2, 8/3]
sage: fq.coefficients?
Docstring:     
   Return the nonzero coefficients of self.

and the doc string continues. (I always fall into it, have no idea why such a function exists - at least i would expect an optional argument / flag that - when set - to insist in giving all coefficients, also the zero ones.)