<s>[INST] How to take $\int_0^{+\infty} \frac{x^2+1}{x^4+1}dx$? The integral:
$$\int_0^{+\infty} \frac{x^2+1}{x^4+1}dx$$
If num were greater than denum I would just devide it normally with long division, but it is not, how should I handle it then?
 [/INST] Whenever I see an integrand that is sort of symmetric under $x \to x^{-1}$,
I will try to see whether I can express the intergrand in terms of $x \pm x^{-1}$.
Using following identities, 
$$\frac{dx}{x} = \frac{d(x-x^{-1})}{x+x^{-1}} = \frac{d(x+x^{-1})}{x-x^{-1}}$$
we find
$$\begin{align}
\int_0^\infty \frac{x^2+1}{x^4+1}dx 
&= \int_0^\infty \frac{x+x^{-1}}{x^2+x^{-2}} \frac{dx}{x} = \int_0^\infty \frac{x+x^{-1}}{x^2+x^{-2}} \frac{d(x-x^{-1})}{x+x^{-1}} = \int_0^\infty \frac{d(x-x^{-1})}{(x-x^{-1})^2+2}\\
&= \int_{-\infty}^\infty \frac{dy}{y^2+2} = \left[\frac{1}{\sqrt{2}}\tan^{-1}\frac{y}{\sqrt{2}}\right]_{-\infty}^\infty 
= \frac{\pi}{\sqrt{2}}
\end{align}
$$
</s>