Why is $\lim_{x\to 1}\sqrt{1-x}\sum_{n=0}^\infty x^{n^2}=\sqrt{\pi}/2\,\,$?

What about squaring? We have $$ \left(\sum_{n\geq 0}x^{n^2}\right)^{2} = \sum_{n\geq 0}r_2(n)\,x^n $$ where $$ r_2(n) = \left|\left\{(a,b)\in\mathbb{N}^2: a^2+b^2 = n\right\}\right| $$ is a nice arithmetic function. For instance, $\sum_{n=0}^{N}r_2(n)$ is the number of lattice points with non-negative coordinates inside the circle $x^2+y^2=N$, but also the coefficient of $x^N$ in $$ \frac{1}{1-x}\left(\sum_{n\geq 0}x^{n^2}\right)^{2} = \sum_{N\geq 0}\left(\sum_{n=0}^{N}r_2(n)\right) x^N. $$ By Gauss circle problem with Voronoi bound we have that $\sum_{n=0}^{N}r_2(n)=\frac{\pi N}{4}+O(N^{1/3})$, hence $x=1$ is a double pole of the previous function and the first term of its Laurent expansion around $x=1$ is given by $\frac{\pi}{4(1-x)^2}$. By multiplying by $(1-x)^2$ and taking the limit as $x\to 1^-$ we get: $$ \lim_{x\to 1^-}\,(1-x)\left(\sum_{n\geq 0}x^{n^2}\right)^2 = \frac{\pi}{4} $$ and the claim easily follows.
It is interesting to point out that the same approach shows that, for any $k\geq 2$, $$ \lim_{x\to 1^-}(1-x)\left(\sum_{n\geq 0}x^{n^k}\right)^k $$ is exactly the (hyper-)volume enclosed by $x_1\geq 0,x_2\geq 0,\ldots x_k\geq 0$ and $x_1^k+x_2^k+\ldots+x_k^k = 1$, that can be computed in the following way: if we assume that $X_1,\ldots,X_k$ are i.i.d. random variables with uniform distribution over $(0,1)$, the PDF of $X_i$ is supported on $(0,1)$ and given by $f(t)=\frac{1}{k} t^{1/k-1}$. To compute the previous volume, it is enough to compute the characteristic function of $X_i$, take its $k$-th power, consider the inverse Fourier transform and integrate it over $(0,1)$ to get the probability that $X_1^k+\ldots+X_k^k\leq 1.$


by the Mac-Laurin-Cauchy Test formula, ($S(x)=\sum_{n=0}^{\infty}e^{\log(x)n^2}$) we have for $x<1$ $$ \frac{\sqrt{\pi}}{2\sqrt{-\log(x)}}=\int_0^{\infty}e^{\log(x)n^2}dn\leq \\S(x)=\\ \leq 1+ \int_0^{\infty}e^{\log(x)n^2}dn=1+\frac{\sqrt{\pi}}{2\sqrt{-\log(x)}} $$

Expanding around $x=1_-$

$$ \frac{\sqrt{\pi}}{2\sqrt{1-x}} \leq S(x)\leq 1+\frac{\sqrt{\pi}}{2\sqrt{1-x}} $$

and therefore

$$ \lim_{x\rightarrow1_-}\sqrt{1-x}S(x)=\frac{\sqrt{\pi}}{2} $$


We can use also the Abel's summation formula. We have $$S\left(N\right)=\sum_{n=0}^{N}x^{n^{2}}=\left(N+1\right)x^{N^{2}}-2\log\left(x\right)\int_{0}^{N}\left\lfloor t+1\right\rfloor tx^{t^{2}}dt $$ where $\left\lfloor t\right\rfloor $ is the floor function. Since $t-1\leq\left\lfloor t\right\rfloor \leq t $ we have $$ \left(N+1\right)x^{N^{2}}-2\log\left(x\right)\int_{0}^{N}t^{2}x^{t^{2}}dt\leq S\left(N\right)\leq Nx^{N^{2}}-2\log\left(x\right)\int_{0}^{N}t^{2}x^{t^{2}}dt+1. $$ Now let us consider the integral. We have, integrating by parts, $$2\log\left(x\right)\int_{0}^{N}t^{2}x^{t^{2}}=x^{N^{2}}N-\int_{0}^{N}x^{t^{2}}dt=x^{N^{2}}N-\int_{0}^{N}e^{\log\left(x\right)t^{2}}dt $$ $$=x^{N^{2}}N-\frac{\sqrt{\pi}\textrm{erfi}\left(iN\sqrt{-\log\left(x\right)}\right)}{2i\sqrt{-\log\left(x\right)}}\rightarrow\frac{\sqrt{\pi}}{2\sqrt{-\log\left(x\right)}} $$ as $N\rightarrow\infty $, where $\textrm{erfi}\left(x\right) $ is the imaginary error function. So using the expansion of $\log$ at $x=1$ and the squeeze theorem we can conclude.