TITLE: Ramanujan's transformation formula connected with $r_{2}(n)$
QUESTION [11 upvotes]: Let $r_{2}(n)$ denote the number of ways in which a positive integer $n$ can be expressed as the sum of squares of two integers. Here the sign as well as order of summands matters. Also by convention we set $r_{2}(0) = 1$. Bruce C. Berndt and George E. Andrews mention the following surprising result of Ramanujan related to $r_{2}(n)$ in their book "Ramanujan's Lost Notebook Vol 4" (page 10): $$\sum_{n = 0}^{\infty}\frac{r_{2}(n)}{\sqrt{n + a}}e^{-2\pi\sqrt{(n + a)b}} = \sum_{n = 0}^{\infty}\frac{r_{2}(n)}{\sqrt{n + b}}e^{-2\pi\sqrt{(n + b)a}}\tag{1}$$ where $a, b$ are positive real numbers.
It is further mentioned that this formula was referred in a paper ("On the expression of a number as the sum of two squares", Quart. J. Math. (Oxford)46(1915), 263–283.) by G. H. Hardy and was not seen anywhere in any of Ramanujan's published/unpublished work. 
Like Ramanujan Berndt / Andrews also don't provide the proof in their book. The only detail I know about $r_{2}(n)$ is its generating function $$\sum_{n = 0}^{\infty}r_{2}(n)q^{n} = \vartheta_{3}^{2}(q) = \left(\sum_{n = -\infty}^{\infty}q^{n^{2}}\right)^{2} = 1 + 4\sum_{n = 1}^{\infty}\frac{q^{n}}{1 + q^{2n}}\tag{2}$$ (see this post) from which it is possible to find a direct formula for $r_{2}(n)$ based on count of divisors of $n$ of type $(4m + 1)$ and of type $(4m + 3)$. On the other hand the formula $(1)$ seems to based on some formula related to the sum $$\sum r_{2}(n)e^{-2\pi\sqrt{(n + a)b}}$$ and then taking its derivative with respect to $a$ to get $$-b\pi\sum \frac{r_{2}(n)}{\sqrt{(n + a)b}}e^{-2\pi\sqrt{(n + a)b}}$$ But when I try to integrate RHS of $(1)$ with respect to $a$ it leads to nowhere. My guess is that it is difficult to obtain $(1)$ as a derivative of some simpler identity.
Any proof of the formula $(1)$ or any reference containing a proof of $(1)$ is desired.

REPLY [19 votes]: We have the identity $$\sum_{n\geq0}\frac{r_{2}\left(n\right)}{\sqrt{n+a}}e^{-2\pi\sqrt{\left(n+a\right)b}}=\frac{1}{\sqrt{\pi}}\sum_{n\geq0}r_{2}\left(n\right)\int_{0}^{\infty}e^{-\left(n+a\right)x-\pi^{2}b/x}\frac{dx}{\sqrt{x}}. \tag{1}$$ In fact $$\int_{0}^{\infty}e^{-\left(n+a\right)x-\pi^{2}b/x}\frac{dx}{\sqrt{x}}=e^{-2\pi\sqrt{\left(n+a\right)b}}\int_{0}^{\infty}e^{-\left(\sqrt{\left(n+a\right)x}-\pi\sqrt{b/x}\right)^{2}}\frac{dx}{\sqrt{x}}
 $$ $$\overset{x=\frac{u}{n+a}}{=}\frac{e^{-2\pi\sqrt{\left(n+a\right)b}}}{\sqrt{n+a}}\int_{0}^{\infty}e^{-\left(\sqrt{u}-\pi\sqrt{b\left(n+a\right)/u}\right)^{2}}\frac{du}{\sqrt{u}}\overset{v=\sqrt{u}}{=}\frac{e^{-2\pi\sqrt{\left(n+a\right)b}}}{\sqrt{n+a}}\int_{-\infty}^{\infty}e^{-\left(v-\pi\sqrt{b\left(n+a\right)}/v\right)^{2}}dv $$ and we recall that if $f $ is an integrable function and $k>0 $, holds (see proof) $$\int_{-\infty}^{\infty}f\left(x-\frac{k}{x}\right)dx=\int_{-\infty}^{\infty}f\left(x\right)dx
 $$ hence $$=\frac{e^{-2\pi\sqrt{\left(n+a\right)b}}}{\sqrt{n+a}}\int_{-\infty}^{\infty}e^{-v^{2}}dv=\frac{e^{-2\pi\sqrt{\left(n+a\right)b}}}{\sqrt{n+a}}\cdot\sqrt{\pi} $$ so we can write $(1)$ as $$=\frac{1}{\sqrt{\pi}}\int_{0}^{\infty}e^{-ax-\pi^{2}b/x}\left(\sum_{n\geq0}r_{2}\left(n\right)e^{-nx}\right)\frac{dx}{\sqrt{x}}=\frac{1}{\sqrt{\pi}}\int_{0}^{\infty}e^{-ax-\pi^{2}b/x}\theta^{2}\left(x\right)\frac{dx}{\sqrt{x}}
 $$ where $\theta\left(x\right)=1+2e^{-x}+2e^{-4\pi x}+\dots
 $ and, recalling the functional identity $$\theta\left(x\right)=\sqrt{\frac{\pi}{x}}\theta\left(\frac{\pi^{2}}{x}\right)
 $$ we have $$=\sqrt{\pi}\int_{0}^{\infty}e^{-ax-\pi^{2}b/x}\theta^{2}\left(\frac{\pi^{2}}{x}\right)\frac{dx}{x\sqrt{x}}=\sqrt{\pi}\sum_{n\geq0}r_{2}\left(n\right)\int_{0}^{\infty}e^{-ax-\pi^{2}\left(b+n\right)/x}\frac{dx}{x\sqrt{x}}=
 $$ $$=\sqrt{\pi}\sum_{n\geq0}r_{2}\left(n\right)e^{-2\pi\sqrt{\left(n+b\right)a}}\int_{0}^{\infty}e^{-\left(\sqrt{ax}-\pi\sqrt{\left(n+b\right)/x}\right)^{2}}\frac{dx}{x\sqrt{x}}
 $$ $$\overset{w=\frac{n+b}{x}}{=}\sqrt{\pi}\sum_{n\geq0}r_{2}\left(n\right)\frac{e^{-2\pi\sqrt{\left(n+b\right)a}}}{\sqrt{n+b}}\int_{0}^{\infty}e^{-\left(\sqrt{a\left(n+b\right)/w}-\pi\sqrt{w}\right)^{2}}\frac{dw}{\sqrt{w}}$$ $$=\sum_{n\geq0}r_{2}\left(n\right)\frac{e^{-2\pi\sqrt{\left(n+b\right)a}}}{\sqrt{n+b}}.
 $$