<s>[INST] Calculate $\int_{-\infty}^{\infty}\;\left( \frac{x^2}{1+4x+3x^2-4x^3-2x^4+2x^5+x^6}\right) \;dx$ 
Calculate $$\displaystyle \int_{-\infty}^{\infty}\;\left(
\frac{x^{2}}{1+4x+3x^{2}-4x^{3}-2x^{4}+2x^{5}+x^{6}}\right) \;dx$$

The answer given is $\pi$. How does one calculate this?
 [/INST] There is an inner structure that enable this integral to be evaluated into such nice form.

Let $$f(x) = 1+4x+3x^2-4x^3-2x^4+2x^5+x^6$$ The first miracle is: $f(x)$ factorizes nicely in $\mathbb{Q}[i]$:
$$f(x) = \underbrace{\left(x^3+(1-i) x^2-(2+i) x-1\right)}_{g(x)} \underbrace{\left(x^3+(1+i) x^2-(2-i) x-1\right)}_{h(x)}$$

The second miracle is: the root of $g(x)$ all lie in the same half plane. In this case, all roots of $g$ are in the upper plane. Denote them by $\alpha_1, \alpha_2, \alpha_3$, by contour integration $$I:=\int_{-\infty}^\infty \frac{x^2}{f(x)}dx = 2\pi i\left[ {\frac{{{\alpha _1}^2}}{{g'({\alpha _1})h({\alpha _1})}} + \frac{{{\alpha _2}^2}}{{g'({\alpha _2})h({\alpha _2})}} + \frac{{{\alpha _3}^2}}{{g'({\alpha _3})h({\alpha _3})}}} \right]$$
Now the right hand side is symmetric in $\alpha_i$, which are roots of $g$. Since $g,h\in \mathbb{Q}[i][x]$, we have
$$\frac{I}{\pi} \in \mathbb{Q}$$
This explain the nice result of the integral. Note that the numerator $x^2$ can be replaced by any polynomial in $\mathbb{Q}[x]$, $I/\pi$ is still rational.

Using similar construction, we obtain the analogous integrals:

Let $$f(x) = 4 + 8x - 11{x^2} - 18{x^3} + 13{x^4} + 8{x^5} + {x^6}$$ then $f$ satisfies the above two "mircales" so we have 
  $$\int_{ - \infty }^\infty  {\frac{1}{{f(x)}}dx}  = \frac{{5\pi }}{6} \qquad \int_{ - \infty }^\infty  {\frac{x}{{f(x)}}dx}  =  - \frac{\pi }{3} \qquad \int_{ - \infty }^\infty  {\frac{{{x^2}}}{{f(x)}}dx}  = \frac{\pi }{3}$$

Another example with

$$f(x) = 4 + 12x - 6{x^2} - 26{x^3} + 11{x^4} + 8{x^5} + {x^6}$$
$$\int_{ - \infty }^\infty  {\frac{1}{{f(x)}}dx}  = \frac{{3\pi }}{4} \qquad \int_{ - \infty }^\infty  {\frac{x}{{f(x)}}dx}  =  - \frac{\pi }{4} \qquad \int_{ - \infty }^\infty  {\frac{{{x^2}}}{{f(x)}}dx}  = \frac{\pi }{4}$$

An octic example:

$$f(x) = 13 + 12 x + 7 x^4 + 2 x^5 - 3 x^6 + x^8$$
$$\int_{ - \infty }^\infty  {\frac{1}{{f(x)}}dx}  = \frac{{487\pi }}{4148} \qquad \int_{ - \infty }^\infty  {\frac{x}{{f(x)}}dx}  =  - \frac{325\pi }{4148} \qquad \int_{ - \infty }^\infty  {\frac{{{x^2}}}{{f(x)}}dx}  = \frac{515\pi }{4148}$$

</s>