show that $\int_{0}^{\infty } \frac {\cos (ax) -\cos (bx)} {x^2}dx=\pi \frac {b-a} {2}$

show that

$$\int_{0}^{\infty } \frac {\cos (ax) -\cos (bx)} {x^2}dx=\pi \frac {b-a} {2}$$ for $a,b\geq 0$

I would like someone solve it using contour integrals, also I would like to see different solutions using different ways to solve it.


$$\begin{aligned}\int_0^{\infty} \frac{\cos ax-\cos bx}{x^2}\,dx &=\int_0^{\infty}\int_a^{b}\frac{\sin tx}{x}\,dt\,dx \\&=\int_a^{b}\int_0^{\infty}\frac{\sin tx}{x}\,dx\,dt\\&=\int_a^b \frac{\pi}{2}\,dt\\&=\frac{(b-a)\pi}{2}\end{aligned} $$


Method 1

Integrate once by parts to get $$\int_0^{\infty}\frac{b\sin bx-a\sin ax}{x}dx$$ and then use Dirichlet integral $\displaystyle \int_0^{\infty}\frac{\sin x}{x}dx=\frac{\pi}{2}$.

Method 2 (contour integration):

Using parity, write the integral as $\displaystyle\frac12\int_{-\infty}^{\infty}$ and then deform the contour to be the line $C$ slightly below the real axis. Next express cosines in terms of exponentials. Then we obtain $$I=\frac14\left(\int_C \frac{e^{iax}dx}{x^2}+\int_C \frac{e^{-iax}dx}{x^2}-\int_C \frac{e^{ibx}dx}{x^2}-\int_C \frac{e^{-ibx}dx}{x^2}\right)$$

For $a,b>0$, in the integrals containing $e^{-iax}$, $e^{-ibx}$, the contour can be closed in the lower half plane (by Jordan lemma) and therefore these integrals vanish (as there are no singularities inside).

The integrals containing $e^{iax}$, $e^{ibx}$ can only be closed in the upper half plane and are therefore given by the residues at $x=0$: $$I=\frac{\pi i}{2}\left(\mathrm{res}_{x=0}\frac{e^{iax}}{x^2}-\mathrm{res}_{x=0}\frac{e^{ibx}}{x^2}\right) =\frac{\pi i}{2}\left(ia-ib\right)=\frac{\pi(b-a)}{2}.$$


Divide into two parts, and then use integration by parts to get a Sine Integral, and note that $\cos(ax)/x$ tends to $0$ as $x\to \infty$, so that you remain with $\rm{Si}(x)$ which tends to $\pi/2$.