TITLE: How does one show that $\lim_{n\to\infty}\ln{n}-\int_{0}^{n}{e^x-x-1\over x(e^x+1)}=\ln{\pi}-\gamma$
QUESTION [8 upvotes]: Consider

$$\lim_{n\to\infty}\ln{n}-\int_{0}^{n}{e^x-x-1\over x(e^x+1)}=\ln{\pi}-\gamma\tag1$$

How does one show that?

Wolfram integrator can't evaluate the indefinite integral $(1)$

REPLY [2 votes]: $\newcommand{\bbx}[1]{\,\bbox[8px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

Note that

\begin{align}
&\lim_{n\to\infty}\bracks{\ln\pars{n} -
\int_{0}^{n}{\expo{x} - x - 1 \over x\pars{\expo{x} + 1}}\,\dd x}
\\[5mm] = &\
\lim_{n\to\infty}\bracks{\ln\pars{n} -
\int_{0}^{n}{1 - \expo{-x} \over 1 + \expo{-x}}\,{\dd x \over x}\ +\
\overbrace{\int_{0}^{n}{\dd x \over \expo{x} + 1}}
^{\ds{\ln\pars{2} - \ln\pars{1 + \expo{-n}}}}}
\\[5mm] = &\
\lim_{n \to \infty}\bracks{%
\ln\pars{2n \over 1 + \expo{-n}} - \pars{%
\int_{0}^{n}{1 - \expo{-x} \over 1 + \expo{-x}}\,{\dd x \over x} -
\int_{0}^{n}{1 - \expo{-x} \over x}\,\dd x} -
\int_{0}^{n}{1 - \expo{-x} \over x}\,\dd x}
\\[5mm] & =
\lim_{n \to \infty}\braces{%
\ln\pars{2n \over 1 + \expo{-n}} + 
\int_{0}^{n}\!\!{\expo{-x} - \expo{-2x} \over 1 + \expo{-x}}\,{\dd x \over x} -
\bracks{\ln\pars{n}\pars{1 - \expo{-n}} -
\int_{0}^{n}\!\!\!\!\ln\pars{x}\expo{-x}\,\dd x}}
\\[5mm] = &\
\ln\pars{2}\ +\
\underbrace{\int_{0}^{\infty}{\expo{-x} - \expo{-2x} \over 1 + \expo{-x}}
\,{\dd x \over x}}_{\ds{\ln\pars{\pi \over 2}}}\ +\
\underbrace{\int_{0}^{\infty}\ln\pars{x}\expo{-x}\,\dd x}_{\ds{-\gamma}} =
\bbx{\ds{\ln\pars{\pi} - \gamma}}
\end{align}

Note that
  $\ds{\int_{0}^{\infty}\ln\pars{x}\expo{-x}\,\dd x =
\left.\totald{}{\mu}\int_{0}^{\infty}x^{\mu}\expo{-x}\,\dd x\,
\right\vert_{\ \mu\ =\ 0} =
\left.\totald{\Gamma\pars{\mu + 1}}{\mu}\right\vert_{\ \mu\ =\ 0} = \Psi\pars{1} = -\gamma}$.


The remaining integral is evaluated as follows:
\begin{align}
&\bbx{\ds{%
\int_{0}^{\infty}{\expo{-x} - \expo{-2x} \over 1 + \expo{-x}}\,{\dd x \over x}}} =
\int_{0}^{\infty}{\expo{-3x} - 2\expo{-2x} + \expo{-x} \over 1 - \expo{-2x}}\,{\dd x \over x}
\\[5mm] \stackrel{\expo{-2x}\ \mapsto\ x}{=}\,\,\,&
-\int_{0}^{1}{x^{1/2} - 2 + x^{-1/2} \over 1 - x}\,{\dd x \over \ln\pars{x}} =
-\int_{0}^{1}{x^{1/2} - 2 + x^{-1/2} \over 1 - x}
\pars{-\int_{0}^{\infty}x^{t}\,\dd t}\,\dd x
\\[5mm] = &\
\int_{0}^{\infty}\int_{0}^{1}
{x^{t + 1/2} - 2x^{t} + x^{t - 1/2} \over 1 - x}\,\dd x\,\dd t
\\[5mm] = &\
\int_{0}^{\infty}\bracks{%
-\int_{0}^{1}{1 - x^{t + 1/2} \over 1 - x}\,\dd x +
2\int_{0}^{1}{1 - x^{t} \over 1 - x}\,\dd x -
\int_{0}^{1}{1 - x^{t - 1/2} \over 1 - x}\,\dd x}\,\dd t
\\[5mm] = &\
\int_{0}^{\infty}\bracks{-\Psi\pars{t + {3 \over 2}} +
2\Psi\pars{t + 1} - \Psi\pars{t + {1 \over 2}}}\dd t
\\[5mm] = &\
\left.-\ln\pars{\Gamma\pars{t + 3/2}\Gamma\pars{t + 1/2} \over
\Gamma^{2}\pars{t + 1}}\right\vert_{\ t\ =\ 0}^{\ t\ \to\ \infty} =
\ln\pars{\Gamma\pars{3/2}\Gamma\pars{1/2} \over \Gamma^{2}\pars{1}} =
\ln\pars{{1 \over 2}\,\Gamma^{2}\pars{1 \over 2}}
\\[5mm] = &\
\bbx{\ds{\ln\pars{\pi \over 2}}}
\end{align}