Evaluation of Singular Integrals by Complex Contour Integration I am learning to compute singular integrals using the '$i\epsilon$-prescription' of complex contour integration from the book Mathematical Physics by V. Balakrishnan (Chapter 23, Article 23.3.4). Following the book, the integral I want to compute is,   

$$f(x_0)=\displaystyle{\int_a^b dx\frac{\phi (x)}{x-x_0}}\tag{1}$$ where $a < x_0 < b$ are real numbers, $\phi(x)$ is a sufficiently smooth function, and $\phi(x_0)\neq 0$. The integrand obviously diverges at $x = x_0$ because of the factor $(x − x_0)$ in the denominator. As it stands, the Riemann integral in Eq.(1) does not exist, because of this nonintegrable singularity of the integrand. Suppose, however, we move the singularity away from the path of integration by giving it either a positive
  imaginary part $+i\epsilon$ (where $\epsilon > 0$), or a negative imaginary part $−i\epsilon$. This step, called an $i\epsilon$-prescription, makes the original integral well-defined. The integrals in the two cases are given, respectively, by $$f(x_0 ± i\epsilon) = \int_a^b dx \frac{\phi(x)}{x−(x_0±i\epsilon)} = \int_a^b dx\frac{\phi(x)}{x−x_0∓i\epsilon}\tag{2}$$ 
  The question is: what happens as $\epsilon \to 0$ ? We can continue to keep the integral well-defined by distorting the path of integration away from the approaching singularity, to form a small semicircle of radius $\epsilon$. This semicircle lies in the lower half-plane in the case of $\boldsymbol{f(x_0+i\epsilon)}$, and in the upper half-plane in the case of $\boldsymbol{f(x_0 − i\epsilon)}$. This is shown in figures (a) and (b) :

  On the small semicircles, the variable of integration is $z = x_0 + \epsilon e^{i\theta}$, so that $dz =\epsilon e^{i\theta}id\theta$. The argument $\theta$ runs from $\pi$ to $2\pi$ in the case of $f (x + i\epsilon)$, and from $\pi$ to $0$ in the case of $f (x − i\epsilon)$. Taking the limit $\epsilon \to 0$ then yields the Cauchy principal value integral from $a$ to $b$, plus the contribution from the semicircle: $$\lim_{\epsilon \to 0}\int_a^b dx\frac{\phi(x)}{x−x_0∓i\epsilon}= P\int_a^b dx\frac{\phi(x)}{x-x_0}± i\pi\phi(x_0)\tag{3}$$ 

I have two questions : 
Firstly, I do not understand the line in bold. Why the semicircle lies in the lower half-plane in the case of $f(x_0+i\epsilon)$, and in the upper half-plane in the case of $f(x_0 − i\epsilon)$ ?  
Secondly, when I am computing the contribution from the semi-circle, I do not get the value $i\pi\phi(x_0)$ . This is how I am doing it for $f(x_0+i\epsilon)$ : $$\begin{align}
\lim_{\epsilon \to 0}\int_{-\epsilon}^{+\epsilon}dz\frac{\phi(z)}{z-x_0-i\epsilon}&=\lim_{\epsilon \to 0}\int_{\pi}^{2\pi} d\theta \,\,\epsilon e^{i\theta}i\frac{\phi(x_0+\epsilon e^{i\theta})}{\epsilon (e^{i\theta}-i)}=i\lim_{\epsilon \to 0}\int_{\pi}^{2\pi} d\theta \,\, e^{i\theta}\frac{\phi(x_0+\epsilon e^{i\theta})}{(e^{i\theta}-i)}\\
&=i\lim_{\epsilon \to 0}\left(\left[\phi(x_0+\epsilon e^{i\theta})\int d\theta\frac{e^{i\theta}}{(e^{i\theta}-i)}\right]_{\pi}^{2\pi}-\epsilon\int_{\pi}^{2\pi} d\theta \,\left\{\frac{d\phi(x_0+\epsilon e^{i\theta})}{d\theta}\int d\theta \frac{e^{i\theta}}{(e^{i\theta}-i)}\right\}\right)
\end{align} $$ 
The second term vanishes by the application of the limit. Then, $$\begin{align}\lim_{\epsilon \to 0}\int_{-\epsilon}^{+\epsilon}dz\frac{\phi(z)}{z-x_0-i\epsilon}&=\lim_{\epsilon \to 0}\left(\left[\phi(x_0+\epsilon e^{i\theta})\ln{(e^{i\theta}-i)}\right]_{\pi}^{2\pi}\right)\\
&=\lim_{\epsilon \to 0}\left(\phi(x_0+\epsilon e^{i\theta})\ln{\left(\frac{1-i}{-1-i}\right)}\right)\\
&=\phi(x_0)\ln{\left(\frac{i-1}{i+1}\right)}\\
&=\phi(x_0)\ln{\left(\frac{{(i-1)}^2}{-2}\right)}\\
&=\phi(x_0)\ln{i}\\
&=\phi(x_0)\ln{e^{i\pi/2}}\\
&=i\frac{\pi}{2}\phi(x_0)
\end{align}$$
So, a factor of 2 is coming in the denominator which should not be there. Where am I getting wrong? Please help.
 A: The answer to your first question: the semicircle is in the lower half-plane for $f(x_0+i\varepsilon)$ so that the singularity at $x=x_0+i\varepsilon$ is not on the semicircle.

