Developing a Process for Contour Integration I am working on developing a personal process to follow (i.e. generalize, as much as is possible) for contour integration. I have seen the following things happen in worked examples and I am not sure why they were performed. I would really appreciate some clarity on the subject and in particular, what is going through your mind that made you think the following were necessary. 
Context: I am a big picture thinker and my professor tends to focus on details. I am a first year graduate student with no experience (other than the course I'm currently in) with complex analysis. These are my questions:
1) In this problem Contour Integration of $\sin(x)/(x+x^3)$ , DonAntonio considers the fuction $f(z)=\frac{e^z}{z(z^2+1)}$ to "replace" the real-valued function $f(x)=\frac{\sin x}{x(x^2+1)}$. 
(a) Why would we choose to use $e^z$ instead of $\sin z$? Is it easier to work with?
(b) Why does $e^z=\sin z$ in the context of this problem? In my mind, $e^z=e^x e^{iy}=e^x( \cos y+i\sin y)$.
2) I have noticed in several problems that the authors choose to change the interval of integration before embarking on the rest of the problem. For example,
$\int_0^{\pi} \frac{d \theta }{a+\cos \theta} = \frac{1}{2}\int_0^{2\pi} \frac{d \theta }{a+\cos \theta} $, $\int_0^{\infty} \frac{x^2dx}{x^4+x^2+1}=\frac{1}{2}\int_{-\infty}^{\infty} \frac{x^2dx}{x^4+x^2+1}$, etc. Is it possible to state generally why they are doing this and when I should do it?
 A: You may find that your questions are surprisingly specific.  Let me answer them as a segue to a possible more general understanding.
