Principal value of integral How to find the Cauchy principal value of the integral $$\int_0^\infty \left(\frac{1}{x^2}-\frac{\cot(x)}{x} \right) dx?$$
 A: A few preliminary notes


*

*$\displaystyle f(z)=\frac1{z^2}-\frac{\cot(z)}{z}$ has a removable singuarity at $0$.

*the other singularities of $f$ have residue $-\dfrac1{n\pi}$ at $z=n\pi$.

*$\left\{\dfrac x\pi\right\}=\dfrac12\implies\cot(z)=i\tanh(y)$

*$|\cot(z)+i\,|\sim2e^{-2|y|}$ as $y\to\infty$.
We will integrate along the following contours:
$\hspace{7mm}$
Where the blue segments are along the lines $x=\pm\left(k+\frac12\right)\pi$ and the green segment is along $y=\sqrt{k}$ as $k\to\infty$.
Since the contour contains no singularities, we have
$$
\begin{align}
0=
&\mathrm{PV}\int_{-\infty}^\infty\left(\frac1{x^2}-\frac{\cot(x)}{x}\right)\,\mathrm{d}x
+\color{#C00000}{\int_{\large\gamma_s}\left(\frac1{z^2}-\frac{\cot(z)}{z}\right)\,\mathrm{d}z}\\
&+\color{#0000FF}{\int_{\large\gamma_v}\left(\frac1{z^2}-\frac{\cot(z)}{z}\right)\,\mathrm{d}z}
+\color{#00A000}{\int_{\large\gamma_h}\left(\frac1{z^2}-\frac{\cot(z)}{z}\right)\,\mathrm{d}z}
\end{align}
$$
Due to 2., the integral along $\color{#C00000}{\gamma_s}$ tends to $0$; that is, the residue at $k\pi$ cancels the residue at $-k\pi$.
Due to 3., the integral along $\color{#0000FF}{\gamma_v}$ tends to $0$; that is, $|\cot(z)|\le1$ on those segments.
Due to 4., the integral along $\color{#00A000}{\gamma_h}$ tends to $-\pi$; that is, $\cot(z)\to-i$.
Putting this all together, we get
$$
0=
\mathrm{PV}\int_{-\infty}^\infty\left(\frac1{x^2}-\frac{\cot(x)}{x}\right)\,\mathrm{d}x
+\color{#C00000}{0}+\color{#0000FF}{0}+\color{#00A000}{-\pi}
$$
Therefore,
$$
\mathrm{PV}\int_0^\infty\left(\frac1{x^2}-\frac{\cot(x)}{x}\right)\,\mathrm{d}x=\frac\pi2
$$
A: See the answer to this question at MO here
