For two modular forms $f, g$ of weights $k_{1}, k_{2}$ respectively, the $n$-th Rankin-Cohen bracket of $f, g$ is given by $$[f, g]_{n} := \sum_{j=0}^{n} (-1)^{j}\binom{n+k_{1}-11}{j}\binom{n+k_{2}-1}{n-j}D^{n-j}(f)D^{j}(g),$$ where $D := q\frac{d}{dq}$ is the $q$-derivative.
I have SAGE code so far as:
MM = 300
def Binom(x, y):
return gamma(x+1)/(gamma(y+1)*gamma(x-y+1))
def D(f, r):
if r == 0:
return f
else:
return sum(n^(r)*f[n]*q^n for n in range(MM))
def Rankin_Cohen(n, f, g, k1, k2):
return sum((-1)^j*Binom(n+k1-1, j)*Binom(n+k2-1, n-j)*D(f, n-j)*D(g, j) for j in range(n+1))
Testing it with a couple of nice functions:
theta = 1 + 2*sum(q^(n^2) for n in range(1, MM))
def E4(k):
return -bernoulli(k)/2*k + sum(sum(d^(k-1) for d in divisors(n))*q^(4*n) for n in range(1, MM))
k = 12
for n in range(floor(k/6)):
R = Rankin_Cohen(n, theta, E4(k-2*n), 1/2, k-2*n)
print(R)
Finally, this is the error I receive from the second block:
TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and 'Power Series Ring in q over Rational Field'
I believe this is because I cannot iterate the $q$-series $D^{n-j}(f), D^{j}(g)$ in my definition for Rankin_Cohen. Is there a way to get around this??
Thanks to John Palmieri in the comments, the
binomialfunction did the trick.