How to calculate $\int_0^\infty \frac{1-\cos(x)}{x^2e^x}dx$ (it beats Maxima)? This is an integration theory practice exam question: Show that
$$\int_0^\infty \frac{1-\cos(x)}{x^2e^x} d\lambda (x)= \frac\pi4-\frac12\ln(2).$$
Hint: You may use without proof that
$$\frac \pi 4=\sum_{n=0}^\infty \frac{(-1)^n}{2n+1}, \quad \ln(2)=\sum_{n=0}^\infty \frac{(-1)^n}{n+1} \quad\text{and}\quad \int_0^\infty x^ne^{-x}dx = n!.$$
I thought it might be a good idea to use the exponential identity of $\cos(x)$, but that seemed to make the situation worse because it introduces complex numbers. Then looking at the hint I thought it might be worth it to insert the power series of $e$ and $\cos$ directly, but (because of the $1-$ term) those power series were "incompatible", nothing seemed to simplify which is always a bad sign.
The first part of this question showed that term by term integration would be justified.
Am I missing some steps before introducing the power series? Or can we simplify the power series expressions somehow?
 A: Let $$I(a)=\int^\infty_0\frac{1-\cos ax}{x^2}\,e^{-x}\,dx.$$ Then, $$I'(a)=\int^\infty_0\frac{\sin ax}{x}\,e^{-x}\,dx$$ and $$I''(a)=\int^\infty_0\cos ax\,e^{-x}\,dx=\frac1{1+a^2}.$$ Differentiating under the integral sign is justified, because the resulting integrals are absolutely convergent. The last integral can be evaluated, integrating by parts twice. Since $I'(0)=I(0)=0,$ we have $$I'(a)=\int^a_0 \frac1{1+t^2}\,dt=\arctan a,$$ and $$I(a)=\int^a_0 \arctan x\,dx=a\,\arctan a -\frac12\,\ln(1+a^2),$$ so the original integral is $$I(1)=\arctan 1-\frac12\,\ln 2=\frac\pi4-\frac12\,\ln 2.$$
A: Use the Taylor series for the cosine, so your integral is$$\sum_{n\ge0}\tfrac{(-1)^n}{(2n+2)!}\int_0^\infty x^{2n}e^{-x}d\lambda(x)=\sum_n\tfrac{(-1)^n}{(2n+1)(2n+2)}=\sum_n\left(\tfrac{(-1)^n}{2n+1}+\tfrac{(-1)^{n+1}}{2n+2}\right)=\tfrac{\pi}{4}-\tfrac12\ln2,$$where the linear combination of two alternating series is legal because the resulting alternating series still converges by the alternating series test.
