prove that $\int_0^\infty \frac{\sin^2 x-x\sin x}{x^3} \, dx= \frac{1}{2} - \ln 2$ 
Prove that
$$ \int_{0}^{\infty} \frac{\sin^2 x-x\sin x}{x^3} \, dx = \frac{1}{2} - \ln 2 .$$

Integration by parts gives
\begin{align*}
&\lim_{R\to \infty} \int_{0}^{R} \frac{\sin^2 x-x\sin x}{x^3} \, dx \\
&= \lim_{R\to \infty} \biggl( \int_{0}^{R} \frac{\sin^2x}{x^3} \, dx - \int_{0}^{R} \frac{\sin x}{x^2} \, dx \biggr)\\
&= \lim_{R\to\infty} \biggl( \frac{\sin^2 x}{-2x^2}\Biggr\rvert_{0}^{R} - \int_{0}^{R} \frac{\sin (2x)}{-2x^2} \, dx - \biggl(-\frac{\sin x}{x} \Biggr\rvert_{0}^{R} + \int_{0}^{R} \frac{\cos x}{x} \,dx \biggr) \biggr) \\
&= \lim_{R\to \infty} \biggl(\frac{1}{2} + \int_{0}^{2R} \frac{\sin u}{u^2/2} \, \Bigl(\frac{1}2 \, du\Bigr) - \biggl( 1 + \int_{0}^{R} \frac{\cos x}{x} \, dx \biggr)\biggr) \\
&\hspace{22em}\text{(using the substitution $u\mapsto 2x$)}\\
&= -\frac{1}{2} + \lim_{R\to \infty} \biggl(\int_{0}^{2R} \frac{\sin u}{u^2} \, du - \int_{0}^{R} \frac{\cos x}{x} \,dx \biggr)\\
&= \frac{1}{2} + \lim_{R\to\infty} \biggl(\int_{R}^{2R} \frac{\cos x}{x} \, dx \biggr)
\end{align*}
Thus it suffices to show that $\lim_{R\to\infty} \int_{R}^{2R} \frac{\cos x}{x} \, dx = \ln 2$. The Taylor series expansion of $\cos x$ is given by $\cos x = \sum_{i=0}^{\infty} \frac{(-1)^i x^{2i}}{(2i)!}$.

(If the step below (the one involving the interchanging of an infinite sum and integral) is valid, why exactly is it valid? For instance, does it use uniform convergence?)

The limit equals
$$
\lim_{R\to\infty} \int_{R}^{2R} \biggl( \frac{1}{x} + \sum_{i=1}^{\infty} \frac{(-1)^i x^{2i-1}}{(2i)!} \biggr) \, dx
= \ln 2 + \lim_{R\to\infty} \sum_{i=1}^{\infty} \biggl[\frac{(-1)^ix^{2i}}{(2i)(2i)!}\biggr]_{R}^{2R} . $$
But I don't know how to show $\lim_{R\to\infty} \lim_{R\to\infty} \sum_{i=1}^{\infty} \Bigl[\frac{(-1)^ix^{2i}}{(2i)(2i)!}\Bigr]_{R}^{2R} = -2 \ln 2$.
 A: Here is a correct solution that you might want to compare with:
