Real integrals in the complex plane Sometimes real valued integrals are evaluated by viewing them as a contour integration in the complex plane.
For example, $$I = \int_{-\infty}^{\infty} \frac {dx}{(x^2 + 1)^2}$$
The question was asked here, 
Real integrals using Complex integration, but there was no attempt an answer.
The question is, why do we think that the contour we evaluate in the complex plane will give us the same answer as the original real integral?
Thanks.
 A: There are some basic approaches to choosing a good contour.
You should ask yourself is where the singularities are.
Then you should take a look at your integral domain.
Then look for symmetries (including $\sin(x)=\Im(e^{ix})$ or $f(ix)=\dots$)
Then, you need to check the asymptotes of your integrand as you approach complex infinities (such as $\lim_{x\to i\infty}e^{ix}=e^{i^2\infty}=e^{-\infty}=0$ or $\left|\frac x{(x^2+1)^2}\right|\ll\frac1{x^3}$)
For your example, one might note that:
$$x=\pm i\implies\frac1{(x^2+1)^2}=\frac10\implies\text{singularities}$$
Our integral domain is $(-\infty,\infty)$, so we'll want to check if a semicircle contour works.
In the case that we were integrating on $[0,\infty)$, you would want to note that
$$\int_{-\infty}^\infty\frac1{(x^2+1)^2}~\mathrm dx=2\int_0^\infty\frac1{(x^2+1)^2}~\mathrm dx$$
which follows from the symmetry step.
Assymptotically as $|z|\to\infty$, we can see that
$$\left|\frac1{(z^2+1)^2}\right|\ll\left|\frac1{z^3}\right|$$
Since this decays faster than $\mathcal O(z^{-1})$, we know that
$$\begin{align}\lim_{R\to\infty}\left|\int_{\{Re^{i\theta}:\theta\in[0,\pi]\}}\frac1{(z^2+1)^2}~\mathrm dz\right|&\le\lim_{R\to\infty}\int_{\{Re^{i\theta}:\theta\in[0,\pi]\}}\left|\frac1{(z^2+1)^2}\right|~\mathrm dz\\&\ll\lim_{R\to\infty}\int_{\{Re^{i\theta}:\theta\in[0,\pi]\}}\left|\frac1{z^3}\right|~\mathrm dz\\&\le\lim_{R\to\infty}\pi R\max_{z\in\{Re^{i\theta}:\theta\in[0,\pi]\}}|z^{-3}|\\&=\lim_{R\to\infty}\frac\pi{R^2}\\&=0\end{align}$$
Thus, we find nicely that
$$\int_{-\infty}^\infty\frac1{(x^2+1)^2}~\mathrm dx=\lim_{z\to\infty}\oint_{\gamma_R}\frac1{(z^2+1)^2}~\mathrm dz$$
$\gamma_R=(-R,R)\cup\{Re^{i\theta}:\theta\in[0,\pi]\}$
And the rest requires the residue theorem.

Of course, not all integrals can be tackled using a semicircle contour.  Some other contours you should keep in mind:
Keyhole contour
Rectangular contour
Wedge contour
Circle contour
Each having its own use depending on the integral at hand.  For example, if a function has a branch cut along a certain line, try a keyhole contour with the keyhole centered at the branch point and the keyhole along the branch cut.  If a keyhole contour doesn't look friendly because there are too many singularities inside it, a wedge contour may be more suited, chosen with an angle so that it only encompasses one singularity.  If a function behave peculiarly nicely along $f(x+iy)$, you may be interested in the rectangular contour.  A circular contour is especially useful for integrals of the form $\int_0^{2\pi}f(\sin(\theta))~\mathrm d\theta=\int_0^{2\pi}f(\cos(\theta))~\mathrm d\theta$.
A: In the simplest case, for $$ J = \int_{-\infty}^\infty f(x)\; dx$$
we take a contour that goes from $-R$ to $R$ on the real axis and then returns by a semicircle in either the upper or lower half plane.  As $R \to \infty$, the limit (if it exists) of the integral from $-R$ to $R$ will be $J$.  We want the integral over the semicircle to go to $0$: for example, it will do so if $f$ is a rational function where the degree of the denominator is greater than that of the numerator by at least $2$.  Then the contour integral can be evaluated using the residue theorem, and its limit will be $J$.
A: I think you can do it, if the Cauchy principal value of the integral is equal to the integral. The integral is equal to its Cauchy principal value if it converges.
So suppose you have an integral $$\int_{-\infty}^{\infty}f(x) dx.$$ If it converges you can say that $$
\int_{-\infty}^{\infty}f(x) dx=\lim_{a\rightarrow\infty}\int_{-a}^{a}f(x)dx.
$$
Now you need to find a closed path $\gamma\subset\mathbb{C}$ that includes the interval $(-a,a)$. To clarify that $\gamma$ depends on $a$, I will denote it as $\gamma(a)$. Finally you can take advantage of complex integration and its beautiful theorems.
Say you look at the closed path integral
$$\oint_{\gamma(a)}f(z)dz.$$ Linearity of integration gives you
$$\oint_{\gamma(a)}f(z)dz=\int_{\gamma'(a)}f(z)dz+\int_{-a}^af(x)dx.$$
Here $\gamma'=\gamma/(-a,a).$ Taking the $\lim_{a\rightarrow\infty}$ will give you the integral you are looking for on the right side. You have to make sure that the integral over $\gamma'(a)\rightarrow 0$ as $a\rightarrow\infty$. The closed path integral you can hopefully calculate with the residue theorem. To be a little more clear: Let $f$ be analytic in $G\subset \mathbb{C}$ except for some points $z_1,...z_n,...z_{p}\in G$. Let $\gamma\subset G$ be a simple closed path and positively oriented, then $$\oint_{\gamma(a)}f(z)dz=2\pi i \sum_{k=1}^n Res(f,z_k).$$ Where $n$ is the number of poles inside $\gamma(a)$ and $$Res(f,z_k)=\lim_{z\rightarrow z_k}\frac{1}{(m-1)!}\frac{d^{m-1}}{dz^{m-1}}\left((z-z_k)^m f(z)\right).$$ $m$ is the order of the pole of $f$ for the point $z_k$. Calculating all these residues will give you the closed path integral, which will be the same as the real integral.
