<s>[INST] Use real integral to calculate $\int_R \frac{x^2 \cos (\pi x)}{(x^2 + 1)(x^2 + 2)}dx$ Problem :
Evaluate $$\int_{-\infty}^{\infty} \frac{x^2 \cos (\pi x)}{(x^2 + 1)(x^2 + 2)}dx$$
Use only real integral.

What I did : 
$$\int_{-\infty}^{\infty} \frac{x^2 \cos (\pi x)}{(x^2 + 1)(x^2 + 2)}dx$$
$$=2\int_{0}^{\infty} \frac{x^2 \cos (\pi x)}{(x^2 + 1)(x^2 + 2)}dx$$
$$=2\int_{0}^{\infty} \left( \frac{2\cos(\pi x)}{x^2+2} - \frac{\cos (\pi x)}{x^2 + 1}\right) dx$$
Any easy way to calculate this? or idea like differentiate under the integral sign?
 [/INST] We can consider a more general function
$$I(t)=2\int_0^\infty\frac{x^2\cos(tx)}{(x^2+1)(x^2+2)}\,\mathrm dx$$
and take its Laplace transform,
$$\begin{align*}
\mathcal{L}\left\{I(t)\right\} &= 2s\int_0^\infty\frac{x^2}{(x^2+s^2)(x^2+1)(x^2+2)}\,\mathrm dx\\ 
 &= 2s\int_0^\infty\left( \frac{1}{(1-s^2)(x^2+1)}+\frac{2}{(s^2-2)(x^2+2)}-\frac{s^2}{(s^4-3s^2+2)(x^2+s^2)}\right )\,\mathrm dx\\ 
 &= \frac{\pi\sqrt{2}}{s+\sqrt{2}}-\frac{\pi}{s+1},\qquad\text{do a bunch of arctan integrals and simplify.}
\end{align*}$$
 
Now if we use the fact that $\mathcal{L}\left\{e^{-\alpha t}\right\}=\frac{1}{s+\alpha}$, we find
$$I(t)=\pi\sqrt{2}e^{-\sqrt{2}t}-\pi e^{-t}.$$
Plugging in $t=\pi$ gives you what you're looking for.
</s>