Proving $\left(\sum_{n=-\infty}^\infty q^{n^2} \right)^2 = \sum_{n=-\infty}^\infty \frac{1}{\cos(n \pi \tau)}$

The so-called "two squares theorem" can be proven by establishing the following identity:

$$\left(\sum_{n=-\infty}^\infty e^{\pi i \tau n^2}\right)^2 = \sum_{n=-\infty}^\infty \frac{1}{\cos(n \pi \tau)}$$

where $\Im \tau>0$.

Stein and Shakarchi give a lengthy proof in their complex analysis book. The proof is quite complicated and the motivation is unclear. I would be interested in a more intuitive (or at least concise) proof of the above identity.


Solution 1:

Below is the shortest proof I know. I would say this proof is motivated insomuch that it is a corollary--albeit not immediate--of the Jacobi triple product.

We proceed a la Ramanujan. The proof is quite elementary, but the algebraic manipulations are a bit tedious. The key ingredient of the proof is the Jacobi triple product: $$\sum_{n \in \mathbb{Z}} q^{n^2} x^n = \prod_{n = 1}^\infty (1 - q^{2n})(1 + q^{2n - 1}x)(1 + q^{2n - 1}x^{-1}), \quad |q| < 1, \quad x \ne 0.$$ Replacing $q$ with $\sqrt{q}$ and letting $x = \sqrt{q}y$ leads to $$\sum_{n \in \mathbb Z} q^{n(n + 1)/2} y^n = \frac{y + 1}{y}\prod_{n = 1}^\infty (1 - q^n)(1 + q^n y)(1 + q^n y^{-1}).$$ Now put $y = -z^2$ so that \begin{align*} \sum_{n \in \mathbb Z} (-1)^n q^{n(n + 1)/2} z^{2n + 1} &= \sum_{n \in \mathbb Z} q^{2n^2 + n} z^{4n + 1} - \sum_{n \in \mathbb Z} q^{2n^2 - n} z^{4n - 1}\\ &= (z - z^{-1})\prod_{n = 1}^\infty (1 - q^n)(1 - q^n z^2)(1 - q^n z^{-2}). \end{align*} Using the Jacobi triple product we can express the sums on the left-hand side as infinite products: \begin{align*} &z\prod_{n = 1}^\infty (1 - q^{4n})(1 + q^{4n - 1} z^4)(1 + q^{4n - 3} z^{-4})\\ &\quad- z^{-1}\prod_{n = 1}^\infty (1 - q^{4n})(1 + q^{4n - 3} z^4)(1 + q^{4n - 1} z^{-4})\\ &= (z - z^{-1})\prod_{n = 1}^\infty (1 - q^n)(1 - q^n z^2)(1 - q^n z^{-2}). \end{align*} If we differentiate both sides logarithmically with respect to $z$ and then set $z = 1$ we get $$1 + 4\sum_{n = 1}^\infty (-1)^n \frac{q^{2n - 1}}{1 + q^{2n - 1}} = \frac{\prod_{n = 1}^\infty (1 - q^n)^3}{\prod_{n = 1}^\infty (1 - q^{4n})(1 + q^{4n - 1})(1 + q^{4n - 3})}.$$ Yet, $$\frac{\prod_{n = 1}^\infty (1 - q^n)^3}{\prod_{n = 1}^\infty (1 - q^{4n})(1 + q^{4n - 1})(1 + q^{4n - 3})} = \frac{\prod_{n = 1}^\infty (1 - q^n)^3}{\prod_{n = 1}^\infty (1 + q^n)(1 - q^{2n})} = \frac{\prod_{n = 1}^\infty (1 - q^n)^2}{\prod_{n = 1}^\infty (1 + q^n)^2} = \theta_4^2(q),$$ where the last equality follows from the Jacobi triple product (use $x = -1$) and Euler's identity: $$(1 + q)(1 + q^2)(1 + q^3)\cdots = \frac{1}{(1 - q)(1 - q^3)(1 - q^5)\cdots}.$$ To prove this identity write $$(1 + q)(1 + q^2)(1 + q^3)\cdots = \frac{(1 + q)(1 - q)(1 + q^2)(1 - q^2)(1 + q^3)(1 - q^3)\cdots}{(1 - q)(1 - q^2)(1 - q^3)\cdots}.$$ Evidently, all the terms of the form $(1 - q^{2n})$ cancel because $(1 + q)(1 - q) = (1 - q^2)$, $(1 + q^2)(1 - q^2) = (1 - q^4)$, etc.

Consequently, $$\theta_4^2(q) = 1 + 4\sum_{n = 1}^\infty (-1)^n \frac{q^{2n - 1}}{1 + q^{2n - 1}},$$ which is equivalent to $$\theta_3^2(q) = 1 + 4\sum_{n = 0}^\infty (-1)^n \frac{q^{2n + 1}}{1 - q^{2n + 1}}$$ as $\theta_4(-q) = \theta_3(q)$. However, $$\sum_{n = 0}^\infty (-1)^n \frac{q^{2n + 1}}{1 - q^{2n + 1}} = \sum_{n = 1}^\infty \frac{q^n}{1 + q^{2n}}$$ because \begin{align*} &(q + q^2 + q^3 + \cdots) - (q^3 + q^6 + q^9 + \cdots) + (q^5 + q^{10} + q^{15} + \cdots) - \cdots\\ &\quad= (q + q^2 + q^3 + \cdots) - (q^3 + q^6 + q^9 + \cdots) + (q^5 + q^{10} + q^{15} + \cdots) - \cdots\\ &\qquad+ (q^3 + q^7 + q^{11} + \cdots) - (q^3 + q^7 + q^{11} + \cdots)\\ &\quad\qquad= q(1 - q^2 + q^4 - \cdots) + q^2(1 - q^4 + q^8 - \cdots) + q^3(1 - q^6 + q^{12} - \cdots) + \cdots \end{align*} Thus $$\theta_3^2(q) = 1 + 4\sum_{n = 1}^\infty \frac{q^n}{1 + q^{2n}} = 1 + 4\sum_{n = 1}^\infty \frac{1}{q^n + q^{-n}} = 2\sum_{n \in \mathbb{Z}} \frac{1}{q^n + q^{-n}} = \sum_{n \in \mathbb{Z}} \frac{1}{\cos(n \pi \tau)}$$ for it is clear that $q^n + q^{-n} = e^{n\pi i \tau} + e^{-n\pi i \tau} = 2\cos(n\pi \tau).$