<s>[INST] Integrate squared trigonometric function I'm trying to integrate $\int_a^b \left( \frac{1}{1+x^2}  \right)^2 dx$
I know that $\frac{d}{dx} \arctan(x) = \frac{1}{1+x^2}$, but how can I integrate with the squared part?
I've tried substitution with no success.
 [/INST] Let $x = \tan\theta$ and make use of 
\begin{align}
1 + \tan^{2}\theta &= \frac{1}{\cos^{2}\theta} \\
dx &= \frac{d\theta}{\cos^2\theta} \\
\sin(\tan^{-1}\theta) &= \frac{x}{\sqrt{1+x^2}} \\
\cos(\tan^{-1}\theta) &= \frac{1}{\sqrt{1 + x^2}}
\end{align}
to obtain:
\begin{align}
I &= \int \frac{dx}{(1+x^2)^2} \\
&= \int \cos^{2}\theta \, d\theta \\
&= \frac{1}{2} \, \int (1 + \cos(2 \theta) ) \, d\theta \\
&= \frac{1}{2} \, \left( \theta + \frac{\sin(2 \theta)}{2} \right) = \frac{1}{2} \, ( \theta + \sin\theta \, \cos\theta ) \\
&= \frac{1}{2} \, \left( \tan^{-1}x + \frac{x}{1+x^2} \right).
\end{align}
Now evaluate the integral with endpoints $a$ and $b$. If the range was $(0,1)$ then
$$\int_{0}^{1} \frac{dx}{(1+x^2)^2} = \frac{\pi + 2}{8}.$$
</s>