Your computation of the contour integral over the semicircle in the lower half-plane, $i\phi(x_0)\pi/2$, is correct.  But you are neglecting the two linear portions of the contour $x\in [a,x_0-\varepsilon]$ and $x\in [x_0+\varepsilon, b]$.  The function $\phi(x)$ can be expanded in a Taylor series about $x_0$ as
$$
  \phi(x) = \phi(x_0) + \phi'(x_0)(x-x_0) + \dots.
$$
Let's compute the contour integral of the contribution of the constant term of the Taylor expansion of $\phi$ over the linear portions of the contour.  This is
$$
  \int_a^{x_0 - \varepsilon} \frac{\phi(x_0) dx}{x - x_0 - i\varepsilon} + 
  \int_{x_0+\varepsilon}^b \frac{\phi(x_0) dx}{x - x_0 - i\varepsilon}.
$$
After integrating and removing the factor $\phi(x_0)$, this is
$$
  \log(-\varepsilon - i\varepsilon) - \log(-1) - \log(x_0-a) + \log(b-x_0) - \log(\varepsilon - i\varepsilon).
$$
We are only interested in the imaginary part of this expression since the real part contributes to the principal value of the definite integral of $\phi(x)/(x-x_0)$.  
The imaginary part is
$$
  \begin{align}
  & \log(\varepsilon(-i-1)) - \log(-1) - \log(\varepsilon(1-i)) \\
  & \quad = \log(-i-1) - \log(-1) - \log(1-i) \\
  & \quad = \log\frac{1+i}{1-i} = \log \frac{(1+i)^2}{2} = \log i = i\pi/2.
  \end{align}
$$
You can show that the imaginary part of 
$$
  \int_a^{x_0 - \varepsilon} \frac{(x-x_0)^n dx}{x - x_0 - i\varepsilon} + 
  \int_{x_0+\varepsilon}^b \frac{(x-x_0)^n dx}{x - x_0 - i\varepsilon}.
$$  
vanishes (in the limit $\varepsilon\rightarrow 0$) if $n$ is any positive integer.  So $i\phi(x_0)\pi/2$ is the imaginary part of
$$
  \int_a^{x_0 - \varepsilon} \frac{\phi(x) dx}{x - x_0 - i\varepsilon} + 
  \int_{x_0+\varepsilon}^b \frac{\phi(x) dx}{x - x_0 - i\varepsilon}
$$
and the imaginary part of the contour integral of $\phi(z)/(z-x_0-i\varepsilon)$ over the entire contour is $i\phi(x_0)\pi.$

