Cauchy principal value: methods I don't understand yet the logic in the Cauchy Principale Value (P.V.) calculations. Let the resideu theorem:
$$\color{red}{\oint_Cf(z) \ dz = 2\pi i \sum_{k=1}^n \underset{z=z_k}{Res}\{f(z)\}}$$
(we supposed that $C$ was a "nice" closed curb and $f(z)$ analytical $\forall z \in \mathrm{int} \ C$ except in $z_k$ ($1 \le k \le n$))
I've got 2 poorly justified examples in my exercice book (forgive me for non-mathjaxing all of that follows) :

Apparently, the corrector found a nice closed curb, but don't want to share how he did it. Usually, when $f(z)$ is pair, we can define such a $C$ curb:

but it doesn't explain why the 2 factor is missing in the answer. Why $\pi i$ instead of $2\pi i$ ?

Second example:
$$P.V. \int_{-\infty}^{+\infty} \frac{\exp(-4ix)}{(x+i)^2} \ dx$$
Here, we have a reversed cup (why reversed ?) $\gamma (R)$ with the segment $C(R)$:

Again, I don't understand what has been done. Is there a general methode I can understand to solve those 2 exercices ?

EDIT: corrected one error pointed out in the comments ($(x+i)^2$ instead of $(x+1)^2$)
 A: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{{\displaystyle #1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\on}[1]{\operatorname{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\sr}[2]{\,\,\,\stackrel{{#1}}{{#2}}\,\,\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

Contour: Semi-circle in the upper complex half plane with an indent around $\ds{x = -1}$.
Integration along the upper arc vanishes out as $\ds{R \to \infty}$.
\begin{align}
& \color{#44f}{\lim_{\epsilon \to 0^{+}}\ \left\{%
\int_{-\infty}^{-1 - \epsilon}{\dd x \over \pars{x + 1}\pars{x^{2} + 2}} +
\int_{\pi}^{0}{\epsilon\expo{\ic\theta}\ic\,\dd\theta \over
\pars{\epsilon\expo{\ic\theta}}\bracks{\pars{-1 + \epsilon\expo{\ic\theta}}^{2} + 2}}\right.}
\\ & \color{#44f}{\left.\phantom{\lim_{\epsilon \to 0^{+}}\,\,\,}\int_{-1 + \epsilon}^{\infty}\,\,
{\dd x \over \pars{x + 1}\pars{x^{2} + 2}}\right\}} =
2\pi\ic\on{Res}\bracks{{1 \over \pars{x + 1}\pars{x^{2} + 2}}, x = \root{2}\ic}
\\[5mm] & \implies
\mbox{P.V.}\int_{-\infty}^{\infty}{\dd x \over \pars{x + 1}\pars{x^{2} + 2}} - {\pi\ic \over 3} = 2\pi\ic\bracks{-\,{1 \over 2\root{2}\pars{\root{2} - \ic}}}
\\ - & -----------------------------------
\\[5mm] & \implies
\mbox{P.V.}\int_{-\infty}^{\infty}{\dd x \over \pars{x + 1}\pars{x^{2} + 2}}  = 2\pi\ic\bracks{-\,{1 \over 2\root{2}\pars{\root{2} - \ic}}} + {\pi \ic \over 3}
\\[5mm] = & \ \bbx{\color{#44f}{{\root{2} \over 6}\,\pi}} \approx 0.7405
\\ &
\end{align}
A: In an attempt to answer all your questions, let's start at the beginning.

For the first example, let $f(z) = \dfrac{1}{(z+1)(z^2+2)}$ and define a counterclockwise contour as
$$C := [-R, -1-\epsilon] \cup \gamma \cup [-1+\epsilon, R] \cup \Gamma,$$
where $\gamma$ is the semicircular indent enclosing the pole at $z_0 := -1$ with a small radius $\epsilon$, and $\Gamma$ is the bigger semicircle of a large radius $R$. (There is a visual provided by the other answerer.) By Cauchy's Residue Theorem,
$$
\eqalign{
2\pi i\operatorname{Res}(f(z), z=\sqrt{2}i) &= \int_{-R}^{-1-\epsilon}f(z)dz + \int_{-1+\epsilon}^{R}f(z)dz + \int_{\Gamma}f(z)dz + \int_{\gamma}f(z)dz \cr
&= \operatorname{P.V.}\int_{-R}^{R}f(z)dz + \int_{\Gamma}f(z)dz + \int_{\gamma}f(z)dz \cr
2\pi i\operatorname{Res}(f(z), z=\sqrt{2}i) + \int_{-\gamma}f(z)dz &= \operatorname{P.V.}\int_{-R}^{R}f(z)dz + \int_{\Gamma}f(z)dz,
}
$$
where we used one of the definitions of the Cauchy Principal Value.

(Answer) Given the above conditions, we will prove
$$\displaystyle \lim_{\epsilon \to 0}\int_{-\gamma}f(z)dz = i\pi\operatorname{Res}(f(z), z=-1).$$
Proof. Enclosing the pole $z_0 := -1$, the function can be expressed as
$$f(z) = g(z) + \displaystyle \sum_{n=-k}^{0} b_{2n-1}(z-z_0)^{2n-1}$$
such that $g(z)$ is analytic at $z_0 = -1$. Thus,
$$\int_{-\gamma}f(z)dz = \int_{-\gamma}g(z)dz + \displaystyle\int_{-\gamma}\sum_{n=-k}^{0}b_{2n-1}(z+1)^{2n-1}dz.$$
Taking $\epsilon \to 0$ on both sides, we will show that $\int_{-\gamma}g(z)dz \to 0$ by using the Estimation Lemma:
$$
\displaystyle
\eqalign{
0 &\leq \left|i\epsilon \int_{-\gamma}g(z)dz\right| \leq \epsilon \pi \sup(g(z), z \in -\gamma) \cr
\lim_{\epsilon \to 0} 0 &\leq \lim_{\epsilon \to 0} \left|i\epsilon \int_{-\gamma}g(z)dz\right| \leq \lim_{\epsilon \to 0} \epsilon \pi \sup(g(z), z \in -\gamma) \cr
0 &\leq  \lim_{\epsilon \to 0} \left|i\epsilon \int_{-\gamma}g(z)dz\right| \leq 0. \cr
}
$$
As $\epsilon \to 0$, the Squeeze Theorem yields $\displaystyle \left|i\epsilon \int_{-\gamma}g(z)dz\right| \to 0$, implying that $\displaystyle i\epsilon \int_{-\gamma}g(z)dz \to 0$ as well.
For the other contour integral, let $z = \epsilon e^{i\theta}-1$for $\theta \in [0,\pi]$. This parameterization results in
$$
\displaystyle
\eqalign{
ia\int_{0}^{\pi}\sum_{n=-k}^{0}b_{2n-1}\left(ae^{i\theta}\right)^{2n-1}e^{i\theta}d\theta &= i\int_{0}^{\pi}\sum_{n=-k}^{0}b_{2n-1}\left(ae^{i\theta}\right)^{2n}d\theta \cr
&= i\int_{0}^{\pi}\left(\sum_{n=-k}^{-1}b_{2n-1}\left(ae^{i\theta}\right)^{2n}+b_{-1}\right)d\theta \cr
&= i\sum_{n=-k}^{-1}b_{2n-1}a^{2n}\int_{0}^{\pi}e^{2ni\theta}d\theta+ib_{-1}\int_{0}^{\pi}d\theta \cr
&= 0+i\pi b_{-1} \cr
&= i\pi \operatorname{Res}(f(z), z=-1), \cr
}
$$
where we used the fact that $e^{2ni\theta}$ has a period $\pi$ to make the integral vanish.
Therefore, we are done. Q.E.D.

As for the second example, it is hard to understand, but I believe this is what the book did. Consider the usual semi-circular contour of radius $R$ but in the third and fourth quadrants, traversed clockwise. Let $C(R)$ be the segment and $\gamma(R)$ be the semicircle such that its ends connect the ends of $C(R)$. Let $f(z) = \dfrac{\exp(-4ix)}{(x+i)^2}$. Then by Cauchy's Residue Theorem, we get
$$\displaystyle \lim_{R \to \infty} -2\pi i \operatorname{Res}(f(z), z=-i) = \lim_{R \to \infty}\int_{C(R)}f(z)dz - \lim_{R \to \infty}\int_{-\gamma(R)}f(z)dz,$$
and the desired result follows, after some work.


but it doesn't explain why the 2 factor is missing in the answer. Why $\pi i$ instead of $2\pi i$ ?

As you probably have observed, the semicircular indent at the pole $z_0 = -1$ does not necessarily involve the famous Residue Theorem because, as you have acknowledged, the path is not closed. The first proof in this answer explains why. The calculations should be straightforward from here.

I don't understand yet the logic in the Cauchy Principale Value (P.V.) calculations.

It is just a matter of understanding the definition of the Cauchy Principal Value. When you take the Cauchy Principal Value of an improper integral, you split up the integral at the "difficult" point/singularity/pole and take an $\epsilon \to 0^+$ near the difficult point.

Again, I don't understand what has been done. Is there a general methode I can understand to solve those 2 exercices ?

It is just a matter of practice. If they help, you can refer to this and this.
Please let me know if you have any questions.
