how to expand $\int_{0}^x \cos(1/\xi)d\xi$ like this? $$
\int_0^x \cos(1/\xi)d\xi
  = x-\frac{\pi}{2}+\frac{1}{2x} - \frac{2!}{4!3!}\frac{1}{x^3}+ \frac{4!}{6!5!}\frac{1}{x^5}\cdots
$$
I expanded the Taylor series for $\cos(1/\xi)$ and integrated that.
but I could not make $\pi/2$.
how to make it?
 A: $$\int_0^x\cos(1/\xi)\,d\xi=\int_{1/x}^\infty\frac{\cos t}{t^2}\,dt$$
at least for $x>0$. Then
$$\int_{1/x}^\infty\frac{\cos t}{t^2}\,dt=x-\int_{1/x}^\infty(1-\cos t)\frac{dt}{t^2}$$
which looks less than $x$. But
$$\int_{1/x}^\infty(1-\cos t)\frac{dt}{t^2}
=\int_0^\infty(1-\cos t)\frac{dt}{t^2}
-\int_0^{1/x}(1-\cos t)\frac{dt}{t^2}.$$
The first term here is constant, and is related by integration by parts
to the "sine integral" $\int_0^\infty\frac{\sin t}t\,dt$
and the second integral can be expanded as a Taylor series.
A: Lord Shark has shown how to derive the expression in question. It is an expansion for $x \gg 1$.
Regarding the followup question whether there is an expansion for $0<x\ll1$: the function is not analytic for small $x$. Nevertheless, we can find an asymptotic expansion for
$$I(x) = \int_0^x \cos(1/\xi)d\xi = x\int_0^1 \cos(1/x t)\,dt = x \operatorname{Re}\underbrace{\int_0^1 e^{i(x t)^{-1}}\,dt}_{=J(x)}\,.$$
In the remaining integral, we perform the substitution $y=1/t$ and obtain
$$J(x) = \int_1^\infty \frac{e^{i y/x}}{y^2} \,dy$$
that is amenable to the saddle point approach. We deform the contour to the integration along the line $1+i\eta$, $\eta>0$ closed by a quarter circle in the first quadrant of the complex plane. The integral along the circle vanishes as the radius increases and we are left with
$$J(x) = i  e^{i/x} \int_0^\infty \frac{e^{-\eta/x}}{(1+ i \eta)^2}  \,dy $$
which is still exact.
We can now expand the denominator of the last expression and obtain
$$ J(x) = i  e^{i/x} \int_0^\infty e^{-\eta/x} \left( \sum_{n=1}^\infty n (-i \eta)^{n - 1} \right)  \,dy 
\sim - e^{i/x} \sum_{n=1}^\infty n! \,(-i x)^{n}$$
From that we obtain the asymptotic expansion (valid for small $x$)
$$I(x) \sim  \cos(1/x) \sum_{m=1}^\infty (-1)^{1 + m} (2 m)! \,x^{2 m} + \sin(1/x) \sum_{m=1}^\infty (-1)^m (2m-1)!\, x^{2m-1}  $$
