Using Complex Analysis to Compute $\int_0 ^\infty \frac{dx}{x^{1/2}(x^2+1)}$ I am aware that there is a theorem which states that for $0<a<2$ we have $$\int_0^\infty\frac{x^{a-1}}{x^2+1}dx=\frac{\pi \cos\big(\frac{a\pi }{2}\big)}{\sin (a\pi) }$$ but I prefer to evaluate the integral using the calculus of residues (since I don't want to have to recall a theorem for almost every other problem of this type). On the other hand, I don't have a useful contour in mind. 
My attempt is the following: Let's take $f(z)=\frac{1}{z^{1/2}(z^2+1)}$ as the complexification of our integrand. Define $\gamma_R=\gamma _R^1+\gamma_R^2+\gamma_R^3$, where $\gamma_R^1(t)=t$ for $t$ from $1/R$ to $R$; $\gamma_R^2(t)=\frac{1}{R}e^{it}$, where $t$ goes from $\pi /4$ to $0$ ; and $\gamma_R^3(t)=e^{\pi i/4}t, $ where $t$ goes from $R$ to $1/R$ (see drawing).
The poles of the integrand are at $0,\pm i$, but those are not contained in the contour, so by the residue theorem $\int_{\gamma_R}f(z)dz=0$. On the other hand, $\int_{\gamma_R}=\int_{\gamma_R^1}+\int_{\gamma_R^2}+\int_{\gamma_R^3}$. As $R\to \infty$, $\int_{\gamma_R^1}f(z)dz\to \int_0 ^\infty \frac{1}{x^{1/2}(x^2+1)}dx$. Also, = $\vert \int_{\gamma_R^2}f(z)dz\vert \le \frac{\pi }{4R}\cdot \frac{1}{R^2-1}$ and the lattest expression tends to $0$ as $R\to \infty$. However, $\int_{\gamma_R^3}f(z)=i\int_R ^{1/R}tdt=\frac{i/R^2-iR^2}{2}$, which is unbounded in absolute value for large $R$. 
Is there a better contour to choose? If so, what is the intuition for finding a good contour in this case?
 A: For this, you want the keyhole contour $\gamma=\gamma_1 \cup \gamma_2 \cup \gamma_3 \cup \gamma_4$, which passes along the positive real axis ($\gamma_1$), circles the origin at a large radius $R$ ($\gamma_2$), and then passes back along the positive real axis $(\gamma_3)$, then encircles the origin again in the opposite direction along a small radius-$\epsilon$ circle ($\gamma_4$). Picture (borrowed from this answer):
$\hspace{4.4cm}$
$\gamma_1$ is green, $\gamma_2$ black, $\gamma_3$ red, and $\gamma_4$ blue.
It is easy to see that the integrals over the large and small circles tend to $0$ as $R \to \infty$, $\epsilon \to 0$, since the integrand times the length is $O(R^{-3/2})$ and $O(\epsilon^{1/2})$ respectively. The remaining integral tends to
$$ \int_{\gamma_1 \cup \gamma_3} = \int_0^{\infty} \frac{x^{-1/2}}{1+x^2} \, dx + \int_{\infty}^0 \frac{(xe^{2\pi i})^{-1/2}}{1+(xe^{2\pi i})^2} \, dx, $$
because we have walked around the origin once, and chosen the branch of the square root based on this. This simplifies to
$$ (1-e^{-\pi i})\int_0^{\infty} \frac{x^{-1/2}}{1+x^2} \, dx = 2I. $$
Now you need to compute the residues of the function at the two poles, using the same branch of the square root. The residues of $1/(1+z^2) = \frac{1}{(z+i)(z-i)}$ are at $z=e^{\pi i/2},e^{3\pi i/2}$, so you find
$$ 2I = 2\pi i \left( \frac{(e^{\pi i/2})^{-1/2}}{2i} +\frac{(e^{3\pi i/2})^{-1/2}}{-2i}  \right) = 2\pi \sin{\frac{1}{4}\pi} = \frac{2\pi}{\sqrt{2}} $$

However, I do recommend that you don't attempt to use contour integration for all such problems: imagine trying to do
$$ \int_0^{\infty} \frac{x^{s-1}}{(a+bx^n)^m} \, dx, $$
for general $a,b,s,m,n$ such that it converges, using that method! No, the useful thing to know is that
$$ \frac{1}{A^n} = \frac{1}{\Gamma(n)}\int_0^{\infty} \alpha^{n-1}e^{-\alpha x} \, dx, $$
which enables you to do more general integrals of this type. Contour integration's often a quick and cheap way of doing simple integrals, but becomes impractical in some general cases.
A: I think what you actually wanted to do was to use a semicircle in the upper half plane.  Generally speaking, for these integrals, you want to use a wedge of angle twice the argument of the pole.  However, you had the right idea of avoiding the branch point at the origin.  Thus, we would introduce a small semicircular detour of radius $\epsilon$ at the origin; this detour contributes nothing to the integral as $\epsilon \to 0$ for $a \gt 0$.  Thus, the contour integral is equal to
$$e^{i \pi} \int_{\infty}^0 dx \frac{e^{i \pi (a-1)} x^{a-1}}{1+x^2} + \int_0^{\infty} dx \frac{x^{a-1}}{1+x^2} + i R \int_0^{\pi} d\theta \, e^{i \theta} \frac{R^{a-1} e^{i (a-1) \theta}}{1+R^2 e^{i 2 \theta}}$$
The third integral vanishes as $R \to \infty$ when $a \lt 2$.  The first two integrals combine as
$$\left ( 1-e^{i a \pi}\right ) \int_0^{\infty} dx \frac{x^{a-1}}{1+x^2}$$
By the residue theorem, the contour integral is also equal to $i 2 \pi$ times the residue at the pole $z=e^{i \pi/2}$.  Thus,
$$\left ( 1-e^{i a \pi}\right ) \int_0^{\infty} dx \frac{x^{a-1}}{1+x^2}= i 2 \pi \frac{e^{i (a-1) \pi/2}}{2 i}$$
The result follows.