\begin{align*}
&\int_{0}^{\infty}\frac{\sin^2 x - x \sin x}{x^3} \, \mathrm{d}x \\
&= \lim_{\substack{R\to\infty \\ \varepsilon \to 0^+}} \int_{\varepsilon}^{R}\frac{\sin^2 x - x \sin x}{x^3} \, \mathrm{d}x \\
&= \lim_{\substack{R\to\infty \\ \varepsilon \to 0^+}} \biggl( \left[ -\frac{\sin^2 x}{2x^2} + \frac{\sin x}{x} \right]_{\varepsilon}^{R} + \int_{\varepsilon}^{R} \left( \frac{\sin(2x)}{2x^2} - \frac{\cos x}{x} \right) \, \mathrm{d}x \biggr) \\
&= -\frac{1}{2} +  \lim_{\substack{R\to\infty \\ \varepsilon \to 0^+}} \biggl( \int_{2\varepsilon}^{2R} \frac{\sin x}{x^2} \, \mathrm{d}x - \int_{\varepsilon}^{R} \frac{\cos x}{x} \, \mathrm{d}x \biggr) \\
&= -\frac{1}{2} +  \lim_{\substack{R\to\infty \\ \varepsilon \to 0^+}} \biggl( \left[ -\frac{\sin x}{x} \right]_{2\varepsilon}^{2R} + \int_{2\varepsilon}^{2R} \frac{\cos x}{x} \, \mathrm{d}x - \int_{\varepsilon}^{R} \frac{\cos x}{x} \, \mathrm{d}x \biggr) \\
&= \frac{1}{2} +  \lim_{\substack{R\to\infty \\ \varepsilon \to 0^+}} \biggl( \int_{R}^{2R} \frac{\cos x}{x} \, \mathrm{d}x - \int_{\varepsilon}^{2\varepsilon} \frac{\cos x}{x} \, \mathrm{d}x \biggr).
\end{align*}
Now by noting that
\begin{align*}
\left|\int_{R}^{2R} \frac{\cos x}{x} \, \mathrm{d}x\right|
&= \left| \frac{\sin R}{R} - \frac{\sin (2R)}{2R} + \int_{R}^{2R} \frac{\sin x}{x^2} \, \mathrm{d}x \right| \\
&\leq \frac{1}{R} + \frac{1}{2R} + \int_{R}^{2R} \frac{1}{x^2} \, \mathrm{d}x \\
&= \frac{2}{R},
\end{align*}
it follows that
$$ \lim_{R\to\infty} \int_{R}^{2R} \frac{\cos x}{x} \, \mathrm{d}x = 0. $$
On the other hand, by substituting $x = \varepsilon u$,
$$ \int_{\varepsilon}^{2\varepsilon} \frac{\cos x}{x} \, \mathrm{d}x
= \int_{1}^{2} \frac{\cos(\varepsilon u)}{u} \, \mathrm{d}u
\xrightarrow{\varepsilon \to 0^+} \int_{1}^{2} \frac{1}{u} \, \mathrm{d}u = \log 2 $$
by the dominated convergence theorem. Therefore
$$ \int_{0}^{\infty}\frac{\sin^2 x - x \sin x}{x^3} \, \mathrm{d}x = \frac{1}{2} - \log 2. $$
A: $$I=\int \frac{\sin^2 (x)-x\sin (x)}{x^3}\, dx=\int \frac{\sin^2 (x)}{x^3}\, dx-\int \frac{\sin (x)}{x^2}\, dx$$
$$\int \frac{\sin^2 (x)}{x^3}\, dx=\frac 1 2\int \frac{1-\cos(2x)}{x^3}\,dx$$
$$\int \frac{1-\cos(2x)}{x^3}\,dx=-\frac 1{2x^2}-\int \frac{\cos(2x)}{x^3}\,dx$$
$$\int \frac{\cos(2x)}{x^3}\,dx=-\frac{\cos(2x)}{x^2}-\int\frac{\sin(2x)}{x^2}\,dx$$
$$\int\frac{\sin(2x)}{x^2}\,dx=-\frac{\sin(2x)}{x}+2\int \frac{\cos(2x)}x\,dx$$
$$\int \frac{\cos(2x)}x\,dx=\int \frac{\cos(y)}y\,dy=\text{Ci}(y)=\text{Ci}(2x)$$
Combining all the above
$$\color{red}{\int \frac{\sin^2 (x)}{x^3}\, dx=\text{Ci}(2 x)-\frac{\sin (x) (\sin (x)+2 x \cos (x))}{2 x^2}}$$
$$\int \frac{\sin (x)}{x^2}\, dx=-\frac{\sin (x)}{x}+\int \frac{\cos(x)}x\,dx$$
$$\color{red}{\int \frac{\sin (x)}{x^2}\, dx=-\frac{\sin (x)}{x}+\text{Ci}(x)}$$
So,
$$\color{blue}{I=-\text{Ci}(x)+\text{Ci}(2 x)-\frac{1}{4 x^2}+\frac{\cos (2 x)}{4 x^2}+\frac{\sin(x)}{x}-\frac{\sin (2 x)}{2 x}}$$ If $x\to \infty$ its value is $0$.
Now, for $x\to 0$, using expansion we have
$$\left(\log (2)-\frac{1}{2}\right)-\frac{x^2}{12}+\frac{13
   x^4}{1440}+O\left(x^6\right)$$
$$J=\int_\epsilon^\infty \frac{\sin^2 (x)-x\sin (x)}{x^3}\, dx=\left(\frac{1}{2}-\log (2)\right)+\frac{\epsilon^2}{12}+O\left(\epsilon^4\right)$$
A: Alternatively, we could use the fact that  $$\int_{0}^{\infty} t^{2} e^{-xt} \, \, \mathrm dt = \frac{2}{x^{3}}, \quad x >0,$$ and then apply Fubini's theorem.$$\begin{align} \int_{0}^{\infty} \frac{\sin^{2}x - x \sin x}{x^{3}}  \,  \mathrm dx &= \frac{1}{2}\int_{0}^{\infty} \left(\sin^{2} x - x \sin x \right) \int_{0}^{\infty} t^{2}e^{-xt} \, \mathrm dt \, \mathrm dx \\ &= \frac{1}{2}\int_{0}^{\infty} t^{2} \int_{0}^{\infty} \left(\sin^{2} x - x \sin x \right) e^{-xt} \, \mathrm dx \, \mathrm dt \\ &= \frac{1}{2}\int_{0}^{\infty} t^{2} \left(\frac{1}{2} - \frac{\cos 2x}{2} - x \sin x \right) e^{-xt} \, \mathrm dx \, \mathrm dt \\ &= \frac{1}{2}\int_{0}^{\infty} t^{2} \left(\frac{1}{2t} - \frac{1}{2} \frac{t}{t^{2}+4}+ \frac{\mathrm d}{\mathrm d t}\frac{1}{t^{2}+1} \right) \, \mathrm dt \tag{1}\\ &= \frac{1}{2}\int_{0}^{\infty} t^{2} \left(\frac{1}{2t} - \frac{1}{2} \frac{t}{t^{2}+4}- \frac{2t}{(t^{2}+1)^{2}} \right) \, \mathrm dt \\ &= \frac{1}{2} \int_{0}^{\infty} t^{2}\left(\frac{2}{t(t^{2}+4)} - \frac{2t}{(t^{2}+1)^{2}}  \right) \, \mathrm dt \\ &= \frac{1}{2} \int_{0}^{\infty} \left(\frac{2t}{t^{2}+4} - \frac{2t}{t^{2}+1} + \frac{2t}{(t^{2}+1)^{2}} \right) \, \mathrm dt \\ &= \frac{1}{2} \left(\ln \left(\frac{t^{2}+4}{t^{2}+1} \right) - \frac{1}{t^{2}+1} \right)\Bigg|_{0}^{\infty} \\ &= \frac{1}{2} \left(-\ln 4 +1  \right) \\ &= \frac{1}{2} - \ln 2. \end{align} $$

$(1)$ $\int_{0}^{\infty} x \sin(x) e^{-xt} \, \mathrm  dx = -\frac{\mathrm d}{\mathrm dt} \int_{0}^{\infty} \sin(x) e^{-xt} \, \mathrm dx$
