TITLE: $u$-substitution failure in finding $f'(x)$ where $ f(x) = \int_x^0 \frac{\cos(xt)}{t}\, dt$
QUESTION [6 upvotes]: I'm practicing for the GRE exam, and came across the following question: If
$$
f(x) = \int_x^0 \frac{\cos(xt)}{t}\, dt,
$$
find $f'(x)$. The answer given is $\frac{1}{x}(1 - 2\cos(x^2))$, and I see how they get that answer. What I'm wondering is why the following $u$-substitution gives the wrong answer (or perhaps I'm making a mistake somewhere):
If we set $u = xt$, then the integral transforms to 
$$
f(x) = \int_{x^2}^0 \frac{\cos(u)}{u}\, du,
$$
which means that $f'(x) = -(\cos(x^2)/x^2)(2x) = -\cos(x^2)/x$, which misses the $1/x$ term which the answer key says we should have.
I cannot see where I am making a mistake in the $u$-sub; is it invalid in this case? Any help is much appreciated.

REPLY [2 votes]: First, the integral $\int_x^0 \frac{\cos(xt)}{t}\,dt$ fails to exist.
So instead, suppose $f(x)$ be given by the integral
$$f(x)=\int_x^0 \frac{\cos(xt)-1}{t}\,dt$$
Then, we have from Leibniz's Rule
$$\begin{align}
f'(x)&=\frac{1-\cos(x^2)}{x}+\int_0^x \sin(xt)\,dt\\\\
&=2\left(\frac{1-\cos(x^2)}{x}\right)
\end{align}$$