Convergence of integral using Cauchy's theorem I've always thought that integrals of the form $\int_0^{x_0}  \frac{dx}{x^d}$ for $d\geq1$ don't converge. However, during a calculation, an integral of this kind (with $d=2$) appeared and I really needed to evaluate it in some way. Here's what I thought:

*

*given that, for $d=2$, the integral is even, we can write it like (also adding a convergence factor)
$$ \int_0^{x_0} \frac{dx}{x^2} = \frac{1}{2} \lim_{\delta \rightarrow 0} \int_{-x_0}^{x_0}\frac{dx}{(x-i\delta)^2}$$

*Now, let $x\in \mathbb{C}$ and use Cauchy's theorem for the pole located at $x=i\delta$
$$ \int_{-x_0}^{x_0}\frac{dx}{(x-i\delta)^2} = 2\pi i Res\big[(x-i\delta)^{-2},x=i\delta\big] - \int_{\Gamma} \frac{dx}{(x-i\delta)^2} $$
where the contour is $\Gamma = \{x_0e^{i\theta}, \theta \in [0,\pi] \} $

*In fact, the residue evaluates to zero. For the integral that is missing, let me perform the change of variables $x=x_0e^{i\theta}$ and $dx= ix_0e^{i\theta} d\theta$, such that
$$\int_{\Gamma} \frac{dx}{(x-i\delta)^2} = ix_0 \int_0^\pi d\theta \  \frac{e^{i\theta}}{x_0^2e^{2i\theta} - 2i\delta x_0e^{i\theta} - \delta^2} = ix_0 \int_0^\pi d\theta \  \frac{1}{x_0^2e^{i\theta} - 2i\delta x_0- \delta^2e^{-i\theta}}$$

*A primitive for the last integrand is $$\frac{i}{e^{i\theta}x_0^2-i\delta x_0}$$
which implies
$$\int_{\Gamma} \frac{dx}{(x-i\delta)^2}  = \frac{2x_0}{x_0^2+\delta^2}$$

*Therefore, plugging all these results together seems to imply that
$$ \int_0^{x_0} \frac{dx}{x^2}  = - \frac{1}{x_0}$$
Can anyone please tell me what did I do wrong? Because I'm pretty sure this should diverge, but I can't find the wrong step here.

 A: Although the $x$ in this answer may be translated along the imaginary axis from the one in the question, the integrals are the same. Here are the contours involved:

The red contour is the reverse of $[-L-i\delta,L-i\delta]$. Cauchy's Theorem says that the integral along the red, green, and blue contours is $0$. Therefore, we get
$$
\begin{align}
\overbrace{\int_{-x_0}^{x_0\vphantom{0}}\frac1{(x-i\delta)^2}\,\mathrm{d}x}^{-\frac{2x_0}{x_0^2+\delta^2}}
&=\overbrace{\int_{-x_0}^{-r\vphantom{0}}\frac1{x^2}\,\mathrm{d}x}^{\frac1r-\frac1{x_0}}
+\overbrace{\int_{-\pi}^0\frac1{\left(re^{i\theta}\right)^2}ire^{i\theta}\,\mathrm{d}\theta}^{-\frac2r}
+\overbrace{\int_r^{x_0\vphantom{0}}\frac1{x^2}\,\mathrm{d}x}^{\frac1r-\frac1{x_0}}\tag1\\
&+\underbrace{\int_0^\delta\frac{i}{(-x_0-it)^2}\,\mathrm{d}t+\int_0^\delta\frac{-i}{(x_0-it)^2}\,\mathrm{d}t}_{\frac{2\delta^2}{x_0\left(x_0^2+\delta^2\right)}}\tag2
\end{align}
$$
The middle integral on the right of $(1)$ (the semi-circular arc) uses $z=re^{i\theta}$, which evaluates to
$$
\begin{align}\int_{-\pi}^0\frac1{\left(re^{i\theta}\right)^2}ire^{i\theta}\,\mathrm{d}\theta
&=\frac ir\int_{-\pi}^0e^{-i\theta}\,\mathrm{d}\theta\\
&=\left.-\frac1re^{-i\theta}\right]_{-\pi}^0\\
&=-\frac2r\tag3
\end{align}
$$
The integrals on $(2)$ consist of the two blue integrals on the ends. We can use
$$
\frac{i}{(-x_0-it)^2}+\frac{-i}{(x_0-it)^2}=\frac{4x_0t}{\left(x_0^2+t^2\right)^2}\tag4
$$
and
$$
\int_0^\delta\frac{4x_0t}{\left(x_0^2+t^2\right)^2}\,\mathrm{d}t
=\frac{2\delta^2}{x_0\!\left(x_0^2+\delta^2\right)}\tag5
$$

The Integral Along The Semi-Circular Curve
One problem is the integral along the semi-circle. For a pole of degree $1$, the integral along an arc around the pole equals the residue times $i$ times the angle of the arc around the singularity. This is  a pole of degree $2$, and while the integral along a circle around the pole is $2\pi i$ times the residue, we cannot use a partial circle as we can with a pole of degree $1$.
Note that above, the residue at $0$ is $0$, but the integral along the semi-circle is $-2/r$, which blows up as $r\to0$.

The First Equation of the Answer
Furthermore, since
$$
\int_{-x_0}^{x_0}\frac{dx}{x^2}\ne\lim_{\delta\to0}\int_{-x_0}^{x_0}\frac{\mathrm{d}x}{(x-i\delta)^2}\tag6
$$
the first equation of the answer does not hold. The path of the integral on the left passes through the singularity, so we cannot apply Cauchy's Theorem.
