How can I use residue theory to verify this integral formula?

I need to use residue theory to verify that:

$$\mathbf\int_0 ^\infty \frac{\sqrt{x}}{x^2+1}dx=\pi/\sqrt2$$

I was told to use a “keyhole” contour with the positive real axis deleted, but I don’t understand how to do this.

Solutions Collecting From Web of "How can I use residue theory to verify this integral formula?"

There are at least two ways to approach this problem. The first employs a substitution, $x\mapsto x^2$, and then the evenness of the integrand:
The integral $(1)$ can be evaluated with the contour, $\gamma_1$, below: along the real axis from $-R$ to $R$, then circle back, counterclockwise, along a circle in the upper-half-plane back to $-R$.

$\hspace{3.2cm}$enter image description here

The integral along the curve vanishes as $R\to\infty$ since the integrand $\sim1/R^2$ and the length of the curve is $\pi R$. Therefore,
The value of the integral in $(2)$ is $2\pi i$ times the sum of the residues at $\color{#C00000}{\frac{i-1}{\sqrt{2}}}$ and $\color{#00A000}{\frac{i+1}{\sqrt{2}}}$:
2\pi i\left(\color{#C00000}{\frac{-1-i}{4\sqrt{2}}}+\color{#00A000}{\frac{1-i}{4\sqrt{2}}}\right)=\frac\pi{\sqrt{2}}\tag{3}

The second method employs a branch-cut along the positive real axis. The square root cannot be defined continuously on $\mathbb{C}$. To see this, follow the circle of radius $1$ counterclockwise from $+1$ back to $+1$:

$\hspace{4.4cm}$enter image description here

We get that $\sqrt{+1}=\color{#C00000}{+1}$, $\sqrt{i}=\color{#C00000}{\frac{i+1}{\sqrt{2}}}$, $\sqrt{-1}=\color{#C00000}{i}$, $\sqrt{-i}=\color{#C00000}{\frac{i-1}{\sqrt{2}}}$, and $\sqrt{+1}=\color{#C00000}{-1}$. Thus, $\sqrt{z}$ cannot circle the origin.

One way to prevent circling the origin, is to remove the positive real axis. The square root just above the positive real axis is the positive square root. Just below the positive real axis is the negative square root.

A contour that is useful when integrating functions requiring a branch-cut is the keyhole contour:

$\hspace{4.4cm}$enter image description here

It follows a large circle (whose radius tends to $\infty$) counterclockwise, a small circle (whose radius tends to $0$) clockwise, and two straight paths connecting them, from the small circle to the large circle above the positive real axis, and from the large circle to the small circle below the positive real axis.

If we integrate $\dfrac12\dfrac{\sqrt{z}}{1+z^2}$ over this contour, the part on the black circle vanishes because the integrand $\sim\frac1{R^{3/2}}$ and the length of the circle is $2\pi R$. The part on the blue circle vanishes since the integrand and the length of the circle tend to $0$. Because $\sqrt{z}$ is positive on the green contour and negative on the red contour, and the red contour is in the opposite direction from the green contour, the sum of those integrals tends to
and the integral in $(5)$ is just $2\pi i$ times the sum of the residues at $\color{#C00000}{i}$ and $\color{#00A000}{-i}$:
2\pi i\left(\color{#C00000}{\frac{1-i}{4\sqrt{2}}}+\color{#00A000}{\frac{-1-i}{4\sqrt{2}}}\right)=\frac\pi{\sqrt{2}}\tag{6}

You can always define $\sqrt z=\sqrt r e^{i\theta/2}$ where $z=re^{i\theta}$ (and $\sqrt r$ being the ordinary nonnegative real square root), the only problem being that $\theta$ is not unique given $z$. If you avoid the positive real axis, as suggested, you can pick $\theta\in(0,2\pi)$. Now you will find that $\sqrt z\to\sqrt r$ when $z$ approaches the positive real axis from above, while $\sqrt z\to-\sqrt r$ if you approach it from below.

So if you create a contour $\Gamma_\delta$, first going along the half line $\{x-i\delta\colon x>0\}$ running from $x=+\infty$ down to $x=0$, then proceeding clockwise around the origin on a semicircle of radius $\delta$, and then goes off to infinity along $\{x+i\delta\colon x>0\}$, you will find that $$\lim_{\delta\to0}\int_{\Gamma_\delta}\frac{\sqrt z}{z^2+1}\,dz=2\int_0^\infty\frac{\sqrt x}{x^2+1}\,dx.$$
(You will need to verify that the integral around the semicircle is negligible in the limit.)

Now the trick is first to notice that the integral is independent of $\delta$ for small $\delta$, so you can drop taking the limit above!
The proof involves taking to contours $\Gamma_{\delta_j}$ for $j=1,2$, chopping off their tails, say at $x=M$, and joining their ends with two small vertical line segments, then using Cauchy’s integral theorem. You will need to use the fact that the integral along the chopped off tails vanish in the limit as $M\to\infty$, and the integrals along the extra line segments as well.

The second part to the trick is to keep $\delta$ fixed, but to deform the path into a two semi-infinite line segments $\{x\pm i\delta\colon x>R\}$ joined by most of the circle (dashed in the figure below) $\lvert z\rvert =R$. Again, the integral is independent of $R$, except that when $R>1$ the path surrounds the poles at $z=\pm i$. So you need to take the residues at those poles into account.

Finally, you notice that as $R\to\infty$ the integral goes to zero, since the absolute value of the integrand is approximately $R^{-3/2}$ when $R$ is large. Put all the pieces together, and you’re done.

Rough picture of the paths