Why doesn't this proof of the Basel problem violate the geometric series convergence constraints? In a proof of the Basel problem, the excellent YouTuber "blackpenredpen" relies on a manipulation which I assume is valid, but I don't know why it is valid.
They split the following integral:
$$\int_0^{\pi/2}\ln(2\cos x)\space dx=\int_0^{\pi/2}\ln(e^{ix}+e^{-ix})\space dx=$$
$$\int_0^{\pi/2}\ln(e^{ix}(1+e^{-2ix}))\space dx=\int_0^{\pi/2}\ln(e^{ix})\space dx + \int_0^{\pi/2}\ln(1+e^{-2ix}))\space dx$$
And in the calculation of the second part of the integral on the right hand side, they use the series expansion:
$$\ln(1+x)=\sum_{n=1}^\infty(-1)^{n-1}\frac{x^n}{n}$$
to represent $\ln(1+e^{-2ix})$ and note that this is only valid for $|x|\leq1, x\neq-1$. Although $|e^{-2ix}|=1,\forall x$, I noticed that the integral runs up to $\frac{\pi}{2}$, and $e^{-2i\cdot\pi/2}=-1$, which means that the series expansion does not converge (the logarithm goes to $\ln(0)$ which is very undefined!) at the upper bound of the integral. I imagine this is valid due to integrals being limits, and perhaps we "approach" $\frac{\pi}{2}$ without reaching it, but I'd like a formal explanation for why this expansion is valid here - I would like to learn when we can and cannot do this sort of thing!
 A: For $\epsilon>0$, we wish to evaluate $\int_0^{\pi/2-\epsilon}\ln(1+e^{-2ix})dx$. Let $\delta>0$ be small, so that
\begin{align}
\int_0^{\pi/2-\epsilon}\ln(1+e^{-2ix})dx=\int_0^{\pi/2-\epsilon}\ln(1+(1-\delta)e^{-2ix})dx+\int_0^{\pi/2-\epsilon}\ln\left(\frac{1+e^{-2ix}}{1+(1-\delta)e^{-2ix}}\right)dx.
\end{align}
Here,
\begin{align}
\left|\ln\left(\frac{1+e^{-2ix}}{1+(1-\delta)e^{-2ix}}\right)\right|&=\left|\ln\left(1-\frac\delta{1+e^{2ix}}\right)\right|\\
&\le\frac32\frac\delta{|1+e^{2ix}|}\\
&=\frac32\frac\delta{\sqrt{(1+\cos(2x))^2+\sin^2(2x)}}\\
&=\frac32\frac\delta{\sqrt{2+2\cos(2x)}},\\
\end{align}
(here, I used this bound), so for $\delta$ small enough, the second term disappears, since $2+2\cos x\ge 2-2\cos(2\epsilon)>0$. Now, one can safely trade the limit and the integral because of uniform convergence:
\begin{align}
\int_0^{\pi/2-\epsilon}\ln(1+(1-\delta)e^{-2ix})dx&=\int_0^{\pi/2-\epsilon}\lim_{N\to\infty}\sum_{n=1}^N(-1)^{n-1}\frac1n(1-\delta)^ne^{-2nix}dx\\
&=\lim_{N\to\infty}\sum_{n=1}^N(-1)^{n-1}\frac1n(1-\delta)^n\int_0^{\pi/2-\epsilon}e^{-2nix}dx\\
&=\sum_{n=1}^\infty(-1)^{n-1}\frac1{2n^2i}(1-\delta)^n(1-(-1)^ne^{2ni\epsilon}).
\end{align}
Since $\epsilon,\delta>0$ were arbitrary, we can take the limit as they approach $0$.
