<s>[INST] Regarding Leibniz formula for $\pi/4$ proof and its convergence \begin{align}
\frac{\pi}{4} & = \arctan(1)\;=\;\int_0^1 \frac 1{1+x^2} \, dx \\[8pt]
& = \int_0^1\left(\sum_{k=0}^n (-1)^k x^{2k}+\frac{(-1)^{n+1}\,x^{2n+2} }{1+x^2}\right) \, dx \\[8pt]
& = \sum_{k=0}^n \frac{(-1)^k}{2k+1}
+(-1)^{n+1}\int_0^1\frac{x^{2n+2}}{1+x^2} \, dx.
\end{align}
After this integration, $\frac{\pi}4\;=\;\sum_{k=0}^\infty\frac{(-1)^k}{2k+1}$
1.
I have trouble understanding why 
$\int_0^1 \frac 1{1+x^2} dx  = \int_0^1\left(\sum_{k=0}^n (-1)^k x^{2k}+\frac{(-1)^{n+1}\,x^{2n+2} }{1+x^2}\right) dx$
2.
How to compare the convergence of 
$\sum_{k=0}^\infty\frac{(-1)^k}{2k+1}$ and 
$\int_0^1\left(\sum_{k=0}^n (-1)^k x^{2k}+\frac{(-1)^{n+1}\,x^{2n+2} }
{1+x^2}\right) dx$?
Which one converge faster and do not have the same range of convergence?
 [/INST] Using long division, the integrand $\frac{1}{1+x^2}$ can be written
$$\begin{align}
\frac{1}{1+x^2}&=1-x^2+x^4-x^6+\cdots +(-1)^nx^{2n}+\frac{(-1)^{n+1}x^{2n+2}}{1+x^2}\\\\
&=\sum_{k=0}^n (-1)^kx^{2k}+\frac{(-1)^{n+1}x^{2n+2}}{1+x^2}
\end{align}$$
Thus, the integral of interest is 
$$\begin{align}
\int_0^1\frac{1}{1+x^2}\,dx&=\int_0^1\left(\sum_{k=0}^n (-1)^kx^{2k}+\frac{(-1)^{n+1}x^{2n+2}}{1+x^2}\right)\,dx\\\\
&=\sum_{k=0}^n (-1)^k\int_0^1x^{2k}\,dx+(-1)^{n+1}\int_0^1\frac{x^{2n+2}}{1+x^2}\,dx\\\\
&=\sum_{k=0}^n\frac{(-1)^k}{2k+1}+(-1)^{n+1}\int_0^1\frac{x^{2n+2}}{1+x^2}\,dx
\end{align}$$
Since $\left|\frac{x^{2n+2}}{1+x^2}\right| \le\frac{1}{1+x^2}$ and $\int_0^1\frac{1}{1+x^2}\,dx$ converges, the Dominated Convergence Theorem guarantees that 
$$\begin{align}
\lim_{n\to \infty}\int_0^1\frac{x^{2n+2}}{1+x^2}\,dx&=\int_0^1\lim_{n\to \infty}\left(\frac{x^{2n+2}}{1+x^2}\right)\,dx\\\\
&=0
\end{align}$$
Therefore, we have
$$\int_0^1\frac{1}{1+x^2}\,dx=\sum_{k=0}^{\infty}\frac{(-1)^{k}}{2k+1}=\pi/4$$
and we are done!
</s>