# Real integral using residue theorem - why doesn't this work?

Consider the following definite real integral: $$I = \int_{0}^\infty dx \frac{e^{-ix} - e^{ix}}{x}$$

Using the $$\text{Si}(x)$$ function, I can solve it easily, $$I = -2i \int_{0}^\infty dx \frac{e^{-ix} - e^{ix}}{-2ix} = -2i \int_{0}^\infty dx \frac{\sin{x}}{x} = -2i \lim_{x \to \infty} \text{Si}(x) = -2i \left(\frac{\pi}{2}\right) = - i \pi,$$ simply because I happen to know that $$\mathrm{Si}(x)$$ asymptotically approaches $$\pi/2$$.

However, if I try to calculate it using the residue theorem, I get the wrong answer, off by a factor of $$2$$ and I'm not sure if I understand why. Here's the procedure: $$I= \int_{0}^\infty dx \frac{e^{-ix}}{x} - \int_{0}^\infty dx \frac{ e^{ix}}{x} = \color{red}{-\int_{-\infty}^0 dx \frac{e^{ix}}{x}} - \int_{0}^\infty dx \frac{ e^{ix}}{x} = -\int_{-\infty}^\infty dx \frac{e^{ix}}{x}$$ Then I define $$I_\epsilon := -\int_{-\infty}^\infty dx \frac{e^{ix}}{x-i\varepsilon}$$ for $$\varepsilon > 0$$ so that$$I=\lim_{\varepsilon \to 0^+} I_\varepsilon.$$ Then I complexify the integration variable and integrate over a D-shaped contour over the upper half of the complex plane. I choose that contour because $$\lim_{x \to +i\infty} \frac{e^{ix}}{x-i\varepsilon} = 0$$ and it contains the simple pole at $$x_0 = i \varepsilon$$. Using the residue theorem with the contour enclosing $$x_0$$ $$I_\varepsilon = -2 \pi i \, \text{Res}_{x_0} \left( \frac{e^{ix}}{x-i\varepsilon}\right) = -2 \pi i \left( \frac{e^{ix}}{1} \right)\Bigg\rvert_{x=x_0=i\varepsilon}=-2 \pi i \, e^{-\varepsilon}.$$ Therefore, $$I=\lim_{\varepsilon \to 0^+} \left( -2 \pi i \, e^{-\varepsilon} \right) = -2\pi i.$$

However, that is obviously wrong. Where exactly is the mistake?

You've replaced the converging integral $$\int_0^\infty \frac{\mathrm{e}^{-\mathrm{i} x} - \mathrm{e}^{\mathrm{i} x}}{x} \,\mathrm{d}x$$ with two divergent integrals, $$\int_0^\infty \frac{\mathrm{e}^{-\mathrm{i} x}}{x} \,\mathrm{d}x$$ and $$\int_0^\infty \frac{\mathrm{e}^{\mathrm{i} x}}{x} \,\mathrm{d}x$$. (That something divergent has been introduced is evident in your need to sneak up on a singularity at $$0$$ that was not in the original integral.)
Also, notice that your D-shaped contour does not go around your freshly minted singularity at $$x = 0$$. The singularity lands on your contour. See the Sokhotski–Plemelj theorem to find that the multiplier for the residue of the pole is $$\pm \pi \mathrm{i}$$, not $$\pm 2 \pi \mathrm{i}$$.
You cannot shift the pole from the integration contour at will. Imagine that you shift it in the lower complex half-plane. Then instead of $$-2\pi i$$ you would obtain for the integral the value $$0$$!