ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 26 Nov 2018 12:44:38 +0100How does one get a list of Fourier coefficients from a q-series?https://ask.sagemath.org/question/44395/how-does-one-get-a-list-of-fourier-coefficients-from-a-q-series/ I'm new to working with SAGE, I need to check congruences with modular forms, this requires that I am able to construct a list of Fourier coefficients from the q series of a modular form, how does this work?Fri, 23 Nov 2018 18:42:30 +0100https://ask.sagemath.org/question/44395/how-does-one-get-a-list-of-fourier-coefficients-from-a-q-series/Answer by dan_fulea for <p>I'm new to working with SAGE, I need to check congruences with modular forms, this requires that I am able to construct a list of Fourier coefficients from the q series of a modular form, how does this work?</p>
https://ask.sagemath.org/question/44395/how-does-one-get-a-list-of-fourier-coefficients-from-a-q-series/?answer=44446#post-id-44446Here 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.)
Mon, 26 Nov 2018 12:44:38 +0100https://ask.sagemath.org/question/44395/how-does-one-get-a-list-of-fourier-coefficients-from-a-q-series/?answer=44446#post-id-44446