TITLE: Application of residue at infinity
QUESTION [6 upvotes]: I am trying to figure out how to find a contour to solve for this integral
$$
\int_{-\infty}^{\infty}\frac{2x}{x^2+x+1}dx = -\frac{2\pi}{\sqrt{3}}
$$
using the residue theorem and the residue at infinity. Without using the idea of residue at infinity, which is equal to $-\frac{1}{2\pi i} \int_{C} f(z)dz$, I will just choose the upper semi-circle. My question is how to choose a contour whose interior includes all the singularities of the function $\frac{2z}{z^2+z+1}$ ($-\frac{1}{2}\pm \frac{\sqrt{3}}{2}i$) such that it also covers the whole real axis as we take appropriate radii to $0$ or $\infty$, etc. I am thinking of a contour will be some sort of keyhole, but couldn't figure out a simpler contour. It seems like using residue at infinity makes the question 10 times more complicated than necessary.

REPLY [2 votes]: Nice explanations were posted - on how to evaluate the integral, closing the contour in the upper half-plane (and using, in fact, half of the residue at the infinity). In my opinion, this is the most adequate way to approach the integral by means of complex integration. However, if we want use a longer road and to use all residues evaluation along this road, we can switch to the keyhole contour. This way will not require the evaluation of the residue at infinity, though (speaking conceptually, the sum of all residues of a meromorphic function is zero).
$$I=\int_{-\infty}^\infty\frac{2x}{x^2+x+1}dx=\int_0^\infty\frac{2x}{x^2+x+1}dx-\int_0^\infty\frac{2x}{x^2-x+1}dx=-\int_0^\infty\frac{4x^2}{(x^2+1)^2-x^2}dx$$
Making the substitution $t=x^2$
$$I=-2\int_0^\infty\frac{\sqrt t}{t^2+t+1}dt$$
The roots of $z^2+z+1$ are $z_{1,2}=e^{\frac{5\pi i}{6}},e^{\frac{7\pi i}{6}}$ (we have chosen all angles $\in[0;2\pi]$).
Making the cut $[0;\infty)$ along the positive part of the axis $X$ and adding a big circle of the radius $R\to\infty$ (counter-clockwise, from the upper bunk of the cut to the lower bank), a small circle (radius $r\to0$, clockwise) around $z=0$, together with the upper and lower banks of the cut, we get a keyhole contour.
Integration along this contour gives:
$$\oint\frac{2\sqrt z}{(z-e^{\frac{5\pi i}{6}})(z-e^{\frac{7\pi i}{6}})}dz=I+I_R-Ie^{\pi i}+I_r=2\pi i\underset{z=z_{1,2}}{\operatorname{Res}}\frac{2\sqrt z}{(z-e^{\frac{5\pi i}{6}})(z-e^{\frac{7\pi i}{6}})}$$
Given that $I_R, I_r\to0$,  $\,\sqrt{e^{\frac{5\pi i}{6}}}=\sqrt{e^{\pi i-\frac{\pi  i}{6}}}=ie^{-\frac{\pi  i}{12}}$ and $\sqrt{e^{\frac{7\pi i}{6}}}=ie^{\frac{\pi  i}{12}}$
$$I=2\pi i\underset{z=z_{1,2}}{\operatorname{Res}}\frac{\sqrt z}{(z-e^{\frac{5\pi i}{6}})(z-e^{\frac{7\pi i}{6}})}=2\pi i\bigg(\frac{ie^{-\frac{\pi  i}{12}}}{e^{\frac{5\pi i}{6}}-e^{\frac{7\pi i}{6}}}+\frac{ie^{\frac{\pi  i}{12}}}{e^{\frac{7\pi i}{6}}-e^{\frac{5\pi i}{6}}}\bigg)$$
$$=-2\pi\frac{\sin\frac{\pi}{12}}{\sin\frac{\pi}{6}}=-\frac{\pi}{\cos\frac{\pi}{12}}$$
Using $\cos\alpha=\sqrt{\frac{1+\cos2\alpha}{2}}$
$$I=-\,\frac{\pi}{\sqrt\frac{1+\cos\frac{\pi}{6}}{2}}=-\frac{2\pi}{\sqrt3}$$