<s>[INST] A difficult integral: $\int_0^{+\infty} e^{ - x}\left(\frac1{x( e^{ - x} - 1 )} + \frac1{x^2} + \frac1{2x} \right) \, dx$. Could you help me calculate the integral?

$$\int_0^{+\infty} e^{-x} \left(\frac1{x(e^{-x}-1)} + \frac1{x^2} + \frac1{2x} \right) \, dx .$$

 [/INST] One may recall Binet's formula, for $\Re z >0$,
$$
\log \Gamma(z)= \left( z-\frac{1}{2}\right)\log z - z + \frac{1}{2}\log(2\pi) + 
\int_0^{\infty} \!
\left(\frac{1}{2} - \frac{1}{x} + \frac{1}{e^{x}-1} \right)\frac{e^{-zx}}{x} \mathrm{d}x. \tag1
$$ Observing  that
$$
{\left( {\frac{1}{{x\left( {{e^{ - x}} - 1} \right)}} + \frac{1}{{{x^2}}} + \frac{1}{{2x}}} \right)} =-\left(\frac{1}{2} - \frac{1}{x} + \frac{1}{e^{x}-1} \right)\frac{1}{x}
$$ then, using $(1)$ with $z:=1$, readily gives

$$
\int_0^{ + \infty } {{e^{ - x}}\left( {\frac{1}{{x\left( {{e^{ - x}} - 1} \right)}} + \frac{1}{{{x^2}}} + \frac{1}{{2x}}} \right)dx}= \frac{1}{2}\log(2\pi)-1.
$$

</s>