<s>[INST] integral computation $\int_{-\infty}^{\infty} \frac{1}{(1+x+x^2)^2} dx $ Compute the following integral: 
$\int_{-\infty}^{\infty} \frac{1}{(1+x+x^2)^2} dx$. Can some one give me some hints on how to do this?
I tried writing $(1+x+x^2)=f(x)$ and then multiplying and dividing by $\frac{d f(x)}{dx}=1+2x$ so we get $\int_{-\infty}^{\infty} \frac{1}{1+2x} \frac{1+2x}{(f(x))^2} dx $ = $\int_{-\infty}^{\infty} \frac{1}{1+2x} \frac{df(x)}{(f(x))^2} $. Here I tried to use integration by parts but I can't get anywhere.
 [/INST] I assume you are not familiar with complex analysis techniques, so I will illustrate a partial fractions decomposition.  The denominator has zeroes when
$$x^2+x+1=0 \implies x=-\frac12 \pm i \frac{\sqrt{3}}{2} = e^{\pm i 2 \pi/3}$$
Thus
$$(x^2+x+1)^2 = (x-e^{i 2 \pi/3})^2 (x-e^{-i 2 \pi/3})^2$$
Let $w=e^{i 2 \pi/3}$.  Then
$$\frac1{(x^2+x+1)^2} = \frac{A}{x-w} + \frac{B}{(x-w)^2} + \frac{C}{x-\bar{w}} + \frac{D}{(x-\bar{w})^2}$$
This means that, when we compare numerators, we get that
$$A(x-w)(x-\bar{w})^2+B (x-\bar{w})^2 + C (x-\bar{w}) (x-w)^2 + D (x-w)^2 = 1$$
Equate coefficients of $x^k$:
$$(A+C) x^3 + [(-w-2 \bar{w}) A + B + (-\bar{w}-2 w) C +D] x^2 \\+ [(2 w \bar{w}+\bar{w}^2) A - 2 \bar{w} B +(2 w \bar{w} + w^2) C - 2 w D] x \\+ [- w \bar{w}^2 A + \bar{w}^2 B - \bar{w} w^2 C + w^2 D] = 1 $$
$$ \implies (A,B,C,D) = \left\{-\frac{2 i}{3 \sqrt{3}},-\frac{1}{3},\frac{2 i}{3
   \sqrt{3}},-\frac{1}{3}\right\}$$
Now, note that we do not even need to worry about the $B$ and $D$ values, because the integrals over the inverse square terms are zero.  Thus we are left with the integrand reducing to
$$-\frac{2 i}{3 \sqrt{3}} \left (\frac1{x-e^{i 2 \pi/3}} - \frac1{x-e^{-i 2 \pi/3}} \right )= \frac{2}{3} \frac1{x^2-x + 1} $$
We integrate this by completing the square in the denominator:
$$\frac{2}{3} \int_{-\infty}^{\infty} \frac{dx}{(x-1/2)^2+3/4} = \frac{2}{3} \int_{-\infty}^{\infty} \frac{dy}{y^2+3/4} = \frac{4 \pi}{3 \sqrt{3}} $$
</s>