Indefinite integral through factorization

If you differentiate $\frac{Cx+D}{x^2+1}$, then you get the quatioent of a second degree polynomial with $(x^2+1)^2$. If you add to it $\frac{Ax+B}{x^2+1}$, then you get the quotient of a cubic polynomial by $(x^2+1)^2$. So, it is reasonable to expect that you can express $\frac1{(x^2+1)^2}$ as such an expression. On the other hand,$$\int\frac{Ax+B}{x^2+1}\,\mathrm dx=\frac A2\log(x^2+1)+B\arctan(x),$$and therefore this allows you to obtain$$\int\frac{\mathrm dx}{(x^2+1)^2}=\frac A2\log(x^2+1)+B\arctan(x)+\frac{Cs+D}{x^2+1}.$$


It is possible to shorten this magic as follows

\begin{eqnarray*} \int \frac{1}{(x^2+1)^2}dx & = & \int \frac{1+x^2 - x^2}{(x^2+1)^2}dx \\ & = & \int \frac{1}{x^2+1}dx - \frac{1}{2}\int x\frac{2x}{(x^2+1)^2}dx \\ & = & \arctan x - \frac{1}{2}\left(- \frac{x}{x^2+1} + \int \frac{1}{x^2+1}dx\right) \\ & = & \arctan x + \frac{1}{2}\frac{x}{x^2+1} - \frac{1}{2}\arctan x \;(+C) \\ & = & \frac{1}{2}\left(\arctan x + \frac{x}{x^2+1}\right) \;(+C) \\ \end{eqnarray*}