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?
 A: Let $F(x) = \frac{x^2}{P(x)}$ where
$$P(x) = x^6+2x^5-2x^4-4x^3+3x^2+4x+1 = (x^3+x^2-2x-1)^2 + (x^2+x)^2$$
Change variable to $u = \frac{1}{x+1} \iff x = \frac{1}{u}-1$. The integral at hand becomes
$$\int_{-\infty}^\infty F(x) dx 
= \left(\int_{-\infty}^{-1^{-}} + \int_{-1^{+}}^\infty\right) F(x) dx
= \left(\int_{0^{-}}^{-\infty} + \int_{+\infty}^{0^{+}}\right) F\left(\frac{1}{u} - 1\right)\left(-\frac{du}{u^2}\right)\\
= \int_{-\infty}^\infty \frac{1}{u^2} F\left(\frac{1}{u}-1\right) du
$$
By direct substitution, we have
$$\frac{1}{u^2}F\left(\frac{1}{u}-1\right)
= \frac{(u^2-u)^2}{u^6-2u^5-2u^4+4u^3+3u^2-4u+1}
= \frac{(u^2-u)^2}{(u^3-u^2-2u+1)^2+(u^2-u)^2}$$
Notice the function defined by
$$g(u) \stackrel{def}{=} \frac{u^3-u^2-2u+1}{u^2-u} = u - \frac{1}{u}-\frac{1}{u-1}$$
has the form where 
Glasser's Master Theorem applies, we get
$$\int_{-\infty}^\infty F(x) dx = \int_{-\infty}^\infty \frac{du}{g(u)^2 + 1}
= \int_{-\infty}^\infty \frac{dx}{x^2+1} = \pi
$$
NOTE
Please note that the statement about Glasser's Master theorem in above link is slightly off. The coefficient $|\alpha|$ in front of $x$ there need to be $1$. Otherwise, there will be an extra scaling factor on RHS of the identity. When in doubt, please consult the original paper by Glasser, 

Glasser, M. L. "A Remarkable Property of Definite Integrals." Math. Comput. 40, 561-563, 1983. 

and an online copy of that paper can be found here.
A: 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}$$

