How to evaluate sums in the form $\sum_{k=-\infty}^\infty e^{-\pi n k^2}$

The sums in question are nothing but values of Jacobi theta function defined by $$\vartheta_{3}(q)=\sum_{n\in\mathbb{Z}}q^{n^2}\tag{1}$$ Evaluation of these functions for certain specific values of $q$ is done via the help of their friends called elliptic integrals. Before discussing the problem of evaluation of theta functions, it is best to give preliminary information about elliptic integrals.

We start with a number $k\in(0,1)$ called elliptic modulus and define another number $k'=\sqrt{1-k^2}$ called complementary (to $k$) modulus. The following equation $$K(k) =\int_{0}^{\pi/2}\frac{dx}{\sqrt{1-k^2\sin^{2}x}}\tag{2}$$ defines complete elliptic integral of first kind $K(k) $ for modulus $k$. The expressions $K(k), K(k') $ are usually denoted by $K, K'$ respectively if $k$ is known from context. It is then a wonderful surprise that if the values $K, K'$ are known the value of modulus $k$ can be obtained via Jacobi theta functions with argument $q=e^{-\pi K'/K} $ (also called nome) $$k=\frac{\vartheta_{2}^{2}(q)}{\vartheta_{3}^{2}(q)},\,\vartheta_{2}(q)=\sum_{n\in\mathbb{Z}}q^{(n+(1/2))^2}\tag{3}$$ Also under these circumstances we have $$\vartheta_{3}^{2}(q)=\frac{2K}{\pi}\tag{4}$$ The most interesting aspect of these functions and integrals was understood by Ramanujan and he championed the idea of a modular equation to which we turn next.

The function $f(k) =K(k') /K(k) $ is strictly decreasing and maps interval $(0,1)$ to $(0,\infty)$ and hence if $p$ is a positive real number then there exists a unique number $l\in(0,1)$ such that $$\frac{K(l')} {K(l)} =p\frac{K(k')} {K(k)} \tag{5}$$ (here $l'=\sqrt{1-l^2}$ is complementary to $l$, also $K(l), K(l')$ are usually denoted by $L, L'$). Thus given $k\in(0,1),p\in(0,\infty)$ we have a new modulus $l$ such that the above equation holds and if $p$ is fixed in our discussion then $l$ is a function of $k$. Jacobi proved in his Fundamenta Nova that if $p$ is a positive rational number then the relationship between $k, l$ is algebraic and this relationship between $k, l$ in form of an algebraic equation is called a modular equation of degree $p$. It is a computational challenge to find such equations for large values of $p$ and Ramanujan was an expert in finding such modular equations.

Let $P(k, l) =0$ be the modular equation of degree $p$ where $P$ is a polynomial with rational coefficients. Ramanujan added another constraint in this equation namely $l=k'$ so that $k=l'$ then the equation $P(k, k') =0$ shows that both $k, l=k'$ are algebraic numbers. And in that case equation $(5)$ leads us to $$\frac{K(l')} {K(l)} =\sqrt{p}, \frac{K(k')} {K(k)} =\frac{1}{\sqrt{p}}\tag{6}$$ and thus we have the following theorem

Theorem: If $p$ is a positive rational number and $K(k') /K(k) =\sqrt{p} $ then $k$ is an algebraic number and such values of $k$ are called singular moduli.

From now on $p$ will denote a positive rational number unless otherwise stated. Note that if $Q=\exp(-\pi K(l') /K(l)) $ then equation $(5)$ shows that $Q=q^{p} $. From equation $(3)$ it follows that a modular equation can also be thought as an algebraic relation between theta functions of arguments $q$ and $q^{p} $. It can also be proved by differentiating the equation $(5)$ that the ratio $K(k) /K(l) $ can be expressed as an algebraic expression in $k, l$. Ramanujan expressed many of his modular equations as algebraic expressions for $K/L$ and that's what we need here.

We start with $q=e^{-\pi} $ so that $K=K', k=k'=1/\sqrt{2}$ and the value of integral $K$ is easily evaluated for this value of $k$ which gives the desired value of the first sum in question. From equation $(4)$ it follows that $$\frac{\vartheta_{3}(q)}{\vartheta_{3}(q^p)}=\sqrt{\frac{K}{L}}$$ And as discussed earlier the ratio $K/L$ can be expressed as an algebraic function of $k, l$ therefore the evaluation of $\vartheta_{3}(q^p)$ can be performed if the value of $l$ as well expression for $K/L$ in terms of $k, l$ is known. The value of $l$ can be obtained by solving the modular equation $P(k, l) =0$ as $k=1/\sqrt{2}$ is known.


To sum up we need the modular equation connecting $k, l$ as well as expression for $K/L$ in terms of $k, l$. These are well known and have a simple form if $p=2$ and are famously known as Landen transformation $$l=\frac{1-k'}{1+k'},\frac{K}{L}=\frac{2}{1+k'}\tag{6}$$ Thus putting $k'=1/\sqrt{2}$ we get $K/L=4/(2+\sqrt{2})$ and the second sum in question $$\vartheta_{3}(e^{-2\pi})=\sqrt{\frac{L}{K}}\vartheta_{3}(e^{-\pi})=\frac{\pi^{1/4}\sqrt{2+\sqrt{2}}}{2\Gamma(3/4)}$$ has the value as mentioned in your post.

For $p=3$ we have the following modular equation $$\sqrt{kl} +\sqrt{k'l'} =1\tag{7}$$ Putting $k=k'=2^{-1/2}$ we get $\sqrt{l} +\sqrt{l'} =2^{1/4}$. With some effort the value of $l$ can be obtained. To get the value of $K/L$ we differentiate equation $(5)$ and get $$\frac{dl} {dk} =p\frac{ll'^{2}L^{2}}{kk'^{2}K^{2}}$$ Thus $$\left(\frac{L} {K} \right) ^{2}=\frac{kk'^{2}}{3ll'^{2}}\frac{dl}{dk}\tag{8}$$ Differentiating equation $(7)$ with respect to $k$ we get $$\sqrt{\frac{l} {k}}+\sqrt{\frac{k} {l}} \frac{dl} {dk} - \frac{k}{k'} \sqrt{\frac{l'} {k'}} - \frac{l} {l'}\sqrt{\frac{k'}{l'}} \frac{dl} {dk} =0$$ ie $$\frac{dl}{dk} =\dfrac{\sqrt{\dfrac{l}{k}}-\dfrac{k}{k'}\sqrt{\dfrac{l'}{k'}}}{\dfrac{l}{l'}\sqrt{\dfrac{k'}{l'}}-\sqrt{\dfrac{k}{l}}}$$ and putting this value of $dl/dk$ in equation $(8)$ we get the value of $L^2/K^2$ in terms of $l, l'$ (the value $k=k'=2^{-1/2}$ being used in the process) as $$\left(\frac{L} {K} \right) ^{2}=\frac{1}{6\sqrt{ll'}}\cdot\frac{1}{l+l'+\sqrt{ll'}}\tag{9}$$ Since the values of $l, l'$ and their square roots are known we can get the value of ratio $L^2/K^2$ in form of a radical expression.

The algebraic calculations are formidable and I managed to get $$\sqrt{l} =\frac{\sqrt{2}-\sqrt[4]{3} (\sqrt{3}-1)} {2^{5/4}}, \sqrt{l'} =\frac{\sqrt{2}+\sqrt[4]{3} (\sqrt{3}-1)} {2^{5/4}}, \sqrt{ll'} =\frac{(\sqrt{3}-1)^{2}}{2\sqrt{2}}$$ and $$l=\frac{(\sqrt{3}-1)(\sqrt{2}-\sqrt[4]{3})}{2}, l'=\frac{(\sqrt{3}-1)(\sqrt{2}+\sqrt[4]{3})}{2}$$ Using these values in equation $(9)$ we can show that $$\left(\frac {L} {K} \right) ^{2}=\frac {3+2\sqrt{3}}{9} $$ and thus the desired value of the third sum is obtained.


For $p=5$ Ramanujan gives the modular equation $$\frac{5L}{K}=\frac{1+(\alpha^5/\beta)^{1/8}} {1+(\alpha\beta^3)^{1/8}}, \frac{K} {L} =\frac{1+((1-\beta)^5/(1-\alpha))^{1/8}}{1+((1-\alpha)^3(1-\beta))^{1/8}} $$ where $\alpha=k^2,\beta=l^2$. Using $$\alpha=\frac{1}{2},\beta=\frac {1}{2}-6\sqrt{161\sqrt{5}-360}=\frac{1-\sqrt{1-\phi^{-24}}}{2}$$ (value of $\beta$ is obtained using value of class invariant $G_{25}=(1+\sqrt {5})/2=\phi$) corresponding to nomes $e^{-\pi}, e^{-5\pi}$ we can get the value of $L/K$ in algebraic form. It is hard to believe, but this thread tell us that the final result has a very simple algebraic form given by $$\frac{L} {K} =\frac{\sqrt{5}+2}{5}$$ The algebra involved can be simplified a lot if we use a denesting by Ramanujan for $\beta^{1/8},(1-\beta)^{1/8}$ given here (see equation $(7)$).