Transfer between integrals and infinite sums So I was watching a video on YouTube about how $$\sum_{i=1}^\infty \frac{\chi(i)}{i} = \frac{\pi}{4}$$ (note that $\chi(i) = 0$ for even numbers $i$, $1$ for $\text{mod}(i, 4) = 1$, and $-1$ for $\text{mod}(i,4) = 3$) and one of the proofs shown involved stating that $$\sum_{i=1}^\infty \frac{\chi(i)}{i} = \int_{0}^{1} \sum_{i=0}^{\infty}\chi(i+1)x^{i}dx\,.$$
My question is 1.) how is this done and 2.) how can this be replicated with different infinite sums. Thanks in advance!
 A: Note that, for all $i\geq 1$,
$$\frac{1}{i} = \int_0^1 x^{i-1} dx$$
(this is a "trick" worth knowing), and therefore
$$
\sum_{i=1}^\infty \frac{\chi(i)}{i} = 
\sum_{i=1}^\infty \chi(i)\int_0^1 x^{i-1} dx
= 
\int_0^1\sum_{i=1}^\infty \chi(i)x^{i-1} dx
= 
\int_0^1\sum_{k=0}^\infty \chi(k+1)x^{k} dx
$$
where the only part which would require justification is when we swap $\int_0^1$ and $\sum_{i=1}^\infty$: this is Tonelli-Fubini.
A: If you have a power series
$$f(x):=\sum_{k=0}^\infty\,a_kx^k$$
with radius of convergence $r\geq 1$ ($a_0,a_1,a_2,\ldots\in\mathbb{C}$), then $f_n|_{[0,1)}\to f|_{[0,1)}$ uniformly on compact sets as $n\to\infty$, where $$f_n(x):=\sum_{k=0}^n\,a_kx^k\text{ for each }x\in\mathbb{C}\text{ and }n\in\mathbb{Z}_{>0}\,.$$
This provides a justification for swapping the infinite sum and the integral, that is,
$$\int_0^1\,f(x)\,\text{d}x=\int_0^1\,\sum_{k=0}^\infty\,a_kx^k\,\text{d}x=\sum_{k=0}^\infty\,\int_0^1\,a_kx^k\,\text{d}x=\sum_{k=0}^\infty\,\frac{a_{k}}{k+1}\,.$$

In particular, the power series
$$g(x):=\sum_{k=0}^\infty\,\chi(k+1)\,x^k$$
has radius of convergence $\dfrac{1}{\limsup\limits_{k\to\infty}\,\sqrt[k]{\big|\chi(k+1)\big|}}=1$.  Therefore, you can swap the integral and the infinite sum to obtain
$$\int_0^1\,g(x)\,\text{d}x=\int_0^1\,\sum_{k=0}^\infty\,\chi(k+1)\,x^k\,\text{d}x=\sum_{k=0}^\infty\,\frac{\chi(k+1)}{k+1}=\sum_{k=1}^\infty\,\frac{\chi(k)}{k}\,.$$
Note that $x^4\,g(x)=g(x)-1+x^2$, so $$g(x)=\frac{1-x^2}{1-x^4}=\frac{1}{1+x^2}\text{ for all }x\in\mathbb{C}\text{ such that }|x|<1\,.$$
That is,
$$\sum_{k=1}^\infty\,\frac{\chi(k)}{k}=\int_0^1\,\frac{1}{1+x^2}\,\text{d}x=\arctan(x)\big|_{x=0}^{x=1}=\frac{\pi}{4}\,.$$

Alternatively, note that
$$\chi(k)=\frac{\text{i}^k-(-\text{i})^k}{2\text{i}}\text{ for each }k=0,1,2,\ldots\,,$$
where $\text{i}$ is the imaginary unit $\sqrt{-1}$.  From the Taylor series of the principal branch of the natural logarithm function $$\ln(1+z)=\sum_{k=1}^\infty\,\frac{(-1)^{k-1}}{k}\,z^k\,,$$ we note that the series above converges for $z=\pm \text{i}$, yielding
$$\frac{1}{2}\,\ln(2)+\text{i}\frac{\pi}{4}=\ln(1+\text{i})=-\sum_{k=1}^\infty\,\frac{(-\text{i})^k}{k}$$
and
$$\frac{1}{2}\,\ln(2)-\text{i}\frac{\pi}{4}=\ln(1-\text{i})=-\sum_{k=1}^\infty\,\frac{\text{i}^k}{k}\,.$$
Subtracting the two equations above and dividing the result by $2\text{i}$ yields
$$\frac{\pi}{4}=\sum_{k=1}^\infty\,\frac{\text{i}^k-(-\text{i})^k}{2\text{i}\,k}=\sum_{k=1}^\infty\,\frac{\chi(k)}{k}\,.$$
