<s>[INST] Finding $\int_{-\infty}^\infty \frac{x^2}{x^4+1}\;dx$ $$\int_{-\infty}^\infty \frac{x^2}{x^4+1}\;dx$$
I'm trying to understand trigonometric substitution better, because I never could get a good handle on it.  All I know is that this integral is supposed to reduce to the integral of some power of cosine.  I tried $x^2=\tan\theta$, but I ended up with $\sin\theta\cos^3\theta$ as my integrand.  Can someone explain how to compute this?
 [/INST] Notice $$\int_{-\infty}^\infty \frac{x^2}{x^4+1} dx
= 2 \int_0^\infty \frac{x^2}{x^4+1} dx
= 2 \int_0^\infty \frac{dx}{x^2+x^{-2}}
= 2 \int_0^\infty \frac{dx}{(x-x^{-1})^2+2}\\
= 2 \left(\color{red}{\int_0^1} + \color{blue}{\int_1^\infty}\right) \frac{dx}{(x-x^{-1})^2+2}
$$
Change variable from $x$ to $\frac1x$ for that part of integral on $(0,1)$, 
this becomes
$$2\int_1^\infty \frac{1}{(x-x^{-1})^2+2}(\color{blue}{1}+\color{red}{x^{-2}})dx
= 2\int_1^\infty \frac{d(x-x^{-1})}{(x-x^{-1})^2+2} $$
Change variable once more to $y = x-x^{-1}$ and then to $y = \sqrt{2}z$, we get
$$\int_{-\infty}^\infty \frac{x^2}{x^4+1} dx
= 2 \int_0^\infty \frac{dy}{y^2+2} 
= \int_{-\infty}^\infty \frac{dy}{y^2+2} 
= \frac{1}{\sqrt{2}}\int_{-\infty}^{\infty} \frac{dz}{1+z^2}
= \frac{\pi}{\sqrt{2}}$$
</s>