1) As @mjqxxxx stated, when we integrate along a semicircle in one of the half-planes, upper or lower, we want to ensure that the resulting integral over the semicircle is at least bounded. Note that $|\sin{z}| = \sinh{y}$ along the imaginary axis i.e., $z=iy$ so that any integral over the semicircle is unbound as $|z| \to \infty$.  However, we know that $\sin{x} = \operatorname{Im}{(e^{ix})}$, and, if we are in the upper half-plane, then $e^{iz} = e^{-y}$ which certainly vanishes.  In fact, we may show that the integral along the whole semicircular arc vanishes by using the nifty inequality $\sin{x} \ge 2 x/\pi$ when $x \in [0,\pi/2]$.  Along the semicircle, $z=R e^{i\theta}$ and we get as the integral over the semicircle in the upper half plane,
$$R \int_0^{\pi} d\theta \, e^{i\theta} \, \frac{e^{i R e^{i\theta}}}{R e^{i\theta} \left ( 1+R^2 e^{i 2\theta} \right )} $$
The magnitude of this integral is bounded by
$$\frac{2}{R^2-1} \int_0^{\pi/2} d\theta \, e^{-R \sin{\theta}} \le \frac{2}{R^2-1} \int_0^{\pi/2} d\theta \, e^{-2 R \theta/\pi} \le \frac{\pi}{R (R^2-1)}$$
Note that
$$|e^{i R e^{i\theta}}| = e^{-R \sin{\theta}}$$
2) We extend over the entire circle or real line because that is how we generate closed contours for the residue theorem (or Cauchy's theorem).  In this case, symmetry of the integrand was used to an advantage to express the original integral as $1/2$ (or some other fraction) of an integral which is a section of a closed contour we would use for the residue theorem. Really, you get used to doing this.
There is a cautionary aspect to this, however. Consider the integral
$$\int_0^{\infty} dx \frac{x^2}{1+x^8} $$
Now we could just extend over the entire real axis.  Then we could consider the semicircular contour as before, noting that the integral over the arc vanishes and we may then proceed with applying the residue theorem to determine the value of the integral.  Nothing wrong with this...except you need to add up residues from four poles in the upper half plane.  It turns out that, with a different contour, you need only one residue from a single pole.  That would be a wedge contour of angle $\pi/4$ with respect to the positive real axis.  The integral about the wedge looks like
$$\int_0^R dx \frac{x^2}{1+x^8} + R \int_0^{\pi/4} d\theta \, e^{i \theta} \frac{R^2 e^{i 2 \theta}}{1+R^8 e^{i 8 \theta}} + e^{i \pi/4} \int_R^0 dt \, \frac{e^{i \pi/2} t^2}{1+e^{i 2 \pi} t^8}$$
It should be clear that the second integral vanishes as $R \to \infty$.  Thus, the contour integral is equal to
$$\left ( 1-e^{i 3 \pi/4} \right ) \int_0^{\infty} dx \frac{x^2}{1+x^8}$$
which, by the residue theorem, is $i 2 \pi$ times the residue at the pole $z=e^{i \pi/8}$.  
Note that if we had gone with the full semicircle, we would have had to compute residues at $z=e^{i \pi/8}$, $z=e^{i 3 \pi/8}$, $z=e^{i 5 \pi/8}$, and $z=e^{i 7\pi/8}$.  So the choice of contour can drastically affect how easy the residue theorem makes computation!
General observations:
Using contour integrals in the complex plane to evaluate real, definite integrals is not work cut out for amateurs.  In a first course in complex analysis, when one is taught the residue theorem, one is spoon-fed the contours to use and the tricks to employ to make things work out just so. 
However, real life isn't so simple.  It takes a lot of practice to apply the fairly obvious ideas involved in using contour integration in this way.  Remember, a contour integral involves both an integrand and a contour.  Both of these entities requires consideration and choice and may not be as easy as just replacing $x$ with $z$ and applying the residue theorem.  
The first thing to understand is that it is the contour integral that is equal to $i 2 \pi$ times the sum of the residues of the poles (if any) interior to the contour (times a respective winding number if things get really hairy), not the real integral.  This means that we have to actually evaluate all of the pieces of the contour integral and wither prove that they vanish or keep them as part of the computation.
Thus, we have to design our contour integral so those other pieces we do not care about are either easy to evaluate or vanish in some limit (as with the semicircles above).  Allow me to present an example of this below.  (In fact, you can search through my contour-integration solutions if you wish and see a bunch more, but why not see one right here?)
The integral to evaluate is
$$
\int_{0}^{\infty} dx \, 
{\cos\left(\pi x^{2}\right)\over
1 + 2\cosh\left(\,2\,\pi\,x\,/\,\sqrt{\,3\,}\,\right)}$$
The solution is to consider the following integral:
$$\oint_C dz \;f(z) $$
where 
$$f(z) = \frac{e^{i \pi z^2}}{\sinh{\left (\sqrt{3} \pi z\right )} \left [ 2 \cosh{\left ( \frac{2 \pi}{\sqrt{3}} z\right )}-1\right ]}$$
and $C$ is the rectangle with vertices in the complex plane $\pm R\pm i \sqrt{3}/2$.  This contour integral is thus equal to
$$\int_{-R}^R dx \; f\left (x-i \frac{\sqrt{3}}{2}\right ) + i \int_{-\sqrt{3}/2}^{\sqrt{3}/2} dy \, f(R+i y) \\ \int_R^{-R} dx\; f\left (x+i \frac{\sqrt{3}}{2}\right ) +i \int_{\sqrt{3}/2}^{-\sqrt{3}/2} dy \, f(-R+i y)$$
It should be clear that the second and fourth integrals vanish as $R\to\infty$, as these integrals vanish as $\pi e^{-\pi R}$ as $R\to\infty$.  In this limit, then, the contour integral is equal to
$$\int_{-\infty}^{\infty} dx \; \left [ f\left (x-i \frac{\sqrt{3}}{2}\right ) - f\left (x+i \frac{\sqrt{3}}{2}\right )\right ] = i 2 e^{-i 3 \pi/4}\int_{-\infty}^{\infty} dx \frac{e^{i \pi x^2}}{2 \cosh{\left ( \frac{2 \pi}{\sqrt{3}} x\right )}+1}$$
I chose not to clutter up this space with the algebra involved in producing this last equation.  The reader, however, should prove to his/herself that this is indeed correct.
By the residue theorem, the contour integral is also equal to $i 2 \pi$ times the sum of the residues of the poles of $f$ inside $C$.  I leave it to the reader to verify that these poles are at $z=0$, $z=\pm i \sqrt{3}/3$, and $z=\pm i\sqrt{3}/6$.  The residues at these poles are straightforward to compute because the poles are simple:
$$\operatorname*{Res}_{z=0} f(z) = \frac1{\sqrt{3} \pi}$$
$$\operatorname*{Res}_{z=\pm i \sqrt{3}/3} f(z) = \frac{e^{-i \pi/3}}{2 \sqrt{3} \pi}$$
$$\operatorname*{Res}_{z=\pm i \sqrt{3}/6} f(z) = -\frac{e^{-i \pi/12}}{2 \pi}$$
So the residue theorem states, equivalently, that
$$\begin{align}\int_{-\infty}^{\infty} dx \frac{e^{i \pi x^2}}{2 \cosh{\left ( \frac{2 \pi}{\sqrt{3}} x\right )}+1} &= \frac{e^{i 3 \pi/4}}{\sqrt{3}} + \frac{e^{i 5 \pi/12}}{\sqrt{3}} - e^{i 2 \pi/3}\\ &= \frac1{\sqrt{6}} (-1+i) + \frac1{2 \sqrt{6}} \left [ (\sqrt{3}-1) + i (\sqrt{3}+1)\right ] + \frac12 (1-i \sqrt{3})\end{align}$$
The integral of interest here is equal to $1/2$ the real part of the above, which is
$$\int_0^{\infty} dx \frac{\cos{\pi x^2}}{2 \cosh{\left ( \frac{2 \pi}{\sqrt{3}} x\right )}+1} = \frac{2+\sqrt{2}-\sqrt{6}}{8} $$
which was to be shown.
ADDENDUM
We may as well reap the reward of the imaginary part we get for free:
$$\int_0^{\infty} dx \frac{\sin{\pi x^2}}{2 \cosh{\left ( \frac{2 \pi}{\sqrt{3}} x\right )}+1} = \frac{\sqrt{2}+\sqrt{6}-2 \sqrt{3}}{8} $$
