# How to do arithmetic with a basis element from modular forms space

Hi, I'm new to Sage and coding in general. I want to look at the 1-dim'l space CuspForms(Gamma0(7), 3) but with character. Here's my code for that

S = G = DirichletGroup(7, QQ)
list(G)
G.gens()
e = G.0
S = CuspForms(e, 3, prec=20)
print(S)
print(Gamma0(7).cusps())
print(S.basis())
g = S.0


Here, g is the only basis element for S. I want to do F = g*(L+4) where L is some eta-quotient of level 7. However, I get a long error with 'NoneType' object is not iterable at the end. So I'm thinking I need to define g in a different way, since it seems to be that g is not a q-series type object the way I've defined it?

edit retag close merge delete

It would be helpful to have the complete code you used to produce L as well...

Yes, sorry. It's L = EtaProduct(7, {1:4, 7:-4}). I also mixed up the level on accident but edited to fix. It's 7.

Sort by » oldest newest most voted You can get the associated formal power series as follows:

sage: g
q - 3*q^2 + 5*q^4 - 7*q^7 - 3*q^8 + 9*q^9 - 6*q^11 + 21*q^14 - 11*q^16 - 27*q^18 + O(q^20)
sage: parent(g)
Cuspidal subspace of dimension 1 of Modular Forms space of dimension 3, character [-1] and weight 3 over Rational Field
sage: g.q_expansion()
q - 3*q^2 + 5*q^4 - 7*q^7 - 3*q^8 + 9*q^9 - 6*q^11 + 21*q^14 - 11*q^16 - 27*q^18 + O(q^20)
sage: parent(_)
Power Series Ring in q over Rational Field

more

Yes, but if I try something like g*L.q_expansion() or g*L.qexp(20) or things like that I get that error.

1

It worked!!! So when I do print(g.q_expansion()*L.q_expansion) something goes wrong, but leaving out "print" seems to fix this... weird.

The answer of FrédéricC is already wonderful, here is maybe a way to make your own way in the next similar situation. First of all, let us consider the code:

G = DirichletGroup(7, QQ)
S = CuspForms(e, 3, prec=20)
g = S.gens()
print( f"g = {g}" )
R = g.qexp().parent()
print( f"R = {R}\nIts default precision is {R.default_prec()}" )
q = R.gen()

L = EtaProduct(7, {1:4, 7:-4})
print( f"L = {L}" )


The above gives

g = q - 3*q^2 + 5*q^4 - 7*q^7 - 3*q^8 + 9*q^9 - 6*q^11 + 21*q^14 - 11*q^16 - 27*q^18 + O(q^20)
R = Power Series Ring in q over Rational Field
Its default precision is 20
L = Eta product of level 7 : (eta_1)^4 (eta_7)^-4


Now i noted that the method L.qexp needs an argument. At least for me in my version. This can be seen / asked in the ipython interpreter for sage as follows...

sage: L.qexp?
Signature:      L.qexp(n)
Docstring:
Alias for "self.q_expansion()".

EXAMPLES:

sage: e = EtaProduct(36, {6:8, 3:-8})
sage: e.qexp(10)
q + 8*q^4 + 36*q^7 + O(q^10)
sage: e.qexp(30) == e.q_expansion(30)
True
Init docstring: Initialize self.  See help(type(self)) for accurate signature.
File:           /usr/lib/python3.8/site-packages/sage/modular/etaproducts.py
Type:           method
sage:


and the above L.qexp goes to the doc string of the method qexp in the class L is an instance for:

sage: L.__class__
<class 'sage.modular.etaproducts.EtaGroupElement'>


So we really need an argument for it in my version.

sage: version()
'SageMath version 9.0, Release Date: 2020-01-01'


In my case L.qexp() produces an error, since one argument is needed, but this is easily corrected, L.exp(20) would be ok. Since the precision of the series for $g$ is $20$, we should use the same precision... Well:

sage: L.qexp(20)
q^-1 - 4 + 2*q + 8*q^2 - 5*q^3 - 4*q^4 - 10*q^5 + 12*q^6 - 7*q^7 + 8*q^8 + 46*q^9 - 36*q^10 - 26*q^11 - 44*q^12 + 46*q^13 - 28*q^14 + 42*q^15 + 188*q^16 - 132*q^17 - 96*q^18 + O(q^19)
sage: g.qexp()
q - 3*q^2 + 5*q^4 - 7*q^7 - 3*q^8 + 9*q^9 - 6*q^11 + 21*q^14 - 11*q^16 - 27*q^18 + O(q^20)


and the series are stopping at the "multiplicative precision" equal to $20$. For $L$ we have an expression modulo $O(q^{19})$ (since it starts with $1/q$), for $g$ we have an expression modulo $O(q^{20})$ . This situation may lead to losing the initial precision.

Now i tried:

• g + O(q^6), but it fails. (Although fL + O(q^6) works.)
• g * fL, but it fails. (Although g(q) * fL works.)

To make things work, replace g by g(q)...

So finally, the following code does the job for me. Framework:

PREC = 20
G = DirichletGroup(7, QQ)
S = CuspForms(e, 3, prec=PREC)
g = S.gens()
R = g.qexp().parent()
q = R.gen()

L = EtaProduct(7, {1:4, 7:-4})
fL = L.qexp(PREC)

g(q) * (fL + 4)(q) + O(q^6)


(Addition, multiplication, and truncation work.) Final result:

1 - 3*q + 2*q^2 + 7*q^3 - 29*q^4 + 21*q^5 + O(q^6)

more