Sorry for this question, but how to compute
$$\sum_{\gamma \in \text{SL}(2,\mathbb Z), \|\gamma\|<1000}\frac{1}{\|\gamma \|^4}$$
in Sagemath? Here the norm is just Frobebius norm (square root of the sum of squares of entries)
I tried something like
from sage.all import *
G = SL(2,ZZ)
s = 0
for r in G:
if r.norm() < 10:
s += 1/r.norm()^4
s
but there is an error and I couldn't figure out how to use SL(2,ZZ) properly.
To save the computational effort, I changed the range from 1000 to 10.
I don't know Sagemath syntax, but G is an infinite group. So your
forloop is asking to loop over infinitely many things. That's an abstract reason why that approach won't work, syntax aside.You know that all four entries of a matrix that contributes to the sum will be in $\left\{-1000,\cdots,1000\right\}$ . So it's not efficient, but you could sum over $(a,b,c,d)\in\left\{-1000,\cdots,1000\right\}^4$ and only add the $\frac{1}{\sqrt{a^2+b^2+c^2+d^2}}$ contribution when $ ad-bc=1$.
You could improve efficiency by summing like this:
$$\sum_{a=-1000}^{1000}\sum_{b=-\sqrt{1000^2-a^2}}^{\sqrt{1000^2-a^2}}\sum_{c=-\sqrt{1000^2-a^2-b^2}}^{\sqrt{1000^2-a^2-b^2}}\sum_{d=-\sqrt{1000^2-a^2-b^2-c^2}}^{\sqrt{1000^2-a^2-b^2-c^2}}$$
And more by not looking over all those $d$-values. Instead, check if $\frac{1+bc}{a}$ is an integer. If so, that is the only value of $d$ to use. And in that case do include the contribution to the overall sum. (Of course you have to handle the $a=0$ tuples separately.)