It turns out that we have the following observation:
Observation. For a nice function $f : [0,\infty) \to \Bbb{C}$, we have
$$ \int_{\epsilon}^{\infty} \frac{f(x)}{x} \, dx = -f(0)\log\epsilon + c(f) + o(1) \qquad \text{as } \epsilon \to 0^+ \tag{1} $$
where the constant $c(f)$ is computed by
$$ c(f) = \lim_{R\to\infty}\left( \int_{0}^{R} \mathcal{L}f(s) \, ds - f(0)\log R\right) - f(0)\gamma. \tag{2} $$
The reasoning is surprisingly simple: First, define $g(x) = (f(x) - f(0)\mathbf{1}_{(0,1)}(x))/x$ and notice that
$$ \int_{\epsilon}^{\infty} \frac{f(x)}{x} \, dx = -f(0)\log\epsilon + \int_{\epsilon}^{\infty} g(x) \, dx. $$
Assuming that the LHS of $\text{(1)}$ exists for all $\epsilon > 0$ and that $f$ behaves nice near $x = 0$, this implies $\text{(1)}$. Next, notice that $c(f) = \mathcal{L}g(0)$ and that $-(\mathcal{L}g(s))' = \mathcal{L}f(s) - f(0) (1-e^{-s})/s$. Therefore
\begin{align*}
c(f)
&= \lim_{R\to\infty} \int_{0}^{R} (-\mathcal{L}g(s))' \, ds \\
&= \lim_{R\to\infty} \left( \int_{0}^{R} \mathcal{L}f(s) \, ds - f(0) (1 - e^{-R})\log R + f(0) \int_{0}^{R} e^{-s}\log s \, ds \right) \\
&= \lim_{R\to\infty} \left( \int_{0}^{R} \mathcal{L}f(s) \, ds - f(0) \log R \right) - f(0)\gamma.
\end{align*}
At this moment this is just a heuristic computation. For a broad class of functions for which the LHS of $\text{(1)}$ exists, however, this computation can be made rigorous. This is particularly true for our function $f(x) = \cos x$. Now plugging $\mathcal{L}f(s) = \frac{s}{s^2+1}$ shows that $c(f) = -\gamma$ and thus
$$ \int_{\epsilon}^{\infty} \frac{\cos x}{x} \, dx = -\log\epsilon - \gamma + o(1). $$
Plugging this asymptotics, we have
$$
\int_{\epsilon}^{\infty} \frac{\cos(x^2) - \cos x}{x} \, dx
= \frac{1}{2}\int_{\epsilon^2}^{\infty} \frac{\cos x}{x} \, dx - \int_{\epsilon}^{\infty} \frac{\cos x}{x} \, dx
= \frac{1}{2}\gamma + o(1)
$$
and the identity follows by letting $\epsilon \to 0^+$.
Here, the constant $c(f)$ can be thought as a regularized value of the divergent integral $\int_{0}^{\infty} \frac{f(x)}{x} \, dx$. This has the following nice properties (whenever they exist)
- $c$ is linear: $c(\alpha f(x) + \beta g(x)) = \alpha c(f) + \beta c(g)$.
- $c(f(x^p)) = \frac{1}{p}c(f)$ for $p > 0$,
- $c(f(px)) = c(f) - f(0)\log p$ for $p > 0$,
Together with some known values, we can easily compute other types of integrals. For instance, using the fact that $c(\cos x) = -\gamma$ and $c(e^{-x}) = -\gamma$, we have
\begin{align*}
\int_{0}^{\infty} \frac{\cos (x^p) - \exp(-x^q)}{x} \, dx
&= c\left\{ \cos (x^p) - \exp(-x^q) \right\} \\
&= \frac{1}{p}c(\cos x) - \frac{1}{q}c(e^{-x})
= \gamma\left( \frac{1}{q} - \frac{1}{p}\right)
\end{align*}
for $p, q > 0$.
\color{#FFFFFF}{}
? $\endgroup$ – Simply Beautiful Art Jan 16 '17 at 19:50